2026-08-02 14:26 UTC
@bemmesr@mathstodon.xyz oh, I forgot one thing. When he talks about "left associativity" he means something a bit more than what most people mean by it. To remind you, in mathematics a binary operator O is associative if (a O b) O c = a O (b O c). Left-associativity is a *notational convention* for a non-associative binary operator in which we agree that when we write a O b O c we mean (a O b) O c. So division is conventionally left-associative, while exponentiation written with "^" is conventionally right-associative.
What he means by left-associativity is that you can rearrange bits of an expression, and hence do them in a different order, as long as you keep them with their *associated* operation, that is the one to their left. If you do the operations in 2÷2×2 from right-to-left, you'd do 2÷(2×2), which is different to the usual result of (2÷2)×2. What he calls "right-to-left" though can be thought of as the following:
Start with an "accumulator" value of 1. Then, find the rightmost number in the expression, and the symbol to its left. Perform that operation with the accumulator and the number. Proceed to the next number to the left, and so on.
You can convince yourself pretty easily that this procedure does indeed allow you to perform the multiplications *and* divisions in an expression in any order, and this is taught in schools because if you go strictly left to right you might start out by creating some horrible fraction, when a different order would instead allow you to work purely in integers - or whatever.
But the critical thing missing from this is that this is not related to what is meant by "order of operations"! If you have a second unknown binary operator P, and the expression a O b P c, you know this expression must mean either to first do a O b or b P c, but without more information it is not clear which. Left-to-right OoO clarifies that a O b is intended, whereas right-to-left would clarify that b P c is intended. If the OoO rules in fact were written to say that multiplication and division were evaluated right-to-left, you wouldn't get the property of left-associativity.
Replies (0)
No replies.