"1/4x" and "1/(4)x" evaluate differently #2951
Replies: 2 comments 3 replies
-
Thanks for your input! The behavior of implicit multiplication was changed a year a go or so, it will be good to read up on the following discussions: Coming up with a simple, coherent rule to deal with division in combination with implicit multiplication is hard. For example, if you evaluate I'm always open to see if we can improve it further. But if you want to rethink the behavior, we have to work out the full list with all cases to see how it would fit in the bigger whole, and weigh the pros/cons again. |
Beta Was this translation helpful? Give feedback.
-
@josdejong Thanks for the context and issues. I've seen 'Rule 2' discussed in issues now and then, I guess this is it 😄 These comments were particularly helpful and still seem accurate, though they're a bit old:
My opinion, which is just of course only that, is that the parser would be better off without this. Less mathematically inclined users might be surprised by the result of The fact that "whether an operand is a numeric literal or a symbol can affect operator precedence" means that changing a constant to a symbol does change results:
I'm mostly agnostic on whether implicit multiplication should be higher or lower precendence than division, but I strongly believe the examples above should all evaluate the same (whether to
I suspect that only division with implicit multiplication breaks these rules. Why use implicit multiplication?: I run a site which uses LaTeX input for mathematical expressions, which are then transformed to something MathJS can parse. Since users might use implicit multiplication, I don't have control over that. The actual issue came up when upgrading MathJS from pre-Rule 2 to post-Rule 2 versions. Previously |
Beta Was this translation helpful? Give feedback.
-
This difference in parsing surprised me and seems like a bug:
Describe the bug
I would not expect parentheses to affect the grouping of items outside the parens. But "1/4x" vs "1/(4)x" changes whether "x" is in the denominator.
Beta Was this translation helpful? Give feedback.
All reactions