
-----------------------------------
ericfourfour
Wed Apr 04, 2007 3:19 pm

Calculator Error
-----------------------------------
This is something that happened in math class today.

If you enter the equation, (-27)^(2/3), into your calculator, you will get an error. However, this should not happen.

What happens when the equation is expanded and then solved?

(-27)^(2/3)
= ((-27)^(1/3))^2)
= (cubed root (-27)) ^ 2
= (-3) ^ 3
= 9

Using the original equation:
My calculator says, "Domain Error"
Turing says, "Attempt to raise a negative number to a real exponent."
it returns 1 in Ruby
Google calculator says, "(-27)^(2 / 3) = -4.5 + 7.79422863 i"

I thought I would post this on a programming forum because I believe this is programming related and has to do with how calculators deal with powers. Does anyone understand why an error is occurring?

-----------------------------------
richcash
Wed Apr 04, 2007 5:43 pm

Re: Calculator Error
-----------------------------------
it returns 1 in Ruby
That's because you did this :
(-27)**(2/3)
And remember Ruby thinks you want an integer result from the "2/3", and will evaluate it to 0. So you're basically doing (-27)**0.

You have to do it like this :
(-27)**(2/3.0)
which will return NaN (which I think means error)

So Ruby also has this problem because, as you pointed out, the answer should be 9. You can't even do this in Ruby :
(-8) ** (1/3.0)

So, I guess Ruby has just disabled negative numbers to be raised to a non-integer exponent because the way they evaluate exponents will lead to incorrect results sometimes.

-----------------------------------
Skynet
Wed Apr 04, 2007 7:58 pm

Re: Calculator Error
-----------------------------------
Here's my hypothesis:

I think your calculator uses http://img225.imageshack.us/img225/3410/convergenceow4.jpg

-----------------------------------
ericfourfour
Wed Apr 04, 2007 8:30 pm

RE:Calculator Error
-----------------------------------
Very nice Skynet! I'm going to have to write this down. I'll try to make sense of it tomorrow.

@richcash Oh, of course! How did I miss that :)

btw. where I wrote (-3)^3, in my original post, it should be (-3)^2

-----------------------------------
Skynet
Wed Apr 04, 2007 9:52 pm

Re: Calculator Error
-----------------------------------
Ah, missed something. Newton's method is really simple for square roots:
x_n+1 = 0.5x_n + 0.5c/x_n  (c is the number you're taking the square root of)

However, if we want to use it for other exponents, the exponent doesn't go away so nicely. We'll still have to evaluate another exponent in the equation.  (It's the sqrt(x_n) in mine) We can do this recursively if we want, but it'll take time.

Here's another idea, and it fits with capabilities a scientific calculator already needs to have around:
a = y ^ x
ln a = ln (y^x)
ln a = x * ln y
a = e ^ (x * ln y)

This needs forward and reverse lookup tables (or formulas) for the natural log and its inverse. Calculators need those already and they can be approximated in quite a few different ways. Since the ln of a negative number is undefined, a domain error makes sense.

One day, I'd like to be able to forget logarithms...I really don't like them. I blame the highschool math curriculum.

-----------------------------------
Brightguy
Fri Apr 06, 2007 11:35 pm

Re: Calculator Error
-----------------------------------
Note that all nonzero numbers have n distinct nth roots.  Any number can be written in the form http://freerange.compsci.ca/texbin/pictures/ca628ebcdb954841c653803d32880668.png (for some nonnegative real r and real &#952;), and the nth roots can be found with http://freerange.compsci.ca/texbin/pictures/a67e2d7e4572404088fe04a2821b5bb8.png by taking k=0,1,...,n-1.

So, if we want to define a root function, which one of these do we take?  For positive real numbers, the obvious choice is the unique positive real root.  In general, though, I believe it's usually defined as the root with the smallest absolute value of the argument (the polar angle) with the positive ones favored.  You can still use the definition Skynet posted, because ln can be defined over the complex numbers if you limit http://freerange.compsci.ca/texbin/pictures/de96218c06c5662e7f0b70359460cd5a.png (this is called the principal branch).

The problem is that if n is odd and you are taking the root of a negative number then there will be a real (negative) solution.  Often people are only concerned with real solutions, so this is the root they want.  Most calculators don't deal with complex numbers anyway so they'll just output the real solution.  Mathematically it's kind of ugly to make an exception for these cases.  (e.g., Maple and MATLAB don't do it by default.)  However, Google does treat it as a special case if an exponent is of the form 1/n with n odd.  So you would want to enter ((-27)^(1/3))^2.  If you want the usual complex root, use Skynet's definition.

One day, I'd like to be able to forget logarithms...I really don't like them. I blame the highschool math curriculum.
Eh?  Exponentiation is one the most important operations in math, so consequently logarithms are as well.

-----------------------------------
Drakain Zeil
Sat Apr 07, 2007 6:30 am

RE:Calculator Error
-----------------------------------
Highscool is a monopoly for money, not education :P

Problem with that system? A few teachers care. Otherwise, it would be quite worthless to you.

-----------------------------------
Skynet
Mon Apr 09, 2007 12:32 am

Re: Calculator Error
-----------------------------------
Eh?  Exponentiation is one the most important operations in math, so consequently logarithms are as well.
Oh, I know...especially after ODE's and my Signals course. Doesn't mean I have to like them. :P
