Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

marked as duplicate by Szabolcs, ciao, m_goldberg, RunnyKine, Mr.Wizard Jun 6 '14 at 11:57

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.

See also – 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
up vote 7 down vote accepted

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}

share|improve this answer
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  *)
share|improve this answer

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