Real mathematicians don’t play games like this. They don’t write out a string of numbers equally spaced with no rhyme or reason to the operators. They tend to group statements in logical groups, using parenthesis when necessary. Multiplication is rarely indicated with a cross, preferring a dot that leaves little room between numbers, or else simply being implied. Division is indicated with a horizontal line, so it is very clear which statements are the divisor and which the dividend. Exponentiation is indicated with a superscript, and parenthesis indicate what is being exponentiated.
No mathematical journal would publish the given statement, because it is unclear and non-intuitive. We should not accept it either.
True, except to bring this back around to more purely mathematical pursuits, side-effect-free functions can’t possibly change what value they return due to differences in sequence points unless you’re doing things like foo(i++ + ++i) or similarly nasty tricks with mutable state, which is horrible for reasons which have noting to do with associativity or precedence.
I don’t know if you know this, but there’s a programming language called APL with precisely this evaluation rule: 3 * 2 + 3 equals 15 in APL (if you translate the ASCII notation I used into the non-ASCII notation APL uses) because 2 + 3 is 5 and 3 * 5 is 15. You can parenthesize to get a different result, but the point is APL’s convention is just as consistent as anyone else’s. Probably more consistent, because it has to be implemented by a piece of software.
And God, I know, I’m one :D:
Even if you know every rule in the precedence and associativity table for the language, it’s still antisocial to write your expressions such that you’re relying on the reader to know those rules. Even if you’re the only one who reads that code, what you know six months from now won’t necessarily be the same as what you know now; human minds aren’t hard drives, they’re cache, and caches get flushed and refilled.
ISTM the kind of amgibuity we are seeing here only happens when you use an implicit (unwritten) multiplication operator, combined with an explicit division operator. The problem never really arises when you use an explicit multiplication operator, as one would do in most programming languages. So, the mathematical language of mathematicians is not exactly identical to the mathematical language of computer programmers.
Somebody just started Yet Another thread about this, here.
See Post #8 there, where I believe I might have written the last word that needs to be written about this. (I would simply cross-post the same thing here instead of a link, but I see that the mods are getting snitty about cross-posting lately.)
Right. I haven’t used Go much, but I know about gofmt. I didn’t realize it was that opinionated, however.
Well, technically, it won’t assume the precise version of PEMDAS people are taught in grade school. It will assume a much longer, much stricter, and therefore entirely comprehensive series of rules built into whatever grammar it is applying to the stream of lexical tokens fed into its parser. This rule set is by definition correct for Go (AFAIK there’s no formal standard but instead one ‘blessed’ implementation which is correct by fiat in these matters) but is wrong or irrelevant in other languages.
So we come back to context, as we’ve been saying all along, and the fact that the context of this little expression is “be ambiguous enough that you can play ‘gotcha’ and bemoan the declining standards of mathematical education from The Good Old Days”. At that it succeeds until it finds someone who actually knows what they’re talking about and who can therefore feel confident enough to roll their eyes at the whole mess, instead of being insecure enough in their mathematical skills to need to get the “right” answer.
It’s a trap laid for the strivers, much like an endless number of pseudo-grammatical shibboleths used to distinguish “correct” (imagined upper-class) speech from “incorrect” (lower-class) speech, and the result is exactly the same: Among the people who actually know enough to learn from, clarity is the only unbreakable rule.
Actually, I just checked, gofmt doesn’t remove parens. I swore it did, maybe you need to use the -s flag (simplify expressions as much as possible) for that.