The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V30. Combinatorics

Mathlib.Combinatorics.SimpleGraph.Matching

56 declarations. Mathlib docs · Source

Matchings

A matching for a simple graph is a set of disjoint pairs of adjacent vertices, and the set of all the vertices in a matching is called its support (and sometimes the vertices in the support are said to be saturated by the matching). A perfect matching is a matching whose support contains every vertex of the graph.

In this module, we represent a matching as a subgraph whose vertices are each incident to at most one edge, and the edges of the subgraph represent the paired vertices.

Main definitions

  • SimpleGraph.Subgraph.IsMatching: M.IsMatching means that M is a matching of its underlying graph.

  • SimpleGraph.Subgraph.IsPerfectMatching defines when a subgraph M of a simple graph is a perfect matching, denoted M.IsPerfectMatching.

  • SimpleGraph.IsMatchingFree means that a graph G has no perfect matchings.

  • SimpleGraph.IsCycles means that a graph consists of cycles (including cycles of length 0, also known as isolated vertices)

  • SimpleGraph.IsAlternating means that edges in a graph G are alternatingly included and not included in some other graph G'

TODO

  • Define an other function and prove useful results about it (https://leanprover.zulipchat.com/#narrow/stream/252551-graph-theory/topic/matchings/near/266205863)

  • Provide a bicoloring for matchings (https://leanprover.zulipchat.com/#narrow/stream/252551-graph-theory/topic/matchings/near/265495120)

  • Tutte's Theorem

theorem SimpleGraph.Subgraph.IsMatching.toEdge.congr_simp E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} (h : M.IsMatching) (v v_1 : ↑M.verts),
  v = v_1 → h.toEdge v = h.toEdge v_1

def SimpleGraph.Subgraph.IsMatching E3 #

{V : Type u_1} → {G : SimpleGraph V} → G.Subgraph → Prop

The subgraph M of G is a matching if every vertex of M is incident to exactly one edge in M. We say that the vertices in M.support are matched or saturated.

def SimpleGraph.Subgraph.IsMatching.toEdge E1 #

{V : Type u_1} → {G : SimpleGraph V} → {M : G.Subgraph} → M.IsMatching → ↑M.verts → ↑M.edgeSet

Given a vertex, returns the unique edge of the matching it is incident to.

theorem SimpleGraph.Subgraph.IsMatching.toEdge_eq_of_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} {v w : V} (h : M.IsMatching) (hvw : M.Adj v w),
  h.toEdge ⟨v, ⋯⟩ = ⟨s(v, w), hvw⟩

theorem SimpleGraph.Subgraph.IsMatching.toEdge.surjective E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} (h : M.IsMatching), Function.Surjective h.toEdge

theorem SimpleGraph.Subgraph.IsMatching.toEdge_eq_toEdge_of_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} {v w : V} (h : M.IsMatching) (ha : M.Adj v w),
  h.toEdge ⟨v, ⋯⟩ = h.toEdge ⟨w, ⋯⟩

theorem SimpleGraph.Subgraph.IsMatching.mem_coe_toEdge E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} (h : M.IsMatching) {v : V} (hv : v ∈ M.verts),
  v ∈ ↑(h.toEdge ⟨v, hv⟩)

theorem SimpleGraph.Subgraph.IsMatching.toEdge_preimage_singleton E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} {u v : V} (h : M.IsMatching) (huv : M.Adj u v),
  h.toEdge ⁻¹' {⟨s(u, v), huv⟩} = {⟨u, ⋯⟩, ⟨v, ⋯⟩}

theorem SimpleGraph.Subgraph.IsMatching.map_ofLE E0 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {M : G.Subgraph},
  M.IsMatching → ∀ (hGG' : G ≤ G'), (SimpleGraph.Subgraph.map (SimpleGraph.Hom.ofLE hGG') M).IsMatching

theorem SimpleGraph.Subgraph.IsMatching.not_adj_left_of_ne E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} {u v w : V}, M.IsMatching → v ≠ w → M.Adj u v → ¬M.Adj u w

theorem SimpleGraph.Subgraph.IsMatching.not_adj_right_of_ne E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} {u v w : V}, M.IsMatching → u ≠ v → M.Adj u w → ¬M.Adj v w

theorem SimpleGraph.Subgraph.IsMatching.sup E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M M' : G.Subgraph},
  M.IsMatching → M'.IsMatching → Disjoint M.support M'.support → (M ⊔ M').IsMatching

theorem SimpleGraph.Subgraph.IsMatching.iSup E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {ι : Type u_3} {f : ι → G.Subgraph},
  (∀ (i : ι), (f i).IsMatching) → (Pairwise fun i j ↦ Disjoint (f i).support (f j).support) → (⨆ i, f i).IsMatching

theorem SimpleGraph.Subgraph.IsMatching.subgraphOfAdj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v w : V} (h : G.Adj v w), (G.subgraphOfAdj h).IsMatching

theorem SimpleGraph.Subgraph.IsMatching.coeSubgraph E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {G' : G.Subgraph} {M : G'.coe.Subgraph},
  M.IsMatching → (SimpleGraph.Subgraph.coeSubgraph M).IsMatching

theorem SimpleGraph.Subgraph.IsMatching.exists_of_disjoint_sets_of_equiv E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {s t : Set V},
  Disjoint s t → ∀ (f : ↑s ≃ ↑t), (∀ (v : ↑s), G.Adj ↑v ↑(f v)) → ∃ M, M.verts = s ∪ t ∧ M.IsMatching

theorem SimpleGraph.Subgraph.IsMatching.map E1 #

∀ {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {G' : SimpleGraph W} {M : G.Subgraph} (f : G →g G'),
  Function.Injective ⇑f → M.IsMatching → (SimpleGraph.Subgraph.map f M).IsMatching

theorem SimpleGraph.Subgraph.Iso.isMatching_map E0 #

∀ {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {G' : SimpleGraph W} {M : G.Subgraph} (f : G ≃g G'),
  (SimpleGraph.Subgraph.map f.toHom M).IsMatching ↔ M.IsMatching

theorem SimpleGraph.Subgraph.IsMatching.verts_eq_biUnion_edgeSet E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph}, M.IsMatching → M.verts = ⋃ e ∈ M.edgeSet, ↑e

theorem SimpleGraph.Subgraph.IsMatching.injOn_edgeSet E1 #

∀ {V : Type u_1} {G : SimpleGraph V},
  Set.InjOn SimpleGraph.Subgraph.edgeSet (Set.ofPred SimpleGraph.Subgraph.IsMatching)

theorem SimpleGraph.Subgraph.IsMatching.strictMonoOn_edgeSet E1 #

∀ {V : Type u_1} {G : SimpleGraph V},
  StrictMonoOn SimpleGraph.Subgraph.edgeSet (Set.ofPred SimpleGraph.Subgraph.IsMatching)

def SimpleGraph.Subgraph.IsPerfectMatching E3 #

{V : Type u_1} → {G : SimpleGraph V} → G.Subgraph → Prop

The subgraph M of G is a perfect matching on G if it's a matching and every vertex G is matched.

theorem SimpleGraph.Subgraph.IsMatching.support_eq_verts E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph}, M.IsMatching → M.support = M.verts

theorem SimpleGraph.Subgraph.isMatching_iff_forall_degree E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} [inst : (v : V) → Fintype ↑(M.neighborSet v)],
  M.IsMatching ↔ ∀ v ∈ M.verts, M.degree v = 1

theorem SimpleGraph.Subgraph.IsMatching.even_card E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} [inst : Fintype ↑M.verts],
  M.IsMatching → Even M.verts.toFinset.card

theorem SimpleGraph.Subgraph.isPerfectMatching_iff E0 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph}, M.IsPerfectMatching ↔ ∀ (v : V), ∃! w, M.Adj v w

theorem SimpleGraph.Subgraph.isPerfectMatching_iff_forall_degree E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} [inst : (v : V) → Fintype ↑(M.neighborSet v)],
  M.IsPerfectMatching ↔ ∀ (v : V), M.degree v = 1

theorem SimpleGraph.Subgraph.IsPerfectMatching.even_card E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} [inst : Fintype V], M.IsPerfectMatching → Even (Fintype.card V)

theorem SimpleGraph.Subgraph.IsMatching.induce_connectedComponent E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph},
  M.IsMatching → ∀ (c : G.ConnectedComponent), (M.induce (M.verts ∩ c.supp)).IsMatching

theorem SimpleGraph.Subgraph.IsPerfectMatching.induce_connectedComponent_isMatching E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph},
  M.IsPerfectMatching → ∀ (c : G.ConnectedComponent), (M.induce c.supp).IsMatching

theorem SimpleGraph.Subgraph.IsPerfectMatching.toSubgraph_iff E0 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {M : G.Subgraph} (h : M.spanningCoe ≤ G'),
  (SimpleGraph.toSubgraph M.spanningCoe h).IsPerfectMatching ↔ M.IsPerfectMatching

theorem SimpleGraph.IsClique.even_iff_exists_isMatching E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u : Set V},
  G.IsClique u → u.Finite → (Even u.ncard ↔ ∃ M, M.verts = u ∧ M.IsMatching)

theorem SimpleGraph.ConnectedComponent.even_card_of_isPerfectMatching E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} [inst : Fintype V] [inst_1 : DecidableEq V]
  [inst_2 : DecidableRel G.Adj] (c : G.ConnectedComponent), M.IsPerfectMatching → Even (Fintype.card ↑c.supp)

theorem SimpleGraph.ConnectedComponent.odd_matches_node_outside E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {M : G.Subgraph} [Finite V] {u : Set V},
  M.IsPerfectMatching → ∀ (c : ↑(⊤.deleteVerts u).coe.oddComponents), ∃ w ∈ u, ∃ v, M.Adj (↑v) w ∧ v ∈ (↑c).supp

def SimpleGraph.IsMatchingFree E3 #

{V : Type u_1} → SimpleGraph V → Prop

A graph is matching free if it has no perfect matching. It does not make much sense to consider a graph being free of just matchings, because any non-trivial graph has those.

theorem SimpleGraph.IsMatchingFree.mono E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V}, G ≤ G' → G'.IsMatchingFree → G.IsMatchingFree

theorem SimpleGraph.exists_maximal_isMatchingFree E1 #

∀ {V : Type u_1} {G : SimpleGraph V} [Finite V],
  G.IsMatchingFree → ∃ Gmax, G ≤ Gmax ∧ Gmax.IsMatchingFree ∧ ∀ G' > Gmax, ∃ M, M.IsPerfectMatching

def SimpleGraph.IsCycles E3 #

{V : Type u_1} → SimpleGraph V → Prop

A graph G consists of a set of cycles, if each vertex is either isolated or connected to exactly two vertices. This is used to create new matchings by taking the symmDiff with cycles. The definition of symmDiff that makes sense is the one for SimpleGraph. The symmDiff for SimpleGraph.Subgraph deriving from the lattice structure also affects the vertices included, which we do not want in this case. This is why this property is defined for SimpleGraph, rather than SimpleGraph.Subgraph.

theorem SimpleGraph.IsCycles.other_adj_of_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v w : V}, G.IsCycles → G.Adj v w → ∃ w', w ≠ w' ∧ G.Adj v w'

Given a vertex with one edge in a graph of cycles this gives the other edge incident to the same vertex.

theorem SimpleGraph.IsCycles.existsUnique_ne_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v w : V}, G.IsCycles → G.Adj v w → ∃! w', w ≠ w' ∧ G.Adj v w'

theorem SimpleGraph.IsCycles.toSimpleGraph E1 #

∀ {V : Type u_1} {G : SimpleGraph V} (c : G.ConnectedComponent), G.IsCycles → c.toSimpleGraph.spanningCoe.IsCycles

theorem SimpleGraph.Walk.IsCycle.isCycles_spanningCoe_toSubgraph E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u : V} {p : G.Walk u u}, p.IsCycle → p.toSubgraph.spanningCoe.IsCycles

theorem SimpleGraph.Walk.IsPath.isCycles_spanningCoe_toSubgraph_sup_edge E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {u v : V} {p : G.Walk u v},
  p.IsPath → u ≠ v → s(v, u) ∉ p.edges → (p.toSubgraph.spanningCoe ⊔ SimpleGraph.edge v u).IsCycles

theorem SimpleGraph.Walk.IsCycle.adj_toSubgraph_iff_of_isCycles E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v : V} [G.LocallyFinite] {u : V} {p : G.Walk u u},
  p.IsCycle → G.IsCycles → v ∈ p.toSubgraph.verts → ∀ (w : V), p.toSubgraph.Adj v w ↔ G.Adj v w

theorem SimpleGraph.Subgraph.IsPerfectMatching.symmDiff_isCycles E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {M : G.Subgraph} {M' : G'.Subgraph},
  M.IsPerfectMatching → M'.IsPerfectMatching → (symmDiff M.spanningCoe M'.spanningCoe).IsCycles

theorem SimpleGraph.IsCycles.snd_of_mem_support_of_isPath_of_adj E1 #

∀ {V : Type u_1} {G : SimpleGraph V} [Finite V] {v w w' : V},
  G.IsCycles → ∀ (p : G.Walk v w), w ≠ w' → w' ∈ p.support → p.IsPath → G.Adj v w' → p.snd = w'

theorem SimpleGraph.IsCycles.reachable_sdiff_toSubgraph_spanningCoe E1 #

∀ {V : Type u_1} {G : SimpleGraph V} [Finite V] {v w : V},
  G.IsCycles → ∀ (p : G.Walk v w), p.IsPath → (G \ p.toSubgraph.spanningCoe).Reachable w v

theorem SimpleGraph.IsCycles.reachable_deleteEdges E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v w : V} [Finite V],
  G.Adj v w → G.IsCycles → (G.deleteEdges {s(v, w)}).Reachable v w

theorem SimpleGraph.IsCycles.exists_cycle_toSubgraph_verts_eq_connectedComponentSupp E1 #

∀ {V : Type u_1} {G : SimpleGraph V} {v : V} [Finite V] {c : G.ConnectedComponent},
  G.IsCycles → v ∈ c.supp → (G.neighborSet v).Nonempty → ∃ p, p.IsCycle ∧ p.toSubgraph.verts = c.supp

def SimpleGraph.IsAlternating E3 #

{V : Type u_1} → SimpleGraph V → SimpleGraph V → Prop

A graph G is alternating with respect to some other graph G', if exactly every other edge in G is in G'. Note that the degree of each vertex needs to be at most 2 for this to be possible. This property is used to create new matchings using symmDiff. The definition of symmDiff that makes sense is the one for SimpleGraph. The symmDiff for SimpleGraph.Subgraph deriving from the lattice structure also affects the vertices included, which we do not want in this case. This is why this property, just like IsCycles, is defined for SimpleGraph rather than SimpleGraph.Subgraph.

theorem SimpleGraph.IsAlternating.mono E1 #

∀ {V : Type u_1} {G G' G'' : SimpleGraph V}, G.IsAlternating G' → G'' ≤ G → G''.IsAlternating G'

theorem SimpleGraph.IsAlternating.spanningCoe E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V}, G.IsAlternating G' → ∀ (H : G.Subgraph), H.spanningCoe.IsAlternating G'

theorem SimpleGraph.IsAlternating.sup_edge E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {u x : V},
  G.IsAlternating G' →
    ¬G'.Adj u x →
      (∀ (u' : V), u' ≠ u → G.Adj x u' → G'.Adj x u') →
        (∀ (x' : V), x' ≠ x → G.Adj x' u → G'.Adj x' u) → (G ⊔ SimpleGraph.edge u x).IsAlternating G'

theorem SimpleGraph.Subgraph.IsPerfectMatching.symmDiff_of_isAlternating E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {M : G.Subgraph},
  M.IsPerfectMatching → G'.IsAlternating M.spanningCoe → G'.IsCycles → ⊤.IsPerfectMatching

theorem SimpleGraph.Subgraph.IsPerfectMatching.isAlternating_symmDiff_left E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {M : G.Subgraph} {M' : G'.Subgraph},
  M.IsPerfectMatching → M'.IsPerfectMatching → (symmDiff M.spanningCoe M'.spanningCoe).IsAlternating M.spanningCoe

theorem SimpleGraph.Subgraph.IsPerfectMatching.isAlternating_symmDiff_right E1 #

∀ {V : Type u_1} {G G' : SimpleGraph V} {M : G.Subgraph} {M' : G'.Subgraph},
  M.IsPerfectMatching → M'.IsPerfectMatching → (symmDiff M.spanningCoe M'.spanningCoe).IsAlternating M'.spanningCoe