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 rationalization — loses 100% of its precision computed directly at large ; rewriting via the conjugate as recovers full precision
- •
alternate quadratic formula — the standard formula catastrophically fails for (returns instead of the correct ); the algebraically equivalent form avoids the cancellation entirely
- •
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
- •
- •