private Dictionary<Variable, Term> unifyVar(Variable var, FOLNode x,
Dictionary<Variable, Term> theta)
{
if (!(x is Term))
{
return null;
}
else if (theta.ContainsKey(var))
{
// if {var/val} E theta then return UNIFY(val, x, theta)
return unify(theta[var], x, theta);
}
else if (theta.Keys.Contains(x))
{
// else if {x/val} E theta then return UNIFY(var, val, theta)
return unify(var, (FOLNode)theta[(Variable)x], theta);
}
else if (occurCheck(theta, var, x))
{
// else if OCCUR-CHECK?(var, x) then return failure
return null;
}
else
{
// else return add {var/x} to theta
cascadeSubstitution(theta, var, (Term)x);
return theta;
}
}