Extensions to SymPy#
Symbol Factory#
Functions#
Takes a sequence and returns the product of all elements |
|
Scalar product between two sequences. |
|
Kronecker delta for variable number of arguments, 1 if all args are equal, otherwise 0 |
|
Approximation of step function by a tanh function |
|
Multidimensional summation |
Expression Analysis#
Simple version of checking if a sympy expression is constant. |
|
Finds least common multiple of all denominators occurring in an expression |
|
Returns the symmetric part of a sympy expressions. |
|
Counts the number of additions, multiplications and division. |
|
Counts number of operations in an abstract syntax tree, see also |
Expression Rewriting and Simplifications#
Removes all sp.Float objects whose absolute value is smaller than threshold |
|
Checks if all elements of the passed sequence can be cast to integers |
|
Expects a sympy expression that can be interpreted as a product and returns a list of all factors. |
|
Similar to itertools.product but yields only values where the index is ascending i.e. values below/up to diagonal. |
|
Similar to sympy subs function. |
|
Transformation for replacing a given subexpression inside a sum. |
|
Replaces second order mixed terms like 4*x*y by 2*( (x+y)**2 - x**2 - y**2 ). |
|
Removes all terms that contain more than 'order' factors of given 'symbols' |
|
Transforms second order polynomial into only squared part. |
|
Completes squares in arguments of exponential which makes them simpler to integrate. |
|
Processes a sum of fractions: determines the most common factor and splits term in common factor and rest |
|
Applies sympy.collect recursively for a list of symbols, collecting symbol 2 in the coefficients of symbol 1, and so on. |
|
Uses the equality a = b + c, where a and b must be symbols, to simplify expr by attempting to express additive combinations of two quantities by the third. |
Typed Expressions#
- class pystencils.TypedSymbol(*args, **kwds)#
- class pystencils.DynamicType(value)#
Dynamic data type that will be resolved during kernel creation
- NUMERIC_TYPE = 1#
Use the default numeric type set for the kernel
- INDEX_TYPE = 2#
Use the default index type set for the kernel.
This is guaranteed to be an interger type.
- class pystencils.sympyextensions.typed_sympy.TypeCast(expr, tatom)#
Explicitly cast an expression to a data type.
- Parameters:
expr (sp.Basic)
tatom (TypeAtom)
- Return type:
TypeCast | None
- classmethod eval(expr, tatom)#
Returns a canonical form of cls applied to arguments args.
Explanation#
The
eval()
method is called when the classcls
is about to be instantiated and it should return either some simplified instance (possible of some other class), or if the classcls
should be unmodified, return None.Examples of
eval()
for the function “sign”@classmethod def eval(cls, arg): if arg is S.NaN: return S.NaN if arg.is_zero: return S.Zero if arg.is_positive: return S.One if arg.is_negative: return S.NegativeOne if isinstance(arg, Mul): coeff, terms = arg.as_coeff_Mul(rational=True) if coeff is not S.One: return cls(coeff) * cls(terms)
Integer Operations#
C-style round-to-zero integer division |
|
C-style round-to-zero integer remainder |
|
Returns the next smaller/equal in magnitude integer divisible by given divisor. |
|
For positive input, returns the next greater/equal integer divisible by given divisor. |
|
For positive input, integer division that is always rounded up, i.e. |