Chinese Remainder Theorem
Summary
This activity explores the historical problem now associated with the Chinese Remainder Theorem through a problem from the Sunzi Suanjing, an early Chinese mathematical text. Students begin with an unknown collection of objects that leaves remainders of 2, 3, and 2 when counted in groups of 3, 5, and 7, respectively. They solve the problem by hand, interpret the historical rule involving the coefficients 70, 21, and 15, and explain why the procedure reconstructs the unknown number.
Students then use MATLAB to implement and compare multiple solution strategies, including exhaustive search, the specialized procedure appearing in the Sunzi Suanjing, and a generalized Chinese Remainder Theorem algorithm. Through computational experiments, students investigate uniqueness, periodicity, efficiency, and the importance of pairwise relatively prime moduli. The activity connects the history of Chinese mathematics with modular arithmetic, algorithm design, mathematical reasoning, and computational experimentation.
Learning Goals
By completing this activity, students will understand the historical problem from the Sunzi Suanjing that is now associated with the Chinese Remainder Theorem. They will solve simultaneous remainder conditions using numerical, historical, and modern methods; explain why the coefficients 70, 21, and 15 reconstruct the desired remainders modulo 3, 5, and 7; recognize that solutions repeat with a period determined by the product of pairwise relatively prime moduli; and distinguish between the procedure presented in the historical text and the modern notation, theorem, and generalized algorithm.
Students will use MATLAB to represent remainders and moduli with vectors, test simultaneous remainder conditions using the mod command, implement an exhaustive-search algorithm with loops and conditional statements, translate the historical reconstruction procedure into executable code, and develop or complete a function that solves generalized systems of congruences. Students will also test their programs with multiple inputs, verify their results, and compare the behavior and efficiency of different computational approaches.
MATLAB improves student learning by making the structure of the historical procedure visible and testable. Students can experiment with different remainders and moduli, receive immediate feedback, identify patterns, and investigate the assumptions required by the Chinese Remainder Theorem. Implementing more than one algorithm also allows students to compare a simple exhaustive search with a direct reconstruction procedure and to consider why some computational methods are more efficient than others.
The activity develops higher-order thinking skills by requiring students to translate a verbal historical procedure into modern mathematical notation, translate mathematical reasoning into an algorithm, compare multiple methods for solving the same problem, use computational evidence to formulate and test conjectures, and analyze the assumptions and limitations of an algorithm.
Students will also develop written communication skills. They will explain the historical procedure and the mathematical reasoning behind it, interpret computational output rather than merely reporting it, and discuss what is gained or potentially obscured when historical mathematics is translated into modern notation and software.
Context for Use
This activity is designed primarily for undergraduate students in a History of Mathematics course, although it could also be used in courses on number theory, discrete mathematics, mathematical computing, or mathematical reasoning. It is appropriate for lower- or upper-division undergraduates and can be completed individually or in small groups. The activity is intended as a multi-day project requiring approximately one to two weeks, including historical reading, hand calculations, MATLAB implementation, computational experimentation, and written reflection.
Students should be comfortable with basic arithmetic and mathematical reasoning. Prior experience with modular arithmetic is helpful but not required, since congruence notation can be introduced through the historical counting problem. No previous study of Chinese mathematics or the Chinese Remainder Theorem is necessary.
Students need basic MATLAB proficiency, including defining variables and vectors, using mod, writing loops and conditional statements, and creating simple functions. An instructor may provide starter code or a short MATLAB warm-up for students with less programming experience. The initial exhaustive-search component is deliberately accessible, while the generalized algorithm can be scaffolded according to students' mathematical and computational backgrounds.
The activity is most naturally situated within a unit on ancient or medieval Chinese mathematics. It may follow students' study of Chinese numeration, counting rods, or algorithmic problem solving. It is also suitable as a bridge from historical mathematical procedures to modern number theory and computational thinking.
The project can be completed in person, in a hybrid course, or online using MATLAB Online. It can be shortened by limiting the activity to the historical problem and two MATLAB algorithms or expanded through investigations of non-coprime moduli, algorithm efficiency, cryptography, and other modern applications.
Description and Teaching Materials
The activity begins with a problem from Chapter 3 of the Sunzi Suanjing:
Suppose there is an unknown number of objects. When counted in threes, 2 are left over; when counted in fives, 3 are left over; and when counted in sevens, 2 are left over. How many objects are there?
Students initially investigate the problem without using modern congruence notation. They may create lists of possible numbers, organize the information in a table, or develop another systematic method. After identifying 23 as the least positive solution, students find additional solutions and investigate why the pattern repeats every 105 objects.
The instructor then introduces the procedure associated with the problem in the Sunzi Suanjing. If a, b, and c are the remainders obtained when the unknown number is divided by 3, 5, and 7, respectively, the procedure calculates
x = 70a + 21b + 15c (mod 105).
For the original problem, the procedure produces
70(2) + 21(3) + 15(2) = 233.
Subtracting two multiples of 105 gives the least positive solution, 23.
Students investigate why the coefficients in this procedure work. They calculate the remainder of each coefficient when divided by 3, 5, and 7. They discover that 70 has remainders 1, 0, and 0; 21 has remainders 0, 1, and 0; and 15 has remainders 0, 0, and 1. Students use these results to explain how each coefficient preserves one desired remainder while contributing zero to the other two remainder conditions.
Students then translate the original problem into modern congruence notation:
x is congruent to 2 modulo 3.
x is congruent to 3 modulo 5.
x is congruent to 2 modulo 7.
The MATLAB portion of the activity proceeds through three methods.
In the first method, students implement an exhaustive search. They write a program that tests successive nonnegative integers until it finds a value satisfying all three remainder conditions. Students then revise the program so that the remainders and moduli are stored in vectors. This method closely resembles the students' initial hand calculations and provides an accessible introduction to the computational problem.
In the second method, students implement the specialized procedure from the Sunzi Suanjing. They store the remainders in one vector and the coefficients 70, 21, and 15 in another. They use MATLAB to calculate the weighted sum and reduce the result modulo 105. Students test the procedure with several different triples of remainders while keeping the moduli 3, 5, and 7 fixed. They verify each solution using the mod command.
In the third method, students generalize the reconstruction procedure to other lists of pairwise relatively prime moduli. For moduli n1, n2, ..., nk, students first calculate
N = n1 times n2 times ... times nk.
For each modulus ni, they calculate
Ni = N/ni
and find a multiplier ui such that
Ni times ui is congruent to 1 modulo ni.
They then calculate
x = a1N1u1 + a2N2u2 + ... + akNkuk (mod N).
Depending on their previous MATLAB experience, students may write the entire generalized function, complete partially provided code, or use a modular-inverse routine supplied by the instructor.
After implementing the algorithms, students conduct a computational investigation. They compare the solutions produced by exhaustive search and direct reconstruction, examine how the search time changes as the moduli increase, and explain why direct reconstruction is more efficient than checking every possible integer. They also investigate whether changing the order of the moduli affects the final solution.
As an extension, students test systems in which the moduli are not pairwise relatively prime. They compare systems that have no solution with compatible systems that do have solutions. This investigation helps students identify the assumptions required by the standard Chinese Remainder Theorem and prevents the impression that every system of remainder conditions automatically has a unique solution modulo the product of the moduli.
Students conclude the activity with a written reflection addressing the following prompt:
The Sunzi Suanjing presents a numerical problem and a computational procedure rather than a theorem expressed in modern symbolic notation. What mathematical knowledge is contained in the historical procedure? What becomes clearer when the procedure is translated into modern notation and MATLAB, and what aspects of the historical method might that translation obscure?
MATLAB was selected because its support for vectors, loops, logical conditions, modular arithmetic, and functions allows students to move naturally from a direct search to a generalized reconstruction algorithm. MATLAB also provides immediate feedback that supports experimentation, verification, debugging, and comparison. The activity could be implemented in another programming language, but MATLAB's interactive environment and accessible syntax allow students to concentrate on the mathematical structure of the algorithms.
Supporting materials for the activity will include a student handout, a MATLAB Live Script, a generalized Chinese Remainder Theorem function, an instructor guide with solutions and teaching suggestions, and an assessment rubric.
Chinese Remainder Theorem MATLAB Function (Matlab File 1kB Sep8 26)
Counting the Unknown MATLAB Live Script (Matlab File 2kB Sep8 26)
Student Handout: Counting the Unknown (Acrobat (PDF) 42kB Sep8 26)
Teaching Notes and Tips
Introduce the activity through the verbal counting problem before presenting congruence notation or naming the Chinese Remainder Theorem. This allows students to experience the mathematical problem in a form closer to its historical presentation and gives them a reason to seek a more systematic procedure.
Students should solve the original problem by hand before using MATLAB. A direct numerical search helps them understand what the program must accomplish and makes the later comparison of algorithms more meaningful. If students need additional MATLAB support, a short preliminary exercise using vectors, loops, conditional statements, and the mod command can be provided.
Students may initially treat the coefficients 70, 21, and 15 as unexplained features of a formula. Calculating the remainders of these coefficients modulo 3, 5, and 7 is central to the activity. Ask students to explain why 70 contributes the desired remainder modulo 3 but contributes nothing modulo 5 or 7. They should then repeat this reasoning for 21 and 15. This explanation provides the conceptual bridge between the historical procedure and the generalized algorithm.
A common source of confusion is the difference between a particular solution and the complete family of solutions. Reinforce that 23 is the least positive solution to the original problem, but every number of the form 23 + 105k, where k is an integer, also satisfies the three remainder conditions.
Students may also struggle with modular inverses during the generalized portion. In an introductory class, allow students to find an inverse through a short MATLAB search. Students with more mathematical preparation may use the extended Euclidean algorithm. Partial code can be provided when the primary goal is interpreting and comparing algorithms rather than constructing every component independently.
Require students to verify each computed answer by substituting it into the original remainder conditions. This reinforces the distinction between code that runs and an algorithm that produces a mathematically correct result.
When students explore non-coprime moduli, distinguish among systems with no solution, systems with compatible remainder conditions, and the standard Chinese Remainder Theorem for pairwise relatively prime moduli. This extension reveals the assumptions built into the generalized algorithm.
If MATLAB's built-in crt function is available, introduce it only after students have implemented and explained at least one reconstruction algorithm. The built-in function is most useful for verification and comparison rather than as a substitute for mathematical reasoning.
Throughout the activity, avoid presenting the historical procedure merely as an incomplete version of modern mathematics. Encourage students to consider what the procedure accomplishes in its own historical context and what mathematical reasoning is encoded within it.
Assessment
Students are assessed through their hand calculations, mathematical explanations, MATLAB code, computational results, and written reflection.
Evidence that students have met the goals of the activity includes correctly solving and verifying the original counting problem; accurately explaining the roles of the coefficients 70, 21, and 15; producing functional and readable MATLAB code for exhaustive search and direct reconstruction; testing the algorithms with several appropriate examples; explaining why solutions are unique modulo the product when the moduli are pairwise relatively prime; identifying what can occur when the moduli are not pairwise relatively prime; and comparing algorithms using mathematical reasoning and computational evidence.
Students must also distinguish between the particular procedure presented in the Sunzi Suanjing and the modern formulation of the Chinese Remainder Theorem. Their final reflection should meaningfully integrate historical, mathematical, and computational perspectives.
An accompanying rubric evaluates student work in five areas: historical understanding and interpretation, mathematical reasoning, MATLAB functionality and clarity, computational investigation and analysis, and written communication and reflection.
Assessment Rubric (Acrobat (PDF) 32kB Sep8 26)
References and Resources
O'Connor, J. J., and E. F. Robertson. "Sun Zi." MacTutor History of Mathematics Archive. https://mathshistory.st-andrews.ac.uk/Biographies/Sun_Zi/
This resource discusses the dating and contents of the Sunzi Suanjing and presents the historical remainder problem and its associated computational procedure.
Shen, Kangshen, John N. Crossley, and Anthony W.-C. Lun. The Nine Chapters on the Mathematical Art: Companion and Commentary. Oxford University Press, 1999.
This book provides translations, commentary, and broader historical context for early Chinese algorithmic mathematics.
Katz, Victor J., and Annette Imhausen, editors. The Mathematics of Egypt, Mesopotamia, China, India, and Islam: A Sourcebook. Princeton University Press, 2007.
This collection provides translations and scholarly commentary that support the study of mathematical procedures within their historical and cultural settings.
MathWorks. "Chinese Remainder Theorem." https://www.mathworks.com/help/phased/ref/crt.html
This documentation describes MATLAB's crt function. The function can be used by instructors or students to verify results produced by independently developed algorithms.