How far off can a Taylor polynomial be? Derive the remainder by integrating by parts, bound it by M|x - a|^(n+1)/(n+1)!, guarantee sin(0.5) and e, find where Taylor series converge, and see why a central difference beats a forward one.
Derive the integral form of the remainder by repeated integration by parts, and from it the bound M|x - a|^(n+1)/(n+1)!.
Use the bound to guarantee an approximation, such as sin(0.5) from x - x^3/6 to within 0.0003, and to count the terms needed for e to five decimals.
Show that the Taylor series of e^x, sin x and cos x equal the function for every x, and use the ratio test to find where the series of 1/(1 - x) and ln(1 + x) converge.
Explain with the bound why the forward difference has an error of order h and the central difference one of order h^2.
In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
The question
The last lesson gave \({\sin 0.5 \approx 0.5 - 0.5^3/6}\), which is 0.4791667. Without the true value at hand, how many of those digits can you trust? A numerical library cannot hope; it needs a guarantee, a number the error can never exceed. The same question decides how a gradient check (M04.2.4) should work: why is the central difference so much more accurate than the forward one?
From the last lesson
1. What is the coefficient of \({(x - a)^k}\) in the Taylor polynomial \({T_n}\)?
Show answer
\({f^{(k)}(a)/k!}\).
2. Why is \({T_2}\) of the running loss, about any centre, the loss itself?
Show answer
The loss is a polynomial of degree 2, and a polynomial of degree at most \(n\) is its own \({T_n}\).
Intuition
Call the error \({R_n(x) = f(x) - T_n(x)}\) the remainder. At the centre it is 0, and so are its first \(n\) derivatives, because \({T_n}\) was built to match them. An error that starts that flat can only grow slowly at first. How slowly is set by the next derivative, the first one that \({T_n}\) does not match.
M04.8.4-F1
The error of \({x - x^3/6}\) as a stand-in for \({\sin x}\) (bottom, purple) stays inside the funnel \({|x|^5/120}\), which is pinched shut at the centre and opens like the fifth power of the distance.
The fifth derivative of \({\sin x}\) is \({\cos x}\), never bigger than 1 in size. That alone traps the error in the funnel \({|x|^5/5!}\), and the same reasoning works for any function and any degree.
Build it up
Step 1. Degree 0. The fundamental theorem (M04.6.3) writes \(f\) through its slope: \({f(x) = f(a) + \int_a^x f'(t)\,dt}\). So \({R_0(x) = \int_a^x f'(t)\,dt}\).
Step 2. One integration by parts. Use M04.7.2 with \({u = f'(t)}\) and \({dv = dt}\), and choose the antiderivative \({v = -(x - t)}\), which is 0 at \({t = x}\):
The bracket is 0 at \({t = x}\), and at \({t = a}\) it is \({-f'(a)(x - a)}\), which is subtracted. So \({f(x) = T_1(x) + R_1(x)}\) with \({R_1(x) = \int_a^x f''(t)\,(x - t)\,dt}\).
Step 3. Again. With \({u = f''(t)}\), \({dv = (x - t)\,dt}\) and \({v = -(x - t)^2/2}\), the same steps move \({f''(a)(x - a)^2/2}\) out of the integral and leave \({R_2(x) = \int_a^x f'''(t)\,(x - t)^2/2!\,dt}\).
Step 4. The pattern. Each round moves the next Taylor term out and raises the power inside, so after \(n\) rounds
NoteResults: Taylor’s remainder and Taylor’s bound
If \(f\) has \({n + 1}\) continuous derivatives on an interval containing \(a\) and \(x\), then \({f(x) = T_n(x) + R_n(x)}\), with \({R_n}\) as in Step 4. If also \({|f^{(n+1)}(t)| \le M}\) for every \(t\) between \(a\) and \(x\), then
The remainder. Steps 1 to 3 are the first cases. In general, integrating \({R_n}\) by parts with \({u = f^{(n+1)}(t)}\) and \({v = -(x - t)^{n+1}/(n + 1)!}\) splits it into \({f^{(n+1)}(a)(x - a)^{n+1}/(n + 1)!}\), exactly the term that \({T_{n+1}}\) adds to \({T_n}\), plus \({R_{n+1}}\). By induction (M01.6.4) the formula holds for every \(n\).
The bound. For \({x > a}\), the size of an integral is at most the integral of the size (the comparison rule of M04.5.3), so
For \({x < a}\) the same steps run with the limits swapped.
Taylor series. If \(f\) has derivatives of every order, its Taylor series about \(a\) is \({\sum_{k=0}^{\infty} f^{(k)}(a)(x - a)^k/k!}\). Its partial sums are \({T_0, T_1, T_2, \dots}\), so it converges to \({f(x)}\) exactly when \({R_n(x) \to 0}\).
\({e^x}\), \({\sin x}\) and \({\cos x}\), for every \(x\). Between 0 and \(x\), every derivative of \({e^x}\) is at most \({e^{|x|}}\), and every derivative of \({\sin x}\) or \({\cos x}\) is at most 1. The bound then has \({|x|^{n+1}/(n + 1)!}\) in it, a term of the series \({\sum |x|^k/k!}\), whose ratios \({|x|/(k + 1)}\) tend to 0. That series converges by the ratio test (M04.8.2), so its terms tend to 0, and so does \({R_n(x)}\).
\({1/(1 - x)}\). The series \({1 + x + x^2 + \cdots}\) has ratio \({|x|}\): it converges for \({|x| < 1}\), to \({1/(1 - x)}\) (M04.8.1), and diverges for \({|x| > 1}\).
\({\ln(1 + x)}\). Its \(k\)-th derivative at 0 is \({(-1)^{k-1}(k - 1)!}\), so the series is \({x - x^2/2 + x^3/3 - \cdots}\), with ratios \({|x|\,k/(k + 1) \to |x|}\): it converges for \({|x| < 1}\) and diverges for \({|x| > 1}\). At \({x = 1}\), the bound with \({|f^{(n+1)}(t)| = n!/(1 + t)^{n+1} \le n!}\) gives \({|R_n(1)| \le 1/(n + 1) \to 0}\), so the series converges to \({\ln 2}\). At \({x = -1}\) it is minus the harmonic series. So it converges for \({-1 < x \le 1}\).
M04.8.4-F2
Where Taylor series converge. The polynomials of \({e^x}\) hug it over a wider stretch at every degree. Those of \({\ln(1 + x)}\) hug it only for \({-1 < x \le 1}\); beyond 1, more terms tear them away.
Why central differences win. For the forward difference of M04.2.4, Taylor’s bound with \({n = 1}\) about \(x\) says that \({|f(x + h) - f(x) - f'(x)h|}\) is at most \({M_2 h^2/2}\), where \({M_2}\) bounds \({|f''|}\) between \(x\) and \({x + h}\). Dividing by \(h\): \({|D_{+}f(x) - f'(x)| \le M_2 h/2}\), an error of order \(h\). For the central difference, with \({M_3}\) bounding \({|f'''|}\) between \({x - h}\) and \({x + h}\), write \({T_2}\) on both sides,
Subtracting, \({f(x)}\) and the \({h^2}\) terms cancel, leaving \({2f'(x)h + R_2(h) - R_2(-h)}\). Each remainder is at most \({M_3 h^3/6}\), so \({|D_0 f(x) - f'(x)| \le M_3 h^2/6}\), of order \({h^2}\). For \({x^3}\), \({M_3 = 6}\) and the bound is \({h^2}\): exactly the error found in M04.2.4.
Go deeper: the series of ln(1 + x) for x between −1 and 0
For \({x < -\tfrac12}\) Taylor’s bound is too weak to show it, but the integral form still works. With \({f^{(n+1)}(t) = (-1)^n n!/(1 + t)^{n+1}}\) and \({x < t < 0}\),
because \({(t - x)/(1 + t)}\) grows with \(t\) and equals \({|x|}\) at \({t = 0}\). Since \({|x| < 1}\), this tends to 0, so the series equals \({\ln(1 + x)}\) on the whole of \({-1 < x \le 1}\).
Go deeper: Euler's formula from three series
M01.9.3 promised that the series of this module would settle what \({e^{i\theta}}\) means. Define it by the series of \({e^x}\) with \({x = i\theta}\). The powers of \(i\) cycle through \({1, i, -1, -i}\), so \({i^{2j} = (-1)^j}\) and \({i^{2j+1} = i\,(-1)^j}\), and the partial sum with \({2m + 2}\) terms splits into
These are partial sums of the series of \({\cos\theta}\) and \({\sin\theta}\), and the one term that a partial sum with an odd number of terms adds shrinks to 0. So \({e^{i\theta} = \cos\theta + i\sin\theta}\).
Worked example
1. Guarantee \({\sin 0.5}\) from \({x - x^3/6}\). This polynomial is \({T_3}\), and also \({T_4}\), since the \({x^4}\) term is 0. Apply the bound to \({T_4}\): the fifth derivative is \({\cos t}\), so \({M = 1}\) and
within 0.0003. The true error is 0.000259. Read as \({T_3}\), the bound would be \({0.5^4/4! \approx
0.0026}\), ten times weaker.
2. Count the terms for \(e\) to five decimals. Take \({e = e^1}\) with centre 0, so \({T_n(1) = 1 + 1 + \tfrac12 + \cdots + \tfrac{1}{n!}}\). Between 0 and 1 every derivative is \({e^t \le e \le 3}\) (M04.1.3 showed that \(e\) is at most 3), so the error is at most \({3/(n + 1)!}\). Five correct decimals need an error below 0.000005:
Since \({9! = 362\,880}\) and \({10! = 3\,628\,800}\), the bound asks for \({n = 9}\): ten terms. Then \({T_9(1) = 2.7182815}\) against \({e = 2.7182818}\); both round to 2.71828.
M04.8.4-F3
The worked example. Left: the guarantee for \({\sin 0.5}\), with the true value inside it. Right: the bound for \(e\) falls below the tolerance at \({n = 9}\); the true error already does at \({n = 8}\).
The bound is a promise, not the error. \({T_8(1)}\) is in fact within 0.0000031, but only \({T_9}\) was guaranteed in advance.
Code
From scratch: the two worked examples, with the remainder integral computed by scipy.integrate.quad as a check.
import mathfrom scipy.integrate import quadx =0.5approx = x - x**3/6# T_4 of sin about 0bound = x**5/ math.factorial(5) # M = 1, since |cos t| <= 1error = math.sin(x) - approxremainder, _ = quad(lambda t: math.cos(t) * (x - t) **4/ math.factorial(4), 0, x)print(f"error {error:.7f} integral remainder {remainder:.7f} bound {bound:.7f}")n =0while3/ math.factorial(n +1) >=0.000005: # e^t <= e <= 3 on [0, 1] n +=1T = math.fsum(1/ math.factorial(k) for k inrange(n +1))T8 = math.fsum(1/ math.factorial(k) for k inrange(9))print("degree needed:", n, " T_n(1) =", round(T, 7), " e =", round(math.e, 7))print("true error of T_8(1):", f"{math.e - T8:.2e}", " 1/9! =", f"{1/ math.factorial(9):.2e}")
error 0.0002589 integral remainder 0.0002589 bound 0.0002604
degree needed: 9 T_n(1) = 2.7182815 e = 2.7182818
true error of T_8(1): 3.06e-06 1/9! = 2.76e-06
Inside and outside the interval of convergence, and the two differences:
import numpy as npdef ln1p_taylor(x, n):"""T_n(x) for ln(1 + x) about 0: x - x^2/2 + x^3/3 - ..."""returnsum((-1) ** (k -1) * x**k / k for k inrange(1, n +1))for x in (0.5, 1.5):print(f"x = {x}: T_4, T_8, T_12, T_16 =", [round(ln1p_taylor(x, n), 3) for n in (4, 8, 12, 16)]," ln(1 + x) =", round(math.log1p(x), 3))for h in (0.1, 0.05): fwd = (math.sin(1+ h) - math.sin(1)) / h - math.cos(1) cen = (math.sin(1+ h) - math.sin(1- h)) / (2* h) - math.cos(1)print(f"h = {h}: forward error {fwd:+.5f} (bound {h /2:.4f}), central {cen:+.6f} (bound {h * h /6:.6f})")
x = 0.5: T_4, T_8, T_12, T_16 = [0.401, 0.405, 0.405, 0.405] ln(1 + x) = 0.405
x = 1.5: T_4, T_8, T_12, T_16 = [0.234, -0.908, -5.352, -23.093] ln(1 + x) = 0.916
h = 0.1: forward error -0.04294 (bound 0.0500), central -0.000900 (bound 0.001667)
h = 0.05: forward error -0.02126 (bound 0.0250), central -0.000225 (bound 0.000417)
The library function numpy.log1p computes \({\ln(1 + x)}\) without first forming \({1 + x}\), which rounds away most of a tiny \(x\). Taylor’s bound shows why \({x - x^2/2}\) is then all one needs: the next derivative is at most about 2, so the error is about \({|x|^3/3}\).
for z in (1e-10, 1e-12):print(f"x = {z}: log(1 + x) = {np.log(1+ z):.12e} log1p(x) = {np.log1p(z):.12e}"f" x - x^2/2 = {z - z * z /2:.12e}")z =-40.0# softplus, ln(1 + e^z), far to the leftprint("softplus(-40):", np.log(1+ np.exp(z)), "with log, ", np.log1p(np.exp(z)), "with log1p")
x = 1e-10: log(1 + x) = 1.000000082690e-10 log1p(x) = 9.999999999500e-11 x - x^2/2 = 9.999999999500e-11
x = 1e-12: log(1 + x) = 1.000088900582e-12 log1p(x) = 9.999999999995e-13 x - x^2/2 = 9.999999999995e-13
softplus(-40): 0.0 with log, 4.248354255291589e-18 with log1p
A softplus layer, \({\ln(1 + e^z)}\), meets the same trouble for very negative \(z\): the plain formula returns 0, while log1p keeps the true value, about \({4.2 \times 10^{-18}}\).
Explore
The module’s interactive, the Taylor builder, is in M04.8.3. Choose \({\ln(1 + x)}\) with centre 0, put the probe at 1.5 and step the degree up: the error swings ever wider. Move the probe to 0.5 and it shrinks. Then drag the centre to 1: the series about 1 converges for \({-1 < x \le 3}\), so 1.5 is now inside.
Pitfalls
M04.8.4-F4
Wrong beside right, for the series of \({\ln(1 + x)}\). At \({x = 1.5}\), outside the interval of convergence, more terms make the estimate swing ever wider. At \({x = 0.5}\), inside, it settles.
“More terms always give a better estimate.”
Only where the series converges. At \({x = 1.5}\) the terms \({1.5^k/k}\) of the series of \({\ln(1 + x)}\) grow, so the partial sums cannot settle; the ratio test predicted this for every \({|x| > 1}\).
“The function is smooth at 1.5, so its series about 0 converges there.”
A power series converges for \({|x - a| < R}\) and diverges for \({|x - a| > R}\), for some radius \(R\) (which may be 0 or infinite). The series of \({\ln(1 + x)}\) diverges at \({x = -1}\), where the function blows up, so \({R \le 1}\), and the series diverges at 1.5 too, however smooth the function is there.
“M is the size of the next derivative at the centre.”
It must bound the derivative over the whole stretch between \(a\) and \(x\). For \(e\) with \({n = 8}\), the value at the centre, \({e^0 = 1}\), would give \({1/9! \approx 2.8 \times 10^{-6}}\), which is below the true error, \({3.1 \times 10^{-6}}\): not a bound at all. On \({[0, 1]}\), \({e^t}\) reaches \(e\).
Check yourself
Recall
1. Write the integral form of the remainder \({R_n(x)}\).
where \(M\) bounds \({|f^{(n+1)}|}\) at every point between \(a\) and \(x\).
3. When does a Taylor series converge to the function?
Show answer
Exactly when the remainder \({R_n(x)}\) tends to 0 as \(n\) grows.
4. Where do the Taylor series about 0 of \({e^x}\), \({1/(1 - x)}\) and \({\ln(1 + x)}\) converge?
Show answer
For every \(x\); for \({-1 < x < 1}\); and for \({-1 < x \le 1}\).
5. Why is the central difference more accurate than the forward one?
Show answer
Its \({h^2}\) terms cancel between \({f(x + h)}\) and \({f(x - h)}\), so its error is at most \({M_3 h^2/6}\), of order \({h^2}\), against \({M_2 h/2}\), of order \(h\).
Exercises
1.★ Bound the error of \({1 - x^2/2}\) as an estimate of \({\cos 0.2}\).
Show solution
\({1 - x^2/2}\) is \({T_2}\) and also \({T_3}\) of \({\cos x}\), since the \({x^3}\) term is 0. Use \({T_3}\): the fourth derivative is \({\cos x}\), so \({M = 1}\) and the error is at most \({0.2^4/4! = 0.0016/24 \approx 0.000067}\). Indeed \({1 - 0.02 = 0.98}\) and \({\cos 0.2 = 0.980067}\).
2.★★ How many terms of the series \({\sum 0.5^k/k!}\) guarantee \({e^{0.5}}\) within \({10^{-6}}\)?
Show solution
With centre 0 and \({x = 0.5}\), every derivative between 0 and 0.5 is at most \({e^{0.5} < 2}\), so the error of \({T_n(0.5)}\) is at most \({2 \times 0.5^{n+1}/(n + 1)!}\). For \({n = 6}\) this is \({2 \times 0.0078125/5040}\), about \({3.1 \times 10^{-6}}\): too big. For \({n = 7}\) it is \({2 \times 0.00390625/40320}\), about \({1.9 \times 10^{-7}}\). So \({n = 7}\): eight terms.
3.★★★ Show that the series of \({\ln(1 + x)}\) converges to \({\ln 2}\) at \({x = 1}\), and that the error after \(n\) terms is at most \({1/(n + 1)}\). How many terms guarantee \({\ln 2}\) to within 0.001, and what does that say about using this series in practice?
Show solution
For \({t \ge 0}\) the derivative \({f^{(n+1)}(t)}\) has size \({n!/(1 + t)^{n+1}}\), which is at most \({n!}\). So Taylor’s bound on \({[0, 1]}\) with \({M = n!}\) gives
which tends to 0. For 0.001 the bound needs \({n + 1 > 1000}\), so \({n = 1000}\) terms. That is slow: at \({x = 1}\), on the edge of the interval, the series barely converges. It is far better to use the series well inside its interval, for instance \({\ln 2 = -\ln(1 - \tfrac12)}\) from the series at \({x = -\tfrac12}\), whose error shrinks like \({0.5^n}\).
Summary card
The error of \({T_n}\) is bounded by the next derivative: \({M|x - a|^{n+1}/(n + 1)!}\).
M04.8.4-F1
The error lives in a funnel.
Remainder.\({R_n(x)}\) is the integral of \({f^{(n+1)}(t)\,(x - t)^n/n!}\) from \(a\) to \(x\).
Bound. If \({|f^{(n+1)}| \le M}\) between \(a\) and \(x\), then \({|R_n(x)|}\) is at most \({M|x - a|^{n+1}/(n + 1)!}\).
Sources. Each was opened and checked against this lesson on 12 November 2026.
Keith Conrad, The remainder in Taylor series (University of Connecticut notes). Theorem 1.2 gives the integral form of the remainder, which Section 3 proves from the fundamental theorem by repeated integration by parts with \({v = t - b}\), and from which it derives Taylor’s inequality; Section 4 shows that \({e^x}\), \({\sin x}\) and \({\cos x}\) equal their Taylor series at every \(x\).
Gilbert Strang and Edwin Herman, Calculus Volume 2 (OpenStax). Section 6.3: Taylor’s theorem with remainder and the bound with \(M\) (Theorem 6.7), convergence exactly when the remainder tends to 0 (Theorem 6.8), and the series of \({e^x}\) and \({\sin x}\) for all \(x\) (Example 6.16). Section 6.4, Table 6.1: the intervals of convergence \({-1 < x < 1}\) for \({1/(1 - x)}\) and \({-1 < x \le 1}\) for \({\ln(1 + x)}\). Section 6.1: a power series converges for \({|x - a| < R}\) and diverges for \({|x - a| > R}\) (Theorem 6.1).
Matthew Boelkins, Active Calculus, Section 8.6: the Lagrange error bound for \({T_n}\), the same bound reached by integrating the bound on the next derivative repeatedly.
NumPy developers, numpy.log1p (NumPy 2.5 reference): \({\log(1 + x)}\), accurate even for \(x\) so small that \({1 + x}\) equals 1 in floating point.
Next. This completes the module. M04.9, differential equations, turns slopes into equations, and its Euler’s method is the linear approximation \({T_1}\) used again and again; M05.5 takes Taylor polynomials to functions of several inputs.