Zulip Chat Archive
Stream: mathlib4
Topic: Refactoring `CategoryTheory.Paths` as a one-field struct
Robin Carlier (Oct 31 2025 at 11:08):
The current docs#CategoryTheory.Paths is a "direct type alias", i.e
/-- A type synonym for the category of paths in a quiver.-/
def Paths (V : Type u₁) : Type u₁ := V
This particular type alias is very prone to defeq abuse, and I’m getting more and more disatisfied with it when working with it in practice (Paths is a necessary ingredient for any kind of category presented by generators and relations.). One of the few pain points are:
- The absence of a good coercion functions to and from the original type. We do have docs#CategoryTheory.Paths.of, which allows in theory to use its
objandmapfields as "coercions", but for instancedocs#CategoryTheory.Paths.of_objis markedsimp, which is very bad (it clearly abuses the defeqV = Paths V). - Similary docs#CategoryTheory.Paths.of_map is also
simpwhich abuses the defeqx ⟶ y = Quiver.Hom.Path x yforx y : Paths V(in the latter form, lean sometimes has trouble unifying with morphisms in a category). This leads to inconsistent writing in the API, where some declarations coerce from morphisms in the quiver to Paths viaPaths.of, while some other do it usingQuiver.Hom.toPath.
As a result, working with Paths often result in either erw hell or with a change-fest (see e.g here or here).
I think the situation would be much better if we could enforce a stronger barrier between Paths and the original type. Concretely, I propose we refactor things in the following way:
- Paths become a one-field structure, i.e
structure Paths (V : Type u₁) : Type u₁ where as : V
- The
Homs for the category struct remain defeq toQuiver.Pathbut we stop usingQuiver.Hom.toPathto coerce morphisms inVto morphisms inPaths V, and we generally banQuiver.Hom.toPathin the "categorical" API (it remains a valid coercion in the Quiver API). The way to translate from the quiver to the path category becomes exclusivelyPaths.of, which gets un-simped.
Are there objections?
Joël Riou (Oct 31 2025 at 12:26):
This looks good to me.
Robin Carlier (Oct 31 2025 at 12:31):
I’m currently experimenting with this and it breaks an unexpected amount of things around Cat.FreeRefl and SSet.HomotopyCategory... Things might not be as easy as I initially made it and may need to wait for a refactor making this part of the library more robust first.
Joël Riou (Oct 31 2025 at 12:36):
It may also break the construction of the localized category (but there the fix should be relatively easy).
Robin Carlier (Oct 31 2025 at 12:37):
Yes, the breakages around Localization/Construction were easy to fix ;)
Emily Riehl (Oct 31 2025 at 17:21):
@Mario Carneiro might be able to diagnose the issues here as he and I are responsible for that code ... :sweat_smile:
Emily Riehl (Oct 31 2025 at 17:22):
But I'm a big fan of anything that will ultimately make SSet.HomotopyCategory easier to work with. It now features in the construction of the strict bicategory of quasicategories.
Joël Riou (Nov 01 2025 at 09:43):
Independently of the refactor of CategoryTheory.Paths, I believe I have found how to make things more practical for doing computations in SSet.HomotopyCategory, in a way that will be consistent with the construction of the fundamental groupoid of a Kan complex, and also get a computable isomorphism for the commutation of hoFunctor to binary products.
https://github.com/joelriou/mathlib4/blob/hofunctor-monoidal/Mathlib/AlgebraicTopology/SimplicialSet/HoFunctorMonoidal.lean (most of the sorries there should be easy)
May I proceed to the appropriate refactor of SSet.HomotopyCategory?
Robin Carlier (Nov 01 2025 at 14:10):
I'm not in a huge hurry for refactoring Paths (I have experimented, but will probably finish the thing in ~2 weeks), so I think there won't be "work clashing" here if you proceed.
Joël Riou (Nov 04 2025 at 10:53):
I have refactored most of the material about the homotopy category of a simplicial set and the nerve adjunction in #31174 (very draft).
Joël Riou (Nov 04 2025 at 10:54):
In order to make the refactor PR a little bit smaller, the first basic PR is #31248.
Joël Riou (Nov 04 2025 at 12:19):
The next two are:
- feat(AlgebraicTopology): Edge and CompStruct for 2-truncated simplicial sets #31254
Joël Riou (Nov 04 2025 at 12:20):
- feat(AlgebraicTopology): inductive construction of StrictSegal structures #31250
Robin Carlier (Nov 04 2025 at 12:20):
Currently having a look at #31250
Joël Riou (Nov 04 2025 at 14:32):
Thanks @Robin Carlier for the reviews!
Joël Riou (Nov 07 2025 at 06:51):
The computable version of the commutation of the homotopy category functor (from simplicial sets or 2-truncated simplicial sets) is now sorry-free #31325
Last updated: Dec 20 2025 at 21:32 UTC