💎 Reusable layer
← all 82R0020

Kirchhoff's matrix-tree theorem

showcase

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.Combinatorics

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

  4. Paste the example

    Lean 4
    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.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).

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

Lean 4
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)
Name
Formalizations.Reusable.det_lapMatrix_submatrix_eq_card_spanningTrees
Import
import Formalizations.Reusable.Combinatorics
Version
formalizations 0.15.0Lean v4.35.0Mathlib f0b4c81
Role
showcase a classical theorem, to consult
Provenance
SimpleGraph.det_reducedLapMatrix_eq_card_spanningTrees in Formalizations.Combinatorics.SimpleGraph.MatrixTree.Kirchhoff
Paper: none
Classical reference
G. Kirchhoff, Ann. Phys. 148 (1847) 497–508; N. Biggs, Algebraic Graph Theory, 2nd ed. (1993), ch. 6
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
Combinatorics

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's reducedLapMatrix is (G.lapMatrix R).submatrix Subtype.val Subtype.val by definition. The module cites no paper DOI of ours. Mathlib's SimpleGraph/IncMatrix.lean lists 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) and v₀ = 0, the reduced Laplacian is !![2, -1; -1, 2] with determinant 3, 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