---
title: Taylor's theorem with remainder
heading: How good is a polynomial approximation, guaranteed?
eyebrow: A14 · Lesson 16 · Taylor's theorem with remainder
xp: 40
---

::: hook
Engineers approximate all the time: $\sin\theta \approx \theta$ for small angles, $e^x \approx 1 + x$ for a small exponent, a diode or a transistor by its tangent at the bias point. Taylor's theorem says exactly how wrong each approximation can be. The error of the degree-n Taylor polynomial is one more term of the series, with the derivative evaluated at some unknown point in between, and bounding that derivative bounds the error. It's the mean value theorem's big brother, and it's where every "$O(h^2)$" in A13 comes from.
:::

::: play
- The dashed curve is the Taylor polynomial of $e^x$ about 0 of degree n; the marker is the point $x_0$ where the errors are measured.
- The readouts compare the true error with the Lagrange bound $\frac{e^{\max(x_0, 0)}\lvert x_0\rvert^{n+1}}{(n + 1)!}$. The bound is always above the true error, and close to it.
- Raise n: near 0 the error collapses quickly; far from 0 it takes many more terms, because $\lvert x_0\rvert^{n+1}$ fights the factorial.
:::
:::

```sim plot
view: graph
x: x = -3..3
y: y = -2..20
slider: n = 1..8 step 1 = 3
slider: x0 = -3..3 step 0.1 = 2
plot: exp(x) | label: eˣ
plot: 1 + x + step(n - 1.5)*x^2/2 + step(n - 2.5)*x^3/6 + step(n - 3.5)*x^4/24 + step(n - 4.5)*x^5/120 + step(n - 5.5)*x^6/720 + step(n - 6.5)*x^7/5040 + step(n - 7.5)*x^8/40320 | dashed | label: Taylor polynomial of degree n
marker: x = x0 | label: x₀
readout: true error at x₀ = abs(exp(x0) - (1 + x0 + step(n - 1.5)*x0^2/2 + step(n - 2.5)*x0^3/6 + step(n - 3.5)*x0^4/24 + step(n - 4.5)*x0^5/120 + step(n - 5.5)*x0^6/720 + step(n - 6.5)*x0^7/5040 + step(n - 7.5)*x0^8/40320))
readout: Lagrange bound = exp((x0 + abs(x0))/2)*abs(x0)^(n + 1)/(n + 1)!
```

::: predict
## The approximation $\sin\theta \approx \theta$ is used up to what angle if the error must stay below 1% of $\sin\theta$?

- [ ] 0.01 rad
- [x] About 0.245 rad (14°)
- [ ] About 1 rad
- [ ] 0.1 rad

::: reveal
About 0.245 rad. The next term of the series is $-\theta^3/6$, so the relative error is about $\theta^2/6$, which reaches 0.01 at $\theta = \sqrt{0.06} = 0.245$. Taylor's theorem turns "small" into a number.
:::
:::

::: nameit
## Taylor's theorem

If f has n + 1 derivatives on an interval containing a and x, then

$$f(x) = \sum_{k=0}^{n}\frac{f^{(k)}(a)}{k!}(x - a)^k + R_n(x), \qquad R_n(x) = \frac{f^{(n+1)}(\xi)}{(n + 1)!}(x - a)^{n+1}$$

for some ξ between a and x (the **Lagrange form** of the remainder). So if $\lvert f^{(n+1)}\rvert \le M$ between a and x,

$$\lvert R_n(x)\rvert \le \frac{M\lvert x - a\rvert^{n+1}}{(n + 1)!}$$

With n = 0 this is the mean value theorem.

## Standard bounds

| Approximation | Error bound |
|---|---|
| $e^x \approx \sum_{k\le n}\frac{x^k}{k!}$ | $\frac{e^{\max(x, 0)}\lvert x\rvert^{n+1}}{(n + 1)!}$ |
| $\sin x \approx x$ | $\frac{\lvert x\rvert^3}{6}$ |
| $\sin x \approx x - \frac{x^3}{6}$ | $\frac{\lvert x\rvert^5}{120}$ |
| $\cos x \approx 1 - \frac{x^2}{2}$ | $\frac{x^4}{24}$ |
| linearization $f(a) + f'(a)(x - a)$ | $\frac{M_2(x - a)^2}{2}$, with $M_2 = \max\lvert f''\rvert$ |

## Where it's used

- Truncation errors of difference formulas and quadrature rules (A13).
- Newton's quadratic convergence: the linearization error is $\frac{M_2}{2}e^2$ (lesson 53 proves the bound).
- Small-signal models of nonlinear devices: the neglected quadratic term sets the distortion.
:::

::: example
## How many terms of $\sum\frac{1}{k!}$ give e to within $10^{-6}$?

::: solution
1. **Bound the remainder.** With x = 1 and $e^\xi < 3$, the remainder after the degree-n term is below
   $$\frac{3}{(n + 1)!}$$
2. **Try n = 8.** Too big:
   $$\frac{3}{9!} = 8.3 \times 10^{-6}$$
3. **Try n = 9.** Small enough:
   $$\frac{3}{10!} = 8.3 \times 10^{-7}$$
4. **Count the terms.** So terms through $\frac{1}{9!}$, ten terms in all, suffice.

**Answer:** ten terms, through $\frac{1}{9!}$, give e to within $10^{-6}$.
:::
:::

::: example
## Bound the error of $\sin x \approx x - \frac{x^3}{6}$ at x = 0.5.

::: solution
1. **Bound the next derivative.** The next nonzero term involves the fifth derivative, at most 1 in size.
2. **Bound the error.**
   $$\frac{0.5^5}{120} = 2.60 \times 10^{-4}$$
3. **Compare with the actual error.** The actual error is $2.59 \times 10^{-4}$: the bound is nearly exact, because the remainder is close to the next term of an alternating series.

**Answer:** the error is at most $2.60 \times 10^{-4}$, and it's actually $2.59 \times 10^{-4}$.
:::
:::

::: example
## How many terms of $\ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots$ give $\ln 1.5$ to within $10^{-6}$?

::: solution
1. **Use the alternating-series bound.** At x = 0.5 the series alternates with terms $\frac{0.5^k}{k}$ that decrease, so the error after n terms is less than the next term:
   $$\frac{0.5^{n+1}}{n + 1}$$
2. **Try n = 14.** Not enough:
   $$\frac{0.5^{15}}{15} = 2.0 \times 10^{-6}$$
3. **Try n = 15.** Small enough:
   $$\frac{0.5^{16}}{16} = 9.5 \times 10^{-7}$$
   So 15 terms suffice.
4. **Compare with x = 1.** At x = 1 the same series needs about a million terms for that accuracy, which is why libraries reduce the argument first.

**Answer:** 15 terms give $\ln 1.5$ to within $10^{-6}$.
:::
:::

::: check
given: x = 1 | 2 | 0.5; n = 3 | 5
answer: exp(x)*x^(n + 1)/(n + 1)!
tolerance: 0.1%

## Using $M = e^x$, what's the Lagrange bound on the error of the degree-{n} Taylor polynomial of $e^x$ at x = {x}?

::: right
Right. $\frac{e^x x^{n+1}}{(n + 1)!}$ = {answer}.
:::

::: misses
- [x^(n + 1)/(n + 1)!] That's the next term with $e^\xi$ replaced by 1; for x > 0 the bound needs $e^x$.
- [any] Not yet. $\frac{M\lvert x\rvert^{n+1}}{(n + 1)!}$ with $M = e^x$.
:::
:::

::: check
given: e = 0.0001 | 0.0000001 | 0.000000001
answer: 5 + step(3/720 - e) + step(3/5040 - e) + step(3/40320 - e) + step(3/362880 - e) + step(3/3628800 - e) + step(3/39916800 - e) + step(3/479001600 - e) + step(3/6227020800 - e)
tolerance: 0

## Using the bound $\frac{3}{(n + 1)!}$, what's the smallest degree n that gives e to within {e}?

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

::: misses
- [any] Not yet. Find the first n with $\frac{3}{(n + 1)!} < \varepsilon$.
:::
:::

::: check
given: p = 1 | 0.1 | 5
answer: sqrt(6*p/100)
unit: rad
tolerance: 0.5%

## Up to what angle is $\sin\theta \approx \theta$ good to {p}% (using relative error $\approx\theta^2/6$)?

::: right
Right. $\theta = \sqrt{6p/100}$ = {answer} rad.
:::

::: misses
- [6*p/100] Take the square root: the error grows as $\theta^2$.
- [any] Not yet. Solve $\theta^2/6 = p/100$.
:::
:::

::: check
given: M = 2 | 10 | 0.5; h = 0.1 | 0.01
answer: M*h^2/2
tolerance: 0.1%

## A function has $\lvert f''\rvert \le$ {M}. How far can its tangent line at a be from f at a distance {h} away?

::: right
Right. $\frac{M h^2}{2}$ = {answer}.
:::

::: misses
- [M*h^2] The remainder has a factor $\frac{1}{2!}$.
- [any] Not yet. $\lvert R_1\rvert \le \frac{M_2h^2}{2}$.
:::
:::

::: check
given: x = 0.3 | 0.5 | 1
answer: x^5/120
tolerance: 0.1%

## Bound the error of $\sin x \approx x - \frac{x^3}{6}$ at x = {x}.

::: right
Right. $\frac{x^5}{120}$ = {answer}.
:::

::: misses
- [x^4/24] The $x^4$ term of sin's series is zero; the next nonzero one is $x^5/120$, and the remainder for degree 4 is the bound to use.
- [any] Not yet. The next nonzero term is $\frac{x^5}{5!}$.
:::
:::

::: check
kind: choice

## The remainder in Taylor's theorem uses $f^{(n+1)}(\xi)$ at an unknown ξ. Why is it still useful?

- [ ] ξ can always be computed
- [x] A bound on $\lvert f^{(n+1)}\rvert$ over the interval bounds the error without knowing ξ
- [ ] ξ is always the midpoint
- [ ] The remainder is always zero for smooth functions

::: misses
- [1] It's usually unknown; only its location between a and x is known.
- [3] It depends on f and x.
- [4] Only for polynomials of degree at most n.
:::
:::

::: check
kind: parts
given: x = 0.2 | 0.5 | 1

## Approximate $\cos x$ by Taylor polynomials at 0, with x = {x}.

::: part
answer: x^4/24
tolerance: 0.5%

### What bounds the error of $1 - \frac{x^2}{2}$?

::: misses
- [x^3/6] The $x^3$ term of cos is zero, so the remainder starts at $x^4$.
- [any] The next nonzero term, $\frac{x^4}{24}$.
:::
:::

::: part
answer: x^6/720
tolerance: 0.5%

### And of $1 - \frac{x^2}{2} + \frac{x^4}{24}$?

::: misses
- [any] $\frac{x^6}{720}$.
:::
:::
:::

::: check
kind: derivation
vars: x = -0.5..0.5

## Expand $\sqrt{1 + x}$ about 0.

::: step
answer: 1 + x/2 - x^2/8

### What is its degree-2 Taylor polynomial?
:::

::: step
answer: x^3/16

### What is the next term?
:::

::: right
Right. The binomial series $\sqrt{1 + x} = 1 + \frac x2 - \frac{x^2}{8} + \frac{x^3}{16} - \cdots$.
:::
:::

::: explain
## Why does the error of a Taylor polynomial look like the next term of the series?

::: model
Taylor's theorem says the error after the degree-n polynomial is exactly $\frac{f^{(n+1)}(\xi)}{(n + 1)!}(x - a)^{n+1}$ for some ξ between a and x. That's the formula for the next term, except that the derivative is evaluated at ξ instead of at a. When x is close to a, ξ is close to a too and the derivative barely changes, so the error is very nearly the first neglected term. Far from a, the derivative can vary a lot over the interval, and the bound uses its largest value there, which is why a Taylor polynomial is excellent near its center and can be poor far away.
:::
:::

::: practice

::: check
given: x = 1.5 | 0.2; n = 4 | 6
answer: exp(x)*x^(n + 1)/(n + 1)!
tolerance: 0.1%

## Lagrange bound for $e^x$, degree {n}, at {x}?

::: misses
- [any] $\frac{e^xx^{n+1}}{(n + 1)!}$.
:::
:::

::: check
given: M = 4 | 0.2; h = 0.05 | 0.3
answer: M*h^2/2
tolerance: 0.1%

## Linearization error bound, $\lvert f''\rvert \le$ {M}, distance {h}?

::: misses
- [any] $\frac{Mh^2}{2}$.
:::
:::

::: check
given: p = 0.1 | 0.2 | 0.5 | 1 | 2 | 5
answer: sqrt(6*p/100)
unit: rad
tolerance: 0.5%

## Small-angle limit for {p}% error?

::: misses
- [any] $\sqrt{6p/100}$.
:::
:::
:::
