There are a few issues that one may encounter when attempting to generalize Lagrange's algorithm to higher dimensions. Most importantly, one needs to figure what is the proper way to swap the vectors around and when to terminate, ideally in in polynomial time. A rough sketch of how the algorithm should look like is
def LLL(B):
d = B.nrows()
i = 1
while i<d:
size_reduce(B)
if swap_condition(B):
i += 1
else:
B[i],B[i-1] = B[i-1],B[i]
i = max(i-1,1)
return B
There are two things we need to figure out, in what order should we reduce the basis elements by and how should we know when to swap. Ideally, we also want the basis to be ordered in a way such that the smallest basis vectors comes first. Intuitively, it would also be better to reduce a vector by the larger vectors first before reducing by the smaller vectors, a very vague analogy to filling up a jar with big stones first before putting in the sand. This leads us to the following size reduction algorithm:
def size_reduce(B):
d = B.nrows()
i = 1
while i<d:
Bs,M = B.gram_schmidt()
for j in reversed(range(i)):
B[i] -= round(M[i,j])*B[j]
Bs,M = B.gram_schmidt()
return B
Next, we need to figure a swapping condition. Naively, we want
We can further improve this by optimizing the Gram Schmidt computation as this algorithm does not modify B∗at all. Furthermoreμchanges in a very predictable fasion and when vectors are swapped, one can write explicit formulas for howB∗changes as well.
∥bi∥≤∥bi+1∥
for all i. However, such a condition does not guarantee termination in polynomial time. As short basis vectors should be almost orthogonal, we may also want to incorperate this notion. Concretely, we want ∣μi,j∣to be somewhat small for all pairs of i,j, i.e. we may want something like
∣μi,j∣≤c
However, since μi,j=⟨bj∗,bj∗⟩⟨bi,bj∗⟩, this condition is easily satisfied for a sufficiently long bj∗, which is not what we want. The key idea is to merge these two in some way and was first noticed by Lovász - named the Lovász condition:
δ∥bi∗∥2≤bi+1∗+μi+1,ibi∗2δ∈(41,1)
It turns out that using this condition, the algorithm above terminates in polynomial time! More specifically, it has a time complexity of O(d5nlog3B)where we havedbasis vectors as a subset of Rnand Bis a bound for the largest norm of bi. 41<δ ensures that the lattice vectors are ordered roughly by size and δ<1ensures the algorithm terminates.
This follows the proof provided by the authors of the LLL paper. We first prove that the algorithm terminates by showing it swaps the vectors finitely many times. Letdbe the number of basis vectors as a subset of Rn. Let dibe the volume of the lattice generated by {bj}j=1iat each step of the algorithm. We have di=∏j=1ibj∗. Now consider the quantity
D=i=1∏ddi
This quantity only changes whenever some bi∗changes, i.e when swaps happen. Let's consider what happens when we swap biand bi+1. Recall the Gram-Schmidt algorithm:
From this, see that when we swap biand bi+1, bi∗is replaced by bi+1∗+μi+1,ibi∗. Now using the Lovász condition, we see that we havebi+1∗+μi+1,ibi∗2<δ∥bi∗∥2, hence the value of dimust decrease by at least δ, i.e. the new diis less than δdi. All other dj,j=imust remain the same as the volume remains fixed when we swap basis vectors around. Hence at each swap, Ddecreases by δ. This is why we need δ<1.Now we are left with showing diis bounded from below then we are done.
Let λ1(L)be the length of the shortest (nonzero) vector in the lattice. We can treat dias the volume of the lattice Ligenerated by{bj}j=1i. Let xibe the shortest vector in the lattice in Li. By using Minkowski's lattice point theorem, we have
(Note that the value of Ciisn't particularly important, one can use a easier value like i)
Hence we see that di, and hence Dhas a (loose) lower bound Dmin=∏i=1ddi,min, meaning that there are at most logDminδlogDswaps. Since at each iteration,keither increases by1when there is no swaps or decreases by at most1when there is swaps and kranges from2tod, the number of time the loop runs must be at most 2logDminδlogD+d, hence the algorithm terminates.
This proof also gives us a handle on the time complexity of the operation. LetBis the length of the longest input basis vector. Since we have di≤Bi, D≤B2m2+mand the algorithm loops O(d2logB)times. The Gram-Schmidt orthogonalization is the most expensive part in the entire process, taking up O(d2n)arithmetic operations. By using classical algorithm for arithmetic operations, each takes O(nlogB)time. From this, we deduce that the time complexity of the LLL algorithm is O(d5mlog2B), a somewhat reasonable polynomial time algorithm.
Let bibe the output of the LLL algorithm, it turns out that we have the bound
∥b1∥≤(4δ−14)4d−1vol(L)d1
which requires δ>41. Such bounds for the shortest vector will be elaborated in more detail in the section on reduced basis.
1) Implement the LLL in sage and experimentally verify that Ddoes indeed decrease byδeach time.
2) Show that the time complexity analysis is correct, and indeed each loop takes at most O(d2n)operations.