Documentation

CslibFrontier.Foundations.Data.Polynomial.CoeffList.DivMod

Computable Euclidean division and GCD on polynomial coefficient lists over a field #

Over a field K with decidable equality, this module defines computable polynomial long division (Polynomial.CoeffList.divMod, div, mod) and Euclidean greatest common divisor (Polynomial.CoeffList.gcd) on little-endian coefficient lists (List K), and proves exact correspondence with Euclidean division and GCD in K[X].

Division by an empty or all-zero divisor list returns ([], trim a), matching p / 0 = 0 and p % 0 = p in K[X], so ofCoeffList_div, ofCoeffList_mod, mod_eq_nil_iff_dvd, and ofCoeffList_gcd hold unconditionally for all a b : List K.

Main definitions #

Main results #

Euclidean long division #

def Polynomial.CoeffList.divModStep {K : Type u_1} [Field K] [DecidableEq K] (b : List K) (st : List K × List K) :

One step of polynomial long division of (quotient, remainder) by b.

def Polynomial.CoeffList.divMod {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

Computable Euclidean (quotient, remainder) of a divided by b in K[X].

def Polynomial.CoeffList.div {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

Computable Euclidean quotient of a divided by b in K[X], as a trimmed list.

def Polynomial.CoeffList.mod {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

Computable Euclidean remainder of a modulo b in K[X], as a trimmed list.

theorem Polynomial.CoeffList.length_divModStep_le {K : Type u_1} [Field K] [DecidableEq K] (b q r : List K) {n : ℕ} (hq : q.length ≤ n) (hr : r.length ≤ n) :

Length preservation across one step of divModStep.

theorem Polynomial.CoeffList.divMod_iterate_bounds {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) (k : ℕ) :
have st := (divModStep b)^[k] ([], trim a); st.1.length ≤ a.length ∧ st.2.length ≤ a.length ∧ IsTrimmed st.1 ∧ IsTrimmed st.2

Length and trimming invariants along iterations of divModStep.

theorem Polynomial.CoeffList.length_sub_smul_shift_lt {K : Type u_1} [Field K] [DecidableEq K] {r b : List K} (hr_trim : IsTrimmed r) (hb_trim : IsTrimmed b) (hbne : b ≠ []) (hle : b.length ≤ r.length) :
(sub r (smul (r.getLastD 0 / b.getLastD 0) (shift (r.length - b.length) b))).length < r.length

Subtracting the leading-term multiple smul (r.getLastD 0 / b.getLastD 0) (shift d b) from a trimmed dividend r (b.length ≤ r.length) strictly reduces the trimmed list length.

theorem Polynomial.CoeffList.isTrimmed_div {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

div a b is trimmed.

theorem Polynomial.CoeffList.isTrimmed_mod {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

mod a b is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_div {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :
trim (div a b) = div a b

trim is the identity on div a b.

@[simp]
theorem Polynomial.CoeffList.trim_mod {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :
trim (mod a b) = mod a b

trim is the identity on mod a b.

theorem Polynomial.CoeffList.length_div_le {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

(div a b).length ≤ a.length.

theorem Polynomial.CoeffList.length_mod_le {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

(mod a b).length ≤ a.length.

Division identity ofCoeffList (div a b) * ofCoeffList b + ofCoeffList (mod a b) = ofCoeffList a for all a b : List K.

theorem Polynomial.CoeffList.length_mod_lt {K : Type u_1} [Field K] [DecidableEq K] {a b : List K} (hb : ofCoeffList b ≠ 0) :
(mod a b).length < (trim b).length

When ofCoeffList b ≠ 0, the remainder list mod a b is strictly shorter than trim b.

@[simp]

div a b represents Euclidean quotient ofCoeffList a / ofCoeffList b in K[X].

@[simp]

mod a b represents Euclidean remainder ofCoeffList a % ofCoeffList b in K[X].

theorem Polynomial.CoeffList.eq_divMod_of_isTrimmed {K : Type u_1} [Field K] [DecidableEq K] {a b q r : List K} (hb : ofCoeffList b ≠ 0) (hq : IsTrimmed q) (hr : IsTrimmed r) (hr_lt : r.length < (trim b).length) (heq : ofCoeffList q * ofCoeffList b + ofCoeffList r = ofCoeffList a) :
(q, r) = divMod a b

Uniqueness of Euclidean division on trimmed coefficient lists when ofCoeffList b ≠ 0: any pair of trimmed lists (q, r) with r.length < (trim b).length and ofCoeffList q * ofCoeffList b + ofCoeffList r = ofCoeffList a equals divMod a b.

@[simp]

mod a b = [] if and only if ofCoeffList b divides ofCoeffList a in K[X].

def Polynomial.CoeffList.negMod {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

Computable negated Euclidean remainder -(ofCoeffList a) % ofCoeffList b in K[X], as a trimmed list.

negMod a b is trimmed.

(negMod a b).length ≤ a.length.

theorem Polynomial.CoeffList.length_negMod_lt {K : Type u_1} [Field K] [DecidableEq K] {a b : List K} (hb : ofCoeffList b ≠ 0) :

When ofCoeffList b ≠ 0, negMod a b is strictly shorter than trim b.

@[simp]

negMod a b represents -(ofCoeffList a) % ofCoeffList b in K[X].

Euclidean greatest common divisor #

def Polynomial.CoeffList.gcdStep {K : Type u_1} [Field K] [DecidableEq K] (st : List K × List K) :

One step of the Euclidean algorithm on (x, y).

def Polynomial.CoeffList.gcd {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

Computable Euclidean GCD of two polynomial coefficient lists over K, as a trimmed list.

theorem Polynomial.CoeffList.gcd_iterate_bounds {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) (k : ℕ) :
have st := gcdStep^[k] (trim a, trim b); st.1.length ≤ max a.length b.length ∧ st.2.length ≤ max a.length b.length

Length bounds preserved along iterations of gcdStep.

theorem Polynomial.CoeffList.isTrimmed_gcd {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

gcd a b is trimmed.

@[simp]
theorem Polynomial.CoeffList.trim_gcd {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :
trim (gcd a b) = gcd a b

trim is the identity on gcd a b.

theorem Polynomial.CoeffList.length_gcd_le {K : Type u_1} [Field K] [DecidableEq K] (a b : List K) :

(gcd a b).length ≤ max a.length b.length.

@[simp]

gcd a b computes EuclideanDomain.gcd (ofCoeffList b) (ofCoeffList a) in K[X].

ofCoeffList (gcd a b) divides ofCoeffList a.

ofCoeffList (gcd a b) divides ofCoeffList b.

theorem Polynomial.CoeffList.dvd_ofCoeffList_gcd {K : Type u_1} [Field K] [DecidableEq K] {a b : List K} {u : Polynomial K} (ha : u ∣ ofCoeffList a) (hb : u ∣ ofCoeffList b) :

Every common divisor of ofCoeffList a and ofCoeffList b divides ofCoeffList (gcd a b).

ofCoeffList (gcd a b) ≠ 0 whenever either input represents a nonzero polynomial.