Simultaneous Linear Congruences- Chinese Remainder Theorem (CRT)



We will now consider the solutions of simultaneous congruences. In the 1st century AD, the Chinese mathematician Sun-Tsu considered problems like ‘find a number which leaves remainders 2,3,2 when divided by 3,5,7 respectively’. Equivalently, he wanted to find $x$ such that the congruences

$$x \equiv 2 \pmod{3}, \quad x \equiv 3 \pmod {5}, \quad x \equiv 2 \pmod {7}$$
 
are simultaneously true. Note that if $x_0$ is any solution, then so is $x_0 +(3 \times 5 \times 7)t$ for any integer $t$, so the solutions form a union of congruence classes mod (105).

We shall show that in this particular case the solutions form a single congruence class, but in other cases we may find that there are several classes or none: as an example, the simultaneous congruences

$$x \equiv 3 \pmod {9},\quad  x \equiv 2 \pmod {6}$$

have no solutions, for if $x \equiv 3 \pmod {9}$ then 3 divides $x$, whereas if $x \equiv 2\pmod {6}$ then 3 does not divide $x$. The difficulty here is that the moduli 9 and 6 have a factor 3 in common, so both congruences have implications about the congruence class of $x \pmod {3}$, and in this particular case these implications are m utually inconsistent. To avoid this type of difficulty, we will initially restrict our attention to cases like our first example, where the moduli are mutually coprime. 
  
Fortunately, the following result, known as the Chinese Remainder Theorem, gives a very satisfactory solution to this type of problem.

The Chinese Remainder Theorem (CRT) is a fundamental theorem in number theory with applications in various fields such as cryptography, computer science, and pure mathematics. It provides a solution to simultaneous congruences.

Statement:

Let n1,n2,,nkn_1, n_2, \ldots, n_kbe positive integers that are pairwise coprime (i.e., for every ij \neq j, gcd(ni,nj)=1\text{gcd}(n_i, n_j) = 1), and let a1,a2,,aka_1, a_2, \ldots, a_kbe any integers. Then the system of simultaneous congruences

xa1(modn1)xa2(modn2)xak(modnk)\begin{align*} x &\equiv a_1 \pmod{n_1} \\ x &\equiv a_2 \pmod{n_2} \\ &\vdots \\ x &\equiv a_k \pmod{n_k} \end{align*}

has a unique solution modulo N=n1×n2××nkN = n_1 \times n_2 \times \ldots \times n_k

Proof:

  1. Existence of a Solution:

    Let N=n1×n2××nkN = n_1 \times n_2 \times \ldots \times n_kFor each ii, let Ni=N/niN_i = N / n_i. Since nin_iand NiN_iare coprime, there exist integers bib_i such that Nibi1(modni)N_i b_i \equiv 1 \pmod{n_i}. Now, let x=i=1kaiNibix = \sum_{i=1}^{k} a_i N_i b_i We claim that xx is a solution to the system of congruences.

    Indeed, for any ii, we have:

    xaiNibiai.1ai(modni)x \equiv a_i N_i b_i \equiv a_i 1  \equiv a_i \pmod{n_i}

    Thus, xx satisfies all the congruences.

  2. Uniqueness of Solution:

    Suppose x1x_1 and x2x_2 are two solutions to the system of congruences. Then x1x2(modni) for all ii. Hence, x1x2(modNi)x_1 \equiv x_2 \pmod{N_i} for all ii.

    Since N=n1×n2××nkN = n_1 \times n_2 \times \ldots \times n_k by the Chinese Remainder Theorem, x1x2(modN)x_1 \equiv x_2 \pmod{N}

    Thus, any two solutions are congruent modulo NN, and hence, the solution is unique modulo N.

Example:

Let's solve the following system of simultaneous congruences:

x2(mod3)x3(mod5)x2(mod7)\begin{align*} x &\equiv 2 \pmod{3} \\ x &\equiv 3 \pmod{5} \\ x &\equiv 2 \pmod{7} \end{align*}

Here, n1=3n_1 = 3, n2=5n_2 = 5, and n3=7n_3 = 7 are pairwise coprime.

  1. Compute N=n1×n2×n3=3×5×7=105N = n_1 \times n_2 \times n_3 = 3 \times 5 \times 7 = 105.
  2. Compute N1=105/3=35N_1 = 105 / 3 = 35, N2=105/5=21N_2 = 105 / 5 = 21, and N3=105/7=15N_3 = 105 / 7 = 15
  3. Compute the inverses b1b_1, b2b_2, and b3b_3 such that Nibi1(modni)N_i b_i \equiv 1 \pmod{n_i}. $35b_1 \equiv 1 \pmod{3},21b_2 \equiv 1\pmod{5},15b_3 \equiv 1 \pmod{7}$
    4.We get b1=2b_1 = 2, b2=1, and b3=1b_3 = 1.
    5.Calculate x=a1N1b1+a2N2b2+a3N3b3=2×35×2+3×21×1+2×15×1=233x = a_1 N_1 b_1 + a_2 N_2 b_2 + a_3 N_3 b_3 = 2 \times 35 \times 2 + 3 \times 21 \times 1 + 2 \times 15 \times 1 = 233

Therefore, the unique solution to the given system of congruences modulo N=105N = 105 is x23(mod105)x \equiv 23 \pmod{105}


Example:

Suppose we have the following system of congruences:

$ \begin{align*} x &\equiv 1 \pmod{3} \\ x &\equiv 4 \pmod{5} \\ x &\equiv 6 \pmod{7} \end{align*} $
 

We follow the steps of the Chinese Remainder Theorem:

  1. Compute N=n1×n2×n3=3×5×7=105N = n_1 \times n_2 \times n_3 = 3 \times 5 \times 7 = 105
  2. Compute N1=105/3=35N_1 = 105 / 3 = 35, N2=105/5=21N_2 = 105 / 5 = 21, and N3=105/7=15
  3. Compute the inverses b1b_1, b2b_2, and b3b_3 such that Nibi1(modni)N_i b_i \equiv 1 \pmod{n_i}

For n1=3n_1 = 3, we have N1b11(mod3)N_1 b_1 \equiv 1 \pmod{3}, so 35b11(mod3)35b_1 \equiv 1 \pmod{3}Solving this congruence, we find b12(mod3)b_1 \equiv 2 \pmod{3}

For n2=5n_2 = 5, we have N2b21(mod5)N_2 b_2 \equiv 1 \pmod{5}, so 21b21(mod5)21b_2 \equiv 1 \pmod{5}. Solving this congruence, we find b21(mod5)b_2 \equiv 1 \pmod{5}

For n3=7n_3 = 7, we have N3b31(mod7), so 15b31(mod7)15b_3 \equiv 1 \pmod{7}. Solving this congruence, we find b31(mod7)b_3 \equiv 1 \pmod{7}

  1. Calculate x=a1N1b1+a2N2b2+a3N3b3=1×35×2+4×21×1+6×15×1=244x = a_1 N_1 b_1 + a_2 N_2 b_2 + a_3 N_3 b_3 = 1 \times 35 \times 2 + 4 \times 21 \times 1 + 6 \times 15 \times 1 = 356

Therefore, the unique solution to the given system of congruences modulo N=105N = 105 is x≡34(mod105)x \equiv 46 \pmod{105}

The linear congruences in the Chinese Remainder Theorem are all of the form $x \equiv a_i \mod (n_i)$. If we are given a set of simultaneous linear congruences, with one (or more) of them in the more general form $ax \equiv b \: mod (n_i)$, then we will first need to use the earlier algorithm to solve this congruence, expressing its general solution as a congruence class modulo some divisor of $n_i$; it will then be possible to apply the techniques based on the Chinese Remainder Theorem to solve the resulting simultaneous congruences. 

Example:

Consider the congruences

$$7x \equiv 3 \pmod {12},\quad 10x \equiv 6 \pmod {14}$$

This can be reduced into

$$x \equiv 9 \pmod {12},\quad x \equiv 2 \pmod {7}$$

Now it is in standard form and can be solved with CRT

The solution is

We follow the steps of the Chinese Remainder Theorem:

  1. Compute N=n1×n2=12×7=84N = n_1 \times n_2 = 12 \times 7 = 84
  2. Compute N1=84/12=7N_1 = 84 / 12 = 7 and N2=84/7=12
  3. Compute the inverses b1b_1 and b2b_2 such that Nibi1(modni)

For n1=12n_1 = 12, we have N1b11(mod12)N_1 b_1 \equiv 1 \pmod{12}, so 7b11(mod12)7b_1 \equiv 1 \pmod{12}. Solving this congruence, we find b17(mod12)b_1 \equiv 7 \pmod{12}

For n2=7n_2 = 7, we have N2b21(mod7)N_2 b_2 \equiv 1 \pmod{7}, so 12b21(mod7)12b_2 \equiv 1 \pmod{7}. Solving this congruence, we find b23(mod7)

  1. Calculate x=a1N1b1+a2N2b2=9×7×7+2×12×3=513

Therefore, the unique solution to the given system of congruences modulo N=84N = 84 is x9(mod84)x \equiv 21 \pmod{84}. General solution is $9+84t$

The Chinese Remainder Theorem (CRT) can be used to convert a single congruence, with a large modulus into several simultaneous congruences with smaller moduli

Example:
Consider the congruence  $13x \equiv 71 \pmod{380}$

Instead of solving this single linear congruence, we can use factorization $380=2^2 \times 5 \times 19$
So we can replace the original congruence with three simultaneous congruences.

$$13x \equiv 71 \pmod{4}, \quad 13x \equiv 71 \pmod{5} ,\quad  13x \equiv 71 \pmod{19} $$

These can be immediately reduced to
$$x \equiv 3 \pmod{4} ,\quad 3x \equiv 1 \pmod{5}, \quad  13x \equiv 14 \pmod{19} $$

We can further reduce this into
$$x \equiv 3 \pmod{4}, \quad x \equiv 2 \pmod{5}, \quad  x \equiv 4 \pmod{19} $$

Now these have mutually coprime  moduli and these can be solved using CRT

We follow the steps of the Chinese Remainder Theorem:Compute $N = n_1 \times n_2 \times n_3= 4 \times 5 \times 19 = 380$
Compute $N_1 = 380 / 4 = 95$ and $N_2=380/5=76$ and $N_3=380/19=20$
Compute the inverses $b_1,b_2$​ and $b_3$​ such that $N_ib_i≡1(mod \:n_i)$

For $n_1=4$, we have $N_1 b_1 \equiv 1 \pmod{4}$, so $95.b_1 \equiv 1 \pmod{4}$. Solving this congruence, we find $b_1 \equiv 3 \pmod{4}$

For $n_2 = 5$, we have $N_2 b_2 \equiv 1 \pmod{5}$, so $76.b_2 \equiv 1 \pmod{5}$. Solving this congruence, we find $b_2≡1 \pmod{5}$

For $n_3 = 19$, we have $N_3 b_3 \equiv 1 \pmod{19}$, so $20.b_3 \equiv 1 \pmod{19}$. Solving this congruence, we find $b_3≡1 \pmod{19}$

Calculate $x=a_1N_1b_1+a_2N_2b_2+a_3N_3b_3=3 \times 95 \times 3+2 \times 76 \times 1+4 \times 20 \times 1=1080=327 \pmod{380}$

Therefore, the unique solution to the given system of congruences modulo $N = 380$ is $x \equiv 327 \pmod{380}$. General solution is $327+380t$

Python code 
$x≡2(mod\;3)x≡3(mod \; 5)x≡2(mod \; 7)$

from sympy.ntheory.modular import crt

print(crt([3, 5, 7], [2, 3, 2]))

Output:(23, 105)

Comments

Popular posts from this blog

Number Theory CST 292 KTU IV Semester Honors Course Notes Dr Binu V P 9847390760

Sum of Squares