A Primer on Category Theory
What in the Heck
Category theory is a (relatively) nascent branch of mathematics that provides a fundamental framework for describing abstract structures in mathematics that serve as the building blocks for all mathematics; it contends set theory in this regard. This provides an excellent segway into aptly describing what these two paradigms focus in on: unlike set theory, category theory concerns the relation between elements (called objects). This necessitates expounding upon by explaining the three most important concepts in category theory.
The Triumvirate
Categories
This is the central point of study, evident in the eponymous name of the field. A category contains objects and morphisms (denoted by arrows). These morphisms are the structure preserving relations between the objects. Below is an example of a category:
Here, the letters A through C are the objects and the morphisms are f, g, and $$ f \circ g $$. More formally, a category $$ \mathcal C $$ is comprised of four things:
- Objects, denoted by $$ A, B, C,\ldots $$
- Morphisms: For a given ordered pair ($$ A, B $$) $$ \in \mathcal C $$, there is a class of morphisms from $$ A $$ to $$ B $$, denoted by $$ \text{Hom}_{C}(A,B). $$. This is sometimes called the hom class.
- Compositions, which follows analogously from function compositions; if $$ f: A \rightarrow B $$ and $$ g: B \rightarrow C $$, there exists a morphism $$ gf: A \rightarrow C $$.
- Identity: for any object $$ X $$, $$ 1_X: X \rightarrow X $$
The notion of objects and morphisms necessitate expounding. Objects can be any mathematical structure (i.e vector spaces, modules, smooth manifolds, rings). Morphisms are maps between two objects. There are several notable morphisms, but the few you’ll encounter the most are
- Homomorphisms (any general morphism)
- Monomorphisms (analogous to an injective function)
- Epimorphisms (analogous to a surjective function)
- Isomorphisms (when a morphism is bijective)
- Automorphisms (when there is an isomorphic map of an object onto itself)
- Endomorphisms (surjective maps of objects onto themselves)
Categories are bound by the properties of associativity and identity.
Examples
There are many categories that you’re familiar with, even if you don’t realize it. Here are just a few of these
- The Set category whose objects are sets related by morphisms which are functions
- The Top category whose objects are topological spaces related by morphisms which are continuous maps
- The Vect category whose objects are vector spaces over a given field, with its morphisms being linear transformations
- The Grp category whose objects are groups, related by homomorphisms
Functors
A functor is a mapping between two categories. Formally defined, let $$ \mathcal N $$ and $$ \mathcal M $$ be categories. A functor $$ T: \mathcal N \rightarrow \mathcal M $$ is a dual mapping which has:
- A mapping $$ F_{obj}: X \rightarrow X’$$ which takes an object $$ X \in \mathcal N $$ and assigns it to an object $$ X’ \in \mathcal M $$
- A mapping $$ F_{mor}: \text{Mor}(\mathcal N) \rightarrow \text{Mor}(\mathcal M) $$ which takes a Morphism $$ f: X \rightarrow Y \in \mathcal N $$ and assigns it to a morphism $$ F(f): F(X) \rightarrow F(Y) \in \mathcal M $$.
Functors must adhere to identities and composition. Functors are analogous to continuous functions. There are two types of functors: covariant and contravariant**. Covariant functors preserve arrow direction while contravariant functors reverse direction by swapping the source and target objects.
Natural Transformations
Just as a category has objects connected by morphisms and functors are a morphism between two categories, a natural transformation is just another abstraction in this chain; that is to say a natural transformation is a morphism between two functors. Formally,
If $$ F $$ and $$ G $$ are functors between categories $$ \mathcal A $$ and $$ \mathcal B $$, then a natural transformation $$ \eta: F \Rightarrow G $$ is a collection of morphisms which assign each object $$ X \in \mathcal A $$ to a morphism $$ \eta_{X}: F(X) \rightarrow G(X) $$ to objects $$ X \in \mathcal B $$ such that $$ \forall h: X \rightarrow Y \in A $$,
$$ \eta_{Y} \circ F(f) = G(f) \circ \eta_{X} $$
The aforementioned collection of morphisms is called a diagram. This diagram of morphisms is indexed by the objects $$ X \in \mathcal A $$, obeying the above equality. Diagrams are analogous to indexed families of sets in set theory.
Natural Transformations are analogous to homotopies
The Yoneda Lemma
Yoneda’s Lemma has a relatively simple formulation, but requires some new concepts:
Recall that if we have two objects $$ X $$ and $$ Y $$, $$ \text{Hom}(X, Y) $$ is the set of all morphisms between $$ X $$ and $$ Y $$. This is called the Hom class as stated above or Hom set. From this, we can discuss Hom functors. We define a contravariant Hom functor
$$ h_X = \text{Hom}(-,X): \mathcal C^{op} \rightarrow Set $$
where $$ \mathcal C^{op} $$ is the opposite category of $$ \mathcal C $$ obtained by reversing the direction of its arrows. This Hom functor maps an object $$ Y $$ to the Hom class $$ \text{Hom}(Y,X) $$. Hom sets are elements of the Set category so the Hom Functor above is a mapping from a category $$ \mathcal C $$ to Set. We then take an arbitrary representable presheaf (that is, some contravariant functor $$ F: \mathcal C \rightarrow Set $$ isomorphic with $$ h_X $$). Then, there exists a natural transformation
$$ \text{Nat}(h_X, F) \cong F(Y) $$
So what does this actually mean? It really says that an object $$ X \in \mathcal C $$ is completely determined by $$ \text{Hom}(-,X) $$; knowing how an object in a category can be mapped to and from determines the object up to isomorphism. This lemma is considered to be a generalization of Cayley’s Theorem
Applications
Category theory is generally best applied in the context of it being a toolbox which recognizes phenomena that occur broadly in mathematics. It can
be considered to be the scaffolding for abstract algebra just as assembly is for C. Outside of pure maths, there are some intriguing applications in
computer science. For example, haskell leverages category theory as the basis for its type system, going as far as to have a class called functor
and
even leverage the concept of morphism with its use of arrows.