Example5.4.1A first CRT example
Let's look at how to solve our original system using this method.
x\equiv 1 (mod 5)
x\equiv 2 (mod 6)
x\equiv 3 (mod 7)
We'll follow along with each of the steps in Sage.
First, I'll make sure I know all my initial constants.
xxxxxxxxxx
n_1, n_2, n_3 = 5,6,7
a_1, a_2, a_3 = 1,2,3
N = n_1*n_2*n_3
print n_1, n_2, n_3
print a_1, a_2, a_3
print N
Next, I'll write down all the c_i, the complements to the moduli, so to speak. Remember, c_i=N/n_i.
xxxxxxxxxx
n_1, n_2, n_3 = 5,6,7
a_1, a_2, a_3 = 1,2,3
N = n_1*n_2*n_3
c_1,c_2,c_3 = N/n_1,N/n_2,N/n_3; c_1,c_2,c_3
Now we need to solve for the inverse of each c_i modulo n_i. One could do this by hand. For instance, \begin{equation*}42d_1\equiv 2d_1\equiv 1\text{ (mod }5)\text{ yielding }d_1=3,\text{ since }2\cdot 3=6\equiv 1\text{ (mod }5)\; .\end{equation*} But that is best done on homework for careful practice; in the text, we might as well use the power of Sage.
xxxxxxxxxx
d_1=inverse_mod(42,5); d_2=inverse_mod(35,6);d_3=inverse_mod(30,7)
d_1,d_2,d_3
Now I'll create each of the big product numbers, as well as their sum.
xxxxxxxxxx
n_1, n_2, n_3 = 5,6,7
a_1, a_2, a_3 = 1,2,3
N = n_1*n_2*n_3
d_1=inverse_mod(42,5); d_2=inverse_mod(35,6); d_3=inverse_mod(30,7)
a_1*c_1*d_1, a_2*c_2*d_2,a_3*c_3*d_3; a_1*c_1*d_1+a_2*c_2*d_2+a_3*c_3*d_3
Of course, we don't recognize 836 as our answer. But:
xxxxxxxxxx
n_1, n_2, n_3 = 5,6,7
N = n_1*n_2*n_3
mod(836,N)