Post Reply 
negative number raised to even power
05-07-2015, 02:59 PM (This post was last modified: 05-07-2015 04:14 PM by Manolo Sobrino.)
Post: #66
RE: negative number raised to even power
(05-07-2015 12:25 PM)Dave Britten Wrote:  I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it?

In CS terms, fully parsing a numeric literal is atomic, and precedes any operations on that number.


Wow...


As has been said (to death) here, -2^2=-4 and (-2)^2=4 in standard mathematical notation, which applies to the stuff we write on blackboards, books and papers to share knowledge with people. Exponentiation has higher precedence than negation, which is on the same level of addition and subtraction (where else could it be?)

If you don't know/care about this or you don't like it, well, it's better to get used to it. It's not a matter of opinion, it's the convention that won.

How you represent numbers in a computer is a different thing, and how you tell the computer to perform arithmetical and order operations with those representations is another one. I don't think there's any advantage in mixing things up.

Any math parser should follow standard mathematical notation, not the other way around. Doing that is a very bad idea, you end with crummy parsers like Excel's one that can't be fixed because of compatibility with legacy misdeeds and users of calculators that think mathematical expressions are sequences of calculator steps. They're not.

Of course you can say that 2.5 = 2 + 0.5, if you square it it's just (2+0.5)*(2+0.5), which is what ^2 means (another notation). That's why (-2)*(-2)=(-2)^2, the same way that 2*2=2^2. The additive inverse of 4 is -4, and as 4=1+1+1+1=(1+1)*(1+1)=2*2=2^2, we can write -4 as -(2^2), or -(2*2), or -((1+1)*(1+1)), or -(1+1+1+1).

Now, let's read those expressions. With the precedence rule "^" > "anything else", parentheses in the first one are redundant: -2^2=-(2^2), hence -2^2=-4. In the second one they are of no effect, as -(2*2)=(-2)*2=2*(-2) you can write it again as -2*2. The other ones have additions (lowest priority), so you keep the parentheses around those.

What's so hard to accept? Why does this keep popping up?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
negative number raised to even power - DrD - 04-25-2015, 11:24 AM
RE: negative number raised to even power - Manolo Sobrino - 05-07-2015 02:59 PM



User(s) browsing this thread: 16 Guest(s)