matchpy.expressions.functions module

is_constant(expression)

Check if the given expression is constant, i.e. it does not contain Wildcards.

is_syntactic(expression)

Check if the given expression is syntactic, i.e. it does not contain sequence wildcards or associative/commutative operations.

get_head(expression)

Returns the given expression’s head.

match_head(subject, pattern)

Checks if the head of subject matches the pattern’s head.

preorder_iter(expression)

Iterate over the expression in preorder.

preorder_iter_with_position(expression)

Iterate over the expression in preorder.

Also yields the position of each subexpression.

is_anonymous(expression)

Returns True iff the expression does not contain any variables.

contains_variables_from_set(expression, variables)

Returns True iff the expression contains any of the variables from the given set.

create_operation_expression(old_operation, new_operands, variable_name=True)
rename_variables(expression: matchpy.expressions.expressions.Expression, renaming: Dict[str, str]) → matchpy.expressions.expressions.Expression

Rename the variables in the expression according to the given dictionary.

Parameters:
  • expression – The expression in which the variables are renamed.
  • renaming – The renaming dictionary. Maps old variable names to new ones. Variable names not occuring in the dictionary are left unchanged.
Returns:

The expression with renamed variables.

op_iter(operation)
op_len(operation)
get_variables(expression, variables=None)

Returns the set of variable names in the given expression.