sympy

sympy

Tools that facilitate in building sympy expressions.

class UnevaluatedExpression(*args: Any, name: Optional[str] = None, **hints: Any)[source]

Bases: Expr

Base class for classes that expressions with an evaluate() method.

Derive from this class when decorating a class with implement_expr() or implement_doit_method(). It is important to derive from UnevaluatedExpression, because an evaluate() method has to be implemented.

DecoratedClass

TypeVar for decorators like make_commutative.

alias of TypeVar(‘DecoratedClass’)

implement_expr(n_args: int) Callable[[DecoratedClass], DecoratedClass][source]

Decorator for classes that derive from UnevaluatedExpression.

Implement a __new__ and doit method for a class that derives from Expr (via UnevaluatedExpression).

implement_new_method(n_args: int) Callable[[DecoratedClass], DecoratedClass][source]

Implement __new__() method for an UnevaluatedExpression class.

Implement a __new__ method for a class that derives from Expr (via UnevaluatedExpression).

implement_doit_method(decorated_class: DecoratedClass) DecoratedClass[source]

Implement doit() method for an UnevaluatedExpression class.

Implement a doit method for a class that derives from Expr (via UnevaluatedExpression).

make_commutative(decorated_class: DecoratedClass) DecoratedClass[source]
create_expression(cls: Type[UnevaluatedExpression], *args: Any, evaluate: bool = False, name: Optional[str] = None, **kwargs: Any) Expr[source]

Helper function for implementing Expr.__new__.

See e.g. source code of BlattWeisskopfSquared.

create_symbol_matrix(name: str, m: int, n: int) MutableDenseMatrix[source]

Create a Matrix with symbols as elements.

The MatrixSymbol has some issues when one is interested in the elements of the matrix. This function instead creates a Matrix where the elements are Indexed instances.

To convert these Indexed instances to a Symbol, use symplot.substitute_indexed_symbols().

>>> create_symbol_matrix("A", m=2, n=3)
Matrix([
[A[0, 0], A[0, 1], A[0, 2]],
[A[1, 0], A[1, 1], A[1, 2]]])

Submodules and Subpackages