Documentation

CompPoly.Fields.PrattCertificate

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 #

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.

theorem Nat.Prime.dvd_mul_list {p : } {l : List } (h : Prime p) :
p l.prod rl, p r
inductive PrattPartList (p : ) (a : ZMod p) :
Prop

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.

Instances For
    structure PrattCertificate' (p : ) :

    Alternative 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.

    Instances For
      theorem PrattPartList.out {p : } {a : ZMod p} {n : } (h : PrattPartList p a n) (q : ) :
      Nat.Prime qq na ^ ((p - 1) / q) 1
      inductive PrattPart (p : ) (a : ZMod p) :
      Prop

      The binary version of PrattPartList. This is the one in the original file.

      Instances For
        structure PrattCertificate (p : ) :
        Instances For
          theorem PrattPart.out {p : } {a : ZMod p} {n : } (h : PrattPart p a n) (q : ) :
          Nat.Prime qq na ^ ((p - 1) / q) 1
          def powMod (a b m : ) :
          Instances For
            structure PowTwoRepr :
            Instances For
              Instances For
                Instances For
                  Instances For
                    def g (n c x : ) :
                    Instances For
                      def rho' (n start c : ) :

                      Auxiliary function for rho that tries to find a factor of n

                      Instances For
                        def rho (n : ) :
                        Instances For
                          partial def factor (n : ) :
                          Instances For

                            Factor n into a list of prime numbers with their multiplicities

                            Instances For
                              @[implicit_reducible]
                              Instances For
                                Instances For
                                  theorem Tactic.ZMod.powEqOfPowMod {n a' c : } (a : ZMod n) :
                                  a' = a(a'.pow (n - 1)).mod n = cc = 1a ^ (n - 1) = 1
                                  theorem Tactic.ZMod.bla {n c : } (a : ZMod n) :
                                  c = 1Mathlib.Meta.NormNum.IsNat (a ^ (n - 1)) ca ^ (n - 1) = 1
                                  def Tactic.verifyEqOne (n a' : Q()) (a : Q(ZMod «$n»)) :
                                  Q(«$a'» = «$a»)Lean.MetaM Q(«$a» ^ («$n» - 1) = 1)
                                  Instances For
                                    theorem Tactic.ZMod.powNeOfPowMod {n a' q c : } (a : ZMod n) :
                                    a' = adecide (n 2) = true(a'.pow ((n - 1) / q)).mod n = cdecide (c 1) = truea ^ ((n - 1) / q) 1
                                    theorem Tactic.ZMod.blub {n q c : } (a : ZMod n) :
                                    decide (n 2) = truedecide (c < n) = truedecide (c 1) = trueMathlib.Meta.NormNum.IsNat (a ^ ((n - 1) / q)) ca ^ ((n - 1) / q) 1
                                    def Tactic.verifyNeOne (n a' q : Q()) (a : Q(ZMod «$n»)) :
                                    Q(«$a'» = «$a»)Lean.MetaM Q(«$a» ^ ((«$n» - 1) / «$q») 1)
                                    Instances For
                                      partial def Tactic.verifyCertificate.generatePart (n' : Q()) (a : Q(ZMod «$n'»)) (a' : Q()) (pa' : Q(«$a'» = «$a»)) :
                                      UnverifiedPrattPartLean.MetaM ((nn : Q()) × Q(PrattPart «$n'» «$a» «$nn»))