The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Determinant.Bird.Cert
41 declarations. Mathlib docs · Source
Certificate-chain evaluator for BirdDet.birdDet
This file contains an evaluator that computes the ring tactic normal form of
Mathlib.LinearAlgebra.Matrix.Determinant.Bird.Defs.birdDet via iteratively
unfolding its definition, using the ring tactic for ring operations, and caching
intermediate certificates.
The structure Cert rα carries the proof certificate and the evaluator builds
larger certificates as birdDet is unfolded.
The entrypoint of the evaluator certBirdDet follows the two branches (n=0,
n=k+1) of the birdDet function:
certBirdDet (birdDet n A)
n = 0:
birdDet n A
= 1 -- via BirdDet.birdDet_zero
= ring normal form of 1 -- via certEval
n = k + 1:
birdDet n A
= (-1)^k * (stepEntry n A)^[k] (get n A) 0 0 -- via BirdDet.birdDet_eq
= ring normal form of the product -- certMul (certBirdSign k) (certIterStepEntry k 0 0)
The (stepEntry n A)^[k] (get n A) i j expression branches on k, so
certIterStepEntry has two branches:
certIterStepEntry k i j
k = 0:
(stepEntry n A)^[0] F i j
= F i j -- via Function.iterate_zero_apply
= ring normal form of A[i][j] -- via certEntry i j
k = t + 1:
(stepEntry n A)^[t + 1] F i j
= -(sumFrom n (i + 1) fun k => (stepEntry n A)^[t] F k k) * get n A i j
+ sumFrom n (i + 1) fun k => (stepEntry n A)^[t] F i k * get n A k j
-- via Function.iterate_succ_apply'
= normal form of the first summand + normal form of the second summand
-- via certAdd
(certMul (certNeg (certDiag t (i + 1))) (certEntry i j))
(certTail t i j (i + 1))
Then the certDiag and certTail functions certify the two kinds of sumFrom
expressions.
The evaluator also memoizes certIterStepEntry, certDiag and certEntry to
improve performance.
Main definitions
certEntrycertifiesBirdDet.get.certSumFromStopandcertSumFromStepcertifyBirdDet.sumFrom_stopandBirdDet.sumFrom_step.certIterStepEntrycertifies entries of(BirdDet.stepEntry n A)^[t] (BirdDet.get n A).certBirdDetcertifiesBirdDet.birdDet_zeroandBirdDet.birdDet_eq.
theorem Mathlib.Tactic.Determinant.CertCache.mk.injEq E0 #
∀ {u : Lean.Level} {α : Q(Type u)} {rα : Q(CommRing «$α»)}
(entryCache : Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα))
(iterStepEntryCache : Std.HashMap (ℕ × ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα))
(diagCache entryCache_1 : Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα))
(iterStepEntryCache_1 : Std.HashMap (ℕ × ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα))
(diagCache_1 : Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)),
({ entryCache := entryCache, iterStepEntryCache := iterStepEntryCache, diagCache := diagCache } =
{ entryCache := entryCache_1, iterStepEntryCache := iterStepEntryCache_1, diagCache := diagCache_1 }) =
(entryCache = entryCache_1 ∧ iterStepEntryCache = iterStepEntryCache_1 ∧ diagCache = diagCache_1)
theorem Mathlib.Tactic.Determinant.Cert.mk.injEq E0 #
∀ {u : Lean.Level} {α : Q(Type u)} {rα : Q(CommRing «$α»)} {subject : Q(«$α»)}
(result : Mathlib.Tactic.Determinant.CertResult rα subject) (isZero : Bool) (subject_1 : Q(«$α»))
(result_1 : Mathlib.Tactic.Determinant.CertResult rα subject_1) (isZero_1 : Bool),
({ subject := subject, result := result, isZero := isZero } =
{ subject := subject_1, result := result_1, isZero := isZero_1 }) =
(subject = subject_1 ∧ result ≍ result_1 ∧ isZero = isZero_1)
theorem Mathlib.Tactic.Determinant.CertCache.mk.inj E1 #
∀ {u : Lean.Level} {α : Q(Type u)} {rα : Q(CommRing «$α»)}
{entryCache : Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)}
{iterStepEntryCache : Std.HashMap (ℕ × ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)}
{diagCache entryCache_1 : Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)}
{iterStepEntryCache_1 : Std.HashMap (ℕ × ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)}
{diagCache_1 : Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)},
{ entryCache := entryCache, iterStepEntryCache := iterStepEntryCache, diagCache := diagCache } =
{ entryCache := entryCache_1, iterStepEntryCache := iterStepEntryCache_1, diagCache := diagCache_1 } →
entryCache = entryCache_1 ∧ iterStepEntryCache = iterStepEntryCache_1 ∧ diagCache = diagCache_1
def Mathlib.Tactic.Determinant.Cert.ctorIdx E1 #
{u : Lean.Level} → {α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.Cert rα → ℕ
def Mathlib.Tactic.Determinant.CertCache.ctorIdx E1 #
{u : Lean.Level} → {α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.CertCache rα → ℕ
theorem Mathlib.Tactic.Determinant.Cert.mk.inj E1 #
∀ {u : Lean.Level} {α : Q(Type u)} {rα : Q(CommRing «$α»)} {subject : Q(«$α»)}
{result : Mathlib.Tactic.Determinant.CertResult rα subject} {isZero : Bool} {subject_1 : Q(«$α»)}
{result_1 : Mathlib.Tactic.Determinant.CertResult rα subject_1} {isZero_1 : Bool},
{ subject := subject, result := result, isZero := isZero } =
{ subject := subject_1, result := result_1, isZero := isZero_1 } →
subject = subject_1 ∧ result ≍ result_1 ∧ isZero = isZero_1
abbrev Mathlib.Tactic.Determinant.CertVal E1 #
{u : Lean.Level} → {α : Q(Type u)} → Q(CommRing «$α») → Q(«$α») → Type
The ring tactic normal-form value.
abbrev Mathlib.Tactic.Determinant.CertResult E1 #
{u : Lean.Level} → {α : Q(Type u)} → Q(CommRing «$α») → Q(«$α») → Type
The ring tactic result carried by a certificate.
def Mathlib.Tactic.Determinant.Ctx.iterStepEntry E1 #
{u : Lean.Level} → {α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.Ctx rα → ℕ → Q(ℕ → ℕ → «$α»)
Return the expression (stepEntry n A)^[t] (get n A).
def Mathlib.Tactic.Determinant.Ctx.sumFrom E1 #
{u : Lean.Level} →
{α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.Ctx rα → ℕ → Q(ℕ → «$α») → Q(«$α»)
Return an expression sumFrom n lo f
structure Mathlib.Tactic.Determinant.Cert E1 #
{u : Lean.Level} → {α : Q(Type u)} → Q(CommRing «$α») → Type
A certificate that proves subject = result.norm via result.proof
ctor Mathlib.Tactic.Determinant.Cert.mk E0 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
{subject : Q(«$α»)} → Mathlib.Tactic.Determinant.CertResult rα subject → Bool → Mathlib.Tactic.Determinant.Cert rα
abbrev Mathlib.Tactic.Determinant.Cert.subject E1 #
{u : Lean.Level} → {α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.Cert rα → Q(«$α»)
The expression being certified.
abbrev Mathlib.Tactic.Determinant.Cert.result E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
(self : Mathlib.Tactic.Determinant.Cert rα) → Mathlib.Tactic.Determinant.CertResult rα self.subject
The result of evaluating subject using the ring tactic.
abbrev Mathlib.Tactic.Determinant.Cert.isZero E1 #
{u : Lean.Level} → {α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.Cert rα → Bool
true when norm is zero, used as a hint to the evaluator.
def Mathlib.Tactic.Determinant.Cert.norm E1 #
{u : Lean.Level} → {α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.Cert rα → Q(«$α»)
The ring tactic normal form of c.subject
def Mathlib.Tactic.Determinant.Cert.val E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → (c : Mathlib.Tactic.Determinant.Cert rα) → Mathlib.Tactic.Determinant.CertVal rα c.norm
The internal ring tactic representation of c.norm
def Mathlib.Tactic.Determinant.Cert.proof E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
(c : Mathlib.Tactic.Determinant.Cert rα) →
have a := c.norm;
have a_1 := c.subject;
Q(«$a_1» = «$a»)
The proof that c.subject = c.norm
def Mathlib.Tactic.Determinant.Cert.chainProof E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
{lhs rhs : Q(«$α»)} → Mathlib.Tactic.Determinant.Cert rα → Q(«$lhs» = «$rhs») → Mathlib.Tactic.Determinant.Cert rα
Prepend an equality to an existing normalized certificate.
Given c.proof : s.subject = c.norm and h : lhs = s.subject return a
certificate with proof : lhs = c.norm.
structure Mathlib.Tactic.Determinant.CertCache E1 #
{u : Lean.Level} → {α : Q(Type u)} → Q(CommRing «$α») → Type
Cache certificates that are reused by the recursive Bird evaluator.
ctor Mathlib.Tactic.Determinant.CertCache.mk E0 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα) →
Std.HashMap (ℕ × ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα) →
Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα) → Mathlib.Tactic.Determinant.CertCache rα
abbrev Mathlib.Tactic.Determinant.CertCache.entryCache E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Mathlib.Tactic.Determinant.CertCache rα → Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)
Cache for entry certificates, keyed by matrix indices.
abbrev Mathlib.Tactic.Determinant.CertCache.iterStepEntryCache E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Mathlib.Tactic.Determinant.CertCache rα → Std.HashMap (ℕ × ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)
Cache for iterated stepEntry certificates, keyed by step and matrix indices.
abbrev Mathlib.Tactic.Determinant.CertCache.diagCache E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Mathlib.Tactic.Determinant.CertCache rα → Std.HashMap (ℕ × ℕ) (Mathlib.Tactic.Determinant.Cert rα)
Cache for diagonal-tail certificates, keyed by recursion index and lower bound.
abbrev Mathlib.Tactic.Determinant.CertM E1 #
{u : Lean.Level} → {α : Q(Type u)} → Q(CommRing «$α») → Type → Type
The monad used by the certificate-chaining evaluator
def Mathlib.Tactic.Determinant.isZeroVal E1 #
{u : Lean.Level} →
{α : Q(Type u)} → {rα : Q(CommRing «$α»)} → {e : Q(«$α»)} → Mathlib.Tactic.Determinant.CertVal rα e → Bool
Checks if val is zero according to the ring tactic
def Mathlib.Tactic.Determinant.toCert E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
{e : Q(«$α»)} →
Mathlib.Tactic.Ring.Common.Result (Mathlib.Tactic.Determinant.CertVal rα) e → Mathlib.Tactic.Determinant.Cert rα
Construct a Cert rα from a ring tactic result
def Mathlib.Tactic.Determinant.zeroCertOfProof E1 #
{u : Lean.Level} →
{α : Q(Type u)} → {rα : Q(CommRing «$α»)} → {lhs : Q(«$α»)} → Q(«$lhs» = 0) → Mathlib.Tactic.Determinant.Cert rα
Build a zero certificate from a proof lhs = 0.
def Mathlib.Tactic.Determinant.zeroProdCert E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Q(«$α») → Mathlib.Tactic.Determinant.Cert rα → Lean.MetaM (Mathlib.Tactic.Determinant.Cert rα)
If c.norm = 0, return a certificate with proof x * c.subject = 0 without
recursively certifying x.
def Mathlib.Tactic.Determinant.certEval E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → Q(«$α») → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify e = norm by evaluating e with the ring normalizer.
def Mathlib.Tactic.Determinant.certAdd E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Mathlib.Tactic.Determinant.Cert rα →
Mathlib.Tactic.Determinant.Cert rα → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify a.subject + b.subject from certificates for a and b.
def Mathlib.Tactic.Determinant.certMul E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Mathlib.Tactic.Determinant.Cert rα →
Mathlib.Tactic.Determinant.Cert rα → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify a.subject * b.subject from certificates for a and b.
def Mathlib.Tactic.Determinant.certNeg E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
Mathlib.Tactic.Determinant.Cert rα → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify -a.subject from a certificate for a.
def Mathlib.Tactic.Determinant.certBirdSign E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → ℕ → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify the sign factor (-1)^k from BirdDet.birdDet_eq.
def Mathlib.Tactic.Determinant.certEntry E3 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → ℕ → ℕ → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify one matrix entry lookup BirdDet.get n A i j.
def Mathlib.Tactic.Determinant.certSumFromStop E3 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → ℕ → Q(ℕ → «$α») → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify the stop branch of BirdDet.sumFrom.
This corresponds to the else 0 branch of:
sumFrom n lo f = if lo < n then f lo + sumFrom n (lo + 1) f else 0
Throws a meta-level error if called with lo such that lo < ctx.dimension.
def Mathlib.Tactic.Determinant.certSumFromStep E3 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} →
ℕ →
Q(ℕ → «$α») →
Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα) →
Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα) →
Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify the step branch of BirdDet.sumFrom.
This corresponds to the lo < n branch of:
sumFrom n lo f = if lo < n then f lo + sumFrom n (lo + 1) f else 0
Throws a meta-level error if called with lo such that ¬ lo < ctx.dimension.
opaque Mathlib.Tactic.Determinant.certIterStepEntry E3 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → ℕ → ℕ → ℕ → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify an entry of (BirdDet.stepEntry n A)^[t] (BirdDet.get n A).
opaque Mathlib.Tactic.Determinant.certDiag E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → ℕ → ℕ → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify the diagonal tail sum in one BirdDet.stepEntry application:
sumFrom n (i + 1) fun k => (stepEntry n A)^[t] F k k)
opaque Mathlib.Tactic.Determinant.certTail E1 #
{u : Lean.Level} →
{α : Q(Type u)} →
{rα : Q(CommRing «$α»)} → ℕ → ℕ → ℕ → ℕ → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify the upper-tail sum in one BirdDet.stepEntry application:
sumFrom n (i + 1) fun k => (stepEntry n A)^[t] F i k * get n A k j
def Mathlib.Tactic.Determinant.certBirdDet E3 #
{u : Lean.Level} →
{α : Q(Type u)} → {rα : Q(CommRing «$α»)} → Mathlib.Tactic.Determinant.CertM rα (Mathlib.Tactic.Determinant.Cert rα)
Certify a BirdDet.birdDet n A call.