CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab...
-
Upload
maude-fitzgerald -
Category
Documents
-
view
217 -
download
0
Transcript of CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab...
![Page 1: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/1.jpg)
CPSC 433 Artificial Intelligence
Rule Based Systems(Prolog)
M. Reza [email protected]
Please include [CPSC433] in the subject line of any emails regarding this course.Slides originally created by Andrew M Kuipers.Some slides adopted from 600.325/425 Declarative Methods - J. Eisner
![Page 2: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/2.jpg)
2
Prolog as constraint programming
• An ordinary constraint between two variables: Person and Food• Prolog makes you name this constraint.
Here’s a program that defines it:– eats(sam, dal). eats(josie, samosas).– eats(sam, curry). eats(josie, curry).– eats(rajiv, dal). …
• Now it acts like a subroutine! At the Prolog prompt you can type – eats(Person1, Food1). % constraint over two variables– eats(Person2, Food2). % constraint over two other variables
(Person, Food)Person Food
sam dal
sam curry
josie samosas
josie curry
rajiv dal
CPSC 433 Artificial Intelligence
![Page 3: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/3.jpg)
3
Using Prolog
– eats(sam, dal). eats(josie, samosas).– eats(sam, curry). eats(josie, curry).– eats(rajiv, burgers). eats(rajiv, dal). …
– eats(Person1, Food), eats(Person2, Food).
• Person1=sam, Person2=josie, Food=curry• Person1=josie, Person2=sam, Food=curry …
Your program file (compiled)Sometimes called the “database”
“Query” that you type interactively
Prolog’s answer
CPSC 433 Artificial Intelligence
![Page 4: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/4.jpg)
CPSC 433 Artificial Intelligence
Adding more rules…
eats(sam, dal). eats(josie, samosas).eats(sam, curry). eats(josie, curry).eats(rajiv, burgers). eats(rajiv, dal).
compatible(Person1, Person2) :- eats(Person1, Food), eats(Person2, Food).
compatible(Person1, Person2) :- watches(Person1, Movie),watches(Person2, Movie).
compatible(hal, Person2) :- female(Person2), rich(Person2).
![Page 5: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/5.jpg)
CPSC 433 Artificial Intelligence
Basic Prolog Process
Negate query, set as current goal.
while current goal is non-empty:choose the leftmost subgoalif a rule applies to the subgoal:
select the first applicable rule (top-to-bottom)perform resolution on subgoal and selected rule
else:backtrack if possible, otherwise fail
success
![Page 6: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/6.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
Logically sound?!!
?- witch(X).
Goals
![Page 7: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/7.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
![Page 8: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/8.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
![Page 9: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/9.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)
![Page 10: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/10.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)
![Page 11: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/11.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0) madeofwood(_G0)
![Page 12: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/12.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0) madeofwood(_G0)
![Page 13: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/13.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)
![Page 14: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/14.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)
![Page 15: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/15.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(duck)
![Page 16: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/16.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(duck)
![Page 17: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/17.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(duck) woman(duck)
![Page 18: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/18.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(duck) woman(duck)
fail! backtrack...
![Page 19: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/19.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)
![Page 20: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/20.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)floats(_G1) sameweight(_G1, _G0)
![Page 21: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/21.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)floats(_G1) sameweight(_G1, _G0)
![Page 22: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/22.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)floats(duck) sameweight(duck, _G0)
![Page 23: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/23.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)floats(duck) sameweight(duck, _G0)
![Page 24: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/24.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(_G0)floats(duck) sameweight(duck, girl)
![Page 25: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/25.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(_G0)
floats(girl)
![Page 26: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/26.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(_G0) woman(_G0)madeofwood(girl)
![Page 27: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/27.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(girl) woman(girl)
![Page 28: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/28.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(_G0)
burns(girl) woman(girl)
works this time
![Page 29: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/29.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
Goalswitch(girl)
![Page 30: CPSC 433 Artificial Intelligence Rule Based Systems (Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca Please include [CPSC433] in the subject line of any.](https://reader034.fdocuments.us/reader034/viewer/2022051402/5697c0071a28abf838cc619a/html5/thumbnails/30.jpg)
CPSC 433 Artificial Intelligence
Sir Bedevere’s Infamous Deductionwitch(X) :- burns(X),woman(X).woman(girl).burns(X) :- madeofwood(X).madeofwood(X) :- floats(X).floats(duck).floats(Y) :- floats(X),sameweight(X,Y).sameweight(duck,girl).
?- witch(X).
X = girl