definition theorem example program
“All concepts are Kan extensions” (Mac Lane). Given and (a possibly lossy, non-surjective “squishing” of into ), a Kan extension extends along to all of . Equality is too much to ask, even a natural iso; one settles for a one-way natural transformation, whose direction distinguishes right from left:
- Right Kan extension : universal — for every there is a unique with . If it exists for all : , i.e. .
- Left Kan extension : universal — for every a unique with ; .
Sources: DaoFP Chapter 19 (“Kan Extensions”: §19.2 “Inverting a functor”, §19.3 “Right Kan extension” incl. “as an end”, “in Haskell”, “Limits as Kan extensions”, “Left adjoint as a right Kan extension”, “Codensity monad”; §19.4 “Left Kan extension” incl. “as a coend”, “Colimits as Kan extensions”, “Right adjoint as a left Kan extension”, “Day convolution as a Kan extension”; §19.5 “Useful Formulas”), Exercises 19.3.1–19.4.2; 7 Sketches §3.4 (, are , ), §3.6.
Intuition: fractions
Adjoints behave like inverses; Kan extensions like fractions : undo (modulo ) and follow with . If has a left adjoint then ; if a right adjoint, . The more discards, the easier the inversion.
Formulas (End/Coend, §19.5)
generalizing the ninja (co-)Yoneda lemmas (). Here is the power (, “multiply copies of ”: ) and the copower (, ); in both decay to the exponential/product, giving Ran p f b = forall e. (b -> p e) -> f e and Lan p f b = exists e. (p e -> b, f e). The proofs write themselves: pull ends out of hom-sets by continuity, apply the (co)power definition, integrate with Yoneda.
Everything is a Kan extension
| concept | as Kan extension |
|---|---|
| Limit of | along (a cone is ) |
| Colimit | |
| left adjoint of | (with , DaoFP Exercise 19.3.2); conversely is a left adjoint iff preserved by |
| right adjoint of | |
| Codensity Monad | (); the density comonad is |
| Day Convolution | for the external product |
| data migration | , on C-sets |
| Dependent Sum / Dependent Product | along a function of sets (discrete categories) |
In Haskell
newtype Ran p f b = Ran (forall e. (b -> p e) -> f e)
counit :: Ran p f (p e') -> f e' -- ε: instantiate at e = e' with id
counit (Ran h) = h id
type Alpha p f g = forall e. g (p e) -> f e -- α : G ∘ P → F
sigma :: Functor g => Alpha p f g -> forall b. g b -> Ran p f b
sigma alpha gb = Ran (\b_pe -> alpha (fmap b_pe gb))
data Lan p f b where Lan :: (p e -> b) -> f e -> Lan p f b
unit :: f e' -> Lan p f (p e') -- η: pick e = e', id
unit fe = Lan id fe
sigmaL :: Functor g => (forall e. f e -> g (p e)) -> forall b. Lan p f b -> g b
sigmaL alpha (Lan pe_b fe) = fmap pe_b (alpha fe)Docs: FinCats · ACSets API · Graphs · Theories & presentations
using Catlab
# Kan extensions of C-sets along a schema functor: Σ_F = Lan_F, Π_F = Ran_F (data migration)
@present SchDDS(FreeSchema) begin State::Ob; next::Hom(State, State) end
@acset_type DDS(SchDDS)
F = FinFunctor(Dict(:V => :State, :E => :State),
Dict(:src => id(SchDDS[:State]), :tgt => :next), FinCat(SchGraph), FinCat(SchDDS))
G = cycle_graph(Graph, 3) # (a path graph would generate an infinite DDS)
Σ = SigmaMigrationFunctor(F, Graph, DDS) # left Kan extension along F
D = Σ(G); nparts(D, :State), D[:next] # (3, [2, 3, 1]): the freely generated DDSimport Mathlib
open CategoryTheory
#check @CategoryTheory.Functor.lan -- left Kan extension functor along P
#check @CategoryTheory.Functor.ran
#check @CategoryTheory.Functor.lanAdjunction -- lan ⊣ (whiskeringLeft P)
#check @CategoryTheory.Functor.ranAdjunction
#check @CategoryTheory.Functor.LeftExtension -- (Lan_P F, η) as a universal left extension
#check @CategoryTheory.Functor.LeftExtension.IsPointwiseLeftKanExtension -- the colimit (coend) formula{-# LANGUAGE RankNTypes, GADTs #-}
newtype Ran p f b = Ran (forall e. (b -> p e) -> f e)
instance Functor (Ran p f) where -- Exercise 19.3.1
fmap g (Ran h) = Ran (\k -> h (k . g))
data Lan p f b where
Lan :: (p e -> b) -> f e -> Lan p f b
instance Functor (Lan p f) where -- Exercise 19.4.1
fmap g (Lan pe_b fe) = Lan (g . pe_b) fe
-- limits as right Kan extensions along ! : J → 1, e.g. products: Ran along the functor from 2