Algorithm Search⌘K

Proofs: LLL algorithm

These are the human proofs of LLL algorithm, at full length.

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∈Qmb_1, \ldots, b_n \in \mathbb{Q}^m and a rational δ\delta with 1/4<δ<11/4 < \delta < 1. We write bi∗b_i^* for the Gram-Schmidt vectors of the current rows, Bi=∥bi∗∥2B_i = \|b_i^*\|^2, μij=⟨bi,bj∗⟩/Bj\mu_{ij} = \langle b_i, b_j^* \rangle / B_j for j<ij < i, so that bi=bi∗+∑j<iμijbj∗b_i = b_i^* + \sum_{j < i} \mu_{ij} b_j^*, and πi\pi_i for the orthogonal projection onto span⁡(b1,…,bi−1)⊥\operatorname{span}(b_1, \ldots, b_{i-1})^\perp. The nearest integer ⌈x⌋=⌊x+1/2⌋\lceil x \rfloor = \lfloor x + 1/2 \rfloor satisfies ∣x−⌈x⌋∣≤1/2|x - \lceil x \rfloor| \le 1/2. The line numbers refer to the main block of the page.

Lemma 1 (the rows stay a basis of LL). At every moment the current rows are a basis of the input lattice LL.

Proof. REDUCE replaces bkb_k by bk−qbjb_k - q b_j with q∈Zq \in \mathbb{Z} and j≠kj \ne k, and line L6 exchanges two rows. Both are multiplications on the left by an integer matrix of determinant ±1\pm 1, whose inverse is again an integer matrix. So the new rows generate the same lattice, and they are still independent. □\square

Lemma 2 (REDUCE keeps the data correct). After REDUCE(k,j)(k, j), j<kj < k, the bi∗b_i^* and BiB_i are unchanged, the stored μ\mu equal the Gram-Schmidt coefficients of the new rows, and ∣μkj∣≤1/2|\mu_{kj}| \le 1/2.

Proof. The change −qbj-q b_j lies in span⁡(b1,…,bk−1)\operatorname{span}(b_1, \ldots, b_{k-1}), so πk(bk)\pi_k(b_k), which is bk∗b_k^*, does not change; no other row changes. Using bj=bj∗+∑i<jμjibi∗b_j = b_j^* + \sum_{i < j} \mu_{ji} b_i^*, the new bkb_k is bk∗+∑i<kμki′bi∗b_k^* + \sum_{i < k} \mu_{ki}' b_i^* with μki′=μki−qμji\mu_{ki}' = \mu_{ki} - q \mu_{ji} for i<ji < j, μkj′=μkj−q\mu_{kj}' = \mu_{kj} - q, and μki′=μki\mu_{ki}' = \mu_{ki} for j<i<kj < i < k. These are the updates of REDUCE, and ∣μkj−⌈μkj⌋∣≤1/2|\mu_{kj} - \lceil \mu_{kj} \rfloor| \le 1/2. Rows i≠ki \ne k of μ\mu are coefficients of other rows on the unchanged bi∗b_i^*, so they do not change. □\square

Lemma 3 (the swap formulas). Let cc be the rows after line L6, so ck−1=bkc_{k-1} = b_k, ck=bk−1c_k = b_{k-1} and ci=bic_i = b_i otherwise. Let μ=μk,k−1\mu = \mu_{k,k-1} and B=Bk+μ2Bk−1B = B_k + \mu^2 B_{k-1}. Then ci∗=bi∗c_i^* = b_i^* for i≠k−1,ki \ne k - 1, k, and

∥ck−1∗∥2=B,ν:=μk,k−1c=μBk−1B,∥ck∗∥2=Bk−1BkB,\|c_{k-1}^*\|^2 = B, \quad \nu := \mu^c_{k,k-1} = \frac{\mu B_{k-1}}{B}, \quad \|c_k^*\|^2 = \frac{B_{k-1} B_k}{B},

μk−1,jc=μk,j\mu^c_{k-1,j} = \mu_{k,j} and μk,jc=μk−1,j\mu^c_{k,j} = \mu_{k-1,j} for j<k−1j < k - 1, and for i>ki > k, μi,kc=μi,k−1−μμi,k\mu^c_{i,k} = \mu_{i,k-1} - \mu \mu_{i,k} and μi,k−1c=μi,k+νμi,kc\mu^c_{i,k-1} = \mu_{i,k} + \nu \mu^c_{i,k}.

Proof. For i<k−1i < k - 1 nothing changes. For i>ki > k, the span of the first i−1i - 1 rows is the same set, so ci∗=bi∗c_i^* = b_i^*; the same holds for the span VV of the first kk rows, so {ck−1∗,ck∗}\{c_{k-1}^*, c_k^*\} and {bk−1∗,bk∗}\{b_{k-1}^*, b_k^*\} are orthogonal bases of the same plane V∩span⁡(b1,…,bk−2)⊥V \cap \operatorname{span}(b_1, \ldots, b_{k-2})^\perp.

Since ck−1=bk=bk∗+μbk−1∗+(a vector of span⁡(b1,…,bk−2))c_{k-1} = b_k = b_k^* + \mu b_{k-1}^* + (\text{a vector of } \operatorname{span}(b_1, \ldots, b_{k-2})), its projection is ck−1∗=bk∗+μbk−1∗c_{k-1}^* = b_k^* + \mu b_{k-1}^*, of squared length Bk+μ2Bk−1=BB_k + \mu^2 B_{k-1} = B, as bk∗⊥bk−1∗b_k^* \perp b_{k-1}^*. Next, ck=bk−1c_k = b_{k-1} projects to bk−1∗b_{k-1}^* orthogonally to span⁡(b1,…,bk−2)\operatorname{span}(b_1, \ldots, b_{k-2}), and then ck∗=bk−1∗−νck−1∗c_k^* = b_{k-1}^* - \nu c_{k-1}^* with ν=⟨bk−1∗,ck−1∗⟩/B=μBk−1/B\nu = \langle b_{k-1}^*, c_{k-1}^* \rangle / B = \mu B_{k-1} / B. The first kk rows generate a lattice whose Gram determinant ∏i≤kBi\prod_{i \le k} B_i does not depend on the order of the rows, so B⋅∥ck∗∥2=Bk−1BkB \cdot \|c_k^*\|^2 = B_{k-1} B_k. For j<k−1j < k - 1, μk−1,jc=⟨bk,bj∗⟩/Bj=μk,j\mu^c_{k-1,j} = \langle b_k, b_j^* \rangle / B_j = \mu_{k,j}, and likewise μk,jc=μk−1,j\mu^c_{k,j} = \mu_{k-1,j}.

For i>ki > k, bib_i has the component μi,k−1bk−1∗+μi,kbk∗\mu_{i,k-1} b_{k-1}^* + \mu_{i,k} b_k^* in the plane. From ck−1∗=bk∗+μbk−1∗c_{k-1}^* = b_k^* + \mu b_{k-1}^* and ck∗=bk−1∗−νck−1∗c_k^* = b_{k-1}^* - \nu c_{k-1}^* we get bk−1∗=ck∗+νck−1∗b_{k-1}^* = c_k^* + \nu c_{k-1}^* and bk∗=(1−μν)ck−1∗−μck∗b_k^* = (1 - \mu \nu) c_{k-1}^* - \mu c_k^*. Substituting,

μi,k−1bk−1∗+μi,kbk∗=(μi,k+ν(μi,k−1−μμi,k))ck−1∗+(μi,k−1−μμi,k)ck∗,\mu_{i,k-1} b_{k-1}^* + \mu_{i,k} b_k^* = \big(\mu_{i,k} + \nu (\mu_{i,k-1} - \mu \mu_{i,k})\big) c_{k-1}^* + (\mu_{i,k-1} - \mu \mu_{i,k}) c_k^*,

which gives the two formulas. □\square

By Lemmas 2 and 3 and the correctness of the Gram-Schmidt step of line L1, the stored BB and μ\mu are always the Gram-Schmidt data of the current rows.

Lemma 4 (loop invariant). Each time line L3 is reached, 2≤k≤n+12 \le k \le n + 1, and b1,…,bk−1b_1, \ldots, b_{k-1} satisfy the two conditions of a δ\delta-LLL-reduced basis among themselves: ∣μij∣≤1/2|\mu_{ij}| \le 1/2 for j<i≤k−1j < i \le k - 1, and δBi−1≤Bi+μi,i−12Bi−1\delta B_{i-1} \le B_i + \mu_{i,i-1}^2 B_{i-1} for 2≤i≤k−12 \le i \le k - 1.

Proof. At the first visit k=2k = 2 and the conditions are empty. Assume the invariant at some visit with k≤nk \le n.

Case of a swap. Line L4 changes only bkb_k and row kk of μ\mu. The swap changes rows k−1k - 1 and kk and the coefficients in rows ≥k−1\ge k - 1, and leaves b1,…,bk−2b_1, \ldots, b_{k-2}, their μij\mu_{ij} and their BiB_i unchanged (Lemma 3). The new value k′=max⁡(2,k−1)k' = \max(2, k - 1) needs the conditions for the first k′−1≤k−2k' - 1 \le 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,…,1j = k - 2, \ldots, 1 in that order), ∣μkj∣≤1/2|\mu_{kj}| \le 1/2 for all j<kj < k: each REDUCE(k,j)(k, j) fixes μkj\mu_{kj} and later calls, with smaller jj, change only μki\mu_{ki} with i<ji < j. REDUCE does not change any BiB_i, nor μk,k−1\mu_{k,k-1} when j<k−1j < k - 1, so the Lovász condition at kk, checked at line L5, still holds. Rows 1,…,k−11, \ldots, k - 1 are unchanged. So the invariant holds for k+1k + 1. □\square

Theorem 1 (correctness). If the algorithm stops, it returns a δ\delta-LLL-reduced basis of LL.

Proof. It stops when line L3 sees k=n+1k = n + 1. By Lemma 4 all nn rows are then reduced, and by Lemma 1 they are a basis of LL. □\square

Lemma 5 (the potential). Let di=∏j≤iBjd_i = \prod_{j \le i} B_j for 0≤i≤n0 \le i \le n and D=∏i=1n−1diD = \prod_{i=1}^{n-1} d_i. Then REDUCE does not change DD, and a swap multiplies DD by a factor less than δ\delta. If the input rows are integer vectors, every did_i is a positive integer at all times.

Proof. REDUCE does not change any BjB_j (Lemma 2). A swap at kk replaces Bk−1,BkB_{k-1}, B_k by B,Bk−1Bk/BB, B_{k-1} B_k / B, so did_i is unchanged for i≠k−1i \ne k - 1, and dk−1d_{k-1} is multiplied by B/Bk−1B / B_{k-1}. The swap is done only when B=Bk+μ2Bk−1<δBk−1B = B_k + \mu^2 B_{k-1} < \delta B_{k-1}. Finally, did_i is the Gram determinant det⁡(Gi)\det(G_i), Gi=(⟨bs,bt⟩)s,t≤iG_i = (\langle b_s, b_t \rangle)_{s,t \le i}, of the first ii rows; it is positive since they are independent, and an integer when the rows are integer vectors. □\square

Theorem 2 (termination and number of swaps). Let the input be an integer basis with ∥bi∥2≤X\|b_i\|^2 \le X for all ii, X≥2X \ge 2. The number ss of swaps satisfies s≤log⁡1/δD0≤n(n−1)2log⁡1/δXs \le \log_{1/\delta} D_0 \le \frac{n (n - 1)}{2} \log_{1/\delta} X, where D0D_0 is the value of DD for the input, and the loop runs at most n−1+2sn - 1 + 2s times. For a rational input the algorithm also stops.

Proof. By Lemma 5, after ss swaps 1≤D≤δsD01 \le D \le \delta^s D_0, so s≤log⁡1/δD0s \le \log_{1/\delta} D_0. At the input, Bj=∥bj∗∥2≤∥bj∥2≤XB_j = \|b_j^*\|^2 \le \|b_j\|^2 \le X, so di≤Xid_i \le X^i and D0≤X1+2+⋯+(n−1)=Xn(n−1)/2D_0 \le X^{1 + 2 + \cdots + (n - 1)} = X^{n(n-1)/2}. Each loop iteration is a pass, which adds 1 to kk, or a swap, which subtracts at most 1. kk goes from 2 to n+1n + 1, so the number pp of passes satisfies p−s≤n−1p - s \le n - 1, that is p≤n−1+sp \le n - 1 + s, and the number of iterations is p+s≤n−1+2sp + s \le n - 1 + 2s.

For a rational input, let cc be a positive integer such that cbi∈Zmc b_i \in \mathbb{Z}^m for all ii. On the rows cbic b_i, the μij\mu_{ij} are the same and the BiB_i are multiplied by c2c^2, so every rounding of REDUCE and every test of line L5, which is homogeneous in the BiB_i, gives the same result. So the run on bb is the run on cbc b divided by cc, and it stops. □\square

Theorem 3 (arithmetic cost). For an integer basis with ∥bi∥2≤X\|b_i\|^2 \le X, m≥nm \ge n and fixed δ\delta, the algorithm uses O(n2m+n3mlog⁡X)O(n^2 m + n^3 m \log X) arithmetic operations, and O(n2m)O(n^2 m) if the input is already δ\delta-LLL-reduced.

Proof. Line L1 is Gram-Schmidt with O(n2m)O(n^2 m) operations. One REDUCE costs O(m+n)O(m + n): mm for the row and at most nn for the coefficients. Lines L4 to L7 cost O(m+n)O(m + n), since the swap formulas touch O(n)O(n) coefficients. Line L9 does at most nn REDUCE calls, O(n(m+n))=O(nm)O(n (m + n)) = O(n m). By Theorem 2 there are O(n+s)O(n + s) iterations with s=O(n2log⁡X)s = O(n^2 \log X), so the total is O(n2m+(n+n2log⁡X)nm)=O(n3mlog⁡X)O(n^2 m + (n + n^2 \log X) n m) = O(n^3 m \log X) for X≥2X \ge 2. If the input is reduced, no test of line L5 fails: a REDUCE(k,k−1)(k, k - 1) on ∣μk,k−1∣≤1/2|\mu_{k,k-1}| \le 1/2 finds q=0q = 0, or q=1q = 1 when μk,k−1=1/2\mu_{k,k-1} = 1/2 exactly, and then the new value is −1/2-1/2; in both cases μk,k−12\mu_{k,k-1}^2 and all BiB_i are unchanged, so the Lovász condition at kk still holds. So s=0s = 0 and the cost is O(n2m)O(n^2 m). ■\blacksquare

The bound on the sizes of the numbers, O(nlog⁡X)O(n \log X) binary digits for the integers did_i, djμijd_j \mu_{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.

Back to LLL algorithm