691 words
3 minutes
Taylor Series

Taylor’s Formula#

Let’s consider a polynomial:

p=p(x)=a0+a1x+a2x2++anxnp=p(x)=a_0+a_1x+a_2x^2+\dots+a_nx^n

Using high school differentiation rules, we can easily obtain the following results:

p=a1+2a2x+3a3x2++nanxn1,p=2a2+32a3x++n(n1)anxn2,p(n)=n(n1)(n2)2an\begin{aligned} p'&=a_1+2a_2x+3a_3x^2+\dots+na_nx^{n-1},\\ p''&=2a_2+3\cdot 2a_3x+\dots+n\cdot (n-1)a_nx^{n-2},\\ &\dots\\ p^{(n)}&=n\cdot(n-1)\cdot(n-2)\dots2\cdot a_n \end{aligned}

Now, let x=0x=0, then we have:

p(i)(0)=aii!ai=p(i)(0)i!p^{(i)}(0)=a_i\cdot i!\\ \Rightarrow a_i=\frac{p^{(i)}(0)}{i!}

Substituting back into the original expression, we get:

p(x)=p(0)+p(0)1!x+p(0)2!x2++p(n)(0)n!xnp(x)=p(0)+\frac{p'(0)}{1!}x+\frac{p''(0)}{2!}x^2+\dots+\frac{p^{(n)}(0)}{n!}x^n

If we had initially let x=(xx0)x=(x-x_0), then at this step, we would obtain:

p(x)=p(x0)+p(x0)1!(xx0)+p(x0)2!(xx0)2++p(n)(x0)n!(xx0)np(x)=p(x_0)+\frac{p'(x_0)}{1!}(x-x_0)+\frac{p''(x_0)}{2!}(x-x_0)^2+\dots+\frac{p^{(n)}(x_0)}{n!}(x-x_0)^n

This is the well-known Taylor’s formula.

Expansion of Arbitrary Functions#

If a function f(x)f(x) is nn-times differentiable at x0x_0 on the interval [a,b][a,b], then we can construct the polynomial

pn(x)=f(x0)+f(x0)1!(xx0)+f(x0)2!(xx0)2++f(n)(x0)n!(xx0)np_n(x)=f(x_0)+\frac{f'(x_0)}{1!}(x-x_0)+\frac{f''(x_0)}{2!}(x-x_0)^2+\dots+\frac{f^{(n)}(x_0)}{n!}(x-x_0)^n

However, at this point, f(x)=pn(x)f(x)=p_n(x) does not necessarily hold true. The p(x)p(x) we obtained can only be regarded as an approximation of the function f(x)f(x).
We denote their error as rn(x)=f(x)pn(x)r_n(x)=f(x)-p_n(x).
We find that when xx0x\rightarrow x_0, rn(x)=o((xx0)n)r_n(x)=o((x-x_0)^n).

Proof

Consider its equivalent proposition:

rn(x0)=rn(x0)==rn(m)(x0)=0r_n(x_0)=r_n'(x_0)=\dots=r_n^{(m)}(x_0)=0

We use mathematical induction for the proof.
When m=0,1m=0,1, clearly:

rn(x0)=rn(x0)=0r_n(x_0)=r_n'(x_0)=0

Assume it holds for 1m=k1\le m=k. To prove it also holds for m=k+1m=k+1, i.e.,

rn(x0)=rn(x0)==rn(k+1)(x0)=0r_n(x_0)=r_n'(x_0)=\dots=r_n^{(k+1)}(x_0)=0

then

rn(x)=o((xx0)k+1)r_n(x)=o((x-x_0)^{k+1})

Thus,

rn(x)=o((xx0)k)r_n'(x)=o((x-x_0)^k)

But (A chinese meme) by Lagrange’s Mean Value Theorem, there must exist xt[x,x0]\exists x_t\in[x,x_0] such that

rn(xt)(xx0)=rn(x)rn(x0)rn(xt)=o((xx0)k)r_n'(x_t)(x-x_0)=r_n(x)-r_n(x_0)\\ \Rightarrow r_n'(x_t)=o((x-x_0)^k)\\

Then we very easily obtain:

f(x)=i=0nf(i)(x0)i!(xx0)i+o((xx0)n)f(x)=\sum^n_{i=0}{\frac{f^{(i)}(x_0)}{i!}(x-x_0)^i}+o((x-x_0)^n)

This is called the Taylor’s formula with Peano remainder.
Next, we prove its uniqueness.

Proof of Uniqueness

Suppose we simultaneously have:

f(x)=i=0nAi(xx0)i+o((xx0)n)f(x)=\sum^n_{i=0}{A_i(x-x_0)^i}+o((x-x_0)^n)

and

f(x)=i=0nAi(xx0)i+o((xx0)n)f(x)=\sum^n_{i=0}{A'_i(x-x_0)^i}+o((x-x_0)^n)

Letting xx0x\to x_0, we get A0=A0A_0=A'_0. Subtract the two equations, then divide by (xx0)(x-x_0), to get A1=A1A_1=A'_1. Continuing this process, we obtain:

Ai=Ai(i[1,n]N)A_i=A'_i(\forall i\in[1,n]\cap\mathbb{N})

Thus, it’s unique!

Substituting x0=0x_0=0, we get a more concise expression called the Maclaurin expansion. Giving it a new name?! Actually quite ironic.
Below are the Maclaurin expansions of some basic elementary functions.

ex=i=0nxii!+o(xn)sin(x)=i=0n(1)i+1x2i1(2i1)!+o(x2n)cos(x)=i=0n(1)ix2i(2i)!+o(x2n+1)\begin{aligned} e^x&=\sum_{i=0}^n\frac{x^i}{i!}+o(x^n)\\ \sin(x)&=\sum_{i=0}^n(-1)^{i+1}\frac{x^{2i-1}}{(2i-1)!}+o(x^{2n})\\ \cos(x)&=\sum_{i=0}^n(-1)^i\frac{x^{2i}}{(2i)!}+o(x^{2n+1})\\ \end{aligned}

Taylor Series#

In the previous Taylor’s formula, note that nn can take any value, so naturally, we consider letting it tend to infinity.
Thus, the Taylor series refers to the Taylor formula when nn\to\infty~
Formally, the Taylor series has the following form:

f(x)=i=0Ai(xx0)if(x)=\sum^\infty_{i=0}{A_i(x-x_0)^i}

where

An=f(i)(x0)i!A_n=\frac{f^{(i)}(x_0)}{i!}

are called the Taylor coefficients.
Although this seems very simple, it raises many problems. The most direct one is: Does that series converge? And will it still equal the original function? This is a very tricky problem.

f(x)f(x) can equal that summation if and only if the remainder term rn(x)r_n(x) satisfies: limnrn(x)=0\lim_{n\to\infty}r_n(x)=0 The proof is obvious.
But to prove this equality holds, we might need to study other forms of the remainder term. Below, I will discuss the case for x0=0x_0=0; other cases are left for the reader to explore.

  • Lagrange form: rn(x)=f(n+1)(θx)(n+1)!xn+1r_n(x)=\frac{f^{(n+1)}(\theta x)}{(n+1)!}x^{n+1}
  • Cauchy form: rn(x)=f(n+1)(θx)n!(1θ)xn+1r_n(x)=\frac{f^{(n+1)}(\theta x)}{n!}(1-\theta)x^{n+1}

where θ[0,1]\theta\in[0,1].
Proof? The Lagrange form is proved using Lagrange’s Mean Value Theorem, and the Cauchy form is proved using Cauchy’s Mean Value Theorem.

Here are the specific Taylor expansions of some functions.

Taylor Expansions of Exponential and Basic Trigonometric Functions#

If a function f(x)f(x) has derivatives of all orders on the interval [0,H][0,H] or [H,0](H>0)[-H,0](H>0), and when xx varies within the given interval, the absolute values of all these derivatives are bounded by the same number: f(n)(x)L|f^{(n)}(x)|\le L Then this function can be expanded as a Taylor series.

Proof

We take the remainder in the Lagrange form, then we easily get: rn(x)=f(n+1)(θx)(n+1)!xn+1LHn+1(n+1)!|r_n(x)|=\frac{|f^{(n+1)}(\theta x)|}{(n+1)!}|x|^{n+1}\le L\cdot\frac{H^{n+1}}{(n+1)!} Let’s prove a stronger conclusion. Summing both sides, we get:

n=0rn(x)Ln=0Hn+1(n+1)!\sum_{n=0}^\infty|r_n(x)|\le L\cdot\sum_{n=0}^\infty \frac{H^{n+1}}{(n+1)!}

The right-hand side clearly converges, thus we can deduce rn(x)0r_n(x)\to 0!

When f(x)=ex,sin(x),cos(x)f(x)=e^x,\sin(x),\cos(x), the conditions are clearly satisfied, so we can write their expansions:

ex=i=0xii!sin(x)=i=1(1)i+1x2i1(2i1)!cos(x)=i=0(1)ix2i(2i)!arctan(x)=i=1(1)i+1x2i12i1\begin{aligned} e^x&=\sum_{i=0}^\infty\frac{x^i}{i!}\\ \sin(x)&=\sum_{i=1}^\infty(-1)^{i+1}\frac{x^{2i-1}}{(2i-1)!}\\ \cos(x)&=\sum_{i=0}^\infty(-1)^i\frac{x^{2i}}{(2i)!}\\ \arctan(x)&=\sum_{i=1}^\infty(-1)^{i+1}\frac{x^{2i-1}}{2i-1} \end{aligned}

Here, for the arctangent expansion, substituting x=1x=1, we get:

π4=113+15\frac\pi4=1-\frac13+\frac15-\cdots

which is the classic Leibniz formula.

Logarithmic Function#

Consider expanding f(x)=ln(1+x)f(x)=\ln(1+x). The reason we expand ln(1+x)\ln(1+x) is that it’s convenient for calculation.
First, write its Taylor series:

ln(1+x)=n=1(1)n+1xnn\ln(1+x)=\sum_{n=1}^\infty(-1)^{n+1}\frac{x^n}{n}

We use the Lagrange form of the remainder to consider its convergence.

limnrn(x)=(1)nn+1(xθx+1)n+1=0\lim_{n\to\infty}r_n(x)=\frac{(-1)^n}{n+1}\cdot(\frac x{\theta x+1})^{n+1}=0

But unfortunately, the above only holds when x(1,1]x\in(-1,1], meaning its expansion converges only in this interval.

Stirling’s Formula#

Most applications of Taylor series involve estimation. Here is a classic example of estimation.
Consider the Taylor expansion of ln(1+x)\ln(1+x) we obtained earlier. We can easily get:

ln1+x1x=ln(1+x)ln(1+(x))=2x(1+x23+x45+)\ln\frac{1+x}{1-x}=\ln(1+x)-\ln(1+(-x))=2x\cdot(1+\frac{x^2}{3}+\frac{x^4}5+\dots)

Let x=12n+1x=\frac1{2n+1}, then we can obtain:

lnn+1n=22n+1[1+131(2n+1)2+]\ln\frac{n+1}{n}=\frac2{2n+1}\cdot[1+\frac13\cdot\frac1{(2n+1)^2}+\dots]

Rearranging terms, we get:

1<(n+12)ln(1+1n)=1+131(2n+1)2+<1+13[1(2n+1)2+1(2n+1)4+]=1+112n(n+1)\begin{aligned} 1<(n+\frac12)\ln(1+\frac1n)&=1+\frac13\cdot\frac1{(2n+1)^2}+\dots\\ &<1+\frac13\cdot[\frac1{(2n+1)^2}+\frac1{(2n+1)^4}+\dots]\\ &=1+\frac1{12n(n+1)} \end{aligned}

Taking the natural exponential on both sides:

1<(1+1n)n+12e<e112n(n+1)1<\frac{(1+\frac1n)^{n+\frac12}}{e}<e^\frac1{12n(n+1)}

Here introduces a genius idea. Let an=n!ennn+12a_n=\frac{n!e^n}{n^{n+\frac12}}, then we can get:

1<anan+1=(1+1n)n+12e<e112n(n+1)=e112ne112(n+1)ane112n<an+1e112(n+1)1<\frac{a_n}{a_{n+1}}=\frac{(1+\frac1n)^{n+\frac12}}{e}<e^\frac1{12n(n+1)}=\frac{e^\frac1{12n}}{e^\frac1{12(n+1)}}\\ \Rightarrow a_n e^{-\frac1{12n}}<a_{n+1}e^{-\frac1{12(n+1)}}

Note that clearly a\exists a such that ane112n<a<ana_n e^{-\frac1{12n}}<a<a_n holds. Let

a=aneθ12na=a_ne^{-\frac\theta{12n}}

Substituting the definition of ana_n, we can obtain:

n!=an(ne)neθ12nn! =a\sqrt n(\frac ne)^n\cdot e^\frac\theta{12n}

Now consider how to solve for aa.
Note that:

π2=limn12n+1[(2n)!!(2n1)!!]2\frac\pi2=\lim_{n\to\infty}\frac1{2n+1}\cdot\left[\frac{(2n)!!}{(2n-1)!!}\right]^2

Let’s transform this double factorial:

(2n)!!(2n1)!!=22n(n!)2(2n)!\frac{(2n)!!}{(2n-1)!!}=\frac{2^{2n}(n!)^2}{(2n)!}

Replace n!n! and (2n)!(2n)! with the results we derived earlier:

(2n)!!(2n1)!!=an2e4θθ24n\frac{(2n)!!}{(2n-1)!!}=a\sqrt\frac n2\cdot e^\frac{4\theta-\theta'}{24n}

Substitute back into the original limit:

π2=limn12n+1a2n2e4θθ12n=a24a=2π\frac\pi2=\lim_{n\to\infty}\frac1{2n+1}a^2\cdot\frac n2\cdot e^\frac{4\theta-\theta'}{12n} =\frac{a^2}4\\ \Rightarrow a=\sqrt{2\pi}

Substitute back into the initial equation, and we finally obtain Stirling’s formula:

n!=2πn(ne)neθ12nn! =\sqrt{2\pi n}\cdot(\frac ne)^n\cdot e^\frac\theta{12n}

This can be used for estimation when nn is very large.

Taylor Series
https://peakyi.github.io/posts/taylor/
Author
Hiiragi Kagami
Published at
2025-10-16
License
CC BY-NC-SA 4.0