260 likes | 451 Views
Resolution and Unification Automated Reasoning, or theorem proving based on chapter 8 , Ben Coppin, Artificial Intelligence Illuminated. CSCE 4613 Artificial Inteligence. 11.05.2013 Nikhil Thomas. Overview. Resolution Skolemization Unification Resolution Algorithm
E N D
Resolution and UnificationAutomated Reasoning, or theorem provingbased on chapter 8, Ben Coppin, Artificial Intelligence Illuminated CSCE 4613 Artificial Inteligence 11.05.2013 Nikhil Thomas
Overview • Resolution • Skolemization • Unification • Resolution Algorithm • Resolution for problem Solving Example 1. Some children will eat any food. 2. No children will eat food that is green. 3. All children like food made by Cadbury’s. Prove:- No food made by Cadbury’s is green.
Resolution • A proof method • Has fixed number of steps • Can be automated
Normal Forms Well-Formed Formula (WFF) In Conjunctive Normal Form (CNF) : set of phrases and-ed together A1∧ A2∧ A3∧ . . . ∧ An where each clause, Ai, is of the form B1∨ B2∨ B3∨ . . . ∨ Bn A ∧ (B ∨ C) ∧ (¬A ∨ ¬B ∨ ¬C ∨ D) In Disjunctive Normal Form (DNF): set of phrases or-ed together A ∨ (B ∧ C) ∨ (¬A ∧ ¬B ∧ ¬C ∧ D)
Conversion of WFF to CNF Example 1. A ↔ B ≡ (A→B) ∧ (B→A) 2. A →B ≡ ¬A ∨ B 3. ¬(A ∧ B) ≡¬A ∨ ¬B 4. ¬(A ∨ B) ≡¬A ∧ ¬B 5. ¬¬A ≡A 6. A ∨ (B ∧ C) ≡(A ∨ B) ∧ (A ∨ C) A↔ (B ∧ C) WFF (A→(B ∧ C)) ∧ ((B ∧ C)→A) (¬A ∨ (B ∧ C)) ∧ (¬(B ∧ C) ∨ A) (¬A ∨ (B ∧ C)) ∧ (¬B ∨ ¬C ∨ A) (¬A ∨ B) ∧ (¬A ∨ C) ∧ (¬B ∨ ¬C ∨ A) CNF {(¬A, B), (¬A, C), (¬B, ¬C, A)} Clause Form (set of clauses) Conversion of WFF to CNF can be automated.
The Resolution Rule A ∨ B ¬B∨ C A ∨ C if A implies B and B implies C, then A implies C. Resolution Rule applied to wff’s in clause form, (A ∨ B) ∧ (¬A ∨ C) ∧ (¬B ∨ C) {(A, B), (¬A, C), (¬B, C)} {(A, B), (¬B, C)} can be resolved to give {(A, C)} {(B, C), (¬B, C)} {C} ‘|=‘ : resolves to (A ∨ B) ∧ (¬A ∨ C) ∧ (¬B ∨ C) |= C
Resolution Refutation {(¬A, B), (¬A, ¬B, C), A, ¬C} {(¬A, C), A, ¬C} {C, ¬C} ⊥ = falsum => original clauses were inconsistent {(¬A, B), (¬A, ¬B, C), A, ¬C} |= ⊥
Proof by Refutation (a.k.a proof by contradiction) • Proof by Refutation or Proof by Contradiction • Negate conclusion • Add it to set of premises • Prove resultant set of expressions is unsatisfiable • Implies argument is valid If it rains and I don’t have an umbrella, then I will get wet. It is raining, and I don’t have an umbrella. Therefore, I will get wet. {(¬A, B, C), A, ¬B, ¬C} (A ∧ ¬B)→C (A ∧ ¬B)→C ≡ ¬(A ∧ ¬B) ∨ C ≡ ¬A ∨ B ∨ C A ∧ ¬B {(B, C), ¬B, ¬C} {C, ¬C} ⊥ ∴C I will get wet : true
Resolution Proof as a Tree {(¬A, B), (¬B, C), (¬C, D), (¬D, E, F), A, ¬F)} Did not resolve to ‘⊥’ (falsum) ∴ original conclusion was not valid.
Application of Resolution Check whether solution exists for combinatorial search problem Eg: three-coloring problem for graphs A graph representing a three-coloring problem
Resolution in Predicate Logic 1. A ↔B ≡ (A→B) ∧ (B→A) 2. A →B ≡ ¬A ∨ B 3. ¬(A ∧ B) ≡ ¬A ∨ ¬B 4. ¬(A ∨ B) ≡ ¬A ∧ ¬B 5. ¬¬A ≡ A 6. A ∨ (B ∧ C) ≡ (A ∨ B) ∧ (A ∨ C) 7. ¬(∀x)A(x) ≡ (∃x)¬A(x) 8. ¬(∃x)A(x) ≡ (∀x)¬A(x) 9. (∀x)A(x) ∧ B ≡ (∀x)(A(x) ∧ B) 10. (∀x)A(x) ∨ B ≡ (∀x)(A(x) ∨ B) 11. (∃x)A(x) ∧ B ≡ (∃x)(A(x) ∧ B) 12. (∃x)A(x) ∨ B ≡ (∃x)(A(x) ∨ B) 13. (∀x)A(x) ∧ (∀y)B(y) ≡ (∀x)(∀y)(A(x) ∧ B(y)) 14. (∀x)A(x) ∧ (∃ y)B(y) ≡ (∀x)(∃y)(A(x) ∧ B(y)) 15. (∃x)A(x) ∧ (∀y)B(y) ≡ (∃x)(∀y)(A(x) ∧ B(y)) 16. (∃x)A(x) ∧ (∃y)B(y) ≡ (∃x)(∃y)(A(x) ∧ B(y)) Normal Forms for Predicate Logic • Move ∀ and ∃ quantifiers to the beginning of the expression • prenex normal form. ∀ :- Universal Quantifier (for all ) ∃ :- Existential Quantifier (there exists one or for some)
Skolemization • Before resolution • eliminate all the existential quantifiers, ∃, from the wff • replacing existentially quantified variable by a constant • ∃(x) P(x) convert to P(c) : c is a constant that has not been used elsewhere in the wff • P(c) is not logically equivalent to ∃(x) P(x) • But useful for resolution to see whether a solution exists • ‘c’ is called a Skolem constant • slightly differently in cases where the ∃ follows a ∀ quantifier • (∀x)(∃y)(P(x,y)) • (∀x)(P(x,f(x)) Replace ’y’ with a skolemfunction Example of Skolemization (∀x)(∃y)(∀z)(P(x) ∧ Q(y, z)) (∀x)(∀z)(P(x) ∧ Q(f(x), z) to (∀w)(∀x)(∀z)(P(x) ∧ Q(w, f(w,x), z) to (∀w)(∀x)(∃y)(∀z)(P(x) ∧ Q(w, y, z))
Unification σ to indicate a substitution • Sometimes clauses can be resolved by making substitutions σ= {y/w, z/x} A = P(w,x) B = ¬P(y,z) Aσ = P(y,z) Bσ= ¬P(y,z) P with ¬P, are not currently identical they have different arguments {(P(w,x)), (¬P(y,z))} replace w with y and x with z {(P(y,z)), (¬P(y,z))} |= ⊥ if a σcan be applied to a set of clauses {A, B, C,. . . } such that Aσ = Bσ= Cσ= . . . substitution : {y/w, z/x} Then σis called a unifier for the set {A, B, C, . . . }. A constant, such as a, cannot be replaced by a variable. A variable x cannot be replaced by a term that contains x.
Unification (contd) Example σ1 = {a/x, x/y, f(a)/z} σ2 = {y/x, f(z)/y} σ1 o σ2 = {aσ2/x, xσ2/y, f(a)σ2/z, y/x, f(z)/y} = {a/x, y/y, f(a)/z, y/x, f(z)/y} = {a/x, f(a)/z, f(z)/y} composition operator, o = composition of those two substitutions σ1 = {a1/x1, a2/x2, . . . , am/xm} σ2 = {b1/y1, b2/y2, . . . , bn/yn} y/y is removed : aiσ2 = xi y/x is removed : yi= xj σ1 o σ2 = {a1σ2/x1, a2σ2/x2, . . . , anσ2/xn, b1/y1, b2/y2, . . . , bn/yn} σ2 o σ1 = {yσ1/x, f(z)σ1/y, a/x, x/y, f(a)/z} = {x/x, f(f(a))/y, a/x, x/y, f(a)/z} = {f(f(a))/y, f(a)/z} If yi = xj then bi/yi can be eliminated. If aiσ2 = xi then aiσ2/xi can be eliminated most general unifier (mgu) : u1 for a set S = {A, B, C, . . . } If any other unifier u2 can be expressed as the composition of u1 with some other substitution σ1 o σ2 ≠ σ2 o σ1.
Unification Algorithm To unify a set of clauses, S0: Initialize: σ0= {} i = 0 Loop: If Si has only one element, terminate and report that σiis the mgu for S0. If Si has more than one element, find the disagreement set Di of Si (i.e., the substitutions that need to be made). If Di contains a variable x and a term t where x is not contained within t, then we say: σi 1= σio {t/x} Si 1 = Si {t/x} Increment i, and repeat the loop.
Unification Example S0 = {P(a, x, y, z), P (x, y, z, w)} (a is a constant, and x, y, z are variables) We initialize σ0= {} and i = 0. D0= {a,x} σ1= σoo {a/x} = {a/x} S1 = So {a/x} = {P(a, a, y, z), P (a, y, z, w)} D1 = {a,y} σ2= {a/x} o {a/y} = {a/x, a/y} S2 = S1 {a/x, a/y} = {P(a, a, a, z), P (a, a, z, w)} D2 = {a, z} σ3= {a/x, a/y} o {a/z} = {a/x, a/y, a/z} S3 = S2 {a/x, a/y, a/z} = {P(a, a, a, a), P(a, a, a, w)} D3 = {a, w} σ4= {a/x, a/y, a/z} o {a/w} = {a/x, a/y, a/z, a/w} S4 = S3 {a/x, a/y, a/z, a/w} = {P(a, a, a, a), P(a, a, a, a)} = {P(a, a, a, a)} S4 has just one element, mgu, σ4 : {a/x, a/y, a/z, a/w}.
Resolution Algorithm Example • First, negate the conclusion and add it to the list of assumptions. • Now convert the assumptions into prenex normal form. • Next, skolemize the resulting expression. • Now convert the expression into a set of clauses. • Now we resolve the clauses using the following method: {A(x,y), B(f(y)), C(x, y, z)} {A(f(x), z), ¬B(z), C(f(a), b, z)} {A(x,y), B(f(y)), C(x, y, z)}{f(y)/z} - B(f(y)){f(y)/z} U (A(f(x), z), ¬B(z), C(f(a), b, z)} - ¬B(z){f(y)/z} = {A(x,y), C(x, y, z)} U {A(f(x), z), C(f(a), b, z)} = {A(x,y), C(x, y, z), A(f(x), z), C(f(a), b, z)} If our clauses are {A, B, C, . . . } A has a literal LA and B has a literal LB such that LA and ¬LB have a mguσ, then we can resolve A and B to give the resolvent of these clauses, which is: (Aσ- LAσ) U (Bσ- LBσ) ∪ set union operator, - set difference operator.
Resolution for Problem Solving premises: 1. Some children will eat any food. 2. No children will eat food that is green. 3. All children like food made by Cadbury’s. Conclusion: No food made by Cadbury’s is green. Primises: 1. (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) 2. (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) 3. (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) Conclusion: (∀x)((F(x) ∧ M(c,x))→¬G(x)) First, negate the conclusion and add it to the set of premises premises and the conclusion in predicate calculus C(x) means “x is a child.” F(x) means “x is food.” L(x, y) means “x likes y.” G(x) means “x is green.” M(x, y) means “x makes y.” c means “Cadbury’s.” (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ∧ (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) ∧ (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) ∧ ¬ ((∀x)((F(x) ∧ M(c,x))→¬G(x)))
1. Some children will eat any food. 2. No children will eat food that is green. 3. All children like food made by Cadbury’s. Conclusion: No food made by Cadbury’s is green (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ∧ (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) ∧ (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) ∧ ¬ ((∀x)((F(x) ∧ M(c,x))→¬G(x))) (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ∧ (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) ∧ (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) ∧ ¬ ((∀x)((F(x) ∧ M(c,x))→¬G(x))) convert this into a set of clauses expression 2 (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) →is eliminated first: (∀x)(¬C(x) ∨ (∀y)(¬(F(y) ∧ G(y)) ∨ ¬L(x,y))) Now DeMorgan’s law is applied: (∀x)(¬C(x) ∨ (∀y)(¬F(y) ∨ ¬G(y) ∨ ¬L(x,y))) Quantifiers are moved to the front: (∀x)(∀y)(¬C(x) ∨ ¬F(y) ∨ ¬G(y) ∨ ¬L(x,y)) This can be written as the following single clause: {¬C(x), ¬F(y), ¬(G(y), ¬L(x,y)} expression 1: (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ‘→’ must be eliminated first: (∃x)(C(x) ∧ (∀y)(¬F(y) ∨ L(x,y))) bring the quantifiers to the front (∃x)(∀y)(C(x) ∧ (¬F(y) ∨ L(x,y))) skolemize, to eliminate the existential quantifier (∀y)(C(a) ∧ (¬F(y) ∨ L(a,y))) This can be expressed as the following clauses: {C(a)}, {¬F(y), L(a,y)}
1. Some children will eat any food. 2. No children will eat food that is green. 3. All children like food made by Cadbury’s. Conclusion: No food made by Cadbury’s is green (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ∧ (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) ∧ (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) ∧ ¬ ((∀x)((F(x) ∧ M(c,x))→¬G(x))) (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ∧ (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) ∧ (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) ∧ ¬ ((∀x)((F(x) ∧ M(c,x))→¬G(x))) conclusion, which has been negated: ¬(∀x)((F(x) ∧ M(c,x))→¬G(x)) First, we eliminate →: ¬(∀x)(¬(F(x) ∧ M(c,x)) ∨ ¬G(x)) apply the quantifier equivalence to move the ¬ from the front of the expression: (∃x)¬(¬(F(x) ∧ M(c,x)) ∨ ¬G(x)) DeMorgan’s law can now be applied: (∃x)(¬¬(F(x) ∧ M(c,x)) ∧ ¬¬G(x)) We can now remove ¬¬: (∃x)(F(x) ∧ M(c,x) ∧ G(x)) This expression is now skolemized: F(b) ∧ M(c,b) ∧ G(b)) This can be expressed as the following set of clauses: {{F(b)}, {M(c,b)}, {G(b)}} expression 3: (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) We first eliminate →: (∀x)(¬(F(x) ∧ M(c,x)) ∨ (∀y)(¬C(y) ∨ L(y,x))) Next, we apply DeMorgan’s law: (∀x)(¬F(x) ∨ ¬M(c,x) ∨ (∀y)(¬C(y) ∨ L(y,x))) bring the quantifiers to the front of the expression: (∀x)(∀y)(¬F(x) ∨ ¬M(c,x) ∨ ¬C(y) ∨ L(y,x)) This can be expressed as the following single clause: {¬F(x), ¬M(c,x), ¬C(y), L(y,x)}
1. Some children will eat any food. 2. No children will eat food that is green. 3. All children like food made by Cadbury’s. Conclusion: No food made by Cadbury’s is green apply resolution : First, unify lines 1 and 3 using {a/x} and resolve these two, to give 8. {¬F(y), ¬(G(y), ¬L(a,y)} the unifier {b/y} can be applied to lines 2 and 5, which are then resolved to give 9. {L(a,b)} Now we apply {b/y} to resolve line 5 with line 8 to give 10. {¬(G(b), ¬L(a,b)} Now lines 9 and 10 can be resolved to give 11. {¬(G(b)} Finally, line 7 can be resolved with line 11 to give 12. ⊥ Falsum (∃x)(C(x) ∧ (∀y)(F(y)→L(x,y))) ∧ (∀x)(C(x)→(∀y)((F(y) ∧ G(y))→¬L(x,y))) ∧ (∀x)((F(x) ∧ M(c,x))→(∀y)(C(y)→L(y,x))) ∧ ¬ ((∀x)((F(x) ∧ M(c,x))→¬G(x))) Clauses 1. {C(a)} 2. {¬F(y), L(a,y)} 3. {¬C(x), ¬F(y), ¬(G(y), ¬L(x,y)} 4. {¬F(x), ¬M(c,x), ¬C(y), L(y,x)} 5. {F(b)} 6. {M(c,b)} 7. {G(b)} • set of clauses derived from the premises 1, 2, and 3, and the negation of the conclusion, are unsatisfiable. • conclusion does indeed follow from the premises,andso the argument is a valid one
Horn Clauses • a clause that has, at most, one positive literal • A ∨ ¬B ∨ ¬C ∨ ¬D ∨ ¬E . . . • can take three forms • fact: clause with no negative literals • rule relation: one positive literal, and one or more negative literals • goal, or a headless clause: no positive literal • A program in PROLOG consists of a set of Horn clauses • PROLOG applies unification and resolution to attempt to derive conclusions from a set ofrulesthat are defined in the language • the programmer • define rules and facts • set up a goal • PROLOG attempt to prove the goal, using unification and resolution.
Herbrand Universes • Herbranduniverse (for a ser of Clauses S) • the set of constants that are contained within S, and the set of functions in S applied to those constants • Constants and functions are known as ground terms. • S is {{A(x), B(y, a), C(z)}, {D(x, a, b), ¬E(y, c, b)}} HS = {a, b, c} • S is {{A(x), B(y, a), C(z)}, {D(x, a, b), ¬E(y, f(x, y))}} HS = {a, b, c, f(a, a), f(a, b), f (b, a), f(b, b), f(f(a), a), f(f(a), f(a)) . . . } • S is {{A(x), B(y, z), C(z)}, {D(x, y, z), ¬E(y, x)}} HS = {a} • ground instance of a clause in S is a version of that clause in which any variables it contains have been replaced by ground terms from HS. • S is {{A(x), B(y, a), C(z)}, {D(x, a, b), ¬E(y, c, b)}} {A(a), B(b, a), C(a)} • The Herbrand Base HS(S) • set of ground atoms that can be obtained by replacing variables in S by members of HS • A ground atom is a formula that contains no variables, only ground terms • S is {{A(x), B(y, a), C(z)}, {D(x, a, b), ¬E(y, c, b)}} HS = {a, b, c} • HS(S) = {{A(a), B(a, a), C(a), D(a, a, b), ¬E(a, c, b),A(b), B(b, a), C(b), D(b, a, b), ¬E(b, c, b),. . . }
Summary • Automated Reasoning and Theorem Proving • Proof by Refutation or Proof by Contradiction • Negate conclusion • Prove resultant set of expressions is unsatisfiable • Implies argument is valid • Resolution • Well Formed Formula to CNF • Prenex Normal Form • Skolemization • Unification • Resolution
Never theorize before you have data. Invariably, you end up twisting facts to suit theories, instead of theories to suit facts. - Sherlock Holmes http://www.imdb.com/title/tt0988045/trivia?tab=qt&ref_=tt_trv_qu https://sherlockxxi.wikispaces.com/Funny+things+and+curiosities+about+Sherlock+Holmes Thank you