Taylor's Theorem

lean4-proofcalculusvisualization
f(x)=k=0nf(k)(x0)k!(xx0)k+Rn(x)f(x) = \sum_{k=0}^{n} \frac{f^{(k)}(x_0)}{k!}(x-x_0)^k + R_n(x)

Statement

If ff is nn times differentiable on an open interval containing x0x_0, then for any xx in that interval:

f(x)=k=0nf(k)(x0)k!(xx0)k+Rn(x)f(x) = \sum_{k=0}^{n} \frac{f^{(k)}(x_0)}{k!}(x - x_0)^k + R_n(x)

Lagrange remainder: There exists cc between x0x_0 and xx such that:

Rn(x)=f(n+1)(c)(n+1)!(xx0)n+1R_n(x) = \frac{f^{(n+1)}(c)}{(n+1)!}(x - x_0)^{n+1}

The theorem gives a polynomial approximation to ff near x0x_0 with a rigorous bound on the error.

Visualization

Approximating sin(x)\sin(x) near x0=0x_0 = 0 using Taylor polynomials of increasing degree:

nnTaylor polynomial Tn(x)T_n(x)Tn(0.5)T_n(0.5)error vs sin(0.5)0.4794\sin(0.5) \approx 0.4794
1xx0.50000.0206
3xx36x - \dfrac{x^3}{6}0.47920.0002
5xx36+x5120x - \dfrac{x^3}{6} + \dfrac{x^5}{120}0.47943<105< 10^{-5}
7xx36+x5120x75040x - \dfrac{x^3}{6} + \dfrac{x^5}{120} - \dfrac{x^7}{5040}0.479426<107< 10^{-7}

The Lagrange remainder for TnT_n at x=0.5x = 0.5: Rn(0.5)(0.5)n+1(n+1)!|R_n(0.5)| \le \dfrac{(0.5)^{n+1}}{(n+1)!}, shrinking rapidly as nn grows.

    sin(x)  — exact
    T₁(x)   ……… degree 1
    T₃(x)   - - degree 3
    T₅(x)   --- degree 5

 1 |   .--sin
   |  /  T₅ ≈ sin here
   | /
 0 +-------> x
   |
-1 |

Proof Sketch

  1. Base case (n=0n = 0): Directly apply the Mean Value TheoremMean Value Theoremc(a,b)  :  f(c)=f(b)f(a)ba\exists\, c \in (a,b)\;:\; f'(c) = \frac{f(b)-f(a)}{b-a}There exists a point where the instantaneous rate of change equals the average rate of changeRead more →f(x)f(x0)=f(c)(xx0)f(x) - f(x_0) = f'(c)(x - x_0).
  2. Induction: Assume Tn1(x)T_{n-1}(x) approximates ff with remainder Rn1R_{n-1}.
  3. Apply the Fundamental Theorem of CalculusFundamental Theorem of Calculusabf(x)dx=f(b)f(a)\int_a^b f'(x)\,dx = f(b) - f(a)Integration and differentiation are inverse operationsRead more →: Write Rn1(x)=x0x(xt)n1(n1)!f(n)(t)dtR_{n-1}(x) = \int_{x_0}^{x} \frac{(x-t)^{n-1}}{(n-1)!} f^{(n)}(t)\,dt.
  4. Lagrange form: Apply the MVT to the integral representation of RnR_n using the weight function (xt)n(x-t)^n. A cc exists with the Lagrange form of the remainder.
  5. Conclude: The remainder Rn(x)M(n+1)!xx0n+1|R_n(x)| \le \frac{M}{(n+1)!}|x - x_0|^{n+1} where M=supf(n+1)M = \sup |f^{(n+1)}|.

Connections

  • Mean Value TheoremMean Value Theoremc(a,b)  :  f(c)=f(b)f(a)ba\exists\, c \in (a,b)\;:\; f'(c) = \frac{f(b)-f(a)}{b-a}There exists a point where the instantaneous rate of change equals the average rate of changeRead more → — the n=0n=0 base case and the Lagrange remainder step both use MVT
  • Fundamental Theorem of CalculusFundamental Theorem of Calculusabf(x)dx=f(b)f(a)\int_a^b f'(x)\,dx = f(b) - f(a)Integration and differentiation are inverse operationsRead more → — the integral remainder representation of RnR_n comes from FTC applied nn times
  • Chain RuleChain Ruleddx[f(g(x))]=f(g(x))g(x)\frac{d}{dx}[f(g(x))] = f'(g(x)) \cdot g'(x)Differentiate composite functions by peeling layersRead more → — used when computing f(k)(x0)f^{(k)}(x_0) for composite functions
  • L’Hôpital's Rule — Taylor expansions provide an alternative route to L'Hôpital-type limits
  • Intermediate Value TheoremIntermediate Value Theoremf(a)yf(b)c[a,b]:  f(c)=yf(a) \le y \le f(b) \Rightarrow \exists\, c \in [a,b]:\; f(c) = yA continuous function on a closed interval hits every value between its endpointsRead more → — continuity required for f(n)f^{(n)} invokes IVT-like arguments

Lean4 Proof

import Mathlib.Analysis.Calculus.Taylor

open Set

/-- Taylor's theorem with the Lagrange remainder: there exists `c ∈ (x₀, x)` such that
    the error between `f(x)` and the degree-`n` Taylor polynomial at `x₀` is
    `f^(n+1)(c) · (x - x₀)^(n+1) / (n+1)!`.
    Wraps Mathlib's `taylor_mean_remainder_lagrange`. -/
theorem taylor_lagrange_remainder {f :   } {x x₀ : } {n : }
    (hx : x₀ < x)
    (hf : ContDiffOn  n f (Icc x₀ x))
    (hf' : DifferentiableOn  (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) :
     c  Ioo x₀ x,
      f x - taylorWithinEval f n (Icc x₀ x) x₀ x =
        iteratedDerivWithin (n + 1) f (Icc x₀ x) c * (x - x₀) ^ (n + 1) / (n + 1)! :=
  taylor_mean_remainder_lagrange hx hf hf'