The type of univariate polynomials with coefficients in a semiring R is Polynomial.
To say "let f be a polynomial with coefficients in R", write:
variable(f:PolynomialR)
The notation R[X] for the polynomial ring over R is also available,
but it is scoped in the Polynomial namespace, so you have to open the scope to use it:
openscopedPolynomialvariable(g:R[X])
In what follows we work over an arbitrary semiring unless stated otherwise.
It is common to open the entire Polynomial namespace,
so that the names Polynomial.C, Polynomial.X, Polynomial.monomial,
Polynomial.eval, Polynomial.natDegree and Polynomial.degree
(and many others) can be written without the Polynomial prefix.
Note that (monomialn:R→ₗ[R]R[X]) is itself an R-linear map
sending a coefficient to the corresponding monomial of degree n,
rather than a plain function of two arguments.
This is occasionally relevant when applying lemmas about linear maps to it.
In practice, concrete polynomials are usually written as sums of terms of the form
(Cr*X^n:R[X]), rather than as (monomialnr:R[X]):
the C/X form composes naturally under +, * and ^,
and most arithmetic and coefficient lemmas are phrased against it.
The Polynomial.monomial form is most useful when you want to manipulate
a single term abstractly, for instance to use its linearity in the coefficient.
The coefficient of degree n of a polynomial p is Polynomial.coeff,
written p.coeffn:
example:R:=p.coeffn
The basic identities for C, X and monomial are Polynomial.coeff_C,
Polynomial.coeff_X and Polynomial.coeff_monomial.
Two polynomials are equal iff all of their coefficients agree,
via Polynomial.coeff_inj and the extensionality lemma Polynomial.ext.
Coefficients of polynomials built from C, X and ring operations
can be computed term-by-term using Polynomial.coeff_add,
Polynomial.coeff_C_mul, Polynomial.coeff_X_pow
(together with Polynomial.coeff_C for constants).
For instance, the coefficients of C r + C 2 * X ^ 2 + X ^ 3 are
r, 0, 2, 1, then 0 from degree 4 on: