Exemplo n.º 1
0
def builtin_function(expr, args=None):
    """Returns a builtin-function call applied to given arguments."""

    if isinstance(expr, Application):
        name = str(type(expr).__name__)
    elif isinstance(expr, str):
        name = expr
    else:
        raise TypeError('expr must be of type str or Function')

    dic = builtin_functions_dict

    if name in dic.keys():
        return dic[name](*args)

    if name == 'Not':
        return Not(*args)

    if name == 'map':
        func = Function(str(expr.args[0].name))
        args = [func] + list(args[1:])
        return PythonMap(*args)

    if name == 'lambdify':
        return lambdify(expr, args)

    return None
Exemplo n.º 2
0
def builtin_function(expr, args=None):
    """Returns a builtin-function call applied to given arguments."""
    if not (isinstance(expr, Application) or isinstance(expr, str)):
        raise TypeError('Expecting a string or a Function class')

    if isinstance(expr, Application):
        name = str(type(expr).__name__)
    elif isinstance(expr, str):
        name = expr
    else:
        raise TypeError('expr must be of type str or Function')

    dic = builtin_functions_dict

    if name in dic.keys() :
        return dic[name](*args)
    elif name == 'array':
        return Array(*args)
    elif name in ['complex']:
        if len(args)==1:
            args = [args[0],Float(0)]
        return Complex(args[0],args[1])
    elif name == 'Not':
        return Not(*args)

    elif name == 'map':
        func = Function(str(expr.args[0].name))
        args = [func]+list(args[1:])
        return Map(*args)

    elif name == 'lambdify':
        return lambdify(expr, args)

    return None