@@ -192,6 +192,14 @@ cdef c2py(RCP[const symengine.Basic] o):
192
192
r = BooleanAtom.__new__ (BooleanAtom)
193
193
elif (symengine.is_a_Interval(deref(o))):
194
194
r = Interval.__new__ (Interval)
195
+ elif (symengine.is_a_And(deref(o))):
196
+ r = Boolean.__new__ (And)
197
+ elif (symengine.is_a_Not(deref(o))):
198
+ r = Boolean.__new__ (Not)
199
+ elif (symengine.is_a_Or(deref(o))):
200
+ r = Boolean.__new__ (Or)
201
+ elif (symengine.is_a_Xor(deref(o))):
202
+ r = Boolean.__new__ (Xor)
195
203
else :
196
204
raise Exception (" Unsupported SymEngine class." )
197
205
r.thisptr = o
@@ -355,6 +363,20 @@ def sympy2symengine(a, raise_error=False):
355
363
return ceiling(a.args[0 ])
356
364
elif isinstance (a, sympy.conjugate):
357
365
return conjugate(a.args[0 ])
366
+ elif isinstance (a, sympy.And):
367
+ return logical_and(* a.args)
368
+ elif isinstance (a, sympy.Or):
369
+ return logical_or(* a.args)
370
+ elif isinstance (a, sympy.Not):
371
+ return logical_not(a.args[0 ])
372
+ elif isinstance (a, sympy.Nor):
373
+ return logical_nor(* a.args)
374
+ elif isinstance (a, sympy.Nand):
375
+ return logical_nand(* a.args)
376
+ elif isinstance (a, sympy.Xor):
377
+ return logical_xor(* a.args)
378
+ elif isinstance (a, sympy.Xnor):
379
+ return logical_xnor(* a.args)
358
380
elif isinstance (a, sympy.gamma):
359
381
return gamma(a.args[0 ])
360
382
elif isinstance (a, sympy.Derivative):
@@ -1067,7 +1089,7 @@ cdef class Constant(Basic):
1067
1089
raise Exception (" Unknown Constant" )
1068
1090
1069
1091
1070
- class Boolean (Basic ):
1092
+ cdef class Boolean(Basic):
1071
1093
pass
1072
1094
1073
1095
@@ -1102,6 +1124,30 @@ class BooleanFalse(BooleanAtom):
1102
1124
return False
1103
1125
1104
1126
1127
+ class And (Boolean ):
1128
+
1129
+ def __new__ (cls , *args ):
1130
+ return logical_and(* args)
1131
+
1132
+
1133
+ class Or (Boolean ):
1134
+
1135
+ def __new__ (cls , *args ):
1136
+ return logical_or(* args)
1137
+
1138
+
1139
+ class Not (Boolean ):
1140
+
1141
+ def __new__ (cls , x ):
1142
+ return logical_not(x)
1143
+
1144
+
1145
+ class Xor (Boolean ):
1146
+
1147
+ def __new__ (cls , *args ):
1148
+ return logical_xor(* args)
1149
+
1150
+
1105
1151
class Relational (Boolean ):
1106
1152
1107
1153
@property
@@ -3363,6 +3409,58 @@ def trigamma(x):
3363
3409
cdef Basic X = sympify(x)
3364
3410
return c2py(symengine.trigamma(X.thisptr))
3365
3411
3412
+ def logical_and (*args ):
3413
+ cdef symengine.set_boolean s
3414
+ cdef Boolean e_
3415
+ for e in args:
3416
+ e_ = sympify(e)
3417
+ s.insert(e_.thisptr)
3418
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_and(s)))
3419
+
3420
+ def logical_or (*args ):
3421
+ cdef symengine.set_boolean s
3422
+ cdef Boolean e_
3423
+ for e in args:
3424
+ e_ = sympify(e)
3425
+ s.insert(e_.thisptr)
3426
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_or(s)))
3427
+
3428
+ def logical_nor (*args ):
3429
+ cdef symengine.set_boolean s
3430
+ cdef Boolean e_
3431
+ for e in args:
3432
+ e_ = sympify(e)
3433
+ s.insert(e_.thisptr)
3434
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_nor(s)))
3435
+
3436
+ def logical_nand (*args ):
3437
+ cdef symengine.set_boolean s
3438
+ cdef Boolean e_
3439
+ for e in args:
3440
+ e_ = sympify(e)
3441
+ s.insert(e_.thisptr)
3442
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_nand(s)))
3443
+
3444
+ def logical_not (x ):
3445
+ cdef Boolean X = sympify(x)
3446
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_not(X.thisptr)))
3447
+
3448
+ def logical_xor (*args ):
3449
+ cdef symengine.vec_boolean v
3450
+ cdef Boolean e_
3451
+ for e in args:
3452
+ e_ = sympify(e)
3453
+ v.push_back(e_.thisptr)
3454
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_xor(v)))
3455
+
3456
+ def logical_xnor (*args ):
3457
+ cdef symengine.vec_boolean v
3458
+ cdef Boolean e_
3459
+ for e in args:
3460
+ e_ = sympify(e)
3461
+ v.push_back(e_.thisptr)
3462
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_xnor(v)))
3463
+
3366
3464
def eval_double (x ):
3367
3465
cdef Basic X = sympify(x)
3368
3466
return c2py(< RCP[const symengine.Basic]> (symengine.real_double(symengine.eval_double(deref(X.thisptr)))))
0 commit comments