Existing in Mathlib · Number theory
Wilson's Theorem
For each natural number n other than 1, n is prime exactly when the natural-number factorial (n−1)!, cast into ZMod n, equals −1. The n = 0 case uses Lean's natural subtraction and factorial conventions and is handled separately, rather than by informal predecessor-product notation.
- Wilson's theorem
- prime characterization
- factorials
- modular arithmetic
- unit inverses
Exact theorem
Exact Mathlib statement
theorem Nat.prime_iff_fac_equiv_neg_one {n : ℕ} (h : n ≠ 1) : Nat.Prime n ↔ ((n - 1)! : ZMod n) = -1The theorem at a glance
Wilson's Theorem — an exact factorial characterization of primes
A visual guide to the theorem's hypotheses, structure, and conclusion; the exact statement gives the formal detail.
Wilson's Theorem — an exact factorial characterization of primes

Detailed visual description
The exact equivalence is supported by two distinct source movements: the prime direction identifies the factorial with the product of all units and pairs inverses, while the converse handles n = 0 separately before using a proper divisor to contradict residue −1.
Statement structure
From hypotheses to conclusion
This map summarizes the statement's structure; the exact Mathlib declaration remains authoritative.
Wilson's equivalence, including the prime-two and zero cases

Detailed visual description
For odd primes, non-fixed units pair with their inverses and the distinct fixed residues are 1 and −1; in ZMod 2 these are one residue. Conversely, the source rejects n = 0 directly. For a remaining nonprime n > 1, a divisor m with 1 < m < n divides (n−1)!, and the asserted residue equality would force m ∣ 1.
Why it matters
A mathematical landmark
Wilson's theorem gives one of the classical exact characterizations of prime numbers and connects elementary factorial arithmetic to the multiplicative structure of finite residue rings.
ProofAtlas record
What has been checked
Mathlib is the source of the theorem; the local Lean replay and page review are separate.
Claim boundary
No new theorem is claimed
This target indexes Mathlib's equivalence for every natural number n ≠ 1: n is prime exactly when the cast of (n−1)! in ZMod n equals −1. The prime direction includes n = 2, where 1 and −1 are the same residue. The converse handles n = 0 separately before treating the remaining nonprime case. It does not assert a fast primality algorithm, a result for n = 1, or a new proof.
- The exact theorem assumes n ≠ 1; it does not silently replace that hypothesis by n > 1.
- The equivalence includes the converse direction and must not be presented as only prime implies factorial congruence.
- The theorem is a characterization, not a claim of computational efficiency.
- ProofAtlas is indexing an existing Mathlib theorem, not claiming new mathematics.
Source and local evidence
Where the theorem comes from
- Existing declaration
Nat.prime_iff_fac_equiv_neg_onein mathlib- Relationship
- The checked artifact is the upstream declaration itself
- Local Lean evidence
artifact.library.mathlib.wilson-theorem.v001