Resolution and Refutation York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 04_Resolution 1
Propositional Logic Resolution Refutation Predicate Logic Substitution Unification Resolution Refutation Search space Overview [ref. Nilsson- Chap.3] [Prof. Zbigniew Stachniak s class notes] 2
Theorems from Logic [from Mathematical Logic, George Tourlakis] Modus Ponens Cut Rule Transitivity of Proof by Contradiction 3
By A. Robinson (1965) Example Prove Resolution in Logic We need to show that the following set is inconsistent 4
Resolution in Logic Programming Program P (facts and rules in clause form) Goal G negated and added to program P To prove G, we need to show Complementary literals P { G} is inconsistent q; t - p., p- s. Parent clauses Resolving upon p, being on different sides of - q; t - s. Resolvent 5
Program P={q-., p-q.} Example (1) Query -p. This is already the negated form of our goal! q-. p- q. -p. -q. - empty clause, inconsistency therefore p is satisfiable true 6
Refutation When resolution is used to prove inconsistency, it is also called refutation. (refute=disprove) The above binary tree, showing resolution and resulting in the empty clause, is called a refutation tree. NOTE To avoid potential mistakes, DO NOT RESOLVE UPON MORE THAN ONE LITERAL SIMULTANEOUSLY. 7
Example (2) A1. If Henry has two days off, then if the weather is bad, Henry is not fishing. A2. if Henry is not fishing and is not drinking in a pub with his friends, then he is watching TV at home. A3. If Henry is working, then he is neither drinking in a pub with his friends nor watching TV at home. Q. If Henry is not watching TV at home and he has two days off, then he is drinking in a pub with his friends provided that the weather is bad. 8
Example (2) (cont.) From logical point of view, we want to prove Q, given A1, A2, A3. { A 1, A2, A3} Q. By refutation principle, the consistency of is examined. C { A1, A2, A3} { Q} Step 1 Represent as propositional formulas Step 2 Represent as clauses Step 3 Determine the consistency of C If C is consistent, answer NO (false) If C is inconsistent, answer YES (true) 9
Example (2) (cont.) A1. If Henry has two days off, then if the weather is bad, Henry is not fishing. A2. if Henry is not fishing and is not drinking in a pub with his friends, then he is watching TV at home. A3. If Henry is working, then he is neither drinking in a pub with his friends nor watching TV at home. Q. If Henry is not watching TV at home and he has two days off, then he is drinking in a pub with his friends provided that the weather is bad. p H has two days off q weather is bad r H is fishing s H is drinking in a pub with his friends t H is watching TV at home u H is working A1. p ->(q ->~r) A2. (~r & ~s) -> t A3. u -> (~s & ~t) Q. (~t & p) -> (q->s) 10
Example (2) (cont.) Conversion to clause form York University- CSE 3401 11. is. q is. p is. is ) ( ) ( ) ( ) (., is., is ) ( ) ( ) ( ) ( 3. ; ; is ) ( ) ( 2.,, is ) ( 1 8 7 6 5 4 3 2 1 s C C C t C s q p t s q p t s q p t Q t u C s u C t u s u t s u t s u A t s r C t s r t s r t s r A r q p C r q p r q p A 04_Resolution
Example (2) (cont.) Determining the consistency of {C 1, C 2,..., C 8 } York University- CSE 3401 12.. q. p..,.,. ; ;.,, C C C C 8 7 6 5 4 3 2 1 s t t u s u t s r r q p C C C C -. s r;., r q -. r r.. 04_Resolution
Example (2) (cont.) C={C1, C2,..., C8} is inconsistent (by resolution/ refutation) Therefore Q is provable (deducible) Answer YES (true) This is how Prolog answers Queries. If the empty string is deduced, Prolog answers YES (or TRUE). 13
Resolution in Predicate Logic A literal in Predicate Logic (PL) is either A positive literal in the form of p(tp ( t 1,,..., tt k k ) where p is a predicate and t i are terms Or a negative literal in the form of p t,..., t ) ( 1 k Two clauses in PL can be resolved upon two complementary unifiable literals Two literals are unifiable if a substitution can make them identical. Example study_hard(x) and study_hard(john) date(d, M, 2001) and date(d1, may, Y1) 14
Substitution Substitution is a finite set of pairs of terms denoted as [X 1 /t 1,..., X n /t n ] where each t i is a term and each X i is a variable. Every variable is mapped to a term; if not explicitly mentioned, it maps to itself. For example date(d, M, 2001) and date(d1, may, Y1) Substitution e= [D/D1, M/may, Y1/2001] 15
Applying substitution to clauses Substitution of a clause is defined by applying substitution to each of its literals e( p - q 1,..., q k.) = e(p) - e(q 1 ),..., e(q k ). Example C pass_3401(x)- student(x, Y), study_hard(x). e=[x/ john, Y/ 3401] e(c)= pass_3401(john)- student(john, 3401), study_hard(john). 16
Applying substitution to literals Example p(x, f(x, 2, Z), 5) e= [X/5, Z/h(a,2+X)] e(p(x, f(x, 2, Z), 5))= p(5, f(5, 2, h(a, 2+X)), 5) Note Simultaneous substitution X in h(a,2+x) is not substituted Example r(x, Y) e=[x/y, Y/X] e(r(x, Y))= r(y, X) Example r(x, f(2, Y)) e=[f(2, Y) / Z] illegal substitution- only variables can be substituted 17
Unifier Let p 1 and p 2 be two literals and let e be a substitution. We call e a unifier of p 1 and p 2 if e(p 1 )=e(p 2 ). Two literals are unifiable if such a unifier exists. Example p 1 date(d, M, 2001) and p 2 date(d1, may, Y1) e=[d/15, D1/ 15, M/may, Y1/2001] e(p 1 )= date(15, may, 2001) e(p 2 )= date(15, may, 2001) e(p 1 )=e(p 2 ) e is a unifier of p 1 and p 2 p 1 and p 2 are unifiable 18
Most General Unifier (mgu) A unifier e is said to be a most general unifier (mgu) of two literals/terms iff e is more general than any other unifier of the terms. Example date(d, M, 2001) and date(d1, may, Y1) e 1 =[D/15, D1/ 15, M/may, Y1/2001] not the most general e 2 =[ D1/D, M/may, Y1/2001] mgu 19
Unification Called matching in Prolog Rules for matching two terms, S and T [Bratko] If S and T are constants, then S and T match only if they are the same object. If S is a variable (and T is anything), then they match and S is substituted by T (instantiated to T). Conversely, if T is a variable, then T is substituted by S. If S and T are structures, then they match iff S and T have the same principal functor All their corresponding components match 20
Examples Are the following literals unifiable? What is their mgu? 1. triangle(point(1,2), X, point(2,4) ) and triangle(a, point(5, Y), point(2, B)) unifiable mgu=[a/point(1,2), X/point(5,Y), B/4] 2. horizontal(point(1,x), Y) and vertical(z, A) not unifiable horizontal vertical 3. plus(2,2) and 4 not unifiable 4. seg(point(1,2), point(3,4)) and seg(f(1,2), Y) not unifiable point f 21
Unification vs. Matching Are p(x) and p(f(x)) unifiable? e=[x/f(x)] X=f(f(f(f(f(...?! This is not allowed in unification. Proper unification requires occurs check a variable X can not be substituted by a term t if X occur in t. This is not done in Prolog s matching for efficiency reasons. Therefore it is referred to as matching in Prolog, and not unification. 22
The resolution rule Given two clauses in the form A 0..A i..a m -B 1...B n. and C 1...C k - D 1..D j..d l. If e is a unifier of A i and D j (i.e. e(a i )=e(d j )) Then the resolvent of the above two clauses is e(a 0 ).. e(a i-1 )e(a i+1 ).. e(a m ) e(c 1 )..e(c k ) - e(b 1 ).. e(b n ) e(d 1 ).. e(d j-1 )e(d j+1 ).. e(d l ). Example C 1 p(y)- r(x, Y), q(y, Z). C 2 - p(f(1)). Unifier of p(f(1)) and p(y) e=[y/f(1)] The resolvent of C 1 and C 2 - r(x, f(1)), q(f(1), Z). 23
Example [Nilsson] C0 proud(x) - parent(x, Y), newborn(y). C1 parent(x, Y) - father (X, Y). C2 parent(x, Y) - mother(x, Y). C3 father(adam, mary). C4 newborn(mary). G0 - proud(z). Unifier of proud(..) in C0 and G0 e=[x/z], resolvent G1 - parent(z,y), newborn(y). Unifier of parent(..) in C1 and G1 e=[x/z, Y/Y], resolvent G2 - father(z,y), newborn(y). To prevent mistakes, we rename the variables whenever we use a fresh copy of a clause. 24
Example (cont.) [Nilsson] G0 - proud(z). (copy of) C0 proud(x 1 ) - parent(x 1, Y 1 ), newborn(y 1 ). Resolve with G0 e=[x 1 /Z] G1 - parent(z,y 1 ), newborn(y 1 ). (copy of) C1 parent(x 2,Y 2 ) - father (X 2, Y 2 ). Resolve with G1 e=[x 2 /Z, Y 2 /Y 1 ] G2 - father(z, Y 1 ), newborn(y 1 ). (copy of) C3 father(adam, mary). Resolve with G2 e=[z/adam, Y 1 /mary] G3 -newborn(mary). (copy of) C4 newborn(mary). Resolve with G3 e=[] G4 - Empty clause answer to query true if Z=adam 25
Example (cont.) [Nilsson] Just a different notation for - 1 1 1 1 1 1 2 2 2 2 1 1 Refutation Tree for G0 26
Linear Refutation We can resolve with different clauses and keep adding new clauses forever! To prevent this, Linear Refutation always starts with a goal (as the example showed previously). Prolog s computation rule Always selects the leftmost subgoal, although logically there is no order for the subgoals. Example When resolving G1 - parent(z,y 1 ), newborn(y 1 )., parent(..) was selected to resolve upon. Prolog also starts from the top of knowledge base and goes down the list of facts and rules. 27
Search Space Based on linear refutation and Prolog s computation rule, we know the search tree of Prolog. Search tree The root in the search tree is the main goal G 0. A child node is a new goal G i obtained through resolution. A link is labelled with the clause resolved with and the substitution. Example C0 grandfather(x,z) - father(x,y), parent(y,z). C1 parent(x,y) - father(x,y). C2 parent(x,y) - mother(x,y). C3 father(a,b)-. C4 mother(b,c)-. C5 mother(b,d)-. G0 - grandfather(a,x). 28
Search Space (example) C0, [Z/X, X 0 /a] 0 C3, [Y 0 /b] C0 grandfather(x,z) - father(x,y), parent(y,z). C1 parent(x,y) - father(x,y). C2 parent(x,y) - mother(x,y). C3 father(a,b)-. C4 mother(b,c)-. C5 mother(b,d)-. G0 - grandfather(a,x). C1, [X 1 /b, Y 1 /X] C2, [X 2 /b, Y 2 /X] Nothing to resolve with, backtrack! C4, [X/c] TRUE, X=c ; (backtrack!) C5, [X/d] TRUE, X=d 29
Search Space What is the search strategy used by Prolog for searching the tree? Depth First Search or Breadth First Search Prolog uses DFS 30
Questions 1. Why is it ok to rename the variables every time we use a fresh copy of a clause (slide #24)? Doesn t that change the clause?! Note that each variable X in our clause is actually bound by a universal quantifier (X). In the last step of converting to CNF, we removed the quantifiers for simpler notation. Renaming the variable bound by a quantifier (dummy renaming) does not alter the semantics of the formula. 31
Questions 2. Why do we always have goals in each node of Prolog s search tree? Why don t we have facts and rules as resolvents?! Each goal is a clause with no head and several literals in the body. On the other hand, each clause in the knowledge base is a fact or a rule, having exactly one literal in the head and zero or more literals in the body. Based on linear refutation, Prolog always resolves the goal with its set of facts and rules. The one literal in the head of the facts and rules, is always cut (resloved) with a subgoal, leaving no literals in the head. Therefore after each resolution step, the resolvent is always a goal. 32
Examples for resolution rule (Slide #23) Example 1 Consider two clauses student(john, 3401)-. - student(john, 3401). We can resolve these two clauses upon the literal student(john,3401), since 1. It is unifiable in both clauses after no substitution (e=[]). 2. It apears on the right side (of - ) in one clause and on the left side in the other clause. The resolvent (cutting the literal in both clauses, and writing what is left from both clauses) is therefore - (the empty clause) 33
Examples for resolution rule (Slide #23) Example 2 Consider two clauses student(john, 3401)-. - student(x, 3401). We can resolve these two clauses upon the literals student(john,3401) and student(x,3401), since 1. These literals are unifiable after substitution e=[x/john]. e(student(john,3401))= e(student(x,3401)) 2. One apears on the right side (of - ) in one clause and the other on the left side in the other clause. The resolvent (cutting the literal in both clauses, and writing what is left from both clauses) is therefore - (the empty clause) 34
Examples for resolution rule (Slide #23) Example 3 Consider two clauses pass(x)- student(x, 3401), study (X). - pass(john). We can resolve these two clauses upon the literals pass(john) and pass(x), since 1. These literals are unifiable after substitution e=[x/john]. e(pass(john))= e(pass(x)) 2. One apears on the right side (of - ) in one clause and the other on the left side in the other clause. The resolvent (cutting the literal in both clauses, and writing what is left from both clauses) is therefore - e(student(x,3401)), e(study(x)). After applying the substitution, it will simplify to - student(john, 3401), study(john). 35