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 K.

Posted 2012-05-11T23:38:19.350

Reputation: 213

2David, 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 – rm -rf – 2012-05-11T23:41:47.990

@R.M Thanks for the tip! I didn't realize I had to do that. – David K. – 2012-05-11T23:42:49.080

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 – 2012-05-11T23:43:08.160

@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. – 2012-05-11T23:48:47.060



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.

rm -rf

Posted 2012-05-11T23:38:19.350

Reputation: 85 395


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.


Posted 2012-05-11T23:38:19.350

Reputation: 259 163

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. – 2012-05-14T00:10:25.413