Algorithm Search⌘K

Proofs: Kannan-Bachem algorithm

These are the human proofs of Kannan-Bachem algorithm, at full length.

The row-insertion Kannan-Bachem algorithm returns the Hermite normal form full

This proof shows: correctness, termination.

Let AA be an m×nm \times n integer matrix with rows a1,…,ama_1, \dots, a_m. For a list of integer vectors SS, let L(S)L(S) be the lattice of their integer combinations. For a nonzero vector ww, lead⁡(w)\operatorname{lead}(w) is the index of its first nonzero entry among the first nn entries. As in the implementation, every row carries mm extra entries, so the algorithm works on the rows of [A∣Im][A \mid I_m]; all statements about "HH" refer to the first nn entries, and lead⁡\operatorname{lead} ignores the extra ones.

A list of nonzero rows h1,…,hsh_1, \dots, h_s with ck=lead⁡(hk)c_k = \operatorname{lead}(h_k) is in Hermite form if c1<c2<⋯<csc_1 < c_2 < \cdots < c_s, hk[ck]>0h_k[c_k] > 0 for all kk, and 0≤hl[ck]<hk[ck]0 \le h_l[c_k] < h_k[c_k] for all l<kl < k.

Claim. KANNAN-BACHEM(A)(A) stops, and returns HH and UU with UU unimodular, UA=HUA = H, and HH the Hermite normal form of AA: its nonzero rows are in Hermite form, they are followed by zero rows, and their number is the rank of AA.

Termination. The loop of line L2 has mm steps. In each, the loop of line L4 has at most ss steps, where s≤ms \le m is the number of stored rows, and the loops of lines L11 and L12 have at most s2s^2 steps.

Unimodular steps. Every change to the rows of [A∣Im][A \mid I_m] is one of the following, each of which is an invertible integer row operation whose inverse is also integral:

  • Line L8 replaces the pair (h,w)(h, w) with (xh+yw, (hc/g) w−(wc/g) h)(x h + y w,\ (h_c / g)\, w - (w_c / g)\, h), where hc=h[c]h_c = h[c], wc=w[c]w_c = w[c] and g=xhc+ywc=gcd⁡(hc,wc)>0g = x h_c + y w_c = \gcd(h_c, w_c) > 0. Its matrix (xy−wc/ghc/g)\begin{pmatrix} x & y \\ -w_c/g & h_c/g \end{pmatrix} has integer entries and determinant (xhc+ywc)/g=1(x h_c + y w_c)/g = 1.
  • Line L10 negates a row (determinant −1-1).
  • Line L13 subtracts an integer multiple of one row from another (determinant 11).

The stored rows, the rows set aside as zero, and the rows not yet inserted are always the rows of V[A∣Im]V [A \mid I_m] for a unimodular VV, up to their order. At the end, UU lists the extra parts of the rows in the output order, and the first nn entries give HH, so H=UAH = UA and UU is unimodular (a permutation of the rows of VV). In particular L(H)=L(A)L(H) = L(A).

Invariant. Before step tt of line L2, the stored rows h1,…,hsh_1, \dots, h_s are in Hermite form and L(h1,…,hs)=L(a1,…,at−1)L(h_1, \dots, h_s) = L(a_1, \dots, a_{t-1}).

Before step 11 there are no stored rows. Assume the invariant before step tt, and let w=atw = a_t.

The loop of line L4. We show that at the start of the iteration with index kk, (i) lead⁡(w)>ck−1\operatorname{lead}(w) > c_{k-1} if w≠0w \ne 0 and k>1k > 1, (ii) the rows h1,…,hk−1h_1, \dots, h_{k-1} have leading columns c1<⋯<ck−1c_1 < \cdots < c_{k-1} with positive leading entries, and (iii) the rows hk,…,hsh_k, \dots, h_s are unchanged. This holds for k=1k = 1. If line L5 breaks, nothing changes. If lead⁡(w)>ck\operatorname{lead}(w) > c_k, the iteration changes nothing and (i) holds for k+1k + 1. If lead⁡(w)=ck=c\operatorname{lead}(w) = c_k = c, then hkh_k and ww are both zero in the columns before cc, so the new rows of line L8 are also zero there. The new hkh_k has hk[c]=xhc+ywc=g>0h_k[c] = x h_c + y w_c = g > 0, so its leading column is still ckc_k with a positive entry. The new ww has w[c]=(hcwc−wchc)/g=0w[c] = (h_c w_c - w_c h_c)/g = 0, so it is zero or has lead⁡(w)>ck\operatorname{lead}(w) > c_k.

Insertion. When the loop ends at index kk (by the break, or with k=s+1k = s + 1), either w=0w = 0, or ck−1<lead⁡(w)c_{k-1} < \operatorname{lead}(w) and, if k≤sk \le s, lead⁡(w)<ck\operatorname{lead}(w) < c_k: the break happens at the first kk with lead⁡(w)<ck\operatorname{lead}(w) < c_k, and lead⁡(w)≠cj\operatorname{lead}(w) \ne c_j for all jj since an equality would have led to a gcd step. If w≠0w \ne 0, line L10 makes its leading entry positive and inserts it at position kk. In both cases the stored rows now have strictly increasing leading columns and positive leading entries, and they span L(a1,…,at)L(a_1, \dots, a_t), since the unimodular steps preserve the lattice spanned by the stored rows together with ww, and a zero ww adds nothing.

Reduction. Renumber the stored rows h1,…,hsh_1, \dots, h_s with pivots pk=hk[ck]>0p_k = h_k[c_k] > 0. Lines L11 to L13 treat l=s−1,…,1l = s - 1, \dots, 1. For fixed ll and kk, line L13 sets hl←hl−⌊hl[ck]/pk⌋hkh_l \leftarrow h_l - \lfloor h_l[c_k] / p_k \rfloor h_k, which gives 0≤hl[ck]<pk0 \le h_l[c_k] < p_k. Since hkh_k is zero in the columns before ckc_k, this changes hlh_l only in the columns ckc_k and later, so it does not undo the reductions at cl+1,…,ck−1c_{l+1}, \dots, c_{k-1}, which were done earlier for this ll, and it does not change the leading entry of hlh_l, since cl<ckc_l < c_k. It does not change any row other than hlh_l, so the rows hl+1,…,hsh_{l+1}, \dots, h_s treated before stay reduced. After the loop, 0≤hl[ck]<pk0 \le h_l[c_k] < p_k for all l<kl < k, so the stored rows are in Hermite form. The steps are unimodular, so the lattice is still L(a1,…,at)L(a_1, \dots, a_t). This proves the invariant for t+1t + 1.

End. After step mm, the stored rows h1,…,hsh_1, \dots, h_s are in Hermite form and span L(A)L(A). Rows in echelon form with nonzero leading entries are linearly independent, so s=dim⁡QQL(A)=rank⁡As = \dim_{\mathbb{Q}} \mathbb{Q} L(A) = \operatorname{rank} A. Every zero ww was set aside, which gives the m−sm - s zero rows at the bottom of HH. A matrix whose nonzero rows are in Hermite form and whose zero rows come last is, by definition, in Hermite normal form, and it is the Hermite normal form of AA because H=UAH = UA with UU unimodular. By the uniqueness theorem for the Hermite normal form, it does not depend on the order of the steps. ■\blacksquare

Remark (sizes). The invariant says that after each insertion the stored rows are the Hermite normal form of a1,…,ata_1, \dots, a_t. If the entries of AA are at most B≥1B \ge 1 in absolute value and a1,…,ata_1, \dots, a_t have rank rtr_t, every entry of that form is at most rt⋅rtrt/2Brtr_t \cdot r_t^{r_t/2} B^{r_t}. Indeed, let PP be the pivot columns and ASA_S a set of rtr_t independent rows among a1,…,ata_1, \dots, a_t; the rt×rtr_t \times r_t block AS[P]A_S[P] is nonsingular, with determinant dd. Each pivot is at most ∏kpk\prod_k p_k, which divides dd, since L(AS)⊆L(H)L(A_S) \subseteq L(H). Each entry of the form in a column jj is ∑kh[ck] zkj\sum_k h[c_k]\, z_{kj}, where zkj=det⁡AS[P,k→j]/dz_{kj} = \det A_S[P, k \to j] / d by Cramer's rule, so it is at most ∑kpk∣det⁡AS[P,k→j]∣/∣d∣≤rt⋅rtrt/2Brt\sum_k p_k |\det A_S[P, k \to j]| / |d| \le r_t \cdot r_t^{r_t/2} B^{r_t} by the Hadamard bound. During one insertion, line L8 combines ww with a row hkh_k of the previous form, not yet changed by (iii), and line L13 combines hlh_l with a row hkh_k, k>lk > l, that is already a row of the new form, since the reduction goes from the bottom up. With the Euclidean cofactors ∣x∣≤∣wc∣/g|x| \le |w_c|/g and ∣y∣≤∣hc∣/g|y| \le |h_c|/g, each such step multiplies the largest absolute value of the changed row by at most 2S+12S + 1, where SS is the bound above. So the lengths of the numbers in the first nn entries grow by O(log⁡S)O(\log S) per step, with O(s2)O(s^2) steps per insertion, and stay polynomial in mm, nn and the length of BB. The tests check the bound on the final form. The argument does not bound the extra entries, the transform UU, when AA has dependent rows; for a nonsingular square AA, U=HA−1U = H A^{-1} is unique and bounded by Cramer's rule.

Back to Kannan-Bachem algorithm