symengine 0.14.0__cp313-cp313t-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. symengine/lib/flint-19.dll +0 -0
  2. symengine/lib/libgcc_s_seh-1.dll +0 -0
  3. symengine/lib/libgmp-10.dll +0 -0
  4. symengine/lib/libmpc-3.dll +0 -0
  5. symengine/lib/libmpfr-6.dll +0 -0
  6. symengine/lib/libwinpthread-1.dll +0 -0
  7. symengine/lib/pywrapper.h +220 -0
  8. symengine/lib/symengine.pxd +955 -0
  9. symengine/lib/symengine_wrapper.cp313t-win_amd64.lib +0 -0
  10. symengine/lib/symengine_wrapper.cp313t-win_amd64.pyd +0 -0
  11. symengine/lib/symengine_wrapper.pxd +78 -0
  12. symengine/lib/zlib.dll +0 -0
  13. symengine/lib/zstd.dll +0 -0
  14. symengine-0.14.0.data/purelib/symengine/__init__.py +79 -0
  15. symengine-0.14.0.data/purelib/symengine/functions.py +10 -0
  16. symengine-0.14.0.data/purelib/symengine/lib/__init__.py +0 -0
  17. symengine-0.14.0.data/purelib/symengine/printing.py +33 -0
  18. symengine-0.14.0.data/purelib/symengine/sympy_compat.py +4 -0
  19. symengine-0.14.0.data/purelib/symengine/test_utilities.py +95 -0
  20. symengine-0.14.0.data/purelib/symengine/tests/__init__.py +0 -0
  21. symengine-0.14.0.data/purelib/symengine/tests/test_arit.py +261 -0
  22. symengine-0.14.0.data/purelib/symengine/tests/test_cse.py +17 -0
  23. symengine-0.14.0.data/purelib/symengine/tests/test_dict_basic.py +28 -0
  24. symengine-0.14.0.data/purelib/symengine/tests/test_eval.py +67 -0
  25. symengine-0.14.0.data/purelib/symengine/tests/test_expr.py +28 -0
  26. symengine-0.14.0.data/purelib/symengine/tests/test_functions.py +432 -0
  27. symengine-0.14.0.data/purelib/symengine/tests/test_lambdify.py +863 -0
  28. symengine-0.14.0.data/purelib/symengine/tests/test_logic.py +124 -0
  29. symengine-0.14.0.data/purelib/symengine/tests/test_matrices.py +757 -0
  30. symengine-0.14.0.data/purelib/symengine/tests/test_ntheory.py +254 -0
  31. symengine-0.14.0.data/purelib/symengine/tests/test_number.py +186 -0
  32. symengine-0.14.0.data/purelib/symengine/tests/test_pickling.py +59 -0
  33. symengine-0.14.0.data/purelib/symengine/tests/test_printing.py +38 -0
  34. symengine-0.14.0.data/purelib/symengine/tests/test_sage.py +175 -0
  35. symengine-0.14.0.data/purelib/symengine/tests/test_series_expansion.py +22 -0
  36. symengine-0.14.0.data/purelib/symengine/tests/test_sets.py +118 -0
  37. symengine-0.14.0.data/purelib/symengine/tests/test_solve.py +25 -0
  38. symengine-0.14.0.data/purelib/symengine/tests/test_subs.py +82 -0
  39. symengine-0.14.0.data/purelib/symengine/tests/test_symbol.py +179 -0
  40. symengine-0.14.0.data/purelib/symengine/tests/test_sympify.py +63 -0
  41. symengine-0.14.0.data/purelib/symengine/tests/test_sympy_compat.py +200 -0
  42. symengine-0.14.0.data/purelib/symengine/tests/test_sympy_conv.py +835 -0
  43. symengine-0.14.0.data/purelib/symengine/tests/test_var.py +68 -0
  44. symengine-0.14.0.data/purelib/symengine/utilities.py +280 -0
  45. symengine-0.14.0.dist-info/AUTHORS +40 -0
  46. symengine-0.14.0.dist-info/LICENSE +430 -0
  47. symengine-0.14.0.dist-info/METADATA +39 -0
  48. symengine-0.14.0.dist-info/RECORD +50 -0
  49. symengine-0.14.0.dist-info/WHEEL +5 -0
  50. symengine-0.14.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,22 @@
1
+ from symengine.test_utilities import raises
2
+ from symengine.lib.symengine_wrapper import (series, have_piranha, have_flint,
3
+ Symbol, Integer, sin, cos, exp, sqrt, E)
4
+
5
+
6
+ def test_series_expansion():
7
+ x = Symbol('x')
8
+ ex = series(sin(1+x), x, n=10)
9
+ assert ex.coeff(x, 7) == -cos(1)/5040
10
+
11
+ x = Symbol('x')
12
+ ex = series(1/(1-x), x, n=10)
13
+ assert ex.coeff(x, 9) == 1
14
+ ex = series(sin(x)*cos(x), x, n=10)
15
+ assert ex.coeff(x, 8) == 0
16
+ assert ex.coeff(x, 9) == Integer(2)/Integer(2835)
17
+
18
+ ex = series(E**x, x, n=10)
19
+ assert ex.coeff(x, 9) == Integer(1)/Integer(362880)
20
+ ex1 = series(1/sqrt(4-x), x, n=50)
21
+ ex2 = series((4-x)**(Integer(-1)/Integer(2)), x, n=50)
22
+ assert ex1.coeff(x, 49) == ex2.coeff(x, 49)
@@ -0,0 +1,118 @@
1
+ from symengine.test_utilities import raises
2
+ from symengine.lib.symengine_wrapper import (Interval, EmptySet, UniversalSet,
3
+ FiniteSet, Union, Complement, ImageSet, ConditionSet, Reals, Rationals,
4
+ Integers, And, Or, oo, Symbol, true, Ge, Eq, Gt)
5
+
6
+
7
+ def test_Interval():
8
+ assert Interval(0, oo) == Interval(0, oo, False, True)
9
+ assert Interval(0, oo) == Interval(0, oo, left_open=False, right_open=True)
10
+ assert Interval(-oo, 0) == Interval(-oo, 0, True, False)
11
+ assert Interval(-oo, 0) == Interval(-oo, 0, left_open=True, right_open=False)
12
+ assert Interval(oo, -oo) == EmptySet()
13
+ assert Interval(oo, oo) == EmptySet()
14
+ assert Interval(-oo, -oo) == EmptySet()
15
+ assert isinstance(Interval(1, 1), FiniteSet)
16
+
17
+ assert Interval(1, 0) == EmptySet()
18
+ assert Interval(1, 1, False, True) == EmptySet()
19
+ assert Interval(1, 1, True, False) == EmptySet()
20
+ assert Interval(1, 1, True, True) == EmptySet()
21
+ assert Interval(1, 2).union(Interval(2, 3)) == Interval(1, 3)
22
+
23
+ assert Interval(-oo, 0).start == -oo
24
+ assert Interval(-oo, 0).end == 0
25
+
26
+
27
+ def test_EmptySet():
28
+ E = EmptySet()
29
+ assert E.intersection(UniversalSet()) == E
30
+
31
+
32
+ def test_UniversalSet():
33
+ U = UniversalSet()
34
+ x = Symbol("x")
35
+ assert U.union(Interval(2, 4)) == U
36
+ assert U.intersection(Interval(2, 4)) == Interval(2, 4)
37
+ assert U.contains(0) == true
38
+
39
+
40
+ def test_Reals():
41
+ R = Reals()
42
+ assert R.union(Interval(2, 4)) == R
43
+ assert R.contains(0) == true
44
+
45
+
46
+ def test_Rationals():
47
+ Q = Rationals()
48
+ assert Q.union(FiniteSet(2, 3)) == Q
49
+ assert Q.contains(0) == true
50
+
51
+
52
+ def test_Integers():
53
+ Z = Integers()
54
+ assert Z.union(FiniteSet(2, 4)) == Z
55
+ assert Z.contains(0) == true
56
+
57
+
58
+ def test_FiniteSet():
59
+ x = Symbol("x")
60
+ A = FiniteSet(1, 2, 3)
61
+ B = FiniteSet(3, 4, 5)
62
+ AorB = Union(A, B)
63
+ AandB = A.intersection(B)
64
+ assert AandB == FiniteSet(3)
65
+
66
+ assert FiniteSet(EmptySet()) != EmptySet()
67
+ assert FiniteSet(FiniteSet(1, 2, 3)) != FiniteSet(1, 2, 3)
68
+
69
+
70
+ def test_Union():
71
+ assert Union(Interval(1, 2), Interval(2, 3)) == Interval(1, 3)
72
+ assert Union(Interval(1, 2), Interval(2, 3, True)) == Interval(1, 3)
73
+ assert Union(Interval(1, 3), Interval(2, 4)) == Interval(1, 4)
74
+ assert Union(Interval(1, 2), Interval(1, 3)) == Interval(1, 3)
75
+ assert Union(Interval(1, 3), Interval(1, 2)) == Interval(1, 3)
76
+ assert Union(Interval(1, 3, False, True), Interval(1, 2)) == \
77
+ Interval(1, 3, False, True)
78
+ assert Union(Interval(1, 3), Interval(1, 2, False, True)) == Interval(1, 3)
79
+ assert Union(Interval(1, 2, True), Interval(1, 3)) == Interval(1, 3)
80
+ assert Union(Interval(1, 2, True), Interval(1, 3, True)) == \
81
+ Interval(1, 3, True)
82
+ assert Union(Interval(1, 2, True), Interval(1, 3, True, True)) == \
83
+ Interval(1, 3, True, True)
84
+ assert Union(Interval(1, 2, True, True), Interval(1, 3, True)) == \
85
+ Interval(1, 3, True)
86
+ assert Union(Interval(1, 3), Interval(2, 3)) == Interval(1, 3)
87
+ assert Union(Interval(1, 3, False, True), Interval(2, 3)) == \
88
+ Interval(1, 3)
89
+ assert Union(Interval(1, 2, False, True), Interval(2, 3, True)) != \
90
+ Interval(1, 3)
91
+ assert Union(Interval(1, 2), EmptySet()) == Interval(1, 2)
92
+ assert Union(EmptySet()) == EmptySet()
93
+
94
+
95
+ def test_Complement():
96
+ assert Complement(Interval(1, 3), Interval(1, 2)) == Interval(2, 3, True)
97
+ assert Complement(FiniteSet(1, 3, 4), FiniteSet(3, 4)) == FiniteSet(1)
98
+ assert Complement(Union(Interval(0, 2),
99
+ FiniteSet(2, 3, 4)), Interval(1, 3)) == \
100
+ Union(Interval(0, 1, False, True), FiniteSet(4))
101
+
102
+
103
+ def test_ConditionSet():
104
+ x = Symbol("x")
105
+ i1 = Interval(-oo, oo)
106
+ f1 = FiniteSet(0, 1, 2, 4)
107
+ cond1 = Ge(x**2, 9)
108
+ assert ConditionSet(x, And(Eq(0, 1), i1.contains(x))) == EmptySet()
109
+ assert ConditionSet(x, And(Gt(1, 0), i1.contains(x))) == i1
110
+ assert ConditionSet(x, And(cond1, f1.contains(x))) == FiniteSet(4)
111
+
112
+
113
+ def test_ImageSet():
114
+ x = Symbol("x")
115
+ i1 = Interval(0, 1)
116
+ assert ImageSet(x, x**2, EmptySet()) == EmptySet()
117
+ assert ImageSet(x, 1, i1) == FiniteSet(1)
118
+ assert ImageSet(x, x, i1) == i1
@@ -0,0 +1,25 @@
1
+ from symengine.test_utilities import raises
2
+ from symengine import (Interval, EmptySet, FiniteSet, I, oo, Eq, Symbol,
3
+ linsolve)
4
+ from symengine.lib.symengine_wrapper import solve
5
+
6
+ def test_solve():
7
+ x = Symbol("x")
8
+ reals = Interval(-oo, oo)
9
+
10
+ assert solve(1, x, reals) == EmptySet
11
+ assert solve(0, x, reals) == reals
12
+ assert solve(x + 3, x, reals) == FiniteSet(-3)
13
+ assert solve(x + 3, x, Interval(0, oo)) == EmptySet
14
+ assert solve(x, x, reals) == FiniteSet(0)
15
+ assert solve(x**2 + 1, x) == FiniteSet(-I, I)
16
+ assert solve(x**2 - 2*x + 1, x) == FiniteSet(1)
17
+ assert solve(Eq(x**3 + 3*x**2 + 3*x, -1), x, reals) == FiniteSet(-1)
18
+ assert solve(x**3 - x, x) == FiniteSet(0, 1, -1)
19
+
20
+ def test_linsolve():
21
+ x = Symbol("x")
22
+ y = Symbol("y")
23
+ assert linsolve([x - 2], [x]) == (2,)
24
+ assert linsolve([x - 2, y - 3], [x, y]) == (2, 3)
25
+ assert linsolve([x + y - 3, x + 2*y - 4], [x, y]) == (2, 1)
@@ -0,0 +1,82 @@
1
+ import unittest
2
+
3
+ from symengine.test_utilities import raises
4
+ from symengine import Symbol, sin, cos, sqrt, Add, function_symbol, have_numpy, log
5
+
6
+
7
+ def test_basic():
8
+ x = Symbol("x")
9
+ y = Symbol("y")
10
+ z = Symbol("z")
11
+ e = x+y+z
12
+ assert e.subs({x: y, z: y}) == 3*y
13
+
14
+
15
+ def test_sin():
16
+ x = Symbol("x")
17
+ y = Symbol("y")
18
+ e = sin(x)
19
+ assert e.subs({x: y}) == sin(y)
20
+ assert e.subs({x: y}) != sin(x)
21
+
22
+ e = cos(x)
23
+ assert e.subs({x: 0}) == 1
24
+ assert e.subs(x, 0) == 1
25
+
26
+
27
+ def test_subs_exception():
28
+ x = Symbol("x")
29
+ expr = sin(log(x))
30
+ raises(RuntimeError, lambda: expr.subs({x: 0}))
31
+
32
+
33
+ def test_args():
34
+ x = Symbol("x")
35
+ e = cos(x)
36
+ raises(TypeError, lambda: e.subs(x, 0, 3))
37
+
38
+
39
+ def test_f():
40
+ x = Symbol("x")
41
+ y = Symbol("y")
42
+ f = function_symbol("f", x)
43
+ g = function_symbol("g", x)
44
+ assert f.subs({function_symbol("f", x): function_symbol("g", x)}) == g
45
+ assert ((f+g).subs({function_symbol("f", x): function_symbol("g", x)}) ==
46
+ 2*g)
47
+
48
+ e = (f+x)**3
49
+ assert e.subs({f: y}) == (x+y)**3
50
+ e = e.expand()
51
+ assert e.subs({f: y}) == ((x+y)**3).expand()
52
+
53
+
54
+ def test_msubs():
55
+ x = Symbol("x")
56
+ y = Symbol("y")
57
+ f = function_symbol("f", x)
58
+ assert f.msubs({f: y}) == y
59
+ assert f.diff(x).msubs({f: y}) == f.diff(x)
60
+
61
+
62
+ def test_xreplace():
63
+ x = Symbol("x")
64
+ y = Symbol("y")
65
+ f = sin(cos(x))
66
+ assert f.xreplace({x: y}) == sin(cos(y))
67
+
68
+
69
+ @unittest.skipUnless(have_numpy, "Numpy not installed")
70
+ def test_float32():
71
+ import numpy as np
72
+ x = Symbol("x")
73
+ expr = x * 2
74
+ assert expr.subs({x: np.float32(2)}) == 4.0
75
+
76
+
77
+ @unittest.skipUnless(have_numpy, "Numpy not installed")
78
+ def test_float16():
79
+ import numpy as np
80
+ x = Symbol("x")
81
+ expr = x * 2
82
+ assert expr.subs({x: np.float16(2)}) == 4.0
@@ -0,0 +1,179 @@
1
+ from symengine import Symbol, symbols, symarray, has_symbol, Dummy
2
+ from symengine.test_utilities import raises
3
+ import unittest
4
+ import platform
5
+
6
+
7
+ def test_symbol():
8
+ x = Symbol("x")
9
+ assert x.name == "x"
10
+ assert str(x) == "x"
11
+ assert str(x) != "y"
12
+ assert repr(x) == str(x)
13
+
14
+
15
+ def test_symbols():
16
+ x = Symbol('x')
17
+ y = Symbol('y')
18
+ z = Symbol('z')
19
+
20
+ assert symbols('x') == x
21
+ assert symbols('x ') == x
22
+ assert symbols(' x ') == x
23
+ assert symbols('x,') == (x,)
24
+ assert symbols('x, ') == (x,)
25
+ assert symbols('x ,') == (x,)
26
+
27
+ assert symbols('x , y') == (x, y)
28
+
29
+ assert symbols('x,y,z') == (x, y, z)
30
+ assert symbols('x y z') == (x, y, z)
31
+
32
+ assert symbols('x,y,z,') == (x, y, z)
33
+ assert symbols('x y z ') == (x, y, z)
34
+
35
+ xyz = Symbol('xyz')
36
+ abc = Symbol('abc')
37
+
38
+ assert symbols('xyz') == xyz
39
+ assert symbols('xyz,') == (xyz,)
40
+ assert symbols('xyz,abc') == (xyz, abc)
41
+
42
+ assert symbols(('xyz',)) == (xyz,)
43
+ assert symbols(('xyz,',)) == ((xyz,),)
44
+ assert symbols(('x,y,z,',)) == ((x, y, z),)
45
+ assert symbols(('xyz', 'abc')) == (xyz, abc)
46
+ assert symbols(('xyz,abc',)) == ((xyz, abc),)
47
+ assert symbols(('xyz,abc', 'x,y,z')) == ((xyz, abc), (x, y, z))
48
+
49
+ assert symbols(('x', 'y', 'z')) == (x, y, z)
50
+ assert symbols(['x', 'y', 'z']) == [x, y, z]
51
+ assert symbols({'x', 'y', 'z'}) == {x, y, z}
52
+
53
+ raises(ValueError, lambda: symbols(''))
54
+ raises(ValueError, lambda: symbols(','))
55
+ raises(ValueError, lambda: symbols('x,,y,,z'))
56
+ raises(ValueError, lambda: symbols(('x', '', 'y', '', 'z')))
57
+
58
+ x0 = Symbol('x0')
59
+ x1 = Symbol('x1')
60
+ x2 = Symbol('x2')
61
+
62
+ y0 = Symbol('y0')
63
+ y1 = Symbol('y1')
64
+
65
+ assert symbols('x0:0') == ()
66
+ assert symbols('x0:1') == (x0,)
67
+ assert symbols('x0:2') == (x0, x1)
68
+ assert symbols('x0:3') == (x0, x1, x2)
69
+
70
+ assert symbols('x:0') == ()
71
+ assert symbols('x:1') == (x0,)
72
+ assert symbols('x:2') == (x0, x1)
73
+ assert symbols('x:3') == (x0, x1, x2)
74
+
75
+ assert symbols('x1:1') == ()
76
+ assert symbols('x1:2') == (x1,)
77
+ assert symbols('x1:3') == (x1, x2)
78
+
79
+ assert symbols('x1:3,x,y,z') == (x1, x2, x, y, z)
80
+
81
+ assert symbols('x:3,y:2') == (x0, x1, x2, y0, y1)
82
+ assert symbols(('x:3', 'y:2')) == ((x0, x1, x2), (y0, y1))
83
+
84
+ a = Symbol('a')
85
+ b = Symbol('b')
86
+ c = Symbol('c')
87
+ d = Symbol('d')
88
+
89
+ assert symbols('x:z') == (x, y, z)
90
+ assert symbols('a:d,x:z') == (a, b, c, d, x, y, z)
91
+ assert symbols(('a:d', 'x:z')) == ((a, b, c, d), (x, y, z))
92
+
93
+ aa = Symbol('aa')
94
+ ab = Symbol('ab')
95
+ ac = Symbol('ac')
96
+ ad = Symbol('ad')
97
+
98
+ assert symbols('aa:d') == (aa, ab, ac, ad)
99
+ assert symbols('aa:d,x:z') == (aa, ab, ac, ad, x, y, z)
100
+ assert symbols(('aa:d', 'x:z')) == ((aa, ab, ac, ad), (x, y, z))
101
+
102
+ def sym(s):
103
+ return str(symbols(s))
104
+ assert sym('a0:4') == '(a0, a1, a2, a3)'
105
+ assert sym('a2:4,b1:3') == '(a2, a3, b1, b2)'
106
+ assert sym('a1(2:4)') == '(a12, a13)'
107
+ assert sym('a0:2.0:2') == '(a0.0, a0.1, a1.0, a1.1)'
108
+ assert sym('aa:cz') == '(aaz, abz, acz)'
109
+ assert sym('aa:c0:2') == '(aa0, aa1, ab0, ab1, ac0, ac1)'
110
+ assert sym('aa:ba:b') == '(aaa, aab, aba, abb)'
111
+ assert sym('a:3b') == '(a0b, a1b, a2b)'
112
+ assert sym('a-1:3b') == '(a-1b, a-2b)'
113
+ assert sym(r'a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
114
+ (chr(0),)*4)
115
+ assert sym('x(:a:3)') == '(x(a0), x(a1), x(a2))'
116
+ assert sym('x(:c):1') == '(xa0, xb0, xc0)'
117
+ assert sym('x((:a)):3') == '(x(a)0, x(a)1, x(a)2)'
118
+ assert sym('x(:a:3') == '(x(a0, x(a1, x(a2)'
119
+ assert sym(':2') == '(0, 1)'
120
+ assert sym(':b') == '(a, b)'
121
+ assert sym(':b:2') == '(a0, a1, b0, b1)'
122
+ assert sym(':2:2') == '(00, 01, 10, 11)'
123
+ assert sym(':b:b') == '(aa, ab, ba, bb)'
124
+
125
+ raises(ValueError, lambda: symbols(':'))
126
+ raises(ValueError, lambda: symbols('a:'))
127
+ raises(ValueError, lambda: symbols('::'))
128
+ raises(ValueError, lambda: symbols('a::'))
129
+ raises(ValueError, lambda: symbols(':a:'))
130
+ raises(ValueError, lambda: symbols('::a'))
131
+
132
+
133
+ def test_symarray():
134
+ try:
135
+ import numpy as np
136
+ except ImportError:
137
+ return
138
+ x0, x1, x2 = arr = symarray('x', 3)
139
+ assert arr.shape == (3,)
140
+
141
+ assert symarray('y', (2, 3)).shape == (2, 3)
142
+
143
+
144
+ def test_has_symbol():
145
+ a = Symbol('a')
146
+ b = Symbol('b')
147
+ c = Symbol('c')
148
+
149
+ assert not has_symbol(2, a)
150
+ assert not has_symbol(c, a)
151
+ assert has_symbol(a+b, b)
152
+
153
+
154
+ def test_dummy():
155
+ x1 = Symbol('x')
156
+ x2 = Symbol('x')
157
+ xdummy1 = Dummy('x')
158
+ xdummy2 = Dummy('x')
159
+
160
+ assert x1 == x2
161
+ assert x1 != xdummy1
162
+ assert xdummy1 == (xdummy1 + 1) - 1
163
+ assert xdummy1 != xdummy2
164
+ assert Dummy() != Dummy()
165
+ assert Dummy('x') != Dummy('x')
166
+
167
+ # Cython cdef classes on PyPy has a __dict__ attribute always
168
+ # __slots__ on PyPy are useless anyways. https://stackoverflow.com/a/23077685/4768820
169
+ @unittest.skipUnless(platform.python_implementation()=="CPython", "__slots__ are useless on PyPy")
170
+ def test_slots():
171
+ x = Dummy('x')
172
+ # Verify the successful use of slots.
173
+ assert not hasattr(x, "__dict__")
174
+ assert not hasattr(x, "__weakref__")
175
+
176
+ x1 = Symbol('x')
177
+ # Verify the successful use of slots.
178
+ assert not hasattr(x, "__dict__")
179
+ assert not hasattr(x, "__weakref__")
@@ -0,0 +1,63 @@
1
+ from symengine.test_utilities import raises
2
+
3
+ from symengine import (Symbol, Integer, sympify, SympifyError, true, false, pi, nan, oo,
4
+ zoo, E, I, GoldenRatio, Catalan, Rational, sqrt, Eq)
5
+ from symengine.lib.symengine_wrapper import _sympify, S, One, polygamma
6
+
7
+
8
+ def test_sympify1():
9
+ assert sympify(1) == Integer(1)
10
+ assert sympify(2) != Integer(1)
11
+ assert sympify(-5) == Integer(-5)
12
+ assert sympify(Integer(3)) == Integer(3)
13
+ assert sympify(('0', '0')) == (0, 0)
14
+ assert sympify(['0', '0']) == [0, 0]
15
+ assert sympify("3+5") == Integer(8)
16
+ assert true == sympify(True)
17
+ assert false == sympify(False)
18
+
19
+
20
+ def test_S():
21
+ assert S(0) == Integer(0)
22
+ assert S(1) == Integer(1)
23
+ assert S(-1) == Integer(-1)
24
+ assert S(1) / 2 == Rational(1, 2)
25
+ assert S.One is S(1)
26
+ assert S.Zero is S(0)
27
+ assert S.NegativeOne is S(-1)
28
+ assert S.Half is S(1) / 2
29
+ assert S.Pi is pi
30
+ assert S.NaN is S(0) / 0
31
+ assert S.Infinity is -oo * -10
32
+ assert S.NegativeInfinity is oo * (-3)
33
+ assert S.ComplexInfinity is zoo
34
+ assert S.Exp1 is (E + 1 - 1)
35
+ assert S.ImaginaryUnit is sqrt(-1)
36
+ assert S.GoldenRatio * 2 / 2 is GoldenRatio
37
+ assert S.Catalan * 1 is Catalan
38
+ assert S.EulerGamma is polygamma(0, 1) * -1
39
+ assert S.true is Eq(2, 2)
40
+ assert S.false is Eq(2, 3)
41
+ assert S(1) / 0 is zoo
42
+ assert S.Pi * 1 is pi
43
+ assert type(S.One) == One
44
+
45
+
46
+ def test_sympify_error1a():
47
+ class Test:
48
+ pass
49
+ raises(SympifyError, lambda: sympify(Test()))
50
+
51
+
52
+ def test_sympify_error1b():
53
+ assert not _sympify("1***2", raise_error=False)
54
+
55
+
56
+ def test_error1():
57
+ # _sympify doesn't parse strings
58
+ raises(SympifyError, lambda: _sympify("x"))
59
+
60
+
61
+ def test_sympify_pow():
62
+ # https://github.com/symengine/symengine.py/issues/251
63
+ assert sympify('y*pow(x, -1)') == Symbol('y')/Symbol('x')
@@ -0,0 +1,200 @@
1
+ from symengine.sympy_compat import (Integer, Rational, S, Basic, Add, Mul,
2
+ Pow, symbols, Symbol, log, sin, cos, sech, csch, zeros, atan2, nan, Number, Float,
3
+ Min, Max, RealDouble, have_mpfr, Abs)
4
+ from symengine.test_utilities import raises
5
+
6
+
7
+ def test_Integer():
8
+ i = Integer(5)
9
+ assert isinstance(i, Integer)
10
+ assert isinstance(i, Rational)
11
+ assert isinstance(i, Number)
12
+ assert isinstance(i, Basic)
13
+ assert i.p == 5
14
+ assert i.q == 1
15
+
16
+
17
+ def test_Rational():
18
+ i = S(1)/2
19
+ assert isinstance(i, Rational)
20
+ assert isinstance(i, Number)
21
+ assert isinstance(i, Basic)
22
+ assert i.p == 1
23
+ assert i.q == 2
24
+ x = symbols("x")
25
+ assert not isinstance(x, Rational)
26
+ assert not isinstance(x, Number)
27
+
28
+
29
+ def test_Float():
30
+ A = Float("1.23", precision = 53)
31
+ B = Float("1.23")
32
+ C = Float(A)
33
+ assert A == B == C
34
+ assert isinstance(A, Float)
35
+ assert isinstance(B, Float)
36
+ assert isinstance(C, Float)
37
+ assert isinstance(A, RealDouble)
38
+ assert isinstance(B, RealDouble)
39
+ assert isinstance(C, RealDouble)
40
+ raises(ValueError, lambda: Float("1.23", dps = 3, precision = 10))
41
+ raises(ValueError, lambda: Float(A, dps = 3, precision = 16))
42
+ if have_mpfr:
43
+ from symengine.sympy_compat import RealMPFR
44
+ A = Float("1.23", dps = 16)
45
+ B = Float("1.23", precision = 56)
46
+ assert A == B
47
+ assert isinstance(A, Float)
48
+ assert isinstance(B, Float)
49
+ assert isinstance(A, RealMPFR)
50
+ assert isinstance(B, RealMPFR)
51
+ A = Float(C, dps = 16)
52
+ assert A == B
53
+ assert isinstance(A, Float)
54
+ assert isinstance(A, RealMPFR)
55
+ A = Float(A, precision = 53)
56
+ assert A == C
57
+ assert isinstance(A, Float)
58
+ assert isinstance(A, RealDouble)
59
+ if not have_mpfr:
60
+ raises(ValueError, lambda: Float("1.23", precision = 58))
61
+
62
+
63
+ def test_Add():
64
+ x, y = symbols("x y")
65
+ i = Add(x, x)
66
+ assert isinstance(i, Mul)
67
+ i = Add(x, y)
68
+ assert isinstance(i, Add)
69
+ assert isinstance(i, Basic)
70
+ assert i.func(y, x) == i
71
+
72
+
73
+ def test_Mul():
74
+ x, y = symbols("x y")
75
+ i = Mul(x, x)
76
+ assert isinstance(i, Pow)
77
+ i = Mul(x, y)
78
+ assert isinstance(i, Mul)
79
+ assert isinstance(i, Basic)
80
+ assert i.func(y, x) == i
81
+
82
+
83
+ def test_Pow():
84
+ x = symbols("x")
85
+ i = Pow(x, 1)
86
+ assert isinstance(i, Symbol)
87
+ i = Pow(x, 2)
88
+ assert isinstance(i, Pow)
89
+ assert isinstance(i, Basic)
90
+ assert i.func(x, 2) == i
91
+
92
+
93
+ def test_Max():
94
+ x = Symbol("x")
95
+ y = Symbol("y")
96
+ z = Symbol("z")
97
+ assert Max(Integer(6)/3, 1) == 2
98
+ assert Max(-2, 2) == 2
99
+ assert Max(2, 2) == 2
100
+ assert Max(0.2, 0.3) == 0.3
101
+ assert Max(x, x) == x
102
+ assert Max(x, y) == Max(y, x)
103
+ assert Max(x, y, z) == Max(z, y, x)
104
+ assert Max(x, Max(y, z)) == Max(z, y, x)
105
+ assert Max(1000, 100, -100, x, y, z) == Max(x, y, z, 1000)
106
+ assert Max(cos(x), sin(x)) == Max(sin(x), cos(x))
107
+
108
+
109
+ def test_Min():
110
+ x = Symbol("x")
111
+ y = Symbol("y")
112
+ z = Symbol("z")
113
+ assert Min(Integer(6)/3, 1) == 1
114
+ assert Min(-2, 2) == -2
115
+ assert Min(2, 2) == 2
116
+ assert Min(0.2, 0.3) == 0.2
117
+ assert Min(x, x) == x
118
+ assert Min(x, y) == Min(y, x)
119
+ assert Min(x, y, z) == Min(z, y, x)
120
+ assert Min(x, Min(y, z)) == Min(z, y, x)
121
+ assert Min(1000, 100, -100, x, y, z) == Min(x, y, z, -100)
122
+ assert Min(cos(x), sin(x)) == Min(cos(x), sin(x))
123
+
124
+
125
+ def test_NaN():
126
+ type(nan)() == nan
127
+
128
+
129
+ def test_sin():
130
+ x = symbols("x")
131
+ i = sin(0)
132
+ assert isinstance(i, Integer)
133
+ i = sin(x)
134
+ assert isinstance(i, sin)
135
+
136
+
137
+ def test_sech():
138
+ x = symbols("x")
139
+ i = sech(0)
140
+ assert isinstance(i, Integer)
141
+ i = sech(x)
142
+ assert isinstance(i, sech)
143
+
144
+
145
+ def test_csch():
146
+ x = symbols("x")
147
+ i = csch(x)
148
+ assert isinstance(i, csch)
149
+ i = csch(-1)
150
+ j = csch(1)
151
+ assert i == -j
152
+
153
+
154
+ def test_log():
155
+ x, y = symbols("x y")
156
+ i = log(x, y)
157
+ assert isinstance(i, Mul)
158
+ i = log(x)
159
+ assert isinstance(i, log)
160
+
161
+
162
+ def test_ATan2():
163
+ x, y = symbols("x y")
164
+ i = atan2(x, y)
165
+ assert isinstance(i, atan2)
166
+ i = atan2(0, 1)
167
+ assert i == 0
168
+
169
+
170
+ def test_zeros():
171
+ assert zeros(3, c=2).shape == (3, 2)
172
+
173
+
174
+ def test_has_functions_module():
175
+ import symengine.sympy_compat as sp
176
+ assert sp.functions.sin(0) == 0
177
+
178
+
179
+ def test_subclass_symbol():
180
+ # Subclass of Symbol with an extra attribute
181
+ class Wrapper(Symbol):
182
+ def __new__(cls, name, extra_attribute):
183
+ return Symbol.__new__(cls, name)
184
+
185
+ def __init__(self, name, extra_attribute):
186
+ super().__init__(name)
187
+ self.extra_attribute = extra_attribute
188
+
189
+ # Instantiate the subclass
190
+ x = Wrapper("x", extra_attribute=3)
191
+ assert x.extra_attribute == 3
192
+ two_x = 2 * x
193
+ # Check that after arithmetic, same subclass is returned
194
+ assert two_x.args[1] is x
195
+ del two_x
196
+ x._unsafe_reset()
197
+
198
+ def test_Abs():
199
+ x = symbols("x")
200
+ assert Abs(x) == Abs(-x)