Zulip Chat Archive
Stream: maths
Topic: Internal categories
Zach Murray (Sep 26 2022 at 19:47):
Hello. I'm an undergrad and inexperienced Lean user. I'm trying to implement internal categories with Dorette Pronk and Martin Szyld at Dalhousie University. I'm looking for opinions on how this should be done, and I've run into an issue.
First, here's what we've got. We decided to implement internal categories without requiring the ambient category to have all of its pullbacks. It only needs those relevant to the definition of an internal category. Moreover, we thought it a good idea to mirror the implementation of categories by founding internal categories on internal quivers. Thus, we have the following (please see nLab on internal categories for notation, and note that Cโ and Cโ have become Obj and Arr, respectively):
import category_theory.category.basic
import category_theory.limits.shapes
open category_theory
open category_theory.limits
noncomputable theory
universes v u
class internal_quiver (๐ธ : Type u) [category.{v} ๐ธ] :=
(Obj Arr : ๐ธ)
(s t : Arr โถ Obj)
class internal_category_struct (๐ธ : Type u) [category.{v} ๐ธ]
extends internal_quiver ๐ธ :=
(e : Obj โถ Arr)
(has_comp : has_pullback t s) -- Arr ร Arr
(c : pullback t s โถ Arr)
(has_assocโ : has_pullback (c โซ t) s) -- (Arr ร Arr) ร Arr
(has_assocแตฃ : has_pullback t (c โซ s)) -- Arr ร (Arr ร Arr)
(has_idโ : has_pullback (๐ Obj) s) -- Obj ร Arr
(has_idแตฃ : has_pullback t (๐ Obj)) -- Arr ร Obj
Now, a problem. Mirroring the prefunctor
and functor
definitions, I've worked on an internal_prefunctor
and internal_functor
:
structure internal_prefunctor {๐ธ : Type u} [category.{v} ๐ธ] (๐ป ๐ผ : internal_quiver ๐ธ) :=
(obj : ๐ป.Obj โถ ๐ผ.Obj)
(arr : ๐ป.Arr โถ ๐ผ.Arr)
structure internal_functor {๐ธ : Type u} [category.{v} ๐ธ] (๐ป ๐ผ : internal_category_struct ๐ธ)
extends internal_prefunctor ๐ป ๐ผ :=
(resp_source : sorry)
(resp_target : sorry)
(resp_id : sorry)
(resp_comp : sorry)
For some reason, internal_functor
gives me this error:
type mismatch at application
internal_prefunctor ๐ป
term
๐ป
has type
internal_category_struct ๐ธ : Type (max u v)
but is expected to have type
internal_quiver ?m_1 : Type (max ? ?)
Changing ๐ป
and ๐ผ
to have type internal_quiver ๐ธ
fixes this error.
I don't understand why this error occurs. Is it not the case that every internal_category_struct ๐ธ
is an internal_quiver ๐ธ
, even though the former extends the latter? Why does the seemingly same strategy work for defining functor
but not internal_functor
? I can only imagine there's something about typeclasses I'm missing.
If anyone has any suggestions on things to consider when implementing internal categories, or how to fix this problem, I'd appreciate them!
Adam Topaz (Sep 26 2022 at 19:50):
the issue is that you've defined internal quivers as classes, whereas they should just be plain strucrtures (similarly for internal_category_struct)
Adam Topaz (Sep 26 2022 at 19:50):
A similar construction we have in mathlib that you can try to mimic is docs#Mon_
Adam Topaz (Sep 26 2022 at 19:51):
and docs#Mon_.hom
Andrew Yang (Sep 26 2022 at 19:52):
Also, to get the underlying internal_quiver ๐ธ
from a ๐ป : internal_category_struct ๐ธ
, you should write ๐ป.to_internal_quiver
.
Adam Topaz (Sep 26 2022 at 19:53):
import category_theory.category.basic
import category_theory.limits.shapes
open category_theory
open category_theory.limits
noncomputable theory
universes v u
structure internal_quiver (๐ธ : Type u) [category.{v} ๐ธ] :=
(Obj Arr : ๐ธ)
(s t : Arr โถ Obj)
structure internal_category_struct (๐ธ : Type u) [category.{v} ๐ธ]
extends internal_quiver ๐ธ :=
(e : Obj โถ Arr)
(has_comp : has_pullback t s) -- Arr ร Arr
(c : pullback t s โถ Arr)
(has_assocโ : has_pullback (c โซ t) s) -- (Arr ร Arr) ร Arr
(has_assocแตฃ : has_pullback t (c โซ s)) -- Arr ร (Arr ร Arr)
(has_idโ : has_pullback (๐ Obj) s) -- Obj ร Arr
(has_idแตฃ : has_pullback t (๐ Obj)) -- Arr ร Obj
structure internal_prefunctor {๐ธ : Type u} [category.{v} ๐ธ] (๐ป ๐ผ : internal_quiver ๐ธ) :=
(obj : ๐ป.Obj โถ ๐ผ.Obj)
(arr : ๐ป.Arr โถ ๐ผ.Arr)
structure internal_functor {๐ธ : Type u} [category.{v} ๐ธ] (๐ป ๐ผ : internal_category_struct ๐ธ)
extends internal_prefunctor ๐ป.to_internal_quiver ๐ผ.to_internal_quiver :=
(resp_source : sorry)
(resp_target : sorry)
(resp_id : sorry)
(resp_comp : sorry)
Zach Murray (Sep 26 2022 at 23:37):
Thank you both.
Another problem I'm having concerns reusing pullback t s
. For example, adding the following code
section
variables {๐ธ : Type u} [category.{v} ๐ธ] [๐ป : internal_category_struct ๐ธ]
example : ๐ธ := pullback ๐ป.t ๐ป.s
end
gives me the error
failed to synthesize type class instance for
๐ธ : Type u,
_inst_1 : category ๐ธ,
๐ป : internal_category_struct ๐ธ
โข has_pullback ๐ป.to_internal_quiver.t ๐ป.to_internal_quiver.s
Why is Lean not using ๐ป.has_comp
to resolve this? (Is it the result of poor style in my definition?)
Adam Topaz (Sep 26 2022 at 23:56):
You need to declare this as an instance.
Zach Murray (Sep 27 2022 at 00:05):
I was going to say I already tried that but I just realized I was declaring my instance as inhabited (has_pullback
instead of just has_pullback
... :sweat_smile: It works now, thanks.
Adam Topaz (Sep 27 2022 at 00:57):
Out of curiosity, what do you plan to do with these internal categories?
Zach Murray (Sep 27 2022 at 01:31):
We'd like to implement something on double categories and fibrations. I don't know the details on the full extent of what we're making since I'm learning this material from Dorette and Martin (I've linked them both, perhaps they'll comment).
We tried implementing double categories using the typical "horizontal arrows, vertical arrows, etc" definition and played around with some modifications, but it got ugly and complicated fast (perhaps because I'm inexperienced with Lean). Also, it seems internal categories will be needed anyway, so I'm starting with them instead.
Martin Szyld (Sep 29 2022 at 19:47):
Hi there, thanks @Adam Topaz and @Andrew Yang for your help here! To satisfy Adam's curiosity a bit, with Dorette and others we've been working the last couple of years on a Grothendieck construction for double categories [1] and on double fibrations (as internal categories in Fib, see [2] for details). Now, the Grothendieck construction of [1] works for a type of indexing functor taking values in double categories and we have shown a correspondence
{these indexing functors} <-> {a type of split fibration between double categories, different to that of [2]}.
But, an issue is that the non-split fibration/indexing pseudofunctors case doesn't seem to "canonnically" work like it did in [2] (or at least we're not clever enough to realize how). So in addition to implementing internal categories and showing how double categories are internal categories in Cat in the Lean context, we were also hoping that the type theory formalism, since in a sense it "forces you to be pseudo" (*), may help us down the road to understand how to correctly "pseudify" the construction in [1].
[1] See Dorette's talk at https://topos.site/topos-colloquium/2021/, this will hopefully be in arXiv soon.
[2] https://arxiv.org/abs/2205.15240
(*) See also https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/double.20categories
Last updated: Dec 20 2023 at 11:08 UTC