3
$\begingroup$

I'm interested in generating digits of $\pi$ (I'm programming it in Python) and from my research it seems Chudnovsky algorithm is the fastest. Unfortunately for me, the Wikipedia page only really gives a massive equation with lots of symbols.

Edit: What would it look like as an infinite series?

I'm in year 11 so simpler explanations would be appreciated.

  • 0
    There is now a reasonably optimized and correctly working python implementation on the wikipedia page linked above.2016-12-09

1 Answers 1

3

The Chudnovsky series is based on a hypergeometric series, which may be why you think it is expressible as a simple geometric series. However, in general hypergeometric series are not expressible as geometric series.

However, using the expression you've linked to at wikipedia, you can write a trivial implementation in Python:

$\frac{1}{\pi}=12\sum_{k=0}^{\infty}{\frac{(-1)^{k}(6k)!(13591409+545140134k)}{(3k)!(k!)^{3}640320^{3k+3/2}}}$

So we have:

$\pi\approx1/\left(12\sum_{k=0}^{x}{\frac{(-1)^{k}(6k)!(13591409+545140134k)}{(3k)!(k!)^{3}640320^{3k+3/2}}}\right)$

For some large value of $x$. So we can write the following:

# x is the limit of the summation, increase the value of x # for a more accurate approximation. def Chudnovsky(x):     sum = 0     while x >= 0:         sum += (((-1)**x) * factorial(6*x) * (13591409 + 545140134*k))/(factorial(3*k)*(factorial(k)**3) * (640320**(3*x + (3/2))))         x -= 1     sum *= 12     return (1/sum) 

However, bear in mind it's been a while since I've done Python scripting, this script was made just based on documentation I could find on the Python site, so I'm unsure if the syntax/semantics are correct, but the concept is there.

Hope this helps.

  • 0
    @Kartik Yes they do2017-05-04