Zulip Chat Archive

Stream: mathlib4

Topic: Refactoring `WithTerminal`


Robin Carlier (Jun 22 2025 at 10:22):

Now that the last entry (#25744) in the "joins of categories" series have been merged, I don’t think there is much benefit of having WithTerminal and WithInitial as separate constructions: they are joins of C with Discrete PUnit.
Almost all constructions for WithTerminal (except the identification between functors out of joins with suitable comma categories) are available as Join construction, so I would like to suggest redefining WithTerminal (and the relevant objects) as an abbrev for C ⋆ Discrete PUnit.{1}. Any objections?

Yaël Dillies (Jun 22 2025 at 10:42):

How does that interact with replacing docs#CategoryTheory.Limits.WidePullbackShape with WithTerminal?

Robin Carlier (Jun 22 2025 at 10:49):

Do you have a wip PR doing this?

I don’t see it being much harder. Joins have nice universal properties to construct and characterize up to iso functors out of them, there’s an induction principle for maps, and WithTerminal.lift (arguably the only way one should define a functor from a WithTerminal) should remain the same.

I was thinking of also doing

@[match_pattern]
abbrev star : WithTerminal C := Join.right ⟨.unit
@[match_pattern]
abbrev of (c : C) : WithTerminal C := Join.left c

so that match statement on objects can literally remain the same.

So tl;dr I don’t think this would have much interaction/negative impact.

Robin Carlier (Jun 22 2025 at 10:50):

(For match on morphisms, they’d be almost the same but aesop has slight trouble using the induction principle for maps, so I feel it’s better anyway in contsructions to go through the provided "universal properties" constructors rather than direct constructions).

Yaël Dillies (Jun 22 2025 at 11:15):

Robin Carlier said:

Do you have a wip PR doing this?

No, I was waiting on @Moisés Herradón Cueto's work to hit mathlib fully before starting such a refactor

Bhavik Mehta (Jun 22 2025 at 12:43):

I agree that both Robin's and Yaël's refactors are good ideas here, and that they can (and should) coexist.


Last updated: Dec 20 2025 at 21:32 UTC