I am trying to solve inequality using sympy symbols but I can't set an interval for my symbols, is there a way to do it???
import sympy as sy
p = sy.Symbol("p") # 0 < p < 1
f = p**2-1
if f < 0:
print("f is negative")
I am trying to solve inequality using sympy symbols but I can't set an interval for my symbols, is there a way to do it???
import sympy as sy
p = sy.Symbol("p") # 0 < p < 1
f = p**2-1
if f < 0:
print("f is negative")
If you replace x
with an expression that has the range you are interested in then you can see that the relationship is true:
>>> from sympy import var, cancel, bottom_up
>>> var('x')
x
>>> var('eps', positive=True)
eps
>>> eq=x**2-1<0
>>> eq.subs(x,1/(1+eps))
-1 + (eps + 1)**(-2) < 0
>>> bottom_up(_, cancel)
True