Documentation

CslibFrontier.Foundations.NumberTheory.Primality.StrongLiars

Strong liars and the Miller–Rabin bound #

Write n - 1 = 2 ^ s * t with t odd. The Miller–Rabin test Rabin declares an odd n > 1 composite when a random base a has a ^ t ≠ 1 and a ^ (2 ^ i * t) ≠ -1 for every i < s modulo n. The bases that pass are the strong liars. Modulo a prime every nonzero residue is a strong liar, because the only square roots of 1 are ±1. Modulo an odd composite n, the strong liars lie in a proper subgroup of (ZMod n)ˣ: for the largest j < s such that some unit has b ^ (2 ^ j * t) = -1, the units whose 2 ^ j * t-th power is ±1. Hence at most half of the units are strong liars. The sharper Rabin–Monier bound φ(n) / 4 for n ≠ 9 is in CslibFrontier.Foundations.NumberTheory.Primality.RabinMonier.

Main definitions #

Main results #

References #

def ZMod.IsStrongLiar (n : ℕ) (a : ZMod n) :

a is a strong liar for n: writing n - 1 = 2 ^ s * t with t odd, a ^ t = 1 or a ^ (2 ^ i * t) = -1 for some i < s.

Instances For
    theorem ZMod.isStrongLiar_iff {n : ℕ} {a : ZMod n} :
    IsStrongLiar n a ↔ a ^ ((n - 1) / 2 ^ (n - 1).factorization 2) = 1 ∨ ∃ i < (n - 1).factorization 2, a ^ (2 ^ i * ((n - 1) / 2 ^ (n - 1).factorization 2)) = -1
    theorem ZMod.IsStrongLiar.isUnit {n : ℕ} (h1 : 1 < n) {a : ZMod n} (h : IsStrongLiar n a) :

    For n > 1, a strong liar is a unit.

    theorem ZMod.isStrongLiar_of_prime {p : ℕ} [Fact (Nat.Prime p)] {a : ZMod p} (ha : a ≠ 0) :

    Strong liars modulo a prime: modulo a prime, every nonzero residue is a strong liar. Going down from a ^ (p - 1) = 1 by square roots, each is 1 or -1.

    The units whose m-th power is 1 or -1.

    theorem ZMod.mem_powEqOneOrNegOne {n m : ℕ} {a : (ZMod n)ˣ} :
    a ∈ powEqOneOrNegOne n m ↔ a ^ m = 1 ∨ a ^ m = -1
    theorem ZMod.exists_pow_eq_neg_one_forall_isStrongLiar {n : ℕ} (hodd : Odd n) (h1 : 1 < n) :
    ∃ (m : ℕ), 2 * m ∣ n - 1 ∧ (∃ (b : (ZMod n)ˣ), b ^ m = -1) ∧ ∀ (a : (ZMod n)ˣ), IsStrongLiar n ↑a → a ∈ powEqOneOrNegOne n m

    The exponent of the strong-liar test. For odd n > 1, write n - 1 = 2 ^ s * t with t odd and take the largest j < s such that some unit b has b ^ (2 ^ j * t) = -1 (j = 0 works with b = -1). Then m = 2 ^ j * t has 2 m ∣ n - 1, b ^ m = -1, and every strong liar a has a ^ m = ±1.

    theorem ZMod.exists_subgroup_ne_top_isStrongLiar {n : ℕ} [NeZero n] (hodd : Odd n) (h1 : 1 < n) (hn : ¬Nat.Prime n) :
    ∃ (H : Subgroup (ZMod n)ˣ), H ≠ ⊤ ∧ ∀ (a : (ZMod n)ˣ), IsStrongLiar n ↑a → a ∈ H

    Strong liars of a composite: modulo an odd composite n, the strong liars lie in a proper subgroup of the units, namely powEqOneOrNegOne n m for the exponent m of exists_pow_eq_neg_one_forall_isStrongLiar, which contains every strong liar. If p ^ 2 ∣ n for an odd prime p, the unit 1 + n / p is outside it. Otherwise n = p q with p an odd prime coprime to q > 1, and the unit that agrees with b modulo p and is 1 modulo q is outside it.

    theorem ZMod.card_isStrongLiar_le_card {n : ℕ} [NeZero n] (h1 : 1 < n) {H : Subgroup (ZMod n)ˣ} (hsub : ∀ (a : (ZMod n)ˣ), IsStrongLiar n ↑a → a ∈ H) :

    The strong liars modulo n > 1 number at most the elements of any subgroup of the units that contains them.

    theorem ZMod.two_mul_card_isStrongLiar_le {n : ℕ} [NeZero n] (hodd : Odd n) (h1 : 1 < n) (hn : ¬Nat.Prime n) :

    The Miller–Rabin bound: modulo an odd composite n, at most half of the units are strong liars.