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.LinearAlgebraIn a file of the project, e.g.
Example.lean.Paste the example
open Formalizations.Reusable Matrix open scoped Kronecker open PowerSeries in open scoped PowerSeries in /-- A symmetric matrix with alternating characteristic polynomial is PSD (passes the hypothesis on). -/ example (A : Matrix (Fin 2) (Fin 2) โ) (hA : A.IsSymm) (h : โ k โค A.charpoly.natDegree, 0 โค (-1 : โ) ^ (A.charpoly.natDegree - k) * A.charpoly.coeff k) : A.PosSemidef := posSemidef_of_charpoly_alternating hA hSteps 3 and 4 together are a complete Lean file:
FormalizationsTest/ReusableLinearAlgebraExample.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).
A real symmetric matrix whose characteristic polynomial has coefficients alternating in sign is positive semidefinite (the polynomial rule is a corollary of Descartes' rule of signs).
Lean statement
theorem posSemidef_of_charpoly_alternating {V : Type*} [Fintype V] [DecidableEq V]
{A : Matrix V V โ} (hA : A.IsSymm)
(halt : โ k โค A.charpoly.natDegree,
0 โค (-1 : โ) ^ (A.charpoly.natDegree - k) * A.charpoly.coeff k) :
A.PosSemidefLinks
- This theorem in
Formalizations/Reusable/LinearAlgebra.lean(lines 187โ203 at v0.15.0) - Archive theorem
AlternatingRoots.posSemidef_of_charpoly_alternating - Archive theorem
AlternatingRoots.root_nonneg_of_alternating - The example in
FormalizationsTest/ReusableLinearAlgebraExample.lean - API documentation (doc-gen4)
Lean docstring
Alternating characteristic polynomial โ positive semidefinite. A real symmetric matrix whose characteristic polynomial has coefficients alternating in sign, (-1)^(n-k) ยท c_k โฅ 0, is positive semidefinite. The polynomial rule behind it (alternating coefficients โ no negative root) is a corollary of Descartes' rule of signs in Mathlib (Polynomial.roots_countP_pos_le_signVariations).
- Archive:
AlternatingRoots.posSemidef_of_charpoly_alternating(Formalizations.Analysis.Polynomial.RealRoots.AlternatingRoots); a piece of the design table (artefact P006, SOS certificates); the module cites no paper DOI of ours. - Classical reference: textbook (spectral theorem; Descartes' rule of signs).
- Example: an exact PSD check of a rational Gram matrix without pivoting: compute its characteristic polynomial and read the signs.
Upstream
Mathlib has the rule of signs and posSemidef_iff_eigenvalues_nonneg but not the charpoly criterion
Depends on, in this repository
None besides the archive module (repo_dependencies = []).