Division of univariate polynomials
The main defs are div_by_monic
and mod_by_monic
.
The compatibility between these is given by mod_by_monic_add_div
.
We also define root_multiplicity
.
The coercion turning a polynomial
into the function which reports the coefficient of a given
monomial X^n
div_X p
return a polynomial q
such that q * X + C (p.coeff 0) = p
.
It can be used in a semiring where the usual division algorithm is not possible
An induction principle for polynomials, valued in Sort* instead of Prop.
Equations
- p.rec_on_horner = λ (M0 : M 0) (MC : Π (p : polynomial R) (a : R), p.coeff 0 = 0 → a ≠ 0 → M p → M (p + ⇑polynomial.C a)) (MX : Π (p : polynomial R), p ≠ 0 → M p → M (p * polynomial.X)), dite (p = 0) (λ (hp : p = 0), _.rec_on M0) (λ (hp : ¬p = 0), _.mpr (dite (p.coeff 0 = 0) (λ (hcp0 : p.coeff 0 = 0), _.mpr (_.mpr (_.mpr (MX p.div_X _ (p.div_X.rec_on_horner M0 MC MX))))) (λ (hcp0 : ¬p.coeff 0 = 0), MC (p.div_X * polynomial.X) (p.coeff 0) _ hcp0 (dite (p.div_X = 0) (λ (hpX0 : p.div_X = 0), show M (p.div_X * polynomial.X), from _.mpr (polynomial.rec_on_horner._main._pack._proof_9.mpr M0)) (λ (hpX0 : ¬p.div_X = 0), MX p.div_X hpX0 (p.div_X.rec_on_horner M0 MC MX))))))
See div_by_monic
.
Equations
- p.div_mod_by_monic_aux = λ (q : polynomial R) (hq : q.monic), ite (q.degree ≤ p.degree ∧ p ≠ 0) (let z : polynomial R := ⇑polynomial.C p.leading_coeff * polynomial.X ^ (p.nat_degree - q.nat_degree) in let dm : polynomial R × polynomial R := (p - z * q).div_mod_by_monic_aux hq in (z + dm.fst, dm.snd)) (0, p)
div_by_monic
gives the quotient of p
by a monic polynomial q
.
mod_by_monic
gives the remainder of p
by a monic polynomial q
.
An algorithm for deciding polynomial divisibility.
The algorithm is "compute p %ₘ q
and compare to 0
".
See
polynomial.mod_by_monicfor the algorithm that computes
%ₘ`.
Equations
- p.decidable_dvd_monic hq = decidable_of_iff (p %ₘ q = 0) _
The largest power of X - C a
which divides p
.
This is computable via the divisibility algorithm decidable_dvd_monic
.
Equations
- polynomial.root_multiplicity a p = dite (p = 0) (λ (h0 : p = 0), 0) (λ (h0 : ¬p = 0), let I : decidable_pred (λ (n : ℕ), ¬(polynomial.X - ⇑polynomial.C a) ^ (n + 1) ∣ p) := λ (n : ℕ), not.decidable in nat.find _)