You are on page 1of 5

Chapter 5: Fermat’s Little Theorem 6

SECTION B Wilson’s Theorem

By the end of this section you will be able to


 prove Wilson’s Theorem
 apply Wilson’s Theorem

Wilson’s result applies to prime moduli. So like Fermat’s Little Theorem we confine
ourselves to prime modulus. For Wilson’s Theorem the result is valid both ways, that is the
result is true going forwards (necessary)  and backwards (sufficient)  . This is not the
case for Fermat’s Little Theorem.
Example 5
Find x in each of the following congruences:
(a) x  4!  mod 5  (b) x  6!  mod 7 
Solution
(a) Remember 4!  1 2  3  4  24 and 24 is 1 modulo 5. Hence
x  1  mod 5 
(b) Similarly we have 6 !  1 2  3  4  5  6  720 and
x  720  6  1  mod 7 
These evaluations were nice and easy but evaluating n ! for a large n will be a tedious task.
We want to find a simpler way of evaluating this n !
We can be smart about these evaluations and use the concept of multiplicative inverse as
described below.
The proof of Wilson’s Theorem relies on the multiplicative inverse in modular arithmetic.
B1 Multiplicative Inverse
Can you recall what a multiplicative inverse means?
This was Definition (4.15) on page 22 of the last chapter
If ax  1  mod n  and gcd  a, n   1 then the unique solution x is called the multiplicative
inverse of a modulo n.
1 1
Just like the inverse of 5 in real numbers is because 5    1 similarly the inverse of a
5 5
modulo n is the residue x such that ax  1  mod n  .

Example 6
Determine x in following congruence:
x  12!  mod 13
Solution
Remember
x  12!  1 2  3  4  5  6  7  8  9 10 1112  mod 13 (*)
Note that if we multiply the first and last elements on the RHS of (*) we have
1 12  12  1  mod 13
Can we carry out some simplification of the remaining numbers 2, 3, 4, 5 , 6, 7, 8 , 9, 10 and
11 on the RHS?
Chapter 5: Fermat’s Little Theorem 7

We are dealing with a prime modulus, 13. If a  2, 3, 4,  , 11 and we know


gcd  a, 13  1 then by the above definition of multiplicative inverse, each of these a’s will
have an inverse. For example
2  7  14  1  mod13
The multiplicative inverse of 2 is 7 modulo 13. Similarly we can pair up other numbers:
3  9  27  1  mod 13
4 10  40  1  mod 13
5  8  40  1  mod 13
6  11  66  1  mod 13
Substituting these into (*) gives
x  12!  112    2  7    3  9    4  10    5  8    6 11  mod 13
      
1 mod13 1 mod13 1 mod13 1 mod13 1 mod13

  1  1  1   1  mod 13


 1  mod 13
We use these concepts of pairing residues with its inverse in the derivation of Wilson’s
Theorem. Before we derive this important theorem we need another result.
B2 Wilson’s Theorem
We need to use the following lemma to prove Wilson’s Theorem.
Lemma (5.3).
Let p be prime then
x 2  1  mod p   x  1  mod p 
What does this result mean?
Means that the modular multiplicative inverse of x modulo p is x modulo p. This x is its own
inverse. Comparing with real numbers the inverse of 1 or 1 is 1 or 1 respectively.
How do we prove this result?
We have the symbol  so we need to prove this both ways.
Proof.
   . We can assume x 2  1  mod p  . From this we have
x 2  1  0  mod p 
 x  1 x  1  0  mod p 
Applying Proposition (4.12) on page 13 of the last chapter:
If ab  0  mod p  where p is prime then a  0  mod p  or b  0  mod p  .
We have
x  1  0  mod p  or x  1  0  mod p 
x  1 mod p  or x  1 mod p 
Hence from x 2  1  mod p  we have x  1  mod p  .
   . We assume x  1  mod p  . Squaring this gives
x 2   1  1  mod p 
2


Chapter 5: Fermat’s Little Theorem 8

In the above Example 13 the congruence in Lemma (5.3) x  1  mod p  corresponds to


x  1  mod 13 , x  12  1  mod 13
The modular inverse of 12  mod 13 is 12  mod 13 because
12  12  144  1 mod 13
We are now in a position to prove Wilson’s Theorem.
Wilson’s Theorem (5.4).
If p is prime then
 p  1!  1  mod p 
How do we prove this result?
First we establish the result for the first two primes - p  2 and p  3 then we prove the
result for the remaining primes.
Proof.
Let p  2 or p  3 then
 2  1!  1  1  mod 2 
 3  1!  2  1  mod 3
The result holds for p  2 and p  3 .
Now let the prime p  5 and consider the least non-negative residues modulo p:
1, 2, 3, 4, … , p  1
By the above Lemma (5.3) we know that the first and last numbers in this list, 1 and p  1 , is
its own inverse. The inverse of the remaining residues 2, 3, 4, …, p  2 is another number in
this list. Why?
Consider the linear congruence
ax  1  mod p  where a  2, 3, 4,  , p  2
Since gcd  a, p   1 so this linear congruence ax  1  mod p  has a unique solution
x  b  mod p  where b  a  mod p  because each of the a  2, 3, 4,  , p  2 is not its own
inverse. This means that residues a and b can be paired up amongst the list
2, 3, 4,  , p  2
such that ab  1  mod p  . Hence we have
2  3  4    p  2   1  mod p 

  p  2 !

 p  2 !  1  mod p 
Therefore we have required result:
 p  1!   p  1
p  2  !  mod p 
 
1  mod p 

  p  1  1 mod p 

Example 6
Determine x in each of the following congruences:
(a) x  16!  mod 17  (b) x  11!  mod 12  (c) x  9!  mod 13
Solution
Chapter 5: Fermat’s Little Theorem 9

(a) Since 17 is a prime, by Wilson’s Theorem we have


x  16!  1  mod 17 
(b) 12 is not prime so we cannot use Wilson’s Theorem. We have
 4  5  6  7  8  9 10  11  mod 12 
x  11!  2  3
12

 0  mod 12 
(c) 13 is prime but we need to find 9! not 12! Need to use brute force to evaluate x:
x  9!  mod 13
 2
4  5
3  6  7  8
9  mod 13
24 2 mod 13 30  4 mod 13 72  7 mod 13

  2   4  7
7  mod 13
49 3 mod 13

  2   4   3  24  11 mod 13

B3 Converse of Wilson’s Theorem


The converse of Wilson’s Theorem is also true. What does this mean?
Means that if  n  1 !  1  mod n  then n is prime. We need to prove this result.
Converse of Wilson’s Theorem (5.5).
If  n  1 !  1  mod n  then n is prime.
How do we prove this result?
Using proof by contradiction.
Proof.
Suppose n is composite. This means that n has a divisor d or d n such that 1  d  n . We
are given that  n  1 !  1  mod n  which means n  n  1 ! 1 . Since d n so
d  n  1 ! 1 which gives dk   n  1 ! 1 for some integer k
We also have d lies between 1 and n because 1  d  n . Therefore
d  n  1 ! which implies that dm   n  1 ! for some integer m
Substituting dm   n  1 ! into dk   n  1 ! 1 gives
dk  dm  1
d  k  m  1  Factorising 
From the last line d  k  m   1 we have d 1 , d divides 1. This is impossible. Why?
Because in the first line of the proof we have 1  d  n which means d is greater than 1.
We have a contradiction to our supposition so n cannot be composite which means it must be
prime.

Can you think of an application where Theorem (5.5) may be useful?
It can used to test for prime numbers because if  n  1 !  1  mod n  then we conclude that
n is prime. However this is not very practical. Why not?
 n  1! becomes very large even for some values of n. It is easier to use trial division rather
than the converse to Wilson’s Theorem. However there are more efficient ways of testing for
prime numbers than any of these methods.
Chapter 5: Fermat’s Little Theorem 10

SUMMARY
Wilson’s Theorem
 n  1!  1  mod n   n is prime
Useful result for simplifying calculations involving prime modulus.

You might also like