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.
- symengine/lib/flint-19.dll +0 -0
- symengine/lib/libgcc_s_seh-1.dll +0 -0
- symengine/lib/libgmp-10.dll +0 -0
- symengine/lib/libmpc-3.dll +0 -0
- symengine/lib/libmpfr-6.dll +0 -0
- symengine/lib/libwinpthread-1.dll +0 -0
- symengine/lib/pywrapper.h +220 -0
- symengine/lib/symengine.pxd +955 -0
- symengine/lib/symengine_wrapper.cp313t-win_amd64.lib +0 -0
- symengine/lib/symengine_wrapper.cp313t-win_amd64.pyd +0 -0
- symengine/lib/symengine_wrapper.pxd +78 -0
- symengine/lib/zlib.dll +0 -0
- symengine/lib/zstd.dll +0 -0
- symengine-0.14.0.data/purelib/symengine/__init__.py +79 -0
- symengine-0.14.0.data/purelib/symengine/functions.py +10 -0
- symengine-0.14.0.data/purelib/symengine/lib/__init__.py +0 -0
- symengine-0.14.0.data/purelib/symengine/printing.py +33 -0
- symengine-0.14.0.data/purelib/symengine/sympy_compat.py +4 -0
- symengine-0.14.0.data/purelib/symengine/test_utilities.py +95 -0
- symengine-0.14.0.data/purelib/symengine/tests/__init__.py +0 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_arit.py +261 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_cse.py +17 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_dict_basic.py +28 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_eval.py +67 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_expr.py +28 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_functions.py +432 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_lambdify.py +863 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_logic.py +124 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_matrices.py +757 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_ntheory.py +254 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_number.py +186 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_pickling.py +59 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_printing.py +38 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sage.py +175 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_series_expansion.py +22 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sets.py +118 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_solve.py +25 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_subs.py +82 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_symbol.py +179 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sympify.py +63 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sympy_compat.py +200 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_sympy_conv.py +835 -0
- symengine-0.14.0.data/purelib/symengine/tests/test_var.py +68 -0
- symengine-0.14.0.data/purelib/symengine/utilities.py +280 -0
- symengine-0.14.0.dist-info/AUTHORS +40 -0
- symengine-0.14.0.dist-info/LICENSE +430 -0
- symengine-0.14.0.dist-info/METADATA +39 -0
- symengine-0.14.0.dist-info/RECORD +50 -0
- symengine-0.14.0.dist-info/WHEEL +5 -0
- symengine-0.14.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,254 @@
|
|
1
|
+
from symengine.test_utilities import raises
|
2
|
+
|
3
|
+
from symengine.lib.symengine_wrapper import (isprime, nextprime, gcd,
|
4
|
+
lcm, gcd_ext, mod, quotient, quotient_mod, mod_inverse, crt, fibonacci,
|
5
|
+
fibonacci2, lucas, lucas2, binomial, factorial, divides, factor,
|
6
|
+
factor_lehman_method, factor_pollard_pm1_method, factor_pollard_rho_method,
|
7
|
+
prime_factors, prime_factor_multiplicities, Sieve, Sieve_iterator,
|
8
|
+
bernoulli, primitive_root, primitive_root_list, totient, carmichael,
|
9
|
+
multiplicative_order, legendre, jacobi, kronecker, nthroot_mod,
|
10
|
+
nthroot_mod_list, powermod, powermod_list, Integer, sqrt_mod)
|
11
|
+
|
12
|
+
|
13
|
+
def test_probab_prime_p():
|
14
|
+
s = set(Sieve.generate_primes(1000))
|
15
|
+
for n in range(1001):
|
16
|
+
assert (n in s) == isprime(n)
|
17
|
+
|
18
|
+
|
19
|
+
def test_nextprime():
|
20
|
+
assert nextprime(-3) == 2
|
21
|
+
assert nextprime(5) == 7
|
22
|
+
assert nextprime(9) == 11
|
23
|
+
|
24
|
+
|
25
|
+
def test_gcd():
|
26
|
+
assert gcd(10, 14) == 2
|
27
|
+
assert gcd(-5, 3) == 1
|
28
|
+
|
29
|
+
|
30
|
+
def test_lcm():
|
31
|
+
assert lcm(10, 14) == 70
|
32
|
+
assert lcm(-5, 3) == 15
|
33
|
+
|
34
|
+
|
35
|
+
def test_gcd_ext():
|
36
|
+
(q, r, p) = gcd_ext(6, 9)
|
37
|
+
assert p == q * 6 + r * 9
|
38
|
+
(q, r, p) = gcd_ext(-15, 10)
|
39
|
+
assert p == q * -15 + r * 10
|
40
|
+
(q, r, p) = gcd_ext(2, 3)
|
41
|
+
assert p == q * 2 + r * 3
|
42
|
+
assert p == 1
|
43
|
+
(q, r, p) = gcd_ext(10, 12)
|
44
|
+
assert p == q * 10 + r * 12
|
45
|
+
assert p == 2
|
46
|
+
(q, r, p) = gcd_ext(100, 2004)
|
47
|
+
assert p == q * 100 + r * 2004
|
48
|
+
assert p == 4
|
49
|
+
|
50
|
+
|
51
|
+
def test_mod():
|
52
|
+
assert mod(13, 5) == 3
|
53
|
+
assert mod(-4, 7) == 3
|
54
|
+
|
55
|
+
|
56
|
+
def test_mod_error():
|
57
|
+
raises(ZeroDivisionError, lambda: mod(2, 0))
|
58
|
+
|
59
|
+
|
60
|
+
def test_quotient():
|
61
|
+
assert quotient(13, 5) == 2
|
62
|
+
assert quotient(-4, 7) == -1
|
63
|
+
|
64
|
+
|
65
|
+
def test_quotient_error():
|
66
|
+
raises(ZeroDivisionError, lambda: quotient(1, 0))
|
67
|
+
|
68
|
+
|
69
|
+
def test_quotient_mod():
|
70
|
+
assert quotient_mod(13, 5) == (2, 3)
|
71
|
+
assert quotient_mod(-4, 7) == (-1, 3)
|
72
|
+
|
73
|
+
|
74
|
+
def test_quotient_mod_error():
|
75
|
+
raises(ZeroDivisionError, lambda: quotient_mod(1, 0))
|
76
|
+
|
77
|
+
|
78
|
+
def test_mod_inverse():
|
79
|
+
mod_inverse(2, 7) == 4
|
80
|
+
mod_inverse(0, 3) is None
|
81
|
+
mod_inverse(4, 6) is None
|
82
|
+
|
83
|
+
|
84
|
+
def test_crt():
|
85
|
+
assert crt([0, 1, 2, 4], [2, 3, 4, 5]) == 34
|
86
|
+
assert crt([3, 5], [6, 21]) is None
|
87
|
+
|
88
|
+
|
89
|
+
def test_fibonacci():
|
90
|
+
assert fibonacci(0) == 0
|
91
|
+
assert fibonacci(5) == 5
|
92
|
+
|
93
|
+
|
94
|
+
def test_fibonacci_error():
|
95
|
+
raises(NotImplementedError, lambda: fibonacci(-3))
|
96
|
+
|
97
|
+
|
98
|
+
def test_fibonacci2():
|
99
|
+
assert fibonacci2(0) == [0, 1]
|
100
|
+
assert fibonacci2(5) == [5, 3]
|
101
|
+
|
102
|
+
|
103
|
+
def test_fibonacci2_error():
|
104
|
+
raises(NotImplementedError, lambda: fibonacci2(-1))
|
105
|
+
|
106
|
+
|
107
|
+
def test_lucas():
|
108
|
+
assert lucas(2) == 3
|
109
|
+
assert lucas(3) == 4
|
110
|
+
|
111
|
+
|
112
|
+
def test_lucas_error():
|
113
|
+
raises(NotImplementedError, lambda: lucas(-1))
|
114
|
+
|
115
|
+
|
116
|
+
def test_lucas2():
|
117
|
+
assert lucas2(3) == [4, 3]
|
118
|
+
assert lucas2(5) == [11, 7]
|
119
|
+
|
120
|
+
|
121
|
+
def test_lucas2_error():
|
122
|
+
raises(NotImplementedError, lambda: lucas2(-1))
|
123
|
+
|
124
|
+
|
125
|
+
def test_binomial():
|
126
|
+
assert binomial(5, 2) == 10
|
127
|
+
assert binomial(5, 7) == 0
|
128
|
+
assert binomial(-5, 2) == 15
|
129
|
+
|
130
|
+
|
131
|
+
def test_binomial_error():
|
132
|
+
raises(ArithmeticError, lambda: binomial(5, -1))
|
133
|
+
|
134
|
+
|
135
|
+
def test_factorial():
|
136
|
+
assert factorial(5) == 120
|
137
|
+
assert factorial(0) == 1
|
138
|
+
|
139
|
+
|
140
|
+
def test_factorial_error():
|
141
|
+
raises(ArithmeticError, lambda: factorial(-1))
|
142
|
+
|
143
|
+
|
144
|
+
def test_divides():
|
145
|
+
assert divides(5, 2) is False
|
146
|
+
assert divides(10, 5) is True
|
147
|
+
assert divides(0, 0) is True
|
148
|
+
assert divides(5, 0) is False
|
149
|
+
|
150
|
+
|
151
|
+
def test_factor():
|
152
|
+
f = factor(102)
|
153
|
+
assert f is not None and divides(102, f)
|
154
|
+
assert factor(101) is None
|
155
|
+
|
156
|
+
|
157
|
+
def test_prime_factors():
|
158
|
+
assert prime_factors(100) == [2, 2, 5, 5]
|
159
|
+
assert prime_factors(1) == []
|
160
|
+
|
161
|
+
|
162
|
+
def test_prime_factor_multiplicities():
|
163
|
+
assert prime_factor_multiplicities(90) == \
|
164
|
+
{Integer(2): 1, Integer(3): 2, Integer(5): 1}
|
165
|
+
assert prime_factor_multiplicities(1) == {}
|
166
|
+
|
167
|
+
|
168
|
+
def test_sieve():
|
169
|
+
assert Sieve.generate_primes(50) == [2, 3, 5, 7, 11, 13, 17,
|
170
|
+
19, 23, 29, 31, 37, 41, 43, 47]
|
171
|
+
assert len(Sieve.generate_primes(1009)) == 169
|
172
|
+
|
173
|
+
|
174
|
+
def test_sieve_iterator():
|
175
|
+
it = Sieve_iterator(101)
|
176
|
+
assert len([i for i in it]) == 26
|
177
|
+
|
178
|
+
|
179
|
+
def test_primitive_root():
|
180
|
+
assert primitive_root(27) in [2, 5, 11, 14, 20, 23]
|
181
|
+
assert primitive_root(15) is None
|
182
|
+
|
183
|
+
|
184
|
+
def test_primitive_root_list():
|
185
|
+
assert primitive_root_list(54) == [5, 11, 23, 29, 41, 47]
|
186
|
+
assert primitive_root_list(12) == []
|
187
|
+
|
188
|
+
|
189
|
+
def test_totient():
|
190
|
+
assert totient(1) == 1
|
191
|
+
assert totient(-15) == 8
|
192
|
+
|
193
|
+
|
194
|
+
def test_carmichael():
|
195
|
+
assert carmichael(8) == 2
|
196
|
+
assert carmichael(-21) == 6
|
197
|
+
|
198
|
+
|
199
|
+
def test_multiplicative_order():
|
200
|
+
assert multiplicative_order(2, 21) == 6
|
201
|
+
assert multiplicative_order(5, 10) is None
|
202
|
+
|
203
|
+
|
204
|
+
def test_legendre():
|
205
|
+
assert legendre(-1, 5) == 1
|
206
|
+
assert legendre(0, 5) == 0
|
207
|
+
assert legendre(2, 5) == -1
|
208
|
+
|
209
|
+
|
210
|
+
def test_jacobi():
|
211
|
+
assert legendre(-1, 77) == 1
|
212
|
+
assert legendre(14, 15) == -1
|
213
|
+
|
214
|
+
|
215
|
+
def test_kronecker():
|
216
|
+
assert kronecker(9, 2) == 1
|
217
|
+
assert kronecker(-5, -1) == -1
|
218
|
+
|
219
|
+
|
220
|
+
def test_nthroot_mod():
|
221
|
+
assert nthroot_mod(12, 5, 77) in [3, 31, 38, 45, 59]
|
222
|
+
assert nthroot_mod(3, 2, 5) is None
|
223
|
+
|
224
|
+
|
225
|
+
def test_sqrt_mod():
|
226
|
+
assert sqrt_mod(3, 13) == 9
|
227
|
+
assert sqrt_mod(6, 23) == 12
|
228
|
+
assert sqrt_mod(345, 690) == 345
|
229
|
+
assert sqrt_mod(9, 27, True) == [3, 6, 12, 15, 21, 24]
|
230
|
+
assert sqrt_mod(9, 81, True) == [3, 24, 30, 51, 57, 78]
|
231
|
+
assert sqrt_mod(9, 3**5, True) == [3, 78, 84, 159, 165, 240]
|
232
|
+
assert sqrt_mod(81, 3**4, True) == [0, 9, 18, 27, 36, 45, 54, 63, 72]
|
233
|
+
assert sqrt_mod(81, 3**5, True) == [9, 18, 36, 45, 63, 72, 90, 99, 117,\
|
234
|
+
126, 144, 153, 171, 180, 198, 207, 225, 234]
|
235
|
+
assert sqrt_mod(81, 3**6, True) == [9, 72, 90, 153, 171, 234, 252, 315,\
|
236
|
+
333, 396, 414, 477, 495, 558, 576, 639, 657, 720]
|
237
|
+
assert sqrt_mod(81, 3**7, True) == [9, 234, 252, 477, 495, 720, 738, 963,\
|
238
|
+
981, 1206, 1224, 1449, 1467, 1692, 1710, 1935, 1953, 2178]
|
239
|
+
|
240
|
+
|
241
|
+
def test_nthroot_mod_list():
|
242
|
+
assert nthroot_mod_list(-4, 4, 65) == [4, 6, 7, 9, 17, 19, 22, 32,
|
243
|
+
33, 43, 46, 48, 56, 58, 59, 61]
|
244
|
+
assert nthroot_mod_list(2, 3, 7) == []
|
245
|
+
|
246
|
+
|
247
|
+
def test_powermod():
|
248
|
+
assert powermod(3, 8, 7) == 2
|
249
|
+
assert powermod(3, Integer(11)/2, 13) in [3, 10]
|
250
|
+
|
251
|
+
|
252
|
+
def test_powermod_list():
|
253
|
+
assert powermod_list(15, Integer(1)/6, 21) == [3, 6, 9, 12, 15, 18]
|
254
|
+
assert powermod_list(2, Integer(5)/2, 11) == []
|
@@ -0,0 +1,186 @@
|
|
1
|
+
from symengine.test_utilities import raises
|
2
|
+
|
3
|
+
from symengine import Integer, I, S, Symbol, pi, Rational
|
4
|
+
from symengine.lib.symengine_wrapper import (perfect_power, is_square, integer_nthroot)
|
5
|
+
|
6
|
+
|
7
|
+
def test_integer():
|
8
|
+
i = Integer(5)
|
9
|
+
assert str(i) == "5"
|
10
|
+
assert int(i) == 5
|
11
|
+
assert float(i) == 5.0
|
12
|
+
assert complex(i) == 5.0 + 0j
|
13
|
+
assert i.real == i
|
14
|
+
assert i.imag == S.Zero
|
15
|
+
|
16
|
+
|
17
|
+
def test_integer_long():
|
18
|
+
py_int = 123434444444444444444
|
19
|
+
i = Integer(py_int)
|
20
|
+
assert str(i) == str(py_int)
|
21
|
+
assert int(i) == py_int
|
22
|
+
|
23
|
+
|
24
|
+
def test_integer_string():
|
25
|
+
assert Integer("133") == 133
|
26
|
+
|
27
|
+
|
28
|
+
def test_rational():
|
29
|
+
i = Integer(5)/10
|
30
|
+
assert str(i) == "1/2"
|
31
|
+
assert int(i) == 0
|
32
|
+
assert float(i) == 0.5
|
33
|
+
assert complex(i) == 0.5 + 0j
|
34
|
+
assert i.real == i
|
35
|
+
assert i.imag == S.Zero
|
36
|
+
|
37
|
+
|
38
|
+
def test_complex():
|
39
|
+
i = Integer(5)/10 + I
|
40
|
+
assert str(i) == "1/2 + I"
|
41
|
+
assert complex(i) == 0.5 + 1j
|
42
|
+
assert i.real == Integer(1)/2
|
43
|
+
assert i.imag == 1
|
44
|
+
|
45
|
+
i = 0.5 + I
|
46
|
+
assert str(i) == "0.5 + 1.0*I"
|
47
|
+
assert complex(i) == 0.5 + 1j
|
48
|
+
assert i.real == 0.5
|
49
|
+
assert i.imag == 1.0
|
50
|
+
|
51
|
+
|
52
|
+
def test_smallfloat_valid():
|
53
|
+
i = Integer(7.5)
|
54
|
+
assert str(i) == "7"
|
55
|
+
|
56
|
+
|
57
|
+
def test_bigfloat_valid():
|
58
|
+
i = Integer(13333333333333334.5)
|
59
|
+
assert str(i) == "13333333333333334"
|
60
|
+
|
61
|
+
|
62
|
+
def test_is_conditions():
|
63
|
+
i = Integer(-123)
|
64
|
+
assert not i.is_zero
|
65
|
+
assert not i.is_positive
|
66
|
+
assert i.is_negative
|
67
|
+
assert i.is_nonzero
|
68
|
+
assert i.is_nonpositive
|
69
|
+
assert not i.is_nonnegative
|
70
|
+
assert not i.is_complex
|
71
|
+
|
72
|
+
i = Integer(123)
|
73
|
+
assert not i.is_zero
|
74
|
+
assert i.is_positive
|
75
|
+
assert not i.is_negative
|
76
|
+
assert i.is_nonzero
|
77
|
+
assert not i.is_nonpositive
|
78
|
+
assert i.is_nonnegative
|
79
|
+
assert not i.is_complex
|
80
|
+
|
81
|
+
i = Integer(0)
|
82
|
+
assert i.is_zero
|
83
|
+
assert not i.is_positive
|
84
|
+
assert not i.is_negative
|
85
|
+
assert not i.is_nonzero
|
86
|
+
assert i.is_nonpositive
|
87
|
+
assert i.is_nonnegative
|
88
|
+
assert not i.is_complex
|
89
|
+
|
90
|
+
i = Integer(1) + I
|
91
|
+
assert not i.is_zero
|
92
|
+
assert not i.is_positive
|
93
|
+
assert not i.is_negative
|
94
|
+
assert not i.is_nonzero
|
95
|
+
assert not i.is_nonpositive
|
96
|
+
assert not i.is_nonnegative
|
97
|
+
assert i.is_complex
|
98
|
+
|
99
|
+
assert pi.is_number
|
100
|
+
|
101
|
+
|
102
|
+
def test_perfect_power():
|
103
|
+
assert perfect_power(1) == True
|
104
|
+
assert perfect_power(7) == False
|
105
|
+
assert perfect_power(8) == True
|
106
|
+
assert perfect_power(9) == True
|
107
|
+
assert perfect_power(10) == False
|
108
|
+
assert perfect_power(1024) == True
|
109
|
+
assert perfect_power(1025) == False
|
110
|
+
assert perfect_power(6**7) == True
|
111
|
+
assert perfect_power(-27) == True
|
112
|
+
assert perfect_power(-64) == True
|
113
|
+
assert perfect_power(-32) == True
|
114
|
+
|
115
|
+
|
116
|
+
def test_perfect_square():
|
117
|
+
assert is_square(7) == False
|
118
|
+
assert is_square(8) == False
|
119
|
+
assert is_square(9) == True
|
120
|
+
assert is_square(10) == False
|
121
|
+
assert perfect_power(49) == True
|
122
|
+
assert perfect_power(50) == False
|
123
|
+
|
124
|
+
|
125
|
+
def test_integer_nthroot():
|
126
|
+
assert integer_nthroot(1, 2) == (1, True)
|
127
|
+
assert integer_nthroot(1, 5) == (1, True)
|
128
|
+
assert integer_nthroot(2, 1) == (2, True)
|
129
|
+
assert integer_nthroot(2, 2) == (1, False)
|
130
|
+
assert integer_nthroot(2, 5) == (1, False)
|
131
|
+
assert integer_nthroot(4, 2) == (2, True)
|
132
|
+
assert integer_nthroot(123**25, 25) == (123, True)
|
133
|
+
assert integer_nthroot(123**25 + 1, 25) == (123, False)
|
134
|
+
assert integer_nthroot(123**25 - 1, 25) == (122, False)
|
135
|
+
assert integer_nthroot(1, 1) == (1, True)
|
136
|
+
assert integer_nthroot(0, 1) == (0, True)
|
137
|
+
assert integer_nthroot(0, 3) == (0, True)
|
138
|
+
assert integer_nthroot(10000, 1) == (10000, True)
|
139
|
+
assert integer_nthroot(4, 2) == (2, True)
|
140
|
+
assert integer_nthroot(16, 2) == (4, True)
|
141
|
+
assert integer_nthroot(26, 2) == (5, False)
|
142
|
+
assert integer_nthroot(1234567**7, 7) == (1234567, True)
|
143
|
+
assert integer_nthroot(1234567**7 + 1, 7) == (1234567, False)
|
144
|
+
assert integer_nthroot(1234567**7 - 1, 7) == (1234566, False)
|
145
|
+
b = 25**1000
|
146
|
+
assert integer_nthroot(b, 1000) == (25, True)
|
147
|
+
assert integer_nthroot(b + 1, 1000) == (25, False)
|
148
|
+
assert integer_nthroot(b - 1, 1000) == (24, False)
|
149
|
+
c = 10**400
|
150
|
+
c2 = c**2
|
151
|
+
assert integer_nthroot(c2, 2) == (c, True)
|
152
|
+
assert integer_nthroot(c2 + 1, 2) == (c, False)
|
153
|
+
assert integer_nthroot(c2 - 1, 2) == (c - 1, False)
|
154
|
+
|
155
|
+
|
156
|
+
def test_is_zero():
|
157
|
+
assert Symbol('x').is_zero is None
|
158
|
+
|
159
|
+
|
160
|
+
def test_is_positive():
|
161
|
+
assert Rational(1, 2).is_positive
|
162
|
+
assert not Rational(-2, 3).is_positive
|
163
|
+
assert Symbol('x').is_positive is None
|
164
|
+
|
165
|
+
|
166
|
+
def test_is_negative():
|
167
|
+
assert not Rational(1, 2).is_negative
|
168
|
+
assert Rational(-2, 3).is_negative
|
169
|
+
assert Symbol('x').is_negative is None
|
170
|
+
|
171
|
+
|
172
|
+
def test_is_nonpositive():
|
173
|
+
assert not Rational(1, 2).is_nonpositive
|
174
|
+
assert Rational(-2, 3).is_nonpositive
|
175
|
+
assert Symbol('x').is_nonpositive is None
|
176
|
+
|
177
|
+
|
178
|
+
def test_is_nonnegative():
|
179
|
+
assert Rational(1, 2).is_nonnegative
|
180
|
+
assert not Rational(-2, 3).is_nonnegative
|
181
|
+
assert Symbol('x').is_nonnegative is None
|
182
|
+
|
183
|
+
|
184
|
+
def test_is_real():
|
185
|
+
assert Rational(1, 2).is_real
|
186
|
+
assert Symbol('x').is_real is None
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from symengine import symbols, sin, sinh, have_numpy, have_llvm, cos, Symbol
|
2
|
+
from symengine.test_utilities import raises
|
3
|
+
import pickle
|
4
|
+
import unittest
|
5
|
+
|
6
|
+
|
7
|
+
def test_basic():
|
8
|
+
x, y, z = symbols('x y z')
|
9
|
+
expr = sin(cos(x + y)/z)**2
|
10
|
+
s = pickle.dumps(expr)
|
11
|
+
expr2 = pickle.loads(s)
|
12
|
+
assert expr == expr2
|
13
|
+
|
14
|
+
|
15
|
+
class MySymbolBase(Symbol):
|
16
|
+
def __init__(self, name, attr):
|
17
|
+
super().__init__(name=name)
|
18
|
+
self.attr = attr
|
19
|
+
|
20
|
+
def __eq__(self, other):
|
21
|
+
if not isinstance(other, MySymbolBase):
|
22
|
+
return False
|
23
|
+
return self.name == other.name and self.attr == other.attr
|
24
|
+
|
25
|
+
|
26
|
+
class MySymbol(MySymbolBase):
|
27
|
+
def __reduce__(self):
|
28
|
+
return (self.__class__, (self.name, self.attr))
|
29
|
+
|
30
|
+
|
31
|
+
def test_pysymbol():
|
32
|
+
a = MySymbol("hello", attr=1)
|
33
|
+
b = pickle.loads(pickle.dumps(a + 2)) - 2
|
34
|
+
try:
|
35
|
+
assert a == b
|
36
|
+
finally:
|
37
|
+
a._unsafe_reset()
|
38
|
+
b._unsafe_reset()
|
39
|
+
|
40
|
+
a = MySymbolBase("hello", attr=1)
|
41
|
+
try:
|
42
|
+
raises(NotImplementedError, lambda: pickle.dumps(a))
|
43
|
+
raises(NotImplementedError, lambda: pickle.dumps(a + 2))
|
44
|
+
finally:
|
45
|
+
a._unsafe_reset()
|
46
|
+
|
47
|
+
|
48
|
+
@unittest.skipUnless(have_llvm, "No LLVM support")
|
49
|
+
@unittest.skipUnless(have_numpy, "Numpy not installed")
|
50
|
+
def test_llvm_double():
|
51
|
+
import numpy as np
|
52
|
+
from symengine import Lambdify
|
53
|
+
args = x, y, z = symbols('x y z')
|
54
|
+
expr = sin(sinh(x+y) + z)
|
55
|
+
l = Lambdify(args, expr, cse=True, backend='llvm')
|
56
|
+
ss = pickle.dumps(l)
|
57
|
+
ll = pickle.loads(ss)
|
58
|
+
inp = [1, 2, 3]
|
59
|
+
assert np.allclose(l(inp), ll(inp))
|
@@ -0,0 +1,38 @@
|
|
1
|
+
from symengine import (ccode, unicode, Symbol, sqrt, Pow, Max, sin, Integer, MutableDenseMatrix)
|
2
|
+
from symengine.test_utilities import raises
|
3
|
+
from symengine.printing import CCodePrinter, init_printing
|
4
|
+
|
5
|
+
def test_ccode():
|
6
|
+
x = Symbol("x")
|
7
|
+
y = Symbol("y")
|
8
|
+
assert ccode(x) == "x"
|
9
|
+
assert ccode(x**3) == "pow(x, 3)"
|
10
|
+
assert ccode(x**(y**3)) == "pow(x, pow(y, 3))"
|
11
|
+
assert ccode(x**-1.0) == "pow(x, -1.0)"
|
12
|
+
assert ccode(Max(x, x*x)) == "fmax(x, pow(x, 2))"
|
13
|
+
assert ccode(sin(x)) == "sin(x)"
|
14
|
+
assert ccode(Integer(67)) == "67"
|
15
|
+
assert ccode(Integer(-1)) == "-1"
|
16
|
+
|
17
|
+
def test_CCodePrinter():
|
18
|
+
x = Symbol("x")
|
19
|
+
y = Symbol("y")
|
20
|
+
myprinter = CCodePrinter()
|
21
|
+
|
22
|
+
assert myprinter.doprint(1+x, "bork") == "bork = 1 + x;"
|
23
|
+
assert myprinter.doprint(1*x) == "x"
|
24
|
+
assert myprinter.doprint(MutableDenseMatrix(1, 2, [x, y]), "larry") == "larry[0] = x;\nlarry[1] = y;"
|
25
|
+
raises(TypeError, lambda: myprinter.doprint(sin(x), Integer))
|
26
|
+
raises(RuntimeError, lambda: myprinter.doprint(MutableDenseMatrix(1, 2, [x, y])))
|
27
|
+
|
28
|
+
def test_init_printing():
|
29
|
+
x = Symbol("x")
|
30
|
+
assert x._repr_latex_() is None
|
31
|
+
init_printing()
|
32
|
+
assert x._repr_latex_() == '$x$'
|
33
|
+
|
34
|
+
|
35
|
+
def test_unicode():
|
36
|
+
x = Symbol("x")
|
37
|
+
y = Integer(2)
|
38
|
+
assert unicode(x / 2) == "x\n―\n2"
|
@@ -0,0 +1,175 @@
|
|
1
|
+
from symengine import (Integer, symbols, sin, cos, pi, E, I, oo, zoo,
|
2
|
+
nan, true, false, Add, function_symbol, DenseMatrix,
|
3
|
+
sympify, log, EulerGamma, Catalan, GoldenRatio)
|
4
|
+
from symengine.lib.symengine_wrapper import (PyNumber, PyFunction,
|
5
|
+
sage_module, wrap_sage_function, LambertW, KroneckerDelta, erf,
|
6
|
+
lowergamma, uppergamma, loggamma, beta, floor, ceiling, conjugate)
|
7
|
+
import unittest
|
8
|
+
|
9
|
+
try:
|
10
|
+
import sage.all as sage
|
11
|
+
have_sage = True
|
12
|
+
except ImportError:
|
13
|
+
have_sage = False
|
14
|
+
|
15
|
+
@unittest.skipUnless(have_sage, "Sage not installed")
|
16
|
+
def test_sage_conversions():
|
17
|
+
|
18
|
+
x, y = sage.SR.var('x y')
|
19
|
+
x1, y1 = symbols('x, y')
|
20
|
+
|
21
|
+
# Symbol
|
22
|
+
assert x1._sage_() == x
|
23
|
+
assert x1 == sympify(x)
|
24
|
+
|
25
|
+
# Integer
|
26
|
+
assert Integer(12)._sage_() == sage.Integer(12)
|
27
|
+
assert Integer(12) == sympify(sage.Integer(12))
|
28
|
+
|
29
|
+
# Rational
|
30
|
+
assert (Integer(1) / 2)._sage_() == sage.Integer(1) / 2
|
31
|
+
assert Integer(1) / 2 == sympify(sage.Integer(1) / 2)
|
32
|
+
|
33
|
+
# Operators
|
34
|
+
assert x1 + y == x1 + y1
|
35
|
+
assert x1 * y == x1 * y1
|
36
|
+
assert x1 ** y == x1 ** y1
|
37
|
+
assert x1 - y == x1 - y1
|
38
|
+
assert x1 / y == x1 / y1
|
39
|
+
|
40
|
+
assert x + y1 == x + y
|
41
|
+
assert x * y1 == x * y
|
42
|
+
# Doesn't work in Sage 6.1.1ubuntu2
|
43
|
+
# assert x ** y1 == x ** y
|
44
|
+
assert x - y1 == x - y
|
45
|
+
assert x / y1 == x / y
|
46
|
+
|
47
|
+
# Conversions
|
48
|
+
assert (x1 + y1)._sage_() == x + y
|
49
|
+
assert (x1 * y1)._sage_() == x * y
|
50
|
+
assert (x1 ** y1)._sage_() == x ** y
|
51
|
+
assert (x1 - y1)._sage_() == x - y
|
52
|
+
assert (x1 / y1)._sage_() == x / y
|
53
|
+
|
54
|
+
assert x1 + y1 == sympify(x + y)
|
55
|
+
assert x1 * y1 == sympify(x * y)
|
56
|
+
assert x1 ** y1 == sympify(x ** y)
|
57
|
+
assert x1 - y1 == sympify(x - y)
|
58
|
+
assert x1 / y1 == sympify(x / y)
|
59
|
+
|
60
|
+
# Functions
|
61
|
+
assert sin(x1) == sin(x)
|
62
|
+
assert sin(x1)._sage_() == sage.sin(x)
|
63
|
+
assert sin(x1) == sympify(sage.sin(x))
|
64
|
+
|
65
|
+
assert cos(x1) == cos(x)
|
66
|
+
assert cos(x1)._sage_() == sage.cos(x)
|
67
|
+
assert cos(x1) == sympify(sage.cos(x))
|
68
|
+
|
69
|
+
assert function_symbol('f', x1, y1)._sage_() == sage.function('f')(x, y)
|
70
|
+
assert (function_symbol('f', 2 * x1, x1 + y1).diff(x1)._sage_() ==
|
71
|
+
sage.function('f')(2 * x, x + y).diff(x))
|
72
|
+
|
73
|
+
assert LambertW(x1) == LambertW(x)
|
74
|
+
assert LambertW(x1)._sage_() == sage.lambert_w(x)
|
75
|
+
|
76
|
+
assert KroneckerDelta(x1, y1) == KroneckerDelta(x, y)
|
77
|
+
assert KroneckerDelta(x1, y1)._sage_() == sage.kronecker_delta(x, y)
|
78
|
+
|
79
|
+
assert erf(x1) == erf(x)
|
80
|
+
assert erf(x1)._sage_() == sage.erf(x)
|
81
|
+
|
82
|
+
assert lowergamma(x1, y1) == lowergamma(x, y)
|
83
|
+
assert lowergamma(x1, y1)._sage_() == sage.gamma_inc_lower(x, y)
|
84
|
+
|
85
|
+
assert uppergamma(x1, y1) == uppergamma(x, y)
|
86
|
+
assert uppergamma(x1, y1)._sage_() == sage.gamma_inc(x, y)
|
87
|
+
|
88
|
+
assert loggamma(x1) == loggamma(x)
|
89
|
+
assert loggamma(x1)._sage_() == sage.log_gamma(x)
|
90
|
+
|
91
|
+
assert beta(x1, y1) == beta(x, y)
|
92
|
+
assert beta(x1, y1)._sage_() == sage.beta(x, y)
|
93
|
+
|
94
|
+
assert floor(x1) == floor(x)
|
95
|
+
assert floor(x1)._sage_() == sage.floor(x)
|
96
|
+
|
97
|
+
assert ceiling(x1) == ceiling(x)
|
98
|
+
assert ceiling(x1)._sage_() == sage.ceil(x)
|
99
|
+
|
100
|
+
assert conjugate(x1) == conjugate(x)
|
101
|
+
assert conjugate(x1)._sage_() == sage.conjugate(x)
|
102
|
+
|
103
|
+
# For the following test, sage needs to be modified
|
104
|
+
# assert sage.sin(x) == sage.sin(x1)
|
105
|
+
|
106
|
+
# Constants and Booleans
|
107
|
+
assert pi._sage_() == sage.pi
|
108
|
+
assert E._sage_() == sage.e
|
109
|
+
assert I._sage_() == sage.I
|
110
|
+
assert GoldenRatio._sage_() == sage.golden_ratio
|
111
|
+
assert Catalan._sage_() == sage.catalan
|
112
|
+
assert EulerGamma._sage_() == sage.euler_gamma
|
113
|
+
assert oo._sage_() == sage.oo
|
114
|
+
assert zoo._sage_() == sage.unsigned_infinity
|
115
|
+
assert nan._sage_() == sage.NaN
|
116
|
+
assert true._sage_() == True
|
117
|
+
assert false._sage_() == False
|
118
|
+
|
119
|
+
assert pi == sympify(sage.pi)
|
120
|
+
assert E == sympify(sage.e)
|
121
|
+
assert GoldenRatio == sympify(sage.golden_ratio)
|
122
|
+
assert Catalan == sympify(sage.catalan)
|
123
|
+
assert EulerGamma == sympify(sage.euler_gamma)
|
124
|
+
assert oo == sympify(sage.oo)
|
125
|
+
assert zoo == sympify(sage.unsigned_infinity)
|
126
|
+
assert nan == sympify(sage.NaN)
|
127
|
+
|
128
|
+
# SympyConverter does not support converting the following
|
129
|
+
# assert I == sympify(sage.I)
|
130
|
+
|
131
|
+
# Matrix
|
132
|
+
assert DenseMatrix(1, 2, [x1, y1])._sage_() == sage.matrix([[x, y]])
|
133
|
+
|
134
|
+
# SympyConverter does not support converting the following
|
135
|
+
# assert DenseMatrix(1, 2, [x1, y1]) == sympify(sage.matrix([[x, y]]))
|
136
|
+
|
137
|
+
# Sage Number
|
138
|
+
a = sage.Mod(2, 7)
|
139
|
+
b = PyNumber(a, sage_module)
|
140
|
+
|
141
|
+
a = a + 8
|
142
|
+
b = b + 8
|
143
|
+
assert isinstance(b, PyNumber)
|
144
|
+
assert b._sage_() == a
|
145
|
+
assert str(a) == str(b)
|
146
|
+
|
147
|
+
# Sage Function
|
148
|
+
e = x1 + wrap_sage_function(sage.log_gamma(x))
|
149
|
+
assert str(e) == "x + log_gamma(x)"
|
150
|
+
assert isinstance(e, Add)
|
151
|
+
assert (e + wrap_sage_function(sage.log_gamma(x)) ==
|
152
|
+
x1 + 2*wrap_sage_function(sage.log_gamma(x)))
|
153
|
+
|
154
|
+
f = e.subs({x1: 10})
|
155
|
+
assert f == 10 + log(362880)
|
156
|
+
|
157
|
+
f = e.subs({x1: 2})
|
158
|
+
assert f == 2
|
159
|
+
|
160
|
+
f = e.subs({x1: 100})
|
161
|
+
v = f.n(53, real=True)
|
162
|
+
assert abs(float(v) - 459.13420537) < 1e-7
|
163
|
+
|
164
|
+
f = e.diff(x1)
|
165
|
+
# Enable this once symengine conversions are in
|
166
|
+
# sage as sage.psi is converted to a sympy function in `e.diff(x1)`
|
167
|
+
# assert f == 1 + wrap_sage_function(sage.psi(x))
|
168
|
+
|
169
|
+
|
170
|
+
# This string contains Sage doctests, that execute all the functions above.
|
171
|
+
# When you add a new function, add it here as well.
|
172
|
+
"""
|
173
|
+
TESTS::
|
174
|
+
sage: test_sage_conversions()
|
175
|
+
"""
|