open import Cat.Instances.Product open import Cat.Univalent using (is-category) open import Cat.Prelude import Cat.Reasoning open Precategory open Functor open _=>_ module Cat.Instances.Functor where private variable o h oβ hβ oβ hβ : Level C D E : Precategory o h F G : Functor C D
Functor (pre)categoriesπ
By assigning the identity morphism to every object in , we get a natural transformation between and itself.
idnt : {F : Functor C D} β F => F idnt {C = C} {D = D} .Ξ· x = D .id idnt {C = C} {D = D} .is-natural x y f = D .idl _ β sym (D .idr _)
Given two natural transformations and , we can show that the assignment of βcomponentwise compositionsβ defines a natural transformation , which serves as the composite of and .
_βnt_ : {F G H : Functor C D} β G => H β F => G β F => H _βnt_ {C = C} {D = D} {F} {G} {H} f g = nat where module D = Precategory D nat : F => H nat .Ξ· x = f .Ξ· _ D.β g .Ξ· _
We can then show that these definitions assemble into a category where the objects are functors , and the morphisms are natural transformations . This is because natural transformations inherit the identity and associativity laws from the codomain category , and since hom-sets are sets, is-natural does not matter.
module _ {oβ hβ oβ hβ} (C : Precategory oβ hβ) (D : Precategory oβ hβ) where open Precategory Cat[_,_] : Precategory (oβ β oβ β hβ β hβ) (oβ β hβ β hβ) Cat[_,_] .Ob = Functor C D Cat[_,_] .Hom F G = F => G Cat[_,_] .id = idnt Cat[_,_] ._β_ = _βnt_
All of the properties that make up a Precategory follow from the characterisation of equalities in natural transformations: They are a set, and equality of the components determines equality of the transformation.
Cat[_,_] .Hom-set F G = Nat-is-set Cat[_,_] .idr f = Nat-path Ξ» x β D .idr _ Cat[_,_] .idl f = Nat-path Ξ» x β D .idl _ Cat[_,_] .assoc f g h = Nat-path Ξ» x β D .assoc _ _ _
Before moving on, we prove the following lemma which characterises equality in Functor (between definitionally equal categories). Given an identification between the object mappings, and an identification of morphism parts that lies over , we can identify the functors .
Functor-path : {F G : Functor C D} β (p0 : β x β Fβ F x β‘ Fβ G x) β (p1 : β {x y} (f : C .Hom x y) β PathP (Ξ» i β D .Hom (p0 x i) (p0 y i)) (Fβ F f) (Fβ G f)) β F β‘ G Functor-path p0 p1 i .Fβ x = p0 x i Functor-path p0 p1 i .Fβ f = p1 f i
Functor categoriesπ
When the codomain category is univalent, then so is the category of functors . Essentially, this can be read as saying that βnaturally isomorphic functors are identifiedβ. We begin by proving that the components of a natural isomorphism (a natural transformation with natural inverse) are themselves isomorphisms in .
Nat-isoβIso : F [C,D].β G β β x β Fβ F x D.β Fβ G x Nat-isoβIso natiso x = D.make-iso (to .Ξ· x) (from .Ξ· x) (Ξ» i β invl i .Ξ· x) (Ξ» i β invr i .Ξ· x) where open [C,D]._β _ natiso
We can now prove that is a category, by showing that, for a fixed functor , the space of functors equipped with natural isomorphisms is contractible. The centre of contraction is the straightforward part: We have the canonical choice of .
Functor-is-category : is-category D β is-category Cat[ C , D ] Functor-is-category _ F .centre = F , id-iso
The hard part is showing that, given some other functor with a natural isomorphism , we can give a continuous deformation , such that, over this , the given isomorphism looks like the identity.
Functor-is-category DisCat F .paths (G , Fβ G) = Ξ£-pathp Fβ‘G idβ‘Fβ G where
The first thing we must note is that we can recover the components of a natural isomorphism while passing to/from paths in . Since is a category, pathβiso is an equivalence; The lemmas we need then follow from equivalences having sections.
ptoi-to : β x β pathβiso (isoβpath DisCat (Nat-isoβIso Fβ G _)) .D._β _.to β‘ Fβ G .to .Ξ· x ptoi-to x = ap (Ξ» e β e .D._β _.to) (equivβsection (pathβiso-is-equiv DisCat) _) ptoi-from : β x β pathβiso (isoβpath DisCat (Nat-isoβIso Fβ G _)) .D._β _.from β‘ Fβ G .from .Ξ· x ptoi-from x = ap (Ξ» e β e .D._β _.from) (equivβsection (pathβiso-is-equiv DisCat) _)
We can then show that the natural isomorphism induces a homotopy between the object parts of and :
Fββ‘Gβ : β x β Fβ F x β‘ Fβ G x Fββ‘Gβ x = isoβpath DisCat (Nat-isoβIso Fβ G x)
A slightly annoying calculation tells us that pre/post composition with does in fact turn into ; This is because is natural, so we can push it βpastβ the morphism part of so that the two halves of the isomorphism annihilate.
abstract Fββ‘Gβ : β {x y} {f : C .Hom x y} β PathP (Ξ» i β D.Hom (Fββ‘Gβ x i) (Fββ‘Gβ y i)) (Fβ F f) (Fβ G f) Fββ‘Gβ {x = x} {y} {f} = Hom-pathp ( _ D.β F .Fβ f D.β _ β‘β¨ (Ξ» i β ptoi-to _ i D.β F .Fβ f D.β ptoi-from _ i) β©β‘ Fβ G .to .Ξ· y D.β F .Fβ f D.β Fβ G .from .Ξ· x β‘β¨ apβ D._β_ refl (sym (Fβ G .from .is-natural _ _ _)) β D.assoc _ _ _ β©β‘ (Fβ G .to .Ξ· y D.β Fβ G .from .Ξ· y) D.β G .Fβ f β‘β¨ apβ D._β_ (Ξ» i β Fβ G .invl i .Ξ· y) refl β©β‘ D.id D.β G .Fβ f β‘β¨ solve D β©β‘ G .Fβ f β) Fβ‘G : F β‘ G Fβ‘G = Functor-path Fββ‘Gβ Ξ» f β Fββ‘Gβ
Putting these homotopies together defines a path Fβ‘G. It remains to show that, over this path, the natural isomorphism we started with is homotopic to the identity; Equality of isomorphisms and natural transformations
are both tested componentwise, so we can βpush downβ the relevant equalities to the level of families of morphisms; By computation, all we have to show is that .
idβ‘Fβ G : PathP (Ξ» i β F β Fβ‘G i) id-iso Fβ G idβ‘Fβ G = β -pathp refl Fβ‘G (Nat-pathp refl Fβ‘G Ξ» x β Hom-pathp ( apβ D._β_ (ptoi-to _) refl Β·Β· apβ D._β_ refl (apβ D._β_ refl (transport-refl _) β D.idl _) Β·Β· D.idr _))
A useful lemma is that if you have a natural transformation where each component is an isomorphism, the evident inverse transformation is natural too, thus defining an inverse to Nat-isoβIso defined above.
module _ {C : Precategory o h} {D : Precategory oβ hβ} {F G : Functor C D} where import Cat.Reasoning D as D import Cat.Reasoning Cat[ C , D ] as [C,D] private module F = Functor F module G = Functor G open D.is-invertible componentwise-invertibleβinvertible : (eta : F => G) β (β x β D.is-invertible (eta .Ξ· x)) β [C,D].is-invertible eta componentwise-invertibleβinvertible eta invs = are-invs where module eta = _=>_ eta eps : G => F eps .Ξ· x = invs x .inv eps .is-natural x y f = invs y .inv D.β G.β f β‘β¨ apβ D._β_ refl (sym (D.idr _) β ap (G.β f D.β_) (sym (invs x .invl))) β©β‘ invs y .inv D.β G.β f D.β eta.Ξ· x D.β invs x .inv β‘β¨ apβ D._β_ refl (D.extendl (sym (eta.is-natural _ _ _))) β©β‘ invs y .inv D.β eta.Ξ· y D.β F.β f D.β invs x .inv β‘β¨ D.cancell (invs y .invr) β©β‘ F.β f D.β invs x .inv β are-invs : [C,D].is-invertible eta are-invs = record { inv = eps ; inverses = record { invl = Nat-path Ξ» x β invs x .invl ; invr = Nat-path Ξ» x β invs x .invr } }
Curryingπ
There is an equivalence between the spaces of bifunctors and the space of functors . We refer to the image of a functor under this equivalence as its exponential transpose, and we refer to the map in the βforwardsβ direction (as in the text above) as currying:
Curry : Functor (C ΓCat D) E β Functor C Cat[ D , E ] Curry {C = C} {D = D} {E = E} F = curried where open import Cat.Functor.Bifunctor {C = C} {D = D} {E = E} F curried : Functor C Cat[ D , E ] curried .Fβ = Right curried .Fβ xβy = NT (Ξ» f β first xβy) Ξ» x y f β sym (F-β F _ _) Β·Β· ap (Fβ F) (Ξ£-pathp (C .idr _ β sym (C .idl _)) (D .idl _ β sym (D .idr _))) Β·Β· F-β F _ _ curried .F-id = Nat-path Ξ» x β F-id F curried .F-β f g = Nat-path Ξ» x β ap (Ξ» x β Fβ F (_ , x)) (sym (D .idl _)) β F-β F _ _ Uncurry : Functor C Cat[ D , E ] β Functor (C ΓCat D) E Uncurry {C = C} {D = D} {E = E} F = uncurried where import Cat.Reasoning C as C import Cat.Reasoning D as D import Cat.Reasoning E as E module F = Functor F uncurried : Functor (C ΓCat D) E uncurried .Fβ (c , d) = Fβ (F.β c) d uncurried .Fβ (f , g) = F.β f .Ξ· _ E.β Fβ (F.β _) g uncurried .F-id {x = x , y} = path where abstract path : E ._β_ (F.β (C .id) .Ξ· y) (Fβ (F.β x) (D .id)) β‘ E .id path = F.β C.id .Ξ· y E.β Fβ (F.β x) D.id β‘β¨ E.elimr (F-id (F.β x)) β©β‘ F.β C.id .Ξ· y β‘β¨ (Ξ» i β F.F-id i .Ξ· y) β©β‘ E.id β uncurried .F-β (f , g) (fβ² , gβ²) = path where abstract path : uncurried .Fβ (f C.β fβ² , g D.β gβ²) β‘ uncurried .Fβ (f , g) E.β uncurried .Fβ (fβ² , gβ²) path = F.β (f C.β fβ²) .Ξ· _ E.β Fβ (F.β _) (g D.β gβ²) β‘Λβ¨ E.pulll (Ξ» i β F.F-β f fβ² (~ i) .Ξ· _) β©β‘Λ F.β f .Ξ· _ E.β F.β fβ² .Ξ· _ E.β Fβ (F.β _) (g D.β gβ²) β‘β¨ (Ξ» i β F.β f .Ξ· _ E.β F.β fβ² .Ξ· _ E.β F-β (F.β _) g gβ² i) β©β‘ F.β f .Ξ· _ E.β F.β fβ² .Ξ· _ E.β Fβ (F.β _) g E.β Fβ (F.β _) gβ² β‘β¨ solve E β©β‘ F.β f .Ξ· _ E.β (F.β fβ² .Ξ· _ E.β Fβ (F.β _) g) E.β Fβ (F.β _) gβ² β‘β¨ ap (Ξ» e β _ E.β e E.β _) (F.β fβ² .is-natural _ _ _) β©β‘ F.β f .Ξ· _ E.β (Fβ (F.β _) g E.β F.β fβ² .Ξ· _) E.β Fβ (F.β _) gβ² β‘β¨ solve E β©β‘ ((F.β f .Ξ· _ E.β Fβ (F.β _) g) E.β (F.β fβ² .Ξ· _ E.β Fβ (F.β _) gβ²)) β