Documentation

CslibFrontier.Foundations.Data.Polynomial.CoeffList.Arith

Computable polynomial arithmetic on little-endian coefficient lists #

This file equips little-endian coefficient lists (List R, constant coefficient first) with canonical trailing-zero trimming (Polynomial.CoeffList.trim) and computable polynomial operations (add, neg, sub, smul, shift, mul, deriv) over semirings and rings with decidable equality. Every operation returns a trimmed list (Polynomial.CoeffList.IsTrimmed) and commutes with Polynomial.ofCoeffList (ofCoeffList_add, ofCoeffList_sub, ofCoeffList_smul, ofCoeffList_shift, ofCoeffList_mul, ofCoeffList_deriv).

Because trimmed coefficient lists have no trailing zero, two trimmed lists represent the same polynomial under Polynomial.ofCoeffList if and only if they are equal (Polynomial.CoeffList.IsTrimmed.eq_of_ofCoeffList_eq).

Main definitions #

Main results #

Trailing-zero trimming and canonical lists #

def Polynomial.CoeffList.IsTrimmed {R : Type u_1} [Zero R] (p : List R) :

Predicate asserting that a little-endian coefficient list has no trailing 0.

The empty coefficient list is trimmed.

theorem Polynomial.CoeffList.isTrimmed_append_singleton {R : Type u_1} [Zero R] (l : List R) {a : R} (ha : a ≠ 0) :

Appending a nonzero leading coefficient produces a trimmed list.

theorem Polynomial.CoeffList.IsTrimmed.exists_append_singleton {R : Type u_1} [Zero R] {p : List R} (hp : IsTrimmed p) (hne : p ≠ []) :
∃ (l : List R) (a : R), a ≠ 0 ∧ p = l ++ [a]

Every nonempty trimmed list decomposes as l ++ [a] with a ≠ 0.

theorem Polynomial.CoeffList.IsTrimmed.map {R : Type u_1} [Zero R] {S : Type u_2} [Zero S] {p : List R} (hp : IsTrimmed p) (f : R → S) (hf : ∀ (a : R), f a = 0 → a = 0) :

Mapping along a zero-reflecting function preserves IsTrimmed.

def Polynomial.CoeffList.trim {R : Type u_1} [Zero R] [DecidableEq R] :
List R → List R

Strip trailing 0 entries from a little-endian coefficient list.

@[simp]

Trimming the empty list yields [].

theorem Polynomial.CoeffList.trim_cons {R : Type u_1} [Zero R] [DecidableEq R] (a : R) (p : List R) :
trim (a :: p) = if a = 0 ∧ (trim p).isEmpty = true then [] else a :: trim p

Unfolding step for trim on a :: p.

Every output of trim is trimmed.

theorem Polynomial.CoeffList.trim_append_singleton {R : Type u_1} [Zero R] [DecidableEq R] (l : List R) {a : R} (ha : a ≠ 0) :
trim (l ++ [a]) = l ++ [a]

A list ending in a nonzero element is unchanged by trim.

@[simp]
theorem Polynomial.CoeffList.trim_append_zero {R : Type u_1} [Zero R] [DecidableEq R] (l : List R) :
trim (l ++ [0]) = trim l

Appending a trailing zero does not change trim.

@[simp]

trim p = p if and only if p is already trimmed.

theorem Polynomial.CoeffList.IsTrimmed.trim_eq {R : Type u_1} [Zero R] [DecidableEq R] {p : List R} :
IsTrimmed p → trim p = p

Alias of the reverse direction of Polynomial.CoeffList.trim_eq_self_iff.


trim p = p if and only if p is already trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_trim {R : Type u_1} [Zero R] [DecidableEq R] (p : List R) :
trim (trim p) = trim p

trim is idempotent.

theorem Polynomial.CoeffList.trim_sublist {R : Type u_1} [Zero R] [DecidableEq R] (p : List R) :

trim p is a sublist of p.

Trimming never increases list length.

theorem Polynomial.CoeffList.trim_map {R : Type u_1} [Zero R] [DecidableEq R] {S : Type u_2} [Zero S] [DecidableEq S] (f : R → S) (hf : ∀ (a : R), f a = 0 ↔ a = 0) (p : List R) :

trim commutes with any map that preserves and reflects 0.

Degree, leading coefficient, and uniqueness of trimmed lists #

theorem Polynomial.CoeffList.IsTrimmed.coeff_last_ne_zero {R : Type u_1} [Semiring R] {p : List R} (hp : IsTrimmed p) (hne : p ≠ []) :

For a nonempty trimmed list p, coefficient p.length - 1 of ofCoeffList p is nonzero.

Every nonempty trimmed list represents a nonzero polynomial.

A trimmed list is empty if and only if its polynomial is 0.

A nonempty trimmed list p has natDegree (ofCoeffList p) = p.length - 1.

The leading coefficient of ofCoeffList p for trimmed p is p.getLastD 0.

theorem Polynomial.CoeffList.IsTrimmed.degree_lt_of_length_lt {R : Type u_1} [Semiring R] {p q : List R} (hp : IsTrimmed p) (hq : IsTrimmed q) (hq0 : q ≠ []) (hlt : p.length < q.length) :

Shorter trimmed lists have strictly smaller polynomial degree than nonempty trimmed q.

theorem Polynomial.CoeffList.IsTrimmed.eq_of_ofCoeffList_eq {R : Type u_1} [Semiring R] {p q : List R} (hp : IsTrimmed p) (hq : IsTrimmed q) (h : ofCoeffList p = ofCoeffList q) :
p = q

Two trimmed lists representing the same polynomial are equal.

@[simp]

Trimming trailing zeros preserves ofCoeffList.

@[simp]

trim p = [] if and only if ofCoeffList p = 0.

Coefficient lists with equal ofCoeffList have the same trim.

For ofCoeffList p ≠ 0, (trim p).length = (ofCoeffList p).natDegree + 1.

theorem Polynomial.CoeffList.length_trim_le_of_coeff_eq_zero {R : Type u_1} [Semiring R] [DecidableEq R] {p : List R} {n : ℕ} (h : ∀ k ≥ n, (ofCoeffList p).coeff k = 0) :

Vanishing of coefficients at and above n bounds (trim p).length ≤ n.

Semiring operations: add, smul, shift, mul, deriv #

def Polynomial.CoeffList.add {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :

Addition of coefficient lists, returning a trimmed list.

theorem Polynomial.CoeffList.isTrimmed_add {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :

add p q is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_add {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :
trim (add p q) = add p q

trim is the identity on add p q.

Length bound on add p q.

@[simp]

add represents polynomial addition under ofCoeffList.

def Polynomial.CoeffList.smul {R : Type u_1} [Semiring R] [DecidableEq R] (c : R) (p : List R) :

Left scalar multiplication of a coefficient list by c : R, trimmed.

theorem Polynomial.CoeffList.isTrimmed_smul {R : Type u_1} [Semiring R] [DecidableEq R] (c : R) (p : List R) :

smul c p is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_smul {R : Type u_1} [Semiring R] [DecidableEq R] (c : R) (p : List R) :
trim (smul c p) = smul c p

trim is the identity on smul c p.

theorem Polynomial.CoeffList.length_smul_le {R : Type u_1} [Semiring R] [DecidableEq R] (c : R) (p : List R) :

Length bound on smul c p.

@[simp]
theorem Polynomial.CoeffList.ofCoeffList_smul {R : Type u_1} [Semiring R] [DecidableEq R] (c : R) (p : List R) :

smul represents multiplication by C c under ofCoeffList.

def Polynomial.CoeffList.shift {R : Type u_1} [Semiring R] [DecidableEq R] (k : ℕ) (p : List R) :

Monomial shift X ^ k * · by prepending k low-degree zeros and trimming.

theorem Polynomial.CoeffList.isTrimmed_shift {R : Type u_1} [Semiring R] [DecidableEq R] (k : ℕ) (p : List R) :

shift k p is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_shift {R : Type u_1} [Semiring R] [DecidableEq R] (k : ℕ) (p : List R) :
trim (shift k p) = shift k p

trim is the identity on shift k p.

theorem Polynomial.CoeffList.length_shift_le {R : Type u_1} [Semiring R] [DecidableEq R] (k : ℕ) (p : List R) :
(shift k p).length ≤ k + p.length

Length bound on shift k p.

@[simp]

shift k p represents X ^ k * ofCoeffList p.

def Polynomial.CoeffList.mul {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :

Multiplication of coefficient lists via the Cauchy product, returning a trimmed list.

theorem Polynomial.CoeffList.isTrimmed_mul {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :

mul p q is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_mul {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :
trim (mul p q) = mul p q

trim is the identity on mul p q.

theorem Polynomial.CoeffList.length_mul_le {R : Type u_1} [Semiring R] [DecidableEq R] (p q : List R) :
(mul p q).length ≤ p.length + q.length - 1

Length bound on mul p q.

@[simp]

mul represents polynomial multiplication under ofCoeffList.

def Polynomial.CoeffList.deriv {R : Type u_1} [Semiring R] [DecidableEq R] (p : List R) :

Formal derivative of a coefficient list, returning a trimmed list.

deriv p is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_deriv {R : Type u_1} [Semiring R] [DecidableEq R] (p : List R) :

trim is the identity on deriv p.

Length bound on deriv p.

@[simp]

deriv represents the formal polynomial derivative under ofCoeffList.

Ring operations: neg, sub #

def Polynomial.CoeffList.neg {R : Type u_1} [Ring R] [DecidableEq R] (p : List R) :

Negation of a coefficient list, returning a trimmed list.

neg p is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_neg {R : Type u_1} [Ring R] [DecidableEq R] (p : List R) :
trim (neg p) = neg p

trim is the identity on neg p.

Length bound on neg p.

@[simp]

neg represents polynomial negation under ofCoeffList.

def Polynomial.CoeffList.sub {R : Type u_1} [Ring R] [DecidableEq R] (p q : List R) :

Subtraction of coefficient lists, returning a trimmed list.

theorem Polynomial.CoeffList.isTrimmed_sub {R : Type u_1} [Ring R] [DecidableEq R] (p q : List R) :

sub p q is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_sub {R : Type u_1} [Ring R] [DecidableEq R] (p q : List R) :
trim (sub p q) = sub p q

trim is the identity on sub p q.

theorem Polynomial.CoeffList.length_sub_le {R : Type u_1} [Ring R] [DecidableEq R] (p q : List R) :

Length bound on sub p q.

@[simp]

sub represents polynomial subtraction under ofCoeffList.