diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index f110f55cfc9..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]) - sage: e = C.random_element() - sage: len(e) + 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) @@ -368,7 +368,7 @@ def cartesian_factors(self): EXAMPLES:: sage: A = cartesian_product([ZZ, RR]) - sage: A((1, 1.23)).cartesian_factors() + sage: A((1, 1.23)).cartesian_factors() # needs sage.rings.real_mpfr (1, 1.23000000000000) sage: type(_) <... 'tuple'> diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 92f17647315..e29f0124224 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 + 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 + 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 + 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 + 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 - { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring } - sage: Z3.variable_names() + 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() + sage: Z3.arguments() # needs sage.modules sage.symbolic (x, y, z) - sage: Q4. = ConditionSet(QQ^4); Q4 + 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() + sage: Q4.variable_names() # needs sage.modules sage.symbolic ('a', 'b', 'c', 'd') - sage: Q4.arguments() + 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 - sage: TestSuite(P_inter_B_again).run() + 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,10 +260,12 @@ def _repr_condition(self, predicate): sage: Evens = ConditionSet(ZZ, is_even) sage: Evens._repr_condition(is_even) '(x)' + + 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 + sage: var('t') # parameter t sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) @@ -285,9 +290,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,6 +344,7 @@ def _call_predicate(self, predicate, element): TESTS:: + 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 @@ -350,6 +356,7 @@ def _call_predicate(self, predicate, element): sage: SmallTriples._call_predicate(predicate, element) sqrt(14) < 12 + sage: # needs sage.modules sage.symbolic sage: var('t') t sage: TinyUniverse = ZZ^0 @@ -372,6 +379,7 @@ def _an_element_(self): TESTS:: + 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 @@ -406,6 +414,7 @@ def _sympy_(self): EXAMPLES:: + 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 @@ -418,17 +427,17 @@ def _sympy_(self): True sage: (5, 7, 9) in ST False - 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_() - ConditionSet(x, (x >= -7) & (x <= 4), SageSet(Real Field with 53 bits of precision)) + 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_() # needs sympy sage.symbolic SageSet({ x ∈ Integer Ring : (x) }) """ from sage.interfaces.sympy import sympy_init @@ -463,10 +472,12 @@ def intersection(self, X): EXAMPLES:: + 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 - { (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 @@ -480,13 +491,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.modules 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 0dc2f93c20b..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) + 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) + 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 + sage: g = d.to_digraph(); g # needs sage.graphs Looped digraph on 5 vertices - sage: g.edges(sort=True) + 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) + 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) + 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 + sage: g = d.to_digraph(); g # needs sage.graphs Looped digraph on 5 vertices - sage: g.edges(sort=True) + 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) + 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 3dea567a779..2375f4d191a 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -90,10 +90,12 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): In general the input can be any family:: + sage: # needs sage.combinat sage: U3 = DisjointUnionEnumeratedSets( ....: Family([2,3,4], Permutations, lazy=True)) sage: U3 - Disjoint union of Lazy family ((i))_{i in [2, 3, 4]} + Disjoint union of Lazy family + ((i))_{i in [2, 3, 4]} sage: U3.cardinality() 32 sage: it = iter(U3) @@ -104,10 +106,12 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): This allows for infinite unions:: + sage: # needs sage.combinat sage: U4 = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Permutations)) sage: U4 - Disjoint union of Lazy family ((i))_{i in Non negative integers} + Disjoint union of Lazy family + ((i))_{i in Non negative integers} sage: U4.cardinality() +Infinity sage: it = iter(U4) @@ -126,6 +130,7 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): We demonstrate the ``keepkey`` option:: + sage: # needs sage.combinat sage: Ukeep = DisjointUnionEnumeratedSets( ....: Family(list(range(4)), Permutations), keepkey=True) sage: it = iter(Ukeep) @@ -136,6 +141,7 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): We now demonstrate the ``facade`` option:: + sage: # needs sage.combinat sage: UNoFacade = DisjointUnionEnumeratedSets( ....: Family(list(range(4)), Permutations), facade=False) sage: it = iter(UNoFacade) @@ -155,12 +161,12 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): 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] # needs 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] # needs sage.combinat 2 Possible extensions: the current enumeration order is not suitable @@ -210,16 +216,18 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): 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() # 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() + 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") + 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 @@ -273,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)}) - sage: TestSuite(X).run() + 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 @@ -326,7 +334,9 @@ def _is_a(self, x): sage: U4 = DisjointUnionEnumeratedSets( ....: 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 + 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 +362,19 @@ def __contains__(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # needs 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 # 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. 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 # needs sage.combinat True The following call will loop forever:: @@ -387,6 +399,7 @@ def __iter__(self): 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: # needs sage.combinat sage: U4 = DisjointUnionEnumeratedSets( ....: Family(NonNegativeIntegers(), Permutations), ....: keepkey=True, facade=False) @@ -463,6 +476,7 @@ def _element_constructor_(self): """ TESTS:: + sage: # needs sage.combinat sage.libs.flint sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=False) sage: U._element_constructor_ @@ -483,6 +497,7 @@ def _element_constructor_default(self, el): r""" TESTS:: + sage: # needs sage.combinat sage.libs.flint sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=False) sage: U([1]) # indirect doctest @@ -497,6 +512,7 @@ def _element_constructor_default(self, el): 2: Partitions of the integer 2, 3: Partitions of the integer 3} + 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 @@ -522,7 +538,9 @@ def _element_constructor_facade(self, el): """ TESTS:: - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) + sage: # needs sage.combinat sage.libs.flint + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) + ....: for i in range(5)}) sage: X([1]).parent() Partitions of the integer 1 sage: X([2,1,1]).parent() # indirect doctest @@ -536,15 +554,17 @@ 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) # needs sage.combinat sage.libs.flint + ....: for i in range(5)}, ....: keepkey=True) - sage: p = X._element_constructor_((0, [])) # indirect doctest - sage: p[1].parent() + 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: # 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)) @@ -588,6 +608,7 @@ def Element(self): """ TESTS:: + sage: # needs sage.combinat sage.libs.flint sage: U = DisjointUnionEnumeratedSets( ....: Family([1,2,3], Partitions), facade=False) sage: U.Element @@ -597,7 +618,8 @@ def Element(self): sage: U.Element 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 diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index a630ef51e24..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) - sage: Family(P, lambda x: x).category() + sage: P = Partitions(3) # needs sage.combinat + sage: Family(P, lambda x: x).category() # needs sage.combinat Category of finite enumerated sets """ @@ -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) # needs sage.combinat Lazy family ((i))_{i in Non negative integers} """ if self.function_name is not None: diff --git a/src/sage/sets/image_set.py b/src/sage/sets/image_set.py index 54b78eede7a..0472d793c19 100644 --- a/src/sage/sets/image_set.py +++ b/src/sage/sets/image_set.py @@ -73,6 +73,7 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve EXAMPLES:: + sage: # needs sage.modules sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) sage: R. = QQ[] sage: H = Hom(M, R, category=Sets()) @@ -173,6 +174,7 @@ def ambient(self): EXAMPLES:: + sage: # needs sage.modules sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) sage: R. = ZZ[] sage: H = Hom(M, R, category=Sets()) @@ -181,8 +183,8 @@ def ambient(self): 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,6 +199,7 @@ def lift(self, x): EXAMPLES:: + sage: # needs sage.modules sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) sage: R. = ZZ[] sage: H = Hom(M, R, category=Sets()) @@ -219,6 +222,7 @@ def retract(self, x): EXAMPLES:: + sage: # needs sage.modules sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) sage: R. = ZZ[] sage: H = Hom(M, R, category=Sets()) @@ -234,7 +238,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 """ @@ -276,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': @@ -294,6 +299,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 +328,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 +342,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 +366,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 1eeb9681527..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) + 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 c7b3fd27a2d..a7995ff3e1e 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -102,17 +102,17 @@ def __contains__(self, elt): True sage: -1 in NN False - sage: x in NN + sage: x in NN # needs sage.symbolic False sage: None in NN False - sage: QQbar(sqrt(2)) in NN + 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 + 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: @@ -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) # 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_() + 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 aae3c5a031f..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_() + 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 df64c2efbbf..ac33901a73b 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() # needs sage.libs.pari sage: Q.category() Category of facade infinite enumerated sets - sage: TestSuite(Q).run() + 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 + 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) + 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) + sage: P.unrank(0) # needs sage.libs.pari 2 - sage: P.unrank(5) + sage: P.unrank(5) # needs sage.libs.pari 13 - sage: P.unrank(42) + 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 47a0505de6b..45394cba23c 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.rings.real_interval_field sage.rings.real_mpfr """ Subsets of the Real Line @@ -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,6 +465,7 @@ def _sympy_(self): EXAMPLES:: + 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 @@ -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,22 @@ class RealSet(UniqueRepresentation, Parent, Set_base, Constructing real sets as manifolds or manifold subsets by passing ``structure='differentiable'``:: + sage: # needs sage.symbolic sage: RealSet(-oo, oo, structure='differentiable') Real number line ℝ - sage: RealSet([0, 1], structure='differentiable') Subset [0, 1] of the Real number line ℝ sage: _.category() Category of subobjects of sets - 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`` 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 +1066,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() @@ -1080,7 +1085,6 @@ 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 @@ -1090,6 +1094,7 @@ class RealSet(UniqueRepresentation, Parent, Set_base, 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 +1128,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 +1634,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 +1646,9 @@ def _sympy_condition_(self, variable): TESTS:: - sage: RealSet(6,6)._sympy_condition_(x) + sage: RealSet(6,6)._sympy_condition_(x) # needs sympy sage.symbolic False - sage: RealSet([6,6])._sympy_condition_(x) + sage: RealSet([6,6])._sympy_condition_(x) # needs sympy sage.symbolic Eq(x, 6) """ x = variable @@ -1664,6 +1671,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 +1683,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 +2115,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], # needs sage.symbolic + ....: RealSet.point(5.0), RealSet.closed_open(2, 4)) (-oo, 0) ∪ [1, 4) ∪ {5} ∪ (6, +oo) """ sets = [self] @@ -2170,7 +2179,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:: @@ -2284,7 +2293,7 @@ def complement(self): TESTS:: - sage: RealSet(x != 0).complement() + sage: RealSet(x != 0).complement() # needs sage.symbolic {0} sage: RealSet.real_line().complement() {} @@ -2638,7 +2647,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 @@ -2795,7 +2804,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 @@ -2806,9 +2815,10 @@ def _sympy_(self): EXAMPLES:: + sage: # needs sympy sage: RealSet()._sympy_() EmptySet - sage: RealSet.point(5)._sympy_() # random - this output format is sympy >= 1.9 + sage: RealSet.point(5)._sympy_() # random - this format is sympy >= 1.9 {5} sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random {1, 2} @@ -2819,8 +2829,8 @@ def _sympy_(self): Infinities are not elements:: - sage: import sympy - sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) + 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 a8b21530946..26bcd769b44 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,9 +395,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: # needs 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)] @@ -880,6 +882,7 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): We compute all the permutations of 3:: + sage: # needs sage.combinat sage: seeds = [Permutation([1,2,3])] sage: succ = attrcall("permutohedron_succ") sage: R = RecursivelyEnumeratedSet(seeds, succ) @@ -954,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 @@ -963,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 @@ -1125,7 +1129,9 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Gaussian integers:: - sage: f = lambda a: [a+1, a+I] + sage: # needs 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 +1148,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Note that interrupting the computation (``KeyboardInterrupt`` for instance) breaks the iterator:: + sage: # needs sage.symbolic sage: def f(a): ....: sleep(0.05r) ....: return [a-1,a+1] @@ -1411,7 +1418,9 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a+1, a+I] + sage: # needs 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 +1433,7 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): We make sure that :trac:`21312` is fixed:: + sage: # needs sage.symbolic sage: def f(a): ....: sleep(0.1r) ....: return [a+1, a+I] diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index a1789c61300..4e8789a2d57 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)) # needs sage.rings.finite_rings True sage: has_finite_length(ZZ) False @@ -100,14 +100,17 @@ def Set(X=None, category=None): EXAMPLES:: - sage: X = Set(GF(9,'a')) + 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) 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 + 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) @@ -115,7 +118,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])] @@ -149,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:: @@ -218,14 +222,20 @@ 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 + 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} + Set-theoretic union of + Set of elements of Rational Field and + {0, 1, 2} sage: 2/3 in X True - sage: GF(3)(2) in X + sage: GF(3)(2) in X # needs sage.libs.pari True sage: GF(5)(2) in X False @@ -253,12 +263,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 # needs sage.rings.finite_rings {} - 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 # needs sage.rings.finite_rings {} """ if isinstance(X, (Set_generic, Set_base)): @@ -282,12 +290,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 # 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'))) - sage: X + 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)): @@ -325,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) + sage: Polyhedron()._test_as_set_object(verbose=True) # needs sage.geometry.polyhedron Running the test suite of Set(self) running ._test_an_element() . . . pass ... @@ -407,15 +413,15 @@ def __add__(self, X): EXAMPLES:: - sage: Set(RealField()) + Set(QQ^5) + 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)) {0, 1, 2, 0, 1} - sage: Set(GF(2)) + Set(GF(4,'a')) + 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) + 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) @@ -583,7 +589,7 @@ def _an_element_(self): EXAMPLES:: sage: R = Set(RR) - sage: R.an_element() # indirect doctest + sage: R.an_element() # indirect doctest # needs sage.rings.real_mpfr 1.00000000000000 sage: F = Set([1, 2, 3]) @@ -606,7 +612,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 # needs sage.libs.pari True sage: 2/1 in X True @@ -673,7 +679,7 @@ def cardinality(self): +Infinity sage: Set(GF(5)).cardinality() 5 - sage: Set(GF(5^2,'a')).cardinality() + sage: Set(GF(5^2,'a')).cardinality() # needs sage.rings.finite_rings 25 """ if self in Sets().Infinite(): @@ -711,7 +717,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() # needs sage.groups False sage: Set(ZZ).is_empty() False @@ -724,7 +730,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() # needs sage.groups False sage: Set(QQ).is_empty() False @@ -739,7 +745,7 @@ def is_finite(self): sage: Set(QQ).is_finite() False - sage: Set(GF(250037)).is_finite() + sage: Set(GF(250037)).is_finite() # needs sage.rings.finite_rings True sage: Set(Integers(2^1000000)).is_finite() True @@ -796,10 +802,10 @@ def subsets_lattice(self): EXAMPLES:: sage: X = Set([1,2,3]) - sage: X.subsets_lattice() + sage: X.subsets_lattice() # needs sage.graphs Finite lattice containing 8 elements sage: Y = Set() - sage: Y.subsets_lattice() + sage: Y.subsets_lattice() # needs sage.graphs Finite lattice containing 1 elements """ @@ -835,7 +841,7 @@ def _sympy_(self): sage: X = Set(ZZ); X Set of elements of Integer Ring - sage: X._sympy_() + sage: X._sympy_() # needs sympy Integers """ from sage.interfaces.sympy import sympy_init @@ -967,6 +973,7 @@ def list(self): EXAMPLES:: + 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} @@ -995,6 +1002,7 @@ def set(self): EXAMPLES:: + 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} @@ -1014,6 +1022,7 @@ def frozenset(self): EXAMPLES:: + 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} @@ -1026,10 +1035,10 @@ def frozenset(self): 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())) + sage: hash(s) != hash(tuple(X.set())) # needs sage.rings.finite_rings True - sage: type(s) + sage: type(s) # needs sage.rings.finite_rings <... 'frozenset'> """ return frozenset(self.object()) @@ -1040,8 +1049,8 @@ def __hash__(self): EXAMPLES:: - sage: s = Set(GF(8,'c')) - sage: hash(s) == hash(s) + 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()) @@ -1052,10 +1061,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')) # needs sage.rings.finite_rings + sage: X == Set(GF(8,'c')) # needs sage.rings.finite_rings True - sage: X == Set(GF(4,'a')) + sage: X == Set(GF(4,'a')) # needs sage.rings.finite_rings False sage: Set(QQ) == Set(ZZ) False @@ -1142,6 +1151,7 @@ def union(self, other): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: X = Set(GF(8,'c')) sage: Y = Set([GF(8,'c').0, 1, 2, 3]) sage: X @@ -1161,10 +1171,10 @@ 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) - {1, c} + 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: 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) @@ -1182,7 +1192,7 @@ def difference(self, other): {3, 4} sage: Z = Set(ZZ) sage: W = Set([2.5, 4, 5, 6]) - sage: W.difference(Z) + sage: W.difference(Z) # needs sage.rings.real_mpfr {2.50000000000000} """ if not isinstance(other, Set_object_enumerated): @@ -1227,16 +1237,16 @@ def _sympy_(self): sage: X = Set({1, 2, 3}); X {1, 2, 3} - sage: sX = X._sympy_(); sX + sage: sX = X._sympy_(); sX # needs sympy Set(1, 2, 3) - sage: sX.is_empty is None + sage: sX.is_empty is None # needs sympy True sage: Empty = Set([]); Empty {} - sage: sEmpty = Empty._sympy_(); sEmpty + sage: sEmpty = Empty._sympy_(); sEmpty # needs sympy EmptySet - sage: sEmpty.is_empty + sage: sEmpty.is_empty # needs sympy True """ from sympy import Set, EmptySet @@ -1264,10 +1274,10 @@ class Set_object_binary(Set_object, metaclass=ClasscallMetaclass): EXAMPLES:: - sage: X = Set(QQ^2) + 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 + 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 @@ -1281,9 +1291,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 # needs sage.modules sage: Y = ZZ - sage: Set_object_binary(X, Y, "union", "\\cup") + 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 @@ -1301,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) + sage: X = Set(QQ^2) # needs 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") # needs sage.modules + sage: type(S) # needs sage.modules """ self._X = X @@ -1371,16 +1381,17 @@ def __init__(self, X, Y, category=None): EXAMPLES:: + sage: # needs sage.modules sage: S = Set(QQ^2) sage: T = Set(ZZ) 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 + 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() Category of infinite sets - sage: latex(X) \Bold{Q}^{2} \cup \Bold{Z} - sage: TestSuite(X).run() """ if category is None: @@ -1422,6 +1433,7 @@ def __richcmp__(self, right, op): EXAMPLES:: + 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 @@ -1466,6 +1478,7 @@ def __contains__(self, x): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: X = Set(GF(3)).union(Set(GF(2))) sage: GF(5)(1) in X False @@ -1505,7 +1518,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_() # needs sympy Union(Integers, Set(1/2)) """ from sympy import Union @@ -1524,10 +1537,13 @@ def __init__(self, X, Y, category=None): EXAMPLES:: + sage: # needs sage.modules 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 + 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() Category of enumerated sets sage: latex(X) @@ -1657,18 +1673,18 @@ 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 # 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 + sage: RR(sqrt(2)) in X # needs sage.rings.real_mpfr sage.symbolic True Real constants are not rational:: - sage: pi in X + sage: pi in X # needs sage.symbolic False """ return x in self._X and x in self._Y @@ -1684,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_() + sage: X._sympy_() # needs sympy Range(2, 6, 1) """ from sympy import Intersection @@ -1829,11 +1845,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 # needs sage.rings.real_mpfr 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 # 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 @@ -1853,7 +1869,7 @@ def _sympy_(self): Set of elements of Integer Ring sage: X.category() Category of sets - sage: X._sympy_() + sage: X._sympy_() # needs sympy Complement(Rationals, Integers) sage: X = Set(ZZ).difference(Set(QQ)); X @@ -1862,7 +1878,7 @@ def _sympy_(self): Set of elements of Rational Field sage: X.category() Category of enumerated sets - sage: X._sympy_() + sage: X._sympy_() # needs sympy EmptySet """ from sympy import Complement @@ -2002,13 +2018,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 # needs sage.rings.real_mpfr False - sage: sqrt(2) in X # since sqrt(2) is currently 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 + sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated # needs sage.rings.real_interval_field True - sage: pi in X + sage: pi in X # needs sage.symbolic False sage: 5/2 in X True @@ -2029,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_() + 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 4c92deb5d52..5123879673a 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -3,15 +3,16 @@ 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: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator sage: E = EnumeratedSetFromIterator( ....: graphs, - ....: name = "Graphs", - ....: category = InfiniteEnumeratedSets(), - ....: cache = True) + ....: name="Graphs", + ....: category=InfiniteEnumeratedSets(), + ....: cache=True) sage: E Graphs sage: E.unrank(0) @@ -37,9 +38,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,25 +98,21 @@ 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,)); 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() # needs sage.graphs Category of facade enumerated sets The same example with a cache and a custom name:: - sage: E = EnumeratedSetFromIterator( - ....: graphs, - ....: args = (8,), - ....: category = FiniteEnumeratedSets(), - ....: name = "Graphs with 8 vertices", - ....: cache = True) - sage: E + 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) + sage: E.unrank(3) # needs sage.graphs Graph on 8 vertices - sage: E.category() + sage: E.category() # needs sage.graphs Category of facade finite enumerated sets TESTS: @@ -154,7 +151,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 +181,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 """ @@ -200,6 +197,7 @@ 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 sage: E = EnumeratedSetFromIterator(graphs, @@ -228,14 +226,16 @@ 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__) + 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__) + 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__, name="Some partitions") + sage: E = EnumeratedSetFromIterator(Partitions(9, min_part=2).__iter__, + ....: name="Some partitions") sage: repr(E) # indirect doctest 'Some partitions' """ @@ -261,9 +261,9 @@ 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: 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) @@ -280,10 +280,14 @@ def __eq__(self, other): TESTS:: + sage: # needs sage.graphs 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 = 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 True sage: E4 == F4 @@ -335,10 +339,14 @@ def __ne__(self, other): TESTS:: + sage: # needs sage.graphs 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 = 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 False sage: E4 != F4 @@ -358,6 +366,7 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.graphs sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator sage: E = EnumeratedSetFromIterator(graphs, args=(8,)) sage: g1 = next(iter(E)); g1 @@ -378,6 +387,7 @@ 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) sage: F = EnumeratedSetFromIterator(graphs, args=(8,), cache=False) @@ -400,7 +410,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): @@ -420,8 +431,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 @@ -501,6 +511,7 @@ 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() @@ -520,11 +531,12 @@ 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() 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={}) @@ -555,12 +567,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:: @@ -584,18 +596,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() @@ -604,38 +614,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) + sage: Graphs(10) # needs sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) + sage: Graphs(10).unrank(0) # needs sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) + sage: Graphs(10) is Graphs(10) # needs 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) + sage: Graphs(10) # needs sage.graphs Graphs on 10 vertices - sage: Graphs(10).unrank(0) + sage: Graphs(10).unrank(0) # needs sage.graphs Graph on 10 vertices - sage: Graphs(10) is Graphs(10) + sage: Graphs(10) is Graphs(10) # needs sage.graphs False """ def __init__(self, f=None, name=None, **options): @@ -719,7 +725,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` """ @@ -746,7 +752,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 @@ -811,8 +818,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, ...} @@ -820,8 +827,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, ...} @@ -850,9 +857,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__) @@ -864,31 +871,28 @@ 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() + sage: G3.cardinality() # needs 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:: 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 @@ -948,9 +952,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} @@ -963,9 +967,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__) 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