Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
Do you know what a geometric series is? The Chudnovsky algorithm doesn't give one, so it's not clear what you mean. – Gerry Myerson Aug 8 '12 at 13:08
It isn't a geometric series. What part of the Chudnovsky series do you have trouble understanding? – J. M. Aug 8 '12 at 13:09
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! – rschwieb Aug 8 '12 at 13:13
Perhaps that the 'mathematical constants' link will help you (they have excellent stuff concerning high precision computation of constants and even a software pifast that you may try). – Raymond Manzoni Aug 8 '12 at 13:26
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 for more info). – Joel Cohen Aug 8 '12 at 19:28
up vote 3 down vote accepted

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:


So we have:


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.

share|cite|improve this answer
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. – J. M. Aug 8 '12 at 16:14
@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. – Shaktal Aug 8 '12 at 16:16
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. – J. M. Aug 8 '12 at 16:16
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. – mjqxxxx Aug 8 '12 at 18:14
@Shaktal I understand this isn't optimised but I must say, I can read your python much better than the actual equation. Thanks! – Jonathan Milford Aug 8 '12 at 20:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.