Post Reply 
Unary minus precedence preference
07-24-2014, 04:11 PM
Post: #27
RE: Unary minus precedence preference
I'll start by saying that I agree that -2^2 should be -4.

Now some philosophical thoughts. It seems to me that the problem is that we use "-" for at least 3 different operations:
  1. subtraction: a - b
  2. unary minus: -x is shorthand for 0-x
  3. specifier for negative numbers: -5 is a number on the number line.


The last one may require some explanation: I'm saying that in this case, the "-" is part of the number, not an operation. The same is true of the decimal mark: in "5.2", the "." isn't an operation, it's part of the way we specify the number itself.


To see the difference, consider the following on a 50g:
Code:
X [ENTER] 5 [+/-] -   ---> 'X--5'
In other words, this is the variable X minus a real number (negative 5)

Or the strange case where sometimes numbers must be enclosed in parenthesis:
5 X Y^X [ENTER] -> '5^X'
5 [+/-] X Y^X [ENTER] ---> '(-5)^X'

This means that decompiling symbolic expressions is hard: negative numbers decompile differently depending on the operations they're involved in.

All of this would be easier of we used different symbols. Suppose:
  • negative numbers are specified with prefix "n". e.g. n5 means -5
  • subtraction is the negative sign: -
  • unary minus is "um"

Now nX^2 isn't a valid math expression. Neither is -X^2 since "-" is a binary operator. umX^2 is the original problem. This is NOT subtraction, so its precedence isn't specified by the PMDAS rules. Mathmatically, it would seem to come between Multiplication/Division and Addition/subtraction, so school children would be taught PMDUAS. Smile

What about 4-2^2 vs -2^2+4? In the new notation it's clear that you're using different operations here: 4-2^2, 4+n2^2 and 4+um2^2 are all different expressions (the latter simplifies to 4-2^2).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Unary minus precedence preference - David Hayden - 07-24-2014 04:11 PM



User(s) browsing this thread: 1 Guest(s)