concepts.dm.crow.crow_expression_utils.crow_flatten_expression#
- crow_flatten_expression(expr, mappings=None, ctx=None, deep=True, flatten_cacheable_expression=True)[source]#
Flatten an expression by replacing certain variables or function applications with sub-expressions. The input mapping is a dictionary of {expression: sub-expression}. There are two cases:
- The expression is a
VariableExpression
, and the sub-expression is a Variable
or aValueOutputExpression
. In this case, the variable expression will is the sub-expression used for replacing the variable.
- The expression is a
- The expression is a
FunctionApplicationExpression
, and the sub-expression is a Variable
. Here, the function application expression must be a “simple” function application expression, i.e., it contains only variables as arguments. The Variable will replace the entire function application expression.
- The expression is a
- Parameters:
expr (Expression) – the expression to flatten.
mappings (Dict[FunctionApplicationExpression | VariableExpression, Variable | ObjectOrValueOutputExpression] | None) – a dictionary of {expression: sub-expression} to replace the expression with the sub-expression.
ctx (ExpressionDefinitionContext | None) – a
ExpressionDefinitionContext
.deep (bool) – whether to recursively flatten the expression (expand derived functions). Default is True.
flatten_cacheable_expression (bool) – whether to flatten cacheable expressions. If False, cacheable function applications will be kept as-is.
- Returns:
the flattened expression.
- Return type:
ObjectOrValueOutputExpression | VariableAssignmentExpression