Use this theorem
Create a project
lake +leanprover/lean4:v4.35.0 new myproject std.toml cd myprojectStandard template, not
math: themathtemplate 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.Add the dependency to
lakefile.toml[[require]] name = "formalizations" git = "https://github.com/karlesmarin/formalizations" rev = "v0.15.0"Import the minimal module
import Formalizations.Reusable.PolynomialIn a file of the project, e.g.
Example.lean.Paste the example
open Formalizations.Reusable Polynomial /-- Budan–Fourier: if the derivative tower loses exactly one sign variation from `a` to `b`, then `p` has a root in `(a, b]` (the parity forbids zero roots). -/ example (p : Polynomial ℝ) (hp : p ≠ 0) {a b : ℝ} (hab : a < b) (ha : p.eval a ≠ 0) (hb : p.eval b ≠ 0) (h1 : ((List.range (p.natDegree + 1)).map (fun k => ((derivative^[k]) p).eval a)).signVariations - ((List.range (p.natDegree + 1)).map (fun k => ((derivative^[k]) p).eval b)).signVariations = 1) : ∃ x ∈ Set.Ioc a b, p.IsRoot x := by obtain ⟨-, hev⟩ := budan_fourier_card_roots_le p hp hab ha hb rw [h1] at hev have hne : (p.roots.filter (fun x => a < x ∧ x ≤ b)).card ≠ 0 := by intro h0 rw [h0] at hev simp at hev obtain ⟨x, hx⟩ := Multiset.card_pos_iff_exists_mem.1 (Nat.pos_of_ne_zero hne) rw [Multiset.mem_filter] at hx exact ⟨x, ⟨hx.2.1, hx.2.2⟩, (mem_roots hp).1 hx.1⟩Steps 3 and 4 together are a complete Lean file:
FormalizationsTest/ReusablePolynomialExample.leanat v0.15.0, compiled by the CI.Fetch and check
lake update lake lean Example.leanlake updatefetches this package and Mathlib, and Mathlib's update hook downloads the compiled Mathlib (lake exe cache get).lake lean Example.leanbuilds the imports of the file (steps 3 and 4) and checks it. If the file belongs to alean_libof your project,lake build <lib>does the same. Avoid a barelake buildin 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: Leanv4.35.0, Mathlibf0b4c81.
Alternative: import Formalizations.Reusable imports the whole layer (all areas).
The Budan–Fourier theorem: for nonzero p ∈ ℝ[X] and a < b with p(a), p(b) ≠ 0, the number of roots of p in (a, b] counted with multiplicity is at most V(a) − V(b), with even difference, where V(x) is the number of sign variations of p, p′, …, p^(deg p) at x.
Lean statement
theorem budan_fourier_card_roots_le (p : Polynomial ℝ) (hp : p ≠ 0) {a b : ℝ} (hab : a < b)
(ha : p.eval a ≠ 0) (hb : p.eval b ≠ 0) :
(p.roots.filter (fun x => a < x ∧ x ≤ b)).card ≤
((List.range (p.natDegree + 1)).map (fun k => ((derivative^[k]) p).eval a)).signVariations -
((List.range (p.natDegree + 1)).map (fun k => ((derivative^[k]) p).eval b)).signVariations ∧
Even (((List.range (p.natDegree + 1)).map
(fun k => ((derivative^[k]) p).eval a)).signVariations -
((List.range (p.natDegree + 1)).map (fun k => ((derivative^[k]) p).eval b)).signVariations -
(p.roots.filter (fun x => a < x ∧ x ≤ b)).card)Links
- This theorem in
Formalizations/Reusable/Polynomial.lean(lines 138–167 at v0.15.0) - Archive theorem
BudanFourier.budan_fourier - Archive theorem
BudanFourier.fourierVar_eq_signVarAt - Archive theorem
Sturm.signVarAt_eq_signVariations - The example in
FormalizationsTest/ReusablePolynomialExample.lean - API documentation (doc-gen4)
Lean docstring
The Budan–Fourier theorem. For a nonzero real polynomial p and a < b with p a ≠ 0 and p b ≠ 0, let V x be the number of sign variations (Mathlib's List.signVariations, zeros skipped) of the derivative tower p, p', p'', …, p^{(deg p)} evaluated at x. Then the number of real roots of p in (a, b], counted with multiplicity, is at most V a − V b, and the difference is even. Descartes' rule of signs is the case (0, ∞).
- Archive:
BudanFourier.budan_fourier(Formalizations.Analysis.Polynomial.RealRoots.BudanFourier), restated withList.signVariationsthrough the archive bridgesBudanFourier.fourierVar_eq_signVarAtandSturm.signVarAt_eq_signVariations. - Classical reference: F. D. Budan (1807), J. Fourier (1820); S. Basu, R. Pollack, M.-F. Roy, Algorithms in Real Algebraic Geometry, ch. 2.
- Example: for
p = X² − 1on(0, 2], the theorem bounds the number of roots (one, at1) by the drop of sign variations of(X² − 1, 2X, 2)from0to2, which is1.
Upstream
Mathlib has Descartes' rule of signs (roots_countP_pos_le_signVariations) and List.signVariations, not Budan–Fourier
Depends on, in this repository
Formalizations.Analysis.Polynomial.RealRoots.Sturm