-
Notifications
You must be signed in to change notification settings - Fork 393
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
Counterintuitive (wrong?) parenthesis when combining exp() and powers #189
Comments
Yeah I know this kind of ambiguity still remains around unary operators, including bracket-less functions as you reported above. We haven't figure out the correct rules around this yet. |
Hi, there. I am really interested in this project. Could I participate in solving this minor issue? |
@xiziqiao Yeah please describe the ideas if you have it already. I want to avoid simply adding brackets to all functions because of its redundancy, but currently I have no clear policy to appropriately choose whether add a bracket or not. |
@odashi Hi Mr. Odashi, thanks for responding. Our thoughts now is pretty straightforward. If we have a input like log x^2, then the output latex should be (log x)^2. If we want the latex output to be log(x^2), then the python input should be log((x^2)). |
@xiziqiao Please keep discussion on this thread to avoid hidden decisions. The library has several rules to avoid parentheses around the argument of several functions to follow the normal math notation. That means the abbreviation is the special case (=most functions are exactly followed by the parentheses), and this issue is eventually related to whether re-considering this rule or not. |
I didn't remember soon about the context around the pow operator, but it looks it should be treated similarly to that of other binary operators? |
how about just add a parentheses when it is found a pow expression is taken as arg in a function call? I think only the pow operator need a special treatment as its precedence is higher than unary function call |
@odashi I am thinking the same thing as @tesknight. We can simply add a parenthese when pow function is put into the function call. |
It looks the cause comes from the custom precedence of function calls. It is set as a smaller value than pow, resulting in removal of brackets between a unary function and pow.
I think this rule can be removed so that unary functions of a non-constant always require brackets. |
Okay. This seems neat. Are you going to keep changing this rule? If so I will take a look of this new bug |
I think the above change shouldn't be applied, and we should change the behavior around the generation rules of Call instead: latexify_py/src/latexify/codegen/expression_codegen.py Lines 409 to 421 in 1cfb8e7
I'm working on this, will propose some appropriate changes. |
I agree. Simply make pow a higher precedence or unary function call a higher precedence both bring some bugs. We may need to force wrap its arg when a Pow expression be its arg |
I made a similar change: #195 |
Description
When you latexify something like log((x/c)^2), the rendering you get looks (to me at least) like it's log(x/c)^2:
In contrast, Wolfram Alpha for example will insert extra parens to disambiguate this case.
Reproduction
Describe how to reproduce the issue by other people.
The text was updated successfully, but these errors were encountered: