Hermite and Smith normal forms
- Cost
- Polynomial in the dimension and the bit size for all algorithms except the classical one; computations modulo keep entries below and cost operations on integers of bits for an matrix.
The Hermite normal form (HNF) is to integer matrices what the reduced row echelon form is to matrices over a field: a canonical form under the row operations that are invertible over . The Smith normal form (SNF) allows column operations as well and describes a matrix up to equivalence; it gives the structure of finitely generated abelian groups. Both are computed by elimination with gcds, and the main difficulty is the growth of the entries, which the algorithms below control in different ways. There are no generic gr_mat versions of these algorithms; they are specific to (fmpz_mat). Over the Howell form plays the role of the HNF (Howell form).
Definitions#
A matrix is unimodular if , equivalently if is an integer matrix. Multiplying on the left by performs a sequence of elementary row operations over : exchanging rows, negating a row, adding an integer multiple of a row to another. The rows of and of generate the same lattice .
Definition 1. An integer matrix of rank is in Hermite normal form if its first rows are nonzero and the others zero, the first nonzero entry of row is positive and lies in column with , and for all .
Theorem 2. For every integer matrix there is exactly one in Hermite normal form with for a unimodular . Two matrices of the same shape have the same Hermite normal form if and only if their rows generate the same lattice.
Proof. Existence follows from the algorithms below. For uniqueness, let and be in Hermite normal form with the same row lattice. The pivot columns are determined by the lattice ( is the least such that the lattice vectors vanishing in columns before have rank ), so they agree, and the pivots agree since is the positive generator of the ideal of values in column of lattice vectors vanishing before . If , let be the last row in which they differ; then is a lattice vector vanishing up to column , so it is a combination of rows of ; its first nonzero entry is in some pivot column with and is then a multiple of , which contradicts the reduction .
For a nonsingular matrix, is upper triangular and .
Theorem 3 (Smith normal form). For every integer matrix of rank there are unimodular , with , and . The are unique: is the gcd of all minors of .
Proof. Existence follows from the algorithms below. The gcd of the minors is invariant under multiplication by unimodular matrices, since by the Cauchy–Binet formula the minors of are integer combinations of those of and conversely. For the diagonal form the gcd is because of the divisibility chain.
The are the elementary divisors (or invariant factors) of , and . The largest one, , is the exponent of the torsion part.
Hermite normal form algorithms#
Classical elimination#
fmpz_mat_hnf_classical processes the columns from left to right. In the current column it repeatedly picks the nonzero entry of least absolute value at or below the current row, moves it into place and reduces the entries below it with integer division, until they are zero; then it makes the pivot positive and reduces the entries above it [Coh1996, Algorithm 2.4.4]. fmpz_mat_hnf_xgcd instead combines two rows with the cofactors of by the unimodular transformation
which clears an entry in one step [Coh1996, Algorithm 2.4.5]. Both are fast for small matrices, but the entries of the rows not yet processed can grow exponentially with the dimension [HM1991].
Kannan–Bachem#
fmpz_mat_hnf_minors [KanBac1979] brings the leading principal submatrix into Hermite normal form for : row is eliminated against rows with the gcd transformation above, and then the entries above the new diagonal are reduced modulo the pivots. Because all rows processed so far are kept reduced, Kannan and Bachem prove that every intermediate entry has a number of bits polynomial in and in the size of , which gives the first polynomial-time Hermite normal form algorithm. FLINT's version requires to have full column rank; it brings a zero diagonal entry into place by exchanging with a later row. fmpz_mat_hnf_minors_transform applies the same operations to an identity matrix to obtain .
Computing modulo a determinant#
The entries of an HNF are bounded by its pivots, so it is natural to compute modulo a multiple of them.
Lemma 4. Let be a lattice of rank with elementary divisors . Then , and hence for every multiple of , in particular for .
Proof. The group is annihilated by .
Hence is generated by the rows of together with the rows of , and all row operations can be done modulo , which bounds the entries by . fmpz_mat_hnf_modular is the algorithm of Domich, Kannan and Trotter [DomKanTro1987; Coh1996, Algorithm 2.4.8]: it eliminates column with gcd transformations, reducing modulo the current , puts on the diagonal, and divides by the pivot for the next column, since the lattice generated by the remaining columns has determinant . fmpz_mat_hnf_modular_eldiv uses the weaker requirement : it computes the strong echelon form modulo (nmod_mat_strong_echelon_form or fmpz_mat_strong_echelon_form_mod), which by the result of Fieker and Hofmann [FieHof2014] is the Hermite normal form of the lattice reduced modulo , and replaces zero diagonal entries, which stand for pivots equal to , by . Hafner and McCurley [HM1991] and Storjohann and Labahn [SL1996] give asymptotically faster modular algorithms based on matrix multiplication.
Pernet–Stein#
For a nonsingular square matrix, can be huge, but for random matrices the lattice generated by of the rows together with a combination of the last two has a small determinant. Pernet and Stein [PernetStein2010], after Micciancio and Warinschi [MW2001], exploit this. For an matrix of rank , fmpz_mat_hnf_pernet_stein does the following.
- Find the pivot rows and columns modulo a random prime; let be the first pivot rows and , the next two, all restricted to the first pivot columns.
- Double determinant: compute and , both from one solution of a linear system over (
fmpq_mat_solve_fmpz_mat) and a few modular determinants. Let . - Replace the pair by ; the resulting matrix has determinant , which is small with high probability for random input. Compute its HNF modulo (
fmpz_mat_hnf_modular), or recursively if is large. - Add columns: the HNF of is with unimodular, so the HNF of the same rows on all columns is times these rows. The other columns are obtained by solving a linear system with .
- Add rows: insert the remaining rows of , including the original rows and , one at a time into the HNF by gcd elimination and reduction.
- If the pivot structure obtained differs from the one predicted modulo the prime, the prime was bad: restart.
The expected cost for random matrices is dominated by linear system solving, bit operations. FLINT falls back to fmpz_mat_hnf_minors when has full column rank and fewer than about 35 to 52 columns, and when the rank is too small for the decomposition. Faster algorithms that certify unimodularity and handle structured input better are given in [PauSto2013].
Choice and transformation#
fmpz_mat_hnf calls fmpz_mat_hnf_classical for matrices with few rows (fewer than 52 rows for entries of 1 or 2 bits, decreasing to 2 rows for entries above 512 bits) and fmpz_mat_hnf_pernet_stein otherwise. fmpz_mat_hnf_transform computes with fmpz_mat_hnf_minors_transform for matrices of full column rank, and otherwise as the right block of the HNF of : that matrix has full row rank, so its HNF is with unimodular.
Smith normal form algorithms#
Elimination#
fmpz_mat_snf_kannan_bachem [KanBac1979] alternately clears the first column with row gcd transformations and the first row with column gcd transformations until both are zero apart from the corner, and repeats if the corner does not divide the remaining entries (adding a row to the first row and continuing). Then it proceeds with the submatrix. fmpz_mat_snf_iliopoulos [Iliopoulos1989] does the same eliminations modulo a multiple of the largest elementary divisor of a nonsingular square matrix, which by Lemma 4 does not change the result and bounds the entries by ; the diagonal is finally normalised by fmpz_mat_snf_diagonal, which replaces pairs of diagonal entries by their gcd and lcm.
Iterated Hermite forms#
fmpz_mat_snf uses a different approach: it alternates the row HNF of the matrix and the row HNF of its transpose (that is, the column HNF) until the matrix is diagonal. Each round is a unimodular transformation, and the leading entries can only become divisors of what they were; Kannan and Bachem show that the number of rounds is bounded by a polynomial in the dimension and the size of the entries [KanBac1979]. The diagonal is then turned into a divisibility chain by gcd and lcm steps. Since fmpz_mat_hnf is fast (Pernet–Stein for large matrices), this inherits its performance; two or three rounds suffice for typical matrices. fmpz_mat_snf_transform does the same with fmpz_mat_hnf_transform and accumulates and ; the final gcd steps are done with extended gcds on pairs of rows and columns.
Elementary divisors by p-adic ranks#
When only the elementary divisors are needed and their prime factors are known, Lübeck's method [Lüb2002] computes the valuations from ranks modulo primes. Let be an basis of the row lattice (the nonzero rows of the HNF), with elementary divisors .
Proposition 5. Let be a prime, let be a basis of the left kernel of modulo (so ), and let be obtained from by replacing, for each , a row in which has entry 1 (and the other have entry 0) by . Then is a basis of , and the elementary divisors of are for the indices with and for the others.
Proof. Choose bases in which (Smith form). Then and with if and otherwise; in particular , so . The vectors span modulo , so the rows of generate , and the replaced rows are recovered as minus the other terms of , so nothing is lost; has rows, so it is a basis.
Iterating until has full rank modulo , the nullities count the elementary divisors with , which determines all valuations. fmpz_mat_elementary_divisors computes the HNF, factors its pivots (whose product is divisible by every prime dividing an ), applies this for each prime, and falls back to fmpz_mat_snf when a pivot is too large to factor or has a prime factor beyond a word. Faster Smith form algorithms based on linear system solving are given in [Gie1995; EGV2000].
Use in FLINT#
| Task | Functions |
|---|---|
| HNF, default | fmpz_mat_hnf |
| HNF, specific algorithm | fmpz_mat_hnf_classical, fmpz_mat_hnf_xgcd, fmpz_mat_hnf_minors, fmpz_mat_hnf_modular, fmpz_mat_hnf_modular_eldiv, fmpz_mat_hnf_pernet_stein |
| HNF with transformation | fmpz_mat_hnf_transform, fmpz_mat_hnf_minors_transform |
| SNF | fmpz_mat_snf, fmpz_mat_snf_kannan_bachem, fmpz_mat_snf_iliopoulos, fmpz_mat_snf_diagonal, fmpz_mat_snf_transform |
| Elementary divisors | fmpz_mat_elementary_divisors |
| Checks | fmpz_mat_is_in_hnf, fmpz_mat_is_in_snf |
| Modulo | fmpz_mat_howell_form_mod, fmpz_mat_strong_echelon_form_mod, nmod_mat_howell_form, nmod_mat_strong_echelon_form |
Referenced from#
References#
- [Coh1996] Cohen, Henri : A course in computational algebraic number theory, Springer, 1996
- [HM1991] J. L. Hafner and K. S. McCurley, "Asymptotically fast triangularization of matrices over rings", SIAM Journal on Computing 20:6 (1991), 1068–1083. https://doi.org/10.1137/0220067
- [KanBac1979] Kannan, R. and Bachem, A. : Polynomial algorithms for computing and the Smith and Hermite normal forms of an integer matrix, SIAM J. Computation vol. 9 (1979) 499–507
- [DomKanTro1987] Domich, P. D. and Kannan, R. and Trotter, L. E. Jr. : Hermite Normal Form Computation Using Modulo Determinant Arithmetic, Math. Operations Res. (12) 1987 50-59
- [FieHof2014] Fieker C. and Hofmann T.: "Computing in quotients of rings of integers" LMS Journal of Computation and Mathematics, 17(A), 349-365
- [SL1996] A. Storjohann and G. Labahn, "Asymptotically fast computation of Hermite normal forms of integer matrices", Proceedings of the 1996 International Symposium on Symbolic and Algebraic Computation (ISSAC 1996), 259–266. https://doi.org/10.1145/236869.237083
- [PernetStein2010] Pernet, C. and Stein, W. : Fast computation of Hermite normal forms of random integer matrices ,J. Number Theory 130:17 (2010) 1675–1683
- [MW2001] D. Micciancio and B. Warinschi, "A linear space algorithm for computing the Hermite normal form", Proceedings of the 2001 International Symposium on Symbolic and Algebraic Computation (ISSAC 2001), 231–236. https://doi.org/10.1145/384101.384133
- [PauSto2013] C. Pauderis and A. Storjohann, "Computing the invariant structure of integer matrices: fast algorithms into practice", Proceedings of the 2013 International Symposium on Symbolic and Algebraic Computation (ISSAC 2013), 307–314. https://doi.org/10.1145/2465506.2465955
- [Iliopoulos1989] Iliopoulos, C. S., Worst-Case Complexity Bounds on Algorithms for Computing the Canonical Structure of Finite Abelian Groups and the Hermite and Smith Normal Forms of an Integer Matrix : SIAM J. Computation 18:4 (1989) 658
- [Lüb2002] F. Lübeck, "On the computation of elementary divisors of integer matrices", Journal of Symbolic Computation 33:1 (2002), 57–65. https://doi.org/10.1006/jsco.2001.0492
- [Gie1995] M. Giesbrecht, "Fast computation of the Smith normal form of an integer matrix", Proceedings of the 1995 International Symposium on Symbolic and Algebraic Computation (ISSAC 1995), 110–118. https://doi.org/10.1145/220346.220361
- [EGV2000] W. Eberly, M. Giesbrecht and G. Villard, "On computing the determinant and Smith form of an integer matrix", Proceedings of the 41st Annual Symposium on Foundations of Computer Science (FOCS 2000), 675–685. https://doi.org/10.1109/SFCS.2000.892335
The FLINT team, “Hermite and Smith normal forms,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/linear-algebra/hermite-smith.html (generated 2026-11-02).
@misc{flint-doc-algorithms-linear-algebra-hermite-smith,
author = {{The FLINT team}},
title = {{Hermite and Smith normal forms}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/linear-algebra/hermite-smith.html},
note = {Generated 2026-11-02}
}