Proving Termination of Graph Transformation Systems using Weighted Type Graphs over Semirings
H.J. Sander Bruggink, Barbara König, Dennis Nolte, Hans Zantema
aa r X i v : . [ c s . L O ] M a y Proving Termination of Graph TransformationSystems using Weighted Type Graphs overSemirings ⋆ H.J. Sander Bruggink , Barbara K¨onig , Dennis Nolte , and Hans Zantema GEBIT Solutions [email protected] Universit¨at Duisburg-Essen { barbara koenig,dennis.nolte } @uni-due.de Technische Universiteit Eindhoven and Radboud Universiteit Nijmegen [email protected]
Abstract.
We introduce techniques for proving uniform termination ofgraph transformation systems, based on matrix interpretations for stringrewriting. We generalize this technique by adapting it to graph rewritinginstead of string rewriting and by generalizing to ordered semirings. Inthis way we obtain a framework which includes the tropical and arctictype graphs of [5] and a new variant of arithmetic type graphs. These typegraphs can be used to assign weights to graphs and to show that theseweights decrease in every rewriting step in order to prove termination. Wepresent an example involving counters and discuss the implementationin the tool Grez.
For every computational formalism, the question of termination is one of themost fundamental problems, consider for instance the halting problem for Tur-ing machines. For graph transformation systems there has been some work ontermination, but this problem has received less attention than, e.g., confluence orreachability analysis. There are several applications where termination analysis isessential: one scenario is termination of graph programs, especially for programsoperating on complex data structures. Furthermore, model transformations, forinstance of UML models, usually require functional behaviour, i.e., every sourcemodel should be translated into a unique target model. This requires terminationand confluence of the model transformation rules.There is a huge body of termination results in string and term rewriting [2]from which one can draw inspiration. Still, adapting these techniques to graphtransformation is often non-trivial. A helpful first step is often to modify thesetechniques to work with cycle rewriting [19,15], which imagines the two ends ofa string to be glued together, so that rewriting is indeed performed on a cycle. ⋆ Research partially supported by DFG project
GaReV . n this paper we focus exclusively on uniform termination, i.e., there is onlya set of graph transformation rules, but no fixed initial graph, and the questionis whether the rules terminate on all graphs. All variants of the terminationproblem, termination on all graphs as well as termination on a fixed set of initialgraphs, are undecidable [14].In [5] we have shown how to adapt methods from string rewriting [17,12] andto develop a technique based on weighted type graphs, which was implemented inthe tool Grez. Despite its simplicity the method is quite powerful and finds termi-nation arguments also in cases which are difficult for human intuition. However,there are some examples (see for instance the example discussed in Section 5)where this technique fails. The corresponding techniques in string rewriting canbe seen as matrix interpretations of strings in certain semirings, more specificallyin the tropical and arctic semiring. Those semirings can be replaced by the arith-metic semiring (the natural numbers with addition and multiplication) in orderto obtain a powerful termination analysis method for string rewriting [11,9].Here we generalize this method to graphs. Due to their non-linear nature,we have to abandon matrices and instead state a different termination criterionthat is based on weights of morphisms of the left-hand and right-hand sides ofrules into a type graph. Type graphs [6] are a standard tool for typing graphtransformation systems, but we are not aware of any case where they have beenused for termination analysis before [5].By introducing weighted type graphs we generalize matrix interpretationsfor string rewriting in two ways: first, we transform graphs instead of stringsand second, we consider general semirings. Our techniques work for so-calledstrictly and strongly ordered semirings, which have to be treated in a slightlydifferent way. After introducing the theory we will discuss an extended example,followed by a presentation of the implementation in the termination tool Grez. All proofs can be found in Appendix A.
We first introduce graphs, morphisms, and graph transformation, in particularthe double pushout approach [7]. In the context of this paper we use edge-labeled,directed graphs, but it is straightforward to generalize the results to hypergraphs.
Definition 1 (Graph).
Let Λ be a fixed set of edge labels. A Λ -labeled graph is a tuple G = h V, E, src , tgt , lab i , where V is a finite set of nodes, E is a finiteset of edges, src , tgt : E → V assign to each edge a source and a target, andlab : E → Λ is a labeling function. As a notational convention, we will denote, for a given graph G , its compo-nents by V G , E G , src G , tgt G and lab G , unless otherwise indicated. efinition 2 (Graph morphism). Let
G, G ′ be two Λ -labeled graphs. A graphmorphism ϕ : G → G ′ consists of two functions ϕ V : V G → V G ′ and ϕ E : E G → E G ′ , such that for each edge e ∈ E G it holds that src G ′ ( ϕ E ( e )) = ϕ V ( src G ( e )) ,tgt G ′ ( ϕ E ( e )) = ϕ V ( tgt G ( e )) and lab G ′ ( ϕ E ( e )) = lab G ( e ) . We will often drop the subscripts
V, E and simply write ϕ instead of ϕ V , ϕ E .We work with standard double-pushout (DPO) graph transformation [7]. Notethat our termination results would still hold if we restricted to injective matches. Definition 3 (Graph transformation). A graph transformation rule ρ con-sists of two morphisms L (cid:0) ϕ L − I − ϕ R (cid:1) R , consisting of the left-hand side L , the right-hand side R and the interface I . We require that I is discrete.A match of a left-hand side in a graph G is a morphism m : L → G . Given arule ρ and a match m : L → G , a graph H is the result of applyingthe rule at the match, written G ⇒ m,ρ H (or G ⇒ ρ H if m is arbitrary or clear from the context), if there existsa graph C and morphisms such that the two squares inthe diagram on the right are pushouts in the category ofgraphs and graph morphisms. L I RG C H ϕ L ϕ R m (po) (po) A graph transformation system R is a finite set of graph transformationrules. For a graph transformation system R , ⇒ R is the rewriting relation ongraphs induced by those rules. Intuitely in a graph transformation step from G to H , the images of allelements of the left-hand side L , which are not present in the interface I aredeleted, and the right-hand side R is added, by gluing it to the interface.Although the graph transformation systems themselves are untyped, ourmethod for termination analysis is based on type graphs [6]. For given graphs G, T , where T is considered as a type graph , we say that G is typed over T when-ever there is a morphism t : G → T . The morphism t will also be called typingmorphism . We need a way to compose and decompose typing morphisms. Lemma 1.
Let a pushout PO consisting of objects G , G , G , G be given. Thenthere exists a bijection between pairs of commuting morphisms t : G → T , t : G → T and morphisms t : G → T (see diagram below). G G G G T ψ ψ ϕ ϕ tt t (po) For each t we obtain a unique pair of morphisms t , t by composing with ϕ and ϕ , respectively. Conversely, for each pair t , t of morphisms with t ◦ ψ = t ◦ ψ we obtain a unique t : G → T as mediating morphism. In this case we will writemed PO ( t , t ) = t and med − PO ( t ) = h t , t i . .2 Matrix Interpretations for String Rewriting Our technique is strongly influenced by matrix interpretations for proving termi-nation in string, cycle and term rewriting systems [11,15,9]. We will generalizethis technique, resulting in a technique for graph transformation systems thathas a distinctly different flavour than the original method. In order to point outthe differences later and motivate our choices, we will introduce matrix interpre-tations first.We are working in the context of string rewrite systems, where a rule is ofthe form ℓ → r , where ℓ, r are both strings over a given alphabet Σ . For instance,consider the rule aa → aba , which rewrites aaa ⇒ abaa ⇒ ababa .We first start with some preliminaries: let A, B be two square matrices
A, B over N of equal dimension n . We write A > B if A , > B , and A i,j ≥ B i,j for all indices i, j with 1 ≤ i, j ≤ n , i.e., we require that the entries in the upperleft corner are strictly ordered, whereas the remaining entries may also be equal.It holds that A > B implies A · C > B · C and C · A > C · B for a matrix C > a ∈ Σ is associated with a square matrix A = [ a ] > n ). Similarly everyword w = a . . . a n is mapped to a matrix [ w ] = [ a ] · · · · · [ a n ], which is obtainedby taking the matrices of the single letters and multiplying them. If we can show[ ℓ ] > [ r ] for every rule ℓ → r , then termination is implied by the considerationsabove and by the fact that the order ≤ on N is well-founded, i.e., there are noinfinite strictly decreasing chains.For the example above take the following matrices (as in [11]):[ a ] = (cid:18) (cid:19) [ b ] = (cid:18) (cid:19) with [ aa ] = (cid:18) (cid:19) > (cid:18) (cid:19) = [ aba ]For cycle rewriting a similar argument can be given, which is based on theidea that the trace, i.e., the sum of the diagonal, of a matrix decreases [15].A natural question to ask is how such matrices can be obtained. We willlater discuss how SMT solvers can be employed to automatically generate therequired weights.In the following, we will generalize this method in two ways: we will replacethe natural numbers by an arbitrary semiring – an observation that has alreadybeen made in the context of string rewriting – and we will make the step fromstring to graph rewriting. We continue by defining semirings, the algebraic structures in which we willevaluate the graphs occurring in transformation sequences, and orders on them. Here 0 denotes the matrix with all entries zero. (partial) order is a reflexive, transitive and antisymmetric relation. If ≤ is an order, then we denote by < its strict subrelation e.g. x < y if and onlyif x ≤ y ∧ x = y . An order is well-founded if it does not allow infinite, strictlydecreasing sequences x > x > x > · · · . Definition 4. A semiring is a tuple h S, ⊕ , ⊗ , , i , where S is the (finite orinfinite) carrier set, h S, ⊕ , i is a commutative monoid, h S, ⊗ , i is a monoid, ⊗ distributes over ⊕ and is an annihilator for ⊗ . That is, the following laws holdfor all x, y, z ∈ S : ( x ⊕ y ) ⊕ z = x ⊕ ( y ⊕ z ) 0 ⊕ x = x x ⊗ x ⊗ y ) ⊗ z = x ⊗ ( y ⊗ z ) x ⊕ x ⊗ x = 0( x ⊕ y ) ⊗ z = ( x ⊗ z ) ⊕ ( y ⊗ z ) 1 ⊗ x = x x ⊕ y = y ⊕ xz ⊗ ( x ⊕ y ) = ( z ⊗ x ) ⊕ ( z ⊗ y ) x ⊗ x A semiring h S, ⊕ , ⊗ , , i is commutative if ⊗ is commutative (that is, if x ⊗ y = y ⊗ x , for all x, y ∈ S ).We will often confuse a semiring with its carrier set, that is, S can refer toboth the semiring h S, ⊕ , ⊗ , , i and the carrier set S . In order to come up with termination arguments, we need a partial order onthe semirings that has to be compatible with its operations.
Definition 5.
A structure h S, ⊕ , ⊗ , , , ≤i is an ordered semiring if h S, ⊕ , ⊗ , , i is a semiring and ≤ ∈ S × S is a partial order on S such that for all x, y, u, z ∈ S : – x ≤ y implies x ⊕ u ≤ y ⊕ u , x ⊗ z ≤ y ⊗ z and z ⊗ x ≤ z ⊗ y for z ≥ .The ordered semiring S is strongly ordered , if – x < y , z < u implies x ⊕ z < y ⊕ u ; and – z > , x < y implies x ⊗ z < y ⊗ z and z ⊗ x < z ⊗ y .The ordered semiring S is strictly ordered , if in addition x < y implies x ⊕ z Definition 6. Let an ordered semiring S be given. A weighted type graph T over S is a graph with a weight function w T : E T → S and a designated flowernode ✲ T ∈ V , such that for each label A ∈ Λ there exists a designated edge e A with src T ( e A ) = ✲ T , tgt T ( e A ) = ✲ T , lab T ( e A ) = A and w T ( e A ) > .For a graph G , we denote with fl T ( G ) (or just fl ( G ) if T is clear from thecontext) the unique morphism from G to T that maps each node v ∈ V G of G tothe flower node ✲ T and each edge e ∈ E G , with lab T ( e ) = A , to e A . Note that,for a morphism c : G → H , it is always the case that fl T ( H ) ◦ c = fl T ( G ) . Note that every matrix A of dimension n can be associated with an (unla-belled) type graph with n nodes, where an edge from node i to j is assignedweight A i,j (or does not exist if A i,j = 0). Hence our idea of weighted typegraphs is strongly related with the matrices of Section 2.2.The node ✲ T is also called the flower node, since the loops attached to it looklike a flower. Those loops correspond to the matrix entries at position (1 , 1) andsimilar to those entries they play a specific role. Note that the flower structurealso ensures that every graph can be typed over T (compare with the terminalobject in the category of graphs, which is exactly such a flower).With a bit of notation overloading, we assign a weight to each morphism t : D → T with codomain T and arbitrary domain D as follows: w T ( t ) = Y e ∈ E D w T ( t ( e )) . That is, we multiply the weights of all edges in the image of t with respect to ⊗ .Finally, the weight of a graph G with respect to T is defined by summing upthe weights of all morphisms from G to T with respect to ⊕ : w T ( G ) = X t G : G → T w T ( t G ) . The subscript T of w T will be omitted if clear from the context. xample 2. We give a small example for the weight of a graph. T = a b a a Consider for instance the type graph T . Edges arelabelled a, b and the weights, in this case natural num-bers, are given as superscripts. Consider also the left-hand side L of rule ρ below, consisting of two a -edges(the graph rewriting analogue of the string rewritingrule aa → aba considered in Section 2.2). There are five morphisms L → T ,each having weight 1, as they are calculated by multiplying the weights of two a -edges which also have weight 1. Hence the weight of L with respect to T is w T ( L ) = 1 + 1 + 1 + 1 + 1 = 5. More details on this are given in Example 3. ρ = a a a b a If we glue two graphs G , G in order to obtain G , the weight of G can beobtained from the weights of G , G . Lemma 2 (Properties of weighted type graphs). Let S be an ordered com-mutative semiring and T a weighted type graph over S .(i) Whenever S is strongly ordered, for allgraphs G , fl T ( G ) : G → T exists and w T ( fl T ( G )) > .(ii) Given the following diagram, where thesquare is a pushout and G is discrete, itholds that w T ( t ) = w T ( t ◦ ϕ ) ⊗ w T ( t ◦ ϕ ) . G G G G T ψ ψ ϕ ϕ t (po) Since property (ii) above only holds if G is discrete we restrict to discretegraphs I in the rule interface. While the process of obtaining the weight of a graph corresponds to calcu-lating the matrix of a word and summing up all its entries, we also require away to be more discriminating, i.e., to access separate matrix entries. Evaluatinga string-like graph would mean to fix its entry and exit node within the typegraph (similarly to fixing two matrix indices). However, in graph rewriting, wehave interfaces of arbitrary size. Hence, we do not index over pairs of nodes,but over arbitrary interface graphs, and compute the weight of a graph L withrespect to a typed interface I . Definition 7. Let ϕ : I → L and t : I → T be graph morphisms, where T is aweighted type graph. We define: w t ( ϕ ) = X t L : L → Tt L ◦ ϕ = t w T ( t L ) . L IT ϕ tt L Compare also with the “stable under pushouts” property of [5]. inally, we can define what it means that a rule is decreasing, analogous tothe condition [ ℓ ] > [ r ] introduced in Section 2.2. In addition we also introducenon-increasingness, a concept that will be needed in the following for so-calledrelative termination arguments. Definition 8. Let a rule ρ = L (cid:0) ϕ L − I − ϕ R (cid:1) R , an ordered commutative semiring S and a weighted type graph T over S be given.(i) The rule ρ is non-increasing if for all t I : I → T it holds that w t I ( ϕ L ) ≥ w t I ( ϕ R ) .(ii) The rule ρ is decreasing if it is non-increasing, and w fl ( I ) ( ϕ L ) > w fl ( I ) ( ϕ R ) .Example 3. We come back to Example 2 and check whether rule ρ is decreasing.For this we have to consider the following four morphisms t : I → T from thetwo-node interface into the weighted type graph T : – The flower morphism fl ( I ) which maps both interface nodes to the left nodeof T . In this case we have w fl ( I ) ( ϕ L ) = 2 > w fl ( I ) ( ϕ R ). – Furthermore there are three other morphisms t , t , t : I → T mapping thetwo interface nodes either both to the right node of T , or the first interfacenode to the left and the second interface node to the right node of T , or viceversa. In all these cases we have w t i ( ϕ L ) = 1 = w t i ( ϕ R ).Hence, the rule is decreasing. Note also that these weights correspond exactly tothe weights of the multiplied matrices in Section 2.2.Finally, we have to show that applying a decreasing rule also decreases theoverall weight of a graph. For a non-increasing rule the weight might also remainthe same. Lemma 3. Let S be a strictly ordered commutative semiring and T a weightedtype graph over S . Furthermore, let ρ be a rule such that G ⇒ ρ H .(i) If ρ is non-increasing, then w T ( G ) ≥ w T ( H ) .(ii) If ρ is decreasing, then w T ( G ) > w T ( H ) . From this lemma we can prove our main theorem that is based on the well-known concept of relative termination [10,18]: if we can find a type graph forwhich some rules are decreasing and the rest is non-increasing, we can remove thedecreasing rules without affecting termination. We are then left with a smallerset of rules for which termination can either be shown with a different type graphor with some other technique entirely. Theorem 1. Let S be a strictly ordered commutative semiring with a well-founded order ≤ and T a weighted type graph over S . Let R be a set of graphtransformation rules, partitioned in two sets R < and R = . Assume that all rulesof R < are decreasing and all rules of R = are non-increasing. Then R is termi-nating if and only if R = is terminating. A special case of the theorem is when R = = ∅ . Then the statement of thetheorem is that a graph transformation system R is terminating if all its rulesare decreasing with respect to a strictly ordered commutative semiring S andtype graph T over S . Using Strongly Ordered Semirings In the last section the semirings were required to be strictly ordered. In thissection we consider what happens when we weaken this requirement and alsoallow non-strictly ordered semirings, which must however be strongly ordered.This allows us to work with the tropical and arctic semiring. It turns out thatwe obtain similar results to above if we strengthen the notion of decreasing. Definition 9. Let a rule ρ = L (cid:0) ϕ L − I − ϕ R (cid:1) R , an ordered commutative semiring S and a weighted type graph T over S be given. The rule ρ is strongly decreasing (with respect to T ) if for all t I : I → T it holds that w t I ( ϕ L ) > w t I ( ϕ R ) . Using this new notion of decreasingness we can also formulate a termina-tion argument, which is basically equivalent to the termination argument wepresented in [5]. Lemma 4. Let S be a strongly ordered commutative semiring and T a weightedtype graph over S . Furthermore, let ρ be a rule such that G ⇒ ρ H .(i) If ρ is non-increasing, then w T ( G ) ≥ w T ( H ) .(ii) If ρ is strongly decreasing, then w T ( G ) > w T ( H ) . Now it is easy to prove a theorem analogous to Theorem 1, using Lemma 4instead of Lemma 3. Theorem 2. Let S be a strongly ordered commutative semiring with a well-founded order ≤ and T a weighted type graph over S . Let R be a set of graphtransformation rules, partitioned in two sets R < and R = . Assume that all rulesof R < are strongly decreasing and all rules of R = are non-increasing. Then R isterminating if and only if R = is terminating. In this way we have recovered the termination analysis from one of our earlierpapers [5], however spelt out differently. In order to explain the connection, letus consider what it means for a rule ρ = L (cid:0) ϕ L − I − ϕ R (cid:1) R to be non-increasingin the tropical semiring where ⊕ is min and ⊗ is +: for each t : I → T into aweighted type graph T it must hold thatmin t L : L → Tt L ◦ ϕ L = t w T ( t L ) ≥ min t R : R → Tt R ◦ ϕ R = t w T ( t R )where w T ( t L ) is the weight of the morphism t L , obtained by summing up (via+) the weights of all edges in the image of t L .A different way of expressing that the minimum of the first set is larger orequal than the minimum of the second set, is to say that for each morphism t L : L → T with t L ◦ ϕ L = t there exists a morphism t R : R → T with t R ◦ ϕ R = t and w T ( t L ) ≥ w T ( t R ). And this is exactly the notion of tropically non-increasingof [5].Comparing the results of Theorems 1 and 2 we notice the following: as un-derlying semiring S we can take either a strictly ordered or a strongly orderedne, but if we choose a strongly ordered semiring, the termination argumentbecomes slightly weaker because for every morphism from the left-hand side tothe type graph there must exist a compatible, strictly smaller morphism fromthe right-hand side to the type graph. We give examples to show that with a weighted type graph over a strictly orderedsemiring (such as the arithmetic semiring), we can prove termination on somegraph transformation systems where strongly ordered semirings fail. We startwith a graph transformation system for which a termination argument can befound using both variants. Then we will modify some rules and explain whyweighted type graphs over strongly ordered semirings can not find a terminationargument for the modified system. Example 4. As an example we take a system consisting of several counters, whichrepresent their current value by a finite number of bits. Each counter may possessan incr marker, that can be consumed to increment the counter by 1. G = . . . . . . incrincr countcountcount One possible graph describinga state of such a system is givenby G . This is just one possible ini-tial graph, since we really showuniform termination, i.e., termi-nation on all initial graphs, eventhose that do not conform to theschema indicated by G .We consider the graph transformation system { ρ , ρ , ρ , ρ } , adapted from[15], consisting of the following four rules: ρ = countincr count ρ = countincr c count ρ = c ρ = c c Each counter may increment at most once. Rules ρ and ρ specify that acounter (represented by a count -labelled edge) may increment its least significantbit by 1 if an incr marker was not consumed yet. If the least significant bit is 1,the bit is marked by a label c , to remember that a carry bit has to be passed tothe following bit. Rule ρ increments the next bit of the counter by 1 (if it was0 before), while rule ρ shifts the carry bit marker over the next 1. trop = count incr c The fact that this graph transformation systemis uniformly terminating can be shown using aweighted type graph over either a strictly orstrongly ordered semiring. For example, using anon-relative termination argument, we evaluate therules with respect to the weighted type graph T trop over the tropical semiring.A relative termination argument is even easier: the rules ρ and ρ can be re-moved due to the decreasing number of incr -labelled edges. Then we can remove ρ due to the decreasing number of c -labelled edges (which remain constant in ρ ) and afterwards remove ρ since it decreases 1-labelled edges. With all rulesremoved, the graph transformation system has been shown to terminate uni-formly. T arit = count incr c We now consider the arithmetic semiring and againuse a non-relative termination argument: we evaluatethe rules with respect to the weighted type graph T arit , where all weights are just increased by one withrespect to T trop . That is due to the fact, that we areworking in the arithmetic semiring and hence have to make sure that all weightsof flower edges are strictly larger than 0. Example 5. We will now modify rules ρ and ρ in order to give an examplewhere weighted type graphs over tropical and arctic semirings fail to find atermination argument.Consider the graph transformation system { ρ ′ , ρ ′ , ρ ′ , ρ ′ } consisting of rules ρ and ρ from Example 4 with two additional new rules: ρ ′ = count count ρ ′ = count c count ρ ′ = c (= ρ ) ρ ′ = c c (= ρ )With respect to Example 4, the counter may increment its value not only oncebut several times, until the least significant bit is permanently marked by thecarrier bit label c . This will eventually happen, since counters are never extendedby additional digits and carry bits finally accumulate and can not be processed.We now give a relative termination argument, to show uniform termination ofthis graph transformation system. The termination of this system is not obviousas the numbers of the labels c , 0 and 1 increase and decrease depending on therules used for the derivation. ′ = count c count c First, we evaluate the rules with respectto the following weighted type graph T ′ over the arithmetic semiring. Consider forinstance rule ρ ′ and the following four in-terface morphisms: – t = fl ( I ) : I → T ′ is the flower morphisms and maps both interface node tothe left node of T ′ . In this situation we have w t ( ϕ L ) = 1 · · > · · w t ( ϕ R ) (there are two ways to map the left-hand side insuch a way that both interface nodes are mapped to the left node, resultingin weight 3; similar for the right-hand side, where we obtain weight 2). – t : I → T ′ is the morphism that maps the first interface node to the rightnode of T ′ and the second interface node to the left node of T ′ . In this casewe have w t ( ϕ L ) = 1 · ≥ · w t ( ϕ R ). – t : I → T ′ is the morphism that maps the first interface node to the leftnode of T ′ and the second interface node to the right node of T ′ . In this casewe have w t ( ϕ L ) = 0 ≥ w t ( ϕ R ), since there are no possibilities to mapeither the left-hand or the right-hand side. – t : I → T ′ is the morphisms that maps both interface node to the right nodeof T ′ . Here we have w t ( ϕ L ) = 0 ≥ w t ( ϕ R ) (again, there are no fittingmatches of the left-hand and right-hand side).Hence ρ ′ is decreasing. Similarly we can prove that ρ ′ is decreasing and ρ ′ , ρ ′ arenon-increasing, which means that ρ ′ , ρ ′ can be removed. To show terminationof the remaining rules ρ ′ , ρ ′ we can simply use the weighted type graph T arit from Example 4 again.We found a relative termination argument for Example 5 using a weightedtype graph over the arithmetic semiring. However, there is no way to obtain atermination argument with a weighted type graph over either tropical or arcticsemirings: in these cases the weight of any graph is linear in the size of the graph(since we use only addition and minimum/maximum to determine the weight ofa graph). If we have an interpretation where at least one rule is decreasing,and the other rules are non-increasing, then in any derivation, the number ofapplications of the decreasing rules is at most linear in the size of the initialgraph. However, if we start with a counter which consists of n bits (all set to 0),we obtain a derivation in which all of the rules are applied at least 2 n times.This means that it is principally impossible to find a proof with weightedtype graphs over the tropical or arctic semiring, even using relative termination.The last two examples were inspired by string rewriting and the example rulescould easily be encoded into a string grammar. We give another final exampleand prove termination using a weighted type graph over the arithmetic semiring.We now switch from strings to trees, staying with a scenario where reductions ofexponential length are possible. In addition we discard the count -label as eachcounter will be represented by a node with no incoming edge and we will exploitthe dangling edge condition. xample 6. In the next example we interweave our counters into a single treelikestructure. Each path from a root node to a leaf can be interpreted as a counter. b G = . . .. . . One possible graph describing a stateof the modified system is given by b G . Eachcounter shares a number of bits with othercounters, where the least significant bit isshared by all counters. Again this is justone possible initial graph, since we proveuniform termination.Let the following graph transformation system { b ρ , b ρ , b ρ , b ρ , b ρ , b ρ } be given: b ρ = b ρ = c b ρ = 12 300 c 12 3 12 310 0 b ρ = 12 301 c 12 3 12 311 0 b ρ = 12 310 c 12 3 12 3 c b ρ = 12 311 c 12 3 12 3 c The rules b ρ and b ρ increment the shared least significant bit by 1. Thesetwo rules can only be applied at the root of the tree (due to the dangling edgecondition of the DPO approach), as long as the edge is either labelled 0 or 1. Byapplying the rules b ρ , . . . , b ρ , a carrier bit can be passed to the next bit. Provingtermination of this graph transformation system is non-trivial. By applying forinstance b ρ , the value of the counters containing interface node 1 does not change,while other counter values decrease. b T = c c We evaluate the rules with respect to thefollowing weighted type graph b T over thearithmetic semiring. We can prove that b ρ and b ρ are decreasing and b ρ , . . . , b ρ arenon-increasing, which means that b ρ , b ρ can be removed using a relative termination argument.The rules b ρ and b ρ can be removed due to the decreasing number of c-labellededges, which remain constant in b ρ and b ρ . Afterwards we can remove b ρ , b ρ sincethey decrease the number of 1-labelled edges. The graph transformation systemhas been shown to terminate uniformly, since there are no rules left. The question of how to find suitable weighted type graphs has been left open sofar. Instead of manually searching for a suitable type graph we employ a satisfi-able modulo theories (SMT) solver (in this case Z3) that can solve inequationsover the natural numbers.e fix a number n of nodes in the type graph and proceed as follows: takea complete graph T with n nodes, i.e., a graph with an edge for every pair i, j ∈ { , . . . , n } of nodes and every edge label a ∈ Λ . Every edge e in this graphis associated with a variable x e . The task is to assign weights to those variablessuch that rules can be shown as either decreasing or non-increasing.Now, for every rule ρ = L (cid:0) ϕ L − I − ϕ R (cid:1) R and every map t : I → T we obtainan inequation: X t L : L → Tt L ◦ ϕ L = t Y e ∈ E L x t L ( e ) ≥ X t R : R → Tt R ◦ ϕ R = t Y e ∈ E R x t R ( e ) If we want to show that ρ is decreasing and t is the flower morphism ≥ has tobe replaced by > .Doing this for each rule and every map t gives us equations that can be used asinput for an SMT-solver. We consider the weights as natural numbers only up to agiven bound by restricting the length of the corresponding bit-vectors. Note thatwe would be outside the decidable fragment of arithmetics otherwise since theequations would contain multiplication of variables (as opposed to multiplicationof constants and variables). By using a bit-vector encoding the SMT-solver Z3can reliably find a solution (if it exists) and especially such solutions are foundfor the examples discussed in Section 5. Any solution gives us a valid weightedtype graph.A prototype Java-based tool, called Grez , has been written and was intro-duced in [5]. Given a graph transformation system R , the tool tries to automat-ically find a proof for the uniform termination of R . The tool supports relativetermination and runs different algorithms (which are chosen by the user) con-currently to search a proof. If one algorithm succeeds in finding a terminationargument for at least one of the rules, all processes are interrupted and the cor-responding rule(s) will be removed from R . The algorithms are then executedon the smaller set of rules and this procedure is repeated until all rules havebeen removed. Afterwards Grez generates the full proof which can be saved asa PDF-file. Grez provides both a command-line interface and a graphical user interface.The tool supports the integration of external tools, such as other terminationtools or SMT-solvers. Grez can use any SMT-solver which supports the SMT-LIB2 format [1]. Grez generates the inequation described above in this formatand passes it, either through a temporary file or via direct output stream, to theSMT-solver. The results are parsed back into the termination proof, as soon asthe SMT-solver terminates and produces a model for the formula.We ran the tool on all examples of this paper using a Windows workstationwith a 2 , 67 Ghz, 4-core CPU and 8 GB RAM. All proofs were generated in lessthan 1 second. The tool, a user manual [4] and the examples from this papercan be downloaded from the Grez webpage. Conclusion We have shown how to generalize the tropical and arctic weighted type graphsof [5] to weighted type graphs over general semirings and their application to thetermination analysis of graph transformation systems. This enables us to workin the arithmetic semiring and to prove termination of systems that could notbe handled with previous approaches. Note that arithmetic type graphs do notsubsume previous termination analysis methods, but rather complement them.In practice one should always try several methods in parallel threads, as it isdone in our termination tool Grez. Related Work. As already mentioned in the introduction, there is some workon termination analysis for graph transformation systems, often using ratherstraightforward counting arguments. Some work is specifically geared to theanalysis of model transformations, taking for instance layers into account.The paper [3] considers high-level replacement units ( hlru ), which are trans-formation systems with external control expressions. The paper introduces ageneral framework for proving termination of such hlru s, but the only concretetermination criteria considered are node and edge counting, which are subsumedby the weighted type graph method (for more details see [5]).In [8] layered graph transformation systems are considered, which are graphtransformation systems where interleaving creation and deletion of edges withthe same label is prohibited and creation of nodes is bounded. The paper showssuch graph transformation systems are terminating.Another interesting approach encodes graph transformation systems intoPetri nets [16] by introducing one place for every edge label and transform-ing rules into transitions. Whenever the Petri net terminates on all markings,we can conclude uniform termination of the original graph transformation rules.Note that the second example of Section 5 can not be handled in this way byPetri nets. On the other hand [16] can handle negative application conditionsin a limited way, a feature we did not consider here.Another termination technique via forward closures is presented in [13]. Notethat the example discussed in this paper (termination of a graph transformationsystem based on the string rewriting rules ab → ac, cd → db ) can be handled byour tool via tropical type graphs. Future Work. Naturally, integration of (negative) application condition is aninteresting direction for future work. Furthermore we have already started towork on techniques for pattern counting. Here we are interested in deciding,whether a given rule ρ always decreases the number of occurrences of a givensubgraph P .Another area of future research that might be of great interest is non-uniformtermination analysis, i.e., to analyse whether the rules terminate only on a re-stricted set of graphs. In applications it is often the case that rules do not alwaysterminate, but they terminate on all input graphs of interest (lists, cycles, trees, Starting with three edges labelled 0 , , count , rule ρ ′ transforms them into threelabels 0 , c, count , which, via rule ρ ′ , are again transformed into 0 , , count . tc.). For this, it will be necessary to find a suitable way to characterize graphlanguages that is useful for the application areas and integrates well with termi-nation analysis. References 1. C. Barrett, A. Stump, and C. Tinelli. The SMT-LIB Standard – Version 2.0. In Proc. of the 8th International Workshop on Satisfiability Modulo Theories (SMT’10) , July 2010. Edinburgh, Scotland.2. M. Bezem, J.W. Klop, and R. de Vrijer, editors. Term Rewriting Systems . Cam-bridge University Press, 2003.3. P. Bottoni, K. Hoffman, F. Parisi Presicce, and G. Taentzer. High-level replace-ment units and their termination properties. Journal of Visual Languages andComputing , 16(6):485 –507, 2005.4. H.J.S. Bruggink. Grez user manual. ,2015.5. H.J.S. Bruggink, B. K¨onig, and H. Zantema. Termination analysis of graph trans-formation systems. In Proc. of TCS 2014 , volume 8705 of LNCS . Springer, 2014.6. A. Corradini, U. Montanari, and F. Rossi. Graph processes. Fundamenta Infor-maticae , 26(3/4):241–265, 1996.7. A. Corradini, U. Montanari, F. Rossi, H. Ehrig, R. Heckel, and M. L¨owe. Algebraicapproaches to graph transformation—part I: Basic concepts and double pushoutapproach. In G. Rozenberg, editor, Handbook of Graph Grammars and Computingby Graph Transformation, Vol. 1: Foundations , chapter 3. World Scientific, 1997.8. H. Ehrig, K. Ehrig, J. de Lara, G. Taentzer, D. Varr´o, and S. Varr´o-Gyapay. Ter-mination criteria for model transformation. In Proc. of FASE 2005 , volume 3442of LNCS . Springer, 2005.9. J. Endrullis, J. Waldmann, and H. Zantema. Matrix interpretations for provingtermination of term rewriting. Journal of Automated Reasoning , 40(2–3):195–220,2008.10. A. Geser. Relative Termination . PhD thesis, Universit¨at Passau, 1990.11. D. Hofbauer and J. Waldmann. Termination of string rewriting with matrix inter-pretations. In Proc. of RTA ’06 , pages 328–342, 2006. LNCS 4098.12. A. Koprowski and J. Waldmann. Arctic termination . . . below zero. In Proc. ofRTA ’08 , pages 202–216. Springer, 2008. LNCS 5117.13. D. Plump. On termination of graph rewriting. In Graph-Theoretic Concepts inComputer Science , pages 88–100. Springer, 1995. LNCS 1017.14. D. Plump. Termination of graph rewriting is undecidable. Fundamenta Informat-icae , 33(2):201–209, 1998.15. D. Sabel and H. Zantema. Transforming cycle rewriting into string rewriting.In Proc. of RTA’15 , LIPIcs. Schloss Dagstuhl – Leibniz-Zentrum fuer Informatik,2015.16. D. Varr´o, S. Varr´o-Gyapay, H. Ehrig, U. Prange, and G. Taentzer. Terminationanalysis of model transformations by Petri Nets. In Proc. of ICGT 2006 , volume4178 of LNCS . Springer, 2006.17. H. Zantema. Termination of term rewriting by semantic labelling. FundamentaInformaticae , 24(1/2):89–105, 1995.18. H. Zantema. Termination. In Marc Bezem, Jan Willem Klop, and Roel de Vrijer,editors, Term Rewriting Systems , chapter 6. Cambridge University Press, 2003.19. H. Zantema, H.J.S. Bruggink, and B. K¨onig. Termination of cycle rewriting. In Proc. of RTA-TLCA ’14 , pages 476–490. Springer, 2014. LNCS 8560. Proofs Lemma 1. Let a pushout PO consisting of objects G , G , G , G be given. Thenthere exists a bijection between pairs of commuting morphisms t : G → T , t : G → T and morphisms t : G → T (see diagram below). G G G G T ψ ψ ϕ ϕ tt t (po) For each t we obtain a unique pair of morphisms t , t by composing with ϕ and ϕ , respectively. Conversely, for each pair t , t of morphisms with t ◦ ψ = t ◦ ψ we obtain a unique t : G → T as mediating morphism. In this case we will writemed PO ( t , t ) = t and med − PO ( t ) = h t , t i .Proof. It is straightforward to verify that med PO and med − PO are indeed inverseto each other and hence both are bijections. ⊓⊔ Lemma 2 (Properties of weighted type graphs). Let S be an orderedcommutative semiring and T a weighted type graph over S .(i) Whenever S is strongly ordered, for allgraphs G , fl T ( G ) : G → T exists and w T ( fl T ( G )) > .(ii) Given the following diagram, where thesquare is a pushout and G is discrete, itholds that w T ( t ) = w T ( t ◦ ϕ ) ⊗ w T ( t ◦ ϕ ) . G G G G T ψ ψ ϕ ϕ t (po) Proof. (i) fl T ( G ) exists by construction. Furthermore, since w T ( e ) > fl T ( G ), it holds that fl T ( G ) > G is discrete and the square is a pushout, the edge set E G is (iso-morphic to) the disjoint union of E G and E G . Thus: w T ( t ) = Y e ∈ E G w T ( t ( e )) = Y e ∈ E G w T (( t ◦ ϕ )( e )) ⊗ Y e ∈ E G w T (( t ◦ ϕ )( e ))= w T ( t ◦ ϕ ) ⊗ w T ( t ◦ ϕ ) , as required. ⊓⊔ Lemma 3. Let S be a strictly ordered commutative semiring and T a weightedtype graph over S . Furthermore, let ρ be a rule such that G ⇒ ρ H .(i) If ρ is non-increasing, then w T ( G ) ≥ w T ( H ) .(ii) If ρ is decreasing, then w T ( G ) > w T ( H ) .roof. Let ρ = L (cid:0) ϕ L − I − ϕ R (cid:1) R . The rewriting step G ⇒ ρ H is depicted belowon the left.For every possibility to type G via t G : G → T , there exists a morphism t C = t G ◦ ψ L : C → T and we obtain t H : H → T as mediating morphism of theright-hand pushout PO (see diagram on the right). L I RG C H ϕ L ϕ R m c nψ L ψ R PO PO L I RG C HT ϕ L ϕ R m c nψ L ψ R t G t C t L t R t H Now we have (compare with the diagram above on the right): w T ( G ) = X t G : G → T w ( t G ) (1)= X t C : C → T X t L : L → Tt L ◦ ϕ L = t C ◦ c w ( med PO ( t C , t L )) (2)= X t C : C → T X t L : L → Tt L ◦ ϕ L = t C ◦ c (cid:0) w ( t L ) ⊗ w ( t C ) (cid:1) (3)= X t C : C → T (cid:16) w ( t C ) ⊗ X t L : L → Tt L ◦ ϕ L = t C ◦ c w ( t L ) (cid:17) (4)= X t C : C → T (cid:0) w ( t C ) ⊗ w t C ◦ c ( ϕ L ) (cid:1) (5)where (2) follows from the fact that med is a bijection (see Lemma 1), (3) is anapplication of the equation w ( t ) = w ( t ◦ ϕ ) ⊗ w ( t ◦ ϕ ) of Lemma 2, (4) followsfrom distributivity and (5) holds by definition. Symmetrically, we have w T ( H ) = X t C : C → T (cid:0) w ( t C ) ⊗ w t C ◦ c ( ϕ R ) (cid:1) . Using this, we can prove the two parts of the lemma.(i) Since ρ is non-increasing, it holds by definition that w t C ◦ c ( ϕ L ) ≥ w t C ◦ c ( ϕ R )for all t C : C → T , and thus w ( t C ) ⊗ w t C ◦ c ( ϕ L ) ≥ w ( t C ) ⊗ w t C ◦ c ( ϕ R ). Fromthis it follows that w T ( G ) ≥ w T ( H ).(ii) Since ρ is decreasing, and thus non-increasing, it holds by definition that w t C ◦ c ( ϕ L ) ≥ w t C ◦ c ( ϕ R ) for all t C : C → T . Additionally, it holds by as-sumption that w fl ( I ) ( ϕ L ) > w fl ( I ) ( ϕ R ). Since w T ( fl ( C )) > S is a strictly ordered semiring, we have that w T ( fl ( C )) ⊗ w fl ( I ) ( ϕ L ) > w T ( fl ( C )) ⊗ w fl ( I ) ( ϕ R )we take t C = fl ( C ) and t C ◦ c = fl ( I )). From these two facts it followsthat w T ( G ) > w T ( H ) (again using the fact that S is a strictly orderedsemiring). ⊓⊔ Theorem 1. Let S be a strictly ordered commutative semiring with a well-founded order ≤ and T a weighted type graph over S . Let R be a set of graphtransformation rules, partitioned in two sets R < and R = . Assume that all rules of R < are decreasing and all rules of R = are non-increasing. Then R is terminatingif and only if R = is terminating.Proof. ( ⇒ ): It is an immediate consquence of R being terminating that its subset R = is also terminating.( ⇐ ): For a rule ρ and transition G ⇒ r H , it holds, by Lemma 3, that w T ( G ) > w T ( H ) if ρ ∈ R < and w T ( G ) ≥ w T ( H ) if ρ ∈ R = . From this itfollows that each infinite transition sequence of R ends in an infinite transitionsequence of R = , which do not exist by assumption. ⊓⊔ Lemma 4. Let S be a strongly ordered commutative semiring and T a weightedtype graph over S . Furthermore, let ρ be a rule such that G ⇒ ρ H .(i) If ρ is non-increasing, then w T ( G ) ≥ w T ( H ) .(ii) If ρ is strongly decreasing, then w T ( G ) > w T ( H ) .Proof. The proof proceeds analogously to the proof of Lemma 3. For non-increasingrules the proof is exactly the same.For strongly decreasing rules we have to show X t C : C → T (cid:0) w ( t C ) ⊗ w t C ◦ c ( ϕ L ) (cid:1) > X t C : C → T (cid:0) w ( t C ) ⊗ w t C ◦ c ( ϕ R ) (cid:1) This holds since w t C ◦ c ( ϕ L ) > w t C ◦ c ( ϕ R ) for all t C , hence the properties ofstrongly ordered semirings allow us to conclude., hence the properties ofstrongly ordered semirings allow us to conclude.