Matrix Graph Grammars: Transformation of Restrictions
In the Matrix approach to graph transformation we represent simple digraphs and rules with Boolean matrices and vectors, and the rewriting is expressed using Boolean operations only. In previous works, we developed analysis techniques enabling the st…
Authors: Pedro Pablo Perez Velasco
1 Matrix Graph Grammars: T ransf ormation of Restrictions Pedr o Pa blo P ´ er ez V elasco School of Computer Science Universidad A ut ´ onoma de Madrid Ciudad Universitaria de Cantoblanco, 28049 - Madrid, Spain pedr o.per ez@uam.es Abstract. In the Matrix appr oach to graph transform ation we represent simple digraphs and rule s with Boo lean ma trices and vectors, and the rewriting is expressed using Boo lean ope rations only . In pre vious works, we developed analysis techniques enablin g the study of the ap plicability of rule sequences, their in depend ence, stated reachability a nd the m inimal d igraph able to fire a sequ ence. See [19] for a co mprehen si ve intro duction. In [2 2], grap h constraints and ap plication condition s (so-called r estrictions ) hav e been studied in detail. In the present con tribution we tack le the prob- lem o f tran slating post-co nditions into pr e-conditio ns and vice versa. Moreover , we shall see that application cond itions can be moved along produ ctions in side a sequenc e ( r estr iction d elocaliza- tion ). As a practical-theo retical application we sho w how application conditions allo w us to perform multidigrap h re writing (as opp osed to simple digraph re writing) using Matrix Graph Grammars. Ke ywords: Matrix Graph Grammars, Graph Dynamics, Graph T ransfo rmation, Restrictio ns, Appli- cation Conditio ns, Precondi tions, Postconditio ns, Graph Constraints . 1. Introd uction Graph transfo rmation [7, 24] is becoming increasin gly popular in order to describ e system beha vior due to its graphica l, decl arati ve and formal nature. For e xample, it has been used to describe the operation al semantic s of Domain Specific V isual Language s (DSVLs, [14]), taking the advan tage tha t it is possible to use the concr ete syntax of the DSVL in the rules which then become more intuiti v e to the designer . 2 P . P . P ´ er ez / Matrix Graph Gra mmars The main for malization of gr aph tran sformatio n is the so-called algeb raic ap proach [7], which uses cate gory the ory in order to expr ess the re writing step. Prominent examples of this ap proach are the doubl e [3, 7] and single [5 ] pusho ut (DPO and S PO) which hav e dev elop ed interesting analysis tech- niques , for example to check seque ntial and parallel independen ce between pairs of rul es [7, 24] or the calcul ation of critical pairs [10, 13]. Frequent ly , graph transformatio n rule s are equipped with applicatio n conditions (A Cs) [6, 7, 11], stating ext ra (in ad dition to the left h and side) p ositi v e and n egati v e cond itions that th e host graph should satisfy for the rule to be a pplicabl e. T he a lgebraic approach has propos ed a kind of A Cs with pre defined diagra ms (i.e. graphs and morphi sms making the condition ) and quantifiers regarding the existence or not of matchings of the diffe rent gra phs of the constraint in the host graph [6, 7]. Most analysis techniques for plain rules (withou t A Cs) ha v e to be adapte d then for rule s with A Cs (see e.g. [13] for critical pairs with negati v e ACs). M oreo ver , dif fere nt adaptations may be needed for dif ferent kinds of A Cs. Thus, a unifor m approach to analyze rules with arbitrar y A Cs would be v ery useful. In pre viou s works [15, 16, 17, 19 ] we de ve loped a frame wor k (Matrix Graph Grammars, MGGs) for the trans formation of simple digra phs. Simple digra phs and their transformatio n rules ca n be represented using Boolea n matrices and ve ctors. Thus, the re writin g can be e xpresse d usi ng Boolean operato rs only . O ne important point is that, as a differ ence from other approach es, we e xplicit ly represent the rule dynamic s (a ddition and deletion of elemen ts) instea d o f only the stati c parts (rule pre and postcond itions). This po int of vi ew enables ne w an alysis techn iques, such as for exampl e chec king independe nce of a sequence of arbitrar y length and a permutation of it, or to obtain th e smalles t grap h able to fire a sequen ce. On the th eoretica l side, our formaliz ation of grap h transfor mation introdu ces concepts from many branc hes of mathematics like Boolean algebra, group theory , functional analysis, tensor algebr a and logics [19, 20, 21]. This wealth of a va ilable mathematical results opens the door to new analysis methods not dev elope d so far , like seque ntial i ndepend ence and exp licit para llelism n ot limited to p airs of sequen ces, applic ability , graph congruence and reachabilit y . On the practical side, the implementatio ns of our analysi s techni ques, being based on Boole an algebra manipulatio ns, are expected to ha v e a good perfor mance. In MGG s w e do not only consider the elements that must be prese nt in order to app ly a productio n (left hand side, L HS, also kno wn as certainty part ) but also those element s that potential ly prev ent its applic ation (also kno wn as nihil or nihilatio n p art ). Refer to [22] in which, bes ides this, appl ication condit ions and graph con straints are studied for the MGG approach . T he present contrib ution is a con - tinuat ion of [22] where a comp arison with related w ork can al so be fo und. W e shall ta ckle pre an d postco ndition s, their trans formation , the seque ntial version of these results and multidigra ph rewritin g. Paper organizat ion . Section 2 giv es an overvi ew of Matrix G raph Grammars. Sec tion 3 revis es ap- plicati on conditions as studied in [22]. P ostcon ditions and their equiv alence to certain sequen ces ar e addres sed in S ec. 4. Section 5 tackles the transformatio n of precon ditions into postcon ditions . The con- P . P . P ´ er ez / Matrix Graph Gr ammars 3 ver se, more natural from a practical po int of view , is also addressed. The trans formation of restric tions is genera lized in Sec. 6 in whi ch deloca lizatio n – ho w to mo ve appli cation conditions from one pr oductio n to another inside the same sequence – is also studied togethe r with variable nodes . A s an applicatio n of restric tions to MGGs, Sec. 7 sho ws ho w to make MGG deal with multid igraphs instead of just simple digrap hs without major modification s to the theory . T he paper ends in Sec. 8 with some conclusion s, furthe r research remarks and ackno wledg ements. 2. Matrix Graph Grammars Over view W e work w ith simple digraphs which we represent as G p M , V q , where M is a B oolean m atrix for edges (the graph adjacency matrix) and V a B oolean vect or for vertices or nodes. 1 The left of Fig. 1 sho ws a graph r epresent ing a p roductio n system made up of a machine ( controll ed by an operator) which consu mes and produces pieces through con veyo rs. Self loops in operators and machines indicate that the y are bu sy . Figure 1. Simple Digraph Example (left). Matr ix Representation (right) W ell-formedness of graphs (i.e. absence of dangl ing edges) can be check ed by verif ying the identity M _ M t d V 1 0 , where d is the Boolean matrix pro duct, 2 M t is the transp ose of the matrix M , V is the negation of the nodes vecto r V , and } } 1 is an operatio n (a norm, actua lly) that resu lts in the or of all the components of the vector . W e call this property compatibility (refer to [15 ]). Note that M d V results in a v ector that con tains a 1 in positio n i when there is an o utgoin g edge from node i to a non-e xistin g node. A similar express ion with the transpo se of M is used to check for incoming edges. A type is assigned to each node in G p M , V q by a function from the set of nodes | V | to a set of types T , λ : | V | Ñ T . S ets will be represented by | | . In F ig. 1 types are represented as an extr a column in the matrices, where the numbers before the colon distinguis h element s of the same type. It is just a visu al aid. For edges we use the types of the ir source and tar get nodes. A typed simple digraph is G T p G, λ q . From now on we sh all assume typed graphs and shall drop the T subind ex. 1 The v ector for nodes is necessa ry because in MGG nodes can be adde d and deleted, and thus we mark th e existing nodes with a 1 in the corresponding position of the vector . 2 The Boolean matrix product is like the re gular matrix product, but with and and or instead of multiplication and addition. 4 P . P . P ´ er ez / Matrix Graph Gra mmars A pr oduction or gra mmar rule p : L Ñ R is a morp hism of typed simpl e digraph s, which is define d as a mapping that transfo rms L in R with the restrictio n that the type of the image must be equ al to the type of the so urce element. 3 More ex plicitly , f p f V , f E q : G 1 Ñ G 2 being f V and f E partial inje cti ve mapping s f V : | V 1 | Ñ | V 2 | , f E : | M 1 | Ñ | M 2 | such that v P D om p f V q , λ 1 p v q λ 2 p f V p v qq and e p n, m q P D om p f E q , f E p e q f E p n, m q p f V p n q , f V p m qq , where D om stan ds for do main, E for edges and V for ver tices. A produ ction p : L Ñ R is statica lly r epr esented as p p L, R q L E , L V , λ L , R E , R V , λ R . The matrices and ve ctors of these graphs are arranged so that the elements identified by morphism p match (this is call ed completion, see belo w). Alternati v ely , a productio n adds and deletes nodes and edges, therefore they can be dynamically r epre sented by encoding the rule’ s LH S together with matrices and vectors represe nting the addition and deletion of edge s and nodes: 4 p p L, e, r q L E , L V , λ L , e E , r E , e V , r V , λ r , where λ r contai ns the types of the ne w nodes, e E and e V are the deletio n Boolean matrix and v ector , r E and r V are the addition B oolean matrix and vector . They hav e a 1 in the position where the element is to be deleted or added, resp ecti vel y . The output of rule p is calcul ated by the Boolean formula R p p L q r _ e L , which applies both to nodes and edges. 5 Figure 2. (a) Rule Examp le. (b ) Static F ormulatio n. (c) Dyn amic F ormulatio n Example . Figure 2 shows a rul e an d i ts associated matrices . The ru le models the con sumption o f a piece (Pack) by a machine (Mach) inpu t via the con v eyo r (Con v). There is an operator (Oper) mana ging the machine. Compati bility of the resulting graph must be ensured, thus the rule cannot be applied if the machine is already b usy , as it w ould end u p with two self loops wh ich is not allo wed in a simple digrap h. This res triction of simple di graphs can be u seful in this kind o f situa tions and act s lik e a b uilt-in ne gati v e applic ation conditio n. Later we will see that the nihilati on m atrix tak es care of this restrictio n. In order to operate with the matrix representati on of graphs of diff erent sizes, an operatio n called 3 W e shall come back to this topic in Sec. 6. 4 W e call such matrices and vectors e for “erase” and r for “restock”. 5 The and symbol ^ is usually omitted in formulae, so R p p L q r _ e ^ L with precedence of ^ ov er _ . P . P . P ´ er ez / Matrix Graph Gr ammars 5 completion adds ex tra rows and columns with zeros to matrices and vecto rs, and rearrange s rows and columns so that the identi fied edges and nodes of the two graphs match. For examp le, in F ig. 2 , if we need to operate L E and R E , completion adds a fourth 0 -ro w and fourth 0 -column to R E . No further modificatio n is neede d because the rest of the elements ha ve the right types and are placed properl y . 6 W ith the purpo se of consideri ng the elements in the host graph that disable a rule applic ation, we ext end the notation for rules w ith a ne w simple digraph K , w hich specifies the tw o kinds of forbidden edges: T hose incident to nodes which are going to be erased and any edge added by the rule (which canno t be added twic e, si nce we are deal ing with simple digraphs). K has non-zero el ements in positions corres ponding to ne wly added edges, and to non -delete d edges inci dent to delet ed nodes. Matrices are deri v ed in the follo wing ord er: p L, R q ÞÑ p e, r q ÞÑ K . Thus, a rule is statically det ermined by its LHS and RHS p p L, R q , from which it is possibl e to gi v e a dynamic definition p p L, e, r q , with e LR and r RL , to end up w ith a full specification including its en vir onment al beha vio r p p L, K, e, r q . No ext ra effo rt is needed from the grammar design er becaus e K can be automatica lly calcul ated: K p p D q , with D e V b e V t . 7 The e v olution of the nihilatio n matrix (what elements can not appe ar in the RHS) – call it Q – is giv en by the in v erse of the product ion: p R, Q q p p L q , p 1 p K q p r _ eL, e _ rK q . See [22] for more detai ls. Inspir ed b y the Dirac or bra-ket notation [2] we split the static part (initial state, L ) from the dyna mics (element addition and deletion, p ): R p p L q x L, p y . The ket operators (those to the right side of the bra-k et) can be moved to the b ra (left hand side) by using their adjoin ts. Matching is the op eration of ident ifying the LHS o f a rule in side a hos t graph. Gi ven a rule p : L Ñ R and a simple d igraph G , an y t otal injec ti ve 8 morphism m : L Ñ G is a matc h for p in G , thus it is o ne of the ways of co mpleting L in G . Besides, we shall consider the elements that must not be present. Giv en the gra mmar rule p : L Ñ R and the graph G p G E , G V q , d p p, m q is called a direct deriv ation with m p m L , m K q and result H p p G q if the follo wing conditi ons are satisfied: 1. There e xist tot al injecti v e morphisms m L : L Ñ G and m K : K Ñ G with m L p n q m K p n q , n P L V . 2. The match m L induce s a completion of L in G . Matric es e and r are then complete d in the same way to yield e and r . The outpu t graph is calcula ted as H p p G q r _ e G . The negati on when applied to graphs alone (not specifyin g the nodes) – e.g. G in the first condition abo ve – will be carried out just on edges. Notice that in particular the first condition abov e gu arantees that L and K will be applied to the same nodes in the host graph G . 6 In t he present contrib ution we shall assume that completion is being performed someho w . This is closely related to non- determinism. The reader is referred to [21] for further details. 7 Symbol b denotes the tensor or Kronecker product, which sums up the cov ariant and contrav arian t parts and multiplies ev ery element of the first vector by the wh ole second vector . 8 MGG considers only injecti ve matches. 6 P . P . P ´ er ez / Matrix Graph Gra mmars In direct deri va tions dangling edg es can occur because the nihilation matrix only consid ers edges incide nt to nodes appearing in the rule’ s LHS and not in the whole host graph. In MGG an operat or T ε tak es care of dangling edges w hich are deleted by adding a preprodu ction (kno wn as ε produ ction) before the original rule. Refer to [15 , 16]. Thus, rule p is transformed into the sequence p ; p ε , where p ε delete s the danglin g edges and p remains unaltered. There are oc casions in which tw o or more p roducti ons should be matched to th e same nodes . This is achie v ed with the marking operato r T µ introd uced i n Chap. 6 in [19]. A g rammar rule and its associated ε -prod uction is one example and we shall find more in fut ure sections. In [15, 16, 17, 19] some analysis techniques for MGGs ha ve been de velo ped w hich we shall skim throug h. One important feature of MGG is that sequences of rules can be analyz ed independen tly to some extent of any host graph. A rule sequence is represented by s n p n ; . . . ; p 1 where applic ation is from righ t to left, i.e. p 1 is applied first. For its analysis, the sequen ce is completed by identify ing the nodes across rules which are assumed to be mapped to the same node in the host graph. Once th e sequ ence is complet ed, sequence coher ence [1 5, 19, 2 0] allo ws u s to k no w if, fo r the gi ve n identi fication, the sequence is potential ly applicable, i.e. if no rule disturbs the applica tion of tho se follo wing it. The formula for coherence results in a matrix and a vect or (which can be interpre ted as a graph) with the proble matic elements. If the sequen ce is coherent, both should be zero; if not, they contai n th e problematic elements. A coheren t se quence is compatible if its applica tion p roduce s a simple digrap h. That is, no danglin g edges are produced in intermediate steps. Giv en a completed sequence, the m inimal initial digra ph (MID) is the smallest gra ph that per mits the applic ation of such sequence. Con versel y , the negativ e in itial digraph (NID) contains all elements that should not be present in the hos t gra ph for the sequence to be applicable. In this way , the NID is a graph that should be found in G for the sequence to be applica ble (i.e. none of its edges can be found in G ). See Sec. 6 in [20] or Chaps. 5 and 6 in [19]. Other concep ts w e dev eloped aim at checking sequential independen ce (same result) between a sequen ce and a permutation of it. G-Congruence detects if two sequences, one p ermutatio n of the o ther , ha ve th e same MID and NID. It returns t wo matri ces and two vec tors, repre senting two graphs wh ich are the diff erences between the MIDs and NIDs of each sequen ce, respecti vel y . Thus if zero, the sequences ha ve the same MID and NID. T wo coherent and compatible comple ted seq uences tha t are G-congru ent are sequen tially indepen dent. See Sec. 7 in [20] or Chap. 7 in [19]. 3. Pr evious W ork on A pplication Conditions in MGG In this section we shall brush up on applica tion conditi ons (A Cs) as introduc ed for MG G in [22] with non-fix ed diagrams and quan tifiers. F or the quanti fication, a full-fledge d monadic second order logic 9 9 MSOL, see e.g. [4]. P . P . P ´ er ez / Matrix Graph Gr ammars 7 formula is used. O ne of the contrib ution s in [22] is tha t a rule with an A C can be transformed in to (seque nces of) plain rules by adding the positi ve information to the left hand side of the productio n and the ne gati v e to the nihila tion matrix. A diagram d is a set of simpl e digraphs t A i u i P I and a set of parti al injecti ve morphisms t d k u k P K with d k : A i Ñ A j . The diagram d is w ell defined if ev ery cycle of morp hisms commute. GC d pt A i u i P I , t d j u j P J q , f is a graph constraint where d is a well defined diagram and f a senten ce with v ariable s in t A i u i P I and predica tes P and Q . See eqs. (1) and (2). Formulae are restric ted to hav e no free varia bles exc ept for the defau lt second ar gument of predicates P and Q , which is the host graph G in which w e ev aluat e the GC. GC formulae are made up of expre ssions abou t graph inclusion s. The predic ates P and Q are giv en by: P p X 1 , X 2 q m r F p m, X 1 q ñ F p m, X 2 qs (1) Q p X 1 , X 2 q D e r F p e, X 1 q ^ F p e, X 2 qs , (2) where pred icate F p m, X q states that element m (a n ode o r an edge) is in graph X . P redica te P p X 1 , X 2 q means that gra ph X 1 is includ ed in X 2 . Predicate Q p X 1 , X 2 q asserts that there is a part ial morphism between X 1 and X 2 , which is defined on at least one edge ( e rang es o ver all edges). The notation (synta x) will be si mplified by m aking the host gr aph G the def ault secon d ar gument for pred icates P and Q . Besides , it will be assu med that by defa ult total morphisms are demanded: Unless oth erwise stated predic ate P is assumed. W e tak e the con v ention that ne gation s in abbre viati ons apply to the predi cate (e.g. D A r A s D A r P p A, G qs ) and not the neg ation of the graph’ s adjacenc y matrix. Figure 3. Diagra m Example Example . The GC in F ig. 3 is satis fied if for e ve ry A 0 in G it is possible to fi nd a related A 1 in G , i.e. its associ ated formula is A 0 D A 1 A 0 ñ A 1 , equi v alent by definition to A 0 D A 1 P A 0 , G ñ P A 1 , G . Nodes and edges in A 0 and A 1 are related through morphism d 01 in which the image of the machine in A 0 is the machine in A 1 . T o enhan ce readabilit y , each graph in the diagram has been marked with the quanti fier giv en in the formula. The GC in F ig. 3 expr esses that each machine should ha ve an output con vey or . Giv en the rule p : L Ñ R with nihilation matrix K , an application condition A C (ov er the free v ariable G ) is a GC satisfy ing: 1. D ! i, j such that A i L and A j K . 8 P . P . P ´ er ez / Matrix Graph Gra mmars 2. D ! k such that A k G is the only free v ariable. 3. f must demand the exist ence of L in G and the existenc e of K in G . For simplicity , we usually do not explici tly sho w the condition 3 in the formulae of A Cs, nor the nihila tion matrix K in the diagram which are e xistent ially quan tified befo re any other graph of the AC. Notice that t he rul e’ s LHS and its nihil ation matrix can be interpre ted as the minimal A C a rule can ha ve . For techni cal reas ons addressed in Sec. 5 (related to con verting pre into postconditio ns) we assume that morphisms d i in the diagram do not ha ve codomai n L or K . This is easily solved as we may alwa ys use their in verses due to d i ’ s injecti ve ness. It is possibl e to embed arbitrary A Cs into rules by includin g the positi v e and neg ati ve conditions in L and K , respecti v ely . Intuiti v ely: “MGG + A C = MGG” and “MGG + G C = MGG”. In [22] two basic operati ons are introduce d: closur e – q T – that transforms uni versa l into existent ial quan tifiers, and decompositio n – p T – that transfo rms partial morphisms into tot al morphisms . Notice tha t a match is an existen tially quantified total morphism. It is prov ed in [22] that any A C can be embedded into its correspond ing di rect deri v ation . This is achie ved by transfo rming the A C into some sequenc es of produ ctions. There are four basic type s of A C s/GCs. Let GC p d , f q be a graph constrai nt w ith diagra m d t A u and cons ider the asso ciated productio n p : L Ñ R . The case f D A r A s is just the matching of A in the host graph G . It is equi v alen t to the sequen ce p ; id A , where id A has A as LHS and RHS, so it simply demands its e xiste nce in G . W e in troduce t he operator T A that replaces p by p ; id A and lea ve s the diagram and the formula unalte red. If the formula f A r A s is considered , we can reduce it to a sequenc e of matchings via the closure operato r q T A whose result is: d ÞÝ Ñ d 1 t A 1 , . . . , A n u , d ij : A i Ñ A j f ÞÝ Ñ f 1 D A 1 . . . D A n n © i 1 A i , (3) with A i A , d ij R iso p A i , A j q , 10 q T A p AC q AC 1 p d 1 , f 1 q and n | par max p A, G q| . 11 This is equi v alen t to the sequen ce p ; id A n ; . . . ; id A 1 . If the applic ation condit ion has formula f D A r Q p A qs , we can proceed by defining the compos ition operator p T A with actio n: d ÞÝ Ñ d 1 t A 1 , . . . , A n u , d ij : A i Ñ A j f ÞÝ Ñ f 1 D A 1 . . . D A n n ª i 1 A i , (4) where A i contai ns a single edge of A and n is the number of edges of A . T his is equi v alent to the set of 10 iso p A, G q t f : A Ñ G | f i s an isomorphism u . 11 par max p A, G q t f : A Ñ G | f i s a maximal non-empty partial morphism with Dom p f q V A V u . P . P . P ´ er ez / Matrix Graph Gr ammars 9 sequen ces t p ; id A i u , i P t 1 , . . . , n u . Less ev ident are formulas of the form f E A r A s A r A s . For tunatel y , ope rators q T and p T commute when composed so we can get along with the operator r T A p T A q T A q T A p T A . The image of r T on such A Cs are g iv en by: d ÞÝ Ñ d 1 t A 11 , . . . , A mn u , d ij : A i Ñ A j f ÞÝ Ñ f 1 D A 11 . . . D A mn m © i 1 n ª j 1 P A ij , G . (5) An A C is said to be coher ent if it is not a cont radictio n (f alse in all scen arios), c ompatible if, together with th e rule’ s actions, produc es a simple di graph, and consistent if D G host graph such that G | ù AC 12 to which the production is applicable. A s A Cs can be transformed into equi va lent (sets of) sequence s, it is pr ov ed in [22] that c oherenc e and compatib ility of an A C is eq ui v alent to coheren ce and compatibil ity of the ass ociated (set of) sequen ce(s), respecti v ely . Also, an A C is c onsiste nt if and only if its equi v al ent (set of) sequenc e(s) is applicab le. Besides, all res ults and anal ysis techniqu es de vel oped for MGG can be appl ied to sequen ces with A Cs. Some e xamples follo w: • As a sequence is applicable if and only if it is coh erent and compatible (see Sec 6.4 in [19]) then an A C is con sistent if and only if it is coherent and compatible. • Sequentia l independe nce allo ws us to delay or adv an ce the constr aints ins ide a seq uence. As long as the producti ons do not modify the elements of the constra ints, this is transformation of precon ditions into postcon ditions. More on Sec. 5. • Initial digr aph calculat ion solv es the prob lem of finding a h ost graph tha t satisfies a gi v en A C /GC. There are some limitations , thoug h. For example it is necessa ry to limit the maximum number of nodes when dealing with uni ver sal qua ntifiers. This ha s no impac t in some cases , for example when non-un iform MGG submodels are conside red (see nodeless MGG in [21]). • Graph c ongrue nce characte rizes sequences with the sa me initial digra ph. Therefore it can be use d to study when two GCs/A C s are equi v al ent for all morphisms or for some of them. Summarizing, there are two basic results in [22 ]. First, it is always possibl e to embed an applic ation condit ion into the LH S of the production or deri va tion. The left hand side L of a product ion receiv es elements that must be found – P p A, G q – and K those whose pres ence is forbidd en – P p A, G q –. S econd, 12 W e shall say th at the host grap h G satisfies D A r A s , written G | ù D A r A s , if and only if D f P par max p A, G q r f P tot p A, G qs , being tot p A, G q t f : A Ñ G | f is a total morphism u par max p A, G q . Also, G satisfies A r A s , writ ten G | ù A r A s , if and only if f P par max p A, G q r f P tot p A, G qs . Usually we shall abuse of the notation and write G | ù GC instead. For more details, please refer to [22]. 10 P . P . P ´ er ez / Matrix Graph Gra mmars it is alwa ys possible to find a sequen ce or a set of sequenc es of plain product ions w hose behav ior is equi v alen t to that of the production plus the applicati on condition. 4. Postcondi tions In this sectio n we shal l introd uce post conditi ons and state some ba sic fac ts about th em analo gous to those for precond itions. W e shall enlarg e the notation by appending a left arro w on top of the condition s to indica te that the y are preconditio ns and an upper right arrow for postco ndition s. Examples are A for a precon dition and Ñ A for a pos tconditi on. If it is clear from the conte xt, arrows will be omitte d. Definition 4.1. (Pre condition and Postc ondition) An application conditio n set on the LHS of a produ ction is kno wn as a pr eco ndition . If it is set on the RHS then it is kno wn as a postcon dition . Operator s T Ñ A , p T Ñ A , q T Ñ A and r T Ñ A are defined similarly for postconditi ons. The follo wing propositio n establ ishes an equ i va lence between the basic formulae (match, decompos ition, closu re and nega ti ve ap- plicati on conditio n) and certain sequenc es of production s. Pro position 4.1. Let Ñ A p f , d q f , pt A u , d : R Ñ A q be a po stcondi tion. T hen we can obtain a set of equi v ale nt sequence s to g iv en basic formulae as follo ws: (Match) f D A r A s ÞÝ Ñ T A p p q id A ; p (6) (Closure ) f E A r A s ÞÝ Ñ q T A p p q id A 1 ; . . . ; id A m ; p (7) (Decompos ition) f D A r A s ÞÝ Ñ p T A p p q id A i ; p ( i 1 ,...,n (8) (N A C) f E A r A s ÞÝ Ñ r T A p p q ! id A 1 i 1 ; . . . ; id A m i m ; p ) i j Pt 1 ,...,n u ,j Pt 1 ,...,m u (9) where m is th e number of po tential matc hes o f A in th e i mage of the ho st g raph, n is the numbe r of edges in A and id A asks for the exis tence of A in the complement of the image of the host graph. Pr oo f For the first case (match) , the AC states that an addit ional graph A has to be found in the image of the hos t graph. This is easily achie v ed by applying id A to the image of L , i.e. by consider ing id A p p p L qq p id A p q p L q . T he element s in A are related to those in R according to the identifica tions in a morphism d that has to be gi ven in the diagr am of the postco ndition . In the four cases considere d in the propositi on we can move from composition to concaten ation by means of the marking ope rator T µ . Recall that T µ guaran tees that the identifica tions in d are preserv ed. P . P . P ´ er ez / Matrix Graph Gr ammars 11 The second case (closure) is very similar . W e hav e to verify all potential appearanc es of A in the image of the host graph becau se E A r A s A r A s . W e proceed as in the first case but this time with a finite numbe r of composi tions: p id A 1 . . . id A m p q p L q . For decompo sition, A is not fou nd in the ho st graph if for so me matc hing t here i s at least one mis sing edge. It is thus similar to matching b ut for a single edge. The way to proceed is to consider the set of sequen ces that appear in eq. (8). Nega ti ve applic ation conditions (NA Cs) are the compos ition of eqs. (7) and (8). One of the main points of the techniq ues a v ailab le for precon ditions is to analyz e rules with A Cs by transla ting them into sequen ces of flat rules, and then analyzin g the sequences of flat rules instead. Theor em 4.1. Any well-d efined postco ndition can be reduced to the study of the corresp onding set of sequen ces. Pr oo f The proof follo ws that of Th. 4.1 in [22] and is includ ed here for completene ss sake. Let the depth of a graph for a fi xed node n 0 be the maximum ov er the shor test path (to av oid c ycles) starting in any node dif ferent from n 0 and ending in n 0 . The depth of a graph is the maxi mum depth for all its nodes. Notice that the depth is 1 if and only if A i , i in the diagram are unrelated . W e shall apply induction on the depth of the A C. A diagram d is a graph where nodes are digraphs A i and edges are morphisms d ij . There are 16 possib ilities for depth 1 in a A C made up of a sing le element A , summarize d in T able 1. (1*) D A r A s (5*) { A r A s (9*) D A r Q p A qs (13*) { A r Q p A qs (2*) D A r A s (6*) { A r A s (10*) D A r Q p A qs (14*) { A r Q p A qs (3*) E A r A s (7*) A r A s (11*) E A r Q p A qs (15*) A r Q p A qs (4*) E A r A s (8*) A r A s (12*) E A r Q p A qs (16*) A r Q p A qs T a ble 1. All Possible Diagram s for a Single Elemen t Elements in the same ro w for each pair of columns are related using equalities E A r A s A r A s and { A r A s D A r A s , so it is possibl e to reduc e the study to cases (1*) – (4*) and (9*) – (12*). Identiti es Q p A q P p A, G q and Q p A q P p A, G q reduce (9*) – (12*) to formulae (1*) – (4*): D A r Q p A qs D A P p A, G q , D A r Q p A qs D A P p A, G q E A r Q p A qs E A P p A, G q , E A r Q p A qs E A P p A, G q . Proposit ion 4.1 con siders the four basic cases which correspon d to (1*) – (4*) in T able 1 , sho w ing that in fac t the y can all be reduced to match ings in the image of the hos t graph, i.e. to (1* ) in T able 1, ver ifying the theorem. 12 P . P . P ´ er ez / Matrix Graph Gra mmars No w we mov e on to the induction step which consid ers combinations of quantifiers. W ell-definednes s guaran tees inde penden ce with respect to the order in which elements A i in the postconditi on are selected. When t here is a univ ersal quan tifier A , ac cording to eq . (7), el ements of A are repli cated as man y times as poten tial instances of A can be foun d in the host graph . In order to co ntinue the proce dure we ha v e to clone th e rest o f th e diagram fo r each repli ca of A , exc ept those g raphs whic h are e xisten tially quantified before A in the formula. That is, if we hav e a formula D B A D C when performing the closur e of A , we ha ve to replicate C as man y times as A , but not B . M oreo ver B has to be conn ected to each replica of A , p reservin g the iden tifications of th e morphi sm B Ñ A . More i n deta il: When closu re is appli ed to A , we iterate on all graphs B j in the diagr am. There are three possibi lities: • If B j is existenti ally qu antified after A – A... D B j – then it is replicated as many times as A . Appropri ate morphisms are created between each A i and B i j if a morphism d : A Ñ B exis ted. The ne w morphisms identify elements in A i and B i j accord ing to d . This permits finding dif ferent matches of B j for each A i , some of which can be equal. 13 • If B j is exist entially quantified before A – D B j ... A – then it is not replicated, but just connecte d to each replica of A if necessar y . This ensure s that a unique B j has to be found for each A i . Moreo ver , the repli cation of A has to preserve t he s hape of the origi nal diagram. That is, if th ere is a morphism d : B Ñ A then each d i : B Ñ A i has to preserv e the identificati ons of d (this means that we take onl y those A i which preserv e the stru cture of the diagram). • If B j is uni v ersally quanti fied (no matter if it is quantified before or after A ), again it is replicated as man y times as A . Afterwa rds, B j will itsel f need to be replicated due to its uni versa lity . T he order in which these replicat ions are performed is not rele v ant as A B j B j A . Pre vious theorem and the corollaries that foll ow heavi ly dep end on the ho st graph and its image (throu gh matching ) so analysis techniques de v eloped so far in M GG which are inde penden t of the host graphs can not be appli ed. The “problem” is the uni vers al quanti fier . W e can consider the initial digraph and dispose to some e xtent of the host gra ph and its image . This is relat ed to the fa ct (Sec. 5) that it is possib le to transfo rm postcon ditions into equiv ale nt precond itions. T wo applications of T h. 4.1 are the follo wing corollarie s that characteri ze coheren ce, compatib ility and consis tency of postcondi tions. Cor ollary 4.1. A postco ndition is coherent if and only if its associated (set of) sequence( s) is coherent. Also, it is compat ible if and onl y if its asso ciated (set of) seq uence(s ) is compatib le and it is cons istent if and only if its assoc iated (set of) sequen ce(s) is applicable . 13 If for example there are three instances of A in t he image of the host graph but only one of B j , then the three replicas of B are matched to the same part of p p G q . P . P . P ´ erez / Matrix Graph Gr ammars 13 Cor ollary 4.2. A postcond ition is consistent if and only if it is coherent and compatible. Example. Let’ s consider the diagra m in Fig. 4 with formula D A 0 D A 1 r A 0 ñ A 1 s . The postcondi tion states that if an operator is con nected to a machine, such machine is b usy . The formula has an implica- tion so it is not possib le to directl y generat e the set of sequences because the postcondit ion also holds when the left of the implication is false. The closure operator q T redu ces the postcondit ion to existen tial quanti fiers, which is repres ented to the right of the figure. The resulting modified formula would be D A 0 1 A 0 2 A 1 1 A 1 2 rp A 0 1 ñ A 1 1 q ^ p A 0 2 ñ A 1 2 qs . Figure 4. Postcondition Examp le Once the formula has e xistent ials only , we manipul ate it to get rid of implicatio ns. Thus, we hav e D A 0 1 A 0 2 A 1 1 A 1 2 rp A 0 1 _ A 1 1 q ^ p A 0 2 _ A 1 2 qs D A 0 1 A 0 2 A 1 1 A 1 2 rp A 0 1 ^ A 1 2 q _ p A 0 1 ^ A 1 2 q _ p A 1 1 ^ A 0 2 q _ p A 1 1 ^ A 1 2 qs . This leads to a set of four seq uences: tp id A 0 1 ; id A 0 2 q , p id A 0 1 ; id A 1 2 q , p id A 1 1 ; id A 0 2 q , p id A 1 1 ; id A 1 2 qu . Thus, the graph p p G q and the production satisfy the postcondit ion if and only if some sequence in the set is applic able to p p G q . Something left undefined is the order of product ions id A i and id A i in the sequences. Con sistenc y does not depen d on the orderin g of product ions – as long as the first to be applied is production p – becaus e productio ns id (and thei r negatio n) are sequen tially independen t (they do n ot add no r delete any edge or node). If they are not sequential ly indep endent then there exists at least one inconsi stenc y . This incons istenc y can be detected using previ ous corollaries independent ly of the ord er of the productions . 5. Moving C onditions In this section w e giv e two differe nt proofs that it is possibl e to transfo rm pre conditio ns into equi v alent postco ndition s and back again . The first proo f (sketch ed) makes use of c ateg ory theory while the s econd 14 P . P . P ´ er ez / Matrix Graph Gra mmars relies on the character izations of cohe rence, G-co ngruen ce and compatibility . T o ease expos ition we shall focus on the certain ty part only as the nihilatio n part would follo w using the in verse of the produ ction. W e shall start with a cas e that can be a ddresse d using equa tions (6) – (9), Th. 4.1 a nd Cor . 4.1: When the transformed postco ndition for a giv en precondi tion does not change. 14 The question of whether it is alw ays po ssible to transform a precon dition into a postc onditio n – and back again – in this rest ricted cas e would be equi v ale nt to as king for sequ ential indep endence of th e prod uction p and the identit ies id or id : p ; id A n ; . . . ; id A 1 id A n ; . . . ; id A 1 ; p, (10) where the se quence to the left of the equ ality correspon ds to a p recond ition and the seq uence to the rig ht corres ponds to its equi v alent postcondi tion. A m A . . . . . . . . . . . . . . . p A / / Ñ A m Ñ A L p / / d L R d L A p A / / m A Ñ A m Ñ A L p / / m L d L ^ ^ = = = = = = = = R m L d L @ @ G p / / H A p A / / Ñ A G p A / / H Figure 5. Preconditio n to Postcondition Transformation In general the production m ay act on elements that appear in the diagram of the precon dition, spoili ng sequen tial independ ence. Left and center of Fig. 5 – in which the first basic A C (match) is consid ered – sugge st that the pre-to-post transformati on is a categori cal push out 15 in the category of simple digraphs and partial morphisms . Theorem 4.1 pro ves that an y postco ndition can be reduc ed to the match case. Beside s, we can trivial ly consid er total morphisms (in stead of parti al ones) by restric ting the d omain and th e codomain of p to the nodes in A . For the post-to-pr e transformat ion we can either use pullbacks or pushouts plus the in v erse of the produ ction in v olv ed. T o see that prec onditio n satisfac tion is eq ui va lent to postco ndition satisfa ction using c ateg ory theor y , we should che ck tha t th e di ff erent pus houts can be constructed ( p , p A , p A , etcete ra) and that d L m A m L and d L m Ñ A m L (refer to Fig. 5 ). Although some topics remain u ntouche d such as dangli ng edges, we shall not carry on with categ ory theory . Example . Let be gi ve n the pr econdit ion A to th e left of Fig . 6 wit h formul a f D A r A s . T o calcul ate its associ ated postc onditio n we can apply the prod uction to A and obtain Ñ A , represente d also to the left of 14 This is not so unrealistic. For exa mple, if the production preserves all elements appearing in the precond ition. 15 The square ! L, R , A , Ñ A ) is a pushou t where p , L , d L , R and A are kno wn and Ñ A , p A and d L need to be calculated. P . P . P ´ erez / Matrix Graph Gr ammars 15 Figure 6. Restriction to Comm on P arts: T otal Morph ism the same figure. Notice ho wev er that it is not possible to fi ng a match of L in A becaus e of node 3 . One possib le solution is to cons ider L 1 L X A and restric t the prod uction to those common elemen ts. This is done to the right of Fig. 6 Theor em 5.1. Any cons istent preconditio n is equiv al ent to some consistent post conditio n and vice versa. Pr oo f For the post-to-pr e transfo rmation roles of p and p 1 are inte rchange d so we shall ad dress only th e pre- to-pos t case. It is eno ugh to study a single A in the diagram as the same proce dure applies mechanically (Th. 4.1 transforms any precon dition into a sequence of productio ns). Also, it suffices to state the result for id A becaus e id A is simil ar b ut the e v oluti on depends on p 1 . Finall y , we shall ass ume that p and id A are not sequ entially independen t. Recall that G -cong ruence guarantee s sameness of the initial digraph, which is w hat the sequence demands o n the host g raph. Therefore, all we ha ve to do i s to use G -congruenc e to check the dif fer ences in the two se quences : p ; id A ÞÝ Ñ id Ñ A ; p. (11) Ho wev er , before that we need to guarant ee coherence and compatibil ity of bot h seque nces (see the hy- pothes is of Th. 4 in [20]). Coherence gi ves rise to th e follo wing equation: r Ñ A R _ e Ñ A 0 r A _ e A L ù ñ e Ñ A _ r A 0 , (12) where e and r corresp ond to p , e A to id A and r Ñ A to id Ñ A . Fortu nately , id is a productio n that does nothin g, so from the dynamical point of vie w any con flict should come from p , i.e. e A r Ñ A 0 which has been used in the implicati on of eq. (12). By consistenc y we ha v e that r A 0 so eq. (12) will be ful filled if the postcondi tion is th e precon- dition but erasing the elements that the produc tion deletes. A similar reason ing for the nihil part tells us that we sho uld add to the postco ndition all those elements added by the product ion. 16 P . P . P ´ er ez / Matrix Graph Gra mmars Compatibil ity can only be ruined by danglin g edges. In Sec. 6.1 in [19] dangling edge s are deleted transfo rming the producti on via the ope artor T ε . This is prove d to be equi v alent to defining a sequence by appending a so-called ε -produc tion. In essenc e the ε -prod uction jus t deletes any dangling edge, thus kee ping compatib ility . This very same pro cedure can be appli ed now: p ; id A T ε ÞÝ Ñ p ; p ε ; id A ÞÝ Ñ p ; id ε A ; p ε ÞÝ Ñ id Ñ A ; p ; p ε . (13) Accordin g to Prop. 5 and Th. 4 in [20], two compatible and cohere nt sequen ces are G -congrue nt if the follo wing equation (adapted to our case) is fulfilled: L A eK r _ e A _ K A r L p e _ r A q 0 . (14) W e ha ve that e A r A 0 . Also, K A 0 because id A acts on the certainty part and er r (se e e.g. Prop. 4.1.4 in [24]). W e are left with L A K K A 0 , (15) which is guaranteed by compatibi lity: once id A is transfor med int o id ε A in eq. (13) there can not be any potent ial danglin g edge, except those to be delet ed by p in the last step. It is worth stres sing the fact that the trans formation between pre and postcon ditions preserv e consis- tenc y o f th e a pplicat ion conditio n. W e hav e se en in this section that p not o nly acts on L bu t o n th e who le precon dition. W e can therefore extend the notati on: Ñ A p p A q , Ñ A x A , p y . (16) Pre-to-po st and post-to-p re transformat ions can af fect the diag ram and the formula . See the e xample belo w . There are two clear cases: • The applica tion condition requires the graph to appear and the production deletes all its elements. • The appl ication cond ition requi res the graph n ot t o a ppear and the prod uction add s al l its elements. For a giv en applicat ion condition A C it is not necess arily true that A p 1 ; p p A q becaus e some ne w ele ments may be add ed and some obsolete elements discard ed. What we will get is an equiv ale nt condit ion adapted to p that holds whene ve r A holds and fai ls to be true w hene v er A is false. Example . In Fig. 7 there is a very simple transfo rmation of a precon dition into a postconditi on thro ugh morphism p p A q . The ass ociated formul a to the p recond ition A that we shal l conside r is f D A r A s . The produ ction deletes two arrows and adds a new one. The ov erall ef fect is rev erting the directi on of the edge between nodes 1 and 2 and deletin g the self-loop in node 1 . N otice that m L can not match node 2 to 2 1 in G because of the edge p 3 , 2 q in the appli cation conditio n. P . P . P ´ erez / Matrix Graph Gr ammars 17 Figure 7. Precon dition to Postcondition Example Suppose we had a (redu ndant) gr aph B made up of a single node 1 with a self loop in the precondi tion and with formula f D AB r AB s . The formula in the postco ndition would still be Ñ f D A r A s . The opposite transformati on, from postcond ition into precond ition, can be obtaine d by re verti ng the arro w , i.e. throug h p 1 p A q . More general schemes can be studied applyin g the same principle s. Let A p 1 p A . If a pre-post-pr e transf ormation is carried out, we w ill hav e A A because edge (2,1) woul d be added to A . Ho wev er , it is true that A p 1 p p A q . Note that in fact id A and p are sequen tially independ ent if we limit ourselve s to edges, so it would be po ssible to simpl y mov e th e precon dition to a pos tcondit ion as it is. Nonetheless, we ha v e to c onsider nodes 1 and 2 as the common parts between L and A . T his is the same kind of restriction as the one illustr ated in Fig. 6. If the pre-po st-pre transfor mation is thought of as an operator T p acting on applica tion conditions , then it fulfills T 2 p id, (17) where id is the ident ity . The same would also be true for a post- pre-pos t transf ormation. A possible interpretati on of eq. (17) is that the definition of the application condition can vary from the natu ral one, accordin g to the production under considerat ion. P re-pos t-pre or post-pre -post transfor - mations adju st applic ation conditio ns to the correspond ing pro duction . When defining diagra ms some “practical prob lems” may turn up. For example, if the dia gram d L d L 0 Ñ A 0 d 10 A 1 is conside red then there are two potent ial problems: 1. The direction in the arrow A 0 A 1 is not the natural one. Nev erthel ess, injecti v eness all ows us to safel y re vert the arro w , d 01 d 1 10 . 2. Even t hough we only fo rmally state d L 0 and d 10 , other mo rphisms nat urally appea r and need to be 18 P . P . P ´ er ez / Matrix Graph Gra mmars check ed out, e.g. d L 1 : R Ñ A 1 . N e w morphisms should be considere d if they relate at least one element. 16 6. Delocalization and V ariable Nodes In th is sect ion we touch o n delo calizat ion of gra ph constr aints and app lication condi tions as well as t heir equi v alen ce. Also, we shall pav e the way to multidig raph re writing to be studied in detail in Sec. 7. Let s p n ; . . . ; p 1 be a sequence of productio ns with their correspo nding A Cs. W e ha ve seen in Th. 4.1 that precondi tions and postcon ditions are equi v alent and in Th. 5.1 that the y can be transforme d into seq uences of pro duction s. As a precon dition in p i 1 is th e same as a postcon dition in p i , we see t hat A Cs can be mo ved arbit rarily inside a sequence. Similarly , constraints set on the intermedia te states of a deriv at ion can be moved among them. A graph constra int GC set in the initial state G to which a product ion p is going to be applied is equi v alent to the preco ndition f pr e D L D K L ^ P K, G ^ f GC . (18) If the GC is set on the final state H p p G q to w hich the production p has been applied, there is an equi v alen t postcondi tion: f post D R D Q P p R, H q ^ P Q, H ^ f GC . (19) In bot h cases the diagrams are giv en by the L HS or the RHS plus the diagram of the graph con straint. W e call this property of application conditions and graph constraints delocalizati on . W e shall no w address v ariable nodes which will be used to enhance MGG functional ity to deal with multidig raphs. Graph transformati on with v ariable s is studied in [12]. W e shall summarize the proposal in [12] and propou nd an alterna ti ve way to close the section. If instead of nodes of fixed type v ariable, types are allo wed we get a so called graph pattern . A rule scheme is just a production in which graphs are graph patterns . A substitution function ι specifies ho w varia ble names taking place in a production are substitute d. A rule scheme p is instan tiated via substi tution functio ns producing a particu lar producti on. For e xample, for substituti on function ι we get p ι . The set of production instanc es for p is defined as the set I p p q t p ι | ι is a substitu tion u . The ker nel of a graph G , ker p G q , is define d as the graph resul ting when all variab le nodes are remov ed. It might be the case that k er p G q H . The basic idea is to reduce any rule scheme to a set of rule instances. Note tha t it is not possible in genera l to generate I p p q becaus e this set can be infinite. The way to proc eed is not dif ficult: 16 Otherwise stated: Any condition made up of n graphs A i can be identified as the complete graph K n , in which nodes are graphs A i and morphisms are d ij . Whether this is a directed graph or not is a matter of taste (morphisms are injectiv e). P . P . P ´ erez / Matrix Graph Gr ammars 19 1. Find a match for the kerne l of L . 2. Induce a substit ution ι such that the match for the kernel becomes a full match m : L ι Ñ G . 3. Construct the instanc e R ι and apply p ι to get the direct deri v ation G p ι ù ñ H . As an alternat iv e, we may exten d the concept of type ass ignment. Recall from Sec. 2 that typ es are assign ed by a function from the set of nodes | V | of a simple digrap h G to some fi xed set T of types, λ : | V | Ñ T . Instea d, we shall define λ : | V | Ý Ñ P p T qzH , (20) where P p T q is the po wer set 17 of T exc ept for the empty set becau se we do not permit nodes without types. When two matric es are operated, the types of a fixed node will be the intersection of the nodes operat ed. For exa mple, s uppose t hat we and two matrices C AB and that the (s et o f) nodes a ssociate d to th e elements a and b are λ p a q and λ p b q , respecti v ely . T hen, λ p c q λ p a q X λ p b q . The operat ion would not be allo wed in case λ p c q λ p a q X λ p b q H . Figure 8. Exam ple of Graph Constraint Example . Let a type of nodes be represented by square s (call them multinodes ) and the rest (call them simple nodes ) by color ed circles. The set of types T is split into two : multinodes and simple nodes. Let’ s consider the graph constra int GC 0 p d 0 , f 0 q , with d 0 the diagra m depicted in Fig. 8 made up of the graphs A 0 and A 1 , along with the formula f 0 A 0 A 1 r Q p A 0 q Q p A 1 qs . T his graph constr aint is “edges must connect node s and m ultino des altern ati vely but no edge is allowed to be incident to two multinod es or to two simple node s, including self-loops ”. In th e grap h A 0 of Fig. 8, x and y represent va riable no des while a and b in A 1 ha ve a fixed type. W e may think of a and b as v ariabl e nodes whose set of types has a single element. 17 The set of all subsets. 20 P . P . P ´ er ez / Matrix Graph Gra mmars 7. Fr om Simple Digraphs to Multidigraphs In th is sect ion we sho w h o w MGG can deal with multidigrap hs (directed graphs a llo wing multip le paral- lel edges) just by conside ring variab le nodes. At fi rst sight this might seem a hard task as MG G hea vily depen ds on adjacen cy matrices . Adjacenc y matrices are w ell su ited for si mple digrap hs but can not cope with parallel edges. This section can be thought of as a theor etical appli cation of graph constrai nts and applic ation conditio ns to Matrix Graph Grammars. The idea is not dif ficult: A specia l kind of node (call it multinode in contrast to simple node ) associ- ated to e ver y edge in the graph is introduc ed, i.e. ed ges in the multidig raph are subs tituted by multino des in a simple digraph represen tation of the multidigraph . G raphic ally , multinod es will be represent ed by a filled square while normal nodes will appear as colore d circles . See the exampl e by the end of Sec. 6 Operatio ns pre vious ly specified on edge s no w act on multinodes: Adding an ed ge is transf ormed into a multinod e a ddition and edge deleti on becomes multinod e de letion. There are edges that link multinodes to their source and tar get simple nodes. Some restriction s (a pplicati on co nditions ) to be imposed on the actions that can be performed on multinod es exist, as well as on the shape or topolog y of permitted graphs (graph constr aints). Not ev ery possib le graph with multinodes represent s a multidigrap h. Figure 9. Multidig raph with T wo Outgoing Edges Example . Consider the simple producti on in Fig. 9 with two parallel edges between nodes 1 and 3 . As commented abo ve, m ultino des are represente d by square nodes while normal nodes are left unchang ed. When p deletes an edge, p τ delete s a multinod e. Adjacenc y matrices for p τ are: P . P . P ´ erez / Matrix Graph Gr ammars 21 L 0 0 0 1 1 1 | 1 0 0 0 0 0 0 | 2 0 0 0 0 0 0 | 3 0 0 1 0 0 0 | a 1 0 0 1 0 0 0 | a 2 0 1 0 0 0 0 | d R 0 0 0 1 1 | 1 0 0 0 0 0 | 2 0 0 0 0 0 | 3 0 0 1 0 0 | a 2 0 1 0 0 0 | d K 0 0 0 0 0 0 | 1 0 0 0 1 0 0 | 2 0 0 0 1 0 0 | 3 1 1 0 1 1 1 | a 1 0 0 0 1 0 0 | a 2 0 0 0 1 0 0 | d e 0 0 0 1 0 0 | 1 0 0 0 0 0 0 | 2 0 0 0 0 0 0 | 3 0 0 1 0 0 0 | a 1 0 0 0 0 0 0 | a 2 0 0 0 0 0 0 | d In a real situatio n, a de velo pment tool such as A T oM 3 or A GG 18 should take care of all these repre- sentat ion issues. A user would see what appe ars to the left of Fig. 9 and not what is depi cted to the right of the same figure. Some restrictions on what a productio n can do to a multidig raph are necess ary in order to obtain a multidig raph again. Think for e xample the case in which afte r applying some producti on we get a graph in whic h there is an isolated multinode (which would stand fo r an edge with no source nor tar get node s). All we ha ve to do is to find the properties that define one edge and impose them on multinod es as graph constr aints: 1. A simple nod e (resp., m ultino de) can not be dire ctly co nnecte d to ano ther si mple node (resp ., multinod e). 2. Edges (encode d as multinodes ) always ha ve a simple nod e as sourc e and a simple node as tar get. First condition abo ve is addr essed in the ex ample of Sec. 6 with gr aph con straint GC 0 . See Fig. 8. The second con dition can be encode d as another graph constraint GC 1 p d 1 , f 1 q . The diagram can be found in Fig. 10 and the formula is f 1 A 2 A 3 r A 2 A 3 s . Figure 10. Multidigr aph C onstraints 18 http://mon cs.cs.mcgil l.ca/MSDL/research/projects/AToM3/ for A T oM 3 and http://www. gratra.org/ for A GG and some other tools. 22 P . P . P ´ er ez / Matrix Graph Gra mmars Theor em 7.1. Any multidigra ph is isomorphic to some simple digraph G togethe r with the gra ph con - straint M C p d 0 Y d 1 , f 0 ^ f 1 q . Pr oo f (sketc h) A graph with multi ple edges M p V , E , s, t q consis ts of disjoint finite sets V of nod es and E of edges and sour ce and tar get func tions s : E Ñ V and t : E Ñ V , respe cti vel y . Function v s p e q , v P V , e P E returns the node source v for edge e . W e are consid ering m ultidi graphs because the pair function p s, t q : E Ñ V V need not be injecti v e, i.e. sev eral diff erent edges may hav e the same source and tar get node s. W e ha v e digra phs becaus e there is a disti nction between so urce and tar get nodes . This is the standa rd definition found in any te xtbook . It is clear that any M can be represented as a multidig raph G satisfying M C . The con verse also holds. T o see it, just con sider all possible combinati ons of two nod es and two multino des and check that any pro blematic situation is ruled out by M C . Inducti on fi nishes the pro of. The multidigrap h constra int M C must be fulfilled by any host graph. If there i s a prod uction p : L Ñ R in v olv ed, M C has to be tran sformed into an applica tion conditi on ove r p . In fact, the multidigraph constr aint should b e demand ed both as p recond ition and pos tcondit ion. This is easil y achie v ed by means of eqs. (18) and (19). This sect ion is closed analyzi ng what beh av ior w e hav e for multidigr aphs with resp ect to dangli ng edges. W ith the theory as de v eloped so far , if a produc tion specifies the dele tion of a simple node then an ε -productio n w ould delete any edge incident to this simple node, connec ting it to any surroun ding multinod e. But restricti ons impo sed by MC do not allow this so any produc tion with potenti al dangling edges can not be applie d. In order to aut omatically delete any pote ntial multiple dangl ing edge, ε -prod uctions need to be re- stated by defining them at a multidigrap h lev el, i.e. ε -produc tions hav e to delet e any pote ntial “dangling multinod e”. A new type of prod uctions ( Ξ -produc tions) are introduced to get rid of anno ying edges 19 that would dang le when multinod es are also deleted by ε -production s. W e will not de velo p the idea in detail an d will limit to describ e the concept s. The way to proceed is to define the appropriat e operator T Ξ and redefine the opera tor T ε . A produ ction p : L Ñ R between multidig raphs that delete s one simple nod e n 1 may giv e r ise to one ε -prod uction that deletes one or more multin odes m i (those “inc ident” to n 1 not dele ted by the grammar rule). This ε -prod uction can in turn be applied only if any edge incident to the m i ’ s has already been erased , hence possib ly prov oki ng the appearan ce of one Ξ -production . This pr ocess is depic ted in Fig. 11 where, in order to apply produc tion p , produ ctions p ε and p Ξ need to be applie d in adv ance p ÞÝ Ñ p ; p ε ; p Ξ . (21) 19 Edges connect simple nodes and multinodes. P . P . P ´ erez / Matrix Graph Gr ammars 23 Figure 11. ε -pro duction and Ξ -production Event ually , one cou ld simply compose the Ξ -productio n w ith its ε -p roduct ion, renaming it to ε - produ ction and defining it as the way to deal with dangling edges in case of multiple edges, fully recov - ering the standard behav ior in MGG . As commented abov e, a potenti al u ser of a de vel opment t ool such as A T oM 3 would stil l see things as in the simple digraph case, with no need to worry about Ξ -productio ns. Another theoretical u se of a pplicati on condi tions and graph cons traints is the enco ding o f T ur ing Ma- chines and Boolean Circuits using Matrix Graph Grammars (see [21]). Howe ve r , they are not necessary for Petri nets (see Chap. 10 in [19]). 8. Conclusions and Futur e W ork In the pre sent cont rib ution we ha ve introduced precond itions and post conditio ns for MGGs, pro ving that there is an equi v alent set of sequences of plain rules to any giv en postcon dition. Besides, coheren ce, compatib ility and consisten cy of postcondi tions ha ve been ch aracteri zed in terms of alread y kno wn con- cepts for sequences. W e ha v e also pro v ed that it is al ways possib le to transform an y postcondit ion into an equi v alent precondit ion and vice v ersa. Moreo ve r , we hav e seen that restr ictions are deloc alized if a sequen ce is unde r conside ration. An a lternati v e way to that in [1 2] to ta ckle v ariab le nodes has also b een propo sed. This allo ws us to exte nd MG G to cope with multidi graphs without major modificatio ns to the theory . In [22] th ere is an ex hausti v e comparison of the app licatio n condition s in MGG and other prop osals. The m ain papers to the best of our kno wledge that tackle this topic are [6 ] (with the de finition of A Cs), [8, 9 ] w here GC s and A Cs are ext ended with nesting and sati sfiability , and also [23] in which A Cs are genera lized to arbitrar y lev els of nesti ng (though restrict ed to trees). For future work, we shall generalize already studie d concepts in MGG for multidigrap hs such as cohere nce, compatibil ity , initial digrap hs, graph congrue nce, reachabilit y , etceter a. Our main interest, ho we ver , will be focu sed on comple xity theo ry and the applicatio n of MGG to the study of comple xity 24 P . P . P ´ er ez / Matrix Graph Gra mmars classe s, P and NP in particula r . [21] follo ws this line of research . Refer ences [1] A GG, The Attributed Graph Grammar system. http: //tfs. cs.tu-berlin.de /agg/ . [2] Bra-ket notation intro: ht tp:// en.wik ipedia.org/wiki/Bra-ket no tatio n [3] Corradini, A., Montanar i, U. , Rossi, F ., Ehrig , H., Heckel, R., L ¨ owe, M. 1999 . Algebraic Appr oaches to Graph T ransforma tion - P art I: Basic Con cepts and Double Pushout Appr oach . In [24], pp.: 163- 246 [4] Courcelle, B. 199 7. The e xpr ession of graph pr op erties and graph tr ansformatio ns in monadic second-order logic . In [24], pp.: 313-4 00. [5] Ehrig, H., Heckel, R., K orff, M. , L ¨ owe , M., Ribeir o, L., W agner, A., Corradin i, A. 19 99. Algebraic Ap- pr oaches to Gr aph T ransformation - P art II: Single Pusho ut Ap pr oach and Comparison w ith Doub le Push out Appr oach. In [24], pp.: 24 7-312 . [6] Ehrig, H., Ehrig, K., Habel, A., Pennemann, K.-H. Constraints and Applicatio n Conditio ns: F r om Graphs to High-Level Structur es . Proc. ICGT’04 . LNCS 3256, pp.: 28 7-303 . Springer . [7] Ehrig, H., Eh rig, K., Prange, U., T aen tzer , G. 200 6. Funda mentals of Algebraic Graph T ransformatio n. Springer . [8] Habel, A., Pennem ann, K.-H. 20 05. Nested Constraints and Application Conditions for High-Level Struc- tur es . In Formal Methods in Software and Systems Modeling , LNCS 339 3, pp. 293-308. Springer . [9] Habel, A., Penn eman, K.-H. 2009 . Corr ectness of High-Level T ransformatio n Systems Relative to Nested Conditions . Math. Struct. Comp. Science 19(2) , pp.: 2 45–29 6. [10] Heckel, R., K ¨ uster, J.-M-., T aentzer, G. 20 02. Confl uence of type d a ttrib uted g raph transformation systems . Proc. ICGT’02, LNCS 2505, pp. 161–17 6. Springer . [11] Heckel, R., W agn er , A. 199 5. Ensurin g co nsistency o f cond itional graph r e writing - a constructive appr oach. , Electr . Notes Theor . Comput. Sci. (2). [12] Hoffman, B. 2005. Gr aph T ransformation with V a riables . In Graph T ransformatio n, V ol. 3393/200 5 o f LNCS, pp. 101-11 5. Springer . [13] Lamber s, L ., Ehrig , H., Orejas, F . 2006 . Con flict Detection for Graph T ransformatio n with Negative A ppli- cation Conditions . Proc ICGT’06, LNCS 4178, pp.: 61-7 6. Springer . [14] de Lara, J., V anghelu we, H. 2004 . Defining V isual Notations an d Their Manipula tion Thr ough Meta- Modelling a nd Graph T r ansformation . Journal of V isual Langu ages an d Compu ting. Special section on “Domain-Sp ecific Modeling with V isua l Languag es”, V ol 15(3 -4), pp.: 309 -330. Else vier Science. [15] P ´ er ez V e lasco, P . P ., de Lara, J. 20 06. T owar ds a New Algebraic Ap pr oach to Graph T rans- formation: Long V ersion. T e ch. Rep. of the Schoo l of Comp. Sci., Univ . Aut ´ onoma Ma drid. http:/ /www. ii.uam.es/ jlara/investigacion/techrep 03 06.p df . P . P . P ´ erez / Matrix Graph Gr ammars 25 [16] P ´ erez V e lasco, P . P ., de Lara , J. 2006 . Matrix Appr oach to Graph T ransformation : Ma tching and Sequen ces . Proc ICGT’06, LNCS 4178 , pp.:122-13 7. Sp ringer . [17] P ´ erez V elasco, P . P . , de Lara, J. 200 7. Using Matrix Graph Gr ammars for the Ana lysis of Behavioural Speci- fications: Sequentia l and P arallel Inde pendenc e Proc. PR OLE’07, pp.: 11-26 . Electr . Notes Th eor . C ompu t. Sci. (206 ). pp.:1 33–15 2. E lse vier . [18] P ´ erez V elasco, P . P . , de Lara, J. 2 007. An alysing R ules with App lication Conditio ns u sing Matrix Graph Grammars . Graph T ransformation for V erification and Concurrency (GTVC) w orksho p. [19] P ´ erez V elasco , P . P . 200 9. Matrix Graph Grammars: An Algebraic App r o ach to Graph Dyn amics . ISBN 978-3 6392 12556. VD M V erlag . Also available as e-b ook at: http:// www.m at2gra.info/ and arXiv: 0801. 1245v1 . [20] P ´ erez V ela sco, P . P ., de Lar a, J. 2 009. A Reformu lation of Matrix Graph Grammars with Boolean Complexes . The E lectronic Journal o f Combinator ics. V ol 16(1 ). R73. A vailable at: http:/ /www. combinat orics.org/ . [21] P ´ erez V elasco , P . P . 20 09. Matrix Graph Grammars a s a Model of Compu tation . Preliminar y version available at arXiv :0905 .1202v2 . [22] P ´ erez V elasco, P . P ., de Lara, J. 201 0. Matrix Graph Gr ammars with App lication Condition s . T o ap pear in Fundamen ta Informaticae. Also av ailable at arXiv: 0902.1 809v2 . [23] Rensink , A. 2004 . Rep r esenting Fi rst-Or der Logic Using Gr aphs. Proc. ICGT’04, LNCS 3256, pp.: 3 19-33 5. Springer . [24] Rozen berg, G. 1 997. Handbo ok of Graph Grammars and Computing by Graph T ransformation. V ol 1. W orld Scientific.
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment