Hi, Here is my summary of some bugs i have found in Relational. I would fix them, but I think there are larger issues that need discussing.
What is the truth value of a symbolic expression? ================================================= The current general pattern is that symbolic expressions evaluate to True: In [61]: bool(x) Out[61]: True In [62]: bool(x+1) Out[62]: True In [63]: bool(x*2) Out[63]: True In [64]: bool(2*x) Out[64]: True In [65]: bool(x>0) Out[65]: True But: In [66]: bool(x<0) Out[66]: False This is obviously not consistent and it a bug in Relational.__nonzero__ Relational classes don't properly evaluate to booleans ====================================================== Consider these examples: In [67]: Eq(0,0) Out[67]: 0 == 0 In [68]: Ge(1,0) Out[68]: 0 <= 1 Obviously, these should resolve to booleans. You may think, why wouldn't you just do 0==0 or 1<0? But consider this: In [69]: e = Ge(x,0) In [70]: e.subs(x,1) Out[70]: 0 <= 1 # Just Ge(1,0)! Thus. it is common and easy to get Relational classes that should evaluate to a boolean but don't. This behavior also affects boolean logic classes like And/Or, etc. as well as Interval: In [71]: e = And(x>0,x<1) In [72]: e.subs(x,0.5) Out[72]: And(0 < 0.5, 0.5 < 1) The problem is that the __new__ method of Relational does NOT actually try to compare the lhs and rhs. That is, Ge.__new__(lhs, rhs) doesn't actually try lhs >= rhs. But, we can't have it try that or it will generate an infinite loop! Resolving this will be quite subtle. Cheers, Brian -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
