-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shouldn't √3x
parse as √3 * x
? It doesn't.
#27641
Comments
Can we get this issue a bug tag and priority? I am not sold on the vincula stuff, but definitely should be parsing it according to the rules of operations. |
This is because both If you're willing to write |
I think the current parsing is intended, and it is also thoroughly documented in its own manual section: https://docs.julialang.org/en/latest/manual/integers-and-floating-point-numbers/#man-numeric-literal-coefficients-1 |
It is a little strange though — numeric juxtaposition already behaves like it's lower precedence for two of the other unary operators ( |
I think the manual is a little vague about the combination of unary operation and implicit multiplication,. I believe it just says that "The precedence of numeric literal coefficients is the same as that of unary operators". To me that seems at odds with the parsing of In any case, was there a strong argument behind the current choice of precedence? Would the proposed change, as stated by @JeffBezanson, produce any unwanted side effect? And if not, am I alone in thinking that this change would make silent bugs less likely? |
Upon further thought, I think the deeper issue here for me is the implicit assumption that juxtaposition should be perfectly equivalent to spelling out the multiplication. It might be my years using Mathematica (where I would therefore not propose to change the precedence of unary operators relative to juxtaposition, but rather parse juxtaposition literally as |
This is not a bug, it's a matter of taste. Mathematica does something else, which is fine; Julia's rules are designed to match intuitive mathematical notation. No matter what rules you pick some people are going to be unhappy some of the time. We've been using these rules for a long time at this point with minimal issues and now is really not the time to change them. |
Perhaps the documentation could include an example such as the case at hand to indicate that it can parse differently from the mathematical operators order of precedence? I thought Something like: |
That's not even it, however, as |
I think @mbauman has a good point: |
Would that mean that |
I don't think so, if we just change the parsing of unary operators, such as Fun fact: the Android calculator on my phone says EDIT: I think I was not clear. I understand my updated proposal to parse juxtaposition as |
I will try giving juxtaposition slightly lower precedence than unary operators and see how it goes. |
I would argue that juxtaposition of constants and variables, such as
3x
should be generalized to work with literals such as√3
, so that√3x
parses as(√3) * x
instead of the current√(3x)
. It might be me, but the current parsing is very surprising, specially with longer variable names,2variable1 + √3variable2
. A bug in a pattern like this had me staring at a single line of code for ~10 minutes, before I figured what was wrong!Without "vincula", such as in
√3̅x̅
, this is obviously ambiguous, but I think that the current parsing is actually inconsistent with the parsing of3x^2
, which correctly parses according to the standard math convention, first the power, then the multiplication.A suggestion in slack by Chris Peel was to change the parsing and additionally teach the parser to understand
\sqrt{3x}
, so that we can still have the present behaviour, but with a vincula rendered using unicode. That part might be much more tricky, however.The text was updated successfully, but these errors were encountered: