Programming Language in Artificial Intelligence | CECS 451, Study notes of Computer Science

Material Type: Notes; Class: Artificial Intelligence; Subject: Computer Engr & Computer Sci; University: California State University - Long Beach; Term: Unknown 2002;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-sxd
koofers-user-sxd 🇺🇸

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 3: Problem-Solving With Prolog
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 .
pf3
pf4
pf5

Partial preview of the text

Download Programming Language in Artificial Intelligence | CECS 451 and more Study notes Computer Science in PDF only on Docsity!

Lecture 3: Problem-Solving With Prolog

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:

  • Symbol: diamonds, ovals, or squiggles
  • Count: 1, 2, or 3 symbols
  • Color: red, green, or purple
  • Shading: outlined, filled, or striped

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.