I am experimenting with piecewise functions with sympy, and have found that it doesn’t like it when I give pairs of expressions and conditions only for certain intervals. For example, when I type the following in an attempt to make the function undefined for x<0
:
from sympy import Symbol, Piecewise
x = Symbol('x')
p = Piecewise((3, 0<=x<=5), (5, x>5))
I get the error message
TypeError: cannot determine truth value of Relational
yet it works fine when I remove the 0<=
from the first condition, but assigns the corresponding expression 3
for negative x
, which I don’t want. In many contexts it makes no sense for a function to be defined for negative x
, and I would like to reflect this in my code.