-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Created a Set Difference class #7462
Conversation
@mrocklin, @skirpichev ping. |
|
||
>>> from sympy import Difference, FiniteSet | ||
|
||
>>> Difference(FiniteSet(0, 1, 2), FiniteSet(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a blank line here will create two different blocks in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks you are right.
|
is_Difference = True | ||
# See if we will be representing sets in terms of differences, | ||
# I guess we can always | ||
# represent a set difference with Union, if yes do we know how? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't make any sense to me.
By the way, go easy on the |
This is the current behavior after the recent commits. @asmeurer @mrocklin @skirpichev @debugger22 Please review. |
On Tue, May 06, 2014 at 10:01:16PM -0700, Harsh Gupta wrote:
I don't sure it's mathematically correct. |
How so? |
See https://en.wikipedia.org/wiki/Set_complement#Absolute_complement. Insomuch as a universal set can be defined (and we have one defined, so I guess for us it can be), the absolute complement of a set is U - A. |
Seems reasonable so far. It would be nice to accompany this work with a motivating use case. |
There are tons of sets you can't represent without this. But probably the simplest example to show would be de'Morgan's laws. |
I don't sure we really know what our ("defined") UniversalSet is. The reference |
I think the problems with UniversalSet are similar to the problems you get with having |
@asmeurer I can't figure out the reason for the travis failure. The only error is with python 3.4 build. |
See #7456 |
@asmeurer @mrocklin @skirpichev Do you think this PR is good to merge as it is. +1 to @asmeurer 's comment. If we disagree on what UniversalSet should be we can sort it out in issue or on mailing list. Anyway there are issue with UniversalSet, we are implicitly assuming it to be |
I would change that so that |
Agreed. But I feel that doing that might get a bit involved, now I'm leveraging the logic coded in BTW what will happen if I create a branch say |
On Fri, May 09, 2014 at 01:14:22PM -0700, Harsh Gupta wrote:
I don't think we should use UniversalSet here, that's why I'm -1. Should we wipe out the UniversalSet class at all - we can discuss |
I have use dUniversalSet just to define complement of A as |
Yes, and I think - that's a bad idea. |
Just raise NotImplementedError for the things that are too much work.
Yes, it should work, as long as you don't rebase.
Would you rather the Reals be the universal set? I think we should keep UniversalSet, just like we should keep oo and nan. They don't make mathematical sense with every operation, but they do make sense with some operations, and are useful in those cases. Why exactly do you want to remove UniversalSet? It probably is better to move this to the mailing list. |
On Sun, May 11, 2014 at 07:16:52PM -0700, Aaron Meurer wrote:
For oo and nan we can precisely restrict their usage to operations,
I don't sure it's a case for UniversalSet (if do, lets Practically, I think that most of time - we want some well defined |
I would just think of For instance, having a universal set allows you to define an abstract "complement", I would keep UniversalSet, but be very conservative with the operations that are allowed with it (e.g., UniversalSet.contains(UniversalSet) should probably raise an error). Are there any other computer algebra systems that can manipulate sets algebraically? |
@@ -1529,33 +1571,6 @@ def _eval_imageset(self, f): | |||
return FiniteSet(*map(f, self)) | |||
|
|||
@property | |||
def _complement(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here was moved to Reals._complement
.
As it should be |
Any news? Lets fill some todo list:
@mrocklin, is there something else? |
@skirpichev I have fixed both issues. |
We have a doctest failure. |
And I don't think we should use the difference syntax for printing of the set complement. It seems, there are a more standard and consistent notation: |
The tests timed out. |
Interval(0, 1), | ||
((Interval(neginf, 0, True, True) + Interval(1, inf, True, True)) | ||
* (Interval(neginf, 0, True, True) + Interval(1, inf, True, True)))) | ||
# It is trouble to do this test as the result can many |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix this problem. Would complement(Interval(-oo,oo)*Interval(-oo,oo))
work?
@@ -1444,6 +1512,56 @@ def _boundary(self): | |||
return EmptySet() | |||
|
|||
|
|||
class UniversalSet(with_metaclass(Singleton, Set)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two UniversalSet classes!
@skirpichev I merged your PR's and also rebased. The travis build also passed. |
@mrocklin can we merge this PR? |
needs another rebase |
@skirpichev @smichr @mrocklin I have resolved the merge conflicts also the travis build passed. |
Sorry for being absent here. I say go ahead. |
Thanks @asmeurer @skirpichev and @mrocklin, the PR is in. I have also updated the release notes https://github.com/sympy/sympy/wiki/Release-Notes-for-0.7.6. |
Todo list: