Coursework & experiments · Algorithms & computing
Tested educational implementation
- Context
- Coursework
- Maturity
- Tested educational implementation
- Evidence
- Locally verified
- Source
- Private source
- Ownership & provenance
- Joint historical submission
Residue Number System and CRT — representing and reconstructing an integer
A tested educational implementation that represents non-negative integers through remainders, performs modular arithmetic, and reconstructs the canonical value with the Chinese Remainder Theorem.

Idea and learning context
Instead of keeping a large integer as one value, a residue number system represents it through several smaller remainders. When the moduli are pairwise coprime, those remainders identify one representative inside the dynamic range, the product of the moduli. This work shows how a value moves into independent modular channels and how the Chinese Remainder Theorem (CRT) reconstructs its canonical representative.
Inputs and outputs
The application accepts a non-negative integer and an ordered set of moduli greater than one. Every pair of moduli must be coprime. Its first output is the residue vector, where rᵢ = x mod mᵢ. Reconstruction returns one value in [0, M), where M is the product of the moduli.
For moduli 3, 5, 7, the dynamic range is M = 105. The integer 20 becomes (2, 0, 6), and CRT reconstructs 20 inside that range. The residues identify a congruence class and its canonical representative in the stated range, not an unlimited absolute integer.
Calculation steps
- Validate that the modulus list is non-empty and contains distinct, pairwise-coprime values greater than one.
- Compute
M = m₁ × m₂ × … × mₙ, then encode the integer as its remainders. - Perform addition, subtraction and multiplication component by component, reducing each result by its channel's modulus.
- For reconstruction, compute
Mᵢ = M / mᵢand the multiplicative inverse ofMᵢmodulomᵢfor every channel. - Sum the terms
rᵢ Mᵢ yᵢand reduce the total moduloMto obtain the canonical representative. - Verify that the reconstructed value reproduces every input remainder.
When is there no unique solution?
Pairwise-coprime moduli give a unique result modulo their product. With non-coprime moduli, the system may be inconsistent and have no solution, or it may have a compatible solution with a different period based on the least common multiple. This educational implementation is limited to pairwise-coprime moduli and rejects modulus sets outside that domain. It also rejects residue vectors of the wrong length or values outside their channel range.
What division means here
Division is modular division, not integer or real-number division. It is accepted only when the divisor is positive and invertible in every channel. Thus 20 / 4 reconstructs to 5, while 5 / 2 reconstructs to 55 because 2 × 55 ≡ 5 (mod 105). This is not a claim that ordinary 5 / 2 equals 55.
Yahya's role and technical decisions
Yahya defined the input domain and rejected cases, separated the mathematical core from the interface, and built the reference application and correctness tests.
Evidence and maturity
Tests cover all 105 values through encoding and reconstruction, all 11,025 input pairs for each of addition, subtraction and multiplication, and invalid moduli, residues and divisors. A separate unsigned non-restoring binary divider was also compared with divmod across 86,870 cases at widths from one to eight bits. This is locally verified educational material; it presents no speed measurement, hardware result or scientific-novelty claim.
Mathematical references: NIST DLMF on the Chinese Remainder Theorem and Residue Number Systems: Theory and Applications.
From an integer to residues and back to the canonical representative
A complete example for moduli 3, 5 and 7. Arrows are mathematical transformations, not a hardware path or performance result.
References
- https://dlmf.nist.gov/27.15
- https://doi.org/10.1007/978-3-319-41385-3

