I created an AddUnsort class that doesn't change the order of its 
argument.  Now, I discovered I get an infinite recursion when I evalf.  
But, I'm having trouble figuring out how to prevent this infinite recursion.

The still get the infinite recursion even with this stripped down class 
that does very little to Add.  The only change is that it doesn't evaluate 
the arguments (it acts as long evaluate=False) and it doesn't order the 
arguments.

from sympy import Add
from sympy.core.cache import cacheit
from sympy.core.sympify import _sympify

class AddUnsortPart(Add):
    @cacheit
    def __new__(cls, *args, **options):
        # __new__ from AssocOp, with differences
        # - we don't throw out the identity
        # - we never evaluate

        args = list(map(_sympify, args))

        if len(args) == 0:
            return cls.identity
        if len(args) == 1:
            return args[0]

        return cls._from_args(args)


But, executing, for example,

AddUnsortPart(2,5).evalf()

gets an infinite loop between the _eval_evalf() function of AssocOp and 
._evalf() of EvalfMixin.  I'm obviously missing something here, as I don't 
see why one usually doesn't get this infinite loop, so what I should do to 
prevent this problem.

Any pointers would be helpful.  The above stripped down class hardly 
modifies Add at all, so it's puzzling why this change creates the problem.  
(Of course, in the real class, I'm making a lot more changes to make it 
useful AddUnsort class.)

Thanks,
Duane




-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/8ea57d65-6e26-4554-b0e3-bcaa8751b234%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to