# Representing a value in an output as a self defined variable

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.

• David, if you register and link your account with your math.se profile, you'll start with 101 rep and you'll have access to other basic functionalities of the site – rm -rf 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}? – rm -rf 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

## 2 Answers

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.

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


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.

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.

• 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