The Semantics of Graph Programs
GP (for Graph Programs) is a rule-based, nondeterministic programming language for solving graph problems at a high level of abstraction, freeing programmers from handling low-level data structures. The core of GP consists of four constructs: single-…
Authors: Detlef Plump (The University of York), S, ra Steinert (The University of York)
I. Mackie and A. Martins Moreira (Eds.): T enth International W orksho p on Rule-Based Programming (RULE 2 009) EPTCS 21, 2010, pp. 27–38, doi:10.4204 /EPTCS .21.3 c D. Plump & S. Steinert The Semantic s of Graph Pr ogram s Detlef Plump Department of Computer Science The Univ ersity of Y ork , UK Sandra Steinert Department of Computer Science The Univ ersity of Y ork , UK GP (for Graph Programs) is a rule-based, nondetermin istic progr amming lang uage for s olving graph problem s at a hig h level of abstraction , freein g prog rammer s from handling low-lev el data structu res. The core of GP con sists of fou r constructs: single-step app lication of a set of con ditional graph - transform ation rules, sequential comp osition, branching and it eration. W e present a f ormal semantics for GP in the style of structural op erational sem antics. A special feature of o ur semantics is the use of finitely failing program s to define GP’ s powerful branchin g and iteration co mmands. 1 Introd uction This paper defines the semantic s of GP , an experimen tal nondete rministic progra mming language for high-l e vel proble m solving in the d omain of g raphs. The la nguage is ba sed on cond itiona l rule schemata for graph transformati on (introduced in [16]) and thereby frees programmers from handling lo w-le vel data structure s for graphs . The prototype implementation of G P compile s graph programs into bytecode for the Y or k abstra ct machine , and comes with a graphical editor for programs and graphs [11]. GP has a simple syntax as its core contains only four commands: single- step application of a set of rule schemata, sequentia l composition , bran ching and as-long-as-p ossib le iteration. Despite its simplic- ity , GP is computatio nally complet e in that ev ery computable function on graphs can be programmed [8]. A ma jor goal of the GP project is the d e vel opment of a pra ctical graph-tr ansfor mation language that comes with a concis e formal semantics, to facilitat e pro gram verificatio n and other formal reasoning on progra ms. Also, a formal semantics provides implementors with a rigorous definition of the language that does not depend on a compiler or machine. T o define the meaning of GP programs, we adopt Plotkin’ s method of structura l o perati onal semantics [14]. This appr oach is well established for impera ti ve programming languag es [13] but is no vel in the field of grap h transforma tion. In brief , the method consist s in devis ing inference rules which ind ucti vely define the ef fect of commands on program states. Whereas a classi c state consis ts of the v alues of all progra m varia bles at a ce rtain point in time , the ana logue for graph tra nsformati on is the graph on whi ch the rules of a progra m opera te. As GP is non determin istic, our s emantics a ssigns to a program P and an in put g raph G all gr aphs that can result from exec uting P on G . A special featur e of the semantics is the use of failing computations to define po werful branching and iteration constructs . (Failu re occurs when a set of rule schemata to be exec uted is not applicable to the current graph .) While the conditi ons of branch ing commands in traditi onal programming lan guage s are boo lean ex pressio ns, GP uses arbitrary programs as conditio ns. The ev aluation of a conditio n C succeeds if there exis ts an ex ecutio n of C on the current graph that produ ces a graph . On the other hand, the ev aluation of C is unsuc cessful if all execu tions of C on the curren t graph result in failure. In this case C finitely fails on the current graph. In logic programming, finite fa ilure (of S LD reso lution ) is used to define neg ation [4]. In the case of GP , it allo ws to “hide” destructi ve execut ions of the conditio n C of a statement if C the n P else Q . This is because afte r ev aluating C , the resulting graph is discarded and either P or Q is execu ted on the 28 Semantics of Graph Progra ms graph with which the branching statement was entered . Finite fail ure also allows to eleg antly lift the applic ation of as-long-as -possib le iteratio n from sets of rule schemata (as in [16]) to arbitrary progra ms: the body of a loop can no longer be applied if it finitely fails on the curre nt graph. Control construct s which allo w programmers to write “strate gies” for applyi ng rewri te rules hav e long been present in term-re writing languages such as Elan [2] and Strateg o [3]. These language s allo w recurs i ve definitions of strate gies whereas G P is b ased on a small s et of b uilt-in , non-r ecursi ve con structs . (See [19] for an exte nsion of GP with recursi ve procedures.) Another differe nce between GP and languages such as Elan and Strateg o is that strateg ies in the latter languages rely on the structur e of the objects that they manipul ate, that is, on the tree structu re of terms. In both languages, term-re w rite rules are applied at the root of a term so that tra versal operat ions are needed to apply rules and strate gies deep inside terms. In contrast, the semantics of GP’ s control constr ucts does not depend on the structure of graphs and is complet ely orthogonal to the semantics of rule schemata. This provid es a clear separat ion of concer ns between rules and the control of rules, making it easy to adapt GP’ s semantic s to differe nt formats of rules or graphs. 1 The contri b utions of this paper can be summarised as follo ws: • A graph-tr ansfor mation langu age with simple synta x and semantics, facilitat ing understan ding by progra mmers and formal reasonin g on programs. Our exp erience so far is that very often short and easy to understan d programs can be written to solve problems on graphs (see [15] for variou s small case stud ies). • The first formal operat ional semantics for a graph-t ransfo rmation langua ge (to the best of our kno wledge). W ell-kno wn languages such as AGG [6], Fujaba [12] and GrGen [7] hav e no formal semantic s. The only graph-tran sformatio n lang uage with a complete formal semantics that we are aware of is PROGRES [18]. Its semantics, giv en by Sch ¨ urr in his disserta tion [17], translates progra ms into control-flo w diagrams and consists of m ore than 300 rules (including the definition of the static seman tics) . • A powerfu l branchi ng const ruct based on the concept of finite failure , allo wing to con ve niently exp ress complex destructi ve tests on input graphs. In addition, finite fail ure enables an elegant definitio n of as-lon g-as-p ossible itera tion. These definitions do not depend on the structu re of graphs and can be used for strin g- or term-based rewrit ing languages , too. The rest of this paper is structured as follo ws. The nex t section re views the graph-tra nsformat ion formalism underlying GP , the so-called double-pus hout appro ach with relabelling . Section 3 introdu ces condit ional rule schemata as the buil ding blocks of GP prog rams. In Section 4, we discus s an e xample progra m for graph colourin g and define the abstrac t syntax of graph pro grams. Section 5 presents our formal semantics of GP in the style of stru ctural ope rationa l semantics. In Section 6, we conclude and mention some topics for future work. 2 Graph T ransf ormation W e briefly re view the mode l of graph transfo rmation unde rlying GP , the double-pu shout approa ch with relabe lling [9]. Our presentati on is tailored to GP in that w e consid er graphs ov er a fi xed lab el alphabet, and rules in which only the interf ace may contain unlabelled nodes. GP programs operate o n graphs la belled with seque nces of integ ers a nd string s. (The reason for using sequen ces will become clear in Section 4.) T o formalis e thi s, let Z be the set of integers and Char be a 1 In the extreme, one could ev en replace the underlying formalism of graph-transformation with some other rule-based frame work, such as string or term rewriting. D. Plump & S. Steinert 29 finite set of characters —we may think of Char as the characters that can be typed on a key board. W e fix the label alphab et L = ( Z ∪ Char ∗ ) + consis ting of all nonempty sequ ences made up from intege rs and charac ter strings. A partially labelled g rap h ove r L (or gr aph fo r short) is a system G = ( V G , E G , s G , t G , l G , m G ) , whe re V G and E G are finite sets of nodes (or vertices ) and edge s , s G , t G : E G → V G are the sour ce and tar get functi ons for edges, l G : V G → L is the part ial nod e labell ing functio n and m G : E G → L is the (total) edge labelling functi on. Giv en a node v , w e write l G ( v ) = ⊥ to expre ss that l G ( v ) is undefined. G raph G is totally labelled if l G is a total functio n. The set of all totally labelled graphs o ver L is denote d by G . GP prog rams operate on the graphs in G , unlabell ed nodes occur only in the interf aces of rules (see belo w) and are necessary in the double - pusho ut approach to relabel nodes. There is no need to relabel edges as the y can always be deleted and reinse rted with changed labels. A graph m orphis m g : G → H betwee n graphs G and H consists of two functions g V : V G → V H and g E : E G → E H that preser ve sources, tar gets and labels (that is, s H ◦ g E = g V ◦ s G , t H ◦ g E = g V ◦ t G , m H ◦ g E = m G , and l H ( g ( v )) = l G ( v ) for all v such t hat l G ( v ) 6 = ⊥ ). Morph ism g is an inc lusion if g ( x ) = x for all nodes and edges x . It is injec tive if g V and g E are injecti ve. A rule r = ( L ← K → R ) consis ts of two inclu sions K → L and K → R where L and R are totally labelle d graphs. Graph K is the interface of r . Intuiti vely , an applicat ion of r to a graph will remov e the items in L − K , prese rve K , add the items in R − K , and rela bel the unlabe lled nodes in K . Give n a graph G in G , an injecti ve graph morphis m g : L → G is a m atch for r if it satisfies the dangling condition : no node in g ( L ) − g ( K ) is incident to an edge in G − g ( L ) . In this case G dir ectly derives the graph H in G that is constru cted from G as follo ws: 2 1. Remov e all nod es and edges in g ( L ) − g ( K ) . 2. Add disjoi ntly all nodes and edges from R − K , keeping their labels. For e ∈ E R − E K , s H ( e ) is s R ( e ) if s R ( e ) ∈ V R − V K , otherwise g V ( s R ( e )) . T ar gets are defined analogou sly . 3. For e ach node v in K with l K ( v ) = ⊥ , l H ( g V ( v )) beco mes l R ( v ) . W e write G ⇒ r , g H (or just G ⇒ r H ) if G directly deri ves H as abov e. Figure 1 sho ws an example of a direct deriv ation. T he rule in the upper row is applied to the left graph of the lower ro w , resulting in the right gra ph of the lo wer row . For simplicity , w e do not dep ict edge label s and assume that the y are all the same. The node ident ifiers 1 and 2 in the rule specify the inclus ions of the interf ace. The middle graph of the lower row is an intermediate result (omitted in the abov e constructio n). This diagram represents a double- pusho ut in the cate gory of partiall y labelled graphs ov er L . T o define condition al rules , we equip r ules with predica tes that restric t sets o f matches. A conditiona l rule q = ( r , P ) consists of a rule r and a predicate P on graph morphisms. Giv en totally labelled graphs G , H and a matc h g : L → G for q , we write G ⇒ q , g H (or jus t G ⇒ q H ) if P ( g ) holds and G ⇒ r , g H . For a set of conditio nal rules R , we write G ⇒ R H if there is some q in R su ch that G ⇒ q H . 3 Conditional Rule Schemata A GP progr am is essential ly a list of declarat ions of conditiona l rule schemata togeth er with a command sequen ce for control ling the applicat ion of the sche mata. R ule schemata genera lise rules in that labels can contain expr ession s ov er parameters of type inte ger or string. In this section , we giv e an abstract 2 See [9] for an equi valent definition by graph pushouts. 30 Semantics of Graph Progra ms 1 1 1 1 2 ← 1 2 → 2 1 3 2 ↓ ↓ ↓ 1 1 1 1 ← 1 → 2 3 1 Figure 1: A dir ect deriv ation syntax for the tex tual components of conditiona l rule schemata and interpret them as sets of condition al rules. Figure 2 sho ws an example for the declaratio n of a conditio nal rule schema. It consists of the iden- tifier bridge follo wed by the declaration of formal parame ters, the left and right graphs of the schema which are labelled with expr ession s ov er the parameter s, the node identifiers 1 , 2 , 3 determin ing the interf ace of the schema, and the key word where follo wed by the condition. bridge ( a , b , x , y , z : i nt ) x 1 y 2 z 3 a b ⇒ x 1 y 2 3 z 3 a + b a b where a > = 0 and b > = 0 an d not edge ( 1 , 3 ) Figure 2: A con dition al rule schema In the GP programming system [11], rule schema ta are constructed with a grap hical editor . Figure 3 giv es a grammar in Extend ed Backus -Naur For m for node and edge labels in the left and right gra ph of a rule schema (categ ories LeftLabel and RightLabel). 3 Labels can be sequences of expressi ons sepa- rated by underscor es, as will be demonstrated by E xample 1 in Section 4. W e require that labels in the left graph m ust be simple expres sions because their values at exec ution time are determined by graph matching . All variab le identifiers in the right graph must also occur in the left graph. Every expres sion in ca tego ry Exp has typ e int or str ing , where arit hmetical oper ators ex pect argu ments of type int and the type of va riable identifier s is determined by their declarati ons. The condition of a rule schema is a boole an ex pressi on b uilt from expre ssions of category Exp and the special predicate edge , see Figure 4. Again, all varia ble iden tifiers occurring in the con dition m ust 3 The grammars in Figure 3 and Figure 4 are ambiguou s, we use parentheses to disambiguate expressions where necessary . D. Plump & S. Steinert 31 LeftLabel ::= SimpleExp [’ ’ LeftLabel] RightLabel ::= Exp [’ ’ RightLabel ] SimpleExp ::= [’-’] Num | String | V arId Exp ::= SimpleExp | Exp ArithOp Exp ArithOp ::= ’ + ’ | ’ - ’ | ’ ∗ ’ | ’ / ’ Num ::= Digit { Digit } String ::= ’ ” ’ { Char } ’ ” ’ Figure 3: Syntax of no de and edge labels BoolExp ::= ed ge ’ (’ Node ’, ’ N ode ’)’ | Exp RelOp Exp | not B oolExp | BoolExp BoolOp BoolExp Node ::= Digit { Digit } RelOp ::= ’ = ’ | ’ \= ’ | ’ > ’ | ’ < ’ | ’ >= ’ | ’ <= ’ BoolOp ::= and | or Figure 4: Syntax of cond itions also occur in the left graph of the schema. The predicate edge dema nds the (no n-)e xisten ce of an edge between two nodes in the graph to which the rule schema is applied . For example, the expre ssion not ed ge ( 1 , 3 ) in th e condition of Figure 2 forb ids an edge from node 1 to no de 3 when the lef t graph is matched. W e interpret a conditio nal rule schema as the (pos sibly infinite) set of conditio nal rules that is ob- tained by instanti ating vari ables with an y v alues and ev aluatin g expressi ons. T o define this , consider a declar ation D of a condition al rule-sche ma. L et L and R be the left and right graphs of D , and c the condit ion. W e w rite V ar ( D ) for the set of variab le identifiers occurring in D . Giv en x in V ar ( D ) , type ( x ) denote s the type associate d with x . An assignment is a mapping α : V ar ( D ) → ( Z ∪ Char ∗ ) such that for each x in V ar ( D ) , type ( x ) = i nt implie s α ( x ) ∈ Z , and type ( x ) = string implies α ( x ) ∈ C har ∗ . Giv en a label l of categ ory RightLabel occur ing in D and an assignment α , the va lue l α ∈ L is induct i vel y defined. If l is a numeral or a sequence of charact ers, then l α is th e inte ger or c haract er string repres ented by l (which is independen t of α ). If l is a variab le identifier , then l α = α ( l ) . O therwise, l α is obtained from the v alues of l ’ s components. If l has the form e 1 ⊕ e 2 with ⊕ in ArithOp and e 1 , e 2 in Exp, then l α = e α 1 ⊕ Z e α 2 where ⊕ Z is the integ er oper ation represen ted by ⊕ . 4 If l has the form e m with e in Exp and m in RightLabel, then l α = e α m α (the concate nation of e α and m α ). Note tha t our definition of l α cov ers all labels in D since LeftLabel is a subcateg ory of R ightLabe l. The val ue of the condition c in D not only depends on an assignment b ut also on a graph morphism. For , if c conta ins the predicate ed ge , we need to con sider the structure of the graph to which we want to apply the rule schema. Consider an assignmen t α and let L α be obta ined from L by replacing each label l with l α . Let g : L α → G be a graph morphism with G ∈ G . Then for each Boolean sube xpression b of c , the val ue b α , g in B = { tt , ff } is inducti vely defined. If b has the form e 1 ⊲ ⊳ e 2 with ⊲ ⊳ in R elOp and e 1 , e 2 in Exp, then b α , g = tt if and onl y if e α 1 ⊲ ⊳ Z e α 2 where ⊲ ⊳ Z is the rel ation on intege rs represen ted by 4 For simplicity , we consider division by zero as an implementation-le vel issue. 32 Semantics of Graph Progra ms ⊲ ⊳ . If b has the form no t b 1 with b 1 in BoolExp, then b α , g = tt if and only if b α , g 1 = ff . If b has the form b 1 ⊕ b 2 with ⊕ in BoolOp and b 1 , b 2 in Bool Exp, then b α , g = b α , g 1 ⊕ B b α , g 2 where ⊕ B is th e Boole an operat ion on B represen ted by ⊕ . A special case is gi ven if b has the form edge ( v , w ) where v , w are identi fiers of inter face nodes in D . W e then hav e b α , g = tt if there is an edge from g ( v ) to g ( w ) , ff otherwis e. Let now r be the rule-sch ema identifier associated with declarati on D . For ev ery assignment α , let r α = ( L α ← K → R α , P α ) be the con dition al rule giv en as follo ws: • L α and R α are obtaine d from L and R by replaci ng each label l with l α . • K is the disc rete subgraph of L and R determined by the node iden tifiers for the interfac e, where all node s are unlabelled . • P α is defined by: P α ( g ) if and only if g is a graph morphism L α → G such that G ∈ G and c α , g = tt . The interpr etation of r is the rule set I ( r ) = { r α | α is an assi gnment } . Fo r notationa l con ven ience, we sometimes denote the relation ⇒ I ( r ) by ⇒ r . Note tha t I ( r ) is a (possibly infinite) set of condit ional rules in the sense of S ection 2, groun ding rule schemata in the theory of the double- pusho ut approach with relabe lling [9]. For exa mple, the upper ro ws of Figure 5 sho w the rule schema brid ge of Figure 2 (without con- dition ) and its instanc e bri dge α , w here α ( x ) = 0, α ( y ) = α ( z ) = 1, α ( a ) = 3 and α ( b ) = 2. The condit ion c of bri dge e v aluate s to the predica te P α which is true for a match g of the left-han d graph if and only if there is no edge from g ( 1 ) to g ( 3 ) . (The sube xpress ions a > = 0 and b > = 0 e valuat e to tt and hence can be ignored.) The lower rows of Figure 5 sho w an applicatio n of br idge α by a graph morphism satisfyi ng P α . Schema: x 1 y 2 z 3 a b ⇒ x 1 y 2 z 3 a b a + b ↓ α ↓ α Instan ce: 0 1 1 2 1 3 3 2 ⇒ 0 1 1 2 1 3 3 2 5 ↓ ↓ 0 1 2 1 3 2 0 1 ⇒ 0 1 2 1 3 2 5 0 1 Figure 5: Applic ation of a rule schema using instantiatio n D. Plump & S. Steinert 33 4 Graph Pr og rams W e start by discussin g an example progra m for graph colo uring. Example 1 (Computing a 2-colourin g) . A colour ing for a graph is an assignment of colours (inte gers) to nodes such that the source and targ et of each edge ha ve dif ferent colours. A graph is 2-colo ura ble (or bipa rtite ) if it possesses a colouring with at m ost two colour s. The prog ram 2-colo uring in Fig- ure 6 generate s a 2-colourin g for nonempty , connected input graphs without loops if such a colou ring exi sts—othe rwise the inpu t grap h is returned . The prog ram consis ts of fiv e rule-schema decl aration s, the macr o colo ur representin g the r ule-sch ema set { col our1 , colou r2 } , and th e ma in command sequence follo wing the key word main . main = c hoose; colour!; if illegal then undo! colour = { colo ur1 , colour2 } choose ( x : int ) illegal ( a , i , x , y : int ) 1 x ⇒ 1 x 0 x i y i 1 2 a ⇒ x i y i 1 2 a colour1 ( a , i , x , y : int ) undo ( i , x : in t ) x i y 1 2 a ⇒ x i y 1 − i 1 2 a 1 x i ⇒ 1 x colour2 ( a , i , x , y : int ) x i y 1 2 a ⇒ x i y 1 − i 1 2 a Figure 6: The prog ram 2-col ouring Giv en an integ er -labelled input graph, the program first uses the rule schema ch oose to pick any node and replac e its label x with x 0. The underscor e opera tor allo ws to add a tag to a label, use d here to add colours to labels. In general, a tagged label consists of a sequen ce of expressio ns join ed by unders cores. After the first node has been coloure d, the command col our! applies the rule schemata colour1 and col our2 nondete rministic ally as long as poss ible to colo ur all remainin g node s. In each iterati on of the loop, an un colour ed node adjacen t to an already colou red node v gets th e colour in { 0 , 1 } that is complementar y to v ’ s colour . If the input graph is connected, the graph resulting from c olour! is correctl y coloured if and only if the rule schema illeg al is not applicable. The latter is checke d by the if-state ment. If il legal is applicable, then the input must contain an undirect ed cyc le of odd length and hence is not 2-c oloura ble (see for e xample [10]). In this cas e the loop undo! remov es al l tags to return the inpu t graph unmodified. Note that the number of rule-schema applica tions performed by 2-colour ing is linear in the number of input nodes. T o make 2-c olouring applicabl e to graphs that are possib ly empty or disconn ected, we can insert 34 Semantics of Graph Progra ms a nested loop: main = (choose; colour! )!; if illegal then undo! . No w if the input graph is empty , choo se fails which causes the outer loop to terminate and return the curren t (empty) graph. On the other hand, if the input consists of sev eral connected components, the body of the outer loop is repeat edly called to colou r each component. Figure 7 sho ws the abstract s yntax o f GP programs. 5 A pr ogram c onsist s of a numb er of declar ations of co nditio nal rule s chemata an d macro s, and e xactly o ne de clarati on of a main comman d seq uence. The rule-sc hema iden tifiers ( cate gory RuleId) oc curring in a call of categor y RuleSet Call refer t o declara tions of conditio nal rule schemata in catego ry RuleDec l (see S ection 3). Semanticall y , each rule-sch ema identi fier r sta nds for the set I ( r ) of conditiona l rule s induce d by that identifier . A call of the form { r 1 , . . . , r n } stan ds for the union S n i = 1 I ( r i ) . Prog ::= Decl { Decl } Decl ::= RuleDecl | MacroDecl | MainDecl MacroDecl ::= MacroId ’=’ ComSeq MainDecl ::= main ’=’ ComSeq ComSeq ::= Com { ’;’ Com } Com ::= RuleSetCall | MacroCall | if ComSeq then ComS eq [ else ComSeq] | ComSeq ’!’ | skip | f ail RuleSetCall ::= RuleId | ’ { ’ [RuleId { ’, ’ R uleId } ] ’ } ’ MacroCall ::= MacroId Figure 7: Abstra ct syntax of GP Macros are a simple means to structu re programs and thereb y to mak e them more readable. Every progra m can be tran sformed into an equi valent macro-free program by replacing macro calls with their associ ated command seque nces (recur si ve macros are not allo wed). In the next section we use the terms “progr am” and “command sequ ence” synonymo usly , assuming that all macro calls hav e been replac ed. The commands skip and fail can be expr essed through the other commands (see next section), hence the core of GP include s on ly the ca ll of a set of conditi onal ru le schemata (RuleSetCall), se quent ial composi tion (’;’), the if-th en-else statement and as-long-as- possib le iteration (’!’). 5 Semantics of Graph Pr ograms W e present a formal semantics of GP in the style of Plotki n’ s structura l operatio nal seman tics [14]. As usual for this approach , inference rules inducti vely define a small-ste p transitio n relation → on configu- rat ions . In our setting, a configur ation is either a command seque nce togethe r with a graph, just a graph or the special element fail : → ⊆ ( ComSeq × G ) × (( ComSeq × G ) ∪ G ∪ { fail } ) . 5 Where necessary we use parentheses to disambiguate programs. D. Plump & S. Steinert 35 Configurati ons in ComSeq × G represe nt unfinished c omputat ions, giv en by a res t pro gram and a stat e in the form of a graph, while graphs in G are proper res ults of computatio ns. In addition, the element fail repres ents a fail ure state. A configurati on γ is termina l if there is no configuration δ such that γ → δ . Each infere nce rule in F igure 8 consists of a premise and a conclusion separated by a horizont al bar . Both parts contain meta-var iables for command sequences and graphs, where R stands for a call in cate gory RuleSetCall, C , P , P ′ , Q stand for command sequen ces in categor y C omSeq and G , H stand for graphs in G . Gi ven a rule-set call R , let I ( R ) = S { I ( r ) | r is a rule-schema identifier in R } (see Section 3 for the definition of I ( r ) ). T he domain of ⇒ I ( R ) , denoted by D om ( ⇒ I ( R ) ) , is the set of all graphs G in G such that G ⇒ I ( R ) H for some graph H . M eta-v ariables are consid ered to be uni versa lly quanti fied. For example, the rule [ Call 1 ] should be read as: “For all R in RuleSetCall and all G , H in G , G ⇒ I ( R ) H implies h R , G i → H . ” Figure 8 sho ws the inference rules for the core constr ucts of GP . W e w rite → + and → ∗ for the transit i ve and reflexi ve-tr ansiti ve closures of → . A command sequ ence C finitely fails on a grap h G ∈ G if (1) there does not exist an infinite sequence h C , G i → h C 1 , G 1 i → . . . an d (2) for each terminal configura tion γ such that h C , G i → ∗ γ , γ = f ail. In other words, C fi nitely fails on G if all computations startin g from ( C , G ) ev entua lly end in the configuration fail. [ Call 1 ] G ⇒ I ( R ) H h R , G i → H [ Call 2 ] G 6∈ Dom ( ⇒ I ( R ) ) h R , G i → f ail [ Seq 1 ] h P , G i → h P ′ , H i h P ; Q , G i → h P ′ ; Q , H i [ Seq 2 ] h P , G i → H h P ; Q , G i → h Q , H i [ Seq 3 ] h P , G i → fail h P ; Q , G i → f ail [ If 1 ] h C , G i → + H h if C then P else Q , G i → h P , G i [ If 2 ] C fi nitely fa ils on G h if C then P else Q , G i → h Q , G i [ Alap 1 ] h P , G i → + H h P ! , G i → h P ! , H i [ Alap 2 ] P finitely fails on G h P ! , G i → G Figure 8: Infe rence rules for core commands The concept of finite failure stems from logic programming where it is used to define ne gation as failur e [4]. In the case of G P , we use it to define po werful branchin g and ite ration const ructs. In particu lar , our definition of the if-then- else command allows to “hid e” destructi ve tests. Example 2 (Recognizing series-par allel graph s) . A graph is series-p ara llel if it reduces to a graph con- sisting of two nodes and an edge between them by the followin g two operations [1, 5]: (1) R eplace a pair of paral lel edges by an edge from their source to their targ et. (2) Giv en a node v with exactly one incoming edge e 1 and exa ctly one outgoin g edge e 2 such that the source of e 1 and the tar get of e 2 are distin ct, replace e 1 , e 2 and v by an edge from the source of e 1 to the tar get of e 2 . Suppose that w e want to check w hether a connec ted, integer -labelled graph G is series-pa rallel and, depen ding on the result, exec ute either a program P or a progr am Q on G . W e can do this with the progra m main = i f { par , seq } !; base th en P else Q whose rul e schemata p ar , seq and base are sho wn in Figure 9. The sub progra m { par , seq } ! appl ies 36 Semantics of Graph Progra ms as long as possibl e the operati ons (1) and (2) to the input graph G , then the rule schema ba se checks if the resu lting grap h consists of two nodes conn ected by an edge. Graph G is series-parall el if and only if base is applicabl e to the reduced graph. (Note that { par , seq } ! pr eserv es con nected ness and that, by the dangling condition, base is applicab le only if the images of its left-hand nodes hav e deg ree one.) It is important to not e that by the inference rules [ If 1 ] and [ If 2 ] , the main progra m ex ecutes P or Q on the input grap h G whereas the graph resulting from the test is discarde d. par ( a , b , x , y : int ) x y 1 2 a b ⇒ x y 1 2 0 seq ( a , b , x , y , z : i nt ) x y z 1 2 a b ⇒ x z 1 2 0 base ( a , x , y : int ) x y a ⇒ / 0 Figure 9: Rule sch emata for recognizin g series-pa rallel graphs The meaning of the remain ing G P commands is defined in terms of the m eaning of the core com- mands, see Figure 10. W e refer to these commands as derived commands. [ Skip ] h skip , G i → h r , G i where r is an iden tifier for the rule schema / 0 ⇒ / 0 [[ Fail ] h fail , G i → h{} , G i [ If 3 ] h if C then P , G i → h if C t hen P else skip , G i Figure 10: Inf erence rules for deri ved commands W e can now summaris e the meaning of GP programs by a semantic functio n J K which ass igns to each progr am P the functio n J P K map ping an input graph G to t he set of al l possib le results of running P on G . The result se t may con tain, beside s proper result s in the for m of grap hs, the spe cial v alue ⊥ which indica tes a nonterminat ing or stuck comput ation. T he se mantic functi on J K : ComSeq → ( G → 2 G ∪{⊥} ) is defined by 6 J P K G = { H ∈ G | h P , G i + → H } ∪ {⊥ | P can di ver ge or get stuck from G } where P can diver ge fr om G if there is an infinite sequence h P , G i → h P 1 , G 1 i → h P 2 , G 2 i → . . . , and P can get stuc k fr om G if there is a terminal configuratio n h Q , H i s uch that h P , G i → ∗ h Q , H i . 6 W e write J P K G for the a pplication of J P K to a graph G . D. Plump & S. Steinert 37 Note that J P K G = / 0 if and only if P finitely fail s on G . In Example 2, for instance , we hav e J { par , seq } !; base K G = / 0 for ev ery connected graph G containin g a cy cle. This is bec ause the graph resulti ng from { par , seq } ! i s still connecte d and cyclic, so the rule schema base is not applica ble. A pr ogram can get stu ck on ly in two si tuatio ns: either it contains a subpro gram if C then P else Q where C both can di ver ge from so me g raph an d can not pro duce a proper r esult fro m th at gra ph, or it c on- tains a subp rogram B ! where the loop ’ s body B posse sses the said property of C . The e v aluation of these subpro grams will get stuck beca use the inference rules for branching and iteration are not applicabl e. 6 Conclusion GP is an e xperimen tal rule-based language for high-le ve l probl em solving in the domain of graphs, freeing programmers from handling lo w-lev el data structure s. The hallmark of GP is syntactic and semantic simplicity . Conditio nal rule schemata for graph transformati on allow to expres s applic ation condit ions and co mputatio ns on labels , in addi tion to structura l changes. The se mantics of rule sc hemata is orthog onal to the semantics of control constru cts, makin g it easy to change the format of rules or graphs . The operatio nal semantics of programs describes the effe ct of G P’ s control constructs in a natural way and captures the nondeter minism of the langu age. In particula r , powerf ul branchi ng and iterati on commands hav e been defined using the concept of finite fa ilure. Destr ucti ve tests on the current graph can be hi dden in the co nditio n of the br anchin g command, and nested loops can b e coded sinc e arbitrary subpro grams can be iterat ed as long as possible. Future exten sions o f GP may include rec ursi ve pro cedure s for writing complex algorithms ( see [19]), and a type concept for restric ting the shape of graphs. Our goal is to support formal reason ing on graph progra ms by de velopin g static analyses for properties such as t erminatio n and confluen ce (unique ness of results ), and a calculus and tool support for program verificatio n. Refer ences [1] Jørgen Bang-Jensen and Gregory Gutin. Digr aphs: The ory , Algorithms and Applica tions . Springer-V erlag, 2000. [2] Peter Borovansk ´ y, Claude Kirchner, H ´ e l ` ene Kirchner, an d Pierre-Etien ne Moreau. ELAN from a rewriting logic point of view . Theo r etica l Computer Science , 285(2):155 –185 , 2 002. [3] Martin Bravenboer , Arth ur van Dam, Karina Olmos, a nd Eelco V isser . Pr ogram transform ation with scoped dynamic rewrite ru les. Fun damenta Informaticae , 69(1–2):12 3–17 8, 20 06. [4] K eith L. Clark. Negation as failure. In Herve Gallaire and Jack Minker, editors, Logic and Data Bases , pag es 293–3 22. Plen um Press, 1978. [5] R. J. Duffin. T opolog y of series-parallel n etworks. Journal of Mathema tical Analysis a nd App lications , 10:303 –318 , 1965. [6] Claudia Er mel, Michael Rudolf, a nd Gabi T aentzer . The A GG approach: Language and environment. In H. Ehrig, G. Engels, H.-J. Kreowski, and G. Rozenb erg, ed itors, Hand book o f Graph Grammars and Com- puting by Graph T ransformation , volume 2, chapter 14, pages 551–603 . W orld Scien tific, 1999. [7] Rubino Geiß , Gerno t V eit Batz, Daniel Gr und, Sebastian Hack, an d Ada m M. Szalkowski. GrGen : A fast SPO-based gr aph rewriting tool. In Pr o c. Interna tional Confer en ce on Graph T ransformation ( ICGT 2006 ) , volume 4178 of Lectur e Notes in Computer Science , pages 383–3 97. Spr inger-V erlag, 2006. 38 Semantics of Graph Progra ms [8] Annegret Habel and Detlef Plump. Compu tational completeness of prog ramming languages based on graph transform ation. In Pr oc. F oundations of So ftwar e Science and Computation Structur es (FOS SACS 20 01) , volume 2030 of Lectur e Notes in Computer Science , pages 230–2 45. Spr inger-V erlag, 2001. [9] Annegret Habel and Detlef Plump. Relabelling in graph transform ation. In Pr o c. Internation al Conference on Graph T ransformation (ICGT 2002) , volume 25 05 of Lectur e Notes in Computer Scie nce , pag es 135– 147. Springer-V erlag, 200 2. [10] Jon Kleinberg and ´ Eva T ardos. Algorithm Design . Add ison W esley , 200 6. [11] Greg Manning and Detlef Plump . Th e GP prog ramming system. In Pr oc. Graph T ransformation and V isual Modelling T echniques (GT -VMT 2008 ) , v olum e 10 of Electr onic Communicatio ns of the EA SST , 2008. [12] Ulrich Nickel, J ¨ org Niere, and Alber t Z ¨ u ndorf . The FUJ AB A environment. In Pr oc. Interna tional Confer ence on Softwar e Engineering (ICSE 2000) , pages 742–74 5. ACM Press, 2 000. [13] Hanne Riis Nielson and Flem ming Nielson. Sema ntics with Applicatio ns: An Ap petizer . Spring er-V erlag , 2007. [14] Gordon D. Plotkin. A structural app roach to operational semantics. Journal of Logic and A lgebraic Pr o - gramming , 60–61:17 –139 , 2 004. [15] Detlef Plump. The graph prog ramming lang uage GP. In Pr oc. Algebraic I nformatics (CAI 2009 ) , volume 5725 of Lectur e Notes in Computer Science , pages 99–122 . Spr inger-V erlag, 2009. [16] Detlef Plu mp and San dra Steiner t. T ow ards grap h pro grams fo r gra ph algo rithms. In Pr oc. Interna tional Confer e nce on Gr aph T ransformation (ICGT 2004) , volume 3256 of Lectur e Notes in Computer Science , pages 128– 143. S pringer-V erlag, 200 4. [17] Andy Sch ¨ urr . Op erationales Spezifizieren mit pr ogrammierten Graphersetzungssystemen . De utscher Uni ver- sit ¨ a ts-V erlag, 1991. In German. [18] Andy Sch ¨ urr , And reas W inter, an d Albert Z ¨ undo rf. The PR OGRES approac h: Langu age and environment. In H. Ehrig, G. En gels, H. -J. Kreowski, an d G. Rozenberg, editors, Handb ook of Graph Grammars and Computing by Graph T ransformation , volume 2, chapter 13, pages 487–55 0. W or ld Scientific, 1999. [19] Sandra Steinert. The Graph Pr ogramming Language GP . Ph D thesis, The Univ ersity of Y or k, 2007.
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment