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

[WIP] Fix digamma integral #26563

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rogerbalsach
Copy link

References to other Issues or PRs

Fixes #26523

Brief description of what is fixed or changed

Added regression tests

Other comments

Release Notes

@sympy-bot
Copy link

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.

❌ There was an issue with the release notes. Please do not close this pull request; instead edit the description after reading the guide on how to write release notes.

  • No release notes were found. Please edit the PR description and write the release notes under <!-- BEGIN RELEASE NOTES -->.
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 #26523


#### Brief description of what is fixed or changed
Added regression tests

#### 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 -->

<!-- END RELEASE NOTES -->

Comment on lines 217 to 220
def _eval_is_finite(self):
z, s, a = self.args
if z == 0 or a == 0:
return z.is_zero and a.is_zero and s.is_nonpositive
Copy link
Contributor

Choose a reason for hiding this comment

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

What should happen here if any of the is_ checks gives None?

https://docs.sympy.org/latest/guides/booleans.html

Copy link
Author

Choose a reason for hiding this comment

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

Hi @oscarbenjamin , thanks for taking a look and the information about the booleans.
I thought python and was compatible with the fuzzy logic but it is indeed not. I will use the fuzzy_and function, this should handle correctly the None cases.
Also, I am not sure what is the convention when the function evaluates to NaN, should the is_finite be None?

Copy link
Contributor

Choose a reason for hiding this comment

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

what is the convention when the function evaluates to NaN, should the is_finite be None?

Probably. What case evaluates to nan that you are thinking of?

Copy link
Author

Choose a reason for hiding this comment

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

It is because a lot of situations where the function is infinite is because one has $0^{-s}$. The previous check s.is_nonpositive gives False when s is not real. I have added a check for s to be real, when s is complex the expression is undefined so now the function should return None.

@rogerbalsach rogerbalsach marked this pull request as ready for review May 4, 2024 22:44
@rogerbalsach rogerbalsach marked this pull request as draft May 4, 2024 22:45
Fixed some edge cases.
Check that s is real for 0**s.
Return None when the arguments are infinite.
Comment on lines +232 to +234
exp_expr = self.expand(func=True)
if exp_expr != self:
return exp_expr.is_finite
Copy link
Contributor

Choose a reason for hiding this comment

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

What is expand(func=True) being used for here?

We should avoid creating new expressions during an assumptions query. Just creating the new expression runs the risk of triggering an identical assumptions query which leads to infinite recursion.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I did not think about that. My idea was that, since LerchPhi includes a lot of common functions as particular values (zeta function, polylog, Dirichlet eta, ...), I can try to write the function in terms of these other functions and then let them determine whether the function is finite or not. Is there a safe way to do it without the risks you are mentioning?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is not really a safe way to do it. We just have to accept that the core assumptions cannot resolve all queries:
https://docs.sympy.org/latest/guides/assumptions.html

if a.is_zero is False:
return True
if s.is_real:
return s.is_nonpositive
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if this works correctly when a.is_zero is None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong result for digamma integral representation
3 participants