Monad operations on mv_polynomial
#
This file defines two monadic operations on mv_polynomial
. Given p : mv_polynomial σ R
,
mv_polynomial.bind₁
andmv_polynomial.join₁
operate on the variable typeσ
.mv_polynomial.bind₂
andmv_polynomial.join₂
operate on the coefficient typeR
.
mv_polynomial.bind₁ f φ
withf : σ → mv_polynomial τ R
andφ : mv_polynomial σ R
, is the polynomialφ(f 1, ..., f i, ...) : mv_polynomial τ R
.mv_polynomial.join₁ φ
withφ : mv_polynomial (mv_polynomial σ R) R
collapsesφ
to amv_polynomial σ R
, by evaluatingφ
under the mapX f ↦ f
forf : mv_polynomial σ R
. In other words, if you have a polynomialφ
in a set of variables indexed by a polynomial ring, you evaluate the polynomial in these indexing polynomials.mv_polynomial.bind₂ f φ
withf : R →+* mv_polynomial σ S
andφ : mv_polynomial σ R
is themv_polynomial σ S
obtained fromφ
by mapping the coefficients ofφ
throughf
and considering the resulting polynomial as polynomial expression inmv_polynomial σ R
.mv_polynomial.join₂ φ
withφ : mv_polynomial σ (mv_polynomial σ R)
collapsesφ
to amv_polynomial σ R
, by consideringφ
as polynomial expression inmv_polynomial σ R
.
These operations themselves have algebraic structure: mv_polynomial.bind₁
and mv_polynomial.join₁
are algebra homs and
mv_polynomial.bind₂
and mv_polynomial.join₂
are ring homs.
They interact in convenient ways with mv_polynomial.rename
, mv_polynomial.map
,
mv_polynomial.vars
, and other polynomial operations.
Indeed, mv_polynomial.rename
is the "map" operation for the (bind₁
, join₁
) pair,
whereas mv_polynomial.map
is the "map" operation for the other pair.
Implementation notes #
We add an is_lawful_monad
instance for the (bind₁
, join₁
) pair.
The second pair cannot be instantiated as a monad
,
since it is not a monad in Type
but in CommRing
(or rather CommSemiRing
).
bind₁
is the "left hand side" bind operation on mv_polynomial
, operating on the variable type.
Given a polynomial p : mv_polynomial σ R
and a map f : σ → mv_polynomial τ R
taking variables
in p
to polynomials in the variable type τ
, bind₁ f p
replaces each variable in p
with
its value under f
, producing a new polynomial in τ
. The coefficient type remains the same.
This operation is an algebra hom.
Equations
bind₂
is the "right hand side" bind operation on mv_polynomial
,
operating on the coefficient type.
Given a polynomial p : mv_polynomial σ R
and
a map f : R → mv_polynomial σ S
taking coefficients in p
to polynomials over a new ring S
,
bind₂ f p
replaces each coefficient in p
with its value under f
,
producing a new polynomial over S
.
The variable type remains the same. This operation is a ring hom.
Equations
join₁
is the monadic join operation corresponding to mv_polynomial.bind₁
. Given a polynomial p
with coefficients in R
whose variables are polynomials in σ
with coefficients in R
,
join₁ p
collapses p
to a polynomial with variables in σ
and coefficients in R
.
This operation is an algebra hom.
Equations
join₂
is the monadic join operation corresponding to mv_polynomial.bind₂
. Given a polynomial p
with variables in σ
whose coefficients are polynomials in σ
with coefficients in R
,
join₂ p
collapses p
to a polynomial with variables in σ
and coefficients in R
.
This operation is a ring hom.