'Helper for xreplace. Tracks whether a replacement actually occurred.'

def _xreplace(self, rule):

    if (self in rule):
        return (rule[self], True)
    elif rule:
        args = []
        changed = False
        for a in self.args:
            try:
                a_xr = a._xreplace(rule)
                args.append(a_xr[0])
                changed |= a_xr[1]
            except AttributeError:
                args.append(a)
        args = tuple(args)
        if changed:
            return (self.func(*args), True)
    return (self, False)
