Unification Algorithm Idea: eliminate disagreements Consider the set - - PowerPoint PPT Presentation
Unification Algorithm Idea: eliminate disagreements Consider the set - - PowerPoint PPT Presentation
Unification Algorithm Idea: eliminate disagreements Consider the set of expressions { P ( a ) , P ( x ) } The expressions disagree on a and x The disagreement set is { a, x } Since x is a variable, we can eliminate this
Idea: eliminate ‘disagreements’
Consider the set of expressions {P (a), P (x)} – The expressions ‘disagree’ on a and x – The disagreement set is {a, x} – Since x is a variable, we can eliminate this disagreement by using the substitution θ = {x/a} – Then P (a)θ = P (x)θ = P (a)
Unification algorithm 1
Idea: eliminate ‘disagreements’
Consider the set of expressions {P (a), P (x)} – The expressions ‘disagree’ on a and x – The disagreement set is {a, x} – Since x is a variable, we can eliminate this disagreement by using the substitution θ = {x/a} – Then P (a)θ = P (x)θ = P (a) Definition The disagreement set for a set W of expressions is obtained by find- ing the first position (starting from the left) at which not all expressions in W have the same symbol. We then extract from each expression in W the sub- expression that begins with the symbol occupying that position. The set of these sub-expressions is the disagreement set for W . Exercise Find the disagreement set for W = {P (x, f(y, z)), P (x, a), P (x, g(h(k(x))))}
Unification algorithm 1
Unification algorithm
Step 1 Set k = 0, W0 = W and σ0 = ε (empty substitution) Step 2 If Wk is a singleton, STOP: σk is an MGU for W . Otherwise, find the disagreement set Dk for Wk. Step 3 If there are xk, tk ∈ Dk such that xk is a variable that does not occur in tk, then go to step 4; otherwise STOP: the set W is not unifiable. Step 4 Set σk+1 = σk {xk/tk} and Wk+1 = Wk{xk/tk} (= W σk+1) Step 5 Set k = k + 1 and go to step 2
Unification algorithm 2
Unification algorithm
Step 1 Set k = 0, W0 = W and σ0 = ε (empty substitution) Step 2 If Wk is a singleton, STOP: σk is an MGU for W . Otherwise, find the disagreement set Dk for Wk. Step 3 If there are xk, tk ∈ Dk such that xk is a variable that does not occur in tk, then go to step 4; otherwise STOP: the set W is not unifiable. Step 4 Set σk+1 = σk {xk/tk} and Wk+1 = Wk{xk/tk} (= W σk+1) Step 5 Set k = k + 1 and go to step 2 Examples Find MGUs for the following sets: – W1 = {P (a, y), P (x, f(b))} – W2 = {P (a, x, f(g(y))), P (z, f(z), f(u))} – W3 = {Q(f(a), g(x)), Q(y, y)} – W4 = {Q(a, x, f(x)), Q(a, y, y)} – W5 = {Q(x, y, z), Q(u, h(v, v), u)}
Unification algorithm 2
Unification algorithm: termination
The unification algorithm always comes to a stop after finitely many steps – For otherwise there would be an infinite sequence W σ0, W σ1, W σ2, . . . – Each step eliminates one variable from W – Which is a contradiction since W contains finitely many variables
Unification algorithm 3
Unification algorithm: termination
The unification algorithm always comes to a stop after finitely many steps – For otherwise there would be an infinite sequence W σ0, W σ1, W σ2, . . . – Each step eliminates one variable from W – Which is a contradiction since W contains finitely many variables
Unification algorithm: correctness
Theorem If W is a finite unifiable set of expressions, then the unification algorithm always comes to a stop and returns an MGU for W . Proof Suppose θ is a unifier for W . By induction on k one can show that there is a substitution λk such that θ = σk λk.
Unification algorithm 3