'Helper for rcall method.'

@staticmethod
def _recursive_call(expr_to_call, on_args):

    from sympy import Symbol
    def the_call_method_is_overridden(expr):
        for cls in getmro(type(expr)):
            if ('__call__' in cls.__dict__):
                return (cls != Basic)
    if (callable(expr_to_call) and the_call_method_is_overridden(expr_to_call)):
        if isinstance(expr_to_call, Symbol):
            return expr_to_call
        else:
            return expr_to_call(*on_args)
    elif expr_to_call.args:
        args = [Basic._recursive_call(sub, on_args) for sub in expr_to_call.args]
        return type(expr_to_call)(*args)
    else:
        return expr_to_call
