Calculating pi - how the heck?

OK, so you want to calculate pi to a jillion places. But don’t you run into a significant figures problem?

Pi is defined as a circle’s circumference over its diameter. Even if we go and say the the d. is exactly 5, say, what number do we put in the numerator? We have to actually measure C., because to calculate it we would have to use pi, which is what we want to generate, not use.

So even if we measure C to 100 places, how do we ever claim to calculate pi to 101 places, when we are limited by sig figs?

I realize someone’s probably going to say something like writing an algorithm for it, but how do you write one for a trancendental number? How would you ever know that your 287th digit was really right? You have nothing to compare it to. No patterns have ever emerged to let us simply extrapolate the next digits, so how are we so sure that we have it right to so many digits?

There are several different series that can be used to calculate pi. For example:

pi = 4/1 - 4/3 + 4/5 - 4/7 + …

The more terms in this series that you add up, the closer you get to pi.

OK, that’s a pretty good answer, but how do we know that that series approaches pi? If we don’t know what pi is exactly, then how do we know this is sort of asymptotic to it? There’s probably some calculus sort of answer that I wouldn’t understand fully, but could someone try to dumb it down a little?

Yeah, it does involve calculus, but here it is, in a nutshell:

Start out with:

S[sub]n[/sub] = 1 - x[sup]2[/sup] + x[sup]4[/sup] - x[sup]6[/sup] + … + x[sup]2n[/sup]

add it to:

x[sup]2[/sup]S[sub]n[/sub] = x[sup]2[/sup] - x[sup]4[/sup] + x[sup]6[/sup] - … + x[sup]2n+2[/sup]

a lot of terms cancel, and you wind up with:

S[sub]n/sub = 1 + x[sup]2n+2[/sup],


S[sub]n[/sub] = (1 + x[sup]2n+2[/sup])/(1+x[sup]2[/sup])
So if we want to add up the entire infinite series:

1 - x[sup]2[/sup] + x[sup]4[/sup] - x[sup]6[/sup] +…

we can take the limit as n goes to infinity and find that this sum is:


Integrate both the infinite series and the expression we just found for it, and we get:

tan[sup]-1[/sup]x = x - x[sup]3[/sup]/3 + x[sup]5[/sup]/5 - x[sup]7[/sup] + …

Plug in 1 into this equation and you get

pi/4 = 1 - 1/3 + 1/5 - 1/7 + …

Sorry, I doubt any of this makes sense if you’re not familiar with calculus, but I don’t think there’s any other way of doing it. Anyway, hope it helped some; I can try and explain some of that further, if you like.

The bottom line is, you find a way of representing a (trig, in this example) function as an “infinite polynomial”. Then, since you know you get pi/4 when you plug a certain number into the trig function, you can use the infinite polynomial to calculate pi/4.


I didn’t follow your step:

‘Sn = (1 + x2n+2)/(1+x2)
So if we want to add up the entire infinite series:
1 - x2 + x4 - x6 +…
we can take the limit as n goes to infinity and find that this sum is:

Should your first equation above have been derived as:

Sn = (1 - x2n+2)/(1+x2)?

Why doesn’t the sun come out at night when the light would be more useful? (Pratchett)

Yeah, I kind of brushed over that part. Sorry. What actually happens is this. For that part, x has to be strictly between 1 and -1. If you take any such number and raise it to a higher and higher power, it keeps getting smaller and gets arbitrarily close to 0. In other words, if |x| < 1, then x[sup]2n+2[/sup] goes to 0 as n goes to infinity. Which is why (1+x[sup]2n+2[/sup])/(1+x[sup]2[/sup]) (our expression for the finite sum) goes to 1/(1+x[sup]2[/sup]) (the infinite sum we want) as n goes to infinity. (BTW, it could have been done with 1-x[sup]2n+2[/sup] in the numerator, as well, since x[sup]2n+2[/sup] goes to 0 anyway).

BTW, when we integrate and get the expression we have for tan[sup]-1[/sup]x, we have the added bonus that this new expression DOES work for x=1 (in the above paragraph, we couldn’t have x=1), which is why we can plug in 1 and get the series for pi that we need.

There are several other expressions you can get for pi, too.

A conceptually simpler (and much older) method of calculating pi is to calculate the area of polygons. Pi is the ratio of a circle’s area to its diameter. You can’t calculate a circle’s area without knowing pi, but you can calculate the area of an inscribed polygon (one whose vertices just touch the circle) and a circumscribed polygon (one whose sides just touch the circle). The area of the circle has to lie between those two values. As you increase the number of sides of the polygon the difference in the areas gets smaller and smaller. Theoretically you can thereby calculate pi to whatever precision you like. Aristotle, among others, used this method to come up with approximations to the value of pi.

The methods described above are used because they are much simpler to calculate.

The second part of the OP, asking if there is a significant figures problem, is resolved by using special math routines that have essentially unlimited precision. You could not, of course, calculate pi to a million digits if your number representation scheme allowed only, for example, 20 digits. Rather than using 32-bit or 64-bit binary representations, the routines use arrays of bytes for storage. They are still limited by the number of bytes available in the computer system but in practice they can get to the billion digit range.

There is a very readable book entitled The Story of Pi that details mankind’s use of pi through the ages, including calculation methods and proof that it is transcendental, etc. I don’t recall the author off hand but it is probably in your public library. Enjoy.

“If ignorance were corn flakes, you’d be General Mills.”
Cecil Adams
The Straight Dope

‘pi’ is a great film some guy in it calculates pi to something like 256th place.

Pi is a good film, though a disturbing one. It even managed to get the math right much of the time (once you buy into the mystical/numerological premise), but it pissed me off when the mathematical genius protagonist casually tossed in the line about being sure that the Jewish mystics had already tried pronouncing every conceivable 216 letter “name of God”. That is simply not an error in scale that someone so dedicated to numbers would make.

(There is also the problem of representing 216 leters with a 216 digit sequence in base 10. What, the Hebrew alphabet has suddenly been reduced to ten letters?)

The best lack all conviction
The worst are full of passionate intensity.

One thing that hasn’t been mentioned is, physically, how such calculations are handled after you’ve come up with a formula.

Real-number calculations with PCs using FPUs are limited to something around sixteen decimal digits of precision. This is plenty for most purposes. There’s an AutoCAD drawing floating around containing a 1:1 model of our solar system. It includes the plaque left on the moon by the first moon landing, and the words are legible.

However, sixteen decimal digits just won’t do for calculating pi to gazillions of significant digits. So it’s done in software. There are many ways of doing it, but they’re all variations on one theme.

Pick a small unit of storage and pick your favorite number system. For purposes of illustration, make the storage unit one byte and the number system base 10. Store numbers by storing some encoded version of each digit in each storage unit. Store the magnitude in some convenient manner; let’s say we use a special code to store the radix point. So, if we encode each digit by its binary equivalent and use 1111111 to mean decimal point, the number 10.2 would be stored in four bytes as:

00000001 00000000 11111111 00000010

(actually, such systems always normalize the numbers to avoid the complications of a radix point, but this is clearer to illustrate the concept)

Now you can write programs that add, subtract, multiply, and divide numbers stored in this fashion just as we do on paper; operate on pairs of digits and keep track of whatever carries or borrows are required by the operation you are carrying out.

With this system, the number of significant digits you can calculate are limited only by the available storage space and how long you are willing to wait for a calculation to complete.