Skip to main content
Springer Nature - PMC COVID-19 Collection logoLink to Springer Nature - PMC COVID-19 Collection
. 2020 May 31;12150:128–145. doi: 10.1007/978-3-030-51372-6_8

Patch Graph Rewriting

Roy Overbeek ‡,, Jörg Endrullis
Editors: Fabio Gadducci8, Timo Kehrer9
PMCID: PMC7314713

Abstract

The basic principle of graph rewriting is the stepwise replacement of subgraphs inside a host graph. A challenge in such replacement steps is the treatment of the patch graph, consisting of those edges of the host graph that touch the subgraph, but are not part of it.

We introduce patch graph rewriting, a visual graph rewriting language with precise formal semantics. The language has rich expressive power in two ways. First, rewrite rules can flexibly constrain the permitted shapes of patches touching matching subgraphs. Second, rules can freely transform patches. We highlight the framework’s distinguishing features by comparing it against existing approaches.

Keywords: Graph rewriting, Embedding, Visual language

Introduction

When matching a graph pattern P inside a host graph G, G can be partitioned into (i) a match M, a subgraph of G isomorphic to the pattern P; (ii) a context C, the largest subgraph of G disjoint from M; and (iii) a patch J, the graph consisting of the edges that are neither in M nor in C. So the patch consists of edges that are either (a) between M and C, in either direction, or (b) between vertices of M not captured by the pattern P. For example, if P and G are respectively graphic file with name 495607_1_En_8_Figa_HTML.jpg then the thick green subgraph is the (only) match M of P in G. The black subgraph of G is the context C, and the dotted red subgraph is the patch J. Metaphorically, patch J patches match M and context C together.

In graph rewriting, subgraphs of some host graph are stepwise replaced by other subgraphs. A requirement for such replacements is that they are properly re-embedded in the host graph. We contend that the patch is the most distinctive and interesting aspect of graph rewriting. This is because its shape is generally unpredictable, making it challenging to specify what constitutes a proper re-embedding of a subgraph replacement. This contrasts strongly with the situation for string and term rewriting, in which the embeddings of substrings and subterms are highly regular.

Most existing approaches to graph rewriting are rather uniform and coarse-grained in their treatment of the patch. For instance, suppose that we wish to delete the match M from G. What should happen to the edges of patch J, which would be left “dangling” by such a removal? The popular double-pushout (DPO) [9] approach to graph rewriting conservatively dictates that the application is not allowed in the first place: nodes connected to the patch must be preserved by the rewrite step, and the patch shall remain connected as before. The single-pushout (SPO) [18] variant, by contrast, permissively answers that such a deletion is always possible. As a side-effect, however, any resulting dangling patch edges are discarded.

In this paper, we introduce the patch graph rewriting (PGR) language. It has the following features:

  • Pluriform, fine-grained control over patches. Rules themselves encode which kinds of patches are allowed around matches, as well as how they should be transformed for the re-embedding, using a unified notation. Thus, these policies are distinctly not decided on the level of the framework.

  • An intuitive visual language. Despite their expressive power and formal semantics, patch rewrite rules admit a visual representation that we believe to be highly intuitive.

  • Lightweight formal semantics. The formal details of PGR are based on elementary set and graph theory, and therefore accessible to a wide audience. In particular, an understanding of category theory is not required to understand these details, unlike for many dominant approaches in graph rewriting.

The remainder of our paper is structured as follows. To fix ideas and emphasize the visual language of PGR, we first provide an intuitive exposition in Sect. 2, and then follow with a formal introduction in Sect. 3. We show the usefulness of PGR by modeling wait-for graphs and deadlock detection in Sect. 4. We compare PGR to other approaches in Sect. 5. In Sect. 6, finally, we mention some future research directions for PGR.

Intuitive Semantics

We start with an intuitive introduction of PGR, to be made formally precise in Sect. 3. The graph G in Fig. 1 will serve as our leading example.

Fig. 1.

Fig. 1.

Graph G.

We begin by considering the rewrite rule in Fig. 2. Figure 3 contains a depiction of G in which the match, context and patch are highlighted: the thick green subgraph is the match for the left-hand side of the rule, the solid black subgraph is the context for this rule application, and the red dotted edges form the patch. In PGR, the rewrite rule in Fig. 2 cannot yet be applied in G. This is because without further annotations, the rule may only be applied if the patch is empty, that is, if the node with the a-loop has no additional edges. In effect, this rule only allows replacing an isolated node with an a-loop by two isolated nodes, one of which has a b-loop.

Fig. 2.

Fig. 2.

A simple rule.

Fig. 3.

Fig. 3.

Match, context and patch.

The rule in Fig. 2 can be generalized to allow for patch edges from and to the context by annotating the left-hand side of the rule as shown in Fig. 4. We call such annotations patch type edges. They can be thought of as placeholders for sets of patch edges:

  • (i)

    The dotted arrow with source Inline graphic is a placeholder for an arbitrary number of edges from the context to the node with the a-loop.

  • (ii)

    Likewise, the outgoing dotted arrow with target Inline graphic is a placeholder for an arbitrary number of edges going into the context.

Fig. 4.

Fig. 4.

An annotated rule.

The rule is now applicable to all nodes that have an a-loop and no other loop, allowing the node to be connected to the context through an arbitrary number of edges. In particular, then, the rule is applicable to the match highlighted in Fig. 3, and it gives rise to the step shown in Fig. 5.

Fig. 5.

Fig. 5.

Applying the rule on the left.

Although we see how patch type edge annotations on the left-hand side can be used to constrain the set of permitted patches around a match, it does not tell us what to do with patch edges if a match is found. To indicate such transformations, the solution is simply to reuse the patch type edges in the right-hand side of the rule. The rule shown in Fig. 4 does not reuse any of the patch type edges, explaining why the corresponding patch edges are deleted in Fig. 5.

One way to preserve the incoming edges bound to Inline graphic and the outgoing edges bound to Inline graphic is shown in Fig. 6. As the visual representation suggests, the incoming edges bound to Inline graphic get redirected to target the upper node of the right-hand side, and the sources of the outgoing edges bound to Inline graphic are redirected to the lower node. The respective sources and targets of the edges are defined to remain unchanged. Applying the rule in G results in the rewrite step depicted in Fig. 7.

Fig. 6.

Fig. 6.

Redirecting patch edges.

Fig. 7.

Fig. 7.

Applying the rule on the left.

Using this visual language, it is easy to duplicate, remove, and redirect edges in the patch. The rule displayed in Fig. 8 removes the incoming patch edges bound to Inline graphic , and duplicates the patch edges bound to Inline graphic : one copy for the upper node of the right-hand side, and two copies for the lower node. The resulting rewrite step is shown in Fig. 9.

Fig. 8.

Fig. 8.

Duplicating patch edges.

Fig. 9.

Fig. 9.

Applying the rule on the left.

Patch graph rewriting also allows for some more exotic transformations, such as inverting patch edges or pulling edges from the context into the pattern. The rule in Fig. 10 reverses the direction of Inline graphic and pulls Inline graphic into the pattern, giving rise to the step in Fig. 11.

Fig. 10.

Fig. 10.

Complex transformation.

Fig. 11.

Fig. 11.

Applying the rule on the left.

All of the above rules are only applicable to nodes that have an a-loop and no other loop. If we want the rule to be applicable to nodes that have additional loops, this can be expressed as in Fig. 12. This rule is now applicable to any node with an a-loop. It makes a copy of the node, as well as all edges incident to it (except for the a-loop, which is removed). If we slightly modify G to include an f-loop on the middle node, the rule gives rise to the rewrite step in Fig. 13.

Fig. 12.

Fig. 12.

Node duplication.

Fig. 13.

Fig. 13.

Applying the rule on the left.

In this brief visual introduction, we have focused on the transformation of the patch. The left-hand sides of the rules has each time been a single node with an a-loop. Its generalization to other patterns is largely obvious, but some edge cases arise. For instance, what could be the semantics of the rule Inline graphic which redirects patch edges between nodes of the pattern into the context? We now turn to the formal semantics of path rewriting, which makes all preceding transformations precise and excludes such edge cases.

Formal Semantics

Notation 1

(Preliminaries). For functions Inline graphic and Inline graphic with disjoint domains (but possibly overlapping codomains), we write Inline graphic for the function Inline graphic given by the union of f and g’s underlying graphs. If typing permits, we generalize functions f to tuples (xy) and sets S in the obvious way, i.e., Inline graphic and Inline graphic.

We define directed, edge-labeled multigraphs in the standard way.

Definition 2

(Graph). A graph Inline graphic with edge labels from L consists of a finite set of vertices (or nodes) V, a finite set of edges E, a source map Inline graphic, a target map Inline graphic, and a labeling Inline graphic. For Inline graphic, we say that Inline graphic, Inline graphic and Inline graphic are the source, target and label of e, respectively.

For convenience, we will write Inline graphic to denote an edge Inline graphic such that Inline graphic, Inline graphic and Inline graphic.

Definition 3

(Basic Graph Notions). We define the following basic graph notions:

  • (i)

    An unlabeled graph Inline graphic is a graph Inline graphic over a singleton label set. In this case we suppress the edge labels.

  • (ii)

    A graph is simple if for all Inline graphic, Inline graphic, Inline graphic and Inline graphic together imply Inline graphic.

  • (iii)

    We say that graphs G and H are disjoint if Inline graphic.

  • (iv)
    For disjoint edge sets Inline graphic, we define the graph union as follows:
    graphic file with name 495607_1_En_8_Equ4_HTML.gif

To rename vertices and edges of a graph, we introduce “graph renamings”. A renaming is a graph isomorphism, where the domain of the renaming is allowed to be a superset of the set of vertices/edges of the graph. In this way, the same renaming can be applied to various graphs with different vertex and edge sets.

Definition 4

(Graph Renaming). A graph renaming Inline graphic for a graph G consists of two bijective functions Inline graphic and Inline graphic such that Inline graphic and Inline graphic.

The Inline graphic-renaming of G, denoted Inline graphic, is the graph Inline graphic defined by

graphic file with name 495607_1_En_8_Equ5_HTML.gif

for every Inline graphic.

Definition 5

(Graph Isomorphism). Graphs G and H are isomorphic, denoted Inline graphic, if there is a graph renaming Inline graphic such that Inline graphic.

Let L be a finite nonempty set of labels. In the sequel, we tacitly assume that all graphs have labels from L.

As motivated by the preceding sections, we allow to compose a context graph C and a match graph M by a “patch” J that may add edges between the nodes of C and M, as well as between the nodes of M.

Definition 6

(Patch). Let C and M be disjoint graphs. A patch for C and M is a graph J such that Inline graphic and Inline graphic, and

graphic file with name 495607_1_En_8_Equ6_HTML.gif

for every edge Inline graphic. In this relation mediated by J, we call C the context graph and M the match graph.

Definition 7

(Patch Composition). Let J be a patch for a context graph C and a match graph M. The patch composition of C and M through patch J, denoted by Inline graphic, is the graph union Inline graphic.

Example 8

Consider the following graphs C, M and G, respectively: graphic file with name 495607_1_En_8_Figm_HTML.jpg The composition of C and M through patch Inline graphic is G, in which C functions as the context graph and M functions as the match graph (w.r.t. J).

Before we consider the formal definition of rewriting, let us discuss the basic principle and motivate some of the design choices. As a first approximation, a graph rewrite rule Inline graphic is a pair of graphs that behave like patterns. Since the edge and vertex identities in such rules are arbitrary (not to be confused with the edge labeling), we close the rule under isomorphism. The rule should also be applicable in contexts in which a patch connects a context and the pattern of the rule. The rule Inline graphic thus give rise to rewrite steps of the form Inline graphic for graphs C, valid patches Inline graphic and graphs Inline graphic and Inline graphic.

Additionally, we would like to exert control over the shape of patches in two ways. A graph rewriting rule should enable one to (a) constrain the choices for the patch J, and (b) define the patch Inline graphic in terms of J. For these purposes, we introduce the concepts of a patch type and a scheme.

Definition 9

(Patch Type). A patch type T for a graph G is an unlabeled patch for G and the trivial graph with node set Inline graphic. Here, the trivial graph functions as the context graph.

Let J be a patch for a context graph C and match graph M, and T a patch type for M. A patch edge Inline graphic (Inline graphic any label) adheres to a patch type edge Inline graphic if the following conditions hold:

graphic file with name M41.gif

The patch J adheres to patch type T if there exists an adherence map from J to T, i.e., a function Inline graphic such that e adheres to f(e) for every Inline graphic.

The restriction to unlabeled patch type edges is motivated purely by simplicity. We intend to relax the definition in future work.

Proposition 10

(Unique Adherences). Let the patch type T be a simple graph. If a patch J adheres to T, then the witnessing adherence map is unique.

Intuitively, we use patch types to annotate the patterns of a rewrite rule. The result we call a scheme.

Definition 11

(Scheme). A scheme is a pair (PT) consisting of a graph P, called a pattern, and a patch type T for P.

graphic file with name 495607_1_En_8_Fign_HTML.jpg

Example 12

(Depicting Schemes). We extend the representation for graphs to schemes (PT) as shown on the right. The pattern P consists of the solid labeled arrows, and the patch type T consists of the dotted arrows. For dotted arrows without a source (or target), the source (or target) is implicitly the context graph node Inline graphic. So T consists of the edges Inline graphic.

We are now ready to define a graph rewrite rule as a relation between schemes Inline graphic and Inline graphic. We equip the rewrite rule with a “trace function” Inline graphic that relates edges in Inline graphic back to edges in Inline graphic, allowing us to interpret Inline graphic as a transformation of Inline graphic, in which patch edges may be freely moved, deleted, duplicated and inverted. For this we require the following constraint: if a patch type edge Inline graphic connects to the context, the corresponding edge Inline graphic must also connect to the context. Without this constraint, it would not be clear how to interpret e’s connection to the context.

Definition 13

(Quasi Patch Graph Rewrite Rule). A quasi patch graph rewrite rule Inline graphic is a pair of schemes Inline graphic and Inline graphic, equipped with a trace function Inline graphic that satisfies Inline graphic for all Inline graphic.

We normally require the left patch type Inline graphic to be simple, so that the edges of Inline graphic-adherent patches J adhere to a single edge in Inline graphic (Proposition 10). As we shall see, this allows us to define a graph rewrite relation in which matches of a rule produce a unique result (modulo Inline graphic).

Definition 14

(Patch Graph Rewrite Rule). A patch graph rewrite rule is a quasi patch graph rewrite rule Inline graphic in which Inline graphic is simple.

Since we restrict attention to unlabeled patch type graphs in this paper, we will use the opportunity to visualize the trace function Inline graphic by means of labels on patch type edges.

Example 15

(Depicting Rules). A depiction of a valid rewrite rule is: graphic file with name 495607_1_En_8_Figo_HTML.jpg The trace function Inline graphic is visualized by means of labels on the type edges: Inline graphic maps type edges with label n on the right-hand side to the type edge with label n on the left-hand side. Throughout the paper, colors are merely used as a supplementary visual aid. (An application example will be given in Example 19.)

Definition 16

(Rule Isomorphism). (Quasi) rewrite rules Inline graphic and Inline graphic are isomorphic, denoted Inline graphic, if there exists a graph renaming Inline graphic such that Inline graphic, Inline graphic, and Inline graphic.

Definition 17

(Patch Graph Rewrite System). A (quasi) patch graph rewrite system (PGR) Inline graphic is a set of (quasi) rewrite rules. For Inline graphic we define the isomorphism closure class Inline graphic.

For a patch J, patch type T and adherence map Inline graphic, we define

graphic file with name 495607_1_En_8_Equ7_HTML.gif

for every Inline graphic. So Inline graphic contains the context node involved in the edge e, or is Inline graphic if the edge does not involve the context.

Definition 18

(Patch Graph Rewriting). A (quasi) patch graph rewrite system Inline graphic induces a rewrite relation Inline graphic on the set of graphs as follows:

Inline graphic if

  • (i)

    Inline graphic,

  • (ii)

    Inline graphic is an adherence map from patch J to patch type Inline graphic,

  • (iii)

    Inline graphic is an adherence map from patch Inline graphic to patch type Inline graphic, and

  • (iv)

    for every Inline graphic there exists a bijection Inline graphic such that Inline graphic and Inline graphic for every Inline graphic.

For such a rewrite step, we say that the graph Inline graphic contains the redex Inline graphic.

Example 19

(Application Example). The rule given in Example 15 gives rise to the following rewrite step: graphic file with name 495607_1_En_8_Figp_HTML.jpg In the graph on the left we have highlighted the match (thick green) and the patch (dotted). We have additionally indicated the adherence map of the patch edges by reusing the colors of the rule definition.

We refer to Sect. 2 for many examples of simple rewrite rules and rewrite steps. A graph rewrite system modeling wait-for-graphs will be given in Sect. 4.

Remark 20

(Finding Redexes). Checking for the presence of a redex is simple. A graph G contains a redex with respect to rule Inline graphic if and only if

  1. there exists a subgraph M of G isomorphic to Inline graphic, and

  2. every edge Inline graphic incident to a Inline graphic adheres to an edge in Inline graphic.

Definition 18 can be understood in more operational terms as follows.

Lemma 21

(Constructing Inline graphic). If conditions (i) and (ii) of Definition 18 are satisfied (fixing some adherence map Inline graphic), the patch Inline graphic and adherence map Inline graphic that satisfy conditions (iii) and (iv) are uniquely determined up to isomorphism. The patch Inline graphic can be constructed using the following procedure.

For every type edge Inline graphic, consider every patch edge Inline graphic for which Inline graphic. There are five exclusive cases:

  1. If Inline graphic, add a new edge Inline graphic to Inline graphic.

  2. If Inline graphic, add a new edge Inline graphic to Inline graphic.

  3. If Inline graphic, add a new edge Inline graphic to Inline graphic.

  4. If Inline graphic, add a new edge Inline graphic to Inline graphic.

  5. If Inline graphic, add a new edge Inline graphic to Inline graphic.

Here, the “new” edge Inline graphic is an edge not in C, Inline graphic or the intermediate construction of Inline graphic. The adherence map Inline graphic is defined such that Inline graphic for each of the considered Inline graphic and t.

Non-quasi rules have the following desirable property.

Proposition 22

(Rule Determinism). Let Inline graphic. If a rule Inline graphic derives both Inline graphic and Inline graphic, then Inline graphic.

Proof

This is a direct consequence of Proposition 10 and Lemma 21.    Inline graphic

In contrast to (non-quasi) graph rewrite rules, quasi rules are not generally deterministic. For instance, consider the quasi rewrite rule graphic file with name 495607_1_En_8_Figq_HTML.jpg which can match any graph G consisting of two nodes x and y and n edges from x to y. For each Inline graphic, the left adherence map Inline graphic can either map e to the patch type edge labeled with 1, or to the type edge labeled with 2. Thus, Inline graphic choices for Inline graphic are possible, and each choice causes a different subset of J to be deleted in a single rewrite step.

Notation 23

(Shorthand Notation). Given a pattern P, we often want to allow for any patch edges between the nodes of a subset Inline graphic as well as the context node Inline graphic. In the notation we have discussed so far, we would then need to draw the complete patch type graph induced by Inline graphic (minus the loop on Inline graphic), which consists of Inline graphic patch type edges.

To avoid spaghetti-like figures, we extend the visual presentation of schemes by allowing each node to be annotated with a set of names (written without set brackets). We say that a node has name x if x is in the set of names of this node. So a node can have 0 or more names. The name annotations are then shorthand for the following patch type edges:

  • (i)

    For every node n and name x of n, the node n has the two patch type edges Inline graphic from and to the context.

  • (ii)

    For every pair of nodes nm and every name x of n and y of m, there is implicitly the patch type edge Inline graphic from n to m. Here n and m can be the same node, and x can be equal to y.

Observe that rules are non-quasi iff every node in the left-hand side has at most one name. We therefore require that distinct nodes do not share names.

As an example, a rule for merging two nodes can be written as

graphic file with name 495607_1_En_8_Equ1_HTML.gif 1

which is shorthand for graphic file with name 495607_1_En_8_Figt_HTML.jpg

Modeling Wait-for Graphs and Deadlock Detection

We now give a more extensive and more realistic modeling example that showcases the expressive power of PGR.

A wait-for graph [14] is a hypergraph in which nodes represent processes, and hyperedges represent requests for resources. A hyperedge has a single source p, representing the process requesting the resources, and Inline graphic targets distinct from p, representing the processes from which a resource is requested. The process p requires Inline graphic of these resources. Thus, for a fixed M, there are multiple types of hyperedges, each representing a particular N-out-of-M request. Processes can have at most one outgoing N-out-of-M request.

The following distributed system behavior is associated with wait-for graphs. A process without an outgoing request is said to be unblocked. An unblocked process can grant an incoming request, deleting the edge, or create a new N-out-of-M request. A process becomes unblocked when its pending N-out-of-M request is resolved, i.e., when N targeted processes have granted the request.

In order to better illustrate some of PGR’s transformational power, we introduce one additional, noncanonical behavior. We consider a process p overloaded when it has Inline graphic incoming requests. When p is overloaded, a clone of p, c(p), may be created which takes over Inline graphic of p’s incoming requests. Because we assume that any outgoing request must be resolved before any incoming requests can be resolved, c(p) replicates p’s outgoing request, if p has one.

We first define a graph grammar that defines the class of valid wait-for graphs. Then, we will show how to augment the rule set in order to model the distributed system behavior. Finally, we explain how deadlocks can be detected. Throughout, we encode hypergraphs as multigraphs. Note that in this encoding, vertices representing processes are always free of loops, while vertices representing hyperedges always have loops. Hence, the given rules can appropriately discriminate between the two types of vertices.

Wait-for Graph Grammar

The starting graph of the grammar is the empty graph, denoted by Inline graphic. Rule

graphic file with name 495607_1_En_8_Figu_HTML.jpg

models process creation, and rule

graphic file with name 495607_1_En_8_Figv_HTML.jpg

allows constructing a valid 1-out-of-1 request between nodes. Labels z and s should be interpreted as 0 and the successor function, respectively, so that n s-loops encode that n requests are yet to be granted.

In the grammar, any N-out-of-M request can be extended to a valid N-out-of-Inline graphic request using rule

graphic file with name 495607_1_En_8_Figw_HTML.jpg

and to a valid Inline graphic-out-of-Inline graphic request using rule

graphic file with name 495607_1_En_8_Figx_HTML.jpg

These four rules suffice for generating any valid wait-for graph.

System Modeling

To model a distributed system, we need rule CREATE for process creation, as well as its inverse, destroy, for process destruction. Note that destroy constrains the process selected for destruction to be isolated in our framework (i.e., it is not associated with any pending requests), as desired.

Any N-out-of-M request is understood to be an atomic action. So for, e.g., modeling 2-out-of-2 requests, we need the rule graphic file with name 495607_1_En_8_Figy_HTML.jpg

Such rules can be easily simulated by a contiguous sequence of rewrite steps 1-OF-1 Inline graphic EXT-0Inline graphic Inline graphic EXT-1Inline graphic, in which the node making the request remains fixed. We omit the details.

A grant request may be modeled by

graphic file with name 495607_1_En_8_Figz_HTML.jpg

and a request resolution by

graphic file with name 495607_1_En_8_Figaa_HTML.jpg

This leaves only the cloning behavior for an overloaded process p. This requires two rules: one for the case in which p is unblocked, and one for the case in which p is blocked. We use the shorthand notation introduced in Notation 23, so that named nodes Inline graphic induce type edges among themselves and from and into the context.1

The case in which p is unblocked is modeled by rule

graphic file with name 495607_1_En_8_Figab_HTML.jpg

and the case in which p is blocked is modeled by rule

graphic file with name 495607_1_En_8_Figac_HTML.jpg

Cloning would be easier to express if PGR were to be extended with support for hyperedges and cardinality constrained type edges. We envision a rule like graphic file with name 495607_1_En_8_Figad_HTML.jpg

to capture the same cases as rules CLONE-1 and CLONE-2 combined. We leave such an extension to future work. In particular, the precise semantics of hyperedge transformation would have to be determined.

Deadlock Detection

Deadlock detection on some valid wait-for graph G can be performed by restricting the rewrite system to rules GRANT, RESOLVE and destroy, yielding a terminating rewrite system. Then the network represented by G contains a deadlock if and only if the (unique) normal form of G is the empty graph Inline graphic.

Comparison

We compare PGR to several other rewriting frameworks. We have selected these frameworks because of their popularity and/or because they bear certain similarities to our approach.

Double-Pushout (DPO). Ehrig et al.’s double-pushout approach (DPO) [9] is one of the most prominent approaches in graph rewriting.

A rewrite rule in the DPO approach is of the form Inline graphic, where L is the subgraph to be replaced by subgraph R. The graph K is an “interface”, used to identify a part of L with a part of R, and it can be thought of as describing which part of L is preserved by the rule. The identification is formally established through the inclusion Inline graphic and the graph morphism Inline graphic. The morphism Inline graphic may be non-injective, allowing it to merge nodes that are in the interface.

A DPO rewrite rule Inline graphic is applied inside a graph G as follows [7, 8]. Let Inline graphic be a graph morphism, which we may assume to be injective [16]. The graph Inline graphic is said to be a match for L. The arising rewrite step replaces m(L) of G by a fresh copy c(R) of R, redirecting edges left dangling by the removal of a Inline graphic to node Inline graphic. For the redirection of edges to work, nodes that leave dangling ends need to be part of the interface, that is, in Inline graphic. This is known as the “gluing condition”.2 If the gluing condition is not met, the rewrite step is not permitted.

Using Notation 23, it is easy to see that PGR at least as expressive as DPO with respect to the generated rewrite relation. A DPO rule Inline graphic can be directly simulated by a PGR rule Inline graphic in which the nodes are annotated with their (set of) names in the interface: Inline graphic is annotated with the names Inline graphic, and Inline graphic is annotated with the names Inline graphic.

However, DPO is stronger in one respect: a DPO rewrite step preserves the subgraph specified in K, whereas a PGR rewrite can be thought of as destroying and replacing the left-hand side of the rule. The consequences for metaproperties relating to parallelism and concurrency will have to be investigated.

Generalized DPO. In some variants of DPO, the inclusion Inline graphic is generalized to a (possibly non-injective) morphism Inline graphic. Intuitively, this allows a node v of L to be “split apart” in the interface K. Applying the DPO method to a host graph ensures that the patch graph edges incident to v will be incident to one of v’s split copies. It does not dictate how these edges should be distributed. Thus, such rewrite steps are non-deterministic.

Generalized DPO rules Inline graphic can be translated to PGR rules Inline graphic in the same way as discussed for DPO. Since Inline graphic is no longer required to be injective, nodes Inline graphic can be annotated with multiple names Inline graphic, thereby leading to (non-deterministic) quasi rules (Definition 13).

Single-Pushout (SPO). The single-pushout (SPO) approach by Löwe [18] is the destructive sibling of DPO. It is operationally like DPO, but it drops the gluing condition. Any edges that would become dangling in the host graph are instead removed.

An SPO rule Inline graphic can be simulated by a PGR rule Inline graphic with annotations as discussed above for DPO, except that each node Inline graphic, for which Inline graphic is empty, is now annotated by a fresh name. The rewrite step will then delete all patch edges connected to such a node.

DPO Rewriting in Context (DPO-C). The DPO Rewriting in Context (DPO-C) approach by Löwe [19, 20] addresses the issue of non-determinism in generalized variants of DPO, using ingoing and outgoing arrow annotations to dictate how these edges should be distributed over split copies. The visual representation of DPO-C therefore bears some similarity to that of PGR. In addition, absence of arrow annotations also define negative application conditions like in PGR. However, the patch cannot be transformed as freely as in PGR. For instance, see rule (2) below.

AGREE. AGREE [3] and PBPO [4] by Corradini et al. extend DPO with the ability to erase and clone nodes, while also being able to specify how patch edges are distributed among the copies. For this purpose, a “filter” for the edges determines what kind of patch edges are to be dropped. This filter can distinguish different types of edges based on their source, target and label. Thereby AGREE and PBPO subsume mildly restricted versions of DPO, SPO, and other formalisms.

PGR has some features that are not present in AGREE and PBPO. First, in PGR rule applicability can be restricted by conditions on the permitted shape of the patch. Second, PGR allows (almost) arbitrary redirecting, moving and copying of patch edges outside the scope of AGREE and PBPO. For instance,

graphic file with name 495607_1_En_8_Equ2_HTML.gif 2

cannot be expressed in the latter frameworks. Also inverting the direction of patch edges, or moving patch edges between nodes of the pattern is not possible in AGREE and PBPO.

On the other hand, AGREE and PBPO capture some transformations that cannot be expressed in PGR. First, AGREE and PBPO can express some global transformations, unlike PGR. Second, the “patch edge filter” in AGREE and PBPO can distinguish patch edges depending on their label and the “type” of the source/target in the context (here the type is given by some type graph). Both features are not present in PGR as presented in this paper. However, PGR can be extended with constraints on the patch type edges. We leave the investigation of a suitable constraint language to future work.

Nagl’s Approach. Nagl [21] has defined a very powerful graph transformation approach. Rather than identifying “gluing points” for the replacement of L by R in a host graph G (as in the previous approaches), rules are equipped with expressions that describe how R is to be embedded into the remainder graph Inline graphic. An expression can, e.g., specify that an edge must be created from Inline graphic to Inline graphic if there existed a path (of certain length and containing certain labels) from u to a Inline graphic. Thus, the embedding context may no longer even be local.

While not all of these transformations are supported by PGR, the expressions are arguably much less intuitive than our representation, in which both application conditions and transformations are visualized in a unified manner.

Habel et al.’s Approach. Habel et al. [15] have introduced graph grammars with rule-dependent application conditions that also admit a very intuitive visual representation. These conditions are more powerful than PGR’s application conditions, since they can extend arbitrarily far into the context graph. However, transformations are not included in the approach, unlike in PGR, in which the notations for application conditions and transformations are unified.

Drags. To generalize term rewriting techniques to the domain of graphs, Dershowitz and Jouannaud [6] have recently defined the drag data structure and framework. A drag is a multigraph in which nodes are labeled by symbols that have an arity equal to the node’s outdegree. Nodes labeled with nullary variable symbols are called sprouts, and resemble output ports. In addition, the drag comes equipped with a finite number of roots, which resemble input ports.

A composition operation Inline graphic for drags, parameterized by a two-way switchboard Inline graphic identifying sprouts with roots, gives rise to a rewrite relation Inline graphic. For this rewrite relation to be well-defined, it is required, among others, that L and R have the same number of roots and the same multisets of variables.

Since drag rewriting imposes arity restrictions on nodes, it is more restrictive than patch rewriting concerning the shapes of the graphs that can be rewritten. As drag rewrite steps are local, we believe that PGR can simulate them, but we leave this investigation to future work.

Conclusion

We have introduced patch graph rewriting, a framework for graph rewriting that enriches the rewrite rules with a simple, yet powerful language for constraining and transforming the local embedding—or patch.

For future work, we plan to investigate various meta-properties central in graph rewriting [8], in particular confluence [12, 17, 22], termination [2, 5], the concurrency theorem [10], decomposability and reversibility of rules. We intend to study these properties both globally, for all graphs, as well as locally [11, 13], for a given language of graphs [23]. Furthermore, we are interested in extending the framework with constraint labels on patch type edges, and in allowing label transformations. We believe this could be useful for modeling a larger class of distributed algorithms [14]. Another interesting direction of research is an equational perspective on patch rewriting, as similarly investigated by Ariola and Klop for term graph rewriting [1].

Acknowledgments

This paper has benefited from discussions with Jan Willem Klop, Nachum Dershowitz, Femke van Raamsdonk, Roel de Vrijer, and Wan Fokkink. We thank Andrea Corradini and the anonymous reviewers for their useful suggestions. Both authors received funding from the Netherlands Organization for Scientific Research (NWO) under the Innovational Research Incentives Scheme Vidi (project. No. VI.Vidi.192.004).

Footnotes

1

The type edges between distinctly named nodes Inline graphic are redundant in the considered scenario, since we know that these type edges will never have adherents.

2

By the injectivity assumption for m, we need not consider what is known as the “identification condition”.

Contributor Information

Fabio Gadducci, Email: gadducci@di.unipi.it.

Timo Kehrer, Email: timo.kehrer@informatik.hu-berlin.de.

Roy Overbeek, Email: r.overbeek@vu.nl.

Jörg Endrullis, Email: j.endrullis@vu.nl.

References

  • 1.Ariola ZM, Klop JW. Equational term graph rewriting. Fundamenta Informaticae. 1996;26(3,4):207–240. doi: 10.3233/FI-1996-263401. [DOI] [Google Scholar]
  • 2.Bruggink HJS, König B, Zantema H. Termination analysis for graph transformation systems. In: Diaz J, Lanese I, Sangiorgi D, editors. Theoretical Computer Science; Heidelberg: Springer; 2014. pp. 179–194. [Google Scholar]
  • 3.Corradini A, Duval D, Echahed R, Prost F, Ribeiro L. AGREE – algebraic graph rewriting with controlled embedding. In: Parisi-Presicce F, Westfechtel B, editors. Graph Transformation; Cham: Springer; 2015. pp. 35–51. [Google Scholar]
  • 4.Corradini A, Duval D, Echahed R, Prost F, Ribeiro L. The PBPO graph transformation approach. J. Log. Algebr. Meth. Program. 2019;103:213–231. doi: 10.1016/j.jlamp.2018.12.003. [DOI] [Google Scholar]
  • 5.Dershowitz, N., Jouannaud, J.-P.: Graph path orderings. In LPAR, volume 57 of EPiC Series in Computing, EasyChair, pp. 307–325 (2018). 10.29007/6hkk
  • 6.Dershowitz N, Jouannaud J-P. Drags: a compositional algebraic framework for graph rewriting. Theor. Comput. Sci. 2019;777:204–231. doi: 10.1016/j.tcs.2019.01.029. [DOI] [Google Scholar]
  • 7.Ehrig H. Tutorial introduction to the algebraic approach of graph grammars. In: Ehrig H, Nagl M, Rozenberg G, Rosenfeld A, editors. Graph-Grammars and Their Application to Computer Science; Heidelberg: Springer; 1987. pp. 1–14. [Google Scholar]
  • 8.Ehrig H, Korff M, Löwe M. Tutorial introduction to the algebraic approach of graph grammars based on double and single pushouts. In: Ehrig H, Kreowski H-J, Rozenberg G, editors. Graph Grammars and Their Application to Computer Science; Heidelberg: Springer; 1991. pp. 24–37. [Google Scholar]
  • 9.Ehrig, H., Pfender, M., Schneider, H.J.: Graph-grammars: an algebraic approach. In: Proceedings of the 14th Annual Symposium on Switching and Automata Theory, Swat 1973, pp. 167–180. IEEE Computer Society (1973). 10.1109/SWAT.1973.11
  • 10.Ehrig H, Rosen BK. Parallelism and concurrency of graph manipulations. Theoret. Comput. Sci. 1980;11(3):247–275. doi: 10.1016/0304-3975(80)90016-X. [DOI] [Google Scholar]
  • 11.Endrullis, J., de Vrijer, R.C., Waldmann, J.: Local termination theory and practice. Logical Methods Comput. Sci. 6(3) (2010)
  • 12.Endrullis, J., Klop, J.W., Overbeek, R.: Decreasing diagrams for confluence and commutation. Logical Methods Comput. Sci. 16(1) (2020). 10.23638/LMCS-16(1:23)2020
  • 13.Endrullis, J., Zantema, H.: Proving non-termination by finite automata. In: Proceedings Conference on Rewriting Techniques and Applications, RTA 2015, LIPIcs, vol. 36, pp. 160–176. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik (2015). 10.4230/LIPIcs.RTA.2015.160
  • 14.Fokkink W. Distributed Algorithms: An Intuitive Approach. Cambridge: MIT Press; 2014. [Google Scholar]
  • 15.Habel A, Heckel R, Taentzer G. Graph grammars with negative application conditions. Fundam. Inform. 1996;26(3/4):287–313. doi: 10.3233/FI-1996-263404. [DOI] [Google Scholar]
  • 16.Habel A, Müller J, Plump D. Double-pushout graph transformation revisited. Math. Struct. Comput. Sci. 2001;11(5):637–688. doi: 10.1017/S0960129501003425. [DOI] [Google Scholar]
  • 17.Heckel R, Küster JM, Taentzer G. Confluence of typed attributed graph transformation systems. In: Corradini A, Ehrig H, Kreowski H-J, Rozenberg G, editors. Graph Transformation; Heidelberg: Springer; 2002. pp. 161–176. [Google Scholar]
  • 18.Löwe M. Algebraic approach to single-pushout graph transformation. Theor. Comput. Sci. 1993;109(1&2):181–224. doi: 10.1016/0304-3975(93)90068-5. [DOI] [Google Scholar]
  • 19.Löwe M. Double-pushout rewriting in context. In: Mazzara M, Ober I, Salaün G, editors. Software Technologies: Applications and Foundations; Cham: Springer; 2018. pp. 447–462. [Google Scholar]
  • 20.Löwe M. Double-pushout rewriting in context. In: Guerra E, Orejas F, editors. Graph Transformation; Cham: Springer; 2019. pp. 21–37. [Google Scholar]
  • 21.Nagl M. Set theoretic approaches to graph grammars. In: Ehrig H, Nagl M, Rozenberg G, Rosenfeld A, editors. Graph-Grammars and Their Application to Computer Science; Heidelberg: Springer; 1987. pp. 41–54. [Google Scholar]
  • 22.Plump D. Confluence of graph transformation revisited. In: Middeldorp A, van Oostrom V, van Raamsdonk F, de Vrijer R, editors. Processes, Terms and Cycles: Steps on the Road to Infinity; Heidelberg: Springer; 2005. pp. 280–308. [Google Scholar]
  • 23.Rensink A. Canonical graph shapes. In: Schmidt D, editor. Programming Languages and Systems; Heidelberg: Springer; 2004. pp. 401–415. [Google Scholar]

Articles from Graph Transformation are provided here courtesy of Nature Publishing Group

RESOURCES