Exact arithmetic, and what it costs instead

What reading the next pivot buys

In a fraction-free elimination every pivot is paid for twice — it multiplies every entry of its own step and divides every entry of the next — and the rule that picks the smallest pivot entry left a median 20 per cent above the least arithmetic any row order reaches. A rule that charges two steps ahead brings the median matrix to within 2.5 per cent, and on one matrix of twenty-four costs 1.87 times the least, worse than the smallest pivot ever does. Charging three steps ahead finds the least of all 40,320 orders on thirteen matrices and is never more than 27 per cent above it. And none of it pays: choosing that way costs forty to two hundred and sixty times the elimination it chooses.

Worth reading first: An answer with no error in it · Every intermediate is a minor.

The pivot is in every product priced a fraction-free elimination by its arithmetic rather than by the size of its numbers. Bareiss’s algorithm keeps every intermediate an integer — each is a minor of the original matrix, and every update is divided exactly by the previous pivot — and the cost of doing it, counted as the sum over every multiplication and division of the product of its operands’ bit lengths, depends on the order the rows are taken in far more than the bit-length profile does. On twelve 8 × 8 matrices, where all 40,320 row orders can be run, the natural order cost 1.748 times the least and the rule that picks the smallest nonzero pivot entry 1.165. The reason was the pivot’s double duty: it multiplies every entry of its own step, and it divides every entry of the next.

That made a rule that reads two pivots the obvious next step. “The division by the previous pivot is the largest part of the cost, so each pivot is paid for twice: once as a multiplier at its own step and once as a divisor at the next. A rule that chose the pivot to keep the product of this pivot’s length and the next one’s small … might close more of the distance to the least-cost order than the smallest pivot’s 1.165. The exhaustive search at n = 8 is the instrument that would say.”

Each pivot rule's area and cost over the least any row order reaches, on 8 × 8 matrices searched exhaustively12 random 8 × 8 integer matrices with entries in ±6, and on each every one of the 40,320 row orders run. Medians over the matrices of each rule's area under the bit-length profile over the least area any order reaches, and of its schoolbook cost over the least cost: natural order, area 1.052; natural order, cost 1.748; largest pivot, area 1.105; largest pivot, cost 2.419; smallest pivot, area 1.045; smallest pivot, cost 1.165; shortest row, original, area 1.041; shortest row, original, cost 1.566; shortest row, current, area 1.033; shortest row, current, cost 1.401; median order, area 1.074. The least-area order is 6.4 per cent below the median order.natural order, area1.052natural order, cost1.748largest pivot, area1.105largest pivot, cost2.419smallest pivot, area1.045smallest pivot, cost1.165shortest row, original, area1.041shortest row, original, cost1.566shortest row, current, area1.033shortest row, current, cost1.401median order, area1.074one is the best order, found by searchthe area has little room; the cost has a great deal
Fig. 1 The earlier measurement this essay starts from: on twelve 8 × 8 matrices, every row order run, and each rule’s area and cost over the least any order reaches.

The earlier figure is the starting line. The rules that read rows — the shortest original row, the shortest current row — sat at 1.4 to 1.6 times the least cost, the smallest pivot at 1.165, and the area under the bit-length profile barely separated any of them. Whatever room is left is in the cost, and it is the smallest pivot’s remaining sixth that a look-ahead has to find.

Four rules that look ahead

The rules are run on twenty-four matrices — the earlier essay’s twelve and twelve more from the same family, 8 × 8 with entries uniform in ±6\pm 6 — and every one is placed against the least cost any of the 40,320 row orders reaches on the same matrix. Beside the natural order and the smallest pivot, four rules read further:

  • The cheapest step simulates the elimination step each candidate pivot would perform and takes the one whose step costs least. It reads the pivot’s first duty exactly and its second not at all.
  • Two pivots ahead simulates each candidate’s step and then each possible next pivot’s step, and takes the candidate whose step plus cheapest next step is least. It reads both of a pivot’s duties.
  • Three pivots ahead does the same over three steps.
  • Smallest, then next takes the shortest pivot entry and breaks ties in bit length by the smallest pivot the step leaves for the step after — the cheap form of reading two pivots, with no step simulated.

A seventh, which estimates the two steps from bit lengths instead of computing them, is measured in its own section below.

The question for each is how close it comes to the least, on the median matrix and on the worst, and how often it finds the least exactly. The figure below is every rule at once.

The arithmetic six fraction-free pivot rules cost on twenty-four 8 × 8 integer matrices, over the least any of the 40,320 row orders reachesFor each rule, the median over twenty-four random integer matrices with entries in plus or minus six of its schoolbook cost — every multiplication and division charged at the product of its operands' bit lengths — divided by the least cost of any row order, with a whisker to the worst matrix and the number of matrices on which the rule is exactly least. natural order: median 1.733, worst 2.406, least on 0; smallest pivot: median 1.199, worst 1.609, least on 0; cheapest step: median 1.187, worst 1.574, least on 1; two pivots ahead: median 1.025, worst 1.871, least on 8; three pivots ahead: median 1.000, worst 1.267, least on 13; smallest, then next: median 1.217, worst 1.891, least on 0; two ahead, estimated: median 1.160, worst 1.871, least on 2.1.001.251.501.752.002.252.50cost ÷ the least any row order reachesnatural order1.733 · worst 2.41 · least on 0smallest pivot1.199 · worst 1.61 · least on 0cheapest step1.187 · worst 1.57 · least on 1two pivots ahead1.025 · worst 1.87 · least on 8three pivots ahead1.000 · worst 1.27 · least on 13smallest, then next1.217 · worst 1.89 · least on 0two ahead, estimated1.160 · worst 1.87 · least on 2bar: median · whisker: worst of twenty-fourthree pivots ahead finds the least on thirteen
Fig. 2 Every rule’s arithmetic over the least any row order reaches, on the median matrix and the worst of twenty-four, beside how often it finds the least exactly.

The cost being minimised is worth keeping in view, because exact arithmetic is the one setting in this field where the rounding error is zero and the cost is not. An answer with no error in it solved an integer system over the rationals and found the price had moved from accuracy to length: nothing is rounded, and every operation is paid for in the size of its operands. The answer is longer than the question showed that the output of an exact solve is unavoidably long. What a pivot order controls is the length of everything in between, and the schoolbook count — every multiplication charged at the product of its operands’ bit lengths — is that length turned into work. On these matrices the entries start at three or four bits and the intermediates reach twenty-odd; a product of two twenty-bit integers costs twenty-five times one of two four-bit integers, so an order that keeps intermediates a few bits shorter at the steps where most products happen saves a real share of the bill.

Reading one step’s cost reads no more than the pivot did

The cheapest-step rule has a median of 1.187 times the least, against the smallest pivot’s 1.199, and its worst is 1.574 against 1.609. On the twenty-four matrices that is no improvement worth the name, and it finds the least exactly on one of them where the smallest pivot finds it on none. The cheap tie-break does no better: smallest-then-next has a median of 1.217 and a worst of 1.891, the worst of every rule.

The tie-break rule’s failure is worth a sentence of its own, because it is the cheapest way anyone would think of to read two pivots. It groups the candidates by the bit length of their pivot entry and, within the shortest group, takes the one whose step leaves the smallest next pivot. On most matrices the shortest group has one or two members and the rule is the smallest pivot under another name — its median, 1.217, is within two hundredths of it. But a group defined by bit length is coarser than the smallest entry: a pivot of 4 and a pivot of 7 have the same length, and choosing between them by what they leave behind gave up the one thing the smallest pivot reads exactly. On matrix 943 it costs 1.891 times the least, slightly worse than the two-step rule, for the same reason.

That is the earlier essay’s mechanism confirmed from the other side. The smallest pivot entry was already the best single-step proxy for a step’s cost, because the pivot multiplies every entry of the step and the other operands are fixed by the matrix; simulating the step adds the cross terms and the division, and they move the choice on few matrices. What the smallest pivot cannot see is the second duty, the division its successor’s step will carry, and a rule that reads only one step cannot see it either.

Two pivots ahead, and the matrix it loses on

Two pivots ahead, against the smallest pivot, on each of twenty-four 8 × 8 integer matricesThe matrices ordered by the smallest-pivot rule's cost over the least any row order reaches; for each, that cost and the two pivots ahead rule's. The look-ahead is cheaper on 19 matrices, dearer on 2 and the same on the rest; its worst is 1.871 against the smallest pivot's 1.609.two pivots aheadcheaper than smallest pivot19dearer211.251.51.75matrix, ordered by the smallest pivot's costcost ÷ the leastsmallest pivottwo pivots aheadhorizontal line: the least any row order reachesa longer look is not always a better one
Fig. 3 One look-ahead rule’s cost over the least on each of twenty-four 8 × 8 matrices, beside the smallest pivot’s on the same matrix, the matrices ordered by the smallest pivot’s cost. The dial chooses how far the rule looks ahead.

Reading the next step changes the picture. The two-pivot rule’s median is 1.025 times the least: three quarters of the distance the smallest pivot left is gone, and on eight of the twenty-four matrices the rule finds the least exactly. On the matrices where the smallest pivot did worst — 1.609, 1.354, 1.313 — it reaches 1.000, 1.002 and 1.000. That is the prediction the earlier essay made, and on the median matrix it is right by more than it asked for.

The dial’s second stop shows the exception. On one matrix, number 943, the two-pivot rule costs 1.871 times the least, where the smallest pivot costs 1.165 — worse than the smallest pivot is on any of the twenty-four, and second only to the natural order’s worst of 2.406. It is cheaper than the smallest pivot on nineteen matrices, the same on three, and dearer on two, and one of the two is that.

One 8 × 8 integer matrix, step by step: what each elimination step costs when the pivot is chosen two steps ahead, three steps ahead, and in the least-cost orderThe schoolbook cost of each of the seven steps of a fraction-free elimination. Two pivots ahead totals 12627, three pivots ahead 8550, the least-cost row order 6750: 1.871 and 1.267 times the least. Two pivots ahead takes the cheaper first steps and pays for them later, at steps whose cost it never looked at.matrix 943two ahead ÷ least1.9three ahead ÷ least1.3123456710²10³10⁴elimination stepbit-products in the steptwo pivots aheadthree pivots aheadleast-cost orderlogarithmic: each step's own billa cheap pair now, a dear step later
Fig. 4 Matrix 943, step by step: the schoolbook cost of each of the seven elimination steps when the pivot is chosen two steps ahead, three steps ahead, and in the least-cost row order, on a logarithmic axis.

The step-by-step costs say what happened. The two-pivot rule’s first steps are as cheap as the least-cost order’s or cheaper — it found a pair of pivots that made steps one and two inexpensive — and its later steps are expensive, three to four times the least-cost order’s at steps four to six. A rule that charges two steps chooses the cheapest pair it can see, and a cheap pair can leave the remaining rows with long entries and no short pivot among them; the bill arrives at steps the rule never charged. The dial’s third stop, the estimated version of the same rule, makes the same choice on this matrix and is described below. It is the horizon effect of any greedy search with a fixed depth, and one step ahead is one step short met the same thing in floating-point elimination, where a rule that looked one step ahead at growth was defeated by a matrix whose damage arrived one step later.

Three pivots ahead

Charging three steps finds the least of all 40,320 orders on thirteen of the twenty-four matrices, has a median of exactly 1.000, and its worst is 1.267 — on matrix 943, where the two-pivot rule’s 1.871 came from; the third step sees the bill the second did not. It is the best rule measured on every summary: median, worst and count of exact hits. Of the matrices where it does not find the least, it is within five per cent on eight.

So the distance between a local pivot rule and the least arithmetic is mostly a matter of horizon. A rule that reads one pivot leaves a fifth of the cost on the table; reading two takes most of it back and introduces a tail; reading three takes nearly all of it back and shortens the tail. Nothing about the measurement suggests that a fourth step would find much: the three-step rule is already at the least on more than half the matrices, and on the rest it is within a few per cent but for two.

And none of it pays

What each pivot rule spends choosing its pivots, against what the elimination it chooses costs, both over the least eliminationMedian over twenty-four 8 × 8 matrices. Horizontally, the schoolbook cost of every step the rule simulates while choosing, the kept ones included, over the least elimination's cost; vertically, the cost of the elimination it produces over the same. smallest pivot: spends 1.2, produces 1.199; two ahead, estimated: spends 1.2, produces 1.160; cheapest step: spends 5.9, produces 1.187; smallest, then next: spends 6.0, produces 1.217; two pivots ahead: spends 42.8, produces 1.025; three pivots ahead: spends 260.4, produces 1.000. The smallest pivot and the estimated rule form no large product while choosing and are placed at their own cost.the look-ahead's own billtwo pivots ahead: spent ÷ least43three pivots ahead: spent ÷ least260110¹10²11.051.11.151.2spent choosing ÷ the least eliminationelimination's cost ÷ the leastsmallest pivottwo ahead, estimatedcheapest stepsmallest, then nexttwo pivots aheadthree pivots aheada rule pays for itself left of a spend of onethe search is the expensive part
Fig. 5 What each rule spends simulating elimination steps while it chooses, against what the elimination it produces costs, both over the least elimination’s cost, median over twenty-four matrices.

Every look-ahead rule chooses by doing the work it is trying to avoid. The cheapest-step rule simulates one step per candidate at every step — eight candidates, then seven, down to two — and its simulations cost 5.9 times the least elimination on the median matrix. The two-pivot rule simulates every candidate and every successor, 42.8 times. The three-pivot rule simulates every candidate, successor and third pivot, 260 times. The elimination each one produces saves at most a fifth of one elimination over the smallest pivot. No look-ahead measured here comes within a factor of five of paying for itself, and the one that saves the most costs the most.

That is the real answer to the earlier essay’s question. Reading two pivots closes most of the distance to the least-cost order, and the distance was worth closing — the smallest pivot’s median matrix pays a fifth more than it has to. But a rule that reads the next pivot by computing the next step has spent the step to learn its price. The smallest pivot is cheap because it reads one number per row; any rule that improves on it has to read the next step’s cost from something cheaper than the step.

A reading that estimates instead of simulating

The obvious way out is to estimate the next step’s cost instead of performing it. A step’s cost is a sum of products of bit lengths, and the bit length of each new entry (p a−b c)/q(p\,a - b\,c)/q is, to within a bit, the larger of len⁡(p)+len⁡(a)\operatorname{len}(p) + \operatorname{len}(a) and len⁡(b)+len⁡(c)\operatorname{len}(b) + \operatorname{len}(c), less len⁡(q)\operatorname{len}(q) — the division is exact, so it removes the divisor’s length. Every quantity a look-ahead needs can therefore be carried on a matrix of lengths, small integers, without forming a single large product. Choosing that way costs no bit-products at all; the real elimination is then run in the order chosen.

The estimate keeps little. On the same twenty-four matrices the estimated two-step rule has a median of 1.160 times the least, against the simulated rule’s 1.025 and the smallest pivot’s 1.199; it finds the least on two matrices, where the simulated rule found it on eight; and it is cheaper than the smallest pivot on thirteen matrices and dearer on seven. A bit of error in each estimated length, compounded over the sixty-odd entries of a step and over two steps, is enough to reorder candidates whose true costs differ by a few per cent, and those are exactly the candidates a look-ahead exists to tell apart.

And on matrix 943 the estimated rule costs 1.871 times the least — the same choice, to three figures, that the simulated two-step rule made. Its tail is not an artefact of simulation; it is the horizon. Both rules see two steps, both find the same cheap pair, and both pay for it at steps four to six. A better estimate could recover the median the simulated rule reached, but no estimate of two steps can see the third.

So the arithmetic has a shape that no cheap rule measured here escapes. The smallest pivot is cheap and leaves a fifth of the cost. A two-step look-ahead recovers most of that fifth only when it computes the steps it reads, which costs forty times the elimination, and keeps a tail either way. A three-step look-ahead removes the tail and costs two hundred and sixty times. Three orders and one last entry found that no order can move the elimination’s peak — the last entry is the determinant — and these measurements add the companion fact about its cost: the order can move it by a fifth, and finding the order that does is far more expensive than the fifth.

That is not a reason to stop at the smallest pivot in every setting. An elimination that is run many times on matrices of one structure — the same sparsity, entries from the same distribution — could pay for a search once and reuse the order it finds, and on twenty-four random matrices the three-step order and the least-cost order were the same thirteen times. Whether an order found on one matrix of a family is near the least on its siblings is the measurement that would say whether the search can be amortised; every intermediate is a minor suggests why it might, since the minors a row order produces depend on the matrix only through which rows meet first.

The least fill there is found the same pattern in sparse elimination, where every order was searched and the cheap local rule placed against the optimum: a greedy rule near the optimum on the median and occasionally far from it, for reasons no single step can see.

What twenty-four matrices do not show

One size, eight, because the least-cost order has to be found by trying all 40,320; at larger sizes the look-ahead rules can still be compared with each other and with the smallest pivot but not with the least. One family, uniform entries in ±6\pm 6, where rows do not differ much in length; the pivot is in every product found that spreading the rows’ lengths separates rules that read rows from rules that read pivots, and a look-ahead might separate further there. And one cost model, schoolbook multiplication, which is right for integers of tens of bits and wrong for integers of thousands, where a subquadratic multiplication makes a long operand relatively cheaper and the pivot’s double duty a smaller share of the bill.

Still open: an order found once, and what the least-cost order looks like

An order reused across a family. The three-step order matched the least-cost order on thirteen of twenty-four matrices, at two hundred and sixty times an elimination’s cost to find. If the order found on one matrix is within a few per cent of the least on matrices drawn from the same family — the same size, the same entry distribution, or the same sparsity — the search is paid once and amortised. The prediction with a sign is that it is not: on these matrices the least-cost order depends on which rows happen to have short entries in which columns, and a reused order should do no better than the natural order’s 1.733.

What the least-cost order looks like. On thirteen matrices the three-step rule reproduces the least-cost order exactly, so on those matrices the least-cost order is a sequence of locally excellent three-step choices. On the other eleven it is not, and the least-cost order there does something no three-step window sees. Reading those eleven orders — whether they take an expensive pivot early to buy short rows later, and how early — is the measurement that would say what a fourth step would have to look for.

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.

Bit lengthDeterminantExact arithmeticExact ground truthFraction-free eliminationGreedy algorithmMinorPermutation