Supported Subset of SymPy

Supported Subset of SymPy#

This page lists the parts of SymPy’s symbolic algebra toolbox that pystencils is able to parse and translate into code. This includes a list of restrictions and caveats.

sympy.core#

Symbols

sp.Symbol

Represent untyped variables

Integers

sp.Integer

Rational Numbers

sp.Rational

Non-integer rationals are interpreted using the division operation of their context’s data type.

Arbitrary-Precision Floating Point

sp.Float

Will initially be narrowed to double-precision (aka. the Python float type),

Transcendentals: \(\pi\) and \(e\)

sp.pi, sp.E

Only valid in floating-point contexts. Will be rounded to the nearest number representable in the respective data type (e.g. pi = 3.1415927 for float32).

Infinities (\(\pm \infty\))

sp.Infinity, sp.NegativeInfinity

Only valid in floating point contexts.

Arithmetic

sp.Add, sp.Mul, sp.Pow,

Integer powers up to \(8\) will be expanded by pairwise multiplication. Negative integer powers will be replaced by divisions. Square root powers with a numerator \(\le 8\) will be replaced by (products of) the sqrt function.

Relations (==, <=, >, …)

sp.Relational

Result has type boolean and can only be used in boolean contexts.

(Nested) Tuples

sp.Tuple

Tuples of expressions are interpreted as array literals. Tuples that contain further nested tuples must have a uniform, cuboid structure, i.e. represent a proper n-dimensional array, to be parsed as multidimensional array literals; otherwise an error is raised.

sympy.functions#

Trigonometry

sp.sin, sp.asin, …

Only valid in floating-point contexts

Hyperbolic Functions

sp.sinh, sp.cosh,

Only valid in floating-point contexts

Exponentials

sp.exp, sp.log,

Only valid in floating-point contexts

Absolute

sp.Abs

Rounding

sp.floor, sp.ceiling

Result will have the same data type as the arguments, so in order to get an integer, a type cast is additionally required (see tcast)

Min/Max

sp.Min, sp.Max

Piecewise Functions

sp.Piecewise

Cases of the piecewise function must be exhaustive; i.e. end with a default case.

sympy.logic#

Boolean atoms

sp.true, sp.false

Basic boolean connectives

sp.And, sp.Or, sp.Not

sympy.tensor#

Indexed Objects

sp.Indexed

Base of the indexed object must have a PsArrayType of the correct dimensionality. Currently, only symbols (sp.Symbol or TypedSymbol) can be used as the base of an Indexed.