I have two expressions:

w1 = (a+b)/c^2;

w2 = (a^3 + 3 a^2 b + 3 a b^2 + b^3)/c^6;

How can I ask Mathematica to try to find an alternative expression for w2 that just uses the variable w1 ? In the above example, for instance, we can write: w2 == w1^3, however, its not always so obvious how to proceed in general instances where one is asked to rewrite one expression ONLY in terms of a variable representing another expression (or to check if this is possible).

[6-5-2014] I've read through Replace expressions with symbols, and its still confusing exactly how to ask Mathematica to do what I'm specifying in my positing. It would really be helpful to see how to do something like my specific example.

  • $\begingroup$ See also mathematica.stackexchange.com/q/33457/12 $\endgroup$
    – Szabolcs
    Jun 5, 2014 at 18:13
  • $\begingroup$ For me it's "immediately obvious" that the assumption is wrong $\endgroup$
    – eldo
    Jun 5, 2014 at 18:18
  • $\begingroup$ @eldo That was a typo, sorry. And my writing is poor, so I apologize if it sounded arrogant. $\endgroup$
    – O.C.
    Jun 5, 2014 at 18:24
  • $\begingroup$ @Öskå I have provided the Mathematica version of the expressions, sorry. $\endgroup$
    – O.C.
    Jun 5, 2014 at 18:26

2 Answers 2


To have w2 expressed in terms of w1, w1 cannot be assigned a value. If it is assigned a value then Mathematica will always substitute that value for w1. Consequently "define" w1 with an equation:


eq = w1 == (a + b)/c^2;

w2 = (a^3 + 3 a^2 b + 3 a b^2 + b^3)/c^6;

w2 /. Solve[eq, a][[1]] // Simplify


However, in this case at least, you could Solve for any one of the variables in w2 and get the same result.

(w2 /. Solve[eq, #][[1]] // Simplify) & /@ Variables[w2]

{w1^3, w1^3, w1^3}

  • $\begingroup$ Very very good ! $\endgroup$
    – eldo
    Jun 5, 2014 at 20:35

Following @BobHanlon's suggestion to use Equal instead of Set, you can also use Eliminate:

 Eliminate[{w1 == (a + b)/c^2, w2 == (a^3 + 3 a^2 b + 3 a b^2 + b^3)/c^6}, {a, b, c}]
 (*  w2 == w1^3  *)

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