# Algorithm of the Week: Algorithm Used for World Record Pi Calculations

Join the DZone community and get the full member experience.

Join For Freethe 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. see more here .

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
**
: 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.

Published at DZone with permission of John Cook, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Comments