Category Theory
The point of Category Theory is to unify mathematical theories (like algebra, geometry, set theory, etc.) into terms that could be common among all the mathematics. It can also be seen as a higher level of abstraction above other mathematical constructs.
Category Theory can be brought down to:
- Composition
- Identity
A Category is a bunch of objects. It’s not a set of objects though, since a set is already quite a loaded term, with its own palette of rules. For simplicity, it’s then just easier to say that a category is a bunch of objects.
An object is a primitive - it has no properties nor structure. It’s like an atom, or a point, the lowest level of abstraction that we can go down to.
There might be morphisms between objects. Here’s an example of a morphism f between objects a and b:
A morphism is an arrow that has a beginning and an end. Between object a and object b, there can be:
- -1 morphisms
- 0 morphism
- many morphisms
An arrow can point from a to b and from b to a at the same time. Or, there could be arrow(s) starting and ending at the same object.
So, a Category is a bunch of objects with morphisms between pairs of these objects. A category could be seen as a kind of graph, loosely speaking - there could be an inifinite number of arrows.
Axioms
Composition and Identity are the fundamental rules of a category.
Composition
If there’s a morphism taking us from a to b and a morphism taking us from
b to c, then there has to be a morphism taking us from a to c defined
as: g ○ f
. The ○
symbol mens that g
is applied after f
(g ○ f
= g
after f
).
The g ○ f
arrow is a composition of arrows f
and g
.
It’s sometimes called multiplication.
Identity
Every object in a category has its identity morphism:
Composition with Identity
Composition of any morphism with identity returns the original morphism:
That’s the right identity.
We can also reverse the order of the morphisms:
That’s the left identity.
Associativity
Example
An example of applying category theory could be the following. Let’s imagine that we have sets A and B:
There is a mapping between A and B, so there exists a function that transforms elements from A to elements from B.
Category theory is supposed to unify various mathematical terms or theories under one umbrella. Therefore, we can transform the sets into category representation:
A set becomes an object. We have objects A and B. Between them, three morphisms have been drawn, because the sets A and B had three functions between them.
We can also see that there is an identity defined for each object. In sets, such identity would be a function that takes a set, and returns the same set.
If there was another set - C - and there was a function defined between some element of B and C, we could draw another object - C - with a morphism between B and C. Possibly, we could also have a composition consisting of morphisms between A and B, and B and C.
After creating the set category, we can forget about the origin of that data, i.e. that it was a bunch of sets. Now we work on that category using category theory. It’s an abstraction making it possible to look at a set (a “low-level thing”) from a higher level of abstraction. It’s kinda like moving from assembler to some high-level language. Instead of a set consisting of some elements, we have a table of morphisms that define our new category. They define the interface of this category. The sets themselves have been “shrunk” down to points A and B.
Functions
In set theory, functions are defined as relations. Relation is a set of tuples (a,b), where a ∈ A and b ∈ B. We have sets:
- domain
- codomain (which is a superset of a range)
A function takes elements from a domain and maps it to some element from a codomain.
Isomorphism
A function may be invertible. A function y = f(x)
is invertible when there is
a way to transform it into x = g(y)
. Such a function f
has to be
one-to-one (which is a synonym of injection) and onto (which is a synonym
of surjection).
- one-to-one- there are no two arguments that have the same result.
- surjective - the range and the codomain are the same
In other words, g
is a reverse of f
, if g ○ f = id
(and f ○ g = id
). A
function that is invertible is called an isomorphism. Here is an example of
an isomorphic mapping (it’s the same illustration as up above):
This is not an isomorphic function:
Given b1
, we cannot resolve it to a single element from A
since both a1
and a2
map to b2
.
Getting back to Category Theory, ismorphism cannot be defined in terms of injective or surjective functions, because these terms have different names in that context.
Injection (one-to-one) becomes epimorphism (epic).
Surjection (onto) becomes monomorphism (monic).