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.

Generated conceptual residue-path and CRT reconstruction cover; not a performance result or hardware diagram
Generated conceptual illustration, not a product screen or research result.

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

  1. Validate that the modulus list is non-empty and contains distinct, pairwise-coprime values greater than one.
  2. Compute M = m₁ × m₂ × … × mₙ, then encode the integer as its remainders.
  3. Perform addition, subtraction and multiplication component by component, reducing each result by its channel's modulus.
  4. For reconstruction, compute Mᵢ = M / mᵢ and the multiplicative inverse of Mᵢ modulo mᵢ for every channel.
  5. Sum the terms rᵢ Mᵢ yᵢ and reduce the total modulo M to obtain the canonical representative.
  6. 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.

Explanatory mathematical diagram

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.

Integer inside the range20Residue modulo 320 mod 3 = 2Residue modulo 520 mod 5 = 0Residue modulo 720 mod 7 = 6CRT reconstructionΣ rᵢ Mᵢ yᵢmod 105Canonicalrepresentative[0, 105)20

Help improve this content

Suggest a correction or edit

Your contribution is private and used to review and improve this content. The Privacy Policy explains how data is processed and retained and how to request deletion. Read the Privacy Policy and Terms of Use.