module Cat.Functor.Hom.Representable {o ΞΊ} {C : Precategory o ΞΊ} where

Representable functorsπŸ”—

A functor F:Copβ†’SetsΞΊF : \mathcal{C}^{\mathrm{op}} \to \mathbf{Sets}_\kappa (from a locally ΞΊ\kappa-small category) is said to be representable when it is naturally isomorphic to Hom(βˆ’,X)\mathbf{Hom}(-, X) for an object X:CX : \mathcal{C} (called the representing object) β€” that is, the functor FF classifies the maps into XX. Note that we can evidently dualise the definition, to get what is called a corepresentable functor, one of the form Hom(X,βˆ’)\mathbf{Hom}(X, -), but we refer informally to both of these situations as β€œrepresentables” and β€œrepresenting objects”.

record Representation (F : Functor (C ^op) (Sets ΞΊ)) : Type (o βŠ” ΞΊ) where
    rep        : C.Ob
    represents : natural-iso F (Hom-into C rep)

  module rep = natural-iso represents

  equiv : βˆ€ {a} β†’ C.Hom a rep ≃ ∣ F .Fβ‚€ a ∣
  equiv = Iso→Equiv λ where
    .fst                β†’ rep.from .Ξ· _
    .snd .is-iso.inv    β†’ .Ξ· _
    .snd .is-iso.rinv x β†’ rep.invr Ξ·β‚š _ $β‚š x
    .snd .is-iso.linv x β†’ rep.invl Ξ·β‚š _ $β‚š x

  module Rep {a} = Equiv (equiv {a})

open Representation
open Representation using (module Rep) public

This definition is deceptively simple: the idea of representable functor (and of representing object) is key to understanding the idea of universal property, which could be called the most important concept in category theory. Most constructions in category theory specified in terms of the existence of certain maps are really instances of representing objects for functors: limits, colimits, coends, adjoint functors, Kan extensions, etc.

The first thing we will observe is an immediate consequence of the Yoneda lemma: representing objects are unique. Intuitively this is because β€œXX is a representation of FF” determines how XX reacts to being mapped into, and since the only thing we can probe objects in an arbitrary category by are morphisms, two objects which react to morphisms in the same way must be isomorphic.

representation-unique : {F : Functor (C ^op) (Sets ΞΊ)} (X Y : Representation F)
                      β†’ X .rep C.β‰… Y .rep
representation-unique X Y =
  is-ffβ†’essentially-injective {F = γ‚ˆ C} (γ‚ˆ-is-fully-faithful C) γ‚ˆXβ‰…γ‚ˆY where
    γ‚ˆXβ‰…γ‚ˆY : γ‚ˆβ‚€ C (X .rep) C^.β‰… γ‚ˆβ‚€ C (Y .rep)
    γ‚ˆXβ‰…γ‚ˆY = (X .represents C^.Iso⁻¹) C^.∘Iso Y .represents

Therefore, if C\mathcal{C} is a univalent category, then the type of representations for a functor FF is a proposition. This does not follow immediately from the lemma above: we also need to show that the isomorphism computed by the full-faithfulness of the Yoneda embedding commutes with the specified representation isomorphism. This follows by construction, but the proof needs to commute

applications of functors and paths-from-isos, which is never pretty:

Representation-is-prop : βˆ€ {F} β†’ is-category C β†’ is-prop (Representation F)
Representation-is-prop {F = F} c-cat x y = path where
  module X = Representation x
  module Y = Representation y

  objs : X.rep ≑ Y.rep
  objs = c-cat .to-path (representation-unique x y)

  path : x ≑ y
  path i .rep = objs i
  path i .represents =
    C^.β‰…-pathp refl (ap (γ‚ˆβ‚€ C) objs) {f = X.represents} {g = Y.represents}
      (Nat-pathp _ _ Ξ» a β†’ Hom-pathp-reflr (Sets _)
        {A = F .Fβ‚€ a} {q = Ξ» i β†’ el! (C.Hom a (objs i))}
        (funext Ξ» x β†’
           ap (Ξ» e β†’ e (ap-Fβ‚€-iso c-cat (Hom-from C a) _) $β‚š _
        Β·Β· sym ( .is-natural _ _ _) $β‚š _
        Β·Β· ap Y.Rep.from (sym (X.rep.from .is-natural _ _ _ $β‚š _)
                       Β·Β· ap (C.idl _)
                       Β·Β· X.Rep.Ξ΅ _)))

As terminal objectsπŸ”—

We begin to connect the idea of representing objects to other universal constructions by proving this alternative characterisation of representations: A functor FF is representable if, and only if, its category of elements ∫F\int F has a terminal object.

  : {F : Functor (C ^op) (Sets ΞΊ)} β†’ Terminal (∫ C F) β†’ Representation F
terminal-element→representation {F} term = f-rep where
  module F = Functor F
  open Terminal term

From the terminal object in ∫F\int F1, we obtain a natural transformation Ξ·y:F(y)β†’Hom(y,X)\eta_y : F(y) \to \mathbf{Hom}(y,X), given componentwise by interpreting each pair (y,s)(y, s) as an object of ∫F\int F, then taking the terminating morphism (y,s)β†’(X,F(X))(y, s) \to (X, F(X)), which satisfies (by definition) F(!)(F(X))=sF(!)(F(X)) = s. This natural transformation is componentwise invertible, as the calculation below shows, so it constitutes a natural isomorphism.

  nat : F => γ‚ˆβ‚€ C (top .ob)
  nat .η ob section = has⊀ (elem ob section) .centre .hom
  nat .is-natural x y f = funext Ξ» sect β†’ ap hom $ has⊀ _ .paths $ elem-hom _ $
    F.₁ (has⊀ _ .centre .hom C.∘ f) (top .section)   β‰‘βŸ¨ happly (F.F-∘ _ _) _ βŸ©β‰‘
    F.₁ f (F.₁ (has⊀ _ .centre .hom) (top .section)) β‰‘βŸ¨ ap (F.₁ f) (has⊀ _ .centre .commute) βŸ©β‰‘
    F.₁ f sect                                       ∎

  inv : βˆ€ x β†’ (nat .Ξ· x)
  inv x = Sets.make-invertible
    (Ξ» f β†’ F.₁ f (top .section))
    (funext Ξ» x β†’ ap hom $ has⊀ _ .paths (elem-hom x refl))
    (funext Ξ» x β†’ has⊀ _ .centre .commute)

  f-rep : Representation F
  f-rep .rep = top .ob
  f-rep .represents = C^.invertible→iso nat $
    componentwise-invertible→invertible nat inv

Universal constructionsπŸ”—

We now show a partial converse to the calculation above: That terminal objects are representing objects for a particular functor. Consider, to be more specific, the constant functor F:Cop→SetsF : \mathcal{C}^{\mathrm{op}} \to \mathbf{Sets} which sends everything to the terminal set. When is FF representable?

Well, unfolding the definition, it’s when we have an object X:CX : \mathcal{C} with a natural isomorphism Hom(βˆ’,X)β‰…F\mathbf{Hom}(-,X) \cong F. Unfolding that, it’s an object XX for which, given any other object YY, we have an isomorphism of sets Hom(Y,X)β‰…{βˆ—}\mathbf{Hom}(Y,X) \cong \{*\}2. Hence, a representing object for the β€œconstantly {βˆ—}\{*\}” functor is precisely a terminal object. It turns out the

  : Representation (Const (el (Lift _ ⊀) (hlevel 2))) β†’ Terminal C
representable-unit→terminal repr = repr .rep
representable-unitβ†’terminal repr .Terminal.has⊀ ob = retractβ†’is-contr
  (Rep.from repr) (Ξ» _ β†’ lift tt) (Rep.Ξ· repr) (hlevel 0)

Corepresentable functorsπŸ”—

As noted earlier, we can dualise the definition of a representable functor to the covariant setting to get corepresentable functors.

record Corepresentation (F : Functor C (Sets ΞΊ)) : Type (o βŠ” ΞΊ) where
    corep : C.Ob
    corepresents : natural-iso F (Hom-from C corep)

  module corep = natural-iso corepresents

  coequiv : βˆ€ {a} β†’ C.Hom corep a ≃ ∣ F .Fβ‚€ a ∣
  coequiv = Iso→Equiv λ where
    .fst β†’ corep.from .Ξ· _
    .snd .is-iso.inv β†’ .Ξ· _
    .snd .is-iso.rinv x β†’ corep.invr Ξ·β‚š _ $β‚š x
    .snd .is-iso.linv x β†’ corep.invl Ξ·β‚š _ $β‚š x

  module Corep {a} = Equiv (coequiv {a})

open Corepresentation
open Corepresentation using (module Corep) public

Much like their contravariant cousins, corepresenting objects are unique up to isomorphism.

  : {F : Functor C (Sets ΞΊ)} (X Y : Corepresentation F)
  β†’ X .corep C.β‰… Y .corep
We omit the proof, as it is identical to the representable case.
corepresentation-unique X Y =
  is-ffβ†’essentially-injective {F = Functor.op (γ‚ˆcov C)}
    (γ‚ˆcov-is-fully-faithful C)
    (iso→co-iso (Cat[ C , Sets κ ]) ni)
    ni : natural-iso (Hom-from C (Y .corep)) (Hom-from C (X .corep))
    ni = (Y .corepresents ni⁻¹) ni∘ X .corepresents

This implies that the type of corepresentations is a proposition when C\mathcal{C} is univalent.

Corepresentation-is-prop : βˆ€ {F} β†’ is-category C β†’ is-prop (Corepresentation F)
We opt to not show the proof, as it is even nastier than the proof for representables due to the fact that the yoneda embedding for covariant functors is itself contravariant.
Corepresentation-is-prop {F = F} c-cat X Y = path where

  objs : X .corep ≑ Y .corep
  objs = c-cat .to-path (corepresentation-unique X Y)

  path : X ≑ Y
  path i .corep = objs i
  path i .corepresents =
    [C,Sets].β‰…-pathp refl (ap (Hom-from C) objs)
       {f = X .corepresents} {g = Y .corepresents}
       (Nat-pathp _ _ Ξ» a β†’ Hom-pathp-reflr (Sets _)
         {A = F .Fβ‚€ a} {q = Ξ» i β†’ el! (C.Hom (objs i) a)}
         (funext Ξ» x β†’
           ap (Ξ» e β†’ e (ap-Fβ‚€-iso (opposite-is-category c-cat) (Hom-into C a) _) $β‚š _
           Β·Β· sym ( Y .is-natural _ _ _ $β‚š _)
           Β·Β· ap (Corep.from Y) (sym (corep.from X .is-natural _ _ _ $β‚š _)
                                 Β·Β· ap ( X) (C.idr _)
                                 Β·Β· Corep.Ξ΅ X _)))

Corepresentable functors preserve limitsπŸ”—

A useful fact about corepresentable functors is that they preserve all limits. To show this, we first need to show that the covariant hom functor C(x,βˆ’)\mathcal{C}(x,-) preserves limits.

To get an intuition for why this is true, consider how the functor C(x,βˆ’)\mathcal{C}(x,-) behaves on products. The set of morphisms C(x,aΓ—b)\mathcal{C}(x,a \times b) is equivalent to the set C(x,a)Γ—C(x,b)\mathcal{C}(x, a) \times \mathcal{C}(x, b) of pairs of morphisms (See product-repr for a proof of this equivalence).

  : βˆ€ {oβ€² ΞΊβ€²}
  β†’ (c : C.Ob)
  β†’ is-continuous oβ€² ΞΊβ€² (Hom-from C c)
Hom-from-preserves-limits c {Diagram = Dia} {K} {eps} lim =
  to-is-limitp ml (funext Ξ» _ β†’ refl) where
  open make-is-limit
  module lim = is-limit lim

  ml : make-is-limit _ _
  ml .ψ j f = lim.ψ j C.∘ f
  ml .commutes f = funext Ξ» g β†’
    C.pulll (sym (eps .is-natural _ _ _))
    βˆ™ (C.elimr (K .F-id) C.⟩∘⟨refl)
  ml .universal eta p x =
    lim.universal (Ξ» j β†’ eta j x) (Ξ» f β†’ p f $β‚š x)
  ml .factors _ _ = funext Ξ» _ β†’
    lim.factors _ _
  ml .unique eps p other q = funext Ξ» x β†’
    lim.unique _ _ _ Ξ» j β†’ q j $β‚š x

Preservation of limits by corepresentable functors then follows from a general fact about functors: if FF preserves limits, and FF is naturally isomorphic to Fβ€²F', then Fβ€²F' must also preserve limits.

  : βˆ€ {oβ€² ΞΊβ€²} {F}
  β†’ Corepresentation F
  β†’ is-continuous oβ€² ΞΊβ€² F
corepresentable-preserves-limits F-corep lim =
     (F-corep .corepresents ni⁻¹)
     (Hom-from-preserves-limits (F-corep .corep))

We can show a similar fact for representable functors, but with a twist: they reverse colimits! This is due to the fact that a representable functor F:Cop→SetsF : \mathcal{C}^{\mathrm{op}} \to \mathbf{Sets} is contravariant. Specifically, FF will take limits in Cop\mathcal{C}^{\mathrm{op}} to limits in Sets\mathbf{Sets}, but limits in Cop\mathcal{C}^{\mathrm{op}} are colimits, so FF will take colimits in C\mathcal{C} to limits in Sets\mathbf{Sets}.

A less formal perspective on this is that the collection of maps out of a colimit is still defined as a limit in Sets\mathbf{Sets}. For instance, to give a a+b→xa + b \to x out of a coproduct, we are required to give a pair of maps a→xa \to x and b→xb \to x.

  : βˆ€ {oβ€² ΞΊβ€²}
  β†’ (c : C.Ob)
  β†’ is-cocontinuous oβ€² ΞΊβ€² (Functor.op (γ‚ˆβ‚€ C c))
γ‚ˆ-reverses-colimits c {Diagram = Dia} {K} {eta} colim =
  to-is-colimitp mc (funext Ξ» _ β†’ refl) where
  open make-is-colimit
  module colim = is-colimit colim

  mc : make-is-colimit _ _
  mc .ψ j f = f C.∘ colim.ψ j
  mc .commutes f = funext Ξ» g β†’
    C.pullr (eta .is-natural _ _ _)
    βˆ™ (C.refl⟩∘⟨ C.eliml (K .F-id))
  mc .universal eps p x =
    colim.universal (Ξ» j β†’ eps j x) (Ξ» f β†’ p f $β‚š x)
  mc .factors eps p = funext Ξ» _ β†’
    colim.factors _ _
  mc .unique eps p other q = funext Ξ» x β†’
    colim.unique _ _ _ Ξ» j β†’ q j $β‚š x

  : βˆ€ {oβ€² ΞΊβ€²} {F}
  β†’ Representation F
  β†’ is-cocontinuous oβ€² ΞΊβ€² (Functor.op F)
representable-reverses-colimits F-rep colim =
    ((F-rep .represents ni^op) ni⁻¹)
    (γ‚ˆ-reverses-colimits (F-rep .rep))

  1. Which, recall, consists of an object X:CX : \mathcal{C} and a section F(X):SetsF(X) : \mathbf{Sets}β†©οΈŽ

  2. which varies naturally in YY, but this naturality is not used in this simple caseβ†©οΈŽ