MathLabs

Foundations of mathematics

The Yoneda lemma

An object is completely determined, up to isomorphism, by the pattern of every arrow pointing into it from everywhere else in the category — the Yoneda lemma turns that observation into a precise bijection, and its corollary that the embedding A↦Hom(−,A)A\mapsto\mathrm{Hom}(-,A) is fully faithful is the single fact that makes "study objects by their maps" a rigorous method rather than a slogan.

IntuitionAn object is what it does

To know an electronic component completely, you do not need to look inside it — it is enough to know, for every possible surrounding circuit, exactly how the component could be wired into it. In a category, the analogous fact is that an object AA is completely pinned down, up to isomorphism, by knowing Hom(X,A)\mathrm{Hom}(X,A) — the set of ways to map into AA — for every single object XX at once.

Interactive diagram of a network of objects with all morphisms pointing toward one distinguished object A.
Every arrow from every object XX into AA, collected at once — the data the presheaf hAh_A records.

UndergraduateRepresentable presheaves

Definition: The presheaf hAh_A

For an object AA of C\mathcal{C}, the representable presheaf hA=HomC(−,A)h_A=\mathrm{Hom}_{\mathcal{C}}(-,A) assigns to every object XX the set hA(X)=HomC(X,A)h_A(X)=\mathrm{Hom}_{\mathcal{C}}(X,A), and to every morphism g:X→Yg:X\to Y the precomposition map hA(g):Hom(Y,A)→Hom(X,A),f↦f∘gh_A(g):\mathrm{Hom}(Y,A)\to\mathrm{Hom}(X,A),\quad f\mapsto f\circ g. This makes hAh_A a functor Cop→Set\mathcal{C}^{\mathrm{op}}\to\mathbf{Set} — contravariant, because composing on the right with gg reverses the direction of the assignment.

hA(X)=HomC(X,A)h_A(X) = \mathrm{Hom}_{\mathcal{C}}(X,A)

Given any functor F:Cop→SetF:\mathcal{C}^{\mathrm{op}}\to\mathbf{Set}, the Yoneda lemma says the natural transformations from hAh_A to FF are in bijection with the elements of the single set F(A)F(A): Nat(HomC(−,A),F)≅F(A)\mathrm{Nat}(\mathrm{Hom}_{\mathcal{C}}(-,A),F)\cong F(A). The bijection is built from two maps, Φ\Phi and Ψ\Psi, going in opposite directions.

Nat(HomC(−,A),F)≅F(A)\mathrm{Nat}(\mathrm{Hom}_{\mathcal{C}}(-,A), F) \cong F(A)
The two directions of the Yoneda bijection
MapDirectionFormula
Φ\PhiNat(hA,F)→F(A)\mathrm{Nat}(h_A,F)\to F(A)Φ(η)=ηA(1A)\Phi(\eta)=\eta_A(1_A)
Ψ\PsiF(A)→Nat(hA,F)F(A)\to\mathrm{Nat}(h_A,F)Ψ(x)X(f)=F(f)(x)\Psi(x)_X(f)=F(f)(x)

AdvancedThe bijection, proved step by step

Φ\Phi evaluates a natural transformation η:hA⇒F\eta:h_A\Rightarrow F at the most economical possible input — the identity 1A∈hA(A)=Hom(A,A)1_A\in h_A(A)=\mathrm{Hom}(A,A) — producing the element ηA(1A)\eta_A(1_A) of F(A)F(A). In the reverse direction, Ψ\Psi starts from an element x∈F(A)x\in F(A) and reconstructs, for every object XX and every f∈Hom(X,A)f\in\mathrm{Hom}(X,A), an element of F(X)F(X) by pushing xx forward along F(f)F(f): Ψ(x)X(f)=F(f)(x)\Psi(x)_X(f)=F(f)(x). Naturality of η\eta is exactly what makes Ψ(Φ(η))\Psi(\Phi(\eta)) recover η\eta, and this is what the next theorem proves in full.

Φ(η)=ηA(1A)\Phi(\eta) = \eta_A(1_A)
Ψ(x)X(f)=F(f)(x)\Psi(x)_X(f) = F(f)(x)

For every functor F:Cop→SetF:\mathcal{C}^{\mathrm{op}}\to\mathbf{Set} and object AA, the maps Φ\Phi and Ψ\Psi above are mutually inverse, so Nat(HomC(−,A),F)≅F(A)\mathrm{Nat}(\mathrm{Hom}_{\mathcal{C}}(-,A),F)\cong F(A) as a genuine bijection of sets.

Why is it true?

This is what lets category theorists trade an infinite, hard-to-grasp family of natural transformations for a single concrete element of F(A)F(A) — every question about maps out of the representable presheaf hAh_A collapses to a question about one set.

Proof

We first check Φ(Ψ(x))=x\Phi(\Psi(x))=x for every x∈F(A)x\in F(A). Unwind the definitions: Ψ(x)A(1A)=F(1A)(x)\Psi(x)_A(1_A)=F(1_A)(x) by the formula for Ψ\Psi, specialized to X=AX=A, f=1Af=1_A. Since FF is a functor, it sends the identity morphism 1A1_A to the identity function on F(A)F(A), so F(1A)(x)=xF(1_A)(x)=x. Therefore Φ(Ψ(x))=Ψ(x)A(1A)=x\Phi(\Psi(x))=\Psi(x)_A(1_A)=x, exactly as required — this direction uses nothing but the functor identity law.

Now we check the harder direction, Ψ(Φ(η))=η\Psi(\Phi(\eta))=\eta for every natural transformation η:hA⇒F\eta:h_A\Rightarrow F. Both sides are natural transformations hA⇒Fh_A\Rightarrow F, so it suffices to show their components agree at every object XX and every element f∈hA(X)=Hom(X,A)f\in h_A(X)=\mathrm{Hom}(X,A).

Unwind Ψ(Φ(η))X(f)\Psi(\Phi(\eta))_X(f) using the formula for Ψ\Psi with x:=Φ(η)=ηA(1A)x:=\Phi(\eta)=\eta_A(1_A): this equals F(f)(ηA(1A))F(f)(\eta_A(1_A)).

Now invoke naturality of η\eta itself, in the form ηY(f∘g)=F(g)(ηX(f))\eta_Y(f\circ g)=F(g)(\eta_X(f)) with g:=f:X→Ag:=f:X\to A and the other variable set to AA: taking f:=1A∈hA(A)f:=1_A\in h_A(A) in that naturality square gives exactly ηX(1A∘f)=F(f)(ηA(1A))\eta_X(1_A\circ f)=F(f)(\eta_A(1_A)), i.e. ηX(f)=F(f)(ηA(1A))\eta_X(f)=F(f)(\eta_A(1_A)), since 1A∘f=f1_A\circ f=f.

Combining the last two displays: Ψ(Φ(η))X(f)=F(f)(ηA(1A))=ηX(f)\Psi(\Phi(\eta))_X(f)=F(f)(\eta_A(1_A))=\eta_X(f). Since XX and ff were arbitrary, the two natural transformations agree everywhere, so Ψ(Φ(η))=η\Psi(\Phi(\eta))=\eta. Together with the first paragraph, Φ\Phi and Ψ\Psi are mutually inverse bijections.

The Yoneda embedding y:C↪[Cop,Set]y:\mathcal{C}\hookrightarrow[\mathcal{C}^{\mathrm{op}},\mathbf{Set}], y(A)=hAy(A)=h_A, is fully faithful: for every A,B∈CA,B\in\mathcal{C}, Nat(hA,hB)≅HomC(A,B)\mathrm{Nat}(h_A,h_B)\cong\mathrm{Hom}_{\mathcal{C}}(A,B), and this bijection sends a morphism f:A→Bf:A\to B to the natural transformation hA⇒hBh_A\Rightarrow h_B given by postcomposition with ff.

Why is it true?

Full faithfulness is exactly the guarantee that the translation A↦hAA\mapsto h_A loses no information whatsoever: distinct morphisms of C\mathcal{C} become distinct natural transformations, and every natural transformation between two representable presheaves comes from an actual morphism of C\mathcal{C}, which is what justifies studying objects purely through the maps into them.

Proof

Apply the Yoneda lemma with the target functor set to F:=hBF:=h_B. The lemma gives a bijection Nat(hA,hB)≅hB(A)\mathrm{Nat}(h_A,h_B)\cong h_B(A), and unwinding the definition hB(A)=HomC(A,B)h_B(A)=\mathrm{Hom}_{\mathcal{C}}(A,B) gives exactly Nat(hA,hB)≅HomC(A,B)\mathrm{Nat}(h_A,h_B)\cong\mathrm{Hom}_{\mathcal{C}}(A,B).

It remains to identify what morphism of C\mathcal{C} a natural transformation η:hA⇒hB\eta:h_A\Rightarrow h_B corresponds to under this bijection, and to check it is postcomposition. By the formula for Φ\Phi, η\eta corresponds to the element Φ(η)=ηA(1A)∈Hom(A,B)\Phi(\eta)=\eta_A(1_A)\in\mathrm{Hom}(A,B); call this morphism ff.

Now use Ψ(Φ(η))=η\Psi(\Phi(\eta))=\eta (the theorem above, applied with F=hBF=h_B) to recover every component of η\eta from ff: for any object XX and any g∈hA(X)=Hom(X,A)g\in h_A(X)=\mathrm{Hom}(X,A), Ψ(f)X(g)=hB(g)(f)\Psi(f)_X(g)=h_B(g)(f). Unwinding the contravariant action of hBh_B on morphisms — precomposition — gives hB(g)(f)=f∘gh_B(g)(f)=f\circ g. So ηX(g)=f∘g\eta_X(g)=f\circ g: every component of η\eta is literally postcomposition with ff.

Because Φ\Phi and Ψ\Psi are mutually inverse bijections (proved above) and postcomposition with ff is exactly Ψ(f)\Psi(f), the assignment sending ff to postcomposition with ff is itself a bijection Hom(A,B)→Nat(hA,hB)\mathrm{Hom}(A,B)\to\mathrm{Nat}(h_A,h_B) — which is precisely the statement that yy is fully faithful.

UndergraduateApplications: moduli spaces and continuation-passing style

In algebraic geometry, a moduli space for some kind of geometric object (curves, vector bundles, ...) is defined by first writing down a functor FF sending a test object XX to the set of families of that geometric structure over XX; the moduli space, if it exists, is an object MM representing FF, i.e. F≅hMF\cong h_M. The Yoneda embedding being fully faithful is exactly why such an MM, when it exists, is unique up to a unique isomorphism — Grothendieck's "functor of points" philosophy treats every scheme as nothing more than its representable presheaf. In functional programming, the type ∀r. (a→r)→r\forall r.\ (a\to r)\to r of continuation-passing style functions is, by construction, the type of natural transformations from the covariant Hom-functor Hom(a,−)\mathrm{Hom}(a,-) to the identity functor; the (covariant, dual) Yoneda lemma says exactly ∀r. (a→r)→rcong a\forall r.\ (a\to r)\to r \\cong\ a, matching the everyday fact that a CPS-transformed value is nothing more than a repackaged ordinary value.

Example: Checking the bijection on a two-object category

Let C\mathcal{C} have two objects 0,10,1, identities, and one non-identity morphism ι:0→1\iota:0\to1. Take A=1A=1 and F=h1F=h_1 itself. Verify by direct enumeration that Nat(HomC(−,A),F)≅F(A)\mathrm{Nat}(\mathrm{Hom}_{\mathcal{C}}(-,A),F)\cong F(A) for this FF, i.e. that Nat(h1,h1)\mathrm{Nat}(h_1,h_1) has exactly as many elements as h1(1)=Hom(1,1)h_1(1)=\mathrm{Hom}(1,1).

Solution

First compute h1h_1 explicitly: h1(0)=Hom(0,1)={ι}h_1(0)=\mathrm{Hom}(0,1)=\{\iota\} (one element) and h1(1)=Hom(1,1)={11}h_1(1)=\mathrm{Hom}(1,1)=\{1_1\} (one element, since C\mathcal{C} has no other morphism ending at 11 from 11). So F(A)=h1(1)F(A)=h_1(1) has exactly one element, 111_1.

By the Yoneda lemma, Nat(h1,h1)\mathrm{Nat}(h_1,h_1) should also have exactly one element. Check this directly: a natural transformation η:h1⇒h1\eta:h_1\Rightarrow h_1 needs components η0:{ι}→{ι}\eta_0:\{\iota\}\to\{\iota\} and η1:{11}→{11}\eta_1:\{1_1\}\to\{1_1\}. Each of these sets has one element, so there is exactly one possible function at each object — the identity function — giving exactly one candidate η\eta overall.

One must still check this candidate satisfies naturality (it automatically does here, since the naturality square forces η0(ι)=η0(11∘ι)=h1(ι)(η1(11))=h1(ι)(11)=11∘ι=ι\eta_0(\iota)=\eta_0(1_1\circ\iota)=h_1(\iota)(\eta_1(1_1))=h_1(\iota)(1_1)=1_1\circ\iota=\iota, which holds since there is only one available value anyway).

So Nat(h1,h1)={idh1}\mathrm{Nat}(h_1,h_1)=\{\mathrm{id}_{h_1}\} has exactly one element, matching F(A)={11}F(A)=\{1_1\} having exactly one element — the bijection Nat(HomC(−,A),F)≅F(A)\mathrm{Nat}(\mathrm{Hom}_{\mathcal{C}}(-,A),F)\cong F(A) holds concretely, and Φ(idh1)=(idh1)1(11)=11\Phi(\mathrm{id}_{h_1})=(\mathrm{id}_{h_1})_1(1_1)=1_1 recovers the single element directly.

Example: Continuation-passing style as Yoneda

In a functional language, a value of type ∀r. (a→r)→r\forall r.\ (a\to r)\to r is a function kk that, given any way of consuming an aa (a function a→ra\to r), produces an rr. Show kk is completely determined by, and recovers, an ordinary value of type aa.

Solution

Identify C=Set\mathcal{C}=\mathbf{Set} (or the category of types and functions), fix the object aa, and let F=IdF=\mathrm{Id} be the identity functor. A value k:∀r. (a→r)→rk:\forall r.\ (a\to r)\to r is, by definition, a choice of function kr:(a→r)→rk_r:(a\to r)\to r for every type rr — exactly a natural transformation from the covariant functor Hom(a,−)\mathrm{Hom}(a,-) to Id\mathrm{Id} (naturality here is exactly the parametricity that "for all rr" enforces).

Apply Φ\Phi from the (covariant, dual) Yoneda lemma: Φ(k)=k(ida)\Phi(k)=k(\mathrm{id}_a) evaluates kk at r:=ar:=a on the identity function ida:a→a\mathrm{id}_a:a\to a, producing an ordinary value of type aa. This is the direction "continuation determines a value".

Apply Ψ\Psi in reverse: given a value n:an:a, define Ψ(n)r(g)=g(n)\Psi(n)_r(g)=g(n) for every rr and every g:a→rg:a\to r — that is, Ψ(n)r(g)=g(n)\Psi(n)_r(g)=g(n), the standard CPS-transform of a value: "the continuation that, given any consumer gg, hands nn to it".

By the Yoneda lemma applied to F=IdF=\mathrm{Id}, these two constructions are mutually inverse: Φ(Ψ(n))=Ψ(n)a(ida)=ida(n)=n\Phi(\Psi(n))=\Psi(n)_a(\mathrm{id}_a)=\mathrm{id}_a(n)=n recovers the value, and Ψ(Φ(k))=k\Psi(\Phi(k))=k by the naturality argument from the theorem above, specialized to F=IdF=\mathrm{Id}. Hence ∀r. (a→r)→rcong a\forall r.\ (a\to r)\to r \\cong\ a, confirming that continuation-passing style values carry exactly the information of an ordinary value, no more and no less.

What does Φ\Phi do to a natural transformation η:hA⇒F\eta:h_A\Rightarrow F?

The uniqueness step in Ψ(Φ(η))=η\Psi(\Phi(\eta))=\eta relies on which property of η\eta?

In continuation-passing style, the type ∀r. (a→r)→r\forall r.\ (a\to r)\to r is naturally isomorphic to which type?

The Yoneda embedding being fully faithful lets us conclude that a representing object MM for a moduli functor FF is:

References

  1. Saunders Mac Lane (1998). Categories for the Working Mathematician
  2. Emily Riehl (2016). Category Theory in Context
  3. Jacob Lurie (2009). Higher Topos Theory · arXiv:math/0608040