Exact arithmetic, and what it costs instead

A cheap logarithm, and what vouches for it

Hadamard's bound budgets forty-six primes for a Pascal determinant of one, and the cheap repair predicted for it was one floating-point LU: the sum of the logarithms of its pivots, within ten bits of the truth everywhere except on Hilbert matrices above order 16. It is exact to a twentieth of a bit on four of six families at every order to 48. On Pascal matrices, which the prediction did not exempt, it is 42 bits high at order 24 and 1,041 at 48, and on Hilbert matrices it is already 22 bits high at 16. It is never low on any of them, but on the determinants built to fool a stop it meets a zero pivot and calls a nonsingular matrix singular. What tells the cases apart is the condition number binary64 computes alongside: below 50 bits, every estimate is exact.

Worth reading first: How many primes the answer needs · The number that decides nothing · Orthogonal is a number.

The budget was a worst case priced the primes a modular determinant is given by Hadamard’s bound against the primes the determinant actually needs, on six families of integer matrix, and found the bound exact on Hadamard matrices, within a prime on random entries, three times too large on scaled Hilbert matrices and forty-six times too large on a Pascal matrix of order 32, whose determinant is one. It then measured the alternative every practical library uses, stopping when the reconstructed value has repeated, found it right on all eighteen matrices tried, and built a determinant that fooled it.

Its first open question was cheaper than either. A logarithm of a determinant is available from a floating-point LU at the cost of one factorisation, as the sum of the logarithms of the pivots’ magnitudes, and the sum cannot overflow where the determinant itself would. Its error is often small even when every digit of the determinant is gone, because the digits and the size are different quantities. The prediction it signed was that this estimate falls within ten bits of the truth on every family at every order, except the Hilbert matrices above order 16, so that a code could set a tight budget for the cost of one prime.

The estimate against the exact length

The families are the same six: random entries below 9 and below 999, Hadamard matrices, Pascal matrices, unit triangular matrices and scaled Hilbert matrices. The orders run from 8 to 48. The exact determinant comes from fraction-free elimination, which returns it in integers because every intermediate is a minor, and its length in bits is the reference. Hadamard matrices exist only at powers of two, so that family contributes four orders rather than seven, and the six families give thirty-nine distinct matrices. The estimate is one LU with partial pivoting in binary64, on the integers rounded to binary64, with ∑ilog⁡2∣uii∣\sum_i \log_2 |u_{ii}| read off the diagonal of UU.

The bits of the determinant of a Pascal matrix against its order: exact, estimated from one binary64 LU, and budgeted by Hadamard's boundPascal, at orders 8, 12, 16, 20, 24, 32, 48: exact 0, 0, 0, 0, 0, 0, 0 bits; estimated 0, 0, 0, 2, 42, 223, 1041; Hadamard's bound 61, 149, 277, 445, 653, 1191, 2753.081624324048050010001500200025003000order of the matrixbits of the determinantHadamard's boundestimate from one LUexactPascal · binary64 for the estimatethe estimate leaves the truth where the condition does
Fig. 1 The bits of the determinant against the order: exact (blue), estimated from one binary64 LU (red), and Hadamard’s bound (grey). The dial sets the family.

On a Pascal matrix the exact line lies on the axis, since the determinant is one at every order. The estimate lies on it too as far as order 16, then rises: 1.5 bits at order 20, 42 at 24, 223 at 32 and 1,041 at 48. Hadamard’s bound, at 2,753 bits at order 48, stays above it throughout. On the scaled Hilbert matrices the estimate leaves the exact line earlier and climbs faster: 22 bits high at order 16, 235 at 24, 685 at 32 and 2,337 at 48, where it reads 4,051 bits against a true 1,713. On random entries, below 9 or below 999, the dial shows the estimate on the exact line at every order, and the bound a little above both.

So the prediction fails twice, in two different ways. On the family it exempted, Hilbert, it fails at order 16, the first order where it was supposed to start holding. And it fails on Pascal matrices, which it did not exempt at all and where the earlier essay found the bound’s worst overpayment. The estimate is wrong in exactly the two families where a budget better than Hadamard’s would have been worth most.

Four families where it is perfect

How far the binary64 estimate of a determinant's bits is from the exact value, against the order, on six families of integer matrixentries below 9: under a twentieth at 8, under a twentieth at 12, under a twentieth at 16, under a twentieth at 20, under a twentieth at 24, under a twentieth at 32, under a twentieth at 48; entries below 999: under a twentieth at 8, under a twentieth at 12, under a twentieth at 16, under a twentieth at 20, under a twentieth at 24, under a twentieth at 32, under a twentieth at 48; Hadamard: under a twentieth at 8, under a twentieth at 16, under a twentieth at 32, under a twentieth at 64; Pascal: under a twentieth at 8, under a twentieth at 12, under a twentieth at 16, 1.5 at 20, 41.8 at 24, 222.8 at 32, 1040.9 at 48; unit triangular: under a twentieth at 8, under a twentieth at 12, under a twentieth at 16, under a twentieth at 20, under a twentieth at 24, under a twentieth at 32, under a twentieth at 48; scaled Hilbert: under a twentieth at 8, under a twentieth at 12, 21.7 at 16, 92.4 at 20, 235.4 at 24, 685.0 at 32, 2338.3 at 48.01632486410⁻²10⁻¹110¹10²10³10⁴order of the matrixerror of the estimate, in bitsentries below 9entries below 999HadamardPascalunit triangularscaled Hilbertfloored at a hundredth of a bittwo families leave, four never do
Fig. 2 The error of the binary64 estimate of a determinant’s bits against the order, on six families, floored at a hundredth of a bit.

On the other four families the error is not small but nil, in any practical sense. Random entries below 9 and below 999, Hadamard matrices and unit triangular matrices give an estimate within a twentieth of a bit of the exact length at every order from 8 to 48, and on most of them the logarithms agree to more places than any count of primes could use. Those four are the families where the bound itself was within a prime, apart from unit triangular matrices at the larger orders, so the estimate’s success is real but its value is small: it matches the determinant where Hadamard’s bound already did.

Two of the four are exact for a reason that has nothing to do with stability. A unit triangular matrix is already its own UU, with ones on the diagonal, and the logarithms sum to zero with no rounding at all. A Hadamard matrix of ±1\pm 1 entries eliminates through small integers and halves, every one of which binary64 holds exactly, so its pivots are the exact pivots and their logarithms sum to n2log⁡2n\tfrac{n}{2}\log_2 n, 192 bits at order 64, to the last place. Only the two random families are exact in the ordinary sense, of rounding that happened and did not matter: their pivots carry relative errors of order 10−1610^{-16}, and a logarithm summed over 48 of them moves by less than 10−1310^{-13} bits.

That is less disappointing than it looks, because the question was never whether a floating-point LU knows the size of a well-behaved determinant. Floating-point elimination with partial pivoting is backward stable, and the number that decides nothing has already drawn what that means for a determinant: the computed value is the exact determinant of a matrix close to the input, and on a matrix whose determinant does not move much when the entries move, close enough. The cases that matter are the ones where it moves a great deal.

What the condition number knows

The two failing families are the two whose condition numbers are large, and the connection can be made quantitative with nothing a code does not already have.

The error of the binary64 estimate of a determinant's bits against the matrix's condition number in bits, as binary64 computes it, on Pascal and Hilbert matrices of order 8 to 48Pascal: 0.0 bits at a condition of 24 bits, 0.0 bits at a condition of 40 bits, 0.0 bits at a condition of 55 bits, 1.5 bits at a condition of 68 bits, 41.8 bits at a condition of 77 bits, 222.8 bits at a condition of 92 bits, 1040.9 bits at a condition of 123 bits; scaled Hilbert: 0.0 bits at a condition of 34 bits, 0.0 bits at a condition of 54 bits, 21.7 bits at a condition of 59 bits, 92.4 bits at a condition of 60 bits, 235.4 bits at a condition of 63 bits, 685.0 bits at a condition of 62 bits, 2338.3 bits at a condition of 64 bits. Every case below 50 bits of condition is within a twentieth of a bit.2040608010012010⁻²10⁻¹110¹10²10³10⁴condition number, in bits, computed in binary64error of the estimate, in bitsPascalHilbertthe line is the 53 bits of the significandHilbert's computed condition stops at 64
Fig. 3 The error of the binary64 estimate against the matrix’s condition number in bits as binary64 computes it, on Pascal (red) and Hilbert (green) matrices of order 8 to 48. The vertical line is the 53 bits of the significand.

Against the condition number, in bits, as a binary64 singular value decomposition reports it, the Pascal errors fall in a clean sequence. At 24, 40 and 55 bits of condition the estimate is exact. At 68 bits it is 1.5 bits out, at 77 bits 42, at 92 bits 223 and at 123 bits 1,041. The Hilbert matrices behave the same way with a twist: their computed condition stops climbing near 64 bits, because a binary64 decomposition cannot resolve a smallest singular value much below the largest times the roundoff, and so their errors pile up in a column there, 22 bits to 2,337 at a computed condition of 60 to 64. That saturation is itself informative. A computed condition number near the precision’s limit means the true one is at least that large and may be far larger.

Across all thirty-nine distinct matrices one rule holds without exception. Wherever the computed condition is below 50 bits, the estimate is within a twentieth of a bit of the exact length, and every miss of a bit or more has a computed condition above 55. A condition number tells how many digits of a solution survive; here it tells how many bits of a determinant’s size do, and it has the same threshold, the significand’s 53 bits.

The mechanism is the same as for a solve. On a matrix with condition κ\kappa, a backward error of order uu in the entries moves the smallest singular values by up to κu\kappa u relative to themselves, and the determinant is their product. Once κu\kappa u reaches one, the smallest singular values the LU has implicitly found are not the matrix’s at all, and their logarithms are whatever rounding left. On a Pascal matrix, rounding leaves pivots much larger than the true ones, which is why the estimate runs high; nothing in the arithmetic requires that direction in general. The sign is the last digit to go found the same threshold from the other end, for the sign of a determinant near singularity: the sign survives until the relative error of the value reaches one, and the logarithm here is the measure of that relative error, read on a scale of bits.

Never low, except where it matters

On the six families the estimate was never low. Its smallest error over all thirty-nine matrices is within a twentieth of a bit of zero, and every real miss is an overestimate. A budget set from it with ten bits of margin is therefore safe on every case measured: it lies between the primes the determinant needs and Hadamard’s budget, every time.

How many 26-bit primes a modular determinant is given at order 32 by the determinant's own length, by the binary64 estimate with ten bits of margin, and by Hadamard's bound, on five familiesentries below 9, order 32: the determinant needs 6, the estimate plus ten bits 6, Hadamard's bound 7; entries below 999, order 32: the determinant needs 14, the estimate plus ten bits 14, Hadamard's bound 15; Hadamard, order 32: the determinant needs 4, the estimate plus ten bits 4, Hadamard's bound 4; Pascal, order 32: the determinant needs 1, the estimate plus ten bits 9, Hadamard's bound 46; scaled Hilbert, order 32: the determinant needs 34, the estimate plus ten bits 61, Hadamard's bound 108.1248163264128entries below 9, order 32the determinant needs6the estimate plus ten bits6Hadamard's bound7entries below 999, order 32the determinant needs14the estimate plus ten bits14Hadamard's bound15Hadamard, order 32the determinant needs4the estimate plus ten bits4Hadamard's bound4Pascal, order 32the determinant needs1the estimate plus ten bits9Hadamard's bound46scaled Hilbert, order 32the determinant needs34the estimate plus ten bits61Hadamard's bound108primesunit triangular: one prime by every routewrong, and still five times tighter
Fig. 4 How many 26-bit primes a modular determinant is given at order 32: by the determinant’s own length (blue), by the estimate plus ten bits (red), and by Hadamard’s bound (grey), on five families.

At order 32, even where it is wrong, the estimate’s budget is far tighter than the bound’s. The Pascal matrix, needing one prime, is budgeted nine by the estimate and forty-six by Hadamard. The scaled Hilbert matrix, needing 34, is budgeted 61 and 108. On the three well-behaved families shown the estimate matches the need exactly, 6, 14 and 4, where the bound asks one more. The unit triangular matrix needs one prime by every route at this order. So a wrong estimate still saves most of what an exact one would, on these two families, and a right one saves the last prime the bound wastes on the others.

But “never low” is an observation about six families, and the earlier essay had already built a seventh. Its fooling matrices have as determinant the product of the first kk primes of the list plus seven, made from an integer matrix of small determinant by integer row operations, which leaves entries far larger than the determinant they produce.

Determinants built on the first k primes of the list: their exact bits, the binary64 estimate, the largest entry's bits and the condition number in bitsbuilt on 2 primes: exact 52 bits, estimate 80, largest entry 59 bits, condition 62 bits; built on 4 primes: exact 104 bits, estimate a zero pivot, largest entry 111 bits, condition 163 bits; built on 6 primes: exact 156 bits, estimate a zero pivot, largest entry 163 bits, condition 213 bits; built on 8 primes: exact 208 bits, estimate a zero pivot, largest entry 215 bits, condition 273 bits.110100exact bits of the determinantbuilt on 2 primes52built on 4 primes104built on 6 primes156built on 8 primes208the estimate: a zero pivot reads as nonebuilt on 2 primes80built on 4 primessingularbuilt on 6 primessingularbuilt on 8 primessingularcondition number in bitsbuilt on 2 primes62built on 4 primes163built on 6 primes213built on 8 primes273bitsentries larger than the determinantthe condition flags every one
Fig. 5 Determinants built on the first kk primes of the list: their exact bits (blue), the binary64 estimate, with a zero pivot read as singular (red), and the condition number in bits (grey).

Built on two primes, the determinant has 52 bits and the estimate reads 80, an overestimate of 28 bits at a computed condition of 62 bits, in line with everything above. Built on four, six or eight primes, the determinant has 104, 156 and 208 bits, its entries run to 111, 163 and 215 bits, and the binary64 LU meets an exactly zero pivot. The estimate is −∞-\infty: the factorisation says the matrix is singular. A budget set from that number is one prime, which returns the determinant modulo one prime, which is wrong.

This is the one way the cheap logarithm can underestimate, and it is the way that matters. The entries do not fit in binary64, so rounding them alone changes the matrix by far more than its determinant, and the rounded matrix genuinely is singular to working precision. A floating-point zero pivot is a statement about the rounded matrix, and here the rounded matrix is not the one asked about. It happens on exactly the matrices built to fool the repeated-value stop, which is not a coincidence: both constructions put a large determinant behind entries that hide it.

What the estimate costs, and what it is for

A floating-point LU of order nn costs about n3/3n^3/3 multiplications and additions, and so does one elimination modulo a word-sized prime. Counted that way, the estimate costs about one prime, and the question is whether it saves more than one. Over the thirty-nine matrices, the rule that trusts it below 50 bits of condition saves twenty-four primes against Hadamard’s bound in total. Four of those are on the unit triangular matrix of order 48, four on the Hilbert matrix of order 8, seven on the two smallest Pascal matrices, and the rest are one prime at a time on random entries, where the bound was already within one. Thirty-nine estimates for twenty-four primes is a loss, on this count. The estimate is trustworthy exactly where a budget barely needed improving, and the condition test sends every matrix where the bound wastes most back to the bound.

So the estimate is not much use as a budget. It is better used as a witness. The repeated-value stop already uses within one prime of the need on every ordinary matrix, Pascal and Hilbert included, and its one weakness is the built determinant, whose congruences are arranged to settle on the wrong value. A stop that also required the settled value’s length to match the floating-point estimate, whenever the condition allows the estimate to be believed, would be fooled only by a matrix that defeats both the congruences and a backward-stable factorisation at once. On the built determinants the condition does not allow it, and the stop would fall back to running out the bound, which is the correct answer to a matrix whose entries hide its determinant. A congruence and a magnitude are independent measurements, in the way a prime that divides the answer found that a single residue is not, and two independent measurements that agree are what a certificate is made of.

What a code can do with this

Put together, the measurements suggest a simple rule rather than a better bound. Factor the matrix once in floating point, and compute or estimate its condition number at the same time; an estimate that can be fooled and two columns see what one walk cannot describe the estimators codes use, which cost a few solves with the factors already in hand. If the condition is below 50 bits and no pivot is zero, budget the estimate plus a margin. Otherwise fall back to Hadamard’s bound, or to the repeated-value stop with its known risk. On the thirty-nine matrices here that rule gives the exact need on every well-conditioned case and Hadamard’s budget on every ill-conditioned one, which is never worse than the bound and never fooled by the built determinants, since every one of them has a computed condition above 60 bits.

The rule is conservative in two places. It sends the Pascal matrix of order 16 and the Hilbert matrix of order 12 to Hadamard’s bound although the estimate was exact on both, because their computed conditions, 55 and 54 bits, sit just above the threshold. And it gives up the saving on the large ill-conditioned matrices, where an overestimate would still have been five times tighter than the bound. A threshold set at the significand is the honest one; one set higher would trade a little safety for those primes.

None of this removes the case for the stop. How many primes the answer needs counted the primes against a determinant’s length, and the repeated-value stop gets within one of that on every ordinary matrix without knowing the length at all. What the floating-point estimate offers is independence: it is a measurement of size that does not go through the congruences, so a matrix built to make the congruences lie does not also make the estimate lie. It makes it fail loudly instead, and a loud failure is a better property in a budget than a silent one.

What this leaves out

The six families are the ones the exact field already used, chosen for what is known about each rather than for being typical. The fooling construction is one recipe; an adversary with the estimate in mind could aim for an overestimate small enough to pass the condition test and a determinant just past the budget it sets, and whether the condition test can be passed that way was not measured. The condition numbers come from a binary64 singular value decomposition, which is more than a code would compute; a cheap estimator can be several bits out, which moves the threshold rather than the rule. And the margin of ten bits was not needed on any well-conditioned case here, where the estimate was within a twentieth of a bit, so it is a choice of how much to trust a backward error analysis rather than a measured requirement.

What stands is that the cheap logarithm is exact where the condition number is moderate and arbitrary where it is not, that the condition number computed beside it tells which, and that the one case where it runs low is a matrix whose entries binary64 could not hold.

Still open: a sharper threshold, and the doubling schedule

A threshold read from the estimator a code has. The rule above uses a binary64 singular value decomposition. The prediction with a sign is that a one-norm condition estimate of the kind LAPACK computes from the LU factors, with a threshold of 48 bits, classifies all thirty-nine matrices the same way as the decomposition at 50, and that on a hundred random integer matrices of order 24 with entries below 999 multiplied by a random unimodular matrix of growing entry size, every case the estimator passes is within a bit of the exact length.

Doubling the batches. The earlier essay’s second question stands, sharpened by the estimate. Reconstructing after 1, 2, 4 and 8 primes rather than after each costs less arithmetic and may overshoot. The prediction is that with doubling the primes used are at most twice the need on every case here, that a schedule starting at the estimate’s budget where the condition allows it needs no second batch on any well-conditioned case, and that the matrix built on six primes still fools the stop unless the first batch exceeds six, so that doubling hides the same failure at a different count while the condition test does not.

What links here

Computed from the collection, not written here: the essays that point at this one.

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.

Chinese remainder theoremCondition numberDeterminantFraction-free eliminationHadamard boundLU factorisationModular arithmetic