《孫子算經卷中》 "Sun Tzŭ's Computational Classic: Volume II"
§19. Rod calculus square root: \sqrt{234567}

This section gives a worked example of the rod calculus square root algorithm.

In my opinion this is by far the most sophisticated piece of mathematics in the entirety of Sun Tzŭ's Computational Classic, which is why I have provided a fully annotated and diagrammed walkthrough, along with a pseudocode summary in the Extended commentary.

Translation

Chinese source text: Version A, Version B, Version C, Version D.
Unless noted otherwise, I follow the text from Version D, 《知不足齋叢書》本.

Source text Target text Notes
今有積二十三萬四千五百六十七步。問為方幾何。 Suppose there be area twenty-three myriad four thousand five hundred [and] sixty-seven paces. [We] ask, how much be [this a] square [of edge]?
答曰、四百八十四步九百六十八分步之三百一十一。 Answer saith: four hundred [and] eighty-four paces [and] three hundred [and] eleven nine hundred [and] sixty-eighths of [a] pace.
  • Here we have an algorithm for computing the square root, in this instance giving
    \sqrt{234567 \unit{paces}^2} \approx 484 \tfrac{311}{968} \unit{paces}.
術曰、置積二十三萬四千五百六十七步為 Method saith: put [down the] area twenty-three myriad four thousand five hundred [and] sixty-seven paces as [the] dividend.
  • The radicand is called the dividend (),
    \colb{d} := \colb{234567}.
    Diagram: There is one row, the dividend 234567.
借一算為下法步之、超一位、至百而止 Next borrow one rod [to] be [the] lower divisor. Step it [forth], leaping over one place, halting [when] arriving at [the] hundreds.
  • 超: leaping over

    Taking double steps, so that 100 is in fact 10000.

  • Since the number of digits of the radicand is
    N := \lfloor \log_{10} d \rfloor + 1 = 6,
    the number of digits of the integer part of its square root is
    n := \left\lceil \frac{N}{2} \right\rceil = 3.
    We then take n - 1 = 2 double steps for the lower divisor (下法)
    \colr{L} := (10 ^ {n - 1}) ^ 2 = \colr{10^4}.
    Diagram: There are now two rows, the dividend 234567 and the lower divisor 10000.
上商置四百於實之上。 [For the] upper quotient, put four hundred above [the] dividend.
  • Version A and Version C have just for 上商.
  • 上商: upper quotient

    The integer part of the square root to be computed.

  • The hundreds digit of the upper quotient (上商) is the largest \colg{a_1} such that \colg{a_1}^2 \colr{L} \le \colb{d}, or
    \colr{10000} \colg{a_1}^2 \le \colb{234567},
    i.e.
    \colg{a_1} := \colg{4}.
    Diagram: There are now three rows: the upper quotient 400, the dividend 234567, and the lower divisor 10000.
置四萬於實之下、下法之上、名為方法 Subsidiarily put four myriad below [the] dividend, [and] above [the] lower divisor, [its] name being [the] upright divisor.
  • 方: upright; or square

    This is one of three named divisors whose names relate to integrity (or to geometry, depending on how you want to render it):

    • 方法: upright divisor (or square divisor), s_1
    • 廉法: incorrupt divisor (or side divisor), s_2
    • 隅法: moral divisor (or corner divisor), s_3

    These shall henceforth be referred to as the straight divisors.

  • The first straight divisor is the upright divisor (方法)
    \colv{s_1} := \colg{a_1} \colr{L} = \colg{4} \times \colr{10000} = \colv{40000}.
    Diagram: There are now four rows: the upper quotient 400, the dividend 234567, the upright divisor 40000, and the lower divisor 10000.
命上商四百除實 Name [the] upper quotient's four hundred [and] remove [this] from [the] dividend.
  • As written, the text says \colb{d} := \colb{d} - \colg{400^2}, but for the purpose of understanding how this step fits in with the others, this is best written
    \begin{aligned} \colb{d} &:= \colb{d} - \colg{a_1} \colv{s_1} \\ &= \colb{234567} - \colg{4} \times \colv{40000} \\ &= \colb{74567}. \end{aligned}
    Diagram: The four rows are now: the upper quotient 400, the dividend 74567, the upright divisor 40000, and the lower divisor 10000.
除訖、倍方法 [The] removal finished, double [the] upright divisor.
  • In modern notation:
    \colv{s_1} := 2 s_1 = 2 \times 40000 = \colv{80000}.
    Diagram: The four rows are now: the upper quotient 400, the dividend 74567, the upright divisor 80000, and the lower divisor 10000.
方法一退下法再退 [The] upright divisor retreateth once; [the] lower divisor retreateth twice.
  • Version A and Version C are missing 方法 in 方法一退.
  • 再: twice; or again
  • In modern notation:
    \begin{aligned} \colv{s_1} &:= s_1 / 10 = 80000 / 10 = \colv{8000} \\ \colr{L} &:= L / 10^2 = 10000 / 100 = \colr{100}. \end{aligned}
    Diagram: The four rows are now: the upper quotient 400, the dividend 74567, the upright divisor 8000, and the lower divisor 100.
置上商八十、以次前商。 Put again [for the] upper quotient eighty, to [be] next [after the] former quotient.
  • The tens digit of the upper quotient (上商) is the largest \colg{a_2} such that \colg{a_2} (\colv{s_1} + \colg{a_2} \colr{L}) \le \colb{d}, or
    \colg{a_2} (\colv{8000} + \colr{100} \colg{a_2}) \le \colb{74567},
    i.e.
    \colg{a_2} := \colg{8}.
    Diagram: The four rows are now: the upper quotient 480, the dividend 74567, the upright divisor 8000, and the lower divisor 100.
置八百於方法之下、下法之上、名為廉法 Subsidiarily put eight hundred below [the] upright divisor, [and] above [the] lower divisor, [its] name being [the] incorrupt divisor.
  • 廉法: incorrupt; or side
  • The second straight divisor is the incorrupt divisor (廉法)
    \colv{s_2} := \colg{a_2} \colr{L} = \colg{8} \times \colr{100} = \colv{800}.
    Diagram: There are now five rows: the upper quotient 480, the dividend 74567, the upright divisor 8000, the incorrupt divisor 800, and the lower divisor 100.
方廉各命上商八十、以除實 Each of [the] upright [and the] incorrupt nameth [the] upper quotient's eighty, to remove from [the] dividend.
  • Version A and Version C are missing .
  • In modern notation:
    \begin{aligned} \colb{d} &:= \colb{d} - \colg{a_2} \colv{(s_1 + s_2)} \\ &= \colb{74567} - \colg{8} \times \colv{(8000 + 800)} \\ &= \colb{4167}. \end{aligned}
    Diagram: The five rows are now: the upper quotient 480, the dividend 4167, the upright divisor 8000, the incorrupt divisor 800, and the lower divisor 100.
除訖、倍廉法、上從方法。 [The] removal finished, double [the] incorrupt divisor, [which] followeth [the] upright divisor above.
  • Version A and Version C are missing .
  • In modern notation:
    \colv{s_2} := 2 s_2 = 2 \times 800 = \colv{1600}.
    Diagram: The five rows are now: the upper quotient 480, the dividend 4167, the upright divisor 8000, the incorrupt divisor 1600, and the lower divisor 100.
方法一退下法再退 [The] upright divisor retreateth once; [the] lower divisor retreateth twice.
  • Version A erroneously has 一退方法 for 方法一退.
  • 再: twice; or again
  • 上從方法 from the previous sentence tells us that the incorrupt divisor (廉法 s_2) is to "follow [the] upright divisor (方法 s_1) above" in its retreat.
  • In modern notation:
    \begin{aligned} \colv{s_1} &:= s_1 / 10 = 8000 / 10 = \colv{800} \\ \colv{s_2} &:= s_2 / 10 = 1600 / 10 = \colv{160} \\ \colr{L} &:= L / 10^2 = 100 / 100 = \colr{1}. \end{aligned}
    Diagram: The five rows are now: the upper quotient 480, the dividend 4167, the upright divisor 800, the incorrupt divisor 160, and the lower divisor 1.
置上商四、以次前。 Put again [for the] upper quotient four, to [be] next [after the] former.
  • The ones digit of the upper quotient (上商) is the largest \colg{a_3} such that \colg{a_3} (\colv{s_1} + \colv{s_2} + \colg{a_3} \colr{L}) \le \colb{d}, or
    \colg{a_3} (\colv{800} + \colv{160} + \colg{a_3}) \le \colb{4167},
    i.e.
    \colg{a_3} := \colg{4}.
    Diagram: The five rows are now: the upper quotient 484, the dividend 4167, the upright divisor 800, the incorrupt divisor 160, and the lower divisor 1.
置四於方法之下、下法之上、名曰隅法 Subsidiarily put four below [the] upright divisor, [and] above [the] lower divisor, [its] name [being] called [the] moral divisor.
  • 隅: moral; or corner
  • The third straight divisor is the moral divisor (隅法)
    \colv{s_3} := \colg{a_3} \colr{L} = \colg{4} \times \colr{1} = \colv{4}.
    Diagram: There are now six rows: the upper quotient 484, the dividend 4167, the upright divisor 800, the incorrupt divisor 160, the moral divisor 4, and the lower divisor 1.
方廉隅各命上商四、以除實 Each of [the] upright, [the] incorrupt, [and the] moral nameth [the] upper quotient's four, to remove from [the] dividend.
  • Version A is missing .
  • In modern notation:
    \begin{aligned} \colb{d} &:= \colb{d} - \colg{a_3} \colv{(s_1 + s_2 + s_3)} \\ &= \colb{4167} - \colg{4} \times \colv{(800 + 160 + 4)} \\ &= \colb{311}. \end{aligned}
    Diagram: The six rows are now: the upper quotient 484, the dividend 311, the upright divisor 800, the incorrupt divisor 160, the moral divisor 4, and the lower divisor 1.
除訖、倍隅法、從方法。 [The] removal finished, double [the] moral divisor, [which] followeth [the] upright divisor.
  • Version A is missing 倍隅法、從方法.
  • In modern notation:
    \colv{s_3} := 2 s_3 = 2 \times 4 = \colv{8}.
    Diagram: The six rows are now: the upper quotient 484, the dividend 311, the upright divisor 800, the incorrupt divisor 160, the moral divisor 8, and the lower divisor 1.
上商得四百八十四下法得九百六十八不盡三百一十一 [The] upper quotient resulteth in four hundred [and] eighty-four, [and the] lower divisors result in nine hundred [and] sixty-eight, remainder three hundred [and] eleven.
  • 下法: lower divisors

    Confusingly, this refers not to the lower divisor (下法), currently \colr{L = 1}, but to the total of the three straight divisors, the upright (\colv{s_1}), the incorrupt (\colv{s_2}), and the moral (\colv{s_3}).

  • In modern notation:
    \begin{aligned} \colg{U} &:= \colg{100 a_1 + 10 a_2 + a_3} = \colg{484} \\ \colv{L} &:= \colv{s_1 + s_2 + s_3} = \colv{968} \\ \colb{R} &:= \colb{d} = \colb{311}. \end{aligned}

    The final arrangement of counting rods is thus:

    Final diagram: The six rows are: the upper quotient 484, the dividend 311, the upright divisor 800, the incorrupt divisor 160, the moral divisor 8, and the lower divisor 1.
是為方四百八十四九百六十八分步之三百一十一 This be [a] square [of edge] four hundred [and] eighty-four paces [and] three hundred [and] eleven nine hundred [and] sixty-eighths of [a] pace.
  • Thus the algorithm gives
    \begin{aligned} \sqrt{234567 \unit{paces}^2} &\approx \left( \colg{U} + \frac{\colb{R}}{\colv{L}} \right) \unit{paces} \\[\tallspace] &= \colg{484} \tfrac{\colb{311}}{\colv{968}} \unit{paces}, \end{aligned}
    which has relative error 2.2 \times 10^{-7}.

Extended commentary

Pseudocode

In modern notation, Sun Tzŭ's algorithm for computing the square root of the positive integer x proceeds thus:

  1. Compute the number of digits of x:
    N := \lfloor \log_{10} x \rfloor + 1.
  2. Compute the number of digits of the upper quotient (上商), which is the integer part of \sqrt{x}:
    n := \left\lceil \frac{N}{2} \right\rceil.
  3. Initialise the lower divisor (下法):
    \colr{L} := (10 ^ {n - 1}) ^ 2.
  4. Initialise the dividend ():
    \colb{d} := x.
  5. For i = 1, 2, \dots, n:
  6. Compute the upper quotient (上商), the sum of the straight divisors, and the remainder (不盡):
    \begin{aligned} \colg{U} &:= \colg{10^{n-1} a_1 + 10^{n-2} a_2 + \dots + a_n} \\ \colv{L} &:= \colv{s_1 + s_2 + \dots + s_n} \\ \colb{R} &:= \colb{d}. \end{aligned}
  7. Return \colg{U} + \colb{R} / \colv{L}.

Why does it work?

Stare at the following identity for a long time:

\begin{aligned} \gdef\coeffbr#1{\Bigl(#1\Bigr)} \roundbr{ a_1 + \frac{a_2}{10} + \frac{a_3}{10^2} + \frac{a_4}{10^3} + \dots } ^ 2 = {a_1}^2 &+ \frac{a_2}{10^2} \coeffbr{20 a_1 + a_2} \\[\tallspace] &+ \frac{a_3}{10^4} \coeffbr{200 a_1 + 20 a_2 + a_3} \\[\tallspace] &+ \frac{a_4}{10^6} \coeffbr{2000 a_1 + 200 a_2 + 20 a_3 + a_4} \\[\tallspace] &+ \dots \end{aligned}

Cite this page

Conway (2023). "Sun Tzŭ's Computational Classic: Volume II §19". <https://yawnoc.github.io/sun-tzu/ii/19> Accessed yyyy-mm-dd.