When mentioning operator precedence for AND / OR, I explained it wrongly. I re-explained it properly using the idea of binding: the operator "binds tightly" to the two expressions immediately on either side.
My incorrect explanation was based on me thinking of a complex expression as a tree, with AND as the root. For example, this fake expression:
expr1 OR expr2 AND expr3
behaves as if there are parentheses around
expr2 AND expr3, but the "tree view of precedence" with AND being "more" would put the parentheses around the OR expression. I didn't explain my wrong idea to the students, but it is an error that I sometimes make in my thinking - it makes sense to me!
Is there a better way of explaining precedence to avoid this ambiguity than to say "it binds tightly"?
I encountered this when teaching SQL, but the question is not really about Boolean operators or Math, it is about Precedence in general as implemented in many languages. (If I had been showing a math example I would have unconsciously followed the rules of Algebra, but Booleans are not as common in my life.) A common synonym for Precedence is "Order Of Operations", but in SQL there is not supposed to be an 'order'. This is especially so with Booleans, because they just yield T/F and so there is no sense of left-to-right or anything.
a + b * cwe first calculate
b * cand only then
a + …— the same with
a OR b AND cwe first calculate
b AND cand only then
a OR …. $\endgroup$