Skip to content

Commit e780437

Browse files
committed
Convert BooleanAtom to bool
1 parent 18b94bc commit e780437

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,13 @@ cdef class BooleanTrue(BooleanAtom):
13011301
def _sage_(self):
13021302
return True
13031303

1304+
def __nonzero__(self):
1305+
return True
1306+
1307+
def __bool__(self):
1308+
return True
1309+
1310+
13041311
true = BooleanTrue()
13051312

13061313

@@ -1316,6 +1323,12 @@ cdef class BooleanFalse(BooleanAtom):
13161323
def _sage_(self):
13171324
return False
13181325

1326+
def __nonzero__(self):
1327+
return False
1328+
1329+
def __bool__(self):
1330+
return False
1331+
13191332
false = BooleanFalse()
13201333

13211334

symengine/tests/test_arit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,11 @@ def test_special_constants():
216216
assert One() == Integer(1)
217217
assert NegativeOne() == Integer(-1)
218218
assert Half() == Rational(1, 2)
219+
220+
221+
def test_bool():
222+
x = Symbol('x')
223+
if (x**2).args[1] > 0:
224+
assert True
225+
if (x**2).args[1] < 0:
226+
assert False

0 commit comments

Comments
 (0)