sympy's solve seems to generally work for inequalities. For example:
from sympy import symbols, solve;
x = symbols('x');
print(solve('x^2 > 4', x)); # ((-oo < x) & (x < -2)) | ((2 < x) & (x < oo))
In some cases where all values of x or no values of x are valid solutions, solve()
returns True
or False
to indicate that.
print(solve('x^2 > 4 + x^2', x)); # False
print(solve('x^2 >= x^2', x)); # True
However, there are other cases where I would expect a result of True or False and instead I get []
:
print(solve('x - x > 0', x)); # []
print(solve('x - x >= 0', x)); # []
Why does this happen/what am I doing wrong?
Remember that expressions are not WYSIWYG: your expressions did not have x
in them:
print(solve('x - x > 0', x)); # [] <-- solve(0>0, x) => solve(False, x)
print(solve('x - x >= 0', x)); # [] <-- solve(0>=0, x) => solve(True, x)
Since x
does not appear in either expression, there are no values of x
to report in the first case that can make the False become True; in the second case there is no way to represent the Universal set (since any value of x cannot change the value of True to anything else). So in both cases there is no solution to report (though maybe an error or at least x<=oo
could be reported for the second case) but in general: if the requested symbol does not appear in the equation (at the outset or after simplification) then []
is returned (and x
does not appear in True).