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 can not 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.
Polynomials should be seen as (semi-)rings with the additional constructor X.
The embedding from R is called C.
- ofFinsupp :: (
- toFinsupp : AddMonoidAlgebra R ℕ
- )
Instances For
Polynomial R is the type of univariate polynomials over R.
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.zero = { zero := { toFinsupp := 0 } }
Equations
- Polynomial.one = { one := { toFinsupp := 1 } }
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.smulZeroClass = SMulZeroClass.mk ⋯
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
- Polynomial.semiring = let __src := Function.Injective.semiring Polynomial.toFinsupp ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯; Semiring.mk ⋯ ⋯ ⋯ ⋯ (fun (n : ℕ) (x : Polynomial R) => x ^ n) ⋯ ⋯
Equations
- Polynomial.distribSMul = let __src := Function.Injective.distribSMul { toFun := Polynomial.toFinsupp, map_zero' := ⋯, map_add' := ⋯ } ⋯ ⋯; DistribSMul.mk ⋯
Equations
- Polynomial.distribMulAction = let __src := Function.Injective.distribMulAction { toFun := Polynomial.toFinsupp, map_zero' := ⋯, map_add' := ⋯ } ⋯ ⋯; DistribMulAction.mk ⋯ ⋯
Equations
- ⋯ = ⋯
Equations
- Polynomial.module = let __src := Function.Injective.module S { toFun := Polynomial.toFinsupp, map_zero' := ⋯, map_add' := ⋯ } ⋯ ⋯; Module.mk ⋯ ⋯
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- Polynomial.unique = let __src := Polynomial.inhabited; { toInhabited := __src, 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
- Polynomial.instDecidableEq R = (Polynomial.toFinsuppIso R).decidableEq
The set of all n such that X^n has a non-zero coefficient.
Equations
- x.support = match x with | { toFinsupp := p } => p.support
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 = let __src := Polynomial.monomial 0; { toFun := __src.toFun, map_one' := ⋯, map_mul' := ⋯, map_zero' := ⋯, map_add' := ⋯ }
Instances For
Alias of Polynomial.C_eq_natCast.
X is the polynomial variable (aka indeterminate).
Equations
- Polynomial.X = (Polynomial.monomial 1) 1
Instances For
X commutes with everything, even when the coefficients are noncommutative.
Prefer putting constants to the left of X.
This lemma is the loop-avoiding simp version of Polynomial.X_mul.
Prefer putting constants to the left of X ^ n.
This lemma is the loop-avoiding simp version of X_pow_mul_assoc.
coeff p n (often denoted p.coeff n) is the coefficient of X^n in p.
Equations
- x.coeff = match (motive := Polynomial R → ℕ → R) x with | { toFinsupp := p } => ⇑p
Instances For
Alias of Polynomial.coeff_natCast_ite.
Monomials generate the additive monoid of polynomials.
Alias of Polynomial.natCast_mul.
Summing the values of a function applied to the coefficients of a polynomial
Equations
- p.sum f = ∑ n ∈ p.support, f n (p.coeff n)
Instances For
Expressing the product of two polynomials as a double sum.
erase p n is the polynomial p in which the X^n term has been erased.
Equations
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.
Equations
- p.update n a = { toFinsupp := Finsupp.update p.toFinsupp n a }
Instances For
Equations
- Polynomial.commSemiring = let __src := Function.Injective.commSemigroup Polynomial.toFinsupp ⋯ ⋯; CommSemiring.mk ⋯
Equations
- Polynomial.ring = let __src := Function.Injective.ring Polynomial.toFinsupp ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯; Ring.mk ⋯ (fun (x : ℤ) (x_1 : Polynomial R) => x • x_1) ⋯ ⋯ ⋯ ⋯ ⋯ ⋯
Alias of Polynomial.C_eq_intCast.
Equations
- Polynomial.commRing = CommRing.mk ⋯
Equations
- ⋯ = ⋯
Equations
- One or more equations did not get rendered due to their size.