The Semantics of Graph Programs



Similar documents
Virtual Machine. Part II: Program Control. Building a Modern Computer From First Principles.

Regular Sets and Expressions

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

Protocol Analysis / Analysis of Software Artifacts Kevin Bierhoff

Homework 3 Solutions

Modular Generic Verification of LTL Properties for Aspects

Hillsborough Township Public Schools Mathematics Department Computer Programming 1

4.11 Inner Product Spaces

FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

Reasoning to Solve Equations and Inequalities

All pay auctions with certain and uncertain prizes a comment

On decidability of LTL model checking for process rewrite systems

Network Configuration Independence Mechanism

JaERM Software-as-a-Solution Package

Babylonian Method of Computing the Square Root: Justifications Based on Fuzzy Techniques and on Computational Complexity

Basic Analysis of Autarky and Free Trade Models

5.2. LINE INTEGRALS 265. Let us quickly review the kind of integrals we have studied so far before we introduce a new one.

Graphs on Logarithmic and Semilogarithmic Paper

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

Section 7-4 Translation of Axes

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

Integration. 148 Chapter 7 Integration

MODULE 3. 0, y = 0 for all y

Operations with Polynomials

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall Final Exam

Concept Formation Using Graph Grammars

Experiment 6: Friction

and thus, they are similar. If k = 3 then the Jordan form of both matrices is

Lecture 3 Gaussian Probability Distribution

Example 27.1 Draw a Venn diagram to show the relationship between counting numbers, whole numbers, integers, and rational numbers.

MATH 150 HOMEWORK 4 SOLUTIONS

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

Math 135 Circles and Completing the Square Examples

Decision Rule Extraction from Trained Neural Networks Using Rough Sets

Java CUP. Java CUP Specifications. User Code Additions You may define Java code to be included within the generated parser:

Vectors Recap of vectors

Regular Languages and Finite Automata

Source Code verification Using Logiscope and CodeReducer. Christophe Peron Principal Consultant Kalimetrix

Module Summary Sheets. C3, Methods for Advanced Mathematics (Version B reference to new book) Topic 2: Natural Logarithms and Exponentials

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

SPECIAL PRODUCTS AND FACTORIZATION

Factoring Polynomials

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

AntiSpyware Enterprise Module 8.5

Warm-up for Differential Calculus

Model Checking for Software Architectures

In-circuit temporal monitors for runtime verification of reconfigurable designs

Small Business Cloud Services

Vendor Rating for Service Desk Selection

Space Vector Pulse Width Modulation Based Induction Motor with V/F Control

Algebra Review. How well do you remember your algebra?

6.2 Volumes of Revolution: The Disk Method

An Undergraduate Curriculum Evaluation with the Analytic Hierarchy Process

Physics 43 Homework Set 9 Chapter 40 Key

Drawing Diagrams From Labelled Graphs

Engineer-to-Engineer Note

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

Assumption Generation for Software Component Verification

ClearPeaks Customer Care Guide. Business as Usual (BaU) Services Peace of mind for your BI Investment

Or more simply put, when adding or subtracting quantities, their uncertainties add.

Section 5.2, Commands for Configuring ISDN Protocols. Section 5.3, Configuring ISDN Signaling. Section 5.4, Configuring ISDN LAPD and Call Control

A.7.1 Trigonometric interpretation of dot product A.7.2 Geometric interpretation of dot product

g(y(a), y(b)) = o, B a y(a)+b b y(b)=c, Boundary Value Problems Lecture Notes to Accompany

2 DIODE CLIPPING and CLAMPING CIRCUITS

trademark and symbol guidelines FOR CORPORATE STATIONARY APPLICATIONS reviewed

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Second Term MAT2060B 1. Supplementary Notes 3 Interchange of Differentiation and Integration

EQUATIONS OF LINES AND PLANES

One Minute To Learn Programming: Finite Automata

9 CONTINUOUS DISTRIBUTIONS

Lectures 8 and 9 1 Rectangular waveguides

Database-Backed Program Analysis for Scalable Error Propagation

flex Regular Expressions and Lexical Scanning Regular Expressions and flex Examples on Alphabet A = {a,b} (Standard) Regular Expressions on Alphabet A


DlNBVRGH + Sickness Absence Monitoring Report. Executive of the Council. Purpose of report

COMPONENTS: COMBINED LOADING

Novel Methods of Generating Self-Invertible Matrix for Hill Cipher Algorithm

Value Function Approximation using Multiple Aggregation for Multiattribute Resource Management

ASG Techniques of Adaptivity

P.3 Polynomials and Factoring. P.3 an 1. Polynomial STUDY TIP. Example 1 Writing Polynomials in Standard Form. What you should learn

Binary Representation of Numbers Autar Kaw

On the Robustness of Most Probable Explanations

FUNCTIONS AND EQUATIONS. xεs. The simplest way to represent a set is by listing its members. We use the notation

5 a LAN 6 a gateway 7 a modem

Orthogonally modeling video structuration and annotation: exploiting the concept of granularity

Generating In-Line Monitors For Rabin Automata

Small Business Networking

Small Business Networking

SyGEMe: Integrated Municipal Facilities Management of Water Ressources Swiss Geoscience Meeting, Neuchâtel, 21 novembre 2009 k

Understanding Basic Analog Ideal Op Amps

Unambiguous Recognizable Two-dimensional Languages

Chapter 6. Logic and Action. 6.1 Actions in General

ORBITAL MANEUVERS USING LOW-THRUST

Learning Workflow Petri Nets

Online Multicommodity Routing with Time Windows

Small Business Networking

CHAPTER 11 Numerical Differentiation and Integration

e.g. f(x) = x domain x 0 (cannot find the square root of negative values)

Automated Grading of DFA Constructions

Transcription:

The Semntics of Grph Progrms Detlef Plump Deprtment of Computer Science The University of York, UK Sndr Steinert Deprtment of Computer Science The University of York, UK GP (for Grph Progrms) is rule-bsed, nondeterministic progrmming lnguge for solving grph problems t high level of bstrction, freeing progrmmers from hndling low-level dt structures. The core of GP consists of four constructs: single-step ppliction of set of conditionl grphtrnsformtion rules, sequentil composition, brnching nd itertion. We present forml semntics for GP in the style of structurl opertionl semntics. A specil feture of our semntics is the use of finitely filing progrms to define GP s powerful brnching nd itertion commnds. Introduction This pper defines the semntics of GP, n experimentl nondeterministic progrmming lnguge for high-level problem solving in the domin of grphs. The lnguge is bsed on conditionl rule schemt for grph trnsformtion (introduced in [6]) nd thereby frees progrmmers from hndling low-level dt structures for grphs. The prototype implementtion of GP compiles grph progrms into bytecode for the York bstrct mchine, nd comes with grphicl editor for progrms nd grphs []. GP hs simple syntx s its core contins only four commnds: single-step ppliction of set of rule schemt, sequentil composition, brnching nd s-long-s-possible itertion. Despite its simplicity, GP is computtionlly complete in tht every computble function on grphs cn be progrmmed [8]. A mjor gol of the GP project is the development of prcticl grph-trnsformtion lnguge tht comes with concise forml semntics, to fcilitte progrm verifiction nd other forml resoning on progrms. Also, forml semntics provides implementors with rigorous definition of the lnguge tht does not depend on compiler or mchine. To define the mening of GP progrms, we dopt Plotkin s method of structurl opertionl semntics [4]. This pproch is well estblished for impertive progrmming lnguges [3] but is novel in the field of grph trnsformtion. In brief, the method consists in devising inference rules which inductively define the effect of commnds on progrm sttes. Wheres clssic stte consists of the vlues of ll progrm vribles t certin point in time, the nlogue for grph trnsformtion is the grph on which the rules of progrm operte. As GP is nondeterministic, our semntics ssigns to progrm P nd n input grph G ll grphs tht cn result from executing P on G. A specil feture of the semntics is the use of filing computtions to define powerful brnching nd itertion constructs. (Filure occurs when set of rule schemt to be executed is not pplicble to the current grph.) While the conditions of brnching commnds in trditionl progrmming lnguges re boolen expressions, GP uses rbitrry progrms s conditions. The evlution of condition C succeeds if there exists n execution of C on the current grph tht produces grph. On the other hnd, the evlution of C is unsuccessful if ll executions of C on the current grph result in filure. In this cse C finitely fils on the current grph. In logic progrmming, finite filure (of SLD resolution) is used to define negtion [4]. In the cse of GP, it llows to hide destructive executions of the condition C of sttement if C then Pelse Q. This is becuse fter evluting C, the resulting grph is discrded nd either P or Q is executed on the I. Mckie nd A. Mrtins Moreir (Eds.): Tenth Interntionl Workshop on Rule-Bsed Progrmming (RULE 009) EPTCS, 00, pp. 7 38, doi:0.404/eptcs..3 c D. Plump & S. Steinert

8 Semntics of Grph Progrms grph with which the brnching sttement ws entered. Finite filure lso llows to elegntly lift the ppliction of s-long-s-possible itertion from sets of rule schemt (s in [6]) to rbitrry progrms: the body of loop cn no longer be pplied if it finitely fils on the current grph. Control constructs which llow progrmmers to write strtegies for pplying rewrite rules hve long been present in term-rewriting lnguges such s Eln [] nd Strtego [3]. These lnguges llow recursive definitions of strtegies wheres GP is bsed on smll set of built-in, non-recursive constructs. (See [9] for n extension of GP with recursive procedures.) Another difference between GP nd lnguges such s Eln nd Strtego is tht strtegies in the ltter lnguges rely on the structure of the objects tht they mnipulte, tht is, on the tree structure of terms. In both lnguges, term-rewrite rules re pplied t the root of term so tht trversl opertions re needed to pply rules nd strtegies deep inside terms. In contrst, the semntics of GP s control constructs does not depend on the structure of grphs nd is completely orthogonl to the semntics of rule schemt. This provides cler seprtion of concerns between rules nd the control of rules, mking it esy to dpt GP s semntics to different formts of rules or grphs. The contributions of this pper cn be summrised s follows: A grph-trnsformtion lnguge with simple syntx nd semntics, fcilitting understnding by progrmmers nd forml resoning on progrms. Our experience so fr is tht very often short nd esy to understnd progrms cn be written to solve problems on grphs (see [5] for vrious smll cse studies). The first forml opertionl semntics for grph-trnsformtion lnguge (to the best of our knowledge). Well-known lnguges such s AGG [6], Fujb [] nd GrGen [7] hve no forml semntics. The only grph-trnsformtion lnguge with complete forml semntics tht we re wre of is PROGRES [8]. Its semntics, given by Schürr in his disserttion [7], trnsltes progrms into control-flow digrms nd consists of more thn 300 rules (including the definition of the sttic semntics). A powerful brnching construct bsed on the concept of finite filure, llowing to conveniently express complex destructive tests on input grphs. In ddition, finite filure enbles n elegnt definition of s-long-s-possible itertion. These definitions do not depend on the structure of grphs nd cn be used for string- or term-bsed rewriting lnguges, too. The rest of this pper is structured s follows. The next section reviews the grph-trnsformtion formlism underlying GP, the so-clled double-pushout pproch with relbelling. Section 3 introduces conditionl rule schemt s the building blocks of GP progrms. In Section 4, we discuss n exmple progrm for grph colouring nd define the bstrct syntx of grph progrms. Section 5 presents our forml semntics of GP in the style of structurl opertionl semntics. In Section 6, we conclude nd mention some topics for future work. Grph Trnsformtion We briefly review the model of grph trnsformtion underlying GP, the double-pushout pproch with relbelling [9]. Our presenttion is tilored to GP in tht we consider grphs over fixed lbel lphbet, nd rules in which only the interfce my contin unlbelled nodes. GP progrms operte on grphs lbelled with sequences of integers nd strings. (The reson for using sequences will become cler in Section 4.) To formlise this, let Z be the set of integers nd Chr be In the extreme, one could even replce the underlying formlism of grph-trnsformtion with some other rule-bsed frmework, such s string or term rewriting.

D. Plump & S. Steinert 9 finite set of chrcters we my think of Chr s the chrcters tht cn be typed on keybord. We fix the lbel lphbet L =(Z Chr ) + consisting of ll nonempty sequences mde up from integers nd chrcter strings. A prtilly lbelled grph over L (or grph for short) is system G=(V G,E G,s G,t G,l G,m G ), where V G nd E G re finite sets of nodes (or vertices) nd edges, s G,t G : E G V G re the source nd trget functions for edges, l G : V G L is the prtil node lbelling function nd m G : E G L is the (totl) edge lbelling function. Given node v, we write l G (v)= to express tht l G (v) is undefined. Grph G is totlly lbelled if l G is totl function. The set of ll totlly lbelled grphs over L is denoted by G. GP progrms operte on the grphs in G, unlbelled nodes occur only in the interfces of rules (see below) nd re necessry in the doublepushout pproch to relbel nodes. There is no need to relbel edges s they cn lwys be deleted nd reinserted with chnged lbels. A grph morphism g: G H between grphs G nd H consists of two functions g V : V G V H nd g E : E G E H tht preserve sources, trgets nd lbels (tht is, s H g E = g V s G, t H g E = g V t G, m H g E = m G, nd l H (g(v))=l G (v) for ll v such tht l G (v) ). Morphism g is n inclusion if g(x)= x for ll nodes nd edges x. It is injective if g V nd g E re injective. A rule r = (L K R) consists of two inclusions K L nd K R where L nd R re totlly lbelled grphs. Grph K is the interfce of r. Intuitively, n ppliction of r to grph will remove the items in L K, preserve K, dd the items in R K, nd relbel the unlbelled nodes in K. Given grph G in G, n injective grph morphism g: L G is mtch for r if it stisfies the dngling condition: no node in g(l) g(k) is incident to n edge in G g(l). In this cse G directly derives the grph H in G tht is constructed from G s follows:. Remove ll nodes nd edges in g(l) g(k).. Add disjointly ll nodes nd edges from R K, keeping their lbels. 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)). Trgets re defined nlogously. 3. For ech node v in K with l K (v)=, l H (g V (v)) becomes l R (v). We write G r,g H (or just G r H) if G directly derives H s bove. Figure shows n exmple of direct derivtion. The rule in the upper row is pplied to the left grph of the lower row, resulting in the right grph of the lower row. For simplicity, we do not depict edge lbels nd ssume tht they re ll the sme. The node identifiers nd in the rule specify the inclusions of the interfce. The middle grph of the lower row is n intermedite result (omitted in the bove construction). This digrm represents double-pushout in the ctegory of prtilly lbelled grphs over L. To define conditionl rules, we equip rules with predictes tht restrict sets of mtches. A conditionl rule q=(r,p) consists of rule r nd predicte P on grph morphisms. Given totlly lbelled grphs G, H nd mtch g: L Gfor q, we write G q,g H (or just G q H) if P(g) holds nd G r,g H. For set of conditionl rules R, we write G R H if there is some q in R such tht G q H. 3 Conditionl Rule Schemt A GP progrm is essentilly list of declrtions of conditionl rule schemt together with commnd sequence for controlling the ppliction of the schemt. Rule schemt generlise rules in tht lbels cn contin expressions over prmeters of type integer or string. In this section, we give n bstrct See [9] for n equivlent definition by grph pushouts.

30 Semntics of Grph Progrms 3 3 Figure : A direct derivtion syntx for the textul components of conditionl rule schemt nd interpret them s sets of conditionl rules. Figure shows n exmple for the declrtion of conditionl rule schem. It consists of the identifier bridge followed by the declrtion of forml prmeters, the left nd right grphs of the schem which re lbelled with expressions over the prmeters, the node identifiers,, 3 determining the interfce of the schem, nd the keyword where followed by the condition. bridge(,b,x,y,z: int) +b x y b z x y b z 3 3 where>=0 nd b>=0 nd notedge(,3) Figure : A conditionl rule schem In the GP progrmming system [], rule schemt re constructed with grphicl editor. Figure 3 gives grmmr in Extended Bckus-Nur Form for node nd edge lbels in the left nd right grph of rule schem (ctegories LeftLbel nd RightLbel). 3 Lbels cn be sequences of expressions seprted by underscores, s will be demonstrted by Exmple in Section 4. We require tht lbels in the left grph must be simple expressions becuse their vlues t execution time re determined by grph mtching. All vrible identifiers in the right grph must lso occur in the left grph. Every expression in ctegory Exp hs typeint orstring, where rithmeticl opertors expect rguments of typeint nd the type of vrible identifiers is determined by their declrtions. The condition of rule schem is boolen expression built from expressions of ctegory Exp nd the specil predicte edge, see Figure 4. Agin, ll vrible identifiers occurring in the condition must 3 The grmmrs in Figure 3 nd Figure 4 re mbiguous, we use prentheses to dismbigute expressions where necessry.

D. Plump & S. Steinert 3 LeftLbel ::= SimpleExp [ LeftLbel] RightLbel ::= Exp [ RightLbel] SimpleExp ::= [ - ] Num String VrId Exp ::= SimpleExp Exp ArithOp Exp ArithOp ::= + - / Num ::= Digit {Digit} String ::= {Chr} Figure 3: Syntx of node nd edge lbels BoolExp ::= edge ( Node, Node ) Exp RelOp Exp not BoolExp BoolExp BoolOp BoolExp Node ::= Digit {Digit} RelOp ::= = \= > < >= <= BoolOp ::= nd or Figure 4: Syntx of conditions lso occur in the left grph of the schem. The predicte edge demnds the (non-)existence of n edge between two nodes in the grph to which the rule schem is pplied. For exmple, the expression notedge(,3) in the condition of Figure forbids n edge from node to node 3 when the left grph is mtched. We interpret conditionl rule schem s the (possibly infinite) set of conditionl rules tht is obtined by instntiting vribles with ny vlues nd evluting expressions. To define this, consider declrtion D of conditionl rule-schem. Let L nd R be the left nd right grphs of D, nd c the condition. We write Vr(D) for the set of vrible identifiers occurring in D. Given x in Vr(D), type(x) denotes the type ssocited with x. An ssignment is mpping α : Vr(D) (Z Chr ) such tht for ech x in Vr(D), type(x)=int implies α(x) Z, nd type(x)=string implies α(x) Chr. Given lbel l of ctegory RightLbel occuring in D nd n ssignment α, the vlue l α L is inductively defined. If l is numerl or sequence of chrcters, then l α is the integer or chrcter string represented by l (which is independent of α). If l is vrible identifier, then l α = α(l). Otherwise, l α is obtined from the vlues of l s components. If l hs the form e e with in ArithOp nd e,e in Exp, then l α = e α Z e α where Z is the integer opertion represented by. 4 If l hs the form e m with e in Exp nd m in RightLbel, then l α = e α m α (the conctention of e α nd m α ). Note tht our definition of l α covers ll lbels in D since LeftLbel is subctegory of RightLbel. The vlue of the condition c in D not only depends on n ssignment but lso on grph morphism. For, if c contins the predicte edge, we need to consider the structure of the grph to which we wnt to pply the rule schem. Consider n ssignment α nd let L α be obtined from L by replcing ech lbel l with l α. Let g: L α G be grph morphism with G G. Then for ech Boolen subexpression b of c, the vlue b α,g in B={tt,ff} is inductively defined. If b hs the form e e with in RelOp nd e,e in Exp, then b α,g =tt if nd only if e α Z e α where Z is the reltion on integers represented by 4 For simplicity, we consider division by zero s n implementtion-level issue.

3 Semntics of Grph Progrms. If b hs the form notb with b in BoolExp, then b α,g =tt if nd only if b α,g =ff. If b hs the form b b with in BoolOp nd b,b in BoolExp, then b α,g = b α,g B b α,g where B is the Boolen opertion on B represented by. A specil cse is given if b hs the form edge(v,w) where v,w re identifiers of interfce nodes in D. We then hve { b α,g tt if there is n edge from g(v) to g(w), = ff otherwise. Let now r be the rule-schem identifier ssocited with declrtion D. For every ssignment α, let r α =(L α K R α, P α ) be the conditionl rule given s follows: L α nd R α re obtined from L nd R by replcing ech lbel l with l α. K is the discrete subgrph of L nd R determined by the node identifiers for the interfce, where ll nodes re unlbelled. P α is defined by: P α (g) if nd only if g is grph morphism L α G such tht G G nd c α,g =tt. The interprettion of r is the rule set I(r) ={r α α is n ssignment}. For nottionl convenience, we sometimes denote the reltion I(r) by r. Note tht I(r) is (possibly infinite) set of conditionl rules in the sense of Section, grounding rule schemt in the theory of the double-pushout pproch with relbelling [9]. For exmple, the upper rows of Figure 5 show the rule schem bridge of Figure (without condition) nd its instnce bridge α, where α(x) = 0, α(y) = α(z) =, α() = 3 nd α(b) =. The condition c of bridge evlutes to the predicte P α which is true for mtch g of the left-hnd grph if nd only if there is no edge from g() to g(3). (The subexpressions >=0 nd b>=0 evlute to tt nd hence cn be ignored.) The lower rows of Figure 5 show n ppliction of bridge α by grph morphism stisfying P α. +b Schem: x y b z x y b z 3 3 α α 5 Instnce: 0 3 0 3 3 3 5 3 0 3 0 0 0 Figure 5: Appliction of rule schem using instntition

D. Plump & S. Steinert 33 4 Grph Progrms We strt by discussing n exmple progrm for grph colouring. Exmple (Computing -colouring). A colouring for grph is n ssignment of colours (integers) to nodes such tht the source nd trget of ech edge hve different colours. A grph is -colourble (or biprtite) if it possesses colouring with t most two colours. The progrm -colouring in Figure 6 genertes -colouring for nonempty, connected input grphs without loops if such colouring exists otherwise the input grph is returned. The progrm consists of five rule-schem declrtions, the mcro colour representing the rule-schem set{colour, colour}, nd the min commnd sequence following the key wordmin. min=choose; colour!; if illegl then undo! colour ={colour, colour} choose(x: int) illegl(,i,x,y: int) x x 0 x i y i x i y i colour(,i,x,y: int) undo(i,x: int) x i y x i y i x i x colour(,i,x,y: int) x i y x i y i Figure 6: The progrm -colouring Given n integer-lbelled input grph, the progrm first uses the rule schem choose to pick ny node nd replce its lbel x with x 0. The underscore opertor llows to dd tg to lbel, used here to dd colours to lbels. In generl, tgged lbel consists of sequence of expressions joined by underscores. After the first node hs been coloured, the commnd colour! pplies the rule schemt colour nd colour nondeterministiclly s long s possible to colour ll remining nodes. In ech itertion of the loop, n uncoloured node djcent to n lredy coloured node v gets the colour in{0,} tht is complementry to v s colour. If the input grph is connected, the grph resulting from colour! is correctly coloured if nd only if the rule schem illegl is not pplicble. The ltter is checked by the if-sttement. If illegl is pplicble, then the input must contin n undirected cycle of odd length nd hence is not -colourble (see for exmple [0]). In this cse the loopundo! removes ll tgs to return the input grph unmodified. Note tht the number of rule-schem pplictions performed by -colouring is liner in the number of input nodes. To mke -colouring pplicble to grphs tht re possibly empty or disconnected, we cn insert

34 Semntics of Grph Progrms nested loop: min = (choose; colour!)!; if illegl then undo!. Now if the input grph is empty, choose fils which cuses the outer loop to terminte nd return the current (empty) grph. On the other hnd, if the input consists of severl connected components, the body of the outer loop is repetedly clled to colour ech component. Figure 7 shows the bstrct syntx of GP progrms. 5 A progrm consists of number of declrtions of conditionl rule schemt nd mcros, nd exctly one declrtion of min commnd sequence. The rule-schem identifiers (ctegory RuleId) occurring in cll of ctegory RuleSetCll refer to declrtions of conditionl rule schemt in ctegory RuleDecl (see Section 3). Semnticlly, ech rule-schem identifier r stnds for the set I(r) of conditionl rules induced by tht identifier. A cll of the form {r,...,r n } stnds for the union n i= I(r i ). Prog ::= Decl {Decl} Decl ::= RuleDecl McroDecl MinDecl McroDecl ::= McroId = ComSeq MinDecl ::= min = ComSeq ComSeq ::= Com{ ; Com} Com ::= RuleSetCll McroCll if ComSeq then ComSeq [else ComSeq] ComSeq! skip fil RuleSetCll ::= RuleId { [RuleId {, RuleId}] } McroCll ::= McroId Figure 7: Abstrct syntx of GP Mcros re simple mens to structure progrms nd thereby to mke them more redble. Every progrm cn be trnsformed into n equivlent mcro-free progrm by replcing mcro clls with their ssocited commnd sequences (recursive mcros re not llowed). In the next section we use the terms progrm nd commnd sequence synonymously, ssuming tht ll mcro clls hve been replced. The commnds skip nd fil cn be expressed through the other commnds (see next section), hence the core of GP includes only the cll of set of conditionl rule schemt (RuleSetCll), sequentil composition ( ; ), the if-then-else sttement nd s-long-s-possible itertion (! ). 5 Semntics of Grph Progrms We present forml semntics of GP in the style of Plotkin s structurl opertionl semntics [4]. As usul for this pproch, inference rules inductively define smll-step trnsition reltion on configurtions. In our setting, configurtion is either commnd sequence together with grph, just grph or the specil element fil: (ComSeq G) ((ComSeq G) G {fil}). 5 Where necessry we use prentheses to dismbigute progrms.

D. Plump & S. Steinert 35 Configurtions in ComSeq G represent unfinished computtions, given by rest progrm nd stte in the form of grph, while grphs in G re proper results of computtions. In ddition, the element fil represents filure stte. A configurtion γ is terminl if there is no configurtion δ such tht γ δ. Ech inference rule in Figure 8 consists of premise nd conclusion seprted by horizontl br. Both prts contin met-vribles for commnd sequences nd grphs, where R stnds for cll in ctegory RuleSetCll, C,P,P,Q stnd for commnd sequences in ctegory ComSeq nd G,H stnd for grphs in G. Given rule-set cll R, let I(R) = {I(r) r is rule-schem identifier in R} (see Section 3 for the definition of I(r)). The domin of I(R), denoted by Dom( I(R) ), is the set of ll grphs G in G such tht G I(R) H for some grph H. Met-vribles re considered to be universlly quntified. For exmple, the rule [Cll ] should be red s: For ll R in RuleSetCll nd ll G,H in G, G I(R) H implies R, G H. Figure 8 shows the inference rules for the core constructs of GP. We write + nd for the trnsitive nd reflexive-trnsitive closures of. A commnd sequence C finitely fils on grph G G if () there does not exist n infinite sequence C, G C, G... nd () for ech terminl configurtion γ such tht C, G γ, γ = fil. In other words, C finitely fils on G if ll computtions strting from (C, G) eventully end in the configurtion fil. [Cll ] [Seq ] G I(R) H R, G H P, G P, H P;Q, G P ;Q, H [Cll ] G Dom( I(R)) R, G fil [Seq ] P, G H P;Q, G Q, H [Seq 3 ] P, G fil P;Q, G fil [If ] [Alp ] C, G + H if C then Pelse Q, G P, G P, G + H P!, G P!, H [If ] [Alp ] C finitely fils on G if C then Pelse Q, G Q, G P finitely fils on G P!, G G Figure 8: Inference rules for core commnds The concept of finite filure stems from logic progrmming where it is used to define negtion s filure [4]. In the cse of GP, we use it to define powerful brnching nd itertion constructs. In prticulr, our definition of the if-then-else commnd llows to hide destructive tests. Exmple (Recognizing series-prllel grphs). A grph is series-prllel if it reduces to grph consisting of two nodes nd n edge between them by the following two opertions [, 5]: () Replce pir of prllel edges by n edge from their source to their trget. () Given node v with exctly one incoming edge e nd exctly one outgoing edge e such tht the source of e nd the trget of e re distinct, replce e, e nd v by n edge from the source of e to the trget of e. Suppose tht we wnt to check whether connected, integer-lbelled grph G is series-prllel nd, depending on the result, execute either progrm P or progrm Q on G. We cn do this with the progrm min = if {pr,seq}!;bsethen Pelse Q whose rule schemt pr, seq nd bse re shown in Figure 9. The subprogrm {pr,seq}! pplies

36 Semntics of Grph Progrms s long s possible the opertions () nd () to the input grph G, then the rule schem bse checks if the resulting grph consists of two nodes connected by n edge. Grph G is series-prllel if nd only ifbse is pplicble to the reduced grph. (Note tht {pr,seq}! preserves connectedness nd tht, by the dngling condition, bse is pplicble only if the imges of its left-hnd nodes hve degree one.) It is importnt to note tht by the inference rules [If ] nd [If ], the min progrm executes P or Q on the input grph G wheres the grph resulting from the test is discrded. pr(,b,x,y: int) x y b 0 x y seq(,b,x,y,z: int) x y b z 0 x z bse(,x,y: int) x y /0 Figure 9: Rule schemt for recognizing series-prllel grphs The mening of the remining GP commnds is defined in terms of the mening of the core commnds, see Figure 0. We refer to these commnds s derived commnds. [Skip] skip, G r, G whereris n identifier for the rule schem /0 /0 [[Fil] fil, G {}, G [If 3 ] if C then P, G if C then Pelseskip, G Figure 0: Inference rules for derived commnds We cn now summrise the mening of GP progrms by semntic function which ssigns to ech progrm P the function P mpping n input grph G to the set of ll possible results of running P on G. The result set my contin, besides proper results in the form of grphs, the specil vlue which indictes nonterminting or stuck computtion. The semntic function : ComSeq (G G { } ) is defined by 6 P G = {H G P, G + H} { P cn diverge or get stuck from G} where P cn diverge from G if there is n infinite sequence P, G P, G P, G..., nd P cn get stuck from G if there is terminl configurtion Q, H such tht P, G Q, H. 6 We write P G for the ppliction of P to grph G.

D. Plump & S. Steinert 37 Note tht P G = /0 if nd only if P finitely fils on G. In Exmple, for instnce, we hve {pr,seq}!;bse G= /0 for every connected grph G contining cycle. This is becuse the grph resulting from {pr,seq}! is still connected nd cyclic, so the rule schembse is not pplicble. A progrm cn get stuck only in two situtions: either it contins subprogrm if C then P else Q where C both cn diverge from some grph nd cnnot produce proper result from tht grph, or it contins subprogrm B! where the loop s body B possesses the sid property of C. The evlution of these subprogrms will get stuck becuse the inference rules for brnching nd itertion re not pplicble. 6 Conclusion GP is n experimentl rule-bsed lnguge for high-level problem solving in the domin of grphs, freeing progrmmers from hndling low-level dt structures. The hllmrk of GP is syntctic nd semntic simplicity. Conditionl rule schemt for grph trnsformtion llow to express ppliction conditions nd computtions on lbels, in ddition to structurl chnges. The semntics of rule schemt is orthogonl to the semntics of control constructs, mking it esy to chnge the formt of rules or grphs. The opertionl semntics of progrms describes the effect of GP s control constructs in nturl wy nd cptures the nondeterminism of the lnguge. In prticulr, powerful brnching nd itertion commnds hve been defined using the concept of finite filure. Destructive tests on the current grph cn be hidden in the condition of the brnching commnd, nd nested loops cn be coded since rbitrry subprogrms cn be iterted s long s possible. Future extensions of GP my include recursive procedures for writing complex lgorithms (see [9]), nd type concept for restricting the shpe of grphs. Our gol is to support forml resoning on grph progrms by developing sttic nlyses for properties such s termintion nd confluence (uniqueness of results), nd clculus nd tool support for progrm verifiction. References [] Jørgen Bng-Jensen nd Gregory Gutin. Digrphs: Theory, Algorithms nd Applictions. Springer-Verlg, 000. [] Peter Borovnský, Clude Kirchner, Hélène Kirchner, nd Pierre-Etienne Moreu. ELAN from rewriting logic point of view. Theoreticl Computer Science, 85():55 85, 00. [3] Mrtin Brvenboer, Arthur vn Dm, Krin Olmos, nd Eelco Visser. Progrm trnsformtion with scoped dynmic rewrite rules. Fundment Informtice, 69( ):3 78, 006. [4] Keith L. Clrk. Negtion s filure. In Herve Gllire nd Jck Minker, editors, Logic nd Dt Bses, pges 93 3. Plenum Press, 978. [5] R. J. Duffin. Topology of series-prllel networks. Journl of Mthemticl Anlysis nd Applictions, 0:303 38, 965. [6] Cludi Ermel, Michel Rudolf, nd Gbi Tentzer. The AGG pproch: Lnguge nd environment. In H. Ehrig, G. Engels, H.-J. Kreowski, nd G. Rozenberg, editors, Hndbook of Grph Grmmrs nd Computing by Grph Trnsformtion, volume, chpter 4, pges 55 603. World Scientific, 999. [7] Rubino Geiß, Gernot Veit Btz, Dniel Grund, Sebstin Hck, nd Adm M. Szlkowski. GrGen: A fst SPO-bsed grph rewriting tool. In Proc. Interntionl Conference on Grph Trnsformtion (ICGT 006), volume 478 of Lecture Notes in Computer Science, pges 383 397. Springer-Verlg, 006.

38 Semntics of Grph Progrms [8] Annegret Hbel nd Detlef Plump. Computtionl completeness of progrmming lnguges bsed on grph trnsformtion. In Proc. Foundtions of Softwre Science nd Computtion Structures (FOSSACS 00), volume 030 of Lecture Notes in Computer Science, pges 30 45. Springer-Verlg, 00. [9] Annegret Hbel nd Detlef Plump. Relbelling in grph trnsformtion. In Proc. Interntionl Conference on Grph Trnsformtion (ICGT 00), volume 505 of Lecture Notes in Computer Science, pges 35 47. Springer-Verlg, 00. [0] Jon Kleinberg nd Év Trdos. Algorithm Design. Addison Wesley, 006. [] Greg Mnning nd Detlef Plump. The GP progrmming system. In Proc. Grph Trnsformtion nd Visul Modelling Techniques (GT-VMT 008), volume 0 of Electronic Communictions of the EASST, 008. [] Ulrich Nickel, Jörg Niere, nd Albert Zündorf. The FUJABA environment. In Proc. Interntionl Conference on Softwre Engineering (ICSE 000), pges 74 745. ACM Press, 000. [3] Hnne Riis Nielson nd Flemming Nielson. Semntics with Applictions: An Appetizer. Springer-Verlg, 007. [4] Gordon D. Plotkin. A structurl pproch to opertionl semntics. Journl of Logic nd Algebric Progrmming, 60 6:7 39, 004. [5] Detlef Plump. The grph progrmming lnguge GP. In Proc. Algebric Informtics (CAI 009), volume 575 of Lecture Notes in Computer Science, pges 99. Springer-Verlg, 009. [6] Detlef Plump nd Sndr Steinert. Towrds grph progrms for grph lgorithms. In Proc. Interntionl Conference on Grph Trnsformtion (ICGT 004), volume 356 of Lecture Notes in Computer Science, pges 8 43. Springer-Verlg, 004. [7] Andy Schürr. Opertionles Spezifizieren mit progrmmierten Grphersetzungssystemen. Deutscher Universitäts-Verlg, 99. In Germn. [8] Andy Schürr, Andres Winter, nd Albert Zündorf. The PROGRES pproch: Lnguge nd environment. In H. Ehrig, G. Engels, H.-J. Kreowski, nd G. Rozenberg, editors, Hndbook of Grph Grmmrs nd Computing by Grph Trnsformtion, volume, chpter 3, pges 487 550. World Scientific, 999. [9] Sndr Steinert. The Grph Progrmming Lnguge GP. PhD thesis, The University of York, 007.