(cls, expr)
Traverses the (func, args) tree of an expression and creates a sympy
        namespace. All other modules are imported only as a module name. That way
        the namespace is not poluted and rests quite small. It probably causes much
        more variable lookups and so it takes more time, but there are no tests on
        that for the moment.
Traverses the (func, args) tree of an expression and creates a sympy
        namespace. All other modules are imported only as a module name. That way
        the namespace is not poluted and rests quite small. It probably causes much
        more variable lookups and so it takes more time, but there are no tests on
        that for the moment.
Traverses the ( func args ) tree of an expression and creates a sympy namespace . All other modules are imported only as a module name . That way the namespace is not poluted and rests quite small . It probably causes much more variable lookups and so it takes more time but there are no tests on that for the moment .
def sympy_expression_namespace(cls, expr):
        """Traverses the (func, args) tree of an expression and creates a sympy
        namespace. All other modules are imported only as a module name. That way
        the namespace is not poluted and rests quite small. It probably causes much
        more variable lookups and so it takes more time, but there are no tests on
        that for the moment."""
        if expr is None:
            return {}
        else:
            funcname = str(expr.func)
            # XXX Workaround
            # Here we add an ugly workaround because str(func(x))
            # is not always the same as str(func). Eg
            # >>> str(Integral(x))
            # "Integral(x)"
            # >>> str(Integral)
            # "<class 'sympy.integrals.integrals.Integral'>"
            # >>> str(sqrt(x))
            # "sqrt(x)"
            # >>> str(sqrt)
            # "<function sqrt at 0x3d92de8>"
            # >>> str(sin(x))
            # "sin(x)"
            # >>> str(sin)
            # "sin"
            # Either one of those can be used but not all at the same time.
            # The code considers the sin example as the right one.
            regexlist = [
                r'<class \'sympy[\w.]*?.([\w]*)\'>$',
                # the example Integral
                r'<function ([\w]*) at 0x[\w]*>$',    # the example sqrt
            ]
            for r in regexlist:
                m = re.match(r, funcname)
                if m is not None:
                    funcname = m.groups()[0]
            # End of the workaround
            # XXX debug: print funcname
            args_dict = {}
            for a in expr.args:
                if (isinstance(a, Symbol) or
                    isinstance(a, NumberSymbol) or
                        a in [I, zoo, oo]):
                    continue
                else:
                    args_dict.update(cls.sympy_expression_namespace(a))
            args_dict.update({funcname: expr.func})
            return args_dict
def sympy_expression_namespace ( cls , expr ) : if expr is None : return { } else : funcname = str ( expr . func ) # XXX Workaround # Here we add an ugly workaround because str(func(x)) # is not always the same as str(func). Eg # >>> str(Integral(x)) # "Integral(x)" # >>> str(Integral) # "<class 'sympy.integrals.integrals.Integral'>" # >>> str(sqrt(x)) # "sqrt(x)" # >>> str(sqrt) # "<function sqrt at 0x3d92de8>" # >>> str(sin(x)) # "sin(x)" # >>> str(sin) # "sin" # Either one of those can be used but not all at the same time. # The code considers the sin example as the right one. regexlist = [ r'<class \'sympy[\w.]*?.([\w]*)\'>$' , # the example Integral r'<function ([\w]*) at 0x[\w]*>$' , # the example sqrt ] for r in regexlist : m = re . match ( r , funcname ) if m is not None : funcname = m . groups ( ) [ 0 ] # End of the workaround # XXX debug: print funcname args_dict = { } for a in expr . args : if ( isinstance ( a , Symbol ) or isinstance ( a , NumberSymbol ) or a in [ I , zoo , oo ] ) : continue else : args_dict . update ( cls . sympy_expression_namespace ( a ) ) args_dict . update ( { funcname : expr . func } ) return args_dict