Jump to content

  • Log In with Google      Sign In   
  • Create Account


Why is the odd integer rootof a negative number undefined?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 gasto   Members   -  Reputation: 261

Like
-4Likes
Like

Posted 02 April 2014 - 09:46 AM

Hey mathematicians, why is (odd integer) root of a negative number undefined behaviour?

  _____
³√-27 = -3 ?
-3 · -3 = 9
9 · -3 = -27
 

Edited by gasto, 02 April 2014 - 09:47 AM.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 4113

Like
0Likes
Like

Posted 02 April 2014 - 09:56 AM

Why do you say it's undefined? My desktop calculator works fine with odd roots of negative numbers.

 

EDIT: FYI, you posted in the Math & Physics forum. Do you perhaps have a programming question, instead?


Edited by Buckeye, 02 April 2014 - 10:58 AM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#3 Rattrap   Members   -  Reputation: 1566

Like
0Likes
Like

Posted 02 April 2014 - 10:02 AM

What is the context of the undefined behavior?  Particular program or language? Calculator?



#4 DiegoSLTS   Members   -  Reputation: 994

Like
0Likes
Like

Posted 02 April 2014 - 10:41 AM

If you're using a software to compute it and it answers undefined, maybe it has a bug. Check this post: http://math.stackexchange.com/questions/25528/cubic-root-of-negative-numbers

 

Even Wolfram Alpha had a bug because of other possible answers (complex numbers), but it looks like now it shows you the real one and there's an option to check the complex ones too.



#5 Álvaro   Crossbones+   -  Reputation: 12509

Like
3Likes
Like

Posted 02 April 2014 - 11:58 AM

 

Hey mathematicians, why is (odd integer) root of a negative number undefined behaviour?

  _____
³√-27 = -3 ?
-3 · -3 = 9
9 · -3 = -27
 

 

Is this becoming a hobby of yours? You ask why something is not the way it should be, but it actually IS the way it should be. You can initialize multi-dimensional arrays in C or C++ to zero by specifying only the first element, and the odd-integer root of a negative number is perfectly well defined.



#6 gasto   Members   -  Reputation: 261

Like
0Likes
Like

Posted 02 April 2014 - 04:21 PM

Good old Windows calculator:

 


Edited by gasto, 02 April 2014 - 04:39 PM.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

#7 Javier Meseguer de Paz   Members   -  Reputation: 347

Like
0Likes
Like

Posted 02 April 2014 - 06:34 PM

It is a problem of the Windows Vista Calculator then. In Windows 7 it works perfectly.

 

Just out of curiosity, try: (-27)^(1/3) in the calculator to see if you get an answer.


“We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil” -  Donald E. Knuth, Structured Programming with go to Statements

 

"First you learn the value of abstraction, then you learn the cost of abstraction, then you're ready to engineer" - Ken Beck, Twitter


#8 Nypyren   Crossbones+   -  Reputation: 4031

Like
0Likes
Like

Posted 02 April 2014 - 07:13 PM

The INV button is not meant to be used with the power buttons in calc.exe - It's more obvious on the Windows 8 desktop version because it re-labels the buttons which it applies to.

Do what Javier says and use a fractional power: -27 x^y (1/3) (or the new "y root x" button if you have a new enough version)

Edited by Nypyren, 02 April 2014 - 07:19 PM.


#9 Álvaro   Crossbones+   -  Reputation: 12509

Like
3Likes
Like

Posted 03 April 2014 - 06:14 AM

Good old Windows calculator:


Here's some advice on how to ask questions on these forums:
* Try to find the answer for yourself first. For instance, using Google. You do have an Internet connection, don't you?
* If you still can't find the answer, post enough detail that we know what the situation is, why you think it's wrong, etc.


Let me illustrate what "enough detail" means:
I tried to compute the cubic root of -27 in Windows Calculator [version blah] and I get an error message that would translate to "invalid value". Shouldn't the answer be -3? Is this a bug?

#10 gasto   Members   -  Reputation: 261

Like
0Likes
Like

Posted 03 April 2014 - 08:26 AM

It is a problem of the Windows Vista Calculator then. In Windows 7 it works perfectly.

 

Just out of curiosity, try: (-27)^(1/3) in the calculator to see if you get an answer.

I get the same "invalid value" message. I used 0,333333333333333333333333333333 instead of 1/3 (since otherwise it would raise it to the first and then divide by three)

(or the new "y root x" button if you have a new enough version)

If you check the gif I linked to, there is no "y root of x" option.


Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

#11 Buckeye   Crossbones+   -  Reputation: 4113

Like
0Likes
Like

Posted 03 April 2014 - 08:36 AM


instead of 1/3 (since otherwise it would raise it to the first and then divide by three)

Either you're not using parentheses correctly, or your calculator is badly broken. Parenthetical expressions are evaluated first and the calculation should reduce to -270.333..


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#12 Álvaro   Crossbones+   -  Reputation: 12509

Like
0Likes
Like

Posted 03 April 2014 - 09:44 AM

It is a problem of the Windows Vista Calculator then. In Windows 7 it works perfectly.

 

Just out of curiosity, try: (-27)^(1/3) in the calculator to see if you get an answer.

 

That won't work. If you compute 1/3 as a floating-point number it will be rounded to some fraction with a power of 2 in the denominator, and now -27 raised to that power won't be a real number.

 

In C99 and C++11 you have the function `cbrt', which will give you the correct value, but if you use `pow', you'll get `nan'.


Edited by Álvaro, 03 April 2014 - 02:18 PM.


#13 Javier Meseguer de Paz   Members   -  Reputation: 347

Like
2Likes
Like

Posted 03 April 2014 - 12:14 PM


That won't work

 

Actually it does in Windows 7's calculator. Windows calculator uses arbitrary precision numbers or it just performs symbolic optimization.

 

Regardless, I hadn't thought about floating point issues when doing the cubic root of a number in C++,so I am glad you pointed out that converting roots to powers is not a good idea when it comes to negative numbers, as a rule smile.png


Edited by Javier Meseguer de Paz, 03 April 2014 - 12:14 PM.

“We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil” -  Donald E. Knuth, Structured Programming with go to Statements

 

"First you learn the value of abstraction, then you learn the cost of abstraction, then you're ready to engineer" - Ken Beck, Twitter





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS