Lagrange's algorithm, often incorrectly called Gaussian reduction, is the 2D analouge to the Euclidean algorithm and is used for lattice reduction. Intuitively, lattice reduction is the idea of finding a new basis that consists of shorter vectors. Before going into Lagrange's algorithm, we first recap the Euclidean algorithm:
def euclid(m,n):
while n!=0:
q = round(m/n)
m -= q*n
if abs(n) > abs(m):
m, n = n, m
return abs(m)
The algorithm primarily consists of two steps, a reduction step where the size of mis brought down by a multiple of nand a swapping step that ensures mis always the largest number. We can adapt this idea for lattices:
def lagrange(b1,b2):
mu = 1
while mu != 0:
mu = round((b1*b2) / (b1*b1))
b2 -= mu*b1
if b1*b1 > b2*b2:
b1, b2 = b2, b1
return b1, b2
Here μis actually the Gram-Schmidt coefficient μ2,1and it turns out that this algorithm will always find the shortest possible basis! Using the basis
b1b2==(−1.8,1.2)(−3.6,2.3)
the Lagrange reduction looks like
and here we see it clearly gives the shortest vectors.
Optimality proof
Let Lbe a lattice. The basis b1,b2is defined to be the shortest for any other basis b1′,b2′,∥b1′∥≤∥b2′∥, we have ∥b1∥≤∥b1′∥and ∥b2∥≤∥b2′∥. Note that this generally cannot be generalized to other dimensions, however in dimension 2, this is possible and is given by Lagrange's algorithm. The proof is a somewhat messy sequence of inequalities that eventually lead to the conclusion we want.
Let b1,b2be the output of the Lagrange reduction for some lattice L. To prove that Lagrange reduction gives the shortest basis, we first show that ∥b1∥is the shortest vector in L.
We know that ∥b1∥2∣⟨b1,b2⟩∣≤21from the algorithm directly. Let v=mb1+nb2∈Lbe any element in L. We first show that ∥b1∥≤∥v∥:
Since m2−mn+n2=(m−2n)2+43n2, this quantity is only 0when m=n=0and is a positive integer for all other cases, hence ∥v∥≥∥b1∥and ∥b1∥is a shortest vector of L. Note that we can have multiple vectors with the same norm as b1, for instance −b1. So this is not a unique shortest vector.
Suppose there exists some basis b1′,b2′for Lsuch that ∥b1′∥≤∥b2′∥. We show that ∥b2∥≤∥b2′∥. Let b2′=mb1+nb2.
If n=0, then b2′=±b1as b1′,b2′must form a basis. This means that ∥b1∥=∥b1′∥=∥b2′∥ and by the inequality above, we must have ±b1′=b2or ±b1′=b1+b2. The first case tells us that ∥b1′∥=∥b2∥. By squaring the second case, we get
Hence proving Lagrange's algorithm indeed gives us the shortest basis vectors.
Exercises
1) Show that the output of Lagrange's algorithm generate the same lattice as the input.
2) Find a case where ∥b1∥=∥b2∥=∥b1+b2∥. Notice that the vectors here is the equality case for the bound given in Exercise 4 of the introduction, this actually tells us that the optimal lattice circle packing in 2D is given by this precise lattice! It turns out that this is actually the optimal circle packing in 2D but the proof is significantly more involved. (See https://arxiv.org/abs/1009.4322 for the details)
3*) Let μ2,1=⌊μ2,1⌉+ε=μ+ϵ, show that
∥b2∥2≥((∣μ∣−21)2−ε2)∥b1∥2+∥b2−μb1∥
and show that ∣μ∣≥2for all steps in the algorithm except the first and last, hence ∥b1∥∥b2∥decreases by at least 3 at each loop and the algorithm runs in polynomial time.