Formalization of the Equivalent Transformation ... - Semantic Scholar

7 downloads 0 Views 247KB Size Report
P.O. Box 22, Thammasat-Rangsit Post Office, Rangsit Campus, Pathumthani 12121, Thailand. E-mail: ... Hokkaido University in 1990-1992 and reported in 1992.
Formalization of the Equivalent Transformation Computation Model

Paper:

Formalization of the Equivalent Transformation Computation Model Kiyoshi Akama , and Ekawit Nantajeewarawat £ Division

of Large-Scale Computational Systems, Information Initiative Center, Hokkaido University Kita 11 Nishi 5, Kita-ku, Sapporo, Hokkaido 060-0811, Japan E-mail: [email protected] ££ Computer Science Program, Sirindhorn International Institute of Technology, Thammasat University P.O. Box 22, Thammasat-Rangsit Post Office, Rangsit Campus, Pathumthani 12121, Thailand E-mail: [email protected] [Received February 22, 2005; accepted December 21, 2005]

In the equivalent transformation (ET) computation model, a specification provides background knowledge in a problem domain and defines a set of queries of interest. A program is a set of prioritized transformation rules, and computation consists in successive reduction of queries using meaning-preserving transformation with respect to given background knowledge. We present a formalization of the ET model from the viewpoint of program synthesis, where not only computation but also program correctness and correctness relations are of central importance. The notion of program correctness defines “what it means for a program to be correct with respect to a specification,” and a correctness relation provides guidance on “how to obtain such a program.” The correctness relation of the ET model is established, based on which how the basic structure of the ET model facilitates program synthesis is discussed together with program synthesis strategies in this model.

Keywords: computation model, equivalent transformation, program synthesis, program correctness, rule-based computation

1. Introduction Computation by equivalent transformation (ET) of declarative descriptions was first implemented in experimental natural language understanding systems at Hokkaido University in 1990-1992 and reported in 1992 and 1995 [1, 2]. In addition to extensive use in the domain of first-order terms, the ET computation model has been applied to knowledge processing systems in other data domains such as RDF, UML and XML (e.g., [3, 4, 5]). Experience with a diverse range of applications has indicated attractive model features such as a simple foundation for guaranteeing correct computation results [6], a wide variety of computation and flexible control (e.g., run-time content-based control) [7], and support for stepwise incremental program construction [8]. Vol.10 No.3, 2006

In computation efficiency, it is often possible to construct ET programs that outperform known programs in other mainstream computation models, including logic programming [9], constraint logic programming [10, 11], and functional programming [12], especially in solving large problems. In program construction, correct ET programs are systematically generated from a given specification, and, compared to other computation models, the computation efficiency of a correct program can be improved, while its correctness is maintained, at lower cost. Advantages of the ET model, due largely to its basic structure, are best explained by analyzing the model from the viewpoint of program synthesis, where not only computation but also the possibility and effectiveness of generating correct and efficient programs from specifications are important.

1.1. Program Synthesis Frameworks and Correctness Relations Based on an axiomatic framework developed in [13] for formalizing computation models from the viewpoint of program synthesis, a computation model is characterized as a pair of (1) a program synthesis framework and (2) a correctness relation. The program synthesis framework is further divided into two self-contained components, called a specification universe and a program universe, which altogether provide a structure for defining the notion of program correctness, i.e., “what it means for a program to be correct with respect to a specification.” Specifications and programs are clearly separated because they play basically different roles in program synthesis. The correctness relation represents a sufficient condition for program correctness used as guidance on “how to construct correct programs from a specification.” It provides a key bridge between the program synthesis framework and practical program synthesis – development of methods and strategies for program synthesis demands an appropriate correctness relation. Emphasis on program correctness and correctness relations, in addition to computation, makes this axiomatic framework dramatically different from other computation theories, most of which focus on computation and computable functions.

Journal of Advanced Computational Intelligence and Intelligent Informatics

245

Akama, K., and Nantajeewarawat, E.

pal X  rv X X  rv     rv A X  Y  rv X R ap R A Y  ap   X X  ap A X  Y A Z  ap X Y Z 

Rule

Replaced atom(s)

Fig. 1. Definite clauses defining predicates pal, rv, and ap.

r0 r1

pal t  rv   t 

r2

rv t1 t2  t3 

r3

rv t1 t2 t3 

r4

rv t1 t2  rv t1 t3 

r5

ap t1 t2  t3 

r6

ap t1 t2  t3 t4 t5 

r7

ap t1 t2 t3 t4 

 

r0 : r1 : r2 : r3 :

r5 : r6 :

  rv x x . rv x   x . rv ax y  rv x v ap v a y . rv x ay   x uv  rv v w ap w u ay rv x y rv x z   y z  rv x y . ap x a b   x a b . ap x a b cy   x bv  ap v a cy . ap x y az   x y az ;   x av  ap v y z . 











 















 















 



 



r7 :



pal x



r4 :

Table 1. Rules in Fig.2. t t1 are variables.











  









  









 





t5 are terms and v v1 v2 v3

Replacement Unification after atom(s) replacement rv t t  – –  t   rv t2 v – ap v t1  t3  rv v1 v2   t1 v3 v1  ap v2 v3  t2 t3  rv t1 t2   t2 t3   t1   –  t2 t3  ap v t2  t4 t5   t1 t3 v  t1   –  t2 t3 t4  ap v t2 t4   t1 t3 v







  







Fig. 2. Examples of transformation rules in ETI.

1.2. Overview By formalization, we provide insights into the basic ET model structure and clarify how this model supports program synthesis. Section 2 introduces computation by ET, Section 3 reviews the axiomatic framework [13], and Section 4 deals with the notion of a program universe specialized into that of a state-transition program universe. Section 5 formulates the ET program synthesis framework, defining the ET specification universe and instantiating the notion of a state-transition program universe into the ET model context. Section 6 defines the correctness relation of the ET model and, based on this relation, discusses how the basic structure of the model facilitates program synthesis. Supplementing examples in Sections 5 and 6, Section 7 illustrates rules with extralogical predicates and procedures along with computation involving transformation steps that differ from unfolding steps. The appendix discusses the syntax and operational semantics of rules in an implemented Equivalent Transformation Interpreter (ETI). Although the ET model deals with data structures of various kinds, we limit our focus to the domain of firstorder terms for simplicity.

2. Computation by ET: Example In the ET model, computation consists in successive reduction of problems using meaning-preserving transformation rules. We begin with an example of problemsolving by ET, showing how computation in the ET model differs from that in logic programming. A class of trans246











.





formation rules supported by the ETI 1 – an interpreter developed at Hokkaido University for ET-based problemsolving – is referenced here.

2.1. Computation by Problem Transformation Assume as background knowledge a set D pal consisting of the five definite clauses in Fig.1, where pal, rv, and ap stand for “palindrome,” “reverse,” and “append.” Consider the problem “find all ground terms t such that 1 t  and 2 t  are palindromes,” represented as a set consisting of a single definite clause ansX   pal  1 X  pal  2 X  where ans stands for “answer” and the clause is intended to mean “X is an answer if both 1 X  and 2 X  satisfy the definition of pal given in D pal .” Solving this problem correctly means that all answers are found and that nonexistence of any other answer is known (in finite time). Figure 2 gives transformation rules in ETI for solving this problem. A rule specifies, at left, a pattern of atomic formulas (atoms) to which it is applied and, at right, how to obtain a transformation result. Table 1 describes rules in Fig.2. The row describing r 3 (the fourth row), for example, means: ¯

r3 is applicable to a clause cl containing a body atom b of the form rvt1 t2 t3 , where the ti are arbitrary terms,

¯

when applied, r 3 replaces the body atom b with two atoms rvv1 v2  and apv2 v3  t2 t3 , where v1 v2 v3 are new variables, i.e., variables that do not occur in cl, and,

¯

after replacement, if t1 and v3 v1  are unifiable, the most general unifier of them is applied to the resulting clause; otherwise the resulting clause is removed (the symbol ‘’ denotes a unification operation).

1. ETI is available at http://assam.cims.hokudai.ac.jp/etpro

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model

ans X pal 1X pal 2X  r  ans X rv 1X 1X pal 2X  r  ans X rv 1X 1X rv 2X 2X  r  ans X rv X A1 ap A1 1 1X rv 2X 2X  r  ans X rv X A1 ap A1 1 1X rv X A2 ap A2 2 2X  r  ans X rv X A1 ap A1 1 1X ap A1 2 2X  r  ans rv ap 2 2 , ans X rv X 1A3 ap A3 1 X ap 1A3 2 2X  r  ans rv ap 2 2 , ans A6A4 rv A4 A5 ap A5 A6 1A3 ap A3 1 A6A4 ap 1A3 2 2 A6A4  r  ans rv ap 2 2  r  ans rv  r  ans  





0









 



0





 



2





  



2





  



  



4

  

   

5

   

1

 





  



  







 















 









Fig. 4. Single-head general unfolding-based rules.







  



   

 





     

Fig. 3. Transformation by applying rules in Fig.2.

Table 2. Classifying rules in Fig.2. Type r0 r1 r2 r3 r4 r5 r6 r7 Single-head Multi-head Unfolding-based General Specialized

                      

Other rows in the table are interpreted in the same way. The row describing r 7 (the last row), however, contains two subrows in the third and the fourth columns, meaning that when r7 is applied, a duplicate copy of a clause containing a replaced atom is made, then replacement and unification specified in the first and the second subrows are applied to the original clause and the copy. Note that the row describing r 4 (the fifth row) specifies a pattern of two replaced atoms, i.e., r 4 is applicable to a clause containing two body atoms conforming to the pattern, and when it is applied, the two atoms are simultaneously replaced. The syntax and the operational semantics of rules in ETI are given in the appendix. Figure 3 shows a sequence of problem reduction steps obtained by successively applying these rules, provided that low priority is given to r7 . Replaced atoms are underlined. The sequence changes the initial problem into the singleton set ans  , meaning “the empty list is an answer (unconditionally) to the problem and there exists no other answer.” The correctness of this computation is verified by proving that each rule in Fig.2 is a meaningpreserving rule with respect to D pal . Table 2 categorizes rules in Fig.2. The rule r 4 replaces more than one atom simultaneously and is called a multihead rule. Every other rule in Fig.2 replaces a single atom at a time and is called a single-head rule. Every singlehead rule in the figure operates as an unfolding rule using Vol.10 No.3, 2006



     



 

 



 

   

   

 









6



  rv x x .     y ;    av  rv v w ap w a y . ap x y z y z ;   x   x av z aw  ap v y w . pal x

rv x y  x  x

     





 

  

   



3





 





  

7



the definition of the predicate appearing at its left and is called an unfolding-based rule. The rule r 0 is applicable to any pal-atom containing any arbitrary term and is called a general rule. All other rules in Fig.2 are applicable to atoms having certain specific patterns and are called specialized rules. The use of specialized rules enables content-based control of computation [7] – an appropriate transformation step is decided based on the run-time contents of clauses in a computation state.

2.2. Comparison to Logic Programming When computation by SLD resolution is viewed in the ET framework, expansion of a node (generation of all of its children) in a search tree for finding SLD-refutations corresponds to an unfolding transformation step. As such, computation in logic programming is seen as computation using only one specific class of transformation rules, i.e., single-head general unfolding-based rules. A logic program consisting of the clauses in Fig.1, for instance, is regarded in the ET paradigm as a program consisting of the three single-head general unfolding-based rules in Fig.4. Using such a restricted class of rules alone, it is often difficult to achieve effective computation control, in particular, for preventing infinite computation or for improving computation efficiency. As an example, consider the query in the preceding section, which is represented in logic programming as the goal clause 

pal  1 X  pal  2 X 

When executing this query, any logic program for checking palindromes enters infinite computation after giving X  , i.e., it fails to infer that the empty list is the “only” possible ground instance of X that satisfies the query, and thus does not yield the correct answer set. This difficulty is overcome in the ET model by contentbased control of computation and the possibility of using several types of transformation rules, including specialized and multi-head rules. To illustrate, attention will now be drawn to the role of the multi-head rule r 4 in successful termination of the reduction sequence in Fig.3. First, consider the two atoms pal  1 X  and pal  2 X , and the case when X is instantiated into a nonempty ground list, say lX . Under the definition of pal in Fig.1, the first palatom restricts the last element of lX to 1, whereas the second one restricts it to 2. This contradiction proves the nonexistence of any answer other than X  . In terms of

Journal of Advanced Computational Intelligence and Intelligent Informatics

247

Akama, K., and Nantajeewarawat, E.





Table 3. Descendants of pal 1 X  and pal 2 X  in states directly related to the application of r4 in Fig.3. State 5th 6th



Insights into the interrelationship between programs, specifications, and program correctness: Clear understanding of the notion of program correctness with respect to specifications is indispensable for discussing program synthesis. In most existing theories of program synthesis, e.g., [14, 15], a certain specific class of programs, with certain specific syntax and semantics, is considered, e.g., imperative programs, logic programs, or functional programs. Many specific details of programs and how programs are defined are not truly relevant to the essence of program correctness.2 By considering programs and specifications as abstract entities characterized solely by axioms capturing their roles in program correctness, we provide a more insightful analysis of pertinent concepts, applicable to many classes of programs.

¯

A larger program space possibly considered: Theoretically, program synthesis is viewed as a search in a certain program space for a program that is both correct with respect to a given specification and sufficiently efficient. The possibility that such a program exists in the program space of interest increases as the program space grows. By adopting an axiomatic approach to describing programs, we consider a very large program space.

¯

Importance of correctness relations for analysis of program synthesis: While the notion of program correctness is a necessary basis for program synthesis, it is not used directly in practice – it is not possible to search for correct programs by blindly generating programs, then checking their correctness. Instead, a sufficient condition for program correctness is used, either implicitly or explicitly, to construct correct programs from a given specification. Use of such a sufficient condition, however, imposes a limitation on the programs possibly obtained – correct programs that do not satisfy the sufficient condition will never be constructed. 3 By introducing the notion of a correctness relation as an algebraic representation of a sufficient condition for program correctness, this limitation can be discussed rigorously. More insightful comparisons between program synthesis methods can be made based on analysis of their underlying correctness relations.



Descendants Descendants Common of pal 1 X  of pal 2 X  variables rv X A1 rv X A2 X ap A1 1 1 X  ap A2 2 2 X  rv X A1 ap A1 1 1 X  ap A1 2 2 X  A1, X

 

 

computation, finding this contradiction involves the exchange of information about restrictions on l X between descendants of the first pal-atom and those of the second pal-atom. Now consider the transformation step using the multihead rule r4 in Fig.3. As highlighted in Table 3, prior to this transformation step, X is the only information connection between the two groups of descendants. Via this connection, however, the constraint on the last element of lX cannot be exchanged in a finite form. For example, passing the restriction “the last element of l X must be 1” through X to the descendants of the pal  2 X  entails passing infinitely many patterns such as X  1, X  v1 1, X  v1 v2 1, X  v1 v2 v3 1, and so forth, where the vi are newly introduced variables. With this information connection alone, a contradiction must be found for each such pattern, one at a time, leading to infinite computation. The multi-head rule r4 provides a simple remedy by creating an additional information connection, i.e., A1, through which the constraint on the last element of l X is passed to apA1 2 2 X  as a single finite pattern, i.e., A1  1 v, where v is some new variable (see the second row in Table 3). Consequently, the all-embracing contradiction can be found using a finite number of transformation steps. Such an additional information connection (common variable) cannot be created by single-head rules. Since computation in logic programming corresponds to computation using only single-head general unfolding-based rules, no logic program for checking palindromes can use an information connection other than X when executing the query  pal  1 X  pal  2 X , and therefore fails to terminate.

3. Basic Formalization Framework After explaining the motivation for developing a new basic framework in [13] and introducing some preliminary notations, we present the notions of a specification universe, a program universe, a program synthesis framework, program correctness, and a correctness relation.

3.1. Motivation Reasons for developing an axiomatic framework for formalizing computation models in [13] include: 248

¯

By instantiating the axiomatic framework of [13] into the context of a specific computation model, the basic structure of the computation model can be examined in terms of program synthesis. Based on this framework, a scheme for comparing computation models by analyzing their correctness relations is discussed in [16].

2. “Program correctness” herein does not refer to “syntactic correctness” of programs. The term “program” itself is intended to mean a “syntactically correct program.” 3. Unless it is also a necessary condition, a sufficient condition for program correctness need not be satisfied by every correct program.

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model

3.2. Preliminary Notation The notation that follows holds thereafter. Given a set A, powA denotes the power set of A. For any binary relation r, domr denotes the domain of r. A partial mapping f and a total mapping g from a set A to a set B are denoted by f : A   B and g : A  B, respectively. Given f : A   B and a  A, f a is said to be defined if a  dom f , and is said to be undefined otherwise. For any nonempty sequence s, f irst s denotes the first element of s, and, if s is finite, last s denotes its last element. 3.3. Specification and Program Universes A specification universe provides a structure for characterizing specifications in terms of the problems they cover, and for defining the answers to these problems. It is formulated as follows:

1. compute : P ROG P ROB   powC OMP, 2. obtain : P ROG C OMP   A NS . The sets P ROG , P ROB , C OMP , and A NS are called the program space, the problem space, the computation space, and the answer space, respectively, of Π. Their elements are called programs, problems, computations, and answers, respectively. Given a program prg  P ROG and a problem prb  P ROB , if compute prg prb is defined, then each computation in compute prg prb is called a computation of prg on prb. A program prg  P ROG is said to be deterministic if for any prb  P ROB , there is at most one computation of prg on prb, and it is said to be nondeterministic otherwise. Given a program prg  P ROG and a computation com  C OMP , if obtain prg com is defined, it is called the answer obtained from com with respect to prg.

Definition 1: A specification universe Σ is a 5-tuple 

S PEC P ROB A NS cover answer

where S PEC P ROB , and A NS are sets, and 1. cover : S PEC  powP ROB,

Note that Definition 2 accounts for possible nondeterministic behavior of a program by allowing more than one computation of it on a single problem, i.e., compute is a partial mapping to powC OMP, rather than to C OMP .

2. answer : S PEC P ROB   A NS . The sets S PEC , P ROB , and A NS are called the specification space, the problem space, and the answer space, respectively, of Σ. Their elements are called specifications, problems, and answers, respectively. Given a specification S  S PEC , each problem in coverS is said to be covered by S. Given a specification S  S PEC and a problem prb  coverS, if answerS prb is defined, it is called the answer to prb with respect to S. As will be seen in Section 5.3, since an answer space can be a power set, the answer to a problem is possibly an answer set. The concept of specification considered in this framework is suitable for discussing program correctness in many computation models, including the logic programming model, the constraint logic programming model, and the functional programming model. It differs, however, from specifications usually used in software engineering, which are given in varying degrees of formality and precision, ranging from informal descriptions to mathematical notations, e.g., Z [17]. 4 In that context, stepwise refinement is a basic means of program development, e.g., [18, 19, 20], and the notion of program correctness differs from that discussed here. Next, a program universe is recalled. It specifies a domain of programs, determines all possible computations of each program, and defines answers obtained from computations. Definition 2: A program universe Π is a 6-tuple 

P ROG P ROB C OMP A NS compute obtain

where P ROG P ROB C OMP , and A NS are sets, and 4. In a formal approach such as Z notation, a specification is often given in terms of preconditions, postconditions, and invariants.

Vol.10 No.3, 2006

3.4. Program Correctness A specification universe Σ and a program universe Π are said to be compatible iff they have the same problem space and the same answer space. A program synthesis framework is a pair Σ Π of a specification universe Σ and a program universe Π such that Σ and Π are compatible. In the sequel, let Σ Π be a program synthesis framework, where Σ  S PEC P ROB A NS cover answer and Π  P ROG P ROB C OMP A NS compute obtain . The concept of program correctness – “what it means for a program to be correct with respect to a specification” – will now be formulated. Definition 3: Let S be a specification in S PEC. A program prg  P ROG is said to be correct with respect to S on Σ Π iff for each problem prb  coverS, the following conditions are satisfied: 1. compute prg prb is defined. / 2. compute prg prb  0. 3. For each com  compute prg prb, a obtain prg com is defined, and b if answerS prb is defined, then obtain prg com  answerS prb. When Σ Π is clear from the context, the qualification “on Σ Π ” is often dropped. Note that, as a consequence of Condition 3 of Definition 3, given a nondeterministic program prg, a specification S, and a problem prb covered by S, if prg is correct with respect to S and the answer to prb with respect to S is defined, then for any computations com and com ¼ of prg on prb,

Journal of Advanced Computational Intelligence and Intelligent Informatics

249

Akama, K., and Nantajeewarawat, E.

obtain prg com  obtain prg com ¼, i.e., the choice of computations of prg on prb does not affect the obtained answer. Next, the correct-program space of Σ Π , which is a subset of S PEC P ROG , is defined. Definition 4: The correct-program space of Σ Π is the set consisting of every pair S prg  S PEC P ROG such that prg is correct with respect to S.

3.5. Program Synthesis and Correctness Relations A program synthesis problem is described as follows: given a specification S  S PEC , construct a program prg  P ROG such that prg is correct with respect to S, and prg is sufficiently efficient. The definition of program correctness (Definition 3) does not suggest any practical method for construction of correct programs. 5 Designing a program synthesis system demands a sufficient condition for program correctness that reduces the problem of checking program correctness to simpler subproblems and provides guidance on “how to construct correct programs from a specification.” A sufficient condition Cond for program correctness on Σ Π determines a binary relation Corr from S PEC to P ROG such that for each pair S prg  S PEC P ROG , Corr contains S prg iff prg satisfies Cond for being correct with respect to S. This binary relation Corr is always a subset of the correct-program space of Σ Π , and is referred to as a correctness relation on Σ Π . The sufficient condition Cond and the correctness relation Corr are two sides of the same coin – Cond provides an intensional description of Corr, while Corr is an algebraic representation of the extension of Cond. In the sequel, the two concepts are mutually identified. Definition 5: A correctness relation on Σ Π is a subset of the correct-program space of Σ Π . Different program synthesis frameworks normally support different correctness relations for program synthesis.

4. State-Transition Program Universes Computing in many models, including computation models in declarative paradigms and those in imperative paradigms, takes a certain form of (nondeterministic) state transition [21],6 and a class of program universes, called state-transition program universes deserves special attention. Such a program universe is formulated using the following template: 1. Determine a set S TATE of states, and designate a set I NI S TATE as the set of initial states and a set F IN S TATE as the set of final states. 5. Definition 3 provides a necessary and sufficient condition for program correctness, but does not suggest how to obtain a correct program from a specification. 6. Every sequential algorithm can be step-for-step simulated by an appropriate state machine (Gurevich’s sequential abstract state machine thesis) [21].

250

2. Determine a set P ROG of programs, and a mapping

τ : P ROG  powS TATE F IN  S TATE  for associating with each program prg in P ROG a binary relation from S TATE F IN  to S TATE representing all possible state transitions that prg can cause. 3. Determine a set P ROB of problems, and a mapping makeState : P ROB  I NI for associating an initial state with a problem. 4. Let C OMP be the set of all nonempty sequences of states in S TATE .  powC OMP  as 5. Define compute : P ROG P ROB  follows: For any prg  P ROG and prb  P ROB , a computation of prg on prb is a nonempty finite or infinite sequence com  st 0 st1 st2    of states such that

a st0  makeState prb, b for any two successive states st i sti sti sti 1  τ  prg,

1

in com,

 domτ  prg, c if com is finite, then last com 

and compute prg prb is the set of all computations of prg on prb. 6. Determine a set A NS of answers, and a mapping makeAns : F IN  A NS for defining the answer obtained from a final state.  A NS as follows. 7. Define obtain : P ROG C OMP  For any prg  P ROG and com  C OMP , if com is finite and last com  F IN , then

obtain prg com  makeAnslast com; otherwise obtain prg com is undefined. The program universe P ROG P ROB C OMP A NS compute obtain thus obtained is called a state-transition program universe. Since programs are characterized as binary relations, rather than functions, on states, construction of a computation of a program is in general nondeterministic. Note that a final state is typically a state from which an answer can be obtained at low cost, and that, due to possible failure to reach a final state in finite steps, obtain is in general not a total mapping.

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model

5. ET Program Synthesis Framework We explain the motivation for formalizing the ET model using the framework of [13], provide basic definitions related to declarative descriptions in the domain of first-order terms, then formulate the ET program synthesis framework in this domain. Program correctness is illustrated. The correctness relation of the ET model is defined in Section 6.

5.1. Motivation A diverse range of ET-based applications has been implemented. Methods and tools for program synthesis in the ET model have been developed and applied to construct many nontrivial programs. Extensive practical experience yields the following observations: ¯

The ET computation model appears to include many computation models as its subclasses.

¯

The ET model is particularly suitable for program synthesis; correct and efficient programs are constructed in this model at relatively low cost.

These observations require rational explanation. A theoretical foundation for conducting analysis is lacking. The framework of [13] provides a promising basis for this purpose for several reasons: ¯

Understanding of the basic ET model structure: Clear understanding of specifications, programs, computations, and program correctness in the ET model and how they interrelate is a prerequisite to examining the observations. This is achieved by instantiating the notion of a specification universe and that of a program universe into the ET model context.

¯

Establishment of the correctness relation of the ET model: Differentiation between program correctness and a correctness relation used for program synthesis is a characteristic feature of the framework of [13]. The correctness relation of the ET model simplifies the task of program construction by restricting the class of transformation rules to be considered to that of ET rules,7 and assuring that a program consisting of ET rules is always correct provided the program terminates successfully, i.e., terminates and reaches a final state.

¯

Foundation for program synthesis in the ET model: By the basic structure of the ET model, ET rules are mutually independent, i.e., augmenting a program with a new ET rule does not affect the correctness of any existing ET rule in the program. This property and the correctness relation of the ET model together provide a basis for program synthesis and suggest a basic program synthesis methodology, i.e., program synthesis in the ET model is realized as a process of step-by-step accumulation of ET rules,

7. The precise definition of an ET rule is given in Section 6.1.

Vol.10 No.3, 2006

following certain strategies for guaranteeing successful program termination and for improving program efficiency. Based on this, we clarify ET model advantages in program synthesis. ¯

Comparison between computation models: Once formalized based on the same framework, the ET model and other computation models can be rigorously compared, and subsumption relations between them can be precisely discussed. Formalizing the ET model is a step toward this study. Formalization of other computation models and development of a general theory for comparing computation models based on the framework of [13] are now in progress. 8

5.2. Declarative Descriptions and Meanings An alphabet Δ  K F V R is assumed, where K is a set of constants, F a set of function symbols, V a set of variables, and R the union of two disjoint sets of predicate symbols R1 and R2 . Given R¼ R, first-order atoms on ¼ ¼ K F V R are referred to as atoms on R . For each i  1 2, let A and G denote the set of all atoms on R i i i and that of all ground atoms on R i , respectively. Let A  A1  A2 and G  G1  G2 . Let S denote the set of all substitutions on Δ. A definite clause cl on Δ is an expression of the form a  b1    bn , where a b1    bn  A and n  0. The atom a is called the head of cl, denoted by head cl . The set b1    bn  is called the body of cl, denoted by bodycl , and each of its elements is called a body atom of cl. When n  0, cl is called a unit clause. A declarative description is a set of definite clauses. Let R a and Rb be subsets of R. A definite clause cl is said to be from R a to Rb iff every element of bodycl  is an atom on R a and head cl  is an atom on R b . A declarative description from Ra to Rb is a set of definite clauses from R a to Rb . Given a declarative description D, a mapping TD on powG is defined by TD G  head cl θ  cl  D & θ  S & bodycl θ  G & head cl θ   G, for each G G, and theËmeaning of D, denoted by MD, is defined by MD  ∞n1 TDn 0/ , where TD1 0/   TD 0/  and TDn 0/   TD TDn 1 0/  for each n  2.

5.3. ET Specification Universe An ET-problem is a singleton set of definite clause from R1 to R2 .9 An ET-specification is a pair D Q , where D is a declarative description from R 1 to R1 and Q is a set of ET-problems. The ET specification universe Σ ET  S PEC P ROB A NS cover answer is defined by: ¯

S PEC is the set of all ET-specifications.

8. Formalization of the logic programming model and of the constraint logic programming model are given in [13] and [22], and a scheme for comparing computation models is discussed in [16]. 9. An ET-problem may also be defined as a set of one or more definite clauses from R1 to R2 whose heads are the same atom. However, by using a different partition of R, such a set can always be reduced to a singleton set without loss of expressiveness.

Journal of Advanced Computational Intelligence and Intelligent Informatics

251

Akama, K., and Nantajeewarawat, E.

Drv



 rv

   

 

¯

A state is a declarative description from R 1 to R2 . It is an initial state iff it consists of exactly one definite clause. It is a final state iff it consists only of unit clauses. Let S TATE , I NI , and F IN be the sets of all such states, initial states, and final states, respectively.

¯

 , where Rule is a An ET-program is a pair Rule  set of transformation rules (or rules, for short), each of which is a binary relation from S TATE F IN  to S TATE , and  is a total quasi-order on Rule. 10 Given  st  S TATE F IN , a rule r  Rule is said to be applicable to st iff st  domr, and r is said to transform st into st ¼ iff st st ¼  r. Given rules r r ¼  Rule,  let r  r¼ denote r  r ¼  & r ¼  r, and r  r ¼  ¼ ¼   denote r  r  & r  r. The total quasi-order  prioritizes the rules in Rule, i.e., if r  r ¼ , then r ¼  takes priority over r (when they are both applicable, r is not used), and if r  r ¼ , then r and r ¼ have the same priority (when they are both applicable, one is selected nondeterministically). Let P ROG be the set of all ET-programs.

¯

Define a mapping

rv A X  Y  rv X R ap R A Y , ap   X X  , ap A X  Y A Z  ap X Y Z 

Q f wd



Qbwd







ans v rv gl v   gl is a finite ground list ans v rv v gl   











gl is a finite ground list &

S1  Drv Q f wd S2  Drv Qbwd S3  Drv Q f wd

 



Q

prb1  ans X  prb2  ans X 

bwd

V  vV 

& v

 

 

rv 1 2 X  rv X 1 2

Fig. 5. Examples of ET-specifications and ET-problems.

¯

P ROB is the set of all ET-problems.

¯

A NS  powG2 .

¯

For each D Q  S PEC , coverD Q   Q.

¯

For any D Q  S PEC and prb  P ROB ,

τ : P ROG  powS TATE F IN  S TATE   be an ET-program. as follows: Let prg  Rule  Given st  S TATE F IN , let AppRule st  denote the set of all rules in Rule that are applicable to st. Then define τ  prg as the binary relation

answerD Q prb  Tprb MD Hereinafter, assume that rv (“reverse”) and ap (“append”) are predicates in R 1 and ans (“answer”) is a predicate in R2 . Standard Prolog notation for lists is used. Elements of ΣET are illustrated below. Example 1: Figure 5 defines a declarative description Drv from R1 to R1 , ET-specifications S1 , S2 and S3 , and ET-problems prb1 and prb2. The problem prb 1 is covered by S1 and S3 , but not by S 2 ; the problem prb2 is covered by S 2 and S3 , but not by S 1 . With reference to S1 (and S3 ), prb1 represents the query “find every ground instance of X that makes rv 1 2 X  satisfy the definition of rv given in Drv .” The answer to prb 1 with respect to S1 (and S3 ) is defined using the mapping answer as the set Tprb MDrv   ans 2 1, indicating that 2 1 is the 1 only such ground instance of X. The same set is also the answer to prb2 with respect to S2 (and S3 ). An answer in Σ ET may contain more than one element. For example, let prb  ansX Y   apX Y 1 2. The answer to prb with respect to D rv Q , where Q contains prb, is the 3-element set ans  1 2 ans 1 2 ans 1 2 .

5.4. ET Program Universe The ET program universe Π ET is defined as a statetransition program universe using the template given in Section 4 as follows: 252

st st ¼  S TATE F IN  S TATE r  maxAppRule st    & r transforms st into st ¼ ,



 denotes where for any Rule ¼ Rule, maxRule¼  the set of all maximal elements of Rule ¼ with respect to  .11 

¯

P ROB is the set of all ET-problems.

¯

For any prb  P ROB , makeState prb  prb.

¯

A NS  powG2.

¯

For any st  F IN , makeAnsst  is the set 





a   st  & θ



S & aθ



G

The examples below illustrate elements of Π ET . They refer to the declarative description D rv and the ETproblems prb1 and prb2 in Fig.5.

10. A quasi-order (or preorder) on a set A is a reflexive and transitive relation on A. It induces an equivalence relation on A, given by: x y iff x y and y  x for any x y  A. A quasi-order on A is said to be total iff x  y or y  x for any x y  A. 11. That is, maxRule¼  is the set r  Rule¼  there exists no r¼  Rule¼ such that r  r¼ .

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model 

ans X rv 1 2 X , ans X rv 2 R1 ap R1 1 X , ans X rv R2 ap R2 2 R1 ap R1 ans X ap 2 R1 ap R1 1 X , ans X ap 2 1 X , ans 2Z3 ap 1 Z3 , ans 2 1  





 











 



 



  





   









  









 

1





X ,





 

  



  

 

  



 

   



 



 

  



  





  

 











  

 













  





Fig. 8. Finite computation of prg1 on prb2 .

  

 





  





  





 







ans X rv X 1 2 , ans A1X1 rv X1 R1 ap R1 A1 1 2 , ans A1 ap A1 1 2 ans A1 A2X2 rv X2 R2 ap R2 A2 R1 ap R1 A1 1 2 , ans A1 ap A1 1 2 ans A1 A2 ap A2 R1 ap R1 A1 1 2 ans A1 A2 A3X3 rv X3 R3 ap R3 A3 R2 ap R2 A2 R1 ap R1 A1 ans A1 ap A1 1 2 



 

Fig. 7. Infinite computation of prg1 on prb1 .

Example 2: Let a rule run f be defined as follows: for any st  S TATE F IN  and st ¼  S TATE , st st ¼  run f iff st ¼ is obtained from st by unfolding some definite clause cl in st with respect to some atom in bodycl  using D rv . Let   , where r prg1 be an ET-program run f   un f  run f . A finite computation of prg 1 on the problem prb 1 is shown in Fig.6, where atoms with respect to which unfolding is applied are underlined. The answer obtained from this computation, determined by the mapping obtain, is the set ans 2 1, which coincides with the answer to prb 1 defined by Σ ET (Example 1). Fig.7 shows another computation of prg1 on prb1, where unfolding is applied with respect to an ap-atom whenever possible. Such a transformation step always creates a new clause containing another ap-atom. This computation is thus infinite and the obtained answer is undefined. Figures 8 and 9 show a finite computation and an infinite computation, respectively, of prg 1 on prb2. The next example shows that some computations may be excluded when a set of prioritized unfolding rules, instead of a single unfolding rule, is used. Example 3: Let rules rrv0 and rap0 be defined as follows: for any st  S TATE F IN  and st ¼  S TATE , st st ¼ belongs to rrv0 (respectively, rap0 ) iff there exists a definite clause cl in st such that bodycl  contains some rv-atom (respectively, apatom) b, and st ¼ is obtained from st by unfolding cl with respect to

Vol.10 No.3, 2006









 



 











 



 

 



 

 





 























 







¯















¯

 

 





  

 















 





   

 













   

  

 

























ans X rv 1 2 X , ans X rv 2 R1 ap R1 1 X , ans 1 rv 2 , ans A2Z2 rv 2 A2X2 ap X2 1 Z2 , ans 1 rv 2 , ans A2 1 rv 2 A2 , ans A2 A3Z3 rv 2 A2 A3X3 ap X3 1 Z3 , ans 1 rv 2 , ans A2 1 rv 2 A2 , ans A2 A3 1 rv 2 A2 A3 , ans A2 A3 A4Z4 rv 2 A2 A3 A4X4 ap X4 1 Z4 , 



 

Fig. 6. Finite computation of prg1 on prb1 . 

ans X rv X 1 2 , ans A1X1 rv X1 R1 ap R1 A1 1 2 , ans A1X1 rv X1 1X2 ap X2 A1 2 , ans 2X1 rv X1 1 ans A1X1 rv X1 1 2X3 ap X3 A1 , ans 2X1 rv X1 1 , ans 2 A4X4 rv X4 R4 ap R4 A4 1 , ans 2 1X4 rv X4 ans 2 A4X4 rv X4 1X5 ap X5 A4 , ans 2 1X4 rv X4 , ans 2 1 ans 2 1 A6X6 rv X6 R6 ap R6 A6 , ans 2 1 

 

















 1



2 ,

ans A1 A2 ap   A2 R1 ap R1 A1 1 2 ans A1 A2 A3 ap   A3 R2 ap R2 A2 R1 ap R1 A1 1 2 , ans A1 A2 A3 A4 X4 rv X4 R4 ap R4 A4 R3 ap R3 A3 R2 ap R2 A2 R1 ap R1 A1 1 2 ,











Fig. 9. Infinite computation of prg1 on prb2 .

b using Drv .  , where r Let prg2 be an ET-program rrv0 rap0   rv0  rap0 . Then the computation in Fig.8, but not that in Fig.9, is a computation of prg 2 on prb2 . Every other computation of prg2 on prb2 is a variant of it.

Since rrv0 is applicable to rv-atoms of any pattern, it is regarded as a general rule for rv-atoms. Likewise, r ap0 is a general rule for ap-atoms. Rules devised for atoms of specific patterns, called specialized rules, are shown next. Example 4: Table 4 defines four rules by specifying the pattern of atoms that each rule replaces, the pattern of replacement atoms, and the substitution applied after the replacement, where for any terms t and t ¼ , mgut t ¼  denotes the most general unifier of t and t ¼ . The row describing the rule rap2 , for example, means that: for any st  S TATE F IN  and st ¼  S TATE , st st ¼ belongs to rap2 iff ¯

there exists a definite clause cl in st such that bodycl  contains an atom b of the pattern

Journal of Advanced Computational Intelligence and Intelligent Informatics

253

Akama, K., and Nantajeewarawat, E.

Table 4. Specialized rules used in Example 4. t t1 are terms and v is a variable. Rule rrv1

Replaced atom rv

  t



rrv2

rv t1 t2  t3 

rap1 rap2

ap   t1 t2  ap t1 t2  t3 t4 





t4

Replacement Substitution applied atom(s) after replacement – mgu   t  rv t2 v, – ap v t1  t3  – mgu t1 t2  ap t2 t3 v mgu t4 t1 v

st ¼ is obtained from st by the following steps: (1) introduce a new variable v that does not occur in cl, (2) replace b with apt 2 t3 v, and (3) if t4 and t1 v are unifiable, then apply the most general unifier of them to the resulting clause, otherwise remove the clause.

Other rows in this table are interpreted in the same way. Let prg3 be an ET-program rrv1 rrv2 rap1 rap2   , where r rv1  rrv2  rap1  rap2 . The computation in  Fig.6, but not that in Fig.7, is a computation of prg 3 on the problem prb 1, and every other computation of prg 3 on prb1 is a variant of it. When it is applied to the problem prb 2, however, the program prg3 fails to reach a final state and thus yields no answer. The next example shows that, by setting appropriate rule priority, the specialized rules in Table 4 can be used in tandem with the general rules in Example 3 to produce only finite computations reaching final states, when they are applied to prb 1 and prb2. Example 5: Referring to Examples 3 and 4, let prg 4 be  , where an ET-program rrv0 rrv1 rrv2 rap0 rap1 rap2   rrv0  rap0  rrv1  rrv2  rap1  rap2 . The set of all computations of prg 4 on prb1 (respectively, of prg 4 on prb2 ) is exactly the same as the set of all those of prg 3 on prb1 (respectively, of prg 2 on prb2). Each of these computations terminates and reaches a final state. The use of specialized rules enables content-based control of computation [7], i.e., appropriate transformation steps are selected based on the run-time content of states. The possibility of increasing the number of clauses in a state reduces as the pattern of a replaced atom becomes more specific. Specialized rules in general thus yield more efficient computation. As will be seen in Section 6.2, adding specialized rules to a program is one basic strategy for program synthesis. See Example 7 for improvement of prg 4 using this strategy.

5.5. Program Correctness on the ET Program Synthesis Framework An ET-program receives from Definition 3 (Section 3.4) the necessary and sufficient condition for being correct with respect to an ET-specification. 254

prg1 prg2 prg3 prg4

S1 not correct not correct correct correct

S2 not correct correct not correct correct

S3 not correct not correct not correct correct



ap t1 t2  t3 t4 , where the ti are arbitrary terms, and ¯

Table 5. Correctness of programs in Examples 2–5.

Example 6: Consider the program prg 2 of Example 3 and the specifications in Fig.5. Some computation of prg 2 on a problem covered by S 1 is infinite (see, e.g., Fig.7) and thus the answer obtained from it is undefined. So prg2 is not correct with respect to S 1 . Since each problem covered by S 1 is covered by S 3 , prg2 is also not correct with respect to S3 . Let prb be a problem covered by S 2 and com a computation of prg 2 on prb. It can be shown that com is always finite (see, e.g., Fig.8). Moreover, since unfolding is a meaning-preserving operation, the answer obtained from com always coincides with the answer to prb defined by Σ ET . The program prg 2 is therefore correct with respect to S2 . Table 5 summarizes the correctness of the ET-programs in Examples 2-5 with respect to the specifications S1 , S2 , and S3 in Fig.5. The incorrectness of these programs arises from the failure to reach a final state in finite transformation steps.

6. ET Model Correctness Relation This section establishes the correctness relation of the ET model, referred to as Corr ET , and discusses how the fundamental structure of the model supports program synthesis based on this correctness relation.

6.1. Correctness Relation Corr ET The notion of an ET rule and that of state reachability used for defining the correctness relation Corr ET are given first. 6.1.1. ET Rules and ET Rule Independence Let D be a declarative description from R 1 to R1 . A rule r is said to be correct with respect to D iff for any ¼ st st  r, MD  st   MD  st ¼  A rule that is correct with respect to D is called an ET rule with respect to D. An important property of ET rules is that the correctness of one rule is totally independent of any other rule. This property is referred to as “independence of ET rules.” As will be seen in Section 6.2, program synthesis in the ET model enjoys this property.

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model

6.1.2. State Reachability A state st ¼ is said to be reachable from a state st using an ET-program prg iff there exists a sequence seq  st0 st1    stn  of states (n  1) such that ¯ ¯

st0  st and stn  st ¼ , for any two successive states st i sti sti 1  τ  prg.

1

in seq, sti

Given an ET-program prg and an ET-specification S, let reach prg S denote the set of all states that are reachable using prg from makeState prb for some problem prb  coverS. 6.1.3. Correctness Relation Corr ET The definition of Corr ET and the proof that it is a correctness relation on Σ ET ΠET are given below. Definition 6: For any ET-specification S  D Q and  , S prg  Corr ET-program prg  Rule  ET iff the following conditions are satisfied: 12 (ETR) Rule consists only of ET rules with respect to D. (TER) For each prb  coverS, if com  compute prg prb, then com is finite. (APP) reach prg S F IN domτ  prg. Theorem 1: Corr ET is a correctness relation on the program synthesis framework Σ ET ΠET . Proof: Let S prg  Corr ET , where S  D Q and  , and prb  Q. By the definition of a prg  Rule  computation of prg on prb in Step 4 of Section 4, there always exists at least one computation of prg on prb, i.e., compute prg prb  0. / Let com be a computation of prg on prb. By Condition (TER), com is finite. Assume that last com   F IN . So last com  reach prg S F IN. By Condition (APP), last com  domτ  prg, which contradicts Condition 0c of Step 4 of Section 4. Hence last com  F IN . Then  prg com  domobtain. It follows that answerS prb  T prb MD  MD  prb  G 2 (since D is from R1 to R1 but prb is from R1 to R2 )  MD  f irst com  G 2  MD  last com  G 2 (by Condition (ETR))  aθ a   last com & θ  S & aθ  G (since last com consists only of unit clauses)  obtain prg com

6.2. Corr ET as a Program Synthesis Basis The correctness relation Corr ET reduces the problem of constructing correct programs to three subproblems: 12. (ETR), (TER), and (APP) are abbreviations for “ET rules alone,” “termination of computation,” and “applicability of a program to non-final states,” respectively.

Vol.10 No.3, 2006

1. how to generate ET rules with respect to a given declarative description, 2. how to ensure termination of computation (how to satisfy Condition (TER)), and 3. how to ensure transition of non-final states (how to satisfy Condition (APP)). The first subproblem is self-contained and can be solved purely algorithmically. An algorithm for generating (specialized) ET rules, based on meta-computation, was devised in [23] – given a declarative description D and a pattern of atoms as inputs, the algorithm automatically generates ET rules with respect to D for transforming atoms conforming to the input pattern. The second subproblem is not separate from the third – preventing infinite computation may reduce the possibility of transforming non-final states. Based on the property “independence of ET rules,” program synthesis strategies are introduced for tackling these two subproblems. They include: [ST1] For (APP), general ET rules are useful. [ST2] For (TER) and for improvement of computation efficiency, specialized ET rules should be added and should take priority over general ET rules. [ST3] For (TER), each specialized ET rule should be safe for termination, i.e., its application should result in (1) replacement of an atom with simpler atoms, (2) removal of an atom, or (3) removal of a clause. [ST4] For (APP), when a definite clause to which no existing specialized rule is applicable is found in a non-final state, one or more body atoms in that clause should be selected, and then, a specialized ET rule for transforming the selected atoms should be added. By “independence of ET rules,” addition of a new ET rule to a program does not affect the quality of “being an ET rule” of any other rule in the program, and thus does not threaten Condition (ETR). As a result, a program can be incrementally constructed by following the above strategies. The next example outlines construction of the program prg4 of Example 5, along with improvement of its efficiency while maintaining its correctness. Example 7: By [ST1], first introduce the two general rules rrv0 and rap0 of Example 3. Their widest applicability guarantees that (APP) is satisfied. By setting r rv0  rap0 , these two rules satisfy (TER) when applied to problems in Qbwd (see, e.g., Example 3) but not when applied to those in Q f wd . By [ST2] and [ST4], in order to deal with problems in Q f wd , the four specialized rules in Table 4 are then added, and they should take priority over r rv0 and rap0 . The addition conforms to [ST3], i.e., all of these specialized rules are safe for termination – for example, rrv2 is safe since its application always replaces an atom a of the form rv t1 t2  t3  with atoms b and b ¼ of the forms

Journal of Advanced Computational Intelligence and Intelligent Informatics

255

Akama, K., and Nantajeewarawat, E.

Table 6. Additional specialized rules. t t1 and v v1 v2 v3 are variables. Replaced atom rv t

 



rv t1 t2 t3 

Replacement atom(s) – rv v1 v2 , ap v2 v3  t2 t3 



ap t1 t2  t3 



ap t1 t2  t3 t4 t5 

ap v t2  t4 t5 









t5 are terms

7. Supplementary Rule Examples

















 





  

 









  

 





Fig. 10. Computation obtained by applying rules in Table 6.



Although program synthesis strategies are illustrated, it should be noted that how the structure of the ET model facilitates program synthesis, rather than the methodology for program synthesis, is of primary concern here.







rvt2 v and apv t1 t3 , respectively, where b is simpler than a since t2 is simpler than t1 t2 , and b¼ is simpler than a since rv is defined using ap in D rv .13 By giving these four specialized rules the same priority, they satisfy both (TER) and (APP) when applied to problems in Q f wd (see, e.g., Example 4). The program prg 4 is now obtained. Each rule in this program is an ET rule with respect to D rv and can be generated using the algorithm in [23]. Strategy [ST2] suggests that the efficiency of prg 4 can be improved by adding specialized rules for handling problems in Qbwd . Following [ST4], the four specialized ET rules in Table 6 are generated for this purpose by using the algorithm in [23]. 14 These new rules take priority over the general rules r rv0 and rap0 . Figs.10 and 11 show computations of the resulting program on the problem prb2. Every other computation of this program on prb2 is a variant of one of these. Observe that they contain fewer states than computations obtained by applying the general rules rrv0 and rap0 to the same problem (e.g., Fig.8). The specialized rules in Table 6 are safe for termination – [ST3] is fulfilled. After these specialized rules are added, the general rules r rv0 and rap0 are no longer used when the program is applied to problems in Q f wd  Qbwd ; the two general rules can thus be removed without affecting Condition (APP), and of course without affecting (TER) and (ETR).







mgu t1 v3 v1 

Æ



 

Substitution applied after replacement mgu t  

θ mgu t2 θ t3 θ , where θ  mgu t1   mgu t1 t3 v

ans X rv X 1 2 , ans A1X1 rv X1 R1 ap R1 A1 1 2 , ans A1X1 rv X1 1X2 ap X2 A1 2 , ans 2X1 rv X1 1 , ans 2 A3X3 rv X3 R3 ap R3 A3 1 , ans 2 1X3 rv X3 , ans 2 1 



ans X rv X 1 2 , ans A1X1 rv X1 R1 ap R1 A1 1 2 , ans A1X1 rv X1 1X2 ap X2 A1 2 , ans A1 A3X3 rv X3 R3 ap R3 A3 1X2 ap X2 A1 2 , ans 2 A3X3 rv X3 R3 ap R3 A3 1 , ans 2 1X3 rv X3 , ans 2 1  

































 







 





  



 



  



  

 



Fig. 11. Computation obtained by applying rules in Table 6.

folding are also often used. Table 7 gives examples of such rules (min stands for “minimum”). Each rule in the table is applicable to a clause containing an atom minl t , where l is a list and t is a term, if its applicability condition (specified in the third column) is satisfied. When it is applied, a new list l ¼ is constructed by a procedure associated with it (specified in the fourth column), and then the atom minl t  is replaced with minl ¼ t . For any list l and term t, the conditions int t , existGt l t , existDi f l , and existDupl  mean “t is an integer,” “l contains some integer greater than t,” “l contains at least two different integers,” and “l contains repeated elements,” respectively; and the procedures rmGt l t l ¼ , rmGtDi f l l ¼ , and rmDupl l ¼  construct a list l ¼ from l by removing each integer greater than t, removing each integer greater than some other integer in l, and eliminating repetition in l, respectively. Note that the four predicates used in the applicability conditions are all extralogical predicates, e.g., int Y  is false and existDup 1 X Y X  is true. Applying rules in Table 7 combined with unfoldingbased rules often yields a considerable efficiency gain. To illustrate, let N be the set of all nonnegative integers, and min, gt, and le be predicates in R 1 ; and, referring to the declarative descriptions D min , Dgt , and Dle in Fig.12, let rules rmn 4 , rmn 5 , and rrel be defined as follows:

General and specialized rules in Sections 5.4 and 6.2 are devised based on unfolding operation. 15 In the ET model, specialized rules that function differently from un-

¯

rmn 4 and rmn 5 are rules for unfolding a clause using Dmin with respect to atoms of the forms min t  t ¼  and min t1 t2 l  t , respectively, where t t ¼ t1 t2 are terms and l is either a list or a variable;

13. Since rv is defined using ap, reduction of an rv-atom into an ap-atom is considered as a simplification. More precise sufficient conditions for ET-program termination are given in [24]. 14. In Table 6, Æ denotes substitution composition. 15. Although applicable to atoms of specific patterns, specialized rules in Examples 4, 5, and 7 yield transformation steps that are similar to unfolding steps. For example, the application of the third rule in Table 6 to the third state in Fig.10 and the two successive unfolding steps applied to the same state in Fig.8 result in the same state.

¯

rrel is a rule for unfolding a clause using D gt  Dle with respect to atoms of the form rel i j, where rel  gt le and i j  N.

256

Let the six rules be prioritized by rmn 5  rrel



rmn 4  rmn 3  rmn 2  rmn 1 

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model

Table 7. Rules with applicability conditions and execution parts. l l are lists and t is a term. ¼

Applicability Execution part Replacement Rule Replaced atom condition atom int t , rmn 1 min l t  rmGt l t l  min l t  existGt l t  rmn 2 min l t  existDi f l  rmGtDi f l l  min l t  rmn 3 min l t  existDup l  rmDup l l  min l t  ¼

¼

¼

¼

¼



Dmin  min X  X  , min A B R M  min A B R M  Dgt Dle

 

 gt i j  le i j

 









¼

 





Fig. 12. Definitions of min, gt, and le.

Figure 13 shows a computation resulting from applying these prioritized rules to the ET-problem ansX Y   min Y 3 6 X  min X 5 8 Y 7 1



which represents the query “find X and Y such that the minimum value among Y , 3, and 6 is X, and the minimum value among X, 5, 8, Y , and 7 is 1.” In the figure, rules are applied in this order: rmn 2 , rmn 1 , rmn 5 , rmn 4 , rmn 1 , rmn 4 , rrel , rmn 4 , rmn 3 , rmn 4 , and rrel . An experimental study showed that when only unfolding-based rules are applied, more than 60 transformation steps are required for finding the answer to the query. In comparison, the computation in Fig.13 yields the answer in only 11 transformation steps. The rules rmn 1 , rmn 2 , and rmn 3 are also ET rules with respect to Dmin  Dgt  Dle .

8. Conclusions Computation in many existing computation models, including logic programming, functional programming, and constraint handling rules, can be regarded as special forms of ET. However, computation by other forms of ET is also often useful, especially for program termination and for improving computation efficiency. By its basic structure, the ET model enables exploitation of a very large class of transformation rules – any rule whose application always results in meaning-preserving transformation with respect to given background knowledge serves as an ET rule. As a consequence, various specific subclasses of rules, with varying expressive power, can be introduced, and a variety of concrete forms of rules can be devised. For example, in the ETI implemented at Hokkaido University, rules with applicability conditions, possibly involving extralogical predicates, rules with execution parts, and multi-head rules are provided. By the basic model structure, the correctness of a rule is verified individually, and is not threatened by the addition Vol.10 No.3, 2006

ans X Y min Y 3 6 X min X 5 8 Y 7 1 , ans X Y min Y 3 X min X 5 8 Y 7 1 , ans X Y min Y 3 X min X Y 1 , ans X Y gt Y 3 min 3 X min X Y 1 , le Y 3 min Y X min X Y 1 , ans X Y ans 3 Y gt Y 3 min 3 Y 1 , le Y 3 min Y X min X Y 1 , ans X Y ans 3 Y gt Y 3 min Y 1 , le Y 3 min Y X min X Y 1 , ans X Y ans 3 1 gt 1 3 , le Y 3 min Y X min X Y 1 , ans X Y ans X Y le Y 3 min Y X min X Y 1 , ans X X le X 3 min X X 1 , ans X X le X 3 min X 1 , ans 1 1 le 1 3 , ans 1 1  













































 













 





























 





 



 























 













 

















 





gt A B min B R M , le A B min A R M 

 i j  N and i j  i j  N and i j





 







Fig. 13. Computation in which some reduction steps are not unfolding steps.

of any other rule – stepwise incremental program construction and improvement are inherently supported. In conjunction with a wide variety of available rule classes, this feature enhances the possibility of constructing correct and efficient programs from specifications. References: [1] K. Akama, “Semantic Processing of Natural Language Sentences by Equivalent Transformation,” Hokkaido University Information Engineering Technical Report, HIER-LI-9225, 1992. [2] K. Akama, Y. Nomura, and E. Miyamoto, “Semantic Interpretation of Natural Language Descriptions by Program Transformation,” Computer Software, Vol.12, No.5, pp. 45-62, 1995. [3] C. Anutariya et al., “RDF Declarative Description (RDD): A Language for Metadata,” Journal of Digital Information, Vol.2, No.2, 2001. [4] E. Nantajeewarawat et al., “Toward Reasoning with Unified Modeling Language Diagrams Based-on Extensible Markup Language Declarative Description Theory,” International Journal of Intelligent Systems, Vol.19, pp. 89-98, 2004. [5] V. Wuwongse et al., “A Data Model for XML Databases,” Journal of Intelligent Information Systems, Vol.20, No.1, pp. 63-80, 2003. [6] K. Akama, T. Shimizu, and E. Miyamoto, “Solving Problems by Equivalent Transformation of Declarative Programs,” Journal of the Japanese Society for Artificial Intelligence, Vol.13, pp. 944-952, 1998. [7] K. Akama, E. Nantajeewarawat, and H. Koike, “A Class of Rewriting Rules and Reverse Transformation for Rule-Based Equivalent Transformation,” Electronic Notes in Theoretical Computer Science, Vol.59, No.4, pp. 1-16, 2001. [8] K. Akama, E. Nantajeewarawat, and H. Koike, “Program Synthesis Based on the Equivalent Transformation Computation Model,” in Proc. the 12th Intl. Workshop on Logic Based Program Synthesis and Transformation, Madrid, Spain, pp. 285-304, 2002. [9] J. W. Lloyd, “Foundations of Logic Programming,” second, extended edition, Springer-Verlag, 1987. [10] T. Fr¨uhwirth, “Theory and Practice of Constraint Handling Rules,” Journal of Logic Programming, Vol.37, pp. 95-138, 1998. [11] J. Jaffar et al., “The Semantics of Constraint Logic Programs,” Journal of Logic Programming, Vol.37, pp. 1-46, 1998. [12] P. Hudak, “Conception, Evolution and Application of Functional Programming Languages,” ACM Computing Surveys, Vol.21, No.3, pp. 359-411, 1989. [13] K. Akama, and E. Nantajeewarawat, “Formalization of Computation Models in View of Program Synthesis,” in Proc. the 4th Intl. Conference on Intelligent Technologies, Chiang Mai, Thailand, pp. 507-516, 2003. [14] A. Pettorossi, and M. Proietti, “Rules and Strategies for Transforming Functional and Logic Programs,” ACM Computing Surveys, Vol.28, No.2, pp. 360-414, 1996.

Journal of Advanced Computational Intelligence and Intelligent Informatics

257

Akama, K., and Nantajeewarawat, E.

             min l1 t existDi f l1   rmGtDi f l1 l2  min l2 t . min l1 t existDup l1   rmDup l1 l2  min l2 t .

min l1 t  int t  existGt l1 t  rmGt l1 t l2 min l2 t . 















Fig. 14. Rules in ETI corresponding to rules in Table 7.

[15] A. Pettorossi, and M. Proietti, “Transformation of Logic Programs,” in D. M. Gabbay, C. J. Hogger, and J. A. Robinson, Eds., Handbook of Logic in Artificial Intelligence and Logic Programming, Vol.5, Oxford University Press, pp. 697-787, 1998. [16] K. Akama, and E. Nantajeewarawat, “Computation Frameworks, Program Synthesis, and Correctness Relations,” Technical Report, Information Initiative Center, Hokkaido University, 2004. [17] J. Woodcock, and J. Davies, “Using Z Specification, Refinement and Proof,” Prentice Hall, 1996. [18] C. Morgan, “Programming from Specifications,” International Series in Computer Science, Prentice Hall, 1994. [19] J. M. Morris, “A Theoretical Basis for Stepwise Refinement and the Programming Calculus,” Science of Computer Programming, Vol.9, No.3, pp. 287-306, 1987. [20] N. Wirth, “Program Development by Stepwise Refinement,” Communications of the ACM, Vol.14, No.4, pp. 221-227, 1971. [21] Y. Gurevich, “Sequential Abstract-State Machines Capture Sequential Algorithms,” ACM Transactions on Computational Logic, Vol.1, No.1, pp. 77-111, 2000. [22] K. Akama, and E. Nantajeewarawat, “Formalization of the Constraint Logic Programming Computation Model,” Technical Report, Information Initiative Center, Hokkaido University, 2004. [23] H. Koike, K. Akama, and E. Boyd, “Program Synthesis by Generating Equivalent Transformation Rules,” in Proc. the 2nd Intl.Conference on Intelligent Technologies, Bangkok, Thailand, pp. 250-259, 2001. [24] I. Takarajima et al., “Design of Termination for Non-Deterministic Programs Based on the Equivalent Transformation Computation Model,” in Proc. the 5th Intl. Conference on Intelligent Technologies, Houston, Texas, pp. 226-235, 2004.

the Bsi are sequences of (usual) atoms. The part Cs is called the applicability-condition part of r. For each i (1  i  n), the pair Esi  Bsi  is called a body of r, and Esi  and Bsi are called an execution part and a replacement part, respectively. The applicability-condition part and each of the execution parts are optional. When Hs contains more than one atom, r is called a multi-head rule, otherwise a single-head rule. Variables used in transformation rules and those used in definite clauses are of different types (they have different instantiation characteristics). For syntactically clear distinction, the former variables always have an asterisk prefixed to their names. Given a definite clause C containing atoms b1    bm , where m  1, in its antecedent, the rule r is applicable to C at b 1    bm iff Hs matches these atoms by a substitution θ (i.e., Hsθ is the sequence b1    bm ) and the evaluation of Csθ succeeds. To apply r to the clause C, the pattern-matching substitution θ is additionally required to instantiate all variables that occur in r but not in Hs into distinct usual variables that do not occur in C. The application then replaces C with clauses obtained as follows: for each i (1  i  n), if the evaluation of Esi θ succeeds and yields a substitution σ , then a clause obtained from Cσ by replacing b 1 σ    bm σ with Bsi θ σ is constructed. To simplify the presentation, we assume here that the evaluation of Csθ specializes neither an execution part nor a replacement part – all rules illustrated herein satisfy this condition. Figure 14 shows rules in ETI that correspond to the rules in Table 7. For a more detailed description of rule semantics in ETI, see [7].

Appendix A. Transformation Rules in ETI In ETI, an executable atom is used in a transformation rule to denote an operation that is realized by some predefined deterministic procedure. Referring to Fig.2 and Table 7, for example, t t ¼ , rmGt l n l ¼ , and int t  are executable atoms that denote the operations “find the most general unifier of terms t and t ¼ ,” “construct a list l ¼ by removing each integer greater than n from a list l,” and “check whether a term t is an integer,” respectively. Such an atom is evaluated by some predetermined evaluator, and if evaluation succeeds, it yields a substitution as the result. For example, the evaluation of the executable atoms  1 X  Y 2 3, rmGt  3 1 5 X  2 L, and int 7 yield X  2 3 Y 1, L 1 X , and the identity substitution, respectively. A transformation rule (or rule) r in ETI takes the form Hs Cs

Es1  Bs1 ;

  

Esn  Bsn ,

 

where n  1, Hs is a nonempty sequence of (usual) atoms, Cs and the Esi are sequences of executable atoms, and 258

Journal of Advanced Computational Intelligence and Intelligent Informatics

Vol.10 No.3, 2006

Formalization of the Equivalent Transformation Computation Model

Name:

Name:

Kiyoshi Akama

Ekawit Nantajeewarawat

Affiliation:

Affiliation:

Professor, Division of Large-Scale Computational Systems, Information Initiative Center, Hokkaido University

Associate Professor, Computer Science Program, Sirindhorn International Institute of Technology, Thammasat University

Address:

Address:

Kita 11 Nishi 5, Kita-ku, Sapporo, Hokkaido 060-0811, Japan

P.O. Box 22, Thammasat-Rangsit Post Office, Rangsit Campus, Pathumthani 12121, Thailand

Brief Biographical History: 1981.4- Instructor, Hokkaido University (Faculty of Letters) 1989.4- Associate Professor, Hokkaido University (Faculty of Engineering) 1999.4- Professor, Hokkaido University (Center for Information and Multimedia Studies) 2003.4- Professor, Hokkaido University (Information Initiative Center)

Brief Biographical History:

Main Works:

Membership in Learned Societies:

 “Formalization of Computation Models in View of Program Synthesis,” Proc. of the 4th International Conference on Intelligent Technologies (InTech 2003), Chiang Mai, Thailand, pp. 507-516, 2003.

1998- Assistant Professor, IT Program, Sirindhorn Intl. Inst. of Tech. 2002- Associate Professor, CS Program, Sirindhorn Intl. Inst. of Tech.

Main Works:

 “Declarative Programs with Implicit Implication,” IEEE Transactions on Knowledge and Data Engineering, Vol.14, pp. 836-849, Aug., 2002.

 The Association for Computing Machinery (ACM)

Membership in Learned Societies:

 The Japanese Society for Artificial Intelligence (JSAI)  Information Processing Society of Japan (IPSJ)

Vol.10 No.3, 2006

Journal of Advanced Computational Intelligence and Intelligent Informatics

259