---
title: "Project: proving a numerical method converges"
heading: Newton's method's error bound, derived from Taylor's theorem and checked against real iterates
eyebrow: "A14 · Lesson 53 · Project: proving a numerical method converges"
xp: 80
---

::: hook
A13 observed that Newton's method doubles its correct digits near a root. This project proves it, with an explicit constant, and then measures how good the proof is. The proof uses only the mean value theorem and Taylor's theorem with remainder: if the slope stays away from zero and the curvature is bounded near the root, each error is at most a fixed multiple of the previous error squared. From that one inequality follow a guaranteed region of convergence, an a priori bound on every iterate, and the number of steps that certainly suffices. You'll write each piece, then compare the guarantees with what Newton's method actually does.
:::

::: predict
## For $f(x) = x^3 - 2x - 5$ on [2, 3], $\lvert f'\rvert \ge 10$ and $\lvert f''\rvert \le 18$. Starting from x = 3, the bound guarantees an error below $10^{-6}$ after how many steps, and how many does Newton actually need?

- [ ] Guarantee 2, actual 2
- [x] Guarantee 7, actual 4
- [ ] Guarantee 20, actual 4
- [ ] Guarantee 4, actual 7

::: reveal
The bound $\lvert e_{n+1}\rvert \le 0.9e_n^2$ guarantees $10^{-6}$ after 7 steps (after 6 it still allows $2.3 \times 10^{-6}$); the actual errors (0.27, 0.033, 5.8 × 10⁻⁴, 1.9 × 10⁻⁷) get there in 4. A proof works with the worst slope and curvature over the whole interval, so it's pessimistic, but it's a guarantee, which observation never is.
:::
:::

::: nameit
## The theorem

Let f be twice continuously differentiable on an interval I containing a root r, with $\lvert f'(x)\rvert \ge m > 0$ and $\lvert f''(x)\rvert \le M$ on I. Let $C = \frac{M}{2m}$. If the Newton iterate $x_n$ is in I, then

$$\lvert x_{n+1} - r\rvert \le C\lvert x_n - r\rvert^2$$

## The proof

By Taylor's theorem at $x_n$, for some ξ between $x_n$ and r:

$$0 = f(r) = f(x_n) + f'(x_n)(r - x_n) + \frac{f''(\xi)}{2}(r - x_n)^2$$

Divide by $f'(x_n)$ and rearrange, using $x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$:

$$x_{n+1} - r = \frac{f''(\xi)}{2f'(x_n)}(x_n - r)^2$$

and bound the fraction by $\frac{M}{2m}$.

## Consequences

- **Region of convergence:** if $C\lvert e_0\rvert < 1$ and the iterates stay in I (true, for instance, when I is symmetric about r and wide enough), the errors shrink every step.
- **A priori bound:** writing $q = C\lvert e_0\rvert$, induction gives

$$\lvert e_n\rvert \le \frac{q^{2^n}}{C}$$

- **Steps that suffice** for a tolerance ε: the smallest n with $\frac{q^{2^n}}{C} < \varepsilon$, which is about $\log_2\frac{\ln(C\varepsilon)}{\ln q}$: a doubly logarithmic count.
:::

::: example
## Apply the theorem to $f(x) = x^2 - 2$ on [1, 2].

::: solution
1. **The constant C.** $f' = 2x \ge 2$ and $f'' = 2$, so
   $$\begin{aligned} C &= \frac{2}{2 \cdot 2} \\ &= \frac12 \end{aligned}$$
2. **The start.** From $x_0 = 2$, $e_0 = 0.586$ and $q = 0.293$.
3. **The bound.**
   $$\lvert e_n\rvert \le 2(0.293)^{2^n}$$
   Against the actual errors:

| n | Bound | Actual error |
|---|---|---|
| 1 | 0.17 | 0.086 |
| 2 | 0.015 | 0.0025 |
| 3 | $1.1 \times 10^{-4}$ | $2.1 \times 10^{-6}$ |
| 4 | $5.9 \times 10^{-9}$ | $1.6 \times 10^{-12}$ |

4. **Check.** The actual errors are inside the bound at every step.

**Answer:** with $C = \frac12$ the theorem bounds the errors by 0.17, 0.015, $1.1 \times 10^{-4}$ and $5.9 \times 10^{-9}$, and the actual errors stay inside at every step.
:::
:::

::: example
## Why is the hypothesis $\lvert f'\rvert \ge m > 0$ essential?

::: solution
1. **A root where f' = 0.** For $f(x) = x^2$, whose root at 0 has $f'(0) = 0$, Newton's iteration is
   $$x_{n+1} = \frac{x_n}{2}$$
   which converges only linearly.
2. **The constant blows up.** $C = \frac{M}{2m}$ is infinite there, and the theorem rightly promises nothing.
3. **In general.** Multiple roots break quadratic convergence (A13, lesson 6).

**Answer:** without it, C can be infinite: at a root where f' = 0, like the root 0 of $x^2$, Newton's method converges only linearly.
:::
:::

::: check
kind: order

## Put the steps of the proof of $\lvert e_{n+1}\rvert \le C e_n^2$ in order.

1. Expand f about $x_n$ by Taylor's theorem: $0 = f(r) = f(x_n) + f'(x_n)(r - x_n) + \frac{f''(\xi)}{2}(r - x_n)^2$.
2. Divide by $f'(x_n)$, which is nonzero because $\lvert f'\rvert \ge m$.
3. Substitute the Newton step $x_{n+1} = x_n - f(x_n)/f'(x_n)$ to get $x_{n+1} - r = \frac{f''(\xi)}{2f'(x_n)}(x_n - r)^2$.
4. Bound $\lvert f''(\xi)\rvert \le M$ and $\lvert f'(x_n)\rvert \ge m$.
5. Conclude $\lvert x_{n+1} - r\rvert \le \frac{M}{2m}\lvert x_n - r\rvert^2$.

::: right
Right. One Taylor expansion, one division, one substitution, two bounds.
:::
:::

::: check
kind: python

## Step 1. Write `newton_errors(f, df, x0, r, n)` returning the list of errors $\lvert x_k - r\rvert$ for k = 0 to n, and `check_bound(errors, C)` returning True if $e_{k+1} \le Ce_k^2$ for every step (allow $10^{-15}$ of rounding slack).

```python starter
import math

def newton_errors(f, df, x0, r, n):
    return []

def check_bound(errors, C):
    return False

e = newton_errors(lambda x: x*x - 2, lambda x: 2*x, 2.0, math.sqrt(2), 4)
print(e, check_bound(e, 0.5))
```

```python solution
import math

def newton_errors(f, df, x0, r, n):
    x = x0
    errs = [abs(x - r)]
    for _ in range(n):
        x = x - f(x) / df(x)
        errs.append(abs(x - r))
    return errs

def check_bound(errors, C):
    return all(b <= C * a * a + 1e-15 for a, b in zip(errors, errors[1:]))

e = newton_errors(lambda x: x*x - 2, lambda x: 2*x, 2.0, math.sqrt(2), 4)
print(e, check_bound(e, 0.5))
```

```python tests
import math
e = newton_errors(lambda x: x*x - 2, lambda x: 2*x, 2.0, math.sqrt(2), 4)
assert len(e) == 5, "Return n + 1 errors, starting with the initial one."
assert abs(e[1] - 0.0857864376) < 1e-9 and abs(e[3] - 2.1239e-6) < 1e-9, f"Errors for √2 from 2 should be 0.586, 0.0858, 0.00245, 2.12e-6, ...; got {e}."
assert check_bound(e, 0.5), "The theorem says every step obeys e_(k+1) ≤ 0.5 e_k² here."
assert not check_bound([1.0, 0.9], 0.5), "check_bound should catch a step that breaks the bound."
r = 2.0945514815423265
e2 = newton_errors(lambda x: x**3 - 2*x - 5, lambda x: 3*x*x - 2, 3.0, r, 5)
assert check_bound(e2, 0.9), "For x³ − 2x − 5 on [2, 3], C = 18/20 = 0.9 must bound every step."
```

::: right
Right. Every step obeys the proved inequality, for both functions.
:::
:::

::: check
kind: python

## Step 2. Write `bound_after(C, e0, n)`, the a priori bound $\frac{(Ce_0)^{2^n}}{C}$, and `steps_needed(C, e0, eps)`, the smallest n whose bound is below eps (assume $Ce_0 < 1$).

```python starter
def bound_after(C, e0, n):
    return 0.0

def steps_needed(C, e0, eps):
    return 0

print(bound_after(0.9, 0.9054, 4), steps_needed(0.9, 0.9054, 1e-6))
```

```python solution
def bound_after(C, e0, n):
    return (C * e0) ** (2 ** n) / C

def steps_needed(C, e0, eps):
    n = 0
    while bound_after(C, e0, n) >= eps:
        n += 1
    return n

print(bound_after(0.9, 0.9054, 4), steps_needed(0.9, 0.9054, 1e-6))
```

```python tests
import math
assert abs(bound_after(0.5, 2 - math.sqrt(2), 3) - (0.5 * (2 - math.sqrt(2))) ** 8 / 0.5) < 1e-15, "bound_after(C, e0, n) is (C e0)^(2^n) / C."
r = 2.0945514815423265
e0 = 3 - r
n = steps_needed(0.9, e0, 1e-6)
assert n == 7, f"With C = 0.9 and e0 = {e0:.4f}, the bound first drops below 1e-6 at n = 7; got {n}."
assert steps_needed(0.5, 2 - math.sqrt(2), 1e-12) == 5, "For √2 from 2, five steps guarantee 1e-12."
x = 3.0
for _ in range(n):
    x = x - (x**3 - 2*x - 5) / (3*x*x - 2)
assert abs(x - r) < 1e-6, "After the guaranteed number of steps, Newton's error must be below the tolerance."
```

::: right
Right. The guarantee says 7 steps; the iterates are already below $10^{-6}$ after 4. The proof is pessimistic but never wrong.
:::
:::

::: check
given: M = 2 | 6 | 18; m = 2 | 10
answer: M/(2*m)
tolerance: 0.1%

## On an interval where $\lvert f''\rvert \le$ {M} and $\lvert f'\rvert \ge$ {m}, what's Newton's constant C?

::: right
Right. $C = \frac{M}{2m}$ = {answer}.
:::

::: misses
- [M/m] Taylor's remainder has a factor ½.
- [any] Not yet. $C = \frac{M}{2m}$.
:::
:::

::: check
given: C = 0.5 | 0.9; e = 0.2 | 0.5; n = 2 | 4
answer: (C*e)^(2^n)/C
tolerance: 0.5%

## With C = {C} and $e_0$ = {e}, what's the a priori bound on $e_{\given{n}}$?

::: right
Right. $\frac{(Ce_0)^{2^n}}{C}$ = {answer}.
:::

::: misses
- [(C*e)^(2^n)] Divide by C.
- [any] Not yet. Iterate $e_{k+1} \le Ce_k^2$: $Ce_{k+1} \le (Ce_k)^2$.
:::
:::

::: explain
## Why does a bound of the form $e_{n+1} \le Ce_n^2$ make the number of correct digits roughly double each step?

::: model
Multiply the inequality by C: $Ce_{n+1} \le (Ce_n)^2$. So the quantity $q_n = Ce_n$ is at most the square of the previous one. If $q_0 = 10^{-1}$, then $q_1 \le 10^{-2}$, $q_2 \le 10^{-4}$, $q_3 \le 10^{-8}$: the exponent doubles each step, which is what "doubling the digits" means. The condition $q_0 = Ce_0 < 1$ is what starts the squaring off in the shrinking direction; if the start is too far away, $Ce_0 \ge 1$, the inequality allows the errors to grow, and Newton's method can indeed wander.
:::
:::

::: practice

::: check
given: M = 4 | 12; m = 1 | 8
answer: M/(2*m)
tolerance: 0.1%

## Newton's constant with $\lvert f''\rvert \le$ {M}, $\lvert f'\rvert \ge$ {m}?

::: misses
- [any] $\frac{M}{2m}$.
:::
:::

::: check
given: C = 0.3 | 2; e = 0.1 | 0.4; n = 3 | 5
answer: (C*e)^(2^n)/C
tolerance: 0.5%

## A priori bound on $e_{\given{n}}$, C = {C}, $e_0$ = {e}?

::: misses
- [any] $\frac{(Ce_0)^{2^n}}{C}$.
:::
:::

::: check
given: x = 2 | 2.1 | 2.2 | 2.5 | 2.75 | 3
answer: (3*x^2 - 2)
tolerance: 0.1%

## $\lvert f'\rvert$ at x = {x} for $f = x^3 - 2x - 5$, the value that bounds the slope from below on [{x}, 3] when x ≥ 2?

::: misses
- [any] $3x^2 - 2$.
:::
:::
:::
