sympy

import tensorwaves.function.sympy

Lambdify sympy expression trees to a Function.

create_function(expression: Expr, backend: str, max_complexity: Optional[int] = None, use_cse: bool = True) PositionalArgumentFunction[source]
create_parametrized_function(expression: Expr, parameters: Mapping[Symbol, Union[complex, float]], backend: str, max_complexity: Optional[int] = None, use_cse: bool = True) ParametrizedBackendFunction[source]
fast_lambdify(expression: Expr, symbols: Sequence[Symbol], backend: str, *, min_complexity: int = 0, max_complexity: int, use_cse: bool = True) Callable[source]

Speed up lambdify() with split_expression().

For a simple example of the reasoning behind this, see Speed up lambdifying.

lambdify(expression: Expr, symbols: Sequence[Symbol], backend: str, use_cse: bool = True) Callable[source]

A wrapper around lambdify().

Parameters
  • expression – the sympy.Expr that you want to express as a function in a certain computation back-end.

  • symbols – The Symbol instances in the expression that you want to serve as positional arguments in the lambdified function. Note that positional arguments are ordered.

  • backend – Computational back-end in which to express the lambdified function.

  • use_cse – Lambdify with common sub-expressions (see cse argument in lambdify()).

split_expression(expression: Expr, max_complexity: int, min_complexity: int = 1) Tuple[Expr, Dict[Symbol, Expr]][source]

Split an expression into a ‘top expression’ and several sub-expressions.

Replace nodes in the expression tree of a sympy.Expr that lie within a certain complexity range (see count_ops()) with symbols and keep a mapping of each to these symbols to the sub-expressions that they replaced.