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'm trying to find a way to have Mathematica always represent a numerical value as a self defined variable that I define using lhs=rhs. For example, if I execute

In[1]:=Solve[x^3 - 1 == 0, x]
Out[1]:={{x -> 1}, {x -> -(-1)^(1/3)}, {x -> (-1)^(2/3)}}

What I'd like is to define a variable rho=(-1)^(1/3) so that when I execute the above I get out something like

In[1]:=Solve[x^3 - 1 == 0, x]
Out[1]:={{x -> 1}, {x -> -rho}, {x -> rho^2}}

Is this possible? I'm basically trying to get mathematica to always represent an $n$th root of unity as a given symbol to clean up inputs and outputs.

share|improve this question
David, if you register and link your account with your profile, you'll start with 101 rep and you'll have access to other basic functionalities of the site – R. M. May 11 '12 at 23:41
@R.M Thanks for the tip! I didn't realize I had to do that. – David K. May 11 '12 at 23:42
Also, I assume you're looking for a general solution and not just for the cube roots, right? i.e., if you type Solve[x^n -1 == 0, x], you get {1, r, r^2, ..., r^n-1}? – R. M. May 11 '12 at 23:43
@R.M Well, a general solution would be kinda neat, that's a little more than I'd had in mind. I was just thinking I could define a symbol for say the primitive 3rd root of unity and have mathematica replace (-1)^{1/3} with that symbol whenever it appears. – David K. May 11 '12 at 23:48
up vote 5 down vote accepted

My solution below uses TagSetDelayed and associates the transformation rules with Power. Although I very much dislike using structural manipulations for such purposes, it might be a viable option here since the use case is narrow.

Power /: Power[-1, Rational[n_Integer, _]] := ρ^n

enter image description here

enter image description here

If you want to define it only for the cube roots of unity, you needn't use a general pattern like the above. Instead, restrict it by changing the _ to 3.

share|improve this answer

The most basic form of this could be implemented as a replacement rule in $Post:

$Post = # /. (-1)^(1/3) -> rho &;

As you can see however this doesn't handle the compound case:

Solve[x^3 - 1 == 0, x]
{{x -> 1}, {x -> -rho}, {x -> (-1)^(2/3)}}

If it is sufficient to include various specific cases in your replacement rules function ($Post) then this should be a solution. If you need to "find" the expression within a compound one, I believe you can adapt and integrate Daniel's PolynomialReduce method.

share|improve this answer
While accepted R.M.'s answer for being the most generalizable solution to my issue. I just wanted to mention that your solution is easiest to implement and ended up being the one that I used for my particular task. – David K. May 14 '12 at 0:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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