Nov 14, 2014 - BS02-016), TGV (CNRS-INRIA-FAPERGS/(156779 and 12/0997-7)), VeriTeS. (CNPq/FAPERGS 11/2016-2 and 485048/2012-4) and PLATUS ...
AGREE – Algebraic Graph Rewriting with Controlled Embedding? A. Corradini1 and D. Duval2 and R. Echahed3 and F. Prost3 and L. Ribeiro4
arXiv:1411.4597v1 [cs.LO] 14 Nov 2014
1
4
Dipartimento di Informatica, Universit` a di Pisa, 2 LJK - Universit´e de Grenoble 3 LIG - Universit´e de Grenoble INF - Universidade Federal do Rio Grande do Sul
Abstract. The several algebraic approaches to graph transformation proposed in the literature all ensure that if an item is preserved by a rule, so are its connections with the context graph where it is embedded. But there are applications in which it is desirable, for example when cloning an item, to specify different embeddings for the original and for the copy. Therefore we propose a conservative extension of these approaches where a rule can specify how the embedding of a preserved item should be changed, typically by removing certain connections.
1
Introduction
Graphs are used to describe a wide range of situations in a precise yet intuitive way. Different kinds of graphs are used in modeling techniques depending on the investigated fields, which include computer science, chemistry, biology, quantum computing, etc. When system states are represented by graphs, it is natural to use rules that transform graphs to describe the system evolution. Mastering graph transformation specification is easier when exploiting advanced languages and techniques which allow one to specify the dynamics of graphs at an abstract level [21,12,13]. There are two main streams in the research on graph transformations: (i) the algorithmic approaches, which describe explicitly, with a concrete algorithm, the result of applying a rule to a graph (see e.g. [16,1,11]), and (ii) the algebraic approaches which define abstractly a graph transformation step using basic constructs borrowed from category theory. In this paper we will consider mainly the latter. The basic idea of all approaches is the same: states are represented by graphs and state changes are represented by rules that modify graphs. The differences are the kind of graphs that may be used, and the definitions of when and how rules may be applied. One critical point when defining graph transformation is that one cannot delete or copy part of a graph without considering the effect ?
This work has been partly funded by projects CLIMT (ANR/(ANR-11BS02-016), TGV (CNRS-INRIA-FAPERGS/(156779 and 12/0997-7)), VeriTeS (CNPq/FAPERGS 11/2016-2 and 485048/2012-4) and PLATUS (CNPq 306843/2010-2).
of the operation on the rest of the graph, because deleted/copied items may be linked to others. For example, rule ρ1 in Figure 1(a) specifies that a node shall be deleted and rule ρ2 that a node shall be duplicated (C indicates the copy). What should be the result of applying these rules to the grey node of graph G in Figure 1(b)? The various approaches give different answers to this questions, in general.
Fig. 1. (a) Delete/Copy Rules (b) Resulting Graphs
The most popular algebraic approaches are the double-pushout (DPO) and the single-pushout (SPO) approaches, which can be illustrated as follows: Lo m
l PO
K d
r PO
/R
L
m0
r0 l0 /H Go D Double pushout rewrite step
m
r PO
/R m0
r0 /H G Single pushout rewrite step
In the DPO approach [15,6], a rule is defined as a span ρ = L ← K → R and a match is a morphism m : L → G. A graph G rewrites into a graph H using rule ρ and match m if the diagram above to the left can be constructed, where both squares are pushouts. Conditions for the existence and uniqueness of graph D need to be studied explicitly, because it is not obtained with a universal construction. With DPO rules (spans of graphs) it is easy to specify the addition, deletion, merging or cloning of items, but their applicability is limited. For example, rule ρ1 of Figure 1 is not applicable to the grey node of G (as it would leave dangling edges), and a rule like ρ2 is usually forbidden as the pushout complement D would not be unique. In the SPO approach [20,18,14], a rule is a partial graph morphism ψ : L → R and a match is a total morphism m : L → G. A graph G rewrites into a graph H using rule ψ and match m if a square like the one above to the right can be constructed, which is a pushout in the category of graphs and partial morphisms. Deleting, adding and merging items can easily be specified with SPO rules, and the approach is appropriate for specifying deletion of nodes in unknown context, thanks to partial morphisms. The deletion of a node causes the deletion of all edges connected to it, and thus applying rule ρ1 to G would result in graph H1 in Figure 1(b). However, since a rule is defined as a single graph morphism, copying of items (as in rule ρ2) cannot be specified directly in SPO. A more recent algebraic approach is the sesqui-pushout approach (SqPO) [5]. Rules are spans like in the DPO, but in the left square of a rewriting step D is built as a final pullback complement. This characterises D with a universal property, and makes it possible in SqPO to apply rule ρ1, obtaining the same result as in the SPO approach (graph H1), as well as rule ρ2, obtaining H2 as 2
result. Also ρ2 has a limited side effect: when a node is copied all the edges of the original node are copied as well. In particular, which edges are deleted and which are copied is not specified explicitly in the rule, but is determined by the categorical constructions that define rule application. In general, in all algebraic approaches, the items that are preserved by a rule will retain the connections they had, before the application of the rule, with items which are not in the image of the match. This holds also for items that are copied in the SqPO approach. However, there are situations in which the designer should be able to specify which of the edges connecting the original node should be copied when a node is copied, depending for example on the direction of the edges (incoming or outgoing), or on their labels, if any. For example, if the graphs of Figure 1 represent web pages (nodes) and hyperlinks among them (edges) it would be reasonable to expect that the result of copying the grey page of G with rule ρ2 would be graph H3 rather than H2, so that new hyperlinks are created only in the new page, and not in the pages pointing to the original one. This example will be discussed further in Sect. 4. As another example, the fork and clone system commands in Linux both generate a clone of a process, but with different semantics. Both commands precisely differ in the way the environment of the cloned process is dealt with: see [19] for more details. These examples motivate the rewriting approach that we introduce in this paper. In order to give the designer the possibility of controlling how the nodes that are preserved or cloned by a rule are embedded in the context graph, we propose a new algebraic approach to graph transformation where rules are triples l
r
t
of arrows with the same source r = (K → L, K → R, K TK ). Arrows l and r are the usual left- and right-hand sides, while t is a mono called the embedding: it will play its role in controlling how the edges are copied from the context. The resulting rewriting approach, called AGREE (for Algebraic Graph Rewriting with controllEd Embedding) is presented in Sect. 3. As usual for the algebraic approaches, AGREE rewriting will be introduced abstractly for a category satisfying suitable requirements, that will be introduced in Sect. 2. For the knowledgeable reader we anticipate that we will require the existence of partial map classifiers [4]. After discussing the example of web pages in Sect. 4, in Sect. 5 we show that AGREE rewriting can simulate both SqPO rewriting (restricted to mono matches) and rewriting with polarised cloning [7]. Finally some related and future works are briefly discussed in Sect. 6.
2
Preliminaries
We start recalling here the definition and a few properties of partial map classifiers: a survey on them (and on partial maps) can be found in [3,4]. Let C be a category with pullbacks. We will use the following properties of pullbacks: – monos are stable under pullbacks; 3
– the composition property of pullbacks: in a commutative diagram as below, if the left and right squares are pullbacks then the large square is a pullback; /•
• •
PB
/ •
/• PB
=⇒
/ •
• •
/•
/•
PB
/ •
/•
– and the decomposition property: in a commutative diagram as below, if the small and large squares are pullbacks then there is a unique map (the dotted arrow in the diagram) such that the left square and the top triangle are commutative, and then the left square is a pullback. • •
PB
/' •
• / •
PB
=⇒
/ •
• •
PB
/•
=
/' •
/ •
/ •
A partial map over C, denoted (i, f ) : Z * Y , is a span made of a mono i : X Z and a map f : X → Y , both in C, up to the equivalence relation (i0 , f 0 ) ∼ (i, f ) whenever there is an isomorphism h with i0 ◦ h = i and f 0 ◦ h = f . Composition of partial maps is defined using pullbacks in C. The resulting category is the category of partial maps over C, let us denote it P. Let I : C → P be the inclusion functor, which maps f : X → Y to (id X , f ) : X * Y . A functor E : P → C is right adjoint to the f inclusion functor I : C → P if there is a nat/Y X (1) · ural transformation η : Id C → E ◦ I such that ηY PB for each partial map (i, f ) : Z * Y there is a i unique total map ϕ(i, f ) : Z → E(Y ) for which / E(Y ) Z square (1) is a pullback. ϕ(i,f ) If the inclusion functor I has a right adjoint E, we will denote by (T, η, µ) the monad associated f with the adjunction I a E, called the partial /Y X (2) map classifier of C. The endofunctor T on C is ηY PB defined as T = E ◦ I, which means that T (X) = ηX E(X) for each object X and T (f ) = E(id X , f ) / T (Y ) T (X) for each map f : X → Y . In addition, it can T (f ) be shown that each component of the unit η is id X mono, and that the natural transformation η is /X X (3) cartesian, which means that for each f : X → Y the naturality commutative square (2) is a pull- i ηX PB back [4]. For each mono i : X Z we will use / T (X) Z the notation ı = ϕ(i, id X ), so that ı is defined ı
by the pullback square (3). Lemma 1. For each partial map (i, f ) : Z * Y , with i : X Z, we have T (f ) ◦ ı = ϕ(i, f ). If in addition (i, f ) is the pullback of some (j, g) with j : Y W mono, then T (f ) ◦ ı = ϕ(i, f ) = ◦ g. 4
Proof. The proof of ϕ(i, f ) = T (f ) ◦ ı is obtained by applying the composition property of pullbacks to diagram (4), where the component squares are pullbacks of shape (3) and (2), respectively. X i
Z
id X
P B(3)
ı
/X
f
ηX
/ T (X)
P B(2)
T (f )
/Y
(4) ηY
/ T (Y )
The proof of ϕ(i, f ) = ◦ f is obtained by applying the composition property of pullbacks to diagram (5), where the square on the left is a pullback by assumption and the square on the right is a pullback of shape (3). X i
Z
f
PB g
/Y
id X
j
/W
P B(3)
/Y
(5) ηY
/ T (Y )
Before discussing some example of categories that have partial map classifiers, let us recall the definition of the category of graphs. Definition 1 (category of graphs). The category of graphs Gr is defined as follows. A graph X is made of a set of nodes NX , a set of edges EX and two functions source and target sX , tX : EX → NX . A morphism of graphs f : X → Y is made of two functions f : NX → NY and f : EX → EY , such that f (e)
e
f (n) → f (p) in Y for each edge n → p in X. Example 1. All elementary toposes have a partial map classifier. These include, among others, the category Set of sets, all presheaf categories (i.e., functor catop egories like SetC , where C is a small category), and the slice categories like C ↓ X where C is a topos and X an object of C (see also Sect. 5.1). For instance, let us look at the boolean topos of sets and the non-boolean topos of graphs. In Set the partial map classifier is defined as T (X) = X + {∗} and T (f ) = f + id {∗} . The unit is made of the inclusions ηX : X → X + {∗}. For each partial function (m, f ) : X * Y , the total function ϕ(m, f ) : X → Y + {∗} “extends” f by mapping x to f (x0 ) when x = m(x0 ) and x to ∗ when x is not in the image of m. So, for each mono m : Y X in C, the total function ϕ(m, id Y ) : X → Y + {∗} maps m(y) to y for each y ∈ Y and maps x to ∗ when x is not in the image of m. op Category Gr is the presheaf category SetC where Cop has two objects {E, N } and two non-identity arrows s, t : E → N . The partial map classifier maps each graph G to the graph T (G) made of the disjoint union of G with a vertex ∗ and with an edge ∗n,p : n → p for each pair of vertices (n, p) in G + {∗}. The total morphisms ϕ(m, f ) are defined essentially as in the category of sets: 5
for each partial map (m, f ) : X * Y , the total map ϕ(m, f ) : X → T (Y ) “extends” f as follows: if x = m(x0 ) is either a vertex or an edge in the image of m then ϕ(m, f )(x) = f (x0 ); if x is a vertex of X not in the image of m then ϕ(m, f )(x) = ∗; and if x : n → p is an edge of X not in the image of m, let n0 = ϕ(m, f )(n) and p0 = ϕ(m, f )(p) (so that n0 is either n or ∗ and p0 is either p or ∗), then ϕ(m, f )(x) = ∗n0 ,p0 : n0 → p0 .
3
Algebraic Graph Rewriting with Controlled Embedding
In this section we introduce the AGREE approach to rewriting, defining rules, matches and rewriting steps. The main difference with respect to the DPO and SqPO approaches is that a rule has an additional component t : K TK , called the embedding, that enriches the interface and can be used to control the embedding of preserved items. Definition 2 (AGREE rules and matches). Let C be a category with all pullbacks, pushouts along monos and with a partial map classifier (T, η, µ). – A rule is a triple of arrows with the same t r l l r /R Lo K source ρ = (K → L, K → R, K TK ) where l and r are the left- and right-hand side, respect tively, and t is called the embedding. A rule ρ is usually depicted as in the diagram to the right. TK m
l
– A match of a rule ρ with left-hand-side K → L is a mono L G. Fact 1 Thanks to the partial map classifier, given a rule ρ and a match m as above we have as additional structure an arrow l0 = ϕ(t, l) : TK → T (L) and an arrow m = ϕ(m, id L ) : G → T (L) such that the following two diagrams are pullbacks. id L l L o K L o L ηL
T (L) o
PB l0
ηL
t
T (L) o
TK
PB
m
m
G l
t
r
Definition 3 (AGREE rewriting). Given a rule ρ = (K → L, K → R, K m TK ) and a match L G, an AGREE rewriting step G ⇒ρ,m H is constructed in two phases as follows, where arrows l0 and m exist by the previous fact: g
n0
m
l0
(a) Span G ← D → TK in diagram (6) is the pullback of G → T (L) ← TK . n Since l0 ◦ t = ηL ◦ l by Fact 1, there is a unique K D making everything commute, and it is mono because so is t. p
h
n
r
(b) R → H ← D is the pushout of D ← K → R. 6
L
o
l
m
ηL =
n
Go
m
T (L) o
D
g
P B (a)
l
/R
r
K
P O (b) h = t
(6)
p
/H
n0
TK
0
Note that by the decomposition property, also the top-left square is a pullback, and therefore D is a pullback complement of l and m. In fact both the bottom square and the enclosing one are pullbacks, the latter by Fact 1. In the general case just presented, the embedding t could have a non-local effect on the rewritten object. In the following example, based on category Set, the rule simply preserves a single element, and t is the identity. If applied to an arbitrary set, its effect is to delete all the elements not matched by the match.
This is both counterintuitive and not desirable, as it would make impossible any kind of analysis of a transformation system based on such rules. Therefore we introduce a suitable constraint on AGREE rules, showing that it ensures a form of locality of transformations. Definition 4 (local embedding and local rules). Let C be a category with partial map classifier (T, η, µ) and with a strict initial object 0, i.e. such that each arrow with target 0 has 0 as source. This implies that for each object K, the only arrow 0K : 0 → K is mono. A mono t : K TK is called a local embedding if there is an arrow f : T (0) → TK such that diagram (7) is a pullback. An AGREE rule is called local if its embedding is local. T (0) id0
T (0)
f
PB
T (0K )
/ TK
(7)
t
/ T (K)
The Set-based rule above is clearly not local, because 0 in Set is the empty set, T (0) = {∗}, and the pullback object of TK = {•} → T (K) = {•, ∗} ← T (0) = {∗} is the empty set. Note that the examples in this paper are based on elementary toposes, which do have strict initial objects. Let us conclude this section by showing in which sense AGREE rewriting via a local rule ρ is indeed “local”. The idea is that if G ⇒ρ,m H, then any sub-object of G that is completely disjoint from the image of the match m is “not affected”. This is formalized as follows. 7
Proposition 1 (locality of AGREE transformation). Let ρ = (l, r, t) be a m rule and L → G be a match, such that G ⇒ρ,m H as in diagram (6). Then for c
each mono C G such that the pullback object of c and m is the initial object, d there is exactly one arrow C → D such that c = g ◦ d. 0 0C
C/
0L
PB
l
K
m
c
/Go
T (0L )
/ T (L) o g
m
0C
T (0) d
/Lo
n
* D
d g
n0
PB
l
TK o
0
[A]
t
T (K) o
T (l)
f
P B (7) T (0K )
T (0) idT (0)
T (0)
idT (0)
Proof (sketch). Since in the above diagram the central square is a pullback by d
construction, to obtain an arrow C → D such that c = g ◦ d it is sufficient to h show that there is an arrow C → TK such that m ◦ c = t0 ◦ h. By applying Lemma 1 to the partial map (0C , 0L ) : C * L, since by hypothesis (0C , 0L ) is def
the pullback of (m, c) we get T (0L ) ◦ 0C = ϕ(0C , 0L ) = m ◦ c. Let h = f ◦ 0C , l0 ◦ h = T (0L ) ◦ 0C can be proved by diagram chasing on the bottom part of the diagram. d0
d
Uniqueness of such a C → D follows from the fact that if C → D and c = g ◦ d0 , then it can be proved that n0 ◦ d0 = f ◦ 0C by diagram chasing and exploiting that (7) is a pullback. A similar result of locality of transformations trivially holds (by definition) for the SqPO approach, and it can be proved by exploiting adhesivity for leftlinear rules in the DPO approach.
4
Example: Copy of Web Pages
The webgraph is the graph generated from the link structure of the web pages. In this graph, each node represents a web page and each arc is a hyperlink from one page to another. Every page has complete control over its out-arcs, since it is the decision of the web page developer when to add/remove such arcs; but the decision about which other pages will have links to this page cannot be controlled. It is well known that the webgraph is sparse, huge and dynamic, i.e., it changes over time. Modeling the webgraph evolution is important to enable the development of better retrieval information and crawling algorithms. In [22] this evolution was described via graph transformation rules, based on 8
a stochastic extension of the SPO approach. However, that model could not faithfully represent one of the basic evolution operators that is used to generate the real webgraph, namely the copy operation. Webgraphs basically evolve by inserting/removing pages and links, but not in a random way. Frequently new pages are created as copies of existing ones (that may be modified later on) [17]. Using the AGREE approach, the copying operation can be modelled using the local rule shown in Figure 2. The rule (K1 → L1, K1 → R1, K1 T K1) is typed over the type graph to the right. Nodes denote web pages, solid edges denote links and dashed edges describe the subpage relation. The different node colours (gray and black) were used just to define the match, whereas the C inside some nodes is used to indicate that this is a copy. When this rule is applied to graph G, only out-links are copied because the pages that link the copied one will remain the same, that is, will only have a link for the original page, not to its copy. Moreover, the subpage structure is not copied. It would be possible also to copy a web page and its subpages. Using the proposed approach, two rules (and auxiliary edges) would be needed to make the copy (one to copy the root and another to recursively copy subpages). Due to space limitations, these rules will not be presented.
Fig. 2. Copy web page
5 5.1
AGREE Subsumes SqPO and Polarized Node Cloning AGREE subsumes SqPO rewriting [5] with injective matches l
As recalled in the Introduction, in the SqPO approach a rule is a span L ← r m K → R and a rewriting step for a match L → G is made of a first phase where the final pullback complement D is constructed, and next a pushout with the right-hand side is performed. Let us introduce some notations in order to recall the definition of the final pullback complement. Definition 5 (final pullback complement functor). For each object X in C, the slice category over X is denoted C ↓ X: its objects are the maps f : Y → 9
X in C and a map g : f1 → f2 in C ↓ X, with f1 : Y1 → X and f2 : Y2 → X in C, is a map g : Y1 → Y2 in C such that f2 ◦ g = f1 . For each endofunctor F : C → C and each object X in C, let us still denote by F the functor F : C ↓ X → C ↓ F (X) which maps each object f of C ↓ X to F (f ) and each map g : f1 → f2 of C ↓ X to F (g). If C has pullbacks then for each f : X → Y in C, the pullback functor associated with f is denoted P Bf : C ↓ Y → C ↓ X. Also, for each f : X → Y in C, the final pullback complement functor associated with f , if it exists, is the right adjoint to P Bf [10,5]. With these notations, when C has pullbacks and a partial map classifier (T, η, µ), for each mono m : L G let us consider the functor P Bm : C ↓ G → C ↓ L and the functor F P BCm = P Bm ◦ T : C ↓ L → C ↓ G. We will prove in Lemma 2 that this notation is sound: the functor F P BCm is indeed the final pullback complement functor associated with m. Lemma 2. Let C be a category with pullbacks and with a partial map classifier (T, η, µ). For each mono m : L G, the functor F P BCm = P Bm ◦T : C ↓ L → C ↓ G is the final pullback complement functor associated with m. In addition, this functor is full and faithful. Proof. We have to prove that the functor F P BCm is right adjoint to the functor P Bm ; let us sketch this proof by describing the unit u and counit c of the adjunction P Bm a F P BCm . For the counit, since m ◦ m = ηL we have P Bm ◦ P Bm = P BηL , and since the natural transformation η is cartesian we have P BηL ◦ T ∼ = Id C↓L . Then the counit c : P Bm ◦ F P BCm ⇒ Id C↓L is the resulting natural isomorphism. For the unit, let g : D → G be an object in C ↓ G and let l = P Bm (g) : K → L in C ↓ L. Let n : K D be the fourth map in this pullback, then by Lemma 1 we have T (l) ◦ n = m ◦ g. Let g 0 = P Bm ◦ T (l) : D0 → G and let q : D0 → T (K) be the fourth map in this pullback. By definition of pullback, there is a unique map ug : D → D0 such that g 0 ◦ ug = g and q ◦ ug = n. It follows that ug : g → g 0 is a map in C ↓ G. Moreover, let n0 = ug ◦ n : K → D0 , then q ◦ n0 = q ◦ ug ◦ n = n ◦ n = ηK . Since η is cartesian, the decomposition property of pullbacks implies that (n0 , l) is the pullback of (m, g 0 ), so that n0 is mono and q = n0 . Then it can be checked that the ug s define a natural transformation u : Id C↓G ⇒ F P BCm ◦ P Bm , which is the unit of the adjunction. In addition, since the counit is an isomorphism, the left adjoint functor F P BCm is full and faithful. L o m
Go
m
T (L) o
l
PB g
=
T (l)
L o
K n
m
D
Go
n
m
T (K)
T (L) o
10
l
PB g0
PB
T (l)
K n0
D0
q=n0
T (K)
We are now ready to state and prove the main result. Theorem 1. Let C be a category with pullbacks and pushouts and with a partial l r map classifier (T, η, µ). Let ρ = L ← K → R be a rule and m : L G be a monic match. Then O G ⇒SqP H ρ,m
if and only if
G ⇒AGREE (l,k,ηK ),m H
In words, the application of rule ρ to match m using the SqPO approach has exactly the same effect of applying to m the same rule enriched with the embedding ηK K → T (K) using the AGREE approach. Proof. Since the pushout phase is the same in AGREE as in SqPO, we only have to prove that if the embedding is ηK , then the pullback complement in the AGREE rewriting step is the final pullback complement. In fact by Lemma 2 we know that in C for each mono m : L G, the functor F P BCm = P Bm ◦ T : C ↓ L → C ↓ G is the final pullback complement functor associated with m. Since, referring to diagram (6), TK = T (K) and t = ηK , by pullback (2) we have l0 = ϕ(t, l) = ϕ(ηK , l) = T (l). By the definition of the first phase T (l)
g
of AGREE rewriting we have G ← D = P Bm (T (L) ← T (K)), and thus g
l
l
G ← D = P Bm ◦ T (L ← K) = F P BCm (L ← K), which concludes the proof. 5.2
AGREE subsumes polarized node cloning on graphs
We now show that AGREE rewriting allows to simulate rewriting with polarized cloning on graphs [8]. Polarization is used to control the copies of the edges (outside the match) connected to a copied node: a node n can be copied either with all its edges, or only with its outgoing edges, or only its with its incoming edges, or without any of its edges. Thus, polarization is a way to tune SqPO rewriting: indeed, SqPO rewriting is the special case of rewriting with polarized cloning where every node is copied with all its edges. Rewriting with polarized cloning is defined in [8] by introducing the notion of polarized graph. A polarized graph is a graph where each node may be annotated with + or − (non exclusively). In a polarized graph, only nodes annotated with + (resp. −) may have outgoing (resp. incoming) edges. We recall the definitions of polarized graphs and of rewriting with polarized cloning in Definitions 6 and 7; more details on this subject can be found in [8]. Then, using the fact that the category of polarized graphs has a relative partial map classifier, we prove in Theorem 2 that each rewriting step with polarized cloning can be simulated by an AGREE rewriting step in the category of graphs. + − Definition 6. A polarized graph X = (X, NX , NX ) is a graph X with a pair e + − (N , N ) of subsets of the set of nodes NX . such that for each edge n → p one + − has n ∈ NX and p ∈ NX . A morphism of polarized graphs f : X → Y, where + − X = (X, NX , NX ) and Y = (Y, NY+ , NY− ), is a morphism of graphs f : X → Y + − such that f (NX ) ⊆ NY+ and f (NX ) ⊆ NY− . This provides the category Gr± of
11
+ − polarized graphs. The underlying graph of a polarized graph X = (X, NX , NX ) is X. The polarized graph X induced by a graph X is X = (X, NX , NX ). This defines two functors Depol : Gr± → Gr and Pol : Gr → Gr± which form an adjunction Depol a Pol such that Depol ◦ Pol = Id Gr ; the unit of this adjunction is denoted u : Id Gr± ⇒ Pol ◦ Depol. A morphism of polarized graphs f : X → Y + is strict, or strictly preserves the polarization, if f (NX ) = f (NX ) ∩ NY+ and − − f (NX ) = f (NX ) ∩ NY .
We will use the fact that, if m : L → G is a mono in Gr, then Pol(m) : Pol(L) → Pol(G) is a strict mono in Gr± . The category Gr± has final pullback complements along strict monos, their construction is given in [7, Appendix]. Roughly speaking, a PSqPO rewrite step is made of a final pullback complement in Gr± followed by a pushout in Gr, thus generalizing a SqPO rewrite step for which both phases are done in the same category. Definition 7 (PSqPO rewriting). A PSqPO rewrite rule ρ is made of a span l
r
+ − of graphs L ← K → R and a polarized graph K = (K, NK , NK ) with underlying graph K. A PSqPO match of the PSqPO rewrite rule ρ is a mono m : L G SqP O H is constructed as follows: in Gr. The PSqPO rewriting step G ⇒P ρ,m
(a) The left-hand-side l of the rule ρ gives rise to a morphism b l = Pol(l) ◦ uK : K → Pol(L) in Gr± . The match m gives rise to a strict mono Pol(m) : g n Pol(L) Pol(G) in Gr± . In the category Gr± let K → D → Pol(G) be the Pol(m)
b l
final pullback complement of K → Pol(L) → Pol(G). (b) Since Depol(K) = K, we get Depol(n) : K → Depol(D) in Gr. In the p
h
r
category Gr let R → H ← D be the pushout of R ← K
L m
G
Pol(L) o Pol(m)
b l
F P BC
Pol(G) o
g
K n
D
K Depol(n)
Depol(D)
Depol(n)
→
r
PO
h
Depol(D).
/R p
/H
Following [3], we define a stable system of monos in a category as a class of monomorphisms containing the isomorphisms, closed under composition and stable under pullbacks. In [4], partial map classifiers are defined with respect to any stable system of monos. Until now we have only used the stable system made of all monos in C, but now we use another system. Section 3 can be generalized as follows. Let C be a category and let M be a stable system of monos in C. Let us assume that C has pullbacks along monos in M and has a partial map classifier (T, η, µ) with respect to M . Then Definition 2 is modified by assuming that the embedding t : K TK for each rule is in M and that each match m : L G is in M . The AGREE rewriting steps are defined as in Definition 3. The stability of M ensures that the mono n : K D is in M . It is easy to 12
check that the strict monos in Gr± form a stable system of monos M and that the category Gr± has a partial map classifier with respect to M : it maps each K to T(K) which is the disjoint union of K with a vertex ∗ and with an edge + − ∗n,p : n → p for each pair of nodes (n, p) ∈ (NK +{∗})×(NK +{∗}). In addition, ± the functor Depol : Gr → Gr has a left adjoint, which maps each graph X + − + − to the polarized graph (X, NX , NX ) where a node is in NX (resp. in NX ) if and only if it has at least one outgoing (resp. incoming) edge in X. So, Depol preserves pullbacks. l
r
+ − Theorem 2. For each PSqPO rule ρ made of L ← K → R and K = (K, NK , NK ), ± let TK = Depol(T(K)) and t = Depol(ηK ). Then we get an AGREE rule ρ in l
r
Gr by adding to the span L ← K → R the embedding t : K TK . For each mono m : L G in Gr, applying the PSqPO rule ρ to m provides the same graph H as applying the AGREE rule ρ± to m in Gr. Proof. Let us apply Theorem 2 (generalized to any stable system of monos) to the category Gr± and to the strict monos. It means that in Definition 7 the final pullback complement (n, g) of (Pol(m), b l) can be obtained from the pullback l)) by defining n as the unique map such that g◦n = Pol(m)◦b l (q, g) of (Pol(m), T(b and q ◦ n = ηK : see diagram below on the left. The functor Depol is applied to this construction; since it preserves pullbacks, we get a similar construction in Gr: see diagram below on the right, where D = Depol(D). Theorem 2 proves that we get the final pullback complement of (m, l) in Gr. Since in the PSqPO approach the pushout phase is done in Gr, both ρ and ρ± produce the same result H.
Pol(L) o Pol(m)
ηPol(L)
o Pol(G) =
Pol(m)
T(Pol(L)) o
b l = g PB T(b l)
L o
K n
D
= ηK
q=n
T(K)
ηL
=
l
K
m
=
D
m
PB
Go
T (L) o
= t
TK
Example 2. As a basic example, let us clone one node x in two nodes x+ and x− such that all edges from x are glued to x+ while all edges to x are glued to x− . Then the graph L is made of one node x and the graph K of two nodes x+ + and x− . For PSqPO rewriting we consider that K is polarized by NK = {x+ } − and NK = {x− }. Equivalently, for AGREE rewriting we consider that K is embedded into TK as in the following diagram.
13
6
Conclusions and Discussion
In this paper we presented the basic definitions of a new approach to algebraic graph rewriting, called AGREE. We showed that this approach subsumes other algebraic approaches like SqPO (Sesqui-pushout) with injective matches (and therefore DPO and SPO under mild restrictions, see [5]), as well as its polarised version PSqPO. The main feature provided by this approach is the possibility, in a rule, of specifying which edges shall be copied as a side effect of the copy of a node. This is important to specify applications in which copy of nodes shall be done in an unknown context, and thus it is not possible to describe in the left-hand side of the rule all edges that shall be copied together with the node. As an example, the copy of web pages was described in Sect. 4. The idea of controlling explicitly in the rule how the right-hand side should be embedded in the context graph is not new in graph rewriting, as it is a standard ingredient of the algorithmic approaches. For example, in Node Label Controlled (NLC) graph rewriting and its variations [16] productions are equipped with embedding rules, which allow one to specify how the right-hand side of a production has to be embedded in the context graph obtained by deleting the corresponding left-hand side. The name of our approach is reminiscent of those older ones. Among the approaches based on categorical constructions, besides those already discussed the most related one is Bauderon’s pullback approach [2]. It was proposed as an algebraic variant of the just mentioned NLC and ed-NLC algorithmic approaches. Bauderon’s approach is similar, in part, to the pullback construction used in our first phase of a rewriting step, but a closer analysis is needed and is planned as future work. We also intend to explore if there are relevant applications where AGREE rewriting in its full generality (i.e., with possibly non-local rules) could be useful. Concerning the applicability of our approach to categories of structures, in practice the requirement of existence of partial maps classifiers looks quite demanding. From the discussion in Example 1 it follows that AGREE rewriting can be applied to categories of typed or coloured graphs, which are used in several applications. But even more used are the categories of attributed graphs or structures [9], which do not form toposes. Under which conditions our approach can be extended to (or how it can be tailored to) such structures is an interesting topic that we intend to investigate.
References 1. Barendregt, H.P., van Eekelen, M.C.J.D., Glauert, J.R.W., Kennaway, R., Plasmeijer, M.J., Sleep, M.R.: Term graph rewriting. In: de Bakker, J.W., Nijman, A.J., Treleaven, P.C. (eds.) PARLE, Parallel Architectures and Languages Europe, Volume II: Parallel Languages. LNCS, vol. 259, pp. 141–158. Springer (1987) 2. Bauderon, M., Jacquet, H.: Pullback as a generic graph rewriting mechanism. Applied Categorical Structures 9(1), 65–82 (2001) 3. Cockett, J., Lack, S.: Restriction categories I: categories of partial maps. Theoretical Computer Science 270(1–2), 223–259 (2002)
14
4. Cockett, J., Lack, S.: Restriction categories II: partial map classification. Theoretical Computer Science 294(1–2), 61–102 (2003) 5. Corradini, A., Heindel, T., Hermann, F., K¨ onig, B.: Sesqui-pushout rewriting. In: Corradini, A., Ehrig, H., Montanari, U., Ribeiro, L., Rozenberg, G. (eds.) Graph Transformations, Third International Conference, ICGT 2006. LNCS, vol. 4178, pp. 30–45. Springer (2006) 6. Corradini, A., Montanari, U., Rossi, F., Ehrig, H., Heckel, R., L¨ owe, M.: Algebraic approaches to graph transformation - part I: basic concepts and double pushout approach. In: Rozenberg [21], pp. 163–246 7. Duval, D., Echahed, R., Prost, F.: Graph rewriting with polarized cloning. CoRR abs/0911.3786 (2009), http://arxiv.org/abs/0911.3786 8. Duval, D., Echahed, R., Prost, F.: Graph transformation with focus on incident edges. In: Ehrig, H., Engels, G., Kreowski, H., Rozenberg, G. (eds.) Graph Transformations - 6th International Conference, ICGT 2012. LNCS, vol. 7562, pp. 156–171. Springer (2012) 9. Duval, D., Echahed, R., Prost, F., Ribeiro, L.: Transformation of attributed structures with cloning. In: Gnesi, S., Rensink, A. (eds.) Fundamental Approaches to Software Engineering - 17th International Conference, FASE 2014. LNCS, vol. 8411, pp. 310–324. Springer (2014) 10. Dyckhoff, R., Tholen, W.: Exponentiable morphisms, partial products and pullback complements. Journal of Pure and Applied Algebra 49(1-2), 103–116 (1987) 11. Echahed, R.: Inductively sequential term-graph rewrite systems. In: Ehrig, H., Heckel, R., Rozenberg, G., Taentzer, G. (eds.) Graph Transformations, 4th International Conference, ICGT 2008. LNCS, vol. 5214, pp. 84–98. Springer (2008) 12. Ehrig, H., Engels, G., Kreowski, H.J., Rozenberg, G. (eds.): Handbook of Graph Grammars and Computing by Graph Transformations, Volume 2: Applications, Languages and Tools. World Scientific (1999) 13. Ehrig, H., Kreowski, H.J., Montanari, U., Rozenberg, G. (eds.): Handbook of Graph Grammars and Computing by Graph Transformations, Volume 3: Concurrency, Parallelism and Distribution. World Scientific (1999) 14. Ehrig, H., Heckel, R., Korff, M., L¨ owe, M., Ribeiro, L., Wagner, A., Corradini, A.: Algebraic approaches to graph transformation - part II: single pushout approach and comparison with double pushout approach. In: Rozenberg [21], pp. 247–312 15. Ehrig, H., Pfender, M., Schneider, H.J.: Graph-grammars: An algebraic approach. In: 14th Annual Symposium on Switching and Automata Theory, Iowa City, Iowa, USA, October 15-17, 1973. pp. 167–180. IEEE Computer Society (1973) 16. Engelfriet, J., Rozenberg, G.: Node replacement graph grammars. In: Rozenberg [21], pp. 1–94 17. Kumar, R., Raghavan, P., Rajagopalan, S., Tomkins, A.: Trawling the web for emerging cyber-communities. Computer Networks 31(11-16), 1481–1493 (1999) 18. L¨ owe, M.: Algebraic approach to single-pushout graph transformation. Theor. Comput. Sci. 109(1&2), 181–224 (1993) 19. Mitchell, M., Oldham, J., Samuel, A.: Advanced Linux Programming. Landmark Series, New Riders (2001) 20. Raoult, J.: On graph rewritings. Theor. Comput. Sci. 32, 1–24 (1984) 21. Rozenberg, G. (ed.): Handbook of Graph Grammars and Computing by Graph Transformations, Volume 1: Foundations. World Scientific (1997) 22. da Silva, R., Buriol, L.S., Ribeiro, L., Dotti, F.L.: Modeling the webgraph evolution. J. Comput. Science 2(1), 67–79 (2011)
15