Skip to content
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

feat(combinatorics/simple_graph/connectivity): number of connected components when deleting edges #17654

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

tjeremie
Copy link
Collaborator

Add definition for number of connected components and then prove that this number either goes up by 1 or is unchanged when an edge is removed, depending on if its in a cycle or not.


Open in Gitpod

Add definition for number of connected components and then prove that this number either goes up by 1 or is unchanged when an edge is removed, depending on if its in a cycle or not.
@tjeremie tjeremie requested a review from a team as a code owner November 21, 2022 00:30
@tjeremie tjeremie added awaiting-review The author would like community review of the PR t-combinatorics Combinatorics labels Nov 21, 2022
@YaelDillies
Copy link
Collaborator

Could you fix the style errors?

@tjeremie
Copy link
Collaborator Author

Could you fix the style errors?

Should be fixed now

@kmill kmill changed the title feat(combinatorics/simple_graph/):number of connected components feat(combinatorics/simple_graph/connectivity): number of connected components when deleting edges Nov 21, 2022
Copy link
Collaborator

@kmill kmill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some comments for the first half. Once you've addressed them, I'll keep going through the rest.

Thanks for your work on the relationship between delete_edges and the number of connected components!

src/combinatorics/simple_graph/basic.lean Outdated Show resolved Hide resolved
@@ -697,6 +705,8 @@ lemma edge_finset_delete_edges [fintype V] [decidable_eq V] [decidable_rel G.adj
(G.delete_edges s).edge_finset = G.edge_finset \ s :=
by { ext e, simp [edge_set_delete_edges] }

lemma delete_non_edge {e: sym2 V} (he: e ∉ G.edge_set) : G.delete_edges {e} = G := by {ext,finish}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that finish has now been banned in mathlib3 since it's not going to be ported to Lean 4.

There are some more general results we should add here, in place of delete_non_edge.

lemma delete_edges_eq_self_iff_disjoint {s : set (sym2 V)} :
  G.delete_edges s = G ↔ disjoint G.edge_set s :=
begin
  rw [set.disjoint_left, simple_graph.ext_iff],
  simp only [function.funext_iff, delete_edges_adj, eq_iff_iff, and_iff_left_iff_imp],
  split,
  { intro h,
    refine sym2.ind (λ v w, _),
    exact h v w, },
  { intros h v w hvw,
    rw ← mem_edge_set at hvw,
    exact h hvw, }
end

lemma delete_edges_singleton_eq_self_iff_not_mem :
  G.delete_edges {e} = G ↔ e ∉ G.edge_set :=
by rw [delete_edges_eq_self_iff_disjoint, set.disjoint_singleton_right]

I should mention that mathlib3 style is that type ascription colons should have a space on both sides, so {e : sym2 V} rather than {e: sym2 V}.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make both of those lemmas simp.

src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
Comment on lines 530 to 531
lemma darts_nodup_of_edges_nodup {u v : V} {p : G.walk u v} (h : p.edges.nodup) : p.darts.nodup
:=list.nodup.of_map dart.edge h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mathlib3 style:

Suggested change
lemma darts_nodup_of_edges_nodup {u v : V} {p : G.walk u v} (h : p.edges.nodup) : p.darts.nodup
:=list.nodup.of_map dart.edge h
lemma darts_nodup_of_edges_nodup {u v : V} {p : G.walk u v} (h : p.edges.nodup) : p.darts.nodup :=
list.nodup.of_map dart.edge h

src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/connectivity.lean Outdated Show resolved Hide resolved
@kmill kmill added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Nov 21, 2022
@tjeremie
Copy link
Collaborator Author

Thanks for your various comments! Sorry for the delay, but I think I've now fixed everything you mentioned (as well as similar issues later in the code). Let me know what you think

@tjeremie tjeremie added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Nov 27, 2022
@semorrison semorrison added the too-late This PR was ready too late for inclusion in mathlib3 label Jul 16, 2023
@kmill
Copy link
Collaborator

kmill commented Jul 16, 2023

This PR is on my radar, and while it missed the mathlib3 cutoff, I'm hoping to (eventually) get it ported to mathlib4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review The author would like community review of the PR t-combinatorics Combinatorics too-late This PR was ready too late for inclusion in mathlib3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants