Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tekchips.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tektronix!tekcrl!tekchips!stevev From: stevev@tekchips.UUCP (Steve Vegdahl) Newsgroups: net.puzzle Subject: Re: x to the x to the x ... (ANSWER/SPOILER) Message-ID: <504@tekchips.UUCP> Date: Sun, 12-May-85 17:10:20 EDT Article-I.D.: tekchips.504 Posted: Sun May 12 17:10:20 1985 Date-Received: Tue, 14-May-85 23:43:34 EDT References: <7219@watdaisy.UUCP> <3681@alice.UUCP> <481@tekchips.UUCP> <379@gitpyr.UUCP> Organization: Tektronix, Beaverton OR Lines: 47 > > While it may be true that > > most programming languages that use '^' for exponentiation define it to be > > right-associative, I do not find either interpretation to be unreasonable. > > The reason that right associativity is preferred is that: > > (x ^ y) ^ z is equivalent to x ^ (y * z) > > and the multiplication is certainly more efficient. Therefore the only > sensible way to associate exponentiation is to the right. If a language > does it the other way, then it's less than useless. There is a great deal to be said for minimizing the number of exceptions in a language. If all operators except '^' are left-associative, many would consider it say good language design to make '^' left-associative as well. I wonder how many people have used the left- or right-associativity of an exponention operator in a program (i.e., written something of the form x^y^z). Is it worth making an exception to the language for a construct that occurs so rarely? Maybe, maybe not. Which strikes you as cleaner language design? "All operators in language X are left-associative" or "All operators in language X are left-associative, except '^'" or "All operators in language X are left-associative, unless the amount on line 12b of Schedule A is less than 10% of adjusted gross income" :-) ALGOL-60 and some of its descendants (e.g., SAIL), use '^' as a left-associative exponentiation operator. I stand by my earlier statement that either interpretation is reasonable. Remember that precedence and left-(right-)associativity are properties of the OPERATOR, not of the FUNCTION. It is possible to define a language with two exponentiation operators (of different precedence), one of which is associates left the and other right. I find the efficiency argument give above to be irrelavent. If (x ^ y) ^ z is equivalent to x ^ (y * z), then an optimizing compiler can transform the former to the latter. I'm not even sure that they are equivalent, when round-off error is considered. Floating-point addition is NOT associative, for example. Steve Vegdahl Computer Research Lab. Tektronix, Inc. Beaverton, Oregon