Module 02

Category Theory Essentials

Category theory provides the natural language for type-safe physics—the mathematics of structure and composition.

📚 2-3 weeks 🎯 Intermediate 💻 Module 1 required

🎯 Learning Objectives

Understand Categories

Master objects, morphisms, identity, and composition—the basic vocabulary of structure.

Work with Functors

Learn structure-preserving maps between categories and how they model physical correspondences.

Grasp Natural Transformations

Understand morphisms between functors and how they express universal physical laws.

Apply the Yoneda Lemma

See how objects are characterized by their relationships—a deeply relational perspective.

📖 Key Concepts

What is a Category?

A category C consists of:

  • Objects: A collection ob(C) of "things"
  • Morphisms: For each pair A, B, a set Hom(A,B) of "arrows" f: A → B
  • Identity: For each object A, an identity morphism id_A: A → A
  • Composition: Given f: A → B and g: B → C, we get g ∘ f: A → C

Satisfying associativity (h ∘ g) ∘ f = h ∘ (g ∘ f) and identity laws id ∘ f = f = f ∘ id.

Categories in Physics

Set   : Sets and functions
Vect  : Vector spaces and linear maps
Hilb  : Hilbert spaces and bounded operators
Man   : Smooth manifolds and smooth maps
Cob_n : (n-1)-manifolds and n-cobordisms

Physical theories ARE categories: objects are systems, morphisms are processes!

Functors: Structure-Preserving Maps

A functor F: C → D maps:

  • Objects A ↦ F(A)
  • Morphisms f: A → B ↦ F(f): F(A) → F(B)

Preserving identity F(id) = id and composition F(g ∘ f) = F(g) ∘ F(f).

Quantization is a functor from classical to quantum mechanics!

Natural Transformations

A natural transformation α: F ⇒ G between functors assigns to each object A a morphism α_A: F(A) → G(A) such that the naturality square commutes:

       F(A) ——α_A——→ G(A)
         |              |
       F(f)           G(f)
         ↓              ↓
       F(B) ——α_B——→ G(B)

  α_B ∘ F(f) = G(f) ∘ α_A

Physical laws are natural transformations—they hold uniformly across all processes.

💻 Code Examples

Categories in Haskell

class Category cat where
  -- Identity morphism
  identity :: cat a a

  -- Composition
  compose :: cat b c -> cat a b -> cat a c

-- Haskell functions form a category!
instance Category (->) where
  identity = id
  compose = (.)

-- Natural transformation
newtype NatTrans f g = NatTrans { runNatTrans :: forall a. f a -> g a }

-- Example: reverse is a natural transformation on lists
reverseNat :: NatTrans [] []
reverseNat = NatTrans reverse
-- Satisfies: reverse . map f = map f . reverse  ✓

🤖 AI Learning Prompts

Core Concepts

"Explain categories, functors, and natural transformations as if teaching a physicist. Use examples from physics: what are the objects and morphisms in the category of Hilbert spaces? What does a functor between physical theories represent?"

Yoneda Lemma

"Explain the Yoneda lemma to me intuitively. Why is it called 'the most important result in category theory'? What does it mean that objects are completely determined by their relationships to other objects? How does this relate to structural realism in philosophy of physics?"

Monoidal Categories

"Explain monoidal categories and why they matter for physics. How does the tensor product in a monoidal category model composite physical systems? What are the coherence conditions and why do they matter?"

Curry-Howard-Lambek

"Explain the Curry-Howard-Lambek correspondence: propositions are types, proofs are programs, and both correspond to objects and morphisms in categories. What does this triple correspondence mean for type-safe physics?"

Functors as Physics

"Give me examples of functors in physics: quantization, classical limits, coarse-graining. What does it mean to say 'the relationship between theories is functorial'? Why must quantization preserve composition?"

Natural Transformations as Laws

"Explain how physical laws can be viewed as natural transformations. Conservation of energy holds for ALL physical processes—this is naturality! How does Noether's theorem relate to natural transformations?"

Haskell Implementation

"Help me understand how Haskell's type system embodies category theory. Explain: types as objects, functions as morphisms, Functor type class, natural transformations as polymorphic functions. Show me the connection to parametric polymorphism and 'theorems for free'."

Adjunctions

"Explain adjoint functors: what does it mean for two functors to be adjoint? Give examples from mathematics (free/forgetful) and physics (quantization/classical limit). Why are adjunctions 'the right notion of sameness' for functors?"

✏️ Exercises

Exercise 1: Verify Category Axioms

Show that finite sets and functions form a category. Verify associativity and identity laws explicitly.

Exercise 2: Construct a Functor

Define the "free vector space" functor from Set to Vect. Show it preserves identity and composition.

Exercise 3: Naturality

Prove that the length function (length :: [a] → Int) is NOT a natural transformation, but head :: [a] → Maybe a IS natural.

📚 Resources