# Rewriting one expression using a variable representing another expression [duplicate]

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.

• – Szabolcs Jun 5 '14 at 18:13
• For me it's "immediately obvious" that the assumption is wrong – eldo Jun 5 '14 at 18:18
• @eldo That was a typo, sorry. And my writing is poor, so I apologize if it sounded arrogant. – O.C. Jun 5 '14 at 18:24
• @Öskå I have provided the Mathematica version of the expressions, sorry. – O.C. Jun 5 '14 at 18:26

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:

Clear[w1];

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][] // Simplify


w1^3

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, #][] // Simplify) & /@ Variables[w2]


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

• Very very good ! – eldo Jun 5 '14 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  *)