Documentation

PrimeCert.Pocklington

Pocklington's primality certificate #

To use this certificate for primality of N, factorise N - 1 completely.

  1. If the largest factor p is > √N, then set F₁ = p.
  2. Otherwise, set F₁ to be the product of enough prime factors to be > √N.
  3. Then, find a primitive root a of N.
  4. Then a will satisfy the conditions required, which are:
theorem List.pairwise_iff_toFinset {α : Type u_1} {β : Type u_2} (l : List α) (hl : l.Nodup) (P : ββProp) (hp : Symmetric P) (e : αβ) [DecidableEq α] :
Pairwise (Function.onFun P e) l _root_.Pairwise (Function.onFun P fun (i : l.toFinset) => e i)
theorem Nat.modEq_finset_prod_iff {a b : } {ι : Type u_1} (s : Finset ι) (e : ι) (co : Pairwise (Function.onFun Coprime fun (i : s) => e i)) :
a b [MOD s.prod e] is, a b [MOD e i]
theorem multiplicity_zero_right {α : Type u_1} [MonoidWithZero α] (x : α) :
theorem Nat.modEq_iff_forall_prime_dvd {a b n : } :
a b [MOD n] ∀ (p : ), p nPrime pa b [MOD p ^ multiplicity p n]
theorem Nat.pow_multiplicity_dvd_of_dvd_of_not_dvd_div {q n x : } (hq : Prime q) (hxn : x n) (hxnq : ¬x n / q) :
theorem pocklington_test (N F₁ : ) (hn₀ : 0 < N) (hf₁ : F₁ N - 1) (primitive : pF₁.primeFactors, ∃ (a : ), a ^ (N - 1) 1 [MOD N] (a ^ ((N - 1) / p) - 1).gcd N = 1) (p : ) (hp : Nat.Prime p) (hpn : p N) :
p 1 [MOD F₁]

Let N be a natural number whose primality we want to certify. Assume we have a partial factorisation N - 1 = F₁ * R₁, where F₁ is fully factorised with prime factors pᵢ. Now for each pᵢ find a pseudo-primitive root aᵢ such that aᵢ ^ (N - 1) ≡ 1 (mod N) and gcd(aᵢ ^ ((N - 1) / pᵢ) - 1, N) = 1. Then any prime factor n of N satisfies n ≡ 1 (mod F₁).

def PocklingtonPred (N root F₁ : ) :

The Pocklington primitive-root predicate: for each prime factor p of F₁, gcd(root ^ ((N-1)/p) - 1, N) = 1. Built incrementally by PocklingtonPred.step.

Equations
Instances For
    theorem pocklington_certify (N F₁ : ) (h2n : 2 N) (hf₁ : F₁ N - 1) (hf₁' : N.sqrt < F₁) (root : ) (psp : root ^ (N - 1) 1 [MOD N]) (primitive : PocklingtonPred N root F₁) :
    theorem pocklington_certifyKR (N root F₁ : ) (primitive : PocklingtonPred N root F₁) (psp : (powModTR root N.pred N).beq 1 = true := by exact eagerReduce (Eq.refl true)) (h2n : Nat.ble 2 N = true := by exact eagerReduce (Eq.refl true)) (hf₁ : (N.pred.mod F₁).beq 0 = true := by exact eagerReduce (Eq.refl true)) (hf₁' : N.blt (F₁.mul F₁) = true := by exact eagerReduce (Eq.refl true)) :
    @[simp]
    theorem PocklingtonPred.zero {N root : } :
    @[simp]
    theorem PocklingtonPred.one {N root : } :
    theorem PocklingtonPred.step_pow {N root F₂ p e : } (hp : Nat.Prime p) (ih : PocklingtonPred N root F₂) (step : ((predModKR (powModTR root (N.pred.div p) N) N).gcd N).beq 1 = true := by exact eagerReduce (Eq.refl true)) (hroot : Nat.blt 0 root = true := by exact eagerReduce (Eq.refl true)) :
    PocklingtonPred N root (F₂.mul (p.pow e))
    theorem PocklingtonPred.step {N root F₂ p : } (hp : Nat.Prime p) (ih : PocklingtonPred N root F₂) (step : ((predModKR (powModTR root (N.pred.div p) N) N).gcd N).beq 1 = true := by exact eagerReduce (Eq.refl true)) (hroot : Nat.blt 0 root = true := by exact eagerReduce (Eq.refl true)) :
    PocklingtonPred N root (F₂.mul p)
    theorem PocklingtonPred.base_pow {N root p e : } (hp : Nat.Prime p) (step : ((predModKR (powModTR root (N.pred.div p) N) N).gcd N).beq 1 = true := by exact eagerReduce (Eq.refl true)) (hroot : Nat.blt 0 root = true := by exact eagerReduce (Eq.refl true)) :
    PocklingtonPred N root (p.pow e)
    theorem PocklingtonPred.base {N root p : } (hp : Nat.Prime p) (step : ((predModKR (powModTR root (N.pred.div p) N) N).gcd N).beq 1 = true := by exact eagerReduce (Eq.refl true)) (hroot : Nat.blt 0 root = true := by exact eagerReduce (Eq.refl true)) :

    A prime power is represented by either p ^ e or p.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        def PrimeCert.Meta.parsePrimePow (stx : Lean.TSyntax `PrimeCert.Meta.prime_pow) :
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          A full factorisation of a number, written like 3 ^ 4 * 29 * 41.

          Equations
          Instances For
            def PrimeCert.Meta.parseFactored (stx : Lean.TSyntax `PrimeCert.Meta.factored) :
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              def PrimeCert.Meta.mkPockPred (N a F₁ : Q()) (steps : Array PrimePow) (dict : PrimeDict) :
              Lean.MetaM Q(PocklingtonPred «$N» «$a» «$F₁»)
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                Syntax for a pock certificate step: (N, root, F₁).

                • N: the number to certify as prime
                • root: a value satisfying root ^ (N-1) ≡ 1 (mod N) and the GCD conditions
                • F₁: a fully-factored divisor of N - 1 with F₁ > √N, written as p₁ ^ e₁ * p₂ * ...

                All prime factors appearing in F₁ must already be in the PrimeDict (certified by earlier small or pock steps).

                -- In a pock% or prime_cert% call:
                pock (339392917, 2, 3 ^ 4 * 29 * 41)
                pock (16290860017, 5, 339392917)
                
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def PrimeCert.Meta.parsePockSpec :
                  PrimeCertMethod `PrimeCert.Meta.pock_spec
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    Equations
                    Instances For
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Convenience elaborator combining small and pock steps into a single term.

                        Syntax: pock% [small_primes; pock_steps]

                        • Before the ;: comma-separated small prime literals whose primality is already known (looked up as PrimeCert.prime_<n> declarations, e.g. PrimeCert.prime_31).
                        • After the ;: comma-separated Pocklington steps (N, root, F₁) where:
                          • N is the number to certify
                          • root is a pseudo-primitive root of N
                          • F₁ is a factored divisor of N - 1 with F₁ > √N, written as p₁ ^ e₁ * p₂ * ...

                        Steps are processed in order; each step can reference primes certified by earlier steps. The last step's N becomes the certified prime.

                        -- Certify 31: declare small primes 2, 3; then one Pocklington step
                        theorem prime_31 : Nat.Prime 31 := pock% [2, 3; (31, 3, 2 * 3)]
                        
                        -- Multi-step ladder: small primes, then intermediate, then target
                        theorem prime_16290860017 : Nat.Prime 16290860017 :=
                          pock% [3, 29, 41; (339392917, 2, 3 ^ 4 * 29 * 41), (16290860017, 5, 339392917)]
                        
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For