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 be an integer matrix with rows . For a list of integer vectors , let be the lattice of their integer combinations. For a nonzero vector , is the index of its first nonzero entry among the first entries. As in the implementation, every row carries extra entries, so the algorithm works on the rows of ; all statements about "" refer to the first entries, and ignores the extra ones.
A list of nonzero rows with is in Hermite form if , for all , and for all .
Claim. KANNAN-BACHEM stops, and returns and with unimodular, , and the Hermite normal form of : its nonzero rows are in Hermite form, they are followed by zero rows, and their number is the rank of .
Termination. The loop of line L2 has steps. In each, the loop of line L4 has at most steps, where is the number of stored rows, and the loops of lines L11 and L12 have at most steps.
Unimodular steps. Every change to the rows of is one of the following, each of which is an invertible integer row operation whose inverse is also integral:
- Line L8 replaces the pair with , where , and . Its matrix has integer entries and determinant .
- Line L10 negates a row (determinant ).
- Line L13 subtracts an integer multiple of one row from another (determinant ).
The stored rows, the rows set aside as zero, and the rows not yet inserted are always the rows of for a unimodular , up to their order. At the end, lists the extra parts of the rows in the output order, and the first entries give , so and is unimodular (a permutation of the rows of ). In particular .
Invariant. Before step of line L2, the stored rows are in Hermite form and .
Before step there are no stored rows. Assume the invariant before step , and let .
The loop of line L4. We show that at the start of the iteration with index , (i) if and , (ii) the rows have leading columns with positive leading entries, and (iii) the rows are unchanged. This holds for . If line L5 breaks, nothing changes. If , the iteration changes nothing and (i) holds for . If , then and are both zero in the columns before , so the new rows of line L8 are also zero there. The new has , so its leading column is still with a positive entry. The new has , so it is zero or has .
Insertion. When the loop ends at index (by the break, or with ), either , or and, if , : the break happens at the first with , and for all since an equality would have led to a gcd step. If , line L10 makes its leading entry positive and inserts it at position . In both cases the stored rows now have strictly increasing leading columns and positive leading entries, and they span , since the unimodular steps preserve the lattice spanned by the stored rows together with , and a zero adds nothing.
Reduction. Renumber the stored rows with pivots . Lines L11 to L13 treat . For fixed and , line L13 sets , which gives . Since is zero in the columns before , this changes only in the columns and later, so it does not undo the reductions at , which were done earlier for this , and it does not change the leading entry of , since . It does not change any row other than , so the rows treated before stay reduced. After the loop, for all , so the stored rows are in Hermite form. The steps are unimodular, so the lattice is still . This proves the invariant for .
End. After step , the stored rows are in Hermite form and span . Rows in echelon form with nonzero leading entries are linearly independent, so . Every zero was set aside, which gives the zero rows at the bottom of . 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 because with unimodular. By the uniqueness theorem for the Hermite normal form, it does not depend on the order of the steps.
Remark (sizes). The invariant says that after each insertion the stored rows are the Hermite normal form of . If the entries of are at most in absolute value and have rank , every entry of that form is at most . Indeed, let be the pivot columns and a set of independent rows among ; the block is nonsingular, with determinant . Each pivot is at most , which divides , since . Each entry of the form in a column is , where by Cramer's rule, so it is at most by the Hadamard bound. During one insertion, line L8 combines with a row of the previous form, not yet changed by (iii), and line L13 combines with a row , , that is already a row of the new form, since the reduction goes from the bottom up. With the Euclidean cofactors and , each such step multiplies the largest absolute value of the changed row by at most , where is the bound above. So the lengths of the numbers in the first entries grow by per step, with steps per insertion, and stay polynomial in , and the length of . The tests check the bound on the final form. The argument does not bound the extra entries, the transform , when has dependent rows; for a nonsingular square , is unique and bounded by Cramer's rule.