# Liu Hui's π algorithm

Liu Hui's method of calculating the area of a circle

Liu Hui's π algorithm was invented by Liu Hui (fl. 3rd century), a mathematician of Wei Kingdom. Before his time, the ratio of the circumference of a circle to diameter was often taken experimentally as three in China, while Zhang Heng (78–139) rendered it as 3.1724 (from the proportion of the celestial circle to the diameter of the earth, 92/29) or as $\pi \approx \sqrt{10} \approx 3.162$. Liu Hui was not satisfied with this value. He commented that it was too large and overshot the mark. Another mathematician Wan Fan (219–257) provided π ≈ 142/45 ≈ 3.156.[1] All these empirical π values were accurate to two digits (i.e. one decimal place). Liu Hui was the first Chinese mathematician to provide a rigorous algorithm for calculation of π to any accuracy. Liu Hui's own calculation with a 96-gon provided an accuracy of five digits: π ≈ 3.1416.

Liu Hui remarked in his commentary to the The Nine Chapters on the Mathematical Art,[2] that the ratio of the circumference of an inscribed hexagon to the diameter of the circle was three, hence π must be greater than three. He went on to provide a detailed step-by-step description of an iterative algorithm to calculate π to any required accuracy based on bisecting polygons; he calculated π to between 3.141024 and 3.142708 with a 96-gon; he suggested that 3.14 was a good enough approximation, and expressed π as 157/50; he admitted that this number was a bit small. Later he invented an ingenious quick method to improve on it, and obtained π ≈ 3.1416 with only a 96-gon, with an accuracy comparable to that from a 1536-gon. His most important contribution in this area was his simple iterative π algorithm.

## Area of a circle

The area within a circle is equal to the radius multiplied by half the circumference, or A = r x C/2 = r x r x π.

Liu Hui argued:

"Multiply one side of a hexagon by the radius (of its circumcircle), then multiply this by three, to yield the area of a dodecagon; if we cut a hexagon into a dodecagon, multiply its side by its radius, then again multiply by six, we get the area of a 24-gon; the finer we cut, the smaller the loss with respect to the area of circle, thus with further cut after cut, the area of the resulting polygon will coincide and become one with the circle; there will be no loss".

$\lim_{N \to \infty}\text{area of }N\text{-gon} = \text{area of circle}. \,$

Further, Liu Hui proved that the area of a circle is half of its circumference multiplied by its radius. He said:

"Between a polygon and a circle, there is excess radius. Multiply the excess radius by a side of the polygon. The resulting area exceeds the boundary of the circle".

In the diagram d = excess radius. Multiplying d by one side results in oblong ABCD which exceeds the boundary of the circle. If a side of the polygon is small (i.e. there is a very large number of sides), then the excess radius will be small, hence excess area will be small.

As in the diagram, when N → ∞, d → 0, and ABCD → 0.

"Multiply the side of a polygon by its radius, and the area doubles; hence multiply half the circumference by the radius to yield the area of circle".

When N → ∞, half the circumference of the N-gon approaches a semicircle, thus half a circumference of a circle multiplied by its radius equals the area of the circle. Liu Hui did not explain in detail this deduction. However it is self-evident by using Liu Hui's "in-out complement principle" which he provided elsewhere in The Nine Chapters on the Mathematical Art: Cut up a geometric shape into parts, rearrange the parts to form another shape, the area of the two shapes will be identical.

Thus rearranging the six green triangles, three blue triangles and three red triangles into a rectangle with width = 3L, and height R shows that the area of the dodecagon = 3RL.

In general, multiplying half of the circumference of a N-gon by its radius yields the area of a 2N-gon. Liu Hui used this result repetitively in his π algorithm.

## Liu Hui's π inequality

Liu Hui's π inequality

Liu Hui proved an inequality involving π by considering the area of inscribed polygons with N and 2N sides.

In the diagram, the yellow area represents the area of an N-gon, denoted by $A_N$, and the yellow area plus the green area represents the area of a 2N-gon, denoted by $A_{2N}$. Therefore the green area represents the difference between the areas of the 2N-gon and the N-gon:

$D_{2N}=A_{2N}-A_N.$

The red area is equal to the green area, and so is also $D_{2N}$. So

Yellow area + green area + red area = $A_{2N} + D_{2N}.$

Let C represent the area of the circle. Then

$A_{2N} < C < A_{2N} + D_{2N}.$

If the radius of the circle is taken to be 1, then we have Liu Hui's π inequality:

$A_{2N} < \pi < A_{2N} + D_{2N}.$

## Iterative algorithm

Liu Hui's π algorithm

Lui Hui began with an inscribed hexagon. Let M be the length of one side AB of hexagon, r is the radius of circle.

Bisect AB with line OPC, AC becomes one side of dodecagon, let its length be m.

AOP, APC are two right angle triangles. Liu Hui used Gou Gu theorem repetitively:

${} G^2 = r^2 - \left(\tfrac{M}{2}\right)^2$
${}G= \sqrt{r^2- \tfrac{M^2}{4}}$
${} j= r - G = r - \sqrt{r^2- \tfrac{M^2}{4}}$
${}m^2= \left(\tfrac{M}{2}\right)^2 + j^2$
${}m=\sqrt{m^2}.$

With r = 10 units, he obtained

area of 48-gon ${}A_{96} = 313 {584 \over 625}$
area of 96-gon ${}A_{192} = 314 {64 \over 625}$
Difference of 96-gon and 48-gon:
${}D_{192} = 314\frac{64}{625} - 313\frac{584}{625} = \frac{105}{625}$
from Liu Hui's π inequality:
$A_{2N} < C < A_{2N} + D_{2N}.$
Since r = 10, C = $100 \times \pi$
therefore:
${}314\frac{64}{625}<100 \times \pi <314 \frac{64}{625} +\frac{105}{625}$
${}314\frac{64}{625}<100 \times \pi <314 \frac{169}{625}$
${} 3.141024 < \pi < 3.142704.$

He never took π as the average of the lower limit 3.141024 and upper limit 3.142704. Instead he suggested that 3.14 was a good enough approximation for π, and expressed it as a fraction $\tfrac{157}{50}$; he pointed out this number is slightly less than the real thing.

Liu Hui carried out his calculation with rod calculus, and expressed his results with fractions. However, the iterative nature of Liu Hui's π algorithm is quite clear:

$2-m^2 =\sqrt{2+(2-M^2)}\, ,$

in which m is the length of one side of next order polygon bisected from M, then repeat the same calculation, each step required only one addition, one square root extraction.

## Quick method

Calculation of square roots of irrational numbers was not an easy task in the third century with counting rods. Liu Hui discovered a short cut by comparing the area differentials of polygons, and found that the proportion of the difference in area of successive order polygons was approximately 1/4.[4]

Let DN denote the difference in areas of N-gon and (N/2)-gon

$D_N = A_N - A_{N/2}\,$

He found:

$D_{96} \approx \tfrac{1}{4} D_{48}$
$D_{192} \approx \tfrac{1}{4} D_{96}$ 1

Hence:

\begin{align} D_{384} & {} \approx \tfrac{1}{4} D_{192} \\ D_{768} & {} \approx \left(\tfrac{1}{4}\right)^2 D_{192} \\ D_{1536} & {} \approx \left(\tfrac{1}{4}\right)^3 D_{192} \\ D_{3072} & {} \approx \left(\tfrac{1}{4}\right)^4 D_{192} \\ & {} \ \ \vdots \end{align}

Area of unit radius circle =

${}\pi = A_{192} + D_{384} + D_{768}+D_{1536}+D_{3072} + \cdots \approx A_{192} + F \cdot D_{192}. \,$

In which

$F = \tfrac{1}{4} + \left(\tfrac{1}{4}\right)^2 + \left(\tfrac{1}{4}\right)^3 + \left(\tfrac{1}{4}\right)^4 + \cdots = \tfrac{1}{3}.$

That is all the subsequent excess areas add up amount to one third of the $D_{192}$

area of unit circle${}=\pi \approx A_{192} + \left(\tfrac{1}{3}\right)D_{192} \approx {3927 \over 1250} \approx 3.1416.\,$2

Liu Hui was quite happy with this result because he had acquired the same result with the calculation for a 1536-gon, obtaining the area of a 3072-gon. This explains four questions:

1. Why he stopped short at A192 in his presentation of his algorithm. Because he discovered a quick method of improving the accuracy of π, achieving same result of 1536-gon with only 96-gon. After all calculation of square roots was not a simple task with rod calculus. With the quick method, he only needed to perform one more subtraction, one more division (by 3) and one more addition, instead of four more square root extractions.
2. Why he preferred to calculate π through calculation of areas instead of circumferences of successive polygons, because the quick method required information about the difference in areas of successive polygons.
3. Who was the true author of the paragraph containing calculation of $\pi = {3927 \over 1250}.$
4. That famous paragraph began with "A Han dynasty bronze container in the military warehouse of Jin dynasty....". Many scholars, among them Yoshio Mikami and Joseph Needham, believed that the "Han dynasty bronze container" paragraph was the work of Liu Hui and not Zu Chongzhi as other believed, because of the strong correlation of the two methods through area calculation, and because there was not a single word mentioning Zu's 3.1415926 < π < 3.1415927 result obtained through 12288-gon.

## Later developments

Liu Hui established a solid algorithm for calculation of π to any accuracy.

• Zu Chongzhi was familiar with Liu Hui's work, and obtained greater accuracy by applying his algorithm to a 12288-gon.
From Liu Hui's formula for 2N-gon:
$A_{2N} = m_{N} \times r$
For 12288-gon inscribed in a unit radius circle:
$A_{24576}=3.14159261864 < \pi$.
From Liu Hui's π inequality:
$A_{24576} < \pi < A_{24576} +D_{24576}$
In which $D_{24576}=A_{24576}- A_{12288}=0.0000001021$
$A_{24576}=3.14159261864 < \pi <3.14159261864 +0.0000001021$.
Therefore
$3.14159261864 < \pi <3.141592706934$

Truncated to eight significant digits:

$3.1415926 < \pi <3.1415927$.

That was the famous Zu Chongzhi π inequality.

Zu Chongzhi then used the interpolation formula by He Chengtian (何承天, 370-447) and obtained an approximating fraction: $\pi \approx {355 \over 113}$.

However, this π value disappeared in Chinese history for a long period of time (e.g. Song dynasty mathematician Qin Jiushao used π= ${22\over 7}$ and $\pi=\sqrt {10})$), until Yuan dynasty mathematician Zhao Yuqin worked on a variation of Liu Hui's π algorithm, by bisecting an inscribed square and obtained again $\pi \approx {355 \over 113}.$[5]

## Significance of Liu Hui's algorithm

Liu Hui's π algorithm was one of his most important contributions to ancient Chinese mathematics. It was based on calculation of N-gon area, in contrast to the Archimedean algorithm based on polygon circumference. Archimedes used a circumscribed 96-gon to obtain an upper limit $\pi <22/7=3.142857$, and an inscribed 96-gon to obtain the lower limit $223/71=3.140845$. Liu Hui was able to obtain both his upper limit 3.142704 and lower limit 3.141024 with only an inscribed 96-gon. Furthermore, both the Liu Hui limits were tighter than Archimedes's: 3.140845 < 3.141024 < π < 3.142704 < 3.142857. With his method Zu Chongzhi obtained the result: 3.1415926 < π < 3.1415927, which held the world record for the most accurate value of π for 1200 years, even by 1600 in Europe, mathematician Adriaen Anthoniszoom and his son obtained π value of 3.1415929, accurate only to 7 digit, still 3 digits short of Zu's result[6]

## Notes

^1 Correct value: 0.2502009052
^2 Correct values:
$A_{192}= 3.1410319509$
$D_{192}=0.0016817478$
$\pi \approx A_{192}+ \frac{1}{3} D_{192}\approxeq 3.1410319509 +0.0016817478/3$
$\pi \approx 3.1410319509 +0.0005605826$
$\pi \approx 3.1415925335.$

Liu Hui's quick method was potentially able to deliver almost the same result of 12288-gon (3.141592516588) with only 96-gon.

## References

1. ^ Schepler, Herman C. (1950), “The Chronology of Pi”, Mathematics Magazine 23 (3): 165–170, ISSN 0025-570X.
2. ^ Needham, Volume 3, 66.
3. ^ First noted by Japanese mathematician Yoshio Mikami
4. ^ Yoshio Mikami: Ph.D. Dissertation 1932
5. ^ Yoshio Mikami said about the work of Zhao Yu Xin:"The sides and consequently the perimeters of these polygons are successively calculated in such a manner as followed by Liu Hui of old", p136, Development of Mathematics in China and Japan
6. ^ Robert Temple, The Genius of China, a refined value of pi, p144-145, ISBN 1-85375-292-4