Taylor Expansion and Local Approximation
Taylor's theorem replaces a smooth function near a point by a polynomial whose derivatives match at that point, with a remainder that quantifies both the accuracy and the limits of the local model.
1. Concept overview
A Taylor polynomial approximates a differentiable function near a point by matching its derivatives there. In one dimension,
where the remainder vanishes faster than as . In multiple dimensions the linear term becomes and the quadratic term becomes .
This is the workhorse of analysis: it turns a nonlinear function into a local polynomial whose error we can bound. Almost every convergence proof in optimization — including the descent lemma behind gradient descent and the quadratic model behind Newton's method — is Taylor's theorem with an explicit remainder.
2. Why this concept exists
Nonlinear functions are hard to reason about globally but simple locally. Taylor expansion buys us three things:
- Approximation with a guarantee: unlike a heuristic fit, the remainder has an explicit form, so we can certify accuracy on a neighborhood.
- Derivative-based algorithms: the first-order model yields the gradient step; the second-order model yields Newton's step; the descent lemma uses a quadratic upper bound to pick safe step sizes.
- Error propagation: if and is uncertain by , Taylor gives — the basis of sensitivity analysis and the delta method in statistics.
Naive alternatives fail: linear interpolation needs two evaluations and gives no derivative information; global polynomial fitting oscillates (Runge's phenomenon); finite differences approximate derivatives but still need a local model to extrapolate. Taylor's theorem is the principled local model, with a rigorous price tag.
3. Historical background
Brook Taylor introduced the series in Methodus Incrementorum Directa et Inversa (1715), presenting it as a finite-difference interpolation result. Colin Maclaurin popularized the special case at in his Treatise of Fluxions (1742). Euler used series extensively in the 1730s–40s, often formally without convergence proofs. The rigorous remainder came later: Lagrange (1797) gave the derivative form ; Cauchy (1821) supplied the mean-value-theorem proof; Peano (1868) formulated the little- remainder; Greenhill and others extended to several variables in the late 19th century. The modern geometric picture — Taylor polynomials as jets on manifolds — belongs to 20th-century differential geometry.
4. Fundamental problem
Given a -times differentiable and a base point , find a polynomial of degree at most that approximates near , and bound uniformly on a ball .
Subtleties: how large can be before the error explodes? Does the infinite series converge to (analyticity), or only asymptotically? In multiple dimensions, which derivatives are needed — all partials of order , or just directional ones? And how do we compute these derivatives efficiently when is large?
5. First-principles explanation
Fact 1 — the derivative is the best linear approximation. Differentiability at means
so the tangent line matches both value and slope; the error is small relative to .
Fact 2 — match derivatives recursively. Seek with for . Differentiating the ansatz gives , hence . The factorial is not a convention — it is forced by repeated differentiation.
Fact 3 — the remainder is a derivative at an intermediate point. Repeated integration by parts (or Cauchy's mean value theorem) shows
All approximation error is governed by the -th derivative times the -th power of the step — the two knobs that determine accuracy.
6. Prerequisite concepts
You need: (1) limits, continuity and little-/big- notation; (2) first and higher derivatives, the chain and product rules; (3) partial derivatives, gradient and Hessian; (4) the mean value theorem and Cauchy's mean value theorem; (5) integration by parts; (6) factorials and the binomial theorem; (7) for the multivariable case, directional derivatives and the identity . See the linked concepts.
7. Complete mathematical formulation
One dimension, Lagrange remainder. If exists on the interval between and ,
Integral remainder. — useful when the derivative is merely integrable.
Peano form. as (requires only derivatives existing at ).
Multivariable. With and :
Compact tensor notation: .
Smoothness bound. If everywhere (i.e. is -smooth),
Series convergence. The infinite series converges on a radius determined by ; within convergence is absolute and uniform on compact subsets.
8. Notation dictionary
| Symbol | Meaning | Type | |---|---|---| | | expansion point (base) | scalar/vector | | | evaluation point and displacement | scalar/vector | | | Taylor polynomial of degree | polynomial | | | remainder after degree | function | | | -th derivative at | scalar | | | gradient vector | vector | | | Hessian matrix | matrix | | | order- derivative tensor | tensor | | | Lipschitz constant of ; curvature bound | scalar | | | asymptotic notation | relation | | | intermediate point from the mean value theorem | scalar | | | radius of convergence | scalar | | | polynomial order | integer | | | number of variables | integer |
9. Step-by-step derivation
Step 1 — ansatz. Write and impose .
Step 2 — solve for coefficients. Since , we get .
Step 3 — one-dimensional remainder. Define . Then , , and differentiating gives . Cauchy's mean value theorem applied to and yields , hence .
Step 4 — multivariable reduction. Set for . Then , , and in general . Apply the 1D theorem at , .
Step 5 — the descent-lemma special case. With and the spectral bound , the Lagrange remainder gives , so
Substituting yields the descent inequality decrease — the rigorous core of gradient descent.
10. Proofs and proof intuition
Theorem (Taylor with Lagrange remainder). If between and , then for some between them. Proof. As in Step 3, define and ; both are continuous on and differentiable on with . Cauchy's MVT gives a with . Since , , so .
Theorem (Peano remainder). If exists, . Proof (induction). The case is continuity. Assuming the result at and applying l'Hôpital to gives the limit because the numerator's derivative is built from , which is by the induction hypothesis.
Proposition (convergence of ). For at , with ; for fixed , , so the series converges to for all .
Proof intuition. Taylor's theorem is the mean value theorem applied repeatedly. The factorial in the denominator is exactly what makes the remainder shrink for smooth functions; the radius of convergence is where the -th derivatives grow too fast for the factorial to tame.
11. Geometric interpretation
The first-order Taylor polynomial is the tangent line (or tangent plane in higher dimensions): it shares the function's value and slope at . The second-order polynomial is the osculating parabola — it also matches curvature, so it hugs the curve to second order. Each additional derivative matches a higher-order geometric feature (jerk, snap, ...).
Close to , a smooth curve is nearly straight — the essence of differentiability. The remainder tells us how fast the curve peels away from its tangent: proportional to curvature times squared distance. For an elongated quadratic bowl, the Hessian's eigenvalues give the curvature in each direction, explaining why a single gradient step overshoots in steep directions and crawls in flat ones.
12. Visual explanation
Use the interactive Taylor Lab: plot together with its approximations of degree 1, 3, 5, 7 on ; the higher-order curves hug the sine over a widening interval. Zoom near 0 and watch all curves coincide. A slider for the expansion point shows that any center works, but accuracy degrades away from it. A second panel shows the remainder bound as a shaded envelope. In 2D, plot a curved surface with its tangent plane and osculating quadratic, and overlay ellipses whose axes are the Hessian eigenvectors to visualize directional curvature.
13. Numerical worked example
Sine at 0.1. Using terms through :
The true value is ; error , consistent with the bound .
Exponential at 0.1. versus ; error .
Square root. ; at this gives versus , error .
Multivariable. near : , Hessian at origin , so . At : versus , error .
Optimization link. For at , the exact increment for is ; the first-order Taylor prediction is (error ), while adding gives — error drops by an order of magnitude.
14. Real-world analogy
A surveyor measures a hill's height and slope at one point. Over a few meters a linear estimate suffices; over a kilometer the curvature matters. Zooming in on any smooth curve with a microscope makes it look straight — that is the first-order Taylor picture. Adding curvature (second derivative) is like fitting the local arc of a circle to the hill; more derivatives are finer adjustments to the fit. The microscope's field of view is the neighborhood where the approximation is valid; walk too far and you need a new expansion point.
15. Algorithm pseudocode
algorithm TaylorPolynomial(f, derivatives, a, k):
# derivatives[j](a) returns the j-th derivative/tensor at a
T <- 0
for j = 0 .. k:
T <- T + derivatives[j](a) / j! * (x - a)^j
return T
algorithm TaylorRemainderBound(f, deriv_k_plus_1, a, x, radius):
M <- sup ||deriv_k_plus_1(z)|| for z in ball(a, radius)
return M * ||x - a||^(k+1) / (k+1)!
algorithm MultivariableQuadratic(f, grad_fn, hess_fn, a, s):
g <- grad_fn(a); H <- hess_fn(a)
return f(a) + dot(g, s) + 0.5 * dot(s, H @ s)
# For L-smooth f: replace 0.5 H by 0.5 L I for a guaranteed upper bound
16. Implementation from scratch
import math
import numpy as np
import sympy as sp
def taylor_1d(f, derivs, a, x, k):
"""Sum f^(j)(a)/j! * (x-a)^j using provided derivative callables."""
return sum(derivs[j](a) * (x-a)**j / math.factorial(j) for j in range(k+1))
def sin_taylor(x, a=0.0, k=7):
# derivatives of sin cycle: sin, cos, -sin, -cos, ...
vals = [math.sin, math.cos, lambda t:-math.sin(t),
lambda t:-math.cos(t)]
return sum(vals[j % 4](a) * (x-a)**j / math.factorial(j)
for j in range(k+1))
def quadratic_model(f, grad, hess, a, s):
a = np.asarray(a, float); s = np.asarray(s, float)
return f(a) + grad(a) @ s + 0.5 * s @ hess(a) @ s
# Symbolic series and exact values
z = sp.symbols("z")
print(sp.series(sp.sin(z), z, 0, 8)) # z - z^3/6 + z^5/120 - z^7/5040
print(sin_taylor(0.1, k=5), math.sin(0.1)) # 0.09983341667, 0.09983341665
f = lambda w: w[0]**2 * w[1] + math.sin(w[1])
g = lambda w: np.array([2*w[0]*w[1], w[0]**2 + math.cos(w[1])])
H = lambda w: np.array([[2*w[1], 2*w[0]], [2*w[0], -math.sin(w[1])]])
print(quadratic_model(f, g, H, [1, 0], [0.1, 0.2])) # 1.22, true f(1.1,0.2)=1.21956
17. Professional library implementation
import sympy as sp
import torch
x = sp.symbols("x")
expr = sp.exp(x) * sp.sin(x)
print(sp.series(expr, x, 0, 6)) # exact symbolic Taylor polynomial
# Higher derivatives with torch.autograd (forward-mode / functorch)
w = torch.tensor([1.0, 0.0], requires_grad=True)
y = torch.exp(w[0]) * torch.sin(w[1])
grad = torch.autograd.grad(y, w, create_graph=True)[0]
hess = torch.stack([torch.autograd.grad(grad[i], w, retain_graph=True)[0]
for i in range(2)])
print(grad, hess)
# JAX: jvp for directional derivatives, hessian via jacfwd(jacrev(f))
import jax, jax.numpy as jnp
f = lambda w: jnp.exp(w[0]) * jnp.sin(w[1])
print(jax.jacfwd(jax.jacrev(f))(jnp.array([1.0, 0.0])))
Use sympy.series for exact symbolic expressions, torch.autograd/functorch for gradients and Hessians of learned models, and jax.jvp for directional (single-direction) derivatives when the full Hessian would be too expensive.
18. Code walkthrough
Scratch. sin_taylor exploits the four-cycle of sine's derivatives; the general taylor_1d accepts any list of derivative callables. The factorial denominator is applied explicitly — forgetting it is the most common implementation bug.
Quadratic model. grad(a) @ s is the directional derivative , and 0.5 * s @ H @ s is the second-order correction. create_graph=True in PyTorch keeps the computational graph so that differentiating the gradient yields the Hessian; without it you get only first derivatives.
Symbolic vs automatic. sp.series performs exact rational arithmetic and is ideal for short series; automatic differentiation scales to millions of parameters but produces numerical derivatives. JAX's jvp computes in one pass without materializing the gradient — the right tool when only one directional derivative is needed.
19. Tensor and memory analysis
In dimensions, the order- derivative tensor has entries: for and the Hessian has entries (4 MB in fp32) — manageable; for it is entries (4 GB) — not. This is why second-order Taylor models are practical and third-order ones usually are not. Storing a single directional derivative needs only , and Jacobian-vector products compute it without materializing the gradient. For a batch of points, the Hessian costs ; matrix-free Hessian-vector products reduce this to .
20. Time complexity
One-dimensional degree- expansion: derivative evaluations plus arithmetic. Multivariable full order : coefficients, hence exponential in — the reason Newton (order 2) is the practical ceiling. Hessian-vector products via automatic differentiation cost each (about 2–4 forward passes), so approximating the quadratic model along a direction is at worst and for a single direction. Symbolic expansion can grow factorially in expression size for composite functions.
21. Space complexity
One-dimensional: . Quadratic model in dimensions: for the dense Hessian, or if only Hessian-vector products are stored (as in Newton–CG or L-BFGS). Full order- tensor: . Batch of : if Hessians are materialized. These numbers explain the dominance of gradient and Hessian approximations in large-scale optimization.
22. Experimental demonstration
Plot for on a log scale: expect roughly , , and machine precision respectively. More generally, plot the error versus step size in log-log coordinates for a fixed ; the slope should be until floating-point roundoff dominates (around for ). Test the radius of convergence with at : the series diverges for even though is perfectly smooth — a dramatic demonstration that smoothness alone does not imply a convergent Taylor series. Finally verify the descent-lemma bound numerically on by checking with .
23. Benchmark results
For at , degree 3 already reaches absolute error; degree 5 hits double-precision roundoff. For at , degree 20 is needed for similar accuracy — the required order grows with , so recenter the expansion near the evaluation point. Numerical differentiation to estimate the needed derivatives costs function evaluations per point but suffers noise; automatic differentiation gives exact derivatives at a small constant-factor cost. Always report the expansion point, order, and remainder bound — an error number without them is meaningless.
24. Limitations
- Local only: accuracy degrades as grows; recenter for distant points.
- Smoothness required: at nonsmooth points (e.g. at 0) no Taylor expansion exists.
- Convergence is not guaranteed: a function can have a divergent Taylor series (e.g. at 0 is flat but nonzero away from 0).
- High-order derivatives are expensive: order in dimensions needs coefficients.
- Catastrophic cancellation: summing alternating series terms of similar magnitude loses digits in floating point.
- Remainder bounds can be loose: using a global bound on may badly overestimate error near .
- Ill-conditioned evaluation for large and high (powers overflow).
25. Failure scenarios
- Outside the radius of convergence: expanding at 0 and evaluating at gives — divergent, though exists.
- Non-smooth point: trying to expand at 0; the derivative does not exist, so no linear approximation (subgradients are needed).
- Flat but non-analytic function: for , has every derivative zero at 0, so its Taylor series is identically zero and never recovers .
- Overflow: for overflows fp64; scale the variable or use Horner's method with rescaling.
- Wrong factorial: omitting produces wildly wrong coefficients — a classic coding bug.
- Over-trusting low order: using a linear model where curvature dominates; the error grows quadratically and can invalidate a step-size argument.
- Noisy derivative estimates: finite differences with too-small amplify roundoff, making higher-order terms inaccurate.
26. Common misconceptions
- "More terms always improve accuracy." Only within the convergence radius and with exact derivatives; outside it, adding terms worsens the approximation.
- "A smooth function always equals its Taylor series." Analyticity is an extra condition; smooth non-analytic functions exist.
- "Taylor expansion is the same as interpolation." Interpolation matches function values at several points; Taylor matches derivatives at one point.
- "The remainder is always small." It is as , but the hidden constant can be huge if is large.
- "The second-order term requires the full Hessian always." Directional second derivatives suffice for many algorithms.
- "Taylor series are only for pure math." They underpin every convergence proof in optimization and numerical solvers.
27. Alternative approaches
- Padé approximants: rational functions often converge far beyond the Taylor radius and handle poles better.
- Chebyshev approximation: near-minimax polynomial on an interval, more uniform than Taylor.
- Splines: piecewise low-order polynomials, stable globally.
- Finite differences: approximate derivatives directly, useful when derivatives are unavailable.
- Automatic differentiation: compute exact derivatives without symbolic or hand derivation.
- Asymptotic expansions: valid as a parameter tends to a limit, sometimes divergent but useful.
- Lagrange interpolation: match values at several points instead of derivatives at one.
- Fourier series: global basis better for periodic functions.
29. Research applications
- Optimization: descent lemma, Newton and quasi-Newton methods, cubic regularization, trust regions.
- Numerical analysis: error analysis of integrators and solvers; Runge–Kutta methods are built on Taylor expansions.
- Statistics: delta method for asymptotic distributions of estimators; Laplace approximations to integrals.
- Physics and engineering: linearization of dynamical systems, small-angle approximations, perturbation theory.
- Machine learning: interpreting loss landscapes, second-order sensitivity, Taylor expansion in influence functions.
- Uncertainty quantification: propagating input noise through nonlinear models.
- Computational mathematics: rigorous interval arithmetic using Taylor models.
30. Important research papers
- Taylor B. (1715), Methodus Incrementorum Directa et Inversa — original series.
- Maclaurin C. (1742), A Treatise of Fluxions — expansion at zero and early rigor.
- Lagrange J.-L. (1797), Théorie des fonctions analytiques — remainder form.
- Cauchy A.-L. (1821), Cours d'Analyse — rigorous mean-value-theorem foundation.
- Peano G. (1868), Sulla integrazione della equazione di Hamilton-Jacobi — Peano remainder.
- Higham N. J. (2002), Accuracy and Stability of Numerical Algorithms, 2nd ed. — modern error analysis.
31. Further reading
- Apostol, Calculus (2nd ed., 1967), chapters 7, 13–14 — rigorous single- and multivariable Taylor theory.
- Rudin, Principles of Mathematical Analysis (3rd ed., 1976), chapter 5 — theorem and remainder.
- Marsden & Tromba, Vector Calculus (5th ed., 2003), chapter 2 — multivariable case.
- Boyer, A History of Mathematics — Taylor, Maclaurin and Lagrange context.
- SymPy documentation:
seriesandnseries; PyTorch autograd tutorial on higher-order derivatives.
32. Practical exercises
- Derive the Taylor polynomial of degree 4 for at 0 and compute ; compare with the true value and the Lagrange bound.
- Implement
sin_taylorfrom memory and verify the error at for . - Prove the integral remainder form by induction and show it implies the Lagrange form.
- For at , compute the gradient and Hessian by hand and verify the quadratic model at .
- Show that has Taylor series with radius 1 and demonstrate divergence at numerically.
- Numerically verify the descent-lemma bound on for with .
33. Debugging challenges
- Taylor coefficients are wrong by factors of 2, 6, 24. You forgot the denominator.
- Series diverges for a function you expect to be smooth. Check the radius of convergence; the function may be non-analytic or you may be outside the disk.
- PyTorch Hessian is all zeros. You omitted
create_graph=Truewhen differentiating the gradient. - Higher-order terms make accuracy worse. Floating-point cancellation or evaluation outside the valid neighborhood; recenter or use Horner's method.
- Remainder bound is absurdly loose. A global is used; tighten it on the actual interval between and .
- Multivariable quadratic model disagrees with the true function. Check that you used the Hessian (not the Jacobian) and included the factor .
34. Advanced exercises
- Give a complete proof of the multivariable Taylor theorem with integral remainder using the fundamental theorem of calculus along the segment .
- Construct a non-analytic function and prove its Taylor series converges to zero everywhere despite the function being nonzero.
- Derive a Padé approximant of order for and compare its accuracy with the degree-4 Taylor polynomial on .
- Implement a high-order Taylor integrator for and derive its local error order.
- Prove the descent lemma from Taylor's theorem with the spectral norm bound , and show the bound is tight for a quadratic.
- Use Taylor expansion to derive the delta method: if , find the asymptotic variance of .
35. Interview questions
- State Taylor's theorem with the Lagrange remainder and prove it via Cauchy's mean value theorem.
- Why is the coefficient ? Derive it by differentiating the ansatz.
- Write the second-order multivariable expansion and explain the role of the Hessian's eigenvectors.
- Give an example of a smooth function whose Taylor series does not converge to it.
- Derive the descent lemma bound from Taylor's theorem.
- A student expands at 0 and evaluates at , getting divergence. Explain precisely why.
- How many coefficients does a full order-3 Taylor polynomial in 50 variables have? What does that imply for algorithms?
36. Research questions
- Can adaptive Taylor models with rigorous remainder bounds make neural-network verification scalable?
- Which approximation scheme (Taylor, Padé, Chebyshev) is optimal for a given function class and domain?
- How can high-order derivative tensors be exploited without storing them explicitly?
- What are the sharpest remainder bounds for functions with structured (e.g. sparse or low-rank) higher derivatives?
- How do Taylor-based error bounds translate into generalization guarantees for nonlinear models?
37. Mastery assessment
To pass: (1) state and prove Taylor's theorem with remainder without notes; (2) compute the multivariable quadratic model and verify it numerically; (3) implement the 1D series and reproduce the sine/exponential numbers; (4) explain radius of convergence, non-analytic smooth functions and the descent-lemma connection; (5) answer the interview questions. Complete the linked assessment; reading alone is not mastery.`
38. Implementation submission
Push a repository with taylor.py (1D series, multivariable quadratic model, remainder bound), experiments.ipynb (sine/exponential/square-root values, log-log error slopes, divergence of , descent-lemma check), a README.md with derivations, and tests asserting error at and the quadratic model for . Submit the repository URL and exact reproduction command.`
39. Completion criteria
All of: every section read; the Lagrange-remainder proof reproduced on paper; scratch implementation passing tests; numerical experiments with recorded errors and plots; one failure case reproduced and explained; a one-page answer to a research question citing at least one paper. Only then mark the concept mastered.``