Certificate-chain evaluator for BirdDet.birdDet #
This file contains an evaulator that computes the ring tactic normal form of
Mathlib.LinearAlgebra.Matrix.Determinant.Bird.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 * iter n A k (get n A) 0 0 -- via BirdDet.birdDet_eq
= ring normal form of the product -- certMul (certBirdSign k) (certIter k 0 0)
The iter n A k (get n A) i j function branches on k, (k=0, k=t+1) and
therefore the certIter function has two branches:
certIter k i j
k = 0:
iter n A 0 F i j = F i j -- via BirdDet.iter_zero
= ring normal form of A[i][j] -- via certEntry i j
k = t + 1:
iter n A (t + 1) F i j
= -(sumFrom n (i + 1) fun k => iter n A t F k k) * get n A i j
+ sumFrom n (i + 1) fun k => iter n A t F i k * get n A k j
-- via BirdDet.iter_succ
= 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 evaulator also memoizes the certIter, certDiag and certEntry functions
to improve performance.
Main definitions #
certEntrycertifiesBirdDet.get.certSumFromStopandcertSumFromStepcertifiesBirdDet.sumFrom_stopandBirdDet.sumFrom_step.certItercertifiesBirdDet.iter_zeroandBirdDet.iter_succ.certBirdDetcertifiesBirdDet.birdDet_zeroandBirdDet.birdDet_eq.
The ring tactic normal-form value.
Equations
Instances For
The ring tactic result carried by a certificate.
Equations
- Mathlib.Tactic.Determinant.CertResult rα subject = Mathlib.Tactic.Ring.Common.Result (Mathlib.Tactic.Determinant.CertVal rα) subject
Instances For
Return an expression for the partially applied function iter n A t (get n A)
Equations
- ctx.iterP t = q(BirdDet.iter unknown_1 unknown_2 «$t» (BirdDet.get unknown_1 unknown_2))
Instances For
Return an expression sumFrom n lo f
Equations
- ctx.sumFrom lo f = q(BirdDet.sumFrom unknown_1 «$lo» «$f»)
Instances For
A certificate that proves subject = result.norm via result.proof
- subject : Q(«$α»)
The expression being certified.
- result : CertResult rα self.subject
The result of evaluating
subjectusing the ring tactic. - isZero : Bool
truewhennormis zero, used as a hint to the evaluator.
Instances For
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Cache certificates that are reused by the recursive Bird evaluator.
- entryCache : Std.HashMap (ℕ × ℕ) (Cert rα)
Cache for entry certificates, keyed by matrix indices.
Cache for
itercertificates, keyed by recursion index and matrix indices.- diagCache : Std.HashMap (ℕ × ℕ) (Cert rα)
Cache for diagonal-tail certificates, keyed by recursion index and lower bound.
Instances For
The monad used by the certificate-chaining evaluator
Equations
Instances For
Checks if val is zero according to the ring tactic
Equations
Instances For
Construct a Cert rα from a ring tactic result
Equations
- Mathlib.Tactic.Determinant.toCert res = { subject := e, result := res, isZero := Mathlib.Tactic.Determinant.isZeroVal res.val }
Instances For
Build a zero certificate from a proof lhs = 0.
Equations
- Mathlib.Tactic.Determinant.zeroCertOfProof h = { subject := lhs, result := { expr := q(0), val := Mathlib.Tactic.Ring.Common.ExSum.zero, proof := h }, isZero := true }
Instances For
If c.norm = 0, return a certificate with proof x * c.subject = 0 without
recursively certifying x.
Equations
Instances For
Certify e = norm by evaluating e with the ring normalizer.
Equations
- Mathlib.Tactic.Determinant.certEval e = do let ctx ← read let res ← liftM (Mathlib.Tactic.Ring.Common.eval Mathlib.Tactic.Ring.rcℕ ctx.rc ctx.cα e) pure (Mathlib.Tactic.Determinant.toCert res)
Instances For
Certify a.subject + b.subject from certificates for a and b.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Certify a.subject * b.subject from certificates for a and b.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Certify -a.subject from a certificate for a.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Certify the sign factor (-1)^k from BirdDet.birdDet_eq.
Equations
Instances For
Certify one matrix entry lookup BirdDet.get n A i j.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Certify a BirdDet.iter call.
Certify the diagonal tail sum from BirdDet.iter_succ:
sumFrom n (i + 1) fun k => iter n A t F k k)
Certify the upper-tail sum from BirdDet.iter_succ:
sumFrom n (i + 1) fun k => iter n A t F i k * get n A k j
Certify a BirdDet.birdDet n A call.
Equations
- One or more equations did not get rendered due to their size.