Computing Pi in The Fifth Century

Chronicles of Computation — The Early Mechanisms

Danilo Poccia
Chronicles of Computation
3 min readJun 28, 2023

--

The name Zu Chongzhi stands out in the fifth century as a beacon of innovation and precision. Born in Jiankang, present-day Nanjing, Zu was a polymath who made significant contributions to the fields of astronomy, mathematics, politics, and literature during the Liu Song and Southern Qi dynasties. His family had a rich history of involvement in astronomical research, and from a young age, Zu was exposed to the wonders of the cosmos and the beauty of numbers.

Zu’s most notable achievement was his precise calculation of the mathematical constant pi (π). He calculated π to be between 3.1415926 and 3.1415927, a feat of accuracy that would remain unsurpassed for over 800 years. To achieve this, he used a method of approximating a circle with a 24,576-sided polygon, a process that required meticulous calculations and a deep understanding of geometry.

Photo by Jason An on Unsplash

Zu’s work was not limited to theoretical mathematics. He also made significant contributions to practical engineering. For example, he was responsible for erecting water-powered trip hammer mills, a feat that was inspected and admired by Emperor Wu of Southern Qi. Zu’s innovative spirit also led him to invent the Chinese paddle boats, which revolutionized transportation during the Southern Qi Dynasty.

Zu’s mathematical prowess extended to the realm of astronomy. He distinguished between the sidereal year and the tropical year, calculated the number of overlaps between the sun and the moon, and accurately predicted eclipses. His work in astronomy was so advanced that it left scholars of the Sung dynasty and Indo influence astronomers of the Tang dynasty in awe.

Let’s take a closer look at one of Zu’s most notable achievements: his calculation of π. His method of approximating π was based on the concept of inscribed and circumscribed polygons. He would increase the number of sides of the polygon, and as the number of sides increased, the polygon would more closely resemble a circle. The perimeter of the polygon would then provide an increasingly accurate approximation of the circumference of the circle, and hence π.

Let’s implement this concept in Python. We’ll start with a polygon with 2 sides (a line), and double the number of sides at each step. We’ll calculate the perimeter of the polygon inscribed in a circle with radius 1 (for simplicity), using the formula for the length of a side of the polygon:

side length = 2 sin(180° / number of sides)

Here’s the Python code:

import math

# Calculate the approximation of Pi
def approx_pi(n_sides):
side_length = 2 * math.sin(math.radians(180/n_sides))
return n_sides * side_length / 2

# Start with 2 sides and double the number of sides at each step
n_sides = [2**i for i in range(1, 16)]

# Calculate the approximation of Pi for each number of sides
approximations = [approx_pi(n) for n in n_sides]

# Print the results
for n, approx in zip(n_sides, approximations):
print(f"{n} sides: Pi approximated to {approx}")

Save the previous file as zu_chongzhi_pi.py and run it using Python. When we run this code, we get the following output:

2 sides: Pi approximated to 2.0
4 sides: Pi approximated to 2.82842712474619
8 sides: Pi approximated to 3.0614674589207183
16 sides: Pi approximated to 3.121445152258052
32 sides: Pi approximated to 3.1365484905459393
64 sides: Pi approximated to 3.140331156954753
128 sides: Pi approximated to 3.141277250932773
256 sides: Pi approximated to 3.141513801144301
512 sides: Pi approximated to 3.1415729403670913
1024 sides: Pi approximated to 3.1415877252771596
2048 sides: Pi approximated to 3.1415914215111997
4096 sides: Pi approximated to 3.1415923455701176
8192 sides: Pi approximated to 3.1415925765848725
16384 sides: Pi approximated to 3.1415926343385627
32768 sides: Pi approximated to 3.1415926487769856

As you can see, as the number of sides increases, the approximation of π becomes more accurate, approaching what we now know is the true value of π:

3.141592653589793238…

This demonstrates the power of Zu Chongzhi’s method and gives us a glimpse into the mathematical genius of this ancient scholar.

Zu’s contributions to the field of software engineering are significant. His precise calculations, innovative methods, and practical applications of mathematical principles laid the groundwork for many modern computational techniques.

This story is part of the Chronicles of Computation book. The next section is The Power of Zero.

--

--

Danilo Poccia
Chronicles of Computation

Passioned about IT, IoT, AI, ML, and other acronyms. Writing the Chronicles of Computation book. Chief Evangelist (EMEA) @ AWS. Opinions are my own.