Functor Composition

lean4-proofcategory-theoryvisualization
(FG)H=F(GH)(F \circ G) \circ H = F \circ (G \circ H)

Statement

Given functors F:ABF : \mathcal{A} \to \mathcal{B}, G:BCG : \mathcal{B} \to \mathcal{C}, H:CDH : \mathcal{C} \to \mathcal{D}, their composites satisfy:

H(GF)=(HG)FH \circ (G \circ F) = (H \circ G) \circ F

and for every functor F:CDF : \mathcal{C} \to \mathcal{D}:

IdDF=F=FIdC\mathrm{Id}_\mathcal{D} \circ F = F = F \circ \mathrm{Id}_\mathcal{C}

These laws make small categories the objects and functors the morphisms of a (very large) category Cat\mathbf{Cat}.

Visualization

Free and forgetful functors compose to give a monad:

  Set ─────Free─────▶ Mon ─────Free─────▶ Ab
       ◀───Forget────      ◀───Forget────

  Composition chain:
    Free_Ab ∘ Free_Mon : Set ──▶ Ab
    (Forget_Mon ∘ Free_Ab)(A) ≈ Ab underlying set of free abelian group

  Concretely on X = {a, b}:
    Free_Mon({a,b}) = {ε, a, b, ab, ba, aab, ...}    (free monoid)
    Free_Ab({a,b})  = {ma·a + mb·b | ma, mb ∈ ℤ}      (ℤ² as abelian group)

  Associativity on objects (trivially definitional):
    (H ∘ G)(F(X)) = H(G(F(X)))   — same object either way

  Identity laws:
    Id_D(F(X)) = F(X)  ✓
    F(Id_C(X)) = F(X)  ✓ (functors preserve identities)

  Composition table for F : A→B, G : B→C on morphisms f:
    (G ∘ F)(f) := G(F(f))
    ((H ∘ G) ∘ F)(f) = H(G(F(f))) = (H ∘ (G ∘ F))(f)  ✓

Proof Sketch

  1. Composition is well-defined: Given FF maps A\mathcal{A}-morphisms to B\mathcal{B}-morphisms and GG maps B\mathcal{B}-morphisms to C\mathcal{C}-morphisms, GFG \circ F maps A\mathcal{A}-morphisms to C\mathcal{C}-morphisms.

  2. Functor laws for GFG \circ F:

    • Identity: (GF)(idX)=G(F(idX))=G(idF(X))=idG(F(X))(G \circ F)(\mathrm{id}_X) = G(F(\mathrm{id}_X)) = G(\mathrm{id}_{F(X)}) = \mathrm{id}_{G(F(X))}.
    • Composition: (GF)(fg)=G(F(fg))=G(F(f)F(g))=G(F(f))G(F(g))(G \circ F)(f \circ g) = G(F(f \circ g)) = G(F(f) \circ F(g)) = G(F(f)) \circ G(F(g)).
  3. Associativity is definitional: All three composites apply HH, then GG, then FF to objects and morphisms; they are equal by definition.

  4. Left and right units are definitional: IdD(F(X))=F(X)\mathrm{Id}_\mathcal{D}(F(X)) = F(X) and F(IdC(X))=F(X)F(\mathrm{Id}_\mathcal{C}(X)) = F(X) by definition of the identity functor.

Connections

Functor composition is the composition law in the category Cat\mathbf{Cat}, which itself can be studied with the Yoneda LemmaYoneda LemmaNat(Hom(X,),F)F(X)\mathrm{Nat}(\mathrm{Hom}(X,-),\, F) \cong F(X)Natural transformations from a representable functor y_X to F biject with elements of F(X)Read more →. The Natural TransformationNatural TransformationG(f)αX=αYF(f)G(f) \circ \alpha_X = \alpha_Y \circ F(f)A family of morphisms α_X : F(X) → G(X) making every naturality square commuteRead more → between composite functors (whiskering) makes Cat\mathbf{Cat} into a 2-category, a structure that appears in 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 → (via triangle identities for LRLR and RLRL).

Lean4 Proof

import Mathlib.CategoryTheory.Functor.Basic

open CategoryTheory

/-- Functor composition is associative (definitionally equal). -/
theorem functor_comp_assoc {A B C D : Type*}
    [Category A] [Category B] [Category C] [Category D]
    (F : AB) (G : BC) (H : CD) :
    (FG) ⋙ H = F ⋙ (GH) :=
  rfl

/-- Right identity: F ⋙ 𝟭 D = F. -/
theorem functor_comp_id_right {C D : Type*} [Category C] [Category D]
    (F : CD) : F ⋙ 𝟭 D = F :=
  Functor.comp_id F

/-- Left identity: 𝟭 C ⋙ F = F. -/
theorem functor_comp_id_left {C D : Type*} [Category C] [Category D]
    (F : CD) : 𝟭 CF = F :=
  Functor.id_comp F