Zulip Chat Archive

Stream: graph theory

Topic: Way ConnectedComponent definition uses Quot?


Iván Renison (Feb 09 2025 at 23:02):

Hi, in the definition of Quotient it says this:

/--
`Quotient α s` is the same as `Quot α r`, but it is specialized to a setoid `s`
(that is, an equivalence relation) instead of an arbitrary relation.
Prefer `Quotient` over `Quot` if your relation is actually an equivalence relation.
-/

And ConnectedComponent is defined like this:

/-- The quotient of `V` by the `SimpleGraph.Reachable` relation gives the connected
components of a graph. -/
def ConnectedComponent := Quot G.Reachable

So I'm wandering, why not Quotient instead of Quot?
We have reachable_is_equivalence that proves that G.Reachable is a equivalence relation

Chris Wong (Feb 09 2025 at 23:59):

I believe @Kyle Miller had some concerns with the design of Quotient.

Kyle Miller (Feb 10 2025 at 01:18):

When you use Quotient API, it causes all the terms to be put in terms of Quotient.mk and Setoid.r rather than your own quotient map and your own relation. Currently there's no good way to prevent this from happening except to copy the Quotient API for your own type.

Ideally we would have some typeclass that says that a particular function is a quotient map, and then have a reusable API around that.

Eric Wieser (Feb 10 2025 at 06:33):

The same is true when using Quot API though, right? What makes Quotient a worse implementation detail than Quot?

Kyle Miller (Feb 10 2025 at 06:35):

Quot.mk is similar, sure, but that still leaves Setoid.r slipping in.

Yaël Dillies (Feb 10 2025 at 07:29):

Kyle Miller said:

Ideally we would have some typeclass that says that a particular function is a quotient map, and then have a reusable API around that.

There's a PR doing just that, in case you weren't aware of it: #16421

Eric Wieser (Feb 10 2025 at 08:50):

Should Quotient have its single Setoid argument exploded into two arguments?

Iván Renison (Feb 11 2025 at 22:35):

I want to prove this:

lemma reachable_of_in {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
    (hu : u  C) (hv : v  C) : G.Reachable u v := sorry

But I don't find an easy proof. I expected that there should be a lemma saying something like this:

lemma aux (r : V  V  Prop) [Membership V (Quot r)] (C : Quot r) (u v : V)
    (hu : u  C) (hv : v  C) : r u v := sorry

But I can find a lemma saying that and I'm not able to prove it. Do you know if that lemma is valid?

Kyle Miller (Feb 11 2025 at 22:44):

import Mathlib.Combinatorics.SimpleGraph.Path

-- correction of `SimpleGraph.ConnectedComponent.mem_supp_iff`
@[simp]
theorem mem_supp_iff' {G : SimpleGraph V} (C : G.ConnectedComponent) (v : V) :
    v  C  G.connectedComponentMk v = C :=
  Iff.rfl

lemma reachable_of_in {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
    (hu : u  C) (hv : v  C) : G.Reachable u v := by
  rw [mem_supp_iff'] at hu hv
  rw [ hv] at hu
  exact SimpleGraph.ConnectedComponent.exact hu

Kyle Miller (Feb 11 2025 at 22:44):

Saving a line:

lemma reachable_of_in {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
    (hu : u  C) (hv : v  C) : G.Reachable u v := by
  rw [mem_supp_iff'] at hu hv
  exact SimpleGraph.ConnectedComponent.exact (hv  hu)

Iván Renison (Feb 11 2025 at 22:50):

Thanks!

Bhavik Mehta (Feb 12 2025 at 16:05):

As an aside, we don't have that in a connected graph on at least two vertices the support is the whole vertex set; this might be a nice thing to do for someone!

Aaron Liu (Feb 12 2025 at 16:36):

This was fun

SimpleGraph.Preconnected.support_eq_univ

Kyle Miller (Feb 12 2025 at 16:47):

A bit shorter:

SimpleGraph.Preconnected.support_eq_univ


Last updated: May 02 2025 at 03:31 UTC