4 ms·
All of the "4096" results have exponentiation as left-associative, despite the common conventions that exponentiation is right associative. Seeing the example
by geoffhill 15y ago
All of the "4096" results have exponentiation as left-associative, despite the common conventions that exponentiation is right associative.
Seeing the example really makes me wonder why that convention exists, and also makes me ponder whether having variate associativity is actually a good idea after all. Especially in languages like Scala, where you can change the associativity of your binary functions through function naming.
Though I can see why things like the cons operator "::" make a lot of sense.
- vrotaru 15y agoWhy is exponentiation associative? This: 4 3 2 You should also try to visualize the 4 smaller and 3, and 3 smaller than 2. Because this is the way it was written for a long time.
- v-yadli 15y agoAt the first glance I thought 3 is smaller than 2, 4 is smaller than 3. But after reading your note, I realize they're of the same size. That's what "conventional" means for me. :-p
- baddox 15y agoIt's interesting to think that the whole notion of associativity and order of operations only exists because for some reason humans seem to find infix notation more "natural" for binary (or fixed arity) operators than more easily parseable and less ambiguous alternatives like prefix.
- sesqu 15y ago^ ^ 2 3 4 Prefix notation doesn't automatically solve the problem, you need to assume an evaluation order. More specifically, you need to not assume associativity.
- baddox 15y agoIsn't the lack of associativity explicit in prefix notation? Prefix notation doesn't even contain the notion of order of operations. You would convert the infix "2^3^4" to prefix in different ways depending on the associativity of exponentiation: For left associativity (uncommon): ^ ^ 2 3 4 For right associativity (common): ^ 2 ^ 3 4 Of course, all this is assuming all operators are fixed arity, otherwise you need parentheses no matter what.
- Someone 15y agoExponentiation is right associative because (a^b)^c = a^(b.c) (using dot for multiplication because I fear that HN will mess up an asterisk) So, a right associative exponentiation makes your expression language more powerful.