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

sets: made Rationals.contains(float) indeterminate #20565

Merged
merged 2 commits into from Dec 12, 2020

Conversation

gopalamn
Copy link
Contributor

@gopalamn gopalamn commented Dec 9, 2020

Currently, sympy.Rationals.contains(0.5) evaluates to False.
This patch instead evaluates the expression to indeterminate
based on the following logic: a float represents an approximation
of an underlying number that could be either rational or irrational.
In relation with this change, I have also adjusted a test case
that currently asserts sympy.Rationals.contains(1.0) evaluates
to False. This test was changed to assert that the expression
above evaluates to indeterminate instead of False or True.

Fixes #20364

Current master behavior:
In [1]: sympy.Rationals.contains(0.5)

False

Patched behavior:
In [1]: sympy.Rationals.contains(0.5)

Contains(0.5, Rationals)

References to other Issues or PRs

Brief description of what is fixed or changed

Other comments

Release Notes

  • sets
    • changed behavior of Rationals.contains(float) to indeterminate
    • tests modified to include new behavior

…rminate

Currently, sympy.Rationals.contains(0.5) evaluates to False.
This patch instead evaluates the expression to indeterminate
based on the following logic: a float represents an approximation
of an underlying number that could be either rational or irrational.
In relation with this change, I have also adjusted a test case
that currently asserts sympy.Rationals.contains(1.0) evaluates
to False. This test was changed to assert that the expression
above evaluates to indeterminate instead of False or True.
@sympy-bot
Copy link

sympy-bot commented Dec 9, 2020

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:

  • sets

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

Click here to see the pull request description that was parsed.
Currently, sympy.Rationals.contains(0.5) evaluates to False.
This patch instead evaluates the expression to indeterminate
based on the following logic: a float represents an approximation
of an underlying number that could be either rational or irrational.
In relation with this change, I have also adjusted a test case
that currently asserts sympy.Rationals.contains(1.0) evaluates
to False. This test was changed to assert that the expression
above evaluates to indeterminate instead of False or True.

Fixes #20364 

Current master behavior:
In [1]: sympy.Rationals.contains(0.5)
>>> False

Patched behavior:
In [1]: sympy.Rationals.contains(0.5)
>>> Contains(0.5, Rationals)

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


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


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. 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 -->
* sets
   * changed behavior of Rationals.contains(float) to indeterminate
   * tests modified to include new behavior
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@czgdp1807 czgdp1807 added the sets label Dec 10, 2020
@gopalamn gopalamn closed this Dec 10, 2020
@gopalamn
Copy link
Contributor Author

Travis build failed for transient reason, so re-doing pull request as suggested in chat.

@gopalamn gopalamn reopened this Dec 10, 2020
@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #20565 (df365e2) into master (7813fc7) will increase coverage by 0.031%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##            master    #20565       +/-   ##
=============================================
+ Coverage   75.741%   75.772%   +0.031%     
=============================================
  Files          673       673               
  Lines       174499    174497        -2     
  Branches     41205     41204        -1     
=============================================
+ Hits        132168    132221       +53     
+ Misses       36611     36561       -50     
+ Partials      5720      5715        -5     

@@ -1046,7 +1046,8 @@ def test_Rationals():
Rational(1, 3), 3, Rational(-1, 3), -3, Rational(2, 3)]
assert Basic() not in S.Rationals
assert S.Half in S.Rationals
assert 1.0 not in S.Rationals
assert S.Rationals.contains(0.5) is not True
assert S.Rationals.contains(0.5) is not False
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to do:

assert Rationals.contains(0.5) == Contains(0.5, Rationals, evaluate=False)

Previously, the test was checking whether Rationals.contains(0.5)
was neither false or true. Now, I've adjusted it slightly to more
clearly evaluate whether Rationals.contains is indeterminate.
@oscarbenjamin
Copy link
Contributor

Closing and reopening to restart the tests.

@oscarbenjamin
Copy link
Contributor

This looks good. Thanks for the contribution!

@oscarbenjamin oscarbenjamin merged commit c842b35 into sympy:master Dec 12, 2020
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.

Rationals does not contain floats
4 participants