'Helper method for match() that looks for a match between Wild symbols
in self and expressions in expr.
Examples
>>> from sympy import symbols, Wild, Basic
>>> a, b, c = symbols(\'a b c\')
>>> x = Wild(\'x\')
>>> Basic(a + x, x).matches(Basic(a + b, c)) is None
True
>>> Basic(a + x, x).matches(Basic(a + b + c, b + c))
{x_: b + c}'

def matches(self, expr, repl_dict={}, old=False):

    expr = sympify(expr)
    if (not isinstance(expr, self.__class__)):
        return None
    if (self == expr):
        return repl_dict
    if (len(self.args) != len(expr.args)):
        return None
    d = repl_dict.copy()
    for (arg, other_arg) in zip(self.args, expr.args):
        if (arg == other_arg):
            continue
        d = arg.xreplace(d).matches(other_arg, d, old=old)
        if (d is None):
            return None
    return d
