Category Theory Foundations
Category Theory is often called “the mathematics of mathematics.” It provides a high-level language for describing cross-disciplinary patterns across algebra, topology, logic, and computer science. Instead of focusing on the elements inside a set, Category Theory focuses on the relationships (morphisms) between objects.
The Definition of a Category
A Category consists of:
- Objects: A collection of objects .
- Morphisms: For every pair of objects , a set of arrows (morphisms) .
- Composition: For and , there is a composition .
- Identity: For every object , there is an identity morphism .
Laws
- Associativity: .
- Unit Laws: and .
Examples of Categories
- Set: Objects are sets; morphisms are functions.
- Grp: Objects are groups; morphisms are group homomorphisms.
- Top: Objects are topological spaces; morphisms are continuous functions.
- Vect: Objects are vector spaces over field ; morphisms are linear maps.
Functors
A Functor is a mapping between categories that preserves structure. It maps:
- Objects to objects .
- Morphisms in to morphisms in .
Functors must preserve identities () and composition ().
Examples:
- Forgetful Functor: Maps a Group to its underlying Set, “forgetting” the group operation.
- Free Functor: Maps a Set to the Free Group generated by that set.
- PowerSet Functor: Maps a set to its power set and functions to their direct images.
Natural Transformations
If Functors are “morphisms between categories,” then Natural Transformations are “morphisms between functors.” A natural transformation provides a family of morphisms such that for any , the following diagram commutes:
This ensures that the transformation is consistent across all objects in the category.
Limits and Colimits
In Category Theory, common constructions like products, unions, and quotients are generalized as Limits and Colimits.
- Product: Generalizes the Cartesian product. It is an object with projections and such that any other object with similar projections factors uniquely through .
- Terminal Object: An object such that for every object , there is exactly one morphism . (In Set, the terminal object is any singleton set).
Universal Properties
A construction is defined by a Universal Property if it is the “best” or “unique” such construction (up to unique isomorphism). This is the standard way to define objects in Category Theory—not by what they are made of, but by how they interact with everyone else.
Python: Representing a Morphism
While Category Theory is abstract, it maps directly to functional programming and type theory.
from typing import Callable, TypeVar, Generic
A = TypeVar('A')
B = TypeVar('B')
C = TypeVar('C')
class Category:
@staticmethod
def compose(f: Callable[[A], B], g: Callable[[B], C]) -> Callable[[A], C]:
return lambda x: g(f(x))
@staticmethod
def identity(x: A) -> A:
return x
# A simple morphism in the category Set
f = lambda x: x + 1
g = lambda x: x * 2
h = Category.compose(f, g) # Equivalent to g(f(x))
print(h(5)) # (5 + 1) * 2 = 12
Why it Matters
Category theory allows us to see that a Product in Group Theory behaves exactly like a Product in Topology or a Product in Computer Science (like a Tuple). It exposes the underlying unity of mathematics and helps prove theorems that apply to all structures at once.