Yoneda Lemma

lean4-proofcategory-theoryvisualization
Nat(Hom(X,),F)F(X)\mathrm{Nat}(\mathrm{Hom}(X,-),\, F) \cong F(X)

Statement

Let C\mathcal{C} be a locally small category, XCX \in \mathcal{C} an object, and F:CopSetF : \mathcal{C}^{\mathrm{op}} \to \mathbf{Set} a presheaf. The Yoneda Lemma states there is a natural bijection:

Nat(Hom(,X),F)    F(X)\mathrm{Nat}(\mathrm{Hom}(-, X),\, F) \;\cong\; F(X)

The bijection sends a natural transformation α:Hom(,X)F\alpha : \mathrm{Hom}(-,X) \Rightarrow F to the element αX(idX)F(X)\alpha_X(\mathrm{id}_X) \in F(X). Its inverse sends xF(X)x \in F(X) to the natural transformation (αx)Y(f)=F(f)(x)(\alpha_x)_Y(f) = F(f)(x).

Visualization

Concretely, take C=Set\mathcal{C} = \mathbf{Set}, X={}X = \{*\} (one-element set), F=PF = \mathcal{P} (power-set functor on Setop\mathbf{Set}^{\mathrm{op}}). Then Hom(,{})\mathrm{Hom}(-, \{*\}) picks out elements, and a natural transformation corresponds to a subset of {}\{*\}:

  Naturality square for α : Hom(-,X) ⇒ F, and f : A → B
                            α_B
  Hom(B, X) ─────────────────────────────▶ F(B)
       │                                      │
  -∘f  │                                      │ F(f)
       ▼                                      ▼
  Hom(A, X) ─────────────────────────────▶ F(A)
                            α_A

  α commutes: F(f)(α_B(g)) = α_A(g ∘ f)  for all g : B → X

  Key computation (recovering x from α):
    given α, set x := α_X(id_X) ∈ F(X)
    then for any f : A → X:
      α_A(f) = α_A(id_X ∘ f) = F(f)(α_X(id_X)) = F(f)(x)  ✓

So α\alpha is completely determined by the single element x=αX(idX)x = \alpha_X(\mathrm{id}_X).

Proof Sketch

  1. Define the map Φ\Phi: Given α:Hom(,X)F\alpha : \mathrm{Hom}(-,X) \Rightarrow F, set Φ(α)=αX(idX)F(X)\Phi(\alpha) = \alpha_X(\mathrm{id}_X) \in F(X).

  2. Define the inverse Ψ\Psi: Given xF(X)x \in F(X), define Ψ(x)A(f)=F(f)(x)\Psi(x)_A(f) = F(f)(x) for f:AXf : A \to X. Naturality of Ψ(x)\Psi(x) follows from functoriality of FF.

  3. ΦΨ=id\Phi \circ \Psi = \mathrm{id}: Φ(Ψ(x))=Ψ(x)X(idX)=F(idX)(x)=x\Phi(\Psi(x)) = \Psi(x)_X(\mathrm{id}_X) = F(\mathrm{id}_X)(x) = x. Since FF is a functor, F(idX)=idF(X)F(\mathrm{id}_X) = \mathrm{id}_{F(X)}.

  4. ΨΦ=id\Psi \circ \Phi = \mathrm{id}: For α\alpha natural and any f:AXf : A \to X, naturality forces αA(f)=F(f)(αX(idX))=Ψ(Φ(α))A(f)\alpha_A(f) = F(f)(\alpha_X(\mathrm{id}_X)) = \Psi(\Phi(\alpha))_A(f).

  5. Naturality of Φ\Phi: Both bijections vary naturally in XX and FF, so Φ\Phi is a natural isomorphism.

Connections

The Yoneda Lemma is the categorical generalization of Cayley's TheoremCayley's TheoremGSGG \hookrightarrow S_{|G|}Every group embeds into a symmetric groupRead more → (every group embeds in its permutation group) and underlies the theory of representable functorsRepresentable FunctorFHom(X,)F \cong \mathrm{Hom}(X, -)A functor F is representable if it is naturally isomorphic to Hom(X,-) for some object XRead more →. It also drives the universal properties behind Adjoint FunctorsAdjoint FunctorsHom(LX,Y)Hom(X,RY)\mathrm{Hom}(LX, Y) \cong \mathrm{Hom}(X, RY)A pair of functors L ⊣ R with a natural bijection Hom(LX, Y) ≅ Hom(X, RY)Read more →.

Lean4 Proof

import Mathlib.CategoryTheory.Yoneda

open CategoryTheory

/-- The Yoneda bijection: natural transformations from the representable
    presheaf yoneda.obj X to F correspond to elements of F.obj (op X).
    Mathlib provides this as `yonedaEquiv`. -/
theorem yoneda_bijection {C : Type*} [Category C]
    {X : C} {F : CᵒᵖType*} :
    (yoneda.obj XF) ≃ F.obj (Opposite.op X) :=
  yonedaEquiv

/-- The underlying element recovered from a natural transformation. -/
theorem yoneda_apply {C : Type*} [Category C]
    {X : C} {F : CᵒᵖType*} (α : yoneda.obj XF) :
    yonedaEquiv α = α.app (Opposite.op X) (𝟙 X) :=
  yonedaEquiv_apply α