3 ms·
That is due to associativity. You're implicitly relying on a consistent left-to-right evaluation order, but the fundamental problem can be phrased as (using s f
by dbaupp 8y ago
That is due to associativity. You're implicitly relying on a consistent left-to-right evaluation order, but the fundamental problem can be phrased as (using s for small and b for big):
(((b + s) + s) + s) + s
Can be different to
b + (s + (s + (s + s)))
This re-parenthesising is related to associativity, not commutivity.
- jonsen 8y agoRearranging operands with their operations is commuting. Rearranging parentheses is associating. Yes, floating point operations are also not in general associative.
- jonsen 8y agoYou're implicitly relying on a consistent left-to-right evaluation order, That’s standard, I think.
- dbaupp 8y agoIndeed, it is standard, but eliding the parentheses doesn't mean they aren't implicitly there, and doesn't turn non-associativity into non-commutativity. Commutivity means that these are equal: (((b + s) + s) + s) + s == s + (s + (s + (s + b)))