And and or priority

David Vallner wrote:

M. Edward (Ed) Borasky wrote:

Matthew Smillie wrote:

Is that actually a mathematical rule, though? I don't remember as such
from any math or logic that I know, and poking around through my old
textbooks made no mention of binding or precedence of logical
operations; the closest thing being a statement that parentheses are
required to avoid ambiguity when mixing and and or in one statement, at
least slightly implying that there is no 'order of operations'.

If anyone has a reference either way on this, I'd be curious to see it.

matthew smillie.

My rather dim recollection is that computer jocks forced "and" to bind
tighter than "or" and "not" to bind tighter than "and" just so it *was*
defined. Only in programming (and logic design) do you usually find
Boolean expressions complicated enough for operator precedence to matter. :slight_smile:

Hmm. If I recall my freshman discrete maths, logical conjunction (and) was the multiplicative operation in boolean algebra, logical disjunction (or) was the additive operation. Or at least were denoted by the same symbols and the analogy made it easier to remember the meaning of those symbols than ∧ and ∨. And in arithmetical maths expressions, multiplication binds before addition. So I might have jumped to the conclusion that in boolean expressions, and would bind before or. (Or made a really lucky guess as to the correct convention.)

Your memory is correct; Boolean + is OR, and Boolean * is AND. (You can remember by observing that this makes the tables the same as arithmetic in seven of the eight possible cases.) This is the reason that AND binds more tightly than OR in nearly all languages.

(The designers of Ada, however, decided that not enough programmers are familiar with Boolean Algebra, and defined the syntax in such a way that AND and OR cannot be mixed in a single expression without explicit parentheses.)

···

--
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
   -- Charles Williams. "Taliessin through Logres: Prelude"