Iterative Series for π

Archemedes effectively invented an iterative series for π when he consider a hexagon inscribed in a circle (i.e. having its vertices on a circle and therefore lying entirely inside it) and a larger one circumscribed on the same circle (i.e. having the centres of its edges on a circle, and therefore lying entirely outside the circle). If the circle has unit diameter, so a circumference of π, the sum of the lengths of the sides of the inscribed hexagon, which is clearly less than the circle's circumference, is three. The sum of the lengths of the sides of the circumscribed hexagon is clearly greater than the cicumference, and is 2√3=3.464.

Not very impressive, but Archimedes worked out how to double the number of edges of both hexagons, and then double again, and again, until he had 96-sided polygons. At this point he managed to show that

223/71 < π < 22/7

pi approximations for polygons of 3, 6 and 12 sides

Archimedes did not know decimals, and had to use fractional approximations for √3. Today we can express his method as

a0=2√3; b0=3
ak+1=2akbk/(ak+bk)
bk+1=√(ak+1bk)

Both a and b converge to π, a remaining greater than π and b remaining less than π. Two iterations are sufficient to add more than an extra decimal digit of accuracy.

 0: 3.0000000000 < pi < 3.4641016151
 1: 3.1058285412 < pi < 3.2153903092
 2: 3.1326286133 < pi < 3.1596599421
 3: 3.1393502030 < pi < 3.1460862151
 4: 3.1410319509 < pi < 3.1427145996
 5: 3.1414524723 < pi < 3.1418730500
 6: 3.1415576079 < pi < 3.1416627471
 7: 3.1415838921 < pi < 3.1416101766
 8: 3.1415904632 < pi < 3.1415970343
 9: 3.1415921060 < pi < 3.1415937488
10: 3.1415925167 < pi < 3.1415929274

iter_Arch.py

This sequence uses hexagons at iteration zero, then dodecagons (12 sides) for iteration 1, then 24 sides, 48 sides, 96 sides, etc. One can start with other polygons. Setting a0=4 and b0=2√2 would use squares, then octagons, then 16 sides, etc.

An advantage of this method is that it does not simply give an approximation, but lower and upper bounds. The uncertainty is immediately obvious.

Liu Hui

Archimedes' work dates from around 250BC. Around 500 years later the Chinese mathematician Liu Hui obtained approximations to π by considering the areas, not perimeters, of polygons inscribed in circles. Like Archimedes, he started with a hexagon. And like Archimedes, he was able to produce lower and upper bounds. His basic method is:

x0=1
xn+1=√(2 - √(4-xn2))
An=3*2n-1*xn-1

and

An < π < 2An - An-1

iter_LH.py

 1: 3.0000000000 < pi < 4.7009618943
 2: 3.1058285412 < pi < 3.2116570825
 3: 3.1326286133 < pi < 3.1594286853
 4: 3.1393502030 < pi < 3.1460717928
 5: 3.1410319509 < pi < 3.1427136987
 6: 3.1414524723 < pi < 3.1418729937
 7: 3.1415576079 < pi < 3.1416627435
 8: 3.1415838921 < pi < 3.1416101764
 9: 3.1415904632 < pi < 3.1415970343
10: 3.1415921060 < pi < 3.1415937488

The convergence is very similar to Archimedes' method, except that Liu Hui also produced a way of estimating the best value of π within the range calculated.

π =(4An - An-1)/3

 1: 3.0000000000 < pi = 3.5669872981 < 4.7009618943
 2: 3.1058285412 < pi = 3.1411047216 < 3.2116570825
 3: 3.1326286133 < pi = 3.1415619706 < 3.1594286853
 4: 3.1393502030 < pi = 3.1415907330 < 3.1460717928
 5: 3.1410319509 < pi = 3.1415925335 < 3.1427136987
 6: 3.1414524723 < pi = 3.1415926461 < 3.1418729937
 7: 3.1415576079 < pi = 3.1415926531 < 3.1416627435
 8: 3.1415838921 < pi = 3.1415926536 < 3.1416101764
 9: 3.1415904632 < pi = 3.1415926536 < 3.1415970343
10: 3.1415921060 < pi = 3.1415926536 < 3.1415937488

Further notes on Liu Hui's method.

Brent–Salamin

The Australian mathematician Richard Brent and the American mathematician Eugene Salamin independently discovered the following algorithm, both in 1975:

a0=1; b0=1/√2; t0=1/4
ak+1=(ak+bk)/2
bk+1=√(akbk)
tk+1=tk-2k(ak+1-ak)2

Then π can be approximated as

π=(ak+bk)2/(4k)

This recipe, which can be expressed in other slightly different but algebraically-identical forms, is heavily based on work by the eighteenth century mathematicians Gauss and Legendre, so it is sometimes called the Gauss–Legendre algorithm.

The convergence of this algorithm is particularly impressive. Each iteration does not add a constant number of correct digits, but rather it doubles the number of correct digits. In 2009 it was used to calculate π to a then-record number of digits, just over 2.5x1012.

 0: 2.91421356237309
 1: 3.14057925052217
 2: 3.14159264621354
 3: 3.14159265358979
 4: 3.14159265358979
 5: 3.14159265358979
 6: 3.14159265358979

iter_GL.py

High Precision

More precision would help to show the rapid convergence, so, using the gmp2 module in python

 0: 2.9142135623730950488016887242096980785696718753769480731766797379907316
 1: 3.140579250522168248311331268975823311773440237512948335643486693345583
 2: 3.1415926462135422821493444319826957743144372233456027945595394848214367
 3: 3.1415926535897932382795127748018639743812255048354469357873307020263851
 4: 3.1415926535897932384626433832795028841971146782836489215566171069760267
 5: 3.1415926535897932384626433832795028841971693993751058209749445923078216
 6: 3.1415926535897932384626433832795028841971693993751058209749445923078216

iter_GL_MP.py

One can easily adjust this code. Ten iterations should produce a thousand digits of π.