38. Taylor's theorem with remainder: how wrong is the truncation?
§8.1 ended with a loose thread: matching every derivative at a point doesn't automatically mean the resulting series equals the function everywhere it converges. This lesson ties that thread off — not by proving full series always work, but by doing something more useful in practice: bounding exactly how wrong a truncated Taylor polynomial is, for any function, at any specific point, using only a finite number of terms.
The Taylor polynomial and the remainder
Truncate a Taylor series after n+1 terms (through the (x-a)^n term) to get the nth-degree Taylor polynomial:
T_n(x)=\sum_{k=0}^n\frac{f^{(k)}(a)}{k!}(x-a)^k
Define the remainder as whatever's left over:
R_n(x)=f(x)-T_n(x)
If R_n(x)\to0 as n\to\infty for a given x, the Taylor series converges to f(x) there — that's precisely the condition §8.1 left unresolved. Taylor's theorem gives a formula for R_n(x) that makes this checkable.
Taylor's theorem (Lagrange form of the remainder)
If f has n+1 continuous derivatives on an interval containing a and x, there exists some c strictly between a and x such that R_n(x)=\frac{f^{(n+1)}(c)}{(n+1)!}(x-a)^{n+1}
This is the Mean Value Theorem, one derivative order up. Recall §3.4: f(b)-f(a)=f'(c)(b-a) for some c between a and b — that's exactly this formula with n=0: R_0(x)=f(x)-f(a)=f'(c)(x-a). Taylor's theorem is the same "some intermediate point makes the leftover term exact" argument, applied to progressively higher derivatives instead of stopping at the first one.
Turning the formula into a usable bound
The formula names an unknown point c — impossible to pin down exactly, but not necessary to. If M is any bound on |f^{(n+1)}| across the whole interval between a and x (found the same way §1.8's Extreme Value Theorem guarantees a max exists, or often from a known property of the function, like |\sin|\le1 always):
|R_n(x)|\le\frac{M}{(n+1)!}|x-a|^{n+1}
This is the practical form of the theorem — an explicit, computable ceiling on the error of a truncated Taylor polynomial, without ever knowing c. It answers a genuinely different question than convergence: even before asking whether the infinite series converges to f(x), this bound tells you how good a specific, finite approximation already is.
Why this bound explains fast convergence
For fixed x near a, |x-a|^{n+1} shrinks (for |x-a|<1) while (n+1)! grows explosively — factorial growth eventually crushes any fixed power, exactly §1.6's growth hierarchy, revisited. This is why Taylor polynomials for e^x, \sin x, and \cos x converge so fast near their center: the (n+1)! in the denominator wins the race against the numerator no matter how large M or |x-a| happen to be, which is also the underlying reason those three series have infinite radius of convergence (§8.0).
Doing it in Python
Bounding the error of a degree-3 Taylor polynomial for \sin(0.5), using M=1 (since every derivative of \sin is \pm\sin or \pm\cos, all bounded by 1):
import sympy as sp
from math import factorial
x = sp.Symbol('x')
a, target = 0, sp.Rational(1, 2)
T3 = x - x**3 / 6 # degree-3 Maclaurin polynomial for sin(x)
approx = float(T3.subs(x, target))
exact = float(sp.sin(target))
actual_error = abs(exact - approx)
M = 1 # bound on |f^(4)(c)| = |sin(c)|, always <= 1
n = 3
bound = M / factorial(n + 1) * abs(float(target) - a)**(n + 1)
print(f"T_3(0.5) = {approx:.8f}")
print(f"sin(0.5) = {exact:.8f}")
print(f"actual error = {actual_error:.8f}")
print(f"theoretical bound = {bound:.8f}")
print(f"bound holds: {actual_error <= bound}")
Watching the error bound shrink as more terms are added — confirming the factorial-beats-power race directly:
from math import factorial
x = 0.5
for n in (1, 3, 5, 7, 9):
bound = 1 / factorial(n + 1) * x**(n + 1)
print(f"n={n}: error bound = {bound:.2e}")
Using the remainder bound to determine how many terms guarantee a target accuracy — solving the bound inequality by searching, rather than computing the true error at all:
from math import factorial
x = 1.0 # approximating e^x at x=1
target_error = 1e-6
M = 3 # any bound on e^c for c in [0,1] works; e < 3
n = 0
while M / factorial(n + 1) * x**(n + 1) > target_error:
n += 1
print(f"need n = {n} (a degree-{n} Taylor polynomial) to guarantee error < {target_error}")
Worked example
Use Taylor's theorem to bound the error of the degree-3 Maclaurin polynomial for \sin x evaluated at x=0.5.
T_3(x)=x-\frac{x^3}6 (the degree-3 truncation — the x^2 coefficient is 0 since \sin is odd, §8.1). The next term needed for the remainder bound is the 4th derivative:
f^{(4)}(x)=\sin x\qquad(\text{the derivative cycle repeats every 4 steps})
Since |\sin c|\le1 for every c, take M=1:
|R_3(0.5)|\le\frac{1}{4!}|0.5-0|^4=\frac1{24}\cdot\frac1{16}=\frac1{384}\approx0.0026
\boxed{|R_3(0.5)|\le\frac1{384}\approx0.0026}
Sanity check. Compute directly: T_3(0.5)=0.5-\frac{0.125}6\approx0.47917, while \sin(0.5)\approx0.47943 — an actual error of about 0.00026, a full order of magnitude inside the bound of 0.0026. That's expected: Taylor's theorem gives a guaranteed ceiling, using the worst-case M=1 across the whole interval, not the exact error — the true error is often considerably smaller than the bound allows, but the bound is what you can compute without already knowing the exact answer you're trying to approximate. ✓
Your turn
1. Bound the error of the degree-2 Maclaurin polynomial for e^x at x=0.2, using M=2 as a bound for e^c on [0,0.2] (since e^{0.2}<2).
2. How many terms of the Maclaurin series for \cos x are needed to approximate \cos(1) with error under 10^{-4}? (Use M=1, since every derivative of \cos is bounded by 1.)
3. True or false: Taylor's theorem guarantees that increasing n always decreases the actual error |R_n(x)|.
Solutions
1. Third derivative of e^x is e^x itself, so f'''(c)=e^c, bounded by M=2:
|R_2(0.2)|\le\frac2{3!}|0.2|^3=\frac26\cdot0.008=\frac{0.016}6\approx0.00267
\boxed{|R_2(0.2)|\lesssim0.00267}
2. Need \dfrac1{(n+1)!}\cdot1^{n+1}<10^{-4}, i.e. (n+1)!>10^4=10{,}000. Check factorials: 7!=5040, 8!=40{,}320 — so n+1=8, meaning \boxed{n=7} (an 8-term, degree-7 polynomial) suffices. (Since \cos x's series only has even powers, this really means terms through x^6 are the last ones needed, with the x^7 coefficient being zero anyway — the bound is conservative but still correctly guarantees the target.)
3. False. The bound \frac{M}{(n+1)!}|x-a|^{n+1} shrinks as n grows whenever M stays bounded — but M itself is a bound on f^{(n+1)}, which can behave very differently at different orders for some functions. Taylor's theorem guarantees the bound can be made small by an appropriate choice of M at each order, and for the well-behaved functions in this lesson (e^x, \sin x, \cos x, all with derivatives uniformly bounded or growing predictably) the actual error does shrink — but the theorem's guarantee is about the existence of some c, not about monotonic improvement in general; some pathological functions (like §8.1's e^{-1/x^2} counterexample) have Taylor polynomials that never converge to f(x) at all, no matter how large n gets.
Check yourself in code
For the degree-3 Maclaurin polynomial of \sin x evaluated at x=0.5, compute the approximation, the exact value, the actual error, and the theoretical error bound from Taylor's theorem (using M=1).
Print exactly this:
T_3(0.5) = 0.47916667
sin(0.5) = 0.47942554
actual error = 0.00025887
theoretical bound = 0.00260417
import sympy as sp
from math import factorial
x = sp.Symbol('x')
target = sp.Rational(1, 2)
T3 = x - x**3 / 6
approx = float(T3.subs(x, target))
exact = float(sp.sin(target))
actual_error = abs(exact - approx)
bound = 1 / factorial(4) * abs(float(target))**4
print("T_3(0.5) = ...")
print("sin(0.5) = ...")
print("actual error = ...")
print("theoretical bound = ...")
import sympy as sp
from math import factorial
x = sp.Symbol('x')
target = sp.Rational(1, 2)
T3 = x - x**3 / 6
approx = float(T3.subs(x, target))
exact = float(sp.sin(target))
actual_error = abs(exact - approx)
bound = 1 / factorial(4) * abs(float(target))**4
print(f"T_3(0.5) = {approx:.8f}")
print(f"sin(0.5) = {exact:.8f}")
print(f"actual error = {actual_error:.8f}")
print(f"theoretical bound = {bound:.8f}")
Taylor's theorem — the Mean Value Theorem promoted one derivative order — turns the leftover error of a truncated Taylor polynomial into a formula, R_n(x)=\frac{f^{(n+1)}(c)}{(n+1)!}(x-a)^{n+1}, and bounding f^{(n+1)} by any convenient M converts that formula into a computable ceiling on the error, without ever needing the exact answer. The (n+1)! in the denominator is what makes Taylor approximations of well-behaved functions converge so fast — factorial growth in the denominator eventually overwhelms any fixed power in the numerator, exactly §1.6's growth hierarchy at work again.
Next: turning this machinery loose on real computation — using Taylor series to compute e, \pi, and the identity connecting them both to trigonometry, Euler's formula.