Known by your relationships
In 1854 Arthur Cayley observed that every group is a group of permutations: an element of can be replaced by the permutation of , and nothing is lost. In a partially ordered set, an element is completely determined by the set 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 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 with all objects, recording every arrow and how the arrows compose. Then nothing is lost — 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.
Follow the identity
Fix an object and a functor . A natural transformation consists of a function for every object — a huge amount of data, one function per object.
But among all arrows out of there is one special one: . Every arrow is obtained from it by composing, . Naturality says that commutes with composing, so must be obtained from by applying . All the data of is packed into the single element
and any element of can be unpacked into a natural transformation. The identity arrow is a generic element: the most general -shaped thing, of which every other is a specialisation.
Definitions
Throughout, is locally small: every is a set. For functors we write for the collection of natural transformations .
Definition— presheaf
A presheaf on is a functor . Presheaves and natural transformations form the presheaf category . When is small (its objects and arrows form sets), is locally small.
Definition— Yoneda embedding
The Yoneda embedding sends an object to the representable presheaf and an arrow to the natural transformation .
Definition— the Yoneda map
For and an object , define
and, in the other direction, for let have components .
Some examples of the objects involved:
- A group is a category with one object , one arrow for each , and composition . A functor is a set with a left -action, a presheaf on is a set with a right action, and natural transformations are equivariant maps. The representable presheaf is acting on itself by right multiplication.
- A directed graph is a functor , where has two objects and two arrows besides identities: is the set of edges, the set of vertices, and give the source and target. Natural transformations are graph homomorphisms. The representable is the walking edge (one edge, from to ), and is a single vertex.
- A poset is a category with an arrow exactly when . The representable is, in effect, the down-set .
- A simplicial set is a presheaf on the category of finite ordinals and order-preserving maps; the representable is the standard -simplex.
The Yoneda lemma and its consequences
Theorem— Theorem 1 (the Yoneda lemma)
Let be locally small, a functor and an object. Then is a natural transformation for every , and and are mutually inverse bijections
Proof
is natural. For and , functoriality of gives
. .
. Let and . Naturality of along says for every . Take :
So and agree at every component, at every arrow.
∎
A remark on size: even when is large, so that a natural transformation is a "large" family, the lemma shows that is in bijection with a set.
Theorem— Theorem 2 (naturality of the Yoneda bijection)
The bijection is natural in both and :
- for a natural transformation , ;
- for an arrow , , where is precomposition with .
So is a natural isomorphism between the two functors given by and .
Proof
(1) , by the definition of vertical composition.
(2) , and by the last step of the proof of Theorem 1, .
∎
Applying Theorem 1 to gives the form used for presheaves.
Theorem— Corollary 3 (contravariant form)
For a presheaf and an object , the map is a bijection , natural in and . Its inverse sends to the transformation , for .
Theorem— Corollary 4 (the Yoneda embedding is full and faithful)
For all objects , the map is a bijection .
Proof
Take in Corollary 3: . The inverse bijection sends to the transformation , which is exactly . So is a bijection.
∎
Theorem— Corollary 5 (the Yoneda principle)
If as presheaves, then . More precisely, every natural isomorphism is for a unique isomorphism . Dually, implies .
Proof
By Corollary 4, and for unique arrows and . Since is a functor, , and since is faithful, . Likewise . The dual statement is the same argument for the covariant embedding of , 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 , the map , , is an injective group homomorphism . Its image consists exactly of the permutations with for all .
Proof
Apply Corollary 4 to . The presheaf is the set , on which an arrow acts by precomposition, . A natural transformation is therefore a map with , and is post-composition , which is . Full faithfulness says every such is for exactly one (concretely, , because ). Functoriality of says and . So is an injective homomorphism into , with the stated image.
∎
Theorem— Corollary 7 (Yoneda for posets)
In a poset, if and only if every also satisfies , i.e. . In particular implies .
Proof
This is Corollary 4 for a thin category, where a hom-set has at most one element: a natural transformation exists exactly when , and an arrow exists exactly when . Directly: if and then by transitivity; conversely take . The second claim follows by antisymmetry.
∎
Theorem— Corollary 8 (natural operations on groups)
Let be the forgetful functor. Every natural transformation is for a unique . Every natural transformation is for a unique word in the free group .
Proof
with universal element , and with universal element . By Theorem 1, ; the element corresponds to , where is the homomorphism with . Similarly : the word corresponds to , the image of under the homomorphism , .
∎
So the only operations that make sense uniformly in all groups and commute with all homomorphisms are words: , , the commutator , 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 be small and a presheaf on . Let be its category of elements: objects are pairs with , and an arrow is an arrow with . Then is the colimit of the diagram , , with coprojections the transformations corresponding to under Corollary 3.
Proof
Write for , so that . Corollary 3 with its naturality gives, for and ,
Cocone. For an arrow of : , so because is injective.
Factorisation. Let be another cocone. Define by . It is natural: for and , is an arrow of , so and
And , so .
Uniqueness. If also for all , then .
Since is small, so is , and this is a small colimit.
∎
For a simplicial set this says that is glued from standard simplices , one for each -simplex of — and Corollary 3 says that the -simplices of are the maps . In the Kan extensions lesson, density is the starting point for extending functors from to all presheaves.
Worked examples
Example— Edges and vertices of a graph
Let be a directed graph, viewed as a functor . A graph homomorphism from the walking edge to is determined by where it sends the edge ; by Theorem 1 it can send it to any edge of , and the endpoints must then go to that edge's source and target. So , the edges. Likewise homomorphisms from the one-vertex graph are the vertices. "The edges of are the maps from an edge" is the Yoneda lemma.
Example— Cayley's theorem for $S_3$
Write with and . Left multiplication by permutes the six elements as two 3-cycles, ; that is the permutation . Of the permutations of , exactly six commute with every right multiplication, and they are — the computation section finds them by brute force. Corollary 6 explains why: a permutation commuting with right multiplications is determined by where it sends .
Example— Divisibility
In , exactly when every divisor of divides (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, . Instead of building the isomorphism by hand, compute hom-sets: naturally in ,
So , and Corollary 5 gives the isomorphism. The same technique proves and, in a cartesian closed category, .
Example— A natural operation that is not a power
Inversion is natural on groups: it is the power . On the category of abelian groups, still, so the natural operations are again . But on rings, , and the natural unary operations are the integer polynomials: , and so on, one for each element of .
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 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.
/-- 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)/-- 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/-- **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]/-- 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/-- **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_ofElementTheorem 2: naturality in and in .
/-- 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/-- 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 α) := rflFull faithfulness and the Yoneda principle, proved from Theorem 1 for the covariant embedding :
/-- **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/-- **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 simpMathlib's versions of Corollaries 3, 4 and 5 for the contravariant embedding, and the density theorem (Theorem 9):
/-- **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/-- **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/-- **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⟩/-- **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⟩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 . Mathlib's version follows.
/-- 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/-- **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/-- **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/-- 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⟩Posets (Corollary 7).
/-- **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)⟩/-- **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))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.
Counting natural transformations
For finite categories and finite sets, the Yoneda lemma is a counting statement: among all families of functions , exactly are natural. The experiment lists every family and tests naturality directly — for a directed graph (a functor on ), for actions of the four-element monoid of all maps , and for acting on six points. Then it finds, among all permutations of , those that commute with right multiplication.
"""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()What to notice: the number of candidates grows fast ( for the monoid acting on the four subsets of ), but the natural ones always number exactly , and hits each element of once. For 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.
Seeing Cayley's theorem
Draw the six elements of and join to by a solid arrow and to by a dashed edge (right multiplication by the generators). This is the Cayley graph of . Left multiplication by any maps it to itself, preserving both kinds of edge, because — and Corollary 6 says these six maps are the only permutations of the vertices that preserve every edge and its style.
Try it: pick a vertex, say , and decide to send there. Following the solid and dashed edges out of forces where every other vertex must go — you will have built . With you are forced to the identity. That forcing is the proof of the Yoneda lemma, drawn.
Exercises
1. The Yoneda lemma
Warm-upHumanIn the Yoneda lemma , which element of corresponds to a natural transformation ?
2. The Yoneda lemma
Warm-upHumanA directed graph (allowing loops and parallel edges) has vertices and edges. View it as a functor on the category with arrows . How many graph homomorphisms are there from the walking edge — one edge from a vertex to a vertex — to ?
3. The Yoneda lemma
CoreHumanOn the category of abelian groups, sends to its elements of order dividing , and sends to all of its elements. How many natural transformations are there?
4. The Yoneda lemma
CoreHumanWhich of these rules define natural transformations , where is the forgetful functor (a rule must be defined for every group and commute with every homomorphism)? Choose all that apply.
5. The Yoneda lemma
CoreHumanIn the proof that we write . Which fact justifies the second equality?
6. The Yoneda lemma
CoreHumanWhich of these conclusions are justified for objects of a locally small category? Choose all that apply.
7. The Yoneda lemma
StretchHumanLet be a group. Which permutations of the set satisfy for all ?
8. The Yoneda lemma
CoreFormalMathlib's coyoneda.obj (op A) is the functor . Which Lean statement formalises "if naturally, then "?
9. The Yoneda lemma
CoreComputationalThe cyclic group acts on when its generator acts by a permutation p (a list with p[x] the image of x) satisfying . 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).
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 . The discrete and indiscrete topologies on have the same points but different continuous maps from, say, the Sierpiński space; their presheaves differ, and so do the spaces.
Misconception
"The lemma must be hard to prove." The proof is three lines: build , check two composites, and the only real step is naturality applied to . Its power comes from how widely it applies — to groups, posets, graphs, spaces, schemes, programs — not from difficulty.
Misconception
"Any bijection will do." The lemma provides a specific bijection, , and its naturality in and (Theorem 2) is what the applications use — for instance in the proof of density and in Corollary 5.
Misconception
" for each is enough." The Yoneda principle needs these bijections to be natural in : compatible with all arrows . An unnatural family of bijections carries no information about arrows between the probes and in general does not produce an isomorphism .
Misconception
Mixing up the two embeddings. is a covariant functor ; is covariant from , i.e. it reverses arrows: gives . In Cayley's theorem this is the difference between left multiplications forming a homomorphism and right multiplications forming an anti-homomorphism.
Viewpoints
Geometry— The functor of points
Grothendieck's reformulation of algebraic geometry is the Yoneda embedding applied to schemes. A scheme gives the presheaf of "-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 ) a scheme is determined by the solutions of its equations in all commutative rings. Yoneda also transports structure: a group structure on (making it a group scheme) is the same thing as a group structure on each , natural in . The multiplicative group is the functor and is ; 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 -simplices are exactly the maps from the standard simplex; density (Theorem 9) says is glued from simplices, and geometric realisation glues the corresponding topological simplices. In cohomology, representability by Eilenberg–MacLane spaces, , combined with Yoneda in the homotopy category, shows that natural transformations — cohomology operations — correspond to elements of . The Steenrod squares are such elements of . The fundamental group itself is Yoneda-flavoured: loops are maps from the circle, . 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 through the regular representation, and every ring inside the ring of additive endomorphisms of , by — the image being exactly the endomorphisms that commute with right multiplications, as in Corollary 6. Corollary 8 says the natural -ary operations on groups are the elements of the free group , and on commutative rings the elements of . 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 .
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 — if and only if every predicate true of is true of — is provable, and Martin-Löf's identity types satisfy a Yoneda-like induction principle: to prove something about all and all it suffices to prove it for and . In homotopy type theory this path induction is often described as the Yoneda lemma for identity types: plays the role of , the generic element from which every other is transported.
Presheaves as free colimits
The Yoneda embedding is full and faithful (Corollary 4), and every presheaf is a colimit of representables (Theorem 9). Together these make the free cocompletion of a small category : for any cocomplete category , functors extend, uniquely up to isomorphism, to colimit-preserving functors , by left Kan extension along . So presheaves are "formal colimits of objects of ", just as a free vector space consists of formal linear combinations. The proof is in the Kan extensions lesson.
Wonder Trail
The product 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 without ever looking inside it — only by how functions go into it?Follow the trailHistory and global context
- Arthur Cayley's paper "On the theory of groups, as depending on the symbolic equation " (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 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
- 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.