passagemath-objects 10.6.41__cp314-cp314t-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-objects might be problematic. Click here for more details.
- passagemath_objects/.dylibs/libgmp.10.dylib +0 -0
- passagemath_objects/__init__.py +3 -0
- passagemath_objects-10.6.41.dist-info/METADATA +115 -0
- passagemath_objects-10.6.41.dist-info/RECORD +280 -0
- passagemath_objects-10.6.41.dist-info/WHEEL +6 -0
- passagemath_objects-10.6.41.dist-info/top_level.txt +3 -0
- sage/all__sagemath_objects.py +37 -0
- sage/arith/all__sagemath_objects.py +5 -0
- sage/arith/long.pxd +411 -0
- sage/arith/numerical_approx.cpython-314t-darwin.so +0 -0
- sage/arith/numerical_approx.pxd +35 -0
- sage/arith/numerical_approx.pyx +75 -0
- sage/arith/power.cpython-314t-darwin.so +0 -0
- sage/arith/power.pxd +31 -0
- sage/arith/power.pyx +127 -0
- sage/categories/action.cpython-314t-darwin.so +0 -0
- sage/categories/action.pxd +29 -0
- sage/categories/action.pyx +641 -0
- sage/categories/algebra_functor.py +745 -0
- sage/categories/all__sagemath_objects.py +33 -0
- sage/categories/basic.py +62 -0
- sage/categories/cartesian_product.py +295 -0
- sage/categories/category.py +3401 -0
- sage/categories/category_cy_helper.cpython-314t-darwin.so +0 -0
- sage/categories/category_cy_helper.pxd +8 -0
- sage/categories/category_cy_helper.pyx +322 -0
- sage/categories/category_singleton.cpython-314t-darwin.so +0 -0
- sage/categories/category_singleton.pxd +3 -0
- sage/categories/category_singleton.pyx +342 -0
- sage/categories/category_types.py +637 -0
- sage/categories/category_with_axiom.py +2876 -0
- sage/categories/covariant_functorial_construction.py +703 -0
- sage/categories/facade_sets.py +228 -0
- sage/categories/functor.cpython-314t-darwin.so +0 -0
- sage/categories/functor.pxd +7 -0
- sage/categories/functor.pyx +691 -0
- sage/categories/homset.py +1338 -0
- sage/categories/homsets.py +364 -0
- sage/categories/isomorphic_objects.py +73 -0
- sage/categories/map.cpython-314t-darwin.so +0 -0
- sage/categories/map.pxd +34 -0
- sage/categories/map.pyx +2112 -0
- sage/categories/morphism.cpython-314t-darwin.so +0 -0
- sage/categories/morphism.pxd +14 -0
- sage/categories/morphism.pyx +895 -0
- sage/categories/objects.py +167 -0
- sage/categories/primer.py +1696 -0
- sage/categories/pushout.py +4834 -0
- sage/categories/quotients.py +64 -0
- sage/categories/realizations.py +200 -0
- sage/categories/sets_cat.py +3228 -0
- sage/categories/sets_with_partial_maps.py +52 -0
- sage/categories/subobjects.py +64 -0
- sage/categories/subquotients.py +21 -0
- sage/categories/with_realizations.py +311 -0
- sage/cpython/__init__.py +19 -0
- sage/cpython/_py2_random.py +619 -0
- sage/cpython/all.py +3 -0
- sage/cpython/atexit.cpython-314t-darwin.so +0 -0
- sage/cpython/atexit.pyx +269 -0
- sage/cpython/builtin_types.cpython-314t-darwin.so +0 -0
- sage/cpython/builtin_types.pyx +7 -0
- sage/cpython/cython_metaclass.cpython-314t-darwin.so +0 -0
- sage/cpython/cython_metaclass.h +117 -0
- sage/cpython/cython_metaclass.pxd +3 -0
- sage/cpython/cython_metaclass.pyx +130 -0
- sage/cpython/debug.cpython-314t-darwin.so +0 -0
- sage/cpython/debug.pyx +302 -0
- sage/cpython/dict_del_by_value.cpython-314t-darwin.so +0 -0
- sage/cpython/dict_del_by_value.pxd +9 -0
- sage/cpython/dict_del_by_value.pyx +191 -0
- sage/cpython/dict_internal.h +245 -0
- sage/cpython/getattr.cpython-314t-darwin.so +0 -0
- sage/cpython/getattr.pxd +9 -0
- sage/cpython/getattr.pyx +439 -0
- sage/cpython/pycore_long.h +97 -0
- sage/cpython/pycore_long.pxd +10 -0
- sage/cpython/python_debug.h +44 -0
- sage/cpython/python_debug.pxd +47 -0
- sage/cpython/pyx_visit.h +13 -0
- sage/cpython/string.cpython-314t-darwin.so +0 -0
- sage/cpython/string.pxd +76 -0
- sage/cpython/string.pyx +34 -0
- sage/cpython/string_impl.h +60 -0
- sage/cpython/type.cpython-314t-darwin.so +0 -0
- sage/cpython/type.pxd +2 -0
- sage/cpython/type.pyx +40 -0
- sage/cpython/wrapperdescr.pxd +67 -0
- sage/ext/all__sagemath_objects.py +3 -0
- sage/ext/ccobject.h +64 -0
- sage/ext/cplusplus.pxd +17 -0
- sage/ext/mod_int.h +30 -0
- sage/ext/mod_int.pxd +24 -0
- sage/ext/stdsage.pxd +39 -0
- sage/groups/all__sagemath_objects.py +1 -0
- sage/groups/group.cpython-314t-darwin.so +0 -0
- sage/groups/group.pxd +14 -0
- sage/groups/group.pyx +322 -0
- sage/groups/old.cpython-314t-darwin.so +0 -0
- sage/groups/old.pxd +14 -0
- sage/groups/old.pyx +219 -0
- sage/libs/all__sagemath_objects.py +3 -0
- sage/libs/gmp/__init__.py +1 -0
- sage/libs/gmp/all.pxd +6 -0
- sage/libs/gmp/binop.pxd +23 -0
- sage/libs/gmp/misc.pxd +8 -0
- sage/libs/gmp/mpf.pxd +88 -0
- sage/libs/gmp/mpn.pxd +57 -0
- sage/libs/gmp/mpq.pxd +57 -0
- sage/libs/gmp/mpz.pxd +202 -0
- sage/libs/gmp/pylong.cpython-314t-darwin.so +0 -0
- sage/libs/gmp/pylong.pxd +12 -0
- sage/libs/gmp/pylong.pyx +150 -0
- sage/libs/gmp/random.pxd +25 -0
- sage/libs/gmp/randomize.pxd +59 -0
- sage/libs/gmp/types.pxd +53 -0
- sage/libs/gmpxx.pxd +19 -0
- sage/misc/abstract_method.py +276 -0
- sage/misc/all__sagemath_objects.py +43 -0
- sage/misc/bindable_class.py +253 -0
- sage/misc/c3_controlled.cpython-314t-darwin.so +0 -0
- sage/misc/c3_controlled.pxd +2 -0
- sage/misc/c3_controlled.pyx +1402 -0
- sage/misc/cachefunc.cpython-314t-darwin.so +0 -0
- sage/misc/cachefunc.pxd +43 -0
- sage/misc/cachefunc.pyx +3781 -0
- sage/misc/call.py +188 -0
- sage/misc/classcall_metaclass.cpython-314t-darwin.so +0 -0
- sage/misc/classcall_metaclass.pxd +14 -0
- sage/misc/classcall_metaclass.pyx +599 -0
- sage/misc/constant_function.cpython-314t-darwin.so +0 -0
- sage/misc/constant_function.pyx +130 -0
- sage/misc/decorators.py +747 -0
- sage/misc/fast_methods.cpython-314t-darwin.so +0 -0
- sage/misc/fast_methods.pxd +20 -0
- sage/misc/fast_methods.pyx +351 -0
- sage/misc/flatten.py +90 -0
- sage/misc/fpickle.cpython-314t-darwin.so +0 -0
- sage/misc/fpickle.pyx +177 -0
- sage/misc/function_mangling.cpython-314t-darwin.so +0 -0
- sage/misc/function_mangling.pxd +11 -0
- sage/misc/function_mangling.pyx +308 -0
- sage/misc/inherit_comparison.cpython-314t-darwin.so +0 -0
- sage/misc/inherit_comparison.pxd +5 -0
- sage/misc/inherit_comparison.pyx +105 -0
- sage/misc/instancedoc.cpython-314t-darwin.so +0 -0
- sage/misc/instancedoc.pyx +331 -0
- sage/misc/lazy_attribute.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_attribute.pyx +607 -0
- sage/misc/lazy_format.py +135 -0
- sage/misc/lazy_import.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_import.pyx +1299 -0
- sage/misc/lazy_import_cache.py +36 -0
- sage/misc/lazy_list.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_list.pxd +19 -0
- sage/misc/lazy_list.pyx +1187 -0
- sage/misc/lazy_string.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_string.pxd +7 -0
- sage/misc/lazy_string.pyx +546 -0
- sage/misc/misc.py +1066 -0
- sage/misc/misc_c.cpython-314t-darwin.so +0 -0
- sage/misc/misc_c.pxd +3 -0
- sage/misc/misc_c.pyx +766 -0
- sage/misc/namespace_package.py +37 -0
- sage/misc/nested_class.cpython-314t-darwin.so +0 -0
- sage/misc/nested_class.pxd +3 -0
- sage/misc/nested_class.pyx +394 -0
- sage/misc/persist.cpython-314t-darwin.so +0 -0
- sage/misc/persist.pyx +1251 -0
- sage/misc/prandom.py +418 -0
- sage/misc/randstate.cpython-314t-darwin.so +0 -0
- sage/misc/randstate.pxd +30 -0
- sage/misc/randstate.pyx +1059 -0
- sage/misc/repr.py +203 -0
- sage/misc/reset.cpython-314t-darwin.so +0 -0
- sage/misc/reset.pyx +196 -0
- sage/misc/sage_ostools.cpython-314t-darwin.so +0 -0
- sage/misc/sage_ostools.pyx +323 -0
- sage/misc/sage_timeit.py +276 -0
- sage/misc/sage_timeit_class.cpython-314t-darwin.so +0 -0
- sage/misc/sage_timeit_class.pyx +120 -0
- sage/misc/sage_unittest.py +637 -0
- sage/misc/sageinspect.py +2768 -0
- sage/misc/session.cpython-314t-darwin.so +0 -0
- sage/misc/session.pyx +392 -0
- sage/misc/superseded.py +557 -0
- sage/misc/test_nested_class.py +228 -0
- sage/misc/timing.py +264 -0
- sage/misc/unknown.py +222 -0
- sage/misc/verbose.py +253 -0
- sage/misc/weak_dict.cpython-314t-darwin.so +0 -0
- sage/misc/weak_dict.pxd +15 -0
- sage/misc/weak_dict.pyx +1231 -0
- sage/modules/all__sagemath_objects.py +1 -0
- sage/modules/module.cpython-314t-darwin.so +0 -0
- sage/modules/module.pxd +5 -0
- sage/modules/module.pyx +329 -0
- sage/rings/all__sagemath_objects.py +3 -0
- sage/rings/integer_fake.h +22 -0
- sage/rings/integer_fake.pxd +55 -0
- sage/sets/all__sagemath_objects.py +3 -0
- sage/sets/pythonclass.cpython-314t-darwin.so +0 -0
- sage/sets/pythonclass.pxd +9 -0
- sage/sets/pythonclass.pyx +247 -0
- sage/structure/__init__.py +4 -0
- sage/structure/all.py +30 -0
- sage/structure/category_object.cpython-314t-darwin.so +0 -0
- sage/structure/category_object.pxd +28 -0
- sage/structure/category_object.pyx +1087 -0
- sage/structure/coerce.cpython-314t-darwin.so +0 -0
- sage/structure/coerce.pxd +44 -0
- sage/structure/coerce.pyx +2107 -0
- sage/structure/coerce_actions.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_actions.pxd +27 -0
- sage/structure/coerce_actions.pyx +988 -0
- sage/structure/coerce_dict.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_dict.pxd +51 -0
- sage/structure/coerce_dict.pyx +1557 -0
- sage/structure/coerce_exceptions.py +23 -0
- sage/structure/coerce_maps.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_maps.pxd +28 -0
- sage/structure/coerce_maps.pyx +718 -0
- sage/structure/debug_options.cpython-314t-darwin.so +0 -0
- sage/structure/debug_options.pxd +6 -0
- sage/structure/debug_options.pyx +54 -0
- sage/structure/dynamic_class.py +541 -0
- sage/structure/element.cpython-314t-darwin.so +0 -0
- sage/structure/element.pxd +272 -0
- sage/structure/element.pyx +4772 -0
- sage/structure/element_wrapper.cpython-314t-darwin.so +0 -0
- sage/structure/element_wrapper.pxd +12 -0
- sage/structure/element_wrapper.pyx +582 -0
- sage/structure/factorization.py +1422 -0
- sage/structure/factorization_integer.py +105 -0
- sage/structure/factory.cpython-314t-darwin.so +0 -0
- sage/structure/factory.pyx +786 -0
- sage/structure/formal_sum.py +489 -0
- sage/structure/gens_py.py +73 -0
- sage/structure/global_options.py +1743 -0
- sage/structure/indexed_generators.py +863 -0
- sage/structure/list_clone.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone.pxd +65 -0
- sage/structure/list_clone.pyx +1867 -0
- sage/structure/list_clone_demo.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone_demo.pyx +248 -0
- sage/structure/list_clone_timings.py +179 -0
- sage/structure/list_clone_timings_cy.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone_timings_cy.pyx +86 -0
- sage/structure/mutability.cpython-314t-darwin.so +0 -0
- sage/structure/mutability.pxd +21 -0
- sage/structure/mutability.pyx +348 -0
- sage/structure/nonexact.py +69 -0
- sage/structure/parent.cpython-314t-darwin.so +0 -0
- sage/structure/parent.pxd +112 -0
- sage/structure/parent.pyx +3093 -0
- sage/structure/parent_base.cpython-314t-darwin.so +0 -0
- sage/structure/parent_base.pxd +13 -0
- sage/structure/parent_base.pyx +44 -0
- sage/structure/parent_gens.cpython-314t-darwin.so +0 -0
- sage/structure/parent_gens.pxd +22 -0
- sage/structure/parent_gens.pyx +377 -0
- sage/structure/parent_old.cpython-314t-darwin.so +0 -0
- sage/structure/parent_old.pxd +25 -0
- sage/structure/parent_old.pyx +294 -0
- sage/structure/proof/__init__.py +1 -0
- sage/structure/proof/all.py +243 -0
- sage/structure/proof/proof.py +300 -0
- sage/structure/richcmp.cpython-314t-darwin.so +0 -0
- sage/structure/richcmp.pxd +213 -0
- sage/structure/richcmp.pyx +495 -0
- sage/structure/sage_object.cpython-314t-darwin.so +0 -0
- sage/structure/sage_object.pxd +3 -0
- sage/structure/sage_object.pyx +988 -0
- sage/structure/sage_object_test.py +19 -0
- sage/structure/sequence.py +937 -0
- sage/structure/set_factories.py +1178 -0
- sage/structure/set_factories_example.py +527 -0
- sage/structure/support_view.py +179 -0
- sage/structure/test_factory.py +56 -0
- sage/structure/unique_representation.py +1359 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
r"""
|
|
3
|
+
An example of set factory
|
|
4
|
+
=========================
|
|
5
|
+
|
|
6
|
+
The goal of this module is to exemplify the use of set factories. Note
|
|
7
|
+
that the code is intentionally kept minimal; many things and in
|
|
8
|
+
particular several iterators could be written in a more efficient way.
|
|
9
|
+
|
|
10
|
+
.. SEEALSO::
|
|
11
|
+
|
|
12
|
+
:mod:`.set_factories` for an introduction to set
|
|
13
|
+
factories, their specifications, and examples of their use and
|
|
14
|
+
implementation based on this module.
|
|
15
|
+
|
|
16
|
+
We describe here a factory used to construct the set `S` of couples `(x,y)`
|
|
17
|
+
with `x` and `y` in `I:=\{0,1,2,3,4\}`, together with the following subsets,
|
|
18
|
+
where `(a, b)\in S`
|
|
19
|
+
|
|
20
|
+
.. MATH::
|
|
21
|
+
|
|
22
|
+
S_a := \{(x,y) \in S \mid x = a\},
|
|
23
|
+
|
|
24
|
+
S^b := \{(x,y) \in S \mid y = b\},
|
|
25
|
+
|
|
26
|
+
S_a^b := \{(x,y) \in S \mid x = a, y = b\}.
|
|
27
|
+
"""
|
|
28
|
+
# ****************************************************************************
|
|
29
|
+
# Copyright (C) 2012 Florent Hivert <florent.hivert at lri.fr>
|
|
30
|
+
#
|
|
31
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
32
|
+
# https://www.gnu.org/licenses/
|
|
33
|
+
# ****************************************************************************
|
|
34
|
+
|
|
35
|
+
from sage.structure.unique_representation import UniqueRepresentation
|
|
36
|
+
from sage.structure.element_wrapper import ElementWrapper
|
|
37
|
+
from sage.structure.set_factories import (
|
|
38
|
+
SetFactory, ParentWithSetFactory, TopMostParentPolicy)
|
|
39
|
+
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
|
|
40
|
+
from sage.sets.family import LazyFamily
|
|
41
|
+
from sage.categories.enumerated_sets import EnumeratedSets
|
|
42
|
+
from sage.rings.integer import Integer
|
|
43
|
+
from sage.misc.lazy_attribute import lazy_attribute
|
|
44
|
+
|
|
45
|
+
MAX = 5
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class XYPairsFactory(SetFactory):
|
|
49
|
+
r"""
|
|
50
|
+
An example of set factory, for sets of pairs of integers.
|
|
51
|
+
|
|
52
|
+
.. SEEALSO::
|
|
53
|
+
|
|
54
|
+
:mod:`.set_factories` for an introduction to set factories.
|
|
55
|
+
"""
|
|
56
|
+
def __call__(self, x=None, y=None, policy=None):
|
|
57
|
+
r"""
|
|
58
|
+
Construct the subset from constraints.
|
|
59
|
+
|
|
60
|
+
Consider the set `S` of couples `(x,y)` with `x` and `y` in
|
|
61
|
+
`I:=\{0,1,2,3,4\}`. Returns the subsets of element of `S` satisfying
|
|
62
|
+
some constraints.
|
|
63
|
+
|
|
64
|
+
INPUT:
|
|
65
|
+
|
|
66
|
+
- ``x=a`` -- where ``a`` is an integer (default: ``None``)
|
|
67
|
+
- ``y=b`` -- where ``b`` is an integer (default: ``None``)
|
|
68
|
+
- ``policy`` -- the policy passed to the created set
|
|
69
|
+
|
|
70
|
+
.. SEEALSO::
|
|
71
|
+
|
|
72
|
+
:class:`.set_factories.SetFactoryPolicy`
|
|
73
|
+
|
|
74
|
+
EXAMPLES:
|
|
75
|
+
|
|
76
|
+
Let us first create the set factory::
|
|
77
|
+
|
|
78
|
+
sage: from sage.structure.set_factories_example import XYPairsFactory
|
|
79
|
+
sage: XYPairs = XYPairsFactory()
|
|
80
|
+
|
|
81
|
+
One can then use the set factory to construct a set::
|
|
82
|
+
|
|
83
|
+
sage: P = XYPairs(); P.list()
|
|
84
|
+
[(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (0, 4), (1, 4), (2, 4), (3, 4), (4, 4)]
|
|
85
|
+
|
|
86
|
+
.. NOTE::
|
|
87
|
+
|
|
88
|
+
This function is actually the ``__call__`` method of
|
|
89
|
+
:class:`XYPairsFactory`.
|
|
90
|
+
|
|
91
|
+
TESTS::
|
|
92
|
+
|
|
93
|
+
sage: TestSuite(P).run()
|
|
94
|
+
"""
|
|
95
|
+
if policy is None:
|
|
96
|
+
policy = self._default_policy
|
|
97
|
+
|
|
98
|
+
if isinstance(x, (Integer, int)):
|
|
99
|
+
if isinstance(y, (Integer, int)):
|
|
100
|
+
return SingletonPair(x, y, policy)
|
|
101
|
+
return PairsX_(x, policy)
|
|
102
|
+
if isinstance(y, (Integer, int)):
|
|
103
|
+
return Pairs_Y(y, policy)
|
|
104
|
+
return AllPairs(policy)
|
|
105
|
+
|
|
106
|
+
def add_constraints(self, cons, args_opts):
|
|
107
|
+
r"""
|
|
108
|
+
Add constraints to the set ``cons`` as per
|
|
109
|
+
:meth:`SetFactory.add_constraints<.set_factories.SetFactory.add_constraints>`.
|
|
110
|
+
|
|
111
|
+
This is a crude implementation for the sake of the demonstration which
|
|
112
|
+
should not be taken as an example.
|
|
113
|
+
|
|
114
|
+
EXAMPLES::
|
|
115
|
+
|
|
116
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
117
|
+
sage: XYPairs.add_constraints((3,None), ((2,), {}))
|
|
118
|
+
Traceback (most recent call last):
|
|
119
|
+
...
|
|
120
|
+
ValueError: Duplicate value for constraints 'x': was 3 now 2
|
|
121
|
+
sage: XYPairs.add_constraints((), ((2,), {}))
|
|
122
|
+
(2, None)
|
|
123
|
+
sage: XYPairs.add_constraints((), ((2,), {'y':3}))
|
|
124
|
+
(2, 3)
|
|
125
|
+
"""
|
|
126
|
+
args, opts = args_opts
|
|
127
|
+
|
|
128
|
+
res = list(cons)
|
|
129
|
+
res += [None] * (2 - len(res))
|
|
130
|
+
|
|
131
|
+
def set_args(argss):
|
|
132
|
+
for i, v in enumerate(argss):
|
|
133
|
+
if res[i] is not None and v is not None:
|
|
134
|
+
raise ValueError("Duplicate value for constraints '{}': "
|
|
135
|
+
"was {} now {}".format(['x', 'y'][i],
|
|
136
|
+
res[i], v))
|
|
137
|
+
if v is not None:
|
|
138
|
+
res[i] = v
|
|
139
|
+
set_args(args)
|
|
140
|
+
|
|
141
|
+
def parse_args(x=None, y=None):
|
|
142
|
+
set_args((x, y))
|
|
143
|
+
parse_args(**opts)
|
|
144
|
+
if res == (None, None):
|
|
145
|
+
return ()
|
|
146
|
+
return tuple(res)
|
|
147
|
+
|
|
148
|
+
@lazy_attribute
|
|
149
|
+
def _default_policy(self):
|
|
150
|
+
r"""
|
|
151
|
+
TESTS::
|
|
152
|
+
|
|
153
|
+
sage: from sage.structure.set_factories_example import XYPairsFactory
|
|
154
|
+
sage: XYPairs = XYPairsFactory()
|
|
155
|
+
sage: XYPairs._default_policy
|
|
156
|
+
Set factory policy for <class 'sage.structure.set_factories_example.XYPair'> with parent AllPairs[=Factory for XY pairs(())]
|
|
157
|
+
"""
|
|
158
|
+
return TopMostParentPolicy(self, (), XYPair)
|
|
159
|
+
|
|
160
|
+
def _repr_(self):
|
|
161
|
+
"""
|
|
162
|
+
TESTS::
|
|
163
|
+
|
|
164
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
165
|
+
sage: XYPairs # indirect doctest
|
|
166
|
+
Factory for XY pairs
|
|
167
|
+
"""
|
|
168
|
+
return "Factory for XY pairs"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
XYPairs = XYPairsFactory()
|
|
172
|
+
XYPairs.__doc__ = XYPairsFactory.__call__.__doc__
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class XYPair(ElementWrapper):
|
|
176
|
+
r"""
|
|
177
|
+
A class for Elements `(x,y)` with `x` and `y` in `\{0,1,2,3,4\}`.
|
|
178
|
+
|
|
179
|
+
EXAMPLES::
|
|
180
|
+
|
|
181
|
+
sage: from sage.structure.set_factories_example import XYPair
|
|
182
|
+
sage: p = XYPair(Parent(), (0,1)); p
|
|
183
|
+
(0, 1)
|
|
184
|
+
sage: p = XYPair(Parent(), (0,8))
|
|
185
|
+
Traceback (most recent call last):
|
|
186
|
+
...
|
|
187
|
+
ValueError: numbers must be in range(5)
|
|
188
|
+
"""
|
|
189
|
+
def __init__(self, parent, value, check=True):
|
|
190
|
+
"""
|
|
191
|
+
TESTS::
|
|
192
|
+
|
|
193
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
194
|
+
sage: P = XYPairs(); p = P.list()[0]
|
|
195
|
+
sage: TestSuite(p).run()
|
|
196
|
+
"""
|
|
197
|
+
if check:
|
|
198
|
+
if not isinstance(value, tuple):
|
|
199
|
+
raise ValueError("Value {} must be a tuple".format(value))
|
|
200
|
+
if len(value) != 2:
|
|
201
|
+
raise ValueError("Value must be of length 2")
|
|
202
|
+
if not all(int(x) in range(MAX) for x in value):
|
|
203
|
+
raise ValueError("numbers must be in range({})".format(MAX))
|
|
204
|
+
ElementWrapper.__init__(self, parent, value)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class AllPairs(ParentWithSetFactory, DisjointUnionEnumeratedSets):
|
|
208
|
+
r"""
|
|
209
|
+
This parent shows how one can use set factories together with
|
|
210
|
+
:class:`DisjointUnionEnumeratedSets`.
|
|
211
|
+
|
|
212
|
+
It is constructed as the disjoint union
|
|
213
|
+
(:class:`DisjointUnionEnumeratedSets`) of :class:`Pairs_Y` parents:
|
|
214
|
+
|
|
215
|
+
.. MATH::
|
|
216
|
+
|
|
217
|
+
S := \bigcup_{i = 0,1,..., 4} S^y
|
|
218
|
+
|
|
219
|
+
.. WARNING::
|
|
220
|
+
|
|
221
|
+
When writing a parent ``P`` as a disjoint union of a family of parents
|
|
222
|
+
``P_i``, the parents ``P_i`` must be constructed as facade parents for
|
|
223
|
+
``P``. As a consequence, it should be passed ``P.facade_policy()`` as
|
|
224
|
+
policy argument. See the source code of :meth:`pairs_y` for an
|
|
225
|
+
example.
|
|
226
|
+
|
|
227
|
+
TESTS::
|
|
228
|
+
|
|
229
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
230
|
+
sage: P = XYPairs(); P.list()
|
|
231
|
+
[(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (0, 4), (1, 4), (2, 4), (3, 4), (4, 4)]
|
|
232
|
+
"""
|
|
233
|
+
def __init__(self, policy):
|
|
234
|
+
r"""
|
|
235
|
+
TESTS::
|
|
236
|
+
|
|
237
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
238
|
+
sage: TestSuite(XYPairs()).run()
|
|
239
|
+
"""
|
|
240
|
+
ParentWithSetFactory.__init__(self, (), policy=policy,
|
|
241
|
+
category=EnumeratedSets().Finite())
|
|
242
|
+
DisjointUnionEnumeratedSets.__init__(self,
|
|
243
|
+
LazyFamily(range(MAX),
|
|
244
|
+
self.pairs_y),
|
|
245
|
+
facade=True, keepkey=False,
|
|
246
|
+
category=self.category())
|
|
247
|
+
|
|
248
|
+
def pairs_y(self, letter):
|
|
249
|
+
r"""
|
|
250
|
+
Construct the parent for the disjoint union.
|
|
251
|
+
|
|
252
|
+
Construct a parent in :class:`Pairs_Y` as a facade parent for ``self``.
|
|
253
|
+
|
|
254
|
+
This is an internal function which should be hidden from the user
|
|
255
|
+
(typically under the name ``_pairs_y``. We put it here for
|
|
256
|
+
documentation.
|
|
257
|
+
|
|
258
|
+
TESTS::
|
|
259
|
+
|
|
260
|
+
sage: from sage.structure.set_factories_example import XYPairs, XYPair
|
|
261
|
+
sage: S = XYPairs()
|
|
262
|
+
sage: S1 = S.pairs_y(1); S1
|
|
263
|
+
{(a, 1) | a in range(5)}
|
|
264
|
+
sage: S.an_element().parent()
|
|
265
|
+
AllPairs
|
|
266
|
+
|
|
267
|
+
sage: from sage.structure.set_factories import SelfParentPolicy
|
|
268
|
+
sage: selfpolicy = SelfParentPolicy(XYPairs, XYPair)
|
|
269
|
+
sage: selfS = XYPairs(policy=selfpolicy)
|
|
270
|
+
sage: selfS1 = selfS.pairs_y(1); selfS1
|
|
271
|
+
{(a, 1) | a in range(5)}
|
|
272
|
+
sage: S.an_element().parent() is selfS
|
|
273
|
+
False
|
|
274
|
+
sage: selfS.an_element().parent() is selfS
|
|
275
|
+
True
|
|
276
|
+
"""
|
|
277
|
+
return Pairs_Y(letter, policy=self.facade_policy())
|
|
278
|
+
|
|
279
|
+
def _repr_(self):
|
|
280
|
+
r"""
|
|
281
|
+
TESTS::
|
|
282
|
+
|
|
283
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
284
|
+
sage: XYPairs() # indirect doctest
|
|
285
|
+
AllPairs
|
|
286
|
+
"""
|
|
287
|
+
return "AllPairs"
|
|
288
|
+
|
|
289
|
+
def check_element(self, el, check):
|
|
290
|
+
r"""
|
|
291
|
+
TESTS::
|
|
292
|
+
|
|
293
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
294
|
+
sage: P = XYPairs()
|
|
295
|
+
sage: P.check_element(P.an_element(), True)
|
|
296
|
+
sage: XYPairs()((7, 0)) # indirect doctest
|
|
297
|
+
Traceback (most recent call last):
|
|
298
|
+
...
|
|
299
|
+
ValueError: numbers must be in range(5)
|
|
300
|
+
"""
|
|
301
|
+
pass
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
class PairsX_(ParentWithSetFactory, UniqueRepresentation):
|
|
305
|
+
r"""
|
|
306
|
+
The set of pairs `(x, 0), (x, 1), ..., (x, 4)`.
|
|
307
|
+
|
|
308
|
+
TESTS::
|
|
309
|
+
|
|
310
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
311
|
+
sage: P = XYPairs(0); P.list()
|
|
312
|
+
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4)]
|
|
313
|
+
"""
|
|
314
|
+
def __init__(self, x, policy):
|
|
315
|
+
r"""
|
|
316
|
+
TESTS::
|
|
317
|
+
|
|
318
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
319
|
+
sage: TestSuite(XYPairs(0)).run()
|
|
320
|
+
"""
|
|
321
|
+
self._x = x
|
|
322
|
+
ParentWithSetFactory.__init__(self, (x, None), policy=policy,
|
|
323
|
+
category=EnumeratedSets().Finite())
|
|
324
|
+
|
|
325
|
+
def _repr_(self):
|
|
326
|
+
"""
|
|
327
|
+
TESTS::
|
|
328
|
+
|
|
329
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
330
|
+
sage: XYPairs(x=1)
|
|
331
|
+
{(1, b) | b in range(5)}
|
|
332
|
+
"""
|
|
333
|
+
return "{(%s, b) | b in range(%s)}" % (self._x, MAX)
|
|
334
|
+
|
|
335
|
+
def an_element(self):
|
|
336
|
+
r"""
|
|
337
|
+
TESTS::
|
|
338
|
+
|
|
339
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
340
|
+
sage: P = XYPairs(x=0); P.an_element()
|
|
341
|
+
(0, 0)
|
|
342
|
+
"""
|
|
343
|
+
return self._element_constructor_((self._x, 0), check=False)
|
|
344
|
+
|
|
345
|
+
def check_element(self, el, check):
|
|
346
|
+
r"""
|
|
347
|
+
TESTS::
|
|
348
|
+
|
|
349
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
350
|
+
sage: P = XYPairs(x=1)
|
|
351
|
+
sage: P.check_element(P.an_element(), True)
|
|
352
|
+
sage: XYPairs(x=1)((0, 0)) # indirect doctest
|
|
353
|
+
Traceback (most recent call last):
|
|
354
|
+
...
|
|
355
|
+
ValueError: Wrong first coordinate
|
|
356
|
+
"""
|
|
357
|
+
(x, y) = el.value
|
|
358
|
+
if x != self._x:
|
|
359
|
+
raise ValueError("Wrong first coordinate")
|
|
360
|
+
|
|
361
|
+
def __iter__(self):
|
|
362
|
+
r"""
|
|
363
|
+
TESTS::
|
|
364
|
+
|
|
365
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
366
|
+
sage: list(XYPairs(x=1))
|
|
367
|
+
[(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)]
|
|
368
|
+
"""
|
|
369
|
+
for i in range(MAX):
|
|
370
|
+
yield self._element_constructor_((self._x, i), check=False)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
class Pairs_Y(ParentWithSetFactory, DisjointUnionEnumeratedSets):
|
|
374
|
+
r"""
|
|
375
|
+
The set of pairs `(0, y), (1, y), ..., (4, y)`.
|
|
376
|
+
|
|
377
|
+
It is constructed as the disjoint union
|
|
378
|
+
(:class:`DisjointUnionEnumeratedSets`) of :class:`SingletonPair` parents:
|
|
379
|
+
|
|
380
|
+
.. MATH::
|
|
381
|
+
|
|
382
|
+
S^y := \bigcup_{i = 0,1,..., 4} S_i^y
|
|
383
|
+
|
|
384
|
+
.. SEEALSO::
|
|
385
|
+
|
|
386
|
+
:class:`AllPairs` for how to properly construct
|
|
387
|
+
:class:`DisjointUnionEnumeratedSets` using
|
|
388
|
+
:class:`~sage.structure.set_factories.ParentWithSetFactory`.
|
|
389
|
+
|
|
390
|
+
TESTS::
|
|
391
|
+
|
|
392
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
393
|
+
sage: P = XYPairs(y=1); P.list()
|
|
394
|
+
[(0, 1), (1, 1), (2, 1), (3, 1), (4, 1)]
|
|
395
|
+
"""
|
|
396
|
+
def __init__(self, y, policy):
|
|
397
|
+
r"""
|
|
398
|
+
TESTS::
|
|
399
|
+
|
|
400
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
401
|
+
sage: TestSuite(XYPairs(y=1)).run()
|
|
402
|
+
"""
|
|
403
|
+
self._y = y
|
|
404
|
+
ParentWithSetFactory.__init__(self, (None, y), policy=policy,
|
|
405
|
+
category=EnumeratedSets().Finite())
|
|
406
|
+
DisjointUnionEnumeratedSets.__init__(
|
|
407
|
+
self, LazyFamily(range(MAX), self.single_pair),
|
|
408
|
+
facade=True, keepkey=False,
|
|
409
|
+
category=self.category()) # TODO remove and fix disjoint union.
|
|
410
|
+
|
|
411
|
+
def _repr_(self):
|
|
412
|
+
"""
|
|
413
|
+
TESTS::
|
|
414
|
+
|
|
415
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
416
|
+
sage: XYPairs(y=1)
|
|
417
|
+
{(a, 1) | a in range(5)}
|
|
418
|
+
"""
|
|
419
|
+
return "{(a, %s) | a in range(%s)}" % (self._y, MAX)
|
|
420
|
+
|
|
421
|
+
def an_element(self):
|
|
422
|
+
r"""
|
|
423
|
+
TESTS::
|
|
424
|
+
|
|
425
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
426
|
+
sage: XYPairs(y=1).an_element()
|
|
427
|
+
(0, 1)
|
|
428
|
+
"""
|
|
429
|
+
return self._element_constructor_((0, self._y), check=False)
|
|
430
|
+
|
|
431
|
+
def single_pair(self, letter):
|
|
432
|
+
r"""
|
|
433
|
+
Construct the singleton pair parent.
|
|
434
|
+
|
|
435
|
+
Construct a singleton pair for ``(self.y, letter)`` as a facade parent
|
|
436
|
+
for ``self``.
|
|
437
|
+
|
|
438
|
+
.. SEEALSO::
|
|
439
|
+
|
|
440
|
+
:class:`AllPairs` for how to properly construct
|
|
441
|
+
:class:`DisjointUnionEnumeratedSets` using
|
|
442
|
+
:class:`~sage.structure.set_factories.ParentWithSetFactory`.
|
|
443
|
+
|
|
444
|
+
TESTS::
|
|
445
|
+
|
|
446
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
447
|
+
sage: P = XYPairs(y=1)
|
|
448
|
+
sage: P.single_pair(0)
|
|
449
|
+
{(0, 1)}
|
|
450
|
+
sage: P.single_pair(0).an_element().parent()
|
|
451
|
+
AllPairs
|
|
452
|
+
"""
|
|
453
|
+
return SingletonPair(letter, self._y, policy=self.facade_policy())
|
|
454
|
+
|
|
455
|
+
def check_element(self, el, check):
|
|
456
|
+
r"""
|
|
457
|
+
TESTS::
|
|
458
|
+
|
|
459
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
460
|
+
sage: P = XYPairs(y=1)
|
|
461
|
+
sage: P.check_element(P.an_element(), True)
|
|
462
|
+
sage: XYPairs(y=1)((1, 0)) # indirect doctest
|
|
463
|
+
Traceback (most recent call last):
|
|
464
|
+
...
|
|
465
|
+
ValueError: Wrong second coordinate
|
|
466
|
+
"""
|
|
467
|
+
(x, y) = el.value
|
|
468
|
+
if y != self._y:
|
|
469
|
+
raise ValueError("Wrong second coordinate")
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
class SingletonPair(ParentWithSetFactory, UniqueRepresentation):
|
|
473
|
+
r"""
|
|
474
|
+
TESTS::
|
|
475
|
+
|
|
476
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
477
|
+
sage: P = XYPairs(0,1); P.list()
|
|
478
|
+
[(0, 1)]
|
|
479
|
+
"""
|
|
480
|
+
def __init__(self, x, y, policy):
|
|
481
|
+
r"""
|
|
482
|
+
TESTS::
|
|
483
|
+
|
|
484
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
485
|
+
sage: TestSuite(XYPairs(0,1)).run()
|
|
486
|
+
"""
|
|
487
|
+
self._xy = (x, y)
|
|
488
|
+
ParentWithSetFactory.__init__(self, (x, y), policy=policy,
|
|
489
|
+
category=EnumeratedSets().Finite())
|
|
490
|
+
|
|
491
|
+
def _repr_(self):
|
|
492
|
+
"""
|
|
493
|
+
TESTS::
|
|
494
|
+
|
|
495
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
496
|
+
sage: XYPairs(x=2, y=1)
|
|
497
|
+
{(2, 1)}
|
|
498
|
+
"""
|
|
499
|
+
return "{%s}" % (self._xy,)
|
|
500
|
+
|
|
501
|
+
def check_element(self, el, check):
|
|
502
|
+
r"""
|
|
503
|
+
TESTS::
|
|
504
|
+
|
|
505
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
506
|
+
sage: XYPairs(0,1).check_element(XYPairs()((0,1)), True)
|
|
507
|
+
sage: XYPairs(0,1).check_element(XYPairs()((1,0)), True)
|
|
508
|
+
Traceback (most recent call last):
|
|
509
|
+
...
|
|
510
|
+
ValueError: Wrong coordinate
|
|
511
|
+
sage: XYPairs(0,1)((1,1))
|
|
512
|
+
Traceback (most recent call last):
|
|
513
|
+
...
|
|
514
|
+
ValueError: Wrong coordinate
|
|
515
|
+
"""
|
|
516
|
+
if el.value != self._xy:
|
|
517
|
+
raise ValueError("Wrong coordinate")
|
|
518
|
+
|
|
519
|
+
def __iter__(self):
|
|
520
|
+
r"""
|
|
521
|
+
TESTS::
|
|
522
|
+
|
|
523
|
+
sage: from sage.structure.set_factories_example import XYPairs
|
|
524
|
+
sage: list(XYPairs(0,1))
|
|
525
|
+
[(0, 1)]
|
|
526
|
+
"""
|
|
527
|
+
yield self._element_constructor_(self._xy, check=False)
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
r"""
|
|
3
|
+
Iterable of the keys of a Mapping associated with nonzero values
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from collections.abc import MappingView, Sequence, Set
|
|
7
|
+
|
|
8
|
+
from sage.misc.superseded import deprecation
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SupportView(MappingView, Sequence, Set):
|
|
12
|
+
r"""
|
|
13
|
+
Dynamic view of the set of keys of a dictionary that are associated with
|
|
14
|
+
nonzero values.
|
|
15
|
+
|
|
16
|
+
It behaves like the objects returned by the :meth:`keys`, :meth:`values`,
|
|
17
|
+
:meth:`items` of a dictionary (or other :class:`collections.abc.Mapping`
|
|
18
|
+
classes).
|
|
19
|
+
|
|
20
|
+
INPUT:
|
|
21
|
+
|
|
22
|
+
- ``mapping`` -- a :class:`dict` or another :class:`collections.abc.Mapping`
|
|
23
|
+
|
|
24
|
+
- ``zero`` -- (optional) test for zeroness by comparing with this value
|
|
25
|
+
|
|
26
|
+
EXAMPLES::
|
|
27
|
+
|
|
28
|
+
sage: d = {'a': 47, 'b': 0, 'c': 11}
|
|
29
|
+
sage: from sage.structure.support_view import SupportView
|
|
30
|
+
sage: supp = SupportView(d); supp
|
|
31
|
+
SupportView({'a': 47, 'b': 0, 'c': 11})
|
|
32
|
+
sage: 'a' in supp, 'b' in supp, 'z' in supp
|
|
33
|
+
(True, False, False)
|
|
34
|
+
sage: len(supp)
|
|
35
|
+
2
|
|
36
|
+
sage: list(supp)
|
|
37
|
+
['a', 'c']
|
|
38
|
+
sage: supp[0], supp[1]
|
|
39
|
+
('a', 'c')
|
|
40
|
+
sage: supp[-1]
|
|
41
|
+
'c'
|
|
42
|
+
sage: supp[:]
|
|
43
|
+
('a', 'c')
|
|
44
|
+
|
|
45
|
+
It reflects changes to the underlying dictionary::
|
|
46
|
+
|
|
47
|
+
sage: d['b'] = 815
|
|
48
|
+
sage: len(supp)
|
|
49
|
+
3
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def __init__(self, mapping, *, zero=None):
|
|
53
|
+
r"""
|
|
54
|
+
TESTS::
|
|
55
|
+
|
|
56
|
+
sage: from sage.structure.support_view import SupportView
|
|
57
|
+
sage: supp = SupportView({'a': 'b', 'c': ''}, zero='')
|
|
58
|
+
sage: len(supp)
|
|
59
|
+
1
|
|
60
|
+
"""
|
|
61
|
+
self._mapping = mapping
|
|
62
|
+
self._zero = zero
|
|
63
|
+
|
|
64
|
+
def __len__(self):
|
|
65
|
+
r"""
|
|
66
|
+
TESTS::
|
|
67
|
+
|
|
68
|
+
sage: d = {'a': 47, 'b': 0, 'c': 11}
|
|
69
|
+
sage: from sage.structure.support_view import SupportView
|
|
70
|
+
sage: supp = SupportView(d); supp
|
|
71
|
+
SupportView({'a': 47, 'b': 0, 'c': 11})
|
|
72
|
+
sage: len(supp)
|
|
73
|
+
2
|
|
74
|
+
"""
|
|
75
|
+
length = 0
|
|
76
|
+
for key in self:
|
|
77
|
+
length += 1
|
|
78
|
+
return length
|
|
79
|
+
|
|
80
|
+
def __getitem__(self, index):
|
|
81
|
+
r"""
|
|
82
|
+
TESTS::
|
|
83
|
+
|
|
84
|
+
sage: d = {'a': 47, 'b': 0, 'c': 11}
|
|
85
|
+
sage: from sage.structure.support_view import SupportView
|
|
86
|
+
sage: supp = SupportView(d); supp
|
|
87
|
+
SupportView({'a': 47, 'b': 0, 'c': 11})
|
|
88
|
+
sage: supp[2]
|
|
89
|
+
Traceback (most recent call last):
|
|
90
|
+
...
|
|
91
|
+
IndexError
|
|
92
|
+
"""
|
|
93
|
+
if isinstance(index, slice):
|
|
94
|
+
return tuple(self)[index]
|
|
95
|
+
if index < 0:
|
|
96
|
+
return tuple(self)[index]
|
|
97
|
+
for i, key in enumerate(self):
|
|
98
|
+
if i == index:
|
|
99
|
+
return key
|
|
100
|
+
raise IndexError
|
|
101
|
+
|
|
102
|
+
def __iter__(self):
|
|
103
|
+
r"""
|
|
104
|
+
TESTS::
|
|
105
|
+
|
|
106
|
+
sage: d = {'a': 47, 'b': 0, 'c': 11}
|
|
107
|
+
sage: from sage.structure.support_view import SupportView
|
|
108
|
+
sage: supp = SupportView(d); supp
|
|
109
|
+
SupportView({'a': 47, 'b': 0, 'c': 11})
|
|
110
|
+
sage: iter(supp)
|
|
111
|
+
<generator object SupportView.__iter__ at ...>
|
|
112
|
+
"""
|
|
113
|
+
zero = self._zero
|
|
114
|
+
if zero is None:
|
|
115
|
+
for key, value in self._mapping.items():
|
|
116
|
+
if value:
|
|
117
|
+
yield key
|
|
118
|
+
else:
|
|
119
|
+
for key, value in self._mapping.items():
|
|
120
|
+
if value != zero:
|
|
121
|
+
yield key
|
|
122
|
+
|
|
123
|
+
def __contains__(self, key):
|
|
124
|
+
r"""
|
|
125
|
+
TESTS::
|
|
126
|
+
|
|
127
|
+
sage: d = {'a': 47, 'b': 0, 'c': 11}
|
|
128
|
+
sage: from sage.structure.support_view import SupportView
|
|
129
|
+
sage: supp = SupportView(d); supp
|
|
130
|
+
SupportView({'a': 47, 'b': 0, 'c': 11})
|
|
131
|
+
sage: 'a' in supp, 'b' in supp, 'z' in supp
|
|
132
|
+
(True, False, False)
|
|
133
|
+
"""
|
|
134
|
+
try:
|
|
135
|
+
value = self._mapping[key]
|
|
136
|
+
except KeyError:
|
|
137
|
+
return False
|
|
138
|
+
zero = self._zero
|
|
139
|
+
if zero is None:
|
|
140
|
+
return bool(value)
|
|
141
|
+
return value != zero
|
|
142
|
+
|
|
143
|
+
def __eq__(self, other):
|
|
144
|
+
r"""
|
|
145
|
+
TESTS::
|
|
146
|
+
|
|
147
|
+
sage: d = {1: 17, 2: 0}
|
|
148
|
+
sage: from sage.structure.support_view import SupportView
|
|
149
|
+
sage: supp = SupportView(d); supp
|
|
150
|
+
SupportView({1: 17, 2: 0})
|
|
151
|
+
sage: supp == [1]
|
|
152
|
+
doctest:warning...
|
|
153
|
+
DeprecationWarning: comparing a SupportView with a list is deprecated
|
|
154
|
+
See https://github.com/sagemath/sage/issues/34509 for details.
|
|
155
|
+
True
|
|
156
|
+
"""
|
|
157
|
+
if isinstance(other, list):
|
|
158
|
+
deprecation(34509, 'comparing a SupportView with a list is deprecated')
|
|
159
|
+
return list(self) == other
|
|
160
|
+
return NotImplemented
|
|
161
|
+
|
|
162
|
+
def __ne__(self, other):
|
|
163
|
+
r"""
|
|
164
|
+
TESTS::
|
|
165
|
+
|
|
166
|
+
sage: d = {1: 17, 2: 0}
|
|
167
|
+
sage: from sage.structure.support_view import SupportView
|
|
168
|
+
sage: supp = SupportView(d); supp
|
|
169
|
+
SupportView({1: 17, 2: 0})
|
|
170
|
+
sage: supp != [1]
|
|
171
|
+
doctest:warning...
|
|
172
|
+
DeprecationWarning: comparing a SupportView with a list is deprecated
|
|
173
|
+
See https://github.com/sagemath/sage/issues/34509 for details.
|
|
174
|
+
False
|
|
175
|
+
"""
|
|
176
|
+
if isinstance(other, list):
|
|
177
|
+
deprecation(34509, 'comparing a SupportView with a list is deprecated')
|
|
178
|
+
return list(self) != other
|
|
179
|
+
return NotImplemented
|