aima/logic.py
def unify(x, y, s):
    """Unify expressions x,y with substitution s; return a substitution that
    would make x,y equal, or None if x,y can not unify. x and y can be
    variables (e.g. Expr('x')), constants, lists, or Exprs. [Fig. 9.1]
    >>> ppsubst(unify(x + y, y + C, {}))
    {x: y, y: C}
    """
    if s is None:
        return None
    elif x == y:
        return s
    elif is_variable(x):
        return unify_var(x, y, s)
    elif is_variable(y):
        return unify_var(y, x, s)
    elif isinstance(x, Expr) and isinstance(y, Expr):
        return unify(x.args, y.args, unify(x.op, y.op, s))
    elif isinstance(x, str) or isinstance(y, str):
        return None
    elif issequence(x) and issequence(y) and len(x) == len(y):
        if not x: return s
        return unify(x[1:], y[1:], unify(x[0], y[0], s))
    else:
        return None
def unify(x, y, s):
    """Unify expressions x,y with substitution s; return a substitution that
    would make x,y equal, or None if x,y can not unify. x and y can be
    variables (e.g. Expr('x')), constants, lists, or Exprs. [Fig. 9.1]
    >>> ppsubst(unify(x + y, y + C, {}))
    {x: y, y: C}
    """
    if s is None:
        return None
    elif x == y:
        return s
    elif is_variable(x):
        return unify_var(x, y, s)
    elif is_variable(y):
        return unify_var(y, x, s)
    elif isinstance(x, Expr) and isinstance(y, Expr):
        return unify(x.args, y.args, unify(x.op, y.op, s))
    elif isinstance(x, str) or isinstance(y, str):
        return None
    elif issequence(x) and issequence(y) and len(x) == len(y):
        if not x: return s
        return unify(x[1:], y[1:], unify(x[0], y[0], s))
    else:
        return None
def unify ( x , y , s ) : if s is None : return None elif x == y : return s elif is_variable ( x ) : return unify_var ( x , y , s ) elif is_variable ( y ) : return unify_var ( y , x , s ) elif isinstance ( x , Expr ) and isinstance ( y , Expr ) : return unify ( x . args , y . args , unify ( x . op , y . op , s ) ) elif isinstance ( x , str ) or isinstance ( y , str ) : return None elif issequence ( x ) and issequence ( y ) and len ( x ) == len ( y ) : if not x : return s return unify ( x [ 1 : ] , y [ 1 : ] , unify ( x [ 0 ] , y [ 0 ] , s ) ) else : return None
Unify expressions x,y with substitution s; return a substitution that
    would make x,y equal, or None if x,y can not unify. x and y can be
    variables (e.g. Expr('x')), constants, lists, or Exprs. [Fig. 9.1]
    >>> ppsubst(unify(x + y, y + C, {}))
    {x: y, y: C}
Unify expressions x y with substitution s ; return a substitution that would make x y equal or None if x y can not unify . x and y can be variables ( e . g . Expr ( x )) constants lists or Exprs . [ Fig . 9 . 1 ] >>> ppsubst ( unify ( x + y y + C {} )) { x : y y : C }