3 ms·
There is value in notational simplicity. For the same reason that math has defined precedence (and even omits multiplication signs entirely in many places), pr
by sokoloff 3y ago
There is value in notational simplicity.
For the same reason that math has defined precedence (and even omits multiplication signs entirely in many places), programming languages in some domains will choose to do the same.
It’s not a problem if you want to create a language that does not do this, but I think it is a problem if you want to ban others from doing it.
- tsimionescu 3y agoAlgebra only really has defined precedence between multiplication and addition/subtraction. In all other cases, even division, there is either a non-linear textual representation, or parantheses are required. You have fractions, exponents, radical signs, various signs which appear only at the beginning of an expression (sigma, integral, lim) etc. Even multiplication is often distinguished more by the shape of the text than by actual precedence rules, once you leave basic arithmetic - expressions like "1 - 3xy + 2y²" make the order of operations obvious from text layout, which is why they are preferred over "1 - 3 × x × y + 2 × y ^ 2", which no mathematician ever writes.
- sokoloff 3y agoExponentiation also has defined precedence, does it not? (Everyone who has passed algebra agrees that y is squared before being multiplied by 2 in your example.)
- tsimionescu 3y agoYou can view that as precedence, but I think it's more correct to say that exponentiation binds to the single symbol it is attached to. When you write x² + 2, I don't think it's operator precedence that makes it clear this is not equal to x ^ 4. Similarly, in the following expression: x _ + 2 2 I don't think it's precedence that makes it clear you first divide by 2 and then add 2 to the result.
- sokoloff 3y agoAlternatively, perhaps what you're observing is simply the graphical representation of the underlying mathematical precedence rules. (Obviously, over hundreds of years of symbolic math, the notation and precedence has co-evolved, with precedence probably generally, well, preceding notation.) y = x / 3 + 2 y = 2 + x / 3 y = x/3 + 2 We all agree those are the same, despite a lack of an any cues in the first two. That suggests to me that there is a defined precedence for division vs addition in math. (So much so that it doesn't even seem like a controversial statement to make.)
- tsimionescu 3y agoPrecedence rules always apply to a specific textual notation. There is no precedence between division and addition, there is a precedence between the / and the + operators. People are generally bad at remembering arbitrary operator precedence rules. That is why most math notation doesn't rely on precedence rules to be unambiguous, it uses other kinds of textual clues. For example, the / operator is virtually never used in algebra. Instead, division is indicated by fractions, which explicitly group their operands and separate them from other adjacent operations. Exponentiation relies on super scripts to separate its arguments, making it extremely unambiguous at least which operations are part of the exponent and which the total. Roots use the radical symbol which extends over the entire expression you're taking the root of, and again rely on a kind of superscript for indicating which root you are taking. Limits and sums use subscripts to separate the iteration direction from the expression. Integrals use both sub and superscripts.
- sokoloff 3y ago> Exponentiation relies on super scripts to separate its arguments, making it extremely unambiguous at least which operations are part of the exponent and which the total. The textual representation even for exponents is not enough if you don't already know that exponentiation has higher precedence than multiplication. "1 - 3xy + 2xy²" Both of us know that only the y term is squared in that expression. How do we know that? I claim that we know that because we know the precedence rules and that someone never exposed to our system of algebra would not inherently and unambiguously know that it was 2·x·(y²) rather than (2·x·y)² or even 2·(x·y)² merely by visual inspection of the expression. This (the meaning of the above expression, including the precedence/grouping) is something that has to be taught in Alegbra/Prealgebra courses, and is something that some students struggle with.
- lex-lightning 3y agoYes, but programming is more akin to copywriting than mathematical notation most of the time. Math has very well-defined, well-trod conventions that are densely packed into the notation. When people try to write code like this though, it’s hard to read. All else equal, I’ll take a snippet of code with more characters in it but less work to unpack those characters. Reading linearly is cheap; I get tired reading formulas faster than reading technical prose. Precedence makes the mental parsing nonlinear.
- dheera 3y agoThe REAL problem comes from math and physics teachers (even at the university level) writing things like: (a + b) / 2π instead of (a + b) / (2π) It seems that math teachers put division above multiplication in order of operations but programming languages almost universally treat division and multiplication as equal and read them left-to-right. I've fixed multiple bugs before that were due to this.