When studying mathematics, universal properties will show up eventually. Most Linear Algebra II courses have to give a definition of the tensor product, and while it is completely possibly to define it for two \(\mathbb{K}\) vector spaces as \[ V \tensor W := \frac{\mathbb{K}\langle V \times W\rangle}{\langle (v_1 + v_2, w) - (v_1, w) - (v_2, w), (v, w_1 + w_2) - (v, w_1) - (v, w_2), (\lambda v, w) - \lambda(v, w), (v, \lambda w) - \lambda(v, w) \rangle}, \] this will for one require separate definitions for other categories making abstraction and reuse of the tensor product difficult (analogous to the Liskov substitution principle from programming) and seconly the defintion is quite long compared to using the universal property.
But I still remember exactly how a classmate once insisted to ask questions to our professor after a lecture, trying to understand what these universal properties actually are, and he never quite got an explanation he was happy with. So here’s my take:
Categories
A category \(\cat{C}\) in category theory is just a collection of objects \(\Ob(\cat{C})\) and arrows \(\Arr(\cat{C})\) (also called morphisms or homomorphisms, or something else entirely depending on the category) between those objects.
We usually assume \(\Ob(\cat{C})\) is a set, and picture categories as directed graphs. In general these graphs have infinitely many nodes and edges, and a slice of one might look like this:
Figure 1: An example of objects and arrows like these might show up in \(\cat{Vect}_\R\).
Diagrams
In Figure 1 we’ve already seen a slice of a category. A fitting name for that would be a diagram. And that’s exactly what such formations are called!
If I have a category \(\cat{C}\), I can pick objects \(A_1, \dots, A_n\) in it and arrows \(f_1, \dots, f_m\) between those objects, which together make up such a slice. So we’re indexing a “subset” (careful: \(\Ob(\cat{C})\) and \(\Arr(\cat{C})\) don’t have to be sets!) and we get a diagram in \(\cat{C}\).
In the language of functors, a diagram is then a functor \(D: \cat{J} \to \cat{C}\), where \(\cat{J}\) is an index category, just formal objects \(\underline{1}, \underline{2}, \dots, \underline{n}\) and formal arrows \(\underline{f_1}, \dots, \underline{f_m}\) between them. \(D\) is then the “glue” that goes from \(\cat{J}\) to \(\cat{C}\).
That gives us Figure 2 as a diagram, namely the following functor:
Figure 2: The index category \(\cat{J}\) (left) with its image under the functor \(D\) (right) which is the latter is exactly the diagram from Figure 1. Remember that this diagram is contained in a far bigger graph.
Universal cones
We’re now halfway through our explanation of universal properties. Given a diagram, you can picture it as a directed graph of objects and arrows from \(\cat{C}\) drawn on a sheet of paper. A cone is then an object \(N\) in \(\cat{C}\) that has an arrow to every object in the diagram, such that all triangles with tip \(N\) and base in the diagram commute.
Figure 3: The diagram from Figure 1 lies on the “sheet of paper”; \(N\) floats above it with an arrow to each object. Drag the slider to draw in the commuting triangles with tip \(N\).
In most cases you’ll have several \(N\)’s, each with arrows into the diagram that make them a cone. Now if you have two such cones \(N_1\) and \(N_2\), one of them might be “smaller” than the other! If there’s an arrow \(N_1 \to N_2\) such that all the triangles still commute, then \(N_2\) is a cone that’s “smaller” than \(N_1\).
Figure 4: Two cones \(N_1\) and \(N_2\) over the same diagram, with the comparison arrow \(N_1 \to N_2\).
If such a universal cone exists (also called a limit), we’ve found an object with the universal property given by the diagram.
One example would be the tensor product, or also the product of objects: depending on which diagram you choose, you get different universal properties that “conjure up” different objects.
Figure 5: For the tensor product, a universal cone over the diagram has to exist for arbitrary bilinear maps \(\varphi: V \times W \to X\) and \(\psi: V \times W \to Y\), and that cone is then the tensor product \(V \tensor W\). The dots between \(\varphi\) and \(\psi\) show that there has to be an arrow in this diagram for every bilinear map with source \(V \times W\) and arbitrary target \(X\) and \(Y\) and we only hint at some.
Demystifying via logic
For most mathematicians, category theory won’t be as familiar as logic is. If you’re more comfortable with logic, you can reduce the language of diagrams and cones down to simple equations:
Given a diagram like this one
Figure 6: The abstract triangle \(f, g, h\) — the slider shows what “commutes” means here.
we can write the condition that this diagram commutes simply as the equation \(h \circ f = g\).
If we want to require several commuting triangles, we can just AND the equations together: \(h_1 \circ f_1 = g_1 \wedge h_2 \circ f_2 = g_2 \wedge \dots h_m \circ f_m = g_m\). Of course we could also use diagrams more complex than triangles, but by the axioms of category theory we can always compose two arrows into one, which produces a triangle.
We can then require the existence of a cone by demanding \(\exists N \in \Ob(\cat{C}) \forall i \in \{1, \dots, n\} \exists f_i: N \to A_i: h_i \circ f_i = g_i\).
If we now want to express, using logic alone, the universality of an object \(N\) with arrows \(f_i': N \to A_i\) with respect to the diagram, we can write the following: \(\forall N_1 \in \Ob(\cat{C}), \forall f_1 : N_1 \to A_1, \dots, f_n : N_1 \to A_n: h_1 \circ f_1 = g_1 \wedge \dots \wedge h_n \circ f_n = g_n \implies \exists ! f: N_1 \to N: f_i' \circ f = f_i \wedge h_i \circ f_i' = g_i \forall i \in \{1, \dots, n\}\). This also makes it pretty clear why people prefer diagram notation instead.
Colimits
Just like an object above the sheet of paper you drew the diagram on, you can also require an object below it, meaning all the arrows go into the object \(N\) instead of out of it! That gives you colimits. Examples would be the coproduct, i.e. the sum of objects.
Figure 7: The dual picture of Figure 4: the same diagram, but now \(N_1\) and \(N_2\) hang below it and the arrows leave the diagram instead of pointing at it — that’s what turns the cone into a cocone.
Real life applications
I have encountered various usages in corporate jobs where this actually gets applied. In fact: the entire job’s purpose was to find a universal object! One important fact is, that we can use category theory to model state changes in state machines: Each object signifies a state and each arrow with this object as its domain represents a state change to another state (the codomain of that arrow).
This technique is famously used for markov chains, where we enrich our category by giving each arrow a weight or probability. Summing over all the weights of all the arrows with domain \(X\) then is required to be \(1\), and each weight must be a positive real number.
Dropping this probability requirement, modelling state changes is one of the most important aspects not just in the job of a software developer or data scientist, but in any job. This is what flow charts are for! However, some routes through a flow chart (or equivalently different algorithms) can lead to the exact same result!
For example: filtering a dataset of people to only include those with surname “Meyer” and then mapping \((+1)\) to their age is equivalent to first mapping \((+1)\) to everyone and loosing information about everyone who does not have the surname “Meyer” (i.e. filtering). In both instances, we end up with the exact same dataset.
This is a trivial example so far, but chain these together and complexity stacks up quickly. Often during conversations with other workers in the IT-sector, their misunderstandings came from not realizing that two different algorithms lead to the same result, making them repeat the same mistakes over and over again, as they struggled to realize some diagram commutes.
So: commutative diagrams are already of utmost importance in the IT-sector. Universal properties are in fact even more so. If you are tasked during a job to find some data that satisfies some constraints, then you have already applied the concept of limits and colimits at your work. You simply lay down which properties your data must satisfy, construct a commutative diagram from that and take the limit (see also F-Algebras).
A toy example would be trying to find the minimum of a list of real numbers which are at least \(0\). We can constrct a diagram that encodes both properties \(\ge 0\) and \(\min\), then take the limit and we are done.
The animations of this post have been inspired by Imaginary Numbers Are Real by Welch Labs