Dynamic Graph Transformation Systems? Roberto Bruni1 and Hern´an Melgratti2 1
Computer Science Department, University of Pisa, Italy. 2 IMT Lucca Institute for Advanced Studies, Italia.
[email protected],
[email protected]
Abstract. We introduce an extension of Graph Grammars (GGs), called Dynamic Graph Grammars (DynGGs), where the right-hand side of a production can spawn fresh parts of the type graph and fresh productions operating on it. The features of DynGGs make them suitable for the straightforward modeling of reflexive mobile systems like dynamic nets and the Join calculus. Our main result shows that each DynGG can be modeled as a (finite) GG, so that the dynamically generated structure can be typed statically, still preserving exactly all derivations.
1
Introduction
Graphs can model complex systems at a level of abstraction that is both intuitive and formal. Graph Grammars (GGs) originated in the late 60’s as a suitable extension of string grammars: string concatenation is replaced by graph gluing and string rewriting by subgraph replacing. As a model of concurrency, there is also a close analogy between GGs and Petri nets (PNs), as a Petri net can be straightforwardly modeled as a particular GG over discrete graphs. Solid theoretical basis are now available for many different kinds of graph transformation, ranging from the essential node replacement systems [8] and edge replacement systems [6] to the more sophisticated synchronized hyperedge replacement systems [3,11,10] and algebraic approaches to graph rewriting [4,7]. To the best of our knowledge, one extension that has not been deeply investigated in the literature is the use of reflexive productions that can release new rewrite rules. Reflexive systems arise naturally in many areas where graph transformation techniques have been applied with success, like biological and chemical systems and distributed and mobile computing. Moreover, the reflexive extension of many different kinds of rewrite systems have been studied in the literature. In particular, dynamic nets are a mobile extension of PNs, expressive enough to model mobile calculi like π-calculus and Join calculus [1,2]. Dynamic nets are indeed strictly more expressive than PNs. Exploiting the analogy between PNs and GGs, we propose a reflexive extension of GGs, called Dynamic Graph Grammars (DynGGs), whose generality is witnessed by encodings of dynamic nets and Join calculus. However, when posing the question: “Are Dynamic Graph Grammars more expressive than ordinary ones?” our main result provides a negative answer: though DynGGs can offer a more convenient abstraction, computationally speaking they are not more expressive than GGs. ?
Research supported by the EU FET-GC2 IST-2004-16004 Integrated Project S ENSORIA
2
R. Bruni and H. Melgratti
From GGs to DynGGs. To complete this informal introduction, we sketch the design choices of DynGGs, introduce some terminology and give a minimal example. Let T denote a type graph and GT a graph typed over T . Ordinary T -typed DPO l r productions are spans of the form p : (LT ← KT → RT ) such that l and r preserve the typing of items in KT . (We assume that the reader has some familiarity with GGs, and hence postpone exact formalization to later sections.) l
r
A first simple extension is to consider productions like p : (LT ← KT → RT 0 ) where T ⊆ T 0 , so that fresh types can be generated and used for typing RT 0 . This way the fresh types introduced by p cannot be exploited in the (left-hand side of) productions. The idea is then to spawn also new productions able to operate on items typed in T 0 \ T . A DynGG is thus a triple (T, GT , P) where T is a type graph, GT a graph typed over l
r
T and P a set of T -typed dynamic productions that take the form p : (LT ← KT → GT 0 ) where GT 0 is again a (T 0 -typed) DynGG and r relates KT to the initial graph of GT 0 . / then the grammar is roughly a T -typed graph GT , which For example, when P = 0, is statically fixed and cannot change. Such grammars are called static. A production p is static if its right-hand side GT 0 is a static grammar and T 0 = T . If all productions are static, then the grammar is called shallow and is essentially an ordinary GGs: the application of any production can neither change the type graph nor spawn new rules. Figures 1 and 2 introduce a small ad hoc example whose purpose is to expose a peculiarity of dynamic rewrites. Let Ta be the singleton type graph with just one node a. Let Tg ⊃ Ta consisting of nodes a and b and two edges f : a → b, and g : b → b. Take the Ta -typed dynamic grammar Ga with the dynamic production p in Figure 1. For simplicity, we take the inclusions as legs of the span and draw the typing (dotted lines) only once for each item. The left-hand side (i) of p consists of a Ta -typed graph with just one node n1 , which is preserved by the context (ii), and the right-hand side (iii) spawns a shallow Tg -typed grammar G p whose initial graph has, beside n1 , one additional node n2 and one arc h. The grammar G p itself has just one static production q ∈ Pp , illustrated in Figure 2: the left-hand side (i) is a graph with three nodes m0 and m1 , m2 , which are all preserved (ii), and two arcs h1 , h2 , which are deleted, and the righthand side (iii) spawns the static Tg -typed grammar Gq (i.e., a graph) with one additional arc l from m1 to m2 and type g. Assume the initial graph of Ga is a discrete graph G0 with one node k typed over a. The application of the production p (with the obvious matching from n1 to k) spawns a fresh instance G1p of G p : the type graph becomes Tg1 and the underlying graph becomes G1 ⊃ G0 with nodes k (typed a) and k1 (typed b1 ) connected by an arc h1 (typed f1 ). Moreover, a production q1 is now available beside p. A second application of p spawns another fresh instance G2p of G p : the type graph becomes Tg1 ∪ Tg2 and the underlying graph becomes G2 ⊃ G1 with a new node k2 and an arc h2 : k → k2 . Again, a production q2 is now available. Similarly, p can be applied again and again (see Figure 6). However, no suitable matching can ever be found for the application of q1 , q2 , etc. In fact, it is not possible to find two arcs with the same type, say fi , and the identification condition prevents a non-injective matching of the two arcs in the left-hand side of qi . Now compare Ga with its static, flattened Tg -typed version, where only two productions p and q are available at any time: after two derivation steps with p the underlying graph has two nodes typed over b and two arcs typed over f , and thus q can be applied!
Dynamic Graph Transformation Systems
n1 •
p:
←Tg
Ta
n1 •
,→
)•
f
n1 •
v
/ • d b
a
3
/ n•2
h
Pp = {q}
g
Fig. 1. A dynamic production p. • m1 rr8 r r r / • m2 m0 • r
• m1
h1
q:
h2
Tg
•O m1 l
m0 •
←-
'•
*&
f
a
• m2
* '/ • d b
,→
g
w
m0 •
• m2 Pq = 0/
Fig. 2. A static production q.
The difference lies in the separation principle that DynGGs imposes on items produced as freshly-typed instances by different applications of the same production. We shall reprise this example to show that incautious encodings of DynGGs intro GGs would introduce unwanted derivations. Synopsis. § 2 accounts for some basics of typed GGs [5]. The definition of DynGGs is original to this contribution and described in § 3, where DynGGs are shown to be a conservative extension of GGs. § 4 reports some sample encodings of other reflexive frameworks. The main result of the paper is in § 5, where it is shown that GGs have the same expressive power as DynGGs. Concluding remarks and future work are in § 6.
2
Typed Graph Grammars
A (directed) graph is a tuple G = hNG , EG , sG ,tG i, where NG is a set of nodes, EG is a set of edges (or arcs), and sG ,tG : EG → NG are the source and target functions. We shall omit subscripts when obvious from the context. A graph morphism f : G → G0 is a couple f = h fN : N → N 0 , fE : E → E 0 i such that: s0 ◦ fE = fN ◦ s and t 0 ◦ fE = fN ◦ t. Definition 2.1 (Typed Graph). Given a graph of types T , a T -typed graph is a pair h|G|, τG i, where |G| is the underlying graph and τG : |G| → T is a total morphism. In GGs the graph |G| defines the configuration of the system and its items (nodes and edges) model resources, while τG defines the typing of the resources. Hence, the underlying graph |G| evolves dynamically, while the type graph T is statically fixed and cannot change at run-time. For example, when encoding Petri nets in GGs the places form the discrete graph of types, while markings form the configurations of the system.
4
R. Bruni and H. Melgratti p: L o
l
m
(1)
Go
b
r
K
k
D
(2)
d
/R
T σ
h
/H
0
T
(a) A DPO direct derivation.
ι
/ T 00
ισ,T 00
ρσ,T 00
/ Tσ,T 00
(b) Standard type graph construction.
Fig. 3. DPO and type graph construction.
A morphism between T -typed graphs f : G1 → G2 is a graph morphisms f : |G1 | → |G2 | such that τG1 = τG2 ◦ f . The category of T -typed graphs and their morphisms is denoted by T -Graph. Since we work only with typed notions, we will usually omit the qualification “typed”, and we will not indicate explicitly the typing morphisms. The following notion of retyping will be used extensively in the context of DynGGs. Definition 2.2 (Graph Retyping). Given a T -typed graph G = h|G|, τG i and a morphism σ : T → T 0 we denote by σ · G the T 0 -typed graph σ · G = h|G|, σ ◦ τG i. The key notion to glue graphs together is that of a categorical pushout. Roughly, a pushout pastes two graphs by injecting them in a larger graph that is (isomorphic to) their disjoint union modulo the collapsing of some common part. We recall that a span is a pair (b, c) of morphisms b : A → B and c : A → C. A pushout of the span (b, c) is then an object D together with two (co-final) morphisms f : B → D and g : C → D such that: (i) f ◦ b = g ◦ c and (ii) for any other choice of f 0 : B → D0 and g0 : C → D0 s.t. f 0 ◦ b = g0 ◦ c there is a unique d : D → D0 s.t. f 0 = d ◦ f and g0 = d ◦ g. If the pushout is defined, then c and g is called the pushout complement of hb, f i. l
r
A (T -typed graph) DPO production p : (L ← K → R) is a span of injective graph morphisms l : K → L and r : K → R. The T -typed graphs L, K, and R are called the left-hand side, the interface, and the right-hand side of the production, respectively. Definition 2.3 (DPO graph grammar). A (T -typed) DPO graph grammar G is a tuple hT, Gin , Pi, where Gin is the initial (T -typed) graph, P is a set of DPO productions. l
r
Given a graph G, a production p : (L ← K → R), and a match m : L → G, a direct derivation δ from G to H using p (based on m) exists, written δ : G ⇒ p H, if and only if the diagram in Figure 3(a) can be constructed, where both squares are pushouts in T -Graph: (1) the rewriting step removes from the graph G the items m(L − l(K)), yielding the graph D (with k, b as a pushout complement of hm, li); (2) then, fresh copies of the items in R − r(K) are added to D yielding H (as a pushout of (k, r)). The interface K specifies both what is preserved and how fresh items must be glued to the existing part. The existence of the pushout complement of hm, li is subject to the satisfaction of the following gluing conditions [4]: – identification condition: ∀x, y ∈ L if x 6= y and m(x) = m(y) then x, y ∈ l(K); – dangling condition: no arc in G \ m(L) should be incident to a node in m(L \ l(K)).
Dynamic Graph Transformation Systems
5
The identification condition is satisfied by valid matches: a match is not valid if it requires a single item to be consumed twice, or to be both consumed and preserved. A derivation is a sequence γ = {δi : Gi−1 ⇒ pi−1 Gi }i∈{1,...,n} of direct derivations.
3
Dynamic Graph Grammars l
r
As aforementioned, a T -typed dynamic production takes the form: p : (LT ← KT → GT 0 ) where GT 0 is a suitable (T 0 -typed) dynamic graph grammar. A dynamic graph grammar can contain any number of such productions. Formally: Definition 3.1 (Dynamic Graph Grammars). The domain of dynamic graph grammars can be expressed as the least set DGG satisfying the equation: D = {(T, Gin , P) | Gin ∈ GraphT ∧ l
r
∀p : (LT ← KT → GTp ) ∈ P.( LT , KT ∈ GraphT ∧ T ⊂ Tp ∧ GTp = (Tp , GTp , Pp ) ∈ D ) } where GraphT is the set of T -typed graphs and r : ι · KT → GTp is a morphism between Tp -typed graphs, where ι : T ,→ Tp denotes the obvious sub-graph injection. Any element G = (T, Gin , P) ∈ DGG is called a Dynamic Graph Grammar. It is static l
r
/ It is shallow if T = Tp and GTp is static for all p : (LT ← KT → GTp ) ∈ P. if P = 0. Note that all Dynamic Graph Grammars are well-founded: since we take DGG as the least set satisfying the recursive domain equation above, the type graphs syntactically appearing in G = (T, Gin , P) ∈ DGG form a finite tree T(G) rooted in T , with parent relation given by immediate subsetting (i.e., Ti is parent of T j iff Ti ⊂ T j and no Tk appears in G such that Ti ⊂ Tk ⊂ T j ) and where leaves are associated with static grammars. We remark that each type graph Tp ⊃ T extends T with local declarations Tp \ T , whose scope is bounded by the specific production p. For simplicity, but without loss of generality, we assume that all additional items introduced by different type graphs inside G are namedSdifferently (i.e., each additional item occurs only in one type graph). We let T(G) = Ti ∈T(G) Ti denote the overall flat type graph of G, and let ιTi : Ti ,→ T(G) denote the obvious sub-graph inclusion. Note that, by the structuring of T(G), the type graph T(G) is just the union of all the leaves of T(G). Similarly, all nested productions in G form the tree P(G) rooted in P with parent relation given by immediate inclusion (i.e., the set of productions Pi is the parl r ent of Pp iff p : (LT ← KT → (Tp , GTp , Pp )) ∈ Pi ). Given a T -typed dynamic producl
r
tion p : (LT ← KT → GTp ) with GTp = (Tp , GTp , Pp ) we say that the ordinary T(G)l
r
typed production flat(p) : (ιT · LT ← ιT · KT → ιTp · GTp ) is the flattening of p. We let S P(G) = Pi ∈P(G) {flat(p) | p ∈ Pi } denote the overall set of flat productions of G. The T(G)-typed shallow grammar F(G) = (T(G), ιT · Gin , P(G)) is called the flattening of G. To define the dynamics of DynGGs we need a more advanced notion of retyping, which can be used to generate fresh items in the type graph. In the following, when considering type graph constructions, we assume that a standard choice of pushout objects
6
R. Bruni and H. Melgratti G0p = ρT,Tp · GTp = (TT,Tp , G0p , P0 ) ιT,Tp · p : LT o
" m
≡ KT o_ _ _ _ _ _/ K 0
l
T
}
ιp
ιT,Tp
Gin o
{ / TT,Tp i d
k0
h
_ _ _/ D0 D o_ _ _ _ ≡
b
/ G0p
/ Tp k ρT,Tp
idT