Consider the following case:
(a^3*b) //. {a^2 -> c, a*b -> d}
instead of c d the output is:
(*a^3*b*)
How can I get what I want?
Consider the following case:
(a^3*b) //. {a^2 -> c, a*b -> d}
instead of c d the output is:
(*a^3*b*)
How can I get what I want?
In general, you want to make the left hand sides of your rules as simple as possible. A simple way of doing what you want is
(a^3*b) //. {a -> Sqrt[c], b -> d/a}
(* c d *)
How about
Last@PolynomialReduce[a^3*b, {a^2 - c, a*b - d}, {a, b}]
c d
Or a more tricky
a^3*b //. {a^n_ :> c*Quotient[n, 2]*a^Mod[n, 2],
Times[r1___, a, b, r2___] :> Times[d, r1, r2]}
c d
Simplify[a^3 b, {a^2 == c, a b == d}]will returnc d. Replacement rules will look for a pattern match, and won't really consider the underlying math. SincePower[a, 2]is not present as such inTimes[Power[a,3], b], it does not get replaced. – MarcoB Jan 27 '17 at 17:36