Wilson's theorem

Wilson's theorem
In algebra and number theory, Wilson's theorem states that a natural number n > 1 is a prime number if and only if the product of all the positive integers less than n is one less than a multiple of n. That is (using the notations of modular arithmetic), the factorial satisfies
exactly when n is a prime number. In other words, any number n is a prime number if, and only if, (n − 1)! + 1 is divisible by n.
History
This theorem was stated by Ibn al-Haytham (c. 1000 AD), and, in the 18th century, by the English mathematician John Wilson. Edward Waring announced the theorem in 1770, although neither he nor his student Wilson could prove it. Lagrange gave the first proof in 1771. There is evidence that Leibniz was also aware of the result a century earlier, but he never published it.
Example
For each of the values of n from 2 to 30, the following table shows the number (n − 1)! and the remainder when (n − 1)! is divided by n. (In the notation of modular arithmetic, the remainder when m is divided by n is written m mod n.)
The background color is blue for prime values of n, gold for composite values.
Proofs
The proofs (for prime moduli) below use the fact that the residue classes modulo a prime number are a field—see the article prime field for more details. Lagrange's theorem, which states that in any field a polynomial of degree n has at most n roots, is needed for all the proofs.
Composite modulus
If n is composite it is divisible by some prime number q, where . Because divides , let for some integer . Suppose for the sake of contradiction that were congruent to where n is composite. Then (n-1)! would also be congruent to −1 (mod q) as implies that for some integer which shows (n-1)! being congruent to -1 (mod q). But (n − 1)! ≡ 0 (mod q) by the fact that q is a term in (n-1)! making (n-1)! a multiple of q. A contradiction is now reached.
In fact, more is true. With the sole exception of 4, where 3! = 6 ≡ 2 (mod 4), if n is composite then (n − 1)! is congruent to 0 (mod n). The proof is divided into two cases: First, if n can be factored as the product of two unequal numbers where 2 ≤ a < b ≤ n − 2, then both a and b will appear in the product and (n − 1)! will be divisible by n. If n has no such factorization, then it must be the square of some prime q, q > 2. But then 2q < q2 = n, both q and 2q will be factors of (n − 1)!, and again n divides (n − 1)!.
Prime modulus
Elementary proof
The result is trivial when , so assume p is an odd prime, . Since the residue classes (mod p) are a field, every non-zero a has a unique multiplicative inverse, a−1. Lagrange's theorem implies that the only values of a for which are (because the congruence can have at most two roots (mod p)). Therefore, with the exception of ±1, the factors of can be arranged in disjoint pairs such that product of each pair is congruent to 1 modulo p. This proves Wilson's theorem.
For example, for , one has
Proof using Fermat's little theorem
Again, the result is trivial for p = 2, so suppose p is an odd prime, . Consider the polynomial
g has degree , leading term , and constant term . Its roots are 1, 2, ..., .
Now consider
h also has degree and leading term . Modulo p, Fermat's little theorem says it also has the same roots, 1, 2, ..., .
Finally, consider
f has degree at most p − 2 (since the leading terms cancel), and modulo p also has the roots 1, 2, ..., . But Lagrange's theorem says it cannot have more than p − 2 roots. Therefore, f must be identically zero (mod p), so its constant term is . This is Wilson's theorem.
Proof using the Sylow theorems
It is possible to deduce Wilson's theorem from a particular application of the Sylow theorems. Let p be a prime. It is immediate to deduce that the symmetric group has exactly elements of order p, namely the p-cycles . On the other hand, each Sylow p-subgroup in is a copy of . Hence it follows that the number of Sylow p-subgroups is . The third Sylow theorem implies
Multiplying both sides by gives
that is, the result.
Applications
Primality tests
In practice, Wilson's theorem is useless as a primality test because computing (n − 1)! modulo n for large n is computationally complex, and much faster primality tests are known (indeed, even trial division is considerably more efficient).
Used in the other direction, to determine the primality of the successors of large factorials, it is indeed a very fast and effective method. This is of limited utility, however.
Quadratic residues
Using Wilson's Theorem, for any odd prime , we can rearrange the left hand side of
to obtain the equality
This becomes
or
We can use this fact to prove part of a famous result: for any prime p such that p ≡ 1 (mod 4), the number (−1) is a square (quadratic residue) mod p. For this, suppose p = 4k + 1 for some integer k. Then we can take m = 2k above, and we conclude that (m!)2 is congruent to (−1) (mod p).
Formulas for primes
Wilson's theorem has been used to construct formulas for primes, but they are too slow to have practical value.
p-adic gamma function
Wilson's theorem allows one to define the p-adic gamma function.
Gauss' generalization
Gauss’ generalization of Wilson’s Theorem states that if is four, an odd prime power, or twice an odd prime power, then the product of relatively prime integers less than itself add one is divisible by . It goes further to say that otherwise, the same product subtract one is divisible by .
To state Gauss' Generalization of Wilson's Theorem, we use the Euler's totient function, denoted , which is defined as the number of positive integers less than or equal to which are also relatively prime with . Let's call such numbers , where .
Gauss proved given an odd prime and some integer , then
.
First, let's note this is the proof for cases , since the results are trivial for .
For all , we know there exist some , where and , such that . This allows us to pair each of the elements together with its inverse. We are left now with being its own inverse. So in other words is a root of in , and , in the polynomial ring . If is a root, it follows that is also a root. Our objective is to show that the number of roots is divisible by four, unless , or .
Let's consider . Then we notice we have one root since .
Consider . Then, it is clear there are two roots, specifically, and .
Say . It is again clear there are two solutions.
We now consider . If one of the factors of is divisible by 2, so is the other. Take the factor to be divisible by . Then, it follows that there are 4 distinct roots of , namely , and , when .
Finally, let's look at the general case where . We find 2 roots of over each and , except when . Using the Chinese remainder theorem, we find that when is not divisible by 2, we have a total of solutions of . Assuming , in , we have one root, so we still have a total of solutions. When , we have 2 roots in , so there are a total of roots of . For all cases where , there are 4 roots in with a total of solutions. This shows that the number of roots are divisible by 4, unless , or .
Say is a root of in . Then . So, if the number of roots of is divisible by 4, then we can say the product of the roots if 1. Otherwise, we can say the product is -1. So we can conclude that
.
See also
Wilson prime
Table of congruences
Notes
References
The Disquisitiones Arithmeticae has been translated from Gauss's Ciceronian Latin into English and German. The German edition includes all of his papers on number theory: all the proofs of quadratic reciprocity, the determination of the sign of the Gauss sum, the investigations into biquadratic reciprocity, and unpublished notes.
.
.
.
External links
Mizar system proof: http://mizar.org/version/current/html/nat_5.html#T22
Modular arithmetic
Factorial and binomial topics
Articles containing proofs
Theorems about prime numbers
Primality tests