Cancellation and Stable Formula Design

Rewrite a difference of nearby computed quantities to preserve meaningful digits, then check its domain and other numerical risks.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Subtracting estimates can expose their prior errors
  2. Rationalize the difference under suitable conditions

Subtracting estimates can expose their prior errors

For large positive \(x\), the expression \(\sqrt{x^2+1}-x\) is small even though both terms are large. If the rounded square root equals \(x\), their subtraction gives zero. The cancellation may occur even when the subtraction itself is exact, because information was already lost in the rounded operands.

Rationalize the difference under suitable conditions

Multiplying numerator and denominator by the conjugate gives

\[ \sqrt{x^2+1}-x=\frac{1}{\sqrt{x^2+1}+x}. \]

For positive large \(x\), the denominator adds quantities of the same sign and the formula retains the small result more faithfully. Squaring \(x\) can still overflow, so a robust implementation can compute the norm-like denominator with scaling. The best rewrite can differ for negative \(x\). Floating-point spacing explains the lost increment. Condition numbers separate sensitivity of the mathematical problem from avoidable error introduced by a formula.[1][2]

References

  1. Nicholas J. Higham, Accuracy and Stability of Numerical Algorithms ↩
  2. Jonathan Richard Shewchuk, Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates ↩