Skip to content

Commit

Permalink
Override __bool__ in Relational, so that it returns whatever the bool…
Browse files Browse the repository at this point in the history
…ean evaluation is, instead of always True. Resolves symengine#312
  • Loading branch information
qthequartermasterman committed Jun 4, 2021
1 parent 7dc38eb commit a96e507
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions symengine/lib/symengine_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,14 @@ class Relational(Boolean):
def is_Relational(self):
return True

def __bool__(self):
if len(self.free_symbols):
# If there are any free symbols, then boolean evaluation is ambiguous in most cases. Throw a Type Error
raise TypeError(f'Relational with free symbols cannot be cast as bool: {self}')
else:
simplification = self.simplify()
return bool(simplification)

Rel = Relational


Expand Down

0 comments on commit a96e507

Please sign in to comment.