The problem¶

There are three classes of corn, of which three bundles of the first class, two of the second, and one of the third make 39 measures. Two of the first, three of the second, and one of the third make 34 measures. And of the first, two of the second, and three of the third make 26 measures. How many measures of grain does one bundle of each class has?
Note: this problem is from an ancient Chinese book The Nine Chapters on the Mathematical Art, which was composed from the 10th-2nd century BCE.It provides solutions to 346 problems. But it doesn't include detail to convince the reader the solution is correct. There are several ancient people in China commenting on this book to provide more detail. Liu Hui, born aroud 250 CE, wrote the popular one and his book appeard before 295 CE. In his book, he applied the elimination method to solve system of equations problem, which we restated above.

The ancient Chinese people naturally developed their own concepts and methods to solve the practical problems they met, one of which we restated above. You can refer to The Nine Chapters on the Mathematical Art for more examples. And they have developed their own number system to facility the calculation. Since around at least 200 BC, the number system more or less like the following one has been used in ancient China.

The number on the top is 1971 and the number on the bottom is 1972. The most significant number is the first symbol from the left, the same as the Arabic number. There are two types of symbols used to represent digits. Please see the following. I will explain it shortly.

Symbols in the first line are Arabic numbers you are familiar with. The corresponding symbols in the second line are called vertical rods. And the corresponding symbols in the third line are called horizontal rods. To represent the number 1971 (you can refer to the top part of our first picture), the first digit from the right is chosen from the vertical rods, and the second digits from the right is chosen from the horizontal rods. The vertical rods and the horizontal rods appear alternatively.

Equations of the problems¶

We can have the following system of equations, where x, y and z are the measures of the first, second and third classes of corn. $$ \begin{cases} 3x + 2y + z = 39\\ 2x + 3y + z = 34\\ x + 2y + 3z = 26 \end{cases} $$

The algorithm to solve the problem¶

Following the guides in Nine Chapters on Mathematical Art, we can organize it as following matrix, each column reprensents one equation and the rightmost column of which reprensents the first equation above. $$ \begin{bmatrix} 1 & 2 & 3\\ 2 & 3 & 2\\ 3 & 1 & 1\\ 26 & 34 & 39 \end{bmatrix} $$

We follow the guids in Nine Chapters on Mathematical Art to solve this system.

  1. Multiply the middle column by 3, which is the first number that is not zero in the last column.
    We will have the following matrix: $$ \begin{bmatrix} 1 & 6 & 3\\ 2 & 9 & 2\\ 3 & 3 & 1\\ 26 & 102 & 39 \end{bmatrix} $$
  2. Remove the last column from the middle column repeatedly, until the first number of the middle column is zero.
    We will get the following matrix: $$ \begin{bmatrix} 1 & 0 & 3\\ 2 & 5 & 2\\ 3 & 1 & 1\\ 26 & 24 & 39 \end{bmatrix} $$
  3. Multiply the first column by 3, which is the first number that is not zero in the last column.
    We will get the following matrix: $$ \begin{bmatrix} 3 & 0 & 3\\ 6 & 5 & 2\\ 9 & 1 & 1\\ 78 & 24 & 39 \end{bmatrix} $$
  4. Remove the last column from the first column repeatedly, until the first number of the first column is zero.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 3\\ 4 & 5 & 2\\ 8 & 1 & 1\\ 39 & 24 & 39 \end{bmatrix} $$
  5. Multiply the first column by 5, which is the first nonzero number in the middle column.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 3\\ 20 & 5 & 2\\ 40 & 1 & 1\\ 195 & 24 & 39 \end{bmatrix} $$
  6. Romove the middle column from the first column repeately, until the second number of the first column is zero.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 3\\ 0 & 5 & 2\\ 36 & 1 & 1\\ 99 & 24 & 39 \end{bmatrix} $$

The above algorithm until now is similar to the forward phase in the Gaussian-Jordan elimation.

  1. Multiply the middle column by 36, which is the first number that is nonzero in the first column.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 3\\ 0 & 180 & 2\\ 36 & 36 & 1\\ 99 & 864 & 39 \end{bmatrix} $$
  2. Romove the first column from the middle column, and divide the middle column by 5, which is the first nonzero number in the middle column from above step 6.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 3\\ 0 & 36 & 2\\ 36 & 0 & 1\\ 99 & 153 & 39 \end{bmatrix} $$
  3. Multiply the third column by 36, which is the first number that is nonzero in the first column.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 108\\ 0 & 36 & 72\\ 36 & 0 & 36\\ 99 & 765 & 1404 \end{bmatrix} $$
  4. Remove the first column and the middle column from the third column, until both the second and the third number in the third column is zero. And divide the resulting third column by 3, which is the first nonzero number in the third column from above step 8.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 36\\ 0 & 36 & 0\\ 36 & 0 & 0\\ 99 & 153 & 333 \end{bmatrix} $$
  5. Divide the matrix by 36, which is the number in each column. The last row of the matrix includes the solustion to this problem.
    We will get the following matrix: $$ \begin{bmatrix} 0 & 0 & 1\\ 0 & 1 & 0\\ 1 & 0 & 0\\ 2\frac{1}{4} & 4\frac{1}{4} & 9\frac{1}{4} \end{bmatrix} $$

The solution is: $$ \begin{cases} x = 9\frac{1}{4} \\ y = 4\frac{1}{4} \\ z = 2\frac{1}{4} \end{cases} $$

In [2]:
import matplotlib.pyplot as plt
import numpy as np
In [82]:
fig, ax = plt.subplots()
ax.tick_params(top=False, labeltop=False, bottom=False, labelbottom=False, labelleft=False,left=False)
plt.xlim((0,10))
plt.ylim((0, 3))
for i in range(1, 10):
    ax.text(i-0.1, 2.5,f"{i}", fontsize="x-large", fontweight=600)
    plot_vertical(ax, i, 0.1)
    plot_horizontal(ax, i, 0.05)
ax.spines["left"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
plt.savefig("number_characters.jpg", dpi=300)
plt.show()
In [48]:
def plot_vertical(axes, n, step):
    if n <= 5:
        for i in range(1, n+1):
            x = n + step * (i - 1) - step * (n - 1)
            axes.plot([x, x],[1.9, 2.1], color="k")
    else:
        axes.plot([n-0.25, n + 0.25],[2.1, 2.1], color="k")
        for i in range(6, n+1):
            x = n + step * (i-5 - 1) - step * (n - 5 -1)/2.0
            axes.plot([x, x],[1.9, 2.1], color="k")
In [61]:
def plot_horizontal(axes, n, step):
    if n <= 5:
        for i in range(1, n+1):
            y = 1 + step * (i - 1) - step * (n - 1)
            axes.plot([n-0.25, n+0.25],[y, y], color="k")
    else:
        axes.plot([n, n],[0.9, 1.1], color="k")
        for i in range(6, n+1):
            y =0.9 - step * (i-5 - 1)
            axes.plot([n-0.25, n+0.25],[y, y], color="k")