-
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
Multiplication needs extra processing to reorder coefficient and variable #114
Comments
To be clear: this reordering should be applicable only when the targeted node represents the exact number. The algorithm can be implemented as a new transformer I think. We should also provide a boolean option to switch the behavior. |
What about in more complicated cases? def solve(x):
return 2 * x * 4 It's probably desirable to bubble constant numbers to the front of each product expression somehow, e.g. |
I think we need to handle #89 before this issue. Adding |
Now that #139 is done, the only times where
In such cases we can implement a simplification procedure similar to #115 and combine all the constant coefficients. |
I'm not sure combining constant coeff is always desirable. It may be nice to keep separate for things like If the user wants them combined they can do it themselves, or maybe it can be introduced as a config option, defaulting to |
Good point, it should be configurable On a related note, operations with brackets, such as |
Yeah that's true, but somewhat tricky. It looks it is desirable to check it in more declarative manner.
It is generally good to keep the original syntax as-is. It would be good to make every option normally off if it is too intelligent (the good example is |
Environment
If you used latexify in your own environment, fill at least the following items.
Feel free to add other items if you think they are useful.
Description
The current implementation of
visit_BinOp
doesn't change the ordering of the operands. This is desirable or acceptable for most operations with multiplication being the exception. Numeric coefficients should always precede variable names. That isa*2
and2*a
should both produce2a
.latexify_py/src/latexify/codegen/function_codegen.py
Lines 473 to 479 in 3b1b05b
Reproduction
produces
\mathrm{solve}(a, b, c) = \frac{-b + \sqrt{b^{{2}} - {4} a c}}{a {2}}
Expected behavior
The above should produce:
\mathrm{solve}(a, b, c) = \frac{-b + \sqrt{b^{{2}} - {4} a c}}{{2} a}
The text was updated successfully, but these errors were encountered: