Resolution and Unification Automated Reasoning or theorem proving

  • Slides: 25
Download presentation
Resolution and Unification Automated Reasoning, or theorem proving based on chapter 8, Ben Coppin,

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 Resolution for problem Solving Example

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

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

Normal Forms Well-Formed Formula (WFF) In Conjunctive Normal Form (CNF) : set of phrases and-ed together A 1∧ A 2∧ A 3∧. . . ∧ An where each clause, Ai, is of the form B 1∨ B 2∨ B 3∨. . . ∨ 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)

The Resolution Rule A ∨ B ¬B ∨ C A∨C if A implies B

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), (¬B, C)} {(A, C)} can be resolved to give (A ∨ B) ∧ (¬A ∨ C) ∧ (¬B ∨ C) {(A, B), (¬A, C), (¬B, C)} {(B, C), (¬B, C)} {C} (A ∨ B) ∧ (¬A ∨ C) ∧ (¬B ∨ C) |= C ‘|=‘ : resolves to

Resolution Refutation {(¬A, B), (¬A, ¬B, C), A, ¬C} {(¬A, C), A, ¬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 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 ∨ C {(B, C), ¬B, ¬C} {C, ¬C} ⊥ I will get wet : true

Resolution Proof as a Tree {(¬A, B), (¬B, C), (¬C, D), (¬D, E, F),

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

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 Normal Forms for Predicate Logic • Move ∀ and ∃

Resolution in Predicate Logic 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) 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) ∧

Skolemization Before resolution • eliminate all the existential quantifiers, ∃, from the wff •

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 skolem function Example of Skolemization (∀x)(∃y)(∀z)(P(x) ∧ Q(y, to z)) (∀w)(∀x)(∃y)(∀z)(P(x) ∧ Q(w, y, to z)) (∀x)(∀z)(P(x) ∧ Q(f(x), z) (∀w)(∀x)(∀z)(P(x) ∧ Q(w, f(w, x), z)

Unification σ to indicate a substitution • Sometimes clauses can be resolved by making

Unification σ to indicate a substitution • Sometimes clauses can be resolved by making substitutions σ= {y/w, z/x} {(P(w, x)), (¬P(y, z))} P with ¬P, are not currently identical they have different arguments A = P(w, x) B = ¬P(y, z) replace w with y and x with z Aσ = P(y, z) Bσ= ¬P(y, z) {(P(y, z)), (¬P(y, z))} |= ⊥ substitution : {y/w, z/x} if a σ can be applied to a set of clauses {A, B, C, . . . } such that Aσ = Bσ= Cσ=. . . 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) composition operator, o = composition of those two substitutions σ1 = {a

Unification (contd) composition operator, o = composition of those two substitutions σ1 = {a 1/x 1, a 2/x 2, . . . , am/xm} σ2 = {b 1/y 1, b 2/y 2, . . . , bn/yn} σ1 o σ2 = {a 1σ2/x 1, a 2σ2/x 2, . . . , anσ2/xn, b 1/y 1, b 2/y 2, . . . , bn/yn} If yi = xj then bi/yi can be eliminated. If aiσ2 = xi then aiσ2/xi can be eliminated most general unifier (mgu) : u 1 for a set S = {A, B, C, . . . } If any other unifier u 2 can be expressed as the composition of u 1 with some other substitution 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} y/y is removed : aiσ2 = xi y/x is removed : yi = xj σ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} σ1 o σ2 ≠ σ2 o σ1.

Unification Algorithm To unify a set of clauses, S 0: Initialize: σ0 = {}

Unification Algorithm To unify a set of clauses, S 0: Initialize: σ0 = {} i=0 Loop: If Si has only one element, terminate and report that σi is the mgu for S 0. 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= σi o {t/x} Si 1 = Si {t/x} Increment i, and repeat the loop.

Unification Example S 0 = {P(a, x, y, z), P (x, y, z, w)}

Unification Example S 0 = {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. D 0 = {a, x} σ1= σo o {a/x} = {a/x} S 1 = So {a/x} = {P(a, a, y, z), P (a, y, z, w)} D 1 = {a, y} σ2 = {a/x} o {a/y} = {a/x, a/y} S 2 = S 1 {a/x, a/y} = {P(a, a, a, z), P (a, a, z, w)} D 2 = {a, z} σ3 = {a/x, a/y} o {a/z} = {a/x, a/y, a/z} S 3 = S 2 {a/x, a/y, a/z} = {P(a, a, a, a), P(a, a, a, w)} D 3 = {a, w} σ4 = {a/x, a/y, a/z} o {a/w} = {a/x, a/y, a/z, a/w} S 4 = S 3 {a/x, a/y, a/z, a/w} = {P(a, a, a, a), P(a, a, a, a)} = {P(a, a, a, a)} S 4 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

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: 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. {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)}

Resolution for Problem Solving premises: 1. Some children will eat any food. 2. No

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. 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: No food made by Cadbury’s is green. Conclusion: (∀x)((F(x) ∧ M(c, x))→¬G(x)) 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. ” First, negate the conclusion and add it to the set of premises (∃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

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. (∃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))) convert this into a set of clauses ∧ ¬ ((∀x)((F(x) ∧ M(c, x))→¬G(x))) 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)} 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))) 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 De. Morgan’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)}

1. Some children will eat any food. 2. No children will eat food that

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. (∃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) expression 3: ∧ M(c, x))→¬G(x))) Conclusion: No food made by Cadbury’s is green (∀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 De. Morgan’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)} (∃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))) conclusion, which has been negated: ∧ ¬ ((∀x)((F(x) ∧ M(c, x))→¬G(x))) ¬(∀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)) De. Morgan’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)}}

1. Some children will eat any food. 2. No children will eat food that

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. (∃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)} 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 ü 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, and so the argument is a valid one

Horn Clauses • a clause that has, at most, one positive literal A ∨

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 ofrules that 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 • Herbrand universe (for a ser of Clauses S) Ø the set

Herbrand Universes • Herbrand universe (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), 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

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

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/tt 0988045/trivia? tab=qt&ref_=tt_trv_qu https: //sherlockxxi. wikispaces. com/Funny+things+and+curiosities+about+Sherlock+Holmes Thank you