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
Fix unevaluated printing of negative sum in numerator #24111
Fix unevaluated printing of negative sum in numerator #24111
Conversation
✅ Hi, I am the SymPy bot (v167). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.12. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Test program
With this PR:
With master:
|
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) before after ratio
[41d90958] [a2400344]
<sympy-1.11.1^0>
- 956±2μs 612±2μs 0.64 solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
- 2.77±0.01ms 1.15±0ms 0.41 solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
- 5.55±0.01ms 1.69±0ms 0.30 solve.TimeSparseSystem.time_linear_eq_to_matrix(30)
Full benchmark results can be found as artifacts in GitHub Actions |
Looks good. |
Looks like the added tests fail. |
fdf52ca
to
9cbb351
Compare
Fixed the tests and replaced As @smichr points out, there are related issues. The test here must be updated when the -1*1 print issue is fixed. |
9cbb351
to
30ed997
Compare
Is that an issue with printing or with parsing? To me this looks correct for the printing code: In [7]: Mul(-1, 1, evaluate=False)
Out[7]: -1⋅1 That printed output is a correct representation of the expression that is being printed. The question coming back from there is why do you have a In [10]: srepr(parse_expr('1-1', evaluate=False))
Out[10]: 'Add(Integer(1), Mul(Integer(-1), Integer(1)))' That could be |
Not sure. The "ironic" thing is that
I'm inclined to ask why anyone would like unevaluated printing at all... |
I think it was a parsing bug and should be fixed by #24096 |
I think what is really wanted is to be able to control how expressions are printed. In other words for some uses it should be possible to define an expression that is to be printed in a certain way and then have it printed in exactly that way. This is sometimes for prettiness purposes e.g. if you aren't really doing much heavy computing with SymPy but you want it to produce displayed equations. Then this kind of thing ruins your equations:
In that context someone might use The other context is things related to code generation e.g. in floating point you might need to care about the distinction between The problem is that SymPy just hasn't been designed with these uses in mind and |
Yes, looks like it: In [2]: from sympy.parsing.latex import parse_latex
In [3]: parse_latex('\\frac {-1 - 1*1}{2}')
Out[3]:
-1 - 1⋅1
────────
2
In [4]: parse_latex('\\frac {-1 - 1}{2}')
Out[4]:
-1 - 1
──────
2 |
That seems fine, albeit annoying. But many of the annoyances are due to things we shouldn't be doing in the printers anyway (like sorting). Again, if the printers could actually tell if an expression was "unevaluated" it would make this easier.
I don't like this as a use-case. If you want this sort of thing for code generation you should use special codegen nodes. evaluate=False is much more fragile for code generation because you're more likely to actually do computation with expressions that are used for codegen, but you never want to do computation on unevaluated expressions. That's where things break and you can get all sorts of bugs, because no other part of the codebase is designed around them. I know the original issue author mentioned code generation, but I don't see why you'd need |
References to other Issues or PRs
Fixes #24108
Brief description of what is fixed or changed
Other comments
Release Notes