I use the sympy's solveset
to solve inequalities in Python.
For example, if I want to solve (10000 / x) - 1 < 0
, I can do this:
x = sympy.Symbol('x')
print(sympy.solveset((10000 / x) - 1 < 0, x, sympy.S.Reals))
What can I do to ask Python to solve a inequality, except that it is enclosed in quotes? For instance, "x**2 > 4, x"
. I tried to search it up, however, all I have found where how to solve "hard-coded" inequalities.
You need to parse the string. Scipy has a parsing module that should do the trick: