-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Merged by Bors] - feat(Combinatorics/SimpleGraph): part of Tutte's theorem #22119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
8622346
Work in progress
pimotte e6d8b3e
Prepping PR
pimotte 4adc803
Refactoring
pimotte d80f82a
Merge remote-tracking branch 'origin/master' into PO_tutte_pt1
pimotte 6552a11
Move off inlined lemma
pimotte 7aeb75d
Refactoring
pimotte d020260
Polishing
pimotte 730107a
Fixes
pimotte 0097b68
Import order
pimotte fe630fb
Namespacing
pimotte 7416cbf
Documentation
pimotte 47b698b
Apply suggestions from code review
pimotte fe83cf9
Post-review patches
pimotte 83c6162
Apply suggestions from code review
pimotte 44b9735
Merge remote-tracking branch 'origin/master' into PO_tutte_pt1
pimotte 58676c7
Patches
pimotte 6d0f1b7
Cosmetic changes
pimotte b69047e
Apply suggestions from code review
pimotte bde854c
Fixes
pimotte dc17aaa
Apply suggestions from code review
pimotte 18fc7d2
Update Mathlib/Combinatorics/SimpleGraph/Tutte.lean
pimotte 782fbc9
Ugly thing
pimotte 4c5ce7e
Unsqueezed simp and other small tweaks
pimotte a5b612e
golf
YaelDillies 68f755b
Update Mathlib/Combinatorics/SimpleGraph/UniversalVerts.lean
pimotte 0e73fb1
Lint fix
pimotte d992a7b
Update Mathlib/Combinatorics/SimpleGraph/Tutte.lean
pimotte b30b3a4
Update Mathlib/Combinatorics/SimpleGraph/Tutte.lean
pimotte 9e03067
golf using `choose`
YaelDillies dea4153
Fix types
pimotte 8628440
Merge branch 'PO_tutte_pt1' of github.com:leanprover-community/mathli…
pimotte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /- | ||
| Copyright (c) 2024 Pim Otte. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Pim Otte | ||
| -/ | ||
|
|
||
| import Mathlib.Combinatorics.SimpleGraph.Matching | ||
| import Mathlib.Combinatorics.SimpleGraph.Operations | ||
| import Mathlib.Combinatorics.SimpleGraph.UniversalVerts | ||
| import Mathlib.Data.Fintype.Card | ||
|
|
||
| /-! | ||
| # Tutte's theorem (work in progress) | ||
|
|
||
| ## Main definitions | ||
| * `SimpleGraph.TutteViolator G u` is a set of vertices `u` which certifies non-existence of a | ||
| perfect matching. | ||
| -/ | ||
|
|
||
| namespace SimpleGraph | ||
|
|
||
| universe u | ||
| variable {V : Type u} {G G' : SimpleGraph V} {u x v' w : V} [Fintype V] | ||
|
|
||
| /-- A set certifying non-existence of a perfect matching. -/ | ||
| def IsTutteViolator (G : SimpleGraph V) (u : Set V) : Prop := | ||
| u.ncard < ((⊤ : G.Subgraph).deleteVerts u).coe.oddComponents.ncard | ||
|
|
||
| /-- Given a graph in which the universal vertices do not violate Tutte's condition, | ||
| if the graph decomposes into cliques, there exists a matching that covers | ||
| everything except some universal vertices. | ||
|
|
||
| This lemma is marked private, because | ||
| it is strictly weaker than `IsPerfectMatching.exists_of_isClique_supp` -/ | ||
|
pimotte marked this conversation as resolved.
Outdated
|
||
| private lemma Subgraph.IsMatching.exists_verts_compl_subset_universalVerts | ||
| (h : ¬IsTutteViolator G G.universalVerts) | ||
| (h' : ∀ (K : G.deleteUniversalVerts.coe.ConnectedComponent), | ||
| G.deleteUniversalVerts.coe.IsClique K.supp) : | ||
| ∃ M : Subgraph G, M.IsMatching ∧ M.vertsᶜ ⊆ G.universalVerts := by | ||
| classical | ||
| have hrep := ConnectedComponent.Represents.image_out | ||
| G.deleteUniversalVerts.coe.oddComponents | ||
| -- First we match one node from each odd component to a universal vertex | ||
| obtain ⟨t, ht, M1, hM1⟩ := Subgraph.IsMatching.exists_of_universalVerts | ||
| (disjoint_image_val_universalVerts _).symm (by | ||
| simp only [IsTutteViolator, not_lt] at h | ||
| rwa [Set.ncard_image_of_injective _ Subtype.val_injective, hrep.ncard_eq]) | ||
| -- Then we match all other nodes in components internally | ||
| have compMatching (K : G.deleteUniversalVerts.coe.ConnectedComponent) : | ||
| ∃ M : Subgraph G, M.verts = Subtype.val '' K.supp \ M1.verts ∧ M.IsMatching := by | ||
| have : G.IsClique (Subtype.val '' K.supp \ M1.verts) := | ||
| ((h' K).of_induce).subset Set.diff_subset | ||
| rw [← this.even_iff_exists_isMatching (Set.toFinite _), hM1.1] | ||
| exact even_ncard_image_val_supp_sdiff_image_val_rep_union _ ht hrep | ||
| let M2 : Subgraph G := ⨆ (K : G.deleteUniversalVerts.coe.ConnectedComponent), | ||
| (compMatching K).choose | ||
| have hM2 : M2.IsMatching := by | ||
| apply Subgraph.IsMatching.iSup (fun c ↦ (compMatching c).choose_spec.2) (fun i j hij ↦ ?_) | ||
| rw [(compMatching i).choose_spec.2.support_eq_verts, | ||
| (compMatching j).choose_spec.2.support_eq_verts, | ||
| (compMatching i).choose_spec.1, (compMatching j).choose_spec.1] | ||
| exact Set.disjoint_of_subset Set.diff_subset Set.diff_subset <| | ||
| Set.disjoint_image_of_injective Subtype.val_injective <| | ||
| SimpleGraph.pairwise_disjoint_supp_connectedComponent _ hij | ||
|
pimotte marked this conversation as resolved.
Outdated
|
||
| have disjointM12 : Disjoint M1.support M2.support := by | ||
| rw [hM1.2.support_eq_verts, hM2.support_eq_verts, Subgraph.verts_iSup, | ||
| Set.disjoint_iUnion_right] | ||
| exact fun K ↦ (compMatching K).choose_spec.1.symm ▸ Set.disjoint_sdiff_right | ||
| -- The only vertices left are indeed contained in universalVerts | ||
| have : (M1.verts ∪ M2.verts)ᶜ ⊆ G.universalVerts := by | ||
| rw [Set.compl_subset_comm, Set.compl_eq_univ_diff] | ||
| intro v hv | ||
| by_cases h : v ∈ M1.verts | ||
| · exact M1.verts.mem_union_left _ h | ||
| right | ||
| simp only [deleteUniversalVerts_verts, Subgraph.verts_iSup, Set.mem_iUnion, M2, | ||
| (compMatching _).choose_spec.1] | ||
| use (G.deleteUniversalVerts.coe.connectedComponentMk ⟨v, hv⟩) | ||
| aesop | ||
| exact ⟨M1 ⊔ M2, hM1.2.sup hM2 disjointM12, this⟩ | ||
|
|
||
| /-- Given a graph in which the universal vertices do not violate Tutte's condition, | ||
| if the graph decomposes into cliques, it has a perfect matching. -/ | ||
| theorem Subgraph.IsPerfectMatching.exists_of_isClique_supp | ||
| (hveven : Even (Fintype.card V)) (h : ¬G.IsTutteViolator G.universalVerts) | ||
| (h' : ∀ (K : G.deleteUniversalVerts.coe.ConnectedComponent), | ||
| G.deleteUniversalVerts.coe.IsClique K.supp) : ∃ (M : Subgraph G), M.IsPerfectMatching := by | ||
| classical | ||
| obtain ⟨M, ⟨hM, hsub⟩⟩ := IsMatching.exists_verts_compl_subset_universalVerts h h' | ||
|
pimotte marked this conversation as resolved.
Outdated
|
||
| obtain ⟨M', hM'⟩ := ((G.isClique_universalVerts.subset hsub).even_iff_exists_isMatching | ||
| (Set.toFinite _)).mp (by simpa [Set.even_ncard_compl_iff hveven, -Set.toFinset_card, | ||
| ← Set.ncard_eq_toFinset_card'] using hM.even_card) | ||
| use M ⊔ M' | ||
| have hspan : (M ⊔ M').IsSpanning := by | ||
| rw [Subgraph.isSpanning_iff, Subgraph.verts_sup, hM'.1] | ||
| exact M.verts.union_compl_self | ||
| exact ⟨hM.sup hM'.2 (by | ||
| simp only [hM.support_eq_verts, hM'.2.support_eq_verts, hM'.1, Subgraph.verts_sup] | ||
| exact (Set.disjoint_compl_left_iff_subset.mpr fun ⦃a⦄ a ↦ a).symm), hspan⟩ | ||
|
|
||
| theorem IsTutteViolator.empty (hodd : Odd (Fintype.card V)) : G.IsTutteViolator ∅ := by | ||
| have c := | ||
| Finite.card_pos_iff.mp | ||
| ((odd_ncard_oddComponents ((⊤ : Subgraph G).deleteVerts ∅).coe).mpr (by | ||
| simpa [Fintype.card_congr (Equiv.Set.univ V)] using hodd)).pos | ||
| rw [IsTutteViolator, Set.ncard_empty, Set.ncard_pos] | ||
| exact Set.Nonempty.of_subtype | ||
|
|
||
| /-- Proves the necessity part of Tutte's theorem -/ | ||
| lemma not_isTutteViolator_of_isPerfectMatching {M : Subgraph G} (hM : M.IsPerfectMatching) | ||
| (u : Set V) : | ||
| ¬G.IsTutteViolator u := by | ||
| choose f hf g hgf hg using ConnectedComponent.odd_matches_node_outside hM (u := u) | ||
| have hfinj : f.Injective := fun c d hcd ↦ by | ||
| replace hcd : g c = g d := Subtype.val_injective <| hM.1.eq_of_adj_right (hgf c) (hcd ▸ hgf d) | ||
| exact Subtype.val_injective <| ConnectedComponent.eq_of_common_vertex (hg c) (hcd ▸ hg d) | ||
| simpa [IsTutteViolator] using | ||
| Finite.card_le_of_injective (fun c ↦ ⟨f c, hf c⟩) (fun c d ↦ by simp [hfinj.eq_iff]) | ||
|
|
||
| end SimpleGraph | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.