



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Artificial Intelligence; Subject: Computer Engr & Computer Sci; University: California State University - Long Beach; Term: Unknown 2002;
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




A Few More Aspects of Prolog
The Cut Symbol (!): when placed in the body of a prolog statement, it prevents back- tracking at the point of where it is placed.
Cut Symbol Example: For the following program, show how the cut symbol can be placed to eliminate unnecessary backtracking for the goal list
? − f( 1 , Y), Y < 2.
Program
f(X, 0 ) : − X < 3. f(X, 2 ) : − 3 =< X, X < 6. f(X, 4 ) : − 6 =< X.
Using cut and fail to handle exceptions: the simple prolog statement fail is always unsatisfiable; and placing the cut operator before it will ensure that goals that are net meant to be satisfied will not be.
Cut and Fail Example: Tam loves all ice-cream flavors except rocky road. Express this in a prolog program so that the goal
? − loves(tam, X).
will be answered by “yes” when X is any ice cream except for rocky road, and “no” when X is rocky road.
Defining negation: not(P) : − P, !, fail; true.
Problem Solving With Prolog: Blocks Example. A robot has the task of stacking cubic blocks in some predetermined order (based on their color). Initially a surface has one or more stacks of blocks, and the robot is to stack and unstack (one block at a time) these blocks to make the desired stack. Write a prolog program that will input a desired color sequence of blocks, and output a list of actions (stacking or unstacking specific blocks) needed to obtain the desired stack.
Problem Solving With Prolog: “Set Me Example”. The game of Set Me is played with a deck of eighty-one cards, each having the following four characteristics:
The cards are shuffled and a tableau (hand) of twelve cards is laid out. Players then attempt to be the first to identify “sets” which exist in the tableau. Sets are removed as they are identified and new cards are dealt in their place. Play continues in this manner until all cards have been used. The winner is the player with the most sets. A set is a collection of three cards in which each characteristic is either the same on all three cards or different on all three cards. Write a prolog program that will find all sets for a given input of one tableau.