# An Infinite Sum Approximation of Pi

The value of Pi rounded to four decimal places is 3.1416, which makes today (3/14/16) one of the most prominent International Pi Days you’ll experience in your lifetime. This year I’m looking at Issac Newton’s infinite series approximation for π. Originating in the long ago 1730s, it’s still one of the fastest converging Pi approximations to this day.

### Issac Newton looked for a Sine

Our story begins with the familiar wave-like pattern produced by a function we all learned about in trigonometry class. The Sine of an angle, Sin θ, within a right triangle is the ratio of the leg opposite the angle θ to the triangle’s hypotenuse. Since the hypotenuse is the longest leg in a right triangle, this value will always be 1 or less (it approaches 1 in the extreme case of θ approaching a full 90 degrees, which will leave you with a flat line rather than a triangle.)

### A Simpler Measure of an Angle

We next learn a more convenient measure of the angle θ is the radian. Some readers may fret the loss of degrees, but you’ll soon recognize why radians make this story much simpler to tell.

Radians arise out of generalizing from the right triangle to the unit circle. While right triangles were instructive learning instruments, their triangular fenced-in parcel of land is very confining for us. Taking what we know about trigonometric functions to apply them to a unit circle will be tremendously liberating.

Our unit circle can be in rectangular coordinates on a Cartesian plane or in polar coordinates. It has a radius, r defined to be 1 (the “unit” in unit circle), and a circumference defined to be 2π radians (from the basic formula for the circumference of a circle, C=2πr). In this mental picture, r, is identical to hypotenuse of a right triangle. The “unit-ness” of r gives us a known value that, combined with a known angle θ, allows us to solve for the trigonometric functions. Many more applications follow from this generalization such as projecting the length of a vector along one or more basis components, so some familiarity with it is crucial.

### Inverting the Sine function

Observe the plot of sin θ, are there any points which jump out at you? It reaches a maximum at 1 when θ is π/2 radians, this was interesting to Newton. Even more so, it is 1/2 when θ is π/6. Newton wants to determine π and there it is, staring back at him in the radian measurement of θ (you couldn’t do this legerdemain with degrees!)

What Newton wants to do is turn the function around, so that instead of giving the sine of an angle, it gives the angle for a sine (ratio of opposite-to-hypotenuse in a right triangle). In mathematics, this would be an inverse function written as $sin^{-1}$.

Owing to the periodic nature of the sine function, it’s inverse would be a multi-valued function. Sine isn’t 1 only for π/2 radians, but for (2k+1)π/2 radians for every integer, k. It will make things simpler for us to only consider the principle value of the inverse, where k=0. This function is Arcsin, and it tells us an angle between -π and π corresponding to its sine parameter.

### From Trigonometric Identity to Infinite Series

We know now that,

π/6 = Arcsin( 1/2 )

Consequently, by multiplying through by 6,

π = 6 Arcsin( 1/2 )

In Newton’s time the Maclaurin series expansion of Arcsin x was well known (I wonder how well known it is in the 21st Century?)

Arcsin( x ) = $x + \frac{x^3}{6} + \frac{3x^5}{40} + \frac{5x^7}{112} + \frac{35x^9}{1152} + ...$

Substituting into the previous equation for π with x=1/2 and multiplying by 6, we obtain this infinite series expansion for π itself,

π = $6(1/2) + (1/2)^3 + \frac{18}{40} (1/2)^5 + \frac{30}{112} (1/2)^7 + \frac{210}{1152} (1/2)^9 + ...$

Computers catch a break when computing all of the (1/2)n to odd powers n because they are powers-of-2, by using their extremely efficient bit-shift operation. Briefly, 2² is represented ‘0100’ in binary. Simply shifting each bit to left one position is equivalent to multiplying by 2, automatically calculating 2³ as 1000 in binary. It is the same as in everyday decimal arithmetic, where ’25’ can be easily multiplied by 10 simply by adding a 0 digit at the end that shifts every digit one position left yielding ‘250’.

### Approximating Pi

All that’s left for Newton to do now is to compute each fraction and add up the series to an arbitrary number of terms. The trade-off made here is common to any Taylor series expansion: the more terms we use in the calculation, the closer our sum will be to the actual value of π. Doing the math, you’ll see here that five terms give you π correct to four decimal places.

 3.0000000
0.1250000
0.0140625
0.0020926
+0.0003560
__________
3.1415111    Approximate sum of five terms
3.1415927    Actual π rounded to 7 decimal places


Not quite as good as the approximate fraction, $\frac{355}{113}$, which is good for six decimal places if you need to calculate π in a pinch. However, Newton’s method lets you add more terms to the sum to reduce the error in the approximation, letting you find π to any arbitrary precision.

### It Makes a Difference

How fast does this sum converge to the precision that you need? I mentioned that Newton’s method was still one of the fastest converging approaches, even after nearly three centuries. For one moment, consider if he had instead used the identity,

π/2 = Arcsin( 1 )

Following all the same logic (this time multiplying by 2 instead of 6) would still produce an infinite sum that converges to π—at infinity! It would not converge quickly to a useful approximation of π. Why not?

Using the same first five terms of the Maclaurin series expansion produces a result of 2.6333829, not even close to 3 (which would be much more useful an approximation), nevermind π itself.

Just look at the first term. You can get a feel for how quickly each sum converges to π from this. Using Arcsin(1) you have x=1 and a multiplier of 2, resulting in the first term of the sum being 2. However, using Arcsin(½) you have x=½ (which is half as much as 1, so you’d expect it to converge half-as-fast) and a multiplier of 6 (which is three times as much as 2, so you’d expect it to converge three-times as fast). This results in the first term of the sum being 3; much closer to π! Further terms contribute smaller and smaller quantities to this sum as it approaches π from below, but the key point was that choosing Arcsin(½) takes you significantly closer to π with very little effort.

### Applications

Pi has applications everywhere. In computing with π, typically modern computers cache its pre-computed value in memory since it is a constant. The technique of approximating numbers with convergent infinite series expansions remains essential for computing transcendental and trigonometric functions, i.e., $e^x$ and Arcsin x. Even if you don’t readily have access to an arbitrarily-precise value for π, in an embedded system for instance, you can still use these techniques to compute π yourself. As an exercise, you can even program the recently released Raspberry Pi 3 to compute π, a fitting (if not Herculean) challenge to work off any calories from the pie you’ve eaten to celebrate this once-in-a-century International Pi Day.

### Want more Pi?

Read more about how the Ancient Greeks found π using geometric arguments that foreshadow today’s concept of a limit!

The reasoning I went into is widely portrayed on the Internet to be the approach taken by Archimedes in computing π, although I believe that’s something of a misconception. Archimedes’ actual proof used Euclid’s theorems of bisecting an angle, in a 96-sided polygon. Rather, approximating a circle using polygons with ever-increasing numbers of sides is simply common sense and was probably the Zeitgeist held by the Ancient Greeks, Egyptians, and Babylonians at the time of Archimedes’ breakthrough.