Taylor expansions
泰勒展开
Build local polynomial approximations, bound what was omitted, and distinguish smooth functions from analytic ones.
taylor-expansionA forecast with an error allowance
To estimate , start at zero: the function value is one, its slope is one, and its second derivative is also one. These give . The actual value is about 1.221402758. The estimate is useful because it is cheap; it becomes trustworthy when we also control the missing 0.001402758.
A Taylor polynomial packages derivatives at one point into a local approximation. Taylor’s theorem supplies a remainder, which tells us how that approximation differs from the function. A finite approximation and an infinite series are different claims. Hunter, Theorem 8.46 and Section 10.7
Keep the remainder attached
Assume f has continuous derivatives through order on a neighborhood containing the segment from a to . A sufficient version of Taylor’s theorem is
Here , , and the usually unknown lies between a and when h is nonzero. Matching derivatives explains the factorial: the kth derivative of at zero is . If the next derivative has absolute value at most M along the segment, then
For the opening estimate, choose because every derivative of exp is exp. The bound is approximately 0.001628537, larger than the actual error. This is a worst-case guarantee, not a prediction that the error equals the bound.
One route to the result starts with the fundamental theorem of calculus and repeatedly integrates by parts. Under the continuous-derivative assumption, the exact integral remainder is
Bounding this integral gives the absolute error estimate, including negative h. It also exposes what information is missing when someone claims “the next term is tiny” without checking the derivative away from the expansion point. Hunter, Theorem 12.48
Estimate exp and report its bound
The complete program forms consecutive terms recursively, so it does not separately recompute every power. Its advertised domain is and degree 0–30. The reported bound concerns the exact Taylor polynomial. Floating-point evaluation introduces a separate error, so the executable checks include a small numerical allowance.
import math
def exp_taylor(x, degree):
if not math.isfinite(x) or abs(x)>1 or type(degree) is not int or not 0<=degree<=30:
raise ValueError("use |x| <= 1 and an integer degree from 0 to 30")
term = 1.
terms = [term]
for k in range(1,degree+1):
term *= x/k
terms.append(term)
value = math.fsum(terms)
remainder_bound = math.exp(abs(x))*abs(x)**(degree+1)/math.factorial(degree+1)
return value,remainder_bound
def flat(x):
if not math.isfinite(x) or abs(x)>1:
raise ValueError("use a finite |x| <= 1")
square = x*x
return 0. if square == 0. else math.exp(-1/square)
value,bound = exp_taylor(.2,2)
assert abs(value-1.22) < 1e-15
assert abs(math.exp(.2)-value) <= bound+1e-15
assert abs(bound-.001628537)<1e-9
for x in [-1.,-.3,0.,.2,1.]:
for degree in range(13):
value,bound = exp_taylor(x,degree)
assert abs(math.exp(x)-value) <= bound+2e-15
assert abs(flat(.5)-math.exp(-4)) < 1e-15
assert flat(0.) == 0.
The recurrence takes arithmetic work and stores terms for fsum; it does not implement the production exp routine. For large negative inputs, summing alternating large terms would invite cancellation, which is one reason for the limited domain. The bound need not decrease forever once rounding dominates an implemented approximation.
Infinitely many derivatives can still miss the function
A real analytic function equals its Taylor series on some neighborhood of each point. A smooth function has derivatives of all orders, but need not have that property. Consider
Away from zero, each derivative is a polynomial in multiplied by the exponential. The exponential tends to zero faster than any inverse power grows, allowing induction to show all derivatives at zero are zero. Its Taylor series at zero is therefore identically zero, while . The series converges, but it converges to the wrong function at every nonzero point. Hunter, Proposition 10.29 and Example 10.31
The numerical flat function may underflow to zero for tiny nonzero inputs; its output cannot prove an exact mathematical zero. For each fixed finite degree, Taylor’s local remainder statement still holds. It does not permit silently taking the degree to infinity at a fixed nonzero h.
For several variables, apply the one-dimensional argument to . The first two derivatives give
This formula holds for a twice continuously differentiable f locally. The vector h carries the direction and step length; it is not a collection of unrelated one-dimensional expansions. MML, Sections 5.7–5.8
Separate three kinds of error
- What is the degree-two polynomial for exp at zero? Answer: , because its first three derivatives at zero are all one.
- On , give one uniform error bound for that polynomial. Answer: , about 0.000184195.
- Does a convergent Taylor series necessarily equal the original smooth function? Answer: no; q provides a counterexample at zero.
- Does the mathematical remainder bound include rounding in the code? Answer: no. Truncation error, floating-point error, and any input measurement error must be distinguished.
Why optimization keeps returning to Taylor
Gradient methods use a local first-order picture; Newton-type methods add curvature. Finite-difference formulas can be derived by subtracting Taylor expansions, revealing their truncation orders. These uses require local remainder control, not a globally convergent infinite series. Continue with the Hessian for the quadratic model and gradient checking for balancing approximation and roundoff.
Make a prediction, then check
If a smooth function’s Taylor series converges, must it equal that function?
Learning objectives
- Build a polynomial from derivatives and bound its remainder.
- Distinguish finite local approximation, series convergence, and equality to the original function.
Prerequisites & connections
Explore related knowledge →References
- An Introduction to Real Analysis
John K. Hunter - Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: specified-source comparison, derivation checks, independent numerical checks, and paragraph-level bilingual comparison; no independent human peer review.
- Used 90-digit Decimal references for 21 inputs and 16 degrees, separately checking exact-polynomial truncation bounds and float evaluation error; recomputed and corrected the last digits of the x=0.2 bound.
- Checked the flat-function induction, nonanalytic point and underflow distinction; computed all three plotted curves and the estimate/error/bound at x=0.8.
- Compared bilingual assumptions, claims, numbers, exercise answers and citations; structural checks additionally compare formulas, code, main anchors and source IDs.
Source locations checked:
- An Introduction to Real Analysis · Theorem 8.46 p.158 / PDF164; Theorem 12.48 p.270 / PDF276; Proposition 10.29 and Example 10.31 pp.201–203 / PDF207–209
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §§5.7–5.8, printed pp.164–167; finite multivariate formula used, smoothness not promoted to analytic equality
Related topics