definition theorem example program

The coend of a functor (a Profunctor when ) is the “sum of its diagonal entries” , corrected for double counting. A cowedge is an object with injections such that for every

(the two ways of “extending” a common ancestor agree). The coend is the universal cowedge: every cowedge factors uniquely as .

Phy;xiPhy;yiPhx;xiRxPhx;xidPhid;fiPhf;idiiyixhPhy;xiPhy;yiPhx;xiRxPhx;xidPhid;fiPhf;idiiyixh

Sources: DaoFP §17.2 (“Coends”: “Extranatural transformations”, “Profunctor composition using coends”, “Colimits as coends”), §17.4–17.6, §17.9 (“Existential lens”), §17.11 (“Important Formulas”), Exercises 17.2.1–17.2.3; 7 Sketches §4.3.2 (profunctor composition as a quantale-valued matrix product — the preorder shadow of a coend).

  • In : take the disjoint union of all and identify with whenever some and satisfy , . On a Discrete Category the cowedge condition is empty and the coend is a plain Coproduct — the trace of a matrix.
  • Extranatural transformations: a family satisfying two “diamond” conditions; the cowedge condition is extranaturality into the constant profunctor (DaoFP Exercise 17.2.1). The coend is universal among extranatural .
  • Profunctor composition (Category of Profunctors, Bicategory of Profunctors): ; in Haskell data Procompose p q a b where Procompose :: q a x -> p x b -> Procompose p q a b — an existential type, data Coend p where Coend :: p x x -> Coend p, and parametricity enforces the cowedge condition for free (DaoFP Exercise 17.2.2, DaoFP Exercise 17.2.3).
  • Colimits as coends: for a profunctor ignoring its first argument, a cowedge is a Cocone, so (a matrix with identical rows: the trace is the sum of the vector). Dually ends are limits and products.
  • Calculus: co-continuity of the hom-functor pulls coends out as ends, — the mapping-out property; the Fubini rule lets double (co)ends be swapped or merged into one over ; the ninja co-Yoneda lemma “integrates against a delta function”. Applications: Day Convolution, the existential type Nu, the existential Lens .

Docs: FinSets · Limits & colimits

using Catlab
# coend of a Set-valued profunctor on a finite category = colimit-style quotient: for a
# discrete category it is just the disjoint union of the diagonal sets
Pdiag = [FinSet(2), FinSet(3), FinSet(1)]        # P⟨x,x⟩ for x = 1,2,3, no non-identity arrows
ob(coproduct(Pdiag))                             # FinSet(6) = ∫^x P⟨x,x⟩ (coproduct of a list)
# with arrows the cowedge condition is a coequalizer of the two extensions (cf. Finite Colimits in Set)
import Mathlib
open CategoryTheory
-- Mathlib has no dedicated coend API; coends are colimits over the twisted arrow category
#check @CategoryTheory.Limits.colimit
#check @CategoryTheory.Functor.leftKanExtension   -- Kan extensions, computed by coends
{-# LANGUAGE GADTs, RankNTypes #-}
data Coend p where
  Coend :: p x x -> Coend p                     -- exists x. p x x
mapOutCoend :: (forall x. p x x -> c) -> Coend p -> c   -- the universal property
mapOutCoend f (Coend pxx) = f pxx
 
data Procompose p q a b where                   -- (p ⋄ q) a b = ∫^x q a x × p x b
  Procompose :: q a x -> p x b -> Procompose p q a b