Floating point problem set, part b: condition numbers, error bounds, Newton, polynomial approximation, low precision
Overview
Section titled “Overview”| Module | S-M09b · solve · none · Pass 6 · 4 to 5 h |
| You build | answers in solve/S-M09b.toml (29 checked by SymPy) and 3 proofs in solve/S-M09b/q6.md, q12.md, q17.md (self-graded against their rubrics) |
| Contract | none: a pen and paper set |
| Tests | course/solve/S-M09b/key.toml (hidden): typed answers plus reject canaries; the problems are in course/solve/S-M09b/problems.md and in section 4 |
| Needs | no code. Reading: S-M09a (representation and rounding), M09.3 (the error bounds and condition numbers as code), M09.4 (the fp8 and MX formats as code), M01.2 (Newton’s method) |
| Used by | no call site (a solve set). Do it beside M09.3 and M09.4; q14 to q17 prepare M09.5 (Newton rsqrt in C) and q18 to q20 prepare M09.6 (expf in C) |
| Milestone | MS-P6 (the Pass 6 gate runs ol check on every solve part of the pass) |
| Optional depth | Higham, Accuracy and Stability of Numerical Algorithms, ch. 2 to 4 and 7; Trefethen, Approximation Theory and Approximation Practice (SIAM, 2013), ch. 1 to 4; Muller, Elementary Functions: Algorithms and Implementation (3rd ed., 2016), ch. 3 and 11 |
Key Takeaways
Section titled “Key Takeaways”- The relative condition number and the matrix condition number say how much the problem amplifies input errors, whatever the algorithm (q1 to q6).
- Every rounding multiplies by , , and of them stay within ; pairwise summation cuts to , and random signs typically give (q7 to q12).
- Fixed-point iteration converges linearly at the rate ; Newton converges quadratically at a simple root, so the correct digits double each step (q13 to q17).
expfreduces to and evaluates a short polynomial; the Lagrange remainder fixes the degree, and Chebyshev nodes minimize the interpolation error’s node product (q18 to q23).- fp8 and MX formats are the same rounding with few bits: E4M3 has precision and range to 448, E5M2 trades a bit of precision for range to 57344, and an MX block scale is the power of two that puts the block’s maximum in the top binade (q24 to q28).
How to work this chapter
Section titled “How to work this chapter”ol start S-M09b # writes solve/S-M09b.toml and the proof filesol check S-M09b # SymPy checks the answers, then asks each proof rubric (y/n)ol check S-M09b --regrade # ask the rubrics again after you change a proof1. Why now
Section titled “1. Why now”Part 8 compares numbers that should agree but were computed differently: your sampler’s float64 sums against the Rust engine’s, a quantized matmul against float32, a float16 KV cache against a float32 one. Part 9 then writes rsqrt by Newton’s method and expf by range reduction and a polynomial, in C, and must prove them accurate to a few ulps. M09.3 and M09.4 turn the bounds and the formats into code; this set makes you derive them by hand first, so a failing tolerance or a kernel that is off by one ulp is something you can explain rather than tune.
2. Principles
Section titled “2. Principles”| Symbol | Meaning | Type / shape |
|---|---|---|
| unit roundoff, significand bits with the implicit 1 | float | |
| accumulated relative error of roundings | float | |
| relative condition number of at | float | |
| 2-norm condition number | float | |
| , | an iteration map and its fixed point | function, float |
| the error after steps | float | |
| the Chebyshev polynomial of degree , | polynomial | |
| an MX block scale, a power of two | float |
2.1 Conditioning
Section titled “2.1 Conditioning”A relative change in the input changes the output of by about (first-order Taylor). For , , with and . The singular values of are the square roots of the eigenvalues of , not the eigenvalues of (they coincide only for symmetric positive semidefinite ).
2.2 Error bounds
Section titled “2.2 Error bounds”Under , , a dot product of length in any order satisfies . To first order . A balanced (pairwise) tree puts each term through additions instead of up to . Rounding errors with independent random signs add like a random walk, so the typical error is about ; the worst case is .
2.3 Iterations
Section titled “2.3 Iterations”If is differentiable near a fixed point , then : linear convergence with rate when it is below 1. Newton’s iteration for a root of is ; at a simple root and : quadratic. At a double root too and the rate degrades to linear.
2.4 Polynomial approximation
Section titled “2.4 Polynomial approximation”Taylor’s theorem with the Lagrange remainder: with . Range reduction , , keeps , so a short polynomial suffices, and is an exponent adjustment. Horner’s rule uses multiplications for degree . Interpolating at nodes leaves an error proportional to ; the Chebyshev nodes (zeros of ) make that product the monic , whose maximum on is , the smallest possible.
2.5 Low precision
Section titled “2.5 Low precision”A format with fraction bits and bias has quantum near ; rounding is to the nearest multiple, ties to the even significand. E4M3 (, , max 448), E5M2 (, , max 57344, top exponent reserved), FP4 E2M1 (values 0, 0.5, 1, 1.5, 2, 3, 4, 6). An MX block scale is , with the exponent of the element format’s largest normal.
3. Worked example by hand
Section titled “3. Worked example by hand”These are siblings of q1, q14, and q24, not graded problems.
Conditioning of . , so for every : square roots halve relative errors.
One Newton step for . With and : . The relative error drops from to , close to : quadratic.
2.75 to E4M3. , quantum , exactly: value 2.75, code . Decode: , , .
4. The problem set
Section titled “4. The problem set”Write each answer in solve/S-M09b.toml; lettered parts are their own tables:
[q1]answer = "1001"[q7]answer = "3/(2^24 - 3)"[q16.b]answer = "1/2"[q6]proof = "S-M09b/q6.md"Give exact values as integers, fractions, powers of two, or expressions in log; only q13 accepts a decimal, within a relative tolerance of .
Condition numbers
Section titled “Condition numbers”q1. Give the relative condition number of at . [number]
q2. Give the relative condition number of at . [number]
q3. Give of . [number]
q4. Give of . [number]
q5. and moves by a relative amount . Give the bound on the relative change of the solution of . [number]
q6. Prove that if and with invertible and , then in the 2-norm. [proof]
Sum and dot error bounds
Section titled “Sum and dot error bounds”q7. Give for float32 exactly. [number]
q8. A float32 dot product of length has . Give the first-order bound on its error. [number]
q9. The same dot product with the sum done pairwise: give the first-order bound (one rounding per product, one per tree level). [number]
q10. In bf16, give the smallest for which , where the bound says nothing. [number]
q11. The statistical rule of thumb replaces by (errors with random signs add like a random walk). Give it for float32 and . [number]
q12. Prove that recursive summation of three numbers satisfies under the model , . [proof]
Fixed point and Newton convergence
Section titled “Fixed point and Newton convergence”q13. The iteration converges to the fixed point . Give its asymptotic linear rate to at least 7 significant digits. [number, rtol 1e-6]
q14. Newton’s method for gives , the update M09.5 uses for rsqrt. With and , give exactly. [number]
q15. Let be the relative error of that iteration. Using the identity of q17, give exactly when . [number]
q16. (a) Give the order of convergence of Newton’s method at a simple root. (b) At a double root Newton converges only linearly; give the rate (the ratio in the limit). [number]
q17. Prove that the iteration of q14 satisfies , and conclude that it converges quadratically. [proof]
Polynomial approximation
Section titled “Polynomial approximation”q18. expf reduces with , so . Give for , exactly. [number]
q19. Give the half-width of the interval the reduced argument lies in. [number]
q20. On , the Taylor polynomial of of degree has the Lagrange bound . Give the smallest for which it is below . [number]
q21. How many multiplications does Horner’s rule use for a polynomial of degree 7? [number]
q22. Give the three Chebyshev nodes on (the zeros of ). [set]
q23. Give for those three nodes. [number]
Low-precision arithmetic
Section titled “Low-precision arithmetic”q24. Round to e4m3 (OCP E4M3: bias 7, 3 fraction bits) with round to nearest, ties to even. (a) Give the value. (b) Give the code as an unsigned integer (sign bit, then 4 exponent bits, then 3 fraction bits). [number]
q25. (a) Give the largest finite e5m2 value (bias 15, 2 fraction bits, the top exponent field reserved for infinity and NaN). (b) Give the smallest positive e4m3 value. [number]
q26. Give the unit roundoff of e4m3. [number]
q27. An MX block in fp4 E2M1 (largest value 6, ) has largest magnitude 13. (a) Give its shared scale . (b) Give the dequantized value of the element 13. [number]
q28. Which fp8 format covers the wider range of magnitudes? (a) e4m3 (b) e5m2 [choice]
5. Pitfalls
Section titled “5. Pitfalls”| Pitfall | Symptom | Caught by |
|---|---|---|
| The absolute condition for the relative one | instead of 50 | q2 (canary exp(50)) |
| Eigenvalues of for singular values | instead of 3 for a non-symmetric matrix | q4 (canary 5/3) |
| for | every bound off by 2; bf16 void at 128 | q7, q8, q10 (canaries with 2^-23, 2^-11, 128) |
| Forgetting that products round too | the pairwise bound one short | q9 (canary 12*2^-24) |
| Quoting the fixed point instead of the rate | 0.739 for 0.674 | q13 (canary) |
| Keeping only the leading term of Newton’s error | instead of | q15 (canary) |
| Rounding up instead of to nearest | a reduced argument outside | q18 (canary 10 - 15*log(2)) |
| Equispaced interpolation nodes | a larger node product (0.385 vs 0.25) | q22, q23 (canaries) |
| E5M2’s or the significand count’s grid for E4M3’s code | wrong value or code | q24 (canaries 21/4, 11, 83) |
| A per-tensor float scale where MX wants a power of two | a scale of 13/6 | q27 (canary 13/6) |
6. Where it’s used next
Section titled “6. Where it’s used next”| Direction | Module | How it uses this |
|---|---|---|
| Back | S-M09a | representation, rounding, and cancellation |
| Back | M01.2 | Newton’s method as code, behind q14 to q17 |
| Forward | M09.3 | q1 to q12 as code: relative_condition, cond, gamma, dot_error_bound |
| Forward | M09.4 | q24 to q28 as code: fp8, FP4, and MX scales |
| Forward | M09.5 | rsqrt in C: q14 to q17’s Newton update and its quadratic convergence |
| Forward | M09.6 | expf in C: q18 to q21’s range reduction, degree, and Horner evaluation |
| Forward | L8.5 | quantization error budgets combine q8 with q24’s rounding error |