Fundamenta Informaticae XXI (2001) 1001–1032 1001 IOS Press Lazy Graph Transformation Fernando Orejas∗ Universitat Politècnica de Catalunya, Spain [email protected] Leen Lambers† Hasso Plattner Institut, Universität Potsdam, Germany [email protected] Abstract. Applying an attributed graph transformation rule to a given object graph always implies some kind of constraint solving. In many cases, the given constraints are almost trivial to solve. For instance, this is the case when a rule describes a transformation G ⇒ H, where the attributes of H are obtained by some simple computation from the attributes of G. However there are many other cases where the constraints to solve may be not so trivial and, moreover, may have several answers. This is the case, for instance, when the transformation process includes some kind of searching. In the current approaches to attributed graph transformation these constraints must be completely solved when defining the matching of the given transformation rule. This kind of early binding is well-known from other areas of Computer Science to be inadequate. For instance, the solution chosen for the constraints associated to a given transformation step may be not fully adequate, meaning that later, in the search for a better solution, we may need to backtrack this transformation step. In this paper, based on our previous work on the use of symbolic graphs to deal with different aspects related with attributed graphs, including attributed graph transformation, we present a new approach that, based on the new notion of narrowing graph transformation rule, allows us to delay constraint solving when doing attributed graph transformation, in a way that resembles lazy computation. For this reason, we have called lazy this new kind of transformation. Moreover, we show that the approach is sound and complete with respect to standard attributed graph transformation. A running example, where a graph transformation system describes some basic operations of a travel agency, shows the practical interest of the approach. Address for correspondence: Fernando Orejas, Departament de Llenguatges i Sistemes Informàtics, Universitat Politècnica de Catalunya, 08034 Barcelona, Spain ∗ The work of this author was partially supported by the MEC project FORMALISM (ref. TIN2007-66523) and by the AGAUR grant to the research group ALBCOM (ref. 00516). † The work of this author was partially funded by the Deutsche Forschungsgemeinschaft in the course of the project - Correct Model Transformations - see http://www.hpi.uni-potsdam.de/giese/projekte/kormoran.html?L=1. 1002 Orejas, Lambers / Symbolic Graph Transformation Keywords: Attributed graph transformation, symbolic graph transformation, lazy transformation 1. Introduction Attributed graphs and attributed graph transformation play a significant role in most applications of graph transformation. In practice, an attributed graph transformation rule is like a normal rule, but some nodes or edges are labelled by expressions over some given variables. Then, defining a match m of a rule to a given object graph, whose attributes are some concrete values, means finding the values that must be assigned to the variables occurring in the rule, so that the value of each expression associated to each node or edge e on the left-hand side of the rule coincides with the value of the corresponding attribute associated to m(e) in the object graph. That is, defining a match of a rule means solving a set of constraints. In many cases, these constraints are trivial. For instance, when a rule describes a transformation G ⇒ H, where the attributes in H are obtained by some simple computation from the attributes in G, e.g. when the expressions used as attributes in the left-hand side of the rules are just variables, and more general expressions, defined over these variables, only occur in the right-hand side. However there are many other cases where the constraints to solve may be not so trivial and, moreover, may have several answers. For instance, when the transformation process includes some kind of searching (e.g. when the right-hand side of a rule involves a variable which does not occur explicitly on the left-hand side). In existing approaches to attributed graph transformation these constraints must be completely solved when defining the matching of the given transformation rule. Then, finding a match means choosing one specific solution. This kind of early binding is well-known from other areas of Computer Science to be inadequate. One problem is that the solution chosen for the constraints associated to a given transformation step may not be fully adequate, meaning that we may need to backtrack this transformation step. The approach taken in areas like Constraint Logic Programming [9], by which our approach is inspired, is to postpone solving the constraints as much as possible, checking meanwhile their satisfiability. Then, not only may we avoid some useless backtracking, but we have other advantages. On the one hand, checking satisfiability may be computationally simpler than solving a set of constraints, meaning that it may also be simpler to apply a transformation step. On the other hand, some constraints which may be difficult to solve at a given moment, may become simpler, even trivial, because of the interaction with constraints defined by later steps. In [12], when studying the problem of defining graph constraints over attributed graphs, we saw that the existing approaches [10, 1, 7, 5, 16] were not fully adequate for our purposes. These approaches presented different kinds of technical difficulties together with a limited expressive power for defining conditions on the attributes. To avoid these problems we presented a new formal approach which (we believe) is conceptually simpler and more powerful than existing approaches. It is simple because, in our approach, attributed graphs are not defined as some kind of combination of a graph and an algebra, as in [10, 1, 7, 5], nor do we have to establish a difference between transformation rules and rule schemata, as in [16]. At the same time, our approach is expressively more powerful, not only because we can define graph constraints with arbitrary conditions on the attributes as we aimed, but also because we can define transformation rules that cannot be defined in other approaches, as shown in [14]. Graphs in our approach are called symbolic graphs, because the attributes in the graph are represented symbolically by variables whose possible values are specified by a set of formulas. However, in this paper, we show that symbolic transformation rules, and the corresponding notion of Orejas, Lambers / Symbolic Graph Transformation 1003 symbolic graph transformation, as defined in [14], are too restrictive for the transformation of arbitrary symbolic graphs. As a consequence, we introduce a more general notion of symbolic graph transformation rules, which we have called narrowing rules, and characterize graph transformation by means of these rules. In addition, we study the compatibility of symbolic graph transformation with the semantics of symbolic graphs1 , showing that this kind of transformation is compatible with the semantics of graphs, but not in a strong sense. Hence, we introduce a variant of symbolic graph transformation, which we have called, narrowing graph transformation, proving that it is strongly compatible with respect to the semantics of graphs. Finally, using the notion of narrowing graph transformation, we present a new approach to symbolic graph transformation that allows us to delay constraint solving when doing attributed graph transformation. In particular we show that this new approach is sound and complete with respect to standard attributed graph transformation, and it is complete and satisfies a property of extended soundness with respect to symbolic graph transformation. Moreover, a running example, where a graph transformation system describes some basic operations of a travel agency, shows the practical interest of the approach. The paper is organized as follows. In Section 2 we recapitulate some notions that are used in the rest of the paper. In Section 3 we present the category and the semantics of symbolic graphs. Section 4 is dedicated to describe how (standard) symbolic graph transformation works. In Section 5 we present the new notions of narrowing rules and narrowing graph transformation studying its compatibility with respect to the semantics of symbolic graphs. Section 6 is dedicated to the new notion of lazy transformation and to prove its soundness and completeness. Finally, in Section 6, we compare our approach with other related work and we draw some conclusions. This paper is an extended version of [15], presented at ICGT 2010. In particular, in addition to the detailed proofs of our results, we introduce the new notion of narrowing rules and narrowing transformation, presenting lazy transformation as a specific instance of narrowing transformation. 2. Preliminaries We assume that the reader has a basic knowledge on algebraic specification and on graph transformation. For instance, we advise to look at [6] for more detail on algebraic specification or at [3] for more detail on graph transformation. 2.1. Basic algebraic concepts and notation A signature Σ = (S, Ω) consists of a set of sorts S, and Ω is a family of operation and predicate symbols typed over these sorts. A Σ-algebra A consists of an S-indexed family of sets {As }s∈S and a function opA (resp. a relation prA ) for each operation op (resp. each predicate pr) in the signature. A Σ-homomorphism h : A → A0 consists of an S-indexed family of functions {hs : As → A0s }s∈S commuting with the operations and preserving the relations. Given a signature Σ, we denote by TΣ the term algebra, consisting of all the possible Σ-(ground) terms. Given any Σ-algebra A there is a unique homomorphism hA : TΣ → A. In particular, hA yields the value of each term in A. Similarly, TΣ (X) denotes the algebra of all Σ-terms with variables in X, and given a variable assignment σ : X → A, this assignment extends to a unique homomorphism 1 This notion is defined in Section 5. 1004 Orejas, Lambers / Symbolic Graph Transformation σ # : TΣ (X) → A yielding the value of each term after the replacement of each variable x by its value σ(x). In particular, when an assignment is defined over the term algebra, i.e. σ : X → TΣ , then σ # (t) denotes the term obtained by substituting each variable x in t by the term σ(x). However, for simplicity, even if it is an abuse of notation, we will write σ(t) instead of σ # (t). 2.2. E-graphs and Attributed Graphs E-graphs are introduced in [3] as a first step to define attributed graphs. An E-graph is a kind of labelled graph, where nodes and edges may be decorated with labels from a given set. The difference with labelled graphs, as commonly understood, is that in labelled graphs it is usually assumed that each node or edge is labelled with a given number of labels, which is fixed a priori. In the case of E-graphs, each node or edge may have any arbitrary (finite) number of labels, which is not fixed a priori. Actually, in the context of graph transformation, the application of a rule may change the number of labels of a node or of an edge. Formally, in E-graphs labels are considered as a special class of nodes and the labeling relation between a node or an edge and a given label is represented by a special kind of edge. For instance, this means that the labeling of an edge is represented by an edge whose source is an edge and whose target is a label. Definition 2.1. (E-Graphs and morphisms) N L , E EL , s , sN L , sEL , t , tN L , tEL ) An E-graph over the set of labels XG is a tuple G = (VG , XG , EG , EG G G G G G G G consisting of: • VG and XG , the sets of graph nodes and of label nodes, respectively. N L , and E EL , the sets of graph edges, node label edges, and edge label edges, respectively. • EG , EG G and the source and target functions: • sG : EG → VG and tG : EG → VG L NL NL NL • sN G : EG → VG and tG : EG → XG EL EL • sEL G : EG → EG and tEL : EG → XG An E-graph is linear if every label x is attached to at most one node or one edge, i.e. there is at most one (node or edge) label edge e such that x = tjG (e), where j ∈ {N L, EL}. Given the E-graphs G and G0 , an E-graph morphism f : G → G 0 is a tuple, hfV : VG → VG0 , fX : 0 ,f NL 0N L EL 0EL XG → XG0 , fE : EG → EG EN L : EG → EG , fEEL : EG → EG i such that f commutes with all the source and target functions. E-graphs and E-graph morphisms form the category E − Graphs. The following constructions on E-graphs are needed in the sections below. The first one tells us how to replace the labels of an E-graph, and is used to define the semantics of a symbolic graph (cf. Definition 3.3): Orejas, Lambers / Symbolic Graph Transformation 1005 Definition 2.2. (Label substitution) N L , E EL , s , sN L , sEL , t , tN L , tEL ), a set of labels X’, and Given an E-graph G = (VG , XG , EG , EG G G G G G G G a function h : XG → X 0 we define the graph resulting from the substitution of XG along h, h(G) = 0 , E 0N L , E 0EL , s , s0 N L , s0 EL , t0 , t0 N L , t0 EL ), where: (VG0 , X 0 , EG G G G G G G G G 0 = E , E 0N L = E N L , E 0EL = E EL , s0 = s , s0 N L = sN L , s0 EL = sEL , and • VG0 = VG , EG G G G G G G G G G G G t0G = tG 0N L : t0N L (e) = h(tN L (e)) • For every e ∈ EG G G 0EL : t0EL (e) = h(tEL (e)) • For every e ∈ EG G G Moreover, h induces the definition of the morphism h : G → h(G), with h = hidV , h, idEG , idEN L , idEEL i. Notice that if f : G → H is a morphism such that fV , fE , fEN L , and fEEL are bijections, then we can consider that f is induced by the label substitution fX (up to isomorphism). We have used the same notation for the morphism associated to a label substitution and the given substitution. This is obviously an abuse of notation, but we believe that it introduces no confusion while it simplifies notation. Reach(G) eliminates all the labels in an E-graph which are not bound to a node or an edge and Restr(G, Y ) eliminates all the labels which are not in Y , assuming that Y includes all reachable labels (and, perhaps, some unreachable ones). These constructions are used to define lazy graph transformation (cf. Definition 6.1). Definition 2.3. (Reachable subgraph and restriction subgraph) Given an E-graph G = (VG , XG , EG , EN L , EEL , {sj , tj }j∈{G,N L,EL} ), we define the reachable subgraph of G, Reach(G) as the largest subgraph of G where XReach(G) consists of all labels x such that: • There is a node label edge nl ∈ EN L such that x = tN L (nl), or • there is an edge label edge el ∈ EEL such that x = tEL (el). Moreover, given a morphism f : G → G 0 we denote by Reach(f ) : Reach(G) → G0 the restriction of f to the subgraph Reach(G). Similarly, we define the restriction of G to a set of labels Y , Restr(G, Y ), where XReach(G) ⊆ Y as the largest subgraph of G where XRestr(G,Y ) = Y . Finally, let us define attributed graphs as presented in [3]. In particular, an attributed graph is an E-graph whose labels are the values of a given data algebra that is assumed to be included in the graph. Definition 2.4. (Attributed graphs and morphisms) An attributed graph over Σ is a pair hG, Di, where D is a given Σ-algebra, called the data algebra of the graph, U and G is an E-graph such that the set XG of labels in G U consists of all the values in D, i.e. XG = s∈S Ds , where s is the set of sorts of the data algebra and denotes disjoint union. Given the attributed graphs over Σ AG = hG, Di and AG0 = hG0 , D0 i, an attributed graph morphism h : AG → AG0 is a pair hhgraph , halg i, where hgraph is an E-graph morphism, hgraph : G → G0 and halg is a Σ-homomorphism, halg : D → D0 such that the values in D are mapped consistently by hgraph and halg , i.e. for each sort s ∈ S the diagram below commutes: 1006 Orejas, Lambers / Symbolic Graph Transformation Ds _ halg / D0 s _ XG hgraph / XG0 Attributed graphs and attributed graph morphisms form the category AttGraphs. 3. Symbolic graphs In this section, we provide a small introduction to symbolic graphs. In particular, in the first subsection, we introduce the category of this kind of graphs and describe some results that can be found in [14]. Then, in the second subsection, we study the semantics of symbolic graphs presenting some new technical results which are used in the rest of the paper. 3.1. The category of symbolic graphs If we consider that an attributed graph is like an E-graph whose labels are values over a given data algebra, a symbolic graph can be seen as the specification of a class of attributed graphs. In particular, a symbolic graph consists of an E-graph G whose labels are variables, together with a set of formulas Φ that constrain the possible values of these variables. We consider that a symbolic graph denotes the class of all attributed graphs where the variables in the E-graph have been replaced by values that make Φ true in the given data domain. For instance, the symbolic graph in Figure 1 specifies a class of attributed graphs, including distances in the edges, that satisfy the well-known triangle inequality. We must note that the graph in this figure is not really an E-graph, but a user-friendly representation of an E-graph. In particular, we have not depicted the edge label edges that would bind the labels d1 , d2 and d3 to the corresponding graph edges. Actually, in the rest of the paper we will always omit depicting (node or edge) label edges, since we think that the resulting graphs are more intuitive. d3 d1 d2 with d3 ! d1+d2 Figure 1. A symbolic graph Definition 3.1. (Symbolic graphs and morphisms) A symbolic graph SG over the data Σ-algebra D, with Σ = (S, Ω), is a pair SG = hG, Φi, where G is an E-graph over an S-sorted set of variables, used as labels, X = {Xs }s∈S , i.e. XG = ∪s∈S Xs , and Φ is a set of first-order Σ-formulas with free variables in X and including elements in D as constants. -1- 1007 Orejas, Lambers / Symbolic Graph Transformation Given symbolic graphs hG1 , Φ1 i and hG2 , Φ2 i over D, a symbolic graph morphism h : hG1 , Φ1 i → hG2 , Φ2 i is an E-graph morphism h : G1 → G2 such that D |= Φ2 ⇒ h(Φ1 ), where h(Φ1 ) is the set of formulas obtained when replacing in Φ1 every variable x1 in the set of labels of G1 by hX (x1 ). Symbolic graphs over D together with their morphisms form the category SymbGraphsD . As said in the definition, we consider that Φ is a set of arbitrary first-order Σ-formulas. However, for practical purposes, we may want to restrict the class of formulas that can occur in this set, since first-order formula satisfiability is an undecidable problem. In principle, the only condition that we need to ensure that the results presented in this paper hold is that the given class of formulas is closed under conjunction, disjunction and existential quantification, because these are the connectives needed to ensure the existence of pushouts and pullbacks in the category of symbolic graphs, as proved in [14]. Remark 3.1. (Symbolic typed graphs) Even if along the paper, for simplicity, we have only considered untyped graphs, in our running example (see Example 3.3) we consider that our graphs are typed. We can easily extend all our theory to the case of typed graphs using the standard technique. In particular, we just have to see typed graphs as morphisms SG → T G, where SG is a symbolic graph and T G is the given type graph, which is a specific symbolic graph (i.e. the category of typed symbolic graphs over the type graph T G is the slice category over T G). In particular, type graphs T G must be symbolic graphs T G = hET G, Falsei, where ET G is an E-graph over a set of labels XET G consisting of just one variable for each sort in the given data signature, and False is the set consisting just of the f alse formula. In this way, given a symbolic graph SG = hG, Φi, any (typing) morphism t : G → ET G for G is also a (typing) morphism t : SG → T G. In [14], we showed that symbolic graphs are an adhesive HLR category taking as M-morphisms all injective graph morphisms where the formulas constraining the source and target graphs are equivalent (in most cases they will just be the same formula). Definition 3.2. (M-morphisms) An M-morphism h : hG, Φi → hG0 , Φ0 i is a monomorphism such that XG ∼ = XG0 , i.e. hX is a bijection, 0 and D |= h(Φ) ⇔ Φ We will not study in detail all the constructions and results that are needed to prove that SymbGraphsD is an adhesive HLR category (the interested reader is addressed to [14]). However, it is important to see how pushouts work in order to understand symbolic graph transformation: Proposition 3.1. [14] Diagram (1) below is a pushout if and only if diagram (2) is a pushout in E − Graphs and D |= Φ3 ⇔ (g1 (Φ1 ) ∪ g2 (Φ2 )). hG0 , Φ0 i h2 hG2 , Φ2 i h1 (1) g2 / hG1 , Φ1 i g1 / hG3 , Φ3 i Therefore, as said above, we have: Theorem 3.1. [14] SymbGraphsD is adhesive HLR. G0 h2 G2 h1 (2) g2 / G1 g1 / G3 1008 Orejas, Lambers / Symbolic Graph Transformation One may wonder whether SymbGraphsD is an adhesive category, in particular if it is adhesive HLR when M-morphisms are just monomorphisms. The answer is no, as it can be seen from the counterexample below: Example 3.1. Let us consider the diagram below, where all the arrows are the identity graph morphism. Then, it is easy to see that the bottom diagram is a pushout in SymbGraphsD , but it is not a van Kampen square [11]. hG, {true}i hG, {true}i ' s hG, {false}i ' s hG, {false}i hG, {false}i hG, {true}i ' s hG, {false}i ' hG, {false}i s In particular, we may easily check that all the morphisms in the diagram are monomorphisms in SymbGraphsD . Moreover, we can also check easily that the top and bottom squares are pushouts and the back squares are pullbacks2 . However the front-left square is not a pullback. In particular, true 6= false ∨ false. Moreover, we may see that, in general, for diagrams along monomorphisms, pushout complements are not unique as the following counterexample shows: Example 3.2. Let us consider the morphisms f : hG, {true}i → hG, {false}i and g : hG, {false}i → hG, {false}i, where both morphisms are identities as E-graph morphisms, then it is easy to see that the diagrams below are pushouts: hG, {true}i hG, {false}i 3.2. f (1) / hG, {false}i hG, {true}i g / hG, {false}i hG, {true}i f (2) / hG, {false}i g / hG, {false}i Semantics of symbolic graphs As we said above, we may consider that a symbolic graph SG denotes a class of attributed graphs. In particular the class of all attributed graphs that can be obtained by replacing the variables in SG by values 2 If the given formulas do not include variables, pullbacks in SymbGraphsD are defined in terms of pullbacks in E − Graphs, where the associated formula of the resulting graph is the disjunction of the formulas of the graphs involved. 1009 Orejas, Lambers / Symbolic Graph Transformation in the given data algebra, so that the associated condition becomes true in the algebra: Definition 3.3. (Semantics of symbolic graphs) The semantics of a symbolic graph hG, Φi over a data algebra D is a class of attributed graphs defined: Sem(hG, Φi) = {hσ(G), Di | σ : XG → D and D |= σ(Φ)} where σ(G) denotes the graph obtained according to Def. 2.2. We may notice that the class of attributed graphs denoted by a symbolic graph may be empty if the associated condition is unsatisfiable. Every attributed graph may be seen as a symbolic graph by just replacing all its values by variables and by including an equation xv = v, for each value v in the data algebra, into the corresponding set of formulas, where xv is the variable that has replaced the value v. We call these kind of symbolic graphs grounded symbolic graphs. For instance, in Figure 2, on the right, we can see the symbolic representation of the attributed graph on the left. However, to enhance readability, in our figures we will often show values of the given data algebra as attributes of the given graph, instead of replacing them by variables and showing the corresponding equation. This is done, for instance, in Example 3.3, where a grounded symbolic graph is displayed as an attributed graph. 18 d3 15 12 d2 d1 with d1= 12, d2= 15, d3= 18 Figure 2. Attributed graph and grounded symbolic graph Definition 3.4. (Grounded symbolic graphs) A symbolic graph hG, Φi over a data algebra D is grounded if -11. XG includes a variable, which we denote by xv , for each value v ∈ D, and 2. For every substitution σ : XG → D, such that D |= σ(Φ), we have σ(xv ) = v, for each variable xv ∈ XG . Moreover, we define GSymbGraphsD as the full subcategory of SymbGraphsD consisting of all grounded graphs. 1010 Orejas, Lambers / Symbolic Graph Transformation It should be obvious that the semantics of a grounded graph includes exactly one attributed graph, and that grounded graphs are closed up to isomorphism. Moreover, in [14] we can see that for every attributed graph AG there is a unique grounded symbolic graph (up to isomorphism) GSG(AG) such that Sem(GSG(AG)) consists of AG. In particular, the E-graph associated to GSG(AG) is obtained substituting every data value v in a set of labels by a variable xv , and the set of formulas in the symbolic graph consists of an equation xv = v, for each value v in D. In [14] we also showed that, given a data algebra D, the category of attributed graphs over D, as presented in [3], and the subcategory of grounded symbolic graphs over D are equivalent, provided that the given data algebra is finitely generated. As a consequence, we may identify them. For instance, we may consider that the semantics of a symbolic graph is a class of grounded symbolic graphs. We may notice that, if h : SG → SG0 is a symbolic graph morphism and SG0 is grounded then the condition D |= Φ0 ⇒ h(Φ), that the symbolic morphism h must satisfy, can be represented as a constraint satisfaction problem: Fact 3.1. Given a symbolic graph SG = hG, Φi and a grounded symbolic graph SG0 = hG0 , Φ0 i, an E-graph morphism h : G → G0 is a symbolic graph morphism if and only if D |= h0 (Φ), where h0 : XG → D is the mapping defined ∀x ∈ XG : h0 (x) = v if h(x) = xv . Proof: By definition, we know that h is a symbolic graph morphism if and only if D |= Φ0 ⇒ h(Φ). This is equivalent to showing that, for every substitution σ, if D |= σ(Φ0 ) then D |= σ(h(Φ)). Now, Φ0 consists of all the equations xv = v, therefore the only substitution σ such that D |= σ(Φ0 ) is σ(xv ) = v. But for every variable x in XG , h0 (x) = σ ◦ h(x). Therefore, this is equivalent to D |= h0 (Φ). t u The above fact means that defining a morphism from SG = hG, Φi into a grounded symbolic graph can be seen partially as a constraint satisfaction problem. In particular, the morphism must provide values to the variables in Φ so that the conditions (constraints) in Φ are satisfied. For instance, in Example 4.2 we see an object graph that represents a customer of a travel agency that wants to make a hotel reservation for two days in Berlin and has a certain budget. Then, in that example, applying a transformation rule that is supposed to implement this reservation (i.e. defining the match morphism) implies finding a hotel a to be bound to a variable h of sort hotel that satisfies two conditions: that a is located in Berlin and that its price for two nights is cheaper than the given budget. Let us now show two facts that are needed in the rest of the paper. The first one shows that for any symbolic graph SG and the grounded representation of any attributed graph AG in the semantics of SG there exists a symbolic morphism between SG and GSG(AG), which is induced by a label substitution. Fact 3.2. An attributed graph AG = hG, Di is in the semantics of SG = hG0 , Φi if and only if there is a symbolic graph morphism h : SG → GSG(AG) induced by a label substitution. Proof: If AG ∈ Sem(SG) this means that G = σ(G0 ) for a given variable substitution σ such that D |= σ(Φ). But this means that we may define h as the morphism associated to σ 0 ◦ σ, where σ 0 is the substitution that maps every value v ∈ D to the variable xv . In addition, D |= σ(Φ) implies, by Fact 3.1, that h is a symbolic graph morphism. Conversely, if there is a symbolic morphism h : SG → GSG(AG) induced by a given label substitution, we can define an assignment σ : XG0 → D with σ(x) = v if h(x) = x0 Orejas, Lambers / Symbolic Graph Transformation 1011 and the equation x0 = v is in ΦGSG(AG) . Then, by Fact 3.1, we know that D |= σ(Φ) implying that the attributed graph hσ(G0 ), Di is in Sem(SG). t u The second fact states that, if AG is in the semantics of SG0 and the variables in SG are a subset of the variables of SG0 then any morphism f from a symbolic graph SG to GSG(AG) can be factorized into two morphisms f 0 : SG → SG0 and h : SG0 → GSG(AG), where h is the morphism defined in the previous fact. Fact 3.3. Given symbolic graphs SG = hG, Φi and SG0 = hG0 , Φ0 i, such that G is linear (cf. Definition 2.1), and given a morphism f : SG → GSG(AG), where AG ∈ Sem(SG0 ), there is an E-graph morphism f 0 : SG → SG0 such that f = h ◦ f 0 , where h : SG0 → GSG(AG) is the morphism defined in Fact 3.2. Proof: It is enough to define f 0 as follows: • For every graph node or edge e, f 0 (e) = h−1 (f (e)). • For every label x ∈ XG , f 0 (x) = x0 , if x is the target in G of some node label edge or of some edge label edge e (i.e. x is attached to a node or an edge via e) and the target of f 0 (e) in G0 is x0 . • For every label x ∈ XG , f 0 (x) = x0 ,if x is not attached to any node or edge in G and x0 is any label in G0 such that f (x) = h(x0 ). It is routine to check that f 0 is an E-morphism because, on the one hand, if h is the morphism induced by a label substitution, h is a bijection on graph nodes and edges, and on the other hand, G is linear, which means that the definition of f 0 on the labels is correct. Moreover, by definition f = h ◦ f 0 . t u Example 3.3. (Introduction to Running Example) In our running example we specify a travel agency in terms of typed symbolic graphs and symbolic graph transformation rules. In particular, the data signature of our example is: Sorts int, bool, city, hotel, flight Opns price : hotel → int location : hotel → city price : flight → int departure : flight → city destination : flight → city and the data algebra, depicted by means of two tables in Figure 3. The type graph, depicted in Figure 4, consists of a Customer that can request a hotel reservation HotelRequest or a flight reservation FlightRequest. These requests can be responded by a FlightReservation or a HotelReservation, respectively. A Customer has the labels name and bud, describing the total budget that the customer is willing to spend for his reservations. A HotelRequest has as labels the number of nights and loc, describing the city where the hotel is located. A FlightRequest has as labels 1012 Orejas, Lambers / Symbolic Graph Transformation hotel price city h1 h2 h3 h4 h5 100 90 85 70 200 München Berlin Berlin Köln Berlin flight price departure destination f1 f2 f3 f4 175 115 150 85 Berlin Berlin Barcelona Barcelona Barcelona Barcelona Berlin Berlin «uses» book flight «uses» book travel book hotel Figure 3. A data algebra «uses» book transfer Traveler Customer -name : string -bud : int int, bool, city, hote price:hotel->int location: hotel -> price:flight->int departure: flight destination: flight FlightRequest HotelRequest -dep : city -dest : city -loc : city -nights : int HotelReservation FlightReservation -h : hotel -f : flight Figure 4. Type graph fr : the FlightRequest reserveFlight fr : FlightRequest dep and dest, the departure and destination city of flight, respectively. The HotelReservation and dep : city dep : city FlightReservation have only one label h and f for the hotel and flight that are reserved, respectively. dest : city dest : city : FlightRe f : flight Finally, a possible start graph describing the needs of a customer called Alice is depicted in Figure 3 and shows a customer with a budget of 450, c : Customer 5. In particular, this graph is assumed to be grounded c : Customer name string requesting a hotel for two nights in Berlin, a flight from :Barcelona to Berlin and a flightname from: string Berlin to bud : int bud : int Barcelona. dep = departure(f) && dest = destination(f) && bud’ = bud - price(f) && 3 As explained above, for readability, it is depicted as an attributed graph hr : HotelRequest loc : city nights : int c : Customer reserveHotel hr : HotelRequest loc : city nights : int : HotelRese h : hotel 0,-./1*8*,0/ 0,-./1*8*,0/ 9*8*?31/(;%" .*8*.(/%& 9*8*?31/(;%" 0#;%*8*1/",0'36*8*,0/ 0#;%*8*1/",0'36@*8*,0/ 815$%$815&(/10*9,$--$2)!3$%$2)!$: *#'/5"*9,$;$0/<9(.,$--$2)!36%7 Orejas, Lambers / Symbolic Graph Transformation 1/#"/*-"#7.8 8*A(/%&=%>3%1/ 8*<&,-./=%>3%1/ &(9*8*9,/:*D*E%"&,0 0,-./1*8*,0/*D*F 6%7*8*9,/:*D*E#"9%&(0# 6%1/*8*9,/:*D*E%"&,0 8*?31/(;%" 8*<&,-./=%>3%1/ 0#;%*8*1/",0-*D*G&,9% '36*8*,0/*D*HIJ 6%7*8*9,/:*D*E%"&,0 6%1/*8*9,/:*D*E#"9%&(0# Figure 5. 4. 1013 Start graph Symbolic graph transformation for attributed graph transformation In the previous section we have seen that the category of symbolic graphs is adhesive HLR. Hence, following [3], we can define a first notion of symbolic graph transformation using spans of M-morphisms. This is equivalent to consider that the left and right-hand sides (and also the interface) of a rule are constrained by the same set of formulas. This means that we may denote symbolic graph transformation rules as pairs hL ←- K ,→ R, Φi, where L, K and R are E-graphs over the same set of labels X and Φ is a set of formulas over X and over the values in D. Intuitively, Φ relates the attributes in the left and right-hand sides of the rule and it may also impose some constraints on the matchings. Moreover, for technical reasons we require that L is linear (cf. Definition 2.1), meaning that no label is bound to two different elements in L4 . Definition 4.1. (Symbolic graph transformation rule) A symbolic graph transformation rule is a pair hL ←- K ,→ R, Φi, where L, K, R are E-graphs over the same set of labels X, L is linear, L ←- K ,→ R is a span of E-graph inclusions5 , and Φ is a set of formulas over X and over the values in the given data algebra D. Example 4.1. (Symbolic graph transformation rules) In Figure 6 we can see the rules that describe some operations of the travel agency of our example. In particular, rule reserveFlight connects a FlightReservation with a FlightRequest for some Customer. Identical names in rules specify that the corresponding nodes are preserved. Edges between nodes with identical names are preserved as well. The rule includes a formula Φ, expressing that the departure city dep and destination city dest of the FlightRequest should be equal to the departure city departure(f) and destination city destination(f) of the reserved flight f, respectively. Moreover the total budget bud of the customer is diminished by the price of the reserved flight price(f) and as an extra constraint it is required that the new budget bud’ is still greater than or equal to zero. The rule reserveHotel connects a HotelReservation with a HotelRequest for some Customer. It holds a formula Φ, expressing that the location loc of the HotelRequest should be identical to the location of the reserved hotel location(h). The total budget bud of the customer is diminished by the price of the reserved hotel multiplied with the 4 If needed we can transform SL into an equivalent linear graph (with the same semantics). We just need to change the repeated occurrences of the same variable by new variables and add the corresponding equalities to the given set of formulas. 5 or, in general, monomorphisms Customer flight -name : string -bud : int int, bool, city, hotel, flight price:hotel->int location: hotel -> city -dep : city price:flight->int -dest : city departure: flight -> city Orejas, Lambers / Symbolic Graph Transformation destination: flight -> city -price : string -source -destination FlightRequest HotelRequest -loc : city -nights : int 1014 HotelReservation hotel -price : string -location FlightReservation city number -h : hotel of nights price(h)*nights and as an extra constraint it is required again that the new budget bud’ -f : flight is still greater than or equal to zero. Notice that the fact that these rules are spans of M-morphisms implies that the variable f in the first Customer rule must be considered to be included in the left-hand side of the rule, even if it is not bound to any node -name : string or edge of the left-hand side graph. The same happens with the variable h in the second rule, as well-bud' as : int with bud’ in both rules. fr : FlightRequest reserveFlight dep : city dest : city fr : FlightRequest : FlightReservation dep : city dest : city f : flight c : Customer c : Customer name : string bud : int name : string bud' : int dep = departure(f) && dest = destination(f) && bud’ = bud - price(f) && bud’ >=0 hr : HotelRequest reserveHotel loc : city nights : int hr : HotelRequest : HotelReservation loc : city nights : int h : hotel c : Customer c : Customer name : string bud : int name : string bud' : int loc = location(h) && bud’ = bud – (price(h) * nights) && bud’>=0 start graph: Figure 6. : FlightRequest : HotelRequest loc : city nights : int Graph transformation rules dep : city dest : city : FlightRequest Customer As usual, :the application of a graph rule hL ←- K ,→ R, Φi to a given symbolic dep :transformation city name : string dest : city graph SG can be defined by a double pushout in the category of symbolic graphs: bud : int Definition 4.2. (Symbolic graph transformation) Given symbolic graphs SG and SH over a Σ-algebra D, a symbolic graph transformation rule, r = hL ←- K ,→ R, Φr i over D, and a morphism m : hL, Φr i → SG, we say that SH is a direct transformation of SG by r via m, denoted SG =⇒r,m SH, if SH can be obtained by the following double pushout in SymbGraphsD : hL, Φr i o m SG o ? _ hK, Φr i ? _ SF / hR, Φr i m0 / SH 1015 Orejas, Lambers / Symbolic Graph Transformation Moreover, we write SG =⇒ SH if the given rule and match can be left implicit, and we write =⇒∗ to denote the reflexive and transitive closure of =⇒. The proposition below states some properties that are important to understand symbolic graph transformation. The first property states that the set of labels and the condition of the given object graph remain invariant after symbolic transformation. The second property states that symbolic transformation preserves groundedness. The third property shows that the application of a symbolic transformation rule can be defined in terms of a transformation of E-graphs. Finally, the last condition states that if we can apply a transformation to a given graph SG, then we can also apply (essentially) the same transformation to a graph that extends SG with some additional variables and whose condition is more restrictive. Proposition 4.1. Given a symbolic graph transformation rule r = hL ←- K ,→ R, Φi over a given data algebra D: 1. If hG, Φ0 i =⇒r,m hH, Φ00 i then XG = XH and D |= Φ0 ⇔ Φ00 . 2. If hG, Φ0 i =⇒r,m hH, Φ00 i and hG, Φ0 i is grounded then hH, Φ00 i is also grounded. 3. If m : L → G is an E-graph morphism, we have that hG, Φ0 i =⇒r,m hH, Φ0 i if and only if the diagram below is a double pushout in E − Graphs and D |= Φ0 ⇒ m(Φ). Lo m Go ? _K /R ? _F /H 4. If hG, Φ0 i =⇒r,m hH, Φ0 i, XG ⊆ X, and D |= Φ00 ⇒ Φ0 then hG∪X, Φ00 i =⇒r,i◦m hH ∪X, Φ00 i, where G ∪ X denotes the graph obtained by adding to G all the labels that are in X but not in XG and i is the inclusion i : G ,→ G ∪ X. Proof: 1. According to the definition of symbolic graph transformation rules, XL = XK = XR implying that the morphisms in the span hL, Φi ←- hK, Φi ,→ hR, Φi are M-morphisms. If hG, Φ0 i =⇒r,m hH, Φ00 i, this means that the diagram below is a double pushout in SymbGraphsD : hL, Φi o m hG, Φ0 i o ? _ hK, Φi m00 ? _ hF, Ψi / hR, Φi m0 / hH, Φ00 i But we know [14] that pushouts in SymbGraphsD preserve M-morphisms (see [14]), hence the morphisms in the span hG, Φ0 i ←- hF, Ψi ,→ hH, Φ00 i are also M-morphisms. This means that XG = XF = XH and D |= Φ0 ⇔ Ψ ⇔ Φ00 . 1016 Orejas, Lambers / Symbolic Graph Transformation 2. A direct consequence of the previous item. The reason is that, if Φ0 defines the values of all the variables in XG , then Φ00 also defines the values of all the variables in XH = XG . 3. If hG, Φ0 i =⇒r,m hH, Φ0 i this means that m is a symbolic graph morphism and the diagram below is a double pushout in SymbGraphsD : ? _ hK, Φi hL, Φi o m (1) m00 ? _ hF, Φ0 i hG, Φ0 i o / hR, Φi (2) m0 / hH, Φ0 i Now, according to Proposition 3.1, this means that the diagram below is a double pushout in E − Graphs. Moreover, since m is a symbolic graph morphism then D |= Φ0 ⇒ m(Φ). ? _K Lo m Go (3) m00 ? _F /R m0 (4) /H Conversely, let us suppose that diagrams (3) and (4) are pushouts in E − Graphs. We know that if the morphisms in the span L ←- K ,→ R are the identity on variables then so are (up to isomorphism) the morphisms on the span G ←- F ,→ H. This means that the morphisms m, m0 and m00 coincide on the variables and, as a consequence, if D |= Φ0 ⇒ m(Φ), then D |= Φ0 ⇒ m0 (Φ) and D |= Φ0 ⇒ m00 (Φ). Hence all the morphisms in (1) + (2) are symbolic graphs morphisms. Therefore, to prove that (1) and (2) are pushouts, according to Prop. 3.1, we have to prove that D |= Φ0 ⇔ Φ0 ∪ m(Φ) and D |= Φ0 ⇔ Φ0 ∪ m0 (Φ), but this is obvious if D |= Φ0 ⇒ m(Φ) and D |= Φ0 ⇒ m0 (Φ). 4. If hG, Φ0 i =⇒r,m hH, Φ0 i this means that D |= Φ0 ⇒ m0 (Φ) and H can be obtained by the double pushout below: ? _K /R Lo m Go m00 ? _F m0 /H We know that i◦m satisfies the gluing conditions with respect to r, since i just adds some variables that are not connected to any node or edge. Therefore, we can build the following double pushout diagram: Lo i◦m G∪X o ? _K /R ? _F ∪ X /H ∪X But, if D |= Φ00 ⇒ Φ0 and i(m0 (Φ)) = m0 (Φ), since i is the equality on all labels in XG , then D |= Φ00 ⇒ i(m0 (Φ)) implying hG ∪ X, Φ00 i =⇒r,i◦m hH ∪ X, Φ00 i. 1017 Orejas, Lambers / Symbolic Graph Transformation t u The fact that the formula constraining the variables of the E-graph H after transformation is the same formula for the graph G before transformation does not mean that the attributes in the graph do not change after transformation. The reason is that the transformation may change the bindings of variables to nodes and edges, as the example below shows. Moreover, according to Fact 3.1, if we apply the rule hL ←- K ,→ R, Φi to a grounded symbolic graph SG = hG, Φ0 i, the condition D |= Φ0 ⇒ m(Φ) can be seen as the constraint satisfaction problem where we find the values to assign to the variables in Φ, so that this set of formulas is satisfied in D. Example 4.2. In Figure 7 we can see how the rule reserveHotel presented in Example 4.1 is applied to a given start graph as presented in Example 3.3, describing a customer that would like to reserve a hotel for 2 days in Berlin and, in addition, would also like to reserve a flight from Barcelona to Berlin and return. : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin reserveHotel : HotelReservation : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin h : hotel = h5 : Customer : FlightRequest name : string = Alice bud : int = 450 dep : city = Berlin dest : city = Barcelona : Customer : FlightRequest name : string = Alice bud : int = 50 dep : city = Berlin dest : city = Barcelona Berlin = location(h) && bud = 450 – (price(h) * 2) && bud >=0 Figure 7. reserveFlight : HotelReservation h : hotel Symbolic transformation : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin fr1 : FlightReservation f : flight : Customer : FlightRequest name : string = Alice bud : int dep : city = Berlin dest : city = Barcelona In this transformation, a hotel in Berlin is chosen non-deterministically. This choice is made when defining the matching between the left-hand side of the rule and the given graph. The reason is that, as Berlin = location(h) && Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && bud = 450 – said above, even if it*is2) not explicitly depicted, the left-hand side of ReserveHotel is supposed to include (price(h) - price(fr1.f) && bud >=0 the variable h, because that variable is explicitly in the right-hand side of the rule and hence it should : HotelRequest : FlightRequest fr1 : FlightReservation also be included in all the graphs the dep rule. when defining the match morphism we must bind reserveFlight loc : city =in Berlin : cityThen, = Barcelona f : flight nights : int = 2 dest : city = Berlin that variable to some hotel hi in D such that the formula hotel : HotelReservation h : hotel : FlightRequest : Customer fr2 : FlightReservation f : flight dep : city = Berlin Berlin = location(hi)name &&: string bud’=450-(price(hi)*2) && bud’>=0 = Alice dest : city = Barcelona bud : int Berlin =the location(h) Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && Berlin = . This kind of is satisfied. Here, chosen&& hotel, h5, satisfies the above formula for h=h5 and bud’=50 departure(fr2.f) && Barcelona = destination(fr2.f) && bud = 450 – (price(h) * 2) - price(fr1.f) early bindingprice(fr2.f) may not&&bebud very efficient. For instance, after the transformation defined above no flight >=0 reservation is possible, because the budget of the user would not be sufficient anymore for reserving any flight connecting Barcelona and Berlin. Hence, we would need to backtrack this transformation and to hotel price location try a different hotel. This situation also occurs h1 100 when Münchenworking with attributed graphs and attributed graph int, bool, city, hotel, flight h2 90 Berlin transformation rules as in [3]. price:hotel->int h3 85 Berlin As shown in hotel [14], -> symbolic graphh4transformation is more powerful than attributed graph transforma70 Köln location: city tion as presented in [3]. In particular, any attributed graph transformation rule r can be represented by price:flight->int flight price departure destination departure: flight -> city a symbolic graph transformation rulef1SR(r) such that an attributed graph AG can be transformed by r 175 Berlin Barcelona destination: flight -> city f2 115 Berlin Barcelona f3 150 Barcelona Berlin f4 85 Barcelona Berlin Possible solutions in the form (h,fr1.f,fr2.f,bud): 1018 Orejas, Lambers / Symbolic Graph Transformation into a graph AH if and only if the grounded graph associated to AG, GSG(AG), can be transformed by SR(r) into GSG(AH). This representation is quite obvious. If ar = AL ←- AK ,→ AR is an attributed graph transformation rule, usually this means that AL, AR and AK are graphs over the term algebra, i.e. they include terms (with variables) as labels. This means that we can, straightforwardly, represent r as a symbolic graph transformation rule SR(r) replacing the graphs involved by their corresponding associated grounded graphs. Note that, in this case, the conditions in the rule (which would coincide with the name conditions in the grounded Customergraphs GSG(AL), GSG(AR), and GSG(AK)) would be equations Xt = t, string where t is a term-name occurring as an attribute in the rule. In this context, as saidCustomer above, it is proven that, given : string attributed graphs-bud AG, AH, AG =⇒r,m AH if and only if GSG(AG) =⇒bud : int SR(r),GSG(m) GSG(AH). int rules that cannot be However, the converse is not true. In [14], we also proved that there are symbolic HotelRequest FlightRequest simulated by attributed graph transformation rules. nights HotelRequest -loc : city -nights : int 5. FlightRequest dep loc -dep : city -dest : city dest Narrowing rules and narrowing graph transformation city hotel powerful flight As we have seen above, symbolic graph transformation can be hconsidered enough to fspecify transformations of attributed graphs as studied in [3]. However, the kind of rules that we have studied in HotelReservation FlightReservation HotelReservation FlightReservation Section 4 are not powerful enough to specify transformations of arbitrary symbolic graphs that may be -h : hotel -f : flight considered reasonable. For instance, given the start graph G in Figure 8, we would be unable to apply the rule ReserveHotel to G. The problem is that we cannot match the variable h, which (as said above) is implicitly in the left hand side of the rule, to any variable in G. We could think that a possible solution is to assume that all symbolic graphs implicitly include a denumerable set of variables of each sort, so that h can be matched to some variable in G of sort hotel6 . However, this is not enough. If f is supposed to be the match morphism then the condition in G (i.e. true) must imply f (Φ), where Φ is the condition of the rule. However, in general, this is obviously false, since true only implies tautologies. Customer -name : string -bud : int Figure 8. HotelRequest -loc : city -nights : int Start graph The problem is that a rule consisting of a span of M-morphisms can transform the structure of an object graph or change the binding of attributes to nodes or edges of the object graph, but it cannot add new information to the graph, where this new information is represented by new variables and new conditions over the variables. To overcome this problem, we consider a more general kind of rules, which we call narrowing transformation rules, because, as we may see below, when applied to a symbolic graph, it restricts or narrows their associated conditions by adding the conditions of the rule. These rules consist of a span of monomorphisms, where only the left morphism is assumed to be an M-morphism. 6 We may note that, in Example 4.2, the start graph does implicitly include a denumerable set of variables, even if they are not depicted in Figure 5. The reason is that, formally, that graph is assumed to be grounded, which means that it includes a variable per each existing data value. 1019 Orejas, Lambers / Symbolic Graph Transformation Definition 5.1. (Narrowing graph transformation rule) A narrowing graph transformation rule over a Σ-algebra D is a triple hΦL , L ←- K ,→ R, ΦR i, where L, K are E-graphs over the same set of labels, L is linear, L ←- K ,→ R is a span of E-graph inclusions7 , which means that XL = XK ⊆ XR , ΦL and ΦR are sets of Σ-formulas over XL and XR , respectively, and over the values in D, and finally D |= ΦR ⇒ ΦL . Note that the fact that the morphism hK, ΦL i ,→ hL, ΦL i is an M-morphism guarantees that the pushout complement in a rule application is unique, if it exists (see Example 3.2). This means that we may define symbolic graph transformation, using narrowing rules, by double pushouts, in the standard way: Definition 5.2. (Symbolic graph transformation with narrowing rules) Given symbolic graphs SG and SH over a Σ-algebra D, a narrowing rule, r = hΦL , L ←- K ,→ R, ΦR i over D, and a morphism m : hL, ΦL i → SG, we say that SH is a direct transformation of SG by r via m, denoted SG =⇒r,m SH, if SH can be obtained by the double pushout in SymbGraphsD : ? _ hK, ΦL i hL, ΦL i o m (1) / hR, ΦR i (2) ? _ SF SG o m0 / SH and Sem(SH) is not empty. As usual, we write SG =⇒ SH if the given rule and match can be left implicit, and we write =⇒∗ to denote the reflexive and transitive closure of =⇒. We may notice that, in principle, the conditions ΦSH of the symbolic graph SH obtained by the above double pushout if hG, Φi =⇒r,m hH, ΦSH i, could be unsatisfiable in D, which means that the semantics of hH, Φ∪m0 (ΦR )i would be empty. Obviously, it makes little sense to make a transformation whose result is inconsistent. For this reason, this is forbidden in this definition. We may also notice that, if SG =⇒r,m SH, SG is a grounded graph and r is a narrowing rule then SH may be not grounded, because the conditions added by the application of r may be satisfied by several non-isomorphic graphs. As in the case of transformations by (standard) symbolic rules, symbolic graph transformations can be defined in terms of E-graph transformations. As in Proposition 4.1, this is just a consequence of how pushouts in SymbGraphsD are defined. Fact 5.1. Given a narrowing transformation rule r = hΦL , L ←- K ,→ R, ΦR i over D and an E-graph morphism m : L → G, we have that hG, Φi =⇒r,m hH, Φ ∪ m0 (ΦR )i if and only if the diagram below is a double pushout in E − Graphs and D |= Φ ⇒ m(ΦL ). ? _K Lo m Go (1) ? _F /R (2) m0 /H Remark 5.1. Obviously, narrowing rules are a generalization of symbolic graph transformation rules, in the sense that every symbolic rule r = hL ←- K ,→ R, Φr i can be seen as the narrowing rule 7 or, in general, monomorphisms 1020 Orejas, Lambers / Symbolic Graph Transformation narrow(r) = hΦr , L ←- K ,→ R, Φr i. Then, as a consequence of the definition of graph transformation, SG =⇒r,m SH if and only if SG =⇒narrow(r),m SH. The fact that symbolic graph transformation with narrowing rules can be defined in terms of E-graph transformation means that it is easy to extend the fundamental results that characterize graph transformation (e.g. the Embedding and Extension theorems or the Church-Rosser and Parallelism Theorems) to this kind of transformations. As said above, symbolic graphs can be seen as specifications of classes of attributed graphs or, equivalently, of grounded symbolic graphs. Therefore symbolic graph transformations, with standard rules or with narrowing rules can be seen as transformations of specifications. In this context, one may ask if graph transformation as defined above is compatible with respect to the semantics of symbolic graphs, in the sense that the semantics of a transformation coincides, in some sense, with the corresponding transformation of the semantics. More precisely: Definition 5.3. (Compatibility of symbolic transformation and semantics) Symbolic graph transformation is compatible with the semantics of symbolic graphs if for every narrowing transformation rule r = hΦL , L ←- K ,→ R, ΦR i, every transformation SG =⇒r,m SH, and every AH ∈ Sem(SH), there is an AG ∈ Sem(SG), such that GSG(AG) =⇒r,h◦m SH 0 and AH ∈ Sem(SH 0 ), where h : SG → GSG(AG) is the morphism defined by Fact 3.2. Moreover, symbolic graph transformation is strongly compatible with the semantics of symbolic graphs if, in addition, for every AG ∈ Sem(SG), if GSG(AG) =⇒r,f SH 0 and f is factorized into h◦m, with h : SG → GSG(AG) and m : L → G, according to Fact 3.3, there is a direct transformation SG =⇒r,m SH such that Sem(SH 0 ) ⊆ Sem(SH). Notice that, in the definition of strong compatibility, Fact 3.3, only ensures that m is an E-graph morphism. Therefore, to ensure strong compatibility we would need to prove first that m is a symbolic graph morphism. Then, we have: Theorem 5.1. Symbolic graph transformation with narrowing rules is compatible, but not strongly compatible, with the semantics of symbolic graphs. Proof: • Compatibility: Let SG = hG, ΦSG i, SH = hH, ΦSH i, AH ∈ Sem(SH), SH 0 = GSG(AH) = hH 0 , ΦSH 0 i, r = hΦL , L ←- K ,→ R, ΦR i, and suppose that SG =⇒r,m SH. This means that diagrams (1) and (2) below are pushouts in the category of E-graphs, ΦSH = ΦSG ∪ m0 (ΦR ) and, according to Fact 3.2 there is a morphism h0 : SH → SH 0 such that h0 is induced by a label substitution and D |= ΦSH 0 ⇒ h0 (ΦSH ). Now, we know that XL = XK ⊆ XR , therefore, without loss of generality, we may assume that XG = XF ⊆ XH . Then, we can define a substitution σ over the variables in G as σ(x) = h0 (x). Let G0 = σ(G), let F 0 = σ(F ), and let h : G → G0 and f : F → F 0 be the corresponding morphisms induced by σ. Then diagrams (3) and (4) below are obviously pushouts, where the monomorphisms F 0 ,→ G0 and F 0 ,→ H 0 are defined like the monomorphisms F ,→ G and F ,→ H on graph nodes and edges and they are the identity on the variables. Orejas, Lambers / Symbolic Graph Transformation ? _K Lo m (1) h (3) G0 o /R m0 (2) ? _F Go 1021 /H f (4) ? _F 0 h0 / H0 This means that (1) + (3) and (2) + (4) are pushouts, and thus hG0 , Φ0 i =⇒r,h◦m hH 0 , Φ0 ∪ h0 ◦ 0 , (x = v) ∈ Φ m0 (ΦR )i, where Φ0 = {x = v | x ∈ XG SH 0 }. Notice that this definition of 0 0 Φ is correct since all the variables in G are in H 0 , and SH 0 is a grounded model, so for each variable x in H 0 there should be an equation x = v in ΦSH 0 . Finally, we can easily see that AH ∈ Sem(hH 0 , Φ0 ∪ h0 ◦ m0 (ΦR )). It is enough to notice that, by construction, we can obtain AH replacing in H 0 each variable x by the value v, if (x = v) ∈ ΦSH 0 . • Strong compatibility: To prove that symbolic graph transformation with narrowing rules is not complete in the above sense, it is enough to consider the following counter example. Let SG be a symbolic graph over the integers data algebra with only one node labelled with a variable x, and with the empty set of conditions. And consider a rule that says that if we have a graph consisting of a node labelled with a variable y whose value is 2 (i.e. ΦL consists of the equation y = 2) then we can replace y by z whose value is 3. Now, we cannot apply that rule to SG with the obvious matching, since the empty set of conditions does not imply x = 2. However, we can apply the rule to the grounded graph that includes the equation x = 2. t u In this context, the solution to obtain a strongly compatible transformation relation is quite obvious. If the problem is caused by not allowing to apply a rule if the conditions of the object graph do not imply the conditions of the left-hand side of the rule, the solution is to allow this application independently of these conditions. We can call this kind of transformation narrowing transformations, and we can show (see Theorem 5.2) that they are strongly compatible with respect to the semantics of symbolic graphs. Definition 5.4. (Narrowing graph transformation) Given a symbolic graph SG = hG, ΦSG i over a Σ-algebra D, a narrowing transformation rule r = hΦL , L ←- K ,→ R, ΦR i over D, and an E-graph morphism m : L → G, we define the direct narrowing transformation of SG by r via m, denoted SG Vr,m SH, as the symbolic graph SH = hH, ΦSH i, such that Sem(SH) 6= ∅, where H is obtained by the double pushout in E − Graphs below: ? _K Lo m Go (1) ? _F /R (2) m0 /H and where ΦSH = ΦSG ∪ m0 (ΦR ) We may notice that, when applying narrowing transformations, the left-hand side condition of a rule, ΦL , plays no role in the transformations. This means that we may also apply narrowing transformation 1022 Orejas, Lambers / Symbolic Graph Transformation using standard rules. In particular, narrowing transformation with a (standard) symbolic rule r = hL ←K ,→ R, Φr i is equivalent to symbolic transformation with the narrowing rule r = h∅, L ←- K ,→ R, Φr i. We can see that narrowing graph transformation is more general than symbolic graph transformation with narrowing rules: Fact 5.2. Given r = hΦL , L ←- K ,→ R, ΦR i, if SG =⇒r,m SH then SG Vr,m SH. Proof: According to Fact 5.1, if SG =⇒r,m SH, where SG = hG, ΦSG i and r = hΦL , L ←- K ,→ R, ΦR i, then SH = hH, ΦSG ∪ m0 (ΦR )i, where H is obtained by the double pushout diagram below: Lo m Go ? _K /R ? _F m0 /H But, by definition of narrowing graph transformation, this means SG Vr,m SH. t u The converse, obviously, is not true in general. To end this section, we can show the strong compatibility of narrowing transformation with respect to the semantics of symbolic graphs: Theorem 5.2. Narrowing graph transformation is strongly compatible with the semantics of symbolic graphs. Proof: • Compatibility: The proof is the same as the proof of compatibility in Theorem 5.1 • Strong compatibility: If AG ∈ Sem(SG), with SG = hG, ΦSG i, and GSG(AG) Vr,h◦m SH 0 , where GSG(AG) = hG0 , ΦGSG(AG) i, h : SG → GSG(AG) is the morphism defined by Fact 3.2, and m : L → G, this means that SH 0 = hH 0 , ΦGSG(AG) ∪ m0 (ΦR )i, where H 0 is obtained by the double pushout below: ? _K Lo h◦m (1) G0 o ? _F 0 /R (2) m0 / H0 but, given the match m : L → G, we can also apply the transformation SG Vr,m SH: ? _K Lo m Go (3) ? _F /R (4) m00 /H where SH = hH, ΦSG ∪ m00 (ΦR )i. Now, pushouts (1) and (2) can be decomposed: Orejas, Lambers / Symbolic Graph Transformation ? _K Lo m (3) Go h G0 o (5) ? _F ? _F 0 1023 /R m00 (4) /H (6) h0 / H0 where m0 = h0 ◦ m00 . On the one hand, we know that XL ⊆ XR , this means that XG ⊆ XH and XG0 ⊆ XH . On the other hand, we also know that h is a morphism induced by a label substitution, implying that it is a bijection on graph nodes and edges. This means that h0 is also a bijection on graph nodes and edges and, therefore it is also induced by a label substitution. Hence, as a consequence of Fact 3.2, if AH ∈ Sem(SH 0 ) we have that AH ∈ Sem(SH). t u 6. Lazy graph transformation In Example 4.2 we saw that, when defining a match for a rule r = hL ←- K ,→ R, Φr i, this match must also be defined on variables that are bound to a node or edge in R but not bound to any node or edge in L (i.e. intuitively, these variables are not part of L). This forces us to bind these variables too early, implying that we may need to backtrack afterwards, as the example showed. The basic idea of our approach to avoid this is that, when applying a rule, we do not need to match these variables. We do this using two ideas. First, instead of applying (standard) symbolic graph transformation with the given rule, we apply narrowing graph transformation. In this way, we do not ask the given match to satisfy the conditions of the rule, but we only add these conditions afterwards. So, in a sense, we are postponing the satisfaction of the associated constraints. However, this is not enough, because the match morphism still has to bind the variables in L that are not bound to any node or edge. Then, the second idea is that the match morphism for r should not be defined on L, but on Reach(L) (cf. Definition 2.3). This is equivalent to transforming each rule into a narrowing rule, whose E-graph in the left-hand side is not L but Reach(L) and whose left condition is empty. As a consequence, when we apply the associated narrowing rule to a graph SG, as we saw in the previous section, we add the formulas in Φr to the result of the transformation, since these formulas define the possible values of the non-matched variables with respect to the values of the rest of the variables, as we can see in Example 6.2. Moreover, as we can also see in this example, after applying a lazy transformation we can simplify the resulting condition. In particular, formula simplification can be considered correct because two symbolic graphs are isomorphic when their corresponding E-graphs are identical (or isomorphic) and their conditions are equivalent. In particular, applying some simplifications after a transformation may be interesting from a practical viewpoint, since we may operate with the associated conditions in a more efficient way. Definition 6.1. (Lazy graph transformation) Given a transformation rule r = hL ←- K ,→ R, Φr i we define its associated lazy rule as the narrowing rule Lazy(r) = h∅, Reach(L) ←- Restr(K, XReach(L) ) ,→ R, Φr i. Then, given a symbolic graph SG = hG, ΦG i and a morphism m : Reach(L) → G, we define the lazy transformation of SG by r via l m, denoted SG =⇒r,m SH as the narrowing transformation SG VLazy(r),m SH. 1024 Orejas, Lambers / Symbolic Graph Transformation l This means that SG =⇒r,m SH if SH = hH, ΦH i, where H is obtained by the double pushout below in the category of E-graphs: ? _ Restr(K, XReach(L) ) Reach(L) o m Go (1) /R (2) ? _F m0 /H l and where ΦH = ΦG ∪ m0 (Φr ). As usual, we write SG =⇒ SH if the given rule and match can be left l ∗ l implicit, and we write =⇒ to denote the reflexive and transitive closure of =⇒. Intuitively, H is similar to the E-graph obtained by a standard symbolic transformation, except that it would include all the variables in XR \ XReach(L) instead of their corresponding matchings. It may be noted that the resulting condition ΦH must be satisfiable for the given data algebra D. The reason is that we have required that the result of a narrowing graph transformation must have non-empty semantics. Example 6.1. For example, if we apply the rule ReserveHotel as in Example 4.2 without binding the variable h to some concrete value hi in Dhotel , then we obtain a lazy graph transformation step as depicted in the first step of the lazy graph transformation in Example 6.2. After this first step the formula Berlin = location(h) && bud=450-(price(h) * 2) && bud>=0 should be satisfied. Given the data algebra D as presented in Example 3.3, it is obvious that this formula is satisfiable. Let us now study the relation between symbolic graph transformation and lazy transformation for the same rule. In particular, we are interested in studying if every symbolic transformation can be implemented in terms of a lazy transformation and, vice versa, if every lazy transformation corresponds to a symbolic transformation. More precisely, we study this issue with respect to the semantics of specifications. These properties are formulated as follows: l ∗ 1. Soundness For every lazy transformation SG =⇒ SH and every attributed graph AH ∈ Sem(SH) there is a symbolic transformation SG =⇒∗ SH 0 such that AH ∈ Sem(SH 0 ). 2. Completeness For every symbolic transformation SG =⇒∗ SH there is a lazy transformation l ∗ SG =⇒ SH 0 such that Sem(SH) ⊆ Sem(SH 0 ). Notice that, when the given SG is a grounded graph, the above properties ensure that we can get exactly the same results with both kinds of transformation, although, in the case of lazy transformation we may need to perform some constraint solving after the transformation process, as we will see in the example below. The first result tells us that, when SH is an arbitrary symbolic graph, lazy graph transformation is a complete implementation of symbolic graph transformation, but it may be considered, technically, not sound. In particular, it may be possible to apply a lazy transformation to a graph SG = hG, ΦG i using the rule r = hL ←- K ,→ R, Φr i, but it may be impossible to apply the same rule to SG to do symbolic 1025 Orejas, Lambers / Symbolic Graph Transformation transformation. The reason is that for symbolic transformation we require that D |= ΦG ⇒ m(Φr ), for a given match m, while in the case of lazy transformation it may be enough that ΦG ∪ m(Φr ) is satisfiable in D. This may happen, for instance, if the condition on G is 0 < X < 5 and the condition on the rule is 3 < X < 7. In that case, we would be unable to apply symbolic graph transformation, since 0 < X < 5 does not imply 3 < X < 7. However, it could be possible to apply lazy transformation and, then, the resulting condition would be 0 < X < 5 ∧ 3 < X < 7, or equivalently 3 < X < 5. Instead, we will show that lazy transformation satisfies a different property, which we call extended soundness. Theorem 6.1. (Extended soundness and completeness of lazy graph transformation) Given a symbolic graph SG = hG, ΦG i, then: l ∗ 1. Extended soundness For every lazy transformation SG =⇒ SH, with SG = hG, ΦSG i and SH = hH, ΦSH i there is a symbolic transformation hG ∪ XH , ΦSH i =⇒∗ SH (up to isomorphism), where G ∪ XH denotes the graph obtained by adding to G all the variables in H (actually the variables that are in H but not in G, since XG ⊆ XH ). 2. Completeness For every symbolic transformation SG =⇒∗ SH there is a lazy transformation l ∗ SG =⇒ SH 0 such that Sem(SH) ⊆ Sem(SH 0 ). Proof: l ∗ 1. Extended Soundness Given the lazy transformation SG =⇒ SH, with SG = hG, ΦSG i and SH = hH, ΦSH i we prove that there is a symbolic transformation hG ∪ XH , ΦSH i =⇒∗ SH by induction on the length of the derivation. If SG = SH, then the case is trivial. For the l ∗ l general case, let us suppose that SG =⇒ SG1 and SG1 =⇒r,m SH, with SG1 = hG1 , ΦSG1 i, SH = hH, ΦSH i where H is defined by the diagram below: ? _ Restr(K, XReach(L) ) Reach(L) o m G1 o (1) ? _ F1 /R (2) m0 /H and ΦSH = ΦSG1 ∪ m0 (Φr ). By induction, we may assume that there is a symbolic transformation hG∪XG1 , ΦSG1 i =⇒∗ SG1 . By Proposition 4.1.4, this means that hG ∪ XH , ΦSH i =⇒∗ hG1 ∪ XH , ΦSH i, since XG ∪ XG1 ⊆ XH and D |= ΦSH ⇒ ΦSG1 . Therefore, we have to prove that there is a match m1 : SL → hG1 ∪XH , ΦSH i such that hG1 ∪XH , ΦSH i =⇒r,m1 SH. Now, without loss of generality, we may assume that XG1 = XF1 ⊆ XH and that m0 is the equality for every variable in XR \ XReach(L) (if needed we could rename the variables in r). Then, XH = XG1 + (XR \ XReach(L) ) = XG1 + (XL \ XReach(L) ). As a consequence, we can define the match m1 : hL, Φr i → hG1 ∪ XH , ΦSH i as follows. For any graph node or any edge e ∈ L: m1 (e) = m(e); for every label x ∈ XReach(L) : m1 (x) = m(x); and for every x ∈ (XL \ XReach(L) ): m1 (x) = x. Then, m1 is a symbolic morphism since D |= ΦSH ⇒ m1 (Φr ), since ΦSH = ΦSG1 ∪ m0 (Φr ) and m0 (Φr ) = m(Φr ) = 1026 Orejas, Lambers / Symbolic Graph Transformation m1 (Φr ). Hence, we have the direct transformation hG1 ∪ XH , ΦSH i =⇒r,m1 hH 0 , ΦSH i, where H 0 is defined by the following double pushout diagram: ? _K Lo m1 (3) /R (4) G1 ∪ XH o ? _F 0 m01 / H0 1 Now, we know that L = Reach(L) + (XL \ XReach(L) ) and K = Restr(K, XReach(L) ) + (XL \ XReach(L) ). Moreover, G1 ∪ XH = G1 + (XL \ XReach(L) ), because we have assumed that m0 is the equality for every variable in (XR \ XReach(L) ) and, hence, XH = XG1 + (XR \ XReach(L) ). Therefore, F10 = F1 + (XL \ XReach(L) ). But then pushout (2) can be decomposed in the two pushouts below: Restr(K, XReach(L) ) / K / F0 1 F1 /R (4) m01 / H0 and this means that H = H 0 (up to isomorphism), implying hG1 ∪ XH , ΦSH i =⇒r,m1 SH. 2. Completeness We proceed by induction on the length of the transformation. In particular we will l ∗ prove that if SG =⇒∗ SH, with SH = hH, ΦSH i, then SG =⇒ SH 0 , with SH 0 = hH 0 , ΦSH 0 i, and there is a label substitution h : XH 0 → XH such that h(H 0 ) = H and D |= h(ΦSH 0 ) ⇔ ΦSH . We may notice that this implies that if AH ∈ Sem(SH) then AH ∈ Sem(SH 0 ). The reason is that if AH ∈ Sem(SH) this means that there is a substitution σ such that AH = hσ(H), Di and D |= σ(ΦSH ), but this implies that AH = hσ(h(H 0 )), Di and D |= σ(h(ΦSH 0 )) and, so, AH ∈ Sem(SH 0 ). The base case, i.e. SG = SH, is trivial. For the general case, let us assume that SG =⇒∗ SG1 and SG1 =⇒r,m SH, with SG1 = hG1 , ΦSG1 i and SH = hH, ΦSH i, with ΦSG1 = ΦSH , since graph conditions remain invariant after symbolic graph transformation with symbolic transformation rules (see Proposition 4.1.3) and where H is defined by the double pushout below: ? _K Lo m G1 o (1) ? _F /R (2) j m0 /H l ∗ By induction, we may assume that there is a lazy transformation SG =⇒ SG01 with SG01 = hG01 , ΦSG01 i and a label substitution h1 : XG01 → XG1 such that h1 (G01 ) = G1 and D |= h1 (ΦSG01 ) ⇔ ΦSG1 . Now, we define the match morphism m1 : Reach(L) → G01 as follows. For any graph node or any edge e ∈ Reach(L): 1027 Orejas, Lambers / Symbolic Graph Transformation • For any graph node or any edge e ∈ Reach(L): m1 (e) = h−1 1 (m(e)) • For every label x ∈ XReach(L) , where x is attached to some node or edge by a node label edge or an edge label edge e (i.e. e ∈ EN L ∪ EEL and tL (e) = x)8 : m1 (x) = y if y is the target of m1 (e) in G01 . This definition is correct because, on the one hand, h1 is a bijection on graph nodes and edges and, on the other hand, because L is a linear symbolic graph and therefore each variable is attached to at most one node or edge. We may notice that, as a consequence of the commuting properties of target functions with graph morphisms, h1 ◦ m1 = m ◦ i, where i is the inclusion i : Reach(L) ,→ L. Now let us consider the following diagrams, where all the squares are pushouts (m◦i, and therefore h ◦ m1 , satisfy the gluing conditions because m and i satisfy them): ? _ Restr(K, XReach(L) ) _ o Reach(L) _ ? _K Lo m m1 (3) i G1 o (1) ? _ Restr(K, XReach(L) ) Reach(L) o h1 ? _F ? _F 0 G01 o m00 1 (4) (5) h00 ? _ F 00 G1 o Now, since the composition of pushouts is a pushout, we know that (1) + (3) and (4) + (5) are pushouts. Moreover, since pushout complements are unique in M-adhesive categories and h1 ◦ m1 = m ◦ i then F = F 00 . Thus, h00 is a morphism from F 0 to F . Moreover, since h is a morphism induced by label substitution, so is h00 . Let us now consider the diagram below: Restr(K, XReach(L) ) /R m00 1 (6) h00 j0 (7) 0 F F j m01 / H0 h0 /H where (6) is a pushout, j is defined in diagram (2) above, and h0 is the unique morphism that satisfies h0 ◦ j 0 = j ◦ h00 and h0 ◦ m01 = m0 , by the universal property of pushout (6). Please, notice that diagram (7) is not necessarily a pushout. Let us now see that h0 is a morphism induced by a label substitution. Without loss of generality we may assume that H 0 = F 0 +(R\Restr(K, XReach(L) )) and H = F + (R \ K), where + denotes disjoint union. Then, if e is a graph node or edge from F 0 , we know that h0 (j 0 (e)) = j(h00 (e)), but h00 is a morphism induced by a label substitution and assuming, without loss of generality, that j and j 0 are inclusions then we have h0 (e) = e. Similarly, if e is a graph node or edge in R \ Restr(K, XReach(L) ), then h0 (m01 (e)) = m0 (e), and assuming 8 L tL is assumed to denote the corresponding target function in L, i.e. tN or tEL L L . 1028 Orejas, Lambers / Symbolic Graph Transformation again without loss of generality that m0 and m01 are the identity on the elements in R \ K and R \ Restr(K, XReach(L) ), respectively, we have h0 (e) = e. Hence, to end the proof, we just have to show that D |= h0 (ΦSH 0 ) ⇔ ΦSH . We know that ΦSH 0 = (ΦSG01 ∪ m01 (Φr )), D |= ΦSH ⇒ m(Φr ), m(Φr ) = m0 (Φr ), and D |= h1 (ΦSG01 ) ⇔ ΦSH . Therefore, we have h0 (ΦSH 0 ) = h0 (ΦSG01 ∪ m01 (Φr )) = h0 (ΦSG01 ) ∪ h0 (m01 (Φr )) = h1 (ΦSG01 ) ∪ m0 (Φr ), because h0 (ΦSG01 ) = h1 (ΦSG01 ) and h0 ◦ m01 = m0 . This implies D |= h0 (ΦSH 0 ) ⇔ ΦSH ∪ m0 (Φr ). But, since D |= ΦSH ⇒ m0 (Φr ), we have D |= h0 (ΦSH 0 ) ⇔ ΦSH . t u The second result tells us that if the given graph SG is grounded (or, equivalently, it is an attributed graph) then lazy transformation is sound and complete with respect to symbolic graph transformation. This means that, semantically, it does not matter if, each time we apply a transformation rule, we solve the constraints associated to that application, or if we apply lazy transformation and, at the end, we solve the constraints of the resulting graph. Theorem 6.2. (Soundness and completeness of lazy graph transformation over grounded graphs) Given a grounded symbolic graph SG = hG, ΦG i, then: l ∗ 1. Soundness For every lazy transformation SG =⇒ SH and every attributed graph AH ∈ Sem(SH) there is a symbolic transformation SG =⇒∗ SH 0 such that AH ∈ Sem(SH 0 ). 2. Completeness For every symbolic transformation SG =⇒∗ SH there is a lazy transformation l ∗ SG =⇒ SH 0 such that Sem(SH) ⊆ Sem(SH 0 ). Proof: 1. Soundness We proceed by induction on the length of the derivation. In particular we will prove l ∗ that if SG =⇒ SH, with SH = hH, ΦSH i, and σ : XH → D satisfies D |= σ(ΦSH ), then there is a transformation SG =⇒∗ SH 0 , a label substitution h : XH → XG , and an assignment σ 0 : XG → D, such that SH 0 = hH 0 , ΦSG i is grounded, h(SH) = SH 0 , and σ = σ 0 ◦ h. This is obviously enough to ensure that AH = hσ 0 (H 0 ), Di is in Sem(SH 0 ). Notice that, asking for the condition h(SH) = SH 0 , when h : XH → XG , makes sense because XG = XH 0 , since symbolic graph transformation preserves the variables of graphs. l ∗ If SG = SH, the case is trivial. For the general case, let us suppose that SG =⇒ SG1 and l SG1 =⇒r,m SH, with SG1 = hG1 , ΦSG1 i, SH = hH, ΦSH i where H is defined by the double pushout diagram below: ? _ Restr(K, XReach(L) ) Reach(L) o m G1 o (1) ? _ F1 /R (2) m0 /H and ΦSH = ΦSG1 ∪ m0 (Φr ), and let σ : XH → D be an assignment such that D |= σ(ΦSH ). Without loss of generality, we may assume that XH = XG1 + (XR \ XReach(L) ) and that for Orejas, Lambers / Symbolic Graph Transformation 1029 every x ∈ XReach(L) : m(x) = m0 (x). Now, let σ1 be the restriction of σ to XG1 . Obviously, D |= σ1 (ΦSG1 ) . By induction, we may assume that there is a symbolic transformation SG =⇒∗ SG01 , a label substitution h1 : XG1 → XG , and an assignment σ 0 : XG → D, such that SG01 = hG01 , ΦSG i is grounded, h1 (SG1 ) = SG01 , and σ1 = σ 0 ◦ h1 . Let m1 : L → G01 be the following match. For every element e ∈ Reach(L) (e is a graph node or edge) m1 (e) = h1 (m(e)) and for every variable x ∈ XL , m1 (x) = xv , where v is the value in D such that σ(m0 (x)) = v. Notice that this definition is correct because, on the one hand, we have assumed that for every x ∈ XReach(L) : m(x) = m0 (x), and on the other hand, G01 is grounded, so it includes a variable xv . Now, we can see that m1 : hL, Φr i → SG01 is a symbolic graph morphism, i.e. that D |= ΦSG01 ⇒ m1 (Φr ). We know that SG01 is grounded, therefore σ 0 is the only substitution such that D |= σ 0 (ΦSG01 ) and this means that σ 0 (xv ) = v, for every value v. By definition of m1 , we have that, for every variable x ∈ XL = XR , σ 0 (m1 (x)) = σ(m0 (x)) and we know that D |= σ(ΦSH ) and D |= ΦSH ⇒ m0 (Φ(r)). But this means D |= σ(m0 (Φ(r))) and, hence, D |= σ 0 (m1 (Φr )). In addition, m1 satisfies the gluing conditions with respect to the rule r because m satisfies them by assumption, and h1 satisfies them because it is a morphism associated to a label substitution. Therefore, we can apply the symbolic transformation SG01 =⇒r,m1 SH 0 and we can define the label substitution h : XH → XG as follows. For every x ∈ XH , if x ∈ XG1 then h(x) = h1 (x), and if x ∈ XL \ XReach(L) then h(x) = m1 (x). Now, SH is grounded because symbolic graph transformation preserves groundedness. Moreover, it is routine to check that h(SH) = SH 0 , and σ = σ 0 ◦ h. 2. Completeness This is just a special case of Theorem 6.1.2. t u Example 6.2. Consider the lazy graph transformation as presented in Figure 9, where a hotel is reserved for two nights in Berlin and a flight from Barcelona to Berlin and return is reserved. The labels h for the hotel, fr1.f and fr2.f for the flights are not bound to a concrete hotel or concrete flights yet. Note that we use the *.* notation to distinguish labels having the same name in different nodes. At the end of this transformation a formula equivalent to: Berlin = location(h) && Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && Berlin = departure(fr2.f) && Barcelona = destination(fr2.f) && bud = 450 - (price(h) * 2) - price(fr1.f) - price(fr2.f) && bud >=0 should be satisfied9 . Solving this formula for the data algebra D given in Example 3.3, we obtain the following solutions for the labels (h,fr1.f,fr2.f,bud): (h2,f4,f1,10), (h3,f4,f1,20), (h2,f3,f2,5), (h3,f3,f2,15), (h2,f4,f2,70) and (h3,f4,f2,80). In particular, for the solution (h2,f4,f1,10) a corresponding symbolic transformation exists, where h, fr1.f and fr2.f are bound to h2, f4 and f1, respectively. Moreover, in the end the total budget bud of the customer is 10. 9 Actually,the formula that we would obtain is a bit more complex including several (renamed copies of the variable bud, since each application of a rule would add a new variable bud and a constraint defining it. However, if we would allow to simplify the given formula after each transformation step, as it is sometimes done in Constraint Logic Programming, we could indeed obtain the above formula 1030 Orejas, Lambers / Symbolic Graph Transformation To solve the resulting constraints after a sequence of transformations we may need to use a specialized constraint solver. If that solver gives the possibility of defining some kind of optimality criteria (e.g. the overall price of the reservations) then it would return us the best solution according to these criteria. However, if the data algebra D can be considered to be implemented by a database, as it may happen in this example, then the resulting constraints after a sequence of transformations could be compiled into a query to that database, meaning that all the possible solutions would just be obtained as a result of that query. : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin reserveHotel : HotelReservation : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin h : hotel : Customer : FlightRequest name : string = Alice bud : int = 450 dep : city = Berlin dest : city = Barcelona : Customer : FlightRequest name : string = Alice bud : int dep : city = Berlin dest : city = Barcelona Berlin = location(h) && bud = 450 – (price(h) * 2) && bud >=0 reserveFlight : HotelReservation h : hotel : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin fr1 : FlightReservation f : flight : Customer : FlightRequest name : string = Alice bud : int dep : city = Berlin dest : city = Barcelona Berlin = location(h) && Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && bud = 450 – (price(h) * 2) - price(fr1.f) && bud >=0 reserveFlight : HotelReservation h : hotel : HotelRequest : FlightRequest loc : city = Berlin nights : int = 2 dep : city = Barcelona dest : city = Berlin fr1 : FlightReservation f : flight : FlightRequest : Customer dep : city = Berlin dest : city = Barcelona name : string = Alice bud : int fr2 : FlightReservation f : flight Berlin = location(h) && Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && Berlin = departure(fr2.f) && Barcelona = destination(fr2.f) && bud = 450 – (price(h) * 2) - price(fr1.f) price(fr2.f) && bud >=0 Figure Lazy graph transformation hotel9. price location int, bool, city, hotel, flight 7. h1 100 München h2 90 Berlin h3 85 Berlin price:hotel->int h4 70 location: hotel -> city price:flight->int flight price departure: flight -> city Conclusion and relatedf1work 175 destination: flight -> city f2 115 Köln departure destination Berlin Barcelona Berlin Barcelona f3 150 Barcelona graph Berlin In this paper we have studied several forms of symbolic transformation, including showing that we f4 85 Barcelona Berlin can delay constraint solving in the framework of attributed graph transformation by means of symbolic graphs. The idea of the technique comes from constraint logic programming [9]. Actually, the idea unin the form (h,fr1.f,fr2.f,bud): derlying Possible symbolicsolutions graphs also comes from constraint logic programming, where the domain of values, (h2,f4,f1,440),(h3,f4,f1,430),(h2,f3,f2,445),(h3,f3,f2,435),(h2,f4,f2,380),(h3,f4,f2,370) and the conditions on them are neatly separated from symbolic clauses. In a similar way, we separate Wrong solutions: (h2,f3,f1,505),(h3,f3,f1,495),(h5,fr1.f,fr2.f,bud) Optimal solution (bud is minimal): (h3,f4,f2,370) Remark: could this optimal solution have been computed without backtracking, using additional axioms? In each step, check that there is no other value in the algebra Orejas, Lambers / Symbolic Graph Transformation 1031 the graph part in symbolic graphs from the conditions defining the value part. Symbolic graph transformation can be seen as a generalization of attribute grammars [8]. In particular, attribute grammars can be considered to provide a method for computing attributes in trees. Moreover, these attributes must be computed in a fixed way: either top-down (inherited attributes) or bottom-up (synthesized attributes). There are three kinds of approaches to define attributed graphs and attributed graph transformation. In [10, 1] attributed graphs are seen as algebras. In particular, the graph part of an attributed graph is encoded as an algebra extending the given data algebra. In [7, 5] an attributed graph is a pair (G, D) consisting of a graph G and a data algebra D whose values are nodes in G. In [2] these two approaches are compared showing that they are, up to a certain point, equivalent. Finally, [16] is based on the use of labelled graphs to represent attributed graphs, and of rule schemata to define graph transformations involving computations on the labels. That approach has some similarities with our approach, including the simplicity provided by the separation of the algebra part and the graph part of attributed graphs. However, the conceptual difference between the notions of attributed graph and of rule schemata has the problem that this approach does not fit as an instance of adhesive rule-based transformation, which means that we cannot apply to this approach the rich theory of adhesive categories. Moreover, we do not think that there is a direct way of defining lazy graph transformations for any of those approaches, since there is no clear way of handling constraints explicitly. There are further aspects related to symbolic graph transformations that deserve some future work. Addressing the implementation of these techniques could be an obvious goal. However, there are other fundamental aspects which may be interesting to study, like developing specific techniques for checking confluence for symbolic transformation or the definition of symbolic graph transformation with borrowing contexts, avoiding some existing technical difficulties. In particular, when computing the borrowed context of a given rule application, we are forced to assign values of the given data algebra to all the variables in the left hand-side of the given rule. This causes that, in general, for any possible rule application we may have an infinite number of contexts that only differ on the values of the attributes. Obviously, this problem poses difficulties for using the borrowing context technique to prove bisimilarity for attributed graph processes. References [1] Berthold, M., Fischer, I. and Koch M. (2000) Attributed Graph Transformation with Partial Attribution. Technical Report 2000-2. [2] Ehrig, H. (2004) Attributed Graphs and Typing: Relationship between Different Representations. Bulletin of the EATCS, 82: 175–190. [3] Ehrig, H., Ehrig, K., Prange, U. and Taentzer, G. (2006) Fundamentals of Algebraic Graph Transformation, Springer. [4] Ehrig, H., Padberg, J., Prange, U. and Habel A. (2006) Adhesive High-Level Replacement Systems: A New Categorical Framework for Graph Transformation. Fundamenta Informaticae, 74(1): 1–29. [5] Ehrig, H., Ehrig, K., Prange, U. and Taentzer, G. (2006) Fundamental Theory for Typed Attributed Graphs and Graph Transformation based on Adhesive HLR Categories. Fundamenta Informaticae, 74(1): 31–61. [6] Ehrig, H., Mahr, B. (1985) Fundamentals of Algebraic Specifications 1: Equations and Initial Semantics. Vol. 6 of EATCS Monographs on Theoretical Computer Science. Springer. 1032 Orejas, Lambers / Symbolic Graph Transformation [7] Heckel, R., Küster, J. and Taentzer, G. (2002) Towards Automatic Translation of UML Models into Semantic Domains. In Proc. APPLIGRAPH Workshop on Applied Graph Transformation, pp. 11–22. [8] Knuth D.E (1968) Semantics of context-free languages, Mathematical Systems Theory, 2: 127–145. [9] Jaffar, J., Maher, M., Marriot, P., and Stukey P. (1998) The semantics of constraint logic programs. The Journal of Logic Programming, 37:1–46. [10] Löwe, M., Korff, M. and Wagner A. (1993) An Algebraic Framework for the Transformation of Attributed Graphs. In Term Graph Rewriting: Theory and Practice, 185–199. John Wiley and Sons Ltd. [11] Lack, S. and Sobocinski P. (2005) Adhesive and quasiadhesive categories. Theoretical Informatics and Applications, 39(3): 511–545. [12] Orejas F. (2008) Attributed Graph Constraints. In Graph Transformations, 4th International Conference, ICGT 2008, Springer LNCS 5214, 274–288. [13] Orejas F. (2011) Attributed Graph Constraints for Attributed Graph Transformation. Journal of Symbolic Computation, 46 (3): 294–315. [14] Orejas F. and Lambers, L. (2010) Symbolic Attributed Graphs for Attributed Graph Transformation. Int. Coll. on Graph and Model Transformation On the occasion of the 65th birthday of Hartmut Ehrig. Comm. of the EASST, 30. [15] Orejas F. and Lambers, L. (2010) Delaying Constraint Solving in Attributed Graph Transformation. In Graph Transformations, 5th International Conference, ICGT 2010, Springer LNCS 6372, 43–58. [16] Plump, D. and Steinert S. (2004) Towards Graph Programs for Graph Algorithms. In Graph Transformations, Second International Conference, ICGT 2004,Springer LNCS 3256, 128–143.
© Copyright 2026 Paperzz