When the problem arrives again

The sum can be single, the residual cannot

A sliding least-squares window's correction has to read every row, so the cheaper correction proposed instead was one whose residual is formed in single precision and summed in double. It was predicted to cost little at κ(A) = 3·10⁴ and a great deal at 3·10⁶. It costs seven to eight decades at both: the window ends at 3.7·10⁻² instead of 3.3·10⁻⁹ at the worse conditioning and at 3.1·10⁻⁴ instead of 2.2·10⁻¹² at the better. The single residual's error is a fixed fraction of single precision's unit roundoff times κ(A), at every noise level, because its rounding reaches the answer through the rows themselves and is amplified once, not squared. The other half of the correction behaves the other way: summing the rows weighted by a double residual in single is free when the data fit exactly and costs in proportion to the residual otherwise, two decades for every decade of κ.

Worth reading first: Stable once, and three thousand times · The projection and the right angle · Buying the accuracy back.

A correction that reads every row took a sliding least-squares window — 24 rows over six nearly parallel columns, a new row in and an old one out at every step — and asked whether its correction could read fewer rows. The window moves its answer by the update its two changed rows imply, then corrects it once: d=G−1AT(y−Aβ)d = G^{-1}A^{\mathsf T}(y - A\beta), a Newton step on the window’s least-squares problem, with G=ATAG = A^{\mathsf T}A held as a Cholesky factor. Read from any subset of the rows, even 23 of 24, the correction converged to the subset’s own answer, which on noisy collinear data is wrong by a relative error of order one. Every row has to be read.

The essay ended on the other way to make the correction cheaper. “A correction’s cost is reading every row and forming the residual. Computed in single precision and accumulated in double, the residual costs less to form and still sums over every row. The prediction with a sign is that a full correction with a single-precision residual ends within a factor of ten of the double-precision one at κ(A)=3⋅104\kappa(A) = 3 \cdot 10^4 and more than a hundred times above it at 3⋅1063 \cdot 10^6, where the residual’s own rounding, amplified by G−1G^{-1}, is the larger term.”

The second half holds, by five decades more than it asked. The first half fails by seven. The mechanism it named was wrong in a way that matters, because the rounding of the residual is not amplified by the square of the conditioning, and the half of the correction that is amplified that way turns out to be the half that can sometimes be made cheap.

Three ways to form a correction

The streams are the earlier essays’: rows of six integer columns built from one large base value plus small perturbations of a chosen spread, so the columns are nearly parallel and the window’s rows have a condition number set by the spread. Across the windows of a stream κ(A)\kappa(A) ranges over a factor of two, from 1.6 to 3.4 times its median; the earlier essays named the worst stream by the top of that range, 3⋅1063 \cdot 10^6, and its median is 2.2⋅1062.2 \cdot 10^6. This essay uses four streams, at medians of about 2⋅1032 \cdot 10^3, 2⋅1042 \cdot 10^4, 2⋅1052 \cdot 10^5 and 2⋅1062 \cdot 10^6, with an integer response carrying noise from none to the size of the data. Every number is checked against the window’s exact least-squares answer, computed in rationals from the integer data, at every fiftieth step.

Each step’s correction reads all 24 rows and is formed four ways. In double, as before. With the residual ri=yi−aiTβr_i = y_i - a_i^{\mathsf T}\beta formed in single — every operand rounded to binary32 and every product and difference rounded too — and ATrA^{\mathsf T}r then summed in double. With the same single residual but the answer split into its binary32 head and the double remainder, so that only the head’s products are rounded. And the other way round: the residual in double, and the sum ATrA^{\mathsf T}r formed in single.

Seven decades at both conditionings

A sliding window's median error against the condition number of its rows, at noise 1, when every step's correction forms its residual in double, forms it in single, or forms it in double and sums the rows weighted by it in single, beside the unit roundoff of single and of double times κ(A)single residual: 3.7e-2, 3.6e-3, 3.1e-4, 3.4e-5; single sum, double residual: 5.5e-2, 6.4e-3, 1.3e-3, 8.6e-5; double: 3.3e-9, 2.4e-11, 2.2e-12, 2.5e-13 at κ(A) about 2.1·10⁶, 2.2·10⁵, 2.2·10⁴, 2.2·10³.10³10⁴10⁵10⁶10⁻¹⁴10⁻¹²10⁻¹⁰10⁻⁸10⁻⁶10⁻⁴10⁻²1κ(A), median over the windowsrelative error, mediansingle's unit roundoff × κdouble's × κsingle residualsingle sum, double residualdoublenoise 1, every step corrected against all 24 rowsthe residual sets the floor
Fig. 1 A sliding window’s median error against the median condition number of its rows, at noise 1, when every step’s correction forms its residual in double, forms it in single, or forms it in double and sums ATrA^{\mathsf T}r in single. The dashed lines are single’s and double’s unit roundoff times κ(A).

At the worst conditioning and noise one the double correction ends at 3.3⋅10−93.3 \cdot 10^{-9}, the number the earlier essay measured, and the single residual at 3.7⋅10−23.7 \cdot 10^{-2}: eleven million times worse, the hundredfold the prediction asked for with five decades to spare. At κ(A)\kappa(A) about 2⋅1042 \cdot 10^4 the double correction ends at 2.2⋅10−122.2 \cdot 10^{-12} and the single residual at 3.1⋅10−43.1 \cdot 10^{-4}, a hundred and forty million times worse, where the prediction said ten. It is not the noise: at that conditioning the single residual ends between 6⋅10−56 \cdot 10^{-5} and 3⋅10−43 \cdot 10^{-4} at every noise level from one to none, and the double between 10−1310^{-13} and 2⋅10−122 \cdot 10^{-12}. Six and a half to nine decades separate them on every noisy stream, at every conditioning.

The single residual’s error falls by a factor of 9 to 12 for each decade of κ(A)\kappa(A): 3.7⋅10−23.7 \cdot 10^{-2}, 3.6⋅10−33.6 \cdot 10^{-3}, 3.1⋅10−43.1 \cdot 10^{-4} and 3.4⋅10−53.4 \cdot 10^{-5} from the worst stream to the best. That is one decade of error per decade of conditioning, not two, and it sits on a line parallel to single’s unit roundoff times κ(A)\kappa(A): between 0.04 and 0.5 of 2−24κ(A)2^{-24}\kappa(A) on every noisy stream. The double correction sits on the matching line for double at three of the four conditionings and a decade above it at the worst.

Why the residual’s rounding is amplified once

The prediction reasoned that the residual’s rounding is “amplified by G−1G^{-1}”, and G−1G^{-1} carries the square of the condition number. But the rounding does not reach G−1G^{-1} on its own. It enters as a perturbation δr\delta r of the residual, and the correction applies ATA^{\mathsf T} to it before it applies G−1G^{-1}: the step’s error is G−1ATδr=A+δrG^{-1}A^{\mathsf T}\delta r = A^{+}\delta r, the pseudo-inverse applied to the perturbation. The pseudo-inverse’s norm is 1/σmin⁡1/\sigma_{\min}, which is κ(A)/∥A∥\kappa(A)/\|A\|, one power of the conditioning and not two. Half of G−1G^{-1}'s amplification is undone by the ATA^{\mathsf T} in front of it, and that is the same reason the seminormal equations, which solve through RTR=ATAR^{\mathsf T}R = A^{\mathsf T}A, are not as bad as the road that squares the problem makes the normal equations look: what squares the conditioning is forming the Gram matrix in floating point, and the correction here never forms anything new from it.

What sets the size of δr\delta r is not the residual. Each aijβja_{ij}\beta_j is a product of the size of the rows times the answer, and the residual is what is left when those products nearly cancel against yiy_i. Rounded to single, each product carries an error of about 2−24∣aij∣∣βj∣2^{-24}|a_{ij}||\beta_j|, whatever the residual is. On the worst stream at noise one the single residual formed at the exact answer is wrong by about one per cent of the largest residual; at noise 10−610^{-6}, where the residual is far smaller than the products that make it, by thirteen per cent. So the single residual’s error is 2−242^{-24} times the size of the rows and the answer, carried by A+A^{+}, and that is 2−24κ(A)2^{-24}\kappa(A) times the answer’s size, up to a constant: the floor the figure shows, independent of the noise.

How wrong a sliding window's residual is when formed in single precision at the window's exact answer: the largest error in one row over the largest row residual, against the noise in the response, at four conditionings, medians over the sampled stepsκ(A) about 2.1·10⁶: noise 1 0.012, noise 10⁻² 0.015, noise 10⁻⁴ 0.012, noise 10⁻⁶ 0.13; κ(A) about 2.2·10⁵: noise 1 0.0016, noise 10⁻² 0.0012, noise 10⁻⁴ 0.0016, noise 10⁻⁶ 0.16; κ(A) about 2.2·10⁴: noise 1 1.3·10⁻⁴, noise 10⁻² 1.7·10⁻⁴, noise 10⁻⁴ 0.0013, noise 10⁻⁶ 0.14; κ(A) about 2.2·10³: noise 1 1.4·10⁻⁵, noise 10⁻² 2·10⁻⁵, noise 10⁻⁴ 0.0012, noise 10⁻⁶ 0.12. With no noise the exact answer leaves every residual zero and nothing to round.10⁻⁶10⁻⁵10⁻⁴10⁻³10⁻²10⁻¹1noise in the responseresidual's own error ÷ largest residual110⁻²10⁻⁴10⁻⁶κ about 2.1·10⁶κ about 2.2·10⁵κ about 2.2·10⁴κ about 2.2·10³the rounding is set by the products, not the residuala small residual on a coarse ruler
Fig. 2 How wrong the residual is when formed in single precision at the window’s exact answer — the largest error in one row over the largest row residual — against the noise in the response, at four conditionings.

Measured at the exact answer, where the double residual is the true one, the single residual’s error has two regimes. With noise the size of the data it depends on the conditioning: about one per cent of the residual at κ(A)\kappa(A) near 2⋅1062 \cdot 10^6, a tenth of that at 2⋅1052 \cdot 10^5, and down to 1.4⋅10−51.4 \cdot 10^{-5} at 2⋅1032 \cdot 10^3, because the window’s answer is larger the more nearly parallel its columns are, and so are the products that have to cancel. As the noise falls the residual shrinks and the products do not, and at 10−610^{-6} every conditioning meets at the same place: the residual formed in single is wrong by 12 to 16 per cent of itself. A residual that small is a few units left over from products of millions, and binary32 spaces numbers of a million to a few million between a sixteenth and half a unit apart.

What a float can hold is the whole of the reason the size of the products matters and the size of the residual does not. Binary32 numbers near a product of the rows’ size are spaced 2−242^{-24} of that size apart, and the residual is read off as a difference between numbers of that size. A small residual is a short distance measured on a coarse ruler: it does not make the ruler finer. That is also why the single residual’s error is so much larger, relative to the residual, at low noise than at high — thirteen per cent against one — and why it makes no difference to the floor. The correction does not care how wrong the residual is as a fraction of itself; it cares how wrong it is in absolute terms, and that is fixed by the products. A small residual is not a small error made the converse point about checking an answer by its residual: the residual’s smallness is not information about the answer’s accuracy. Here it is not even information about the residual’s own.

Buying the accuracy back found the same verdict for a linear system: a factorisation in single corrected by residuals in double recovers a double-precision answer, and with residuals in single the identical algorithm recovers nothing. The window adds two things to that. The floor has a slope, one decade per decade of conditioning, which says how much a single residual costs at any κ\kappa rather than whether it costs. And the earlier essay’s mechanism of amplification by G−1G^{-1} — which was right for what it explained, the partial correction’s fixed point at the subset’s answer — does not carry over to rounding, because rounding arrives through ATA^{\mathsf T} and a missing row does not.

Splitting the answer does not help

A sliding window's median error against the noise in its response at κ(A) about 2.2·10⁴, with every step's correction formed four ways: the residual in double, in single, in single with the answer split into a single head and a double tail, and the residual in double with the rows weighted by it summed in singlesingle residual: 3.1e-4, 2.6e-4, 6.1e-5, 8.4e-5, 7.7e-5; single, answer split: 3.2e-4, 2.6e-4, 7.2e-5, 6.6e-5, 1.0e-16; single sum, double residual: 1.3e-3, 1.1e-3, 3.2e-5, 5.4e-7, 1.7e-13; double: 2.2e-12, 1.6e-12, 1.6e-13, 1.4e-13, 1.6e-13 at noise 1, noise 10⁻², noise 10⁻⁴, noise 10⁻⁶, no noise. The split reads zero on the stream with no noise, where the exact answer is a vector of ones and minus ones and its single head is exact.10⁻¹⁴10⁻¹²10⁻¹⁰10⁻⁸10⁻⁶10⁻⁴10⁻²noise in the responserelative error, median110⁻²10⁻⁴10⁻⁶nonesingle residualsingle, answer splitsingle sum, double residualdoublea single sum is free only where the residual vanishesa single residual is not free anywhere
Fig. 3 A sliding window’s median error against the noise in its response at κ(A) about 2·10⁴, with every step’s correction formed four ways: the residual in double, in single, in single with the answer split into a single head and a double tail, and in double with ATrA^{\mathsf T}r summed in single.

If the trouble is that the products carry the answer’s size, the obvious repair is to keep the answer’s low part out of the rounding: round only its binary32 head, and add the tail’s contribution in double. It changes nothing. On every noisy stream the split’s error is within a factor of two of the plain single residual’s: 3.2⋅10−43.2 \cdot 10^{-4} against 3.1⋅10−43.1 \cdot 10^{-4} at noise one, 7.2⋅10−57.2 \cdot 10^{-5} against 6.1⋅10−56.1 \cdot 10^{-5} at 10−410^{-4}. The head’s products are still rounded to single, and the head carries almost all of the answer’s size, so almost all of the rounding is still there.

The one place the split reads zero is the stream with no noise at the two better conditionings, and it is a coincidence of the test rather than a property of the split. With no noise the exact answer is a vector of ones and minus ones, which binary32 represents exactly; once the window has converged its head is the answer, its tail is zero, and every product it rounds is an integer times one. On the worst stream the same coincidence does not save it, and on any real stream the answer is not a vector of small integers.

The other half can be single, where the residual is small

The fourth way of forming the correction is the reverse: the residual in double, so its cancellation happens at full precision, and the sum ATrA^{\mathsf T}r in single. On the stream with no noise it is free. At every conditioning it ends within a factor of two of the double correction — 1.2⋅10−111.2 \cdot 10^{-11} against 1.4⋅10−111.4 \cdot 10^{-11} at the worst, 1.7⋅10−131.7 \cdot 10^{-13} against 1.6⋅10−131.6 \cdot 10^{-13} at 2⋅1042 \cdot 10^4. On a noisy stream it is not, and the way it fails is the opposite of the residual’s.

A sliding window's median error against the condition number of its rows when each correction forms its residual in double and sums the rows weighted by it in single, at five noise levelsnoise 1: 5.5e-2, 6.4e-3, 1.3e-3, 8.6e-5; noise 10⁻²: 9.1e-2, 9.0e-3, 1.1e-3, 9.0e-5; noise 10⁻⁴: 1.2e-1, 1.0e-2, 3.2e-5, 2.9e-7; noise 10⁻⁶: 4.9e-3, 3.9e-5, 5.4e-7, 5.9e-9; no noise: 1.2e-11, 1.1e-12, 1.7e-13, 1.3e-14 at κ(A) about 2.1·10⁶, 2.2·10⁵, 2.2·10⁴, 2.2·10³.10³10⁴10⁵10⁶10⁻¹⁵10⁻¹²10⁻⁹10⁻⁶10⁻³1κ(A), median over the windowsrelative error, mediannoise 1noise 10⁻²noise 10⁻⁴noise 10⁻⁶no noiseat small noise, two decades of error a decade of κthe sum's rounding scales with the residual
Fig. 4 A sliding window’s median error against the condition number of its rows when each correction forms its residual in double and sums ATrA^{\mathsf T}r in single, at five noise levels.

At noise 10−610^{-6} the single sum’s error is 4.9⋅10−34.9 \cdot 10^{-3}, 3.9⋅10−53.9 \cdot 10^{-5}, 5.4⋅10−75.4 \cdot 10^{-7} and 5.9⋅10−95.9 \cdot 10^{-9} from the worst conditioning to the best: a factor of 73 to 124 for each decade of κ(A)\kappa(A), two decades a decade. And at every conditioning it grows with the noise — at 2⋅1032 \cdot 10^3, from 5.9⋅10−95.9 \cdot 10^{-9} at noise 10−610^{-6} to 2.9⋅10−72.9 \cdot 10^{-7} at 10−410^{-4} — until at noise of the size of the data it meets the single residual’s floor.

This is the amplification the prediction had in mind, attached to the other half. The rounding of a sum of products aijria_{ij}r_i is about 2−242^{-24} times the sum of their sizes, which is proportional to the residual, and it lands in c=ATrc = A^{\mathsf T}r directly. Nothing applies ATA^{\mathsf T} to it first, so G−1G^{-1} amplifies it by the full square of the conditioning: an error of 2−24κ(A)22^{-24}\kappa(A)^2 times the residual’s size over the rows’. When the data fit exactly the residual goes to zero and takes the rounding with it. When they do not, the rounding is the residual’s size times κ2\kappa^2.

So the two halves of a correction cost in different currencies. The residual’s rounding is set by the size of what cancels — the rows and the answer — and is amplified once; it costs 2−24κ2^{-24}\kappa on every stream, whatever the noise. The sum’s rounding is set by the size of what survives the cancellation — the residual — and is amplified twice; it costs 2−24κ22^{-24}\kappa^2 times the residual, which is nothing on consistent data and everything on noisy data at high conditioning.

Along the stream

A sliding window's relative error along the stream at κ(A) about 2.2·10⁴ and noise 10⁻⁴, with each step's correction forming its residual in double, in single, or in double with the rows weighted by it summed in singlesingle residual: median 6.12e-5, worst 3.11e-4; single sum, double residual: median 3.19e-5, worst 1.79e-4; double: median 1.64e-13, worst 8.00e-13.0200400600800100010⁻¹⁵10⁻¹³10⁻¹¹10⁻⁹10⁻⁷10⁻⁵10⁻³10⁻¹steps along the streamrelative errorsingle residualsingle sum, double residualdoubleevery 50th step, against the exact answera flat floor, not a drift
Fig. 5 A sliding window’s relative error along the stream at κ(A) about 2·10⁴ and the noise on the dial, with each step’s correction forming its residual in double, in single, or in double with ATrA^{\mathsf T}r summed in single.

Neither cheap correction drifts. At noise 10−410^{-4} and κ(A)\kappa(A) about 2⋅1042 \cdot 10^4 the single residual’s error has a median of 6.1⋅10−56.1 \cdot 10^{-5} and a worst of 3.1⋅10−43.1 \cdot 10^{-4} over the sampled steps, a floor that is there from the start, and the double correction’s sits eight and a half decades below it. That is what stable once and three thousand times and the repair the drift did not need found of the window itself: every step’s error is set afresh by that step’s arithmetic, because each correction is a contraction toward the window’s answer, and nothing accumulates. Turn the dial down through the noise levels and the single sum’s line falls toward the double one, reaching it only at none, while the single residual’s line stays where it is.

What the window was asking for

The proposal wanted a correction that costs less and still reads every row. The measurement says which half of it can be cheapened, and when. The residual cannot, at any conditioning these streams reach: a single-precision residual puts a floor of a few hundredths of 2−24κ(A)2^{-24}\kappa(A) under the answer, which at κ=2⋅103\kappa = 2 \cdot 10^3 is already 3⋅10−53 \cdot 10^{-5} — more than any double correction’s error by eight decades. The sum can, but only where the residual is small enough that 2−24κ22^{-24}\kappa^2 times it is below what the answer needs. On these streams that is the consistent one, and close to it.

The step the two rows owe found that the update the window starts from is already the right move on data that fit and three orders short on data that do not, and the answer the last window left drew the same line for carrying the previous answer forward. The precision of the sum falls on the same side of the same line: everything a sliding window can economise on is free when the data agree exactly and has a price proportional to the disagreement otherwise. The residual’s precision is the exception. It is paid on every stream, because what it rounds is not the disagreement but the size of the data.

It is worth being exact about what the cheap half would buy, since the proposal was about cost. A correction reads every row twice: once to form the residual, six products and a subtraction a row, and once to form the sum, six more products a row; then it applies the factor, two triangular solves on 21 numbers. The rows are most of the traffic, and both halves read them. Making the sum single halves the precision of one of the two passes over the rows and leaves the other, so on a machine where the cost is memory it is a quarter of the correction’s traffic at most — and it is free only where the data nearly fit. The pass that would have saved the most is the residual, which reads the rows and the response together, and it is the one that cannot be made cheaper at all.

What four streams do not show

One family of streams, six columns, a window of 24, integer data whose exact answer can be computed. On data whose answer is small beside the rows — a well-scaled problem rather than a collinear one — the products that cancel in the residual are smaller and the single residual’s floor lower in absolute terms, though the measurement here says its slope in κ\kappa would be the same. No fused multiply-add: a residual formed with one rounding per product-sum would round less, and how much less on a cancellation this severe is not measured. And the cost the proposal was about — memory traffic, which is what single precision saves on a real machine — is not measured at all; these are the accuracies, and whether either cheap half is worth its saving depends on a machine this essay does not have.

Still open: a single factor, and a wider window

A factor in single, a residual in double. The half of the correction the measurement has not touched is the solve: the Cholesky factor of GG, used in two triangular solves per step. Buying the accuracy back found a single factorisation corrected by double residuals recovers double accuracy on a linear system, as long as the single factor is good enough to contract. The prediction with a sign is that the window with its factor updated and held in single and its residual and sum in double ends within a factor of ten of the all-double window at κ(A)\kappa(A) up to 2⋅1052 \cdot 10^5, and fails to contract at all at 2⋅1062 \cdot 10^6, where 2−24κ(A)22^{-24}\kappa(A)^2 passes one.

A wider window. The earlier essay’s prediction for 72 of 96 rows still stands untested. This essay adds one with a sign: with 96 rows the single residual’s floor stays within a factor of two of the 24-row window’s at every conditioning, because the floor is set by κ(A)\kappa(A) and the size of the answer, neither of which the width changes, while the double correction’s error falls.

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.

Condition numberExact ground truthIterative refinementLeast squaresLow-rank updateMixed-precisionSeminormal equationsUnit roundoff