Documentation

CslibFrontier.Foundations.NumberTheory.Primality.Witness

Witnesses for odd composite moduli #

The Solovay–Strassen and Miller–Rabin bounds Solovay and Strassen Rabin show that the bases fooling a primality test modulo an odd composite n lie in a proper subgroup of (ZMod n)ˣ, hence make up at most half of the units. Both proofs split an odd composite n into one of two shapes and build a unit witness for each; this file collects the shared facts.

Main results #

References #

theorem Subgroup.two_mul_card_le_of_ne_top {G : Type u_1} [Group G] [Finite G] {H : Subgroup G} (hH : H ≠ ⊤) :

A proper subgroup of a finite group has at most half of its elements.

theorem Nat.exists_sq_dvd_or_eq_mul_coprime {n : ℕ} (hodd : Odd n) (h1 : 1 < n) (hn : ¬Prime n) :
(∃ (p : ℕ), Prime p ∧ p ≠ 2 ∧ p ^ 2 ∣ n) ∨ ∃ (p : ℕ) (q : ℕ), n = p * q ∧ Prime p ∧ p ≠ 2 ∧ p.Coprime q ∧ Odd q ∧ 1 < q

An odd composite number is divisible by the square of an odd prime, or is the product of an odd prime p and an odd q > 1 coprime to p.

theorem one_add_pow_of_sq_eq_zero {R : Type u_1} [CommRing R] {x : R} (hx : x ^ 2 = 0) (k : ℕ) :
(1 + x) ^ k = 1 + ↑k * x

If x ^ 2 = 0, then (1 + x) ^ k = 1 + k x.

theorem ZMod.chineseRemainder_apply {p q : ℕ} (h : p.Coprime q) (z : ZMod (p * q)) :
(chineseRemainder h) z = ((castHom ⋯ (ZMod p)) z, (castHom ⋯ (ZMod q)) z)

The Chinese remainder isomorphism reduces modulo each factor.

theorem ZMod.exists_unit_castHom_eq {p q : ℕ} (h : p.Coprime q) (u : (ZMod p)ˣ) (v : (ZMod q)ˣ) :
∃ (c : (ZMod (p * q))ˣ), (castHom ⋯ (ZMod p)) ↑c = ↑u ∧ (castHom ⋯ (ZMod q)) ↑c = ↑v

Chinese remainder theorem for units: units modulo coprime p and q lift to a unit modulo p * q.

theorem ZMod.neg_one_ne_one_of_odd {n : ℕ} (hn : Odd n) (h1 : 1 < n) :
-1 ≠ 1

-1 ≠ 1 modulo an odd n > 1.

theorem ZMod.exists_unit_pow_of_sq_dvd {n p : ℕ} (hp : Nat.Prime p) (hp2 : p ≠ 2) (hn : n ≠ 0) (hpn : p ^ 2 ∣ n) :
∃ (c : (ZMod n)ˣ), (∀ (m : ℕ), ↑c ^ m = 1 → p ∣ m) ∧ ∀ (m : ℕ), ↑c ^ m ≠ -1

The witness for a square factor. If p ^ 2 ∣ n for an odd prime p and n ≠ 0, then c = 1 + n / p is a unit modulo n with c ^ m = 1 only when p ∣ m, and never c ^ m = -1.