cannot determine truth value of Relational: symbol interval

125 Views Asked by At

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")
1

There are 1 best solutions below

2
smichr On

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