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

[Merged by Bors] - feat(combinatorics/simple_graph/basic): add definition of complement of simple graph #5697

Closed
wants to merge 19 commits into from

Conversation

agusakov
Copy link
Collaborator

Add definition of the complement of a simple graph. Part of branch strongly_regular_graph, with the goal of proving facts about strongly regular graphs.


@agusakov agusakov added awaiting-review The author would like community review of the PR easy < 20s of review time. See the lifecycle page for guidelines. labels Jan 11, 2021
@agusakov agusakov requested a review from kmill January 11, 2021 01:25
Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Can you add a simp lemma that shows complement (complement g) = g?

@agusakov
Copy link
Collaborator Author

Done!

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.

Other than adding the additional @[simp] attributes, 👍

src/combinatorics/simple_graph/basic.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/basic.lean Show resolved Hide resolved
src/combinatorics/simple_graph/basic.lean Show resolved Hide resolved
@eric-wieser
Copy link
Member

Instead of G.compl, does it make sense to use has_compl here and use the notation?

@kmill
Copy link
Collaborator

kmill commented Jan 11, 2021

@eric-wieser Graphs do form a boolean_algebra under operations on the edge set (which would be implemented through boolean operations on the values of adj), so it wouldn't hurt to add a has_compl instance.

The two textbooks I have in front of me use overlines for complementation, but Gᶜ isn't uncommon.

@eric-wieser
Copy link
Member

eric-wieser commented Jan 12, 2021

I'm starting to wonder if simple_graph should have been defined as set (edge V), so that the boolean algebra structure is automatic. Here, edge is just a subtype of sym2 that forbids reflexive objects.

@kmill
Copy link
Collaborator

kmill commented Jan 12, 2021

@eric-wieser You can think of the current definition as being that but expanded out to not mention quotients or sets of subtypes. The following are equivalent:

  • set (edge V)
  • set {e : sym2 V // ¬e.is_diag}
  • {s : set (sym2 V) // ∀ e ∈ s, ¬e.is_diag}
  • {s : set (V × V) // ∀ e ∈ s, e.1 ≠ e.2 ∧ e.swap ∈ s}
  • {s : V × V → Prop // ∀ e, s e → e.1 ≠ e.2 ∧ s e.swap}
  • {s : V → V → Prop // irreflexive s ∧ symmetric s}

It tends to be easier to deal with this last form in proofs because it's all basic logic. Feel free to experiment, though, to see if it ends up being easier overall:

structure simple_graph' (V : Type u) :=
(edges : set {e : finset V // e.card = 2})

@eric-wieser
Copy link
Member

It tends to be easier to deal with this last form in proofs because it's all basic logic.

Right, but it also means you don't have the entire set API automatically available to apply to graphs. Your first two definitions get that for free.

Of course, you can always pick one definition and then write an API to make it have the desirable properties of another definition - my claim is simply that the current choice requires more of this glue than other choices. But I don't have experience proving things about graphs so could be mistaken.

@b-mehta
Copy link
Collaborator

b-mehta commented Jan 12, 2021

structure simple_graph' (V : Type u) :=
(edges : set {e : finset V // e.card = 2})

I've found that this particular version can be really awkward to work with, especially compared to the sym2 version which looks similar a priori

@eric-wieser
Copy link
Member

I guess an equiv between graphs and set {e : sym2 V // ¬e.is_diag} would be enough to transfer the entire boolean algebra structure

agusakov and others added 3 commits January 12, 2021 17:20
Co-authored-by: Kyle Miller <kmill31415@gmail.com>
Co-authored-by: Kyle Miller <kmill31415@gmail.com>
@agusakov
Copy link
Collaborator Author

Should I add the equivalence and boolean_algebra instance to this PR?

@bryangingechen
Copy link
Collaborator

Should I add the equivalence and boolean_algebra instance to this PR?

If they're simple and straightforward (e.g. the fields are mostly 1-line proofs after golfing), yes. Otherwise you can add them to a PR that's dependent on this one.

src/combinatorics/simple_graph/basic.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/basic.lean Outdated Show resolved Hide resolved
src/combinatorics/simple_graph/basic.lean Outdated Show resolved Hide resolved
agusakov and others added 3 commits January 12, 2021 18:08
Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com>
Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com>
Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com>
@agusakov
Copy link
Collaborator Author

Should I add the equivalence and boolean_algebra instance to this PR?

If they're simple and straightforward (e.g. the fields are mostly 1-line proofs after golfing), yes. Otherwise you can add them to a PR that's dependent on this one.

I think I'm going to need to make it a separate PR - iirc the boolean algebra instance relies on definitions of subgraphs and such

@agusakov
Copy link
Collaborator Author

agusakov commented Jan 12, 2021

Also, for some reason compl_adj doesn't work (anymore?). Not sure how to fix that

@kmill
Copy link
Collaborator

kmill commented Jan 12, 2021

I'd say hold off implementing the boolean algebra structure until you actually need it -- I'm not really sure where the full structure would even be used.

Copy link
Collaborator

@bryangingechen bryangingechen left a comment

Choose a reason for hiding this comment

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

Thanks!
bors r+

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Jan 13, 2021
@eric-wieser
Copy link
Member

iirc the boolean algebra instance relies on definitions of subgraphs and such

I'd look at this the other way - the boolean algebra gives you definitions of (edge-)subgraphs for free.

bors bot pushed a commit that referenced this pull request Jan 13, 2021
…of simple graph (#5697)

Add definition of the complement of a simple graph. Part of branch [strongly_regular_graph](https://github.com/leanprover-community/mathlib/tree/strongly_regular_graph), with the goal of proving facts about strongly regular graphs.



Co-authored-by: agusakov <39916842+agusakov@users.noreply.github.com>
@bors
Copy link

bors bot commented Jan 13, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(combinatorics/simple_graph/basic): add definition of complement of simple graph [Merged by Bors] - feat(combinatorics/simple_graph/basic): add definition of complement of simple graph Jan 13, 2021
@bors bors bot closed this Jan 13, 2021
@bors bors bot deleted the graph_compl branch January 13, 2021 18:52
b-mehta pushed a commit that referenced this pull request Jan 16, 2021
…of simple graph (#5697)

Add definition of the complement of a simple graph. Part of branch [strongly_regular_graph](https://github.com/leanprover-community/mathlib/tree/strongly_regular_graph), with the goal of proving facts about strongly regular graphs.



Co-authored-by: agusakov <39916842+agusakov@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy < 20s of review time. See the lifecycle page for guidelines. ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants