> > In [1]: if x < y and x > y: > > ...: print "I would not expect to see this printed" > > But why would you want to do this? "if x < y" doesn't make sense if x and y > are symbols.
Because it could make sense to compare python objects that way. (but see below) > But then we loose the shortcut x < y => Lt(x, y). Actually no, x < y can return Lt(x, y). The comparison is only handed over to python when you try to evaluate it with bool(Lt(x, y)). (I think I am only describing how things work today, but from a different perspective.) > This will change in Python 3. There, objects have to be the same type to be > compared. Oh, that changes the situation. The future python programmer will not expect the comparison operators to apply everywhere, so then I can understand your point that "x < y doesn't make sense if x and y are symbols." But still, it would be easy to work with a rule that says that bool(Relational(...)) hands over the evaluation to python. This would mean that "if x < y:" acts like the comparison python would normally do, and "if ask(x < y, Assume(x- y,Q.whatever):" tries to determine the mathematical question. I think the central point in my objection is that if you write a piece of python code using the sympy libraries, it would be very confusing if some comparisons turn out to be always True. Because of this, I suggest that relational objects should not simply return True to indicate that they are ``nonzero''. Since the mathematical problem can be non-trivial or impossible to determine, that is not an option, so instead the comparisons should be handed over to python, completely transparent to the user. All that is needed if we go for this solution is a section in the "gotchas and pitfalls" explaining what the user should do to evaluate a mathematical inequality, and what "if x<y:" really means. Øyvind -- 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.
