Where the flop count stopped predicting the time

Doing it twice

Cholesky QR squares the condition number — a fitted slope of 1.95 in κ against the Householder sweep's 1.00. Run the identical routine a second time on the Q it returned and the slope is 0.93, the orthogonality is at or below the sweep's at every κ, and the price is one more all-reduce.

Worth reading first: A reduction that changes the order · The road that squares the problem · Orthogonal is a number.

The message and the word put three factorisations of one matrix on two axes and found they rank differently on each: 48, 4 and 4 communication rounds against 1,170, 1,170 and 2,160 words. The method with the fewest rounds — Cholesky QR, which forms G = AᵀA in a single all-reduce and factorises it locally — pays for that with the site’s oldest currency.

κ(AᵀA) = κ(A)². The implied orthogonality of Cholesky QR’s Q has a fitted slope of 1.95 in κ where the Householder sweep and the reduction tree stay at 1.00, and past κ ≈ 3·10¹⁰ the Gram matrix is numerically indefinite and the factorisation stops.

The repair is one line.

Implied orthogonality of four factorisations of a 256×8 matrixFour curves against the condition number, both axes logarithmic. Cholesky QR's implied orthogonality has a fitted slope of 1.99 and reaches 0.373; the same routine run twice has a slope of 0.96 and reaches 3.75·10⁻⁹, which is where the Householder sweep and the reduction tree are.10²10³10⁴10⁵10⁶10⁷10⁸10⁻¹⁴10⁻¹¹10⁻⁸10⁻⁵10⁻²condition number‖QᵀQ − I‖one passsweeptwicetreewhat the second pass removesfitted slope, one pass2fitted slope, two passes0.96rounds, two passes6rounds, the sweep24one pass squares the condition numberand two do not
Fig. 1 Four factorisations of one matrix, at seven condition numbers. Two of the four curves are the same routine, run once and twice.

The one line

Q₁R₁ = A by Cholesky QR. Then Q₂R₂ = Q₁ by Cholesky QR again. Take Q = Q₂ and R = R₂R₁.

κ(A) Cholesky QR twice Householder tree
10² 2.3·10⁻¹³ 5.1·10⁻¹⁵ 2.7·10⁻¹⁴ 1.2·10⁻¹⁴
10⁴ 2.3·10⁻⁹ 5.2·10⁻¹³ 3.4·10⁻¹² 8.6·10⁻¹³
10⁶ 1.9·10⁻⁵ 9.8·10⁻¹² 1.5·10⁻¹⁰ 5.2·10⁻¹¹
10⁸ 3.7·10⁻¹ 3.8·10⁻⁹ 8.5·10⁻⁹ 7.5·10⁻⁹
10¹⁰ 1.3 3.7·10⁻⁷ 3.0·10⁻⁷ 2.4·10⁻⁷

Fitted slopes: 1.95 for one pass, 0.93 for two. The square is gone, and what is left is κu, which is what a backward-stable factorisation costs and what the other two methods have.

The second column is not merely improved. At every condition number in the table it is at or below the Householder sweep’s — the sweep being the reference implementation of a backward-stable QR, and the method Cholesky QR was supposed to be a cheap and inferior substitute for.

Why a second pass is enough, and a third is not

The mechanism is short enough to state and is the reason this is not a trick.

The first pass returns a Q₁ whose orthogonality error is of order κ²u. That means κ(Q₁) is about 1 + κ²u rather than κ: it is nearly orthogonal, and how nearly is exactly what the first pass got wrong. The second Cholesky QR squares that condition number — and squaring a number that is nearly one leaves a number that is nearly one.

So the second pass has an easy problem precisely because the first pass had a hard one, and the composition lands at u rather than at κ⁴u or at anything else the arithmetic might have suggested.

The two condition numbers, measured rather than asserted:

κ(A) κ(A)² κ(AᵀA), measured κ(Q₁)
10² 10⁴ 1.00·10⁴ 1.0000
10⁴ 10⁸ 1.00·10⁸ 1.0000
10⁶ 10¹² 1.00·10¹² 1.0000
10⁸ 10¹⁶ 6.28·10¹⁵ 1.2625

The first two columns agree to three digits over twelve decades, which is the squaring happening exactly as the algebra says — and the last column is the reason the second pass is cheap. The matrix handed to it has a condition number of one, to four decimal places, at every κ where the first pass returns anything usable at all. At κ = 10⁸, where the first pass’s Q is 0.37 from orthogonal, κ(Q₁) is 1.26.

Squaring 1.26 is 1.59. Squaring 10⁸ is 10¹⁶, which is past 1/u and is where the method stops.

A third pass has nothing left to do, and that is the refusal this essay’s library publishes: feeding the build the claim that a third pass improves the accumulated orthogonality by an order of magnitude must fail, because the second pass has already reached the floor a backward-stable factorisation has.

‖QᵀQ − I‖ of the implied Q, against the condition numberLoss of orthogonality against κ, both axes logarithmic, for three factorisations of the same 256×8 matrix. The column sweep and the reduction tree run from 2.7·10⁻¹⁴ to 1.5·10⁻¹⁰. Cholesky QR — the one with a single reduction — runs from 2.3·10⁻¹³ to 1.8·10⁻⁵, a fitted slope of 1.97 against the others' near-flat one.10²10³10⁴10⁵10⁶10⁻¹⁴10⁻¹²10⁻¹⁰10⁻⁸10⁻⁶condition number κ‖QᵀQ − I‖Cholesky QRsweeptreethe price of one roundfitted slope, Cholesky QR2‖QᵀQ − I‖ at κ = 10·10⁵1.8·10⁻⁵the sweep's, at the same κ1.5·10⁻¹⁰one reduction instead of nand the condition number squared
Fig. 2 The κ² this removes, from the communication field: Cholesky QR’s implied orthogonality against the two backward-stable methods, with the fitted slope of 1.97 that the second pass takes to 0.93.

What it costs, counted

One more all-reduce of n² numbers.

method rounds words
Cholesky QR 3 448
Cholesky QR twice 6 896
Householder sweep 24 252
reduction tree 3 252

At p = 8 and n = 8. The sweep needs one reduction per column, so its rounds grow with n; the two Cholesky runs need one and two whatever n is.

A quarter of the sweep’s rounds for the same orthogonality is the headline, and the honest sentence beside it is that the reduction tree spends 3 rounds and 252 words and reaches the same place. On both counts this file measures, the tree is the better method.

What Cholesky QR twice has instead is its shape: two Gram matrices, two Cholesky factorisations and two triangular solves, every one of them a dense matrix–matrix operation, with no tree, no user-defined reduction operator and no dependency between processors beyond two collective calls that every library already implements. That is an argument about what a machine is fast at rather than about what it counts, and this essay does not make it — it counts.

Communication for a 512×12 factorisation on 16 processorsTwo counts for the same factorisation. Rounds on the critical path: 48 for the column sweep, 4 for the reduction tree, 4 for Cholesky QR — a factor of n between the first and the other two. Words sent: 1170, 1170 and 2160 — the sweep and the tree send the same number, and the method with the fewest rounds sends the most.rounds on the critical pathHouseholder sweep48reduction tree4Cholesky QR4words sentHouseholder sweep1170reduction tree1170Cholesky QR2160two counts, two rankingsrounds, sweep ÷ tree12words, Cholesky ÷ tree1.8arithmetic, tree ÷ sweep1.5the rounds separate the threeand the words do not
Fig. 3 The two counts that rank the same methods differently, from the field this essay sits in. The pair of Cholesky passes lands in the same corner as one pass, at twice the distance from the origin.

The boundary is the first pass’s boundary

Running it twice cannot repair a first pass that refused, and this is where the honest reporting has to be careful, because the first pass’s failure is not a threshold.

κ(A) Cholesky QR twice Householder
3·10¹⁰ refused at column 7 refused, first pass 6.7·10⁻⁶
10¹¹ refused at column 6 refused, first pass 7.5·10⁻⁶
3·10¹¹ 1.62 1.2·10⁻⁶ 3.5·10⁻⁵
10¹² 1.49 7.9·10⁻⁵ 1.4·10⁻⁴

It refuses at 3·10¹⁰ and 10¹¹ and returns an answer at 3·10¹¹ and 10¹² — an answer on a worse-conditioned matrix than one it declined, which is the erratic boundary the communication field already recorded for one pass and which two passes inherit unchanged.

And where it does return past the cliff, the second pass is better than the Householder sweep: 1.2·10⁻⁶ against 3.5·10⁻⁵ at κ = 3·10¹¹. The first pass’s Q there is 1.62 from orthogonal — worse than useless — and the second pass turns that into an answer an order of magnitude better than the reference method’s.

That combination is worth sitting with. The method either declines or returns something good, and which of the two it does is not predictable from κ. A code that treats a refusal as a signal to fall back is doing the right thing; one that treats κ as a guide to whether to try is not.

Every method reconstructs, including the one whose Q is worthless

The site’s rule earns its place here more than anywhere.

At κ = 10⁸ all four methods reconstruct A to about 10⁻¹⁶:

method ‖A − QR‖/‖A‖ ‖QᵀQ − I‖
Cholesky QR 1.2·10⁻¹⁶ 3.7·10⁻¹
twice 9.8·10⁻¹⁷ 3.7·10⁻⁹
Householder 1.1·10⁻¹⁶ 8.5·10⁻⁹
tree 1.1·10⁻¹⁶ 7.5·10⁻⁹

The residual — the quantity anybody checks a factorisation with — is identical to two significant figures across a method whose Q is 37% wrong and three whose Q is right to nine digits.

That is the refutation this essay publishes, and it is not a subtle one: a residual says nothing about orthogonality. The reason is structural rather than numerical. Q = AR⁻¹ by construction, so QR = A whatever R is, as long as R is invertible; the residual is testing the triangular solve and nothing else.

QᵀQ from classical Gram–Schmidt and from Householder on the 8×8 Hilbert matrixTwo eight-by-eight tables of QᵀQ. The upper one has ones on the diagonal and entries as large as one off it; the lower one is the identity to three decimal places everywhere.A = H8 · κ = 1.5·10¹⁰ · both factorisations reconstruct A to 6·10⁻¹⁷the diagonal is 1 in both — every column is a unit vector either way1.000000000001.000000000001.000000000001.000000000001.00000.002-0.002000001.0000.125-0.13300000.0020.1251.000-1.0000000-0.002-0.133-1.0001.000classical Gram–Schmidt1.000000000001.000000000001.000000000001.000000000001.000000000001.000000000001.000000000001.000Householderclassical ‖QᵀQ − I‖1.4Householder ‖QᵀQ − I‖1.4·10⁻¹⁵largest off-diagonal 1 against 3.1·10⁻¹⁶length is not angle
Fig. 4 The site’s founding measurement: ‖QᵀQ − I‖ printed beside a reconstruction that is perfect either way. The rule that no decomposition is drawn without its residual exists because of exactly the row at the top of the table above.

Two passes, and where the idea comes from

The construction has a name and a literature and this essay measures it rather than deriving it, so it is worth saying what was already known and what was checked.

Known: that Cholesky QR’s orthogonality degrades like κ², that a second pass restores it while κ²u < 1, and that the composition is what the published analysis calls CholeskyQR2. None of that is a finding here.

Checked: the two slopes, on this site’s own matrices, with the site’s own implied-orthogonality measure — 1.95 and 0.93 rather than 2 and 1. The claim that the second pass reaches the Householder sweep’s accuracy rather than merely improving, which the table above makes precise and which is stronger than the usual statement. The round and word counts, from the same network model the communication field uses for the other three methods, so the four are comparable. The behaviour past the cliff, which is where the published analysis stops and where the erratic refusals live. And the residual, which is identical across a method whose Q is 37% wrong and three whose Q is right.

The last of those is the one this site adds. Every published comparison of these methods reports orthogonality; the reason the residual belongs beside it is that the residual is what a reader would otherwise check, and it says nothing at all.

What the second pass does not fix

Three things, and the third is the one that would matter in practice.

It does not make the residual mean more. Both passes produce a Q from a triangular solve, so QR = A either way and the reconstruction is uninformative either way. A code that wants to know whether its Q is orthogonal has to measure ‖QᵀQ − I‖, which costs a product the factorisation was trying to avoid.

It does not extend the range. The cliff is where the first pass’s Gram matrix goes indefinite, and that is a property of κ(A)²u alone. Two passes have exactly the range one pass has.

And it does not help a matrix that is rank-deficient rather than ill-conditioned. Everything here is measured on matrices with a prescribed condition number and full numerical rank. A tall-skinny matrix with a genuinely dependent column has a singular Gram matrix, the first Cholesky refuses at that column, and there is nothing for a second pass to be run on — where the reduction tree and the sweep both return an R with a zero on the diagonal and let the caller decide what that means.

That last one is the practical reason the tree stays the default in libraries, and it is worth stating because it is not a numerical argument at all: it is about what a routine does when the input is not what it was promised.

Where this sits among the site’s second passes

Running something twice to buy back accuracy is a shape this site has met three times now, and the three are worth laying beside each other because they are not the same trade.

Iterative refinement solves the system again against the residual of the first solve, and buys back the digits a low-precision factorisation lost — but only while κu < 1, and the mixed-precision field measured the threshold at exactly that boundary.

Reorthogonalising a Gram–Schmidt step projects a second time against the vectors already orthogonalised against, and takes ‖QᵀQ − I‖ from 10⁻² to 10⁻¹⁶ — the twice is enough, measured table the standard pass added to the orthogonality field.

And this. A second Cholesky QR, which is the same idea one level up: the object being re-processed is a whole factorisation rather than a vector or a right-hand side.

All three work for one reason. The first pass produces something whose error is a known function of the input’s conditioning, and the second pass sees an input whose conditioning is that error rather than the original problem’s. Composing a squaring with a nearly-one leaves a nearly-one — which is why the answer is always twice, in all three cases, and never three times.

Iterative refinement from a 24-bit factorisation, κ = 10⁴A semi-logarithmic plot of forward error against refinement step. One curve falls steeply to the level of a double-precision solve; the other is nearly flat.012345610⁻¹⁶10⁻¹³10⁻¹⁰10⁻⁷10⁻⁴10⁻¹refinement step‖x − x*‖ / ‖x*‖a full double-precision solveresidual in24-bitresidual indoubleone argument apartκ·u of the factorisation6·10⁻⁴double residual, final3.2·10⁻¹³same-precision, final1.3·10⁻⁴30×30, κ = 10⁴, same factors in both runsidentical cost
Fig. 5 The oldest of the three on this site: iterative refinement recovering the accuracy a low-precision factorisation lost, with the same κu boundary past which it stops working. The pattern in this essay is that one with a factorisation in place of a solve.

When to use which

The measurements support a short table rather than a recommendation, and the entries are about what a machine is slow at rather than about the matrices.

If the reduction is cheap — a small machine, a fast network, a factorisation that is not on the critical path — the Householder sweep is the reference and there is no reason to leave it. It costs n reductions and nothing else on this page beats it for simplicity.

If the reduction is expensive and κ is under about 10⁷, two Cholesky passes give the sweep’s orthogonality for two collective calls, in an arithmetic that is entirely matrix–matrix.

If κ is unknown, the refusal is the feature. The first pass declines rather than lying — usually — and a code that falls back on a refusal is correct; a code that trusts κ to predict the refusal is not, because the boundary is erratic and it returned an answer at 3·10¹¹ having refused at 10¹¹.

And if the reduction is expensive and the matrix might be badly conditioned, the reduction tree does everything this method does with fewer rounds and fewer words, and it never refuses. That is the conclusion this essay’s own counts point to, and the argument against it is one about implementation shape rather than about arithmetic — which is the honest place to leave it.

Past the cliff: what each method returnsLoss of orthogonality at four condition numbers past κ²u = 1. Cholesky QR returns a factor whose implied Q is 0.37 away from orthogonal at κ = 10⁸ and 1.49 at 10¹² — and at 3·10¹⁰ it refuses outright, on a pivot of -6.5·10⁻¹⁷. The sweep and the tree return a usable factorisation of every one of these matrices.‖QᵀQ − I‖ of the implied Qκ = 10⁸, Cholesky0.37κ = 10⁸, sweep8.5·10⁻⁹κ = 10¹⁰, Cholesky1.3κ = 10¹⁰, sweep3·10⁻⁷κ = 3·10¹⁰, Choleskyrefusedκ = 3·10¹⁰, sweep6.7·10⁻⁶κ = 10¹², Cholesky1.5κ = 10¹², sweep1.4·10⁻⁴the safe run is the one that failsrefusals in the range1wholly non-orthogonal returns2the pivot it refused on-6.5·10⁻¹⁷one of these outcomes is safeand it is the refusal
Fig. 6 The cliff both passes inherit: past it the first Cholesky either refuses or returns something far from orthogonal, and which of the two is not predictable from κ.
Four factorisations of one 512×12 matrix, κ = 7151A ranked bar chart of the departure from orthogonality, on a logarithmic scale. Classical Gram–Schmidt loses 4.6·10⁻¹⁰, modified 1.5·10⁻¹², Householder 2·10⁻¹⁴. The reduction tree, which touches the matrix once instead of 12 times, is of the same size as Householder's — and its error does not grow with the depth of the tree.classical Gram–Schmidt4.62·10⁻¹⁰modified Gram–Schmidt1.49·10⁻¹²Householder, one sweep2.03·10⁻¹⁴reduction tree, 16 leaves1.48·10⁻¹⁵departure from orthogonality, logarithmicthe tree, at four depths‖AᵀA − RᵀR‖/‖AᵀA‖, depth 13.4·10⁻¹⁵‖AᵀA − RᵀR‖/‖AᵀA‖, depth 24.3·10⁻¹⁵‖AᵀA − RᵀR‖/‖AᵀA‖, depth 31.7·10⁻¹⁵‖AᵀA − RᵀR‖/‖AᵀA‖, depth 41.5·10⁻¹⁵the same algebra, four timestwo of them are products of reflections
Fig. 7 The method that beats this one on both counts. The reduction tree spends three rounds and 252 words and reaches the same orthogonality, which is the honest comparison.

What the residual is measuring instead

One more observation about the residual table, because it explains why every number in that column is the same.

Q is formed as AR⁻¹ in all four methods — that is what impliedOrthogonality does, and it is what a caller who solves a least-squares problem through R is implicitly doing. So QR is A R⁻¹ R, and the residual ‖A − QR‖ is measuring the accuracy of a triangular solve followed by a triangular multiply, which is a backward-stable pair whatever R happens to be.

That makes the residual a test of the triangular arithmetic and nothing else. It would catch an R with a garbage entry, a wrong dimension, a transposed factor. It cannot catch an R that is a perfectly good triangular factor of the wrong Gram matrix, which is exactly what Cholesky QR returns past its cliff.

The measurement that does catch it is ‖QᵀQ − I‖, and it costs a product the whole family of methods was designed to avoid — n² inner products of length m, which is the same order as the factorisation itself. That is the reason the check is not routinely made, and the reason this site prints it on every figure that draws a factorisation.

What the drag does

The slider is the number of columns, and it moves one thing and leaves another alone.

What moves is the sweep’s cost: one reduction per column, so at n = 16 the Householder sweep spends 48 rounds where the two Cholesky passes still spend 6. The advantage the second pass has in synchronisations grows linearly with the width.

What does not move is either slope. κ² is a property of forming AᵀA and κ is a property of not having to, and neither depends on the shape of the matrix — which is why the figure asserts the two slopes at every position of the slider rather than at one.

The slider starts at six columns rather than four, and the reason is the cliff. At four columns the Gram matrix of a κ = 10⁸ matrix is already numerically indefinite, the first pass refuses, and the curve cannot be drawn through a refusal — which is the same boundary the table above is about, arriving in the figure’s own assertion.

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.

All reduceBackward stabilityCholesky qrCommunication avoidingCondition numberGram matrixNormal equationsOrthogonality lossReorthogonalisationUnit roundoff