Often I have to do perform a succession of substitutions on some expression, and in a notebook the way I know to do that is
((((expr /. subst1) /.subst2) /.subst3) ...
So everytime I want to add a substitution I have to go back at the beginning of the line and add a (
and then go at the end of the line and add a )
and then put the new substitution.
Is there a more comfortable way to do that? Something like
expr // function1 // function2 // function3 ...
On the same line, when I have to both apply functions and substitution I have to use again the brackets, because
expr // function1 /. subst1 // function2...
mess up the order in which things are done: function2
is applied to subst1
which is then applied to function1
which is then applied to expr
.
ReplaceAll
has an operator form.expr // ReplaceAll[expr -> 1] // ReplaceAll[1 -> 2]
$\endgroup$expr /. subst1 /.subst2 /.subst3
. $\endgroup$Fold
convenient: e.g.,substitutions = {a -> 1, b -> d, c -> 2, d -> 3}; Fold[ReplaceAll, {a, b, c, d}, substitutions]
. $\endgroup$expr/.{subst1,subst2,subst3}
. It they are not independent,expr//.{subst1,subst2,subst3}
might give you the answer you need. $\endgroup$