Yes, it turned out to mess it up for my use case.  It would just confuse 
folks using my application if And(a>2, a<3) ended up always being true when 
a is symbolic.

My solution was to make a derived class off And and add the methods

    def __nonzero__(self):
        raise TypeError("cannot determine truth value of And")

    __bool__ = __nonzero__


This means, that if the And was not evaluated to a boolean (i.e., it is 
still an And), then it shouldn't have a truth value.  It works fine, except 
for the following strange behavior in ipython (this is with my customized 
And function):

In [9]: expr=And(a>2, a<3)

In [10]: ?expr
[snip]
TypeError: cannot determine truth value of And

But, it does act as it is supposed to, so I'm fine with it for my purpose.  
However, I'm not what the right way would be to make such a change to the 
actual sympy code if folks agree this is the correct behavior.  I assume 
one would want ?expr in ipython to work correctly.  (I'm also not sure to 
which of the parent classes of And one should add this behavior.)

Duane





On Friday, May 15, 2015 at 4:34:21 PM UTC-5, Joachim Durchholz wrote:
>
> I agree that `bool(And(a>2, a<3))` and `bool(a>2)` should show analogous 
> behaviour. 
> At least that's what I'd assume from my current understanding of 
> assumptions and evaluation in SymPy. I'd like to defer to the real 
> experts on these components (I think that's @asmeurer and @certik). 
>

-- 
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/9043ddaf-1958-4bf4-9119-c5ea66c4fc13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to