In many previous posts, we have discussed connections between monads and universal algebra. So far, we have seen that given a presentation of an algebraic theory in terms of set of operations , and equations , there is a corresponding monad such that:

- The Eilenberg-Moore algebras of the monad are the algebras described by the chosen presentation.
- The Kleisli category is the full subcategory of free algebras.

Many other aspects of monad theory can then be stood from this algebraic perspective.

Every monad arising from a presentation in terms of operations and equations is finitary. This is a technical condition saying that certain colimits are preserved by the monad endofunctor, but we will not dwell on the precise details. Intuitively, the idea is that the functor is completely defined by its action on finite objects. The key point is that there is a correspondence between algebraic presentations and finitary monads, *for which the categories of algebras coincide*. It is essential that the categories of models agree for this relationship to be algebraically meaningful. Note this is *not* a bijection, as a given finitary monad will have infinitely many potential presentations in terms of operations and equations.

In this post, we will see a third perspective on describing algebraic structures, Lawvere theories. These sit somewhere between conventional universal algebra and monads in their level of abstraction. As with any mathematical phenomenon, each new perspective deepens our understanding, and emphasises new features and intuitions.

## The Idea of Lawvere Theories

To be concrete, lets consider what we need to do to describe a monoid. The general situation for different algebraic structures will follow in the same way.

Typically, we first pick out an underlying set , and two functions:

- A zero argument function, or constant, for the unit element. We can identity this as a function .
- A two argument function, or binary operation, for the monoid multiplication. We can identify this with a function .

Of course, once we have these functions, we can build further ones by combining them together. For example

Which informally we can think of as corresponding to a term . Of course, by one of the monoid unit axioms, we require that this composite is equal to

which we can think of as corresponding to a variable . So in this way of describing a monoid, we:

- Pick out some basic operations, which are maps of the form .
- Build lots of other operations by composing the basic operations together, using category composition, and the properties of products.
- Require that certain of the operations are equal.

We note some issues with this naive plan. Firstly, where did the basic operations come from, and why do we distinguish them from the other operations? This bias towards certain operations seems categorically unnatural, and raises the ugly question of whether any further mathematical results we derive might be dependent on our choice of presentation. Secondly, a small but annoying detail. It was a pain that was only isomorphic, and not equal to when we built our composite terms. If we build up more complicated composites involving higher Cartesian powers, we will spend a lot of time bookkeeping how to bracket expressions like:

for no practical benefit. So putting all this together, it would be convenient if we could describe the theory of monoids as a category with:

- Objects the natural numbers, corresponding to the number of arguments of our operations.
- (Strict) finite products are given by adding the required arities together .
- Intuitively, we consider an operation of arity to be a morphism of type . For example, a binary operation is a morphism and a constant is a morphism . Notice that, unlike the common convention,
*in this case is the terminal object*. - A family of such operations is a morphism of type . This is automatic from universal property of the assumed strict finite products.
- A diagram commutes in our category if and only if the corresponding operations should be equal in the theory of monoids.

In fact, it is technical important to add a little bit more structure. If we consider the category of sets, and take the full subcategory with objects

this category clearly has finite coproducts, given by:

If we identify the objects of this category with the natural numbers, via:

this yields a category with finite coproducts , and therefore a category with finite products .

Moving away from the special case of monoids, we then define a **Lawvere theory** to be a category with strict finite products, with an identity on objects strict finite product preserving functor . The category can be interpreted as encoding the operations and equations of the theory. We shall return to the interpretation of the inclusion later. A **morphism of Lawvere theories** is a finite product preserving functor such that .

What we really wanted to do was describe a class of algebraic structures, using our theory. A **model of a Lawvere theory** in a category with finite products is a finite product preserving functor

and a homorphism of models is a natural transformation between them. For conventional algebraic structures, we take . Note we don’t require that the models interact appropriately with the product structure, as in fact this is automatic. The category of models of a Lawvere theory and their homomorphisms is denoted

This approach of identifying structures with functors from a suitably structured category is known as **functorial semantics**. Notice the difference with monads as a categorical tool for describing algebraic structures. The Eilenberg-Moore category of a monad captures algebraic structures on a fixed base category, whereas we can straightforwardly considering models of Lawvere theories in any category with finite products. There is a forgetful functor given by evaluation at the object :

In many cases, for example if is locally presentable, this functor will have a left adjoint, and will therefore induce a monad on . So a single Lawvere theory induces monads on many different base categories.

If we have two Lawvere theories such that we have equivalence:

then there is an isomorphism in the category of Lawvere theories. So there is a very tight correspondence between Lawvere theories and the category of models that they describe.

## How to build a Lawvere – take one

So how do we build a Lawvere theory? One approach is to start with a presentation . We then form a category with:

- Object the natural numbers
- Morphisms are m-tuples of terms in variables, quotiented by provable equality in equational logic, with respect to the equations of our presentation.
- The product projection onto the ith component of a product corresponds to the term for the ith variable.
- Identity morphisms are (necessarily) the tuples of projection morphisms.
- Composition is given by substitution of terms.
- The inclusion morphism picks out the projection morphism in .

So we see the intuition for the inclusion is that it picks out the trivial terms corresponding to bare variables within the broader collection of operations.

**Example**: We can build a Lawvere theory for monoids from the usual presentation in terms of a unit and multiplication operation, and unitality and associativity axioms. The category is then equivalent to the usual category of monoids.

Note is important that we do not require models of a Lawvere theory strictly preserves product structure. For the usual products in , if we did this, the category of models for the Lawvere theory of monoids would be empty!

## How to build a Lawvere Theory – take two

Instead of starting with a presentation in terms of operations and equations, what if we were given a finitary monad? Can we construct a Lawvere theory directly from this data?

The structure of a Lawvere theory in terms of equivalence classes of terms composed by substitution sounds suspiciously like the algebraic perspective on the Kleisli category of a monad. In fact, the two are very similar, up to some cosmetic details. For a finitary -monad , we can construct a Lawvere theory as follows:

- Form the Kleisli category .
- Restrict to the full subcategory of objects , and rename the objects to natural numbers in a similar way to the section above.
- Take the opposite category.

Tersely, we say the required Lawvere theory is the opposite of (the skeleton of) the full subcategory of finitely generated free algebras. As we would hope, we have an equivalence between and , so the categories of models coincide.

## Monads to Lawvere Theories

Given a Lawvere theory , we would like to go in the other direction, and construct a corresponding finitary monad. This can be done by taking a coend:

If this is unfamilar, the idea is that we can construct the required monad as a certain categorical colimit. Intuitively, we form the collection of equivalence classes of terms, identifying product structure where appropriate.

Again, the categories of Eilenberg-Moore algebras and models of the Lawvere theory in agree up to equivalence.

In fact, the connection between Lawvere theories and finitary monads is about as strong as we might hope. *The category of Lawvere theories is equivalent to the category of finitary monads on .* The presence of the inclusion morphism in the definition of a Lawvere theory ensures that this equivalence goes through correctly.

## Conclusion

Lawvere theories give a presentation independent formulation of algebra. They have several strengths:

- They are relatively close in form to concepts from conventional universal algebra. In particular, they can be seen as an abstraction of the notion of clone.
- Unlike monads, a single object can describe models taken in different categories. For example, we can take models of the Lawvere theory of monoids in sets, posets, topological spaces and so on.
- Certain operations for combining theories are more natural from the perspective of Lawvere theories, rather than that of finitary monads.
- They are algebraic by construction. By comparison, monads include structures such as the continuation monad, which don’t have a clear interpretation in terms of universal algebra.

There are many generalisations of Lawvere theories, for example to incorporate operations of larger aritites, or enrichments of the base category. These typically come with a correspondence to a natural class of monads, providing a different perspective to work with. The functorial semantics of Lawvere theories also suggests other structures, such as PROs and PROPs, which move us further away from convention algebra to structures potentially having multiple outputs as well as inputs.

One intriguing question is what is the equivalent of Lawvere theories for comonads. At this point there does not seem to be a satisfactory answer, as highlighted in the paper “Category Theoretic Understandings of Universal Algebra and its dual: monads and Lawvere theories, comonads and ?” This example highlight how comonad theory cannot always be seen as routinely “flipping monad theory upside down”, and sometimes a routine application of duality isn’t enough.

**Further reading**: An excellent source for background is the book “Algebraic Theories” by Adamek, Rosicky and Vitale. Also useful for background is Hyland and Power’s “The Category Theoretic Understanding of Universal Algebra: Lawvere Theories and Monads”. Power has developed much of the theory generalising Lawvere theories in various ways, and applying them in computer science.