-
-
Notifications
You must be signed in to change notification settings - Fork 691
Implement isdisjoint for finite sets
#41107
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
Open
whoami730
wants to merge
2
commits into
sagemath:develop
Choose a base branch
from
whoami730:isdisjoint
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,21 +35,18 @@ | |||||||||
| # https://www.gnu.org/licenses/ | ||||||||||
| # **************************************************************************** | ||||||||||
|
|
||||||||||
| import sage.rings.infinity | ||||||||||
| from sage.categories.enumerated_sets import EnumeratedSets | ||||||||||
| from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets | ||||||||||
| from sage.categories.sets_cat import Sets | ||||||||||
| from sage.misc.cachefunc import cached_method | ||||||||||
| from sage.misc.classcall_metaclass import ClasscallMetaclass | ||||||||||
| from sage.misc.latex import latex | ||||||||||
| from sage.misc.prandom import choice | ||||||||||
| from sage.misc.cachefunc import cached_method | ||||||||||
|
|
||||||||||
| from sage.structure.category_object import CategoryObject | ||||||||||
| from sage.structure.element import Element | ||||||||||
| from sage.structure.parent import Parent, Set_generic | ||||||||||
| from sage.structure.richcmp import richcmp_method, richcmp, rich_to_bool | ||||||||||
| from sage.misc.classcall_metaclass import ClasscallMetaclass | ||||||||||
|
|
||||||||||
| from sage.categories.sets_cat import Sets | ||||||||||
| from sage.categories.enumerated_sets import EnumeratedSets | ||||||||||
| from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets | ||||||||||
|
|
||||||||||
| import sage.rings.infinity | ||||||||||
| from sage.structure.richcmp import rich_to_bool, richcmp, richcmp_method | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def has_finite_length(obj) -> bool: | ||||||||||
|
|
@@ -1085,6 +1082,32 @@ def __richcmp__(self, other, op): | |||||||||
| return rich_to_bool(op, 0) | ||||||||||
| return rich_to_bool(op, -1) | ||||||||||
|
|
||||||||||
| def isdisjoint(self, other): | ||||||||||
| """ | ||||||||||
| Return whether ``self`` and ``other`` are disjoint. | ||||||||||
|
|
||||||||||
| INPUT: | ||||||||||
|
|
||||||||||
| - ``other`` -- a finite Set | ||||||||||
|
|
||||||||||
| EXAMPLES:: | ||||||||||
|
|
||||||||||
| sage: X = Set([1,2,3]) | ||||||||||
| sage: Y = Set([2,4,6]) | ||||||||||
| sage: Z = Set([4,5,6]) | ||||||||||
| sage: X.isdisjoint(Y) | ||||||||||
| False | ||||||||||
| sage: X.isdisjoint(Z) | ||||||||||
| True | ||||||||||
| sage: Y.isdisjoint(Z) | ||||||||||
| False | ||||||||||
| """ | ||||||||||
| if not isinstance(other, Set_object_enumerated): | ||||||||||
| raise NotImplementedError | ||||||||||
| return self.set().isdisjoint(other.set()) | ||||||||||
|
Comment on lines
+1105
to
+1107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be much less restrictive here. For example, just works, and I see no good reason why it shouldn't. So possibly simply (untested!):
Suggested change
|
||||||||||
|
|
||||||||||
| is_disjoint = isdisjoint | ||||||||||
|
|
||||||||||
| def issubset(self, other): | ||||||||||
| r""" | ||||||||||
| Return whether ``self`` is a subset of ``other``. | ||||||||||
|
|
@@ -1113,6 +1136,8 @@ def issubset(self, other): | |||||||||
| raise NotImplementedError | ||||||||||
| return self.set().issubset(other.set()) | ||||||||||
|
|
||||||||||
| is_subset = issubset | ||||||||||
|
|
||||||||||
| def issuperset(self, other): | ||||||||||
| r""" | ||||||||||
| Return whether ``self`` is a superset of ``other``. | ||||||||||
|
|
@@ -1141,6 +1166,8 @@ def issuperset(self, other): | |||||||||
| raise NotImplementedError | ||||||||||
| return self.set().issuperset(other.set()) | ||||||||||
|
|
||||||||||
| is_superset = issuperset | ||||||||||
|
|
||||||||||
| def union(self, other): | ||||||||||
| """ | ||||||||||
| Return the union of ``self`` and ``other``. | ||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 standard in Sage is to add underscores between separate words in method names.
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.
I would suggest not to do this in this very special case, because
Setis supposed to be a "better"set(it is not, in my opinion, but it tries), and it isset.isdisjointrather thanset.is_disjoint.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.
Alright, I see.
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.
I'm afraid I have to take this back, the situation in sage is already chaotic :-(
Set(andFrozenBitset) indeed implementsissubsetetc., but there are some classes (MutablePoset,ManifoldSubset,RealSet, I couldn't find any others) that implementis_subset. In #41113, another class is going to implementis_subset.It is not clear to me what's best.
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.
I suppose fundamentally we should make a choice and then rename/deprecate. For the time being, implementing both could be alright (it's just an extra line
isdisjoint = is_disjointin the class).