From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9cccf6ef6149fdaa X-Google-Attributes: gid103376,public From: "Howard W. LUDWIG" Subject: Operator precedence--was Re: Operators -> unit analysis Date: 2000/01/10 Message-ID: <387A0865.A50A980F@lmco.com>#1/1 X-Deja-AN: 572337350 Content-Transfer-Encoding: 7bit References: <38620350.48F8FC08@gecm.com> <83u8l0$5i5$1@nnrp1.deja.com> <84rd2f$snm$1@nntp3.atl.mindspring.net> <84thof$9r3$1@nntp4.atl.mindspring.net> <387383D0.4EA02E95@earthlink.net> <850jiq$mad$1@nnrp1.deja.com> <3874D0BE.82F04763@Raytheon.com> <853lkg$tgj$1@nnrp1.deja.com> <38764aac_2@news1.prserv.net> X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii Organization: LMC Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-01-10T00:00:00+00:00 List-Id: Matthew Heaney wrote: > > In article , Robert A Duff > wrote: > > > I would say: If it's not a precedence rule I learned in grade school, > > then it shouldn't be in a programming language (whether it was put there > > by the language designer or by some "clever" programmer). > > Oh dear, I'll probably get horribly flamed for saying so, but I disagree > with the Ada(83) decision to require that "and" and "or" operators > appearing within the same statement also require parenthesis. This statement shows a fundamental, yet very common, misunderstanding of Boolean algebra, exemplifying the value of Robert Duff's idea. If one uses 0 for false and 1 for true, the operation table for "and" and "or" matches that of "*" and "+" in 7 out of 8 slots, which digital engineers seem to regard as a passing grade so they can feel justified with treating "and" just like "*" and "or" just like "+", including implied operations and operator precedence without parentheses. However, that one mismatch has profound impact, causing Boolean algebras to have some very different properties (along with some similar ones) than fields. With any of the fields of rational, real, or complex numbers using standard addition and multiplication, one of the operations (multiplication) is distributive across the other (addition), but not vice versa--this is the basis for the justification of assigning precedence to multiplication over addition. In Boolean algebras, on the other hand, each binary operation is distributive across the other; this, combined with other defining properties, leads to the vital concept of duality, which says that swapping "and"s and "or"s and swapping 1s and 0s has no impact on the truth (or lack thereof) of a statement. Some interesting consequences result: (1) if the statement "AND has precedence over OR" has any validity, then so does its dual "OR has precedence over AND."--a contradiction. (2) The association of "and" with "*", "or" with "+", "1" with TRUE, and "0" with FALSE is a _totally arbitrary_ convention; duality indicates that everything would work just fine if the opposite would be chosen as convention. I have yet to see a logician write an expression with both "and" and "or" using infix notation without writing parentheses to indicate explicitly which is to be done first. (And "and" and "or" are defined as logical operators in Ada, not as digital electronics operators, so I would expect logicians to have some say about precedence, especially since they are very careful to be rigorous and consistent, unlike many digital folks I know who would rather slop something together conveniently and quickly without worrying about rigor and consistency--reminds me of the hacking mentality we commonly associate with the C world, especially the idea of striving to save two characters of typing.) Also, I have yet to see a set theorist write an expression with both intersection and union operations without using parentheses to indicate explicitly which is to be done first. > I think that, as in C, "and" should be given a higher precedence than > "or", analogous to how "*" is given a higher precedence than "+". I repeat my comment about C hackers saving typing two characters regardless of impact on readability and maintenance. I would think very carefully before using C as a example for how Ada should be (although the newly released ISO standard has some major improvements over the 1990 version). > -- > Evolution is as well documented as any phenomenon in science, as > strongly as the earth's revolution around the sun rather than vice > versa. > > Stephen Jay Gould, Time, 23 Aug 1999 Another thing about which to dream on. Howard W. LUDWIG