Towards 3-Dimensional Rewriting Theory

String rewriting systems have proved very useful to study monoids. In good cases, they give finite presentations of monoids, allowing computations on those and their manipulation by a computer. Even better, when the presentation is confluent and terminating, they provide one with a notion of canonical representative of the elements of the presented monoid. Polygraphs are a higher-dimensional generalization of this notion of presentation, from the setting of monoids to the much more general setting of n-categories. One of the main purposes of this article is to give a progressive introduction to the notion of higher-dimensional rewriting system provided by polygraphs, and describe its links with classical rewriting theory, string and term rewriting systems in particular. After introducing the general setting, we will be interested in proving local confluence for polygraphs presenting 2-categories and introduce a framework in which a finite 3-dimensional rewriting system admits a finite number of critical pairs.


Towards higher-dimensional rewriting systems
In order to generalize the notion of rewriting system to higher dimensions, one should follow the principles established by topology and category theory: a 0-dimensional rewriting system should be a set of "points" and an (n + 1)-dimensional rewriting system should consist of rules which rewrite rewriting paths in an n-dimensional rewriting system. Informally, one should think of the well-known situation arising in the study of λ-calculus: if we consider the λ-terms modulo α-conversion as 0-dimensional terms, the rules for β-reduction would play the role of a 1-dimensional rewriting system, and the rules for standardization [7], which rewrite any reduction sequence into a "standard" one, would play the role of a 2-dimensional rewriting system because they rewrite rewriting paths.
The idea is quite appealing, but it is not clear at first how the classical rewriting frameworks should fit in this picture, and one should first try to understand in a uniform way the two major examples of rewriting theory: string rewriting systems and term rewriting systems. Namely, string rewriting systems should intuitively be part of 2-dimensional rewriting systems because they rewrite words which can be considered as 1-dimensional objects: a word abc can be seen geometrically as a path However, this intuition does not give precise directions about how a 4-dimensional rewriting system should be defined for example. It turns out that generalizing a bit the settings of string and term rewriting systems reveals an inductive pattern in the definition of these rewriting frameworks, whose discovery motivated the definition of polygraphs, which can be considered as the good notion of higher-dimensional rewriting system. We shall begin by explaining this in details.
1.1.1. Definition. Rewriting systems in dimension 1 should be defined in the most simple way. The fact that a topological space of dimension 0 is a point suggests that we should define a 0-signature simply as a set E 0 , whose elements are called (0-dimensional) terms. A 1-dimensional rewriting system on the signature E 0 is a set of rules rewriting a term into another term. It therefore consists of a set E 1 , whose elements are the rules, together with two functions s, t : E 1 → E 0 which to every rule r ∈ E 1 associate its source s(r) and its target t(r). In other words, a 1-rewriting system is a diagram in the category Set (the category whose objects are sets and morphisms are functions). We sometimes write r : A → B to indicate that r is a rule with A as source and B as target and say that A one-step rewrites by r to B. We simply write A → B when there exists a rule r : A → B, write → * for the transitive closure of the relation →, and say that a term A rewrites to a term B when A → * B.
1.1.2. The free category generated by a rewriting system. Notice that a rewriting system of the form (1.1) can also be seen as a graph with E 0 as set of vertices and E 1 as set of edges, the functions s and t indicating the source and the target of an edge. Such a graph generates a free category C which is the smallest category with E 0 as set of objects and containing all the edges r : A → B in E 1 as morphisms. We write E * 1 for the set of morphisms of this category, and s * , t * : E * 1 → E 0 for the functions which to every morphism of this category associate its source and target respectively. Since the set E * 1 contains the set E 1 , there is an injection i 1 : E 1 → E * 1 . Moreover, since C is the free category generated by the graph (1.1), E * 1 is the smallest set containing E 1 and closed under identities and composition: E * 1 is the set of paths in the graph, with concatenation as composition and empty paths as identities, with the obvious source and target functions s * 1 and t * 1 . The data generated by this free construction can be summarized by a diagram in Set, together with the composition morphism E * 1 × E 0 E * 1 → E * 1 which to every pair of composable morphisms associate their composition (i.e. the concatenation of the two paths) TOWARDS 3-DIMENSIONAL REWRITING THEORY 5 and the identity morphism E 0 → E * 1 which to every object in E 0 associates an identity morphism (i.e. the empty path on this object): these two last operations define a structure of category on the graph (a category is a graph together with composition and identity operations satisfying axioms). Moreover, the diagram above "commutes" in the sense that s * • i = s and t * • i = t which expresses the fact that if r : A → B is an arrow in the graph, then it has the same source and target if we see it as a path of length 1 in the graph. Notice that, by definition, a term A rewrites to a term B when there exists a path from A to B in the graph, i.e. when there exists a morphism from A to B in the generated category: the morphisms of the freely generated category can be seen as rewriting sequences. i.e. formally It generates a category which has the words of the form (f g) * as morphisms from A to A (where the star denotes the Kleene star), (f g) * f from A to B, g(f g) * from B to A, and (gf ) * from B to B, i.e. formally E * 1 = (f g) * g(f g) * (f g) * f (gf ) * . (2) The following graph with one vertex and one arrow * 1 e e generates a category with one object isomorphic to the category whose morphisms are natural integers N with addition as composition and 0 as identity.
(3) More generally, given a set Σ, the graph G Σ with one object * and Σ as set of arrows (all from * to * ) generates a category isomorphic to the category with one object and the free monoid Σ * on Σ as set of morphisms, with concatenation as composition and empty word as identity. In other words, the category generated by G Σ is essentially the same as the free monoid Σ * generated by Σ.

1.2.1.
String rewriting systems. Suppose given an alphabet E 1 . We write E * 1 for the free monoid generated by E 1 and i 1 : E 1 → E * 1 for the injection sending a letter of the alphabet to the corresponding word with only one letter. A string rewriting system R on the alphabet E 1 is usually defined as a relation R ⊆ E * 1 × E * 1 over the free monoid generated by E 1 . One says that a word u one-step rewrites to a word v, what we write u ⇒ v, when there exists two words w 1 , w 2 ∈ E * 1 such that u = w 1 u w 2 v = w 1 v w 2 and (u , v ) ∈ R (1.2)

S. MIMRAM
If we write ⇒ * for the reflexive and transitive closure of the relation ⇒, a word u rewrites to a word v when u ⇒ * v.
In order to make the definition closer to the one given in previous section, we can make a small generalization and allow to have two distinct rules both rewriting the same word u to the same word v, by giving names to the rules. Such a string rewriting system can be formalized as a set E 2 whose elements are the (names of) the rules together with two functions s 1 , t 1 : E 2 → E * 1 indicating respectively the source and target of a rule: 1Ẽ * 1 and again we write ρ : u ⇒ v to indicate that ρ ∈ E 2 is a rule with s 1 (ρ) = u and t 1 (ρ) = v. Example 1.2. One can for example consider the rewriting system on an alphabet with two letters a, b and a rule ba ⇒ ab, which would be formalized by where ⊗ denotes the concatenation operation on words.
More details and examples of uses of such rewriting systems are given in Section 2.1.1.

2-dimensional rewriting systems.
Remember that our general plan is to express 2-dimensional rewriting systems as rewriting on 1-dimensional rewriting paths. In order to do so, one should have in mind that a set is "the same as" a graph with one vertex. Formally, there exist two functors which are inverse one of each other, where Graph * is the full subcategory of Graph (the category of graphs) whose objects are graphs with only one vertex: the functor F sends a set Σ to the graph with one vertex * and Σ as set of arrows (all going from * to * ) and the functor G sends a graph with one vertex to its set of edges. Similarly, a monoid is "the same as" a category with one object, the multiplication and unit of a monoid corresponding to the composition and identity of the category. For instance, we have explained in the last point of Example 1.1 that the free monoid generated by a set is, with respect to this point of view, "the same as" the free category generated by the graph corresponding to the set. Therefore, instead of having a mere set as alphabet, one might equivalently declare that an alphabet is a 1-dimensional rewriting system as defined in Section 1.2, with the set E 0 being reduced to one element. Again, this does not bring more information than the set E 1 itself, since the set E 0 is uniquely defined up to a canonical isomorphism (it contains only one object) and the functions s 0 , t 0 : E 1 → E 0 are uniquely defined because E 0 is terminal in Set. If we write E * 1 for the set of morphisms of in Set, with E 0 containing only one element, together with a structure of category on the graph It turns out that the supposition that the set E 0 is reduced to one element is not necessary in order to proceed with the usual developments of string rewriting theory. We thus drop this condition in the following and suppose that an alphabet for a 2-dimensional rewriting system is any 1-dimensional rewriting system. This amounts to generalizing string rewriting systems to the case where the letters a : A → B are typed (with A as source and B as target), and to consider only composable string of letters as words (the words are thus also typed). In order for substitution to be well-defined, we have to suppose that a word u : A → B can only be rewritten to a word v : A → B of the same type (i.e. A = A and B = B). It is enough to suppose that this property is satisfied for the rules, which amounts to impose the further axiom that in any 2-dimensional rewriting system (1.4), the equations • t 1 are satisfied (these are sometimes called the globular equations). An example of such a rewriting system is given in Section 1.2.5.

1.2.3.
The free 2-category generated by a rewriting system. In the same way that a 1-dimensional rewriting system freely generates a 1-category (i.e. a category), a 2-dimensional rewriting system freely generates a 2-category: it is the smallest 2-category with (1.5) as underlying category and the containing the elements of E 2 as 2-cells. We recall that the notion of 2-category is defined as follows. horizontal composition (we will drop the subscripts of ⊗ in the following). -A 1-cell id A : A → A for every object A called vertical identity. These should be such that the following properties are satisfied.
-Horizontal composition is associative: for every 0-cells A, B, C and D, for every 1-cells f, f : A → B, g, g : B → C and h, h : C → D, for every 2-cells α : f ⇒ f , β : g ⇒ g and γ : h ⇒ h , -Horizontal identities are neutral elements for horizontal composition: for every 0-cells A and B, for every 1-cells f, f : A → B, for every 2-cell α : f ⇒ f , If we write E * 2 for the set of 2-cells of the 2-category generated by the 2-rewriting system (1.4), i 2 : E 2 → E * 2 for the canonical injection expressing the inclusion of E 2 into E * 2 and s * 1 , t * 1 : in Set, together with a structure of 2-category on the 2-graph which commutes in the sense that In the same way as previously, the 2-cells of this 2-category correspond to the rewriting paths: a (typed) word u : A → B rewrites to a (typed) word w : A → B if and only if there exists a 2-cell α : u ⇒ v : A → B. In particular, if there is only one 0-cell, this notion of rewriting corresponds the usual notion of rewriting for string rewriting systems. As previously, notice that a 1-cell is rewritten into a parallel 1-cell, i.e. a 1-cell having the same source and same target.
1.2.4. A diagrammatic notation for 2-cells. Before going on describing how to incorporate string rewriting systems in our framework, we shall try to understand a bit more 2-categories, and the previous construction.
Given a 2-category C, a 2-cell α : u ⇒ v : A → B is often written diagrammatically as With this notation, vertical composition corresponds to vertical juxtaposition: the compos- (1.6) and the horizontal composition α ⊗ β : For every 1-cell u : A → B, a vertical identity 2-cell should be given which acts as neutral element for vertical composition. The functoriality of the horizontal composition implies a last fundamental identity called the exchange law. Given four 2-cells α, β, α and β as in the diagram there are two ways to compose them altogether: either first vertically and then horizontally or the converse. The exchange law which is satisfied in any 2-category states that these two composites are equal: Thanks to this, the diagram (1.8) is not ambiguous. This law can equivalently be reformulated slightly differently as the Godement law : given two 2-cells α and β as in (1.7), the following identity is always satisfied: i.e. using the previously introduced notations In particular, the 1-rewriting system playing the role of signature for this 2-rewriting system is the one given in first point of Example 1.1, and the ⊗ operation denotes the composition of the category it generates. As explained earlier, A and B should be seen as types for words, f and g should be seen as the letters of the signature and the ⊗ operation as the concatenation for words (we thus sometimes omit it and write f g instead of f ⊗ g). These letters are typed and one only considers words obtained by composing compatible letters; for example f ⊗ g ⊗ f is a word of type A → B, graphically represented as the path whereas f ⊗ f does not make sense. Finally, ρ is a rewriting rule, which we may represent as a 2-cell which transforms a word into another. The rewriting paths are the morphisms in the 2-category generated by the 2-rewriting system: its 2-cells are formal vertical and horizontal composites of rules quotiented by the axioms of 2-categories. Vertical compositions correspond to sequences of rewriting: if a word u rewrites to a word v, which is witnessed by a morphism α : u ⇒ v, and the word v rewrites to a word w, which is witnessed by a morphism β : v ⇒ w, then the composite morphism β • α : u ⇒ w witnesses the fact that u rewrites to w, which is represented diagrammatically in (1.6). Horizontal compositions correspond similarly to rewritings done in parallel: if a word u rewrites to u by α : u ⇒ u and a word v rewrites to v by β : v ⇒ v then u ⊗ v rewrites to u ⊗ v by α ⊗ β, as shown in (1.7). For example, the usual condition for one-step rewrites (1.2) can be recovered as follows: the generator ρ rewrites f gf g into f g, so, given two words u : C → A and v : A → D (where C and D are either A or B), the word uf gf gv rewrites to uf gv, which is witnessed by the morphism which can be represented as We usually omit drawing the identity 2-cells and simply write for this 2-cell. As another example of the fact that 2-cells represent rewriting paths, consider the word f gf gf g which can be rewritten to f g: Actually, there are two such rewriting paths because, in the first step, the rule ρ can be applied either on the left or on the right of the word. These two distinct paths correspond to the morphisms respectively represented diagrammatically by (1. 11) and Notice that it is also possible in this setting to express the rewriting of two disjoint parts of a word in parallel, such as String diagrams. The diagrammatic notation for cells in 2-categories introduced in Section 1.2.4 is quite useful and convenient. However, from such diagrams, it is sometimes difficult to get intuitions about the way morphisms should be manipulated and having another, more "geometrical", representation of morphisms can be very useful. Such a notation was formally introduced by Joyal and Street [17] and is called string diagrams. We shall first explain this notation on an example. Consider the 2-cell ρ in the 2-category described in previous section, whose diagrammatic representation is given in (1.10). We can consider this 2-cell as a device with four typed inputs respectively of type f , g, f and g, which produces two outputs respectively of type f and g. It is thus natural to depict it as The 2-cell ρ is represented by the point in the center, each of the 1-cells in its input (resp. output) correspond to a wire going in (resp. out of) it. The portions of the plane delimited by the wires correspond to 0-cells at the source or target of the 1-cells corresponding to the delimiting wires. Since, in this representation, 2-cells consist of points linked by strings (or wires), it is called a string diagram.
Vertical composition amounts to vertically juxtaposing diagrams and "linking the wires", whereas horizontal composition is given by horizontal juxtaposition of diagrams. The two diagrams for composition (1.6) and (1.7) are thus drawn respectively by and vertical identities are represented by wires. For example, the string-diagrammatic notation of the morphism (1.11) is These diagrams should be considered modulo planar continuous deformations. In particular, the Godement exchange law (1.9) is satisfied because the diagram on the left can be deformed into the diagram on the right, and more generally, it can be checked that all the axioms of 2-categories are satisfied.

Term rewriting systems.
In the same way string rewriting systems can be generalized to 2-dimensional rewriting systems, which rewrite rewriting paths in 1-dimensional rewriting systems, term rewriting systems can be generalized to 3-dimensional rewriting systems which rewrite rewriting paths in 2-dimensional rewriting systems. A signature (Σ, a) consists of a set Σ called alphabet, whose elements are called symbols, together with a function a : Σ → N which to every symbol f ∈ Σ associates its arity. We also suppose fixed a set V ar of variables. A term is either a variable x ∈ V ar or of the form f (t 1 , . . . , t n ) where the t i are terms and f is a symbol of arity n. Given two terms t and u and a variable x, we denote by t[u/x] the term obtained from t by substituting all the occurrences of the variable x by u. We write Σ * for the set of terms generated by the signature Σ. A substitution σ : V ar → Σ * is a function which to every variable associates a term. Given a term t, we write t[σ] for the term obtained from t by replacing every variable x by σ(x). A term rewriting system R on such a signature is a set R ⊆ Σ * × Σ * of pairs of terms. A term t one-step rewrites to a term u, what we write t u, when there exists a rule (l, r) ∈ R and a substitution σ such that u = l[σ] and v = r[σ]. We write * for the transitive closure of the relation on terms, and say that a term t rewrites to a term u whenever t * u.
We now generalize the notion of term rewriting system so that it appears as an extension of 2-dimensional rewriting systems. Having done that, we shall be able to see a term as a rewriting path in a 2-dimensional rewriting system: a 3-dimensional rewriting system will thus consist of rewriting rules which relate terms, i.e. rewriting rules which rewrite rewriting paths in a 2-dimensional rewriting system. We should follow the intuition given by string diagrams. For example, if we consider a signature Σ = {f, g}, the two symbols f and g being of arity 2, as mentioned in the introduction, the term f (x, g(y, z)), where x, y and z are variables, can be drawn as a tree x y z g f which looks very much like the string-diagrammatic notation for a morphism f • (id ⊗ g), whose diagrammatic notation would be In order to make this intuition formal, recall from Example 1.1 that the monoid N of integers can be seen as the category generated by the graph with only one vertex and one edge: if we write E 0 = { * } for the set of vertices ( * being the only vertex) and E 1 = {1} for the set of edges (1 being the only edge, with * both as source and target) and follow the notations is the set of morphisms in the category generated by the graph (i.e. the paths in the graph). For example, the integer 3 corresponds to the path 1 ⊗ 1 ⊗ 1: and more generally an integer n to the composition of n copies of 1. The arity can thus be seen as an arrow a : Σ → E * 1 . In order to be consistent with the previous notations, we write E 2 instead of Σ and s 1 instead of a, since the arity denotes the number of inputs. We also write t 1 : E 2 → E * 2 for the constant function equal to 1: it denotes the coarity of a symbol (its number of outputs), which is always 1 in the setting of term rewriting systems. The signature of a term rewriting system can thus be specified by a 2-rewriting system and t 1 is the constant function equal to 1. For example, the previously considered signature with two symbols f , g of arity 2 is represented by the 2-rewriting system such that Any such signature being a 2-rewriting system, it generates a 2-category C with E * 2 as set of 2-cells. As previously, we write i 2 : E 2 → E * 2 for the canonical injection and s * 1 , t * 1 : E * 2 → E * 1 for the maps associating to each 2-cell its source and target respectively. Since E 0 = { * }, the 2-category C has only one 0-cell * . Since E 1 = {1}, the 1-cells of the 2-category C are in bijection with N (as explained above). It is easy to show that the 2-cells α : n ⇒ 1 : * → * of C are in bijection with linear terms with variables in x 1 , . . . , x n : a term is linear when all the variables x 1 , . . . , x n appear exactly once in the term, in this order, e.g. with the signature (1.12), the term f (x 1 , g(x 2 , x 3 )) is linear whereas f (x 1 , x 1 ) and g(x 2 , x 1 ) are not. More generally, the 2-cells α : n ⇒ m : * → * are in bijection with linear m-uples of terms with n variables x 1 , . . . , x n . For example, with the signature (1.12), the term which can be represented diagrammatically as * . A term rewriting system operating on linear terms can thus be thought as rewriting rewriting paths in a 2-dimensional rewriting system and be represented as a diagram where E 2 is the alphabet and E 3 is the set of rewriting rules, such that rules rewrite a term into a term of the same type: • t 2 and the three conditions below are satisfied: (1) the set E 0 is reduced to one element * , (2) the set E 1 is reduced to one element 1, (3) the function t 2 is the constant function equal to 1. In the following, we drop those three conditions in the general definition of 3-dimensional rewriting systems. Dropping condition (3) allows us to consider terms with multiple outputs (whereas terms in term-rewriting systems always have exactly one output). In particular, we will see in Section 2.2.2 that this enables us to recover the usual setting of (non-linear) term rewriting systems: non-linearity is obtained by adding to the signature symbols to explicitly duplicate, erase and swap variables. Dropping condition (2) allows us to consider typed terms. For example, a symbol f ∈ E 2 with s 1 (f ) = A ⊗ B and t 1 (f ) = C ⊗ D, where A, B, C, D ∈ E 1 means that f has two inputs of respective types A and B and two outputs of respective types C and D; diagrammatically, Finally, dropping condition (1) allows to have typed types, as explained in Section 1.2. Notice that usually, term rewriting systems are considered to generalize string rewriting system because a letter can be seen as a symbol of arity 1. While this is true, this is not the right point of view! At the light of the previous explanations, we see that term rewriting systems do generalize string rewriting systems in the sense that they rewrite rewriting paths in string rewriting systems.

Polygraphs.
We believe that the general pattern should have become clear now, and one can generalize the situation in order to inductively define a notion of n-dimensional rewriting system. This was formalized by Burroni under the name of n-polygraph [5]. The article introducing polygraphs was in fact rediscovering the notion of n-computad invented 17 years earlier by Street in its 2-dimensional version [36] and later on generalized to higher dimensions by Power [32]. We insist here on the contribution of Burroni, who first found and formalized connections between these general constructions and rewriting theory.
The notion of n-polygraph is defined inductively (on n ∈ N) as follows. A 0-polygraph is a set E 0 . Now suppose given an n-polygraph, i.e. a diagram in Set together with a structure of (n − 1)-category on the (n − 1)-graph Such a polygraph generates a free n-category, which will be noted E * , with the previous (n − 1)-category as underlying (n − 1)-category and containing the elements of E n as n-cells, with source and target indicated by the functions s n−1 and t n−1 . We write E * n for its set of n-cells, i n : E n → E * n for the canonical injection and s * n−1 , t * n−1 : E * n → E * n−1 for the source and target maps. An (n + 1)-polygraph is then defined as a diagram of the form in Set, together with the structure of n-category on the n-graph at the bottom of the diagram, such that We refer the reader to [5] for a detailed definition and to [14] for a more abstract equivalent definition.
Given an n-polygraph (1.14), the elements of E k are called k-generators. Notice that E * 0 is the free 0-category (i.e. set) on E 0 , so E * 0 is isomorphic to E 0 , and we might as well decide that they are equal: we have implicitly done this assumption in our presentation of n-dimensional rewriting systems in order to ease the explanation. Given two n-polygraphs E and F , a morphism between them consists of a family (f k : E k → F k ) 0 k n of functions such that s k • f k+1 = f * k • s k for every index k, and we write Pol n for the category of n-polygraphs. Every m-polygraph E admits an underlying n-polygraph (with m > n), often written E| n , thus inducing a forgetful functor Pol m → Pol n .

Presentations of n-categories
A crucial application of polygraphs relies on the fact that they provide us with a notion of presentation of n-categories: an (n + 1)-polygraph E can be seen as a description of an n-category by generators (the elements of E k with 0 k n being generators for k-cells) quotiented by relations (the elements of E n+1 ). More precisely, an (n + 1)-polygraph E generates an (n + 1)-category E * . The n-category presented by the polygraph E, written E * is obtained by quotienting the underlying n-category of E * by the relation identifying two n-cells f and g whenever there exists an (n + 1)-cell α : f → g in E * . More generally, one says that an n-category C is presented by an (n + 1)-polygraph E when C is isomorphic to E * .
Presentations of categories are useful in the sense that they can provide us with small (even sometimes finite) descriptions of categories. This idea of presentation generalizes the well-known notion of presentation of a monoid (or a group). We begin by recalling this simple and well studied setting.

Presentations of categories.
2.1.1. Presentations of monoids. One of the main applications of string rewriting systems, that we are going to generalize here, is the construction of presentations of a monoid.
where Σ * denotes the free monoid over Σ, such that the monoid M is isomorphic to Σ * / ≡ R , where ≡ R is the smallest congruence (with respect to concatenation of words) on Σ * containing R.
Example 2.2. The additive monoid N admits the presentation with one generator a and no relation a | . Similarly, and, if we write S n for the monoid of symmetries on n elements, which is a priori difficult because the second monoid is described as terms modulo a congruence. One of the great usefulness of string rewriting systems is that, when they are convergent (i.e. terminating and confluent), they provide one with a notion of normal form of terms modulo the congruence generated by the rewriting rules. In order to show the isomorphism M ∼ = (Σ * / ≡ R ), one can thus try to follow the following recipe: (1) Orient the relations in R in order to get a string rewriting system on the alphabet Σ.
(2) Show that the rewriting system is terminating.
(3) Compute the critical pairs of the rewriting system and show that they are joinable. (4) The two previous points ensure that the rewriting system is convergent. Compute the normal forms and show that they are in bijection with the elements of M in a way compatible with multiplication and unit. It is well known that the joinability of critical pairs checked in (3) implies the local confluence of the rewriting system. Its confluence can then be deduced by Newman's lemma provided that it is terminating (2). The compatibility condition of (4) can be made explicit as follows. We write (M, ×, 1) for the operations of the monoid M , we write w for the normal form of a word w ∈ Σ * , and set Σ * = { w | w ∈ Σ * }. One should provide a pair of functions f : Σ * → M and g : M → Σ * , which are mutually inverse morphisms of monoids: for every u, v ∈ Σ * and m, n ∈ M , where ⊗ denotes concatenation and ε the empty word. (1) We orient the rules as follows: ba ⇒ ab and bb ⇒ 1 (2) The system is terminating: introduce a suitable measure on words based on the fact that the rules respectively decrease the number of a after a b, and the total number of b in a word. Since normal forms are canonical representatives of elements of the free monoid Σ * over the alphabet Σ modulo the congruence ≡ R , in order to define the morphism f witnessing the bijection (4), by universal property of the free monoid it is enough to define f on letters in Σ, extend it as a morphism f : Σ * → M and show that the images of two words equivalent with respect to ≡ R are equal, which can be checked by showing that the image by f of any left member of any rule is equal the corresponding right member. Of course, the explicit construction of g is not necessary and it is equivalent (and sometimes more natural) to show that f is both surjective and injective. This general methodology can be straightforwardly adapted to n-polygraphs in order to build presentations of n-categories. We detail a few interesting particular cases in the following.
Remark 2.5. Notice that the method described above is only a "recipe" for constructing presentations, which works (or can be adapted) in many cases. In fact, it has been shown by Squier [35,23], using homological methods, that there exists monoids which admit finite presentations, but no finite presentation which can be oriented into a convergent rewriting system. These theoretical considerations aside, convergent presentations are sometimes difficult to build: in these cases, the following weaker method (used for example in [22]) can be tried: (2) Introduce a notion of canonical form for words (which will play the role of previous normal forms). (3) Show that every word reduces to a canonical form. (4) Define a morphism f : Σ * → M which is compatible with rewriting rules as previously, and show that it induces a bijection between the canonical forms and the elements of M . This variant has the advantage of not requiring to show termination, but it can lead one to have to consider many cases (many more than critical pairs when the system is convergent).

2.1.2.
Presentations of categories. 2-polygraphs more generally present categories: the case of a presentation of a monoid is the particular case where the presented category has only one object. Namely, a 2-polygraph E describes a category which is the smallest category with the 0-generators in E 0 as objects, containing the typed 1-generators in E 1 as morphisms, quotiented by the relations in E 2 .
Example 2.6. Consider the simplicial category ∆: its objects are natural integers n ∈ N, where n is seen as the totally ordered set with n elements {0, 1, 2, . . . , n − 1} and morphisms f : m → n are increasing functions. This category is presented by the 2-polygraph E with E 0 = N, the set E 1 contains the two families of 1-generators indexed by integers n, i ∈ N, such that 0 i n, µ n+1 i : n + 2 → n + 1 and η n i : n → n + 1 and the set E 2 of rewriting rules contains the families of 2-generators index by n, i ∈ N In order to show this, the same recipe as previously can be used: the rewriting system can be shown to be terminating and confluent, the normal forms being terms of the form : m → n such that n = m − h + k, n > i k > . . . > i 1 ≥ 0 and 0 j h < . . . < j 1 < m. We can then construct a functor F : E * → ∆, which is defined as the identity on objects and is defined on 1-generators by The image of the left member of a rule by F can be checked to be equal to the image of the corresponding right member and it can be shown to be a bijection, see [26] (section VII.5) for details. A refined way to construct this presentation is hinted in Example 2.18.

Presentations of 2-categories.
2.2.1. Monoidal categories. Before explaining how term rewriting systems provide us with a notion of presentation of a Lawvere theory, we need to introduce the notion of monoidal category. Formally, a monoidal category could be defined as a 2-category (Definition 1.3) with exactly one 0-cell. However, in the same way that a category with only one object can be reformulated as a monoid (i.e. a set with operations), a monoidal category is generally defined as a category with operations.
Definition 2.7. A strict monoidal category (C, ⊗, I) consists of a category C together with -a functor ⊗ : C × C → C, called tensor product, -an object I of C, called unit, such that -tensor product is associative: for every objects A,B and C, (A ⊗ B) ⊗ C = A ⊗ (B ⊗ C) -units are neutral elements: for every object A, I ⊗ A = A = A ⊗ I.
The tensor product f ⊗g of two morphisms f and g should be thought as the morphism f "in parallel" with the morphism g. This definition is a particular case of a more general definition of monoidal categories [26] (which is why it is called strict), however we will only consider this variant here. A monoidal category (C, ⊗, I) as above gives rise to a 2-category, with only one 0-cell, the 1-cells being the objects of C, the 2-cells being the morphisms of C, vertical composition being given by the composition of C and horizontal composition being given by ⊗; and this induces an isomorphism between the category of monoidal categories and the categories of 2-categories with one object (this is a generalization of the situation between monoids and categories described in Section 1.2.2). In other words, a monoidal category is "the same as" a 2-category with one object and we can in particular reuse the string-diagrammatic notation for morphisms. We thus sometimes implicitly consider a monoidal category as a 2-category in the following.
Any cartesian category C can be equipped with a structure of monoidal category (C, ×, 1), tensor product being cartesian product and unit being the terminal object -for simplicity, we consider that cartesian products are strictly associative, which is always true up to equivalence of categories, but this assumption could have been dropped if we had worked with the more general notion of (non-strict) monoidal category. The usual notion of monoid can be generalized from the monoidal category (Set, ×, 1) to any monoidal category as follows. As mentioned before, the tensor product intuitively expresses the possibility of having two morphisms done in parallel. One sometimes also needs to be able to "swap" two morphisms, which is formalized by the notion of symmetric monoidal category. Definition 2.10. A symmetric monoidal category (C, ⊗, I, γ) consists of a monoidal category (C, ⊗, I) together with a family γ of isomorphisms γ A,B : A ⊗ B → B ⊗ A, indexed by pairs of objects A, B of C and called symmetry, which is natural in the sense that for every morphisms f : A → A and g : B → B , and such that for every objects A, B and C the diagrams This result was considered for a long time as folklore in category theory. A detailed proof of this fact is not really difficult and can for example be found in [27]. The intuition behind this result is however very enlightening: a cartesian category is a monoidal category in which any object A can be duplicated (by δ A : A → A ⊗ A), erased (by ε A : A → I) or swapped with another object B (by γ A,B : A ⊗ B → B ⊗ A)! These operations can also be thought as the analogous of contraction, weakening and exchange rules respectively in sequent calculus. We use this result below in order to show that in fact presentations of Lawvere theories are a particular case of presentations of 2-categories.

Presentations of Lawvere theories.
We have seen that string rewriting systems correspond to presentations of monoids. Similarly, we may wonder: what are term rewriting systems presentations of? It turns out that the right answer for this are particular categories, called Lawvere theories, which were introduced by Lawvere in his thesis [24]. Definition 2.13. A Lawvere theory is a cartesian category whose objects are integers N such that 0 is a terminal object and product is given on objects by addition. The link with term rewriting systems can be explained as follows. Suppose given a signature (Σ, a). This signature induces a Lawvere theory L Σ whose morphisms t : m → n 24 S. MIMRAM are n-uples (t 1 , . . . , t n ) of terms using variables in X m = {x 1 , . . . , x m }. The composition u • t : m → p of two morphisms t : m → n and u : n → p is the morphism v defined by substitution as (u 1 [t 1 /x 1 , . . . , t n /x n ] , . . . , u p [t 1 /x 1 , . . . , t n /x n ]) and the identity on an object n is (x 1 , . . . , x n ). This category is cartesian, in particular the structure of commutative comonoid (1, δ : 1 → 2, ε : 1 → 0) on the object 1 given by Proposition 2.12 is defined by δ = (x 1 , x 1 ), ε = () and the symmetry on 1 is γ 1,1 = (x 2 , x 1 ).
Suppose given a term rewriting system R on Σ. We write ≡ R for the smallest congruence on terms containing the rules in R. A term rewriting system R presents a Lawvere theory C when C is isomorphic to L Σ / ≡ R (the Lawvere theory generated by the signature Σ whose morphisms are quotiented by the equivalence relation ≡ R ). Notice that, in order to show the isomorphism, one can try to apply the method given in Section 2.1.1. This rewriting system presents the Lawvere theory Mat of N-valued matrices described in Example 2.14. In order to show this, one could try to show that the rewriting system is convergent, but this fails immediately: the rewriting system is not terminating because of the last rule for commutativity. It is however possible to overcome this difficulty by working on terms modulo commutativity, but we do not detail this here since a more satisfactory way of proving the result is mentioned in Example 2.17. In order to provide an intuition about the result we shall however describe the functor F : (L Σ / ≡ R ) → Mat witnessing the isomorphism between the two categories, which can be shown to preserve cartesian products. is equivalent to the morphism above and has the same image under F . Finally, the functor F can be shown to be an isomorphism.
The result above is quite interesting because it provides one with a concrete description of the category generated by the rewriting system which describes the notion of commutative monoid in a cartesian category: from the result in the example above, it is easy to deduce the somewhat surprising fact that the category Mat "impersonates" the notion of monoid in the sense that a monoid in a cartesian category C is "the same as" a functor Mat → C which preserves cartesian products (more formally, the category of product-preserving functors from Mat to C and cartesian natural transformations between them is equivalent to the category of monoids in C and morphisms of monoids).
We have explained in Section 1.3.1 that a 3-polygraph (1.13) with E 0 = { * } and E 1 = {1} reduced to exactly one element and t 1 indicating that all the 2-generators have exactly one output reformulate linear term rewriting systems. At the light of Proposition 2.12, if we allow 2-generators with multiple outputs, (non-linear) term rewriting systems can be represented by adding 2-generators which will allow explicit duplication, erasure and swapping of variables. This was first formalized in [5]: Proposition 2.16. Suppose given a term rewriting system R on a signature (Σ, a). The Lawvere theory L Σ / ≡ R generated by the rewriting system (seen as a monoidal category and thus as a 2-category) is isomorphic to the 2-category E * presented by the 3-polygraph E with with the expected source and target maps, where the rules in C express the fact that (1, δ, ε) has a natural structure of commutative comonoid with γ generating the symmetry.
We shall make the source and target maps and the rules in C a bit more explicit. If we write n, as previously, for the tensor of n copies of the object 1, the map s 1 : for any symbol f ∈ Σ of arity a(f ), and similarly t 1 is defined by and the morphisms corresponding to generators should be natural with respect to every other morphism corresponding to a generator, e.g. for every element f : 1 ⇒ 1 of E 2 , C should also contain the rules (similar rules should also be introduced for 2-generators f whose arity or coarity is different from 1, see [5]). Finally, the rules in R have source and target the terms corresponding to their left and right member "translated" to explicit manipulations of variables (by using the morphisms δ, ε and γ) followed by a linear term. For example, if Σ contains two symbols f and g of arity 2, a rule f (g(x 2 , x 1 ), x 2 ) g(x 1 , x 1 ) will be translated as which is maybe best understood with the corresponding string diagrammatic notation δ γ g f ε δ g (which is again very close to the usual notation of sharing graphs). This way of representing variables in terms has been the starting point for numerous series of works trying to formalize and axiomatize variable binding, e.g. [6].
Example 2.17. The 3-polygraph corresponding to the term rewriting system of monoids introduced in Example 2.15 is the theory of bicommutative bialgebras, and this polygraph can be shown directly to present the 2-category Mat using rewriting techniques [22,28,29]. A particularly interesting point is that since swapping of variables is now explicit, the rule expressing commutativity of the monoid is now expressed as γ µ µ where γ and µ are the 2-generators corresponding to symmetry and multiplication respectively: the rule is not anymore a priori an obstacle to termination (contrarily to the approach of Example 2.15) because it makes the number of γ generators decrease in the morphisms. However, no convergent rewriting system for bicommutative bialgebras is currently known.

Presentations of 2-categories. 3-polygraphs provide us with a general notion of presentation by 0-, 1-and 2-generators and relations (the 3-generators) of a 2-category.
Many examples of such presentations have been studied by Lafont [22]. We briefly recall here some fundamental examples that he discovered. The notion of critical pair of the corresponding rewriting systems will be formally introduced in Section 3.2.
Example 2.18. In Example 2.6, we have recalled the presentation of the simplicial category ∆. An unsatisfactory point about this presentation is that it is infinite (it has an infinite number of generators and of relations). Interestingly, one can provide a finite presentation of this category by considering it as a 2-category (more precisely as a monoidal category). Namely, a tensor product ⊗ on the category can be defined on objects m and n by m ⊗ n = m + n and on morphisms f : m → m and g : n → n as the morphism This induces a structure of monoidal category on ∆, with 0 as unit. This monoidal category admits a presentation by the 3-polygraph E corresponding to the theory of monoids (see Definition 2.8), with E 0 = { * }, E 1 = {1}, E 2 = {µ : 2 → 1, η : 0 → 1} and the 3-generators being with the following string diagrammatic representation One can define a functor F : E * → ∆ as follows. The functor is the identity on objects. The image of µ : 2 → 1 is the constant function m : 2 → 1 (which to 0 and 1 associates 1) and the image of η : 0 → 1 is the constant function e : 0 → 1. Finally, the functor F can be shown to be an isomorphism (it is easy to show that there is a one-to-one correspondence between normal forms in E and functions in ∆). The fact that F is full means that every function can be expressed as a composite and tensor of m and e. For example, the function f : 4 → 3 whose graph is pictured on the left (such that f Of course there are many ways to express a given function f using m and e. The fact that the functor is faithful expresses the fact that if two morphisms obtained by composing and tensoring µ and η have the same image by F , then they are equivalent modulo the rewriting rules. Notice that the result of Example 2.6 can be recovered by defining µ n+1 i = id i ⊗µ⊗id n−i and η n i = id i ⊗ η ⊗ id n−i . Example 2.19. The monoidal category Bij is defined similarly as the simplicial category ∆ excepting that its morphisms are bijective functions. This monoidal category admits a presentation by the 3-polygraph E corresponding to the theory of symmetries, with E 0 = { * }, E 1 = {1}, E 2 = {γ : 2 → 2} and the 3-generators being The monoid of endomorphisms of an object n in the category Bij is the symmetric group S n (seen as a monoid). In this sense, the polygraph above provides a finite presentation of all the symmetric groups at once.
Interestingly, the preceding rewriting system can be shown to be convergent even though it has an infinite number of critical pairs. Namely, it has the three following obvious critical

(2.2)
can be rewritten in two different ways, giving rise to an infinite number of critical pairs. Yet, the rewriting system can be shown to be convergent [22]. This contrasts with string or term rewriting systems, which always admit a finite number of critical pairs when they are finite. The difference here seems to come essentially from the fact that the generator γ has multiple outputs as well as multiple inputs.
More recently, these tools have also been applied to more unexpected fields of computer science. For example, the author has proposed a 3-polygraph presenting a monoidal category of game semantics for first order propositional logic [29].

Representing 2-dimensional critical pairs
One of the main achievement of rewriting theory is to provide us with algorithms to compute the critical pairs [1], which are at the basis of many advanced tools, to automatically check the confluence of rewriting systems or do Knuth-Bendix completions for example. The fact that the number of critical pairs might be infinite for a finite rewriting system seems to indicate that there is little hope to extend these nice techniques to higher dimensions. We introduce here new theoretical tools in order to overcome this difficulty.
In 3-dimensional rewriting systems, it turns out that we can nevertheless recover a finite description of the critical pairs if we allow ourselves to consider a more general notion of critical pair. For example, in the case of the presentation of the category Bij given in Example 2.19, the rewriting system admits a finite number of "critical pairs" if we consider the diagram on the left of (3.1) as a morphism: Of course, this "diagram" does not formally make sense: it is not a proper string diagram in the usual sense [17], because of the "punched hole" in the right border. However, one can make this intuitive approach precise by embedding the 2-category of terms into the free 2-category with adjoints it generates, which string diagrammatically corresponds to adding the possibility of "bending wires". The diagram on the left of (3.1) will thus be actually formalized by a diagram such as the one on the right.
This section certainly constitutes the most novel part of the present paper. However, the purpose of this article was to introduce the reader to the concept of higher-dimensional rewriting theory, and to motivate the further developments which are described below. We detail the construction of the multicategory of compact contexts generated by a 2-polygraph E and show that the 2-category E * it generates can be embedded into it. We also describe how this setting can be used in order to formulate a unification algorithm for 3-polygraphs. A preliminary version of a formal exposition of these later works can be found in [31].
3.1. The multicategory of contexts. In order to formalize the notion of critical pair for a 3-polygraph, we need to first formalize the notion of context in the category E * generated by a 2-polygraph E. This methodology can easily be generalized to n-polygraphs, but we only describe it here in the case of dimension 3 for clarity. Intuitively, a context is a morphism with multiple typed "holes" or "metavariables". Since such a context can have multiple inputs (i.e. multiple holes) and one output (the morphism resulting from filling the holes with morphisms), the contexts are naturally structured as a multicategory [25].  (f 1 , . . . , f n ), -an operation id A : A → A, called identity, for every object A, such that -composition is associative: . . , f kn n ) for every choice of operations f , f i and f j i for which the compositions make sense, -identities are neutral elements for composition: for every f : A 1 , . . . , A n → A, we have f • (id A , . . . , id A ) = f . A symmetric multicategory is a multicategory M together with a bijection between the classes M(A 1 , . . . , A n ; A) and M(A σ(1) , . . . , A σ(n) ; A) of operations, for every permutation σ : n → n, these bijections having to satisfy some coherence axioms that will be omitted here.
Suppose given a 2-polygraph E. Given a pair of 0-cells A, B ∈ E * 0 and a pair of parallel 1-cells f, g : for the polygraph obtained from E by adding a new 2-generator X : f ⇒ g, i.e. (E[f ⇒ g]) 2 = E 2 {X}, such that s 1 (X) = f and t 1 (X) = g. The 2-cells in E[f ⇒ g] * being obtained by tensoring and composing 2-generators in E 2 {X}, they can be seen as terms in E * with a metavariable X of type f ⇒ g. In particular, any morphism of E * can be seen as a morphism of E[f ⇒ g] * which does not use the metavariable and we write I f ⇒g : E * → E[f ⇒ g] * for the corresponding inclusion functor.
By the universal property of the free 2-category E[f ⇒ g] * over the polygraph E[f ⇒ g], for any 2-category D, functor F : E * → D and 2-cell α : where X is the newly added metavariable. A nice understanding of this can be given by adopting a more abstract definition of polygraphs [14,31], that we did not give here for the sake of simplicity. As a particular case, substitution can be defined using this property: given a 2-cell α : f ⇒ g in E * 2 , when D = E * and F : E * → E * is the identity functor Id, the image of the image , and corresponds to the morphism obtained from β by replacing every instance of the metavariable X by α.
We more generally write E[f 1 ⇒ g 1 , .
. . , f n ⇒ g n ] for (((E[f 1 ⇒ g 1 ]) . . .)[f n ⇒ g n ]), extend notation for substitution accordingly, and often write X i for the newly introduced variable of type f i ⇒ g i . If we fix an enumeration E 2 = {α 1 , . . . , α n } of the 2-generators of E, and write f i (resp. g i ) for the source (resp. target) of α i , then the polygraph E is isomorphic to E [f 1 ⇒ g 1 , . . . , f n ⇒ g n ], where E is the 2-polygraph obtained from E by removing all the 2-generators, i.e. E 2 = ∅. Now, given a fixed index k, we write φ : E 2 → N for the function such that ϕ(α i ) = 0 if i = k, and ϕ(α k ) = 1. If we write N for the 2-category with one 0-cell, one 1-cell, and N as set of 2-cells with addition as vertical composition and 0 as vertical identity, and F : E * → N for the only functor between the 2-categories E * 32 S. MIMRAM and N , the deduced functor F [ϕ] : E * → N sends a 2-cell β to an integer, which is called the weight of the 2-generator α k in β and written β α k . The weight β α indicates the number of times a 2-generator α of E occurs in a 2-cell β of E * . Similarly, the size β of a 2-cell β is the number of 2-generators that it contains, i.e. β = α∈E 2 β α .
Definition 3.2. The multicategory of contexts of a 2-polygraph E, denoted by K E , is the symmetric multicategory whose -objects are pairs of parallel 1-cells f and g of E * , which are often written f ⇒ g, -operations α : . . , f n ⇒ g n ] * such that for every index i, α X i = 1, i.e. every metavariable occurs exactly once in the morphism, composition is induced by substitution as expected, the identity id f ⇒g : f ⇒ g → f ⇒ g on f ⇒ g is the variable X : f ⇒ g, and symmetry corresponds to renaming of variables.
In particular, if we restrict to unary operations (operations whose type is of the form f 1 ⇒ g 1 → f ⇒ g) the structure of multicategory reduces to a structure of category of contexts, which acts on the set of 2-cells of the 2-category E * : if K : f 1 ⇒ g 1 → f ⇒ g is a unary context, and α : f 1 ⇒ g 1 is a 2-cell of C, we often write K(α) : f ⇒ g for the 2-cell K[α] of C obtained from K by substituting the variable by α. More generally, a context in a 3-polygraph is a context in the underlying 2-polygraph, and if K : f 1 ⇒ g 1 → f ⇒ g is a context in a 3-polygraph and r : α β : f 1 ⇒ g 1 is a 3-cell in the 3-category E * , we write K(r) : K(α) ⇒ K(β) : f ⇒ g for the obvious 3-cell obtained from r by composing (in dimensions 0 and 1) with identity 2-cells. Notice also that the nullary operations are precisely the 2-cells of E * .
It is possible to more generally define a notion of multicategory of contexts K C of any 2-category C, which coincides with the previously given definition in the case where C is of the form C = E * for some 2-polygraph E. We will only need to consider this last case in the following, which is why we do not give the general definition.

. A terminating polygraph is confluent if and only if it is locally confluent.
In some simple cases, termination of polygraphs can be deduced from the fact that all the rules make the size of morphisms decrease: Lemma 3.5. If E is a 3-polygraph such that for every 3-generator r : α β we have α > β , then E is terminating.
This simple criterion for showing the termination of a polygraph is often too weak. More elaborate termination orders for 3-polygraphs have been studied by Guiraud [11]. In this paper, we are mostly interested in studying local confluence of polygraphs and will not detail those. The usual notion of critical pair can be extended to the setting of 3-polygraphs as follows.
Definition 3.6. A unifier of a pair of 2-cells α 1 : f 1 ⇒ g 1 and α 2 : f 2 ⇒ g 2 in a 2-category C consists of a pair of cofinal unary contexts . A unifier is most general when it is non-trivial : there is no binary context 2 ) and K 2 = K • (α 1 , id f 2 ⇒g 2 ) minimal : for every unifier (K 1 , K 2 ) of α 1 and α 2 such that K 1 = K 1 •K 1 and K 2 = K 2 •K 2 for some contexts K 1 and K 2 , the unary contexts K 1 and K 2 are invertible.
since the morphism α would not be a normal form (the rule l f k−1 could be applied), and the 2-cell α thus contains a 2-generator η f k+1 . By using a similar argument, α also contains the 2-generator ε f k+2 . So, by induction, the 2-cell α would contain all the 2-generators ε f k+2i with i ∈ N and would therefore be a composite of an infinite number of generators. This is absurd since the 2-cells in F * are inductively generated. We deduce that α does not contain a 2-generator of the form ε f k with k > 0. Similarly, it does not contain a 2-generator η f k with k > 0. The cases where k 0 are also similar (we construct an infinite sequence of generators that α would contain, with strictly decreasing winding numbers).
From this, we can deduce that the 2-cells of C, which shows that the embedding of E * into F * is full and faithful (this embedding is the functor defined as the identity on objects, as f → f 0 on 1-cells and as α → α 0 on 2-cells). A 2-cell α whose source and target is of the form above is called regular (the regular 2-cells are thus those which are in the image of the embedding). The argument can easily be generalized to any category C, not necessarily generated by a 2-polygraph (but we will only make use of the case proved in previous lemma): Proposition 3.13. The components η C : C → A C of the unit of the adjunction between 2-categories and compact 2-categories are full and faithful.
This means that given two 0-cells A and B of C, the hom-categories C(A, B) and A C (A, B) are isomorphic in a coherent way. The 2-category A C thus provides a "larger world" in which we can embed the 2-category C without losing information.
An interesting observation about compact 2-categories is that, in those, the distinction between the source and the target of a 1-cell is quite "artificial". This is formalized by the following proposition.
Proposition 3.14. If C is a compact 2-category, the sets are naturally isomorphic by the function Similarly, the sets This operation amounts to merging the outputs of type g 1 and g 0 of α, thus creating a "hole" which is formally taken in account as a metavariable in the multicategory of compact contexts.
3.6. Towards a unification algorithm for 3-polygraphs. Using the partial composition and merging operations defined above, it is possible to formulate an algorithm for computing critical pairs in a 3-polygraph, which will proceed as follows. Suppose given a 3-polygraph E. This polygraph generates a 3-category E * whose underlying 2-category is written C (the 2-category C is freely generated by the underlying 2-polygraph E| 2 of E). The 2-category C can be fully and faithfully embedded into the free compact 2-category A C it generates (Proposition 3.13). In turn, this compact 2-category generates a multicategory of contexts K A C in which it can be embedded (any 2-cell of A C can be seen as a nullary context in K A C ). Given two rewriting rules r : α β : f ⇒ g and r : α β : f ⇒ g the two 2-cells α : f ⇒ g and α : f ⇒ g in C can be seen as 2-cells α 0 : f 0 ⇒ g 0 and α 0 : f 0 ⇒ g 0 in A C , which in turn can be seen as nullary contexts in K A C (; f 0 ⇒ g 0 ) and K A C (; f 0 ⇒ g 0 ) respectively. Our algorithm will compute a unifier of those in the category of compact contexts, consisting of a pair . . , f n ⇒ g n → f ⇒ g and . . , f n ⇒ g n → f ⇒ g of compact contexts such that which is minimal and non-trivial (in a sense similar to Definition 3.6), up to the symmetry of the multicategory and rotations. Notice that the usual critical pairs in 3-polygraphs having 2-generators of arity 1 (e.g. the polygraph of monoids given in Example 2.18) are recovered as the particular case where the unifiers are such that n = 0 (there is no hole in the unifier) and the morphism ( where the α i are morphisms in A C seen as nullary compact contexts and K is a unary regular compact context. In this sense, the critical pairs in the category of compact contexts generate all the unifiers in the usual sense, and have the advantage of always being finite in number for a finite polygraph. A concrete description of the algorithm is out of the scope of this paper since it requires the elaboration of an explicit representation of the morphisms in the 2-category E * generated by a 2-polygraph E [30,31]: up to now we have defined these morphisms using an abstract universal construction (see Section 1.2.3) however a more concrete representation is needed in order manipulate them algorithmically. Such a representation was developed by the author, by describing the 2-cells in E * themselves as polygraphs labeled by E (i.e. objects in the slice category Pol 2 ↓ E) up to isomorphism. For example, if E is the 2-polygraph corresponding to the signature of monoids defined in Example 2.18, the morphism µ • (µ ⊗ id 1 ) can be represented by the polygraph M such that M → E such that all the 0-, 1-and 2-generators are labeled by * , 1 and µ respectively. Graphically, this corresponds to give different names (or numbers in this case) to the various instances of generators used to build the morphism: Of course, the naming of generators is not canonical which explains why we have to consider these labeled polygraphs up to isomorphism (this can be seen as some form of α-conversion).
The precise description of this 2-category can be achieved by constructing a structure of monoidal globular category [4] on the globular category of polygraphs. This will be presented in detail in further work.
We shall only illustrate how our algorithm works, by giving an example. Consider a 3-polygraph E with one 0-generator * , one 1-generator 1 : * → * , three 2-cells δ : 1 → 4, µ : 4 → 1 and σ : 1 → 1 (where 4 denotes 1 ⊗ 1 ⊗ 1 ⊗ 1) and two rewriting rules (3-generators) whose left members are respectively α = ς • δ and β = µ • ς, where ς = σ ⊗ σ ⊗ σ ⊗ σ, i.e. string diagrammatically The algorithm for unifying these two morphisms will go on as follows. It is non-deterministic and all the unifiers of the two morphisms (possibly with duplicates) will be obtained as the collection of all the results of non-failed execution branches the algorithm. It starts by choosing a 2-generator in each of the morphisms (the gray-colored ones in the diagram above), and then it will progressively attach new cells to the left one, or link wires together so that it becomes a most general unifier. If the two chosen 2-generators are not the same then the algorithm fails (here it does not because both are σ). Since the σ generator selected on the morphism on the left is linked with a µ generator, the algorithm will start by adding a µ generator to the morphism on the left and doing a partial composition with it, as shown on the left of (3.4). The unification is then propagated: the µ generator in the morphism on the right is connected with four σ generators. The algorithm will non-deterministically choose one which has not already been unified and will propagate the unification. For example, if the third σ from the left is selected, the morphism in the middle of (3.4) might be obtained by adding a new σ generator to the morphism. Non-deterministically, instead of adding a new generator, the algorithm might choose to merge (using the operation described at the end of Section 3.5) two inputs or outputs of the morphisms and the morphism on the right of (3.4) might be obtained as well (in this case a new hole is added to the unifier being constructed). Finally, by fully executing the algorithm, the three morphisms below will be obtained as unifiers (as well as many others). It can be shown that the algorithm terminates and generates all the critical pairs in compact contexts, and these are in finite number. It is important to notice that the algorithm generates the critical pairs of a rewriting system R in the "bigger world" of compact contexts, from which we can generate the critical pairs in the 2-category generated by R (which are not necessarily in finite number as explained in the introduction). If joinability of the critical pairs in compact contexts implies that the rewriting system is confluent, the converse is unfortunately not true: a similar situation is well known in the study of λ-calculus with explicit substitutions, where a rewriting system might be confluent without being confluent on terms with metavariables.
We have done a toy implementation of the algorithm in less than 2000 lines of OCaml, with which we have been able to successfully recover the critical pairs of rewriting systems in [22]. Even though we did not particularly focus on efficiency, the execution times are good, typically less than a second, because the morphisms involved in polygraphic rewriting systems are usually small (but they can generate a large number of critical pairs). We thus have hope to be able to build efficient tools in order to help dealing with large algebraic structures.

Future work
We have tried gradually to expose the notion of higher-dimensional rewriting system and to connect it with the well known and well studied special cases of string and term rewriting system. We have also introduced the notion of multicategory of compact contexts generated by a 2-polygraph, which lays the theoretical foundations for unification in polygraphic 2-dimensional rewriting systems. This leaves many research tracks open for future work, some of which are detailed below. 4.1. A 2-dimensional unification algorithm. We have hinted in Section 3.6 how the theoretical tools introduced in this article can be used to formulate a unification algorithm for 3-polygraphs. This algorithm will be described and proven correct in detail in subsequent work [31]. In particular, we plan to study the precise links between our algorithm and the usual unification for term rewriting systems, as well as algorithms for (planar) graph rewriting.

4.2.
Compact rewriting systems. The use of compact 2-categories seems to be very promising, since it provides a bigger world in which unification is simple to handle (there are a finite number of critical pairs in particular). Moreover, left and right members of rules in polygraphic rewriting systems are morphisms in 2-categories, but we can extend the framework to have "compact rewriting rules" whose left and right members are morphisms in compact 2-categories. There is no known finite convergent polygraphic rewriting system presenting the category Rel of finite sets and relations [22] (which corresponds to the theory of qualitative bicommutative bialgebras [29]). We conjecture that such a system does not exist. However, we believe that it would be possible to have a finite convergent compact polygraphic rewriting system containing rules such as γ δ µ γ δ γ γ µ where γ is the generator for the symmetry, δ is the comultiplication and µ is the multiplication. We plan to use our unification algorithm in order to define and study such a rewriting system. It would also be interesting to adapt the techniques developed by Guiraud to show termination of polygraphic systems [11]. 4.3. Parametric polygraphs. In order to describe those free compact 2-categories, we had to modify the definition of the notion of polygraph by replacing the free category construction by a free category with formal adjoints construction, and the free 2-category construction by a free compact 2-category construction. This suggests that it might be interesting to investigate a more modular notion of polygraph, parametrized by a series of adjunctions, which could be used to generate free n-categories with properties (e.g. compact categories, groupoids, etc.).

4.4.
Towards higher dimensions. Since the notion of polygraphic rewriting system can be generalized to any dimension, we would like to also have a generalization of rewriting theory to higher dimensions using polygraphic rewriting systems. This would require a more abstract and general formulation of the unification techniques that are used here, in order to be able to extend them easily to higher dimensions. 4.5. Practical uses of this work. In some sense, our work can be considered as an algebraic study of the notion of a bunch of operators linked by planar wires. We believe that this point of view should be taken seriously and we plan to investigate a possible application of the polygraphic rewriting techniques to electronic circuits. This could provide a nice theoretical framework in which we could express and study optimization of integrated circuits. Another field of application should be the design of an optimizing language for digital signal processing. Sound effects are often described by diagrammatic notation which is very close to the string-diagrammatic notation for morphisms in 2-categories generated by where + adds to signals, ×a amplifies the signal by a coefficient a < 1 and d delays the signal for d seconds: the echo is obtained by adding the signal d seconds before, at a lower volume, to the current signal. The rewriting techniques offered by polygraphs could therefore be used in order to optimize those circuits using 3-dimensional rewriting systems.