There's an issue for this too:
http://code.google.com/p/sympy/issues/detail?id=2960
Python evaluates "a < b < c" as "(a < b) and (b < c)". Since it's
impossible to override the "and" operator, this always returns the
first one if it evaluate to True or the second one if it evaluate to
True (or False if neither do). Right now, this happens arbitrarily
(see http://code.google.com/p/sympy/issues/detail?id=2832).
This can be done, however, just not using that syntax. Use the And()
object. For example:
In [30]: And(10 < x, x < 13)
Out[30]: x < 13 ∧ 10 < x
In [14]: And(10 < x, x < 13).subs(x, 9)
Out[14]: False
In [15]: And(10 < x, x < 13).subs(x, 11)
Out[15]: True
Depending on what you are doing, you might be able to also make use of
the Interval() object:
In [18]: Interval(10, 13, True, True)
Out[18]: (10, 13)
We don't have an In() object yet, though (there's an issue for this
somewhere, but I couldn't find it, as In is a hard word to search
for), so if you want to explicitly represent the fact that some value
x is inside an interval, for now, you will have to use And() and
inequalities. What you can do is use Interval and it's useful
operations (such as union and intersection) until you need an explicit
relationship, and then use .as_relational()
In [31]: Interval(10, 13, True, True).as_relational(x)
Out[31]: x < 13 ∧ 10 < x
Of course, whether to use And() and inequalities or intervals depends
on what you are doing.
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/_BmcIHE29zcJ.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
I posted my comments on the issue page.
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/0Jl0-og4sgQJ.