---
title: 'Wilson''s Theorem: Prime Criterion'
url: https://www.emergentmind.com/topics/wilson-s-theorem
type: topic
---

# Wilson's Theorem: Prime Criterion

Wilson’s theorem is the congruence
\[
(p-1)!\equiv -1 \pmod p
\]
for prime \(p\), equivalently the primality criterion
\[
n\in\mathcal P \quad\Longleftrightarrow\quad n\mid \bigl(1+(n-1)!\bigr)
\]
for integers \(n\ge2\). It identifies primality through a factorial residue and has become a prototype for congruential primality criteria, \(p\)-adic refinements, Stirling-number generalizations, and finite-field product formulas [1911.09492]. The congruence was discovered, in somewhat different language, by Lagrange in 1771, and later appeared under Wilson’s name [1809.04767].

## 1. Classical formulation and arithmetic content

In its standard form, Wilson’s theorem asserts that if \(p\) is prime, then \((p-1)!\equiv -1\pmod p\), and the converse also holds: if \((n-1)!\equiv -1\pmod n\), then \(n\) is prime [1809.04767]. The theorem therefore gives an exact congruential characterization of primality.

A common sharpening separates the prime and composite cases more explicitly. For integers \(n\ge2\),
\[
(n-1)!\equiv
\begin{cases}
-1\pmod n,& n\text{ prime},\\
0\pmod n,& n\text{ composite},\ n\neq4,
\end{cases}
\]
with the unique composite exception \(n=4\), since \(3!=6\equiv2\pmod4\) [1302.3676]. This formulation isolates the exceptional behavior of the modulus \(4\) and clarifies that the factorial is usually annihilated modulo a composite modulus.

The converse direction is elementary and structurally important. If \(n>1\) is composite and \(d\) is a nontrivial divisor of \(n\), then \(d\mid (n-1)!\), so \((n-1)!+1\not\equiv0\pmod d\), hence \((n-1)!\not\equiv-1\pmod n\) [1911.09492]. The prime case is therefore the genuinely nontrivial part of the theorem.

## 2. Proof architectures

The most classical proof uses the multiplicative group \((\mathbb Z/p\mathbb Z)^\times\). Every residue \(a\not\equiv a^{-1}\pmod p\) pairs with its inverse, and each pair contributes \(1\) to the total product. The only unpaired elements are those satisfying \(a^2\equiv1\pmod p\), namely \(a=1\) and \(a=p-1\equiv-1\), so
\[
(p-1)!\equiv 1\cdot(-1)\equiv -1\pmod p
\]
[1911.09492]. This proof makes explicit that the theorem is a statement about the involutive structure of the unit group.

A second proof is polynomial. Over \((\mathbb Z/p\mathbb Z)[X]\), Fermat’s little theorem implies that every nonzero residue is a root of \(X^{p-1}-1\), hence
\[
X^{p-1}-1=\prod_{k=1}^{p-1}(X-k).
\]
Comparing constant terms yields
\[
-1\equiv (-1)^{p-1}(p-1)!\equiv (p-1)!\pmod p
\]
[1912.06652]. A closely related formulation is
\[
\prod_{a=1}^{p-1}(x-a)\equiv x^{p-1}-1 \pmod p,
\]
which is the starting point for several later higher-power refinements [2509.05235].

A third proof, closer to Lagrange’s original style, expands
\[
(x-1)(x-2)\cdots(x-(n-1))
=\sum_{k=0}^{n-1}(-1)^kP_kx^{\,n-1-k},
\]
where \(P_k\) is the \(k\)th elementary symmetric sum in \(1,\dots,n-1\). A coefficient comparison after shifting the variable produces the recurrence
\[
(m-1)\,P_{m-1}=\sum_{k=0}^{m-2}P_k\binom{n-k}{m-k},
\]
and when \(n=p\) is prime this recurrence yields \(p\mid P_1,\dots,P_{p-2}\). Setting \(m=p\) then gives \((p-1)!\equiv-1\pmod p\) [1809.04767]. This approach is notable because the same symmetric-sum machinery also leads to Wolstenholme’s theorem.

## 3. Wilson quotient and higher prime powers

Wilson’s theorem can be reframed through the Wilson quotient
\[
W_p=\frac{(p-1)!+1}{p},
\]
which is integral exactly because \((p-1)!\equiv-1\pmod p\) [2509.05235]. This reformulation converts the basic congruence into a \(p\)-adic object and opens the way to supercongruences.

A central auxiliary notion is the Fermat quotient
\[
q_p(a)=\frac{a^{p-1}-1}{p},
\]
defined for \(\gcd(a,p)=1\), together with its power sums
\[
Q_p(n)=\sum_{a=1}^{p-1} q_p(a)^n.
\]
Lerch’s congruence states that
\[
W_p\equiv Q_p(1)\pmod p
\]
[2509.05235]. Kellner’s later work lifts this to arbitrary higher prime powers by combining symmetric-function identities, Bell polynomials, and Newton’s identities. For every \(n\ge1\) and every odd prime \(p>n\), there are unique integer polynomials \(\psi_1,\dots,\psi_n\) with no constant term such that
\[
W_p\equiv \sum_{\nu=1}^{n}\frac{p^{\nu-1}}{\nu!}\,
\psi_\nu\bigl(Q_p(1),\ldots,Q_p(\nu)\bigr)\pmod{p^n},
\]
and equivalently
\[
(p-1)!\equiv -1+\sum_{\nu=1}^{n}\frac{p^\nu}{\nu!}\,
\psi_\nu\bigl(Q_p(1),\ldots,Q_p(\nu)\bigr)\pmod{p^{n+1}}
\]
[2509.05235].

An earlier higher-power milestone is Glaisher’s congruence, recovered by Levaillant through \(p\)-adic lifting and Faulhaber polynomials:
\[
(p-1)!\equiv -1+p\,B_{p-1}\pmod{p^2}.
\]
The same method also yields a formula for \((p-1)!\) modulo \(p^3\) in terms of Bernoulli numbers [1912.06652].

Kellner’s second and third papers translate the \(\psi_\nu\)-expansions into explicit congruences involving divided Bernoulli numbers and Kummer congruences, obtaining \(W_p\) modulo \(p^4\) and equivalently \((p-1)!\) modulo \(p^5\), then extending further to \(W_p\) modulo \(p^5\) and \(p^6\), and equivalently \((p-1)!\) modulo \(p^6\) and \(p^7\) [2509.05402; 2510.26743].

| Paper | Explicit reach | Main mechanism |
|---|---|---|
| [1912.06652] | \((p-1)!\) mod \(p^2\), \(p^3\) | Hensel lifting, Faulhaber polynomials, Bernoulli numbers |
| [2509.05402] | \(W_p\) mod \(p^4\), \((p-1)!\) mod \(p^5\) | \(\psi_\nu\)-polynomials, Bernoulli polynomials, Kummer congruences |
| [2510.26743] | \(W_p\) mod \(p^5\), \(p^6\); \((p-1)!\) mod \(p^6\), \(p^7\) | Fermat-quotient power sums, divided Bernoulli numbers |

These developments show that classical Wilson is the first layer of a much richer \(p\)-adic expansion, rather than an isolated mod-\(p\) coincidence.

## 4. Stirling-theoretic and combinatorial generalizations

A substantial generalization arises from Stirling numbers of the second kind. For positive integers \(m,n\) and complex \(z\), the Stirling function
\[
S(m,n,z):=(-1)^d\,n!\sum_{k=0}^n \binom{n}{k}(-1)^k(z-k)^m,
\qquad d=m-n,
\]
satisfies
\[
S(m,n,z)-S(m,n)=(-1)^dP_{(m,n)}(z)
\]
when \(d>0\), where
\[
P_{(m,n)}(z)=\sum_{j=1}^d \binom{m}{j}S(m-j,n)(-z)^j.
\]
With \(B(m,n):=n!\,S(m,n)\), the main arithmetic result is:
\[
p\text{ is prime}\quad\Longleftrightarrow\quad
-1\equiv_p B(n(p-1),p-1)\ \text{for every }n\in\mathbb Z_+
\]
[1701.00044]. The case \(n=1\) gives
\[
B(p-1,p-1)=(p-1)!,
\]
so classical Wilson is recovered exactly.

The same framework yields complementary congruences for Stirling numbers. If \(p>2\) is prime, then for every \(n\in\mathbb Z_+\) and every \(0<k<p-1\),
\[
S(n(p-1),p-k)\equiv (k-1)!\pmod p
\]
[1701.00044]. This places Wilson’s theorem inside a broader pattern of congruences indexed by Stirling shifts.

A distinct combinatorial extension replaces \((n-1)!\) by sums of products of subsets of \(\{1,\dots,n-1\}\). If \(\mathcal N[k]\) denotes the multiset of all products of \(k\)-subsets of \(\{1,\dots,n-1\}\), then for fixed \(c\ge0\) and \(n\ge(2c+3)^2\),
\[
\biggl((-1)^c+\sum_{M\in\mathcal N[n-1-c]}M\biggr)(c+1)\equiv0\pmod n
\quad\Longleftrightarrow\quad
n=(c+1)p\text{ for some prime }p.
\]
When \(c=0\), this reduces to Wilson’s theorem because \(\mathcal N[n-1]=\{(n-1)!\}\) [2403.09644].

Another extension interpolates among “partial factorial blocks.” For integers \(n\ge1\) and \(0\le k<n\),
\[
(-1)^k\,k!\,(n-k-1)!\equiv -1\pmod n
\]
if and only if \(n\in\mathbb P_1\), and this leads to generalized Wilson quotients
\[
M_k(n)=\frac{1+(-1)^k\,k!\,(n-k-1)!}{n}
\]
[2505.16201]. This suggests a family of Wilson-type residues parameterized by the truncation point \(k\).

## 5. Wilson-like analogues beyond the ordinary factorial

Wilson-type congruences extend to several other factorial-like functions. For primes \(p\), Aebi and Cairns proved congruences for the superfactorial \(\mathrm{sf}(n)=\prod_{k=1}^n k!\), the hyperfactorial \(H(n)=\prod_{k=1}^n k^k\), the double factorial \(n!!\), and the subfactorial \(!n\) [1302.3676]. In particular, if \(p\) is prime, then
\[
\mathrm{sf}(p-1)\equiv (p-1)!!\pmod p,
\]
and for odd prime \(p\),
\[
H(p-1)\equiv (-1)^{\frac{p-1}{2}}(p-1)!!\pmod p.
\]
For all integers \(n\ge1\),
\[
!n\equiv(-1)^n\pmod n.
\]
The prime-case congruences therefore organize several factorial variants around a small set of distinguished residues.

A particularly compact relation among these functions is
\[
(p-1)!!\equiv \mathrm{sf}(p-1)\equiv
(-1)^{\frac{p-1}{2}}H(p-1)\pmod p
\]
for primes \(p\) [1302.3676]. This gives a uniform residue-theoretic connection between ordinary Wilson behavior and higher factorial constructions.

There is also a finite-field analogue. For any odd prime power \(q\),
\[
\prod_{a\in\mathbb F_q^\times} a=-1,
\]
which is the direct finite-field version of Wilson’s theorem [1707.06870]. Bluher further defined natural subsets of \(\mathbb F_q^\times\) by quadratic-character conditions and obtained explicit products for these subsets. One example is
\[
\prod\left\{ a \in {\mathbb F}_q^\times : \text{$1-a$ and $3+a$ are nonsquares} \right\}
=
\begin{cases}
2,& q\equiv \pm1\pmod{12},\\
-1,& \text{otherwise,}
\end{cases}
\]
showing that Wilson-like product formulas persist after restricting from all nonzero field elements to Legendre-symbol slices [1707.06870].

## 6. Relations to Giuga, Wolstenholme, and current themes

Wilson’s theorem also appears as one endpoint of an interpolation toward Giuga’s conjecture. Sauvaget introduced
\[
H_k(n):=
1+\sum_{i=1}^{n-1}\frac{(n+i-1-k)!}{i!}\,i^k,
\]
with the properties
\[
H_1(n)\equiv 1+(n-1)!\pmod n
\]
and
\[
H_{n-1}(n)=1+\sum_{i=1}^{n-1}i^{n-1}.
\]
Thus \(k=1\) recovers Wilson’s criterion, while \(k=n-1\) gives the Giuga-type power-sum condition [1911.09492]. The interpolation conjecture proposed there is that for every fixed \(k\),
\[
n\in\mathcal P,\ n\ge k+1
\quad\Longleftrightarrow\quad
n\mid H_k(n).
\]
This suggests that Wilson’s theorem may be viewed as the first member of a broader family linking factorial and power-sum primality congruences.

The Lagrange symmetric-sum framework also connects Wilson with Wolstenholme’s theorem. Using the same elementary symmetric sums \(P_k\) that prove Wilson, one obtains
\[
\binom{2p-1}{p-1}\equiv1\pmod{p^3},\qquad p\ge5,
\]
which is Wolstenholme’s theorem [1809.04767]. In this sense Wilson’s theorem is not isolated even among classical congruences: it belongs to a cluster of prime-specific identities accessible from the same algebraic setup.

Recent work therefore treats Wilson’s theorem less as a terminal statement than as a base layer. Stirling-function constructions, Bell-polynomial supercongruences, Bernoulli-number expansions, subset-product criteria, and finite-field character products all preserve the theorem’s central theme: primality manifests itself through exceptionally rigid multiplicative congruences [1701.00044; 2509.05235; 1707.06870].

Source: https://www.emergentmind.com/topics/wilson-s-theorem