A matrix that is definite on one machine
Worth reading first: One multiply the compiler removed · A factorisation with nothing to pivot for.
Is this matrix positive definite is the one question in the subject with a two-word answer. There is no tolerance in it, no unit, and no scale: a matrix is positive definite or it is not, and a Cholesky factorisation answers by completing or by stopping at a pivot that is not positive.
Which makes it the sharpest possible test of the previous essay’s claim. A determinant can be a little wrong. A verdict cannot.
Two hundred matrices, twenty-six disagreements, and the shaded parts are not the whole bars.
The experiment
Each matrix is a Gram matrix AᵀA, formed from a tall matrix whose last column is nearly the sum of its first two. Such a matrix is positive definite whenever the columns are independent, which they are by construction — but only just, and how just is the horizontal axis: the perturbation that separates the last column from the sum of the other two runs from 10⁻⁸ down to 10⁻¹².
The entries of AᵀA are formed exactly, by an error-free product expansion and an exactly rounded sum, so that the matrix handed to both routines is the same matrix and any disagreement afterwards belongs to the factorisation rather than to the assembly.
Then each matrix is asked the question twice.
One build accumulates each inner product with a single rounding per term — the fused form, which
is what a compiler emits from s -= L[i][k]*L[j][k] when it contracts.
The other rounds each product before subtracting it — the unfused form, which is what the same source produces on a machine without the instruction, or with the contraction disabled.
Nothing else differs: the same algorithm, the same order, the same precision, the same matrix.
The adjudicator
A disagreement between two routines is only interesting if there is a third thing that settles it, and here there is one that admits no argument.
Sylvester’s criterion: a symmetric matrix is positive definite exactly when every leading principal
minor is positive. Every entry of the matrix is a binary64 number and therefore a rational with a
power of two underneath it, so its minors are rationals, and their signs are facts rather than
measurements. This site’s exact.js computes them in BigInt, which is the same machinery
the exact answer, in rationals uses for a Hilbert inverse.
So each of the two hundred matrices has a true verdict, computed by a route that shares no arithmetic with either build.
The result
Twenty-six of the two hundred came back with different verdicts. On each of those, exactly one of the two builds was right — which is a check rather than an observation, and is asserted on every build of this site.
The fused build was the right one nine times. The unfused build was right seventeen.
That is the finding, and it is the opposite of the tidy story. The previous essay’s determinant is exact under the fused form and zero under the other, which invites the conclusion that fusing is correct and contracting is a hazard. It is not: on a computation nobody designed around the instruction, the fusion moves the answer by one rounding in a direction with no reason to be right, and the census says it is right about a third of the time.
The honest statement is therefore not use the fused form. It is:
The verdict is a property of the build, and which build is right is a property of the matrix.
Why a definiteness test is where this shows
Three reasons, and they compound.
The quantity is a difference of nearly equal things. The last pivot of a Cholesky is Aⱼⱼ − Σ L²ⱼₖ, and for a matrix that is barely definite the two are nearly equal, so the summation condition number of that inner product is enormous — which is exactly where the vector that hides it puts every quantity a decision is read from.
The comparison is with zero. A threshold has a margin and a sign does not. Whatever the disagreement between two builds, if it straddles zero the verdicts differ, and the disagreement is guaranteed to straddle zero when the true pivot is smaller than the disagreement.
The matrix is a Gram matrix. Forming AᵀA squares the condition number, which the road that squares the problem is the essay about. So a matrix whose columns are separated by 10⁻¹⁰ arrives at the factorisation with a condition number near 10²⁰, and its smallest pivot is below the rounding of the entries — which is the regime the census is drawn in.
The third one is worth dwelling on because it is not a contrivance. A Gram matrix is what a normal equations solve, a kernel method, a covariance estimate and a least-squares fit all produce, and “nearly dependent columns” is the ordinary situation in all four.
What the disagreement rate is a function of
The bars are not uniform across the horizontal axis and the shape is worth reading rather than averaging away: 7 disagreements at a separation of 10⁻⁸, 2 at 10⁻⁹, 4 at 10⁻¹⁰, 10 at 10⁻¹¹ and 3 at 10⁻¹². The rate does not climb monotonically as the matrices get harder, which is what a first guess would predict.
The reason is that two things move in opposite directions. As the columns become more nearly dependent, the true smallest pivot falls — so it is more often below the rounding, and the two builds are more often deciding a sign from noise. But past a point both builds are deciding from noise, and two coin flips agree half the time. The disagreement rate is highest in the band where the pivot and the rounding are comparable, and falls off on both sides of it: above, because both builds are right; below, because both are guessing and guessing agrees as often as not.
That band is narrow — about two decades wide here — and its position is set by the size of the matrix and the scale of its entries rather than by anything a caller controls. Which is the practical reason the phenomenon is under-reported: a test suite that happens to sample outside the band sees perfect agreement and concludes there is nothing to see, and the same suite on a slightly different problem sees a third of its matrices flip.
What the verdict is actually reporting
Here is the reading that makes the census less alarming and more useful.
When the two builds disagree, the true smallest pivot is smaller than the rounding either build commits. In that regime the question is this matrix positive definite has an exact answer — the minors settle it — and it is a question about the matrix’s last few bits rather than about anything a computation is going to use.
A matrix with a smallest eigenvalue of 10⁻²⁰ relative to its largest is definite, and every computation done with it will behave as though it were singular. Its Cholesky factor, if one is produced, has a last column of noise. The definiteness verdict is true and it is not useful, which is a distinction the subject has a standing answer for: report the pivot, not the verdict.
That is what makes this essay a companion to rank is a decision rather than a scandal. Rank is not a property a floating-point matrix has; it is a decision about a gap, and the honest output of a rank computation is the spectrum with the threshold drawn on it. Definiteness is the same object with the threshold nailed to zero, and nailing a threshold to zero is what makes it a machine-dependent decision rather than a reported one.
The repair, which is not to fix the arithmetic
Three options, and the third is the recommendation.
Compute the pivots exactly. The minors in BigInt settle it, at a cost that is polynomial and enormous — this site can afford it up to about 10 × 10 and not beyond. It is the right instrument for adjudicating a census and the wrong one for a solver.
Make the inner products order-independent. Pre-rounded accumulation removes the disagreement between partitionings, but not between the fused and unfused forms — those differ in how a single product is rounded, which is upstream of the summation policy. So this fixes one of the two causes in the field and not this one.
Report the smallest pivot beside the verdict, and let the caller set a threshold. This is what
LAPACK’s info plus the diagonal of the factor already allows and what almost no caller reads. A
routine that returns definite, smallest pivot 3.1·10⁻¹⁷, matrix norm 4.2 has said everything, and
a caller who wants a machine-independent answer thresholds the pivot at something above the
rounding.
The third option is free, and it converts a verdict two builds disagree about into a number they agree about to within a factor.
Where else a sign is a verdict
The census is about definiteness because definiteness is the cleanest case, but the same shape appears wherever a computed sign chooses a branch, and the field’s other essays are the same argument on different objects:
- a pivot’s sign in a symmetric indefinite factorisation, which decides between a 1 × 1 and a 2 × 2 block — when symmetry is not enough;
- a residual’s comparison with a tolerance, which decides whether to stop — a stopping test is a race;
- a singular value’s comparison with a threshold, which decides a rank — a rank that depends on the thread count;
- a polynomial’s sign near a root, which decides which side a bisection takes — a square that evaluates negative.
Four verdicts, four different mechanisms, and one common feature: each turns a real number that two builds compute differently into a discrete outcome that has no room to differ a little.
A note on what was held fixed
The census is careful about one thing that is easy to get wrong, and the care is the reason its number means anything.
Both builds are handed the same matrix, and that matrix’s entries are computed exactly. If the Gram matrix were formed in ordinary arithmetic, the fused and unfused builds would each assemble a slightly different AᵀA, and a disagreement afterwards would be a disagreement about two different matrices — which is a much weaker and less interesting statement, and is the one an unguarded experiment would have measured.
Fixing the matrix costs an error-free product expansion per entry and it moves the question from do two builds compute different matrices to do two builds reach different verdicts about one matrix. Only the second is a statement about the factorisation, and only the second has an exact adjudicator, since the exact minors are minors of a matrix that has to be the same one.
The same discipline is why the adjudicator uses rationals rather than a longer float. A quadruple precision Cholesky would agree with one of the two builds most of the time and would be a third opinion rather than a verdict — and this site’s habit is that two routes to a number means two routes that share no arithmetic, not two precisions of one.
The one that cannot be repaired at all
A closing observation about the limit of the recommendation.
Report the number and let the caller threshold it works when there is a number to report. It does not work when the branch is inside a library the caller cannot see — when a factorisation routine tries a 2 × 2 pivot, or a solver switches to a different algorithm on detecting near-singularity, or an eigensolver deflates a converged value. Those decisions are made from computed quantities, taken inside a routine, and never surfaced.
That is the position most callers are in most of the time, and it is why this field’s practical advice ends where the library’s interface does. What can be measured from outside is the spread of the final answer, and what can be asked for is a tolerance that admits it, which is the subject of what a regression test can ask for.
What this costs somebody who has to ship
The uncomfortable version, since a reader who maintains a solver has to do something on Monday.
An algorithm that branches on definiteness — and there are many: a trust-region method choosing between a Newton step and a direction of negative curvature, a preconditioner deciding whether a Cholesky is available, an optimiser testing a Hessian — has a branch whose direction is a property of the build. Two machines then take different code paths, and after a different code path the answers are not close: they are the answers of two different algorithms.
That sounds worse than it is, and the reason is the one this essay’s middle section makes. The branch differs only when the true pivot is below the rounding, and in that regime both branches are defensible — a matrix that is definite by 10⁻²⁰ is a matrix a Cholesky cannot usefully factorise, and the negative-curvature branch is not the wrong thing to do with it. The divergence in the answers is real and the divergence in their quality usually is not.
Which yields the practical rule, and it is the same one negative curvature is the useful direction reaches from the other side: branch on a margin, never on a sign. Test the pivot against a multiple of the rounding — n·u·‖A‖ is the honest scale — rather than against zero. Both builds then take the same branch, because both agree about which side of a threshold that is orders of magnitude above their disagreement a number lies on.
The cost is one constant that has to be chosen and defended, which is the cost this site’s regularisation field spends four essays on. The alternative is a branch that no test can pin down.
At other settings
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.
- Small compared to what — both name condition squaring, exact arithmetic
Named objects
A flat tag is an object no other essay names yet.
Cholesky factorisationCondition squaringDefiniteness testExact arithmeticExpression contractionFused multiply-addGram matrixPositive definite