The Lucas test for primes. #
This file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for
Mersenne primes). A number a witnesses that n is prime if a has order n-1 in the
multiplicative group of integers mod n. This is checked by verifying that a^(n-1) = 1 (mod n)
and a^d ≠ 1 (mod n) for any divisor d | n - 1. This test is the basis of the Pratt primality
certificate.
TODO #
- Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness.
Use
Units.IsCyclicfromRingTheory/IntegralDomainto show the group is cyclic. - Write a tactic that uses this theorem to generate Pratt primality certificates
- Integrate Pratt primality certificates into the norm_num primality verifier
Implementation notes #
Note that the proof for lucas_primality relies on analyzing the multiplicative group
modulo p. Despite this, the theorem still holds vacuously for p = 0 and p = 1: In these
cases, we can take q to be any prime and see that hd does not hold, since a^((p-1)/q) reduces
to 1.
Recursive form of a Pratt certificate for p, which may take in Pratt certificates
for a list of prime powers r less than p whose product is equal to p - 1.
- prime {p : ℕ} {a : ZMod p} (n k nk : ℕ) : Nat.Prime n → a ^ ((p - 1) / n) ≠ 1 → n ^ k = nk → PrattPartList p a nk
- split {p : ℕ} {a : ZMod p} {n : ℕ} (list : List ℕ) : (∀ r ∈ list, PrattPartList p a r) → list.prod = n → PrattPartList p a n
Instances For
The binary version of PrattPartList. This is the one in the original file.
- prime {p : ℕ} {a : ZMod p} (n k nk : ℕ) : Nat.Prime n → a ^ ((p - 1) / n) ≠ 1 → n ^ k = nk → PrattPart p a nk
- split {p : ℕ} {a : ZMod p} {n : ℕ} (l r : ℕ) : PrattPart p a l → PrattPart p a r → l * r = n → PrattPart p a n
Instances For
Equations
Instances For
- prime (p k : ℕ) (hp : UnverifiedPrattCertificate p) : UnverifiedPrattPart
- split : UnverifiedPrattPart → UnverifiedPrattPart → UnverifiedPrattPart
Instances For
Equations
- knownPrime (n : ℕ) : UnverifiedPrattCertificate n
- of (n a : ℕ) (part : UnverifiedPrattPart) : UnverifiedPrattCertificate n