If you’re like me, you might be worried that the world is being taken over by monoids. Binary operators that are associative and respect unity are popping up everywhere. Even our beloved monads are being dismissively called “just” monoids in the category of endofunctors. Personally, I have nothing against associativity, but when it’s not there, it’s not there. Did you know, for instance, that addition is non-associative? Of course, I’m talking about floating-point addition. Taking averages is non-associative. Lie algebras are non-associative. At a recent FARM (Functional Art, Music, Modelling and Design) Workshop, Paul Hudak spoke of a non-associative way of tiling temporal media (the %\ — percent backslash — operator).

In mathematics, there exists a simpler notion of *magma*, which is a structure with a binary operator with no additional conditions imposed on it. So monoid is really “just” a magma with some additional structure. Take that monoid!

There was a recent interesting post about free magmas and their relation to binary trees, which shows that magmas might be relevant outside of geology. All this encouraged me to revisit some of the areas traditionally associated with monoids and give them another look-see. If nothing else, it’s an opportunity to have a little refresher in monoidal and enriched categories. Hopefully, this will also help in understanding Edward Kmett’s latest experiments with encoding category theory in Hask.

## Magmatic Category

Let’s start by slimming down the usual definition of a monoidal category: A magmatic category is a category 𝒱_{0} with a functor ⨁ : 𝒱_{0} ⨯ 𝒱_{0} → 𝒱_{0} from the cartesian product of 𝒱_{0} with itself to 𝒱_{0}. This is our “attach” operator that works on objects and can be lifted to morphisms.

That’s it! A monoidal category would also have the unit object I, the associator, the left unitor, the right unitor, and two coherence axioms. But if magma is all we need, we’re done.

In what follows I’m not going to be interested in associativity until much later, but I will consider including the unit object I (a magma with a unit is called a *unital* magma). What defines the unit object are two natural (in X) isomorphisms: *l*_{X}: I ⨁ X → X, and *r*_{X}: X ⨁ I → X, called, respectively, the left and the right unitors. Still, because of no associativity, there are no coherence axioms one has to worry about in a monoidal category.

Having a unit object allows us to define an interesting functor that maps any object X to the hom-set 𝒱_{0}(I, X) — the set of morphisms from I to X (obviously, this is a set only if 𝒱_{0} is locally small). We’ll call this functor V, to make sure you pay attention to fonts, and not just letters. Why is it interesting? Because it’s as close as we can get, in category theory, to defining an element of an object. Remember: in category theory you don’t look inside objects — all you have at your disposal are morphisms between amorphous objects.

So how would you define an element of, let’s say, a set, without looking inside it? You’d define it as a function (morphism) from a *one-element set*. Such a morphism picks a single element in the target set. But what’s a one-element set (remember: we can’t look inside sets)? Well, it’s a *terminal object* in the category of sets. Again, a terminal object is defined entirely in terms of morphisms. It’s the object that has a unique morphism coming to it from any other object. (Exercise: Show that a one element set is terminal among sets.)

So an element of a set can be defined as a morphism from the terminal set. Nothing stops us from extending this definition of an “element” to an arbitrary category that has a terminal object. But what does a terminal object have to do with a unit object in the monoidal (or unital-magmatic) category? In the archetypal monoidal category — the cartesian monoidal category — the terminal object *is* the unit. The binary operator is the product, defined by a universal construction. That’s why we can call a morphism f from the hom-set 𝒱_{0}(I, X) an *element* of X. In this language, V maps X into a set of *elements* of X — the *underlying* set.

## Exponential Objects and Currying

The usual universal construction of an exponential object Y^{X} can be easily reproduced in a magmatic category. We just replace the cartesian product in that construction with the “attach” operator we have at our disposal.

Here’s how you do it: Start with a pair of objects, X and Y. Consider all pairs <object Z, morphism g> in which g is a morphism from Z ⨁ X to Y. We are looking for one of these pairs, call it <Y^{X}, app>, such that any other pair “factorizes” through it (Y^{X} is just an object with a funny symbol). It means that, for each <Z, g> there is a unique morphism λg : Z→ Y^{X}, such that:

g = app ∘ (λg ⨁ id)

Notice that we are using the fact that ⨁ is a (bi-)functor, which means it can be applied to morphisms as well as objects. Here it’s applied to λg and id (the identity morphism on X).

There is an interesting class of categories in which there is an exponential object for every pair of objects. Or even better, an exponential objects that is defined by an adjunction. An adjunction relates two functors. In this case, one functor is defined by the action of the binary operator: Z→ Z ⨁ X. The exponentiation functor Y→ Y^{X} is then its right adjoint. The adjunction is a natural bijection of hom-sets:

λ: 𝒱_{0}(Z ⨁ X, Y) ≅ 𝒱_{0}(Z, Y^{X})

This equation is just the re-statement of the condition that for every g : Z ⨁ X→ Y there is a unique λg : Z→ Y^{X}, except that we now require this mapping to be natural in both Y and Z.

Here’s the interesting part: This definition can be viewed as generalized currying. Normal currying establishes the relationship between functions of two arguments and functions returning functions. A function of two arguments can be thought of as a function defined on a cartesian product of those arguments. Here, we are replacing the cartesian product with our magmatic operation, and the adjunction tells us that for every morphism g from Z ⨁ X to Y there is a morphism λg from Z to the exponential object Y^{X}. The currying intuition is that Y^{X} objectifies morphisms from X to Y; it objectifies the hom-set 𝒱_{0}(X, Y) inside 𝒱_{0}. In fact Y^{X} is often called the *internal* hom-set (in which case 𝒱_{0}(X, Y) is called the *external* hom-set).

This intuition is reinforced by the observation that, if we replace Z with I, the magmatic unit, in the adjunction, we get:

𝒱_{0}(I ⨁ X, Y) ≅ 𝒱_{0}(I, Y^{X})

I ⨁ X is naturally isomorphic to X (through the left unitor), so we get:

𝒱_{0}(X, Y) ≅ 𝒱_{0}(I, Y^{X})

Now recall what we have said about morphisms from the unit: they define elements of an object through the functor we called V. The equation:

𝒱_{0}(X, Y) ≅ V Y^{X}

tells us that elements of the (external) hom-set 𝒱_{0}(X, Y) are in one-to-one correspondence with the “elements” of the exponential Y^{X}. This is not exactly the isomorphism of external and internal hom-sets, because of the intervening functor V, which might not even be faithful. However, this is exactly one of the conditions that define a closed category, hinting at the possibility that the adjunction defining the exponential object in a unital magmatic category might be enough to make it closed.

All this was done without any mention of associativity. So what is associativity good for? Here’s an example. Let’s replace X with (A ⨁ B) in the adjunction:

𝒱_{0}(Z ⨁ (A ⨁ B), Y) ≅ 𝒱_{0}(Z, Y^{(A ⨁ B)})

If we have associativity, the above is naturally isomorphic to:

𝒱_{0}((Z ⨁ A) ⨁ B, Y) ≅ 𝒱_{0}(Z ⨁ A, Y^{B}) ≅ 𝒱_{0}(Z, Y^{BA})

Putting it all together and replacing Z with I, we get the natural isomorphism between “elements” of two objects:

V Y^{(A ⨁ B)} ≅ V Y^{BA}

This looks just like currying inside the internal hom-set, except for the functor V. So to curry from the external to the internal hom-set it’s enough to have a unital magmatic category, but to curry within the internal hom-set we need the full monoidal category.

A word about notation: Traditionally, the exponential object from X to Y is denoted as Y^{X}. That’s the convention I’ve been following so far. Arguably, this notation is somewhat awkward. In his book, Basic Concepts of Enriched Category Theory, Kelly uses a more convenient notation: [X, Y]. In his notation, the above equation takes a slightly more readable form:

V [(A ⨁ B), Y] ≅ V [A, [B, Y]]

## Magmatically Enriched Category

A (locally small) category consists of object and sets of morphisms, hom-sets, between every pair of objects. All we need to assume about morphisms is that they compose nicely and that there exist morphisms that act as units of composition. Think of it this way: Each hom-set is an object from the Set category. Composition is a mapping from a cartesian product of two such objects to a third object.

But why restrict ourselves to Set to draw our hom-sets from? Why not pick an arbitrary category? The only question is: How should we define composition of morphisms? Morphisms are *elements* of hom-sets. In an arbitrary category we might not be able to define *elements* of objects. What we could do, however, is to pick a category that has all the products and define composition as a mapping (morphism) from a product of two objects to a third object. This is analogous to defining composition in terms of cartesian products of hom-sets, rather than defining it point-wise on individual morphisms.

But once we made a bold decision to abandon sets, why restrict ourselves to cartesian monoidal categories (the ones with a product defined by a universal construction)? All we really need is some notion of a binary operation, and that’s given by a magmatic category. So let’s define a magmatically enriched category 𝒜 as a collection of objects together with an additional magmatic category (𝒱_{0}, ⨁) from which we pick our hom-objects (no longer called hom-*sets*). For any two objects A and B in the category 𝒜, a hom-object 𝒜(A, B) is an object of 𝒱_{0}. Composition is defined for any triple of objects A, B, and C. It’s a morphism between objects in 𝒱_{0}:

M: 𝒜(B, C) ⨁ 𝒜(A, B) → 𝒜(A, C)

Of course I stole this definition from a monoidally enriched category. Another part of it, which might be useful in the future, is the definition of a unit element. In a normal category, a unit morphism id_{A} is an element of the hom-set 𝒜(A, A) of morphisms that go from A back to A. In an enriched category, the only way to define an *element* of a hom-object is though a mapping from a unit object I, so here’s the generalization of the identity morphism:

j_{A}: I → 𝒜(A, A)

We have to make sure that there is appropriate interplay between composition, left and right unitors, and the unit element. These are expressed through commutative diagrams:

As before, since we don’t have to worry about associativity, we can omit the rest of the axioms.

## Functors and Natural Transformations

A functor maps objects to objects and morphisms to morphisms. The mapping of objects translates directly to enriched settings, but we don’t want to deal with morphisms individually. We don’t want to look inside hom objects. Fortunately, we can define the action of a functor on a hom-object as a whole. The mappings of hom-objects are just morphisms in 𝒱_{0}.

To define a functor T from an enriched category 𝒜 to ℬ, we have to define its action on any hom-object 𝒜(A, B):

T_{AB} : 𝒜(A, B) → ℬ(T A, T B)

Notice that both categories must be enriched over the same 𝒱_{0} for T_{AB} to be a morphism.

A natural transformation is trickier. Normally it is defined as a family of morphisms parameterized by objects. In the enriched setting, we have a slight problem: For a given object A we have to pick a single morphism from the hom-object ℬ(T A, S A). Here T and S are functors between two enriched categories 𝒜 and ℬ. Luckily, we have this trick of replacing element selection with a mapping from the unit object. We’ll use it to define the *components* of a natural transformation:

α_{A}: I → ℬ(T A, S A).

The fact that the existence of the unit is necessary to define natural transformations in enriched categories is a little surprising. It also means that adjointness, which is defined through *natural* isomorphism between hom-objects, cannot be defined without a unit.

The generalization of the naturality condition is also tricky. Normally we just pick a morphism f : A → B in the category 𝒜 and lift it using two functors, T and S, to the target category ℬ. We get two morphisms,

T f : T A → T B

S f : S A → S B

We can then compose them with two components of the natural transformation,

α_{A} : T A → S A

α_{B} : T B → S B

and demand that the resulting diagram commute:

α_{B} ∘ T f = S f ∘ α_{A}

In an enriched category we can’t easily pick individual morphisms, so we have to operate on whole hom-objects. Here’s what we have at our disposal. The components of the natural transformation at A and B:

α_{B}: I → ℬ(T B, S B)

α_{A}: I → ℬ(T A, S A)

The action of the two functors on the hom-object connecting A to B:

T_{AB} : 𝒜(A, B) → ℬ(T A, T B)

S_{AB} : 𝒜(A, B) → ℬ(S A, S B)

Also, the composition of morphisms is replaced with the action of our binary operator on hom-objects. If you look at the hom-sets involved in the standard naturality condition, their composition corresponds to these two mappings under M:

ℬ(T B, S B) ⨁ ℬ(T A, T B) → ℬ(T A, S B)

ℬ(S A, S B) ⨁ ℬ(T A, S A) → ℬ(T A, S B)

The right hand sides are identical, the left hand sides can be obtained by either acting with α on the unit object, or by lifting the hom-object 𝒜(A, B) using S or T. There aren’t that many choices in this jigsaw puzzle. In particular, we get:

α ⨁ T : I ⨁ 𝒜(A, B) → ℬ(T B, S B) ⨁ ℬ(T A, T B)

S ⨁ α : 𝒜(A, B) ⨁ I → ℬ(S A, S B) ⨁ ℬ(T A, S A)

Finally, both of the left hand sides can be obtained from 𝒜(A, B) by applying the inverse of, respectively, *l* and *r* — the left and right unitors (remember, they are isomorphisms, so they are invertible). That gives us the naturality hexagon:

## Representable functors and the Yoneda lemma

On the surface, the enriched version of the Yoneda lemma looks deceptively simple. But there are some interesting nuances that should be mentioned. So let me recap what Yoneda is in the more traditional setting (see my blog post about it). It’s about functors from an arbitrary category to a much simpler category of sets — a category where we can actually look at elements, and where morphisms are familiar functions. In particular we are practically given for free those very convenient representable functors. These are the functors that map objects to hom-sets. You just fix one object, say K, in the category 𝒜, and for any other object X you get the set 𝒜(K, X) in Set.

This mapping of X to 𝒜(K, X) is called a representable functor because, in a way, it represents the object X as a set. It is a functor because it’s also defined on morphisms. Indeed, take a morphism f: X → Y. Its image must be a function from 𝒜(K, X) to 𝒜(K, Y). So pick an h in 𝒜(K, X) and map it to the composition f∘h, which is indeed in 𝒜(K, Y).

Now take any functor F from 𝒜 to Set, not necessarily representable. Yoneda tells us that natural transformations from any representable functor 𝒜(K, _) to F are in one to one correspondence with the elements of F K. In other words, there is a bijection:

Nat(𝒜(K, _), F) ≅ F K

which, additionally, is natural in both K and F (naturality if F requires you to look at F as an object in the category of functors, where morphisms are natural transformations).

### Enriched representable functors

So how do we go about generalizing Yoneda to an enriched category. We start with a representable functor, except that now 𝒜(K, X) is not a hom-set but a hom-object in 𝒱_{0}. The mapping from the enriched category 𝒜 to 𝒱_{0} cannot be treated as an enriched functor, because enriched functors are only defined between categories enriched over the same base category, and 𝒱_{0} is not enriched. So the trick is to enrich 𝒱_{0} over itself.

What does it mean? We want to keep the objects of 𝒱_{0} but somehow replace the hom-sets with objects from — again — 𝒱_{0}. Now, if 𝒱_{0} is closed, it contains objects that are perfect for this purpose: the exponential objects. We’ll call the category resulting from enriching 𝒱_{0} over 𝒱_{0} simply 𝒱, hoping not to cause too much confusion. So we define a hom-object 𝒱(X, Y) as [X, Y] (the new notation for Y^{X}). We can apply our magmatic binary operator to two such hom-objects and map the resulting object to another hom-object:

M: [Y, Z] ⨁ [X, Y] → [X, Z]

This defines composition of hom-objects for us. The mapping is induced by the adjunction that defines the exponential object, and in fact requires associativity, so we can relax and admit that we are now in a closed monoidal (rather than magmatic) category. Oh well!

We’ve seen before that there is a mapping between hom-sets and exponentials, which we can rewrite in this form:

𝒱_{0}(X, Y) ≅ V [X, Y]

(with V on the right hand side the functor that defines “elements” of an object). So 𝒱 not only has the same objects as 𝒱_{0} but its hom-objects are lifted by the functor V from hom-sets of 𝒱_{0}. That makes 𝒱 a perfect stand-in for 𝒱_{0} in the enriched realm.

We are now free to define (enriched) functors that go from any category 𝒜 enriched over 𝒱_{0} to 𝒱. In particular, the mapping 𝒜(K, _): 𝒜 → 𝒱, which assigns the object 𝒜(K, X) to every X, defines a representable enriched functor. This way an object X in some exotic enriched category 𝒜 is represented by an object in a presumably better understood category 𝒱 which, being closed and monoidal, has more structure to play with.

### Enriched Yoneda lemma

We now have all the tools to formulate the Yoneda lemma for enriched categories. Let’s pick an object K in an enriched category 𝒜. It defines an enriched representable functor, 𝒜(K, _) from 𝒜 to 𝒱. Let’s take another functor F from 𝒜 to 𝒱. The Yoneda lemma states that all natural transformations between these two functors:

α: 𝒜(K, _) → F

are in one-to-one correspondence with “elements” of the object F K, where by “elements” we mean mappings:

η: I → F K

More precisely, there is a bijection (one-to-one mapping that is onto) between the set of natural transformations Nat(𝒜(K, _)) and the set 𝒱_{0}(I, F K).

Nat(𝒜(K, _)) ≅ 𝒱_{0}(I, F K).

Notice that the bijection here is between *sets*: a set of natural transformations and a set of morphisms. There is a stronger version of the Yoneda lemma, which established a bijection between objects rather than sets. But for that one needs to objectify natural transformations, something that can indeed be done using ends. But that’s a topic for a whole new post.

## Conclusions

My main motivation in this blog post was to try to figure out how far one can get with magmas before being forced to introduce a unit, and how far one can get with unital magmas before being forced to introduce associativity. These results are far from rigorous, since I might not have been aware of some hidden assumptions, and because the fact that some property is used in the proof of another property doesn’t mean that it is necessary.

So here’s the short summary. The following things are possible to define:

- Magmatic category
- Exponential objects and currying in a magmatic category
- Adjunction between magmatic product and exponentiation — the internal hom
- In unital magmatic category, the adjunction leads to isomorphism between external hom-set and “elements” of the internal hom
- Currying in the internal hom requires a monoidal category

Having a magmatic category one can define a magmatically enriched category and the following things:

- Functors
- Natural transformations — only over unitally magmatic category
- Enriched Yoneda lemma — only over monoidal category

## Acknowledments

I’m grateful to Gershom Bazerman for stimulating discussions and helpful pointers.

## Bibliography

- G. M. Kelly, Basic Concepts of Enriched Category Theory
- nLab, Closed category

September 30, 2014 at 7:04 pm

Cheers, I discovered more than your blog, I discovered a kindred spirit: I too combine both worlds of theoretical physics and programming.

“in category theory you don’t look inside objects — all you have at your disposal are morphisms between amorphous objects.” Indeed.

It may interest you that quantum mechanics has a very deep relationship with category theory and monoids: category theory completely determine the algebraic structure of QM and from this one obtains the standard formulation in terms of Hilbert spaces, nothing more, nothing less (http://arxiv.org/abs/1407.7610).

November 4, 2014 at 8:37 am

Hi, I have a hard time reading this post because of the inability of my different browsers to correctly display the 𝒜 and 𝒜.:(

Is there anything I can do about it ?

Best regards

December 22, 2017 at 7:22 am

I stumbled onto this page because I was trying to understand more about the Eckmann Hilton Argument. In the category of Monoids you use the argument to show that a monoid object is a commutative monoid. But if you do the math in the category of sets, the assumptions are set with two compatible unital Magma structures (both operations are homomorphisms of each other). and proves that both magmas have the same unit, that they are equal, and that they are associative. So I am wondering is a magma object in the category of Magmas a commutative magma