5
Unification We can represent any substitution by a set of ordered pairs: s = { t 1 /v 1 , t 2 /v 2 , …, t n /v n } where: t i /v i means that the term i substitutes variable i throughout the expression. e.g. s1 = {b/x, a/y, a/z} Note: - every occurrence of a variable should be substituted by the same term. - no variable can be replaced by a term that contains the same variable. Def . To denote a substitution instance of an expression E, using a substitution s, we write: Es.

Unification We can represent any substitution by a set of ordered pairs: s = { t 1 /v 1, t 2 /v 2, …, t n /v n } where: t i /v i means that the term i

Embed Size (px)

Citation preview

Unification

We can represent any substitution by a set of ordered pairs:

s = { t1/v1, t2/v2, …, tn/vn}

where: ti/vi means that the term i substitutes variable i throughout the expression.

e.g. s1 = {b/x, a/y, a/z}Note:

- every occurrence of a variable should be substituted by the same term.- no variable can be replaced by a term that contains the same variable.

Def. To denote a substitution instance of an expression E, using a substitution s, we write: Es.

Def. Finding substitutions of terms for variables to make two or more expressions identical is called unification.

e.g. {p(g(x,f(y)),a), p(g(b,f(z)),y)} ==> p(g(b,f(a)),a)

Def. A substitution instance of an expression is obtained by substituting terms for variables in that expression.

Def. A ground instance of an expression is one in which there are no variables (and consequently, no quantifiers).

Def. An instance of an expression which results from changing just the names of the variables in it, is called an alphabetic variant of the original.

e.g. x.p(x,f(x,b)) ==> z.p(z,f(z,b))

Unification

Def. A composition of two substitutions s1 and s2 is written s1s2, and it is accomplished following the steps:- apply s2 to the elements of s1.- add any pairs of s2 having variables not occurring in s1.

e.g. s1={g(x,y)/z}, s2={a/x, b/y, c/w, d/z} s1s2 ==> {g(a,b)/z, a/x, b/y, c/w}

s2s1 ==> {a/x, b/y, c/w, d/z} = s2Some properties of composition are:

1. (Es1)s2=E(s1s2)2. s1(s2s3)=(s1s2)s3

Unification

Def. We say that a set {Ei} of expressions is unifiable if there exists a substitution s that makes: E1s=E2s=…=Ens.

Def. If a substitution g has the property that if s is a unifier of {Ei} yielding {Ei} s, then there exists a substitution s’ such that

{Ei} s={Ei} gs’, then g is called the most general unifier mgu.

For the unify procedure presented next, it is assumed that its arguments are two lists of expressions. e.g.

g(r(x,f(z)),y) ==> [g, [r, x, [f, z ]], y] g(r(a, y), u) ==> [g, [r, a, y], u]

Unification

Procedure UNIFIY (E1, E2)If either E1 or E2 is an atom { if E1 and E2 are identical, return

NIL if E1 is a variable, do:

{ if E1 occurs in E2, return FAIL

return {E2/E1} } if E2 is a variable, return {E1/E2} return FAIL }F1 the first element of E1T1 the rest of E1F2 the first element of E2 T2 the rest of E2Z1 UNIFY(F1, F2)

If Z1 = FAIL, return FAILG1 result of applying Z1 to T1G2 result of applying Z1 to T2Z2 UNIFY(G1, G2)If Z2 = FAIL, return FAILReturn the composition of Z1 and Z2

________________________

Procedure taken from Nilsson N.J. “Principles of Artificial Intelligence”, Tioga Publishing, California 1980.

Unification Algorithm