Is this an error/bug with Plot Command? [duplicate]

This question already has an answer here:

I've tried doing:

Plot[x^(2/3), {x, -10, 10}]

and I get Which is wrong, since the cubic root can receive negative numbers. Also when I plot something supposedly equivalent

Plot[(x^2)^(1/3), {x, -10, 10}]

I get I would understand this kind of behaviour by the Plot command if instead of (1/3) we had (1/even number). But with (1/odd number) the domain of the function should be all the real numbers. Or am I wrong??

marked as duplicate by Sjoerd C. de Vries, Karsten 7., RunnyKine, Öskå, m_goldbergOct 24 '14 at 2:32

• try N@(-1)^(2/3) ... – Dr. belisarius Oct 23 '14 at 15:37
• @belisarius (-1)^(1/3) // N gives 0.5 + 0.866025 I which is wrong... -1*-1*-1= -1 – An old man in the sea. Oct 23 '14 at 15:40
• @belisarius (0.5000000000000001 + 0.8660254037844386 I)^3 gives -1. + 3.88578*10^-16 I – An old man in the sea. Oct 23 '14 at 15:43
• Look at Series[a^x, {x, 0, 5}] and replace a by -1 – Dr. belisarius Oct 23 '14 at 15:43
• @belisarius, I'm sorry, but I'm not understanding what you mean. You're saying that Plot uses series approximations instead of the true functions? – An old man in the sea. Oct 23 '14 at 15:47

You can see the root of this behaviour (no pun intended) as follows:

(-1)^(2/3)//ComplexExpand
(*
==> -1/2 + (I/2)*Sqrt
*)

You can also check that this solution is correct, by doing

%^(3/2)
(*
==> -1
*)

So what is happening? Strictly speaking, a non-integer power does not have a single value, but many values. For example, there are two values of $1^{1/2}$, namely $+1$ and $-1$, because $1^2=(-1)^2=1$. Therefore when calculating the power, you have to choose one.

When the base is real and positive, the convention is to take the root that also is real and positive. However, what to take when the base is negative?

Your expectation is that for odd denominator of the exponent, you would get the root that is real and negative. When considering the function as a purely real one, this makes sense, because after all, in the real numbers there exists no other solution (and for other denominators, there's generally no solution at all).

However Mathematica interprets this as complex exponentiation, as shown above. And for complex exponentiation, it makes more sense to use the same rule as for other exponents (where you don't have a real solution), and this is done using a so-called branch cut.

To understand what this means, consider that you can write every complex number in polar form as $z=r\mathrm e^{\mathrm i\phi}$ with $r\ge 0$ and $\phi$ in some half-open interval of length $2\pi$ (because adding $2\pi$ to $\phi$ gives the same number $z$ again). The selection of the interval is exactly what determines the so-called branch cut (that is, in the end the branch cut determines which of the infinitely many possible values of $\phi$ is chosen for a given $z$).

Mathematica uses the interval $(-\pi,\pi]$, which has the nice property that you get the intuitive result $(-1)^{1/2}=\mathrm i$ and also plays well with complex conjugation.

Now in polar form, simple arithmetics gives you $z^\alpha = r^\alpha \mathrm e^{\mathrm i\phi\alpha}$. Nor consider the famous formula $\mathrm e^{\mathrm i\pi}=-1$, and you immediately get $(-1)^{2/3} = \mathrm e^{2\mathrm i\pi/3}=-\frac{1}{2}+\mathrm i\frac{1}{2}\sqrt{3}$, which is indeed the result Mathematica gives you, as shown above.

So why does Plot show nothing in the negative area? Well, simply because only real numbers are plotted.

And finally, why does (x^2)^(1/3) give the result you desired? Well, let's look again at the case $-1$: $(-1)^2=1$, and $1^{1/3}=1$. You can verify both results in the polar representation with the chosen branch cut.

Generally, the rule $(a^b)^c=a^{bc}$ only holds if either $a>0$ or $b$ and $c$ are integers. Neither is the case in your code for $x<0$.

The following gives you the real solution if it exists (probably there are simpler ways, but I don't know them):

realpower[x_, y_Rational] :=
If[x>=0 || Denominator[y]==1, x^y,
Module[{tmp, sol},
sol=Solve[tmp^Denominator[y] == x^Numerator[y], tmp, Reals];
If[sol=={},Undefined,tmp/.First@sol]]]
• So, by default it represents the number in polar form. Is there a way to make plot use real numbers usual representation only? Because the left side is still missing... – An old man in the sea. Oct 23 '14 at 16:16
• Also, thanks for you answer. – An old man in the sea. Oct 23 '14 at 16:20
• @Anoldmaninthesea.: Actually, it is not the representation, but the definition of the complex power. It's just easiest described in the polar representation (most probably, internally the formula $x^y=\exp(y\ln x)$ is used, together with an appropriate branch cut for $\ln x$). However see my edit for a function that does what you want (but probably has a lot of room for improvement). – celtschk Oct 23 '14 at 16:33
• Ok. Many thanks ;) – An old man in the sea. Oct 23 '14 at 17:30
• Instead of realpower, you should look into Surd and CubeRoot. – Chip Hurst Oct 28 '14 at 15:42

Briefly, although (-3)^3 is -27 the reverse is not so, because -3 is just one amongst other possible answer, so the answer is kept in the complex form. E.g. These are the possible answers:- 