module Cat.Instances.Elements.Covariant where

The covariant category of elementsπŸ”—

While the category of elements comes up most often in the context of presheaves (i.e., contravariant functors into the construction makes sense for covariant functors as well.

Sadly, we cannot simply reuse the contravariant construction, instantiating as the resulting category would be the opposite of what we want. Indeed, in both the covariant and contravariant cases, we want the projection to be covariant.

Thus we proceed to dualise the whole construction.

  Element : Type (o βŠ” s)
  Element = Σ[ ob ∈ Ob ] P ʻ ob

  pattern elem x s = x , s

  record Element-hom (x y : Element) : Type (β„“ βŠ” s) where
    constructor elem-hom
    field
      hom     : Hom (x .fst) (y .fst)
      commute : P.₁ hom (x .snd) ≑ y .snd

  open Element-hom
  ∫ : Precategory (o βŠ” s) (β„“ βŠ” s)
  ∫ .Precategory.Ob = Element P
  ∫ .Precategory.Hom = Element-hom P
  ∫ .Precategory.Hom-set _ _ = hlevel 2
  ∫ .Precategory.id {x = x} = elem-hom id Ξ» i β†’ P.F-id i (x .snd)
  ∫ .Precategory._∘_ {x = x} {y = y} {z = z} f g = elem-hom (f .hom ∘ g .hom) comm where abstract
    comm : P.₁ (f .hom ∘ g .hom) (x .snd) ≑ z .snd
    comm =
      P.₁ (f .hom ∘ g .hom) (x .snd)       β‰‘βŸ¨ happly (P.F-∘ (f .hom) (g .hom)) (x .snd) βŸ©β‰‘
      P.₁ (f .hom) (P.₁ (g .hom) (x .snd)) β‰‘βŸ¨ ap (P.F₁ (f .hom)) (g .commute)  βŸ©β‰‘
      P.₁ (f .hom) (y .snd)                β‰‘βŸ¨ f .commute βŸ©β‰‘
      z .snd ∎
  ∫ .Precategory.idr f = ext (idr (f .hom))
  ∫ .Precategory.idl f = ext (idl (f .hom))
  ∫ .Precategory.assoc f g h = ext (assoc (f .hom) (g .hom) (h .hom))

  Ο€β‚š : Functor ∫ C
  Ο€β‚š .Fβ‚€ x = x .fst
  Ο€β‚š .F₁ f = f .hom
  Ο€β‚š .F-id = refl
  Ο€β‚š .F-∘ f g = refl

We can now relate the two constructions: the covariant category of elements of is the opposite of the contravariant category of elements of seen as a contravariant functor on (thus a functor

  co-∫ : ∫ ≑ Contra.∫ (C ^op) (record { Functor P }) ^op
  co-∫ = Precategory-path F F-is-precat-iso where
    F : Functor ∫ (Contra.∫ (C ^op) (record { Functor P }) ^op)
    F .Fβ‚€ e = e
    F .F₁ h = Contra.elem-hom (h .hom) (h .commute)
    F .F-id = refl
    F .F-∘ _ _ = ext refl

    F-is-precat-iso : is-precat-iso F
    F-is-precat-iso .is-precat-iso.has-is-iso = id-equiv
    F-is-precat-iso .is-precat-iso.has-is-ff = is-iso→is-equiv λ where
      .is-iso.from h β†’ elem-hom (h .Contra.Element-hom.hom) (h .Contra.Element-hom.commute)
      .is-iso.rinv h β†’ ext refl
      .is-iso.linv h β†’ ext refl