It's an extremely brief question. I want to replace all variables in an expression to another ones, say $x \rightarrow y$. But the command
x + Subscript[a, x] /. x -> y
replaces also the subscript. How can I do replacements while leaving the Subscript object unchanged?
Answer
When you want to do replacements with a pattern that shouldn't be changed, I like to use multiple replacement rules (as in this answer):
ReplaceAll[
x + Subscript[a, x],
{
s_Subscript :> s, (* pattern to avoid *)
x -> y
}
]
y + Subscript[a, x]
Comments
Post a Comment