Catastrophic Cancellation
- •
What it is
- •
severe loss of significant digits that occurs when subtracting two nearly-equal numbers (), since their leading digits cancel out and only rounding-error digits remain
- •
- •
- •
Mitigation strategies (each with a worked example)
- •
Algebraic reformulation can substantially reduce cancellation, but does not universally guarantee full precision or eliminate every source of error.
- •
Rationalization: . The second form can reduce cancellation; attainable accuracy still depends on the inputs and arithmetic.
- •
For the quadratic example above, the rationalized expression improves the small-root calculation. The direct float64 calculation loses accuracy but does not return zero in the checked example.
- •
trigonometric identity substitution — for small cancels to zero directly; the double-angle identity computes correctly
- •
Taylor series substitution — for very small loses precision directly; expanding via its Taylor series and simplifying gives a numerically stable formula
- •
two-pass variance formula — the textbook shortcut can catastrophically fail for data with large values close together (e.g. ), potentially even producing a mathematically impossible negative variance; computing deviations from the mean directly () avoids this
- •
- •
- •
Related