The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Primality
11 declarations. Mathlib docs · Source
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.
theorem Mathlib.Tactic.Primality.Config.mk.inj E1 #
∀ {cert cert_1 : Mathlib.Tactic.Primality.CertMode}, { cert := cert } = { cert := cert_1 } → cert = cert_1
theorem Mathlib.Tactic.Primality.Config.mk.injEq E0 #
∀ (cert cert_1 : Mathlib.Tactic.Primality.CertMode), ({ cert := cert } = { cert := cert_1 }) = (cert = cert_1)
def Mathlib.Tactic.Primality.Config.ctorIdx E1 #
Mathlib.Tactic.Primality.Config → ℕ
def Mathlib.Tactic.Primality.provePrime E1 #
(p : ℕ) →
optParam Mathlib.Tactic.Primality.CertBuilder (Mathlib.Tactic.Primality.Cert.search { }) →
StateT (Std.HashMap ℕ Lean.Expr) Lean.MetaM Q(Nat.Prime «$p»)
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.
structure Mathlib.Tactic.Primality.Config E1 #
Type
Configuration for primality.
ctor Mathlib.Tactic.Primality.Config.mk E0 #
Mathlib.Tactic.Primality.CertMode → Mathlib.Tactic.Primality.Config
abbrev Mathlib.Tactic.Primality.Config.cert E1 #
Mathlib.Tactic.Primality.Config → Mathlib.Tactic.Primality.CertMode
The certificate configuration to use.
def Mathlib.Tactic.Primality.elabPrimalityConfig E1 #
Lean.Syntax →
optParam Mathlib.Tactic.Primality.Config { } →
optParam Bool true → Lean.Elab.Tactic.TacticM Mathlib.Tactic.Primality.Config
Function elaborating Config.
def Mathlib.Tactic.Primality.evalNumeral? E1 #
(e : Q(ℕ)) → Lean.MetaM (Option (ℕ × (nQ : Q(ℕ)) × Q(Mathlib.Meta.NormNum.IsNat «$e» «$nQ»)))
Evaluates e to a numeral with norm_num, if it can.
def Mathlib.Tactic.Primality.elabKnownPrimes E1 #
Array Lean.Term → Lean.Elab.Tactic.TacticM (Std.HashMap ℕ Lean.Expr)
Store the proofs hs of Nat.Prime n in a hashmap.
def Mathlib.Tactic.Primality.primality E1 #
Lean.ParserDescr
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.