Documentation

CompPoly.Multivariate.CMvPolynomial

Computable multivariate polynomials #

Polynomials of the form α₁ * m₁ + α₂ * m₂ + ... + αₖ * mₖ where αᵢ is any semiring and mᵢ is a CMvMonomial.

This is implemented as a wrapper around CPoly.Lawful, which ensures that all stored coefficients are non-zero.

This file contains the core type definition and basic operations. Higher-level definitions that depend on ring instances (monomial orders, rename, aeval, etc.) are in CMvPolynomial.lean. The CommSemiring and CommRing instances are in MvPolyEquiv.lean.

Main definitions #

@[reducible, inline]
abbrev CPoly.CMvPolynomial (n : ) (R : Type u_1) [Zero R] :
Type u_1

A computable multivariate polynomial in n variables with coefficients in R.

Instances For
    def CPoly.CMvPolynomial.C {n : } {R : Type u_2} [BEq R] [LawfulBEq R] [Zero R] (c : R) :

    Construct a constant polynomial.

    Instances For
      def CPoly.CMvPolynomial.X {n : } {R : Type u_2} [Zero R] [One R] [BEq R] [LawfulBEq R] (i : Fin n) :

      Construct the polynomial $X_i$.

      Instances For
        def CPoly.CMvPolynomial.coeff {R : Type u_2} {n : } [Zero R] (m : CMvMonomial n) (p : CMvPolynomial n R) :
        R

        Extract the coefficient of a monomial.

        Instances For
          theorem CPoly.CMvPolynomial.ext {R : Type u_1} {n : } [Zero R] (p q : CMvPolynomial n R) (h : ∀ (m : CMvMonomial n), coeff m p = coeff m q) :
          p = q

          Extensionality: two polynomials are equal if all their coefficients are equal.

          theorem CPoly.CMvPolynomial.ext_iff {R : Type u_1} {n : } [Zero R] {p q : CMvPolynomial n R} :
          p = q ∀ (m : CMvMonomial n), coeff m p = coeff m q
          @[simp]
          theorem CPoly.CMvPolynomial.add_getD? {R : Type u_1} [BEq R] [LawfulBEq R] {n : } [CommSemiring R] {m : CMvMonomial n} {p q : CMvPolynomial n R} :
          (↑(p + q))[m]?.getD 0 = (↑p)[m]?.getD 0 + (↑q)[m]?.getD 0
          @[simp]
          theorem CPoly.CMvPolynomial.coeff_add {R : Type u_1} [BEq R] [LawfulBEq R] {n : } [CommSemiring R] {m : CMvMonomial n} {p q : CMvPolynomial n R} :
          coeff m (p + q) = coeff m p + coeff m q
          theorem CPoly.CMvPolynomial.fromUnlawful_fold_eq_fold_fromUnlawful₀ {R : Type u_1} [BEq R] [LawfulBEq R] {n : } [CommSemiring R] {t : List (CMvMonomial n × R)} {f : CMvMonomial nRUnlawful n R} (init : Unlawful n R) :
          Lawful.fromUnlawful (List.foldl (fun (u : Unlawful n R) (term : CMvMonomial n × R) => f term.1 term.2 + u) init t) = List.foldl (fun (l : Lawful n R) (term : CMvMonomial n × R) => Lawful.fromUnlawful (f term.1 term.2) + l) (Lawful.fromUnlawful init) t

          Auxiliary lemma showing that conversion from unlawful polynomials respects the sum fold.

          theorem CPoly.CMvPolynomial.fromUnlawful_fold_eq_fold_fromUnlawful {R : Type u_1} [BEq R] [LawfulBEq R] {n : } [CommSemiring R] {t : Unlawful n R} {f : CMvMonomial nRUnlawful n R} :
          Lawful.fromUnlawful (Std.ExtTreeMap.foldl (fun (u : Unlawful n R) (m : CMvMonomial n) (c : R) => f m c + u) 0 t) = Std.ExtTreeMap.foldl (fun (l : Lawful n R) (m : CMvMonomial n) (c : R) => Lawful.fromUnlawful (f m c) + l) 0 t

          Auxiliary lemma showing that conversion from unlawful polynomials respects the fold over terms.

          def CPoly.CMvPolynomial.eval₂ {R : Type u_2} {S : Type u_3} {n : } [Semiring R] [CommSemiring S] :
          (R →+* S) → (Fin nS)CMvPolynomial n RS

          Evaluate a polynomial at a point given by a ring homomorphism f and variable assignments vs.

          Instances For
            @[reducible, inline]
            abbrev CPoly.CMvPolynomial.HornerTerm (n : ) (S : Type u_2) :
            Type u_2

            Term representation used by the fixed-order multivariate Horner evaluator.

            Instances For
              @[reducible, inline]
              abbrev CPoly.CMvPolynomial.HornerGroup (n : ) (S : Type u_2) :
              Type u_2

              Terms grouped by one variable exponent.

              Instances For

                Read the exponent for a variable index represented as a natural number.

                Instances For
                  def CPoly.CMvPolynomial.insertHornerTerm {n : } {S : Type u_2} (exponent : ) (term : HornerTerm n S) :

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

                  Instances For

                    Insert an exponent group into descending exponent order.

                    Instances For
                      def CPoly.CMvPolynomial.collectHornerGroups {n : } {S : Type u_2} (k : ) (terms : List (HornerTerm n S)) :

                      Collect terms into association-list groups keyed by the current variable exponent.

                      Instances For
                        def CPoly.CMvPolynomial.sortHornerGroups {n : } {S : Type u_2} (groups : List (HornerGroup n S)) :

                        Sort exponent groups from high exponent to low exponent.

                        Instances For
                          def CPoly.CMvPolynomial.hornerGroups {n : } {S : Type u_2} (k : ) (terms : List (HornerTerm n S)) :

                          Group terms by the current variable exponent, sorted from high to low exponent.

                          Instances For

                            Sparse Horner fold for already-evaluated coefficient groups.

                            Instances For
                              def CPoly.CMvPolynomial.eval₂HornerTerms {n : } {S : Type u_2} [CommSemiring S] (xs : S) :
                              List (HornerTerm n S)S

                              Evaluate sparse multivariate terms by fixed-order Horner in variables 0, 1, ..., n-1.

                              Instances For
                                def CPoly.CMvPolynomial.eval₂Horner {R : Type u_2} {S : Type u_3} {n : } [Semiring R] [CommSemiring S] :
                                (R →+* S) → (Fin nS)CMvPolynomial n RS

                                Evaluate a polynomial using fixed-order multivariate Horner evaluation.

                                Instances For
                                  def CPoly.CMvPolynomial.eval {R : Type u_2} {n : } [CommSemiring R] :
                                  (Fin nR)CMvPolynomial n RR

                                  Evaluate a polynomial at a given point.

                                  Instances For
                                    def CPoly.CMvPolynomial.evalHorner {R : Type u_2} {n : } [CommSemiring R] :
                                    (Fin nR)CMvPolynomial n RR

                                    Evaluate a polynomial at a given point using fixed-order multivariate Horner evaluation.

                                    Instances For
                                      def CPoly.CMvPolynomial.support {R : Type u_2} {n : } [Zero R] (p : CMvPolynomial n R) :

                                      The support of a polynomial (set of monomials with non-zero coefficients), represented as Finsupps.

                                      Instances For

                                        The total degree of a polynomial (maximum total degree of its monomials).

                                        Instances For
                                          def CPoly.CMvPolynomial.degreeOf {R : Type u_2} {n : } [Zero R] (i : Fin n) :

                                          The degree of a polynomial in a specific variable.

                                          Instances For
                                            def CPoly.CMvPolynomial.monomial {n : } {R : Type u_2} [BEq R] [LawfulBEq R] [Zero R] (m : CMvMonomial n) (c : R) :

                                            Construct a monomial c * m as a CMvPolynomial n R.

                                            Creates a polynomial with a single monomial term. If c = 0, returns the zero polynomial.

                                            Instances For
                                              def CPoly.CMvPolynomial.degrees {n : } {R : Type u_2} [Zero R] (p : CMvPolynomial n R) :

                                              Multiset of all variable degrees appearing in the polynomial.

                                              Each variable i appears degreeOf i p times in the multiset.

                                              Instances For

                                                degreeOf is the multiplicity of a variable in degrees.

                                                def CPoly.CMvPolynomial.vars {n : } {R : Type u_2} [Zero R] (p : CMvPolynomial n R) :

                                                Extract the set of variables that appear in a polynomial.

                                                Returns the set of variable indices i : Fin n such that degreeOf i p > 0.

                                                Instances For
                                                  def CPoly.CMvPolynomial.restrictBy {n : } {R : Type u_2} [BEq R] [LawfulBEq R] [Zero R] (keep : CMvMonomial nProp) [DecidablePred keep] (p : CMvPolynomial n R) :

                                                  Filter a polynomial, keeping only monomials for which keep m is true.

                                                  Instances For
                                                    def CPoly.CMvPolynomial.restrictTotalDegree {n : } {R : Type u_2} [BEq R] [LawfulBEq R] [Zero R] (d : ) (p : CMvPolynomial n R) :

                                                    Restrict polynomial to monomials with total degree ≤ d.

                                                    Filters out all monomials where m.totalDegree > d.

                                                    Instances For
                                                      def CPoly.CMvPolynomial.restrictDegree {n : } {R : Type u_2} [BEq R] [LawfulBEq R] [Zero R] (d : ) (p : CMvPolynomial n R) :

                                                      Restrict polynomial to monomials whose degree in each variable is ≤ d.

                                                      Filters out all monomials where m.degreeOf i > d for some variable i.

                                                      Instances For