Unary minus precedence preference
07-24-2014, 01:57 AM
Post: #21
 Claudio L. Senior Member Posts: 1,681 Joined: Dec 2013
RE: Unary minus precedence preference
(07-23-2014 10:10 PM)htom trites Wrote:  This really comes down to precedence and associations. Part of the reason that 0-2^2 "feels like" -4 is that our minds bind the - as a subtraction (which it is, it's not unary!)

The conflict is that unary - , to be truly unary, has to bind as or higher than parentheses; -2^2 has to become (-2)^2.

So there is no unary -, it's just a writing convention of deleting the 0.

Regarding the existence or not of the unary minus operator, I think in computing the unary minus is very real. I don't know if it meets your standards to be "truly unary" but it is real enough for all HP calculators to have a key dedicated to the unary minus (NEG, +/-, CHS), and a separate one for the binary minus.
And more so thinking in RPN, where there's no ambiguity, no operator precedence, and not even algebraic expressions. Yet the unary minus exists by itself.
I could also point out that in two's complement, the unary minus is not defined as (0-x), but it's defined as (~x)+1, where ~ is an operator that toggles all bits (XOR 0xFFFFFFF...). Granted, with the properly defined subtraction in the same domain, 0-x should give the same result as -x, but the definition of the unary minus exists by itself and is independent from the binary minus. And in hardware where you have only adders, it's common to define the binary minus in terms of the unary minus:
a-b = a+(-b) = a+(~b)+1
So in that case, the unary minus exists, but the binary minus doesn't!
And I guess you could generalize that and say that the subtraction doesn't exist, it's actually the addition of a negative number.
It's all a matter of perspective.

Claudio
 « Next Oldest | Next Newest »

 Messages In This Thread Unary minus precedence preference - Claudio L. - 07-21-2014, 08:00 PM RE: Unary minus precedence preference - walter b - 07-21-2014, 08:09 PM RE: Unary minus precedence preference - Claudio L. - 07-21-2014, 09:13 PM RE: Unary minus precedence preference - Thomas Radtke - 07-22-2014, 07:56 AM RE: Unary minus precedence preference - John R - 07-23-2014, 02:36 AM RE: Unary minus precedence preference - Claudio L. - 07-23-2014, 01:45 PM RE: Unary minus precedence preference - Wes Loewer - 07-23-2014, 07:59 PM RE: Unary minus precedence preference - Claudio L. - 07-23-2014, 09:10 PM RE: Unary minus precedence preference - walter b - 07-22-2014, 09:09 PM RE: Unary minus precedence preference - SlideRule - 07-22-2014, 06:18 PM RE: Unary minus precedence preference - Don Shepherd - 07-22-2014, 06:50 PM RE: Unary minus precedence preference - CosmicTruth - 07-23-2014, 01:59 AM RE: Unary minus precedence preference - htom trites - 07-23-2014, 03:14 AM RE: Unary minus precedence preference - John R - 07-23-2014, 04:16 AM RE: Unary minus precedence preference - ttw - 07-23-2014, 03:40 AM RE: Unary minus precedence preference - Wes Loewer - 07-23-2014, 12:08 PM RE: Unary minus precedence preference - Claudio L. - 07-23-2014, 02:05 PM RE: Unary minus precedence preference - Wes Loewer - 07-23-2014, 08:27 PM RE: Unary minus precedence preference - Wes Loewer - 07-24-2014, 07:31 AM RE: Unary minus precedence preference - Marcus von Cube - 07-24-2014, 08:53 AM RE: Unary minus precedence preference - walter b - 07-24-2014, 09:01 AM RE: Unary minus precedence preference - Claudio L. - 07-24-2014, 01:35 PM RE: Unary minus precedence preference - Marcus von Cube - 07-24-2014, 01:53 PM RE: Unary minus precedence preference - Tim Wessman - 07-23-2014, 05:57 PM RE: Unary minus precedence preference - htom trites - 07-23-2014, 10:10 PM RE: Unary minus precedence preference - Claudio L. - 07-24-2014 01:57 AM RE: Unary minus precedence preference - David Hayden - 07-24-2014, 04:11 PM RE: Unary minus precedence preference - Don Shepherd - 07-25-2014, 11:26 AM RE: Unary minus precedence preference - Les Bell - 07-25-2014, 03:15 AM RE: Unary minus precedence preference - Eddie W. Shore - 07-29-2014, 07:25 PM

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