From e58d2abf9490496346fb4f114d98a9c9393a2b8d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 18 Aug 2022 18:48:10 -0700 Subject: [PATCH] Set_object_intersection.cardinality: Remove; move delegation to super to Set_object --- src/sage/sets/set.py | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 8c0668724d0..b76e6b064ef 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -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): """ @@ -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() @@ -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.