The Art of Prolog

ly, this program guesses nondeterministically the correct permutation via permutation(Xs,Ys), and ordered checks that the permutation is actually ordered. Operationally, the behavior is as follows. A query involving sort is reduced to a query involving permutation and ordered. A failure-driven loop ensues. A permutation of the list is generated by permutation and tested by ordered. If the permuted list is not ordered, the execution backtracks to the permutation goal, which generates another permutation to be tested. Eventually an ordered permutation is generated and the computation terminates. Permutation sort is a highly inefficient sorting algorithm, requiring time super-exponential in the size of the list to be sorted. Pushing the tester into the generator, however, leads to a reasonable algorithm. The generator for permutation sort, permutation, selects an arbitrary element and recursively permutes the rest of the list. The tester, ordered, verifies that the first two elements of the permutation are in order, then recursively checks the rest. If we view the combined recursive permutation and ordered goals as a recursive sorting process, we have the basis for insertion sort, Program 3.21. To sort a list, sort the tail of the list and insert the head of the list into its correct place in the order. The arbitrary selection of an element has been replaced by choosing the first element. Another example of the advantage of intertwining generating and testing can be seen with programs solving the N queens problem. The N queens problem requires the placement of N pieces on an Nby-N rectangular board so that no two pieces are on the same line: horizontal, vertical, or diagonal. The original formulation called for 8 queens to be placed on a chessboard, and the criterion of not being on the same line corresponds to two queens not attacking each other under the rules of chess. Hence the problem's name. 253 Nondeterministic Programming

[1]  Akikazu Takeuchi,et al.  Partial Evaluation of Prolog Programs and its Application to Meta Programming , 1986, IFIP Congress.

[2]  Leon Sterling,et al.  An explanation shell for expert systems , 1986, Comput. Intell..

[3]  Lee Naish,et al.  Automating Control for Logic Programs , 1985, J. Log. Program..

[4]  Arun Lakhotia,et al.  Incorporating 'Programming Techniques' into Prolog Programs , 1989, NACLP.

[5]  Robert A. Kowalski,et al.  Algorithm = logic + control , 1979, CACM.

[6]  David H. D. Warren Logic programming and compiler writing , 1980, Softw. Pract. Exp..

[7]  Krzysztof R. Apt,et al.  Contributions to the Theory of Logic Programming , 1982, JACM.

[8]  DONALD MICHIE,et al.  “Memo” Functions and Machine Learning , 1968, Nature.

[9]  Leon Sterling,et al.  Meta-Level Inference and Program Verification , 1982, CADE.

[10]  Benjamin Kuipers,et al.  Computer power and human reason , 1976, SGAR.

[11]  John W. Lloyd,et al.  Analysis of Meta-Programs , 1989, META.

[12]  J. A. Robinson,et al.  A Machine-Oriented Logic Based on the Resolution Principle , 1965, JACM.

[13]  Richard A. O'Keefe,et al.  Efficient Implementation of a Defensible Semantics for Dynamic PROLOG Code , 1987, International Conference on Logic Programming.

[14]  Leon Sterling,et al.  Composing Prolog Meta-Interpreters , 1988, ICLP/SLP.

[15]  JACQUES COHEN,et al.  Describing Prolog by its interpretation and compilation , 1985, CACM.

[16]  Albert Bruffaerts,et al.  Negation as Failure: Proofs, Inference Rules and Meta-Interpreters , 1989, International Workshop on Meta-Programming in Logic.

[17]  Mihai Nadin T. Winograd, Language as a Cognitive Process, Volume I: Syntax , 1985, Artif. Intell..

[18]  Luís Moniz Pereira Logic Control with Logic , 1982, Implementations of Prolog.

[19]  Leon Sterling,et al.  Metainterpreters for Expert System Construction , 1989, J. Log. Program..

[20]  Alberto Martelli,et al.  An Efficient Unification Algorithm , 1982, TOPL.

[21]  Robert A. Kowalski,et al.  Logic for problem solving , 1982, The computer science library : Artificial intelligence series.

[22]  William F. Clocksin,et al.  Programming in Prolog , 1987, Springer Berlin Heidelberg.

[23]  Kenneth M. Kahn,et al.  A Primitive for the Control of Logic Programs , 1984, SLP.

[24]  James R. Slagle,et al.  Experiments With Some Programs That Search Game Trees , 1969, JACM.

[25]  Leon Sterling,et al.  A prototype expert system for credit evaluation , 1986 .

[26]  MinkerJack,et al.  Logic and Databases: A Deductive Approach , 1984 .

[27]  Helder Coelho,et al.  Prolog by Example , 1988, Symbolic Computation.

[28]  Lee Naish,et al.  Negation and Control in Prolog , 1986, Lecture Notes in Computer Science.

[29]  John C. Mitchell,et al.  On the Sequential Nature of Unification , 1984, J. Log. Program..

[30]  John Darlington,et al.  A Transformation System for Developing Recursive Programs , 1977, J. ACM.

[31]  Takashi Chikayama,et al.  Unique Features of ESP , 1984, FGCS.

[32]  John P. Gallagher,et al.  Transforming Logic Programs by Specialising Interpreters , 1986, ECAI.

[33]  Mehmet Dincbas,et al.  Metacontrol of Logic Programs in Metalog , 1984, FGCS.

[34]  R. Schank,et al.  Inside Computer Understanding: Five Programs Plus Miniatures , 1982 .

[35]  Joxan Jaffar,et al.  From Unification to Constraints , 1987, LP.

[36]  Raf Venken A Prolog Meta-Interpreter for Partial Evaluation and its Application to Source to Source Transformation and Query-Optimisation , 1984, ECAI.

[37]  C. Yates Recursive Functions , 1970, Nature.

[38]  Mike Paterson,et al.  Linear unification , 1976, STOC '76.

[39]  Ellis Horowitz,et al.  Fundamentals of Computer Algorithms , 1978 .

[40]  Ehud Shapiro,et al.  A subset of Concurrent Prolog and its interpreter , 1988 .

[41]  Simin Nadjm-Tehrani,et al.  Algorithmic Debugging with Assertions , 1989, META.

[42]  Chris Moss,et al.  Cut and Paste - defining the impure Primitives of Prolog , 1986, ICLP.

[43]  David H. D. Warren,et al.  Definite Clause Grammars for Language Analysis - A Survey of the Formalism and a Comparison with Augmented Transition Networks , 1980, Artif. Intell..

[44]  Ehud Y. Shapiro Alternation and the Computational Complexity of Logic Programs , 1984, J. Log. Program..

[45]  Stuart M. Shieber,et al.  Prolog and Natural-Language Analysis , 1987 .

[46]  Henryk Jan Komorowski,et al.  A specification of an abstract Prolog machine and its application to partial evaluation , 1981 .

[47]  Richard A. O'Keefe,et al.  On the Treatment of Cuts in Prolog Source-Level Tools , 1985, SLP.

[48]  Leon Sterling,et al.  An Integrated Interpreter for Explaining Prolog's Successes and Failures , 1989, International Workshop on Meta-Programming in Logic.

[49]  Maurice Bruynooghe,et al.  The memory management of PROLOG implementations , 1980 .

[50]  Deyi Li A PROLOG database system , 1984 .

[51]  Chris Mellish,et al.  Some Global Optimizations for a Prolog Compiler , 1985, J. Log. Program..

[52]  Alan Bundy,et al.  Meta-Level Inference , 1984 .

[53]  Ehud Shapiro,et al.  Algorithmic Program Debugging , 1983 .

[54]  Jeffrey D. Ullman,et al.  Introduction to Automata Theory, Languages and Computation , 1979 .

[55]  David A. Watt,et al.  Pascal, an introduction to methodical programming , 1978 .

[56]  Nils J. Nilsson,et al.  Problem-solving methods in artificial intelligence , 1971, McGraw-Hill computer science series.

[57]  F. Harary,et al.  The theory of graphs and its applications , 1963 .

[58]  Keith L. Clark,et al.  A First Order Theory of Data and Programs , 1977, IFIP Congress.

[59]  Verónica Dahl,et al.  Logic Grammars , 1989, Symbolic Computation.

[60]  Kazunori Ueda,et al.  What is a Variable in Prolog? , 1984, Fifth Generation Computer Systems.

[61]  Gerald J. Sussman,et al.  Structure and interpretation of computer programs , 1985, Proceedings of the IEEE.

[62]  Luís Moniz Pereira,et al.  How to solve it with prolog , 1982 .

[63]  Ewing L. Lusk,et al.  Experiments with OR-Parallel Logic Programs , 1987, ICLP.

[64]  E. W. Elcock The Pragmatics of Prolog: Some Comments , 1983, Logic Programming Workshop.

[65]  Joxan Jaffar,et al.  Completeness of the Negation as Failure Rule , 1983, IJCAI.

[66]  Michael Kifer,et al.  HiLog: A First-Order Semantics for Higher-Order Logic Programming Constructs , 1989, NACLP.

[67]  Nils J. Nilsson,et al.  Principles of Artificial Intelligence , 1980, IEEE Transactions on Pattern Analysis and Machine Intelligence.

[68]  J. D. Uiiman,et al.  Principles of Database Systems , 2004, PODS 2004.

[69]  Harvey Abramson,et al.  Meta-programming in logic programming , 1989 .

[70]  N.R. Malik,et al.  Graph theory with applications to engineering and computer science , 1975, Proceedings of the IEEE.

[71]  Steve Gregory,et al.  Parallel logic programming in parlo9 , 1987 .

[72]  Ehud Y. Shapiro,et al.  Logic Programs With Uncertainties: A Tool for Implementing Rule-Based Systems , 1983, IJCAI.

[73]  David H. D. Warren,et al.  Generating Conditional Plans and Programs , 1976, AISB.

[74]  J. Lloyd Foundations of Logic Programming , 1984, Symbolic Computation.

[75]  Ehud Y. Shapiro,et al.  Playing mastermind logically , 1983, SGAR.

[76]  Alan Bundy,et al.  Using Meta-Level Inference for Selective Application of Multiple Rewrite Rules in Algebraic Manipulation , 1980, CADE.

[77]  Leon Sterling,et al.  Pressing for Parallelism: A Prolog Program made Concurrent , 1986, J. Log. Program..

[78]  Alan Bundy A generalized interval package and its use for semantic checking , 1984, TOMS.

[79]  Keith L. Clark,et al.  A relational language for parallel programming , 1981, FPCA '81.

[80]  Robert A. Kowalski,et al.  The early years of logic programming , 1988, CACM.

[81]  Marek Sergot,et al.  A Query-the-User Facility for Logic Programming , 1984, ECICS.

[82]  Gerald Jay Sussman,et al.  The Art of the Interpreter or, The Modularity Complex (Parts Zero, One, and Two) , 1978 .