I want to extract value from the result i get by running reduce_rational_inequalities([[-3 < 2*x + 1]], x). For example my answer after running the above function is
And(-2 < x, x < oo)
. Now i want
-2
from this output. I am doing same thing operation with another equation as well. reduce_rational_inequalities([[2*x + 1 < 5]], x). And answer i am getting is
And(-oo < x, x < 2)
. Now i want
2
from this output as well. and want to merge those two outputs.
If anyone went through this sympy library with particular operation. Please let me know.
Thank you for any help in advance.
Someone may well provide a better answer. But this approach does work.
>>> reduce_rational_inequalities([[-3 < 2*x + 1]], x)
And(-2 < x, x < oo)
>>> result = reduce_rational_inequalities([[-3 < 2*x + 1]], x)
>>> result.args
(-2 < x, x < oo)
>>> result.args[0]
-2 < x
>>> result.args[1]
x < oo
>>> result.args[0].args[0]
-2
>>> result.args[0].args[0].is_number
True
Even when the result can be expressed as a tuple of one-sided intervals, as is the case here, then the constants involved could still appear on either side of the inequality. However, you can use the is_number method to determine which side contains the number.
Let's hope someone has a better way.
If you set x as finite, the x < oo part is removed:
>>> from sympy.solvers.inequalities import reduce_rational_inequalities
>>> x = symbols('x', finite=True)
>>> reduce_rational_inequalities([[-3 < 2*x + 1]], x)
-2 < x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With