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 a
is the polynomiala X^n
. Note thatmonomial n
is defined as anR
-linear map.C a
is the constant polynomiala
. Note thatC
is defined as a ring homomorphism.X
is the polynomialX
, i.e.,monomial 1 1
.p.sum f
is∑ n in p.support, f n (p.coeff n)
, i.e., one sums the values of functions applied to coefficients of the polynomialp
.p.erase n
is the polynomialp
in which one removes thec X^n
term.
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_index
states that(p + q).sum f = p.sum f + q.sum f
;sum_add
states 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 (_ : ∀ (a : S), { toFinsupp := a • 0.toFinsupp } = { toFinsupp := 0 })
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
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- (_ : FaithfulSMul S (Polynomial R)) = (_ : FaithfulSMul S (Polynomial R))
Equations
- One or more equations did not get rendered due to their size.
Equations
- (_ : SMulCommClass S₁ S₂ (Polynomial R)) = (_ : SMulCommClass S₁ S₂ (Polynomial R))
Equations
- (_ : IsScalarTower S₁ S₂ (Polynomial R)) = (_ : IsScalarTower S₁ S₂ (Polynomial R))
Equations
- (_ : IsScalarTower α (Polynomial K) (Polynomial K)) = (_ : IsScalarTower α (Polynomial K) (Polynomial K))
Equations
- (_ : IsCentralScalar S (Polynomial R)) = (_ : IsCentralScalar S (Polynomial R))
Equations
- Polynomial.unique = let src := Polynomial.inhabited; { toInhabited := src, uniq := (_ : ∀ (a : Polynomial R), a = default) }
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
- One or more equations did not get rendered due to their size.
Instances For
Equations
The set of all n
such that X^n
has a non-zero coefficient.
Equations
- Polynomial.support x = match x with | { toFinsupp := p } => p.support
Instances For
monomial s a
is the monomial a * X^s
Equations
- One or more equations did not get rendered due to their size.
Instances For
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
- Polynomial.coeff x = match (motive := Polynomial R → ℕ → R) x with | { toFinsupp := p } => ⇑p
Instances For
Monomials generate the additive monoid of polynomials.
Summing the values of a function applied to the coefficients of a polynomial
Equations
- Polynomial.sum p f = Finset.sum (Polynomial.support p) fun (n : ℕ) => f n (Polynomial.coeff p 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
- Polynomial.update p n a = { toFinsupp := Finsupp.update p.toFinsupp n a }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Polynomial.commRing = CommRing.mk (_ : ∀ (a b : Polynomial R), a * b = b * a)
Equations
- (_ : Nontrivial (Polynomial R)) = (_ : Nontrivial (Polynomial R))
Equations
- One or more equations did not get rendered due to their size.