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 set is equal to set only #20208

Merged
merged 2 commits into from Oct 6, 2020
Merged

Fixed set is equal to set only #20208

merged 2 commits into from Oct 6, 2020

Conversation

sidhu1012
Copy link
Contributor

@sidhu1012 sidhu1012 commented Oct 5, 2020

References to other Issues or PRs

Fixes #20089

Brief description of what is fixed or changed

Earlier #in #subset gave wrong output due to inconsistency of #Eq with sets and expr

Other comments

Release Notes

  • sets
    • Earlier expr and sets were treated equal which gave incorrect output for some set functions(mainly : - in, is_subset), made sets and expr not to be equal

@sympy-bot
Copy link

sympy-bot commented Oct 5, 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
    • Earlier expr and sets were treated equal which gave incorrect output for some set functions(mainly : - in, is_subset), made sets and expr not to be equal (#20208 by @sidhu1012)

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

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

#### Brief description of what is fixed or changed
Earlier #in #subset gave wrong output due to inconsistency of #Eq with sets and expr

#### 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
     - Earlier expr and sets were treated equal which gave incorrect output for some set functions(mainly : - in, is_subset), made sets and expr not to be equal
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov
Copy link

codecov bot commented Oct 5, 2020

Codecov Report

Merging #20208 into master will increase coverage by 19.970%.
The diff coverage is 100.000%.

@@              Coverage Diff               @@
##            master    #20208        +/-   ##
==============================================
+ Coverage   44.413%   64.384%   +19.970%     
==============================================
  Files          671       671                
  Lines       173799    174149       +350     
  Branches     41067     41093        +26     
==============================================
+ Hits         77191    112125     +34934     
+ Misses       90709     55600     -35109     
- Partials      5899      6424       +525     

@sidhu1012
Copy link
Contributor Author

Pls review

@@ -1342,6 +1343,10 @@ def is_eq(lhs, rhs):
return retval

retval = _eval_is_eq(lhs, rhs)

if isinstance(lhs, Set) and not isinstance(rhs, Set) or not isinstance(lhs, Set) and isinstance(rhs, Set):
retval = False
Copy link
Contributor

Choose a reason for hiding this comment

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

A better fix would be to add _eval_Is_eq handlers in sets/handlers. We can have a handler for Set, Basic that always returns False and then a handler for Set, Set that returns None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes , thats what I tried at first but the two modules are so closely linked that their circular import issue couldn't be solved.

Copy link
Contributor

Choose a reason for hiding this comment

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

There will be some way to solve the circular import. It just sometimes involves moving some imports around in other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll give it another try

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin Review pls

assert Eq(1, FiniteSet(1, 2)) == False
assert FiniteSet(1) in B
A = FiniteSet(1, 2)
assert not A.issubset(B)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe test A in B as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it would be good to test an example that is a subset as well.

def test_issue_20089():
B = FiniteSet(FiniteSet(1, 2), FiniteSet(1))
assert not 1 in B
assert Eq(1, FiniteSet(1, 2)) == False
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be is S.false rather than == False.

@oscarbenjamin
Copy link
Contributor

This looks good but there could be a few more tests

@sidhu1012
Copy link
Contributor Author

@oscarbenjamin I have added more test cases.

@oscarbenjamin
Copy link
Contributor

Looks good

@sidhu1012
Copy link
Contributor Author

Looks good

Can it be merged now?

@oscarbenjamin
Copy link
Contributor

Yes, I was just waiting for the tests to pass

@oscarbenjamin oscarbenjamin merged commit 04c7849 into sympy:master Oct 6, 2020
@sidhu1012 sidhu1012 deleted the set branch October 7, 2020 10:35
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.

FiniteSet not Value False
3 participants