From d03dd0c3305dd8fa05560f3c880a763ba8d140aa Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 22 Feb 2023 20:33:27 -0800 Subject: [PATCH 01/37] src/sage/sets: Add # optional --- src/sage/sets/cartesian_product.py | 24 ++-- src/sage/sets/set.py | 194 +++++++++++++++-------------- 2 files changed, 110 insertions(+), 108 deletions(-) diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index f110f55cfc9..dac1cef42c0 100644 --- a/src/sage/sets/cartesian_product.py +++ b/src/sage/sets/cartesian_product.py @@ -37,14 +37,14 @@ class CartesianProduct(UniqueRepresentation, Parent): EXAMPLES:: - sage: G = cartesian_product([GF(5), Permutations(10)]) - sage: G.cartesian_factors() + sage: G = cartesian_product([GF(5), Permutations(10)]) # optional - sage.libs.pari + sage: G.cartesian_factors() # optional - sage.libs.pari (Finite Field of size 5, Standard permutations of 10) - sage: G.cardinality() + sage: G.cardinality() # optional - sage.libs.pari 18144000 - sage: G.random_element() # random + sage: G.random_element() # random # optional - sage.libs.pari (1, [4, 7, 6, 5, 10, 1, 3, 2, 8, 9]) - sage: G.category() + sage: G.category() # optional - sage.libs.pari Join of Category of finite monoids and Category of Cartesian products of monoids and Category of Cartesian products of finite enumerated sets @@ -93,24 +93,24 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: C = cartesian_product([GF(5), GF(3)]) - sage: x = C((1,3)); x + sage: C = cartesian_product([GF(5), GF(3)]) # optional - sage.libs.pari + sage: x = C((1,3)); x # optional - sage.libs.pari (1, 0) - sage: x.parent() + sage: x.parent() # optional - sage.libs.pari The Cartesian product of (Finite Field of size 5, Finite Field of size 3) - sage: x[0].parent() + sage: x[0].parent() # optional - sage.libs.pari Finite Field of size 5 - sage: x[1].parent() + sage: x[1].parent() # optional - sage.libs.pari Finite Field of size 3 An iterable is also accepted as input:: - sage: C(i for i in range(2)) + sage: C(i for i in range(2)) # optional - sage.libs.pari (0, 1) TESTS:: - sage: C((1,3,4)) + sage: C((1,3,4)) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: (1, 3, 4) should be of length 2 diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index a1789c61300..dab3cf749f7 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -71,7 +71,7 @@ def has_finite_length(obj): True sage: has_finite_length(iter(range(10))) False - sage: has_finite_length(GF(17^127)) + sage: has_finite_length(GF(17^127)) # optional - sage.libs.pari True sage: has_finite_length(ZZ) False @@ -100,7 +100,7 @@ def Set(X=None, category=None): EXAMPLES:: - sage: X = Set(GF(9,'a')) + sage: X = Set(GF(9, 'a')) # optional - sage.libs.pari sage: X {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} sage: type(X) @@ -218,18 +218,24 @@ def union(self, X): EXAMPLES:: sage: Set(QQ).union(Set(ZZ)) - Set-theoretic union of Set of elements of Rational Field and Set of elements of Integer Ring + Set-theoretic union of + Set of elements of Rational Field and + Set of elements of Integer Ring sage: Set(QQ) + Set(ZZ) - Set-theoretic union of Set of elements of Rational Field and Set of elements of Integer Ring - sage: X = Set(QQ).union(Set(GF(3))); X - Set-theoretic union of Set of elements of Rational Field and {0, 1, 2} - sage: 2/3 in X + Set-theoretic union of + Set of elements of Rational Field and + Set of elements of Integer Ring + sage: X = Set(QQ).union(Set(GF(3))); X # optional - sage.libs.pari + Set-theoretic union of + Set of elements of Rational Field and + {0, 1, 2} + sage: 2/3 in X # optional - sage.libs.pari True - sage: GF(3)(2) in X + sage: GF(3)(2) in X # optional - sage.libs.pari True - sage: GF(5)(2) in X + sage: GF(5)(2) in X # optional - sage.libs.pari False - sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) + sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) # optional - sage.libs.pari [0, 0, 1, 1, 2, 2, 3, 4, 5, 6] """ if isinstance(X, (Set_generic, Set_base)): @@ -253,12 +259,10 @@ def intersection(self, X): sage: 2/1 in X True - sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))) - sage: X + sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))); X # optional - sage.libs.pari {} - sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))) - sage: X + sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))); X # optional - sage.libs.pari {} """ if isinstance(X, (Set_generic, Set_base)): @@ -282,12 +286,10 @@ def difference(self, X): sage: 4/1 in X True - sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))) - sage: X + sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))); X # optional - sage.libs.pari {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2} - sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))) - sage: X + sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))); X # optional - sage.libs.pari {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2} """ if isinstance(X, (Set_generic, Set_base)): @@ -411,11 +413,11 @@ def __add__(self, X): Set-theoretic union of Set of elements of Real Field with 53 bits of precision and Set of elements of Vector space of dimension 5 over Rational Field - sage: Set(GF(3)) + Set(GF(2)) + sage: Set(GF(3)) + Set(GF(2)) # optional - sage.libs.pari {0, 1, 2, 0, 1} - sage: Set(GF(2)) + Set(GF(4,'a')) + sage: Set(GF(2)) + Set(GF(4,'a')) # optional - sage.libs.pari {0, 1, a, a + 1} - sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) + sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) # optional - sage.libs.pari [0, 0, 1, 1, a, a + 1, b, b + 1, b^2, b^2 + 1, b^2 + b, b^2 + b + 1] """ return self.union(X) @@ -441,14 +443,14 @@ class Set_object(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_opera EXAMPLES:: - sage: K = GF(19) - sage: Set(K) + sage: K = GF(19) # optional - sage.libs.pari + sage: Set(K) # optional - sage.libs.pari {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18} - sage: S = Set(K) + sage: S = Set(K) # optional - sage.libs.pari - sage: latex(S) + sage: latex(S) # optional - sage.libs.pari \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\} - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.libs.pari sage: latex(Set(ZZ)) \Bold{Z} @@ -606,7 +608,7 @@ def __contains__(self, x): sage: X = Set(ZZ) sage: 5 in X True - sage: GF(7)(3) in X + sage: GF(7)(3) in X # optional - sage.libs.pari True sage: 2/1 in X True @@ -618,16 +620,16 @@ def __contains__(self, x): Finite fields better illustrate the difference between ``__contains__`` for objects and their underlying sets:: - sage: X = Set(GF(7)) - sage: X + sage: X = Set(GF(7)) # optional - sage.libs.pari + sage: X # optional - sage.libs.pari {0, 1, 2, 3, 4, 5, 6} - sage: 5/3 in X + sage: 5/3 in X # optional - sage.libs.pari False - sage: 5/3 in GF(7) + sage: 5/3 in GF(7) # optional - sage.libs.pari False - sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) + sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) # optional - sage.libs.pari [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6] - sage: Set(GF(7)).intersection(Set(GF(5))) + sage: Set(GF(7)).intersection(Set(GF(5))) # optional - sage.libs.pari {} """ return x in self.__object @@ -671,9 +673,9 @@ def cardinality(self): +Infinity sage: Primes().cardinality() +Infinity - sage: Set(GF(5)).cardinality() + sage: Set(GF(5)).cardinality() # optional - sage.libs.pari 5 - sage: Set(GF(5^2,'a')).cardinality() + sage: Set(GF(5^2,'a')).cardinality() # optional - sage.libs.pari 25 """ if self in Sets().Infinite(): @@ -739,7 +741,7 @@ def is_finite(self): sage: Set(QQ).is_finite() False - sage: Set(GF(250037)).is_finite() + sage: Set(GF(250037)).is_finite() # optional - sage.libs.pari True sage: Set(Integers(2^1000000)).is_finite() True @@ -853,13 +855,13 @@ def __init__(self, X, category=None): EXAMPLES:: - sage: S = Set(GF(19)); S + sage: S = Set(GF(19)); S # optional - sage.libs.pari {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18} - sage: S.category() + sage: S.category() # optional - sage.libs.pari Category of finite enumerated sets - sage: print(latex(S)) + sage: print(latex(S)) # optional - sage.libs.pari \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\} - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.libs.pari """ Set_object.__init__(self, X, category=FiniteEnumeratedSets().or_subcategory(category)) @@ -884,7 +886,7 @@ def is_finite(self): EXAMPLES:: - sage: Set(GF(19)).is_finite() + sage: Set(GF(19)).is_finite() # optional - sage.libs.pari True """ return True @@ -916,15 +918,15 @@ def __iter__(self): EXAMPLES:: - sage: S = Set(GF(19)) - sage: I = iter(S) - sage: next(I) + sage: S = Set(GF(19)) # optional - sage.libs.pari + sage: I = iter(S) # optional - sage.libs.pari + sage: next(I) # optional - sage.libs.pari 0 - sage: next(I) + sage: next(I) # optional - sage.libs.pari 1 - sage: next(I) + sage: next(I) # optional - sage.libs.pari 2 - sage: next(I) + sage: next(I) # optional - sage.libs.pari 3 """ return iter(self.set()) @@ -935,8 +937,8 @@ def _latex_(self): EXAMPLES:: - sage: S = Set(GF(2)) - sage: latex(S) + sage: S = Set(GF(2)) # optional - sage.libs.pari + sage: latex(S) # optional - sage.libs.pari \left\{0, 1\right\} """ return '\\left\\{' + ', '.join(latex(x) for x in self.set()) + '\\right\\}' @@ -947,8 +949,8 @@ def _repr_(self): EXAMPLES:: - sage: S = Set(GF(2)) - sage: S + sage: S = Set(GF(2)) # optional - sage.libs.pari + sage: S # optional - sage.libs.pari {0, 1} TESTS:: @@ -967,12 +969,12 @@ def list(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.libs.pari + sage: X # optional - sage.libs.pari {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: X.list() + sage: X.list() # optional - sage.libs.pari [0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1] - sage: type(X.list()) + sage: type(X.list()) # optional - sage.libs.pari <... 'list'> .. TODO:: @@ -995,14 +997,14 @@ def set(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.libs.pari + sage: X # optional - sage.libs.pari {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: X.set() + sage: X.set() # optional - sage.libs.pari {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: type(X.set()) + sage: type(X.set()) # optional - sage.libs.pari <... 'set'> - sage: type(X) + sage: type(X) # optional - sage.libs.pari """ return set(self.object()) @@ -1014,22 +1016,22 @@ def frozenset(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.libs.pari + sage: X # optional - sage.libs.pari {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: s = X.set(); s + sage: s = X.set(); s # optional - sage.libs.pari {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: hash(s) + sage: hash(s) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: unhashable type: 'set' - sage: s = X.frozenset(); s + sage: s = X.frozenset(); s # optional - sage.libs.pari frozenset({0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}) - sage: hash(s) != hash(tuple(X.set())) + sage: hash(s) != hash(tuple(X.set())) # optional - sage.libs.pari True - sage: type(s) + sage: type(s) # optional - sage.libs.pari <... 'frozenset'> """ return frozenset(self.object()) @@ -1040,8 +1042,8 @@ def __hash__(self): EXAMPLES:: - sage: s = Set(GF(8,'c')) - sage: hash(s) == hash(s) + sage: s = Set(GF(8,'c')) # optional - sage.libs.pari + sage: hash(s) == hash(s) # optional - sage.libs.pari True """ return hash(self.frozenset()) @@ -1052,10 +1054,10 @@ def __richcmp__(self, other, op): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X == Set(GF(8,'c')) + sage: X = Set(GF(8,'c')) # optional - sage.libs.pari + sage: X == Set(GF(8,'c')) # optional - sage.libs.pari True - sage: X == Set(GF(4,'a')) + sage: X == Set(GF(4,'a')) # optional - sage.libs.pari False sage: Set(QQ) == Set(ZZ) False @@ -1142,13 +1144,13 @@ def union(self, other): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: Y = Set([GF(8,'c').0, 1, 2, 3]) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.libs.pari + sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # optional - sage.libs.pari + sage: X # optional - sage.libs.pari {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: sorted(Y) + sage: sorted(Y) # optional - sage.libs.pari [1, 2, 3, c] - sage: sorted(X.union(Y), key=str) + sage: sorted(X.union(Y), key=str) # optional - sage.libs.pari [0, 1, 2, 3, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1] """ if not isinstance(other, Set_object_enumerated): @@ -1161,9 +1163,9 @@ def intersection(self, other): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: Y = Set([GF(8,'c').0, 1, 2, 3]) - sage: X.intersection(Y) + sage: X = Set(GF(8,'c')) # optional - sage.libs.pari + sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # optional - sage.libs.pari + sage: X.intersection(Y) # optional - sage.libs.pari {1, c} """ if not isinstance(other, Set_object_enumerated): @@ -1319,7 +1321,7 @@ def _repr_(self): EXAMPLES:: - sage: Set(ZZ).union(Set(GF(5))) + sage: Set(ZZ).union(Set(GF(5))) # optional - sage.libs.pari Set-theoretic union of Set of elements of Integer Ring and {0, 1, 2, 3, 4} """ return "Set-theoretic {} of {} and {}".format(self._op, self._X, self._Y) @@ -1330,7 +1332,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Set(ZZ).union(Set(GF(5)))) + sage: latex(Set(ZZ).union(Set(GF(5)))) # optional - sage.libs.pari \Bold{Z} \cup \left\{0, 1, 2, 3, 4\right\} """ return latex(self._X) + self._latex_op + latex(self._Y) @@ -1344,9 +1346,9 @@ def __hash__(self): The hash values of equal sets are in general not equal since it is not decidable whether two sets are equal:: - sage: X = Set(GF(13)).intersection(Set(ZZ)) - sage: Y = Set(ZZ).intersection(Set(GF(13))) - sage: hash(X) == hash(Y) + sage: X = Set(GF(13)).intersection(Set(ZZ)) # optional - sage.libs.pari + sage: Y = Set(ZZ).intersection(Set(GF(13))) # optional - sage.libs.pari + sage: hash(X) == hash(Y) # optional - sage.libs.pari False TESTS: @@ -1452,7 +1454,7 @@ def __iter__(self): EXAMPLES:: - sage: [x for x in Set(GF(3)).union(Set(GF(2)))] + sage: [x for x in Set(GF(3)).union(Set(GF(2)))] # optional - sage.libs.pari [0, 1, 2, 0, 1] """ for x in self._X: @@ -1466,14 +1468,14 @@ def __contains__(self, x): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) - sage: GF(5)(1) in X + sage: X = Set(GF(3)).union(Set(GF(2))) # optional - sage.libs.pari + sage: GF(5)(1) in X # optional - sage.libs.pari False - sage: GF(3)(2) in X + sage: GF(3)(2) in X # optional - sage.libs.pari True - sage: GF(2)(0) in X + sage: GF(2)(0) in X # optional - sage.libs.pari True - sage: GF(5)(0) in X + sage: GF(5)(0) in X # optional - sage.libs.pari False """ return x in self._X or x in self._Y @@ -1484,14 +1486,14 @@ def cardinality(self): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) - sage: X + sage: X = Set(GF(3)).union(Set(GF(2))) # optional - sage.libs.pari + sage: X # optional - sage.libs.pari {0, 1, 2, 0, 1} - sage: X.cardinality() + sage: X.cardinality() # optional - sage.libs.pari 5 - sage: X = Set(GF(3)).union(Set(ZZ)) - sage: X.cardinality() + sage: X = Set(GF(3)).union(Set(ZZ)) # optional - sage.libs.pari + sage: X.cardinality() # optional - sage.libs.pari +Infinity """ return self._X.cardinality() + self._Y.cardinality() From 6c4478ad0d45a6b0cbf814cc3798ac60cb1984ed Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 23 Feb 2023 08:50:53 -0800 Subject: [PATCH 02/37] src/sage/sets/set.py: Fix # optional --- src/sage/sets/set.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index dab3cf749f7..1015cdf3b3e 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -101,14 +101,16 @@ def Set(X=None, category=None): EXAMPLES:: sage: X = Set(GF(9, 'a')) # optional - sage.libs.pari - sage: X + sage: X # optional - sage.libs.pari {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} - sage: type(X) + sage: type(X) # optional - sage.libs.pari - sage: Y = X.union(Set(QQ)) - sage: Y - Set-theoretic union of {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} and Set of elements of Rational Field - sage: type(Y) + sage: Y = X.union(Set(QQ)) # optional - sage.libs.pari + sage: Y # optional - sage.libs.pari + Set-theoretic union of + {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} and + Set of elements of Rational Field + sage: type(Y) # optional - sage.libs.pari Usually sets can be used as dictionary keys. From 37cac272ad7d33f913dbd475786176cc8f9e1c55 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 23 Feb 2023 22:11:36 -0800 Subject: [PATCH 03/37] sage.sets: Add more # optional --- src/sage/sets/non_negative_integers.py | 8 ++++---- src/sage/sets/set.py | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sage/sets/non_negative_integers.py b/src/sage/sets/non_negative_integers.py index c7b3fd27a2d..8e013eec8ad 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -102,15 +102,15 @@ def __contains__(self, elt): True sage: -1 in NN False - sage: x in NN + sage: x in NN # optional - sage.symbolic False sage: None in NN False - sage: QQbar(sqrt(2)) in NN + sage: QQbar(sqrt(2)) in NN # optional - sage.symbolic, sage.rings.number_field False sage: RIF(1,2) in NN False - sage: QQbar(2) in NN + sage: QQbar(2) in NN # optional - sage.rings.number_field True sage: RIF(2) in NN True @@ -135,7 +135,7 @@ def _element_constructor_(self, i): Traceback (most recent call last): ... ValueError: Value -5 in not in Non negative integers. - sage: NN._element_constructor_(x) + sage: NN._element_constructor_(x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Value x in not in Non negative integers. diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 1015cdf3b3e..d21ef863293 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -329,7 +329,7 @@ def _test_as_set_object(self, tester=None, **options): Instances of other subclasses of :class:`Set_base` run this method:: - sage: Polyhedron()._test_as_set_object(verbose=True) + sage: Polyhedron()._test_as_set_object(verbose=True) # optional - sage.geometry.polyhedron Running the test suite of Set(self) running ._test_an_element() . . . pass ... @@ -715,7 +715,7 @@ def is_empty(self): False sage: Set([1..100]).is_empty() False - sage: Set(SymmetricGroup(2).list()).is_empty() + sage: Set(SymmetricGroup(2).list()).is_empty() # optional - sage.groups False sage: Set(ZZ).is_empty() False @@ -728,7 +728,7 @@ def is_empty(self): False sage: Set([1..100]).is_empty() False - sage: Set(DihedralGroup(4).list()).is_empty() + sage: Set(DihedralGroup(4).list()).is_empty() # optional - sage.groups False sage: Set(QQ).is_empty() False @@ -800,10 +800,10 @@ def subsets_lattice(self): EXAMPLES:: sage: X = Set([1,2,3]) - sage: X.subsets_lattice() + sage: X.subsets_lattice() # optional - sage.combinat Finite lattice containing 8 elements sage: Y = Set() - sage: Y.subsets_lattice() + sage: Y.subsets_lattice() # optional - sage.combinat Finite lattice containing 1 elements """ @@ -1105,7 +1105,7 @@ def issubset(self, other): TESTS:: - sage: len([Z for Z in Y.subsets() if Z.issubset(X)]) + sage: len([Z for Z in Y.subsets() if Z.issubset(X)]) # optional - sage.combinat 8 """ if not isinstance(other, Set_object_enumerated): @@ -1133,7 +1133,7 @@ def issuperset(self, other): TESTS:: - sage: len([Z for Z in Y.subsets() if Z.issuperset(X)]) + sage: len([Z for Z in Y.subsets() if Z.issuperset(X)]) # optional - sage.combinat 4 """ if not isinstance(other, Set_object_enumerated): From a2b8381d4ab795f2fa4b3925adf3b4ce76a6dc3d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 3 Mar 2023 15:40:01 -0800 Subject: [PATCH 04/37] sage.sets: More # optional --- src/sage/sets/image_set.py | 52 +++++++++++++++++++------------------- src/sage/sets/set.py | 44 +++++++++++++++++--------------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/sage/sets/image_set.py b/src/sage/sets/image_set.py index 54b78eede7a..74a99c65641 100644 --- a/src/sage/sets/image_set.py +++ b/src/sage/sets/image_set.py @@ -73,12 +73,12 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve EXAMPLES:: - sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) + sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) # optional - sage.modules sage: R. = QQ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) - sage: Im = f.image() - sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', # optional - sage.modules ....: '_test_some_elements', '_test_elements']) """ if not is_Parent(domain_subset): @@ -173,12 +173,12 @@ def ambient(self): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) - sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) - sage: Im = f.image() - sage: Im.ambient() is R + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules + sage: R. = ZZ[] # optional - sage.modules + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: Im.ambient() is R # optional - sage.modules True sage: P = Partitions(3).map(attrcall('conjugate')) @@ -197,14 +197,14 @@ def lift(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) - sage: Im = f.image() - sage: p = Im.lift(Im.an_element()); p + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: p = Im.lift(Im.an_element()); p # optional - sage.modules 2*x - 4 - sage: p.parent() is R + sage: p.parent() is R # optional - sage.modules True """ return x @@ -219,13 +219,13 @@ def retract(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) - sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) - sage: Im = f.image() - sage: p = 2 * x - 4 - sage: Im.retract(p).parent() + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules + sage: R. = ZZ[] # optional - sage.modules + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: p = 2 * x - 4 # optional - sage.modules + sage: Im.retract(p).parent() # optional - sage.modules Multivariate Polynomial Ring in x, y over Integer Ring """ return x @@ -251,8 +251,8 @@ def cardinality(self) -> Integer: :meth:`~sage.categories.enumerated_sets.EnumeratedSets.ParentMethods.map` defaults to ``is_injective=True``): - sage: R = Permutations(10).map(attrcall('reduced_word')) - sage: R.cardinality() + sage: R = Permutations(10).map(attrcall('reduced_word')) # optional - sage.combinat + sage: R.cardinality() # optional - sage.combinat 3628800 sage: Evens = ZZ.map(lambda x: 2 * x) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index d21ef863293..69a81546bb4 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -411,7 +411,7 @@ def __add__(self, X): EXAMPLES:: - sage: Set(RealField()) + Set(QQ^5) + sage: Set(RealField()) + Set(QQ^5) # optional - sage.modules Set-theoretic union of Set of elements of Real Field with 53 bits of precision and Set of elements of Vector space of dimension 5 over Rational Field @@ -785,9 +785,9 @@ def subsets(self, size=None): EXAMPLES:: sage: X = Set([1, 2, 3]) - sage: list(X.subsets()) + sage: list(X.subsets()) # optional - sage.combinat [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] - sage: list(X.subsets(2)) + sage: list(X.subsets(2)) # optional - sage.combinat [{1, 2}, {1, 3}, {2, 3}] """ from sage.combinat.subset import Subsets @@ -1268,10 +1268,10 @@ class Set_object_binary(Set_object, metaclass=ClasscallMetaclass): EXAMPLES:: - sage: X = Set(QQ^2) + sage: X = Set(QQ^2) # optional - sage.modules sage: Y = Set(ZZ) sage: from sage.sets.set import Set_object_binary - sage: S = Set_object_binary(X, Y, "union", "\\cup"); S + sage: S = Set_object_binary(X, Y, "union", "\\cup"); S # optional - sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring @@ -1285,9 +1285,9 @@ def __classcall__(cls, X, Y, *args, **kwds): TESTS:: sage: from sage.sets.set import Set_object_binary - sage: X = QQ^2 + sage: X = QQ^2 # optional - sage.modules sage: Y = ZZ - sage: Set_object_binary(X, Y, "union", "\\cup") + sage: Set_object_binary(X, Y, "union", "\\cup") # optional - sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring @@ -1305,10 +1305,10 @@ def __init__(self, X, Y, op, latex_op, category=None): TESTS:: sage: from sage.sets.set import Set_object_binary - sage: X = Set(QQ^2) + sage: X = Set(QQ^2) # optional - sage.modules sage: Y = Set(ZZ) - sage: S = Set_object_binary(X, Y, "union", "\\cup") - sage: type(S) + sage: S = Set_object_binary(X, Y, "union", "\\cup") # optional - sage.modules + sage: type(S) # optional - sage.modules """ self._X = X @@ -1375,17 +1375,17 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) + sage: S = Set(QQ^2) # optional - sage.modules sage: T = Set(ZZ) - sage: X = S.union(T); X + sage: X = S.union(T); X # optional - sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() + sage: X.category() # optional - sage.modules Category of infinite sets - sage: latex(X) + sage: latex(X) # optional - sage.modules \Bold{Q}^{2} \cup \Bold{Z} - sage: TestSuite(X).run() + sage: TestSuite(X).run() # optional - sage.modules """ if category is None: category = Sets() @@ -1528,13 +1528,15 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) - sage: T = Set(ZZ) - sage: X = S.intersection(T); X - Set-theoretic intersection of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() + sage: S = Set(QQ^2) # optional - sage.modules + sage: T = Set(ZZ) # optional - sage.modules + sage: X = S.intersection(T); X # optional - sage.modules + Set-theoretic intersection of + Set of elements of Vector space of dimension 2 over Rational Field and + Set of elements of Integer Ring + sage: X.category() # optional - sage.modules Category of enumerated sets - sage: latex(X) + sage: latex(X) # optional - sage.modules \Bold{Q}^{2} \cap \Bold{Z} sage: X = Set(IntegerRange(100)).intersection(Primes()) From dcc4c1cab1efeafb2236f6dc240c6f85d7c4e0c9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 4 Mar 2023 01:14:56 -0800 Subject: [PATCH 05/37] sage.sets: More # optional --- src/sage/sets/set.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 69a81546bb4..ccdbef457ad 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -1426,11 +1426,11 @@ def __richcmp__(self, right, op): EXAMPLES:: - sage: Y = Set(ZZ^2).union(Set(ZZ^3)) - sage: X = Set(ZZ^3).union(Set(ZZ^2)) - sage: X == Y + sage: Y = Set(ZZ^2).union(Set(ZZ^3)) # optional - sage.modules + sage: X = Set(ZZ^3).union(Set(ZZ^2)) # optional - sage.modules + sage: X == Y # optional - sage.modules True - sage: Y == X + sage: Y == X # optional - sage.modules True This illustrates that equality testing for formal unions From 62ab33aa726f1532792ca77f7156fadece73768b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 5 Mar 2023 21:38:40 -0800 Subject: [PATCH 06/37] Add # optional - numpy etc. --- src/sage/sets/non_negative_integers.py | 2 +- src/sage/sets/positive_integers.py | 2 +- src/sage/sets/real_set.py | 14 +++++++------- src/sage/sets/set.py | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sage/sets/non_negative_integers.py b/src/sage/sets/non_negative_integers.py index 8e013eec8ad..0f632c0cd88 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -231,7 +231,7 @@ def _sympy_(self): EXAMPLES:: sage: NN = NonNegativeIntegers() - sage: NN._sympy_() + sage: NN._sympy_() # optional - sympy Naturals0 """ from sympy import Naturals0 diff --git a/src/sage/sets/positive_integers.py b/src/sage/sets/positive_integers.py index aae3c5a031f..26bf71a9cae 100644 --- a/src/sage/sets/positive_integers.py +++ b/src/sage/sets/positive_integers.py @@ -83,7 +83,7 @@ def _sympy_(self): EXAMPLES:: - sage: PositiveIntegers()._sympy_() + sage: PositiveIntegers()._sympy_() # optional - sympy Naturals """ from sympy import Naturals diff --git a/src/sage/sets/real_set.py b/src/sage/sets/real_set.py index 47a0505de6b..b4e1d5ca266 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -2806,21 +2806,21 @@ def _sympy_(self): EXAMPLES:: - sage: RealSet()._sympy_() + sage: RealSet()._sympy_() # optional - sympy EmptySet - sage: RealSet.point(5)._sympy_() # random - this output format is sympy >= 1.9 + sage: RealSet.point(5)._sympy_() # random - this output format is sympy >= 1.9 # optional - sympy {5} - sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random + sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random # optional - sympy {1, 2} - sage: (RealSet(1, 2).union(RealSet.closed(3, 4)))._sympy_() + sage: (RealSet(1, 2).union(RealSet.closed(3, 4)))._sympy_() # optional - sympy Union(Interval.open(1, 2), Interval(3, 4)) - sage: RealSet(-oo, oo)._sympy_() + sage: RealSet(-oo, oo)._sympy_() # optional - sympy Reals Infinities are not elements:: - sage: import sympy - sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) + sage: import sympy # optional - sympy + sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) # optional - sympy False """ from sympy import Reals, Union diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index ccdbef457ad..875ab3765f7 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -839,7 +839,7 @@ def _sympy_(self): sage: X = Set(ZZ); X Set of elements of Integer Ring - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Integers """ from sage.interfaces.sympy import sympy_init @@ -1231,16 +1231,16 @@ def _sympy_(self): sage: X = Set({1, 2, 3}); X {1, 2, 3} - sage: sX = X._sympy_(); sX + sage: sX = X._sympy_(); sX # optional - sympy Set(1, 2, 3) - sage: sX.is_empty is None + sage: sX.is_empty is None # optional - sympy True sage: Empty = Set([]); Empty {} - sage: sEmpty = Empty._sympy_(); sEmpty + sage: sEmpty = Empty._sympy_(); sEmpty # optional - sympy EmptySet - sage: sEmpty.is_empty + sage: sEmpty.is_empty # optional - sympy True """ from sympy import Set, EmptySet @@ -1509,7 +1509,7 @@ def _sympy_(self): sage: X = Set(ZZ).union(Set([1/2])); X Set-theoretic union of Set of elements of Integer Ring and {1/2} - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Union(Integers, Set(1/2)) """ from sympy import Union @@ -1690,7 +1690,7 @@ def _sympy_(self): Set-theoretic intersection of Set of elements of Integer Ring and Set of elements of [3/2, 11/2] - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Range(2, 6, 1) """ from sympy import Intersection @@ -1859,7 +1859,7 @@ def _sympy_(self): Set of elements of Integer Ring sage: X.category() Category of sets - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Complement(Rationals, Integers) sage: X = Set(ZZ).difference(Set(QQ)); X @@ -1868,7 +1868,7 @@ def _sympy_(self): Set of elements of Rational Field sage: X.category() Category of enumerated sets - sage: X._sympy_() + sage: X._sympy_() # optional - sympy EmptySet """ from sympy import Complement @@ -2035,7 +2035,7 @@ def _sympy_(self): Set-theoretic symmetric difference of Set of elements of Integer Ring and {0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3} - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Union(Complement(Integers, Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3)), Complement(Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3), Integers)) """ From 4500966434c647580ddadb4c14d304018f5872ee Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 7 Mar 2023 19:13:14 -0800 Subject: [PATCH 07/37] sage.sets: More # optional --- src/sage/sets/primes.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sage/sets/primes.py b/src/sage/sets/primes.py index df64c2efbbf..b95ed278e45 100644 --- a/src/sage/sets/primes.py +++ b/src/sage/sets/primes.py @@ -66,18 +66,18 @@ def __init__(self, proof): sage: P = Primes(); P Set of all prime numbers: 2, 3, 5, 7, ... - sage: Q = Primes(proof = False); Q + sage: Q = Primes(proof=False); Q Set of all prime numbers: 2, 3, 5, 7, ... TESTS:: sage: P.category() Category of facade infinite enumerated sets - sage: TestSuite(P).run() + sage: TestSuite(P).run() # optional - sage.libs.pari sage: Q.category() Category of facade infinite enumerated sets - sage: TestSuite(Q).run() + sage: TestSuite(Q).run() # optional - sage.libs.pari The set of primes can be compared to various things, but is only equal to itself:: @@ -123,7 +123,7 @@ def __contains__(self, x): False sage: 1.5 in P False - sage: e in P + sage: e in P # optional - sage.symbolic False """ try: @@ -164,7 +164,7 @@ def next(self, pr): EXAMPLES:: sage: P = Primes() - sage: P.next(5) + sage: P.next(5) # optional - sage.libs.pari 7 """ pr = pr.next_prime(self.__proof) @@ -177,11 +177,11 @@ def unrank(self, n): EXAMPLES:: sage: P = Primes() - sage: P.unrank(0) + sage: P.unrank(0) # optional - sage.libs.pari 2 - sage: P.unrank(5) + sage: P.unrank(5) # optional - sage.libs.pari 13 - sage: P.unrank(42) + sage: P.unrank(42) # optional - sage.libs.pari 191 """ return nth_prime(n + 1) From 76ddcc09afb8fae53920bc5bf247cd820b97b5a3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 8 Mar 2023 00:08:19 -0800 Subject: [PATCH 08/37] sage.sets: More # optional --- src/sage/sets/condition_set.py | 22 +-- .../sets/disjoint_union_enumerated_sets.py | 186 +++++++++--------- 2 files changed, 108 insertions(+), 100 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 92f17647315..b4d6f8e84ec 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -104,24 +104,24 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope Using ``ConditionSet`` without predicates provides a way of attaching variable names to a set:: - sage: Z3 = ConditionSet(ZZ^3, vars=['x', 'y', 'z']); Z3 + sage: Z3 = ConditionSet(ZZ^3, vars=['x', 'y', 'z']); Z3 # optional - sage.modules { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring } - sage: Z3.variable_names() + sage: Z3.variable_names() # optional - sage.modules ('x', 'y', 'z') - sage: Z3.arguments() + sage: Z3.arguments() # optional - sage.modules (x, y, z) - sage: Q4. = ConditionSet(QQ^4); Q4 + sage: Q4. = ConditionSet(QQ^4); Q4 # optional - sage.modules { (a, b, c, d) ∈ Vector space of dimension 4 over Rational Field } - sage: Q4.variable_names() + sage: Q4.variable_names() # optional - sage.modules ('a', 'b', 'c', 'd') - sage: Q4.arguments() + sage: Q4.arguments() # optional - sage.modules (a, b, c, d) TESTS:: - sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas - sage: TestSuite(P_inter_B_again).run() + sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas # optional - sage.geometry.polyhedron + sage: TestSuite(P_inter_B_again).run() # optional - sage.geometry.polyhedron, sage.symbolic """ @staticmethod def __classcall_private__(cls, universe, *predicates, vars=None, names=None, category=None): @@ -345,9 +345,9 @@ def _call_predicate(self, predicate, element): sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: predicate = SmallTriples._predicates[0] - sage: element = TripleDigits((1, 2, 3)) - sage: SmallTriples._call_predicate(predicate, element) + sage: predicate = SmallTriples._predicates[0] # optional - sage.symbolic + sage: element = TripleDigits((1, 2, 3)) # optional - sage.symbolic + sage: SmallTriples._call_predicate(predicate, element) # optional - sage.symbolic sqrt(14) < 12 sage: var('t') diff --git a/src/sage/sets/disjoint_union_enumerated_sets.py b/src/sage/sets/disjoint_union_enumerated_sets.py index 3dea567a779..6b21beda837 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -90,30 +90,32 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): In general the input can be any family:: - sage: U3 = DisjointUnionEnumeratedSets( + sage: U3 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([2,3,4], Permutations, lazy=True)) - sage: U3 - Disjoint union of Lazy family ((i))_{i in [2, 3, 4]} - sage: U3.cardinality() + sage: U3 # optional - sage.combinat + Disjoint union of Lazy family + ((i))_{i in [2, 3, 4]} + sage: U3.cardinality() # optional - sage.combinat 32 - sage: it = iter(U3) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U3) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [[1, 2], [2, 1], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1]] - sage: U3.unrank(18) + sage: U3.unrank(18) # optional - sage.combinat [2, 4, 1, 3] This allows for infinite unions:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations)) - sage: U4 - Disjoint union of Lazy family ((i))_{i in Non negative integers} - sage: U4.cardinality() + sage: U4 # optional - sage.combinat + Disjoint union of Lazy family + ((i))_{i in Non negative integers} + sage: U4.cardinality() # optional - sage.combinat +Infinity - sage: it = iter(U4) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U4) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: U4.unrank(18) + sage: U4.unrank(18) # optional - sage.combinat [2, 3, 1, 4] .. WARNING:: @@ -126,41 +128,41 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): We demonstrate the ``keepkey`` option:: - sage: Ukeep = DisjointUnionEnumeratedSets( + sage: Ukeep = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(list(range(4)), Permutations), keepkey=True) - sage: it = iter(Ukeep) - sage: [next(it) for i in range(6)] + sage: it = iter(Ukeep) # optional - sage.combinat + sage: [next(it) for i in range(6)] # optional - sage.combinat [(0, []), (1, [1]), (2, [1, 2]), (2, [2, 1]), (3, [1, 2, 3]), (3, [1, 3, 2])] - sage: type(next(it)[1]) + sage: type(next(it)[1]) # optional - sage.combinat We now demonstrate the ``facade`` option:: - sage: UNoFacade = DisjointUnionEnumeratedSets( + sage: UNoFacade = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(list(range(4)), Permutations), facade=False) - sage: it = iter(UNoFacade) - sage: [next(it) for i in range(6)] + sage: it = iter(UNoFacade) # optional - sage.combinat + sage: [next(it) for i in range(6)] # optional - sage.combinat [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: el = next(it); el + sage: el = next(it); el # optional - sage.combinat [2, 1, 3] - sage: type(el) + sage: type(el) # optional - sage.combinat <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: el.parent() == UNoFacade + sage: el.parent() == UNoFacade # optional - sage.combinat True - sage: elv = el.value; elv + sage: elv = el.value; elv # optional - sage.combinat [2, 1, 3] - sage: type(elv) + sage: type(elv) # optional - sage.combinat The elements ``el`` of the disjoint union are simple wrapped elements. So to access the methods, you need to do ``el.value``:: - sage: el[0] + sage: el[0] # optional - sage.combinat Traceback (most recent call last): ... TypeError: 'sage.structure.element_wrapper.ElementWrapper' object is not subscriptable - sage: el.value[0] + sage: el.value[0] # optional - sage.combinat 2 Possible extensions: the current enumeration order is not suitable @@ -182,12 +184,12 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): :class:`DisjointUnionEnumeratedSets`. Then, one simply writes the ``__init__`` method as usual:: - sage: class MyUnion(DisjointUnionEnumeratedSets): + sage: class MyUnion(DisjointUnionEnumeratedSets): # optional - sage.combinat ....: def __init__(self): ....: DisjointUnionEnumeratedSets.__init__(self, ....: Family([1,2], Permutations)) - sage: pp = MyUnion() - sage: pp.list() + sage: pp = MyUnion() # optional - sage.combinat + sage: pp.list() # optional - sage.combinat [[1], [1, 2], [2, 1]] In case the :meth:`__init__` method takes optional arguments, @@ -202,19 +204,21 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): sage: class UnionOfSpecialSets(DisjointUnionEnumeratedSets): ....: __classcall_private__ = staticmethod(DisjointUnionEnumeratedSets.__classcall_private__) - sage: psp = UnionOfSpecialSets(Family([1,2], Permutations)) - sage: psp.list() + sage: psp = UnionOfSpecialSets(Family([1,2], Permutations)) # optional - sage.combinat + sage: psp.list() # optional - sage.combinat [[1], [1, 2], [2, 1]] TESTS:: sage: TestSuite(U1).run() sage: TestSuite(U2).run() - sage: TestSuite(U3).run() - sage: TestSuite(U4).run() - doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union + sage: TestSuite(U3).run() # optional - sage.combinat + sage: TestSuite(U4).run() # optional - sage.combinat + doctest:...: UserWarning: Disjoint union of Lazy family + ((i))_{i in Non negative integers} + is an infinite union The default implementation of __contains__ can loop forever. Please overload it. - sage: TestSuite(UNoFacade).run() + sage: TestSuite(UNoFacade).run() # optional - sage.combinat We skip ``_test_an_element`` because the coercion framework does not currently allow a tuple to be returned for facade parents:: @@ -226,11 +230,11 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): been defined interactively:: sage: import __main__ - sage: __main__.MyUnion = MyUnion + sage: __main__.MyUnion = MyUnion # optional - sage.combinat sage: __main__.UnionOfSpecialSets = UnionOfSpecialSets - sage: TestSuite(pp).run() - sage: TestSuite(psp).run() + sage: TestSuite(pp).run() # optional - sage.combinat + sage: TestSuite(psp).run() # optional - sage.combinat """ @@ -323,10 +327,12 @@ def _is_a(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Compositions)) - sage: U4._is_a(Composition([3,2,1,1])) - doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union + sage: U4._is_a(Composition([3,2,1,1])) # optional - sage.combinat + doctest:...: UserWarning: Disjoint union of Lazy family + ((i))_{i in Non negative integers} + is an infinite union The default implementation of __contains__ can loop forever. Please overload it. True """ @@ -352,17 +358,19 @@ def __contains__(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Partitions)) - sage: Partition([]) in U4 - doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union + sage: Partition([]) in U4 # optional - sage.combinat + doctest:...: UserWarning: Disjoint union of Lazy family + ((i))_{i in Non negative integers} + is an infinite union The default implementation of __contains__ can loop forever. Please overload it. True Note: one has to use a different family from the previous one in this file otherwise the warning is not re-issued:: - sage: Partition([3,2,1,1]) in U4 + sage: Partition([3,2,1,1]) in U4 # optional - sage.combinat True The following call will loop forever:: @@ -381,21 +389,21 @@ def __iter__(self): """ TESTS:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations)) - sage: it = iter(U4) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U4) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations), ....: keepkey=True, facade=False) - sage: it = iter(U4) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U4) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [(0, []), (1, [1]), (2, [1, 2]), (2, [2, 1]), (3, [1, 2, 3]), (3, [1, 3, 2])] - sage: el = next(it); el.parent() == U4 + sage: el = next(it); el.parent() == U4 # optional - sage.combinat True - sage: el.value == (3, Permutation([2,1,3])) + sage: el.value == (3, Permutation([2,1,3])) # optional - sage.combinat True """ for k in self._family.keys(): @@ -414,7 +422,7 @@ def an_element(self): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([3, 5, 7], Permutations)) sage: U4.an_element() [1, 2, 3] @@ -431,16 +439,16 @@ def cardinality(self): For finite disjoint unions, the cardinality is computed by summing the cardinalities of the enumerated sets:: - sage: U = DisjointUnionEnumeratedSets(Family([0,1,2,3], Permutations)) - sage: U.cardinality() + sage: U = DisjointUnionEnumeratedSets(Family([0,1,2,3], Permutations)) # optional - sage.combinat + sage: U.cardinality() # optional - sage.combinat 10 For infinite disjoint unions, this makes the assumption that the result is infinite:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations)) - sage: U.cardinality() + sage: U.cardinality() # optional - sage.combinat +Infinity .. WARNING:: @@ -463,14 +471,14 @@ def _element_constructor_(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=False) - sage: U._element_constructor_ + sage: U._element_constructor_ # optional - sage.combinat - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=True) - sage: U._element_constructor_ + sage: U._element_constructor_ # optional - sage.combinat """ @@ -483,13 +491,13 @@ def _element_constructor_default(self, el): r""" TESTS:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=False) - sage: U([1]) # indirect doctest + sage: U([1]) # indirect doctest # optional - sage.combinat [1] - sage: U([2,1]) # indirect doctest + sage: U([2,1]) # indirect doctest # optional - sage.combinat [2, 1] - sage: U([1,3,2]) # indirect doctest + sage: U([1,3,2]) # indirect doctest # optional - sage.combinat Traceback (most recent call last): ... ValueError: value [1, 3, 2] does not belong to Disjoint union of @@ -497,13 +505,13 @@ def _element_constructor_default(self, el): 2: Partitions of the integer 2, 3: Partitions of the integer 3} - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), keepkey=True, facade=False) - sage: U((1, [1])) # indirect doctest + sage: U((1, [1])) # indirect doctest # optional - sage.combinat (1, [1]) - sage: U((3,[2,1])) # indirect doctest + sage: U((3,[2,1])) # indirect doctest # optional - sage.combinat (3, [2, 1]) - sage: U((4,[2,1])) # indirect doctest + sage: U((4,[2,1])) # indirect doctest # optional - sage.combinat Traceback (most recent call last): ... ValueError: value (4, [2, 1]) does not belong to Disjoint union of @@ -522,12 +530,12 @@ def _element_constructor_facade(self, el): """ TESTS:: - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) - sage: X([1]).parent() + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat + sage: X([1]).parent() # optional - sage.combinat Partitions of the integer 1 - sage: X([2,1,1]).parent() # indirect doctest + sage: X([2,1,1]).parent() # indirect doctest # optional - sage.combinat Partitions of the integer 4 - sage: X([6]) + sage: X([6]) # optional - sage.combinat Traceback (most recent call last): ... ValueError: cannot coerce `[6]` in any parent in `Finite family {...}` @@ -536,23 +544,23 @@ def _element_constructor_facade(self, el): because this returns a `tuple`, where the coercion framework requires an :class:`Element` be returned. - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}, + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}, # optional - sage.combinat ....: keepkey=True) - sage: p = X._element_constructor_((0, [])) # indirect doctest - sage: p[1].parent() + sage: p = X._element_constructor_((0, [])) # indirect doctest # optional - sage.combinat + sage: p[1].parent() # optional - sage.combinat Partitions of the integer 0 Test that facade parents can create and properly access elements that are tuples (fixed by :trac:`22382`):: - sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), + sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), # optional - sage.combinat ....: mu.standard_tableaux()]) - sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) - sage: s = StandardTableau([[1,3],[2,4]]) - sage: (s,s) in tabs + sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) # optional - sage.combinat + sage: s = StandardTableau([[1,3],[2,4]]) # optional - sage.combinat + sage: (s,s) in tabs # optional - sage.combinat True - sage: ss = tabs( (s,s) ) - sage: ss[0] + sage: ss = tabs( (s,s) ) # optional - sage.combinat + sage: ss[0] # optional - sage.combinat [[1, 3], [2, 4]] We do not coerce when one of the elements is already in the set:: @@ -588,13 +596,13 @@ def Element(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=False) - sage: U.Element + sage: U.Element # optional - sage.combinat <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=True) - sage: U.Element + sage: U.Element # optional - sage.combinat Traceback (most recent call last): ... AttributeError: 'DisjointUnionEnumeratedSets_with_category' object has no attribute 'Element' From 4c8c2adfbb003bb4e21ed8eaedc060db48c58033 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 8 Mar 2023 01:08:07 -0800 Subject: [PATCH 09/37] More # optional --- src/sage/sets/disjoint_union_enumerated_sets.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/sets/disjoint_union_enumerated_sets.py b/src/sage/sets/disjoint_union_enumerated_sets.py index 6b21beda837..5ad8546c99b 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -223,7 +223,7 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): We skip ``_test_an_element`` because the coercion framework does not currently allow a tuple to be returned for facade parents:: - sage: TestSuite(Ukeep).run(skip="_test_an_element") + sage: TestSuite(Ukeep).run(skip="_test_an_element") # optional - sage.combinat The following three lines are required for the pickling tests, because the classes ``MyUnion`` and ``UnionOfSpecialSets`` have @@ -277,8 +277,8 @@ def __init__(self, family, facade=True, keepkey=False, category=None): ....: 2: FiniteEnumeratedSet([4,5,6])}) sage: TestSuite(U).run() - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) - sage: TestSuite(X).run() + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat + sage: TestSuite(X).run() # optional - sage.combinat """ self._family = family self._facade = facade @@ -424,7 +424,7 @@ def an_element(self): sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([3, 5, 7], Permutations)) - sage: U4.an_element() + sage: U4.an_element() # optional - sage.combinat [1, 2, 3] """ return self._an_element_from_iterator() From 0e0387d656d136d85b58269759322161dd46ff88 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 8 Mar 2023 10:25:42 -0800 Subject: [PATCH 10/37] In # optional, no commas between tags --- src/sage/sets/condition_set.py | 8 ++++---- src/sage/sets/non_negative_integers.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index b4d6f8e84ec..2e8a1de78bb 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -79,11 +79,11 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 1.2; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 1.20000000000000 - sage: P_inter_B_again = ConditionSet(P, predicate); P_inter_B_again + sage: P_inter_B_again = ConditionSet(P, predicate); P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic { (x, y, z) ∈ P : sqrt(x^2 + y^2 + z^2) < 1.20000000000000 } - sage: vector([1, 0, 0]) in P_inter_B_again + sage: vector([1, 0, 0]) in P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic True - sage: vector([1, 1, 1]) in P_inter_B_again + sage: vector([1, 1, 1]) in P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic False Iterating over subsets determined by predicates:: @@ -121,7 +121,7 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope TESTS:: sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas # optional - sage.geometry.polyhedron - sage: TestSuite(P_inter_B_again).run() # optional - sage.geometry.polyhedron, sage.symbolic + sage: TestSuite(P_inter_B_again).run() # optional - sage.geometry.polyhedron sage.symbolic """ @staticmethod def __classcall_private__(cls, universe, *predicates, vars=None, names=None, category=None): diff --git a/src/sage/sets/non_negative_integers.py b/src/sage/sets/non_negative_integers.py index 0f632c0cd88..72601250a97 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -106,7 +106,7 @@ def __contains__(self, elt): False sage: None in NN False - sage: QQbar(sqrt(2)) in NN # optional - sage.symbolic, sage.rings.number_field + sage: QQbar(sqrt(2)) in NN # optional - sage.symbolic sage.rings.number_field False sage: RIF(1,2) in NN False From bb9a561170da7378187e34685bece61372ca4128 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Sep 2023 11:41:11 -0700 Subject: [PATCH 11/37] More # optional --- src/sage/sets/family.py | 70 ++++---- src/sage/sets/recursively_enumerated_set.pyx | 8 +- src/sage/sets/set_from_iterator.py | 176 ++++++++++--------- 3 files changed, 128 insertions(+), 126 deletions(-) diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index a630ef51e24..eb08c87a12d 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -17,8 +17,8 @@ Check :trac:`12482` (shall be run in a fresh session):: - sage: P = Partitions(3) - sage: Family(P, lambda x: x).category() + sage: P = Partitions(3) # optional - sage.combinat + sage: Family(P, lambda x: x).category() # optional - sage.combinat Category of finite enumerated sets """ @@ -185,10 +185,10 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa Beware that for those kind of families len(f) is not supposed to work. As a replacement, use the .cardinality() method:: - sage: f = Family(Permutations(3), attrcall("to_lehmer_code")) - sage: list(f) + sage: f = Family(Permutations(3), attrcall("to_lehmer_code")) # optional - sage.combinat + sage: list(f) # optional - sage.combinat [[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0], [2, 0, 0], [2, 1, 0]] - sage: f.cardinality() + sage: f.cardinality() # optional - sage.combinat 6 Caveat: Only certain families with lazy behavior can be pickled. In @@ -196,14 +196,14 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa and unpickle_function (in sage.misc.fpickle) will correctly unpickle. The following two work:: - sage: f = Family(Permutations(3), lambda p: p.to_lehmer_code()); f + sage: f = Family(Permutations(3), lambda p: p.to_lehmer_code()); f # optional - sage.combinat Lazy family ((i))_{i in Standard permutations of 3} - sage: f == loads(dumps(f)) + sage: f == loads(dumps(f)) # optional - sage.combinat True - sage: f = Family(Permutations(3), attrcall("to_lehmer_code")); f + sage: f = Family(Permutations(3), attrcall("to_lehmer_code")); f # optional - sage.combinat Lazy family (i.to_lehmer_code())_{i in Standard permutations of 3} - sage: f == loads(dumps(f)) + sage: f == loads(dumps(f)) # optional - sage.combinat True But this one does not:: @@ -1187,12 +1187,12 @@ def __getstate__(self): sage: d['set'] [3, 4, 7] - sage: f = LazyFamily(Permutations(3), lambda p: p.to_lehmer_code()) - sage: f == loads(dumps(f)) + sage: f = LazyFamily(Permutations(3), lambda p: p.to_lehmer_code()) # optional - sage.combinat + sage: f == loads(dumps(f)) # optional - sage.combinat True - sage: f = LazyFamily(Permutations(3), attrcall("to_lehmer_code")) - sage: f == loads(dumps(f)) + sage: f = LazyFamily(Permutations(3), attrcall("to_lehmer_code")) # optional - sage.combinat + sage: f == loads(dumps(f)) # optional - sage.combinat True """ f = self.function @@ -1417,8 +1417,8 @@ def __init__(self, enumset): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) - sage: TestSuite(f).run() + sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat + sage: TestSuite(f).run() # optional - sage.combinat sage: f = Family(NonNegativeIntegers()) sage: TestSuite(f).run() @@ -1428,12 +1428,12 @@ def __init__(self, enumset): Check that category and keys are set correctly (:trac:`28274`):: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(4)) - sage: f.category() + sage: f = EnumeratedFamily(Permutations(4)) # optional - sage.combinat + sage: f.category() # optional - sage.combinat Category of finite enumerated sets - sage: list(f.keys()) == list(range(f.cardinality())) + sage: list(f.keys()) == list(range(f.cardinality())) # optional - sage.combinat True - sage: Family(Permutations()).keys() + sage: Family(Permutations()).keys() # optional - sage.combinat Non negative integers sage: type(Family(NN)) @@ -1449,8 +1449,8 @@ def __eq__(self, other): """ EXAMPLES:: - sage: f = Family(Permutations(3)) - sage: g = Family(Permutations(3)) + sage: f = Family(Permutations(3)) # optional - sage.combinat + sage: g = Family(Permutations(3)) # optional - sage.combinat sage: f == g True """ @@ -1461,7 +1461,7 @@ def __repr__(self): """ EXAMPLES:: - sage: f = Family(Permutations(3)); f # indirect doctest + sage: f = Family(Permutations(3)); f # indirect doctest # optional - sage.combinat Family (Standard permutations of 3) sage: f = Family(NonNegativeIntegers()); f @@ -1476,7 +1476,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: f = Family(Permutations(3)) + sage: f = Family(Permutations(3)) # optional - sage.combinat sage: [2,1,3] in f True """ @@ -1489,8 +1489,8 @@ def cardinality(self): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) - sage: f.cardinality() + sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat + sage: f.cardinality() # optional - sage.combinat 6 sage: f = Family(NonNegativeIntegers()) @@ -1504,8 +1504,8 @@ def __iter__(self): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) - sage: [i for i in f] + sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat + sage: [i for i in f] # optional - sage.combinat [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ for i in self.enumset: @@ -1516,8 +1516,8 @@ def __getitem__(self, i): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) - sage: f[1] + sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat + sage: f[1] # optional - sage.combinat [1, 3, 2] """ return self.enumset.unrank(i) @@ -1527,10 +1527,10 @@ def __getstate__(self): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) - sage: f.__getstate__() + sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat + sage: f.__getstate__() # optional - sage.combinat {'enumset': Standard permutations of 3} - sage: loads(dumps(f)) == f + sage: loads(dumps(f)) == f # optional - sage.combinat True """ return {'enumset': self.enumset} @@ -1540,9 +1540,9 @@ def __setstate__(self, state): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(0)) - sage: f.__setstate__({'enumset': Permutations(3)}) - sage: f + sage: f = EnumeratedFamily(Permutations(0)) # optional - sage.combinat + sage: f.__setstate__({'enumset': Permutations(3)}) # optional - sage.combinat + sage: f # optional - sage.combinat Family (Standard permutations of 3) """ self.__init__(state['enumset']) diff --git a/src/sage/sets/recursively_enumerated_set.pyx b/src/sage/sets/recursively_enumerated_set.pyx index a8b21530946..50bcd6ad9fb 100644 --- a/src/sage/sets/recursively_enumerated_set.pyx +++ b/src/sage/sets/recursively_enumerated_set.pyx @@ -880,10 +880,10 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): We compute all the permutations of 3:: - sage: seeds = [Permutation([1,2,3])] - sage: succ = attrcall("permutohedron_succ") - sage: R = RecursivelyEnumeratedSet(seeds, succ) - sage: sorted(R.naive_search_iterator()) + sage: seeds = [Permutation([1,2,3])] # optional - sage.combinat + sage: succ = attrcall("permutohedron_succ") # optional - sage.combinat + sage: R = RecursivelyEnumeratedSet(seeds, succ) # optional - sage.combinat + sage: sorted(R.naive_search_iterator()) # optional - sage.combinat [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ cdef set known, todo diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 4c92deb5d52..fa67e99fa25 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -7,20 +7,20 @@ representative for each isomorphism class of graphs:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator( + sage: E = EnumeratedSetFromIterator( # optional - sage.graphs ....: graphs, - ....: name = "Graphs", - ....: category = InfiniteEnumeratedSets(), - ....: cache = True) - sage: E + ....: name="Graphs", + ....: category=InfiniteEnumeratedSets(), + ....: cache=True) + sage: E # optional - sage.graphs Graphs - sage: E.unrank(0) + sage: E.unrank(0) # optional - sage.graphs Graph on 0 vertices - sage: E.unrank(4) + sage: E.unrank(4) # optional - sage.graphs Graph on 3 vertices - sage: E.cardinality() + sage: E.cardinality() # optional - sage.graphs +Infinity - sage: E.category() + sage: E.category() # optional - sage.graphs Category of facade infinite enumerated sets The module also provides decorator for functions and methods:: @@ -97,25 +97,26 @@ class EnumeratedSetFromIterator(Parent): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args = (7,)) - sage: E - {Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, ...} - sage: E.category() + sage: E = EnumeratedSetFromIterator(graphs, args = (7,)) # optional - sage.graphs + sage: E # optional - sage.graphs + {Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, + Graph on 7 vertices, Graph on 7 vertices, ...} + sage: E.category() # optional - sage.graphs Category of facade enumerated sets The same example with a cache and a custom name:: - sage: E = EnumeratedSetFromIterator( + sage: E = EnumeratedSetFromIterator( # optional - sage.graphs ....: graphs, ....: args = (8,), ....: category = FiniteEnumeratedSets(), ....: name = "Graphs with 8 vertices", ....: cache = True) - sage: E + sage: E # optional - sage.graphs Graphs with 8 vertices - sage: E.unrank(3) + sage: E.unrank(3) # optional - sage.graphs Graph on 8 vertices - sage: E.category() + sage: E.category() # optional - sage.graphs Category of facade finite enumerated sets TESTS: @@ -154,7 +155,7 @@ def __init__(self, f, args=None, kwds=None, name=None, category=None, cache=Fals TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: S = EnumeratedSetFromIterator(xsrange, (1,200,-1), category=FiniteEnumeratedSets()) + sage: S = EnumeratedSetFromIterator(xsrange, (1, 200, -1), category=FiniteEnumeratedSets()) sage: TestSuite(S).run() """ if category is not None: @@ -184,7 +185,7 @@ def __hash__(self): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(xsrange, (1,200)) + sage: E = EnumeratedSetFromIterator(xsrange, (1, 200)) sage: hash(E) == hash(tuple(range(1, 14))) True """ @@ -201,16 +202,16 @@ def __reduce__(self): TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: from sage.graphs.graph_generators import graphs - sage: E = EnumeratedSetFromIterator(graphs, + sage: from sage.graphs.graph_generators import graphs # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, # optional - sage.graphs ....: args=(3,), ....: category=FiniteEnumeratedSets(), ....: name="Graphs on 3 vertices") - sage: E + sage: E # optional - sage.graphs Graphs on 3 vertices - sage: F = loads(dumps(E)); F + sage: F = loads(dumps(E)); F # optional - sage.graphs Graphs on 3 vertices - sage: E == F + sage: E == F # optional - sage.graphs True """ return (EnumeratedSetFromIterator, @@ -229,14 +230,15 @@ def _repr_(self): TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(Partitions(7,min_part=2).__iter__) - sage: repr(E) # indirect doctest + sage: E = EnumeratedSetFromIterator(Partitions(7, min_part=2).__iter__) # optional - sage.combinat + sage: repr(E) # indirect doctest # optional - sage.combinat '{[7], [5, 2], [4, 3], [3, 2, 2]}' - sage: E = EnumeratedSetFromIterator(Partitions(9,min_part=2).__iter__) - sage: repr(E) # indirect doctest + sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__) # optional - sage.combinat + sage: repr(E) # indirect doctest # optional - sage.combinat '{[9], [7, 2], [6, 3], [5, 4], [5, 2, 2], ...}' - sage: E = EnumeratedSetFromIterator(Partitions(9,min_part=2).__iter__, name="Some partitions") - sage: repr(E) # indirect doctest + sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__, # optional - sage.combinat + ....: name="Some partitions") + sage: repr(E) # indirect doctest # optional - sage.combinat 'Some partitions' """ l = [] @@ -260,10 +262,10 @@ def __contains__(self, x): EXAMPLES:: - sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: P = Partitions(12,min_part=2,max_part=5) - sage: E = EnumeratedSetFromIterator(P.__iter__) - sage: P([5,5,2]) in E + sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator # optional - sage.combinat + sage: P = Partitions(12, min_part=2, max_part=5) # optional - sage.combinat + sage: E = EnumeratedSetFromIterator(P.__iter__) # optional - sage.combinat + sage: P([5,5,2]) in E # optional - sage.combinat True """ return any(x == y for y in self) @@ -281,18 +283,18 @@ def __eq__(self, other): TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) - sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) - sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), category=FiniteEnumeratedSets()) - sage: E4 == E4 + sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs + sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs + sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), category=FiniteEnumeratedSets()) # optional - sage.graphs + sage: E4 == E4 # optional - sage.graphs True - sage: E4 == F4 + sage: E4 == F4 # optional - sage.graphs True - sage: E4 == E5 + sage: E4 == E5 # optional - sage.graphs False - sage: E5 == E4 + sage: E5 == E4 # optional - sage.graphs False - sage: E5 == E5 + sage: E5 == E5 # optional - sage.graphs True """ if isinstance(other, EnumeratedSetFromIterator): @@ -336,18 +338,18 @@ def __ne__(self, other): TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) - sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) - sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), category=FiniteEnumeratedSets()) - sage: E4 != E4 + sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs + sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs + sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), category=FiniteEnumeratedSets()) # optional - sage.graphs + sage: E4 != E4 # optional - sage.graphs False - sage: E4 != F4 + sage: E4 != F4 # optional - sage.graphs False - sage: E4 != E5 + sage: E4 != E5 # optional - sage.graphs True - sage: E5 != E4 + sage: E5 != E4 # optional - sage.graphs True - sage: E5 != E5 + sage: E5 != E5 # optional - sage.graphs False """ return not self == other @@ -359,13 +361,13 @@ def __iter__(self): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) - sage: g1 = next(iter(E)); g1 + sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) # optional - sage.graphs + sage: g1 = next(iter(E)); g1 # optional - sage.graphs Graph on 8 vertices - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) - sage: g2 = next(iter(E)); g2 + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs + sage: g2 = next(iter(E)); g2 # optional - sage.graphs Graph on 8 vertices - sage: g1 == g2 + sage: g1 == g2 # optional - sage.graphs True """ if hasattr(self, '_cache'): @@ -379,11 +381,11 @@ def unrank(self, i): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) - sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) - sage: E.unrank(2) + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs + sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) # optional - sage.graphs + sage: E.unrank(2) # optional - sage.graphs Graph on 8 vertices - sage: E.unrank(2) == F.unrank(2) + sage: E.unrank(2) == F.unrank(2) # optional - sage.graphs True """ if hasattr(self, '_cache'): @@ -504,11 +506,11 @@ def _sage_src_lines_(self): sage: from sage.misc.sageinspect import sage_getsourcelines sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = MathieuGroup.order - sage: S = sage_getsourcelines(d) # indirect doctest - sage: S[0][2] + sage: d.f = MathieuGroup.order # optional - sage.groups + sage: S = sage_getsourcelines(d) # indirect doctest # optional - sage.groups + sage: S[0][2] # optional - sage.groups ' Return the number of elements of this group.\n' - sage: S[0][25] + sage: S[0][25] # optional - sage.groups ' if not gens:\n' """ from sage.misc.sageinspect import sage_getsourcelines @@ -593,8 +595,8 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): A simple example with many options:: sage: @set_from_function( - ....: name = "From %(m)d to %(n)d", - ....: category = FiniteEnumeratedSets()) + ....: name="From %(m)d to %(n)d", + ....: category=FiniteEnumeratedSets()) ....: def f(m, n): return xsrange(m,n+1) sage: E = f(3,10); E From 3 to 10 @@ -612,30 +614,30 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): sage: @cached_function ....: @set_from_function( - ....: name = "Graphs on %(n)d vertices", - ....: category = FiniteEnumeratedSets(), - ....: cache = True) + ....: name="Graphs on %(n)d vertices", + ....: category=FiniteEnumeratedSets(), + ....: cache=True) ....: def Graphs(n): return graphs(n) - sage: Graphs(10) + sage: Graphs(10) # optional - sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) + sage: Graphs(10).unrank(0) # optional - sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) + sage: Graphs(10) is Graphs(10) # optional - sage.graphs True The ``cached_function`` must go first:: sage: @set_from_function( - ....: name = "Graphs on %(n)d vertices", - ....: category = FiniteEnumeratedSets(), - ....: cache = True) + ....: name="Graphs on %(n)d vertices", + ....: category=FiniteEnumeratedSets(), + ....: cache=True) ....: @cached_function ....: def Graphs(n): return graphs(n) - sage: Graphs(10) + sage: Graphs(10) # optional - sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) + sage: Graphs(10).unrank(0) # optional - sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) + sage: Graphs(10) is Graphs(10) # optional - sage.graphs False """ def __init__(self, f=None, name=None, **options): @@ -865,18 +867,18 @@ class EnumeratedSetFromIterator_method_decorator(): sage: class B(): ....: @set_from_method( - ....: name = "Graphs(%(n)d)", - ....: category = FiniteEnumeratedSets()) + ....: name="Graphs(%(n)d)", + ....: category=FiniteEnumeratedSets()) ....: def graphs(self, n): return graphs(n) sage: b = B() sage: G3 = b.graphs(3) sage: G3 Graphs(3) - sage: G3.cardinality() + sage: G3.cardinality() # optional - sage.graphs 4 sage: G3.category() Category of facade finite enumerated sets - sage: B.graphs(b,3) + sage: B.graphs(b, 3) Graphs(3) And a last example with a name parametrized by a function:: @@ -885,8 +887,8 @@ class EnumeratedSetFromIterator_method_decorator(): ....: def __init__(self, name): self.name = str(name) ....: def __str__(self): return self.name ....: @set_from_method( - ....: name = lambda self,n: str(self)*n, - ....: category = FiniteEnumeratedSets()) + ....: name=lambda self, n: str(self) * n, + ....: category=FiniteEnumeratedSets()) ....: def subset(self, n): ....: return xsrange(n) sage: d = D('a') @@ -914,11 +916,11 @@ def __init__(self, f=None, **options): :mod:`sage.combinat.permutation`) because its method ``bruhat_succ`` and ``bruhat_pred`` are decorated with ``set_from_method``:: - sage: from sage.combinat.permutation import Permutation - sage: loads(dumps(Permutation)) + sage: from sage.combinat.permutation import Permutation # optional - sage.combinat + sage: loads(dumps(Permutation)) # optional - sage.combinat - sage: p = Permutation([3,2,1]) - sage: loads(dumps(p)) == p + sage: p = Permutation([3,2,1]) # optional - sage.combinat + sage: loads(dumps(p)) == p # optional - sage.combinat True """ if f is not None: From 49a927b30069d1d9d779fe46b10525dc57aa3ee3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 13 Mar 2023 01:27:57 -0700 Subject: [PATCH 12/37] sage.sets: More # optional --- src/sage/sets/family.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index eb08c87a12d..bf4ecb47f97 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -1056,7 +1056,7 @@ def _repr_(self): sage: f = LazyFamily([3,4,7], fun); f Lazy family (fun(i))_{i in [3, 4, 7]} - sage: f = Family(Permutations(3), attrcall("to_lehmer_code"), lazy=True); f + sage: f = Family(Permutations(3), attrcall("to_lehmer_code"), lazy=True); f # optional - sage.combinat Lazy family (i.to_lehmer_code())_{i in Standard permutations of 3} sage: f = LazyFamily([3,4,7], lambda i: 2*i); f @@ -1451,7 +1451,7 @@ def __eq__(self, other): sage: f = Family(Permutations(3)) # optional - sage.combinat sage: g = Family(Permutations(3)) # optional - sage.combinat - sage: f == g + sage: f == g # optional - sage.combinat True """ return (isinstance(other, self.__class__) and @@ -1477,7 +1477,7 @@ def __contains__(self, x): EXAMPLES:: sage: f = Family(Permutations(3)) # optional - sage.combinat - sage: [2,1,3] in f + sage: [2,1,3] in f # optional - sage.combinat True """ return x in self.enumset From d703a91804cf68e7fa2cff7d5461b7a47fd682a4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 17 Mar 2023 20:32:46 -0700 Subject: [PATCH 13/37] sage.sets: More # optional --- src/sage/sets/family.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index bf4ecb47f97..3e3676c2d03 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -1069,7 +1069,7 @@ def _repr_(self): Check that using a class as the function is correctly handled:: - sage: Family(NonNegativeIntegers(), PerfectMatchings) + sage: Family(NonNegativeIntegers(), PerfectMatchings) # optional - sage.combinat Lazy family ((i))_{i in Non negative integers} """ if self.function_name is not None: From bbed2e0127b42480bedd68d6d3166b985ed9a828 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 25 Apr 2023 23:10:36 -0700 Subject: [PATCH 14/37] sage.{sets,structure}: More # optional --- src/sage/sets/condition_set.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 2e8a1de78bb..49ddcf26cd0 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -419,16 +419,17 @@ def _sympy_(self): sage: (5, 7, 9) in ST False - sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval + sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval # optional - sage.symbolic { x ∈ Real Field with 53 bits of precision : x >= -7, x <= 4 } - sage: Interval._sympy_() - ConditionSet(x, (x >= -7) & (x <= 4), SageSet(Real Field with 53 bits of precision)) + sage: Interval._sympy_() # optional - sage.symbolic sympy + ConditionSet(x, (x >= -7) & (x <= 4), + SageSet(Real Field with 53 bits of precision)) If a predicate is not symbolic, we fall back to creating a wrapper:: sage: Evens = ConditionSet(ZZ, is_even); Evens { x ∈ Integer Ring : (x) } - sage: Evens._sympy_() + sage: Evens._sympy_() # optional - sympy SageSet({ x ∈ Integer Ring : (x) }) """ from sage.interfaces.sympy import sympy_init From 3f549138b9121fb8e7ad8c16b446a6034d80c872 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 28 Apr 2023 12:01:47 -0700 Subject: [PATCH 15/37] sage.{geometry,matrix,modules,repl,sets}: More # optional --- src/sage/sets/condition_set.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 49ddcf26cd0..e58d68bfa12 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -74,7 +74,7 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope { x ∈ P : at 0x...>(x) } sage: vector([1, 0, 0]) in P_inter_B True - sage: vector([1, 1, 1]) in P_inter_B + sage: vector([1, 1, 1]) in P_inter_B # optional - sage.geometry.polyhedron sage.symbolic False sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 1.2; predicate From 4b16bd5c965f165b305e0da195194fd16a4fef29 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Sep 2023 11:41:46 -0700 Subject: [PATCH 16/37] Doctest cosmetics --- src/sage/sets/set_from_iterator.py | 205 ++++++++++++++--------------- 1 file changed, 99 insertions(+), 106 deletions(-) diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index fa67e99fa25..fc1a8f5dc1a 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -3,7 +3,7 @@ EXAMPLES: -We build a set from the iterator ``graphs`` that returns a canonical +We build a set from the iterator :obj:`graphs` that returns a canonical representative for each isomorphism class of graphs:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator @@ -37,9 +37,9 @@ sage: from sage.sets.set_from_iterator import set_from_method sage: class A: - ....: @set_from_method - ....: def f(self,n): - ....: return xsrange(n) + ....: @set_from_method + ....: def f(self,n): + ....: return xsrange(n) sage: a = A() sage: a.f(3) {0, 1, 2} @@ -97,8 +97,7 @@ class EnumeratedSetFromIterator(Parent): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args = (7,)) # optional - sage.graphs - sage: E # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(7,)); E # optional - sage.graphs {Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, ...} sage: E.category() # optional - sage.graphs @@ -106,13 +105,9 @@ class EnumeratedSetFromIterator(Parent): The same example with a cache and a custom name:: - sage: E = EnumeratedSetFromIterator( # optional - sage.graphs - ....: graphs, - ....: args = (8,), - ....: category = FiniteEnumeratedSets(), - ....: name = "Graphs with 8 vertices", - ....: cache = True) - sage: E # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True, # optional - sage.graphs + ....: name="Graphs with 8 vertices", + ....: category=FiniteEnumeratedSets()); E Graphs with 8 vertices sage: E.unrank(3) # optional - sage.graphs Graph on 8 vertices @@ -283,18 +278,21 @@ def __eq__(self, other): TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs - sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs - sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), category=FiniteEnumeratedSets()) # optional - sage.graphs - sage: E4 == E4 # optional - sage.graphs + sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + ....: category=FiniteEnumeratedSets()) + sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + ....: category=FiniteEnumeratedSets()) + sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), # optional - sage.graphs + ....: category=FiniteEnumeratedSets()) + sage: E4 == E4 # optional - sage.graphs True - sage: E4 == F4 # optional - sage.graphs + sage: E4 == F4 # optional - sage.graphs True - sage: E4 == E5 # optional - sage.graphs + sage: E4 == E5 # optional - sage.graphs False - sage: E5 == E4 # optional - sage.graphs + sage: E5 == E4 # optional - sage.graphs False - sage: E5 == E5 # optional - sage.graphs + sage: E5 == E5 # optional - sage.graphs True """ if isinstance(other, EnumeratedSetFromIterator): @@ -338,18 +336,21 @@ def __ne__(self, other): TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs - sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), category=FiniteEnumeratedSets()) # optional - sage.graphs - sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), category=FiniteEnumeratedSets()) # optional - sage.graphs - sage: E4 != E4 # optional - sage.graphs + sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + ....: category=FiniteEnumeratedSets()) + sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + ....: category=FiniteEnumeratedSets()) + sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), # optional - sage.graphs + ....: category=FiniteEnumeratedSets()) + sage: E4 != E4 # optional - sage.graphs False - sage: E4 != F4 # optional - sage.graphs + sage: E4 != F4 # optional - sage.graphs False - sage: E4 != E5 # optional - sage.graphs + sage: E4 != E5 # optional - sage.graphs True - sage: E5 != E4 # optional - sage.graphs + sage: E5 != E4 # optional - sage.graphs True - sage: E5 != E5 # optional - sage.graphs + sage: E5 != E5 # optional - sage.graphs False """ return not self == other @@ -361,13 +362,13 @@ def __iter__(self): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) # optional - sage.graphs - sage: g1 = next(iter(E)); g1 # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) # optional - sage.graphs + sage: g1 = next(iter(E)); g1 # optional - sage.graphs Graph on 8 vertices - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs - sage: g2 = next(iter(E)); g2 # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs + sage: g2 = next(iter(E)); g2 # optional - sage.graphs Graph on 8 vertices - sage: g1 == g2 # optional - sage.graphs + sage: g1 == g2 # optional - sage.graphs True """ if hasattr(self, '_cache'): @@ -381,11 +382,11 @@ def unrank(self, i): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs - sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) # optional - sage.graphs - sage: E.unrank(2) # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs + sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) # optional - sage.graphs + sage: E.unrank(2) # optional - sage.graphs Graph on 8 vertices - sage: E.unrank(2) == F.unrank(2) # optional - sage.graphs + sage: E.unrank(2) == F.unrank(2) # optional - sage.graphs True """ if hasattr(self, '_cache'): @@ -402,7 +403,8 @@ def _element_constructor_(self, el): sage: S = EnumeratedSetFromIterator(range, args=(1,4)) sage: S(1) - doctest:...: UserWarning: Testing equality of infinite sets which will not end in case of equality + doctest:...: UserWarning: Testing equality of infinite sets + which will not end in case of equality 1 sage: S(0) # indirect doctest Traceback (most recent call last): @@ -422,8 +424,7 @@ def clear_cache(self): sage: from itertools import count sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator sage: E = EnumeratedSetFromIterator(count, args=(1,), cache=True) - sage: e1 = E._cache - sage: e1 + sage: e1 = E._cache; e1 lazy list [1, 2, 3, ...] sage: E.clear_cache() sage: E._cache @@ -506,11 +507,11 @@ def _sage_src_lines_(self): sage: from sage.misc.sageinspect import sage_getsourcelines sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = MathieuGroup.order # optional - sage.groups - sage: S = sage_getsourcelines(d) # indirect doctest # optional - sage.groups - sage: S[0][2] # optional - sage.groups + sage: d.f = MathieuGroup.order # optional - sage.groups + sage: S = sage_getsourcelines(d) # indirect doctest # optional - sage.groups + sage: S[0][2] # optional - sage.groups ' Return the number of elements of this group.\n' - sage: S[0][25] # optional - sage.groups + sage: S[0][25] # optional - sage.groups ' if not gens:\n' """ from sage.misc.sageinspect import sage_getsourcelines @@ -526,7 +527,7 @@ def _sage_argspec_(self): sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() sage: d.f = find_local_minimum - sage: sage_getargspec(d) # indirect doctest + sage: sage_getargspec(d) # indirect doctest FullArgSpec(args=['f', 'a', 'b', 'tol', 'maxfun'], varargs=None, varkw=None, defaults=(1.48e-08, 500), kwonlyargs=[], kwonlydefaults=None, annotations={}) @@ -557,12 +558,12 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): r""" Decorator for :class:`EnumeratedSetFromIterator`. - Name could be string or a function ``(args,kwds) -> string``. + Name could be string or a function ``(args, kwds) -> string``. .. WARNING:: - If you are going to use this with the decorator ``cached_function``, - you must place the ``cached_function`` first. See the example below. + If you are going to use this with the decorator :func:`cached_function`, + you must place the ``@cached_function`` first. See the example below. EXAMPLES:: @@ -586,18 +587,16 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): ....: while True: ....: yield a ....: a, b = b, a + b - sage: F = Fibonacci() - sage: F + sage: F = Fibonacci(); F {1, 2, 3, 5, 8, ...} sage: F.cardinality() +Infinity A simple example with many options:: - sage: @set_from_function( - ....: name="From %(m)d to %(n)d", - ....: category=FiniteEnumeratedSets()) - ....: def f(m, n): return xsrange(m,n+1) + sage: @set_from_function(name="From %(m)d to %(n)d", + ....: category=FiniteEnumeratedSets()) + ....: def f(m, n): return xsrange(m, n + 1) sage: E = f(3,10); E From 3 to 10 sage: E.list() @@ -606,38 +605,34 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): From 1 to 100 sage: E.cardinality() 100 - sage: f(n=100,m=1) == E + sage: f(n=100, m=1) == E True - An example which mixes together ``set_from_function`` and - ``cached_method``:: + An example which mixes together :func:`set_from_function` and + :func:`cached_method`:: sage: @cached_function - ....: @set_from_function( - ....: name="Graphs on %(n)d vertices", - ....: category=FiniteEnumeratedSets(), - ....: cache=True) + ....: @set_from_function(name="Graphs on %(n)d vertices", + ....: category=FiniteEnumeratedSets(), cache=True) ....: def Graphs(n): return graphs(n) - sage: Graphs(10) # optional - sage.graphs + sage: Graphs(10) # optional - sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) # optional - sage.graphs + sage: Graphs(10).unrank(0) # optional - sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) # optional - sage.graphs + sage: Graphs(10) is Graphs(10) # optional - sage.graphs True - The ``cached_function`` must go first:: + The ``@cached_function`` must go first:: - sage: @set_from_function( - ....: name="Graphs on %(n)d vertices", - ....: category=FiniteEnumeratedSets(), - ....: cache=True) + sage: @set_from_function(name="Graphs on %(n)d vertices", + ....: category=FiniteEnumeratedSets(), cache=True) ....: @cached_function ....: def Graphs(n): return graphs(n) - sage: Graphs(10) # optional - sage.graphs + sage: Graphs(10) # optional - sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) # optional - sage.graphs + sage: Graphs(10).unrank(0) # optional - sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) # optional - sage.graphs + sage: Graphs(10) is Graphs(10) # optional - sage.graphs False """ def __init__(self, f=None, name=None, **options): @@ -721,7 +716,7 @@ class EnumeratedSetFromIterator_method_caller(Decorator): - ``f`` -- a method of a class of ``inst`` (and not of the instance itself) - ``name`` -- optional -- either a string (which may contains substitution - rules from argument or a function args,kwds -> string. + rules from argument or a function ``args, kwds -> string``. - ``options`` -- any option accepted by :class:`EnumeratedSetFromIterator` """ @@ -748,7 +743,8 @@ def __init__(self, inst, f, name=None, **options): sage: loads(dumps(d.f())) Traceback (most recent call last): ... - _pickle.PicklingError: Can't pickle : it's not the same object as sage.sets.set_from_iterator.DummyExampleForPicklingTest.f + _pickle.PicklingError: Can't pickle : + it's not the same object as sage.sets.set_from_iterator.DummyExampleForPicklingTest.f """ self.inst = inst self.f = f @@ -813,8 +809,8 @@ def __get__(self, inst, cls): sage: class A: ....: stop = 10000 ....: @set_from_method - ....: def f(self,start): - ....: return xsrange(start,self.stop) + ....: def f(self, start): + ....: return xsrange(start, self.stop) sage: a = A() sage: A.f(a,4) {4, 5, 6, 7, 8, ...} @@ -822,8 +818,8 @@ def __get__(self, inst, cls): sage: class B: ....: stop = 10000 ....: @set_from_method(category=FiniteEnumeratedSets()) - ....: def f(self,start): - ....: return xsrange(start,self.stop) + ....: def f(self, start): + ....: return xsrange(start, self.stop) sage: b = B() sage: B.f(b,2) {2, 3, 4, 5, 6, ...} @@ -852,9 +848,9 @@ class EnumeratedSetFromIterator_method_decorator(): sage: from sage.sets.set_from_iterator import set_from_method sage: class A(): - ....: def n(self): return 12 - ....: @set_from_method - ....: def f(self): return xsrange(self.n()) + ....: def n(self): return 12 + ....: @set_from_method + ....: def f(self): return xsrange(self.n()) sage: a = A() sage: print(a.f.__class__) @@ -866,15 +862,13 @@ class EnumeratedSetFromIterator_method_decorator(): A more complicated example with a parametrized name:: sage: class B(): - ....: @set_from_method( - ....: name="Graphs(%(n)d)", - ....: category=FiniteEnumeratedSets()) - ....: def graphs(self, n): return graphs(n) + ....: @set_from_method(name="Graphs(%(n)d)", + ....: category=FiniteEnumeratedSets()) + ....: def graphs(self, n): return graphs(n) sage: b = B() - sage: G3 = b.graphs(3) - sage: G3 + sage: G3 = b.graphs(3); G3 Graphs(3) - sage: G3.cardinality() # optional - sage.graphs + sage: G3.cardinality() # optional - sage.graphs 4 sage: G3.category() Category of facade finite enumerated sets @@ -884,13 +878,12 @@ class EnumeratedSetFromIterator_method_decorator(): And a last example with a name parametrized by a function:: sage: class D(): - ....: def __init__(self, name): self.name = str(name) - ....: def __str__(self): return self.name - ....: @set_from_method( - ....: name=lambda self, n: str(self) * n, - ....: category=FiniteEnumeratedSets()) - ....: def subset(self, n): - ....: return xsrange(n) + ....: def __init__(self, name): self.name = str(name) + ....: def __str__(self): return self.name + ....: @set_from_method(name=lambda self, n: str(self) * n, + ....: category=FiniteEnumeratedSets()) + ....: def subset(self, n): + ....: return xsrange(n) sage: d = D('a') sage: E = d.subset(3); E aaa @@ -916,11 +909,11 @@ def __init__(self, f=None, **options): :mod:`sage.combinat.permutation`) because its method ``bruhat_succ`` and ``bruhat_pred`` are decorated with ``set_from_method``:: - sage: from sage.combinat.permutation import Permutation # optional - sage.combinat - sage: loads(dumps(Permutation)) # optional - sage.combinat + sage: from sage.combinat.permutation import Permutation # optional - sage.combinat + sage: loads(dumps(Permutation)) # optional - sage.combinat - sage: p = Permutation([3,2,1]) # optional - sage.combinat - sage: loads(dumps(p)) == p # optional - sage.combinat + sage: p = Permutation([3,2,1]) # optional - sage.combinat + sage: loads(dumps(p)) == p # optional - sage.combinat True """ if f is not None: @@ -950,9 +943,9 @@ def __call__(self, f): sage: from sage.sets.set_from_iterator import set_from_method sage: class A: # indirect doctest - ....: @set_from_method() - ....: def f(self): - ....: return xsrange(3) + ....: @set_from_method() + ....: def f(self): + ....: return xsrange(3) sage: a = A() sage: a.f() {0, 1, 2} @@ -965,9 +958,9 @@ def __get__(self, inst, cls): sage: from sage.sets.set_from_iterator import set_from_method sage: class A(): - ....: def n(self): return 12 - ....: @set_from_method - ....: def f(self): return xsrange(self.n()) + ....: def n(self): return 12 + ....: @set_from_method + ....: def f(self): return xsrange(self.n()) sage: a = A() sage: print(A.f.__class__) From 71cc773a6dbe657938a98f5c22a57b4105b1ce5d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 12 May 2023 20:01:52 -0700 Subject: [PATCH 17/37] Fix # optional --- src/sage/sets/condition_set.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index e58d68bfa12..7d66f59300c 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -345,18 +345,18 @@ def _call_predicate(self, predicate, element): sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: predicate = SmallTriples._predicates[0] # optional - sage.symbolic - sage: element = TripleDigits((1, 2, 3)) # optional - sage.symbolic - sage: SmallTriples._call_predicate(predicate, element) # optional - sage.symbolic + sage: predicate = SmallTriples._predicates[0] # optional - sage.symbolic + sage: element = TripleDigits((1, 2, 3)) # optional - sage.modules + sage: SmallTriples._call_predicate(predicate, element) # optional - sage.modules sage.symbolic sqrt(14) < 12 sage: var('t') t - sage: TinyUniverse = ZZ^0 - sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) - sage: predicate = Nullary._predicates[0] - sage: element = TinyUniverse(0) - sage: Nullary._call_predicate(predicate, element) + sage: TinyUniverse = ZZ^0 # optional - sage.modules + sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) # optional - sage.modules sage.symbolic + sage: predicate = Nullary._predicates[0] # optional - sage.modules sage.symbolic + sage: element = TinyUniverse(0) # optional - sage.modules + sage: Nullary._call_predicate(predicate, element) # optional - sage.modules sage.symbolic t > 0 """ if isinstance(predicate, Expression) and predicate.is_callable(): From 6dd822522ab497128897926993efda0f1c0e1842 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 17 May 2023 13:20:30 -0700 Subject: [PATCH 18/37] Massive modularization fixes --- src/sage/sets/condition_set.py | 10 +++++----- src/sage/sets/real_set.py | 15 ++++++++------- src/sage/sets/set.py | 10 +++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 7d66f59300c..18b88e2b809 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -108,14 +108,14 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring } sage: Z3.variable_names() # optional - sage.modules ('x', 'y', 'z') - sage: Z3.arguments() # optional - sage.modules + sage: Z3.arguments() # optional - sage.modules sage.symbolic (x, y, z) - sage: Q4. = ConditionSet(QQ^4); Q4 # optional - sage.modules + sage: Q4. = ConditionSet(QQ^4); Q4 # optional - sage.modules sage.symbolic { (a, b, c, d) ∈ Vector space of dimension 4 over Rational Field } - sage: Q4.variable_names() # optional - sage.modules + sage: Q4.variable_names() # optional - sage.modules sage.symbolic ('a', 'b', 'c', 'd') - sage: Q4.arguments() # optional - sage.modules + sage: Q4.arguments() # optional - sage.modules sage.symbolic (a, b, c, d) TESTS:: @@ -429,7 +429,7 @@ def _sympy_(self): sage: Evens = ConditionSet(ZZ, is_even); Evens { x ∈ Integer Ring : (x) } - sage: Evens._sympy_() # optional - sympy + sage: Evens._sympy_() # optional - sage.symbolic sympy SageSet({ x ∈ Integer Ring : (x) }) """ from sage.interfaces.sympy import sympy_init diff --git a/src/sage/sets/real_set.py b/src/sage/sets/real_set.py index b4e1d5ca266..d341d09eba9 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -464,17 +464,17 @@ def _sympy_(self): EXAMPLES:: - sage: RealSet.open_closed(0, 1)[0]._sympy_() + sage: RealSet.open_closed(0, 1)[0]._sympy_() # optional - sympy Interval.Lopen(0, 1) - sage: RealSet.point(0)[0]._sympy_() # random - this output format is sympy >= 1.9 + sage: RealSet.point(0)[0]._sympy_() # random - this output format is sympy >= 1.9 # optional - sympy {0} - sage: type(_) + sage: type(_) # optional - sympy - sage: RealSet.open(0,1)[0]._sympy_() + sage: RealSet.open(0,1)[0]._sympy_() # optional - sympy Interval.open(0, 1) - sage: RealSet.open(-oo,1)[0]._sympy_() + sage: RealSet.open(-oo,1)[0]._sympy_() # optional - sympy Interval.open(-oo, 1) - sage: RealSet.open(0, oo)[0]._sympy_() + sage: RealSet.open(0, oo)[0]._sympy_() # optional - sympy Interval.open(0, oo) """ from sympy import Interval @@ -2107,7 +2107,8 @@ def union(self, *real_set_collection): (-oo, +oo) sage: s = RealSet().union([1, 2], (2, 3)); s [1, 3) - sage: RealSet().union((-oo, 0), x > 6, s[0], RealSet.point(5.0), RealSet.closed_open(2, 4)) + sage: RealSet().union((-oo, 0), x > 6, s[0], # optional - sage.symbolic + ....: RealSet.point(5.0), RealSet.closed_open(2, 4)) (-oo, 0) ∪ [1, 4) ∪ {5} ∪ (6, +oo) """ sets = [self] diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 875ab3765f7..943efee47be 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -1669,12 +1669,12 @@ def __contains__(self, x): Any specific floating-point number in Sage is to finite precision, hence it is rational:: - sage: RR(sqrt(2)) in X + sage: RR(sqrt(2)) in X # optional - sage.symbolic True Real constants are not rational:: - sage: pi in X + sage: pi in X # optional - sage.symbolic False """ return x in self._X and x in self._Y @@ -1837,9 +1837,9 @@ def __contains__(self, x): False sage: ComplexField().0 in X False - sage: sqrt(2) in X # since sqrt(2) is not a numerical approx + sage: sqrt(2) in X # since sqrt(2) is not a numerical approx # optional - sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx # optional - sage.symbolic True sage: 5/2 in X True @@ -2010,7 +2010,7 @@ def __contains__(self, x): True sage: ComplexField().0 in X False - sage: sqrt(2) in X # since sqrt(2) is currently symbolic + sage: sqrt(2) in X # since sqrt(2) is currently symbolic # optional - sage.symbolic False sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated True From 370ae890f73e4a105e53d776055037dbfca0cbba Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 27 May 2023 20:18:26 -0700 Subject: [PATCH 19/37] Add # optional --- src/sage/sets/disjoint_set.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/sets/disjoint_set.pyx b/src/sage/sets/disjoint_set.pyx index 0dc2f93c20b..602bcdd3aa4 100644 --- a/src/sage/sets/disjoint_set.pyx +++ b/src/sage/sets/disjoint_set.pyx @@ -561,7 +561,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d.union(4,1) sage: e = d.element_to_root_dict(); e {0: 0, 1: 4, 2: 2, 3: 2, 4: 4} - sage: WordMorphism(e) + sage: WordMorphism(e) # optional - sage.combinat WordMorphism: 0->0, 1->4, 2->2, 3->2, 4->4 """ d = {} @@ -849,7 +849,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: e = d.element_to_root_dict() sage: sorted(e.items()) [(0, 0), (1, 4), (2, 2), (3, 2), (4, 4)] - sage: WordMorphism(e) + sage: WordMorphism(e) # optional - sage.combinat WordMorphism: 0->0, 1->4, 2->2, 3->2, 4->4 """ d = {} From 05a77d9b43ec21ba29aace9ab3020207ce703840 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 31 May 2023 14:51:31 -0700 Subject: [PATCH 20/37] src/sage/sets/disjoint_set.pyx: Add # optional --- src/sage/sets/disjoint_set.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sage/sets/disjoint_set.pyx b/src/sage/sets/disjoint_set.pyx index 602bcdd3aa4..5b291c9eb97 100644 --- a/src/sage/sets/disjoint_set.pyx +++ b/src/sage/sets/disjoint_set.pyx @@ -583,9 +583,9 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d.union(3,4) sage: d {{0}, {1, 2, 3, 4}} - sage: g = d.to_digraph(); g + sage: g = d.to_digraph(); g # optional - sage.graphs Looped digraph on 5 vertices - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [(0, 0, None), (1, 2, None), (2, 2, None), (3, 2, None), (4, 2, None)] The result depends on the ordering of the union:: @@ -596,7 +596,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d.union(1,4) sage: d {{0}, {1, 2, 3, 4}} - sage: d.to_digraph().edges(sort=True) + sage: d.to_digraph().edges(sort=True) # optional - sage.graphs [(0, 0, None), (1, 1, None), (2, 1, None), (3, 1, None), (4, 1, None)] """ d = {i: [self._nodes.parent[i]] for i in range(self.cardinality())} @@ -870,7 +870,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: d.union(3,4) sage: d {{0}, {1, 2, 3, 4}} - sage: g = d.to_digraph(); g + sage: g = d.to_digraph(); g # optional - sage.graphs Looped digraph on 5 vertices sage: g.edges(sort=True) [(0, 0, None), (1, 2, None), (2, 2, None), (3, 2, None), (4, 2, None)] @@ -883,7 +883,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: d.union(1,4) sage: d {{0}, {1, 2, 3, 4}} - sage: d.to_digraph().edges(sort=True) + sage: d.to_digraph().edges(sort=True) # optional - sage.graphs [(0, 0, None), (1, 1, None), (2, 1, None), (3, 1, None), (4, 1, None)] """ d = {} From d8c5aa6d450d2c9d2ce457298ea28c0337c0a774 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 31 May 2023 23:18:40 -0700 Subject: [PATCH 21/37] sage.sets: More # optional --- src/sage/sets/disjoint_set.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/sets/disjoint_set.pyx b/src/sage/sets/disjoint_set.pyx index 5b291c9eb97..edaf98ad5ae 100644 --- a/src/sage/sets/disjoint_set.pyx +++ b/src/sage/sets/disjoint_set.pyx @@ -872,7 +872,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): {{0}, {1, 2, 3, 4}} sage: g = d.to_digraph(); g # optional - sage.graphs Looped digraph on 5 vertices - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [(0, 0, None), (1, 2, None), (2, 2, None), (3, 2, None), (4, 2, None)] The result depends on the ordering of the union:: From dd5bc38005e3dc11b8910b01973a21063308ab9f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 9 Jun 2023 00:55:41 -0700 Subject: [PATCH 22/37] More # optional --- src/sage/sets/real_set.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/sets/real_set.py b/src/sage/sets/real_set.py index d341d09eba9..ec57b00236f 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.rings.real_mpfr """ Subsets of the Real Line From f8ad1e3fc6fde900f305953e1ef08456fc5f1508 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 17:49:30 -0700 Subject: [PATCH 23/37] More # optional --- .../sets/disjoint_union_enumerated_sets.py | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/sage/sets/disjoint_union_enumerated_sets.py b/src/sage/sets/disjoint_union_enumerated_sets.py index 5ad8546c99b..aa51ebe7fd0 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -277,8 +277,8 @@ def __init__(self, family, facade=True, keepkey=False, category=None): ....: 2: FiniteEnumeratedSet([4,5,6])}) sage: TestSuite(U).run() - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat - sage: TestSuite(X).run() # optional - sage.combinat + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat sage.libs.flint + sage: TestSuite(X).run() # optional - sage.combinat sage.libs.flint """ self._family = family self._facade = facade @@ -471,14 +471,14 @@ def _element_constructor_(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint ....: Family([1,2,3], Partitions), facade=False) - sage: U._element_constructor_ # optional - sage.combinat + sage: U._element_constructor_ # optional - sage.combinat sage.libs.flint - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint ....: Family([1,2,3], Partitions), facade=True) - sage: U._element_constructor_ # optional - sage.combinat + sage: U._element_constructor_ # optional - sage.combinat sage.libs.flint """ @@ -491,13 +491,13 @@ def _element_constructor_default(self, el): r""" TESTS:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint ....: Family([1,2,3], Partitions), facade=False) - sage: U([1]) # indirect doctest # optional - sage.combinat + sage: U([1]) # indirect doctest # optional - sage.combinat sage.libs.flint [1] - sage: U([2,1]) # indirect doctest # optional - sage.combinat + sage: U([2,1]) # indirect doctest # optional - sage.combinat sage.libs.flint [2, 1] - sage: U([1,3,2]) # indirect doctest # optional - sage.combinat + sage: U([1,3,2]) # indirect doctest # optional - sage.combinat sage.libs.flint Traceback (most recent call last): ... ValueError: value [1, 3, 2] does not belong to Disjoint union of @@ -505,13 +505,13 @@ def _element_constructor_default(self, el): 2: Partitions of the integer 2, 3: Partitions of the integer 3} - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint ....: Family([1,2,3], Partitions), keepkey=True, facade=False) - sage: U((1, [1])) # indirect doctest # optional - sage.combinat + sage: U((1, [1])) # indirect doctest # optional - sage.combinat sage.libs.flint (1, [1]) - sage: U((3,[2,1])) # indirect doctest # optional - sage.combinat + sage: U((3,[2,1])) # indirect doctest # optional - sage.combinat sage.libs.flint (3, [2, 1]) - sage: U((4,[2,1])) # indirect doctest # optional - sage.combinat + sage: U((4,[2,1])) # indirect doctest # optional - sage.combinat sage.libs.flint Traceback (most recent call last): ... ValueError: value (4, [2, 1]) does not belong to Disjoint union of @@ -530,12 +530,13 @@ def _element_constructor_facade(self, el): """ TESTS:: - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat - sage: X([1]).parent() # optional - sage.combinat + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) # optional - sage.combinat sage.libs.flint + ....: for i in range(5)}) + sage: X([1]).parent() # optional - sage.combinat sage.libs.flint Partitions of the integer 1 - sage: X([2,1,1]).parent() # indirect doctest # optional - sage.combinat + sage: X([2,1,1]).parent() # indirect doctest # optional - sage.combinat sage.libs.flint Partitions of the integer 4 - sage: X([6]) # optional - sage.combinat + sage: X([6]) # optional - sage.combinat sage.libs.flint Traceback (most recent call last): ... ValueError: cannot coerce `[6]` in any parent in `Finite family {...}` @@ -544,23 +545,24 @@ def _element_constructor_facade(self, el): because this returns a `tuple`, where the coercion framework requires an :class:`Element` be returned. - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}, # optional - sage.combinat + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) # optional - sage.combinat sage.libs.flint + ....: for i in range(5)}, ....: keepkey=True) - sage: p = X._element_constructor_((0, [])) # indirect doctest # optional - sage.combinat - sage: p[1].parent() # optional - sage.combinat + sage: p = X._element_constructor_((0, [])) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: p[1].parent() # optional - sage.combinat sage.libs.flint Partitions of the integer 0 Test that facade parents can create and properly access elements that are tuples (fixed by :trac:`22382`):: - sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), # optional - sage.combinat + sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), # optional - sage.combinat sage.libs.flint ....: mu.standard_tableaux()]) - sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) # optional - sage.combinat - sage: s = StandardTableau([[1,3],[2,4]]) # optional - sage.combinat - sage: (s,s) in tabs # optional - sage.combinat + sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) # optional - sage.combinat sage.libs.flint + sage: s = StandardTableau([[1,3],[2,4]]) # optional - sage.combinat sage.libs.flint + sage: (s,s) in tabs # optional - sage.combinat sage.libs.flint True - sage: ss = tabs( (s,s) ) # optional - sage.combinat - sage: ss[0] # optional - sage.combinat + sage: ss = tabs( (s,s) ) # optional - sage.combinat sage.libs.flint + sage: ss[0] # optional - sage.combinat sage.libs.flint [[1, 3], [2, 4]] We do not coerce when one of the elements is already in the set:: @@ -596,16 +598,17 @@ def Element(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint ....: Family([1,2,3], Partitions), facade=False) - sage: U.Element # optional - sage.combinat + sage: U.Element # optional - sage.combinat sage.libs.flint <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint ....: Family([1,2,3], Partitions), facade=True) - sage: U.Element # optional - sage.combinat + sage: U.Element # optional - sage.combinat sage.libs.flint Traceback (most recent call last): ... - AttributeError: 'DisjointUnionEnumeratedSets_with_category' object has no attribute 'Element' + AttributeError: 'DisjointUnionEnumeratedSets_with_category' object + has no attribute 'Element' """ if not self._facade: return ElementWrapper From 5cf167b0c8b5db016664c2306255e6d7e17439f7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 11 Jun 2023 23:47:37 -0700 Subject: [PATCH 24/37] More # optional --- src/sage/sets/set.py | 4 ++-- src/sage/sets/set_from_iterator.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 943efee47be..8ad86411222 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -800,10 +800,10 @@ def subsets_lattice(self): EXAMPLES:: sage: X = Set([1,2,3]) - sage: X.subsets_lattice() # optional - sage.combinat + sage: X.subsets_lattice() # optional - sage.combinat sage.graphs sage.modules Finite lattice containing 8 elements sage: Y = Set() - sage: Y.subsets_lattice() # optional - sage.combinat + sage: Y.subsets_lattice() # optional - sage.combinat sage.graphs sage.modules Finite lattice containing 1 elements """ diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index fc1a8f5dc1a..0c7e4f35aa4 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -526,8 +526,8 @@ def _sage_argspec_(self): sage: from sage.misc.sageinspect import sage_getargspec sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = find_local_minimum - sage: sage_getargspec(d) # indirect doctest + sage: d.f = find_local_minimum # optional - scipy + sage: sage_getargspec(d) # indirect doctest # optional - scipy FullArgSpec(args=['f', 'a', 'b', 'tol', 'maxfun'], varargs=None, varkw=None, defaults=(1.48e-08, 500), kwonlyargs=[], kwonlydefaults=None, annotations={}) From 3d0d2f1161011cf6909aee39cfcb6560ef54da40 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 15 Jun 2023 21:40:28 -0700 Subject: [PATCH 25/37] sage.sets: More # optional --- src/sage/sets/cartesian_product.py | 12 ++++++------ src/sage/sets/set.py | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index dac1cef42c0..e4c15f778bd 100644 --- a/src/sage/sets/cartesian_product.py +++ b/src/sage/sets/cartesian_product.py @@ -354,9 +354,9 @@ def __len__(self): EXAMPLES:: - sage: C = cartesian_product([ZZ, QQ, CC]) - sage: e = C.random_element() - sage: len(e) + sage: C = cartesian_product([ZZ, QQ, CC]) # optional - sage.rings.real_mpfr + sage: e = C.random_element() # optional - sage.rings.real_mpfr + sage: len(e) # optional - sage.rings.real_mpfr 3 """ return len(self.value) @@ -367,10 +367,10 @@ def cartesian_factors(self): EXAMPLES:: - sage: A = cartesian_product([ZZ, RR]) - sage: A((1, 1.23)).cartesian_factors() + sage: A = cartesian_product([ZZ, RR]) # optional - sage.rings.real_mpfr + sage: A((1, 1.23)).cartesian_factors() # optional - sage.rings.real_mpfr (1, 1.23000000000000) - sage: type(_) + sage: type(_) # optional - sage.rings.real_mpfr <... 'tuple'> """ return self.value diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 8ad86411222..fe5f97d9133 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -1663,13 +1663,13 @@ def __contains__(self, x): sage: X = Set(QQ).intersection(Set(RR)) sage: 5 in X True - sage: ComplexField().0 in X + sage: ComplexField().0 in X # optional - sage.rings.real_mpfr False Any specific floating-point number in Sage is to finite precision, hence it is rational:: - sage: RR(sqrt(2)) in X # optional - sage.symbolic + sage: RR(sqrt(2)) in X # optional - sage.rings.real_mpfr sage.symbolic True Real constants are not rational:: @@ -1835,11 +1835,11 @@ def __contains__(self, x): sage: X = Set(QQ).difference(Set(ZZ)) sage: 5 in X False - sage: ComplexField().0 in X + sage: ComplexField().0 in X # optional - sage.rings.real_mpfr False sage: sqrt(2) in X # since sqrt(2) is not a numerical approx # optional - sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx # optional - sage.symbolic + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx # optional - sage.rings.real_mpfr sage.symbolic True sage: 5/2 in X True @@ -2008,13 +2008,13 @@ def __contains__(self, x): sage: X = Set(QQ).symmetric_difference(Primes()) sage: 4 in X True - sage: ComplexField().0 in X + sage: ComplexField().0 in X # optional - sage.rings.real_mpfr False sage: sqrt(2) in X # since sqrt(2) is currently symbolic # optional - sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated # optional - sage.rings.real_mpfr True - sage: pi in X + sage: pi in X # optional - sage.symbolic False sage: 5/2 in X True From 5918b0bd6c79be399587885bffd84a0e83fc2332 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 27 Jun 2023 09:35:21 -0700 Subject: [PATCH 26/37] sage.sets: Remove '# optional - sage.rings.finite_rings' that are now unnecessary --- src/sage/sets/cartesian_product.py | 24 ++++----- src/sage/sets/set.py | 82 +++++++++++++++--------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index e4c15f778bd..87157bc9256 100644 --- a/src/sage/sets/cartesian_product.py +++ b/src/sage/sets/cartesian_product.py @@ -37,14 +37,14 @@ class CartesianProduct(UniqueRepresentation, Parent): EXAMPLES:: - sage: G = cartesian_product([GF(5), Permutations(10)]) # optional - sage.libs.pari - sage: G.cartesian_factors() # optional - sage.libs.pari + sage: G = cartesian_product([GF(5), Permutations(10)]) + sage: G.cartesian_factors() (Finite Field of size 5, Standard permutations of 10) - sage: G.cardinality() # optional - sage.libs.pari + sage: G.cardinality() 18144000 - sage: G.random_element() # random # optional - sage.libs.pari + sage: G.random_element() (1, [4, 7, 6, 5, 10, 1, 3, 2, 8, 9]) - sage: G.category() # optional - sage.libs.pari + sage: G.category() Join of Category of finite monoids and Category of Cartesian products of monoids and Category of Cartesian products of finite enumerated sets @@ -93,24 +93,24 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: C = cartesian_product([GF(5), GF(3)]) # optional - sage.libs.pari - sage: x = C((1,3)); x # optional - sage.libs.pari + sage: C = cartesian_product([GF(5), GF(3)]) + sage: x = C((1,3)); x (1, 0) - sage: x.parent() # optional - sage.libs.pari + sage: x.parent() The Cartesian product of (Finite Field of size 5, Finite Field of size 3) - sage: x[0].parent() # optional - sage.libs.pari + sage: x[0].parent() Finite Field of size 5 - sage: x[1].parent() # optional - sage.libs.pari + sage: x[1].parent() Finite Field of size 3 An iterable is also accepted as input:: - sage: C(i for i in range(2)) # optional - sage.libs.pari + sage: C(i for i in range(2)) (0, 1) TESTS:: - sage: C((1,3,4)) # optional - sage.libs.pari + sage: C((1,3,4)) Traceback (most recent call last): ... ValueError: (1, 3, 4) should be of length 2 diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index fe5f97d9133..11a99a33a7e 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -227,11 +227,11 @@ def union(self, X): Set-theoretic union of Set of elements of Rational Field and Set of elements of Integer Ring - sage: X = Set(QQ).union(Set(GF(3))); X # optional - sage.libs.pari + sage: X = Set(QQ).union(Set(GF(3))); X Set-theoretic union of Set of elements of Rational Field and {0, 1, 2} - sage: 2/3 in X # optional - sage.libs.pari + sage: 2/3 in X True sage: GF(3)(2) in X # optional - sage.libs.pari True @@ -445,14 +445,14 @@ class Set_object(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_opera EXAMPLES:: - sage: K = GF(19) # optional - sage.libs.pari - sage: Set(K) # optional - sage.libs.pari + sage: K = GF(19) + sage: Set(K) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18} - sage: S = Set(K) # optional - sage.libs.pari + sage: S = Set(K) - sage: latex(S) # optional - sage.libs.pari + sage: latex(S) \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\} - sage: TestSuite(S).run() # optional - sage.libs.pari + sage: TestSuite(S).run() sage: latex(Set(ZZ)) \Bold{Z} @@ -622,12 +622,12 @@ def __contains__(self, x): Finite fields better illustrate the difference between ``__contains__`` for objects and their underlying sets:: - sage: X = Set(GF(7)) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: X = Set(GF(7)) + sage: X {0, 1, 2, 3, 4, 5, 6} - sage: 5/3 in X # optional - sage.libs.pari + sage: 5/3 in X False - sage: 5/3 in GF(7) # optional - sage.libs.pari + sage: 5/3 in GF(7) False sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) # optional - sage.libs.pari [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6] @@ -675,7 +675,7 @@ def cardinality(self): +Infinity sage: Primes().cardinality() +Infinity - sage: Set(GF(5)).cardinality() # optional - sage.libs.pari + sage: Set(GF(5)).cardinality() 5 sage: Set(GF(5^2,'a')).cardinality() # optional - sage.libs.pari 25 @@ -785,9 +785,9 @@ def subsets(self, size=None): EXAMPLES:: sage: X = Set([1, 2, 3]) - sage: list(X.subsets()) # optional - sage.combinat + sage: list(X.subsets()) [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] - sage: list(X.subsets(2)) # optional - sage.combinat + sage: list(X.subsets(2)) [{1, 2}, {1, 3}, {2, 3}] """ from sage.combinat.subset import Subsets @@ -857,13 +857,13 @@ def __init__(self, X, category=None): EXAMPLES:: - sage: S = Set(GF(19)); S # optional - sage.libs.pari + sage: S = Set(GF(19)); S {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18} - sage: S.category() # optional - sage.libs.pari + sage: S.category() Category of finite enumerated sets - sage: print(latex(S)) # optional - sage.libs.pari + sage: print(latex(S)) \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\} - sage: TestSuite(S).run() # optional - sage.libs.pari + sage: TestSuite(S).run() """ Set_object.__init__(self, X, category=FiniteEnumeratedSets().or_subcategory(category)) @@ -888,7 +888,7 @@ def is_finite(self): EXAMPLES:: - sage: Set(GF(19)).is_finite() # optional - sage.libs.pari + sage: Set(GF(19)).is_finite() True """ return True @@ -920,15 +920,15 @@ def __iter__(self): EXAMPLES:: - sage: S = Set(GF(19)) # optional - sage.libs.pari - sage: I = iter(S) # optional - sage.libs.pari - sage: next(I) # optional - sage.libs.pari + sage: S = Set(GF(19)) + sage: I = iter(S) + sage: next(I) 0 - sage: next(I) # optional - sage.libs.pari + sage: next(I) 1 - sage: next(I) # optional - sage.libs.pari + sage: next(I) 2 - sage: next(I) # optional - sage.libs.pari + sage: next(I) 3 """ return iter(self.set()) @@ -939,8 +939,8 @@ def _latex_(self): EXAMPLES:: - sage: S = Set(GF(2)) # optional - sage.libs.pari - sage: latex(S) # optional - sage.libs.pari + sage: S = Set(GF(2)) + sage: latex(S) \left\{0, 1\right\} """ return '\\left\\{' + ', '.join(latex(x) for x in self.set()) + '\\right\\}' @@ -951,8 +951,8 @@ def _repr_(self): EXAMPLES:: - sage: S = Set(GF(2)) # optional - sage.libs.pari - sage: S # optional - sage.libs.pari + sage: S = Set(GF(2)) + sage: S {0, 1} TESTS:: @@ -1105,7 +1105,7 @@ def issubset(self, other): TESTS:: - sage: len([Z for Z in Y.subsets() if Z.issubset(X)]) # optional - sage.combinat + sage: len([Z for Z in Y.subsets() if Z.issubset(X)]) 8 """ if not isinstance(other, Set_object_enumerated): @@ -1133,7 +1133,7 @@ def issuperset(self, other): TESTS:: - sage: len([Z for Z in Y.subsets() if Z.issuperset(X)]) # optional - sage.combinat + sage: len([Z for Z in Y.subsets() if Z.issuperset(X)]) 4 """ if not isinstance(other, Set_object_enumerated): @@ -1323,7 +1323,7 @@ def _repr_(self): EXAMPLES:: - sage: Set(ZZ).union(Set(GF(5))) # optional - sage.libs.pari + sage: Set(ZZ).union(Set(GF(5))) Set-theoretic union of Set of elements of Integer Ring and {0, 1, 2, 3, 4} """ return "Set-theoretic {} of {} and {}".format(self._op, self._X, self._Y) @@ -1334,7 +1334,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Set(ZZ).union(Set(GF(5)))) # optional - sage.libs.pari + sage: latex(Set(ZZ).union(Set(GF(5)))) \Bold{Z} \cup \left\{0, 1, 2, 3, 4\right\} """ return latex(self._X) + self._latex_op + latex(self._Y) @@ -1348,9 +1348,9 @@ def __hash__(self): The hash values of equal sets are in general not equal since it is not decidable whether two sets are equal:: - sage: X = Set(GF(13)).intersection(Set(ZZ)) # optional - sage.libs.pari - sage: Y = Set(ZZ).intersection(Set(GF(13))) # optional - sage.libs.pari - sage: hash(X) == hash(Y) # optional - sage.libs.pari + sage: X = Set(GF(13)).intersection(Set(ZZ)) + sage: Y = Set(ZZ).intersection(Set(GF(13))) + sage: hash(X) == hash(Y) False TESTS: @@ -1494,8 +1494,8 @@ def cardinality(self): sage: X.cardinality() # optional - sage.libs.pari 5 - sage: X = Set(GF(3)).union(Set(ZZ)) # optional - sage.libs.pari - sage: X.cardinality() # optional - sage.libs.pari + sage: X = Set(GF(3)).union(Set(ZZ)) + sage: X.cardinality() +Infinity """ return self._X.cardinality() + self._Y.cardinality() @@ -1528,9 +1528,9 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) # optional - sage.modules - sage: T = Set(ZZ) # optional - sage.modules - sage: X = S.intersection(T); X # optional - sage.modules + sage: S = Set(QQ^2) # optional - sage.modules + sage: T = Set(ZZ) + sage: X = S.intersection(T); X # optional - sage.modules Set-theoretic intersection of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring From fbd72eb35aea08f7059d2265a882a8e3f712308e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 27 Jun 2023 13:54:02 -0700 Subject: [PATCH 27/37] src/sage/sets/cartesian_product.py: Restore # random --- src/sage/sets/cartesian_product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index 87157bc9256..0afdd88ef1a 100644 --- a/src/sage/sets/cartesian_product.py +++ b/src/sage/sets/cartesian_product.py @@ -42,7 +42,7 @@ class CartesianProduct(UniqueRepresentation, Parent): (Finite Field of size 5, Standard permutations of 10) sage: G.cardinality() 18144000 - sage: G.random_element() + sage: G.random_element() # random (1, [4, 7, 6, 5, 10, 1, 3, 2, 8, 9]) sage: G.category() Join of Category of finite monoids From cff77b01e1b7f05e38bb0ea7f92d047d155fae35 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 1 Jul 2023 15:42:59 -0700 Subject: [PATCH 28/37] Update # optional / # needs --- src/sage/sets/recursively_enumerated_set.pyx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/sage/sets/recursively_enumerated_set.pyx b/src/sage/sets/recursively_enumerated_set.pyx index 50bcd6ad9fb..094b1d852de 100644 --- a/src/sage/sets/recursively_enumerated_set.pyx +++ b/src/sage/sets/recursively_enumerated_set.pyx @@ -394,9 +394,10 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, A recursive set given by a graded relation:: - sage: f = lambda a: [a+1, a+I] - sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') - sage: C + sage: # optional - sage.symbolic + sage: def f(a): + ....: return [a + 1, a + I] + sage: C = RecursivelyEnumeratedSet([0], f, structure='graded'); C A recursively enumerated set with a graded structure (breadth first search) sage: it = iter(C) sage: [next(it) for _ in range(7)] @@ -1125,7 +1126,9 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Gaussian integers:: - sage: f = lambda a: [a+1, a+I] + sage: # optional - sage.symbolic + sage: def f(a): + ....: return [a + 1, a + I] sage: S = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: it = S.graded_component_iterator() sage: [sorted(next(it)) for _ in range(7)] @@ -1142,6 +1145,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Note that interrupting the computation (``KeyboardInterrupt`` for instance) breaks the iterator:: + sage: # optional - sage.symbolic sage: def f(a): ....: sleep(0.05r) ....: return [a-1,a+1] @@ -1411,7 +1415,9 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a+1, a+I] + sage: # optional - sage.symbolic + sage: def f(a): + ....: return [a + 1, a + I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') sage: for i in range(5): sorted(C.graded_component(i)) [0] @@ -1424,6 +1430,7 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): We make sure that :trac:`21312` is fixed:: + sage: # optional - sage.symbolic sage: def f(a): ....: sleep(0.1r) ....: return [a+1, a+I] From dccc19f9ad53a106d372309fbcc5d926cb4072a6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 01:06:19 -0700 Subject: [PATCH 29/37] Update # optional / # needs --- src/sage/sets/disjoint_set.pyx | 2 +- src/sage/sets/integer_range.py | 2 +- src/sage/sets/set.py | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/sage/sets/disjoint_set.pyx b/src/sage/sets/disjoint_set.pyx index edaf98ad5ae..11a17542910 100644 --- a/src/sage/sets/disjoint_set.pyx +++ b/src/sage/sets/disjoint_set.pyx @@ -122,7 +122,7 @@ def DisjointSet(arg): or an iterable:: - sage: DisjointSet(4.3) + sage: DisjointSet(4.3) # optional - sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not iterable diff --git a/src/sage/sets/integer_range.py b/src/sage/sets/integer_range.py index 1eeb9681527..984b3edf045 100644 --- a/src/sage/sets/integer_range.py +++ b/src/sage/sets/integer_range.py @@ -217,7 +217,7 @@ def __classcall_private__(cls, begin, end=None, step=Integer(1), middle_point=No ValueError: IntegerRange() step argument must not be zero sage: IntegerRange(2) is IntegerRange(0, 2) True - sage: IntegerRange(1.0) + sage: IntegerRange(1.0) # optional - sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: end must be Integer or Infinity, not <... 'sage.rings.real_mpfr.RealLiteral'> diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 11a99a33a7e..cadbb7fe461 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -117,7 +117,8 @@ def Set(X=None, category=None): :: - sage: d={Set([2*I,1+I]):10} + sage: # needs sage.symbolic + sage: d = {Set([2*I, 1 + I]): 10} sage: d # key is randomly ordered {{I + 1, 2*I}: 10} sage: d[Set([1+I,2*I])] @@ -586,8 +587,8 @@ def _an_element_(self): EXAMPLES:: - sage: R = Set(RR) - sage: R.an_element() # indirect doctest + sage: R = Set(RR) # optional - sage.rings.real_mpfr + sage: R.an_element() # indirect doctest # optional - sage.rings.real_mpfr 1.00000000000000 sage: F = Set([1, 2, 3]) @@ -1185,8 +1186,8 @@ def difference(self, other): sage: X.difference(Y) {3, 4} sage: Z = Set(ZZ) - sage: W = Set([2.5, 4, 5, 6]) - sage: W.difference(Z) + sage: W = Set([2.5, 4, 5, 6]) # optional - sage.rings.real_mpfr + sage: W.difference(Z) # optional - sage.rings.real_mpfr {2.50000000000000} """ if not isinstance(other, Set_object_enumerated): From f752918b2af296151e25b1321e8d1cc240cad9b5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Sep 2023 11:42:30 -0700 Subject: [PATCH 30/37] ./sage -fixdoctests --distribution sagemath-categories --probe all --only-tags src/sage/sets --- src/sage/sets/cartesian_product.py | 12 +- src/sage/sets/condition_set.py | 113 +++++---- src/sage/sets/disjoint_set.pyx | 18 +- .../sets/disjoint_union_enumerated_sets.py | 187 +++++++------- src/sage/sets/family.py | 78 +++--- src/sage/sets/image_set.py | 74 +++--- src/sage/sets/integer_range.py | 2 +- src/sage/sets/non_negative_integers.py | 10 +- src/sage/sets/positive_integers.py | 2 +- src/sage/sets/primes.py | 14 +- src/sage/sets/real_set.py | 93 +++---- src/sage/sets/recursively_enumerated_set.pyx | 36 +-- src/sage/sets/set.py | 229 +++++++++--------- src/sage/sets/set_from_iterator.py | 143 +++++------ src/sage/sets/totally_ordered_finite_set.py | 4 +- 15 files changed, 535 insertions(+), 480 deletions(-) diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index 0afdd88ef1a..9d0bb024a12 100644 --- a/src/sage/sets/cartesian_product.py +++ b/src/sage/sets/cartesian_product.py @@ -354,9 +354,9 @@ def __len__(self): EXAMPLES:: - sage: C = cartesian_product([ZZ, QQ, CC]) # optional - sage.rings.real_mpfr - sage: e = C.random_element() # optional - sage.rings.real_mpfr - sage: len(e) # optional - sage.rings.real_mpfr + sage: C = cartesian_product([ZZ, QQ, CC]) # needs sage.rings.real_mpfr + sage: e = C.random_element() # needs sage.rings.real_mpfr + sage: len(e) # needs sage.rings.real_mpfr 3 """ return len(self.value) @@ -367,10 +367,10 @@ def cartesian_factors(self): EXAMPLES:: - sage: A = cartesian_product([ZZ, RR]) # optional - sage.rings.real_mpfr - sage: A((1, 1.23)).cartesian_factors() # optional - sage.rings.real_mpfr + sage: A = cartesian_product([ZZ, RR]) + sage: A((1, 1.23)).cartesian_factors() # needs sage.rings.real_mpfr (1, 1.23000000000000) - sage: type(_) # optional - sage.rings.real_mpfr + sage: type(_) <... 'tuple'> """ return self.value diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 18b88e2b809..ad8c2a8d512 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -62,11 +62,12 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope sage: 7/2 in EvensAndOdds False - sage: var('y') + sage: var('y') # needs sage.symbolic y - sage: SmallOdds = ConditionSet(ZZ, is_odd, abs(y) <= 11, vars=[y]); SmallOdds + sage: SmallOdds = ConditionSet(ZZ, is_odd, abs(y) <= 11, vars=[y]); SmallOdds # needs sage.symbolic { y ∈ Integer Ring : abs(y) <= 11, (y) } + sage: # needs sage.geometry.polyhedron sage: P = polytopes.cube(); P A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices sage: P.rename("P") @@ -74,16 +75,17 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope { x ∈ P : at 0x...>(x) } sage: vector([1, 0, 0]) in P_inter_B True - sage: vector([1, 1, 1]) in P_inter_B # optional - sage.geometry.polyhedron sage.symbolic + sage: vector([1, 1, 1]) in P_inter_B # needs sage.symbolic False + sage: # needs sage.symbolic sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 1.2; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 1.20000000000000 - sage: P_inter_B_again = ConditionSet(P, predicate); P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic + sage: P_inter_B_again = ConditionSet(P, predicate); P_inter_B_again # needs sage.geometry.polyhedron { (x, y, z) ∈ P : sqrt(x^2 + y^2 + z^2) < 1.20000000000000 } - sage: vector([1, 0, 0]) in P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic + sage: vector([1, 0, 0]) in P_inter_B_again # needs sage.geometry.polyhedron True - sage: vector([1, 1, 1]) in P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic + sage: vector([1, 1, 1]) in P_inter_B_again # needs sage.geometry.polyhedron False Iterating over subsets determined by predicates:: @@ -104,24 +106,25 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope Using ``ConditionSet`` without predicates provides a way of attaching variable names to a set:: - sage: Z3 = ConditionSet(ZZ^3, vars=['x', 'y', 'z']); Z3 # optional - sage.modules - { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring } - sage: Z3.variable_names() # optional - sage.modules + sage: Z3 = ConditionSet(ZZ^3, vars=['x', 'y', 'z']); Z3 # needs sage.modules + { (x, y, z) ∈ Ambient free module of rank 3 + over the principal ideal domain Integer Ring } + sage: Z3.variable_names() # needs sage.modules ('x', 'y', 'z') - sage: Z3.arguments() # optional - sage.modules sage.symbolic + sage: Z3.arguments() # needs sage.modules sage.symbolic (x, y, z) - sage: Q4. = ConditionSet(QQ^4); Q4 # optional - sage.modules sage.symbolic + sage: Q4. = ConditionSet(QQ^4); Q4 # needs sage.modules sage.symbolic { (a, b, c, d) ∈ Vector space of dimension 4 over Rational Field } - sage: Q4.variable_names() # optional - sage.modules sage.symbolic + sage: Q4.variable_names() # needs sage.modules sage.symbolic ('a', 'b', 'c', 'd') - sage: Q4.arguments() # optional - sage.modules sage.symbolic + sage: Q4.arguments() # needs sage.modules sage.symbolic (a, b, c, d) TESTS:: - sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas # optional - sage.geometry.polyhedron - sage: TestSuite(P_inter_B_again).run() # optional - sage.geometry.polyhedron sage.symbolic + sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas # needs sage.geometry.polyhedron + sage: TestSuite(P_inter_B_again).run() # needs sage.geometry.polyhedron sage.symbolic """ @staticmethod def __classcall_private__(cls, universe, *predicates, vars=None, names=None, category=None): @@ -130,9 +133,9 @@ def __classcall_private__(cls, universe, *predicates, vars=None, names=None, cat TESTS:: - sage: ConditionSet(ZZ, names=["x"]) is ConditionSet(ZZ, names=x) + sage: ConditionSet(ZZ, names=["x"]) is ConditionSet(ZZ, names=x) # needs sage.symbolic True - sage: ConditionSet(RR, x > 0, names=x) is ConditionSet(RR, (x > 0).function(x)) + sage: ConditionSet(RR, x > 0, names=x) is ConditionSet(RR, (x > 0).function(x)) # needs sage.symbolic True """ if category is None: @@ -224,10 +227,10 @@ def _repr_(self): EXAMPLES:: - sage: var('t') # parameter + sage: var('t') # parameter # needs sage.symbolic t - sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) - sage: ZeroDimButNotNullary._repr_() + sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) # needs sage.symbolic + sage: ZeroDimButNotNullary._repr_() # needs sage.symbolic '{ q ∈ Ambient free module of rank 0 over the principal ideal domain Integer Ring : t > 0 }' """ @@ -257,13 +260,13 @@ def _repr_condition(self, predicate): sage: Evens = ConditionSet(ZZ, is_even) sage: Evens._repr_condition(is_even) '(x)' - sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) - sage: BigSin._repr_condition(BigSin._predicates[0]) + sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) # needs sage.symbolic + sage: BigSin._repr_condition(BigSin._predicates[0]) # needs sage.symbolic 'sin(x) > 0.900000000000000' - sage: var('t') # parameter + sage: var('t') # parameter # needs sage.symbolic t - sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) - sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) + sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) # needs sage.symbolic + sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) # needs sage.symbolic 't > 0' """ if isinstance(predicate, Expression) and predicate.is_callable(): @@ -285,9 +288,9 @@ def arguments(self): sage: Odds = ConditionSet(ZZ, is_odd); Odds { x ∈ Integer Ring : (x) } - sage: args = Odds.arguments(); args + sage: args = Odds.arguments(); args # needs sage.symbolic (x,) - sage: args[0].parent() + sage: args[0].parent() # needs sage.symbolic Symbolic Ring """ from sage.symbolic.ring import SR @@ -339,24 +342,24 @@ def _call_predicate(self, predicate, element): TESTS:: - sage: TripleDigits = ZZ^3 - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate + sage: TripleDigits = ZZ^3 # needs sage.modules + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # needs sage.symbolic (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # needs sage.symbolic { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: predicate = SmallTriples._predicates[0] # optional - sage.symbolic - sage: element = TripleDigits((1, 2, 3)) # optional - sage.modules - sage: SmallTriples._call_predicate(predicate, element) # optional - sage.modules sage.symbolic + sage: predicate = SmallTriples._predicates[0] # needs sage.symbolic + sage: element = TripleDigits((1, 2, 3)) # needs sage.modules + sage: SmallTriples._call_predicate(predicate, element) # needs sage.modules sage.symbolic sqrt(14) < 12 - sage: var('t') + sage: var('t') # needs sage.symbolic t - sage: TinyUniverse = ZZ^0 # optional - sage.modules - sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) # optional - sage.modules sage.symbolic - sage: predicate = Nullary._predicates[0] # optional - sage.modules sage.symbolic - sage: element = TinyUniverse(0) # optional - sage.modules - sage: Nullary._call_predicate(predicate, element) # optional - sage.modules sage.symbolic + sage: TinyUniverse = ZZ^0 # needs sage.modules + sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) # needs sage.modules sage.symbolic + sage: predicate = Nullary._predicates[0] # needs sage.modules sage.symbolic + sage: element = TinyUniverse(0) # needs sage.modules + sage: Nullary._call_predicate(predicate, element) # needs sage.modules sage.symbolic t > 0 """ if isinstance(predicate, Expression) and predicate.is_callable(): @@ -372,13 +375,13 @@ def _an_element_(self): TESTS:: - sage: TripleDigits = ZZ^3 - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate + sage: TripleDigits = ZZ^3 # needs sage.modules + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # needs sage.symbolic (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # needs sage.symbolic { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: SmallTriples.an_element() # indirect doctest + sage: SmallTriples.an_element() # indirect doctest # needs sage.symbolic (1, 0, 0) """ for element in self._universe.some_elements(): @@ -406,6 +409,7 @@ def _sympy_(self): EXAMPLES:: + sage: # needs sage.symbolic sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples @@ -419,9 +423,9 @@ def _sympy_(self): sage: (5, 7, 9) in ST False - sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval # optional - sage.symbolic + sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval # needs sage.symbolic { x ∈ Real Field with 53 bits of precision : x >= -7, x <= 4 } - sage: Interval._sympy_() # optional - sage.symbolic sympy + sage: Interval._sympy_() # needs sympy sage.symbolic ConditionSet(x, (x >= -7) & (x <= 4), SageSet(Real Field with 53 bits of precision)) @@ -429,7 +433,7 @@ def _sympy_(self): sage: Evens = ConditionSet(ZZ, is_even); Evens { x ∈ Integer Ring : (x) } - sage: Evens._sympy_() # optional - sage.symbolic sympy + sage: Evens._sympy_() # needs sympy sage.symbolic SageSet({ x ∈ Integer Ring : (x) }) """ from sage.interfaces.sympy import sympy_init @@ -464,10 +468,12 @@ def intersection(self, X): EXAMPLES:: + sage: # needs sage.symbolic sage: in_small_oblong(x, y) = x^2 + 3 * y^2 <= 42 sage: SmallOblongUniverse = ConditionSet(QQ^2, in_small_oblong) sage: SmallOblongUniverse - { (x, y) ∈ Vector space of dimension 2 over Rational Field : x^2 + 3*y^2 <= 42 } + { (x, y) ∈ Vector space of dimension 2 + over Rational Field : x^2 + 3*y^2 <= 42 } sage: parity_check(x, y) = abs(sin(pi/2*(x + y))) < 1/1000 sage: EvenUniverse = ConditionSet(ZZ^2, parity_check); EvenUniverse { (x, y) ∈ Ambient free module of rank 2 over the principal ideal @@ -481,13 +487,18 @@ def intersection(self, X): Combining two ``ConditionSet``s with different formal variables works correctly. The formal variables of the intersection are taken from ``self``:: - sage: SmallMirrorUniverse = ConditionSet(QQ^2, in_small_oblong, vars=(y, x)) + sage: # needs sage.symbolic + sage: SmallMirrorUniverse = ConditionSet(QQ^2, in_small_oblong, + ....: vars=(y, x)) sage: SmallMirrorUniverse - { (y, x) ∈ Vector space of dimension 2 over Rational Field : 3*x^2 + y^2 <= 42 } + { (y, x) ∈ Vector space of dimension 2 + over Rational Field : 3*x^2 + y^2 <= 42 } sage: SmallOblongUniverse & SmallMirrorUniverse - { (x, y) ∈ Vector space of dimension 2 over Rational Field : x^2 + 3*y^2 <= 42 } + { (x, y) ∈ Vector space of dimension 2 + over Rational Field : x^2 + 3*y^2 <= 42 } sage: SmallMirrorUniverse & SmallOblongUniverse - { (y, x) ∈ Vector space of dimension 2 over Rational Field : 3*x^2 + y^2 <= 42 } + { (y, x) ∈ Vector space of dimension 2 + over Rational Field : 3*x^2 + y^2 <= 42 } """ if isinstance(X, ConditionSet): return ConditionSet(self.ambient().intersection(X.ambient()), diff --git a/src/sage/sets/disjoint_set.pyx b/src/sage/sets/disjoint_set.pyx index 11a17542910..4db91f4f058 100644 --- a/src/sage/sets/disjoint_set.pyx +++ b/src/sage/sets/disjoint_set.pyx @@ -122,7 +122,7 @@ def DisjointSet(arg): or an iterable:: - sage: DisjointSet(4.3) # optional - sage.rings.real_mpfr + sage: DisjointSet(4.3) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not iterable @@ -561,7 +561,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d.union(4,1) sage: e = d.element_to_root_dict(); e {0: 0, 1: 4, 2: 2, 3: 2, 4: 4} - sage: WordMorphism(e) # optional - sage.combinat + sage: WordMorphism(e) # needs sage.combinat WordMorphism: 0->0, 1->4, 2->2, 3->2, 4->4 """ d = {} @@ -583,9 +583,9 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d.union(3,4) sage: d {{0}, {1, 2, 3, 4}} - sage: g = d.to_digraph(); g # optional - sage.graphs + sage: g = d.to_digraph(); g # needs sage.graphs Looped digraph on 5 vertices - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(0, 0, None), (1, 2, None), (2, 2, None), (3, 2, None), (4, 2, None)] The result depends on the ordering of the union:: @@ -596,7 +596,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class): sage: d.union(1,4) sage: d {{0}, {1, 2, 3, 4}} - sage: d.to_digraph().edges(sort=True) # optional - sage.graphs + sage: d.to_digraph().edges(sort=True) # needs sage.graphs [(0, 0, None), (1, 1, None), (2, 1, None), (3, 1, None), (4, 1, None)] """ d = {i: [self._nodes.parent[i]] for i in range(self.cardinality())} @@ -849,7 +849,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: e = d.element_to_root_dict() sage: sorted(e.items()) [(0, 0), (1, 4), (2, 2), (3, 2), (4, 4)] - sage: WordMorphism(e) # optional - sage.combinat + sage: WordMorphism(e) # needs sage.combinat WordMorphism: 0->0, 1->4, 2->2, 3->2, 4->4 """ d = {} @@ -870,9 +870,9 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: d.union(3,4) sage: d {{0}, {1, 2, 3, 4}} - sage: g = d.to_digraph(); g # optional - sage.graphs + sage: g = d.to_digraph(); g # needs sage.graphs Looped digraph on 5 vertices - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(0, 0, None), (1, 2, None), (2, 2, None), (3, 2, None), (4, 2, None)] The result depends on the ordering of the union:: @@ -883,7 +883,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class): sage: d.union(1,4) sage: d {{0}, {1, 2, 3, 4}} - sage: d.to_digraph().edges(sort=True) # optional - sage.graphs + sage: d.to_digraph().edges(sort=True) # needs sage.graphs [(0, 0, None), (1, 1, None), (2, 1, None), (3, 1, None), (4, 1, None)] """ d = {} diff --git a/src/sage/sets/disjoint_union_enumerated_sets.py b/src/sage/sets/disjoint_union_enumerated_sets.py index aa51ebe7fd0..2375f4d191a 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -90,32 +90,34 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): In general the input can be any family:: - sage: U3 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: # needs sage.combinat + sage: U3 = DisjointUnionEnumeratedSets( ....: Family([2,3,4], Permutations, lazy=True)) - sage: U3 # optional - sage.combinat + sage: U3 Disjoint union of Lazy family ((i))_{i in [2, 3, 4]} - sage: U3.cardinality() # optional - sage.combinat + sage: U3.cardinality() 32 - sage: it = iter(U3) # optional - sage.combinat - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat + sage: it = iter(U3) + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] [[1, 2], [2, 1], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1]] - sage: U3.unrank(18) # optional - sage.combinat + sage: U3.unrank(18) [2, 4, 1, 3] This allows for infinite unions:: - sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: # needs sage.combinat + sage: U4 = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Permutations)) - sage: U4 # optional - sage.combinat + sage: U4 Disjoint union of Lazy family ((i))_{i in Non negative integers} - sage: U4.cardinality() # optional - sage.combinat + sage: U4.cardinality() +Infinity - sage: it = iter(U4) # optional - sage.combinat - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat + sage: it = iter(U4) + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: U4.unrank(18) # optional - sage.combinat + sage: U4.unrank(18) [2, 3, 1, 4] .. WARNING:: @@ -128,41 +130,43 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): We demonstrate the ``keepkey`` option:: - sage: Ukeep = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: # needs sage.combinat + sage: Ukeep = DisjointUnionEnumeratedSets( ....: Family(list(range(4)), Permutations), keepkey=True) - sage: it = iter(Ukeep) # optional - sage.combinat - sage: [next(it) for i in range(6)] # optional - sage.combinat + sage: it = iter(Ukeep) + sage: [next(it) for i in range(6)] [(0, []), (1, [1]), (2, [1, 2]), (2, [2, 1]), (3, [1, 2, 3]), (3, [1, 3, 2])] - sage: type(next(it)[1]) # optional - sage.combinat + sage: type(next(it)[1]) We now demonstrate the ``facade`` option:: - sage: UNoFacade = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: # needs sage.combinat + sage: UNoFacade = DisjointUnionEnumeratedSets( ....: Family(list(range(4)), Permutations), facade=False) - sage: it = iter(UNoFacade) # optional - sage.combinat - sage: [next(it) for i in range(6)] # optional - sage.combinat + sage: it = iter(UNoFacade) + sage: [next(it) for i in range(6)] [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: el = next(it); el # optional - sage.combinat + sage: el = next(it); el [2, 1, 3] - sage: type(el) # optional - sage.combinat + sage: type(el) <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: el.parent() == UNoFacade # optional - sage.combinat + sage: el.parent() == UNoFacade True - sage: elv = el.value; elv # optional - sage.combinat + sage: elv = el.value; elv [2, 1, 3] - sage: type(elv) # optional - sage.combinat + sage: type(elv) The elements ``el`` of the disjoint union are simple wrapped elements. So to access the methods, you need to do ``el.value``:: - sage: el[0] # optional - sage.combinat + sage: el[0] # needs sage.combinat Traceback (most recent call last): ... TypeError: 'sage.structure.element_wrapper.ElementWrapper' object is not subscriptable - sage: el.value[0] # optional - sage.combinat + sage: el.value[0] # needs sage.combinat 2 Possible extensions: the current enumeration order is not suitable @@ -184,12 +188,12 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): :class:`DisjointUnionEnumeratedSets`. Then, one simply writes the ``__init__`` method as usual:: - sage: class MyUnion(DisjointUnionEnumeratedSets): # optional - sage.combinat + sage: class MyUnion(DisjointUnionEnumeratedSets): ....: def __init__(self): ....: DisjointUnionEnumeratedSets.__init__(self, ....: Family([1,2], Permutations)) - sage: pp = MyUnion() # optional - sage.combinat - sage: pp.list() # optional - sage.combinat + sage: pp = MyUnion() + sage: pp.list() [[1], [1, 2], [2, 1]] In case the :meth:`__init__` method takes optional arguments, @@ -204,37 +208,37 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): sage: class UnionOfSpecialSets(DisjointUnionEnumeratedSets): ....: __classcall_private__ = staticmethod(DisjointUnionEnumeratedSets.__classcall_private__) - sage: psp = UnionOfSpecialSets(Family([1,2], Permutations)) # optional - sage.combinat - sage: psp.list() # optional - sage.combinat + sage: psp = UnionOfSpecialSets(Family([1,2], Permutations)) + sage: psp.list() [[1], [1, 2], [2, 1]] TESTS:: sage: TestSuite(U1).run() sage: TestSuite(U2).run() - sage: TestSuite(U3).run() # optional - sage.combinat - sage: TestSuite(U4).run() # optional - sage.combinat + sage: TestSuite(U3).run() # needs sage.combinat + sage: TestSuite(U4).run() # needs sage.combinat doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union The default implementation of __contains__ can loop forever. Please overload it. - sage: TestSuite(UNoFacade).run() # optional - sage.combinat + sage: TestSuite(UNoFacade).run() # needs sage.combinat We skip ``_test_an_element`` because the coercion framework does not currently allow a tuple to be returned for facade parents:: - sage: TestSuite(Ukeep).run(skip="_test_an_element") # optional - sage.combinat + sage: TestSuite(Ukeep).run(skip="_test_an_element") # needs sage.combinat The following three lines are required for the pickling tests, because the classes ``MyUnion`` and ``UnionOfSpecialSets`` have been defined interactively:: sage: import __main__ - sage: __main__.MyUnion = MyUnion # optional - sage.combinat + sage: __main__.MyUnion = MyUnion sage: __main__.UnionOfSpecialSets = UnionOfSpecialSets - sage: TestSuite(pp).run() # optional - sage.combinat - sage: TestSuite(psp).run() # optional - sage.combinat + sage: TestSuite(pp).run() + sage: TestSuite(psp).run() """ @@ -277,8 +281,8 @@ def __init__(self, family, facade=True, keepkey=False, category=None): ....: 2: FiniteEnumeratedSet([4,5,6])}) sage: TestSuite(U).run() - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat sage.libs.flint - sage: TestSuite(X).run() # optional - sage.combinat sage.libs.flint + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # needs sage.combinat sage.libs.flint + sage: TestSuite(X).run() # needs sage.combinat sage.libs.flint """ self._family = family self._facade = facade @@ -327,9 +331,9 @@ def _is_a(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U4 = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Compositions)) - sage: U4._is_a(Composition([3,2,1,1])) # optional - sage.combinat + sage: U4._is_a(Composition([3,2,1,1])) doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union @@ -358,9 +362,9 @@ def __contains__(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U4 = DisjointUnionEnumeratedSets( # needs sage.combinat ....: Family(NonNegativeIntegers(), Partitions)) - sage: Partition([]) in U4 # optional - sage.combinat + sage: Partition([]) in U4 # needs sage.combinat doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union @@ -370,7 +374,7 @@ def __contains__(self, x): Note: one has to use a different family from the previous one in this file otherwise the warning is not re-issued:: - sage: Partition([3,2,1,1]) in U4 # optional - sage.combinat + sage: Partition([3,2,1,1]) in U4 # needs sage.combinat True The following call will loop forever:: @@ -389,21 +393,22 @@ def __iter__(self): """ TESTS:: - sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U4 = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Permutations)) - sage: it = iter(U4) # optional - sage.combinat - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat + sage: it = iter(U4) + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: # needs sage.combinat + sage: U4 = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Permutations), ....: keepkey=True, facade=False) - sage: it = iter(U4) # optional - sage.combinat - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat + sage: it = iter(U4) + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] [(0, []), (1, [1]), (2, [1, 2]), (2, [2, 1]), (3, [1, 2, 3]), (3, [1, 3, 2])] - sage: el = next(it); el.parent() == U4 # optional - sage.combinat + sage: el = next(it); el.parent() == U4 True - sage: el.value == (3, Permutation([2,1,3])) # optional - sage.combinat + sage: el.value == (3, Permutation([2,1,3])) True """ for k in self._family.keys(): @@ -422,9 +427,9 @@ def an_element(self): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U4 = DisjointUnionEnumeratedSets( ....: Family([3, 5, 7], Permutations)) - sage: U4.an_element() # optional - sage.combinat + sage: U4.an_element() [1, 2, 3] """ return self._an_element_from_iterator() @@ -439,16 +444,16 @@ def cardinality(self): For finite disjoint unions, the cardinality is computed by summing the cardinalities of the enumerated sets:: - sage: U = DisjointUnionEnumeratedSets(Family([0,1,2,3], Permutations)) # optional - sage.combinat - sage: U.cardinality() # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets(Family([0,1,2,3], Permutations)) + sage: U.cardinality() 10 For infinite disjoint unions, this makes the assumption that the result is infinite:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat + sage: U = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Permutations)) - sage: U.cardinality() # optional - sage.combinat + sage: U.cardinality() +Infinity .. WARNING:: @@ -471,14 +476,15 @@ def _element_constructor_(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint + sage: # needs sage.combinat sage.libs.flint + sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=False) - sage: U._element_constructor_ # optional - sage.combinat sage.libs.flint + sage: U._element_constructor_ - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint + sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=True) - sage: U._element_constructor_ # optional - sage.combinat sage.libs.flint + sage: U._element_constructor_ """ @@ -491,13 +497,14 @@ def _element_constructor_default(self, el): r""" TESTS:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint + sage: # needs sage.combinat sage.libs.flint + sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=False) - sage: U([1]) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: U([1]) # indirect doctest [1] - sage: U([2,1]) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: U([2,1]) # indirect doctest [2, 1] - sage: U([1,3,2]) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: U([1,3,2]) # indirect doctest Traceback (most recent call last): ... ValueError: value [1, 3, 2] does not belong to Disjoint union of @@ -505,13 +512,14 @@ def _element_constructor_default(self, el): 2: Partitions of the integer 2, 3: Partitions of the integer 3} - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint + sage: # needs sage.combinat sage.libs.flint + sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), keepkey=True, facade=False) - sage: U((1, [1])) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: U((1, [1])) # indirect doctest (1, [1]) - sage: U((3,[2,1])) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: U((3,[2,1])) # indirect doctest (3, [2, 1]) - sage: U((4,[2,1])) # indirect doctest # optional - sage.combinat sage.libs.flint + sage: U((4,[2,1])) # indirect doctest Traceback (most recent call last): ... ValueError: value (4, [2, 1]) does not belong to Disjoint union of @@ -530,13 +538,14 @@ def _element_constructor_facade(self, el): """ TESTS:: - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) # optional - sage.combinat sage.libs.flint + sage: # needs sage.combinat sage.libs.flint + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) ....: for i in range(5)}) - sage: X([1]).parent() # optional - sage.combinat sage.libs.flint + sage: X([1]).parent() Partitions of the integer 1 - sage: X([2,1,1]).parent() # indirect doctest # optional - sage.combinat sage.libs.flint + sage: X([2,1,1]).parent() # indirect doctest Partitions of the integer 4 - sage: X([6]) # optional - sage.combinat sage.libs.flint + sage: X([6]) Traceback (most recent call last): ... ValueError: cannot coerce `[6]` in any parent in `Finite family {...}` @@ -545,24 +554,25 @@ def _element_constructor_facade(self, el): because this returns a `tuple`, where the coercion framework requires an :class:`Element` be returned. - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) # optional - sage.combinat sage.libs.flint + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) # needs sage.combinat sage.libs.flint ....: for i in range(5)}, ....: keepkey=True) - sage: p = X._element_constructor_((0, [])) # indirect doctest # optional - sage.combinat sage.libs.flint - sage: p[1].parent() # optional - sage.combinat sage.libs.flint + sage: p = X._element_constructor_((0, [])) # indirect doctest # needs sage.combinat sage.libs.flint + sage: p[1].parent() # needs sage.combinat sage.libs.flint Partitions of the integer 0 Test that facade parents can create and properly access elements that are tuples (fixed by :trac:`22382`):: - sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), # optional - sage.combinat sage.libs.flint + sage: # needs sage.combinat sage.libs.flint + sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), ....: mu.standard_tableaux()]) - sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) # optional - sage.combinat sage.libs.flint - sage: s = StandardTableau([[1,3],[2,4]]) # optional - sage.combinat sage.libs.flint - sage: (s,s) in tabs # optional - sage.combinat sage.libs.flint + sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) + sage: s = StandardTableau([[1,3],[2,4]]) + sage: (s,s) in tabs True - sage: ss = tabs( (s,s) ) # optional - sage.combinat sage.libs.flint - sage: ss[0] # optional - sage.combinat sage.libs.flint + sage: ss = tabs( (s,s) ) + sage: ss[0] [[1, 3], [2, 4]] We do not coerce when one of the elements is already in the set:: @@ -598,13 +608,14 @@ def Element(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint + sage: # needs sage.combinat sage.libs.flint + sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=False) - sage: U.Element # optional - sage.combinat sage.libs.flint + sage: U.Element <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat sage.libs.flint + sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=True) - sage: U.Element # optional - sage.combinat sage.libs.flint + sage: U.Element Traceback (most recent call last): ... AttributeError: 'DisjointUnionEnumeratedSets_with_category' object diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index 3e3676c2d03..6c007a96835 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -17,8 +17,8 @@ Check :trac:`12482` (shall be run in a fresh session):: - sage: P = Partitions(3) # optional - sage.combinat - sage: Family(P, lambda x: x).category() # optional - sage.combinat + sage: P = Partitions(3) # needs sage.combinat + sage: Family(P, lambda x: x).category() # needs sage.combinat Category of finite enumerated sets """ @@ -185,10 +185,10 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa Beware that for those kind of families len(f) is not supposed to work. As a replacement, use the .cardinality() method:: - sage: f = Family(Permutations(3), attrcall("to_lehmer_code")) # optional - sage.combinat - sage: list(f) # optional - sage.combinat + sage: f = Family(Permutations(3), attrcall("to_lehmer_code")) + sage: list(f) [[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0], [2, 0, 0], [2, 1, 0]] - sage: f.cardinality() # optional - sage.combinat + sage: f.cardinality() 6 Caveat: Only certain families with lazy behavior can be pickled. In @@ -196,14 +196,14 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa and unpickle_function (in sage.misc.fpickle) will correctly unpickle. The following two work:: - sage: f = Family(Permutations(3), lambda p: p.to_lehmer_code()); f # optional - sage.combinat + sage: f = Family(Permutations(3), lambda p: p.to_lehmer_code()); f Lazy family ((i))_{i in Standard permutations of 3} - sage: f == loads(dumps(f)) # optional - sage.combinat + sage: f == loads(dumps(f)) True - sage: f = Family(Permutations(3), attrcall("to_lehmer_code")); f # optional - sage.combinat + sage: f = Family(Permutations(3), attrcall("to_lehmer_code")); f Lazy family (i.to_lehmer_code())_{i in Standard permutations of 3} - sage: f == loads(dumps(f)) # optional - sage.combinat + sage: f == loads(dumps(f)) True But this one does not:: @@ -1056,7 +1056,7 @@ def _repr_(self): sage: f = LazyFamily([3,4,7], fun); f Lazy family (fun(i))_{i in [3, 4, 7]} - sage: f = Family(Permutations(3), attrcall("to_lehmer_code"), lazy=True); f # optional - sage.combinat + sage: f = Family(Permutations(3), attrcall("to_lehmer_code"), lazy=True); f Lazy family (i.to_lehmer_code())_{i in Standard permutations of 3} sage: f = LazyFamily([3,4,7], lambda i: 2*i); f @@ -1069,7 +1069,7 @@ def _repr_(self): Check that using a class as the function is correctly handled:: - sage: Family(NonNegativeIntegers(), PerfectMatchings) # optional - sage.combinat + sage: Family(NonNegativeIntegers(), PerfectMatchings) # needs sage.combinat Lazy family ((i))_{i in Non negative integers} """ if self.function_name is not None: @@ -1187,12 +1187,12 @@ def __getstate__(self): sage: d['set'] [3, 4, 7] - sage: f = LazyFamily(Permutations(3), lambda p: p.to_lehmer_code()) # optional - sage.combinat - sage: f == loads(dumps(f)) # optional - sage.combinat + sage: f = LazyFamily(Permutations(3), lambda p: p.to_lehmer_code()) + sage: f == loads(dumps(f)) True - sage: f = LazyFamily(Permutations(3), attrcall("to_lehmer_code")) # optional - sage.combinat - sage: f == loads(dumps(f)) # optional - sage.combinat + sage: f = LazyFamily(Permutations(3), attrcall("to_lehmer_code")) + sage: f == loads(dumps(f)) True """ f = self.function @@ -1417,8 +1417,8 @@ def __init__(self, enumset): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat - sage: TestSuite(f).run() # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(3)) + sage: TestSuite(f).run() sage: f = Family(NonNegativeIntegers()) sage: TestSuite(f).run() @@ -1428,12 +1428,12 @@ def __init__(self, enumset): Check that category and keys are set correctly (:trac:`28274`):: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(4)) # optional - sage.combinat - sage: f.category() # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(4)) + sage: f.category() Category of finite enumerated sets - sage: list(f.keys()) == list(range(f.cardinality())) # optional - sage.combinat + sage: list(f.keys()) == list(range(f.cardinality())) True - sage: Family(Permutations()).keys() # optional - sage.combinat + sage: Family(Permutations()).keys() Non negative integers sage: type(Family(NN)) @@ -1449,9 +1449,9 @@ def __eq__(self, other): """ EXAMPLES:: - sage: f = Family(Permutations(3)) # optional - sage.combinat - sage: g = Family(Permutations(3)) # optional - sage.combinat - sage: f == g # optional - sage.combinat + sage: f = Family(Permutations(3)) + sage: g = Family(Permutations(3)) + sage: f == g True """ return (isinstance(other, self.__class__) and @@ -1461,7 +1461,7 @@ def __repr__(self): """ EXAMPLES:: - sage: f = Family(Permutations(3)); f # indirect doctest # optional - sage.combinat + sage: f = Family(Permutations(3)); f # indirect doctest Family (Standard permutations of 3) sage: f = Family(NonNegativeIntegers()); f @@ -1476,8 +1476,8 @@ def __contains__(self, x): """ EXAMPLES:: - sage: f = Family(Permutations(3)) # optional - sage.combinat - sage: [2,1,3] in f # optional - sage.combinat + sage: f = Family(Permutations(3)) + sage: [2,1,3] in f True """ return x in self.enumset @@ -1489,8 +1489,8 @@ def cardinality(self): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat - sage: f.cardinality() # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(3)) + sage: f.cardinality() 6 sage: f = Family(NonNegativeIntegers()) @@ -1504,8 +1504,8 @@ def __iter__(self): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat - sage: [i for i in f] # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(3)) + sage: [i for i in f] [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ for i in self.enumset: @@ -1516,8 +1516,8 @@ def __getitem__(self, i): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat - sage: f[1] # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(3)) + sage: f[1] [1, 3, 2] """ return self.enumset.unrank(i) @@ -1527,10 +1527,10 @@ def __getstate__(self): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(3)) # optional - sage.combinat - sage: f.__getstate__() # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(3)) + sage: f.__getstate__() {'enumset': Standard permutations of 3} - sage: loads(dumps(f)) == f # optional - sage.combinat + sage: loads(dumps(f)) == f True """ return {'enumset': self.enumset} @@ -1540,9 +1540,9 @@ def __setstate__(self, state): EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily - sage: f = EnumeratedFamily(Permutations(0)) # optional - sage.combinat - sage: f.__setstate__({'enumset': Permutations(3)}) # optional - sage.combinat - sage: f # optional - sage.combinat + sage: f = EnumeratedFamily(Permutations(0)) + sage: f.__setstate__({'enumset': Permutations(3)}) + sage: f Family (Standard permutations of 3) """ self.__init__(state['enumset']) diff --git a/src/sage/sets/image_set.py b/src/sage/sets/image_set.py index 74a99c65641..4ad2d76a0a3 100644 --- a/src/sage/sets/image_set.py +++ b/src/sage/sets/image_set.py @@ -73,12 +73,12 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve EXAMPLES:: - sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) # optional - sage.modules + sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) # needs sage.modules sage: R. = QQ[] - sage: H = Hom(M, R, category=Sets()) # optional - sage.modules - sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) # optional - sage.modules - sage: Im = f.image() # optional - sage.modules - sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', # optional - sage.modules + sage: H = Hom(M, R, category=Sets()) # needs sage.modules + sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) # needs sage.modules + sage: Im = f.image() # needs sage.modules + sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', # needs sage.modules ....: '_test_some_elements', '_test_elements']) """ if not is_Parent(domain_subset): @@ -173,16 +173,17 @@ def ambient(self): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules - sage: R. = ZZ[] # optional - sage.modules - sage: H = Hom(M, R, category=Sets()) # optional - sage.modules - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules - sage: Im = f.image() # optional - sage.modules - sage: Im.ambient() is R # optional - sage.modules + sage: # needs sage.modules + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) + sage: R. = ZZ[] + sage: H = Hom(M, R, category=Sets()) + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) + sage: Im = f.image() + sage: Im.ambient() is R True - sage: P = Partitions(3).map(attrcall('conjugate')) - sage: P.ambient() is None + sage: P = Partitions(3).map(attrcall('conjugate')) # needs sage.combinat + sage: P.ambient() is None # needs sage.combinat True sage: R = Permutations(10).map(attrcall('reduced_word')) @@ -197,14 +198,14 @@ def lift(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # needs sage.modules sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) # optional - sage.modules - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules - sage: Im = f.image() # optional - sage.modules - sage: p = Im.lift(Im.an_element()); p # optional - sage.modules + sage: H = Hom(M, R, category=Sets()) # needs sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # needs sage.modules + sage: Im = f.image() # needs sage.modules + sage: p = Im.lift(Im.an_element()); p # needs sage.modules 2*x - 4 - sage: p.parent() is R # optional - sage.modules + sage: p.parent() is R # needs sage.modules True """ return x @@ -219,13 +220,14 @@ def retract(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules - sage: R. = ZZ[] # optional - sage.modules - sage: H = Hom(M, R, category=Sets()) # optional - sage.modules - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules - sage: Im = f.image() # optional - sage.modules - sage: p = 2 * x - 4 # optional - sage.modules - sage: Im.retract(p).parent() # optional - sage.modules + sage: # needs sage.modules + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) + sage: R. = ZZ[] + sage: H = Hom(M, R, category=Sets()) + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) + sage: Im = f.image() + sage: p = 2 * x - 4 + sage: Im.retract(p).parent() Multivariate Polynomial Ring in x, y over Integer Ring """ return x @@ -234,7 +236,7 @@ def _repr_(self) -> str: r""" TESTS:: - sage: Partitions(3).map(attrcall('conjugate')) + sage: Partitions(3).map(attrcall('conjugate')) # needs sage.combinat Image of Partitions of the integer 3 by The map *.conjugate() from Partitions of the integer 3 """ @@ -251,8 +253,8 @@ def cardinality(self) -> Integer: :meth:`~sage.categories.enumerated_sets.EnumeratedSets.ParentMethods.map` defaults to ``is_injective=True``): - sage: R = Permutations(10).map(attrcall('reduced_word')) # optional - sage.combinat - sage: R.cardinality() # optional - sage.combinat + sage: R = Permutations(10).map(attrcall('reduced_word')) + sage: R.cardinality() 3628800 sage: Evens = ZZ.map(lambda x: 2 * x) @@ -294,6 +296,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: + sage: # needs sage.combinat sage: P = Partitions() sage: H = Hom(P, ZZ) sage: f = H(ZZ.sum) @@ -322,8 +325,8 @@ def _an_element_(self): EXAMPLES:: - sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) - sage: R.an_element() + sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) # needs sage.groups + sage: R.an_element() # needs sage.groups [9, 8, 7, 6, 5, 4, 3, 2] """ domain_element = self._domain_subset.an_element() @@ -336,9 +339,9 @@ def _sympy_(self): EXAMPLES:: sage: from sage.sets.image_set import ImageSet - sage: S = ImageSet(sin, RealSet.open(0, pi/4)); S + sage: S = ImageSet(sin, RealSet.open(0, pi/4)); S # needs sage.symbolic Image of (0, 1/4*pi) by The map sin from (0, 1/4*pi) - sage: S._sympy_() + sage: S._sympy_() # needs sage.symbolic ImageSet(Lambda(x, sin(x)), Interval.open(0, pi/4)) """ from sympy import imageset @@ -360,11 +363,12 @@ class ImageSet(ImageSubobject, Set_base, Set_add_sub_operators, Set_boolean_oper Symbolics:: - sage: ImageSet(sin, RealSet.open(0, pi/4)) + sage: ImageSet(sin, RealSet.open(0, pi/4)) # needs sage.symbolic Image of (0, 1/4*pi) by The map sin from (0, 1/4*pi) - sage: _.an_element() + sage: _.an_element() # needs sage.symbolic 1/2*sqrt(-sqrt(2) + 2) + sage: # needs sage.symbolic sage: sos(x,y) = x^2 + y^2; sos (x, y) |--> x^2 + y^2 sage: ImageSet(sos, ZZ^2) diff --git a/src/sage/sets/integer_range.py b/src/sage/sets/integer_range.py index 984b3edf045..d42f77a5307 100644 --- a/src/sage/sets/integer_range.py +++ b/src/sage/sets/integer_range.py @@ -217,7 +217,7 @@ def __classcall_private__(cls, begin, end=None, step=Integer(1), middle_point=No ValueError: IntegerRange() step argument must not be zero sage: IntegerRange(2) is IntegerRange(0, 2) True - sage: IntegerRange(1.0) # optional - sage.rings.real_mpfr + sage: IntegerRange(1.0) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: end must be Integer or Infinity, not <... 'sage.rings.real_mpfr.RealLiteral'> diff --git a/src/sage/sets/non_negative_integers.py b/src/sage/sets/non_negative_integers.py index 72601250a97..8eb83f3dfc1 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -102,15 +102,15 @@ def __contains__(self, elt): True sage: -1 in NN False - sage: x in NN # optional - sage.symbolic + sage: x in NN # needs sage.symbolic False sage: None in NN False - sage: QQbar(sqrt(2)) in NN # optional - sage.symbolic sage.rings.number_field + sage: QQbar(sqrt(2)) in NN # needs sage.rings.number_field sage.symbolic False sage: RIF(1,2) in NN False - sage: QQbar(2) in NN # optional - sage.rings.number_field + sage: QQbar(2) in NN # needs sage.rings.number_field True sage: RIF(2) in NN True @@ -135,7 +135,7 @@ def _element_constructor_(self, i): Traceback (most recent call last): ... ValueError: Value -5 in not in Non negative integers. - sage: NN._element_constructor_(x) # optional - sage.symbolic + sage: NN._element_constructor_(x) # needs sage.symbolic Traceback (most recent call last): ... ValueError: Value x in not in Non negative integers. @@ -231,7 +231,7 @@ def _sympy_(self): EXAMPLES:: sage: NN = NonNegativeIntegers() - sage: NN._sympy_() # optional - sympy + sage: NN._sympy_() # needs sympy Naturals0 """ from sympy import Naturals0 diff --git a/src/sage/sets/positive_integers.py b/src/sage/sets/positive_integers.py index 26bf71a9cae..70625fb53b7 100644 --- a/src/sage/sets/positive_integers.py +++ b/src/sage/sets/positive_integers.py @@ -83,7 +83,7 @@ def _sympy_(self): EXAMPLES:: - sage: PositiveIntegers()._sympy_() # optional - sympy + sage: PositiveIntegers()._sympy_() # needs sympy Naturals """ from sympy import Naturals diff --git a/src/sage/sets/primes.py b/src/sage/sets/primes.py index b95ed278e45..ac33901a73b 100644 --- a/src/sage/sets/primes.py +++ b/src/sage/sets/primes.py @@ -73,11 +73,11 @@ def __init__(self, proof): sage: P.category() Category of facade infinite enumerated sets - sage: TestSuite(P).run() # optional - sage.libs.pari + sage: TestSuite(P).run() # needs sage.libs.pari sage: Q.category() Category of facade infinite enumerated sets - sage: TestSuite(Q).run() # optional - sage.libs.pari + sage: TestSuite(Q).run() # needs sage.libs.pari The set of primes can be compared to various things, but is only equal to itself:: @@ -123,7 +123,7 @@ def __contains__(self, x): False sage: 1.5 in P False - sage: e in P # optional - sage.symbolic + sage: e in P # needs sage.symbolic False """ try: @@ -164,7 +164,7 @@ def next(self, pr): EXAMPLES:: sage: P = Primes() - sage: P.next(5) # optional - sage.libs.pari + sage: P.next(5) # needs sage.libs.pari 7 """ pr = pr.next_prime(self.__proof) @@ -177,11 +177,11 @@ def unrank(self, n): EXAMPLES:: sage: P = Primes() - sage: P.unrank(0) # optional - sage.libs.pari + sage: P.unrank(0) # needs sage.libs.pari 2 - sage: P.unrank(5) # optional - sage.libs.pari + sage: P.unrank(5) # needs sage.libs.pari 13 - sage: P.unrank(42) # optional - sage.libs.pari + sage: P.unrank(42) # needs sage.libs.pari 191 """ return nth_prime(n + 1) diff --git a/src/sage/sets/real_set.py b/src/sage/sets/real_set.py index ec57b00236f..df54230cc07 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -48,6 +48,7 @@ Relations containing symbols and numeric values or constants:: + sage: # needs sage.symbolic sage: RealSet(x != 0) (-oo, 0) ∪ (0, +oo) sage: RealSet(x == pi) @@ -61,11 +62,11 @@ Note that multiple arguments are combined as union:: - sage: RealSet(x >= 0, x < 1) + sage: RealSet(x >= 0, x < 1) # needs sage.symbolic (-oo, +oo) - sage: RealSet(x >= 0, x > 1) + sage: RealSet(x >= 0, x > 1) # needs sage.symbolic [0, +oo) - sage: RealSet(x >= 0, x > -1) + sage: RealSet(x >= 0, x > -1) # needs sage.symbolic (-1, +oo) AUTHORS: @@ -406,9 +407,9 @@ def _latex_(self): EXAMPLES:: - sage: RealSet.open_closed(1/2, pi)._latex_() + sage: RealSet.open_closed(1/2, pi)._latex_() # needs sage.symbolic '(\\frac{1}{2}, \\pi]' - sage: (RealSet.point(sqrt(2)))._latex_() + sage: (RealSet.point(sqrt(2)))._latex_() # needs sage.symbolic '\\{\\sqrt{2}\\}' """ from sage.misc.latex import latex @@ -435,7 +436,7 @@ def _sympy_condition_(self, variable): EXAMPLES:: - sage: RealSet(0, 4)._sympy_condition_(x) + sage: RealSet(0, 4)._sympy_condition_(x) # needs sage.symbolic (0 < x) & (x < 4) """ x = variable @@ -464,17 +465,18 @@ def _sympy_(self): EXAMPLES:: - sage: RealSet.open_closed(0, 1)[0]._sympy_() # optional - sympy + sage: # needs sympy + sage: RealSet.open_closed(0, 1)[0]._sympy_() Interval.Lopen(0, 1) - sage: RealSet.point(0)[0]._sympy_() # random - this output format is sympy >= 1.9 # optional - sympy + sage: RealSet.point(0)[0]._sympy_() # random - this output format is sympy >= 1.9 {0} - sage: type(_) # optional - sympy + sage: type(_) - sage: RealSet.open(0,1)[0]._sympy_() # optional - sympy + sage: RealSet.open(0,1)[0]._sympy_() Interval.open(0, 1) - sage: RealSet.open(-oo,1)[0]._sympy_() # optional - sympy + sage: RealSet.open(-oo,1)[0]._sympy_() Interval.open(-oo, 1) - sage: RealSet.open(0, oo)[0]._sympy_() # optional - sympy + sage: RealSet.open(0, oo)[0]._sympy_() Interval.open(0, oo) """ from sympy import Interval @@ -494,7 +496,7 @@ def _giac_condition_(self, variable): EXAMPLES:: - sage: RealSet(0, 4)._giac_condition_(x) + sage: RealSet(0, 4)._giac_condition_(x) # needs sage.symbolic '((0 < sageVARx) and (sageVARx < 4))' """ x = variable @@ -985,11 +987,13 @@ class RealSet(UniqueRepresentation, Parent, Set_base, sage: i1, i2 = s1[0], s2[0] sage: RealSet(i2, i1) # union of intervals (1, 2) ∪ [3, 4] - sage: RealSet((-oo, 0), x > 6, i1, RealSet.point(5), RealSet.closed_open(4, 3)) + sage: RealSet((-oo, 0), x > 6, i1, RealSet.point(5), # needs sage.symbolic + ....: RealSet.closed_open(4, 3)) (-oo, 0) ∪ (1, 2) ∪ [3, 4) ∪ {5} ∪ (6, +oo) Initialization from manifold objects:: + sage: # needs sage.symbolic sage: R = manifolds.RealLine(); R Real number line ℝ sage: RealSet(R) @@ -1004,7 +1008,8 @@ class RealSet(UniqueRepresentation, Parent, Set_base, (0, 1) sage: RealSet(I01_of_R.closure()) [0, 1] - sage: I01_of_I02 = manifolds.OpenInterval(0, 1, ambient_interval=I02); I01_of_I02 + sage: I01_of_I02 = manifolds.OpenInterval(0, 1, + ....: ambient_interval=I02); I01_of_I02 Real interval (0, 1) sage: RealSet(I01_of_I02) (0, 1) @@ -1038,23 +1043,23 @@ class RealSet(UniqueRepresentation, Parent, Set_base, Constructing real sets as manifolds or manifold subsets by passing ``structure='differentiable'``:: - sage: RealSet(-oo, oo, structure='differentiable') + sage: RealSet(-oo, oo, structure='differentiable') # needs sage.symbolic Real number line ℝ - sage: RealSet([0, 1], structure='differentiable') + sage: RealSet([0, 1], structure='differentiable') # needs sage.symbolic Subset [0, 1] of the Real number line ℝ - sage: _.category() + sage: _.category() # needs sage.symbolic Category of subobjects of sets - sage: RealSet.open_closed(0, 5, structure='differentiable') + sage: RealSet.open_closed(0, 5, structure='differentiable') # needs sage.symbolic Subset (0, 5] of the Real number line ℝ This is implied when a coordinate name is given using the keywords ``coordinate`` or ``names``:: - sage: RealSet(0, 1, coordinate='λ') + sage: RealSet(0, 1, coordinate='λ') # needs sage.symbolic Open subset (0, 1) of the Real number line ℝ - sage: _.category() + sage: _.category() # needs sage.symbolic Join of Category of smooth manifolds over Real Field with 53 bits of precision and Category of connected manifolds over Real Field with 53 bits of precision and @@ -1062,14 +1067,15 @@ class RealSet(UniqueRepresentation, Parent, Set_base, It is also implied by assigning a coordinate name using generator notation:: - sage: R_xi.<ξ> = RealSet.real_line(); R_xi + sage: R_xi.<ξ> = RealSet.real_line(); R_xi # needs sage.symbolic Real number line ℝ - sage: R_xi.canonical_chart() + sage: R_xi.canonical_chart() # needs sage.symbolic Chart (ℝ, (ξ,)) With the keyword ``ambient``, we can construct a subset of a previously constructed manifold:: + sage: # needs sage.symbolic sage: P_xi = RealSet(0, oo, ambient=R_xi); P_xi Open subset (0, +oo) of the Real number line ℝ sage: P_xi.default_chart() @@ -1083,13 +1089,14 @@ class RealSet(UniqueRepresentation, Parent, Set_base, sage: F = RealSet.point(0).union(RealSet.point(1)).union(RealSet.point(2)); F {0} ∪ {1} ∪ {2} - sage: F_tau = RealSet(F, names="τ"); F_tau + sage: F_tau = RealSet(F, names="τ"); F_tau # needs sage.symbolic Subset {0} ∪ {1} ∪ {2} of the Real number line ℝ - sage: F_tau.manifold().canonical_chart() + sage: F_tau.manifold().canonical_chart() # needs sage.symbolic Chart (ℝ, (τ,)) TESTS:: + sage: # needs sage.symbolic sage: TestSuite(R_xi).run() sage: TestSuite(P_xi).run() sage: R_xi.point((1,)) in P_xi @@ -1123,6 +1130,7 @@ def __classcall__(cls, *args, **kwds): TESTS:: + sage: # needs sage.symbolic sage: RealSet(x != 0) (-oo, 0) ∪ (0, +oo) sage: RealSet(x == pi) @@ -1628,6 +1636,7 @@ def _sympy_condition_(self, variable): EXAMPLES:: + sage: # needs sage.symbolic sage: RealSet(0, 1)._sympy_condition_(x) (0 < x) & (x < 1) sage: RealSet((0,1), [2,3])._sympy_condition_(x) @@ -1639,9 +1648,9 @@ def _sympy_condition_(self, variable): TESTS:: - sage: RealSet(6,6)._sympy_condition_(x) + sage: RealSet(6,6)._sympy_condition_(x) # needs sage.symbolic False - sage: RealSet([6,6])._sympy_condition_(x) + sage: RealSet([6,6])._sympy_condition_(x) # needs sage.symbolic Eq(x, 6) """ x = variable @@ -1664,6 +1673,7 @@ def _giac_condition_(self, variable): EXAMPLES:: + sage: # needs sage.symbolic sage: RealSet(0, 1)._giac_condition_(x) '((0 < sageVARx) and (sageVARx < 1))' sage: RealSet((0,1), [2,3])._giac_condition_(x) @@ -1675,9 +1685,9 @@ def _giac_condition_(self, variable): TESTS:: - sage: RealSet(6,6)._giac_condition_(x) + sage: RealSet(6,6)._giac_condition_(x) # needs sage.symbolic 'false' - sage: RealSet([6,6])._giac_condition_(x) + sage: RealSet([6,6])._giac_condition_(x) # needs sage.symbolic 'sageVARx == 6' """ x = variable @@ -2107,7 +2117,7 @@ def union(self, *real_set_collection): (-oo, +oo) sage: s = RealSet().union([1, 2], (2, 3)); s [1, 3) - sage: RealSet().union((-oo, 0), x > 6, s[0], # optional - sage.symbolic + sage: RealSet().union((-oo, 0), x > 6, s[0], # needs sage.symbolic ....: RealSet.point(5.0), RealSet.closed_open(2, 4)) (-oo, 0) ∪ [1, 4) ∪ {5} ∪ (6, +oo) """ @@ -2171,7 +2181,7 @@ def intersection(self, *real_set_collection): [1, 10) sage: s5.intersection(-oo, +oo) [1, 10) - sage: s5.intersection(x != 2, (-oo, 3), RealSet.real_line()[0]) + sage: s5.intersection(x != 2, (-oo, 3), RealSet.real_line()[0]) # needs sage.symbolic [1, 2) ∪ (2, 3) TESTS:: @@ -2285,7 +2295,7 @@ def complement(self): TESTS:: - sage: RealSet(x != 0).complement() + sage: RealSet(x != 0).complement() # needs sage.symbolic {0} sage: RealSet.real_line().complement() {} @@ -2639,7 +2649,7 @@ def is_connected(self): (-oo, -10] ∪ (1, 3) sage: s3.is_connected() False - sage: RealSet(x != 0).is_connected() + sage: RealSet(x != 0).is_connected() # needs sage.symbolic False sage: RealSet(-oo, oo).is_connected() True @@ -2796,7 +2806,7 @@ def __rmul__(self, other): sage: A = RealSet([0, 1/2], RealSet.unbounded_above_closed(2)); A [0, 1/2] ∪ [2, +oo) - sage: pi * A + sage: pi * A # needs sage.symbolic [0, 1/2*pi] ∪ [2*pi, +oo) """ return self * other @@ -2807,21 +2817,22 @@ def _sympy_(self): EXAMPLES:: - sage: RealSet()._sympy_() # optional - sympy + sage: # needs sympy + sage: RealSet()._sympy_() EmptySet - sage: RealSet.point(5)._sympy_() # random - this output format is sympy >= 1.9 # optional - sympy + sage: RealSet.point(5)._sympy_() # random - this format is sympy >= 1.9 {5} - sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random # optional - sympy + sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random {1, 2} - sage: (RealSet(1, 2).union(RealSet.closed(3, 4)))._sympy_() # optional - sympy + sage: (RealSet(1, 2).union(RealSet.closed(3, 4)))._sympy_() Union(Interval.open(1, 2), Interval(3, 4)) - sage: RealSet(-oo, oo)._sympy_() # optional - sympy + sage: RealSet(-oo, oo)._sympy_() Reals Infinities are not elements:: - sage: import sympy # optional - sympy - sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) # optional - sympy + sage: import sympy # needs sympy + sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) # needs sympy False """ from sympy import Reals, Union diff --git a/src/sage/sets/recursively_enumerated_set.pyx b/src/sage/sets/recursively_enumerated_set.pyx index 094b1d852de..7a072820514 100644 --- a/src/sage/sets/recursively_enumerated_set.pyx +++ b/src/sage/sets/recursively_enumerated_set.pyx @@ -127,6 +127,7 @@ Elements of given depth iterator:: Graded components (set of elements of the same depth):: + sage: # needs sage.combinat sage: sorted(R.graded_component(0)) [[1, 2, 3, 4, 5]] sage: sorted(R.graded_component(1)) @@ -394,7 +395,7 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, A recursive set given by a graded relation:: - sage: # optional - sage.symbolic + sage: # needs sage.symbolic sage: def f(a): ....: return [a + 1, a + I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded'); C @@ -881,10 +882,11 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): We compute all the permutations of 3:: - sage: seeds = [Permutation([1,2,3])] # optional - sage.combinat - sage: succ = attrcall("permutohedron_succ") # optional - sage.combinat - sage: R = RecursivelyEnumeratedSet(seeds, succ) # optional - sage.combinat - sage: sorted(R.naive_search_iterator()) # optional - sage.combinat + sage: # needs sage.combinat + sage: seeds = [Permutation([1,2,3])] + sage: succ = attrcall("permutohedron_succ") + sage: R = RecursivelyEnumeratedSet(seeds, succ) + sage: sorted(R.naive_search_iterator()) [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ cdef set known, todo @@ -955,7 +957,7 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): sage: child = lambda i: [(i+3) % 10, (i+8) % 10] sage: R = RecursivelyEnumeratedSet([0], child) - sage: R.to_digraph() + sage: R.to_digraph() # needs sage.graphs Looped multi-digraph on 10 vertices Digraph of an recursively enumerated set with a symmetric structure of @@ -964,20 +966,21 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): sage: succ = lambda a: [(a[0]-1,a[1]), (a[0],a[1]-1), (a[0]+1,a[1]), (a[0],a[1]+1)] sage: seeds = [(0,0)] sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric') - sage: C.to_digraph(max_depth=3) + sage: C.to_digraph(max_depth=3) # needs sage.graphs Looped multi-digraph on 41 vertices The ``max_depth`` argument can be given at the creation of the set:: - sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric', max_depth=2) - sage: C.to_digraph() + sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric', + ....: max_depth=2) + sage: C.to_digraph() # needs sage.graphs Looped multi-digraph on 25 vertices Digraph of an recursively enumerated set with a graded structure:: sage: f = lambda a: [a+1, a+I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') - sage: C.to_digraph(max_depth=4) + sage: C.to_digraph(max_depth=4) # needs sage.graphs Looped multi-digraph on 21 vertices """ successors = self.successors @@ -1126,7 +1129,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Gaussian integers:: - sage: # optional - sage.symbolic + sage: # needs sage.symbolic sage: def f(a): ....: return [a + 1, a + I] sage: S = RecursivelyEnumeratedSet([0], f, structure='symmetric') @@ -1145,7 +1148,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Note that interrupting the computation (``KeyboardInterrupt`` for instance) breaks the iterator:: - sage: # optional - sage.symbolic + sage: # needs sage.symbolic sage: def f(a): ....: sleep(0.05r) ....: return [a-1,a+1] @@ -1415,7 +1418,7 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: # optional - sage.symbolic + sage: # needs sage.symbolic sage: def f(a): ....: return [a + 1, a + I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') @@ -1430,7 +1433,7 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): We make sure that :trac:`21312` is fixed:: - sage: # optional - sage.symbolic + sage: # needs sage.symbolic sage: def f(a): ....: sleep(0.1r) ....: return [a+1, a+I] @@ -2095,14 +2098,13 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: F = RecursivelyEnumeratedSet(seeds, succ, ....: structure='forest', enumeration='depth') - sage: # needs sage.symbolic - sage: y = var('y') + sage: y = var('y') # needs sage.symbolic sage: def map_function(t): ....: li, sum, _ = t ....: return y ^ sum sage: def reduce_function(x, y): ....: return x + y - sage: F.map_reduce(map_function, reduce_function, 0) + sage: F.map_reduce(map_function, reduce_function, 0) # needs sage.symbolic y^45 + y^44 + y^43 + 2*y^42 + 2*y^41 + 3*y^40 + 4*y^39 + 5*y^38 + 6*y^37 + 8*y^36 + 9*y^35 + 10*y^34 + 12*y^33 + 13*y^32 + 15*y^31 + 17*y^30 + 18*y^29 + 19*y^28 + 21*y^27 + 21*y^26 + 22*y^25 + 23*y^24 + 23*y^23 diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index cadbb7fe461..304d37ba1f1 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -71,7 +71,7 @@ def has_finite_length(obj): True sage: has_finite_length(iter(range(10))) False - sage: has_finite_length(GF(17^127)) # optional - sage.libs.pari + sage: has_finite_length(GF(17^127)) # needs sage.rings.finite_rings True sage: has_finite_length(ZZ) False @@ -100,17 +100,18 @@ def Set(X=None, category=None): EXAMPLES:: - sage: X = Set(GF(9, 'a')) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: # needs sage.rings.finite_rings + sage: X = Set(GF(9, 'a')) + sage: X {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} - sage: type(X) # optional - sage.libs.pari + sage: type(X) - sage: Y = X.union(Set(QQ)) # optional - sage.libs.pari - sage: Y # optional - sage.libs.pari + sage: Y = X.union(Set(QQ)) + sage: Y Set-theoretic union of {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} and Set of elements of Rational Field - sage: type(Y) # optional - sage.libs.pari + sage: type(Y) Usually sets can be used as dictionary keys. @@ -152,7 +153,7 @@ def Set(X=None, category=None): We can also create sets from different types:: - sage: sorted(Set([Sequence([3,1], immutable=True), 5, QQ, Partition([3,1,1])]), key=str) + sage: sorted(Set([Sequence([3,1], immutable=True), 5, QQ, Partition([3,1,1])]), key=str) # needs sage.combinat [5, Rational Field, [3, 1, 1], [3, 1]] Sets with unhashable objects work, but with less functionality:: @@ -236,9 +237,9 @@ def union(self, X): True sage: GF(3)(2) in X # optional - sage.libs.pari True - sage: GF(5)(2) in X # optional - sage.libs.pari + sage: GF(5)(2) in X # needs sage.rings.finite_rings False - sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) # optional - sage.libs.pari + sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) # needs sage.rings.finite_rings [0, 0, 1, 1, 2, 2, 3, 4, 5, 6] """ if isinstance(X, (Set_generic, Set_base)): @@ -262,10 +263,10 @@ def intersection(self, X): sage: 2/1 in X True - sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))); X # optional - sage.libs.pari + sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))); X # needs sage.rings.finite_rings {} - sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))); X # optional - sage.libs.pari + sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))); X # needs sage.rings.finite_rings {} """ if isinstance(X, (Set_generic, Set_base)): @@ -289,10 +290,10 @@ def difference(self, X): sage: 4/1 in X True - sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))); X # optional - sage.libs.pari + sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))); X # needs sage.rings.finite_rings {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2} - sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))); X # optional - sage.libs.pari + sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))); X # needs sage.rings.finite_rings {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2} """ if isinstance(X, (Set_generic, Set_base)): @@ -330,7 +331,7 @@ def _test_as_set_object(self, tester=None, **options): Instances of other subclasses of :class:`Set_base` run this method:: - sage: Polyhedron()._test_as_set_object(verbose=True) # optional - sage.geometry.polyhedron + sage: Polyhedron()._test_as_set_object(verbose=True) # needs sage.geometry.polyhedron Running the test suite of Set(self) running ._test_an_element() . . . pass ... @@ -412,15 +413,15 @@ def __add__(self, X): EXAMPLES:: - sage: Set(RealField()) + Set(QQ^5) # optional - sage.modules + sage: Set(RealField()) + Set(QQ^5) # needs sage.modules Set-theoretic union of Set of elements of Real Field with 53 bits of precision and Set of elements of Vector space of dimension 5 over Rational Field - sage: Set(GF(3)) + Set(GF(2)) # optional - sage.libs.pari + sage: Set(GF(3)) + Set(GF(2)) # needs sage.rings.finite_rings {0, 1, 2, 0, 1} - sage: Set(GF(2)) + Set(GF(4,'a')) # optional - sage.libs.pari + sage: Set(GF(2)) + Set(GF(4,'a')) # needs sage.rings.finite_rings {0, 1, a, a + 1} - sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) # optional - sage.libs.pari + sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) # needs sage.rings.finite_rings [0, 0, 1, 1, a, a + 1, b, b + 1, b^2, b^2 + 1, b^2 + b, b^2 + b + 1] """ return self.union(X) @@ -587,8 +588,8 @@ def _an_element_(self): EXAMPLES:: - sage: R = Set(RR) # optional - sage.rings.real_mpfr - sage: R.an_element() # indirect doctest # optional - sage.rings.real_mpfr + sage: R = Set(RR) + sage: R.an_element() # indirect doctest # needs sage.rings.real_mpfr 1.00000000000000 sage: F = Set([1, 2, 3]) @@ -630,9 +631,9 @@ def __contains__(self, x): False sage: 5/3 in GF(7) False - sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) # optional - sage.libs.pari + sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) # needs sage.rings.finite_rings [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6] - sage: Set(GF(7)).intersection(Set(GF(5))) # optional - sage.libs.pari + sage: Set(GF(7)).intersection(Set(GF(5))) # needs sage.rings.finite_rings {} """ return x in self.__object @@ -678,7 +679,7 @@ def cardinality(self): +Infinity sage: Set(GF(5)).cardinality() 5 - sage: Set(GF(5^2,'a')).cardinality() # optional - sage.libs.pari + sage: Set(GF(5^2,'a')).cardinality() # needs sage.rings.finite_rings 25 """ if self in Sets().Infinite(): @@ -716,7 +717,7 @@ def is_empty(self): False sage: Set([1..100]).is_empty() False - sage: Set(SymmetricGroup(2).list()).is_empty() # optional - sage.groups + sage: Set(SymmetricGroup(2).list()).is_empty() # needs sage.groups False sage: Set(ZZ).is_empty() False @@ -729,7 +730,7 @@ def is_empty(self): False sage: Set([1..100]).is_empty() False - sage: Set(DihedralGroup(4).list()).is_empty() # optional - sage.groups + sage: Set(DihedralGroup(4).list()).is_empty() # needs sage.groups False sage: Set(QQ).is_empty() False @@ -744,7 +745,7 @@ def is_finite(self): sage: Set(QQ).is_finite() False - sage: Set(GF(250037)).is_finite() # optional - sage.libs.pari + sage: Set(GF(250037)).is_finite() # needs sage.rings.finite_rings True sage: Set(Integers(2^1000000)).is_finite() True @@ -801,10 +802,10 @@ def subsets_lattice(self): EXAMPLES:: sage: X = Set([1,2,3]) - sage: X.subsets_lattice() # optional - sage.combinat sage.graphs sage.modules + sage: X.subsets_lattice() # needs sage.combinat sage.graphs sage.modules Finite lattice containing 8 elements sage: Y = Set() - sage: Y.subsets_lattice() # optional - sage.combinat sage.graphs sage.modules + sage: Y.subsets_lattice() # needs sage.combinat sage.graphs sage.modules Finite lattice containing 1 elements """ @@ -840,7 +841,7 @@ def _sympy_(self): sage: X = Set(ZZ); X Set of elements of Integer Ring - sage: X._sympy_() # optional - sympy + sage: X._sympy_() # needs sympy Integers """ from sage.interfaces.sympy import sympy_init @@ -972,12 +973,13 @@ def list(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: # needs sage.rings.finite_rings + sage: X = Set(GF(8,'c')) + sage: X {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: X.list() # optional - sage.libs.pari + sage: X.list() [0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1] - sage: type(X.list()) # optional - sage.libs.pari + sage: type(X.list()) <... 'list'> .. TODO:: @@ -1000,14 +1002,15 @@ def set(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: # needs sage.rings.finite_rings + sage: X = Set(GF(8,'c')) + sage: X {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: X.set() # optional - sage.libs.pari + sage: X.set() {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: type(X.set()) # optional - sage.libs.pari + sage: type(X.set()) <... 'set'> - sage: type(X) # optional - sage.libs.pari + sage: type(X) """ return set(self.object()) @@ -1019,22 +1022,23 @@ def frozenset(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: # needs sage.rings.finite_rings + sage: X = Set(GF(8,'c')) + sage: X {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: s = X.set(); s # optional - sage.libs.pari + sage: s = X.set(); s {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: hash(s) # optional - sage.libs.pari + sage: hash(s) Traceback (most recent call last): ... TypeError: unhashable type: 'set' - sage: s = X.frozenset(); s # optional - sage.libs.pari + sage: s = X.frozenset(); s frozenset({0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}) - sage: hash(s) != hash(tuple(X.set())) # optional - sage.libs.pari + sage: hash(s) != hash(tuple(X.set())) # needs sage.rings.finite_rings True - sage: type(s) # optional - sage.libs.pari + sage: type(s) # needs sage.rings.finite_rings <... 'frozenset'> """ return frozenset(self.object()) @@ -1045,8 +1049,8 @@ def __hash__(self): EXAMPLES:: - sage: s = Set(GF(8,'c')) # optional - sage.libs.pari - sage: hash(s) == hash(s) # optional - sage.libs.pari + sage: s = Set(GF(8,'c')) # needs sage.rings.finite_rings + sage: hash(s) == hash(s) # needs sage.rings.finite_rings True """ return hash(self.frozenset()) @@ -1057,10 +1061,10 @@ def __richcmp__(self, other, op): EXAMPLES:: - sage: X = Set(GF(8,'c')) # optional - sage.libs.pari - sage: X == Set(GF(8,'c')) # optional - sage.libs.pari + sage: X = Set(GF(8,'c')) # needs sage.rings.finite_rings + sage: X == Set(GF(8,'c')) # needs sage.rings.finite_rings True - sage: X == Set(GF(4,'a')) # optional - sage.libs.pari + sage: X == Set(GF(4,'a')) # needs sage.rings.finite_rings False sage: Set(QQ) == Set(ZZ) False @@ -1147,13 +1151,14 @@ def union(self, other): EXAMPLES:: - sage: X = Set(GF(8,'c')) # optional - sage.libs.pari - sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: # needs sage.rings.finite_rings + sage: X = Set(GF(8,'c')) + sage: Y = Set([GF(8,'c').0, 1, 2, 3]) + sage: X {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: sorted(Y) # optional - sage.libs.pari + sage: sorted(Y) [1, 2, 3, c] - sage: sorted(X.union(Y), key=str) # optional - sage.libs.pari + sage: sorted(X.union(Y), key=str) [0, 1, 2, 3, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1] """ if not isinstance(other, Set_object_enumerated): @@ -1166,9 +1171,9 @@ def intersection(self, other): EXAMPLES:: - sage: X = Set(GF(8,'c')) # optional - sage.libs.pari - sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # optional - sage.libs.pari - sage: X.intersection(Y) # optional - sage.libs.pari + sage: X = Set(GF(8,'c')) # needs sage.rings.finite_rings + sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # needs sage.rings.finite_rings + sage: X.intersection(Y) # needs sage.rings.finite_rings {1, c} """ if not isinstance(other, Set_object_enumerated): @@ -1186,8 +1191,8 @@ def difference(self, other): sage: X.difference(Y) {3, 4} sage: Z = Set(ZZ) - sage: W = Set([2.5, 4, 5, 6]) # optional - sage.rings.real_mpfr - sage: W.difference(Z) # optional - sage.rings.real_mpfr + sage: W = Set([2.5, 4, 5, 6]) + sage: W.difference(Z) # needs sage.rings.real_mpfr {2.50000000000000} """ if not isinstance(other, Set_object_enumerated): @@ -1232,16 +1237,16 @@ def _sympy_(self): sage: X = Set({1, 2, 3}); X {1, 2, 3} - sage: sX = X._sympy_(); sX # optional - sympy + sage: sX = X._sympy_(); sX # needs sympy Set(1, 2, 3) - sage: sX.is_empty is None # optional - sympy + sage: sX.is_empty is None # needs sympy True sage: Empty = Set([]); Empty {} - sage: sEmpty = Empty._sympy_(); sEmpty # optional - sympy + sage: sEmpty = Empty._sympy_(); sEmpty # needs sympy EmptySet - sage: sEmpty.is_empty # optional - sympy + sage: sEmpty.is_empty # needs sympy True """ from sympy import Set, EmptySet @@ -1269,10 +1274,10 @@ class Set_object_binary(Set_object, metaclass=ClasscallMetaclass): EXAMPLES:: - sage: X = Set(QQ^2) # optional - sage.modules + sage: X = Set(QQ^2) # needs sage.modules sage: Y = Set(ZZ) sage: from sage.sets.set import Set_object_binary - sage: S = Set_object_binary(X, Y, "union", "\\cup"); S # optional - sage.modules + sage: S = Set_object_binary(X, Y, "union", "\\cup"); S # needs sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring @@ -1286,9 +1291,9 @@ def __classcall__(cls, X, Y, *args, **kwds): TESTS:: sage: from sage.sets.set import Set_object_binary - sage: X = QQ^2 # optional - sage.modules + sage: X = QQ^2 # needs sage.modules sage: Y = ZZ - sage: Set_object_binary(X, Y, "union", "\\cup") # optional - sage.modules + sage: Set_object_binary(X, Y, "union", "\\cup") # needs sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring @@ -1306,10 +1311,10 @@ def __init__(self, X, Y, op, latex_op, category=None): TESTS:: sage: from sage.sets.set import Set_object_binary - sage: X = Set(QQ^2) # optional - sage.modules + sage: X = Set(QQ^2) # needs sage.modules sage: Y = Set(ZZ) - sage: S = Set_object_binary(X, Y, "union", "\\cup") # optional - sage.modules - sage: type(S) # optional - sage.modules + sage: S = Set_object_binary(X, Y, "union", "\\cup") # needs sage.modules + sage: type(S) # needs sage.modules """ self._X = X @@ -1376,17 +1381,19 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) # optional - sage.modules + sage: S = Set(QQ^2) # needs sage.modules sage: T = Set(ZZ) - sage: X = S.union(T); X # optional - sage.modules - Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() # optional - sage.modules + sage: X = S.union(T); X # needs sage.modules + Set-theoretic union of + Set of elements of Vector space of dimension 2 over Rational Field and + Set of elements of Integer Ring + sage: X.category() # needs sage.modules Category of infinite sets - sage: latex(X) # optional - sage.modules + sage: latex(X) # needs sage.modules \Bold{Q}^{2} \cup \Bold{Z} - sage: TestSuite(X).run() # optional - sage.modules + sage: TestSuite(X).run() # needs sage.modules """ if category is None: category = Sets() @@ -1427,11 +1434,12 @@ def __richcmp__(self, right, op): EXAMPLES:: - sage: Y = Set(ZZ^2).union(Set(ZZ^3)) # optional - sage.modules - sage: X = Set(ZZ^3).union(Set(ZZ^2)) # optional - sage.modules - sage: X == Y # optional - sage.modules + sage: # needs sage.modules + sage: Y = Set(ZZ^2).union(Set(ZZ^3)) + sage: X = Set(ZZ^3).union(Set(ZZ^2)) + sage: X == Y True - sage: Y == X # optional - sage.modules + sage: Y == X True This illustrates that equality testing for formal unions @@ -1457,7 +1465,7 @@ def __iter__(self): EXAMPLES:: - sage: [x for x in Set(GF(3)).union(Set(GF(2)))] # optional - sage.libs.pari + sage: [x for x in Set(GF(3)).union(Set(GF(2)))] # needs sage.rings.finite_rings [0, 1, 2, 0, 1] """ for x in self._X: @@ -1471,14 +1479,15 @@ def __contains__(self, x): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) # optional - sage.libs.pari - sage: GF(5)(1) in X # optional - sage.libs.pari + sage: # needs sage.rings.finite_rings + sage: X = Set(GF(3)).union(Set(GF(2))) + sage: GF(5)(1) in X False - sage: GF(3)(2) in X # optional - sage.libs.pari + sage: GF(3)(2) in X True - sage: GF(2)(0) in X # optional - sage.libs.pari + sage: GF(2)(0) in X True - sage: GF(5)(0) in X # optional - sage.libs.pari + sage: GF(5)(0) in X False """ return x in self._X or x in self._Y @@ -1489,10 +1498,10 @@ def cardinality(self): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: X = Set(GF(3)).union(Set(GF(2))) # needs sage.rings.finite_rings + sage: X # needs sage.rings.finite_rings {0, 1, 2, 0, 1} - sage: X.cardinality() # optional - sage.libs.pari + sage: X.cardinality() # needs sage.rings.finite_rings 5 sage: X = Set(GF(3)).union(Set(ZZ)) @@ -1510,7 +1519,7 @@ def _sympy_(self): sage: X = Set(ZZ).union(Set([1/2])); X Set-theoretic union of Set of elements of Integer Ring and {1/2} - sage: X._sympy_() # optional - sympy + sage: X._sympy_() # needs sympy Union(Integers, Set(1/2)) """ from sympy import Union @@ -1529,15 +1538,15 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) # optional - sage.modules + sage: S = Set(QQ^2) # needs sage.modules sage: T = Set(ZZ) - sage: X = S.intersection(T); X # optional - sage.modules + sage: X = S.intersection(T); X # needs sage.modules Set-theoretic intersection of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() # optional - sage.modules + sage: X.category() # needs sage.modules Category of enumerated sets - sage: latex(X) # optional - sage.modules + sage: latex(X) # needs sage.modules \Bold{Q}^{2} \cap \Bold{Z} sage: X = Set(IntegerRange(100)).intersection(Primes()) @@ -1664,18 +1673,18 @@ def __contains__(self, x): sage: X = Set(QQ).intersection(Set(RR)) sage: 5 in X True - sage: ComplexField().0 in X # optional - sage.rings.real_mpfr + sage: ComplexField().0 in X # needs sage.rings.real_mpfr False Any specific floating-point number in Sage is to finite precision, hence it is rational:: - sage: RR(sqrt(2)) in X # optional - sage.rings.real_mpfr sage.symbolic + sage: RR(sqrt(2)) in X # needs sage.rings.real_mpfr sage.symbolic True Real constants are not rational:: - sage: pi in X # optional - sage.symbolic + sage: pi in X # needs sage.symbolic False """ return x in self._X and x in self._Y @@ -1691,7 +1700,7 @@ def _sympy_(self): Set-theoretic intersection of Set of elements of Integer Ring and Set of elements of [3/2, 11/2] - sage: X._sympy_() # optional - sympy + sage: X._sympy_() # needs sympy Range(2, 6, 1) """ from sympy import Intersection @@ -1836,11 +1845,11 @@ def __contains__(self, x): sage: X = Set(QQ).difference(Set(ZZ)) sage: 5 in X False - sage: ComplexField().0 in X # optional - sage.rings.real_mpfr + sage: ComplexField().0 in X # needs sage.rings.real_mpfr False - sage: sqrt(2) in X # since sqrt(2) is not a numerical approx # optional - sage.symbolic + sage: sqrt(2) in X # since sqrt(2) is not a numerical approx # needs sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx # optional - sage.rings.real_mpfr sage.symbolic + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx True sage: 5/2 in X True @@ -1860,7 +1869,7 @@ def _sympy_(self): Set of elements of Integer Ring sage: X.category() Category of sets - sage: X._sympy_() # optional - sympy + sage: X._sympy_() # needs sympy Complement(Rationals, Integers) sage: X = Set(ZZ).difference(Set(QQ)); X @@ -1869,7 +1878,7 @@ def _sympy_(self): Set of elements of Rational Field sage: X.category() Category of enumerated sets - sage: X._sympy_() # optional - sympy + sage: X._sympy_() # needs sympy EmptySet """ from sympy import Complement @@ -2009,13 +2018,13 @@ def __contains__(self, x): sage: X = Set(QQ).symmetric_difference(Primes()) sage: 4 in X True - sage: ComplexField().0 in X # optional - sage.rings.real_mpfr + sage: ComplexField().0 in X # needs sage.rings.real_mpfr False - sage: sqrt(2) in X # since sqrt(2) is currently symbolic # optional - sage.symbolic + sage: sqrt(2) in X # since sqrt(2) is currently symbolic # needs sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated # optional - sage.rings.real_mpfr + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated True - sage: pi in X # optional - sage.symbolic + sage: pi in X # needs sage.symbolic False sage: 5/2 in X True @@ -2036,7 +2045,7 @@ def _sympy_(self): Set-theoretic symmetric difference of Set of elements of Integer Ring and {0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3} - sage: X._sympy_() # optional - sympy + sage: X._sympy_() # needs sympy Union(Complement(Integers, Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3)), Complement(Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3), Integers)) """ diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 0c7e4f35aa4..7d97cfc4064 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -6,21 +6,22 @@ We build a set from the iterator :obj:`graphs` that returns a canonical representative for each isomorphism class of graphs:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator( # optional - sage.graphs + sage: E = EnumeratedSetFromIterator( ....: graphs, ....: name="Graphs", ....: category=InfiniteEnumeratedSets(), ....: cache=True) - sage: E # optional - sage.graphs + sage: E Graphs - sage: E.unrank(0) # optional - sage.graphs + sage: E.unrank(0) Graph on 0 vertices - sage: E.unrank(4) # optional - sage.graphs + sage: E.unrank(4) Graph on 3 vertices - sage: E.cardinality() # optional - sage.graphs + sage: E.cardinality() +Infinity - sage: E.category() # optional - sage.graphs + sage: E.category() Category of facade infinite enumerated sets The module also provides decorator for functions and methods:: @@ -97,21 +98,21 @@ class EnumeratedSetFromIterator(Parent): EXAMPLES:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(7,)); E # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(7,)); E # needs sage.graphs {Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, Graph on 7 vertices, ...} - sage: E.category() # optional - sage.graphs + sage: E.category() # needs sage.graphs Category of facade enumerated sets The same example with a cache and a custom name:: - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True, # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True, # needs sage.graphs ....: name="Graphs with 8 vertices", ....: category=FiniteEnumeratedSets()); E Graphs with 8 vertices - sage: E.unrank(3) # optional - sage.graphs + sage: E.unrank(3) # needs sage.graphs Graph on 8 vertices - sage: E.category() # optional - sage.graphs + sage: E.category() # needs sage.graphs Category of facade finite enumerated sets TESTS: @@ -196,17 +197,18 @@ def __reduce__(self): TESTS:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: from sage.graphs.graph_generators import graphs # optional - sage.graphs - sage: E = EnumeratedSetFromIterator(graphs, # optional - sage.graphs + sage: from sage.graphs.graph_generators import graphs + sage: E = EnumeratedSetFromIterator(graphs, ....: args=(3,), ....: category=FiniteEnumeratedSets(), ....: name="Graphs on 3 vertices") - sage: E # optional - sage.graphs + sage: E Graphs on 3 vertices - sage: F = loads(dumps(E)); F # optional - sage.graphs + sage: F = loads(dumps(E)); F Graphs on 3 vertices - sage: E == F # optional - sage.graphs + sage: E == F True """ return (EnumeratedSetFromIterator, @@ -224,16 +226,17 @@ def _repr_(self): TESTS:: + sage: # needs sage.combinat sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(Partitions(7, min_part=2).__iter__) # optional - sage.combinat - sage: repr(E) # indirect doctest # optional - sage.combinat + sage: E = EnumeratedSetFromIterator(Partitions(7, min_part=2).__iter__) + sage: repr(E) # indirect doctest '{[7], [5, 2], [4, 3], [3, 2, 2]}' - sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__) # optional - sage.combinat - sage: repr(E) # indirect doctest # optional - sage.combinat + sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__) + sage: repr(E) # indirect doctest '{[9], [7, 2], [6, 3], [5, 4], [5, 2, 2], ...}' - sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__, # optional - sage.combinat + sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__, ....: name="Some partitions") - sage: repr(E) # indirect doctest # optional - sage.combinat + sage: repr(E) # indirect doctest 'Some partitions' """ l = [] @@ -257,10 +260,10 @@ def __contains__(self, x): EXAMPLES:: - sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator # optional - sage.combinat - sage: P = Partitions(12, min_part=2, max_part=5) # optional - sage.combinat - sage: E = EnumeratedSetFromIterator(P.__iter__) # optional - sage.combinat - sage: P([5,5,2]) in E # optional - sage.combinat + sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator + sage: P = Partitions(12, min_part=2, max_part=5) # needs sage.combinat + sage: E = EnumeratedSetFromIterator(P.__iter__) # needs sage.combinat + sage: P([5,5,2]) in E # needs sage.combinat True """ return any(x == y for y in self) @@ -277,22 +280,23 @@ def __eq__(self, other): TESTS:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), ....: category=FiniteEnumeratedSets()) - sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), ....: category=FiniteEnumeratedSets()) - sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), # optional - sage.graphs + sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), ....: category=FiniteEnumeratedSets()) - sage: E4 == E4 # optional - sage.graphs + sage: E4 == E4 True - sage: E4 == F4 # optional - sage.graphs + sage: E4 == F4 True - sage: E4 == E5 # optional - sage.graphs + sage: E4 == E5 False - sage: E5 == E4 # optional - sage.graphs + sage: E5 == E4 False - sage: E5 == E5 # optional - sage.graphs + sage: E5 == E5 True """ if isinstance(other, EnumeratedSetFromIterator): @@ -335,22 +339,23 @@ def __ne__(self, other): TESTS:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + sage: E4 = EnumeratedSetFromIterator(graphs, args=(4,), ....: category=FiniteEnumeratedSets()) - sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), # optional - sage.graphs + sage: F4 = EnumeratedSetFromIterator(graphs, args=(4,), ....: category=FiniteEnumeratedSets()) - sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), # optional - sage.graphs + sage: E5 = EnumeratedSetFromIterator(graphs, args=(5,), ....: category=FiniteEnumeratedSets()) - sage: E4 != E4 # optional - sage.graphs + sage: E4 != E4 False - sage: E4 != F4 # optional - sage.graphs + sage: E4 != F4 False - sage: E4 != E5 # optional - sage.graphs + sage: E4 != E5 True - sage: E5 != E4 # optional - sage.graphs + sage: E5 != E4 True - sage: E5 != E5 # optional - sage.graphs + sage: E5 != E5 False """ return not self == other @@ -361,14 +366,15 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) # optional - sage.graphs - sage: g1 = next(iter(E)); g1 # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) + sage: g1 = next(iter(E)); g1 Graph on 8 vertices - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs - sage: g2 = next(iter(E)); g2 # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) + sage: g2 = next(iter(E)); g2 Graph on 8 vertices - sage: g1 == g2 # optional - sage.graphs + sage: g1 == g2 True """ if hasattr(self, '_cache'): @@ -381,12 +387,13 @@ def unrank(self, i): EXAMPLES:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator - sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) # optional - sage.graphs - sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) # optional - sage.graphs - sage: E.unrank(2) # optional - sage.graphs + sage: E = EnumeratedSetFromIterator(graphs, args=(8,), cache=True) + sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) + sage: E.unrank(2) Graph on 8 vertices - sage: E.unrank(2) == F.unrank(2) # optional - sage.graphs + sage: E.unrank(2) == F.unrank(2) True """ if hasattr(self, '_cache'): @@ -507,11 +514,11 @@ def _sage_src_lines_(self): sage: from sage.misc.sageinspect import sage_getsourcelines sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = MathieuGroup.order # optional - sage.groups - sage: S = sage_getsourcelines(d) # indirect doctest # optional - sage.groups - sage: S[0][2] # optional - sage.groups + sage: d.f = MathieuGroup.order # needs sage.groups + sage: S = sage_getsourcelines(d) # indirect doctest # needs sage.groups + sage: S[0][2] # needs sage.groups ' Return the number of elements of this group.\n' - sage: S[0][25] # optional - sage.groups + sage: S[0][25] # needs sage.groups ' if not gens:\n' """ from sage.misc.sageinspect import sage_getsourcelines @@ -526,8 +533,8 @@ def _sage_argspec_(self): sage: from sage.misc.sageinspect import sage_getargspec sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = find_local_minimum # optional - scipy - sage: sage_getargspec(d) # indirect doctest # optional - scipy + sage: d.f = find_local_minimum # needs scipy + sage: sage_getargspec(d) # indirect doctest # needs scipy FullArgSpec(args=['f', 'a', 'b', 'tol', 'maxfun'], varargs=None, varkw=None, defaults=(1.48e-08, 500), kwonlyargs=[], kwonlydefaults=None, annotations={}) @@ -615,11 +622,11 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): ....: @set_from_function(name="Graphs on %(n)d vertices", ....: category=FiniteEnumeratedSets(), cache=True) ....: def Graphs(n): return graphs(n) - sage: Graphs(10) # optional - sage.graphs + sage: Graphs(10) # needs sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) # optional - sage.graphs + sage: Graphs(10).unrank(0) # needs sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) # optional - sage.graphs + sage: Graphs(10) is Graphs(10) # needs sage.graphs True The ``@cached_function`` must go first:: @@ -628,11 +635,11 @@ class EnumeratedSetFromIterator_function_decorator(Decorator): ....: category=FiniteEnumeratedSets(), cache=True) ....: @cached_function ....: def Graphs(n): return graphs(n) - sage: Graphs(10) # optional - sage.graphs + sage: Graphs(10) # needs sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) # optional - sage.graphs + sage: Graphs(10).unrank(0) # needs sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) # optional - sage.graphs + sage: Graphs(10) is Graphs(10) # needs sage.graphs False """ def __init__(self, f=None, name=None, **options): @@ -868,7 +875,7 @@ class EnumeratedSetFromIterator_method_decorator(): sage: b = B() sage: G3 = b.graphs(3); G3 Graphs(3) - sage: G3.cardinality() # optional - sage.graphs + sage: G3.cardinality() # needs sage.graphs 4 sage: G3.category() Category of facade finite enumerated sets @@ -909,11 +916,11 @@ def __init__(self, f=None, **options): :mod:`sage.combinat.permutation`) because its method ``bruhat_succ`` and ``bruhat_pred`` are decorated with ``set_from_method``:: - sage: from sage.combinat.permutation import Permutation # optional - sage.combinat - sage: loads(dumps(Permutation)) # optional - sage.combinat + sage: from sage.combinat.permutation import Permutation + sage: loads(dumps(Permutation)) - sage: p = Permutation([3,2,1]) # optional - sage.combinat - sage: loads(dumps(p)) == p # optional - sage.combinat + sage: p = Permutation([3,2,1]) + sage: loads(dumps(p)) == p True """ if f is not None: diff --git a/src/sage/sets/totally_ordered_finite_set.py b/src/sage/sets/totally_ordered_finite_set.py index fde8984b501..f28840c81f7 100644 --- a/src/sage/sets/totally_ordered_finite_set.py +++ b/src/sage/sets/totally_ordered_finite_set.py @@ -173,8 +173,8 @@ class TotallyOrderedFiniteSet(FiniteEnumeratedSet): sage: T1 = TotallyOrderedFiniteSet([3,2,5,1]) sage: T1(3) < T1(1) False - sage: T2 = TotallyOrderedFiniteSet([3,var('x')]) - sage: T2(3) < T2(var('x')) + sage: T2 = TotallyOrderedFiniteSet([3, x]) # needs sage.symbolic + sage: T2(3) < T2(x) # needs sage.symbolic 3 < x To make the above example work, you should set the argument facade to From 726c3cf00494a382cc694b448f790616ac565c07 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 13 Jul 2023 22:33:35 -0700 Subject: [PATCH 31/37] sage.parallel, sage.sets: Update # needs --- src/sage/sets/recursively_enumerated_set.pyx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/sets/recursively_enumerated_set.pyx b/src/sage/sets/recursively_enumerated_set.pyx index 7a072820514..26bcd769b44 100644 --- a/src/sage/sets/recursively_enumerated_set.pyx +++ b/src/sage/sets/recursively_enumerated_set.pyx @@ -2098,13 +2098,14 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: F = RecursivelyEnumeratedSet(seeds, succ, ....: structure='forest', enumeration='depth') - sage: y = var('y') # needs sage.symbolic + sage: # needs sage.symbolic + sage: y = var('y') sage: def map_function(t): ....: li, sum, _ = t ....: return y ^ sum sage: def reduce_function(x, y): ....: return x + y - sage: F.map_reduce(map_function, reduce_function, 0) # needs sage.symbolic + sage: F.map_reduce(map_function, reduce_function, 0) y^45 + y^44 + y^43 + 2*y^42 + 2*y^41 + 3*y^40 + 4*y^39 + 5*y^38 + 6*y^37 + 8*y^36 + 9*y^35 + 10*y^34 + 12*y^33 + 13*y^32 + 15*y^31 + 17*y^30 + 18*y^29 + 19*y^28 + 21*y^27 + 21*y^26 + 22*y^25 + 23*y^24 + 23*y^23 From 783ea1547a3b21cfb4323c199b62d656e9e9a8e6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 18:30:46 -0700 Subject: [PATCH 32/37] sage.sets: Update # needs --- src/sage/sets/non_negative_integers.py | 4 ++-- src/sage/sets/set.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/sets/non_negative_integers.py b/src/sage/sets/non_negative_integers.py index 8eb83f3dfc1..a7995ff3e1e 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -108,11 +108,11 @@ def __contains__(self, elt): False sage: QQbar(sqrt(2)) in NN # needs sage.rings.number_field sage.symbolic False - sage: RIF(1,2) in NN + sage: RIF(1,2) in NN # needs sage.rings.real_interval_field False sage: QQbar(2) in NN # needs sage.rings.number_field True - sage: RIF(2) in NN + sage: RIF(2) in NN # needs sage.rings.real_interval_field True """ try: diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 304d37ba1f1..f650fa7674b 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -1173,8 +1173,8 @@ def intersection(self, other): sage: X = Set(GF(8,'c')) # needs sage.rings.finite_rings sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # needs sage.rings.finite_rings - sage: X.intersection(Y) # needs sage.rings.finite_rings - {1, c} + sage: sorted(X.intersection(Y), key=str) # needs sage.rings.finite_rings + [1, c] """ if not isinstance(other, Set_object_enumerated): return Set_object.intersection(self, other) From 0a5857108f41c49a5a836ae8aa2f4f5e2c304eb6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Sep 2023 09:47:44 -0700 Subject: [PATCH 33/37] sage.sets: Update # needs --- src/sage/sets/real_set.py | 22 ++++++++++------------ src/sage/sets/set.py | 26 +++++++++++++------------- src/sage/sets/set_from_iterator.py | 4 ++-- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/sage/sets/real_set.py b/src/sage/sets/real_set.py index df54230cc07..45394cba23c 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.real_mpfr +# sage.doctest: needs sage.rings.real_interval_field sage.rings.real_mpfr """ Subsets of the Real Line @@ -1043,15 +1043,14 @@ class RealSet(UniqueRepresentation, Parent, Set_base, Constructing real sets as manifolds or manifold subsets by passing ``structure='differentiable'``:: - sage: RealSet(-oo, oo, structure='differentiable') # needs sage.symbolic + sage: # needs sage.symbolic + sage: RealSet(-oo, oo, structure='differentiable') Real number line ℝ - - sage: RealSet([0, 1], structure='differentiable') # needs sage.symbolic + sage: RealSet([0, 1], structure='differentiable') Subset [0, 1] of the Real number line ℝ - sage: _.category() # needs sage.symbolic + sage: _.category() Category of subobjects of sets - - sage: RealSet.open_closed(0, 5, structure='differentiable') # needs sage.symbolic + sage: RealSet.open_closed(0, 5, structure='differentiable') Subset (0, 5] of the Real number line ℝ This is implied when a coordinate name is given using the keywords ``coordinate`` @@ -1086,12 +1085,11 @@ class RealSet(UniqueRepresentation, Parent, Set_base, Chart ((0, 1), (ξ,)) sage: R_xi.subset_family() Set {(0, +oo), (0, 1), ℝ} of open subsets of the Real number line ℝ - sage: F = RealSet.point(0).union(RealSet.point(1)).union(RealSet.point(2)); F {0} ∪ {1} ∪ {2} - sage: F_tau = RealSet(F, names="τ"); F_tau # needs sage.symbolic + sage: F_tau = RealSet(F, names="τ"); F_tau Subset {0} ∪ {1} ∪ {2} of the Real number line ℝ - sage: F_tau.manifold().canonical_chart() # needs sage.symbolic + sage: F_tau.manifold().canonical_chart() Chart (ℝ, (τ,)) TESTS:: @@ -1648,9 +1646,9 @@ def _sympy_condition_(self, variable): TESTS:: - sage: RealSet(6,6)._sympy_condition_(x) # needs sage.symbolic + sage: RealSet(6,6)._sympy_condition_(x) # needs sympy sage.symbolic False - sage: RealSet([6,6])._sympy_condition_(x) # needs sage.symbolic + sage: RealSet([6,6])._sympy_condition_(x) # needs sympy sage.symbolic Eq(x, 6) """ x = variable diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index f650fa7674b..a8854d0df2b 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -237,9 +237,9 @@ def union(self, X): True sage: GF(3)(2) in X # optional - sage.libs.pari True - sage: GF(5)(2) in X # needs sage.rings.finite_rings + sage: GF(5)(2) in X False - sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) # needs sage.rings.finite_rings + sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) [0, 0, 1, 1, 2, 2, 3, 4, 5, 6] """ if isinstance(X, (Set_generic, Set_base)): @@ -417,7 +417,7 @@ def __add__(self, X): Set-theoretic union of Set of elements of Real Field with 53 bits of precision and Set of elements of Vector space of dimension 5 over Rational Field - sage: Set(GF(3)) + Set(GF(2)) # needs sage.rings.finite_rings + sage: Set(GF(3)) + Set(GF(2)) {0, 1, 2, 0, 1} sage: Set(GF(2)) + Set(GF(4,'a')) # needs sage.rings.finite_rings {0, 1, a, a + 1} @@ -631,9 +631,9 @@ def __contains__(self, x): False sage: 5/3 in GF(7) False - sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) # needs sage.rings.finite_rings + sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6] - sage: Set(GF(7)).intersection(Set(GF(5))) # needs sage.rings.finite_rings + sage: Set(GF(7)).intersection(Set(GF(5))) {} """ return x in self.__object @@ -802,10 +802,10 @@ def subsets_lattice(self): EXAMPLES:: sage: X = Set([1,2,3]) - sage: X.subsets_lattice() # needs sage.combinat sage.graphs sage.modules + sage: X.subsets_lattice() # needs sage.graphs Finite lattice containing 8 elements sage: Y = Set() - sage: Y.subsets_lattice() # needs sage.combinat sage.graphs sage.modules + sage: Y.subsets_lattice() # needs sage.graphs Finite lattice containing 1 elements """ @@ -1465,7 +1465,7 @@ def __iter__(self): EXAMPLES:: - sage: [x for x in Set(GF(3)).union(Set(GF(2)))] # needs sage.rings.finite_rings + sage: [x for x in Set(GF(3)).union(Set(GF(2)))] [0, 1, 2, 0, 1] """ for x in self._X: @@ -1498,10 +1498,10 @@ def cardinality(self): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) # needs sage.rings.finite_rings - sage: X # needs sage.rings.finite_rings + sage: X = Set(GF(3)).union(Set(GF(2))) + sage: X {0, 1, 2, 0, 1} - sage: X.cardinality() # needs sage.rings.finite_rings + sage: X.cardinality() 5 sage: X = Set(GF(3)).union(Set(ZZ)) @@ -1849,7 +1849,7 @@ def __contains__(self, x): False sage: sqrt(2) in X # since sqrt(2) is not a numerical approx # needs sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx # needs sage.rings.real_interval_field True sage: 5/2 in X True @@ -2022,7 +2022,7 @@ def __contains__(self, x): False sage: sqrt(2) in X # since sqrt(2) is currently symbolic # needs sage.symbolic False - sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated # needs sage.rings.real_interval_field True sage: pi in X # needs sage.symbolic False diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 7d97cfc4064..ef3e479c26c 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -533,8 +533,8 @@ def _sage_argspec_(self): sage: from sage.misc.sageinspect import sage_getargspec sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = find_local_minimum # needs scipy - sage: sage_getargspec(d) # indirect doctest # needs scipy + sage: d.f = find_local_minimum + sage: sage_getargspec(d) # indirect doctest FullArgSpec(args=['f', 'a', 'b', 'tol', 'maxfun'], varargs=None, varkw=None, defaults=(1.48e-08, 500), kwonlyargs=[], kwonlydefaults=None, annotations={}) From 0a28f0c09eec718b8a2950dc4f95775ae0e14979 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Sep 2023 09:10:49 -0700 Subject: [PATCH 34/37] src/sage/sets/set_from_iterator.py: Fix # needs --- src/sage/sets/set_from_iterator.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index ef3e479c26c..4b78c2cb59e 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -511,12 +511,13 @@ def _sage_src_lines_(self): TESTS:: + sage: # needs sage.groups sage: from sage.misc.sageinspect import sage_getsourcelines sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() - sage: d.f = MathieuGroup.order # needs sage.groups - sage: S = sage_getsourcelines(d) # indirect doctest # needs sage.groups - sage: S[0][2] # needs sage.groups + sage: d.f = MathieuGroup.order + sage: S = sage_getsourcelines(d) # indirect doctest + sage: S[0][2] ' Return the number of elements of this group.\n' sage: S[0][25] # needs sage.groups ' if not gens:\n' @@ -530,6 +531,7 @@ def _sage_argspec_(self): TESTS:: + sage: # needs sage.modules sage: from sage.misc.sageinspect import sage_getargspec sage: from sage.sets.set_from_iterator import Decorator sage: d = Decorator() From eac6dc37687f56481adcb8a564734b7a7275c4fa Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Sep 2023 11:42:48 -0700 Subject: [PATCH 35/37] sage -fixdoctests --no-test --only-tags src/sage/sets --- src/sage/sets/set.py | 4 ++-- src/sage/sets/set_from_iterator.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index a8854d0df2b..117b830621a 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -235,7 +235,7 @@ def union(self, X): {0, 1, 2} sage: 2/3 in X True - sage: GF(3)(2) in X # optional - sage.libs.pari + sage: GF(3)(2) in X # needs sage.libs.pari True sage: GF(5)(2) in X False @@ -612,7 +612,7 @@ def __contains__(self, x): sage: X = Set(ZZ) sage: 5 in X True - sage: GF(7)(3) in X # optional - sage.libs.pari + sage: GF(7)(3) in X # needs sage.libs.pari True sage: 2/1 in X True diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 4b78c2cb59e..5123879673a 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -519,7 +519,7 @@ def _sage_src_lines_(self): sage: S = sage_getsourcelines(d) # indirect doctest sage: S[0][2] ' Return the number of elements of this group.\n' - sage: S[0][25] # needs sage.groups + sage: S[0][25] ' if not gens:\n' """ from sage.misc.sageinspect import sage_getsourcelines From a330894dc098502b865b58039516ecee6fb6f309 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 30 Sep 2023 21:44:44 -0700 Subject: [PATCH 36/37] sage.sets: More block tags --- src/sage/sets/condition_set.py | 53 +++++++++++++++++++--------------- src/sage/sets/image_set.py | 27 +++++++++-------- src/sage/sets/set.py | 22 +++++++------- 3 files changed, 55 insertions(+), 47 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index ad8c2a8d512..539b850027f 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -260,13 +260,15 @@ def _repr_condition(self, predicate): sage: Evens = ConditionSet(ZZ, is_even) sage: Evens._repr_condition(is_even) '(x)' - sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) # needs sage.symbolic - sage: BigSin._repr_condition(BigSin._predicates[0]) # needs sage.symbolic + + sage: # needs sage.symbolic + sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) + sage: BigSin._repr_condition(BigSin._predicates[0]) 'sin(x) > 0.900000000000000' - sage: var('t') # parameter # needs sage.symbolic + sage: var('t') # parameter t - sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) # needs sage.symbolic - sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) # needs sage.symbolic + sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) + sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) 't > 0' """ if isinstance(predicate, Expression) and predicate.is_callable(): @@ -342,24 +344,26 @@ def _call_predicate(self, predicate, element): TESTS:: - sage: TripleDigits = ZZ^3 # needs sage.modules - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # needs sage.symbolic + sage: # needs sage.modules sage.symbolic + sage: TripleDigits = ZZ^3 + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # needs sage.symbolic + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: predicate = SmallTriples._predicates[0] # needs sage.symbolic - sage: element = TripleDigits((1, 2, 3)) # needs sage.modules - sage: SmallTriples._call_predicate(predicate, element) # needs sage.modules sage.symbolic + sage: predicate = SmallTriples._predicates[0] + sage: element = TripleDigits((1, 2, 3)) + sage: SmallTriples._call_predicate(predicate, element) sqrt(14) < 12 - sage: var('t') # needs sage.symbolic + sage: # needs sage.modules sage.symbolic + sage: var('t') t - sage: TinyUniverse = ZZ^0 # needs sage.modules - sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) # needs sage.modules sage.symbolic - sage: predicate = Nullary._predicates[0] # needs sage.modules sage.symbolic - sage: element = TinyUniverse(0) # needs sage.modules - sage: Nullary._call_predicate(predicate, element) # needs sage.modules sage.symbolic + sage: TinyUniverse = ZZ^0 + sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) + sage: predicate = Nullary._predicates[0] + sage: element = TinyUniverse(0) + sage: Nullary._call_predicate(predicate, element) t > 0 """ if isinstance(predicate, Expression) and predicate.is_callable(): @@ -375,13 +379,14 @@ def _an_element_(self): TESTS:: - sage: TripleDigits = ZZ^3 # needs sage.modules - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # needs sage.symbolic + sage: # needs sage.modules sage.symbolic + sage: TripleDigits = ZZ^3 + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # needs sage.symbolic + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: SmallTriples.an_element() # indirect doctest # needs sage.symbolic + sage: SmallTriples.an_element() # indirect doctest (1, 0, 0) """ for element in self._universe.some_elements(): @@ -409,7 +414,7 @@ def _sympy_(self): EXAMPLES:: - sage: # needs sage.symbolic + sage: # needs sage.modules sage.symbolic sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples @@ -468,7 +473,7 @@ def intersection(self, X): EXAMPLES:: - sage: # needs sage.symbolic + sage: # needs sage.modules sage.symbolic sage: in_small_oblong(x, y) = x^2 + 3 * y^2 <= 42 sage: SmallOblongUniverse = ConditionSet(QQ^2, in_small_oblong) sage: SmallOblongUniverse @@ -487,7 +492,7 @@ def intersection(self, X): Combining two ``ConditionSet``s with different formal variables works correctly. The formal variables of the intersection are taken from ``self``:: - sage: # needs sage.symbolic + sage: # needs sage.modules sage.symbolic sage: SmallMirrorUniverse = ConditionSet(QQ^2, in_small_oblong, ....: vars=(y, x)) sage: SmallMirrorUniverse diff --git a/src/sage/sets/image_set.py b/src/sage/sets/image_set.py index 4ad2d76a0a3..0472d793c19 100644 --- a/src/sage/sets/image_set.py +++ b/src/sage/sets/image_set.py @@ -73,12 +73,13 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve EXAMPLES:: - sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) # needs sage.modules + sage: # needs sage.modules + sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) sage: R. = QQ[] - sage: H = Hom(M, R, category=Sets()) # needs sage.modules - sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) # needs sage.modules - sage: Im = f.image() # needs sage.modules - sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', # needs sage.modules + sage: H = Hom(M, R, category=Sets()) + sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) + sage: Im = f.image() + sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', ....: '_test_some_elements', '_test_elements']) """ if not is_Parent(domain_subset): @@ -198,14 +199,15 @@ def lift(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # needs sage.modules + sage: # needs sage.modules + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) # needs sage.modules - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # needs sage.modules - sage: Im = f.image() # needs sage.modules - sage: p = Im.lift(Im.an_element()); p # needs sage.modules + sage: H = Hom(M, R, category=Sets()) + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) + sage: Im = f.image() + sage: p = Im.lift(Im.an_element()); p 2*x - 4 - sage: p.parent() is R # needs sage.modules + sage: p.parent() is R True """ return x @@ -278,7 +280,8 @@ def cardinality(self) -> Integer: sage: Mod2.cardinality() Traceback (most recent call last): ... - NotImplementedError: cannot determine cardinality of a non-injective image of an infinite set + NotImplementedError: cannot determine cardinality of a + non-injective image of an infinite set """ domain_cardinality = self._domain_subset.cardinality() if self._is_injective and self._is_injective != 'check': diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index 117b830621a..4e8789a2d57 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -1381,19 +1381,18 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) # needs sage.modules + sage: # needs sage.modules + sage: S = Set(QQ^2) sage: T = Set(ZZ) - sage: X = S.union(T); X # needs sage.modules + sage: X = S.union(T); X Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() # needs sage.modules + sage: X.category() Category of infinite sets - - sage: latex(X) # needs sage.modules + sage: latex(X) \Bold{Q}^{2} \cup \Bold{Z} - - sage: TestSuite(X).run() # needs sage.modules + sage: TestSuite(X).run() """ if category is None: category = Sets() @@ -1538,15 +1537,16 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) # needs sage.modules + sage: # needs sage.modules + sage: S = Set(QQ^2) sage: T = Set(ZZ) - sage: X = S.intersection(T); X # needs sage.modules + sage: X = S.intersection(T); X Set-theoretic intersection of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() # needs sage.modules + sage: X.category() Category of enumerated sets - sage: latex(X) # needs sage.modules + sage: latex(X) \Bold{Q}^{2} \cap \Bold{Z} sage: X = Set(IntegerRange(100)).intersection(Primes()) From 34e4139acf7bb6d3b5d6956e0d1f43e7a8ed99ce Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 1 Oct 2023 09:41:15 -0700 Subject: [PATCH 37/37] src/sage/sets/condition_set.py: Fix doctest dataflow warning --- src/sage/sets/condition_set.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 539b850027f..e29f0124224 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -414,7 +414,7 @@ def _sympy_(self): EXAMPLES:: - sage: # needs sage.modules sage.symbolic + sage: # needs sympy sage.modules sage.symbolic sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples @@ -427,10 +427,9 @@ def _sympy_(self): True sage: (5, 7, 9) in ST False - - sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval # needs sage.symbolic + sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval { x ∈ Real Field with 53 bits of precision : x >= -7, x <= 4 } - sage: Interval._sympy_() # needs sympy sage.symbolic + sage: Interval._sympy_() ConditionSet(x, (x >= -7) & (x <= 4), SageSet(Real Field with 53 bits of precision))