SAT-Based Loop Detection in Graph Rewriting
SAT-Based Loop Detection in Graph Rewriting
Marcus Ermler
Abstract
In this paper, we propose an approach for detecting loops in derivations of graph rewriting systems
via a translation of the derivation process and loop conditions into propositional formulas. A
satisfying assignment represents a derivation with a detected loop and so it witnesses that the
corresponding graph rewriting system does not terminate.
1 Introduction
The question of termination or non-termination of graph rewriting systems seems to be
an interesting issue, but is in general undecidable [5]. Nevertheless, techniques to prove
termination of graph rewriting systems were introduced (cf. e.g. [4]). Termination of graph
rewriting is defined in the following way (cf. [4]).
The question of looping or non-looping has attracted much attention over the last years in the
context of string and term rewriting systems, but is not so much studied in the area of graph
rewriting. Also, SAT-based approaches are applied to string and term rewriting (cf. e.g. [6]).
In this paper, we propose a new approach for detecting loops in derivations of graph rewriting
systems via a translation of derivations and loop conditions into propositional formulas. The
idea of translating graph rewriting into SAT was introduced in [3], the proposed technique
for loop detection is supplemented to this approach. By using a translation to SAT, we want
to benefit from fast solving techniques implemented in modern SAT solvers.
2 Graph Rewriting
We use edge labeled directed graphs without multiple edges and with a finite node set. For
a finite set Σ of labels, such a graph is a pair G = (V, E) where V = {1, . . . , n} = [n] for
some n ∈ N is a finite set of nodes, numbered from 1 to n, and E ⊆ V × Σ × V is a set of
labeled edges. n is called the size of G. The components V and E are also denoted by VG
and EG . We call an edge (v, x, v) a sling and an edge (v, ∗, v 0 ) unlabeled and omit the label
∗ in drawings. Two edges (v1 , x, v2 ) and (v10 , x0 , v20 ) are considered as an undirected edge if
v1 = v20 and v2 = v10 . A special graph is the empty graph ∅ = (∅, ∅). We call G a subgraph of
H, denoted by G ⊆ H, if VG ⊆ VH and EG ⊆ EH .
Furthermore, we use injective graph morphisms for the matching. Let G, H be two graphs
as defined above. An injective graph morphism from g : G → H is an injective mapping
gV : VG → VH , that is structure- and label-preserving, i.e. for each edge (v, x, v 0 ) ∈ EG ,
(gV (v), x, gV (v 0 )) ∈ EH . An injective graph morphism g : G → H yields the image g(G) =
(gV (VG ), gE (EG )) ⊆ H with gE (EG )) = {(gV (v), x, gV (v 0 )) | (v, x, v 0 ) ∈ EG } called the
2 SAT-Based Loop Detection in Graph Rewriting
match of G in H. In the following, we will write g(v) and g(e) for nodes v ∈ VG and edges
e ∈ EG because the type of the argument indicates the indices V and E.
I Example 2. Figure 1 shows the example graph G0 . Its nodes are numbered from 1 to
4 and all its edges except the slings are unlabeled and undirected. The slings are labeled
with ∅ to denote that the corresponding nodes have not yet been chosen. The graph on
the left-hand of the arrow in Figure 2, called Lchoose in the following, is a subgraph of G0 .
One can choose four injective mappings from Lchoose to G0 : g = {1 7→ 1}, g = {1 7→ 2},
g = {1 7→ 3}, or g = {1 7→ 4}.
1 2 3 4 1 −→ 1 1 2 −→ 1 2
Figure 1 The graph G0 Figure 2 The rule choose Figure 3 The rule remEdge
A rule r = (L ⊇ K ⊆ R) consists of three graphs: the left-hand side L, the gluing graph
K, and the right-hand side R. In our approach, we only consider rules with EK = ∅ and an
invariant node set, i.e. VL = VK = VR . For that reason, we simplify the rule notation to
r = (L → R), denote the set of nodes of a rule r by Vr and its size by size(r) = size(L).
The application of a rule to a graph works as follows. Let r = (L → R) be a rule,
G a graph, and g : L → G an injective graph morphism. Remove the edges in g(L) from
G yielding D and add R disjointly to D. Finally, glue R and D as follows. (1) Merge
each v ∈ VR with g(v). (2) If there is an edge (v, x, v 0 ) ∈ ER with v, v 0 ∈ VR and an edge
(g(v), x, g(v 0 )) ∈ ED then these edges are identified. The application of a rule r to a graph G
with respect to an injective graph morphism g yielding a graph H is denoted by G =⇒ H.
r,g
This is called rule application or direct derivation and fits into the double-pushout approach
(cf. [1]). The sequential composition d = G0 =⇒ G1 =⇒ · · · =⇒ Gn of n direct derivations
r1 ,g1 r2 ,g2 rn ,gn
∗ +
for some n ∈ N is called a derivation, shortly denoted by G0 =⇒ Gn for n ≥ 0 and G0 =⇒ Gn
P P
for n > 0 if r1 , . . . , rn ∈ P .
I Example 3. In Figure 2, one can find an example for a graph rewriting rule which adds
a member sling to a node. As described above, there are four mappings from Lchoose to
G0 . In Figure 4 a derivation is shown. The first graph G1 of the derivation is the result of
applying choose to G0 twice by using the mappings g = {1 7→ 2} and, then, g = {1 7→ 4}.
Applying the rule remEdge from Figure 3 with the mapping g = {1 7→ 4, 2 7→ 3} results in
the second graph. Finally, a three time application of the rule remEdge yields the last graph.
I Example 4. As an example, we consider the vertex cover problem that refers to the question,
whether for a graph G = (V, E), a subset X ⊆ V exists, such that for all (v, x, v 0 ) ∈ E,
v ∈ X or v 0 ∈ X. The corresponding graph grammar for the graph G0 from Figure 1 is
V C = (G0 , {choose, remEdge}, {member, ∅}). The derivation in Figure 4 states the last
part of a possible computation with G0 as input. The two-time application of choose yields
the first graph of the derivation as detailed above. A vertex cover is found, because the last
graph of the derivation has only edges labeled with member or ∅.
I Example 5. Then, the graph G0 in Figure 1 is expressed via the following formula
^ ^
graph(G0 )(0) = edge(v, a, v 0 , 0) ∧ ¬edge(v, a, v 0 , 0)
(v,a,v 0 )∈E0 (v,a,v 0 )∈([n]×Σ×[n])−E0
where E0 = {(1, ∗, 2), (2, ∗, 1), (2, ∗, 3), (3, ∗, 2), (3, ∗, 4), (4, ∗, 3), (2, ∗, 4), (4, ∗, 2), (1, ∅, 1),
(2, ∅, 2), (3, ∅, 3), (4, ∅, 4)}. Please note, that in case of undirected edges both corresponding
directed edges have to occur in the formula.
For a rule r = (L → R) the set of injective graph morphisms from [size(r)] to the set of
nodes [n] is denoted by M(r, n). Let k ∈ N be a derivation step, Gk−1 be a graph with the
node set [n], r = (L → R) be a rule, and g ∈ M(r, n). The application of r to Gk−1 with
respect to g is then expressed by the following formulas
morph(r, g, k) = (v,a,v0 )∈EL edge(g(v), a, g(v 0 ), k − 1),
V
For each rule r ∈ P and each mapping g ∈ M(r, n), the possible applications of r to
W
Gk−1 are expressed via step(k) = r∈P,g∈M (r,n) apply(r, g, k). All derivation starting in G0 of
Vm
length m are described by der(G0 , m) = graph(G0 )(0) ∧ k=1 step(k). The following theorem
states the connection between der and successful derivations.
I Theorem 8. Let G0 and GT be two graphs of size n, P be a rule set, and m ∈ N be the
m
number of derivation steps. Then there is a successful derivation G0 =⇒ GT if and only if
P
there is a satisfying assignment to der(G0 , m) ∧ graph(GT )(m).
Let n be the size of G0 and p(n) be a polynomial bound. Then all derivations starting in G0
Wp(n)
with a length of at most p(n) are expressed via all_der(G0 , p(n)) = m=0 der(G0 , m).
I Example 9. A satisfying assignment to the following subformula yields the derivation
detailed in Example 3 where c is an abbreviation for choose and rE for remEdge
graph(G0 )(0) ∧ apply(c, {1 7→ 2}, 1) ∧ apply(c, {1 7→ 4}, 2) ∧ apply(rE, {1 7→ 4, 2 7→ 3}, 3)∧
apply(rE, {1 7→ 2, 2 7→ 1}, 4) ∧ apply(rE, {1 7→ 2, 2 7→ 3}, 5) ∧ apply(rE, {1 7→ 4, 2 7→ 2}, 6).
Let G0 and H0 be two graphs and g : G0 → H0 be an injective graph morphism. Then
n
the JOIN-Theorem in ([2], p. 101) states the conditions under which a derivation G0 =⇒ Gn
n
can be extended to a derivation H0 =⇒ Hn . Loosely speaking, H0 − G0 is joined with each
n
Gi . This result can be used to find derivations of the form G0 =⇒ Gn =⇒ H0 ⊃ ∼ G0 , i.e. to
n
detect loops in derivations. According to the JOIN-Theorem, the derivation G0 =⇒ Gn would
n
be extended to a derivation H0 =⇒ Hn . Important here is that nodes connecting g(G0 ) and
H0 − g(G0 ) are not deleted during the derivation. In this paper, we only consider rules that
do not delete nodes but this is still a special case. Thus, we use the term simple looping
instead of looping and define it as follows.
I Definition 10 (Simple Loops). A graph rewriting system with an initial graph G0 and a
rule set P containing no node deletion rules is called simple looping, if there are graphs G, H
∗ +
and an injective graph morphism g : G → H such that G0 =⇒ G =⇒ H.
P P
I Example 11. Let us consider again Example 4 and let us assume that choose has been
defined in a wrong way (see Figure 5). The application of choose to G0 yields the last graph
in Figure 6 where G0 is isomorphic to a subgraph of it, i.e. the derivation contains a simple
loop. The rule choose can be applied infinitely often to node 2.
∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅
∅ ∅ =⇒
1 2 3 4 choose 1 2 3 4
1 −→ 1 member
member
For some graph in a derivation of length m isomorphic to a subgraph of the last graph of
this derivation, we define the following propositional formula
m−1
_ _ ^
loop(m) = edge(v, a, v 0 , k) → edge(g(v), a, g(v 0 ), m) .
k=1 g∈M(n,n) (v,a,v 0 )∈[n]×Σ×[n]
Please note, that this formula generates up to nn possible morphisms (g ∈ M(n, n)) and
has to be restricted in some way. An idea could be to use node types to reduce the possible
M.Ermler 5
matchings. In the derivation from Example 3, we could use the member- and ∅-slings as node
types such that member-nodes could only match member-nodes (the same for ∅-nodes).
Detecting a simple loop in all derivations up to a length of p(n) is defined as follows
p(n)
_
loop_detection(G0 , p(n)) = der(G0 , m) ∧ loop(m) .
m=0
4 Conclusion
In this paper, we have introduced a SAT-based approach for detecting simple loops in
derivations of graph rewriting systems. In future, we want to investigate looping for subgraphs,
∗ +
i.e. we want to find derivations G0 =⇒ G =⇒ H where a subgraph G of G is isomorphic to
a subgraph of H. This idea would cover simple looping. Moreover, we want to devise a
translation to SAT for graph rewriting systems with node deletion rules.
Acknowledgements The author is grateful to Johannes Waldmann for his suggestion that
the SAT-based approach to graph rewriting could be used for loop detection, to Hans-Jörg
Kreowski for his suggestion that the JOIN-Theorem could be useful for Definition 10, and to
the anonymous referees for their helpful comments.
References
1 Andrea Corradini, Hartmut Ehrig, Reiko Heckel, Michael Löwe, Ugo Montanari, and
Francesca Rossi. Algebraic approaches to graph transformation part I: Basic concepts
and double pushout approach. In Grzegorz Rozenberg, editor, Handbook of Graph Gram-
mars and Computing by Graph Transformation, Vol. 1: Foundations, pages 163–245. World
Scientific, 1997.
2 Hans-Jörg Kreowski. Manipulationen von Graphmanipulationen. PhD thesis, TU Berlin,
1978.
3 Hans-Jörg Kreowski, Sabine Kuske, and Robert Wille. Graph transformation units guided
by a SAT solver. In Hartmut Ehrig, Arend Rensink, Grzegorz Rozenberg, and Andy Schürr,
editors, Proc. 5th Intl. Conference on Graph Transformations (ICGT 2010), volume 6372
of Lecture Notes in Computer Science, pages 27–42. Springer, 2010.
4 Detlef Plump. On termination of graph rewriting. In Manfred Nagl, editor, Proc. Graph-
Theoretic Concepts in Computer Science, volume 1017 of Lecture Notes in Computer Sci-
ence, pages 88–100, 1995.
5 Detlef Plump. Termination of graph rewriting is undecidable. Fundamenta Informaticae,
33(2):201–209, 1998.
6 Harald Zankl, Christian Sternagel, Dieter Hofbauer, and Aart Middeldorp. Finding and
certifying loops. In Jan van Leeuwen, Anca Muscholl, David Peleg, Jaroslav Pokorný, and
Bernhard Rumpe, editors, Proc. 36th Conference on Current Trends in Theory and Practice
of Computer Science (SOFSEM 2010), volume 5901 of Lecture Notes in Computer Science,
pages 755–766. Springer, 2010.