this post was submitted on 31 May 2025
215 points (90.3% liked)

Technology

71953 readers
4189 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] HereIAm@lemmy.world 1 points 3 weeks ago* (last edited 3 weeks ago) (2 children)

Except it does matter. I left some examples for another post with multiplication and division, I'll give you some addition and subtraction to see order matter with those operations as well.

Let's take:
1 + 2 - 3 + 4

Addition first:
(1 + 2) - (3 + 4)
3 - 7 = -4

Subtraction first:
1 + (2 - 3) + 4
1 + (-1) + 4 = 4

Right to left:
1 + (2 - (3 + 4))
1 + (2 - 7)
1 + (-5) = -4

Left to right:
((1 + 2) - 3) + 4
(3 - 3) + 4 = 4

Edit: You can argue that, for example, the addition first could be (1 + 2) + (-3 + 4) in which case it does end up as 4, but in my opinion that's another ambiguous case.

[–] SmartmanApps@programming.dev 0 points 1 day ago

Except it does matter

No it doesn't. You disobeying the rules and getting lots of wrong answers in your examples doesn't change that.

I left some examples for another post with multiplication and division

Which you did wrong.

I’ll give you some addition and subtraction to see order matter with those operations as well

And I'll show you it doesn't matter when you do it correctly

Subtraction first: 1 + (2 - 3) + 4 1 + (-1) + 4 = 4

Nope. Right answer for wrong reason - you only co-incidentally got the answer right. -3+1+2+4=-3+7=4

Right to left: 1 + (2 - (3 + 4)) 1 + (2 - 7) 1 + (-5) = -4

Nope. 4-3+2+1=1+2+1=3+1=4

Edit: You can argue that, for example, the addition first could be (1 + 2) + (-3 + 4)

Or you could just do it correctly in the first place, always obeying Left Associativity and never adding Brackets

in my opinion that’s another ambiguous case

There aren't ANY ambiguous cases. In every case it's equal to 4. If you didn't get 4, then you made a mistake and got a wrong answer.

[–] troistigrestristes 2 points 3 weeks ago (1 children)

Oh, but of course the statement changes if you add parentheses. Basically, you’re changing the effective numbers that are being used, because the parentheses act as containers with a given value (you even showed the effective numbers in your examples).

Get this : + 1 - 1 + 1 - 1 + 1 - 1 + 1

You can change the result several times by choosing where you want to put the parentheses. However, the order of operations of same priority inside a container (parentheses) does not change the resulting value of the container.

In the example, there were no parentheses, so no ambiguity (there wouldn’t be any ambiguity with parentheses either, the correct way of calculating would just change), and I don’t think you can add “ambiguity” by adding parentheses — you’re just changing the effective expression to be evaluated.

By the way, this is the reason why I absolutely overuse parentheses in my engineering code. It can be redundant, but at least I am SURE that it is going to follow the order that I wanted.

[–] SmartmanApps@programming.dev 0 points 1 day ago

Oh, but of course the statement changes if you add parentheses

It sure does, but they don't seem to understand that.