In order to represent (and modify) a sympy expression within Mathics we've 
been using the following:

BasicSympy = sympy.Expr

class SympyExpression(BasicSympy):
    is_Function = True
    nargs = None

    def __new__(cls, expr):
        obj = BasicSympy.__new__(
            cls, *(expr.head.to_sympy(),) + tuple(leaf.to_sympy()
                                                  for leaf in expr.leaves))
        obj.expr = expr
        return obj

    @property
    def func(self):
        class SympyExpressionFunc(object):
            def __new__(cls, *args):
                return SympyExpression(self.expr)
        return SympyExpressionFunc

    def has_any_symbols(self, *syms):
        result = any(arg.has_any_symbols(*syms) for arg in self.args)
        return result

    def _eval_subs(self, old, new):
        if self == old:
            return new
        old, new = from_sympy(old), from_sympy(new)
        old_name = old.get_name()
        if old_name:
            new_expr = self.expr.replace_vars({old_name: new})
            return SympyExpression(new_expr)
        return self

    def _eval_rewrite(self, pattern, rule, **hints):
        return self

    @property
    def is_commutative(self):
        if all(getattr(t, 'is_commutative') for t in self.args):
            return True
        else:
            return False

    def __str__(self):
        return '%s[%s]' % (super(SympyExpression, self).__str__(), 
self.expr)

 
The problem is that sympy.expr._expand_hint has been modified to create a 
new sympy.Expr instance (line 2808 of sympy/core/expr.py) rather than using 
func. Because SympyExpression overrides __new__ to only accept one 
argument, this raises an error. 

My original thought was to modify SympyExpression (e.g. a factory that does 
some monkey-patching on sympy.Expr), but asmeurer told me that the 
implementation in sympy.Expr._expand_hint is wrong.

Should we revert some of the changes in 
commit 4b7c2b8199322d8b364b97f6bd27ccaa9dc21dae?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to