module Cat.Functor.Base where

Functor precategoriesπŸ”—

Fix a pair of (completely arbitrary!) precategories C\mathcal{C} and D\mathcal{D}. We’ll show how to make the type of functors Cβ†’D\mathcal{C} \to \mathcal{D} into a precategory on its own right, with the natural transformations Fβ‡’GF \Rightarrow G as the morphisms. First, given F:Cβ†’DF : \mathcal{C} \to \mathcal{D}, we construct the identity natural transformation by having every component be the identity:

  idnt : {F : Functor C D} β†’ F => F
  idnt .Ξ· _              = D.id
  idnt .is-natural _ _ _ = D.id-comm-sym

Moreover, if we have a pair of composable-looking natural transformations α:G⇒H\alpha : G \Rightarrow H and β:F⇒G\beta : F \Rightarrow G, then we can indeed make their pointwise composite into a natural transformation:

  _∘nt_ : βˆ€ {F G H : Functor C D} β†’ G => H β†’ F => G β†’ F => H
  (f ∘nt g) .η x = f .η x D.∘ g .η x
  _∘nt_ {F} {G} {H} f g .is-natural x y h =
    (f .Ξ· y D.∘ g .Ξ· y) D.∘ F .F₁ h β‰‘βŸ¨ D.pullr (g .is-natural x y h) ⟩
    f .Ξ· y D.∘ G .F₁ h D.∘ g .Ξ· x   β‰‘βŸ¨ D.extendl (f .is-natural x y h) ⟩
    H .F₁ h D.∘ f .Ξ· x D.∘ g .Ξ· x   ∎

  infixr 40 _∘nt_

Since we already know that identity of natural transformations is determined by identity of the underlying family of morphisms, and the identities and composition we’ve just defined are componentwise just identity and composition in D\mathcal{D}, then the category laws we have to prove are, once again, those of D\mathcal{D}:

Cat[_,_]
  : Precategory o β„“ β†’ Precategory o₁ ℓ₁
  β†’ Precategory (o βŠ” β„“ βŠ” o₁ βŠ” ℓ₁) (o βŠ” β„“ βŠ” ℓ₁)
Cat[ C , D ] .Pc.Ob          = Functor C D
Cat[ C , D ] .Pc.Hom         = _=>_
Cat[ C , D ] .Pc.Hom-set F G = Nat-is-set

Cat[ C , D ] .Pc.id  = idnt
Cat[ C , D ] .Pc._∘_ = _∘nt_

Cat[ C , D ] .Pc.idr f       = ext Ξ» x β†’ Pc.idr D _
Cat[ C , D ] .Pc.idl f       = ext Ξ» x β†’ Pc.idl D _
Cat[ C , D ] .Pc.assoc f g h = ext Ξ» x β†’ Pc.assoc D _ _ _

We’ll also need the following foundational tool, characterising paths between functors. It says that, given a homotopy p0p_0 between the object-parts of functors F,G:Cβ†’DF, G : \mathcal{C} \to \mathcal{D}, and, over this, an identification between the actions of FF and GG on morphisms, we can construct a path F≑GF \equiv G.

Paths between functorsπŸ”—

Functor-path
  : {F G : Functor C D}
  β†’ (p0 : βˆ€ x β†’ Fβ‚€ F x ≑ Fβ‚€ G x)
  β†’ (p1 : βˆ€ {x y} (f : C .Pc.Hom x y)
        β†’ PathP (Ξ» i β†’ D .Pc.Hom (p0 x i) (p0 y i)) (F .F₁ f) (G .F₁ f))
  β†’ F ≑ G

Note that this lemma is a bit unusual: we’re characterising the identity type of the objects of a precategory, rather than, as is more common, the morphisms of a precategory. However, this characterisation will let us swiftly establish necessary conditions for univalence of functor categories.

Action on isomorphismsπŸ”—

We have also to make note of the following fact: absolutely all functors preserve isomorphisms, and, more generally, preserve invertibility.

  F-map-iso : βˆ€ {x y} (F : Functor C D) β†’ x C.β‰… y β†’ Fβ‚€ F x D.β‰… Fβ‚€ F y
  F-map-iso F x .to       = F .F₁ (x .to)
  F-map-iso F x .from     = F .F₁ (x .from)
  F-map-iso F x .inverses =
    record { invl = sym (F .F-∘ _ _) βˆ™ ap (F .F₁) (x .invl) βˆ™ F .F-id
           ; invr = sym (F .F-∘ _ _) βˆ™ ap (F .F₁) (x .invr) βˆ™ F .F-id
           }
    where module x = C._β‰…_ x

  F-map-invertible : βˆ€ {x y} (F : Functor C D) {f : C.Hom x y} β†’ C.is-invertible f β†’ D.is-invertible (F₁ F f)
  F-map-invertible F inv =
    D.make-invertible (F₁ F _)
      (sym (F-∘ F _ _) Β·Β· ap (F₁ F) x.invl Β·Β· F-id F)
      (sym (F-∘ F _ _) Β·Β· ap (F₁ F) x.invr Β·Β· F-id F)
    where module x = C.is-invertible inv

If the categories the functor maps between are univalent, there is a competing notion of preserving isomorphisms: the action on paths of the object-part of the functor. We first turn the isomorphism into a path (using univalence of the domain), run it through the functor, then turn the resulting path back into an isomorphism. Fortunately, functors are already coherent enough to ensure that these actions agree:

  F-map-path
    : (ccat : is-category C) (dcat : is-category D)
    β†’ βˆ€ (F : Functor C D) {x y} (i : x C.β‰… y)
    β†’ ap (Fβ‚€ F) (Univalent.isoβ†’path ccat i) ≑ Univalent.isoβ†’path dcat (F-map-iso F i)
  F-map-path ccat dcat F {x} = Univalent.J-iso ccat P pr where
    P : (b : C.Ob) β†’ C.Isomorphism x b β†’ Type _
    P b im = ap (F₀ F) (Univalent.iso→path ccat im)
           ≑ Univalent.isoβ†’path dcat (F-map-iso F im)

    pr : P x C.id-iso
    pr =
      ap (Fβ‚€ F) (Univalent.isoβ†’path ccat C.id-iso) β‰‘βŸ¨ ap (ap (Fβ‚€ F)) (Univalent.isoβ†’path-id ccat) ⟩
      ap (Fβ‚€ F) refl                               β‰‘Λ˜βŸ¨ Univalent.isoβ†’path-id dcat ⟩
      dcat .to-path D.id-iso                       β‰‘βŸ¨ ap (dcat .to-path) (D.β‰…-path (sym (F .F-id))) ⟩
      dcat .to-path (F-map-iso F C.id-iso)         ∎

Presheaf precategoriesπŸ”—

Of principal importance among the functor categories are those to the category Sets\mathbf{Sets}: these are the presheaf categories.

PSh : βˆ€ ΞΊ {o β„“} β†’ Precategory o β„“ β†’ Precategory _ _
PSh ΞΊ C = Cat[ C ^op , Sets ΞΊ ]