418
submitted 11 months ago by Toes@ani.social to c/196@lemmy.blahaj.zone
you are viewing a single comment's thread
view the rest of the comments
[-] ReveredOxygen@sh.itjust.works 1 points 11 months ago

But subtraction and division are not associative. Any time you work on paper, 2 - 2 - 2 would equal -2. That is, (2-2)-2=0-2=-2. If you evaluate right to left, you get 2-2-2=2-(2-2)=2-0=2

[-] nutcase2690@lemmy.dbzer0.com 3 points 11 months ago

Correct, subtraction and division are not associative. However, what is subtraction if not adding the opposite of a number? Or division if not multiplying the inverse? And addition and multiplication are associative.

2-2-2 can be written as 2 + (-2) + (-2) which would equal -2 no matter if you solve left to right, or right to left.

In your example with the formula from right to left, distributing the negative sign reveals that the base equation was changed, so it makes sense that you saw a different answer.

2 - (2 - 2) = 2 + ((-2) + 2) = 2

[-] SmartmanApps@programming.dev 2 points 7 months ago

2-(2-2)

But you broke the rule of left-associativity there. You can go right to left provided you keep each number with the sign to it's left (and you didn't do that when you separated the first 2 in brackets from it's minus sign).

this post was submitted on 03 Dec 2023
418 points (100.0% liked)

196

16436 readers
2118 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS