A Third Look At Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.1.

Slides:



Advertisements
Similar presentations
CS4026 Formal Models of Computation Part II The Logic Model Lecture 8 – Search and conclusions.
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 6 – Arithmetic, fail and the cut.
Informed search algorithms
Modern Programming Languages, 2nd ed.
SLD-resolution Introduction Most general unifiers SLD-resolution
8 Queens. Problem: Placing 8 queens on a chessboard such that they don’t attack each other Three different Prolog programs are suggessted as solutions.
PROLOG 8 QUEENS PROBLEM.
Modern Programming Languages
Prolog.
BackTracking Algorithms
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
1 Conjunctions of Queries. 2 Conjunctive Queries A conjunctive query is a single Datalog rule with only non-negated atoms in the body. (Note: No negated.
COUNTING AND PROBABILITY
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Eight queens puzzle. The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them are able to capture.
Copyright © Cengage Learning. All rights reserved.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Greedy vs Dynamic Programming Approach
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Lists, Operators, Arithmetic Notes for Ch.3 of Bratko For CSCE 580 Sp03 Marco.
KNAPSACK PROBLEM A dynamic approach. Knapsack Problem  Given a sack, able to hold K kg  Given a list of objects  Each has a weight and a value  Try.
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Prolog Language Hamid Harroud School of Science and Engineering, Akhawayn University
Dr Eleni Mangina – COURSE: LOGIC PROGRAMMING (during a joint degree with Fudan University in Software Engineering) DEPT. OF COMPUTER SCIENCE UCD LOGIC.
Linear Equations in Linear Algebra
Backtracking.
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
 Optimal Packing of High- Precision Rectangles By Eric Huang & Richard E. Korf 25 th AAAI Conference, 2011 Florida Institute of Technology CSE 5694 Robotics.
Systems and Matrices (Chapter5)
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
Chapter Twenty-TwoModern Programming Languages1 A Third Look At Prolog.
COMP4730/2004/lec9/H.Melikyan Logic Programming in Prolog  A Brief Introduction to Predicate Calculus  Predicate Calculus and Proving Theorems  An Overview.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
CS 321 Programming Languages and Compilers Prolog part 2.
Recursion and Dynamic Programming. Recursive thinking… Recursion is a method where the solution to a problem depends on solutions to smaller instances.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Ch. 11: Cantor’s Infinity!. N = {1, 2, 3, 4, 5, 6, …} “the natural numbers” Z = {…, –3, –2, –1, 0, 1, 2, 3, …} “the integers” Q = {all quotients “a/b”
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Hard Problems Some problems are hard to solve.  No polynomial time algorithm is known.  E.g., NP-hard problems such as machine scheduling, bin packing,
Hard Problems Sanghyun Park Fall 2002 CSE, POSTECH.
Analysis & Design of Algorithms (CSCE 321)
1 Prolog - Conclusions. 2 Outline n Numeric computation in Prolog n Problem space search – Knapsack – 8-queens n Farewell to Prolog.
Chapter 13 Backtracking Introduction The 3-coloring problem
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Hard Problems Some problems are hard to solve.  No polynomial time algorithm is known.  E.g., NP-hard problems such as machine scheduling, bin packing,
8.3.2 Constant Distance Approximations
Hard Problems Some problems are hard to solve.
CSCI 104 Backtracking Search
Graphing Equations and Inequalities
BACKTRACKING- GENERAL METHOD
Design and Analysis of Algorithm
Chapter 11 :: Logic Languages
Brute Force Approaches
This Lecture Substitution model
Chapter 12 :: Logic Languages
Chapter 15 Roots and Radicals.
Programming Techniques
Recursion as a Problem-Solving Technique
Hard Problems Some problems are hard to solve.
This Lecture Substitution model
Lisp.
Chapter 12 :: Logic Languages
Presentation transcript:

A Third Look At Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.1

Outline n Numeric computation in Prolog n Problem space search – Knapsack – 8-queens n Farewell to Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.2

Unevaluated Terms n Prolog operators allow terms to be written more concisely, but are not evaluated n These are all the same Prolog term: n That term does not unify with 7 Chapter Twenty-TwoModern Programming Languages, 2nd ed.3 +(1,*(2,3)) 1+ *(2,3) +(1,2*3) (1+(2*3)) 1+2*3

Evaluating Expressions The predefined predicate is can be used to evaluate a term that is a numeric expression is(X,Y) evaluates the term Y and unifies X with the resulting atom n It is usually used as an operator Chapter Twenty-TwoModern Programming Languages, 2nd ed.4 ?- X is 1+2*3. X = 7.

Instantiation Is Required Chapter Twenty-TwoModern Programming Languages, 2nd ed.5 ?- Y=X+2, X=1. Y = 1+2, X = 1. ?- Y is X+2, X=1. ERROR: is/2: Arguments are not sufficiently instantiated ?- X=1, Y is X+2. X = 1, Y = 3.

Evaluable Predicates For X is Y, the predicates that appear in Y have to be evaluable predicates This includes things like the predefined operators +, -, * and / There are also other predefined evaluable predicates, like abs(Z) and sqrt(Z) Chapter Twenty-TwoModern Programming Languages, 2nd ed.6

Real Values And Integers Chapter Twenty-TwoModern Programming Languages, 2nd ed.7 ?- X is 1/2. X = 0.5. ?- X is 1.0/2.0. X = 0.5. ?- X is 2/1. X = 2. ?- X is 2.0/1.0. X = 2.0. There are two numeric types: integer and real. Most of the evaluable predicates are overloaded for all combinations. Prolog is dynamically typed; the types are used at runtime to resolve the overloading. But note that the goal 2=2.0 would fail.

Comparisons Numeric comparison operators:, = =, =:=, =\= n To solve a numeric comparison goal, Prolog evaluates both sides and compares the results numerically n So both sides must be fully instantiated Chapter Twenty-TwoModern Programming Languages, 2nd ed.8

Comparisons Chapter Twenty-TwoModern Programming Languages, 2nd ed.9 ?- 1+2 =1+3. false. ?- X is 1-3, Y is 0-2, X =:= Y. X = -2, Y = -2.

Equalities In Prolog n We have used three different but related equality operators: – X is Y evaluates Y and unifies the result with X : 3 is 1+2 succeeds, but 1+2 is 3 fails – X = Y unifies X and Y, with no evaluation: both 3 = 1+2 and 1+2 = 3 fail – X =:= Y evaluates both and compares: both 3 =:= 1+2 and 1+2 =:= 3 succeed (and so does 1 =:= 1.0 ) n Any evaluated term must be fully instantiated Chapter Twenty-TwoModern Programming Languages, 2nd ed.10

Example: mylength Chapter Twenty-TwoModern Programming Languages, 2nd ed.11 mylength([],0). mylength([_|Tail], Len) :- mylength(Tail, TailLen), Len is TailLen + 1. ?- mylength([a,b,c],X). X = 3. ?- mylength(X,3). X = [_G266, _G269, _G272].

Counterexample: mylength Chapter Twenty-TwoModern Programming Languages, 2nd ed.12 mylength([],0). mylength([_|Tail], Len) :- mylength(Tail, TailLen), Len = TailLen + 1. ?- mylength([1,2,3,4,5],X). X =

Example: sum Chapter Twenty-TwoModern Programming Languages, 2nd ed.13 sum([],0). sum([Head|Tail],X) :- sum(Tail,TailSum), X is Head + TailSum. ?- sum([1,2,3],X). X = 6. ?- sum([1,2.5,3],X). X = 6.5.

Example: gcd Chapter Twenty-TwoModern Programming Languages, 2nd ed.14 gcd(X,Y,Z) :- X =:= Y, Z is X. gcd(X,Y,Denom) :- X Y, NewX is X - Y, gcd(NewX,Y,Denom). Note: not just gcd(X,X,X)

The gcd Predicate At Work Chapter Twenty-TwoModern Programming Languages, 2nd ed.15 ?- gcd(5,5,X). X = 5. ?- gcd(12,21,X). X = 3. ?- gcd(91,105,X). X = 7. ?- gcd(91,X,7). ERROR: Arguments are not sufficiently instantiated

Cutting Wasted Backtracking Chapter Twenty-TwoModern Programming Languages, 2nd ed.16 gcd(X,Y,Z) :- X =:= Y, Z is X, !. gcd(X,Y,Denom) :- X Y, NewX is X - Y, gcd(NewX,Y,Denom). If this rule succeeds, there’s no point in trying the others Same here. With those cuts, this test is unnecessary (but we’ll leave it there).

Example: fact Chapter Twenty-TwoModern Programming Languages, 2nd ed.17 fact(X,1) :- X =:= 1, !. fact(X,Fact) :- X > 1, NewX is X - 1, fact(NewX,NF), Fact is X * NF. ?- fact(5,X). X = 120. ?- fact(20,X). X = ?- fact(-2,X). false.

Outline n Numeric computation in Prolog n Problem space search – Knapsack – 8-queens n Farewell to Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.18

Problem Space Search n Prolog’s strength is (obviously) not numeric computation n The kinds of problems it does best on are those that involve problem space search – You give a logical definition of the solution – Then let Prolog find it Chapter Twenty-TwoModern Programming Languages, 2nd ed.19

The Knapsack Problem n You are packing for a camping trip n Your pantry contains these items: n Your knapsack holds 4 kg. n What choice <= 4 kg. maximizes calories? Chapter Twenty-TwoModern Programming Languages, 2nd ed.20 ItemWeight in kilogramsCalories bread49200 pasta24600 peanut butter16700 baby food36900

Greedy Methods Do Not Work n Most calories first: bread only, 9200 n Lightest first: peanut butter + pasta, n (Best choice: peanut butter + baby food, 13600) Chapter Twenty-TwoModern Programming Languages, 2nd ed.21 ItemWeight in kilogramsCalories bread49200 pasta24600 peanut butter16700 baby food36900

Search n No algorithm for this problem is known that – Always gives the best answer, and – Takes less than exponential time n So brute-force search is nothing to be ashamed of here n That’s good, since search is something Prolog does really well Chapter Twenty-TwoModern Programming Languages, 2nd ed.22

Representation We will represent each food item as a term food(N,W,C) Pantry in our example is [food(bread,4,9200), food(pasta,2,4500), food(peanutButter,1,6700), food(babyFood,3,6900)] n Same representation for knapsack contents Chapter Twenty-TwoModern Programming Languages, 2nd ed.23

Chapter Twenty-TwoModern Programming Languages, 2nd ed.24 /* weight(L,N) takes a list L of food terms, each of the form food(Name,Weight,Calories). We unify N with the sum of all the Weights. */ weight([],0). weight([food(_,W,_) | Rest], X) :- weight(Rest,RestW), X is W + RestW. /* calories(L,N) takes a list L of food terms, each of the form food(Name,Weight,Calories). We unify N with the sum of all the Calories. */ calories([],0). calories([food(_,_,C) | Rest], X) :- calories(Rest,RestC), X is C + RestC.

n A subsequence of a list is a copy of the list with any number of elements omitted n (Knapsacks are subsequences of the pantry) Chapter Twenty-TwoModern Programming Languages, 2nd ed.25 /* subseq(X,Y) succeeds when list X is the same as list Y, but with zero or more elements omitted. This can be used with any pattern of instantiations. */ subseq([],[]). subseq([Item | RestX], [Item | RestY]) :- subseq(RestX,RestY). subseq(X, [_ | RestY]) :- subseq(X,RestY).

Chapter Twenty-TwoModern Programming Languages, 2nd ed.26 ?- subseq([1,3],[1,2,3,4]). true. ?- subseq(X,[1,2,3]). X = [1, 2, 3] ; X = [1, 2] ; X = [1, 3] ; X = [1] ; X = [2, 3] ; X = [2] ; X = [3] ; X = [] ; false. Note that subseq can do more than just test whether one list is a subsequence of another; it can generate subsequences, which is how we will use it for the knapsack problem.

Chapter Twenty-TwoModern Programming Languages, 2nd ed.27 /* knapsackDecision(Pantry,Capacity,Goal,Knapsack) takes a list Pantry of food terms, a positive number Capacity, and a positive number Goal. We unify Knapsack with a subsequence of Pantry representing a knapsack with total calories >= goal, subject to the constraint that the total weight is = = Goal.

n This decides whether there is a solution that meets the given calorie goal n Not exactly the answer we want… Chapter Twenty-TwoModern Programming Languages, 2nd ed.28 ?- knapsackDecision( | [food(bread,4,9200), | food(pasta,2,4500), | food(peanutButter,1,6700), | food(babyFood,3,6900)], | 4, | 10000, | X). X = [food(pasta, 2, 4500), food(peanutButter, 1, 6700)].

Decision And Optimization n We solved the knapsack decision problem n What we wanted to solve was the knapsack optimization problem To do that, we will use another predefined predicate: findall Chapter Twenty-TwoModern Programming Languages, 2nd ed.29

The findall Predicate findall(X,Goal,L) – Finds all the ways of proving Goal – For each, applies to X the same substitution that made a provable instance of Goal – Unifies L with the list of all those X ’s Chapter Twenty-TwoModern Programming Languages, 2nd ed.30

Counting The Solutions This shows there were four ways of proving subseq(_,[1,2]) n Collected a list of 1’s, one for each proof Chapter Twenty-TwoModern Programming Languages, 2nd ed.31 ?- findall(1,subseq(_,[1,2]),L). L = [1, 1, 1, 1].

Collecting The Instances The first and second parameters to findall are the same This collects all four provable instances of the goal subseq(X,[1,2]) Chapter Twenty-TwoModern Programming Languages, 2nd ed.32 ?- findall(subseq(X,[1,2]),subseq(X,[1,2]),L). L = [subseq([1, 2], [1, 2]), subseq([1], [1, 2]), subseq([2], [1, 2]), subseq([], [1, 2])].

Collecting Particular Substitutions A common use of findall : the first parameter is a variable from the second This collects all four X ’s that make the goal subseq(X,[1,2]) provable Chapter Twenty-TwoModern Programming Languages, 2nd ed.33 ?- findall(X,subseq(X,[1,2]),L). L = [[1, 2], [1], [2], []].

Chapter Twenty-TwoModern Programming Languages, 2nd ed.34 /* legalKnapsack(Pantry,Capacity,Knapsack) takes a list Pantry of food terms and a positive number Capacity. We unify Knapsack with a subsequence of Pantry whose total weight is =< Capacity. */ legalKnapsack(Pantry,Capacity,Knapsack):- subseq(Knapsack,Pantry), weight(Knapsack,W), W =< Capacity.

Chapter Twenty-TwoModern Programming Languages, 2nd ed.35 /* maxCalories(List,Result) takes a List of lists of food terms. We unify Result with an element from the list that maximizes the total calories. We use a helper predicate maxC that takes four paramters: the remaining list of lists of food terms, the best list of food terms seen so far, its total calories, and the final result. */ maxC([],Sofar,_,Sofar). maxC([First | Rest],_,MC,Result) :- calories(First,FirstC), MC = FirstC, maxC(Rest,Sofar,MC,Result). maxCalories([First | Rest],Result) :- calories(First,FirstC), maxC(Rest,First,FirstC,Result).

Chapter Twenty-TwoModern Programming Languages, 2nd ed.36 /* knapsackOptimization(Pantry,Capacity,Knapsack) takes a list Pantry of food items and a positive integer Capacity. We unify Knapsack with a subsequence of Pantry representing a knapsack of maximum total calories, subject to the constraint that the total weight is =< Capacity. */ knapsackOptimization(Pantry,Capacity,Knapsack) :- findall(K,legalKnapsack(Pantry,Capacity,K),L), maxCalories(L,Knapsack).

Chapter Twenty-TwoModern Programming Languages, 2nd ed.37 ?- knapsackOptimization( | [food(bread,4,9200), | food(pasta,2,4500), | food(peanutButter,1,6700), | food(babyFood,3,6900)], | 4, | Knapsack). Knapsack = [food(peanutButter, 1, 6700), food(babyFood, 3, 6900)].

Outline n Numeric computation in Prolog n Problem space search – Knapsack – 8-queens n Farewell to Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.38

The 8-Queens Problem n Chess background: – Played on an 8-by-8 grid – Queen can move any number of spaces vertically, horizontally or diagonally – Two queens are in check if they are in the same row, column or diagonal, so that one could move to the other’s square n The problem: place 8 queens on an empty chess board so that no queen is in check Chapter Twenty-TwoModern Programming Languages, 2nd ed.39

Representation n We could represent a queen in column 2, row 5 with the term queen(2,5) n But it will be more readable if we use something more compact n Since there will be no other pieces—no pawn(X,Y) or king(X,Y) —we will just use a term of the form X/Y n (We won’t evaluate it as a quotient) Chapter Twenty-TwoModern Programming Languages, 2nd ed.40

Example n A chessboard configuration is just a list of queens This one is [2/5,3/7,6/1] Chapter Twenty-TwoModern Programming Languages, 2nd ed.41

Chapter Twenty-TwoModern Programming Languages, 2nd ed.42 /* nocheck(X/Y,L) takes a queen X/Y and a list of queens. We succeed if and only if the X/Y queen holds none of the others in check. */ nocheck(_, []). nocheck(X/Y, [X1/Y1 | Rest]) :- X =\= X1, Y =\= Y1, abs(Y1-Y) =\= abs(X1-X), nocheck(X/Y, Rest).

Chapter Twenty-TwoModern Programming Languages, 2nd ed.43 /* legal(L) succeeds if L is a legal placement of queens: all coordinates in range and no queen in check. */ legal([]). legal([X/Y | Rest]) :- legal(Rest), member(X,[1,2,3,4,5,6,7,8]), member(Y,[1,2,3,4,5,6,7,8]), nocheck(X/Y, Rest).

Adequate This is already enough to solve the problem: the query legal(X) will find all legal configurations: Chapter Twenty-TwoModern Programming Languages, 2nd ed.44 ?- legal(X). X = [] ; X = [1/1] ; X = [1/2] ; X = [1/3] ; etc.

8-Queens Solution n Of course that will take too long: it finds all 64 legal 1-queens solutions, then starts on the 2-queens solutions, and so on n To make it concentrate right away on 8-queens, we can give a different query: Chapter Twenty-TwoModern Programming Languages, 2nd ed.45 ?- X = [_,_,_,_,_,_,_,_], legal(X). X = [8/4, 7/2, 6/7, 5/3, 4/6, 3/8, 2/5, 1/1].

Example n Our 8-queens solution n [8/4, 7/2, 6/7, 5/3, 4/6, 3/8, 2/5, 1/1] Chapter Twenty-TwoModern Programming Languages, 2nd ed.46

Room For Improvement n Slow n Finds trivial permutations after the first: Chapter Twenty-TwoModern Programming Languages, 2nd ed.47 ?- X = [_,_,_,_,_,_,_,_], legal(X). X = [8/4, 7/2, 6/7, 5/3, 4/6, 3/8, 2/5, 1/1] ; X = [7/2, 8/4, 6/7, 5/3, 4/6, 3/8, 2/5, 1/1] ; X = [8/4, 6/7, 7/2, 5/3, 4/6, 3/8, 2/5, 1/1] ; X = [6/7, 8/4, 7/2, 5/3, 4/6, 3/8, 2/5, 1/1] ; etc.

An Improvement n Clearly every solution has 1 queen in each column So every solution can be written in a fixed order, like this: X=[1/_,2/_,3/_,4/_,5/_,6/_,7/_,8/_] n Starting with a goal term of that form will restrict the search (speeding it up) and avoid those trivial permutations Chapter Twenty-TwoModern Programming Languages, 2nd ed.48

Chapter Twenty-TwoModern Programming Languages, 2nd ed.49 /* eightqueens(X) succeeds if X is a legal placement of eight queens, listed in order of their X coordinates. */ eightqueens(X) :- X = [1/_,2/_,3/_,4/_,5/_,6/_,7/_,8/_], legal(X).

n Since all X-coordinates are already known to be in range and distinct, these can be optimized a little Chapter Twenty-TwoModern Programming Languages, 2nd ed.50 nocheck(_, []). nocheck(X/Y, [X1/Y1 | Rest]) :- % X =\= X1, assume the X's are distinct Y =\= Y1, abs(Y1-Y) =\= abs(X1-X), nocheck(X/Y, Rest). legal([]). legal([X/Y | Rest]) :- legal(Rest), % member(X,[1,2,3,4,5,6,7,8]), assume X in range member(Y,[1,2,3,4,5,6,7,8]), nocheck(X/Y, Rest).

Improved 8-Queens Solution n Now much faster n Does not bother with permutations Chapter Twenty-TwoModern Programming Languages, 2nd ed.51 ?- eightqueens(X). X = [1/4, 2/2, 3/7, 4/3, 5/6, 6/8, 7/5, 8/1] ; X = [1/5, 2/2, 3/4, 4/7, 5/3, 6/8, 7/6, 8/1] ; etc.

An Experiment n Fails: “arguments not sufficiently instantiated” n The member condition does not just test in-range coordinates; it generates them Chapter Twenty-TwoModern Programming Languages, 2nd ed.52 legal([]). legal([X/Y | Rest]) :- legal(Rest), % member(X,[1,2,3,4,5,6,7,8]), assume X in range 1=<Y, Y=<8, % was member(Y,[1,2,3,4,5,6,7,8]), nocheck(X/Y, Rest).

Another Experiment n Fails: “arguments not sufficiently instantiated” The legal(Rest) condition must come first, because it generates the partial solution tested by nocheck Chapter Twenty-TwoModern Programming Languages, 2nd ed.53 legal([]). legal([X/Y | Rest]) :- % member(X,[1,2,3,4,5,6,7,8]), assume X in range member(Y,[1,2,3,4,5,6,7,8]), nocheck(X/Y, Rest), legal(Rest). % formerly the first condition

Outline n Numeric computation in Prolog n Problem space search – Knapsack – 8-queens n Farewell to Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.54

Parts We Skipped n Some control predicate shortcuts – -> for if-then and if-then-else – ; for a disjunction of goals n Exception handling – System-generated or user-generated exceptions – throw and catch predicates n The API – A small ISO API; most systems provide more – Many public Prolog libraries: network and file I/O, graphical user interfaces, etc. Chapter Twenty-TwoModern Programming Languages, 2nd ed.55

A Small Language n We did not have to skip as much of Prolog as we did of ML and Java n Prolog is a small language n Yet it is powerful and not easy to master n The most important things we skipped are the techniques Prolog programmers use to get the most out of it Chapter Twenty-TwoModern Programming Languages, 2nd ed.56