pymor.analyticalproblems.expressions
¶
This module contains a basic symbolic expression library.
The library is used by ExpressionFunction
and ExpressionParameterFunctional
by calling parse_expression
, which parses str
expressions by replacing
the names in the string with objects from this module. The result is an
Expression
object, which can be converted to a NumPy
vectorized function
using Expression.to_numpy
. In the future, more conversion routines will
be added to make the same Expression
usable for pymor.discretizers
that use external PDE solvers. Further advantages of using this expression library:
meaningful error messages are generated at parse time of the
str
expression, instead of hardtodebug errors in lambda functions at evaluation time,expressions are automatically correctly vectorized. In particular, there is no longer a need to add
...
to indexing expressions,the shape of the resulting expressions is automatically determined.
In the future, we will also provide support for symbolic differentiation of the
given Expressions
.
Every Expression
is built from the following atoms:
a
Constant
, which is a fixed value of arbitrary shape,a
Parameter
, which is a variable of a fixed onedimensional shape.
Note that both Parameters
and input variables are treated as a Parameter
in the expression. Only when calling, e.g., to_numpy
, it is
determined which Parameter
belongs to the resulting function’s Parameters
and which Parameter
is treated as an input variable.
More complex expressions can be built using:
For binary operations of Expressions
of different shape,
the usual broadcasting rules apply.
Module Contents¶
Classes¶
A symbolic math expression 

A constant value. 

A constant value given by a 

A free parameter in an 

An array of scalarvalued 

Compound 

Negated 

Indexed 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

Compound 

A constant value. 

A constant value. 
Functions¶
Used internally to convert literals/list constructors to an 

Attributes¶
 pymor.analyticalproblems.expressions.parse_expression(expression, parameters={}, values={})[source]¶
 class pymor.analyticalproblems.expressions.Expression[source]¶
Bases:
pymor.parameters.base.ParametricObject
A symbolic math expression
 to_numpy(self, variables)[source]¶
Convert expression to a
NumPy
vectorized callable.Parameters
 variables
List of names of
~Parameters
in the expression which shall be treated as input variables.
 class pymor.analyticalproblems.expressions.BaseConstant[source]¶
Bases:
Expression
A constant value.
 class pymor.analyticalproblems.expressions.Constant(value)[source]¶
Bases:
BaseConstant
A constant value given by a
NumPy
array.
 class pymor.analyticalproblems.expressions.Parameter(name, dim)[source]¶
Bases:
Expression
A free parameter in an
Expression
.Parameters represent both pyMOR
Parameters
as well as input variables. Each parameter is a vector of shape(dim,)
.Parameters
 name
The name of the parameter.
 dim
The dimension of the parameter.
 class pymor.analyticalproblems.expressions.Array(array)[source]¶
Bases:
Expression
An array of scalarvalued
Expressions
.
 class pymor.analyticalproblems.expressions.BinaryOp(first, second)[source]¶
Bases:
Expression
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.Neg(operand)[source]¶
Bases:
Expression
Negated
Expression
.
 class pymor.analyticalproblems.expressions.Indexed(base, index)[source]¶
Bases:
Expression
Indexed
Expression
.
 class pymor.analyticalproblems.expressions.UnaryFunctionCall(arg, *args)[source]¶
Bases:
Expression
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.UnaryReductionCall(arg, *args)[source]¶
Bases:
Expression
Compound
Expression
of an unary function applied to a subexpression.The function is applied to the entire vector/matrix/tensor the subexpression evaluates to, returning a single number.
 pymor.analyticalproblems.expressions._convert_to_expression(obj)[source]¶
Used internally to convert literals/list constructors to an
Expression
.
 class pymor.analyticalproblems.expressions.Sum(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.Diff(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.Prod(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.Div(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.Pow(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.Mod(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.LE(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.GE(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.LT(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.GT(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two subexpressions.
 class pymor.analyticalproblems.expressions.sin(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.cos(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.tan(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.arcsin(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.arccos(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.arctan(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.sinh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.cosh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.tanh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.arcsinh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.arccosh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.arctanh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.exp(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.exp2(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.log(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.log2(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.log10(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.sqrt(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.abs(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.sign(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.angle(arg)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied componentwise.
 class pymor.analyticalproblems.expressions.norm(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied to the entire vector/matrix/tensor the subexpression evaluates to, returning a single number.
 class pymor.analyticalproblems.expressions.min(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied to the entire vector/matrix/tensor the subexpression evaluates to, returning a single number.
 class pymor.analyticalproblems.expressions.max(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied to the entire vector/matrix/tensor the subexpression evaluates to, returning a single number.
 class pymor.analyticalproblems.expressions.sum(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied to the entire vector/matrix/tensor the subexpression evaluates to, returning a single number.
 class pymor.analyticalproblems.expressions.prod(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a subexpression.The function is applied to the entire vector/matrix/tensor the subexpression evaluates to, returning a single number.
 class pymor.analyticalproblems.expressions.Pi[source]¶
Bases:
BaseConstant
A constant value.
 class pymor.analyticalproblems.expressions.E[source]¶
Bases:
BaseConstant
A constant value.