Template Function sequant::replace(ExprPtr&, const ExprPtr&, const ExprPtr&, EqualityComparator)¶
Defined in File expr.hpp
Function Documentation¶
-
template<typename EqualityComparator = std::equal_to<>>
ExprPtr &sequant::replace(ExprPtr &expr, const ExprPtr &target, const ExprPtr &replacement, EqualityComparator cmp = {})¶ Replaces a given target expression by a given replacement
If target and replacement have common indices, the indices in the replacement will be updated for each individual match of target. This is relevant in cases the provided comparator doesn’t account for index equality. For instance, in t{a1;a2} -> r{a1;a5} applied to var * t{a3;a4} the replacement shares the index a1 with the target. If the target gets matched to t{a3;a4}, the replacement will be adapted via a1 -> a3, whereas the index a5 will be left as is. Overall, this would lead to var * r{a3;a5}.
Note
At this time, target must not be a composite expression
- Parameters:
expr – The expression to perform the replacements in
target – The target expression to be replaced
replacement – The expression to replace the target with
cmp – The comparator used to determine equality between expressions
- Returns:
A reference to expr, which has been modified in-place (useful for chaining)