Skip to content
The Lumenary
Advanced undergraduateUndergraduate 110 min

The Yoneda lemma

A natural transformation out of Hom(A,−)\Hom(A, -) is decided by where it sends idA\id_A — and from this one-line idea, every object is determined by the arrows around it.

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

Known by your relationships

In 1854 Arthur Cayley observed that every group is a group of permutations: an element gg of GG can be replaced by the permutation x↦gxx \mapsto gx of GG, and nothing is lost. In a partially ordered set, an element xx is completely determined by the set {z∣z≤x}\{z \mid z \le x\} of elements below it. In linear algebra, a finite-dimensional vector space can be recovered from its dual, the linear maps out of it.

But "determined by its relationships" needs care. A topological space is not determined by its points: the sets {0,1}\{0, 1\} with the discrete and with the indiscrete topology have the same points — the same continuous maps from a one-point space — but they are different spaces. One kind of probe is not enough.

The Yoneda lemma says what is enough: probe an object AA with all objects, recording every arrow X→AX \to A and how the arrows compose. Then nothing is lost — AA can be recovered up to isomorphism, and arrows between objects are recovered exactly. The lemma itself is short and its proof is a single idea, but it is the reason universal properties determine objects, the reason Grothendieck could treat geometric spaces as functors, and the reason so many constructions in mathematics are "the same". This lesson builds on representable functors and natural transformations.

IntuitionH

Follow the identity

Fix an object AA and a functor F:C→SetF : \mathcal{C} \to \cat{Set}. A natural transformation α:Hom(A,−)⇒F\alpha : \Hom(A, -) \Rightarrow F consists of a function αX:Hom(A,X)→F(X)\alpha_X : \Hom(A, X) \to F(X) for every object XX — a huge amount of data, one function per object.

But among all arrows out of AA there is one special one: idA\id_A. Every arrow f:A→Xf : A \to X is obtained from it by composing, f=f∘idAf = f \circ \id_A. Naturality says that α\alpha commutes with composing, so αX(f)\alpha_X(f) must be obtained from αA(idA)\alpha_A(\id_A) by applying F(f)F(f). All the data of α\alpha is packed into the single element

αA(idA)∈F(A),\alpha_A(\id_A) \in F(A),

and any element of F(A)F(A) can be unpacked into a natural transformation. The identity arrow is a generic element: the most general AA-shaped thing, of which every other is a specialisation.

Hom(A,A)\Hom(A, A)
F(A)F(A)
Hom(A,X)\Hom(A, X)
F(X)F(X)
αA\alpha_A
f∘−f \circ -
F(f)F(f)
αX\alpha_X
Naturality along f:A→Xf : A \to X, applied to idA\id_A: going down then across gives αX(f)\alpha_X(f), going across then down gives F(f)(αA(idA))F(f)(\alpha_A(\id_A)).
DefinitionsH

Definitions

Throughout, C\mathcal{C} is locally small: every Hom(A,B)\Hom(A, B) is a set. For functors F,GF, G we write Nat(F,G)\mathrm{Nat}(F, G) for the collection of natural transformations F⇒GF \Rightarrow G.

Definition— presheaf

A presheaf on C\mathcal{C} is a functor P:Cop→SetP : \mathcal{C}^{\mathrm{op}} \to \cat{Set}. Presheaves and natural transformations form the presheaf category C^=[Cop,Set]\widehat{\mathcal{C}} = [\mathcal{C}^{\mathrm{op}}, \cat{Set}]. When C\mathcal{C} is small (its objects and arrows form sets), C^\widehat{\mathcal{C}} is locally small.

Definition— Yoneda embedding

The Yoneda embedding y:C→C^y : \mathcal{C} \to \widehat{\mathcal{C}} sends an object AA to the representable presheaf y(A)=Hom(−,A)y(A) = \Hom(-, A) and an arrow f:A→Bf : A \to B to the natural transformation y(f)=f∘−:Hom(−,A)⇒Hom(−,B)y(f) = f \circ - : \Hom(-, A) \Rightarrow \Hom(-, B).

Definition— the Yoneda map

For F:C→SetF : \mathcal{C} \to \cat{Set} and an object AA, define

Φ:Nat(Hom(A,−),F)→F(A),Φ(α)=αA(idA),\Phi : \mathrm{Nat}(\Hom(A, -), F) \to F(A), \qquad \Phi(\alpha) = \alpha_A(\id_A),

and, in the other direction, for x∈F(A)x \in F(A) let Ψ(x):Hom(A,−)⇒F\Psi(x) : \Hom(A, -) \Rightarrow F have components Ψ(x)X(f)=F(f)(x)\Psi(x)_X(f) = F(f)(x).

Some examples of the objects involved:

  • A group GG is a category BG\mathbf{B}G with one object ∗\ast, one arrow for each g∈Gg \in G, and composition g∘h=ghg \circ h = gh. A functor BG→Set\mathbf{B}G \to \cat{Set} is a set with a left GG-action, a presheaf on BG\mathbf{B}G is a set with a right action, and natural transformations are equivariant maps. The representable presheaf y(∗)y(\ast) is GG acting on itself by right multiplication.
  • A directed graph is a functor G:E→SetG : \mathbb{E} \to \cat{Set}, where E\mathbb{E} has two objects E,VE, V and two arrows s,t:E→Vs, t : E \to V besides identities: G(E)G(E) is the set of edges, G(V)G(V) the set of vertices, G(s)G(s) and G(t)G(t) give the source and target. Natural transformations are graph homomorphisms. The representable Hom(E,−)\Hom(E, -) is the walking edge (one edge, from ss to tt), and Hom(V,−)\Hom(V, -) is a single vertex.
  • A poset (P,≤)(P, \le) is a category with an arrow x→yx \to y exactly when x≤yx \le y. The representable Hom(−,x)\Hom(-, x) is, in effect, the down-set ↓x={z∣z≤x}\downarrow x = \{z \mid z \le x\}.
  • A simplicial set is a presheaf on the category Δ\Delta of finite ordinals [n]={0<1<⋯<n}[n] = \{0 < 1 < \dots < n\} and order-preserving maps; the representable Δ[n]=HomΔ(−,[n])\Delta[n] = \Hom_\Delta(-, [n]) is the standard nn-simplex.
ProofH

The Yoneda lemma and its consequences

Theorem— Theorem 1 (the Yoneda lemma)

Let C\mathcal{C} be locally small, F:C→SetF : \mathcal{C} \to \cat{Set} a functor and AA an object. Then Ψ(x)\Psi(x) is a natural transformation for every x∈F(A)x \in F(A), and Φ\Phi and Ψ\Psi are mutually inverse bijections

Nat(Hom(A,−),F)  ≅  F(A).\mathrm{Nat}(\Hom(A, -), F) \;\cong\; F(A).

Proof

Ψ(x)\Psi(x) is natural. For g:X→Yg : X \to Y and f:A→Xf : A \to X, functoriality of FF gives

Ψ(x)Y(g∘f)=F(g∘f)(x)=F(g)(F(f)(x))=F(g)(Ψ(x)X(f)).\Psi(x)_Y(g \circ f) = F(g \circ f)(x) = F(g)\big(F(f)(x)\big) = F(g)\big(\Psi(x)_X(f)\big).

Φ∘Ψ=id\Phi \circ \Psi = \id. Φ(Ψ(x))=Ψ(x)A(idA)=F(idA)(x)=x\Phi(\Psi(x)) = \Psi(x)_A(\id_A) = F(\id_A)(x) = x.

Ψ∘Φ=id\Psi \circ \Phi = \id. Let α:Hom(A,−)⇒F\alpha : \Hom(A, -) \Rightarrow F and f:A→Xf : A \to X. Naturality of α\alpha along ff says αX(f∘h)=F(f)(αA(h))\alpha_X(f \circ h) = F(f)(\alpha_A(h)) for every h:A→Ah : A \to A. Take h=idAh = \id_A:

αX(f)=αX(f∘idA)=F(f)(αA(idA))=Ψ(Φ(α))X(f).\alpha_X(f) = \alpha_X(f \circ \id_A) = F(f)\big(\alpha_A(\id_A)\big) = \Psi(\Phi(\alpha))_X(f).

So Ψ(Φ(α))\Psi(\Phi(\alpha)) and α\alpha agree at every component, at every arrow.

∎

A remark on size: even when C\mathcal{C} is large, so that a natural transformation is a "large" family, the lemma shows that Nat(Hom(A,−),F)\mathrm{Nat}(\Hom(A, -), F) is in bijection with a set.

Theorem— Theorem 2 (naturality of the Yoneda bijection)

The bijection Φ\Phi is natural in both FF and AA:

  1. for a natural transformation β:F⇒G\beta : F \Rightarrow G,   Φ(β∘α)=βA(Φ(α))\;\Phi(\beta \circ \alpha) = \beta_A(\Phi(\alpha));
  2. for an arrow f:A→A′f : A \to A',   Φ(α∘Hom(f,−))=F(f)(Φ(α))\;\Phi\big(\alpha \circ \Hom(f, -)\big) = F(f)(\Phi(\alpha)), where Hom(f,−):Hom(A′,−)⇒Hom(A,−)\Hom(f, -) : \Hom(A', -) \Rightarrow \Hom(A, -) is precomposition with ff.

So Φ\Phi is a natural isomorphism between the two functors C×[C,Set]→Set\mathcal{C} \times [\mathcal{C}, \cat{Set}] \to \cat{Set} given by (A,F)↦Nat(Hom(A,−),F)(A, F) \mapsto \mathrm{Nat}(\Hom(A, -), F) and (A,F)↦F(A)(A, F) \mapsto F(A).

Proof

(1) Φ(β∘α)=(β∘α)A(idA)=βA(αA(idA))\Phi(\beta \circ \alpha) = (\beta \circ \alpha)_A(\id_A) = \beta_A(\alpha_A(\id_A)), by the definition of vertical composition.

(2) Φ(α∘Hom(f,−))=αA′(Hom(f,−)A′(idA′))=αA′(idA′∘f)=αA′(f)\Phi(\alpha \circ \Hom(f, -)) = \alpha_{A'}\big(\Hom(f, -)_{A'}(\id_{A'})\big) = \alpha_{A'}(\id_{A'} \circ f) = \alpha_{A'}(f), and by the last step of the proof of Theorem 1, αA′(f)=F(f)(αA(idA))\alpha_{A'}(f) = F(f)(\alpha_A(\id_A)).

∎

Applying Theorem 1 to Cop\mathcal{C}^{\mathrm{op}} gives the form used for presheaves.

Theorem— Corollary 3 (contravariant form)

For a presheaf P:Cop→SetP : \mathcal{C}^{\mathrm{op}} \to \cat{Set} and an object AA, the map α↦αA(idA)\alpha \mapsto \alpha_A(\id_A) is a bijection Nat(Hom(−,A),P)≅P(A)\mathrm{Nat}(\Hom(-, A), P) \cong P(A), natural in AA and PP. Its inverse sends x∈P(A)x \in P(A) to the transformation f↦P(f)(x)f \mapsto P(f)(x), for f:X→Af : X \to A.

Theorem— Corollary 4 (the Yoneda embedding is full and faithful)

For all objects A,BA, B, the map f↦y(f)f \mapsto y(f) is a bijection Hom(A,B)≅Nat(y(A),y(B))\Hom(A, B) \cong \mathrm{Nat}(y(A), y(B)).

Proof

Take P=y(B)=Hom(−,B)P = y(B) = \Hom(-, B) in Corollary 3: Nat(y(A),y(B))≅Hom(A,B)\mathrm{Nat}(y(A), y(B)) \cong \Hom(A, B). The inverse bijection sends f:A→Bf : A \to B to the transformation g↦y(B)(g)(f)=f∘gg \mapsto y(B)(g)(f) = f \circ g, which is exactly y(f)y(f). So f↦y(f)f \mapsto y(f) is a bijection.

∎

Theorem— Corollary 5 (the Yoneda principle)

If Hom(−,A)≅Hom(−,B)\Hom(-, A) \cong \Hom(-, B) as presheaves, then A≅BA \cong B. More precisely, every natural isomorphism θ:y(A)≅y(B)\theta : y(A) \cong y(B) is y(φ)y(\varphi) for a unique isomorphism φ:A→B\varphi : A \to B. Dually, Hom(A,−)≅Hom(B,−)\Hom(A, -) \cong \Hom(B, -) implies A≅BA \cong B.

Proof

By Corollary 4, θ=y(φ)\theta = y(\varphi) and θ−1=y(ψ)\theta^{-1} = y(\psi) for unique arrows φ:A→B\varphi : A \to B and ψ:B→A\psi : B \to A. Since yy is a functor, y(ψ∘φ)=θ−1∘θ=idy(A)=y(idA)y(\psi \circ \varphi) = \theta^{-1} \circ \theta = \id_{y(A)} = y(\id_A), and since yy is faithful, ψ∘φ=idA\psi \circ \varphi = \id_A. Likewise φ∘ψ=idB\varphi \circ \psi = \id_B. The dual statement is the same argument for the covariant embedding A↦Hom(A,−)A \mapsto \Hom(A, -) of Cop\mathcal{C}^{\mathrm{op}}, using Theorem 1.

∎

This is why every universal property determines its object up to a unique isomorphism: a universal property says that some object represents a given functor, and two representing objects have isomorphic hom functors.

Theorem— Corollary 6 (Cayley's theorem)

For a group GG, the map g↦λgg \mapsto \lambda_g, λg(x)=gx\lambda_g(x) = gx, is an injective group homomorphism G→Sym(G)G \to \mathrm{Sym}(G). Its image consists exactly of the permutations σ\sigma with σ(xh)=σ(x)h\sigma(xh) = \sigma(x)h for all x,hx, h.

Proof

Apply Corollary 4 to BG\mathbf{B}G. The presheaf y(∗)y(\ast) is the set GG, on which an arrow hh acts by precomposition, x↦x∘h=xhx \mapsto x \circ h = xh. A natural transformation y(∗)⇒y(∗)y(\ast) \Rightarrow y(\ast) is therefore a map σ:G→G\sigma : G \to G with σ(xh)=σ(x)h\sigma(xh) = \sigma(x)h, and y(g)y(g) is post-composition x↦g∘x=gxx \mapsto g \circ x = gx, which is λg\lambda_g. Full faithfulness says every such σ\sigma is λg\lambda_g for exactly one gg (concretely, g=σ(e)g = \sigma(e), because σ(x)=σ(e x)=σ(e) x\sigma(x) = \sigma(e\,x) = \sigma(e)\,x). Functoriality of yy says λgh=λg∘λh\lambda_{gh} = \lambda_g \circ \lambda_h and λe=id\lambda_e = \id. So g↦λgg \mapsto \lambda_g is an injective homomorphism into Sym(G)\mathrm{Sym}(G), with the stated image.

∎

Theorem— Corollary 7 (Yoneda for posets)

In a poset, x≤yx \le y if and only if every z≤xz \le x also satisfies z≤yz \le y, i.e. ↓x⊆↓y\downarrow x \subseteq \downarrow y. In particular ↓x=↓y\downarrow x = \downarrow y implies x=yx = y.

Proof

This is Corollary 4 for a thin category, where a hom-set has at most one element: a natural transformation Hom(−,x)⇒Hom(−,y)\Hom(-, x) \Rightarrow \Hom(-, y) exists exactly when ↓x⊆↓y\downarrow x \subseteq \downarrow y, and an arrow x→yx \to y exists exactly when x≤yx \le y. Directly: if x≤yx \le y and z≤xz \le x then z≤yz \le y by transitivity; conversely take z=xz = x. The second claim follows by antisymmetry.

∎

Theorem— Corollary 8 (natural operations on groups)

Let U:Grp→SetU : \cat{Grp} \to \cat{Set} be the forgetful functor. Every natural transformation θ:U⇒U\theta : U \Rightarrow U is g↦gng \mapsto g^n for a unique n∈Zn \in \Z. Every natural transformation U×U⇒UU \times U \Rightarrow U is (g,h)↦w(g,h)(g, h) \mapsto w(g, h) for a unique word ww in the free group F2=⟨a,b⟩F_2 = \langle a, b \rangle.

Proof

U≅Hom(Z,−)U \cong \Hom(\Z, -) with universal element 11, and U×U≅Hom(F2,−)U \times U \cong \Hom(F_2, -) with universal element (a,b)(a, b). By Theorem 1, Nat(Hom(Z,−),U)≅U(Z)=Z\mathrm{Nat}(\Hom(\Z, -), U) \cong U(\Z) = \Z; the element nn corresponds to θG(g)=U(φg)(n)=gn\theta_G(g) = U(\varphi_g)(n) = g^n, where φg:Z→G\varphi_g : \Z \to G is the homomorphism with 1↦g1 \mapsto g. Similarly Nat(Hom(F2,−),U)≅U(F2)\mathrm{Nat}(\Hom(F_2, -), U) \cong U(F_2): the word ww corresponds to (g,h)↦w(g,h)(g, h) \mapsto w(g, h), the image of ww under the homomorphism a↦ga \mapsto g, b↦hb \mapsto h.

∎

So the only operations that make sense uniformly in all groups and commute with all homomorphisms are words: g−1g^{-1}, g2h−3g^2 h^{-3}, the commutator ghg−1h−1ghg^{-1}h^{-1}, and so on. "Conjugate by a fixed element" is not one of them — there is no fixed element common to all groups.

Theorem— Theorem 9 (density: presheaves are colimits of representables)

Let C\mathcal{C} be small and PP a presheaf on C\mathcal{C}. Let ∫P\int P be its category of elements: objects are pairs (c,x)(c, x) with x∈P(c)x \in P(c), and an arrow (c,x)→(c′,x′)(c, x) \to (c', x') is an arrow f:c→c′f : c \to c' with P(f)(x′)=xP(f)(x') = x. Then PP is the colimit of the diagram ∫P→C^\int P \to \widehat{\mathcal{C}}, (c,x)↦y(c)(c, x) \mapsto y(c), with coprojections λ(c,x):y(c)⇒P\lambda_{(c, x)} : y(c) \Rightarrow P the transformations corresponding to xx under Corollary 3.

Proof

Write Φ(α)=αc(idc)\Phi(\alpha) = \alpha_c(\id_c) for α:y(c)⇒Q\alpha : y(c) \Rightarrow Q, so that Φ(λ(c,x))=x\Phi(\lambda_{(c, x)}) = x. Corollary 3 with its naturality gives, for f:c′→cf : c' \to c and β:Q⇒R\beta : Q \Rightarrow R,

Φ(α∘y(f))=Q(f)(Φ(α)),Φ(β∘α)=βc(Φ(α)).\Phi(\alpha \circ y(f)) = Q(f)(\Phi(\alpha)), \qquad \Phi(\beta \circ \alpha) = \beta_c(\Phi(\alpha)).

Cocone. For an arrow f:(c,x)→(c′,x′)f : (c, x) \to (c', x') of ∫P\int P: Φ(λ(c′,x′)∘y(f))=P(f)(x′)=x=Φ(λ(c,x))\Phi(\lambda_{(c', x')} \circ y(f)) = P(f)(x') = x = \Phi(\lambda_{(c, x)}), so λ(c′,x′)∘y(f)=λ(c,x)\lambda_{(c', x')} \circ y(f) = \lambda_{(c, x)} because Φ\Phi is injective.

Factorisation. Let μ(c,x):y(c)⇒Q\mu_{(c, x)} : y(c) \Rightarrow Q be another cocone. Define τc:P(c)→Q(c)\tau_c : P(c) \to Q(c) by τc(x)=Φ(μ(c,x))\tau_c(x) = \Phi(\mu_{(c, x)}). It is natural: for f:c′→cf : c' \to c and x∈P(c)x \in P(c), ff is an arrow (c′,P(f)(x))→(c,x)(c', P(f)(x)) \to (c, x) of ∫P\int P, so μ(c,x)∘y(f)=μ(c′,P(f)(x))\mu_{(c, x)} \circ y(f) = \mu_{(c', P(f)(x))} and

τc′(P(f)(x))=Φ(μ(c,x)∘y(f))=Q(f)(Φ(μ(c,x)))=Q(f)(τc(x)).\tau_{c'}\big(P(f)(x)\big) = \Phi\big(\mu_{(c, x)} \circ y(f)\big) = Q(f)\big(\Phi(\mu_{(c, x)})\big) = Q(f)\big(\tau_c(x)\big).

And Φ(τ∘λ(c,x))=τc(x)=Φ(μ(c,x))\Phi(\tau \circ \lambda_{(c, x)}) = \tau_c(x) = \Phi(\mu_{(c, x)}), so τ∘λ(c,x)=μ(c,x)\tau \circ \lambda_{(c, x)} = \mu_{(c, x)}.

Uniqueness. If also τ′∘λ(c,x)=μ(c,x)\tau' \circ \lambda_{(c, x)} = \mu_{(c, x)} for all (c,x)(c, x), then τc′(x)=τc′(Φ(λ(c,x)))=Φ(τ′∘λ(c,x))=Φ(μ(c,x))=τc(x)\tau'_c(x) = \tau'_c(\Phi(\lambda_{(c, x)})) = \Phi(\tau' \circ \lambda_{(c, x)}) = \Phi(\mu_{(c, x)}) = \tau_c(x).

Since C\mathcal{C} is small, so is ∫P\int P, and this is a small colimit.

∎

For a simplicial set XX this says that XX is glued from standard simplices Δ[n]\Delta[n], one for each nn-simplex of XX — and Corollary 3 says that the nn-simplices of XX are the maps Δ[n]→X\Delta[n] \to X. In the Kan extensions lesson, density is the starting point for extending functors from C\mathcal{C} to all presheaves.

Worked examplesH

Worked examples

Example— Edges and vertices of a graph

Let GG be a directed graph, viewed as a functor E→Set\mathbb{E} \to \cat{Set}. A graph homomorphism from the walking edge Hom(E,−)\Hom(E, -) to GG is determined by where it sends the edge idE\id_E; by Theorem 1 it can send it to any edge of GG, and the endpoints s,ts, t must then go to that edge's source and target. So Nat(Hom(E,−),G)≅G(E)\mathrm{Nat}(\Hom(E, -), G) \cong G(E), the edges. Likewise homomorphisms from the one-vertex graph are the vertices. "The edges of GG are the maps from an edge" is the Yoneda lemma.

Example— Cayley's theorem for $S_3$

Write S3={e,r,r2,s,rs,r2s}S_3 = \{e, r, r^2, s, rs, r^2 s\} with r3=s2=er^3 = s^2 = e and srs−1=r−1srs^{-1} = r^{-1}. Left multiplication by rr permutes the six elements as two 3-cycles, (e  r  r2)(s  rs  r2s)(e\ \ r\ \ r^2)(s\ \ rs\ \ r^2 s); that is the permutation λr\lambda_r. Of the 6!=7206! = 720 permutations of S3S_3, exactly six commute with every right multiplication, and they are λe,λr,…\lambda_e, \lambda_r, \dots — the computation section finds them by brute force. Corollary 6 explains why: a permutation commuting with right multiplications is determined by where it sends ee.

Example— Divisibility

In (N≥1,∣)(\N_{\ge 1}, \mid), a∣ba \mid b exactly when every divisor of aa divides bb (Corollary 7). Two numbers with the same set of divisors are equal. Nothing deep — but it is the same theorem as Cayley's.

Example— Proving an isomorphism by Yoneda

For objects with products, (A×B)×C≅A×(B×C)(A \times B) \times C \cong A \times (B \times C). Instead of building the isomorphism by hand, compute hom-sets: naturally in XX,

Hom(X,(A×B)×C)≅Hom(X,A)×Hom(X,B)×Hom(X,C)≅Hom(X,A×(B×C)).\Hom(X, (A \times B) \times C) \cong \Hom(X, A) \times \Hom(X, B) \times \Hom(X, C) \cong \Hom(X, A \times (B \times C)).

So y((A×B)×C)≅y(A×(B×C))y((A \times B) \times C) \cong y(A \times (B \times C)), and Corollary 5 gives the isomorphism. The same technique proves A×B≅B×AA \times B \cong B \times A and, in a cartesian closed category, (CB)A≅CA×B(C^B)^A \cong C^{A \times B}.

Example— A natural operation that is not a power

Inversion g↦g−1g \mapsto g^{-1} is natural on groups: it is the power n=−1n = -1. On the category of abelian groups, U≅Hom(Z,−)U \cong \Hom(\Z, -) still, so the natural operations are again g↦ngg \mapsto ng. But on rings, U≅Hom(Z[x],−)U \cong \Hom(\Z[x], -), and the natural unary operations are the integer polynomials: r↦r2+3r−1r \mapsto r^2 + 3r - 1, and so on, one for each element of Z[x]\Z[x].

Formal mathematicsF

The Yoneda lemma in Lean

Mathlib's yoneda : C ⥤ (Cᵒᵖ ⥤ Type) sends A to Hom(−, A), and coyoneda sends A to Hom(A, −). Composition f ≫ g means "first f, then g" (so g∘fg \circ f is f ≫ g).

Theorem 1, independently. The two maps of the proof, then the two composites. The key step ofElement_toElement is the human proof's last line as a calc block: naturality applied to the identity, then 𝟙 A ≫ f = f.

toElementLean 4Formally verified
/-- The Yoneda map: a natural transformation `α : Hom(A, −) ⇒ F` goes to the element
`α_A(id_A) ∈ F(A)` — "where `α` sends the identity". -/
def toElement {A : C} {F : C ⥤ Type v} (α : coyoneda.obj (op A) ⟶ F) : F.obj A :=
  α.app A (𝟙 A)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
ofElementLean 4Formally verified
/-- The inverse map: an element `x ∈ F(A)` gives the natural transformation
`Hom(A, −) ⇒ F` whose component at `B` sends `f : A ⟶ B` to `F(f)(x)`. Naturality is
functoriality of `F`: `F(f ≫ g)(x) = F(g)(F(f)(x))`. -/
def ofElement {A : C} {F : C ⥤ Type v} (x : F.obj A) : coyoneda.obj (op A) ⟶ F where
  app B := ↾fun f => F.map f x
  naturality B B' g := by
    ext f
    exact Functor.map_comp_apply F f g x
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
ofElement_toElementLean 4Proved here from basic factsFormally verified
/-- **The heart of the Yoneda lemma**: a natural transformation `α : Hom(A, −) ⇒ F` is
determined by `α_A(id_A)`. For `f : A ⟶ B`, naturality of `α` along `f` applied to `id_A` gives
`α_B(f) = α_B(id_A ≫ f) = F(f)(α_A(id_A))`. -/
theorem ofElement_toElement {A : C} {F : C ⥤ Type v} (α : coyoneda.obj (op A) ⟶ F) :
    ofElement (toElement α) = α := by
  ext B f
  calc F.map f (α.app A (𝟙 A))
      = α.app B ((coyoneda.obj (op A)).map f (𝟙 A)) := (NatTrans.naturality_apply α f _).symm
    _ = α.app B (𝟙 A ≫ f) := rfl
    _ = α.app B f := by rw [Category.id_comp]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
toElement_ofElementLean 4Proved here from basic factsFormally verified
/-- The other composite: the transformation built from `x` sends `id_A` to `F(id_A)(x) = x`. -/
theorem toElement_ofElement {A : C} {F : C ⥤ Type v} (x : F.obj A) :
    toElement (ofElement x) = x :=
  Functor.map_id_apply F A x
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
yonedaBijectionLean 4Formally verified
/-- **The Yoneda lemma** (covariant form): `Nat(Hom(A, −), F) ≃ F(A)`, via `α ↦ α_A(id_A)`,
with inverse `x ↦ (f ↦ F(f)(x))`. Packaged from the two theorems above. -/
def yonedaBijection {A : C} {F : C ⥤ Type v} : (coyoneda.obj (op A) ⟶ F) ≃ F.obj A where
  toFun := toElement
  invFun := ofElement
  left_inv := ofElement_toElement
  right_inv := toElement_ofElement
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor

Theorem 2: naturality in FF and in AA.

toElement_natural_functorLean 4Proved here from basic factsFormally verified
/-- The Yoneda bijection is **natural in `F`**: following `α` by a transformation
`β : F ⇒ G` corresponds to applying `β_A` to the element. -/
theorem toElement_natural_functor {A : C} {F G : C ⥤ Type v} (α : coyoneda.obj (op A) ⟶ F)
    (β : F ⟶ G) : toElement (α ≫ β) = β.app A (toElement α) :=
  rfl
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
toElement_natural_objectLean 4Proved here from basic factsFormally verified
/-- The Yoneda bijection is **natural in `A`**: for `f : A ⟶ A'`, precomposing `α` with
`Hom(f, −) : Hom(A', −) ⇒ Hom(A, −)` corresponds to applying `F(f)` to the element. -/
theorem toElement_natural_object {A A' : C} {F : C ⥤ Type v} (f : A ⟶ A')
    (α : coyoneda.obj (op A) ⟶ F) :
    toElement (coyoneda.map f.op ≫ α) = F.map f (toElement α) := by
  calc toElement (coyoneda.map f.op ≫ α)
      = α.app A' (f ≫ 𝟙 A') := rfl
    _ = α.app A' f := by rw [Category.comp_id]
    _ = (ofElement (toElement α)).app A' f := by rw [ofElement_toElement]
    _ = F.map f (toElement α) := rfl
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor

Full faithfulness and the Yoneda principle, proved from Theorem 1 for the covariant embedding A↦Hom(A,−)A \mapsto \Hom(A, -):

nat_trans_representablesLean 4Proved here from basic factsFormally verified
/-- **Full and faithful**: every natural transformation `α : Hom(A, −) ⇒ Hom(B, −)` is
precomposition with exactly one arrow `g : B ⟶ A`, namely `g = α_A(id_A)`. This is the Yoneda
lemma for `F = Hom(B, −)`; it says that `coyoneda` is full and faithful. -/
theorem nat_trans_representables {A B : C}
    (α : coyoneda.obj (op A) ⟶ coyoneda.obj (op B)) :
    ∃! g : B ⟶ A, coyoneda.map g.op = α := by
  refine ⟨toElement α, ?_, ?_⟩
  · calc coyoneda.map (toElement α).op = ofElement (toElement α) := by
          ext X f
          rfl
      _ = α := ofElement_toElement α
  · intro g hg
    rw [← hg]
    exact (Category.comp_id g).symm
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
iso_of_corepresentable_isoLean 4Proved here from basic factsFormally verified
/-- **An object is determined by the arrows out of it.** If `Hom(A, −) ≅ Hom(B, −)` naturally,
then `A ≅ B`. With `g = e(id_A) : B ⟶ A` and `h = e⁻¹(id_B) : A ⟶ B`, the components of `e` and
`e⁻¹` are precomposition with `g` and `h`, and `e⁻¹ ∘ e = id` evaluated at `id_A` reads
`h ≫ g = id_A`; similarly `g ≫ h = id_B`. -/
theorem iso_of_corepresentable_iso {A B : C}
    (e : coyoneda.obj (op A) ≅ coyoneda.obj (op B)) : Nonempty (A ≅ B) := by
  have hom_app : ∀ (X : C) (f : A ⟶ X), e.hom.app X f = toElement e.hom ≫ f := fun X f =>
    calc e.hom.app X f = (ofElement (toElement e.hom)).app X f := by rw [ofElement_toElement]
      _ = toElement e.hom ≫ f := rfl
  have inv_app : ∀ (X : C) (f : B ⟶ X), e.inv.app X f = toElement e.inv ≫ f := fun X f =>
    calc e.inv.app X f = (ofElement (toElement e.inv)).app X f := by rw [ofElement_toElement]
      _ = toElement e.inv ≫ f := rfl
  refine ⟨⟨toElement e.inv, toElement e.hom, ?_, ?_⟩⟩
  · calc toElement e.inv ≫ toElement e.hom = e.inv.app A (toElement e.hom) := (inv_app A _).symm
      _ = e.inv.app A (e.hom.app A (𝟙 A)) := rfl
      _ = 𝟙 A := by simp
  · calc toElement e.hom ≫ toElement e.inv = e.hom.app B (toElement e.inv) := (hom_app B _).symm
      _ = e.hom.app B (e.inv.app B (𝟙 B)) := rfl
      _ = 𝟙 B := by simp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor

Mathlib's versions of Corollaries 3, 4 and 5 for the contravariant embedding, and the density theorem (Theorem 9):

yoneda_lemma_libraryLean 4Applies a library theoremFormally verified
/-- **The Yoneda lemma, contravariant form, from Mathlib**: for a presheaf `P : Cᵒᵖ ⥤ Type`,
`α ↦ α_A(id_A)` is a bijection `Nat(Hom(−, A), P) ≃ P(A)`. This applies Mathlib's
`yonedaEquiv`. -/
theorem yoneda_lemma_library (P : Cᵒᵖ ⥤ Type v) (A : C) :
    Function.Bijective (fun α : yoneda.obj A ⟶ P => α.app (op A) (𝟙 A)) :=
  yonedaEquiv.bijective
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
yoneda_fully_faithfulLean 4Applies a library theoremFormally verified
/-- **The Yoneda embedding `C ⥤ [Cᵒᵖ, Set]` is full and faithful**: `f ↦ yoneda.map f` is a
bijection `Hom(A, B) ≃ Nat(Hom(−, A), Hom(−, B))`. This applies Mathlib's
`Yoneda.fullyFaithful` and `FullyFaithful.map_bijective`. -/
theorem yoneda_fully_faithful (A B : C) :
    Function.Bijective (yoneda.map : (A ⟶ B) → (yoneda.obj A ⟶ yoneda.obj B)) :=
  Yoneda.fullyFaithful.map_bijective A B
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
iso_of_representable_isoLean 4Applies a library theoremFormally verified
/-- **An object is determined by the arrows into it**: `Hom(−, A) ≅ Hom(−, B)` implies
`A ≅ B`. This applies Mathlib's `FullyFaithful.preimageIso` to the Yoneda embedding. -/
theorem iso_of_representable_iso {A B : C} (e : yoneda.obj A ≅ yoneda.obj B) :
    Nonempty (A ≅ B) :=
  ⟨Yoneda.fullyFaithful.preimageIso e⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
densityLean 4Applies a library theoremFormally verified
/-- **Density: every presheaf is a colimit of representables.** For `P : Cᵒᵖ ⥤ Type`, the
cocone over all representables `Hom(−, A) ⟶ P` with apex `P` is a colimit cocone. This applies
Mathlib's `Presheaf.isColimitTautologicalCocone` (Kashiwara–Schapira, Prop. 2.6.3). -/
theorem density (P : Cᵒᵖ ⥤ Type v) :
    Nonempty (Limits.IsColimit (Presheaf.tautologicalCocone P)) :=
  ⟨Presheaf.isColimitTautologicalCocone P⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor

Cayley's theorem (Corollary 6). The faithful half is cayley_injective and the full half — every permutation commuting with right multiplications is a left multiplication — is equivariant_eq_cayley, whose calc block is the one-line Yoneda argument σ(x)=σ(1⋅x)=σ(1) x\sigma(x) = \sigma(1 \cdot x) = \sigma(1)\,x. Mathlib's version follows.

cayleyLean 4Formally verified
/-- The Cayley map `G → Sym(G)`, `g ↦ (x ↦ g x)` (Mathlib's `Equiv.mulLeft g`). It is the
Yoneda embedding of the one-object category of `G`: arrow `g` goes to "compose with `g`". -/
def cayley : G →* Equiv.Perm G where
  toFun g := Equiv.mulLeft g
  map_one' := by
    ext x
    simp
  map_mul' g h := by
    ext x
    simp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
cayley_injectiveLean 4Proved here from basic factsFormally verified
/-- **Cayley's theorem**: the Cayley map is injective, so every group is isomorphic to a group
of permutations (its image). Evaluate at `1`: if `g · 1 = h · 1` then `g = h` — the faithful
half of Yoneda, "a transformation is determined by where it sends the identity". -/
theorem cayley_injective : Function.Injective (cayley : G →* Equiv.Perm G) := by
  intro g h hgh
  have h1 : cayley g 1 = cayley h 1 := by rw [hgh]
  simpa [cayley] using h1
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
equivariant_eq_cayleyLean 4Proved here from basic factsFormally verified
/-- **The full half: the image of Cayley's map is exactly the equivariant permutations.**
A permutation `σ` of `G` that commutes with every right multiplication
(`σ (x h) = σ(x) h` — a natural transformation of the representable functor of the one-object
category) is left multiplication by `σ(1)`: `σ(x) = σ(1 · x) = σ(1) x`. -/
theorem equivariant_eq_cayley (σ : Equiv.Perm G) (hσ : ∀ x h : G, σ (x * h) = σ x * h) :
    σ = cayley (σ 1) := by
  ext x
  calc σ x = σ (1 * x) := by rw [one_mul]
    _ = σ 1 * x := hσ 1 x
    _ = cayley (σ 1) x := rfl
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor
cayley_libraryLean 4Applies a library theoremFormally verified
/-- Cayley's theorem from Mathlib: `G` is isomorphic to a subgroup of the permutations of `G`.
This applies Mathlib's `Equiv.Perm.subgroupOfMulAction` for the faithful action of `G` on
itself by left multiplication. -/
theorem cayley_library : Nonempty (G ≃* (MulAction.toPermHom G G).range) :=
  ⟨Equiv.Perm.subgroupOfMulAction G G⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Yoneda.leanTry it in the Lean web editor

Posets (Corollary 7).

le_iff_forall_leLean 4Proved here from basic factsFormally verified
/-- **Yoneda for preorders.** In a preorder (a category with at most one arrow between two
objects), `x ≤ y` exactly when everything below `x` is below `y`: "`Hom(−, x) ⇒ Hom(−, y)`
exists iff `Hom(x, y)` is inhabited". Forwards by transitivity; backwards apply the hypothesis
to `z = x` (the identity `x ≤ x`). -/
theorem le_iff_forall_le [Preorder P] (x y : P) : x ≤ y ↔ ∀ z, z ≤ x → z ≤ y :=
  ⟨fun hxy _ hzx => le_trans hzx hxy, fun h => h x (le_refl x)⟩
Axioms used: No axiomsformal/Lumenary/Yoneda.leanTry it in the Lean web editor
eq_of_same_lowerLean 4Proved here from basic factsFormally verified
/-- **The Yoneda principle for partial orders**: if exactly the same elements lie below `x` and
below `y`, then `x = y`. (Mathlib has this as `eq_of_forall_le_iff`.) -/
theorem eq_of_same_lower [PartialOrder P] {x y : P} (h : ∀ z, z ≤ x ↔ z ≤ y) : x = y :=
  le_antisymm ((h x).1 (le_refl x)) ((h y).2 (le_refl y))
Axioms used: No axiomsformal/Lumenary/Yoneda.leanTry it in the Lean web editor

What is and is not formalised. Theorems 1 and 2, full faithfulness of the covariant embedding and the Yoneda principle are proved independently in every locally small category; Corollaries 3–5 for the contravariant embedding and Theorem 9 are cited from Mathlib; Corollaries 6 and 7 are proved independently. Corollary 8 (natural operations on groups) is not formalised here.

ComputationC

Counting natural transformations

For finite categories and finite sets, the Yoneda lemma is a counting statement: among all families of functions Hom(A,X)→F(X)\Hom(A, X) \to F(X), exactly ∣F(A)∣|F(A)| are natural. The experiment lists every family and tests naturality directly — for a directed graph (a functor on E\mathbb{E}), for actions of the four-element monoid of all maps {0,1}→{0,1}\{0, 1\} \to \{0, 1\}, and for Z/3\Z/3 acting on six points. Then it finds, among all 720720 permutations of S3S_3, those that commute with right multiplication.

The Yoneda lemma by brute force in finite categoriesPythonExhaustive finite checkExact computationComputationally tested
"""The Yoneda lemma, checked by brute force in small finite categories.

For a finite category C, an object A and a functor F : C -> FinSet, we list
every family of functions alpha_B : Hom(A, B) -> F(B) and keep the natural
ones. The Yoneda lemma predicts exactly |F(A)| of them, and that
alpha -> alpha_A(id_A) is a bijection. We test this for directed graphs
(functors on the category E ⇉ V), for actions of the four-element monoid
of all maps {0, 1} -> {0, 1}, and for a group action. Then the one-object
case: among all 720 permutations of the six elements of S3, exactly six
commute with every right multiplication, and they are the left
multiplications (Cayley). Finally the poset case for divisibility. This is
exhaustive evidence in finitely many cases; the lemma is proved in general.
"""

import itertools

class FiniteCategory:
    """Objects, named arrows with (domain, codomain), identities and a
    composition table ``comp[(g, f)] = g ∘ f`` (first f, then g)."""

    def __init__(self, arrows, identities, comp):
        self.arrows = arrows
        self.identities = identities
        self.comp = comp
        self.objects = list(identities)

    def hom(self, a, b):
        """Names of the arrows a -> b."""
        return [f for f, (d, c) in self.arrows.items() if d == a and c == b]

def natural_transformations(cat, a, obj, arr):
    """All natural transformations Hom(a, −) => F, by brute force.

    ``obj[B]`` is the set F(B) (a list), ``arr[g]`` the function F(g) (a
    dict). A candidate picks, for every B and every f : a -> B, an element of
    F(B); it is natural if alpha(g ∘ f) = F(g)(alpha(f)) for all composable
    g, f. Returns the list of natural ones (each a dict f -> element) and
    the number of candidates examined.
    """
    slots = [f for b in cat.objects for f in cat.hom(a, b)]
    choices = [obj[cat.arrows[f][1]] for f in slots]
    natural, candidates = [], 0
    for values in itertools.product(*choices):
        candidates += 1
        alpha = dict(zip(slots, values))
        if all(alpha[cat.comp[(g, f)]] == arr[g][alpha[f]]
               for f in slots for g, (d, _) in cat.arrows.items()
               if d == cat.arrows[f][1]):
            natural.append(alpha)
    return natural, candidates

def yoneda_check(cat, a, obj, arr):
    """(number of natural transformations, |F(a)|, candidates, whether
    alpha -> alpha_a(id_a) is a bijection onto F(a))."""
    nats, candidates = natural_transformations(cat, a, obj, arr)
    images = [alpha[cat.identities[a]] for alpha in nats]
    bijective = sorted(images, key=repr) == sorted(obj[a], key=repr)
    return len(nats), len(obj[a]), candidates, bijective

def parallel_pair():
    """The category E ⇉ V: a functor out of it is a directed graph."""
    arrows = {"1E": ("E", "E"), "1V": ("V", "V"), "s": ("E", "V"), "t": ("E", "V")}
    comp = {("1E", "1E"): "1E", ("1V", "1V"): "1V", ("s", "1E"): "s",
            ("t", "1E"): "t", ("1V", "s"): "s", ("1V", "t"): "t"}
    return FiniteCategory(arrows, {"E": "1E", "V": "1V"}, comp)

def monoid_category(elements, mul, one):
    """A monoid as a category with one object '*'."""
    arrows = {m: ("*", "*") for m in elements}
    comp = {(g, f): mul(g, f) for g in elements for f in elements}
    return FiniteCategory(arrows, {"*": one}, comp)

#: The monoid of all maps {0,1} -> {0,1}, written as (image of 0, image of 1).
T2 = [(0, 1), (1, 0), (0, 0), (1, 1)]

def t2_mul(g, f):
    """g ∘ f: first f, then g."""
    return (g[f[0]], g[f[1]])

def examples():
    """(description, category, object, F on objects, F on arrows)."""
    out = []
    pp = parallel_pair()
    edges = {"e1": ("a", "b"), "e2": ("b", "c"), "e3": ("c", "a"), "e4": ("a", "a")}
    g_obj = {"E": list(edges), "V": ["a", "b", "c"]}
    g_arr = {"1E": {e: e for e in edges}, "1V": {v: v for v in "abc"},
             "s": {e: st[0] for e, st in edges.items()},
             "t": {e: st[1] for e, st in edges.items()}}
    out.append(("graph, A = E (edges)", pp, "E", g_obj, g_arr))
    out.append(("graph, A = V (vertices)", pp, "V", g_obj, g_arr))
    t2 = monoid_category(T2, t2_mul, (0, 1))
    pts = [0, 1]
    out.append(("T2 acting on {0,1}", t2, "*", {"*": pts},
                {m: {x: m[x] for x in pts} for m in T2}))
    subs = [frozenset(s) for s in ([], [0], [1], [0, 1])]
    out.append(("T2 acting on subsets (image)", t2, "*", {"*": subs},
                {m: {s: frozenset(m[x] for x in s) for s in subs} for m in T2}))
    z3 = monoid_category([0, 1, 2], lambda g, f: (g + f) % 3, 0)
    six = [(i, j) for i in range(3) for j in range(2)]
    out.append(("Z/3 rotating 3 + 3 points", z3, "*", {"*": six},
                {g: {(i, j): ((i + g) % 3, j) for i, j in six} for g in range(3)}))
    return out

def cayley_check():
    """Permutations of S3 commuting with all right multiplications, and
    whether they are exactly the left multiplications."""
    s3 = list(itertools.permutations(range(3)))

    def mul(p, q):
        return tuple(p[q[i]] for i in range(3))

    commuting = []
    for images in itertools.permutations(s3):
        sigma = dict(zip(s3, images))
        if all(sigma[mul(x, h)] == mul(sigma[x], h) for x in s3 for h in s3):
            commuting.append(sigma)
    lefts = [{x: mul(g, x) for x in s3} for g in s3]
    return len(commuting), sorted(map(repr, commuting)) == sorted(map(repr, lefts))

def divisibility_check(n):
    """Yoneda for the poset ({1..n}, |): a | b iff every divisor of a
    divides b. Returns the number of pairs checked and of failures."""
    divisors = {a: {d for d in range(1, a + 1) if a % d == 0}
                for a in range(1, n + 1)}
    pairs = [(a, b) for a in range(1, n + 1) for b in range(1, n + 1)]
    failures = sum((b % a == 0) != (divisors[a] <= divisors[b]) for a, b in pairs)
    return len(pairs), failures

def main():
    print("Natural transformations Hom(A, −) => F, found by brute force")
    print(f"  {'example':<31}{'candidates':>11}{'natural':>9}{'|F(A)|':>8}"
          f"  bijection")
    for name, cat, a, obj, arr in examples():
        n_nat, size, cands, bij = yoneda_check(cat, a, obj, arr)
        print(f"  {name:<31}{cands:>11}{n_nat:>9}{size:>8}  {bij}")
    print()
    count, exact = cayley_check()
    print("One object: permutations of S3 commuting with right multiplication")
    print(f"  {count} of 720; exactly the left multiplications x -> gx: {exact}")
    pairs, failures = divisibility_check(60)
    print("Posets: a | b  <=>  every divisor of a divides b, for a, b <= 60")
    print(f"  {pairs} pairs checked, {failures} failures")
    print()
    print("Epistemic status: exhaustive and exact in these finite examples. "
          "They\nillustrate the Yoneda lemma; the proof for every locally "
          "small category\nis in the lesson, and is machine-checked in Lean.")

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

What to notice: the number of candidates grows fast (44=2564^4 = 256 for the monoid acting on the four subsets of {0,1}\{0, 1\}), but the natural ones always number exactly ∣F(A)∣|F(A)|, and α↦αA(idA)\alpha \mapsto \alpha_A(\id_A) hits each element of F(A)F(A) once. For S3S_3 the six survivors are precisely the left multiplications. These are exhaustive checks of finitely many cases; the lemma itself is proved above for every locally small category, and in Lean.

Explore

Seeing Cayley's theorem

Draw the six elements of S3S_3 and join xx to xrxr by a solid arrow and xx to xsxs by a dashed edge (right multiplication by the generators). This is the Cayley graph of S3S_3. Left multiplication by any gg maps it to itself, preserving both kinds of edge, because g(xr)=(gx)rg(xr) = (gx)r — and Corollary 6 says these six maps are the only permutations of the vertices that preserve every edge and its style.

err²srsr²s
The Cayley graph of S₃ for the generators r (solid arrows, x → xr) and s (dashed, x — xs). Its edge-preserving symmetries are exactly the six left multiplications: a symmetry is determined by where it sends e.

Try it: pick a vertex, say rr, and decide to send ee there. Following the solid and dashed edges out of ee forces where every other vertex must go — you will have built λr\lambda_r. With e↦ee \mapsto e you are forced to the identity. That forcing is the proof of the Yoneda lemma, drawn.

Exercises

Exercises

1. The Yoneda lemma

Warm-upHuman

In the Yoneda lemma Nat(Hom(A,−),F)≅F(A)\mathrm{Nat}(\Hom(A, -), F) \cong F(A), which element of F(A)F(A) corresponds to a natural transformation α:Hom(A,−)⇒F\alpha : \Hom(A, -) \Rightarrow F?

Choose one

2. The Yoneda lemma

Warm-upHuman

A directed graph GG (allowing loops and parallel edges) has 77 vertices and 1212 edges. View it as a functor on the category E\mathbb{E} with arrows s,t:E→Vs, t : E \to V. How many graph homomorphisms are there from the walking edge Hom(E,−)\Hom(E, -) — one edge from a vertex ss to a vertex tt — to GG?

3. The Yoneda lemma

CoreHuman

On the category Ab\cat{Ab} of abelian groups, Hom(Z/3,−)\Hom(\Z/3, -) sends GG to its elements of order dividing 33, and Hom(Z,−)\Hom(\Z, -) sends GG to all of its elements. How many natural transformations Hom(Z/3,−)⇒Hom(Z,−)\Hom(\Z/3, -) \Rightarrow \Hom(\Z, -) are there?

4. The Yoneda lemma

CoreHuman

Which of these rules define natural transformations U⇒UU \Rightarrow U, where U:Grp→SetU : \cat{Grp} \to \cat{Set} is the forgetful functor (a rule must be defined for every group and commute with every homomorphism)? Choose all that apply.

Choose all that apply

5. The Yoneda lemma

CoreHuman

In the proof that Ψ(Φ(α))=α\Psi(\Phi(\alpha)) = \alpha we write αX(f)=αX(f∘idA)=F(f)(αA(idA))\alpha_X(f) = \alpha_X(f \circ \id_A) = F(f)(\alpha_A(\id_A)). Which fact justifies the second equality?

Choose one

6. The Yoneda lemma

CoreHuman

Which of these conclusions are justified for objects A,BA, B of a locally small category? Choose all that apply.

Choose all that apply

7. The Yoneda lemma

StretchHuman

Let GG be a group. Which permutations σ\sigma of the set GG satisfy σ(xh)=σ(x)h\sigma(xh) = \sigma(x)h for all x,h∈Gx, h \in G?

Choose one

8. The Yoneda lemma

CoreFormal

Mathlib's coyoneda.obj (op A) is the functor Hom(A,−)\Hom(A, -). Which Lean statement formalises "if Hom(A,−)≅Hom(B,−)\Hom(A, -) \cong \Hom(B, -) naturally, then A≅BA \cong B"?

Choose one

9. The Yoneda lemma

CoreComputational

The cyclic group Z/n\Z/n acts on X={0,…,m−1}X = \{0, \dots, m-1\} when its generator acts by a permutation p (a list with p[x] the image of x) satisfying pn=idp^n = \mathrm{id}. An equivariant map from the regular action is a function a : Z/n → X (a list of length n) with a[(k + 1) % n] == p[a[k]] for all k. Write count_equivariant(n, p) that counts such maps by brute force over all functions (use itertools.product). The Yoneda lemma predicts the answer len(p).

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

Common misconceptions

Misconception

"Yoneda says an object is its set of elements." It says an object is determined by the arrows into it from all objects, together with how they compose — not by its points Hom(1,A)\Hom(1, A). The discrete and indiscrete topologies on {0,1}\{0, 1\} have the same points but different continuous maps from, say, the Sierpiński space; their presheaves Hom(−,A)\Hom(-, A) differ, and so do the spaces.

Misconception

"The lemma must be hard to prove." The proof is three lines: build Ψ\Psi, check two composites, and the only real step is naturality applied to idA\id_A. Its power comes from how widely it applies — to groups, posets, graphs, spaces, schemes, programs — not from difficulty.

Misconception

"Any bijection Nat(Hom(A,−),F)≅F(A)\mathrm{Nat}(\Hom(A, -), F) \cong F(A) will do." The lemma provides a specific bijection, α↦αA(idA)\alpha \mapsto \alpha_A(\id_A), and its naturality in AA and FF (Theorem 2) is what the applications use — for instance in the proof of density and in Corollary 5.

Misconception

"Hom(X,A)≅Hom(X,B)\Hom(X, A) \cong \Hom(X, B) for each XX is enough." The Yoneda principle needs these bijections to be natural in XX: compatible with all arrows X′→XX' \to X. An unnatural family of bijections carries no information about arrows between the probes and in general does not produce an isomorphism A→BA \to B.

Misconception

Mixing up the two embeddings. A↦Hom(−,A)A \mapsto \Hom(-, A) is a covariant functor C→[Cop,Set]\mathcal{C} \to [\mathcal{C}^{\mathrm{op}}, \cat{Set}]; A↦Hom(A,−)A \mapsto \Hom(A, -) is covariant from Cop\mathcal{C}^{\mathrm{op}}, i.e. it reverses arrows: f:A→Bf : A \to B gives Hom(B,−)⇒Hom(A,−)\Hom(B, -) \Rightarrow \Hom(A, -). In Cayley's theorem this is the difference between left multiplications forming a homomorphism g↦λgg \mapsto \lambda_g and right multiplications forming an anti-homomorphism.

ViewpointsH

Viewpoints

Geometry— The functor of points

Grothendieck's reformulation of algebraic geometry is the Yoneda embedding applied to schemes. A scheme XX gives the presheaf T↦X(T)=Hom(T,X)T \mapsto X(T) = \Hom(T, X) of "TT-valued points", and by Corollary 4 no information is lost: morphisms of schemes are exactly natural transformations of their functors of points, and (restricting to affine T=Spec⁡RT = \operatorname{Spec} R) a scheme is determined by the solutions of its equations in all commutative rings. Yoneda also transports structure: a group structure on XX (making it a group scheme) is the same thing as a group structure on each X(T)X(T), natural in TT. The multiplicative group Gm\mathbb{G}_m is the functor R↦R×R \mapsto R^\times and GLn\mathrm{GL}_n is R↦GLn(R)R \mapsto \mathrm{GL}_n(R); the group laws are verified pointwise, where they are just the familiar laws for matrices. See algebraic geometry.

Topology— Simplices, cohomology operations and homotopy

A simplicial set is a combinatorial model of a space, and Corollary 3 says its nn-simplices are exactly the maps Δ[n]→X\Delta[n] \to X from the standard simplex; density (Theorem 9) says XX is glued from simplices, and geometric realisation glues the corresponding topological simplices. In cohomology, representability by Eilenberg–MacLane spaces, Hn(X;G)≅[X,K(G,n)]H^n(X; G) \cong [X, K(G, n)], combined with Yoneda in the homotopy category, shows that natural transformations Hn(−;G)⇒Hm(−;G′)H^n(-; G) \Rightarrow H^m(-; G') — cohomology operations — correspond to elements of Hm(K(G,n);G′)H^m(K(G, n); G'). The Steenrod squares Sqi\mathrm{Sq}^i are such elements of Hn+i(K(Z/2,n);Z/2)H^{n+i}(K(\Z/2, n); \Z/2). The fundamental group itself is Yoneda-flavoured: loops are maps from the circle, π1(X,x0)=[(S1,∗),(X,x0)]\pi_1(X, x_0) = [(S^1, \ast), (X, x_0)]. See algebraic topology.

Algebra— Operations are words: Cayley and beyond

Corollaries 6 and 8 are the algebraist's Yoneda. Cayley's theorem realises every group inside a symmetric group; its linear cousin realises every group inside GL(k[G])\mathrm{GL}(k[G]) through the regular representation, and every ring RR inside the ring of additive endomorphisms of RR, by r↦(x↦rx)r \mapsto (x \mapsto rx) — the image being exactly the endomorphisms that commute with right multiplications, as in Corollary 6. Corollary 8 says the natural nn-ary operations on groups are the elements of the free group FnF_n, and on commutative rings the elements of Z[x1,…,xn]\Z[x_1, \dots, x_n]. Lawvere's functorial semantics turns this around: an algebraic theory is (the opposite of) the category of its finitely generated free algebras, and its models are the product-preserving functors from it to Set\cat{Set}.

Computation— Continuations and the Yoneda trick in programming

In a typed functional language, a polymorphic function of type ∀ r. (a → r) → F r, for a functor F, corresponds to a value of type F a — Theorem 1 with types as objects, assuming the functions are parametric (they cannot inspect the type r). With F the identity, ∀ r. (a → r) → r ≅ a: a value is the same as the ability to hand it to any continuation, the basis of continuation-passing style. Compilers and libraries use the wrapped form to fuse repeated fmaps into one pass (fmap f . fmap g = fmap (f . g) becomes automatic). The correspondence relies on parametricity (Reynolds, Wadler), a theorem about the language, not on category theory alone.

Logic— Leibniz, identity types and path induction

Corollary 7 is Leibniz's principle in order-theoretic form: two things with the same "properties" (here: the same elements below them) are equal. In type theory, the Leibniz-style characterisation of equality — x=yx = y if and only if every predicate true of xx is true of yy — is provable, and Martin-Löf's identity types satisfy a Yoneda-like induction principle: to prove something about all yy and all p:x=yp : x = y it suffices to prove it for y=xy = x and p=reflxp = \mathrm{refl}_x. In homotopy type theory this path induction is often described as the Yoneda lemma for identity types: reflx\mathrm{refl}_x plays the role of idA\id_A, the generic element from which every other is transported.

Category-theoretic connectionH

Presheaves as free colimits

The Yoneda embedding y:C→C^y : \mathcal{C} \to \widehat{\mathcal{C}} is full and faithful (Corollary 4), and every presheaf is a colimit of representables (Theorem 9). Together these make C^\widehat{\mathcal{C}} the free cocompletion of a small category C\mathcal{C}: for any cocomplete category E\mathcal{E}, functors C→E\mathcal{C} \to \mathcal{E} extend, uniquely up to isomorphism, to colimit-preserving functors C^→E\widehat{\mathcal{C}} \to \mathcal{E}, by left Kan extension along yy. So presheaves are "formal colimits of objects of C\mathcal{C}", just as a free vector space consists of formal linear combinations. The proof is in the Kan extensions lesson.

Wonder Trails

Wonder Trail

The product A×BA \times B is determined by its maps: the trail explores, with finite sets, the universal property that the Yoneda principle turns into uniqueness.

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

  • Arthur Cayley's paper "On the theory of groups, as depending on the symbolic equation θn=1\theta^n = 1" (1854) gave the first abstract definition of a group and observed that a group can be represented by permutations of its own elements.
  • Nobuo Yoneda (1930–1996), a Japanese mathematician who later turned to computer science, used the lemma in his work on homological algebra, published as "On the homology theory of modules" (Journal of the Faculty of Science, University of Tokyo, 1954), the paper that also introduced the description of Ext\mathrm{Ext} by extensions now called Yoneda Ext. Saunders Mac Lane recalled learning the lemma from Yoneda in conversation at the Gare du Nord in Paris in 1954, and it was Mac Lane who made it widely known under Yoneda's name.
  • Alexander Grothendieck made the embedding of a category into its presheaves central to algebraic geometry from about 1960, treating spaces through their functors of points and developing topos theory from categories of sheaves.
  • F. William Lawvere's thesis (1963) used the same circle of ideas for universal algebra, and John C. Reynolds (1983) and Philip Wadler (1989) developed the parametricity that connects the lemma to typed programs.
  • Today the lemma has versions for enriched categories, 2-categories and ∞-categories, and it is a basic tool in algebraic geometry, homotopy theory, logic and programming-language semantics.
Further reading

Further reading

  • Emily Riehl, Category Theory in Context (2016), Chapter 2 — the Yoneda lemma with many applications; Chapter 6 for density and Kan extensions.
  • Tom Leinster, Basic Category Theory (2014), Chapter 4 — representables and the Yoneda lemma, very clearly motivated.
  • Saunders Mac Lane, Categories for the Working Mathematician (1971; 2nd edition 1998), Section III.2.
  • Saunders Mac Lane and Ieke Moerdijk, Sheaves in Geometry and Logic (1992), Chapter I — presheaves, the Yoneda embedding and colimits of representables.
  • David Eisenbud and Joe Harris, The Geometry of Schemes (2000), Chapter VI — the functor of points.
  • Nobuo Yoneda, "On the homology theory of modules", J. Fac. Sci. Univ. Tokyo Sect. I 7 (1954) — the original source.