Logic Program Synthesis
Total Page:16
File Type:pdf, Size:1020Kb
J. LOGIC PROGRAMMING 1993:12:1{199 1 LOGIC PROGRAM SYNTHESIS YVES DEVILLE AND KUNG-KIU LAU > This pap er presents an overview and a survey of logic program synthesis. Logic program synthesis is interpreted here in a broad way; it is concerned with the following question: given a sp eci cation, howdowe get a logic pro- gram satisfying the sp eci cation? Logic programming provides a uniquely nice and uniform framework for program synthesis since the sp eci cation, the synthesis pro cess and the resulting program can all b e expressed in logic. Three main approaches to logic program synthesis by formal metho ds are describ ed: constructive synthesis, deductivesynthesis and inductive syn- thesis. Related issues such as correctness and veri cation as well as syn- thesis by informal metho ds are brie y presented. Our presentation is made coherentbyemploying a uni ed framework of terminology and notation, and by using the same running example for all the approaches covered. This pap er thus intends to provide an assessment of existing work and a framework for future research in logic program syn- thesis. < 1. INTRODUCTION Program synthesis refers to the elab oration of a program in some systematic man- ner, starting from a sp eci cation, that is a statement describing what the program should do. A sp eci cation mayhavemany forms. We can distinguish formal sp eci- cations from informal ones. For the latter, the synthesis pro cess cannot b e totally formalised and can only b e partially automated. Wethus distinguish b etween syn- thesis by formal methods and synthesis by informal methods . Address correspondencetoUnite d'Informatique,Universite Catholique de Louvain, Place Ste Barb e, 2, B-1348 Louvain-la-Neuve, Belgium. Address correspondencetoDepartment of Computer Science, UniversityofManchester, Oxford Road, Manchester M13 9PL, United Kingdom. THE JOURNAL OF LOGIC PROGRAMMING c Elsevier Science Publishing Co., Inc., 1993 655 Avenue of the Americas, New York, NY 10010 0743-1066/93/$3.50 2 Program synthesis in general has b een an active area of research outside logic programming. See [BGK84,Bal85, Gol86, Bie92], for example, for a presentation of the ma jor achievements. In the early days of logic programming, logic program synthesis was one of the rst areas of active research, mainly fo cusing on manual program derivation. By the middle eighties, however, this work had dwindled considerably. More recently, it has b ecome an active area of research once again, this time fo cusing mainly on automated or semi-automated synthesis. In this pap er, wegive a brief survey of the work to date in logic program synthesis. Logic program synthesis is concerned with the following: Given a (non-executable) sp eci cation, how to get an (executable) logic program satisfying the sp eci cation? where the notions of \sp eci cation" and \executability" are interpreted broadly. For tackling this problem, logic programming provides a uniquely uniform frame- work b ecause the sp eci cation, the synthesis pro cess and the resulting program can all b e expressed in logic. There are three main approaches to logic program synthesis by formal metho ds: 1 In the constructive approach, a conjecture based on the sp eci cation is constructively proved, and from this pro of the sp eci ed program is extracted. We call this approach constructive synthesis . A more direct approach is to deduce clauses for the sp eci ed program directly from the sp eci cation. We shall call this approach deductive synthesis . Another approach can induce a program from a partial sp eci cation of the program. The program is a generalisation of the partial sp eci cation. We shall call this approach inductive synthesis . This survey covers all the ab ove approaches. Related issues such as correctness and veri cation, as well as synthesis by informal metho ds will brie y b e presented. This pap er do es not cover some other synthesis approaches, suchasknowledge- based synthesis [Smi90], synthesis by insp ection (see [BF82, BGK84]), b ecause very little work has b een done using these approaches in logic programming. Thus this survey covers only the program synthesis part of the so-called program development area. Program developmentisamuch larger area since it also includes other asp ects such as program analysis (e.g. abstract interpretation, termination) and program transformation (e.g. fold/unfold, partial evaluation), inter alia (see related pap ers in this Sp ecial Issue for other asp ects of Program Development). Indeed for the whole pro cess of program development, we should consider the re- alistic scenario depicted by the spiral: (informal sp eci cation ! incomplete formal sp eci cation ! unsatisfactory program ! b etter sp eci cation ! more satisfactory program, and so on). This scenario shows the development pro cess as a life-cycle, within which program synthesis enables a transition from sp eci cation to program. We will not deal with this entire life-cycle in this survey. Rather, we concentrate on synthesis metho ds. However, the reader should b ear in mind the larger context of program development. The distinction b etween deductive program synthesis and program transforma- tion is rather sub jective and often dep ends on the context of the research. A 1 Also known as the proofs-as-programs approach, after [BC85]. 3 p ossible di erence could b e that synthesis starts from some non-executable sp ec- i cation, which usually means a non-recursive description of the problem, whilst transformation usually starts from an already executable description. Program transformation will b e covered by a separate survey in this volume. We shall not cover other related logic programming topics such as programming environments, inductive logic programming, and semantics. Our aim for this survey is to provide a broad, extensive (and hop efully complete) survey in the eld of logic program synthesis. We shall give a coherent presentation using a uni ed framework of terminology and notation, and the same running ex- ample for all the approaches covered. By so doing, we shall attempt to exp ose the similarities and dissimilarities b etween the di erent approaches, and to evaluate their resp ective strengths and weaknesses. Given the space limit, it is not p ossible to describ e all the theoretical background necessary for a full treatment of the examples, or the theoretical diculties and unsolved theoretical problems for each metho d. Nevertheless, a basic knowledge of logic programming will b e sucient to get a precise idea of the synthesis metho ds presented. However, the reader will need to read the original pap ers for a deep er understanding. We hop e this pap er provides an assessment of existing work and a framework for future research in logic program synthesis. The pap er is organised as follows. In Section 2 we de ne and explain the basic concepts. In Sections 3, 4, 5, and 6, we present an account of constructivesyn- thesis, deductive synthesis, inductivesynthesis and synthesis by informal metho ds resp ectively.Ineach of these sections, we describ e the approach, show the running example for this approach, and give a brief overview of existing metho ds using the approach. Finally, in Section 7, we conclude with an assessment of existing work and pro er our views on the wayahead. 2. BASIC CONCEPTS In this section, we rst de ne and describ e basic concepts such as sp eci cations and programs, and then weintro duce commonly used notions of program correctness, in the framework of logic programming. Finally,wegiveanoverview of correctness criteria and veri cation metho ds that have b een prop osed. 2.1. Speci cations and Programs A sp eci cation can b e formal or informal; a program can b e either a pure logic program or a program in an existing logic programming language such as Prolog. An informal sp eci cation describ es what will b e called the intended relation. This is the relation the programmer/sp eci er has in mind when synthesising a program. De nition 1. The intendedrelation for a predicate r (of arity n), denoted by I (r ), is a set (of n-tuples) of ground terms. Example 2. Apairhl ;l i b elongs to I (incl uded)i l , l are ground lists, and 1 2 1 2 all the elements of l b elong to l . 1 2 4 The intended relation for a predicate r can also b e seen as a sp eci c (Herbrand) interpretation for the predicate r . In logic programming, formal sp eci cations are usually expressed in some logic. Such a sp eci cation will b e called a logic sp eci cation. De nition 3. A logic speci cation of a predicate r , denoted Spec(r )isasetof logical formulas involving r . In the ab ove de nition, the form of the logic formulas de ning a logic sp eci- cation is delib erately vague, to allow sp eci cations by examples and incomplete sp eci cations. The logic formulas of a logic sp eci cation Spec(r ) necessarily involve predicate r , but can also contain other predicates de ned within the sp eci cation, or de ned elsewhere (primitives or other sp eci cations). In Example 4, the predicate member is assumed to b e a primitivesuchthat member (H; L) holds i H is a memb er of list L. In practice, member can b e sp eci ed in another sp eci cation, or together with the sp eci cation of incl uded. The second logic sp eci cation in Example 4 is a \sp eci cation by examples".