Using SymPy, is it possible to limit the possible values of a symbol/variable to a certain range? I now I can set some properties while defining symbols, like positive
positive
You can specify the bounds as inequalities such as x >= lb and x <= ub, for example:
x >= lb
x <= ub
from sympy.solvers import solve from sympy import Symbol x = Symbol('x') solve([x >= 0.5, x <= 3, x**2 - 1], x)
Here we search for a solution of equation x**2 == 1 such that x is in the interval [0.5, 3].
x**2 == 1
x
[0.5, 3]