Skip to content
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

[GSoC]Refactored series code and added aseries suppport for lambertw #26961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arnabnandikgp
Copy link
Contributor

@arnabnandikgp arnabnandikgp commented Aug 14, 2024

References to other Issues or PRs

Fixes #26105

Brief description of what is fixed or changed

Other comments

Release Notes

  • series
    • Fixed bugs and refactored code for the _eval_as_leading_term and _eval_nseries methods of lambertw.
    • Implemented _eval_aseries method for lambertw function.

@sympy-bot
Copy link

sympy-bot commented Aug 14, 2024

Hi, I am the SymPy bot. 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:

  • series
    • Fixed bugs and refactored code for the _eval_as_leading_term and _eval_nseries methods of lambertw. (#26961 by @arnabnandikgp)

    • Implemented _eval_aseries method for lambertw function. (#26961 by @arnabnandikgp)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.14.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #26105 

#### Brief description of what is fixed or changed


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* series
  * Fixed bugs and refactored code for the `_eval_as_leading_term` and `_eval_nseries` methods of lambertw.
  * Implemented `_eval_aseries` method for lambertw function.

<!-- END RELEASE NOTES -->

Copy link

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).


return s + Order(x**n, x)
if lte.is_positive:
if ceiling(n/lte) >= 1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test like if ceiling(n/lte) >= 1 can fail if lte is a symbol:

In [1]: x = Symbol('x', positive=True)

In [2]: x.is_positive
Out[2]: True

In [3]: x >= 1
Out[3]: x1

In [4]: if x >= 1:
   ...:     print('something')
   ...: 
---------------------------------------------------------------------------
TypeError

@arnabnandikgp
Copy link
Contributor Author

also ping @anutosh491 for reviews

Comment on lines 1253 to 1255
if lte.is_positive:
if (ceiling(n/lte) - 1).is_nonnegative is not False:
s = Add(*[(-S.One)**(k - 1)*Integer(k)**(k - 2)/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing is_nonnegative is not False means that we go down this branch when is_nonnegative is None.

It is possible to use inequalities here but it needs to be like:

if (ceiling(n / lte) >= 1) is S.true:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is necessary to evaluate range(1, ceiling(n/lte)), ceiling(n/lte) must be a positive integer.

x = symbols('x', positive=True)
if (ceiling(x) >= 1) is S.true:
    range(1, ceiling(x)) # error

Therefore, we need to check if it is a positive integer as follows:

c = ceiling(n/lte)
if c.is_Integer and c >= 1:
    ...

@arnabnandikgp
Copy link
Contributor Author

ping for further reviews.

@oscarbenjamin
Copy link
Collaborator

I haven't checked whether anything is mathematically correct but otherwise it looks okay.

sympy/functions/elementary/exponential.py Outdated Show resolved Hide resolved
from sympy.functions.combinatorial.numbers import stirling
if len(self.args) == 1:
point = args0[0]
if point is S.Infinity:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result is not defined when point is not S.Infinity. To avoid mistakes, I think it's better to use an early return.

if len(self.args) != 1:
    return super()._eval_aseries(n, args0, x, logx)
if args0[0] is not S.Infinity:
    return None
...

#test aseries
assert LambertW(x).aseries(x, n = 2) == -log(log(x))/log(x)**2 + log(log(x))/log(x) - \
log(log(x)) + log(x) + O(x**(-2), (x, oo))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear whether the issue has been resolved. I would like to add a test.

@arnabnandikgp
Copy link
Contributor Author

ping for further reviews.

@arnabnandikgp arnabnandikgp force-pushed the lambertw_series branch 2 times, most recently from 6dd7b87 to 7248031 Compare September 9, 2024 08:09
Signed-off-by: arnabnandikgp <arnabnandi2002@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong series expansion
5 participants