# Taylor's series

A well-behaved function can be expanded into a power series. This means that for all non-negative integers ${\displaystyle k}$ there are real numbers ${\displaystyle a_{k}}$ such that

${\displaystyle f(x)=\sum _{k=0}^{\infty }a_{k}x^{k}=a_{0}+a_{1}x+a_{2}x^{2}+a_{3}x^{3}+a_{4}x^{4}+\cdots }$

Let us calculate the first four derivatives using ${\displaystyle (x^{n})'=n\,x^{n-1}}$:

${\displaystyle f'(x)=a_{1}+2\,a_{2}x+3\,a_{3}x^{2}+4\,a_{4}x^{3}+5\,a_{5}x^{4}+\cdots }$
${\displaystyle f''(x)=2\,a_{2}+2\cdot 3\,a_{3}x+3\cdot 4\,a_{4}x^{2}+4\cdot 5\,a_{5}x^{3}+\cdots }$
${\displaystyle f'''(x)=2\cdot 3\,a_{3}+2\cdot 3\cdot 4\,a_{4}x+3\cdot 4\cdot 5\,a_{5}x^{2}+\cdots }$
${\displaystyle f''''(x)=2\cdot 3\cdot 4\,a_{4}+2\cdot 3\cdot 4\cdot 5\,a_{5}x+\cdots }$

Setting ${\displaystyle x}$ equal to zero, we obtain

${\displaystyle f(0)=a_{0},\quad f'(0)=a_{1},\quad f''(0)=2\,a_{2},\quad f'''(0)=2\times 3\,a_{3},\quad f''''(0)=2\times 3\times 4\,a_{4}.}$

Let us write ${\displaystyle f^{(n)}(x)}$ for the ${\displaystyle n}$-th derivative of ${\displaystyle f(x).}$ We also write ${\displaystyle f^{(0)}(x)=f(x)}$ — think of ${\displaystyle f(x)}$ as the "zeroth derivative" of ${\displaystyle f(x).}$ We thus arrive at the general result ${\displaystyle f^{(k)}(0)=k!\,a_{k},}$ where the factorial ${\displaystyle k!}$ is defined as equal to 1 for ${\displaystyle k=0}$ and ${\displaystyle k=1}$ and as the product of all natural numbers ${\displaystyle n\leq k}$ for ${\displaystyle k>1.}$ Expressing the coefficients ${\displaystyle a_{k}}$ in terms of the derivatives of ${\displaystyle f(x)}$ at ${\displaystyle x=0,}$ we obtain

 ${\displaystyle f(x)=\sum _{k=0}^{\infty }{f^{(k)}(0) \over k!}x^{k}=f(0)+f'(0)x+f''(0){x^{2} \over 2!}+f'''(0){x^{3} \over 3!}+\cdots }$

This is the Taylor series for ${\displaystyle f(x).}$

A remarkable result: if you know the value of a well-behaved function ${\displaystyle f(x)}$ and the values of all of its derivatives at the single point ${\displaystyle x=0}$ then you know ${\displaystyle f(x)}$ at all points ${\displaystyle x.}$ Besides, there is nothing special about ${\displaystyle x=0,}$ so ${\displaystyle f(x)}$ is also determined by its value and the values of its derivatives at any other point ${\displaystyle x_{0}}$:

 ${\displaystyle f(x)=\sum _{k=0}^{\infty }{f^{(k)}(x_{0}) \over k!}(x-x_{0})^{k}.}$

## Examples

### cos${\displaystyle (x)}$

${\displaystyle f(x)=\cos(x);\ f(0)=\cos(0)=1}$

${\displaystyle f'(x)=-\sin(x);\ f'(0)=-\sin(0)=0}$

${\displaystyle f''(x)=-\cos(x);\ f''(0)=-\cos(0)=-1}$

${\displaystyle f'''(x)=\sin(x);\ f'''(0)=\sin(0)=0}$

${\displaystyle f''''(x)=\cos(x);\ f''''(0)=\cos(0)=1}$

${\displaystyle a_{0}=f(0)=1}$

${\displaystyle a_{1}=f'(0)=0}$

${\displaystyle a_{2}={\frac {f''(0)}{2}}={\frac {-1}{2!}}}$

${\displaystyle a_{3}={\frac {f'''(0)}{2*3}}={\frac {0}{3!}}=0}$

${\displaystyle a_{4}={\frac {f''''(0)}{2*3*4}}={\frac {1}{4!}}}$

${\displaystyle \cos(x)=a_{0}+a_{1}x+a_{2}x^{2}+a_{3}x^{3}+a_{4}x^{4}+\cdots }$ ${\displaystyle =1+(0)x+{\frac {-1}{2}}x^{2}+0x+{\frac {1}{4!}}x^{4}+\cdots }$ ${\displaystyle =1-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-{\frac {x^{6}}{6!}}+{\frac {x^{8}}{8!}}-\cdots }$

Some basic checking:

${\displaystyle \cos(0)=1-{\frac {0^{2}}{2!}}+{\frac {0^{4}}{4!}}-{\frac {0^{6}}{6!}}+{\frac {0^{8}}{8!}}-\cdots =1}$

${\displaystyle \cos(-x)=1-{\frac {(-x)^{2}}{2!}}+{\frac {(-x)^{4}}{4!}}-{\frac {(-x)^{6}}{6!}}+{\frac {(-x)^{8}}{8!}}-\cdots }$ ${\displaystyle =1-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-{\frac {x^{6}}{6!}}+{\frac {x^{8}}{8!}}-\cdots =\cos(x)}$

### arctan${\displaystyle (x)}$

${\displaystyle y=\arctan(x)}$

${\displaystyle x=\tan(y)}$

${\displaystyle {\frac {dx}{dy}}=\sec ^{2}(y)}$

${\displaystyle y'={\frac {dy}{dx}}=\cos ^{2}(y)={\frac {1}{1+x^{2}}}}$. See ${\displaystyle \cos(\theta )}$.

#### Second derivative ${\displaystyle y''}$

 ${\displaystyle (1+x^{2})y'=1}$ ${\displaystyle (1+x^{2})y''+y'(2x)=0}$ ${\displaystyle y''={\frac {-y'(2x)}{1+x^{2}}}}$ ${\displaystyle ={\frac {-2x}{1+x^{2}}}.y'}$ ${\displaystyle ={\frac {-2x}{1+x^{2}}}.{\frac {1}{1+x^{2}}}}$ ${\displaystyle ={\frac {-2x}{(1+x^{2})^{2}}}}$

#### Third derivative ${\displaystyle y'''}$

 ${\displaystyle (1+2x^{2}+x^{4})y''=-2x}$ ${\displaystyle (1+2x^{2}+x^{4})y'''+y''(4x+4x^{3})=-2}$ ${\displaystyle y'''={\frac {-2-y''(4x+4x^{3})}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {-2-y''4x(1+x^{2})}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {-2-{\frac {-2x}{(1+x^{2})^{2}}}.4x(1+x^{2})}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {-2-{\frac {-2x}{1+x^{2}}}.4x}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {-2+{\frac {8x^{2}}{1+x^{2}}}}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {\frac {-2(1+x^{2})+8x^{2}}{1+x^{2}}}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {\frac {-2-2x^{2}+8x^{2}}{1+x^{2}}}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {\frac {-2+6x^{2}}{1+x^{2}}}{1+2x^{2}+x^{4}}}}$ ${\displaystyle ={\frac {-2+6x^{2}}{(1+2x^{2}+x^{4})(1+x^{2})}}}$ ${\displaystyle ={\frac {-2+6x^{2}}{(1+x^{2})^{3}}}}$

### (continued)

If you continue to calculate derivatives, you will produce the following sequence:

${\displaystyle f(0)=0}$

${\displaystyle f'(0)=1}$

${\displaystyle f''(0)=0}$

${\displaystyle f'''(0)=-2=-(2!)}$

${\displaystyle f''''(0)=0}$

${\displaystyle f^{v}(0)=24=4!}$

${\displaystyle f^{vi}(0)=0}$

${\displaystyle f^{vii}(0)=-720=-(6!)}$

${\displaystyle f^{viii}(0)=0}$

${\displaystyle f^{viiii}(0)=40320=8!}$

${\displaystyle f^{x}(0)=0}$

${\displaystyle f^{xi}(0)=-3628800=-(10!)}$

${\displaystyle f^{xii}(0)=0}$

${\displaystyle f^{xiii}(0)=479001600=12!}$

${\displaystyle \arctan(x)=a_{0}+a_{1}x+a_{2}x^{2}+a_{3}x^{3}+a_{4}x^{4}+\cdots }$

${\displaystyle =0+(1)x+(0)x^{2}+{\frac {-(2!)}{3!}}x^{3}+(0)x^{4}+{\frac {4!}{5!}}x^{5}+(0)x^{6}+{\frac {-(6!)}{7!}}x^{7}+(0)x^{8}+{\frac {8!}{9!}}x^{9}+(0)x^{10}+{\frac {-(10!)}{11!}}x^{11}+\cdots }$

${\displaystyle =x-{\frac {1}{3}}x^{3}+{\frac {1}{5}}x^{5}-{\frac {1}{7}}x^{7}+{\frac {1}{9}}x^{9}-{\frac {1}{11}}x^{11}+\cdots }$

Some basic checking:

${\displaystyle \arctan(0)=0}$

${\displaystyle \arctan(-x)=-\arctan(x).}$

### arcsin${\displaystyle (x)}$

${\displaystyle y=\arcsin(x)}$

${\displaystyle x=\sin(y)}$

${\displaystyle {\frac {dx}{dy}}=\cos(y)={\sqrt {1-x^{2}}}}$

${\displaystyle {\frac {dy}{dx}}={\frac {1}{\cos(y)}}={\frac {1}{\sqrt {1-x^{2}}}}}$

Simple differential equations eliminate the square root and make calculations so much easier.

Let ${\displaystyle a={\frac {dy}{dx}}}$

Then ${\displaystyle a^{2}U=1}$ where ${\displaystyle U=1-x^{2}}$ and ${\displaystyle U^{'}=-2x.}$

Differentiating both sides:

${\displaystyle a^{2}(-2x)+U2aa^{'}=0}$

${\displaystyle U2aa^{'}=2xa^{2}}$

${\displaystyle a^{'}={\frac {2xaa}{2aU}}={\frac {ax}{U}}.}$

Let ${\displaystyle b=a^{'}}$

Then ${\displaystyle bU=ax}$

Differentiating both sides:

${\displaystyle b(-2x)+Ub^{'}=a+xa^{'}=a+xb}$

Let ${\displaystyle c=b^{'}}$

Then ${\displaystyle c={\frac {a+3bx}{U}}}$

When ${\displaystyle x=0,\ U=1.}$ Calculation of more derivatives yields:

${\displaystyle y=f(x)=\arcsin(x)}$

${\displaystyle a=f^{'}(x)={\frac {1}{\sqrt {1-x^{2}}}}}$

${\displaystyle b=f^{''}(x)=ax}$

${\displaystyle c=f^{'''}(x)=a+3bx}$

${\displaystyle d=f^{''''}(x)=4b+5cx}$

${\displaystyle g=f^{v}(x)=9c+7dx}$

${\displaystyle h=f^{vi}(x)=16d+9gx}$

${\displaystyle j=f^{vii}(x)=25g+11hx}$

${\displaystyle k=f^{viii}(x)=36h+13jx}$

${\displaystyle l=f^{viiii}(x)=49j+15kx}$

and so on.

${\displaystyle \cdots =k=h=d=b=0}$

${\displaystyle a=1;\ c=1^{2}a;\ g=3^{2}c;\ j=5^{2}g;\ l=7^{2}j;\ \cdots .}$

${\displaystyle \arcsin(x)=x+{\frac {1}{3!}}x^{3}+{\frac {3^{2}}{5!}}x^{5}+{\frac {3^{2}\cdot 5^{2}}{7!}}x^{7}+{\frac {3^{2}\cdot 5^{2}\cdot 7^{2}}{9!}}x^{9}+{\frac {3^{2}\cdot 5^{2}\cdot 7^{2}\cdot 9^{2}}{11!}}x^{11}+\cdots }$

${\displaystyle \arcsin(x)=x+{\frac {1}{3!}}x^{3}+{\frac {3}{(2!)(2^{2})5}}x^{5}+{\frac {3\cdot 5}{(3!)(2^{3})7}}x^{7}+{\frac {3\cdot 5\cdot 7}{(4!)(2^{4})9}}x^{9}+{\frac {3\cdot 5\cdot 7\cdot 9}{(5!)(2^{5})11}}x^{11}+\cdots }$

#### As programming algorithm:

${\displaystyle \arcsin(x)=x+{\frac {top=1}{(bottom=2)3}}(X=x^{3})}$ ${\displaystyle +{\frac {top=top(5-2)}{(bottom=bottom(5-1))5}}(X=X(x^{2}))}$ ${\displaystyle +{\frac {top=top(7-2)}{(bottom=bottom(7-1))7}}(X=X(x^{2}))}$ ${\displaystyle +\cdots }$ ${\displaystyle +{\frac {top=top(n-2)}{(bottom=bottom(n-1))n}}(X=X(x^{2}))}$

#### As implemented in Python:

from decimal import * # Default precision is 28.

π = ("3.14159265358979323846264338327950288419716939937510582097494459230781")
π = Decimal(π)

x = Decimal(2).sqrt()/2 # Expecting result of π/4

xSQ = x*x
X = x*xSQ

top = Decimal(1)
bottom = Decimal(2)

bottom1 = bottom*3
sum = x + X*top / bottom1

status = 1
for n in range(5,200,2) :
X = X*xSQ
top = top*(n-2)
bottom = bottom*(n-1)
bottom1 = bottom*n
status = 0
break

if status :
print ('error. count expired.')
else :
print (x, sum==π/4, n)

0.707106781186547524400844362 True 171

#### In practice

If ${\displaystyle |x|}$ is close to ${\displaystyle 1,}$ the calculation of ${\displaystyle \arcsin(x)}$ will take forever.

If you limit ${\displaystyle x}$ to ${\displaystyle \sin 45^{\circ }>=x>=-\sin 45^{\circ },}$ then ${\displaystyle x^{2}<=0.5}$ and each term is guaranteed to be less than half the preceding term.

If ${\displaystyle x>\sin 45^{\circ },}$ let ${\displaystyle t={\frac {\pi }{2}}-y.}$

Then ${\displaystyle \sin t=\cos y;\ t=\arcsin(\cos y);\ y={\frac {\pi }{2}}-t.}$