M01 — Error, tolerance and order of convergence
Every number a solver returns is wrong. The useful questions are how wrong, how fast the error shrinks when you work harder, and when working harder stops helping. This notebook answers them with the smallest possible example: the derivative of at , whose exact value you know.
Book pages: Error, and what a tolerance is and Convergence, and how to measure it
in books/numerical-methods.
The question. You approximate for with a difference quotient and a step . Does a smaller always give a better answer?
By the end you can:
- say what machine epsilon bounds, and why relative error is the measure
- spot a cancellation and remove it by rewriting the formula
- read the order off a convergence table, and say why halving divides the error by
- estimate the order and an improved answer with no exact solution (Richardson)
- explain the round-off floor and find the best step
Assumes: Taylor series to the third term, and logarithms base 2.
How to use it: predict before you reveal, commit before you check, and move the controls until the equation's behaviour stops surprising you.
1. Relative error and machine epsilon
Setting: the problem, its sets and its symbols
Problem. Given a true value and a computed value , measure the error of on a scale that does not depend on the magnitude of ; and, for the rounding map , find a bound such that with for every in the range of .
| Symbol | In | Meaning |
|---|---|---|
| the finite IEEE 754 doubles: 53 significant bits | ||
| the true value (the data) | ||
| the computed value | ||
| round to the nearest double | ||
| the absolute error, in the units of | ||
| the relative error, dimensionless | ||
| the distance from a double to the next larger one | ||
| machine epsilon: | ||
| the relative rounding error of one operation, and its bound (the unknown) | ||
| the slider: the table's is | ||
| the condition number of at , dimensionless | ||
| the function being evaluated; here |
How these symbols connect
A real input is mapped by to a computed double , giving either the absolute error (in the units of ) or the dimensionless relative error . The unknown rounding bound caps across the range of , anchored by and as the slider sweeps . Passing into then links relative input error to relative output error through the dimensionless condition number .
Symbol-by-symbol notes
$\mathbb{F}$ and $\mathrm{fl}$ — finite doubles and rounding
is a finite subset of whose spacing scales with magnitude rather than staying uniform. The map rounds each real value in range to the nearest element of , producing .
$\lvert \hat x - x \rvert$ vs $\lvert \hat x - x \rvert / \lvert x \rvert$ — absolute vs relative error
Absolute error keeps the units and scale of , so a fixed value means very different accuracy at and . Dividing by removes the units and scale, which requires .
$\epsilon$, $\operatorname{gap}(x)$, $\delta$ and $u$ — spacing vs rounding bound
is the distance from a double to the next larger double, and is that spacing at . Do not confuse with : is the signed relative error of one rounding, while (unit round-off) bounds .
$\kappa$ — condition number of $f$ at $x$
belongs to the mathematical map at , not to the algorithm or to floating-point arithmetic. It is dimensionless because it compares relative output change to relative input change, and requires and .
Write the true value as and the computed value as . The absolute error is no verdict on its own: is large next to and tiny next to . The measure that travels is the relative error
A double keeps 53 binary digits. The gap between 1 and the next double is , machine epsilon. Each arithmetic operation returns the exact result rounded to a double, so it is within a relative of the truth. The gap itself scales with the number: move the slider and watch the absolute gap change while the relative gap stays put.
0.1 + 0.2 == 0.3 is False: the two sides differ by
5.55e-17, one gap at 0.3. Neither 0.1 nor 0.2 is a double; each
was rounded on the way in. Compare floats with a relative tolerance, never with ==.
Conditioning. Some problems amplify an input error whoever solves them. The condition number is the factor: for it is , so at an input rounded by gives an answer good to about . That loss belongs to the question, not to the method.
2. Cancellation
Setting: the problem, its sets and its symbols
Problem. Given and , , find a formula for , equal to it in exact arithmetic, whose evaluation in has a relative error of order for every such .
| Symbol | In | Meaning |
|---|---|---|
| the finite doubles | ||
| machine epsilon, | ||
| the argument (the data), dimensionless | ||
| the exact function | ||
| evaluated operation by operation in doubles, for a given formula | ||
| the relative error, against a 50-digit decimal reference for |
How these symbols connect
Each dimensionless input passes into both the exact function and a floating-point evaluation defined by a specific algebraic formula executed in . Two formulas that represent the same exact can yield very different maps once each intermediate operation rounds. Measuring the dimensionless relative error tests whether a formula stays within order across the whole domain.
Symbol-by-symbol notes
$g$ vs $\hat g$ — exact function vs floating-point evaluation
is the mathematical map , whereas depends on the exact sequence of rounded operations in . An algebraic rewrite leaves unchanged while replacing with a different finite-precision map.
$x \in \mathbb{F} \cap [10^{-16}, 10^{-1}]$ — exact small inputs
Taking means the input itself needs no initial rounding, so every digit lost comes from evaluating the formula. The lower end sits just below .
$\lvert \hat g(x) - g(x) \rvert / g(x)$ — relative error against the reference
Since on , no absolute-value bars are needed in the denominator. Evaluating to 50 decimal digits supplies an exact reference for independent of double-precision rounding.
Compute at . The true value is about . But rounds to exactly 1, its square root is 1, and the subtraction returns 0. Each operand was accurate to ; their difference kept none of their digits.
The cure is algebra, not more precision. Multiply by the conjugate:
The right side divides two numbers of size about 1 and , with no subtraction of nearly equal values. The chart compares both against a 50-digit decimal reference, with values below machine epsilon clipped to the floor .
When the rewritten formula breaks
- Assumes: the rewrite removes the subtraction of nearly equal numbers
- When it fails: a rewrite that only reorders the same subtraction loses the same digits
- Check: compare both forms over from to : the stable one stays at relative error near
3. Order of convergence
Setting: the problem, its sets and its symbols
Problem. Given , here , the point , and a difference quotient that approximates , find the order and the constant , independent of , such that as .
| Symbol | In | Meaning |
|---|---|---|
| the function differentiated; here | ||
| the point; here , so exactly | ||
| the step | ||
| the halving index | ||
| the slider: the number of steps tabulated | ||
| the forward difference | ||
| the central difference | ||
| the error of a quotient | ||
| the order (an unknown) | ||
| the leading constant: depends on and , not on (an unknown) |
How these symbols connect
Given a smooth function and a fixed point , each step (for ) feeds into a difference quotient or to approximate . Subtracting the exact derivative produces the error in the units of . Matching to as is repeatedly halved yields the two unknowns: the dimensionless order and the leading constant .
Symbol-by-symbol notes
$f \in C^3(\mathbb{R})$ — smoothness requirement
is the set of functions with continuous first, second and third derivatives on . That smoothness ensures Taylor expansions around carry a well-behaved cubic remainder.
$D\lt em>+(h)$ vs $D\lt /em>c(h)$ — one-sided vs symmetric quotients
samples on one side at and , whereas samples symmetrically at and across a span of . Both return approximations in the units of .
$E(h) = C h^p + O(h^{p+1})$ — error model, $p$ and $C$
collects all higher-order terms that shrink at least as fast as as . The order is dimensionless and sets how fast shrinks with , while depends on and (not ) and carries units of .
$h = 0.2 \cdot 2^{-j}$ — geometric step sequence
Each increment of halves , giving a geometric sequence of step sizes rather than a uniform grid. Comparing errors at and eliminates once is small enough that is negligible.
Write the error after a step as
is the order; depends on the problem but not on . Halving divides the leading term by , so with errors at and
Taylor's theorem gives the two classic orders. The forward difference has . In the central difference the even terms cancel, leaving , so . On log–log axes an error is a straight line of slope .
Reveal result (lock in your prediction above first)
| h | forward | central | forward order | central order |
|---|---|---|---|---|
| 0.2 | 0.2909 | 0.01816 | — | — |
| 0.1 | 0.1406 | 0.004533 | 1.049 | 2.002 |
| 0.05 | 0.0691 | 0.001133 | 1.024 | 2.001 |
| 0.025 | 0.03426 | 0.0002832 | 1.012 | 2 |
| 0.0125 | 0.01706 | 7.079e-05 | 1.006 | 2 |
| 0.00625 | 0.008512 | 1.770e-05 | 1.003 | 2 |
The first forward order is 1.05, not 1.00: at the term is not yet negligible. That is the pre-asymptotic region, visible in one row.
When the observed order breaks
- Assumes: the function is smooth enough for the Taylor expansion behind
- When it fails: at a kink or a discontinuity the expansion does not exist and the observed order drops (a second-order method reads as first order or worse)
- Check: the observed order should settle over at least two refinements
4. Richardson: the order with no exact answer
Setting: the problem, its sets and its symbols
Problem. Given three computed values of a method whose error is , with the limit , the order and the constant all unknown, find estimates of and of .
| Symbol | In | Meaning |
|---|---|---|
| the coarsest of the three steps; the slider sets | ||
| the method's value at step ; here the central difference of at | ||
| the limit as (the unknown answer; here , used only to score the estimate) | ||
| the order (an unknown) | ||
| the leading constant, independent of (an unknown) | ||
| the finite doubles |
How these symbols connect
From one coarsest step , evaluating the method in at the three nested steps , and yields three computed values , all in the units of the target limit . Because all three share the expansion with unknowns , pairwise differences eliminate , their ratio eliminates to estimate the dimensionless order , and combining two runs with that extrapolates .
Symbol-by-symbol notes
$f\lt em>h$ vs $f\lt /em>0$ — computed method output vs exact limit
Here is the numerical method's output at step (not §3's underlying function evaluated at ). The subscript in marks the limit that is unknown in practice.
$h$, $h/2$, $h/4$ — why three nested runs are needed
The leading model contains three unknowns: , and . Two steps leave undetermined; a third halved step supplies a second difference whose ratio with the first cancels both and .
$h \in [10^{-4}, 10^{-0.5}]$ — coarsest step and slider
The slider sets , so the three runs use with the coarsest of the trio. Because lives in , the expansion holds only where truncation error dominates both the remainder and floating-point rounding.
In real work the exact answer is the thing you do not have, so is unknown. But differences of computed values carry the same leading term: . Three runs give
The second formula extrapolates: it subtracts the estimated leading error and gains an order for free. Move : the estimate is good in the asymptotic region and falls apart near round-off.
When Richardson extrapolation breaks
- Assumes: the leading error term is with the same at all three steps
- When it fails: pre-asymptotic or round-off rows give an unstable , and the extrapolated value is then no more accurate
- Check: estimate from two different triples; extrapolate only if they agree
5. The round-off floor
Setting: the problem, its sets and its symbols
Problem. Given at and the difference quotients and evaluated in , where each value of carries an absolute rounding error of about , find how the total error of the computed quotient behaves as decreases over , and the step at which it is smallest.
| Symbol | In | Meaning |
|---|---|---|
| the finite doubles | ||
| machine epsilon, | ||
| here , evaluated at | ||
| the step | ||
| the forward and central differences, computed in doubles | ||
| the total error : truncation and rounding together | ||
| the order and leading constant of the truncation error, from §3 | ||
| the step of least total error (the unknown) |
How these symbols connect
Each step is passed into the finite-precision quotients applied to at . Comparing each computed value with gives the total error (in the units of ), which combines the truncation error set by with the rounding error set by . Tracking across fifteen decades of shows how those two sources interact and identifies the unknown optimal step .
Symbol-by-symbol notes
$D\lt em>+, D\lt /em>c : (0, \infty) \to \mathbb{F}$ — finite-precision quotients
Unlike §3's idealised real-valued quotients, here and land in , so each evaluation of , subtraction and division rounds to a double. Because is evaluated at , rounding errors of size about enter before the division by .
$E(h)$ — total error vs truncation error
In §3, reflected truncation error because stayed relatively large. Over , measures truncation error (governed by and ) and rounding error (governed by ) together.
$h^*$ — step of least total error
is the positive step, in the same units as , that minimises for a given difference quotient. Each of and has its own , set by its order and by .
The difference quotient subtracts two nearly equal values and divides by , so an absolute rounding error of about in becomes about in the result. The total error is roughly
which is smallest near : about 1.5e-08 for the forward difference and 6.1e-06 for the central one (the dashed lines). Below , working harder makes the answer worse.
Reveal result (lock in your prediction above first)
Measured best steps: central h = 5.0e-06 (error 3.6e-12), forward h = 1.0e-08 (error 6.6e-09). The central difference wins twice: a smaller error at every step, and a larger best step.
When shrinking the step breaks
- Assumes: truncation error is the only error
- When it fails: below rounding dominates and the error grows
- Check: plot the error against on log-log axes and find where the V turns
Practice
Hint 1
Use .
Hint 2
With the denominator is , so you add the difference once more.
Check yourself (closed book)
Keep these:
- Measure error relatively; one operation is good to about .
- A subtraction of nearly equal numbers loses digits: rewrite the formula.
- Order means halving divides the error by ; read it as a slope.
- Three runs give the order and an extrapolated answer, no exact value needed.
- Total error : the best step is near , and smaller is worse.
Your connection
Name one number you rely on that comes from a computation with a step or a tolerance (a simulation, a spreadsheet, a solver). How would you check its order?
Answers
Practice A. .
Practice B. .
Practice C. , from .
Mixed practice. run, compute the order, check it settled, extrapolate, stop before round-off.
Where the maths is derived
Optional. These notes give the intuition and application; the sources below give the full derivations and proofs.
§1 Relative error and machine epsilon
- Higham (2002), Accuracy and Stability of Numerical Algorithms: floating-point arithmetic, rounding, conditioning, forward and backward error (ch. 1–2).
§2 Cancellation
- Higham (2002), Accuracy and Stability of Numerical Algorithms: cancellation and how rewriting a formula avoids it (§1.7).
§3 Order of convergence
- LeVeque (2007), Finite Difference Methods for Ordinary and Partial Differential Equations: the Taylor expansions behind forward and central differences, and their orders (ch. 1).
§4 Richardson extrapolation
- LeVeque (2007), Finite Difference Methods for Ordinary and Partial Differential Equations: measuring errors and estimating them from refined grids (appendix A).
Compiled from notebooks/methods/m01_error_and_order.py — run locally with cd notebooks && uv run marimo edit methods/m01_error_and_order.py for live Python scratch cells.
Back to the book: Error, and what a tolerance is · Convergence, and how to measure it