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.

  • 4
    Do you know what a geometric series is? The Chudnovsky algorithm doesn't give one, so it's not clear what you mean.2012-08-08
  • 0
    It isn't a geometric series. What part of the Chudnovsky series do you have trouble understanding?2012-08-08
  • 0
    It might be worthwhile to spend time trying to understand the massive equation rather than let it intimidate you! You will also probably be able to find less cryptic descriptions of the algorithm outside of WP. Good luck!2012-08-08
  • 0
    Perhaps that the 'mathematical constants' [link](http://numbers.computation.free.fr/Constants/constants.html) will help you (they have excellent stuff concerning high precision computation of constants and even a software pifast that you may try).2012-08-08
  • 2
    By combining Machin's Formula ($\frac{\pi}{4} = 4 \arctan\left(\frac{1}{5}\right) + \arctan\left(\frac{1}{239}\right)$) and the series expansion of $\arctan$ ($\arctan(x) = \sum_{n = 0}^{\infty} \frac{(-1)^n x^{2n+1}}{2n+1}$), you get a way to compute $\pi$ that is reasonably fast and simple to implement (see http://en.wikipedia.org/wiki/Machin-like_formula for more info).2012-08-08
  • 0
    @user: You had flagged the mods with a request to merge your account with a non-MSE account. I wanted to let you know that is not something mods can do. You must be the one to associate your different accounts and logins (the easiest way is to use the same OpenID).2012-08-12
  • 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
    For purposes of efficiency, one might consider generating the factorial portions of the series through multiplicative updates; e.g. for the $k!^3$ term, start with $1$ and multiply with $k^3$ at each iteration.2012-08-08
  • 0
    @J.M. I completely disregarded efficiency in this example, because it seemed to me that the OP was having trouble understanding the series notation etc. So I focused on having simple to a simple-to-read script.2012-08-08
  • 0
    Also, conventionally, one starts from the $k=1$ term, and goes on summing up until the ratio of the $k$-th term to the corresponding partial sum is less than, say, machine epsilon.2012-08-08
  • 1
    The sum needs to start at $k=0$, and the $k=0$ term already yields $\pi \approx 3.1415926535897345$, i.e., about $12$ significant figures.2012-08-08
  • 0
    @Shaktal I understand this isn't optimised but I must say, I can read your python much better than the actual equation. Thanks!2012-08-08
  • 0
    `-=` and `+=` dont work in python2014-12-26
  • 0
    @Kartik Yes they do2017-05-04