1 / 30

Rule Based Systems (Prolog)

Rule Based Systems (Prolog). M. Reza Zakerinasab mrzakeri@ucalgary.ca 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.

ann
Download Presentation

Rule Based Systems (Prolog)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rule Based Systems(Prolog) M. Reza Zakerinasab mrzakeri@ucalgary.ca 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 CPSC 433 Artificial Intelligence

  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 CPSC 433 Artificial Intelligence

  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

  4. 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). CPSC 433 Artificial Intelligence

  5. Basic Prolog Process Negate query, set as current goal. while current goal is non-empty: choose the leftmost subgoal if 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 CPSC 433 Artificial Intelligence

  6. Sir Bedevere’s Infamous Deduction witch(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 CPSC 433 Artificial Intelligence

  7. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) CPSC 433 Artificial Intelligence

  8. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) CPSC 433 Artificial Intelligence

  9. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(_G0)  woman(_G0) CPSC 433 Artificial Intelligence

  10. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(_G0)  woman(_G0) CPSC 433 Artificial Intelligence

  11. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(_G0)  woman(_G0)  madeofwood(_G0) CPSC 433 Artificial Intelligence

  12. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(_G0)  woman(_G0)  madeofwood(_G0) CPSC 433 Artificial Intelligence

  13. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) CPSC 433 Artificial Intelligence

  14. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) CPSC 433 Artificial Intelligence

  15. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(duck) CPSC 433 Artificial Intelligence

  16. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(duck) CPSC 433 Artificial Intelligence

  17. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(duck)  woman(duck) CPSC 433 Artificial Intelligence

  18. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(duck)  woman(duck) fail! backtrack... CPSC 433 Artificial Intelligence

  19. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) CPSC 433 Artificial Intelligence

  20. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) • floats(_G1)  sameweight(_G1, _G0) CPSC 433 Artificial Intelligence

  21. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) • floats(_G1)  sameweight(_G1, _G0) CPSC 433 Artificial Intelligence

  22. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) • floats(duck)  sameweight(duck, _G0) CPSC 433 Artificial Intelligence

  23. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) • floats(duck)  sameweight(duck, _G0) CPSC 433 Artificial Intelligence

  24. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(_G0) • floats(duck)  sameweight(duck, girl) CPSC 433 Artificial Intelligence

  25. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(_G0) • floats(girl) CPSC 433 Artificial Intelligence

  26. Sir Bedevere’s Infamous Deduction witch(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). • Goals • witch(_G0) • burns(_G0)  woman(_G0) • madeofwood(girl) CPSC 433 Artificial Intelligence

  27. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(girl)  woman(girl) CPSC 433 Artificial Intelligence

  28. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(_G0) burns(girl)  woman(girl) works this time CPSC 433 Artificial Intelligence

  29. Sir Bedevere’s Infamous Deduction witch(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). Goals witch(girl) CPSC 433 Artificial Intelligence

  30. Sir Bedevere’s Infamous Deduction witch(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 CPSC 433 Artificial Intelligence

More Related