Finding something worth knowing…

Science

Parentheses can vanish—until floating-point math arrives

If a binary operation is associative, regrouping never changes the answer, so long as the operands stay in order. Real addition and multiplication obey that rule. Computer floating-point addition usually does not, and the grouping you choose can change rounding error.

Associativity says that in a chain of the same operator, how you place parentheses does not matter if the sequence of operands is fixed. Addition and multiplication of real numbers are associative; so are many less familiar operations. Commutativity is different: it asks whether swapping two operands changes the result. Function composition and matrix multiplication are typically associative yet not commutative. Algebraic structures such as semigroups and categories bake associativity into their definitions.

The generalized associative law says every legal parenthesization of a long product yields the same value, so parentheses become optional. That fails for some symbols even when the operation is associative: the logical biconditional ↔ is associative, yet writing A ↔ B ↔ C is often read as both adjacent pairs being equivalent, which is not the same as associating a single ternary chain. In propositional logic, associativity also appears as a replacement rule that lets you move parentheses in proofs. Conjunction and disjunction are associative connectives; joint denial is an example that is not.

Plenty of important operations refuse the law: subtraction, exponentiation, and the vector cross product. For cross products of the standard basis vectors, i × (i × j) and (i × i) × j give different answers. Infinite series can break associativity even when finite sums behave; regrouping can change a sum's value. Non-associative algebras such as the octonions and Lie algebras replace the associative law with other identities—the Jacobi identity for Lie algebras. In numerical computing, floating-point addition and multiplication are not associative because different evaluation orders introduce different rounding, so algorithm design must track association carefully.

Source: Associative property

Related

More in Science · All topics