# π GPS (Greater Precision Solutions)

In my previous blog post π Places, I reviewed special fractions that were very good approximations to the value of π to 2 and 6 decimal places: i.e. 22/7 and 355/113 respectively.

In this post, I would like to explore the more modern (since 1593) approximations based on infinite series.

Note: If the mathematics shown creates immediate “eye-glaze”, please skip to the Activities section, which is much more entertaining in comparison.

A Series sums up a finite or infinite collection of terms of a Sequence. If finite, there are a definite, bounded number of values that add up to a specific, measurable value. If infinite, there are an endless, unbounded number of values that add up to either a specific, measurable value (converge), or add up to an indefinite, unmeasurable value (diverge), which is denoted as infinity ().

Here are two examples of each:

#### Finite Series

##### First 10 Natural Numbers sum

1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = sum_(n=1)^10 n=(10(10+1))/2=55     [1]

##### π expansion to 7 decimal places:

3 + 1/10 + 4/10^2 + 1/10^3 + 5/10^4 + 9/10^5 + 2/10^6 + 6/10^7 = 3.1415926                 [2]

#### Infinite Series (Convergent)

##### π decimal expansion:

3 + 1/10 + 4/10^2 + 1/10^3 + 5/10^4 + 9/10^5 + 2/10^6 + 6/10^7 + … =  π                      [3]

##### Geometric Series:

1 + 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + … + 1/2^(n-1) + … = sum_(n=1)^oo 1/2^(n-1)=2            [4]

#### Infinite Series (Divergent)

##### Natural Number Series:

1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + … = sum_(n=1)^oo n=oo                        [5]

##### Harmonic Series:

1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + … + 1/n + … = sum_(n=1)^oo 1/n=oo                 [6]

For those interested in mathematically (in)finite series, look at the following
List of Mathematical Series. Summed general expressions are given for series organized by sums of powers, power series, binomial coefficients, trigonometric and rational functions. At the top, there are subscripted letters and Greek letter functions (such a necessary annoyance) that are separately named and linked.

### Greater Decimal Places Approximators

Over the years, many mathematicians have tried to evaluate a finite number of terms in an infinite series to approximate π.

• Francois Viete in 1593, using an infinite product, calculated π to 9 decimal digits, by applying the Archimedes method of exhaustion to a polygon with bb 6 × 2^16 = 393216 sides and calculating the circumference (perimeter) when the diameter is 1. π =
2/[sqrt(1/2)*(sqrt[1/2+(1/2)*sqrt(1/2)])*(sqrt[1/2+(1/2)*sqrt{1/2+(1/2)*sqrt{1/2}]))*… [7]

Quite the eye-roller! Alternatively, this looks slightly less volatile, but is equivalent:

π ~~ 2^k*sqrt(2–sqrt(2+sqrt(2+sqrt(2+sqrt(2+sqrt(2+sqrt(2+…))))))) ~~ 3.14157294   [8]

• James Gregory in 1671 published the arctangent (arctan) infinite series expansion and Gottfried W. Leibniz in 1682 published the specific case with x = 1 and based on

arctangent(1) = pi/4                [9]
Expanding this via the infinite series for arctangent(x), where bb | x | ≤ 1, we get:

arctangent(x)= x – x^3/3 + x^5/5 – x^7/7 + … = sum_(n=0)^oo (-1)^n*(x^(2n+1))/(2n+1)                [10]
• John Machin in 1706, using arctangent and the Gregory-Leibniz Infinite Series expansion for arctangent, as shown below, calculated it to 100 decimal digits.

π = 4∙[4∙arctangent(1/5) + arctangent(1/239)]                 [11]
π =                                                                                                 [12]
4*{ 4*[ 1/5 – 1/(3*5^3) + 1/(5*5^5) – 1/(7*5^7)+… ] + [ 1/239 – 1/(3*239^3) + 1/(5*239^5) – 1/(7*239^7)+… ] }
• Srinivasa Ramanujan, was a renowned Indian mathematician who made novel contributions to mathematics and to determining π during his short life (1887-1920). The first formula below gives π to 11 decimal places.

π = root(4)[81+(19^2/22)] = 3.14159265262                        [13]
The following iterative formula was due to Jonathan and Peter Borwein based on Ramanujan’s formulas:

π = [9801/(2*sqrt(2))]*[1/(sum_(n=0)^oo {([(4n)!]/(n!)^4)*[(1103 + 26390n)/(4*99)^(4n)]}]]        [14]
Ramanujan’s integration formula for π is also quite innovative:

(pi/2)^3 = int_0^oo [(log x)^2/(1+x^2)]dx        [15]
which can easily be solved for π.
• David and Gregory Chudnovsky in 1989 in New York City, created their own supercomputer (named m zero) to compute 1 billion decimal places of π from their home. It operated at 100 billion calculations per minute for almost a week.
In 1997, they moved to Polytechnic Institute of Brooklyn (my Alma Mater and now part of New York University), creating the Institute for Mathematics and Advanced Supercomputing. By then, their computer worked for a week (with a better algorithm) to compute up to 8 billion decimal places for π.

Their π calculation is based on:

1/pi = 12*sum_(n=0)^oo (-1)^n*{([(6n)!]/[(n!)^3*(3n)!])*[(13591409 + 545140134n)/(640320^(3n+3/2))]}  [16]
• Yasumasa Kanada holds the 2002 record for bb 1.2411 × 10^12 decimal places for π. His computer programs (written in Fortran and C) were based on K. Takano’s 1982 arctangent formula [17] below and ran on a Hitachi SR8000/MPP with 144 nodes. The computations were carried out in hexadecimal (base 16) arithmetic and converted at the end to decimal for maximal efficiency. Further details about the computation are found on Yasumasa Kanada 2002 π Summary Page.

π ~~                               [17]
48*arctan(1/49) +128*arctan(1/57) – 20*arctan (1/239) + 48*arctan(1/110443)
This took 400 hours (hexadecimal computing) + bb 23 1/3 hours (conversion).
It was verified with F.C.M. Stoemer’s 1896 arctangent formula:

π ~~                               [18]
176*arctan(1/57) +28*arctan(1/239) – 48*arctan (1/682) + 96*arctan(1/12943)
The verification formula [18] took 157.067 hours (hexadecimal computing) + 21.53 hours (conversion) to evaluate and compare.
• As of October 8, 2014, an anonymous mathematician named “houkouonchi” completed computing and verifying π to a total of bb 1.33 × 10^13 decimal places using the Chudnovsky formula [16]. It took his program 208 days to compute and 182 hours to verify on an 2 x Xeon E5-4650L @ 2.6 GHz. See:
Validation of π computation.

## π Activities To Try:

#### Entertaining Websites:

Within the mathisfun.com website, there is an activity to guide you to find the approximate value of π. Look at π approximation

Many people are emotionally attached to the numbers in their life. Their social security number (e.g. 423456789), their birthday (02022015), their 7-digit telephone number (3234777).

There is a great website, called the Pi Search Page that lets you enter your special number and it reports where, in the 200 million decimal places of π that it is located, how many times it shows up (including not at all) and how long it took to search (typically in bb 1/5 of a second).

Go to π Search Page and interact with it.

[Updated to add:] To see 10,000, 100,000 or 1 million digits of bb pi in all their glory in a downloaded file, a related site called digits of Pi; lets you view 10,000 places or access the download links.

Note that the probability that your birthday number string (8 digits long) will be embedded in the first 200 Million decimal places of π is equal to bb (1 – 1/e^2) which is just below 86.47%.

There is a World Ranking List of people who have memorized some number of digits of π and recited them. Please view π World Ranking List

• Blatner, David (1997). The Joy of π . London, UK. Walker/Bloomsbury Books.The website Joy of π has a set of links to many π oriented pages including: π mysteries, music and π, memorizing π digits, having fun and enjoying weird aspects of π.

David Blatner wrote about the statistical distribution of digits in the first million decimal places of π which are comprised of:
 99959  0's 99758  1's 100026 2's 100229 3's 100230 4's 100359 5's 99548  6's 99800  7's 99985  8's 100106 9's 
For these data, I computed the following statistics: the mean (average) is 100000; the median (middle) is 100005.5; the standard deviation is 247.41 and the range of the data is 811, with the digit 5 being most frequent and the digit 6 being least frequent.

• Beckmann, Petr (1971). A History of π (pi). New York, NY. St. Martin’s PressThis impressive source book traces the history of the constant and of the mathematicians that sought greater and greater π precision. There are many illustrations of artifacts and notations used to demonstrate the mathematics involved.

This completes the technical and non-technical tour of π. Please let me know if I’ve missed anything that could be further explored.

# π Places

π (say ‘pie’) is the lower case Greek letter symbol that stands for a number defined as the ratio of the circumference (C) of a circle divided by its diameter (d).

Circumference means the distance around something, like a circle or a polygon. A synonym would be perimeter.

A diameter is the length of a line that is drawn starting from any point on the circle’s boundary and going through the center point of the circle and then continuing to the opposite boundary point. A radius (r) is the length of a line drawn from the center to any point on the circle’s boundary. It is half the diameter. It’s clearer in the diagram:

As a formula (no numbers, please), we write:

pi = C/d                                                   [1]

If d = 1 inch, then because π has a fixed, constant value, C must be equal to that value of π inches.

A closely related formula involving π involves the Area A, of a Circle and its radius r, (remember? – half of the diameter’s length). The formula is:

pi = A/r^2                                                   [2]

Most descriptions of π state when it was first historically used and trace a series of numerical refinements in its approximated value over the last 4500 years.

A chronology of the computation of π from 2500 BC (calculated as 22/7 ) to the present is shown in the following link: π Chronology

It shows the date, the person, milestone or event and the decimal value of π (or the correct number of decimal digits after 3.) up through October 8, 2014, when π had been computed and verified (anonymously) to 1.33∙10^13 (over 13 Trillion) decimal digits.

## Classifications

It turns out that π is an irrational number. (Johann Heinrich Lambert proved this in 1761.)

This means that we cannot discover a fraction that provides its value exactly. Writing its decimal digits never ends. So over the years, mathematicians have labored to compute π accurately to more and more decimal places using “good” fractions and infinite series where only the first “few” terms are evaluated and summed.

It is also true the π is a transcendental number. A transcendental number is an irrational number that is not an algebraic number. An algebraic number is one that satisfies a polynomial equation with a finite number of terms and with rational coefficients. So, for example, sqrt(2) is an irrational (non-repeating decimal number) and an algebraic number, since it is a solution to the algebraic equation: x^2 = 2

For non-algebraic equations, we have two equations from trigonometry, which use pi/4 radians rather than 45 degrees:

tangent(pi/4) = 1                                                  [3]

and particularly its counterpart:

arctangent(1) = pi/4                                                [4]

is used as a starting point for determining π more precisely.

## Rational (Fractional) Approximations

Methods of approximation started with Archimedes, who, around 250 BC, applied the method of exhaustion with inscribed and circumscribed regular polygons to enclose the lower and upper bounds of area and circumference of the circle. Shown below are inscribed and circumscribed pentagons, hexagons and octagons (n = 5, 6, 8). Starting with a hexagon, he doubled the sides for inner and outer n-gons until n = 96, finding the inner and outer perimeters at each value of n.

Archimedes found bounds for π as:

3 + 10/71 < pi < 3 + 10/70      or      223/71 < pi < 22/7                   [5]

This gives the value of π to 2 decimal places, as 3.14.

### A Cool Procedure And Shell Script For a better Fraction for π

Using the circumference formula [1], we can create a procedure based on one suggested by Rhett Allain (See:
Best Fraction For π to calculate a fraction that represents π for a given number of digits.

For reference, suppose πref is set to 3.14159265358979, which is to 14 decimal places. We use this 12 step procedure:

1. Set πref = 3.14159265358979
2. Set (1/πref) = 0.31830988618379
3. Set loopcount = 500
4. Set C = 22
5. Set D = 7
6. Set Percentage Error = 0.001
7. Is loopcount = 0 ?
Then output BestC, BestD, BestC/BestD, Error, BestLoop
and stop

8. Set πest = C/D
9. Calculate Absolute Value of E = | (πref – πest) / πref |
via E = | (πref – πest) ∙ (1/πref) |
10. Is E < Error ?
Then set BestC = C, set BestD=D, set Error = E,
and set Bestloop = 500 – loopcount

11. Is πest < πref ?
Then add 1 to C and go to step 12
Otherwise add 1 to D and go to step 12

12. Subtract 1 from loopcount and go back to step 7 and compute new πest

Here is the bash shell script that I wrote to program this algorithm. It takes slightly under 7.5 seconds (what’s your hurry?) to finish 500 iterations (on a 2010 vintage 32-bit MacBook Pro) and 3.55 seconds on a 64-bit GNU/Linux Server.

The script successfully finds the fraction

355/113 = 3.141592920353982                                              [6]

a close approximation to the reference π that is accurate to 6 decimal places. The percentage error using this fraction is 0.0000084913679%

In this script, the Linux utility bc is needed to offer/preserve 15 decimal place precision in the computations it performs. The shell facilities for operating with numbers using anything other than positive integers are minimal.


#! /bin/bash
USAGE="Usage: pifraction.bash"
# Version 1.0 by arkay on 1/17/2015
# Version 1.1 by arkay on 1/18/2015
#   Computed (1/Pi_ref) once and used it to multiply for
#   % difference.

# Set Starting values for variables
Pi_ref="3.14159265358979"
Pi_ref_inv="0.31830988618379"
loopcount=500
C=22
D=7
Error="0.001"
# loop 500 times
until (( loopcount < 1 ))
do
# Calculate Pi.est
Pi_est=$(echo "scale=15;$C/$D" | bc -l) # Calculate the percentage error E E=$(echo "scale=15; ($Pi_ref -$Pi_est)*$Pi_ref_inv" | bc -l) if [ "${E%%[0-9.]*}" == "-" ]  #Apply Absolute Value:
# extract first character of E, either "–" or ""
then
E=$(echo "scale=15; (-1)*$E" | bc -l)
fi
# Compare E with current minimum % Error
T=$( echo "scale=15;$E<$Error" | bc -l ) if [ "$T" -eq "1" ] # bc returns 1 if inequality true
then
BestC=$C; BestD=$D; Error=$E; BestLoop=$(expr 500 - $loopcount) fi # Compare Pi_est with Pi_ref S=$( echo "scale=15; $Pi_est<$Pi_ref" | bc -l )
if [ "$S" -eq "1" ] # bc returns 1 if inequality true then (( C += 1)) else (( D += 1)) fi (( loopcount -= 1 )) done # Produce the results BestCoverD=$(echo "scale=15; $BestC/$BestD" | bc -l)
echo "BestC=$BestC BestD=$BestD BestCoverD=$BestCoverD" echo "Pi_ref=$Pi_ref  Error=$Error BestLoop=$BestLoop"
exit   # Normal stopping point

# End of pifraction.bash



Output results from this shell script are shown as:
BestC=355 BestD=113 BestCoverD=3.141592920353982
Pi_ref=3.14159265358979 Error=.000000084913679 BestLoop=439

In my next post about π, I will write about greater decimal place approximators and Interesting π activities to try.

Oh, one last thing…
This is a delightful Math Trick attributed to Martin Gardner:

Write all 26 letters of the alphabet, but start with the letter J as shown:

JKLMNOPQRSTUVWXYZABCDEFGHI

Then, remove all the letters that have vertical symmetry as shown:

JKL   N   PQRS              Z   BCDEFG

Now, count the letters that remain in each subset: 3 1 4 1 6.