Zulip Chat Archive
Stream: mathlib4
Topic: symmetric closure definition
Chris Henson (Jan 24 2026 at 18:26):
@Snir Broshi recently pointed out to me that the symmetric closure of a relation appears as docs#CompRel. This is a leaf file with respect to Mathlib, but is used in the CGT repo (cc @Violeta Hernández ).
This definition seems to be an outlier with respect to TransGen in core and other closures in Mathlib.Logic.Relation in terms of naming and its being a Prop-valued def versus an inductive. Especially if one were inclined to define the transitive symmetric closure, this is a bit awkward.
My question is if adding an inductive SymmGen to Mathlib.Logic.Relation makes sense, and if so should CompRel be deprecated in favor of this or just proven to be equivalent? There is also docs#IncompRel to consider here.
Bhavik Mehta (Jan 24 2026 at 19:22):
TransGen and ReflTransGen can (essentially) only really be defined as inductives, but the symmetric closure of a relation has a much simpler definition, so I think it's reasonable to use the simpler definition here (and doing induction on it is just the eliminator for Or!). The symmetric transitive closure should be the same as TransGen (CompRel r). In particular, the transitive closure of a symmetric relation should be symmetric, with proof looking similar to https://leanprover-community.github.io/mathlib4_docs/Mathlib/Logic/Relation.html#Relation.ReflTransGen.symmetric
Bhavik Mehta (Jan 24 2026 at 19:26):
import Mathlib.Logic.Relation
open Relation
theorem TransGen.symmetric {α : Type*} {r : α → α → Prop} (h : Symmetric r) :
Symmetric (TransGen r) := by
intro x y h
induction h with
| single i => exact .single (h i)
| tail h1 h2 h3 => exact .head (h h2) h3
(the person who added the ReflTransGen version to mathlib really should've done the TransGen one too...)
Bhavik Mehta (Jan 24 2026 at 19:38):
Added in #34382
Chris Henson (Jan 24 2026 at 19:40):
My primary concern here is with naming. Given CompRel is in a different module and doesn't follow the naming pattern, it's a bit hard to discover.
Bhavik Mehta said:
TransGen and ReflTransGen can (essentially) only really be defined as inductives, but the symmetric closure of a relation has a much simpler definition, so I think it's reasonable to use the simpler definition here (and doing induction on it is just the eliminator for Or!).
This is true, I just wondered if this is consistent with how for instance ReflGen is an inductive and docs#Relation.reflGen_iff is generated by mk_iff. I think it is nice when the constructor names are consistent.
The symmetric transitive closure should be the same as
TransGen (CompRel r)?
Yes. I was wondering if this should follow the same pattern as the simp theorems docs#Relation.reflGen_transGen and docs#Relation.transGen_reflGen.
Bhavik Mehta (Jan 24 2026 at 19:45):
Yeah I agree the naming is a little weird in that context, though the other factor is that CompRel makes sense as the name in the context of order theory, in which case CompRel (· ≤ ·) gives the comparability relation, and calling that the symmetric closure feels a little strange? Perhaps it's not as bad though.
Chris Henson (Jan 24 2026 at 19:49):
If it were just CompRel I'd be more confident in arguing to rename it, but stranding IncompRel would be awkward too...
Bhavik Mehta (Jan 24 2026 at 19:51):
Note there's also docs#AntisymmRel
Chris Henson (Jan 24 2026 at 19:56):
Yes, and there is API connecting them in Mathlib.Order.Comparable. If it is sufficient to just use AntisymmRel (which I guess is a question for CGT since IncompRel is not used elsewhere in Mathlib) then I would confidently argue to deprecate the module and rename CompRel to Relation.SymmGen.
Bhavik Mehta (Jan 24 2026 at 20:04):
I don't think it's sufficient to just use AntisymmRel, and in particular I think the TODO in the CompRel file should be applied and CompRel should be used to define IsChain
Chris Henson (Jan 24 2026 at 20:17):
Hmm, I hadn't seen that. I can't think of a nice way (i.e. not involving duplicate definitions) to resolve the naming incongruity given these overlapping but distinct uses.
Chris Henson (Jan 24 2026 at 22:02):
It seems that the conclusion here is that CompRel should be left as is. So if we want theorems like ReflTransGen (CompRel r) = EqvGen r (this is in CSLib at the moment) relating it to the other closures, it seems these should go into Mathlib.Logic.Relation? Maybe that helps a bit with discovery.
Bhavik Mehta (Jan 24 2026 at 22:09):
Yeah I think it's reasonable for that theorem to be in mathlib. I'm warming to the idea of renaming CompRel to SymmGen to be honest
Violeta Hernández (Jan 24 2026 at 22:14):
Is the proposal to rename CompRel to SymmGen?
Violeta Hernández (Jan 24 2026 at 22:14):
I don't really mind. At the moment this is not used anywhere, I mostly just added it for parity with IncompRel.
Chris Henson (Jan 26 2026 at 04:19):
I have opened #34428, just renaming CompRel.
Eric Wieser (Jan 26 2026 at 05:46):
What's the purpose of the Gen(erator) token in these names? Should they instead be ReflClosure, SymmClosure, etc? Or are we willing to use Gen to mean Closure for brevity?
Eric Wieser (Jan 26 2026 at 05:47):
(to me Gen seems to be pointing out the definition happens to be inductive, but that's largely an implementation detail!)
Chris Henson (Jan 26 2026 at 05:47):
I assume it was a decision made for consistency with docs#Relation.TransGen, which is in core.
Eric Wieser (Jan 26 2026 at 05:48):
Ah, I missed that core made the decision; though I suspect it was made long ago in Lean 3
Eric Wieser (Jan 26 2026 at 05:49):
Violeta Hernández said:
Is the proposal to rename
CompReltoRelation.SymmGen?
Given the PR seems to indicate yes, can interested parties :+1:/:minus:/:-1: this message to indicate if you are in favor?
Chris Henson (Jan 26 2026 at 23:12):
So it looks like of those responding at this point, opinion ranges from neutral to in favor.
Violeta Hernández (Jan 26 2026 at 23:35):
Again, I have no use for CompRel, so I don't mind what it's called.
Eric Wieser (Jan 27 2026 at 00:04):
I'm happy to go ahead with the rename given the above, hence removing the awaiting-zulip label from the PR
Eric Wieser (Jan 27 2026 at 19:49):
So is the thought that we rename IncompRel to Relation.AsymmGen? or similar?
Aaron Liu (Jan 27 2026 at 19:52):
that's not
Aaron Liu (Jan 27 2026 at 19:52):
no
Aaron Liu (Jan 27 2026 at 19:52):
r a b doesn't imply IncompRel r a b
Aaron Liu (Jan 27 2026 at 19:52):
so it's not anything Gen
Chris Henson (Jan 27 2026 at 20:10):
It would be consistent naming-wise, but odd mathematically. If you interpret it as a closure, it's saying to discard the relation, not something we usually give a name.
Chris Henson (Jan 27 2026 at 20:14):
I guess the point here is that there are two concepts (symmetric closure and comparability) that happen to coincide definitionally but is awkward for the negation.
Bhavik Mehta (Jan 27 2026 at 23:41):
Yes I agree with Chris, no further renames are necessary: "symmetric closure" and "comparability relation" happen to be the same informal name for the same concept used in different areas. But IncompRel/AntisymmRel and TransGen/ReflTransGen don't really have analogues on the other side. So we have this slightly odd inconsistency between SymmGen and IncompRel, but it's less odd than the old CompRel/TransGen, and Chris' change makes all of these concepts more discoverable and more closely linked, and so imo no further action is needed
Last updated: Feb 28 2026 at 14:05 UTC