Solving Congruences
Contents
4.3. Solving Congruences#
We know from Section 4.1.3 that working modulo a positive integer forms a special kind of equivalence relation known as a congruence relation. For example, \(4 \equiv 16 \bmod 6\) since \(6 \mid 16 - 4\).
Now, we look to include variables in equivalence relations and solve for those variables.
4.3.1. Linear Congruences#
A linear congruence is an equivalence of the form \(ax \equiv b \bmod m\) where \(x\) is a variable, \(a,b\) are positive integers, and \(m\) is the modulus.
The solution to such a congruence is all integers \(x\) which satisfy the congruence.
Solution to a linear congruence
By inspection we find that \(2 \cdot 3 = 6 \equiv 1 \mod 5\). Therefore, a solution this linear congruence is \(x = 3\). However, notice that \(x=8\) is also a solution since \(2\cdot 8 = 16 \equiv 1 \mod 5\).
In a linear congruence, there are infinitely many possible solutions. In the previouse example we saw that \(x=3\) and \(x=8\) were both solutions. In this case, since \(x=3\) was a solution, then so is every element in the congruence class of \(3\). Recall that the congruence class of \(3\) modulo \(5\) is defined as:
Modular Inverses#
To solve an equation like \(ax = b\) over the reals, we would normally divide through by \(a\), assuming \(a \neq 0\), to get \(x = \frac{b}{a}\). This is equivalent to multiplying both sides by the multiplicative inverse of \(a\). A multiplicative inverse of a number is another number such that their product equals \(1\).
Over the real numbers we have \(a \cdot \frac{1}{a} = 1\) for any \(a\). Therefore, we can solve \(ax = b\) by multiplying both sides by \(\frac{1}{a}\).
Just as over the rational numbers or real numbers, there are (often, but not always) multiplicative inverses when working modulo a number. Given a number \(x\) and a modulus \(m\), the modular multiplicative inverse of \(x\) is another number \(a\) such that \(ax \equiv 1 \mod m\).
Modular inverse
Compute the inverse of \(3\) modulo \(7\).
Similar to linear congruences, there may be many modular inverses of a number. In the previous example, \(5\) was the modular inverse of \(3 \mod 7\). Any number in the congruence class of \(5\) modulo \(7\) is a multiplicative inverse. Moreover, any number in the congruence class of \(5\) modulo \(7\) is a multiplicative inverse of any number in the congruecne class of \(3\) modulo \(7\).
We can use modular inverses to solve linear congruences. Let \(a'\) be the inverse of \(a\) modulo \(m\). Then, we have the following:
Modular inverses may not exist
It may happen that certain numbers do not have multiplciative inverses modulo a particular modulus.
Consider \(2\) modulo \(6\). It does not have an inverse. We can verify this by attempting to multiply \(2\) by each of \(0, 1, 2, 3, 4, 5\).
Theorem 4.3.1 will establish when modular inverses exist.
But when do they not exist? In this case it is because \(\gcd(2,6) \neq 1\). Because of that fact, \(2\) is called a zero-divisor for arithmeitc modulo \(m\).
Computing Modular Inverses#
Finding the modular inverse of a number can be very challenging. It is easy to find by inspection the inverse of \(3 \bmod 8\) (it is \(3\) itself since \(3\cdot3 = 9 \equiv 1 \bmod 8\)).
However, can you find the inverse of \(151 \bmod 951\)?.
An algorithmic process exists to compute modular inverses using the Euclidean algorithm and Bézout relations. This is based on the following theorem.
Theorem 4.3.1
If \(a\) and \(m\) are relatively prime integers with \(m > 1\), then there exists a unique modular inverse \(x\) of \(a\) modulo \(m\) satisfying \(0 < x < m\).
Proof:
We first prove the exitence of \(x\). By hypothesis we have \(\gcd(a,m) = 1\). Therefore, By Bézout’s theorem there exists integers \(s\) and \(t\) such that \(sa + tm = 1\).
We have:
Therefore, \(s = x\) is the modular inverse of \(m\).
Next, we show uniqueness. Assume there exists another modular inverse \(b\) of \(a\). By the definition of modular inverses we have \(xa \equiv 1 \bmod m\) and \(ba \equiv 1 \bmod m\). Therefore, \(xa \equiv ba \bmod m\).
From Theorem 4.2.10, we have \(x \equiv b \bmod m\) since \(\gcd(a,m) = 1\). Therefore, \(x\) is unique for \(0 < x < m\). \(\blacksquare\)
The previous theorem establishes criteria for a modular inverse to exist. The proof of this theorem suggests how to compute the inverses: we compute a Bézout relation betwen the modulus and the number to invert.
Computing an easy modular inverse
Find the inverse of \(3\) modulo \(7\).
Since \(\gcd(3,7) = 1\), an inverse must exist. From Euclidean division we have \(7 = 2\cdot3 + 1\) and thus \(-2\cdot3 + 1\cdot 7 = 1\). Hence, \(-2\) is the Bézout coefficient of \(3\) and \(-2 \equiv 5 \bmod 7\) is the modular inverse of \(3\).
Computing a hard modular inverse
Find the inverse of \(151\) modulo \(951\).
Using the Euclidean algorithm we find:
Therefore, \(\gcd(951,151) = 1\). Morevoer, we can find a Bézout relation between \(951\) and \(151\) via back substitution:
Therefore, the modular inverse of \(151\) modulo \(951\) is \(-296 \equiv 655 \bmod 951\).
Using inverses to solve linear congruences
Solve the following linear congruence by first computing an inverse.
Using inverses to solve linear congruences
First find the inverse of \(57\) modulo \(67\). Use the Euclidean algorithm:
We have \(\gcd(67,57) = 1\) so a modular inverse exists. Then compute the Bézout coefficients:
The inverse of \(57\) modulo \(67\) is \(20\). This yields:
4.3.2. Systems of Linear Congruences#
Consider a system of linear congruences.
Could we find a value of \(x\) that simultaneously satisfies both of these equations?
By inspection, one could find that \(45\) is a possible solution. Indeed, \(7 \mid (45 -3) = 42\) and \(13 \mid (45 - 6) = 39\).
Is there an algorithmic process to find such an \(x\)? Yes!
Chinese Remainder Theorem#
Theorem 4.3.2 (Chinese Remainder Theorem)
Let \(m,n\) be two co-prime integers greater than \(1\). Then,
has a unique solution modulo \(m\cdot n\).
Proof:
Since \(m\) and \(n\) are co-prime, by the Bézout theorem there exists integers \(s,t\) such that:
Then, notice that \(x = bsm + atn\) satisfies the linear congruences:
Now consider uniqueness. Let \(x = y\) and \(x = z\) be two solutions of this system. Then, \(y\) and \(z\) must give the same remainder when divided by \(m\) or divided by \(n\). Therefore, \(m \mid y - z\) and \(n \mid y - z\).
Since \(m\) and \(n\) are co-prime, it follows that \(m\cdot n \mid y -z\) (see Exercise 4.18). Therefore \(y \equiv z \bmod m\cdot n\). \(\blacksquare\)
Let’s try an example.
A system of linear congruences.
Find all integers \(x\), \(0 \leq x < 15\) such that:
Since \(3\) and \(5\) are co-prime, Chinese Remainder Theorem states there exists a unique solution modulo \(15\). Therefore, there is exactly one solution \(x\) with \(0 \leq x < 15\).
Apply the Euclidean algorithm to find \(s,t\) such that \(3s + 5t = 1\). Or, by inspection, we see \(3(2) + 5(-1) = 1\) implies \(s = 2\), \(t = -1\).
Therefore, \(x = 2(3s) + 1(5t) = 2(3)(2) + 1(5)(-1) = 7 \equiv 7 \bmod 15\).
Solve a system of linear congruences
Solve the system of linear congurences presented at the beggining of this section for \(0 \leq x < 91\) using the Chinese Remainder Theorem.
Solve a system of linear congruences
Surely \(7\) and \(13\) are co-prime since they are both prime. Therefore, there exists \(s,t\) such that \(7s + 13t = 1\). By inspection we see \(s = 2\) and \(t = -1\).
Therefore, a solution is \(x = 6(7s) + 3(13t) = 84 - 39 = 45\).
We verify this by seeing that \(7 \mid 45 - 3 = 42\) and \(13 \mod 45 - 6 = 39\).
4.3.3. Exercises#
Find the multiplicative inverse of:
\(8\) modulo \(17\).
\(9\) modulo \(23\).
\(11\) modulo \(71\).
Prove the following lemma.
Lemma 4.3.3
Let \(m\) and \(n\) be co-prime integers.
For any integer \(x\) such that \(m \mid x\) and \(n \mid x\), then \(mn \mid x\).
Solution to Exercise 4.18
By hypothesis \(m \mid x\) and \(n \mid x\), therefore there exists integers \(q_m, q_n\) such that \(x = mq_m\) and \(x = nq_n\). Hence \(mq_m = nq_n\).
Since \(m\) and \(n\) are co-prime there exists \(s\) and \(t\) such that \(sm + tn = 1\).
Therefore, we have \(smq_m + tnq_m = q_m\) and, combining with our hypotheses, gives \(snq_n + tnq_m = q_m\) and thus \(n(sq_n + tq_m) = q_m\).
From \(x = mq_m\) we get \(x = mn(sq_n + tq_m)\). Hence, \(mn \mid x\). \(\blacksquare\)
Solve the following linear congruences. Give the unique positive solution which is less than the modulus.
\(x \equiv 12 \mod 7\)
\(2x \equiv 12 \mod 7\)
\(13x \equiv 15 \mod 23\)
Solution to Exercise 4.19
\(5\)
\(6\)
\(10\)
Solve the following system of linear congruences for \(0 \leq x < 77\).
Solution to Exercise 4.20
Computing modular inverses gives:
By CRT we have \(x \equiv 19 \mod 77\).
Solve the following system of linear congruences for \(0 \leq x < 221\).
Solution to Exercise 4.21
Computing modular inverses gives:
By CRT we have \(x \equiv 97 \mod 77\).