3
$\begingroup$

This question already has an answer here:

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?

$\endgroup$

marked as duplicate by MarcoB, m_goldberg, Jason B., Community Jan 27 '17 at 19:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 6
    $\begingroup$ 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. $\endgroup$ – MarcoB Jan 27 '17 at 17:36
  • $\begingroup$ So there is no way. Thanks. $\endgroup$ – mattiav27 Jan 27 '17 at 17:39
  • 2
    $\begingroup$ mathematica.stackexchange.com/q/3822/121 $\endgroup$ – Mr.Wizard Jan 27 '17 at 17:44
3
$\begingroup$

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 *)
$\endgroup$
1
$\begingroup$

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

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.