Section 9.3 Using Euler's Theorem
Euler's Theorem has many uses, especially theoretical ones we will use throughout. We will begin with its use in some computations we are already familiar with; see Section 10.5 for some more interesting computational uses.
Subsection 9.3.1 Inverses
We can use it to compute inverses mod \((n)\text{,}\) with just a little cleverness. If
then certainly multiplying both sides by \(a^{-1}\) yields
We can check this using Sage.
Example 9.3.1.
Let's pick a congruence we wanted to solve earlier, like
and try to solve it this way. Instead of all the stuff we did before, we could just multiply both sides by the inverse of 53 in this form.
Now using Theorem 9.2.5, we get
One could conceivably do this power by hand using our tricks for powers; using a computer, it would look like the following in Sage.
This answer jells with our previous calculation. Better, I didn't have to solve a different linear congruence in order to solve my original one; I just had to have a way to do multiplication mod \((n)\text{.}\)
Sage note 9.3.2. Euler phi in Sage.
Notice that Sage has a command to get the Euler phi function, namely euler_phi(n)
. This doesn't have the direct connection to the group, but is easier to use than Integers(n).unit_group_order()
.
Subsection 9.3.2 Using Euler's theorem with the CRT
We can use this to do Chinese Remainder Theorem systems much more easily, as long as we have access to \(\phi\text{.}\)
Remember the algorithm for the CRT, where we tried to solve systems like this:
\(x\equiv a_1\) (mod \(n_1\))
\(x\equiv a_2\) (mod \(n_2\))
\(\displaystyle \cdots\)
There, we had to calculate many solutions to congruences of the form
(This was to get the \(d_i\) numbers.) Our new information means that this inverse is just
since we are looking at a congruence modulo \(n_i\text{.}\)
So the things in the final solution which looked like
can be thought of as
which is much cooler and simpler! So the answer to the general system is just
Sage note 9.3.3. More complex list comprehension.
It's possible to do the previous work more concisely, no matter how many congruences you have, if you know a little Python and recall from Sage note 4.6.2 the little something called a ‘list comprehension’.
But that's not necessary for our purposes.
Example 9.3.4.
We can do this one step even better. Take a huge system like
\(3x\equiv 7\) (mod \(10\))
\(2x\equiv 5\) (mod \(9\))
\(4x\equiv 1\) (mod \(7\))
Can we find solutions for this using the same mechanism? Yes, and without too much difficulty now.
Since one can solve \(bx\equiv c\) (mod \(n\)) with
any likely system of congruences with coprime moduli
where \(N\) is the product of the moduli could be solved by
Let's use this to solve this system; we print a few intermediate steps.
Notice that we make as much stuff modulo \(M\) to begin with as possible. Even for bigger numbers, asking Sage to first make things modular is a big help – it takes essentially no time!
Example 9.3.5.
We can demonstrate this with much larger examples, picking essentially random large primes \(m_i\) to compute with.
\(3x\equiv 7\) (mod \(m_1\))
\(2x\equiv 5\) (mod \(m_2\))
\(4x\equiv 1\) (mod \(m_3\))
In the first one, we choose primes in the ten thousands.
It's worth trying to time this – recall that we can use %time
for this in notebooks, see Sage note 4.2.1. The second example uses primes in the millions range.