Post Reply 
Unary minus precedence preference
06-04-2024, 11:54 AM
Post: #41
RE: Unary minus precedence preference
(07-23-2014 03:14 AM)htom trites Wrote:  Do you take -2^2 to mean: (-2)^2, -(2^2), or 0-(2^2)?

I've always taught that unary minus is the last (and should be parsed as if it was that by a computer), even though it's usually written as the second.

(I admit I came to this conclusion writing a compiler that emitted code for both one's and two's complement ALUs.)

I don't see any practical difference between your second and third meanings, only a notational difference.

On HP Prime and TI nNspire II CAS (and many others, it would seem) the unary minus is assigned the same priority as addition and subtraction so the exponentiation is done first.

-2^2 is seen as
-(2^2)

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-04-2024, 07:23 PM
Post: #42
RE: Unary minus precedence preference
And there are those that say we leave off a lot of operators and coefficients as they are assumed present. Arguably these operators are really always unary, was they only really relate to the number directly to the right:

2 - 3

is arguably:

+2 -3
or
-3 +2

With the number being left-associated with the operator, the '+' assumed and the order not really mattering.

I agree though that a negative number is a perfectly valid number, and it's hard to say that the number '3' can have the honour of being written 3², whereas the number '-3' does not have that honour and must sit in brackets. We also tend to put decimals in brackets too - i.e. I think 3.15² is usually written (3.15)². Even though on our RPN calculators we could easily square a perfectly valid number in our x register: -3.345x10³, I don't think any of us would expect to write that square without brackets.

But we can write a², even while a = -3.

I guess negative numbers and imaginary numbers aren't really 'real'. They are useful concepts to help our calculations. But we don't have negative mass, negative temperature, negative distances, negative apples in 'reality'.

In conclusion, unless you are a natural number, you can't expect to be a first class citizen in algebra!
Find all posts by this user
Quote this message in a reply
06-04-2024, 09:20 PM
Post: #43
RE: Unary minus precedence preference
(06-04-2024 07:23 PM)dm319 Wrote:  I guess negative numbers and imaginary numbers aren't really 'real'. They are useful concepts to help our calculations. But we don't have negative mass, negative temperature, negative distances, negative apples in 'reality'.

In conclusion, unless you are a natural number, you can't expect to be a first class citizen in algebra!

It's getting cold down here in Australia, the temperature outside is about -2 degrees C this morning. And our dollar is down too, about -1% against the USD. But I'll be working today, my leave balance at work is -6 days, since I took a vacation a couple of months ago. I'll be working on some LRC circuits, for which the impedance of my 220uF capacitors at 110hZ is -6.6i.

So there's lots of unary negatives in my real world today. Except for the capacitive reactance, which is an imaginary number.
Find all posts by this user
Quote this message in a reply
06-04-2024, 10:23 PM
Post: #44
RE: Unary minus precedence preference
I guess it depends on perspective (I'm not sure I really believe all this, but let me be the devils advocate for a moment)...

(06-04-2024 09:20 PM)Johnh Wrote:  It's getting cold down here in Australia, the temperature outside is about -2 degrees C this morning.

Sure, but this is a fabrication of the way we measure. Temperature as the movement of atoms ranges from nothing to a lot. -2 is just 2 less than an arbitrary amount.

(06-04-2024 09:20 PM)Johnh Wrote:  And our dollar is down too, about -1% against the USD.

Two positive values change from one day to the next in relation to each other. Sure the sign is useful to tell us how which way they change day by day, but arguably there isn't a negative AU$ - just real money owed in a different direction.

(06-04-2024 09:20 PM)Johnh Wrote:  But I'll be working today, my leave balance at work is -6 days, since I took a vacation a couple of months ago.

While using negative numbers is useful here, there isn't really such a thing as a negative day. You owe an extra 6 whole days to your employer to keep them happy. It's nice to use positive/negative to describe the flow of things one way or another, but they are just whole things moving one way or another. If I owe you 6 apples, I don't actually have 6 anti-apples.

(06-04-2024 09:20 PM)Johnh Wrote:  I'll be working on some LRC circuits, for which the impedance of my 220uF capacitors at 110hZ is -6.6i.

I don't know a lot of things. Impedance is one of those things. And imaginary numbers I guess Smile Maybe negative numbers...
Find all posts by this user
Quote this message in a reply
06-05-2024, 02:25 PM (This post was last modified: 06-05-2024 02:27 PM by toml_12953.)
Post: #45
RE: Unary minus precedence preference
(06-04-2024 09:20 PM)Johnh Wrote:  It's getting cold down here in Australia, the temperature outside is about -2 degrees C this morning. And our dollar is down too, about -1% against the USD. But I'll be working today, my leave balance at work is -6 days, since I took a vacation a couple of months ago. I'll be working on some LRC circuits, for which the impedance of my 220uF capacitors at 110hZ is -6.6i.

So there's lots of unary negatives in my real world today. Except for the capacitive reactance, which is an imaginary number.

Last Winter (Northern Hemisphere) there were days when we had no temperature at all! Yes, it was actually 0°. Canadians froze first seeing how it was still 32° here when it was 0° there. Eventually, however, all molecular motion stopped in both countries, and we all froze solid. Fortunately, the temperature went back up so we could resume our lives.
It was quite refreshing.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-05-2024, 06:12 PM
Post: #46
RE: Unary minus precedence preference
(06-05-2024 02:25 PM)toml_12953 Wrote:  It was quite refreshing.

Sadly every time I hit my 'pause the world now' button, it always seems to go by so quickly and I get very little resulting relaxation, what am I doing wrong?
Find all posts by this user
Quote this message in a reply
Post Reply 




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