norm_num
extensions on natural numbers #
This file provides a norm_num
extension to prove that natural numbers are prime and compute
its minimal factor. Todo: compute the list of all factors.
Implementation Notes #
For numbers larger than 25 bits, the primality proof produced by norm_num
is an expression
that is thousands of levels deep, and the Lean kernel seems to raise a stack overflow when
type-checking that proof. If we want an implementation that works for larger primes, we should
generate a proof that has a smaller depth.
Note: evalMinFac.aux
does not raise a stack overflow, which can be checked by replacing the
prf'
in the recursive call by something like (.sort .zero)
A predicate representing partial progress in a proof of minFac
.
Equations
Instances For
theorem
Mathlib.Meta.NormNum.minFacHelper_0
(n : ℕ)
(h1 : Nat.ble 2 n = true)
(h2 : 1 = n % 2)
:
MinFacHelper n 3
theorem
Mathlib.Meta.NormNum.minFacHelper_1
{n k k' : ℕ}
(e : k + 2 = k')
(h : MinFacHelper n k)
(np : n.minFac ≠ k)
:
MinFacHelper n k'
theorem
Mathlib.Meta.NormNum.minFacHelper_2
{n k k' : ℕ}
(e : k + 2 = k')
(nk : ¬Nat.Prime k)
(h : MinFacHelper n k)
:
MinFacHelper n k'
theorem
Mathlib.Meta.NormNum.minFacHelper_3
{n k k' : ℕ}
(e : k + 2 = k')
(nk : (n % k).beq 0 = false)
(h : MinFacHelper n k)
:
MinFacHelper n k'
partial def
Mathlib.Meta.NormNum.evalMinFac.aux
(n : Q(ℕ))
(sℕ : Q(AddMonoidWithOne ℕ))
(nn : Q(ℕ))
(pn : Q(IsNat «$n» «$nn»))
(n' : ℕ)
(ek : Q(ℕ))
(prf : Q(MinFacHelper «$nn» «$ek»))
:
def
Mathlib.Meta.NormNum.evalMinFac.core
(n : Q(ℕ))
(sℕ : Q(AddMonoidWithOne ℕ))
(nn : Q(ℕ))
(pn : Q(IsNat «$n» «$nn»))
(n' : ℕ)
:
Lean.MetaM (Result q(«$n».minFac))
Equations
Instances For
def
Mathlib.Meta.NormNum.evalNatPrime.core
(n nn : Q(ℕ))
(pn : Q(IsNat «$n» «$nn»))
(n' : ℕ)
:
Lean.MetaM (Result q(Nat.Prime «$n»))