Exact arithmetic, and what it costs instead

The budget was a worst case

The number of primes a modular determinant needs was said to have to be fixed in advance by a theorem, not by trying more until the answer settles. Hadamard's bound is that theorem, and it is tight on a Hadamard matrix and within one prime on random entries. On a Pascal matrix of order 32 it budgets forty-six primes for a determinant of one, and on a scaled Hilbert matrix three times what is needed. Stopping when the value repeats finds the right determinant on all eighteen matrices tried, at one prime more than needed. It can be fooled: a determinant built on the first six primes of an ordered list is reported as seven by every stop asking fewer than six repeats. Draw the primes at random from a pool and the same matrix fools it at the rate chance predicts.

Worth reading first: How many primes the answer needs · An answer with no error in it.

How many primes the answer needs set up a modular determinant with a fixed plan. Work modulo a word-sized prime and no intermediate can exceed twenty-six bits, whatever the matrix does. Reassemble the answer from several primes by the Chinese remainder theorem. And decide how many primes beforehand, “by a theorem about how large a determinant can be, not by trying more until it settles”. Hadamard’s bound is the theorem. A fraction recovered from one remainder closed its own route with the same note: nothing in the algorithm adapts, and every quantity deciding how much work happens is computed before any work happens.

The plan is clean, and it is not what anybody writing a production exact solver actually does. Reconstruct after every prime, watch the value, and stop when it stops changing. The difference is worth measuring in both directions, because a theorem about a worst case may be far from the case in hand, and because a value that has stopped changing is not automatically a value that is right.

Both directions are measurable exactly here. Fraction-free elimination returns the true determinant in integers, on every matrix below, so each stop can be scored with no margin at all.

What the bound budgets against what the matrix needs

Six families are used, at orders 8, 16 and 32. Three of them are built so their determinants are large or their rows are long: random entries below 9, random entries below 999, and Hadamard matrices, whose rows are exactly orthogonal. Two have a determinant of one: Pascal matrices and unit triangular ones. And scaled Hilbert matrices have a determinant that is large in itself but far below the size of the entries. For each, Hadamard’s product of row norms is taken, and a prime supplies about twenty-six bits.

Word-sized primes for an exact determinant at order 32, by family: how many Hadamard's bound budgets, how many the determinant's own size needs, and how many a stop on one repeated value usesentries below 9: budget 7, needed 6, used 7; entries below 999: budget 15, needed 14, used 15; Hadamard: budget 4, needed 4, used 5; Pascal: budget 46, needed 1, used 2; unit triangular: budget 3, needed 1, used 2; scaled Hilbert: budget 107, needed 34, used 35.110100entries below 9budgeted by the bound7enough for the determinant6used, stopping on one repeat7entries below 999budgeted by the bound15enough for the determinant14used, stopping on one repeat15Hadamardbudgeted by the bound4enough for the determinant4used, stopping on one repeat5Pascalbudgeted by the bound46enough for the determinant1used, stopping on one repeat2unit triangularbudgeted by the bound3enough for the determinant1used, stopping on one repeat2scaled Hilbertbudgeted by the bound107enough for the determinant34used, stopping on one repeat35primes of about twenty-six bitsorder 32 · every stop was checked exactlya bound is not a measurement
Fig. 1 Word-sized primes for an exact determinant, by family: how many Hadamard’s bound budgets, how many the determinant’s own size needs, and how many a stop on one repeated value uses. The dial sets the order.

At order 32 the bound is doing very different amounts of work. On a Hadamard matrix it is exact: four primes budgeted, four needed. That family is the case of equality in the bound, by construction. On random entries it is nearly exact too, seven budgeted against six needed below 9 and fifteen against fourteen below 999. A random matrix has nearly orthogonal rows, so its determinant comes within a factor that is modest in the logarithm of the product of its row norms, and a logarithm is what primes are counted in.

The three other families are nothing like that. The scaled Hilbert matrix is budgeted 107 primes and needs 34. The unit triangular matrix is budgeted three and needs one. And the Pascal matrix, whose rows hold binomial coefficients of up to fifty-nine bits, is budgeted forty-six primes for a determinant of exactly one.

The bits of an exact determinant and the bits Hadamard's bound allows for it, against the order, for three familiesentries below 9: bound 15, 33, 53, 73, 95, 116, 138, 161; determinant 13, 24, 40, 57, 76, 95, 117, 137; scaled Hilbert: bound 35, 141, 374, 714, 1013, 1604, 2107, 2782; determinant 13, 40, 131, 266, 297, 556, 664, 881; Pascal: bound 14, 62, 150, 278, 446, 654, 903, 1192; determinant 1, 1, 1, 1, 1, 1, 1, 1 at orders 4, 8, 12, 16, 20, 24, 28, 32.48121620242832110¹10²10³orderbitssmall entries: the boundsmall entries: its determinantHilbert: the boundHilbert: its determinantPascal: the boundPascal: its determinantdashed: the boundthe gap is the family's, not the order's
Fig. 2 The bits of an exact determinant and the bits the bound allows for it, against the order, for three families. Dashed lines are the bound.

Across the orders this picture is very regular. On the random family the two curves run together, 137 bits against 161 at order 32. On the Hilbert family they run parallel at a factor of about three, on a logarithmic axis, so the gap grows with the order: 881 bits of determinant against a bound of 2,782. And on Pascal the determinant stays at one bit while the bound goes through 1,192. So the size of the gap is a property of the family and not of the order. A matrix whose rows are far from orthogonal has a determinant far below the product of their lengths, and nothing about that is an accident, since that is exactly what the bound’s equality condition says.

How many times the bits of a determinant Hadamard's bound allows, by family and orderentries below 9: 1.4, 1.3, 1.2; entries below 999: 1.1, 1.1, 1.1; Hadamard: 1.1, 1.0, 1.0; Pascal: 62.0, 278.0, 1192.0; unit triangular: 10.0, 25.0, 61.0; scaled Hilbert: 3.5, 2.7, 3.2.1101001000entries below 9order 81.4order 161.3order 321.2entries below 999order 81.1order 161.1order 321.1Hadamardorder 81.1order 161.0order 321.0Pascalorder 862.0order 16278.0order 321192.0unit triangularorder 810.0order 1625.0order 3261.0scaled Hilbertorder 83.5order 162.7order 323.2the bound's bits over the determinant'sthe closer to one the tightera thousandfold on a determinant of one
Fig. 3 How many times the bits of a determinant Hadamard’s bound allows, by family and order.

The Hadamard ratio that the number that decides nothing proposed as a scale-free measure of how far the columns are from orthogonal is the same quantity seen from the other side. Written in bits it is exactly the size of the over-budget, so the first thing an exact solver could read about a matrix before running anything is how badly its budget will overpay, given a cheap estimate of the determinant’s size. Such an estimate is generally not to be had, and that is why the plan exists at all.

The stop that tries more until it settles

The alternative costs almost nothing to state. After each prime, update the running value by Garner’s incremental form of the remainder theorem, centre it in the symmetric range, and compare it with the last one. If the value is the same for tt primes in a row, return it.

The arithmetic behind it is simple. A true determinant dd of bb bits has a unique symmetric residue once the product of the primes passes 2b+12^{b+1}, so from that prime on the value does not move, whatever else happens. The stop therefore returns no later than the number of primes the determinant needs, plus tt. That part is a theorem as well. It gives the stop an upper limit that depends on the determinant and not on the rows.

On all eighteen cases, at each of t=1t = 1, 2 and 3, the value the stop returned equals the determinant from exact elimination. The count of primes is exactly the need plus tt every time. The Pascal matrix of order 32 returns after two primes, or 4 per cent of the budget, and the scaled Hilbert matrix after 35, or a third of it.

At order 32, the primes each stop uses as a share of the bound's budget, for one, two and three repeats, by familyentries below 9: 1.00, 1.14, 1.29 of a budget of 7; entries below 999: 1.00, 1.07, 1.13 of a budget of 15; Hadamard: 1.25, 1.50, 1.75 of a budget of 4; Pascal: 0.04, 0.07, 0.09 of a budget of 46; unit triangular: 0.67, 1.00, 1.33 of a budget of 3; scaled Hilbert: 0.33, 0.34, 0.35 of a budget of 107.00.511.52entries below 91 repeat, needs 61.002 repeats, needs 61.143 repeats, needs 61.29entries below 9991 repeat, needs 141.002 repeats, needs 141.073 repeats, needs 141.13Hadamard1 repeat, needs 41.252 repeats, needs 41.503 repeats, needs 41.75Pascal1 repeat, needs 10.042 repeats, needs 10.073 repeats, needs 10.09unit triangular1 repeat, needs 10.672 repeats, needs 11.003 repeats, needs 11.33scaled Hilbert1 repeat, needs 340.332 repeats, needs 340.343 repeats, needs 340.35primes used over primes budgetedorder 32 · above one the stop costs moretight bounds are where it does not pay
Fig. 4 At order 32, the primes each stop uses as a share of the bound’s budget, for one, two and three repeats, by family. Above one the stop costs more than the plan.

The figure also shows who loses. On Hadamard matrices at order 32, the stop with one repeat uses five primes where the plan uses four, and at three repeats it uses seven. That is 75 per cent more than the plan. On the two random families a stop with one repeat breaks even and three repeats pay about a fifth more. The bound was already tight on these, so any confirmation primes are simply extra. The stop saves work where the bound is loose, and it costs a constant where the bound is tight. Since the constant is a few primes and the saving is potentially most of them, that trade favours the stop on any collection that is not made up purely of matrices with nearly orthogonal rows. The plan, however, has a different virtue, which is what the next section is about.

A value can settle and be wrong

The stop’s failure is simple to arrange. Suppose d≡vd \equiv v modulo every prime the stop has seen, with d≠vd \ne v. Then the value stays at vv and the stop returns it. So all that is needed is a true determinant that differs from a small number by a multiple of the first few primes in the list. And an integer matrix can be built with any chosen determinant: a diagonal matrix with that number in one corner, multiplied on each side by a few random unimodular matrices.

A determinant built as the product of the first primes of an ordered list, plus seven: the primes a stop uses, and whether the value it stops on is the determinant, against how many repeats it asks forbuilt on 2 primes, 1 repeat: wrong, after 2 primes; built on 2 primes, 2 repeats: right, after 5 primes; built on 3 primes, 1 repeat: wrong, after 2 primes; built on 3 primes, 2 repeats: wrong, after 3 primes; built on 3 primes, 3 repeats: right, after 7 primes; built on 6 primes, 1 repeat: wrong, after 2 primes; built on 6 primes, 2 repeats: wrong, after 3 primes; built on 6 primes, 3 repeats: wrong, after 4 primes; built on 6 primes, 6 repeats: right, after 13 primes.04812built on 2 primes, 1 repeat: wrong2built on 2 primes, 2 repeats: right5built on 3 primes, 1 repeat: wrong2built on 3 primes, 2 repeats: wrong3built on 3 primes, 3 repeats: right7built on 6 primes, 1 repeat: wrong2built on 6 primes, 2 repeats: wrong3built on 6 primes, 3 repeats: wrong4built on 6 primes, 6 repeats: right13primes used before stopping, in list orderorder 8 · the determinant is the product plus sevenred: stopped on the wrong value
Fig. 5 A determinant built as the product of the first primes of an ordered list plus seven: the primes a stop uses, and whether the value it stops on is the determinant, against how many repeats it asks for.

That is the result here. An order-8 matrix built on the first six primes of the list has a determinant with 156 bits, and every stop asking for fewer than six repeats reads a value of seven and returns it: after two primes at one repeat, three at two repeats, four at three repeats. The answer has the right sign and looks very plausible. It is wrong by something a hundred and fifty bits long. Only when the stop asks for as many repeats as the determinant has built-in primes does the value finally move, and after six repeats it stops at thirteen primes with the right number. A stop cannot know what repeat count would be enough without knowing the answer. Hadamard’s bound is true of this matrix too. Its entries run to 160 bits, a consequence of how it was built, so the bound budgets 1,138 bits or 44 primes, and the plan returns the right answer without any question arising.

A prime that divides the answer already showed the small case of this: a modular elimination reports a singular matrix, truthfully, because the prime divides the determinant, and the residue itself gives no warning. This is that same phenomenon lengthened. A stop that takes each prime’s word for what it says inherits the same blindness once per prime.

So the plan’s virtue is real, and that is what the original essay meant. A count derived from a theorem cannot be fooled by the matrix. A count derived from what the computation has seen so far can. This matrix was built for the purpose, and its 160-bit entries show it, but nothing in the failure needs them: any determinant is a multiple of its own factors, and it is only an adversary, or extreme bad luck, that places several of those at the front of one particular list.

Randomness instead of a budget

That last observation points at the repair. The stop has no defence against a list that is known in advance. It does have a defence against bad luck, because the list can be chosen after the matrix.

The same built determinant with the primes drawn in random order from a pool of forty, over 2,000 draws: how often the stop is fooled, against the chance that the first primes all divide the built product6 bad primes, 1 repeat: measured 2.6e-2; by chance 1.9e-2; 6 bad primes, 2 repeats: measured 2.5e-3; by chance 2.0e-3; 12 bad primes, 1 repeat: measured 9.2e-2; by chance 8.5e-2; 12 bad primes, 2 repeats: measured 2.6e-2; by chance 2.2e-2; 12 bad primes, 3 repeats: measured 7.0e-3; by chance 5.4e-3.10⁻⁴10⁻³10⁻²10⁻¹16 bad primes, 1 repeat: measuredby chance6 bad primes, 2 repeats: measuredby chance12 bad primes, 1 repeat: measuredby chance12 bad primes, 2 repeats: measuredby chance12 bad primes, 3 repeats: measuredby chanceprobability of stopping on the wrong valuepool of forty · floored at 10⁻⁴a larger pool lowers every row
Fig. 6 The same built determinant with the primes drawn in random order from a pool of forty, over 2,000 draws: how often the stop is fooled, against the chance that the first primes all divide the built product.

Draw the primes in random order from the same pool of forty. A stop with one repeat on a matrix with six bad primes in the pool is fooled when both of its first two primes are bad, with a probability of about 1.9 per cent. Over 2,000 draws it is measured at 2.6 per cent, and it stays close to the calculated rate at each of the five settings in the figure, from 9.2 per cent measured against 8.5 calculated down to 0.7 against 0.54. Each extra repeat multiplies the probability by a small ratio.

Forty primes is a small pool, chosen so that the measurement could see the failures. The primes below 2262^{26} number about four million. If a determinant is bounded by BB bits, it can have at most B/26B/26 of them as factors, however it was built. So with the pool that large, the probability that a stop’s next prime is bad, once the value is wrong, is at most about B/26B/26 in four million. For the largest budget on this page, BB of 2,782, that bound is one in 37,000, and each further repeat multiplies by another factor of that size. This is a proved inequality rather than a measurement, and it holds against any matrix chosen without knowledge of the random draw.

So the choice is not really between a theorem and a guess. It is between a deterministic count, which costs the budget, and a probabilistic stop, which costs the need plus a few, with a failure probability that one prime buys down by four or five decades. Most exact libraries take the second, and it is why they can handle matrices whose budget is unaffordable.

What the saving is worth in eliminations

Each prime costs one elimination modulo that prime, about n3/3n^3/3 word multiplications. At order 32 that is 10,923, and the counts above turn directly into totals. The scaled Hilbert matrix pays 1.17 million under the plan and 382,000 under a stop with one repeat. The Pascal matrix pays 502,000 and 22,000. The Hadamard matrix pays 44,000 and 55,000, the one place in this table where the plan is cheaper, and by the price of the confirming prime.

Those are small numbers next to what the same determinant would cost by the route this field began with. The answer is longer than the question measures fraction-free elimination’s intermediates, which on these matrices reach the size of the bound, so that every multiplication is a multi-word one. That is the true reason a budget matters. A modular determinant at a budget of 107 primes does 107 eliminations in machine words, and it remains far cheaper than a single elimination with 2,800-bit numbers. The saving on offer here comes on top of a route that has already won, and an exact answer to a measured problem would add that for many matrices none of this matters, because entries measured to six digits do not deserve a determinant correct to eight hundred bits.

The budget’s size also has a practical side that the table at order 32 understates. The pool of primes below 2262^{26} runs out of bits nowhere near any of these budgets, but a matrix of order a thousand with entries of a hundred bits has a budget of about 10510^5 bits, or four thousand eliminations of a cubic cost. A plan that spends that whenever its row norms say so, on a matrix that might well have a small determinant, is not something a code can simply accept, and that is the pressure which pushes exact libraries towards adapting.

What a determinant cannot check and a solution can

There is a further distinction, which the fraction essay’s own closing step already contains. Its route ends with a verification: form Ay−dbAy - db in integers and confirm that it is zero. That one exact product turns an answer into a certificate. So a rational solver can use the early stop with no risk at all, however the primes came. It reconstructs when the value settles, multiplies, and either has a proof or has learned to try more. An adaptive solve that ends with that check is exact, and that is a stronger statement than either the plan or the stop makes on its own.

A determinant has no such check. Nothing cheaper than computing it confirms that a number is the determinant of a matrix; that is exactly why this family of failures is possible. The closest thing is a further random prime, which is what a repeat is. This is where a plan’s ability to say that it is right still has a real advantage, and the budget is therefore not wasted in the case where a guarantee is the point. The normal forms essay uses a determinant’s bound as a modulus, where a wrong value would silently corrupt everything else, and there the argument for the plan is at its strongest. The rank is in between: the field decides it usually measures how often a single prime gets a rank right, and a rank from a prime is at worst an underestimate, so it fails in one known direction, which a determinant’s residue does not.

What this leaves out

The cost of a prime here is one elimination, n3/3n^3/3 word operations, and the cost of the reconstruction is ignored. Garner’s incremental form costs on the order of k2k^2 limb operations over kk primes, which is small beside elimination at every size on this page. A real code would also not reconstruct after every prime, but in doubling batches, which makes the stop a bit later and the arithmetic cheaper.

The families were chosen to show the range rather than to represent what a person will meet. Six families cannot say how often a real matrix sits near each end, and a matrix from an integer programming model or a graph has its own distribution, about which nothing here is known. The pool used for the random draw is small, by design, and its first primes were the ones built into the fooling matrix, so these measurements test the failure when it is available to happen and not how a pool of millions would fare. And since dd here is a determinant, nothing in this measures early stopping on a matrix’s rank or on a solution.

Still open: a cheap estimate of the bits, and a stop that is also a solve

An estimate from floating point. A logarithm of a determinant is available from a floating-point LU at the cost of one factorisation, and its error is small even when the digits of the value are all gone. The prediction with a sign is that the floating-point value of log⁡2∣d∣\log_2 |d| is within ten bits of the truth on every family at every order here except the Hilbert matrices above order 16, so that a code could set a tight budget in advance for the cost of one prime. If it holds, the case for the stop shrinks to the matrices floating point cannot handle.

Doubling the batches. Reconstructing after 1, 2, 4, 8 primes rather than after each costs less arithmetic and may overshoot. The prediction is that with doubling the total of primes used is at most twice the need on every case here, that the reconstruction work falls below one elimination’s on all of them at order 32, and that the fooling matrix built on six primes still fools the stop unless the first batch exceeds six, so that a batching schedule hides the same failure at a different count.

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 theoremDeterminantExact arithmeticHadamard boundModular arithmeticUnlucky prime