Oh, this one should have been obvious. The solution you are using with
eval only works on subclasses of Function. Add and Mul are not
subclasses of Function. To get them to work, you need to override the
flatten classmethod. The API for flatten is a little different. Look
at the current implementation for more details, but basically it needs
to take in a sequence and spit out two sequences and some
order_symbols thing (I'm not entirely sure what the API for this
should be, but if you never use O, just return None). So for instance,
if you only care about commutatives and no order symbols, you can use

class noevalAdd(Add):
    @classmethod
    def flatten(cls, seq):
        return seq, [], None

Alternately, you can just override __new__. You may need to redo some
logic, though (or at the very least make sure to call some superclass
initializers correctly). The advantage of this is that 0 is removed in
__new__, not flatten, so the above will still remove 0. Take a look at
AssocOp.__new__.

Aaron Meurer


On Wed, Oct 2, 2013 at 9:35 AM, Ben Lucato <[email protected]> wrote:
> The exact code being used is:
>
> class noevalAdd(sympy.Add):
>     @classmethod
>     def eval(cls, arg):
>         return
>
>
> On 2 October 2013 02:26, Aaron Meurer <[email protected]> wrote:
>>
>> This is probably an instance of the sort of thing I mentioned earlier in
>> this thread where some classes do not play nicely with potential subclasses.
>> What is the exact code you are using for noevalAdd?
>>
>> Aaron Meurer
>>
>> On Oct 1, 2013, at 3:45 AM, Ben Lucato <[email protected]> wrote:
>>
>> I have been doing some more work on this, and wanted to further include
>> sympy.Add, sympy.Mul and sympy.Pow, however it doesn't work the same.
>>
>> For instance, doing noevalAdd(1, 2) returns 3, whereas sympy.Add(1, 2,
>> evaluate=False) returns 1 + 2.
>>
>>
>> Is there a way to do the same thing for these 'core' classes?
>>
>> --
>> 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.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "sympy" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/sympy/zilEXwN26so/unsubscribe.
>> To unsubscribe from this group and all its topics, 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.
>
>
>
>
> --
>
>
> Ben Lucato
> ----------------------------------------------------------------------------------
> Phone: +61 400 159 632 | Email: [email protected]
>
> --
> 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.

-- 
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