Skip to content

Commit 0cdc26b

Browse files
pimotteYaelDillies
andcommitted
feat(Combinatorics/SimpleGraph): define odd components (#22125)
Adds the definition `oddComponents`: The set of connected components of odd cardinality. In preparation for Tutte's theorem. Co-authored-by: Pim Otte <otte.pim@gmail.com> Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>
1 parent b2814bd commit 0cdc26b

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

Mathlib/Combinatorics/SimpleGraph/Connectivity/WalkCounting.lean

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,26 @@ lemma disjiUnion_supp_toFinset_eq_supp_toFinset {G' : SimpleGraph V} (h : G ≤
234234

235235
end Fintype
236236

237-
lemma ConnectedComponent.odd_card_supp_iff_odd_subcomponents [Finite V] {G'}
237+
/-- The odd components are the connected components of odd cardinality. This definition excludes
238+
infinite components. -/
239+
abbrev oddComponents : Set G.ConnectedComponent := {c : G.ConnectedComponent | Odd c.supp.ncard}
240+
241+
lemma ConnectedComponent.odd_oddComponents_ncard_subset_supp [Finite V] {G'}
238242
(h : G ≤ G') (c' : ConnectedComponent G') :
239-
Odd c'.supp.ncard ↔
240-
Odd {c : ConnectedComponent G | c.supp ⊆ c'.supp ∧ Odd c.supp.ncard}.ncard := by
243+
Odd {c ∈ G.oddComponents | c.supp ⊆ c'.supp}.ncard ↔ Odd c'.supp.ncard := by
241244
simp_rw [← Set.Nat.card_coe_set_eq]
242245
classical
243246
cases nonempty_fintype V
244-
rw [Nat.card_eq_card_toFinset, ← disjiUnion_supp_toFinset_eq_supp_toFinset h]
245-
simp only [Finset.card_disjiUnion, Set.toFinset_card]
247+
rw [Nat.card_eq_card_toFinset c'.supp, ← disjiUnion_supp_toFinset_eq_supp_toFinset h]
248+
simp only [Finset.card_disjiUnion, Set.toFinset_card, Fintype.card_ofFinset]
246249
rw [Finset.odd_sum_iff_odd_card_odd, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
247-
simp only [Nat.card_eq_fintype_card, Finset.filter_filter]
250+
congr! 2
251+
ext c
252+
simp only [Set.toFinset_setOf, mem_filter, mem_univ, true_and, ← Set.ncard_coe_Finset, coe_filter,
253+
mem_supp_iff, and_comm (a := _ ⊆ _)]
248254
rfl
249255

250-
lemma odd_card_iff_odd_components [Finite V] : Odd (Nat.card V) ↔
251-
Odd {c : ConnectedComponent G | Odd c.supp.ncard}.ncard := by
256+
lemma odd_ncard_oddComponents [Finite V] : Odd G.oddComponents.ncard ↔ Odd (Nat.card V) := by
252257
classical
253258
cases nonempty_fintype V
254259
rw [Nat.card_eq_fintype_card]
@@ -259,24 +264,22 @@ lemma odd_card_iff_odd_components [Finite V] : Odd (Nat.card V) ↔
259264
(fun x _ y _ hxy ↦ Set.disjoint_toFinset.mpr (pairwise_disjoint_supp_connectedComponent _ hxy))]
260265
simp_rw [Set.toFinset_card, ← Nat.card_eq_fintype_card, ← Finset.coe_filter_univ,
261266
Set.ncard_coe_Finset, Set.Nat.card_coe_set_eq]
262-
exact (Finset.odd_sum_iff_odd_card_odd (fun x : G.ConnectedComponent ↦ x.supp.ncard))
267+
exact (Finset.odd_sum_iff_odd_card_odd (fun x : G.ConnectedComponent ↦ x.supp.ncard)).symm
263268

264-
lemma ncard_odd_components_mono [Finite V] {G' : SimpleGraph V} (h : G ≤ G') :
265-
{c : ConnectedComponent G' | Odd c.supp.ncard}.ncard
266-
≤ {c : ConnectedComponent G | Odd c.supp.ncard}.ncard := by
269+
lemma ncard_oddComponents_mono [Finite V] {G' : SimpleGraph V} (h : G ≤ G') :
270+
G'.oddComponents.ncard ≤ G.oddComponents.ncard := by
267271
have aux (c : G'.ConnectedComponent) (hc : Odd c.supp.ncard) :
268-
{c' : G.ConnectedComponent | c'.supp ⊆ c.supp ∧ Odd c'.supp.ncard}.Nonempty := by
272+
{c' : G.ConnectedComponent | Odd c'.supp.ncard ∧ c'.supp ⊆ c.supp}.Nonempty := by
269273
refine Set.nonempty_of_ncard_ne_zero fun h' ↦ ?_
270274
simpa [-Nat.card_eq_fintype_card, -Set.coe_setOf, h']
271-
using (c.odd_card_supp_iff_odd_subcomponents _ h).mp hc
272-
let f : {c : ConnectedComponent G' | Odd (Nat.card c.supp)} →
273-
{c : ConnectedComponent G | Odd (Nat.card c.supp)} :=
274-
fun ⟨c, hc⟩ ↦ ⟨(aux c hc).choose, (aux c hc).choose_spec.2
275+
using (c.odd_oddComponents_ncard_subset_supp _ h).2 hc
276+
let f : G'.oddComponents → G.oddComponents :=
277+
fun ⟨c, hc⟩ ↦ ⟨(aux c hc).choose, (aux c hc).choose_spec.1
275278
refine Finite.card_le_of_injective f fun c c' fcc' ↦ ?_
276279
simp only [Subtype.mk.injEq, f] at fcc'
277280
exact Subtype.val_injective (ConnectedComponent.eq_of_common_vertex
278-
((fcc' ▸ (aux c.1 c.2).choose_spec.1) (ConnectedComponent.nonempty_supp _).some_mem)
279-
((aux c'.1 c'.2).choose_spec.1 (ConnectedComponent.nonempty_supp _).some_mem))
281+
((fcc' ▸ (aux c.1 c.2).choose_spec.2) (ConnectedComponent.nonempty_supp _).some_mem)
282+
((aux c'.1 c'.2).choose_spec.2 (ConnectedComponent.nonempty_supp _).some_mem))
280283

281284
end WalkCounting
282285

Mathlib/Combinatorics/SimpleGraph/Matching.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,10 @@ lemma even_card_of_isPerfectMatching [Fintype V] [DecidableEq V] [DecidableRel G
276276
simpa using (hM.induce_connectedComponent_isMatching c).even_card
277277

278278
lemma odd_matches_node_outside [Finite V] {u : Set V}
279-
{c : ConnectedComponent (Subgraph.deleteVerts ⊤ u).coe}
280-
(hM : M.IsPerfectMatching) (codd : Odd c.supp.ncard) :
281-
∃ᵉ (w ∈ u) (v : ((⊤ : G.Subgraph).deleteVerts u).verts), M.Adj v w ∧ v ∈ c.supp := by
279+
(hM : M.IsPerfectMatching) (c : (Subgraph.deleteVerts ⊤ u).coe.oddComponents) :
280+
∃ᵉ (w ∈ u) (v : ((⊤ : G.Subgraph).deleteVerts u).verts), M.Adj v w ∧ v ∈ c.val.supp := by
282281
by_contra! h
283-
have hMmatch : (M.induce c.supp).IsMatching := by
282+
have hMmatch : (M.induce c.val.supp).IsMatching := by
284283
intro v hv
285284
obtain ⟨w, hw⟩ := hM.1 (hM.2 v)
286285
obtain ⟨⟨v', hv'⟩, ⟨hv , rfl⟩⟩ := hv
@@ -292,10 +291,10 @@ lemma odd_matches_node_outside [Finite V] {u : Set V}
292291
Subgraph.induce_adj, hwnu, not_false_eq_true, and_self, Subgraph.top_adj, M.adj_sub hw.1,
293292
and_true] at hv' ⊢
294293
trivial
295-
apply Nat.not_even_iff_odd.2 codd
296-
haveI : Fintype ↑(Subgraph.induce M (Subtype.val '' supp c)).verts := Fintype.ofFinite _
294+
apply Nat.not_even_iff_odd.2 c.prop
295+
haveI : Fintype ↑(Subgraph.induce M (Subtype.val '' supp c.val)).verts := Fintype.ofFinite _
297296
classical
298-
haveI : Fintype (c.supp) := Fintype.ofFinite _
297+
haveI : Fintype (c.val.supp) := Fintype.ofFinite _
299298
simpa [Subgraph.induce_verts, Subgraph.verts_top, Set.toFinset_image, Nat.card_eq_fintype_card,
300299
Set.toFinset_image,Finset.card_image_of_injective _ (Subtype.val_injective), Set.toFinset_card,
301300
← Set.Nat.card_coe_set_eq] using hMmatch.even_card

0 commit comments

Comments
 (0)