In explanations about commutative monads, it is common to see a passing remark such as “as we’d expect, the Abelian monoid monad is commutative”. Now I might be over-interpreting these comments, but they seem to imply that the monad being commutative is related to the algebraic structure having a commutative binary operation. Now it is true that the Abelian monoid (a.k.a. multiset) monad is commutative, and several other commutative monads are induced by algebraic structures with commutative binary operations, but how well does this intuition hold together more generally?
Firstly, we consider if being a commutative monad implies commutativity of the binary operations in equational presentations.
Counterexample: We saw last time that the finite distribution monad is commutative. This monad is isomorphic to the monad presented by a family of binary operations satisfying the following equations:
- Idempotence: For all
,
.
- Pseudo-commutativity: For all
,
.
- Pseudo-associativity: For all
,
Algebras for this theory are called convex algebras. Intuitively, the operation forms the probabilistic mixture
and the axioms can be understood from this point of view. The pseudo-associativity axiom is particularly unpleasant to look at, but is easier to understand in terms of re-bracketing weighted binary combinations.
The axioms presenting convex algebras don’t have explicit commutativity equations for all the binary operations, but they might be derivable. To make sure this isn’t the case, we consider the concrete description of the free algebras that we get from the isomorphism to the finite distribution monad.
Specifically, the free algebra on has universe finitely supported convex sums over
, and the operations are the obvious weighted sums:
This operation is clearly not commutative, except when . So there is a commutative monad presented by an algebraic theory with (many different) non-commutative algebraic operations.
(I thank Maaike Zwart for suggesting this natural concrete counterexample)
What about the other direction, does an equational presentation where all the binary operations are commutative imply commutativity?
Counterexample: We have already seen that the exception monad is only commutative if
is a singleton set. The exception monad is isomorphic to the monad for an equational theory with constant symbols the elements of
, and no equations. So there are both commutative and non-commutative monads with presentations containing no binary operations at all.
The previous counterexample is a bit too trivial to be satisfactory, as there are no binary operations involved at all, and we’re quantifying over the empty set when making statements about commutativity in the algebraic sense.
As a second attempt, we shall synthesise an equational presentation in which the only components involved are commutative binary operations.
Counterexample: Consider an equational presentation with two binary operations and
, with the only equations being those requiring both operations are commutative. We consider the action of the double strengths on the equivalence classes
and
. For the first:
and for the second:
If this monad is commutative, we must have equality of equivalence classes:
We note that the provable equalities in our theory must have the same number of occurrences of
and
on both sides. Therefore the two equivalence classes are distinct, and the monad is not commutative.
So we have seen that there is a monad that is not commutative, presented by an equational theory containing only commutative binary operations.
The previous two counterexamples reflect the fact that commutative binary operations should not have anything essential to do with monad commutativity. Monads presented by theories with just constants may or may not be commutative. Theories just involving just binary operations may or may not be commutative. Obviously there are other arities of operation to consider, but by this point hopefully it’s clear that there’s no tight relationship.
In fact, a monad being commutative does imply that certain equations must hold. In the case of binary operations, it is sufficient for the operation to be commutative to satisfy some of these equations. In simple cases, for example theories with a single binary operation, this might explain some of the misleading patterns that emerge.
We shall examine commutative monads from an algebraic perspective in a later post, and see exactly what it is that can be commuted that inspires the terminology.