ArticleslgStudy

mathematics

Wilson's theorem

Wilson's theorem is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Wilson's theorem rather than just read about it. In short: 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 (n−1)!=1×2×3×⋯×(n−1) satisfies (n−1)! ≡−1(modn) exactly when n is a prime number.

Key takeaways

  • Wilson's theorem belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Wilson's theorem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Wilson's theorem from memory before moving on to harder problems.

Reference excerpt

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 (n−1)!=1×2×3×⋯×(n−1) satisfies

(n−1)! ≡−1(modn) exactly when n is a prime number. In other words, any integer n > 1 is a prime number if, and only if, (n − 1)! + 1 is divisible by n.

History The theorem was first stated by Ibn al-Haytham c. 1000 AD. Edward Waring announced the theorem in 1770 without proving it, crediting his student John Wilson for the discovery. Lagrange gave the first proof in 1771. There is evidence that Leibniz was also aware of the result a century earlier, but 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.) As expected, (n−1)! ≡n−1mod n when n is prime. The background color is blue for prime values of n, gold for composite values.

Proofs As a biconditional (if and only if) statement, the proof has two halves: to show that equality does not hold when n is composite, and to show that it does hold when n is prime.

Composite modulus Suppose that n is composite. Therefore, it is divisible by some prime number q where 2≤q<n. Because q divides n, there is an integer k such that n=qk. Suppose for the sake of contradiction that (n−1)! were congruent to −1 modulo n. Then (n−1)! would also be congruent to −1 modulo q: indeed, if (n−1)!≡−1(modn) then (n−1)!=nm−1=(qk)m−1=q(km)−1 for some integer m, and consequently (n−1)! is one less than a multiple of q. On the other hand, since 2≤q≤n−1, one of the factors in the expanded product (n−1)!=(n−1)×(n−2)×⋯×2×1 is q. Therefore (n−1)!≡0(modq). This is a contradiction; therefore it is not possible that (n−1)!≡−1(modn) when n is composite. In fact, more is true. With the sole exception of the case n=4, where 3!=6≡2(mod4), if n is composite then (n−1)! is congruent to 0 modulo n. The proof can be divided into two cases: First, if n can be factored as the product of two unequal numbers, n=ab, where 2≤a<b<n, then both a and b will appear as factors in the product (n−1)!=(n−1)×(n−2)×⋯×2×1 and so (n−1)! is divisible by ab=n. If n has no such factorization, then it must be the square of some prime q larger than 2. But then 2q<q2=n, so both q and 2q will be factors of (n−1)!, and so n divides (n−1)! in this case, as well.

Prime modulus The first two proofs below use the fact that the residue classes modulo a prime number form a finite field (specifically, a prime field).

Elementary proof The result is trivial when p=2, so assume p is an odd prime, p≥3. Since the residue classes modulo p form a field, every non-zero residue a has a unique multiplicative inverse a−1. Euclid's lemma implies that the only values of a for which a≡a−1(modp) are a≡±1(modp). Therefore, with the exception of ±1, the factors in the expanded form of (p−1)! 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 p=11, one has 10!=[(1⋅10)]⋅[(2⋅6)(3⋅4)(5⋅9)(7⋅8)]≡[−1]⋅[1⋅1⋅1⋅1]≡−1(mod11).

Proof using Fermat's little theorem Again, the result is trivial for p = 2, so suppose p is an odd prime, p ≥ 3. Consider the polynomial

g(x)=(x−1)(x−2)⋯(x−(p−1)). g has degree p − 1, leading term xp − 1, and constant term (p − 1)!. Its p − 1 roots are 1, 2, ..., p − 1. Now consider

h(x)=xp−1−1. h also has degree p − 1 and leading term xp − 1. Modulo p, Fermat's little theorem says it also has the same p − 1 roots, 1, 2, ..., p − 1. Finally, consider

f(x)=g(x)−h(x). f has degree at most p − 2 (since the leading terms cancel), and modulo p also has the p − 1 roots 1, 2, ..., p − 1. 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 (p − 1)! + 1 ≡ 0 (mod p). This is Wilson's theorem.

Proof using elementary Group Theory Let p be an odd prime. Let 𝔽p× denote the multiplicative group of integers modulo p, such that (p−1)!≡∏x∈𝔽p×xmodp. Since 𝔽p× is cyclic, there exists a group isomorphism φ:𝔽p×→ℤp−1, where ℤp−1 is the additive group of integers modulo p - 1. Therefore:

φ(∏x∈𝔽p×x)=∑x∈𝔽p×φ(x)=∑n∈ℤp−1n≡p(p−1)2mod(p−1) Since p was an odd prime, p(p−1)2 has order 2 inside ℤp−1. Since isomorphisms preserve the orders of elements, it follows that φ−1(p(p−1)2)=∏x∈𝔽p×x also has order exactly 2. The only such element in 𝔽p× is p−1.

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 Sp has exactly (p−1)! elements of order p, namely the p-cycles Cp. On the other hand, each Sylow p-subgroup in Sp is a copy of Cp. Hence it follows that the number of Sylow p-subgroups is np=(p−2)!. The third Sylow theorem implies

(p−2)!≡1(modp). Multiplying both sides by (p − 1) gives

(p−1)!≡p−1≡−1(modp), 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.

Quadratic residues Using Wilson's Theorem, for any odd prime p = 2m + 1, we can rearrange the left hand side of 1⋅2⋯(p−1) ≡ −1 (modp) to obtain the equality 1⋅(p−1)⋅2⋅(p−2)⋯m⋅(p−m) ≡ 1⋅(−1)⋅2⋅(−2)⋯m⋅(−m) ≡ −1(modp). This becomes ∏j=1m j2 ≡(−1)m+1(modp) or (m!)2≡(−1)m+1(modp). 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.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Wilson's theorem

Start with the simplest possible case. Write down what Wilson's theorem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Wilson's theorem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Wilson's theorem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Wilson's theorem

In research
Wilson's theorem appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Wilson's theorem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Wilson's theorem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Factorial and binomial topics, Modular arithmetic, Primality tests, so understanding it makes those chapters shorter.
In everyday life
Look for Wilson's theorem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Wilson's theorem” →

How to study Wilson's theorem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Wilson's theorem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Wilson's theorem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Wilson's theorem in simple terms?

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 (n−1)!=1×2×3×⋯×(n−1) satisfies…

Why does Wilson's theorem matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Wilson's theorem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Wilson's theorem.

Tags

  • Factorial and binomial topics
  • Modular arithmetic
  • Primality tests
  • Theorems about prime numbers

Keep exploring