-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(Combinatorics/Graph): connected graphs #37861
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
Open
Jun2M
wants to merge
13
commits into
leanprover-community:master
Choose a base branch
from
Jun2M:GraphIsCompOf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−0
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9e603d9
init
Jun2M 378bfd6
isClosedSubgraph_bot_iff
Jun2M cad5d40
disjoint
Jun2M 5c1189e
Merge branch 'master' into GraphOrderBot
Jun2M bddb032
Apply comment
Jun2M c298fd6
Update Mathlib/Combinatorics/Graph/Subgraph.lean
Jun2M 0b0786d
rm vertexSet_disjoint_of_disjoint
Jun2M 501f7b8
Merge branch 'GraphOrderBot' of https://github.com/Jun2M/mathlib4 int…
Jun2M 989cb0a
init
Jun2M c550e8e
Name change
Jun2M 4f8586d
Merge branch 'master' into GraphIsCompOf
Jun2M 5b9375b
name change
Jun2M 0a53085
Merge branch 'master' into GraphIsCompOf
Jun2M 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /- | ||
| Copyright (c) 2025 Peter Nelson. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Peter Nelson, Jun Kwon | ||
| -/ | ||
| module | ||
|
|
||
| public import Mathlib.Order.Minimal | ||
| public import Mathlib.Combinatorics.Graph.Subgraph | ||
|
|
||
| /-! | ||
| # Connected components of graphs | ||
|
|
||
| This file defines the connected components and connectedness of a graph. | ||
|
|
||
| ## Main definitions | ||
|
|
||
| * `IsCompOf`: a graph `H` is a component of `G` if it is a minimal nonempty closed subgraph of `G`. | ||
| * `IsConnected`: a graph `G` is connected if it is a component of itself. Empty graph is not | ||
| considered connected. | ||
|
|
||
| -/ | ||
|
|
||
| public section | ||
|
|
||
| variable {α β : Type*} {G H K : Graph α β} | ||
|
|
||
| namespace Graph | ||
|
|
||
| /-! ### Components -/ | ||
|
|
||
| /-- A component of `G` is a minimal nonempty closed subgraph of `G`. -/ | ||
| @[expose] def IsCompOf (H G : Graph α β) : Prop := Minimal (fun H ↦ H ≤c G ∧ V(H).Nonempty) H | ||
|
|
||
| namespace IsCompOf | ||
|
|
||
| @[simp] lemma isClosedSubgraph (h : H.IsCompOf G) : H ≤c G := h.prop.1 | ||
| lemma isInducedSubgraph (h : H.IsCompOf G) : H ≤i G := h.isClosedSubgraph.isInducedSubgraph | ||
| @[simp] lemma le (h : H.IsCompOf G) : H ≤ G := h.isClosedSubgraph.le | ||
| @[simp, grind →] lemma nonempty (h : H.IsCompOf G) : V(H).Nonempty := h.prop.2 | ||
|
|
||
| lemma anti_right (hKH : K ≤ H) (hHG : H ≤ G) (h : K.IsCompOf G) : K.IsCompOf H := | ||
| ⟨⟨h.isClosedSubgraph.anti_right hKH hHG, h.nonempty⟩, fun _ ⟨hK'H, hK'ne⟩ hK'K ↦ | ||
| h.le_of_le ⟨(hK'H.anti_right hK'K hKH).trans h.isClosedSubgraph, hK'ne⟩ hK'K⟩ | ||
|
|
||
| end IsCompOf | ||
|
|
||
| /-! ### Connectedness -/ | ||
|
|
||
| /-- A graph is connected if it is a minimal closed subgraph of itself. -/ | ||
| protected def IsConnected (G : Graph α β) : Prop := G.IsCompOf G | ||
|
|
||
| lemma IsConnected.nonempty (hG : G.IsConnected) : V(G).Nonempty := IsCompOf.nonempty hG | ||
|
|
||
| @[simp] | ||
| lemma IsConnected.bot_not_isConnected : ¬ (⊥ : Graph α β).IsConnected := by | ||
| rintro h | ||
| simpa using h.nonempty | ||
|
|
||
| lemma isConnected_iff_forall_closed (hG : V(G).Nonempty) : | ||
| G.IsConnected ↔ ∀ ⦃H⦄, H ≤c G → V(H).Nonempty → H = G := by | ||
| refine ⟨fun h H hHG hHne ↦ ?_, fun h ↦ ⟨by simpa, fun H ⟨hle, hH⟩ _ ↦ (h hle hH).symm.le⟩⟩ | ||
| rw [Graph.IsConnected] at h | ||
| exact h.eq_of_le ⟨hHG, hHne⟩ hHG.le | ||
|
|
||
| lemma isConnected_iff_forall_closed_ge (hG : V(G).Nonempty) : | ||
| G.IsConnected ↔ ∀ ⦃H⦄, H ≤c G → V(H).Nonempty → G ≤ H := by | ||
| rw [isConnected_iff_forall_closed hG] | ||
| exact ⟨fun h H hle hne ↦ (h hle hne).symm.le, fun h H hle hne ↦ (h hle hne).antisymm' hle.le⟩ | ||
|
|
||
| lemma IsConnected.ext_of_isClosedSubgraph (hH : H ≤c G) (hne : V(H).Nonempty) (hG : G.IsConnected) : | ||
| H = G := by | ||
| rw [isConnected_iff_forall_closed (hne.mono hH.le.vertexSet_mono)] at hG | ||
| exact hG hH hne | ||
|
|
||
| lemma IsCompOf.isConnected (h : H.IsCompOf G) : H.IsConnected := h.anti_right le_rfl h.le | ||
|
|
||
| lemma IsConnected.exists_inc_notMem_of_lt (hlt : H < G) (hne : V(H).Nonempty) (hG : G.IsConnected) : | ||
| ∃ e x, G.Inc e x ∧ e ∉ E(H) ∧ x ∈ V(H) := by | ||
| refine by_contra fun hcon ↦ hlt.ne <| hG.ext_of_isClosedSubgraph ?_ hne | ||
| refine IsClosedSubgraph.mk' hlt.le fun e x hex hx ↦ ?_ | ||
| simp only [not_exists, not_and, not_imp_not] at hcon | ||
| exact hcon _ _ hex hx | ||
|
|
||
| end Graph | ||
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
Oops, something went wrong.
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.