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.16.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 /-- R0084: `virtualRoots_count_le_derivative_add_one` gives the upper side for the same polynomial; together the two cards differ by at most one. -/ example (x : โ) : ((VirtualRoots.vroots (-2) 2 (Polynomial.X ^ 2 - 1 : Polynomial โ) : Multiset โ).filter (fun r => x < r)).card โค ((VirtualRoots.vroots (-2) 2 (Polynomial.derivative (Polynomial.X ^ 2 - 1 : Polynomial โ)) : Multiset โ).filter (fun r => x < r)).card + 1 := virtualRoots_count_le_derivative_add_one (by norm_num) _ xSteps 3 and 4 together are a complete Lean file:
FormalizationsTest/ReusablePolynomialExample.leanat v0.16.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).
For lo โค hi and every real polynomial p, the number of virtual roots of p strictly above x is at most one plus the number of virtual roots of p' strictly above x.
Lean statement
theorem virtualRoots_count_le_derivative_add_one {lo hi : โ} (hab : lo โค hi)
(p : Polynomial โ) (x : โ) :
((VirtualRoots.vroots lo hi p : Multiset โ).filter (fun r => x < r)).card โค
((VirtualRoots.vroots lo hi (Polynomial.derivative p) : Multiset โ).filter
(fun r => x < r)).card + 1Links
Lean docstring
Virtual-root count, derivative upper bound. On lo โค hi, the number of virtual roots of p strictly above x exceeds the number for p' by at most one.
- Archive:
VirtualRoots.N_le_N_deriv_succ(Formalizations.Analysis.Polynomial.RealRoots.VirtualRoots.Count). - Classical reference: derivative interlacing; this virtual-root formulation is from the archive.
- Example: combine with
virtualRoots_derivative_count_leto bound a recursive count.
Upstream
Uses the archive's virtual-root list; Mathlib does not define that list.
Depends on, in this repository
Formalizations.Analysis.Polynomial.RealRoots.VirtualRoots.Basic