Verify the 1/pi generator from Ramanujan up to 1000 digits with Python

Pi Day

Verify Ramanujan’s 1/PI generator from up to 1000 digits with the language of your choice, that was the Programming Challenge announced by O’Reilly OST to celebrate this year’s PI day.

Ramanujan’s generator:

\frac{1}{\pi} = \frac{2 \sqrt 2}{9801} \sum_{k=0}^\infty \frac{(4k)!(1103+26390k)}{(k!)^4 396^{4k}}

I’m afraid I can’t offer pointers about how you can get to this results 🙂 but this is my verification using Python 3.0:

The use of Python simply allow us to take advance of the configurable precision of the Decimal data type. Another possible choice could be the Maple platform that also support an arbitrary precision but Python is just perfect for the task.

You can find the official info of the Decimal data type here. For a few terms of PI check this. If you don’t know who was Ramanujan please don’t postpone a visit to this link.

Hope you like it and Happy Pi Day!

-horatio

NOTE: This post was originally published in my former blog at merthin.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s