…, a monoid is a category, a category is a monad, a monad is a monoid, …

In the last few months I taught three graduate mini-courses about string diagrams and graphical linear algebra – at Phd Open in Warsaw, a winter school in Estonia, and a graduate school in Leicester. That and teaching have been keeping me busy, so I haven’t invested as much time as I would have liked on the blog. There was also the need to write down all the work done in Hawaii, and Dusko, Filippo and I just finished writing a meaty technical report, which will soon appear on the arXiv. The time that I actually did spent writing blog stuff was distributed across a number of different articles; so now I have a whole bunch of half-finished stuff. I really need to start managing this whole project a little better!

Here’s something really short and off the cuff. At MGS in Leicester, during the exercise sessions, I talked about distributive laws of props. At the same graduate school, Alexander Kurz was giving a course on category theory.  I got the inspiration for this article from one of his lectures.

As part of the distributive laws of props story, you realise that categories are a special case of the concept of monad. But monads are a special case of the concept of monoidAnd monoids–of course–are a special case of the concept of category. By transitivity of the “special case of” relation, we should therefore probably just admit that they are all really the same thing: some kind of Platonic form of plugging things into each other. The story is full of pleasant categorical mental gymnastics. Think of it as the categorical equivalent of a 5km fun run.

… , a monoid is a category, …

A category is a collection of objects and arrows. Every object has an identity arrow, and any pair arrows f: A → B, g: B → C, where f‘s codomain is the same as g‘s domain, can be composed. Composition is associative, and composing with identities does nothing.

If we restrict to categories with exactly one object – let’s give it a name, say – there is just one identity arrow  (the identity id* on *). Every arrow has * as both domain and codomain, since there are no other objects around. So every arrow can be composed with every other arrow. Composition is associative, and composing with id* on either side leaves any arrow unchanged. In other words, there is a set of arrows Ar with a total, associative, unital operation: i.e. a monoid. The fact that there is an object * adds no interesting information.

So every monoid is a kind of category, a category with one object. Categories, it would seem, are the more general concept. Indeed, some people say that categories are the “categorification” of the concept of monoid. Maybe categories should actually have been called monoidoids?

… , a category is a monad, …

One way to define the concept of monad is as a triple (T, μ, η), where T: C → C is an endofunctor, μ: T2 → T is the multiplication natural transformation, and η: 1 → C is the unit natural transformation. Multiplication μ is associative and has η as unit, which is usually said with the aid of three commutative diagrams.

In the famous paper 1970s paper “The formal theory of monads“, Ross Street realised that this popular definition is unnecessarily specific. There’s no reason to be overly specific in mathematics: if you can easily have a more general theory/theorems, then why not? What matters is getting to the core of the issues, and not getting too hung up on extraneous details.

In this specific case, an endofunctor is a 1-cell in the 2-category Cat of categories, functors, and natural transformations. The data defining a monad is thus one 1-cell and two 2-cells, subject to some commutative diagrams of 2-cells. The fact that this data lives in Cat brings nothing important to the story: the definition clearly makes sense in any 2-category.

The 2-category Span(Set) is one of my favourites. It’s actually a bicategory–composition is not strictly associative, but we will ignore that detail for the purposes of this lightning article. It’s really just a bit of bureaucracy and adds nothing to the story. Trust me.

The objects of Span(Set) are sets. The arrows from X to Y are spans of functions

X ← Z → Y

Identities are spans formed of two identity functions. Composition of spans involves taking pullbacks. Finally, the 2-cells are span morphisms; functions Z→Z’ that make the two resulting triangles commute. I won’t bore you with the details which you can find on nlab.

The interesting question is what happens when we consider a monad in Span(Set). An endo-1-cell is span of the form

X ← Y → X                           (†).

Let’s call the left function δ0 and the right δ1. Now we need to give two 2-cells, that is, morphisms of spans. Let’s do the unit first: when you unpack the definitions it is a function

ι: X → Y such that δ0ιx = δ1ιx = x.

The multiplication μ goes from the span composed with itself back to itself. When you compute the composition, taking the pullback, the span is

X ← Y×XY → X

where XY = { (y,y’) | δ1(y) = δ0(y’) }. So μ: Y×XY → Y, satisfying δ0μ(y, y’) = δ0y and δ1μ(y, y’) = δ1y’.

So far so good. Associativity says simply that μ(μ(y, y’), y”) = μ(y, μ(y’, y”)) and the unit conditions say that μ(y, ιδ1 y) = y = μ( ιδ0y, y).

All this data has another name: a category. Let’s make it clearer with more familiar terminology: X is the set of objects, Y is the set of arrows. δ0 and δ1 give, respectively, the domain and codomain of each arrow. The function ι: X→Y picks out the identity arrows. Next, XY is the set of composable arrows, and μ: Y×XY → Y defines the composition for any composable pair. The remaining conditions say exactly that composition is associative and identities work as they should. It’s precisely the data we need.

So, a category is just a special case of the more general concept of monad, right?

… , a monad is a monoid, …

Not so fast. We talked about monads in the generality of 2-categories. The theory of monoids can be easily generalised too: there’s no reason for the specificity of  “set” M, with unit “element” e and multiplication “function” m, satisfying associativity and the unit equations. The world would be boring if everything was just sets and functions. In fact, the concept of monoid makes sense in any monoidal category. Pick some monoidal category X; the data of a monoid consists of

an object X, and arrows m: X⊗X → X and e: I → X

where I is the monoidal unit object. Associativity and the unit laws can be expressed as three commutative diagrams. The usual monoid-as-a-set version is now a monoid, in the more general sense, instantiated in the monoidal category of sets and functions Set×. Here the cartesian product serves as monoidal product.

So now let’s consider some 2-category C, pick an object  C and focus on the set of 1-cells from C to C. Let’s call this thing [C, C]. Actually, it’s not really a set: it’s the full sub-2-category of C on C; i.e. a 2-category with one object. We saw before that to give a category with one object is to give a monoid. In the same spirit, a 2-category with one object has the same information as a (strict) monoidal category. The objects are the 1-cells, and monoidal product (on 1-cells) is composition. I’ll leave the remaining details as a simple exercise.

So what is a monoid in [C, C], considered as a monoidal category? You guessed it – it’s a monad.

So monads are really special kinds of monoids. And monoids are really special kinds of categories. And categories are really special kinds of monads. And …

10 thoughts on “…, a monoid is a category, a category is a monad, a monad is a monoid, …”

“since there is are other objects around”

Liked by 1 person

2. I really enjoyed reading this. The last section is very condensed, so I had to re-read it several times before I finally got it. Juggling 1-cells, 2-cells, and monoidal products at the same time takes some concentration.
I noticed a typo in your definition of mu: delta one (y, y’) should be delta one mu (y, y’).

Liked by 1 person

• Thanks, I fixed the typo! And yes, I did speed up in the end — the blog has been a bit dormant in the last few months and I wanted to get an article out fast.
Thanks for commenting, and I’m happy you enjoyed it!

P.S. On the hacker news submission for this article https://news.ycombinator.com/item?id=14126629 a lot of people are raving about your videos; I need to check them out!

Like

3. zeta12ti says:

(reposted from reddit)

So from my reading of this, we have

Monoid: Ordinary 1-category with one object.

Category: Monad internal to the 2-category Span(Set)

Monad: A monoid object internal to monoidal category of endofunctors of a given ordinary 1-category.

The only problem is this doesn’t use consistent definitions for each. For example, we have to consider monads internal to a 2-category and monoids internal to a monoidal category, but elsewhere use the usual definitions (internal to Cat/Set). Using “generalized” to indicate this, we get “a monoid is a category, a category is a generalized monad, a monad is a generalized monoid” It doesn’t quite work thanks to the passing from generalized to ordinary.

Another thing, in the “a category is a monad” section, we actually only recover small categories (a set of objects and morphisms), so you won’t get something like Set from that construction (which has a proper class of objects and morphisms). It’s not really necessary for this idea though; you could just replace every instance of category with small category (“…a monoid is a small category” etc.). Monoids are typically implicitly small, though there’s no reason we couldn’t extend the definition to large monoid-like structures.

I wonder if it’s possible to start and end at literally the same thing through sufficient generalization. Maybe make everything internal to an arbitrary infinity category with enough (weak) pullbacks.

btw, when I say n-category, I always mean the weak variant, so for example a 2-category is what this author calls a bicategory.

Liked by 3 people

4. The sentence that talks about [C, C] is confusing: “Actually, it’s not really a set: it’s the full sub-2-category of C on C; i.e. a 2-category with one object.” I think you don’t mean that [C, C] is the sub-2-category. The sub-2-category is the object C together with endo-1-cells and 2-cells. Right? It’s confusing especially because [C, C] is indeed a 1-category. Hom objects in a bicategory are categories.

Like

• Yeah, it’s a bit confusing the way it’s written. I meant to highlight the fact that if we focus down on the full sub-2-cat determined by one object, the data is the same as the data of a monoidal category. Objects = 1-cells, Arrows = 2-cells, composition = vertical composition of 2-cells, monoidal product on objects = composition of 1-cells, monoidal product on arrows = horizontal composition of 2-cells.

Like