Matrix-Tree Theorem

lean4-proofgraph-theoryvisualization
τ(G)=det(L(ii))\tau(G) = \det(L^{(ii)})

Statement

Let GG be a finite connected graph on nn vertices with Laplacian matrix L=DAL = D - A (where DD is the degree matrix and AA the adjacency matrix). Then the number of spanning trees τ(G)\tau(G) equals any cofactor of LL:

τ(G)=det(L(ii))\tau(G) = \det(L^{(ii)})

where L(ii)L^{(ii)} is the matrix obtained by deleting row ii and column ii. The result is independent of which row/column is deleted.

Visualization

K3K_3 on vertices {1,2,3}\{1, 2, 3\}: every vertex has degree 2.

L=DA=(211121112)L = D - A = \begin{pmatrix} 2 & -1 & -1 \\ -1 & 2 & -1 \\ -1 & -1 & 2 \end{pmatrix}

Delete row 3 and column 3 to get L(33)L^{(33)}:

L(33)=(2112)L^{(33)} = \begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}
det(L(33))=(2)(2)(1)(1)=41=3\det(L^{(33)}) = (2)(2) - (-1)(-1) = 4 - 1 = 3

The spanning trees of K3K_3: there are exactly 3, one for each omitted edge.

Tree 1: 1─2, 1─3   (omit edge 2─3)
Tree 2: 1─2, 2─3   (omit edge 1─3)
Tree 3: 1─3, 2─3   (omit edge 1─2)

τ(K3)=3=det(L(33))\tau(K_3) = 3 = \det(L^{(33)}) — confirmed.

By <a class="concept-link" data-concept="Cayley's Formula (nn2n^{n-2} trees)">Cayley's Formula (nn2n^{n-2} trees), τ(Kn)=nn2\tau(K_n) = n^{n-2}, so det(LKn(ii))=nn2\det(L_{K_n}^{(ii)}) = n^{n-2}. For n=3n=3: 31=33^1 = 3. For n=4n=4: 42=164^2 = 16.

Graphnnτ\taudet(L(11))\det(L^{(11)})
K2K_2211
K3K_3333
K4K_441616

Proof Sketch

  1. Laplacian: Lij=deg(i)L_{ij} = \deg(i) if i=ji=j, 1-1 if {i,j}E\{i,j\} \in E, 00 otherwise. Note L1=0L\mathbf{1} = 0.
  2. Matrix-tree identity: Expand det(L(ii))\det(L^{(ii)}) via the Cauchy–Binet formula applied to the signed incidence matrix BB of GG. The identity L=BBTL = BB^T (for any oriented incidence matrix BB) reduces the cofactor to a sum over spanning trees.
  3. Spanning tree terms: By the Cauchy–Binet formula, det(L(ii))=T spanning tree(detBT)2\det(L^{(ii)}) = \sum_{T \text{ spanning tree}} (\det B_T)^2 where BTB_T is the submatrix of BB with columns indexed by TT's edges. Each detBT=±1\det B_T = \pm 1, so the sum equals τ(G)\tau(G).
  4. Independence: Symmetry of the argument in ii shows the cofactor is the same for all ii.

Connections

The Matrix-Tree Theorem is the algebraic proof of <a class="concept-link" data-concept="Cayley's Formula (nn2n^{n-2} trees)">Cayley's Formula (nn2n^{n-2} trees) and a flagship application of the Determinant MultiplicativityDeterminant Multiplicativitydet(AB)=det(A)det(B)\det(AB) = \det(A)\,\det(B)The determinant of a product equals the product of determinantsRead more → identity (Cauchy–Binet). The Laplacian LL also features in Rank–Nullity TheoremRank–Nullity Theoremrank(f)+nullity(f)=dimV\operatorname{rank}(f) + \operatorname{nullity}(f) = \dim VThe dimensions of image and kernel of a linear map sum to the domain dimensionRead more →: kerL\ker L has dimension equal to the number of connected components, proved via card_connectedComponent_eq_finrank_ker\text{card\_connectedComponent\_eq\_finrank\_ker} in Mathlib. The spectral properties of LL (eigenvalues, Spectral TheoremSpectral TheoremA=QΛQT  (real symmetric case)A = Q \Lambda Q^T \;\text{(real symmetric case)}Every real symmetric matrix is orthogonally diagonalizableRead more →) underlie the algebraic connectivity (Fiedler value) used in graph partitioning.

Lean4 Proof

import Mathlib.Combinatorics.SimpleGraph.LapMatrix
import Mathlib.Data.Matrix.Basic

-- Mathlib provides SimpleGraph.lapMatrix.
-- The full matrix-tree theorem is not yet in Mathlib v4.28.0;
-- we verify the K₃ cofactor directly.

-- The 2×2 submatrix of L(K₃) after deleting row/col 3:
def L33 : Matrix (Fin 2) (Fin 2)  :=
  !![2, -1; -1, 2]

theorem K3_spanning_trees : L33.det = 3 := by decide