The following algorithm is based on work of Ramanujan and has been used in several world-record calculations of pi.

Initialize a_{0} = 6 − 4 √2 and y_{0} = √2 − 1. Then compute

and

The terms a_{n} form a sequence of approximations to 1/π. The error in each approximation is given by

This says that the number of correct digits roughly *quadruples* after each step. To see this, note that the number of correct decimal places after the *n*th step is the negative of the logarithm base 10 of the error:

[The error term goes to zero so quickly that you cannot (in ordinary precision) compute the error bound and then take logarithms; the exp(−2π 4* ^{n}*) term will underflow to zero for n larger than 3. (See why here.) You have to take the log of the error term directly before evaluating numerically.]

The number of correct digits quadruples at each step because the leading term in the numerator above is 4* ^{n}*.

To give a few specifics, *a*_{1} is accurate to 9 digits, *a*_{2} is accurate to 41 digits, and *a*_{3} is accurate to 171 digits. After 10 steps, *a*_{10} is accurate to over 2.8 million digits.

The algorithm given here was state of the art as of 1989. It was used to set world records in 1986. I don’t know whether it has been used more recently.

According to this page, π has been calculated to 6.4 billion digits. You can beat this record if you can carry out 16 steps of the method described here. *a*_{16} would be accurate to over 11 billion digits.

**Update** (18 April 2012): The algorithm used most recently for world record calculations for pi has been the Chudnovsky algorithm. As of October 2011, the record was over 10 trillion digits.

My head just imploded. :-)

If I’m not mistaken, the number must be verified by at least two algorithms (in addition to being longer than any other) before it can be accepted as a world record.

Fantastic post for pi day (3/14)!

Amazing!

It is way more than 6.4 (American) billion digits. We are now on 10 trillions. http://www.numberworld.org/misc_runs/pi-5t/details.html

I’m curious about the choice of initial conditions.

a0 corresponds to an initial estimate of pi of 2.914… which is correct in 0 decimal places. I realize that the choice of y0 is linked to the choice of a0, but the details of how you might choose a better starting point. I guess, since a single iteration gets you to 9 correct digits, it doesn’t matter too much in practice.

hi, im in high school and enjoy maths so i thought to myself, hey why not learn more about pi so here i am on a forum that hasn’t had a comment in like 3 years.

anyway im interested in learning this algorithm but, since i am in highschool, i have a limited source of study material from the school maths textbook and i can not teach my self this algorithm, so could someone explain it to me?

Livito: I’d start by learning calculus. None of the algorithms for computing pi will make much sense without calculus.

would it be possible for you to give me a brief description on calculus

Livito: You could start here: http://en.wikipedia.org/wiki/Calculus

Nice, stumbled over this cool posting by your today’s tweet.

You mentioned 3 steps give 171 digits accuracy, 4 steps show 694 digits precision in nodejs, see comment of this blog posting:

https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/Pi_day_GatewayScript_use_of_decimal_js_arbitrary_precision_decimal_library?lang=en#threadid=10979cbd-c978-4d57-98d9-829b3e90a352