πculator Help

Welcome to the πculator! This wonderful web-app allows you to approximate π (pi), the ratio of a circle's circumference to its diameter. It also provides the very code it uses so you can try it for yourself.

Quick Usage

Input the number of decimal places to approximate and the number of iterations for the approximation, then select your preferred algorithm for the computation. Voila!

Jargon

Decimal Places

How many digits of π to be approximated. Increasing the value of this number will slow down calculations. Setting this number in the high thousands may cause a timeout, but the option has been provided nonetheless.

Loops

How many iterations to perform when approximating π. Increasing the value of this number will increase the accuracy of the approximation, but as a result, will slow down calculations. Setting this number in the high hundreds may cause a timeout as well.

Algorithm

The mathematical procedure for approximating π. In the πculator, the algorithms are identified by the names of their creators. Some such examples are "Chudnovsky" and "Leibniz".

Dynamic

The πculator is run in "dynamic mode" by clicking the button to the right of the corresponding algorithm button. When run in dynamic mode, the number of loops provided is used as a maximum, and the page continually updates with a more accurate version of π until the desired number of decimal places have been accurately calculated.

As the calculations progress, the πculator shows how much each decimal place has changed from the previous loop. This is represented in the background colour of the individual decimal places. If the background is transparent, the decimal place has not changed, otherwise, the background colour will range from green to red, green being a smaller change, red being a larger change.

Colours corresponding to change in decimal place value: 0123456789

πculator

Decimal Places:Loops:Method:
Messages:Invalid number of decimal places specified. Using default of 50.Invalid number of loops specified. Using default of 10.Invalid method specified. Using default of 6.
3.1415926535897911463887769659103474147790158884889

Code

Implements the Bailey-Borwein-Plouffe algorithm.
$$\pi = \sum\limits_{k=0}^\infty \left(\frac{1}{16^{k}}\left(\frac{4}{8k + 1} - \frac{2}{8k + 4} - \frac{1}{8k+5} - \frac{1}{8k + 6}\right)\right) $$
from decimal import getcontext, Decimal

getcontext().prec = 50 + 2
loops = 10

def pi_method_bailey_borwein_plouffe():
    p1 = Decimal('1')
    p2 = Decimal('2')
    p4 = Decimal('4')
    p5 = Decimal('5')
    p6 = Decimal('6')
    p8 = Decimal('8')
    p1o16 = p1 / Decimal('16')
    answer = Decimal('0')
    for x in xrange(loops):
        x = Decimal(x)
        p8x = p8 * x
        answer += p1o16 ** x * (
            (p4 / (p8x + p1)) -
            (p2 / (p8x + p4)) -
            (p1 / (p8x + p5)) -
            (p1 / (p8x + p6))
        )
    return answer