For example, if
 , then
, then 
 .
If
.
If  , then
, then 
 
But if
 , then
, then 
 
so
 is composite.  Thus Wilson's theorem could be viewed
as a primality test, though, from a computational point of view, 
it is probably one of the world's least efficient 
primality tests since computing
 is composite.  Thus Wilson's theorem could be viewed
as a primality test, though, from a computational point of view, 
it is probably one of the world's least efficient 
primality tests since computing  takes so many steps.
 takes so many steps.
 , so henceforth we assume
that
, so henceforth we assume
that  .
We first assume that
.
We first assume that  is prime and prove that
 is prime and prove that 
 .  If
.  If 
 then
the equation
 then
the equation 
 
has a unique solution
 .
If
.
If  , then
, then 
 , so
, so 
 , so
, so 
 or
 or 
 , so
, so 
 .  
We can thus pair off the elements of
.  
We can thus pair off the elements of 
 ,
each with their inverse. 
Thus
,
each with their inverse. 
Thus
 
Multiplying both sides by
 proves that
 proves that
 .
.
Next we assume that 
 and
prove that
 and
prove that  must be prime.  Suppose not, so that
 must be prime.  Suppose not, so that  is a composite number.  Let
 
is a composite number.  Let  be a prime divisor
of
 be a prime divisor
of  .  Then
.  Then  , so
, so 
 .  Also,
by assumption,
.  Also,
by assumption,
 
This is a contradiction, because a prime can not divide a number
 and
also divide
 and
also divide  , since it would then have to divide
, since it would then have to divide 
 .
.
  
 .
We have
.
We have
 
where we have paired up the numbers
 for 
which
 for 
which 
 .
.
 , the second column contains
, the second column contains  modulo
 modulo  ,
and the third contains
,
and the third contains
 modulo
 modulo  .  Notice that the first columns contains a prime
precisely when the second and third columns are equal.
(The ... notation indicates indentation in SAGE; you should not type the dots
in explicitly.)
.  Notice that the first columns contains a prime
precisely when the second and third columns are equal.
(The ... notation indicates indentation in SAGE; you should not type the dots
in explicitly.)
sage: for n in range(1,10): ... print n, factorial(n-1) % n, -1 % n 1 0 0 2 1 1 3 2 2 4 2 3 5 4 4 6 0 5 7 6 6 8 0 7 9 0 8
William 2007-06-01