definition theorem example program
The end of a functor is the dual of the Coend: the “product of the diagonal entries”. A wedge is an object with projections such that for every
and the end is the universal wedge. In : form the giant product of all and keep only the tuples satisfying the wedge condition. In Haskell, parametricity makes the wedge condition automatic: type End p = forall x. p x x — to build an end one must supply a polymorphic formula, whereas to build a coend one picks a single type (exists x. p x x).
Sources: DaoFP §17.3 (“Ends”: “Natural transformations as an end”, “Limits as ends”), §17.4 (“Continuity of the Hom-Functor”), §17.5 (“Fubini Rule”), §17.6, §17.11, Exercise 17.3.1; §20.3 (ends as weighted limits).
- Natural transformations as an end: is a profunctor, and the wedge condition for its diagonal is exactly naturality ; hence
- Limits as ends: for a wedge is a Cone, so ; a Product is the end over the discrete two-object category (DaoFP Exercise 17.3.1).
- Continuity of the hom-functor: preserves limits () and turns colimits into limits (); hence the integral sign can be pulled out of a hom-set: and .
- Fubini: whenever the ends exist; likewise for coends.
- The Ninja Yoneda Lemma is the Yoneda lemma with the set of natural transformations written as an end. In calculus one rarely sees “product integrals” because logarithms turn them into sums; category theory has no logarithm, so ends and coends are equally important.
Docs: FinSets · Limits & colimits · C-set morphisms · Graphs
using Catlab
# ends over a finite discrete category are products of the diagonal sets
Pdiag = [FinSet(2), FinSet(3)]
ob(product(Pdiag)) # FinSet(6) = ∫_x P⟨x,x⟩ = P⟨1,1⟩ × P⟨2,2⟩
# natural transformations as an end: all homs between two graphs, checked for naturality
G = path_graph(Graph, 2); H = cycle_graph(Graph, 2)
length(homomorphisms(G, H)) # the (finite) end ∫_x Set(F x, G x) for C-setsimport Mathlib
open CategoryTheory
-- natural transformations as an end: NatTrans F G is a family with the wedge (naturality) condition
#check @CategoryTheory.NatTrans
#check @CategoryTheory.NatTrans.naturality
#check @CategoryTheory.Limits.limit -- ends are limits over the twisted arrow category{-# LANGUAGE RankNTypes #-}
type End p = forall x. p x x
type Natural f g = forall x. f x -> g x -- ∫_x Hom(f x, g x)
newtype HomFG f g x y = HomFG (f x -> g y) -- the profunctor ⟨x,y⟩ ↦ Hom(F x, G y)
-- End (HomFG f g) ≅ Natural f g