# Maths question - exponents



## neilms (Jun 22, 2020)

Hi
I’m trying to understand a little bit about exponents and getting confused with the topic of negative base numbers and their exponents.
For example, I read that :

-5 (with no brackets) raised to the power of 2 = -25.

Contrast this with:
(-5) raised to the power of 2 = 25   :that is a positive number. 
(-5) raised to the power of 2 = 25   :that is a positive number. 

I don’t understand why the first with no brackets is negative but the second is positive. Can someone please help and explain to me exactly why this is the case? Many thanks


----------



## Jose (Jun 22, 2020)

Hard to tell without an explicit reference to a programming language or platform, but I'm guessing this is an operator precedence problem. Any negative number times another negative number equals a positive number. This is why the square root of -1 is imaginary.  Expanding what I think you mean:
-5 squared = -5 * -5 = +25
the negative of 5 squared = (5 * 5) * -1 = -25


----------



## VladiBG (Jun 22, 2020)

_View: https://www.youtube.com/watch?v=CnfsXS02dNM_


----------



## a6h (Jun 22, 2020)

Jose said:


> This is why the square root of -1 is imaginary


Nitpicking! That holds true in the set of Complex numbers.
The square root of a negative numbers do not exist in the set of Real Numbers.


----------



## Mjölnir (Jun 23, 2020)

The short answer is: because this is the correct result of applying the mathematical rules involved in the calculation.  Loosely speaking:

braces override operator precedence
minus times minus = plus (- * - = +)
The long answer is:

-5^2 = -(5^2) = -(5*5) = -(25) = -25
because the _exponent operator_ has higher _precedence_ than the _minus operator_ (see also: topic #4 3)
I.e. the _to-the-power-of_ operator ('^') applies first
IFF -5^2 = 25 (THIS IS WRONG)
_then the programming language or calculator you use is errorneous (obscure) because it does not get the operator precedence right_
-5 = (-1)*5
This is how _integer_ (union of _natural_ and _negative_) numbers are constructed (the _negative_ numbers are derived from the _natural_ (positive) numbers by preceding them with a _minus_ sign, which is in turn means _multiply with (-1)_)
Thus (-5)^2 = ((-1)*5)*((-1)*5) = (-1)*5*(-1)*5
Mathematic Law of Associativity i.e. you can set the braces as you want for some _operations/operators_, e.g. plus and multiply
(-1)*5*(-1)*5 = (-1)*(-1)*5*5=((-1)*(-1))*(5*5)
Mathematic Law of Commutativity, i.e. you can change the order of _operands_ (usually numbers) for some _operations/operators_ but the result stays the same (e.g. addition & multiplication).
(-1)*(-1) = -(-1) and -(-1) = 1
This is a property of the Multiplication operation (look for _Negation_) on the realm of _integer_ numbers
Thus (-5)^2 = ((-1)*5)*((-1)*5) = ((-1)*(-1))*(5*5) = 1*(5*5) = 1*25 = 25
_Voilà: __q.e.d.__ (quod erat demonstrandum)_


----------



## jomonger (Jun 23, 2020)

Just always use brackets. Like in programming, calling power2(-5) is smth diffrent than -1*power2(5). (Let: int power2(int a){return a*a})

Don't skip any operators, both in math or in programming language, unless you are fluent in them.

To be honest these are basics from mid school (at least in my country). No offence ofc, now as adult you should be able to learn faster.
imo You should redo basics of principles of math analysis, becouse you will find lot more things you don't uderstand and you can get lost. Basic algebra should be known also, to understand mjollnir answer.
It is hard to understand math only at random topics.

Cheers.


----------



## SirDice (Jun 23, 2020)

jomonger said:


> To be honest these are basics from mid school (at least in my country). No offence ofc, now as adult you should be able to learn faster.


Plenty of people still get this wrong. If I go by these "98% will get this wrong" type posts I see on Facebook.  You know the ones, with something like "1+0*2+3=?" (the answer is 4, not 6. Multiplication is done _before_ addition).

Back in school I was taught a mnemonic to remember the order; "Meneer Van Dalen Wacht Op Antwoord".  It's in Dutch so it's not going to make sense in English. But it made it easier to remember  the correct order. 






						Order of operations - Wikipedia
					






					en.wikipedia.org


----------



## phalange (Jun 23, 2020)

SirDice said:


> Back in school I was taught a mnemonic to remember the order; "Meneer Van Dalen Wacht Op Antwoord"



Hey that's cool. what does it translate to in English? When I was a kid we memorized PEMDAS which was generally made into the mnemonic "Please Excuse My Dear Aunt Sally"


----------



## SirDice (Jun 23, 2020)

Roughly translated it means "Mister Van Dalen waits for an answer". But that really ruins the mnemonic and its meaning. It certainly did its job for me, after 30+ years I still remember it well. 



phalange said:


> When I was a kid we memorized PEMDAS which was generally made into the mnemonic "Please Excuse My Dear Aunt Sally"


Yeah, I was looking for those. I'm sure other languages have similar mnemonics. In Dutch we would call this an "Ezelsbrug" (Donkey Bridge; it really makes no sense in any other language  )


----------



## jomonger (Jun 23, 2020)

SirDice said:


> Plenty of people still get this wrong. If I go by these "98% will get this wrong" type posts I see on Facebook. You know the ones, with something like "1+0*2+3=?" (the answer is 4, not 6. Multiplication is done _before_ addition).


Yeah, lots of people make this mistake. I meant it should be easy to learn for adult, expeccially with no exam stress and such.

When I was kid I invented for myself that "The more powerfull operator is (and its opposition) the higher priority it has". It works for Cartesian operators and is nice generalization imo. I think it is intuitive and it also works for function analysis (first you integrate f(x), then multiply).

I don't like mnemonics (like right hand rule) becouse there is propability for me to forget f.e. which hand mnemonic was about xd.

But everyone has their own way of thinking and think that works.


----------



## neilms (Jun 23, 2020)

jomonger said:


> Just always use brackets. Like in programming, calling power2(-5) is smth diffrent than -1*power2(5). (Let: int power2(int a){return a*a})
> 
> Don't skip any operators, both in math or in programming language, unless you are fluent in them.
> 
> ...


This question was asked not in relation to any programming problem. I am self studying basic pre algebra maths (to begin with) because I never had any formal education in mathematics at school.
No offence is taken.


----------



## jomonger (Jun 23, 2020)

neilms said:


> I am self studying basic pre algebra maths (...)



Wish you best then, and big shout out for taking math on your own.

I naturally started to think about programs like SciLab and such.


----------



## Mjölnir (Jun 23, 2020)

SirDice said:


> [...] In Dutch we would call this an "Ezelsbrug" (Donkey Bridge; it really makes no sense in any other language  )


It does! It's the same in german: _Eselsbrücke_


----------



## phalange (Jun 23, 2020)

jomonger said:


> I don't like mnemonics (like right hand rule) becouse there is propability for me to forget f.e. which hand mnemonic was about xd.



Well, as a statistician, I think as long as that probability is under 0.05, I'm happy with the mnemonic.


----------



## kpedersen (Jun 23, 2020)

In some ways languages without operator overloading make this a bit easier to read.

vec3 val = vec3_div(vec3_mul(a, b), c);

Obviously in this case the multiply happens first. But I suppose this is really just the same as using brackets for everything.


----------



## Mjölnir (Jun 23, 2020)

neilms said:


> [...] I am self studying basic pre algebra maths (to begin with) because I never had any formal education in mathematics at school.


Right you are!  To not know s/th is no shame.  It's a shame to be too lazy to learn what your intellect can handle.
Good luck & be patient.  PJ Harvey: Shame (Live@Jonathan Ross)


----------



## jomonger (Jun 23, 2020)

kpedersen said:


> Obviously in this case the multiply happens first. But I suppose this is really just the same as using brackets for everything.



In programming is used smth called Łukasiewicz notation.

Example:

Infix notation with parenthesis: (3 + 2) * (5 – 1)

Łukasiewicz notation: * + 3 2 – 5 1

You could write the latter as *((+ 3 2)(- 5 1)), and in such way you have written your code.


----------



## kpedersen (Jun 23, 2020)

jomonger said:


> In programming is used smth called Łukasiewicz notation.



Hmm, not heard it being called that before. I am assuming that is the same thing as reverse polish notation (RPN)?
UNIX comes with one of these calculators in base (dc, https://www.freebsd.org/cgi/man.cgi?query=dc&sektion=1).


----------



## jomonger (Jun 23, 2020)

kpedersen said:


> Hmm, not heard it being called that. I am assuming that is the same thing as reverse polish notation (RPN).
> UNIX comes with one of these calculators in base (dc, https://www.freebsd.org/cgi/man.cgi?query=dc&sektion=1).


Yeah, Łukasiewicz, Polish, Warsaw, prefix, reverse notation is same thing. I used inventor surname.


----------



## kpedersen (Jun 23, 2020)

I used to use dc a fair amount, mostly because I would keep forgetting to add -l to bc making it useless for decimals haha.
I was also tripped up too many times with expr and quoting the operators (looked and felt horrible). Now I use an alias for bc so I don't look weird infront of my colleagues


----------



## SirDice (Jun 23, 2020)

I got a HP-42s back when I was in school, it was awesome. While I still have that calculator I mostly use the Free42 app on my phone nowadays. RPN takes some time to get used to it but it's really powerful. I've gotten so used to it I can't even use a 'regular' calculator any more. On FreeBSD you'll want to use  dc(1) instead of bc(1) if you like RPN.


----------



## a6h (Jun 23, 2020)

neilms said:


> I never had any formal education in mathematics at school


I learned mathematics on my own. It may sounds overkill, but number theory and mathematical logic have helped me immensely.


SirDice said:


> Back in school I was taught a mnemonic to remember the order


Mnemonics and music get a boost from each others. A musical mnemonic is the best.


----------



## Mjölnir (Jun 23, 2020)

Guys, when I 1st saw this thread, I though: Hmm? 
Then it has grown to become one of the highlights of this wonderful sunshiny day


----------



## Criosphinx (Jun 23, 2020)

After I installed math/reduce I was looking for tutorials and that led me to this:



			essential mathematics


----------



## SirDice (Jun 23, 2020)

I've got some Youtube channels you might like if you're interested in math.

3Blue1Brown:








						3Blue1Brown
					

3Blue1Brown, by Grant Sanderson, is some combination of math and entertainment, depending on your disposition. The goal is for explanations to be driven by a...




					www.youtube.com
				




Mathologer:








						Mathologer
					

Enter the world of the Mathologer for really accessible explanations of hard and beautiful math(s). In real life the Mathologer is a math(s) professor at Mon...




					www.youtube.com
				




Numberphile:








						Numberphile
					

Videos about numbers - it's that simple. Videos by Brady Haran




					www.youtube.com
				




Stand-up Maths








						Stand-up Maths
					

I do mathematics and stand-up. Sometimes simultaneously. Occasionally while being filmed. (It's quite the Venn diagram.) Principle channel supporter: Jane St...




					www.youtube.com
				




Professor Dave Explains:




_View: https://www.youtube.com/watch?v=JbhBdOfMEPs&list=PLybg94GvOJ9FoGQeUMFZ4SWZsr30jlUYK_


----------



## Jose (Jun 23, 2020)

phalange said:


> Hey that's cool. what does it translate to in English? When I was a kid we memorized PEMDAS which was generally made into the mnemonic "Please Excuse My Dear Aunt Sally"


The English mnemonic I was taught was BODMAS. I can't believe I still remember that 38 years after brother Fergus McArdle's Traditional Algebra I class.

I really like Khan Academy videos for basic math. Looks like they prefer PEDMAS.


----------



## a6h (Jun 23, 2020)

I have a thing for pencil and paper. Give your paper books away for free, to your friends and family. There's no such thing as karma, but _F=ma_ is real.
I often get better results with paperbacks. As a non native english speaker, I always have three paper books on my desk: Oxford dictionary/grammar and Linguaphone (the old one). Same goes with mathematics.
I believe (with capital B), that 3Ps (paper book, pencil and paper) is the _Major Triad_, resolving to _perfect authentic cadence._



SirDice said:


> Professor Dave Explains:


That dude has an attitude.


----------



## Mjölnir (Jun 23, 2020)

When pointing the OP neilms to Math-links, it would be good to know his native tongue. S/he is from _Cydonia._
Addition from me: _Cydonia, Milkyway._  Often, Mathematics is much better understood in one's native tongue.


----------



## ralphbsz (Jun 23, 2020)

I think the OP has indicated that his question is not operator precedence, nor programming languages, but the actual math. So let me try this.

If we restrict ourselves to positive integer exponents, then the definition of x ^ i (where normally that would be written as x with superscript i) is: "1 * x * x * x * ... * x * x", with the x repeated i times. Special cases include x ^ 1 (which is just "x" written once), and x ^ 0 (which is just 1, because I explicitly included the "1 *" in the above expression to be clear). So far, so good?

Now, with negative numbers, this works exactly the same, except that we now have to be careful about where to place the brackets. Everyone agrees that (-5) * (-5) = 25, because the minus signs cancel, right? Therefore (-5) ^ 2 is also 25.

By the way, from this we can derive a fun fact: A negative number, when taken to an even power, will be positive. When taken to an odd power, it will be negative. The proof is left to the student. Along the same lines, we can extend the above notation to the case of negative exponents, if we define x^(-i) to be "1 / (x * x * x * ... * x * x)", with i instances of x.

The confusion that most posters have been trying to address is that the expression "-5^2" can be ambiguous, it can be interpreted as (-5) ^ 2 or as -( 5^ 2). To fix this ambiguity, one would need operator precedence rules. For example, everyone knows that multiplication has higher precedence than addition. So the expression "1*2+3*4" needs to be interpreted as " (1*2) + (3*4)", which makes 14. There are many other ways one could interpret it, for example left to right as "((1*2) + 3) *4", which makes 20. There are zillions of other ways to interpret that expression. The important part is that programming languages have strict rules for operator precedence. Mathematics also has them. But in practice, one should not rely on the obscure part of rules (for example whether unary - is different from operator -), but use brackets generously to make things clear. Or to say it different: writing "-5^2" is a bad idea, because it requires the reader to think, and that's hard. Either write "(-5)^2" or "-(5^2)" to be clearer. If there is any chance that the reader could be confused, add brackets. This is like the old joke about punctuation saves lives: there is a difference between "let's eat grandma", and "let's eat, grandma".


----------

