module Cat.Diagram.Coend.Sets where
Coends in Sets🔗
We can give an explicit construction of coends in the category of sets by
taking a coequaliser.
Intuitively, the coend should be the “sum of the diagonal” of a functor
which translates directly to the sigma type
Σ[ X ∈ Ob ] ∣ F₀ (X , X) ∣
. However, trying to use this
without some sort of quotient is going to be immediately problematic.
For starters, this isn’t even a set! More importantly, we run into an
immediate issue when we try to prove that this is extranatural; we need
to show that F₁ (f , id) Fyx ≡ F₁ (id , f) Fyx
for all
f : Hom Y X
and ∣ Fyx : F₀ (X , Y) ∣
.
However, if we take a coequaliser of
Σ[ X ∈ Ob ] ∣ F₀ (X , X) ∣
both of these problems
immediately disappear. In particular, we want to take the coequaliser of
the following pair of functions:
This allows us to prove the troublesome extranaturality condition
directly with glue
. With that
motivation out of the way, let’s continue with the construction!
module _ {o ℓ} {C : Precategory o ℓ} (F : Functor (C ^op ×ᶜ C) (Sets (o ⊔ ℓ))) where
open Precategory C
open Functor F
open Coend
open Cowedge
We start by defining the two maps we will coequalise along. Quite a bit of bundling is required to make things well typed, but this is exactly the same pair of maps in the diagram above.
: Σ[ X ∈ C ] Σ[ Y ∈ C ] Σ[ f ∈ Hom Y X ] F ʻ (X , Y)
dimapl → Σ[ X ∈ C ] F ʻ (X , X)
(X , Y , f , Fxy) = X , F₁ (id , f) Fxy
dimapl
: Σ[ X ∈ C ] Σ[ Y ∈ C ] Σ[ f ∈ Hom Y X ] F ʻ (X , Y)
dimapr → Σ[ X ∈ C ] F ʻ (X , X)
(X , Y , f , Fxy) = Y , F₁ (f , id) Fxy dimapr
Constructing the universal Cowedge
is easy now that we’ve taken the
right coequaliser.
: Coend F
Set-coend = coend where
Set-coend : Cowedge F
universal-cowedge .nadir = el! (Coeq dimapl dimapr)
universal-cowedge .ψ X Fxx = inc (X , Fxx)
universal-cowedge .extranatural {X} {Y} f =
universal-cowedge λ Fyx → glue (Y , X , f , Fyx) funext
To show that the Cowedge
is universal, we can
essentially just project out the bundled up object from the coend and
feed that to the family associated to the cowedge W
.
: (W : Cowedge F) → Coeq dimapl dimapr → ⌞ W .nadir ⌟
factoring (inc (o , x)) = W .ψ o x
factoring W (glue (X , Y , f , Fxy) i) = W .extranatural f i Fxy
factoring W (squash x y p q i j) = W .nadir .is-tr (factoring W x) (factoring W y) (λ i → factoring W (p i)) (λ i → factoring W (q i)) i j
factoring W
: Coend F
coend .cowedge = universal-cowedge
coend .factor W = factoring W
coend .commutes = refl
coend .unique {W = W} p = ext λ X x → p ·ₚ x coend
This construction is actually functorial! Given any functor we can naturally construct its Coend in This ends up assembling into a functor from the functor category into
module _ {o ℓ} {𝒞 : Precategory o ℓ} where
open Precategory 𝒞
open Functor
open _=>_
: Functor Cat[ 𝒞 ^op ×ᶜ 𝒞 , Sets (o ⊔ ℓ) ] (Sets (o ⊔ ℓ))
Coends .F₀ F = el! (Coeq (dimapl F) (dimapr F))
Coends .F₁ α =
Coends (λ ∫F → inc ((∫F .fst) , α .η _ (∫F .snd))) λ where
Coeq-rec (X , Y , f , Fxy) →
(ap (λ ϕ → inc (X , ϕ)) $ happly (α .is-natural (X , Y) (X , X) (id , f)) Fxy) ∙∙
(X , Y , f , α .η (X , Y) Fxy) ∙∙
glue (sym $ ap (λ ϕ → inc (Y , ϕ)) $ happly (α .is-natural (X , Y) (Y , Y) (f , id)) Fxy)
.F-id = ext λ _ _ → refl
Coends .F-∘ f g = ext λ _ _ → refl Coends