Skip to content

Commit a96e507

Browse files
Override __bool__ in Relational, so that it returns whatever the boolean evaluation is, instead of always True. Resolves symengine#312
1 parent 7dc38eb commit a96e507

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,14 @@ class Relational(Boolean):
15021502
def is_Relational(self):
15031503
return True
15041504

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

15071515

0 commit comments

Comments
 (0)