Commutativity is an easy property to render into English: it means order doesn’t matter.
For example “three groups of five rocks” totals the same as “five groups of three rocks”. In fact a general proposition is true: “L groups of R rocks” totals the same as “R groups of L rocks” for any L,R. Which is surprising if you think about arraying the stones in piles or spirals or circles
but less so if you think about arraying them in grids
But what about associativity? It’s a basic assumption of category theory and every monoid or semigroup is associative. Since functional programming (
Haskell, etc) is based in these composition-friendly mathematics of braids, string diagrams, monads, and monoids, the associative assumption will come up in functional programming as well.
If the property holds then we can do things like this:
but what does it mean for associativity to hold? Just like I didn’t understand why the classical poetry I read in school was considered good until I read some truly bad poetry, I need some examples of non-associative things before I can understand what it means to assume some process is associative.
The sedenions aren’t associative
and neither are the octonions.
But these two algebras are unusual so in order to explain why they don’t translate evaluation parentheses, you have to first figure out how they work. Same with Okubo algebras, Jordan algebras, Poisson algebras, and vector cross-products. How about a more commonly understood subject matter?
Here is one: arithmetic of exponents.
The Berkeley calculator evaluates 2^2^2^2^2 right-to-left.
To access the Berkeley Calculator: Type
bc -l at the terminal in Linux or Mac. In Windows get PuTTY and
If the evaluation order doesn’t matter (associativity), then the square root of 2^2^2^2^2 should be the same as the base-two log of 2^2^2^2^2, since one cancels “from the bottom” and one of them cancels “from the top”.
But guess what?
square root of 65536 is 256, but the
log_2 of 65536 is ≈16. Since they’re not the same, exponentiation is non-associative.
Playing around with exponents of a few two’s and different evaluation orders can be done either in
bc -l or on paper.
4^4^2 (2^2)^(2^2)^(2) (2^2^2^2)^2 (2^2^2^2)*(2^2^2^2) 65536^2 = 4294967296 2^65536 = ridiculous (2^3)^2 = 8^2 = 64 2^(3^2) = 2^9 = 512
And now that I’ve played around I have a plain-English description of what associativity means: "Order of evaluation doesn’t matter"