Documentation

CslibFrontier.Algorithms.Matching.MVV

Isolating weights and the Mulmuley–Vazirani–Vazirani matching algorithm #

The algebraic and probabilistic core of the parallel matching algorithm of Mulmuley, Vazirani and Vazirani [MVV87] Motwani and Raghavan, Section 12.4, for a bipartite graph G : V × V → Bool. Give each edge (i, j) a weight w (i, j) and let B be the Edmonds matrix at the values 2 ^ w (i, j) (Cslib.Algorithms.Matching.weightedEdmonds G w, a matrix over ℤ). Each perfect matching σ contributes ± 2 ^ (weight of σ) to det B. When the minimum-weight perfect matching σ₀ is unique, of weight W, every other term is divisible by 2 ^ (W + 1), so

MVV state these lemmas for the Tutte matrix of a general graph, where the power is 2 ^ (2 W); the statements here are their bipartite (Edmonds-matrix) form. The procedure Cslib.Algorithms.Matching.mvvOutput G w computes W from det B and outputs the pairs (i, j) passing the divisibility test; on isolating weights it outputs exactly σ₀ (Cslib.Algorithms.Matching.mvvOutput_iff_apply_eq).

The isolation lemma makes the minimum unique with probability at least 1 / 2 when the edge weights are independent and uniform on {1, …, N} with N ≥ 2 |E| (Cslib.Algorithms.Matching.half_le_dens_exists_isUniqueMinMatching, from Cslib.Probability.half_le_dens_minWeightSets_card_eq_one). Together, the procedure returns a perfect matching of G with probability at least 1 / 2 (Cslib.Algorithms.Matching.half_le_dens_mvv). Probabilities are proportions of the weight functions, as in the isolation lemma. The parallel (NC) computation of the determinant and the adjugate is not formalized.

Main definitions #

Main results #

References #

Signed sums of powers of two with a unique smallest exponent #

The weighted Edmonds matrix #

def Cslib.Algorithms.Matching.weightedEdmonds {V : Type u_1} (G : V × V → Bool) (w : V × V → ℕ) :

The Edmonds matrix at the powers of two 2 ^ w (i, j).

theorem Cslib.Algorithms.Matching.weightedEdmonds_apply {V : Type u_1} (G : V × V → Bool) (w : V × V → ℕ) (i j : V) :
weightedEdmonds G w i j = if G (i, j) = true then 2 ^ w (i, j) else 0

An entry of the weighted Edmonds matrix.

def Cslib.Algorithms.Matching.matchingWeight {V : Type u_1} [Fintype V] (w : V × V → ℕ) (σ : Equiv.Perm V) :

The weight ∑ v, w (v, σ v) of the perfect matching σ.

theorem Cslib.Algorithms.Matching.matchingWeight_def {V : Type u_1} [Fintype V] (w : V × V → ℕ) (σ : Equiv.Perm V) :
matchingWeight w σ = ∑ v : V, w (v, σ v)

The weight of a perfect matching is the sum of the weights of its pairs.

The perfect matchings of G, as permutations.

theorem Cslib.Algorithms.Matching.mem_perfectMatchings {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {σ : Equiv.Perm V} :
σ ∈ perfectMatchings G ↔ ∀ (v : V), G (v, σ v) = true

Membership in perfectMatchings.

theorem Cslib.Algorithms.Matching.prod_weightedEdmonds {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) (σ : Equiv.Perm V) :
∏ v : V, weightedEdmonds G w v (σ v) = if σ ∈ perfectMatchings G then 2 ^ matchingWeight w σ else 0

The term of σ in the Leibniz expansion of the weighted Edmonds matrix: 2 to the weight of σ for a perfect matching, 0 otherwise.

theorem Cslib.Algorithms.Matching.det_weightedEdmonds {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) :

The determinant of the weighted Edmonds matrix as a signed sum over the perfect matchings.

theorem Cslib.Algorithms.Matching.mul_adjugate_weightedEdmonds {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) (i j : V) :
weightedEdmonds G w i j * (weightedEdmonds G w).adjugate j i = ∑ σ ∈ perfectMatchings G with σ i = j, ↑(Equiv.Perm.sign σ) * 2 ^ matchingWeight w σ

The entry B i j of the weighted Edmonds matrix times the cofactor adj(B) j i is the signed sum over the perfect matchings that match i to j.

Reading off a unique minimum-weight perfect matching #

def Cslib.Algorithms.Matching.IsUniqueMinMatching {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) (σ₀ : Equiv.Perm V) :

σ₀ is the unique minimum-weight perfect matching of the bipartite graph G under w.

Instances For
    theorem Cslib.Algorithms.Matching.isUniqueMinMatching_iff {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} :
    IsUniqueMinMatching G w σ₀ ↔ σ₀ ∈ perfectMatchings G ∧ ∀ σ ∈ perfectMatchings G, σ ≠ σ₀ → matchingWeight w σ₀ < matchingWeight w σ

    σ₀ is the unique minimum-weight perfect matching when it is a perfect matching and every other perfect matching is strictly heavier.

    @[instance_reducible]
    instance Cslib.Algorithms.Matching.instDecidableIsUniqueMinMatching {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) (σ₀ : Equiv.Perm V) :

    Being the unique minimum-weight perfect matching is decidable.

    theorem Cslib.Algorithms.Matching.two_pow_dvd_det_weightedEdmonds {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) :

    The weight of the isolated matching divides the determinant: if σ₀ is the unique minimum-weight perfect matching of the bipartite graph G, of weight W, then 2 ^ W divides the determinant of the weighted Edmonds matrix. With not_two_pow_succ_dvd_det_weightedEdmonds, this is the bipartite (Edmonds-matrix) form of the determinant lemma of [MVV87], which is stated for the Tutte matrix of a general graph, where the power is 2 ^ (2 W); see Motwani and Raghavan, Section 12.4.

    theorem Cslib.Algorithms.Matching.not_two_pow_succ_dvd_det_weightedEdmonds {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) :

    If σ₀ is the unique minimum-weight perfect matching of the bipartite graph G, of weight W, then 2 ^ (W + 1) does not divide the determinant of the weighted Edmonds matrix. So W is the exponent of the largest power of two dividing it (matchingWeight_eq_padicValInt_det).

    theorem Cslib.Algorithms.Matching.det_weightedEdmonds_ne_zero {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) :

    The determinant of the weighted Edmonds matrix is nonzero when the minimum-weight perfect matching is unique.

    theorem Cslib.Algorithms.Matching.two_pow_dvd_mul_adjugate_weightedEdmonds {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) (i j : V) :

    If σ₀ is the unique minimum-weight perfect matching of the bipartite graph G, of weight W, then 2 ^ W divides B i j * adj(B) j i for all i, j, where B is the weighted Edmonds matrix.

    theorem Cslib.Algorithms.Matching.apply_eq_iff_not_two_pow_succ_dvd_mul_adjugate {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) (i j : V) :
    σ₀ i = j ↔ ¬2 ^ (matchingWeight w σ₀ + 1) ∣ weightedEdmonds G w i j * (weightedEdmonds G w).adjugate j i

    Reading off the isolated matching: if σ₀ is the unique minimum-weight perfect matching of the bipartite graph G, of weight W, then σ₀ matches i to j exactly when 2 ^ (W + 1) does not divide B i j * adj(B) j i, where B is the weighted Edmonds matrix. This is the bipartite (Edmonds-matrix) form of the edge test of [MVV87], which is stated for the Tutte matrix of a general graph; see Motwani and Raghavan, Section 12.4.

    theorem Cslib.Algorithms.Matching.matchingWeight_eq_padicValInt_det {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) :

    The weight of the unique minimum-weight perfect matching is the exponent of the largest power of two dividing the determinant of the weighted Edmonds matrix.

    The output of the procedure #

    def Cslib.Algorithms.Matching.mvvOutput {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) (i j : V) :

    The output of the Mulmuley–Vazirani–Vazirani procedure on the bipartite graph G with weights w: with B the weighted Edmonds matrix and W the exponent of the largest power of two dividing det B, the pair (i, j) is output when 2 ^ (W + 1) does not divide B i j * adj(B) j i.

    Instances For
      theorem Cslib.Algorithms.Matching.mvvOutput_iff {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {i j : V} :

      The defining divisibility test of mvvOutput.

      @[instance_reducible]
      instance Cslib.Algorithms.Matching.instDecidableMvvOutput {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) (i j : V) :

      The output of the procedure is decidable, by an executable test. Mathlib's padicValInt is noncomputable, so the instance decides the same divisibility with the executable padicValNat, which Nat.padicValNat_def identifies with the multiplicity that padicValInt unfolds to.

      theorem Cslib.Algorithms.Matching.mvvOutput_iff_apply_eq {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) (i j : V) :
      mvvOutput G w i j ↔ σ₀ i = j

      The procedure is correct on isolating weights: if σ₀ is the unique minimum-weight perfect matching of the bipartite graph G under w, the procedure outputs exactly the pairs of σ₀.

      def Cslib.Algorithms.Matching.MVVSucceeds {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) :

      The procedure succeeds on the bipartite graph G with weights w: its output is a perfect matching of G.

      Instances For
        theorem Cslib.Algorithms.Matching.mvvSucceeds_iff {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} :
        MVVSucceeds G w ↔ ∃ σ ∈ perfectMatchings G, ∀ (i j : V), σ i = j ↔ mvvOutput G w i j

        The procedure succeeds when its output is the graph of a perfect matching.

        @[instance_reducible]
        instance Cslib.Algorithms.Matching.instDecidableMVVSucceeds {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) (w : V × V → ℕ) :

        Success of the procedure is decidable, by searching the permutations with the executable test for mvvOutput.

        theorem Cslib.Algorithms.Matching.mvvSucceeds_of_isUniqueMinMatching {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {w : V × V → ℕ} {σ₀ : Equiv.Perm V} (h : IsUniqueMinMatching G w σ₀) :

        The procedure succeeds whenever the minimum-weight perfect matching is unique.

        Isolating weights #

        @[reducible, inline]
        abbrev Cslib.Algorithms.Matching.Edges {V : Type u_1} (G : V × V → Bool) :
        Type u_1

        The edges of the bipartite graph G.

        The edges of the perfect matching σ.

        theorem Cslib.Algorithms.Matching.mem_matchingEdges {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {σ : Equiv.Perm V} {e : Edges G} :
        e ∈ matchingEdges G σ ↔ σ (↑e).1 = (↑e).2

        An edge (i, j) belongs to the matching σ when σ i = j.

        def Cslib.Algorithms.Matching.extendWeight {V : Type u_1} {G : V × V → Bool} {N : ℕ} (w : Edges G → Fin N) (e : V × V) :

        The weight x + 1 ∈ {1, …, N} on the edges of G, extended by 0 to all pairs.

        theorem Cslib.Algorithms.Matching.extendWeight_of_edge {V : Type u_1} {G : V × V → Bool} {N : ℕ} (w : Edges G → Fin N) {e : V × V} (h : G e = true) :
        extendWeight w e = ↑(w ⟨e, h⟩) + 1

        On an edge, the extended weight is the label plus one.

        theorem Cslib.Algorithms.Matching.extendWeight_of_not_edge {V : Type u_1} {G : V × V → Bool} {N : ℕ} (w : Edges G → Fin N) {e : V × V} (h : G e = false) :

        Off the edges, the extended weight is 0.

        Distinct perfect matchings have distinct edge sets.

        theorem Cslib.Algorithms.Matching.setWeight_matchingEdges {V : Type u_1} [Fintype V] [DecidableEq V] {G : V × V → Bool} {σ : Equiv.Perm V} (hσ : σ ∈ perfectMatchings G) {N : ℕ} (w : Edges G → Fin N) :
        Probability.setWeight (fun (x : Fin N) => ↑x + 1) w (matchingEdges G σ) = matchingWeight (extendWeight w) σ

        The isolation-lemma weight of the edges of a perfect matching is its matching weight under the extended weights.

        The isolation lemma for bipartite perfect matchings [MVV87]: if the bipartite graph G has a perfect matching and its edges get independent uniform weights from {1, …, N} with N ≥ 2 |E|, then with probability at least 1 / 2 the minimum-weight perfect matching is unique.

        The Mulmuley–Vazirani–Vazirani algorithm for bipartite graphs, algebraic core [MVV87] Motwani and Raghavan, Section 12.4: if the bipartite graph G has a perfect matching and its edges get independent uniform weights w from {1, …, N} with N ≥ 2 |E|, then with probability at least 1 / 2 the procedure mvvOutput outputs a perfect matching of G.