I'm not sure if I'm doing something wrong, I have the following script:
X = sympy.Symbol('X', real=True)
Y = sympy.Symbol('Y', real=True)
ex = ((X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2) & (Y >= 0)).simplify()
ex = sympy.logic.boolalg.simplify_logic(ex, force=True, deep=True)
print(ex)
The result is:
(X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2) & (Y >= 0)
But I would expect that the 3 comparisons with the variable Y to be reduced to:
(Y <= 0.5) & (Y > 0.2)
Any advise on how to do this?
This might be a bug in sympy.
If you use two separate expressions, one with X and one with Y, they simplify properly:
>>> ex1 = (X >= 1.4) & (X <= 1.6)
>>> ex2 = (Y <= 0.5) & (Y > 0.2) & (Y >= 0)
>>> ex1
(X >= 1.4) & (X <= 1.6)
>>> ex2
(Y <= 0.5) & (Y > 0.2) & (Y >= 0)
>>>
>>> ex = ex1 & ex2
>>> ex
(X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2) & (Y >= 0)
>>> ex = ex.simplify()
>>> ex
(X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2) & (Y >= 0)
>>>
>>> ex1 = ex1.simplify()
>>> ex1
(X >= 1.4) & (X <= 1.6)
>>> ex2 = ex2.simplify()
>>> ex2
(Y <= 0.5) & (Y > 0.2)
>>> ex = ex1 & ex2
>>> ex
(X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2)
I'd suggest talking to the sympy devs (not sure if that would be a github issue or forum post somewhere) to ask about this.
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