Floating-Point Arithmetic, Conditioning, and Stability
Why finite-precision numbers are enough - and the two independent things that can still ruin an answer.
Leads to: Conditioning and stability are the lens for judging LU, QR, Cholesky and eigen-solvers in 5.2–5.5.
Learning Objectives
Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.
- Explain the IEEE-754 double model and bound rounding by machine epsilon.
- Define the condition number of a problem and compute it for matrix solves.
- Distinguish a well-posed but ill-conditioned problem from an unstable algorithm.
- Interpret backward stability and the rule of thumb error ≤ condition × machine epsilon.
- Implement a 2-norm condition-number routine and diagnose catastrophic cancellation.
Key Vocabulary
- Machine epsilon
- The gap between 1 and the next representable double, \(\epsilon_{\text{mach}}\approx 1.1\times10^{-16}\); bounds relative rounding error.
- Floating-point number
- A value \(\pm(1.f)_2\times 2^{e}\) with a finite mantissa; only finitely many exist in any range.
- Condition number
- How much a problem amplifies relative input error; for solving \(Ax=b\) it is \(\kappa(A)=\lVert A\rVert\,\lVert A^{-1}\rVert\).
- Backward stability
- An algorithm is backward stable if its computed answer is the exact answer to a slightly perturbed input.
- Catastrophic cancellation
- Loss of significant digits when subtracting two nearly equal, individually rounded numbers.
- Forward error
- The difference between the computed and true answer; bounded by (condition)×(backward error).
Intuition & Motivation
Floating point in one model
A double stores a sign, a 52-bit mantissa, and an 11-bit exponent. The key fact for analysis is that rounding any real \(x\) to its nearest double \(\text{fl}(x)\) costs at most a relative \(\epsilon_{\text{mach}}\):
Each elementary operation \(\{+,-,\times,\div\}\) incurs one such \(\delta\). Errors normally accumulate gently - except under subtraction of near-equal numbers, where the leading digits cancel and only rounding noise remains.
Interactive: watch a solve amplify error
Drag the near-singular entries and see how the solution of \(Ax=b\) reacts to tiny changes - the geometric meaning of a large condition number.
Interactive: compute the condition number
Implement the 2-norm condition number from the SVD and confirm the diagnosis above numerically.
- Blaming the solver for a large forward error when the matrix is ill-conditioned - that error is unavoidable.
- Testing floating-point results with
==instead of a tolerance. - Computing variance as E[x²]−E[x]² on clustered data, inviting catastrophic cancellation (use a two-pass or Welford method).
- Assuming more iterations always help; past \(\kappa\epsilon_{\text{mach}}\) accuracy you are only refining noise.
- Report the condition number alongside any linear solve; it tells you how many digits you can trust.
- Prefer backward-stable factorizations (QR, Cholesky) over forming \(A^{-1}\) or normal equations explicitly.
- Rule of thumb: you lose about \(\log_{10}\kappa\) decimal digits solving \(Ax=b\).
- Scale/equilibrate columns so units don’t artificially inflate the condition number.
Practice this in the Euler Lab
Computational problems that exercise exactly this technique. Each opens in the Euler Lab with a Python workbench, a progressive hint ladder, and answer checking. Tier A/B run at full scale in the browser.
Warm-up:
#24 Lexicographic Permutations (6%, tier A) #65 Convergents of $e$ (6%, tier A) #205 Dice Game (10%, tier A) #68 Magic 5-gon Ring (9%, tier B)
Applied:
#816 Shortest Distance Among Points (17%, tier B) #323 Bitwise-OR Operations on Random In (18%, tier B) #479 Roots on the Rise (19%, tier B)
Challenge:
#666 Polymorphic Bacteria (41%, tier C) #869 Prime Guessing (41%, tier C)
146 Project Euler problems in total are mapped to this lesson. Open the Euler Lab to filter them all.
Knowledge Check
Practical Exercise
Explain, using the backward-stability bound, why solving the normal equations \(A^\top A x = A^\top b\) for least squares can lose twice as many digits as a QR-based solve. Give the key inequality.
The conditioning of the least-squares problem scales with \(\kappa(A)\). Forming \(A^\top A\) squares the singular values, so \(\kappa(A^\top A)=\kappa(A)^2\).
A backward-stable solve of the normal equations therefore yields forward error \(\sim\kappa(A)^2\,\epsilon_{\text{mach}}\), whereas a QR-based solve keeps the conditioning at \(\kappa(A)\), giving \(\sim\kappa(A)\,\epsilon_{\text{mach}}\).
Lesson Summary
Retrieval Practice
Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.
A: For a backward-stable algorithm, relative forward error is on the order of \(\kappa\,\epsilon_{\text{mach}}\); you lose about \(\log_{10}\kappa\) digits.
A: Because \(\kappa(A^\top A)=\kappa(A)^2\), squaring the conditioning and doubling the digits lost; QR avoids this.
Completion Checklist
- I can explain the core ideas in my own words
- I worked the derivations/examples by hand
- I completed the interactive workbench(es)
- I passed the knowledge check
Source References
This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.
- Numerical Linear Algebra (Trefethen & Bau, SIAM, 1997) foundational - Lec 12–15 - Lectures 12–15: floating point, conditioning, stability, backward error.
- Linear Algebra Done Right (Sheldon Axler, 4th ed., 2024) current - Ch. 7 - Singular values and operator norms behind \(\kappa=\sigma_{\max}/\sigma_{\min}\).