Modular Inverse
In modular arithmetic, a modular inverse exists for every , such that , if and only if (i.e., and must be coprime). The easiest way to find the greatest common divisor of two integers is using Euclid’s Algorithm, which recursively divides the integers based on the identity
and terminates when the remainder becomes zero.The Extended Euclidean Algorithm not only computes , but also performs a backward pass to find (not necessarily distinct) integers , which satisfy Bezout’s identity,
It is executed as follows:
- Set the starting pair and .
- While (forward pass / standard Euclid):
- Let and .
- Now set and .
- Then, for (backward pass):
- Let and .
- When you are done, you will have the coefficients and factor that solve .
Proof & Intuition
Inversion
Here is where modular arithmetic gets a little tricky. We will go ahead and prove necessity and sufficiency for inversion:
- Sufficiency (): Since and are coprime, neither can divide the other. Enter Bezout’s Identity, which states that . We take both sides modulo , and obtain As such, we find that is the inverse of . You can think of as the “correction term” for the linear Diophantine, although it has no modular meaning unless we rearrange and , such that is the inverse of .
- Necessity () We have that . Then by definition of modular congruence, there exists an integer (quotient) such that: . Rearranging, per Bezout’s identity.
Intuitively, why is the condition for modular inversion? Think about it this way: if and shared a common factor , then that must be able to divide any linear combination of and .
Euclid’s Algorithm
The statement above will help us prove the fact that . In order to see it, express . Then, if divides and , then also divides , as well as when rearranging. Now plug and and try it yourself.
Extended Euclid
Now, let’s switch gears to extended Euclid.
Properties
(Divisibility) Let , such that . If , then .
(Prime Modulus) If is a prime number, all numbers have a modular inverse.
(Fermat’s Little Theorem) For all primes , if , and for all .
Examples
(Easy) Finding Inverses
We will investigate the existence and uniqueness of inverses:
Is 3 an inverse of 5 modulo 14? , the answer is yes.
Since
Is 3 an inverse of 5 modulo 10? (also because ).
No, since
For all , is an inverse of 5 modulo 14? We have that , so yes.
Does 4 have an inverse modulo 8? .
No, because
(Easy) Inverse Proofs
Prove or disprove the following statements:
There exists some such that and . Let and . Then, and , which is a contradiction. Therefore,y this statement is false.
The congruence is equivalent to . We can divide both sides by (using the modular inverse) if and are coprime. However, , which means that naive division does not work here. As a counterexample, consider .
The congruence is equivalent to . Let . Then, , which is true.
The congruence has a solution. The easy way out is to say that , and so there is no solution.
For a more intuitive understanding, consider the congruence . Since , we must check whether divides the right-hand side. But , so there is no solution–the congruence is inconsistent modulo . In other words, for any solution to exist, both sides must be divisible by . Since does not divide , no value of will satisfy the equation modulo .
Let be inverses of modulo . Is it possible that ?
(Medium) Proving the Fundamental Theorem of Arithmetic
Prove that every integer greater than 1 can be written uniquely as a product of (not necessarily unique) prime numbers, up to the order of the factors.
Solution. . We leverage Bezout's Identity,
In other words, FTA states that any number can be expressed as
(Medium) Iterative EGCD!?
In this example, we explore an alternative way of finding the triple in an iterative, rather than a recursive way.
How Many Solutions?
Consider the equation for prime . In the below three parts, all values , , are defined as values in the range . In addition, include justification for your answers to all the subparts of this problem.
For how many pairs does the equation have (1) a unique solution, (2) no solution, (3) solutions? (1) Since for all , there are exactly values of such that . Then, supports all values in the set . As such, there are value pairs of that have a unique solution.
(2) In order for to have no solution, must not have an inverse. In the set , the only value of that has no solution is . Set to , and can be any of the nonzero elements. Therefore, there are exactly pairs with no solution.
(3)