This rule works fine, of course:
a x + b /. a x + b -> z (* z *) However, this one does not:
a x + b /. -a x - b -> -z (* b + a x *) I understand that when one expands the expressions using FullForm the patterns do not match.
This works:
w /. Solve[w == a x + b && z == -a x - b, {w}, {a, x, b}][[1]] (* -z *) But it looks way too complicated. Is there a smarter way?
(Of course in this particular example there is an obvious solution: the first command shown above. Let us assume the perfectly matching pattern is not known)
Thanks for the help.
PolynomialReduce.In[9]:= PolynomialReduce[a x + b, {-a x - b + z}, {a, b}][[2]] Out[9]= z$\endgroup$FullSimplify[ax + b, Assumptions -> (-ax - b == -z)]$\endgroup$Simplify[ax + b, (-ax - b == -z)]$\endgroup$