Documentation

CslibFrontier.Algorithms.Matching.Edmonds

The Edmonds matrix and the randomized perfect-matching test #

A bipartite graph G on left and right vertices both indexed by a finite type V has the Edmonds matrix Cslib.Algorithms.Matching.edmondsMatrix G: its entry (i, j) is the indeterminate X (i, j) when (i, j) is an edge and 0 otherwise. Its determinant, a polynomial in the variables V × V, is nonzero exactly when G has a perfect matching (Cslib.Algorithms.Matching.det_edmondsMatrix_ne_zero_iff), over every nontrivial commutative ring. In the Leibniz expansion every permutation σ gives the monomial ∏ v, X (v, σ v) when its pairs are all edges and 0 otherwise. Without a perfect matching every term vanishes. With one, σ, evaluating at the indicator of the pairs (v, σ v) turns the matrix into the permutation matrix of σ, of determinant sign σ ≠ 0. This is Edmonds' observation [Edm67b] that underlies Lovász's randomized matching algorithm [Lov79a] Motwani and Raghavan, Section 7.3.

The randomized test substitutes values r : V × V → R for the indeterminates (Cslib.Algorithms.Matching.edmondsEval G r) and checks whether the determinant is nonzero. Its error is one-sided. Without a perfect matching the determinant is always 0 (Cslib.Algorithms.Matching.det_edmondsEval_eq_zero). With one, over an integral domain and with the values drawn independently and uniformly from a finite set S, the determinant vanishes with probability at most |V| / |S| (Cslib.Algorithms.Matching.card_det_edmondsEval_eq_zero_div_le), by the Schwartz–Zippel lemma, since the determinant has total degree at most |V|.

Main definitions #

Main results #

References #

noncomputable def Cslib.Algorithms.Matching.edmondsMatrix {V : Type u_1} {R : Type u_2} [CommRing R] (G : V × V → Bool) :
Matrix V V (MvPolynomial (V × V) R)

The Edmonds matrix of a bipartite graph G on V × V: the indeterminate X (i, j) at each edge (i, j) and 0 elsewhere.

def Cslib.Algorithms.Matching.edmondsEval {V : Type u_1} {R : Type u_2} [CommRing R] (G : V × V → Bool) (r : V × V → R) :
Matrix V V R

The Edmonds matrix at the values r : V × V → R: r (i, j) at each edge (i, j) and 0 elsewhere.

theorem Cslib.Algorithms.Matching.edmondsEval_apply {V : Type u_1} {R : Type u_2} [CommRing R] (G : V × V → Bool) (r : V × V → R) (i j : V) :
edmondsEval G r i j = if G (i, j) = true then r (i, j) else 0

An entry of the Edmonds matrix at values.

theorem Cslib.Algorithms.Matching.map_eval_edmondsMatrix {V : Type u_1} {R : Type u_2} [CommRing R] (G : V × V → Bool) (r : V × V → R) :

Substituting values for the indeterminates of the Edmonds matrix.

theorem Cslib.Algorithms.Matching.totalDegree_edmondsMatrix_le {V : Type u_1} {R : Type u_2} [CommRing R] (G : V × V → Bool) (i j : V) :

An entry of the Edmonds matrix has total degree at most 1.

theorem Cslib.Algorithms.Matching.edmondsEval_indicator {V : Type u_1} {R : Type u_2} [CommRing R] [DecidableEq V] {G : V × V → Bool} {σ : Equiv.Perm V} (hσ : ∀ (v : V), G (v, σ v) = true) :
(edmondsEval G fun (e : V × V) => if σ e.1 = e.2 then 1 else 0) = Equiv.Perm.permMatrix R σ

Evaluating the Edmonds matrix at the indicator of the pairs (v, σ v) of a perfect matching σ gives the permutation matrix of σ.

theorem Cslib.Algorithms.Matching.det_edmondsEval {V : Type u_1} {R : Type u_2} [CommRing R] [DecidableEq V] [Fintype V] (G : V × V → Bool) (r : V × V → R) :

The determinant of the Edmonds matrix at values is the determinant polynomial evaluated at them.

Without a perfect matching, the determinant of the Edmonds matrix is the zero polynomial: every term of the Leibniz expansion has a factor 0.

No false positives: without a perfect matching, the Edmonds matrix has determinant 0 at all values.

With a perfect matching, the determinant of the Edmonds matrix is a nonzero polynomial.

Edmonds' criterion [Edm67b]: over a nontrivial commutative ring, the determinant of the Edmonds matrix of a bipartite graph is a nonzero polynomial exactly when the graph has a perfect matching.

The determinant of the Edmonds matrix has total degree at most |V|.

theorem Cslib.Algorithms.Matching.card_det_edmondsEval_eq_zero_div_le {V : Type u_1} {R : Type u_2} [CommRing R] [DecidableEq V] [Fintype V] [IsDomain R] [DecidableEq R] {G : V × V → Bool} (hG : Circuits.BipartiteMatching.HasPerfectMatching G) (S : Finset R) :
↑{r ∈ Fintype.piFinset fun (x : V × V) => S | (edmondsEval G r).det = 0}.card / ↑S.card ^ Fintype.card (V × V) ≤ ↑(Fintype.card V) / ↑S.card

The randomized perfect-matching test: for a bipartite graph with a perfect matching, over an integral domain, the Edmonds matrix at values drawn independently and uniformly from a finite set S is singular with probability at most |V| / |S|.

theorem Cslib.Algorithms.Matching.exists_det_edmondsEval_ne_zero {V : Type u_1} {R : Type u_2} [CommRing R] [DecidableEq V] [Fintype V] [IsDomain R] {G : V × V → Bool} (hG : Circuits.BipartiteMatching.HasPerfectMatching G) {S : Finset R} (hS : Fintype.card V < S.card) :
∃ (r : V × V → R), (∀ (e : V × V), r e ∈ S) ∧ (edmondsEval G r).det ≠ 0

Values from any set of more than |V| elements of an integral domain detect a perfect matching: some choice of them makes the Edmonds matrix nonsingular.