Documentation

PrimeCert.Pocklington3

Pocklington's primality test, cube-root variant #

The classic Pocklington test requires factoring a divisor F > √N of N - 1. This variant (due to Brillhart–Lehmer–Selfridge) only needs F > N^(1/3), at the cost of an additional divisibility sieve up to a small bound m and a non-square check on r² - 8s (where R = (N-1)/F and R = 2·F·s + r).

theorem Nat.prime_iff_not_exists_mul_eq' (p : ) :
Prime p 2 p ¬∃ (m : ) (n : ), 2 m m < p 2 n n < p m * n = p
theorem Nat.modEq_prod {ι : Type u_1} {s : Finset ι} {f g : ι} {b : } (hb : is, f i g i [MOD b]) :
is, f i is, g i [MOD b]
theorem Nat.modEq_one_of_dvd_of_prime (n b : ) (prime : ∀ (p : ), Prime pp np 1 [MOD b]) (d : ) (hdn : d n) :
d 1 [MOD b]
theorem Nat.modEq_iff_exists_mul_add {p q b : } (hqb : q < b) :
p q [MOD b] ∃ (k : ), k * b + q = p
theorem Nat.modEq_iff_exists_mul_add' {p q b : } (hqp : q p) :
p q [MOD b] ∃ (k : ), k * b + q = p
theorem Nat.add_sq_eq_dist_sq_add_four_mul (c d : ) :
(c + d) ^ 2 = (max c d - min c d) ^ 2 + 4 * (c * d)

The non-square certificate: one of three conditions that rule out r² - 8s being a perfect square, which is needed to exclude composite factorisations.

Equations
Instances For
    theorem PrimeCert.pocklington3_test (N F R m r s : ) (R_def : F * R + 1 = N) (r_def : R % (2 * F) = r) (s_def : R / (2 * F) = s) (h2n : 2 N) (odd_n : Odd N) (odd_R : Odd R) (primitive : pF.primeFactors, ∃ (a : ), a ^ (N - 1) 1 [MOD N] (a ^ ((N - 1) / p) - 1).gcd N = 1) (divisors : ∀ (l : ), 1 ll < m¬l * F + 1 N) (bound : N + (m * F + 1) * (m * F) < (m * F + 1) * (2 * F ^ 2 + r * F + 1)) (cert : s = 0 ¬IsSquare (r ^ 2 - 8 * s) r ^ 2 < 8 * s) :
    def PrimeCert.forallB (f : Bool) (start len : ) (step : := 1) :
    Equations
    Instances For
      theorem PrimeCert.forallB_iff_range' (f : Bool) (start len step : ) :
      forallB f start len step = true nList.range' start len step, f n = true
      theorem PrimeCert.forallB_iff (f : Bool) (start len step : ) :
      forallB f start len step = true n < len, f (n * step + start) = true
      theorem PrimeCert.forallB_iff' (f : Bool) (start r len step : ) :
      forallB f (start * step + r) len step = true ∀ (n : ), start nn < start + lenf (n * step + r) = true
      theorem PrimeCert.forallB_one_iff (f : Bool) (start len : ) :
      forallB f start len = true ∀ (n : ), start nn < start + lenf n = true
      theorem PrimeCert.Pocklington3Cert.of_prime (r s p : ) (hp : Nat.Prime p) (h2p : 2 < p) (cond : powMod (r ^ 2 - 8 * s) (p / 2) p = p - 1) :

      How to discharge the Pocklington3Cert obligation:

      • zero: s = 0
      • prime p hp: witness that r² - 8s is a quadratic non-residue mod p
      • lt: r² < 8s
      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          Instances For
            noncomputable def PrimeCert.PrimePow.toNat (pp : PrimePow) :
            Equations
            Instances For
              @[simp]
              noncomputable def PrimeCert.pocklington3_calculate (N e root m : ) (F' : List PrimePow) (mode : Pocklington3CertMode) :
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem List.rec_and {α : Type u_1} (f : αBool) (b : Bool) (l : List α) :
                rec b (fun (hd : α) (x : List α) (ih : Bool) => f hd && ih) l = true b = true xl, f x = true
                theorem PrimeCert.of_gcd_pred_mod_eq_one (a b : ) (h : (a % b - 1).gcd b = 1) (hb : 2 b) :
                (a - 1).gcd b = 1
                theorem PrimeCert.pocklington3_certKR (N root m e : ) (F' : List PrimePow) (mode : Pocklington3CertMode) (cert : pocklington3_calculate N e root m F' mode = true) :

                Inputs (not all needed):

                • N: the number to be certified as prime
                • F: an even divisor of N-1, fully factored, to be given as a literal
                • F': the odd part of F, given in factorised form
                • e: the exponent of 2 in F, so that F = 2^e * F'
                • R: the quotient (N-1)/F, odd, given as a literal.
                • root: a pseudo-primitive root (for F)
                • m: an arbitrary number (> 0), which should be small for better performance.
                • s, r := divmod(R, 2*F), given as literals

                Syntax for the non-square certificate mode in pock3:

                • A numeric literal 0 means s = 0
                • A numeric literal p (prime, p > 2) means r² - 8s is a quadratic non-residue mod p
                • < means r² < 8s
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def PrimeCert.Meta.parsePock3Mode (stx : Lean.TSyntax `PrimeCert.Meta.pock3_mode) (dict : PrimeDict) :
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Syntax for a pock3 certificate step: (N, root, m, mode, F).

                    • N: the number to certify as prime
                    • root: a pseudo-primitive root (for the factored part of N - 1)
                    • m: sieve bound — all l * F + 1 for 1 ≤ l < m must not divide N (smaller m = less sieve work but requires larger F)
                    • mode: how to discharge the non-square condition (see pock3_mode)
                    • F: the even, fully-factored divisor of N - 1, written as 2 ^ e * p₁ ^ e₁ * p₂ * ... (the power of 2 must come first)
                    -- Certify 73471: root 3, sieve bound 1, non-square witness 7, F = 2 * 31
                    pock3 (73471, 3, 1, 7, 2 * 31)
                    
                    -- With higher power of 2 and multiple odd factors:
                    pock3 (32560621, 2, 1, 7, 2 ^ 2 * 3 * 29)
                    
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def PrimeCert.Meta.parsePrimePow' (stx : Lean.TSyntax `PrimeCert.Meta.prime_pow) (dict : PrimeDict) :
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def PrimeCert.Meta.parseFactored' (stx : Lean.TSyntax `PrimeCert.Meta.factored) (dict : PrimeDict) :
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          def PrimeCert.Meta.parsePock3Spec :
                          PrimeCertMethod `PrimeCert.Meta.pock3_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