Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Practical Introduction to Prolog Basics II.

Similar presentations


Presentation on theme: "Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Practical Introduction to Prolog Basics II."— Presentation transcript:

1 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Practical Introduction to Prolog Basics II

2 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Logic Programming Excursions II 4 Negation and the Cut 4 Backward and Forward Chaining 4 Explicit Negation, Belief and the Mystery Solver 4 Intermediate Prolog Programming Examples –Language Acceptors –Transitive Closure –Sub terms –Trees

3 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Negation and the Cut 4 Negation as Failure –Negation succeeds if search fails. –Not Constructive - Unification does not produce any bindings. –Consistent Interpretation depends on Closed World Assumption 4 The Cut ‘!’ –A device for controlling the search –Used to increase efficiency –BUT can alter semantics of a program -- change its solution set.

4 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Negation as Failure 4 single_student(X) :- not(married(X)), student(X). 4 student(bill). 4 student(joe). 4 married(joe). 4 :- single_student(bill). –  yes. 4 :- single_student(joe). –  no. 4 ?- single_student(X)  no.

5 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Negation as Failure 2 nd Try 4 single_student(X) :- student(X), not(married(X)). 4 student(bill). 4 student(joe). 4 married(joe). 4 :- single_student(bill). –  yes. 4 :- single_student(joe). –  no. 4 ?- single_student(X)  X=bill.

6 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Closed World Assumption 4 Assumption that the world is defined in its entirety –The representation is “complete”/”closed” 4 No true statement is missing from the representation 4 In practice, assumed for conventional databases –“Sorry, sir you must NOT exist your social security number is NOT IN our database, bye, bye”. 4 From a LP, P, allows us to conclude –the negation of A –IF A is NOT IN the meaning of P

7 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Negation as Failure & the CWA 4 single_student(X) :- student(X), not(married(X)). 4 student(bill). 4 student(joe). 4 married(joe). 4 student(jim) 4 :- single_student(bill). –  yes. 4 :- single_student(joe). –  no. 4 :- single_student(jim). –  yes. 4 But Jim IS married. 4 Maybe I should read up on the CWA.

8 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes The Cut (!)

9 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes A Green Cut fact(N,1) :- N = 0, !. fact(N,F) :- N > 0, M is N -1, fact(M,F1) F is N * F1. If N = 0 in first clause we do not need to consider second clause. The second will fail...so we CUT to prune unnecessary consideration of the second clause. With or without the cut the program produces the same solutions. Its intended meaning is intact.

10 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes A Good Red Cut if_then_else(If,Then,Else) :- If, !, Then. if_then_else(If, Then, Else) :- Else. ?- if_then_else(true, write(equal), write(not_equal)) equal yes. ?- if_then_else(false, write(equal), write(not_equal)) not_equal yes. if_then_else(If,Then,Else) :- If, Then. if_then_else(If,Then,Else) :- Else. If we take out the cut we change the meaning -- so the cut is RED. But it is used to produce the meaning we want -- so the cut is GOOD. ?- if_then_else(true, write(equal), write(not_equal)) equal not_equal yes.

11 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes A BAD Red Cut R1. pension(X,disabled) :- disabled(X),!. R2. pension(X,senior) :- over65(X), paid_up(X),!. R3. pension(X,supplemental) :- over65(X),!. R4. pension(X,nothing). %"The Default" If everything else fails. F1. disabled(joe).F4. over65(lou). F2. over65(joe).F5. paid_up(lou). F3. paid_up(joe). Q1. ?- pension(joe, nothing) -> yes. OOPS! "I'm sorry Mr. Joe...yes Mr. Joe you are entitled, it was a small computer error...really Mr. Joe computers DO make mistakes...I'm sorry what was that about intended meaning?". Q2. ?- pension(joe,P) -> P = disabled Does Joe get more than one pension payment? Q3. ?- pension(X, senior) -> X = joe. What happened to Lou's pension? Isn’t he a senior? The cut is used to implement the default case -- Yike!

12 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Joe's Revenge R1. pension(X,disabled) :- disabled(X). R2. pension(X,senior) :- over65(X), paid_up(X). R3. pension(X,supplemental) :- over65(X). R4. entitled(X,Pension) :- pension(X,Pension). R5. entitled(X,nothing) :- not(pension(X,Pension)). %%%R5. entitled(X,nothing). F1. disabled(joe).F4. over65(lou). F2. over65(joe).F5. paid_up(lou). F3. paid_up(joe). Q1. ?- entitled(joe,nothing) -> no. Q2. ?- entitled(joe,P) -> 1. P = disabled, 2. P=senior, 3. P=supplemental Q3. ?- entitled(X,senior_pension) -> 1. X = joe 2. X = lou Q4. ?- entitled(X,disabled_pension) -> 1. X = joe.

13 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Is it Good, Bad or Just Ugly? not(P) :- P,!,fail. not(P).

14 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Deductive Reasoning Mechanisms 4 Backward Chaining –Theorem Proving –Goal-Directed Reasoning Start with a goal and try to proof it by working backwards G is true if A, A is true if B, B is true if C. C is true. –Typically used for diagnostic systems Systems that start with hypothesis and try to substantiated them by working backwards. 4 Forward Chaining –Data-Directed Reasoning –Production Rule Systems: If X is true then make Y true. –Looks for patterns in data, updates the data and trys again. –Moves forward from one state to the next. –Typical used for control or simulation systems

15 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Programming Workshop 0 Represent a very simple blocks world where blocks are either on top of each other or next to each other. Build a simple agent using a forward chaining mechanism that finds any two blocks next to each other stacks on top of the other.

16 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Programming Workshop 1 "Your hands, my dear sir!, Your right hand is quite a size larger than your left. You must have worked with it and the muscles are more developed...The fish you have tattooed immediately above your wrist could only have been done in China. That trick of staining the fishes' scales of a delicate pink is quite peculiar to China. What else can be indicated by that right cuff so very shiny for five inches, and the left one with the smooth patch near the elbow where you rest it upon the desk..." Develop a general representation, inspired by the above quote from Sherlock Holmes, for a detective's knowledge base that will enable deductions about a person's travels, their occupations and other habits based on observable data.

17 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Programming Workshop 2 “Vic has been murdered and Art, Burt and Carl are suspects. Art says he did not do it. He says that Burt was the victim’s friend, but that Carl hated the victim. Burt says he was out of town on the day of the murder and besides he didn’t even know the guy. Carl says that he is innocent and that he saw Art and Burt just before the murder.” Assuming that everyone, except possibly for the murderer is telling the truth, build a detective (an automated reasoning system) in Prolog and solve the crime.

18 Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Detective’s Brain General Detective's Knowledge friend -> know hate -> know etc. Case Facts Art claims/believes friend(bert,vic) etc. Detective's Thinking Engine Deductive Reasoning Engine Resolution, Explicit Negation Problem Solving Strategy IF only one suspect is lying then the only the guilty person’s story might contradict all the other suspect’s stories. Possible Worlds Reasoning Deduction in separate belief spaces


Download ppt "Dr. David A Ferrucci -- Logic Programming and AI Lecture Notes Practical Introduction to Prolog Basics II."

Similar presentations


Ads by Google