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