Documentation

CslibFrontier.Computability.Circuit.BipartiteMatching

Bipartite perfect matching #

A bipartite graph with n left and n right vertices is a subgraph of the complete bipartite graph K_{n,n}, given by the indicator of its edges, one bit for each pair (i, j) of a left vertex i and a right vertex j (Cslib.Circuits.BipartiteMatching.graph, numbering the pairs by finProdFinEquiv), which contains a set of edges when it has each of them (BipartiteMatching.Contains). A set of edges is a matching when no two of them share an endpoint (BipartiteMatching.IsMatching). A graph has a perfect matching when some bijection σ from the left to the right vertices uses only edges, (i, σ i) for every i (BipartiteMatching.HasPerfectMatching). The bipartite perfect matching function Cslib.Circuits.bipartitePerfectMatching n of the n * n possible edges says whether the graph has a perfect matching. It is monotone (monotone_bipartitePerfectMatching): adding edges keeps a perfect matching.

Relabelling the left and the right vertices along bijections preserves perfect matchings (BipartiteMatching.hasPerfectMatching_comp_iff). A graph has no perfect matching when a set of left vertices has fewer neighbours (BipartiteMatching.not_hasPerfectMatching_of_card_lt), the easy direction of Hall's theorem; Hall's theorem itself, from Mathlib's Finset.all_card_le_biUnion_card_iff_existsInjective', says that a perfect matching exists exactly when every set of left vertices has at least as many neighbours (BipartiteMatching.hasPerfectMatching_iff_forall_card_le).

Main definitions #

Main results #

References #

A bipartite graph whose left and right vertices are both indexed by V, given by the indicator of its edges (left, right), has a perfect matching: a bijection σ from the left to the right vertices with (v, σ v) an edge for every v.

Instances For
    @[instance_reducible]

    Whether a bipartite graph on a finite vertex type has a perfect matching is decidable.

    theorem Cslib.Circuits.BipartiteMatching.hasPerfectMatching_comp_iff {V : Type u_1} {W : Type u_2} (hL hR : W ≃ V) (G : V × V → Bool) :
    (HasPerfectMatching fun (e : W × W) => G (hL e.1, hR e.2)) ↔ HasPerfectMatching G

    Relabelling the left vertices along hL and the right vertices along hR preserves perfect matchings.

    theorem Cslib.Circuits.BipartiteMatching.not_hasPerfectMatching_of_card_lt {V : Type u_1} {G : V × V → Bool} {S T : Finset V} (hST : ∀ v ∈ S, ∀ (w : V), G (v, w) = true → w ∈ T) (hcard : T.card < S.card) :

    Hall's condition is necessary: if the edges from a set S of left vertices all end in a set T of fewer right vertices, the graph has no perfect matching.

    theorem Cslib.Circuits.BipartiteMatching.hasPerfectMatching_iff_forall_card_le {V : Type u_1} [Fintype V] [DecidableEq V] (G : V × V → Bool) :
    HasPerfectMatching G ↔ ∀ (S : Finset V), S.card ≤ (S.biUnion fun (v : V) => {w : V | G (v, w) = true}).card

    Hall's theorem for bipartite graphs on V × V: a perfect matching exists exactly when every set of left vertices has at least as many neighbours.

    Adding edges keeps a perfect matching.

    def Cslib.Circuits.BipartiteMatching.IsMatching {V : Type u_1} {W : Type u_2} (E : Finset (V × W)) :

    A set of edges of a bipartite graph is a matching when two of its edges sharing an endpoint are equal.

    Instances For
      @[instance_reducible]

      Whether a set of edges is a matching is decidable.

      theorem Cslib.Circuits.BipartiteMatching.IsMatching.mono {V : Type u_1} {W : Type u_2} {E F : Finset (V × W)} (hE : IsMatching E) (hFE : F ⊆ E) :

      A subset of a matching is a matching.

      theorem Cslib.Circuits.BipartiteMatching.IsMatching.insert {V : Type u_1} {W : Type u_2} [DecidableEq V] [DecidableEq W] {E : Finset (V × W)} (hE : IsMatching E) {e : V × W} (h₁ : ∀ e' ∈ E, e'.1 ≠ e.1) (h₂ : ∀ e' ∈ E, e'.2 ≠ e.2) :

      Adding to a matching an edge whose endpoints are both unmatched gives a matching.

      A single edge is a matching.

      The bipartite graph of an input: the left vertex i and the right vertex j are adjacent when the bit numbered finProdFinEquiv (i, j) is one.

      The input x contains all edges of E.

      Instances For
        @[instance_reducible]

        Whether an input contains all edges of a set is decidable.

        theorem Cslib.Circuits.BipartiteMatching.Contains.mono {n : ℕ} {x : BitString (n * n)} {E F : Finset (Fin n × Fin n)} (h : Contains x E) (hFE : F ⊆ E) :

        An input containing all edges of a set contains all edges of its subsets.

        The bipartite perfect matching function of the n * n possible edges of the complete bipartite graph K_{n,n}: whether the graph of the input (BipartiteMatching.graph) has a perfect matching.

        The bipartite perfect matching function is true exactly on graphs with a perfect matching.

        The bipartite perfect matching function is monotone: adding edges keeps a perfect matching.