Constraint Logic Programming: a Survey
Total Page:16
File Type:pdf, Size:1020Kb
J LOGIC PROGRAMMING to app ear Constraint Logic Programming A Survey Joxan Jaffar and Michael J Maher Constraint Logic Programming CLP is a merger of two declarativepara digms constraint solving and logic programming Though a relatively new eld CLP has progressed in several quite dierent directions In particu lar the early fundamental concepts have b een adapted to b etter servein dierent areas of applications In this survey of CLP a primary goal is to give a systematic description of the ma jor trends in terms of common fun damental concepts The three main parts cover the theory implementation issues and programming for applications Intro duction Constraint Logic Programming CLP b egan as a natural merger of two declarative paradigms constraint solving and logic programming This combination helps make CLP programs b oth expressive and exible and in some cases more ecient than other kinds of programs Though a relatively new eld CLP has progressed in several and quite dierent directions In particular the early fundamental concepts have b een adapted to b etter serve in dierent areas of applications In this survey of CLP a primary goal is to give a systematic description of the ma jor trends in terms of common fundamental concepts Consider rst an example program in order to identify some crucial CLP con cepts The program b elow denes the relation sumton n for natural numb ers n sumto sumtoN S N N S sumtoN S N The query S sumtoN S gives rise to three answers N S Address correspondenceto Joxan Jaar and Michael Maher IBM Thomas J Watson Research Center PO Box Yorktown Heights NY USA Email fjoxanmjmgwatsonibmcom FINAL DRAFT Comments esp ecially ab out errors are solicited N S andN S and terminates The computation sequence of states for the third answer for example is S sumtoN S S N N S S N N S sumtoN S N S N N S S N N S N N S N S N N S N S N sumto S N N S S N N S N N S N S N N S N S N The constraints in the nal state imply the answer N S Termination is reasoned as follows Any innite computation must use only the second program rule for state transitions This means that its rst three states mustbeasshown ab ove and its fourth state must b e S N N S S N N S N N S N S N N S N N S N S N N S sumto We note nowthatthiscontains an unsatisable set of constraints and in CLPno further reductions are allowed This example shows the following key features in CLP Constraints are used to sp ecify the query as well as the answers During execution new variables and constraints are created The collection of constraints in every state is tested as a whole for satisa bility b efore execution pro ceeds further In summary constraints are used for inputoutput dynamically generated and globally tested in order to control execution Constraint Languages Considerable work on constraint programming languages preceded logic program ming and constraint logic programming Weno w briey survey some imp ortant works with a view toward the following features Are constraints used for in putoutput Can new variables andor constraints b e dynamically generated Are constraints used for control What is the constraint solving algorithm and to what extent is it complete What follows is adapted from the survey in SKETCHPAD was p erhaps the earliest work that one could classify as a constraint language It was in fact an interactive drawing system allowing the user to build geometric ob jects from language primitives and certain constraints The constraints are static and were solved by lo cal propagation and relaxation tech niques See chapter in for an intro duction to these and related techniques Subsequent related work was THINGLAB whose language to ok an ob ject oriented avor While lo cal propagation and relaxation were also used to deal with the essentially static constraints the system considered constraint solving in two dierent phases When a graphical ob ject is manipulated a plan was generated for quickly resolving the appropriate constraints for changed part of the ob ject This plan was then rep eatedly executed while the manipulation continued Works following the THINGLAB tradition included the Filters Pro ject and Animus Another graphical system this one fo cusing on geometrical layout was JUNO The constraints were constructed as in THINGLAB by text or graphical primitives and the geometric ob ject could b e manipulated A dierence from the ab ovementioned works is that constraint solving was p erformed numerically using a NewtonRaphson solver Another collection of early works arose from MIT motivated by applications in electrical circuit analysis and synthesis gave rise to languages for general problem solving In the CONSTRAINTS language variables and constraints are static and constraint solving was limited to using lo cal propagation An extension of this work provided a more sophisticated environment for constraint programming including explanation facilities Some other related systems ELARS and SYN used the constraintsolver MACSYMA toavoid the restrictions of that there was a conceptual lo cal propagation It was noted at this p erio d corresp ondence b etween the constrainttechniques and logic programming The REFARF system was also designed for problem solving One comp o nent REF was essentially a pro cedural language but with nondeterminism b ecause of constraints used in conditional statements The constraints are static They are in fact linear integer constraints and all variables are b ounded ab ove and b elow The constraint solver ARF used backtracking The Bertrand system was designed as a metalanguage for the building of constraint solvers It is itself a constraint language based on term rewriting Constraints are dynamic here and are used in control All constructs of the lan guage are based on augmented rewrite rules and the programmer adds rules for the sp ecic constraint solving algorithm to b e implemented PostCLP there have b een a numberofworks which are able to deal with dy namic constraints The language LP is describ ed to b e a CLP language with a Clike syntax for representing and solving combinatorial problems Obtaining parallel execution is one of the main ob jectives of this work The commercial lan guage CHARME also based on a pro cedural framework arose from the work on CHIP by essentially omitting the logic programming part of CHIP The subse quentwork ILOG which is also commercial is a library of constraint algorithms designed to work with C programs Using a pro cedural language as a basis intro duced Constraint Imp erative Programming which has explicit constraints in the usual way and also a new kind of constraints obtained by considering variable assignments suchasx x as timestamp ed Such assignments are treatable as constraints of the form x x Finallywe mention ConstraintFunc i i tional Programming whose goal is the amalgamation of the ideas of functional programming found in the HOPE language with constraints There is work on languages and systems which are not generally regarded as constraint languages but are nevertheless related to CLP languages The develop ment of symb olic algebra systems suchasMACSYMA concentrated on the solving of dicult algebraic problems The programming language asp ects are less develop ed Languages for linear programming provide little more than a prim itive do cumentation facility for the array of co ecients whichisinputinto a linear programming mo dule In parallel with the development of these constraint languages muchwork was done on the mo delling of combinatorial problems as Constraint Satisfaction Prob lems CSPs and the development of techniques for solving such problems The work was generally indep endentofany host language A p ossible exception is ALICE which provided a wide variety of primitives to implement dierent search techniques One imp ortantdevelopmentwas the denition and study of several notions of consistencyThiswork had a signicant inuence on the later development of the CLP language CHIPWe refer the reader to foranintro duction to the basic techniques and results concerning CSPs Finallywe mention the survey which deals not just with constraint programming languages but constraintbased programming techniques Logic Programming Next we consider conventional logic programming LP and argue by example that hanges to LP systems the p ower of CLP cannot b e obtained by making simple c The question at hand is whether predicates in a logic program can b e meaningfully regarded as constraints That is is a predicate with the same declarative semantics as a constraint a sucient implementation of the constraint as p er CLP Consider for example the logic program add N N addsN M sK addN M K where natural numb ers n are represented by ss with n o ccurrences of s Clearly the meaning of the predicate addn m k coincides with the relation n m k However the query addN M K addN M sKwhich is clearly unsatisable runs forever in a conventional LP system The imp ortant p oint here is that a global test for the satisabilityofthetwo add constraints is not done by the underlying LP machinery In this example the problem is that the add predicate is not invoked with a representation of the add constraints collected so far and neither do es it return such a representation after having dealt with one more constraint More concretely the second subgoal of the query ab ove is not given a representation of the fact that N M K A partial solution