Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big...

30
Resolution

Transcript of Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big...

Page 1: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Resolution

Page 2: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

An example1. John is a lawyer.

2. Lawyers are rich.

3. Rich people have big houses.

4. Big houses are a lot of work.

• We would like to conclude that John’s house is a lot of work.

• Natural languages are ambiguous so we can have different axiomatizations.

Page 3: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Axiomatization 11. lawyer(john)2. x lawyer(x) rich(x)3. x rich(x) y house(x,y) 4. x,y rich(x) house(x,y) big(y)5. x,y ( house(x,y) big(y) work(y) )

• 3 and 4, say that rich people do have at least one house and all their houses are big.

• Conclusion we want to show: house(john, jhouse) work(john, jhouse)

• Or, do we want to conclude that John has at least one house that needs a lot of work? I.e.

y house(john,y) work(y)

Page 4: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Axiomatization 21. lawyer(john)2. x lawyer(x) rich(x)3. x rich(x) y house(x,y) big(y) 4. x,y ( house(x,y) big(y) work(y) )

• Now, 3 says that rich people have at least one house which is big. • Conclusion we want to show:

house(john, jhouse) work(john, jhouse)Well, this is not anymore a conclusion we can or want to derive!

• So, now we want to conclude that John has at least one house that needs a lot of work? I.e.

y house(john,y) work(y)

Page 5: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Let’s fix axiomatization 1…1. lawyer(john)2. x lawyer(x) rich(x)3. x rich(x) y house(x,y) 4. x,y rich(x) house(x,y) big(y)5. x,y ( house(x,y) big(y) work(y) )

• Conclusion we want to show: John has at least one house that needs a lot of work. I.e.y house(john,y) work(y)

• Think about sentence 3. It says that every rich person x, has a house; which house? The one that belongs to him, I.e. let’s name it: houseof(x). Now, 3 can be rewritten as x rich(x) house(x, houseof(x))

• This is called skolemization.

Page 6: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Universal quantifiers• Since universal quantifiers appear so often, it is common

simply to omit them, using the convention that any variable not associated with a quantifier is implicitly universally quantified.

• So, the premises become:

1. lawyer(john)

2. lawyer(x) rich(x)

3. rich(x) house(x, houseof(x))

4. rich(x) house(x,y) big(y)

5. house(x,y) big(y) work(y)

Page 7: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Clausal Form• A literal is either an atomic sentence or a negation of an atomic sentence.

• A clausal sentence is either a literal or a disjunction of literals.

• A clause is a set of literals.

{p(a)}

{p(a)}

{p(a), q(b)}

• The empty clause {} is unsatisfiable.

• Before applying resolution we want to convert the sentences into clausal form.

Page 8: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Inseado• Implications Out:

1 2 1 2

1 2 1 2

1 2 (1 2 ) (1 2 )

• Negations In:(1 2 ) 1 2

(1 2 ) 1 2

....

Page 9: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Inseado (continued)• Standardize variables (I.e. renaming)

x.p(x) x.q(x) x.p(x) y.q(y)

The scope of quantifiers determines the scope of variables. So, in order to avoid name conflicts we rename the variables.

• Existentials Outx.p(x) p(a)

xy.(p(x) z.q(x, y, z)) xy.(p(x) q(x, y, f (x, y)))

This is called skolemization. Recall example with lawyers.

When the existentially quantified variable is not in the scope of any universally quantified variable, we just replace it with an object constant (name doesn’t matter). See first case.

Page 10: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Inseado (concluded)• Alls Out

x.( p(x) q(x, y, f (x, y))) p(x) q(x, y, f (x, y))

• Distribution1 (2 3) (1 2) (1 3)

(1 2) 3 (1 3) (2 3)

• Operators out1 ... n 1

...

n

1 ... n {1,..., n}

Page 11: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Example1. {lawyer(john)}

2. x (lawyer(x) rich(x))

3. x (rich(x) y house(x,y))

4. x,y (rich(x) house(x,y) big(y))

5. x,y ( house(x,y) big(y) work(y) )

x (lawyer(x) rich(x))

I x (lawyer(x) rich(x))

N x (lawyer(x) rich(x))

S x (lawyer(x) rich(x))

E x (lawyer(x) rich(x))

A lawyer(x) rich(x)

D lawyer(x) rich(x)

O {lawyer(x), rich(x)}

x (rich(x) y house(x,y))

I x (rich(x) y house(x,y))

N x (rich(x) y house(x,y))

S x (rich(x) y house(x,y))

E x (rich(x) house(x,houseof(x))

A rich(x) house(x,houseof(x))

D rich(x) house(x,houseof(x))

O {rich(x), house(x,houseof(x))}

x,y (rich(x) house(x,y) big(y))

I x,y ((rich(x) house(x,y)) big(y))

N x,y (rich(x) house(x,y) big(y))

S x,y (rich(x) house(x,y) big(y))

E x,y (rich(x) house(x,y) big(y))

A rich(x) house(x,y) big(y)

D rich(x) house(x,y) big(y)

O {rich(x), house(x,y), big(y)}

Page 12: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Example (continued)x,y ( house(x,y) big(y) work(y) )

I x,y ((house(x,y) big(y)) work(y) )N x,y (house(x,y) big(y) work(y) )S x,y (house(x,y) big(y) work(y) )E x,y (house(x,y) big(y) work(y) )A house(x,y) big(y) work(y)D house(x,y) big(y) work(y)O {house(x,y), big(y), work(y)}

Negated conclusion:y (house(john,y) work(y))

I y (house(john,y) work(y))N y (house(john,y) work(y))S y (house(john,y) work(y))E y (house(john,y) work(y))A house(john,y) work(y)D house(john,y) work(y)O {house(john,y), work(y)}

Page 13: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Example (concluded)Here are all the clauses we got through INSEADO from the

premises and the negated conclusion.

• {lawyer(john)}

• {lawyer(x1), rich(x1)}

• {rich(x2), house(x2,houseof(x2))}

• {rich(x3), house(x3,y1), big(y1)}

• {house(x4,y2), big(y2), work(y2)}

• {house(john,y3), work(y3)}

Note: We rename the variables, in order to not have variable name clashes between clauses.

Page 14: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

ResolutionPropositional resolution was:

{1,..., ,..., m}

{1,..., ,...,n}

{1,..., m,1,..., n}

Similarly, relational resolution is:

{1,..., ,..., m}

{1,..., ,..., n}

{1,..., m,1,..., n}

where mgu(,)

mgu(,): Most General Unifier

Example.

{ p(a, y),r(y)}

{p(x,b)}

{r(y)} {xa, yb}

{r(b)}

We are unifying (or making the same) p(a, y) with p(x,b).

So, what we should do?

Make xa and yb.

The set {xa, yb}, which is a mapping from variables to constants is called a unifier.

Page 15: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Unification• Unification is the process of determining whether two expressions can be made

identical by the appropriate substitutions for their variables.

• A substitution is a finite mapping of variables to terms. We write substitutions as sets of replacement rules, e.g.:{xa,yf (b),z v}

• In each rule, the variable to which the arrow is pointing to is to be replaced by the term from which the arrow is pointing. • In this case, x is to be replaced by a, • y is to be replaced by f(b), and • z is to be replaced by v.

• The variables being replaced constitute the domain of the substitution, and the terms replacing them constitute the range. In the example above: • domain is {x, y, z}, and range is {a, b, v}.

• The variables in the domain are called bound. The terms in the range are called variable bindings.

Page 16: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

• A substitution is pure when all replacement terms in the range are free of the variables in the domain of the substitution.

• Otherwise, the substitution is impure. The substitution shown above is pure whereas the one shown below is impure.{xa,yf (b),z x}

• The result of applying a substitution to an expression is the expression obtained from the original expression by replacing every occurrence of every variable in the domain of the substitution by the term with which it is associated.

• Examples:

q(x, y) {xa, yf (b), zv} q(a, f (b))

q(x, x) {xa, yf (b), zv} q(a,a)

q(x,w) {xa, yf (b), zv} q(a,w)

q(z,v) {xa, yf (b), zv} q(v,v)

Page 17: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

• If no bound variable of a pure substitution occurs in another pure substitution , then we can compose with , obtaining so a new substitution which is also pure.

• We do the composition by applying at the bindings of , and then adding remaining bindings from .

• E.g. {wg(x,y)} {xa, yb, zc} = {wg(a,b), xa, yb, zc}

• A set of expressions {1, …, n} is unifiable if and only if there is a substitution that makes the expressions identical; I.e. 1 = …= n is said to be a unifer for the set.

• E.g. {xa, yb, zc} unifies the expressions p(a,y,z) and p(x,b,z):

• p(a,y,z) {xa, yb, zc} = p(a,b,c) = P(x,b,z) {xa, yb, zc}

• The above is not the only unifier.

• We can say for z, zw or zc. • Well, the zw is more “general” than zc,

because w is variable, which can bounded later to any other variable or constant, while c as constant can’t be bounded to anything at all.

Page 18: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

• Formally: We say that a substitution is more general than a unifier if there exists a substitution such that = .

• A most general unifier (mgu) has the property that any other unifier can be obtained from by some substitution: = .

• The mgu is unique up to variable renaming. • Example. p(x,y) and p(a,v) are unifiable because they have a unifier, e.g.

{xa,yb,vb}• The results of applying this substitution to the two expressions are:

p(x, y) {x a, yb,vb} p(a,b)p(a,v) {xa,y b,vb} p(a,b)

• We could have substituted c or d or f(c) or f(w) for y and v.

• In fact, we can unify the expressions without changing v at all by simply replacing y by v.

• So, the substitution {xa,yv} is more general than {xa,yf(c),vf(c)} since there is a substitution {vf(c)} that, when applied to the former, gives the latter:{xa,yv} {vf (c)}{x a, yf (c),vf (c)}

Page 19: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Mgu (x,y) {if (x==y) return {};if (Variable(x)) return MguVar(x,y);if (Variable(y)) return MguVar(y,x);if (Constant(x) || Constant(y))

exit(“Non unifiable”);if (Length(x) != Length(y))

exit(“Non unifiable”);;i = 0; g = {};while (TRUE) {

if (i==Length(x)) return g;s = Mgu (Part(x,i), Part(y,i));g = Compose(g,s);x = Substitute(x,g); y =

Substitute(y,g);i = i + 1;

}}MguVar (x,y) {

if (x occurs in y) exit(“Non unifiable”);return {xy};

}Well, this is for the computer…In doing examples by

hand, we can easily find the mgu by looking.

Variable(x) returns TRUE is x is variable.

Length(x) for x e.g. x=F(A,G(y)) returns the number of arguments, I.e. 2.

Part(i) returns the i-th part. E.g.

Part(F(A,G(y)), 0) = F

Part(F(A,G(y)), 1) = A

Part(F(A,G(y)), 2) = G(y)

Compose(g,s) is self-explanatory.

Substitute(x,g) is self-explanatory.

Recursive procedure for the mgu of two expressions(starting with a relation or function)

Page 20: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Unification exampleE1: p(x, g(y,y), x) with E2: p(g(a,z), v, v)

p==p -- part 0Now try to unify x with g(a,z) -- part 1xg(a,z) Now apply this substitution to both E1 and E2E1: p(g(a,z), g(y,y), g(a,z)) E2: p(g(a,z), v, v)Now try to unify g(y,y) with v -- part 2vg(y,y)Now apply this substitution to both E1 and E2E1: p(g(a,z), g(y,y), g(a,z)) E2: p(g(a,z), g(y,y), g(y,y))Now try to unify g(a,z) with g(y,y) -- part 3Recursively, we find ya and za.Finally, {xg(a,a), ya, za, vg(a,a)}E1: p(g(a,a), g(a,a), g(a,a)) E2: p(g(a,a), g(a,a), g(a,a))

Page 21: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Example. 1. {p(a,b)}

2. {p(x,y), q(x,y)}

3. {q(z,w), r(z)} 4. {r(v)} 5. {q(a,b)}

1,26. {q(v,w)}

3,47. {}

5,6

• When the {} conclusion is derived we have a contradiction. It is useful in proving things by refutation, I.e. assuming that what we want to prove is not true…

• There are other possible conclusions that can be derived from the same premises. In the following graph there are the possible conclusions.

{p(a,b)} {p(x,y), q(x,y)} {q(z,w), r(z)} {r(v)}

{q(a,b)}

{p(z,w), r(z)}

{q(v,w)}

{r(a)} {r(a)} {} {p(v,w)} {p(v,w)}

Page 22: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

1. {p(a,b)}

2. {p(x,y), q(x,y)}

3. {q(z,w), r(z)} 4. {r(v)}

5. {q(a,b)}1,2

6. {p(z,w), r(z)} 2,37. {q(v,w)}

3,4

8. {r(a)} 3,59. {r(a)} 1,610. {p(v,w)}

4,611. {p(v,w)}

2,712. {}

1,10

• We keep two pointers (the slow and the fast);

• On each step we compare the sentences under the pointers. If we can resolve, we add the new derived sentence at the end of the list.

• At the start of the inference we initialize slow and fast at the top of the list.

• As long as the two pointers point to different positions, we leave the slow where it is and advance the fast.

• When they meet, we move the fast at the top of the list and we move the slow one position down the list.

Page 23: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Lawyer’s example1. {lawyer(john)}

2. {lawyer(x1), rich(x1)}

3. {rich(x2), house(x2,houseof(x2))}

4. {rich(x3), house(x3,y1), big(y1)}

5. {house(x4,y2), big(y2), work(y2)}

6. {house(john,y3), work(y3)}7. {rich(john)} 1,2 mgu = {x1john}

8. {lawyer(x2), house(x2,houseof(x2))} 2,3 mgu = {x1x2}

9. {lawyer(x2), house(x3,y1), big(y1)} 2,4

10. {rich(x3), big(houseof(x3))} 3,4

11. {rich(x2), big(houseof(x2)), work(houseof(x2))} 3,512. {…} 4,513. {…} 3,614. {…} 5,6… you can continue with the two finger method…but it’s too long.

Page 24: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Lawyer’s example in short…1. {lawyer(john)}

2. {lawyer(x1), rich(x1)}

3. {rich(x2), house(x2,houseof(x2))}

4. {rich(x3), house(x3,y1), big(y1)}

5. {house(x4,y2), big(y2), work(y2)}

6. {house(john,y3), work(y3)}

7. {rich(john)} 1,2

8. {rich(john), work(houseof(john))} 3,6

9. {work(houseof(john))} 7,8

10. {house(john,houseof(john))} 3,7

11. {house(john,y1), big(y1)} 4,7

12. {big(houseof(john))} 10,11

13. {house(x4, houseof(john)), work(houseof(john))} 5,12

14. {work(houseof(john))} 10,13

15. {} 9,14

Page 25: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Curiosity and the cat• Everyone who loves all animals is loved by someone.

• Anyone who kills an animal is loved by no one.

• Jack loves all animals.

• Either Jack or Curiosity killed the cat, who is named Tuna.

• Did Curiosity kill the cat?

1. x [y animal(y) loves(x,y)] [y loves(y,x)]

2. x [y animal(y) kills(x,y)] [z loves(z,x)]

3. y animal(y) loves(jack,y)

4. kills(jack,tuna) kills(curiosity,tuna)

5. x cat(x) animal(x)

6. kills(curiosity,tuna) negated goal

Page 26: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Curiosity – Inseado (1)x [y (animal(y) loves(x,y))] [y loves(y,x)]

I x [y (animal(y) loves(x,y))] [y loves(y,x)]

N x [y (animal(y) loves(x,y))] [y loves(y,x)]

x [y (animal(y) loves(x,y))] [y loves(y,x)]

S x [y (animal(y) loves(x,y))] [z loves(z,x)]

E x [animal(f(x)) loves(x,f(x))] [loves(g(x),x)]

A [animal(f(x)) loves(x,f(x))] [loves(g(x),x)]

D [animal(f(x)) loves(g(x),x) ] [loves(x,f(x)) loves(g(x),x)]

O {animal(f(x)), loves(g(x),x)}

{loves(x,f(x)), loves(g(x),x)}

Page 27: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Curiosity – Inseado (2)x [y animal(y) kills(x,y)] [z loves(z,x)]

I x [y animal(y) kills(x,y)] [z loves(z,x)]

N x [y animal(y) kills(x,y)] [z loves(z,x)]

S x [y animal(y) kills(x,y)] [z loves(z,x)]

E x [y animal(y) kills(x,y)] [z loves(z,x)]

A animal(y) kills(x,y) loves(z,x)

D animal(y) kills(x,y) loves(z,x)

O {animal(y), kills(x,y), loves(z,x)}

Page 28: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Curiosity – Inseado (3-5)y animal(y) loves(jack,y)

INSE y animal(y) loves(jack,y)

AD animal(y) loves(jack,y)

O {animal(y), loves(jack,y)}

kills(jack,tuna) kills(curiosity,tuna)

INSEADO {kills(jack,tuna), kills(curiosity,tuna)}

x cat(x) animal(x)

INSE x cat(x) animal(x)

AD cat(x) animal(x)

O {cat(x), animal(x)}

Page 29: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.

Clausal Curiosity1. {animal(f(x1)), loves(g(x1),x1)}

2. {loves(x2,f(x2)), loves(g(x2),x2)}

3. {animal(y1), kills(x3,y1), loves(z,x3)}

4. {animal(y2), loves(jack,y2)}

5. {kills(jack,tuna), kills(curiosity,tuna)}

6. {cat(x4), animal(x4)}

7. kills(curiosity,tuna)

Note: We rename the variables, in order to not have variable name clashes between clauses.

Page 30: Resolution. An example 1.John is a lawyer. 2.Lawyers are rich. 3.Rich people have big houses. 4.Big houses are a lot of work. We would like to conclude.