20
Nov 07
Mathematica and the sqrt(x)^2

I found this interesting issue (bug?) in the well known Wolfram Mathematica ® system.

 When you have something like sqrt(x)^2 (where sqrt means the square root, and ^ an exponentiation), what would you expect it to be in a graphic?  Well, some might say it's the graphic of x, but that would be wrong. Although the square root may be associated with the power by two as its inverse function, that's only true for the non-negative side of the x axis.  There's no inverse of x^2, the result is not a function, so you can't simply cancel the functions and return x.

 So, the graphic of this would only be x on the positive side of the x axis, on the negative side the graphic is as possible as the square root of a negative number (mnham, mnham, complexes...), which is impossible if we're in the plane that we're supposed to, the real plane.

Now, here's the Mathematica's graphic of that:

 

graph of sqrt(x)^2 in Mathematica

 



So, or Mathematica simplified the sqrt(x)^2 in x^(1/2)^2, canceled the exponents and returned x, or it simply processed the square root of negative numbers as complexes, which, of course, squared, returns x, but that's not a valid operation in the real plane. 

I find it interesting how respectful systems have bugs like these. 


Go to Blog

Comments

Manuel Marques 20 of November of 2007
Agreed! And with other "not-so-professional" apps, it yields the right solution! Strange :P
Tony 24 of November of 2007
Franco-Pais Paradox FTW!
Dave Bacon 29 of December of 2007
If the domain of x is the complex numbers this is what should happen, right? The square root of a negative x is plus or minus i times the square root of -x. Squaring both of these gives you back x. BTW, for a real bug try Simplify[Sqrt[x]^2, x ∈ Reals] and it gave me x, which is more damning.
Miguel Pais 29 of December of 2007
Exactly Dave, if we were dealing with complexes. But I don't think we're supposed to do that kind of operations in a real plane (i think Mathematica's function Plot deals with the real plane, not the complex one), that way we would end up with what you just said, a simplification of sqrt(x)^2 returns x. In other words, Mathematica is doing what I suspected. It takes sqrt(x) as x^(1/2) and then squares it: x^(1/2)^(2). The problem is, in a expression like this you can't simply cut the 2, and Mathematica is doing that.
greg laden 29 of December of 2007
Is it possible to examine the code in the software to see what is going on here?
Miguel Pais 29 of December of 2007
No, it's not, we can only suspect. Blame it on closed-source software...
greg laden 29 of December of 2007
Just as I thought. http://tinyurl.com/2veddk
Greg 29 of December of 2007
The square of a square root of x must always by definition be x, unless I missed something in my math class about the non-uniqueness of squares. If you feed in real numbers, then you will always get real numbers out, and so Sqrt[x]^2 may legitimately be plotted in the real plane. The problem you mention in the comments is a non-issue -- your plot only required Sqrt[x]^2 to be real, it required nothing of the intermediate expression Sqrt[x]. If you really wanted to force Mathematica to work only in the real plane, you would have to somehow tell that you wanted that, though I am not sure the easiest way to do that.
Joe 29 of December of 2007
I think I agree with Greg (the second one) - x remains real, and the function specified here seems valid. Yes, there is an imaginary intermediate, but you didn't tell mathematica to avoid that, just real in/out. Your complaint would be like objecting to mathematica plotting the Real[Exp[i k x]] as Cos[k x]
Miguel Pais 29 of December of 2007
Alright. Now the way that Mathematica functions is clear. When we try to plot something all the necessary calculus are done, if the result returns complex numbers, those are not plotted, as in Sqrt[x]^3 (x = -1 would return -i ), but when the result gives reals, it's plotted. Nevertheless I think this can confuse people.
Tim Kostka 01 of November of 2008
This isn't a bug. It's absolutely and rigorously correct since you are specifying x as a real number. Although Sqrt[x]^2 is NOT always x, when you use the Plot command and specify the bounds for x, you are specifying x as a REAL NUMBER. If you make a two dimensional plot to cover imaginary numbers, you will see different results. Sqrt[x]^2 = x for ALL real numbers x: If x is real and x >= 0: Sqrt[x] = +/-|x| (+/-|x|)^2 = x If x is real and x < 0: Sqrt[x] = +/-i|x| (+/-i|x|)^2 = -x If you put in Sqrt[x]^2 into the console, it does not return x. No bug here.

Add your thoughts about it!