A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Catastrophic Cancellation

Graduate Depth 86 in the knowledge graph I know this Set as goal
8topics build on this
342prerequisites beneath it
See this on the map →
Rounding Errors and Error PropagationNumerical Stability and Conditioning
cancellation subtraction error-amplification

Core Idea

Catastrophic cancellation occurs when subtracting two nearly equal floating point numbers, losing most significant digits in the result. A relative error of 10⁻¹⁶ in the inputs can become an error of magnitude 1 in the output. Recognizing and avoiding this phenomenon through algebraic reformulation is critical for stable algorithms.

How It's Best Learned

Compute examples like √(x²+1) - √(x²) for large x using direct and rationalized forms to see the difference in accuracy.

Common Misconceptions

Explainer

From your study of rounding errors, you know that floating-point numbers are stored with a fixed number of significant digits — roughly 15–16 decimal digits for IEEE 754 double precision. Each number carries a tiny relative error: a stored value x̂ satisfies x̂ = x(1 + ε) where |ε| ≤ machine epsilon ≈ 10⁻¹⁶. This small relative error is usually harmless. Catastrophic cancellation is what happens when subtraction destroys this safety.

Consider computing a = 1.000000000000001 and b = 1.000000000000000 in double precision. Each is accurate to 15 significant digits. Their difference a − b should be 10⁻¹⁵, but in a 64-bit float both values may round to exactly the same stored representation, yielding a − b = 0 — a relative error of 100%. More generally, when two numbers agree to k significant digits, their difference has at most (15 − k) significant digits of accuracy. If they agree to 14 digits, the difference has only 1 significant digit. This is catastrophic cancellation: the leading significant digits cancel away, leaving a result dominated by rounding noise from both operands.

The classic example is the quadratic formula. For large c/a, the roots x = (−b ± √(b² − 4ac)) / (2a) involve adding and subtracting nearly equal quantities when b² ≫ 4ac. Concretely, take b = 10⁸ and b² − 4ac = 1: then √(b² − 4ac) ≈ 10⁸ as well, and computing −b + √(b² − 4ac) subtracts two numbers that agree to 8 digits, leaving only ~7 digits of accuracy in a result that should be close to zero. The fix: use the rationalized form x = −2c / (b + √(b² − 4ac)) for the small root, which avoids the cancellation entirely by multiplying and dividing rather than subtracting near-equal terms.

The general strategy is algebraic reformulation: rewrite expressions to avoid subtraction of near-equal quantities before evaluation. Common techniques include multiplying and dividing by the conjugate (for expressions like √(x + h) − √x), using Taylor expansions for quantities where direct subtraction is near zero (e.g., ex − 1 near x = 0 should use the built-in `expm1` function), or using compensated summation algorithms like Kahan summation for summing many small terms. Switching from float to double helps by pushing the danger threshold further away, but it cannot fix a structurally cancellation-prone formula — only reformulation can.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsLogic Gates FundamentalsImplementing Boolean Functions with GatesKarnaugh Map SimplificationCombinational Circuit DesignFlip-Flops and LatchesBinary Counters: Design and AnalysisBinary ArithmeticFixed-Point Number RepresentationTwo's Complement RepresentationFloating-Point Representation (IEEE 754)Machine Epsilon and Unit RoundoffFloating Point RepresentationRounding Errors and Error PropagationCatastrophic Cancellation

Longest path: 87 steps · 342 total prerequisite topics

Prerequisites (1)

Leads To (1)