Vol. I a living index of named laws · est. mmxxvi no ads · no account
The Law Tomeindex of named laws

Wilson's Theorem

also known as — Wilson's prime criterion, Al-Haytham's theorem
"A number above one is prime exactly when one less than it, factorialised, is one short of a multiple of it."
In plain English

What does Wilson's Theorem mean?

Wilson's theorem is a clean characterisation of the prime numbers using factorials. It states that a whole number greater than one is prime if and only if the factorial of one less than it, the product of all positive integers below it, is congruent to minus one modulo that number; equivalently, that factorial plus one is divisible by the number. The condition is both necessary and sufficient, so it perfectly separates primes from composites, unlike weaker tests that admit exceptions. For example, four factorial is twenty-four, and twenty-four plus one is twenty-five, a multiple of five, confirming five is prime. Elegant and exact, the theorem ties together factorials, divisibility, and primality in a single congruence.

In symbols

What is the formula for Wilson's Theorem?

(p-1)!+1 \equiv 0 \pmod p
The defining formula as recorded on Wikidata. (p-1)!+1 \equiv 0 \pmod p
Run the numbers

Wilson's Theorem calculator

A number is prime exactly when the factorial below it leaves a remainder one short of itself. A primality test, and a hopeless one to compute.

(n-1)! mod n = n-1 if and only if n is prime

n
The number under test
(n-1)! mod n —
Wilson says prime —

Computed live from (n-1)! mod n = n-1 if and only if n is prime — the law's own arithmetic, nothing fitted or predicted.

Reliability

Rated Empirical: grounded in studies or measurable evidence. The other 608.

How it works

How does Wilson's Theorem work?

The reason lies in how numbers pair up under multiplication modulo a prime. Among the numbers from one to one less than a prime, each has a unique partner whose product with it leaves remainder one, and only one and the number one less than the prime are their own partners. Pairing off all the others cancels their contributions to the factorial, leaving just the product of the two self-paired numbers, which works out to minus one modulo the prime. For a composite number greater than four, by contrast, its factors reappear inside the factorial and make it divisible by the number, giving remainder zero rather than minus one, so the congruence fails, which is exactly why the criterion detects composites.

Where you'll see it

What are examples of Wilson's Theorem?

Checking five Four factorial equals twenty-four, and twenty-four is congruent to minus one modulo five since twenty-four plus one is twenty-five, so five passes and is prime.
The composite signature For any composite number above four, the factorial of one less than it is congruent to zero, not minus one, because its factors already appear in the product.
An ancient discovery The result was known to Ibn al-Haytham around the year one thousand, long before John Wilson, and the first published proof was given by Lagrange in the eighteenth century.
Types & variants

What are the types of Wilson's Theorem?

The composite converse§

The other half of the characterisation, that a composite number greater than four divides the factorial of one less than it, giving remainder zero and so failing the prime condition.

The n equals four case§

The small exception among composites, where three factorial is six, congruent to two modulo four rather than zero, the one composite that does not give remainder zero.

Why it matters

Why does Wilson's Theorem matter?

Wilson's theorem is prized as a rare exact characterisation of primality, a single congruence that is true for every prime and false for every composite, with no exceptions of the kind that plague probabilistic tests like the Fermat test and its Carmichael numbers. It is a jewel of elementary number theory, linking factorials to primes and illustrating the group structure of arithmetic modulo a prime. Though beautiful, it is impractical as an actual primality test, because computing the factorial of one less than a large number is far more work than modern tests require, so its value is theoretical and pedagogical rather than computational.

Working with it

How do you apply Wilson's Theorem?

  • Test primality exactly — check whether the factorial of one less than a number is congruent to minus one modulo that number; if so the number is prime, if not it is composite.
  • See the pairing — understand the prime case through multiplicative inverses pairing off, leaving only the two self-paired terms whose product is minus one.
  • Do not use it in practice — treat it as an elegant characterisation, not a working test, since the factorial is far too costly to compute for large numbers.
Where it breaks down

What are the limits of Wilson's Theorem?

As a primality test the theorem is impractical, because evaluating the factorial of one less than a number requires more computation than the number of steps efficient modern tests need, so it is prized for elegance rather than use. It applies to whole numbers greater than one, and the small composite four is a special case giving remainder two rather than the zero that all larger composites give. The theorem characterises primality perfectly but offers no shortcut to factoring a composite it flags, so its exactness buys certainty about whether a number is prime without any help in decomposing it.

What it doesn't say

What are common misconceptions about Wilson's Theorem?

The theorem is an exact if-and-only-if characterisation, not a one-directional or probabilistic test, so unlike the Fermat test it has no false positives or Carmichael-number exceptions. Its perfection does not make it practical: the factorial involved is astronomically expensive, so it is not used to test large numbers despite being always correct. And the composite case gives remainder zero only for composites greater than four; the number four itself is the lone small exception, giving remainder two, which is a quirk to remember rather than a flaw.

Is it real?

Is Wilson's Theorem real?

Yes, as far as the evidence goes. Wilson's Theorem is rated Empirical here: it rests on studies or measurements rather than on a saying.

Rated from two sources. 609 of the 1,116 entries carry this rating. How the scale works.

Rarely printedin printed books: one of 196 names in its band, of 903 measured
38 of 51entries in mathematics & proof carry the same rating

The best-known laws are the least likely to rest on measurement.

Origin

Where did Wilson's Theorem come from?

Known to Ibn al-Haytham around the year one thousand, stated by John Wilson and reported by Edward Waring in his Meditationes Algebraicae of 1770, and first proved by Joseph-Louis Lagrange in 1771.

How the name spread

When did people start saying “Wilson's Theorem”?

18002019
How often “Wilson 's Theorem” appears in printed English, which takes hold around 1807 and peaks around 1892. This tracks the phrase and not the idea. A law is usually older than the name for it. Source: Google Books Ngrams.
Known elsewhere as

What is Wilson's Theorem called in other languages?

  • Arabicمبرهنة ويلسون
  • GermanSatz von Wilson
  • Spanishteorema de Wilson
  • Frenchthéorème de Wilson
  • Italianteorema di Wilson
  • Japaneseウィルソンの定理
  • Portugueseteorema de Wilson
  • RussianТеорема Вильсона
  • Chinese威尔逊定理

9 languages, as recorded on Wikidata. These are names the idea already goes by, not translations we made. The whole index by language.

Sources

Sources & further reading

  1. 1Wilson's theorem, Wikipedia. — the if-and-only-if factorial congruence, the n equals five example, the Ibn al-Haytham, Wilson-Waring, and Lagrange history, and the impracticality as a test.secondary
  2. 2Wilson's Theorem, Wolfram MathWorld. — the prime characterisation and its contrast with Fermat's little theorem.secondary

Everything above traces to en.wikipedia.org and mathworld.wolfram.com: two secondary sources, accounts of the original rather than the original itself, which has not been located for this entry. Nothing is written from memory, and the method is written down. Spot an error or a better source? Suggest a fix.

What we checked

  • 1,116entries in the tomeListed one by one on the browse page.
  • 1,116of them citing a sourceOpen any entry: its sources sit at the foot of the page.
  • 2,489source references in allEach is named, and linked wherever the source is online.