2

This is very similar to: Chinese Remainder Theorem Problem in that in applying an algorithm, I get an incorrect answer and do not see where my mistake lies.

One of the answers to the question linked to above noted that there are many different algorithms circulating for solving the CRT. The one I am using is similar to that used above, but not exactly the same. I got mine from Chapter 33 of Algorithms, by Cormen, Leiserson, and Rivest.

The problem is to find z that satisfies $$3\ mod\ 8$$ $$7\ mod\ 21$$ $$22\ mod\ 25$$ $$2\ mod\ 11$$

Since 8, 21, 25, and 11 are relatively prime, there is a solution.

The method hinges on finding constants $c_1, .., c_4$ in the following manner. Let $(a_1, .., a_4) = (3, 7, 22, 2)$, and $(n_1,..,n_4) = (8, 21, 25, 11)$. $n$ is the product of the $n_i$: Here 46200. Define $(m_1,..,m_4)$ by dividing out $n_i$ from $n$, e.g. ($\frac{46200}{8}, \frac{46200}{21}, \frac{46200}{25}, \frac{46200}{11}$), or $(5775, 2200, 1848, 4200)$.

Find $(m_i^{-1}\ mod\ n_i)$. For the $m_i$ given these calculations are below. By way of explanation, in the calculation below for $m_1^{-1}$, $m_1 + 1 = 5775 + 1 = 5776$ is divisible by $8$, which is true (in other words that 1 is the inverse of 5775 in the mod 8 equivalence class). $$m_1^{-1}\ mod\ 8 = 1$$ $$m_2^{-1}\ mod\ 21 = 5$$ $$m_3^{-1}\ mod\ 25 = 2$$ $$m_4^{-1}\ mod\ 11 = 2$$.

The constants $c_i$ are now formed from the $m_i$ and the inverses just found $(1, 5, 2, 2)$ by multiplying corresponding pairs: $(1 \cdot 5775, 5 \cdot 2200, 2 \cdot 1848, 2 \cdot 4200)$, or ($5775, 11000, 3696, 8400$).

Finally, one solves $$a = (a_1 \cdot c_1 + .. + a_4 \cdot c_4)\ mod\ n$$ to get $$(3 \cdot 5775 + 7 \cdot 11000 + 22 \cdot 3696 + 2 \cdot 8400)\ mod\ 46200$$

I get as one of the solutions for this the number $a = 7637$.

However 7637 does not work! For example, $7637\ mod\ 8 = 5$, whereas to be a solution it must be true that $7637\ mod\ 8 = 3$.

If someone can point out what I am doing wrong, I would greatly appreciate it!

2 Answers2

1

The multiplicative inverse, $a^{-1} \pmod n$ is defined as : $a^{-1}a\equiv 1\pmod{n}$

To find $m_1^{-1}\pmod{8}$, you need to solve below congruence : $$\color{blue}{m_1x\equiv 1\pmod{8}}$$

and not $$\color{red}{m_1 + x \equiv 0 \pmod{8}}$$

Hence, you will get $$\color{blue}{x\equiv 7 \pmod{8}} $$

and not

$$\color{red}{ x \equiv 1 \pmod{8}}$$

AgentS
  • 12,195
1

The arithmetic is usually easier if you solve congruences successively in pairs instead of in parallel. Start off with $\,x = 22+25i\,$ by $\,x\equiv 22\pmod{\!25}.$ Substitute that into $\,x\equiv 7\pmod{\!21},$ solve for $\,i$ to get a new value for $\,x,\,$ substitute that into next congruence, etc, i.e.

${\rm mod}\ 21\!:\ 7 \equiv 22+25\,\color{#c00}i\equiv 1+4i\!\iff\! 4i\equiv 6\!\iff\! 2i\equiv 3\iff\! \smash[t]{\overbrace{\color{}i\equiv 3/2\equiv 24/2\equiv \color{}{12}}^{\Large \color{#c00}{i\, =\, 12}\, +\, 21j}}\phantom{1^{1^{1^{1^{1^(1^1}}}}}$

${\rm mod}\ 11\!:\ 2\equiv 22+25(\color{#c00}{12}+21\color{#0a0}j)\,\equiv\, 3(1-j)\iff 3j\equiv 1\iff\! \smash[b]{\underbrace{\color{}j\equiv 1/3\equiv 12/3\equiv \color{}4}_{\Large\color{#0a0}{j\,=\, 4}\,+\,11k}}$

${\rm mod}\,\ \ 8\!:\ 3\equiv 22+25(12+21(\color{#0a0}4+11k))$ $\qquad\qquad 3 \equiv -2\ \ +\ (\ \ 4\ -\ 3(4\,+\ \,3\color{#c0f}k)) \equiv\, {-}2-k \iff \smash[b]{\underbrace{\color{}k\equiv-5\equiv \color{}3}_{\Large \color{#c0f}{k\,=\,3}\,+\,8n}}$

$\!\begin{align}{\rm Hence}\ \ x\equiv &\ \ 22+25(12+21(4+11(\color{#c0f}3+8n)))\\ =&\ \ 19747+46200 n\end{align}$

Notice that this way all the numbers are so small that all the arithmetic can be done mentally, except possibly for the final additions and multiplications in the last line.

Bill Dubuque
  • 272,048