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`
– Daniel Lichtblau Oct 05 '16 at 15:17FullSimplify[ax + b, Assumptions -> (-ax - b == -z)]– Frank Martin Oct 05 '16 at 15:24Simplify[ax + b, (-ax - b == -z)]– Frank Martin Oct 05 '16 at 15:32Simplify[a*x + b, -a*x - b == -z]returns 'z' for me and alsoSimplify[a*x + b, -a*x - b == z]returns '-z' for me. Could you please check that? (I'm working in Mathematica 11) – Frank Martin Oct 06 '16 at 08:24