### Author Topic: A little bit of a maths problem with indices  (Read 7199 times)

0 Members and 1 Guest are viewing this topic.

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### A little bit of a maths problem with indices
« on: December 29, 2014, 12:09:49 pm »
I have to solve an equation I've been through all of the learning material and cannot find an explanation for my dilemma. I have to solve an equation with three unknowns and the problem gives me those unknowns. Two of them are negative numbers and in the equation the unknowns are raised to the power of two and to the power of three. Now do I treat the racing to the power of an unknown as though the whole of the unknown is in parentheses and the index is applied to everything in the parenthesis. Or do I raised a number to its index and then apply the sign of what is now the variable.

I am wondering if the idea of the problem is to demonstrate putting into an equation -2 to the power of two in which case maybe you raised two to the power of two and give it a minus because the index takes precedence over the sign and perhaps when an X is raised to a power and then that X is replaced with a negative number in which case everything within the X is raised to the power and therefore it would be like putting the whole value of X in parentheses and raising everything in the parenthesis to the power.

So I would say that -2 to the power of two is perhaps -4 but if I have exited the power of two and replace X with -2 then the result is for.

#### Leuams

• Contributor
• Posts: 21
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #1 on: December 29, 2014, 12:41:54 pm »
In Algebra everything in the parentheses is raised to the power. Remember PEMDAS

(-2)^2 = 4

Your post and use of math is confusing me unless I am reading your post wrong and forget basic math.

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #2 on: December 29, 2014, 12:44:56 pm »
That's what I thought basically the difference is as follows:

-2^2 = -4

x^2,
for x = -2,
(-2)^2 = 4

#### Christopher

• Frequent Contributor
• Posts: 429
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #3 on: December 29, 2014, 12:48:58 pm »
Negative number times negative number is positive as signs cancel out

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #4 on: December 29, 2014, 12:53:30 pm »
Well according to this video on the Khan Academy unless you explicitly put a negative number embraces the index is considered as a first operation without considering the negative: https://www.khanacademy.org/math/cc-seventh-grade-math/cc-7th-negative-numbers/cc-7th-exponents-negative-base/v/exponents-with-negative-bases

In my case things are slightly more complicated because it is a variable which is been raised to the power and that variable is then replaced by a negative number so I am assuming I believe correctly that I would put the whole variable in brackets and then raise everything in brackets to the power. To expand on my thinking there will be nothing to stop the whole variable being replaced by an expression in which case it would definitely have to go in brackets and then the whole expression would be raised to the power of two.

I suspect the whole purpose of the exercise is to check my understanding of this subtlety in dealing with negative numbers or negative variables which have to be raised to a power.

#### Falcon69

• Super Contributor
• Posts: 1475
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #5 on: December 29, 2014, 09:14:45 pm »
If you have three unknowns, and one of them is a power, i.e 3x, you can use substitution.  Make 3x, X.  Then make the other 2 unknowns Y and Z.  If you are given any of the unknowns, then it is simple.  Solve for the others.

If You have three unknowns, and they are, well, unknown, you can again use substitution. For example...

(3x-4y)/6=z becomes (x-4y)/6=z  which again, you can substitute which becomes u/6=z

Solve for u, which is u=6z....and so on.

I think the only way to solve for multiple unknowns is to use substitution.

EDIT:  actually, making 3x = x (substitution) might be confusing. You can pick any letter, like b or something.  But keep in mind what it is. some letters, like s (seconds) or t (time) can get confusing too.  It works for any letter, you just have to remember what it is.  Always write down somewhere on the paper that 3x = x (or whatever letter you choose)
« Last Edit: December 29, 2014, 09:17:41 pm by Falcon69 »

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #6 on: December 29, 2014, 09:22:29 pm »
The three "unknowns" were all given. The point of the exercise was to correctly substitute the X the Y and the Z for the numbers given two of which were negative. I'm not sure what you were getting at but to be able to solve an equation with three unknowns you need to have the same three unknowns in three equations and use the methods of solving for simultaneous equations.

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #7 on: December 29, 2014, 09:26:20 pm »
It just seems like you're getting hung up on where the parenthesis go.

-2^2 is ambiguous.  Is it -(2^2) or (-2)^2?

Obviously if the (-2) is a variable x, and the equation is x^2, then you're dealing with the latter.  If the (2) is a variable x, and the equation is -x^2, then you're back to the ambiguous beginning, unless some parenthesis are added.  If this is an excerpt from an equation, eg: y-x^2, then you can safely assume that it means y-(x^2), because the - is not a negative sign anymore, it's the mathematical operation "minus" or "subtract", which comes after exponents in the order of operations.

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #8 on: December 29, 2014, 09:29:35 pm »
"^" has priority over "-". So:
Code: [Select]
-2^2 = -(2^2) = -4(-2)^2 = 4

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #9 on: December 29, 2014, 09:30:31 pm »
It just seems like you're getting hung up on where the parenthesis go.

-2^2 is ambiguous.  Is it -(2^2) or (-2)^2?

Obviously if the (-2) is a variable x, and the equation is x^2, then you're dealing with the latter.  If the (2) is a variable x, and the equation is -x^2, then you're back to the ambiguous beginning, unless some parenthesis are added.  If this is an excerpt from an equation, eg: y-x^2, then you can safely assume that it means y-(x^2), because the - is not a negative sign anymore, it's the mathematical operation "minus" or "subtract", which comes after exponents in the order of operations.

There aren't any parentheses per se, the whole point of the parentheses is to correctly isolate the parts been raised to a power. Your conclusion is correct. I am being asked to resolve an equation in which X is -2 therefore when X is raised to the power of two it is the whole -2 that is being raised to the power of two the actual section is -3XY^2 the Y being -1 which could sway the equation one way or the other.

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #10 on: December 29, 2014, 09:31:30 pm »
"^" has priority over "-". So:
Code: [Select]
-2^2 = -(2^2) = -4(-2)^2 = 4

Not in this case because it is x^2 and x=-2 so it is (-2)^2 = 4

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #11 on: December 29, 2014, 09:37:09 pm »
"^" has priority over "-". So:
Code: [Select]
-2^2 = -(2^2) = -4(-2)^2 = 4

Only when the "-" means the mathematical operation "minus", as in y-x^2.  When the - is defining the number itself (eg: negative two), it doesn't have any place in the order of operations, it's part of the definition of the number and of course needs to be a part of the base being raised to the exponent.

The problem is the symbol "-" has two definitions.  The mathematical operation "minus", and the symbol to denote a number with a value less than 0.  Which definition is appropriate depends on context.

-2^2 is ambiguous, either definition could be appropriate.  I would tend to lean towards (-2)^2 unless there were parenthesis around the (2^2), simply because -(2^2) would almost certainly be written as -1*2^2 instead.

5 - 2^2 is not ambiguous, clearly it means 5 - (2^2)

5 + -2^2 is not ambiguous either, it means 5 + (-2)^2.

It all depends on context.
« Last Edit: December 29, 2014, 09:45:34 pm by suicidaleggroll »

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #12 on: December 29, 2014, 09:47:11 pm »
Which definition is appropriate depends on context.

And that was the point of the exercise in the assignment to see if I would screw it up or not.

#### Fsck

• Super Contributor
• Posts: 1157
• Country:
• sleep deprived
##### Re: A little bit of a maths problem with indices
« Reply #13 on: December 29, 2014, 10:15:25 pm »
"^" has priority over "-". So:
Code: [Select]
-2^2 = -(2^2) = -4(-2)^2 = 4

Only when the "-" means the mathematical operation "minus", as in y-x^2.  When the - is defining the number itself (eg: negative two), it doesn't have any place in the order of operations, it's part of the definition of the number and of course needs to be a part of the base being raised to the exponent.

The problem is the symbol "-" has two definitions.  The mathematical operation "minus", and the symbol to denote a number with a value less than 0.  Which definition is appropriate depends on context.

-2^2 is ambiguous, either definition could be appropriate.  I would tend to lean towards (-2)^2 unless there were parenthesis around the (2^2), simply because -(2^2) would almost certainly be written as -1*2^2 instead.

5 - 2^2 is not ambiguous, clearly it means 5 - (2^2)

5 + -2^2 is not ambiguous either, it means 5 + (-2)^2.

It all depends on context.

not really ambiguous, no brackets = no priority.
"This is a one line proof...if we start sufficiently far to the left."

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #14 on: December 29, 2014, 10:17:42 pm »
"^" has priority over "-". So:
Code: [Select]
-2^2 = -(2^2) = -4(-2)^2 = 4

Not in this case because it is x^2 and x=-2 so it is (-2)^2 = 4
Yes, it holds in this case because if x = -2, for example,
Code: [Select]
x*(-5) = (x)*(-5) = (-2)*(-5) = 10 When x is used in context, then you can (and should) add additional/extra parenthesis around x before expanding it.

"^" has priority over "-". So:
Code: [Select]
-2^2 = -(2^2) = -4(-2)^2 = 4
Only when the "-" means the mathematical operation "minus", as in y-x^2.  When the - is defining the number itself (eg: negative two), it doesn't have any place in the order of operations, it's part of the definition of the number and of course needs to be a part of the base being raised to the exponent.

The problem is the symbol "-" has two definitions.  The mathematical operation "minus", and the symbol to denote a number with a value less than 0.  Which definition is appropriate depends on context.
Yes, "-" (minus) has two meanings. Meaning depends on the context. Which meaning makes sense? If only one holds, then use that. If both meanings are probable, higher prioritity operation wins. In this case, "^".

-2^2 is ambiguous, either definition could be appropriate.  I would tend to lean towards (-2)^2 unless there were parenthesis around the (2^2), simply because -(2^2) would almost certainly be written as -1*2^2 instead.

5 - 2^2 is not ambiguous, clearly it means 5 - (2^2)

5 + -2^2 is not ambiguous either, it means 5 + (-2)^2.

It all depends on context.
"Ambiguousness" depends on how strictly you or somebody else adhere to the rules. This is not ambiguous with priority rules
Code: [Select]
-2^2 =-(2^2) = -4x = -2; x^2 = (-2)^2 = 4If you know the rules and everybody plays by the rules, then all is OK. If either condition is broken ...

Which definition is appropriate depends on context.
And that was the point of the exercise in the assignment to see if I would screw it up or not.
I do not know original problem, so cannot comment
« Last Edit: December 29, 2014, 10:20:35 pm by electr_peter »

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #15 on: December 29, 2014, 10:21:41 pm »
Code: [Select]
{x^2 -3xy^3 +2z^2} / {x(y^2 -z)} x=-1y=-2z=1
I make the result 7

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #16 on: December 29, 2014, 10:24:47 pm »
"Ambiguousness" depends on how strictly you or somebody else adhere to the rules. This is not ambiguous with priority rules
Code: [Select]
-2^2 =-(2^2) = -4x = -2; x^2 = (-2)^2 = 4If you know the rules and everybody plays by the rules, then all is OK. If either condition is broken ...

I disagree.  The problem is that one of those definitions of "-" is NOT an operation, and therefore is not subject to the agreed upon order of operations.  It's part of the definition of the number, and therefore must come before ANY mathematical operation on that number.

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #17 on: December 29, 2014, 10:27:33 pm »
Code: [Select]
{x^2 -3xy^3 +2z^2} / {x(y^2 -z)} x=-1y=-2z=1
I make the result 7
Correct (-21/-3 = 7)
So what is the problem?

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #18 on: December 29, 2014, 10:30:35 pm »
Code: [Select]
{x^2 -3xy^3 +2z^2} / {x(y^2 -z)} x=-1y=-2z=1
I make the result 7
Correct (-21/-3 = 7)
So what is the problem?

none now that it is established that x^2 and for x=-1 the result of x^2 is (-1)^2 ad not -1^2 as the results would have been the opposite.

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #19 on: December 29, 2014, 10:39:48 pm »
"Ambiguousness" depends on how strictly you or somebody else adhere to the rules. This is not ambiguous with priority rules
Code: [Select]
-2^2 =-(2^2) = -4x = -2; x^2 = (-2)^2 = 4If you know the rules and everybody plays by the rules, then all is OK. If either condition is broken ...

I disagree.  The problem is that one of those definitions of "-" is NOT an operation, and therefore is not subject to the agreed upon order of operations.  It's part of the definition of the number, and therefore must come before ANY mathematical operation on that number.
Please show a clear case where this is the issue. You do it by the rules, result should be the same. Also, those two meanings are almost identical in practice.

5 - 4 means either
• (5) - (4) or
• (5) (-4) = [so what now? What is the operation between two numbers? We seem to have broken math by your interpretation. Obviously, addition] = (5) + (-4)
We interpreted minus symbol both ways and got the same result. No surprises here.
Mathematics has rules to make it consistent.

Have you studied any math subject in college/uni? How do compare math there to school level?
Maybe there is difference in teaching of such things. Many of my lecturers have strong (negative) observations about school math level teaching. There were even articles released about some of the issues.
« Last Edit: December 29, 2014, 10:48:30 pm by electr_peter »

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #20 on: December 29, 2014, 11:05:59 pm »
Please show a clear case where this is the issue. You do it by the rules, result should be the same. Also, those two meanings are almost identical in practice.
You mean other than the entire premise on which this thread is based?

-2^2

That's as clear-cut an example where the definition of "-" changes the result.  Either it's the mathematical operation "minus", in which case there is an implied 0 that you're subtracting from, and order of operations defines that the exponent is computed first, OR there's an implied "1*" and it should actually be -1*2^2, in which case order of operations defines that the exponent is computed first, OR it's defining the number "negative two", in which case it's actually (-2)^2.

If you type "-2^2" into a program, chances are most languages would return -4, but that doesn't mean it's not ambiguous.  If somebody were to write down on a piece of paper "-2^2", chances are they mean "(-2)^2", since as I said before, nobody would write -2^2 and mean -(2^2) (unless it was following some other number, eg y-2^2), they would write -1*2^2 instead.  If somebody on my team were to put "-2^2" into a program, I would demand that they add parenthesis to clarify the operation.  Even if they actually did mean -(2^2), as the compiler would most likely interpret it, that doesn't mean it won't trip up every person who reads through the code.  The person reading through the code might know it would come out as -4, but how do they know that's what the developer meant to do?  Most of the time you see that in code, it's a typo, and the developer actually meant (-2)^2.  A side effect of translating a written equation into code without taking into account the interpretation of the "-" symbol by the compiler.

Have you studied any math subject in college/uni? How do compare math there to school level?
Maybe there is difference in teaching of such things. Many of my lecturers have strong (negative) observations about school math level teaching. There were even articles released about some of the issues.
Yes, I have a BSEE with a math minor.  Grade school math was a joke by comparison, and the teachers were beyond useless.
« Last Edit: December 29, 2014, 11:14:37 pm by suicidaleggroll »

#### Neganur

• Supporter
• Posts: 1114
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #21 on: December 29, 2014, 11:14:45 pm »
[...]none now that it is established that x^2 and for x=-1 the result of x^2 is (-1)^2 ad not -1^2 as the results would have been the opposite.

-1^2 is terrible style, avoid it at all cost. You can spend all day arguing with someone about if it is -(1^2) or (-1)^2 because both have a strong case.

In university math and engineering it is strongly advised to use parenthesis, since the goal is to minimize errors and to communicate proof. It can be assumed that 9 out of 10 times (-1) is what was meant and the author was just lazy, this is very common. Again, avoid this by all means.

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #22 on: December 29, 2014, 11:21:34 pm »
-1^2 is terrible style, avoid it at all cost. You can spend all day arguing with someone about if it is -(1^2) or (-1)^2 because both have a strong case.

Well the whole question was around how to write the equation when the unknowns were substituted in and how to interpret that substitution. At the end of the day there is only one way of interpreting each way of writing it down it's a case of writing it down correctly in the first place and then interpreting it correctly when you work it out.

I have found from limited personal experience that using parentheses even slightly in excess does help clarify matters particularly when writing software to ensure the compiler does not get it wrong.

#### IanB

• Super Contributor
• Posts: 9630
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #23 on: December 29, 2014, 11:36:22 pm »
This is an awfully long thread for a question that shouldn't be a question, so let's try to clarify it:

x2 means "x squared" which means "x times x". There can be no possible ambiguity about this.

If x = 2 then x2 is 2 times 2 which is 4.

If x = -2 then it is -2 times -2, which is also 4.

I'm writing this in words rather than symbolic notation to make it especially clear what is going on here. It is about taking one number and multiplying it by another number. A number is a "thing", and a negative number is just as much a "thing" as a positive number.
I'm not an EE--what am I doing here?

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #24 on: December 29, 2014, 11:38:47 pm »
Yes we have been over it twice already although some of us still struggle with the concepts.

#### IanB

• Super Contributor
• Posts: 9630
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #25 on: December 29, 2014, 11:50:33 pm »
Yes we have been over it twice already although some of us still struggle with the concepts.
OK, but it's really important to grasp that -2 is a complete whole number to itself, it is not "-" and "2" as if somehow they could be separated. Sometimes -2 might be written as -2 to reinforce this.
I'm not an EE--what am I doing here?

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #26 on: December 29, 2014, 11:50:47 pm »
Please show a clear case where this is the issue. You do it by the rules, result should be the same. Also, those two meanings are almost identical in practice.
You mean other than the entire premise on which this thread is based?

-2^2
...
I can understand why is it somewhat ambiguous with +/- final result. As I said, correctly defined rules solves this problem without any ambiguity (in theory)

However, in practice you want to have final result correct while intermediate steps are being done by person/compiler/... who can interpret the logical operations in it's own way. This leads you only one option - strictly adhere to the rules and at all costs avoid any possibility for interpretation by using parenthesis.

That is, rewrite equation/formula in more easily understable way.
-2^2 could become x=2; -x^2 or extreme case obvious for anyone and anything (-((2)^(2))). I would argue that later case is hardly comprehensible for humans with more numbers and functions, but gets job done in programs/compilers.
It is not nice practical solution for operation priority problem "If you know the rules and everybody plays by the rules, then all is OK. If either condition is broken ..."
« Last Edit: December 29, 2014, 11:52:21 pm by electr_peter »

#### Neganur

• Supporter
• Posts: 1114
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #27 on: December 30, 2014, 12:27:29 am »
Hmm, I read the whole thing again and I'm pretty sure you (Simon) had the position that you want to put a parenthesis around the numbers you substitute for a variable. I agreed. (yes! 7)

What I was commenting was that someone started arguing that this is only the case "when '-' means the mathematical operation 'minus'", which is utter nonsense. Minus is always minus.
This happens when variables are confused with values. Expressions with variables is fine and substituting without parenthesis is bad style.

-x^2 cannot be misinterpreted (by mathematicians). There is no, "but the '-' here means that x has a negative sign!". The value of the variable x did not change (you may not even know the value).
Or let me ask very provokingly, do you claim that "-x" is a negative number

Regarding compilers and programs, I don't know how the compiler does math but I assume it adheres to operator precedence. Anything else would be terrible!

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #28 on: December 30, 2014, 04:04:22 am »
What I was commenting was that someone started arguing that this is only the case "when '-' means the mathematical operation 'minus'", which is utter nonsense. Minus is always minus.

I was merely trying to draw a distinction between the "-" symbol when used to denote a negative number, versus the "-" symbol when used to denote a subtraction operation.  The two are similar, but not the same.

The former is part of the number, and is not subject to order of operations (PEMDAS), the latter is a mathematical operation that is subject to PEMDAS.

-1^2 can be interpreted both ways.  Either "negative one, squared", or if you follow PEMDAS, -(1^2).  This is where the ambiguity stems from.  Does the "-" mean "negative one", or is it a simple mathematical operation that should be applied after the exponent.  Most compilers would follow the latter, while most human-written equations would imply the former.  As you said, this kind of syntax should be avoided at all costs, use parenthesis and it's not a problem.

And yes, every time you do a variable substitution, stick parenthesis around it to avoid any confusion.  Eg:

Code: [Select]
{x^2 -3xy^3 +2z^2} / {x(y^2 -z)} x=-1y=-2z=1would become
Code: [Select]
{(-1)^2 - 3(-1)(-2)^3 + 2(1)^2} / {(-1)[(-2)^2 - (1)]}
« Last Edit: December 30, 2014, 04:09:46 am by suicidaleggroll »

#### c4757p

• Super Contributor
• Posts: 7805
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #29 on: December 30, 2014, 04:14:56 am »
-1^2 can be interpreted both ways.  Either "negative one, squared", or if you follow PEMDAS, -(1^2).  This is where the ambiguity stems from.  Does the "-" mean "negative one", or is it a simple mathematical operation that should be applied after the exponent.  Most compilers would follow the latter, while most human-written equations would imply the former.  As you said, this kind of syntax should be avoided at all costs, use parenthesis and it's not a problem.

Through all of my education so far, including part of a math degree, I always learned that -1^2 = -(1^2) because a prefix of "-" is equivalent to multiplication by negative one: it sits in the same place as multiplication in the order of operations. It's frowned upon to write that in places where one is trying to be as clear as possible, but I've never met anybody who knows what he's talking about, who doesn't know that -1^2 = -(1^2).
No longer active here - try the IRC channel if you just can't be without me

#### Neganur

• Supporter
• Posts: 1114
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #30 on: December 30, 2014, 04:33:10 am »
-1^2 can be interpreted both ways.

It cannot possibly be interpreted wrong. You either follow rules of arithmetic or you admit that your expression it is mis-spelled and needs parenthesis because you claim that the minus is a sign, and want it to be stronger than the exponentiation. You cannot use the sign of a number this way. As I said, it is bad style.

#### miguelvp

• Super Contributor
• Posts: 5549
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #31 on: December 30, 2014, 04:37:56 am »
If someone has any of the following programming languages, just test it and I'm pretty sure it will do the exponentiation first and then multiply by negative 1

Algol, Commodore BASIC, BASIC, J, MATLAB, R, Microsoft Excel, TeX, TI-BASIC, bc, Lua, ASP and most computer algebra systems D, Ada, Bash, COBOL, CoffeeScript, Fortran, FoxPro, Gnuplot, OCaml, F#, Perl, PHP, PL/I, Python, Rexx, Ruby, SAS, Seed7, Tcl, ABAP, Mercury, Haskell, Turing, VHDL.

Source: http://en.wikipedia.org/wiki/Exponentiation#In_programming_languages

The rest of the languages will use a function so you can't write it like that so it doesn't matter.

The exponent operator for all those languages varies:^, ^^, ** and up-arrow which I don't have on my keyboard.

Edit: Python
Code: [Select]
Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> print -1**2-1>>>
« Last Edit: December 30, 2014, 04:44:49 am by miguelvp »

#### Christopher

• Frequent Contributor
• Posts: 429
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #32 on: December 30, 2014, 06:44:17 am »
Simon I occasionally forgot math laws when studying for my HNC/D. have a look at this, it helped me as it's a quick reference

Math cheat sheet - by Dr Seiden

#### Simon

• Global Moderator
• Posts: 14441
• Country:
• Did that just blow up? No? might work after all !!
##### Re: A little bit of a maths problem with indices
« Reply #33 on: December 30, 2014, 09:41:37 am »
Well at the moment it is the mass that I am studying, hopefully once I am through this maths module I can get on with the good old electronics HNC without having to be too pedantic about the maths. Because I am a clever cookie sometimes I realised that this particular exercise was designed to see if I had understood how to substitute a number into an expression and yes the order of precedence of the operations.

#### IanB

• Super Contributor
• Posts: 9630
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #34 on: December 30, 2014, 09:56:16 am »
You can investigate this with your calculator. Enter -2 onto the display and then press the x2 button. Do you get 4 or -4 as the result?

(Also take note of  how you enter -2. I.e. you don't press "-" and then "2", rather you press "2" first and then press the "+/-" key. This illustrates how the sign belongs to the number and is not a subtraction operation.)
I'm not an EE--what am I doing here?

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #35 on: December 30, 2014, 02:23:19 pm »
You can investigate this with your calculator. Enter -2 onto the display and then press the x2 button. Do you get 4 or -4 as the result?

(Also take note of  how you enter -2. I.e. you don't press "-" and then "2", rather you press "2" first and then press the "+/-" key. This illustrates how the sign belongs to the number and is not a subtraction operation.)

Exactly.  It's just one of those subtle differences between how humans write equations and how those equations as written would be interpreted by a compiler.  Calculators have separate + (add), - (subtract), and +/- (positive/negative) buttons for this reason.  Programming languages/compilers don't, so you need parenthesis to specify.

Another example is division.  When humans write equations, there are multiple signs for division.
Code: [Select]
  4  --  5-----  6is different than
Code: [Select]
  4-----  5  --  6
Compilers don't have "big" and "little" division signs.  If you type "4/5/6" into a computer program, it's going to do the former, you need parenthesis to specify the latter, even though no parenthesis are necessary and they look very similar when written on paper.

90% of the time if I see an equation start with a minus sign in a program, it either doesn't make a difference (eg: -2+3), or it's a typo (eg: -2^2).  Unfortunately you have to go back to the original equation from whatever paper/publication/derivation it came from to verify.  I also cringe whenever I see "4/5/6".  Most of the time it's written correctly, but a significant portion of the time it's a mistake in transcribing the equation and needs parenthesis.

If you just follow PEMDAS verbatim like a robot, you're going to make a terrible code debugger.  You have to recognize the nuances in human writing, including math equations, and notice when an equation, as written, could be a mistake that would give the wrong result from a compiler.  It's also not enough to make sure the compiler does what you want, you need to make sure that future debuggers and developers know that's what you meant to do as well.  The "subtract" versus "negative" meanings of the "-" symbol is just one of these nuances.

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #36 on: December 30, 2014, 03:00:05 pm »
It cannot possibly be interpreted wrong. You either follow rules of arithmetic or you admit that your expression it is mis-spelled and needs parenthesis because you claim that the minus is a sign, and want it to be stronger than the exponentiation. You cannot use the sign of a number this way.

Where is this coming from?  You seem to have done a complete 180 since posting this just a few hours before (with which I agree completely):
-1^2 is terrible style, avoid it at all cost. You can spend all day arguing with someone about if it is -(1^2) or (-1)^2 because both have a strong case.

In university math and engineering it is strongly advised to use parenthesis, since the goal is to minimize errors and to communicate proof. It can be assumed that 9 out of 10 times (-1) is what was meant and the author was just lazy, this is very common.

All I've been saying, from the start, is that "-1^2" (or if you prefer, "-12") is ambiguous and should be avoided.  As a hand-written equation, chances are it means "(-1)^2", in computer code it will be interpreted as "-(1^2)".  That's the definition of ambiguity.  I'm amazed at the number of people saying it's not ambiguous at all and couldn't possibly be interpreted or intended as anything but "-(1^2)", which is just ignorant.
« Last Edit: December 30, 2014, 03:10:20 pm by suicidaleggroll »

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #37 on: December 30, 2014, 03:32:39 pm »
Question is why one would write something like -2^2 in a program at all? That is not efficient and borderline crazy - pre-calculate and then white full number/constant and save some clock cycles.

If you are paranoid that your writing can be misinterpreted, rewrite equation in a different way or use parenthesis everywhere.
If you are paranoid that you can not interpret writings of other people, that is your problem.

All this minus ("-") stuff has nothing to do with any compilers or mathematics itself. It has something to do with the users.

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #38 on: December 30, 2014, 04:11:06 pm »
Question is why one would write something like -2^2 in a program at all? That is not efficient and borderline crazy - pre-calculate and then white full number/constant and save some clock cycles.
You must not do a lot of work with complicated equations and math in programs?  Any decent compiler will pull it out, that's not a problem, but clarity is.  Writing known constants correctly has great value when using large equations, it makes finding mistakes and making your intent clear without even having to comment it.  Boiling complicated equations down as far as possible, while it might make you feel better about yourself, won't make the resulting code any quicker (as long as the compiler is reasonably intelligent), it will just make debugging next to impossible.

All this minus ("-") stuff has nothing to do with any compilers or mathematics itself. It has something to do with the users.
The problem is the translation between mathematical concepts and their symbolic representations in our numeral system.

Negative two is a concept, it's not "negative one times two", it is its own number.  It just so happens that our numeral system represents the number "negative two" as "-2", which could also be interpreted as "-1*2", and that's where the breakdown occurs.  By introducing the multiplication by -1 (also its own number, or is it -1*1?  Which would be -1*1*1, and so on), you add an operation, which means PEMDAS takes effect and you have the opportunity to screw things up unless you add parenthesis to force the compiler, reader, whoever to interpret that number as "negative two" instead of "negative one times 2".

Math is unambiguous, but the symbolic representation of math in our numeral system is not.  Just like our language itself, there are multiple meanings, implications, etc. that need to be taken into account if you want to interpret an ambiguous combination of symbols in the way the author intended.  In an ideal world people would always use parenthesis to clarify their intent and there would never be a problem, but the real world isn't so simple.  People make implications or assumptions without even realizing it, usually through laziness, and when that happens it's up to the reader to recognize at least the possibility of an error and take appropriate action, whether it's to ask the author to clarify or to look up the source and re-derive the equation from scratch to verify.  -12 is one of those cases.
« Last Edit: December 30, 2014, 04:16:55 pm by suicidaleggroll »

#### mrflibble

• Super Contributor
• Posts: 1982
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #39 on: December 30, 2014, 04:42:46 pm »
Buy a decent calculus book is all I can say.

-1^2 is not open for interpretation. No, not even if you have been taught so by some lying community college pamphlet or other. What you have there is the unary minus operator and the power operator, and operator precedence. As luck would have it, any university level calculus or algebra book I have ever read that starts with a formal definition of the algebra also defines the unary minus roughly like so:

unary minus operator acting on an element a: -a, such that (-a) + (a) = 0

And precedence is also totally defined.

-a^n = -(a^n)

The End. No debate, no context. Come on, this is math. Yes, great idea, lets make things ambiguous when there is an easy way to define things clearly. Pfffffrt.

Of course you don't have to believe me. In which case give me a book reference for a decent uni level calculus or algebra book that opens up the unary minus for debate. That said, it cannot hurt to explicitely use some parenthesis. So yes, I would probably also write (-1)^2 just to be sure there is no confusion induced by a less formal math education. But to say that -1^2 is ambiguous is bullshit. The definition is the definition, and -1^2 = -(1^2) = -1. Power operator takes precedence over unary minus.

The situation also is not helped by programming languages, where things can be different. But we are talking about mathematics in written form here, and there the definition is clear. So please no "examples" from the field of programming please. Different different thing is different because it is not the same. The topic here is written mathematics, zero computers, zero software.

I can quote wikipedia here (since it backs up my argument), but for subtle points like this wikipedia sucks. I certainly would not accept it as an authoritive answer to something like this, so I will not inflict it on someone else either. This is a reasonable post on the subject, but not authoritive either: http://mathforum.org/library/drmath/view/53194.html

In closing, get a decent calculus book and check the definitions.

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #40 on: December 30, 2014, 04:55:02 pm »
Question is why one would write something like -2^2 in a program at all? That is not efficient and borderline crazy - pre-calculate and then white full number/constant and save some clock cycles.
You must not do a lot of work with complicated equations and math in programs?  Any decent compiler will pull it out, that's not a problem, but clarity is.  Writing known constants correctly has great value when using large equations, it makes finding mistakes and making your intent clear without even having to comment it.  Boiling complicated equations down as far as possible, while it might make you feel better about yourself, won't make the resulting code any quicker (as long as the compiler is reasonably intelligent), it will just make debugging next to impossible.
I do write programs including heavy computational stuff, just for you to know.
You know, there is concept called comments in almost every programming language. Expecting every computable program line to be easily read by anyone without a clue is a share lunacy.
There are various ways to deal with the simplification - but that is still a problem for you.

All this minus ("-") stuff has nothing to do with any compilers or mathematics itself. It has something to do with the users.
The problem is the translation between mathematical concepts and their symbolic representations in our numeral system.

[rambling about how you don't understand definitions]
What is your problem? You seem to have problem understanding basic concepts of mathematics, yet still you claim to have a strong point about something.
Teach yourself something - read introductory booksabout algebra, mathematic definitions and logic.
« Last Edit: December 30, 2014, 04:59:47 pm by electr_peter »

#### suicidaleggroll

• Super Contributor
• Posts: 1455
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #41 on: December 30, 2014, 05:49:12 pm »

You're right, there's no such thing as negative numbers, only negative unary operators on positive numbers.

Pointless debate is pointless, I'm out.

#### mrflibble

• Super Contributor
• Posts: 1982
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #42 on: December 30, 2014, 06:01:39 pm »
Just because you have a use case and youthink math should work such and such does not make it so. And that is the whole point here. I get your confusion and why you think it should be the way you would like it to be, but the definition does not give a shit about your confusion nor your feelings. It is what it is. No point arguing because you would like things to be different.

The math is well defined. Read a book.

#### c4757p

• Super Contributor
• Posts: 7805
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #43 on: December 30, 2014, 06:11:30 pm »
Question is why one would write something like -2^2 in a program at all? That is not efficient and borderline crazy - pre-calculate and then white full number/constant and save some clock cycles.
You must not do a lot of work with complicated equations and math in programs?  Any decent compiler will pull it out, that's not a problem, but clarity is.  Writing known constants correctly has great value when using large equations, it makes finding mistakes and making your intent clear without even having to comment it.  Boiling complicated equations down as far as possible, while it might make you feel better about yourself, won't make the resulting code any quicker (as long as the compiler is reasonably intelligent), it will just make debugging next to impossible.
I do write programs including heavy computational stuff, just for you to know.
You know, there is concept called comments in almost every programming language. Expecting every computable program line to be easily read by anyone without a clue is a share lunacy.
There are various ways to deal with the simplification - but that is still a problem for you.

The compiler will do the computation before compiling. This is not up for debate - grab the assembly output and look at it. What kind of shitty compiler wouldn't?

This is "share" lunacy:

Code: [Select]
// 3*5*7*9*11*13*15*17 = 34459425i += 34459425;
What kind of shitty programmer would write that? The compiler will generate the exact same code for this:

Code: [Select]
i += 3*5*7*9*11*13*15*17;
Quote
Expecting every computable program line to be easily read by anyone without a clue is a share lunacy.

No, it's common freaking sense.

And for Christ's sake, why are we arguing about the order of operations at all? All you people who think -2^2 is ambiguous might as well be arguing that 2+2 is ambiguous because someone might look at it with his head cocked and mistake the + for a ×! It's absurd. There is a defined order of operations, and negation falls in that. That is not ambiguous.

That, by the way, is a completely different argument to whether or not it's good practice, for the sake of the understanding of people who don't know the order of operations. "Ambiguous" and "unclear" are not the same thing. Using points from one argument against the other argument is just hamfisted - surely you people can produce better arguments than that.
« Last Edit: December 30, 2014, 06:19:03 pm by c4757p »
No longer active here - try the IRC channel if you just can't be without me

#### electr_peter

• Supporter
• Posts: 936
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #44 on: December 30, 2014, 06:28:44 pm »
The compiler will do the computation before compiling. This is not up for debate - grab the assembly output and look at it. What kind of shitty compiler wouldn't?

This is "share" lunacy:

Code: [Select]
// 3*5*7*9*11*13*15*17 = 34459425i += 34459425;
What kind of shitty programmer would write that? The compiler will generate the exact same code for this:

Code: [Select]
i += 3*5*7*9*11*13*15*17;
You suggested this poor example. There is nothing to comment really.
And not everything can be written in numbers - you can use various constants and variables (end result would be the same). Variable name can explain number value  better than number itself.

Quote
Quote
Expecting every computable program line to be easily read by anyone without a clue is a share lunacy.
No, it's common freaking sense.
Expectation for every line to be easily readable is a share lunacy. Programming in a way that is readable is(and should be) a common sense.

#### c4757p

• Super Contributor
• Posts: 7805
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #45 on: December 30, 2014, 06:33:02 pm »
You suggested this poor example. There is nothing to comment really.
And not everything can be written in numbers - you can use various constants and variables (end result would be the same). Variable name can explain number value  better than number itself.

Yes, obviously the use of "magic numbers" is also poor practice, but that's a separate point. Obviously I didn't have a real-life use case immediately available, so I grabbed some numbers to demonstrate my point...
No longer active here - try the IRC channel if you just can't be without me

#### IanB

• Super Contributor
• Posts: 9630
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #46 on: December 30, 2014, 08:03:47 pm »
Come on, this is math.
No, it's not math. It's a fussy, anally retentive argument about symbols on a screen, somewhat akin to language pedants arguing about grammar. Grammar is not communication any more than a symbolic notation is mathematics. To believe that PEMDAS (which, by the way is alien to the British, who are familiar with BODMAS) is relevant to the study and understanding of mathematics is to completely miss what mathematics is about.
I'm not an EE--what am I doing here?

#### mrflibble

• Super Contributor
• Posts: 1982
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #47 on: December 30, 2014, 08:55:31 pm »
The this in that (*) quote was intended as having a little wider scope than the yesnoyesno argument going on, but what the hell. You can read it that way if you like. My bad for not dereferencing every fucking word to prevent an out of context quote. I'll agree with you that there are more important parts about math than the purely pedantic parts. Anyways, I stand by what I wrote and am done with this thread as well. Enjoy!

(*) Uh-oh another reference.

#### Neganur

• Supporter
• Posts: 1114
• Country:
##### Re: A little bit of a maths problem with indices
« Reply #48 on: December 30, 2014, 09:34:28 pm »
You seem to have done a complete 180 since posting this just a few hours before (with which I agree completely):

I did not change my position, I still agree with you that there are cases where people use poor style and I think that it is pointless to argue about it because it is very clear to those people what was meant (think of a typical person writing on the blackboard while talking to an audience and never using parenthesis when substituting - possibly even announcing that he does so, before he starts).

However, I shifted my focus a bit more to the point that this is not the way maths is being taught and that it, strictly speaking, is wrong.

I am a bit worried about the argument that compilers or calculators do it wrong, it sounds more like poor implementation of the expressions by the programmer. It also sounds like you have to evaluate (and correct) "what the hell did the programmer mean" on a regular basis? You have all my sympathy in that case, that does not sound like it is fun.

#### T3sl4co1l

• Super Contributor
• Posts: 14729
• Country:
• Expert, Analog Electronics, PCB Layout, EMC
##### Re: A little bit of a maths problem with indices
« Reply #49 on: December 31, 2014, 12:52:17 am »
Oh, just a niggle about "indices":

You're talking about exponents (superscript following a quantity).

Indices are, in most notations, a subscript following a variable, which is used to convey something about that variable.  Much as a function f(x) is used to provide a value to the expression for f, the index F_i is used to provide a value to the expression for F.

Typical uses of indices include discrete time systems -- DSP -- where the sample number (and therefore time) is indicated with an index, as x[i ] or x_i.

(And yes, you can have both, so {x_n}^2 is called "x sub n squared" or "nth value of x, squared".  Ugh, this gets tricky to talk about, because I want to use the braces {} to indicate that the 'square' goes outside of the index.  It's not enough to say "x_n^2" because, the way that's usually formatted, the 2 looks like a superscript index -- which is indeed used occasionally as an index as well!  Yes, some branches of math use both superscript and subscript indices.  Some also use prefix indices.)

TLDR: mathematicians can't make up their mind on coherent formatting..?

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!

Smf