@@ -192,6 +192,12 @@ 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_EmptySet(deref(o))):
196
+ r = EmptySet.__new__ (EmptySet)
197
+ elif (symengine.is_a_UniversalSet(deref(o))):
198
+ r = UniversalSet.__new__ (UniversalSet)
199
+ elif (symengine.is_a_FiniteSet(deref(o))):
200
+ r = FiniteSet.__new__ (FiniteSet)
195
201
elif (symengine.is_a_And(deref(o))):
196
202
r = Boolean.__new__ (And)
197
203
elif (symengine.is_a_Not(deref(o))):
@@ -398,9 +404,15 @@ def sympy2symengine(a, raise_error=False):
398
404
return BooleanFalse
399
405
elif isinstance (a, (sympy.Piecewise)):
400
406
return piecewise(* (a.args))
401
- elif isinstance (a, ( sympy.Interval) ):
407
+ elif isinstance (a, sympy.Interval):
402
408
return interval(* (a.args))
403
- elif isinstance (a, (sympy.Contains)):
409
+ elif isinstance (a, sympy.S.EmptySet):
410
+ return emptyset()
411
+ elif isinstance (a, sympy.S.UniversalSet):
412
+ return universalset()
413
+ elif isinstance (a, sympy.FiniteSet):
414
+ return finiteset(* (a.args))
415
+ elif isinstance (a, sympy.Contains):
404
416
return contains(* (a.args))
405
417
elif isinstance (a, sympy.Function):
406
418
return PyFunction(a, a.args, a.func, sympy_module)
@@ -1090,7 +1102,9 @@ cdef class Constant(Basic):
1090
1102
1091
1103
1092
1104
cdef class Boolean(Basic):
1093
- pass
1105
+
1106
+ def logical_not (self ):
1107
+ return c2py(< RCP[const symengine.Basic]> (deref(symengine.rcp_static_cast_Boolean(self .thisptr)).logical_not()))
1094
1108
1095
1109
1096
1110
class BooleanAtom (Boolean ):
@@ -1129,24 +1143,43 @@ class And(Boolean):
1129
1143
def __new__ (cls , *args ):
1130
1144
return logical_and(* args)
1131
1145
1146
+ def _sympy_ (self ):
1147
+ import sympy
1148
+ s = self .args_as_sympy()
1149
+ return sympy.And(* s)
1150
+
1132
1151
1133
1152
class Or (Boolean ):
1134
1153
1135
1154
def __new__ (cls , *args ):
1136
1155
return logical_or(* args)
1137
1156
1157
+ def _sympy_ (self ):
1158
+ import sympy
1159
+ s = self .args_as_sympy()
1160
+ return sympy.Or(* s)
1161
+
1138
1162
1139
1163
class Not (Boolean ):
1140
1164
1141
1165
def __new__ (cls , x ):
1142
1166
return logical_not(x)
1143
1167
1168
+ def _sympy_ (self ):
1169
+ import sympy
1170
+ return sympy.Not(c2py(< RCP[const symengine.Basic]> (self .args[0 ])._sympy_()))
1171
+
1144
1172
1145
1173
class Xor (Boolean ):
1146
1174
1147
1175
def __new__ (cls , *args ):
1148
1176
return logical_xor(* args)
1149
1177
1178
+ def _sympy_ (self ):
1179
+ import sympy
1180
+ s = self .args_as_sympy()
1181
+ return sympy.Xor(* s)
1182
+
1150
1183
1151
1184
class Relational (Boolean ):
1152
1185
@@ -2482,6 +2515,10 @@ class Subs(Basic):
2482
2515
2483
2516
2484
2517
cdef class Piecewise(Basic):
2518
+
2519
+ def __new__ (self , *args ):
2520
+ return piecewise(* args)
2521
+
2485
2522
def _sympy_ (self ):
2486
2523
import sympy
2487
2524
a = self .args
@@ -2492,6 +2529,7 @@ cdef class Piecewise(Basic):
2492
2529
2493
2530
2494
2531
cdef class Set(Basic):
2532
+
2495
2533
def intersection (self , a ):
2496
2534
cdef Set other = sympify(a)
2497
2535
cdef RCP[const symengine.Set] other_ = symengine.rcp_static_cast_Set(other.thisptr)
@@ -2502,16 +2540,65 @@ cdef class Set(Basic):
2502
2540
cdef Set other = sympify(a)
2503
2541
cdef RCP[const symengine.Set] other_ = symengine.rcp_static_cast_Set(other.thisptr)
2504
2542
return c2py(< RCP[const symengine.Basic]> (deref(symengine.rcp_static_cast_Set(self .thisptr))
2505
- .set_intersection(other_)))
2543
+ .set_union(other_)))
2544
+
2545
+ def complement (self , a ):
2546
+ cdef Set other = sympify(a)
2547
+ cdef RCP[const symengine.Set] other_ = symengine.rcp_static_cast_Set(other.thisptr)
2548
+ return c2py(< RCP[const symengine.Basic]> (deref(symengine.rcp_static_cast_Set(self .thisptr))
2549
+ .set_complement(other_)))
2550
+
2551
+ def contains (self , a ):
2552
+ cdef Basic a_ = sympify(a)
2553
+ return c2py(< RCP[const symengine.Basic]> (deref(symengine.rcp_static_cast_Set(self .thisptr))
2554
+ .contains(a_)))
2506
2555
2507
2556
2508
2557
cdef class Interval(Set):
2558
+
2559
+ def __new__ (self , *args ):
2560
+ return interval(* args)
2561
+
2509
2562
def _sympy_ (self ):
2510
2563
import sympy
2511
2564
return sympy.Interval(* [arg._sympy_() for arg in self .args])
2512
2565
2513
2566
2567
+ cdef class EmptySet(Set):
2568
+
2569
+ def __new__ (self ):
2570
+ return emptyset()
2571
+
2572
+ def _sympy_ (self ):
2573
+ import sympy
2574
+ return sympy.EmptySet()
2575
+
2576
+
2577
+ cdef class UniversalSet(Set):
2578
+
2579
+ def __new__ (self ):
2580
+ return universalset()
2581
+
2582
+ def _sympy_ (self ):
2583
+ import sympy
2584
+ return sympy.UniversalSet()
2585
+
2586
+
2587
+ cdef class FiniteSet(Set):
2588
+
2589
+ def __new__ (self , *args ):
2590
+ return finiteset(* args)
2591
+
2592
+ def _sympy_ (self ):
2593
+ import sympy
2594
+ return sympy.FiniteSet(* [arg._sympy_() for arg in self .args])
2595
+
2596
+
2514
2597
cdef class Contains(Boolean):
2598
+
2599
+ def __new__ (self , expr , sset ):
2600
+ return contains(expr, sset)
2601
+
2515
2602
def _sympy_ (self ):
2516
2603
import sympy
2517
2604
return sympy.Contains(* [arg._sympy_() for arg in self .args])
@@ -3433,6 +3520,8 @@ def logical_nor(*args):
3433
3520
s.insert(e_.thisptr)
3434
3521
return c2py(< RCP[const symengine.Basic]> (symengine.logical_nor(s)))
3435
3522
3523
+ Nor = logical_nor
3524
+
3436
3525
def logical_nand (*args ):
3437
3526
cdef symengine.set_boolean s
3438
3527
cdef Boolean e_
@@ -3441,6 +3530,8 @@ def logical_nand(*args):
3441
3530
s.insert(e_.thisptr)
3442
3531
return c2py(< RCP[const symengine.Basic]> (symengine.logical_nand(s)))
3443
3532
3533
+ Nand = logical_nand
3534
+
3444
3535
def logical_not (x ):
3445
3536
cdef Boolean X = sympify(x)
3446
3537
return c2py(< RCP[const symengine.Basic]> (symengine.logical_not(X.thisptr)))
@@ -3461,6 +3552,8 @@ def logical_xnor(*args):
3461
3552
v.push_back(e_.thisptr)
3462
3553
return c2py(< RCP[const symengine.Basic]> (symengine.logical_xnor(v)))
3463
3554
3555
+ Xnor = logical_xnor
3556
+
3464
3557
def eval_double (x ):
3465
3558
cdef Basic X = sympify(x)
3466
3559
return c2py(< RCP[const symengine.Basic]> (symengine.real_double(symengine.eval_double(deref(X.thisptr)))))
@@ -4334,11 +4427,28 @@ def interval(start, end, left_open=False, right_open=False):
4334
4427
return c2py(symengine.interval(n1, n2, left_open_, right_open_))
4335
4428
4336
4429
4430
+ def emptyset ():
4431
+ return c2py(< RCP[const symengine.Basic]> (symengine.emptyset()))
4432
+
4433
+
4434
+ def universalset ():
4435
+ return c2py(< RCP[const symengine.Basic]> (symengine.universalset()))
4436
+
4437
+
4438
+ def finiteset (*args )
4439
+ cdef symengine.set_basic s
4440
+ cdef Basic e_
4441
+ for e in args:
4442
+ e_ = sympify(e)
4443
+ s.insert(e_.thisptr )
4444
+ return c2py(<RCP[const symengine.Basic]>(symengine.finiteset(s )))
4445
+
4446
+
4337
4447
def contains(expr , sset ):
4338
4448
cdef Basic expr_ = sympify(expr)
4339
4449
cdef Set sset_ = sympify(sset)
4340
4450
cdef RCP[const symengine.Set] s = symengine.rcp_static_cast_Set(sset_.thisptr)
4341
- return c2py(< RCP[const symengine.Basic]> symengine.contains(expr_.thisptr, s))
4451
+ return c2py(< RCP[const symengine.Basic]> ( symengine.contains(expr_.thisptr, s) ))
4342
4452
4343
4453
def ccode (expr ):
4344
4454
cdef Basic expr_ = sympify(expr)
0 commit comments