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]Adding series methods for gamma and incomplete gamma functions and expint #26892

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

arnabnandikgp
Copy link
Contributor

@arnabnandikgp arnabnandikgp commented Jul 31, 2024

References to other Issues or PRs

Closes #24027

Brief description of what is fixed or changed

Other comments

Release Notes

  • series
    • Implemented leading term methods for expint error funciton.
    • Implemented leading term methods for uppergamma and lowergamma fucntion.
    • Implemented aseries method for gamma function.
    • Added helper classes for expint for being tractable for gruntz.
    • Extends aseries expansion for loggamma in negative infinity and corresponding limits

@sympy-bot
Copy link

sympy-bot commented Jul 31, 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:

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. -->
Closes #24027

#### 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
  * Implemented leading term methods for expint error funciton.
  * Implemented leading term methods for uppergamma and lowergamma fucntion.
  * Implemented aseries method for gamma function.
  * Added helper classes for expint for being tractable for gruntz.
  * Extends aseries expansion for loggamma in negative infinity and corresponding limits
<!-- END RELEASE NOTES -->

Comment on lines 1439 to 1441
if nu.is_real and nu >= 1:
arg = 1/(nu - 1)
if nu == 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Writing if nu >= 1 can result in an error if nu is an expression rather than a rational number:

In [1]: x, y = symbols('x, y', real=True)

In [2]: expint(x, y)
Out[2]: Eₓ(y)

In [3]: expint(x, y).leadterm(x)
---------------------------------------------------------------------------
TypeError: cannot determine truth value of Relational: x >= 1 

Checking if nu == 1 only checks if nu is the explicit integer 1. If nu is any other symbolic expression then it will return False.

The code shown might work for integer values of nu but will fail in different ways for symbolic expressions.

Also if checking nu == 1 then it should be done before computing 1/(nu - 1).

@arnabnandikgp arnabnandikgp marked this pull request as ready for review August 14, 2024 13:32
@arnabnandikgp arnabnandikgp reopened this Aug 14, 2024
@arnabnandikgp arnabnandikgp reopened this Aug 26, 2024
fucntions

Signed-off-by: arnabnandikgp <arnabnandi2002@gmail.com>
@arnabnandikgp arnabnandikgp force-pushed the gamma_factorial_series branch from 21c8d3a to 8eb7f61 Compare August 26, 2024 18:50
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).

@arnabnandikgp arnabnandikgp marked this pull request as draft August 26, 2024 21:24
@arnabnandikgp arnabnandikgp marked this pull request as ready for review August 28, 2024 11:58
@arnabnandikgp
Copy link
Contributor Author

arnabnandikgp commented Aug 29, 2024

ping for reviews @anutosh491 and @oscarbenjamin.

Signed-off-by: arnabnandikgp <arnabnandi2002@gmail.com>
@arnabnandikgp
Copy link
Contributor Author

arnabnandikgp commented Sep 8, 2024

It seems there were a lot of problems with the expint function,

  1. the aseries method is not triggered due to bad handling of expression in the _eval_nseries
In [3]: expint(4, x).series(x, oo,4)
Out[3]: -I*pi*x**3/6 + O(x**(-4), (x, oo))

  1. limits
In [4]: limit(expint(1,x),x ,oo)
Out[4]: expint(1, oo)

In [5]: limit(expint(4,x),x ,oo)
Out[5]: -oo*I

in the latest commit I have fixed these issues

@arnabnandikgp arnabnandikgp changed the title [GSoC]Adding series methods for gamma and incomplete gamma functions [GSoC]Adding series methods for gamma and incomplete gamma functions and expint Sep 8, 2024
…ctable at infinty

Signed-off-by: arnabnandikgp <arnabnandi2002@gmail.com>
Signed-off-by: arnabnandikgp <arnabnandi2002@gmail.com>
point = args0[1]
nu = self.args[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.

We should have the following here !

if point in [S.Infinity, S.NegativeInfinity]:

On top of it, we could surely have checks for eg
expint(1, 1/x).as_leading_term(x, logx=None, cdir=1) and cdir = -1 returning self

Then if we add tests for limits eg limit(expint(1, 1/x), x, 0) (check both + and - ... we should get separate results) .... we then know for sure that the results are returned through gruntz as expected.

try:
_, ex = self.args[1].leadterm(x)
except (ValueError, NotImplementedError):
return self
Copy link
Member

Choose a reason for hiding this comment

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

How necessary are these try-except blocks here ?

They might be important but I don't see any tests being added for this case. Maybe you can add some ?

Copy link
Member

@anutosh491 anutosh491 left a comment

Choose a reason for hiding this comment

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

I like a good portion of what I see. Left some comments. The main one which should be addressed is this https://github.com/sympy/sympy/pull/26892/files#r1745358695


# test limits
assert limit(expint(3, x), x, oo) == S.Zero
assert limit(expint(1, x), x, oo) == S.Zero
Copy link
Member

Choose a reason for hiding this comment

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

test negative infinity too (should be 0 so can be checked bi-directionally)

…nding tests

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.

4 participants