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

Fixed #22020 by checking for oo in numerical equals #22022

Closed
wants to merge 2 commits into from

Conversation

oscargus
Copy link
Contributor

@oscargus oscargus commented Sep 5, 2021

References to other Issues or PRs

Closes #22020

Brief description of what is fixed or changed

It seems like evalf now returns oo instead of throwing ZeroDivisionError for some cases. This breaks equals resulting in an error that oo cannot be turned into an int.

Other comments

Release Notes

  • core
    • Fixed issue when performing is_constant() on certain expressions which may result in division by zero.

@oscargus oscargus added the core label Sep 5, 2021
@sympy-bot
Copy link

sympy-bot commented Sep 5, 2021

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

  • core
    • Fixed issue when performing is_constant() on certain expressions which may result in division by zero. (#22022 by @oscargus)

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

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

#### Brief description of what is fixed or changed
It seems like `evalf` now returns `oo`  instead of throwing `ZeroDivisionError` for some cases. This breaks equals resulting in an error that `oo` cannot be turned into an `int`.

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

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 -->
* core
    * Fixed issue when performing `is_constant()` on certain expressions which may result in division by zero.
<!-- END RELEASE NOTES -->

@oscarbenjamin
Copy link
Contributor

It seems like evalf now returns oo instead of throwing ZeroDivisionError for some cases.

May it is evalf that should be fixed... The problem originates from #20885

@github-actions
Copy link

github-actions bot commented Sep 5, 2021

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).

@oscargus
Copy link
Contributor Author

oscargus commented Sep 5, 2021

May it is evalf that should be fixed...

I do not disagree with it. However, there may be cases where we actually want to return oo from evalf, while this should take care of those cases as well (as I assume that just because two expressions both evaluate to oo does not make them equal and that oo may show up from evalf in cases that does not involve a division by zero).

So either wait for a "proper" fix or go with this that will not break anything (as far as I can tell, maybe one should check for S.ComplexInfinity as well though).

@@ -666,7 +666,7 @@ def check_denominator_zeros(expression):
a = expr._random(None, 0, 0, 0, 0)
except ZeroDivisionError:
a = None
if a is not None and a is not S.NaN:
if a is not None and a not in (S.NaN, S.Infinity, S.NegativeInfinity):
Copy link
Member

Choose a reason for hiding this comment

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

from sympy.polys.polyutils import illegal
...
if a is not None and a not in illegals:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdly enough adding S.ComplexInfinity, i.e., using illegal (should be in a better location, right? In core somewhere?) leads to that the following test fails:

    x = Symbol('x', positive=True)
    e5 = (1 + x)/x
    assert e5.is_constant() is False

I realize by checking the blame that I added it a while back, but do not really remember the circumstances. It is stated in the documentation that it is tested for denominators being zero. However, in this case returning None should be more correct than False since x cannot be zero...

@oscargus
Copy link
Contributor Author

oscargus commented Sep 5, 2021

Found a better way to fix it, so I close this (as it is done in a completely different way).

@oscargus oscargus closed this Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comparing two operations that contain log sometimes leads to TypeError exception
4 participants