Theory of univariate polynomials #
This file defines Polynomial R, the type of univariate polynomials over the semiring R, builds
a semiring structure on it, and gives basic definitions that are expanded in other files in this
directory.
Main definitions #
monomial n ais the polynomiala X^n. Note thatmonomial nis defined as anR-linear map.C ais the constant polynomiala. Note thatCis defined as a ring homomorphism.Xis the polynomialX, i.e.,monomial 1 1.p.sum fis∑ n ∈ p.support, f n (p.coeff n), i.e., one sums the values of functions applied to coefficients of the polynomialp.p.erase nis the polynomialpin which one removes thec X^nterm.
There are often two natural variants of lemmas involving sums, depending on whether one acts on the
polynomials, or on the function. The naming convention is that one adds index when acting on
the polynomials. For instance,
sum_add_indexstates that(p + q).sum f = p.sum f + q.sum f;sum_addstates thatp.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g.- Notation to refer to
Polynomial R, asR[X]orR[t].
Implementation #
Polynomials are defined using R[ℕ], where R is a semiring.
The variable X commutes with every polynomial p: lemma X_mul proves the identity
X * p = p * X. The relationship to R[ℕ] is through a structure
to make polynomials irreducible from the point of view of the kernel. Most operations
are irreducible since Lean cannot compute anyway with AddMonoidAlgebra. There are two
exceptions that we make semireducible:
- The zero polynomial, so that its coefficients are definitionally equal to
0. - The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds.
The raw implementation of the equivalence between R[X] and R[ℕ] is
done through ofFinsupp and toFinsupp (or, equivalently, rcases p when p is a polynomial
gives an element q of R[ℕ], and conversely ⟨q⟩ gives back p). The
equivalence is also registered as a ring equiv in Polynomial.toFinsuppIso. These should
in general not be used once the basic API for polynomials is constructed.
Polynomial R is the type of univariate polynomials over R,
denoted as R[X] within the Polynomial namespace.
Polynomials should be seen as (semi-)rings with the additional constructor X.
The embedding from R is called C.
- ofFinsupp :: (
- toFinsupp : AddMonoidAlgebra R ℕ
The coefficients
ℕ →₀ Rof a polynomial inR[X]. - )
Instances For
Polynomial R is the type of univariate polynomials over R,
denoted as R[X] within the Polynomial namespace.
Polynomials should be seen as (semi-)rings with the additional constructor X.
The embedding from R is called C.
Equations
- Polynomial.«term_[X]» = Lean.ParserDescr.trailingNode `Polynomial.«term_[X]» 9000 0 (Lean.ParserDescr.symbol "[X]")
Instances For
Conversions to and from AddMonoidAlgebra #
Since R[X] is not defeq to R[ℕ], but instead is a structure wrapping
it, we have to copy across all the arithmetic operators manually, along with the lemmas about how
they unfold around Polynomial.ofFinsupp and Polynomial.toFinsupp.
Equations
- Polynomial.add' = { add := Polynomial.add✝ }
Equations
- Polynomial.neg' = { neg := Polynomial.neg✝ }
Equations
- Polynomial.sub = { sub := fun (a b : Polynomial R) => a + -b }
Equations
- Polynomial.mul' = { mul := Polynomial.mul✝ }
Equations
- Polynomial.instNSMul = { smul := fun (r : ℕ) (p : Polynomial R) => { toFinsupp := r • p.toFinsupp } }
Equations
- Polynomial.smulZeroClass = { smul := fun (r : S) (p : Polynomial R) => { toFinsupp := r • p.toFinsupp }, smul_zero := ⋯ }
Equations
- Polynomial.pow = { pow := fun (p : Polynomial R) (n : ℕ) => npowRec n p }
A more convenient spelling of Polynomial.ofFinsupp.injEq in terms of Iff.
Equations
- Polynomial.inhabited = { default := 0 }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Polynomial.distribSMul = { toSMulZeroClass := Polynomial.smulZeroClass, smul_add := ⋯ }
Equations
- Polynomial.distribMulAction = { toSMul := Polynomial.smulZeroClass.toSMul, one_smul := ⋯, mul_smul := ⋯, smul_zero := ⋯, smul_add := ⋯ }
Equations
- Polynomial.module = { toDistribMulAction := Polynomial.distribMulAction, add_smul := ⋯, zero_smul := ⋯ }
Equations
- Polynomial.unique = { toInhabited := Polynomial.inhabited, uniq := ⋯ }
Ring isomorphism between R[X] and R[ℕ]. This is just an
implementation detail, but it can be useful to transfer results from Finsupp to polynomials.
Equations
- Polynomial.toFinsuppIso R = { toFun := Polynomial.toFinsupp, invFun := Polynomial.ofFinsupp, left_inv := ⋯, right_inv := ⋯, map_mul' := ⋯, map_add' := ⋯ }
Instances For
Equations
Linear isomorphism between R[X] and R[ℕ]. This is just an
implementation detail, but it can be useful to transfer results from Finsupp to polynomials.
Equations
- Polynomial.toFinsuppIsoLinear R = { toFun := (Polynomial.toFinsuppIso R).toFun, map_add' := ⋯, map_smul' := ⋯, invFun := (Polynomial.toFinsuppIso R).invFun, left_inv := ⋯, right_inv := ⋯ }
Instances For
monomial s a is the monomial a * X^s
Equations
- Polynomial.monomial n = { toFun := fun (t : R) => { toFinsupp := Finsupp.single n t }, map_add' := ⋯, map_smul' := ⋯ }
Instances For
C a is the constant polynomial a.
C is provided as a ring homomorphism.
Equations
- Polynomial.C = { toFun := (Polynomial.monomial 0).toFun, map_one' := ⋯, map_mul' := ⋯, map_zero' := ⋯, map_add' := ⋯ }
Instances For
X is the polynomial variable (aka indeterminate).
Equations
- Polynomial.X = (Polynomial.monomial 1) 1
Instances For
Alias of Polynomial.notMem_support_iff.
Monomials generate the additive monoid of polynomials.
Summing the values of a function applied to the coefficients of a polynomial
Instances For
To prove something about polynomials, it suffices to show the condition is closed under taking sums, and it holds for monomials.
erase p n is the polynomial p in which the X^n term has been erased.
Equations
- Polynomial.erase n x✝ = match x✝ with | { toFinsupp := p } => { toFinsupp := Finsupp.erase n p }
Instances For
Replace the coefficient of a p : R[X] at a given degree n : ℕ
by a given value a : R. If a = 0, this is equal to p.erase n
If p.natDegree < n and a ≠ 0, this increases the degree to n.
Instances For
The finset of nonzero coefficients of a polynomial.
Instances For
Equations
- Polynomial.commSemiring = { toSemiring := Polynomial.semiring, mul_comm := ⋯ }
Equations
- Polynomial.instZSMul = { smul := fun (r : ℤ) (p : Polynomial R) => { toFinsupp := r • p.toFinsupp } }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Polynomial.commRing = { toRing := Polynomial.ring, mul_comm := ⋯ }
See also Polynomial.isCancelMulZero_iff: in order for R[X] to have cancellative
multiplication (stronger than NoZeroDivisors in general, but equivalent if R is a ring),
R must have both cancellative multiplication and cancellative addition.
Equations
- One or more equations did not get rendered due to their size.