Orthogonality, measured

A rounding chosen once is still repeated

One binary32 rotation multiplied into itself a million times loses orthogonality in a straight line, 622,126 units of roundoff on the first of five rotations, because its rounding defect is the same every time. The prediction was that choosing the best of the factor's representable neighbours would cut that rate tenfold and leave the angle alone. The best of 512 neighbours cuts it by 1 to 5 per cent. A greedy search eight ulps wide cuts it at most by half, and where it does, it moves the factor off the rotation and multiplies the angle's error by up to five. What works is to stop repeating the rounding: rounded afresh at random each product, the same factor loses 1,717 to 3,377 units at a million, and its angle is two hundred times nearer the truth than any fixed choice.

Worth reading first: Orthogonal is a number · The direction the error leans.

A repeated rotation drifts in a straight line multiplied rotations of order three together in binary32 and measured ∥QTQ−I∥\|Q^{\mathsf T}Q - I\|. With a fresh factor at every step the loss walked like the square root of the number of products, slope 0.52 over a million. With one factor repeated, as a fixed-step integrator or an animation loop repeats one incremental rotation, the slope was 1.00 and the loss at a million products was 622,127 units of binary32’s roundoff against 2,404. The reason was one defect met in the same direction every time: the rounded factor is not quite orthogonal, and the product’s departure is that departure times the number of products.

If the drift is the factor’s defect, the factor can be chosen. Each entry of the exact rotation lies between two neighbouring binary32 numbers, so there are 29=5122^9 = 512 matrices with every entry rounded down or up, and one of them has the smallest defect. The essay signed a prediction about that choice: a small search over those neighbours, made once at setup, would reduce the linear rate by a factor of at least ten, from 0.62 units a product to under 0.06, and it would do nothing about the angle’s error, which comes from the factor being a slightly wrong rotation rather than a slightly stretched one.

Both halves fail, and the reason they fail points at the repair that does work.

Five rotations and six ways to round them

The rotations are the earlier essay’s: three small turns about the three axes, each angle drawn below a tenth of a radian, on five seeds. Each is formed exactly in binary64 and then rounded to binary32 in one of six ways. The nearest rounding is what any code does. The best neighbour is the least-defect matrix among the 512 down-or-up roundings. Three greedy searches move one entry at a time by one ulp, accept any move that lowers the defect, and stop when none does, never moving an entry further than 2, 4 or 8 ulps from the exact value. The sixth does not fix a factor at all: at each product, every entry is rounded up or down at random, up with probability equal to the exact value’s distance above the lower neighbour as a share of the gap, so that the rounded factor’s expected value is the exact rotation.

Each factor is multiplied into the running product a million times, in binary32 throughout, and two numbers are read at each decade: the loss of orthogonality, and the distance from the same power of the exact binary64 rotation, which is the angle’s error plus the stretch.

The loss of orthogonality of a product of one binary32 rotation of order three with itself, against the number of products, for four ways of rounding the factor, rotation 1 of fivenearest binary32: 58 at 100, 639 at 1,000, 6,083 at 10,000, 61,624 at 100,000, 622,126 at 1,000,000; best of 512 neighbours: 56 at 100, 593 at 1,000, 5,857 at 10,000, 58,766 at 100,000, 590,696 at 1,000,000; greedy, within 8 ulps: 34 at 100, 259 at 1,000, 2,921 at 10,000, 27,494 at 100,000, 275,113 at 1,000,000; rounded afresh at random: 27 at 100, 85 at 1,000, 247 at 10,000, 858 at 100,000, 1,717 at 1,000,000, in units of binary32's roundoff.10²10³10⁴10⁵10⁶110¹10²10³10⁴10⁵10⁶number of productsloss of orthogonality, in unitsnearest binary32best of 512 neighboursgreedy, within 8 ulpsrounded afresh at randombinary32 · order three · rotation 1 of fivethree lines and a walk
Fig. 1 The loss of orthogonality against the number of products for four ways of rounding the factor: the nearest (red), the best of 512 neighbours (amber), a greedy search within eight ulps (green) and a factor rounded afresh at random each product (blue). The dial sets the rotation.

On the first rotation the nearest factor loses 639 units at a thousand products and 622,126 at a million, the earlier essay’s line. The best neighbour lies just under it, 593 and 590,696. The greedy search within eight ulps lies under that, at 275,113 at a million. All three are straight lines of slope one. The factor rounded at random lies two and a half decades below the rest, at 1,717 units at a million, and it is not a straight line at all. The dial shows the same order on all five rotations, with the gap between the three fixed choices varying from nothing to a factor of two.

The grid has no better matrix nearby

The first half of the prediction assumed that among a factor’s neighbours there is one much closer to orthogonal. There is not, and the factors’ own defects show why.

The defect of the binary32 factor itself, its departure from orthogonality in units of the roundoff, for five ways of choosing it, on five rotationsrotation 1: nearest binary32 0.892, best of 512 neighbours 0.866, greedy, within 2 ulps 0.794, greedy, within 4 ulps 0.711, greedy, within 8 ulps 0.556; rotation 2: nearest binary32 0.801, best of 512 neighbours 0.788, greedy, within 2 ulps 0.714, greedy, within 4 ulps 0.615, greedy, within 8 ulps 0.433; rotation 3: nearest binary32 0.459, best of 512 neighbours 0.449, greedy, within 2 ulps 0.459, greedy, within 4 ulps 0.459, greedy, within 8 ulps 0.459; rotation 4: nearest binary32 1.018, best of 512 neighbours 1.006, greedy, within 2 ulps 1.010, greedy, within 4 ulps 1.006, greedy, within 8 ulps 1.000; rotation 5: nearest binary32 0.391, best of 512 neighbours 0.390, greedy, within 2 ulps 0.391, greedy, within 4 ulps 0.391, greedy, within 8 ulps 0.391.00.30.60.91.2rotation 1nearest binary320.89best of 512 neighbours0.87greedy, within 2 ulps0.79greedy, within 4 ulps0.71greedy, within 8 ulps0.56rotation 2nearest binary320.80best of 512 neighbours0.79greedy, within 2 ulps0.71greedy, within 4 ulps0.61greedy, within 8 ulps0.43rotation 3nearest binary320.46best of 512 neighbours0.45greedy, within 2 ulps0.46greedy, within 4 ulps0.46greedy, within 8 ulps0.46rotation 4nearest binary321.02best of 512 neighbours1.01greedy, within 2 ulps1.01greedy, within 4 ulps1.01greedy, within 8 ulps1.00rotation 5nearest binary320.39best of 512 neighbours0.39greedy, within 2 ulps0.39greedy, within 4 ulps0.39greedy, within 8 ulps0.39defect of one factor, in units of the roundoffbinary32 · order threethe grid holds nothing much better
Fig. 2 The defect of one binary32 factor, its own departure from orthogonality in units of the roundoff, for the nearest rounding, the best of 512 neighbours and three greedy searches, on five rotations.

The nearest roundings have defects of 0.39 to 1.02 units on the five rotations. The best of the 512 neighbours improves on that by 0.1 to 2.9 per cent: 0.866 against 0.892 on the first, 0.390 against 0.391 on the fifth. The greedy searches find more on two rotations, reaching 0.56 and 0.43 within eight ulps, and on the other three they find nothing at all, because no single one-ulp move lowers the defect and the search stops where it started.

An inner product with no fixed sign showed how the computed inner product of two nearly orthogonal vectors is a rounding error with no preferred sign, and the entries of FTF−IF^{\mathsf T}F - I are exactly such inner products. The reason no neighbour does much better is in the arithmetic of the defect. FTF−IF^{\mathsf T}F - I is a symmetric matrix with six independent entries, each a sum of products of entries of FF, and each is shifted by about one unit of roundoff when any entry of FF moves by one ulp. A matrix within one ulp of the rotation in every entry has a defect of the order of one unit, and every one of the 512 does; to find one with a defect a tenth of that, the six numbers have to cancel to a tenth of their typical size at once, which happens by chance in about one candidate in 10610^6, not one in 512. A wider box has more candidates, but they are further from the rotation. And an exactly orthogonal binary32 matrix close to a small rotation does not exist: the cosine and sine would have to be dyadic fractions whose squares sum to exactly one, which only zero and one manage.

So the rate barely moves. At a million products the best neighbour’s loss is within 1 to 5 per cent of the nearest rounding’s on every rotation. The loss is the defect times the number of products, to within a factor of 0.5 to 1.2 on both choices and all five rotations, which is the earlier essay’s law with the constant read off. A factor of ten in the rate would need a factor of ten in the defect, and the neighbourhood does not contain one.

A wider search trades the angle for the stretch

Where the greedy search does find a smaller defect, the second half of the prediction is tested, and it fails more instructively than the first.

What a wider search buys and costs: at a million products, the loss of orthogonality and the distance from the exact rotation's product, against the width of the greedy search in ulps plus one, on five rotationsrotation 1: loss 622,126, 543,663, 387,818, 275,113 and error 309,435, 611,955, 1,075,106, 1,748,475 at widths 0, 2, 4 and 8; rotation 2: loss 780,361, 689,766, 592,391, 415,212 and error 388,836, 613,510, 1,065,991, 1,983,986 at widths 0, 2, 4 and 8; rotation 3: loss 285,006, 288,495, 288,495, 288,495 and error 145,379, 146,766, 146,766, 146,766 at widths 0, 2, 4 and 8; rotation 4: loss 766,718, 768,275, 762,508, 757,669 and error 387,841, 391,739, 386,413, 382,861 at widths 0, 2, 4 and 8; rotation 5: loss 342,171, 342,171, 342,171, 342,171 and error 171,691, 171,691, 171,691, 171,691 at widths 0, 2, 4 and 8.110¹10⁵10⁵.⁵10⁶10⁶.⁵width of the search in ulps, plus oneunits at a million productsangle's error, each rotationloss, each rotationwidth 0 is the nearest factorless stretch, more turn
Fig. 3 At a million products, the loss of orthogonality (red) and the distance from the exact rotation’s product (green) against the width of the greedy search in ulps, plus one, on five rotations.

On the first rotation, widening the search from nothing to 2, 4 and 8 ulps lowers the loss at a million from 622,126 to 543,663, 387,818 and 275,113 units. Over the same widths the distance from the exact rotation’s product rises from 309,435 to 611,955, 1,075,106 and 1,748,475. The second rotation behaves the same way: loss down from 780,361 to 415,212, distance up from 388,836 to 1,983,986. The three rotations on which the search found nothing keep both numbers where they were.

The prediction said the angle’s error “stays where it was” because orthogonalising a factor cannot change the rotation it represents. That is true of a repair applied to the product, which the nearest orthogonal matrix defines as the closest rotation to whatever has accumulated. It is not true of a search over the factor. To lower the defect, the search moves entries away from the exact rotation’s values by several ulps, and a matrix that is more nearly orthogonal and further from the rotation is a more accurate rotation by a different angle. Every ulp of movement is mostly turn rather than stretch, and the turn is repeated a million times exactly as the stretch was. The search exchanges a stretch, which a later repair could remove, for an angle error, which nothing downstream can.

The repetition is the defect

Both failures come from treating the defect as a property of a factor to be minimised, when the earlier essay’s own finding was that the problem is the repetition. A random set of fresh factors has defects of the same size, about one unit each, and walked only 2,404 units in a million products, because their defects point in different directions and partly cancel. The repeated factor’s single defect, however small it is made, adds in one direction for ever.

That suggests not choosing a rounding at all, but drawing a new one every time from the two neighbours of each entry, with the probabilities set so the drawn factor equals the exact rotation on average. This is stochastic rounding applied to a constant. A coin flip that fixes the average measured the same idea on a sum, where rounding to nearest drifts in one direction and stochastic rounding does not, and every equal tail has a cliff found a norm wrong by thousands of units for the same reason as here: one rounding, met every time, added in the same direction.

The median over five rotations of the loss of orthogonality and the distance from the exact product, against the number of products, for the factor rounded afresh at random and for the nearest factor repeatedRounded at random: loss 15, 61, 210, 858, 2,538 and error 8, 33, 109, 434, 1,381 at a hundred to a million products; slopes 0.46, 0.56, 0.53, 0.61, 0.58. Nearest, repeated: loss 58, 639, 6,083, 61,624, 622,126.10²10³10⁴10⁵10⁶110¹10²10³10⁴10⁵10⁶number of productsunits, median of five rotationsnearest, lossnearest, errorat random, lossat random, errorbinary32 · order threeslope one against slope a half
Fig. 4 The median over five rotations of the loss of orthogonality and of the distance from the exact rotation’s product against the number of products, for the factor rounded afresh at random (blue and green) and the nearest factor repeated (red and amber).

The randomly rounded factor walks. Its median loss over the five rotations is 15 units at a hundred products, 61 at a thousand, 210 at ten thousand, 858 at a hundred thousand and 2,538 at a million, and the fitted slopes on the five rotations are 0.46 to 0.61, the slope of fresh factors. Its distance from the exact product walks too: a median of 1,381 units at a million, where the nearest factor’s is 309,435 to 388,836. One random choice of neighbour per entry per product has done for the angle what no fixed choice could, because the angle’s error was also a rounding repeated: the nearest factor’s entries are each off in a fixed direction, and so is the rotation they represent.

Why the angle walks as well

The factor rounded at random differs from the exact rotation by a matrix EkE_k that is new at every product, with each entry’s expected value zero. Its symmetric part stretches the product and its skew part turns it, and both parts now have zero mean and are independent from one product to the next. A sum of a million independent terms of a unit each has a typical size of about a thousand units, and that is what both measurements show: 2,538 for the loss and 1,381 for the distance at the median, in the same ratio of nearly two that the earlier essay found between them, since a stretch of size ee shows as 2e2e in QTQ−IQ^{\mathsf T}Q - I.

The nearest factor’s EE is the same matrix every time, so the same million terms add to a million times one of them. The fixed choices differ only in which EE they repeat, and every EE within a few ulps of the rotation has entries of about a unit, so no choice can do better than a few hundred thousand units at a million products. That is the whole of the argument, and it is the argument the direction the error leans made for rounding modes in a sum: an unbiased error grows as the square root of the count, and a biased one, however small its bias, grows as the count.

There is a cost in the other direction, and it is visible at the start. At a hundred products the random rounding’s median loss is 15 units against 58 for the nearest factor on the first rotation, already better, but the first few products of a random walk have no cancellation yet to benefit from, and a short computation, a few dozen products long, gains little. The advantage grows as the square root of the number of products: a factor of about thirty at ten thousand, of two hundred and fifty at a million.

What each approach leaves, side by side

At a million products, the loss of orthogonality and the distance from the exact rotation's product, for the nearest factor and the range over all six routes, on five rotationsrotation 1: nearest binary32 loss 622,126 and error 309,435; best of 512 neighbours loss 590,696 and error 319,265; greedy, within 2 ulps loss 543,663 and error 611,955; greedy, within 4 ulps loss 387,818 and error 1,075,106; greedy, within 8 ulps loss 275,113 and error 1,748,475; rounded afresh at random loss 1,717 and error 906. rotation 2: nearest binary32 loss 780,361 and error 388,836; best of 512 neighbours loss 763,624 and error 395,639; greedy, within 2 ulps loss 689,766 and error 613,510; greedy, within 4 ulps loss 592,391 and error 1,065,991; greedy, within 8 ulps loss 415,212 and error 1,983,986; rounded afresh at random loss 2,538 and error 1,381. rotation 3: nearest binary32 loss 285,006 and error 145,379; best of 512 neighbours loss 270,461 and error 203,445; greedy, within 2 ulps loss 288,495 and error 146,766; greedy, within 4 ulps loss 288,495 and error 146,766; greedy, within 8 ulps loss 288,495 and error 146,766; rounded afresh at random loss 2,406 and error 1,323. rotation 4: nearest binary32 loss 766,718 and error 387,841; best of 512 neighbours loss 762,932 and error 401,401; greedy, within 2 ulps loss 768,275 and error 391,739; greedy, within 4 ulps loss 762,508 and error 386,413; greedy, within 8 ulps loss 757,669 and error 382,861; rounded afresh at random loss 3,377 and error 1,696. rotation 5: nearest binary32 loss 342,171 and error 171,691; best of 512 neighbours loss 338,587 and error 170,963; greedy, within 2 ulps loss 342,171 and error 171,691; greedy, within 4 ulps loss 342,171 and error 171,691; greedy, within 8 ulps loss 342,171 and error 171,691; rounded afresh at random loss 3,171 and error 1,769, in units.1001,00010,000100,0001,000,000loss of orthogonality: nearest, and the range over six routesrotation 11,717 to 622,126rotation 22,538 to 780,361rotation 32,406 to 288,495rotation 43,377 to 768,275rotation 53,171 to 342,171error from the exact rotation's product: the samerotation 1906 to 1,748,475rotation 21,381 to 1,983,986rotation 31,323 to 203,445rotation 41,696 to 401,401rotation 51,769 to 171,691units of binary32's roundoff, at a million productsthe low end of each range is the random routetwo decades below the rest
Fig. 5 At a million products, the loss of orthogonality (above) and the distance from the exact rotation’s product (below) on five rotations: the nearest factor’s value, with the range over all six routes.

At a million products the six routes span about two and a half decades on every rotation, and the low end of each range is always the random rounding. Its loss is 1,717 to 3,377 units where the fixed choices’ are 270,461 to 780,361, and its distance from the exact product is 906 to 1,769 units where theirs are 145,379 to 1,983,986. The fixed choices differ among themselves by at most a factor of three in the loss, and in the distance the cleverest of them is the worst.

The earlier essay’s repairs belong in this comparison. One polar step on a schedule, an iteration that only multiplies, removed the stretch at any period and left an angle error of about 1,600 units at a hundred thousand products, growing linearly to about sixteen thousand at a million, because no orthogonalisation can touch an angle. The random rounding leaves about a tenth of that angle error with no repair at all, and its loss of 2,538 units is 1.5⋅10−41.5 \cdot 10^{-4} in absolute terms, small enough that a single polar step at the end, or one every hundred thousand products, would remove it. The two are complementary: the random rounding removes the bias that a repair cannot, and a rare repair removes the walk that the rounding leaves.

What it costs, and where it does not apply

Rounding a factor at random costs nine random numbers and nine comparisons a product, against the 27 multiplications and 18 additions of the product itself, and it needs the factor in a higher precision than the one the product is computed in, so that there is something to round from. A code that holds its incremental rotation in binary64 and multiplies in binary32, which is the usual reason for the arithmetic to be binary32 at all, has both. A code whose rotation is computed afresh each step from an angle, rather than held fixed, already has fresh roundings, and the earlier essay’s slope of 0.52 is its law. And a code that can carry its rotation as a product of reflectors avoids the question, since a reflection cannot stop being one in the sense that matters here: it is orthogonal by construction, whatever its rounding.

The measurements are of order three, in binary32, over a million products, on five rotations of small angle. Order eight and binary64 were not repeated here; the earlier essay found the same laws in both, scaled by each format’s roundoff, and there is no mechanism in the argument that depends on the order. The random rounding uses one stream of pseudorandom numbers per run, and a poor pseudorandom source, or one whose period is short against a million products, would reintroduce a repetition. The greedy search is a local one, and a global search over a wider box might find a factor with a much smaller defect; the argument above says it would have to move further from the rotation to do it, and the angle would pay.

What is settled is the shape. A factor’s defect cannot be chosen much below a unit of roundoff from among its neighbours; lowering it further moves the factor off the rotation and buys a smaller stretch with a larger angle error; and refusing to repeat a rounding, by drawing it afresh at random, turns both the stretch and the angle into walks two decades shorter than any fixed choice. Orthogonal is a number supplied the instrument that measured all of it.

Still open: the quaternion, and a deterministic way to stop repeating

A representation with no stretch to lose. The earlier essay’s second question stands: a quaternion carries a rotation in four numbers, and its repeated product scales its norm rather than losing orthogonality. The prediction with a sign is that a unit quaternion multiplied into itself a million times in binary32 drifts in norm linearly at a rate within a factor of three of the matrix’s defect rate, and that rounding its four components at random each product turns that into a walk of slope near a half, exactly as here, so that the representation changes the constant and not the law.

Two roundings, alternated. Randomness is not the only way to stop a rounding repeating. Among the 512 neighbours there are pairs whose defects point in nearly opposite directions. The prediction is that alternating the best such pair, so that every two products have a combined defect below a tenth of a unit, gives a straight line again but with a slope one at a rate ten times lower, and an angle error no better than the nearest factor’s, because the two halves of the pair are both off the rotation by a fixed amount; so that a deterministic cancellation fixes the stretch and not the angle, and only a rounding that is unbiased on average fixes both.

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.

Binary32Loss of orthogonalityOrthogonalityPolar decompositionRandom walkRounding modesUnit roundoff