The areas / V09. Commutative algebra I: ideals, polynomials, factorization
Mathlib.Algebra.Polynomial.RuleOfSigns
14 declarations. Mathlib docs · Source
Descartes' Rule of Signs
We define the "sign changes" in the coefficients of a polynomial, and prove Descartes' Rule of Signs: a real polynomial has at most as many positive roots as there are sign changes. A sign change is when there is a positive coefficient followed by a negative coefficient, or vice versa, with any number of zero coefficients in between.
Main Definitions
Polynomial.signVariations: The number of sign changes in a polynomial's coefficients, where0coefficients are ignored.
Main theorem
Polynomial.roots_countP_pos_le_signVariations. States thatP.roots.countP (0 < ·) ≤ P.signVariations, so that positive roots are counted with multiplicity. It's currently proved for anyCommRingwithIsStrictOrderedRing. There is likely some correct statement in terms of a (noncommutative)Ring, butPolynomial.rootsis only defined for commutative rings.
References
def Polynomial.signVariations E3 #
{R : Type u_1} → [inst : Semiring R] → [LinearOrder R] → Polynomial R → ℕ
Counts the number of times that the coefficients in a polynomial change sign, ignoring zero coefficients.
theorem Polynomial.signVariations_zero E0 #
∀ (R : Type u_1) [inst : Semiring R] [inst_1 : LinearOrder R], Polynomial.signVariations 0 = 0
theorem Polynomial.signVariations_monomial E0 #
∀ {R : Type u_1} [inst : Semiring R] [inst_1 : LinearOrder R] (d : ℕ) (c : R),
((Polynomial.monomial d) c).signVariations = 0
Sign variations of a monomial are always zero.
theorem Polynomial.signVariations_eraseLead E1 #
∀ {R : Type u_1} [inst : Semiring R] [inst_1 : LinearOrder R] (P : Polynomial R),
SignType.sign P.leadingCoeff = SignType.sign P.nextCoeff → P.eraseLead.signVariations = P.signVariations
If the first two signs are the same, then signVariations is unchanged by eraseLead
theorem Polynomial.signVariations_eq_eraseLead_add_ite E1 #
∀ {R : Type u_1} [inst : Semiring R] [inst_1 : LinearOrder R] {P : Polynomial R},
P ≠ 0 →
P.signVariations =
P.eraseLead.signVariations +
if SignType.sign P.leadingCoeff = -SignType.sign P.eraseLead.leadingCoeff then 1 else 0
If we drop the leading coefficient, the sign changes drop by 0 or 1 depending on whether the first two nonzero coefficients match.
theorem Polynomial.signVariations_eraseLead_le E1 #
∀ {R : Type u_1} [inst : Semiring R] [inst_1 : LinearOrder R] (P : Polynomial R),
P.eraseLead.signVariations ≤ P.signVariations
We can only lose, not gain, sign changes if we drop the leading coefficient.
theorem Polynomial.signVariations_le_eraseLead_succ E1 #
∀ {R : Type u_1} [inst : Semiring R] [inst_1 : LinearOrder R] (P : Polynomial R),
P.signVariations ≤ P.eraseLead.signVariations + 1
We can only lose at most one sign changes if we drop the leading coefficient.
theorem Polynomial.signVariations_neg E0 #
∀ {R : Type u_1} [inst : Ring R] [inst_1 : LinearOrder R] [IsOrderedRing R] (P : Polynomial R),
(-P).signVariations = P.signVariations
The number of sign changes does not change if we negate.
theorem Polynomial.signVariations_C_mul E0 #
∀ {R : Type u_1} [inst : Ring R] [inst_1 : LinearOrder R] [IsStrictOrderedRing R] {η : R} (P : Polynomial R),
η ≠ 0 → (Polynomial.C η * P).signVariations = P.signVariations
The number of sign changes does not change if we multiply by any nonzero scalar.
theorem Polynomial.signVariations_eraseLead_mul_X_sub_C E1 #
∀ {R : Type u_1} [inst : Ring R] [inst_1 : LinearOrder R] [IsStrictOrderedRing R] {P : Polynomial R} {η : R},
0 < η →
0 < P.leadingCoeff →
P.nextCoeff < 0 →
((Polynomial.X - Polynomial.C η) * P).eraseLead.signVariations =
((Polynomial.X - Polynomial.C η) * P.eraseLead).signVariations
If P's coefficients start with signs [+, -, ...], then multiplying by a binomial X - η
commutes with eraseLead in the number of sign changes. This is because the product of
P and X - η has the pattern [+, -, ...] as well, so then P.eraseLead starts with
[-,...], and multiplying by X - η gives [-, ...] too.
theorem Polynomial.succ_signVariations_X_sub_C_mul_monomial E2 #
∀ {R : Type u_1} [inst : Ring R] [inst_1 : LinearOrder R] [IsStrictOrderedRing R] {η : R} {d : ℕ} {c : R},
c ≠ 0 →
0 < η →
((Polynomial.monomial d) c).signVariations + 1 ≤
((Polynomial.X - Polynomial.C η) * (Polynomial.monomial d) c).signVariations
This lemma is really a specialization of succ_signVariations_le_sub_mul to monomials.
theorem Polynomial.signVariations_X_sub_C_mul_eraseLead_le E2 #
∀ {R : Type u_1} [inst : Ring R] [inst_1 : LinearOrder R] [IsStrictOrderedRing R] {P : Polynomial R} {η : R},
0 < P.leadingCoeff →
0 < P.nextCoeff →
((Polynomial.X - Polynomial.C η) * P.eraseLead).signVariations ≤
((Polynomial.X - Polynomial.C η) * P).signVariations
If a polynomial starts with two positive coefficients, then the sign changes in the product
(X - η) * P is at least the sign changes of (X - η) * P.eraseLead. This lemma lets us do
induction on the degree of P when P starts with matching coefficient signs. Of course this is
also true when the first two coefficients of P are negative, but we just prove the case where
they're positive since it's cleaner and sufficient for the later use.
theorem Polynomial.succ_signVariations_le_X_sub_C_mul E1 #
∀ {R : Type u_1} [inst : Ring R] [inst_1 : LinearOrder R] [IsStrictOrderedRing R] {P : Polynomial R} {η : R},
0 < η → P ≠ 0 → P.signVariations + 1 ≤ ((Polynomial.X - Polynomial.C η) * P).signVariations
Multiplying a polynomial by a linear term X - η adds at least one sign change. This is the
basis for the induction in roots_countP_pos_le_signVariations.
theorem Polynomial.roots_countP_pos_le_signVariations E3 #
∀ {R : Type u_1} [inst : CommRing R] [inst_1 : LinearOrder R] [inst_2 : IsStrictOrderedRing R] (P : Polynomial R),
Multiset.countP (fun x ↦ 0 < x) P.roots ≤ P.signVariations
Descartes' Rule of Signs: the number of positive roots is at most the number of sign variations.