# obtaining real roots of negative numbers in a long expression [duplicate]

I have a complicated symbolic expression which contains many terms like $(a/(a-2))^{1/m}$, where $a/(a-2)$ could be positive or negative after replacement.

I only need the real root after replacement, but Power[] function in Mathematica most of the time gives me a complex number instead. I found something that almost suits my need here (the realPower function by Peter Breitfeld), but I have a hard time get it working in the way I want.

For example:

((a/(-2 + a))^(1/3) /. {x_^y_ :> realPower[x, y]}) /. {a -> 0.5}


still gives me a complex number. (it seems that realPower only work with numerical values) What should I do to get only the real root after replacement?

• If you read another answers to the question you linked to in your post you wouldn't have asked this one. – Artes Sep 25 '13 at 21:25

Surd is your friend:

Surd[a/(-2 + a), 3] /. a -> 0.5


-0.693361

It can be entered in formatted form as Esc surd Esc. Surd was introduced in Mathematica 9. In previous versions you can use

((a/(-2 + a))^(1/3) /. {x_^y_ :> Sign[x] Abs[x]^y}) /. {a -> 0.5}


-0.693361