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
Implement lazy dictionary for trigonometric special angles #24566
Conversation
✅ Hi, I am the SymPy bot (v169). 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. |
🟠Hi, I am the SymPy bot (v169). I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it. This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75. The following commits add new files:
The following commits delete files:
If these files were added/deleted on purpose, you can ignore this message. |
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] [c25ecf0e]
<sympy-1.11.1^0>
- 964±3μs 604±1μs 0.63 solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
- 2.77±0ms 1.14±0ms 0.41 solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
- 5.59±0.01ms 1.68±0.01ms 0.30 solve.TimeSparseSystem.time_linear_eq_to_matrix(30)
Full benchmark results can be found as artifacts in GitHub Actions |
Looks ok to me. Maybe someone else will have suggestions. |
Isn't a function already a "lazy dictionary"? I don't see the need for the indirection here. You can just have |
I would just want to keep dictionary than functions. Because having functions implies something more, like making the logic sequential and and hierarchical than the mapping,
|
This reasoning really doesn't make any sense to me. An The code here is unnecessarily complicated with indirections. if pi_coeff.q in cst_table_some:
rv = chebyshevt(pi_coeff.p, cst_table_some[pi_coeff.q]()) could just be fermat_primes = [3, 5, 17, 257] # defined above somewhere
if pi_coeff.q in fermat_primes:
rv = chebyshevt(pi_coeff.p, cos_table(pi_coeff.q)) where |
By the way, it might be worth sympifying a string form of cos_257. It's a bit of a hack, but in my tests it's considerably faster. If we can speed up the actual construction that would be great, but I expect that would require a lot of cleaning up of assumptions use in constructors which will be harder due how it breaks things. |
I should note that that's specifically with |
It doesn't necessarily characterize the reason to use functions for me,
I'm not sure how you've done that, without an obvious nasty workaround of keeping the form of |
References to other Issues or PRs
#24172
Brief description of what is fixed or changed
I've implemented lazy dictionary based on functional approach
It should be more easier to implement, and have more robust behavior than object-oriented approach in the original suggestion.
This can solve some hidden slowdown issues with trig rewrites like
cos(x + pi/6).expand(trig=True)
I'm trying to collect these issues though.
I'm also planning to make
trigonometric_special.py
to make the special angle formula more explicitly accessible for users, than having to access silently viarewrite
.It could be more easier to use for users who want more concrete input structure like
cos_special(1, 17), cos_special(2, 17), ...
.Other comments
Release Notes
cos(pi/257)
eagerly even if it is not needed. Now,cos(x + pi/6).expand(trig=True)
gives more faster result.