-5^2

P

per.fack

Why does excel calculate -5^2 as (-5)^2 = 25,
when 0-5^2 is calculated as 0-(5^2) = -25.
Other calculators (including handheld), mathematic software, and math books,
would give the answer -5^2 = -25.
 
S

Stan Brown

Not if they want to be right IIRC, as -5^2 <> 0-5^2. :)

Sorry, but those two are identically equal as far as algebra is
concerned, and also according to programming languages like C. Excel
gets it wrong.
There is a strict order of application of arithmetic functions, which (again
IIRC :) ) goes ...

parentheses
unitary +/- (ie change sign)
Exponentiation
* and /
+ and -

My HP calculator gives -5 squared as 25 ... as I would expect. :)

Your calculator is wrong, and so is your memory. There is no
distinction in math between -x and 0-x. (You mean "unary", not
"unitary".)

http://en.wikipedia.org/wiki/Plus_and_minus_signs

"In mathematics and most programming languages, the rules for the
order of operations mean that -52 is equal to -25. Powers bind more
strongly than multiplication or division which binds more strongly
than addition or subtraction. While strictly speaking, the unary
minus is not subtraction, it is given the same place as subtraction.
However in some programming languages and Excel in particular, unary
operators bind strongest, so in these -5^2 is 25 but 0-5^2 is -25."
 
B

Bruce Sinclair

Why does excel calculate -5^2 as (-5)^2 = 25,
when 0-5^2 is calculated as 0-(5^2) = -25.
Other calculators (including handheld), mathematic software, and math books,
would give the answer -5^2 = -25.

Not if they want to be right IIRC, as -5^2 <> 0-5^2. :)

There is a strict order of application of arithmetic functions, which (again
IIRC :) ) goes ...

parentheses
unitary +/- (ie change sign)
Exponentiation
* and /
+ and -

My HP calculator gives -5 squared as 25 ... as I would expect. :)
 
J

joeu2004

Why does excel calculate -5^2 as (-5)^2 = 25,
when 0-5^2 is calculated as 0-(5^2) = -25.
Other calculators (including handheld), mathematic software,
and math books, would give the answer -5^2 = -25.

Not exactly true with respect to calculators. It depends on how you choose
to enter -5 in the calculator. If you enter 5, then CHS (change sign) or
the equivalent, you will indeed get +25 when you square it.

Contrary to those with limited experience, there is no single way to do that
in computer languages. Some computer languages do it the way that Excel
does. It was actually a topic of some debate among computer scientists in
the 1950s. But granted, -(5^2) is more common.

Comparisons with mathematics is inappropriate since the precedence is
implied by superscripting.

It is a valid observation that we might want -5^2 and 0-5^2 to have the same
result. But it is not "wrong" if they are different. It is simply the
difference between the unary negative operative and the subtraction
operation, which happen to use the same symbol (-).

The bottom line is: as with natural languages, each computer language has
its own rules for syntax and semantics. Is Yoda-speak "wrong"?
 
B

Bruce Sinclair

Sorry, but those two are identically equal as far as algebra is
concerned, and also according to programming languages like C. Excel
gets it wrong.

Doh ! ... you are quite right. Apologies to all. :)

Your calculator is wrong, and so is your memory. There is no
distinction in math between -x and 0-x. (You mean "unary", not
"unitary".)
http://en.wikipedia.org/wiki/Plus_and_minus_signs

<sigh> ... why is it when you are absolutely certain, that is the time you
will be most wrong ? :)

"In mathematics and most programming languages, the rules for the
order of operations mean that -52 is equal to -25.
?
Powers bind more
strongly than multiplication or division which binds more strongly
than addition or subtraction. While strictly speaking, the unary
minus is not subtraction, it is given the same place as subtraction.
However in some programming languages and Excel in particular, unary
operators bind strongest, so in these -5^2 is 25 but 0-5^2 is -25."

Ah ... an XL "speciality". Thanks for the heads up. :)

As I say to everyone who has trouble with this stuff, if you use parentheses
you are much more likely to get what you expect. I usually use them. :)
 
P

per.fack

Den tirsdag den 27. november 2012 02.03.48 UTC+1 skrev joeu2004:
Comparisons with mathematics is inappropriate since the precedence is
implied by superscripting.

What do you mean by "implied by superscripting"?

It is a valid observation that we might want -5^2 and 0-5^2 to have the same
result. But it is not "wrong" if they are different. It is simply the
difference between the unary negative operative and the subtraction
operation, which happen to use the same symbol (-).

Yes. Having the same symbol for the two different things often cause confusion.
My students have difficulties regarding this.

Here http://en.wikipedia.org/wiki/Plus_and_minus_signs (Use in elementary education) the symbols are different. I have never seen this used in real.
Might cause other difficulties.
 
S

Salmon Egg

Why does excel calculate -5^2 as (-5)^2 = 25,
when 0-5^2 is calculated as 0-(5^2) = -25.
Other calculators (including handheld), mathematic software, and math books,
would give the answer -5^2 = -25.

From when I first used computer languages, there has been a problem
distinguishing the unary minus sign "-" from the subtraction operation
sign which also is "-". That is if x = 5 and y = -5, we are talking two
distinct numbers. y happens to be the inverse of x under the (group)
operation of addition. Instead of having a new symbol for y, the symbol
used for it uses the - permanently attached to the symbol of x; -5 in
this case.

All algebraic computer languages lie FORTRAN or Excel have an order of
valuation that can be modified using parentheses or something like them.
In this case, exponentiation has highest priority. Then the unary minus
sign gets attached. Excel is very explicit in the order of operation.

--

Sam

Conservatives are against Darwinism but for natural selection.
Liberals are for Darwinism but totally against any selection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top