5 ms·
> "6 ÷ 2x" gets parsed as "6 / (2 * x)" Edit: I'm probably wrong about precedence for 2x, which should be stronger. Which would leave 2(1+2) still really ambig
by merijnv 15y ago
> "6 ÷ 2x" gets parsed as "6 / (2 * x)"
Edit: I'm probably wrong about precedence for 2x, which should be stronger. Which would leave 2(1+2) still really ambiguous. I guess the true lesson here is to always parenthesize explicitly or use over/under notation,
But this is wrong! Division and multiplication have the same precedence and left-to-right application order!
Hence, "6 ÷ 2x" should be parsed as "(6 ÷ 2) * x", which I admit is a bit confusing, so you probably should write out either the parenthesis or the multiplication. But, just because the notation is confusing doesn't mean the rules no longer apply.
- chc 15y agoBut this makes almost everybody wrong. Going by this, you would evaluate 6x ÷ 2x to 3(x^2) rather than 3. That is clearly not the intention, so somebody is wrong here, but it's a matter of opinion whether it's the writer (for not precisely following standard notation) or the standard notation (for being counterintuitive) that deserves the blame.
- droithomme 15y agoYes, this is correct and is the reason why I set implicit multiplication to a higher precedence in the calculators I've written. Obviously not everyone agrees though, but it's certainly the way it's always been interpreted in written algebra textbooks. Precedence rules are essentially arbitrary. We have to make them up. Going by most common historical use is a reasonable choice.
- dalke 15y agoWhy does the multiplication in "2x" have the same precedence as in "2 * x"? The previous poster is saying that the no-operator version binds stronger than the versions with operations. I agree that the no-symbol version has different rules than the explicit symbol. Consider the expression "h-bar is h over 2 pi". That's "ħ = h/2π", and is definitely not the same as "(h/2) * π". This is because of the convention that you write the numerator terms and then the denominator terms. That is, if you wanted "h/2 * π" then you would tend to write it hπ/2. As another example, consider Schrödinger's equation, with (-ħ²/2m) * Ψ(r, t). There too the 'm' is well-understood as being in the denominator.
- oddthink 15y agoExactly. This whole thing seems extremely artificial to me; notation is fluid and ambiguous, despite what elementary-school teachers may say. If you're calculating something, you can use whatever rules you want, and if you're reading some else's work, you can complain if they're being ambiguous. My intuitions (astrophysics/finance background) say multiplication-by-juxtaposition is higher-precedence than multiplication-by-symbol, so "x/y(1+y)" would be "x/(y(1+y))"; interpreting it as "(x/y)(1+y)" seems wrong. Then again, "x/y*(1+y)" already looks wrong. The solidus is too powerful. I'd write "(x/y)(1+y)" explicitly.