Boolean operation of a Boolean variable on a symbol produces TypeError
, but the reverse has no problem:
>>> from sympy import *
>>> x = Symbol('x', bool=True)
>>> x ^ True
Not(x)
>>> True ^ x
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
True ^ x
TypeError: unsupported operand type(s) for ^: 'bool' and 'Symbol'
I can do try-catch:
try :
print True ^ x
except TypeError:
print x ^ True
Not(x)
But, for my present task, it is impossible to implement this with try-except
as I have to deal with ~200 symbols. How can I achieve this?