Note
Go to the end to download the full example code.
Archimedes’ method of exhaustion: squeezing pi#
Doubles the sides of inscribed and circumscribed regular polygons from 6 to 96, reproducing Archimedes’ bounds 3 10/71 < pi < 3 1/7, and shows that the gap shrinks by a factor of four with each doubling.
import math
import matplotlib.pyplot as plt
from mathematicskit.calculus import archimedes_pi_bounds
The 96-gon bounds#
result = archimedes_pi_bounds(4)
for n, lo, hi in zip(result.sides, result.lower, result.upper):
print(f"{n:3d} sides: {lo:.6f} < pi < {hi:.6f}")
print(f"Archimedes: {3 + 10 / 71:.6f} < pi < {3 + 1 / 7:.6f}")
6 sides: 3.000000 < pi < 3.464102
12 sides: 3.105829 < pi < 3.215390
24 sides: 3.132629 < pi < 3.159660
48 sides: 3.139350 < pi < 3.146086
96 sides: 3.141032 < pi < 3.142715
Archimedes: 3.140845 < pi < 3.142857
Convergence of the gap#
result = archimedes_pi_bounds(15)
gaps = [hi - lo for lo, hi in zip(result.lower, result.upper)]
fig, ax = plt.subplots()
ax.loglog(result.sides, gaps, "o-", label="upper - lower")
ax.loglog(result.sides, [gaps[0] * (6 / n) ** 2 for n in result.sides], "--", label=r"$\propto n^{-2}$")
ax.axhline(abs(math.pi - 22 / 7), color="0.6", lw=0.8)
ax.set_xlabel("polygon sides n")
ax.set_ylabel("width of the bracket on pi")
ax.legend()
ax.set_title("Each doubling cuts the gap by 4")

Text(0.5, 1.0, 'Each doubling cuts the gap by 4')
Total running time of the script: (0 minutes 0.047 seconds)