25
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

CSCE 4613 Artificial Inteligence

  • Upload
    lang

  • View
    104

  • Download
    3

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: CSCE 4613  Artificial  Inteligence

Resolution and Unification

Automated Reasoning, or theorem provingbased on chapter 8, Ben Coppin, Artificial Intelligence Illuminated

CSCE 4613 Artificial Inteligence

11.05.2013Nikhil Thomas

Page 2: CSCE 4613  Artificial  Inteligence

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.

Page 3: CSCE 4613  Artificial  Inteligence

Resolution• A proof method• Has fixed number of steps• Can be automated

Page 4: CSCE 4613  Artificial  Inteligence

Normal FormsWell-Formed Formula (WFF)

In Conjunctive Normal Form (CNF) : set of phrases and-ed together

where each clause, Ai, is of the formB1∨ B2∨ B3∨ . . . ∨ Bn

A1∧ A2∧ A3∧ . . . ∧ An

In Disjunctive Normal Form (DNF): set of phrases or-ed together

A (B C) (¬A ¬B ¬C D)∨ ∧ ∨ ∧ ∧ ∧

A (B C) (¬A ¬B ¬C D)∧ ∨ ∧ ∨ ∨ ∨

Page 5: CSCE 4613  Artificial  Inteligence

Conversion of WFF to CNF

1. A ↔ B ≡ (A→B) (B→A)∧2. A →B ≡ ¬A B∨3. ¬(A B) ≡¬A ¬B∧ ∨4. ¬(A B) ≡¬A ¬B∨ ∧5. ¬¬A ≡A6. 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)

Example

Conversion of WFF to CNF can be automated.

Page 6: CSCE 4613  Artificial  Inteligence

The Resolution RuleA B ¬B C ∨ ∨ A C∨

if A implies B and B implies C, then A implies C.

{(A, B), (¬B, C)} can be resolved to give

{(A, C)}

Resolution Rule applied to wff ’s in clause form, (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

Page 7: CSCE 4613  Artificial  Inteligence

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} |= ⊥

Page 8: CSCE 4613  Artificial  Inteligence

Proof by Refutation (a.k.a proof by contradiction)

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

• 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

Page 9: CSCE 4613  Artificial  Inteligence

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

∴ original conclusion was not valid.

Did not resolve to ‘ ’ (falsum)⊥

Page 10: CSCE 4613  Artificial  Inteligence

Application of Resolution

Check whether solution exists for combinatorial search problem

Eg: three-coloring problem for graphs

A graph representing a three-coloring problem

Page 11: CSCE 4613  Artificial  Inteligence

Resolution in Predicate Logic

Normal Forms for Predicate Logic

• Move and quantifiers to the beginning of the expression∀ ∃• prenex normal form.

1. A ↔B ≡ (A→B) (B→A)∧2. A →B ≡ ¬A B∨3. ¬(A B) ≡ ¬A ¬B∧ ∨4. ¬(A B) ≡ ¬A ¬B∨ ∧5. ¬¬A ≡ A6. 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))∃ ∧ ∃ ∃ ∃ ∧

∀ :- Universal Quantifier (for all ) ∃ :- Existential Quantifier (there exists one or for some)

Page 12: CSCE 4613  Artificial  Inteligence

SkolemizationBefore 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, z))∃ ∀ ∧ ( x)( z)(P(x) Q(∀ ∀ ∧ f(x), z)to

( w)( x)∀ ∀ ( y)( z)(P(x) Q(w, y, z))∃ ∀ ∧ to ( w)( x)( z)(P(x) Q(w, ∀ ∀ ∀ ∧ f(w,x), z)

Page 13: CSCE 4613  Artificial  Inteligence

Unification• Sometimes clauses can be resolved by making substitutions

{(P(w,x)), (¬P(y,z))} P with ¬P, are not currently identical they have different arguments

replace w with y and x with z

{(P(y,z)), (¬P(y,z))} |= ⊥

substitution : {y/w, z/x}

σ= {y/w, z/x}

A = P(w,x)B = ¬P(y,z)

Aσ = P(y,z)Bσ= ¬P(y,z)

σ to indicate a substitution

if a σ can be applied to a set of clauses {A, B, C,. . . }such thatAσ = 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.

Page 14: CSCE 4613  Artificial  Inteligence

Unification (contd)

compositionoperator, o = composition of those two substitutions

σ1 = {a1/x1, a2/x2, . . . , am/xm}σ2 = {b1/y1, b2/y2, . . . , bn/yn}

σ1 o σ2 = {a1σ2/x1, a2σ2/x2, . . . , anσ2/xn, b1/y1, b2/y2, . . . , bn/yn}

If yi = xj then bi/yi can be eliminated.If aiσ2 = xi then aiσ2/xi can be eliminated

σ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}

Example

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.most general unifier (mgu) : u1for a set S = {A, B, C, . . . } If any other unifier u2 can be expressed as the composition of u1 with some other substitution

Page 15: CSCE 4613  Artificial  Inteligence

Unification AlgorithmTo unify a set of clauses, S0:Initialize: σ0 = {}i = 0

Loop: If Si has only one element, terminate and report that σi isthe mgu for S0.

If Si has more than one element, find the disagreement setDi 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 containedwithin t, then we say:σi 1= σi o {t/x}Si 1 = Si {t/x}

Increment i, and repeat the loop.

Page 16: CSCE 4613  Artificial  Inteligence

Unification ExampleS0 = {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= σo o {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}.

Page 17: CSCE 4613  Artificial  Inteligence

Resolution Algorithm• 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 LBsuch that LA and ¬LB have a mgu σ, then we can resolve A and B to give theresolvent 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)}

Example

Page 18: CSCE 4613  Artificial  Inteligence

Resolution for Problem Solvingpremises: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.

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.”

premises and the conclusion in predicate calculus

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

( 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)))∀ ∧

Page 19: CSCE 4613  Artificial  Inteligence

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)))∀ ∧convert this into a set of clauses

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)}

( 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 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)}

Page 20: CSCE 4613  Artificial  Inteligence

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)))∀ ∧

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)}

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)}}

Page 21: CSCE 4613  Artificial  Inteligence

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)))∀ ∧

apply resolution :First, unify lines 1 and 3 using {a/x} and resolve these two, to give8. {¬F(y), ¬(G(y), ¬L(a,y)}the unifier {b/y} can be applied to lines 2 and 5, which are thenresolved to give9. {L(a,b)}Now we apply {b/y} to resolve line 5 with line 8 to give10. {¬(G(b), ¬L(a,b)}Now lines 9 and 10 can be resolved to give11. {¬(G(b)}Finally, line 7 can be resolved with line 11 to give

12. Falsum⊥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,and so the argument is a valid one

Page 22: CSCE 4613  Artificial  Inteligence

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.

Page 23: CSCE 4613  Artificial  Inteligence

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), 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),. . . }

Page 24: CSCE 4613  Artificial  Inteligence

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

Page 25: CSCE 4613  Artificial  Inteligence

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

Thank youhttps://sherlockxxi.wikispaces.com/Funny+things+and+curiosities+about+Sherlock+Holmes