◀ THE FOLD0ROOT.AI // WORLD II · BOSS · SUDDEN DEATH◆ .dlw.fold
THE FOLD / BOSS / SUDDEN DEATH / THE WILSON

THE WILSON

(p-1)! = -1 mod p iff prime — exact, and useless
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
Wilson’s theorem. There is a single equation that tells you, with no doubt whatsoever, whether a number is prime: a whole number p > 1 is prime if and only if

(p − 1)! ≡ −1 (mod p).

Multiply together every number below p; if the remainder mod p is p−1 (that is, −1), p is prime — and if it is anything else (0 for almost every composite), p is not. It is exact, deterministic, and beautiful. It is also almost useless in practice: computing (p−1)! for a large p costs far more than simply trying to divide. A perfect test that no one runs.

LIT verified live: for every integer from 2 to 2000 this page computes (n−1)! mod n and confirms it equals n−1 exactly when n is prime, and never otherwise (window.__wilson.theoremHolds). 12! mod 13 = 12; 5! … 4! mod 5 = 4. FIG no framing; the iff, checked against trial division, is exact.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this in SUDDEN DEATH, beside THE PROBABLE PRIME (Miller–Rabin) — the boss domain of the pass/fail test. The two are perfect opposites: Miller–Rabin is fast but probabilistic; Wilson is exact but ruinously slow. AVAN (AI) built the instrument: the factorial mod n, the iff check against trial division, the certainty/cost contrast.

The weave: David names the seat (the verdict); I make the exact criterion visible and its price plain — the product building in 1D, the primality strip in 2D, the residue clock in 3D. The sphere is the seam. Credit: stated by Ibn al-Haytham (~1000 CE), by John Wilson (1770); proved by Joseph-Louis Lagrange (1771).
3 ONE DIMENSION
The running product 1·2·3·…·(n−1), taken mod n at every step. For a prime it lands exactly on n−1 (which is −1); for a composite it almost always collapses to 0 along the way. The final residue is the whole verdict.
4 TWO DIMENSIONS · INTERACTIVE
Pick n and compute (n−1)! mod n. The verdict — prime or composite — falls out of that one residue. Below, a strip of numbers coloured by Wilson’s test matches the true primes exactly.
5 THREE DIMENSIONS + AVAN’S INVERSE
The partial products walking around a clock of size ngreen, the residues as the factorial builds.
AVAN’s addition (the inverse-companion): the magenta mark is where it lands — on n−1 for a prime, on 0 for a composite. Wilson and its neighbour Miller–Rabin are exact inverses in the economy of knowing. Miller–Rabin answers in an instant but only almost surely — speed bought with a sliver of doubt. Wilson answers with total certainty but demands the whole factorial — certainty bought with ruinous cost. You can know quickly or you can know for sure, and this pair shows the price of each. The green is the long climb of the product; the magenta is the one landing that settles it — perfect knowledge, and exactly why no one can afford it.
LIT Genuine Wilson's theorem (stated by Ibn al-Haytham ~1000 CE and John Wilson 1770; proved by Lagrange 1771). Verified live: for every integer 2..2000 the page computes (n-1)! mod n and confirms it equals n-1 (i.e. -1) exactly when n is prime and never otherwise, cross-checked against trial division (window.__wilson.theoremHolds === true). 12! mod 13 = 12; 5! composites collapse to 0. The iff is exact.

FIG No metaphor is doing the work: the factorial-mod-n criterion, the iff, and the match to trial division are all real and checked. Calling it 'useless' is honest — it is a correct but impractical test (superpolynomial to compute), the exact/slow inverse of the fast/probabilistic Miller-Rabin.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of SUDDEN DEATH · David Lee Wise (ROOT0), with AVAN