module Cat.Functor.Base where

Functor precategoriesπŸ”—

Fix a pair of (completely arbitrary!) precategories and We’ll show how to make the type of functors into a precategory on its own right, with the natural transformations as the morphisms. First, given 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 and 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 then the category laws we have to prove are, once again, those of

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 between the object-parts of functors and, over this, an identification between the actions of and on morphisms, we can construct a path

Paths between functorsπŸ”—

Functor-path
  : {F G : Functor C D}
  β†’ (p0 : βˆ€ x β†’ F .Fβ‚€ x ≑ G .Fβ‚€ 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.

Functor-pathp
  : {C : I β†’ Precategory o β„“} {D : I β†’ Precategory o₁ ℓ₁}
    {F : Functor (C i0) (D i0)} {G : Functor (C i1) (D i1)}
  β†’ (p0 : βˆ€ (p : βˆ€ i β†’ C i .Pc.Ob) β†’ PathP (Ξ» i β†’ D i .Pc.Ob) (F .Fβ‚€ (p i0)) (G .Fβ‚€ (p i1)))
  β†’ (p1 : βˆ€ {x y : βˆ€ i β†’ _}
        β†’ (r : βˆ€ i β†’ C i .Pc.Hom (x i) (y i))
        β†’ PathP (Ξ» i β†’ D i .Pc.Hom (p0 x i) (p0 y i))
                (F .F₁ (r i0)) (G .F₁ (r i1)))
  β†’ PathP (Ξ» i β†’ Functor (C i) (D i)) F G
Functor-pathp {C = C} {D} {F} {G} p0 p1 = fn where
  open Pc
  cob : I β†’ Type _
  cob = Ξ» i β†’ C i .Ob

  exth
    : βˆ€ i j (x y : C i .Ob) (f : C i .Hom x y)
    β†’ C i .Hom (coe cob i i x) (coe cob i i y)
  exth i j x y f =
    comp (Ξ» j β†’ C i .Hom (coeiβ†’i cob i x (~ j ∨ i)) (coeiβ†’i cob i y (~ j ∨ i)))
    ((~ i ∧ ~ j) ∨ (i ∧ j))
    Ξ» where
      k (k = i0) β†’ f
      k (i = i0) (j = i0) β†’ f
      k (i = i1) (j = i1) β†’ f

  actm
    : βˆ€ i (x y : C i .Ob) f
    β†’ D i .Hom (p0 (Ξ» j β†’ coe cob i j x) i) (p0 (Ξ» j β†’ coe cob i j y) i)
  actm i x y f =
    p1 {Ξ» j β†’ coe cob i j x} {Ξ» j β†’ coe cob i j y}
      (Ξ» j β†’ coe (Ξ» j β†’ C j .Hom (coe cob i j x) (coe cob i j y)) i j (exth i j x y f))
      i

  fn : PathP (Ξ» i β†’ Functor (C i) (D i)) F G
  fn i .Fβ‚€ x =
    p0 (Ξ» j β†’ coe cob i j x)
      i
  fn i .F₁ {x} {y} f = actm i x y f
  fn i .F-id {x} =
    hcomp (βˆ‚ i) Ξ» where
      j (i = i0) β†’ D i .Hom-set (F .Fβ‚€ x) (F .Fβ‚€ x) (F .F₁ (C i .id)) (D i .id) base (F .F-id) j
      j (i = i1) β†’ D i .Hom-set (G .Fβ‚€ x) (G .Fβ‚€ x) (G .F₁ (C i .id)) (D i .id) base (G .F-id) j
      j (j = i0) β†’ base
    where
      base = coe0β†’i (Ξ» i β†’ (x : C i .Ob) β†’ actm i x x (C i .id) ≑ D i .id) i
        (Ξ» _ β†’ F .F-id) x
  fn i .F-∘ {x} {y} {z} f g =
    hcomp (βˆ‚ i) Ξ» where
      j (i = i0) β†’ D i .Hom-set (F .Fβ‚€ x) (F .Fβ‚€ z) _ _ base (F .F-∘ f g) j
      j (i = i1) β†’ D i .Hom-set (G .Fβ‚€ x) (G .Fβ‚€ z) _ _ base (G .F-∘ f g) j
      j (j = i0) β†’ base
    where
      base = coe0β†’i (Ξ» i β†’ (x y z : C i .Ob) (f : C i .Hom y z) (g : C i .Hom x y)
                         β†’ actm i x z (C i ._∘_ f g)
                         ≑ D i ._∘_ (actm i y z f) (actm i x y g)) i
        (Ξ» _ _ _ β†’ F .F-∘) x y z f g

Functor-path p0 p1 i .Fβ‚€ x = p0 x i
Functor-path p0 p1 i .F₁ f = p1 f i
Functor-path {C = C} {D = D} {F = F} {G = G} p0 p1 i .F-id =
  is-prop→pathp (λ j → D .Pc.Hom-set _ _ (p1 (C .Pc.id) j) (D .Pc.id))
    (F .F-id) (G .F-id) i
Functor-path {C = C} {D = D} {F = F} {G = G} p0 p1 i .F-∘ f g =
  is-propβ†’pathp (Ξ» i β†’ D .Pc.Hom-set _ _ (p1 (C .Pc._∘_ f g) i) (D .Pc._∘_ (p1 f i) (p1 g i)))
    (F .F-∘ f g) (G .F-∘ f g) i

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} β†’ x C.β‰… y β†’ F # x D.β‰… F # y
  F-map-iso x .to       = F .F₁ (x .to)
  F-map-iso x .from     = F .F₁ (x .from)
  F-map-iso 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 : C.Hom x y} β†’ C.is-invertible f β†’ D.is-invertible (F .F₁ f)
  F-map-invertible inv =
    D.make-invertible (F .F₁ _)
      (sym (F .F-∘ _ _) Β·Β· ap (F .F₁) x.invl Β·Β· F .F-id)
      (sym (F .F-∘ _ _) Β·Β· ap (F .F₁) x.invr Β·Β· F .F-id)
    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)
    β†’ βˆ€ {x y} (i : x C.β‰… y)
    β†’ ap# F (Univalent.isoβ†’path ccat i) ≑ Univalent.isoβ†’path dcat (F-map-iso i)
  F-map-path ccat dcat {x} = Univalent.J-iso ccat P pr where
    P : (b : C.Ob) β†’ C.Isomorphism x b β†’ Type _
    P b im = ap# F (Univalent.iso→path ccat im)
           ≑ Univalent.isoβ†’path dcat (F-map-iso im)

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

Presheaf precategoriesπŸ”—

Of principal importance among the functor categories are those to the category these are the presheaf categories.

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