Documentation

Mathlib.Tactic.Determinant.Bird.Cert

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 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 #

@[reducible, inline]
abbrev Mathlib.Tactic.Determinant.CertVal {u : Lean.Level} {α : Q(Type u)} ( : Q(CommRing «$α»)) (e : Q(«$α»)) :

The ring tactic normal-form value.

Equations
Instances For
    @[reducible, inline]
    abbrev Mathlib.Tactic.Determinant.CertResult {u : Lean.Level} {α : Q(Type u)} ( : Q(CommRing «$α»)) (subject : Q(«$α»)) :

    The ring tactic result carried by a certificate.

    Equations
    Instances For
      def Mathlib.Tactic.Determinant.Ctx.iterP {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (ctx : Ctx ) (t : ) :
      Q(«$α»)

      Return an expression for the partially applied function iter n A t (get n A)

      Equations
      Instances For
        def Mathlib.Tactic.Determinant.Ctx.sumFrom {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (ctx : Ctx ) (lo : ) (f : Q(«$α»)) :
        Q(«$α»)

        Return an expression sumFrom n lo f

        Equations
        Instances For
          structure Mathlib.Tactic.Determinant.Cert {u : Lean.Level} {α : Q(Type u)} ( : Q(CommRing «$α»)) :

          A certificate that proves subject = result.norm via result.proof

          • subject : Q(«$α»)

            The expression being certified.

          • result : CertResult self.subject

            The result of evaluating subject using the ring tactic.

          • isZero : Bool

            true when norm is zero, used as a hint to the evaluator.

          Instances For
            def Mathlib.Tactic.Determinant.Cert.norm {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (c : Cert ) :
            Q(«$α»)

            The ring tactic normal form of c.subject

            Equations
            Instances For
              def Mathlib.Tactic.Determinant.Cert.val {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (c : Cert ) :

              The internal ring tactic representation of c.norm

              Equations
              Instances For
                def Mathlib.Tactic.Determinant.Cert.proof {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (c : Cert ) :
                have a := c.norm; have a_1 := c.subject; Q(«$a_1» = «$a»)

                The proof that c.subject = c.norm

                Equations
                Instances For
                  def Mathlib.Tactic.Determinant.Cert.chainProof {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} {lhs rhs : Q(«$α»)} (c : Cert ) (h : Q(«$lhs» = «$rhs»)) :
                  Cert

                  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
                    structure Mathlib.Tactic.Determinant.CertCache {u : Lean.Level} {α : Q(Type u)} ( : Q(CommRing «$α»)) :

                    Cache certificates that are reused by the recursive Bird evaluator.

                    Instances For
                      @[reducible, inline]
                      abbrev Mathlib.Tactic.Determinant.CertM {u : Lean.Level} {α : Q(Type u)} ( : Q(CommRing «$α»)) :

                      The monad used by the certificate-chaining evaluator

                      Equations
                      Instances For
                        def Mathlib.Tactic.Determinant.isZeroVal {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} {e : Q(«$α»)} (val : CertVal e) :

                        Checks if val is zero according to the ring tactic

                        Equations
                        Instances For
                          def Mathlib.Tactic.Determinant.toCert {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} {e : Q(«$α»)} (res : Ring.Common.Result (CertVal ) e) :
                          Cert

                          Construct a Cert from a ring tactic result

                          Equations
                          Instances For
                            def Mathlib.Tactic.Determinant.zeroCertOfProof {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} {lhs : Q(«$α»)} (h : Q(«$lhs» = 0)) :
                            Cert

                            Build a zero certificate from a proof lhs = 0.

                            Equations
                            Instances For
                              def Mathlib.Tactic.Determinant.zeroProdCert {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (x : Q(«$α»)) (c : Cert ) :

                              If c.norm = 0, return a certificate with proof x * c.subject = 0 without recursively certifying x.

                              Equations
                              Instances For
                                def Mathlib.Tactic.Determinant.certEval {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (e : Q(«$α»)) :
                                CertM (Cert )

                                Certify e = norm by evaluating e with the ring normalizer.

                                Equations
                                Instances For
                                  def Mathlib.Tactic.Determinant.certAdd {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (a b : Cert ) :
                                  CertM (Cert )

                                  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
                                    def Mathlib.Tactic.Determinant.certMul {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (a b : Cert ) :
                                    CertM (Cert )

                                    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
                                      def Mathlib.Tactic.Determinant.certNeg {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (a : Cert ) :
                                      CertM (Cert )

                                      Certify -a.subject from a certificate for a.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        def Mathlib.Tactic.Determinant.certBirdSign {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (k : ) :
                                        CertM (Cert )

                                        Certify the sign factor (-1)^k from BirdDet.birdDet_eq.

                                        Equations
                                        Instances For
                                          def Mathlib.Tactic.Determinant.certEntry {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (i j : ) :
                                          CertM (Cert )

                                          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
                                            def Mathlib.Tactic.Determinant.certSumFromStop {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (lo : ) (f : Q(«$α»)) :
                                            CertM (Cert )

                                            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
                                              def Mathlib.Tactic.Determinant.certSumFromStep {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (lo : ) (f : Q(«$α»)) (headCert tailCert : CertM (Cert )) :
                                              CertM (Cert )

                                              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
                                                partial def Mathlib.Tactic.Determinant.certIter {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (t i j : ) :
                                                CertM (Cert )

                                                Certify a BirdDet.iter call.

                                                partial def Mathlib.Tactic.Determinant.certDiag {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (t lo : ) :
                                                CertM (Cert )

                                                Certify the diagonal tail sum from BirdDet.iter_succ:

                                                sumFrom n (i + 1) fun k => iter n A t F k k)
                                                
                                                partial def Mathlib.Tactic.Determinant.certTail {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} (t i j lo : ) :
                                                CertM (Cert )

                                                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
                                                
                                                def Mathlib.Tactic.Determinant.certBirdDet {u : Lean.Level} {α : Q(Type u)} { : Q(CommRing «$α»)} :
                                                CertM (Cert )

                                                Certify a BirdDet.birdDet n A call.

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