15.3 Error analysis, condition numbers, and tolerance budgets
Sooner or later every numerical codebase has to compare two numbers that are not equal and must not be. In AI Engineering, the C matmul of Cache-blocked, packed, batch-invariant matmul in C sums in tiles while numpy sums pairwise in blocks, and the two agree only to rounding. The int8 and int4 kernels of Fused int4 and int8 dequantize-matmul in C start from weights that Quantization: int8, int4 groups, fp8, and the KV cache moved on purpose. A tolerance chosen by eye fails in one of two ways. Too tight, and a correct kernel fails on a long row, because the error of a dot product grows with its length. Too loose, and a kernel that drops one term of 257 passes.
Concepts from other sections (15)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Dot product: ; it measures how much two vectors point the same way, and it is zero exactly when they are perpendicular. Read more: Chapter 10: Calculus 3
- BF16: a 16-bit float with float32’s sign and exponent and 7 mantissa bits; the top half of a rounded float32. Read more: 6.7 Safetensors for every dtype, atomic checkpoints, and the token stream in AI Engineering
- Relative condition number: , the factor by which amplifies relative input errors. Read more: 15.9 Problem set B: condition numbers, error bounds, Newton, polynomial approximation, and low precision
- machine epsilon: , the gap between 1 and the next float64. Read more: 7.1 Derivatives and Finite Differences
- rounding error: the error from floating-point rounding, about in a difference quotient. Read more: 7.1 Derivatives and Finite Differences
- Eigenvector / eigenvalue: a non-zero and scalar with . Read more: 9.4 Eigenvalues, power iteration, and the spectral radius
- forward difference: , a first-order approximation of . Read more: 7.1 Derivatives and Finite Differences
- truncation error: the error from dropping the higher terms of the Taylor series. Read more: 7.1 Derivatives and Finite Differences
- central difference: , a second-order approximation of . Read more: 7.1 Derivatives and Finite Differences
- Gradient check: a comparison of an analytic gradient against the numerical one that reports pass or fail and the element furthest past its allowance. Read more: 10.1 Partial derivatives, gradients, and gradcheck
- Subnormal: a value with exponent field 0, no implicit leading 1, and a fixed exponent , filling the gap between zero and the smallest normal. Read more: 15.1 IEEE 754 anatomy, ulps, and round to nearest even
- Differential test: a check that two implementations of the same contract agree on generated inputs. Read more: 3.3 Oracles, golden and differential tests, gradcheck as a test in Software Engineering
- Transformation (JAX): a function such as
jit,grad,vmap, orpmapthat takes a pure function and returns a compiled, differentiated, batched, or parallel version of it. Read more: 16.3 Embeddings, small models, and platforms in AI Engineering - Gradcheck: a comparison of a hand-written gradient against central differences of . Read more: 3.3 Oracles, golden and differential tests, gradcheck as a test in Software Engineering
- central differences: the numerical derivative , used as an oracle for analytic gradients. Read more: 6.3 The op library and gradcheck_all in AI Engineering
The usual way out is a rule, which is a statistical rule of thumb. This section derives the rigorous version before the kernels arrive: where the error comes from, how big it can be for a given input, and how much of it is the problem’s fault rather than the algorithm’s. You will build one model of rounding, use it to bound sums, dot products, and matrix products, add deliberate perturbations such as quantization to the budget, separate conditioning from stability, and finally use the same reasoning to choose the step of a finite difference.
The section builds on the unit roundoff of IEEE 754 anatomy, ulps, and round to nearest even, the summation orders of Stable numerics, and the cancellation problems of Problem set A. In code it uses svd from SVD, Eckart-Young low rank, and least squares (its singular values feed cond) and central_diff from Derivatives and Finite Differences (the real difference the optimal step is measured against). The reference implementation is tolerance.py, with its interface in tolerance.pyi.
Learning objectives
- Derive from the standard rounding model and use it to bound the error of a sum, a dot product, and a matrix product in any summation order.
- Explain why rounding bounds scale with rather than .
- Build a tolerance budget that includes a deliberate perturbation such as quantization.
- Compute the condition number of a scalar function and of a linear system, and explain what it says that an algorithm cannot fix.
- Derive the optimal step for forward and central finite differences.
The notation
Section titled “The notation”The symbols used throughout the section:
| Symbol | Meaning | Type / shape |
|---|---|---|
| significand bits including the implicit 1: 53 (f64), 24 (f32), 11 (f16), 8 (bf16), 4 (e4m3), 3 (e5m2) | integer | |
| unit roundoff: the largest relative error of one rounding | float | |
| the floating-point result of an expression | float | |
| the relative error of one rounding, | float | |
| the accumulated relative error of roundings, for | float | |
| the vectors of a dot product | float[k] | |
| elementwise absolute value | float[k] | |
| matrices, is , is | float[m, k], float[k, n] | |
| the largest and smallest singular values | float | |
| the 2-norm condition number | float | |
| the relative condition number of a scalar function | float | |
| a finite-difference step | float |
The rounding model
Section titled “The rounding model”IEEE arithmetic rounds the exact result of each operation to the nearest float, so for
is half the gap between 1 and the next float. That gap is (machine epsilon, np.finfo(np.float32).eps ), and rounding to the nearest float errs by at most half of it, for float32. Counting the implicit bit matters: bf16 stores 7 fraction bits but keeps 8 significant bits, so its is .
One rounding is easy. The interesting question is what happens when a value passes through many. After roundings it carries a factor , and if ,
The proof is an induction: , and . To first order ; the denominator makes the bound rigorous and says it is void once , which for bf16 happens at .
Now apply it to a dot product summed left to right: , . The term goes through one multiplication and additions, and for through one multiplication and additions. Every term goes through at most roundings, so
The same count holds for any order of the additions (pairwise, blocked, tiled), because each term meets at most additions. That is why one bound covers numpy’s BLAS, the tiled C kernel, and a plain loop. A sum without products (, exact multiplications) needs only , since one term alone is exact.
The bound has an absolute value inside the sum, and that is not a technicality. The roundings are relative to the partial sums, and the partial sums can be large even when the result is small. in float32 computes , then : the exact result is lost completely, a 100% relative error, and that is correct float32 arithmetic. The bound allows it. A bound proportional to would call a correct kernel broken. For a matrix product the elementwise bound is .
Tolerance budgets
Section titled “Tolerance budgets”With a bound for rounding in hand, you can write a test allowance that is derived rather than guessed. A test compares an implementation against a reference, and every source of difference must be in the allowance, and nothing else:
With quantization to a grid of step , each weight moves by at most . With it is the plain rounding bound that the standalone C matmul is checked against. bound_ratio reports : at most 1 passes, and how close to 1 it is tells you whether the test can still catch a bug. assert_close_bounded multiplies the dot bound by a slack (default 4) because the “expected” side is itself computed in floating point (in float64, or in float32 by a different order).
The worst case is rarely reached. Rounding errors have random signs and partially cancel, so the typical error grows like , not (Higham and Mary 2019). A statistical rule uses that: tolerances times . It is tighter and almost always right; the bound here is looser and always right. Use the bound when a false failure would be expensive to debug.
Condition numbers
Section titled “Condition numbers”So far the question has been how wrong an algorithm can be. Error analysis separates that from a second question. The backward error of an algorithm asks: for which nearby input is my computed output the exact answer? The condition number of the problem asks: how much does the exact answer move when the input moves? The forward error is at most their product.
For a scalar function, a relative change in changes by , a relative change of
has : it halves relative errors. near has , which is at . The cancellation of Problem set A is ill-conditioning, a property of subtraction near equal numbers, not of any algorithm.
For a linear system and a perturbation , you have , so , and . Multiplying,
in the 2-norm, where and . Equality holds when lies along the top left singular vector and along the bottom one. Eigenvalues are not a substitute: has both eigenvalues 1 and . A matrix whose is below is singular to working precision, and cond returns rather than a meaningless .
The optimal finite-difference step
Section titled “The optimal finite-difference step”The same two-sided accounting answers a question from the calculus chapters: how small should a finite-difference step be? The forward difference of Derivatives and Finite Differences has truncation error (Taylor) and rounding error up to (two evaluations, each off by , divided by ). The total is
with and . The central difference has truncation and rounding :
In float64 with unit scales that is about and , and the best achievable errors are about and . The central difference wins by three orders of magnitude, which is why gradient checks use it.
Working it by hand
Section titled “Working it by hand”Two small examples make the bounds concrete. First, a dot product that loses two terms: , , all float32. In recursive summation rounds to 1 (the gap at 1 is , and is less than half of it), and so does the next addition. The computed result is 1, the exact result is , and the error is .
For the bound, , , and , so the allowance is . The error is about 0.11 of the allowance: inside, as it must be.
Second, an ill-conditioned system. is symmetric, so its singular values are its eigenvalues, : about and . So . With the solution is . Move to , a relative change of , and the solution becomes , a relative change of . The amplification is , below 40002 as the theory says. No algorithm can do better than this problem allows. Both examples become the first test cases below.
Designing the API
Section titled “Designing the API”The helpers are for tests that compare two floating-point computations: they turn a tolerance into a derived number instead of a guess.
def unit_roundoff(dtype: str) -> float # "f32" -> 2^-24def gamma(k: int, dtype: str) -> float # k u / (1 - k u)def sum_error_bound(k: int, dtype: str, abs_sum) -> NDArray # gamma_(k-1) * sum|x|def dot_error_bound(k: int, dtype: str, abs_dot) -> NDArray # gamma_k * |x|.|y|def matmul_error_bound(A, B, dtype: str, dA=0.0) -> NDArray # dA|B| + gamma_k (|A| + dA)|B|def assert_close_bounded(actual, expected, k: int, dtype: str, abs_dot, slack: float = 4.0) -> Nonedef bound_ratio(actual, expected, bound) -> float # max |error| / bounddef cond(A) -> float # sigma_max / sigma_min via svddef relative_condition(f, df, x: float) -> float # |x f'(x) / f(x)|def fd_error_model(h, order, dtype, f_scale=1.0, deriv_scale=1.0) -> floatdef optimal_fd_step(order, dtype, f_scale=1.0, deriv_scale=1.0) -> floatdtype is one of "f64", "f32", "f16", "bf16", "e4m3", "e5m2" or the numpy names.
Building it step by step
Section titled “Building it step by step”Each function falls out of one principle. Everything starts from : every bound above is a multiple of , so the first piece is a table of (significand bits including the implicit 1) per format. Storing rather than keeps the table exact and readable, and is one power of two away. Next, must refuse where it is void. The induction proves only for ; past that point no finite number is a bound, so the honest output is an error, not a large float.
# significand bits including the implicit leading 1_PRECISION = { "f64": 53, "float64": 53, "f32": 24, "float32": 24, "f16": 11, "float16": 11, "bf16": 8, "bfloat16": 8, # 7 stored fraction bits + the implicit 1 "e4m3": 4, "e5m2": 3,}
def unit_roundoff(dtype: str) -> float: if dtype not in _PRECISION: raise ValueError(f"unknown dtype {dtype!r}; one of {sorted(_PRECISION)}") return 2.0 ** -_PRECISION[dtype] # u = 2^-p, half of machine epsilon
def gamma(k: int, dtype: str) -> float: u = unit_roundoff(dtype) if k < 0: raise ValueError(f"k must be >= 0, got {k}") ku = k * u if ku >= 1.0: # the induction needs ku < 1 raise ValueError(f"k u = {ku} >= 1: the bound is void for k = {k} in {dtype}") return ku / (1.0 - ku) # gamma_0 = 0: no rounding, no errorAn unknown format raises rather than defaulting to float32, because a silently wrong scales every tolerance by a power of two. The bf16 entry is the one most often written as 7; the rounding model above explains why it is 8.
Then come the counts. A sum of terms has roundings, a dot product : the first term of a sum is exact, and a dot product adds one multiplication to every term. So sum_error_bound uses and dot_error_bound uses , each times the caller’s (the absolute values, not the result). A matmul bound is a matrix of dot bounds: element is a dot product of length , so the bound is , computed in float64 with one matrix product of absolute values. A deliberate perturbation enters twice: moving by at most moves the exact product by at most , and the perturbed has , so its rounding is at most .
def sum_error_bound(k: int, dtype: str, abs_sum: ArrayLike) -> NDArray: if k < 1: raise ValueError(f"a sum has k >= 1 terms, got {k}") return gamma(k - 1, dtype) * np.asarray(abs_sum, dtype=np.float64) # first term is exact
def dot_error_bound(k: int, dtype: str, abs_dot: ArrayLike) -> NDArray: if k < 1: raise ValueError(f"a dot product has k >= 1 terms, got {k}") return gamma(k, dtype) * np.asarray(abs_dot, dtype=np.float64) # + one multiply per term
def matmul_error_bound(A: ArrayLike, B: ArrayLike, dtype: str, dA: ArrayLike = 0.0) -> NDArray: a = np.abs(np.asarray(A, dtype=np.float64)) b = np.abs(np.asarray(B, dtype=np.float64)) if a.ndim != 2 or b.ndim != 2 or a.shape[1] != b.shape[0] or a.shape[1] < 1: raise ValueError(f"need A [m, k] and B [k, n] with k >= 1, got {a.shape} and {b.shape}") d = np.broadcast_to(np.asarray(dA, dtype=np.float64), a.shape) # scalar or per-weight if (d < 0).any(): raise ValueError("dA must be >= 0") k = a.shape[1] # The perturbation moves the exact product by at most dA @ |B|; rounding # the perturbed product adds gamma_k |A'| @ |B| <= gamma_k (|A| + dA) @ |B|. return d @ b + gamma(k, dtype) * ((a + d) @ b)The bounds take the absolute sum as an argument rather than the vectors: the caller already has (or computes it once in float64), and the bound then works for any shape by broadcasting. Absolute values are taken before the product (np.abs(A) @ np.abs(B)), never after, because is the cancelling quantity. For the quantization chapter, dA = abs(W - dequantize(q)) is a full matrix, which is why dA is broadcast to ‘s shape rather than required to be a scalar.
A check needs slack for its own reference. The expected side was also computed in floating point, so the comparison allows slack times the bound, and it treats NaN-against-NaN and identical infinities as equal (their difference is NaN):
def assert_close_bounded(actual, expected, k, dtype, abs_dot, slack=4.0) -> None: # ... argument checks: slack > 0, shapes equal ... allowed = slack * np.broadcast_to(dot_error_bound(k, dtype, abs_dot), a.shape) with np.errstate(invalid="ignore"): err = np.abs(a - e) # inf - inf = nan, which fails <= ok = (err <= allowed) | (np.isnan(a) & np.isnan(e)) | (a == e) if ok.all(): return i = tuple(int(j) for j in np.argwhere(~ok)[0]) # report the first failure ratio = err[i] / allowed[i] if allowed[i] > 0 else math.inf raise AssertionError(...) # count, index, actual, expected, |error|, allowed, ratio, dtype
def bound_ratio(actual, expected, bound) -> float: a = np.asarray(actual, dtype=np.float64) e = np.asarray(expected, dtype=np.float64) b = np.broadcast_to(np.asarray(bound, dtype=np.float64), a.shape) if a.size == 0: return 0.0 err = np.abs(a - e) with np.errstate(divide="ignore", invalid="ignore"): r = np.where(err == 0, 0.0, err / b) # 0/0 is "exact", x/0 is inf return float(np.max(r))The three-way ok is what makes the check usable on overflowed kernels: two NaNs agree, two equal infinities agree (a == e), and everything else must be within the allowance. bound_ratio answers the second question a budget raises: not just pass or fail, but how close to the edge, so a ratio of tells you the test could not catch a dropped term.
cond takes singular values and declares numerical singularity. , and below the smallest singular value is rounding noise, so the answer is :
def cond(A: ArrayLike) -> float: a = np.asarray(A, dtype=np.float64) if a.ndim != 2 or a.size == 0 or not np.isfinite(a).all(): raise ValueError(f"cond needs a finite, non-empty 2-D array, got shape {a.shape}") s = svd(a)[1] # singular values, descending smax, smin = float(s[0]), float(s[-1]) if smax == 0.0 or smin <= max(a.shape) * 2.0**-52 * smax: return math.inf # singular to working precision return smax / smin
def relative_condition(f, df, x: float) -> float: num = abs(x * df(x)) if num == 0.0: return 0.0 # nothing moves, even if f(x) = 0 fx = abs(f(x)) return math.inf if fx == 0.0 else num / fxcond uses singular values, not eigenvalues, because the 2-norms of and are and ; the non-normal example above has eigenvalues and . The threshold is the same rank rule numpy’s matrix_rank uses. relative_condition handles explicitly: at is infinitely ill-conditioned, while means a zero response whatever is.
Finally, the finite-difference step is the minimum of a two-term model: write truncation plus rounding, differentiate in , solve. The code is those two closed forms:
def fd_error_model(h, order, dtype, f_scale=1.0, deriv_scale=1.0) -> float: if not h > 0: raise ValueError(f"h must be > 0, got {h}") u = unit_roundoff(dtype) if order == 1: return deriv_scale * h / 2.0 + 2.0 * u * f_scale / h # E_1(h): D h/2 + 2uF/h if order == 2: return deriv_scale * h * h / 6.0 + u * f_scale / h # E_2(h): D h^2/6 + uF/h raise ValueError(f"order must be 1 (forward) or 2 (central), got {order!r}")
def optimal_fd_step(order, dtype, f_scale=1.0, deriv_scale=1.0) -> float: # ... f_scale > 0 and deriv_scale > 0 ... u = unit_roundoff(dtype) if order == 1: # d/dh (D h / 2 + 2 u F / h) = D / 2 - 2 u F / h^2 = 0 return 2.0 * math.sqrt(u * f_scale / deriv_scale) if order == 2: # d/dh (D h^2 / 6 + u F / h) = D h / 3 - u F / h^2 = 0 return (3.0 * u * f_scale / deriv_scale) ** (1.0 / 3.0) raise ValueError(f"order must be 1 (forward) or 2 (central), got {order!r}")The model and the optimum are written as a pair so that one can be checked against the other: fd_error_model(optimal_fd_step(o, d), o, d) must be no larger than the model at any other step. In float64 with unit scales the two steps are and , the numbers derived above. The full solution is in tolerance.py.
Why this design
Section titled “Why this design”Every bound is on top of the caller’s absolute sums, except matmul_error_bound, which is one or two extra float64 matmuls: the same order as the product it checks. cond is an SVD, , which is fine for test-sized matrices.
The design prefers a worst-case bound to a statistical one. The rule is tighter and nearly always right; this bound is looser and always right. For tests on kernels you cannot easily debug (tiled C, quantized), a false failure is expensive, and a bound with a median bound/error ratio under 100 still catches a dropped term. It is elementwise, not normwise: a normwise bound is simpler but lets a single bad element hide behind large ones, while the elementwise checks every output. And it uses an SVD rather than a condition estimator. LAPACK’s xGECON estimates in after an LU factorization, which is faster but approximate and in a different norm; the exact matches the theorem above and reuses the existing svd.
One tradeoff is accepted: the bounds ignore underflow (a subnormal partial sum has an absolute, not relative, error). For the matrices in these books that term is negligible, and adding it would make every formula carry an extra .
What can go wrong
Section titled “What can go wrong”The tests check each claim of the section. The two hand examples pin the definitions (, , the dot bound) and the meaning of a condition number (, amplification 28284). The unit roundoff table covers six formats and the numpy names, with , since every bound scales with it. is checked at its edges: , the exact formula, and void at , which is why bf16 sums of 256 terms have no bound. The dot bound must hold on 1000 float32 dots and must not be loose, with a median bound/error ratio under 100, so the tolerance never false-fails and still catches errors. The sum bound must hold for float16 running sums within , with exact. Bounds are elementwise arrays (array in, float64 array out), because kernel tests pass whole matrices.
The matmul bound must cover any order: BLAS, long sequential sums, and cancellation all stay inside, since the tiled C kernel sums in its own order. The budget must include the perturbation: quantized weights pass with and fail without it. assert_close_bounded must pass a correct dot, fail one with a dropped term, and scale with slack, and it must handle NaN, infinities, zero bounds, and shape mismatches so that overflowed kernels compare sanely. bound_ratio must report the worst element, with and , since the C parity check reports one number per operation. cond must match LAPACK on square, tall, wide, Hilbert, and non-normal matrices, must handle the identity, scale invariance, orthogonal matrices, and singular matrices (giving , never a meaningless ), and must bound the amplification, with the bound reached at the singular directions. relative_condition is checked on , , near 1, and zeros. The finite-difference model and both optimal steps are checked for minimality, and on real differences the central difference of the calculus chapter must be best near , showing that the model predicts real behavior.
The common mistakes:
| Pitfall | Symptom | How the solution avoids it |
|---|---|---|
| using for , or forgetting the implicit bit | every tolerance off by 2 | stores with the implicit bit and returns |
| without the denominator | a bound that stays finite where it is void | gamma returns and raises at |
| the wrong count of roundings, or for | a correct kernel fails on long or cancelling rows | for sums, for dots, and absolute values before the product |
| a budget without the deliberate perturbation | a correct int4 kernel fails its test | matmul_error_bound adds d @ b and uses (a + d) @ b |
| ignoring the slack on the expected side | flaky failures at long | assert_close_bounded multiplies by slack (default 4) |
| treating a numerically singular matrix as finite | reported as a number | cond returns below the rank threshold |
| eigenvalues instead of singular values | non-normal matrices look well conditioned | cond reads svd(a)[1] |
| the absolute condition | a scale-dependent number | relative_condition multiplies by |
| for the central difference | a step 100 times too small, ten times the error | optimal_fd_step returns for order 2 |
Where this leads
Section titled “Where this leads”The main consumer is quantization. In AI Engineering, output_error_bound(w, q, x) in Quantization: int8, int4 groups, fp8, and the KV cache is matmul_error_bound(W, x^T, "f32", dA=abs(W - dequantize(q))): the quantization step (at most scale/2) plus the f32 rounding. The optional Cache-blocked, packed, batch-invariant matmul in C checks its standalone C matmul against fixture values within matmul_error_bound, and states its own differential test with these bounds. Any differential test that compares two orders of summation can use them too. The next section, FP8 and microscaling formats, supplies the values for the 8-bit formats in the precision table.
Production tools take different points on the same spectrum. PyTorch’s torch.testing.assert_close uses per-dtype default tolerances with NaN and device handling: a fixed table, not a bound (torch/testing/_comparison.py). Probabilistic error analysis gives bounds that hold with probability . numpy.linalg.cond and LAPACK’s xGECON estimate in from an LU factorization instead of an SVD (dgecon.f). JAX and PyTorch gradcheck use central differences at a fixed in float64 (torch/autograd/gradcheck.py), close to the optimal step derived here.
Further reading
Section titled “Further reading”- Higham, Accuracy and Stability of Numerical Algorithms (SIAM, 2nd ed.), chapters 2 to 4 and 7.
- Trefethen and Bau, Numerical Linear Algebra, lectures 12 to 15.
- Higham and Mary, “A New Approach to Probabilistic Rounding Error Analysis” (SIAM J. Sci. Comput., 2019).
Key terms
Section titled “Key terms”- Unit roundoff: , the largest relative error of one rounding; half of machine epsilon.
- : , a rigorous bound on the relative error accumulated over roundings, valid for .
- Tolerance budget: a test allowance that sums every deliberate perturbation and the rounding bound, and nothing else.
- Backward error: how far the input must move for the computed output to be the exact answer.
- Condition number: how much the exact answer of a problem moves relative to a change in its input.
- Optimal finite-difference step: the step that balances truncation error against rounding error.
Summary
Section titled “Summary”- One model of rounding, with , chained through operations, gives , and with it a bound on a dot product’s error that holds for every input and every summation order.
- The bound scales with , not with : when terms cancel, the relative error of the result can be huge while the algorithm is perfectly fine.
- The condition number measures the problem, not the algorithm: bounds how much a relative change in moves the solution of , and the bound is reached.
- A tolerance budget adds what you introduce on purpose (quantization moves each weight by up to half a step) to what rounding adds; a test that only allows rounding fails a correct quantized kernel.
- Finite differences trade truncation (falls with ) against rounding (grows as ); the optimal step is forward and central.
Review questions
Section titled “Review questions”-
Why does
sum_error_bounduse whiledot_error_bounduses ?Answer
A sum of exact inputs performs additions, and the first term never passes through a rounding of its own, so each term meets at most roundings. A dot product first rounds each product , one more rounding per term, so the count is .
-
Why is the matmul bound computed from and not from ?
Answer
Each rounding is relative to a partial sum, and partial sums can be large when the result is small. In the exact result is but the partial sums are of size 1, and float32 loses the whole result. would give an allowance near and fail correct arithmetic; gives .
-
In
matmul_error_boundwith a perturbation, why doesdAappear inside the term as well as on its own?Answer
Two errors are being added. The deliberate move changes the exact product by at most . The kernel then multiplies the moved matrix in floating point, and its rounding error is bounded by ; since , the rounding term uses . Leaving
dAout of the second term undercounts the rounding of large moved weights. -
Why does
condreturn instead of when is tiny?Answer
The SVD itself is computed with backward error about , so any singular value below roughly is indistinguishable from 0. Dividing by it produces a number like whose digits mean nothing; states the true conclusion, that the matrix is singular to working precision.
-
Why is the optimal central-difference step and not ?
Answer
The truncation error of the central difference is quadratic in (), while rounding still grows as . Balancing against gives , so . is the forward-difference answer, where truncation is linear; used for the central difference it is about 100 times too small in float64, and rounding dominates.