Deriving a Power Series for π

Today, I want to talk about how you can use a power series to define π. No CS today, all math! My impetus for writing this post was reading through the chapter 11.9 exercises of Stewart Calculus, one of which asks you to prove that a specific infinite series equals π, so I wanted to take it a step further and derive that series from the definitions of trigonometric functions. Hope you enjoy!


Given a right triangle, we define the main trigonometric functions as follows:

sin(θ)=o/h, cos(θ)=a/hsin(\theta) = o/h, \space cos(\theta) = a/h

where o and a are the opposite and adjacent sides relative to the angle, and the hypotenuse is the side opposite the 90 degree angle. From the definitions of sine and cosine, we derive the tan, csc, sec, and cot functions. Tangent, in particular, is defined as

tan(θ)=sin(θ)/cos(θ)=o/atan(\theta)=sin(\theta)/cos(\theta)=o/a

The trigonometric functions each have inverses, and we can define them. For arctan, it is

x=tan(y)y=arctan(x)x=tan(y) \rightarrow y=arctan(x)

Using implicit differentiation, we can calculate the derivative of arctan easily:

1=sec2(y)dydxdydx=1sec2(y)1 = sec^2(y)\frac{dy}{dx} \rightarrow \frac{dy}{dx}=\frac{1}{sec^2(y)}

If we draw a right triangle with the angle y, we can see that

sec(x)=1+x2sec2(x)=1+x2sec(x)=\sqrt{1+x^2} \rightarrow sec^2(x)=1+x^2

which implies that

dydx=11+x2\frac{dy}{dx}=\frac{1}{1+x^2}

From the definition of power series and geometric series, we know that

11x=n=0xn, x<1\frac{1}{1-x}=\sum_{n=0}^{\infty}x^n, \space |x|<1

We can derive a series for

f(x)=11+x2f(x)=\frac{1}{1+x^2}

by rewriting it as

11(x2)=n=0(1)nx2n, x<1\frac{1}{1-(-x^2)}=\sum_{n=0}^{\infty}(-1)^nx^{2n}, \space |x|<1 =1x2+x4x6+= 1-x^2+x^4-x^6+\cdots

If we integrate term by term, we can derive the power series for arctan by integrating term by term like so:

n=0(1)nx2n=xx33+x55x77+\int \sum_{n=0}^{\infty}(-1)^nx^{2n} = x-\frac{x^3}{3}+\frac{x^5}{5}-\frac{x^7}{7}+\cdots =n=0(1)nx2n+12n+1, x<1= \sum_{n=0}^{\infty}(-1)^n\frac{x^{2n+1}}{2n+1}, \space |x|<1

We can evaluate the endpoints (x=±1), but we don’t need to for our purposes. We can just use the fact that

arctan(33)=π6π=6arctan(33) arctan(\frac{\sqrt{3}}{3})=\frac{\pi}{6} \rightarrow \pi = 6 \cdot arctan(\frac{\sqrt{3}}{3})

Since π/6 is in the interval of convergence, if we evaluate the series at that value, and multiply the whole thing by 6, we get

π=6n=0(1)n(33)2n+12n+1 \pi = 6 \cdot \sum_{n=0}^{\infty}(-1)^n\frac{(\frac{\sqrt{3}}{3})^{2n+1}}{2n+1}

which simplifies to

π=23n=0(1)n13n(2n+1) \pi = 2\sqrt{3} \cdot \sum_{n=0}^{\infty}(-1)^n\frac{1}{3^n(2n+1)}

This converges pretty slowly, and isn’t a great approximation, and you probably shouldn’t use it to calculate π. If you’re just a user of pi, just hardcode the value or use your programming language’s hardcoded value. If you actually care about calculating the digits of π, use the Ramanujan-Sato series or the Chudnovsky algorithm. I wrote this post because I think it’s pretty cool that you can define π as an infinite series.


Anyway, till next time, thanks for reading (:

calculus
power-series