For example, the substitution (x + y) -> s fails here:
In[1]:= (-x - y) /. (x + y) -> s
Out[1]= -x - y
Of course, I could try applying the rule (-x - y) -> -s, but this strategy becomes unwieldy in more complicated cases. At the very least it would require duplicating a lot of rules. For example, if the expression to be transformed were something like
(x + y)^2 + 2 (-x - y)
...then I'd need to use something like
{(x + y) -> s, (-x - y) -> -s}
Is there a better way to transform the above expression to s^2 - 2 s?
expr /. x -> (s - y)– Kuba Jan 16 '14 at 20:03FullForm[x + y]andFullForm[-x - y]to see how those two expressions are different (orTreeFormif you are feeling daring).ReplaceAllis a dumb function that is not going to transform your expression for you. It may not be friendly, but it is reliable. In general, as Kuba has suggested, it's better to replace atomic elements. – wxffles Jan 16 '14 at 21:54EliminateorGroebnerBasistoo, e.g. like here It depends on the situation if they work well. – Szabolcs Jan 16 '14 at 23:24