Skip to content

Commit 9c5c632

Browse files
committed
Merge branch 'master' of github.com:symengine/symengine.py into 0.6.x
2 parents 1a8e604 + dd28416 commit 9c5c632

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

symengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ImmutableMatrix, ImmutableDenseMatrix, MutableDenseMatrix,
88
MatrixBase, Basic, DictBasic, symarray, series, diff, zeros,
99
eye, diag, ones, Derivative, Subs, expand, has_symbol,
10-
UndefFunction, Function, latex,
10+
UndefFunction, Function, UnevaluatedExpr, latex,
1111
have_numpy, true, false, Equality, Unequality, GreaterThan,
1212
LessThan, StrictGreaterThan, StrictLessThan, Eq, Ne, Ge, Le,
1313
Gt, Lt, And, Or, Not, Nand, Nor, Xor, Xnor, perfect_power, integer_nthroot,

symengine/lib/symengine.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ cdef extern from "<symengine/basic.h>" namespace "SymEngine":
307307
bool is_a_Complement "SymEngine::is_a<SymEngine::Complement>"(const Basic &b) nogil
308308
bool is_a_ConditionSet "SymEngine::is_a<SymEngine::ConditionSet>"(const Basic &b) nogil
309309
bool is_a_ImageSet "SymEngine::is_a<SymEngine::ImageSet>"(const Basic &b) nogil
310-
310+
bool is_a_UnevaluatedExpr "SymEngine::is_a<SymEngine::UnevaluatedExpr>"(const Basic &b) nogil
311311
bool is_a_Piecewise "SymEngine::is_a<SymEngine::Piecewise>"(const Basic &b) nogil
312312
bool is_a_Contains "SymEngine::is_a<SymEngine::Contains>"(const Basic &b) nogil
313313
bool is_a_And "SymEngine::is_a<SymEngine::And>"(const Basic &b) nogil
@@ -535,6 +535,7 @@ cdef extern from "<symengine/functions.h>" namespace "SymEngine":
535535
cdef rcp_const_basic conjugate(rcp_const_basic &x) nogil except+
536536
cdef rcp_const_basic log(rcp_const_basic &x) nogil except+
537537
cdef rcp_const_basic log(rcp_const_basic &x, rcp_const_basic &y) nogil except+
538+
cdef rcp_const_basic unevaluated_expr(rcp_const_basic &x) nogil except+
538539

539540
cdef cppclass Function(Basic):
540541
pass

symengine/lib/symengine_wrapper.pyx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ cdef object c2py(rcp_const_basic o):
245245
r = Boolean.__new__(Or)
246246
elif (symengine.is_a_Xor(deref(o))):
247247
r = Boolean.__new__(Xor)
248+
elif (symengine.is_a_UnevaluatedExpr(deref(o))):
249+
r = Function.__new__(UnevaluatedExpr)
248250
else:
249251
raise Exception("Unsupported SymEngine class.")
250252
r.thisptr = o
@@ -451,6 +453,8 @@ def sympy2symengine(a, raise_error=False):
451453
return imageset(*(a.args))
452454
elif isinstance(a, sympy.Function):
453455
return PyFunction(a, a.args, a.func, sympy_module)
456+
elif isinstance(a, sympy.UnevaluatedExpr):
457+
return UnevaluatedExpr(a.args[0])
454458
elif isinstance(a, sympy.MatrixBase):
455459
row, col = a.shape
456460
v = []
@@ -2571,6 +2575,24 @@ add = Add
25712575
mul = Mul
25722576

25732577

2578+
class UnevaluatedExpr(OneArgFunction):
2579+
def __new__(cls, x):
2580+
cdef Basic X = sympify(x)
2581+
return c2py(symengine.unevaluated_expr(X.thisptr))
2582+
2583+
@property
2584+
def is_number(self):
2585+
return self.args[0].is_number
2586+
2587+
@property
2588+
def is_integer(self):
2589+
return self.args[0].is_integer
2590+
2591+
@property
2592+
def is_finite(self):
2593+
return self.args[0].is_finite
2594+
2595+
25742596
class Abs(OneArgFunction):
25752597

25762598
@property

symengine/tests/test_functions.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rational, EulerGamma, Function, Subs, Derivative, LambertW, zeta, dirichlet_eta,
44
zoo, pi, KroneckerDelta, LeviCivita, erf, erfc, oo, lowergamma, uppergamma, exp,
55
loggamma, beta, polygamma, digamma, trigamma, sign, floor, ceiling, conjugate,
6-
nan, Float
6+
nan, Float, UnevaluatedExpr
77
)
88

99
import unittest
@@ -386,3 +386,17 @@ def test_ceiling():
386386
def test_conjugate():
387387
assert conjugate(pi) == pi
388388
assert conjugate(I) == -I
389+
390+
391+
def test_unevaluated_expr():
392+
x = Symbol("x")
393+
t = UnevaluatedExpr(x)
394+
assert x + t != 2 * x
395+
assert not t.is_number
396+
assert not t.is_integer
397+
assert not t.is_finite
398+
399+
t = UnevaluatedExpr(1)
400+
assert t.is_number
401+
assert t.is_integer
402+
assert t.is_finite

symengine/tests/test_sympy_conv.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exp, gamma, have_mpfr, have_mpc, DenseMatrix, sin, cos, tan, cot,
44
csc, sec, asin, acos, atan, acot, acsc, asec, sinh, cosh, tanh, coth,
55
asinh, acosh, atanh, acoth, Add, Mul, Pow, diff, GoldenRatio,
6-
Catalan, EulerGamma)
6+
Catalan, EulerGamma, UnevaluatedExpr)
77
from symengine.lib.symengine_wrapper import (Subs, Derivative, RealMPFR,
88
ComplexMPC, PyNumber, Function, LambertW, zeta, dirichlet_eta,
99
KroneckerDelta, LeviCivita, erf, erfc, lowergamma, uppergamma,
@@ -651,6 +651,15 @@ def test_conjugate():
651651
assert e2._sympy_() == e1
652652

653653

654+
@unittest.skipIf(not have_sympy, "SymPy not installed")
655+
def test_unevaluated_expr():
656+
x = Symbol("x")
657+
e1 = sympy.UnevaluatedExpr(sympy.Symbol("x"))
658+
e2 = UnevaluatedExpr(x)
659+
assert sympify(e1) == e2
660+
assert e2._sympy_() == e1
661+
662+
654663
@unittest.skipIf(not have_sympy, "SymPy not installed")
655664
def test_logic():
656665
x = true

symengine_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.6.0
1+
fbd501264a86b7452ec35bb0370fbabc6d83b5c6

0 commit comments

Comments
 (0)