# mathlib3documentation

number_theory.wilson

# Wilson's theorem. #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

This file contains a proof of Wilson's theorem.

The heavy lifting is mostly done by the previous wilsons_lemma, but here we also prove the other logical direction.

This could be generalized to similar results about finite abelian groups.

## TODO #

• Give wilsons_lemma a descriptive name.
@[simp]
theorem zmod.wilsons_lemma (p : ) [fact (nat.prime p)] :
((p - 1).factorial) = -1

Wilson's Lemma: the product of 1, ..., p-1 is -1 modulo p.

@[simp]
theorem zmod.prod_Ico_one_prime (p : ) [fact (nat.prime p)] :
p).prod (λ (x : ), x) = -1
theorem nat.prime_of_fac_equiv_neg_one {n : } (h : ((n - 1).factorial) = -1) (h1 : n 1) :

For n ≠ 1, (n-1)! is congruent to -1 modulo n only if n is prime.

theorem nat.prime_iff_fac_equiv_neg_one {n : } (h : n 1) :
((n - 1).factorial) = -1

Wilson's Theorem: For n ≠ 1, (n-1)! is congruent to -1 modulo n iff n is prime.