2023-08-28 06:26 UTC
3/6
The problem in question included the expression +5-4+1. Left associativity means a term is associated with the sign to the left. i.e. 4 is associated with a minus, the other 2 terms with a plus. We have discussed previously that we can do addition and subtraction in any order, and this is true... provided you preserve left associativity! And one way to do that is always work left-to-right. But imagine we wanted to go right to left, and read it right to left! Then we would read it as...
Replies (1)
-
@SmartmanApps@dotnet.social 2023-08-28 06:27
4/6 1+4-5, which is clearly wrong, because we didn't preserve left associativity. To work right-to-left preserving left associativity, we would do +1-4+5, and we get the correct answer, because we correctly kept the minus sign with the 4 A mistake I have seen people make with 5-4+1 is to first calculate 4+1, then subtract that from 5! That's the same as doing 5-(4+1), which is NOT the same as 5-4+1 - you changed a sign and changed the answer! Hmmm, adding brackets and changing the answer ๐ ๐