Wilson's theorem
ProvedFamousTheorems.wilsons_lemmamathlibnumber-theory
Wilson's theorem.
For a prime ,
Pairing each residue in with its inverse leaves only the self-inverse elements and , whose product is ; all other residues cancel in pairs. The converse also holds, so this is a characterisation of primes — though a useless primality test, since computing is far harder than trial division.
Stated by Ibn al-Haytham around 1000, conjectured again by Wilson, and first proved by Lagrange in 1771.
Preamble
import Mathlib
Formal statement
namespace FamousTheorems theorem wilsons_lemma : ∀ (p : ℕ) [Fact (Nat.Prime p)], (((p - 1).factorial : ℕ) : ZMod p) = -1 := by sorry end FamousTheorems
Source
One of Freek Wiedijk's "100 theorems"; formalized in Mathlib. Proof here reduces to the corresponding Mathlib result.