Is -2^2 equal to 4 or -4? which has precedence, the negate or the power? TI algebraic calculators do it one way while HP's algebraic calculators do it another.
I believe the most common answer is -4, due to exponentiation having a higher precedence than negation. I'm not sure it's completely standard, though. In written mathematics it would be more common to write (-2)^2 if you really meant the -2 to be exponentiated. But, it might be different if you were using a style of traditional mathematics typesetting where unary negation and subtraction are more clearly distinguished. I could imagine something like 5 - -2^2 meaning to subtract (-2)^2 from 5, if it were written in a typesetting style where the unary minus was smaller and clearly more "bound" to the 2 than the subtraction was.<p>Miscellaneous support: a random elementary algebra textbook: <a href="http://infinity.cos.edu/algebra/Rueger%20Text/Chapter02/2.6_Exponents%20and%20Order%20of%20Operations.pdf" rel="nofollow">http://infinity.cos.edu/algebra/Rueger%20Text/Chapter02/2.6_...</a> and a dude from mathforum.org: <a href="http://mathforum.org/library/drmath/view/53240.html" rel="nofollow">http://mathforum.org/library/drmath/view/53240.html</a>
Considering operator precedence <a href="http://en.wikipedia.org/wiki/Order_of_operations" rel="nofollow">http://en.wikipedia.org/wiki/Order_of_operations</a>
Quote:
"Unfortunately, there exist differing conventions concerning the unary operator − (usually read "minus"). In written or printed mathematics, the expression −32 is interpreted to mean −(32) = −9, but in some applications and programming languages, notably the application Microsoft Office Excel and the programming language bc, unary operators have a higher priority than binary operators, that is, the unary minus (negation) has higher precedence than exponentiation, so in those languages −32 will be interpreted as (−3)2 = 9. [1]. In any case where there is a possibility that the notation might be misinterpreted, it is advisable to use parentheses to clarify which interpretation is intended."
Just remember PEMDAS: Parentheses first, Exponents next, Multiply/Divide, Add/Subtract. This is the order for dealing with simple math manipulations; don't trust a calculator that tells you otherwise.
Somewhat related, in the Io language, I was surprised to find that the expression "-23 abs" evaluates to "-23" <i>not</i> +23. The language desugars the expression to "0-(23 abs)". I think what threw me was the fact that Io uses a space rather than a dot for member selectors. No one would be surprised that C++ evaluates "-numObj.abs()" that way.
I remember Stoustrup saying that this question was the reason that C++ doesn't have a double-asterisk operator. Everyone seems to give a different "obvious" answer.