| ▲ | vlovich123 10 hours ago | ||||||||||||||||||||||||||||||||||||||||||||||
Unless I’m having a brain fart it’s not commutative or you mean something by “relevant and appropriate” that I’m not understanding. a+b+c != c+b+a That’s why you need techniques like Kahan summation. | |||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | amluto 7 hours ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||
I think the other replies are overcomplicating this. + is a binary operation, and a+b+c can’t be interpreted without knowing whether one treats + as left-associative or right-associative. Let’s assume the former: a+b+c really means (a+b)+c. If + is commutative, you can turn (a+b)+c into (b+a)+c or c+(a+b) or (commuting twice) c+(b+a). But that last expression is not the same thing as (c+b)+a. Getting there requires associativity, and floating point addition is not associative. | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | wtallis 10 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||
"a+b+c" doesn't describe a unique evaluation order. You need some parentheses to disambiguate which changes are due to associativity vs commutativity. a+(b+c)=(c+b)+a should be true of floating point numbers, due to commutativity. a+(b+c)=(a+b)+c may fail due to the lack of associativity. | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | dataangel 6 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||
For those to be equal you need both associativity and commutativity. Commutativity says that a*b = b*a, but that's not enough to allow arbitrary reordering. When you write a*b*c depending on whether * is left or right associative that either means a*(b*c) or (a*b)*c. If those are equal we say the operation is associative. You need both to allow arbitrary reordering. If an operation is only commutative you can turn a*(b*c) into a*(c*b) or (b*c)*a but there is no way to put a in the middle. | |||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | wfleming 9 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||
We’re in very nitpicky terminology weeds here (and I’m not the person you’re replying to), but my understanding is “commutative” is specifically about reordering operands of one binary op (4+3 == 3+4), while “associative” is about reordering a longer chain of the same operation (1+2+3 == 1+3+2). Edit: Wikipedia actually says associativity is definitionally about changing parens[0]. Mostly amounts to the same thing for standard arithmetic operators, but it’s an interesting distinction. | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | nyrikki 10 hours ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||||||||
IEEE 754 floating-point addition and multiplication are commutative in practice, even if there are exceptions with NaNs etc.. But remember that commutative is on the operations (+,x) which are binary operations, a+b=b+a and ab=ba, you can get accumulated rounding errors on iterated forms of those binary operations. | |||||||||||||||||||||||||||||||||||||||||||||||