Documentation

Mathlib.Tactic.Primality

primality #

Defines the frontend of the primality tactic, which closes goals Nat.Prime n using a certificate constructed from witnesses it finds itself or takes from the user. It also defines provePrime, which proves Nat.Prime p for other meta code.

Proves Nat.Prime p by constructing a certificate with mkCert and turning it into a proof with certifyPrime. A caller with a complete certificate should call certifyPrime directly instead. mkCert may use the primes proved in the state. The proofs constructed on the way are added to the state to be shared.

Equations
Instances For

    Configuration for primality.

    • cert : CertMode

      The certificate configuration to use.

    Instances For

      Function elaborating Config.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Mathlib.Tactic.Primality.evalNumeral? (e : Q(ℕ)) :
        Lean.MetaM (Option (ℕ × (nQ : Q(ℕ)) × Q(Meta.NormNum.IsNat «$e» «$nQ»)))

        Evaluates e to a numeral with norm_num, if it can.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Store the proofs hs of Nat.Prime n in a hashmap.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            primality proves a goal Nat.Prime n, where norm_num evaluates n to a numeral, from a Lucas certificate whose witnesses it searches for or takes from the user.

            A Lucas certificate proves p prime by a primitive root a of p, a number with a ^ (p - 1) % p = 1 and a ^ ((p - 1) / q) % p ≠ 1 for each prime factor q of p - 1. Each such q needs a certificate too, except for primes below 2 ^ 10 which are left to norm_num.

            By default the witnesses are searched for, factorizing each p - 1 by trial division and Pollard's rho method, and (cert := .search { factors := […] }) adds candidate prime factors to the search. (cert := .witnesses […]) takes the witnesses from the user instead:

            example : Nat.Prime 1000003 := by
              primality (cert := .witnesses [
                -- Proves `1000003` prime, since `1000003 - 1 = 2 * 3 * 166667` and `2` is a primitive root.
                .lucas { root := 2, primeFactors := [2, 3, 166667] },
                -- Proves `166667` prime, since `166667 - 1 = 2 * 167 * 499` and `2` is a primitive root.
                .lucas { root := 2, primeFactors := [2, 167, 499] }])
            

            primality (cert := …) [h₁, …] takes proofs hᵢ : Nat.Prime m instead of a certificate. See MathlibTest/Tactic/Primality.lean for more examples.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For