3

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?

corey979
  • 23,947
  • 7
  • 58
  • 101
mattiav27
  • 6,677
  • 3
  • 28
  • 64
  • 6
    Simplify[a^3 b, {a^2 == c, a b == d}] will return c d. Replacement rules will look for a pattern match, and won't really consider the underlying math. Since Power[a, 2] is not present as such in Times[Power[a,3], b], it does not get replaced. – MarcoB Jan 27 '17 at 17:36
  • So there is no way. Thanks. – mattiav27 Jan 27 '17 at 17:39
  • 2
    http://mathematica.stackexchange.com/q/3822/121 – Mr.Wizard Jan 27 '17 at 17:44

2 Answers2

3

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 *)
mikado
  • 16,741
  • 2
  • 20
  • 54
1

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

corey979
  • 23,947
  • 7
  • 58
  • 101