Relating Two Categorical ?Models of Term Rewriting A. Corradini, F. Gadducci and U. Montanari Universita di Pisa, Dipartimento di Informatica, Corso Italia 40, 56125 Pisa, Italy (fandrea,gadducci,
[email protected], Tel: +39-50-887268, Fax: +39-50-887266)
Abstract. In the last years there has been a growing interest towards categorical models for term rewriting systems (trs's). In our opinion, very interesting are those associating to each trs's a cat-enriched structure: a category whose hom-sets are categories. Interpreting rewriting steps as morphisms in hom-categories, these models provide rewriting systems with a concurrent semantics in a clean algebraic way. In this paper we provide a uni ed presentation of two models recently proposed in literature by Jose Meseguer [Mes90, Mes92, MOM93] and John Stell [Ste92, Ste94], respectively, pursuing a critical analysis of both of them. More precisely, we show why they are to a certain extent unsatisfactory in providing a concurrent semantics for rewriting systems. It turns out that the derivation space of Meseguer's Rewriting Logic associated with each term (i.e., the set of coinitial computations) fails in general to form a prime algebraic domain: a condition that is generally considered as expressing a directly implementable model of concurrency for distributed systems (see [Win89]). On the contrary, the resulting derivation space in Stell's model is actually a prime algebraic domain, but too few computations are identi ed: only disjoint concurrency can be expressed, limiting the degree of parallelism described by the model.
Keywords: term rewriting, categorical models, concurrency, rewriting logic.
1 Introduction Term rewriting systems (brie y, trs's; see [DJ90]) are a simple yet powerful framework, based on the notion of (sequence of) rewrites: a binary, transitive
relation over terms, usually generated from a nite set of rules (i.e., of pair of terms, subject to some further restriction), where each element t; s states the transformation from term t to term s. Despite their simplicity, trs's propose themselves as a basic paradigm for computational devices: terms are states of an abstract machine, while rewriting rules are state-transforming functions: in this framework, computations simply are sequences of rewrites. A very intuitive operational model for trs's is represented by their derivation spaces: a class of (structured) elements representing all the possible computations h
i
? Research partially supported by ESPRIT BRA project 6564 CONFER.
the system can perform. These structures are easily de ned, but, unfortunately, the resulting operational semantics is usually too concrete: in order to obtain a description as much as possible independent from the actual implementation of the rewriting machine, we need to abstract away from irrelevant details. More precisely, if we see a term as a completely distributed structure, such that an actual rewriting machine can act simultaneously (in parallel) on dierent subterms, then a concurrent semantics is interested in exploiting to a maximum degree the parallelism implicit in the de nition of trs's. Usually, such a semantics can be recovered imposing an equivalence relation on computations, equating sequences of rewrites that are the same up to some conditions. Those conditions express the properties of the rewriting mechanism over the distributed system under examination: each equivalence class represents an abstract computation, corresponding to a family of computationally equivalent sequences of rewrites. In the classical approach the derivation space is just a set, and the equivalence on computations relies on the notion of residual: given two computations d and d , then the residual d d of d after d is intuitively \what-remains-to-be-done" of d after the execution of d. Abstract computations are the elements of the set of \concrete" derivations, quotiented by the smallest equivalence induced by the axiom schema d d d = d d d , where indicates concatenation of rewrites. This equivalence is known as permutation equivalence [Lev80, Bou85], and it equates computations that are the same up to permutation of independent rewrites. Recently, 2-categories and sesqui-categories have been proposed respectively by Jose Meseguer [Mes90, Mes92, MOM93] and John Stell [Ste92, Ste94] as a more abstract, algebraic way to equip trs's with a concurrent semantics. A catenriched structure as a 2-category or a sesqui-category is given by a category such that also each hom-set forms a category: the class of morphisms (called cells) of these hom-categories are closed under certain composition operators, and are subject to suitable coherence axioms. In the paper we show a uni ed, two-phase method to generate such algebraic structures starting from a trs's. First, to each trs a c-computad is associated: a pair D ; S , where D is a category whose arrows represent terms, while S is a collection of cells describing the rewriting rules of ; then from the c-computad an enriched structure is freely generated, obtaining a derivation space (the cells of the enriched structure) that is already subject to an equivalence relation, due to the coherence axioms: since there exists a correspondence between cells and computations, this way a trs is equipped with a concurrent semantics. The resulting construction is strictly related, in the case of 2-categories, to the functorial semantics considered by Meseguer in the Appendix of [Mes90], while for sesqui-categories it can be considered as an original, algebraic presentation of Stell's proposal [Ste92]. In the second part of the paper we will consider some algebraic properties of the equivalences on derivations induced by the two models, analyzing in particular the \natural" partial order on computations. In a classical, set-theoretic context, a similar task has been tackled for -calculus by Laneve in [Lan94], where a new semantics is introduced (induced by the distributive permutation equivalence, where only permutation of distributed rewrites is allowed), showing 0
0
0
n
0
0
0
n
n
0
R
h
R
R
2
R
Ri
R
that the corresponding derivation space forms a prime algebraic domain. Prime algebraic domains (pad's) are a simple, general and well-accepted model to describe the behaviour of concurrent, non-deterministic systems. Their acceptance in the concurrency eld is due, besides to their historical relevance (dating back to the work of Kahn and Plotkin on concrete domains, and of Berry on dI domains) to their tight correspondence with Prime Events Structures [Win89]. Firstly introduced in the early eighties, Prime Event Structures (pes's) are partial orders of \events", equipped with a \con ict" relation. Such structures are very suitable for describing the behaviour of distributed and nondeterministic computational devices generating instantaneous atomic events, which can be causally related or mutually exclusive: the level of abstraction they capture is considered as directly re ecting that of a possible, concurrent implementation, where each event corresponds to a basic action of the underlying machine. To each pes is associated a set of con gurations: compatible, left-closed subsets of its events. Intuitively, a con guration corresponds to a speci c state of the system reached after some computation, and its events are all those generated during that speci c computation. A fundamental result due to Winskel shows that the set of all con gurations of a pes ordered by set inclusion (its \domain" of con gurations) forms a pad; moreover, for each pad there is a pes such that its domain of con gurations is isomorphic to the given pad. Thus the use of pad's or pes's for the description of computational systems is equivalent. Coming back to term rewriting systems, in each of the two models mentioned above the collection of all abstract derivations starting from a given initial term t can be equipped easily with a pre x partial ordering: d d i there exists a derivation d such that d d = d . In Section 5 we will show that only the pre x partial order induced by Stell's model is a pad, while that induced by Meseguer's model fails to satisfy the \distributive property" of pad's. The paper has the following structure. In Section 2 we recall the basic notions of enriched category theory which are useful for our discussion. In Section 3, besides the de nitions of term algebras and of term rewriting systems, we introduce some notions borrowed from Meseguer's Rewriting Logic [Mes92]. In Section 4 we present an alternative, categorical description of trs, and we introduce in a uni ed presentation the two categorical models proposed by Jose Meseguer and John Stell. In Section 5 we analize the adequacy of such modelizations, along the line discussed in this introduction, providing a pad semantics for sesqui-categorical models. Finally, in Section 6 we draw our conclusions about the previous results, suggesting further directions for future work.
00
00
0
0
2 Background on 2-categories and Sesqui-categories In the following we assume that some basic de nitions of category theory are known, for which we refer the reader to [ML71]. In this section we will introduce 2-categories and sesqui-categories, lifting to this enriched context some constructions of the classical category theory. Basically, a cat-enriched category simply is a category C such that, given any two object a; b, the hom-set C[a; b], i.e., the 3
class of morphisms from a to b is a category: moreover, these hom-categories satisfy particular composition properties. A morphism in C[a; b], a cell, is denoted as : f g : a b, where f; g : a b; or graphicallly, as 2
)
!
!
f
a
g
%
9
b:
The following de nition is adapted from [Ste92].
De nition1 (2-Categories and Sesqui-Categories). Let C be a category such that each homset C[a; b] also forms a category. Moreover, let us assume that for each triple a; b; c of objects there are two composition functions L and R such that, given : f h : a b and : g i : b c, then = f L C[a; c] and = R g C[a; c]. Graphically,
0
)
0
2
a
f /
g
b
i
$
:
!
!
2
=
c
)
fg fi ;
a
0
$
:
c
C[a; c]
2
;
(analogously for = R g) where ; denotes composition inside C. Let us consider the situation denoted by the following cells: 0
j
f
a
/
b
k
g
/
F
h
c
/
d i e: /
E
A 2-category C (or simply C) is a category C (called the underlying category) with a structure as the one above de ned, such that the composition functions are subject to the following equations: 2
(1) idc L = ;
(2) (f; g) L = f L (g L );
(3) g L idh = idg h ;
(4) g L ( ) = (g L ) (g L );
(5) R idc = ;
(6) R (h; i) = ( R h) R i;
;
(7) idg R h = idg h ;
(8) ( ) R h = ( R h) ( R h);
;
(9) (f L ) R h = f L ( R h);
(10) (j L ) ( R h) = ( R k) (g L ):
2
We are quite informal here: both 2-categories and sesqui-categories are categories enriched over Cat, in the sense of [Kel82], but the tensor product used is dierent in the two cases (see [Ste94]). In the following we shall refer to both 2-categories and sesqui-categories as \cat-enriched categories", stressing that their hom-sets form categories: [Str92] contains a comprehensive introduction to this topic.
4
where denotes composition insides hom-categories. A sesqui-category CS (or simply C: usually, there is no ambiguity) is a category C with a structure subject to equations (1)-(9). A 2-functor (sesqui-functor, or just functor in both cases) F : C D is a function mapping objects to objects, morphisms to morphisms and cells to cells, preserving identities and compositions of all kinds. Let 2-Cat (S-Cat) be the category of 2-categories (sesqui-categories) and 2functors (sesqui-functors): there exists an inclusion functor Ui : 2-Cat S-Cat, whose left adjoint Fi simply quotients the structure of a sesqui-category with respect to the axiom (10) (or interchange axiom). As a matter of fact, 2-Cat is re ective inside S-Cat. Note also that, thanks to axiom (10), it is possible to de ne the notion of horizontal composition of cells, so that the given de nition for 2-category is then equivalent to the classical one (see [KS74]) (j L ) ( R h) = ( R k) (g L ) = : A category C is cartesian if it has a terminal object 0, such that for every object a there exists a unique arrow !a : a 0; and (binary) products, i.e., a triple a;b = a b; : a b a; : a b b for each pair a; b of objects, such that, given the arrows f : c a; g : c b , there is a unique arrow f; g : c a b satisfying f; g ; = f and f; g ; = g. These properties are required for cells in an enriched context. De nition2 (Cartesian Cat-Enriched Categories). Let C be a 2-category (sesqui-category) such that the underlying category C is cartesian. We say that C has nite 2-products (sesqui-products), if for every pair : f g : c a and : h k : c b of cells, there exists a unique cell = ; : f; h g; k : c a b satisfying R = and R = . Graphically,
!
t u
!
!
h
0
!
h
h
i
!
1
h
!
i
!
i
!
h
0
i
i
1
)
)
h
i
!
!
h
c
0
f;hi
a b 0 hg;k i
h
)
/
5
1
=
a
f
c
g
!
i
$
:
h
i )
a
(similarly for ). C has terminal 2-object if for every cell : f g : c a we have R !c =!a , where 0 is terminal in C and !a : a 0, !c : c 0. We de ne 2C-Cat (SC-Cat) as the category of cartesian 2-categories (sesquicategories) and functors preserving products and terminal object: the pair of functors Ui ; Fi introduced above still forms an adjunction when restricted to 2C-Cat and SC-Cat, respectively, if we require that functors in those categories preserve products and terminal object \on the nose". We will be interested in a nitary presentation of an enriched structure, i.e., in a set of generators such that a cat-enriched category can be obtained freely composing cells. An appropriate structure for that is represented by c-computads. De nition3 (C-Computads). A c-computad is a pair C; S , where C is a category and S is a set of cells, each of which has two parallel arrows of C as source and target, respectively. Given the c-computads C; S and C ; S , a c-morphism is a pair F; h such that F : C C is a functor, h : S S is a function, and for every cell : f g S we have h() : F(f) F(g) S . )
!
h
!
!
t u
i
h
h
h
i
!
)
2
i
i
0
0
!
)
5
h
2
0
i
0
0
t u
A c-computad C; S is cartesian if so is C, while a c-morphism F; h preserves products and terminal object if F does so. Let C-Comp be the category of cartesian c-computads and c-morphisms preserving products and terminal object: there exists an obvious forgetful functor U : 2C-Cat C-Comp which forgets the composition of cells, with left adjoint F . This adjoint composes the cells of a c-computad in all the possible ways, both horizontally and vertically, imposing further equalities in order to satisfy the axioms of a 2-category and to preserve nite products and terminal object on the underlying category. There exists also a similar adjunction pair Us ; Fs between SC-Cat and C-Comp, such that the following diagram commutes h
i
h
i
!
2
2
h
i
C-CompNNNNN
NNNNF2 Us Fs U2 NNNNNNNNNN N SC-Cat Fi 2C-Cat Ui O
f
&
/
o
All functors preserve products and terminal object \on the nose": in particular, those originating from C-Comp preserve products in the underlying category.
3 Term Algebras and Rewriting Systems We start recalling some well-known results about universal algebras (see e.g. [ADJ77]) We will introduce them in the classical, set-theoretical way, dealing in particular with the structure of terms in free algebras. De nition4 (The Class of -algebras). Let be a (one-sorted) signature, i.e., a ranked alphabet of operator symbols = n n (saying that f is of arity n for f n ). A -algebra is a pair A = A ; A such that A is a set (the carrier), and A = fA f is a family of functions such that for each f n , fA : A n A . Let A; B be two -algebras: a -homomorphism : A B is a function : A B preserving operators, i.e., such that for each f n , fA = fB n. It is well-known that for each signature there exists an initial algebra, often called the word algebra and denoted by T : the elements of the word algebra are all the terms freely generated from the constants and the operators of . Given a set X = x ; : : :; xn of variables, the elements of the algebra T (X), i.e., the algebra of terms with variables in X, are the terms of T X , freely generated from adding the elements of X as new constants. Given a term t = f(t ; : : :; tn), a subterm of t could be simply de ned as t itself, or any subterm of ti : but since we want to distinguish among dierent occurrences of the same subterm in t, we need to de ne in a formal way the notion of \occurrence". The set (t) of occurrences of a term t is the subset of IlN de ned inductively in the following way 1. (the empty string) is an occurrence of t; [ 2IN l
2
hj
f
2
j
j
! j
!
j
f
1
j
i
j
j
g
j
j
2
2
j ! j
j
t u
g
[
1
O
6
2. if t = f(t ; : : :; tn) and w (ti ), then iw (t). In the following, as a subterm of t we mean a pair w; s : s is the actual subterm, while w is the position of that particular subterm in t. Each (t) can be equipped with a partial order relation: w w i there exists w such that w w = w ; two occurrences w ; w are disjoint if neither w w nor w w ; two subterms are disjoint if so are their respective occurrences. Finally, given two nite sets X; Y of variables, a substitution is a function : X T (Y ), usually denoted as a set of the form x =t ; : : :; xn=tn for xi = ti (in post x notation). A substitution extends to a function (also denoted ) from T (X) to T (Y ), de ned inductively as f(s ; : : :; sn) = f(s ; : : :; sn) for every operator f . Now we are ready to introduce (term) rewriting systems, which are just (labelled) sets of rules, i.e., of pairs of terms. De nition5 ((Term) Rewriting Systems). Let X be a set of variables. A (term) rewriting system is a tuple (; L; R), where is a signature, L is a set of labels, and R is a function R : L T (X) T (X), such that for all d L, if R(d) = l; r then var(r) var (l) X and l is not a variable. We write d : l r R if d L and R(d) = l; r ; sometimes, to make explicit the variables contained in a rule, we will write d(x ; : : :; xn) : l(x ; : : :; xn) r(x ; : : :; xn) R where x ; : : :; xn = var (l); moreover, given a substitution = x =t ; : : :; xn=tn , we will write l(t ; : : :; tn) for l. From the classical viewpoint, a rule d : l r can be applied to a term t if there is a subterm w; s of t such that l matches s, and the result is the term t where the matched subterm is replaced by a suitable instantiation of r. Moreover, a term can be rewritten into another if there exists an appropriate chain of rules applications. This presentation makes sequences of rewrites the basic notion: it does not allow to reason about how a rewrite can be executed, i.e., to record the possible, dierent justi cations of a derivation. To this aim, we introduce now an alternative de nition of rewriting, borrowed from the seminal work by Jose Meseguer [Mes90, Mes92]. The idea is to take a logical viewpoint, regarding a rewriting system as a theory, and any rewriting - making use of rules in - as a sequent entailed by the theory. The entailment relation is de ned inductively by the deduction rules of rewriting logic. De nition6 (Proof Terms and Rewriting Sequents). Let = (; L; R) be a rewriting system. Let = n n be the signature containing all the rules d : l r R with the corresponding arity given by the number of variables in d: more precisely, for each n, n = d d(x ; : : :; xn) : l(x ; : : :; xn) r(x ; : : :; xn) R . A proof term is a term of the algebra T = T (X), where \ " is a binary operator (we assume that there are no clashes of names among the various sets of operators). A (rewriting) sequent is a triple ; t; s (usually written as : t s) where is a proof term and t; s T (X). So, sequents in rewriting logic have the form : t s, where t and s are terms and is a proof term, encoding a justi cation of the rewriting of t into 2 O
1
2 O h
i
O
1
1
2
3
2
1
!
2
f
1
1
2
3
2
1
g
1
1
1
2
R
!
h
i
!
2
2
2
h
i
1
2
1
f
1
f
g
1
!
1
g
1
t u
1
!
h
i
R
R
R
[
!
2
f
2
1
j
1
!
1
g
R
[
[fg
h
!
2
!
7
i
t u
s. We say that t rewrites to s via if the sequent : t s can be obtained by nitely many applications of certain rules of deduction. !
De nition7 (Rewriting Logic). Let = (; L; R) be a rewriting system. We say that entails the full sequent : s t if it can be obtained by a nite number of applications of the following rules of deduction: R
R
!
(Re exivity)
t T t : t t; 2
!
(Full Instantiation) d:l
!
r R; d n; i : ti si sequents for i = 1; : : :; n ; d( ; : : :; n) : l(t ; : : :; tn) r(s ; : : :; sn ) 2
2
!
1
(Congruence)
1
f n ; i : ti si sequents for i = 1; : : :; n ; f( ; : : :; n) : f(t ; : : :; tn) f(s ; : : :; sn ) 2
!
1
(Transitivity)
!
1
!
1
1
: s t; : t u : :s u The rewriting system entails the at sequent : s t if it can be obtained by a nite number of applications of the rules Identity, Congruence, Transitivity, and Flat Instantiation, where !
!
!
R
!
(Flat Instantiation) d:l
r R; d n; ti T (X) for i = 1; : : :; n d(t ; : : :; tn) : l(t ; : : :; tn) r(t ; : : :; tn) : !
2
1
2
2
!
1
1
t u
Let us point out the meaning of these rules. Re exivity and Transitivity are self-explaining. Congruence states that disjoint rewrites can be executed in parallel: the associated proof term provides the context for the respective justi cations. The most interesting rules are the two dierent kinds of instantiation. Full Instantiation allows for nested rewriting: two subterms matching the left-hand sides of two rules can be rewritten in parallel even if their roots are not disjoint, i.e., if one is above the other, provided that they do not overlap. On the contrary, Flat Instantiation does not allow such nesting: each rule can only be instantiated with elements of T (X), and thus the rule names in a proof term generated using this rule instead of Full Instantiation will appear at mutually disjoint positions. It is worth stressing that on the one hand full sequents correspond exactly to the entailment relation de ned by Meseguer (for the unconditional case) in [Mes92]. On the other hand, we introduced at sequents as the syntactical counterpart of Stell's categorical model, as we will see in the next sections. 8
As an example, consider the rewriting system = d(x) : f(x) g(x); d : a b . It entails the at sequents d(a) g(d ) and f(d ) d(b) with source f(a) and target g(b): rule d has been instantiated with x=a and x=b respectively, while d has been contextualized; it also entails the full sequent d(d ) : f(a) g(b), where d is nested inside d. Graphically, we have the rewrites V
!
g
0
f
0
f
0
!
g
f
g
0
0
!
0
d _a _
f_
'& %$ ! "#
g
( )
g
f _d _b _ g
f
'& %$
'& %$
! "#
! "#
f _ _ _g
( )
'& %$ ! "#
dd (
a
'& ! %$ "#
a _f _d _ b
a _g _d _ b (
0
)
(
0
a_
b
'& ! %$ "#
'& ! %$ "#
)
'& ! %$ "#
0
)
_ _
b
using the standard (yet suggestive, in our case) representation of terms as trees. The complete agreement between the classical de nition of derivability among terms and the one above using Rewriting Logic was already stated in [Mes92] (and it has been formally established and generalized to in nite rewriting in [CG94]). More precisely, it is not dicult to show that there exists a derivation from t to s in a trs i entails a sequent ( at or full) : t s. The same kind of agreement holds between full and at entailment: a rewriting system entails a full sequent : t s, i there exists a nite chain i : ti si ; i = 1; : : :; n of at sequents, such that : : : n : t s. So, why to distinguish between at and full rewrites? First of all, we must remind the reader that sequents represent an operational model for rewriting systems: each sequent can be considered as the encoding of a \concrete" computation of the machine. If we consider a term as a totally distributed structure, i.e., such that an actual rewriting machine can act separately on each occurrence of the term, then full sequents are able to describe the simultaneous execution of nested rewrites. Instead, a at sequent can express only \disjoint" concurrency: two rewrites can be executed simultaneously only if they act on disjoint positions of a term. In other words, choosing a set of deduction rules is implicitly the same as choosing a particular implementation schema, so to say, for a rewriting system. We already stated in the introduction the reasons why providing a concurrent semantics for a rewriting system means equipping its set of computations with a suitable equivalence relation. This is a particularly easy task in the setting of Rewriting Logic, where the elements of the space of computations are encoded by terms of the algebra T . So, an equivalence relation can be easily expressed as an appropriate set of axioms on proof terms. R
R
!
R
!
!
1
!
R
De nition8 (Abstract Sequents). Let be a rewriting system. An abstract
at sequent entailed by
R
is an equivalence class of at sequents entailed by modulo the following set E of axioms, which are intended to apply to the corresponding proof terms: R
R
{ (Associativity)
; ; proof terms ( ) = ( ) ;
9
{ (Distributivity)
f n ; i; i proof terms for i = 1; : : :; n f( ; : : :; n n ) = f( ; : : :; n) f( ; : : :; n) ; 2
1
{ (Identity)
1
1
1
: s t sequent : s == t It is easy to check that proof terms equated by the above equations have the same source and target terms, thus an abstract at sequent can be represented safely as []E : s t. Similarly, an abstract full sequent entailed by is an equivalence class []E : s t of full sequents entailed by , where []E is an equivalence class of proof terms modulo the equations in E , which is the union of the above equations and the following one: !
!
R
!
R
0
0
0
{ (Interchange)
d : l r R; d n; i : ti si sequents for i = 1; : : :; n d( ; : : :; n) = l( ; : : :; n) d(s ; : : :; sn ) = d(t ; : : :; tn) r( ; : : :; n) : !
2
1
2
1
!
1
1
1
t u
Associativity and Identity need no explanation. Also Distributivity has an obvious meaning: to give a context to the composition of two rewrites is the same as to compose the contextualization of the single rewrites. The Interchange axiom is applied to full sequents only: it states that each nested rewrite can be expressed as the sequential composition of two simpler rewrites. Similarly to De nition 7, the set E of axioms coincides with those given by Meseguer, while we introduced E, as we will see in the next section, as the algebraic counterpart of Stell's categorical model. 0
4 Categorical Models of Rewriting Systems The aim of the previous section was to provide set-theoretic models for rewriting systems. Instead, the main concern of this section is for categorical models: we want to introduce enriched structures such that their cells are in one-to-one correspondence with the abstract sequents of a rewriting system. We rst de ne a structure such that its set of cells is in one-to-one correspondence with the rewrite rules in , and, moreover, the underlying category is able to describe in a faithful way the structure of the word algebra associated to a given signature. Given a signature , we denote by Th() the associated Lawvere theory [Law63]: it is a category with nite products having natural numbers as objects, freely generated from the operators of . De nition9 (Lawvere Theories). Given a signature , the associated Lawvere theory is the category Th() with nite products such that R
10
{ its objects are underlined natural numbers: 0 is the terminal object and the product is de ned as n m = n + m; { the arrows are generated by the following inference rules:
(pairing) s :s;nt : nm; t :mn + mm m IlN (identities) id n: n IlN n (projections) : n + m n; n; :n+m m n s : n n IlN m; t : m k (composition) ( terminal arrows ) s; t : n k !n : n 0 and satisfying the axioms of cartesian categories. It can be shown that arrows from n to 1 are in one-to-one correspondence with -terms whose variables are among x ,...,xn: by t : n 1 we shall denote the arrow corresponding to a term t. Similarly, an arrow n m corresponds to a muple of -terms with n variables, and arrows composition is terms substitution. Note that, since 0 is the terminal object, there exists a (unique) arrow !m : m 0 for m IlN. As for the so-called duplicators n = idn; idn : n 2n, these arrows play a fundamental r^ole in the one-to-one correspondence between arrows and terms. Let us consider a constant c: as a generator, the corresponding arrow is c : 0 1, while, when considering c as an element of T (x ; x ), then the associated arrow is ! ; c : 2 1; moreover, these arrows are unique, since for each s : m n, we have s; !m =!n. Without going any further, the Lawvere theory Th() can be regarded simply as an alternative presentation of the signature (where the basic operators are those we called generators), while each homset Th()[n; m] (i.e., the set of morphisms with source n and target m) is equivalent to [T (x ; : : :; xn)]m , the set of m-tuples of terms of the free -algebra with at most n variables. De nition10 (From Rewriting Systems to Computads). Given a rewriting system = (; L; R), the associated c-computad Th( ) is given by the pair Th(); Rc , where Rc is a set of cells between the arrows of Th(), such that : s t i c : s t Rc. After seminal studies in the late Eighties [RS87, Pow89], the correspondence between rewriting systems and c-computads has been at the basis of many works on rewriting. The usual technique consists of freely generating from a c-computad a cat-enriched structure such that its cells represent (equivalence classes of) sequences of rewrites: given a cell c, left-composition s L c instantiates the rewrite corresponding to c, while right-composition c R t inserts it in a context. The approaches by Meseguer [Mes90, Mes92] using 2-categories and by Stell [Ste92, Ste94] using sesqui-categories are instances of such a general idea. Thus they can be easily rephrased in this categorical setting by using the free functors relating c-computads and cat-enriched categories introduced after De nition 3. It is worth stressing that this presentation departs from those proposed in the original works (dramatically so for Stell's model): but it is essentially the same, in the sense that the induced equivalences on derivations are actually coincident. (generators) f f : nn 1
!
2
!
h
i
2
0
!
0
!
2
!
!
0
!
!
1
2
!
!
!
t u
!
1
!
!
2
r
h
i
!
!
1
2
!
2
!
1
R
h
R
i
!
2 R
!
2
t u
11
De nition11 (Space of Computations). Let be a rewriting system and let Th( ) be its associated c-computads. Then the associated Meseguer's space of computations 2-Th( ) is the cartesian 2-category F (Th( )), while its Stell's space of computations S-Th( ) is the cartesian sesqui-category Fs (Th( )). R
R
R
R
2
R
R
t u
Both these cat-enriched categories provide concurrent models for rewriting systems, since they impose an equivalence relation over cells (i.e., sequences of rewrites). Dierent equivalences, since the interchange axiom plays a crucial r^ole. Let us consider the rewriting system = d(x) : f(x) g(x; x); d : a b; d (x) : h(x) c ; the computad Th( ) has the following set of cells W
00
!
g
f
d
2 g 1
/
r1
a
0
"
/
b
d
$
0 :
0
!
W
1
f
h d"
1 1
!
0 b 1 "
/
!1
/
First of all, note the importance of duplicator and terminal arrow ! for the correspondence between rewriting rules and cells. Note also that cells such as (d R f) (b L d) and (a L d) (d R ( ; g)) = (a L d) ( d ; d R g), originating from a; f : 0 1 (the morphism associated to the term f(a)), belong to both spaces of computations. But while in Stell's space they are dierent, in Meseguer's space, thanks to the interchange axiom, they are equated. The same happens to the cells (d R h) (b L d ) and (a L d ) (d R (! ; b)) = (a L d ) originating from the morphism a; h. This suggests that sesqui-categories are suitable models of at entailment: as an example, there is no intuitive semantical counterpart for the abstract full sequent [d(d )]E : f(a) g(b; b) in the sesqui-category S-Th( ). On the contrary, 2-categories are models for the full entailment relation: since the interchange axiom holds, the cell associated to that sequent is given by (d R f) (b L d) = (a L d) (d R ( ; g)) = d d . All this discussion is summarized by the following theorem, stating in a clear way the relationship between spaces of computations and abstract sequents. r1
0
0
1
r1
h
0
0
i
!
0
0
00
00
0
1
!
0
W
0
0
r1
00
0
Theorem 12 (Correspondence of Algebraic and Categorical Models).
Let R be a rewriting system. Then the following statements hold: 1. For each n 2 IlN there exists a bijective function n between the set of all abstract at sequents entailed by R containing variables in fx ; : : :; xng and the cells in S-Th(R)[n; 1], such that ([]E ) : s ! t i []E : s ! t. 2. Similarly, for each n 2 IlN there exists a bijective function n between the set of all abstract full sequents entailed by R containing variables in fx ; : : :; xng and the cells in 2-Th(R)[n; 1], such that ([]E ) : s ! t i []E : s ! t. 1
1
0
0
t u
5 Categorical Models and Prime Algebraic Domains In this section we aim at analyzing the algebraic properties of the categorical models we just introduced. As a start, we introduce Prime Algebraic Domains 12
(pad's for short; see [Win89]). A pad is simply a partial order (po) verifying some additional properties. The use of po's in semantics relies on the old idea that a computing machine determines an ordered space of computations: the richer structure of pad's, however, make them especially suitable for modelling distributed systems. De nition13 (Prime Algebraic Domains). Let = D; be a po: 1. The least upper bound (shortly lub) of a set X D is an element F X F such that X for all x X, and F X x z. We F such that for all z D, ( x X : x z) write x y for x; y . 2. Symmetrically, the greatest lower bound (shortly glb) of a set X D is an element uX such that uX x for all x X, and such that for all z D, ( x X : z x) z uX. We write x y for u x; y . 3. A directed subset of D is a subset S D such that for any nite subset X S there is an element s S such that x X : x s. F 4. An element x D is nite if for all directed sets S, x S implies that there is some s S such that x s. 5. is nitary if for every nite element x D, the set y y x is nite. 6. An element x DF is complete prime ) if for each X D (each F X,(prime nite X D), if X exists and x then there exists an y X such that x y. F 7. is prime algebraic if for all x D, x = y x y is complete prime . 8. For x; y D, we write x y (and we say that x and y are compatible) if there exists a z such that x z and y z. We say that X D is pairwise compatible if for all x; y X we have x y. 9. A nitary partial order D; is distributive if, whenever x y, then we have (x y) z = (x z) (y z). 10. is nitely coherent if it has lub's of nite, pairwise compatible subsets. is a coherent domain if it has lub's of arbitrary, pairwise compatible subsets. D
h
vi
)
2
2
t
f
8
2
g
8
2
)
2
2
u
f
g
2
8
2
2
v
2
v
D
2
f
j
v
g
2
v
2
v
D
2
2
v
v
j
g
v
2
h
t
f
"
u
u
"
vi
t
"
u
D
D
t u
Fact 14. Any coherent, nitary prime algebraic domain is distributive. D
t u
As we remarked in the introduction, whenever the derivation space of a model forms a pad, this can be seen as an implicit con rmation of the \adequate degree of concurrency" of that model. Given term t, we de ne now formally its derivation space as the subset of cells originating from t . De nition15 (Derivation Spaces). Let = ; L; R be a rewriting system, and t T (X). The Meseguer's derivation space (t) associated to t is the partial order (t); , where (t) is the set of coinitial cells in 2-Th( ) originating from t , and is the partial ordering relation de ned as R
2
i
L2
hD2 3
3
h
v2 i
D2
v2
R
v2
An equivalent de nition could be given in categorical terms. Let us assume that t : n ! 1, and let us denote 2-Th(R)[n; 1] by C: then the objects of the comma category (t # C) coincide with the elements of the derivation space D2 (t). The same relation holds for sesqui-categorical models.
13
i there exists such that = . Similarly, we de ne the Stell's derivation space LS (t) = hDS (t); vS i by simply replacing 2-Th(R) with S-Th(R) in the
above de nition. It turns out that, in general, the derivation spaces induced by 2-categorical models fail to satisfy the distributive property of pad's, since the ordering in which rewrites are executed in uences the number of basic steps which are to be performed . This is summarized by a nave result of category theory: due to the structure of cells, in a cartesian 2-category no notion of length is de nable. As for a counterexample to distributivity, let us consider the rewriting system de ned in the previous section. If we look at the space of computations 2-Th( ) and the term f(a), the associated derivation space (f(a)) has the following structure (where the partial ordering ows downwards): ida f a Ld d Rf a L d d R (a id ); g a L d d R (id a); g d R f b L d = a L d (d d ); g Let x = a L d d R (a id ); g, y = a L d d R (id a); g, and z = d R f: then z = (x y) z = (x z) (y z) = ida f , hence (f(a)) is not distributive. In categorical terms, this means that to allow together the cartesian structure and the interchange axiom does not permit to recover a pad semantics: since the execution ordering in uences in 2-categorical models the number of basic steps, it creates a causal link between dierent processors. Instead, in Stell's approach the interchange axiom is dropped, still preserving the cartesian structure on cells: this way, we are able to state the following theorem. Theorem 16 (Derivation Spaces and pad's). Let = ; L; R be a rewriting system. For any t T (X), the po S (t) is a coherent, nitary pad. t u
4
W
D2
W
;
0
0
t
0
u
0
6
u
0
u
;
0
1
L
1
0
D2
R
2
0
0
1
t
1
h
i
t u
6 Conclusions The main purpose of this paper was to analyze two categorical semantics for term rewriting systems proposed in the literature. To this aim we rstly introduced a new, uni ed presentation for them. Then we showed that the derivation spaces associated to Stell's model are prime algebraic domains, that is, a well accepted model for expressing the concurrency of an abstract formalism. On the contrary, this is not true in general for the derivation spaces associated to Meseguer's model (based on cartesian structure plus interchange axiom). 4
The same result could be inferred also by the analysis of [LM92, Lan94]. In the rst paper it is shown that the equivalence induced on rewrites in Meseguer's space of computations coincides with permutation equivalence. In the second, it is shown that in the case of -calculus (and more generally, for any trs) permutation equivalence cannot be the basis for a prime algebraic domain semantics.
14
However, we view Stell's proposal as too narrow: dropping interchange means limiting the degree of concurrency expressible by the model in an unacceptable way. For instance, let us consider the rewriting system (Section 3): the computations corresponding to d(a); d and d ; d(b) : f(a) g(b) are not equated in the sesqui-category S-Th( ). On the other hand, the 2-categorical model fails to generate a sc pda when non-linear rewriting rules are involved (a rule is linear if each variable appears exactly once both in the left and right-hand side), since for such rules the execution order in uences the number of basic steps to be performed. As an example, in the 2-category 2-Th( ) (Section 4) the following derivations with dierent length are equated a;a V
0
0
!
V
W
0
a
b
d
$
0 :
r1
1
/
=
2 a
0
a;ai d hb;bi
h
h
2
0 '
7
=
2
0
i
ha;bi dr dl hb;bi 0
/
0
?
2
() y
id
= 0 d 1 1 0 0 0 0 () b where 2d = d L = d ; d , dl = d ; idb and dr = ida ; d . The cartesian structure on cells allows for implicit garbage collection and duplication (as discussed in [Cor94]): these \housekeeping" operations are performed silently, in the sense that the abstract machine corresponding to the model cannot distinguish for instance between states where garbage has been already collected, and states where it has not. The situation is well-shown by ( ) and ( ): it seems evident that models with interchange axiom and implicit behaviour on these operation cannot be the basis for a pad semantics. Stell's solution still keeps these operations silent, while dropping interchange forces the model to distinguish between derivations diering for the order of execution of nested rewrites. A current trend of work is investigating the case of preserving interchange and dealing with some kind of weak cartesianity (along the line of Jacobs [Jac93] for the semantics of linear logic), making housekeeping explicit. Although a detailed discussion about the actual implementability of term rewriting in a way re ecting the degree of concurrency of either models goes beyond the scope of this paper, some comment is in order. Even if the computations of the 2-categorical model do not form a pad, it does not mean that the model cannot be implemented on a parallel computer, as by the way has been shown by Meseguer's work on the Rewriting Rule Machine (see [LMR94]). However, if a concurrent machine (one with loosely coupled processors) is chosen as target, the results of this paper show that the 2-category model cannot be implemented directly, i.e., by representing operations of processors with events of a pes having the same domain of computations. Of course the 2-categorical model can be mapped to a concrete, concurrent machine, but the compilation process should be designed carefully in order to minimize hidden, expensive synchronizations and sequentializations of processors, which are unavoidable according to our results. !
$
0
0
y
0
/
z
/
:
r1
h
0
0
i
0
h
0
i
0
h
0
i
z
Acknowledgments: We wish to thank Jose Meseguer for the interesting discussions and his careful reviewing of the manuscript. 15
References [ADJ77] J.A. Goguen, J.W. Tatcher, E.G. Wagner, J.R. Wright, Initial Algebra Semantics and Continuous Algebras , Journal of ACM 24 (1), 1977, pp. 68-95. [Bou85] G. Boudol, Computational Semantics of Term Rewriting Systems , in Algebraic Methods in Semantics, eds. M. Nivat and J. Reynolds, Cambridge University Press, 1985. [CG94] A. Corradini, F. Gadducci, CPO Models for In nite Term Rewriting, draft. [Cor94] A. Corradini, Term Rewriting, in Parallel , draft. [DJ90] N. Dershowitz, J.P. Jouannaud, Rewrite Systems , Handbook of Theoretical Computer Science B, ed. J. van Leeuwen, North Holland, 1990, pp. 243{320. [Jac93] B. Jacobs, Semantics of Weakening and Contraction, draft. [Kel82] G.M. Kelly, Basic Concepts of Enriched Category Theory, London Mathematical Society, LN Series 64, 1982. [KS74] G.M. Kelly, R.H. Street, Review of the Elements of 2-categories, Lecture Notes in Mathematics 420, 1974, pp. 75-103. [Lan94] C. Laneve, Distributive Evaluations of -calculus , Fundamenta Informaticae 20 (4), 1994, pp. 333-352. [Law63] F. W. Lawvere, Functorial Semantics of Algebraic Theories, Proc. National Academy of Science 50, 1963, pp. 869-872. [Lev80] J.J. Levy, Optimal Reductions in the -calculus, in To H.B. Curry, Essays in Combinatory Logic, Lambda Calculus and Formalism, eds. J.P. Seldin and J.R. Hindley, Academic Press, 1980, pp. 159-191. [LM92] C. Laneve, U. Montanari, Axiomatizing Permutation Equivalence in the calculus , in Proc. 3rd ALP, LNCS 632, 1992, pp. 350-363. [LMR94] P. Lincoln, J. Meseguer, L. Ricciulli, The Rewrite Rule Machine Node Architecture and its Performance, in Proc. CONPAR'94, LNCS 854, 1994, pp. 509-520. [Mes90] J. Meseguer, Functorial Semantics of Rewrite Systems, appendix of Rewriting as a Uni ed Model of Concurrency, SRI Technical Report, CSL-93-02R, 1990. [Mes92] J. Meseguer, Conditional Rewriting Logic as a Uni ed Model of Concurrency, in Selected Papers of 2th Workshop on Concurrency and Compositionality, Theoretical Computer Science 96, 1992, pp. 73-155. [ML71] S. MacLane, Categories for the Working Mathematician, Springer, 1971. [MOM93] N. Mart-Oliet, J. Meseguer, Rewriting Logic as a Logical and Semantic Framework, SRI Technical Report, CSL-93-05, 1993. [Pow89] A.J. Power, An Abstract Formulation for Rewrite Systems, in Proc. CTCS'89, LNCS 389, 1989, pp. 300-312. [RS87] D.E. Rydeheard, J.G. Stell, Foundations of Equational Deduction, in Proc. CTCS'87, LNCS 283, 1987, pp. 114-339. [Ste92] J. G. Stell, Categorical Aspects of Uni cation and Rewriting , Ph.D. Thesis, Faculty of Science, University of Manchester, 1992. [Ste94] J. G. Stell, Modelling Term Rewriting System by Sesqui-categories , Technical Report TR94-02, Keele University, 1994. [Str92] R.H. Street, Categorical Structures, in Handbook of Algebra, eds. M. Hazewinkel et al., Elsevier, preprint 1992. [Win89] G. Winskel, An Introduction to Event Structures , Lecture Notes for the REX Summer School, LNCS 354, 1989, pp. 285-363.
16