Some Properties of Non-Orthogonal Term Graph Rewriting - CiteSeerX

0 downloads 0 Views 208KB Size Report
sequences based on Boudol's work on the semantics of term rewriting, it shows that .... Although the rst two sequences are equivalent to the last sequence they.
URL: http://www.elsevier.nl/locate/entcs/volume2.html

10 pages

Some Properties of Non-Orthogonal Term Graph Rewriting David Clark Department of Computing Imperial College London, UK

Richard Kennaway

1

Department of Information Systems University of East Anglia Norwich, UK

Abstract

This paper examines left-linear non-orthogonal term graph rewriting systems that allow asymmetric con icts between redexes. Using a de nition of compatibility of sequences based on Boudol's work on the semantics of term rewriting, it shows that two properties associated with functional languages are true of such graph rewriting systems. First, that a notion of standard computation can be de ned and that an associated standardisation theorem can be proved. Second, that a set of events can be associated with a reduction sequence and hence event structures modelling all the possible reduction sequences from a given initial graph can be constructed.

1 Introduction

What properties of rewrite systems associated with functional languages carry over to non-orthogonal term graph rewrite systems? This paper concerns itself with two properties of reduction sequences: a notion of standard reduction and the construction of event structures. We show that both are possible. By term graph rewriting we have in mind a formal system such as the ones described in [8] and [7]. We adopt this description for use in this paper since it has the advantage of a high level of abstraction and implicit garbage collection, allowing us to talk about rewrite steps without requiring us to go into details unnecessarily. We require our systems to be left-linear but allow non-disjoint (con icting) redexes. This type of non-orthogonal term graph rewrite system Richard Kennaway was partially supported by an EPSRC Advanced Fellowship, and by SEMAGRAPH II, ESPRIT Working Group 6345.

c 1

1995 Elsevier Science B. V.

Clark and Kennaway

seems suciently general to be able to describe languages without a functional strategy, the abstract reduction used to do strictness analysis in CLEAN, and non-deterministic term graph rewriting. We begin with the fundamental de nition, that of disjoint redexes. A category theoretic version may be found in [7]. De nition 1.1 (Disjoint redexes) A pair of distinct redexes in a graph is said to be disjoint if there is no node of the graph which is erased by the reduction of one redex but pattern-matched by the other. Following Boudol [2] we de ne a notion of compatibility for sequences of rewrites. The notion underlies the rest of the paper. Intuitively sequences are compatible if neither contains a redex which con icts with a redex in the other. Hence compatible sequences each have a residual of one by the reduction of the other and these residuals are de ned below.  is used for the empty sequence. De nition 1.2 (Compatibility of sequences) Two sequences, s1 and s2, are compatible, s1 s2, and we have s=s0 and s0 =s exist i (i) s1 =  and s1=s2 =  and s2=s1 = s2, or (ii) s2 =  and s2=s1 =  and s1=s2 = s1, or (iii) s1 = r s and s2 = r0 s0 and (a) r and r0 are disjoint redexes (b) r=r0 s0 and r0=r s (c) s=(r0=r) s0=(r=r0 ) (d) s1=s2 = (r=r0 )=s0 (s=(r0=r))=(s0 =(r=r0 )) (e) s2=s1 = (r0=r)=s (s0=(r=r0 ))=(s=(r0 =r)) "





"

"

"





r r0

s0

s

-

? r=r0

r0=r

(r0=r)=s

s=(r0 =r)

-?

s0=(r=r0 )

-?

(s0=(r=r0 ))=(s=(r0 =r))

?(r=r0)=s0 - ? (s=(r0 =r))=(s0=(r=r0 ))

-?

We de ne Levy (permutation) equivalence. The de nition is similar to the one for orthogonal systems [7] except that we must take the transitive closure as it is possible for two sequences of non-orthogonal rewrite steps to be Levy equivalent to a third sequence but not to each other using that de nition. For example, suppose we have the following rewrite rules: A B , A C , and F (x) G Using these rules we can construct the following three sequences of rewrites 2 !

!

!

Clark and Kennaway

from initial graph F (A):

F (A) A

!

B- F (B ) F (x)

!

G- G

F (A) A

!

C- F (C ) F (x)

!

G- G

F (A) F (x)

!

G- G

Although the rst two sequences are equivalent to the last sequence they are not equivalent to each other. Intuitively, we expect that the three sequences have done the same work, i.e. are equivalent.

De nition 1.3 (Levy Equivalence)

(i) De ne = between two sequences as the smallest relation satisfying (a) r (r0=r) = r0 (r=r0 ) if r r0 (b) s = s0 s1 s s2 = s1 s0 s2 (ii) De ne L as =+ , i.e the transitive closure of = The following useful results about the de nitions can be demonstrated by some straightforward inductions. Lemma 1.4 s s1 s2 i s s1 and s=s1 s2. Lemma 1.5 If s s1 s2 then s=(s1 s2) = (s=s1)=s2 and (s1 s2)=s = (s1=s) s2=(s=s1). Lemma 1.6 If s = s0 then s s00 i s0 s00. Note that the relation between the sequences in this last lemma is = rather than L. The latter is not generally true but see strong compatibility below. 









)



"













"





"

"

"











"

"





2 External Sequences

Notions of a standard reduction sequence exist for the lambda calculus [1] and term rewriting [6], [2]. As far as we are aware there is no de nition of a standard reduction sequence for term graph rewriting in the literature. Gonthier, Levy and Mellies have proposed an axiomatised framework which allows the proof of a standardisation theorem and which is general enough to cover both the lambda calculus and term rewriting [4]. To date they been unable to nd suitable de nitions of the underlying notions (such as the nesting of redexes relation) which work for term graphs or dags. Our approach rather follows [2]. In the rest of this section we de ne external sequences and prove that every sequence is Levy equivalent (see the following section) to an external sequence. We begin by de ning a notion of occurrence for a term graph. These may be 3

Clark and Kennaway

thought of as a way of distinguishing between the di erent pointers into a subgraph. De nition 2.1 (Term Graph Occurrence) An occurrence in a term graph is the name of a path to a node from the root of the graph. An occurrence is an element of N  giving the concatenation of the pointers out from each node in the path, in order. The pointers are numbered from the left and the empty path (i.e. the single occurrence at the root node) is denoted by . Write occ(n) for the set of occurrences at node n in G, and dom(r) for the set of occurrences at the root node of a redex. It is clear that occurrences can be ordered partially by means of a pre x ordering (henceforth: pref ) and totally by adding the numerical order between single pointers with the same pre x. De nition 2.2 (Trace and Residual of an Occurrence) The trace, w r , and residual, w=r, of an occurrence, w, by the reduction of a redex, r, is given by (i) u dom(r). u is incomparable with w or w pref u then w=r = w = 

h i

8

2



f

g

wr (ii) u dom(r). u pref w then (a) if w is pattern-matched by r, w=r = and w r = u (b) if not, for every variable, x, in the left hand side of the rule for r with occurrence v such that w = uvw0 and w=r = w r = u:v 0:w0 v 0 is an occurrence of x in the right hand side of the rule for r h i

9

2



;

h i

f g

h i

f

j

g

It is worth noting that in case (ii)(a) in the de nition above the trace must necessarily be a singleton set. De nition 2.3 (External Occurrence of a Sequence) For s : G H , w occ(G) is external for s, w extR(s), i (i) s =  or (ii) s = r s0 and (a) u dom(r).( u pref w v int(lhs(r)). w = uv) (b) w r extR(s0) In the above we use lhs as a map from a redex to the term graph which is the left hand side of its rule, and int as a map from a term graph, G, which is part of a rule, to the subset of the occurrences of G which are not the occurrences of variables (i.e. are in some sense internal to the pattern of the redex). Hence an occurrence is external if the sequence is empty or, when the sequence is non-empty, if there is an occurrence of the redex in the rst step of the sequence above the external occurrence then the external occurrence is pattern-matched by the redex and its trace is external to the remainder of the sequence. The subscript R refers to the set of rules for the reductions. De nition 2.4 (Occurrence Reduced by a Sequence) A redex, r, is said to be reduced at an occurrence, w, if w is one of the occurrences at the root of r when it is reduced. An occurrence, w, is reduced by a sequence, if a redex !

2

2



8

2



) 9

h i 

4

2

Clark and Kennaway

at that occurrence is reduced in the course of the sequence. An initial redex of a sequence is one which is present in the initial graph. De nition 2.5 (Initial Redex) s : G ! H and a redex, r, of s is an initial redex for s, i.e. r 2 initredR(s) i s = r0  s0 and (i) r = r0 or (ii) r " r0, r=r0 6= ; and r=r0 2 initredR(s0) The de nition of an external redex is the key de nition in this section. It stipulates that an external redex for a sequence is one which has at least one external occurrence and that all the external occurrences are reduced together and that no occurrences of the redex remain after the external occurrences are reduced. De nition 2.6 (External Redex) s : G ! H and a redex, r, of s is external for s, r 2 extredR(s), i r is an initial redex whose root node satis es (i) it has at least one external occurrence (ii) every external occurrence is reduced by s when r is reduced It is worth remarking that this de nition collapses to the usual de nition of an external redex for term rewriting sequences if the graph is a term. De nition 2.7 (External (Standard) Sequence) A sequence is external if it reduces only external redexes at each step Lemma 2.8 If s is a sequence and r is an external redex of s then s=r and r=s exist (i.e. r " s) and r=s = ; An external redex of a sequence is compatible with the sequence and has no residual after the reduction of the sequence. De nition 2.9 (Strong Compatibility) A redex, r, is de ned to be strongly compatible with a sequence, s, and we write r * s if we have

s0

L



s

)

r s0 "

Strong compatibility then means a redex is compatible with all sequences equivalent to the original. An external redex is strongly compatible with the sequence to which it is external. Lemma 2.10 r extredR(s) r s and s L r (s=r) Furthermore, if two sequences are Levy equivalent the two sequences have the same set of external redexes. Lemma 2.11 s L s0 extredR(s) = extredR(s0) Since we are only considering nite sequences the repeated reduction of external redexes is well-founded (Noetherian). Lemma 2.12 s  s0 def r extredR(s) s0 = s=r. Then  is Noetherian. [5] Using these properties (and others) we can prove a form of standardisation theorem. 5 2



)

*



)

()

9

2





Clark and Kennaway

Theorem 2.13 (Standardisation Theorem) s is an external sequence and s L s Proof is by Noetherian induction on .

8

2 C

R (G) : 9s

2 C

R (G) : s

3 Event Structures

Elementary event structures whose con gurations are sequences of needed reductions from a given, normalisable, initial graph in an orthogonal term graph rewrite system are constructed in [7]. Corradini [3] has done some work on extending this to non-orthogonal systems equivalent to the type of systems outlined in our introduction. However we feel that in introducing a symmetric con ict relation early on in his scheme he has not dealt with con icts between redexes correctly. It is clear that a non-orthogonal term graph rewriting system will allow asymmetric con icts between redexes and we feel that this should be re ected in the event structures for such systems. De nition 3.1 (Pre-event) A pre-event is a pair, (s; r), consisting of a sequence followed by the reduction of a single redex. However a sequence giving the history preceding the reduction of a redex may have done some compatible reductions in a di erent order or may have done some \extra", unneeded reductions. De nition 3.2 (Pre-event equivalence) Two pre-events are equivalent if they can be proved so by repeated application of the following: (i) (s; r) (s0; r) if s L s0 (ii) (s; r) (s s0; r=s0 ) if r=s0 exists and is non-empty. In order to prove a theorem stating that no two distinct steps of a sequence belong to the same equivalence class of pre-events it will be necessary to be able to produce pre-events equivalent to the original but which contain no redundant steps. It is then possible to work with a restricted de nition of pre-event equivalence, so-called strong equivalence, which is just that part of the de nition which allows pre-events to be equivalent if they are the same redex with Levy-equivalent histories. Having (rightly!) allowed pre-events to be equivalent if one is simply the other after an additional, compatible, redundant sequence of reductions with the e ect of deferring the reduction of the redex it is necessary to, in a sense, discount the e ect of this equivalence. The following de nitions express the notion of an irredundant sequence. De nition 3.3 (Contributing Pre-event) In a sequence s r s0 r0 preevent (s; r) contributes to pre-event (s r s0; r0 ) if there is a node n which is either at the root of the contractum of r, which is preserved by s0 and is such that n=s0 is matched by r0 . De nition 3.4 (Needed Pre-event) (s; r) is needed for (s r s0; r0) if it contributes to (s r s0 ; r0 ) or if it contributes to a later pre-event of s r s0 that is needed for (s r s0; r0 ). Otherwise it is redundant. 6 

































Clark and Kennaway

De nition 3.5 (Irredundant Pre-event) A pre-event, (s; r), is irredundant if every pre-event of s is needed for (s; r).

De nition 3.6 (Redundancy of a Sequence) Given a pre-event, (s:r), if

s = s1 r1 s2 call r1 s2 the height of r1. Let the redundancy of (s; r) be the sum of the heights of the redundant redexes of s. 



j



j

Applying the following algorithm to a pre-event yields a pre-event equivalent to the original but with no redundancy. Algorithm 1 (Minimisation Algorithm) The algorithm is de ned in terms of a pair of functions. , the top-level function is recursive. (s; r) = (s; r), if the redundancy of (s; r) is zero = ( (s; r)), otherwise M

M

M O

applies a single step of the algorithm in the case in which the algorithm has yet to terminate. Let r1 be the rightmost redundant step of s: (i) r1 is the last step in s, i.e. s = s1  r1. O (s; r ) = (s1 ; r2 ) where r = r2 =r1 (ii) r1 is not the last step of s, i.e. s = s1  r1  r2  s2 where s2 may or may not be empty. O (s; r ) = (s1  r3  r1 =r3  s2 ; r ) where r2 = r3 =r1 Clearly the algorithm terminates as each application of O reduces the redundancy of the pre-event to which it is applied. Since at each application of O the resulting pre-event is Levy-equivalent to the previous one by one of the cases of  = it is clear that M(s; r)  (s; r) by a straightforward induction on the de nition of M. Lemma 3.7 If (s0; r0) = M(s; r), then the equivalence of (s0; r0) and (s; r) can be proved by at most two applications of the axioms for equivalence: (s0; r0)  (s0  (s=s0); r0=(s=s0))  (s; r) where r = r0=(s=s0 ) and s0  (s=s0) L s Lemma 3.8 If (s0; r0)  (s1; r1) and if M(si; ri) = (s0i; ri0 ) for i = 0; 1 then s00 L s01 and r00 = r10 , i.e. the results of minimising the pre-events are strongly equivalent. Using lemmas 3.7 and 3.8 we then prove the following: Lemma 3.9 (s0; r0)  (s0  r0  s1; r1) and r0 non-empty ) r0 or r1 empty Theorem 3.10 No two distinct, non-empty steps of a sequence belong to the same equivalence class.

O

Proof. Assume that we have a sequence in which two distinct, non-empty steps belong to the same equivalence class. By lemma 3.9 we have a contradiction. 2 De nition 3.11 (Event) An event in the possible reductions from a graph

G is an equivalence class of pre-events. 7

Clark and Kennaway

Given the above de nition and theorem 3.9 we can associate a set of events with a sequence of non-orthogonal reductions. Following Winskel in [10] and [11] we can show that the set of events formed from the union of all sets of events associated with all the possible sequences of reductions from a given graph has a prime event structure. De nition 3.12 (Prime Event Structure) A Prime Event Structure E = (E; Con; ) consists of a set E , of events which are partially ordered by , the causal dependency relation, and a predicate Con fin E , the Consistency relation, which satisfy  e 0 e0 e is nite,  e Con,  Y X Con Y Con,  X Con and e0 X : e e0 X e Con for all e E , and nite subsets X , Y of E . We now construct event structures from term graphs. De nition 3.13 Pre(s) = (s0; r0) s0 r0 is an initial segment of s De nition 3.14 Ev(s) = e (s0; r0) Pre(s) : (s0; r0) represents e De nition 3.15 Let (G) = (Ev(G); Con; ), where (i) Ev(G) = e s : G H : e Ev(s) (ii) e e0 if s : s : G H : e0 Ev(s) e Ev(s) (iii) X Con if s : G H : X fin Ev(s) It is straightforward to show that this is a prime event structure. Theorem 3.16 (G) de nes a prime event structure The con gurations of a prime event structure are given by Winskel ([10] as the consistent subsets which are left-closed under the causality ordering (i.e. ). The con gurations are themselves ordered by subset inclusion. However Winskel's de nitions do not adequately account for the con gurations of events observable in sequences of non-orthogonal reductions in term graphs where there is the possibility of asymmetric con icts. In order to remedy this we need to amend the ordering on con gurations so that it is a restriction of the subset ordering and ensure that the de nition of con gurations is such that every con guration is reachable in the restricted ordering. To this end we de ne on events an asymmetric con ict relation, prevents, in the style of Pinna and Poigne [9]. De nition 3.17 (Prevents Relation) De ne ; E E as e1 ; e2 i e1 (s; r) and e2 (s0; r0), s L s0 and the root node of r is pattern-matched by r0 . The prevents relation will not be sucient in itself to account for all the possible restrictions on the ordering of con gurations. Without a notion of needed events it is possible for some events to \erase" others, thereby in





f

j



g

f g 2 

2

)

2

9

2

2



)

[f g 2

2

f

f

j

j9



g

2

g

E

f



2

j9

8



!

2

!

9

g

2

!

)

2



E



6







8





6

Clark and Kennaway

troducing another kind of prevention which will also a ect the ordering. A convincing account of the con gurations and their ordering must remain for future work. 4 Conclusions

We have de ned external term graph reduction sequences and proved that every sequence of non-orthogonal term graph reductions is equivalent up to permutation to an external sequence. These external sequences are themselves only unique up to permutation but could easily be made unique (i.e. standard) by the introduction of an additional constraint on the order of reduction. We have also shown that a set of events can be associated with a sequence of non-orthogonal term graph reductions. Consequently a prime event structure can be constructed for the set of all possible non-orthogonal reductions from a given initial term graph. This structure does not by itself take into account the possibility of asymmetric con icts between redexes. After the style of Pinna and Poigne, we do this by de ning an explicit asymmetric con ict relation. However there remains the question of a satisfactory account of the con gurations of the event structure and their ordering. References [1] H.P. Barendregt. The Lambda Calculus, volume 103 of Studies in Logic and the Foundations of Mathematics. Elsevier Science Publishers B.V., P.O. Box 1991, 1000 BZ Amsterdam, The Netherlands, 2nd edition, 1984. [2] G. Boudol. Computational semantics of term rewriting systems. In M. Nivat and J. C. Reynolds, editors, Algebraic Methods in Semantics, chapter 5, pages 169{236. Cambridge University Press, 1985. [3] A. Corradini. Term rewriting, in parallel. Unpublished draft, available by application to the author at [email protected], 1994. [4] G. Gonthier, J.-J. Levy, and P. A. Mellies. An abstract standardisation theorem. In Seventh annual IEEE Symposium on Logic in Computer Science, August 1992. [5] G. Huet. Con uent reductions: abstract properties and applications to term rewriting systems. Journal of the Association for Computing Machinery, 27:797{821, 1980. [6] G. Huet and J.-J. Levy. Computations in orthogonal rewriting systems: I and ii. In J. Lassez and G. D. Plotkin, editors, Computational Logic: Essays in Honor of Alan Robinson, pages 394{443. MIT Press, 1991. [7] J. R. Kennaway, J. W. Klop, M. R. Sleep, and F. J. de Vries. Event structures and orthogonal term graph rewriting. In Term Graph Rewriting, theory and practice, pages 141{155. John Wiley and Sons Ltd., 1993.

9

Clark and Kennaway [8] J.R. Kennaway. Graph rewriting in some categories of partial morphisms. In International Workshop on Graph Grammars and their Application to Computer Science, number 532 in Lecture Notes in Computer Science, pages 490{504, Bremen, 1991. Springer Verlag. [9] G. Pinna and A. Poigne. On the nature of events. In Mathematical Foundations of Computer Science. Springer-Verlag LNCS 629, 1992. [10] G. Winskel. Event structures. Technical Report 95, University of Cambridge Computer Laboratory, July 1986. [11] G. Winskel. Event structures. In Advances in Petri Nets, 1986, Part II, number 255 in Lecture Notes in Computer Science. Springer Verlag, 1987.

10