@@ -183,25 +183,25 @@ cdef c2py(RCP[const symengine.Basic] o):
183
183
elif (symengine.is_a_PyNumber(deref(o))):
184
184
r = PyNumber.__new__ (PyNumber)
185
185
elif (symengine.is_a_Piecewise(deref(o))):
186
- r = Piecewise .__new__ (Piecewise)
186
+ r = Basic .__new__ (Piecewise)
187
187
elif (symengine.is_a_Contains(deref(o))):
188
- r = Contains .__new__ (Contains)
188
+ r = Boolean .__new__ (Contains)
189
189
elif (symengine.is_a_Interval(deref(o))):
190
- r = Interval .__new__ (Interval)
190
+ r = Set .__new__ (Interval)
191
191
elif (symengine.is_a_EmptySet(deref(o))):
192
- r = EmptySet .__new__ (EmptySet)
192
+ r = Set .__new__ (EmptySet)
193
193
elif (symengine.is_a_UniversalSet(deref(o))):
194
- r = UniversalSet .__new__ (UniversalSet)
194
+ r = Set .__new__ (UniversalSet)
195
195
elif (symengine.is_a_FiniteSet(deref(o))):
196
- r = FiniteSet .__new__ (FiniteSet)
196
+ r = Set .__new__ (FiniteSet)
197
197
elif (symengine.is_a_Union(deref(o))):
198
- r = Union .__new__ (Union)
198
+ r = Set .__new__ (Union)
199
199
elif (symengine.is_a_Complement(deref(o))):
200
- r = Complement .__new__ (Complement)
200
+ r = Set .__new__ (Complement)
201
201
elif (symengine.is_a_ConditionSet(deref(o))):
202
- r = ConditionSet .__new__ (ConditionSet)
202
+ r = Set .__new__ (ConditionSet)
203
203
elif (symengine.is_a_ImageSet(deref(o))):
204
- r = ImageSet .__new__ (ImageSet)
204
+ r = Set .__new__ (ImageSet)
205
205
elif (symengine.is_a_And(deref(o))):
206
206
r = Boolean.__new__ (And)
207
207
elif (symengine.is_a_Not(deref(o))):
@@ -380,13 +380,11 @@ def sympy2symengine(a, raise_error=False):
380
380
elif isinstance (a, sympy.Not):
381
381
return logical_not(a.args[0 ])
382
382
elif isinstance (a, sympy.Nor):
383
- return logical_nor (* a.args)
383
+ return Nor (* a.args)
384
384
elif isinstance (a, sympy.Nand):
385
- return logical_nand (* a.args)
385
+ return Nand (* a.args)
386
386
elif isinstance (a, sympy.Xor):
387
387
return logical_xor(* a.args)
388
- elif isinstance (a, sympy.Xnor):
389
- return logical_xnor(* a.args)
390
388
elif isinstance (a, sympy.gamma):
391
389
return gamma(a.args[0 ])
392
390
elif isinstance (a, sympy.Derivative):
@@ -400,10 +398,8 @@ def sympy2symengine(a, raise_error=False):
400
398
return piecewise(* (a.args))
401
399
elif isinstance (a, sympy.Interval):
402
400
return interval(* (a.args))
403
- elif isinstance (a, sympy.S. EmptySet):
401
+ elif isinstance (a, sympy.EmptySet):
404
402
return emptyset()
405
- elif isinstance (a, sympy.S.UniversalSet):
406
- return universalset()
407
403
elif isinstance (a, sympy.FiniteSet):
408
404
return finiteset(* (a.args))
409
405
elif isinstance (a, sympy.Contains):
@@ -414,8 +410,6 @@ def sympy2symengine(a, raise_error=False):
414
410
return set_intersection(* (a.args))
415
411
elif isinstance (a, sympy.Complement):
416
412
return set_complement(* (a.args))
417
- elif isinstance (a, sympy.ConditionSet):
418
- return conditionset(* (a.args))
419
413
elif isinstance (a, sympy.ImageSet):
420
414
return imageset(* (a.args))
421
415
elif isinstance (a, sympy.Function):
@@ -439,6 +433,8 @@ def sympy2symengine(a, raise_error=False):
439
433
return acsch(a.args[0 ])
440
434
elif isinstance (a, sympy.asech):
441
435
return asech(a.args[0 ])
436
+ elif isinstance (a, sympy.ConditionSet):
437
+ return conditionset(* (a.args))
442
438
443
439
if raise_error:
444
440
raise SympifyError(" sympy2symengine: Cannot convert '%r ' to a symengine type." % a)
@@ -1171,7 +1167,8 @@ class Not(Boolean):
1171
1167
1172
1168
def _sympy_ (self ):
1173
1169
import sympy
1174
- return sympy.Not(c2py(< RCP[const symengine.Basic]> (self .args[0 ])._sympy_()))
1170
+ s = self .args_as_sympy()[0 ]
1171
+ return sympy.Not(s)
1175
1172
1176
1173
1177
1174
class Xor (Boolean ):
@@ -2577,6 +2574,10 @@ class EmptySet(Set):
2577
2574
import sympy
2578
2575
return sympy.EmptySet()
2579
2576
2577
+ @property
2578
+ def func (self ):
2579
+ return self .__class__
2580
+
2580
2581
2581
2582
class UniversalSet (Set ):
2582
2583
@@ -2585,7 +2586,11 @@ class UniversalSet(Set):
2585
2586
2586
2587
def _sympy_ (self ):
2587
2588
import sympy
2588
- return sympy.UniversalSet()
2589
+ return sympy.S.UniversalSet
2590
+
2591
+ @property
2592
+ def func (self ):
2593
+ return self .__class__
2589
2594
2590
2595
2591
2596
class FiniteSet (Set ):
@@ -2633,19 +2638,12 @@ class ConditionSet(Set):
2633
2638
def __new__ (self , sym , condition ):
2634
2639
return conditionset(sym, condition)
2635
2640
2636
- def _sympy_ (self ):
2637
- import sympy
2638
- return sympy.ConditionSet(* [arg._sympy_() for arg in self .args])
2639
-
2640
2641
2641
2642
class ImageSet (Set ):
2642
2643
2643
2644
def __new__ (self , sym , expr , base ):
2644
2645
return imageset(sym, expr, base)
2645
2646
2646
- def _sympy_ (self ):
2647
- import sympy
2648
- return sympy.ImageSet(* [arg._sympy_() for arg in self .args])
2649
2647
2650
2648
2651
2649
cdef class MatrixBase:
@@ -3556,29 +3554,27 @@ def logical_or(*args):
3556
3554
s.insert(symengine.rcp_static_cast_Boolean(e_.thisptr))
3557
3555
return c2py(< RCP[const symengine.Basic]> (symengine.logical_or(s)))
3558
3556
3559
- def logical_nor (*args ):
3557
+ def Nor (*args ):
3560
3558
cdef symengine.set_boolean s
3561
3559
cdef Boolean e_
3562
3560
for e in args:
3563
3561
e_ = sympify(e)
3564
3562
s.insert(symengine.rcp_static_cast_Boolean(e_.thisptr))
3565
3563
return c2py(< RCP[const symengine.Basic]> (symengine.logical_nor(s)))
3566
3564
3567
- Nor = logical_nor
3568
-
3569
- def logical_nand (*args ):
3565
+ def Nand (*args ):
3570
3566
cdef symengine.set_boolean s
3571
3567
cdef Boolean e_
3572
3568
for e in args:
3573
3569
e_ = sympify(e)
3574
3570
s.insert(symengine.rcp_static_cast_Boolean(e_.thisptr))
3575
3571
return c2py(< RCP[const symengine.Basic]> (symengine.logical_nand(s)))
3576
3572
3577
- Nand = logical_nand
3578
-
3579
3573
def logical_not (x ):
3580
- cdef Boolean X = sympify(x)
3581
- return c2py(< RCP[const symengine.Basic]> (symengine.logical_not(symengine.rcp_static_cast_Boolean(X.thisptr))))
3574
+ cdef Basic x_ = sympify(x)
3575
+ require(x_, Boolean)
3576
+ cdef RCP[const symengine.Boolean] _x = symengine.rcp_static_cast_Boolean(x_.thisptr)
3577
+ return c2py(< RCP[const symengine.Basic]> (symengine.logical_not(_x)))
3582
3578
3583
3579
def logical_xor (*args ):
3584
3580
cdef symengine.vec_boolean v
@@ -3588,16 +3584,14 @@ def logical_xor(*args):
3588
3584
v.push_back(symengine.rcp_static_cast_Boolean(e_.thisptr))
3589
3585
return c2py(< RCP[const symengine.Basic]> (symengine.logical_xor(v)))
3590
3586
3591
- def logical_xnor (*args ):
3587
+ def Xnor (*args ):
3592
3588
cdef symengine.vec_boolean v
3593
3589
cdef Boolean e_
3594
3590
for e in args:
3595
3591
e_ = sympify(e)
3596
3592
v.push_back(symengine.rcp_static_cast_Boolean(e_.thisptr))
3597
3593
return c2py(< RCP[const symengine.Basic]> (symengine.logical_xnor(v)))
3598
3594
3599
- Xnor = logical_xnor
3600
-
3601
3595
def eval_double (x ):
3602
3596
cdef Basic X = sympify(x)
3603
3597
return c2py(< RCP[const symengine.Basic]> (symengine.real_double(symengine.eval_double(deref(X.thisptr)))))
@@ -3998,7 +3992,6 @@ def powermod(a, b, m):
3998
3992
cdef RCP[const symengine.Integer] m1 = symengine.rcp_static_cast_Integer(_m.thisptr)
3999
3993
cdef RCP[const symengine.Number] b1 = symengine.rcp_static_cast_Number(_b.thisptr)
4000
3994
cdef RCP[const symengine.Integer] root
4001
-
4002
3995
cdef cppbool ret_val = symengine.powermod(symengine.outArg_Integer(root), a1, b1, m1)
4003
3996
if ret_val == 0 :
4004
3997
return None
@@ -4405,6 +4398,10 @@ def piecewise(*v):
4405
4398
4406
4399
4407
4400
def interval (start , end , left_open = False , right_open = False ):
4401
+ if isinstance (start, NegativeInfinity):
4402
+ left_open = True
4403
+ if isinstance (end, Infinity):
4404
+ right_open = True
4408
4405
cdef Number start_ = sympify(start)
4409
4406
cdef Number end_ = sympify(end)
4410
4407
cdef cppbool left_open_ = left_open
@@ -4427,7 +4424,7 @@ def finiteset(*args):
4427
4424
cdef Basic e_
4428
4425
for e in args:
4429
4426
e_ = sympify(e)
4430
- s.insert(e_.thisptr)
4427
+ s.insert(< RCP[symengine.const_Basic] > ( e_.thisptr) )
4431
4428
return c2py(< RCP[const symengine.Basic]> (symengine.finiteset(s)))
4432
4429
4433
4430
@@ -4486,5 +4483,18 @@ def imageset(sym, expr, base):
4486
4483
cdef RCP[const symengine.Set] b = symengine.rcp_static_cast_Set(base_.thisptr)
4487
4484
return c2py(< RCP[const symengine.Basic]> (symengine.imageset(sym_.thisptr, expr_.thisptr, b)))
4488
4485
4486
+
4487
+ def solve (f , sym , domain = None ):
4488
+ cdef Basic f_ = sympify(f)
4489
+ cdef Basic sym_ = sympify(sym)
4490
+ require(sym_, Symbol)
4491
+ cdef RCP[const symengine.Symbol] x = symengine.rcp_static_cast_Symbol(sym_.thisptr)
4492
+ if domain is None :
4493
+ return c2py(< RCP[const symengine.Basic]> (symengine.solve(f_.thisptr, x)))
4494
+ cdef Set domain_ = sympify(domain)
4495
+ cdef RCP[const symengine.Set] d = symengine.rcp_static_cast_Set(domain_.thisptr)
4496
+ return c2py(< RCP[const symengine.Basic]> (symengine.solve(f_.thisptr, x, d)))
4497
+
4498
+
4489
4499
# Turn on nice stacktraces:
4490
4500
symengine.print_stack_on_segfault()
0 commit comments