sym package¶
Unified wrapper for symbolic manipulation libraries in Python.
Submodules¶
sym.backend module¶
-
sym.backend.
Backend
(name=None, envvar='SYM_BACKEND', default='sympy')[source]¶ Backend for the underlying symbolic manipulation packages
Parameters: name: str (default: None)
Name of package e.g. ‘sympy’
envvar: str (default: ‘SYM_BACKEND’)
name of environment variable to read name from (when name is
None
)default: str
name to use when the environment variable described by
envvar
is unset or empty (default: ‘sympy’)Examples
>>> be = Backend('sympy') # or e.g. 'symengine' >>> x, y = map(be.Symbol, 'xy') >>> exprs = [x + y + 1, x*y**2] >>> lmb = be.Lambdify([x, y], exprs) >>> import numpy as np >>> lmb(np.arange(6.0).reshape((3, 2))) array([[ 2., 0.], [ 6., 18.], [ 10., 100.]])
sym.util module¶
-
sym.util.
banded_jacobian
(y, x, ml, mu)[source]¶ Calculates a banded version of the jacobian
Compatible with the format requested by
scipy.integrate.ode()
(for SciPy >= v0.15).Parameters: y: array_like of expressions
x: array_like of symbols
ml: int
number of lower bands
mu: int
number of upper bands
Returns: 2D array of shape
(1+ml+mu, len(y))
-
sym.util.
check_transforms
(fw, bw, symbs)[source]¶ Verify validity of a pair of forward and backward transformations
Parameters: fw: expression
forward transformation
bw: expression
backward transformation
symbs: iterable of symbols
the variables that are transformed
-
sym.util.
linear_rref
(A, b, backend)[source]¶ Transform a linear system to reduced row-echelon form
Transforms both the matrix and right-hand side of a linear system of equations to reduced row echelon form
Parameters: A: Matrix-like
iterable of rows
b: iterable
Returns: A’, b’ - transformed versions
-
sym.util.
sparse_jacobian_csc
(y, x)[source]¶ - Calculates a compressed sparse column (CSC)
- version of the jacobian
Parameters: y: array_like of expressions
x: array_like of symbols
Returns: jac_exprs: flattened list of expressions for nonzero entries of dy/dx in column-major order
colptrs: list of length
len(y) + 1
, wherejac_exprs[colptrs[i]:colptrs[i+1]]
arethe nonzero entries of column
i
indy/dx
rowvals: list of length
len(jac_exprs
, denoting the row index indy/dx
for eachentry in
jac_exprs
-
sym.util.
sparse_jacobian_csr
(y, x)[source]¶ - Calculates a compressed sparse row (CSR)
- version of the jacobian
Parameters: y: array_like of expressions
x: array_like of symbols
Returns: jac_exprs: flattened list of expressions for nonzero entries of dy/dx in row-major order
rowptrs: list of length
len(y) + 1
, wherejac_exprs[colptrs[i]:colptrs[i+1]]
arethe nonzero entries of row
i
indy/dx
colvals: list of length
len(jac_exprs
, denoting the column index indy/dx
for eachentry in
jac_exprs