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
Binary file
|
Binary file
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#cython: language_level=3
|
2
|
+
|
3
|
+
cimport symengine
|
4
|
+
from symengine cimport RCP, map_basic_basic, rcp_const_basic
|
5
|
+
from libcpp.memory cimport unique_ptr
|
6
|
+
from libcpp.vector cimport vector
|
7
|
+
from libcpp.string cimport string
|
8
|
+
from libcpp cimport bool as cppbool
|
9
|
+
|
10
|
+
cdef class Basic(object):
|
11
|
+
cdef rcp_const_basic thisptr
|
12
|
+
|
13
|
+
cdef class MatrixBase(object):
|
14
|
+
cdef symengine.MatrixBase* thisptr
|
15
|
+
|
16
|
+
cdef class PyFunctionClass(object):
|
17
|
+
cdef RCP[const symengine.PyFunctionClass] thisptr
|
18
|
+
|
19
|
+
cdef class PyModule(object):
|
20
|
+
cdef RCP[const symengine.PyModule] thisptr
|
21
|
+
|
22
|
+
cdef class _DictBasic(object):
|
23
|
+
cdef map_basic_basic c
|
24
|
+
|
25
|
+
cdef class DictBasicIter(object):
|
26
|
+
cdef map_basic_basic.iterator begin
|
27
|
+
cdef map_basic_basic.iterator end
|
28
|
+
cdef init(self, map_basic_basic.iterator begin, map_basic_basic.iterator end)
|
29
|
+
|
30
|
+
cdef object c2py(rcp_const_basic o)
|
31
|
+
|
32
|
+
cdef class _Lambdify(object):
|
33
|
+
cdef size_t args_size, tot_out_size
|
34
|
+
cdef list out_shapes
|
35
|
+
cdef readonly bint real
|
36
|
+
cdef readonly size_t n_exprs
|
37
|
+
cdef public str order
|
38
|
+
cdef vector[int] accum_out_sizes
|
39
|
+
cdef object numpy_dtype
|
40
|
+
|
41
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
42
|
+
cdef _load(self, const string &s)
|
43
|
+
cpdef eval_real(self, inp, out)
|
44
|
+
cpdef eval_complex(self, inp, out)
|
45
|
+
cpdef unsafe_eval(sef, inp, out, unsigned nbroadcast=*)
|
46
|
+
|
47
|
+
cdef class LambdaDouble(_Lambdify):
|
48
|
+
cdef unique_ptr[symengine.LambdaRealDoubleVisitor] lambda_visitor
|
49
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
50
|
+
cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=*, int out_offset=*)
|
51
|
+
cpdef as_scipy_low_level_callable(self)
|
52
|
+
cpdef as_ctypes(self)
|
53
|
+
cpdef unsafe_real(self,
|
54
|
+
double[::1] inp, double[::1] out,
|
55
|
+
int inp_offset=*, int out_offset=*)
|
56
|
+
|
57
|
+
cdef class LambdaComplexDouble(_Lambdify):
|
58
|
+
cdef unique_ptr[symengine.LambdaComplexDoubleVisitor] lambda_visitor
|
59
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
60
|
+
cpdef unsafe_complex(self, double complex[::1] inp, double complex[::1] out, int inp_offset=*, int out_offset=*)
|
61
|
+
|
62
|
+
cdef class _LLVMLambdify(_Lambdify):
|
63
|
+
cdef int opt_level
|
64
|
+
|
65
|
+
cdef class LLVMDouble(_LLVMLambdify):
|
66
|
+
cdef unique_ptr[symengine.LLVMDoubleVisitor] lambda_visitor
|
67
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
68
|
+
cdef _load(self, const string &s)
|
69
|
+
cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=*, int out_offset=*)
|
70
|
+
cpdef as_scipy_low_level_callable(self)
|
71
|
+
cpdef as_ctypes(self)
|
72
|
+
|
73
|
+
cdef class LLVMFloat(_LLVMLambdify):
|
74
|
+
cdef unique_ptr[symengine.LLVMFloatVisitor] lambda_visitor
|
75
|
+
cdef _init(self, symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse)
|
76
|
+
cdef _load(self, const string &s)
|
77
|
+
cpdef unsafe_real(self, float[::1] inp, float[::1] out, int inp_offset=*, int out_offset=*)
|
78
|
+
|
symengine/lib/zlib.dll
ADDED
Binary file
|
symengine/lib/zstd.dll
ADDED
Binary file
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
|
4
|
+
if sys.platform == 'win32' \
|
5
|
+
and 'SYMENGINE_PY_ADD_PATH_TO_SEARCH_DIRS' in os.environ:
|
6
|
+
for directory in os.environ['PATH'].split(';'):
|
7
|
+
if os.path.isdir(directory):
|
8
|
+
os.add_dll_directory(directory)
|
9
|
+
|
10
|
+
del os, sys
|
11
|
+
|
12
|
+
import symengine.lib.symengine_wrapper as wrapper
|
13
|
+
|
14
|
+
from .lib.symengine_wrapper import (
|
15
|
+
have_mpfr, have_mpc, have_flint, have_piranha, have_llvm, have_llvm_long_double,
|
16
|
+
I, E, pi, oo, zoo, nan, Symbol, Dummy, S, sympify, SympifyError,
|
17
|
+
Integer, Rational, Float, Number, RealNumber, RealDouble, ComplexDouble,
|
18
|
+
add, Add, Mul, Pow, function_symbol,
|
19
|
+
Max, Min, DenseMatrix, Matrix,
|
20
|
+
ImmutableMatrix, ImmutableDenseMatrix, MutableDenseMatrix,
|
21
|
+
MatrixBase, Basic, DictBasic, symarray, series, diff, zeros,
|
22
|
+
eye, diag, ones, Derivative, Subs, expand, has_symbol,
|
23
|
+
UndefFunction, Function, UnevaluatedExpr, latex,
|
24
|
+
have_numpy, true, false, Equality, Unequality, GreaterThan,
|
25
|
+
LessThan, StrictGreaterThan, StrictLessThan, Eq, Ne, Ge, Le,
|
26
|
+
Gt, Lt, And, Or, Not, Nand, Nor, Xor, Xnor, perfect_power, integer_nthroot,
|
27
|
+
isprime, sqrt_mod, Expr, cse, count_ops, ccode, Piecewise, Contains, Interval, FiniteSet,
|
28
|
+
linsolve,
|
29
|
+
FunctionSymbol,
|
30
|
+
golden_ratio as GoldenRatio,
|
31
|
+
catalan as Catalan,
|
32
|
+
eulergamma as EulerGamma,
|
33
|
+
unicode
|
34
|
+
)
|
35
|
+
from .utilities import var, symbols
|
36
|
+
from .functions import *
|
37
|
+
from .printing import init_printing
|
38
|
+
|
39
|
+
|
40
|
+
AppliedUndef = FunctionSymbol # an alias
|
41
|
+
EmptySet = wrapper.S.EmptySet
|
42
|
+
UniversalSet = wrapper.S.UniversalSet
|
43
|
+
Reals = wrapper.S.Reals
|
44
|
+
Integers = wrapper.S.Integers
|
45
|
+
Rationals = wrapper.S.Rationals
|
46
|
+
|
47
|
+
|
48
|
+
if have_mpfr:
|
49
|
+
from .lib.symengine_wrapper import RealMPFR
|
50
|
+
|
51
|
+
if have_mpc:
|
52
|
+
from .lib.symengine_wrapper import ComplexMPC
|
53
|
+
|
54
|
+
if have_numpy:
|
55
|
+
from .lib.symengine_wrapper import (Lambdify, LambdifyCSE)
|
56
|
+
|
57
|
+
def lambdify(args, exprs, **kwargs):
|
58
|
+
return Lambdify(args, *exprs, **kwargs)
|
59
|
+
else:
|
60
|
+
def __getattr__(name):
|
61
|
+
if name == 'lambdify':
|
62
|
+
raise AttributeError("Cannot import numpy, which is required for `lambdify` to work")
|
63
|
+
raise AttributeError(f"module 'symengine' has no attribute '{name}'")
|
64
|
+
|
65
|
+
|
66
|
+
__version__ = "0.14.0"
|
67
|
+
|
68
|
+
|
69
|
+
# To not expose internals
|
70
|
+
del lib.symengine_wrapper
|
71
|
+
del lib
|
72
|
+
del wrapper
|
73
|
+
|
74
|
+
|
75
|
+
def test():
|
76
|
+
import pytest
|
77
|
+
import os
|
78
|
+
return not pytest.cmdline.main(
|
79
|
+
[os.path.dirname(os.path.abspath(__file__))])
|
@@ -0,0 +1,10 @@
|
|
1
|
+
from .lib.symengine_wrapper import (sin, cos, tan, cot, csc, sec,
|
2
|
+
asin, acos, atan, acot, acsc, asec,
|
3
|
+
sinh, cosh, tanh, coth, sech, csch,
|
4
|
+
asinh, acosh, atanh, acoth, asech, acsch,
|
5
|
+
gamma, log, atan2, sqrt, exp, Abs,
|
6
|
+
LambertW, zeta, dirichlet_eta,
|
7
|
+
KroneckerDelta, LeviCivita, erf, erfc,
|
8
|
+
lowergamma, uppergamma, loggamma, beta,
|
9
|
+
polygamma, sign, floor, ceiling,
|
10
|
+
conjugate, digamma, trigamma)
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from .lib.symengine_wrapper import ccode, sympify, Basic, repr_latex as _repr_latex
|
2
|
+
|
3
|
+
class CCodePrinter:
|
4
|
+
|
5
|
+
def doprint(self, expr, assign_to=None):
|
6
|
+
if not isinstance(assign_to, (Basic, type(None), str)):
|
7
|
+
raise TypeError("{} cannot assign to object of type {}".format(
|
8
|
+
type(self).__name__, type(assign_to)))
|
9
|
+
|
10
|
+
expr = sympify(expr)
|
11
|
+
if not assign_to:
|
12
|
+
if expr.is_Matrix:
|
13
|
+
raise RuntimeError("Matrices need a assign_to parameter")
|
14
|
+
return ccode(expr)
|
15
|
+
|
16
|
+
assign_to = str(assign_to)
|
17
|
+
if not expr.is_Matrix:
|
18
|
+
return f"{assign_to} = {ccode(expr)};"
|
19
|
+
|
20
|
+
code_lines = []
|
21
|
+
for i, element in enumerate(expr):
|
22
|
+
code_line = f'{assign_to}[{i}] = {element};'
|
23
|
+
code_lines.append(code_line)
|
24
|
+
return '\n'.join(code_lines)
|
25
|
+
|
26
|
+
|
27
|
+
def init_printing(pretty_print=True, use_latex=True):
|
28
|
+
if pretty_print:
|
29
|
+
if not use_latex:
|
30
|
+
raise RuntimeError("Only latex is supported for pretty printing")
|
31
|
+
_repr_latex[0] = True
|
32
|
+
else:
|
33
|
+
_repr_latex[0] = False
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import sys
|
2
|
+
|
3
|
+
try:
|
4
|
+
import py
|
5
|
+
from py.test import skip, raises
|
6
|
+
USE_PYTEST = getattr(sys, '_running_pytest', False)
|
7
|
+
except ImportError:
|
8
|
+
USE_PYTEST = False
|
9
|
+
|
10
|
+
if not USE_PYTEST:
|
11
|
+
def raises(expectedException, code=None):
|
12
|
+
"""
|
13
|
+
Tests that ``code`` raises the exception ``expectedException``.
|
14
|
+
|
15
|
+
``code`` may be a callable, such as a lambda expression or function
|
16
|
+
name.
|
17
|
+
|
18
|
+
If ``code`` is not given or None, ``raises`` will return a context
|
19
|
+
manager for use in ``with`` statements; the code to execute then
|
20
|
+
comes from the scope of the ``with``.
|
21
|
+
|
22
|
+
``raises()`` does nothing if the callable raises the expected
|
23
|
+
exception, otherwise it raises an AssertionError.
|
24
|
+
|
25
|
+
Examples
|
26
|
+
========
|
27
|
+
|
28
|
+
>>> from symengine.pytest import raises
|
29
|
+
|
30
|
+
>>> raises(ZeroDivisionError, lambda: 1/0)
|
31
|
+
>>> raises(ZeroDivisionError, lambda: 1/2)
|
32
|
+
Traceback (most recent call last):
|
33
|
+
...
|
34
|
+
AssertionError: DID NOT RAISE
|
35
|
+
|
36
|
+
>>> with raises(ZeroDivisionError):
|
37
|
+
... n = 1/0
|
38
|
+
>>> with raises(ZeroDivisionError):
|
39
|
+
... n = 1/2
|
40
|
+
Traceback (most recent call last):
|
41
|
+
...
|
42
|
+
AssertionError: DID NOT RAISE
|
43
|
+
|
44
|
+
Note that you cannot test multiple statements via
|
45
|
+
``with raises``:
|
46
|
+
|
47
|
+
>>> with raises(ZeroDivisionError):
|
48
|
+
... n = 1/0 # will execute and raise, aborting the ``with``
|
49
|
+
... n = 9999/0 # never executed
|
50
|
+
|
51
|
+
This is just what ``with`` is supposed to do: abort the
|
52
|
+
contained statement sequence at the first exception and let
|
53
|
+
the context manager deal with the exception.
|
54
|
+
|
55
|
+
To test multiple statements, you'll need a separate ``with``
|
56
|
+
for each:
|
57
|
+
|
58
|
+
>>> with raises(ZeroDivisionError):
|
59
|
+
... n = 1/0 # will execute and raise
|
60
|
+
>>> with raises(ZeroDivisionError):
|
61
|
+
... n = 9999/0 # will also execute and raise
|
62
|
+
|
63
|
+
"""
|
64
|
+
if code is None:
|
65
|
+
return RaisesContext(expectedException)
|
66
|
+
elif callable(code):
|
67
|
+
try:
|
68
|
+
code()
|
69
|
+
except expectedException:
|
70
|
+
return
|
71
|
+
raise AssertionError("DID NOT RAISE")
|
72
|
+
elif isinstance(code, str):
|
73
|
+
raise TypeError(
|
74
|
+
'\'raises(xxx, "code")\' has been phased out; '
|
75
|
+
'change \'raises(xxx, "expression")\' '
|
76
|
+
'to \'raises(xxx, lambda: expression)\', '
|
77
|
+
'\'raises(xxx, "statement")\' '
|
78
|
+
'to \'with raises(xxx): statement\'')
|
79
|
+
else:
|
80
|
+
raise TypeError(
|
81
|
+
'raises() expects a callable for the 2nd argument.')
|
82
|
+
|
83
|
+
class RaisesContext:
|
84
|
+
def __init__(self, expectedException):
|
85
|
+
self.expectedException = expectedException
|
86
|
+
|
87
|
+
def __enter__(self):
|
88
|
+
return None
|
89
|
+
|
90
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
91
|
+
if exc_type is None:
|
92
|
+
raise AssertionError("DID NOT RAISE")
|
93
|
+
return issubclass(exc_type, self.expectedException)
|
94
|
+
|
95
|
+
|
File without changes
|
@@ -0,0 +1,261 @@
|
|
1
|
+
from symengine.test_utilities import raises
|
2
|
+
|
3
|
+
from symengine import (Symbol, Integer, Add, Mul, Pow, Rational, sqrt,
|
4
|
+
symbols, S, I, count_ops, floor)
|
5
|
+
|
6
|
+
|
7
|
+
def test_arit1():
|
8
|
+
x = Symbol("x")
|
9
|
+
y = Symbol("y")
|
10
|
+
e = x + y
|
11
|
+
e = x * y
|
12
|
+
e = Integer(2)*x
|
13
|
+
e = 2*x
|
14
|
+
e = x + 1
|
15
|
+
e = 1 + x
|
16
|
+
|
17
|
+
|
18
|
+
def test_arit2():
|
19
|
+
x = Symbol("x")
|
20
|
+
y = Symbol("y")
|
21
|
+
assert x+x == Integer(2) * x
|
22
|
+
assert x+x != Integer(3) * x
|
23
|
+
assert x+y == y+x
|
24
|
+
assert x+x == 2*x
|
25
|
+
assert x+x == x*2
|
26
|
+
assert x+x+x == 3*x
|
27
|
+
assert x+y+x+x == 3*x+y
|
28
|
+
|
29
|
+
assert not x+x == 3*x
|
30
|
+
assert not x+x != 2*x
|
31
|
+
|
32
|
+
|
33
|
+
def test_arit3():
|
34
|
+
x = Symbol("x")
|
35
|
+
y = Symbol("y")
|
36
|
+
raises(TypeError, lambda: ("x"*x))
|
37
|
+
|
38
|
+
|
39
|
+
def test_arit4():
|
40
|
+
x = Symbol("x")
|
41
|
+
y = Symbol("y")
|
42
|
+
assert x*x == x**2
|
43
|
+
assert x*y == y*x
|
44
|
+
assert x*x*x == x**3
|
45
|
+
assert x*y*x*x == x**3*y
|
46
|
+
|
47
|
+
|
48
|
+
def test_arit5():
|
49
|
+
x = Symbol("x")
|
50
|
+
y = Symbol("y")
|
51
|
+
e = (x+y)**2
|
52
|
+
f = e.expand()
|
53
|
+
assert e == (x+y)**2
|
54
|
+
assert e != x**2 + 2*x*y + y**2
|
55
|
+
assert isinstance(e, Pow)
|
56
|
+
assert f == x**2 + 2*x*y + y**2
|
57
|
+
assert isinstance(f, Add)
|
58
|
+
|
59
|
+
|
60
|
+
def test_arit6():
|
61
|
+
x = Symbol("x")
|
62
|
+
y = Symbol("y")
|
63
|
+
e = x + y
|
64
|
+
assert str(e) == "x + y" or "y + x"
|
65
|
+
e = x * y
|
66
|
+
assert str(e) == "x*y" or "y*x"
|
67
|
+
e = Integer(2)*x
|
68
|
+
assert str(e) == "2*x"
|
69
|
+
e = 2*x
|
70
|
+
assert str(e) == "2*x"
|
71
|
+
|
72
|
+
|
73
|
+
def test_arit7():
|
74
|
+
x = Symbol("x")
|
75
|
+
y = Symbol("y")
|
76
|
+
assert x - x == 0
|
77
|
+
assert x - y != y - x
|
78
|
+
assert 2*x - x == x
|
79
|
+
assert 3*x - x == 2*x
|
80
|
+
|
81
|
+
assert 2*x*y - x*y == x*y
|
82
|
+
|
83
|
+
|
84
|
+
def test_arit8():
|
85
|
+
x = Symbol("x")
|
86
|
+
y = Symbol("y")
|
87
|
+
z = Symbol("z")
|
88
|
+
assert x**y * x**x == x**(x+y)
|
89
|
+
assert x**y * x**x * x**z == x**(x+y+z)
|
90
|
+
assert x**y - x**y == 0
|
91
|
+
|
92
|
+
assert x**2 / x == x
|
93
|
+
assert y*x**2 / (x*y) == x
|
94
|
+
assert (2 * x**3 * y**2 * z)**3 / 8 == x**9 * y**6 * z**3
|
95
|
+
assert (2*y**(-2*x**2)) * (3*y**(2*x**2)) == 6
|
96
|
+
|
97
|
+
|
98
|
+
def test_unary():
|
99
|
+
x = Symbol("x")
|
100
|
+
assert -x == 0 - x
|
101
|
+
assert +x == x
|
102
|
+
|
103
|
+
|
104
|
+
def test_expand1():
|
105
|
+
x = Symbol("x")
|
106
|
+
y = Symbol("y")
|
107
|
+
z = Symbol("z")
|
108
|
+
assert ((2*x+y)**2).expand() == 4*x**2 + 4*x*y + y**2
|
109
|
+
assert (x**2)**3 == x**6
|
110
|
+
assert ((2*x**2+3*y)**2).expand() == 4*x**4 + 12*x**2*y + 9*y**2
|
111
|
+
assert ((2*x/3+y/4)**2).expand() == 4*x**2/9 + x*y/3 + y**2/16
|
112
|
+
|
113
|
+
|
114
|
+
def test_arit9():
|
115
|
+
x = Symbol("x")
|
116
|
+
y = Symbol("y")
|
117
|
+
assert 1/x == 1/x
|
118
|
+
assert 1/x != 1/y
|
119
|
+
|
120
|
+
|
121
|
+
def test_expand2():
|
122
|
+
x = Symbol("x")
|
123
|
+
y = Symbol("y")
|
124
|
+
z = Symbol("z")
|
125
|
+
assert ((1/(y*z) - y*z)*y*z).expand() == 1-(y*z)**2
|
126
|
+
assert (2*(x + 2*(y + z))).expand(deep=False) == 2*x + 4*(y+z)
|
127
|
+
ex = x + 2*(y + z)
|
128
|
+
assert ex.expand(deep=False) == ex
|
129
|
+
|
130
|
+
|
131
|
+
def test_expand3():
|
132
|
+
x = Symbol("x")
|
133
|
+
y = Symbol("y")
|
134
|
+
assert ((1/(x*y) - x*y+2)*(1+x*y)).expand() == 3 + 1/(x*y) + x*y - (x*y)**2
|
135
|
+
|
136
|
+
|
137
|
+
def test_args():
|
138
|
+
x = Symbol("x")
|
139
|
+
y = Symbol("y")
|
140
|
+
assert (x**2).args == (x, 2)
|
141
|
+
assert (x**2 + 5).args == (5, x**2)
|
142
|
+
assert set((x**2 + 2*x*y + 5).args) == {x**2, 2*x*y, Integer(5)}
|
143
|
+
assert (2*x**2).args == (2, x**2)
|
144
|
+
assert set((2*x**2*y).args) == {Integer(2), x**2, y}
|
145
|
+
|
146
|
+
|
147
|
+
def test_atoms():
|
148
|
+
x = Symbol("x")
|
149
|
+
y = Symbol("y")
|
150
|
+
z = Symbol("z")
|
151
|
+
assert (x**2).atoms() == {x}
|
152
|
+
assert (x**2).atoms(Symbol) == {x}
|
153
|
+
assert (x ** y + z).atoms() == {x, y, z}
|
154
|
+
assert (x**y + z).atoms(Symbol) == {x, y, z}
|
155
|
+
|
156
|
+
|
157
|
+
def test_free_symbols():
|
158
|
+
x = Symbol("x")
|
159
|
+
y = Symbol("y")
|
160
|
+
z = Symbol("z")
|
161
|
+
assert (x**2).free_symbols == {x}
|
162
|
+
assert (x**y + z).free_symbols == {x, y, z}
|
163
|
+
|
164
|
+
|
165
|
+
def test_as_numer_denom():
|
166
|
+
x, y = Rational(17, 26).as_numer_denom()
|
167
|
+
assert x == Integer(17)
|
168
|
+
assert y == Integer(26)
|
169
|
+
|
170
|
+
x, y = Integer(-5).as_numer_denom()
|
171
|
+
assert x == Integer(-5)
|
172
|
+
assert y == Integer(1)
|
173
|
+
|
174
|
+
|
175
|
+
def test_floor():
|
176
|
+
exprs = [Symbol("x"), Symbol("y"), Integer(2), Rational(-3, 5), Integer(-3)]
|
177
|
+
|
178
|
+
for x in exprs:
|
179
|
+
for y in exprs:
|
180
|
+
assert x // y == floor(x / y)
|
181
|
+
assert x == y * (x // y) + x % y
|
182
|
+
|
183
|
+
|
184
|
+
def test_as_real_imag():
|
185
|
+
x, y = (5 + 6 * I).as_real_imag()
|
186
|
+
|
187
|
+
assert x == 5
|
188
|
+
assert y == 6
|
189
|
+
|
190
|
+
|
191
|
+
def test_from_args():
|
192
|
+
x = Symbol("x")
|
193
|
+
y = Symbol("y")
|
194
|
+
|
195
|
+
assert Add._from_args([]) == 0
|
196
|
+
assert Add._from_args([x]) == x
|
197
|
+
assert Add._from_args([x, y]) == x + y
|
198
|
+
|
199
|
+
assert Mul._from_args([]) == 1
|
200
|
+
assert Mul._from_args([x]) == x
|
201
|
+
assert Mul._from_args([x, y]) == x * y
|
202
|
+
|
203
|
+
|
204
|
+
def test_make_args():
|
205
|
+
x = Symbol("x")
|
206
|
+
y = Symbol("y")
|
207
|
+
z = Symbol("z")
|
208
|
+
|
209
|
+
assert Add.make_args(x) == (x,)
|
210
|
+
assert Mul.make_args(x) == (x,)
|
211
|
+
|
212
|
+
assert Add.make_args(x*y*z) == (x*y*z,)
|
213
|
+
assert Mul.make_args(x*y*z) == (x*y*z).args
|
214
|
+
|
215
|
+
assert Add.make_args(x + y + z) == (x + y + z).args
|
216
|
+
assert Mul.make_args(x + y + z) == (x + y + z,)
|
217
|
+
|
218
|
+
assert Add.make_args((x + y)**z) == ((x + y)**z,)
|
219
|
+
assert Mul.make_args((x + y)**z) == ((x + y)**z,)
|
220
|
+
|
221
|
+
|
222
|
+
def test_Pow_base_exp():
|
223
|
+
x = Symbol("x")
|
224
|
+
y = Symbol("y")
|
225
|
+
e = Pow(x + y, 2)
|
226
|
+
assert isinstance(e, Pow)
|
227
|
+
assert e.exp == 2
|
228
|
+
assert e.base == x + y
|
229
|
+
|
230
|
+
assert sqrt(x - 1).as_base_exp() == (x - 1, Rational(1, 2))
|
231
|
+
|
232
|
+
|
233
|
+
def test_copy():
|
234
|
+
b = Symbol("b")
|
235
|
+
a = b.copy()
|
236
|
+
assert a is b
|
237
|
+
assert type(a) == type(b)
|
238
|
+
|
239
|
+
|
240
|
+
def test_special_constants():
|
241
|
+
assert S.Zero == Integer(0)
|
242
|
+
assert S.One == Integer(1)
|
243
|
+
assert S.NegativeOne == Integer(-1)
|
244
|
+
assert S.Half == Rational(1, 2)
|
245
|
+
|
246
|
+
|
247
|
+
def test_bool():
|
248
|
+
x = Symbol('x')
|
249
|
+
if (x**2).args[1] > 0:
|
250
|
+
assert True
|
251
|
+
if (x**2).args[1] < 0:
|
252
|
+
assert False
|
253
|
+
|
254
|
+
|
255
|
+
def test_count_ops():
|
256
|
+
x, y = symbols("x, y")
|
257
|
+
assert count_ops(x+y) == 1
|
258
|
+
assert count_ops((x+y, x*y)) == 2
|
259
|
+
assert count_ops([[x**y], [x+y-1]]) == 3
|
260
|
+
assert count_ops(x+y, x*y) == 2
|
261
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from symengine import cse, sqrt, symbols
|
2
|
+
|
3
|
+
def test_cse_single():
|
4
|
+
x, y, x0 = symbols("x, y, x0")
|
5
|
+
e = pow(x + y, 2) + sqrt(x + y)
|
6
|
+
substs, reduced = cse([e])
|
7
|
+
assert substs == [(x0, x + y)]
|
8
|
+
assert reduced == [sqrt(x0) + x0**2]
|
9
|
+
|
10
|
+
|
11
|
+
def test_multiple_expressions():
|
12
|
+
w, x, y, z, x0 = symbols("w, x, y, z, x0")
|
13
|
+
e1 = (x + y)*z
|
14
|
+
e2 = (x + y)*w
|
15
|
+
substs, reduced = cse([e1, e2])
|
16
|
+
assert substs == [(x0, x + y)]
|
17
|
+
assert reduced == [x0*z, x0*w]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
from symengine.test_utilities import raises
|
2
|
+
|
3
|
+
from symengine import symbols, DictBasic, sin, Integer
|
4
|
+
|
5
|
+
|
6
|
+
def test_DictBasic():
|
7
|
+
x, y, z = symbols("x y z")
|
8
|
+
d = DictBasic({x: 2, y: z})
|
9
|
+
|
10
|
+
assert str(d) == "{x: 2, y: z}" or str(d) == "{y: z, x: 2}"
|
11
|
+
assert d[x] == 2
|
12
|
+
|
13
|
+
raises(KeyError, lambda: d[2*z])
|
14
|
+
if 2*z in d:
|
15
|
+
assert False
|
16
|
+
|
17
|
+
d[2*z] = x
|
18
|
+
assert d[2*z] == x
|
19
|
+
if 2*z not in d:
|
20
|
+
assert False
|
21
|
+
assert set(d.items()) == {(2*z, x), (x, Integer(2)), (y, z)}
|
22
|
+
|
23
|
+
del d[x]
|
24
|
+
assert set(d.keys()) == {2*z, y}
|
25
|
+
assert set(d.values()) == {x, z}
|
26
|
+
|
27
|
+
e = y + sin(2*z)
|
28
|
+
assert e.subs(d) == z + sin(x)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
from symengine.test_utilities import raises
|
2
|
+
from symengine import (Symbol, sin, cos, Integer, Add, I, RealDouble, ComplexDouble, sqrt)
|
3
|
+
|
4
|
+
from unittest.case import SkipTest
|
5
|
+
|
6
|
+
def test_eval_double1():
|
7
|
+
x = Symbol("x")
|
8
|
+
y = Symbol("y")
|
9
|
+
e = sin(x)**2 + cos(x)**2
|
10
|
+
e = e.subs(x, 7)
|
11
|
+
assert abs(e.n(real=True) - 1) < 1e-9
|
12
|
+
assert abs(e.n() - 1) < 1e-9
|
13
|
+
|
14
|
+
|
15
|
+
def test_eval_double2():
|
16
|
+
x = Symbol("x")
|
17
|
+
e = sin(x)**2 + sqrt(2)
|
18
|
+
raises(RuntimeError, lambda: e.n(real=True))
|
19
|
+
assert abs(e.n() - sin(x)**2.0 - 1.414) < 1e-3
|
20
|
+
|
21
|
+
def test_n():
|
22
|
+
x = Symbol("x")
|
23
|
+
raises(RuntimeError, lambda: x.n(real=True))
|
24
|
+
assert x.n() == x + 0.0
|
25
|
+
|
26
|
+
x = 2 + I
|
27
|
+
raises(RuntimeError, lambda: (x.n(real=True)))
|
28
|
+
|
29
|
+
x = sqrt(Integer(4))
|
30
|
+
y = RealDouble(2.0)
|
31
|
+
assert x.n(real=True) == y
|
32
|
+
|
33
|
+
x = 1 + 2*I
|
34
|
+
y = 1.0 + 2.0*I
|
35
|
+
assert x.n() == y
|
36
|
+
|
37
|
+
|
38
|
+
def test_n_mpfr():
|
39
|
+
x = sqrt(Integer(2))
|
40
|
+
try:
|
41
|
+
from symengine import RealMPFR
|
42
|
+
y = RealMPFR('1.41421356237309504880169', 75)
|
43
|
+
assert x.n(75, real=True) == y
|
44
|
+
except ImportError:
|
45
|
+
raises(ValueError, lambda: (x.n(75, real=True)))
|
46
|
+
raises(ValueError, lambda: (x.n(75)))
|
47
|
+
raise SkipTest("No MPFR support")
|
48
|
+
|
49
|
+
|
50
|
+
def test_n_mpc():
|
51
|
+
x = sqrt(Integer(2)) + 3*I
|
52
|
+
try:
|
53
|
+
from symengine import ComplexMPC
|
54
|
+
y = ComplexMPC('1.41421356237309504880169', '3.0', 75)
|
55
|
+
assert x.n(75) == y
|
56
|
+
except ImportError:
|
57
|
+
raises(Exception, lambda: (x.n(75, real=True)))
|
58
|
+
raises(ValueError, lambda: (x.n(75, real=False)))
|
59
|
+
raises(ValueError, lambda: (x.n(75)))
|
60
|
+
raise SkipTest("No MPC support")
|
61
|
+
|
62
|
+
|
63
|
+
def test_rel():
|
64
|
+
x = Symbol("x")
|
65
|
+
y = Symbol("y")
|
66
|
+
ex = (x + y < x)
|
67
|
+
assert repr(ex) == "x + y < x"
|