32
Fundamenta Informaticae XXI (2001) 1001–1032 1001 IOS Press Lazy Graph Transformation Fernando Orejas * Universitat Polit` ecnica de Catalunya, Spain [email protected] Leen Lambers Hasso Plattner Institut, Universit¨ at 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 cho- sen 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 ap- proach 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` atics, Universitat Polit` ecnica 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.

Lazy Graph Transformation - Departament de Llenguatges i

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Fundamenta Informaticae XXI (2001) 1001–1032 1001

IOS Press

Lazy Graph Transformation

Fernando Orejas∗

Universitat Politecnica de Catalunya, Spain

[email protected]

Leen Lambers†

Hasso Plattner Institut, Universitat Potsdam, Germany

[email protected]

Abstract. Applying an attributed graph transformation rule to a given object graph always impliessome kind of constraint solving. In many cases, the given constraints are almost trivial to solve. Forinstance, this is the case when a rule describes a transformation G ⇒ H , where the attributes of Hare obtained by some simple computation from the attributes of G. However there are many othercases 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 completelysolved when defining the matching of the given transformation rule. This kind of early binding iswell-known from other areas of Computer Science to be inadequate. For instance, the solution cho-sen for the constraints associated to a given transformation step may be not fully adequate, meaningthat 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 aspectsrelated with attributed graphs, including attributed graph transformation, we present a new approachthat, based on the new notion of narrowing graph transformation rule, allows us to delay constraintsolving when doing attributed graph transformation, in a way that resembles lazy computation. Forthis reason, we have called lazy this new kind of transformation. Moreover, we show that the ap-proach is sound and complete with respect to standard attributed graph transformation. A runningexample, 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 Informatics, Universitat Politecnica deCatalunya, 08034 Barcelona, Spain∗The work of this author was partially supported by the MEC project FORMALISM (ref. TIN2007-66523) and by the AGAURgrant 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 - CorrectModel 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 ofgraph transformation. In practice, an attributed graph transformation rule is like a normal rule, but somenodes or edges are labelled by expressions over some given variables. Then, defining a match m of arule to a given object graph, whose attributes are some concrete values, means finding the values thatmust be assigned to the variables occurring in the rule, so that the value of each expression associatedto each node or edge e on the left-hand side of the rule coincides with the value of the correspondingattribute associated to m(e) in the object graph. That is, defining a match of a rule means solvinga set of constraints. In many cases, these constraints are trivial. For instance, when a rule describesa transformation G ⇒ H , where the attributes in H are obtained by some simple computation fromthe attributes in G, e.g. when the expressions used as attributes in the left-hand side of the rules arejust variables, and more general expressions, defined over these variables, only occur in the right-handside. 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 kindof searching (e.g. when the right-hand side of a rule involves a variable which does not occur explicitlyon the left-hand side). In existing approaches to attributed graph transformation these constraints mustbe completely solved when defining the matching of the given transformation rule. Then, finding amatch means choosing one specific solution. This kind of early binding is well-known from other areasof Computer Science to be inadequate. One problem is that the solution chosen for the constraintsassociated to a given transformation step may not be fully adequate, meaning that we may need tobacktrack 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, checkingmeanwhile their satisfiability. Then, not only may we avoid some useless backtracking, but we haveother advantages. On the one hand, checking satisfiability may be computationally simpler than solvinga set of constraints, meaning that it may also be simpler to apply a transformation step. On the otherhand, some constraints which may be difficult to solve at a given moment, may become simpler, eventrivial, 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 thatthe existing approaches [10, 1, 7, 5, 16] were not fully adequate for our purposes. These approachespresented different kinds of technical difficulties together with a limited expressive power for definingconditions on the attributes. To avoid these problems we presented a new formal approach which (webelieve) is conceptually simpler and more powerful than existing approaches. It is simple because, in ourapproach, 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 candefine graph constraints with arbitrary conditions on the attributes as we aimed, but also because we candefine transformation rules that cannot be defined in other approaches, as shown in [14]. Graphs in ourapproach are called symbolic graphs, because the attributes in the graph are represented symbolically byvariables 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 arbitrarysymbolic graphs. As a consequence, we introduce a more general notion of symbolic graph transfor-mation rules, which we have called narrowing rules, and characterize graph transformation by meansof these rules. In addition, we study the compatibility of symbolic graph transformation with the se-mantics of symbolic graphs1, showing that this kind of transformation is compatible with the semanticsof 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 re-spect to the semantics of graphs. Finally, using the notion of narrowing graph transformation, we presenta new approach to symbolic graph transformation that allows us to delay constraint solving when doingattributed graph transformation. In particular we show that this new approach is sound and completewith respect to standard attributed graph transformation, and it is complete and satisfies a property ofextended soundness with respect to symbolic graph transformation. Moreover, a running example, wherea graph transformation system describes some basic operations of a travel agency, shows the practicalinterest of the approach.

The paper is organized as follows. In Section 2 we recapitulate some notions that are used in therest of the paper. In Section 3 we present the category and the semantics of symbolic graphs. Section 4is dedicated to describe how (standard) symbolic graph transformation works. In Section 5 we presentthe new notions of narrowing rules and narrowing graph transformation studying its compatibility withrespect to the semantics of symbolic graphs. Section 6 is dedicated to the new notion of lazy transforma-tion and to prove its soundness and completeness. Finally, in Section 6, we compare our approach withother related work and we draw some conclusions.

This paper is an extended version of [15], presented at ICGT 2010. In particular, in addition to thedetailed proofs of our results, we introduce the new notion of narrowing rules and narrowing transforma-tion, 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 detailon 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 predicatesymbols typed over these sorts. A Σ-algebra A consists of an S-indexed family of sets Ass∈S anda function opA (resp. a relation prA) for each operation op (resp. each predicate pr) in the signature.A Σ-homomorphism h : A → A′ consists of an S-indexed family of functions hs : As → A′ss∈Scommuting 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 yieldsthe value of each term in A. Similarly, TΣ(X) denotes the algebra of all Σ-terms with variables inX , and given a variable assignment σ : X → A, this assignment extends to a unique homomorphism

1This 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 labelledgraph, where nodes and edges may be decorated with labels from a given set. The difference with labelledgraphs, as commonly understood, is that in labelled graphs it is usually assumed that each node or edgeis labelled with a given number of labels, which is fixed a priori. In the case of E-graphs, each node oredge may have any arbitrary (finite) number of labels, which is not fixed a priori. Actually, in the contextof graph transformation, the application of a rule may change the number of labels of a node or of anedge.

Formally, in E-graphs labels are considered as a special class of nodes and the labeling relationbetween a node or an edge and a given label is represented by a special kind of edge. For instance, thismeans that the labeling of an edge is represented by an edge whose source is an edge and whose target isa label.

Definition 2.1. (E-Graphs and morphisms)An E-graph over the set of labelsXG is a tupleG = (VG, XG, EG, E

NLG , EEL

G , sG, sNLG , sEL

G , tG, tNLG , tEL

G )consisting of:

• VG and XG, the sets of graph nodes and of label nodes, respectively.

• EG, ENLG , and EEL

G , the sets of graph edges, node label edges, and edge label edges, respectively.

and the source and target functions:

• sG : EG → VG and tG : EG → VG

• sNLG : ENL

G → VG and tNLG : ENL

G → XG

• sELG : EEL

G → EG and tEL : EELG → 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 mostone (node or edge) label edge e such that x = tjG(e), where j ∈ NL,EL.

Given the E-graphs G and G′, an E-graph morphism f : G → G ′ is a tuple, 〈fV : VG → V ′G, fX :XG → XG′ , fE : EG → E′G, fENL

: ENLG → E′NL

G , fEEL: EEL

G → E′ELG 〉 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 howto replace the labels of an E-graph, and is used to define the semantics of a symbolic graph (cf. Definition3.3):

Orejas, Lambers / Symbolic Graph Transformation 1005

Definition 2.2. (Label substitution)Given an E-graph G = (VG, XG, EG, E

NLG , EEL

G , sG, sNLG , sEL

G , tG, tNLG , tEL

G ), a set of labels X’, anda function h : XG → X ′ we define the graph resulting from the substitution of XG along h, h(G) =(V ′G, X

′, E′G, E′NLG , E′EL

G , sG, s′NLG , s′EL

G , t′G, t′NLG , t′EL

G ), where:

• V ′G = VG, E′G = EG, E

′NLG = ENL

G , E′ELG = EEL

G , s′G = sG, s′NLG = sNL

G , s′ELG = sEL

G , andt′G = tG

• For every e ∈ E′NLG : t′NL

G (e) = h(tNLG (e))

• For every e ∈ E′ELG : t′EL

G (e) = h(tELG (e))

Moreover, h induces the definition of the morphism h : G→ h(G), with h = 〈idV , h, idEG, idENL

, idEEL〉.

Notice that if f : G → H is a morphism such that fV , fE , fENL, and fEEL

are bijections, then wecan 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 givensubstitution. This is obviously an abuse of notation, but we believe that it introduces no confusion whileit simplifies notation.

Reach(G) eliminates all the labels in an E-graph which are not bound to a node or an edge andRestr(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, ENL, EEL, sj , tjj∈G,NL,EL), we define the reachable sub-graph 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 ∈ ENL such that x = tNL(nl), or

• there is an edge label edge el ∈ EEL such that x = tEL(el).

Moreover, given a morphism f : G→ G ′ we denote byReach(f) : Reach(G)→ G′ the restrictionof 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 asthe 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 anE-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 〈G,D〉, where D is a given Σ-algebra, called the data algebra ofthe graph, and G is an E-graph such that the set XG of labels in G 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 = 〈G,D〉 and AG′ = 〈G′, D′〉, an attributed graph mor-phism h : AG → AG′ is a pair 〈hgraph, halg〉, where hgraph is an E-graph morphism, hgraph : G → G′

and halg is a Σ-homomorphism, halg : D → D′ such that the values in D are mapped consistently byhgraph and halg, i.e. for each sort s ∈ S the diagram below commutes:

1006 Orejas, Lambers / Symbolic Graph Transformation

Dshalg //

_

D′s _

XG

hgraph

// XG′

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 technicalresults 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 dataalgebra, 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 classof 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 attributedgraphs, including distances in the edges, that satisfy the well-known triangle inequality. We must notethat 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 thecorresponding graph edges. Actually, in the rest of the paper we will always omit depicting (node oredge) label edges, since we think that the resulting graphs are more intuitive.

- 1 -

with d3 ! d

1+d

2

d1

d2

d3

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 = 〈G,Φ〉, where G isan E-graph over an S-sorted set of variables, used as labels, X = Xss∈S , i.e. XG = ∪s∈SXs, and Φis a set of first-order Σ-formulas with free variables in X and including elements in D as constants.

Orejas, Lambers / Symbolic Graph Transformation 1007

Given symbolic graphs 〈G1,Φ1〉 and 〈G2,Φ2〉 over D, a symbolic graph morphism h : 〈G1,Φ1〉 →〈G2,Φ2〉 is an E-graph morphism h : G1 → G2 such that D |= Φ2 ⇒ h(Φ1), where h(Φ1) is the set offormulas 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, sincefirst-order formula satisfiability is an undecidable problem. In principle, the only condition that weneed to ensure that the results presented in this paper hold is that the given class of formulas is closedunder conjunction, disjunction and existential quantification, because these are the connectives neededto 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 oftyped graphs using the standard technique. In particular, we just have to see typed graphs as morphismsSG→ TG, where SG is a symbolic graph and TG is the given type graph, which is a specific symbolicgraph (i.e. the category of typed symbolic graphs over the type graph TG is the slice category over TG).In particular, type graphs TG must be symbolic graphs TG = 〈ETG,False〉, where ETG is an E-graphover a set of labels XETG consisting of just one variable for each sort in the given data signature, andFalse is the set consisting just of the false formula. In this way, given a symbolic graph SG = 〈G,Φ〉,any (typing) morphism t : G→ ETG for G is also a (typing) morphism t : SG→ TG.

In [14], we showed that symbolic graphs are an adhesive HLR category taking as M-morphisms allinjective 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 : 〈G,Φ〉 → 〈G′,Φ′〉 is a monomorphism such that XG

∼= XG′ , i.e. hX is a bijection,and D |= h(Φ)⇔ Φ′

We will not study in detail all the constructions and results that are needed to prove that SymbGraphsDis an adhesive HLR category (the interested reader is addressed to [14]). However, it is important to seehow 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−Graphsand D |= Φ3 ⇔ (g1(Φ1) ∪ g2(Φ2)).

〈G0,Φ0〉

(1)

h1 //

h2

〈G1,Φ1〉g1

G0h1 //

(2)h2

G1

g1

〈G2,Φ2〉 g2

// 〈G3,Φ3〉 G2 g2// G3

Therefore, as said above, we have:

Theorem 3.1. [14] SymbGraphsD is adhesive HLR.

1008 Orejas, Lambers / Symbolic Graph Transformation

One may wonder whether SymbGraphsD is an adhesive category, in particular if it is adhesiveHLR when M-morphisms are just monomorphisms. The answer is no, as it can be seen from the counter-example 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 vanKampen square [11].

〈G, true〉

ss ''

〈G, true〉

''

〈G, false〉

ss〈G, false〉

〈G, true〉

ss ''〈G, false〉

''

〈G, false〉

ss〈G, false〉

In particular, we may easily check that all the morphisms in the diagram are monomorphisms inSymbGraphsD. Moreover, we can also check easily that the top and bottom squares are pushoutsand 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 complementsare not unique as the following counterexample shows:

Example 3.2. Let us consider the morphisms f : 〈G, true〉 → 〈G, false〉 and g : 〈G, false〉 →〈G, false〉, where both morphisms are identities as E-graph morphisms, then it is easy to see that thediagrams below are pushouts:

〈G, true〉

(1)

f //

〈G, false〉g

〈G, true〉 f //

(2)

〈G, false〉g

〈G, false〉 // 〈G, false〉 〈G, true〉 // 〈G, false〉

3.2. Semantics of symbolic graphs

As we said above, we may consider that a symbolic graph SG denotes a class of attributed graphs. Inparticular the class of all attributed graphs that can be obtained by replacing the variables in SG by values2If the given formulas do not include variables, pullbacks in SymbGraphsD are defined in terms of pullbacks inE−Graphs, where the associated formula of the resulting graph is the disjunction of the formulas of the graphs involved.

Orejas, Lambers / Symbolic Graph Transformation 1009

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 〈G,Φ〉 over a data algebra D is a class of attributed graphs defined:

Sem(〈G,Φ〉) = 〈σ(G), D〉 | σ : 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 theassociated condition is unsatisfiable.

Every attributed graph may be seen as a symbolic graph by just replacing all its values by variablesand by including an equation xv = v, for each value v in the data algebra, into the corresponding set offormulas, where xv is the variable that has replaced the value v. We call these kind of symbolic graphsgrounded symbolic graphs. For instance, in Figure 2, on the right, we can see the symbolic representationof the attributed graph on the left. However, to enhance readability, in our figures we will often showvalues of the given data algebra as attributes of the given graph, instead of replacing them by variablesand showing the corresponding equation. This is done, for instance, in Example 3.3, where a groundedsymbolic graph is displayed as an attributed graph.

- 1 -

with d1= 12, d2= 15, d3= 18

12

15

18

d1

d2

d3

Figure 2. Attributed graph and grounded symbolic graph

Definition 3.4. (Grounded symbolic graphs)A symbolic graph 〈G,Φ〉 over a data algebra D is grounded if

1. 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 variablexv ∈ XG.

Moreover, we define GSymbGraphsD as the full subcategory of SymbGraphsD consisting ofall 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 everyattributed graph AG there is a unique grounded symbolic graph (up to isomorphism) GSG(AG) suchthat Sem(GSG(AG)) consists of AG. In particular, the E-graph associated to GSG(AG) is obtainedsubstituting every data value v in a set of labels by a variable xv, and the set of formulas in the symbolicgraph 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, aspresented in [3], and the subcategory of grounded symbolic graphs over D are equivalent, provided thatthe given data algebra is finitely generated. As a consequence, we may identify them. For instance, wemay consider that the semantics of a symbolic graph is a class of grounded symbolic graphs.

We may notice that, if h : SG → SG′ is a symbolic graph morphism and SG′ is grounded thenthe condition D |= Φ′ ⇒ h(Φ), that the symbolic morphism h must satisfy, can be represented as aconstraint satisfaction problem:

Fact 3.1. Given a symbolic graph SG = 〈G,Φ〉 and a grounded symbolic graph SG′ = 〈G′,Φ′〉, anE-graph morphism h : G → G′ is a symbolic graph morphism if and only if D |= h′(Φ), whereh′ : XG → D is the mapping defined ∀x ∈ XG : h′(x) = v if h(x) = xv.

Proof:By definition, we know that h is a symbolic graph morphism if and only if D |= Φ′ ⇒ h(Φ). This isequivalent to showing that, for every substitution σ, if D |= σ(Φ′) then D |= σ(h(Φ)). Now, Φ′ consistsof all the equations xv = v, therefore the only substitution σ such that D |= σ(Φ′) is σ(xv) = v. But forevery variable x in XG, h′(x) = σ h(x). Therefore, this is equivalent to D |= h′(Φ). ut

The above fact means that defining a morphism from SG = 〈G,Φ〉 into a grounded symbolic graphcan be seen partially as a constraint satisfaction problem. In particular, the morphism must provide valuesto the variables in Φ so that the conditions (constraints) in Φ are satisfied. For instance, in Example 4.2we see an object graph that represents a customer of a travel agency that wants to make a hotel reservationfor two days in Berlin and has a certain budget. Then, in that example, applying a transformation rulethat is supposed to implement this reservation (i.e. defining the match morphism) implies finding a hotela to be bound to a variable h of sort hotel that satisfies two conditions: that a is located in Berlin andthat 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 anysymbolic graph SG and the grounded representation of any attributed graph AG in the semantics of SGthere exists a symbolic morphism between SG and GSG(AG), which is induced by a label substitution.

Fact 3.2. An attributed graph AG = 〈G,D〉 is in the semantics of SG = 〈G′,Φ〉 if and only if there isa symbolic graph morphism h : SG→ GSG(AG) induced by a label substitution.

Proof:If AG ∈ Sem(SG) this means that G = σ(G′) for a given variable substitution σ such that D |= σ(Φ).But this means that we may define h as the morphism associated to σ′ σ, where σ′ is the substitutionthat maps every value v ∈ D to the variable xv. In addition, D |= σ(Φ) implies, by Fact 3.1, that h is asymbolic graph morphism. Conversely, if there is a symbolic morphism h : SG→ GSG(AG) inducedby a given label substitution, we can define an assignment σ : XG′ → D with σ(x) = v if h(x) = x′

Orejas, Lambers / Symbolic Graph Transformation 1011

and the equation x′ = v is in ΦGSG(AG). Then, by Fact 3.1, we know that D |= σ(Φ) implying that theattributed graph 〈σ(G′), D〉 is in Sem(SG). ut

The second fact states that, if AG is in the semantics of SG′ and the variables in SG are a subset ofthe variables of SG′ then any morphism f from a symbolic graph SG to GSG(AG) can be factorizedinto two morphisms f ′ : SG → SG′ and h : SG′ → GSG(AG), where h is the morphism defined inthe previous fact.

Fact 3.3. Given symbolic graphs SG = 〈G,Φ〉 and SG′ = 〈G′,Φ′〉, such thatG is linear (cf. Definition2.1), and given a morphism f : SG → GSG(AG), where AG ∈ Sem(SG′), there is an E-graphmorphism f ′ : SG→ SG′ such that f = h f ′, where h : SG′ → GSG(AG) is the morphism definedin Fact 3.2.

Proof:It is enough to define f ′ as follows:

• For every graph node or edge e, f ′(e) = h−1(f(e)).

• For every label x ∈ XG, f ′(x) = x′, if x is the target in G of some node label edge or of someedge label edge e (i.e. x is attached to a node or an edge via e) and the target of f ′(e) in G′ is x′.

• For every label x ∈ XG, f ′(x) = x′,if x is not attached to any node or edge in G and x′ is anylabel in G′ such that f(x) = h(x′).

It is routine to check that f ′ is an E-morphism because, on the one hand, if h is the morphism inducedby a label substitution, h is a bijection on graph nodes and edges, and on the other hand,G is linear, whichmeans that the definition of f ′ on the labels is correct. Moreover, by definition f = h f ′. ut

Example 3.3. (Introduction to Running Example)In our running example we specify a travel agency in terms of typed symbolic graphs and symbolic graphtransformation rules. In particular, the data signature of our example is:

Sorts int,bool, city,hotel, flightOpns price : hotel→ int

location : hotel→ cityprice : flight→ intdeparture : flight→ citydestination : 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 FlightReser-vation or a HotelReservation, respectively. A Customer has the labels name and bud, describing thetotal budget that the customer is willing to spend for his reservations. A HotelRequest has as labels thenumber 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 100 Munchenh2 90 Berlinh3 85 Berlinh4 70 Kolnh5 200 Berlin

flight price departure destination

f1 175 Berlin Barcelonaf2 115 Berlin Barcelonaf3 150 Barcelona Berlinf4 85 Barcelona Berlin

Figure 3. A data algebra

Traveler

book flight

book hotel

book transfer

book travel

«uses»

«uses»

«uses»

-dep : city

-dest : city

FlightRequest

-name : string

-bud : int

Customer

-loc : city

-nights : int

HotelRequest

dep : city

dest : city

fr : FlightRequest

dep : city

dest : city

fr : FlightRequest

f : flight

: FlightReservationreserveFlight

name : string

bud : int

c : Customer

name : string

bud : int

c : Customer

loc : city

nights : int

hr : HotelRequest

loc : city

nights : int

hr : HotelRequest

h : hotel

: HotelReservationreserveHotel

name : string

bud : int

c : Customer

name : string

bud : int

c : Customer

int, bool, city, hotel, flight

price:hotel->int

location: hotel -> city

price:flight->int

departure: flight -> city

destination: flight -> city

-price : string

-source

-destination

flight

-price : string

-location

hotel

start graph:

city-f : flight

FlightReservation

-h : hotel

HotelReservation

loc : city

nights : int

: HotelRequest

name : string

bud : int

: Customer

dep : city

dest : city

: FlightRequest

dep : city

dest : city

: FlightRequest

-name : string

-bud' : int

Traveler

dep = departure(f) && dest = destination(f) && bud’ = bud - price(f) && bud’ >=0

loc = location(h) && bud’ = bud – (price(h) * nights) && bud’>=0

Figure 4. Type graph

dep and dest, the departure and destination city of the flight, respectively. The HotelReservation andFlightReservation have only one label h and f for the hotel and flight that are reserved, respectively.

Finally, a possible start graph describing the needs of a customer called Alice is depicted in Figure5. In particular, this graph is assumed to be grounded3 and shows a customer with a budget of 450,requesting a hotel for two nights in Berlin, a flight from Barcelona to Berlin and a flight from Berlin toBarcelona.

3As explained above, for readability, it is depicted as an attributed graph

Orejas, Lambers / Symbolic Graph Transformation 1013

!"#$%&%"

'(()*+&,-./

'(()*.(/%&

'(()*/"#01+%"

'(()*/"#$%&

231%14

231%14

231%14

56%7*8*9,/:56%1/*8*9,/:

!"#$%&'()*(+&

50#;%*8*1/",0-5'36*8*,0/

,*+&-.(/

5&(9*8*9,/:50,-./1*8*,0/

0-&("'()*(+&

6%7*8*9,/:6%1/*8*9,/:

+"*8*<&,-./=%>3%1/

6%7*8*9,/:6%1/*8*9,/:

+"*8*<&,-./=%>3%1/

+*8*+&,-./8*<&,-./=%1%"$#/,(0"%1%"$%<&,-./

0#;%*8*1/",0-'36*8*,0/

9*8*?31/(;%"

0#;%*8*1/",0-'36@*8*,0/

9*8*?31/(;%"

&(9*8*9,/:0,-./1*8*,0/

."*8*A(/%&=%>3%1/

&(9*8*9,/:0,-./1*8*,0/

."*8*A(/%&=%>3%1/

.*8*.(/%&8*A(/%&=%1%"$#/,(0"%1%"$%A(/%&

0#;%*8*1/",0-'36*8*,0/

9*8*?31/(;%"

0#;%*8*1/",0-'36@*8*,0/

9*8*?31/(;%"

,0/B*'((&B*9,/:B*.(/%&B*+&,-./

7",9%8.(/%&5C,0/&(9#/,(08*.(/%&*5C*9,/:7",9%8+&,-./5C,0/6%7#"/3"%8*+&,-./*5C*9,/:6%1/,0#/,(08*+&,-./*5C*9,/:

57",9%*8*1/",0-51(3"9%56%1/,0#/,(0

1"#$%&

57",9%*8*1/",0-5&(9#/,(0

%-&("

1/#"/*-"#7.8

2#&35+*8*+&,-./!"#$%&'(+(/45&#-6

5.*8*.(/%&0-&("'(+(/45&#-6

&(9*8*9,/:*D*E%"&,00,-./1*8*,0/*D*F

8*A(/%&=%>3%1/

0#;%*8*1/",0-*D*G&,9%'36*8*,0/*D*HIJ

8*?31/(;%"

6%7*8*9,/:*D*E#"9%&(0#6%1/*8*9,/:*D*E%"&,0

8*<&,-./=%>3%1/

6%7*8*9,/:*D*E%"&,06%1/*8*9,/:*D*E#"9%&(0#

8*<&,-./=%>3%1/

50#;%*8*1/",0-5'36@*8*,0/

,*+&-.(/

!"#$%$!"#&'()'"*+,$--$!".($%$!".(/0&(/10*+,$--$2)!3$%$2)!$4 #'/5"*+,$--$2)!3$6%7

815$%$815&(/10*9,$--$2)!3$%$2)!$: *#'/5"*9,$;$0/<9(.,$--$2)!36%7

Figure 5. Start graph

4. 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 areconstrained by the same set of formulas. This means that we may denote symbolic graph transformationrules as pairs 〈L ← K → R,Φ〉, 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 andright-hand sides of the rule and it may also impose some constraints on the matchings. Moreover, fortechnical reasons we require that L is linear (cf. Definition 2.1), meaning that no label is bound to twodifferent elements in L4.

Definition 4.1. (Symbolic graph transformation rule)A symbolic graph transformation rule is a pair 〈L ← K → R,Φ〉, where L,K,R are E-graphs overthe same set of labels X , L is linear, L ← K → R is a span of E-graph inclusions5, and Φ is a set offormulas 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 withidentical names are preserved as well. The rule includes a formula Φ, expressing that the departure citydep 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 budof the customer is diminished by the price of the reserved flight price(f) and as an extra constraint it isrequired that the new budget bud’ is still greater than or equal to zero. The rule reserveHotel connectsa HotelReservation with a HotelRequest for some Customer. It holds a formula Φ, expressing that thelocation loc of the HotelRequest should be identical to the location of the reserved hotel location(h). Thetotal budget bud of the customer is diminished by the price of the reserved hotel multiplied with the

4If needed we can transform SL into an equivalent linear graph (with the same semantics). We just need to change the repeatedoccurrences of the same variable by new variables and add the corresponding equalities to the given set of formulas.5or, in general, monomorphisms

1014 Orejas, Lambers / Symbolic Graph Transformation

number of nights price(h)*nights and as an extra constraint it is required again that the new budget bud’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 firstrule must be considered to be included in the left-hand side of the rule, even if it is not bound to any nodeor edge of the left-hand side graph. The same happens with the variable h in the second rule, as well aswith bud’ in both rules.

Traveler

book flight

book hotel

book transfer

book travel

«uses»

«uses»

«uses»

-dep : city

-dest : city

FlightRequest

-name : string

-bud : int

Customer

-loc : city

-nights : int

HotelRequest

dep : city

dest : city

fr : FlightRequest

dep : city

dest : city

fr : FlightRequest

f : flight

: FlightReservationreserveFlight

name : string

bud : int

c : Customer

name : string

bud' : int

c : Customer

loc : city

nights : int

hr : HotelRequest

loc : city

nights : int

hr : HotelRequest

h : hotel

: HotelReservationreserveHotel

name : string

bud : int

c : Customer

name : string

bud' : int

c : Customer

int, bool, city, hotel, flight

price:hotel->int

location: hotel -> city

price:flight->int

departure: flight -> city

destination: flight -> city

-price : string

-source

-destination

flight

-price : string

-location

hotel

start graph:

city-f : flight

FlightReservation

-h : hotel

HotelReservation

loc : city

nights : int

: HotelRequest

name : string

bud : int

: Customer

dep : city

dest : city

: FlightRequest

dep : city

dest : city

: FlightRequest

-name : string

-bud' : int

Customer

dep = departure(f) && dest = destination(f) && bud’ = bud - price(f) && bud’ >=0

loc = location(h) && bud’ = bud – (price(h) * nights) && bud’>=0

Figure 6. Graph transformation rules

As usual, the application of a graph transformation rule 〈L ← K → R,Φ〉 to a given symbolicgraph SG can be defined by a double pushout in the category of symbolic graphs:

Definition 4.2. (Symbolic graph transformation)Given symbolic graphs SG and SH over a Σ-algebra D, a symbolic graph transformation rule, r =〈L ← K → R,Φr〉 over D, and a morphism m : 〈L,Φr〉 → SG, we say that SH is a direct trans-formation of SG by r via m, denoted SG =⇒r,m SH , if SH can be obtained by the following doublepushout in SymbGraphsD:

〈L,Φr〉m

〈K,Φr〉? _oo //

〈R,Φr〉

m′

SG SF? _oo // SH

Orejas, Lambers / Symbolic Graph Transformation 1015

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 trans-formation. The first property states that the set of labels and the condition of the given object graphremain invariant after symbolic transformation. The second property states that symbolic transformationpreserves groundedness. The third property shows that the application of a symbolic transformation rulecan be defined in terms of a transformation of E-graphs. Finally, the last condition states that if we canapply a transformation to a given graph SG, then we can also apply (essentially) the same transformationto 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 = 〈L← K → R,Φ〉 over a given data algebra D:

1. If 〈G,Φ′〉 =⇒r,m 〈H,Φ′′〉 then XG = XH and D |= Φ′ ⇔ Φ′′.

2. If 〈G,Φ′〉 =⇒r,m 〈H,Φ′′〉 and 〈G,Φ′〉 is grounded then 〈H,Φ′′〉 is also grounded.

3. If m : L → G is an E-graph morphism, we have that 〈G,Φ′〉 =⇒r,m 〈H,Φ′〉 if and only if thediagram below is a double pushout in E−Graphs and D |= Φ′ ⇒ m(Φ).

L

m

K? _oo //

R

G F? _oo // H

4. If 〈G,Φ′〉 =⇒r,m 〈H,Φ′〉,XG ⊆ X , andD |= Φ′′ ⇒ Φ′ then 〈G∪X,Φ′′〉 =⇒r,im 〈H∪X,Φ′′〉,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 implyingthat the morphisms in the span 〈L,Φ〉 ← 〈K,Φ〉 → 〈R,Φ〉 are M-morphisms. If 〈G,Φ′〉 =⇒r,m

〈H,Φ′′〉, this means that the diagram below is a double pushout in SymbGraphsD:

〈L,Φ〉

m

〈K,Φ〉? _oo //

m′′

〈R,Φ〉

m′

〈G,Φ′〉 〈F,Ψ〉? _oo // 〈H,Φ′′〉

But we know [14] that pushouts in SymbGraphsD preserve M-morphisms (see [14]), hence themorphisms in the span 〈G,Φ′〉 ← 〈F,Ψ〉 → 〈H,Φ′′〉 are also M-morphisms. This means thatXG = XF = XH and D |= Φ′ ⇔ Ψ⇔ Φ′′.

1016 Orejas, Lambers / Symbolic Graph Transformation

2. A direct consequence of the previous item. The reason is that, if Φ′ defines the values of all thevariables in XG, then Φ′′ also defines the values of all the variables in XH = XG.

3. If 〈G,Φ′〉 =⇒r,m 〈H,Φ′〉 this means thatm is a symbolic graph morphism and the diagram belowis a double pushout in SymbGraphsD:

〈L,Φ〉

(1)m

〈K,Φ〉

(2)

? _oo //

m′′

〈R,Φ〉

m′

〈G,Φ′〉 〈F,Φ′〉? _oo // 〈H,Φ′〉

Now, according to Proposition 3.1, this means that the diagram below is a double pushout inE−Graphs. Moreover, since m is a symbolic graph morphism then D |= Φ′ ⇒ m(Φ).

L

(3)m

K

(4)

? _oo //

m′′

R

m′

G F? _oo // H

Conversely, let us suppose that diagrams (3) and (4) are pushouts in E−Graphs. We knowthat if the morphisms in the span L ← K → R are the identity on variables then so are (upto isomorphism) the morphisms on the span G ← F → H . This means that the morphismsm, m′ and m′′ coincide on the variables and, as a consequence, if D |= Φ′ ⇒ m(Φ), thenD |= Φ′ ⇒ m′(Φ) and D |= Φ′ ⇒ m′′(Φ). Hence all the morphisms in (1) + (2) are symbolicgraphs morphisms. Therefore, to prove that (1) and (2) are pushouts, according to Prop. 3.1, wehave to prove that D |= Φ′ ⇔ Φ′ ∪ m(Φ) and D |= Φ′ ⇔ Φ′ ∪ m′(Φ), but this is obvious ifD |= Φ′ ⇒ m(Φ) and D |= Φ′ ⇒ m′(Φ).

4. If 〈G,Φ′〉 =⇒r,m 〈H,Φ′〉 this means thatD |= Φ′ ⇒ m′(Φ) andH can be obtained by the doublepushout below:

L

m

K? _oo //

m′′

R

m′

G F? _oo // H

We know that im satisfies the gluing conditions with respect to r, since i just adds some variablesthat are not connected to any node or edge. Therefore, we can build the following double pushoutdiagram:

L

im

K? _oo //

R

G ∪X F ∪X? _oo // H ∪X

But, if D |= Φ′′ ⇒ Φ′ and i(m′(Φ)) = m′(Φ), since i is the equality on all labels in XG, thenD |= Φ′′ ⇒ i(m′(Φ)) implying 〈G ∪X,Φ′′〉 =⇒r,im 〈H ∪X,Φ′′〉.

Orejas, Lambers / Symbolic Graph Transformation 1017

ut

The fact that the formula constraining the variables of the E-graph H after transformation is thesame formula for the graph G before transformation does not mean that the attributes in the graph do notchange after transformation. The reason is that the transformation may change the bindings of variablesto nodes and edges, as the example below shows. Moreover, according to Fact 3.1, if we apply the rule〈L ← K → R,Φ〉 to a grounded symbolic graph SG = 〈G,Φ′〉, the condition D |= Φ′ ⇒ m(Φ) canbe seen as the constraint satisfaction problem where we find the values to assign to the variables in Φ, sothat 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 toa given start graph as presented in Example 3.3, describing a customer that would like to reserve a hotelfor 2 days in Berlin and, in addition, would also like to reserve a flight from Barcelona to Berlin andreturn.

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int = 450

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequest

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int = 50

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequesth : hotel = h5: HotelReservation

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequesth : hotel: HotelReservation

f : flightfr1 : FlightReservation

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequesth : hotel: HotelReservation

f : flightfr1 : FlightReservation

f : flightfr2 : FlightReservation

Berlin = location(h) && bud = 450 – (price(h) * 2) && bud >=0

Berlin = location(h) && Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && bud = 450 –(price(h) * 2) - price(fr1.f) && bud >=0

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

int, bool, city, hotel, flight

price:hotel->intlocation: hotel -> cityprice:flight->intdeparture: flight -> citydestination: flight -> city

price

100

90

85

70

location

München

Berlin

Berlin

Köln

hotel

h1

h2

h3

h4

price

175

115

150

85

departure

Berlin

Berlin

Barcelona

Barcelona

destination

Barcelona

Barcelona

Berlin

Berlin

flight

f1

f2

f3

f4

Possible solutions in the form (h,fr1.f,fr2.f,bud): (h2,f4,f1,440),(h3,f4,f1,430),(h2,f3,f2,445),(h3,f3,f2,435),(h2,f4,f2,380),(h3,f4,f2,370)

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 which is smaller. E.g. by adding inequalities of the following kind price(h) <= price(h’), where h’ is a variable present as a label in the E-graph of the rule, but without incoming edges. Another alternative in the formalization would be to allow more variables in the formulas as the number of labels present in the E-graph.

reserveHotel

reserveFlight

reserveFlight

Figure 7. Symbolic transformation

In this transformation, a hotel in Berlin is chosen non-deterministically. This choice is made whendefining the matching between the left-hand side of the rule and the given graph. The reason is that, assaid above, even if it is not explicitly depicted, the left-hand side of ReserveHotel is supposed to includethe variable h, because that variable is explicitly in the right-hand side of the rule and hence it shouldalso be included in all the graphs in the rule. Then, when defining the match morphism we must bindthat variable to some hotel hi in Dhotel such that the formula

Berlin = location(hi) && bud’=450-(price(hi)*2) && bud’>=0

is satisfied. Here, the chosen hotel, h5, satisfies the above formula for h=h5 and bud’=50. This kind ofearly binding may not be very efficient. For instance, after the transformation defined above no flightreservation is possible, because the budget of the user would not be sufficient anymore for reserving anyflight connecting Barcelona and Berlin. Hence, we would need to backtrack this transformation and totry a different hotel. This situation also occurs when working with attributed graphs and attributed graphtransformation rules as in [3].

As shown in [14], symbolic graph transformation is more powerful than attributed graph transforma-tion as presented in [3]. In particular, any attributed graph transformation rule r can be represented bya symbolic graph transformation rule SR(r) such that an attributed graph AG can be transformed by r

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 bySR(r) intoGSG(AH). This representation is quite obvious. If ar = AL← AK → AR is an attributedgraph transformation rule, usually this means thatAL, AR andAK are graphs over the term algebra, i.e.they include terms (with variables) as labels. This means that we can, straightforwardly, represent r as asymbolic graph transformation rule SR(r) replacing the graphs involved by their corresponding associ-ated grounded graphs. Note that, in this case, the conditions in the rule (which would coincide with theconditions in the grounded graphsGSG(AL), GSG(AR), andGSG(AK)) would be equationsXt = t,where t is a term occurring as an attribute in the rule. In this context, as said above, it is proven that, givenattributed graphs AG,AH , AG =⇒r,m AH if and only if GSG(AG) =⇒SR(r),GSG(m) GSG(AH).However, the converse is not true. In [14], we also proved that there are symbolic rules that cannot besimulated by attributed graph transformation rules.

5. Narrowing rules and narrowing graph transformation

As we have seen above, symbolic graph transformation can be considered powerful enough to specifytransformations of attributed graphs as studied in [3]. However, the kind of rules that we have studied inSection 4 are not powerful enough to specify transformations of arbitrary symbolic graphs that may beconsidered reasonable. For instance, given the start graph G in Figure 8, we would be unable to applythe rule ReserveHotel to G. The problem is that we cannot match the variable h, which (as said above) isimplicitly in the left hand side of the rule, to any variable in G. We could think that a possible solution isto assume that all symbolic graphs implicitly include a denumerable set of variables of each sort, so thath can be matched to some variable in G of sort hotel6. However, this is not enough. If f is supposed tobe the match morphism then the condition in G (i.e. true) must imply f(Φ), where Φ is the conditionof the rule. However, in general, this is obviously false, since true only implies tautologies.

-dep : city-dest : city

FlightRequest

-name : string-bud : int

Customer

-loc : city-nights : int

HotelRequest

-f : flightFlightReservation

-h : hotelHotelReservation

Customer

HotelRequest FlightRequest

FlightReservationHotelReservation

string

int

city

hotel flight

name

nightsdep

dest

hf

loc

bud

-name : string-bud : int

Customer-loc : city-nights : int

HotelRequest

Figure 8. Start graph

The problem is that a rule consisting of a span of M-morphisms can transform the structure of anobject graph or change the binding of attributes to nodes or edges of the object graph, but it cannotadd new information to the graph, where this new information is represented by new variables and newconditions over the variables. To overcome this problem, we consider a more general kind of rules, whichwe call narrowing transformation rules, because, as we may see below, when applied to a symbolicgraph, it restricts or narrows their associated conditions by adding the conditions of the rule. These rulesconsist of a span of monomorphisms, where only the left morphism is assumed to be an M-morphism.

6We may note that, in Example 4.2, the start graph does implicitly include a denumerable set of variables, even if they are notdepicted in Figure 5. The reason is that, formally, that graph is assumed to be grounded, which means that it includes a variableper each existing data value.

Orejas, Lambers / Symbolic Graph Transformation 1019

Definition 5.1. (Narrowing graph transformation rule)A narrowing graph transformation rule over a Σ-algebra D is a triple 〈ΦL, L ← K → R,ΦR〉, whereL,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 〈K,ΦL〉 → 〈L,ΦL〉 is an M-morphism guarantees that thepushout complement in a rule application is unique, if it exists (see Example 3.2). This means that wemay define symbolic graph transformation, using narrowing rules, by double pushouts, in the standardway:

Definition 5.2. (Symbolic graph transformation with narrowing rules)Given symbolic graphs SG and SH over a Σ-algebraD, a narrowing rule, r = 〈ΦL, L← K → R,ΦR〉over D, and a morphism m : 〈L,ΦL〉 → SG, we say that SH is a direct transformation of SG by r viam, denoted SG =⇒r,m SH , if SH can be obtained by the double pushout in SymbGraphsD:

〈L,ΦL〉

(1)m

〈K,ΦL〉

(2)

? _oo //

〈R,ΦR〉

m′

SG SF? _oo // SH

and Sem(SH) is not empty. As usual, we write SG =⇒ SH if the given rule and match can be leftimplicit, 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 theabove double pushout if 〈G,Φ〉 =⇒r,m 〈H,ΦSH〉, could be unsatisfiable in D, which means that thesemantics of 〈H,Φ∪m′(ΦR)〉would be empty. Obviously, it makes little sense to make a transformationwhose 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 canbe defined in terms of E-graph transformations. As in Proposition 4.1, this is just a consequence of howpushouts in SymbGraphsD are defined.

Fact 5.1. Given a narrowing transformation rule r = 〈ΦL, L ← K → R,ΦR〉 over D and an E-graphmorphism m : L → G, we have that 〈G,Φ〉 =⇒r,m 〈H,Φ ∪m′(ΦR)〉 if and only if the diagram belowis a double pushout in E−Graphs and D |= Φ⇒ m(ΦL).

L

(1)m

K

(2)

? _oo //

R

m′

G F? _oo // H

Remark 5.1. Obviously, narrowing rules are a generalization of symbolic graph transformation rules,in the sense that every symbolic rule r = 〈L ← K → R,Φr〉 can be seen as the narrowing rule

7or, in general, monomorphisms

1020 Orejas, Lambers / Symbolic Graph Transformation

narrow(r) = 〈Φr, L ← K → R,Φr〉. Then, as a consequence of the definition of graph transforma-tion, 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-graphtransformation means that it is easy to extend the fundamental results that characterize graph transfor-mation (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, equiv-alently, of grounded symbolic graphs. Therefore symbolic graph transformations, with standard rules orwith narrowing rules can be seen as transformations of specifications. In this context, one may ask ifgraph 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 correspondingtransformation 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 nar-rowing transformation rule r = 〈ΦL, L ← K → R,ΦR〉, every transformation SG =⇒r,m SH ,and every AH ∈ Sem(SH), there is an AG ∈ Sem(SG), such that GSG(AG) =⇒r,hm SH ′ andAH ∈ Sem(SH ′), where h : SG→ GSG(AG) is the morphism defined by Fact 3.2.

Moreover, symbolic graph transformation is strongly compatible with the semantics of symbolicgraphs if, in addition, for every AG ∈ Sem(SG), if GSG(AG) =⇒r,f SH

′ and f is factorized intohm, with h : SG→ GSG(AG) andm : L→ G, according to Fact 3.3, there is a direct transformationSG =⇒r,m SH such that Sem(SH ′) ⊆ Sem(SH).

Notice that, in the definition of strong compatibility, Fact 3.3, only ensures that m is an E-graphmorphism. Therefore, to ensure strong compatibility we would need to prove first that m is a symbolicgraph morphism. Then, we have:

Theorem 5.1. Symbolic graph transformation with narrowing rules is compatible, but not strongly com-patible, with the semantics of symbolic graphs.

Proof:

• Compatibility: Let SG = 〈G,ΦSG〉, SH = 〈H,ΦSH〉, AH ∈ Sem(SH), SH ′ = GSG(AH) =〈H ′,ΦSH′〉, r = 〈ΦL, L ← K → R,ΦR〉, and suppose that SG =⇒r,m SH . This means thatdiagrams (1) and (2) below are pushouts in the category of E-graphs, ΦSH = ΦSG∪m′(ΦR) and,according to Fact 3.2 there is a morphism h′ : SH → SH ′ such that h′ is induced by a label sub-stitution and D |= ΦSH′ ⇒ h′(ΦSH). Now, we know that XL = XK ⊆ XR, therefore, withoutloss of generality, we may assume that XG = XF ⊆ XH . Then, we can define a substitution σover the variables in G as σ(x) = h′(x). Let G′ = σ(G), let F ′ = σ(F ), and let h : G → G′

and f : F → F ′ be the corresponding morphisms induced by σ. Then diagrams (3) and (4) beloware obviously pushouts, where the monomorphisms F ′ → G′ and F ′ → H ′ are defined like themonomorphisms F → G and F → H on graph nodes and edges and they are the identity on thevariables.

Orejas, Lambers / Symbolic Graph Transformation 1021

L

(1)m

K

(2)

? _oo //

R

m′

G

(3)h

F

(4)f

? _oo // H

h′

G′ F ′? _oo // H ′

This means that (1) + (3) and (2) + (4) are pushouts, and thus 〈G′,Φ′〉 =⇒r,hm 〈H ′,Φ′ ∪ h′ m′(ΦR)〉, where Φ′ = x = v | x ∈ X ′G, (x = v) ∈ ΦSH′. Notice that this definition ofΦ′ is correct since all the variables in G′ are in H ′, and SH ′ is a grounded model, so for eachvariable x in H ′ there should be an equation x = v in ΦSH′ . Finally, we can easily see thatAH ∈ Sem(〈H ′,Φ′ ∪ h′ m′(ΦR)). It is enough to notice that, by construction, we can obtainAH replacing in H ′ each variable x by the value v, if (x = v) ∈ ΦSH′ .

• Strong compatibility: To prove that symbolic graph transformation with narrowing rules is notcomplete in the above sense, it is enough to consider the following counter example. Let SG be asymbolic graph over the integers data algebra with only one node labelled with a variable x, andwith the empty set of conditions. And consider a rule that says that if we have a graph consistingof a node labelled with a variable y whose value is 2 (i.e. ΦL consists of the equation y = 2) thenwe can replace y by z whose value is 3. Now, we cannot apply that rule to SG with the obviousmatching, since the empty set of conditions does not imply x = 2. However, we can apply the ruleto the grounded graph that includes the equation x = 2.

ut

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 implythe conditions of the left-hand side of the rule, the solution is to allow this application independently ofthese 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 = 〈G,ΦSG〉 over a Σ-algebra D, a narrowing transformation rule r =〈ΦL, L← K → R,ΦR〉 over D, and an E-graph morphism m : L→ G, we define the direct narrowingtransformation of SG by r viam, denoted SGVr,m SH , as the symbolic graph SH = 〈H,ΦSH〉, suchthat Sem(SH) 6= ∅, where H is obtained by the double pushout in E−Graphs below:

L

(1)m

K

(2)

? _oo //

R

m′

G F? _oo // H

and where ΦSH = ΦSG ∪m′(Φ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 = 〈L←K → R,Φr〉 is equivalent to symbolic transformation with the narrowing rule r = 〈∅, L ← K →R,Φr〉.

We can see that narrowing graph transformation is more general than symbolic graph transformationwith narrowing rules:

Fact 5.2. Given r = 〈ΦL, L← K → R,ΦR〉, if SG =⇒r,m SH then SGVr,m SH .

Proof:According to Fact 5.1, if SG =⇒r,m SH , where SG = 〈G,ΦSG〉 and r = 〈ΦL, L ← K → R,ΦR〉,then SH = 〈H,ΦSG ∪m′(ΦR)〉, where H is obtained by the double pushout diagram below:

L

m

K? _oo //

R

m′

G F? _oo // H

But, by definition of narrowing graph transformation, this means SGVr,m SH . ut

The converse, obviously, is not true in general. To end this section, we can show the strong compati-bility of narrowing transformation with respect to the semantics of symbolic graphs:

Theorem 5.2. Narrowing graph transformation is strongly compatible with the semantics of symbolicgraphs.

Proof:

• Compatibility: The proof is the same as the proof of compatibility in Theorem 5.1

• Strong compatibility: If AG ∈ Sem(SG), with SG = 〈G,ΦSG〉, and GSG(AG) Vr,hm SH ′,where GSG(AG) = 〈G′,ΦGSG(AG)〉, h : SG → GSG(AG) is the morphism defined by Fact3.2, and m : L→ G, this means that SH ′ = 〈H ′,ΦGSG(AG) ∪m′(ΦR)〉, where H ′ is obtained bythe double pushout below:

L

(1)hm

K

(2)

? _oo //

R

m′

G′ F ′? _oo // H ′

but, given the match m : L→ G, we can also apply the transformation SGVr,m SH:

L

(3)m

K

(4)

? _oo //

R

m′′

G F? _oo // H

where SH = 〈H,ΦSG ∪m′′(ΦR)〉. Now, pushouts (1) and (2) can be decomposed:

Orejas, Lambers / Symbolic Graph Transformation 1023

L

(3)m

K

(4)

? _oo //

R

m′′

G

(5)h

F

(6)

? _oo // H

h′

G′ F ′? _oo // H ′

where m′ = h′ m′′. On the one hand, we know that XL ⊆ XR, this means that XG ⊆ XH

and XG′ ⊆ XH . On the other hand, we also know that h is a morphism induced by a labelsubstitution, implying that it is a bijection on graph nodes and edges. This means that h′ is also abijection 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 ′) we have that AH ∈ Sem(SH).

ut

6. Lazy graph transformation

In Example 4.2 we saw that, when defining a match for a rule r = 〈L ← K → R,Φr〉, this matchmust also be defined on variables that are bound to a node or edge in R but not bound to any node oredge in L (i.e. intuitively, these variables are not part of L). This forces us to bind these variables tooearly, implying that we may need to backtrack afterwards, as the example showed. The basic idea ofour approach to avoid this is that, when applying a rule, we do not need to match these variables. Wedo this using two ideas. First, instead of applying (standard) symbolic graph transformation with thegiven rule, we apply narrowing graph transformation. In this way, we do not ask the given match tosatisfy the conditions of the rule, but we only add these conditions afterwards. So, in a sense, we arepostponing the satisfaction of the associated constraints. However, this is not enough, because the matchmorphism still has to bind the variables in L that are not bound to any node or edge. Then, the secondidea is that the match morphism for r should not be defined on L, but on Reach(L) (cf. Definition2.3). This is equivalent to transforming each rule into a narrowing rule, whose E-graph in the left-handside is not L but Reach(L) and whose left condition is empty. As a consequence, when we apply theassociated 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-matchedvariables 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 resultingcondition. In particular, formula simplification can be considered correct because two symbolic graphsare isomorphic when their corresponding E-graphs are identical (or isomorphic) and their conditions areequivalent. In particular, applying some simplifications after a transformation may be interesting from apractical 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 = 〈L← K → R,Φr〉 we define its associated lazy rule as the narrowingrule Lazy(r) = 〈∅, Reach(L) ← Restr(K,XReach(L)) → R,Φr〉. Then, given a symbolic graphSG = 〈G,ΦG〉 and a morphism m : Reach(L)→ G, we define the lazy transformation of SG by r via

m, denoted SG l=⇒r,m SH as the narrowing transformation SGVLazy(r),m SH .

1024 Orejas, Lambers / Symbolic Graph Transformation

This means that SG l=⇒r,m SH if SH = 〈H,ΦH〉, where H is obtained by the double pushout

below in the category of E-graphs:

Reach(L)

(1)m

Restr(K,XReach(L))

(2)

? _oo //

R

m′

G F? _oo // H

and where ΦH = ΦG ∪m′(Φr). As usual, we write SG l=⇒ SH if the given rule and match can be left

implicit, and we write l=⇒

∗to denote the reflexive and transitive closure of l

=⇒.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-emptysemantics.

Example 6.1. For example, if we apply the rule ReserveHotel as in Example 4.2 without binding thevariable h to some concrete value hi inDhotel, then we obtain a lazy graph transformation step as depictedin 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 formulais satisfiable.

Let us now study the relation between symbolic graph transformation and lazy transformation for thesame rule. In particular, we are interested in studying if every symbolic transformation can be imple-mented in terms of a lazy transformation and, vice versa, if every lazy transformation corresponds to asymbolic transformation. More precisely, we study this issue with respect to the semantics of specifica-tions. These properties are formulated as follows:

1. Soundness For every lazy transformation SG l=⇒

∗SH and every attributed graphAH ∈ Sem(SH)

there is a symbolic transformation SG =⇒∗ SH ′ such that AH ∈ Sem(SH ′).

2. Completeness For every symbolic transformation SG =⇒∗ SH there is a lazy transformation

SGl

=⇒∗SH ′ such that Sem(SH) ⊆ Sem(SH ′).

Notice that, when the given SG is a grounded graph, the above properties ensure that we can getexactly the same results with both kinds of transformation, although, in the case of lazy transformationwe may need to perform some constraint solving after the transformation process, as we will see in theexample below.

The first result tells us that, when SH is an arbitrary symbolic graph, lazy graph transformation isa complete implementation of symbolic graph transformation, but it may be considered, technically, notsound. In particular, it may be possible to apply a lazy transformation to a graph SG = 〈G,ΦG〉 usingthe rule r = 〈L← K → R,Φr〉, but it may be impossible to apply the same rule to SG to do symbolic

Orejas, Lambers / Symbolic Graph Transformation 1025

transformation. The reason is that for symbolic transformation we require thatD |= ΦG ⇒ m(Φr), for agiven match m, while in the case of lazy transformation it may be enough that ΦG ∪m(Φr) is satisfiablein D. This may happen, for instance, if the condition on G is 0 < X < 5 and the condition on the rule is3 < X < 7. In that case, we would be unable to apply symbolic graph transformation, since 0 < X < 5does not imply 3 < X < 7. However, it could be possible to apply lazy transformation and, then, theresulting condition would be 0 < X < 5 ∧ 3 < X < 7, or equivalently 3 < X < 5. Instead, we willshow 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 = 〈G,ΦG〉, then:

1. Extended soundness For every lazy transformation SG l=⇒

∗SH , with SG = 〈G,ΦSG〉 and

SH = 〈H,ΦSH〉 there is a symbolic transformation 〈G ∪ XH ,ΦSH〉 =⇒∗ SH (up to isomor-phism), where G∪XH denotes the graph obtained by adding to G all the variables in H (actuallythe 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

SGl

=⇒∗SH ′ such that Sem(SH) ⊆ Sem(SH ′).

Proof:

1. Extended Soundness Given the lazy transformation SG l=⇒

∗SH , with SG = 〈G,ΦSG〉 and

SH = 〈H,ΦSH〉 we prove that there is a symbolic transformation 〈G ∪ XH ,ΦSH〉 =⇒∗ SHby induction on the length of the derivation. If SG = SH , then the case is trivial. For the

general case, let us suppose that SG l=⇒

∗SG1 and SG1

l=⇒r,m SH , with SG1 = 〈G1,ΦSG1〉,

SH = 〈H,ΦSH〉 where H is defined by the diagram below:

Reach(L)

(1)m

Restr(K,XReach(L))

(2)

? _oo //

R

m′

G1 F1

? _oo // H

and ΦSH = ΦSG1 ∪m′(Φr).

By induction, we may assume that there is a symbolic transformation 〈G∪XG1 ,ΦSG1〉 =⇒∗ SG1.By Proposition 4.1.4, this means that 〈G∪XH ,ΦSH〉 =⇒∗ 〈G1∪XH ,ΦSH〉, since XG∪XG1 ⊆XH and D |= ΦSH ⇒ ΦSG1 . Therefore, we have to prove that there is a match m1 : SL →〈G1∪XH ,ΦSH〉 such that 〈G1∪XH ,ΦSH〉 =⇒r,m1 SH . Now, without loss of generality, we mayassume that XG1 = XF1 ⊆ XH and that m′ 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 : 〈L,Φr〉 → 〈G1 ∪XH ,ΦSH〉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 symbolicmorphism since D |= ΦSH ⇒ m1(Φr), since ΦSH = ΦSG1 ∪m′(Φr) and m′(Φr) = m(Φr) =

1026 Orejas, Lambers / Symbolic Graph Transformation

m1(Φr). Hence, we have the direct transformation 〈G1 ∪XH ,ΦSH〉 =⇒r,m1 〈H ′,ΦSH〉, whereH ′ is defined by the following double pushout diagram:

L

(3)m1

K

(4)

? _oo //

R

m′1

G1 ∪XH F ′1? _oo // H ′

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 m′ isthe equality for every variable in (XR \XReach(L)) and, hence, XH = XG1 + (XR \XReach(L)).Therefore, F ′1 = F1 + (XL \ XReach(L)). But then pushout (2) can be decomposed in the twopushouts below:

Restr(K,XReach(L)) //

K

(4)

//

R

m′1

F1 // F ′1

// H ′

and this means that H = H ′ (up to isomorphism), implying 〈G1 ∪XH ,ΦSH〉 =⇒r,m1 SH .

2. Completeness We proceed by induction on the length of the transformation. In particular we will

prove that if SG =⇒∗ SH , with SH = 〈H,ΦSH〉, then SG l=⇒

∗SH ′, with SH ′ = 〈H ′,ΦSH′〉,

and there is a label substitution h : XH′ → XH such that h(H ′) = H andD |= h(ΦSH′)⇔ ΦSH .We may notice that this implies that if AH ∈ Sem(SH) then AH ∈ Sem(SH ′). The reason isthat if AH ∈ Sem(SH) this means that there is a substitution σ such that AH = 〈σ(H), D〉and D |= σ(ΦSH), but this implies that AH = 〈σ(h(H ′)), D〉 and D |= σ(h(ΦSH′)) and, so,AH ∈ Sem(SH ′).

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 = 〈G1,ΦSG1〉 and SH = 〈H,ΦSH〉, with ΦSG1 =ΦSH , since graph conditions remain invariant after symbolic graph transformation with symbolictransformation rules (see Proposition 4.1.3) and where H is defined by the double pushout below:

L

(1)m

K

(2)

? _oo

// R

m′

G1 F? _oo

j// H

By induction, we may assume that there is a lazy transformation SG l=⇒

∗SG′1 with SG′1 =

〈G′1,ΦSG′1〉 and a label substitution h1 : XG′1

→ XG1 such that h1(G′1) = G1 and D |=h1(ΦSG′1

) ⇔ ΦSG1 . Now, we define the match morphism m1 : Reach(L) → G′1 as follows.For any graph node or any edge e ∈ Reach(L):

Orejas, Lambers / Symbolic Graph Transformation 1027

• For any graph node or any edge e ∈ Reach(L): m1(e) = h−11 (m(e))

• For every label x ∈ XReach(L), where x is attached to some node or edge by a node labeledge or an edge label edge e (i.e. e ∈ ENL ∪ EEL and tL(e) = x)8: m1(x) = y if y is thetarget of m1(e) in G′1.

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 atmost one node or edge. We may notice that, as a consequence of the commuting properties of targetfunctions 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 (mi, and thereforeh m1, satisfy the gluing conditions because m and i satisfy them):

Reach(L)

(3)

_

i

Restr(K,XReach(L))? _oo _

Reach(L)

(4)m1

Restr(K,XReach(L))? _oo

m′′1

L

(1)m

K? _oo

G′1

(5)h1

F ′? _oo

h′′

G1 F? _oo G1 F ′′? _oo

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 andh1 m1 = m i then F = F ′′. Thus, h′′ is a morphism from F ′ to F . Moreover, since h is amorphism induced by label substitution, so is h′′. Let us now consider the diagram below:

Restr(K,XReach(L))

(6)

//

m′′1

R

m′1

F ′

(7)

j′//

h′′

H ′

h′

F

j// H

where (6) is a pushout, j is defined in diagram (2) above, and h′ is the unique morphism that satis-fies h′ j′ = j h′′ and h′ m′1 = m′, by the universal property of pushout (6). Please, notice thatdiagram (7) is not necessarily a pushout. Let us now see that h′ is a morphism induced by a labelsubstitution. Without loss of generality we may assume thatH ′ = F ′+(R\Restr(K,XReach(L)))and H = F + (R \K), where + denotes disjoint union. Then, if e is a graph node or edge fromF ′, we know that h′(j′(e)) = j(h′′(e)), but h′′ is a morphism induced by a label substitution andassuming, without loss of generality, that j and j′ are inclusions then we have h′(e) = e. Similarly,if e is a graph node or edge in R \Restr(K,XReach(L)), then h′(m′1(e)) = m′(e), and assuming

8tL is assumed to denote the corresponding target function in L, i.e. tNLL or tEL

L .

1028 Orejas, Lambers / Symbolic Graph Transformation

again without loss of generality that m′ and m′1 are the identity on the elements in R \ K andR \Restr(K,XReach(L)), respectively, we have h′(e) = e.

Hence, to end the proof, we just have to show thatD |= h′(ΦSH′)⇔ ΦSH . We know that ΦSH′ =(ΦSG′1

∪ m′1(Φr)), D |= ΦSH ⇒ m(Φr), m(Φr) = m′(Φr), and D |= h1(ΦSG′1) ⇔ ΦSH .

Therefore, we have h′(ΦSH′) = h′(ΦSG′1∪m′1(Φr)) = h′(ΦSG′1

) ∪ h′(m′1(Φr)) = h1(ΦSG′1) ∪

m′(Φr), because h′(ΦSG′1) = h1(ΦSG′1

) and h′ m′1 = m′. This implies D |= h′(ΦSH′) ⇔ΦSH ∪m′(Φr). But, since D |= ΦSH ⇒ m′(Φr), we have D |= h′(ΦSH′)⇔ ΦSH .

ut

The second result tells us that if the given graph SG is grounded (or, equivalently, it is an attributedgraph) 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 solvethe constraints associated to that application, or if we apply lazy transformation and, at the end, we solvethe constraints of the resulting graph.

Theorem 6.2. (Soundness and completeness of lazy graph transformation over grounded graphs)Given a grounded symbolic graph SG = 〈G,ΦG〉, then:

1. Soundness For every lazy transformation SG l=⇒

∗SH and every attributed graphAH ∈ Sem(SH)

there is a symbolic transformation SG =⇒∗ SH ′ such that AH ∈ Sem(SH ′).

2. Completeness For every symbolic transformation SG =⇒∗ SH there is a lazy transformation

SGl

=⇒∗SH ′ such that Sem(SH) ⊆ Sem(SH ′).

Proof:

1. Soundness We proceed by induction on the length of the derivation. In particular we will prove

that if SG l=⇒

∗SH , with SH = 〈H,ΦSH〉, and σ : XH → D satisfies D |= σ(ΦSH), then

there is a transformation SG =⇒∗ SH ′, a label substitution h : XH → XG, and an assignmentσ′ : XG → D, such that SH ′ = 〈H ′,ΦSG〉 is grounded, h(SH) = SH ′, and σ = σ′ h. This isobviously enough to ensure that AH = 〈σ′(H ′), D〉 is in Sem(SH ′). Notice that, asking for thecondition h(SH) = SH ′, when h : XH → XG, makes sense becauseXG = XH′ , since symbolicgraph transformation preserves the variables of graphs.

If SG = SH , the case is trivial. For the general case, let us suppose that SG l=⇒

∗SG1 and

SG1l

=⇒r,m SH , with SG1 = 〈G1,ΦSG1〉, SH = 〈H,ΦSH〉 where H is defined by the doublepushout diagram below:

Reach(L)

(1)m

Restr(K,XReach(L))

(2)

? _oo //

R

m′

G1 F1

? _oo // H

and ΦSH = ΦSG1 ∪ m′(Φ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) = m′(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 =⇒∗ SG′1, a labelsubstitution h1 : XG1 → XG, and an assignment σ′ : XG → D, such that SG′1 = 〈G′1,ΦSG〉 isgrounded, h1(SG1) = SG′1, and σ1 = σ′ h1.

Let m1 : L→ G′1 be the following match. For every element e ∈ Reach(L) (e is a graph node oredge) m1(e) = h1(m(e)) and for every variable x ∈ XL, m1(x) = xv, where v is the value in Dsuch that σ(m′(x)) = v. Notice that this definition is correct because, on the one hand, we haveassumed that for every x ∈ XReach(L) : m(x) = m′(x), and on the other hand, G′1 is grounded,so it includes a variable xv. Now, we can see that m1 : 〈L,Φr〉 → SG′1 is a symbolic graphmorphism, i.e. that D |= ΦSG′1

⇒ m1(Φr). We know that SG′1 is grounded, therefore σ′ is theonly substitution such that D |= σ′(ΦSG′1

) and this means that σ′(xv) = v, for every value v. Bydefinition of m1, we have that, for every variable x ∈ XL = XR, σ′(m1(x)) = σ(m′(x)) and weknow that D |= σ(ΦSH) and D |= ΦSH ⇒ m′(Φ(r)). But this means D |= σ(m′(Φ(r))) and,hence, D |= σ′(m1(Φr)). In addition, m1 satisfies the gluing conditions with respect to the rule rbecause m satisfies them by assumption, and h1 satisfies them because it is a morphism associatedto a label substitution. Therefore, we can apply the symbolic transformation SG′1 =⇒r,m1 SH

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 groundedbecause symbolic graph transformation preserves groundedness. Moreover, it is routine to checkthat h(SH) = SH ′, and σ = σ′ h.

2. Completeness This is just a special case of Theorem 6.1.2.ut

Example 6.2. Consider the lazy graph transformation as presented in Figure 9, where a hotel is reservedfor two nights in Berlin and a flight from Barcelona to Berlin and return is reserved. The labels h forthe hotel, fr1.f and fr2.f for the flights are not bound to a concrete hotel or concrete flights yet. Note thatwe use the *.* notation to distinguish labels having the same name in different nodes. At the end of thistransformation 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 thefollowing 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 symbolictransformation exists, where h, fr1.f and fr2.f are bound to h2, f4 and f1, respectively. Moreover, in theend the total budget bud of the customer is 10.9Actually,the formula that we would obtain is a bit more complex including several (renamed copies of the variable bud, sinceeach application of a rule would add a new variable bud and a constraint defining it. However, if we would allow to simplifythe given formula after each transformation step, as it is sometimes done in Constraint Logic Programming, we could indeedobtain 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 special-ized 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 inthis example, then the resulting constraints after a sequence of transformations could be compiled into aquery to that database, meaning that all the possible solutions would just be obtained as a result of thatquery.

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int = 450

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequest

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequesth : hotel: HotelReservation

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequesth : hotel: HotelReservation

f : flightfr1 : FlightReservation

loc : city = Berlinnights : int = 2

: HotelRequest

name : string = Alicebud : int

: Customer

dep : city = Barcelonadest : city = Berlin

: FlightRequest

dep : city = Berlindest : city = Barcelona

: FlightRequesth : hotel: HotelReservation

f : flightfr1 : FlightReservation

f : flightfr2 : FlightReservation

Berlin = location(h) && bud = 450 – (price(h) * 2) && bud >=0

Berlin = location(h) && Barcelona = departure(fr1.f) && Berlin = destination(fr1.f) && bud = 450 –(price(h) * 2) - price(fr1.f) && bud >=0

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

int, bool, city, hotel, flight

price:hotel->intlocation: hotel -> cityprice:flight->intdeparture: flight -> citydestination: flight -> city

price

100

90

85

70

location

München

Berlin

Berlin

Köln

hotel

h1

h2

h3

h4

price

175

115

150

85

departure

Berlin

Berlin

Barcelona

Barcelona

destination

Barcelona

Barcelona

Berlin

Berlin

flight

f1

f2

f3

f4

Possible solutions in the form (h,fr1.f,fr2.f,bud): (h2,f4,f1,440),(h3,f4,f1,430),(h2,f3,f2,445),(h3,f3,f2,435),(h2,f4,f2,380),(h3,f4,f2,370)

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 which is smaller. E.g. by adding inequalities of the following kind price(h) <= price(h’), where h’ is a variable present as a label in the E-graph of the rule, but without incoming edges. Another alternative in the formalization would be to allow more variables in the formulas as the number of labels present in the E-graph.

reserveHotel

reserveFlight

reserveFlight

Figure 9. Lazy graph transformation

7. Conclusion and related work

In this paper we have studied several forms of symbolic graph transformation, including showing that wecan delay constraint solving in the framework of attributed graph transformation by means of symbolicgraphs. The idea of the technique comes from constraint logic programming [9]. Actually, the idea un-derlying symbolic graphs also comes from constraint logic programming, where the domain of values,and the conditions on them are neatly separated from symbolic clauses. In a similar way, we separate

Orejas, Lambers / Symbolic Graph Transformation 1031

the graph part in symbolic graphs from the conditions defining the value part. Symbolic graph transfor-mation can be seen as a generalization of attribute grammars [8]. In particular, attribute grammars canbe considered to provide a method for computing attributes in trees. Moreover, these attributes must becomputed 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 isencoded 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 approachesare compared showing that they are, up to a certain point, equivalent. Finally, [16] is based on the useof labelled graphs to represent attributed graphs, and of rule schemata to define graph transformationsinvolving computations on the labels. That approach has some similarities with our approach, includingthe 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 hasthe problem that this approach does not fit as an instance of adhesive rule-based transformation, whichmeans that we cannot apply to this approach the rich theory of adhesive categories. Moreover, we do notthink that there is a direct way of defining lazy graph transformations for any of those approaches, sincethere 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 otherfundamental aspects which may be interesting to study, like developing specific techniques for checkingconfluence for symbolic transformation or the definition of symbolic graph transformation with borrow-ing contexts, avoiding some existing technical difficulties. In particular, when computing the borrowedcontext of a given rule application, we are forced to assign values of the given data algebra to all the vari-ables in the left hand-side of the given rule. This causes that, in general, for any possible rule applicationwe may have an infinite number of contexts that only differ on the values of the attributes. Obviously, thisproblem poses difficulties for using the borrowing context technique to prove bisimilarity for attributedgraph 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 ofthe 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 NewCategorical 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 Graphsand 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., Kuster, J. and Taentzer, G. (2002) Towards Automatic Translation of UML Models into SemanticDomains. 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. TheJournal of Logic Programming, 37:1–46.

[10] Lowe, M., Korff, M. and Wagner A. (1993) An Algebraic Framework for the Transformation of AttributedGraphs. 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 Ap-plications, 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 SymbolicComputation, 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 theEASST, 30.

[15] Orejas F. and Lambers, L. (2010) Delaying Constraint Solving in Attributed Graph Transformation. In GraphTransformations, 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.