Calculus · Differential calculus

Taylor's Formula: Replacing a Function by a Polynomial, with a Guarantee

The tangent line is the best straight-line approximation of a function near a point. Taylor's formula goes further: it gives the best approximating polynomial of any degree, and, crucially, an exact expression for the error. With it you can compute \(\sin 0.5\) by hand to four decimals and know they are correct, evaluate tricky limits, and prove inequalities. This post explains the formula, where it comes from, and how to use it.

1. The idea: matching derivatives

Near a point \(a\), the tangent line \( f(a) + f'(a)(x - a) \) has the same value and the same slope as \(f\) (post on the differential). But a line can't bend, so it soon drifts away from the curve. A parabola can bend: if we also match the second derivative, the curvature, the approximation improves. Matching the third derivative improves it further, and so on.

Which polynomial of degree \(n\) has the same value and the same first \(n\) derivatives at \(a\) as \(f\)? Write it in powers of \((x - a)\):

\[ T_n(x) = c_0 + c_1(x - a) + c_2(x - a)^2 + \cdots + c_n(x - a)^n. \]

Differentiating \(k\) times and putting \(x = a\) kills every term except one: \( T_n^{(k)}(a) = k!\,c_k \). So the condition \( T_n^{(k)}(a) = f^{(k)}(a) \) gives

\[ c_k = \frac{f^{(k)}(a)}{k!}. \]
Taylor polynomial \[ T_n(x) = f(a) + \frac{x - a}{1!}f'(a) + \frac{(x - a)^2}{2!}f''(a) + \cdots + \frac{(x - a)^n}{n!}f^{(n)}(a) = \sum_{k=0}^n\frac{f^{(k)}(a)}{k!}(x - a)^k. \]

For \(n = 1\) it is the tangent line; for \(n = 2\), the parabola that "hugs" the curve best at \(a\).

x y T₂ eˣ T₃ T₁ T₂
Figure 1. \(y = e^x\) (black) and its Taylor polynomials at \(a = 0\): \(T_1 = 1 + x\), \(T_2 = 1 + x + \frac{x^2}{2}\), \(T_3 = 1 + x + \frac{x^2}{2} + \frac{x^3}{6}\). Each higher degree follows the curve over a wider range, but all of them eventually drift away. Taylor's formula measures exactly how far.

2. Taylor's formula

The polynomial is only an approximation. Taylor's formula says what the exact error is.

Taylor's formula If the function \(y = f(x)\) has continuous derivatives up to order \(n\) for \(x \in [a, b]\), and a finite \((n + 1)\)-th derivative for \(x \in (a, b)\), then for \(x \in [a, b]\): \[ f(x) = f(a) + \frac{x - a}{1!}f'(a) + \frac{(x - a)^2}{2!}f''(a) + \cdots + \frac{(x - a)^n}{n!}f^{(n)}(a) + \frac{(x - a)^{n+1}}{(n + 1)!}f^{(n+1)}(\xi), \] where \( \xi = a + \theta(x - a) \), \( 0 < \theta < 1 \).

The last term is the remainder:

Two forms of the remainder Lagrange's form: \[ R_n(x) = \frac{(x - a)^{n+1}}{(n + 1)!}f^{(n+1)}\big[a + \theta(x - a)\big], \qquad 0 < \theta < 1. \] Cauchy's form: \[ R_n(x) = \frac{(1 - \theta_1)^n(x - a)^{n+1}}{n!}f^{(n+1)}\big[a + \theta_1(x - a)\big], \qquad 0 < \theta_1 < 1. \]

How to read Lagrange's form: the remainder looks exactly like the next term of the polynomial, except that the derivative is evaluated not at \(a\), but at some unknown point \(\xi\) between \(a\) and \(x\). We don't know \(\xi\) (it depends on \(x\) and on \(n\)), but we usually don't need it: it is enough to bound \( |f^{(n+1)}| \) on the interval.

Special case \(n = 0\): the formula reads \( f(x) = f(a) + (x - a)f'(\xi) \), which is Lagrange's mean value theorem. Taylor's formula is its far-reaching generalization.

3. Where the remainder comes from

The proof is a clever application of Cauchy's mean value theorem (post on mean value theorems). Fix \(x\), and regard the "Taylor polynomial centred at a variable point \(t\)" as a function of \(t\):

\[ g(t) = f(x) - \left[f(t) + \frac{f'(t)}{1!}(x - t) + \cdots + \frac{f^{(n)}(t)}{n!}(x - t)^n\right]. \]

At the two ends: \( g(x) = 0 \) (every power of \(x - t\) vanishes) and \( g(a) = R_n(x) \) (exactly the remainder we want). When we differentiate in \(t\), the terms cancel in pairs (a telescoping sum), and only one survives:

\[ g'(t) = -\frac{f^{(n+1)}(t)}{n!}(x - t)^n. \]

Now apply Cauchy's theorem to \(g\) and an auxiliary function \(\varphi\) on the interval between \(a\) and \(x\):

\[ \frac{g(x) - g(a)}{\varphi(x) - \varphi(a)} = \frac{g'(\xi)}{\varphi'(\xi)}. \]

Different choices of \(\varphi\) give different forms of the same remainder. Lagrange's is the easiest to use; Cauchy's is sometimes sharper (see Section 8).

4. Maclaurin's formula and the standard expansions

Maclaurin's formula In the special case \(a = 0\): \[ f(x) = f(0) + \frac{x}{1!}f'(0) + \frac{x^2}{2!}f''(0) + \cdots + \frac{x^n}{n!}f^{(n)}(0) + \frac{x^{n+1}}{(n + 1)!}f^{(n+1)}(\xi), \qquad \xi = \theta x,\ 0 < \theta < 1. \]

Using the \(n\)-th derivatives from the post on higher derivatives, we get the expansions you should know by heart, now with their remainders:

FunctionMaclaurin's formula (Lagrange remainder)
\(e^x\)\( 1 + x + \frac{x^2}{2!} + \cdots + \frac{x^n}{n!} + \frac{e^{\theta x}}{(n+1)!}x^{n+1} \)
\(\sin x\)\( x - \frac{x^3}{3!} + \cdots + (-1)^{m-1}\frac{x^{2m-1}}{(2m-1)!} + R_{2m}, \quad |R_{2m}| \le \frac{|x|^{2m+1}}{(2m+1)!} \)
\(\cos x\)\( 1 - \frac{x^2}{2!} + \cdots + (-1)^m\frac{x^{2m}}{(2m)!} + R_{2m+1}, \quad |R_{2m+1}| \le \frac{|x|^{2m+2}}{(2m+2)!} \)
\(\ln(1 + x)\)\( x - \frac{x^2}{2} + \cdots + (-1)^{n-1}\frac{x^n}{n} + \frac{(-1)^n x^{n+1}}{(n+1)(1 + \theta x)^{n+1}} \)
\((1 + x)^\alpha\)\( 1 + \alpha x + \frac{\alpha(\alpha-1)}{2!}x^2 + \cdots + \binom\alpha n x^n + \binom{\alpha}{n+1}(1 + \theta x)^{\alpha - n - 1}x^{n+1} \)

A small trick for sine and cosine: since \(\sin x\) has only odd powers, its polynomial of degree \(2m - 1\) is also its polynomial of degree \(2m\) (the even coefficient is zero). So we can use the remainder \(R_{2m}\), with \(x^{2m+1}\), which is smaller. All derivatives of \(\sin\) and \(\cos\) are bounded by \(1\), which gives the simple bounds in the table.

Example 1 · A Taylor polynomial away from zero Expand \( f(x) = \sqrt x \) around \(a = 4\) up to degree \(2\). \( f(4) = 2 \), \( f'(x) = \frac{1}{2\sqrt x} \Rightarrow f'(4) = \frac14 \), \( f''(x) = -\frac{1}{4x^{3/2}} \Rightarrow f''(4) = -\frac{1}{32} \): \[ \sqrt x \approx 2 + \frac{x - 4}{4} - \frac{(x - 4)^2}{64}. \] At \(x = 4.2\): \( 2 + 0.05 - 0.000625 = 2.049375 \); the true value is \( \sqrt{4.2} = 2.04939\dots \)
Example 2 · Rewriting a polynomial Write \( P(x) = x^3 - 2x + 1 \) in powers of \( (x - 1) \). \( P(1) = 0 \), \( P'(1) = 3 - 2 = 1 \), \( P''(1) = 6 \), \( P'''(1) = 6 \), and all higher derivatives are \(0\), so the remainder vanishes for \(n = 3\): \[ P(x) = (x - 1) + 3(x - 1)^2 + (x - 1)^3. \] For a polynomial of degree \(n\), Taylor's formula is exact: it is just a change of variable.

5. Approximation with a guaranteed error

This is the main practical use: replace \(f\) by \(T_n\) and bound the remainder to know how accurate the result is.

  1. Choose a point \(a\) near \(x\) where the derivatives are easy to compute.
  2. Find a bound \( |f^{(n+1)}(t)| \le M \) for all \(t\) between \(a\) and \(x\).
  3. Then \( |R_n(x)| \le \frac{M\,|x - a|^{n+1}}{(n + 1)!} \). Choose \(n\) large enough to make this smaller than the required accuracy.
Example 3 · \(\sin 0.5\) with a certificate \( \sin 0.5 \approx 0.5 - \frac{0.5^3}{6} = 0.479167 \). This is the polynomial of degree \(3\), and also of degree \(4\), so \[ |R_4| \le \frac{0.5^5}{5!} = \frac{0.03125}{120} \approx 0.00026. \] So \( 0.47891 \le \sin 0.5 \le 0.47943 \). The true value is \(0.479426\dots\), inside the guaranteed interval.
Example 4 · How many terms do we need? Compute \( \ln 1.1 \) with an error below \(10^{-4}\). With \(x = 0.1 > 0\), the Lagrange remainder of \( \ln(1 + x) \) satisfies \[ |R_n| = \frac{x^{n+1}}{(n + 1)(1 + \theta x)^{n+1}} \le \frac{0.1^{n+1}}{n + 1}. \] For \(n = 3\) this is \( \frac{10^{-4}}{4} = 2.5\cdot10^{-5} \). Enough: \[ \ln 1.1 \approx 0.1 - \frac{0.01}{2} + \frac{0.001}{3} = 0.095333. \] The true value is \( 0.0953102\dots \), with an actual error of \(2.3\cdot10^{-5}\), as promised.

6. Limits and the "little o" form

If \(f^{(n+1)}\) is bounded near \(a\), the remainder \(R_n(x)\) contains the factor \((x - a)^{n+1}\), so it tends to zero faster than \((x - a)^n\). This is written

\[ f(x) = T_n(x) + o\big((x - a)^n\big), \qquad x \to a, \]

where \( o\big((x - a)^n\big) \) ("little o") denotes any quantity with \( \frac{o((x - a)^n)}{(x - a)^n} \to 0 \). This is the Peano form of the remainder, and it is all that's needed for limits: replace each function by its Taylor polynomial, cancel, and look at the lowest surviving power.

Example 5 \[ \lim_{x\to0}\frac{e^x - 1 - x - \frac{x^2}{2}}{x^3} = \lim_{x\to0}\frac{\frac{x^3}{6} + o(x^3)}{x^3} = \frac16. \]

L'Hôpital's rule would need three differentiations; with Taylor's formula it is one line.

Example 6 · Combining expansions \[ \lim_{x\to0}\frac{x - \sin x}{x(1 - \cos x)} = \lim_{x\to0}\frac{\frac{x^3}{6} + o(x^3)}{x\big(\frac{x^2}{2} + o(x^2)\big)} = \frac{1/6}{1/2} = \frac13. \] The rule: expand each function just far enough to get the first non-zero term.

7. Inequalities

When the sign of the remainder is known, Taylor's formula proves inequalities.

Example 7 · \( e^x \ge 1 + x \) for all \(x\) With \(n = 1\): \( e^x = 1 + x + \frac{e^{\theta x}}{2}x^2 \). The remainder is \(\ge 0\) for every \(x\), with equality only at \(x = 0\). Geometrically: the graph of \(e^x\) lies above its tangent at \(0\), as it is concave up everywhere.
Example 8 · \( \ln(1 + x) \le x \) for \(x > -1\) With \(n = 1\): \( \ln(1 + x) = x - \frac{x^2}{2(1 + \theta x)^2} \). The remainder is \(\le 0\), which proves the inequality. (Compare with the proof by Lagrange's theorem in the post on mean value theorems.)

8. Formula versus series

It is worth separating two things that are easily confused:

So Taylor's formula is the tool for proving that a Taylor series converges to the function: estimate \(R_n\) and show it tends to zero. For \(e^x\), \(\sin x\), \(\cos x\) this works with Lagrange's form for every \(x\).

Why we need Cauchy's form too For \( \ln(1 + x) \) with \( -1 < x < -\frac12 \), Lagrange's form of the remainder is too crude: the bound \( \frac{|x|^{n+1}}{(n+1)(1 + \theta x)^{n+1}} \) can't be shown to go to zero, because \(1 + \theta x\) may be smaller than \(|x|\). Cauchy's form, with its factor \((1 - \theta_1)^n\), handles the whole interval \(-1 < x \le 1\). The two forms describe the same number; they just give different estimates of it.

9. Summary

ConceptFormula
Taylor polynomial\( T_n(x) = \sum_{k=0}^n\frac{f^{(k)}(a)}{k!}(x - a)^k \)
Taylor's formula\( f(x) = T_n(x) + R_n(x) \)
Lagrange remainder\( R_n = \frac{(x - a)^{n+1}}{(n+1)!}f^{(n+1)}[a + \theta(x - a)] \)
Cauchy remainder\( R_n = \frac{(1 - \theta_1)^n(x - a)^{n+1}}{n!}f^{(n+1)}[a + \theta_1(x - a)] \)
Peano remainder\( R_n = o\big((x - a)^n\big),\ x \to a \)
Error bound\( |R_n| \le \frac{M|x - a|^{n+1}}{(n+1)!} \), \( M = \max|f^{(n+1)}| \)
Maclaurin (\(a = 0\))\( \xi = \theta x \)
\(n = 0\)Lagrange's mean value theorem

10. Practice problems

Try each one before opening the solution. More solved problems from this topic are in Differential Calculus.

Problem 1: Find the Taylor polynomial of degree \(3\) of \( \sqrt x \) at \(a = 4\).

\( f'''(x) = \frac{3}{8x^{5/2}} \Rightarrow f'''(4) = \frac{3}{256} \). So \( T_3 = 2 + \frac{x - 4}{4} - \frac{(x - 4)^2}{64} + \frac{(x - 4)^3}{512} \).

Problem 2: Compute \(e\) with an error less than \(0.001\).

At \(x = 1\): \( R_n = \frac{e^\theta}{(n + 1)!} < \frac{3}{(n + 1)!} \). We need \( (n + 1)! > 3000 \): \( 7! = 5040 \), so \(n = 6\): \( e \approx 1 + 1 + \frac12 + \frac16 + \frac1{24} + \frac1{120} + \frac1{720} = 2.71806 \) (true: \(2.71828\)).

Problem 3: Show that \( |\sin x - x| \le \frac{|x|^3}{6} \) for all \(x\).

Maclaurin with \(n = 2\): \( \sin x = x + R_2 \), \( R_2 = \frac{x^3}{3!}\sin'''(\theta x) = -\frac{x^3}{6}\cos(\theta x) \), and \( |\cos| \le 1 \).

Problem 4: Compute \( \displaystyle\lim_{x\to0}\frac{\cos x - 1 + \frac{x^2}{2}}{x^4} \).

\( \cos x = 1 - \frac{x^2}{2} + \frac{x^4}{24} + o(x^4) \), so the limit is \( \frac{1}{24} \).

Problem 5: Find the Maclaurin polynomial of degree \(3\) of \( \operatorname{tg}x \).

\( f(0) = 0 \), \( f' = 1 + \operatorname{tg}^2x \Rightarrow 1 \), \( f'' = 2\operatorname{tg}x(1 + \operatorname{tg}^2x) \Rightarrow 0 \), \( f'''(0) = 2 \). So \( \operatorname{tg}x \approx x + \frac{x^3}{3} \).

Problem 6: How many terms are needed to compute \(\cos 1\) with an error below \(10^{-5}\)?

\( |R| \le \frac{1}{(2m + 2)!} < 10^{-5} \) needs \( (2m + 2)! > 10^5 \): \( 8! = 40320 \) is not enough, \( 10! \) is. So \(2m = 8\): \( \cos 1 \approx 1 - \frac12 + \frac1{24} - \frac1{720} + \frac1{40320} = 0.540303 \) (true: \(0.5403023\)).

Problem 7: Using Taylor's formula, show that \( \sqrt{1 + x} \le 1 + \frac x2 \) for \(x > -1\).

With \(n = 1\): \( \sqrt{1 + x} = 1 + \frac x2 + \frac{f''(\theta x)}{2}x^2 \), where \( f''(t) = -\frac14(1 + t)^{-3/2} < 0 \). The remainder is \(\le 0\), so the curve lies below its tangent \(1 + \frac x2\) at \(x = 0\).

Problem 8: Explain why Taylor's formula with \(n = 0\) is Lagrange's mean value theorem.

\( T_0(x) = f(a) \), and the Lagrange remainder is \( R_0 = (x - a)f'(\xi) \). So \( f(x) - f(a) = (x - a)f'(\xi) \), exactly Lagrange's theorem.

Final thoughts

Taylor's formula turns any smooth function into a polynomial plus an error term you can control. The polynomial is built by matching derivatives at one point; the remainder looks like the next term, evaluated at an unknown intermediate point. That simple description is enough to compute values with certified accuracy, to resolve limits faster than L'Hôpital, to prove inequalities, and to justify every power series expansion. It is one of the central results of differential calculus, and it sits right on top of the mean value theorems it generalizes.

Related posts: the mean value theorems (the proof), higher derivatives (computing \(f^{(n)}\)), power series (the infinite version) and L'Hôpital's rule (an alternative for limits).