The Chudnovsky algorithm is a fast method for calculating the digits of π. It was published by the Chudnovsky brothers in 1989, and was used in the world record calculations of 2.7 trillion digits of π in December 2009, 5 trillion digits of π in August 2010, 10 trillion digits of π in October 2011, and 12.1 trillion digits in December 2013. and 22.4 trillion digits of π in November 2016.
The algorithm is based on the negated Heegner number d = −163, the j-function j(1+√−163/2) = −7005640320000000000♠6403203, and on the following rapidly convergent generalized hypergeometric series:
For a high performance iterative implementation, this can be simplified to
There are 3 big integer terms (the multinomial term Mk, the linear term Lk, and the exponential term Xk) that make up the series and π equals the constant C divided by the sum of the series, as below:
Mk+1 = Mk * (12k+2) * (12k+6) * (12k+10) / (k+1)^3 and M0 = 1 [Mk = (6k)! / ((3k)! * (k!)^3)]
Lk+1 = Lk + 545,140,134 and L0 = 13,591,409 [Lk = 13591409 + 545140134*k]
Xk+1 = Xk * -262,537,412,640,768,000 and X0 = 1 [Xk = (-640320)^3k = (-262537412640768000)^k]Mk can be optimized further:
Kk+1 = Kk + 12 and K0 = 6
Mk+1 = Mk * (Kk^3 - 16Kk) / (k+1)^3 and M0 = 1
Note that
This identity is similar to some of Ramanujan's formulas involving π, and is an example of a Ramanujan–Sato series.
Example: Python Implementation
π can be computed to any precision using the above algorithm in any environment which supports arbitrary-precision arithmetic. As an example, here is a Python implementation: