GSoC 2021 Report: Improving Series Expansion (Sidharth Mundhra) - sympy/sympy GitHub Wiki
This report summarizes the work I have done as a part of GSoC 2021 for SymPy. The links to the PRs are in chronological order.
About Me
I am Sidharth Mundhra, a third-year undergraduate student pursuing a major in Mechanical Engineering and a minor in Computer Science from the Indian Institute of Technology (IIT) Bombay.
Project Synopsis
The primary goal of my project was to improve the series expansions capability of SymPy, by fixing the _eval_as_leading_term
methods of various functions. These methods are used to give the leading (first) term of the series expansion and are used directly to calculate limits. When this method raises an error, the highly-recursive gruntz
method is called, which is slower. Fixing the various issues allows more limits to be computed through the leading term method rather than gruntz
, making overall limit computations faster. My weekly blogs can be found here.
Pull Requests
Merged
-
#21253: Fixes a few buggy
_eval_as_leading_term
methods: This PR changed leading term methods ofAdd
andPow
to simplify irrational and imaginary expressions, and also those oftan
andcot
so that they can work for angles outside their principle domain. These changes also led to a few bug fixes which can be seen linked to the PR. -
#21589: A few leading term methods changed: This PR fixes a long-standing issue of incorrect handling of leading term at singularities. Earlier, for compatibility reasons, the expression itself was returned, which is incorrect.
exp(1/x)
does not have any leading term asx->0
, so an error must be raised. This PR changesPow
,exp
,factorial
andgamma
_eval_as_leading_term
to raisePoleError
when the argument is unbounded. Apart from that, this PR also -- Added
LambertW
,SingularityFunction
,fresnels
,fresnelc
, erfi - Fixed
besselj
andbessely
leading term methods - Added
SingularityFunction
power series expansion
- Added
-
#21731: Improvements to
Limit.doit
: This PR focused on removing and re-ordering heuristics of theLimit.doit
method. In the process, leading term methods for many special functions were added. -
#21775: Limit bug fixes: This PR focused on fixing a few new (not regressions) bugs that had popped up since the start of GSoC. The details can be found in the release notes section.
-
#21805: Fixes regression in limits: Due to a change in code path in a previous PR, a masked bug was revealed, leading to the failure of a limit that passed previously. This bug was identified and fix, and other similar places in the code were also patched.
Work in Progress
-
#21837: mrv_leadterm changes: This PR is focusing on removing the fragile
calculate_series
method. After the changes in the previous PRs, this method is no longer required, as we can simply calculate the leading term instead the series in most cases, and in other cases, we could callseries
.compute_leading_term
is also being deprecated (see #21843 for more details). -
Improving documentation of
series
related functions
Issues Opened
- #21758: Printing of Piecewise FourierSeries does not terminate on isympy
- #21836: Wrong number of terms by nseries
- #21838: Deprecation of calculate_series of gruntz
- #21843: Deprecation of compute_leading_term
- #21938: Series raises an error at infinity for an example which can be solved by aseries
Future Work
- A lot of special functions now have an
_eval_as_leading_term
method, but a few remain. It should also be added for them, along with_eval_nseries
and_eval_aseries
- Make
Order
substitution work better. This was mentioned in my proposal but was not implemented. - Implement the
bound
parameter ofaseries
. It was found during the summer that thebound
parameter's intentions were not clear from the docstring, and it did not perform the presumed functions. Its purpose should be thought of and mentioned clearly, and then it should be implemented. - Extending
ring_series
module
Conclusion
The series module now attempts to find the limit by calculating the leading term of the series expansion, before jumping into the gruntz
method. This is sufficient, and faster than gruntz
in many cases, hence speeding up the limit calculations. Proper exception raising and handling have also been implemented, replacing make-shift solutions, making the module more robust, and fixing close to 20 issues. As the series module reaches a good extent of development, extending the faster ring_series
module should be the next target for development.
This summer has been a great exposure to undertaking a large coding project, and working while documenting and writing tests I am grateful to my mentors, Kalevi Suominen and Sachin Agarwal for being readily available for discussions throughout the summer, which smoothened the development process. I plan to continue contributing to SymPy and will also try to help the new contributors.