Download presentation
Presentation is loading. Please wait.
1
CS2136: Paradigms of Computation
Class 08: More on Resolution Horn Clauses Unification Copyright 2001, 2002, 2003 Michael J. Ciaraldi and David Finkel
2
Resolution
3
Clauses I We saw last time that an implication
p q (if p then q) is equivalent to ~ p q (not p or q) This is an example of a clause.
4
Clauses II It turns out that any logical statements made up of (and), (or), (implies), (is equivalent to), and (not) can be expressed as statements of the form: (p1 p2 … pn) (q1 q2 … qm) In FOPC, this is called a “clause” and written p1; p2 ;… pn :- q1, q2, … ,qm
5
Resolution How can we use clauses to make logical deductions?
J. Alan Robinson discovered the Resolution Principle, which can determine this mechanically. Fit two clauses together, then drop out the same atomic formula from both sides.
6
Resolution Example In this notation, “;” means “or”. Clauses:
sad(chris);angry(chris) :- workday(today), raining(today). unpleasant(chris) :- angry(chris),tired(chris). Merge to get: sad(chris);angry(chris);unpleasant(chris) :- workday(today),raining(today), angry(chris),tired(chris). Simplify to: sad(chris);unpleasant(chris) :- workday(today),raining(today),tired(chris).
7
Remember! OR (;) on the left. AND (,) on the right.
8
Problems With Resolution
Resolution may generate many clauses. How do you get them all? How do you know which ones you want? Resolution does not guarantee that you can prove some clause is true. Resolution can show if a set of clauses is consistent or inconsistent. Inconsistent if they resolve to the empty clause “:- .”
9
What Good Does This Do? You can assert something is true by putting it on the left side of an “:-”. loyal(rover) :- . You can assert something is false by putting it on the right side of an “:-”. :- loyal(rover). So…
10
Proving Through Resolution
Start with a set of clauses which are consistent. Add the negation of the clause you are trying to prove. See if they resolve to the empty clause, meaning they are inconsistent. If so, the clause is true.
11
Horn Clauses
12
Horn Clauses Horn clauses have at most one unnegated literal.
i.e. on the left. Headed Horn clauses have one. bachelor(X) :- male(X),unmarried(X). Headless Horn clauses have none. :- bachelor(X). [X is not a bachelor.]
13
Horn Clauses II Any soluble problem in theorem-proving that can be expressed as a set of Horn clauses can be written as: Some headed Horn clauses. One headless Horn clause. (You can start with more, but you can reduce them to one.) This is the goal.
14
Prolog and Horn Clauses
In Prolog, we can only directly express Horn clauses. Prolog questions turn into headless Horn clauses. [Prolog:] ?- A1, A2, A3. [Horn:] :- A1, A2, A3. All clauses (facts and rules) of a Prolog program are headed. One question (goal) is considered at a time. One goal at a time! If you have subgoals, hold them in abeyance.
15
How Does Prolog Work? You have a goal (ask a question).
Prolog resolves it with the hypotheses (matches against the database), to form new clauses. Prolog keeps going until either: resolves to the empty clause. The question is true! Prolog runs out of clauses The question is presumed false.
16
So, Is Prolog Good For Logic Programming?
It’s a start, but… Always does things in the same order. Can use assert and retract to change the database. “Cut” and other procedural things. Prolog uses depth-first, not breadth-first search of alternative clauses. Can get into loops. Designed for Horn clauses.
17
Two More Things About Resolution
What goes where, and why does it matter? Unification
18
What Goes Where If you end up with terms on the left side of the “:-”, but nothing on the right, you are not done. king(arthur) :- . Why? This just proves that this assertion is consistent with the facts and rules you already have. This does not prove that it is a logical consequence.
19
What Goes Where II The only sure way is to assert the negation of the term (by sticking it on the right side), then prove that it causes a contradiction, i.e. it all resolves to the empty clause.
20
Unification
21
Unification You have to match up the variables.
Having the same names in different clauses is not how it’s done. Prolog has no global variables.
22
Example: Trivial Unification
Prolog would not rely on this shortcut. Original rules admit_to_wpi(X) :- smart(X). smart(X) :- sat_over(X, 1200). Query admit_to_wpi(X). Merge both sides admit_to_wpi(X); smart(X) :- sat_over(X,1200), smart(X). Cancel to get new rule admit_to_wpi(X) :- sat_over(X, 1200). Prolog would not do this, even though it is valid in FOPC.
23
More Usual Unification
Original rules smart(torvalds). admires(ciaraldi,torvalds). [Ciaraldi admires Torvalds] smart(X) :- admires(X,Y),smart(Y). admit_to_wpi(Z) :- smart(Z). hire_at_wpi(Y) :- smart(Y). Query admit_to_wpi(ciaraldi). Must unify before merging. Z matches X.
24
More Usual Unification II
Original rules smart(torvalds). admires(ciaraldi,torvalds). smart(X) :- admires(X,Y),smart(Y). admit_to_wpi(Z) :- smart(Z). hire_at_wpi(Y) :- smart(Y). Query hire_at_wpi(ciaraldi). Must unify before merging. One of the Y’s matches X. Prolog uses internal variable names as needed.
25
Next Times Tuesday: Review. Thursday: Prolog Exam. Friday: Start Java.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.