And then read https://xkcd.com/169/
Anyway, I'm sure there'll be a YouTube video about this with an AI voiceover soon.
And then read https://xkcd.com/169/
Anyway, I'm sure there'll be a YouTube video about this with an AI voiceover soon.
6÷2(1+2) is written in a deliberately confusing fashion. This is a simple math olympiad-style question. All universal quantifications on the empty set are true, for the same reason that the implication A -> B is true when A is false regardless of B. It cannot be any other way. Precedence of infix operators on the other hand is completely arbitrary, we settled on multiplication before addition because otherwise it would be a pain to write polynomials.
It might be a math Olympiad question, but a math Olympiad participant is supposed to know how, say, a vacuous truth works, and, moreover the mapping of formal English to logical operators (see also: the inclusive or) and that is not how everyone in the world will parse the statement of the problem.
Is the point here to educate people on a quirk of formal logic, or is a smugbait to promote a book? Oh look, there's a book. Quelle surprise.
And, as usual, the xkcd is fantastic.
If there's a case where one computation needs to occur before others, then that's where I always use parens.
I'm also never doing a^b^c, either as a^(b^c) or (a^b)^c, but if I did, there would be parens.
Readibility in one's code is necessary for those of us who must re-read our code when we need to refamiliarize ourselves with it before making changes. It is said that programmers spend far more time reading code than writing it, and I have found that to be true. As someone who has developed large pieces of software, my strategies include clarity for the reader, who is, first of all, myself.
As to what it's called, yeah, 'associativity' is the math term, but if you think I don't understand the concept, then you don't understand the depth that precedence goes to the heart of parsing source code to produce executable code. And I do understand that, friend, for four decades now.