π (pi) is the ratio of the circumference of a circle to its diameter.
There are many ways to derive an approximate value for it, some
highly arcane and others less so, but even the simplest approaches
typically require moderately advanced trigonometry and some calculus.
For example, two solutions I learned in school were to do it by
finding the area of a half-circle of radius 1 by integrating √1-x
2, and by finding the arctangent of 1 by integrating 1/(1+x
2)
from 0 to 1. Yet the value of π was known with some accuracy by
the ancient Greeks, who had only rather simple mathematical tools
available; clearly it's possible to do it more simply than the
approaches I just mentioned.
On this page, we'll obtain a reasonably good value for π using nothing more advanced than
Pythagoras's theorem.
The accuracy of the value we obtain will actually be limited by
accumulated floating point errors -- the technique we'll use doesn't
behave particularly well with regard to error control, and so won't
easily produce a highly precise result using ordinary double precision
arithmetic. However, it's sufficiently simple that one could do
the calculations by hand and obtain a moderately accurate result
(though on this page we'll actually use a Perl script for the "heavy
lifting").
Overview of the Method
We define the
perimeter
of a polygon as the sum of the lengths of all of its sides. If we
imagine an ant walking around the perimeter of a circle, and then
walking around the perimeter of a polygon of the same radius, it's
clear that, as the number of sides of the polygon increases, the total
length walked by the ant in going around the polygon will approach the
total length walked in going around the circle. So, we'll just
find the perimeter of a polygon with a very large number of sides.
If
we start with a circle, we can either inscribe a polygon within the
circle, or inscribe the circle within a polygon. We're actually
going to do it both ways; that way we obtain bounds on the perimeter of
the circle: It's at least as long as the interior polygon, and no
longer than the exterior polygon. And when the accumulated errors
finally blow up and the method diverges, we'll know it, because the new
values we obtain will fall outside the range we already established at
previous steps of the process. Finally, we'll use the average of
the "best" two values we obtain as our estimate for π.
In each
approach, we're going to start with a square, then split each side in
half to make an octagon, and then split each side again to make a
16-sided figure, and so forth, finding better and better approximations
to π (until we start to lose accuracy as a result of accumulating
floating point errors).
To do this, we'll need to find a recurrence relation which, given an
n-gon of a particular radius with a particular side length, tells us how long a side will be for an
n+1-gon
of the same radius. Once we've found that, we can apply it
repeatedly to obtain the perimeter of a figure with as many sides as we
like.
Circle Inscribed in a Polygon
In
this section we'll find a formula for the perimeter of a polygon in
which a circle is inscribed. (The polygon's perimeter will be, in
each instance,
longer than the perimeter of the inscribed
circle.) We're going to work exclusively with polygons with power
of 2 sides -- 4, 8, 16, etc. The recurrence formula is easy to
find for this case, and by doubling the number of sides at each step,
we get to polygons with large numbers of sides quickly, which is what
we want.
Figure 1: Circle inscribed in a square:
 | Circle in an octagon:
 | Circle in a 16-gon:
 |
The perimeter of a square which inscribes a circle is easy enough to find (
figure 1): it's just 8 times the radius.
Figure 2: Recurrence relation, inscribed circle:
 |
We'll now assume we have a polygon with
n sides, where the length of one side is
2a, and with radius of the inscribed circle equal to
r. (We make the side length
2a rather than
a to make the diagrams simpler.) The radius,
r, is also the distance from the center of the polygon to the midpoint of each of its sides.
Given those assumptions, we'll now find the length of one side of a polygon which has
2n sides.
Let:
(1)

We're
going to find the values for the new polygon by "cutting off the
points" on the old polygon in order to double the number of sides.
In
figure 2, we show a piece of the polygon, with sides of length
2a
drawn in red, and the new segment we've added when we "cut off the
point" is shown in green. We can identify two right triangles in
the figure, named here by their side lengths:
Triangle
r a (r+c) Triangle
b c (a-b)From Pythagoras's theorem, we then have:
(2a)

(2b)

Multiplying out the square in (2b) and canceling
b2, we have:
(3)

And from (2a) we have:
(4)

Plugging (4) into (3), multiplying out, canceling terms, and multiplying through by -1, we obtain:
(5)

Multiplying through by 1/
(2a) and factoring out
r2 we obtain,
(6)

We
don't really care about the absolute radius; all we're interested in is
the ratio of the length of one side to the radius. Dividing
through by
r, we obtain
(7)

For clarity we define
(
8)

and then (7) becomes
(9)  |
This polygon has
2n sides, and
βr is
half the length of one side. If we let
N=
2n=number of sides, then the perimeter will be
2Nrβ, and the ratio of the perimeter to the diameter, which is our approximate value for π, will be
(10)  |
Incidentally,
since this doesn't depend on the size of the polygons we're using,
we've just shown that π is the same for all circles regardless of their
size.
For a square, we have the following:
(11)

Using the square as a starting point, we can use (
9) to find the value for β for each succeeding figure, where we double the number of sides at each step. Along with (
10)
we can use that to find successively better approximations for π.
We will do that a little later, after we find the equivalent to
(9) for a polygon inscribed in a circle. But first, as a simple
example, we'll work out the values for an octagon by hand.
For the octagon, we start with a square and double the number of sides. So, in (
9) we plug in α=1, and since we have
N=8 for an octagon, we find
(
12)

Polygon Inscribed in a Circle
In
this section, we'll find a formula for the perimeter of a polygon which
is inscribed in a circle. (In each case the perimeter of the
polygon will be
shorter than the perimeter of the circle.) Again, we will be working exclusively with polygons with a power of 2 number of sides.
Figure 3: Square inscribed in a circle:
 | Octagon inscribed in a circle:
 | 16-gon in a circle:
 |
The perimeter of a square inscribed in a circle, as we see from
figure 3 (and Pythagoras's theorem), is
r·4√2.
Figure 4: Recurrence relation, inscribed polygon:
 |
As
in the previous section, we'll now proceed to find a recurrence
relation which, given the radius and length of one side of a polygon,
will tell us the length of one side of a polygon with twice as many
sides. We will again define the length of one side of the "old"
polygon to be
2a, and the length of one side of the "new" polygon to be
2b. The old polygon is assumed to have
n sides, and the new one will have
2n sides. This time, since the polygon is inscribed in the circle, the radius,
r, is the distance from the center to one point. To double the number of sides, we'll
split each side, and insert an extra vertex in the middle of the split side. The splitting operation is shown in
figure 4.
We can identify two distinct right triangles in figure 4. Calling them by the lengths of their sides, they are:
Triangle
c a r Triangle
a (r-c) (2b)From triangle
c,a,r, we have:
(13)

From triangle
a,(r-c),(2b) we have:
(14)

Substituting (13) into (14) we obtain:
(15)

Multiplying out the square and bringing
b2 over onto the left by itself, we have:
(16)

As
above, we're interested in the ratio of the side lengths to the radius
rather than the absolute lengths of the sides, so we will again define
α and β as in equations (
8). Dividing (16) through by
r2, expressing it in terms of α and β, and taking square roots of both sides, we obtain:
(17)  |
As in the previous section, the perimeter of the inscribed polygon with
N sides is
2Nrβ, and our approximate value for π is the perimeter divided by twice the radius, which leads us again back to equation (
10).
For the inscribed square, with
N=4, we have:
(18)

Using the square as a starting point, and using the recurrence relation in (
17),
doubling the number of sides at each step, we can again find
successively better values for π. We will, again, work out the
case of the octagon "by hand" (with a small assist from a calculator
for the square roots). Plugging the value of β for the square
into (17), and then multiplying by
N=8 for the octagon, we have
(19)

Averaging this with the value we obtained above, in equations (
12), for a circle inscribed in an octagon, we obtain the value
3.188
-- not awful for a value which we can obtain with hand calculation, but
we can do much better just iterating a few times, as we'll show in the
next section.
Finding a Better Value Using a Script
We built a small Perl script, which is
here, which iterates, applying equations (
9) and (
17), along with (
10),
to find the ratio of the perimeter to twice the radius for polygons
with increasing numbers of sides. The script runs 20 steps,
doubling the number of sides each time, and then goes back over the
data to find the first step which went "out of bounds". We use
the "interior" polygon approximation for π as a lower bound and the
"exterior" polygon approximation as an upper bound; at each step the
new values for those should lie between the old values, unless
accumulated errors have become so large that the result is not valid.
We've
summarized the results in table 1, below. The algorithm went "out
of bounds" at step 14, when finding the values for polygons with 65,536
sides. It's interesting to note that, since there were only 14
steps (because we're
doubling the number of sides at each
step), it would have been be very tedious but none the less possible to
compute the values in the table entirely by hand.
Table 1: Results of the Perl script:
| Sides | Interior Polygon Value for Pi | Exterior Polygon Value for Pi | Average |
| 4 | 2.82842712474619 | 4 | 3.41421356237309 |
| 8 | 3.06146745892072 | 3.31370849898476 | 3.18758797895274 |
| 16 | 3.12144515225805 | 3.18259787807453 | 3.15202151516629 |
| 32 | 3.13654849054594 | 3.15172490742924 | 3.14413669898759 |
| 64 | 3.14033115695474 | 3.14411838524586 | 3.1422247711003 |
| 128 | 3.14127725093276 | 3.14222362994269 | 3.14175044043772 |
| 256 | 3.14151380114415 | 3.14175036917004 | 3.14163208515709 |
| 512 | 3.14157294036788 | 3.14163208070386 | 3.14160251053587 |
| 1024 | 3.14158772527996 | 3.14160251023713 | 3.14159511775855 |
| 2048 | 3.14159142150464 | 3.14159511763137 | 3.141593269568 |
| 4096 | 3.14159234561108 | 3.14159326953813 | 3.14159280757461 |
| 8192 | 3.141592576545 | 3.1415928080678 | 3.1415926923064 |
| 16384 | 3.14159263346325 | 3.14159268885851 | 3.14159266116088 |
| 32768 | 3.14159265480759 | 3.14159265160561 | 3.1415926532066 |
| 65536 | 3.14159264532122 | 3.14159262180328 | 3.14159263356225 |
|
The last row, which finally went "out of bounds"
due to accumulation of errors, is colored red. Our "best" value
for π, which is the average of the interior and exterior polygon values
on the step before the algorithm "went out of bounds", is
3.1415926532066,
where we have again colored the erroneous digits red. The correct
value, to 11 places, is 3.14159265359. The difference is
3.832e-10. So, our approximation is good to 10 decimal
places, which is about the best we can expect from the double precision
floating point package we were using.
Page
created on 2/20/2008. Table of values corrected, later on 2/20/2008