Enriched Lawvere Theories for Operational Semantics
John C. Baez (University of California, Riverside), Christian Williams, (University of California, Riverside)

TL;DR
This paper introduces enriched Lawvere theories as a flexible framework for modeling operational semantics of formal systems, enabling translation between different semantic forms and unifying models through the Grothendieck construction.
Contribution
It extends Lawvere theories to enriched settings, allowing detailed descriptions of operational semantics and providing a categorical approach to relate various semantic models.
Findings
Enriched Lawvere theories effectively model operational semantics.
The Grothendieck construction unifies models across contexts.
Application to SKI-combinator calculus demonstrates practical utility.
Abstract
Enriched Lawvere theories are a generalization of Lawvere theories that allow us to describe the operational semantics of formal systems. For example, a graph enriched Lawvere theory describes structures that have a graph of operations of each arity, where the vertices are operations and the edges are rewrites between operations. Enriched theories can be used to equip systems with operational semantics, and maps between enriching categories can serve to translate between different forms of operational and denotational semantics. The Grothendieck construction lets us study all models of all enriched theories in all contexts in a single category. We illustrate these ideas with the SKI-combinator calculus, a variable-free version of the lambda calculus.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsLogic, programming, and type systems · Logic, Reasoning, and Knowledge · Computability, Logic, AI Algorithms
Enriched Lawvere Theories for Operational Semantics
John C. Baez and Christian Williams
Department of Mathematics
U. C. Riverside
Riverside
CA
92521 USA
[email protected], [email protected]
Abstract
Enriched Lawvere theories are a generalization of Lawvere theories that allow us to describe the operational semantics of formal systems. For example, a graph-enriched Lawvere theory describes structures that have a graph of operations of each arity, where the vertices are operations and the edges are rewrites between operations. Enriched theories can be used to equip systems with operational semantics, and maps between enriching categories can serve to translate between different forms of operational and denotational semantics. The Grothendieck construction lets us study all models of all enriched theories in all contexts in a single category. We illustrate these ideas with the -combinator calculus, a variable-free version of the lambda calculus.
1 Introduction
Formal systems are not always explicitly connected to how they operate in practice. Lawvere theories [21] are an excellent formalism for describing algebraic structures obeying equational laws, but they do not specify how to compute in such a structure, for example taking a complex expression and simplifying it using rewrite rules. Recall that a Lawvere theory is a category with finite products generated by a single object , for “type”, and morphisms representing -ary operations, with commutative diagrams specifying equations. There is a theory for groups, a theory for rings, and so on. We can specify algebraic structures of a given kind in some category with finite products by a product-preserving functor . This is a simple and elegant form of denotational semantics. However, Lawvere theories know nothing of operational semantics. Our goal here is to address this using “enriched” Lawvere theories.
In a Lawvere theory, the objects are types and the morphisms are terms; however, there are no relations between terms, only equations. The process of computing one term into another should be given by hom-objects with more structure. In operational semantics, program behavior is often specified by labelled transition systems, or labelled directed multigraphs [27]. The edges of such a graph represent rewrites:
{(\lambda x.x+x\;\;2)}$${2+2}$${4}$$\scriptstyle{\beta}$$\scriptstyle{+}
We can use an enhanced Lawvere theory in which, rather than merely sets of morphisms, there are graphs or perhaps categories. Enriched Lawvere theories are exactly for this purpose.
In a theory enriched in a category of some kind of “directed object”, including graphs, categories, and posets, the theory has the following interpretation:
[TABLE]
To be clear, this is not a new idea. Using enriched Lawvere theories for operational semantics has been explored in the past. For example, category-enriched theories have been studied by Seely [30] for the -calculus, and poset-enriched ones by Ghani and Lüth [24] for understanding “modularity” in term rewriting systems. They have been utilized extensively by Power, enriching in -complete partial orders to study recursion [14] – in fact, there the simplified “natural number” enriched theories which we explore were implicitly considered.
The goal of this paper is to give a simple unified explanation of enriched Lawvere theories and some of their applications to operational semantics. We aim our explanations at readers familiar with category theory but not yet enriched categories. To reduce the technical overhead we only consider enrichment over cartesian closed categories.
In general for a cartesian closed category , a -theory is a -enriched Lawvere theory with natural number arities. We consider as a choice of “method of computation” for algebraic theories. The main idea of this paper is that product-preserving functors between enriching categories allow for the translation between different kinds of semantics. This translation could be called “change of computation”—or, following standard mathematical terminology, change of base.
Because operational semantics uses graphs to represent terms and rewrites, one might expect some category like , the category of directed multigraphs, to be our main example of enriching category: that is, the “thing” of -ary operations, or -variable terms in a theory, is a directed graph whose edges are rewrites. This is known as small-step operational semantics, meaning each edge represents a single instance of a rewrite rule.
When studying formal languages, one wants to pass from this local view to a global view: given a term, one cares about its possible evolutions after not only one rewrite but any finite sequence of rewrites. We study how programs operate in finite time. In computer science, this corresponds to defining a rewrite relation and forming its transitive closure, called big-step operational semantics. This is the classic example which change of base aims to generalize.
However, there is a subtlety. We may try to model the translation from small-step to big-step operational semantics using the “free category” functor, which for any directed multigraph forms the category whose objects are vertices and morphisms are finite paths of edges. However, this functor does not preserve products. One might hope to cure this using a better-behaved variant of directed multigraphs, such as reflexive graphs. One advantage of reflexive graphs is that that each vertex has a distinguished edge from it to itself; these describe rewrites that “do nothing”. Thus, in a product of reflexive graphs there are edges describing the process of rewriting one factor while doing nothing in the other. This lets us handle parallelism. Unfortunately, as we shall explain, the free category functor from reflexive graphs to categories still fails to preserve products.
To obtain a product-preserving change of base taking us from small-step to big-step operational semantics, it seems the cleanest solution is to generalize graphs to simplicial sets. A simplicial set is a contravariant functor from the category of finite linear orders and monotone maps to the category of sets and functions. It can be visualized as a space built from “simplices”, which generalize triangles to any dimension: point, line, triangle, tetrahedron, etc. For an introduction to simplicial sets, see Friedman [13]. We use to denote the category of simplicial sets, namely .
Simplicial sets allow one to generalize rewriting to higher-dimensional rewriting, but this is not our focus here. Indeed, we only need two facts about simplicial sets in this paper:
- •
There is a full and faithful embedding of , the category of reflexive graphs, in , so we can think of a reflexive graph as a special kind of simplicial set (namely one whose -simplices for are all degenerate).
- •
The free category functor , often called “realization”, preserves products.
We thus obtain a spectrum of cartesian closed categories to enrich over, each connected to the next by a product-preserving functor, which allow us to examine the computation of term calculi in various ways:
[TABLE]
In Section 2 we review Lawvere theories as a more explicit, but equivalent, presentation of finitary monads. In Section 3, we recall the basics of enrichment over cartesian closed categories. In Section 4 we give the central definition of -theory, adapted from the work of Lucyshyn-Wright [23]. Using his work we show that a -theory gives a monadic adjunction between and the -category of models of in . This generalizes a fundamental result for Lawvere theories.
In Section 5 we discuss how suitable functors between enriching categories induce change of base: they transform theories, and their models, from one method of rewriting to another. Our main examples arise from this chain of adjunctions:
[TABLE]
The right adjoints here automatically preserve finite products, but the left adjoints do as well, and these are what we really need:
- •
The functor maps a simplicial set (for example a reflexive graph) to the category it freely generates. Change of base along maps small-step operational semantics to big-step operational semantics.
- •
The functor maps a category to the poset whose elements are objects of , with iff has a morphism from to . Change of base along maps big-step operational semantics to full-step operational semantics.
- •
The functor maps a poset to the set of “components” of , where are in the same component if . Change of base along maps full-step operational semantics to denotational semantics.
In Section 6 we show that models of all -theories for all enriching can be assimilated into one category using the Grothendieck construction. In Section 7 we bring all the strands together and demonstrate these concepts in applications. First we consider the -combinator calculus, and then we show how theories enriched over the category of labelled graphs can be used to study bisimulation.
Acknowledgements
This paper builds upon the ideas of Mike Stay and Greg Meredith presented in “Representing operational semantics with enriched Lawvere theories” [31]. We appreciate their offer to let us develop this work further for use in the innovative distributed computing system RChain, and gratefully acknowledge the support of Pyrofex Corporation. We also thank Richard Garner, Todd Trimble and others at the -Category Café for classifying cartesian closed categories where every object is a finite coproduct of copies of the terminal object [3].
2 Lawvere Theories
Algebraic structures are traditionally treated as sets equipped with operations obeying equations, but we can generalize such structures to live in any category with finite products. For example, given any category with finite products, we can define a monoid internal to to consist of:
[TABLE]
Lawvere theories formalize this idea. For example, there is a Lawvere theory , the category with finite products freely generated by an object equipped with an identity element and multiplication obeying the associative law and unit laws listed above. This captures the “Platonic idea” of a monoid internal to a category with finite products. A monoid internal to then corresponds to a functor that preserves finite products.
In more detail, let be any skeleton of the category of finite sets . Because is the free category with finite coproducts on , is the free category with finite products on . A Lawvere theory is a category with finite products equipped with a functor that is the identity on objects and preserves finite products. Thus, a Lawvere theory is essentially a category generated by one object and -ary operations , as well as the projection and diagonal morphisms of finite products.
For efficiency let us call a functor that preserves finite products cartesian. Lawvere theories are the objects of a category whose morphisms are cartesian functors that obey . More generally, for any category with finite products , a model of the Lawvere theory in is a cartesian functor . The models of in are the objects of a category , in which the morphisms are natural transformations.
A theory can thus have models in many different contexts. For example, there is a Lawvere theory , the theory of monoids, described as above. Ordinary monoids are models of this theory in , while topological monoids are models of this theory in .
For completeness, it is worthwhile to mention the presentation of a Lawvere theory: how exactly does the above “sketch” of produce a category with finite products? It is precisely analogous to the presentation of an algebra by generators and relations: we form the free category with finite products on the data given, and impose the required equations. The result is a category whose objects are powers of , and whose morphisms are composites of products of the morphisms in , projections, deletions, symmetries and diagonals. A detailed account was given by Barr and Wells [5, Chap. 4].
In 1965, Linton [22] proved that Lawvere theories correspond to “finitary monads” on the category of sets. For every Lawvere theory , there is an adjunction:
[TABLE]
The functor
[TABLE]
sends each model to its underlying set, . Its left adjoint, the free model functor
[TABLE]
sends each finite set to the representable functor , and in general any set to the colimit of all such representables as ranges over the poset of finite subsets of . In rough terms, is the model of all -ary operations from on the set .
If we momentarily abbreviate as , we obtain an adjunction
[TABLE]
where the left isomorphism arises from the Yoneda lemma, and the right isomorphism from the product preservation of .
This adjunction induces a monad on :
[TABLE]
The integral here is a coend, essentially a coproduct quotiented by the equations of the theory and the equations induced by the cartesian structure of the category. This forms the set of all terms that can be constructed from applying the operations to the elements, subject to the equations of the theory. The monad constructed this way is always finitary: that is, it preserves filtered colimits [2], or its action on sets is determined by its action on finite sets.
Conversely, for a monad on , its Kleisli category is the category of all free algebras of the monad, which has all coproducts. There is a functor that is the identity on objects and preserves coproducts. Thus,
[TABLE]
is a cartesian functor, and restricting its domain to is a Lawvere theory . To see what this is doing, note that:
[TABLE]
where the latter is considered as -ary operations in the Lawvere theory . When is finitary, the monad arising from this Lawvere theory is naturally isomorphic to itself.
This correspondence sets up an equivalence between the category of Lawvere theories and the category of finitary monads on . There is also an equivalence between the category of models of a Lawvere theory and the category of algebras of the corresponding finitary monad . Furthermore, all this generalizes with replaced by any “locally finitely presentable” category [2]. For more details see [5, 21, 25].
One final point, provided to us by Mike Stay: while monads are often associated with functional programming languages such as Haskell, Lawvere theories correspond to interfaces or abstract classes in object-oriented programming. In these one declares various constants, types, and abstract functions satisfying tests, and then one implements the interface by assigning these elements, sets, functions, and equations—precisely a model in . While people think of monads as the main example of “categories in programming”, in fact Lawvere theories are ubiquitous.
3 Enrichment
To incorporate the aspect of computation, we now turn to Lawvere theories that have hom-objects rather than mere hom-sets. To do this we use enriched category theory [19] and replace sets with objects of a cartesian closed category , called the “enriching” category or “base”. A -enriched category or -category is:
[TABLE]
such that composition is associative and unital. A -functor is:
[TABLE]
such that preserves composition and identity. A -natural transformation is:
[TABLE]
such that is “natural” in : an evident square commutes. There is a 2-category of -categories, -functors, and -natural transformations.
We can construct new -categories from old ones by taking products or opposites, in obvious ways. There is also a -category denoted with the same objects as and with hom-objects given by the internal hom:
[TABLE]
The concepts of adjunction and monad generalize straightforwardly to -categories, and when we speak of an adjunction or monad in the enriched context this generalization is what we mean [19]. For example, there is an adjunction
[TABLE]
called “currying”.
We can generalize products and coproducts to the enriched context. Given a -category , the -coproduct of an -tuple of objects is an object equipped with a -natural isomorphism
[TABLE]
If such an object exists, we denote it by . This makes sense even when : a 0-ary -coproduct in is called a -initial object and denoted as . When is cartesian closed, any finite coproduct that exists in is also a -coproduct in . In particular,
[TABLE]
whenever [math] is an initial object of . Conversely, any finite -coproduct that exists in is also a coproduct in the usual sense.
Similarly, a -product of objects is an object equipped with a -natural isomorphism
[TABLE]
If such an object exists, we denote it by . A 0-ary product in is called a -terminal object and denoted as . Whenever is cartesian closed, the finite products in are also -products in . In particular,
[TABLE]
where our chosen terminal object is also -terminal. Conversely, any finite -product in is also a product in the usual sense.
A general -category does not exactly have projections from a -product to its factors, since given two objects there is not, fundamentally, a set of morphisms from to . Instead there is the hom-object , which is an object of . However, any object of has a set of elements, namely morphisms . Elements of act like morphisms from to .
In particular, any -product gives rise to elements
[TABLE]
which serve as substitutes for the projections in a usual product. These elements are defined as composites
[TABLE]
where the isomorphism comes from Eq. (2) and the last arrow is a projection in .
Even better, we can bundle up all these elements into a single element
[TABLE]
which serves as a substitute for the universal cone in a usual product. Starting from we can recover the -natural isomorphism in Eq. (2) as follows:
[TABLE]
where the last arrow is given by composition. Thus, we say a universal cone exhibiting as the -product of objects is an element such that the -natural transformation given by Eq. (3) is an isomorphism.
The advantage of this reformulation is that we can say a -functor preserves finite -products if for every universal cone exhibiting as the -product of the objects , the composite
[TABLE]
is universal cone exhibiting as the -product of the objects .
A bit more subtly, generalizing the exponentials in , a -category can have “powers”. Given , we say an object is a -power of if it is equipped with a -natural isomorphism
[TABLE]
In the special case this forces to be the -fold product of copies of . As with -products, it is useful to repackage the isomorphism of Eq. (4) so we can say what it means for a -functor to preserve -powers. First, note that this isomorphism gives rise to an element
[TABLE]
namely the composite
[TABLE]
Conversely, any element determines a -natural transformation , and we say is a universal cone if this -natural transformation is an isomorphism. Next, suppose and are -categories with -powers. We say a -functor preserves -powers if it maps universal cones to universal cones.
There are just a few more technicalities. A category is locally finitely presentable if it is the category of models for a finite limits theory, and an object is finite if its representable functor is finitary: that is, it preserves filtered colimits [2]. A -category is locally finitely presentable if its underlying category is locally finitely presentable, has finite powers, and is finitary for all finitely presentable . The details are not crucial here: all categories to be considered are locally finitely presentable. We will use to denote the full subcategory of of finite objects: in , these are simplicial sets with finitely many -simplices for each .
4 Enriched Lawvere Theories
Power introduced the notion of enriched Lawvere theory about twenty years ago, “in seeking a general account of what have been called notions of computation” [28]. The original definition is as follows: for a symmetric monoidal closed category , a “-enriched Lawvere theory” is a -category that has powers by objects in , equipped with an identity-on-objects -functor
[TABLE]
that preserves these powers. A “model” of a -theory is a -functor that preserves powers by finite objects of . There is a category whose objects are models and whose morphisms are -natural transformations. The monadic adjunction and equivalence of Section 2 generalize to the enriched setting.
In this paper, however, we only consider natural number arities, while still retaining enrichment. To do this we use the work of Lucyshyn-Wright [23], who along with Power [26] has generalized Power’s original ideas to allow a more flexible choice of arities. We also limit ourselves to the case where the tensor product of is cartesian. This has a significant simplifying effect, yet it suffices for many cases of interest in computer science.
Thus, in all that follows, we let be a cartesian closed category equipped with chosen finite coproducts of the terminal object , say
[TABLE]
Define to be the full subcategory of containing just these objects . There is also a -category whose objects are those of and whose hom-objects are given as in . We define the -category of arities for to be
[TABLE]
We shall soon see that has finite -products.
Definition 1**.**
We define a -theory to be a -category equipped with a -functor
[TABLE]
that is the identity on objects and preserves finite -products.
Definition 2**.**
A model of in a -category is a -functor
[TABLE]
that preserves finite -products.
Just as all the objects of a Lawvere theory are finite products of a single object, we shall see that all the objects of are finite -products of the object
[TABLE]
Definition 3**.**
We define , the category of -theories, to be the category for which an object is a -theory and a morphism from to is a -functor that preserves finite -products and has .
Definition 4**.**
For every -theory and every -category with finite -products, we define , the category of models of in , to be the category for which an object is a -functor that preserves finite -products and a morphism is a -natural transformation.
The basic monadicity results for Lawvere theories generalize to -theories when is complete and cocomplete, as in the main examples we consider: and . Under this extra assumption and can be promoted to -categories, which we call and . Furthermore, there is a -functor
[TABLE]
sending any model to its underlying object . Recall that monads and adjunctions make sense in , just as they do in . The -functor has a left adjoint
[TABLE]
and is equivalent to the -category of algebras of the resulting monad . More precisely:
Theorem 5**.**
Suppose is cartesian closed, complete and cocomplete, and has chosen finite coproducts of the terminal object. Let be a -theory. Then there is a monadic adjunction
[TABLE]
Proof.
This follows from Lucyshyn-Wright’s general theory [23], so our task is simply to explain how. He allows to be a symmetric monoidal category, and uses a more general concept of algebraic theory with a system of arities given by any fully faithful symmetric monoidal -functor . For us and is the obvious inclusion; this is his Example 3.7.
Lucyshyn-Wright defines a -theory to be a -functor that is the identity on objects and preserves powers by objects in (or more precisely, their images under ). For us . So, to apply his theory, we need to show that a -functor preserves powers by objects in if and only if it preserves finite -products. This is Lemma 16 below.
He defines a model (or “algebra”) of a -theory to be a -functor that preserves powers by objects in . He defines a morphism of models to be a -natural transformation between such -functors. So, to apply his theory, we also need to show that when , a -functor preserves powers by objects of if and only if it preserves finite -products. This is Lemma 17 below.
A technical concept fundamental to Lucyshyn-Wright’s theory is that of an eleutheric system of arities . This is one where the left Kan extension of any -functor along exists and is preserved by each -functor . In Example 7.5.5 he shows that is eleutheric when is countably cocomplete. In Thm. 8.9 shows that when is eleutheric, and has equalizers, we may form the -category , and that the forgetful -functor
[TABLE]
is monadic. This is the result we need. So, our theorem actually holds whenever is cartesian closed, with equalizers and countable colimits, and has chosen finite coproducts of the initial object. ∎
Before turning to examples, a word about Lucyshyn-Wright’s construction of the left adjoint and the monad is in order. These rely on the “free model” on an object . This is the enriched generalization of the free model described in Section 2: it is the composite of with the enriched Yoneda embedding :
[TABLE]
Since an object of does not necessarily have a “poset of finite subobjects” over which to take a filtered colimit (as in ), the extension of this “free model” functor to all of is specified by a somewhat higher-powered generalization: it is the left Kan extension of along .
[TABLE]
This is the universal “best solution” to the problem of making the triangle commute up to a -natural transformation. That is, for any functor and -natural transformation , the latter factors uniquely through . From the adjunction between and the category of models we obtain a -enriched monad
[TABLE]
and this has a more concrete formula as an enriched coend:
[TABLE]
We next give two examples of a rather abstract nature, where we show how -enriched Lawvere theories can describe categories with extra structure. In Section 7 we study examples more directly connected to operational semantics.
Example 6**.**
When , a -category is a 2-category, so a -theory deserves to be called a 2-theory. For example, let be the 2-theory of pseudomonoids. A pseudomonoid [10] is a weakened version of a monoid: rather than associativity and unitality equations, it has 2-isomorphisms called the associator and unitors, which we can treat as rewrite rules. To equate various possible rewrite sequences, these 2-isomorphisms must obey equations called “coherence laws”. Power [20] has introduced “enriched sketches” as a way of presenting enriched Lawvere theories. Informally, here is a presentation of the 2-theory for pseudomonoids:
[TABLE]
[TABLE]
[TABLE]
[TABLE]
We write the equations as commutative diagrams merely for convenience; they could also be written as equations in a more traditional style. The top diagram expresses the pentagon identity for the associator, while the bottom one expresses the usual coherence law involving the left and right unitors.
Models of in are monoidal categories: let us explore this example in more detail. A model of is a finite-product-preserving 2-functor , which sends
[TABLE]
such that the coherence laws of the rewrites are preserved. Thus, a model is a category equipped with a tensor product and unit object such that these operations are associative and unital up to natural isomorphism; so these models are precisely monoidal categories.
Given two models , a morphism of models is a 2-natural transformation ; this amounts to a strict monoidal functor . The strictness arises because morphisms between models are 2-natural transformations rather than pseudonatural transformations. There is a substantial amount of theory on pseudomonads and pseudoalgebras [7, 11], but to the authors’ knowledge the theory-monad correspondence has not yet been extended to include the case of weak naturality.
Finally, because is complete and cocomplete, the category of models can be promoted to a 2-category . This is the 2-category of monoidal categories, strict monoidal functors, and monoidal natural transformations.
We can accomplish the same thing on the monad side: a -enriched monad is called a 2-monad, and gives rise to the “free monoidal category” 2-monad on [7]. To apply this 2-monad to we first form the free model on by taking a left Kan extension as above, and then evaluate this model at the generating object. In the same way that the (underlying set of the) free monoid on a set consists of all finite strings of elements of , is the monoidal category consisting of all finite tensor products of objects of and all morphisms built from those of by composition and tensoring together with associators and unitors obeying the necessary coherence laws. Morphisms of these algebras are strict monoidal functors, while 2-morphisms are natural transformation. We thus have a 2-equivalence between and the 2-category of algebras of .
In this way, 2-theories generalize equipping set-like objects with operations obeying equations to equipping category-like objects with operations obeying equations up to transformations that obey equations of their own. In particular, this gives us a way to present graphical calculi such as string diagrams – the language of monoidal categories.
Example 7**.**
Enrichment generalizes operations in more ways than by weakening equations to coherent isomorphisms. We can also use 2-theories to describe other structures that make sense inside 2-categories, such as adjunctions.
For example, we may define a cartesian category to be one equipped with right adjoints to the diagonal and the unique functor . These right adjoints are a functor describing binary products in and a functor picking out the terminal object in . We can capture the fact that they are right adjoints by providing them with units and counits and imposing the triangle equations. There is thus a 2-theory whose models in are categories with chosen finite products. More generally a model of this 2-theory in any 2-category with finite products is called a cartesian object in .
[TABLE]
[TABLE]
[TABLE]
[TABLE]
Again we write the equations as commutative diagrams, but this time commutative triangles of 2-morphisms in . These are the triangle equations that force to be the right adjoint of and to be the right adjoint of . A model of is a category with chosen binary products and a chosen terminal object; morphisms in are functors that strictly preserve this extra structure.
The subtle interplay between the cartesian structure of and the cartesian structure of the object is an example of the “microcosm principle”: objects with a given structure are most generally defined in a context that has the same sort of structure. As seen in the previous example, we can also define pseudomonoids in any 2-category with finite products, but this is excess to requirements: one can in fact define them more generally in any monoidal 2-category [10].
In fact, if we let arities be finite categories, we would have -theories of categories with finite limits and colimits. However, for the purposes of this paper we are using only natural number arities. This suffices for constructing and also , the theory of categories with chosen binary coproducts and a chosen initial object. Various other kinds of categories—distributive categories, rig categories, etc.—can also be expressed using -theories with natural number arities. This gives a systematic formalization of these categories, internalizes them to new contexts, and allows for the generation of 2-monads that describe them.
5 Change of Base
We now have the tools to formulate the main idea: a choice of enrichment for Lawvere theories corresponds to a choice of computation, and changing enrichments corresponds to a change of computation. We propose a general framework in which one can translate between different forms of computation: small-step, big-step, full-step operational semantics, and denotational semantics.
5.1 General results
Suppose that and are enriching categories of the sort we are considering: cartesian closed categories equipped with chosen finite coproducts of the terminal object. Suppose preserves finite products. This induces a change of base functor [8] which takes any -category and produces a -category with the same objects but with
[TABLE]
for all objects . Composition in is defined by
[TABLE]
The identity-assigning morphisms are given by
[TABLE]
Moreover, if is a -functor, there is a -functor that on objects equals and on hom-objects equals . If is a -natural transformation and , then we define
[TABLE]
Thus, change of base actually gives a 2-functor from the 2-category of -categories, -functors and -natural transformations to the corresponding 2-category for .
In fact, the change of base operation gives a 2-functor
[TABLE]
where is the 2-category of cartesian closed categories equipped with chosen finite coproducts of the terminal object, finite product preserving functors preserving these chosen finite coproducts, and natural transformations. In particular, if has not just finite coproducts of the terminal object but all coproducts of this object, there is a map of adjunctions
[TABLE]
Each set is mapped to the -indexed coproduct of the terminal object in and conversely each object of is represented in by the hom-set from the unit to . The latter induces the “underlying category” change of base, which forgets the enrichment. The former induces the “free -enrichment” change of base, whereby ordinary -categories are converted to -categories, denoted . These form an adjunction, because 2-functors preserve adjunctions.
We now study how change of base affects theories and their models. We start by asking when a functor induces a change of base that “preserves enriched theories”. That is, given a -theory
[TABLE]
we want to determine conditions for the base-changed functor
[TABLE]
to induce a -theory in a canonical way. Recall that we require and to be cartesian closed, equipped with chosen finite coproducts of their terminal objects. We thus expect the following conditions to be sufficient: should be cartesian, and it should preserve the chosen finite coproducts of the terminal object:
[TABLE]
for all .
Given these conditions there is a -functor, in fact an isomorphism
[TABLE]
On objects this maps to , and on hom-objects it is simply the identity from
[TABLE]
to
[TABLE]
where we use Lemma 13 in these computations.
Using this we obtain a composite -functor
[TABLE]
This is the identity on objects and preserves finite -products because each of the factors has these properties. It is thus a -theory.
Theorem 8**.**
Let , be cartesian closed categories with chosen finite coproducts of their terminal objects, and let be a cartesian functor that preserves these chosen coproducts. Then preserves enriched theories: that is, for every -theory , the -functor
[TABLE]
is a -theory. Moreover, preserves models: for every model of , the -functor is a model of .
Proof.
We have shown the first part. For the second, by Lemma 17 it suffices to assume that preserves finite -powers and check that preserves -powers. We leave this as an exercise to the reader. ∎
Hence, any cartesian functor that preserves chosen finite coproducts of the terminal object gives a change of base. It thus provides for a method of translating formal languages between various “modes of operation”. Moreover, this reasoning generalizes to multisorted -theories, enriched theories which have multiple sorts: given any , the monoidal subcategory is also an eleutheric system of arities, so Lucyshyn-Wright’s monadicity theorem still applies.
5.2 Examples
Now let us look at some examples. The most important changes of base are the left adjoints in this diagram from Sec. 1:
[TABLE]
The first step describes the translation from small-step to big-step operational semantics. As already mentioned, we need to use simplicial sets rather than graphs; let us now say more about why.
A first attempt might use directed multigraphs. Such graphs have directed edges and allow multiple edges between any pair of vertices. The category of directed multigraphs is where is the category with two objects and and two morphisms . The “free category” functor gives for every graph a category as follows:
[TABLE]
The morphisms in are called edge paths. Just as an edge describes a single rewrite in small-step operational sematics, an edge path describes a sequence of rewrites in big-step operational semantics. The edge paths with serve as identity morphisms.
Unfortunately, does not preserve products, so it is not a valid base change. To see this, let be , the graph with two vertices and one edge. The product looks like this:
[TABLE]
Thus the free category has just one non-identity morphism. On the other hand has five non-identity morphisms, shown here:
[TABLE]
where we write for identity morphisms and for the edge path consisting of the single edge . Note that the triangles in this diagram commute. In terms of rewriting, the category only allows the rewrite to occur simultaneously in both factors, while allows it to occur independently in either factor, in a commuting way.
To solve this problem one, might try to use reflexive graphs. Such graphs have directed edges and allows multiple edges between any pair of vertices; further, each vertex is equipped with a distinguished identity edge from to itself. The category of reflexive graphs is , where is the category with two objects and , two morphisms , and a morphism obeying . There is a free category functor , which is like the free category functor for except that we identify an edge path with the same path having omitted when is an identity edge. Thus, the identity edges of a reflexive graph become identity morphisms in .
The advantage of reflexive graphs is that they allow rewrites in a product to occur independently in either factor. For example, let be the reflexive graph with two vertices and one non-identity edge, (where we do not draw identity edges). The product has five non-identity edges:
[TABLE]
Thus, the free category has two noncommuting triangles. On the other hand, is the product of the category with a single non-identity morphism with itself, so it is this category:
[TABLE]
with two commuting triangles. Thus again fails to preserve products, though in some sense it comes closer. Simply put, while allows rewrites to be done independently in either factor, these rewrites fail to commute.
To solve this problem we shall consider as a full subcategory of the category of simplicial sets, . To do this, we treat a reflexive graph as a simplicial set with only degenerate simplices for . There is a left adjoint , usually called realization, and this functor preserves products [17, Prop. B.0.15]. For example, if we treat above as a simplicial set and take the product in , this contains triangles that force the triangles in to commute. Thus, realization provides a useful base change to translate from small-step operational semantics to big-step operational semantics.
The other functors in our chain of left adjoints are simpler. The “free poset” functor maps any category to the poset whose elements are objects of , with iff contains a morphism from to . This is a valid change of base—i.e., it preserves finite products—because the product of posets is defined in the same way as the product of categories. If we apply this change of base to a model of a -enriched theory, we obtain a model of a -enriched theory that says for any pair of terms the presence or absence of a rewrite sequence from one to the other, without distinguishing between different sequences. We call this full-step operational semantics.
Finally, we can pass to the purely abstract realm where all computation is already complete. For this we take the left adjoint to the functor sending any set to the discrete poset on that set. The functor collapses each connected component of the poset to a point; this too preserves finite products. If we apply this change of base to a model of a -enriched theory, we obtain a model of a -enriched theory that extracts its denotational semantics by identifying all terms related by rewrites. If the rewrites are terminating and confluent, we can choose a representative term for each equivalence class: the unique term that admits no nontrivial rewrites.
6 The Category of All Models
In addition to base change, there are two other natural and useful ways to go between models of enriched theories. Suppose is any cartesian closed category with chosen finite coproducts of the terminal object. Let be the category of models of a -theory in a -category with finite -products, as in Defn. 4. A morphism of -theories induces a change of theory functor between the respective categories of models
[TABLE]
defined as pre-composition with . Similarly, a -product-preserving -functor induces a change of context functor
[TABLE]
defined as post-composition with .
These translations, as well as change of base, can all be packed up nicely using the Grothendieck construction: given any functor , there is a category that encapsulates all of the categories in the image of , defined as follows:
[TABLE]
Moreover there is a functor given as follows:
[TABLE]
For more details see [8, 16]. We noted in Section 4 that and can be promoted to -categories when is complete and cocomplete: this and further conditions imply that we can use the enriched Grothendieck construction [6], but we focus on the ordinary Grothendieck construction for simplicity.
First, this construction lets us bring together all models of all different -theories in all different contexts into one category. All the -theories are objects of , as in Defn. 3. We can also create a category of all “-contexts”.
Definition 9**.**
Let , the category of -contexts be the category for which an object is a -category with finite -products and a morphism is a functor that preserves finite -products.
There is a functor
[TABLE]
that sends any object to and any morphism to . The functoriality of summarizes the contravariant change-of-theory and the covariant change-of-context above. Applying the Grothedieck construction we obtain a category . Technically an object of is a triple , but more intuitively it is a model of any -theory in any -context . Similarly, a morphism
[TABLE]
in consists of:
- •
a morphism of -theories ,
- •
a -functor that preserves finite -products, and
- •
a -natural transformation .
This is a natural way to map between different models of different theories in different contexts.
We can go further by creating a category that even contains all choices of enriching categories :
Definition 10**.**
Let be the category for which an object is a cartesian closed category with chosen finite coproducts of the terminal object, and a morphism is a cartesian functor preserving the chosen finite coproducts of the initial object.
There is a functor
[TABLE]
that maps any object to and any morphism to a functor
[TABLE]
that has the following effect:
- •
maps any object to the object .
- •
maps any morphism to the morphism .
Thus, we can use the Grothendieck construction once more to pack up all choices of enrichment into one big category:
Theorem 11**.**
There is a category in which:
- •
An object is a choice of cartesian closed category with chosen finite coproducts of the terminal object, a -theory , a -category with finite -products, and a model .
- •
A morphism is a cartesian functor preserving the chosen finite coproducts of the terminal object and a morphism in .
This category allows us to formally treat morphisms between objects of “different kinds”, something we often use informally, for example when speaking of a map from a set to a ring, or a group to a topological group. There are many unexplored questions about the large, heterogeneous categories which arise from the Grothendieck construction, regarding what unusual structure may be gained, such as limits and colimits with objects of different types, or identifying “processes” in which the kinds of objects change in an essential way. However, for our purposes we need only recognize that enriched Lawvere theories can be assimilated into one category, providing a single place in which to study change of base, change of theory, and change of context.
7 Applications
In computer science literature, enriched algebraic theories have primarily been studied in the context of “computational effects” [14]. Stay and Meredith have proposed that enriched Lawvere theories can be utilized for the design of programming languages [32]. To circumvent the question of variable binding, there is another approach which instead uses an enriched theory as a “compiler” which translates a language with binding to one without. This idea comes from the subject of combinatory logic.
7.1 The -combinator calculus
The -calculus is an elegant formal language which is the foundation of functional computation, the model of intuitionistic logic, and the internal logic of cartesian closed categories: this is the Curry–Howard–Lambek correspondence [4].
Terms are constructed recursively by variables, application, and abstraction, and the basic rewrite is beta reduction, which substitutes the applied term for the bound variable:
[TABLE]
Despite the apparent simplicity, there are complications regarding substitution. Consider the term : if this is applied to the variable , then — but this is not intended, because the in is just a placeholder, it is “bound” by whatever will be plugged in, while the being substituted is “free”, meaning it can refer to some other value or function in the program. Hence whenever a free variable is to be substituted for a bound variable, we need to rename the bound variable to prevent “variable capture” (e.g. ).
This problem was noticed early in the history of mathematical foundations, even before the -calculus, and so Moses Schönfinkel invented combinatory logic [29], a basic form of logic without the red tape of variable binding, hence without functions in the usual sense. The -calculus is the “variable-free” representation of the -calculus; -terms are translated via “abstraction elimination” into strings of combinators and applications. This is a technique for programming languages to minimize the subtleties of variables.
The insight of Stay and Meredith [31] is that even though enriched Lawvere theories have no variables, they can be used to study some programming languages through abstraction elimination. When representing such a language as a -theory, vertices—i.e., 0-simplices—in the simplicial set serve as closed terms. More generally, vertices in serve as terms with free variables. Rewrite rules going between such terms are edges—i.e., 1-simplices—in .
To illustrate this, here is the theory of the -calculus:
[TABLE]
[TABLE]
These rewrites are implicitly universally quantified; i.e., they apply to arbitrary subterms without any variable binding involved, by using the cartesian structure of the category. They are edges with vertices as follows:
[TABLE]
Here denote the unitors and the symmetry of the product.
These abstract rules are evaluated on concrete terms by “plugging in” via precomposition. For example:
[TABLE]
A model of this theory is a -functor that preserves finite -products. This gives a simplicial set . The images of the nullary operations under are distinguished vertices of , because preserves the terminal object, which “points out” vertices. The image of the binary operation gives for every pair of vertices a vertex in which stands for their application. In this way all possible terms built from , , and application give vertices in . Similarly, rewrites going between these terms give edges in . Thus, gives a map of simplicial sets
[TABLE]
that maps the “syntactic” graph of all closed terms and rewrites to the “semantic” graph: each rewrite between terms in the theory is sent to a rewrite between the images of these terms in the model.
The fact that is not just a function but a map of simplicial sets means that pairs of edges in are sent to edges in . This gives the full complexity of the theory: given a large term (program), there are many different ways it can be computed—and some take fewer steps than others:
[TABLE]
More generally, the image is a simplicial set whose vertices are -terms with free variables and whose edges are -tuples of rewrites between such terms. This is because the enriched functor gives maps of simplicial sets
[TABLE]
As the -ary operations and rewrites thereof are built up from application and the three rewrites, everything works the same way as in the case .
This process is intuitive, but how do we actually define the model, as a functor, to pick out a specific graph? There are many models of , but in particular we care about the canonical free model, which means that is simply the graph of all closed terms and rewrites in the -calculus. This utilizes the enriched adjunction of Thm. 5:
[TABLE]
Then the canonical model of closed terms and rewrites is simply the free model on the empty graph, , i.e. the -functor . Hence for us, the syntax and semantics of the combinator calculus are unified in the model
[TABLE]
Here we reap the benefits of the abstract construction: the graph represents the small-step operational semantics of the -calculus:
[TABLE]
We can now consider the base changes in Sec. 5.2, to translate between several important kinds of computation for the -calculus. Given the above description of as enriched in , we can apply the “free category” realization functor to the hom-objects, turning these reflexive graphs into categories.
Here we enjoy the fact that this functor indeed preserves products, which is essential for considering tuples of programs running in parallel: for example if we designate , then the fact that ensures that the execution of an -term program and an -term program simultaneously (but independently) is the same as executing one, then the other.
Thus translates the theory of from “small-step” to “big-step” operational semantics:
is the theory of the calculus, but now with hom-categories whose morphisms represent finite sequences of rewrite edges in the original theory.
We can continue these base-changes to “full-step” and denotational semantics, by applying the “free poset” and “free set” (connected components) functors to the hom-objects of this theory. This process demonstrates the idea of having a “spectrum” of detail with which to analyze the semantics of a programming language, or general algebraic theory.
For example, consider the following computation:
[TABLE]
The solid arrows are the one-step rewrites of the initial -theory; applying gives the dotted composites, and asserts that all composites between any two objects are equal. Finally, collapses the whole diagram to . This is a simple demonstration of the basic stages of computation: small-step, big-step, full-step, and denotational semantics.
7.2 Change of theory
We can equip term calculi with reduction contexts, which determine when rewrites are valid, thus giving the language a certain evaluation strategy. For example, the “weak head normal form” is given by only allowing rewrites on the left-hand side of the term.
We can do this for by adding a reduction context marker as a unary operation, and a structural congruence rule which pushes the marker to the left-hand side of an application; lastly we modify the rewrite rules to be valid only when the marker is present:
[TABLE]
[TABLE]
The -calculus is thereby equipped with “lazy evaluation”, an essential paradigm in modern programming. This represents a broad potential application of equipping theories with computational methods, such as evaluation strategies.
Moreover, these equipments can be added or removed as needed: using change-of-theory, we can utilize a “free reduction” -functor :
[TABLE]
This essentially interprets ordinary as having every subterm be a reduction context. This is a -functor because its hom component consists of graph-homomorphisms
[TABLE]
which simply send each application to its postcomposition with , and each rewrite to its “marked” correspondent.
So, by precomposition this induces the change of theory on categories of models:
[TABLE]
for all semantic categories , which forgets the reduction contexts.
Similarly, there is a -functor which forgets reduction contexts, by sending and ; this latter is the only way that the marked reductions can be mapped coherently to the unmarked. However, this means that does not give the desired change-of-theory of “freely adjoining contexts”, because collapsing to the identity eliminates the significance of the marker.
This illustrates a key aspect of categorical universal algebra: because change-of-theory is given by precomposition and is thus contravariant, properties (equations) and structure (operations) can only be removed. This is a necessary limitation, at least in the present setup, but there are ways to make do. These abstract theories are not floating in isolation but are implemented in code: one can simply use a “maximal theory” with all pertinent structure, then selectively forget as needed.
8 Conclusion
We have shown how enriched Lawvere theories provide a framework for unifying the structure and behavior of formal languages. Enriching theories in category-like structures reifies operational semantics by incorporating rewrites between terms, and appropriate functors between enriching categories induce change-of-base functors between categories of enriched theories and models—this simplified condition is obtained by using only natural number arities. This idea is motivated by an example sequence of such functors, which provide a spectrum of detail in which to study the rewriting properties of a theory.
Change of base, along with change of theory and change of context, can be used to create a single category , which consists of all models of all enriched Lawvere theories in all contexts. We have demonstrated these concepts with the theory of combinatory logic, , describing a change of base from small-step operational semantics to big-step to full-step to denotational semantics.
Finally, we suggest that there are many interesting change-of-base functors, by considering an endofunctor on the category of labelled transition systems, which quotients by the bisimulation relation and is indeed a change of base.
Appendix A Natural Number Arities
In this appendix we prove the lemmas required for Theorem 5 and our study of base change in Section 5. Throughout we assume is cartesian closed with chosen -fold coproducts of its terminal object.
We begin with a study of , the full subcategory of on the objects . First we must resolve a potential ambiguity. On the one hand, for any object of we can form the exponential . On the other hand, we can take the product of copies of , which we call . Luckily these are the same, or at least naturally isomorphic:
Lemma 12**.**
The functors and are naturally isomorphic.
Proof.
If , then
[TABLE]
Each of these isomorphisms is natural in and , so by the Yoneda lemma . ∎
We can now understand coproducts, products and exponentials in :
Lemma 13**.**
If is any cartesian closed category with chosen coproducts of the initial object then is cartesian closed, with finite coproducts. The unique initial object of is . The binary coproducts in are unique, given by
[TABLE]
The unique terminal object of is , and the binary products are unique, given by
[TABLE]
Exponentials in are also unique, given by
[TABLE]
Proof.
In we know that is an initial object and is a terminal object, by definition. Since the subcategory is skeletal is the unique initial object and is the unique terminal object in . Similarly, in we have defined to be a coproduct of and , so in it is the unique such, and we can unambiguously write
[TABLE]
Products distribute over coproducts in any cartesian closed category, so in we have
[TABLE]
where in the second step we use the distributive law twice. It follows that has finite products, and since this subcategory is skeletal they are unique, given by
[TABLE]
Finally, by Lemma 12 we have
[TABLE]
It follows that has exponentials, and since this subcategory is skeletal they are unique, given by
[TABLE]
We warn the reader that may not have elements. It does in and of course , but not in , where . In fact, whenever has finite hom-sets it is equivalent to for some . The reason is that is an internal Boolean algebra in , so its set of elements must be some Boolean algebra in . A further argument due to Garner and Trimble shows that is completely characterized, up to equivalence, by this Boolean algebra, and any Boolean algebra can occur [3]. If this Boolean algebra is finite it must be isomorphic to for some . In this case, is equivalent to .
Now suppose is a -category. The question arises whether the power of an object by must also be the -product of copies of . The answer is yes:
Lemma 14**.**
Let be a -category and . Then the power exists if and only if the -fold -product exists, in which case they are isomorphic.
Proof.
In Section 3 we saw that an object is an -fold -product of copies of precisely when it is equipped with a universal cone
[TABLE]
Similarly, is an -power of when it is equipped with a universal cone
[TABLE]
The universality properties have the same form, and by Lemma 12 the functors and are naturally isomorphic. Thus, given either sort of universal cone we get the other, so an object is an -fold product of copies of if and only if it is the -power of . ∎
Lemma 15**.**
Suppose is a -category such that every object is the -fold -product of some object . Then a -functor preserves finite -products if and only if it preserves powers by all objects of .
Proof.
Define a “finite -power” to be a finite -product of copies of the same object. The -functor preserves finite -powers if and only if it maps any universal cone
[TABLE]
in to a universal cone in . Similarly, preserves powers by all objects of if and only if it maps any universal cone
[TABLE]
in to a universal cone in . Two kinds of universality are involved here, but since they have the same form, and since Lemma 12 says the functors and are naturally isomorphic, it follows that preserves finite -powers if and only if it preserves powers by all objects of .
It thus suffices to show that preserves finite -products if and only if it preserves finite -powers. This follows from the assumption that every object is the -fold -product of some object . ∎
Lemma 16**.**
Let be cartesian closed with chosen finite coproducts of the terminal object and let be a -category. These conditions for a -functor are equivalent:
is a -theory, 2. 2.
preserves finite -products, 3. 3.
preserves powers by objects of .
Proof.
Conditions 1 and 2 are equivalent by definition. Since , finite -products in are the same as finite -coproducts in , which are the same as finite coproducts in . Since every object in is a finite coproduct of copies of , Lemma 15 implies that conditions 2 and 3 are equivalent. ∎
Lemma 17**.**
Given a -theory and a -functor , the following conditions are equivalent:
- •
is a model of ,
- •
preserves finite -products,
- •
preserves powers by objects of .
Proof.
Conditions 1 and 2 are equivalent by definition. Since is the identity on objects and preserves -products each object of is of the form where . Thus, Lemma 15 implies that conditions 2 and 3 are equivalent. ∎
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1]
- 2[2] J. Adámek & J. Rosický (1994): Locally Presentable and Accessible Categories . London Mathematical Society Lecture Note Series 189, Cambridge University Press, Cambridge, 10.1017/CBO 9780511600579 . · doi ↗
- 3[3] J. C. Baez (2019): Can 1+1 have more than two points? The n 𝑛 n -Category Café. Available at https://golem.ph.utexas.edu/category/2019/04/can_11_have_more_than_two_poin.html .
- 4[4] J. C. Baez & M. Stay (2011): Physics, topology, logic and computation: a Rosetta Stone . In B. Coecke, editor: New Structures for Physics , Springer, Berlin, pp. 95–172, 10.1007/978-3-642-12821-9 . Available at https://arxiv.org/abs/0903.0340 . · doi ↗
- 5[5] M. Barr & C. Wells (1984): Toposes, Triples and Theories . Grundlehren der mathematischen Wissenschaften 278, Springer, Berlin, 10.4204/EPTCS . Available at https://www.math.mcgill.ca/barr/papers/ttt.pdf . · doi ↗
- 6[6] J. Beardsley & L. Z. Wong (2019): The enriched Grothendieck construction . Advances in Mathematics 344, pp. 234 – 261, 10.1016/j.aim.2018.12.009 . Available at https://arxiv.org/abs/1804.03829 . · doi ↗
- 7[7] R. Blackwell, G. M. Kelly & A. J. Power (1989): Two-dimensional monad theory . Journal of Pure and Applied Algebra 59(1), pp. 1–41, 10.1016/0022-4049(89)90160-6 . · doi ↗
- 8[8] F. Borceux (1994): Handbook of Categorical Algebra . Cambridge University Press, Cambridge, 10.1112/BLMS/28.4.440 . · doi ↗
