Anda di halaman 1dari 34

Substitution

and
Unication

Substitution and Unication


Summary

Substitution
and
Unication

Substitution and Unication [Chang-Lee Ch. 5.3]


Unication Algorithm [Chang-Lee Ch. 5.4]
Finding complementary literals

Substitution
and
Unication

need of unication
To apply resolution we need to nd complementary literals:
L1 = P , L2 = P
This is not a problem for ground or propositional clauses
When variables are involved things get more complicated
It is not obvious to decide whether two literals are
complementary
Example

Substitution
and
Unication

Example (complementary literals with variables)

C1 = P (x ) Q (x ), C2 = P (f (y )) R (y )
There is no complementary literal, but:

C10 = P (x = f (a))Q (x = f (a)), C20 = P (f (y = a))R (y = a)

Then C10 and C20 are ground instances of C1 and C2 , and


P (f (a)) and P (f (a)) are complementary.
Example, contd.

Substitution
and
Unication

Example (complementary literals with variables)


Then we can apply resolution and obtain:
P (f (a)) Q (f (a)) P (f (a)) R (a)
Q (f (a)) R (a)
Where C30 = Q (f (a)) R (a) is a resolvent for C10 and C20
Example, contd.

Substitution
and Example (complementary literals with variables)
Unication
More in general, we can substitute x = f (y ) in C1 and obtain
C1 = P (f (y )) Q (f (y ))
P (f (y )) Q (f (y )) P (f (y )) R (y )
Q (f (y )) R (y )
C1 is an instance of C1 and C30 is a (ground) instance of
C3 = Q (f (y )) R (y )
By substituting appropiate terms we can generate new
clauses for C1 and C2
By applying resolution to such clauses we obtain other
clauses which will all be instance of C3 .
C3 is the most general clause and is called a resolvent of
C1 and C2 .
Substitutions

Substitution
and
Unication

Substitutions
To obtain a resolvent from clauses containing variables we need
to substitute variables with terms, and apply resolution.
Denition (Substitution)
A substitution is a nite set {t1 /v1 , , t /v } where every v
n n i

is a variable and every t is a term, dierent from v , and no two


i i

elements in the set have the same variable after the / symbol.
Example, contd.

Substitution
and
Unication

Example (Substitution)

{f (z )/x , y /z } is a substitution
{a/x , g (y )/y , f (g (b))/z } is a substitution
{y /x , g (b)/y } is a substitution
{a/x , g (y )/x , f (g (b))/z } is not a substitution
{g (y )/x , z /f (g (b))} is not a substitution
Ground and Empty substitutions

Substitution
and
Unication Denition (Ground substitution)
A substitution {t1 /v1 , , t /v } is ground when {t1 , , t }
n n n

are all ground terms.

Example (Ground Substitution)

{f (a)/x , b/z } is a ground substitution


{a/x , g (b)/y , f (g (b))/z } is a ground substitution

Denition (Empty substitution)


A substitution that contains no element {} is the empty
substitution, we denote the empty substitution with .
Instances of clauses

Substitution
and
Unication

Denition (Instance)
Let = {t1 /v1 , , t /v } be a substitution and let E be an
n n

expression. Then E is an expression obtained by replacing


simultaneously all occurrences of every v , 1 i n, in E with
i

the corresponding term t . E is an instance of E .


i
Example

Substitution
and Example (Instances)
Unication

Let = {a/x , f (b)/y , c /z } and E = P (x , y , z ) then


E = P (a, f (b), c ) is an instance of E
Let = {f (f (a))/x } and C = P (x ) Q (g (x )) then
G = P (f (f (a)) Q (g (f (f (a)))) is an instance of C
Let = {y /x , f (b)/y } and R = P (x ) Q (y ) then
R = P (y ) Q (f (b)) is an instance of R

Notes
Denition of ground instance of a clause is compatible with
denition of instance given here.
substitution is simultaneous. If not simultaneous we could
have dierent outcomes
R = P (x y f (b)) Q (y f (b))
Composition

Substitution
and
Unication

Composition
Let = {t1 /x1 , , t /x } and = {u1 /y1 , , u /y }
n n m m

be two substitutions. Then the composition of and


is denoted by , and is obtained by building the set
{t1 /x1 , , t /x , u /y1 , , u /y } and deleting the fol-
n n n m m

lowing elements:
any element t /x such that t = x
j j j j

any element u /y such that y is in {x1 , , x }


i i i n
Example

Substitution
and Example (composition)
Unication
Given:
= {t1 /x1 , t2 /x2 } = {f (y )/x , z /y }
= {u1 /y1 , u2 /y2 , u3 /y3 } = {a/x , b/y , y /z }
We build the following set:
{t1 /x1 , t2 /x2 , u1 /y1 , u2 /y2 , u3 /y3 } = {f (b )/x , y /y , a/x , b /y , y /z }

We remove the proper elements:


t /x such that t = x therefore we remove y /y
j j j j

u /y such that y is in {x1 , , x } therefore we remove


i i i n

a/x and b/y


Finally,
= {f (b)/x , y /z }
Properties of composition

Substitution
and
Unication
associativeness
Let , and be substitutions we have that () = ()
Example
Let = {f (y )/x }, = {z /y } and = {a/z }. We have
= = {f (y )/x , z /y } = {f (z )/x , z /y } and
= {f (z )/x , z /y , a/z } = {f (a)/x , a/y , a/z }
0 = = {z /y , a/z } = {a/y , a/z } and
0 = {f (y )0 /x , a/y , a/z } = {f (a)/x , a/y , a/z }

Identity of empty substitution


Let be a substitution then  =  =
Unication and substitutions

Substitution
and
Unication
Unifying expressions using substitutions
When using resolution we need to match or unify
expressions to nd complementary pairs of literals.
This can be done by applying proper substitutions to
relevant expression to make them identical
Example
Let C1 = P (x ) Q (x ) and C2 = P (f (y )) Q (y )), and let
L1 = P (x ), L2 = P (f (y ))
By applying = {f (y )/x }.
We have that L1 = L2 = P (f (y )).
Unier

Substitution
and
Unication

Denition (Unier)
A substitution is called a unier for a set {E1 , , E } i
k

E1 = E2 = = E . The set {E1 , , E } is uniable i


k k

there exists a unier for it.


Example
The set {P (x ), P (f (y ))} is uniable and = {f (y )/x } is a
unier for it, because P (x ) = P (f (y )) = P (f (y ))
Most General Unier

Substitution
and
Unication
Denition (MGF)
A unier is a most general unier for a set {E1 , , E } i for
k

each unier there exists a substitution such that = .

Example
Consider the set {P (x ), P (f (y ))} and
= {f (f (z ))/x , f (z )/y }.
is a unier because P (x ) = P (f (y )) = P (f (f (z )))
= {f (y )/x } is a unier and is a most general unier
for example, we can nd = {f (z )/y } such that
= {f (y )/x , f (z )/y } = {f (f (z ))/x , f (z )/y } =
Example: Most General Unier

Substitution
and
Unication

Example
Consider the set {P (a, y ), P (x , f (b))}
The set is uniable
= {a/x , f (b)/y } is a (most general) unier for the set.
An algorithm for Unication

Substitution
and
Unication

Unication Algorithm
Need a procedure to nd a MGU given a set of expressions
Requirements:
stop after a nite number of steps
return an MGU if the set is uniable
state that the set is not uniable otherwise
There are many possibilities
We go for a recursive procedure.
Basic ideas

Substitution
and
Unication

Basic ideas
Given a set of expressions {E1 , , E }
k

Find a disagreement set


Build a substitution that can eliminate the disagreement
Disagreement elimination: Example

Substitution
and
Unication

Example (Disagreement elimination)


Consider the set {P (a), P (x )}. This expressions are not
identical.
They disagree because of the arguments a and x
The disagreement set here is {a, x }
Since x is a variable, we can eliminate this disagreement by
using the substitution = {a/x }
P (a) = P (x ) = P (a)
Disagreement set

Substitution
and
Unication Denition (Disagreement Set)
The disagreement set of a nonempty set of expressions W is
obtained by nding the rst position (starting from the left) at
which not all the expressions in the W have the same symbol.
We then extract, from each expression, the sub-expression that
begins with the symbol occupying that position. The set of
these sub-expressions is the Disagreement Set.

Example (Disagreement Set)


Consider the set {P (a), P (x )}, the Disagreement Set is
{a, x }.because the rst position at which the string of symbols
P (a) and P (x ) dier is the position number 3. The sub
expression starting from position 3 is a and x respectively.
Example

Substitution
and
Unication

Example (Disagreement Set)


Find the Disagreement Set for
W = {P (x , f (y , z )), P (x , a), P (x , g (h(k (x ))))}
Example

Substitution
and
Unication

Example (Disagreement Set)


Find the Disagreement Set for
W = {P (x , f (y , z )), P (x , a), P (x , g (h(k (x ))))}
Sol.
D = {f (y , z ), a, g (h(k (x )))}
Unication Algorithm: Basic Steps

Substitution
and
Unication
Basic Steps
1 Set k = 0, W0 = W and 0 = 
2 If W is a singleton, STOP, is a MGU. Otherwise, nd
k k

the disagreement set D for W . k k

3 If there is a pair hv , t i such that v , t D , v is a


k k k k k k

variable that does not occur in t go to step 4, otherwise


k

STOP, W is not uniable.


4 Let +1 = {t /v } and W +1 = W {t /v }.
k k k k k k k k

5 Set k = k + 1 go to step 2.

Note
In step 4 W +1 = W {t /v } = W
k k k k k +1 because composition
of substitutions is associative.
Example

Substitution
and
Unication

Example (Unication Algorithm)


Find a most general unier for the set
W = {P (a, y ), P (x , f (b))}
Example

Substitution
and
Unication

Example (Unication Algorithm)


Find a most general unier for the set
W = {P (a, y ), P (x , f (b))}
Sol.
= {a/x , f (b)/y }
Example II

Substitution
and
Unication

Example (Unication Algorithm)


Find a most general unier for the set
W = {P (a, x , f (g (y ))), P (z , f (z ), f (u ))}
Example II

Substitution
and
Unication

Example (Unication Algorithm)


Find a most general unier for the set
W = {P (a, x , f (g (y ))), P (z , f (z ), f (u ))}
Sol.
= {a/z , f (a)/x , g (y )/u }
Example III

Substitution
and
Unication

Example (Unication Algorithm)


Determine whether or not the set
W = {Q (f (a), g (x )), Q (y , y )} is uniable.
Example III

Substitution
and
Unication

Example (Unication Algorithm)


Determine whether or not the set
W = {Q (f (a), g (x )), Q (y , y )} is uniable.
Sol.
W is not uniable
Unication Algorithm: Termination

Substitution
and
Unication
Termination
The unication algorithm will always terminate after a nite num-
ber of steps.
Otherwise we will have an innite sequence
W 0 , W 1 , W 2 ,
Each step eliminates one variable from W (specically
W contains v but W +1 does not)
k k k

And W has a nite number of variable


Thus the algorithm will always terminate: returning a
MGU or stating W is not uniable
Unication Algorithm: Correctness

Substitution
and
Unication

Theorem (Correctness of Unication Algorithm)


If W is a nite, non empty, uniable set of expressions, the
unication algorithm will always terminate with a MGU for
k

W.

basic idea.
We can prove by induction on k that for any which is a unier
we have =
k k
Exercises Unication algorithm

Substitution
and
Unication

Exercise
Determine whether each of the following set of expressions is
uniable. If yes give a MGU
1 W = {Q (a, x , f (x )), Q (a, y , y )}
2 W = {Q (x , y , z ), Q (u , h(v , v ), u )}

Anda mungkin juga menyukai