pystencils.AssignmentCollection

pystencils.AssignmentCollection#

class pystencils.AssignmentCollection(main_assignments, subexpressions=None, simplification_hints=None, subexpression_symbol_generator=None)#

A collection of equations with subexpression definitions, also represented as assignments, that are used in the main equations. AssignmentCollection can be passed to simplification methods. These simplification methods can change the subexpressions, but the number and left hand side of the main equations themselves is not altered. Additionally a dictionary of simplification hints is stored, which are set by the functions that create assignment collections to transport information to the simplification system.

Parameters:
  • main_assignments (Union[List[Assignment], Dict[Expr, Expr]]) – List of assignments. Main assignments are characterised, that the right hand side of each assignment is a field access. Thus the generated equations write on arrays.

  • subexpressions (Union[List[Assignment], Dict[Expr, Expr], None]) – List of assignments defining subexpressions used in main equations

  • simplification_hints (Optional[Dict[str, Any]]) – Dict that is used to annotate the assignment collection with hints that are used by the simplification system. See documentation of the simplification rules for potentially required hints and their meaning.

  • subexpression_symbol_generator (Optional[Iterator[Symbol]]) – Generator for new symbols that are used when new subexpressions are added used to get new symbols that are unique for this AssignmentCollection

Methods

__init__(main_assignments[, subexpressions, ...])

add_simplification_hint(key, value)

Adds an entry to the simplification_hints dictionary and checks that is does not exist yet.

add_subexpression(rhs[, lhs, topological_sort])

Adds a subexpression to current collection.

atoms(*args)

copy([main_assignments, subexpressions])

Returns a copy with optionally replaced main_assignments and/or subexpressions.

dependent_symbols(symbols)

Returns all symbols that depend on one of the passed symbols.

find(*args, **kwargs)

lambdify(symbols[, fixed_symbols, module])

Returns a python function to evaluate this equation collection.

match(*args, **kwargs)

new_filtered(symbols_to_extract)

Extracts equations that have symbols_to_extract as left hand side, together with necessary subexpressions.

new_merged(other)

Returns a new collection which contains self and other.

new_with_inserted_subexpression(symbol)

Eliminates the subexpression with the given symbol on its left hand side, by substituting it everywhere.

new_with_substitutions(substitutions[, ...])

Returns new object, where terms are substituted according to the passed substitution dict.

new_without_subexpressions([...])

Returns a new collection where all subexpressions have been inserted.

new_without_unused_subexpressions()

Returns new collection that only contains subexpressions required to compute the main assignments.

replace(*args, **kwargs)

set_main_assignments_from_dict(...)

set_sub_expressions_from_dict(...)

subs(*args, **kwargs)

topological_sort([sort_subexpressions, ...])

Sorts subexpressions and/or main_equations topologically to make sure symbol usage comes after definition.

Attributes

all_assignments

Subexpression and main equations as a single list.

bound_fields

All field accessed on the left hand side of a main assignment or a subexpression.

bound_symbols

All symbols which occur on the left hand side of a main assignment or a subexpression.

defined_symbols

All symbols which occur as left-hand-sides of one of the main equations

free_fields

All fields accessed in the assignment collection, which do not occur as left hand sides in any assignment.

free_symbols

All symbols used in the assignment collection, which do not occur as left hand sides in any assignment.

main_assignments_dict

operation_count

See count_operations()

rhs_fields

All fields accessed in the assignment collection, which do not occur as left hand sides in any assignment.

rhs_symbols

All symbols used in the assignment collection, which occur on the rhs of any assignment.

subexpressions_dict