module Cat.Diagram.Coend where

private variable o β o' β' : Level C D : Precategory o' β' coend-level : {C : Precategory o β} {D : Precategory o' β'} β Functor (C ^op ΓαΆ C) D β Level coend-level {o = o} {β} {o'} {β'} _ = o β o' β β β β'

# Coendsπ

Let
$F:C_{op}ΓCβD$
be a functor, which, by the general yoga of bifunctors we think of as
combining a contravariant action
$F(β,x):C_{op}βD$
and a covariant action
$F(x,β):CβD$
of
$C$
on
$D$^{1}. As a concrete example, we could
take
$C=BR,$
the 1-object $Ab-category$
associated to a ring
$R$
β then the functors
$F(β,x)$
and
$F(x,β)$
would be left- and right-
$R-modules,$
respectively. In fact, let us focus on this case and consider two
modules
$A$
and
$B,$
incarnated as a pair of functors
$A:BR_{op}βAb$
and
$B:BRβAb.$

In this situation, we may study the **tensor product**
(of modules!)
$Aβ_{R}B$
as being an βuniversal object where the actions of
$A$
and
$B$
agreeβ. In particular, itβs known that we can compute the tensor product
of modules as being (the object in) a coequaliser diagram like

where the undecorated $AβB$ stands for the tensor product of abelian groups, and the two maps are given by the $R-actions$ of $A$ and $B.$ More explicitly, letting $aβb$ stand for a tensor, the equation $aβrb=arβb$ holds in $Aβ_{R}B,$ and the tensor product is the universal object where this is forced to hold.

Going back to the absurd generality of a bifunctor $F:C_{op}ΓCβD,$ we may still wish to consider these sorts of βuniversal quotients where a pair of actions are forced to agreeβ, even if our codomain category $D$ does not have a well-behaved calculus of tensor products. As a motivating example, the computation of left Kan extensions as certain colimits has this form!

We call such an object a **coend** of the functor
$F,$
and denote it by
$β«_{c}F(c,c)$
(or
$β«F$
for short). Being a type of colimit, coends are initial objects in a particular
category, but we will unpack the definition here and talk about
**cowedges** instead.

## Formalisationπ

record Cowedge (F : Functor (C ^op ΓαΆ C) D) : Type (coend-level F) where no-eta-equality

A **cowedge** under a functor
$F$
is given by an object
$w:D$
(which we refer to as the `nadir`

, because weβre pretentious),
together with a family of maps
$Ο_{c}:F(c,c)βw.$

field nadir : D.Ob Ο : β c β D.Hom (F.β (c , c)) nadir

This family of maps must satisfy a condition called
**extranaturality**, expressing that the diagram below
commutes. As the name implies, this is like the naturality condition for
a natural
transformation, but extra! In particular, it copes with the functor
being covariant in one argument and contravariant in the other.

extranatural : β {c c'} (f : C.Hom c c') β Ο c' D.β F.second f β‘ Ο c D.β F.first f

A coend, then, is a universal cowedge. In particular, we say that
**$(w,Ο)$
is a coend for
$F$**
such that, given any other wedge
$(w_{β²},Ο)$
under
$F,$
we can factor
$w$
through
$w_{β²}$
by a unique map
$e:wβw_{β²}.$
Furthermore, the map
$e$
must commute with the maps
$Ο,$
meaning explicitly that
$eΟ_{a}=Ο_{a}.$

record Coend (F : Functor (C ^op ΓαΆ C) D) : Type (coend-level F) where

field cowedge : Cowedge F

Unfolding the requirement of uniqueness for $e,$ we require that, given any other map $f:wβw_{β²}$ s.t. $fΟ_{a}=Ο_{a}$ for all objects $a,$ then $e=f.$ This is exactly analogous to the uniqueness properties of colimiting maps for every other colimit.

field factor : β (W : Cowedge F) β D.Hom cowedge.nadir (W .nadir) commutes : β {W : Cowedge F} {a} β factor W D.β cowedge.Ο a β‘ W .Ο a unique : β {W : Cowedge F} {g : D.Hom cowedge.nadir (W .nadir)} β (β {a} β g D.β cowedge.Ο a β‘ W .Ο a) β g β‘ factor W

βActionβ here is meant evoke the idea of e.g.Β group actions, and does not refer to a specific conceptβ©οΈ