News for hackers. Stuff that matters.
Re:2^3^4 - a comparison of math packages by geoffhill on Monday February 06, 2012 @03:13AM (#3556649)
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.

Re:2^3^4 - a comparison of math packages by Someone on Monday February 06, 2012 @05:28AM (#3556927)
Exponentiation 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.

Re:2^3^4 - a comparison of math packages by baddox on Monday February 06, 2012 @03:41AM (#3556692)
It'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.
Re:2^3^4 - a comparison of math packages by sesqu on Monday February 06, 2012 @06:50AM (#3557091)
^ ^ 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.

Re:2^3^4 - a comparison of math packages by baddox on Monday February 06, 2012 @01:27PM (#3558540)
Isn'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.
Re:2^3^4 - a comparison of math packages by vrotaru on Monday February 06, 2012 @03:29AM (#3556676)
Why 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.
Re:2^3^4 - a comparison of math packages by v-yadli on Monday February 06, 2012 @03:44AM (#3556696)
At 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