Documentation

HexMvPoly.Eval

def Hex.MvPoly.eval₂ {n : Nat} {R : Type u} {S : Type v} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Zero R] [Lean.Grind.Semiring S] (f : RS) (x : Fin nS) (p : MvPoly n R cmp) :
S

Evaluate coefficients through f and variables through x. Powers are computed by repeated squaring in Mono.prod.

Equations
Instances For
    def Hex.MvPoly.eval {n : Nat} {R : Type u} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Lean.Grind.Semiring R] (x : Fin nR) (p : MvPoly n R cmp) :
    R

    Evaluate a polynomial at x.

    Equations
    Instances For
      @[reducible, inline]
      abbrev Hex.MvPoly.HornerTerm (n : Nat) (S : Type v) :

      A term whose coefficient has already been mapped into the target semiring.

      Equations
      Instances For
        @[reducible, inline]
        abbrev Hex.MvPoly.HornerGroup (n : Nat) (S : Type v) :

        Terms sharing one exponent in the variable currently being evaluated.

        Equations
        Instances For
          def Hex.MvPoly.hornerExponent {n : Nat} (k : Nat) (m : Mono n) :

          Read an exponent using a natural variable index, returning zero when the index is out of range.

          Equations
          Instances For
            def Hex.MvPoly.insertHornerTerm {n : Nat} {S : Type v} (exponent : Nat) (term : HornerTerm n S) :

            Add a term to an association list keyed by one variable exponent.

            Equations
            Instances For
              def Hex.MvPoly.insertHornerGroupDesc {n : Nat} {S : Type v} (group : HornerGroup n S) :

              Insert an exponent group into descending exponent order.

              Equations
              Instances For
                def Hex.MvPoly.collectHornerGroups {n : Nat} {S : Type v} (k : Nat) (terms : List (HornerTerm n S)) :

                Collect terms into groups keyed by their exponent at variable k.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def Hex.MvPoly.sortHornerGroups {n : Nat} {S : Type v} (groups : List (HornerGroup n S)) :

                  Sort exponent groups from high exponent to low exponent.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Hex.MvPoly.hornerGroups {n : Nat} {S : Type v} (k : Nat) (terms : List (HornerTerm n S)) :

                    Group terms by one variable exponent, ordered from high to low.

                    Equations
                    Instances For
                      def Hex.MvPoly.hornerStep {S : Type v} [Lean.Grind.Semiring S] (x : S) (state group : Nat × S) :

                      Advance one descending sparse-Horner exponent group.

                      Equations
                      Instances For

                        Sparse Horner fold over already-evaluated coefficient groups. Callers must supply groups in descending exponent order. Missing exponents are skipped with repeated-squaring powers.

                        Equations
                        Instances For
                          def Hex.MvPoly.eval₂HornerTerms {n : Nat} {S : Type v} [Lean.Grind.Semiring S] (xs : NatS) :
                          NatNatList (HornerTerm n S)S

                          Evaluate sparse terms by fixed-order Horner in variables 0, 1, ..., n - 1. fuel is the number of variables left.

                          Equations
                          Instances For
                            def Hex.MvPoly.eval₂Horner {n : Nat} {R : Type u} {S : Type v} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Zero R] [Lean.Grind.CommSemiring S] (f : RS) (x : Fin nS) (p : MvPoly n R cmp) :
                            S

                            Evaluate using fixed-variable-order sparse Horner evaluation. The target semiring is commutative because variable nesting may reorder factors.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Hex.MvPoly.evalHorner {n : Nat} {R : Type u} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Lean.Grind.CommSemiring R] (x : Fin nR) (p : MvPoly n R cmp) :
                              R

                              Evaluate at x using fixed-variable-order sparse Horner evaluation.

                              Equations
                              Instances For
                                def Hex.MvPoly.eraseAssigned {n : Nat} {R : Type u} (s : Fin nOption R) (m : Mono n) :

                                Erase the exponents of variables assigned by s.

                                Equations
                                Instances For
                                  def Hex.MvPoly.partialEval {n : Nat} {R : Type u} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Lean.Grind.Semiring R] [DecidableEq R] (s : Fin nOption R) (p : MvPoly n R cmp) :
                                  MvPoly n R cmp

                                  Evaluate the variables assigned by s, leaving all other variables in the same ambient polynomial ring. Terms that collide are combined.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem Hex.MvPoly.eval₂_eq {n : Nat} {R : Type u} {S : Type v} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Zero R] [Lean.Grind.Semiring S] (f : RS) (x : Fin nS) (p : MvPoly n R cmp) :
                                    eval₂ f x p = List.foldl (fun (acc : S) (term : Mono n × R) => acc + f term.snd * Mono.prod x term.fst) 0 p.termsList

                                    Evaluation is the ordered term fold of mapped coefficients times monomial values.

                                    theorem Hex.MvPoly.eval_eq {n : Nat} {R : Type u} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Lean.Grind.Semiring R] (x : Fin nR) (p : MvPoly n R cmp) :
                                    eval x p = List.foldl (fun (acc : R) (term : Mono n × R) => acc + term.snd * Mono.prod x term.fst) 0 p.termsList

                                    Same-ring evaluation is the ordered term fold with unchanged coefficients.

                                    theorem Hex.MvPoly.eval₂Horner_eq {n : Nat} {R : Type u} {S : Type v} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Zero R] [Lean.Grind.CommSemiring S] (f : RS) (x : Fin nS) (p : MvPoly n R cmp) :
                                    eval₂Horner f x p = eval₂ f x p

                                    Sparse Horner evaluation agrees with direct term evaluation.

                                    theorem Hex.MvPoly.evalHorner_eq {n : Nat} {R : Type u} {cmp : Mono nMono nOrdering} [Std.TransCmp cmp] [Std.LawfulEqCmp cmp] [Lean.Grind.CommSemiring R] (x : Fin nR) (p : MvPoly n R cmp) :
                                    evalHorner x p = eval x p

                                    Same-ring sparse Horner evaluation agrees with ordinary evaluation.