21

$-3^2 = -9$

I found this problem while doing an algebra refresher in the book The Complete Idiot's Guide to Algebra. I asked my engineer brother this problem and he got it wrong. A search on Google for why is a negative number squared negative I get conflicting results.

Google presents an excerpt from a site that says the converse. "This is because to square a number just means to multiply it by itself. For example, $(-2)$ squared is $(-2)(-2) = 4$. Note that this is positive because when you multiply two negative numbers you get a positive result." - This, of course, is the exact opposite of what was asked, but it's the given response.

The third item on Google's search results offered up a math forum where the moderator, one Doctor Rick, states that whether it is interpreted as -3^2 or -(3)^2 is a difference of opinion. It's math. How can it be a matter of opinion? If an equation is being used for calculating a space craft landing, or the engineering of a bridge design, a difference of opinion on how to calulate this could prove catastrophic.

The high school math teacher that authored The Complete Idiot's Guide to Algebra presented this question as "be careful, this one is tricky" specifically to teach this situation, but since there seems to some confusion as to which is the right way to calculate this.

My scientific calculator tells me it is 9. Another question here on SE regarding calculators with this same issue, the accepted answer was that adding parentheses fixed the "issue", but doesn't address whether the calculator is getting it "wrong" because it's not actually wrong.

What is the correct answer, and why? Thanks!

Mark
  • 345
  • 18
    $$-a^2 \neq (-a)^2 $$ – Jack D'Aurizio Jul 03 '16 at 16:32
  • 4
    Exponentiation precedes multiplication precedes substruction. $-3^2=0-3^2=0-9=-9$. – barak manos Jul 03 '16 at 16:33
  • 2
    When you have $-3$ entered in to a calculator, then you press a button to square the current value, you are effectively performing $(-3)^2=(-3)*(-3)=9$. If, in a calculator or computer program you enter $-3^2$ the precedence of the operations is interpreted as $-(3^2)=-9$. – abiessu Jul 03 '16 at 16:38
  • Squaring a negative number gives a positive number. Negating a squared number gives a negative number (or zero). – Joffan Jul 03 '16 at 16:38
  • 12
    It is unclear to me why this question would not be on-topic. It is not a complicated question but it can be confusing. And its author made some effort to explain their problem. @Jyrki what's wrong with the question? – quid Jul 03 '16 at 16:42
  • @DavidMitra given your opinion I think you should vote to reopen the question. (I did but as of now mine is the only vote.) – quid Jul 03 '16 at 16:53
  • $-9=-(3)^2=-3^2\neq (-3)^2=9$ – Zelos Malum Jul 03 '16 at 16:57
  • 6
  • 2
    Sadly, if you put this expression into Excel you will get a positive number. I think that in practical use what $-3^2$ means will almost always be clear; but accurate use of notation is nevertheless important. – Joffan Jul 03 '16 at 17:08
  • @joffan: what is the expression that you enter into excel? – abiessu Jul 03 '16 at 17:17
  • @abiessu -3^2 - ie., exactly what we are discussing. – Joffan Jul 03 '16 at 17:22
  • 1
    @Joffan: wow, that just makes everything worse... I don't have excel, does the same thing happen if you put in 0-3^2? I'm guessing it's a problem with the syntactic sugar of ^... – abiessu Jul 03 '16 at 18:07
  • @Joffan: I just found this thread: http://www.eng-tips.com/viewthread.cfm?qid=277266 so obviously it's a bit more convoluted there... – abiessu Jul 03 '16 at 18:12
  • 1
    @abiessu No, in the case of 0-3^2, the - is interpreted as a binary op and is enacted after exponentiation. Result -9 – Joffan Jul 03 '16 at 18:13
  • To my less-than-sophisticated eye for math, -3 is a number in and of itself, and not a number with an operation. The Spanish alphabet has 27 letters. ñ is not the letter 'N' plus an operation, but a letter in and of itself. As young people we are shown negative numbers on a number line, and -3 represents a "physical" point on the line, not a positive number plus an operation. – Mark Jul 03 '16 at 18:38
  • 1
    @Mark: I agree, and I think the convention should be the other way. But that's what it is. ¯\(ツ) – Deusovi Jul 03 '16 at 21:16

5 Answers5

32

Here's the issue that the other comments have been missing:

$-3^2$ does not mean "the square of negative three". The exponent takes priority over the negative: it means "the negative of $3^2$". If you want to say "the square of negative three" you write $(-3)^2$. (This also explains the issues with your programming languages - the ones that say $-9$ write it without the function notation doing the grouping for you, so the negative is applied after.)

Deusovi
  • 2,792
  • 1
  • 20
  • 23
  • 4
    When I did algebra 1 as a kid, this confused me beyond belief until I finally got it. Then it confused everybody else when I corrected/explained it to them. –  Jul 03 '16 at 21:01
  • 4
    You kids today. In my day we call "priority" the order of operations. I explained that like this: crack open eggs, scramble them, fry them. Change the order of that around and what you get might not be the same. Math is the same way. Understand when order is important. Now, if you can scramble an egg in the shell... hmm anyone have a paint mixer? – candied_orange Jul 03 '16 at 21:08
  • @CandiedOrange: It's true that order matters, but order of operations is a convention for interpreting expressions, not an actual mathematical idea. It tells us whether $3+2\times 8$ is $3+(2\times8)$ or $(3+2)\times8$. It doesn't tell us that multiplication always comes before addition; it says that all else being equal (no parentheses), you should pick the first interpretation in the example rather than the second. – Deusovi Jul 04 '16 at 00:22
  • (I know that you probably understand that, but your example doesn't quite fit and I fear it may do more harm than good for OP by suggesting that expressions like "$(-3)^2$" aren't even allowed to exist.) – Deusovi Jul 04 '16 at 00:23
  • 1
    @Deusovi Not suggesting that. I'm saying some can't be swapped around and still express the same value (some can). If you scramble a fried egg people who ordered a scrambled egg will look at you funny when you serve it to them. You followed the right steps in the wrong order. Doing that is how OP got 9 rather than -9. That doesn't mean you have to order scrambled eggs. You can order fried eggs. And you can say (-3)². Just don't tell me it's the same as -3² or you'll have egg on your face. – candied_orange Jul 04 '16 at 00:44
  • Thanks, was about to go on a rant about Chrome's calculator being broken! – Jack Vial Oct 25 '17 at 17:33
11

It is not an opinion but a convention (accepted in all the world as far as I know) :

$$ -3^2=(-1)\cdot 3^2= (-1) \cdot 9 = -9 $$

Emilio Novati
  • 62,675
  • "as far as I know" - is where my problem is. As I said in my OP, my brother is an engineer, and he got it wrong. Scientific calculators do it wrong. Answers on other forums have it wrong. It was offered in here that Excel gets it wrong.

    I tried a couple of programming languages and got interesting results.

    – Mark Jul 03 '16 at 18:20
  • Python gets it right -3**2 = -9.

    C# (and probably all other forms of C/C++, etc) gets it wrong Math.Pow(-3,2) = 9

    PHP has two ways to do exponents. A formula and an operator (new to PHP 5.6). PHP gets it right AND wrong. pow(-3,2) = 9 -3 ** 2 = -9

    – Mark Jul 03 '16 at 18:30
  • 11
    @Mark: they're all correct, it's just a question of what the notation means. -3**2 means $-(3^2)$, pow(-3,2) means $(-3)^2$. – Javier Jul 03 '16 at 18:49
  • @Mark if you search calculator in google and then use it to evaluate the problem you will get $-9$. This is the worst convention in my opinion. –  Jul 03 '16 at 18:51
  • @Mark As the others mention it is just a convention, but it is an overwhelmingly accepted convention. Every scientific calculator I've used gives $-9$ as a result. I just tested it on a TI-84 again to make sure I wasn't crazy. Your brother maybe just never ran into this issue, though that seems hard to believe. I study physics and math and I'm confident that most if not all of my engineering/physics/math friends would agree the answer should be interpreted as negative. – wgrenard Jul 03 '16 at 21:01
  • 2
    @Mark there's no question of precedence in such a case, there isn't even a choice to make for precedence to resolve, pow(-3, 2) can only mean the square of minus 3. – harold Jul 03 '16 at 21:40
  • 1
    C# does get it right: -Math.Pow(3,2) = -9 – BenM Jul 03 '16 at 22:49
  • 1
    @wgrenard This is speculative, but if his brother is a engineer in computer science, I believe he is more likely to genuinely get it wrong. When a developer sees $-3^2$ without context, they may enter tunnel vision in which they see $a^n$ instead, -3 being a value to be passed as an argument, forgetting it is a mathematical expression. But honestly I think @Mark asked him a different question than he intended (because he didn't know the concept), especially considering how the title of this StackExchange question is formulated: "Is a negative number squared negative?" – Hay Jul 04 '16 at 00:24
  • 1
    @Mark I am an engineer. I get things wrong all the time. Whether or not a particular person gets something wrong is not always a valid indicator that something is a problem. This notation, like others have said, is a convention. It is still a good question to ask. – Jared Becksfort Jul 03 '18 at 14:46
6

$ -3^2 = -9 $ now, if you have parenthesis, like this:
$(-3)^2$ , then the answer will be $ 9 $.

4

IMO it helps a lot to understand how syntax of programming languages, and in a less straighforward way also maths notation, always correspends to a tree data structure. For instance, $f(g(x), h(y,z))$ is really a character-string encoding for something like $$ \begin{matrix} & & f & & \\& \nearrow & & \nwarrow & \\ g & & & & h \\ \uparrow & & & \nearrow & \uparrow \\ x & & y & & z \end{matrix} $$ The term $-3^2$, or the Python expression -3**2, means $$ \begin{matrix} & & -\square\quad & & \\ & & \uparrow & & \\ & & ** & & \\& \nearrow & & \nwarrow & \\ 3 & & & & 2 \end{matrix} $$ It does not mean $$ \begin{matrix} & & ** & & \\& \nearrow & & \nwarrow & \\ -\square & & & & 2 \\ \uparrow\!\!\!\!\! & & & & \\ 3 \!\!\!\!\! & & & & \end{matrix} $$ Why not? Well, these are just the conventions for how expressions are parsed: exponentiation binds more tightly than negation (which is, kinda reasonably, on the same level as addition).

OTOH, if you write in C# Math.pow(-3, 2), then this clearly is parsed as $$ \begin{matrix} & & \mathrm{pow} & & \\& \nearrow & & \nwarrow & \\ -3 & & & & 2 \end{matrix} $$ which is a different calculation and gives the result $9$. To express $-3^2$ in C#, use - Math.pow(3,2).

In programming languages, the parsing rules are generally these:

  • Parentheses group a subtree together, no matter what happens around them. Function application is typically connected to parenthesis, so this also binds tighly.
  • Commata always separate independent subtrees. Hence the -3 in pow(-3,2) is independent of the 2 and the pow function.
  • All other infix operators, like + and **, have some predefined fixity. For instance, in C and C++ the operator-precendence hierarchy includes the following:

    1. <, <=, >, >=
    2. <<, >>
    3. +, -
    4. *, /, %

    so when the expression pow(0+(-1)*3, 2) is encountered, the parser first splits it up at the comma, then at the +, then at the *, before considering the inner parenthesis.
    But in languages with an exponentiation operator, this should, as in maths notation, have a higher fixity than the other operators.

These parsing rules may subtly vary between different programming languages, but at least for a single language they must always be well-specified.

Alas, in maths it's often not so clear-cut – for some expressions it is indeed up to interpretation what they mean! For instance, does $\sin x^2$ mean $(\sin x)^2$ or rather $\sin(x^2)$? IMO it should be the former (because function application binds tightly), but I think the majority of mathematicians and scientist don't agree, and hence the completely ridiculous notation $\sin^2 x$ is used for that.

Oh well...

  • Sorry but wrong; in C/C++ <<,>> are at lower precedence than +,-,*,/! This cost me a few bugs, and made me very frustrated with the language, which is why I immediately noticed the error here. As for "$\sin x^2$", it is because spacing is different. Conventionally the precedence order is {super/sub}script > juxtaposition > spaced binding > binary operator. So $\sin ax+b = \sin(ax)+b$ and $\sum_{k=1}^n k^2 b \times \sum_{k=1}^n a k + c = ( \sum_{k=1}^n ( k^2 b ) ) \times ( \sum_{k=1}^n ( a k ) ) + c$. – user21820 Jul 03 '16 at 23:57
  • 1
    But I agree that "$\sin^2$" is plain ridiculous, because we also have $\sin^{-1}$. Either one or the other has to go, for consistency's sake. – user21820 Jul 03 '16 at 23:59
  • You may want to include a link to the actual precedence rules, for people to see, such as http://en.cppreference.com/w/cpp/language/operator_precedence. – user21820 Jul 04 '16 at 00:01
  • @user21820: I did write that << and >> have lower fixity than the arithmetic operators. (And C++ actually makes good use of this; it uses these operators more for stream insertion than for bit shifting). Now as for precedence with spaced bindings... well, that might work, if there was a clear distinction between spaced binding, juxtaposition, and omitted multiplication operator. Also, it's not uncommon to see $\sum_k a_k\cdot c + b_k\cdot c$, meaning $\sum_k (a_k\cdot c + b_k\cdot c)$. So... – leftaroundabout Jul 04 '16 at 00:11
  • (I avoid talking about “higher precedence”, since that term is also ambiguous: precendence 5 is higher than precedence 7, what? Fixity is understood to actually assign tight-binding operators higher numbers, which makes more sense.) – leftaroundabout Jul 04 '16 at 00:15
  • Oh oops I assumed you had it in descending order... I should not be posting comments when I'm sleepy. Anyway there's the term "binding strength" if you don't like "precedence", but all programming language references I know use the term "precedence rules" haha.. – user21820 Jul 04 '16 at 00:23
  • @user21820: yeah... I daresay most languages don't spend all that much thought on how best to talk about operator precedences, because it's something that only needs to be decided once, written in a table, and done. But the few languages who have full support for custom operators use, I think, all the term fixity. – leftaroundabout Jul 04 '16 at 08:20
  • I see. This is actually the first time I'm seeing the term "fixity", but indeed the only languages I've used don't have fully customizable operators.. I guess the problem is that nobody knows what "fixity" means and one still has to define it in terms of precedence or order of evaluation anyway. – user21820 Jul 04 '16 at 13:02
  • I applaud you for the effort it took to draw those diagrams. – Steven Alexis Gregory Jun 22 '19 at 02:53
3

In order to conserve the distributive law of arithmetic: $x(y+z)=(xy)+(xz), $ along with the other basic laws of arithmetic, when extending the number-system to include additive inverses, we must have $$1=1+0=1+(-1)\cdot 0=$$ $$=1+(-1)[1+(-1)]=$$ $$=1+[(-1)1]+[(-1)(-1)]=$$ $$=1+(-1)+(-1)^2=0+(-1)^2=$$ $$=(-1)^2.$$

  • I am curious why this answer isn't getting more upvotes? This seems to be the one answer that actually explains why the order of precedence is absolute and not just a convention. – Mark Jul 05 '16 at 13:43
  • Since the Q has now been marked as a duplicate of an earlier Q, it may be that some readers haven't read beyond the "Duplicate" notification. – DanielWainfleet Jul 05 '16 at 15:55