Happy Pi Day!

To celebrate Pi Day, I wrote a Python program for my Raspberry Pi. It’s a simple demonstration of Archimedes’s method for calculating upper and lower bounds on Pi. Of course, there are much faster ways to calculate Pi now, but Archimedes’s method is visual and easy to understand.

Download the python program here: piday-inscribed-circles.py (Works well on any version of Windows or Linux with python 2.7 or newer and pyqt4. The Raspberry Pi is optional, but it adds to the pun, and thus the fun.)

Here’s an overview of the program: you can inscribe a hexagon and also circumscribe a hexagon around a circle. If the circle has a radius of 2, then the perimeter of the hexagons provide lower and upper bounds on Pi, respectively:


Increasing to 10 sides (decagon) improves the bounds:


Pushing it to the limit of N=100,000,000 sided n-gons, the bounds on Pi reach the limits of double precision floating point numbers (about 16 digits of Pi):


This method isn’t efficient because the regular n-gons are not a very tight boundary on the circle. Other mathematicians proved that even billions of sides in an n-gon provide a worse boundary than simpler arctangent-based series. Of course, Wikipedia has the whole story here.

Maybe next year I’ll have time to combine the puns with Monty Python: a Monte Carlo simulation for calculating Pi, written in Python, running on a Raspberry Pi, drawing part of a Monty Python cartoon.

Anyway, eat some pie and have a happy Pi Day!