Reputation: 49
Is there a library in python to simplify boolean expression with comparison expressions e.g.
from:
(a < 10 & a <= 10) | b
to:
(a < 10) | b
Upvotes: 0
Views: 72
Reputation: 14573
SymPy can do some simplification of this kind:
In [15]: from sympy import symbols
In [16]: a, b = symbols('a, b')
In [17]: condition = ((a < 10) & (a <= 10)) | b
In [18]: condition
Out[18]: b ∨ (a ≤ 10 ∧ a < 10)
In [19]: simplify(condition)
Out[19]: b ∨ a < 10
For more complicated problems you might need to tell SymPy how exactly to simplify the condition.
Upvotes: 2