42.4 Error Analysis and Stability

Finite‑precision arithmetic accumulates error. Understand where it arises and how to mitigate it.


42.4.1 Sources of Error

  • Rounding in floating‑point operations
  • Catastrophic cancellation (subtracting nearly equal numbers)
  • Accumulation across long sums/products

42.4.2 Mitigation Techniques

  • Kahan summation for dot products
  • Reorder operations to improve conditioning (e.g., sum small to large)
  • Scale/normalize inputs to avoid extreme magnitudes

42.4.3 Validation Metrics

  • Relative/absolute error
  • Unit in last place (ULP) differences
  • Residual checks for linear systems
float ulpDiff(float a, float b) { return Math.ulp(Math.max(Math.abs(a), Math.abs(b))); }