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
strexpression, instead of hard-to-debug 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 one-dimensional 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 scalar-valued |
|
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.ParametricObjectA symbolic math expression
- to_numpy(self, variables)[source]¶
Convert expression to a
NumPy-vectorized callable.Parameters
- variables
List of names of
~Parametersin the expression which shall be treated as input variables.
- class pymor.analyticalproblems.expressions.BaseConstant[source]¶
Bases:
ExpressionA constant value.
- class pymor.analyticalproblems.expressions.Constant(value)[source]¶
Bases:
BaseConstantA constant value given by a
NumPyarray.
- class pymor.analyticalproblems.expressions.Parameter(name, dim)[source]¶
Bases:
ExpressionA free parameter in an
Expression.Parameters represent both pyMOR
Parametersas 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:
ExpressionAn array of scalar-valued
Expressions.
- class pymor.analyticalproblems.expressions.BinaryOp(first, second)[source]¶
Bases:
ExpressionCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Neg(operand)[source]¶
Bases:
ExpressionNegated
Expression.
- class pymor.analyticalproblems.expressions.Indexed(base, index)[source]¶
Bases:
ExpressionIndexed
Expression.
- class pymor.analyticalproblems.expressions.UnaryFunctionCall(*arg)[source]¶
Bases:
ExpressionCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.UnaryReductionCall(*arg)[source]¶
Bases:
ExpressionCompound
Expressionof an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression 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:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Diff(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Prod(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Div(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Pow(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Mod(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.LE(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.GE(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.LT(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.GT(first, second)[source]¶
Bases:
BinaryOpCompound
Expressionof a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.sin(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.cos(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.tan(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arcsin(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arccos(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arctan(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sinh(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.cosh(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.tanh(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arcsinh(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arccosh(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arctanh(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.exp(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.exp2(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.log(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.log2(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.log10(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sqrt(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.abs(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sign(*arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.angle(arg)[source]¶
Bases:
UnaryFunctionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.norm(*arg)[source]¶
Bases:
UnaryReductionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.min(*arg)[source]¶
Bases:
UnaryReductionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.max(*arg)[source]¶
Bases:
UnaryReductionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.sum(*arg)[source]¶
Bases:
UnaryReductionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.prod(*arg)[source]¶
Bases:
UnaryReductionCallCompound
Expressionof an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.Pi[source]¶
Bases:
BaseConstantA constant value.
- class pymor.analyticalproblems.expressions.E[source]¶
Bases:
BaseConstantA constant value.