The LLL algorithm returns a delta-LLL-reduced basis of the same lattice after O(n^2 log X) swaps full
This proof shows: correctness, termination, time.worst.
Setting. The input is a list of linearly independent rows b1,…,bn∈Qm and a rational δ with 1/4<δ<1. We write bi∗ for the Gram-Schmidt vectors of the current rows, Bi=∥bi∗∥2, μij=⟨bi,bj∗⟩/Bj for j<i, so that bi=bi∗+∑j<iμijbj∗, and πi for the orthogonal projection onto span(b1,…,bi−1)⊥. The nearest integer ⌈x⌋=⌊x+1/2⌋ satisfies ∣x−⌈x⌋∣≤1/2. The line numbers refer to the main block of the page.
Lemma 1 (the rows stay a basis of L). At every moment the current rows are a basis of the input lattice L.
Proof. REDUCE replaces bk by bk−qbj with q∈Z and j=k, and line L6 exchanges two rows. Both are multiplications on the left by an integer matrix of determinant ±1, whose inverse is again an integer matrix. So the new rows generate the same lattice, and they are still independent. □
Lemma 2 (REDUCE keeps the data correct). After REDUCE(k,j), j<k, the bi∗ and Bi are unchanged, the stored μ equal the Gram-Schmidt coefficients of the new rows, and ∣μkj∣≤1/2.
Proof. The change −qbj lies in span(b1,…,bk−1), so πk(bk), which is bk∗, does not change; no other row changes. Using bj=bj∗+∑i<jμjibi∗, the new bk is bk∗+∑i<kμki′bi∗ with μki′=μki−qμji for i<j, μkj′=μkj−q, and μki′=μki for j<i<k. These are the updates of REDUCE, and ∣μkj−⌈μkj⌋∣≤1/2. Rows i=k of μ are coefficients of other rows on the unchanged bi∗, so they do not change. □
Lemma 3 (the swap formulas). Let c be the rows after line L6, so ck−1=bk, ck=bk−1 and ci=bi otherwise. Let μ=μk,k−1 and B=Bk+μ2Bk−1. Then ci∗=bi∗ for i=k−1,k, and
∥ck−1∗∥2=B,ν:=μk,k−1c=BμBk−1,∥ck∗∥2=BBk−1Bk, μk−1,jc=μk,j and μk,jc=μk−1,j for j<k−1, and for i>k, μi,kc=μi,k−1−μμi,k and μi,k−1c=μi,k+νμi,kc.
Proof. For i<k−1 nothing changes. For i>k, the span of the first i−1 rows is the same set, so ci∗=bi∗; the same holds for the span V of the first k rows, so {ck−1∗,ck∗} and {bk−1∗,bk∗} are orthogonal bases of the same plane V∩span(b1,…,bk−2)⊥.
Since ck−1=bk=bk∗+μbk−1∗+(a vector of span(b1,…,bk−2)), its projection is ck−1∗=bk∗+μbk−1∗, of squared length Bk+μ2Bk−1=B, as bk∗⊥bk−1∗. Next, ck=bk−1 projects to bk−1∗ orthogonally to span(b1,…,bk−2), and then ck∗=bk−1∗−νck−1∗ with ν=⟨bk−1∗,ck−1∗⟩/B=μBk−1/B. The first k rows generate a lattice whose Gram determinant ∏i≤kBi does not depend on the order of the rows, so B⋅∥ck∗∥2=Bk−1Bk. For j<k−1, μk−1,jc=⟨bk,bj∗⟩/Bj=μk,j, and likewise μk,jc=μk−1,j.
For i>k, bi has the component μi,k−1bk−1∗+μi,kbk∗ in the plane. From ck−1∗=bk∗+μbk−1∗ and ck∗=bk−1∗−νck−1∗ we get bk−1∗=ck∗+νck−1∗ and bk∗=(1−μν)ck−1∗−μck∗. Substituting,
μi,k−1bk−1∗+μi,kbk∗=(μi,k+ν(μi,k−1−μμi,k))ck−1∗+(μi,k−1−μμi,k)ck∗, which gives the two formulas. □
By Lemmas 2 and 3 and the correctness of the Gram-Schmidt step of line L1, the stored B and μ are always the Gram-Schmidt data of the current rows.
Lemma 4 (loop invariant). Each time line L3 is reached, 2≤k≤n+1, and b1,…,bk−1 satisfy the two conditions of a δ-LLL-reduced basis among themselves: ∣μij∣≤1/2 for j<i≤k−1, and δBi−1≤Bi+μi,i−12Bi−1 for 2≤i≤k−1.
Proof. At the first visit k=2 and the conditions are empty. Assume the invariant at some visit with k≤n.
Case of a swap. Line L4 changes only bk and row k of μ. The swap changes rows k−1 and k and the coefficients in rows ≥k−1, and leaves b1,…,bk−2, their μij and their Bi unchanged (Lemma 3). The new value k′=max(2,k−1) needs the conditions for the first k′−1≤k−2 rows, which held before.
Case of a pass. By Lemma 2, after line L4 and the loop of line L9 (which runs j=k−2,…,1 in that order), ∣μkj∣≤1/2 for all j<k: each REDUCE(k,j) fixes μkj and later calls, with smaller j, change only μki with i<j. REDUCE does not change any Bi, nor μk,k−1 when j<k−1, so the Lovász condition at k, checked at line L5, still holds. Rows 1,…,k−1 are unchanged. So the invariant holds for k+1. □
Theorem 1 (correctness). If the algorithm stops, it returns a δ-LLL-reduced basis of L.
Proof. It stops when line L3 sees k=n+1. By Lemma 4 all n rows are then reduced, and by Lemma 1 they are a basis of L. □
Lemma 5 (the potential). Let di=∏j≤iBj for 0≤i≤n and D=∏i=1n−1di. Then REDUCE does not change D, and a swap multiplies D by a factor less than δ. If the input rows are integer vectors, every di is a positive integer at all times.
Proof. REDUCE does not change any Bj (Lemma 2). A swap at k replaces Bk−1,Bk by B,Bk−1Bk/B, so di is unchanged for i=k−1, and dk−1 is multiplied by B/Bk−1. The swap is done only when B=Bk+μ2Bk−1<δBk−1. Finally, di is the Gram determinant det(Gi), Gi=(⟨bs,bt⟩)s,t≤i, of the first i rows; it is positive since they are independent, and an integer when the rows are integer vectors. □
Theorem 2 (termination and number of swaps). Let the input be an integer basis with ∥bi∥2≤X for all i, X≥2. The number s of swaps satisfies s≤log1/δD0≤2n(n−1)log1/δX, where D0 is the value of D for the input, and the loop runs at most n−1+2s times. For a rational input the algorithm also stops.
Proof. By Lemma 5, after s swaps 1≤D≤δsD0, so s≤log1/δD0. At the input, Bj=∥bj∗∥2≤∥bj∥2≤X, so di≤Xi and D0≤X1+2+⋯+(n−1)=Xn(n−1)/2. Each loop iteration is a pass, which adds 1 to k, or a swap, which subtracts at most 1. k goes from 2 to n+1, so the number p of passes satisfies p−s≤n−1, that is p≤n−1+s, and the number of iterations is p+s≤n−1+2s.
For a rational input, let c be a positive integer such that cbi∈Zm for all i. On the rows cbi, the μij are the same and the Bi are multiplied by c2, so every rounding of REDUCE and every test of line L5, which is homogeneous in the Bi, gives the same result. So the run on b is the run on cb divided by c, and it stops. □
Theorem 3 (arithmetic cost). For an integer basis with ∥bi∥2≤X, m≥n and fixed δ, the algorithm uses O(n2m+n3mlogX) arithmetic operations, and O(n2m) if the input is already δ-LLL-reduced.
Proof. Line L1 is Gram-Schmidt with O(n2m) operations. One REDUCE costs O(m+n): m for the row and at most n for the coefficients. Lines L4 to L7 cost O(m+n), since the swap formulas touch O(n) coefficients. Line L9 does at most n REDUCE calls, O(n(m+n))=O(nm). By Theorem 2 there are O(n+s) iterations with s=O(n2logX), so the total is O(n2m+(n+n2logX)nm)=O(n3mlogX) for X≥2. If the input is reduced, no test of line L5 fails: a REDUCE(k,k−1) on ∣μk,k−1∣≤1/2 finds q=0, or q=1 when μk,k−1=1/2 exactly, and then the new value is −1/2; in both cases μk,k−12 and all Bi are unchanged, so the Lovász condition at k still holds. So s=0 and the cost is O(n2m). ■
The bound on the sizes of the numbers, O(nlogX) binary digits for the integers di, djμij and the entries of the rows, is proved in Section 1 of Lenstra, Lenstra and Lovász (1982); it turns Theorem 3 into the bit bound on the page.