I’m using Sympy to work with inequalties. An example of expression would be:
expression = (x > 852 | y <= 7) & (x > 704 | y >= 6)
Then I want to apply a constraint:
constraint = x <= 759 (known to be true)
Then the term (x > 852) is False
The expected expression should be simplified to:
(y <= 7) & (x > 704 | y >= 6)
Is this possible with Sympy?
An example for the code would be:
import sympy
x = sympy.Symbol(‘x’)
y = sympy.Symbol(‘y’)
(x > 852 | y <= 7) & (x > 704 | y >= 6)
expression = (sympy.Gt(x, 852) | sympy.Le(y, 7)) & (sympy.Gt(x, 704) | sympy.Ge(y, 6))
x <= 759
condition = sympy.Le(x, 759)
This will only do direct substitution of the condition
expression = expression.subs(condition, True)
Germán Castro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.