Exact arithmetic, and what it costs instead

Every entry under the determinant

The Hermite form's swell was put down to its transform — the record of how the answer was reached — while the form's own entries stayed bounded. Instrumented separately, the form's intermediates swell exactly as much: 3,371 bits against the transform's 3,366 for a random 48 × 48 matrix whose determinant has 219. Carried out modulo the determinant instead, every entry stays within the determinant's width, the answer is identical on every matrix to n = 80, and it is almost always the identity with the whole determinant in its last pivot and last column. What the bound does not buy is speed: counted in bit operations the modular route does more work until just past n = 72, because its steps multiply numbers the determinant's size where plain elimination multiplies wide numbers by small quotients.

Worth reading first: What a determinant does not determine · The number that decides nothing · An answer with no error in it.

What a determinant does not determine computed the two normal forms of an integer matrix — the Smith form’s diagonal of invariant factors, and the Hermite form, upper triangular with every entry reduced modulo the pivot below it — and was candid about its routines: they “make no attempt to control the growth that a modular or a Hermite-first approach would”, so every figure stopped at six by six. It also said where the Hermite form’s growth comes from: “The entries of the Hermite form itself are bounded, because each is reduced modulo a pivot. The transform is not … It is not the fractions that grow — it is the coefficients of a combination, and any algorithm that reports how it reached its answer pays for the report.”

Both remarks can be tested once the routine is instrumented and the modular approach is built. The first one’s promise holds completely, and costs more than it saves at every size the earlier essay could have afforded. The second puts the growth in the wrong place.

Two routes to one form

The plain route is the earlier essay’s: integer row operations only, each column reduced to a single nonzero by repeated Euclidean steps, then the entries above each pivot reduced modulo it. It is instrumented here to record two widths separately at every step — the widest entry of the matrix being reduced, and the widest entry of the transform UU with UA=HUA = H that it carries along.

The modular route rests on one fact about lattices. If AA is square and nonsingular with D=∣det⁡A∣D = |\det A|, then every vector DejD e_j is an integer combination of AA’s rows — the adjugate gives the coefficients — so the lattice AA’s rows generate is also generated by those rows together with DID I. Adding any multiple of DejD e_j to a row stays in the lattice, which means every entry can be reduced modulo DD at every step. At column cc the route adds DecD e_c to the remaining rows, combines their column-cc entries into one pivot by extended-gcd steps, each a unimodular two-by-two transformation, reduces everything else modulo DD, and finally reduces above the pivots as the plain route does.

The determinant comes first, computed exactly by fraction-free elimination, whose intermediates every intermediate is a minor showed are bounded by Hadamard’s inequality. The matrices are random, with entries from −9-9 to 99 to n=80n = 80, and from −999-999 to 999999 to n=32n = 32.

Four by four, by hand

The smallest case shows everything. Take the four-by-four matrix with rows (8,6,4,−8)(8, 6, 4, -8), (−8,−8,−5,2)(-8, -8, -5, 2), (−7,9,2,1)(-7, 9, 2, 1) and (−6,7,8,−1)(-6, 7, 8, -1) — one of the random matrices, with nothing special about it. Its determinant is 5,174, a thirteen-bit number. Its Hermite form is the identity in its first three columns, with a last column of 1,784, 4,565, 1,224 and 5,174: three residues and the determinant. Every row of the answer says that one coordinate, taken with a multiple of the last, lies in the lattice — and the lattice is every integer vector whose coordinates satisfy a single congruence modulo 5,174.

Plain elimination reaches that answer through numbers of six bits after the first column, ten after the second and twenty after the third — a million, beside an answer whose largest entry is five thousand — before the last column’s reductions bring everything back under the pivots. The modular route works with residues modulo 5,174 throughout, so no stored number is wider than thirteen bits and no product before a reduction wider than twenty-six. The two routes end at the same four rows.

Identical answers, one of them never wide

The figure at the top of the page is the whole measurement of size.

The two routes return the same Hermite form, entry for entry, on every matrix, and its pivots multiply to ∣det⁡A∣|\det A|. Modulo the determinant every stored entry fits in the determinant’s own width — 13 bits at n=4n = 4, 60 at 16, 219 at 48, 390 at 80 — and every product formed before a reduction fits in twice that. The plain route’s widest intermediate is 21 bits at n=4n = 4, 307 at 16, 3,371 at 48 and 13,835 at 80. On the wider entries the gap is the same shape: 167 against 899 bits at n=16n = 16, 347 against 3,727 at 32.

The widest entry after each column of the Hermite normal form of one random 24 × 24 matrix: plain elimination's form and transform, and the route modulo the determinantPlain form after each column: 7, 11, 13, 19, 31, 41, 51, 62, 84, 109, 128, 158, 185, 221, 259, 293, 329, 374, 428, 489, 540, 604, 696, 98 bits. Modular stored: 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98 bits. The determinant has 98 bits.n = 24, bitsplain, widest696modular, widest98determinant980481216202428320200400600800100012001400columnwidest entry, bitsred: plain (dashed: its transform); blue: modulo the determinant; purple: |det A|the swell is in the elimination
Fig. 1 One random 24 × 24 matrix, column by column: the plain route’s widest entry (red) and the modular route’s (blue), with the determinant’s width. Drag the size from 16 to 32.

Followed column by column the two routes look nothing alike. The plain route’s widest entry climbs steadily through the elimination, from 7 bits after the first column to 696 after the twenty-third, and falls back to 98 at the last, when the final reductions bring every entry under its pivot. The modular route is at the determinant’s width, 98 bits, from the first column and never leaves it. The plain route’s swell is not a peak at one awkward step. It is the whole elimination, growing the remaining rows column after column until the end discards it.

The swell is the elimination’s, not the report’s

The dashed red line in that figure, the transform’s width, is invisible because it lies on the solid one. At n=24n = 24 the form’s widest intermediate is 696 bits and the transform’s 693; at 48, 3,371 and 3,366; at 80, 13,835 and 13,832. At every size and on both families the form is within five per cent of the transform and usually a few bits wider.

So the earlier essay’s account of where the growth lives does not survive being measured. It is true that the finished form’s entries are bounded — every entry above a pivot is reduced modulo it — and true that the transform grows. But the form’s intermediates grow just as much, because the same Euclidean steps that build up the transform’s coefficients are applied to the rows being reduced. An algorithm that computed the Hermite form and threw the transform away would save memory for one matrix and save nothing in the width of the numbers it handles. The growth belongs to the elimination, and the report — the transform — merely records it.

The plain route's widest intermediate divided by the determinant's width, in bits, against nentries to ±9, n = 4: 1.6; entries to ±9, n = 8: 2.8; entries to ±9, n = 12: 3.4; entries to ±9, n = 16: 5.1; entries to ±9, n = 20: 5.8; entries to ±9, n = 24: 7.1; entries to ±9, n = 32: 10.1; entries to ±9, n = 40: 12.6; entries to ±9, n = 48: 15.4; entries to ±9, n = 64: 24.4; entries to ±9, n = 72: 29.5; entries to ±9, n = 80: 35.5; entries to ±999, n = 4: 1.6; entries to ±999, n = 8: 2.9; entries to ±999, n = 12: 4.3; entries to ±999, n = 16: 5.4; entries to ±999, n = 20: 6.8; entries to ±999, n = 24: 7.9; entries to ±999, n = 32: 10.7. The determinant's width grows like n log n; the plain route's like n squared.01632486480010203040nplain widest ÷ determinant, in bitsentries to ±9entries to ±999a straight line: the ratio grows in proportion to nthe swell outgrows the answer
Fig. 2 The plain route’s widest intermediate divided by the determinant’s width, against n: 1.6 at n = 4, 15 at 48, 35 at 80, for entries to ±9; and similarly for entries to ±999.

The two widths grow differently in kind. The determinant’s width grows like nlog⁡nn \log n — Hadamard’s bound, roughly the log of the entries plus half the log of nn, times nn. The plain route’s widest intermediate grows roughly like n2n^2, so their ratio grows in proportion to nn: 1.6 at n=4n = 4, 5.1 at 16, 10 at 32, 15 at 48 and 35 at 80. That is the same contrast the answer is longer than the question found between Bareiss’s elimination and naive rational arithmetic — linear growth against something faster — arriving here inside a routine that uses no fractions at all.

The finished report is narrow too

There is a second half to the earlier essay’s sentence — “any algorithm that reports how it reached its answer pays for the report” — and it can be tested the same way. The report is the transform UU, and the figure at the top of the page draws its finished width as well as its intermediates. The finished transform is as narrow as the form: 23 bits at n=8n = 8, 95 at 24, 209 at 48, each within the determinant’s width, while the transform’s intermediates on the way were 69, 693 and 3,366 bits. On every matrix measured the finished form and the finished transform both fit inside the determinant’s width.

That is not a coincidence of these matrices. For a nonsingular AA the transform is unique, U=HA−1U = HA^{-1}, and A−1A^{-1} is the adjugate over the determinant, so U=H adj⁡(A)/det⁡AU = H\,\operatorname{adj}(A)/\det A — a product of two matrices whose entries are bounded by the determinant’s width, divided exactly by the determinant. The report has a size fixed by the problem, as the answer does; what is unbounded is only the path plain elimination takes to both.

Which also means the report can be had without the path. Once the modular route has produced HH, the transform is the solution of UA=HUA = H, an integer system whose answer is known in advance to be integral; fraction-free elimination solves it with every intermediate a minor, and the inverse that is never formed is the reminder that it should be solved rather than computed as HH times an inverse. Nothing in that recovery is wider than the determinant’s width plus the form’s, so a caller who needs the transform does not have to choose between it and the bound.

What the answer actually is

The width of the intermediates is out of all proportion to the answer, and the answer is worth looking at.

The Hermite normal form of a random 12 × 12 integer matrix with entries from −9 to 9: every entry, the wide ones shown by their width in bitsDiagonal: 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 bits, 5 bits, 39 bits. The determinant has 44 bits. Every column but the last holds entries of at most 5 bits; the last holds entries up to 39 bits, each below the last pivot.1·········1139b·1········239b··1·······838b···1······539b····1····11039b·····1···1139b······1··11238b·······1···39b········1·1239b·········21037b··········1739b···········39ba wide entry is shown as its width in bits, '39b'almost the identity, with the answer in one column
Fig. 3 The Hermite form of a random 12 × 12 matrix with entries to ±9. Wide entries are shown by their width in bits. Eleven of the twelve columns are the identity’s or within five bits of it.

The Hermite form of a random integer matrix is almost the identity. At n=12n = 12 the first nine pivots are 1, the next two are 2 and 17, and the last is a 39-bit number; every column but the last holds entries of at most five bits, and the last column holds entries up to 39 bits, each below the last pivot. Of the determinant’s 44 bits, 39 sit in one corner entry.

Twenty random 24 × 24 integer matrices: how many of the Hermite form's pivots differ from one, and how many of the determinant's bits sit in the last pivot1 pivots not one, 94 of 94 bits in the last; 1 pivots not one, 95 of 95 bits in the last; 4 pivots not one, 94 of 97 bits in the last; 2 pivots not one, 98 of 99 bits in the last; 2 pivots not one, 91 of 94 bits in the last; 2 pivots not one, 95 of 96 bits in the last; 1 pivots not one, 96 of 96 bits in the last; 2 pivots not one, 93 of 97 bits in the last; 2 pivots not one, 95 of 96 bits in the last; 1 pivots not one, 98 of 98 bits in the last; 1 pivots not one, 96 of 96 bits in the last; 2 pivots not one, 93 of 94 bits in the last; 2 pivots not one, 98 of 100 bits in the last; 1 pivots not one, 94 of 94 bits in the last; 1 pivots not one, 99 of 99 bits in the last; 1 pivots not one, 99 of 99 bits in the last; 1 pivots not one, 98 of 98 bits in the last; 1 pivots not one, 96 of 96 bits in the last; 4 pivots not one, 91 of 96 bits in the last; 1 pivots not one, 97 of 97 bits in the last.02550751001 pivot ≠ 11 pivot ≠ 14 pivots ≠ 12 pivots ≠ 12 pivots ≠ 12 pivots ≠ 11 pivot ≠ 12 pivots ≠ 12 pivots ≠ 11 pivot ≠ 11 pivot ≠ 12 pivots ≠ 12 pivots ≠ 11 pivot ≠ 11 pivot ≠ 11 pivot ≠ 11 pivot ≠ 11 pivot ≠ 14 pivots ≠ 11 pivot ≠ 1bits of the determinant: in the last pivot (blue), in the others (red)each row one random matrix, entries from −9 to 9the determinant lives in the corner
Fig. 4 Twenty random 24 × 24 matrices: for each, how many pivots differ from one, and how the determinant’s bits divide between the last pivot and the others.

Over twenty random matrices at n=24n = 24 it is the same: between one and four pivots differ from one — exactly one on eleven of the twenty — and the last pivot carries at least 95 per cent of the determinant’s 94 to 100 bits. When the last pivot is the only one, the lattice a random integer matrix generates is the set of all integer vectors satisfying a single linear congruence modulo the determinant, and one number and one column of residues describe it. Plain elimination produces numbers of thirteen thousand bits on the way to an answer that is a column of four-hundred-bit residues and an identity. The modular route never writes down anything wider than the answer’s own widest entry.

That shape is what the Smith form records as invariant factors of one and a single large last factor: the quotient of all integer vectors by the lattice is cyclic. The rank depends on the ring found an integer matrix of rank six over the rationals whose rank drops to five modulo three and four modulo two — a matrix whose quotient is not cyclic — and a matrix like that cannot have a Hermite form with a single non-unit pivot, since a single non-unit pivot would make the quotient cyclic.

A bound is not a saving

The measurement that changes the conclusion is the cost.

The work of computing the Hermite normal form, in schoolbook bit operations, against n: plain elimination and the route modulo the determinant, on matrices with entries to ±9 and to ±999entries to ±9, n = 4: plain 4406, modular 1.68·10⁴; entries to ±9, n = 8: plain 1.58·10⁵, modular 6.33·10⁵; entries to ±9, n = 12: plain 1.47·10⁶, modular 6.65·10⁶; entries to ±9, n = 16: plain 9.83·10⁶, modular 2.96·10⁷; entries to ±9, n = 20: plain 3.19·10⁷, modular 1.05·10⁸; entries to ±9, n = 24: plain 1.11·10⁸, modular 2.85·10⁸; entries to ±9, n = 32: plain 6.67·10⁸, modular 1.52·10⁹; entries to ±9, n = 40: plain 2.83·10⁹, modular 6.03·10⁹; entries to ±9, n = 48: plain 9.28·10⁹, modular 1.74·10¹⁰; entries to ±9, n = 64: plain 7.8·10¹⁰, modular 9.66·10¹⁰; entries to ±9, n = 72: plain 1.85·10¹¹, modular 1.9·10¹¹; entries to ±9, n = 80: plain 4.3·10¹¹, modular 3.66·10¹¹; entries to ±999, n = 4: plain 3.27·10⁴, modular 1.98·10⁵; entries to ±999, n = 8: plain 1.42·10⁶, modular 6.26·10⁶; entries to ±999, n = 12: plain 1.66·10⁷, modular 5.41·10⁷; entries to ±999, n = 16: plain 7.85·10⁷, modular 2.44·10⁸; entries to ±999, n = 20: plain 3.02·10⁸, modular 8.17·10⁸; entries to ±999, n = 24: plain 8.6·10⁸, modular 2.23·10⁹; entries to ±999, n = 32: plain 4.93·10⁹, modular 1.09·10¹⁰. The two routes cost the same at n = 72 (ratio 0.97); below, plain elimination does less work.10³10⁴10⁵10⁶10⁷10⁸10⁹10¹⁰10¹¹10¹²nbit operations48163264plain, ±9modular, ±9plain, ±999modular, ±999red: plain; blue: modular; open dots: entries to ±999bounded is not cheaper until n ≈ 72
Fig. 5 The work of each route in schoolbook bit operations, against n, for entries to ±9 (filled) and ±999 (open). The two routes cross at n = 72.

The cost is counted in schoolbook bit operations — a multiplication costs the product of its operands’ widths, a division the product of dividend’s and divisor’s, an addition the wider operand — so that it does not depend on the machine. Counted that way, and with the modular route charged for computing its determinant, it does more work than plain elimination at every size to 64 on both families: 3.8 times as much at n=4n = 4, 2.6 times at 24, 1.2 times at 64. The two are within three per cent at n=72n = 72, and at 80 the modular route is a sixth cheaper.

The reason is in what each route multiplies. Plain elimination’s Euclidean steps mostly multiply a wide row by a small quotient — a few bits times thousands — which is cheap per step even when the row is huge. The modular route’s extended-gcd steps multiply rows of determinant-sized entries by determinant-sized coefficients and then reduce the products modulo the determinant, which is a wide number times a wide number on every step. The plain route’s numbers grow like n2n^2 in bits and the modular route’s like nlog⁡nn \log n, so the plain route’s cost must eventually overtake, and it does — but not until the matrices are larger than anything the earlier essay could have computed with its routine.

So the earlier essay’s remark that a modular approach would control the growth is right, and the implication that it would be what made larger sizes affordable is not, at least not below seventy. What the bound buys at these sizes is memory and predictability: the modular route’s numbers are never wider than twice the determinant, known in advance from Hadamard’s bound, while the plain route’s widest number cannot be predicted without running it.

Where the determinant comes from

The modular route needs ∣det⁡A∣|\det A| before it starts, and that is not free either. It is the one number that has to be exact before anything else is, and it could be produced modulo enough primes and reconstructed, the way a fraction recovered from one remainder recovers a rational from a single modular image. Here it comes from fraction-free elimination, n3n^3 operations on numbers bounded by the determinant’s width, and in the same count it is 2 to 5 per cent of the modular route’s total — a small part of why the crossover is as late as it is. How many primes the answer needs priced the other route to a determinant — compute it modulo enough word-sized primes and reconstruct it — and found the number of primes set by the same Hadamard bound. Either way the determinant is cheap beside what follows it: the expensive part of the modular route is the elimination modulo the determinant itself, every step of which multiplies two numbers of the determinant’s width.

There is also a subtlety the measurement passes over because these matrices never trigger it: the modular route needs a nonsingular matrix, since a zero determinant gives no modulus, and for a singular or rectangular matrix the standard variants work modulo a nonzero maximal minor instead. The refusal attached to this essay feeds the route a singular matrix and requires it to say so rather than return a form computed modulo zero.

What eighty random matrices do not show

Every matrix here is random with small entries, square and nonsingular. Random matrices are the case where the Hermite form is almost the identity, and a matrix built to have many non-unit pivots — a lattice with structure, the kind a basis that describes its lattice badly reduces — would give the modular route more to do at every column, and the plain route a different growth. The cost model counts schoolbook operations; a multiplication algorithm faster than schoolbook on wide numbers would cut the plain route’s large multiplications less than proportionally, since most of them are wide-by-small, and would favour the modular route earlier. And the plain route’s growth on these matrices is roughly quadratic in bits, which is benign: plain Hermite elimination can be driven to far worse growth by adversarial matrices, and none of them is measured here.

Still open: the Smith form modulo the determinant, structured lattices, and the crossover’s size

The Smith form. The same lattice fact lets the Smith form be computed modulo the determinant, with column operations as well as row operations. The prediction with a sign is that it returns the earlier essay’s invariant factors exactly, never writes a number wider than twice the determinant, and — because random matrices have Smith forms of all ones but one entry — finishes in about the same bit operations as the modular Hermite form, rather than the far larger count the plain Smith routine needs, which the earlier essay could not take past six.

A lattice with structure. Take a matrix whose Hermite form has many non-unit pivots — the product of a random unimodular matrix and a diagonal of small primes. The prediction is that the modular route’s advantage in width is unchanged, and that its cost crossover moves to smaller nn, because the plain route’s Euclidean steps there involve more and larger quotients.

Where the crossover sits. The two routes cross at n=72n = 72 for entries to ±9. The prediction is that for entries to ±999 they cross earlier, near n=48n = 48, because the determinant’s width grows by a fixed amount per row and the plain route’s quadratic growth starts from wider entries — and that the crossover in general falls where the plain route’s widest entry is about forty times the determinant’s.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A flat tag is an object no other essay names yet.

Coefficient growthDeterminantExact arithmeticHermite normal formLatticeSmith normal formUnimodular