Is a negative number squared negative? [duplicate]

$-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!

marked as duplicate by Joffan, Martin Sleziak, user223391, Henrik, user21820Jul 3 '16 at 23:46

• $$-a^2 \neq (-a)^2$$ – Jack D'Aurizio Jul 3 '16 at 16:32
• Exponentiation precedes multiplication precedes substruction. $-3^2=0-3^2=0-9=-9$. – barak manos Jul 3 '16 at 16:33
• 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 3 '16 at 16:38
• 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 3 '16 at 16:42
• Related (perhaps even close to duplicate): Does the negative apply before or after an exponent and What is the accepted syntax for a negative number with an exponent? – Martin Sleziak Jul 3 '16 at 17:00

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.)

• 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. – Riker Jul 3 '16 at 21:01
• 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 3 '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 4 '16 at 0: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 4 '16 at 0:23
• @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 4 '16 at 0:44

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$$

• @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 3 '16 at 18:49
• @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 3 '16 at 21:40
• C# does get it right: -Math.Pow(3,2) = -9 – BenM Jul 3 '16 at 22:49
• @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 4 '16 at 0:24
• @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 3 '18 at 14:46

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

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 3 '16 at 23:57
• 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 3 '16 at 23:59
• You may want to include a link to the actual precedence rules, for people to see, such as en.cppreference.com/w/cpp/language/operator_precedence. – user21820 Jul 4 '16 at 0: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 4 '16 at 0: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 4 '16 at 0:15

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 5 '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 5 '16 at 15:55