πŸ’Ž Reusable layer
← all 82R0013

Sturm's theorem

API

Use this theorem

  1. Create a project

    Shell
    lake +leanprover/lean4:v4.35.0 new myproject std.toml
    cd myproject

    Standard template, not math: the math template adds its own Mathlib requirement pinned to the Lean release tag, not to the Mathlib commit this package is built and tested with, so you would get a second, different Mathlib. Mathlib comes in through this package. Skip this step in an existing project with the same Lean and Mathlib.

  2. Add the dependency to lakefile.toml

    TOML
    [[require]]
    name = "formalizations"
    git = "https://github.com/karlesmarin/formalizations"
    rev = "v0.15.0"
  3. Import the minimal module

    Lean 4
    import Formalizations.Reusable.Polynomial

    In a file of the project, e.g. Example.lean.

  4. Paste the example

    Lean 4
    open Formalizations.Reusable Polynomial
    
    /-- Sturm: if the Sturm chain of a squarefree `p` does not lose sign variations from `a` to `b`,
    then `p` has no root in `(a, b]`. -/
    example (p : Polynomial ℝ) (hp : Squarefree p) {a b : ℝ} (hab : a < b) (ha : p.eval a β‰  0)
        (hb : p.eval b β‰  0)
        (h : ((sturmSeq p (derivative p)).map (fun q => q.eval a)).signVariations ≀
          ((sturmSeq p (derivative p)).map (fun q => q.eval b)).signVariations) :
        βˆ€ x ∈ Set.Ioc a b, Β¬ p.IsRoot x := by
      intro x hx hroot
      have hcount := sturm_signVariations_sub_eq_card_roots p hp hab ha hb
      have hmem : x ∈ p.roots.toFinset.filter (fun x => a < x ∧ x ≀ b) := by
        rw [Finset.mem_filter, Multiset.mem_toFinset, mem_roots hp.ne_zero]
        exact ⟨hroot, hx.1, hx.2⟩
      have hpos := Finset.card_pos.2 ⟨x, hmem⟩
      omega

    Steps 3 and 4 together are a complete Lean file:FormalizationsTest/ReusablePolynomialExample.lean at v0.15.0, compiled by the CI.

  5. Fetch and check

    Shell
    lake update
    lake lean Example.lean

    lake update fetches this package and Mathlib, and Mathlib's update hook downloads the compiled Mathlib (lake exe cache get). lake lean Example.lean builds the imports of the file (steps 3 and 4) and checks it. If the file belongs to a lean_lib of your project, lake build <lib> does the same. Avoid a bare lake build in a project from the standard template: its default target is the executable, whose link compiles every imported Mathlib module to native code. Same versions required: Lean v4.35.0, Mathlib f0b4c81.

Alternative: import Formalizations.Reusable imports the whole layer (all areas).

Sturm's theorem: for squarefree p ∈ ℝ[X] and a < b with p(a), p(b) β‰  0, the sign variations of Mathlib's Polynomial.sturmSeq p p' at a minus those at b equal the number of distinct roots of p in (a, b].

Lean statement

Lean 4
theorem sturm_signVariations_sub_eq_card_roots (p : Polynomial ℝ) (hp : Squarefree p) {a b : ℝ}
    (hab : a < b) (ha : p.eval a β‰  0) (hb : p.eval b β‰  0) :
    ((Polynomial.sturmSeq p (derivative p)).map (fun q => q.eval a)).signVariations -
        ((Polynomial.sturmSeq p (derivative p)).map (fun q => q.eval b)).signVariations =
      (p.roots.toFinset.filter (fun x => a < x ∧ x ≀ b)).card
Name
Formalizations.Reusable.sturm_signVariations_sub_eq_card_roots
Import
import Formalizations.Reusable.Polynomial
Version
formalizations 0.15.0Lean v4.35.0Mathlib f0b4c81
Role
API a lemma to import and build other proofs on
Provenance
Sturm.sturm, Sturm.sturmSeq_eq, Sturm.signVarAt_eq_signVariations in Formalizations.Analysis.Polynomial.RealRoots.Sturm
Paper: none
Classical reference
C. Sturm (1829); S. Basu, R. Pollack, M.-F. Roy, Algorithms in Real Algebraic Geometry, ch. 2
Trust
standard axioms only propext, Classical.choice, Quot.sound
#print axioms in FormalizationsTest/Axioms.lean, audited by scripts/check_axioms.sh (2758 results), which the CI build workflow runs and passed at this commit.
Status
reusable upstream candidate
Area
Polynomial

Links

Lean docstring

Sturm's theorem. For a squarefree real polynomial p and a < b with p a β‰  0 and p b β‰  0, the number of sign variations of Mathlib's Sturm chain Polynomial.sturmSeq p (derivative p) evaluated at a, minus the number at b, is the number of distinct real roots of p in (a, b]. Sign variations are Mathlib's List.signVariations (zeros are skipped).

  • Archive: Sturm.sturm (Formalizations.Analysis.Polynomial.RealRoots.Sturm), restated with Mathlib's chain and counter through the archive bridges Sturm.sturmSeq_eq and Sturm.signVarAt_eq_signVariations. Mathlib's Polynomial.sturmSeq contains only the algebraic properties of the chain; this is the theorem it is defined for.
  • Classical reference: C. Sturm (1829); S. Basu, R. Pollack, M.-F. Roy, Algorithms in Real Algebraic Geometry, ch. 2.
  • Example: for p = XΒ² βˆ’ 2 on [0, 2], the theorem counts the single root √2.

Upstream

the theorem Mathlib's Polynomial.sturmSeq is defined for (its docstring: only the algebraic properties); its authors may be writing it, so check before any PR

Depends on, in this repository

None besides the archive module (repo_dependencies = []).