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.CombinatoricsIn a file of the project, e.g.
Example.lean.Paste the example
open Formalizations.Reusable Filter Topology Classical /-- Kirchhoff: the determinant of a reduced Laplacian over `ℤ` is nonnegative (it counts the spanning trees). -/ example {V : Type*} [Fintype V] [LinearOrder V] (G : SimpleGraph V) [DecidableRel G.Adj] (v₀ : V) : 0 ≤ ((G.lapMatrix ℤ).submatrix (Subtype.val : {v : V // v ≠ v₀} → V) Subtype.val).det := by rw [det_lapMatrix_submatrix_eq_card_spanningTrees ℤ G v₀] exact Int.natCast_nonneg _Steps 3 and 4 together are a complete Lean file:
FormalizationsTest/ReusableCombinatoricsExample.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).
Kirchhoff's matrix-tree theorem: over an integral domain, deleting the row and column of any vertex from the Laplacian (Mathlib's lapMatrix) of a finite simple graph leaves a matrix whose determinant is the number of spanning trees.
Lean statement
theorem det_lapMatrix_submatrix_eq_card_spanningTrees {V : Type*} (R : Type*) [CommRing R]
[IsDomain R] (G : SimpleGraph V) [Fintype V] [LinearOrder V] [DecidableRel G.Adj] (v₀ : V) :
((G.lapMatrix R).submatrix (Subtype.val : {v : V // v ≠ v₀} → V) Subtype.val).det
= ((Finset.univ.filter
(fun S : {s : Finset (Sym2 V) // s.card = Fintype.card {v : V // v ≠ v₀}} =>
↑S.1 ⊆ G.edgeSet ∧ (SimpleGraph.fromEdgeSet (↑S.1 : Set (Sym2 V))).IsTree)).card : R)Links
Lean docstring
Kirchhoff's matrix-tree theorem. Let G be a simple graph on a finite linearly ordered vertex type V, v₀ : V and R an integral domain. Deleting the row and the column of v₀ from Mathlib's Laplacian G.lapMatrix R leaves a matrix whose determinant is the number of spanning trees of G, counted as the sets of |V| − 1 edges of G whose spanning subgraph (SimpleGraph.fromEdgeSet) is a tree. The linear order on V only fixes the orientation used in the proof (oriented incidence matrix and Cauchy–Binet); any order gives the same count.
- Archive:
SimpleGraph.det_reducedLapMatrix_eq_card_spanningTrees(Formalizations.Combinatorics.SimpleGraph.MatrixTree.Kirchhoff, with the oriented incidence matrix and the Cauchy–Binet formula of the same archive); the archive'sreducedLapMatrixis(G.lapMatrix R).submatrix Subtype.val Subtype.valby definition. The module cites no paper DOI of ours. Mathlib'sSimpleGraph/IncMatrix.leanlists the oriented incidence matrix and the Laplacian as a TODO. - Classical reference: G. Kirchhoff, Ann. Phys. 148 (1847) 497–508; N. Biggs, Algebraic Graph Theory, 2nd ed. (1993), ch. 6.
- Example: for the complete graph on
Fin 3(a triangle) andv₀ = 0, the reduced Laplacian is!![2, -1; -1, 2]with determinant3, the three spanning trees of the triangle.
Upstream
answers the TODO in Mathlib/Combinatorics/SimpleGraph/IncMatrix.lean and the 1000+ list (Q2226691); Mathlib has not accepted this from anyone (#44234 closed); LeanPool is the realistic route
Depends on, in this repository
Formalizations.LinearAlgebra.Matrix.CauchyBinet, Formalizations.Combinatorics.SimpleGraph.OrientedIncMatrix, Formalizations.Combinatorics.SimpleGraph.MatrixTree.Basic, Formalizations.Combinatorics.SimpleGraph.MatrixTree.SpanningTreeMinor