Yoneda lemma. Let be a (locally small) Category, a Functor, and an object. Then there is a bijection
natural in both and . Dually (contravariant Yoneda), for a Presheaf .
Sources: Kittenlab Lecture 12 (“That’s Yoneda, Babe”); DaoFP §3.3 (“Reasoning with Arrows”), §9.6 (“The Yoneda Lemma”, “Yoneda lemma in programming”, “The contravariant Yoneda lemma”), §9.10, §17.6 (“Ninja Yoneda”), §20.4 (enriched); 7 Sketches Exercise 1.66 (Yoneda Lemma for Preorders), Remark 1.82; DaoFP Preface: “the fundamental theorem of category theory”; CTfS §5.2.1.6 (Lemma 5.2.1.7: “each row in table induces its SIRS throughout the database”)
Intuition
-
“A vibe check for category theory”: we say all the time that all that matters is the morphisms out of (or into) an object; the Yoneda lemma formalizes this (Kittenlab).
-
The trivial case: for a set , — "". For graphs: the vertices of are the maps from the one-vertex graph , , and the edges are maps from the one-edge graph, , because naturality forces where go once is sent to an edge (Kittenlab).
-
DaoFP: is the “panoramic, very detailed view of from the vantage point of ”; an arbitrary is another, lossy model; a natural transformation embeds one model in the other, and the set of all such is “fully determined by the set “. “The proof starts with a single identity arrow and lets naturality propagate it across the whole category.”
-
Databases (CTfS §5.2.1.6): for a schema and an instance , a row has a value in every foreign-key column leaving , those values have values in their columns, and so on: the row “induces its schematically implied reference spread” through the database. The representable is that spread with placeholder values (see Representable Functor), and the Yoneda lemma says filling in the placeholders from is a bijection .
Proof (Kittenlab / DaoFP)
Forward. Given define by for . (Naturality in is DaoFP Exercise 9.6.2.)
Backward. Given , take — the Yoneda trick: substitute for the variable to get an endo-hom-set and pick its canonical element.
Inverse. . Conversely, for and , the naturality square for applied to gives
so : “where goes is wholly determined by where goes”. (DaoFP Exercise 9.6.1 handles .)
Consequences
- Corollary (Kittenlab): — take . Hence iff : representing objects are unique up to isomorphism, and universal constructions defined by representability (Coproduct, Coequalizer, Colimit, Product, …) are well defined. E.g. : two morphisms each.
- The Yoneda Embedding , , is fully faithful (DaoFP §9.7); -sets naturally isomorphic implies objects isomorphic (Isomorphism).
- Every isomorphism of hom-sets used in adjunctions, counits, universal arrows and adjoint functor theorems is manipulated via the Yoneda trick (DaoFP §10). Preorder version: iff (Yoneda Lemma for Preorders).
- In programming (DaoFP §9.6):
forall x. (a -> x) -> f x ≅ f a, withyoneda g = g idandyoneda_1 y = \h -> fmap h y(really the enriched Yoneda lemma in the self-enriched ). For :a ≅ forall x. (a -> x) -> x— the continuation-passing transform (a value is replaced by a function taking a handler/callback), used for remote values and for turning recursion tail-recursive; continuations form a monad. Contravariant:coyoneda g = g id,coyoneda_1 y = \h -> contramap h y. - Enriched and coend forms: the Ninja Yoneda Lemma and (DaoFP §17.6, §20.4).
Docs: Categories & functors · C-set morphisms · ACSets API · Graphs — Kittenlab Lecture 12
# Kittenlab Lecture 12 for graphs: elements of G(V) ↔ maps from the one-vertex graph
using Catlab
G = @acset Graph begin V = 3; E = 2; src = [1, 2]; tgt = [2, 3] end
yV = representable(Graph, :V); yE = representable(Graph, :E)
# forward: x ∈ G(E) ↦ x* : yE → G sending id_E ↦ x (and src, tgt forced)
# (in Catlab's representable(Graph, :E) the edge runs from vertex 2 to vertex 1)
x_star(e) = ACSetTransformation(yE, G; E = [e], V = [tgt(G, e), src(G, e)])
all(is_natural(x_star(e)) for e in edges(G)) # true
# backward: α ↦ α_E(id_E)
sort([α[:E](1) for α in homomorphisms(yE, G)]) == edges(G) # true: the bijection G(E) ≅ Hom(yE, G)#check CategoryTheory.yonedaEquiv -- (yoneda.obj X ⟶ F) ≃ F.obj (op X)
#check CategoryTheory.coyonedaEquiv -- (coyoneda.obj (op X) ⟶ F) ≃ F.obj X (covariant form)
#check CategoryTheory.yonedaLemma -- the natural isomorphism, natural in X and F
#check CategoryTheory.Yoneda.fullyFaithful{-# LANGUAGE RankNTypes #-}
-- DaoFP §9.6: the Yoneda lemma as a pair of inverse functions
yoneda :: Functor f => (forall x. (a -> x) -> f x) -> f a
yoneda g = g id -- the Yoneda trick
yoneda_1 :: Functor f => f a -> (forall x. (a -> x) -> f x)
yoneda_1 y = \h -> fmap h y
-- contravariant version
coyoneda :: Contravariant f => (forall x. (x -> a) -> f x) -> f a
coyoneda g = g id
coyoneda_1 :: Contravariant f => f a -> (forall x. (x -> a) -> f x)
coyoneda_1 y = \h -> contramap h y
-- f = Identity: continuation passing style, a ≅ forall x. (a -> x) -> x
toCPS :: a -> (forall x. (a -> x) -> x)
toCPS a = \k -> k a
fromCPS :: (forall x. (a -> x) -> x) -> a
fromCPS c = c id