Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Set_object_intersection.cardinality: Remove; move delegation to super…
Browse files Browse the repository at this point in the history
… to Set_object
  • Loading branch information
Matthias Koeppe committed Aug 19, 2022
1 parent 970d467 commit e58d2ab
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/sage/sets/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def cardinality(self):
except TypeError:
pass

raise NotImplementedError("computation of cardinality of %s not yet implemented" % self.__object)
return super().cardinality()

def is_empty(self):
"""
Expand Down Expand Up @@ -1526,9 +1526,16 @@ def __init__(self, X, Y, category=None):
sage: X = Set(IntegerRange(100)).intersection(Primes())
sage: X.is_finite()
True
sage: X.cardinality()
25
sage: X.category()
Category of finite enumerated sets
sage: TestSuite(X).run()
sage: X = Set(Primes(), category=Sets()).intersection(Set(IntegerRange(200)))
sage: X.cardinality()
46
sage: TestSuite(X).run()
"""
if category is None:
category = Sets()
Expand All @@ -1538,27 +1545,6 @@ def __init__(self, X, Y, category=None):
category = category.Enumerated()
Set_object_binary.__init__(self, X, Y, "intersection", "\\cap", category=category)

def cardinality(self):
r"""
Return the cardinality of this set.
EXAMPLES::
sage: X = Set(IntegerRange(100)).intersection(Primes())
sage: X.cardinality()
25
sage: X = Set(Primes(), category=Sets()).intersection(Set(IntegerRange(200)))
sage: X.cardinality()
46
"""
if self in Sets().Infinite():
return Infinity
if self in Sets().Finite():
from sage.rings.integer import Integer
return Integer(len(list(iter(self))))
return super().cardinality()

def is_finite(self):
r"""
Return whether this set is finite.
Expand Down

0 comments on commit e58d2ab

Please sign in to comment.