Top Banner
AR for Horn clause logic AR for Horn clause logic Introducing: Introducing: Unification Unification
27

AR for Horn clause logic

Mar 19, 2016

Download

Documents

gasha

AR for Horn clause logic. Introducing: Unification. Example:.  p lot_maint(house(p))  big(house(p)) false  lot_maint(house(Bos)). We would like to conclude: by means of generalized modus ponens. false  big(house(Bos)). How to deal with variables?. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AR for Horn clause logic

AR for Horn clause logicAR for Horn clause logic

Introducing: Introducing: UnificationUnification

Page 2: AR for Horn clause logic

2

How to deal with variables? How to deal with variables? Example:Example:

p p lot_maint(house(p))lot_maint(house(p)) big(house(p)) big(house(p))false false lot_maint(house(Bos))lot_maint(house(Bos))

We would like to conclude:We would like to conclude:

by means of generalized modus ponens.by means of generalized modus ponens.false false big(house(Bos)) big(house(Bos))

Principle:Principle: use instantiations of the 2 Horn use instantiations of the 2 Horn clauses, such that these DO ‘match’.clauses, such that these DO ‘match’.

Page 3: AR for Horn clause logic

3

More examples:More examples: We drop the universal quantification, since all We drop the universal quantification, since all

variables are universally quantified anyway. variables are universally quantified anyway.

Some examples using standard modus ponens:Some examples using standard modus ponens:

related(related(xx,,yy) ) parent( parent(xx,,yy)) parent(John,Mary)parent(John,Mary)related(related(JohnJohn,,MaryMary))

loves(John,loves(John,xx) ) related(John, related(John,xx)) related(related(yy,father(,father(yy))))loves(John,loves(John,father(John)father(John)))

Unification !!Unification !!

Page 4: AR for Horn clause logic

4

Substitutions:Substitutions: Examples:Examples:

={={ x x // h(g(A))h(g(A)) , , y y // g(A)g(A) ,, z z // ww}} = {= { x x // g(z)g(z) ,, y y // BB}}

A A substitutionsubstitution is a is a finite set of pairsfinite set of pairs of the form of the form variable variable // termterm, such that all , such that all variablesvariables at the at the left-hand sides of the pairs are distinct. left-hand sides of the pairs are distinct.

In our substitutions we will NOT allow that some In our substitutions we will NOT allow that some variablevariable that occurs left also occurs in some that occurs left also occurs in some termterm at the right.at the right.

Page 5: AR for Horn clause logic

5

Applying substitutions:Applying substitutions:

Substitutions can be Substitutions can be appliedapplied to to simple simple expressionsexpressions (atoms or terms), by replacing all (atoms or terms), by replacing all occurrences of the left-side occurrences of the left-side variablesvariables in the in the expression by the corresponding expression by the corresponding termsterms..

= {= { x x // g(z)g(z) ,, y y // BB}}

p(p(xx , f(, f(yy, z)), z)) = p(= p(g(z)g(z) , f(, f(BB, , z))z))

={={ x x // h(g(A))h(g(A)) , , y y // g(A)g(A) ,, z z // ww}}p(p(xx, f(, f(yy, , zz)) )) == p(p(h(g(A))h(g(A)) , f(, f(g(A)g(A) ,, ww))))

Examples:Examples:

Page 6: AR for Horn clause logic

6

Remember the motivation:Remember the motivation:

We want substitutions that make atoms equal. We want substitutions that make atoms equal.

lot_maint(house(lot_maint(house(pp)))) big(house(p)) big(house(p))false false lot_maint(house(lot_maint(house(BosBos))))

The two atoms in the clauses:The two atoms in the clauses:

must be made must be made equalequal..

Page 7: AR for Horn clause logic

7

““Unifiers”Unifiers” Example:Example:S = {related(John,S = {related(John,xx), related(), related(yy,, father( father(yy))}))}

= {= {y y // JohnJohn,, x x // father(John)father(John)}} is a unifier foris a unifier for SS

SS = = {related({related(JohnJohn,,father(John)father(John))})}

Given a Given a setset of simple expressions of simple expressions SS, we call a , we call a substitution substitution a a unifierunifier for for SS if: if:

S S is a singleton is a singleton

Page 8: AR for Horn clause logic

8

One more refinement:One more refinement: For deduction step:For deduction step: related(related(xx,,yy) ) parent( parent(xx,,yy))

parent(John,z)parent(John,z)

we have:we have: S = {parent(S = {parent(xx,,yy), parent(John,z)}), parent(John,z)} and there are several unifiers:and there are several unifiers:

= {= {x x // JohnJohn, , y y // zz}} = {= {x x // JohnJohn, , y y // MaryMary, z / , z / MaryMary}}etcetc..

Only the most general one, Only the most general one, ,, allows to derive the allows to derive the strongest conclusion:strongest conclusion:

related(related(JohnJohn,,zz))

Page 9: AR for Horn clause logic

9

Relation between these?Relation between these? Example:Example: S = {parent(S = {parent(xx,,yy), parent(John,z)}), parent(John,z)}

= {= {x x // JohnJohn, , y y // zz}} S S = {parent(= {parent(JohnJohn,,zz)})} = {= {x x // JohnJohn, , y y // MaryMary, z / , z / MaryMary}}

S S = {parent(= {parent(JohnJohn,,MaryMary)})}

There exists a There exists a third third substitution:substitution: = {z /= {z / MaryMary}} withwith S S = ( = (S S ) )

Page 10: AR for Horn clause logic

10

Most general unifier:Most general unifier:

Given a set of simple expressions Given a set of simple expressions SS, a , a most most general unifiergeneral unifier for for SS is a unifier for is a unifier for SS, such , such that for all other unifiers that for all other unifiers for for SS, there exists a , there exists a third substitution third substitution such that: such that:

SS = (S= (S ))

Key-idea: create minimal instantiation changes!Key-idea: create minimal instantiation changes! Notation: Notation: = = mgumgu((SS) , or ) , or = = mgumgu((AA, , BB) for S = {A,B} ) for S = {A,B}

Page 11: AR for Horn clause logic

11

Generalized modus ponens for Generalized modus ponens for Horn clausesHorn clauses

A B1 B2 … Bi … BnBi’ C1 C2 … Cm(A B1 B2 … C1 C2 … Cm … Bn)

Generalized modus ponens must be further Generalized modus ponens must be further extended as:extended as:

where where = = mgu(mgu( BiBi,, Bi’Bi’)) NoteNote: : BiBi and and Bi’Bi’ must have the same predicate. must have the same predicate. CorrectnessCorrectness: due to correctness for all ground instances of this derivation. : due to correctness for all ground instances of this derivation.

Page 12: AR for Horn clause logic

12

Example: a few stepsExample: a few steps

ObserveObserve: we will always provide the variables : we will always provide the variables with with new namesnew names in order to avoid ‘accidental’ in order to avoid ‘accidental’ clashes of names. clashes of names.

false lot_maint(house(x)) lot_maint(house(y)) big(house(y)) false big(house(y))

false showm(z) belg(z) showm(Bos)false belg(Bos)

Another step, much later:Another step, much later:

Page 13: AR for Horn clause logic

13

Backward procedure Backward procedure for Horn clausesfor Horn clauses

Goal Goal := := false false B1 B1 B2 B2 … … Bn Bn ; ;RepeatRepeat

Select some Select some BiBi atom from the body of atom from the body of GoalGoal Select some clause Select some clause Bi’ Bi’ C1 C1 C2 C2 … … Cm Cm from from TT such that such that = mgu( = mgu(BiBi,, Bi’Bi’)) exists exists

GoalGoal := := false false (B1 (B1 … … Bi-1 Bi-1 C1 C1 C2 C2 … … Cm Cm Bi+1 Bi+1 … … Bn) Bn) UntilUntil GoalGoal = = false false or no more Selections possible or no more Selections possible

AgainAgain: concrete versions of this generic scheme : concrete versions of this generic scheme should allow for should allow for backtrackingbacktracking over previous selections, over previous selections,

or they should treat the problem as a or they should treat the problem as a general search general search problemproblem through the space of derivable goals. through the space of derivable goals.

Page 14: AR for Horn clause logic

14

The example again:The example again:

false lot_maint(house(x))

european(x) belg(x)rich(x) showm(x) european(x)big(house(x)) rich(x)lot_maint(house(x)) big(house(x))false lot_maint(house(x))

showm(Bos)belg(Bos)

lot_maint(house(x1)) big(house(x1)) = { x1 / x}= { x1 / x}

false big(house(x)) = { x2 / x}= { x2 / x}big(house(x2)) rich(x2)

false rich(x) = { x3 / x }= { x3 / x }rich(x3) showm(x3) european(x3)

false showm(x) european(x)false showm(x) belg(x)

european(x4) belg(x4) = { x4 / x }= { x4 / x }

belg(Bos) = { x / Bos }= { x / Bos }

false showm(Bos) showm(Bos) = { }= { }

false

Page 15: AR for Horn clause logic

15

Why rename variables?Why rename variables?

false p(x) p(y) q(z,y) false q(z,y) = {= {xx//yy } }

false p(x) p(y) q(x,y) false q(y,y) = {= {xx//yy }}

Consider the derivation step:Consider the derivation step:

Problem: Problem: p(y) p(y) q( q(xx,y),y) is equivalent with is equivalent with p(y) p(y) q( q(zz,y),y) so that alternatively we could perform the step:so that alternatively we could perform the step:

Which gives us a strictly stronger conclusion !Which gives us a strictly stronger conclusion !

Always first rename variables apart !!Always first rename variables apart !!

Page 16: AR for Horn clause logic

16

Another example:Another example:anc(x,y) parent(x,y) (1)anc(x,y) parent(x,z) anc(z,y) (2)parent(A,B) (3) parent(B,C) (4)false anc(u,v)

false anc(u,v)

false parent(x1,z1) anc(z1,y1) (2) {u/x1,v/y1}

false anc(B,y1)(3) {x1/A,z1/B}

false parent(B,y1)(1) {x2/B,y2/y1}

false (4) {y1/C}

false parent(x1,y1)(1) {u/x1,v/y1}

false (3) {x1/A,y1/B}

false (4) {x1/B,y1/C}

Several different proofs are possible !Several different proofs are possible !

Page 17: AR for Horn clause logic

17

Completeness:Completeness: Backward generalized modus ponens, Backward generalized modus ponens, using a using a

complete search method complete search method to search the space of to search the space of derived goals and derived goals and with renaming with renaming of variables of variables is is completecomplete..

Remark that it can Remark that it can only be semi-decidingonly be semi-deciding, because , because the search space of goals may be infinitely large. the search space of goals may be infinitely large.

thus, in general, this cannot help us to decide thus, in general, this cannot help us to decide whether whether false false is derivable. is derivable.

Page 18: AR for Horn clause logic

18

An infinite derivation:An infinite derivation: ExampleExample:: nat(s(x)) nat(x)

false nat(u)

false nat(u)

false nat(x1){{uu//s(x1)s(x1)}}

false nat(x2)

{{x1x1//s(x2)s(x2)}}

...

Page 19: AR for Horn clause logic

19

Using a complete searchUsing a complete searchwe do get an answer for:we do get an answer for:

ExampleExample:: nat(0)nat(s(x)) nat(x)false nat(u)

false nat(u)

false nat(x1){{uu//s(x1)s(x1)}}

false nat(x2)

{{x1x1//s(x2)s(x2)}}

...

false {{uu//00}}

false {{x1x1//00}}

Page 20: AR for Horn clause logic

UnificationUnification

A basic algorithm in Automated ReasoningA basic algorithm in Automated Reasoning

Page 21: AR for Horn clause logic

21

A unification algorithmA unification algorithmmgu:=:= { { ss = = t t };};

StopStop:= false;:= false;

Case:Case: t t is a variable,is a variable, ss isis not a variable:not a variable: replacereplace s s = = tt by by t t = = ss in in mgumgu;;

Case:Case: ss is a variable,is a variable, t t is the SAME variable:is the SAME variable: deletedelete s s = = tt from from mgumgu;;

Case:Case: ss is a variable,is a variable, t t is not a variable and is not a variable and contains contains s s : : StopStop:= true; := true;

......

WhileWhile not(not(StopStop) and ) and mgumgu still contains still contains ss = = tt ofof

Page 22: AR for Horn clause logic

22

Unification algorithm (2)Unification algorithm (2)

If If StopStop = false : Report = false : Report mgumgu ! !

Case:Case: ss is a variable,is a variable, t t is not identical to nor is not identical to nor contains contains ss and and s s occurs elsewhere in occurs elsewhere in mgumgu: : replace all other occurrences of replace all other occurrences of ss in in mgumgu by by tt ; ;

......

Case:Case: ss is of the form is of the form f(s1,…,sn)f(s1,…,sn) , , t t ofof g(t1,…,tm): g(t1,…,tm): ifif ff gg or or nn mm : : StopStop := true; := true;

elseelse replace replace ss = = tt in in mgumgu by by s1s1 = = t1t1 , , s2s2 = = t2 t2 , …, , …, snsn = = tn tn ;;End_whileEnd_while

Page 23: AR for Horn clause logic

23

Example 1:Example 1: Unify:Unify: p(B,y)p(B,y) andand p(x,f(x))p(x,f(x)) : :

InitInit:: mgumgu:= { := { p(B,y)p(B,y) == p(x,f(x))p(x,f(x))}} Case 5Case 5: : mgumgu:= {:= {BB = = xx, , yy = = f(x)f(x) } } Case 1Case 1: : mgumgu:= {:= {xx = = BB, , yy = = f(x)f(x) } } Case 4Case 4: : mgumgu:= {:= {xx = = BB, , yy = = f(B)f(B) } }

No more cases applicable !No more cases applicable ! p(B,y)p(B,y) and and p(x,f(x))p(x,f(x)) are unifiable are unifiable mgumgu = { = { xx//BB, , yy//f(B)f(B) } } result: p(B, f(B))result: p(B, f(B))

Page 24: AR for Horn clause logic

24

Example 2 & 3:Example 2 & 3: Unify:Unify: p(A)p(A) andand p(f(x))p(f(x)) : :

InitInit:: mgumgu:= { := { p(A)p(A) == p(f(x))p(f(x))}} Case 5Case 5: : mgumgu:= {:= {AA = = f(x)f(x) } } Case 5Case 5: : StopStop:= true:= true NOT unifiable!NOT unifiable!

Unify:Unify: xx andand f(x)f(x) : :

InitInit:: mgumgu:= { := { xx == f(x)f(x)}} Case 3Case 3: : StopStop:= true:= true NOT unifiable!NOT unifiable!

Page 25: AR for Horn clause logic

25

Termination of the algorithm:Termination of the algorithm: Stop Stop = true= true

no unifierno unifier expressions are not unifiableexpressions are not unifiable

No more cases applicable:No more cases applicable: mgumgu contains a set of equalities of the form: contains a set of equalities of the form:

{{x1x1 = = t1 t1, …, , …, xnxn = = tntn}} with with all all x1x1,,……,,xnxn mutually distinct variables ! mutually distinct variables !

The substitution The substitution {{x1x1//t1t1,…,,…,xnxn//tntn}} is a most general is a most general unifier for the initial unifier for the initial ss and and tt . .

Martelli-Montanari algorithm.Martelli-Montanari algorithm. Extendable for more than 2 expressions. Extendable for more than 2 expressions.

Page 26: AR for Horn clause logic

26

Deducing with unificationDeducing with unification Example:Example:

is impliedis implied: : mgumgu = {= {uu//point(1,z)point(1,z)}}

is impliedis implied: : mgumgu = {= {uu//yy,,vv//yy } }

vertical(segment(point(x,y),point(x,z)))vertical(segment(point(x,y),point(x,z)))horizontal(segment(point(x,y),point(z,yhorizontal(segment(point(x,y),point(z,y))))))

u vertical(segment(point(1,2),u))u vertical(segment(point(1,2),u))

u,v horizontal(segment(point(1,u),point(2,v)))u,v horizontal(segment(point(1,u),point(2,v)))

Page 27: AR for Horn clause logic

27

Representation-powerRepresentation-powerof Horn clausesof Horn clauses

Most predicate logic formulae can easily be rewritten Most predicate logic formulae can easily be rewritten in Horn clauses.in Horn clauses.

Examples:Examples:x cat(x) x cat(x) dog(x) dog(x) pet(x) pet(x)

x poodle(x) x poodle(x) dog(x) dog(x) small(x) small(x)

pet(x) cat(x)pet(x) dog(x)dog(x) poodle(x)small(x) poodle(x)

BUTBUT::x human(x) x human(x) male(x) male(x) female(x) female(x)

x dog(x) x dog(x) ~abnormal(x) ~abnormal(x) has_4_legs(x) has_4_legs(x)

????

????