module Cat.Diagram.Limit.Base where

LimitsπŸ”—

Note

This page describes the general definition of limits, and assumes some familiarity with some concrete examples, in particular terminal objects, products, equalisers, and pullbacks. It might be a good idea to check out those pages before continuing!

IdeaπŸ”—

To motivate limits, note how all the above examples have roughly the same structure. They all consist of some object, a bunch of maps out of said object, some commutativity conditions, and a universal property that states that we can construct unique maps into the object under certain conditions.

Our first step towards making this vague intuition precise is to construct a mathematical widget that picks out a collection of objects, arrows, and commutativity conditions in a category. This is required to describe the collection of maps out of our special objects, and the equations they satisfy. Luckily, we already have such a widget: functors!

To see how this works, let’s take a very simple example: a functor out of the single object category with one morphism into some category If we look at the image of such a functor, we can see that it picks out a single object; the single morphism must be taken to the identity morphism due to functoriality. We can scale this example up to functors from discrete category with elements; if we look at the image of such a functor, we shall see that it selects out objects of

We can perform the same trick with non-discrete categories; for instance, a functor out of the parallel arrows category selects a pair of parallel arrows in a functor out of the isomorphism category selects an isomorphism in and so on. We call such functors diagrams to suggest that we should think of them as picking out some shape in

We can use this newfound insight to describe the shape that each of our examples is defined over. Products are defined over a diagram that consists of a pair of objects; these diagrams correspond to functors out of the category with 2 objects and only identity morphisms. Equalisers are defined over a diagram that consists of a pair of parallel morphisms; such diagrams are given by functors out of the aforementioned parallel arrows category. Pullbacks defined over a diagram of the shape, again, these diagrams are given by functors out of the category with that exact shape. Terminal objects may seem to break this trend, but we can think of them as being defined over the empty diagram, the unique functor from the category with no objects.

We now move our attention to the maps out of our special object into the objects of the diagram. Note that these maps need to commute with any morphisms in the diagram, as is the case with pullbacks and equalisers. This is where our definition diverges from many other introductory sources. The typical approach is to define a bespoke widget called a cone that encodes the required morphisms and commuting conditions, and then proceeding from there.

However, this approach is somewhat unsatisfying. Why did we have to invent a new object just to bundle up the data we needed? Furthermore, cones are somewhat disconnected from the rest of category theory, which makes it more difficult to integrate results about limits into the larger body of work. It would be great if we could encode the data we needed using existing objects!

Luckily, we can! If we take a step back, we can notice that we are trying to construct a map into a functor. What are maps into functors? Natural transformations! Concretely, let be some diagram. We can encode the same data as a cone in a natural transformation where denotes the constant functor that maps object to and every morphism to and denotes the unique functor into the terminal category. The components of such a natural transformation yield maps from for every and naturality ensures that these maps must commute with the rest of the diagram. We can describe this situation diagrammatically like so:

All that remains is the universal property. If we translate this into our existing machinery, that means that must be the universal functor equipped with a natural transformation that is, for any other equipped with we have a unique natural transformation that factors This is a bit of a mouthful, so let’s look at a diagram instead.

We might be tempted to stop here and call it a day, but we can go one step further. It turns out that these universal functors have a name: they are right Kan extensions. This allows for an extremely concise definition of limits: is the limit of a diagram when the constant functor is a right Kan extension of along

module _ {J : Precategory o₁ h₁} {C : Precategory oβ‚‚ hβ‚‚} (Diagram : Functor J C) where
  private
    module C = Precategory C
    open _=>_
    open Functor

  is-limit : (x : C.Ob) β†’ Const x => Diagram β†’ Type _
  is-limit x cone = is-ran !F Diagram (!Const x) cone

In a β€œbundled” form, we may define the type of limits for a diagram as the type of right extensions of along the terminating functor

  Limit : Type _
  Limit = Ran !F Diagram

ConcretelyπŸ”—

The definition above is very concise, and it has the benefit of being abstract: We can re-use definitions and theorems originally stated for right Kan extensions to limits. However, it has the downside of being abstract: it’s good for working with limits in general, but working with a specific limit is penalised, as the data we want to get at is β€œburied”.

The definition above is also hard to instantiate, since you have to.. bury the data, and some of it is really quite deep! What we do is provide an auxiliary record, make-is-limit, which computes right extensions to the point.

We solve this by defining a concretised version of is-limit, called make-is-limit, which exposes the following data. First, we have morphisms from the apex to every value in the diagram, a family called Moreover, if is a morphism in the β€œshape” category then i.e., the maps fit into triangles

    field
      ψ        : (j : J.Ob) β†’ C.Hom apex (Fβ‚€ j)
      commutes : βˆ€ {x y} (f : J.Hom x y) β†’ F₁ f C.∘ ψ x ≑ ψ y

The rest of the data says that is the universal family of maps with this property: If is another family of maps with the same commutativity property, then each factors through the apex by a single, unique universal morphism:

      universal
        : βˆ€ {x : C.Ob}
        β†’ (eps : βˆ€ j β†’ C.Hom x (Fβ‚€ j))
        β†’ (βˆ€ {x y} (f : J.Hom x y) β†’ F₁ f C.∘ eps x ≑ eps y)
        β†’ C.Hom x apex

      factors
        : βˆ€ {j : J.Ob} {x : C.Ob}
        β†’ (eps : βˆ€ j β†’ C.Hom x (Fβ‚€ j))
        β†’ (p : βˆ€ {x y} (f : J.Hom x y) β†’ F₁ f C.∘ eps x ≑ eps y)
        β†’ ψ j C.∘ universal eps p ≑ eps j

      unique
        : βˆ€ {x : C.Ob}
        β†’ (eps : βˆ€ j β†’ C.Hom x (Fβ‚€ j))
        β†’ (p : βˆ€ {x y} (f : J.Hom x y) β†’ F₁ f C.∘ eps x ≑ eps y)
        β†’ (other : C.Hom x apex)
        β†’ (βˆ€ j β†’ ψ j C.∘ other ≑ eps j)
        β†’ other ≑ universal eps p

If we have this data, then we can make a value of is-limit. It might seem like naturality, required for a right Kan extension, is missing from make-is-limit, but it can be derived from the other data we have been given:

  to-is-limit : βˆ€ {D : Functor J C} {apex}
              β†’ (mk : make-is-limit D apex)
              β†’ is-limit D apex (to-cone mk)
  to-is-limit {Diagram} {apex} mklim = lim where
    open make-is-limit mklim
    open is-ran
    open Functor
    open _=>_

    lim : is-limit Diagram apex (to-cone mklim)
    lim .Οƒ {M = M} Ξ± .Ξ· _ =
      universal (Ξ± .Ξ·) (Ξ» f β†’ sym (Ξ± .is-natural _ _ f) βˆ™ C.elimr (M .F-id))
    lim .Οƒ {M = M} Ξ± .is-natural _ _ _ =
      lim .Οƒ Ξ± .Ξ· _ C.∘ M .F₁ tt β‰‘βŸ¨ C.elimr (M .F-id) βŸ©β‰‘
      lim .Οƒ Ξ± .Ξ· _              β‰‘Λ˜βŸ¨ C.idl _ βŸ©β‰‘Λ˜
      C.id C.∘ lim .Οƒ Ξ± .Ξ· _     ∎
    lim .Οƒ-comm {Ξ² = Ξ²} = ext Ξ» j β†’ factors (Ξ² .Ξ·) _
    lim .Οƒ-uniq {Ξ² = Ξ²} {Οƒ' = Οƒ'} p = ext Ξ» _ β†’
      sym $ unique (Ξ² .Ξ·) _ (Οƒ' .Ξ· tt) (Ξ» j β†’ sym (p Ξ·β‚š j))

To use the data of is-limit, we provide a function for unmaking a limit:

  unmake-limit
    : βˆ€ {D : Functor J C} {F : Functor ⊀Cat C} {eps}
    β†’ is-ran !F D F eps
    β†’ make-is-limit D (F # tt)

We also provide a similar interface for the bundled form of limits.

module Limit
  {J : Precategory o₁ h₁} {C : Precategory oβ‚‚ hβ‚‚} {D : Functor J C} (L : Limit D)
  where

The β€œapex” object of the limit is the single value in the image of the extension functor.

  apex : C.Ob
  apex = Ext.β‚€ tt

Furthermore, we can show that the apex is the limit, in the sense of is-limit, of the diagram. You’d think this is immediate, but unfortunately, proof assistants: is-limit asks for the constant functor functor with value apex to be a Kan extension, but Limit, being an instance of Ran, packages an arbitrary functor

Since Agda does not compare functors for we have to shuffle our data around manually. Fortunately, this isn’t a very long computation.

  cone : Const apex => D
  cone .Ξ· x = eps .Ξ· x
  cone .is-natural x y f = ap (_ C.∘_) (sym $ Ext .F-id) βˆ™ eps .is-natural x y f

  has-limit : is-limit D apex cone
  has-limit .is-ran.Οƒ Ξ± .Ξ· = Οƒ Ξ± .Ξ·
  has-limit .is-ran.Οƒ Ξ± .is-natural x y f =
    Οƒ Ξ± .is-natural tt tt tt βˆ™ ap (C._∘ _) (Ext .F-id)
  has-limit .is-ran.Οƒ-comm = ext (Οƒ-comm Ξ·β‚š_)
  has-limit .is-ran.Οƒ-uniq {M = M} {Οƒ' = Οƒ'} p =
    ext Ξ» _ β†’ Οƒ-uniq {Οƒ' = nt} (reext! p) Ξ·β‚š _ where
      nt : M => Ext
      nt .Ξ· = Οƒ' .Ξ·
      nt .is-natural x y f = Οƒ' .is-natural x y f βˆ™ ap (C._∘ _) (sym $ Ext .F-id)

  open is-limit has-limit public

UniquenessπŸ”—

Above, there has been mention of the limit. The limit of a diagram, if it exists, is unique up to isomorphism. This follows directly from uniqueness of Kan extensions.

We show a slightly more general result first: if there exist a pair of maps between the apexes of the 2 limits, and these maps commute with the 2 limits, then and are inverses.

  limits→inversesp
    : βˆ€ {f : C.Hom x y} {g : C.Hom y x}
    β†’ (βˆ€ {j : J.Ob} β†’ Ly.ψ j C.∘ f ≑ Lx.ψ j)
    β†’ (βˆ€ {j : J.Ob} β†’ Lx.ψ j C.∘ g ≑ Ly.ψ j)
    β†’ C.Inverses f g
  limits→inversesp {f = f} {g = g} f-factor g-factor =
    inversesⁿ→inverses {Ξ± = !constⁿ f} {Ξ² = !constⁿ g}
      (Ran-unique.Οƒ-inversesp Ly Lx
        (ext Ξ» j β†’ f-factor {j})
        (ext Ξ» j β†’ g-factor {j}))
      tt

Furthermore, any morphism between apexes that commutes with the limit must be invertible.

  limits→invertiblep
    : βˆ€ {f : C.Hom x y}
    β†’ (βˆ€ {j : J.Ob} β†’ Ly.ψ j C.∘ f ≑ Lx.ψ j)
    β†’ C.is-invertible f
  limitsβ†’invertiblep {f = f} f-factor = is-invertibleⁿ→is-invertible
    {α = !constⁿ f}
    (Ran-unique.Οƒ-is-invertiblep Ly Lx
      (ext Ξ» j β†’ f-factor {j}))
    tt

This implies that the universal maps must also be inverses.

  limits→inverses
    : C.Inverses (Ly.universal Lx.ψ Lx.commutes) (Lx.universal Ly.ψ Ly.commutes)
  limits→inverses =
    limitsβ†’inversesp (Ly.factors Lx.ψ Lx.commutes) (Lx.factors Ly.ψ Ly.commutes)

  limits→invertible
    : C.is-invertible (Ly.universal Lx.ψ Lx.commutes)
  limitsβ†’invertible = limitsβ†’invertiblep (Ly.factors Lx.ψ Lx.commutes)

Finally, we can bundle this data up to show that the apexes are isomorphic.

  limits-unique : x C.β‰… y
  limits-unique = isoⁿ→iso (Ran-unique.unique Lx Ly) tt

Furthermore, if the universal map is invertible, then that means that its domain is also a limit of the diagram.

  is-invertible→is-limitp
    : βˆ€ {K' : Functor ⊀Cat C} {eps : K' F∘ !F => D}
    β†’ (eps' : βˆ€ j β†’ C.Hom (K' .Fβ‚€ tt) (D.β‚€ j))
    β†’ (p : βˆ€ {x y} (f : J.Hom x y) β†’ D.₁ f C.∘ eps' x ≑ eps' y)
    β†’ (βˆ€ {j} β†’ eps' j ≑ eps .Ξ· j)
    β†’ C.is-invertible (Ly.universal eps' p)
    β†’ is-ran !F D K' eps
  is-invertible→is-limitp {K' = K'} eps' p q invert =
    generalize-limitp
      (is-invertibleβ†’is-ran Ly $ invertibleβ†’invertibleⁿ _ (Ξ» _ β†’ invert))
      q

Another useful fact is that if is a limit of some diagram and is naturally isomorphic to some other diagram then the apex of is also a limit of

  natural-iso-diagram→is-limitp
    : βˆ€ {D' : Functor J C} {eps : K F∘ !F => D'}
    β†’ (isos : D ≅ⁿ D')
    β†’ (βˆ€ {j} β†’ Isoⁿ.to isos .Ξ· j C.∘ Ly.ψ j ≑ eps .Ξ· j)
    β†’ is-ran !F D' K eps
  natural-iso-diagram→is-limitp {D' = D'} isos p =
    generalize-limitp
      (natural-iso-of→is-ran Ly isos)
      p

Since limits are unique β€œup to isomorphism”, if is a univalent category, then Limit itself is a proposition! This is an instance of the more general uniqueness of Kan extensions.

  Limit-is-prop : is-category C β†’ is-prop (Limit Diagram)
  Limit-is-prop cat = Ran-is-prop cat

Preservation of limitsπŸ”—

Suppose you have a limit of a diagram We say that preserves if is also a limit of More precisely, we say a functor preserves limits of if it takes limiting cones β€œupstairs” to limiting cones β€œdownstairs”.

This definition is necessary because will not, in general, possess an operation assigning a limit to every diagram β€” therefore, there might not be a β€œcanonical limit” of we could compare to. However, since limits are described by a universal property (in particular, being terminal), we don’t need such an object! Any limit is as good as any other.

  preserves-limit : Type _
  preserves-limit =
    βˆ€ {K : Functor ⊀Cat C} {eps : K F∘ !F => Diagram}
    β†’ (lim : is-ran !F Diagram K eps)
    β†’ preserves-ran F lim

Reflection of limitsπŸ”—

Using the terminology from before, we say a functor reflects limits if it only takes limiting cones β€œupstairs” to limiting cones β€œdownstairs”: this is the converse implication from preservation of limits. More concretely, if we have a cone over whose image under is a limiting cone over then reflects this limit if we already had a limiting cone to begin with!

  reflects-limit : Type _
  reflects-limit =
    βˆ€ {K : Functor ⊀Cat C} {eps : K F∘ !F => Diagram}
    β†’ (ran : is-ran !F (F F∘ Diagram) (F F∘ K) (nat-assoc-from (F β–Έ eps)))
    β†’ reflects-ran F ran
module preserves-limit
  {J : Precategory o₁ h₁} {C : Precategory oβ‚‚ hβ‚‚} {D : Precategory o₃ h₃}
  {F : Functor C D} {Dia : Functor J C}
  (preserves : preserves-limit F Dia)
  {K : Functor ⊀Cat C} {eps : K F∘ !F => Dia}
  (lim : is-ran !F Dia K eps)
  where
  private
    module D = Precategory D
    module C = Precategory C
    module J = Precategory J
    module F = Func F
    module Dia = Func Dia

    module lim = is-limit lim
    module F-lim = is-limit (preserves lim)

  universal
    : {x : C.Ob}
    β†’ {eps : (j : J.Ob) β†’ C.Hom x (Dia.Fβ‚€ j)}
    β†’ {p : βˆ€ {i j} (f : J.Hom i j) β†’ Dia.F₁ f C.∘ eps i ≑ eps j}
    β†’ F.F₁ (lim.universal eps p) ≑ F-lim.universal (Ξ» j β†’ F.F₁ (eps j)) (Ξ» f β†’ F.collapse (p f))
  universal = F-lim.unique _ _ _ (Ξ» j β†’ F.collapse (lim.factors _ _))

module _ {J : Precategory o₁ h₁} {C : Precategory oβ‚‚ hβ‚‚} {D : Precategory o₃ h₃}
         {F F' : Functor C D} {Dia : Functor J C} where

  private
    module D = Cat.Reasoning D
    open Func
    open _=>_

  natural-iso→preserves-limits
    : F ≅ⁿ F'
    β†’ preserves-limit F Dia
    β†’ preserves-limit F' Dia
  natural-iso→preserves-limits α F-preserves {K = K} {eps} lim =
    natural-isos→is-ran
      idni (Ξ± β—‚ni Dia) (Ξ± β—‚ni K)
        (ext Ξ» j β†’
          Ξ±.to .Ξ· _ D.∘ (F .F₁ (eps .Ξ· j) D.∘ ⌜ F .F₁ (K .F₁ tt) D.∘ Ξ±.from .Ξ· _ ⌝) β‰‘βŸ¨ ap! (eliml F (K .F-id)) βŸ©β‰‘
          Ξ±.to .Ξ· _ D.∘ (F .F₁ (eps .Ξ· j) D.∘ Ξ±.from .Ξ· _)                          β‰‘βŸ¨ D.pushr (sym (Ξ±.from .is-natural _ _ _)) βŸ©β‰‘
          (Ξ±.to .Ξ· _ D.∘ Ξ±.from .Ξ· _) D.∘ F' .F₁ (eps .Ξ· j)                         β‰‘βŸ¨ D.eliml (Ξ±.invl Ξ·β‚š _) βŸ©β‰‘
          F' .F₁ (eps .Ξ· j)                                                         ∎)
        (F-preserves lim)
    where
      module α = Isoⁿ α

ContinuityπŸ”—

is-continuous
  : βˆ€ (oshape hshape : Level)
      {C : Precategory o₁ h₁}
      {D : Precategory oβ‚‚ hβ‚‚}
  β†’ Functor C D β†’ Type _

A continuous functor is one that β€” for every shape of diagram J, and every diagram diagram of shape J in C β€” preserves the limit for that diagram.

is-continuous oshape hshape {C = C} F =
  βˆ€ {J : Precategory oshape hshape} {Diagram : Functor J C}
  β†’ preserves-limit F Diagram

CompletenessπŸ”—

A category is complete if it admits limits for diagrams of arbitrary shape. However, in the presence of excluded middle, if a category admits products indexed by its class of morphisms, then it is automatically a poset. Since excluded middle is independent of type theory, we can not prove that any non-thin categories have arbitrary limits.

Instead, categories are complete with respect to a pair of universes: A category is if it has limits for any diagram indexed by a precategory with objects in and morphisms in

is-complete : βˆ€ {oc β„“c} o β„“ β†’ Precategory oc β„“c β†’ Type _
is-complete oj β„“j C = βˆ€ {J : Precategory oj β„“j} (F : Functor J C) β†’ Limit F

While this condition might sound very strong, and thus that it would be hard to come by, it turns out we can get away with only two fundamental types of limits: products and equalisers. In order to construct the limit for a diagram of shape we will require products indexed by type of objects and by its type of morphisms.

  limit-as-equaliser-of-product
    : βˆ€ {oj β„“j} {J : Precategory oj β„“j}
    β†’ has-products-indexed-by C ⌞ J ⌟
    β†’ has-products-indexed-by C (Arrows J)
    β†’ has-equalisers C
    β†’ (F : Functor J C) β†’ Limit F
  limit-as-equaliser-of-product {oj} {β„“j} {J} has-Ob-prod has-Arrows-prod has-eq F =
    to-limit (to-is-limit lim) where

Given a diagram we start by building the product of all the objects appearing in the diagram.

    Obs : Indexed-product C Ξ» o β†’ Fβ‚€ o
    Obs = has-Ob-prod _

Our limit will arise as a subobject of this product-of-objects, namely the equaliser of two carefully chosen morphisms.

As a guiding example, the pullback of and should be the subobject of consisting of triples such that In full generality, for each arrow in our diagram, we should have that projecting out the component of our product should give the same result as projecting out the component and postcomposing with

This suggests to build another indexed product of all the codomains of arrows in the diagram, taking the first morphism to be the projection of the codomain and the second morphism to be the projection of the domain postcomposed with

    Cod : Indexed-product C {Idx = Arrows J} Ξ» (a , b , f) β†’ Fβ‚€ b
    Cod = has-Arrows-prod _

    s t : C.Hom (Obs .Ξ F) (Cod .Ξ F)
    s = Cod .tuple Ξ» (a , b , f) β†’ F₁ f C.∘ Obs .Ο€ a
    t = Cod .tuple Ξ» (a , b , f) β†’ Obs .Ο€ b

    eq : Equaliser C s t
    eq = has-eq _ _

    lim : make-is-limit F (eq .apex)
The rest of the proof amounts to repackaging the data of the equaliser and products as the data for a limit.
    lim .ψ c = Obs .Ο€ c C.∘ eq .equ
    lim .commutes {a} {b} f =
      F₁ f C.∘ Obs .Ο€ a C.∘ eq .equ            β‰‘Λ˜βŸ¨ C.extendl (Cod .commute) βŸ©β‰‘Λ˜
      Cod .Ο€ (a , b , f) C.∘ ⌜ s C.∘ eq .equ ⌝ β‰‘βŸ¨ ap! (eq .equal) βŸ©β‰‘
      Cod .Ο€ (a , b , f) C.∘ t C.∘ eq .equ     β‰‘βŸ¨ C.pulll (Cod .commute) βŸ©β‰‘
      Obs .Ο€ b C.∘ eq .equ                     ∎
    lim .universal {x} e comm = eq .universal comm' where
      e' : C.Hom x (Obs .Ξ F)
      e' = Obs .tuple e
      comm' : s C.∘ e' ≑ t C.∘ e'
      comm' = Indexed-product.uniqueβ‚‚ Cod Ξ» i@(a , b , f) β†’
        Cod .Ο€ i C.∘ s C.∘ e'        β‰‘βŸ¨ C.extendl (Cod .commute) βŸ©β‰‘
        F₁ f C.∘ ⌜ Obs .Ο€ a C.∘ e' ⌝ β‰‘βŸ¨ ap! (Obs .commute) βŸ©β‰‘
        F₁ f C.∘ e a                 β‰‘βŸ¨ comm f βŸ©β‰‘
        e b                          β‰‘Λ˜βŸ¨ Obs .commute βŸ©β‰‘Λ˜
        Obs .Ο€ b C.∘ e'              β‰‘Λ˜βŸ¨ C.pulll (Cod .commute) βŸ©β‰‘Λ˜
        Cod .Ο€ i C.∘ t C.∘ e'        ∎
    lim .factors {j} e comm =
      (Obs .Ο€ j C.∘ eq .equ) C.∘ lim .universal e comm β‰‘βŸ¨ C.pullr (eq .factors) βŸ©β‰‘
      Obs .Ο€ j C.∘ Obs .tuple e                        β‰‘βŸ¨ Obs .commute βŸ©β‰‘
      e j                                              ∎
    lim .unique e comm u' fac = eq .unique $ Obs .unique _
      Ξ» i β†’ C.assoc _ _ _ βˆ™ fac i

This implies that a category with equalisers and large enough indexed products has all limits.

  products+equalisers→complete
    : βˆ€ {oj β„“j}
    β†’ has-indexed-products C (oj βŠ” β„“j)
    β†’ has-equalisers C
    β†’ is-complete oj β„“j C
  products+equalisers→complete {oj} {ℓj} has-prod has-eq =
    limit-as-equaliser-of-product
      (Ξ» _ β†’ Lift-Indexed-product C β„“j (has-prod _))
      (Ξ» _ β†’ has-prod _)
      has-eq