Function sequant::replace(ResultExpr&, const ExprMatcher&, const Expr&)

Function Documentation

ResultExpr &sequant::replace(ResultExpr &expr, const ExprMatcher &target, const Expr &replacement)

Replaces a given target expression by a given replacement. Result indices are adapted as needed.

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

Returns:

A reference to expr, which has been modified in-place (useful for chaining)