Categorical Term Rewriting: Monads and Modularity

Christoph Lüth

Doctor of Philosophy University of Edinburgh

Abstract

Term rewriting systems are widely used throughout computer science as they provide an abstract model of computation while retaining a comparatively simple syntax and semantics. In order to reason within large term rewriting systems, structuring operations are used to build large term rewriting systems from smaller ones. Of particular interest is whether key properties are modular, that is, if the components of a structured term rewriting system satisfy a property, then does the term rewriting system as a whole? A body of literature addresses this problem, but most of the results and proofs depend on strong syntactic conditions and do not easily generalize. Although many specific modularity results are known, a coherent framework which explains the underlying principles behind these results is lacking.

This thesis posits that part of the problem is the usual, concrete and syntaxoriented semantics of term rewriting systems, and that a semantics is needed which on the one hand elides unnecessary syntactic details but on the other hand still possesses enough expressive power to model the key concepts arising from the term structure, such as substitutions, layers, redexes etc. Drawing on the concepts of category theory, such a semantics is proposed, based on the concept of a monad, generalising the very elegant treatment of equational presentations in category theory. The theoretical basis of this work is the theory of enriched monads.

It is shown how structuring operations are modelled on the level of monads, and that the semantics is compositional (it preserves the structuring operations). Modularity results can now be obtained directly at the level of combining monads without recourse to the syntax at all. As an application and demonstration of the usefulness of this approach, two modularity results for the disjoint union of two term rewriting systems are proven, the modularity of confluence (Toyama’s theorem) and the modularity of strong normalization for a particular class of term rewriting systems (non-collapsing term rewriting systems). The proofs in the categorical setting provide a mild generalisation of these results.

Acknowledgements

First of all, I would like to thank my supervisors, Don Sannella and Stefan Kahrs. Together and between themselves, their support, patience and countless suggestions, corrections and ideas kept my research and this thesis on an even keel. For a while, they were ably supported by Andrzej Tarlecki during his stay at Edinburgh.

A very special thanks is due to Neil Ghani, not only for keeping me company, but also for his enthusiasm in this work, which sometimes surpassed my own, which certainly was a great motivation.

Postgraduate study at the LFCS in Edinburgh has been very stimulating, due to the Theory of Computation course, the various “clubs” and talks, and the people present, and I thank everyone involved; I would like to single out Barry Jay for introducing me to category theory in general, and to categorical term rewriting in particular and John Power for his talks about monads and enriched category theory.

Thank you to everybody who read this thesis and suggested improvements, first of all Stefan and Don, but further Neil, Paul-André Melliès, and Burkhart Wolff.

I benefited from a DAAD grant, and Paul Taylor’s macro package.

On a more personal note, I would like to thank everybody who made my stay in Edinburgh more pleasant: Simon McPartlin (also for introducing me to the delights of Easter Road), Roope Kaivola, Ally Hume, David Aspinall, all those who played football with me (real or otherwise), my landlords Helmut and Catherine Petzsch, and Martin Köhler (the London correspondent); and also everybody at Bremen for their company, in particular Burkhart, Sabine, and Stefan. My parents have always supported me, for which I am particularly grateful.

Declaration

I declare that this thesis was composed by myself and that the work contained therein is my own, except where explicitly stated otherwise in the text. The main results of chapter 4 have appeared in [50], and the main results of chapter 5 have appeared in [51].

(Christoph Lüth)

Table of Contents

Chapter 1 Introduction and Preliminaries 5 1.1 Scope, Approach and Structure of This Thesis . . . . . . . . . . . 6 1.2 How to read this Thesis . . . . . . . . . . . . . . . . . . . . . . . 10 1.3 Basic Notions of Category Theory . . . . . . . . . . . . . . . . . . 12

1.3.1 Foundations . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.3.2 Categories, Functors and Natural Transformations . . . . . 13 1.3.3 Representability, Limits and Colimits . . . . . . . . . . . . 14 1.3.4 Particular Limits and Categories . . . . . . . . . . . . . . 15 1.3.5 Colimits from Coproducts and Coequalizers . . . . . . . . 16 1.3.6 Monads . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.3.7 Kan Extensions . . . . . . . . . . . . . . . . . . . . . . . . 18 1.3.8 Locally Finitely Presentable Categories . . . . . . . . . . . 19 1.3.9 Weakly Filtered Colimits . . . . . . . . . . . . . . . . . . . 20

1.4 Basic Notions of Enriched Category Theory . . . . . . . . . . . . 27 1.4.1 Symmetric monoidal closed categories . . . . . . . . . . . . 28 1.4.2 V-categories . . . . . . . . . . . . . . . . . . . . . . . . . . 29 1.4.3 2-categories . . . . . . . . . . . . . . . . . . . . . . . . . . 30 1.4.4 V is a V-category . . . . . . . . . . . . . . . . . . . . . . . 32 1.4.5 Enriched Functor Categories . . . . . . . . . . . . . . . . . 33 1.4.6 Limits and Colimits for V-categories . . . . . . . . . . . . 33 1.4.7 Tensors and Cotensors . . . . . . . . . . . . . . . . . . . . 34 1.4.8 Change of base . . . . . . . . . . . . . . . . . . . . . . . . 34

1.5 Particular Categories . . . . . . . . . . . . . . . . . . . . . . . . . 35 1.5.1 Graphs and the Category Grph . . . . . . . . . . . . . . . 36 1.5.2 Binary Relations and the category Rel . . . . . . . . . . . 40 1.5.3 Small Categories and the Category Cat . . . . . . . . . . 43

1.6 Basic Principles of Term Rewriting . . . . . . . . . . . . . . . . . 45 1.6.1 Abstract Reduction Systems and Term Rewriting Systems 45 1.6.2 Commutativity, Confluence and Strong Normalization … 46

1.7 Words and Languages . . . . . . . . . . . . . . . . . . . . . . . . 47

Chapter 2 Compositional Semantics for Term Rewriting Systems 49

2.1 Signatures and Equational Presentations . . . . . . . . . . . . . . 52 2.1.1 Signatures and Algebras . . . . . . . . . . . . . . . . . . . 52 2.1.2 The Term Algebra . . . . . . . . . . . . . . . . . . . . . . 53 2.1.3 The Internal Language of a Monad . . . . . . . . . . . . . 57 2.1.4 Equational Presentations . . . . . . . . . . . . . . . . . . . 60

2.2 Basic Principles of Enriched Monad Theory . . . . . . . . . . . . 62 2.3 Enriched Monads as a Semantics for Term Rewriting Systems . . 65

2.3.1 Sets with Structure . . . . . . . . . . . . . . . . . . . . . . 66 2.3.2 Arities, Contexts and Rewrite Rules . . . . . . . . . . . . . 68 2.3.3 The Term Reduction Algebra and the Monad T_{Θ} . . . . . 70 2.3.4 The Internal Language of a Monad . . . . . . . . . . . . . 74 2.3.5 Comparison with the Literature Definition 1.6.1 . . . . . . 76

2.4 Properties of the Monad T_{Θ} . . . . . . . . . . . . . . . . . . . . . 77 2.4.1 Finitariness . . . . . . . . . . . . . . . . . . . . . . . . . . 78 2.4.2 Regular Monads . . . . . . . . . . . . . . . . . . . . . . . . 78 2.4.3 Expanding and Collapsing Monads . . . . . . . . . . . . . 81 2.4.4 Quasi-Non-Expanding Term Rewriting Systems and Monads 85

2.5 Compositionality . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 2.6 Conclusions and Discussion . . . . . . . . . . . . . . . . . . . . . 89

Chapter 3 Structuring operations 92

3.1 The Coproduct of Two Strongly Finitary Monads . . . . . . . . . 95 3.1.1 The Coproduct Monad as a Pointwise Colimit . . . . . . . 96 3.1.2 Unit, Multiplication and the Monad Laws . . . . . . . . . 99 3.1.3 The Universal Property . . . . . . . . . . . . . . . . . . . 101 3.1.4 Consequences of the Enrichment . . . . . . . . . . . . . . . 108 3.1.5 An Alternative Construction . . . . . . . . . . . . . . . . . 109

3.2 Deciding the Equality . . . . . . . . . . . . . . . . . . . . . . . . . 109 3.2.1 The Coequalizer . . . . . . . . . . . . . . . . . . . . . . . . 110 3.2.2 Normal Forms for Objects . . . . . . . . . . . . . . . . . . 111 3.2.3 Normal Forms for Morphisms . . . . . . . . . . . . . . . . 114

3.3 The Coequalizer of Strongly Finitary Monads . . . . . . . . . . . 119 3.4 Summary and Conclusion . . . . . . . . . . . . . . . . . . . . . . 121 Chapter 4 Modularity of Confluence 123

4.1 A Semantic Definition of Confluence . . . . . . . . . . . . . . . . 124 4.1.1 Confluent Monads . . . . . . . . . . . . . . . . . . . . . . 124 4.1.2 Confluent Term Rewriting Systems . . . . . . . . . . . . . 126 4.1.3 Equivalence of the Two Notions . . . . . . . . . . . . . . . 129

4.2 Preservation of Confluence for Coequalizers . . . . . . . . . . . . . 131 4.2.1 The Diamond Property . . . . . . . . . . . . . . . . . . . . 131 4.2.2 Witnesses . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

4.3 Toyama’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . 135 4.4 Modularity of Confluence for Quasi-Non-Expanding Monads … 137

4.4.1 Completable and Co-Initial Subcategories . . . . . . . . . 138 4.4.2 Finding a Completable Co-initial Subcategory . . . . . . . 140

4.5 Summary and Conclusion . . . . . . . . . . . . . . . . . . . . . . 142

Chapter 5 Modularity of Strong Normalization 146

5.1 A Semantic Definition of Strong Normalization . . . . . . . . . . . 148 5.1.1 Termination for Categories and Monads . . . . . . . . . . 148 5.1.2 Equivalence of Notions . . . . . . . . . . . . . . . . . . . . 149

5.2 Strong Normalization for the Coproduct Monad . . . . . . . . . . 151 5.3 Modularity of Strong Normalization for Non-Collapsing Monads . 155

5.3.1 Modularity of Termination for Non-Collapsing TRS’s … 156 5.3.2 The Monad Proof . . . . . . . . . . . . . . . . . . . . . . . 157

5.4 Summary and Conclusion . . . . . . . . . . . . . . . . . . . . . . 161

Chapter 6 Conclusions and Further Work 163

6.1 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 6.1.1 Early Work . . . . . . . . . . . . . . . . . . . . . . . . . . 164 6.1.2 Later and Contemporary Work . . . . . . . . . . . . . . . 165 6.1.3 Other Work . . . . . . . . . . . . . . . . . . . . . . . . . . 166 6.1.4 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

6.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 6.2.1 Generalizing the Term Rewriting . . . . . . . . . . . . . . 168 6.2.2 Improving the Theory . . . . . . . . . . . . . . . . . . . . 170 6.2.3 Generalizing the Structuring Operations . . . . . . . . . . 171

6.3 Concluding Remarks . . . . . . . . . . . . . . . . . . . . . . . . . 171

Appendix A Using Monads to Model Named Reductions 172 A.1 A Term Construction for Named Reductions . . . . . . . . . . . . 173 A.1.1 Prereductions . . . . . . . . . . . . . . . . . . . . . . . . . 174 A.1.2 Named Reductions . . . . . . . . . . . . . . . . . . . . . . 179 A.1.3 The Monad T_{Θ} . . . . . . . . . . . . . . . . . . . . . . . . 183 A.1.4 Named vs. Unnamed Reductions . . . . . . . . . . . . . . . 186

A.2 Properties of the Monad T_{Θ} . . . . . . . . . . . . . . . . . . . . . 186 A.3 Compositionality . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 A.4 Summary and Conclusion . . . . . . . . . . . . . . . . . . . . . . 195

Bibliography 196

Chapter 1

Introduction and Preliminaries

A term rewriting system is a set of directed equations like the following:

K.x.y → x
S.x.y.z → x.z.(y.z)

This system is in fact one of the first, and still one of the most prominent term rewriting systems, called Combinatory Logic. Ever since its invention by Schönfinkel and Curry in the 1920’s, followed by Church’s λ-calculus shortly after, term rewriting has been a useful tool in mathematics and (later) computer science. Its use has spread to such diverse areas as

• foundational and meta-mathematical issues (which it was first invented for);

• automated theorem proving;

• implementation of programming languages.

Term rewriting is attractive because it provides an abstract model of computation while retaining a relatively simple syntax and semantics. In fact, this very simplicity also limits the usefulness of term rewriting. Realistic programs or specifications tend to be very large. In order to keep them manageable, they are built from smaller ones using structuring operations; the simplest example of a structuring operation being the disjoint union. The interaction between these structuring operations and term rewriting is not at all clear, precisely because the semantics is too simple to express how rewrites in the component systems can be put together to rewrites in the combined system. In particular, we are interested in whether properties of term rewriting systems such as confluence or termination are preserved by these operations — whether they are modular.

The aim of this thesis is to investigate modularity problems in a coherent framework. The means to this end will be a compositional semantics for term rewriting systems. By this, we mean the translation of a term rewriting system into a mathematical structure such that we can combine these mathematical structures and obtain the same semantics as if we had combined the corresponding term rewriting systems.

We will demonstrate the viability of our approach by proving some rather strong modularity results known from the literature within our framework.

1.1 Scope, Approach and Structure

Why Semantics?

By giving a semantics to a term rewriting system, we want to reason about its “meaning” independent of its particular syntactic presentation. For example, consider the way we give a semantics to equational presentations in universal algebra. A set of equations like

x.(y.z) = (x.y).z
I(x).x = 1
1.x = x

is on first sight just a collection of syntax, but we can interpret it in the language of sets and functions (by picking a particular set X to interpret all terms, an element a ∈ X to interpret the constant 1, a unary function b : X → X to interpret I and a binary function c : X × X → X to interpret .). When doing so, the above equations entail the equation x.1 = x (i.e. whatever set and functions we chose, this equation will hold); we say that the equation x.1 = x is in the equational theory of the three equations above. When reasoning about structures described by the three equations (in other words, groups) we want to refer to whole class of equations derivable from those given. This is meant by independence from syntactic presentations. In the same vein, when reasoning about a term rewriting system, we want to refer to all rewrites derivable in it — its so-called theory.

Semantics for Term Rewriting Systems

Traditionally, the theory of a term rewriting system is defined rather syntactically, by using concepts such as substitution and contexts (the latter can be thought of as terms with a “hole” given by a special unary symbol □): given a rule l → r, a substitution σ of the variables in l and r, and a context C[], the left hand side of the rule with the variables substituted by σ and put into context rewrites to the right hand side of the rule with the variables substituted by σ and put into context: C[σ(l)] → C[σ(r)]. We say C[σ(l)] reduces to C[σ(r)] in one step.

Hence the domain of discourse of the semantics are relations– we talk about sets of objects, here terms, with a binary relation, the reduction relation generated by the rewrite rules, on them. These binary relations are called abstract reduction systems (ARS’s). While some results can be proven directly at the level of abstract reduction systems, more sophisticated ones and especially those concerning modularity, cannot, since abstract reduction systems lack the expressivity to deal with key concepts such as substitutions, layers, redexes, orthogonality etc. so results relying on these concepts have to be proven directly at the level of the syntax. This approach does not offer any compositionality: we cannot combine rewrites from different systems, just the syntax. This way of defining the semantics of combined systems is referred to as flattening: for a structured term rewriting system, we take the component systems and calculate one large term rewriting system equivalent to the structured system (the flattened system). Hence, when considering whether a certain property is preserved under the disjoint union of two term rewriting systems, we consider rewrites built over the disjoint union of the two signatures and rewrite rules, rather than the combination of rewrites from both systems, and a rather complicated syntactic machinery is set up to extract the rewrites in the component systems (one needs to introduce the notions of layers, special subterms, different colours etc.), for which the assumptions can be applied.

The example of universal algebra above has actually not been chosen accidentally. As universal algebra deals with terms and equations on them, a careful analysis and generalization of the methods of universal algebra will allow us to develop a similar treatment for term rewriting systems; after all, rewrite rules are just directed equations.

Universal Algebra

In universal algebra, there are two ways of giving a semantics to a set of equations (an equational presentation):

• One can define an equational calculus on the terms. Essentially, close the equations under substitution, application of operations, transitivity, reflexivity and symmetry; so e.g. if s = t has been derived as valid, t = s is valid as well. Then the semantics of the equational presentation (called the equational theory) is the set of all derivable equations.

• One can interpret the operations in the language of sets and functions as above. In particular, one defines an algebra as a set together with a function for each operation symbol. This way we can evaluate a term in the algebra once we fix the values of the variables in the term; and we say an algebra admits an equation s = t if the evaluation of both s and t is the same for all possible values of the variables in s and t. Then the semantics of the equational presentation is the set of those equations admitted by all algebras that admit the equations in the presentation.

In universal algebra, both these semantics coincide. For term rewriting, only the first kind of semantics has been developed at all.

Generalizing Universal Algebra

Where above equations are interpreted in the structure of sets and operations on them, we will interpret term rewriting systems in the language of “sets with structure”. Our first task will be to define what exactly we mean by “sets with structure”, and it turns out that there is more than one possibility, all of which make perfect sense.

The semantic framework we choose is category theory, because as opposed to set theory (or formal logic, type theory etc.), category theory concentrates on the abstract properties of structures as exhibited by the maps between them rather than their concrete representation. In particular, there is a construction modelling the “closure”, for example of a set of operations under composition — and this is precisely the term algebra, the process of building terms from a given set of operations and deriving a theory from a given set of rewrite rules. Moreover, for this construct there is an abstract notion of an “algebra”, and hence this construct subsumes both approaches mentioned above.

This construct is called a monad, and a particular class of instances of it (monads on the base category of all sets) is well-known to model universal algebra. Our semantics will generalize this treatment of universal algebra along the lines laid down by a particular branch of category theory called enriched category theory. The key for the development of an appropriate semantics will be the proper generalization of the underlying concepts from sets to “sets with structure”. This will form the core of chapter 2.

Structuring Operations

The above is not eo ipso an example of a compositional semantics, because it is not clear how to semantically represent the structuring operations. In fact, structuring operations have mostly been considered in the context of algebraic specifications, where the techniques of universal algebra are used to specify programs. Whereas in term rewriting and universal algebra, attention was mostly restricted to the (disjoint and non-disjoint) union, the theory of algebraic specifications has arrived at the characterisation of structuring operations by another concept from category theory, called a colimit (which contains unions as a special case), and this allows a very precise characterisation of compositionality: a mapping from syntactic presentations to semantic presentations preserving these colimits. Structuring operations, and how they operate on the semantic presentations (i.e. the monads) will be the scope of chapter 3.

Properties of Term Rewriting Systems

Not every term rewriting system is useful. A system like

F (x) → F (x)

that reduces a term just to itself is clearly useless and uninteresting. The system of Combinatory Logic given above is interesting, because it can represent every computable function.

A taxonomy of term rewriting systems is based on the properties they enjoy. Two of the most important properties are

• confluence, and

• strong normalization.

Confluence means that whenever there are two reductions from the same term to two different terms, we can find another two reductions from these terms both yielding the same term. This means that whichever of the two branching reductions we choose, we arrive at the same result in the end as long as we keep going. Strong normalization means that there is no infinite sequence of one-step reductions— every reduction eventually terminates.

A system which is confluent as well as terminating is complete. A complete term rewriting system gives a decision procedure for the equational theory the term rewriting system describes: given two terms s, t, we reduce them until we cannot reduce any further; the resulting terms s′, t′ are called the normal form of s and t. By confluence, a term only has one normal form, and two terms are equivalent in the equational theory iff their normal forms are equal.

In the context of structured systems, the question which structuring operation preserves which property, summed up under the headline of modularity, has been attracting a lot of attention — not at least from this thesis, where we will discuss the modularity of confluence in chapter 4 and the modularity of strong normalization in chapter 5. In these two chapters, we will prove known results from term rewriting within our new semantic framework, demonstrating the viability of our approach by simplifying the existing proofs and making them amenable to generalization, as indicated by the slight generalizations of the original results we obtain by re-proving them in our framework.

Category Theory in This Thesis

One of the aims of this thesis is to demonstrate that enriched category theory is a useful basis for the theory of computation, and that the results from enriched category theory can be put to good use in computer science.^{1} Hence, this thesis has been written such that the results (if not every detail of the proofs) should be understandable to a reader with a passing acquaintance with category theory (like the first six chapters of [52]), and no knowledge of enriched category theory at all, if the reader is willing to suspend belief at some points and accept some of the categorical results as they are presented, or on the basis of some informal reasoning. I would be delighted if this thesis would entice readers to learn more about category theory, or indeed enriched category theory.

The reader with a good categorical background, however, may find that at some points the simplification of categorical matters borders on the imprecise and erroneous; so where I felt an explanation of the finer points of the category theory was needed, this has been put into separate, dedicated sections. These

few sections are marked with a symbol !_{Categories} in order to warn the unaware; their content is not essential to an understanding of what follows (under the caveats mentioned above).

1.2 How to read this Thesis

Thesis Outline

In summary, this thesis is structured as follows:

• Chapter 1: The rest of this chapter introduces the notions and concepts of category theory as used in this thesis. Besides the standard concepts found in any textbook on the matter, we will draw upon a less commonly known area called enriched category theory. While only briefly recalling the basic notions of category theory, more in order to define the notation than as a self-contained introduction, the subsequent introduction to enriched category theory and 2-categories is slightly more detailed, although the reader is unlikely to obtain an in-depth understanding without consulting the literature. We will further present an extensive review of the categories we will use to model reductions — namely, graphs, relations, preorders and categories. The chapter closes with a few lemmas about the algebra of words over an alphabet L, which will be needed in chapter 3.

1There is a deep reason for this: “ordinary” category theory deals essentially with the equational theory of structures (and maps between them); but computer science is more about computation than equality, and the additional structure offered by the enrichment exactly fits this need.

• Chapter 2: The theory construction.

We review how monads on the category of sets model signatures and equational presentations, followed by a review of the theory of enriched monads. We then show how a specialization of the general theory of enriched monads to a particular category of sets-with-structure yields a semantics for term rewriting systems. We close the chapter by showing compositionality of the semantics.

• Chapter 3: Structuring Operations.

Structuring operations are colimits, constructed from coproducts and coequalizers. We consider the coproduct of two monads, and its construction, and briefly touch on the coequalizer of two monads.

• Chapter 4: Modularity of Confluence.

We show the modularity of confluence for the coproduct of two monads (Toyama’s theorem).

• Chapter 5: Modularity of Strong Normalization. We define a subclass of strongly normalizing monads called strongly normalizing under non-deterministic collapses, and show the modularity of strong normalization for this subclass.

• Chapter 6: Conclusion and Further Work. We review the literature on categorical term rewriting, relate our work to the literature, and indicate possible directions of further research.

Chapter Dependencies 4

[figure: 1.3 to 1.7; .; .; .; .; .; .; .; .; .; .; .; .; .; .; 2; 3]
\overline{}5

where sections 1.3 to 1.7 are intended as a stock of references to be consulted when the results are used, rather than as a straight read.

1.3 Basic Notions of Category Theory

This section recalls some of the basic notions of category theory. It is neither self-contained nor intended to be, and the reader is advised that a knowledge of the basic concepts of category theory (as mentioned in this section) will be necessary to understand what follows (and is unlikely to be gained from this section alone). The standard introductory text is of course [52], but there are a plethora of introductory texts of varying quality.

Readers with a working knowledge of category theory, and a passing knowledge of enriched category theory will be able to skip this section completely, and refer back to it later on whenever they encounter references to those results in this section which are unknown to them. Readers with a working knowledge of category theory, but no knowledge of enriched category theory are invited to consult §1.4; but as mentioned above, this thesis should be readable even with no knowledge of enriched category theory.

We will use the notation of [52] (so readers familiar with the material of the first six chapters of this book will be able to skip this section), except for the following:

• the hom-sets of a category C are written C(x, y) rather than hom(x, y);

• the category of functors from C to D is written [C, D] rather than D^{C}.

1.3.1 Foundations

Following the approach of [52, Chapter I.6, pg. 21ff.], we shall in the following assume the existence of a universe U within which all sets defined in the following live. The universe is a set with certain properties (e.g. it contains the set ω of all finite ordinals and is closed under powersets), the elements of which are called small sets. We are not at all concerned with foundational issues here, and shall just note that if a set or category gets “too large” for a particular universe, there is always a larger one which it lives in, and we shall mention these “size conditions” in passing whenever we encounter them.

1.3.2 Categories, Functors and Natural Transformations

A category C is given by

• a set of objects |C|,

• and a set of morphisms Mor_{C}, with two functions δ_{s}, δ_{t} : Mor_{C} → |C| assigning a source and target to every morphism; or alternatively, a family {C(x, y)}_{x,y∈|C|} of hom-sets (we will use both notions interchangeably);

• for every object x ∈ |C|, an identity 1_{x} : x → x on x;

• and a composition function, mapping two morphisms f : x → y, g : y → z, to their composition g.f : x → z.^{2}

such that the composition is associative and the identity its left and right unit. A category C is called discrete if all its morphisms are identities. The dual C^{op} of the category C has the same objects, but reversed arrows: C^{op}(y, x) =^{def} C(x, y).

We will use calligraphic letters such as C, X as variables for categories and bold letters (as in Set) for specific categories. We will further write x ∈ C as an abbreviation for x ∈ |C|, and f : x → y in C as an abbreviation for x, y ∈ |C|, f ∈ C(x, y).

A morphism m : X → Y in C is monic (or a monomorphism) iff for all Z ∈ C and f_{1}, f_{2} : Y → Z m.f_{1} = m.f_{2} implies f_{1} = f_{2}. A morphism e : X → Y in C is epi (or an epimorphism) iff for all U ∈ C and g_{1}, g_{2} : U → X, g_{1}.e = g_{2}.e implies g_{1} = g_{2}. In Set, the category of small sets and functions between them (see below), a function is epi iff it is surjective, and monic iff it is injective. Finally, a morphism f : X → Y is an isomorphism iff it is invertible, i.e. if there is a morphism f^{−1} : Y → X such that f^{−1}.f = 1_{X} and f.f^{−1} = 1_{Y}. In this case, we also say that the objects X and Y are isomorphic.

A functor F : X → Y is given by an object function F_{Obj} : |X | → |Y| and a morphism function F : Mor_{X} → Mor_{Y}, which preserves the source and target of the morphisms, and identities and composition (i.e. 1_{F Obj(X)} = F 1_{X} and F g.F f = F (g.f)). By slight abuse of notation, we usually write F for the object function as well. A functor F : X → Y can also be given as a family of functions F_{x,y} : X (x, y) → Y(F x, F y) for all x, y ∈ X. Then F is full if all F_{x,y} are surjective, and faithful if all F_{x,y} are injective.

2Note that although the author is a computer scientist, composition is written in applicative (not diagrammatic) order.

A natural transformation α : F ⇒ G : X → Y between two functors F and G is given by a family {α_{x} : F X → GX}_{x∈X} of arrows in Y, indexed by the objects in X, such that for all f : X → Y (this is called the naturality of α in X):

α_{Y}.F f = Gf.α_{X}  (1.1)

Given two categories X , Y the functor category [X , Y] between them has functors as objects and natural transformations as morphisms, with the obvious composition and the identity transformation id_{F}, given by the identity 1_{F X} for every object X ∈ X.^{3} The constant functor ΔY : X → Y for Y ∈ Y maps every object to Y, and every morphism to the identity on Y. For a morphism f : Y → Z, the natural transformation Δf : ΔY ⇒ ΔZ is f for every object X ∈ X. This gives the diagonal functor Δ(−) : Y → [X , Y].

1.3.3 Representability, Limits and Colimits

A particularly important category is the category Set which has all small sets as objects, and the functions between them as morphisms. Then for a small category C there are the two hom-functors for every object X ∈ C: C(X, −) : C → Set, which on the objects maps Y to C(X, Y), and maps a morphism f : Y → Z to the postcomposition f.(−) : C(X, Y) → C(X, Z), mapping g : X → Y to g.f : X → Z; and C(−, X) : C^{op} → Set, which maps Y to C(Y, X) and f to (−).f, the precomposition with f.

A functor F : C → Set is representable if there is an object X ∈ C such that for all Y ∈ C, there is an isomorphism C(X, Y) ≅ F Y which is natural in Y, also written as C(X, −) ≅ F.

Given a functor F : J → C, a cone to the base F from vertex X is given by an object X ∈ C, and a natural transformation ν : ΔX ⇒ F; and a cone over F to the vertex X is given by an object X ∈ C, and a natural transformation ν : F ⇒ ΔX. F has a limit if the functor [J , C](Δ−, F) : C^{op} → Set is representable; the representing object X is called the limit of F, and c : ΔX ⇒ F is the limiting cone. Dually, if the functor [J , C](F, Δ−) : C → Set is representable, F has a colimit given by a colimiting object X and a colimiting cone c : F ⇒ ΔX (sometimes written as a tuple (c, X)). The limiting object for a functor F is sometimes denoted as lim F, and the colimiting object as colim F.

3The functor category is the first instance of the “size conditions” mentioned above: the functor category [X , Y] may be larger than X and Y; see [52, pg. 41]. To be more precise: a category C is small if both the set of its objects and of its morphisms are small sets, then [X , Y] is only small if X is small.

We say a functor H : C → D preserves limits if the image Hc : Hlim F ⇒ HF for the limit (c, lim F) of a functor F : J → C is a limiting cone for HF.

Given a functor F : X → Y, if the functor Y(F (−), Y) : X^{op} → Set is representable for every object Y ∈ Y, F has a right adjoint, which is a functor G : Y → X, mapping Y to the representing object GY; and we have an isomorphism ϕ : Y(F −, Y) ≅ X^{op}(GY, −) ≅ X (−, GY) which maps a function f : Y → Z to the function ϕ(f) : X (GZ, GY). We say F and G form an adjunction F −| G : X → Y (or are adjoint). The existence of an adjunction can be characterised in at least three other ways: given two functors F : X → Y, G : Y → X, they are adjoint if

• there is a bijection Y(F X, Y) ≅ X (X, GY) which is natural in X ∈ X and Y ∈ Y;

• there are two natural transformations η : 1_{X} → GF (the unit of the adjunction) and ε : F G ⇒ 1_{Y} (the counit of the adjunction), satisfying the triangle laws: Gε_{Y}.η_{GY} = 1_{GY} and ε_{F X}.F η_{X} = 1_{F X} (for X ∈ X , Y ∈ Y).

• there is, for every object X ∈ X, a morphism η_{X} : X → GF X which is universal from X to G: for every other object Y ∈ Y, and every other morphism f : X → GY, there is a unique morphism !_{f} : F X → Y in X such that f = G(!_{f}).η_{X}.

All of these formulations are equivalent [52, pg. 81]. An important fact about adjoints is that left adjoints preserve colimits and right adjoint preserve limits [52, pg. 114].

Limits can also be considered as adjoints: a category C has a limit for all functors F : J → C (it is complete) iff the diagonal functor Δ : C → [J , C] has a right adjoint (and dually, it has colimits (is cocomplete) iff the diagonal functor has a left adjoint).

1.3.4 Particular Limits and Categories

The empty category ∅ has no objects and no morphisms. For any category C, there is exactly one functor ! : ∅ → C. The limit (colimit) of this functor (if it exists) is called the terminal (initial) object in C.

The one-object category 1 is has one object |1| = {∗} and a single morphism, the identity on it. A functor F : 1 → C specifies exactly one object of C.

More generally, for any natural number n ∈ ℕ there is the discrete category n which has the ordinal n as objects; then a functor F : n → C specifies n objects in C, and its limit (colimit) is the n-ary (cartesian) product (coproduct). If these exist for any n, we say C has all finite products (coproducts). This can be extended to any set v, and if v is infinite, we say C has infinite products (coproducts). Coproducts are often written in the form X_{1} + X_{2} + ⋯ + X_{n} or even ∐_{i=1}^{n} X_{i} (with the similar notation X_{1} × X_{2} × … X_{n} = ∏_{i=1}^{n} X_{i}) for products).

The one-arrow category → has two objects with two identity morphisms and one non-identity morphism between them; the two-arrow category ⇉ has two objects with two identities and two non-identity morphisms between them. Then a functor F :⇉→ C specifies two morphisms f, g : X → Y in C with the same source and target (called a fork) and the limit (colimit) of F is called the equalizer (coequalizer) of f and g.

(Co-)Products and (co-)equalizers are important because if they exist all other (co-) limits exists, as will be shown in the following section.

1.3.5 Colimits from Coproducts and Coequalizers

One of the most useful theorems about limits says that any limit can actually be constructed from products and equalizers. Since we will need the dual of this construction later on, it is worth spelling out in some detail in the following proposition, which is the dual of Theorem 1 in [52, pg. 109].

Proposition 1.3.1 Given two categories J and C, if C has all coproducts indexed by the set of objects and morphisms of J, and coequalizers for all pairs of arrows, then C has a colimit for every functor F : J → C.

Proof. Form the coproduct ∐_{u:j→k} F j, indexed by all arrows u : j → k in J.

\begin{aligned}& F j \\ ∐_{u:j→k} F j & [figure: f; g] & ι_{u}_{\underline{}} & ∐_{i} F i & q^{}Q & ^{ι_{j}  ^{\overline{}}} \\ F j & ^{ι_{u} } & \overline{F u ^{}} & F k & ^{ι_{k} } \end{aligned}  (1.2)

Now for every arrow u : j → k, we define two maps from F j into the coproduct ∐_{i∈J} F i: f_{u} is the injection ι_{j} of F j into the coproduct, and g_{u} is F u followed by the injection ι_{k}. This gives two unique arrows f, g, such that in diagram 1.2, f makes the upper triangle and g the lower square commute for all arrows u : j → k. Then the coequalizer Q is the colimit of F. The colimiting cone μ : F ⇒ ΔQ is given by μ_{j} =^{def} ι_{j}.q; which is a cone since q coequalizes f and g, and it is the universal cone, since any other cone ν : F → ΔP necessarily coequalizes f and g, and hence there is a unique morphism ! : Q → P. □

1.3.6 Monads

A monad T = ⟨T, η, μ⟩ on a category C is given by a functor T : C → C (the action of the monad), and two natural transformations η : 1_{C} ⇒ T and μ : T T ⇒ T (the unit and the multiplication), such that the monad laws hold: μ.η_{T} = 1_{C}, μ.T η = 1_{C} and μ.T μ = μ.μ_{T} (these state that η and μ form a monoid, with η a unit to μ on the left and right, and μ associative).

An algebra for a monad T is given by an object X ∈ C and a morphism α : T X → X (called the structure map of the algebra), such that α.μ_{X} = α.T α, and α.η_{X} = 1_{X}. A map between two algebras α : T X → X and β : T Y → Y is a morphism f : X → Y s.t. f.α = β.T f.

Every adjunction F −| G : X → Y with unit η and counit υ gives rise to a monad T =^{def} ⟨GF, η, Gυ_{F} ⟩; on the other hand, every monad T gives rise to a variety of adjunctions, in particular between C and the Kleisli-category C_{T} (see [52, Section VI.5]), and C and the Eilenberg-Moore-category C^{T}, given by the algebras and morphisms between them. The left adjoint is F^{T} : C → C^{T}, mapping X to the free algebra μ_{X} : T T X → T X, whereas the right adjoint U^{T} : C^{T} → C maps α : T X → X to the object X.

If a functor G : D → C has a left adjoint F : C → D, and D is isomorphic to the Eilenberg-Moore category of the resulting monad, we say that G is monadic, or even that D is monadic over C if G is understood. This means that D can be generated from C by a set of operations plus equations on them; examples are the category of groups, Grp which is monadic over Set, or the category of small categories Cat which is monadic over Grph. A non-example is Cat, which is not monadic over Set.

The Category of Monads on C

Given two monads T_{1} = ⟨T_{1}, η_{1}, μ_{1}⟩, T_{2} = ⟨T_{2}, η_{2}, μ_{2}⟩, a monad morphism α : T_{1} → T_{2} is given by a natural transformation α : T_{1} ⇒ T_{2} such that α commutes with the unit and multiplication of the two monads as in 1.3 and 1.4, where (∗) commutes by naturality of α.

\begin{matrix}[figure: T_{1}X; X; η_{1,X}; T_{2}X; α_{X}; η_{2,X}] & [figure: T_{1}^{2}X; μ_{1,X}; T_{1}X; T_{1}T_{2}X; T_{1}α_{X}; (∗); T_{2}T_{1}X; α_{1,T_{1}X}; T_{2}^{2}X; μ_{2,X}; T_{2}α_{X}; α_{T_{2}X}; T_{2}X; α_{X}] \\ (1.3) & (1.4) \end{matrix}

The category Mon(C) of monads on C has monads on C as objects and monad morphisms between them as morphisms.^{4}

A particular monad is the identity monad on C , Id_{C} =^{def} ⟨1_{C}, id_{1_{C}}, id_{1_{C}}⟩ which has the identity on C as its action, and the identity transformations as both unit and multiplication. By equation 1.3, it is the initial object in Mon(C).

1.3.7 Kan Extensions

Kan extensions can be thought of as a canonical way of extending the domain of a functor. Given a functor K : M → C and a category A, the precomposition with K defines a functor (−).K : [C, A] → [M, A], which takes every functor F : C → A to F K : M → A. The adjoints of (−).K, if they exist, are the Kan extensions. Thus Kan extensions come in two variants, left and right. More explicitly, given functors K : M → C and T : M → A, the left Kan extension of T along K is given by a functor Lan_{K}T : C → A and a natural transformation ε : T ⇒ Lan_{K}T.K which is universal, i.e. for any other functor S : C → A and natural transformation α : T ⇒ SK, there is a unique natural transformation σ : Lan_{K}T ⇒ S such that α = σK.ε. The right Kan extension is given similarly by the right adjoint (see [52, Chapter X] for details).

If C is cocomplete, the left Kan extension can be constructed as a pointwise colimit [52, Chapter X.5]. For K : M → C and T : M → A, the value of the left Kan extension at c ∈ C is given by

4Of course, this is not a category unless some size restrictions are placed on C, i.e. C being small. If C is not small, Mon(C) will be a large category. We have to be careful not to treat Mon(C) in turn as a category of the same size as C (in particular, Mon(Cat) is not an object of Cat), but apart from that we can treat Mon(C) as a normal category.

Lan_{K}T (c) = colim ([figure: (K ↓ c); P; M; T; A])  (1.5)

where (K ↓ c) is the so-called comma category [52, Chapter II.6] which has as objects morphisms f : Kx → c in C, and as morphisms commuting triangles

[figure: Kx; f; c; Ky; Ku; g]

and P is the projection functor, taking f : Kx → c to x and Ku as above to u.

A useful fact about Kan extensions is that extension to the left preserves colimits, and to the right limits respectively. Limits and colimits are given by the left and right adjoint of the diagonal functor Δ (see page 15 above). The composition of the diagonal functor Δ : A → [C, A] with the postcomposition (−).K : [C, A] → [M, A] yields a functor which for any a ∈ A gives the constant functor Δa : M → A, hence is equal to Δ : A → [M, A].

Then by diagram 1.6, colim .Lan_{K}(−) : [M, A] → A is a left adjoint to

[figure: A; \underline{colim}; ⊥; Δ; ⊥; \underline{lim}; [C, A]; \underline{Lan_{K}(−)}; ⊥; (−).K; ⊥; \underline{Ran_{K}(−)}; [M, A]]  (1.6)

Δ : A → [M, A] and thus maps any functor to its colimit: for any F : M → A,

colim Lan_{K}F ≅ colim F  (1.7)

1.3.8 Locally Finitely Presentable Categories

In the category Set, there are the finite sets and the finite ordinals; the generalisation of this concept leads to finitely presentable objects (see [1, Chapter 1] or [4] for a motivation of the following definitions).

A partially ordered set (I, ≤) is called directed if for any two objects j, k ∈ I there is an object l ∈ I such that j ≤ l, k ≤ l. A directed colimit is the colimit of a functor D : (I, ≤) → C where (I, ≤) is a directed poset considered as a category. An object k ∈ C is finitely presentable (or fp) if its hom-functor C(k, −) : C → Set preserves directed colimits. A category C is locally finitely presentable (also written as lfp) if its cocomplete, and there is a set A of finitely presentable objects such that every object is a directed colimit of objects from A. The subcategory of C given by the fp objects is written as C_{fp}. Intuitively, fp objects are “finite objects”, and a category is lfp if it can be generated from its finite objects.

Examples of finitely presentable objects are finite sets in Set, finite graphs in Grph, finite preorders in Pre, and categories with a finite set of objects and morphisms which are generated from a finite set of morphisms by closing under composition and quotienting with a finite number of equations on them in Cat. All of these categories (Set, Grph, Pre, Cat) are locally finitely presentable. A category which is not lfp is CPO, the category of complete partial orders and continuous functions. For more examples see [1, Chapter 1].

An equivalent characterization of lfp is via generators: a strong generator G of a category C is a small full subcategory J : G ↪ C such that f : X → Y is an isomorphism iff for all G ∈ G, C(G, f) : C(G, X) → C(G, Y) is an isomorphism. Then C is lfp iff C is cocomplete and has a strong generator [1, Theorem 1.11]. An example of this is the functor category [C, Set] for any small category C: by the Yoneda lemma the representable functors form a small set of generators in [C, Set], hence [C, Set] is lfp.

An equivalent concept to directed colimits are filtered colimits, which are often more convenient to use. A category J is filtered if

(i) for any two objects two objects i, j ∈ J, there is an object k ∈ J and morphisms f : i → k, g : j → k, and

(ii) for any two parallel arrows r, s : i → j, there is an arrow q : j → k such that q.r = q.s.

A filtered colimit is the colimit of a functor F : J → C with J filtered. A category C has all filtered colimits iff it it has all directed colimits [1, Theorem 1.5] (and hence a functor preserves filtered colimits iff it preserves directed colimits).

If we liken coequalizers to quotients and coproducts to the disjoint union, filtered or directed colimits can be thought of as a completeness property; this is reflected by the fact that a category has directed colimits iff it has colimits of chains [1, Corollary 1.7].

1.3.9 Weakly Filtered Colimits

Weakly filtered categories are a non-standard concept which is introduced here, because the canonical diagrams we will encounter will not be filtered, merely weakly filtered. A weakly filtered category lacks the second property of a filtered category:

Definition 1.3.2 (Weakly Filtered Categories and Colimits) A category J is weakly filtered if for every two objects i, j ∈ J, there is an object k ∈ J and morphisms f : i → k, g : j → k.

The colimit of a functor F : J → C is called weakly filtered if the category J is weakly filtered.

Not every weakly filtered category is filtered, since there can be parallel arrows r, s : i → j but there is no arrow q : j → k with q.r = q.s. Hence, weakly filtered colimits are a strictly weaker notion than filtered or directed colimits, but if a functor preserves coequalizers of parallel arrows and preserves filtered colimits, it will also preserve all weakly filtered colimits.

To show this lemma, we will first extend the weakly filtered category J to a filtered category. Then any weakly filtered functor can be made into a filtered one by its left Kan extension along the inclusion; and if we can show that the functor preserves this Kan extension if it preserves coequalizers, then by equation 1.7 it will preserve any weakly filtered diagram.

The filtered completion J_{0} of a weakly filtered category will have, for all objects j ∈ J an object \overline{ȷ} and a morphism from j to \overline{ȷ} which coequalizes all parallel arrows into j, thus satisfying the second condition for filtered categories. To have the resulting category still satisfy the first condition, we further need to add in exactly one morphism between \overline{ȷ} and \overline{k} iff there is at least one between j and k.

Definition 1.3.3 (The Filtered Completion) Given a weakly filtered category J, its filtered completion J_{0} is defined as the category with

• objects: \{j, \overline{ȷ} | j ∈ J \}

• morphisms:

f : i → j for f : i → j in J
ι_{i,j} : i → \overline{ȷ} for i, j ∈ J if there is f : i → j in J
κ_{i,j} : \overline{ı} → \overline{ȷ} if there is f : i → j in J

where for all f, g : i → j, \overline{f} = \overline{g}. Further, J_{0}(\overline{ı}, j) =^{def} ∅ for all i, j ∈ J.

Composition in J_{0} is defined as follows (for i, j, k ∈ J):

1. for f : i → j, g : j → k, g.f is given by composition in J;

2. for κ_{i,j} : \overline{ı} → \overline{ȷ}, κ_{j,k} : \overline{ȷ} → \overline{k}, κ_{j,k}.κ_{i,j} =^{def} κ_{i,k} (where κ_{i,k} is given by the

composition g.f of the morphisms f : i → j and g : j → k giving rise to κ_{i,j} and κ_{j,k});

3. for f : i → j, ι_{j,k} : j → \overline{k}, ι_{j,k}.f =^{def} ι_{i,k} (where ι_{i,k} is given by g.f : i → k in J);

4. for ι_{i,j} : i → \overline{ȷ}, κ_{j,k} : \overline{ȷ} → \overline{k}, κ_{j,k}.ι_{i,j} =^{def} ι_{i,k} (where ι_{i,k} is given by the

composition g.f of f : i → j, g : j → k giving rise to ι_{i,j} and κ_{j,k}).

The identities are 1_{j} and κ_{j,j} (given by 1_{j}).

Let \overline{J} be the full subcategory of J_{0} given by all objects \overline{ȷ} ∈ J_{0} for j ∈ J; this subcategory is ismorphic to J(J) (where J is the functor from page 42 below) taking a category to a preorder by identifying all arrows with the same source and target.

The functor I : J → J_{0} is the inclusion J ↪ J_{0}.

Lemma 1.3.4 If J is weakly filtered, then J_{0} is filtered.

Proof. First, we show that for all j, k ∈ J_{0} there is i ∈ J_{0}, p : j → i, q : k → i in J_{0}. We distinguish four cases: firstly, j, k ∈ J, then because J is weakly filtered, there is i ∈ J, and p : j → i, q : k → i in J and hence in J_{0}; secondly, if \overline{ȷ}, \overline{k} ∈ \overline{J}, then since J is weakly filtered, there is i ∈ J, and κ_{j,i} : \overline{ȷ} → \overline{ı}, κ_{k,i} : \overline{k} → \overline{ı} in J_{0}; thirdly, if j ∈ J , \overline{k} ∈ \overline{J}, then there is i ∈ J, and p : j → i, q : k → i in J, and hence \overline{ı} ∈ J_{0}, ι_{j,i} : j → \overline{ı}, κ_{k,i} : \overline{k} → \overline{ı}; and finally \overline{ȷ} ∈ J , k ∈ \overline{J}, which is symmetric to the third case.

It remains to show that for any two arrows r, s : i → j in J_{0}, there is an arrow q : j → k in J_{0} such that q.r = q.s. We have three cases: firstly, if i, j ∈ J, then q =^{def} ι_{j,j} with ι_{j,j}.r = ι_{j,j}.s = ι_{j,i}; secondly, if \overline{ı}, \overline{ȷ} ∈ \overline{J}, then r = s = κ_{i,j}, hence q =^{def} 1\overline{ȷ}; thirdly, if i ∈ J , \overline{ȷ} ∈ \overline{J}, then r = s = ι_{i,j}, hence q =^{def} 1\overline{ȷ}. A fourth case, \overline{ı} ∈ \overline{J} , j ∈ J, can be excluded by definition of J_{0}. □

We can now turn any weakly filtered functor F : J → C into a filtered functor by taking its Kan extension along I : J → J_{0}; by isomorphism 1.7, the colimit will remain the same. If a functor T : C → D preserves this Kan extension and filtered colimits, then it will preserve weakly filtered colimits. Under some mild additional assumptions, it turns out that in addition to preservation of filtered colimits, preservation of coequalizers is sufficient.

The following are the additional assumptions we need to make. They roughly say that the diagrams are finitely generated, and are formulated in quite a strong way such that they still hold for the diagrams we consider (in chapter 3), while making rather weak assumptions on the functor F in question for an easy proof. For example, the requirement below that the hom-sets be at most countably infinite could be dropped if we required the functor to preserve coequalizers of arbitrary sets of parallel morphisms, but since the diagrams in question have countably infinite hom-sets we considered the weaker assumption that the functor preserves coequalizers of pairs of parallel arrows.

Definition 1.3.5 ((Weakly) ω-Filtered Categories) A (weakly) filtered category J is called (weakly) ω-filtered, if

(i) for all j ∈ J, card(|(J ↓ j)|) = card({i | ∃f : i → j in J }) ≤ ℵ_{0} i.e. for any object j there are at most countably infinitely many objects from which there is a morphism into j

(ii) for all i, j ∈ J, card(J (i, j)) ≤ ℵ_{0}, i.e. all hom-sets are at most countably infinite.

Lemma 1.3.6 Given a weakly ω-filtered category J, a functor F : J → C where C is cocomplete, and a functor T : C → D which preserves coequalizers and filtered colimits, then T preserves the left Kan extension along I : J → J_{0}:

T Lan_{I}F ≅ Lan_{I}T F  (1.8)

Proof. Since C is cocomplete, the left Kan extension can be constructed pointwise by equation 1.5: hence, for j ∈ J_{0}, Lan_{I}F (j) is given as

Lan_{I}F (j) = colim ([figure: (I ↓ j); P; J; F; C])  (1.9)

We will now investigate how cones over F P look, and construct a colimiting one. We will then show the lemma by showing that T preserves this colimiting cone.

We first show that for all i, j ∈ J, there is an object S ∈ C and a morphism q : F j → S in C such that q is the coequalizer of all arrows F k : F i → F j for k : i → j in J, written

(S, q) = coeq ({F k : F i → F j | k : i → j in J })

and that T preserves this coequalizer. Since all hom-sets in J are at most countably infinite, we can enumerate the morphisms in J (i, j) as f_{1}, f_{2} …, f_{n}, . . .. If J(i, j) is empty, then S =^{def} F j and q =^{def} 1_{F j}. Otherwise, S and q are given as the colimit colim_{n<ω} S_{n} of the ω-chain (S_{n})_{n<ω} with ι_{n} : S_{n−1} → S_{n} defined as

S_{0} =^{def} F j  q_{0} =^{def} 1_{F j}
(S_{n+1}, ι_{n+1}) =^{def} coeq (q_{n}.F f_{n+1}, q_{n}.F f_{0}) q_{n+1} =^{def} ι_{n+1}.q_{n}

where we write (S, q) for the coequalizing object and morphism of the two arrows q_{n}.F f_{n+1} and q_{n}.F f_{0}. Then for all m < ω, i, j < m, q_{m}.F f_{i} = q_{m}.F f_{j}, hence the colimit (S, q) of the chain makes all the arrows equal. It remains to show this is the coequalizer of all morphisms in J (i, j), which is shown by the universal property: suppose there is an object X ∈ C and a morphism g : F j → X such that for all h_{1}, h_{2} : i → j in J, g.F h_{1} = g.F h_{2}, then we construct a unique morphism !_{g} : S → X such that g =!_{g}.q. The morphism !_{g} is given by a cone ν_{n} : S_{n} → X over the chain such that for all n < ω, ν_{n}.q_{n} = g. This cone is defined inductively as follows: ν_{0} =^{def} g, with ν_{0}.q_{0} = g; and ν_{n+1} is given by ν_{n} as follows: with g.F f_{n+1} = g.F f_{0}, we have ν_{n}.q_{n}.F f_{n+1} = ν_{n}.q_{n}.F f_{0}, and since (S_{n+1}, q_{n+1}) is the coequalizer of q_{n}.F f_{n+1} and q_{n}.F f_{0}, there is a unique ν_{n+1} such that ν_{n+1}.ι_{n+1} = ν_{n}. Then we have ν_{n+1}.q_{n+1} = ν_{n+1}.ι_{n+1}.q_{n} = ν_{n}.q_{n} = g, as required. Since T preserves filtered colimits, it will preserve the colimit of the chain, and since it further preserves coequalizers, it will preserve the coequalizer of all arrows:

T (coeq ({F k : F i → F j | k : i → j in J }))

≅ coeq ({T F k : T F i → T F j | k : i → j in J }) (1.10)

We now turn to the cone over F P. Formally, a cone ν : F P ⇒ Δx is given by morphisms ν_{f} : F P (f) → x in C, indexed by objects f of (I ↓ j), which are in turn morphisms f : i → j in J_{0} where i is in the image of the inclusion functor I and thus in J, such that for all morphism u : f → g (where g : k → j) in (I ↓ j), given by morphisms u : i → k in J such that g.u = f, ν_{g}.F P (u) = ν_{f}, which amounts to ν_{g}.F u = ν_{f}.

We first show that any cone ν : F P ⇒ Δx over F P is determined by a single morphism ν : F j → x in C which if j ∈ \overline{J} has to make all parallel arrows into j equal: i.e. for all f_{1}, f_{2} : i → j in J, ν.F f_{1} = ν.F f_{2}.

We consider two cases: j ∈ J, and \overline{ȷ} ∈ \overline{J}. For the first, the identity 1_{j} : Ij → j is an object of (I ↓ j), giving a morphism ν_{1_{j}} : j → x, and moreover it is terminal— for any other f : Ii → j, there is a unique morphism in (I ↓ j), given by f, into 1_{j} : Ij → j. Hence, any ν_{f} : F P (f) → x has to filter through ν_{1} : j → j: ν_{f} = ν_{1}.F P (f), which decodes as

[figure: F i; ν_{f}; x; F j; ν_{1}; F f]

hence ν_{1} determines the value of ν_{f} for all other f : i → j.

For the second case, an object (I ↓ \overline{ȷ}) is a morphism Ii → \overline{ȷ} in J_{0}, which is ι_{i,j}, given by some f : i → j in J. The identity 1 : j → j gives a weakly terminal object ι_{j,j}, because for any f : i → j, ι_{j,j}.f = ι_{i,j}; but this not unique, since there can be another g : i → j, which gives the same object in (I ↓ j) (namely, ι_{i,j}), but a different morphism in (I ↓ j) into ι_{j,j}, given by g: ι_{j,j}.g = ι_{i,j}. Now both f and g give rise to the same object ι_{i,j} in (I ↓ j) and hence the same morphism ν_{ι_{i,j}} : F i → x for the cone ν, which is also given by both f and g filtering through ν_{1}:

[figure: F i; ν_{ι_{i,j}}; x; F j; ν_{1}; F g; F f]

Hence if for all f_{1}, f_{2} : i → j, F f_{1}.ν_{1} = F f_{2}.ν_{1}, then ν_{1} : F j → x gives rise to a cone over F P.

It is now clear what a colimiting cone over F P is; namely, for j ∈ J, it is given by ν =^{def} 1_{F j}, and for j ∈ \overline{J}, ν is the coequalizer in C of the image F f, F g : F i → F j of parallel arrows f, g : i → j into j under F. This reflects the intuition behind the construction of J_{0} and the Kan extension: on the objects of J, nothing changes, but the additional objects of J_{0} get mapped to the coequalizing objects, making J_{0} filtered.

We are now going to construct a colimiting cone over F P, and show that T preserves this construction. For the first case, j ∈ J, this is rather trivial: with ν =^{def} 1_{F j}, T (ν) = 1_{T F j} because any functor preserves identities.

For the second case, let j ∈ \overline{J}. Since J is weakly ω-filtered, the objects of (I ↓ j) can be enumerated as a sequence j_{1}, j_{2}, …, j_{n}, . . .. We now define a chain (S_{i})_{i<ω} the colimit of which will be a colimiting cone over F P. As above, we write (S, q) = coeq (M) for the coequalizing object and morphism of a set M of

[figure: F j = S_{0}; ν; x; F j_{1}; F j; q_{1}; q_{0} ; = = = = = = = = = = = = =; S_{1}; σ_{1}; μ_{1}; F j_{2}; S_{2}; σ_{2}; μ_{2}; q_{2}; F j_{3}; S_{3}; σ_{3}; μ_{3}; q_{3}] ; (1.11)

morphisms with the same source and target:

(S_{0}, σ_{0}) =^{def} (F j, 1_{F j})
q_{0} =^{def} 1_{F j}
(S_{n+1}, σ_{n+1}) =^{def} coeq ({q_{n}.F f | f : j_{n} → j in J })
q_{n+1} =^{def} σ_{n+1}.q_{n}

(see also diagram 1.11). The colimit of this chain is also a colimit cone over F P:

colim F P ≅ colim_{n<ω} S_{n}

This is shown by its universal property: given any other cone over F P, which as shown above is given by a morphism ν : F j → x such that ν.F f = ν.F g for all f, g : i → j, there is a unique cone morphism !_{ν} : colim_{n<ω} S_{n} → x. This morphism is constructed by constructing a cone over the chain (S_{i})_{i<ω}, given by morphisms μ_{i} : S_{i} → x such that ν = μ_{n}.q_{n}, as follows:

• μ_{0} =^{def} ν, with ν = μ_{0}.1_{F j} = μ_{0}.q_{0};

• given μ_{n} : S_{n} → x, we have ν = μ_{n}.q_{n} and for any f, g : j_{n} → j, ν.F f = ν.F g. Hence μ_{n}.q_{n}.F f = μ_{n}.q_{n}.F g, so by the universal property of S_{n+1} there is μ_{n+1} : S_{n+1} → x s.t. μ_{n+1}.σ_{n} = μ_{n} (which makes μ_{i} a cone over the chain), and further

μ_{n+1}.q_{n+1} = μ_{n+1}.σ_{n+1}.q_{n} = μ_{n}.q_{n} = ν

as required (see also diagram 1.11).

It remains to show that T preserves the colimiting cone just constructed. Since T preserves filtered colimits, it in particular preserves colimits of ω-chains, hence

T colim_{n<ω} S_{n} ≅ colim_{n<ω} T S_{n}

Further, by equation 1.10, T preserves coequalizers of sets of morphisms, hence

T S_{n} = T (coeq ({q_{n}.F f | f : j_{n} → j in J }))
≅ coeq ({T q_{n}.T F f | f : j_{n} → j in J })

This describes the colimiting cone for (I ↓ j) \overline{P ^{}}J_{0} T F^{}D, which gives Lan_{I}T F. Hence, for all j ∈ J_{0}, T Lan_{I}F (j) ≅ Lan_{I}T F (j). □

Lemma 1.3.7 A functor T : C → D, where C is cocomplete, preserves weakly ω-filtered colimits if it preserves filtered colimits and coequalizers.

Proof. Let J be a weakly ω-filtered category and F : J → C, then we have

T (colim F) ≅ T colim Lan_{I}F by isomorphism 1.7
≅
colim T Lan_{I}F

since T preserves filtered colimits, and Lan_{I}F is filtered by lemma 1.3.4

≅ colim Lan_{I}T F by isomorphism 1.8
≅ colim T F  by isomorphism 1.7
□

We call a functor F finitary if it preserves filtered colimits, and strongly finitary if it preserves weakly ω-filtered colimits.^{5} A monad is called (strongly) finitary if its action is (strongly) finitary, and the category given by strongly finitary monads and all monad morphisms between them is written as Mon_{Fin}(C).

1.4 Basic Notions of Enriched Category Theory

The following is an introduction to those concepts and notions of enriched category theory which shall be needed later on. No proofs are given. The reader is referred to the standard text in the field [36] for an in-depth presentation of the theory, although some readers may find the concise precision of the text too demanding, and it covers far more material than is required here. [4, Chapter 6] gives a more detailed introduction to the area, covering all the concepts presented here, and is the recommended companion to this introduction. Finally, [46] contains a good motivation, and a very readable introduction to enriched category theory.

5A note on the terminology: since not all weakly filtered colimits are filtered, preservation of weakly filtered colimits is a stronger requirement than preservation of filtered colimits, hence we call those functors strongly finitary.

1.4.1 Symmetric monoidal closed categories

A monoidal category V = (V_{0}, ⊗, I, a, l, r) is given by

• a category V_{0} called the underlying category,

• a functor ⊗ : V_{0} × V_{0} → V_{0} called the multiplication,

• an object I ∈ V_{0} called the unit,

• for all x, y, z ∈ V_{0}, an isomorphism a_{x,y,z} : (x ⊗ y) ⊗ z → x ⊗ (y ⊗ z) called the associativity, which is natural in x, y and z,

• and for all x ∈ V_{0}, isomorphism l_{x} : I ⊗ x → x and r_{x} : x ⊗ I → x called left and right unit respectively, which are natural in x,

making diagrams 1.12 and 1.13 commute for all objects W, X, Y and Z. Dia-

[figure: ((W ⊗ X) ⊗ Y) ⊗ Z; a; (W ⊗ X) ⊗ (Y ⊗ Z); a; W ⊗ (X ⊗ (Y ⊗ Z)); (W ⊗ (X ⊗ Y)) ⊗ Z; a ⊗ 1_{Z}; a; W ⊗ ((X ⊗ Y) ⊗ Z); 1_{W} ⊗ a](1.12)

[figure: (X ⊗ I) ⊗ Y; a; X ⊗ (I ⊗ Y); X ⊗ Y; 1_{X} ⊗ l; r ⊗ 1_{Y}]  (1.13)

grams of isomorphisms such as these are called coherence axioms. They ensure that every diagram built out of the left and right unit, associativity and multiplication commutes (see [52, Chapter VII]). If the isomorphisms are all identities, the monoidal category V is called strict. In that case, we shall allow ourselves to omit the identities when denoting V, as we shall when these are canonical isomorphisms: for example, (Set, ×, {∗}) is the monoidal category of small sets with the cartesian product and the unit set (and the canonical isomorphisms), and (Set, +, ∅) is the monoidal category of small sets with the coproduct and the empty set. Other examples of monoidal categories include the category Grph of graphs (see §1.5.1 below), the category Cat of small categories (see §1.5.3 below), the category →, and more generally, ordered sets with finite intersections.

A monoidal category V is symmetric if there is natural isomorphism s_{x,y} : x ⊗ y → y ⊗ x, subject to certain other coherence axioms and the symmetry axiom s_{y,x}.s_{x,y} = 1_{x⊗y}.

A monoidal category V is closed if the functor − ⊗ X : V_{0} → V_{0} has a right adjoint [X, −] : V_{0} → V_{0} for every object X, with the counit ε_{X} : [X, Y]⊗X → Y called the evaluation at X.

If the multiplication is the cartesian product of the two objects, and the unit the terminal object, with the associativity and unit the canonical isomorphisms, then V is cartesian; and if it is closed, it is a cartesian closed category.

In the examples above, Set is cartesian closed, Grph is closed with respect to the “tensor product” of two graphs as defined below, but not with respect to the cartesian product, and Cat is closed with respect to both the cartesian and another monoidal product.

For a monoidal category V, a morphism f : I → X in V_{0} can be regarded as an element of X; under the mild assumption that V_{0} is locally small (i.e. all hom-sets are small) there is a functor V =^{def} V_{0}(I, −) : V_{0} → Set which gives the “underlying set of objects” for the objects of V. For example, for a graph G, V G is (isomorphic to) its set of vertices, and for a category C, V C is its set of objects.

1.4.2 V-categories

The monoidal structure is all one needs to do enriched category theory: we can now replace the set of morphisms between any two objects with an object from V_{0}, and obtain V-categories, V-functors, and V-natural transformations analogously.

If we want to explicitly distinguish categories as defined above from V-cate-gories we are just about to define and 2-categories later on, we will call them ordinary categories (and similarly, ordinary functors, natural transformations, adjunctions etc.)

Let V be a monoidal category. A V-category C is given by

• a set |C| of objects,

• for every two objects X, Y ∈ C, an object C(X, Y) ∈ V_{0}, called the homobject,

• for all X, Y, Z ∈ C, a morphism c_{X,Y,Z} : C(Y, Z) ⊗ C(X, Y) → C(X, Z) in V_{0} called the composition,

• and for all X ∈ C, a morphism i_{X} : I → C(X, X) in V_{0} called the identity on X,

such that the composition is associative and the identity a unit on the left and right.

Given two V-categories C and D, a V-functor F : C → D is given by • an object function F_{Obj} : |C| → |D|, and

• for any two objects X, Y ∈ C, a morphism in V_{0}

F_{X,Y} : C(X, Y) → D(F_{Obj}(X), F_{Obj}(Y))

which respect the composition and identity.

As a matter of convenience, we usual do not distinguish between F and F_{Obj}, with the tacit understanding that we mean F_{Obj}(X) in the previous notation when writing F (X) for an object X ∈ C.

Given two V-functors F, G : C → D, a V-natural transformation α : F ⇒ G is given by a family of morphisms {α_{X} : I → D(F X, GX)}_{X∈C} indexed by objects in C, which is natural in the sense that diagram 1.14 commutes for all X and Y.

[figure: C(X,Y)⊗I; G_{X,Y} ⊗α_{X}; D(GX,GY)⊗D(F X,GX); C(X,Y); r_{X,Y}^{−1}; D(F X,GY); c_{F X,GX,GY}; I⊗C(X,Y); α_{Y} ⊗F_{X,Y}; l_{X,Y}^{−1}; D(F Y,GY)⊗D(F X,F Y); c_{F X,F Y,GY}] (1.14)

We shall in the following assume that V is an arbitrary but fixed symmetric monoidal closed category. Also, functors between V-categories are always understood to be V-functors, and natural transformations between V-functors are always V-natural transformations.

1.4.3 2-categories

The category of all small V-categories, V-functors, and V-natural transformations between them has as much structure as Cat, the category of all small ordinary categories, so all constructions on ordinary categories which can be expressed in terms of functors and natural transformations in Cat are also possible on Vcategories. To make this precise, the concept of a 2-category will be introduced.

A 2-category is a category enriched over the category of all small categories with the cartesian product, the one-object-category 1 as unit and the canonical isomorphisms; a 2-functor is Cat-enriched functor, and so on. In more detail, a 2-category C has

• a set |C| of objects,

• for every two objects X, Y ∈ C, a hom-category C(X, Y); • for all X, Y, Z ∈ C, a bifunctor ∘_{X,Y,Z} : C(Y, Z) × C(X, Y) → C(X, Z);

• and for all X ∈ C, an object 1_{X} ∈ C(X, X) in the hom-category;

A 2-category has two kinds of composition: the composition within each homcategory, called vertical composition, and the composition given by the bifunctor ∘_{X,Y,Z}, called horizontal composition. The functoriality of ∘ means that it has to preserve the vertical composition; this is also called the interchange law. The objects of the hom-categories are also called the 1-cells of C, and the morphisms of the hom-categories the 2-cells .

By taking the objects |C| of C, and the objects |C(X, Y)| as hom-sets between X and Y, with the object function of ∘ as the composition, we obtain the underlying ordinary category C_{0} of C; and similarly, we obtain an underlying ordinary functor F_{0} for a 2-functor F.

The horizontal and vertical composition allows us to draw “pasting diagrams” [40, 66] to reason about the equality of 2-cells. Also, given a morphism f : X → Y and a 2-cell α ∈ C(Y, Z), we can compose α with f, written as f−∘α =^{def} 1_{f} ∘ α.^{6} As an example of this, here is the diagram defining 2-naturality: given two 2functors F, G : C → D, a 2-natural transformation ν : F ⇒ G is, for every object X ∈ C, a 1-cell ν_{X} ∈ D(F X, GX); then diagram 1.14 is a diagram of functors, which on the object level imply the usual naturality, and on the morphism level commutativity of diagram 1.15. Since in general V-natural transformations form

[figure: F X; F f; ⇓ F α; F g; F Y; GX; ν_{X}; Gf; ⇓ Gα; Gg; GY; ν_{Y}]  (1.15)

a V-object, there is also a notion of 2-cells between 2-natural transformations: a modification γ : ν → μ : F ⇒ G : C → D is given by a family of 2-cells {γ_{X}}_{X∈X} indexed by objects in C satisfying diagram 1.16.^{7}

6This is also sometimes referred to as tadpole composition, since this is what it is supposed to look like in a diagram. Incidentally, it is possible to define a 2-category in terms of this tadpole compositions: a set of objects, a set of morphisms between objects, and a set of 2-cells between morphisms, with an identity morphism for every object, an identity 2-cell for every morphism, a (horizontal) composition between the morphisms, and a tadpole composition “on the left” between any morphism f : Y → X and 2-cell α : g ⇒ h : Y → Z, and “on the right”

between any 2-cell α and morphism u : Z → U, which is subject to ten equations[82, pg.52].

[figure: F X; F f; F Y; GX; ν_{X}; ⇒^{γ_{X}}; μ_{X}; Gf; GY; ν_{Y}; ⇒^{γ_{Y}}; μ_{Y}]  (1.16)

2-categories are more than just another enriched category; they are the “natural” setting for constructions such as adjunctions [40] and monads [85], the whole theory of which can be entirely formulated in terms of 1-cells and 2-cells in a 2-category.^{8} Since small V-categories, V-functors and V-natural transformations between form a 2-category V-Cat, we can deduce how to define adjunctions and monads for V-categories as specializations of the more general case.

1.4.4 V is a V-category

The closed structure of V makes V itself a V-category: more precisely, if V_{0} is closed, we have a bijection

V_{0}(X ⊗ Y, Z) ≅ V_{0}(X, [Y, Z])

Let X =^{def} I, and recall the definition of V as V =^{def} V_{0}(I, −), then

V_{0}(Y, Z) ≅ V_{0}(I ⊗ Y, Z) ≅ V_{0}(I, [Y, Z]) = V [Y, Z]  (1.17)

so the V-object [Y, Z] is the lifting of the hom-set between Y and Z through V; and we can define the V-category V:

• the objects are the same as V_{0}: |V| =^{def} |V_{0}|;

• for any two objects X, Y, V(X, Y) =^{def} [X, Y];

• the composition is given by under the bijection

V_{0}([Y, Z] ⊗ [X, Y], [X, Z]) ≅ V_{0}(([Y, Z] ⊗ [X, Y]) ⊗ X, Z)

7This means that the 2-category Cat-Cat of small 2-categories, 2-functors and 2-natural transformations is enriched over Cat-Cat, and thus a “3-category”, and this process can be carried on to n-categories, but we shall refrain from doing so here, since little is known about the medical implications.

8For example, the construction of an adjunction from a monad by the Eilenberg-Moore category C^{T} for a monad T on a V-category C can be described as the left adjoint for the 2-functor mapping every category to the identity monad on it; and the Kleisli construction is just the dual of this case.

as the composition of

[figure: ([Y, Z] ⊗ [X, Y]) ⊗ X; a; ([Y, Z] ⊗ ([X, Y] ⊗ X)); 1 ⊗ ε_{X}; ([Y, Z] ⊗ Y); ε_{Y}; Z]

• and the identities are given by the image of l : I ⊗ X → X under the bijection V_{0}(I, [X, X]) ≅ V_{0}(I ⊗ X, X)

1.4.5 Enriched Functor Categories

Under the assumption that V is complete, and again certain size conditions, given two V-categories C,D, there is V-category V[C, D], the underlying ordinary category of which is V-Cat(C, D), the category of V-functors and natural transformations between them; for the details of this construction, we refer to [36, Chapter 2] or [4, Proposition 6.3.1].

1.4.6 Limits and Colimits for V-categories

The generalization of limits from ordinary category theory to the enriched case is more subtle. Recall that a limit for an ordinary functor F : J → C is defined in terms of the representability of the functor [J , C](Δ−, F) : C^{op} → Set. The problem is that it is not possible to define the constant functor ΔY : J → C in the enriched context, because we would have to give, for all J, K ∈ J, a morphism ΔX_{J,K} in V_{0} filtering through the identity on X (diagram 1.18); for the ordinary

[figure: J (J, K); ΔX_{J,K}; C(X, X); I; i_{X}; m]  (1.18)

case, I = {∗} is terminal in Set, so m is the unique morphism !_{J (J,K)} into {∗}, but in general this map m need not exist.

It turns out that the appropriate generalization of this concept is to allow weighted or indexed limits. A weight (or index) for a diagram given by a functor F : J → C is a functor G : J → V. Then the limit of F weighted or indexed by G, exists if the functor [J , V](G, C(X, F −)) exists for all X ∈ C and admits a representation

C(X, lim_{G}F) ≅ [J , V](G, C(X, F −))

We shall not pursue this theory here, since we do not need it below. The interested reader is referred to [4, Section 6.4] for a more lucid motivation of the construction, and to [36] for the finer points of the theory. For the reader interested in examples, [38] presents constructions like comma-categories and lax limits as (simple) weighted limits in Cat.

Like ordinary limits and colimits, weighted limits (colimits) are preserved by right (left) adjoints (which are enriched adjunctions, of course). For ordinary categories, we can weigh every diagram with Δ({∗}) : J → Set (for any J), recovering the conical limits from §1.3.3.

1.4.7 Tensors and Cotensors

In the category Set, sets of cardinality n represent n-tuples of elements under the following bijection:

Set(∐_{n}{∗}, Z) ≅ ∏_{n} Set({∗}, Z)  (1.19)

There is no reason that a similar bijection should hold in V_{0}; hence, to represent “tuples” of elements the notions of tensor and cotensor are introduced. In a Vcategory A, a the tensor of an object A ∈ A and X ∈ V is an object V ⊗ A s.t. for all B ∈ A,

A(X ⊗ A, B) ≅ V(X, A(A, B))

(Note the overloading of the symbol ⊗.) Dually the cotensor of A and X is an object X ⋔ A s.t.

A(A, X ⋔ B) ≅ V(X, A(A, B))

If these objects exist for all A and X, we say A is tensored (and cotensored, respectively). Tensors and cotensors are the simplest examples of weighted limits: the cotensor X ⋔ A is the limit of the functor F : 1 → A (where 1 is the oneobject V-category), weighted by G : 1 → V with G({∗}) = X. Proposition 1.3.1 now generalizes, a V-category A has all weighted colimits if it has all coproducts, coequalizers and is cotensored. Further, if U : A → B has a left adjoint, then U preserves cotensors as well as weighted colimits; and on the other hand, if the underlying ordinary functor U_{0} : A_{0} → B_{0} has an ordinary left adjoint, and U : A → B preserves cotensors, then U has a left adjoint.

1.4.8 Change of base

Let V = (V_{0}, ⊗, I) and W = (W_{0}, ⊕, J) be two monoidal closed categories, than a morphism between them is given by

• a functor F : V_{0} → W_{0}, • for all objects X, Y ∈ V, a morphism τ_{X,Y} : F X ⊕ F Y → F (X ⊗ Y) in W_{0},

which is natural in X and Y, and

• a morphism ε : J → F (I) in W_{0}.

respecting the associativity and the left and right unit (and the symmetry, if it is a morphism between symmetric monoidal closed categories).

A morphism like the above induces a 2-functor F^{∗} : V-Cat → W-Cat, which is defined as follows: let C be a V-category, then the W-category D =^{def} F^{∗}(C) has the same objects as C; for any two objects, D(X, Y) =^{def} F (C(X, Y)), the composition is given by

[figure: F (C(Y, Z)) ⊕ F (C(X, Y)); τ; F (C(Y, Z) ⊗ C(X, Y); F c_{X,Y,Z}; F (C(X, Z))]

and the identities for X ∈ D are given by

[figure: J; ε; F (I); F i_{X}; F (C(X, X))]

An application of this is that for any symmetric monoidal closed category V, there is a 2-functor U : V-Cat → Cat, defined as the lifting of the functor V =^{def} V_{0}(I, −) → Set taking a V-category C to its underlying ordinary category UC.

If V is cocomplete, this functor has a left adjoint^{9} F_{V}(−) : Cat → V-Cat, mapping an ordinary category C to its free V-category F_{V}(C); briefly, the construction is as follows: the functor V : V_{0} → Set has an ordinary left adjoint F : Set → V_{0}, which for a set X is ∐_{X} I, the X-th copower of the unit in V_{0}, and we have a bijection

V_{0}(∐_{X} I, Y) ≅ ∏_{X} V_{0}(I, Y) ≅ Set(X, V_{0}(I, Y))  (1.20)

For an ordinary category C, the free V-category has the same objects as C, and as hom-objects the image of the hom-sets under F. Again, we refer to the literature for the details of the construction ([4, Section 6.4] or [36, Section 2.5]).

1.5 Particular Categories

We shall in the following investigate the category of graphs, the category of binary relations, and the category of small categories, since they will play an important rôle in modelling reductions later on.

9To be precise, a left adjoint 2-functor.

1.5.1 Graphs and the Category Grph

This section reviews the definitions of a graph, the category of all graphs, paths in a graph and the relation between graphs and categories. A closer examination of the category of all graphs reveals that it has a closed structure but it is not cartesian closed. We will further investigate the relation between graphs and relations, and categories and pre-orders.

A Warning

In traditional graph theory, there are various definitions of graphs. Here, we prefer (of course) the definition from [52]. The reader with a background in graph theory rather than category theory should be aware of the following discrepancies between our definition and those found in graph theory: firstly, our graphs are directed (but we still say they have edges, not arcs, as is sometimes done); and secondly, our graphs can have more than one edge between two given vertices (graphs like these are sometimes referred to as multigraphs [92], although this term does not seem to be standard).

Graphs and the Category Grph

A graph G = (G_{0}, G_{1}, δ_{s}, δ_{t}) is given by a set of vertices G_{0}, a set of edges G_{1}, and two functions δ_{s}, δ_{t} : G_{0} → G_{1} assigning a source and a target vertex to every edge.

Given a graph G as above, we write V (G) for its set of vertices G_{0} and E(G) for its set of edges G_{1}. Further, we write e : x → y ∈ E(G) as an abbreviation of the statement that e is an edge in G with source x and target y.

A graph morphism f : G → H from a graph G to a graph H is given by two functions f_{V} : V (G) → V (H) and f_{E} : E(G) → E(H) respecting the source and target mapping, i.e.

\begin{aligned}δ′_{s}.f_{E} & = & f_{V}.δ_{s} \\ δ′_{t}.f_{E} & = & f_{V}.δ_{t} \end{aligned}  (1.21)

The category Grph consists of graphs as objects and graph morphisms as morphisms, with the evident identities and compositions.

More abstractly, a graph is a functor from the category ⇉ to the category Set of sets. The category Grph is the functor category [⇉, Set], and equation 1.21 just says that graph morphisms are natural transformations. This abstract view tells us that Grph is lfp, and it also tells us the generators in Grph (see §1.3.8 on page 19): the representable functors. Since the category ⇉ has two objects, there are two^{10} representable functors, giving two fp objects, namely the graph I, and the graph → which has two vertices and a single edge between them.

Paths in a Graph

A path in a graph G is given by a sequence <X_{1}, e_{1}, X_{2}, …, X_{n+1}> where n ≥ 0, X_{j} ∈ V (G), e_{i} ∈ E(G) and δ_{s}(e_{i}) = X_{i}, δ_{t}(e_{i}) = X_{i+1} for j = 1, …, n + 1 and i = 1, …, n. The set of all paths in G is denoted by G^{∗}.

For a path p = <X_{1}, e_{1}, X_{2}, …, X_{n+1}>, its source and target are defined as s(p) =^{def} X_{1}, t(p) =^{def} X_{n+1}. For two paths p = <X_{1}, e_{1}, X_{2}, …, X_{n+1}>, q = <Y_{1}, f_{1}, Y_{2}, …, Y_{m+1}> such that X_{n+1} = Y_{1}, their concatenation (composition) is defined as

p::q =^{def} <X_{1}, e_{1}, X_{2}, …, X_{n+1}, f_{1}, Y_{2}, …, Y_{m+1}>

The length of a path is the number of edges it contains:

|<X_{1}, e_{1}, X_{2}, …, X_{n+1}>| =^{def} n

In a non-empty path <X_{1}, e_{1}, X_{2}, …, X_{n+1}> (i.e. n > 0), we can omit the vertices X_{i}, since they are implicitly given by the edges. Thus, in the following, we write <e_{1}, e_{2}, …, e_{n}> for a non-empty path <δ_{s}(e_{1}), e_{1}, δ_{t}(e_{1}), e_{2}, δ_{t}(e_{2}), …, δ_{t}(e_{n})>; and for the empty path <X> with X ∈ V (G), we write id_{X}.

A path congruence on the paths G^{∗} is an equivalence relation ≡ ⊆ G^{∗} × G^{∗} which is compatible with path composition, i.e. the following two implications hold:

p ≡ q ⇒ s(p) = s(q), t(p) = t(q)  (1.22)

and for all paths p, q, r, s ∈ G^{∗} such that t(p) = s(q) and t(r) = s(s),

p ≡ r, q ≡ s ⇒ p::q ≡ r::s  (1.23)

Free Categories and Underlying Graphs

For a graph G, its free category F(G) has the vertices V (G) of G as objects, and paths in G as morphisms, with id_{X} as identities and concatenation as composition. This assignment extends to a functor F : Grph → Cat.

Every small category C has an underlying graph, the vertices of which are the objects of C, and the edges are the morphisms of C (with source and target as in C). This extends to a functor U : Cat → Grph, which is the right adjoint of the functor F.

10Up to isomorphism.

By this adjunction, to define a functor M : F(G) → X, it is sufficient to define a graph morphism d : G → UX. Then, d is called a diagram in X.

A Monoidal Closed Structure on Grph

Grph has a cartesian product, but is not cartesian closed. Grph also has a tensor product, which leads to a closed structure in which the internal homs are “transformations” – just like natural transformations on Cat, but without the naturality condition.

Given two graphs G, H, their cartesian product G × H is defined as the graph with

V (G × H) =^{def} V (G) × V (H)
E(G × H) =^{def} E(G) × E(H)

with the obvious source and target mappings. But this definition does not lead to a closed structure; there is no right adjoint for the functor − × G. There is one for a different monoidal structure, though:

Definition 1.5.1 (Tensor Product of Graphs) Given two graphs G, H, their tensor product G ⊗ H is defined as the graph with

V (G ⊗ H) =^{def} V (G) × V (H)
E(G ⊗ H) =^{def} V (G) × E(H) + E(G) × V (H)

with the source mapping defined as follows:

δ_{s}((x, e)) =^{def} \{ \begin{matrix}(x, δ_{s}(e)) & if x ∈ V (G), e ∈ E(H) \\ (δ_{s}(e), x) & if e ∈ E(G), x ∈ V (H) \end{matrix}

and the target mapping defined analogously.

The unit of the monoidal structure is the one-element graph I with one vertex, no edges and empty source and target mappings: I =^{def} ({∗}, ∅,!,!). Note that this is not the unit of the cartesian structure, since for any graph G, I × G has an empty set of edges; rather, the unit for the cartesian structure is given by

1 =^{def} ({∗}, {∗}, 1_{{∗}}, 1_{{∗}}).

When showing that the structure given by the tensor product and the unit as defined above is indeed monoidal structure (and even closed), the main emphasis will be on the edges of the graphs involved, since on the vertices, this is the cartesian product on Set (which is well-known to be monoidal and closed).

Lemma 1.5.2 Grph =^{def} (Grph, ⊗, I) is a symmetric monoidal category.

Proof. The proof of associativity of the tensor requires distributivity of the coproduct (disjoint union) over the cartesian product in Set, plus associativity and commutativity of the two. Hence, for three graphs G, H, K, the set of edges (for the vertices, associativity is just associativity of the product in Set), is given by

E((G ⊗ H) ⊗ K)
= V (G) × V (H) × E(K) + (V (G) × E(H) + E(G) × V (H)) × V (K)
≅ E(G) × V (H) × V (K) + V (G) × E(H) × V (K) + V (G) × V (H) × E(K)
≅ V (G) × (V (H) × E(K) + E(H) × E(H))E(G) × V (H) × V (K)
= E(G ⊗ (H ⊗ K))

The third line gives the set of edges of three edges as a polynomial in the product and sum on Set. This polynomial allows the “pointwise” verification of the coherence diagrams 1.12 and 1.13; e.g. for four graphs G_{1}, G_{2}, G_{3}, G_{4}, the edges of the tensor product can be given as a similar polynomial, which is the result of either way of chasing round diagram 1.12 (see [52, pg. 159]). Symmetry again follows from symmetry of the product and coproduct on Set. □

This leads to the closed structure on Grph: a transformation between graph morphisms is essentially like a natural transformation but without the naturality condition (for which to be stated the composition of edges would be needed).

Definition 1.5.3 (Transformation) Given two graph morphisms f, g : G → H from a graph G to a graph H, a transformation α : f ⇒ g is a set of edges in H indexed by vertices in G, such that for all x ∈ V (G) there is a α_{x} : f_{V} (x) → g_{V} (x) ∈ E(H).

We obtain a graph representing the function space between two graphs, the socalled internal hom in Grph:

Definition 1.5.4 The internal hom (or function space graph) of two graphs G, H is the graph [G, H] which has as its vertices all graph morphisms from G to H, and as edges all transformations between these graph morphisms, with the obvious source and target mappings.

We now want to show that the internal hom indeed represents the function space, i.e. for any given graph G, the functor [G, −] : Grph → Grph is right adjoint to the tensor product with G.

Lemma 1.5.5 For any graph G, the functor [G, −] : Grph → Grph is right adjoint to the functor − ⊗ G : Grph → Grph. Hence, the monoidal category Grph =^{def} (Grph, ⊗, I) is closed.

Proof. For all graphs H, there is a graph morphism e_{H} : [G, H] ⊗ G → H which is natural in H and universal from − ⊗ G to H, defined as follows:

e_{H}_{V} (m, x) =^{def} m_{E}(x)
e_{H}_{E}(α, y) =^{def} α_{x} : m_{E}(y) → n_{E}(y) for α : m ⇒ n : G → H, y ∈ V (G)
e_{H}_{E}(m, a) =^{def} m_{E}(a) for m : G → H, a ∈ E(H)

Showing that this is a graph morphism, and natural in H is fairly routine. To show that it is universal, we have to show that for all graphs K and graph morphisms f : K ⊗ G → H, there is a unique f̂: K → [G, H], called the currying of f, such that

[figure: [G, H] ⊗ G; e_{H}; H; K ⊗ G; f̂⊗ 1_{G}; f]

f̂ is defined as follows: on vertices, it maps a morphism m : K → H to a a graph morphism f̂(m) : G → H which itself is given by on the vertices by f̂(m)_{V} (x) =^{def} f_{V} (m, x) and on the edges by f̂(m)_{E}(e) =^{def} f_{E}(m, e); and on edges, f̂ maps a transformation α : m ⇒ n : K → H to a transformation β : f̂(m) ⇒ f̂(n) : G → H, defined as β_{x} =^{def} f_{E}(α, x). The requirement that this is a graph morphism amounts to the universality (any other such graph morphism is equal to f̂). □

In the preceding, we have concentrated on the monoidal structure on the objects; of course, one has to show that ⊗ is in fact a functor. For two graph morphisms f : G → G′, g : H → H′, f ⊗ g is a graph morphism f ⊗ g : G ⊗ H → G′ ⊗ H′ which on the edges is defined is defined as follows (on the vertices, it is the obvious definition):

(f ⊗ g)_{E}⟨x, e : y → y′⟩ =^{def} ⟨f_{V} (x), e_{E}⟩
(f ⊗ g)_{E}⟨e : x → x′, y⟩ =^{def} ⟨f_{E}(e), y_{V} ⟩

The internal hom [G, −] on morphisms maps f : H → K to the postcomposition f.(−) with f, much like its analogue Set(X, −) : Set → Set in the category of small sets.

1.5.2 Binary Relations and the category Rel

A binary relation R on a set X is a subset of the product X × X, written (X, R). A relation morphism f : (X, R) → (Y, S) is a function f : X → Y which is monotone, i.e. for all x, y ∈ X, xRy ⇒ (fx)S(fy), where xRy is the infix notation for (x, y) ∈ R which will be used in the following. This gives the category Rel of relations and morphisms between them; it has, just as graphs, a cartesian product R × S and a tensor product R ⊗ S defined as follows:

(X, R) × (Y, S) =^{def} (X × Y, {((x_{1}, y_{1}), (x_{2}, y_{2})) | x_{1}Rx_{2} ∧ y_{1}Sy_{2}})
(X, R) ⊗ (Y, S) =^{def} (X × Y, \{((x_{1}, y_{1}), (x_{2}, y_{2})) | \begin{matrix}(x_{1} = x_{2} ∧ y_{1}Sy_{2}) ∨ \\ (x_{1}Rx_{2} ∧ y_{1} = y_{2})\}) \end{matrix}

The unit for the cartesian product is given by the one-element all-relation 1 =^{def} ({∗}, {(∗, ∗)}), and the unit for the tensor product, the one-element empty relation I =^{def} ({∗}, ∅). We obtain two monoidal structures on Rel, and Rel is closed with respect to both of these, but with two different relations on the functions: given (X, R) and (Y, S), then the function space between them will be the set [X, Y] of all functions from X to Y which are monotone w.r.t.. R and S. If we order the functions pointwise

f < g ⇔ ∀x ∈ X. fx S gx

then the relation ([X, Y], <) is the internal hom with respect to the tensor product. If on the other hand we order the functions implicational

f ≻ g ⇔ ∀x, y ∈ X. xRy ⇒ fx S gy

then the relation ([X, Y], ≻) is the internal hom with respect to the cartesian product.

Closures

Given two relations (X, R) and (X, S), their relational product is defined as

(X, R; S) =^{def} (X, {(x, z) | ∃y.xRy ∧ ySz})

The reflexive closure of a relation (X, R) is defined as

(X, R)^{=} =^{def} (X, R ∪ {(x, x) | x ∈ X})

and the transitive closure (X, R)^{+} as the smallest relation closed under the relational product (X, R) ⊆ (X, R; R). Both the reflexive and the transitive closure of a relation can be given by monads on the category Rel, the algebras being reflexive and transitive relations, respectively. They can be combined into a single monad, giving for a relation (X, R) its transitive-reflexive closure (X, R)^{∗}.

Hence, there is the following system of adjunctions between the categories of reflexive, transitive and reflexive-transitive relations. A relation which is reflexive and transitive is also called a preorder, with Pre the category of preorders:

Rel [figure: (−)^{=}; ⊥; \overline{⊃}] RRel

TRel ⊣ (−)^{+}_{}^{^{∪} } [figure: (−)^{R}; ⊥; \overline{⊃}] Pre ⊣ (−)^{+}_{}^{^{∪} }

In this case, the two monads can be combined in both possible ways, making the diagram commute; in general, this is not the case (e.g. if we replace the reflexive by the symmetric closure above). The reflexive-transitive closure of a relation (X, R) is written as (X, R)^{∗}, and satisfies the following property with respect to the relational product

(X, R ∪ S)^{∗} = (X, R^{∗}; S^{∗})^{∗}  (1.24)

Relations and Graphs

A relation (X, R) can be considered as a graph G(R) =^{def} (X, R, π_{1}, π_{2}); hence a relation is equivalent to a graph with at most one edge between any two given vertices, and we can even say that Rel is a subcategory of Grph. On the other hand, given a graph G, we obtain a binary relation |G| ⊆ V (G) × V (G) on the vertices of G, defined by (x, y) ∈ |G| ⇔ ∃p : x → y ∈ E(G). This extends to a functor G : Rel → Grph, which is left adjoint to the inclusion Rel ↪ Grph, so Rel is a reflective subcategory of Grph.

Similarly, a preorder can be considered a category with at most one morphism between any two morphisms, with the identities and composition given by the reflexivity and the transitivity. The adjunction between Rel and Grph can be lifted to categories and preorders: for a category C, the relation given by the underlying graph of C is a preorder, giving a functor J : Cat → Pre by J(C) =^{def} |UC| which identifies all morphisms between the same source and target, which is left adjoint to the inclusion I : Pre ↪ Cat. Moreover, the counit of this adjunction is the identity

J(I(X)) = X  (1.25)

since any preorder X considered as a category will have at most one morphism between any two objects:

In summary we obtain the following system of commuting adjunctions:

Rel [figure: (−)^{∗}; ⊥; \overline{⊃}] Pre

Grph ⊢ |−| ^{∩} [figure: F; ⊥; \underline{U}] Cat ⊢ J ^{∩}

1.5.3 Small Categories and the Category Cat

In this section, we will investigate the internal structure of the category Cat of all small categories. The results in this section are more or less standard.

Epimorphisms and Monomorphisms in Cat

An epimorphism in Cat is a functor which is surjective on objects, and surjective under closure on morphisms^{11}, i.e. given F : X → Y, for all β ∈ Mor_{Y} there are α_{1}, …, α_{n} ∈ Mor_{X} such that β = F (α_{n}). . . ..F (α_{1}). A monomorphism in Cat is a functor which is injective on objects, and injective on morphisms (i.e. it is faithful); we call such functors injective in the following.

Closed Monoidal Structures on Cat

The cartesian product of two categories X , Y is called a product category, and has as objects and morphisms pairs of objects and morphisms from X and Y (with the obvious pointwise definitions for identity and composition):

|X × Y| =^{def} |X | × |Y|
X × Y((x_{1}, y_{1}), (x_{2}, y_{2})) =^{def} X (x_{1}, x_{2}) × Y(y_{1}, y_{2})

Further, Cat is cartesian closed: for any category X, the functor − × X : Cat → Cat mapping Y to the product category Y ×X has a right adjoint [X , −] : Cat → Cat mapping Y to the functor category [X , Y].

Cat also inherits the tensor product from Grph. For two categories, X, Y, their tensor product X ⊗ Y has the same objects as the product category, but as morphisms sequences of pairs of objects and morphisms <(α_{1}, β_{1}), …, (α_{n}, β_{n})> such that for i = 1, …, n, either α_{i} ∈ X , β_{i} ∈ Y(x_{i}, y_{i}) with β_{i} ≠ 1_{x_{i}} and if i < n then α_{i+1} ∈ X (x_{i+1}, y_{i+1}), β_{i+1} ∈ Y with α_{i} = x_{i+1} and y_{i} = β_{i+1}, or the other way around, i.e. α_{i} ∈ X (x_{i}, y_{i}), β_{i} ∈ Y with α_{i} ≠ 1_{x_{i}} and if i < n then α_{i+1} ∈ X , β_{i+1} ∈ Y(x_{i+1}, y_{i+1}) with y_{i} = α_{i+1} and β_{i} = x_{i+1}. The source of the path above is the source of (α_{1}, β_{1}), which is (α_{1}, x_{1}) if α_{1} ∈ X , β_{1} ∈ X (x_{1}, y_{1}), and (x_{1}, β_{1}) otherwise; the target is defined analogously. The identity is given by the empty sequence, and composition by concatenation and composition in X and Y. This monoidal structure is closed: the functor − ⊗ X : Cat → Cat has a right adjoint. This is best explained in terms of the internal hom resulting from it: given two functors F, G : X → Y, a transformation α : F ⇒ G between them is a family {α_{X} : F X → GX}_{X∈X} of arrows in Y, indexed by the objects in X. (In other words, a natural transformation without the naturality requirement 1.1). Taking the functors between X and Y as objects, we obtain the category of functors and transformations between them, denoted as [[X , Y]], and we have the adjunction − ⊗ X −| [[X , −]].

11This does not mean it is full, as one might perhaps expect.

In summary, we obtain the two closed monoidal categories Cat_{C} =^{def} (Cat, ×, 1) and Cat_{S} =^{def} (Cat, ⊗, 1).

Coproducts and Coequalizers in Cat

In order to construct colimits in Cat, using proposition 1.3.1 we need coproducts and coequalizers. The first is easy: the coproduct of two categories C and D is given by their disjoint union, the objects and morphisms of which are the disjoint union of the objects and morphisms of C and D, respectively.

The construction of the coequalizer is a bit more involved. Given two functors F, G : X → Y, their coequalizer in Cat is a category Z and a functor Q : Y → Z,

[figure: X; F; G; Y; Q; Z]

with Z defined as follows (see also [24, Chapter I.1]):

• Its objects are given by the coequalizer in Set of the two object functions |F |, |G| of F and G respectively; in other words, the objects of Y quotiented by the equivalence closure ≡_{O} of the relation ∼ defined as

x ∼ y ⇔ ∃z ∈ Y.F z = x, Gz = y

• Its morphisms are given as follows: we define the graph Z_{0} which has

Vertices: V (Z_{0}) =^{def} |Y|/≡_{O}
Edges: E(Z_{0}) =^{def} {α : [x] → [y] | α ∈ Y(x, y)}

The equivalence relation ≡_{M} on Z_{0}^{∗} is defined as the smallest path congruence on Z_{0}^{∗} such that (i) for all α ∈ Y(x, y), β ∈ Y(y, z), <α, β> ≡_{M} <β.α> (ii) for all α ∈ Mor_{X}, <F α> ≡_{M} <Gα>

Then for X, Y ∈ Z, the set of morphisms is

Z(X, Y) =^{def} {α ∈ Z_{0}^{∗} | s(α) = X, t(α) = Y }/≡_{M}

For an object X ∈ Y, the identity on X is the equivalence class of the empty path 1_{X} =^{def} [id_{X}]. The composition of two morphisms [A], [B] is given by [B].[A] =^{def} [A::B]. This is well-defined because ≡_{M} is a path congruence.

The functor Q : Y → Z maps objects to their equivalence classes, and morphisms to the equivalence class of the singleton sequence: for x ∈ Y and α ∈ Y(x, y),

Q(x) =^{def} [x]
Q(α) =^{def} [<α>]

1.6 Basic Principles of Term Rewriting

In this section, we will briefly recall those basic concepts of term rewriting which we will need in this thesis. For a more detailed introduction, we refer the reader to e.g. [41, 10].

1.6.1 Abstract Reduction Systems and Term Rewriting Systems

The following definition is slightly paraphrased from [41]:

Definition 1.6.1 An abstract reduction system is a structure A = ⟨A, {→_{α}}_{α∈I}⟩ consisting of a carrier set A and a family of binary relations →_{α}⊆ A × A, called reduction or rewrite relations.

Fix a countably infinite set V of variables.^{12} A substitution is a map σ : T_{Ω}(V) → T_{Ω}(V) such that σ(f(t_{1}, …, t_{n})) = f(σt_{1}, …, σt_{n}) for all operations f ∈ Ω. A context is a term C ∈ T_{Ω⊎{□}}(V) with exactly one occurrence of a special constant □. A context is generally denoted by C[ ]. If t ∈ T_{Ω}(V), the result of substituting t for □ in a context C[ ] is written C[t].

12Which in [41] is actually taken to be part of the signature.

A rewrite rule r : t → s is given by two terms t, s ∈ T_{Ω}(V). A rewrite rule gives rise to reduction steps C[σ(t)] →_{r} C[σ(s)], for all contexts C[ ], and substitutions σ.

Then for every term rewriting system Θ = (Ω, R), given by a signature Ω and a set of rewrite rules R, there is an abstract reduction system (the one-step reduction relation) (T_{Ω}(V), {→_{r}}_{r∈R}).

The many-step reduction relation {↠_{r}} is defined as the transitive-reflexive closure of {→_{r}}, describing the reduction of term s to another term t in 0 or more steps. The one-step reduction relation →_{R} is the union of →_{r} for all r ∈ R (and similarly ↠_{R}). Further, the equivalence closure of ↠_{R}, denoted =_{R}, is called the convertibility relation generated by R, and describes the equational theory generated by the term rewriting system, or equivalently, the theory of the rewrite rules considered as equations.

1.6.2 Commutativity, Confluence and Strong Normalization

Properties of term rewriting systems such as confluence and strong normalisation can be defined on the level of binary relations (see §1.5.2 above). This has the advantage that one can prove lemmas (such as the Hindley-Rosen lemma below) directly at this more abstract level.

Definition 1.6.2 (Commuting Relations) A binary relation →_{R}⊆ X × X commutes with a binary relation →_{S}⊆ X × X if for all x, y, z ∈ X such that x →_{R} y and x →_{S} z, there is a u ∈ X such that

x

y R ; \underline{↞}  z^{S \overline{↠}}

u R ; \underline{↞}^{S  \overline{↠}}

(where ↠_{R} is the reflexive-transitive closure of →_{R}).

A binary relation is confluent if it commutes with itself. If above y →_{S^{=}} u, y →_{R^{=}} u we say that →_{R} subcommutes with →_{S}. If both →_{R} and →_{S} above are confluent, then commutativity means that their union is confluent as well:

Lemma 1.6.3 (Hindley-Rosen [71]) Given two confluent binary relations →_{R} ⊆ X × X, →_{S} ⊆ X × X where →_{R} commutes with →_{S}, then →_{R} ∪ →_{S} is confluent.

Definition 1.6.4 (Strong Normalization) A binary relation →_{R} ⊆ X × X is called strongly normalizing (terminating) if there is no infinite sequence

x_{1} →_{R} x_{2} →_{R} x_{3} →_{R} …

Finally, the notions of confluence and strong normalization carry over to term rewriting systems: a term rewriting system Θ = (Ω, R) is confluent if the one-step reduction relation →_{R} is confluent, and a term rewriting system Θ = (Ω, R) is strongly normalizing (or terminating) if →_{R} is strongly normalizing.

A binary relation (or term rewriting system) which is both confluent and strongly normalizing is called complete.

1.7 Words and Languages

This section contains a few definitions and lemmas dealing with the algebra of words over a language. These are technical preliminaries for §3.2, so the reader may want to defer studying these definitions until that point.

Let L^{∗} be the language of words over an alphabet L. We write ε for the empty word in L^{∗}, and juxtaposition for the concatenation of words. Further, L^{+} is the sublanguage of non-empty words: L^{+} =^{def} L^{∗} \ {ε}. ≤ ⊆ L^{∗} × L^{∗} is the prefix ordering on words: w_{1} ≤ w_{2} iff there is u ∈ L^{∗} such that w_{1}u = w_{2}. < is the strict prefix ordering: w_{1} < w_{2} iff there is u ∈ L^{+} such that w_{1}u = w_{2}. The length of a word w ∈ L^{∗} is defined as follows: |ε| =^{def} 0, |jw′| = 1 + |w′| for j ∈ L, w′ ∈ L^{∗}

Lemma 1.7.1 Let v, w, x, y ∈ L^{∗} such that vw = xy, then one of the following three is true: v < x, x = v, or x < v.

Proof. By induction on the length of w and a careful case distinction [47]. □

The notion of a decomposition as defined in the following, and the lemmas to go with it, seem not to be standard, hence we go into perhaps more detail than the substance of the material warrants.

A decomposition of a word w ∈ L^{∗} is given by words x, y, z ∈ L^{+} such that xyz = w. We will need the following facts about decompositions:

Lemma 1.7.2 Given two decompositions w = rst and w = xyz, at least one of the following six cases is true:

(i) there is u ∈ L^{∗} s.t. w = rsuyz;

(ii) there is u ∈ L^{∗} s.t. w = xyust;
(iii) there are u, v ∈ L^{∗} s.t. v ≤ y, xv = r, vs = yu and ut = z;
(iv) there are u, v ∈ L^{∗} s.t. u ≤ s, ru = x, uy = sv and vz = t;
(v) there are u, v ∈ L^{∗} s.t. ruyvt = w;
(vi) there are u, v ∈ L^{∗} s.t. xusvz = w.

In case (i) and (ii), we say s and y are independent; in case (iii) and (iv), we say they are overlapping; in case (v) we say s contains y, and in case (vi) that y contains s.

Proof. Using lemma 1.7.1, we do a case distinction on the strict prefix ordering:

1. x < r then ∃v′ ∈ L^{∗}.xv′ = r, with the following sub-cases:

(a) xy ≤ r then ∃u′ ∈ L^{∗}.xyu′ = r: case (ii) with u =^{def} u′;

(b) r < xy then ∃u′ ∈ L^{∗}.ru′ = xy, with the following two sub-cases: i. xy ≤ rs then ∃w′ ∈ L^{∗}.xyw′ = rs: case (iii) with u =^{def} w′, v =^{def} v′; ii. rs < xy then ∃w′ ∈ L^{∗}.rsw′ = xy: case (vi) with u =^{def} v′, v =^{def} u′ as

given.

2. x = r then we have the following sub-cases:

(a) y = s: cases (iii) and (iv) with u, v =^{def} ε;

(b) y < s then ∃u′ ∈ L^{∗}.su′ = y: cases (iii) and (v) with u =^{def} ε, v =^{def} u′.

(c) s < y then ∃u′ ∈ L^{∗}.yu′ = s: cases (iv) and (vi) with u =^{def} ε, v =^{def} u′.

3. r < x: symmetric to the first case, covering cases (i), (iv) and (v).

□

We will below be interested in cases in which we can make the following useful simplification: Lemma 1.7.3 Given two decompositions w = rst and w = xyz of w such that ||s| − |y|| ≤ 1, then cases (v) and (vi) are subsumed by cases (iii) and (iv). In other words, s and y are either independent or overlapping.

Proof. Assume that s contains y, then there are u, v ∈ L^{∗} such that ruyvt = w, then uyv = s, and |u| + |y| + |v| = |s|, |u| + |v| = |s| − |y| ≤ 1, hence |u| = 0 or |v| = 0. |u| = 0 implies u = ε, and this is covered by case (iii) with v′ =^{def} ε, u′ =^{def} s; similarly, |v| = 0 implies v = ε, which is covered by case (iv) with v′ =^{def} u,

u′ =^{def} ε. □

A Compositional Semantics for Term Rewriting Systems

Signatures and equational presentations (i.e. signatures together with sets of equations) can be modelled by monads on the category Set of all small sets. Here is how a monad T = ⟨T, η, μ⟩ on Set captures the way terms are built:

• For a set X, we can consider T X to be the term algebra (the set of terms built over the variables X);

• then the unit η_{X} : X → T X describes how to make elements of X into variables (i.e. terms);

• and the multiplication μ : T T X → T X describes how to substitute terms for variables.

The monad laws mean that this substitution is associative, and that substituting a term into a variable, and a variable for itself, yields the identity (in an informal notation, x[t/x] = t and t[x/x] = t). The naturality of η and μ mean that the process of taking an element of X to a variable has be uniform over all sets X (i.e. does not depend on the set X). It turns out this is all one needs to do universal algebra (see [53]).

The key issue of this chapter will be the generalization of this construction to “sets with structure”, by endowing the set T X of terms with a reduction structure between its elements. We will now try to sketch what this structure could be before describing the difficulties we are likely to encounter during the generalization. This will be the main motivation for the rest of this chapter, which will deal with resolving the issues and questions raised in the following two paragraphs.

Sets With Structure

What do we mean by “set with structure”? The intuitive picture is of a set as collection of elements (denoting terms), then the structure consists of some sort of “arrows” in between them (denoting reductions). The exact definition depends on the kind of reduction structure we are interested in. In particular, we can distinguish between one-step and many-step reductions, and between named and unnamed reductions (with the latter, any two reductions between the same two terms are equal). Each of these structures corresponds to one concrete instantiation of the abstract theory.

The Monad Construction

The generalization of the monad construction is more subtle than a cursory first glance might suggest^{1}, because we have to make explicit some of the implicit properties of Set used in the modelling of the equational presentations.

First, in the category Set we can completely forget about the internal structure of the objects, since every set X is determined by the morphisms into it, which in turn form a set. Abstracting from the properties of objects is a key concept in category theory, so if we generalize our objects to “sets with structure”, we have to generalize the set of morphisms (hom-sets in category theory parlance) to sets-with-structure of morphisms as well; this means our construction has to be an enriched monad in the sense of §1.4.

The second realization is that terms are just composed operations. Consequently, contexts (sets of variables to build terms from) and arities (the number of arguments of an operation) are essentially the same, and have to modelled by the same objects of the base category.^{2} In Set, these are finite sets (as contexts) or natural numbers or finite ordinals (as arities). In categories of sets-with-structure, this rôle will be taken, roughly speaking, by finite sets-with-structure. This means the arities of operations can be more than just natural numbers, and will have interesting ramifications on the rewrite rules, since it will allow rewrites between variables.

Compositionality

Giving a “semantics” to a formal system such as a term rewriting systems or equational specification amounts to constructing a mapping from the syntactic presentation of these systems into a mathematical structure such as relations (for term rewriting systems) or sets and operations on them (for equational presentations). One then aims to understand the formal system by reflecting the behaviour of the predefined structure back to the formal system; e.g. an equation which holds in all algebras satisfying an equational presentation follows from the equations of the presentation.

1In particular, it is not sufficient to merely change the base category of the monad.

2One particular point here is that the arities are modelled by objects of the base category in the first place, something which may not be clear a priori.

A semantics is called compositional if the mapping preserves structuring operations, such as the disjoint union. The structuring operations, and their definitions on both the syntactic and the semantic representations will be the focus of the next chapter, but in this chapter we will show that our semantics satisfies a property which makes it preserve most structuring operations; namely, it is a left adjoint.

Structure of this Chapter

The rest of this chapter is structured as follows:

• In §2.1, we will recall the categorical treatment of universal algebra by monads on the category Set of all small sets. Besides motivation, this will provide us with the objects of sets with structure.

• We will then in §2.2 present the basic principles of the theoretical foundation of this work as developed by Kelly and Power in [39]. This section is optional, and can be skipped by readers feeling uneasy about enriched category theory.

• In §2.3, we will instantiate the general theory of §2.2 to our particular needs, explaining the general notions (as far as needed) in the process. We will then develop a term construction, ultimately yielding a monad on the category Pre of preorders modelling a term rewriting system.

• In §2.4, we will develop some properties of the monad as needed in the later chapters.

• Finally, in §2.5, we will show the semantics to be compositional in the sense that it is left adjoint; the precise meaning of this, and the structuring operations themselves will be discussed in the next chapter.

The main section of this chapter is §2.3; the two sections before are motivation and definitions leading up to that section. The hurried reader may choose to restrict his attention in these sections to definition 2.1.2 and §2.1.2, which introduce notations used extensively in the following.

2.1 Signatures and Equational Presentations

In this section, we recall the well known notions of universal algebra and their categorical treatment, such as the definitions of signatures, signature morphisms, algebras and algebra homomorphisms (the “semantic” treatment of signatures) in §2.1.1, and the construction of the term algebra (the “syntactic” treatment) in §2.1.2. The fact that the term algebra is free over other algebras of the same signature corresponds to an adjunction between the category of algebras for the signature, and the category of all small sets. This naturally leads to the modelling a signature by a monad on Set. In §2.1.3 we will develop the notion of the internal signature of a monad; the mapping of a signature to the modelling monad, and of a monad to its internal signature will be adjoint. Finally, as an aside in §2.1.4 we will sketch the modelling of equational presentations.

The reader familiar with e.g. the material in the first three chapters of [12] will be able to skip §2.1.1 and §2.1.2, but should have a brief glance at definitions 2.1.1 and 2.1.2 to pick up our notation.

2.1.1 Signatures and Algebras

Signatures and Signature Morphisms

Signatures or operator domains are sets of operators equipped with an arity. Morphisms are maps between them respecting these arities; and signatures and the morphisms between them give rise to the category Sig.

Definition 2.1.1 (Signature) A finitary signature or operator domain Ω is given by a map Ω : ℕ → Set, giving for a natural number n ∈ ℕ the set Ω_{n} =^{def} Ω(n) of operations of arity n.

In the literature, the name operator domain is mainly used for the traditional single-sorted case [8, 53], and signature for the many-sorted case used in the context of algebraic specifications [12]. We will stick to the second term. Also, normally signatures are defined “the other way around”, as a set of operations Ω together with a function ar : Ω → ℕ assigning an arity to each operation. This is equivalent to definition 2.1.1 in the sense that given a signature as Ω′ : ℕ → Set, one can always define a set of operators Ω together with an arity function ar : Ω → ℕ, and vice versa, but definition 2.1.1 allows an easier development of the theory.

If the arities of the operations are not restricted to finite ordinals, one obtains infinitary signatures. Using monads, these can also be treated in much the same way as the finitary ones^{3}, but the resulting monads do not enjoy some of the properties needed later on (see section 2.4.1). Moreover, they do not seem of great practical relevance; hence, we restrict ourselves to finitary signatures, and in the following, mean finitary signatures whenever we merely say signature.

Given two signatures Ω and Σ, a signature morphism σ : Ω → Σ is a family of maps {σ_{n} : Ω(n) → Σ(n)}_{n∈ℕ}. This gives the category Sig with signatures as objects, and signature morphisms as morphisms. More abstractly, if we consider ℕ as a discrete category, Sig is the functor category [ℕ, Set]; a signature morphism is a natural transformation, but since ℕ is discrete, the naturality condition is vacuous.

When writing signatures, we will use subscripts to denote the arities; e.g. writing Ω = {F_{1}, K_{2}} means there is a signature Ω = {1 ↦ {F}, 2 ↦ {K}}.

Algebras for a Signature

Given a signature Ω, a Ω-algebra A = (A_{S}, {ω_{A}}_{ω∈Ω}), is given by a set A_{S}, called the carrier set and, for all operations ω ∈ Ω_{n}, a function ω_{A} : A^{n} → A.

Given two Ω-algebras A, B, a homomorphism between them is given by a map f : A_{S} → B_{S} respecting the operations in Ω: for all ω ∈ Ω_{n}, and for all a_{1}, …, a_{n} ∈ A_{S},

ω_{B}(f(a_{1}), …, f(a_{n})) = f(ω_{A}(a_{1}, …, a_{n}))  (2.1)

Alternatively, this requirement can be written (without using elements of A_{S}) as ω_{B}.f^{n} = f.ω_{A} (where f^{n} is the n-fold product of f with itself, rather than the n-fold composition of f with itself). We obtain, for a signature Ω, the category Ω-Alg of Ω-algebras.

2.1.2 The Term Algebra

Very crudely spoken, a term is a syntactic entity generated by the signature. Terms have the structure of an algebra, and moreover a very important one (it is “freely generated”, meaning there is exactly one mapping to any other algebra). Another way to regard terms is as composed operations; then the set of all terms is the closure of the operations under composition.

The Term Algebra Construction

Given a set X of variables, the term algebra T_{Ω}(X) is the smallest set which contains all variables x ∈ X and is closed under application of the operations in Ω. Put formally (this also fixes the notation we use for terms in the following)^{4}

3This is one of the advantages of the monad treatment.

Definition 2.1.2 (Term Algebra) Given a signature Ω and a set X, the term algebra T_{Ω}(X) is the smallest set satisfying the following implications:

'x ∈ T_{Ω}(X) x ∈ X  {t_{1}, …, t_{n} ∈ T_{Ω}(X) \atop ω(t_{1}, …, t_{n}) ∈ T_{Ω}(X)} ω ∈ Ω_{n}

The set of variables of a term t ∈ T_{Ω}(X) is defined inductively as follows:

var('x) =^{def} {x}
var(ω(t_{1}, …, t_{n})) =^{def} ⋃_{i=1,... ,n} var(t_{i})

We are now going to extend construction 2.3.4 to a monad. In order to prove the monad properties, we need a structural induction scheme.

Structural induction

To prove that a predicate holds for all terms, a method called structural induction is used:

Proposition 2.1.3 For a predicate R on T_{Ω}(X), we write t ⊧ R (R holds for t) if t ∈ R for t ∈ T_{Ω}(X). Then t ⊧ R for all t ∈ T_{Ω}(X) (R holds for all terms) if the following two implications hold:

x ∈ X ⇒ 'x ⊧ R
ω ∈ Ω_{n}, t_{1} ⊧ R, …, t_{n} ⊧ R ⇒ ω(t_{1}, …, t_{n}) ⊧ R

The first of these is called the induction base, the second the induction step.

Proof. This is proven by reducing it to natural induction. For the details, see e.g. [12, pg. 19]. We define the size of a term as the number of operation symbols in it; then for a predicate R define a predicate q on the natural numbers such that q(n) holds iff. R holds for all terms of size n or less; then show that if the two implications above hold, q(n) holds for all n ∈ ℕ, and hence for all terms, by natural induction on n. □

4The reader may wonder about the reason for notation 'x: later on we will consider terms built over terms, and we will have to distinguish terms like 'x in T_{Ω}(X) and ''x in T_{Ω}(T_{Ω}(X)), or even 'K('x) and K(''x) in T_{Ω}(T_{Ω}(X)).

Freeness of the Term Algebra

The term algebra is free in the class of all algebras over a set X, meaning there is exactly one homomorphism from it to any other algebra A once the assignment of the variables in X has been fixed. This homomorphism lets us evaluate terms from T_{Ω}(X) in A.

Lemma 2.1.4 Given a set X, an Ω-algebra A, and a map σ : X → A_{S} (called an assignment of the variables in X), there is a unique map \overline{σ} : T_{Ω}(X) → A_{S} which is an algebra homomorphism, called the homomorphic extension of σ, satisfying

[figure: X; η_{X}; T_{Ω}(X); A_{S}; \overline{σ}; σ]  (2.2)

diagram 2.2, where η_{X} is the inclusion of the variables into the term algebra, defined as

η_{X}(x) =^{def} 'x

Proof. \overline{σ} is defined as follows:

\overline{σ}(ω(t_{1}, …, t_{n})) =^{def} ω_{A}(\overline{σ}(t_{1}), …, \overline{σ}(t_{n}))
\overline{σ}('x) =^{def} σ(x)

The second of these equations makes diagram 2.2 commute. Any homomorphism has to satisfy equation 2.1 which is the first equation. Hence \overline{σ} is uniquely defined.

□

In fact, the inclusion η_{X} is the unit of an adjunction between the category of all sets, and the category of all Ω-algebras, given by

F_{Ω} −| U_{Ω} : Set → Ω-Alg  (2.3)

where the left adjoint F_{Ω} maps any set X to the term algebra T_{Ω}(X), and the right adjoint U_{Ω} maps any Ω-algebra A to its carrier set A_{S}. The uniqueness of the homomorphic extension is exactly the universal property of the unit of the adjunction.

A Signature is Modelled by a Monad

Like every adjunction, this gives rise to a monad which as argued in the introduction exactly captures the way terms are built. We will first describe the left adjoint F_{Ω} in more detail:

Definition 2.1.5 The functor F_{Ω} : Set → Ω-Alg maps a set X to T_{Ω}(X), and a map f : X → Y in Set to its lifting f^{∗} : T_{Ω}(X) → T_{Ω}(Y), defined as follows:

f^{∗}(ω(t_{1}, …, t_{n})) =^{def} ω(f^{∗}(t_{1}), …, f^{∗}(t_{n})) where ω ∈ Ω_{n}
f^{∗}('x) =^{def} 'fx

That f^{∗} is an Ω-homomorphism (i.e. respects the operations) is obvious. That the assignment f : X → Y to f^{∗} : T_{Ω}(X) → T_{Ω}(Y) is functorial (preserves composition and identities) is shown by routine structural induction.

The counit of the adjunction is a natural transformation ε_{A} : F_{Ω}(U_{Ω}(A)) → A for every Ω-algebra A, which can be thought of as the evaluation of terms t in the algebra A. It is defined as follows:

\begin{matrix}ε_{A}('x) & =^{def} & x \\ ε_{A}(ω(x_{1}, …, x_{n})) & =^{def} & ω_{A}(ε_{A}(x_{1}), …, ε_{A}(x_{n})) \end{matrix}  (2.4)

Proposition 2.1.6 Every signature Ω gives rise to a monad T_{Ω} =^{def} ⟨T_{Ω}, η, μ⟩ on Set, where T_{Ω} maps X to the term algebra T_{Ω}(X), and f : X → Y to its lifting f^{∗} : T_{Ω}(X) → T_{Ω}(Y). The multiplication is given by μ =^{def} U_{Ω}ε_{F_{Ω}}, or more explicitly

μ_{X}(ω(t_{1}, …, t_{n})) = ω(μ_{X}(t_{1}), …, μ_{X}(t_{n}))
μ_{X}('x) = x

This monad actually subsumes the adjunction 2.3, because one can show that the Eilenberg-Moore-category of algebras of this monad and the category Ω-Alg of Ω-algebras are isomorphic; hence the categorical notion of an algebra subsumes the notion of an Ω-algebra. This even works for equational presentations, so “finitary universal algebra is the study of finitary monads on Set” [53, pg. 42].

Finitariness

The monad T_{Ω} satisfies an important continuity condition: it is finitary. To understand this condition, consider the term algebra T_{Ω}(X) over an infinite set X. Since every operation ω ∈ Ω_{n} can only take finitely many arguments, every term t ∈ T_{Ω}(X) can only contain finitely many variables from X; and hence, instead of building the term algebra over the infinite set X, we can also build the term algebras over all finite subsets X_{0} of X and take the union of these:

T_{Ω}(X) = ⋃_{X_{0}⊆X} T_{Ω}(X_{0})

Categorically, we say that the set X is the colimit of the directed diagram of its finite subsets; and above equation means that the functor T_{Ω} has to preserve directed colimits or in other words is finitary.

The monad T_{Ω} arising from a signature even is strongly finitary, since the absence of equations means precisely that the action T_{Ω} preserves coequalizers and hence weakly filtered colimits (see lemma 1.3.7), whereas the monad T_{(Ω,E)} arising from an equational presentation will not preserve coequalizers and hence be merely finitary.

That T_{Ω} is finitary will be proven in greater detail in §2.4.1 where the present case is treated as a corollary.

2.1.3 The Internal Language of a Monad

Not only does every signature give rise to a monad, a monad gives rise to a signature as well. In analogy to the situation with the simply typed λ-calculus and cartesian closed categories [45], this signature is called the internal language of the monad.

Internal Signatures

Definition 2.1.7 (Internal Signature) The internal signature of a finitary monad S = ⟨S, η, μ⟩ on Set is given by

Σ(S)(n) =^{def} ⋃_{card(X)=n} S(X)

The unit and multiplication of the monad give the infrastructure to talk about terms. Specifically, an operation f of arity n is given by an element f ∈ SX with card(X) = n. card(X) = n means that X is isomorphic to n copies of the oneelement set 1. A map 1 → Z represents exactly one element of Z, hence a map X → Z corresponds to an n-tuple of elements of Z under the following bijection:

Set(X, Z) ≅ Set(∐_{n} 1, Z) ≅ ∏_{n} Set(1, Z) ≅ ∏_{n} Z  (2.5)

Given t_{1}, …, t_{n} in Z, we use the notation [t_{1}, …, t_{n}] to denote the morphism from X to Z given by the previous bijection. If these n elements are operations themselves (i.e. Z = SY for some Y), the composition of the operation f with these operations is given by the image of f under the following two morphisms:

[figure: SX; S[t_{1}, …, t_{n}]; SSY; μ_{Y}; SY]

Alternatively, if we think of f, t_{1}, …, t_{n} as terms, this defines the substitution of the variables from X in f with the terms t_{1}, …, t_{n}. Hence, both the substitution of variables and the composition of operations are modelled by the same construction. By slight abuse of notation, we write f[f_{1}, …, f_{n}] for this substitution.

The Adjunction F −| U

The mappings of a signature Ω to the monad T_{Ω}, and of a monad S to its internal signature Σ(S) form an adjunction between the category of signatures and the category of finitary monads on Set. This adjunction between the category of syntactic and semantic presentations justifies our calling the semantics compositional: structuring operations like the coproduct are colimits, and a left adjoint functor preserves these. We will further elaborate on this point below.

We are now going to construct this adjunction. The category Sig has been defined above and the category Mon_{Fin}(Set) has been given in §1.3.6 on page 17, so we first need to extend the two maps to proper functors:

Definition 2.1.8 The functor F : Sig → Mon_{Fin}(Set) maps a signature Ω to the monad T_{Ω}, and a signature morphism σ : Ω → Σ to its lifting, the monad morphism σ̂ : T_{Ω} ⇒ T_{Σ}, which is defined pointwise for X ∈ Set as follows:

σ̂_{X}(e(t_{1}, …, t_{n})) =^{def} (σe)(σ̂_{X}(t_{1}), …, σ̂_{X}(t_{n}))
σ̂_{X}('x) =^{def} 'x

The functor U : Mon_{Fin}(Set) → Sig maps a finitary monad T = ⟨T, η, μ⟩ to its internal signature Σ(T), and a monad morphism σ : T ⇒ S to a signature morphism Uσ : Σ(T) → Σ(S) defined by

(Uσ)_{n}(f) =^{def} σ_{X}(f) for f ∈ T X with card(X) = n  (2.6)

It is easy to see that σ̂ is natural in X and a monad morphism. Uσ is a signature morphism by construction. We further have to show the functoriality of F and U, i.e. preservation of identity and composition. For F, this means that given a signature Ω, ˆ1_{Ω} = id_{T_{Ω}}, which is proven by showing ˆ1_{σ}(t) = t for all X ∈ Set and t ∈ T_{Ω}(X) by (an easy) structural induction on t, and that given two signature morphisms σ : Ω → Σ, τ : Σ → Σ′, τ̂.σ̂ = τ̂.σ, which is proven by showing that τ̂(σ̂(t)) = τ̂.σ(t) for all X ∈ Set and t ∈ T_{Ω}(X). For U, we have to show that U(id_{T}) = 1_{L(T)}, which follows just by definition (id_{T,X}(f) = f for all X ∈ Set, t ∈ T X in equation 2.6), and that U(τ.σ) = Uτ.Uσ, which again follows from equation 2.6.

Lemma 2.1.9 The two functors F and U form an adjunction F −| U : Sig → Mon_{Fin}(Set).

Proof. We show adjointness by constructing a unit υ_{Ω} : Ω → Σ(T_{Ω}) which is universal from Ω to U.

The unit is a signature morphism υ_{Ω} : Ω → UT_{Ω} which is defined as υ_{Ω,n}(ω) =^{def} ω('0, …, 'n − 1) (with the natural number n considered as the ordinal n = {0, …, n − 1}). Clearly υ is natural in Ω. To show that it is universal from Ω to U, we have to show that given any monad S = ⟨S, ζ, ξ⟩, and a signature morphism ν : Ω → Σ(S), there is a unique monad morphism !_{ν} : T_{Ω} ⇒ S such that

(U!_{ν}).υ_{Ω} = ν  (2.7)

which we define as follows (where ω ∈ Ω_{n}, hence ν(ω) ∈ SY with card(Y) = n):

!_{ν,X}(ω(t_{1}, …, t_{n})) =^{def} ξ_{X}.S[!_{ν,X}(t_{1}), …,!_{ν,X}(t_{n})](ν(ω))
!_{ν,X}('x) =^{def} ζ_{X}(x)

This definition is unique, since the second line makes !_{ν} satisfy equation 2.7, and the first line makes it a monad morphism. □

The counit of this adjunction consists of monad morphisms ε_{T} : T_{Σ(T)} ⇒ T. We can think of ε_{T} as evaluating terms built over the internal signature of T in T, and we say that the monad T admits an equation t_{1} = t_{2} if ε_{T} (t_{1}) = ε_{T} (t_{2}), leading to the concept of an internal language consisting of the internal signature and the set of equations admitted by the monad (see below). The counit is given by ε_{T} =!_{1_{T}}, or more explicitly:

ε_{T,X}(f(t_{1}, …, t_{n})) = μ_{X}.T [ε_{T,X}(t_{1}), …, ε_{T,X}(t_{n})](f)
ε_{T,X}('x) = η_{X}(x)

We will below need to refer to this being natural in T, so let us conclude by spelling out what this means: if we have a monad morphism σ : T ⇒ S, we have for all sets X:

[figure: T_{Σ(T)}X; ε_{T,X}; T X; T_{Σ(S)}X; Ûσ_{X}; ε_{S,X}; SX; σ_{X}]  (2.8)

The Internal Language at Work

We will below need the property that lifted morphisms commute with the substitution, i.e. given g : Y → Z, t_{1}, …, t_{n} ∈ T Y, and t ∈ T X with card(X) = n, then

g^{∗}(t[t_{1}, …, t_{n}]) = t[g^{∗}(t_{1}), …, g^{∗}(t_{n})]  (2.9)

This can be proven by an easy structural induction on the term t, but we can prove it directly and more elegantly in the internal signature. Equation 2.9 translates as

g^{∗}(μ_{Y} (T [f_{1}, …, f_{n}](t))) = μ_{Z}(T [g^{∗}t_{1}, …, g^{∗}t_{n}](t))

By applying g^{∗} to both sides of bijection 2.5 we get [g^{∗}t_{1}, …, g^{∗}t_{n}] = g^{∗}[t_{1}, …, t_{n}]. The proof then is given by diagram 2.10, where triangle (1) commutes because T is a functor preserving composition (recall that g^{∗} = T g), and square (2) commutes because μ is a natural transformation.

[figure: T X; T [t_{1}, …, t_{n}]; T T Y; μ_{Y}; T Y; (1)  (2); T Z; g^{∗∗}; μ_{Z}; T [g^{∗}t_{1}, …, g^{∗}t_{n}]; T Z; g^{∗}]  (2.10)

2.1.4 Equational Presentations

We have shown that every signature can be modelled by a finitary monad on the category Set. In fact, monads are more general and can be used to model equational presentations, which consist of a signature and a set of equations on the derived terms. We shall briefly review this material, but leave the reader to consult the standard references [69, 53, 52] for more details.

Definition 2.1.10 (Equations and Equational Presentations) Let Ω be a signature. A (finitary) Ω-equation is of the form X ⊢ t = s where X is a (finite) set and t, s ∈ T_{Ω}(X). An equational presentation A = (Ω, E) consists of a signature Ω and a set E of Ω-equations.

Given an equational presentation A = (Ω, E) one defines the relations ∼_{X} on the set of terms T_{Ω}(X) as the least equivalence relation generated by

\begin{matrix}(X ⊢ t = s) ∈ E & θ : X → T_{Ω}(Y) \\ \overline{θ}(t) ∼_{Y} \overline{θ}(s) \end{matrix} ; \begin{matrix}f ∈ Ω_{n} & t_{i} ∼_{X} u_{i} for i = 1, …, n \\ f(t_{1}, …, t_{n}) ∼_{X} f(u_{1}, …, u_{n}) \end{matrix}

where \overline{θ} is the homomorphic extension (see lemma 2.1.4) of θ, i.e. the function substituting θ(x) for each variable x in a term. The term algebra construction generalizes from signatures to equational presentations by mapping a set X to the term algebra T_{Ω}(X) quotiented by the equivalence relation ∼_{X}

T_{A}(X) = T_{Ω}(X)/ ∼_{X}

Lemma 2.1.11 Given an equational presentation A, the map X ↦ T_{A}(X) extends to a finitary monad T_{A} on the category Set.

Proof. Essentially the same as T_{Ω} proposition 2.1.6, except that one must ensure that provability is respected. See any of [69, 52, 53] for more details. □

An Ω-algebra A admits an Ω-equation X ⊢ t = s if for all σ : X → A_{S}, t and s evaluate to the same value in A: \overline{σ}(t) = \overline{σ}(s). For an equational presentation A = (Ω, E), an A-algebra is an Ω-algebra admitting all equations in E. We obtain the category of A-algebras, and the term algebra T_{A}(X) is free in all algebras over X (lemma 2.1.4).

We can further extend §2.1.3 to equational presentations:

Definition 2.1.12 (Internal Language) The internal language of a finitary monad T = ⟨T, η, μ⟩ on Set is the equational presentation

L(T) =^{def} (Σ(T), E(T))

where E(T) is the set of equations admitted by the monad T, defined as

E(T) =^{def} {X ⊢ t = s | X ∈ Set_{fp}, ε_{T,X}(t) = ε_{T,X}(s)}

One can then extend the adjunction from lemma 2.1.9 to an adjunction between the category of equational presentations, and finitary monads on Set, but we shall refrain here from doing so.

As a side remark for the interested reader, we note that Birkhoff’s theorem for equational presentations, which gives sufficient and necessary conditions for a set of Ω-algebras to be the set of algebras for an equational presentation finds a categorical counterpart in Beck’s theorem [52, pg. 147] (generalized in [39, Theorem 2.4]), which gives sufficient and necessary conditions for a category to be monadic over Set, but can be generalized to base categories other than Set.

2.2 Basic Principles of Enriched Monad Theory

!_{Categories} As has been pointed out at the beginning of this chapter, the main point of the construction of the semantics as a monad from a categorical point of view is that it has to be enriched over the category V of sets-with-structure. In this section, we will present the basic principles of the theoretical foundations of this work: the theory of enriched monads as developed by Kelly and Power in [39]. Readers who feel put off by the very first sentence of the following paragraph should probably skip this section and continue with §2.3, which is the application of this (rather abstract) theory, and will be understandable without this section.

This general theory deals with finitary monads on a locally finitely presentable V-category A (where V is lfp as a closed category [37], meaning that V_{0} is lfp as an ordinary category, the tensor product preserves finite presentability and the unit I is fp.) Further, A is small in the sense that there is a small set N (regarded as a discrete category) of objects representing isomorphism classes of fp objects of A, with the inclusions I : N ↪ A_{fp}, J : A_{fp} ↪ A.

In this abstract setting, a signature is a functor B : N → A, which for all b ∈ N gives the A-object of b-ary operations. For such a signature, one constructs a monad corresponding to the term algebra as the free monad on the left Kan extension of B along JI. More explicitly, F B is given as the colimit of the following sequence of functors:

F B =^{def} colim_{n<ω} S_{n}
S_{0} =^{def} JI
S_{n+1}(c) =^{def} c + ∑_{e∈N} A(e, S_{n}c) ⊗ Be  (2.11)

We can think of S_{n+1}(X) as the terms of depth n + 1, which are either variables, or constructed from operations of arity c applied to c-tuples of terms of depth n.

On the other hand, we can precompose every finitary monad with IJ to obtain a functor N → A; and there is an (ordinary) adjunction

[N , A] [figure: \underline{F}; ⊥; U] Mon_{Fin}(A)  (2.12)

The main result of [39] is that every finitary monad T on A can be presented, i.e. given as the coequalizer of σ and τ in the category of finitary monads over A:

[figure: F E; σ; τ; F B; T]

Under adjunction 2.12, this corresponds to two maps E [figure: σ′; τ′] UF B, which

for all objects c ∈ N gives a pair (σ′(Ec), τ′(Ec)) of terms from F Bc, which we can consider to be “equations” since T has to coequalize these maps.

Note how the tensor product between an object from V_{0} (on the left) and an object from A (on the right) in equation 2.11 generalizes bijection 2.5 (see §1.4.7 on page 34). This is the general notion of “c-tuples” (where c is an fp object): maps from finitely presentable objects, represented by the tensor. In our case, A will always be V, so the tensor is just the monoidal product, but this seem more like a matter of coincidental convenience rather than purposeful planning.

Further, the c-object of operations will be a relation (preorder etc.), the objects of which are the usual term-forming operations of arity c; and the edges of which will be the rewrite rules. In order to specify rewrites between composed operations (terms) and not only between basic operations, we use the equations to specify source and target of a rewrite rule. Let A = V = Pre, and consider the simple system

(Ω = {G_{1}, F_{2}}, R = {F (G(x), y) → G(y)}

then the corresponding signature would be given by the functor

B(I) =^{def} ({G}, ∅)
B(I + I) =^{def} ({F, s, t}, <) where s < t

with the equations F (G(x), y) = s(x, y) and G(y) = t(x, y), given by E(I + I) = ({A, B}, ∅) and maps σ′(A) = F (G(x), y), τ′(A) = x etc. We do not explicitly write down these equations; they will occur implicitly in the term constructions below. Further, the arity c above being non-discrete corresponds exactly to the variable rewrites. These should not occur for term-forming operations (like F and G above), which corresponds to the monad T being regular (in particular, being strongly finitary as opposed to just finitary).

It is interesting to see how the difference between an n-ary operation, and a term built over a set with n variables is modelled. The former always takes precisely n arguments, and will “use” each of them once; the latter may “discard” values substituted for a variable, or “use” a variable more than once.^{5} This difference is described by the left Kan extension along the inclusion J : N → A_{fp}; for example, consider a signature with just one binary operation F, corresponding to a functor B(2) = {F}, then the left Kan extension is given by

Lan_{J}B(c) =^{def} ∑_{e∈N} A_{fp}(e, c) ⊗ Be

which for the following sets gives us the following values:

\begin{matrix}∅ ↦ & ∅ \\ \{x\} ↦ & \{((x, x), F)\} \\ \{x, y\} ↦ & \{((x, x), F), ((y, y), F), ((x, y), F), ((y, x), F)\} \end{matrix}

These are more recognisable when written as terms, e.g. F(x, x). We will not use this in the following, but this observation allows a precise characterization of linear terms (terms which use each of the variables in their context exactly once): these are those for which in equation 2.11 the V_{0}-object A(e, S_{n}c) is an isomorphism (and this for all n < ω).

In the following section, we are going to give a particular syntactic construction for the case of V = (Pre, ×, I), and later review how this can be seen as a special instance of equation 2.11.

Following [39], we can assume that N and A_{fp} have the same objects. In our particular case, the finitely presentable objects of Rel and Pre are the relations or preorders with a finite number of objects, and in Grph, the graphs with a finite number of vertices and edges. Finitely presentable objects in Cat are categories with a finite number of objects, and a finite set M of morphisms in Mor_{X}, such that every morphism is given by identifying a finite number of sequence of morphisms from M (or equivalently, all free categories of locally finitely presentable objects in Grph closed under finite coequalizers in Cat) [15, pg. 3]. This awkward definition is one of the reasons that the technical details of the monad construction for preorders are much simpler for preorders than for categories; the correct modelling of contexts by finitely presentable objects in Cat requires careful attention to the morphisms of the contexts– something which is not very interesting from the term rewriting point of view.

5This is like the weakening or contraction rules in linear logic or sequent calculi.

To sum up this section, in order to put the general theory to work, we need to find a locally finitely presentable, symmetric monoidal closed category V (or a symmetric monoidal closed V along with an lfp V-category A). Then equation 2.11 gives us a general recipe for constructing terms, and the main result tells us how to treat equations. To instantiate this general theory for our use, we now have to find a suitable V and A.

2.3 Enriched Monads as a Semantics for Term Rewriting Systems

In §2.1, we have presented a uniform treatment of signatures and equational presentations by monads on Set. In the previous section, we have presented the generalization of the underlying category theory. We will now apply the previous section to term rewriting systems, obtaining a semantics for term rewriting systems. The theory of enriched monads as presented there provides the foundation of this work, a technical framework which by instantiating its parameters is adapted to our needs. It is not at all necessary to have understood (or even read) §2.2 to understand what follows; we will develop and motivate the semantics independently before showing how they are a specialization of the general theory. We will obtain a semantics which has several advantages:

• it has a solid mathematical foundation, and is easily adaptable;

• it is compositional (§2.5);

• it is useful (as will be demonstrated by the applications in Chapters 4 and 5).

The semantics in places differs from the literature definition 1.6.1: it has another way of dealing with one-step reductions, and admits a more general form of rewrite rule. In the important part, however, the two semantics coincide: a term reduces to another term in the new semantics in nil or many steps iff it does so in the old, as we will show in §2.3.5.

In order to instantiate the general theory, we first need to decide what exactly “sets with structure” should be. There is more than one possible choice here, each of which corresponds to a different aspect of term rewriting one might be interested in.

2.3.1 Sets with Structure

The usual semantics for term rewriting systems are abstract reduction systems, which are given by a set A and a family {→_{α}}_{α∈I} of binary relations →_{α}⊆ A×A on A (see definition 1.6.1 on page 45). When combining two term rewriting systems one does not distinguish between different reductions between the same two terms in the same term rewriting system at all, the index set just being I = {1, 2} (where →_{1} are the reductions in the first system, and →_{2} the reductions in the second system). Thus it seems also feasible to model the reduction by just one binary relation. For many-step reductions this relation has to be reflexive and transitive (i.e. a preorder).

Nat  =^{def} (Nat, RNat)
Nat =^{def} {Z_{0}, S_{1}, A_{2}}

             RNat  =^{def} \{ \begin{matrix}A(Z, 'x) & → & 'x, \\ A(S('x), 'y) & → & S(A('x, 'y))\} \end{matrix}

Table 2.1: The term rewriting system Nat

The question is really which reductions one wants to distinguish with the indexing set I. E.g. given the term rewriting system Nat in table 2.1, there are two reductions from A(S(A(Z, 'x)), 'y) to S(A('x, 'y)) (see diagram 2.13); and

                           A(S(A(Z, 'x)), 'y)
                [figure: A(S('x), 'y); S(A(A(Z, 'x), 'y))]
                             [figure: S(A('x, 'y))]

(2.13)

the question is whether we want these two reductions to “be the same”, and what this equality of reductions means in the first place. A satisfactory treatment of this question leads to an “algebra of reductions”. If we do not wish to distinguish between different reductions, we say we are dealing with unnamed reductions, otherwise we have named reductions.

In summary, depending on whether we want to investigate unnamed or named, and one-step or many-step reductions, our “sets with structure” can be binary relations, graphs, preorders or categories (see table 2.2).

Deciding between one-step and many-step reductions is easy, since modularity results as a rule are about combining many-step reductions, so the crucial question

Unnamed reductions  Named reductions
One-step Binary Relations  Graphs
Many-step Preorders  Categories

Table 2.2: “Sets with Structure”

is whether we are interested in named or unnamed reductions. The arguments in favour of unnamed reductions are that

• the construction is considerably simpler, and does not obscure the merits of the semantics by technical details which are uninteresting from the term rewriting point of view,

• and it is closer to the literature.

where the arguments for named reductions are that

• it is more general, yet still a faithful interpretation of the literature,

• it allows us to address a variety of new questions and problems,

• and semantically, preorders are categories anyway.

We will combine the advantages of both approaches by sidestepping the decision and proceeding as follows: we will first give a term construction for unnamed reductions, and show how to model the theory of a term rewriting system by a monad on the category Pre of preorders.

The semantic framework in the rest of this thesis will be monads on Cat however^{6}, as from the categorical point of view the restriction to preorders does not offer many advantages. Since preorders are categories anyway the proofs for Cat carry over to Pre. The full description of how to model the named manystep theory by a monad on Cat has been put into appendix A, where the reader can peruse the full details.

Instantiating the General Theory

!_{Categories}, In order to instantiate the general theory, we need to check whether the category of sets-with-structure satisfy the criteria of the theory; in particular, whether they form a locally finitely presentable, symmetric monoidal closed Vcategory. Fortunately, the category Pre is locally finitely presentable — the important point here is that there is the notion of “finite objects” (the fp objects), given by finite preorders — and it also is symmetric monoidal closed — there is the cartesian product of two preorders, and a function space between two preorders, the elements of which again form a preorder (by the pointwise order).

6To be precise, monads enriched over Cat with the usual cartesian structure. There is another closed monoidal structure on Cat we could enrich over, but it does not seem to offer any theoretical advantages in our setting; see page 180 for further discussion.

Further, bijection 2.5 generalizes to a bijection on preorders:

Pre(∐_{n} 1, X) ≅ ∏_{n} Pre(1, X)  (2.14)

since (t_{1}, …, t_{n}) ≤ (s_{1}, …, s_{n}) iff for i = 1, …, n, t_{i} ≤ s_{i}. Further, this bijection also holds for categories (as will be needed in the appendix)

Cat(∐_{n} 1, C) ≅ ∏_{n} Cat(1, C)  (2.15)

since a functor 1 → C is just an object of C, and giving a natural transformation on the left amounts to giving n morphisms in C, which is exactly a morphism in the product category on the right.

2.3.2 Arities, Contexts and Rewrite Rules

The two main principles of the monad semantics can be summed up as

• terms are composed operations;

• arities are contexts, given by the finitely presentable objects of the base category.

In order to be able to compose operations in a meaningful way, we need to handle arities appropriately. In the equational case, arities are natural numbers. Here, the fp objects of Pre are finite preorders. This has interesting ramifications: if contexts and arities are to be finite preorders, they do not have to be discrete. In other words, we should be able to assume more about variables than merely their existence. For if a context X = {x, y, z} of variables is just a way of modelling the assumption that there are three entities x, y and z which we can build terms with, then to model reductions there should be a way of assuming there are reductions between these. For example, in the context X above a rewrite α : x → y would mean that whatever we instantiate x and y with, there has to be a rewrite between the two of them. Consequently, we arrive at the concept of a generalized rewrite rule (Y ⊢ l → r) where Y is a finite preorder. The “usual” case — sets of variables without a reduction structure — will be retained as a special case of the generalized concept.

Definition 2.3.1 (Generalized Rewrite Rule) A generalized rewrite rule in a signature Ω is given by a triple (X, l, r), written as (X ⊢ l → r), where X = (X_{0}, ≥) is a preorder, and l, r ∈ T_{Ω}(X_{0}). X is called the context, l the left-hand side, and r the right-hand side of the rule.

If the preorder X is discrete, the rewrite rule is called ordinary; if the preorder X is finite, it is called finitary.

If x ≥ y in the context X, we say there is a variable rewrite from x to y.

It should be pointed out that this definition is a conservative extension of definition 1.6.1 in the sense that the special case of ordinary rewrite rules are precisely the rewrite rules from definition 1.6.1. In the following, we always mean generalized rewrite rule when writing rewrite rule.

With generalized rewrite rules, it is now possible to encode the requirement that two (or more variables) have a common reduct directly into the rewrite rules. For example, given the preorder X = (X_{0}, ≤) as a context, which has objects X_{0} =^{def} {x, y, z}, ordered as x ≤ z, y ≤ z, then the rewrite rule (X ⊢ F('x, 'y) → G('z)) means that only if we can instantiate x and y with terms t_{1} and t_{2} which have common reduct t_{3} (which is the instantiation of z), then there is a reduction from F(t_{1}, t_{2}) to G(t_{3}).

Further, a rewrite rule (X ⊢ l → r) is called

• variable-introducing if var(r) ⊈ var(l) (there are variables on the right hand side which do not occur on the left);

• collapsing if ∃x ∈ X. r = 'x (the right hand side is a variable);

• expanding if ∃x ∈ X. l = 'x (the left hand side is a variable).

We can now define term rewriting systems:

Definition 2.3.2 (Term Rewriting System) A term rewriting system Θ = (Ω, R) is given by a signature Ω and a set of rewrite rules R for Ω.

A term rewriting system Θ = (Ω, R) is finitary if Ω is finitary and all rules in R are finitary. Since we only deal with finitary operations, we restrict ourselves to finitary rewrite rules as well; hence, in the following, when we say rewrite rule we mean a finitary rewrite rule.

Normally, one restricts term rewriting systems not to contain expanding or variable-introducing rules [41]. We do not do this here, since none of the following constructions depend on it. By carefully observing where these conditions are needed in the proofs below, we shall seek to generalize as far as possible to systems not satisfying these conditions. One of these generalizations will depend on the concept of bounded variables, which are variables which themselves need not appear on the left-hand side of a rewrite rule, but which rewrite from something occuring there:

Definition 2.3.3 (Bounded Variables) For a rewrite rule (X ⊢ l → r), a variable y ∈ X is bounded if there is x ∈ var(l) s.t. x ≥ y.

A rewrite rule (X ⊢ l → r) introduces bounded variables if if it is variableintroducing, but all variables are bounded; a rule for which there is x ∈ X which is not bounded is said to introduce unbounded variables.

Note that a unbounded variable necessarily will not occur on the left-hand side of a rule, because for all x ∈ var(l), x ≥ x.

We will now construct a free or term algebra for a term rewriting system, which we will call the term reduction algebra. This construction will then be extended to a monad on Pre.

2.3.3 The Term Reduction Algebra and the Monad T_{Θ}

In definition 1.6.1 on page 45, the rewriting relation is obtained as a sequence of single step rewrites, which are defined to be the rewrite rules with the variables substituted, placed in a context; i.e. if l → r is a rewrite, and σ is a substitution, then C[σ(l)] → C[σ(r)] is a single rewrite step, where σ(t) is the result of applying substitution σ to term t.

We shall here do very much the same, but without explicitly defining contexts, rather relying on an inductive definition. The term reduction algebra on a preorder X = (X_{0}, ≽) will be the smallest preorder on the terms T_{Ω}(X_{0}) formed by the following rules:

• All variable rewrites (rule [Var] below) are reductions;

• Operations have to preserve reductions [Pre]. Larger contexts are built by repeated applications of this rule;

• Instantiation of a rewrite rule [Inst]: if we can assign a term to each object in the context, such that for each variable rewrite in the context there is a reduction between the two corresponding terms, then the instantiated left-hand side of the rule reduces to the instantiated right-hand side of the rule.

Definition 2.3.4 (Term Reduction Algebra) Given a term rewriting system Θ = (Ω, R) and a preorder X = (X_{0}, ≽), the term reduction algebra on X is the smallest preorder T_{Θ}(X) = (T_{Ω}(X_{0}), ≥) on the terms over X_{0} satisfying the implications in table 2.3.

[Var] {x ≽ y \atop 'x ≥ 'y} x, y ∈ X_{0}

[Pre] {t_{1} ≥ s_{1}, …, t_{n} ≥ s_{n} \atop ω(t_{1}, …, t_{n}) ≥ ω(s_{1}, …, s_{n})} ω ∈ Ω_{n}

[Inst] \begin{matrix}ρ = ((Y_{0}, ≽) ⊢ l → r) ∈ R, Y_{0} = \{y_{1}, …, y_{n}\} \\ ∀i = 1, …, n ∀j = 1, … n. y_{i} ≽ y_{j} ⇒ t_{i} ≥ t_{j} \end{matrix} ; l[t_{1}, …, t_{n}] ≥ r[t_{1}, …, t_{n}] t_{1}, …, t_{n} ∈ T_{Ω}(X_{0})

Table 2.3: Definition of the Term Reduction Algebra.

Note that we do not need an explicit rule for the formation of sequences, since every preorder has to be transitive anyway.

Example 2.3.5 Given the term rewriting system Nat and the preorder Z = (Z_{0}, ≤) with Z_{0} =^{def} {a, …, z}, ordered lexicographically (a ≤ b etc.) then the term reduction algebra TNat(Z) has the terms T_{Nat}(Z_{0}), ordered as follows:

A(Z, t) ≥ t,

                      A(S(t), s) ≥ S(A(t, s))

So for example, we have A(S(S(Z)), 'a) ≥ S(S(A(Z, 'a))) ≥ S(S('a)), or
A(S('a), 'b) ≥ S(A('a, 'b)) ≥ S(A('a, 'c)), or S(S('e)) ≥ S(S('f)), but

of course not S('a) ≥ 'a. □

Example 2.3.6 This example involves a generalized rewrite rule. Given the term rewriting system Ref = (∅, RNat) which has an empty signature and only one rule

RNat =^{def} {(({x, y}, x ≤ y) ⊢ 'y → 'x)}

Then for a preorder X = (X_{0}, ≽), TRef(X) only has variables 'x for x ∈ X as terms, but the reduction order ≥ is the reflexive closure of ≽; and since it is also a preorder, which is transitive and reflexive, it is in fact the equivalence closure of X. □

Structural Induction

To show that a predicate P holds for all reductions in T_{Θ}(X), we use a structural induction, not unlike the structural induction on terms in proposition 2.1.3.

Proposition 2.3.7 Given a preorder X = (X_{0}, ≥) and a binary relation P_{X} ⊆ T_{Θ}(X) × T_{Θ}(X). If for all s, t ∈ T_{Θ}(X), s ≥ t implies (s, t) ∈ P_{X} we say that P_{X} holds for all reductions in T_{Θ}(X). This is the case if P_{X} is a preorder and satisfies the following three implications:

{x ≥ y \atop ('x, 'y) ∈ P_{X}}

{∀i = 1, …, n.(s_{i}, t_{i}) ∈ P_{X} \atop (ω(t_{1}, …, t_{n}), ω(s_{1}, …, s_{n})) ∈ P_{X}} ω ∈ Ω_{n}

{∀i, j.y_{i} ≥ y_{j} ⇒ (t_{i}, t_{j}) ∈ P_{X} \atop (l[t_{1}, …, t_{n}], r[t_{1}, …, t_{n}]) ∈ P_{X}} ((Y_{0}, ≥) ⊢ l → r) ∈ R, Y_{0} = \{y_{1}, …, y_{n}\}

Proof. This is proven by reducing it to well-founded induction. We define a partial map size : T_{Θ}(X) × T_{Θ}(X) ⇀ ℕ, which for s, t ∈ T_{Θ}(X) is only defined if we can derive s ≥ t, and then gives the number of times we have to apply one of the rules [Pre] and [Inst], starting with the variable rewrites (rule [Var]) which have size 0, or the reflexive closure (i.e. s = t). We define a predicate q on ℕ:

q(n) ⇔ (∀s, t ∈ T_{Ω}(X). size(s, t) ≤ n ∧ s ≥ t ⇒ (s, t) ∈ P_{X})

and show that the three implications above give rise to a well-founded induction by which we can show that for all n ∈ ℕ, q(n). We conclude that for all s, t ∈ T_{Ω}(X) if s ≥ t then (s, t) ∈ P_{X}. The appendix contains a more detailed proof of the general construction for categories (proposition A.1.5 on page 177). □

We are now going to define the monad T_{Θ}, starting with its action, the endofunctor T_{Θ} : Pre → Pre. Its object function will map X to T_{Θ}(X), and on the morphisms, it will map a preorder morphism to the lifting of the underlying function on the term algebras.

The Action of the Monad Lemma 2.3.8 The mapping of a preorder X to the term reduction algebra T_{Θ}(X) extends to a functor T_{Θ}, by mapping a preorder morphism f : (X_{0}, ≥) → (Y_{0}, ≥) to its lifting f^{∗} : T_{Ω}(X_{0}) → T_{Ω}(Y_{0}) from definition 2.1.5.

Proof. We have to show that T_{Θ} is indeed a functor, in particular that f^{∗} is a preorder morphism, and that the lifting process preserves the pointwise order on morphisms (making T_{Θ} a Pre-enriched functor).

To show that f^{∗} is a preorder morphism we have to show

t ≥ s ⇒ f^{∗}t ≥ f^{∗}s  (2.16)

This is proven by structural induction on the reduction f^{∗}t ≥ f^{∗}s:

1. If x ≥ y in X, then fx ≥ fy in Y, and hence f^{∗}('x) ≥ f^{∗}('y).

2. If (Z ⊢ l → r) ∈ R, and l[t_{1}, …, t_{n}] ≥ r[t_{1}, …, t_{n}], then we can assume that t_{i} ≥ t_{j} ⇒ f^{∗}t_{i} ≥ f^{∗}t_{j}, hence l[f^{∗}t_{1}, …, f^{∗}t_{n}] ≥ r[f^{∗}t_{1}, …, f^{∗}t_{n}], and using equations 2.9:

f^{∗}(l[t_{1}, …, t_{n}]) = l[f^{∗}t_{1}, …, f^{∗}t_{n}]
≥ r[f^{∗}t_{1}, …, f^{∗}t_{n}]
= f^{∗}(r[t_{1}, …, t_{n}])

3. Finally, for e(t_{1}, …, t_{n}) ≥ e(s_{1}, …, s_{n}) where t_{i} ≥ s_{i} (for i = 1, …, n),

we can assume that f^{∗}t_{i} ≥ f^{∗}s_{i}, then

f^{∗}(e(t_{1}, …, t_{n})) = e(f^{∗}t_{1}, …, f^{∗}t_{n})
≥ e(f^{∗}s_{1}, …, f^{∗}s_{n})
= f^{∗}(e(s_{1}, …, s_{n}))

where the equations hold by definition of f^{∗}. Preorder morphisms are ordered pointwise: for f, g : X → Y, f ≥ g iff for

all x ∈ X_{0}, fx ≥ gx. We have to show that the lifting preserves this order, and hence gives rise to a Pre-enriched functor:

∀x ∈ X_{0}.fx ≥ gx ⇒ ∀t ∈ T_{Ω}(X_{0}).f^{∗}t ≥ g^{∗}t  (2.17)

This is proven by structural induction on the term t; the induction assumption is 'x ∈ T_{Ω}(X_{0}), then f^{∗}('x) = 'fx ≥ 'gx = g^{∗}('x); for the induction step, let e(t_{1}, …, t_{n}) ∈ T_{Ω}(X_{0}) and assume f^{∗}(t_{i}) ≥ g^{∗}(t_{i}), then

f^{∗}(e(t_{1}, …, t_{n})) = e(f^{∗}t_{1}, …, f^{∗}t_{n}) ≥ e(g^{∗}t_{1}, …, g^{∗}t_{n}) = g^{∗}(e(t_{1}, …, t_{n})) The lifting preserves identities and composition because of the functoriality of T_{Ω}, and hence definition 2.1.5 is correct. □

Unit and Multiplication

The unit and multiplication of the monad are given by the unit and multiplication of the monad T_{Ω} from proposition 2.1.6. We have to show that they are preorder morphisms (i.e. preserve the order); naturality has been shown above.

The unit is trivially a preorder morphism by rule [Var]. That the multiplication is a preorder morphism is proven by structural induction; the crucial step is to show that μ_{X_{0}}(l[t_{1}, …, t_{n}]) ≥ μ_{X_{0}}(r[t_{1}, …, t_{n}]) for a rule ((Z_{0}, ≽) ⊢ l → r) ∈ R with card(Z_{0}) = n, and t_{i} ∈ T_{Ω}(T_{Ω}(X_{0})) with t_{i} ≥ t_{j} if z_{i} ≽ z_{j}. We first show by induction on the term that for all s ∈ T_{Ω}(Z_{0})

μ_{X_{0}}(s[t_{1}, …, t_{n}]) = s[μ_{X_{0}}(t_{1}), …, μ_{X_{0}}(t_{n})]  (2.18)

Since by rule [Inst], l[t_{1}, …, t_{n}] ≥ r[t_{1}, …, t_{n}], we now have to show that μ_{X_{0}}(l[t_{1}, …, t_{n}]) ≥ μ_{X_{0}}(r[t_{1}, …, t_{n}]), which easily follows from equation 2.18 and rule [Inst].

The monad laws will hold since they just carry over from the underlying morphisms. Hence, we have the main proposition of this section: Proposition 2.3.9 Every term rewriting system Θ = (Ω, R) gives rise to a monad T_{Θ} =^{def} ⟨T_{Θ}, η, μ⟩ on the category Pre, enriched over Pre.

We will now explore how proposition 2.3.9 works the other way around: how we can consider a monad on Pre as a term rewriting system by considering its internal language, generalizing §2.1.3. We will close the section by relating the term reduction algebra defined above to the “traditional” definition 1.6.1.

2.3.4 The Internal Language of a Monad

Given a monad T = ⟨T, η, μ⟩ on Pre, the object functions of its components yield an ordinary monad on Set, called the underlying object monad of T and denoted T_{0} =^{def} ⟨T_{Obj}, η_{Obj}, μ_{Obj}⟩. The internal signature of this monad yields a term language about the objects of the monad T. The counit of the adjunction from lemma 2.1.9 gives us, for any preorder X = (X_{0}, ≽), a function ε_{T_{0},X_{0}} : T_{Σ(T_{0})}(X_{0}) → T X_{0} which lets us evaluate terms built in the internal signature in the monad T. The internal language of T should now give us all rewrites admitted by T, much like the internal language of a monad on Set are all equations admitted by the monad (definition 2.1.12).

Definition 2.3.10 (Internal Language) The internal language of a finitary monad T = ⟨T, η, μ⟩ on Pre is given by

L(T) =^{def} (Σ(T_{0}), R(T))

where Σ(T_{0}) is the internal signature (definition 2.1.7) of the underlying monad T_{0} on Set, and R(T) is the set of rewrite rules admitted by the monad T defined as follows:

R(T) =^{def} {(X ⊢ l → r) | X ∈ Pre_{fp}, T X = (Y_{0}, ≥), ε_{T_{0},X}(l) ≥ ε_{T_{0},X}(r)}

Note that it is sufficient to define the internal language over the finitely presentable objects Pre_{fp}, since all other objects are given as a directed colimit of fp objects, and finitary functors preserve directed colimits.

We will now consider two examples for the internal language, in a slightly informal manner.

Example 2.3.11 As a very simple example, consider the internal language of the identity monad 1_{Pre} = ⟨1_{Pre}, 1, 1⟩ which just maps a preorder to itself.

Then Σ(1_{Pre})_{n} = {x | x ∈ X, card(X) = n} or slightly rephrased Σ(1_{Pre})_{n} = {x_{i} | x_{i} ∈ {x_{1}, …, x_{n}}}. The terms we can build in the internal language are e.g. t = x_{i}(x_{1}, …, x_{n}), which the evaluation takes to ε(t) = x_{i}. □

Example 2.3.12 The monad B = ⟨B, η_{B}, μ_{B}⟩ freely adjoins an initial element ⊥ to the argument preorder. Its action is defined as

B(X, ≥) =^{def} (X + {⊥}, ≽)

where the order is defined as x ≥ y ⇒ x ≽ y, and for all x ∈ X, ⊥ ≽ x. On morphisms, f : X → Y is mapped to f^{∗} : B(X) → B(Y) which takes x ∈ X to f(x) ∈ Y, and ⊥ to ⊥.

The unit η_{B,X} : X → B(X) embeds X into B(X), whereas μ_{B,X} : B(B(X)) → B(X) identifies the two distinct elements ⊥ added by the two applications of B.

The internal language of this monad is given as follows: its signature has

Σ(B)_{n} = {⊥, x_{1}, …, x_{n}}

The terms are evaluated as follows

ε_{B}(x_{i}(t_{1}, …, t_{n})) = ε_{B}(t_{i})
ε_{B}(⊥(t_{1}, …, t_{n})) = ⊥

The rewrites of the internal language are essentially rewrites ⊥ → t for all terms t, and l → r if l ≥ r in X, so we can think of this monad as having, for any n ∈ ℕ, an n-ary operation ⊥, and rewrites ⊥(x_{1}, …, x_{n}) → x_{i}. The substitution here “collapses” the ⊥, so e.g. μ_{B}(⊥('⊥, ''x)) = ⊥('x). □

2.3.5 Comparison with the Literature Definition 1.6.1

A natural question to ask is how the term reduction algebra T_{Θ}(X) is related to the many-step reduction relation ↠_{R} from definition 1.6.1 on page 45. It is fairly obvious that if X is discrete, the relation ≥ on the terms is the same as the many-step reduction ↠_{R}. In fact, T_{Θ}(X) is given by →_{R} plus the variable rewrites given by X, closed under congruence, and formally stated this will be the main result of this section. The constructions and results of this section are only needed when relating our definitions to definition 1.6.1 (for example, to show that our definition of confluence below coincides with the one found in the literature), and this will not be the case again until §4.1.3.

In the following, consider an ordinary term rewriting system Θ = (Ω, R), and both T_{Θ}(X) = (T_{Ω}(X), ≥) and →_{R}⊆ T_{Ω}(X) × T_{Ω}(X) for an arbitrary but fixed relation X = (X_{0}, <).^{7} We are first going to define the congruence closure of <, followed by the main proposition of this section:

Definition 2.3.13 (Congruence Closure of Variable Rewrites) Given a preorder X = (X_{0}, <), the congruence closure →_{X} of the variable rewrites in X is the smallest preorder on T_{Ω}(X) such that

∀x, y ∈ X_{0}.x < y ⇒ 'x →_{X} 'y
ω ∈ Ω_{n}, s_{i} →_{X} t_{i} for i = 1, …, n ⇒ ω(s_{1}, …, s_{n}) →_{X} ω(t_{1}, …, t_{n})

Proposition 2.3.14 All reductions in the reduction algebra are given as a sequence of reductions from either the one-step reduction generated by the rules, or from variable rewrites closed under congruence:

≥ = (→_{R} ∪ →_{X})^{∗}

Proof. We are going to show the equality by inclusion in both directions. For notational convenience, let S =^{def} →_{R} ∪ →_{X}.

1. s ≥ t ⇒ s S^{∗} t The proof proceeds by structural induction over s ≥ t. If s ≥ t by rule [Var], then s →_{X} t, and if s ≥ t by rule [Inst], then s →_{R} t. [Pre] offers a slight complication, since if there are terms s_{1}, t_{1}, …, s_{n}, t_{n}, ∈ T_{Ω}(X) such that s_{i} ≥ t_{i}, we can only assume that for all i = 1, …, n, either s_{i} →_{X} t_{i} or s_{i} →_{R} t_{i}, but for different values of i, different of the two alternatives may hold, and we can not uniformly apply the induction assumption. However, we can decompose a rewrite ω(s_{1}, …, s_{n}) ≥ ω(t_{1}, …, t_{n}) into n rewrites

7For the latter, following definition 1.6.1 to the letter, X needs to be infinite. This seems to be a convenience in the definition, made such that one does not run out of fresh variables when one wants to rename the variables of two terms apart.

ω(s_{1}, s_{2}, …, s_{n}) ≥ ω(t_{1}, s_{2}, …, s_{n})
≥ ω(t_{1}, t_{2}, …, s_{n})
… ≥ ω(t_{1}, t_{2}, …, t_{n})  (2.19)

Then for i = 1, …, n, we can assume that since s_{i} ≥ t_{i}, s_{i} S^{∗} t_{i}. Since both →_{X} and →_{R} are closed under application of operations, we have ω(…, s_{i}, …) S^{∗} ω(…, t_{i}, …) for i = 1, …, n, and by transitivity of S^{∗} the composition of the n rewrites in equation 2.19 is in S^{∗}.

2. s S^{∗} t ⇒ s ≥ t The proof proceeds by a case distinction. If s →_{X} t, then s ≥ t by rules [Var] and [Pre], if s →_{R} t, then s ≥ t by rules [Inst] and [Pre], and if sS^{∗}t then s ≥ t by transitivity and reflexivity of ≥.

□

This proposition has an easy corollary which will be useful later on:

Corollary 2.3.15 If the relation X is discrete, then ↠_{R} = T_{Θ}(X).

2.4 Properties of the Monad T_{Θ}

Monads are a generalisation of universal algebra, in which structures are defined by operations and equations. Term rewriting systems do not have equations, hence monads are a more general concept, and not every monad on Pre is generated from a term rewriting system. In this section, we will try to axiomatize those properties of monads on Pre which are given by term rewriting systems. We try to keep these properties as weak as possible — the more general these properties are, the more generalisations we can later make.

The properties in question are finitariness (corresponding to operations of finite arity), and preservation of coequalizers (corresponding to absence of equations), which together are strong finitariness; and further a newly introduced property called regularity which corresponds to free term generation and essentially means that the monad’s substitution is well-behaved, and that the monad does not confuse variables with other terms.

We close with a section on non-expandingness, which is not a property characterizing term rewriting systems, but a property of term rewriting systems. We introduce this property here, since the main results of chapters 4 and 5 only hold for non-expanding term rewriting systems (and monads).

2.4.1 Finitariness

In a locally finitely presentable category (as Set or Pre) every object can be given as the directed (or filtered) colimit of the finitely presentable objects. Hence, if the action of a monad preserves this particular kind of colimits, its action on any object will be determined by its action on the finitely presentable objects; such a monad is called finitary (see page 56 above). If moreover the monad preserves weakly filtered colimits, it is called strongly finitary, and these are precisely the monads corresponding to finitary term rewriting systems.

We are now going to show that the monad T_{Θ} arising from a finitary term rewriting system Θ is strongly finitary. We will separately show that T_{Θ} preserves filtered colimits and coequalizers, and use lemma 1.3.7. The rather technical proofs of the two main lemmas have been relegated into the appendix, where they are shown for the more general case of named reductions.

Lemma 2.4.1 Given a term rewriting system Θ = (Ω, R), the monad T_{Θ} is strongly finitary.

Proof. By specialising lemma A.2.2 (page 187f), the monad T_{Θ} is finitary, and by specialising lemma A.2.3 (page 190f), the functor T_{Θ} preserves coequalizers. Hence, by lemma 1.3.7, T_{Θ} is strongly finitary. □

2.4.2 Regular Monads

Regularity is concerned with a couple of additional conditions on the unit and multiplication of the monad, corresponding to conditions on the variables and the substitution. These conditions can be described as follows:

• Different objects of X should give rise to different variables;

• Lifted morphisms should not identify variables and terms: given a morphism f : X → Y, and y ∈ T_{Θ}(Y), x ∈ T_{Ω}(X) such that f^{∗}(x) = 'y, there is x_{0} ∈ T_{Θ}(X) such that x = 'x_{0} and y = f(x_{0}) (corresponding to the η being regular as defined below). In other words, if a lifted morphism f^{∗} and the unit η_{X} agree on a term, than this term has to be variable which moreover is given by an object in the image of the unlifted morphism f.

• In the same vein, lifting should be stable under substitution: for f : X → Y as above, given t ∈ T_{Θ}(X), s ∈ T_{Θ}(T_{Θ}(Y)) such that f^{∗}(t) = μ_{Y} (s), there is t_{0} ∈ T_{Θ}(T_{Θ}(X)) such that t = μ_{X}(t_{0}) and s = f^{∗∗}(t_{0}).

These should hold in arbitrary contexts as well. This means that the action of the monad (which gives the context-building operations) should preserve these properties.

Further, we will define the properties on the level of monads on Cat; as mentioned above, these will be the semantic framework in the remainder of this thesis, so it is worthwhile to give the following definitions on a more general level from the start. This in particular means that the last two conditions also have to hold for the morphisms. In fact, the two last conditions above look fairly similar, and since both the unit and the multiplication are of course natural transformations, we can formulate them in terms of a natural transformations α:

Definition 2.4.2 (Regular Natural Transformations) Given two functors T, S : Cat → Cat, a natural transformation α : T ⇒ S is called regular if given the naturality square

[figure: T X; α_{X}; SX; T Y; T f; α_{Y}; SY; Sf]

the following two hold:^{8}

∀x ∈ SX , y ∈ T Y. Sf(x) = α_{Y}(y) ⇒ ∃x_{0} ∈ T X . x = α_{X} (x_{0}) ∧ y = T f(x_{0})

∀r : x → x′ in SX , s : y → y′ in T Y. Sf(r) = α_{Y}(s) ⇒ ∃r_{0} : x_{0} → x′_{0} in T X . r = α_{X} (r_{0}) ∧ s = T f(r_{0})

When specializing definition 2.4.2 to preorders, we of course do not have a regular transformation, we merely have two preorder morphisms f, g such that f ≤ g in the pointwise order. This simplifies the second condition above. This also allows us to conveniently express the requirement that the action preserves “regularity”: it means that the action preserves regularity of natural transformations.

Definition 2.4.3 (Regular Monads) A monad T = ⟨T, η, μ⟩ on Cat is regular if it satisfies the following conditions:

8Note that this does not quite mean the naturality square is a pullback-square, since we do not require x_{0} and r_{0} to be unique.

(i) T is strongly finitary;

(ii) η and μ are regular in the sense of definition 2.4.2, and T preserves regularity of natural transformations;

(iii) For all categories X, η_{X} is monic in Cat (i.e. injective on the objects and faithful), and T_{Θ} preserves monicness.

Proposition 2.4.4 Given a term rewriting system Θ, the monad T_{Θ} is regular.

Proof. In lemma 2.4.1, it was shown that T_{Θ} is strongly finitary. That η_{X} is monic follows from the free generation of the term reduction algebra (no terms are identified). Preservation of monicness is shown by an easy structural induction (given F : X → Y which is monic, show that F^{∗} : T_{Θ}(X) → T_{Θ}(Y) is monic by showing that F^{∗}(s) = F^{∗}(t) implies s = t). That η_{X} is regular, and that T_{Θ} preserves regularity follows from the definition of the lifting.

Regularity of μ is proven as follows: on the objects, given s ∈ T_{Ω}(T_{Ω}(Y)), t ∈ T_{Ω}(X) and f : X → Y s.t. f^{∗}(s) = μ_{X}(t), we construct a term t_{0} ∈ T_{Ω}(T_{Ω}(X)) by t_{0} =^{def} σ(s, t) where σ : T_{Ω}(T_{Ω}(Y)) × T_{Ω}(X) ⇀ T_{Ω}(T_{Ω}(X)) is a partial function, defined as follows:

σ(e(s_{1}, …, s_{n}), e(t_{1}, …, t_{n})) =^{def} e(σ(s_{1}, t_{1}), …, σ(s_{n}, t_{n}))
σ('x, t) =^{def} 't

σ(s, t) is undefined if f^{∗}(s) ≠ μ_{X}(t). On the morphisms, a similar proof applies. □

We have separated strong finitariness from the other three conditions, because the construction of the coproduct of two monads in §3.1 works for any strongly finitary (not necessarily regular) monad. It is only for the modularity proofs that we need the other conditions.

Incidentally, monads in which every component of the unit is a monomorphism are called computational monads by Moggi [61], although the monads he considers are in general not finitary. Further, if one strengthens the requirements of definition 2.4.2 to the naturality square being a pullback square, such a natural transformation is called cartesian. Carboni and Johnstone [7] show that if the unit and multiplication of a monad are cartesian, and T preserves wide pullbacks^{9}, such monads on Set are exactly those given by finite operations and strongly regular equations, where an equation is strongly regular if the same variables occur in each side of the equations, in the same order and without repetition.

9Also called fibre products— pullbacks of more than two morphism with the same source.

2.4.3 Expanding and Collapsing Monads

Recall that a rewrite rule (X ⊢ l → r) is expanding if l = 'x for some x ∈ X. For the monad T_{Θ}, this means that there are is a rewrite s ≥ t in T_{Θ}(X) where s is in the image of the unit (s = 'x), and t not (otherwise, it would just be a variable rewrite). We now want to define this property for any monad T on Pre, and even more general, on Cat, with Pre just being a special case.

Definition 2.4.5 (Expanding Functors and Monads) A functor F : X → Y is expanding (at x ∈ X), if there is a morphism α : F x → y′ in Y s.t. for all morphisms β : x → y in X, F β ≠ α.

A monad T = ⟨T, η, μ⟩ on Cat is expanding if there is a component η_{X} : X → T X of the unit which is expanding, and the action preserves expandingness for injective functors, i.e. if F : X → Y is injective and expanding, then so is T F.

Obviously, a functor is non-expanding if it is non-expanding at all x ∈ X; i.e. for all x ∈ X and α : F x → y, there is β : x → x′ such that F β = α. Further, a monad is non-expanding if all components of the unit are non-expanding, and the action preserves non-expanding functors. The dual notion of expanding is collapsing (although for reasons explained on page 84 below, the action of the monad is not required to preserve collapsingness or non-collapsingness respectively).

Definition 2.4.6 (Collapsing Functors and Monads) A functor F : X → Y is collapsing (at x ∈ X), if F^{op} : X^{op} → Y^{op} is expanding (at x). A monad T = ⟨T, η, μ⟩ on Cat is collapsing if all components η_{X} : X → T X of the unit are collapsing.

The specialization of definitions 2.4.5 and 2.4.6 to preorders is straightforward: a preorder morphism f is non-expanding if considered as a functor it is non-expanding; and a monad T = ⟨T, η, μ⟩ on Pre is non-expanding if all components η_{X} of the unit are non-expanding, and the action preserves non-expanding preorder morphisms.

It now remains to show that a non-expanding term rewriting system gives rise to a non-expanding monad. Clearly, if the term rewriting system is nonexpanding, so is the unit of the monad, but slightly surprisingly the action of the monad fails to preserve non-expandingness if the term rewriting system introduces unbounded variables (see definition 2.3.3). As a counterexample, consider the monad B from example 2.3.12 from page 75. Although the unit η_{B} is nonexpanding, the action of B does not preserve non-expandingness: consider the unique preorder morphism ! : 0 → 1 from the empty preorder to the one-object preorder, and let x ∈ 1 be that object, then B(!) : B(0) → B(1) maps the only object ⊥ ∈ B(0) to ⊥ ∈ B(1), but there is a morphism ⊥ → x in B(1), hence B(!) is expanding, whereas ! is not.

Before we show that a non-expanding system gives rise to a non-expanding monad, we need a bit of notation. A partial function from X to Y is written as X ⇀ Y. A partial function between pre-orders is a partial function between the underlying sets which respects the order. Given such a partial function f : X ⇀ Y, its lifting to a partial function f^{∗} : T_{Ω}(X) ⇀ T_{Ω}(Y) is defined analogous to definition 2.1.5; f^{∗} is defined at t ∈ T_{Ω}(X) iff f is defined at all x ∈ var(t). With this machinery, we can prove the following technical lemma, which essentially says that the lifting of injective functions commutes with substitution— given a term l and a substitution σ such that σ applied to l lies in the image of a the lifting of an injective function f, then σ filters through the lifting of f.

Lemma 2.4.7 Given a term rewriting system Θ = (Ω, R) and a rule ρ = (Z ⊢ l → r) in R which does not introduce unbounded variables, an injective function f : X → Y, a term t ∈ T_{Ω}(X) and a preorder morphism σ : Z → T_{Ω}(Y) such that f^{∗}(t) = μ_{Y} (σ^{∗}(l)), which is non-expanding for all z ∈ Z (i.e. if f^{∗}(t) = σ(z) and z ≥ u in Z, then there is s ∈ T_{Ω}(X) s.t. t ≥ s in T_{Θ}(X) and f^{∗}(s) = σ(u)).

Then there is a preorder morphism τ : Z → T_{Ω}(X) such that

μ_{X}(τ^{∗}(l)) = t  (2.20)
σ = f^{∗}.τ  (2.21)

Proof. We construct a partial map τ : Z ⇀ T_{Ω}(X) which satisfies equations 2.20 and 2.21, and then show it is totally defined.

The construction proceeds by induction over l. For the induction base, let l =^{def} 'z with z ∈ Z, then μ_{Y} (σ^{∗}(l)) = μ_{Y} ('σ(z)) = σ(z), hence f^{∗}(t) = σ(z). In this case, τ has to map z to t. Now for z_{0} ∈ Z with z ≥ z_{0}, then since f^{∗} is non-expanding at z, there is s ∈ T_{Ω}(X) such that t ≥ s and f^{∗}(s) = σ(z_{0}). In that case, τ has to map z_{0} to s. In all other cases, τ is undefined. This gives the following definition for τ:

τ(z_{0}) =^{def} \{ \begin{matrix}t & for f^{∗}(t) = σ(z_{0}) \\ ⊥ & otherwise \end{matrix}  (2.22)

So, τ is defined for z and all variables to which z rewrites; for the latter the value of τ is given by non-expandingness of f^{∗}, and it is well-defined by injectivity of f^{∗}: if f^{∗}(t_{1}) = f^{∗}(t_{2}) then t_{1} = t_{2}. Equations 2.20 and 2.21 hold by μ_{X}(τ^{∗}(l)) = μ_{X}('τ(z)) = μ_{X}('t) = t, and σ(z) = f^{∗}(t) = f^{∗}(τ(z)).

For the induction step, we have l = ω(l_{1}, …, l_{n}), and further μ_{Y} (σ^{∗}(l)) = ω(μ_{Y} (σ^{∗}(l_{1})), …, μ_{Y} (σ^{∗}(l_{n}))). The induction assumption is that there are t_{i} ∈ T_{Ω}(X) with f^{∗}(t_{i}) = μ_{Y} (σ^{∗}(l_{i})) (for i = 1, …, n), and that for these we have τ_{i} : Z ⇀ T_{Ω}(X) such that μ_{X}(τ^{∗}(l_{i})) = t_{i} and σ = f^{∗}.τ_{i}. Now define τ : Z ⇀ T_{Ω}(X) as

τ(z) =^{def} \{ \begin{matrix}τ_{i}(z) & if τ_{i} is defined at z for some i, 1 ≤ i ≤ n \\ ⊥ & otherwise \end{matrix}

This is well-defined: if τ_{i} and τ_{j} with i ≠ j are both defined at z, then by the induction assumption, σ(z) = f^{∗}(τ_{i}(z)) and σ(z) = f^{∗}(τ_{j}(z)), so f^{∗}(τ_{i}(z)) = f^{∗}(τ_{j}(z)), and by injectivity of f^{∗}, τ_{i}(z) = τ_{j}(z). This also means that equation 2.21 holds; for equation 2.20, μ_{X}(τ^{∗}(ω(l_{1}, …, l_{n}))) = ω(μ_{X}(τ^{∗}(l_{1})), …, μ_{X}(τ^{∗}(l_{1}))) = ω(t_{1}, …, t_{n}) = t. This concludes the induction.

It remains to show that τ(z) is defined for all z ∈ Z, and hence τ : Z → T_{Ω}(X) is a total function as required. First, for all z ∈ var(l), we have some s ∈ T_{Ω}(X) such that σ(z) = f^{∗}(t), and hence τ(z) = t. Since all variables in Z are bounded, for all z ∈ Z there is y ∈ var(l) such that y ≤ z, and τ(z) is defined by clause 2.22 above. □

We can now show the main lemma of this section.

Lemma 2.4.8 If a term rewriting system Θ = (Ω, R) is non-expanding and does not introduce unbounded variables, then the monad T_{Θ} = ⟨T_{Θ}, η, μ⟩ is nonexpanding.

Proof. According to definition 2.4.5, we have to show that η is non-expanding, and that T_{Θ} preserves non-expandingness of injective functors.

We first show that η is non-expanding: given s, t ∈ T_{Ω}(X) with s ≥ t in T_{Θ}(X), then s is in the image of η_{X} iff there is x ∈ X with s = 'x. Hence, s can’t be of the form ω(s_{1}, …, s_{n}) or l[s_{1}, …, s_{n}] for (X ⊢ l → r) in R, since for all l, l ≠ 'x. So s ≥ t can only be derived by rule [Var], and t = 'y with x ≥ y in X.

To show that T_{Θ} preserves non-expandingness of injective pre-order morphisms, suppose f : X → Y (with X = (X_{0}, ≥), Y = (Y_{0}, ≽)) is injective and non-expanding; we then have to show that f^{∗} is non-expanding as well: for all t ∈ T_{Ω}(X_{0}), if there is s′ ∈ T_{Ω}(Y_{0}) s.t f^{∗}(t) ≽ s′ then there is s ∈ T_{Ω}(X_{0}) such that f^{∗}(s) = s′ and t ≥ s. The proof proceeds by structural induction on the reduction f^{∗}(t) ≥ s′ in T_{Θ}(Y), with the following three cases:

1. If f^{∗}(t) ≥ s′ by [Var], then f^{∗}(t) = 'y_{1} where y_{1} = f(x_{1}) for x_{1} ∈ X_{0}, and s′ = 'y_{2} with y_{1}, y_{2} ∈ Y_{0} and y_{1} ≽ y_{2}. Since f is non-expanding, there has to be x_{2} ∈ X_{0} such that f(x_{2}) = y_{2} and then s =^{def} 'x_{2}.

2. If f^{∗}(t) ≥ s′ by [Pre], then f^{∗}(t) = ω(f^{∗}(t_{1}), …, f^{∗}(t_{n})), and s′ = ω(s′_{1}, …, s′_{n}) with f^{∗}(t_{i}) ≽ s′_{i}, and the induction assumption is that there are s_{i} ∈ T_{Ω}(X_{0}) such that f^{∗}(s_{i}) = s′_{i}, and t_{i} ≥ s_{i}, all for i = 1, …, n. Then let s =^{def} ω(s_{1}, …, s_{n}), with f^{∗}(s) = s′ and t ≥ s as required.

3. Finally, if f^{∗}(t) ≽ s′ by [Inst], then there is a rewrite rule ρ = (Z ⊢ l → r) in R, and a preorder morphism σ : Z → T_{Θ}(Y) such that s′ = μ_{Y} (σ^{∗}(r)) and f^{∗}(t) = μ_{Y} (σ^{∗}(l)). The induction assumption is that f^{∗} is non-expanding for all z ∈ Z, i.e. if σ(z_{1}) = f^{∗}(t) and z_{1} ≥ z_{2}, then there is s ∈ T_{Ω}(X) s.t. t ≥ s and f^{∗}(s) = σ(z_{1}). Then by lemma 2.4.7, there is τ : Z → T_{Θ}(X) such that μ_{X}(τ^{∗}(l)) = t and σ = f^{∗}.τ. Now let s =^{def} μ_{X}(τ^{∗}(r)), then t ≥ s and further

f^{∗}(s) = f^{∗}(μ_{X}(τ^{∗}(r)))
= μ_{Y} (f^{∗∗}(τ^{∗}(r)))
= μ_{Y} ((f^{∗}τ)^{∗}(r))
= μ_{Y} (σ^{∗}(r))) = s′

as required. This concludes the induction, and the proof.

□

The next lemma says that a non-collapsing term rewriting system gives rise to a non-collapsing monad. It also explains why a non-collapsing monad does not have to preserve non-collapsingness: by dualising the proof of lemma 2.4.8, only monads arising from term rewriting systems in which the variables of the right-hand side of every rule are contained in the left-hand side, or rewrite to a variable in there, preserve non-collapsingness, so lemma 2.4.9 would not hold.

Lemma 2.4.9 If a term rewriting system Θ = (Ω, R) is not collapsing, then the monad T_{Θ} = ⟨T_{Θ}, η, μ⟩ is non-collapsing.

Proof. By simply dualising the first part of the proof of lemma 2.4.8 as follows. We have to show that η is non-collapsing: given s, t ∈ T_{Ω}(X) with s ≥ t in T_{Θ}(X), then t is in the image of η_{X} iff there is y ∈ X with t = 'y. Hence, t can’t be of the form ω(t_{1}, …, t_{n}) or r[t_{1}, …, t_{n}] for (X ⊢ l → r) in R, since for all r, r ≠ 'x. So s ≥ t can only be derived by rule [Var], and s = 'x with x ≥ y in X. □

2.4.4 Quasi-Non-Expanding Term Rewriting Systems and Monads

In some cases, non-expandingness is a too strong requirement, e.g. when considering η-expansions [32]. In these cases, it is enough that expanding rewrites can be contracted again — if there is a rewrite from a variable x to a term t, we can reduce the term to the variable x again. In the presence of variable rewrites, we actually don’t need to reduce t back to x, it is sufficient to reduce t to another variable y such that there is a variable rewrite between x and y. We call these term rewriting systems quasi-non-expanding.

Definition 2.4.10 (Quasi-Non-Expanding Term Rewriting Systems) A term rewriting system Θ = (Ω, R) is called quasi-non-expanding (qne), iff for all preorders X = (X_{0}, ≽), if there is a rewrite 'x ≥ t in T_{Θ}(X), then t is not a variable (t ≠ 'z), and there is a rewrite t ≥ 'y in T_{Θ}(X) such that x ≽ y.

We can then formulate the corresponding property for functors and monads:

Definition 2.4.11 (Quasi-non-expanding Functors and Monads) A functor F : X → Y is called quasi-non-expanding at x ∈ X, if it is full and for all α : F x → y in Y, there are γ : y → y′ in Y, β : x → z in X such that γ.α = F β, and it is quasi-non-expanding if it is quasi-non-expanding at all x ∈ X.

A monad T = ⟨T, η, μ⟩ on Cat is quasi-non-expanding if all components η_{X} : X → T X of the unit are quasi-non-expanding, and the action preserves this for injective functors: if F : X → Y is quasi-non-expanding and injective, then so is T F.

The specialization of this definition to preorder morphisms and monads on Pre is straightforward. Then we have to prove that a qne term rewriting system gives rise to a qne monad.

Lemma 2.4.12 If the term rewriting system Θ is quasi-non-expanding and does not introduce unbounded variables, the monad T_{Θ} is quasi-non-expanding.

Proof. That the unit is qne follows easy: given X = (X_{0}, ≽), then η_{X}(x) = 'x; and since Θ is qne, if 'x ≥ t, then t ≥ 'y s.t. x ≽ y.

To show that T_{Θ} preserves qne requires a structural induction analogous to the proof of lemma 2.4.8. □

2.5 Compositionality

In this section, we will justify our calling the semantics defined above “compositional”. We will in chapter 3 elaborate on the fact that many structuring operations, such as the disjoint union, non-disjoint union, or push-out style parametrisation can be expressed as colimits; as a simple example one may take the disjoint union of two term rewriting systems given by the coproduct.

One can either take this coproduct in the category of syntactic presentations (here, term rewriting systems), or in the category of semantic representations (here, monads). Then “compositionality of the semantics” means that the mapping from the syntax to the semantics should preserve the coproduct (or any other colimit); for this, it is sufficient that the mapping is (or extends to) a left adjoint, and this will be the main result of this section.

Of course, one also has to show that these colimits exist in both categories, and this will be the scope of chapter 3. In fact, before we have not done so we cannot fully claim that the semantics is compositional. The main result of this section will nevertheless be an important step in that direction.

We first need to define the two categories in question. The category of semantic representations is the category of strongly finitary monads on Pre, Mon_{Fin}(Pre) which is the subcategory of Mon(Pre) (see §1.3.6 on page 17) given by the strongly finitary monads.

The category of syntactic presentations is given by term rewriting systems and morphisms between them. A morphism between term rewriting systems is given by a signature morphism σ_{S} and a mapping on the rewrite rules, which maps every rule (X ⊢ l → r) to one between the images of l and r under the lifted signature morphism σ̂ (see definition 2.1.8).

Definition 2.5.1 (TRS Morphism and the Category TRS) Given two term rewriting systems Θ = (Ω, R), Θ′ = (Σ, R′), a term rewriting system morphism or TRS morphism σ : Θ → Θ′ between them is given by

• a signature morphism σ_{S} : Ω → Σ,

• and a map σ_{R} : R → R′ such that σ_{R}(X ⊢ l → r) = (X ⊢ s → t) with s = σ̂_{S}(l) and t = σ̂_{S}(t).

The category TRS has term rewriting systems as objects, and TRS morphisms as morphisms.

We can now extend the mapping of a term rewriting system Θ to T_{Θ} to a functor, and this functor will be left adjoint to the mapping of a term rewriting system to its internal language from definition 2.3.10.

Definition 2.5.2 The functor F : TRS → Mon_{Fin}(Pre) maps a term rewriting system Θ to the monad T_{Θ}, and a TRS morphism σ : Θ → Θ′ to its lifting, the monad morphism σ̂ : T_{Θ} ⇒ T_{Θ′}, which is defined pointwise for a preorder X as a preorder morphism σ̂_{X} : T_{Θ}(X) → T_{Θ′}(X), given by the lifting of the signature morphism σ_{S} from definition 2.1.8.

The functor U : Mon_{Fin}(Pre) → TRS maps a finitary monad T to its internal language L(T) (definition 2.3.10), and a monad morphism α : T ⇒ S to the TRS morphism Uα : L(T) → L(S) which on the signatures is as in lemma 2.1.9, and on rules

(Uα)_{R}(X ⊢ l → r) =^{def} (X ⊢ Ûα_{S}(l) → Ûα_{S}(r))

To show that this definition is correct, we have to show that σ̂ is a preorder morphism, and that U(α) is a TRS morphism.

By structural induction, we can show that σ̂_{X} is a preorder morphism, and that it is natural in X. That it satisfies equations 1.3 and 1.4, making it a monad morphism, follows from the fact that the lifting of σ on the object level satisfies these equations.

To show that Uα is indeed a morphism of term rewriting systems, we have to show that (Uα)_{R}(X ⊢ l → r) is a rewrite rule in the internal language of S, i.e. (Uα)_{R}(X ⊢ l → r) ∈ R(S). Let X_{0} denote the set of objects of X; and note that since ε_{T_{0}} is natural in T_{0} (equation 2.8), we have

α_{X}.ε_{T_{0},X_{0}} = ε_{S_{0},X_{0}}.α̂_{S}  (2.23)

With T X = (T_{0}X_{0}, ≥) and SX = (S_{0}X_{0}, ≽), then by definition (X ⊢ l → r) ∈ R(T) iff ε_{T_{0},X_{0}}(l) ≥ ε_{T_{0},X_{0}}(r). Since α_{X} is a preorder morphism, α_{X_{0}}ε_{T_{0},X_{0}}(l) ≽ α_{X_{0}}ε_{T_{0},X_{0}}(r), and by equation 2.23, ε_{S_{0},X_{0}}(α̂_{S}(l)) ≽ ε_{S_{0},X_{0}}(α̂_{S}(r)), hence (X ⊢ α̂_{S}(l) → α̂_{S}(r)) is in the internal language of S as required.

To show functoriality of F and U, we only need to show functoriality of the object functions, as the underlying object functions are covered by §2.1.3. The proof principles remain the same: structural induction for the functoriality of F, and unfolding the definition for functoriality of U. The latter requires the functoriality of U on the terms, and of F, to show that U maps the identity morphism id_{T} on a monad T to the identity TRS morphism on L(T): for id_{T}, { \atop Uid_{T}}(l) = \begin{matrix} \\ 1 & Σ(T) \end{matrix}(l) = 1_{T_{Σ(T)}}(l) = l (similarly for the composition). We can now state the main proposition of this section:

Proposition 2.5.3 The two functors F and U form an adjunction F −| U : TRS → Mon_{Fin}(Pre).

Proof. We show adjointness by constructing a unit υ : 1_{TRS} → UF which is universal from Θ to U.

Given a term rewriting system Θ = (Ω, R), the unit at Θ is a TRS morphism υ_{Θ} : Θ → L(T_{Θ}) defined as follows:

• On the signature, it is the unit of the adjunction from lemma 2.1.9:

υ_{Θ,S} =^{def} υ_{Ω}

• On the rules, it is defined as

υ_{Θ,R}(X ⊢ l → r) =^{def} (X ⊢ υ̂_{Ω}(l) → υ̂_{Ω}(r))

This is a TRS morphism by the triangle laws of the adjunction from lemma 2.1.9: these imply that ε_{T_{Ω}}.υ̂_{Ω}(l) = l and ε_{T_{Ω}}.υ̂_{Ω}(r) = r, hence (X ⊢ υ̂_{Ω}(l) → υ̂_{Ω}(r)) ∈ R(T_{Θ}).

We first have to show that ν is natural in Θ, i.e. for all σ : Θ → Θ′, we have υ_{Θ′}.σ = (UF (σ)).υ_{Θ}. On the signature part of υ, this follows from lemma 2.1.9; on the rewrite rules, this means that for all (X ⊢ l → r) ∈ R, UF (σ)(υ_{Θ}(X ⊢ l → r)) = υ_{Θ′}(σ(X ⊢ l → r)). The proof requires the naturality on the operations and the functoriality of the lifting, and apart from that just follows by substituting the definitions.

As the final step, we show the universality of υ_{Θ} from Θ to U: given a monad S = ⟨S, ζ, ξ⟩ and a TRS morphism ν : Θ → L(S), there is a unique monad morphism !_{ν} : T_{Θ} ⇒ S such that U!_{ν}.υ_{Θ} = ν. This monad morphism is given by a family of preorder morphisms !_{ν,X} : T_{Θ}X → SX for every preorder X, which are given by lemma 2.1.9.

We have to show that !_{ν,X} is a preorder morphism, i.e. with SX = (S_{0}X_{0}, ≽), for all s, t ∈ T_{Θ}(X) such that s ≥ t, !_{ν,X}(s) ≽!_{ν,X}(t). This is rather unsurprisingly shown by induction on the structure of the reduction. The base case relies on the unit ζ of S being a preorder morphism, then 'x ≥ 'y implies ζ(x) ≽ ζ(y), hence !_{ν,X}('x) ≽!_{ν,X}('y). There are two induction steps, operations and instantiated rules. For the first, let t = e(t_{1}, …, t_{n}) and s = e(s_{1}, …, s_{n}) and assume that for i = 1, …, n, t_{i} ≥ s_{i} (hence s ≥ t), and by induction assumption !_{ν}(t_{i}) ≽!_{ν}(s_{i}). By bijection 2.14 (on morphisms) [!_{ν}(t_{1}), …,!_{ν}(t_{n})] ≽ [!_{ν}(s_{1}), …,!_{ν}(s_{n})], and because S is a Pre-enriched functor, S[!_{ν}(t_{1}), …,!_{ν}(t_{n})] ≽ S[!_{ν}(s_{1}), …,!_{ν}(s_{n})].

Since these are two morphisms, ordered pointwise, we have in particular for e ∈ SX, S[!_{ν}(t_{1}), …,!_{ν}(t_{n})](ν_{e}) ≽ S[!_{ν}(s_{1}), …,!_{ν}(s_{n})](ν_{e}), and since the multiplication ζ of S is a preorder morphism, we have ζ(S[!_{ν}(t_{1}), …,!_{ν}(t_{n})](e)) ≽ ζ(S[!_{ν}(s_{1}), …,!_{ν}(s_{n})](e)), hence !_{ν}(t) ≽!_{ν}(s) just as required.

For the other induction step, let (X ⊢ l → r) ∈ R, and l[t_{1}, …, t_{n}] ≥ r[t_{1}, …, t_{n}], then !_{ν}(l) ≽!_{ν}(r), and by a similar argument !_{ν}(l[t_{1}, …, t_{n}]) ≽ !_{ν}(r[t_{1}, …, t_{n}]). □

Finally, note that the category of finitary monads over Pre is in general not a Pre-category.^{10} Hence, the adjunction above is merely an ordinary adjunction, not an enriched one.

2.6 Conclusions and Discussion

Summary

In this chapter, we have reviewed the well-known treatment of universal algebra by finitary monads on the category Set of all sets. Based on the general theory of enriched finitary monads, we have generalized this to term rewriting systems, obtaining for a term rewriting system Θ a monad T_{Θ} on the category Pre of all preorders. This monad is enriched over Pre. The finite preorders play the rôle of the natural numbers as arities for operations. Non-discrete finite preorders lead to non-discrete arities, which lead us to the notion of variable rewrites and generalized rewrite rules.

The monad on Pre models a particular aspect of term rewriting (namely, many-step unnamed reductions), and it is feasible to find monads on other base categories to model other aspects of term rewriting (as done in the appendix).

In the other direction, we have given the internal language L(T) of a monad T as a term rewriting system, and we have shown that the mapping of a term rewriting system Θ to the monad T_{Θ} is left adjoint to this, making precise the claim that the semantics is compositional.

Assessment

The main novelties of the categorical semantics presented in this chapter are the following features:

• the construction of the semantics as a monad; • the generalized rewrite rules and variable rewrites; and

10 Put more generally, the monads over V do not form a V-category [39].

• the freeness of the construction, exhibited by the adjunction in proposition 2.5.3.

The monad construction separates the process of constructing the theory of a term rewriting system, given by the monad, from the choice of the structure used to model reductions. Once the theory is constructed, we need not concern ourselves with the more subtle intricacies of enriched category theory. We can think of the term reduction algebra as a particular preorder, and the monad T_{Θ} just maps preorders to preorders; the additional enriched structure of the theory construction just ensures that this mapping respects the reduction structure.^{11} When reasoning about this theory, we reason about preorders (or categories); contrast this with [83, 73, 81, 64], where the reductions between terms are always 2-cells in a 2-category or a Sesqui-category.

The concept of generalised rewrite rules is particularly interesting in the context of the disjoint union of term rewriting systems, since it alleviates the complications usually associated with inner and outer reductions [42]. Because the rewrites between variables specify exactly the rewrites which are possible for any instantiation, the inner reduction cannot destroy redexes, and we have a one-step completion property with respect to rewrites from one system; we will elaborate on this in chapter 4.

The crucial insights here come from the theory of enriched monads: terms are composed operations, contexts and arities are the same, and the arities of operations are the finitely presentable objects of the base category. This leads to the concept of a generalized rewrite rule: rewrite rules are the operations which build the reduction structure, and their arity is the context. Using finitely presentable preorders (or categories) as arities means that the contexts not only contain variables, but reductions (variable rewrites) between them.

Generalized rewrite rules are interesting from another point of view: they show how a gentle generalisation suggested by a semantic treatment can lead to a more satisfying theory. Here, the theory construction would not be a left adjoint if we would not allow generalized rewrite rules. Of course, one has to be careful that these generalizations are conservative and do not change the meaning of previous definitions.

11This is because we use the closed structure of Pre, which makes Pre itself Pre-category, so instead of Pre-categories we can think in more familiar terms of preorders and preorder morphisms.

The theory construction being left adjoint is crucial for the compositionality of the semantics: we will in the following chapter see that many important structuring operations can be expressed as colimits, which are preserved by a left adjoint.

Possible Extensions

We do not cater for many-sorted signatures. This is more in order to maintain a minimum of readability and understandability rather than because of technical difficulties. Briefly, for a set A of sorts, a signature Σ = (A, Ω) is modelled by a monad on the category Set^{A}, and a term rewriting system to that signature by a monad on Pre^{A}. All the above proofs and constructions still go through, but have to be decorated with a sorts index S ∈ A; e.g. the term reduction algebra T_{Θ}(X) is now given by the product of all term reduction algebras T_{Θ,S}(X) for reductions of sorts S ∈ A. [69] gives this construction for many-sorted equational presentations; the generalization to term rewriting systems based on the previous chapter is straightforward.

It is also fairly straightforward to generalize our semantics to rewriting modulo equations, given by Θ = (Ω, E, R) where E is a set of equations over the signature Ω, and R is a set of rewrite rules. The theory construction proceeds as above, only that the objects of our preorder would be equivalence classes of terms, not terms. Of course, the resulting monad would not satisfy the properties we have shown in section 2.4 (in particular, preservation of coequalizers and regularity), so the results of the following chapters do not apply.

Extensions to conditional term rewriting or other variants of term rewriting are not quite as straightforward and will be discussed in chapter 6.

Structuring operations

Structuring operations are used to build large specifications or term rewriting systems from small ones. One of the most basic structuring operations is the disjoint union, which has been the focus of most research in the term rewriting literature; more sophisticated ones can be found in [77, 12, 13, 79, 75]. As observed by Goguen and Burstall [21, 6, 22], quite a lot of structuring operations can be described by colimits, either in the category of syntactic presentations (here, term rewriting systems), or in the category of semantic representations (here, monads). Although colimits cannot express all structuring operations, they can express those which can loosely be characterized by “shared or disjoint union and quotienting”; and we posit that this class encompasses many of the important structuring operations, such that a semantics preserving this class of operations can justifiably be called compositional. Hence, we have to show that the mapping from the syntax to the semantics preserves colimits, for which it is sufficient that the mapping is (or extends to) a left adjoint. If we can then show that both categories have colimits, we can reason about structured systems in terms of colimits of their semantics; in our particular case, we can reason about the disjoint union of term rewriting systems in terms of coproducts of monads. The adjunction was shown in §2.5, so this chapter is devoted to showing the existence of the colimits, in particular in the category of strongly finitary monads.

Any colimit can be constructed using coproducts and coequalizers (see proposition 1.3.1), so we will investigate how to construct coproducts and coequalizers of monads respectively. The main emphasis will be on the coproduct of two monads, since we will concentrate on this structuring operation in the following two chapters, when we will investigate how confluence and strong normalization are preserved under the coproduct.

Structuring operations

In support of our claim that the class of structuring operations expressible by colimits comprise many of the important ones we will now exhibit some wellknown structuring operations which can be expressed by colimits of particular diagrams, and some which cannot.

Since signatures are maps from ℕ to Set, and rewrite rules form sets, we can give a naïve semantics to structuring operations on the syntactic presentations in terms of the usual operations on sets; for example, it is clear how to form the union of two signatures.^{1} The reader is invited to verify that the usual definition indeed satisfies the required universal property of the colimit of the diagrams in the following.

• Disjoint union. The disjoint union of two term rewriting systems Θ_{1},Θ_{2} is given by the coproduct Θ_{1} + Θ_{2}.

• Non-disjoint union. Given two term rewriting systems Θ_{1} = (Ω_{1}, R_{1}) and Θ_{2} = (Ω_{2}, R_{2}) which have a shared part Θ_{0} = (Ω_{0}, R_{0}), then the union Θ_{1} +_{Θ_{0}} Θ_{2} is described by the push-out of the inclusions:

[figure: (Ω_{0}, R_{0}); ⊂; (Ω_{1}, R_{1}); (Ω_{2}, R_{2}); ∩; Θ_{1} +_{Θ_{0}} Θ_{2}]

• Translation along a signature morphism. Given a term rewriting system Θ = (Ω, R) and a signature morphism σ : Ω → Σ, the translation of the rules along the signature morphism is given as (Σ, σ̂(R)). This can be described by the following push-out:

[figure: (Ω, ∅); (σ, 1); (Σ, ∅); (Ω, R); ∩; .]

If σ is the inclusion of Ω into Σ, this describes the extension of the signature Ω.

1For two signatures Ω, Σ, their union is given by (Ω + Σ)(n) =^{def} Ω(n) + Σ(n).

• Parameterization (I). Following the approach for parameterized specifications from CLEAR [6] and ACT ONE[12], a parameterized term rewriting system is given by a pair (Θ_{P} , Θ_{1}) with an inclusion i : Θ_{P} ↪ Θ_{1}. An instantiation of the parameter Θ_{P} is given by a system Θ_{A} and a morphism h : Θ_{P} → Θ_{A}, with the instantiated parameterized term rewriting system given by the push-out of h and i.

There are other ways of modelling parameterized specifications, however;^{2} and this leads us to examples of structuring operations which can not be modelled with colimits:

• Parameterization (II). Following the approach of ASL and its successors [79, 78], a parameterized term rewriting system is now given as Θ_{P} = λX : Σ.Θ_{B}; then Θ_{P} can be instantiated with any term rewriting system Ξ with signature Σ, and the instantiation is defined as Θ_{P} (Ξ) =^{def} Θ_{B}[Ξ/X].

• Hidden Operations and Reductions. A term rewriting system with hidden operations (and rules) is given by a pair (Θ_{0}, Θ_{1}) where the operations and rules (and sorts, in the many-sorted case) Θ_{0} are considered to be visible. This concept cannot be modelled with colimits because given a monad T all operations and rewrite rules in the internal language L(T) are visible.

• Observational and Behavioural Equivalence. In the context of algebraic specifications, this means that one restricts “observations” to a certain form, like terms from certain sorts [76]. Some specification languages provide operations for the closure under observational or behavioural abstraction; this cannot be expressed in terms of colimits.

A Unified Treatment

As mentioned before, we will in the remainder of the thesis consider monads on Cat, enriched over Cat as our semantic domain. The results we will obtain still apply to the previous definitions and constructions by just regarding preorders as categories with at most one morphism between any two objects.

2To be precise, there are different kinds of parameterization [74]: specifications of parameterized data types (like lists generic over the elements), and parameterized specifications (like sets generic over the specification of the elements).

Structure of this Chapter

The remainder of this chapter is structured as follows:

• In §3.1, we will give a detailed account of the pointwise construction of the coproduct of two finitary monads, which will be the main section of this chapter. Along with the initial object given by the identity monad, this gives all finite products.

• The coproduct monad will map a category X to a category T X, given as the colimit of a diagram D_{X}. In §3.2 we will investigate the structure of this colimit, along with a few other technical lemmas.

• We finish by briefly sketching the construction of the coequalizer of two monads in §3.3, something more of an afterthought since it will not be needed in the following.

3.1 The Coproduct of Two Strongly Finitary Monads

Given two strongly finitary monads T_{1} = ⟨T_{1}, η_{1}, μ_{1}⟩, T_{2} = ⟨T_{2}, η_{2}, μ_{2}⟩ on Cat, the coproduct monad T_{1+2} = ⟨T, η, μ⟩ is given by its universal property: there are two monad morphisms ι_{1} : T_{1} → T_{1+2}, ι_{2} : T_{2} → T_{1+2} (called the injections) such that for any other monad S = ⟨S, η_{S}, μ_{S}⟩ with monad morphisms α : T_{1} → S, β : T_{2} → S, there is a unique monad morphism [α, β] : T_{1+2} → S such that α = [α, β].ι_{1} and β = [α, β].ι_{2}.

In the following, we give a pointwise construction of the coproduct monad. We define the action for each category X ∈ Cat, extend it to an endofunctor, define unit and multiplication, show it satisfies the monad laws and show the monad thus defined satisfies the universal property.

Unfortunately, it is unavoidable that the construction becomes rather technical at times. The essentials of the construction are contained in §3.1.1, whereas §3.1.2 and §3.1.3 can be omitted by hurried readers (or those disinclined to indulge in technicalities) prepared to accept that the construction indeed gives rise to the coproduct monad (proposition 3.1.9 being the result of all the technical work).

3.1.1 The Coproduct Monad as a Pointwise Colimit

Principal Subterms and Layers

The definition of the action as given below is not immediately obvious, so we will first give a motivation of its construction. For an accessible example, consider two monads on the category Set given by signatures Ω_{1}, Ω_{2}. Then the coproduct of T_{Ω_{1}} and T_{Ω_{2}} should map a set X to the set of all terms built from operations of Ω_{1} + Ω_{2}. Terms from T_{Ω_{1}+Ω_{2}}(X) can be decomposed into layers of terms from T_{Ω_{1}}(X) and T_{Ω_{2}}(X) (aliens or principal subterms); we here give the definition from [42], slightly paraphrased:

For any signature Ω, a context is an element of T_{Ω⊎{□}}(X), where □ is a “fresh” constant called a hole. For any context C ∈ T_{Ω⊎{□}}(X) with n holes, and terms t_{1}, …, t_{n} ∈ T_{Ω}(X), C[t_{1}, …, t_{n}] denotes the result of replacing from left to right the holes in C by t_{1}, …, t_{n}. The root symbol of a term t ∈ T_{Ω_{1}+Ω_{2}}(X) is defined as

root(t) =^{def} \{ \begin{matrix}f & if t = f(t_{1}, …, t_{n}) \\ x & if t = 'x \end{matrix}

Let t = C[t_{1}, …, t_{n}] with C ≠ □, then we write t = C[[t_{1}, …, t_{n}]] if C ∈ T_{Ω_{i}⊎{□}}(X) and root(t_{1}), …, root(t_{n}) ∈ Ω_{j} for i, j ∈ {1, 2} and i ≠ j. t_{1}, …, t_{n} are principal subterms or aliens. The rank of a term t ∈ T_{Ω_{1}+Ω_{2}}(X) is defined as

rank(t) =^{def} \{ \begin{matrix}1 & if t ∈ T_{Ω_{1}}(X) ⊎ T_{Ω_{2}}(X) \\ 1 + max\{rank(t_{i}) | 1 ≤ i ≤ n\} & if t = C[[t_{1}, …, t_{n}]], n ≥ 1 \end{matrix}

In our approach we forego the introduction of holes and principal subterms, and take the notion of a layer as primitive insofar as every application of the action T_{1} or T_{2} corresponds to one layer; i.e. it takes t_{1}, …, t_{n} to C[[t_{1}, …, t_{n}]]. This is because we can build term algebras on top of term algebras; for example, the elements of T_{Ω_{1}}(T_{Ω_{2}}(X)) correspond (roughly) to terms of rank two in the above definition. However, in term algebras like T_{Ω_{2}}(T_{Ω_{1}}(T_{Ω_{2}}(X))) we will have terms from T_{Ω_{2}}(X) treated as variables in T_{Ω_{1}}(X) inserted into terms of T_{Ω_{2}}(X), which should be equivalent to a term from T_{Ω_{2}}(X); for example, if F ∈ Ω_{2}, then F(''F('x)) and F(F('x)) describe the same term. This identification is called “collapsing layers”.

Hence, the coproduct should be the disjoint union of all the term algebras

T_{Ω_{1}+Ω_{2}}(X) =^{def} X + T_{Ω_{1}}(X) + T_{Ω_{2}}(X)+ T_{Ω_{1}}(T_{Ω_{2}}(X)) + T_{Ω_{2}}(T_{Ω_{1}}(X))+ T_{Ω_{1}}(T_{Ω_{2}}(T_{Ω_{1}}(X))) + T_{Ω_{2}}(T_{Ω_{1}}(T_{Ω_{2}}(X))) + …

quotiented by a suitable equivalence relation, which will be affected by the unit and the multiplication: the unit identifies all the variables from X in the different term algebras, and the multiplication collapses layers as described above. We arrive at a definition of the action T as the colimit of a diagram which has all the combinations of T_{1} and T_{2} as objects, and all morphisms which can be formed using the unit and multiplication of the two monads as morphisms.

The diagram in question will be weakly ω-filtered in the sense of definition 1.3.5. We will restrict ourselves to strongly finitary monads (the ones preserving diagrams of this kind), since they are the ones of interest and for them the construction simplifies considerably.

The Action of the Coproduct

In the following, we use the alphabet L =^{def} {1, 2}, and let W =^{def} L^{∗} be the words over that alphabet. We further assume that both monads T_{1} and T_{2} are strongly finitary.

The diagram D_{X} is defined by defining a graph G, and a graph morphims d_{X} : G → U(Cat). Then D_{X} : F(G) → Cat is the transpose of d_{X} under the adjunction between Grph and Cat (see page 37). The graph G is defined as follows:

Vertices: V (G) =^{def} W
Edges: E(G) =^{def} {e_{j,v}^{w} : wv → wjv | w, v ∈ W, j ∈ L} ∪
{m_{j,v}^{w} : wjjv → wjv | w, v ∈ W, j ∈ L}

The graph morphism d_{X} : G → U(Cat) is defined as

On the vertices: d_{X} (w) =^{def} T^{w}(X)
On the edges: d_{X} (e_{j,v}^{w}) =^{def} T^{w}(η_{j,T^{v}(X)})
d_{X} (m_{j,v}^{w}) =^{def} T^{w}(μ_{j,T^{v}(X)})

where for all w ∈ W, the functor T^{w} : Cat → Cat is defined as follows:

T^{ε} =^{def} 1_{Cat}
T^{jw} =^{def} T_{j}T^{w}

In the following, we will write η_{j,v}^{w} for T^{w}(η_{j,T^{v}(X)}) and μ_{j,v}^{w} for T^{w}(μ_{j,T^{v}(X)}): and we further drop the empty word from super- and subscripts, so e.g. μ_{1,21} = μ_{1,21}^{ε}.

The object function of the endofunctor T will map X to the colimit of D_{X} in Cat. For a functor F : X → Y (i.e. a morphism in Cat), precomposition with F of the cone over D_{Y} given by the colimit T Y = colim D_{Y} gives a cone over D_{X}, since the following two diagrams commute for all w, v ∈ W, j ∈ L by naturality of η_{j} and μ_{j}, respectively, preserved by applying T^{v} and hence induces a morphism !_{F} : colim D_{X} → colim D_{Y}.

[figure: T^{vw}X; η_{j,w}^{v}; T^{vjw}X; T^{vw}Y; T^{vw}f; η_{j,w}^{v}; T^{vjw}Y; T^{vjw}f; T^{vjjw}X; μ_{j,w}^{v}; T^{vjw}X; T^{vjjw}Y; T^{vjjw}f; μ_{j,w}^{v}; T^{vjw}Y; T^{vjw}f]  (3.1)

Definition 3.1.1 The endofunctor T : Cat → Cat is defined as follows:

On objects:  T (X) =^{def} colim D_{X}
On morphisms: T (F : X → Y) =^{def} !_{F} : colim D_{X} → colim D_{Y}

In fact, we are working in an enriched setting here, so T should be a monad enriched over Cat. We have elided the necessary definitions to make T into a 2monad on the 2-category Cat, not because this is unnecessary but in order to keep the categorical details at a manageable level. We will consider the consequences of the enrichment in detail in §3.1.4.

Before we define the unit and the multiplication of the monad, we need to show that F(G) is a weakly ω-filtered category (see definition 1.3.5 on page 23), and hence T_{1} and T_{2} preserve the colimit of D_{X}. First, observe that if d : v → w (v, w ∈ W) is a morphism in F(G), there are also morphisms d′ : uv → uw for all u ∈ W. Further, F(G) is pointed: for all w ∈ W, there is a morphism p : ε → w, constructed by induction on w. For w = ε, voilà; for w = jw′ (j ∈ L, w′ ∈ W), let there be p′ : ε → w′; then there is e_{j,w′} : w′ → jw′ hence p =^{def} e_{jw′}.p′. (Note that this morphism is of course not unique.) We can now show that:

Lemma 3.1.2 F(G) is a weakly ω-filtered category.

Proof. We first show that F(G) is weakly filtered (definition 1.3.2: given v, w ∈ W, there is u ∈ W such that there are morphisms p : v → u, q : w → u. This is shown by induction on v and w. If v = ε, then by pointedness of F(G), there is p : ε → w, hence u =^{def} w, and the same applies if w = ε. Now let w = jw′ and v = iv′ (with i, j ∈ L, and w′, v′ ∈ W, and assume that there is u′ ∈ W such that there are p′ : v′ → u′, q′ : w′ → u′. Now there are two cases: i = j, or i ≠ j. For the first case, let u =^{def} iu′, and then there are p : iw → iu and q : iv → iu. For the second case, let u =^{def} iju′; then there are p′′ : iv′ → iu′ and q′′ : jw′ → ju′, so let p =^{def} e_{j,u′}^{i}.p′′ and q =^{def} e_{i,ju′}.q′′ (and again, u is not unique).

To show weakly ω-filteredness, it remains to be shown that:

(i) for all v ∈ W, there at most countably infinitely many u ∈ W such that there is p : u → v. This is the case since there are only countably infinitely many objects words in W.

(ii) for all u, v ∈ W, the hom-set F(G)(u, v) is at most countably infinite.

This is the case since it is generated from a finite set of edges.

□

Note that F(G) is not directed or filtered, because there are morphisms with the same source and target which cannot be coequalized by any other morphism in F(G). For example, there is no morphism d : T^{121}X → T^{v}X which when composed with the following two morphisms makes to the two compositions equal:

T^{21}X
[figure: T^{1}X; η_{2,1}; T^{121}X; η_{1,21}]
[figure: T^{12}X; η_{1}^{12}; η_{2}^{1}]

3.1.2 Unit, Multiplication and the Monad Laws

Having defined the action of the monad, it remains to define unit and multiplication and show that they satisfy the monad laws.

The Unit and Multiplication of the Coproduct

Recall that the colimit of a functor D : J → C is given by an object C ∈ C together with a cone c : D ⇒ ΔC, which is universal amongst these cones, i.e. given any other cone m : D ⇒ ΔX, there is a unique morphism !_{m} : C → X, such that m = Δ!_{m}.c (see page 14). This means that defining a morphism F : colim D_{X} → Y out of the colimit amounts to giving a cone ν : D_{X} ⇒ ΔY, given by a family of functors ν_{w} : T^{w}X → Y for all w ∈ W which commute with the morphisms in D_{X}. In the following, let c_{X} : D_{X} ⇒ Δ(colim D_{X}) be the colimiting cone over D_{X}, with components functors c_{X ,w} : T^{w}X → colim D_{X}; we will usually omit the index category X when it is clear from the context. The unit is defined as the component of the colimiting cone for the empty word ε:

Definition 3.1.3 The natural transformation η : 1_{Cat} ⇒ T is given by

η_{X} =^{def} c_{X ,ε}

The multiplication uses the fact that the two monads are strongly finitary. To define it, we need to give a morphism μ_{X} : T T X → T X. Since T T X = colimD_{T X}, this morphism is given by a cone ν : D_{T X} → T X, that is for all w ∈ W, a morphism ν_{w} : T^{w}T X → T X. T^{w} preserves weakly ω-filtered colimits, hence T^{w}T X = T^{w}colim D_{T X} ≅ colim T^{w}D_{X}, and the morphism out of this colimit is given by another cone ν_{w,v} : T^{w}T^{v}X → T X for all v ∈ W defined as follows:

Definition 3.1.4 The multiplication μ_{X} : T T X → T X is given by the cone ν_{w,v} : T^{w}T^{v}X → T X which for all w, v ∈ W is defined as

ν_{w,v} =^{def} c_{wv}

Naturality of the unit and multiplication follow from the fact that all components of the diagram D_{X} are natural transformations (diagrams 3.1). So given a functor F : X → Y, diagram 3.2 commutes for any morphism p_{w,X} : X → T^{w}X

[figure: X; p_{w,X}; T_{X}^{w}; Y; F; p_{w,Y}; T_{Y}^{w}; T^{w}F]  (3.2)

in the diagram, making η natural in X.

We now have to show that the unit and multiplication as defined satisfy the monad laws, and that the monad thus defined has the universal property.

The Monad Laws

Lemma 3.1.5 For η and μ, the monad laws hold:

μ_{X} η_{T X} = 1_{T X}  (3.3)
μ_{X} T η_{X} = 1_{T X}  (3.4)
μ_{X} μ_{T X} = μ_{X} T μ_{X}  (3.5)

Proof. We show each of these in turn.

To show equation 3.3, we have to show that the cone inducing the composite μ_{X} η_{T X} is the same as the colimiting cone c.

The morphism η_{T X} : T X → T T X = c_{T X} is given by a cone ζ : D_{X} ⇒ T T X, defined as ζ_{w} =^{def} c_{w,T X}.T^{w}(η_{X}):

[figure: T^{w}X; T^{w}(η_{X}); T^{w}T X; c_{w,T X}; T T X]

Since μ is the morphism induced by the cone c_{uw} : T^{u}T^{w}X → T X, we have to show that for all morphisms d : X → T^{w}X in D_{X}, c_{uw}T^{u}d = c_{u}. In other words, commutativity of the diagram on the left is shown by commutativity of the diagram on the right:

[figure: T X; T T X; η_{T X}; T X; 1_{X}; μ_{X}; T^{u}X; T^{u}T^{w}X; T^{u}d; T X; c_{u}; c_{uw}]

The commutativity of the diagram on the right follows from the fact that if d is a morphism in D_{X} so is T^{u}d, and c is a cone over D_{X}.

To show equation 3.4, T η_{X} is defined as the unique morphism making the following diagram commute

[figure: X; c_{X}; T X; T X; η_{X}; c_{T X}; T T X; T η_{X}; . . . . . . . . . . . . . . . . .]

By definition η_{X} = c_{X}, so T η_{X} = c_{T X} = η_{T X}, and then equation 3.4 reduces to equation 3.3.

For the associativity (equation 3.5), consider

[figure: T^{u}T^{v}T^{w}X; T^{u}c_{vw}; T^{u}T X; T T^{v}T^{w}X; c_{u,T^{v}T^{w}X}; T c_{vw}; T T X; c_{u,T X}]

T c_{vw} is the unique morphism on the bottom making this square commute. c_{vw} induces μ, hence the composition along the bottom and the left side induces T μ; and the composition along the right side and the top induces μ_{T}. Hence, μ_{T} = T μ and μ.μ_{T} = μ.T μ. □

3.1.3 The Universal Property

We now have to show that the monad defined in the previous section satisfies the universal property which makes it the coproduct in the category of monads. We will first define the injections into the coproduct, and given another monad with two monad morphisms, construct the universal morphism out of the coproduct which commutes with the injections.

The Injections

Definition 3.1.6 The natural transformations ι_{1} : T_{1} ⇒ T, ι_{2} : T_{2} ⇒ T are defined by

ι_{1,X} =^{def} c_{1} : T_{1}X → T X
ι_{2,X} =^{def} c_{2} : T_{2}X → T X

Lemma 3.1.7 ι_{1}, ι_{2} are monad morphisms.

Proof. We have to show that both satisfy equations 1.3 and 1.4.

The first equation holds because η_{1,X} is a morphism in the diagram D_{X}, and c a cone over it: η_{1,X}.ι_{1,X} = c_{1}.η_{1,X} = c_{ε} = η_{X}.

For the second equation, consider diagram 3.6, where the upper right triangle commutes since μ_{1} is a morphism in D_{X}, and the lower left triangle by definition of μ. □

[figure: T_{1}T_{1}; μ_{1}; T_{1}; T_{1}T X; T_{1}c_{1}; T T X; c_{1,T X}; μ; T X; c_{1}; c_{11}]  (3.6)

The Universal Property

Lemma 3.1.8 Given a monad S = ⟨S, ζ, ξ⟩ and two monad morphisms α : T_{1} ⇒ S, β : T_{2} ⇒ S, there is a unique monad morphism u : T ⇒ S such that u.ι = α and u.ι_{2} = β

Proof. The proof will proceed as follows: we will construct a cone ν : D_{X} ⇒ ΔSX over the diagram D_{X} which will induce a morphism u_{X} : T X → SX. We will then show these morphisms form a natural transformation u : T ⇒ S, and that this natural transformation is a monad morphism. Finally, we show it satisfies u.ι_{1} = α and u.ι_{2} = β.

The definition of the cone ν for an object X ∈ Cat is inductive over w ∈ W. For w = ε, define ν_{ε} =^{def} ζ_{X}; for w = 1v (with v ∈ W), define ν_{T^{1v}} = ν_{T_{1}T^{v}} as the composition of diagram 3.7 where square (∗) commutes by naturality of α, and

[figure: T_{1}T^{v}X; T_{1}ν_{v}; T_{1}SX; (∗); ST^{v}X; α_{T^{v}X}; Sν_{v}; SSX; α_{SX}; ξ_{X}; SX]  (3.7)

for w = 2v correspondingly with β in place of α. Note that for w = 1, we have (by the above definition with ν_{ε} = ζ) ν_{1} = ξ_{X}.Sζ_{X}.α_{X} = α_{X} (by the unit law for S).

To show that ν is a cone, we have to show that for all morphisms d : T^{v}X → T^{w}X in D_{X}, we have

[figure: T^{v}X; d; T^{w}X; SX; ν_{w}; ν_{v}]

Since all morphisms in D_{X} are either of the form η_{i,s}^{r} or μ_{j,v}^{w}, or sequences of these, it is sufficient to show that for all w ∈ W the following two hold

ν_{w} = ν_{1w}.η_{1,w}  (3.8)
ν_{11w} = ν_{1w}.μ_{1,w}  (3.9)

and application of T_{1} and T_{2} preserve these: given an arrow f : T^{w}X → T^{v}X in D_{X} such that ν_{w} = ν_{v}.f, with j ∈ L, the following holds:

ν_{jw} = ν_{jv}.T_{j}f  (3.10)

We prove the three equations in turn. For equation 3.8, consider diagram 3.11.

[figure: T^{w}X; η_{1,w}; T_{1}T^{w}X; SX; ν_{w}; η_{1,SX}; T_{1}SX; T_{1}ν_{w}; SSX; α_{SX}; ζ_{SX}; SX; ξ_{X}; = = = = = = = = = = = = = = = = = = = = = = = = = =]  (3.11)

The square commutes by naturality of η_{1}, the upper of the two triangles by α being a monad morphism and the lower is the unit law for S. The composition of the arrows on the right is by definition ν_{1w}, hence the equation holds.

For equation 3.9, consider diagram 3.12. where square (1) commutes because α

[figure: T_{1}T_{1}T^{w}X; μ_{1,w}; T_{1}T^{w}X; (1); ST_{1}T^{w}X; α_{T_{1}T^{w}X}; Sα_{T^{w}X}; SST^{w}X; ξ_{T^{w}}; ST^{w}X; α_{T_{1}T^{w}X}; (2)  (3); SSX; Sν_{1w}; Sξ_{X}; SSSX; SSν_{w}; ξ_{SX}; SSX; Sν_{w}; (4); SX; ξ_{X}; ξ_{X}] (3.12)

is a monad morphism, (2) by applying S to the definition of ν_{1w}, (3) by naturality of ξ and (4) is the associativity law of S. Then ν_{11w} is the composition of the arrows on the left side of the diagram, and ν_{1w} is the composition of the arrows on the right side of the diagram, hence equation 3.9 holds.

To show equation 3.10. assume we have f : T^{w} → T^{v}X in D_{X} such that ν_{w} = ν_{v}.f, ν_{1w} = ν_{1v}.T_{1}f. Applying T_{1} to this we obtain the upper triangle in diagram 3.13, where the outer two triangles are the definition of ν_{1w} and ν_{1v}

[figure: T_{1}T^{w}X; T_{1}f; T_{1}T^{v}Y; T_{1}SX; T_{1}ν_{v}; T_{1}ν_{w}; SSX; α_{SX}; SX; ξ_{X}; ν_{1v}; ν_{1w}] (3.13)

respectively. Hence equation 3.10 holds as well.

This shows that ν as defined forms a cone ν : D_{X} ⇒ ΔSX over D_{X}, and hence there is a unique morphism u_{X} : T X → SX such that u_{X}.c = ν. To be precise, we have to index the cone ν with the category X as well (we have not done so above to avoid unnecessarily cluttered notation), since there will be one cone ν_{X} for every category X.

To show that the induced morphism u_{X} : T X → SX is natural, we have to show that given a morphism f : X → Y, the two cones ν_{X} , ν_{Y} over the diagrams D_{X} and D_{Y} are natural in the sense that for all u ∈ W, we have to show that diagram 3.14 commutes. This proceeds by expanding the definitions of ν_{X ,u} and

[figure: T_{u}X; T^{u}f; T^{u}Y; SX; ν_{X ,u}; Sf; SY; ν_{Y,u}]  (3.14)

ν_{Y,u} in diagram 3.14, and using the fact that all of the components (α, ξ and ζ for w = ε) are components of natural transformations.

We now show that the natural transformation u : T ⇒ S is a monad morphism, i.e. satisfies equations 1.3 and 1.4. For equation 1.3, we have to show that for all morphisms d : X → T^{u}X in D_{X}, we have ν_{u}.d = ζ_{X}. This follows from the fact that ζ_{X} = ν_{ε}, and the fact that ν is a cone over D_{X}.

For equation 1.4, we have to show that for all u, v ∈ W, diagram 3.15 commutes. In order to do so, we use u_{X}.c_{uv} = ν_{uv} and proceed by induction over u.

[figure: T^{u}T^{v}X; c_{uv}; T X; T^{u}SX; T^{u}ν_{X ,v}; ST^{v}X; ν_{T^{v}X ,u}; SSX; ξ; Sν_{X ,v}; ν_{SX ,u}; SX; u_{X}] (3.15)

For u = ε, using the unit law of S and the definition of ν_{ε} = ζ_{X}, the diagram simplifies to diagram 3.16. For the induction step, assume that diagram 3.15

[figure: T^{v}X; SX; ν_{v}; SSX; ζ_{SX}; ξ_{X}; SX; ν_{v}; ^{1^{SX}} = = = = = = = = = = = = = = = = =]  (3.16)

commutes for u, v ∈ W, and than show it commutes for w = 1u (similarly, of course for w = 2u). Consider diagram 3.17, where square (1) is T_{1} applied to

[figure: T_{1}T^{u}T^{v}X = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = T_{1}T^{u}T^{v}X; T_{1}T^{u}SX; T_{1}T^{u}ν_{X ,v}; (1); (4); T_{1}SSX; T_{1}ξ_{X}; T_{1}ν_{SX ,u}; T_{1}SX; T_{1}ν_{X ,uv}; (2)  (3); SSSX; α_{SSX}; Sξ_{X}; SSX; α_{SX}; (5); SSX; ν_{SX ,1u}; ξ_{SX}; ξ_{SX}; SX; ν_{X ,1uv}; ξ_{X}] (3.17)

the induction assumption (using T^{1u} = T_{1}T^{u}), square (2) and (4) the respective definitions of ν_{1u,SX} and ν_{1uv} (with ν_{SX ,1} = α_{SX}), square (3) the naturality of α and (5) the associativity of ξ. This concludes the proof that u is a monad morphism.

Finally, we have to show that u.ι_{1} = α. Since ι_{1,X} = c_{1,X} and α = ν_{1}, this reduces to u.c_{1} = ν_{1}. (And similarly for u.ι_{2} = β.) □

Proposition 3.1.9 Given two monads T_{1} = ⟨T_{1}, η_{1}, μ_{1}⟩, T_{2} = ⟨T_{2}, η_{2}, μ_{2}⟩, their coproduct is the monad T_{1+2} =^{def} ⟨T, η, μ⟩ with the action, unit and multiplication defined in definitions 3.1.1, 3.1.3 and 3.1.4 respectively.

Proof. In lemma 3.1.5, T_{1+2} has been shown to be a monad, and in lemma 3.1.8 the universal property of the coproduct has been shown. □

With the initial object in Mon_{Fin}(Cat) given by the identity monad Id_{Cat} (see §1.3.6 on page 17), we have the following corollary:

Corollary 3.1.10 The category Mon_{Fin}(Cat) has all finite coproducts.

3.1.4 Consequences of the Enrichment

!_{Categories} We have presented a construction of the coproduct of two monads on the category Cat, throughout which we have neglected the enrichment– the 2categorical properties. It should be stressed that this has been done in order to simplify the presentation, not because one can disregard the enrichment— in fact, the appropriate handling of the enrichment is the cornerstone of the theory developed in this thesis. We will now consider the various issues arising as consequences of the enriched setting.

Recall from §1.4.6 on page 33 that enriched categories in general have indexed limits; but since Cat has a terminal object which is the unit of the monoidal structure, one obtains the usual limits (and colimits) as a special case— so it makes indeed sense to define the diagram D_{X} as we have done. However, “everything is 2-everything”, or slightly more precise, the monads T_{1}, T_{2} are 2-monads, T_{1+2} has to be made into one, and all natural transformations are 2-natural transformations. Fortunately, Mon_{Fin}(Cat) is itself not a 2-category, so there is no corresponding universal property on the 2-cells (i.e. modifications between monad morphisms), which would mean all diagrams of §3.1.3 would have to bear 2-cells.

[figure: T^{vw}X; η_{j,w}^{v}; T^{vjw}X; T^{vw}Y; T^{vw}F; ⇒^{T^{vw}α}; T^{vw}G; η_{j,w}^{v}; T^{vjw}Y; T^{vjw}F; ⇒^{T^{vjw}α}; T^{vjw}G]  (3.18)

[figure: T^{vjjw}X; μ_{j,w}^{v}; T^{vjw}X; T^{vjjw}Y; T^{vjjw}F; ⇒^{T^{vjjw}α}; T^{vjjw}G; μ_{j,w}^{v}; T^{vjw}Y; T^{vjw}F; ⇒^{T^{vjw}α}; T^{vjw}G]  (3.19)

First, we can take the colimit of the ordinary (Set-enriched) functor D_{X} : F(G) → Cat in the Set-enriched category of all small categories as we have done; and this will be a colimit in the 2-category of all small 2-categories as well, since the diagram D_{X} considered as a 2-category only has identity 2-cells.^{3}

We can now define the action T on 2-cells: for a natural transformation α : F ⇒ G, precomposition with α induces a modification between the two cones given by F and G respectively; that this is a modification follows from the 2naturality of η_{1}, η_{2} and μ_{1}, μ_{2}. We can replace the morphism F by a 2-cell α : F ⇒ G in diagrams 3.1, giving diagrams 3.18 and 3.19. Hence there is a unique a 2-cell !_{α} :!_{F} ⇒!_{G}, which is the action of T on 2-cells.

3Similarly, the coproduct of two categories in Cat as an ordinary category enjoys the 2colimiting properties in Cat as a 2-category as well.

That η and μ are 2-natural follows from the 2-naturality of the components of D_{X}, just like naturality of η and μ follows from the naturality of the components.

3.1.5 An Alternative Construction

The previous construction does have some drawbacks: it is rather involved, and it does not generalize easily to finitary (as opposed to strongly finitary) monads. A more general construction does seem desirable, and a simple, elegant construction suggesting itself would be to take the coproduct as the free monad on the functor Q : Cat → Cat, which maps a category X to the following push-out in Cat:

[figure: X; η_{1}; T_{1}X; T_{2}X; η_{2}; QX]

where the free monad F T on a finitary endofunctor T : C → C is given inductively by (see [35, 39])

S_{n+1}(d) =^{def} d + T S_{n}(d) S_{0}(d) =^{def} d F T =^{def} colim_{n<ω} S_{n}

However, this simple approach does not take the multiplications into account, and hence the injections ι_{1}, ι_{2} would not be monad morphisms, since equation 1.4 does not hold. A more sophisticated approach is to consider monads in turns as algebras, constructing the coproduct as a colimit of algebras (see §6.2.2 on page 170).

3.2 Deciding the Equality

In this section, we will investigate the structure of the category T X. T X is the colimit of the diagram D_{X} in Cat, and by proposition 1.3.1, a colimit can be expressed as a coequalizer. We know how to construct coequalizers in Cat, so we just need to decode all this information.

The colimiting object colimD_{X} is a category, which has as objects equivalence classes of objects from ∐_{w∈W} T^{w}X; we will call these composed terms. We will give a reduction system which reduces any composed term to a unique normal form, hence deciding the equivalence. The morphisms of colimD_{X} are equivalence classes of paths <α_{1}, …, α_{n}> of morphisms α_{i} from ∐_{w∈W} T^{w}X, and we will consider normal forms and a similar reduction system for the morphisms as well. However, we will not give a decision procedure for the equality on morphisms, since we are not really concerned with equality of the paths, as it turns out that the more relevant characteristic of paths is their length.

In the subsequent chapters, when studying modularity, these normal forms will play a pivotal rôle; essentially, to see if a property P is modular, one investigates if P is preserved in passing from a term to its normal form, and if P is preserved when combining two normal forms.

In the rest of this section we will assume that the monads T_{1}, T_{2} are regular (see definition 2.4.3 on page 79), without explicitly requiring it every time.

3.2.1 The Coequalizer

We will now give an explicit construction of the action T X of the coproduct monad. By proposition 1.3.1, the colimit of D_{X} is given by the coequalizer of

∐_{d:u→v in F(G)} T^{u}X  [figure: F; G] ∐_{w∈W} T^{w}X  (3.20)

diagram 3.20, where on the left side, we have for any morphism d : T^{u}X → T^{v}X in D_{X} (with u, v ∈ W) the component T^{u}X of the coproduct, and the two functors F and G are defined as F (T^{u}X) =^{def} ι_{u}(T^{u}X) and G(T^{u}X) =^{def} ι_{v}(d(T^{u}X)) where ι_{u} and ι_{v} are the injections into the coproduct on the right.

Let us spell this out in more detail, according to the construction given in §1.5.3 on page 44. The set of objects of T X is the set of objects in ∐_{w∈W} T^{w}X, quotiented by the equivalence closure ≡_{O} of the relation ∼ given by

x ∼ η_{j,v}^{w}(x)  (3.21)
x ∼ μ_{i,t}^{u}(x)  (3.22)

for all i, j ∈ L and t, u, v, w ∈ W. We will give a normal form by orienting these equations and obtain a reduction system which we will then show to be complete. Intuitively, given any composed term t, we will collapse as many layers in t as we possibly can, and remove all quotes we can remove. For example, consider the two signatures Ω_{1} = {K_{1}}, Ω_{2} = {L_{1}}. The normal form for the composed term K('K('x)) ∈ T^{11}X will be K(K('x)), for ''x ∈ T^{12}X it will be x and for 'L(''K('x)) ∈ T^{1221}X it will be L('K('x)).^{4}

The morphisms are equivalence classes of paths <α_{1}, …, α_{n}> where α_{i} : x_{i} → y_{i} in T^{w}X for w ∈ W, and y_{i} ≡_{O} x_{i+1}. The paths are quotiented by the path congruence ≡_{M} generated by the relation ∼ given by

<α, β> ∼ <β.α>  if α, β composable  (3.23)
<α> ∼ <η_{j,v}^{w}(α)>  (3.24)
<α> ∼ <μ_{i,s}^{r}(α)>  (3.25)

By applying the same reduction system as for the objects, we are able to give a normal for paths <α> of length one. For longer paths, we develop the notion of a path of minimal length.

3.2.2 Normal Forms for Objects

The normal form sketched above corresponds to orienting equation 3.21 right-to-left, and equation 3.22 left-to-right.

Definition 3.2.1 (The Reduction System →_{Ob}) We define following reduction systems on the objects of ∐_{w∈W} T^{w}X:

→_{μ} =^{def} {x →_{μ} μ_{j,v}^{u}(x) | u, v ∈ W, j ∈ L, x ∈ T^{ujjv}X }
→_{η} =^{def} {η_{j,v}^{u}(x) →_{η} x | u, v ∈ W, j ∈ L, x ∈ T^{uv}X }
→_{Ob} =^{def} →_{η} ∪ →_{μ}

We now show that ↠_{Ob}, the transitive-reflexive closure of →_{Ob}, is complete, and hence obtain a decision procedure for the associated equality. We first tackle confluence. We show that →_{Ob} is confluent by showing that the two component systems →_{μ} and →_{η} are confluent, and that they commute. This will be the scope of the following three lemmas.

These lemmas will make heavy use of the algebra of words over L, and in particular the notation, definitions and lemmas of §1.7. We typically have two decompositions w = rst and w = xyz of a word w ∈ W, and a case distinction: if s and y are independent, then we can apply the naturality of the either μ or η (and for the latter, we additionally need regularity of η); and if they are not independent, we use • the fact that the unit is monic for confluence of →_{η},

4Note that we have to state which component of the coproduct a composed term comes from, since the terms from different components may look the same and yet have different normal forms. For example, there are terms K(''x) ∈ T^{12}X and K(''x) ∈ T^{11}X; and the former is in normal form, whereas the normal form for the second is K('x).

• the associativity of the multiplication for confluence of →_{μ}, and

• the unit law of the monad for the commutativity of ↠_{η} and ↠_{μ}.

Lemma 3.2.2 →_{η} is confluent.

Proof. We have to show that given two morphisms η_{j,v}^{w}, η_{i,s}^{r} in D_{X} such that wjv = ris, and given y_{1} ∈ T^{wv}X , y_{2} ∈ T^{rs}X such that η_{j,v}^{w}(y_{1}) = η_{i,s}^{r}(y_{2}), there is u ∈ W, x ∈ T^{u}X, and w′, v′, r′, s′ such that η_{i,v′}^{w′}(x) = y_{1}, η_{i,s′}^{r′}(x) = y_{2}. There are two cases here: if i and j are overlapping, then i = j, w = v and r = s, and we can use monicness of η.

If i and j are independent, then there is u ∈ W such that w_{0} = wjuis or w_{0} = riujv (with w_{0} =^{def} wjv). Suppose the former. By regularity of η_{j} (T^{w}

[figure: T^{jus}X; η_{j,us}; T^{us}X; T^{juis}X; η_{i,s}^{ju}; η_{j,uis}; T^{uis}X; η_{i,s}^{u}]  (3.26)

applied to the naturality square 3.26), there is x_{0} ∈ T^{wus} such that η_{j,us}^{w}(x_{0}) = y_{1}, and η_{i,s}^{wu}(x_{0}) = y_{2}. Hence, y_{1} →_{η} x_{0} and y_{2} →_{η} x_{0} as required. □

Lemma 3.2.3 →_{μ} is confluent.

Proof. Here, we have to show that given μ_{i,v}^{w}, μ_{j,s}^{r} such that wiiv = rjjs, then either w = r, i = j, v = s, or there are w′, v′, r′, s′ ∈ W such that

μ_{j,v′}^{w′}.μ_{i,v}^{w} = μ_{i,s′}^{r′}.μ_{j,s}^{r}  (3.27)

Let w_{0} =^{def} wiiv = rjjs. Again, we have two cases:

If ii and jj are independent, there is u ∈ W such that w_{0} = wiiujjs or w_{0} = rjjuiiv. Assume the former, then we have w′ =^{def} wiu, v′ =^{def} s, r′ =^{def} w and s′ =^{def} ujs. To obtain equation 3.27, apply T^{w} to the following naturality square of μ_{i} (where ujjs = v and wiiu = r):

[figure: T^{iiujjs}X; μ_{i,ujjs}; T^{iujjs}X; T^{iiujs}X; T^{iiu}(μ_{j,s}); μ_{i,ujs}; T^{iujs}X; T^{iu}(μ_{i,s})]

If w_{0} = rjjuiiv, then there is a similar naturality square for μ_{j}.

If ii and jj are not independent, but (by lemma 1.7.3) overlapping, then i = j; and either w = r and r = s; or w_{0} = wiiit or w_{0} = riiiv. For the former, let w′ =^{def} w, v′ =^{def} s, r′ =^{def} w and t′ =^{def} t, and apply T^{w} to the associativity law to show equation 3.27:

[figure: T^{iiit}X; μ_{i,T^{it}X}; T^{iit}X; T^{iit}X; T_{i}μ_{i,T^{t}X}; μ_{i,T^{t}X}; T^{it}X; μ_{i,T^{t}X}]

□

Lemma 3.2.4 ↠_{η} and ↠_{μ} commute.

Proof. We in fact show something stronger: ↠_{η} and ↠_{μ} subcommute (see §1.6.2 on page 46), i.e. given two morphisms e = η_{j,v}^{w}, m = μ_{i,t}^{s} in D_{X} such that wjv = siit (i.e. the target of e is the source of f), then there are either e′ = η_{j,v′}^{w′}, m′ = μ_{i,t′}^{s′} s.t. m.e = e′.m′, or m.e = 1_{wv}.

Let w_{0} =^{def} wjv = siit. If j and ii are independent (as defined in lemma 1.7.2), then there is a naturality square similar to the one in the proof of lemma 3.2.3.

If j and ii are not independent, by lemma 1.7.3 they are overlapping, hence i = j and either w = s and v = it, or s = iw and v = t. Then apply T^{s} to the unit laws (the left side for the first case, the second case for the second case)

[figure: T^{it}X; η_{i,T^{it}X}; T^{iit}X; T_{i}(η_{i,T^{t}X}); T^{it}X; T^{iv}X; μ_{i,T^{t}X}; = = = = = = = = = = = = = = = =; = = = = = = = = = = = = = = = =]

□

We can now show that ↠_{Ob}, the transitive-reflexive closure of →_{Ob}, is complete and hence obtain a decision procedure for the associated equality. To do this, we define the rank of a term t ∈ T^{w}X as rank(t) =^{def} |w| (where |w| is the length of the word w).

Lemma 3.2.5 ↠_{Ob} is complete.

Proof. First, ↠_{Ob} is confluent by the Hindley-Rosen lemma 1.6.3, since →_{η} and →_{μ} are confluent, and ↠_{η} and ↠_{μ} commute, by the three lemmas just shown.

To show termination of ↠_{Ob}, and hence completeness, note that in all rules of l →_{Ob} r, the rank of l is strictly greater than that of r and hence there can be no infinite reduction x_{1} →_{Ob} x_{2} →_{Ob} x_{3} . . .. □

Since ↠_{Ob} is complete, every object in t ∈ ∐_{w∈W} T^{w}X reduces to a unique normal form which we denote NF(t). This forms a decision procedure for the equivalence of the objects:

Lemma 3.2.6 Given t, t′ ∈ ∐_{w∈W} T^{w}X, Qt = Qt′ iff NF(t) = NF(t′).

Proof. NF(t) = NF(t′) iff t and t′ are related is the equational theory on ∐_{w∈W} T^{w}X generated by ↠_{Ob}. This theory is clearly the same as that induced by equations 3.21 and 3.22. □

3.2.3 Normal Forms for Morphisms

We now consider morphisms in the coequalizer of diagram 3.20. On the objects, the reduction system ↠_{Ob} gives us a normal form deciding the equivalence generated by diagram 3.20. It was obtained by orienting equations 3.21 and 3.22. Unfortunately, we can’t do the same with equations 3.23, 3.24 and 3.25. Obviously, to obtain a strongly normalizing system we would have to orient 3.23 left-to-right, obtaining a reduction system ↠_{Comp} on the paths. This system is confluent (by associativity of the composition), but it fails to commute with ↠_{η} (the system generated by equation 3.24, see 3.2.7 below), as the following examples shows. Let the monad T_{1} be given by a unary operation F, and the monad T_{2} by a unary operation G and rules

R_{2} = {G('y) → 'y}

and let α be the rewrite F('G('x)) → F(''x) in T^{12}X, and β : x → y be in X. Then there is the path <α, ''β>, which reduces by ↠_{Comp} to <''β.α>, and by ↠_{η} to <α, 'β>; this span cannot be completed. This doesn’t mean that one can’t find a complete reduction system to produce normal forms for the paths; it just means that the straightforward approach does not work. Since we do not need to effectively decide the equality on morphisms anyway, but are more interested in the length of these paths (in order to deal with strong normalisation), we will develop the notion of a path of minimal length: a path such that no equivalent path is shorter.

We will approach the problem as follows: we will first define a normal form for morphisms in ∐_{w∈W} T^{w}X, corresponding to a normal form for paths of length one by orienting clauses 3.24 and 3.25 above. We will then define the notion of a path of minimal length, and find necessary and sufficient characterisations of paths of minimal length. For this, we will investigate pairs of two morphisms the target of the first of which is equivalent to the source of the second, but which cannot be composed; these will be called incomposable pairs and they correspond to normal forms for clause 3.23.

Normal Forms for Morphisms in ∐_{w∈W} T^{w}X

Definition 3.2.7 (The Reduction System →_{Mor}) Define the reduction systems on the morphisms of ∐_{w∈W} T^{w}X:

→_{μ} =^{def} {α →_{μ} μ_{j,v}^{u}(α) | u, v ∈ W, j ∈ L, α : t → t′ ∈ T^{ujjv}X }
→_{η} =^{def} {η_{j,v}^{u}(α) →_{η} α | u, v ∈ W, j ∈ L, α : t → t′ ∈ T^{uv}X }
→_{Mor} =^{def} →_{η} ∪ →_{μ}

Lemma 3.2.8 →_{Mor} is complete, and every α : x → y in T^{w}X reduces to a unique normal form NF(α) : x′ → y′ s.t. for all β, Qα = Qβ iff NF(α) = NF(β).

Proof. Analogously to lemma 3.2.5 and 3.2.6. □

The mapping of terms and morphisms to their normal form can not be extended to an endofunctor on ∐_{w∈W} T^{w}X, since the presence of expanding or collapsing rewrites means that the normal form need not preserve the source and target of a morphism. For example, given the rewrite α : 'x → G('x) in T_{1}(X), then NF(α) = α which is in T_{1}(X) while NF('x) = x which is in X. Such a rewrite is called “layer-expanding”, since it introduces a new layer in a rewrite path. The dual notion (which is actually more important) is called “layer-collapsing”.

Definition 3.2.9 (Layer-collapsing and Layer-expanding) Let α : s → t be in T^{w}X, and NF(α) : s′ → t′ be its normal form. Then α is called layercollapsing at y ∈ T^{uv}X in T_{j} if t′ is in the image of η_{j}: there are u, v ∈ W, j ∈ L with t′ = η_{j,v}^{u}(y). Dually, α is called layer-expanding in T_{j} if the above holds for s′ instead of t′.

Note that a rewrite can be layer-expanding or layer-collapsing in both systems at the same time.

Lemma 3.2.10 Layer-expanding (layer-collapsing) rewrites are those for which the normal form of the source (target) is not the same as the source (target) of the normal form:

(i) α : s → t in T^{w}X is layer-expanding iff for NF(α) : s′ → t′,
s′ ≠ NF(s).
(ii) α : s → t in T^{w}X is layer-collapsing iff for NF(α) : s′ → t′,
t′ ≠ NF(t).

Proof. We prove the first clause; the second is proven analogously.

We can apply →_{μ} to a morphism α : x → y if and only if we can apply →_{μ} to its source x and target y. Further, whenever we can apply →_{η} to α, we can apply →_{η} to x and y. Hence, whenever α →_{Mor} α′, the source and target of α reduce as well. The only case in which we can apply →_{η} to x (or y) but not to α is if x = η_{j,v}^{u}(x′), but for all β : x′ → y′, η_{j,v}^{u}(β) ≠ α (and so α ↛_{η}β), which is precisely the definition of layer-expanding. □

Note that the existence of an α : x → y above such that for all β : NF(x) → x′, η_{j,v}^{u}(β) ≠ α is exactly the definition of η_{j,v}^{u} being expanding at NF(x), hence if both monads are non-expanding, we have s′ = NF(s) for all rewrites α : s → t and their normal form NF(α) : s′ → t′.

Normal Forms for Paths

As mentioned above, for paths <α_{1}, …, α_{n}>, we do not get a complete reduction system deciding the equivalence. Yet, we merely want to reason about their length, in the light of lemma 5.2.2 below which says that the coproduct monad is not strongly normalizing if there are arbitrarily long paths in the coproduct. Hence we introduce the notion of minimal length— a path is of minimal length if there is no equivalent path which is shorter.

We need to find a sufficient and necessary characterisation for paths of minimal length. This will lead us to the notion of incomposable pairs, two morphisms α, β such that the target of α is equivalent to the source of β (hence they form a path) but α and β are incomposable, and moreover we can’t find two morphisms equivalent to α and β each which are composable.

Definition 3.2.11 (Minimal Length) A path A = <α_{1}, …, α_{n}> is of minimal length iff

(i) All elements of the path are normal forms: for i = 1, …, n, α_{i} = NF(α_{i}).

(ii) No equivalent path is shorter: B ≡ A ⇒ |A| ≤ |B|

In other words, a path A = <α_{1}, …, α_{n}> is of minimal length if all α_{i} are in normal form, and α_{i} and α_{i+1} cannot be composed in T^{w}X, or are an incomposable pair:

Definition 3.2.12 (Incomposable Pair) For α in T^{w}X, β in T^{v}X, (α, β) are an incomposable pair if both are in normal form and the target of α is equivalent to the source of β, but they cannot be composed, nor are they equivalent to any α′, β′ which can be composed: NF(δ_{t}(α)) = NF(δ_{s}(β)) and ∀α′, β′.NF(α′) = NF(α) ∧ NF(β′) = NF(β) ⇒ δ_{t}(NF(α)) ≠ δ_{s}(NF(β))

A path A = <α_{1}, …, α_{n}> is of minimal length iff (α_{i}, α_{i+1}) for i = 1, …, n−1 are incomposable pairs. To find a characterisation of incomposable pairs, reconsider the example on page 114 above. There, we had a pair of two morphisms α, 'β which were not composable. This is not an incomposable pair, since 'β ≡_{M} ''β, which is composable with α. Hence we modify the example: consider the two monads given by the following two term rewriting systems (omitting the signatures):

                     R_{1} = {F(F('x)) → H('x)}

R_{2} = {G('y) → 'y}

Then there is the incomposable pair (α_{1}, α_{2}) with

                 α : F('G('F('x))) → F(''F('x))
                  β : F(F('x)) → H('x)

This situation is prototypical. The point here is that α is layer-collapsing, i.e. there is y ∈ T^{11}X such that the target of α is η_{2,1}^{1}(y). But that alone is not sufficient, since for any rewrite α′ : y → y′, there would also be a rewrite η_{2,1}^{1}(α′) which is composable with α. The point here is that we can apply μ_{1} to y, so the source of β is in the image of μ_{1}, but that for all β′ : y → y′′, μ_{1}(β′) ≠ β. This means exactly that μ_{1} is expanding at y— we say β is μ-expansive.

Of course, there is also the dual situation, in which β would be layer-expan-ding. The precise characterisation is given by the following lemma:

Definition 3.2.13 (μ-Expansive and μ-Contractive) α : x → y is said to be μ-expansive at z ∈ T^{ujjw}X, if for its normal form NF(α) : x′ → y′ there are u, w ∈ W, j ∈ L, with μ_{j,w}^{u}(z) = x′ s.t. μ_{j,w}^{u} is expanding at z: for all β : z → z′, μ_{j,w}^{u}(β) ≠ NF(α).

Dually, α : x → y is μ-contractive at z ∈ T^{ujjw}X if for its normal form NF(α) : x′ → y′, we have μ_{j,w}^{u}(z) = y′ s.t. μ_{j,w}^{u} is collapsing at z: for all β : z′ → z, μ_{j,w}^{u}(β) ≠ NF(α).

Lemma 3.2.14 Given two α : x_{1} → y_{1}, β : x_{2} → y_{2} in normal form, such that Q(y_{1}) = Q(x_{2}). Then (α, β) are an incomposable pair iff

• Either there are r, s ∈ W, i, j ∈ L, i ≠ j and z ∈ T^{riis}X such that

(i) α is layer-collapsing at z, with y_{1} = η_{j,is}^{ri}(z), and (ii) β is μ-expansive at z, with x_{2} = μ_{i,s}^{r}(z), and for all β′ : z → z′,

μ_{i,s}^{r}(β′) ≠ β.

• or there are r, s ∈ W, i, j ∈ L, i ≠ j and z ∈ T^{riis}X such that

(i) β is layer-expanding at z, with x_{2} = η_{j,is}^{ri}(z), and (ii) α is μ-contractive at z, with y_{1} = μ_{i,s}^{r}(z) andfor all β′ : z′ → z,

μ_{i,s}^{r}(β′) ≠ β.

Proof. We first prove sufficiency. Assume the first of the two alternatives (the second is proven analogously), then we have y_{1} →_{η} z →_{μ} x_{2}. Clearly α and β cannot be composed. Suppose there were β′ with β′ ≡_{M} β which is composable with NF(α), then β′ would be in T^{rijis}X; and since β′ and β should be equivalent, and β is a normal form, β′ ↠_{Mor} β. But the only possible reduction would be β′ →_{η} β′′ →_{μ} β, for some β′′ : z → z′′ with μ_{j,v}^{w}(β′) = β, which is a contradiction (since β is μ-expansive). On the other hand, if there were α′ with Qα = Qα′ and α′ composable with NF(β), then the rank of α′ would be the same as for β, which is rank(α) − 2; so α′ cannot reduce to α, and neither the other way around (since α is a normal form), so there there can be no such α′.

For necessity, we know that Q(y_{1}) = Q(x_{2}) but δ_{t}(NF(α)) ≠ δ_{s}(NF(β)). Hence y_{1} ≠ δ_{t}(NF(α)) (then by lemma 3.2.10, α is layer-collapsing), or x_{2} ≠ δ_{s}(NF(β)) (then by lemma 3.2.10 β is layer-expanding). Assume the former (corresponding to the first clause above— the latter gives the second clause), then (by definition 3.2.9) there are u, v ∈ W, i ∈ L and z ∈ T^{uv}X s.t. y_{1} = η_{j,v}^{u}(z) (this being clause (i)). Since β is not composable with α, nor equivalent to anything composable with α, the source of β (but not β itself) has to lie in the image of μ; and this in such a way that μ and η are natural not over each other. In other words, there is x s.t. y →_{η} z →_{μ} x, but x ≠ y and there is no z′ with y →_{μ} z′ →_{η} x. This is only the case if x_{2} = μ_{i,s}^{r}(z) with i ≠ j, and i and j are not independent, i.e. w = ri, v = is; and further, β is in the image of μ: for all β′ : z → z′, μ_{i,s}^{r}(β′) ≠ β. All of this constitutes clause (ii). □

3.3 The Coequalizer of Strongly Finitary Monads

The coequalizer of two strongly finitary monads is constructed as a pointwise colimit, just like the coproduct. Given two monads T_{1} = ⟨T_{1}, η_{1}, μ_{1}⟩, T_{2} = ⟨T_{2}, η_{2}, μ_{2}⟩ on Cat,^{5} and two monad morphisms α, β : T_{1} ⇒ T_{2}. Then for a category X, there is the coequalizer

[figure: T_{1}X; α_{X}; βX; T_{2}X; q; Q]

Mapping every X to the coequalizer Q above would give an endofunctor on Cat, but it would fail to be a monad, since one cannot construct a multiplication. To get around this, we take the same approach as for the coproduct: we build a large diagram from all possible combinations of T_{1} and T_{2} which is weakly ω-filtered, and closed under application of T_{1} and T_{2}. Then applying T_{1} or T_{2} to the colimit C of the diagram will give rise to a cone over the diagram, and hence a morphism out of T_{1}C. This way, we can construct a morphism out of the diagram built at the colimit of another diagram— i.e. the constructed endofunctor applied twice— and this will give us the multiplication of the monad.

Clearly, the vertices of the diagram should be same as those for the coproduct diagram— iterated combinations of T_{1} and T_{2}. For the edges, we will need α and β, in any context, under application of T_{1} and T_{2}, and the multiplication of the two monads. Surprisingly, we do not need the units of the two monads.

Formally, the diagram is given by a graph Q, which has

Edges: V (Q) =^{def} L^{+}
Vertices: E(Q) =^{def} {m_{j,v}^{w} : wjjv → wjv | w, v ∈ W, j ∈ L} ∪
{a_{v}^{w} : w1v → w2v | w, v ∈ W } ∪
{b_{v}^{w} : w1v → w2v | w, v ∈ W }

(Recall that L^{+} is the set of non-empty words over the alphabet L.) Then, for a category X ∈ Cat, we define the functor Q_{X} : F(Q) → Cat as the transpose of the graph morphism q_{X} : G → U(Cat), which is given as follows:

On the vertices: q_{X} (w) =^{def} T^{w}(X)
On the edges: q_{X} (m_{j,v}^{w}) =^{def} T^{w}(μ_{j,T^{v}(X)})
q_{X} (a_{v}^{w}) =^{def} T^{w}(α_{T^{v}(X)})
q_{X} (b_{v}^{w}) =^{def} T^{w}(β_{T^{v}(X)})

5Again, these monads are actually enriched, but in this section, we will altogether pass over this fact.

The endofunctor T : Cat → Cat, which is the action of the coequalizer monad, maps X to colim Q_{X}, and a functor F : X → Y to the morphism colim Q_{X} → colim Q_{Y}, induced by precomposing the colimiting cone over Q_{Y} with F; since all components of the diagram are natural transformations, this yields a cone over Q_{X}, and hence a morphism !_{F} : colim Q_{X} → colim Q_{Y}.

Let c : Q_{X} → colimQ_{X} be the colimiting cone, then the unit η of the monad is given by [figure: X; η_{2}; T_{2}X; c_{2}; colim Q_{X}]. The multiplication μ, as mentioned above, is given by the fact that Q_{X} is a weakly ω-filtered diagram (which is easy to check — from any vertex, there is a morphism into T_{2}X which is sufficient for weak filteredness, and for ω-filteredness, card(F(Q)) ≤ ℵ_{0}). Then T T X = colim Q_{colim Q_{X}}, and T_{1} preserves weakly ω-filtered colimits: T_{1}colim Q_{X} ≅ colim T_{1}(Q_{X}). T_{1}(Q_{X}) is again in Q_{X}, so the colimiting cone over Q_{X} gives a colimiting cone over T_{1}Q_{X}, and ultimately over Q_{colim Q_{X}} as well, which induces a morphism colimQ_{colim Q_{X}} → colimQ_{X}, which is the multiplication. The proof of the monad laws then proceeds along the same lines as for the coproduct.

This gives the monad T =^{def} ⟨T, η, μ⟩, and the monad morphism q : T_{2}X → T X (given by the colimiting cone c at T_{2}X), both of which form the coequalizer of the two monad morphisms α, β.

It remains to show that it is indeed the coequalizer, which is shown by the universal property. Given any other monad S = ⟨S, ζ, ξ⟩, and a monad morphism γ : T_{2} → S such that γα = γβ, there has to be a unique u : T → S such that uq = γ. This unique u is constructed by giving by a cone ν_{X} : Q_{X} → SX (for all categories X), which is defined inductively. The base case is ν_{1} =^{def} γ_{X} α_{X} = γ_{X} β_{X}, and ν_{2} =^{def} γ. If ν_{w} : T^{w}X → SX is given, we obtain ν_{1w} and ν_{2w} by the following diagram:

\begin{matrix}T_{1}T^{w}X & \overline{T_{1}ν_{w} ^{}} & T_{1}SX \\ T_{2}T^{w}X & \overline{T_{2}ν_{w} ^{}} & T_{2}SX & [figure: α_{SX}; β_{SX}] & \overline{γ_{SX} ^{}} & SSX & ξ_{X}^{}SX \end{matrix}

where γ_{SX}.α_{SX} = γ_{SX}.β_{SX} because γ coequalizes α and β. Hence, we have constructed the coequalizer of α and β:

Proposition 3.3.1 Given two strongly finitary monads T_{1}, T_{2}, and two monad morphisms α, β : T_{1} → T_{2}, the monad T = ⟨T, η, μ⟩ as defined above is their coequalizer in Mon_{Fin}(Cat).

And with proposition 1.3.1 (colimits are given by coproducts and coequalizers) and corollary 3.1.10 (Mon_{Fin}(Cat) has all coproducts), we have the cocompletness of Mon_{Fin}(Cat):

Corollary 3.3.2 The category Mon_{Fin}(Cat) has all small finite colimits.

3.4 Summary and Conclusion

This chapter started with the claim that “structuring operations are colimits”. While not all structuring operations can be expressed with colimits, many important ones can be; and while this may not be the ultima ratio it may at least serve as a useful working hypothesis, in particular since we are going to concentrate on one particular operation, the one which hitherto has received most attention in the term rewriting literature: the disjoint union of two term rewriting systems.

The working hypothesis has two ramifications. Firstly, it means we have to look at the colimits in the category of semantic presentations, the category of finitary monads on Cat. To this end, we have given a detailed construction of the coproduct of two monads, and we have sketched the construction of the coequalizer. Together, this gives the existence of all colimits. Secondly, compositionality can now be given a precise meaning: a semantics is compositional if the mapping from syntactic presentations to semantics representations preserves colimits. Here, this is shown by the existence of a right adjoint for the mapping from the category of term rewriting systems to the category of monads, and it means in particular that the coproduct of two monads arising from term rewriting systems Θ_{1}, Θ_{2} is isomorphic to the theory of their disjoint union:

T_{Θ_{1}+Θ_{2}} ≅ T_{Θ_{1}} + T_{Θ_{2}}

This result is important because results about the coproduct monad now pertain to the disjoint union — e.g. if we now show that the coproduct is confluent, then this will mean that the disjoint union of two term rewriting systems is confluent as well.

Apart from constructing the coproduct, we have developed a theory about “equality of objects and morphisms in the coproduct”. The coproduct essentially consists of composed terms, which are elements of ∐_{w∈W} T^{w}X, quotiented by an equivalence relation which identifies variables and collapses layers. We have given a decision procedure for this equality, by giving a normal form for the equivalence. This will aid us in reasoning about the coproduct.

Morphisms in the coproduct are equivalence classes of paths of morphisms from ∐_{w∈W} T^{w}X; here, our main attention has been the length of these paths, since when considering modularity of strong normalization we will show that the coproduct is strongly normalizing if there is an upper bound on the length of the paths in the coproduct. Instead of developing a normal form for the morphisms, we have developed the notion of minimal length for paths — a path being of minimal length if there is no equivalent path which is shorter.

In conclusion, this chapter has completed the demonstration of the compositionality of the semantics, and has set up the technical machinery needed to reason about the modularity of confluence and strong normalization, as we will do in the next two chapters.

Modularity of Confluence

In this chapter, we will prove a categorical version of Toyama’s theorem [88]: the disjoint union of two term rewriting systems is confluent iff the two term rewriting systems are. In the light of the results of the previous chapter, this means that the coproduct of two regular monads is confluent iff the two monads are.

The coproduct monad has been defined as the colimit of the diagram D_{X}. Proposition 1.3.1 from page 16 describes how to construct the colimit of a diagram from coproducts and coequalizers, so much of the proof that the coproduct is confluent can be done in a more abstract setting, investigating the preservation of confluence under the formation of coproducts and colimits in Cat. But even before we embark on this, we have to define what it means for a category and a monad to be confluent. This turns out to be a simple extension of the definition of confluence for relations, but it requires a little more effort to show that this new, semantic definition is equivalent to the old, syntactic one.

It should be stressed that the parts of this chapter dealing with the preservation of confluence are solely concerned with regular monads, and nowhere depend on the fact that these monads arise from term rewriting systems (even if we use term rewriting systems and signatures as examples.) This allows us to prove a slightly more general theorem than the original [88].

Structure of the Chapter

• In §4.1, we will define confluence for categories and monads on Cat. We call this the semantic notion of confluence. We will show that the semantic notion coincides with the syntactic notion, i.e. the monad T_{Θ} is confluent according to our definition iff the term rewriting system Θ is.

• In §4.2, we will consider the preservation of confluence under formation of coequalizers in Cat. (Preservation of confluence for the coproduct of two categories is trivial.) We will introduce the notion of a witness of a term, and show that the coequalizer preserves confluence if any two equivalent objects have a common witness.

• We will then apply this technique in §4.3 to the coequalizer which gives us the colimit of the diagram D_{X}. We show that the normal form of a term t with respect to the induced equivalence, as defined in §3.2.2, is a witness of t. We then conclude that the coequalizer of D_{X} preserves confluence, and hence the coproduct of two regular non-expanding confluent monads is confluent, the main result of this chapter.

• In §4.4, we will drop the non-expanding requirement and investigate quasinon-expanding monads (see §2.4.4 on page 85). Extending the main result of §4.3, we will show that the coproduct of two regular quasi-non-expanding confluent monads is confluent.

4.1 A Semantic Definition of Confluence

We will first extend the well-known definition of confluence for preorders to confluence of categories and monads. We then show that this semantic definition coincides with the usual, syntactic definition which talks about derivations of terms — i.e. that the monad given by a term rewriting system Θ is confluent according to our new, semantic definition if and only if the system Θ is confluent according to the old, syntactic definition. This will form proposition 4.1.7, the main result of this section.

4.1.1 Confluent Monads

Recall from §1.6.2 on page 46 that a preorder X = (X_{0}, ≥) is confluent if for all elements x, y, z ∈ X_{0} such that x ≥ y and x ≥ z (called spans or co-initial cells), there is a completion: an element u ∈ X_{0} such that y ≥ u, z ≥ u.

When extending this definition to categories, one has to decide whether this completion is required to commute; i.e. given α, β in diagram 4.1, we will always require γ, δ to exist, but do we require diagram 4.1 to commute? We will in

[figure: x; y; α; z; β; u; δ; γ]  (4.1)

general require it not to commute, since this is closer to what is happening with term rewriting systems; if it always commutes, we will call the category commuting confluent (and we can show modularity for both confluence and commuting confluence). Confluence of a category X coincides with the confluence of the associated preorder J(X), obtained by identifying all morphisms with the same source and target (see page 43).

Further, a term rewriting system Θ = (Ω, R) is confluent if all spans in ↠_{R} can be completed; but here we have to assume that all spans of variable rewrites can be completed by variable rewrites, which is equivalent to the preorder X being confluent. Hence, a monad T is confluent if T X is confluent whenever X is.

Definition 4.1.1 (Confluence) A category C is confluent if for any two morphisms α : x → y, β : x → z there are morphisms γ : y → u, δ : z → u. C is commuting confluent if additionally γ.α = δ.β.

A monad T = ⟨T, η, μ⟩ on Cat is (commuting) confluent if for all (commuting) confluent categories X, T X is (commuting) confluent.

Our definition coincides with Stell’s [82, pg. 105], but is different from Hilken [29], where confluence is what is here called commuting confluence, and from Jay [31], where a confluent category is a category enriched over confluent orders.

The reason for introducing two different concepts here (confluence vs. commuting confluence) is that commuting confluence is strictly stronger than confluence. For example, the term rewriting system G = (Σ_{G}, R_{G}) in figure 4.1 is confluent,^{1} but not commuting confluent: the span in diagram 4.2 (obtained by applying

Σ_{G} = { e_{0}, I_{1}, o_{2} }

 R_{G} = \{ \begin{matrix}o(e, 'x) → 'x, & o(I('x), 'x) → 'x, \\ o(o('x)'y, 'z) → o('x, o('y, 'z)), & o(I('x), o('x, 'z)) → 'z, \\ o('y, e) → 'y, & I(I('x)) → 'x, \\ I(e) → e, & o('x, I('x)) → e, \\ I(o('x, 'y)) → o(I('x), I('y)), & o('y, o(I('y), 'x)) → 'x\} \end{matrix}

Figure 4.1: A Confluent Term Rewriting System for Group Theory the second and third rule respectively) can be completed again (by the first and fourth rule, respectively), but this diagram does not commute in the monad T_{G} on

1This may not be evident on first glance, if one has not seen this term rewriting system before, but it is in fact a rather famous confluent system, obtained by orienting the equations of group theory as term rewrite rules, and making the system confluent by adding in additional rules, the so-called Knuth-Bendix completion [43, 41].

                      o(o(I('x), 'x), 'z)

[figure]

                  o(e, 'z)      o(I('x), o('x, 'z))

[figure]

                             'z

(4.2)

Cat given by the term named-reduction algebra (see definition A.1.8 on page 183 below).

On the other hand, commuting confluence is a stronger property; a term rewriting system is commuting confluent if it is confluent without overlapping rules (hence no spans like in diagram 4.2 above), and if we can show modularity of commuting confluence, this is a different result than modularity of confluence; hence, we keep both notions, and show modularity of both. Essentially, in our proofs if we only make sure there is at least one completion of any span, we can show modularity of confluence, and for modularity of commuting confluence, we need to do some more work and show the completions actually commute.

4.1.2 Confluent Term Rewriting Systems

The above definition of confluent monad was preceded by a sentence arguing why this definition is the one “making sense”. If we want to be able to relate results about confluent monads to confluent term rewriting systems, we have to formally show that these two notions coincide by showing that an ordinary TRS Θ is confluent by the syntactic definition from §1.6.2 if and only if the monad T_{Θ} is confluent by the semantic definition 4.1.1.

Recall from definition 1.6.1 that →_{R} is the one-step reduction relation induced by a term rewriting system, ↠_{R} the many-step reduction relation, and from §1.6.2 on page 46 that an (ordinary) term rewriting system Θ = (Ω, R) is confluent if ↠_{R} is confluent. Further, recall from definition 2.3.13 that →_{X} the congruence closure of the variable rewrites for a preorder X, and from proposition 2.3.14 that all reductions in T_{Θ}(X) are given as sequences of either one-step reductions, or variable rewrites:

T_{Θ}(X) = (→_{R} ∪ →_{X})^{∗}

It is easy to see that if T_{Θ} is confluent, then Θ is confluent (note that a discrete preorder is confluent, and use corollary 2.3.15: T_{Θ}(X) = ↠_{R} if X is discrete). In the other direction, we use proposition 2.3.14. By assumption, both →_{X} and →_{R} are confluent. Unfortunately, they do not commute, that is we do not have a completion property like the diagram 4.3 otherwise we could use the Hindley-Rosen

\begin{aligned}& x \\ y & X ; \underline{↞} & z & ^{R \overline{↠}} \\ u & X ; \underline{↞} & ^{R  \overline{↠}} \end{aligned}  (4.3)

lemma 1.6.3. Let us first see why they do not commute: given the term rewriting system D = ({G, F}, F('x, 'x) → G('x)), and the preorder X = ({a, b, c, d}, ≥), ordered as a ≥ b, a ≥ c, b ≥ d, c ≥ d, a ≥ d (both of which are obviously confluent), then there is the span in (4.4) which cannot be completed as above. (In

                       \begin{matrix}F & ( & 'a, 'a & ) \\ F('b, 'c) & X_{\underline{}} & G('a) & ^{R ^{\overline{}}} \end{matrix}(4.4)

the term F('x, 'x), 'x is sometimes called a δ-redex; and in the span above, the rewrite on the left is said to destroy δ-redexes). We can complete spans like this by first adding another variable rewrite to the rewrite on the left.

This means that →_{R} is strongly extendable over →_{X} as defined by Kahrs [34, pg 19ff]. He shows that if two relations are confluent, and one is strongly extendable over the other, which additionally is strongly normalizing, then their union is confluent as well. Here, we can not assume that →_{X} is strongly normalizing, but we can show that the additional rewrites do not destroy any more δ-redexes and that they (but only they) commute with →_{R}. Somewhat lost for words, as one tends to be when christening new exotic and rather abstract concepts, we say that →_{X} is coherently extendable over →_{R}, and we can prove a variation of Kahrs’ lemma that the union of two confluent relations, in which one is coherently extendable over the other, is confluent.

Definition 4.1.2 (Coherent Extendability) A relation →_{R} ⊆ X × X is coherently extendable over →_{S} ⊆ X × X, if

(i) there is a subrelation →_{S_{0}} ⊆ →_{S} (called the commuting subrelation)

that commutes with →_{R} (ii) and for all x, y, z ∈ X such that x ↠_{R} y, x ↠_{S} z, there are

u, v ∈ X such that x  \overline{_{S ↠}} z

u S_{0} ; ↓ ↓

y R ; ↓ ↓  \overline{_{S ↠}} vR ; ↓ ↓

Lemma 4.1.3 Given two confluent relations →_{R}, →_{S} ⊆ X × X such that →_{R} is coherently extendable over →_{S} and the commuting subrelation →_{S_{0}} is confluent, then →_{R} ∪ →_{S} is confluent as well.

Proof. Recall that by equation 1.24 from §1.5.2 we have

(→_{R} ∪ →_{S})^{∗} = (↠_{S}; ↠_{R})^{∗}  (4.5)

Diagram 4.6 shows that ↠_{S}; ↠_{R} commutes: the squares (2) are the coherent extendability of →_{R} over →_{S}, square (1) is confluence of →_{S}, square (3) is the

\begin{aligned}& \overline{S ↠} & \overline{R  ↠} \\ & (1) & (2) \\ S ; ↓ ↓ & \overline{S ↠} & S ; ↓ ↓ & \overline{S_{0} ↠} & \overline{R ↠} & S ; ↓ ↓ \\ (3) & (4) \\ (2) & S_{0} ; ↓ ↓ & \overline{S_{0} ↠} & S_{0} ; ↓ ↓ & \overline{R ↠} & S ; ↓ ↓ \\ (4) & (5) \\ R ; ↓ ↓ & \overline{_{S ↠}} & R ; ↓ ↓ & \overline{_{S ↠}} & R ; ↓ ↓ & \overline{_{R ↠}} & R ; ↓ ↓ \end{aligned}  (4.6)

confluence of the commuting subrelation →_{S_{0}}, square (4) is →_{R} commuting with →_{S_{0}}, and (5) is confluence of →_{R}.

Hence (↠_{S}; ↠_{R})^{∗} is confluent, and any relation P such that P^{∗} = (↠_{S}; ↠_{R})^{∗}, so by equation 4.5, →_{R} ∪ →_{S} is confluent. □

4.1.3 Equivalence of the Two Notions

We can now use lemma 4.1.3 to show that the semantic definition 4.1.1 of confluence coincides with the syntactic definition from §1.6.2. We will first exhibit the commuting subrelation of →_{X}, and then show that →_{R} is coherently extendable over →_{X}. First, note that →_{X} is confluent if X is; this is shown by structural induction. Then the commuting subrelation will consist of the congruence closure of those variable rewrites which do not destroy any δ-redexes, or in other words do no rewrite the same variable to different variables:

Definition 4.1.4 Let →_{X}^{C} be the smallest relation on T_{Ω}(X) such that t →_{X}^{C} s iff s = t[y_{1}/x_{1}, …, y_{n}/x_{n}] with y_{i}, x_{i} ∈ X and x_{i} ≥ y_{i} for i = 1, …, n.

That →_{X}^{C} is confluent is fairly easy to see, since any span can be completed pointwise in the variables of the substitution. To show that it commutes with →_{R}, assume that there is a term t ∈ T_{Ω}(X) such that t = C[σ(l)] for a rule (Y ⊢ l → r) ∈ R and a substitution σ : Y → T_{Ω}(X), and that x_{i} ≥ y_{i} for i = 1, …, n. Let s =^{def} C[σ(r)] and we have a span t →_{R} s, t →_{X}^{C} t[y_{i}/x_{i}]_{i=1,... ,n}. Then there is a completion s →_{X}^{C} s[y_{i}/x_{i}]_{i=1,... ,n} and C[σ(l)][y_{i}/x_{i}] →_{R} C[σ(r)][y_{i}/x_{i}]. From the following lemma we obtain the coherent extendability of →_{R} over →_{X}. It shows that any rewrite in →_{X} can be extended by one from →_{X}^{C} into one from →_{X}^{C} by pointwise completing all destroyed δ-redexes with rewrites which do not destroy δ-redexes themselves.

Lemma 4.1.5 For all s, t ∈ T_{Ω}(X) such that t →_{X} s, there is u ∈ T_{Ω}(X) such that s →_{X}^{C} u and t →_{X}^{C} u.

Proof. Let X = {x_{1}, …, x_{n}}. We are going to construct a sequence s′_{0}, …, s′_{n} ∈ T_{Ω}(X) of terms, starting with s′_{0} = s, and ending with s′_{n} = u. For 1 ≥ i ≥ n, let R(x_{i}) =^{def} {y ∈ X | x_{i} ≥ y} (this can be thought of as the set of reducts of x_{i}). Then by confluence of X, there is z_{i} ∈ X such that ∀y ∈ R(x_{i}). y ≥ z_{i} (i.e. we can complete any spans created by the different reducts of x_{i}). Let s′_{i} = s′_{i−1}[z/y_{1}, …, z/y_{m}] with R(x_{i}) = {y_{1}, …, y_{m}}, then s′_{i−1} →_{X}^{C} s′_{i}.

Let u =^{def} s′_{n}, then s →_{X}^{C} s′_{1} →_{X}^{C} s′_{2} … s′_{n} = u; and further, t →_{X}^{C} u, since

u = t[z_{i}/x_{i}]_{i=1,... ,n} and x_{i} ≥ y_{i}. □

Lemma 4.1.6 The term rewriting system Θ = (Ω, R) is confluent iff if the monad T_{Θ} on Pre is confluent.

Proof. We have to show that the term rewriting system Θ = (Ω, R) is confluent iff the term reduction algebra T_{Θ}(X) is confluent whenever the preorder X is confluent. Right-to-left, by corollary 2.3.15 a discrete preorder X is always confluent, hence T_{Θ}(X) will be confluent, and so will be ↠_{R}.

Left-to-right, assume that ↠_{R} is confluent and that X is confluent. From lemma 4.1.5 it follows that →_{R} is coherently extendable over →_{X}, with →_{X}^{C} being the commuting subrelation. Since →_{X}^{C} is confluent and commutes with →_{R}, by lemma 4.1.3 (→_{R} ∪ →_{X})^{∗} is confluent, and by proposition 2.3.14 (→_{R} ∪ →_{X})^{∗} = T_{Θ}(X), hence T_{Θ}(X) is confluent. □

The previous lemma talks about the monad T_{Θ} on Pre given by the term reduction algebra; it remains to make the final link to the monad on Cat, which is given by the named reduction algebra (definition A.1.8), and show that confluence of that monad coincides with confluence of Θ.

Proposition 4.1.7 The term rewriting system Θ = (Ω, R) is confluent iff the monad T_{Θ} on Cat is confluent.

Proof. We show that the monad T_{Θ} on Cat is confluent iff the monad T_{Θ} on Pre is confluent, and use lemma 4.1.6.

Left-to-right, given a confluent preorder X, we have to show the term reduction algebra T_{Θ}(X) is confluent. By equation 1.25 we have J(I(X)) = X (where I : Pre → Cat is the inclusion of preorders into categories, see page 42), hence if X is confluent, so is I(X) and hence because the monad T_{Θ} on Cat is confluent, T_{Θ}(I(X)) is confluent, which means J(T_{Θ}(I(X))) is confluent, and by equations A.15 and 1.25, J(T_{Θ}(I(X))) = T_{Θ}(J(I(X))) = T_{Θ}(X), hence T_{Θ}(X) is confluent as required.

Right-to-left, given a confluent category X, we know J(X) is confluent, and hence T_{Θ}(J(X)), and by equation A.15, T_{Θ}(J(X)) = J(T_{Θ}(X)), hence T_{Θ}(X) is confluent, making the monad T_{Θ} confluent. □

That the implication “Θ confluent ⇒ T_{Θ} confluent” is harder to prove than the other way is an indication that we have managed to incorporate more properties into the definition without actually strengthening it. The definition has become less axiomatic, but easier to work with — something one would like from a semantic definition.

4.2 Preservation of Confluence for Coequalizers

We have postulated above that most structuring operations on term rewriting systems are constructed as colimits. In our category of semantic representations, these are colimits of monads, which in turn are constructed pointwise as colimits of diagrams in Cat. Reasoning about preservation of confluence for any structuring operation then amounts to reasoning about preservation of confluence for colimits of certain diagrams like D_{X} for the coproduct. The colimit of these diagrams can be calculated using coproducts and coequalizers in Cat (proposition 1.3.1). Breaking down the reasoning further, we have to reason about preservation of confluence for coproducts and coequalizers. That coproducts preserve confluence is nearly trivial, since the coproduct does not identify any objects or morphisms. This leaves us with the preservation of confluence under coequalizers, which will be the scope of this section. In the next section, we will apply the techniques developed in this section to prove the modularity of confluence for the coproduct of two monads.

We will attempt to give an abstract characterisation (of the categories and functors involved) which makes the coequalizer of two functors F, G confluent:

[figure: X; F; G; Y; Q; Z]

Recall from §1.5.3 on page 44 that the coequalizer Z of the two functors F, G is a category which has as objects equivalence classes of objects from Y, and as morphisms (equivalence classes of) paths in a graph Z_{0}, the edges of which are morphisms from Y. We first show a lemma which states that Z will be confluent if Y is, and we can complete any span of two morphisms in Y the sources of which are equivalent in the equivalence relation induced on the objects: this property will be referred to as the diamond property, since it corresponds to a “one-step completion property modulo F ”. We then introduce a technique which can be used to show that the coequalizer (or more precisely, the category Y with respect to the coequalizer) has said diamond property.

Further, we can systematically strengthen the obtained properties to be sufficient for the preservation of commuting confluence. This will allow us to prove modularity of both confluence and commuting confluence in the same framework.

4.2.1 The Diamond Property

Definition 4.2.1 (Diamond Property) Given a functor F : Y → Z, the category Y has the diamond property with respect to F, written Y ⊧_{F} ♢, if for all morphisms α : x → x′, β : y → y′ in Y such that F x = F y there are morphisms γ : v → v′, δ : w → w′ in Y such that F x′ = F v, F y′ = F w and F v′ = F w.

If additionally F γ.F α = F δ.F β, then we say Y has the strong diamond property with respect to F, written Y ⊧_{F} ♦.

The idea of the following lemma is that to complete a span of two paths p = <α_{1}, …, α_{n}> and q = <β_{1}, …, β_{m}> with equivalent sources it is sufficient to be able to “tile” the squares in figure 4.2 (except that sources and targets of the squares are merely equivalent, not equal). This tiling is equivalent to two inductions over both the length of p and q. For commuting confluence, figure 4.2 additionally has to be commute up to equivalence.

[figure: α_{1}; α_{2}; …; α_{n}]

[figure: β_{1}; α′_{1}; β′_{1}; α′_{2}; β′′_{1}; …; β_{1}^{(n−1)}; α′_{n}; β_{1}^{(n)}]

[figure: β_{2}; α′′_{1}; β′_{2}; α′′_{2}; β′′_{2}; …; β_{2}^{(n−1)}; α′′_{n}; β_{2}^{(n)}]
⋮  ⋮  ⋮  ⋮  ⋮
[figure: α_{1}^{(m−1)}; α_{2}^{(m−1)}; …; α_{n}^{(m−1)}]

[figure: β_{m}; α_{1}^{(m)}; β′_{m}; α_{2}^{(m)}; β′′_{m}; …; β_{m}^{(n−1)}; α_{n}^{(m)}; β_{m}^{(n)}]

Figure 4.2: Completing sequences of morphisms by “tiling”

Lemma 4.2.2 (The Tiling Lemma) Let Q : Y → Z be the coequalizer of two functors F, G : X → Y in Cat as given in §1.5.3. If Y is confluent and Y ⊧_{Q} ♢, then Z is confluent; if Y is commuting confluent and Y ⊧_{Q} ♦, then Z is commuting confluent.

Proof. To show confluence, we show that given two paths p, q such that s(p) = s(q), there are paths r, s such that t(p) = s(r), t(q) = s(s) and t(s) = t(t). For commuting confluence, we show that additionally p::r ≡_{M} q::s (where ≡_{M} is the equivalence on morphisms induced by Q, see §1.5.3). Both are proven by induction over the lengths of the two paths p and q.

We first show that for all p = <α_{1}, …, α_{n}> and β ∈ Y(x, y) such that [x] = s(p), there is a morphism β′ and a path <α′_{1}, …, α′_{n}> such that p′ =^{def} <α_{1}, …, α_{n}, β′> and q′ =^{def} <β, α′_{1}, …, α′_{n}> are both paths with the same target: t(p′) = t(q′); and under the additional assumption Y ⊧_{Q} ♦, that p′ ≡_{M} q′.

This is shown by induction on n. The induction base is n = 0, in which case β′ =^{def} β. For the induction step, given a path p = <α_{1}, …, α_{n}> and β ∈ Y(x, y) with [x] = δ_{s}(α_{1}), since Y ⊧_{Q} ♢ there are morphisms γ, δ in Y s.t. Q(δ_{t}(α_{1})) = Q(δ_{s}(γ)), Q(y) = Q(δ_{s}(δ)) and Q(δ_{t}(γ)) = Q(δ_{t}(δ)), i.e. <α_{1}, γ> and <β, δ> are paths with the same target. We can apply the induction assumption to γ and <α_{2}, …, α_{n}> (since the latter is only of length n−1), and obtain morphisms

γ′, α′_{2}, …, α′_{n} such that p′ =^{def} <α_{2}, …, α_{n}, γ′> and q′ =^{def} <γ, α′_{2}, …, α′_{n}> are paths

with the same target. Then the desired completions are γ′ and <δ, α′_{2}, …, α′_{n}>, with t(<β, δ, α′_{2}, …, α′_{n}>) = Q(δ_{t}(α′_{n})) = Q(δ_{t}(γ′)) = t(<α_{1}, …, α_{n}, γ′>) as required.

Under the stronger assumption Y ⊧_{Q} ♦, we have that above

Qγ.Qα_{1} = Qδ.Qβ ⇔ <α_{1}, γ> ≡_{M} <β, δ>

The induction assumption is strengthened to

<α_{2}, …, α_{n}, γ′> ≡_{M} <γ, α′_{2}, …, α′_{n}>

and the desired completions are equivalent as follows:

<α_{1}, α_{2}, …, α_{n}, γ′> ≡_{M} <α_{1}, γ, α′_{2}, …, α′_{n}>
≡_{M} <β, δ, α′_{2}, …, α′_{n}>

Now we can do an induction on the length m of the second sequence. The induction base is m = 0, which is trivial. For m > 0, since s(p) = s(q), we can use the previous result to obtain β′ and a path α′_{1}, …, α′_{n} such that <α_{1}, …, α_{n}, β′> and <β_{1}, α′_{1}, …, α′_{n}> are paths with the same target. The induction assumption is that for p′ =^{def} <β_{2}, …, β_{m}> and q′ =^{def} <α′_{1}, …, α′_{n}> there are paths p′′, q′′ such that t(p′) = s(p′′), t(q′) = s(q′′) and t(p′′) = t(q′′). Then the desired completions are r =^{def} <β′>::q′′ and s =^{def} p′′.

This concludes that proof that Z is confluent if Y ⊧_{Q} ♢. Under the stronger assumption that Y ⊧_{Q} ♦, we can (in the induction step) use the previous result to obtain

<α_{1}, …, α_{n}, β′> ≡_{M} <β_{1}, α′_{1}, …, α′_{n}>

Then the induction assumption is that p′::p′′ ≡_{M} q′::q′′, and hence we have

p::r ≡_{M} <α_{1}, …, α_{n}, β′>::q′′
≡_{M} <β_{1}, α′_{1}, …, α′_{n}>::q′′
≡_{M} <β_{1}>::q′::q′′
≡_{M} <β_{1}>::p′::p′′
≡_{M} <β_{1}, β_{2}, …, β_{m}>::p′′
≡_{M} q::s

This means that the completion commutes, and hence Z is commuting confluent.

□

4.2.2 Witnesses

In this section, we introduce the notion of a witness, and show how it can be used to assert the diamond property as defined above. The idea is that any span in Z comes from two morphisms α : x → x′, β : y → y′ in Y such that Qx = Qy; we call this a span under Q. Being able to complete any such span under Q is equivalent to Y having the diamond property w.r.t. Q.

In order to find a completion of α and β, we find a span in Y of two morphisms α′ : z → z′, β′ : z → z′′ which are equivalent to α and β respectively, then use the confluence of Y to complete the span in Y, and Q will preserve the completion. The object z is constructed by introducing a witness. We say an object z witnesses an object x if for any rewrite α out of x there is a rewrite α′ out of z which is equivalent (i.e. Qα = Qβ). If we can prove that any two equivalent objects have the same witness, then we will be able to complete any spans under Q, and obtain confluence; if we can even prove that the completion commutes, we will obtain commuting confluence.

Definition 4.2.3 (Witness) Given a functor F : X → Y, and two objects x, y ∈ X, x is a witness of y with respect to F, written x wit_{F} y if F x = F y and for all morphisms β : y → y′ in X, there is a morphism α : x → x′ in X such that F α = F β.

Lemma 4.2.4 Given the coequalizer Q : Y → Z of two functors F, G : X → Y, if Y is (commuting) confluent and for all x, y ∈ Y s.t. Qx = Qy there is a common witness z ∈ Y such that z wit_{Q} x and z wit_{Q} y then Z is (commuting) confluent.

Proof. We show that Y ⊧_{Q} ♢ if Y is confluent, and Y ⊧_{Q} ♦ if Y is commuting confluent, and then use lemma 4.2.2.

Given α : x → x′, β : y → y′ such that Qx = Qy. Then since x and y have a common witness z ∈ Y with Qz = Qy = Qx, there are α′ : z → z′, β′ : z → z′′ such that Qα′ = Qα, Qβ′ = Qβ. α′ and β′ form a span in Y, which by confluence of Y has a completion γ : z′ → u, δ : z′′ → u with Qz = Qx′ and Qz′ = Qy′ as required; hence Y ⊧_{Q} ♢. If further Y is commuting confluent, we have γ.α′ = δ.β′, hence (since Q preserves composition) Qγ.Qα′ = Qδ.Qβ′, hence Qγ.Qα = Qδ.Qβ, so Y ⊧_{Q} ♦. □

We will now put this machinery to work with the diagram D_{X} to show modularity of confluence and commuting confluence for the coproduct of two regular, non-expanding monads.

4.3 Toyama’s Theorem

We are now going to prove modularity of confluence: given two regular, nonexpanding monads T_{1} = ⟨T_{1}, η_{1}, μ_{1}⟩ and T_{2} = ⟨T_{2}, η_{2}, μ_{2}⟩, we want to show that the coproduct monad T_{1+2} = ⟨T, η, μ⟩ is confluent iff the two monads T_{1} and T_{2} are. One direction of the implication is easy: if T_{1+2} is confluent, T_{1} and T_{2} must be confluent as well, since T_{1} and T_{2} are faithfully embedded into T by the two injections. To show the other direction of the implication, we have to show that under the assumption that T_{1} and T_{2} are confluent, for all categories X which are confluent, T X is confluent.

By definition 3.1.1, the coproduct T X is the colimit of the diagram D_{X} in Cat. By proposition 1.3.1, this colimit is given by the coequalizer of diagram 3.20 reproduced here:

∐_{d:u→v in F(G)} T^{u}X  [figure: F; G] ∐_{w∈W} T^{w}X

In order to be able to use lemma 4.2.4, we first need to show that the target of the two arrows to be coequalized is (commuting) confluent:

Lemma 4.3.1 If T_{1} and T_{2} are (commuting) confluent, then the coproduct ∐_{w∈W} T^{w}X is (commuting) confluent whenever X is.

Proof. It is sufficient to show that for all w ∈ W, T^{w}X is (commuting) confluent. This is shown by a simple induction on w: for w = ε, T^{w}X = X which is (commuting) confluent by assumption; and if T^{w}X is (commuting) confluent, so is T^{jw}X = T_{j}T^{w}X (for all j ∈ L), since both T_{1} and T_{2} preserve (commuting) confluence. □

We now need to find a common witness for any two equivalent objects s, t ∈ ∐_{w∈W} T^{w}X. Recall from lemma 3.2.6 that for every object t there is a normal form NF(t) (with respect to the reduction relation ↠_{Ob} from definition 3.2.1) which decides the equivalence on the objects induced by F and G, hence Qt = Qs iff NF(s) = NF(t). This normal form will also be the common witness of s and t, thus ensuring in one fell swoop that any two equivalent objects have the same witness and that every object has one. All that remains to be shown is that the normal form NF(x) of an object x witnesses x. This is shown by a rather simple induction on the derivation, but we have to assume that the monads T_{1}, T_{2} are non-expanding in the sense of definition 2.4.5. This is essential, since in the presence of expanding rewrite rules Toyama’s theorem doesn’t hold, as the following counterexample shows. Consider the two confluent term rewriting systems (where R_{1} is expanding)

R_{1} =^{def} {'x → A('x)}

                   R_{2} =^{def} {B(C('x)) → C(B('x))}

then in the disjoint union R_{1} + R_{2} there is the uncompletable span

                    \begin{matrix}B & ( & C('x) & ) \\ C(B('x)) & R_{2}_{\underline{}} & B(A(C('x))) & ^{R_{1}  ^{\overline{}}} \end{matrix}

However, instead of requiring every rewrite to be non-expanding, we can slightly relax the requirement to every rewrite being able to be made into one which is non-expanding; this is the quasi-non-expanding property from definition 2.4.11 on page 85, and this generalisation will be the subject of §4.4 below.

Lemma 4.3.2 If T_{1} and T_{2} are non-expanding, then the normal form of an object x witnesses x:

NF(x) wit x

Proof. Given any α : x → x′, then by lemma 3.2.10, if T_{1}, T_{2} are non-expanding, there is NF(α) : NF(x) → x′. Since Q(NF(α)) = Q(α), NF(x) witnesses x. □

Theorem 4.3.3 (Modularity of Confluence) The coproduct of two regular, (commuting) confluent, non-expanding monads on Cat is (commuting) confluent.

Proof. If X is a (commuting) confluent category, then by lemma 4.3.1, the coproduct ∐_{w∈W} T^{w}X is (commuting) confluent. Given x, y ∈ ∐_{w∈W} T^{w}X s.t. Qx = Qy, then by lemma 3.2.6 NF(x) = NF(y), and by lemma 4.3.2, NF(x) wit x and NF(y) wit y, so x and y have a common witness NF(x) = NF(y). Hence by lemma 4.2.4, the colimit colim D_{X} = T X is (commuting) confluent, making the monad T_{1} + T_{2} (commuting) confluent. □

The original theorem is a corollary of theorem 4.3.3: Corollary 4.3.4 (Toyama) The disjoint union of two confluent, non-exanding term rewriting systems which do not introduce unbounded variables is confluent. Proof. Given two confluent, non-expanding term rewriting systems Θ_{1}, Θ_{2} which do not introduce unbounded variables, the monads T_{Θ_{1}} and T_{Θ_{2}} are non-ex-panding by lemma 2.4.8, regular by proposition 2.4.4 and confluent by proposition 4.1.7. Then by theorem 4.3.3, T_{Θ_{1}}+T_{Θ_{2}} is confluent, and by proposition 2.5.3, T_{Θ_{1}} + T_{Θ_{2}} ≅ T_{Θ_{1}+Θ_{2}}. Hence (again by proposition 4.1.7), Θ_{1} + Θ_{2} is confluent.

□

Note that the proof nowhere used the fact that the monads T_{1}, T_{2} arise from term rewriting systems (apart from them being regular). In particular, the proof of theorem 4.3.3 does not depend on the fact the rules of the term rewriting systems do not introduce variables, as long as the resulting monad is non-expanding. Hence by lemma 2.4.8, corollary 4.3.4 holds for term rewriting systems which do introduce bounded variables on the right as well, slightly generalising the original theorem [88, 42].

4.4 Modularity of Confluence for Quasi-Non-Expanding Monads

In this section we will extend Toyama’s theorem (theorem 4.3.3) to systems which are quasi-non-expanding (qne, see definition 2.4.11). For the proof of theorem 4.3.3, lemma 3.2.10 is essential, since it ascertains that for any rewrite α : s → t which is not layer-expanding, there is a rewrite NF(α) : NF(s) → t, making the normal form a witness and thus allowing to complete every span under Q. If the monads T_{1}, T_{2} are expanding, this will not hold any more, but as it turns out it is sufficient that we are able to compose any rewrite with one which is not layer-expanding such that the composition is not layer-expanding either.

We will give a more abstract characterisation of this situation: if we have a confluent subcategory of ∐_{w∈W} T^{w}X (like the non-layer-expanding morphisms) for which the diamond property wrt Q holds, we call this a completable subcategory; and if we can compose any morphism with one from the subcategory to obtain a morphism in the subcategory we call this subcategory co-initial. Then the existence of a completable co-initial subcategory is sufficient to show confluence. Strengthening our assumption to commuting confluence and the strong diamond property, we obtain commuting confluence.

4.4.1 Completable and Co-Initial Subcategories

Definition 4.4.1 (Completable Subcategory) Given a functor F : X → Y, a (commuting) completable subcategory w.r.t. F is a subcategory J : C ↪ X such that C is (commuting) confluent and satisfies the (strong) diamond property w.r.t. F J: C ⊧_{F J} ♢ (C ⊧_{F J} ♦)

We will in the following omit the embedding functor J, and say that an object x ∈ X, or a morphism α : x → x′ in X is in C if it is the image of J. In this notation, the definition of a completable subcategory spells out as follows: for all morphisms α : x → x′, β : y → y′ in C such that F (x) = F (y) there are morphisms γ : x′′ → u, δ : y′′ → u′ in C (and if C is commuting completable, F γ.F α = F δ.F β). We can now complete any paths which consist only of morphisms in C, obtaining a relaxed version of the tiling lemma 4.2.2.

We also need some more notation for paths: for two paths A, B we say A ∼ B iff s(A) = s(B) and t(A) = t(B) — i.e. A and B are paths with the same source and target.

Lemma 4.4.2 Let Q : Y → Z be the coequalizer of two functors F, G : X → Y, and let J : C ↪ Y be a completable subcategory of Y w.r.t. Q. We say that a path A = <α_{1}, …, α_{n}> is in C if all α_{i} are in C.

Then for all paths A, B which are in C, and for which s(A) = s(B), there are paths C, D in C such that t(A) = s(C), t(B) = s(D) and A::C ∼ B::D.

If C is a commuting confluent subcategory, we furthermore have Q(A::C) = Q(B::D).

Proof. By “tiling”, i.e. induction on the length of A and B (like lemma 4.2.2). The crucial point here is that the completion of two morphisms α : x → x′, β : y → y′ in C is in C again, allowing the induction to go through. □

We say the subcategory C is co-initial in X if for every morphism α in X, there is a morphism β in C such that their composition β.α is in C as well.

Definition 4.4.3 (Co-initial Subcategory) Given a functor F : X → Y, a subcategory J : C ↪ X is called co-initial, if for all morphisms f : x → y in X there is a morphism g : y → z in C such that g.f is in C.

Note that a necessary condition for C to be a co-initial subcategory is that C contains all the objects of X. Now, if there is a (commuting) completable subcategory with respect to the coequalizer of two functors which is co-initial as well, the coequalizing category will be (commuting) confluent:

Lemma 4.4.4 Let Q : Y → Z be the coequalizer of two functors F, G : X → Y. If there is a co-initial (commuting) completable subcategory w.r.t. Q, and Y is (commuting) confluent, then Z is (commuting) confluent.

Proof. We will first show that for all paths A = <α_{1}, …, α_{n}> there are paths B = <β_{1}, …, β_{n}> and C = <γ_{1}, …, γ_{n}> in C such that t(A) = s(B), and A::B ∼ C; and under the stronger assumption that C is a commuting completable subcategory, we have A::B ≡_{M} C. We can then use lemma 4.4.2 to conclude confluence of Z.

The proof proceeds by induction on the length of A. The induction assumption is n = 0, which is trivial. For the induction step, given A = <α_{1}, …, α_{n}>, we can apply the induction assumption to A′ = <α_{1}, …, α_{n−1}> and obtain B′ = <β_{1}, …, β_{n−1}>, C′ = <γ_{1}, …, γ_{n−1}> in C such that A′::B′ ∼ C′. Now since C is a completable subcategory, for α_{n} there is α′ in C s.t. α′_{n} =^{def} α′.α_{n} is in C. Since α′_{n} and β_{1}, …, β_{n−1} are in C, there are α′′_{n} and <β′_{1}, …, β′_{n−1}> (by tiling as in the proof of lemma 4.2.2) in C with <β_{1}, …, β_{n−1}, α′′_{n}> ∼ <α′_{n}, β′_{1}, …, β′_{n−1}>. Then

let B =^{def} <α′_{n}, β′_{1}, …, β′_{n−1}> and C =^{def} <γ_{1}, …, γ_{n−1}, α′′_{n}>, both of which are in C,

and t(A) = s(B) and further A::B ∼ C as required. See also diagram 4.7, where

[figure: α_{1}; ....................; α_{n−1}; α_{n}; γ_{1}; β_{1}; α′; α′_{n}; ...........................; . . . . . . . . . . . .; β′_{1}; β_{n−1}; γ_{n−1}; . . . . . . . . . . . .; β′_{n−1}; α′′_{n}]  (4.7)

the large triangle on the left is the induction assumption, the small triangle on the top right corner is given by the fact that C is a co-initial subcategory, and the parallelograms down the right side are constructed from the top (by tiling) since β_{1}, …, β_{n−1} and α′_{n} are in C. Note the large triangle, and the parallelograms do not commute, unless we can assume commuting completability as follows.

If there is a co-initial commuting completable subcategory, we can show that A::B ≡_{M} C. The induction assumption strengthens to A′.B′ ≡_{M} C′, and for β′_{1}, …, β′_{n} and α′′ we have that <β_{1}, …, β_{n−1}, α′′_{n}> ≡_{M} <α′_{n}, β′_{1}, …, β′_{n−1}>. Then we can show that

A::B =  <α_{1}, …, α_{n}, α′, β′_{1}, …, β′_{n−1}>
≡_{M} <α_{1}, …, α_{n−1}, α′_{n}.α_{n}, β′_{1}, …, β′_{n−1}>
≡_{M} <α_{1}, …, α_{n−1}, β_{1}, …, β_{n−1}, α′′_{n}>
≡_{M} A′::B′::<α′′_{n}> ≡_{M} C′::<α′′_{n}> = C

This concludes the induction.

We can now show confluence. Given two paths A, B such that s(A) = s(B), we have just shown there are paths B′, A′, C_{1}, C_{2} in C such that A::A′ ∼ C_{1} and B::B′ ∼ C_{2}. By lemma 4.4.2, there are D_{1}, D_{2} such that C_{1}::D_{1} ∼ C_{2}::D_{2}. Hence, for A and B we have A′::D_{1} and B′::D_{2} such that A::(A′::D_{1}) ∼ C_{1}::D_{1} ∼ C_{2}::D_{2} ∼ B::(B′::D_{2}), so we have a completion for A and Z is confluent.

Under the stronger assumption of C being a commuting completable subcategory, we have shown that A::A′ ≡_{M} C_{1} and B::B′ ≡_{M} C_{2} ; and by lemma 4.4.2, there are D_{1}, D_{2} such that C_{1}::D_{1} ≡_{M} C_{2}::D_{2}. By the same reasoning as above, it follows that A::(A′::D_{1}) ≡_{M} C_{1}::D_{1} ≡_{M} C_{2}::D_{2} ≡_{M} B::(B′::D_{2}), hence we have a commuting completion for A and B and Z is commuting confluent. □

4.4.2 Finding a Completable Co-initial Subcategory

In this case, the completable co-initial subcategory will be given by the non-layer-expanding rewrites. That a span of two non-layer-expanding rewrites can be completed has been shown above, so the main work will be to show that for every rewrite α, we can find a rewrite β such that β.α is not layer-expanding, and that this β is not layer-expanding itself. β will exists if both monads T_{1}, T_{2} are qne, so any expanding rewrite can be contracted again. However, α can be expanding in several layers at the same time, so we need to contract all these layers. For example, consider the term rewriting system E = (E_{1}, {'x → E('x), E('x) → 'x}) as the first system, and just the signature with one unary operation F and no rewrites as the second system; then we have the rewrite F(''F(''x)) ↠ F('E('F('E('x)))) in T_{2}T_{1}T_{2}T_{1}X which is expanding in two layers at the same time. However, both can be contracted again, and moreover, the rewrite contracting a rewrite in one layer is not expanding another layer.

Lemma 4.4.5 If T_{1}, T_{2} are quasi-non-expanding, the subcategory of ∐_{w∈W} T^{w}X given by the non-layer-expanding morphisms is co-initial.

Proof. We have to show that for all α in T^{w}X, there is α′ in T^{w}X which is not layer-expanding such that α′.α is not layer-expanding. Let α : s → t be layerexpanding, with NF(α) : s_{0} → t_{0}. Then s_{0} ≠ NF(s), with s_{0} →_{η} s_{1} →_{η} … NF(s_{0}) (there can be no reduction steps from →_{μ} here, since α →_{μ} α′ iff δ_{s}(α) →_{μ} δ_{s}(α)). To be more precise, we have s_{0}, …, s_{n} with s_{i} = η_{j_{i},v_{i}}^{u_{i}}(s_{i+1}) for i = 0, …, n − 1 (u_{i}, v_{i} ∈ W, j_{i} ∈ L) and s_{n} = NF(s_{0}).

The proof proceeds by induction on n. The induction base is n = 0, which is trivial. For the induction step, we assume the lemma for s_{1} ↠_{η} NF(s_{0}), and let s_{0} = η_{j,v}^{u}(s_{1}). Now for NF(α) : s_{0} → t_{0}, since η_{j,v}^{u} is qne there are β : t_{0} → t′_{0}, γ : s_{1} → t_{1} such that η_{j,v}^{u}(γ) = β.NF(α). Since t_{0} is not in the image of η_{j,v}^{u} (otherwise η_{j,v}^{u} would not be full, and T_{j} not qne), β is not expanding w.r.t. η_{j,v}^{u} and hence not layer-expanding.

However, γ will be expanding w.r.t. η_{j_{1},v_{1}}^{u_{1}}, i.e. for all δ : s_{2} → t_{2} we will have η_{j_{1},v_{1}}^{u_{1}}(δ) ≠ γ (but η_{j_{1},v_{1}}^{u_{1}}(s_{2}) = s_{1}). We can apply the induction assumption to s_{1} and γ: there is γ′ : t_{1} → t′_{1} which is not layer-expanding, and further γ′.γ is not layer-expanding either. With t′_{0} = η_{j,v}^{u}(t_{1}), we can compose β above and η_{j,v}^{u}(γ′), obtaining α′ =^{def} η_{j,v}^{u}(γ′).β. Since both β and η_{j,v}^{u}(γ′) are not layer-expanding, α′ is neither, and since β.NF(α) is not layer-expanding, α′.NF(α) = η_{j,v}^{u}(γ′).β.NF(α) will not be. □

Depending on whether the monads T_{1}, T_{2} are confluent or commuting confluent, the non-layer-expanding morphisms will form a completable or commuting completable subcategory of ∐_{w∈W} T^{w}X.

Lemma 4.4.6 If T_{1}, T_{2} are (commuting) confluent and quasi-non-expanding, the non-layer-expanding morphisms form a (commuting) completable subcategory of ∐_{w∈W} T^{w}X w.r.t. Q.

Proof. Given two non-layer-expanding morphisms α : s → s′, β : t → t′ in ∐_{w∈W} T^{w}X such that Q(s) = Q(t). By lemma 3.2.10, we have NF(α) : NF(s) → s′′ and NF(β) : NF(t) → t′′, and by lemma 3.2.6 NF(s) = NF(t) iff Q(s) = Q(t). By confluence of T^{w}X, the span formed by NF(α) and NF(β) can then be completed, i.e. there are γ : s′′ → u and δ : t′′ → u in T^{w}X.

If further T^{w}X is commuting confluent, we have γ.NF(α) = δ.NF(β), hence Q(γ).Q(α) = Q(γ).Q(NF(α)) = Q(δ).Q(NF(β)) = Q(δ).Q(β). □

We can now combine the previous lemmas into the main theorem:

Theorem 4.4.7 (Modularity of Confluence for Quasi-Non-Expanding Monads) The coproduct of two (commuting) confluent, regular, quasi-non-ex-panding monads is (commuting) confluent.

Proof. If T_{1} and T_{2} are two confluent, quasi-non-expanding monads, and if X is a (commuting) confluent category, then by lemma 4.3.1, the coproduct ∐_{w∈W} T^{w}X is (commuting) confluent. By lemmas 4.4.6 and 4.4.5, the non-layer-expanding rewrites form a co-initial (commuting) completable subcategory in ∐_{w∈W} T^{w}X, so by lemma 4.4.4 the colimit colim D_{X} = T X is (commuting) confluent, making the monad T_{1} + T_{2} (commuting) confluent. □

Again, the corollary of this is that the disjoint union of two quasi-non-expan-ding confluent rewrite systems is confluent:

Corollary 4.4.8 The disjoint union of two confluent quasi-non-expanding term rewriting systems which do not introduce unbounded variables is confluent.

Proof. Substitute theorem 4.3.3 with theorem 4.4.7, and lemma 2.4.8 with lemma 2.4.12 in the proof of corollary 4.3.4. □

Of course, §4.3 is a special case of this section, but we felt developing it separately would lead to a clearer exposition. The aim of this section is not so much to prove a more general result, but rather to demonstrate the flexibility and adaptability of our modularity proof.

4.5 Summary and Conclusion

In this chapter, we have proven the modularity of confluence for the disjoint union. We first defined a semantic notion of confluence for categories and monads, and showed that it is equivalent to the usual, syntactic definition in the sense that the monad T_{Θ} is confluent according to the new, semantic definition if and only if the term rewriting system Θ is confluent according the old, syntactic definition.

Building on the observation that the colimit of any diagram can be constructed as a coequalizer of coproducts, we then developed techniques to reason about preservation of confluence for coequalizers in Cat. We gave a property under which confluence is preserved by a coequalizer, the so-called diamond property, and we further introduced the notion of a witness.

The main result was to show that the coproduct of two confluent, nonexpanding regular monads is confluent (Toyama’s theorem), using the machinery set up before. Since the proof solely depends on the properties of the two monads, our proof slightly generalizes the original theorem to systems which introduce bounded variables. We then extended this proof to quasi-non-expanding monads, showing that the coproduct of two confluent quasi-non-expanding regular monads is confluent.

To close this section, we will compare our proof with [42], a simplified and clearer version of the original proof [88]. For the notation and notions used in the following, the reader should recall the quote on page 96. The authors start their proof by observing that

the main obstacle for giving a ‘straightforward’ proof of the modularity of confluence is the fact that the black and white layer structure of a term need not be preserved under reduction. That is, by a destructive rewrite step a e.g. black layer may disappear, thus allowing two originally distinct white layers to coalesce.

They proceed to define the notion of a preserved term — a term from which no reduction sequence with a destructive rewrite starts, and of inner preserved term, a term all the principal subterms of which are preserved. It is shown that

• inner preserved terms are confluent (meaning any span starting from the terms can be completed), and that

• every term reduces to a witness. Given a term s, the witness ṡ is an inner preserved term such that if all principal subterms of s are confluent, then for all other terms t, if s ↠ t, then ṡ ↓ ṫ.

The final step is to show that every term t is confluent by induction on the rank of t. From the induction assumption, it follows that all principal subterms of t are confluent; so given any reduction t ↠ s, the previous lemma about witnesses can be applied to ṫ and ṡ, hence t and s are joinable, making t confluent.

Comparing the two proofs, our notion of a witness (definition 4.2.3) is similar only insofar as it represents reductions as well. Whereas witnesses in [42] are merely joinable, our witnesses represent all reductions in an “algebraic” sense (i.e. if there is a reduction starting from t, then there is an equivalent reduction starting from the witness of t as well).

In [42], the main obstacle of the proof — the destructive reductions — is handled by reducing all terms until no further destructive reductions can occur. Hence, the completion of a span is not very constructive. In contrast, in our proof we take the reductions in the theory of the two systems (the many-step reductions, as given by the monads) as primitive, and show that for any span of these, we can find ones which are equivalent under the equivalence generated by combining the two systems, described by the diagram D_{X} and given by its colimit, and can be joined. This gives our proof an algebraic, and rather constructive, flavour, since it involves neither preservation nor induction on the ranks of the terms involved.

Further, the presence of the variable rewrites allows us to abolish the distinction between inner and outer reductions. Since the variable rewrites specify the rewrites between the terms which are instantiated for the variables, instantiation cannot destroy inner redexes. Hence, in a confluent monad every span of rewrites can be completed in one step (taking many-step reductions in one system as basic steps). For example, consider the two systems

R_{1} =^{def} {F('x, 'x) → G('x)}

        R_{2} =^{def} {K('x) → L('x), K('x) → H('x), L('x) → H('x)}

Then there is the following span

                             F(K('x), K('x))

                      [figure: F(L('x), H('x)); R_{2}; G(K('x)); R_{1}]

In order to complete this span, we first need some more inner R_{2}-steps on the left. In the monad semantics, the existence of these R_{2}-steps precisely corresponds to variable rewrites, which by definition of confluence we can assume to be confluent; and by rule [Var], these R_{2}-steps are R_{1}-steps as well, so the outer system (R_{1}) is completable in one step as well. Nevertheless, confluence for monads is not a strictly stronger concept than confluence for term rewriting systems, as was shown in proposition 4.1.7. In the proof of that proposition, exactly the above situation showed up (diagram 4.4), which shows that our definition handles this situation adequately. The handling of substitution as a natural transformation, which has to preserve the reduction structure, together with the variable rewrites, is the key element here.

The algebraic nature of the proof extends it to systems with bounded variables on the right, and further allows the generalisation of §4.4 to quasi-non-expanding systems. (Both of these allow rules that can arbitrarily increase the rank of a reduction, and hence break the original proof.) In closing, I think one can say that the proof method introduced here is substantially new, not merely a rephrasing of the old proof in a categorical framework.

Modularity of Strong Normalization

A term rewriting system is strongly normalizing if there are only finite reduction sequences: reduction can’t go on for ever. Strongly normalizing systems are also called terminating, and for variety, we shall use the two words synonymously.

Termination is important, because it means that in an implementation of the term rewriting system, every reduction eventually ends. A system which is confluent as well as terminating is called complete. A complete term rewriting system gives a decision procedure for the equational theory the term rewriting system describes^{1} (if the term rewriting system has finitely many rules): every term reduces to exactly one normal form, and two terms are equal in the equational theory iff their normal forms are the same.

Known Results about Modularity of Termination

Unlike confluence, strong normalization is in general not modular. The simplest, earliest and best-known counterexample [87] is given by the following two terminating systems:

R = ({A_{0}, B_{0}, F_{3}}, {F(A, B, 'x) → F('x, 'x, 'x)})
S = ({G_{2}}, {G('x, 'y) → 'x, G('x, 'y) → 'y})

Then in the coproduct, there is an infinite reduction sequence starting

F(G(A, B), G(A, B), G(A, B)) ↠_{S} F(A, B, G(A, B)) →_{R} F(G(A, B), G(A, B), G(A, B)) . . .

One can also show [87] that completeness is not modular, i.e. even if both systems are confluent as well as terminating, their disjoint union will in general not be terminating (although of course it will be confluent). There is a wide variety of conditions, however, under which strong normalization is modular:

1Actually, to decide the equality weak normalization [41] together with confluence suffices.

• Both systems are not collapsing [72];

• Both systems are not duplicating [72];

• One of the systems is neither duplicating nor collapsing [58];

• Both systems are simply terminating, and finite [44].

This is defined as follows: a simplification ordering for a term rewriting system Θ = (Ω, R) is a partial order (T_{Ω}(V), >) on the terms^{2} which

– is monotonic: s > t implies F(…, s, …) > F(…, t, …);

– possesses the subterm property: F(…, t, …) > t

Then Θ is simply terminating if the reduction order can be embedded into a simplification ordering >, i.e. ↠_{R} ⊆ >.

• One system is left-linear, the other is right-linear and there is no overlap between the left sides of the first, and the right sides of the second system [16];

• Both systems are confluent, and left-linear [89].

• One system is not collapsing, and the other one preserves strong normalization under non-deterministic collapses [23, 62], which means the disjoint of that system with the system C_{E} is strongly normalizing, where C_{E} is the term rewriting system

C_{E} =^{def} {G('x, 'y) → 'x, G('x, 'y) → 'y}

Some of these conditions are strictly more general than others, for example the last subsumes all but the second last. We will in this chapter give a technical framework to prove modularity results for strong normalization, and as an application show modularity of strong normalization for non-collapsing systems.

2Recall from definition 1.6.1 that the set V of variables is supposed to be part of the signature.

Structure of this Chapter

• We fill first (in §5.1) define the notion of strong normalization for categories and monads on Cat. Just like we have done for confluence, we will show the equivalence of this semantic definition of strong normalization and the syntactic definition 1.6.4 from page 47.

• In §5.2, we will give a simple necessary and sufficient condition for the coproduct of two strongly normalizing monads to be strongly normalizing: that we cannot form paths of arbitrary length (infinite paths, in a manner of speaking).

• In §5.3, we will put the technical framework developed in the previous section to use and prove modularity of strong normalization for non-collapsing monads.

5.1 A Semantic Definition of Strong Normalization

5.1.1 Termination for Categories and Monads

For termination, we really need to consider categories rather than just preorders. The reason is that we have to be able to tell apart the identity on an object x from some other endomorphism on x, such as the cyclic reduction on F(G(A, B), G(A, B), G(A, B)) at the beginning of this chapter which makes a term rewriting system non-terminating. The other possibility would be to use transitive relations (i.e. modelling a term rewriting system by a monad over the category TRel of transitive relations). This requires a different semantics than the one presented in chapter 2, whereas the named reduction semantics from appendix A is a proper generalization of it.

Roughly speaking, a category is strongly normalizing if the underlying relation minus the reflexive relation given by the identities is strongly normalizing. We call this the underlying non-identity relation:

Definition 5.1.1 (Strong Normalization for Categories and Monads) The underlying non-identity relation of a category C, R^{−}(C) is defined as

R^{−}(C) =^{def} (|C|, {x > y | ∃α : x → y ∧ α ≠ 1_{x}})

A category C is strongly normalizing (or terminating), written C ⊧ SN, iff its underlying non-identity relation is strongly normalizing:

C ⊧ SN ⇔ R^{−}(C) ⊧ SN

A monad T on Cat is strongly normalizing if it preserves strong normalization:

X ⊧ SN ⇒ T X ⊧ SN

In a strongly normalizing category, the only endomorphisms are identities. Further, there can be no pair of morphisms f : x → y, g : y → x: even if gf = 1_{x} and fg = 1_{y}, we would have an infinite sequence in the underlying irreflexive relation R^{−}(C), given by x > y > x > y …; hence, the only isomorphisms in a strongly normalizing category are identities. Such a category (with the latter property concerning isomorphisms) is called skeletal.

The definition above differs substantially from Hilken’s [29], where strong normalization is defined in terms of separating cocones for filtered diagrams. The precise relation between the two definitions still needs to be clarified.

5.1.2 Equivalence of Notions

Just as for confluence, we have to make sure that the our notion of strong normalization coincides with the one found in the literature for term rewriting systems. Recall from definition 1.6.4 on page 47 that a term rewriting system Θ is terminating if there is no infinite sequence x_{1} →_{Θ} x_{2} →_{Θ} x_{3} →_{Θ} . . .. We now want to show that Θ is terminating by the above definition if and only if T_{Θ} is by definition 5.1.1. Unfortunately, we cannot directly use proposition 2.3.14, since as pointed out above in a preorder we cannot distinguish identities from cyclic rewrites, so we first prove a variation of that proposition, using the term named-reduction algebra from definition A.1.8.

Lemma 5.1.2 Given a category X, the underlying non-identity relation of the term named-reduction algebra on X is equal to the transitive closure of the union of →_{R} and →_{X}, where X =^{def} R^{−}(X):

R^{−}(T_{Θ}(X)) = (→_{R} ∪ →_{X})^{+}

Proof. The proof of this lemma is a variation of the proof of proposition 2.3.14. The equality is proven by proving inclusion in both directions. Right-to-left is rather easy, since any reduction in →_{R} or →_{X} corresponds to a non-identity morphism in T_{Θ}(X).

Left-to-right we again need to decompose the arguments for the [Pre] rule; and further, there is a non-identity rewrite s → t only if there is a non-identity variable rewrite (by rule [Var]) or an instantiated rewrite rule ([Inst]); hence we have the transitive closure (not the reflexive-transitive closure) on the right.

□

Now the main step in the proof will be to show that →_{X} ∪ →_{R} is terminating if →_{R} is. We can show that for any reduction in the union of →_{X} and →_{R}, we get one in →_{R} which has the same number of →_{R} steps; hence if there were an infinite reduction in the union, there would have to be one in →_{R} as well, which leads to a contradiction.

The key idea, due to Neil Ghani, is to assume the relation X to be confluent as well as strongly normalizing. If it isn’t, we can complete it to a relation X̂ which is confluent, and we show strong normalization of one relation by embedding it into one which is strongly normalizing. Under this additional assumption, we can show that any reduction in ↠_{S} gives rise to one in ↠_{R} of at least the same length. This is done by reducing every variable x to its normal form. The normal form is uniquely determined, and hence this reduction does not destroy any redexes. This is the content of the following lemma:

Lemma 5.1.3 Given a complete binary relation (X, <), and t_{1}, t_{2} ∈ T_{Ω}(X) s.t. t_{1} →_{R} t_{2}, then

[figure: t_{1}; R; t_{2}; NF_{X}(t_{1}); X ; ↓ ↓; R; NF_{X}(t_{2}); X ; ↓ ↓]

where NF_{X}(t_{1}) is the normal form of t_{1} in →_{X}.

Proof. t_{1} →_{R} t_{2} iff there is a context C and a substitution σ s.t. t_{1} = C[σ(l)] and t_{2} = C[σ(r)], and l → r ∈ R. Define the substitution τ(x) =^{def} NF_{X}(x) (which is well-defined since X is complete), then NF_{X}(t_{1}) = τ(t_{1}) = C[τ(σ(l))] (since substitutions commute with operations and contexts) and similarly NF_{X}(t_{2}) = C[τ(σ(r))]. Hence, with the substitution σ′ = τ.σ, NF_{X}(t_{1}) ↠_{R} NF_{X}(t_{2}) as required. □

Now given a sequence t_{1} →_{S} t_{2} →_{S} … t_{n}, we can now apply lemma 5.1.3, and get a normal form with respect to ↠_{X}. We obtain a shorter sequence containing only reductions in R.

Corollary 5.1.4 Let S =^{def} →_{R} ∪ →_{X} and (X, <) be complete. For any sequence P = t_{1} →_{S} t_{2} →_{S} … t_{n} in →_{S} with m (m ≤ n) reductions in →_{R}, there is a reduction s_{1} →_{R} s_{2} →_{R} … s_{m}, where all s_{i} are normal forms with respect to →_{X}, t_{1} ↠_{X} s_{1} and t_{n} ↠_{X} s_{m}.

Proof. The corollary is shown by an induction over length n of the sequence P, and applying lemma 5.1.3. □

We are now in a position to show the main result of this section:

Proposition 5.1.5 A term rewriting system Θ is strongly normalizing iff T_{Θ} is a strongly normalizing monad.

Proof. Let X be a strongly normalizing category, and X =^{def} R^{−}(X). Then by lemma 5.1.2, R^{−}(T_{Θ}(X)) = (→_{R} ∪ →_{X})^{+}, hence T_{Θ}(X) ⊧ SN iff (→_{X} ∪ →_{R})^{+} ⊧ SN iff →_{X} ∪ →_{R} ⊧ SN. As an abbreviation, let S =^{def} →_{R} ∪ →_{X}. Then to show the lemma, we have to show that →_{R} ⊧ SN iff S ⊧ SN.

One direction is trivial, since →_{R}⊆ S. For the other direction, assume that X is confluent as well as strongly normalizing, and proceed by contradiction as follows: assume there were an infinite sequence P = t_{1} →_{S} t_{2} →_{S} … t_{n} →_{S} … in S^{+}, then this sequence would have to contain infinitely many steps from both →_{R} and →_{X} (since both are SN). With the additional assumption of X being complete, we can apply corollary 5.1.4; so there would be an infinite sequence P′ in →_{R}. But →_{R} is terminating by assumption, hence there cannot be such a sequence in →_{S}.

If X is not confluent, then it can be completed to a relation X̂ which is. The previous paragraph applies to X̂, hence →_{R} ∪ →X̂ is strongly normalizing; but then (→_{R} ∪ →_{X}) ⊆ (→_{R} ∪ →X̂), and any subrelation of a strongly normalizing relation is strongly normalizing. □

5.2 Strong Normalization for the Coproduct Monad

Unfortunately, there is no equivalent of the tiling lemma 4.2.2 for strong normalization. There does not seem to be a useful characterization of preservation of strong normalization for the coequalizer of two functors.

Hence, we have to bite the bullet and directly reason about the coproduct of the colimit of D_{X}. Fortunately, we can find a good characterization when this colimit is strongly normalizing. This characterization is based on the fact that for every path in the colimit of D_{X}, there is an equivalent one of minimal length (§3.2.3 on page 114). These paths of minimal length give rise to sequences in the underlying non-identity relation of colim D_{X}, and if roughly speaking there are no infinite paths of minimal length, then there will be no infinite sequences in R^{−}(colim D_{X}), and hence colim D_{X} ⊧ SN. In other words, if we cannot form arbitrarily long paths of morphisms from ∐_{w∈W} T^{w}X in the coequalizer, then the coequalizer will be strongly normalizing.

Of course, every path on its own is finite (otherwise it would not have a target), so we have to be more precise here. We do not have one infinite path, but a sequence

<α_{1}>, <α_{1}, α_{2}>, <α_{1}, α_{2}, α_{3}>, <α_{1}, α_{2}, α_{3}, α_{4}>, <α_{1}, α_{2}, α_{3}, α_{4}, α_{5}>, …

of paths of minimal length which keeps growing indefinitely. We call this an infinite sequence in colim D_{X}:

Definition 5.2.1 (Infinite Sequence) An infinite sequence (α_{i})_{i∈ℕ^{+}} in colim D_{X} is given by morphisms α_{i} : x_{i} → y_{i} in ∐_{w∈W} T^{w}X such that for all k ∈ ℕ^{+}, <α_{1}, …, α_{k}> is a path of minimal length.

If we can find such an infinite sequence in colimD_{X} then T_{1}+T_{2} is not strongly normalizing.

Lemma 5.2.2 Let T_{1}, T_{2} ⊧ SN. If there is an infinite sequence (α_{i})_{i∈ℕ^{+}} in colim D_{X} for some strongly normalizing category X, then T_{1} + T_{2} ⊭ SN.

Proof. If there is an infinite sequence (α_{i})_{i∈ℕ^{+}} in colimD_{X}, we construct an infinite sequence

z_{1} < z_{2} < z_{3} < …

in R^{−}(colim D_{X}) by letting z_{i} =^{def} [s(α_{i})], so colim D_{X} ⊭ SN and hence T_{1} + T_{2} ⊭ SN. Since for all k ∈ ℕ^{+}, A = <α_{1}, …, α_{k}> is of minimal length, α_{i} ≠ 1 for all i ∈ ℕ^{+} (otherwise A would not be of minimal length), hence [s(α_{i})] < [t(α_{i})] in R^{−}(colim D_{X}), and with [t(α_{i})] = [s(α_{i+1})] = z_{i+1}, z_{i} < z_{i+1}. □

The converse of lemma 5.2.2 does not hold in general, because non-termination of the coproduct can also be caused by an unbounded increase in rank; see the counterexample on page 155 below. However, if we restrict ourselves to nonexpanding monads, the converse of lemma 5.2.2 holds.

Lemma 5.2.3 Let T_{1}, T_{2} ⊧ SN. If T_{1}, T_{2} are non-expanding and T_{1} + T_{2} ⊭ SN, then there is an infinite sequence (α_{i})_{i∈ℕ^{+}} in colim D_{X} for some strongly normalizing category X.

Proof. If T_{1} + T_{2} ⊭ SN, then colim D_{X} ⊭ SN for some strongly normalizing category X, which is the case if there is an infinite sequence

S = z_{1} < z_{2} < z_{3} < …

in R^{−}(colimD_{X}). S is given by morphisms f_{i} : z_{i} → z_{i+1} in colimD_{X} (for i ∈ ℕ^{+}), with f_{i} ≠ 1. Morphisms in colim D_{X} are equivalence classes of paths, represented by paths of minimal length. Without loss of generality, we can assume that these paths of minimal length are of length one, i.e. f_{i} = <β_{i}> with β_{i} : x_{i} → y_{i} in ∐_{w∈W} T^{w}X and in normal form. (If they are not, we can decompose them into paths of length one, obtaining a longer, still infinite sequence S above.)

Hence, S is given by β_{i} : x_{i} → y_{i} in ∐_{w∈W} T^{w}X with [x_{i}] = z_{i} and [y_{i}] = z_{i+1} for i ∈ ℕ^{+}. We now have to construct an infinite sequence in colim D_{X} from S. Intuitively, this is done by composing as many β_{i}, β_{i+1} as possible; then the remaining ones are incomposable and will hence form a path of minimal length. Since both T_{1} and T_{2} are strongly normalizing, ∐_{w∈W} T^{w}X is strongly normalizing as well, and so we can only compose finitely many β_{i} and β_{i+1}, so the remaining sequence will be infinite.

To this end, we define two functions σ, υ : ℕ^{+} → ℕ^{+}, and a sequence (γ_{β,k})_{k∈ℕ^{+}} which for k ∈ ℕ^{+} gives a pair σ(k), υ(σ(k)) such that σ(k) ≤ υ(σ(k)) and <γ_{β,υ(σ(k))}> ≡_{M} <β_{σ(k)}, …, β_{υ(σ(k))}>. σ(k) can be thought of as the first morphism in the sequence S to make up of the k-th morphism in the infinite sequence, υ(k) as the last morphism in S still “composable” with β_{k} in the sense that there are β_{k}, β_{k+1} which are not an incomposable pair,^{3} and γ_{β,υ(σ(k))} gives the k-th morphism in the infinite sequence. σ, υ and γ_{β} are defined inductively as follows:

σ(1) =^{def} 1
σ(k + 1) =^{def} υ(σ(k)) + 1
γ_{β,1} =^{def} β_{1}
γ_{β,k+1} =^{def} \{ \begin{matrix}β_{k+1} & if (γ_{β,k}, β_{k+1}) are an incomposable pair \\ α & where <α> ≡_{M} <γ_{β,k}, β_{k+1}> \end{matrix}
υ(k) = \{ \begin{matrix}υ(k + 1) & otherwise \\ k & if (γ_{β,k}, β_{k+1}) are an incomposable pair \end{matrix}

We first show that the above is well-defined. To do so, it is sufficient to show that

∀k ∈ ℕ^{+} ∃l ∈ ℕ^{+} . k ≤ l ∧ (γ_{β,l}, β_{l+1}) are an incomposable pair (5.1)

3This means that we may not be able to compose β_{k}, β_{k+1} directly but there will be two morphisms equivalent to β_{k}, β_{k+1} which are composable. The result of this composition for β_{σ(k)}, …, β_{υ(σ(k))} is accumulated in γ_{β,k}. Actually, σ and υ depend on β as well, and hence should be indexed with β, but to maintain readability we only do this with γ.

Since T_{1}, T_{2} are non-expanding, by lemma 4.3.2, NF(x) is a witness of x, i.e. for all α : x → x′, there is β : NF(x) → x′′ s.t. <α> ≡_{M} <β>. Furthermore, for all α : y → y′ with y ≡_{O} x, there is β : NF(x) → x′ with <α> ≡_{M} <β>, since NF(y) = NF(x). To show 5.1, let t =^{def} δ_{s}(β_{k}) with t ∈ T^{w}X, and let i = k, k + 1, k + 2, . . .. If (γ_{β,i}, β_{i+1}) are an incomposable pair, l =^{def} i and we are done; if not, there is α s.t. <α> ≡_{M} <γ_{β,i}, β_{i+1}> and since t ≡_{M} δ_{s}(α), there is α′ : t → t′ such that <α′> = <α>. So wolg. we may assume that δ_{s}(α) is actually t, and hence all γ_{β,i} are morphisms in T^{w}X. Since for all j ∈ ℕ^{+}, β_{j} ≠ 1, this gives rise to a sequence z_{0} < z_{1} < z_{2} < … in R^{−}(T^{w}X), with z_{0} =^{def} t, z_{i} =^{def} δ_{t}(γ_{β,i}). But T^{w}X ⊧ SN, so this sequence cannot be infinite, hence there has to be an l such that (γ_{β,l}, β_{l+1}) are an incomposable pair.

Unfortunately, we are not quite done yet. We would like to define an infinite sequence the k-th element of which is γ_{β,υ(σ(k))}; but from the definition, it merely follows that γ_{β,υ(σ(k))} and β_{υ(σ(k+1))} = β_{σ(k+1)} are an incomposable pair, not γ_{β,υ(σ(k))} and γ_{β,υ(σ(k+1))}, as would be required. Hence, we iterate our construction by again composing as many morphisms as can be composed; and again appeal to strong normalization of the two monads T_{1}, T_{2} for termination.

In detail, we define sequences (α_{k}^{i})_{k∈ℕ^{+}} for i ∈ ℕ as follows:

α_{k}^{0} =^{def} γ_{β,υ(σ(k))}
α_{k}^{i+1} =^{def} γ_{α^{i},υ(σ(k))}

It remains to show that this iteration terminates, i.e. for all k ∈ ℕ^{+}, there is m ∈ ℕ^{+} such that α_{k}^{m} = α_{k}^{m+1}, or equivalently (α_{k}^{m}, α_{k+1}^{m}) are an incomposable pair. This is shown by contradiction: assume there would be k ∈ ℕ^{+} such that for all m ∈ ℕ, α_{k}^{m} ≠ α_{k}^{m+1}. Without loss of generality, we can assume that this is the smallest such k, i.e. there is an n ∈ ℕ s.t. n ≤ m and for all l ≤ k, α_{l}^{n} = α_{l}^{n+1}. Then the source of all α_{k}^{m} with n ≤ m would be the same. Call this object t where t ∈ T^{w}X. With T_{1}, T_{2} non-expanding, NF(t) witnesses all α_{k}^{m}, and since α_{k}^{m} ≠ α_{k}^{m+1}, there is an infinite sequence z_{0} < z_{1} < z_{2} < … in R^{−}(T^{w}X), with z_{0} =^{def} NF(t), z_{i} =^{def} δ_{s}(α_{k}^{m+i}). Since T^{w}X ⊧ SN, there cannot be such a sequence, so for all k ∈ ℕ^{+}, there is m ∈ ℕ^{+} such that α_{k}^{m} = α_{k}^{m+1}, or equivalently (α_{k}^{m}, α_{k+1}^{m}) are an incomposable pair. We then define the sequence (ν_{k})_{k∈ℕ^{+}} in colim D_{X} as

ν_{k} =^{def} α_{k}^{i} where α_{k}^{i} = α_{k+1}^{i}

for which by construction, (ν_{k}, ν_{k+1}) are an incomposable pair as required, hence (ν_{k})_{k∈ℕ^{+}} is in infinite sequence in colim D_{X}. □

The negation of lemma 5.2.3 gives us the following useful corollary:

Corollary 5.2.4 Let T_{1}, T_{2} ⊧ SN. If T_{1}, T_{2} are non-expanding and for every strongly normalizing category X, there is no infinite sequence (α_{i})_{i∈ℕ^{+}} in colim D_{X}, then T_{1} + T_{2} ⊧ SN.

We now give a counterexample, due to Paul-André Melliès, showing why lemma 5.2.3 requires the monads to be non-expanding. Recall the monad B = ⟨B, η_{B}, μ_{B}⟩ from example 2.3.12 on page 75. It was there given on Pre; on Cat, it adds an object ⊥ and for every object x ∈ X a morphism ⊥ → x to its argument category X. It is not non-expanding, or more precisely does not preserve non-expandingness (see page 81), and by this property gives us a counterexample to the converse of lemma 5.2.3. Let Σ =^{def} {F_{1}} be the signature with just one unary operation, then in T_{Σ} +B(X) (for any non-empty X), there is the sequence

         [figure: ⊥; β_{1}; 'F('⊥); β_{2}; 'F(''F('⊥))]
                          'F(F('⊥)) |||  \overline{β_{3}^{}}'F(F(''F('⊥)))
                                         'F(F(F('⊥))) |||  . . .

Here, β_{1} lives in B(T_{Σ}(B(X))), and β_{2} lives in B(T_{Σ}(B(T_{Σ}(B(X))))); their composition (or more precisely, the morphism γ equivalent to the path <β_{1}, β_{2}>) lives in the latter as well. Similarly, β_{3} cannot be directly composed with γ, but β′_{3} : 'F(''F('⊥)) → 'F(''F(''F('⊥))) (which is equivalent) can. This way, we construct a sequence α_{1} =^{def} β_{1}, α_{2} =^{def} γ_{1}, α_{3} =^{def} β′_{3}.γ_{1}, … in which the rank strictly increases (rank(α_{i}) < rank(α_{i+1})), but which is not an infinite sequence in the sense of definition 5.2.1. This is only possible because B does not preserve nonexpandingness, in particular B(T_{Σ}(B(T_{Σ}(η_{B})))) maps '⊥ ∈ B(T_{Σ}(B(T_{Σ}(X)))) to '⊥ ∈ B(T_{Σ}(B(T_{Σ}(B(X))))), and there is β_{2} as above which does not come from any map in B(T_{Σ}(B(T_{Σ}(X)))).

5.3 Modularity of Strong Normalization for Non-Collapsing Monads

As an application of our methodology, we will in this section prove the modularity of strong normalization for non-collapsing monads, and term rewriting systems. Our main tools will be lemma 3.2.14 and corollary 5.2.4. The argument will be that if there are no collapsing rewrite rules, then by lemma 3.2.14 there are no incomposable pairs (which correspond to new rewrites being created by collapsing of layers), and hence all sequences in colimD_{X} (for a strongly normalizing category X) will be of length one. Then by corollary 5.2.4 the coproduct monad will be strongly normalizing.

Lemma 3.2.14 says that an incomposable pair (α, β) is given by two morphisms such that α is layer-collapsing, and β μ-expansive. The most straightforward argument would be that if a monad is non-collapsing, which would mean that its unit is non-collapsing and the action preserves non-collapsingness, then there could be no layer-collapsing morphisms. Unfortunately, this argument is too restrictive, since only monads arising from term rewriting systems in which the variables of the right-hand side of every rule are contained in the left-hand side preserve non-collapsingness (this the dual of lemma 2.4.8); a counterexample is obtained by dualising the counterexample given on page 81.

So in order to show the result for all collapsing term rewriting systems, we can only assume that the units of the monads are non-collapsing. We will now first give a sketch of the proof for two monads arising from term rewriting systems, before generalizing the proof to arbitrary monads; when doing so, we will need to develop certain notions from term rewriting like “variables occuring in a term” in the monad setting.

5.3.1 Modularity of Termination for Non-Collapsing Term Rewriting Systems

Given two non-collapsing term rewriting systems Θ = (Ω, R) and Ψ = (Σ, S). The main lemma will be to show that for any strongly normalizing category X there is no incomposable pair in colim D_{X}. By lemma 3.2.14, it is sufficient to show that if there is α : t′ → t in T_{Θ}(T_{Ψ}(T_{Θ}(X))) which is in normal form (for all α′ in T_{Θ}(T_{Θ}(X)), T_{Θ}η_{Ψ,T_{Θ}(X)}(α′) ≠ α), but there is s ∈ T_{Θ}(T_{Θ}(X)) such that t = T_{Θ}η_{Ψ,T_{Θ}(X)}(s) (i.e. α is layer-collapsing), then for all β : μ_{Θ,X} (s) → s′′ in T_{Θ}(X) there is β′ : s → s′ such that β′ = μ_{Θ,X} (β); in other words, if there is a layer-collapsing rewrite, it cannot be followed by a μ-expansive one.

For the proof, we decompose the rewrite α : t′ → t into its “top layer” α_{0} and the rest, as follows. For a term t, we have the set var(t) of variables of t; here, since t ∈ T_{Θ}(T_{Ψ}(T_{Θ}(X))), the variables are a subset of the objects of T_{Ψ}(T_{Θ}(X)). Let σ be the inclusion σ : var(t) ↪ T_{Ψ}(T_{Θ}(X)), then t can be given as t = T_{Θ}σ(t_{0}) where t_{0} ∈ T_{Θ}(var(t)) is the “top layer”. Similarly, for α there is a rewrite α_{0} in T_{Θ}(Z) where Z is the subcategory of T_{Ψ}(T_{Θ}(X)) given by those terms and rewrites between them occuring in α; we can define this by structural induction (just like the variables of a term on page 54). α is then given as α = T_{Θ}σ(α_{0}) where σ : Z ↪ T_{Ψ}(T_{Θ}(X)) is the inclusion of Z into T_{Ψ}(T_{Θ}(X)).

Since α is a normal form, no rewrite γ in Z is in the image of η_{Ψ,T_{Θ}(X)}, i.e. no rewrite is a variable, and because η_{Ψ,T_{Θ}(X)} is non-collapsing, no target of γ is in the image of η_{Ψ,T_{Θ}(X)}:

∀x ∈ var(t) ∀y ∈ T_{Ψ}(T_{Θ}(X)) . x ≠ η_{Ψ,T_{Θ}(X)}(y)  (5.2)

Now furthermore assume that α is collapsing, i.e. there is s ∈ T_{Θ}(T_{Θ}(X)) such that T_{Θ}η_{Ψ,T_{Θ}(X)}(s) = t. We now want to show that for all β : μ_{X} (s) → s′ in T_{Θ}(X) there is β′ : s → s′′ in T_{Θ}(T_{Θ}(X)) s.t. β = μ_{X} (β′).

We prove this by showing that under the assumptions just given t as above is a constant, i.e. var(t) = ∅. The proof proceeds by structural induction on t. Let Z =^{def} var(t) be the set of variables of the whole term t. For the induction step, if t = e(t_{1}, …, t_{n}) then T_{Θ}η_{Ψ,T_{Θ}(X)}(s) = e(t_{1}, …, t_{n}) only if s = e(s_{1}, …, s_{n}) and T_{Θ}η_{Ψ,T_{Θ}(X)}(s_{i}) = t_{i}— that is the induction assumption. For the induction base, t = 'x (with x ∈ Z), then T_{Θ}η_{Ψ,T_{Θ}(X)}(s) = 'x only if s = 'y, η_{Ψ,T_{Θ}(X)}(y) = x. This can however be excluded by 5.2 above; hence there can only be an s such that T_{Θ}η_{Ψ,T_{Θ}(X)}(s) = t if there are no variables in t.

Now if t is a constant, s is a constant as well, as will be μ_{X} (s), and if we assume non-expandingness of the two term rewriting systems, a constant in T_{Θ}(X) only rewrites to another constant s′ in T_{Θ}(X), which in turn can be given as a constant s′′ in T_{Θ}(T_{Θ}(X)), giving rise to a rewrite s → s′′ in T_{Θ}(T_{Θ}(X)) as required.

5.3.2 The Monad Proof

The proof just sketched used a couple of concepts for terms which we have not yet developed in the monad setting:

• A term (or rewrite) from T^{w}X was decomposed into a top layer from T_{1}X, and the rest from T^{w}X;

• For a term t ∈ T X, variables x ∈ X may or may not occur in t;

• From this, constants were defined (terms in which no variables occur), along with some properties.

For a monad T = ⟨T, η, μ⟩ on Cat, a term is an object of T X and a rewrite is a morphism in T X, for some category X (see §2.3.4 on page 74); the category X is the context, its objects are the variables, and its morphisms the variable rewrites. But a term t ∈ T_{Ω}(X) need not contain all variables x ∈ X (i.e. there are t s.t var(t) ≠ |X |), so what does it mean for an object x ∈ X to actually occur in t ∈ T X? It seems easy to characterize when x does not occur in t; namely, if we can map x to different values while t remains the same. In other words, if there are two maps (i.e. functors) σ_{1}, σ_{2} : X → Y such that σ_{1}(x) ≠ σ_{2}(x) but T σ_{1}(t) = T σ_{2}(t). Then x occurs in t if T σ_{1}(t) = T σ_{2}(t) implies σ_{1}(x) = σ_{2}(x). This allows us to define the set, or rather the category, of variables of t ∈ T X as a subcategory of the context X. This notion easily carries over to a morphism α : s → t in T X.

Definition 5.3.1 (Category of Variables) Given a monad T = ⟨T, η, μ⟩ on Cat, then for t ∈ T X, for some X, we say that for x ∈ X,

x occurs in t ⇔ ∀σ_{1}, σ_{2} : X → Y . T σ_{1}(t) = T σ_{2}(t) ⇒ σ_{1}(x) = σ_{2}(x)

We similarly define when a variable rewrite f : x → y in X occurs in t, and when x or f occur in α : s → t in T X.

The category of variables Var(t) of t (and Var(α) of α) is defined as the smallest subcategory of X given by all objects and morphisms occuring in t or α, respectively.

Note that for an arbitrary monad we can have non-identity variable rewrites f : x → y occuring in a term t ∈ T X; this will not occur with monads given by term rewriting systems, since it corresponds to the presence of an operation with a non-discrete arity, e.g. an operation F which takes two arguments such that the first argument has to rewrite to the second one.

It is easy to show that for a monad T_{Θ} given by term rewriting system Θ, the objects of Var(X) are isomorphic to the set var(t) of variables of t for all t ∈ T_{Θ}(X); this is done by a structural induction on t, showing that if x ∈ var(t), x occurs in t as defined above, and on the other hand if x occurs in t than it has to be an element of var(t). Further, if η is monic we can show that x occurs in η(y) iff x = y, using naturality if η: T σ_{1}(η_{X} (x)) = T σ_{2}(η_{X} (x)) iff η_{Y}(σ_{1}(x)) = η_{Y}(σ_{2}(x)) iff σ_{1}(x) = σ_{2}(x).

A fact that is actually needed below is that the variables occuring in the source and target of a rewrite will occur in the variables of the rewrite itself as well:

Lemma 5.3.2 For a morphism α : s → t in T X, Var(s) and Var(t) are subcategories of Var(α): Var(s) ↪ Var(α) and Var(t) ↪ Var(α)

Proof. Given x ∈ X, we want to show that if x occurs in s, then x occurs in α as well. Since T σ_{1}, T σ_{2} are functors, we have first implication below, and if x occurs in s we have the second implication:

T σ_{1}(α) = T σ_{2}(α) ⇒ T σ_{1}(s) = T σ_{2}(s)
T σ_{1}(s) = T σ_{2}(s) ⇒ σ_{1}(x) = σ_{2}(x)

so taking the two together, we can conclude that x occurs in α.

A similar argument holds for the variable rewrites f : x → y occuring in s and hence α, making Var(s) a subcategory of Var(α); and similarly, we can show that Var(t) is a subcategory of Var(α). □

We can now decompose any object t or morphism α : u → v in T_{i}T^{w}(X) (with i ∈ L, w ∈ W) into t_{0} ∈ T_{i}(Var(t)), σ : Var(t) ↪ T^{w}(X) with t = T σ(t_{0}), or α_{0} : u_{0} → v_{0} in T_{i}(Var(α)), τ : Var(α) ↪ T^{w}(X) (where τ, σ are the obvious embeddings).

Constants are objects t or morphisms α in T X the category of variables of which is the empty category, 0. The empty category is initial in Cat, i.e. for any other category Y there is a unique functor !_{Y} : 0 → Y. Then the fact that constants remain constants under substitution of variables, and that in a nonexpanding system constants can only rewrite to constants follow categorically: for any monad T = ⟨T, η, μ⟩ on Cat and for all categories Y,

μ_{Y}(T!_{T Y}) = T!_{Y}  (5.3)

which is proven by diagram 5.4, where the left triangle is T applied to !_{T Y} = η_{Y}.!_{Y},

[figure: T 0; T!_{Y}; T Y; T T Y; T η_{Y}; μ_{Y}; T!_{T Y}; T Y; = = = = = = = = = = = = =]  (5.4)

the uniqueness of !, and the right triangle is one of the monad laws.

Further, if T is non-expanding, then T (!_{Y}) is non-expanding, i.e. for all t ∈ T 0, if there is α : T!_{Y}(t) → s, then there is α′(t) → s′ in T 0 s.t. T!_{Y}(α′) = α. This follows because !_{Y} : 0 → Y is non-expanding (simply because there is no x ∈ 0 for which there could be f :!_{Y}(x) → y in Y), and if T is non-expanding, it preserves this, making T!_{Y} non-expanding.

We have now defined and proven the main notions and properties to show the main technical lemma:

Lemma 5.3.3 Let T_{1}, T_{2} be strongly normalizing, regular, non-expanding and non-collapsing monads on Cat, and X be a strongly normalizing category. Let α′ : r′ → t′ be a morphism in T_{1}T_{2}T_{1}X with α : r → t its normal form α = NF(α′) such that α is layer-collapsing, i.e. there is s ∈ T_{1}T_{1}X s.t. t = T_{1}(η_{2,T_{1}X} (t_{0})). Then μ_{1,X} is not expansive at s, i.e. for all β : μ_{1,X} (s) → s′ in T_{1}X, there is β′ : s → s′′ such that μ_{1,X} (β′) = β.

Proof. We decompose α into α_{0} in T_{1}(Var(α)), and σ : Var(α) → T_{2}T_{1}X such that α = T_{1}σ(α_{0}); and similarly, t into t_{0} ∈ T_{1}(Var(t)), τ : Var(t) → T_{2}T_{1}X such that t = T_{1}τ(t_{0}). Since α is a normal form, for all κ in Var(α) there is no λ in T_{1}X such that η_{2,T_{1}X} (λ) = σ(κ); and then since η_{2} is non-collapsing, for all x ∈ Var(α) there is no v ∈ T_{1}X such that η_{2,T_{1}X} (v) = σ(x). By lemma 5.3.2, Var(t) is a subcategory of Var(α), hence this holds in particular for all x ∈ Var(t): there is no v ∈ T_{1}X such that η_{2,T_{1}X} (v) = τ(x). On the other hand, t = T_{1}η_{2,T_{1}X} (t_{0}), hence for all x ∈ Var(t), there is u ∈ T_{1}X such that η_{2,T_{1}X} (u) = τ(x).

Since no x ∈ Var(t) can satisfy both of these properties, we conclude Var(t) has no objects (or morphisms): Var(t) ≅ 0. Then τ : Var(t) → T_{2}T_{1}X is the unique morphism !_{T_{2}T_{1}X} : 0 → T_{2}T_{1}X. By T_{1} applied to uniqueness of !, T_{1}!_{T_{2}T_{1}X} = T_{1}η_{2,T_{1}X}.T_{1}!_{T_{1}X}, hence t = T_{1}η_{2,T_{1}X} (s) = T_{1}η_{2,T_{1}X}.T_{1}!_{T_{1}X} (t_{0}), and by injectivity of T_{1}η_{2} (given by regularity of T_{1} and T_{2}) s = T_{1}!_{T_{1}X} (t_{0}). This means that s is a constant as well, as it can be decomposed into t_{0} ∈ T_{1}0 and !_{T_{1}X} : 0 → T_{1}X.

By equation 5.3, μ_{1,X} (s) = μ_{1,X} (T_{1}!_{T_{1}X} (t_{0})) = T_{1}!_{X} (t_{0}). Since T_{1}!_{X} is nonexpanding, for all β : μ_{1,X} (s) → s′, i.e. β : T_{1}!_{X} (t_{0}) → s′, there is γ : t_{0} → s_{0} such that β = T_{1}!_{X} (γ) = μ_{1,X} (T_{1}!_{T_{1}X} (γ)), hence we have β′ =^{def} T_{1}!_{T_{1}X} (γ) with μ_{1,X} (β′) = β as required. □

Theorem 5.3.4 The coproduct of two strongly normalizing, non-collapsing, regular, and non-expanding monads T_{1}, T_{2} on Cat is strongly normalizing.

Proof. Given a strongly normalizing category X, we have to show that the coproduct T_{1} + T_{2} at X, given by colim D_{X}, is strongly normalizing.

By corollary 5.2.4, it is sufficient to show that for all strongly normalizing categories X, there are no infinite sequences (α_{i})_{i∈ℕ^{+}} in colim D_{X}. Such an infinite sequence consists of morphisms α_{i} in ∐_{w∈W} T^{w}X such that for all k ∈ ℕ^{+}, <α_{1}, …, α_{k}> is a path of minimal length; then by definition 3.2.11 all (α_{i}, α_{i+1}) have to be incomposable pairs.

We will show that there are no incomposable pairs; we can then conclude that there is no infinite sequence. By lemma 3.2.14, an incomposable pair (α, β) is given by two morphisms α : x_{1} → y_{1}, β : x_{2} → y_{2} in normal form such that there are r, s ∈ W, i, j ∈ L, i ≠ j and z ∈ T^{riis}X where α is layer-collapsing at z with y_{1} = η_{j,is}^{ri}(z), and β is μ-expansive at z: x_{2} = μ_{i,s}^{r}(z), and for all β′ : z → z′, μ_{i,s}^{r}(β′) ≠ β. (We can exclude the second case from lemma 3.2.14 here, because both monads are non-expanding.)

Any layer-collapsing morphism α : s → t in T^{rijis}X gives rise to a layercollapsing morphism α′ : s′ → t′ in T^{ijis}X, for which by lemma 5.3.3 there are no μ-expansive morphisms in T^{iis}X (set X in lemma 5.3.3 to T^{s}X, which is a strongly normalizing category.) Since T_{1} and T_{2} are non-expanding, they will preserve the non-expandingness of μ_{i,X}, hence there is no μ-expansive β in T^{ris} and hence there cannot be an incomposable pair. □

Modularity of strong normalization for non-collapsing term rewriting systems then follows as a corollary of this theorem:

Corollary 5.3.5 The disjoint union of two strongly normalizing, non-collapsing, term rewriting systems which do not introduce unbounded variables is strongly normalizing.

Proof. Given two strongly normalizing, non-collapsing, non-expanding term rewriting systems Θ_{1}, Θ_{2} which do not introduce unbounded variables, the monads T_{Θ_{1}} and T_{Θ_{2}} are strongly normalizing by proposition 5.1.5, non-collapsing by lemma 2.4.9, regular by proposition 2.4.4 and non-expanding by lemma 2.4.8. Then by theorem 5.3.4, T_{Θ_{1}} + T_{Θ_{2}} is strongly normalizing, and by proposition 2.5.3, T_{Θ_{1}} + T_{Θ_{2}} ≅ T_{Θ_{1}+Θ_{2}}. Hence (again by proposition 5.1.5), Θ_{1} + Θ_{2} is strongly normalizing. □

5.4 Summary and Conclusion

In this chapter, we have investigated modularity of strong normalization (termination) for monads.

We have defined a semantic notion of termination for categories and monads, and showed it to be equivalent to the usual, syntactic definition found in the literature, in the sense that the monad T_{Θ} is terminating according to the semantic definition if and only if the term rewriting system Θ is terminating according the syntactic definition.

We have given a characterization of termination of the coproduct monad of two terminating monads by infinite sequences of morphisms from the components T^{w}X of ∐_{w∈W} T^{w}X, i.e. the coproduct is terminating if and only if the process of forming paths terminates. In one direction, this characterization only holds for non-expanding monads. This technical lemma is an important tool in proving the strong normalization of the coproduct monad.

Unlike confluence, termination is not modular in general, it only holds under certain assumptions on the term rewriting systems in questions. Usually these formulations are formulated rather syntactically. Here we have proven modularity of strong normalization for non-collapsing monads on a semantic level, using purely categorical reasoning without recourse to the syntax. In order to be able to this, we had to develop categorical counterparts of certain syntactic properties, e.g. we had to define a notion of a variable (an object x ∈ X) occuring in a term (an object t ∈ T X) for an arbitrary monad T. The proof demonstrates that our approach is also suitable for modularity proofs for strong normalization.

All in all, strong normalization with the inherent notion of “counting steps” seems less amenable to categorical analysis than confluence, which after all is just completing diagrams. Nevertheless we were able to show some modularity results, hopefully setting the scene for some more in the future. A worthwhile target would be a categorical version of the results by Gramlich [23] and Ohlebusch [62] that strong normalization is modular for a system which is strongly normalizing under non-deterministic collapses, or an appropriate categorical version thereof. In the long run, exploring a more abstract definition of strong normalization (perhaps along the lines of Hilken [29] mentioned above) may be potentially fruitful avenue of further research.

Conclusions and Further Work

The aim of this thesis was to give a semantics to term rewriting systems which can express the key concepts such as layers and substitutions, but abstracts from unnecessary syntactic details (such as “contexts”), to demonstrate the advantages of the semantics by applying it to modularity problems, and to show the usefulness of (enriched) category theory in the process.

Summary

Our starting point was the modelling of equational presentations by monads on the category of sets.

We have then generalized this to the modelling of term rewriting systems by monads on the category of sets-with-structure. Depending on what aspect of term rewriting one is interested in (one-step vs. many-step, named vs. unnamed reductions), sets-with-structure can be relations, preorders, categories etc, and we can instantiate the general theory to any of these. The theoretical basis is enriched category theory, in particular the theory of finitary enriched monads; the crucial point here is that the construction has to be properly enriched. One of the consequences of this is that the finitely presentable objects of the category of sets-with-structure are the arities of the operations, leading to generalized rewrite rules in which rewrites between variables are allowed.

We have shown that the mapping of term rewriting systems to monads has a right adjoint, given by the internal language of a monad, justifying our calling the semantics compositional; the working assumption here (following Goguen and Burstall) is that many important structuring operations can be expressed as colimits. We have shown in detail how to construct the coproduct of two finitary monads (corresponding to the disjoint union of two term rewriting systems), and sketched the construction of the coequalizer; from these, any other colimit can be constructed.

As an application of our semantics, we have turned our attention to modularity problems, in particular the modularity of confluence and strong normalization under the disjoint union. We have proven modularity of confluence (Toyama’s theorem), and the modularity of strong normalization for non-collapsing term rewriting systems. By proving these results in our more general, abstract, categorical framework we were able to extend Toyama’s theorem to systems which introduce so-called bounded variables on the right, and to quasi-non-expanding systems.

In the rest of this concluding chapter, we will review other approaches to categorical term rewriting, and compare them with our work. We will close this chapter by indicating directions of future research.

6.1 Related Work

Categorical term rewriting — using category theory to give models of term rewriting systems — is by no means new. We will now give a (necessarily subjective and incomplete) review of the literature in this field, in order to assess the significance of the work presented in this thesis.

As far as the category theory is concerned, the reader is referred to [69] for an account of the work on monads. Suffice it to say here that the modelling of equational presentations started with Linton [48], and that its generalization, to base categories other than Set and to enriched categories, is due, apart from Kelly and Power [39], to Dubuc and Kelly [11], and Burroni [5].

6.1.1 Early Work

The idea of representing term rewriting systems by 2-categories (or other enriched categories), in which the morphisms represent the terms and the 2-cells the reductions between them, goes back to two seminal papers by Seely [81] and Rydeheard and Stell [73].

Seely [81] argues that “2-categories occur naturally as structures in computer science”, and as an example presents a 2-category LAMBDA which has the types of the simply typed λ-calculus as objects, the terms as morphisms and βηreductions between the terms as 2-cells. The motivation for putting 2-cells in a perfectly ordinary category lie in categorical logic: both proofs in intuitionistic first-order logic and terms of the simply typed λ-calculus can be presented by a cartesian closed category, in which the types are objects and the terms are morphisms (see [45]). Then reductions between proofs, as studied in proof theory [67], lead to 2-cells between morphisms and 2-categories as models of these reductions (called hyperdoctrines [80]), and since reductions between proofs correspond to reductions in the λ-calculus, one arrives at the 2-category sketched above.

The foundations for this work have been laid by the “Australian school” around the Sydney Category Seminar and their work on 2-categories and enriched categories; in particular, Street [86] proposes the notion of a computad which is essentially a Semi-Thue or string rewriting system, but without making the relation to term rewriting explicit; this has been left to Power [64].

Rydeheard and Stell [73] start from a completely different (and more familiar) angle: the categorical treatment of universal algebra. They consider the Kleislicategory Set_{T_{Ω}} of the monad T_{Ω} given by a signature Ω: this has sets of variables as objects, and substitutions of variables as morphisms (i.e. morphisms in Set_{T_{Ω}} are of the form σ : X → T_{Ω}(Y), where X and Y are sets, which we can think of as assignment of variables from X to terms in T_{Ω}(Y)), and proceed to introduce reductions on the substitutions as 2-cells. This work has been developed by Stell in his thesis [82] and the subsequent [83], in which he advocates the use of Sesquicategories instead of 2-categories, because they have a notion of length which 2-categories lack.

6.1.2 Later and Contemporary Work

The work of Seely [81] was further developed by Jay and Ghani [31, 32, 17, 18]. They investigate structures modelling reductions for a specific term rewriting systems, namely the typed λ-calculus and extensions of it. The category theory is used to arrive at “well-behaved” rewrite rules; in particular [17] proposes the idea that the introduction and elimination rules for a particular type should be adjoint to each other. This for example leads to η-expansions rather than ηcontractions, and was successful in solving a long standing problem about the confluence of the simply typed λ-calculus with a coproduct type. [17] lead to a series of papers, systematically applying the theory of η-expansions to increasingly complicated type theories, from System F [19] to the Calculus of Constructions [20].

The 2-category T_{Ω} constructed in [73] can be obtained essentially as the Kleisli-category of the monad T_{Θ} of proposition 2.3.9, except that T_{Ω} has sets rather than categories as objects. Stell [82, 83] uses Sesqui-categories rather than 2-categories, but the construction remains the same. All of this is more concerned with investigating the structure of the reductions given by the term rewriting systems, rather than finding a compositional semantics as is our aim; for example, a typical theorem [82, Theorem 5.4.2] shows that a specific kind of spans^{1} in the Sesqui-category corresponds precisely to the critical pairs of the term rewriting system. Hilken [29] investigates the algebraic structure given by the 2-cells in the categorical models of the typed λ-calculus in order to develop a proof theory for the reductions in the typed λ-calculus.

Gray, in a series of papers, proposed “enriched sketches” to model typed λcalculi [28] and algebraic datatypes [26, 25, 27]. This work uses the formalism of sketches to investigate properties of the datatypes and term rewriting systems specified (to great effect: [28] shows that the typed λ-calculus can be given as an initial algebra for a finite limit sketch, and derives from it an implementation in the rewriting tool Mathematica), and is not concerned with modularity.

Johnson [33], on the other hand, goes a step further and gives a 3-categorical model of (linear) term rewriting systems. This allows to consider linear term rewriting systems as Semi-Thue systems with an extra dimension, but it is not clear that the additional complications of 3-categories outweigh this simplification.

A rather different approach is put forward by Melliès, which he calls axiomatic rewriting [55, 56]. He defines an Axiomatic Rewrite System as a graph with a reduction (or derivation) structure on the paths, giving rise to a 2-category, which is then shown to satisfy certain standardization properties. The key point here is the correlation of the Church-Rosser property to the existence of push-outs, and the standardization to factorization systems as in [14].

6.1.3 Other Work

Meseguer [57] uses a generalized form of term rewriting systems called rewrite theories to model concurrent systems. Briefly, a rewrite theory is a a signature with equations, and conditional term rewrite rules of the form [s] ↠ [t] if [s_{1}] ↠ [t_{1}], …, [s_{n}] ↠ [t_{n}] meaning the equivalence class [s] rewrites to [t] if all [s_{i}] rewrite to [t_{i}]. The construction of the syntactic model T_{R}(X) for a rewrite theory R is somewhat similar to the construction of the term reduction algebra T_{Θ}(X) (similar rules to generate derivations, similar equations on them), but it is far more general in scope (providing a unified model of concurrency). The common feature here, also occurring in Milner’s action structures [60] is the use of enriched categories with a monoidal structure, the morphisms of which are terms, and the enrichment models the reduction. [9] investigates the relation between Meseguer’s rewriting logic and Stell’s modelling of term rewriting further, though not necessarily more deeply.

1Two 2-cells with the same source.

Power [65] considers a categorical formulation of Hoare’s data refinement [30] in terms of enriched monads over Pos as an instantiation of the enriched monad theory in [39], but although the categorical framework is essentially the same as used in this thesis, no explicit connection to term rewriting is made.

Reichel [68] and Stokkermans [84] both consider critical-pair completion procedures in a 2-categorical framework. This allows an abstract notion of critical pair completion, subsuming such apparently diverse problems as Knuth-Bendix completion [43], construction of Gröbner bases or resolution [70]. Although an elegant abstract notion, it does not lend itself to new results.

Although the phrase “free”^{2} is liberally used to describe categorical models of term rewriting systems [83, 57], only [86] explicitly exhibits the adjunction between syntax (computads) and semantics (the category of 2-categories) (and in particular, the right adjoint).

6.1.4 Discussion

As mentioned above, the main novelties of the semantics presented in thesis are:

• the construction of the semantics as a monad;

• the generalized rewrite rules and variable rewrites;

• the freeness of the construction, exhibited by the adjunction in proposition 2.5.3;

• the modularity results obtained from it.

The monad gives the abstract way of building the semantics, and the theory of enriched monads tells us how the terms are constructed, what arities are, what algebras are etc. Separate from this, the different choices of enrichment correspond to different models of reduction, so we can model all of ordered categories, Sesquicategories or 2-categories in this framework. This is precisely what makes the semantics amenable to generalizations in various respects (see §6.2 below): the “modularization” of the semantics allows to change parts of it without having to rebuild it from scratch.

When the work mentioned in §6.1.1– §6.1.3 lead to new results (e.g. [18]), these are mostly proven syntactically, on the level of terms; that term rewriting results (like the generalization of Toyama’s theorem) are obtained using purely categorical reasoning is another distinguishing feature of this work. In fact, none of the work mentioned above tackled modularity, probably because there is no canonical way to combine arbitrary 2-categories. And while I would not claim that the construction of the coproduct monad is particularly simple, it is far simpler than the corresponding combination of 2-categories.

2Sometimes, “free” is used to describe a left adjoint (e.g. [12]). This wording is unfortunate, since the more common understanding in calling a functors F : C → D free is that D is monadic over C.

6.2 Future Work

The work in this thesis hopefully serves as a starting point for future research.The amenability to generalization has been pointed out as one of the advantages of the approach, so possibilities for future work exist at least in three directions:

• generalizing the term rewriting;

• improvements of the theory;

• or generalizing the structuring operations.

6.2.1 Generalizing the Term Rewriting

This thesis dealt with unconditional, single-sorted, first-order term rewriting systems. The generalization to many-sorted term rewriting systems is straightforward (see page 91), but one can envisage other more challenging generalizations:

• Conditional term rewriting systems. A conditional term rewriting system is given by a signature Ω, and rules l → r ⇐ s_{1} ≈ t_{1} … s_{n} ≈ t_{n}. The ≈ can be interpreted in at least three different ways, giving rise to different variations of conditional rewrite systems (see e.g. [3]). One way to model a conditional term rewriting system C in this framework would be to construct an endofunctor S_{C} on the category Ω-Alg of Ωalgebras in Pre, taking any algebra A to the smallest algebra A′ s.t. A′ ⊧ l → r if A ⊧ s_{i} ≈ t_{i} for all i = 1, …, n and all conditional rules l → r ⇐ s_{1} ≈ t_{1} … s_{n} ≈ t_{n}, or taking A to A if this is not the case. Then let T_{C} be the free monad on S_{C}, and by precomposition with the adjunction between Pre and Ω-Alg to obtain a monad on Pre. Another way to model conditional systems would be to encode the conditions in the arities (using non-discrete arities); this would mean that the arities could be non-finite, and would lead to non-finitary monads.

• Variable rewrites.

Variable rewrites allow us to write down more things than before, for example the equivalence closure of a term rewriting systems as a term rewriting system (see example 2.3.6 on page 71). In effect, this is a (albeit rather limited) form of conditional term rewriting, and it would be interesting to investigate the limits of the additional expressivity gained.

• Hidden sorts and operations.

There should be a way to model hidden operations (and sorts, for the manysorted case), and observational equivalence, perhaps by using final semantics rather than initial semantics [91]. The monad framework might even allow to combine initial and final semantics [90].

• λ-calculi.

It is well-known how to model typed λ-calculi in cartesian closed categories [45], and how closed cartesian categories can be obtained as algebras for a 2-monad on Cat; so it should be possible to generalize this to the reduction structure given by the η-expansion and β-reduction. It would be particularly attractive to be able to use the modularity results of chapters 4 and 5 to show confluence and strong normalization of different variations of the typed λ-calculus.

• Orthogonal term rewriting systems. A term rewriting system is orthogonal if it is left-linear, and the rules contain no overlapping left sides. This is actually a specialization rather than a generalization, but orthogonal systems enjoy a lot of desirable properties (e.g. they are confluent), and it might be worthwhile to arrive at an abstract notion of orthogonality on the level of monads, perhaps along the lines of [63]. Related to this, one might want to consider critical pairs and completion procedures in this setting, as in [84] and [68].

• Rewriting modulo equations.

The generalization of the monad construction to a rewriting system with equations (aka. a rewriting logic [57]) is straightforward and has already been sketched above (page 91). However, the resulting monad does not preserve coequalizers and will hence not be strongly finitary (only finitary), so neither the coproduct construction nor the modularity results apply. Hence, the treatment of rewriting modulo equations, in particular modularity results for these systems, will require a more general construction for the coproduct.

• Connection with axiomatic rewriting.

The connection of the approach presented here with Melliès’ axiomatic rewriting [55, 56] is far from clear, and deserves further clarification. For example, can we derive similar modularity results as in chapter 4 if we replace our definition of confluence with Melliès’ pushout property?

• Other properties.

Although confluence and strong normalization are the most important properties of term rewriting systems, one might want to prove to investigate modularity results for other properties such as weak normalization (which is modular, see e.g. [59], where further modularity results for other properties can be found as well). In particular, a categorical proof of the modularity of completeness for left-linear systems [89] would be an interesting challenge ([54] presents a simplified proof of this result).

6.2.2 Improving the Theory

The coproduct construction as given in chapter 3 is rather ad hoc: it assumes that the two monads in question are strongly finitary, a quite strong restriction. A more general and systematic approach (suggested by John Power) would start from the observation that the category of monads on A is itself monadic over the category of finitary endofunctors on A, and then apply the construction of colimits of algebras from [2, Chapter 9.3] and [49].

Another area worthy of improvement are the regularity conditions on the monads in §2.4.2. The present definitions are more a convenient technical shortstop than a good attempt at an axiomatization, and it would be worthwhile to investigate whether they can be replaced by a set of conditions which would be easier to verify, less technical in nature, or hopefully both. In particular, it should be investigated wether one can replace definition 2.4.2 by requiring the unit and multiplication to be cartesian natural transformations (see also [7], and the discussion on page 80).

6.2.3 Generalizing the Structuring Operations

We have only considered coproducts of monads above, so the obvious generalization here would be to consider modularity for coequalizers of monads. Unfortunately, in this generality we even lose modularity of confluence (coequalizers correspond to arbitrary quotienting, and it is easy to see that this destroys confluence). Perhaps attention should be restricted to particular colimits such as push-outs modelling unions with shared constructors. This would correspond to a pushout diagram like 6.1 in which the inclusions i_{1}, i_{2} are non-expanding.

[figure: Θ_{0}; ⊂; i_{1}; Θ_{2}; Θ_{2}; i_{2}; ∩; Θ_{1} +_{Θ_{0}} Θ_{2}]  (6.1)

6.3 Concluding Remarks

The aim of this thesis was to present a semantics for term rewriting systems which is on the one hand abstract enough to be able to forget all about the details of the syntax, and on the other hand still expressive enough to be able to prove the properties arising from the syntax.

I hope the reader will agree that the proofs given in chapter 4 and 5 justify these claims. All in all, this work should just be a start — the real test will be to arrive at really new term rewriting results, along the lines of the future research mentioned above. A semantics is after all only useful if it gives us new insights into the area we study.

Appendix A

Using Monads to Model Named Reductions

In this appendix, we will elaborate on the remarks on page 67 and show how to model named reductions by a monad on the category of small categories. The construction contains three main steps, just like the corresponding construction for unnamed reductions in chapter 2.

Apart from showing how the generic framework of enriched monad theory adumbrated in §2.2 can be instantiated to a different framework then preorders, named reductions are important in their own right for two reasons:

• When considering strongly normalizing systems, preorders are actually not precise enough, because the reflexive closure destroys strong normalization for any term reduction algebra: the term reduction algebra from definition 2.3.4 will never be strongly normalizing, neither as a relation (by definition 1.6.4) nor as a category (by definition 5.1.1). In order to make them strongly normalizing by definition 5.1.1, we need to be able to tell apart the identity rewrite 1_{t} : t → t on any term t from other, cyclic rewrites from t to itself.

• When considering quasi-non-expanding systems, we actually want equations on the reductions. We would like to be able to express that a reduction α : t → s has a retract α^{−1} : s → t, which when composed with α yields the identity on t: α^{−1}.α = 1_{t}. In order to formulate equations on reductions, they have to be named.

The structure of this chapter mirrors the structure of chapter 2: we first define a monad T_{Θ} on the category Cat in §A.1 (as in §2.3)), then show that the monad is regular (§A.2, corresponding to §2.4), and finally show that there is an adjunction between the category of term rewriting systems and the category of monads on Cat (§A.3, corresponding to §2.5).

A.1 A Term Construction for Named Reductions

In chapter 2, we have seen how term rewriting systems can be modelled by monads on the category of sets-with-structure, generalizing the treatment of equational presentations. The choice of the particular set-with-structure depends on which aspect of term rewriting one is interested in, and in §2.3, we have seen how a monad on the category Pre of preorders models unnamed many-step reductions. In this section of the appendix, we will see how to model named many-step reductions by a monad on the category Cat of all small categories.

The basic construction will be the same— closing the rules under substitution, application of operations, reflexivity (identities) and transitivity (composition), but the named reductions offer us some technical complications. Since we now want to distinguish different reductions between the same two terms, we have to introduce a term structure on the reductions. This in turn means that where in the unnamed case it was enough to show that the definitions on the objects preserve the order structure, we now have to define everything in the morphisms explicitly.

We will, for a category X, construct the term named-reduction algebra T_{Θ}(X), a category which has as objects the terms built over the objects of X, and as morphisms named reductions between the terms. These reductions will be freely generated, and then quotiented in order to make the mapping of X to the term reduction algebra a suitably enriched functor, and to make the unit and multiplication natural transformations. These equations can also be motivated from a term rewriting point of view, and it is instructive to see how the instantiation of the general theory makes sense in a particular setting.

The freely generated term structure, called the prereductions, will be defined in §A.1.1, together with a substitution function, and a notion of lifting functors and natural transformations. In §A.1.2, we will define the necessary equations on the prereductions, obtaining the term named-reduction algebra T_{Θ}(X) on a category X, which has terms as objects and named reductions between terms as morphisms. Finally, in §A.1.3, we will show that the mapping X ↦ T_{Θ}(X) extends to a monad T_{Θ} on Cat. We will close the section by investigating the relationship to the “unnamed” term reduction algebra defined in §2.3.3.

The monad T_{Θ} is of course enriched, and as has been mentioned in §1.5.3 on page 43, there are two different closed monoidal structures on Cat, the familiar cartesian one, and a slightly more exotic one called Sesqui (as in Sesqui-category). It is possible to enrich over either of them, but instead of picking one now, we will first develop that part of the theory which is common to both enrichments, and on page 180, we will discuss the differences within this framework; this allows us a uniform treatment of both enrichments and a discussion of their difference. As it turns out, the differences are fairly small, amounting to just one additional equation being necessary for the cartesian closed structure.

A.1.1 Prereductions

Since the contexts of the rewrite rules are given by the finitely presentable objects of the base category, they will now be given by fp categories (i.e. finitely presentable objects in Cat, see §1.3.8 on page 19), and we need to readjust the definition of generalized rewrite rules accordingly. This is merely a rephrasing of definition 2.3.1 on page 69, which it supersedes for the rest of this section:

Definition A.1.1 (Generalized Rewrite Rule) A generalized rewrite rule in a signature Ω is given by a triple (X , l, r), written as (X ⊢ l → r), where X is a category, and l, r ∈ T_{Ω}(|X |). X is called the context, l the left-hand side, and r the right-hand side of the rule. If the category X is discrete, the rewrite rule is called ordinary; if the category X is fp, it is called finitary. If there is a morphism f : x → y in X, we say there is a variable rewrite from x to y.

When instantiating a finitary rule (X ⊢ l → r), it is no more sufficient to give the instantiations of the terms, we have to explicitly supply a morphism Inst(α) for all morphisms α : x → y in X, which means an instantiation of a rule (X ⊢ l → r) in Z is a functor Inst : X → Z.

The construction of prereductions now follows very much definition 2.3.4 — the prereductions are given by variable rewrites (rule [Var] below), application of operations (rule [Pre]) and instantiated rewrite rules (rule [Inst]). Note that in the latter case, although a finitely presentable category X may have infinitely many morphisms, a functor F : X → Y is determined by its action on a finite subset of the morphisms in X.

Definition A.1.2 (Prereductions) For a category X (called the context), the prereduction graph Q_{Θ}(X) on X is the graph with

• vertices, the set of terms built over the objects of X: V (Q_{Θ}(X)) =^{def} T_{Ω}(|X |)

• edges, the smallest set satisfying the implications in table A.1.

[Var] {κ ∈ X (x, y) \atop 'κ : 'x → 'y ∈ E(Q_{Θ}(X))}

[Pre] \begin{matrix}for i = 1, …, m. β_{i} : s_{i} → t_{i} in F(Q_{Θ}(X)) \\ ω(β_{1}, …, β_{m}) : ω(s_{1}, …, s_{m}) → ω(t_{1}, …, t_{m}) ∈ E(Q_{Θ}(X)) \end{matrix} ω ∈ Ω_{m}

[Inst] Inst : Y → F(Q_{Θ}(X)) is a functor ρ[Inst] : s → t ∈ E(Q_{Θ}(X)) where s =^{def} μ_{|X |}(Inst_{Obj}^{∗}(l)), t =^{def} μ_{|X |}(Inst_{Obj}^{∗}(r)) ρ = (Y ⊢ l → r) ∈ R

Table A.1: Definition of prereduction graph.

The prereductions on X are given by the free category on the prereduction graph Q_{Θ}(X):

P_{Θ}(X) =^{def} F(Q_{Θ}(X))

For rule [Pre], recall from page 37 the notation s(s) and t(s) for the source and target of a path t. Further, for rule [Inst] Inst_{Obj}^{∗} is the lifting of the object function Inst_{Obj} of the functor Inst, as from definition 2.1.5, and μ_{|X |} is the multiplication for terms of the monad T_{Ω} from proposition 2.1.6. Then μ_{|X |}(Inst_{Obj}^{∗}(l)) is the substitution of the variables in l, which in the notation from page 58 can also be written l[t_{1}, …, t_{n}] with t_{i} =^{def} Inst(y_{i}).

Under the adjunction between Grph and Cat, in order to define a functor F : P_{Θ}(X) → Y we have to give a graph morphism f : Q_{Θ}(X) → UY, and this means we have to define a vertex function f_{V} : T_{Ω}(|X |) → |Y| (the object function for F), and a map f_{E} : Q_{Θ}(X) → UMor_{Y}, mapping edges in T_{Θ}(X) to morphisms in Y. This way we can define the process of lifting functors and transformations, which will later become the action of the monad modelling the term rewriting system on the morphisms and 2-cells of Cat, respectively.

Note that we define the lifting for the slightly more general notion of transformations rather than natural transformations— this means that we can use the same definition for both different enrichments over Cat.^{1} Definition A.1.3 (Lifting of Functors and Transformations) For a functor F : X → Y its lifting is given by the functor F^{∗} : P_{Θ}(X) → P_{Θ}(Y), which on objects is given by F_{Obj}^{∗} : T_{Ω}(|X |) → T_{Ω}(|Y|) from definition 2.1.5, and on the paths is defined by the following mapping on the edges:

1Of course, we will have to show that the lifting of a natural transformation is again natural — or rather, we will need some equations to enforce this since it is not the case with the definition as it stands.

F^{∗}(ω(α_{1}, …, α_{n})) =^{def} <ω(F^{∗}α_{1}, …, F^{∗}α_{n})> where ω ∈ Ω_{n}
F^{∗}(ρ[Inst]) =^{def} <ρ[F^{∗}.Inst]>  where ρ ∈ R
F^{∗}('κ) =^{def} <{' \atop (F κ)}>

Given a transformation α : F ⇒ G : X → Y, its lifting is a transformation α^{∗} : F^{∗} ⇒ G^{∗} : P_{Θ}(X) → P_{Θ}(Y), given by a family of prereductions in P_{Θ}(Y), indexed by terms t ∈ T_{Ω}(|X |), defined inductively on t as follows:

α_{ω(t_{1},... ,t_{n})}^{∗} =^{def} <ω(α_{F^{∗}(t_{1})}^{∗}, …, α_{F^{∗}(t_{n})}^{∗})> for t_{1}, …, t_{n} ∈ T_{Ω}(|X |)
α_{'x}^{∗} =^{def} <{' \atop α_{x}}>  for x ∈ |X |

Having defined the lifting, we give the transformation which models the the substitution of the nascent term calculus. We leave aside the variables (i.e. the unit) just now, since we do not need them for the time being.

Definition A.1.4 (Substitution) For a category X, the object function of the functor μ_{X} : P_{Θ}(P_{Θ}(X)) → P_{Θ}(X) is given by the natural transformation μ_{|X |} : T_{Ω}(T_{Ω}(|X |)) → T_{Ω}(|X |) from proposition 2.1.6, and the morphisms function as follows:

μ_{X} (e(α_{1}, …, α_{m})) =^{def} <e(μ_{X} (α_{1}), …, μ_{X} (α_{m}))>
μ_{X} (ρ[Inst]) =^{def} <ρ[μ_{X}.Inst]>
μ_{X} ('κ) =^{def} κ

The process of lifting is unfortunately not functorial. In particular, the lifting id_{F}^{∗} of the identity transformation id_{F} on a functor F : X → Y is not the identity transformation id_{F^{∗}} on the lifted functor, as can be easily seen: the latter is given by the empty path id_{F^{∗}(t)} for any t ∈ P_{Θ}(X), whereas lifted transformations are by definition not empty. (Recall from page 37 that the empty path from t to itself is written as id_{t}.) Hence, we will need to enforce some equations on the prereductions in order to make it into one. Apart from a category theorist’s idle worries, there are actually quite good reasons for these equations from the term rewriting point of view, which we will explain below.

But first, we would like to prove that μ_{X} is natural in X. For this, we introduce our main proof principle — a structural induction scheme like proposition 2.3.7.

Structural Induction

We need some notation for fp categories first. Let Y be an fp category, then FinMor_{Y} is the finite set of morphisms generating all other morphisms by composition and identifying. Those morphisms determine the image of any functor F : Y → X, since any functor has to preserve composition, and any morphism in Y can be given as a composition of morphisms from FinMor_{Y}. The reason for introducing this notation is the computation of the size of a prereduction below, which would not go through if we would form a sum over an infinite set.

Proposition A.1.5 Given a predicate Z ⊆ P_{Θ}(X), we write α ⊧ Z (Z holds for α) if α ∈ Z for α ∈ P_{Θ}(X). Then ∀α ∈ P_{Θ}(X). α ⊧ Z (Z holds for all prereductions), if all implications in table A.2 hold.

[IndBase] <'κ> ⊧ Z κ : x → y in X

[IndInst] ∀α ∈ FinMor_{Y}. Inst(α) ⊧ Z <ρ[Inst]> ⊧ Z \begin{matrix}ρ = (Y ⊢ l → r) ∈ R, \\ Inst : Y → P_{Θ}(X) \end{matrix}

[IndPre] {β_{1} ⊧ Z, …, β_{n} ⊧ Z \atop <e(β_{1}, …, β_{n})> ⊧ Z} e ∈ Ω_{n}, β_{i} ∈ P_{Θ}(X) for i = 1, …, n

[IndSeq] {<α_{1}> ⊧ Z, …, <α_{n}> ⊧ Z \atop <α_{1}, …, α_{n}> ⊧ Z} α_{i} ∈ Q_{Θ}(X) for i = 1, …, n

Table A.2: Structural Induction for Prereductions.

Proof. We prove the validity of structural induction by reducing it to natural induction. To this end, we define the size of a prereduction (intuitively, the number of times one of the prereduction forming rules [Pre] and [Inst] is applied) as follows:

size('κ) =^{def} 0
size(e(α_{1}, …, α_{n})) =^{def} 1 + ∑_{i=1}^{n} size(α_{i})  (A.1)

size(<ρ[Inst]>) =^{def} 1 + ∑_{α∈FinMor_{Y}} size(Inst(α))  (A.2)
size(<α_{1}, …, α_{n}>) =^{def} ∑_{i=1}^{n} size(α_{i})

Given a predicate Z on P_{Θ}(X) as above, we define the predicate q on ℕ:

q(n) ⇔ (∀α ∈ P_{Θ}(X). size(α) ≤ n ⇒ α ⊧ Z)

If under the assumption that the four implications in table A.2 hold we can show that q(n) holds for all n ∈ ℕ , we can then by definition of q conclude that Z holds for all prereductions α.

We now show that q(n) holds for all n ∈ ℕ by well-founded induction on n. Generally, for any path <α_{1}, …, α_{m}> ∈ P_{Θ}(X) if we can establish <α_{i}> ⊧ Z for i = 1, …, m, we can use [IndSeq] to conclude <α_{1}, …, α_{m}> ⊧ Z.

The induction base is q(0). Then for a path <α_{1}, …, α_{m}> ∈ P_{Θ}(X) with size(<α_{1}, …, α_{m}>) = 0, we have that for j = 1, …, m, α_{j} must be a variable, so α_{j} = 'κ; and by applying [IndBase], <{' \atop α_{j}}> ⊧ Z, hence <α_{1}, …, α_{n}> ⊧ Z. Further, note that by [IndSeq], id_{t} ⊧ Z for all t, i.e. Z holds for all empty paths.

For the induction step, we have to show q(n), assuming q(m) for all m < n; i.e. assume that for all β ∈ P_{Θ}(X) with size(β) < n, β ⊧ Z, and then show (using the implications) that for all <α_{1}, …, α_{l}> ∈ P_{Θ}(X) with size(<α_{1}, …, α_{l}>) = n, <α_{1}, …, α_{l}> ⊧ Z. For i = 1, …, l, α_{i} is of size size(α_{i}) ≤ n, and we distinguish three cases:

1. α_{i} = 'κ, then by [IndBase], <'κ> ⊧ Z.

2. α_{i} = e(β_{1}, …, β_{k}), then for all j = 1, …, k, by clause A.1 above size(β_{j}) < n, and by the induction assumption β_{j} ⊧ Z; using [IndPre], we conclude <e(α_{1}, …, α_{k})> ⊧ Z.

3. α_{i} = ρ[Inst], then similarly by clause A.2 we can apply the induction assumption to all α ∈ FinMor_{Y}, and use [IndInst] to obtain <ρ[Inst]> ⊧ Z.

Hence we can conclude that <α_{1}, …, α_{m}> ⊧ Z and that q(n) holds. □

As an example of structural induction, we show that the substitution μ_{X} : P_{Θ}(P_{Θ}(X)) → P_{Θ}(X) is natural in X, i.e. for all functors F : X → Y, we have

F^{∗}μ_{X} = μ_{Y}F^{∗∗}  (A.3)

The equation is shown extensionally, i.e. we show that F^{∗}μ_{X} (α) = μ_{Y}F^{∗∗}(α) for all prereductions α in P_{Θ}(P_{Θ}(X)) by structural induction. The induction base is α = <'κ>, then F^{∗}(μ_{X} (<'κ>)) = F^{∗}κ = μ_{Y}<'F^{∗}κ> = μ_{Y}F^{∗∗}<'κ>. The induction steps proceed by unfolding the definitions, applying the induction assumption, and folding the definitions again, e.g.

F^{∗}μ_{X} <e(β_{1}, …, β_{n})> = <e(F^{∗}μ_{X} β_{1}, …, F^{∗}μ_{X} β_{n})>
= <e(μ_{Y}F^{∗∗}β_{1}, …, μ_{Y}F^{∗∗}β_{n})>
= μ_{Y}F^{∗∗}<e(β_{1}, …, β_{n})>

A.1.2 Named Reductions

We are now going to describe the particular set of equations which we are going to enforce on the prereductions. These equations can be motivated twofold: from a categorical point of view, these equations make the whole construction into a monad; in particular, they make the lifting process functorial. This may not be very interesting from a term rewriting point of view, but one might want to bear in mind that in category theory, “everything important happens in the morphisms”^{2}, so having accepted its basic tenets we should let this principle guide us to a “good” construction. Moreover, we can also motivate these equations from a term rewriting point of view; here, they mean that the composition of rewrites is compatible with putting rewrites into a context as well as with taking morphisms from X to rewrites in P_{Θ}(X), and that identity variable rewrites are identity rewrites. In an informal notation,

• if C is a context, and α_{1}, α_{2} prereductions, then

C[α_{1}]::C[α_{2}] = C[α_{1}::α_{2}]

• if κ and λ are composable variable rewrites, then

                           <'κ>::<'λ> = <'λ.κ>

• and for t ∈ T_{Ω}(|X |),

                              id_{t} = <\begin{matrix}' \\ 1 & t \end{matrix}>

One could further want that putting a rewrite into context commutes with instantiating rules; this will be the equation that distinguishes Sesqui-enrichment from cartesian enrichment.

2Or rather hom-objects, since we are talking enriched categories here.

Different Enrichments

At this juncture we need to have another look at the two possible enrichments over the two monoidal structures on Cat. The above equations are enough — as we will presently see — to define a monad on Cat_{S}, the Sesqui-category of all small categories. But this monad will not be enriched over Cat_{C}, the 2-category of all small categories, since the lifting of a natural transformation is not necessarily natural.

To explain this, consider the simple system with two unary operations F, G and the rule ρ = (Z ⊢ F('z) → G('z)), where Z is the category with one object z. Let X be the category with two objects x, y and a non-identity morphism f : x → y. By mapping z to x and y, respectively, we have two functors I, J : Z → X, and the morphism f in X gives a natural transformation α : I ⇒ J. By definition A.1.3, we can lift I, J and α to α^{∗} : I^{∗} ⇒ J^{∗} : P_{Θ}(X) → P_{Θ}(Y). Consider the prereduction s =^{def} <r[1_{z}]> in P_{Θ}(Z), then I^{∗}(s) = <ρ[1_{x}]> and J^{∗}(s) = <ρ[1_{y}]>. If α^{∗} were natural, then the following diagram in P_{Θ}(X) would commute

                         F('x) \overline{α_{F('z)}^{∗}_{}}F('y)

                       [figure: G('x); I^{∗}(s); α_{G('z)}^{∗}; G('y); J^{∗}(s)]

but this does not follow from the equations above. Another way to look at this is that the rewrite 'f : 'x → 'y put into the contexts given by the source and target of the rewrite rule ρ should commute with the instantiated rewrite rule.

From a term rewriting point of view, this question is equivalent to asking that for any rule ρ : l → r, and any rewrite α : s → t, we have

<l[α], ρ[t]> = <ρ[s], r[α]>

and it is debatable whether this question should hold or not. One may think of the equation as describing that rewrites can take place in parallel, concurrently [57]. From a categorical point of view, cartesian enrichment seems favourable, since the main advantage of Sesqui-categories is that they have a categorical notion of length [83], which we do not need for our treatment of strong normalization, and all in all cartesian enrichment seems more natural.

The language of lifted functors, transformations and the substitution μ_{X} from definition A.1.4 lets us make rather elusive informal notation such as l[α] precise, as we will be doing now in order to define the necessary equations.

Horizontal Composition

Given a natural transformation α : F ⇒ G : X → Y, and a functor H : Y → Z, the horizontal composition of α with H is a natural transformation Hα : HF ⇒ HG : X → Z, defined by (Hα)_{x} =^{def} H(α_{x}). Similarly, the horizontal composition of α with a functor M : W → X is defined as αM : F M ⇒ GM : W → Y,

(αM)_{x} =^{def} α_{Mx}.^{3}

Here, the functors roughly correspond to terms or contexts, and natural transformations correspond to rewrites, so the horizontal composition of α with a functor H on the left corresponds to putting the rewrite into context, whereas composition of α with M on the right corresponds to instantiating the variables in α. To illustrate this principle, we will now prove two equations, which say that substitution commutes with rewriting (equation A.4), and that translation (along a lifted functor) commutes with the substitution of variables (equation A.5). The equations will be needed later on.

For the first equation, given a natural transformation α^{∗} : F^{∗} ⇒ G^{∗} : P_{Θ}(X) → P_{Θ}(Y), we can compose α^{∗} with the functor μ_{X} : P_{Θ}(P_{Θ}(X)) → P_{Θ}(X) on the right, or we can compose the functor μ_{Y} : P_{Θ}(P_{Θ}(Y)) → P_{Θ}(Y) with the lifting of α^{∗}, α^{∗∗} : F^{∗∗} ⇒ G^{∗∗}, on the right. Both of these should be equal:

α^{∗}μ_{X} = μ_{Y}α^{∗∗}  (A.4)

This is also called the 2-naturality of μ, and it is proven by showing that for all t ∈ P_{Θ}(P_{Θ}(X)), α_{μ_{X} (t)}^{∗} = μ_{Y}α_{t}^{∗∗}. The proof proceeds by structural induction on the term t. The induction base is given by

α_{μ_{X} ('s)}^{∗} = α_{s}^{∗} = μ_{Y}<'α_{s}^{∗}> = μ_{Y}(α_{s}^{∗∗})

and the induction step is similar (if even more straightforward).

For the second equation, given a functor F : X → Y, and a natural transformation α : I ⇒ J : Z → P_{Θ}(X), we can lift the horizontal composition F^{∗}α, obtaining (F^{∗}α)^{∗} : F^{∗∗}I^{∗} ⇒ F^{∗∗}J^{∗}, with (F^{∗}α)_{t}^{∗} = F^{∗∗}(α_{t}^{∗}). Together with the naturality of μ (equation A.3), we obtain

F^{∗}(μ_{X} (α_{t}^{∗})) = μ_{Y}(F^{∗∗}(α_{t}^{∗})) = μ_{Y}((F^{∗}α)_{t}^{∗})  (A.5)

Equations on prereductions

An equation on prereductions is a pair of prereductions in the same context X with the same source and target, i.e. a triple (X , l, r) where X is a fp category, and l, r ∈ P_{Θ}(X) s.t. s(l) = s(r), t(l) = t(r). An equation (X , l, r) is denoted as X ⊢ l = r. Recall from page 37 that a path congruence is an equivalence relation on paths with the same source and target (implication 1.22), compatible with the composition (implication 1.23). A congruence relation on prereductions is a path congruence additionally compatible with the application of operations and instantiation of rules.

3This is special case of the tadpole composition introduced on page 31.

Definition A.1.6 (Prereduction Congruence) For a category X, a prereduction congruence is given by a path congruence ≡ ⊆ P_{Θ}(X) × P_{Θ}(X) such that for all ω ∈ Ω_{n} and α_{1}, β_{1}, …, α_{n}, β_{n} ∈ P_{Θ}(X),

α_{1} ≡ β_{1}, …, α_{n} ≡ β_{n} ⇒ <ω(α_{1}, …, α_{n})> ≡ <ω(β_{1}, …, β_{n})> (A.6)

and for all (Z ⊢ l → r) ∈ R, Inst_{1}, Inst_{2} : Z → P_{Θ}(X)

(∀α in Z . Inst_{1}(α) ≡ Inst_{2}(α)) ⇒ <ρ[Inst_{1}]> ≡ <ρ[Inst_{2}]>  (A.7)

Given a set of equations on prereductions, we can generate a prereduction congruence for categories X by closing under equivalence (i.e. reflexivity, transitivity and symmetry) and implications 1.23, A.6 and A.7.

Reductions

Putting the last two sections together, we can now make the informal notation of the section before that precise.

Definition A.1.7 (Equations on the Prereductions) For an fp category X, the set of equations E_{0} is defined as the smallest set of equations such that:

• For all operations ω ∈ Ω_{n}, and for i = 1, …, n, α_{i} ∈ P_{Θ}(X), β_{i} ∈ P_{Θ}(X) s.t. t(α_{i}) = s(β_{i})

X ⊢ <e(α_{1}, …, α_{n}), e(β_{1}, …, β_{n})> = <e(α_{1}::β_{1}, …, α_{n}::β_{n})> ∈ E_{0} (A.8)

• For all κ : x → y, λ : y → z in X:

X ⊢ <'κ, 'λ> = <'(λ.κ)> ∈ E_{0}  (A.9)

• For all x ∈ X,

X ⊢ <\begin{matrix}' \\ 1 & x \end{matrix}> = id_{'x} ∈ E_{0}  (A.10)

The set E_{1} is defined as E_{0}, augmented by the following additional equations: for all rules ρ = (Z ⊢ l → r) ∈ R, functors Inst_{1}, Inst_{2} : Z → P_{Θ}(X) and natural transformations α : Inst_{1} ⇒ Inst_{2},

X ⊢ <ρ[Inst_{1}]>::μ_{X} (α_{r}^{∗}) = μ_{X} (α_{l}^{∗})::<ρ[Inst_{2}]> ∈ E_{1}  (A.11)

Definition A.1.8 (Term Named-Reduction Algebra) Given a term rewriting system Θ = (Ω, R). Let ≡_{0} be the prereduction congruence generated from the set of equations E_{0}, and ≡_{1} be the prereduction congruence generated from E_{1}. Then for a category X, the term named-reduction algebra T_{Θ}(X) on X is the category with terms T_{Ω}(|X |) as objects and the reductions as morphisms:

T_{Θ}(X) =^{def} P_{Θ}(X)/≡_{1}

with the obvious sources and targets, the identity on t being given by 1_{t} =^{def} [id_{t}], and the composition by the composition of (equivalence classes of) paths.

This definition is suited for cartesian enrichment; for the Sesqui variant, we need to quotient the reductions by the equivalence E_{0}. Instead of using equivalence classes we will continue to work with prereductions, using the congruences ≡_{0} and ≡_{1} as equality. This also means we can still use structural induction as defined above. When defining functions (or predicates) in this manner, we have to ascertain that they are well-defined, i.e. they preserve the congruence. This means in particular they have to respect equations A.8 to A.11. We will stress the cartesian enrichment in the following, since we consider it more important; but we will use E_{0} as equality where it is sufficient to do so, making it clear for which results precisely the additional equation in E_{1} is used. It turns out that it is only needed to show the naturality of lifted natural transformations.

A.1.3 The Monad T_{Θ}

We are now going to extend the assignment X ↦ T_{Θ}(X) to a functor on the category Cat_{C} of all small categories, enriched over the cartesian product. We have defined above (definition A.1.3) the lifting of functors and natural transformations on prereductions; we now have to show that these definitions are well-defined w.r.t. to the congruences ≡_{0} and ≡_{1}, respectively; and further, that this lifting is functorial in the sense that it preserves compositions and identities.

We first treat the lifting of functors. Given a functor F : X → Y, we have to show that equations A.8 to A.11 are preserved, i.e. if Z ⊢ s = t ∈ E_{0} then F^{∗}(l) ≡_{0} F^{∗}(r). For equation A.8, we use the fact that F^{∗} preserves composition of paths, for equation A.9 the fact that F is a functor and preserves composition in X, and for equation A.10, the fact that F preserves identities (hence <\begin{matrix}' \\ 1 & F x \end{matrix}> = <{' \atop F 1_{x}}>). For equation A.11, we use equation A.5, then

F^{∗}(<ρ[Inst_{1}]>::μ_{X} (α_{r}^{∗})) = <ρ[F^{∗}Inst_{1}]>::μ_{Y}((F^{∗}α)_{r}^{∗})
≡_{1} μ_{Y}(F^{∗}α)_{l}^{∗}::<ρ[F^{∗}Inst_{2}]>
= F^{∗}(μ_{X} (α_{l}^{∗})::<ρ[Inst_{2}]>)

This ends the proof that F^{∗} is well-defined. We now turn to natural transformations. Given ν : F ⇒ G : X → Y, ν^{∗} is clearly well-defined. To prove that ν^{∗} is natural, we have to show that for all α : s → t in P_{Θ}(X),

F^{∗}(α)::ν_{t}^{∗} ≡_{1} ν_{s}^{∗}::G^{∗}(α)

The proof proceeds by structural induction on α. The induction base uses the naturality of ν: let κ : x → y in X, then

F^{∗}<'κ>::ν_{'y}^{∗} = <{' \atop F κ}>::<{' \atop ν_{y}}> ≡_{0} <'ν_{y}.F κ> = <'Gκ.ν_{x}> ≡_{0} ν_{'x::G^{∗}<'κ>}^{∗}

The induction steps [IndPre] and [IndSeq] are just a matter of applying the definitions, and the induction assumption. The case [IndInst] is different. We first apply the definition of F^{∗}, followed by equations A.4 and A.11:

F^{∗}(<ρ[Inst]>)::ν_{μ_{X} Inst^{∗}(r)}^{∗} = <ρ[F^{∗}Inst]>::μ_{X} ν_{Inst^{∗}(r)}^{∗∗}
= <ρ[F^{∗}Inst]>::μ_{X} (ν_{Inst}^{∗})_{r}^{∗}
≡_{1} μ_{Y}(ν_{Inst}^{∗})_{l}^{∗}::<ρ[G^{∗}Inst]>
= ν_{μ_{Y}Inst^{∗}(l)}::G^{∗}<ρ[Inst]>

This ends the proof of well-definedness for ν^{∗}. We can now define the action of the monad.

Definition A.1.9 (Action of the Monad) Given a term rewriting system Θ = (Ω, R), the functor T_{Θ} : Cat → Cat maps a category X to the term reduction algebra T_{Θ}(X) on X, a functor F : X → Y to its lifting F^{∗} : T_{Θ}(X) → T_{Θ}(Y), and a natural transformation ν : F ⇒ G to its lifting ν^{∗} : F^{∗} ⇒ G^{∗}.

We have to show that T_{Θ} is indeed a functor (a 2-functor to be precise), meaning it preserves composition and identities for functors natural transformations.

The former means that for two functors F : X → Y and G : Y → Z, (GF)^{∗} = G^{∗}F^{∗}, and for any category X, (1_{X})^{∗} = 1_{T_{Θ}(X)}, both of which are proven pointwise (i.e. for any category X) by routine structural induction (on the reductions in T_{Θ}(X)). The latter means that for any two natural transformations ν : F ⇒ G : X → Y and ι : G ⇒ H : X → Y, (ι.ν)^{∗} = ι^{∗}.ν^{∗}. This is also proven pointwise: for any category X, and any object t ∈ T_{Θ}X (i.e. term t ∈ T_{Ω}(|X |)), show that (ι.ν)_{t}^{∗} ≡_{0} ι_{t}^{∗}.ν_{t}^{∗} by structural induction on t.

The identity on a functor F : X → Y is given the identity transformation id_{F} : F ⇒ F (see page 14). Preservation of this means that the lifting of the identity is the same as the identity on the lifting, i.e. id_{F^{∗}} = id_{F}^{∗}. In the same vein as before, the proof proceeds pointwise, showing for any category X, id_{F^{∗}(t)} ≡_{1} id_{F (t)}^{∗} for all objects t ∈ T_{Ω}(|X |) by structural induction on t. We are now in a position to state the main result:

Proposition A.1.10 Every term rewriting system Θ = (Ω, R) gives rise to a monad T_{Θ} = ⟨T_{Θ}, η, μ⟩ on Cat.

Proof. The action of the monad has been defined in definition A.1.9, and the multiplication in definition A.1.4. Equations A.3 and A.4 show naturality and 2-naturality of μ. It remains to define the unit, and show the monad laws.

The unit is given by a natural transformation η : 1_{Cat} ⇒ T_{Θ}, which is a family of functors

η_{X} : X → T_{Θ}(X)

indexed by categories X. On objects, it is defined by the natural transformation η_{|X |} : 1_{|X |} ⇒ T_{Ω} from lemma 2.1.4, and on morphisms as follows:

η_{X} (κ) =^{def} <'κ>

Showing that every η_{X} is a functor, and that η forms a natural transformation is a matter of routine induction.

It remains to prove the monad laws. In particular these are

μ_{X}.η_{T_{Θ}(X)} = 1_{X}  (A.12)
μ_{X}.η_{X}^{∗} = 1_{X}  (A.13)
μ_{X}.μ_{X}^{∗} = μ_{X}.μ_{T_{Θ}(X)}  (A.14)

All of these equations are proven pointwise on reductions α ∈ T_{Θ}(X). Equation A.12 follows straightforward from the definition of η and μ. Equations A.13 and A.14 are proven by routine structural induction on α. □

A.1.4 Named vs. Unnamed Reductions

In §2.3.3 on page 70, the term reduction algebra was defined (which we will call term unnamed-reduction algebra in the following to distinguish it from the term named-reduction algebra), and a natural question to ask is the precise relation between that and the term named-reduction algebra which we have just defined. The answer is that the preorder given by the term named-reduction algebra over a category X is equal to the term unnamed-reduction algebra over the preorder given by X. For the following, recall that J : Cat → Pre is the functor taking a category to a preorder by identifying all morphisms between the same objects in the category (see page 42).

Lemma A.1.11 For a term rewriting system Θ = (Ω, R), and an fp category X,

J(T_{Θ}(X)) = T_{Θ}(J(X))  (A.15)

where on the left we have the term named-reduction algebra, and on the left the term unnamed-reduction algebra built over the preorder J(X).

Proof. Obviously, the objects of J(T_{Θ}(X)) and T_{Θ}(J(X)) are the same (namely, the terms T_{Ω}(|X |)); it remains to show that there is a reduction s ≥ t in T_{Θ}(J(X)) iff there is a reduction α : s → t in T_{Θ}(X) (for s, t ∈ T_{Ω}(|X |)). We show that s ≥ t in T_{Θ}(J(X)) iff there is a prereduction α : s → t by a routine structural induction in two directions, observing that for all rules in table A.1, definition A.1.2, there is a corresponding rule in table 2.3, definition 2.3.4, and vice versa. Then iff there is at least one prereduction, there will be at least one reduction. □

However, the term unnamed-reduction algebra considered as a category over a preorder X is not isomorphic to the term named-reduction algebra over X considered as a category, because the former (but not the latter) will identify any two reductions with the same source and target.

A.2 Properties of the Monad T_{Θ}

We are now going to show that the monad T_{Θ} is regular in the sense of definition 2.4.3. We first show that T_{Θ} is strongly finitary. For this, we separately show that T_{Θ} preserves filtered colimits, and coequalizers, and then use lemma 1.3.7. To prove preservation of filtered colimits, we need the following lemma, which roughly says that a colimit does not contain more objects and morphisms than necessary:

Lemma A.2.1 Given a filtered functor F : J → Cat, and a colimiting cone c : F ⇒ ΔC, then all objects and morphisms in C are in the image of c in the following sense:

∀x ∈ C ∃j ∈ J , y ∈ F j. x = c_{j}(y)  (A.16)
∀α ∈ Mor_{C} ∃j ∈ J , β ∈ Mor_{F j}. c_{j}(β) = α  (A.17)

Proof. Recall from proposition 1.3.1 that every colimiting cone can be constructed as a coequalizer, and that every coequalizer is epi. From section 1.5.3 we know that epis in Cat are functors which are surjective on objects (that is (A.16) above), and surjective under closure on morphisms:

∀α ∈ C ∃j ∈ J , β_{1}, …, β_{n} ∈ Mor_{F j} . c_{j}(β_{n}). . . ..c_{j}(β_{1}) = α (A.18)

For filtered colimits, the hom-sets of C can be constructed “pointwise” without needing to close under composition since F does not identify objects (cf. [4, 5.2.2.f]), then (A.18) simplifies to (A.17) above. □

Lemma A.2.2 Given a term rewriting system Θ = (Ω, R), the monad T_{Θ} is finitary.

Proof. Let F : J → Cat be a functor with J filtered. Let c : F ⇒ ΔX be a colimiting cone for F. We now want to show that the lifting c^{∗} : T_{Θ}F ⇒ ΔT_{Θ}(X) of c is colimiting for T_{Θ}F. We do this by establishing the universal property: given any other cone ν : T_{Θ}F ⇒ ΔY over T_{Θ}F, there is a unique functor !_{ν} : X → Y such that

\begin{matrix}T_{Θ}F & = c^{∗} ⇒ & ΔT_{Θ}(X) \\ ΔY & ^{Δ!_{ν} ; ‖} & ^{ν \begin{matrix}= \\ = \\ = \\ = \\ = \\ = \\ = \\ = \\ = \\ = \\ = \\ = \\ ⇒ \end{matrix}} \end{matrix}

We are now going to define the functor !_{ν}. The idea of the proof is as follows: we show that any object in T_{Θ}(X) is in the image of c^{∗} (A.19 below), and then its value under !_{ν} is the value of this object under ν. This gives a mapping on the objects of T_{Θ}(X), which we then extend to a functor.

To define !_{ν}, we first prove that

∀t ∈ T_{Ω}(|X |) ∃j ∈ J , y ∈ T_{Ω}(|F j|) . c_{j}^{∗}(y) = t  (A.19)

and then define

!_{ν}(t) =^{def} ν_{j}(y)  (A.20)

and we furthermore have to show that this definition is well-defined (in particular, independent of the choice of j in A.19).

Both the proof of A.19 and of the well-definedness proceed by structural induction on t. For the induction base, let 'x ∈ T_{Ω}(|X |), then x ∈ X, and by lemma A.2.1, there is j ∈ J , y ∈ F j such that x = c_{j}(y), hence c^{∗}('y) = 'x.

For the induction step, let ω(t_{1}, …, t_{n}) ∈ T_{Ω}(|X |), and assume that for i = 1, …, n, we have k_{i} ∈ J and t′_{i} ∈ F k_{i} s.t. c_{k_{i}}^{∗}(t′_{i}) = t_{i}. Since J is filtered, there is an object j ∈ J and morphisms p_{i} : k_{i} → j, and with c^{∗} being a cone over T_{Θ}F, we have

c_{k_{i}}^{∗} = c_{j}^{∗}(F p_{i})^{∗}

and then y is defined as

y =^{def} ω((F p_{1})^{∗}(t′_{1}), …, (F p_{n})^{∗}(t′_{n}))

and as required

c_{j}^{∗}(y) = c_{j}^{∗}(ω((F p_{1})^{∗}(t′_{1}), …, (F p_{n})^{∗}(t′_{n})))
= ω(c_{j}^{∗}(F p_{1})^{∗}(t′_{1}), …, c_{j}^{∗}(F p_{n})^{∗}(t′_{n}))
= ω(c_{k_{1}}^{∗}(t′_{1}), …, c_{k_{n}}^{∗}(t′_{n}))
= ω(t_{1}, …, t_{n})

Now show that equation A.20 is well-defined: suppose we have another object l ∈ |J | with morphisms q_{i} : k_{i} → l; then this defines

z =^{def} ω((F q_{1})^{∗}(t′_{1}), …, (F q_{n})^{∗}(t′_{n}))

and we have to show that ν_{l}(z) = ν_{j}(y). By filteredness of J, for i = 1, …, n there is an object m ∈ J and morphisms s : l → m and r : j → m such that s.q_{i} = r.p_{i}; and since ν is a cone over T_{Θ}F, diagram A.21 commutes and we have

[figure: T_{Θ}F l; T_{Θ}F k_{i}; (F q_{i})^{∗}; T_{Θ}F m; ν_{m}; (F s)^{∗}; |X |; ν_{l}; T_{Θ}F j; ν_{j}; (F r)^{∗}; (F p_{i})^{∗}]  (A.21)

the following:

ν_{j}(y) =^{def} ν_{j}(ω((F p_{1})^{∗}(t′_{1}), …, (F p_{n})^{∗}(t′_{n}))
= ν_{m}(ω((F r)^{∗}(F p_{1})^{∗}(t′_{1}), …, (F r)^{∗}(F p_{n})^{∗}(t′_{n})))
= ν_{m}(ω((F s)^{∗}(F q_{1})^{∗}(t′_{1}), …, (F s)^{∗}(F q_{n})^{∗}(t′_{n})))
= ν_{l}(ω((F q_{1})^{∗}(t′_{1}), …, (F q_{n})^{∗}(t′_{n})))
= ν_{l}(z)

This concludes the structural induction and the construction of the object function of !_{ν}. We now have to construct !_{ν} on the morphisms. We have to show that

∀α ∈ T_{Θ}(X) ∃j ∈ J β ∈ T_{Θ}(F j) . c_{j}^{∗}(β) = α  (A.22)

and then define

!_{ν}(α) =^{def} ν_{j}(β)  (A.23)

Again, this is proven by structural induction, this time on the reduction α.

The base case is <'κ> ∈ T_{Θ}(X), then κ ∈ Mor_{X} and by lemma A.2.1 there is j ∈ J, λ ∈ Mor_{F j} such that c_{j}(λ) = κ, hence c^{∗}(<'λ>) = <'κ>. The case of <ω(α_{1}, …, α_{n})> is very similar to the induction step of the object case above (use induction assumption for the α_{i}, and filteredness of J).

For the case of <ρ[Inst]>, with ρ = (Z ⊢ l → r), the induction assumption is that for all α : z → z′ in Z there is l_{α} ∈ J , β_{α} : s → t in T_{Θ}(F j) s.t. c_{l_{α}}^{∗}(β_{α}) = Inst(α). Again, by filteredness there is j ∈ J and morphisms p_{α} : l_{α} → j s.t. c_{l_{α}}^{∗} = c_{j}^{∗}(F p_{α})^{∗}. We define the instantiation

Inst′(α) = F p_{α}(β_{α})

then c_{j}^{∗}(Inst′(α)) = c_{j}^{∗}(F p_{α}(β_{α})) = c_{l_{α}}^{∗}(β_{α}) = Inst(α) and have y =^{def} <ρ[Inst′]>, with

c_{j}^{∗}<ρ[Inst′]> = <ρ[c_{j}^{∗}Inst]>
= <ρ[Inst]>

Uniqueness is again proven like before: if there is any other object l ∈ J satisfying A.22, then there is another object m ∈ |J | and morphisms r : j → m, s : l → m, and both ν_{l} and ν_{j} filter through ν_{m}, hence !_{ν}(x) is well-defined. This ends the structural induction on the reductions, and the proof.

□

Lemma A.2.3 Given a term rewriting system Θ, the functor T_{Θ} preserves coequalizers.

Proof. Given two functors F, G : X → Y. Let Q : Y → Z be the coequalizer of F and G, and P : T_{Θ}(X) → C be the coequalizer of F^{∗} and G^{∗}. To show the lemma, we show that C and T_{Θ}(Z) are isomorphic.

Since all coequalizers are epi (see lemma A.2.1), all objects in C lie in image of P (which in the following will just be denoted by the representative [x] = P (x)); and for the same reason, all objects in Z lie in the image of Q, hence all objects in T_{Θ}(Z) lie in the image of Q^{∗}. We show the isomorphism by showing that, for all objects s, t ∈ T_{Ω}(|Y|)

Q^{∗}(s) = Q^{∗}(t) ⇔ [s] = [t]  (A.24)

and for all reductions α, β in T_{Θ}(Y)

Q^{∗}(α) = Q^{∗}(β) ⇔ [α] = [β]  (A.25)

In other words, we prove that the equivalence generated by F^{∗} and G^{∗} is a congruence on the terms; and this follows from the fact that F^{∗} and G^{∗} by definition respect the structure of the terms.

We will first prove equation A.24. To this end, some notation: let ∼ be the relation generating the equivalence ≡ on T_{Ω}(|Y|), defined as

x ∼ y ⇔ ∃z ∈ T_{Ω}(|X |).f^{∗}z = x, g^{∗}z = y

then ≡ is the equivalence closure of ∼. The proof proceeds by structural induction on both s (the outer induction) and t (the inner induction).q We distinguish four case (corresponding to the inner and outer induction bases and steps, respectively):

1. s = 'x, t = 'y For all x ∈ X, Q^{∗}('x) = 'Qx = '[x] = ['x]; hence Q^{∗}('x) = Q^{∗}('y) iff [x] = [y] iff ['x] = ['y].

2. s = 'x, t = ω(t_{1}, …, t_{m}) Since Q^{∗}('x) ≠ Q^{∗}(ω(t_{1}, …, t_{m})), we show that ['x] ≠ [ω(t_{1}, …, t_{m})]. In this case s ≁ t, since there is no z ∈ T_{Ω}(|X |) such that F^{∗}z = 'x and G^{∗}z = ω(t_{1}, …, t_{m}) (because F^{∗}z = 'x only if z = 'u, and then G^{∗}z ≠ ω(t_{1}, …, t_{m}), and vice versa). This is preserved by the equivalence closure: reflexive and symmetric closure are trivial, and for the transitive closure, G^{∗}z_{1} = F^{∗}z_{2} only if both z_{1} = 'u_{1} and z_{2} = 'u_{2}, or z_{1} = e(u_{1}, …, u_{n}) and z_{2} = e(v_{1}, …, v_{n}) with F^{∗}u_{i} = G^{∗}v_{i}.

3. s = e(s_{1}, …, s_{n}), t = 'y This case is symmetric to the one before.

4. s = e(s_{1}, …, s_{n}), t = ω(t_{1}, …, t_{m}) Q^{∗}(e(s_{1}, …, s_{n})) = Q^{∗}(ω(t_{1}, …, t_{m})) iff e = ω and Q^{∗}s_{i} = Q^{∗}t_{i} for i = 1, …, n. The induction assumption here is that Q^{∗}(s_{i}) = Q^{∗}(t_{i}) iff [t_{i}] = [s_{i}]; and it remains to show that [e(s_{1}, …, s_{n})] = [ω(t_{1}, …, t_{m})] iff e = ω and [s_{i}] = [t_{i}] for all i = 1, …, n. The direction “only if” is easy to see; to show the other direction, note that F^{∗}z = e(s_{1}, …, s_{n}) implies z = e(z_{1}, …, z_{n}) (similarly for G^{∗}); with this, we can show that e(s_{1}, …, s_{n}) ∼ ω(t_{1}, …, t_{m}) if e = ω and s_{i} ∼ t_{i} for i = 1, …, m. This is preserved under the equivalence closure, hence [e(s_{1}, …, s_{n})] = [ω(t_{1}, …, t_{m})] iff e = ω and [s_{i}] = [t_{i}] for all i = 1, …, n as desired.

This ends the proof of equivalence A.24.

The proof is completed by showing the equivalence between the morphisms of C and T_{Θ}(Z) (equation A.25). This proof proceeds by a similar structural induction on the two reductions α, β in equation A.25. The basic proof scheme is the same, but for reductions we have four implications in the structural induction, as opposed to two for terms, leading to sixteen cases. Reductions generated from different rules can never be equivalent (cases 3 and 4 above), nor can lifted functors identify them; rules generated with the same rule are identified if they are generated with the same parameter (the operations e and ω above, here either two operations, or two rules), which is exactly the case in which the lifted functors can identify objects. □

We can now state the main result of this section:

Proposition A.2.4 Given a term rewriting system Θ, the monad T_{Θ} on Cat is regular.

Proof. By lemma A.2.2, T_{Θ} is finitary, by lemma A.2.3 preserves coequalizers, hence by lemma 1.3.7, T_{Θ} is strongly finitary.

That η is monic follows straightforward from the definition, as well as η being regular. That μ is regular is proven similar to proposition 2.4.4; we have to extend the partial function σ from the objects to the morphisms, by defining the morphism function of σ : T_{Θ}(T_{Θ}(Y)) × T_{Θ}(X) ⇀ T_{Θ}(T_{Θ}(X)) as follows:

σ(e(α_{1}, …, α_{n}), e(β_{1}, …, β_{n})) =^{def} e(σ(α_{1}, β_{1}), …, σ(α_{n}, β_{n}])
σ(ρ[Inst], ρ[Inst′]) =^{def} ρ[σ⟨Inst, Inst′⟩]
σ('κ, λ) =^{def} <'λ>

One now shows that this is well-defined, i.e. respects the equations A.8 to A.11 by a structural induction on the first argument. □

A.3 Compositionality

This section extends §2.5 to the named reduction case. There it was shown that there is an adjunction

TRS [figure: ⊥] Mon_{Fin}(Pre)

between the category of term rewriting systems, and the category of strongly finitary monads on Pre, and it was argued that this adjunction justified our calling the semantics compositional. Here, we are going to show that there is an adjunction

TRS [figure: ⊥] Mon_{Fin}(Cat)

between the category of term rewriting systems, and the category of strongly finitary monads on Cat, making the named reduction semantics compositional as well.

We first define the internal language of a finitary monad on Cat. This internal language is a more elaborate version of the internal language for a monad on Pre (see §2.3.4 on page 74), where we can now tell the structure of a reduction — one can think of this as the reason, or proof, why one term rewrites to another.

For the following, recall the adjunction from lemma 2.1.9, given by the monad generated from a signature, and the internal signature of a monad; in particular its counit, consisting of natural transformations ε_{T} : T_{Σ(T)} ⇒ T for every monad T on Set, which allows us to evaluate terms built in the internal signature in T.

Definition A.3.1 (The Internal Language) The internal language of a finitary monad T = ⟨T, η, μ⟩ on Cat is given by

L(T) =^{def} (Σ(T_{0}), R(T))

where Σ(T_{0}) is the internal signature (definition 2.1.7) of the underlying object monad T_{0} on Set (see §2.3.4 on page 74), and R(T) is the set of rewrite rules admitted by T defined as follows:

R(T) =^{def} \{r(α) : (X ⊢ l → r) | \begin{matrix}∃X ∈ Cat_{fp}, \\ α ∈ T X (ε_{T_{0},|X |}(l), ε_{T_{0},|X |}(r))\} \end{matrix}

where r(α) can be thought of as the rewrite rule given by the the morphism α.

We are now going to extend the mapping of a term rewriting system Θ to the monad T_{Θ} from proposition A.1.10, and on the other hand a monad to its internal language, to a pair of functors between the categories TRS and Mon_{Fin}(Cat).

Definition A.3.2 The functor F : TRS → Mon_{Fin}(Cat) maps a term rewriting system Θ to the monad T_{Θ}, and a TRS morphism σ : Θ → Θ′ to its lifting, the monad morphism σ̂ : T_{Θ} ⇒ T_{Θ′}, defined pointwise for every category X as a functor σ̂_{X} : T_{Θ}(X) → T_{Θ′}(X). The object function is given by the lifting of the signature morphism σ_{S} in definition 2.1.8, and the morphism function as follows:

σ̂_{X} (e(α_{1}, …, α_{n})) =^{def} <(σ_{S}e)(σ̂_{X} (α_{1}), …, σ̂_{X} (α_{n}))>
σ̂_{X} (ρ[Inst]) =^{def} <(σ_{R})[σ̂_{X}.Inst]>
σ̂_{X}('κ) =^{def} <'κ>

The functor U : Mon_{Fin}(Cat) → TRS maps a finitary monad T to its internal language L(T), and a monad morphism σ : T ⇒ S to the TRS morphism Uσ : L(T) → L(S) which on the signatures is as in definition 2.1.7, and on rules

Uσ_{R}(r(α) : (X ⊢ l → r)) =^{def} r(σ_{X} (α)) : (X ⊢ { \atop (Uσ)}_{S}(l) → { \atop (Uσ)}_{S}(r))

That the lifting σ̂ is natural in X is shown by structural induction; that it satisfies equation 1.3 is fairly obvious, that it satisfies 1.4 requires another easy induction. Hence σ̂ is a monad morphism. Two more structural inductions show that the lifting is functorial, i.e. τ̂.σ = τ̂.σ̂, and ˆ1_{Θ} = id_{T_{Θ}}.

To show that Uσ as above is a morphism of term rewriting systems, we have to show that Uσ_{R}(r(α)) is a rewrite rule in the internal language of S, i.e. Uσ_{R}(r(α)) ∈ R(S). Since ε_{T_{0}} is natural in T_{0} (equation 2.8), we have

σ_{|X |}.ε_{T_{0},|X |} = ε_{S_{0},|X |}.σ̂_{S}

and hence the following chain of implications:

α ∈ T X (ε_{T_{0},|X |}(l), ε_{T_{0},|X |}(r))

⇒ σ_{X} α ∈ SX (σ_{|X |}ε_{T_{0},|X |}(l), σ_{|X |}ε_{T_{0},|X |}(r))
⇒ σ_{X} α ∈ SX (ε_{S_{0},|X |}.σ̂_{S}(l), ε_{S_{0},|X |}.σ̂_{S}(r))
⇒  r(σ_{X} (α)) ∈ R(S)

We can now show the main result of this section, that the two functors F and U are adjoint.

Proposition A.3.3 The two functors F and U form an adjunction F −| U : TRS → Mon_{Fin}(Cat).

Proof. Given a term rewriting system Θ = (Ω, R), the unit of the adjunction is a TRS morphism υ_{Θ} : Θ → L(T_{Θ}) defined as follows:

• On the signatures, it is the unit of the adjunction from lemma 2.1.9:

υ_{Θ,S} =^{def} υ_{Ω}

• On the rules, it is defined as

υ_{Θ,R}(ρ) =^{def} r(<ρ[1_{X}]>) : (X ⊢ υ̂_{Ω}(l) → υ̂_{Ω}(r)) where ρ = (X ⊢ l → r)

This is a TRS morphism by the triangle laws of the adjunction from lemma 2.1.9: these imply that ε_{T_{Ω}}.υ̂_{Ω}(l) = l and ε_{T_{Ω}}.υ̂_{Ω}(r) = r, hence r(<ρ[1_{X}]>) ∈ R(T_{Θ}).

To show adjointness, we show the universality of υ_{Θ} from Θ to U: given a monad S = ⟨S, ζ, ξ⟩ and a TRS morphism ν : Θ → L(S), there is a unique monad morphism !_{ν} : T_{Θ} ⇒ S such that U!_{ν}.υ_{Θ} = ν. This monad morphism is a natural transformation given by a family of functors !_{ν,X} : T_{Θ}X → SX for every category X, which on the objects are given by !_{S_{0},|X |} : T_{Ω}(|X |) → S_{0}(|X |) from lemma 2.1.9, and on the morphisms is defined as follows:

!_{ν,X} (e(α_{1}, …, α_{1})) =^{def} ν(e)[!_{ν,X} (α_{1}), …,!_{ν,X} (α_{n})]
!_{ν,X} (ρ[Inst]) =^{def} ξ_{X} (S(!_{ν,X}.Inst)(ϕ))
where r(ϕ) = ν(ρ)
!_{ν,X} ('κ) =^{def} ζ_{X} (κ)

which is readily shown to be natural in X, a monad morphism and the only one satisfying the equation above. □

We finish this section by again drawing attention to the fact that the adjunction above is ordinary, not enriched (see the footnote on page 89).

A.4 Summary and Conclusion

In this appendix, we have shown how to instantiate the general theory of enriched monads in a slightly different and more elaborate way, obtaining a semantics for named reductions by monads over the category Cat of all small categories. The construction of the semantics is mainly an extension of chapter 2 to a suitable term structure on the morphisms. The semantics is compositional as well, i.e. there is an adjunction between the category of term rewriting systems and the category of finitary monads over Cat.

This semantics goes beyond normal term rewriting in that we can distinguish different reductions between two terms. One could use this setting to e.g. reason about reduction strategies. It is also useful when reasoning about strong normalization, where one needs to be able to tell the identity on a object apart from other endomorphisms (since the latter always lead to non-termination).

Bibliography

[1] J. Adamek and J. Rosický. Locally Presentable and Accessible Categories. Number 189 in London Mathematical Society Lecture Note Series. Cambridge University Press, 1994.

[2] M. Barr and C. Wells. Toposes, Triples and Theories. Number 278 in Grundlehren der mathematischen Wissenschaften. Springer Verlag, 1985.

[3] J. A. Bergstra and J. W. Klop. Conditional rewrite rules: Confluence and termination. Journal of Computer and System Sciences, 32:323– 362, 1986.

[4] F. Borceux. Handbook of Categorical Algebra 2: Categories and Structures. Number 51 in Encyclopedia of Mathematics and its Applications. Cambridge University Press, 1994.

[5] A. Burroni. Algèbres graphiques. Cahiers de Topologie et Géométrie Différentielle, 23:249– 265, 1981.

[6] R. M. Burstall and J. A. Goguen. The semantics of CLEAR, a specification language. In Proc. Advanced Course in Abstract Software Specification, number 86 in Lecture Notes in Computer Science, pages 292– 332, Copenhagen, 1980. Springer Verlag.

[7] A. Carboni and P. T. Johnstone. Connected limits, familial representability and Artin glueing. Mathematical Structures in Computer Science, 5:441– 449, 1995.

[8] P. M. Cohn. Universal Algbra. Harper and Row, 1965.

[9] A. Corradini, F. Gadducci, and U. Montanari. Relating two categorical models of term rewriting. In J. Hsiang, editor, Rewriting Techniques and Applications, 6^{th} International Conference, number 914 in Lecture Notes in Computer Science, pages 225– 240, Kaiserslautern, Apr. 1995. Springer Verlag.

[10] N. Dershowitz and J. P. Jouannaud. Rewrite systems. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Handbook of Theoretical Computer Science, volume B (Formal Methods and Semantics), chapter 6, pages 243– 320. The MIT Press, 1990.

[11] E. J. Dubuc and G. M. Kelly. A presentation of topoi as algebraic relative to categories or graphs. Journal for Algebra, 81:420–433, 1983.

[12] H. Ehrig and B. Mahr. Fundamentals of Algebraic Specification 1: Equations and Initial Semantics, volume 6 of EATCS Monographs on Theoretical Computer Science. Springer Verlag, 1985.

[13] H. Ehrig and B. Mahr. Fundamentals of Algebraic Specification 2: Module Specifications and Constraints, volume 21 of EATCS Monographs on Theoretical Computer Science. Springer Verlag, 1990.

[14] P. J. Freyd and G. M. Kelly. Categories of continuous functors I. Journal for Pure and Applied Algebra, 2:169–191, 1972.

[15] P. Gabriel and F. Ulmer. Lokal präsentierbare Kategorien. Number 221 in Lecture Notes in Mathematics. Springer Verlag, 1971.

[16] H. Ganzinger and R. Giegerich. A note on termination in combinations of heterogeneous term rewriting systems. Bulletin of the EATCS, 31, Feb. 1987.

[17] N. Ghani. Adjoint Rewriting. PhD thesis, University of Edinburgh, 1995.

[18] N. Ghani. βη-equality for coproducts. In Second Conference on Typed Lambda Calculus and its Applications, Edinburgh, Apr. 1995.

[19] N. Ghani. Eta-expansions in system F. Technical Report LIENS-96-10, LIENS-DMI, École Normale Supérieure, 1996.

[20] N. Ghani. Eta-expansions in dependent type theory— the calculus of constructions. In Typed Lambda-Calculus and Applications, number 1210 in Lecture Notes in Computer Science, pages 164– 180. Springer Verlag, 1997.

[21] J. A. Goguen. A categorical manifesto. Technical Report PRG-72, Oxford University Computing Laboratory, Programming Research Group, Oxford, England, Mar. 1989.

[22] J. A. Goguen and R. Burstall. Institutions: Abstract model theory for specification and programming. Journal of the ACM, 39:95– 146, 1992.

[23] B. Gramlich. Generalized sufficient conditions for modular termination of rewriting. In Proceedings of the Third International Conference on Algebraic and Logic Programming, number 632 in Lecture Notes in Computer Science, pages 53–68. Springer Verlag, 1992.

[24] J. W. Gray. Formal Category Theory: Adjointness for 2-Categories. Number 391 in Lecture Notes in Mathematics. Springer Verlag, 1974.

[25] J. W. Gray. Categorical aspects of data type constructors. Theoretical Computer Science, 50:103–135, 1987.

[26] J. W. Gray. The category of sketches as a model for algebraic semantics. In J. W. Gray and A. Scedrov, editors, Categories in Computer Science and Logic, number 92 in Contemporary Mathematics, pages 109–135. American Mathematical Society, 1989.

[27] J. W. Gray. The integration of logical and algebraic types. In H. Ehrig, editor, Categorical Methods in Computer Science (with Aspects from Topology), number 393 in Lecture Notes in Computer Science, pages 16–35, Berlin, 1989. Springer Verlag.

[28] J. W. Gray. Order-enriched sketches for typed lambda calculi. In Carboni, Pedicchio, and Rosolini, editors, Category Theory, number 1488 in Lecture Notes in Mathematics, pages 105–130, Como, 1990. Springer Verlag.

[29] B. Hilken. Towards a proof theory of rewriting: the simply typed 2λ-calculus. Theoretical Computer Science, 170:407– 444, 1996.

[30] C. A. R. Hoare and J. He. Data refinement in a categorical setting, Feb. 1988.

[31] C. B. Jay. Modelling reductions in confluent categories. In Proceedings of the Durham Symposium on Applications of Categories in Computer Science, 1990.

[32] C. B. Jay and N. Ghani. The virtues of η-expansion. Journal for Functional Programming, 5(2):135– 154, Apr. 1995.

[33] M. Johnson. Linear term rewriting systems are higher dimensional string rewriting systems. In C. M. I. Rattray and R. G. Clark, editors, The Unified Computation Laboratory, pages 103– 112. Oxford University Press, 1991.

[34] S. Kahrs. λ-rewriting. PhD thesis, Universität Bremen, Jan. 1991.

[35] G. M. Kelly. A unified treatment of transfinite constructions for free algebras, free monoids, colimits, associated sheaves and so on. Bulletins of the Australian Mathematical Society, 22:1– 83, 1980.

[36] G. M. Kelly. Basic Concepts of Enriched Category Theory, volume 64 of London Mathematical Society Lecture Note Series. Cambridge University Press, 1982.

[37] G. M. Kelly. Structures defined by finite limits in the enriched context I. Cahiers de Topologie et Géométrie Différentielle, XXIII(1):3–40, 1982.

[38] G. M. Kelly. Elementary observations on 2-categorical limits. Bulletins of the Australian Mathematical Society, 39:301–317, 1989.

[39] G. M. Kelly and A. J. Power. Adjunctions whose counits are coequalizers, and presentations of finitary monads. Journal for Pure and Applied Algebra, 89:163– 179, 1993.

[40] G. M. Kelly and R. Street. Review of the elements of 2-categories. In Category Seminar Sydney 1972/73, number 420 in Lecture Notes in Mathematics, pages 75–103. Springer Verlag, 1974.

[41] J. W. Klop. Term rewriting systems. In S. Abramsky, D. M. Gabbay, and T. S. E. Maibaum, editors, Handbook of Logic in Computer Science, volume 2 (Background: Computational Structures), pages 1–116. Oxford University Press, 1992.

[42] J. W. Klop, A. Middeldorp, Y. Toyama, and R. de Vrijer. A simplified proof of Toyama’s theorem. Information Processing Letters, 49:101–109, 1994.

[43] D. Knuth and P. Bendix. Simple word problems in universal algebra. In J. Leech, editor, Computational Problems in Universal Algebras, pages 263– 297. Pergamon Press, 1970.

[44] M. Kurihara and A. Ohuchi. Modularity of simple termination of term rewriting systems with shared constructors. Theoretical Computer Science, 103:273– 282, 1992.

[45] J. Lambek and P. J. Scott. Introduction to Higher Order Categorical Logic, volume 7 of Cambridge studies in advanced mathematics. Cambridge University Press, 1986.

[46] F. W. Lawvere. Metric spaces, generalized logic, and closed categories. In Rend. del Sem. Mat. e Fis. di Milano, volume 43, pages 135–166, 1973.

[47] F. W. Levi. On semigroups. Bulletin of the Calcutta Mathematical Society, 36:142–146, 1944.

[48] F. E. J. Linton. Some aspects of equational categories. In S. Eilenberg, D. K. Harrison, S. MacLane, and H. Röhrl, editors, Proceedings of the Conference on Categorical Algebra, pages 84–94, La Jolla, 1965. Springer Verlag.

[49] F. E. J. Linton. Coequalizers in categories of algebras. In B. Eckmann, editor, Seminar on Triples and Categorical Homology Theory, number 80 in Lecture Notes in Mathematics, pages 75– 90. Springer Verlag, 1969.

[50] C. Lüth. Compositional term rewriting: An algebraic proof of Toyama’s theorem. In H. Ganzinger, editor, Rewriting Techniques and Applications, 7^{th} International Conference, number 1103 in Lecture Notes in Computer Science, pages 261– 275, New Brunswick, USA, July 1996. Springer Verlag.

[51] C. Lüth and N. Ghani. Monads and modular term rewriting. In Category Theory in Computer Science CTCS’97, number 1290 in Lecture Notes in Computer Science, pages 69– 86, Santa Margherita, Italy, Sept. 1997. Springer Verlag.

[52] S. Mac Lane. Categories for the Working Mathematician, volume 5 of Graduate Texts in Mathematics. Springer Verlag, 1971.

[53] E. G. Manes. Algebraic Theories, volume 26 of Graduate Texts in Mathematics. Springer Verlag, 1976.

[54] M. Marchiori. Modularity of completeness revisited. In J. Hsiang, editor, Proceedings of the 6^{th} International Conference on Rewriting Techniques and Applications, number 914 in Lecture Notes in Computer Science, pages 2– 10, Kaiserslautern, Apr. 1995. Springer Verlag.

[55] P.-A. Melliès. A factorisation theorem in rewriting theory. In Category Theory in Computer Science CTCS’97, number 1290 in Lecture Notes in Computer Science, pages 49– 68, Santa Margherita, Italy, Sept. 1997. Springer Verlag.

[56] P.-A. Melliès. A stability theorem in rewriting theory. In 14th Annual Symposium on Logic in Computer Science, Indianapolis, USA, 1998. IEEE, Computer Society Press.

[57] J. Meseguer. Conditional rewriting logic as a unified model of concurrency. Theoretical Computer Science, 96:73–155, 1992.

[58] A. Middeldorp. A sufficient condition for the termination of the direct sum of term rewriting systems. In Fourth Annual Symposium on Logic in Computer Science, pages 396–401. IEEE, Computer Society Press, June 1989.

[59] A. Middeldorp. Modular Properties of Term Rewriting Systems. PhD thesis, Vrije Universiteit te Amsterdam, 1990.

[60] R. Milner. Action structures. Technical Report ECS-LFCS-92-249, LFCS, Dec 1992.

[61] E. Moggi. Computational lambda-calculus and monads. In Fourth Annual Symposium on Logic in Computer Science. IEEE, Computer Society Press, June 1989.

[62] E. Ohlebusch. On the modularity of termination of term rewriting systems. Theoretical Computer Science, 136:333– 360, 1994.

[63] V. v. Oostrom. Confluence for Abstract and Higher-Order Rewriting. PhD thesis, Vrije Universiteit te Amsterdam, 1994.

[64] A. J. Power. An abstract formulation for rewrite systems. In D. H. Pitt, D. E. Rydeheard, P. Dybjer, A. M. Pitts, and A. Poigné, editors, Category Theory and Computer Science, number 389 in Lecture Notes in Computer Science, pages 300–312, Manchester, Sept. 1989. Springer Verlag.

[65] A. J. Power. An algebraic formulation for data refinement. In M. Main, A. Meton, M. Mislove, and D. Schmidt, editors, Mathematical Foundations of Programming Semantics. 5^{th} International Conference, number 442 in Lecture Notes in Computer Science, pages 390–401. Springer Verlag, Mar/Apr 1989.

[66] A. J. Power. A 2-categorical pasting theorem. Journal of Algebra, 2(129), Mar 1990.

[67] D. Prawitz. Ideas and results in proof theory. In J. E. Fenstad, editor, Proceedings of the 2^{nd} Scandinavian Logic Symposium, pages 235–307. North Holland, 1971.

[68] H. Reichel. A 2-category approach to critical pair completion. In Recent Trends in Data Type Specification, number 534 in Lecture Notes in Computer Science, pages 266–273. Springer Verlag, 1991.

[69] E. Robinson. Variations on algebra: monadicity and generalisations of equational theories. Technical Report 6/94, Sussex Computer Science Technical Report, 1994.

[70] J. A. Robinson. A machine-oriented logic based on the resolution principle. Journal of the ACM, 12:23– 41, 1965.

[71] R. K. Rosen. Tree-manipulating systems and Church-Rosser theorems. Journal of the ACM, 20:160– 187, Nov 1973.

[72] M. Rusinowitch. On the termination of the direct sum of term-rewriting systems. Information Processing Letters, 26(2):65–70, 1987.

[73] D. E. Rydeheard and J. G. Stell. Foundations of equational deduction: A categorical treatment of equational proofs and unification algorithms. In Category Theory and Computer Science, number 283 in Lecture Notes in Computer Science, pages 114– 139. Springer Verlag, 1987.

[74] D. Sannella, S. Sokołowski, and A. Tarlecki. Toward formal development of programs from algebraic specifications: Parameterisation revisited. Acta Informatica, 29(8):689–736, 1992.

[75] D. T. Sannella and R. M. Burstall. Structured theories in LCF. In 8^{th} Colloqium on Trees in Algebra and Programming, number 159 in Lecture Notes in Computer Science, pages 377– 391, L’Aquila, Italy, 1983. Springer Verlag.

[76] D. T. Sannella and A. Tarlecki. On observational equivalence and algebraic specification. Journal of Computer and System Sciences, 34(2/3):150– 178, April/June 1987.

[77] D. T. Sannella and A. Tarlecki. Specifications in an arbitrary institution. Information and Computation, 76(2/3):165–210, Feb/Mar 1988.

[78] D. T. Sannella and A. Tarlecki. A kernel specification formalism with higherorder parameterisation. LFCS Report Series ECS-LFCS-91-139, LFCS, Feb.

[79] D. T. Sannella and M. Wirsing. A kernel language for algebraic specification and implementation. In International Conference on Foundations of Computation Theory, number 158 in Lecture Notes in Computer Science, pages 413– 427, Borgholm, Sweden, 1983. Springer Verlag.

[80] R. A. G. Seely. Hyperdoctrines and Natural Deduction. PhD thesis, University of Cambridge, Jun 1977.

[81] R. A. G. Seely. Modelling computations: A 2-categorical framework. In Proceedings of the Second Annual Symposium on Logic in Computer Science, pages 65–71, 1987.

[82] J. G. Stell. Categorical Aspects of Unification and Rewriting. PhD thesis, Unversity of Manchester, 1992.

[83] J. G. Stell. Modelling term rewriting systems by Sesqui-categories. Technical Report TR94-02, Keele Unversity, Jan. 1994.

[84] K. Stokkermans. A categorical formulation for critical-pair/completion procedures. In M. Rusinowitch and J. L. Rémy, editors, Third International Workshop on Conditional Term Rewriting Systems, number 656 in Lecture Notes in Computer Science, pages 171–175, Pout-à-Mousson, 1992.

[85] R. Street. The formal theory of monads. Journal for Pure and Applied Algebra, 2:149–168, 1972.

[86] R. Street. Limits indexed by category-valued 2-functors. Journal for Pure and Applied Algebra, 8:149–181, 1976.

[87] Y. Toyama. Counterexamples to termination for the direct sum of term rewriting systems. Information Processing Letters, 25(3):141–143, 1987.

[88] Y. Toyama. On the Church-Rosser property for the direct sum of term rewriting systems. Journal of the ACM, 34(1):128–143, 1987.

[89] Y. Toyama, J. W. Klop, and H. P. Barendregt. Termination for the direct sums of left-linear complete term rewriting systems. Journal of the ACM, 42(6):1275– 1304, Nov 1995.

[90] D. Turi and G. Plotkin. Towards a mathematical operational semantics. In Twelfth Annual Symposium on Logic in Computer Science. IEEE, Computer Society Press, 1997.

[91] D. Turi and J. Rutten. On the foundations of final co-algebra semantics: nonwell-founded sets, partial orders, metric spaces. Mathematical Structures in Computer Science, To appear, 1998.

[92] H. P. Yap. Some Topics in Graph Theory, volume 108 of London Mathematical Society Lecture Note Series. Cambridge University Press, 1986.

Index

2-cells, 31

abstract reduction system, 45 action of a monad, 17 adjunction, 15

F −| U : Sig → Mon_{Fin}(Set), 59 F −| U : TRS → Mon_{Fin}(Pre),

88 F −| U : TRS → Mon_{Fin}(Cat),

194 F −| U : [N , A] → Mon_{Fin}(A),

63 algebra

for a monad, 17 for a signature, 53

aliens, 96

bounded variable, 70

cartesian product, 15 of categories, 43 of graphs, 38 of relations, 41

category, 13 — of variables, 158 ∅, 15 →, 16 CPO, 20 ⇉, 16 2-category, 30 Cat, 43–45 Mon_{Fin}(C), 27 F(G), free category, 37 Grph, 36–40 Ω-Alg, 53 Pre, 42 Rel, 40–43 Set, 14 Sig, 53 TRS, 86 V-Cat, 32 cartesian closed —, 29 closed monoidal —, 29 cocomplete —, 15 complete —, 15 discrete —, 13 filtered —, 20 functor —, 14 locally finitely presentable —, 20 monoidal —, 28 of monads Mon(C), 18 ordinary —, 29 product —, 43 small —, 14 symmetric monoidal —, 28 underlying ordinary —, 35 V-category, 29 weakly filtered —, 21

coequalizer, 16 in Cat, 44 of monads, 119–121

coherent extendable, 127 colimit, 14

filtered —, 20 in Cat, 44 weakly filtered —, 21

collapsing functor, 81 monad, 81

commuting confluent, 125 commuting relations, 46 commuting subrelation, 127 complete relation, 47 composition, 13

horizontal —, 31 tadpole —, 31 vertical —, 31

cone, 14 confluence

commuting —, 125 confluent

category, 125 monad, 125 relation, 46 term rewriting system, 47

constants, 159 context, 45 coproduct, 16 coproduct of two monads, 95–107 cotensor, 34 counit of adjunction, 15

decomposition of a word, 47 diagram D_{X}, 97 diamond property, 131 dual, 13

edges, 36 epimorphism, 13

in Cat, 43 equalizer, 16 equational presentation, 61 evaluation of terms

in an algebra, 56 expanding

— functor, 81

— monad, 81

fork, 16 fp, see objects, finitely presentable functor, 13

V : V_{0} → Set, 29 2-functor, 30 F : Sig → Mon_{Fin}(Set), 58 U : Mon_{Fin}(Set) → Sig, 58 T_{Θ}, 72 F : TRS → Mon_{Fin}(Pre), 87 U : Mon_{Fin}(Pre) → TRS, 87 F : TRS → Mon_{Fin}(Cat), 193 U : Mon_{Fin}(Cat) → TRS, 193 constant —, 14 diagonal —, 14 expanding —, 81 faithful, 14 finitary, 27 full, 14 injective —, 43 ordinary —, 29 representable, 14 strongly finitary, 27 V-functor, 29

generator, 20 graph, 36

underlying —, 37 graph morphism, 36

hom-functors, 14 hom-objects, 29 hom-set, 13 homomorphic extension, 55 identity, 13 incomposable pair, 117 infinite sequence, 152 interchange law, 31 internal

equations, 61 language, 60, 61, 74, 192 signature, 57

isomorphism, 13

Kan extension, 18

layer-collapsing, 115 layer-expanding, 115 lfp, see category, locally finitely pre-

sentable lifting, 72

of a functor, 176 of a morphism in Set, 56 of a natural transformation, 176 of a TRS morphism, 87, 193

limit, 14 indexed or weighted, 33

minimal length, 116 modification, 31 monad, 17

B, 75 T_{Ω}, 56 T_{Θ}, 74 arising from adjunction, 17 expanding —, 81 finitary, 56 identity —, Id_{C}, 18 morphism, 17 presentation of finitary monads,

63 strongly finitary —, 27

monad laws, 17 monadic, 17 monomorphism, 13

in Cat, 43 morphism, 13

epi, 13 monic, 13 universal —, see universality

μ-contractive, 117 μ-expansive, 117 multiplication

of a monad, 17 of a monoidal category, 28

natural transformations

cartesian —, 80 natural transformation, 14

identity —, 14 naturality, 14 non-collapsing, 81 non-expanding, 81 normal form

for morphisms of ∐_{w∈W} T^{w}X, 115 for objects of ∐_{w∈W} T^{w}X, 114,

115

object, 13 finitely presentable —, 19 initial —, 15 terminal —, 15

occurrence, 158

path, 37 — congruence, 37 concatenation ::, 37 empty id_{X}, 37 length, 37 source s(p), 37 target t(p), 37

postcomposition, 14 precomposition, 14 preorder, 42 prereduction congruence, 182 prereductions, 174 principal subterms, 96 product, 15

quasi-non-expanding, 85

reduction many-step —, ↠_{R}, 46 named —, 66 one-step —, →_{R}, 46 reduction —, 183 unnamed —, 66

reduction system ↠_{η}, 115 →_{η}, 111 →_{Mor}, 115 →_{μ}, 111, 115 →_{Ob}, 111

reflexive closure, 41 regular

monad, 79 natural transformation, 79

relational product, 41 rewrite rule, 46

admitted by a monad, 75, 193 collapsing, 69 expanding, 69 generalized, 69, 174 ordinary, 69 variable-introducing, 69

root symbol, 96

sets with structure, 66 signature, 52, 62

morphism, 53 span, 124

under Q, 134

strongly normalizing category, 148 monad, 148 relation, 47 term rewriting system, 47 structural induction, 54, 72, 177 subcategory

co-initial, 139

commuting completable, 138 completable, 138 subcommuting relation, 46 substitution, 45

tensor, 34

tensor product, 63 of categories, 43 of graphs, 38 of relations, 41

term algebra, 54

term reduction algebra, 71

named, 183 term rewriting system, 69 orthogonal, 169

terminating, see strongly normalizing tiling lemma, 132 transformation

of functors, 44

of graph morphisms, 39 transitive closure, 41 triangle laws, 15 TRS morphism, 86

underlying non-identity relation, R^{−}(C),

148 unit

of a monad, 17

of a monoidal category, 28

of an adjunction, 15 universality, 15 universe, 12

variable rewrite, 69 variables

— by Kan extension, 64

— of a term, 54 vertices, 36

witness, 134 words

empty — ε, 47 non-empty words over an alpha-

bet L^{+}, 47 over an alphabet L^{∗}, 47 prefix ordering, 47