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 #
CPoly.CMvPolynomial n R: The type of multivariate polynomials innvariables with coefficients inR.CPoly.CMvPolynomial.C: Constant polynomial constructor.CPoly.CMvPolynomial.X: Variable polynomial constructor.CPoly.CMvPolynomial.monomial: Monomial constructor.CPoly.CMvPolynomial.coeff: Extract the coefficient of a monomial.CPoly.CMvPolynomial.eval₂,CPoly.CMvPolynomial.eval: Polynomial evaluation.CPoly.CMvPolynomial.support,CPoly.CMvPolynomial.totalDegree,CPoly.CMvPolynomial.degreeOf,CPoly.CMvPolynomial.degrees,CPoly.CMvPolynomial.vars: Degree and support queries.
A computable multivariate polynomial in n variables with coefficients in R.
Equations
- CPoly.CMvPolynomial n R = CPoly.Lawful n R
Instances For
Construct a constant polynomial.
Equations
Instances For
Construct the polynomial $X_i$.
Equations
- CPoly.CMvPolynomial.X i = CPoly.Lawful.fromUnlawful (CPoly.Unlawful.ofList [(Vector.ofFn fun (j : Fin n) => if j = i then 1 else 0, 1)])
Instances For
Extract the coefficient of a monomial.
Instances For
Extensionality: two polynomials are equal if all their coefficients are equal.
Auxiliary lemma showing that conversion from unlawful polynomials respects the sum fold.
Auxiliary lemma showing that conversion from unlawful polynomials respects the fold over terms.
Evaluate a polynomial at a point given by a ring homomorphism f
and variable assignments vs.
Equations
- CPoly.CMvPolynomial.eval₂ f vs p = Std.ExtTreeMap.foldl (fun (s : S) (m : CPoly.CMvMonomial n) (c : R) => f c * CPoly.MonoR.evalMonomial vs m + s) 0 ↑p
Instances For
Evaluate a polynomial at a given point.
Equations
Instances For
The support of a polynomial (set of monomials with non-zero coefficients), represented as Finsupps.
Equations
Instances For
The total degree of a polynomial (maximum total degree of its monomials).
Equations
- p.totalDegree = (List.map CPoly.CMvMonomial.toFinsupp (CPoly.Lawful.monomials p)).toFinset.sup fun (s : Fin n →₀ ℕ) => s.sum fun (x : Fin n) (e : ℕ) => e
Instances For
The degree of a polynomial in a specific variable.
Equations
- CPoly.CMvPolynomial.degreeOf i p = Multiset.count i ((List.map CPoly.CMvMonomial.toFinsupp (CPoly.Lawful.monomials p)).toFinset.sup fun (s : Fin n →₀ ℕ) => Finsupp.toMultiset s)
Instances For
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.
Equations
- CPoly.CMvPolynomial.monomial m c = if (c == 0) = true then 0 else CPoly.Lawful.fromUnlawful (CPoly.Unlawful.ofList [(m, c)])
Instances For
Multiset of all variable degrees appearing in the polynomial.
Each variable i appears degreeOf i p times in the multiset.
Equations
- p.degrees = ∑ i : Fin n, Multiset.replicate (CPoly.CMvPolynomial.degreeOf i p) i
Instances For
Filter a polynomial, keeping only monomials for which keep m is true.
Equations
- CPoly.CMvPolynomial.restrictBy keep p = CPoly.Lawful.fromUnlawful (Std.ExtTreeMap.filter (fun (m : CPoly.CMvMonomial n) (x : R) => decide (keep m)) ↑p)
Instances For
Restrict polynomial to monomials with total degree ≤ d.
Filters out all monomials where m.totalDegree > d.
Equations
- CPoly.CMvPolynomial.restrictTotalDegree d p = CPoly.CMvPolynomial.restrictBy (fun (m : CPoly.CMvMonomial n) => m.totalDegree ≤ d) p
Instances For
Restrict polynomial to monomials whose degree in each variable is ≤ d.
Filters out all monomials where m.degreeOf i > d for some variable i.
Equations
- CPoly.CMvPolynomial.restrictDegree d p = CPoly.CMvPolynomial.restrictBy (fun (m : CPoly.CMvMonomial n) => ∀ (i : Fin n), m.degreeOf i ≤ d) p