A-13 Chinese Remainder Theorem

- Reference 1: Brilliant – Chinese Remainder Theorem [4]

- Reference 2: YouTube – Extended Euclidean Algorithm Tutorial

Theorem A-13.1 Chinese Remainder Theorem

Suppose we have positive coprime integers n0,n1,n2,,nk. Let N = n1n2nk. We sample k + 1 random integers a0,a1,a2,,ak from each modulo domain n0,n1,n2,,nk (i.e., a0 n0, a1 n1, , ak nk). Then, there exists one and only one solution x mod N such that x is congruent with a0,a1,a2,,ak in each modulo n0,n1,n2,,nk. That is:

x a0 mod n0

x a1 mod n1

x a2 mod n2

x ak mod nk

To compute x, we first compute each yi and zi (for 0 i k) as follows:

yi = N ni, zi = yi1 mod ni

Note that each yi’s inverse (i.e., yi1) can be computed by using the Extended Euclidean algorithm (watch the YouTube tutorial). Then, the unique solution x can be computed as follows:

x = i=0kaiyizi # Alternatively, we can compute x = i=0k|aizi|niyi (where |aizi|ni = aizi mod ni)

Since such x is unique in mod  N, there are isomorphic mappings between x mod N and (a0,a1,a2,,ak).

Also, yizi (yizi)2 mod N for all 0 i k

Proof.

1.
Given x = i=0kaiyizi, let’s compute x mod ni for each i where 0 i k:

x mod ni = i=0kaiyizi mod ni

= a0y0z0 + a1y1z1 + a2y2z2 + + akykzk mod ni

= aiyizi mod ni # because yj 0 mod ni for all ji, as they are a multiple of ni

= ai # because yizi = yiyi1 = 1

Thus, the value of x in each modulo n0,n1,n2,,nk is congruent with a0,a1,a2,,ak.

Alternatively, note that the following is also true:

x mod ni = i=0k|aizi|niyi (mod ni)

= |a0z0|n0y0 + |a1z1|n1y1 + |a2z2|n2y2 + + |akyk|nkyk mod ni

= |aizi|niyi mod ni

= ai

2.
Now, we prove that x is a unique solution in modulo N. Suppose there were two solutions: x and x such that:

x x a0 mod n0

x x a1 mod n1

x x a2 mod n2

x x ak mod nk

Then, by definition of modulo congruence, n0 | (x x),n1 | (x x), n2 | (x x),  , nk | (x x).

Also, since n0,n1,n2,,nk are coprime, it must be the case that n0n1n2n3nk | (x x), or N | (x x). This means that x xmod N. Therefore, x is a unique solution in modulo N.

3.
Now, we will prove that yizi (yizi)2 mod N for all 0 i k.

In the case of modulo ni, yizi 1 mod ni, since zi is an inverse of yi modulo nj. In the case of all other modulo nj where ij, yizi 0 mod nj, because yi = N ni and thus nj divides yi.

By squaring both sides of (yizi) 1 mod ni, we get (yizi)2 1 mod ni. Similarly, by squaring both sides of (yizi) 1 mod nj, we get (yizi)2 0 mod nj.

Therefore, yizi (yizi)2 0 mod ni, and yizi (yizi)2 0 mod nj. In other words, yizi (yizi)2 0 mod nj for all 0 j k.

Then, we do the similar reasoning as step 2: since every co-prime nj divides yizi (yizi)2, n0n1nk = N divides yizi (yizi)2. Thus, yizi (yizi)2 0 mod N, which is yizi (yizi)2 mod N. This is true for all 0 i k.


A-13.1 Application: Residue Number System (RNS)