Multivariate polynomials
This file defines polynomial rings over a base ring (or even semiring),
with variables from a general type σ
(which could be infinite).
Important definitions
Let R
be a commutative ring (or a semiring) and let σ
be an arbitrary
type. This file creates the type mv_polynomial σ R
, which mathematicians
might denote R[X_i : i ∈ σ]
. It is the type of multivariate
(a.k.a. multivariable) polynomials, with variables
corresponding to the terms in σ
, and coefficients in R
.
Notation
In the definitions below, we use the following notation:
σ : Type*
(indexing the variables)R : Type*
[comm_semiring R]
(the coefficients)s : σ →₀ ℕ
, a function fromσ
toℕ
which is zero away from a finite set. This will give rise to a monomial inmv_polynomial σ R
which mathematicians might callX^s
a : R
i : σ
, with corresponding monomialX i
, often denotedX_i
by mathematiciansp : mv_polynomial σ R
Definitions
mv_polynomial σ R
: the type of polynomials with variables of typeσ
and coefficients in the commutative semiringR
monomial s a
: the monomial which mathematically would be denoteda * X^s
C a
: the constant polynomial with valuea
X i
: the degree one monomial corresponding to i; mathematically this might be denotedXᵢ
.coeff s p
: the coefficient ofs
inp
.eval₂ (f : R → S) (g : σ → S) p
: given a semiring homomorphism fromR
to another semiringS
, and a mapσ → S
, evaluatesp
at this valuation, returning a term of typeS
. Note thateval₂
can be made usingeval
andmap
(see below), and it has been suggested that sticking toeval
andmap
might make the code less brittle.eval (g : σ → R) p
: given a mapσ → R
, evaluatesp
at this valuation, returning a term of typeR
map (f : R → S) p
: returns the multivariate polynomial obtained fromp
by the change of coefficient semiring corresponding tof
degrees p
: the multiset of variables representing the union of the multisets corresponding to each non-zero monomial inp
. For example if7 ≠ 0
inR
andp = x²y+7y³
thendegrees p = {x, x, y, y, y}
vars p
: the finset of variables occurring inp
. For example ifp = x⁴y+yz
thenvars p = {x, y, z}
degree_of n p : ℕ
-- the total degree ofp
with respect to the variablen
. For example ifp = x⁴y+yz
thendegree_of y p = 1
.total_degree p : ℕ
-- the max of the sizes of the multisetss
whose monomialsX^s
occur inp
. For example ifp = x⁴y+yz
thentotal_degree p = 5
.pderivative i p
: the partial derivative ofp
with respect toi
.
Implementation notes
Recall that if Y
has a zero, then X →₀ Y
is the type of functions from X
to Y
with finite
support, i.e. such that only finitely many elements of X
get sent to non-zero terms in Y
.
The definition of mv_polynomial σ α
is (σ →₀ ℕ) →₀ α
; here σ →₀ ℕ
denotes the space of all
monomials in the variables, and the function to α
sends a monomial to its coefficient in
the polynomial being represented.
Tags
polynomial, multivariate polynomial, multivariable polynomial
Multivariate polynomial, where σ
is the index set of the variables and
α
is the coefficient ring
Equations
- mv_polynomial σ α = add_monoid_algebra α (σ →₀ ℕ)
Equations
- mv_polynomial.inhabited = {default := 0}
Equations
the coercion turning an mv_polynomial
into the function which reports the coefficient of a given monomial
monomial s a
is the monomial a * X^s
Equations
- mv_polynomial.monomial s a = finsupp.single s a
C a
is the constant polynomial with value a
Equations
- mv_polynomial.C = {to_fun := mv_polynomial.monomial 0, map_one' := _, map_mul' := _, map_zero' := _, map_add' := _}
X n
is the degree 1
monomial 1*n
Equations
- mv_polynomial.X n = mv_polynomial.monomial (finsupp.single n 1) 1
The coefficient of the monomial m
in the multi-variable polynomial p
.
Equations
- mv_polynomial.coeff m p = ⇑p m
Equations
- _ = _
Evaluate a polynomial p
given a valuation g
of all the variables
and a ring hom f
from the scalar ring to the target
Equations
- mv_polynomial.eval₂ f g p = finsupp.sum p (λ (s : σ →₀ ℕ) (a : α), ⇑f a * s.prod (λ (n : σ) (e : ℕ), g n ^ e))
Equations
- _ = _
mv_polynomial.eval₂
as a ring_hom
.
Equations
Evaluate a polynomial p
given a valuation f
of all the variables
Equations
map f p
maps a polynomial p
across a ring hom f
Equations
The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, degrees (x^2 * y + y^3)
would be {x, x, y, y, y}
.)
vars p
is the set of variables appearing in the polynomial p
degree_of n p
gives the highest power of X_n that appears in p
Equations
total_degree p
gives the maximum |s| over the monomials X^s in p
The algebra of multivariate polynomials
A map σ → A
where A
is an algebra over R
generates an R
-algebra homomorphism
from multivariate polynomials over σ
to A
.
Equations
- mv_polynomial.aeval f = {to_fun := (mv_polynomial.eval₂_hom (algebra_map R A) f).to_fun, map_one' := _, map_mul' := _, map_zero' := _, map_add' := _, commutes' := _}
Equations
A ring homomorphism f : Z[X_1, X_2, ...] → R is determined by the evaluations f(X_1), f(X_2), ...
Ring homomorphisms out of integer polynomials on a type σ
are the same as
functions out of the type σ
,
Equations
- mv_polynomial.hom_equiv = {to_fun := λ (f : mv_polynomial σ ℤ →+* β), ⇑f ∘ mv_polynomial.X, inv_fun := λ (f : σ → β), mv_polynomial.eval₂_hom (int.cast_ring_hom β) f, left_inv := _, right_inv := _}
Rename all the variables in a multivariable polynomial.
Equations
Every polynomial is a polynomial in finitely many variables.
Every polynomial is a polynomial in finitely many variables.
The ring isomorphism between multivariable polynomials in no variables and the ground ring.
Equations
- mv_polynomial.pempty_ring_equiv α = {to_fun := mv_polynomial.eval₂ (ring_hom.id α) pempty.elim, inv_fun := ⇑mv_polynomial.C, left_inv := _, right_inv := _, map_mul' := _, map_add' := _}
The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring.
Equations
- mv_polynomial.punit_ring_equiv α = {to_fun := mv_polynomial.eval₂ polynomial.C (λ (u : punit), polynomial.X), inv_fun := polynomial.eval₂ mv_polynomial.C (mv_polynomial.X punit.star), left_inv := _, right_inv := _, map_mul' := _, map_add' := _}
The ring isomorphism between multivariable polynomials induced by an equivalence of the variables.
The ring isomorphism between multivariable polynomials induced by a ring isomorphism of the ground ring.
The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficents in multivariable polynomials in the other type.
See sum_ring_equiv
for the ring isomorphism.
Equations
- mv_polynomial.sum_to_iter α β γ = mv_polynomial.eval₂_hom (mv_polynomial.C.comp mv_polynomial.C) (λ (bc : β ⊕ γ), bc.rec_on mv_polynomial.X (⇑mv_polynomial.C ∘ mv_polynomial.X))
Equations
- _ = _
The function from multivariable polynomials in one type, with coefficents in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types.
See sum_ring_equiv
for the ring isomorphism.
Equations
A helper function for sum_ring_equiv
.
The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficents in multivariable polynomials in the other type.
Equations
- mv_polynomial.sum_ring_equiv α β γ = mv_polynomial.mv_polynomial_equiv_mv_polynomial α (β ⊕ γ) β (mv_polynomial γ α) (mv_polynomial.sum_to_iter α β γ) (mv_polynomial.iter_to_sum α β γ) _ _ _ _
The ring isomorphism between multivariable polynomials in option β
and
polynomials with coefficients in mv_polynomial β α
.
Equations
The ring isomorphism between multivariable polynomials in option β
and
multivariable polynomials with coefficients in polynomials.
The ring isomorphism between multivariable polynomials in fin (n + 1)
and
polynomials over multivariable polynomials in fin n
.
Equations
Partial derivatives
pderivative v p
is the partial derivative of p
with respect to v
Equations
- mv_polynomial.pderivative v p = finsupp.sum p (λ (A : S →₀ ℕ) (B : R), mv_polynomial.monomial (A - finsupp.single v 1) (B * ↑(⇑A v)))
pderivative : S → mv_polynomial S R → mv_polynomial S R
as an add_monoid_hom
Equations
- mv_polynomial.pderivative.add_monoid_hom R v = {to_fun := mv_polynomial.pderivative v, map_zero' := _, map_add' := _}