Skip to content
This repository was archived by the owner on Nov 6, 2026. It is now read-only.

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

Closed
agusakov wants to merge 19 commits into
masterfrom
graph_compl
Closed

agusakov wants to merge 19 commits into
masterfrom
graph_compl

Conversation

@agusakov

Copy link
Copy Markdown
Contributor

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

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

Done!

@kmill kmill left a comment

Copy link
Copy Markdown
Collaborator

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, 👍

@eric-wieser

Copy link
Copy Markdown
Member

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

@kmill

kmill commented Jan 11, 2021

Copy link
Copy Markdown
Collaborator

@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

eric-wieser commented Jan 12, 2021 •

Copy link
Copy Markdown
Member

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

kmill commented Jan 12, 2021

Copy link
Copy Markdown
Collaborator

@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
Copy Markdown
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

b-mehta commented Jan 12, 2021

Copy link
Copy Markdown
Collaborator
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
Copy Markdown
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

Copy link
Copy Markdown
Contributor Author

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

@bryangingechen

Copy link
Copy Markdown
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.

@agusakov

Copy link
Copy Markdown
Contributor 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

agusakov commented Jan 12, 2021 •

Copy link
Copy Markdown
Contributor Author

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

@kmill

kmill commented Jan 12, 2021

Copy link
Copy Markdown
Collaborator

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.

@bryangingechen bryangingechen left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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 <[email protected]>
@bors

bors Bot commented Jan 13, 2021

Copy link
Copy Markdown

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 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

5 participants