This lecture will focus on Wilson’s Theorem. Let \(m\) be an integer. Consider the following
Trying different values for \(m\), we see the following pattern
\(m\) | \(m - 1\) | \((m - 1)! \bmod m\) |
---|---|---|
\(1\) | \(0\) | \(1\) |
\(2\) | \(1\) | \(-1\) |
\(3\) | \(2\) | \(-1\) |
\(4\) | \(6\) | \(2\) |
\(5\) | \(24\) | \(-1\) |
\(6\) | \(120\) | \(0\) |
\(7\) | \(720\) | \(-1\) |
\(8\) | \(5040\) | \(0\) |
\(9\) | \(40320\) | \(0\) |
Observe here that \((m-1)! \bmod m\) is \(-1\) when \(m\) is prime. This is precisely Wilson’s Theorem. We state it again as follow
Next, we will see an example to informally show why this theorem works.
Informal Proof
Let’s start with finding \((11-1)! \pmod{11}\). We can expand \((11-1)!\) to see that
We can pair the numbers together to see that
Therefore
Also note here that \(1\) is its own inverse module \(11\). Similarly, \(10\) is its own inverse module \(11\). This is the reason they were the ones left over at the end. In general, given \(a\), if \(a \neq a^{-1}\), we see that they cancel. When \(a^{-1} = a\), they don’t cancel. Moreover, we see that in this case
But \(11\) is prime so either \(a - 1 \equiv 0 \pmod{11}\) or \(a + 1\equiv 0 \pmod{11}\) (Reminder: this is because \(ab \equiv 0 \pmod {p}\) means that \(p\) divides \(ab\) but \(p\) is prime so it must divide \(a\) or \(b\) or both). Therefore,
We can now generalize this for any prime \(p\). The expansion of \((p-1)!\) is
All the numbers in the middle from \(2\) to \(p-2\) will pair off. What remains is
This is great because now we have another test for primality as follows
But this test is totally useless! since it’s hard to figure out \((m-1)! \bmod m\) without knowing whether \(m\) itself is prime to be able to use Wilson’s theorem. In general, it is hard to compute \(a! \bmod m\)
When \(m\) is not Prime
What if \(m\) is not prime? From the table above, can we conclude that
Since \(m\) is not prime, then we can write
\(a\) and \(b\) are strictly less than \(m\). This means that they must show up in the expansion of \((m-1)!\). But this means that
which makes the claim correct. However this is not true in general. Take \(m = 4\). Then \(4 = 2 \cdot 2\). The issue here that the two factors are exactly the same so the argument above doesn’t work. Exercise: work out the argument for when \(m\) is composite and \(m \neq 4\). This should work even though some numbers do have square factors.
Application 1: Square Root of \(-1\)
Over \(\mathbb{R}\), we don’t have a solution. Over \(\mathbb{C}\), there is a solution but we’re not interested in that. We’re interested in a solution over \(\mathbb{Z}_p\). So does \(-1\) have a square root module \(p\) when \(p\) is prime? This statement is equivalent to solving
Square both sides to see that
so \(x\) has order \(4\). But by Fermat’s Theorem and since \(p\) is prime, we know that
We also know from the last lecture that the order of \(x\) must divide \(p - 1\). So this means that we must have \(4 \mid p - 1\). We can then write this as
So to have a solution \(p\) must be congruent to \(1\) module \(4\). So now the problem can be stated as
Checking a few cases. Take \(p = 5, 13, 17 \cdots\). We will see that
Things seem to work. Can we prove that this work in general? yes, It turns out that
Why? Take \(p = 13\). The expansion of \((13-1)!\) is
Now, \(\left(\frac{p-1}{2}\right)!\) is the product of the first \(6\) elements above. But these \(6\) elements pair off with the remaining \(6\) numbers (except for the sign) meaning that
Therefore, we can write
But by Wilson’s theorem, we know that
Thus
In other words,
Recall that
so \(p - 1 = 4k\) for some \(k\). Therefore
So \(\frac{p-1}{2}\) is even. Therefore In other words,
as we wanted to show. \(\blacksquare\)
So now we might ask
Again, we have the same equation
But we can see here that \(p = 4k + 3\). Therefore,
Thus, \(\frac{p-1}{2}\) is now odd and not even. Therefore
But this means that we have two solutions so
Both cases can occur. For example when \(p = 3\), then this a square root of \(-1\) while if \(p = 7\), then this is a square root of \(1\).
Application 2: Proof of Fermat / Euler
We can use the same idea to try to prove Fermat/Euler’s theorems.
Proof: consider the product
and then compare this against
Since we’re working module \(p\), then the numbers above are exactly the same as the first product but just in a different order. So
But now observe that we can group these factors in a way to get
Recall that Wilson’s theorem that states that
Therefore
And so we proved Fermat’s theorem. We can use the same technique to prove Euler’s theorem. It’s the same proof except but we want to multiply all numbers coprime to \(m\).
Application 3
Suppose now that \(m\) is not prime.
We always want to look at examples first.
\(m\) | Coprime numbers to \(m\) | \(\prod \bmod m\) |
---|---|---|
\(1\) | \(1\) | \(1\) |
\(2\) | \(1\) | \(-1\) |
\(3\) | \(1,2\) | \(-1\) |
\(4\) | \(1,3\) | \(-1\) |
\(5\) | \(1,2,3,4\) | \(-1\) |
\(6\) | \(1,5\) | \(-1\) |
\(7\) | \(1,2,3,4,5,6\) | \(-1\) |
\(8\) | \(1,3,5,7\) | \(1\) |
\(9\) | \(1,2,4,5,7,8\) | \(-1\) |
So for some reason the product module \(m\) when \(m = 8\), is \(1\) and not \(-1\). So what is the product of all residue classes coprime to \(m\) module \(m\)? We can use the same trick of pairing out elements. Recall that if \(a \neq a^{-1}\), then the product is \(a^{-1}a \equiv 1 \pmod{m}\) so these elements will cancel out. Then, we’re left with all the elements such that \(a = a^{-1}\). In this case, these elements don’t cancel out with anything. So now the product looks like
Suppose now that there is only one number such that \(a \neq 1\) and \(a = a^{-1}\). In this case, \(a\) must be \(-1\) since \(a^2=(-1)^2 = 1\). Then, in this case we get Wilson’s theorem.
What if there are other numbers? So suppose that there is one more number \(a\) such that \(a \neq \pm 1\) and \(a^2 \equiv 1 \bmod m\). Then, we have the following
Furthermore, if we re-consider \(-1, 1\), then we have 4 numbers \(\{1, -1, a, -a\}\) such that \(x^2 \equiv 1 \pmod{m}\). . In this case, the product
So for \(m = 8\)
Now, what if there are even more numbers than just 4 numbers? So we have \(a \neq \pm 1\) such that \(a^2 \equiv 1\). Suppose now, we also have \(b^2 \equiv 1\). But then we get these additional numbers that are congruent to \(1\) (This is in addition to the numbers we found earlier \(\{-a,a,-1,1\}\). The product of the new numbers is also congruent to 1.
So whenever we add a new number such that \(c^2 \equiv 1\), we get 4 new numbers. This will make the product congruent to 1 every time. Therefore,
Thus
It is \(-1\) if \(-1\) is the only solution to \(x^2 \equiv 1\) and it is 1 if there are more solution to \(x^2 \equiv\) other than \(-1\).