Skip to content
The Lumenary
First-year graduateGraduate 120 min

Kan extensions

The best possible way to extend a functor along another — and why limits, adjoints, induced representations and even the floor function are all instances of it.

Formally verified · 19 LeanComputationally tested · 1 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

Extending as well as possible

Here are three problems that look unrelated.

  • You know a function only on the integers, say n↦nn \mapsto n, and you want a monotone function on all of R\mathbb{R} that is “as close as possible” to it. From below, the answer is ⌊x⌋\lfloor x \rfloor; from above, ⌈x⌉\lceil x \rceil.
  • A subgroup HH of a group GG acts on a set or a vector space VV. You want a GG-action that is “freely generated” by the HH-action. The answer is the induced representation IndHGV\mathrm{Ind}_H^G V.
  • You know a topological space Δn\Delta^n for each standard simplex [n][n], and you want to turn every simplicial set into a space, gluing simplices the way the simplicial set says. The answer is geometric realisation.

In each case there is a functor F:C→EF : \mathcal{C} \to \mathcal{E} defined on a “small piece” C\mathcal{C}, a functor K:C→DK : \mathcal{C} \to \mathcal{D} embedding (or merely mapping) that piece into a larger world, and we want the best functor D→E\mathcal{D} \to \mathcal{E} that extends FF. In general no functor extends FF on the nose — but there is a best approximation from the left and a best approximation from the right. These are the left and right Kan extensions, and they turn out to be so universal that Saunders Mac Lane ended the first edition of Categories for the Working Mathematician (1971) with a section titled “All concepts are Kan extensions”.

This lesson assumes adjunctions, limits and colimits and the Yoneda lemma.

IntuitionH

The picture: a triangle that need not commute

Draw FF and KK as two sides of a triangle. We want to fill in the third side.

C\mathcal{C}
E\mathcal{E}
D\mathcal{D}
FF
KK
LanKF\mathrm{Lan}_K F
A left Kan extension fills the triangle up to a universal natural transformation η:F⇒(LanKF)∘K\eta : F \Rightarrow (\mathrm{Lan}_K F) \circ K, not up to equality.

Asking for L∘K=FL \circ K = F is usually hopeless: if KK sends two objects a,ba, b to the same object dd, then L(d)L(d) would have to equal both F(a)F(a) and F(b)F(b). Category theory's answer is to ask instead for a natural transformation F⇒L∘KF \Rightarrow L \circ K — “LL is at least as big as FF along KK” — and to take the smallest such LL. Dually, a right Kan extension is the largest RR with R∘K⇒FR \circ K \Rightarrow F.

The poset case makes this concrete. A poset is a category with at most one arrow between two objects, a functor between posets is a monotone map, and a natural transformation f⇒gf \Rightarrow g exists exactly when f≤gf \le g pointwise. The smallest monotone LL with f(c)≤L(k(c))f(c) \le L(k(c)) is forced: L(d)L(d) must be at least f(c)f(c) whenever k(c)≤dk(c) \le d, so the best choice is

L(d)=⋁{ f(c)∣k(c)≤d }.L(d) = \bigvee \{\, f(c) \mid k(c) \le d \,\}.

That supremum is the poset shadow of the general formula: a left Kan extension at dd is the colimit of everything that maps to dd.

DefinitionsH

Definitions

Throughout, K:C→DK : \mathcal{C} \to \mathcal{D} and F:C→EF : \mathcal{C} \to \mathcal{E} are functors. For a functor G:D→EG : \mathcal{D} \to \mathcal{E}, write GK=G∘KGK = G \circ K, and for a natural transformation σ:G⇒G′\sigma : G \Rightarrow G' write σK:GK⇒G′K\sigma K : GK \Rightarrow G'K for the whiskered transformation with components (σK)c=σKc(\sigma K)_c = \sigma_{Kc}.

Definition— left Kan extension

A left Kan extension of FF along KK is a functor L:D→EL : \mathcal{D} \to \mathcal{E} together with a natural transformation η:F⇒LK\eta : F \Rightarrow LK (the unit) such that for every functor G:D→EG : \mathcal{D} \to \mathcal{E} and every natural transformation α:F⇒GK\alpha : F \Rightarrow GK there is a unique natural transformation σ:L⇒G\sigma : L \Rightarrow G with

α=(σK)∘η,i.e.αc=σKc∘ηc  for all c.\alpha = (\sigma K) \circ \eta, \qquad\text{i.e.}\qquad \alpha_c = \sigma_{Kc} \circ \eta_c \ \text{ for all } c.

Equivalently, σ↦(σK)∘η\sigma \mapsto (\sigma K) \circ \eta is a bijection Nat(L,G)≅Nat(F,GK)\mathrm{Nat}(L, G) \cong \mathrm{Nat}(F, GK) for every GG. We write L=LanKFL = \mathrm{Lan}_K F; it is unique up to unique isomorphism, as any universal object is.

FF
(LanKF) K(\mathrm{Lan}_K F)\,K
GKG K
η\eta
α\alpha
σK\sigma K
The universal property, drawn in the functor category [C,E][\mathcal{C}, \mathcal{E}]: every α\alpha factors uniquely through the unit η\eta.

Definition— right Kan extension

A right Kan extension of FF along KK is a functor R=RanKF:D→ER = \mathrm{Ran}_K F : \mathcal{D} \to \mathcal{E} with a natural transformation ε:RK⇒F\varepsilon : RK \Rightarrow F (the counit) such that for every GG and every β:GK⇒F\beta : GK \Rightarrow F there is a unique σ:G⇒R\sigma : G \Rightarrow R with β=ε∘(σK)\beta = \varepsilon \circ (\sigma K). Equivalently, Nat(G,R)≅Nat(GK,F)\mathrm{Nat}(G, R) \cong \mathrm{Nat}(GK, F).

If every F:C→EF : \mathcal{C} \to \mathcal{E} has a left (respectively right) Kan extension along KK, the bijections above say precisely that LanK\mathrm{Lan}_K and RanK\mathrm{Ran}_K are the left and right adjoints of restriction along KK, the functor K∗:[D,E]→[C,E]K^* : [\mathcal{D}, \mathcal{E}] \to [\mathcal{C}, \mathcal{E}], G↦GKG \mapsto GK:

LanK  ⊣  K∗  ⊣  RanK.\mathrm{Lan}_K \;\dashv\; K^* \;\dashv\; \mathrm{Ran}_K .

To compute Kan extensions we need comma categories.

Definition— comma categories over and under an object

For an object d∈Dd \in \mathcal{D}, the comma category (K↓d)(K \downarrow d) has as objects the pairs (c,f)(c, f) with c∈Cc \in \mathcal{C} and f:Kc→df : Kc \to d; a morphism (c,f)→(c′,f′)(c, f) \to (c', f') is a morphism u:c→c′u : c \to c' with f′∘K(u)=ff' \circ K(u) = f. It comes with the projection πd:(K↓d)→C\pi_d : (K \downarrow d) \to \mathcal{C}, (c,f)↦c(c, f) \mapsto c. Dually, (d↓K)(d \downarrow K) has objects (c,f:d→Kc)(c, f : d \to Kc) and morphisms uu with K(u)∘f=f′K(u) \circ f = f'. (Mathlib calls these CostructuredArrow K d and StructuredArrow d K.)

Definition— pointwise Kan extension

The left Kan extension is pointwise when, for every dd,

(LanKF)(d)=colim⁡(c, f)∈(K↓d)F(c),(\mathrm{Lan}_K F)(d) = \operatorname*{colim}_{(c,\, f) \in (K \downarrow d)} F(c),

the colimit of F∘πdF \circ \pi_d, and dually (RanKF)(d)=lim⁡(c,f)∈(d↓K)F(c)(\mathrm{Ran}_K F)(d) = \lim_{(c, f) \in (d \downarrow K)} F(c). In words: the left Kan extension at dd glues together the values F(c)F(c) of everything that maps to dd, identified along the arrows between them.

Worked examplesH

Examples, non-examples and boundary cases

Example— Floor and ceiling

Let K:Z↪RK : \mathbb{Z} \hookrightarrow \mathbb{R} be the inclusion and F:Z→Z‾=Z∪{±∞}F : \mathbb{Z} \to \overline{\mathbb{Z}} = \mathbb{Z} \cup \{\pm\infty\} the inclusion into the complete lattice of extended integers. By the poset formula,

(LanKF)(x)=sup⁡{ n∈Z∣n≤x }=⌊x⌋,(RanKF)(x)=inf⁡{ n∈Z∣x≤n }=⌈x⌉.(\mathrm{Lan}_K F)(x) = \sup\{\, n \in \mathbb{Z} \mid n \le x \,\} = \lfloor x \rfloor, \qquad (\mathrm{Ran}_K F)(x) = \inf\{\, n \in \mathbb{Z} \mid x \le n \,\} = \lceil x \rceil.

Every monotone g:R→Z‾g : \mathbb{R} \to \overline{\mathbb{Z}} that agrees with FF on the integers satisfies ⌊x⌋≤g(x)≤⌈x⌉\lfloor x \rfloor \le g(x) \le \lceil x \rceil: the Kan extensions are the extreme extensions. Since KK is an order embedding, both restrict back to FF on Z\mathbb{Z}.

123floorceiling
The floor function (solid) is the left Kan extension of the integers along ℤ ⊂ ℝ, the ceiling (dashed) the right Kan extension. They agree exactly at the integers, where both extend the original function.

Example— Limits and colimits

Let 1\mathbf{1} be the terminal category and !:J→1! : J \to \mathbf{1} the unique functor. A functor c:1→Ec : \mathbf{1} \to \mathcal{E} is an object cc, and a natural transformation c∘!⇒Fc \circ {!} \Rightarrow F is a family of maps c→F(j)c \to F(j) compatible with all F(u)F(u) — a cone over FF with vertex cc. The universal property of Ran!F\mathrm{Ran}_! F says that there is a universal cone. Hence

Ran!F=lim⁡F,Lan!F=colim⁡F,\mathrm{Ran}_! F = \lim F, \qquad \mathrm{Lan}_! F = \operatorname{colim} F,

each existing exactly when the (co)limit does. (A full proof is in the next section.) For JJ the discrete category on two objects this gives products and coproducts: the right Kan extension of (A,B)(A, B) to 1\mathbf{1} is A×BA \times B — the universal property explored in the trail The product, by its maps.

Example— Extending along a non-injective functor: no strict extension

Let K:{a,b}→1K : \{a, b\} \to \mathbf{1} (discrete source) and F:{a,b}→SetF : \{a, b\} \to \mathbf{Set} with ∣F(a)∣=2|F(a)| = 2, ∣F(b)∣=3|F(b)| = 3. Then (LanKF)(∗)=F(a)⊔F(b)(\mathrm{Lan}_K F)(\ast) = F(a) \sqcup F(b) has 55 elements and (RanKF)(∗)=F(a)×F(b)(\mathrm{Ran}_K F)(\ast) = F(a) \times F(b) has 66. Neither restricts back to FF: (LanKF)K(a)(\mathrm{Lan}_K F)K(a) has 55 elements, not 22. The unit ηa:F(a)→F(a)⊔F(b)\eta_a : F(a) \to F(a) \sqcup F(b) is the coproduct inclusion — a genuine map, not an identity.

Example— Induced and coinduced actions

A group GG is a category BG\mathbf{B}G with one object ∗\ast and one arrow for each g∈Gg \in G; a functor BG→Set\mathbf{B}G \to \mathbf{Set} is a GG-set. For a subgroup H≤GH \le G with inclusion i:BH→BGi : \mathbf{B}H \to \mathbf{B}G and an HH-set XX:

  • The comma category (i↓∗)(i \downarrow \ast) has one object for each g∈Gg \in G (an arrow i(∗)→∗i(\ast) \to \ast), and an arrow g′h→g′g'h \to g' for each h∈Hh \in H. Its colimit glues (g′h,x)(g'h, x) to (g′,hx)(g', h x), so (LaniX)(∗)=G×HX(\mathrm{Lan}_i X)(\ast) = G \times_H X, the induced GG-set, with [G:H] ∣X∣[G : H]\,|X| elements when GG is finite.
  • Dually (RaniX)(∗)=HomH(G,X)(\mathrm{Ran}_i X)(\ast) = \mathrm{Hom}_H(G, X), the coinduced GG-set of HH-equivariant maps, with ∣X∣[G:H]|X|^{[G:H]} elements.

For H=1H = 1 and X={∗}X = \{\ast\}, LaniX=G\mathrm{Lan}_i X = G acting on itself: the free GG-set on one generator. The experiment below computes all of these as colimits and limits.

Example— Non-example: a Kan extension that does not exist

Let kk be the inclusion of the discrete poset {a,b}\{a, b\} into {a,b,⊤}\{a, b, \top\} with a,b≤⊤a, b \le \top, and let ff send a↦xa \mapsto x, b↦yb \mapsto y in the discrete two-element poset {x,y}\{x, y\}. A monotone gg with f≤g∘kf \le g \circ k would need x≤g(a)≤g(⊤)x \le g(a) \le g(\top) and y≤g(b)≤g(⊤)y \le g(b) \le g(\top), which is impossible. So there is no extension at all, and certainly no Kan extension. The pointwise formula fails precisely because the join x∨yx \vee y does not exist.

ProofH

The main theorems

Theorem— Theorem 1 (the pointwise formula)

Suppose that for every d∈Dd \in \mathcal{D} the colimit L(d)=colim⁡(F∘πd)L(d) = \operatorname{colim}(F \circ \pi_d) over (K↓d)(K \downarrow d) exists, with coprojections ι(c,f):F(c)→L(d)\iota_{(c, f)} : F(c) \to L(d). Then d↦L(d)d \mapsto L(d) extends uniquely to a functor L:D→EL : \mathcal{D} \to \mathcal{E} with L(g)∘ι(c,f)=ι(c, gf)L(g) \circ \iota_{(c, f)} = \iota_{(c,\, g f)}, and with ηc=ι(c, idKc)\eta_c = \iota_{(c,\, \mathrm{id}_{Kc})} the pair (L,η)(L, \eta) is a left Kan extension of FF along KK.

Proof

Functoriality. An arrow g:d→d′g : d \to d' induces a functor g∗:(K↓d)→(K↓d′)g_* : (K \downarrow d) \to (K \downarrow d'), (c,f)↦(c,gf)(c, f) \mapsto (c, gf), with πd′∘g∗=πd\pi_{d'} \circ g_* = \pi_d. The maps ι(c,gf):F(c)→L(d′)\iota_{(c, gf)} : F(c) \to L(d') therefore form a cocone over F∘πdF \circ \pi_d, so there is a unique L(g):L(d)→L(d′)L(g) : L(d) \to L(d') with L(g)∘ι(c,f)=ι(c,gf)L(g) \circ \iota_{(c, f)} = \iota_{(c, gf)}. Both L(id)L(\mathrm{id}) and id\mathrm{id}, and both L(g′g)L(g'g) and L(g′)L(g)L(g') L(g), satisfy the same equations on coprojections, so they agree by the uniqueness clause of the colimit.

The unit is natural. For u:c→c′u : c \to c' in C\mathcal{C} we must show L(Ku)∘ηc=ηc′∘F(u)L(Ku) \circ \eta_c = \eta_{c'} \circ F(u). The left side is ι(c,Ku)\iota_{(c, Ku)} by definition of L(Ku)L(Ku). On the right, uu is a morphism (c,Ku)→(c′,idKc′)(c, Ku) \to (c', \mathrm{id}_{Kc'}) of (K↓Kc′)(K \downarrow Kc'), so the cocone condition gives ι(c′,id)∘F(u)=ι(c,Ku)\iota_{(c', \mathrm{id})} \circ F(u) = \iota_{(c, Ku)}.

Existence of factorisations. Let G:D→EG : \mathcal{D} \to \mathcal{E} and α:F⇒GK\alpha : F \Rightarrow GK. For fixed dd, the maps G(f)∘αc:F(c)→G(d)G(f) \circ \alpha_c : F(c) \to G(d) form a cocone over F∘πdF \circ \pi_d: if u:(c,f)→(c′,f′)u : (c, f) \to (c', f'), then f′∘K(u)=ff' \circ K(u) = f, and naturality of α\alpha gives

G(f′)∘αc′∘F(u)=G(f′)∘G(Ku)∘αc=G(f)∘αc.G(f') \circ \alpha_{c'} \circ F(u) = G(f') \circ G(Ku) \circ \alpha_c = G(f) \circ \alpha_c .

So there is a unique σd:L(d)→G(d)\sigma_d : L(d) \to G(d) with σd∘ι(c,f)=G(f)∘αc\sigma_d \circ \iota_{(c, f)} = G(f) \circ \alpha_c. It is natural in dd, because for g:d→d′g : d \to d' both σd′∘L(g)\sigma_{d'} \circ L(g) and G(g)∘σdG(g) \circ \sigma_d send ι(c,f)\iota_{(c,f)} to G(gf)∘αcG(gf) \circ \alpha_c. Finally σKc∘ηc=σKc∘ι(c,id)=G(id)∘αc=αc\sigma_{Kc} \circ \eta_c = \sigma_{Kc} \circ \iota_{(c, \mathrm{id})} = G(\mathrm{id}) \circ \alpha_c = \alpha_c.

Uniqueness. If σ′:L⇒G\sigma' : L \Rightarrow G also satisfies σKc′∘ηc=αc\sigma'_{Kc} \circ \eta_c = \alpha_c, then, using ι(c,f)=L(f)∘ι(c,id)=L(f)∘ηc\iota_{(c, f)} = L(f) \circ \iota_{(c, \mathrm{id})} = L(f) \circ \eta_c and naturality of σ′\sigma',

σd′∘ι(c,f)=σd′∘L(f)∘ηc=G(f)∘σKc′∘ηc=G(f)∘αc=σd∘ι(c,f),\sigma'_d \circ \iota_{(c, f)} = \sigma'_d \circ L(f) \circ \eta_c = G(f) \circ \sigma'_{Kc} \circ \eta_c = G(f) \circ \alpha_c = \sigma_d \circ \iota_{(c, f)} ,

so σd′=σd\sigma'_d = \sigma_d by the uniqueness of maps out of a colimit.

∎

Theorem— Corollary (existence)

If C\mathcal{C} is small, D\mathcal{D} is locally small and E\mathcal{E} has all small colimits, then every F:C→EF : \mathcal{C} \to \mathcal{E} has a pointwise left Kan extension along every KK, so LanK⊣K∗\mathrm{Lan}_K \dashv K^*. Dually, if E\mathcal{E} has all small limits, K∗⊣RanKK^* \dashv \mathrm{Ran}_K.

Proof

Each (K↓d)(K \downarrow d) is small: its objects form the set ∐cD(Kc,d)\coprod_{c} \mathcal{D}(Kc, d) (a set because C\mathcal{C} is small and D\mathcal{D} locally small), and its morphisms are among those of C\mathcal{C}. So the colimits in Theorem 1 exist. The dual statement is Theorem 1 applied to KopK^{\mathrm{op}} and FopF^{\mathrm{op}}.

∎

Theorem— Proposition 2 (extension along a fully faithful functor)

If KK is fully faithful and LanKF\mathrm{Lan}_K F is pointwise, then the unit η:F⇒(LanKF)K\eta : F \Rightarrow (\mathrm{Lan}_K F) K is a natural isomorphism: the Kan extension really extends FF.

Proof

In (K↓Kc)(K \downarrow Kc) the object (c,idKc)(c, \mathrm{id}_{Kc}) is terminal: given (c′,f:Kc′→Kc)(c', f : Kc' \to Kc), full faithfulness gives a unique u:c′→cu : c' \to c with K(u)=fK(u) = f, which is exactly a unique morphism (c′,f)→(c,id)(c', f) \to (c, \mathrm{id}). The colimit of a diagram over a category with a terminal object tt is its value at tt, with coprojection at tt an isomorphism. Here that coprojection is ι(c,id)=ηc\iota_{(c, \mathrm{id})} = \eta_c.

∎

The hypothesis matters: the two-point example above shows what happens for a KK that is not injective on objects.

Theorem— Proposition 3 (limits are right Kan extensions)

For F:J→EF : J \to \mathcal{E}, an object ℓ\ell with a cone λ:ℓ∘!⇒F\lambda : \ell \circ {!} \Rightarrow F is a right Kan extension of FF along !:J→1! : J \to \mathbf{1} if and only if (ℓ,λ)(\ell, \lambda) is a limit of FF.

Proof

Functors 1→E\mathbf{1} \to \mathcal{E} are objects, and natural transformations between them are morphisms. A transformation β:c∘!⇒F\beta : c \circ {!} \Rightarrow F is a cone with vertex cc, and for σ:c→ℓ\sigma : c \to \ell the composite λ∘(σ !)\lambda \circ (\sigma\, {!}) is the cone (λj∘σ)j(\lambda_j \circ \sigma)_j. So the universal property of Ran!\mathrm{Ran}_! — every β\beta equals λ∘(σ !)\lambda \circ (\sigma\, !) for a unique σ\sigma — is word for word the universal property of a limit.

∎

Theorem— Theorem 4 (adjoints are Kan extensions; Mac Lane)

A functor G:A→XG : \mathcal{A} \to \mathcal{X} has a left adjoint if and only if the right Kan extension (R,ε)=RanGidA(R, \varepsilon) = \mathrm{Ran}_G \mathrm{id}_{\mathcal{A}} exists and is preserved by GG, meaning that (GR,Gε)(GR, G\varepsilon) is a right Kan extension of GG along GG. In that case RR is the left adjoint, with counit ε\varepsilon. In fact, if F⊣GF \dashv G then (F,ε)(F, \varepsilon) is preserved by every functor out of A\mathcal{A}.

Proof

(⇒\Rightarrow) Let F⊣GF \dashv G with unit η:idX⇒GF\eta : \mathrm{id}_{\mathcal{X}} \Rightarrow GF, counit ε:FG⇒idA\varepsilon : FG \Rightarrow \mathrm{id}_{\mathcal{A}}, and triangle identities Gε∘ηG=1GG\varepsilon \circ \eta G = 1_G and εF∘Fη=1F\varepsilon F \circ F\eta = 1_F. Let P:A→BP : \mathcal{A} \to \mathcal{B} be any functor; we show (PF,Pε)(PF, P\varepsilon) is a right Kan extension of PP along GG. Given H:X→BH : \mathcal{X} \to \mathcal{B} and β:HG⇒P\beta : HG \Rightarrow P, put σx=βFx∘H(ηx):H(x)→PF(x)\sigma_x = \beta_{Fx} \circ H(\eta_x) : H(x) \to PF(x). Then, by naturality of β\beta at εa\varepsilon_a and the first triangle identity,

P(εa)∘σGa=P(εa)∘βFGa∘H(ηGa)=βa∘HG(εa)∘H(ηGa)=βa∘H(G(εa)∘ηGa)=βa.P(\varepsilon_a) \circ \sigma_{Ga} = P(\varepsilon_a) \circ \beta_{FGa} \circ H(\eta_{Ga}) = \beta_a \circ HG(\varepsilon_a) \circ H(\eta_{Ga}) = \beta_a \circ H\big(G(\varepsilon_a) \circ \eta_{Ga}\big) = \beta_a .

If σ′\sigma' is another solution, the second triangle identity and naturality of σ′\sigma' at ηx\eta_x give

σx′=P(εFx)∘PF(ηx)∘σx′=P(εFx)∘σGFx′∘H(ηx)=βFx∘H(ηx)=σx.\sigma'_x = P(\varepsilon_{Fx}) \circ PF(\eta_x) \circ \sigma'_x = P(\varepsilon_{Fx}) \circ \sigma'_{GFx} \circ H(\eta_x) = \beta_{Fx} \circ H(\eta_x) = \sigma_x .

Taking P=idP = \mathrm{id} shows (F,ε)=RanGid(F, \varepsilon) = \mathrm{Ran}_G \mathrm{id}; taking P=GP = G shows that GG preserves it.

(⇐\Leftarrow) Suppose (R,ε:RG⇒idA)(R, \varepsilon : RG \Rightarrow \mathrm{id}_{\mathcal{A}}) is RanGid\mathrm{Ran}_G \mathrm{id} and (GR,Gε)(GR, G\varepsilon) is RanGG\mathrm{Ran}_G G. Apply the universal property of (GR,Gε)(GR, G\varepsilon) to the identity transformation 1G:idXG⇒G1_G : \mathrm{id}_{\mathcal{X}} G \Rightarrow G: there is a unique η:idX⇒GR\eta : \mathrm{id}_{\mathcal{X}} \Rightarrow GR with Gε∘ηG=1GG\varepsilon \circ \eta G = 1_G, which is one triangle identity. For the other, both 1R1_R and τ=εR∘Rη\tau = \varepsilon R \circ R\eta are transformations R⇒RR \Rightarrow R, and the universal property of (R,ε)(R, \varepsilon) says there is only one τ\tau with ε∘τG=ε\varepsilon \circ \tau G = \varepsilon. The identity qualifies, and so does τ\tau: by naturality of ε\varepsilon at the arrow εa\varepsilon_a,

εa∘εRGa∘R(ηGa)=εa∘RG(εa)∘R(ηGa)=εa∘R(G(εa)∘ηGa)=εa.\varepsilon_a \circ \varepsilon_{RGa} \circ R(\eta_{Ga}) = \varepsilon_a \circ RG(\varepsilon_a) \circ R(\eta_{Ga}) = \varepsilon_a \circ R\big(G(\varepsilon_a) \circ \eta_{Ga}\big) = \varepsilon_a .

Hence εR∘Rη=1R\varepsilon R \circ R\eta = 1_R. Both triangle identities hold, so R⊣GR \dashv G with unit η\eta and counit ε\varepsilon.

∎

Note the twist: a left adjoint is a right Kan extension, F=RanGidF = \mathrm{Ran}_G \mathrm{id}, and dually a right adjoint is a left Kan extension, G=LanFidG = \mathrm{Lan}_F \mathrm{id}. In posets: the ceiling function, left adjoint to Z↪R\mathbb{Z} \hookrightarrow \mathbb{R}, is an infimum; the floor, right adjoint, is a supremum.

Theorem— Theorem 5 (extending along the Yoneda embedding)

Let C\mathcal{C} be small, E\mathcal{E} cocomplete and locally small, F:C→EF : \mathcal{C} \to \mathcal{E}, and y:C→C^=[Cop,Set]y : \mathcal{C} \to \widehat{\mathcal{C}} = [\mathcal{C}^{\mathrm{op}}, \mathbf{Set}] the Yoneda embedding. Then L=LanyFL = \mathrm{Lan}_y F exists and is given by

L(P)=colim⁡(c, x)∈∫PF(c),L(P) = \operatorname*{colim}_{(c,\, x) \in \int P} F(c),

the colimit over the category of elements of PP (objects: pairs c∈Cc \in \mathcal{C}, x∈P(c)x \in P(c)). Moreover L∘y≅FL \circ y \cong F; LL is left adjoint to the “nerve” NF:E→C^N_F : \mathcal{E} \to \widehat{\mathcal{C}}, NF(e)=E(F(−),e)N_F(e) = \mathcal{E}(F(-), e); and LL is, up to isomorphism, the unique colimit-preserving functor C^→E\widehat{\mathcal{C}} \to \mathcal{E} whose composite with yy is isomorphic to FF.

Proof

Sketch. By the Yoneda lemma an arrow y(c)→Py(c) \to P is the same as an element x∈P(c)x \in P(c), and this identifies the comma category (y↓P)(y \downarrow P) with ∫P\int P (up to size: C^\widehat{\mathcal{C}} is locally small because C\mathcal{C} is small, so ∫P\int P is small). Theorem 1 gives the formula. The Yoneda embedding is fully faithful, so Proposition 2 gives Ly≅FLy \cong F. For the adjunction, maps out of a colimit are compatible families:

E(LP,e)≅lim⁡(c,x)∈∫PE(Fc,e)≅Nat(P,E(F(−),e)),\mathcal{E}(L P, e) \cong \lim_{(c, x) \in \int P} \mathcal{E}(F c, e) \cong \mathrm{Nat}\big(P, \mathcal{E}(F(-), e)\big),

the second step because a natural transformation P⇒NF(e)P \Rightarrow N_F(e) is exactly an assignment x↦(Fc→e)x \mapsto (Fc \to e) compatible with restriction. Being a left adjoint, LL preserves colimits. Uniqueness: every presheaf is canonically the colimit of representables over its category of elements (the density theorem, which is the case F=yF = y), so a colimit-preserving functor is determined by its values on representables. Full details: Riehl (2016), Chapter 6, or Mac Lane and Moerdijk (1992), Chapter I.

∎

This “nerve and realisation” pattern appears all over mathematics: with F:Δ→TopF : \Delta \to \mathbf{Top}, [n]↦Δn[n] \mapsto \Delta^n, it gives geometric realisation ∣−∣⊣Sing|{-}| \dashv \mathrm{Sing}; with F:Δ→CatF : \Delta \to \mathbf{Cat}, [n]↦[n] \mapsto the poset {0<⋯<n}\{0 < \dots < n\}, it gives the nerve of a category and its left adjoint.

Formal mathematicsF

Kan extensions in Lean

The Lean module has two parts.

Part 1 (independent): the thin case. For preorders C,DC, D and a complete lattice EE, everything above can be proved from scratch, because in a thin category a natural transformation exists exactly when there is a pointwise inequality, and colimits and limits in a complete lattice are suprema and infima. The definitions are the pointwise formulas:

lanLean 4Formally verified
/-- The **pointwise left Kan extension** of `f : C → E` along `k : C → D`, for a preorder `D`
and a complete lattice `E` (the order of `C`, if any, plays no role in the formula):
`lan k f d = ⨆ { f c | k c ≤ d }`.
This is the formula `(Lan_k f)(d) = colim_{(k ↓ d)} f`: in a thin category the comma category
`(k ↓ d)` is the set of `c` with `k c ≤ d`, and a colimit in a complete lattice is a supremum. -/
def lan (k : C → D) (f : C → E) (d : D) : E :=
  ⨆ (c : C) (_ : k c ≤ d), f c
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
ranLean 4Formally verified
/-- The **pointwise right Kan extension**: `ran k f d = ⨅ { f c | d ≤ k c }`, the limit of `f`
over the comma category `(d ↓ k)`. -/
def ran (k : C → D) (f : C → E) (d : D) : E :=
  ⨅ (c : C) (_ : d ≤ k c), f c
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

lan k f is a functor, the unit exists, and the universal property holds — the poset shadow of Theorem 1:

lan_monotoneLean 4Proved here from basic factsFormally verified
/-- `lan k f` is a functor, i.e. monotone: if `d ≤ d'` then every `c` with `k c ≤ d` also has
`k c ≤ d'`, so the supremum can only grow. (This is how a pointwise Kan extension acts on
arrows: an arrow `d → d'` induces a functor `(k ↓ d) → (k ↓ d')` and hence a map of colimits.) -/
theorem lan_monotone (k : C → D) (f : C → E) : Monotone (lan k f) := by
  intro d d' h
  exact iSup₂_le fun c hc => le_iSup₂_of_le c (hc.trans h) le_rfl
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
le_lan_compLean 4Proved here from basic factsFormally verified
/-- The **unit** `f ⇒ (Lan_k f) ∘ k`: `f c ≤ lan k f (k c)`, because `c` itself lies in the
comma category `(k ↓ k c)` (via the identity `k c ≤ k c`). -/
theorem le_lan_comp (k : C → D) (f : C → E) (c : C) : f c ≤ lan k f (k c) :=
  le_iSup₂_of_le c le_rfl le_rfl
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
lan_le_iffLean 4Proved here from basic factsFormally verified
/-- The **universal property** of the left Kan extension. For every monotone `g : D → E`:
`Lan_k f ≤ g` if and only if `f ≤ g ∘ k`.
(→) compose with the unit: `f c ≤ lan k f (k c) ≤ g (k c)`.
(←) each term `f c` with `k c ≤ d` satisfies `f c ≤ g (k c) ≤ g d` by monotonicity of `g`.
In a thin category, arrows are unique when they exist, so this *is* the statement that every
`f ⇒ g ∘ k` factors uniquely through the unit. -/
theorem lan_le_iff (k : C → D) (f : C → E) {g : D → E} (hg : Monotone g) :
    lan k f ≤ g ↔ ∀ c, f c ≤ g (k c) := by
  constructor
  · intro h c
    exact (le_lan_comp k f c).trans (h (k c))
  · intro h d
    exact iSup₂_le fun c hc => (h c).trans (hg hc)
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

Any functor with this universal property is lan k f (uniqueness of universal objects), and along an order embedding the extension restricts back to f (Proposition 2):

lan_uniqueLean 4Proved here from basic factsFormally verified
/-- **Uniqueness**: any monotone `L : D → E` with the universal property of a left Kan
extension equals the pointwise formula. As always with universal properties, the proof plays
the two universal properties against each other. -/
theorem lan_unique (k : C → D) (f : C → E) {L : D → E} (hL : Monotone L)
    (huniv : ∀ g : D → E, Monotone g → (L ≤ g ↔ ∀ c, f c ≤ g (k c))) :
    L = lan k f := by
  apply le_antisymm
  · exact (huniv (lan k f) (lan_monotone k f)).2 (le_lan_comp k f)
  · exact (lan_le_iff k f hL).2 ((huniv L hL).1 le_rfl)
Axioms used: Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
lan_comp_of_embeddingLean 4Proved here from basic factsFormally verified
/-- **Kan extension along a fully faithful functor is a genuine extension.** If `k` is an order
embedding (`k c ≤ k c' ↔ c ≤ c'`, the thin version of "fully faithful") and `f` is monotone,
then `lan k f (k c) = f c`: the unit is an isomorphism. The comma category `(k ↓ k c)` then
has the terminal object `c`, and a colimit over a category with a terminal object is the value
there. -/
theorem lan_comp_of_embedding [Preorder C] {k : C → D} (hk : ∀ c c', k c ≤ k c' ↔ c ≤ c') {f : C → E}
    (hf : Monotone f) (c : C) : lan k f (k c) = f c := by
  apply le_antisymm
  · exact iSup₂_le fun c' hc' => hf ((hk c' c).1 hc')
  · exact le_lan_comp k f c
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

Read as an adjunction between the preorders of monotone maps, the universal property is Lank⊣k∗\mathrm{Lan}_k \dashv k^*:

lan_gcLean 4Proved here from basic factsFormally verified
/-- **`Lan_k` is left adjoint to restriction along `k`.** On monotone maps (functors),
`Lan_k ⊣ k^*` where `k^* g = g ∘ k`: this is a Galois connection between the preorders of
functors `C →o E` and `D →o E` (ordered pointwise, i.e. by the existence of natural
transformations). It is `lan_le_iff` read as an adjunction. -/
theorem lan_gc [Preorder C] (k : C →o D) :
    GaloisConnection (fun f : C →o E => (⟨lan k f, lan_monotone k f⟩ : D →o E))
      (fun g : D →o E => g.comp k) := by
  intro f g
  exact lan_le_iff k f g.monotone
Axioms used: propextformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

The right Kan extension is dual, and limits and colimits are Kan extensions along the map to Unit (Proposition 3):

ran_monotoneLean 4Proved here from basic factsFormally verified
/-- `ran k f` is monotone: if `d ≤ d'`, every `c` with `d' ≤ k c` also has `d ≤ k c`, so the
infimum defining `ran k f d` is taken over a larger family and can only be smaller. -/
theorem ran_monotone (k : C → D) (f : C → E) : Monotone (ran k f) := by
  intro d d' h
  exact le_iInf₂ fun c hc => iInf₂_le_of_le c (h.trans hc) le_rfl
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
ran_comp_leLean 4Proved here from basic factsFormally verified
/-- The **counit** of the right Kan extension: `(Ran_k f) ∘ k ⇒ f`, i.e.
`ran k f (k c) ≤ f c`, because `c` lies in `(k c ↓ k)`. -/
theorem ran_comp_le (k : C → D) (f : C → E) (c : C) : ran k f (k c) ≤ f c :=
  iInf₂_le_of_le c le_rfl le_rfl
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
le_ran_iffLean 4Proved here from basic factsFormally verified
/-- The universal property of the **right** Kan extension, dual to `lan_le_iff`: for monotone
`g : D → E`, `g ≤ Ran_k f` if and only if `g ∘ k ≤ f`. -/
theorem le_ran_iff (k : C → D) (f : C → E) {g : D → E} (hg : Monotone g) :
    g ≤ ran k f ↔ ∀ c, g (k c) ≤ f c := by
  constructor
  · intro h c
    exact (h (k c)).trans (ran_comp_le k f c)
  · intro h d
    exact le_iInf₂ fun c hc => (hg hc).trans (h c)
Axioms used: No axiomsformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
ran_const_eq_iInfLean 4Proved here from basic factsFormally verified
/-- **A limit is a right Kan extension along the functor to the terminal category.** Along
`! : C → Unit`, the comma category `(() ↓ !)` is all of `C`, so `Ran_! f` at the unique object
is `⨅ c, f c`, the infimum — which is the limit of `f` in the complete lattice `E`. -/
theorem ran_const_eq_iInf (f : C → E) : ran (fun _ : C => ()) f () = ⨅ c, f c := by
  simp [ran]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
lan_const_eq_iSupLean 4Proved here from basic factsFormally verified
/-- Dually, a **colimit is a left Kan extension along `! : C → Unit`**: `Lan_! f () = ⨆ c, f c`. -/
theorem lan_const_eq_iSup (f : C → E) : lan (fun _ : C => ()) f () = ⨆ c, f c := by
  simp [lan]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

Theorem 4 for complete lattices, where adjunctions are Galois connections: a left adjoint is RanGid\mathrm{Ran}_G \mathrm{id}, a right adjoint is LanFid\mathrm{Lan}_F \mathrm{id}, and GG has a left adjoint exactly when it preserves RanGid\mathrm{Ran}_G \mathrm{id}. The last result is the adjoint functor theorem for complete lattices.

left_adjoint_eq_ranLean 4Proved here from basic factsFormally verified
/-- **A left adjoint is a right Kan extension of the identity.** If `F ⊣ G` (a Galois
connection `F x ≤ a ↔ x ≤ G a`), then `F = Ran_G id`, i.e.
`F x = ⨅ { a | x ≤ G a }`. In words: `F x` is the best approximation of `x` from above by
things of the form "an `a` with `x ≤ G a`". -/
theorem left_adjoint_eq_ran {F : X → A} {G : A → X} (gc : GaloisConnection F G) :
    F = ran G id := by
  funext x
  apply le_antisymm
  · exact le_iInf₂ fun a hx => (gc x a).2 hx
  · exact iInf₂_le_of_le (F x) (gc.le_u_l x) le_rfl
Axioms used: propext, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
right_adjoint_eq_lanLean 4Proved here from basic factsFormally verified
/-- Dually, **a right adjoint is a left Kan extension of the identity**: if `F ⊣ G` then
`G = Lan_F id`, i.e. `G a = ⨆ { x | F x ≤ a }` — the best approximation of `a` from below. -/
theorem right_adjoint_eq_lan {F : X → A} {G : A → X} (gc : GaloisConnection F G) :
    G = lan F id := by
  funext a
  apply le_antisymm
  · exact le_iSup₂_of_le (G a) (gc.l_u_le a) le_rfl
  · exact iSup₂_le fun x hx => (gc x a).1 hx
Axioms used: Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
exists_left_adjoint_iffLean 4Proved here from basic factsFormally verified
/-- **Mac Lane's criterion for adjoints, for complete lattices.** A monotone `G : A → X` has a
left adjoint if and only if `G` *preserves* the right Kan extension `Ran_G id`, meaning
`G ∘ Ran_G id = Ran_G G`:
`G (⨅ { a | x ≤ G a }) = ⨅ { G a | x ≤ G a }` for every `x`.
In a complete lattice `Ran_G id` always exists (it is the formula); the content is preservation.
The left adjoint is then `Ran_G id` (see `left_adjoint_eq_ran`). -/
theorem exists_left_adjoint_iff {G : A → X} (hG : Monotone G) :
    (∃ F : X → A, GaloisConnection F G) ↔ ∀ x, G (ran G id x) = ran G G x := by
  constructor
  · rintro ⟨F, gc⟩ x
    rw [← left_adjoint_eq_ran gc]
    apply le_antisymm
    · exact le_iInf₂ fun a hx => hG ((gc x a).2 hx)
    · exact iInf₂_le_of_le (F x) (gc.le_u_l x) le_rfl
  · intro h
    refine ⟨ran G id, fun x a => ⟨fun hxa => ?_, fun hxa => iInf₂_le_of_le a hxa le_rfl⟩⟩
    -- `x ≤ G (Ran_G id x)` because `G` preserves the infimum, and each term is `≥ x`.
    have hx : x ≤ G (ran G id x) := by
      rw [h x]
      exact le_iInf₂ fun _ hc => hc
    exact hx.trans (hG hxa)
Axioms used: propext, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
exists_left_adjoint_of_map_sInfLean 4Proved here from basic factsFormally verified
/-- **The adjoint functor theorem for complete lattices.** If `G : A → X` preserves all
infima, then `G` has a left adjoint. Preserving all infima includes preserving the particular
infimum `Ran_G id x = ⨅ { a | x ≤ G a }`, so this follows from `exists_left_adjoint_iff`;
monotonicity comes from preserving binary infima. -/
theorem exists_left_adjoint_of_map_sInf {G : A → X}
    (hG : ∀ s : Set A, G (sInf s) = ⨅ a ∈ s, G a) : ∃ F : X → A, GaloisConnection F G := by
  have mono : Monotone G := by
    intro a b hab
    have h := hG {a, b}
    rw [sInf_pair, inf_eq_left.2 hab] at h
    rw [h]
    exact iInf₂_le b (by simp)
  refine (exists_left_adjoint_iff mono).2 fun x => ?_
  have hs : ran G id x = sInf { a | x ≤ G a } := by
    simp [ran, sInf_eq_iInf]
  rw [hs, hG]
  simp [ran]
Axioms used: propext, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

Part 2 (library): the general theory. Mathlib has Kan extensions for arbitrary categories (Functor.LeftExtension, Functor.IsLeftKanExtension, Functor.leftKanExtension, pointwise Kan extensions in Mathlib.CategoryTheory.Functor.KanExtension.Pointwise). Two results of this lesson, in full generality, by applying Mathlib's theorems: LanL\mathrm{Lan}_L is left adjoint to restriction, and the pointwise formula with its existence conditions (Theorem 1 and its corollary).

lan_isLeftAdjointLean 4Applies a library theoremFormally verified
/-- **In general, `Lan_L` is left adjoint to restriction along `L`.** For any functor
`L : C ⥤ D` such that every `F : C ⥤ H` has a left Kan extension along `L`, the functor
`L.lan : (C ⥤ H) ⥤ (D ⥤ H)` is a left adjoint; its right adjoint is precomposition with `L`.
This applies Mathlib's `Functor.lanAdjunction` (with `Adjunction.isLeftAdjoint`). -/
theorem lan_isLeftAdjoint {C D H : Type*} [Category C] [Category D] [Category H]
    (L : C ⥤ D) [∀ F : C ⥤ H, L.HasLeftKanExtension F] :
    (L.lan : (C ⥤ H) ⥤ (D ⥤ H)).IsLeftAdjoint :=
  (L.lanAdjunction H).isLeftAdjoint
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor
lan_obj_iso_colimitLean 4Applies a library theoremFormally verified
/-- **The pointwise formula, in general.** If `C` is small, `D` is locally small (its
hom-sets live in the same universe) and `H` has all small colimits, then the left Kan extension
of `F : C ⥤ H` along `L : C ⥤ D` exists and its value at `d` is the colimit of `F` over the
comma category `(L ↓ d)` (`CostructuredArrow L d` in Mathlib).
This applies Mathlib's `Functor.leftKanExtensionObjIsoColimit`; the existence of the colimits
is found by instance search from `HasColimits H`. -/
theorem lan_obj_iso_colimit {C D H : Type*} [SmallCategory C] [Category D] [Category H]
    (L : C ⥤ D) (F : C ⥤ H) (d : D) [HasColimits H] :
    Nonempty ((L.leftKanExtension F).obj d ≅ colimit (CostructuredArrow.proj L d ⋙ F)) :=
  ⟨L.leftKanExtensionObjIsoColimit F d⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/KanExtensions.leanTry it in the Lean web editor

What is and is not formalised. Theorems 1–4 are proved here independently only in the thin case (posets valued in complete lattices); the general pointwise formula and adjunction are cited from Mathlib. Theorem 4 in general (with absolute Kan extensions) and Theorem 5 (extension along Yoneda) are not formalised in this module.

ComputationC

Computing Kan extensions of finite sets

For functors into finite sets the pointwise formulas are algorithms: a colimit is a disjoint union glued along the arrows (a union–find computation), and a limit is the set of compatible families. The experiment computes Lan and Ran along a map of finite posets, a colimit over a diagram with a terminal object, and induced and coinduced actions of the subgroups of S3S_3.

Pointwise Kan extensions of finite sets: colimits and limitsPythonExact computationExhaustive finite checkComputationally tested
"""Pointwise Kan extensions of finite set-valued functors, computed exactly.

The pointwise formulas say that a left Kan extension is a colimit over a
comma category and a right Kan extension is a limit. For diagrams of finite
sets both can be computed exactly: a colimit is a disjoint union glued by a
union-find structure, a limit is the set of compatible families. We use this
to (1) compare Lan and Ran along an inclusion of finite posets (coproducts
versus products, initial versus terminal objects), (2) see that a colimit over
a category with a terminal object is the value there, and (3) induce and
coinduce actions of subgroups H of S3, checking |G x_H X| = [G:H] |X| and
|Hom_H(G, X)| = |X|^[G:H]. This is exact, exhaustive computation in finite
cases; the general theorems are proved in the lesson.
"""

from itertools import permutations, product

def colimit(sets, arrows):
    """Colimit of a finite diagram of finite sets.

    ``sets`` maps each object to a list of elements; ``arrows`` is a list of
    ``(source, target, function)``. Returns the equivalence classes of the
    disjoint union {(object, element)} under (s, x) ~ (t, function(x)).
    """
    parent = {(o, x): (o, x) for o in sets for x in sets[o]}

    def find(a):
        while parent[a] != a:
            parent[a] = parent[parent[a]]
            a = parent[a]
        return a

    for source, target, fn in arrows:
        for x in sets[source]:
            ra, rb = find((source, x)), find((target, fn(x)))
            if ra != rb:
                parent[ra] = rb
    classes = {}
    for a in parent:
        classes.setdefault(find(a), set()).add(a)
    return [frozenset(c) for c in classes.values()]

def limit(sets, arrows):
    """Limit of a finite diagram of finite sets: all compatible families.

    A family picks one element of each set; it is compatible when
    ``function(family[source]) == family[target]`` for every arrow. The empty
    diagram has exactly one (empty) family: the limit is a one-point set.
    """
    objects = list(sets)
    families = []
    for values in product(*(sets[o] for o in objects)):
        family = dict(zip(objects, values))
        if all(fn(family[s]) == family[t] for s, t, fn in arrows):
            families.append(family)
    return families

def thin_diagram(objects, leq, sets, fmap):
    """Restrict a functor on a poset to ``objects`` (all arrows c < c')."""
    arrows = [
        (c, c2, (lambda x, c=c, c2=c2: fmap(c, c2, x)))
        for c in objects
        for c2 in objects
        if c != c2 and leq(c, c2)
    ]
    return {c: sets[c] for c in objects}, arrows

def lan_size(C, leq_c, k, leq_d, d, sets, fmap):
    """|Lan_k F (d)|: the colimit of F over the comma category (k | d)."""
    comma = [c for c in C if leq_d(k(c), d)]
    return len(colimit(*thin_diagram(comma, leq_c, sets, fmap)))

def ran_size(C, leq_c, k, leq_d, d, sets, fmap):
    """|Ran_k F (d)|: the limit of F over the comma category (d | k)."""
    comma = [c for c in C if leq_d(d, k(c))]
    return len(limit(*thin_diagram(comma, leq_c, sets, fmap)))

def compose(p, q):
    """Composite permutation p o q (first q, then p) of tuples."""
    return tuple(p[i] for i in q)

S3 = sorted(permutations(range(3)))

def induced_diagram(G, H, X, act):
    """F o proj on the comma category (i | *) for i : BH -> BG.

    Objects are g in G; for g2 in G and h in H there is an arrow
    g2 h -> g2 acting on X by h. Its colimit is G x_H X.
    """
    sets = {g: list(X) for g in G}
    arrows = [(compose(g2, h), g2, (lambda x, h=h: act(h, x)))
              for g2 in G for h in H]
    return sets, arrows

def coinduced_diagram(G, H, X, act):
    """F o proj on (* | i): arrows g -> h g acting by h; limit Hom_H(G, X)."""
    sets = {g: list(X) for g in G}
    arrows = [(g, compose(h, g), (lambda x, h=h: act(h, x)))
              for g in G for h in H]
    return sets, arrows

def sign(p):
    """Sign of a permutation tuple (+1 or -1), by counting inversions."""
    inv = sum(1 for i in range(len(p)) for j in range(i) if p[j] > p[i])
    return -1 if inv % 2 else 1

# Poset example: C = {a, b} discrete inside D = {bot < a, b < top}.
POSET_C = ["a", "b"]
POSET_D = ["bot", "a", "b", "top"]
POSET_SETS = {"a": [0, 1], "b": [0, 1, 2]}

def leq_d(x, y):
    """The order of D = {bot < a, b < top}."""
    return x == y or x == "bot" or y == "top"

def leq_discrete(x, y):
    """The discrete order: only x <= x."""
    return x == y

# Chain example: 0 < 1 < 2 with F(0) -> F(1) -> F(2).
CHAIN = [0, 1, 2]
CHAIN_SETS = {0: list(range(4)), 1: list(range(3)), 2: list(range(2))}

def chain_map(c, c2, x):
    """F(c <= c2): halve from F(0) to F(1), take parity from F(1) to F(2)."""
    if c == 0 and c2 >= 1:
        x, c = x // 2, 1
    if c == 1 and c2 == 2:
        x = x % 2
    return x

def subgroup_cases():
    """(name, H, X, action) for the induction table."""
    swap = [(0, 1, 2), (1, 0, 2)]
    a3 = [p for p in S3 if sign(p) == 1]
    return [
        ("H = <(0 1)>, X = {+1,-1}, sign", swap, [1, -1],
         lambda h, x: sign(h) * x),
        ("H = A3, X = {0,1,2}, rotation", a3, [0, 1, 2],
         lambda h, x: h[x]),
        ("H = 1, X = {*}", [(0, 1, 2)], ["*"], lambda h, x: x),
    ]

def main():
    print("1. Lan and Ran along C = {a, b} (discrete) -> D = {bot < a, b < top}")
    print("   with |F a| = 2, |F b| = 3:")
    print("   d     |Lan F(d)|  |Ran F(d)|")
    for d in POSET_D:
        lan = lan_size(POSET_C, leq_discrete, lambda c: c, leq_d, d,
                       POSET_SETS, None)
        ran = ran_size(POSET_C, leq_discrete, lambda c: c, leq_d, d,
                       POSET_SETS, None)
        print(f"   {d:<5} {lan:>10}  {ran:>10}")
    print("   Lan(top) is the coproduct 2 + 3, Ran(bot) the product 2 x 3;")
    print("   Lan(bot) = 0 is an empty colimit, Ran(top) = 1 an empty limit.")
    print()
    print("2. Along C = {0 < 1 < 2} -> 1 with |F| = 4, 3, 2:")
    sets, arrows = thin_diagram(CHAIN, lambda x, y: x <= y, CHAIN_SETS,
                                chain_map)
    print(f"   colim F has {len(colimit(sets, arrows))} elements = |F(2)|"
          f" (2 is terminal); lim F has {len(limit(sets, arrows))} = |F(0)|.")
    print()
    print("3. Kan extension along BH -> BG, G = S3 (|G| = 6):")
    print("   case                                 [G:H]  |Lan|  |Ran|")
    for name, H, X, act in subgroup_cases():
        index = len(S3) // len(H)
        lan = len(colimit(*induced_diagram(S3, H, X, act)))
        ran = len(limit(*coinduced_diagram(S3, H, X, act)))
        print(f"   {name:<37} {index:>5}  {lan:>5}  {ran:>5}")
    print("   Lan = G x_H X has [G:H]|X| elements; Ran = Hom_H(G, X) has")
    print("   |X|^[G:H]. For H = 1, Lan is G acting on itself: the free G-set.")
    print()
    print("Epistemic status: exact computation of finite colimits and limits;")
    print("it confirms the pointwise formulas and the induction counts only in")
    print("these finite examples. The general statements (the pointwise")
    print("formula and its consequences) are theorems proved in the lesson.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

What to notice: at the top of the poset, Lan gives the coproduct (2+32 + 3); at the bottom, Ran gives the product (2×32 \times 3); at aa and bb, both restrict back to FF, as Proposition 2 predicts for an order embedding. For groups, induction multiplies by the index while coinduction exponentiates. This is exact computation in finitely many cases — it illustrates the theorems but does not prove them.

Explore

Seeing the pointwise formula

A left Kan extension at dd is a colimit: each object (c,f)(c, f) of (K↓d)(K \downarrow d) contributes a coprojection, and each morphism u:(c,f)→(c′,f′)u : (c, f) \to (c', f') forces a triangle to commute.

F(c)F(c)
F(c′)F(c')
(LanKF)(d)(\mathrm{Lan}_K F)(d)
F(u)F(u)
ι(c,f)\iota_{(c,f)}
ι(c′,f′)\iota_{(c',f')}
The colimit cocone over the comma category: whenever f′∘K(u)=ff' \circ K(u) = f, the triangle commutes.

In the poset example of the experiment (C={a,b}C = \{a, b\} discrete inside {⊥<a,b<⊤}\{\bot < a, b < \top\}), the comma category at ⊤\top is {a,b}\{a, b\} and the one under ⊥\bot is {a,b}\{a, b\} as well, so the two extensions produce the two universal constructions on the pair F(a),F(b)F(a), F(b):

(RankF)(⊥)=F(a)×F(b)(\mathrm{Ran}_k F)(\bot) = F(a) \times F(b)
F(a)F(a)
F(b)F(b)
(LankF)(⊤)=F(a)⊔F(b)(\mathrm{Lan}_k F)(\top) = F(a) \sqcup F(b)
π1\pi_1
π2\pi_2
ι1\iota_1
ι2\iota_2
Right Kan extension at the bottom is a limit (product); left Kan extension at the top is a colimit (coproduct).

Try it yourself: in the experiment's code, change the sizes of F(a)F(a) and F(b)F(b) in POSET_SETS and predict the table before running it. Then compare part 2 of the experiment: there the indexing category is the chain 0<1<20 < 1 < 2, which has the terminal object 22, so the colimit is F(2)F(2) and, dually, the limit is the value F(0)F(0) at the initial object.

Exercises

Exercises

1. Kan extensions

Warm-upHuman

Let CC and DD be posets, EE a complete lattice, k:C→Dk : C \to D monotone and f:C→Ef : C \to E monotone, all viewed as thin categories and functors. Which formula gives the pointwise left Kan extension (Lankf)(d)(\mathrm{Lan}_k f)(d)?

Choose one

2. Kan extensions

Warm-upHuman

Let K:{a,b}→1K : \{a, b\} \to \mathbf{1} be the functor from the discrete category with two objects to the terminal category, and let F:{a,b}→SetF : \{a, b\} \to \mathbf{Set} have ∣F(a)∣=3|F(a)| = 3 and ∣F(b)∣=4|F(b)| = 4. How many elements does (LanKF)(∗)(\mathrm{Lan}_K F)(\ast) have?

3. Kan extensions

CoreHuman

Let HH be a subgroup of index 33 in a finite group GG, let i:BH→BGi : \mathbf{B}H \to \mathbf{B}G be the inclusion of one-object categories, and let XX be an HH-set (a functor BH→Set\mathbf{B}H \to \mathbf{Set}) with ∣X∣=2|X| = 2. How many elements does the right Kan extension (RaniX)(∗)=HomH(G,X)(\mathrm{Ran}_i X)(\ast) = \mathrm{Hom}_H(G, X) have?

4. Kan extensions

CoreHuman

In the proof that the pointwise formula gives a left Kan extension, given G:D→EG : \mathcal{D} \to \mathcal{E} and α:F⇒GK\alpha : F \Rightarrow G K, we define σd:(LanKF)(d)→G(d)\sigma_d : (\mathrm{Lan}_K F)(d) \to G(d) by σd∘ι(c,f)=G(f)∘αc\sigma_d \circ \iota_{(c,f)} = G(f) \circ \alpha_c. For this to make sense, the maps G(f)∘αcG(f) \circ \alpha_c must form a cocone over (K↓d)(K \downarrow d): for u:(c,f)→(c′,f′)u : (c, f) \to (c', f') we need G(f′)∘αc′∘F(u)=G(f)∘αcG(f') \circ \alpha_{c'} \circ F(u) = G(f) \circ \alpha_c. Which fact gives this?

Choose one

5. Kan extensions

CoreHuman

Which situation gives a functor FF with no left Kan extension along KK?

Choose one

6. Kan extensions

CoreHuman

Which of these are Kan extensions? (Choose all that apply.)

Choose all that apply

7. Kan extensions

StretchHuman

Suppose F⊣GF \dashv G with G:A→XG : \mathcal{A} \to \mathcal{X}, unit η\eta and counit ε\varepsilon. Which statement is correct?

Choose one

8. Kan extensions

CoreFormal

In the lesson's Lean file, lan k f d = ⨆ (c : C) (_ : k c ≤ d), f c. Which Lean statement says that Lank\mathrm{Lan}_k is left adjoint to restriction along kk (for monotone k:C→Dk : C \to D, on monotone maps into a complete lattice EE)?

Choose one

9. Kan extensions

CoreComputational

Let CC be a finite set of sample points in R\mathbb{R}, k:C↪Rk : C \hookrightarrow \mathbb{R} the inclusion and f:C→R∪{±∞}f : C \to \mathbb{R} \cup \{\pm\infty\} any function, given as a dictionary {point: value}. Write lan_value(f, d) returning (Lankf)(d)=sup⁡{f(c)∣c≤d}(\mathrm{Lan}_k f)(d) = \sup\{ f(c) \mid c \le d \} (use float('-inf') for an empty supremum) and ran_value(f, d) returning (Rankf)(d)=inf⁡{f(c)∣c≥d}(\mathrm{Ran}_k f)(d) = \inf\{ f(c) \mid c \ge d \} (float('inf') if empty). Then check: when ff is not monotone, Lankf\mathrm{Lan}_k f is its running maximum, the smallest monotone function above ff on the sample points.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

“Kan extensions always exist.” They do not: the two-point example above has no extension at all, because the target lacks a join. The standard sufficient condition is: C\mathcal{C} small, D\mathcal{D} locally small, and E\mathcal{E} cocomplete (for Lan\mathrm{Lan}) or complete (for Ran\mathrm{Ran}). The local smallness of D\mathcal{D} is easy to forget: it is what makes the comma categories (K↓d)(K \downarrow d) small. Not every Kan extension that exists is pointwise either; in practice the pointwise ones are the ones that behave well.

Misconception

Confusing left and right. Left Kan extensions are computed by colimits over (K↓d)(K \downarrow d) — “everything that maps to dd” — and right Kan extensions by limits over (d↓K)(d \downarrow K). Mnemonic: floor is Lan\mathrm{Lan}, ceiling is Ran\mathrm{Ran}. But beware the twist: a left adjoint is a right Kan extension, F=RanGidF = \mathrm{Ran}_G \mathrm{id}, because its counit FG⇒idFG \Rightarrow \mathrm{id} has the shape of a Kan extension counit.

Misconception

“A Kan extension restricts back to the original functor.” Only when the unit is an isomorphism, which holds for pointwise extensions along fully faithful KK (Proposition 2). Along K:{a,b}→1K : \{a, b\} \to \mathbf{1}, (LanKF)K(a)=F(a)⊔F(b)≠F(a)(\mathrm{Lan}_K F)K(a) = F(a) \sqcup F(b) \neq F(a).

Misconception

“A Kan extension is just some extension.” The universal property is the point: LanKF\mathrm{Lan}_K F is the initial functor equipped with F⇒(−)KF \Rightarrow (-)K. In the floor example infinitely many monotone functions extend the integers; the Kan extensions are the two extreme ones.

ViewpointsH

Viewpoints

Algebra— Induction, Frobenius reciprocity and extension of scalars

For a subgroup H≤GH \le G and the inclusion i:BH→BGi : \mathbf{B}H \to \mathbf{B}G, restriction i∗i^* is restriction of representations from GG to HH. For functors into Vectk\mathrm{Vect}_k, the pointwise formula gives

LaniV=k[G]⊗k[H]V=IndHGV,RaniV=Homk[H](k[G],V)=CoIndHGV,\mathrm{Lan}_i V = k[G] \otimes_{k[H]} V = \mathrm{Ind}_H^G V, \qquad \mathrm{Ran}_i V = \mathrm{Hom}_{k[H]}(k[G], V) = \mathrm{CoInd}_H^G V,

and the adjunctions Lani⊣i∗⊣Rani\mathrm{Lan}_i \dashv i^* \dashv \mathrm{Ran}_i are Frobenius reciprocity: HomG(IndHGV,W)≅HomH(V,ResHGW)\mathrm{Hom}_G(\mathrm{Ind}_H^G V, W) \cong \mathrm{Hom}_H(V, \mathrm{Res}^G_H W), and its dual. For linear representations and [G:H]<∞[G:H] < \infty, induction and coinduction are isomorphic; for GG-sets they are not ([G:H] ∣X∣[G:H]\,|X| versus ∣X∣[G:H]|X|^{[G:H]} elements), which the experiment shows. More generally, a ring homomorphism R→SR \to S is a functor between one-object Ab\mathbf{Ab}-enriched categories, and the enriched left Kan extension of a module along it is extension of scalars S⊗RMS \otimes_R M, with coextension HomR(S,M)\mathrm{Hom}_R(S, M) on the right; this needs the enriched theory of enriched categories, where Kan extensions are coends.

Topology— Inverse images of presheaves and geometric realisation

Let f:X→Yf : X \to Y be continuous and write O(X)\mathcal{O}(X) for the poset of open sets. Preimage is a monotone map f−1:O(Y)→O(X)f^{-1} : \mathcal{O}(Y) \to \mathcal{O}(X). For a presheaf F\mathcal{F} on YY, the pushforward is just precomposition, f∗F=F∘(f−1)opf_*\mathcal{F} = \mathcal{F} \circ (f^{-1})^{\mathrm{op}}, so its left adjoint is a left Kan extension along (f−1)op(f^{-1})^{\mathrm{op}}. The pointwise formula computes it: the comma category at an open U⊆XU \subseteq X consists of the opens V⊆YV \subseteq Y with U⊆f−1(V)U \subseteq f^{-1}(V), i.e. f(U)⊆Vf(U) \subseteq V, so

(fpre−1F)(U)=colim⁡V⊇f(U)F(V),(f^{-1}_{\mathrm{pre}} \mathcal{F})(U) = \operatorname*{colim}_{V \supseteq f(U)} \mathcal{F}(V),

the familiar formula for the presheaf inverse image (the sheaf inverse image is its sheafification; see sheaves). Geometric realisation of simplicial sets is the left Kan extension of [n]↦Δn[n] \mapsto \Delta^n along the Yoneda embedding Δ→sSet\Delta \to \mathbf{sSet} (Theorem 5), with right adjoint the singular complex. Beyond this lesson: in homotopy theory one needs homotopy Kan extensions (derived functors of Lan\mathrm{Lan}, such as homotopy colimits), and in ∞-categories Kan extensions are defined up to coherent homotopy.

Analysis— Best approximations from below and above

Let f:Q→Rf : \mathbb{Q} \to \mathbb{R} be monotone and k:Q↪Rk : \mathbb{Q} \hookrightarrow \mathbb{R} the inclusion, with values in the complete lattice [−∞,∞][-\infty, \infty]. Then

(Lankf)(x)=sup⁡q≤xf(q),(Rankf)(x)=inf⁡q≥xf(q).(\mathrm{Lan}_k f)(x) = \sup_{q \le x} f(q), \qquad (\mathrm{Ran}_k f)(x) = \inf_{q \ge x} f(q).

Both extend ff (since kk is an order embedding), every monotone extension gg of ff satisfies Lankf≤g≤Rankf\mathrm{Lan}_k f \le g \le \mathrm{Ran}_k f, and at an irrational xx the two are the one-sided limits f(x−)f(x^-) and f(x+)f(x^+). They differ exactly at the jumps of ff, and a monotone real-valued function has at most countably many jumps (disjoint open intervals each contain a rational). So the monotone extension of ff to R\mathbb{R} is unique if and only if ff has no jumps at irrational points. The Python exercise computes these envelopes on finitely many sample points.

Logic— Quantifiers are Kan extensions

Regard a function f:X→Yf : X \to Y as a functor between discrete categories, and a predicate on XX as a functor P:X→2={⊥≤⊤}P : X \to \mathbf{2} = \{\bot \le \top\}. Then the pointwise formulas give

(LanfP)(y)=∃x (f(x)=y∧P(x)),(RanfP)(y)=∀x (f(x)=y⇒P(x)),(\mathrm{Lan}_f P)(y) = \exists x\, \big(f(x) = y \wedge P(x)\big), \qquad (\mathrm{Ran}_f P)(y) = \forall x\, \big(f(x) = y \Rightarrow P(x)\big),

and Lanf⊣f∗⊣Ranf\mathrm{Lan}_f \dashv f^* \dashv \mathrm{Ran}_f is Lawvere's discovery that ∃f⊣f∗⊣∀f\exists_f \dashv f^* \dashv \forall_f: quantifiers are adjoint to substitution. For a projection X×Y→XX \times Y \to X these are the ordinary quantifiers over YY. See categorical logic.

Computation— Codensity monads and faster programs

For any functor G:A→XG : \mathcal{A} \to \mathcal{X}, if the right Kan extension T=RanGGT = \mathrm{Ran}_G G exists it carries a canonical monad structure, the codensity monad of GG; when GG has a left adjoint FF, T≅GFT \cong GF is the monad of the adjunction (by Theorem 4, applied with P=GP = G). A classical example (Kennison and Gildenhuys, 1971): the codensity monad of the inclusion FinSet↪Set\mathbf{FinSet} \hookrightarrow \mathbf{Set} is the ultrafilter monad. In functional programming, Haskell's Codensity m a = forall b. (a -> m b) -> m b is Ranmm\mathrm{Ran}_m m written as an end, and Voigtländer (2008) used it to turn left-nested binds of free monads from quadratic into linear time.

Category-theoretic connectionH

All concepts are Kan extensions

Mac Lane's slogan collects the results of this lesson:

  • limits and colimits are Kan extensions along J→1J \to \mathbf{1} (Proposition 3);
  • adjoints are Kan extensions of identities, F=RanGidF = \mathrm{Ran}_G \mathrm{id} and G=LanFidG = \mathrm{Lan}_F \mathrm{id} (Theorem 4);
  • density and Yoneda: the density theorem says Lany y≅idC^\mathrm{Lan}_y\, y \cong \mathrm{id}_{\widehat{\mathcal{C}}} — every presheaf is canonically a colimit of representables (Theorem 5 with F=yF = y);
  • monads arise as codensity monads RanGG\mathrm{Ran}_G G.

Even Kan extensions are Kan extensions: the definition uses only functors, natural transformations and their composites, so it makes sense in any 2-category, and the pointwise formula becomes a weighted colimit (a coend, ∫cD(Kc,d)⋅F(c)\int^{c} \mathcal{D}(Kc, d) \cdot F(c)) in the enriched setting of Kelly (1982). The slogan is an exaggeration — not every concept is usefully a Kan extension — but it records how often a construction turns out to be “the best approximation along a functor”.

Wonder Trails

Wonder Trail

The product A×BA \times B is the right Kan extension of the pair (A,B)(A, B) along the functor from the two-object discrete category to 1\mathbf{1}. This trail explores its universal property from first principles.

Wonder Trail · Optional · never gradedThe product, by its mapsCan you describe the set of pairs A×BA \times B without ever looking inside it — only by how functions go into it?Follow the trail
History & global context

History and global context

  • Daniel M. Kan (born in the Netherlands, later at MIT) introduced adjoint functors in his paper Adjoint functors (Transactions of the American Mathematical Society, 1958), working in homotopy theory and simplicial sets. The same paper constructs what are now called Kan extensions, by the colimit and limit formulas.
  • In the 1960s, the Grothendieck school's work on topos theory (SGA 4, 1963–64) made systematic use of extending functors from a site to all presheaves by colimits, and F. William Lawvere showed that quantifiers are adjoint to substitution (1969).
  • Saunders Mac Lane's Categories for the Working Mathematician (1971) ends its chapter on Kan extensions with the section “All concepts are Kan extensions”.
  • Eduardo Dubuc (Argentina) developed Kan extensions in enriched category theory (Springer Lecture Notes 145, 1970), and G. M. Kelly (Sydney) made pointwise enriched Kan extensions central in Basic Concepts of Enriched Category Theory (1982).
  • Today Kan extensions are basic tools in homotopy theory (homotopy Kan extensions, ∞-categorical Kan extensions in Lurie's Higher Topos Theory, 2009), in representation theory, in algebraic geometry, and in functional programming.
Further reading

Further reading

  • Saunders Mac Lane, Categories for the Working Mathematician (1971; 2nd edition 1998), Chapter X — Kan extensions, pointwise extensions, density, and “all concepts are Kan extensions”.
  • Emily Riehl, Category Theory in Context (2016), Chapter 6 — a modern account with many examples.
  • Fosco Loregian, (Co)end Calculus (2021) — Kan extensions as coends, with applications.
  • G. M. Kelly, Basic Concepts of Enriched Category Theory (1982), Chapter 4 — enriched and pointwise Kan extensions.
  • Emily Riehl, Categorical Homotopy Theory (2014) — homotopy Kan extensions and derived functors.
  • Daniel M. Kan, “Adjoint functors”, Transactions of the American Mathematical Society 87 (1958) — the original paper.
  • Saunders Mac Lane and Ieke Moerdijk, Sheaves in Geometry and Logic (1992), Chapter I — presheaves, colimits of representables and the nerve–realisation adjunction.