Bernhard Beckert and Joachim Posegga. \term_expansion((define C as A with B), (C=>A:-B,!)). A=?B :- [A,B]=>*[D,C], D==C."

Similar documents
Universitat Karlsruhe. Am Fasanengarten 5, Karsruhe, Germany. WWW:

76128 Karlsruhe, Germany; \term_expansion((define C as A with B), (C=>A:-B,!)).

A Poor Man's. Bernhard Beckert. Joachim Posegga. Interner Bericht 25/95

Evolving Algebras and Partial Evaluation

Expressions that talk about themselves. Maarten Fokkinga, University of Twente, dept. INF, Version of May 6, 1994

Programming Languages Third Edition

Evolving Algebras. Mini-Course. Basic Research in Computer Science. BRICS NS-95-4 Gurevich & Börger: Evolving Algebras. Yuri Gurevich Egon Börger

Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee. The Chinese University of Hong Kong.

The Prolog to Mercury transition guide

Abstract This paper describes AxSL, an Axiomatic Specication Language that extends algebraic axiom methods to support object-oriented concepts such as

Operational Semantics

The underlying idea for the proposed proof procedure is to transform a formula into a Shannon graph and compile this graph into Horn clauses When run

Part I Logic programming paradigm

SAMOS: an Active Object{Oriented Database System. Stella Gatziu, Klaus R. Dittrich. Database Technology Research Group

An ASM Semantics for SSA Intermediate Representations

For our sample application we have realized a wrapper WWWSEARCH which is able to retrieve HTML-pages from a web server and extract pieces of informati

(b) extended UML state machine diagram. (a) UML state machine diagram. tr D2 tr D1 D2 D1 D2

reduction of functional expressions to normal form. Then we dene six typical provably

1 Lexical Considerations

3.7 Denotational Semantics

2 pecifying Complex and tructured ystems with Evolving Algebras On the other side, the at concept, based on elementary updates, provides no means for

Fuzzy logic. 1. Introduction. 2. Fuzzy sets. Radosªaw Warzocha. Wrocªaw, February 4, Denition Set operations

Local Specialization in Open-Axiom

Proc. XVIII Conf. Latinoamericana de Informatica, PANEL'92, pages , August Timed automata have been proposed in [1, 8] to model nite-s

Electrical Engineering and Computer Science Department. Ann Arbor, MI , USA. Fall 1992

Functional Programming. Big Picture. Design of Programming Languages

A Bintree Representation of Generalized Binary. Digital Images

(Refer Slide Time: 4:00)

A Small Interpreted Language

proc {Produce State Out} local State2 Out2 in State2 = State + 1 Out = State Out2 {Produce State2 Out2}

A macro- generator for ALGOL

A taxonomy of race. D. P. Helmbold, C. E. McDowell. September 28, University of California, Santa Cruz. Santa Cruz, CA

Institut für Informatik D Augsburg

Lexical Considerations

Documentation for LISP in BASIC

Induction and Semantics in Dafny

15-819M: Data, Code, Decisions

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

Denotational semantics

Abstract formula. Net formula

Typed Racket: Racket with Static Types

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

This chapter describes the syntax and semantics of the safemos programming language,

Functional Programming. Pure Functional Programming

Brouillon d'article pour les Cahiers GUTenberg n?? February 5, xndy A Flexible Indexing System Roger Kehr Institut fur Theoretische Informatik

User-defined Functions. Conditional Expressions in Scheme

AsmL Specification and Verification of Lamport s Bakery Algorithm

Research Report AI A Numerical Equation Solver in Prolog Michael A. Covington Artificial Intelligence Programs The University of Georgia

once. A at term is a variable or a term of the form f(x 1 ; : : : ; x n ), where n 0 and the x i are distinct variables. Atoms are denoted by h, queri

STABILITY AND PARADOX IN ALGORITHMIC LOGIC

Abstract State Machines: An Overview of the Project

A Tribute to Dean Rosenzweig

Structure of Abstract Syntax trees for Colored Nets in PNML

Let v be a vertex primed by v i (s). Then the number f(v) of neighbours of v which have

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

such internal data dependencies can be formally specied. A possible approach to specify

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen

6.001 Notes: Section 6.1

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

CSCC24 Functional Programming Scheme Part 2

Higher-Order Conditional Term Rewriting. In this paper, we extend the notions of rst-order conditional rewrite systems

COMPUTER SCIENCE TRIPOS

Chapter 6 Control Flow. June 9, 2015

Functional Programming

Semantics of programming languages

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

CS 314 Principles of Programming Languages

Implementação de Linguagens 2016/2017

1.3. Conditional expressions To express case distinctions like

An Introduction to Functions

Citation for published version (APA): Veenstra, M. J. A. (1998). Formalizing the minimalist program Groningen: s.n.

6.001 Notes: Section 4.1

Dependent Object Types - A foundation for Scala's type system

QUTE: A PROLOG/LISP TYPE LANGUAGE FOR LOGIC PROGRAMMING

Autolink. A Tool for the Automatic and Semi-Automatic Test Generation

when a process of the form if be then p else q is executed and also when an output action is performed. 1. Unnecessary substitution: Let p = c!25 c?x:

Logic Programming and Resolution Lecture notes for INF3170/4171

Handout 10: Imperative programs and the Lambda Calculus

A Practical Approach to Programming With Assertions

Equations for Asynchronous Message Passing

Case study: leical analysis Leical analysis converts u sequences of characters u into u sequences of tokens u tokens are also called words or leemes F

Functional programming with Common Lisp

Functional Logic Programming Language Curry

Lecture 11: Feb. 10, 2016

Manfred Broy. Leslie Lamport. Sat 6 Aug The problem calls for the specication and verication of a series of components.

A Combined BIT and TIMESTAMP Algorithm for. the List Update Problem. Susanne Albers, Bernhard von Stengel, Ralph Werchner

Formal specification of semantics of UML 2.0 activity diagrams by using Graph Transformation Systems

source constructs created by the operation. he complexity of these computations contributes to the complexity of the entire language translator specic

University of Utrecht. 1992; Fokker, 1995), the use of monads to structure functional programs (Wadler,

Principles of Programming Languages 2017W, Functional Programming

Data Analytics and Boolean Algebras

Abstract algorithms. Claus Diem. September 17, 2014

The Resolution Algorithm

Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3

Term Algebras with Length Function and Bounded Quantifier Elimination

7. Relational Calculus (Part I) 7.1 Introduction

Shell CSCE 314 TAMU. Haskell Functions

to automatically generate parallel code for many applications that periodically update shared data structures using commuting operations and/or manipu

Lexical Considerations

Partial Exam Compilation and Program Analysis (CAP) October, 24th, 2016 Duration: 2 Hours

Transcription:

leanea: A Lean Evolving Algebra Compiler Bernhard Beckert and Joachim Posegga Abstract. The Prolog program \term_expansion((define C as A with B), (C=>A:-B,!)). term_expansion((transition E if C then D), ((transition E):-C,!,B,A,(transition _))) :- serialize(d,b,a). serialize((e,f),(c,d),(a,b)) :- serialize(e,c,b), serialize(f,d,a). serialize(f:=g, ([G]=>*[E],F=..[C D],D=>*B,A=..[C B]), asserta(a=>e)). [G H]=>*[E F] :- (G=\E; G=..[C D],D=>*B,A=..[C B],A=>E),!,H=>*F. []=>*[]. A=?B :- [A,B]=>*[D,C], D==C." implements a virtual machine for evolving algebras. It oers an ecient and very exible framework for their simulation. 1 Introduction Evolving algebras (EAs) [Gur91, Gur94] are abstract machines used mainly for formal specication of algorithms. The main advantage of EAs over classical formalisms for specifying operational semantics, like Turing machines for instance, is that they have been designed to be usable by human beings: whilst the concrete appearance of a Turing machine has a solely mathematical motivation, EAs try to provide a user friendly and natural though rigorous specication tool. The number of specications using EAs is rapidly growing; 1 examples are specications of the languages ANSI C [GH93] and ISO Prolog [BR94], and of the virtual architecture APE [BDGR94]. EA specications have also been used to validate language implementations (e.g., Occam [BDR94]) and distributed protocols [GM94]. There is little sense in implementing a Turing machine (besides for pedagogical reasons); however, an implementation of a machine for executing EAs can help a person working with this formalism a lot, as the level of abstraction in an EA specications is problem-oriented. This observation is of course not new and implementations of abstract machines for EAs already exist: Angelica Kappel describes a Prolog-based implementation in [Kap93], and Jim Huggins reports an implementation in C. Both implementations are quite sophisticated and oer a convenient language for specifying EAs. In this paper, we describe an approach to implementing an abstract machine for EAs which is dierent, in that it emphasizes on simplicity and elegance of the implementation, rather than on sophistication. We present a simple, Prolog-based approach for executing EAs. The underlying idea is to map EA specications into Prolog programs. Rather than Universitat Karlsruhe, Institut fur Logik, Komplexitat und Deduktionssysteme, Am Fasanengarten 5, 76128 Karsruhe, Germany. fbeckert;poseggag@ira.uka.de, http://i12www.ira.uka.de 1 See http://www.eecs.umich.edu/ealgebras for a a collection of papers on EAs.

programming a machine explicitly, we turn the Prolog system itself into a virtual machine for EA specications: this is achieved by changing the Prolog reader, such that the transformation of EAs into Prolog code takes place whenever the Prolog system reads input. As a result, evolving algebra specications can be treated like ordinary Prolog programs. The main advantage of our approach, which we call leanea, is that it is very exible: the Prolog program we discuss in the sequel can easily be understood and extended to the needs of concrete specication tasks (non-determinism, special handling of undened functions, etc.). Furthermore, its exibility allows to easily embed it into, or interface it with other systems. The paper is organized as follows: in Section 2, we start with explaining how a deterministic, untyped EA can be programmed in leanea; this section is written pragmatically, in the sense that we do not present a mathematical treatment, but explain what a user has to do in order to use EAs with leanea. The implementation of leanea is explained in parallel. An extended example of using leanea is given in Section 3. In Section 4 we make some remarks regardings semantics of leanea specications. We draw conclusions from our research in Section 5. 2 Programming EAs in leanea 2.1 The Basics of leanea An algebra can be understood as a formalism for describing static relations between things: there is a universe consisting of the objects we are talking about, and a set of functions mapping members of the universe to other members. Evolving algebras oer a formalism for describing changes as well: an algebra can be \moved" from one state to another, in that the functions can be changed. leanea is a programming language that allows to program this behaviour. From a declarative point of view, a leanea program is a specication of an EA. Here, however, we will not argue declaratively, but operationally by describing how statements of leanea set up an EA and move it from one state to another. leanea is an extension of standard Prolog 2, thus a leanea program can be treated like any other Prolog program, i.e., it can simply be loaded (or compiled) into the underlying Prolog system (provided leanea itself has been loaded before). leanea has two syntactical constructs for programming an EA: the rst are function denitions of the form define Location as Value with Goal. which specify the initial state of an EA. The second construct are transition denitions which dene the EA's evolving, i.e., the mapping from one state to the next: transition Name if Condition then Updates. The signature of EAs is in our approach the set of all ground Prolog terms. The (single) universe, that is not sorted, consists of ground Prolog terms, too; it is not specied explicitly. Also, the nal state(s) of the EA are not given explicitly in leanea. Instead, a state S is dened to be nal if no transition is applicable in S or if a transition res that uses undened functions in its updates. 2 We assume the reader to be familiar with Prolog. An introduction can be found in [O'K90]. 2

The computation of the specied evolving algebra is started by calling the Prolog goal \transition _". 2.2 Representation of States in leanea Before explaining how function denitions set up the initial state of an EA, we take a look at the leanea internals for representing states: A state is given by the mapping of locations to their values, i.e., elements of the universe. A location f (u1; : : : ; un), n 0, consists of a functor f and arguments u1 ; : : : ; u n that are members of the universe. Example 1 Assume, for instance, that there is a partial function denoted by f that maps a pair of members of the universe to a single element, and that 2 and 3 are members of the universe. The application of f to 2 and 3 is denoted by the Prolog term f(2,3). This location can either have a value in the current state, or it can be undened. A state in leanea is represented by the values of all dened locations. Technically, this is achieved by dening a Prolog predicate =>/2, 3 that behaves as follows: The goal \Loc => Val" succeeds if Loc is bound to a ground Prolog term that is a location in the algebra, and if a value is dened for this location; then Val is bound to that value. The goal fails if no value is dened for Loc in the current state of the algebra. To evaluate a function call like f(f(2,3),3), leanea uses the evaluation predicate =>*/2: the relation t =>* v holds for ground Prolog terms t and v if the value of t where t is interpreted as a function call is v (in the current state of the algebra). In general, the arguments of a function call are not elements of the universe (contrary to the arguments of a location). They are recursively evaluated. To make it possible to use members of the universe in function calls explicitly, they can be denoted by preceding them with a backslash \\": this disables the evaluation of whatever Prolog term comes after the backslash. We will refer to this as quoting in the sequel. For economical reasons, the predicate =>*/2 actually maps a list of function calls to a list of values. Figure 1, Lines 27{34, shows the Prolog code for =>*, which is more or less straightforward: if the term to be evaluated is preceded with a backslash, the term itself is the result of the evaluation; otherwise, all arguments are recursively evaluated and the value of the term is looked up with the predicate =>/2. Easing the evaluation of the arguments of terms is the reason for implementing =>* over lists. The base step of the recursion is the identity of the empty list (Line 34). =>* fails, if the value of the function call is undened in the current state. Example 2 As an example, consider again the binary function f, and assume it behaves like addition in the current state of the algebra. Then both the goals \[f(\1,\2)] =>* [X]" and \[f(f(\0,\1),\2)] =>* [X]" succeed with binding X to 3. The goal \[f(\f(0,1)},\2)] =>* [X]", however, will fail since addition is undened on the term f(0,1), which is not an integer. After exploring the leanea internals for evaluating expressions, we come back to programming in leanea. The rest of this section will explain the purpose of function and transition denitions, and how they aect the internal predicates just explained. 3 Note, that =>/2 is dened to be dynamic such that it can be changed by transitions (Fig. 1, Line 8). 3

2.3 Function Denitions The initial state of an EA is specied by a sequence of function denitions. They dene the inital values of locations by giving Prolog code to compute these values. A construct of the form define Location as Value with Goal. gives a procedure for computing the value of a location that matches the Prolog term Location: if Goal succeeds, then Value is taken as the value of this location. Function denitions set up the predicate => (and thus =>*) in the initial state. One function denition can specify values for more than one functor of the algebra. It is possible in principle, although quite inconvenient, to dene all functors within a single function denition. The value computed for a location may depend on the additional Prolog code in a leanea-program (code besides function and transition denitions), since Goal may call predicates from the additional code. If several function denitions dene values for a single location, the (textually) rst is chosen. A function denition is translated into the Prolog clause (Location => Value) :- Goal,!. Since each denition is mapped into one such clause, Goal must not contain a cut \!"; otherwise, the cut might prevent Prolog from considering subsequent => clauses that match a certain location. The translation of a dene statement to a => clause is implemented by modifying the Prolog reader as shown in Figure 1, Lines 10{11. 4 Example 3 Examples for function denitions are: define register1 as 1 with true. Assigns the value 1 to the constant (0-ary location) register1. define X as X with (X=[]; X=[H T]). This denes that all lists evaluate to themselves; thus, it is not necessary to quote lists in function calls with a backslash. Similarly, define X as X with integer(x). denes that Prolog integers are in the universe and evaluate to themselves. define X+Y as Z with Z is X+Y. This denition shows how Prolog predicates can be used for calculating the value of (external) functions within an EA. The user is responsible that the Prolog goals for calculation values meet certain conditions: the computed values have to be ground Prolog terms, and the goals must either fail or succeed (i.e., terminate) for all possible instantiations that might appear. 5 In addition, the goals must not change the Prolog data base or have any other side eects; 6 and they must not call the leanea internal predicates transition/1, =>*/2, and =>/2. 4 In most Prolog dialects (e.g., SICStus Prolog and Quintus Prolog) this is done by adding clauses for the term expansion/2 predicate. If a term t is read, and term expansion(t,s) succeeds and binds the variable S to a term s, then the Prolog reader replaces t by s. 5 Prolog exceptions that terminate execution have to be avoided as well. Thus, it is advisable to formulate the denition of + as: define X+Y as Z with integer(x),integer(y),z is X+Y. 6 Side eects that do not inuence other computations are harmless and often useful; an example are the denitions for input and output of the EA in Section 3. 4

2.4 Transition Denitions A transition, if applicable, maps one state of an EA to a new state by changing the value of certain locations. Transitions have the following syntax: where transition Name if Condition then Updates. Name is an arbitrary Prolog term (usually an atom). Condition is a Prolog goal containing calls to the predicate =?/2 (see below), or combinations thereof that are built using the logical Prolog operators \," (conjunction), \;" (disjunction), \->" (implication), and \\+" (negation). Updates is a comma-separated sequence of updates of the form f1(r11 ; : : : ; r 1n 1 ) := v1,. fk(rk1 ; : : : ; r kn k ) := vk An update fi(ri1 ; : : : ; r in i ) := vi (1 i k) changes the value of the location that consists of (a) the functor fi and (b) the elements of the universe that are the values of the function calls ri1; : : : ; rin i ; the new value of this location is determined by evaluating the function call vi. All function calls in the updates are evaluated simultaneously (i.e., in the old state). If one of the function calls is undened, the assignment fails. If the left-hand side of an update is quoted by a preceding backslash, the update will have no eect besides that the right-hand side is evaluated; the meaning of the backslash cannot be changed. A transition is applicable (res) in a state, if Condition succeeds. For calculating the successor state, the (textually) rst applicable transition is selected. Then the Updates of selected transition are executed. If no transition res or if one of the updates of the rst ring transition fails, the the new state cannot be computed. In that case, the evolving algebra terminates, i.e., the current state is nal. Else the computation continues iteratively with calculating further states of the algebra. A transition is transformed into the clause transition(name) :- Condition,!, UpdateCode, transition( ). This is done by modifying the Prolog reader as shown in Figure 1, Lines 13{16. Since updates must be executed simultaneously, all function calls are evaluated before the rst assignment takes place. The auxiliary predicate serialize/3 (Lines 18{25) serves this purpose: it splits all updates into evaluation code, that uses the predicate =>*/2, and into code for storing the new values by asserting an appropriate =>/2 clause. Besides logical operators, leanea allows in the condition of transitions the pre-dened predicate =?/2 (Fig. 1, Line 36) implementing the equality relation: the goal \s =? t" succeeds if the function calls s and t evaluate (in the current state) to the same element of the universe. It fails, if one of the calls is undened or if they evaluate to dierent elements. 5

It is possible to implement similar relations using the leanea internal predicate =>* to evaluate the arguments of the relation: A predicate p(t1; : : : ; tn) (n 0) is implemented by adding the code p(t1; : : : ; tn) :- [t1 ; : : : ; t n] =>* [x1 ; : : : ; x n], Code. to leanea. 7 Then the goal \p(t1 ; : : : ; t n)" can be used in conditions of transitions instead of p 0 (t1 ; : : : ; t n) =? true", where p 0 is dened by the function denition define p 0 (x1 ; : : : ; x n) as true with Code. (which is the standard way of implementing relations using function denitions). Note, that p fails, if one of the function calls t1 ; : : : ; t n is undened in the current state. Example 4 The is-not-equal relation is implemented by adding the clause (A <> B) :- ([A,B] =>* [Val1,Val2], Val1 \== Val2). for the predicate <>/2 to leanea. 2.5 leanea's Operators To make it possible to use the syntax for function and transition denitions as described in the previous sections, a couple of Prolog operators have to be dened with appropriate preferences; they are shown in Figure 1, Lines 1{6. Note, that the preferences of operators (those pre-dened by leanea as well as others used in a leanea program) can inuence the semantics of Prolog terms and thus of function calls. 3 An Example Algebra The following program species an EA for computing n!: define state as initial with true. define readint as X with read(x), integer(x). define write(x) as X with write(x). define X as X with integer(x). define X-Y as R with integer(x),integer(y),r is X-Y. define X*Y as R with integer(x),integer(y),r is X*Y. transition step if state =? \running, \+(reg1 =? 1) then reg1 := reg1-1, reg2 := (reg2*reg1). transition start 7 x1; : : : ; x n must be n distinct Prolog variables and must not be instantiated when =>* is called. Thus, \(A =? B) :- ([A,B] =>* [V,V])." must not be used to implement =?, but \(A =? B) :- ([A,B] =>* [V1,V2]), V1 == V2.". 6

if state =? \initial then reg1 := readint, reg2 := 1, state := \running. transition result if state =? \running, reg1 =? 1 then reg2 := write(reg2), state := \final. The constant state is used for controlling the ring of transitions: in the initial state, only the transition start res and reads an integer; it assigns the input value to reg1. The transition step iteratively computes the faculty of reg1's value by decrementing reg1 and storing the intermediate results in reg2. If the value of reg1 is 0, the computation is complete, and the only applicable transition result prints reg2. After this, the algebra halts since no further transition res and a nal state is reached. 4 Some Remarks Regarding Semantics Relations There are no special pre-dened elements denoting true and false in the universe. The value of the relation =? (and similar pre-dened relations) is represented by succeeding (resp. failing) of the corresponding predicate. Undened Functions Calls Similarly, there is no pre-dened element undef in the universe, but evaluation fails if no value is dened. This, however, can be changed by adding define _ as undef with true. as the last function denition. Internal and External Functions In leanea there is no formal distinction between internal and external functions. Function denitions can be seen as giving default values to functions; if the default values of a function remain unchanged, then it can be regarded external (pre-dened). If no default value is dened for a certain function, it is classically internal. If the default value of a location is changed, this is what is called an external location in [Gur94]. The relation =? (and similar predicates) are static. Since there is no real distinction, it is possible to mix internal and external functions in function calls. Importing and Discarding Elements leanea does not have constructs for importing or discarding elements. The latter is not needed anyway. If the former useful for an application, the user can simulate \import v" by the \v := import", where import is dened by the function denition define import as X with gensym(f,x). 8 8 The Prolog predicate gensym generates a new atom every time it is called. 7

Local Nondeterminism If the updates of a ring transition are inconsitent, i.e., several updates dene a new value for the same location, the rst value is chosen (this is called local nondeterminism in [Gur94]). 5 Conclusion We presented leanea, an approach to implementing an abstract machine for evolving algebras. The underlying idea is to modifying the Prolog reader, such that loading a specication of an evolving algebra means compiling it into Prolog clauses. Thus, the Prolog system itself is turned into an abstract machine for running EAs. The contribution of our work is twofold: Firstly, leanea oers an ecient and very exible framework for simulating EAs. leanea is open, in the sense that it is easily interfaced with other applications, embedded into other systems, or adapted to concrete needs. We believe that this is a very important feature that is often underestimated: if a specication system is supposed to be used in practice, then it must be embedded in an appropriate system for program development. leanea, as presented in this paper, is surely more a starting point than a solution for this, but it demonstrates clearly one way for proceeding. Second, leanea demonstrates that little eort is needed to implement a simulator for EAs. This supports the claim that EAs are a practically relevant tool, and it shows a clear advantage of EAs over other specication formalisms: these are often hard to understand, and dicult to deal with when implementing them. EAs, on the other hand, are easily understood and easily used. Thus, leanea shows that one of the major goals of EAs, namely to \bridge the gap between computation models and specication methods" (following [Gur94]), was achieved. References [BDGR94] E. Borger, G. Del Castillo, P. Glavan, and D. Rosenzweig. Towards a mathematical specication of the APE100 architecture: The APESE model. In B. Pehrson and I. Simon, editors, Proceedings, IFIP 13th World Computer Congress, volume 1, pages 396{401, Amsterdam, 1994. Elsevier. [BDR94] E. Borger, I. Durdanovic, and D. Rosenzweig. Occam: Specication and compiler correctness. In U. Montanari and E.-R. Olderog, editors, Proceedings, IFIP Working Conference on Programming Concepts, Methods and Calculi (PROCO- MET 94), pages 489{508. North-Holland, 1994. [BR94] Egon Borger and Dean Rosenzweig. A mathematical denition of full Prolog. Science of Computer Programming, 1994. [GH93] Yuri Gurevich and Jim Huggins. The semantics of the C programming language. In Proceedings, Computer Science Logic (CSL), LNCS 702, pages 273{309. Springer, 1993. [GM94] Yuri Gurevich and Raghu Mani. Group membership protocol: Specication and verication. In E. Borger, editor, Specication and Validation Methods. Oxford University Press, 1994. 8

[Gur91] Yuri Gurevich. Evolving algebras. A tutorial introduction. Bulletin of the EATCS, 43:264{284, 1991. [Gur94] Yuri Gurevich. Evolving algebras 1993: Lipari Guide. In E. Borger, editor, Specication and Validation Methods. Oxford University Press, 1994. [Kap93] Angelica M. Kappel. Executable Specications based on Dynamic Algebras. In Proceedings, 4th International Conference on Logic Programming and Automated Reasoning (LPAR), St. Petersburg, Russia, LNCS 698, pages 229{240. Springer, July 1993. [O'K90] Richard A. O'Keefe. The Craft of Prolog. MIT Press, 1990. 9

1 :- op(1199,fy,(transition)), op(1180,xfx,(if)), 2 op(1192,fy,(define)), op(1185,xfy,(with)), 3 op(1190,xfy,(as)), op(1170,xfx,(then)), 4 op(900,xfx,(=>)), op(900,xfx,(=>*)), 5 op(900,xfx,(:=)), op(900,xfx,(=?)), 6 op(100,fx,(\)). 7 8 :- dynamic (=>)/2. 9 10 term_expansion((define Term as Res with Code), 11 ((Term => Res) :- Code,!)). 12 13 term_expansion((transition Name if Cond then Update), 14 (transition(name) :- 15 (Cond,!,FrontCode,BackCode,transition(_)))) :- 16 serialize(update,frontcode,backcode). 17 18 serialize((a,b),(fronta,frontb),(backb,backa)) :- 19 serialize(a,fronta,backa), 20 serialize(b,frontb,backb). 21 22 serialize((locterm := Expr), 23 ([Expr] =>* [Val], LocTerm =.. [Func Args], 24 Args =>* ArgVals, Loc =..[Func ArgVals]), 25 asserta(loc => Val)). 26 27 ([H T] =>* [HVal TVal]) :- 28 ( H = \HVal 29 ; H =.. [Func Args], Args =>* ArgVals, 30 H1 =.. [Func ArgVals], H1 => HVal 31 ),!, 32 T =>* TVal. 33 34 [] =>* []. 35 36 (A =? B) :- ([A,B] =>* [Val1,Val2]), Val1 == Val2. Figure 1: leanea: the program 10