Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 1.81 KB

Unify.md

File metadata and controls

28 lines (23 loc) · 1.81 KB

UNIFY

AIMA3e

function UNIFY(x, y, θ) returns a substitution to make x and y identical
inputs: x, a variable, constant, list, or compound
    y, a variable, constant, list, or compound
    θ, the substitution built up so far (optional, defaults to empty)

if θ = failure then return failure
else if x = y then return θ
else if VARIABLE?(x) then return UNIVY-VAR(x, y, θ)
else if VARIABLE?(y) then return UNIFY-VAR(y, x, θ)
else if COMPOUND?(x) and COMPOUND?(y) then
   return UNIFY(x.ARGS, y.ARGS, UNIFY(x.OP, y.OP, θ))
else if LIST?(x) and LIST?(y) then
   return UNIFY(x.REST, y.REST, UNIFY(x.FIRST, y.FIRST, θ))
else return failure


function UNIFY-VAR(var, x, θ) returns a substitution

if {var / val} ∈ θ then return UNIFY(val, x, θ)
else if {x / val} ∈ θ then return UNIFY(var, val, θ)
else if OCCUR-CHECK?(var, x) then return failure
else return add {var/x} to θ


Figure ?? The unification algorithm. The algorithm works by comparing the structures of the inputs, elements by element. The substitution θ that is the argument to UNIFY is built up along the way and is used to make sure that later comparisons are consistent with bindings that were established earlier. In a compound expression, such as F(A, B), the OP field picks out the function symbol F and the ARGS field picks out the argument list (A, B).