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): boolean_algebra for simple_graphs. #8330

Closed
wants to merge 28 commits into from

Conversation

ericrbg
Copy link
Collaborator

@ericrbg ericrbg commented Jul 16, 2021


Open in Gitpod

There's a couple questions I left in the comments; also, am happy to do further work, just ran out of ideas (creative brain isn't on today)

@ericrbg ericrbg added the awaiting-review The author would like community review of the PR label Jul 16, 2021
Comment on lines 45 to 61
instance : bounded_lattice (simple_graph V) :=
{ le := is_subgraph,
sup := union,
inf := inter,
top := complete_graph V,
bot := empty_graph V,
le_refl := λ _ _ _ h, h,
le_trans := λ x y z hxy hyz _ _ h, hyz (hxy h),
le_antisymm := λ x y hxy hyx, by { ext v w, exact ⟨λ h, hxy h, λ h, hyx h⟩ },
le_top := λ x v w h, x.ne_of_adj h,
bot_le := λ x v w h, h.elim,
sup_le := λ x y z hxy hyz v w h, h.cases_on (λ h, hxy h) (λ h, hyz h),
le_sup_left := λ x y v w h, or.inl h,
le_sup_right := λ x y v w h, or.inr h,
le_inf := λ x y z hxy hyz v w h, ⟨hxy h, hyz h⟩,
inf_le_left := λ x y v w h, h.1,
inf_le_right := λ x y v w h, h.2 }
Copy link
Member

Choose a reason for hiding this comment

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

There's an easier way to build the partial order instance:

Suggested change
instance : bounded_lattice (simple_graph V) :=
{ le := is_subgraph,
sup := union,
inf := inter,
top := complete_graph V,
bot := empty_graph V,
le_refl := λ _ _ _ h, h,
le_trans := λ x y z hxy hyz _ _ h, hyz (hxy h),
le_antisymm := λ x y hxy hyx, by { ext v w, exact ⟨λ h, hxy h, λ h, hyx h⟩ },
le_top := λ x v w h, x.ne_of_adj h,
bot_le := λ x v w h, h.elim,
sup_le := λ x y z hxy hyz v w h, h.cases_on (λ h, hxy h) (λ h, hyz h),
le_sup_left := λ x y v w h, or.inl h,
le_sup_right := λ x y v w h, or.inr h,
le_inf := λ x y z hxy hyz v w h, ⟨hxy h, hyz h⟩,
inf_le_left := λ x y v w h, h.1,
inf_le_right := λ x y v w h, h.2 }
instance : bounded_lattice (simple_graph V) :=
{ le := is_subgraph,
sup := union,
inf := inter,
top := complete_graph V,
bot := empty_graph V,
le_top := λ x v w h, x.ne_of_adj h,
bot_le := λ x v w h, h.elim,
sup_le := λ x y z hxy hyz v w h, h.cases_on (λ h, hxy h) (λ h, hyz h),
le_sup_left := λ x y v w h, or.inl h,
le_sup_right := λ x y v w h, or.inr h,
le_inf := λ x y z hxy hyz v w h, ⟨hxy h, hyz h⟩,
inf_le_left := λ x y v w h, h.1,
inf_le_right := λ x y v w h, h.2,
.. partial_order.lift simple_graph.adj (λ (x y : simple_graph V) h, by { ext, rw h }) }

I think a bounded_lattice.lift might be useful here.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for sure, I find it very weird that with your example, removing le ruins it all, even though the bounded_lattice you create has the lt implied by partial_order.lift instead of the lt implied by is_subgraph

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also, i'll change this on the subgraph one too if we find a good way as it's pretty much a copy-paste of that

Copy link
Member

Choose a reason for hiding this comment

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

It breaks if you remove le because pi.le is defined with (v w : V) not ⦃v w : V⦄, so you need extra underscores. I think your custom binders are better though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(I am leaving this unresolved in case we get bounded_lattice.lift or further ideas)

ericrbg and others added 2 commits July 16, 2021 15:27
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
ericrbg and others added 3 commits July 16, 2021 15:34
@ericrbg
Copy link
Collaborator Author

ericrbg commented Jul 16, 2021

i'm not super happy with some of the stuff I did to get the top/bot instances working, but I don't really have better ideas either

Comment on lines 127 to 149
/-- The union of two `simple_graph`s. -/
protected def union (x y : simple_graph V) : simple_graph V :=
{ adj := x.adj ⊔ y.adj,
sym := λ v w h, by rwa [sup_apply, sup_apply, x.adj_comm, y.adj_comm] }

/-- The intersection of two `simple_graph`s. -/
protected def inter (x y : simple_graph V) : simple_graph V :=
{ adj := x.adj ⊓ y.adj,
sym := λ v w h, by rwa [inf_apply, inf_apply, x.adj_comm, y.adj_comm] }

/-- We define `compl G` to be the `simple_graph V` such that no two adjacent vertices in `G`
are adjacent in the complement, and every nonadjacent pair of vertices is adjacent
(still ensuring that vertices are not adjacent to themselves.) -/
protected def compl (G : simple_graph V) : simple_graph V :=
{ adj := λ v w, v ≠ w ∧ ¬G.adj v w,
sym := λ v w ⟨hne, _⟩, ⟨hne.symm, by rwa adj_comm⟩,
loopless := λ v ⟨hne, _⟩, false.elim (hne rfl) }

instance (V : Type u) : inhabited (simple_graph V) :=
⟨complete_graph V⟩
/-- The difference of two `simple_graph`s, which is the simple graph whose edges
are all of those from the first graph that aren't in the second graph. -/
protected def sdiff (x y : simple_graph V) : simple_graph V :=
{ adj := x.adj \ y.adj,
sym := λ v w h, by change x.adj w v ∧ ¬ y.adj w v; rwa [x.adj_comm, y.adj_comm] }
Copy link
Member

Choose a reason for hiding this comment

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

I would lean towards defining these directly as the instances:

Suggested change
/-- The union of two `simple_graph`s. -/
protected def union (x y : simple_graph V) : simple_graph V :=
{ adj := x.adj ⊔ y.adj,
sym := λ v w h, by rwa [sup_apply, sup_apply, x.adj_comm, y.adj_comm] }
/-- The intersection of two `simple_graph`s. -/
protected def inter (x y : simple_graph V) : simple_graph V :=
{ adj := x.adj ⊓ y.adj,
sym := λ v w h, by rwa [inf_apply, inf_apply, x.adj_comm, y.adj_comm] }
/-- We define `compl G` to be the `simple_graph V` such that no two adjacent vertices in `G`
are adjacent in the complement, and every nonadjacent pair of vertices is adjacent
(still ensuring that vertices are not adjacent to themselves.) -/
protected def compl (G : simple_graph V) : simple_graph V :=
{ adj := λ v w, v ≠ w ∧ ¬G.adj v w,
sym := λ v w ⟨hne, _⟩, ⟨hne.symm, by rwa adj_comm⟩,
loopless := λ v ⟨hne, _⟩, false.elim (hne rfl) }
instance (V : Type u) : inhabited (simple_graph V) :=
⟨complete_graph V⟩
/-- The difference of two `simple_graph`s, which is the simple graph whose edges
are all of those from the first graph that aren't in the second graph. -/
protected def sdiff (x y : simple_graph V) : simple_graph V :=
{ adj := x.adj \ y.adj,
sym := λ v w h, by change x.adj w v ∧ ¬ y.adj w v; rwa [x.adj_comm, y.adj_comm] }
/-- We define `Gᶜ` to be the `simple_graph V` such that no two adjacent vertices in `G`
are adjacent in the complement, and every nonadjacent pair of vertices is adjacent
(still ensuring that vertices are not adjacent to themselves.) -/
instance : has_compl (simple_graph V) :=
⟨{ adj := λ v w, v ≠ w ∧ ¬G.adj v w,
sym := λ v w ⟨hne, _⟩, ⟨hne.symm, by rwa adj_comm⟩,
loopless := λ v ⟨hne, _⟩, false.elim (hne rfl) }⟩
/-- The difference of two `simple_graph`s, which is the simple graph whose edges
are all of those from the first graph that aren't in the second graph. -/
instance : has_sdiff (simple_graph V) :=
⟨{ adj := x.adj \ y.adj,
sym := λ v w h, by change x.adj w v ∧ ¬ y.adj w v; rwa [x.adj_comm, y.adj_comm] }⟩

etc. The corresponding foo_adj lemmas can go immediately after each instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

shame simps makes something like simple_graph.has_sup_sup_adj: > ∀ {V : Type u} (x y : simple_graph V) (ᾰ ᾰ_1 : V), (x ⊔ y).adj ᾰ ᾰ_1 = (x.adj ⊔ y.adj) ᾰ ᾰ_1 here, so I have to do it manually

Copy link
Member

Choose a reason for hiding this comment

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

@[simps {simp_rhs := tt}] does a better job probably, but still uses a weird lemma name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it makes (x.adj ᾰ ∪ y.adj ᾰ) ᾰ_1 actually, which doesn't seem like the right simp-normal form

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't know we also had pi.has_union

Copy link
Member

Choose a reason for hiding this comment

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

That's a little alarming - it must be swapping between set X and X -> Prop somewhere...

Does this fail if you put it in that file?

example {α} [has_sup α] (x y : α → α → Prop) (m n : α) : (x ⊔ y) m n :=
begin
  simp?,
  guard_target_strict x m n ∨ y m n,
  sorry
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, the simp? output is simp only [set.sup_eq_union, sup_apply]

Copy link
Member

Choose a reason for hiding this comment

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

Ouch, that shouldn't happen :(

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
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.

bors d+

@bors
Copy link

bors bot commented Jul 21, 2021

✌️ ericrbg can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@github-actions github-actions bot added delegated The PR author may merge after reviewing final suggestions. and removed awaiting-review The author would like community review of the PR labels Jul 21, 2021
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@ericrbg
Copy link
Collaborator Author

ericrbg commented Jul 21, 2021

bors r+

bors bot pushed a commit that referenced this pull request Jul 21, 2021
…`s. (#8330)




Co-authored-by: Eric <37984851+ericrbg@users.noreply.github.com>
@bors
Copy link

bors bot commented Jul 21, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(combinatorics/simple_graph): boolean_algebra for simple_graphs. [Merged by Bors] - feat(combinatorics/simple_graph): boolean_algebra for simple_graphs. Jul 21, 2021
@bors bors bot closed this Jul 21, 2021
@bors bors bot deleted the subgraph_fulltype branch July 21, 2021 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated The PR author may merge after reviewing final suggestions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants