comp.lang.ada
 help / color / mirror / Atom feed
From: "Howard W. LUDWIG" <howard.w.ludwig@lmco.com>
Subject: Operator precedence--was Re: Operators -> unit analysis
Date: 2000/01/10
Date: 2000-01-10T00:00:00+00:00	[thread overview]
Message-ID: <387A0865.A50A980F@lmco.com> (raw)
In-Reply-To: 38764aac_2@news1.prserv.net

Matthew Heaney wrote:
> 
> In article <wccln626ily.fsf@world.std.com> , Robert A Duff
> <bobduff@world.std.com>  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




  parent reply	other threads:[~2000-01-10  0:00 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-23  0:00 Ada Brijesh
1999-12-23  0:00 ` Ada reason67
1999-12-23  0:00   ` Ada Robert Dewar
2000-01-03  0:00     ` Ada Terry Sikes
2000-01-03  0:00       ` Ada Hyman Rosen
2000-01-04  0:00         ` Ada Richard D Riehle
2000-01-04  0:00           ` Ada Hyman Rosen
2000-01-04  0:00             ` Ada Richard D Riehle
2000-01-04  0:00             ` Ada Robert A Duff
2000-01-04  0:00         ` Ada Terry Sikes
2000-01-05  0:00           ` Operators -> unit analysis Charles Hixson
2000-01-05  0:00             ` Hyman Rosen
2000-01-05  0:00               ` Matthew Heaney
2000-01-05  0:00             ` Matthew Heaney
2000-01-05  0:00               ` Charles Hixson
2000-01-05  0:00             ` Ted Dennison
2000-01-06  0:00               ` Samuel T. Harris
2000-01-07  0:00                 ` Robert Dewar
2000-01-07  0:00                   ` Ted Dennison
2000-01-07  0:00                     ` Brian Rogoff
2000-01-07  0:00                   ` Robert A Duff
2000-01-07  0:00                     ` Matthew Heaney
2000-01-08  0:00                       ` Robert Dewar
2000-01-08  0:00                         ` Robert A Duff
2000-01-10  0:00                       ` Howard W. LUDWIG [this message]
2000-01-14  0:00                         ` Operator precedence--was " Mark A Biggar
2000-01-06  0:00               ` Charles Hixson
2000-01-05  0:00             ` Pat Rogers
2000-01-05  0:00               ` Charles Hixson
2000-01-06  0:00             ` Robert Dewar
2000-01-06  0:00               ` Terry Sikes
2000-01-06  0:00                 ` Robert A Duff
2000-01-07  0:00                   ` Terry Sikes
2000-01-07  0:00                     ` Brian Rogoff
2000-01-07  0:00                 ` Ted Dennison
2000-01-07  0:00                   ` Tucker Taft
2000-01-08  0:00                     ` Robert Dewar
2000-01-10  0:00                       ` Tucker Taft
2000-01-10  0:00                         ` Florian Weimer
2000-01-04  0:00         ` Ada Robert Dewar
2000-01-04  0:00           ` Ada Hyman Rosen
2000-01-04  0:00           ` Ada Robert A Duff
2000-01-04  0:00             ` Ada Hyman Rosen
2000-01-04  0:00         ` Ada Florian Weimer
2000-01-04  0:00           ` Ada Brian Rogoff
2000-01-04  0:00           ` Ada Hyman Rosen
2000-01-04  0:00       ` Ada Robert Dewar
2000-01-04  0:00         ` Ada Terry Sikes
2000-01-05  0:00           ` Ada Robert Dewar
2000-01-05  0:00             ` Ada Terry Sikes
2000-01-06  0:00           ` Ada Al Christians
2000-01-06  0:00             ` Ada Terry Sikes
2000-01-07  0:00             ` Ada Robert Dewar
1999-12-23  0:00 ` Ada Jon Jensen
1999-12-23  0:00 ` Ada Roger Racine
1999-12-28  0:00   ` Ada Marin D. Condic
1999-12-31  0:00     ` Ada Richard D Riehle
2000-01-02  0:00       ` Ada Marin D. Condic
2000-01-02  0:00         ` Ada Robert Dewar
2000-01-02  0:00           ` Ada Marin D. Condic
2000-01-03  0:00             ` Ada Ted Dennison
2000-01-03  0:00             ` Ada Robert Dewar
2000-01-03  0:00               ` Ada Marin D. Condic
2000-01-03  0:00                 ` Ada Larry Kilgallen
2000-01-04  0:00                   ` Ada Charles Hixson
2000-01-03  0:00                 ` Ada Roger Racine
2000-01-13  0:00     ` Ada Magnus Alexandersson
2000-01-14  0:00       ` Ada Tarjei T. Jensen
2000-01-14  0:00         ` Ada Larry Kilgallen
2000-01-14  0:00           ` Ada Marin D. Condic
2000-01-14  0:00             ` Ada Magnus Alexandersson
2000-01-14  0:00               ` Ada Marin D. Condic
2000-01-13  0:00     ` Ada Magnus Alexandersson
1999-12-23  0:00 ` Ada Robert Dewar
1999-12-23  0:00   ` Ada tmoran
1999-12-23  0:00 ` Ada Greg Martin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox