| PhamNuwen |
| Posted: Sep 1 2007, 01:23 PM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
| CODE | init { a = 10 temp = -a^2 printdeep ("-a^2", temp) temp = -(a^2) printdeep ("-(a^2)", temp) temp = (-a)^2 printdeep ("(-a)^2", temp) }
|
OUTPUT ------ Print Output ------ 1: -a^2: 100 1: -(a^2): -100 1: (-a)^2: 100
Does that seem wrong to anyone else?
For example, I might expect EXP^(-(x-u)^2/s^2), where EXP = 2.61, to always be less than one normally, but here .. it would not be. |
| hunter |
| Posted: Sep 1 2007, 05:09 PM |
 |
|

hunter: 99% nerd 1% dwarf star matter
    
Group: Registered Owners
Posts: 543 (14 robots)
Member No.: 191
Joined: 23-April 04

|
No.. That's exactly right.
negativeNumber*negativeNumber = positiveNumber
-------------------- There are only 10 type of people in the world. Those who speak binary and those who don't. |
| yoyodyn |
| Posted: Sep 1 2007, 07:09 PM |
 |
|
Academic Advocate
    
Group: Registered Owners
Posts: 237 (3 robots)
Member No.: 145
Joined: 19-February 04

|
I think some other programming languages might give the exponent operator a higher precedence but other than that it looks right.
-------------------- "Yea though I walk through the valley of the shadow of Gates, I will fear no Windows." |
| PhamNuwen |
| Posted: Sep 2 2007, 06:02 AM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
In any language I've ever used, the exponent had higher precedence:
Compare:
-1*x^2 -1*x*x -x*x 1 - x^2 1 + (-1*x^2)
- x^2 is really implied -1*x^2.
and multiplication has a lower precedence than exponentiation.
But maybe thats just not always how its done. Are there really computer languages where "-x^2" is positive?
If you considered ^ an operator that acted like ^(n1,n2) with n1 ^ n2, then I could see -10^2 being positive. But still -x^2 has to be 2 operators, the minus sign (which is equivalent to -1*) and the ^.
This post has been edited by PhamNuwen on Sep 2 2007, 06:11 AM |
| chess123mate |
| Posted: Sep 2 2007, 08:31 AM |
 |
|
Logical Programmer
    
Group: Members
Posts: 587 (24 robots)
Member No.: 936
Joined: 3-February 07

|
I agree, it doesn't look right. You are supposed to do the exponents first according to that famous BEDMAS, and the negative sign is much like "0 - a" or "0 - x".
I wonder what happens if you do "0 - a ^ 2"... |
| PhamNuwen |
| Posted: Sep 2 2007, 11:43 AM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
1: 0 - a^2: -100 |
| hunter |
| Posted: Sep 2 2007, 03:28 PM |
 |
|

hunter: 99% nerd 1% dwarf star matter
    
Group: Registered Owners
Posts: 543 (14 robots)
Member No.: 191
Joined: 23-April 04

|
but when you're doing that, you aren't thinking -1*a^2, which would be negative, you're thinking (well, at least this is how i think) (-a)^2, which should be positive. i
-------------------- There are only 10 type of people in the world. Those who speak binary and those who don't. |
| PhamNuwen |
| Posted: Sep 2 2007, 04:00 PM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
Not quite sure what you mean, but I think -a^2 = -(a^2) . Exponent should take precedence over everything but the trig functions. If I were to do math on paper, and I wrote, -a^2, that is the exact same thing as -(a^2). I think its even pretty clear when I put that in my post. Matlab and IDL both interpret -a^2 as -(a^2).
So the program does fine with 0-a^2. But somehow -a^2 is not equal to 0-a^2. It is pretty easy to get around though, now that I realize how it works in RSL.
This post has been edited by PhamNuwen on Sep 2 2007, 04:04 PM |
| yoyodyn |
| Posted: Sep 2 2007, 04:35 PM |
 |
|
Academic Advocate
    
Group: Registered Owners
Posts: 237 (3 robots)
Member No.: 145
Joined: 19-February 04

|
Just to play devil's advocate,
What if you take variables out of it.
does: -2^2 = 4 or -4?
And does writing it on paper or in a computer make a difference to the interpretation in this case?
This post has been edited by yoyodyn on Sep 2 2007, 04:36 PM
-------------------- "Yea though I walk through the valley of the shadow of Gates, I will fear no Windows." |
| hunter |
| Posted: Sep 2 2007, 04:51 PM |
 |
|

hunter: 99% nerd 1% dwarf star matter
    
Group: Registered Owners
Posts: 543 (14 robots)
Member No.: 191
Joined: 23-April 04

|
okay, everyone, a^2, means a*a, a^3 means a*a*a, etc etc. a negative number, times a negative number, is positive, -2^2, is 4, not -4.
-x^2 is not really implied -1*x^2, it's implied (-1*x)^2, so parentheses take precedence over exponent.
IMO, and that of math teachers i've had, 0-a^2, would be the same as -1*(a^2), -a^2 would be the same as (-1*a)^2.
-------------------- There are only 10 type of people in the world. Those who speak binary and those who don't. |
| PhamNuwen |
| Posted: Sep 2 2007, 05:52 PM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
| QUOTE | okay, everyone, a^2, means a*a, a^3 means a*a*a, etc etc. a negative number, times a negative number, is positive, -2^2, is 4, not -4.
-x^2 is not really implied -1*x^2, it's implied (-1*x)^2, so parentheses take precedence over exponent.
IMO, and that of math teachers i've had, 0-a^2, would be the same as -1*(a^2), -a^2 would be the same as (-1*a)^2.
|
if a^2 means a*a then -a^2 = -a*a = - (a^2) (Thats because of operator precedence) I will not say anything else about this, and I'm not going to quote credentials unless you ask, but I have done plenty of math in my life, and -a^2 is the same as -(a^2). You are simply wrong and your math teachers didn't know what they are talking about.... hope this doesn't sound too harsh.
Here is the wikipedia link, in case you still don't believe me.
http://en.wikipedia.org/wiki/Order_of_operations
| QUOTE | 5. Evaluate negation on the same level as subtraction, starting from the left:[1]
-3^2=-[3^2]=-9
|
When I made that first post I was somewhat under the assumption that everyone would agree with the basic principles. I usually try not to force my opinion. But in this case, you are simply wrong. Whether it should be fixed in RSL, after so many people have programmed already with this rule, is questionable. For anyone intuitively sees this the way I do, and uses exponents, I would check your code.
This post has been edited by PhamNuwen on Sep 2 2007, 05:55 PM |
| PhamNuwen |
| Posted: Sep 2 2007, 05:58 PM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
Ahh.. but here may be our confusion:
| QUOTE | Acting contrary to the standard order of operations, some programs, notably Microsoft Office Excel and the programming language bc, give unary operators a higher priority than binary operators, e.g. the unary minus (negation) has higher precedence than exponentiation. [3].
|
So there is some basis for using this order of operations in a programming language. I'd never heard about that before. |
| Ichabod |
| Posted: Sep 3 2007, 05:08 AM |
 |
|

Grand Vizier
    
Group: Contest Hosts
Posts: 1238 (16 robots)
Member No.: 700
Joined: 2-May 06

|
If you read the discussion section of that wikipedia article you quoted, you will see that there is not even agreement between mathematical professionals, at least when it comes to -2^2.
-------------------- -Ichabod Nils illegitimo carborundum
| QUOTE (Cho Setsu) | | By eliminating disturbances, we redouble the disease. |
131,628,711 robots killed in the name of simulation |
| steJ |
| Posted: Sep 3 2007, 05:40 AM |
 |
|

Tiny Bot Obsessive
    
Group: Moderators
Posts: 951 (13 robots)
Member No.: 9
Joined: 2-May 03

|
Never encountered any problems with this myself. I guess thats because i use lots of brackets!
I can see how issues could arise from this though, especially without a live debugger
-------------------- He who laughs last, thinks slowest. SteJ |
| PhamNuwen |
| Posted: Sep 3 2007, 01:25 PM |
 |
|
Serious Player
  
Group: Members
Posts: 39 (2 robots)
Member No.: 1142
Joined: 9-June 07

|
| QUOTE | If you read the discussion section of that wikipedia article you quoted, you will see that there is not even agreement between mathematical professionals, at least when it comes to -2^2.
|
Interesting point--I didn't read the discussion section. I can certainly see -2^2 being a little bit ambiguous. Especially in a computer language... depends whether it interprets -2 as a negative integer/float, or as the binary minus operation on the integer/float. |
|