 
 
 
 
 
   
 is prime if and only if
 is prime if and only if
 
? p=3 %1 = 3 ? (p-1)! % 3 %2 = 2 ? p=17 %3 = 17 ? (p-1)! %4 = 20922789888000 ? (p-1)! % p %5 = 16
 is prime and prove that
 is prime and prove that 
 .  If
.  If 
 then
the equation
 then
the equation 
 
 .
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 its inverse. 
Thus
,
each with its inverse. 
Thus
 
 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
 
is a composite number  .  Let
.  Let  be a prime divisor
of
 be a prime divisor
of  .  Then
.  Then  , so
, so 
 .  Also,
.  Also,
 
 and
also divide
 and
also divide  , since it would then have to divide
, since it would then have to divide  .
.
  
 , we have
, we have
 
 for 
which
 for 
which 
 .
.Let's test Wilson's Theorem in PARI:
? wilson(n) = Mod((n-1)!,n) == Mod(-1,n) ? wilson(5) %9 = 1 ? wilson(10) %10 = 0 ? wilson(389) %11 = 1 ? wilson(2001) %12 = 0
Warning:  In practice, this is a horribly inefficient way to check
whether or not a number is prime.
 
 
 
 
