---
title: Order of convergence and safeguarded root finding
heading: Measuring how fast a method closes in, and making a fast one safe
eyebrow: A13 · Lesson 7 · Order of convergence and safeguarded root finding
xp: 40
---

::: hook
Bisection never fails but crawls. Newton flies but can be thrown anywhere by a bad start. Real solvers combine them: keep a bracket that's guaranteed to contain the root, take the fast step when it lands inside the bracket and actually helps, and fall back to bisection when it doesn't. That's how `scipy.optimize.brentq` and every robust root finder in a simulator work. To compare methods honestly you need one number for speed, the **order of convergence**, and a way to measure it from a run.
:::

::: play
- Each stem is $\log_{10}$ of the error after n steps, starting from the same error $e_0$ (with all constants set to 1).
- Linear convergence (rate ρ) is a straight line falling $\log_{10}(1/\rho)$ per step. The secant method (order 1.618) and Newton (order 2) curve downward ever faster: each step multiplies the number of correct digits by the order.
- Make $e_0$ larger (a worse start): every method takes longer, but the superlinear ones lose only a step or two.
:::
:::

```sim plot
view: graph
x: n = 0..12
y: digits = -16..0
slider: e0 = 0.01..0.9 = 0.3 log
slider: r = 0.1..0.9 step 0.05 = 0.5
plot: n*log(r) + log(e0) | stems | label: linear, rate ρ
plot: 1.618^n*log(e0) | stems | color: ch2 | label: order 1.618 (secant)
plot: 2^n*log(e0) | stems | color: ch3 | label: order 2 (Newton)
readout: Newton steps to 15 digits = ln(15/(-log(e0)))/ln(2)
readout: linear steps to 15 digits = (15 + log(e0))/(-log(r))
```

::: predict
## A method's errors are $10^{-2}$, $10^{-3}$, $10^{-4.5}$, $10^{-6.75}$. What's its order?

- [ ] 1
- [x] 1.5
- [ ] 2
- [ ] 3

::: reveal
1.5: each exponent is 1.5 times the last (2, 3, 4.5, 6.75). The order is the ratio $\frac{\ln(e_{n+1}/e_n)}{\ln(e_n/e_{n-1})}$, here $\frac{1.5}{1} = 1.5$, measured straight from a run.
:::
:::

::: nameit
## Order of convergence

A sequence converges with **order p** if $e_{n+1} \approx Ce_n^p$:

| Method | Order | New evaluations per step |
|---|---|---|
| bisection | 1 (rate ½) | 1 |
| fixed-point iteration | 1 (rate $\lvert g'(x^*)\rvert$) | 1 |
| secant | 1.618 | 1 |
| Newton | 2 | 2 (f and f′) |
| Halley | 3 | 3 (f, f′ and f″) |

To estimate p from three successive errors (or from successive steps, when the root is unknown):

$$p \approx \frac{\ln(e_{n+1}/e_n)}{\ln(e_n/e_{n-1})}$$

The **efficiency index** $p^{1/w}$, for w evaluations per step, compares methods per unit of work: secant 1.618, Newton 1.414, Halley 1.442.

## Safeguarded root finding

Keep a bracket [a, b] with $f(a)$ and $f(b)$ of opposite sign. Each step:

1. Propose a fast step (Newton, secant, or inverse quadratic interpolation through three points).
2. Accept it if it lands inside the bracket and shrinks the problem enough (Brent's test: the step must be less than half the one before last).
3. Otherwise take a bisection step.
4. Update the bracket so it still has a sign change.

The result can't do worse than bisection and is usually as fast as the secant method. **Brent's method** is this scheme with inverse quadratic interpolation; it's the default scalar root finder in most libraries.

## Accelerating a linear sequence

If $x_n$ converges linearly, **Aitken's Δ² formula** $\hat x = x_{n+2} - \frac{(x_{n+2} - x_{n+1})^2}{x_{n+2} - 2x_{n+1} + x_n}$ usually lands much closer, by assuming the error shrinks by the same factor each step.
:::

::: example
## Newton's iterates for $\sqrt2$ have errors $8.6 \times 10^{-2}$, $2.45 \times 10^{-3}$, $2.12 \times 10^{-6}$. Estimate the order.

::: solution
1. **Log of the newer error ratio.**
   $$\ln\frac{2.12 \times 10^{-6}}{2.45 \times 10^{-3}} = -7.05$$
2. **Log of the older error ratio.**
   $$\ln\frac{2.45 \times 10^{-3}}{8.6 \times 10^{-2}} = -3.56$$
3. **Their quotient is the order.**
   $$\frac{-7.05}{-3.56} = 1.98$$
   Quadratic, as theory says.

**Answer:** the order is about 1.98, quadratic.
:::
:::

::: example
## Apply Aitken's formula to $x \leftarrow \cos x$ from 1: 0.540302, 0.857553, 0.654290.

::: solution
1. **The denominator.** With $x_0, x_1, x_2$ the three iterates,
   $$\begin{aligned} &x_2 - 2x_1 + x_0 \\ &= 0.654290 - 1.715106 \\ &\quad + 0.540302 \\ &= -0.520514 \end{aligned}$$
2. **Aitken's formula.** The numerator is $(x_2 - x_1)^2 = (-0.203263)^2$:
   $$\begin{aligned} \hat x &= 0.654290 - \frac{(-0.203263)^2}{-0.520514} \\ &= 0.654290 + \frac{0.041316}{0.520514} \\ &= 0.733665 \end{aligned}$$
3. **Compare with the fixed point.** Against 0.739085, one formula took the error from 0.085 to 0.005.

**Answer:** $\hat x = 0.733665$, an error of 0.005 against the last iterate's 0.085.
:::
:::

::: example
## Newton costs one function and one derivative evaluation per step; the secant method costs one function evaluation. If a derivative costs as much as a function, which converges faster per evaluation?

::: solution
1. **Newton's index.** Order 2 per step, using 2 evaluations, gives
   $$2^{1/2} = 1.414$$
   per evaluation.
2. **The secant method's index.** Its order is
   $$\frac{1 + \sqrt5}{2} = 1.618$$
   with 1 evaluation, an index of 1.618.
3. **Compare.** The secant method wins: per unit of work it multiplies the number of correct digits by 1.618 against Newton's 1.414.
4. **When Newton wins.** If the derivative is nearly free (as in polynomials evaluated with Horner's rule), Newton's index rises toward 2 and it wins instead.

**Answer:** the secant method, with an efficiency index of 1.618 per evaluation against Newton's 1.414.
:::
:::

::: check
given: a = 1 | 2; q = 1.5 | 2 | 3; let e0 = 10^(-a); let e1 = 10^(-a*q); let e2 = 10^(-a*q^2)
answer: ln(e2/e1)/ln(e1/e0)
tolerance: 1%

## A method's successive errors are {e0}, {e1} and {e2}. What's its order?

::: right
Right. {answer}.
:::

::: misses
- [log(e2/e1)] Take the ratio of two logarithms of error ratios.
- [any] Not yet. $p = \frac{\ln(e_{n+1}/e_n)}{\ln(e_n/e_{n-1})}$.
:::
:::

::: check
given: p = 1.618 | 2 | 3; w = 2 | 3
answer: p^(1/w)
tolerance: 0.5%

## A method of order {p} needs {w} function evaluations per step. What's its efficiency index?

::: right
Right. $p^{1/w}$ = {answer}.
:::

::: misses
- [p/w] It's a root, since orders multiply over steps: two steps of order p have order $p^2$.
- [any] Not yet. $p^{1/w}$.
:::
:::

::: check
given: e0 = 0.1 | 0.01; d = 12 | 15
answer: ceil(ln(d/(-log(e0)))/ln(2))
tolerance: 0

## Newton's method starts with error {e0} (take C = 1). How many steps until the error is below $10^{-\given{d}}$?

::: right
Right. The digits double each step: {answer} steps.
:::

::: misses
- [ceil(d/(-log(e0)))] That's linear growth in digits; Newton doubles them.
- [any] Not yet. After n steps the error is $e_0^{2^n}$.
:::
:::

::: check
given: s = 0.3 | 0.5 | 0.8 | 1 | 1.2 | 1.5; let x0 = round(cos(s)*10000)/10000; let x1 = round(cos(x0)*10000)/10000; let x2 = round(cos(x1)*10000)/10000
answer: x2 - (x2 - x1)^2/(x2 - 2*x1 + x0)
tolerance: 0.1%

## Apply Aitken's Δ² formula to {x0}, {x1}, {x2}.

::: right
Right. {answer}.
:::

::: misses
- [any] Not yet. $x_{n+2} - \frac{(x_{n+2} - x_{n+1})^2}{x_{n+2} - 2x_{n+1} + x_n}$.
:::
:::

::: check
given: W = 1 | 4; d = 0.000001 | 0.000000001
answer: ceil(ln(W/d)/ln(2) - 1)
tolerance: 0

## A safeguarded solver falls back to bisection every step on a nasty function. At worst, how many steps does it need to get within {d} of a root bracketed {W} wide?

::: right
Right. No worse than bisection: {answer} steps.
:::

::: misses
- [any] Not yet. Bisection's count: smallest n with $W/2^{n+1} \le \delta$.
:::
:::

::: check
kind: choice

## A safeguarded solver's Newton step lands outside the current bracket. What should it do?

- [ ] Accept it anyway; Newton is fast
- [x] Reject it and bisect, so the bracket keeps the root
- [ ] Restart from the original guess
- [ ] Halve the step and accept it whatever happens

::: misses
- [1] A step outside the bracket can't be closer to the root than the bracket's own points.
- [3] That wastes the progress already made.
- [4] Halving may still leave it outside; bisection is the guaranteed fallback.
:::
:::

::: check
kind: parts
given: e = 0.1 | 0.01; p = 1.618 | 2

## A method of order {p} starts with error {e} (take C = 1).

::: part
answer: ceil(ln(ln(1e-12)/ln(e))/ln(p))
tolerance: 0

### How many steps until the error is below $10^{-12}$?

::: misses
- [any] After n steps the error is $e^{p^n}$; solve $p^n\ln e \le \ln 10^{-12}$.
:::
:::
:::

::: check
kind: derivation
vars: L = -2..2, K = 0.5..2, r = 0.2..0.8

## Aitken's formula is $\hat x = x_2 - \frac{(x_2 - x_1)^2}{x_2 - 2x_1 + x_0}$.

::: step
answer: L + K*r^2

### A sequence is exactly $x_n = L + Kr^n$. What is $x_2$?
:::

::: step
answer: L

### What does Aitken's formula give from $x_0$, $x_1$, $x_2$?
:::

::: right
Right. For an exactly geometric error Aitken recovers the limit; for real sequences it removes the leading geometric part.
:::
:::

::: explain
## Why does a safeguarded method converge as fast as the secant method on good problems but never slower than bisection on bad ones?

::: model
It keeps a bracket in which f changes sign, so the root is always inside it. On each step it tries the fast update and accepts it only if it lands inside the bracket and shrinks things enough; otherwise it bisects. Near a simple root of a smooth function the fast steps always pass the test, so the method inherits their superlinear order. On a badly behaved function the fast steps get rejected, and each rejection costs one bisection step, which still halves the bracket. So the worst case is bisection's guaranteed one bit per step, and the typical case is far better.
:::
:::

::: practice

::: check
given: a = 1 | 3; q = 1.618 | 2.5; let e0 = 10^(-a); let e1 = 10^(-a*q); let e2 = 10^(-a*q^2)
answer: ln(e2/e1)/ln(e1/e0)
tolerance: 1%

## Order from errors {e0}, {e1}, {e2}?

::: misses
- [any] $\frac{\ln(e_2/e_1)}{\ln(e_1/e_0)}$.
:::
:::

::: check
given: p = 2 | 4; w = 2 | 3
answer: p^(1/w)
tolerance: 0.5%

## Efficiency index, order {p}, {w} evaluations?

::: misses
- [any] $p^{1/w}$.
:::
:::

::: check
given: e0 = 0.2 | 0.001; d = 10 | 16
answer: ceil(ln(d/(-log(e0)))/ln(2))
tolerance: 0

## Newton steps from error {e0} to $10^{-\given{d}}$?

::: misses
- [any] Smallest n with $2^n(-\log_{10}e_0) \ge d$.
:::
:::
:::
