Polynomials from a list of coefficients, and division by a monic polynomial #
Polynomial is a Finsupp, so none of its arithmetic reduces in the kernel. A polynomial
presented instead by the list of its coefficients does compute, and this file sets up the
translation, together with the one algorithm a computation on such lists needs: division by a
monic polynomial.
TauCeti.Polynomial.ofCoeffList l is the polynomial whose coefficients are the entries of l,
read from the highest degree down, so that it inverts Mathlib's Polynomial.coeffList
(TauCeti.Polynomial.coeffList_ofCoeffList and TauCeti.Polynomial.ofCoeffList_coeffList). Its
defining recursion is Horner's, ofCoeffList (l ++ [a]) = ofCoeffList l * X + C a, and every proof
below runs along it. It is a noncomputable specification map: the lists are what compute.
TauCeti.Polynomial.mulCoeffList multiplies two such lists by convolving their coefficients, and
TauCeti.Polynomial.ofCoeffList_mulCoeffList identifies the result with the product polynomial.
TauCeti.Polynomial.divModByMonicList t l is long division of ofCoeffList l by the monic
polynomial X ^ t.length + ofCoeffList t, carried out as the usual synthetic division: a window of
t.length remainder coefficients is carried along the dividend, and at each step the coefficient
shifted out of the window is the next quotient coefficient and is used to clear the window against
the divisor. Presenting the divisor by the list t of the coefficients below its leading one
makes it monic by construction, so TauCeti.Polynomial.ofCoeffList_divByMonicList and
TauCeti.Polynomial.ofCoeffList_modByMonicList, which identify the two outputs with Mathlib's /ₘ
and %ₘ, need no hypotheses at all. Like Mathlib's /ₘ and %ₘ, the division needs no
commutativity: the window is cleared by x - y * c, with the quotient coefficient c on the
right, which is what matches Mathlib's convention f = g * q + r with the divisor on the left.
The division definitions are @[expose]d, since a consumer computing with them in another module
reduces them in the kernel.
The polynomial whose coefficients are the entries of l, highest degree first:
ofCoeffList [a, b, c] = C a * X ^ 2 + C b * X + C c. This is Horner's rule, and it inverts
Mathlib's Polynomial.coeffList (TauCeti.Polynomial.coeffList_ofCoeffList).
Equations
- TauCeti.Polynomial.ofCoeffList l = List.foldl (fun (p : Polynomial R) (a : R) => p * Polynomial.X + Polynomial.C a) 0 l
Instances For
The empty list of coefficients defines the zero polynomial.
The Horner recursion defining TauCeti.Polynomial.ofCoeffList: appending the coefficient a
at the bottom multiplies the polynomial so far by X and adds the constant C a.
The coefficients of TauCeti.Polynomial.ofCoeffList l are the entries of l read backwards.
Evaluating TauCeti.Polynomial.ofCoeffList l is Horner's rule run directly on the list.
A list of n coefficients defines a polynomial of degree less than n.
Splitting off the leading coefficient of a list of coefficients.
A leading zero coefficient may be dropped. This is not a simp lemma: simp already gets
there through TauCeti.Polynomial.ofCoeffList_cons.
A list of zeros defines the zero polynomial.
The top coefficient of TauCeti.Polynomial.ofCoeffList l is the head of l.
Two lists of the same length define the same polynomial only if they are equal. This is not
injectivity of TauCeti.Polynomial.ofCoeffList, which discards leading zeros.
TauCeti.Polynomial.ofCoeffList inverts Mathlib's Polynomial.coeffList on the lists that
arise as coefficient lists, namely those with no leading zero.
TauCeti.Polynomial.ofCoeffList is a left inverse of Mathlib's Polynomial.coeffList: every
polynomial is recovered from its coefficient list.
Multiplication of descending coefficient lists, by convolving them in ascending degree order.
The output has the usual l.length + m.length - 1 slots; if either input is empty, all of those
slots are zero. This is @[expose]d, since a consumer computing with it in another module
reduces it in the kernel.
Equations
Instances For
TauCeti.Polynomial.mulCoeffList lists the coefficients of a product of polynomials.
The divisor X ^ t.length + ofCoeffList t of TauCeti.Polynomial.divModByMonicList is
monic.
The divisor X ^ t.length + ofCoeffList t has degree exactly t.length.
A monic polynomial is X ^ n plus the polynomial of its remaining coefficients. This is how
a computed coefficient list is recognized as a divisor for TauCeti.Polynomial.divByMonicList.
Scaling every coefficient on the left scales the polynomial.
Negating every coefficient negates the polynomial.
Subtracting a right multiple of one list of coefficients from another, entrywise.
One step of synthetic division by the monic polynomial X ^ t.length + ofCoeffList t: the
pair qr holds the quotient coefficients found so far together with a window of t.length
remainder coefficients, and a is the next coefficient of the dividend.
Equations
Instances For
Long division of the polynomial with coefficient list l by the monic polynomial
X ^ t.length + ofCoeffList t, by synthetic division. The first component is the coefficient
list of the quotient, the second that of the remainder.
Equations
Instances For
The quotient of ofCoeffList l by the monic polynomial X ^ t.length + ofCoeffList t, as a
coefficient list.
Equations
Instances For
The remainder of ofCoeffList l on division by the monic polynomial
X ^ t.length + ofCoeffList t, as a coefficient list.
Equations
Instances For
The division sweeps the dividend from the top coefficient down, one step per coefficient.
The remainder window keeps the length of the divisor's degree throughout the division.
The computed remainder has the length of the divisor's degree.
The division identity for synthetic division: at every stage of the sweep, the part of the dividend read so far is the divisor times the quotient found so far, plus the remainder window.
Synthetic division computes the quotient: the first output of
TauCeti.Polynomial.divModByMonicList is Mathlib's /ₘ by the monic divisor.
Synthetic division computes the remainder: the second output of
TauCeti.Polynomial.divModByMonicList is Mathlib's %ₘ by the monic divisor.