passagemath-objects 10.6.41__cp312-cp312-win_amd64.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.
Files changed (281) hide show
  1. passagemath_objects/__init__.py +3 -0
  2. passagemath_objects-10.6.41.dist-info/DELVEWHEEL +2 -0
  3. passagemath_objects-10.6.41.dist-info/METADATA +115 -0
  4. passagemath_objects-10.6.41.dist-info/RECORD +281 -0
  5. passagemath_objects-10.6.41.dist-info/WHEEL +5 -0
  6. passagemath_objects-10.6.41.dist-info/top_level.txt +3 -0
  7. passagemath_objects.libs/libgmp-10-79b4110c7ea2b760f16cfef97e8a8a34.dll +0 -0
  8. sage/all__sagemath_objects.py +46 -0
  9. sage/arith/all__sagemath_objects.py +5 -0
  10. sage/arith/long.pxd +411 -0
  11. sage/arith/numerical_approx.cp312-win_amd64.pyd +0 -0
  12. sage/arith/numerical_approx.pxd +35 -0
  13. sage/arith/numerical_approx.pyx +75 -0
  14. sage/arith/power.cp312-win_amd64.pyd +0 -0
  15. sage/arith/power.pxd +31 -0
  16. sage/arith/power.pyx +127 -0
  17. sage/categories/action.cp312-win_amd64.pyd +0 -0
  18. sage/categories/action.pxd +29 -0
  19. sage/categories/action.pyx +641 -0
  20. sage/categories/algebra_functor.py +745 -0
  21. sage/categories/all__sagemath_objects.py +33 -0
  22. sage/categories/basic.py +71 -0
  23. sage/categories/cartesian_product.py +295 -0
  24. sage/categories/category.py +3401 -0
  25. sage/categories/category_cy_helper.cp312-win_amd64.pyd +0 -0
  26. sage/categories/category_cy_helper.pxd +8 -0
  27. sage/categories/category_cy_helper.pyx +322 -0
  28. sage/categories/category_singleton.cp312-win_amd64.pyd +0 -0
  29. sage/categories/category_singleton.pxd +3 -0
  30. sage/categories/category_singleton.pyx +342 -0
  31. sage/categories/category_types.py +637 -0
  32. sage/categories/category_with_axiom.py +2885 -0
  33. sage/categories/covariant_functorial_construction.py +703 -0
  34. sage/categories/facade_sets.py +228 -0
  35. sage/categories/functor.cp312-win_amd64.pyd +0 -0
  36. sage/categories/functor.pxd +7 -0
  37. sage/categories/functor.pyx +691 -0
  38. sage/categories/homset.py +1338 -0
  39. sage/categories/homsets.py +364 -0
  40. sage/categories/isomorphic_objects.py +73 -0
  41. sage/categories/map.cp312-win_amd64.pyd +0 -0
  42. sage/categories/map.pxd +34 -0
  43. sage/categories/map.pyx +2112 -0
  44. sage/categories/morphism.cp312-win_amd64.pyd +0 -0
  45. sage/categories/morphism.pxd +14 -0
  46. sage/categories/morphism.pyx +895 -0
  47. sage/categories/objects.py +167 -0
  48. sage/categories/primer.py +1696 -0
  49. sage/categories/pushout.py +4834 -0
  50. sage/categories/quotients.py +64 -0
  51. sage/categories/realizations.py +200 -0
  52. sage/categories/sets_cat.py +3228 -0
  53. sage/categories/sets_with_partial_maps.py +52 -0
  54. sage/categories/subobjects.py +64 -0
  55. sage/categories/subquotients.py +21 -0
  56. sage/categories/with_realizations.py +311 -0
  57. sage/cpython/__init__.py +28 -0
  58. sage/cpython/_py2_random.py +619 -0
  59. sage/cpython/all.py +3 -0
  60. sage/cpython/atexit.cp312-win_amd64.pyd +0 -0
  61. sage/cpython/atexit.pyx +269 -0
  62. sage/cpython/builtin_types.cp312-win_amd64.pyd +0 -0
  63. sage/cpython/builtin_types.pyx +7 -0
  64. sage/cpython/cython_metaclass.cp312-win_amd64.pyd +0 -0
  65. sage/cpython/cython_metaclass.h +117 -0
  66. sage/cpython/cython_metaclass.pxd +3 -0
  67. sage/cpython/cython_metaclass.pyx +130 -0
  68. sage/cpython/debug.cp312-win_amd64.pyd +0 -0
  69. sage/cpython/debug.pyx +302 -0
  70. sage/cpython/dict_del_by_value.cp312-win_amd64.pyd +0 -0
  71. sage/cpython/dict_del_by_value.pxd +9 -0
  72. sage/cpython/dict_del_by_value.pyx +191 -0
  73. sage/cpython/dict_internal.h +245 -0
  74. sage/cpython/getattr.cp312-win_amd64.pyd +0 -0
  75. sage/cpython/getattr.pxd +9 -0
  76. sage/cpython/getattr.pyx +439 -0
  77. sage/cpython/pycore_long.h +97 -0
  78. sage/cpython/pycore_long.pxd +10 -0
  79. sage/cpython/python_debug.h +44 -0
  80. sage/cpython/python_debug.pxd +47 -0
  81. sage/cpython/pyx_visit.h +13 -0
  82. sage/cpython/string.cp312-win_amd64.pyd +0 -0
  83. sage/cpython/string.pxd +76 -0
  84. sage/cpython/string.pyx +34 -0
  85. sage/cpython/string_impl.h +60 -0
  86. sage/cpython/type.cp312-win_amd64.pyd +0 -0
  87. sage/cpython/type.pxd +2 -0
  88. sage/cpython/type.pyx +40 -0
  89. sage/cpython/wrapperdescr.pxd +67 -0
  90. sage/ext/all__sagemath_objects.py +3 -0
  91. sage/ext/ccobject.h +64 -0
  92. sage/ext/cplusplus.pxd +17 -0
  93. sage/ext/mod_int.h +30 -0
  94. sage/ext/mod_int.pxd +24 -0
  95. sage/ext/stdsage.pxd +39 -0
  96. sage/groups/all__sagemath_objects.py +1 -0
  97. sage/groups/group.cp312-win_amd64.pyd +0 -0
  98. sage/groups/group.pxd +14 -0
  99. sage/groups/group.pyx +322 -0
  100. sage/groups/old.cp312-win_amd64.pyd +0 -0
  101. sage/groups/old.pxd +14 -0
  102. sage/groups/old.pyx +219 -0
  103. sage/libs/all__sagemath_objects.py +3 -0
  104. sage/libs/gmp/__init__.py +1 -0
  105. sage/libs/gmp/all.pxd +6 -0
  106. sage/libs/gmp/binop.pxd +23 -0
  107. sage/libs/gmp/misc.pxd +8 -0
  108. sage/libs/gmp/mpf.pxd +88 -0
  109. sage/libs/gmp/mpn.pxd +57 -0
  110. sage/libs/gmp/mpq.pxd +57 -0
  111. sage/libs/gmp/mpz.pxd +202 -0
  112. sage/libs/gmp/pylong.cp312-win_amd64.pyd +0 -0
  113. sage/libs/gmp/pylong.pxd +12 -0
  114. sage/libs/gmp/pylong.pyx +150 -0
  115. sage/libs/gmp/random.pxd +25 -0
  116. sage/libs/gmp/randomize.pxd +59 -0
  117. sage/libs/gmp/types.pxd +53 -0
  118. sage/libs/gmpxx.pxd +19 -0
  119. sage/misc/abstract_method.py +276 -0
  120. sage/misc/all__sagemath_objects.py +43 -0
  121. sage/misc/bindable_class.py +253 -0
  122. sage/misc/c3_controlled.cp312-win_amd64.pyd +0 -0
  123. sage/misc/c3_controlled.pxd +2 -0
  124. sage/misc/c3_controlled.pyx +1402 -0
  125. sage/misc/cachefunc.cp312-win_amd64.pyd +0 -0
  126. sage/misc/cachefunc.pxd +43 -0
  127. sage/misc/cachefunc.pyx +3781 -0
  128. sage/misc/call.py +188 -0
  129. sage/misc/classcall_metaclass.cp312-win_amd64.pyd +0 -0
  130. sage/misc/classcall_metaclass.pxd +14 -0
  131. sage/misc/classcall_metaclass.pyx +599 -0
  132. sage/misc/constant_function.cp312-win_amd64.pyd +0 -0
  133. sage/misc/constant_function.pyx +130 -0
  134. sage/misc/decorators.py +747 -0
  135. sage/misc/fast_methods.cp312-win_amd64.pyd +0 -0
  136. sage/misc/fast_methods.pxd +20 -0
  137. sage/misc/fast_methods.pyx +351 -0
  138. sage/misc/flatten.py +90 -0
  139. sage/misc/fpickle.cp312-win_amd64.pyd +0 -0
  140. sage/misc/fpickle.pyx +177 -0
  141. sage/misc/function_mangling.cp312-win_amd64.pyd +0 -0
  142. sage/misc/function_mangling.pxd +11 -0
  143. sage/misc/function_mangling.pyx +308 -0
  144. sage/misc/inherit_comparison.cp312-win_amd64.pyd +0 -0
  145. sage/misc/inherit_comparison.pxd +5 -0
  146. sage/misc/inherit_comparison.pyx +105 -0
  147. sage/misc/instancedoc.cp312-win_amd64.pyd +0 -0
  148. sage/misc/instancedoc.pyx +331 -0
  149. sage/misc/lazy_attribute.cp312-win_amd64.pyd +0 -0
  150. sage/misc/lazy_attribute.pyx +607 -0
  151. sage/misc/lazy_format.py +135 -0
  152. sage/misc/lazy_import.cp312-win_amd64.pyd +0 -0
  153. sage/misc/lazy_import.pyx +1299 -0
  154. sage/misc/lazy_import_cache.py +36 -0
  155. sage/misc/lazy_list.cp312-win_amd64.pyd +0 -0
  156. sage/misc/lazy_list.pxd +19 -0
  157. sage/misc/lazy_list.pyx +1187 -0
  158. sage/misc/lazy_string.cp312-win_amd64.pyd +0 -0
  159. sage/misc/lazy_string.pxd +7 -0
  160. sage/misc/lazy_string.pyx +546 -0
  161. sage/misc/misc.py +1066 -0
  162. sage/misc/misc_c.cp312-win_amd64.pyd +0 -0
  163. sage/misc/misc_c.pxd +3 -0
  164. sage/misc/misc_c.pyx +766 -0
  165. sage/misc/namespace_package.py +37 -0
  166. sage/misc/nested_class.cp312-win_amd64.pyd +0 -0
  167. sage/misc/nested_class.pxd +3 -0
  168. sage/misc/nested_class.pyx +394 -0
  169. sage/misc/persist.cp312-win_amd64.pyd +0 -0
  170. sage/misc/persist.pyx +1251 -0
  171. sage/misc/prandom.py +418 -0
  172. sage/misc/randstate.cp312-win_amd64.pyd +0 -0
  173. sage/misc/randstate.pxd +30 -0
  174. sage/misc/randstate.pyx +1059 -0
  175. sage/misc/repr.py +203 -0
  176. sage/misc/reset.cp312-win_amd64.pyd +0 -0
  177. sage/misc/reset.pyx +196 -0
  178. sage/misc/sage_ostools.cp312-win_amd64.pyd +0 -0
  179. sage/misc/sage_ostools.pyx +323 -0
  180. sage/misc/sage_timeit.py +276 -0
  181. sage/misc/sage_timeit_class.cp312-win_amd64.pyd +0 -0
  182. sage/misc/sage_timeit_class.pyx +120 -0
  183. sage/misc/sage_unittest.py +637 -0
  184. sage/misc/sageinspect.py +2768 -0
  185. sage/misc/session.cp312-win_amd64.pyd +0 -0
  186. sage/misc/session.pyx +392 -0
  187. sage/misc/superseded.py +557 -0
  188. sage/misc/test_nested_class.py +228 -0
  189. sage/misc/timing.py +264 -0
  190. sage/misc/unknown.py +222 -0
  191. sage/misc/verbose.py +253 -0
  192. sage/misc/weak_dict.cp312-win_amd64.pyd +0 -0
  193. sage/misc/weak_dict.pxd +15 -0
  194. sage/misc/weak_dict.pyx +1231 -0
  195. sage/modules/all__sagemath_objects.py +1 -0
  196. sage/modules/module.cp312-win_amd64.pyd +0 -0
  197. sage/modules/module.pxd +5 -0
  198. sage/modules/module.pyx +329 -0
  199. sage/rings/all__sagemath_objects.py +3 -0
  200. sage/rings/integer_fake.h +22 -0
  201. sage/rings/integer_fake.pxd +55 -0
  202. sage/sets/all__sagemath_objects.py +3 -0
  203. sage/sets/pythonclass.cp312-win_amd64.pyd +0 -0
  204. sage/sets/pythonclass.pxd +9 -0
  205. sage/sets/pythonclass.pyx +247 -0
  206. sage/structure/__init__.py +13 -0
  207. sage/structure/all.py +30 -0
  208. sage/structure/category_object.cp312-win_amd64.pyd +0 -0
  209. sage/structure/category_object.pxd +28 -0
  210. sage/structure/category_object.pyx +1087 -0
  211. sage/structure/coerce.cp312-win_amd64.pyd +0 -0
  212. sage/structure/coerce.pxd +44 -0
  213. sage/structure/coerce.pyx +2107 -0
  214. sage/structure/coerce_actions.cp312-win_amd64.pyd +0 -0
  215. sage/structure/coerce_actions.pxd +27 -0
  216. sage/structure/coerce_actions.pyx +988 -0
  217. sage/structure/coerce_dict.cp312-win_amd64.pyd +0 -0
  218. sage/structure/coerce_dict.pxd +51 -0
  219. sage/structure/coerce_dict.pyx +1557 -0
  220. sage/structure/coerce_exceptions.py +23 -0
  221. sage/structure/coerce_maps.cp312-win_amd64.pyd +0 -0
  222. sage/structure/coerce_maps.pxd +28 -0
  223. sage/structure/coerce_maps.pyx +718 -0
  224. sage/structure/debug_options.cp312-win_amd64.pyd +0 -0
  225. sage/structure/debug_options.pxd +6 -0
  226. sage/structure/debug_options.pyx +54 -0
  227. sage/structure/dynamic_class.py +541 -0
  228. sage/structure/element.cp312-win_amd64.pyd +0 -0
  229. sage/structure/element.pxd +272 -0
  230. sage/structure/element.pyx +4772 -0
  231. sage/structure/element_wrapper.cp312-win_amd64.pyd +0 -0
  232. sage/structure/element_wrapper.pxd +12 -0
  233. sage/structure/element_wrapper.pyx +582 -0
  234. sage/structure/factorization.py +1422 -0
  235. sage/structure/factorization_integer.py +105 -0
  236. sage/structure/factory.cp312-win_amd64.pyd +0 -0
  237. sage/structure/factory.pyx +786 -0
  238. sage/structure/formal_sum.py +489 -0
  239. sage/structure/gens_py.py +73 -0
  240. sage/structure/global_options.py +1743 -0
  241. sage/structure/indexed_generators.py +863 -0
  242. sage/structure/list_clone.cp312-win_amd64.pyd +0 -0
  243. sage/structure/list_clone.pxd +65 -0
  244. sage/structure/list_clone.pyx +1867 -0
  245. sage/structure/list_clone_demo.cp312-win_amd64.pyd +0 -0
  246. sage/structure/list_clone_demo.pyx +248 -0
  247. sage/structure/list_clone_timings.py +179 -0
  248. sage/structure/list_clone_timings_cy.cp312-win_amd64.pyd +0 -0
  249. sage/structure/list_clone_timings_cy.pyx +86 -0
  250. sage/structure/mutability.cp312-win_amd64.pyd +0 -0
  251. sage/structure/mutability.pxd +21 -0
  252. sage/structure/mutability.pyx +348 -0
  253. sage/structure/nonexact.py +69 -0
  254. sage/structure/parent.cp312-win_amd64.pyd +0 -0
  255. sage/structure/parent.pxd +112 -0
  256. sage/structure/parent.pyx +3093 -0
  257. sage/structure/parent_base.cp312-win_amd64.pyd +0 -0
  258. sage/structure/parent_base.pxd +13 -0
  259. sage/structure/parent_base.pyx +44 -0
  260. sage/structure/parent_gens.cp312-win_amd64.pyd +0 -0
  261. sage/structure/parent_gens.pxd +22 -0
  262. sage/structure/parent_gens.pyx +377 -0
  263. sage/structure/parent_old.cp312-win_amd64.pyd +0 -0
  264. sage/structure/parent_old.pxd +25 -0
  265. sage/structure/parent_old.pyx +294 -0
  266. sage/structure/proof/__init__.py +1 -0
  267. sage/structure/proof/all.py +243 -0
  268. sage/structure/proof/proof.py +300 -0
  269. sage/structure/richcmp.cp312-win_amd64.pyd +0 -0
  270. sage/structure/richcmp.pxd +213 -0
  271. sage/structure/richcmp.pyx +495 -0
  272. sage/structure/sage_object.cp312-win_amd64.pyd +0 -0
  273. sage/structure/sage_object.pxd +3 -0
  274. sage/structure/sage_object.pyx +988 -0
  275. sage/structure/sage_object_test.py +19 -0
  276. sage/structure/sequence.py +937 -0
  277. sage/structure/set_factories.py +1178 -0
  278. sage/structure/set_factories_example.py +527 -0
  279. sage/structure/support_view.py +179 -0
  280. sage/structure/test_factory.py +56 -0
  281. sage/structure/unique_representation.py +1359 -0
@@ -0,0 +1,937 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ r"""
3
+ Finite Homogeneous Sequences
4
+
5
+ A mutable sequence of elements with a common guaranteed category,
6
+ which can be set immutable.
7
+
8
+ Sequence derives from list, so has all the functionality of lists and
9
+ can be used wherever lists are used. When a sequence is created
10
+ without explicitly given the common universe of the elements, the
11
+ constructor coerces the first and second element to some
12
+ *canonical* common parent, if possible, then the second and
13
+ third, etc. If this is possible, it then coerces everything into the
14
+ canonical parent at the end. (Note that canonical coercion is very
15
+ restrictive.) The sequence then has a function ``universe()``
16
+ which returns either the common canonical parent (if the coercion
17
+ succeeded), or the category of all objects (Objects()). So if you
18
+ have a list `v` and type::
19
+
20
+ sage: v = [1, 2/3, 5]
21
+ sage: w = Sequence(v)
22
+ sage: w.universe()
23
+ Rational Field
24
+
25
+ then since ``w.universe()`` is `\QQ`, you're guaranteed that all
26
+ elements of `w` are rationals::
27
+
28
+ sage: v[0].parent()
29
+ Integer Ring
30
+ sage: w[0].parent()
31
+ Rational Field
32
+
33
+ If you do assignment to `w` this property of being rationals is guaranteed
34
+ to be preserved::
35
+
36
+ sage: w[0] = 2
37
+ sage: w[0].parent()
38
+ Rational Field
39
+ sage: w[0] = 'hi'
40
+ Traceback (most recent call last):
41
+ ...
42
+ TypeError: unable to convert 'hi' to a rational
43
+
44
+ However, if you do ``w = Sequence(v)`` and the resulting universe
45
+ is ``Objects()``, the elements are not guaranteed to have any
46
+ special parent. This is what should happen, e.g., with finite field
47
+ elements of different characteristics::
48
+
49
+ sage: v = Sequence([GF(3)(1), GF(7)(1)])
50
+ sage: v.universe()
51
+ Category of objects
52
+
53
+ You can make a list immutable with ``v.freeze()``. Assignment is
54
+ never again allowed on an immutable list.
55
+
56
+ Creation of a sequence involves making a copy of the input list, and
57
+ substantial coercions. It can be greatly sped up by explicitly
58
+ specifying the universe of the sequence::
59
+
60
+ sage: v = Sequence(range(10000), universe=ZZ)
61
+ """
62
+
63
+ # ****************************************************************************
64
+ # Copyright (C) 2006 William Stein <wstein@gmail.com>
65
+ #
66
+ # This program is free software: you can redistribute it and/or modify
67
+ # it under the terms of the GNU General Public License as published by
68
+ # the Free Software Foundation, either version 2 of the License, or
69
+ # (at your option) any later version.
70
+ # https://www.gnu.org/licenses/
71
+ # ****************************************************************************
72
+
73
+ from sage.misc.persist import register_unpickle_override
74
+ from sage.structure.sage_object import SageObject
75
+
76
+ from sage.misc.lazy_import import lazy_import
77
+
78
+ lazy_import('sage.rings.polynomial.multi_polynomial_ideal', 'MPolynomialIdeal')
79
+ lazy_import('sage.rings.polynomial.multi_polynomial_ring', 'MPolynomialRing_base')
80
+ lazy_import('sage.rings.polynomial.multi_polynomial_sequence', 'PolynomialSequence')
81
+ lazy_import('sage.rings.polynomial.pbori.pbori', 'BooleanMonomialMonoid')
82
+ lazy_import('sage.rings.quotient_ring', 'QuotientRing_nc')
83
+
84
+
85
+ def Sequence(x, universe=None, check=True, immutable=False, cr=False, cr_str=None, use_sage_types=False):
86
+ r"""
87
+ A mutable list of elements with a common guaranteed universe,
88
+ which can be set immutable.
89
+
90
+ A universe is either an object that supports coercion (e.g., a
91
+ parent), or a category.
92
+
93
+ INPUT:
94
+
95
+ - ``x`` -- list or tuple instance
96
+
97
+ - ``universe`` -- (default: ``None``) the universe of elements; if ``None``
98
+ determined using canonical coercions and the entire list of elements.
99
+ If list is empty, is category ``Objects()`` of all objects.
100
+
101
+ - ``check`` -- boolean (default: ``True``); whether to coerce the elements of x
102
+ into the universe
103
+
104
+ - ``immutable`` -- boolean (default: ``True``); whether or not this sequence is
105
+ immutable
106
+
107
+ - ``cr`` -- boolean (default: ``False``); if ``True``, then print a carriage return
108
+ after each comma when calling ``repr()`` on this sequence (see note below)
109
+
110
+ - ``cr_str`` -- boolean (default: same as ``cr``); if ``True``, then print a carriage return
111
+ after each comma when calling ``str()`` on this sequence (see note below)
112
+
113
+ - ``use_sage_types`` -- boolean (default: ``False``); if ``True``, coerce the
114
+ built-in Python numerical types int, float, complex to the corresponding
115
+ Sage types (this makes functions like ``vector()`` more flexible)
116
+
117
+ OUTPUT: a sequence
118
+
119
+ EXAMPLES::
120
+
121
+ sage: v = Sequence(range(10))
122
+ sage: v.universe()
123
+ <class 'int'>
124
+ sage: v
125
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
126
+
127
+ We can request that the built-in Python numerical types be coerced
128
+ to Sage objects::
129
+
130
+ sage: v = Sequence(range(10), use_sage_types=True)
131
+ sage: v.universe()
132
+ Integer Ring
133
+ sage: v
134
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
135
+
136
+ You can also use seq for "Sequence", which is identical to using
137
+ Sequence::
138
+
139
+ sage: v = seq([1,2,1/1]); v
140
+ [1, 2, 1]
141
+ sage: v.universe()
142
+ Rational Field
143
+
144
+ Note that assignment coerces if possible,::
145
+
146
+ sage: v = Sequence(range(10), ZZ)
147
+ sage: a = QQ(5)
148
+ sage: v[3] = a
149
+ sage: parent(v[3])
150
+ Integer Ring
151
+ sage: parent(a)
152
+ Rational Field
153
+ sage: v[3] = 2/3
154
+ Traceback (most recent call last):
155
+ ...
156
+ TypeError: no conversion of this rational to integer
157
+
158
+ Sequences can be used absolutely anywhere lists or tuples can be used::
159
+
160
+ sage: isinstance(v, list)
161
+ True
162
+
163
+ Sequence can be immutable, so entries can't be changed::
164
+
165
+ sage: v = Sequence([1,2,3], immutable=True)
166
+ sage: v.is_immutable()
167
+ True
168
+ sage: v[0] = 5
169
+ Traceback (most recent call last):
170
+ ...
171
+ ValueError: object is immutable; please change a copy instead.
172
+
173
+ Only immutable sequences are hashable (unlike Python lists),
174
+ though the hashing is potentially slow, since it first involves
175
+ conversion of the sequence to a tuple, and returning the hash of
176
+ that.::
177
+
178
+ sage: v = Sequence(range(10), ZZ, immutable=True)
179
+ sage: hash(v) == hash(tuple(range(10)))
180
+ True
181
+
182
+
183
+ If you really know what you are doing, you can circumvent the type
184
+ checking (for an efficiency gain)::
185
+
186
+ sage: list.__setitem__(v, int(1), 2/3) # bad circumvention
187
+ sage: v
188
+ [0, 2/3, 2, 3, 4, 5, 6, 7, 8, 9]
189
+ sage: list.__setitem__(v, int(1), int(2)) # not so bad circumvention
190
+
191
+ You can make a sequence with a new universe from an old sequence.::
192
+
193
+ sage: w = Sequence(v, QQ)
194
+ sage: w
195
+ [0, 2, 2, 3, 4, 5, 6, 7, 8, 9]
196
+ sage: w.universe()
197
+ Rational Field
198
+ sage: w[1] = 2/3
199
+ sage: w
200
+ [0, 2/3, 2, 3, 4, 5, 6, 7, 8, 9]
201
+
202
+ The default universe for any sequence, if no compatible parent structure
203
+ can be found, is the universe of all Sage objects.
204
+
205
+ This example illustrates how every element of a list is taken into account
206
+ when constructing a sequence.::
207
+
208
+ sage: v = Sequence([1, 7, 6, GF(5)(3)]); v
209
+ [1, 2, 1, 3]
210
+ sage: v.universe()
211
+ Finite Field of size 5
212
+
213
+ .. NOTE::
214
+
215
+ ``cr`` and ``cr_str`` is not recommended (because IPython's pretty printer is used);
216
+ nevertheless it is kept for backwards compatibility.
217
+
218
+ By default ``Sequence`` are printed using IPython's pretty printer,
219
+ so ``cr`` and ``cr_str`` are not taken into account at all::
220
+
221
+ sage: Sequence([1, 2, 3], cr=False)
222
+ [1, 2, 3]
223
+ sage: Sequence([1, 2, 3], cr=True)
224
+ [1, 2, 3]
225
+
226
+ Nevertheless, before the pretty printer exists, ``repr()`` is used.
227
+ Now ``cr`` and ``cr_str`` still affects the behavior of ``repr()`` and ``str()``::
228
+
229
+ sage: repr(Sequence([1, 2, 3], cr=False))
230
+ '[1, 2, 3]'
231
+ sage: repr(Sequence([1, 2, 3], cr=True))
232
+ '[\n1,\n2,\n3\n]'
233
+
234
+ In any case, this behavior should probably not be relied upon.
235
+
236
+ TESTS::
237
+
238
+ sage: Sequence(["a"], universe=ZZ)
239
+ Traceback (most recent call last):
240
+ ...
241
+ TypeError: unable to convert a to an element of Integer Ring
242
+
243
+ Here are some tests for ``cr`` and ``cr_str``, even though they shouldn't be used.
244
+ ``cr_str`` can be weird in this case, but we keep the current implementation
245
+ (the feature is not recommended anyway so it doesn't make much difference)::
246
+
247
+ sage: str(Sequence([1, 2, 3], cr=True, cr_str=True))
248
+ '[\n1,\n2,\n3\n]'
249
+ sage: str(Sequence([1, 2, 3], cr=True, cr_str=False))
250
+ '[\n1,\n2,\n3\n]'
251
+
252
+ In the opposite case, ``cr_str`` works fine::
253
+
254
+ sage: str(Sequence([1, 2, 3], cr=False, cr_str=False))
255
+ '[1, 2, 3]'
256
+ sage: str(Sequence([1, 2, 3], cr=False, cr_str=True))
257
+ '[\n1,\n2,\n3\n]'
258
+ sage: repr(Sequence([1, 2, 3], cr=False, cr_str=False))
259
+ '[1, 2, 3]'
260
+ sage: repr(Sequence([1, 2, 3], cr=False, cr_str=True))
261
+ '[1, 2, 3]'
262
+ """
263
+ if universe is None:
264
+ if isinstance(x, Sequence_generic):
265
+ universe = x.universe()
266
+ x = list(x)
267
+ else:
268
+ if isinstance(x, MPolynomialIdeal):
269
+ universe = x.ring()
270
+ x = x.gens()
271
+
272
+ if universe is None:
273
+ orig_x = x
274
+ x = list(x) # make a copy even if x is a list, we're going to change it
275
+
276
+ if len(x) == 0:
277
+ from sage.categories.objects import Objects
278
+ universe = Objects()
279
+ else:
280
+ import sage.structure.element
281
+ if use_sage_types:
282
+ # convert any Python built-in numerical types to Sage objects
283
+ x = [sage.structure.coerce.py_scalar_to_element(e) for e in x]
284
+ # start the pairwise coercion
285
+ for i in range(len(x) - 1):
286
+ try:
287
+ x[i], x[i+1] = sage.structure.element.canonical_coercion(x[i], x[i+1])
288
+ except TypeError:
289
+ from sage.categories.objects import Objects
290
+ universe = Objects()
291
+ x = list(orig_x)
292
+ check = False # no point
293
+ break
294
+ if universe is None: # no type errors raised.
295
+ universe = sage.structure.element.parent(x[len(x)-1])
296
+
297
+ if isinstance(universe, (MPolynomialRing_base, BooleanMonomialMonoid)) or (isinstance(universe, QuotientRing_nc) and isinstance(universe.cover_ring(), MPolynomialRing_base)):
298
+ return PolynomialSequence(x, universe, immutable=immutable, cr=cr, cr_str=cr_str)
299
+
300
+ return Sequence_generic(x, universe, check, immutable, cr, cr_str, use_sage_types)
301
+
302
+
303
+ class Sequence_generic(SageObject, list):
304
+ """
305
+ A mutable list of elements with a common guaranteed universe,
306
+ which can be set immutable.
307
+
308
+ A universe is either an object that supports coercion (e.g., a parent),
309
+ or a category.
310
+
311
+ INPUT:
312
+
313
+ - ``x`` -- list or tuple instance
314
+
315
+ - ``universe`` -- (default: ``None``) the universe of elements; if ``None``
316
+ determined using canonical coercions and the entire list of elements.
317
+ If list is empty, is category ``Objects()`` of all objects.
318
+
319
+ - ``check`` -- boolean (default: ``True``); whether to coerce the elements of x
320
+ into the universe
321
+
322
+ - ``immutable`` -- boolean (default: ``True``); whether or not this sequence is
323
+ immutable
324
+
325
+ - ``cr``, ``cr_str`` -- see :func:`Sequence`
326
+
327
+ - ``use_sage_types`` -- boolean (default: ``False``); if ``True``, coerce the
328
+ built-in Python numerical types int, float, complex to the corresponding
329
+ Sage types (this makes functions like ``vector()`` more flexible)
330
+
331
+ OUTPUT: a sequence
332
+
333
+ EXAMPLES::
334
+
335
+ sage: v = Sequence(range(10))
336
+ sage: v.universe()
337
+ <class 'int'>
338
+ sage: v
339
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
340
+
341
+ We can request that the built-in Python numerical types be coerced
342
+ to Sage objects::
343
+
344
+ sage: v = Sequence(range(10), use_sage_types=True)
345
+ sage: v.universe()
346
+ Integer Ring
347
+ sage: v
348
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
349
+
350
+ You can also use seq for "Sequence", which is identical to using Sequence::
351
+
352
+ sage: v = seq([1,2,1/1]); v
353
+ [1, 2, 1]
354
+ sage: v.universe()
355
+ Rational Field
356
+
357
+ Note that assignment coerces if possible,
358
+
359
+ ::
360
+
361
+ sage: v = Sequence(range(10), ZZ)
362
+ sage: a = QQ(5)
363
+ sage: v[3] = a
364
+ sage: parent(v[3])
365
+ Integer Ring
366
+ sage: parent(a)
367
+ Rational Field
368
+ sage: v[3] = 2/3
369
+ Traceback (most recent call last):
370
+ ...
371
+ TypeError: no conversion of this rational to integer
372
+
373
+ Sequences can be used absolutely anywhere lists or tuples can be used::
374
+
375
+ sage: isinstance(v, list)
376
+ True
377
+
378
+ Sequence can be immutable, so entries can't be changed::
379
+
380
+ sage: v = Sequence([1,2,3], immutable=True)
381
+ sage: v.is_immutable()
382
+ True
383
+ sage: v[0] = 5
384
+ Traceback (most recent call last):
385
+ ...
386
+ ValueError: object is immutable; please change a copy instead.
387
+
388
+ Only immutable sequences are hashable (unlike Python lists),
389
+ though the hashing is potentially slow, since it first involves
390
+ conversion of the sequence to a tuple, and returning the hash of
391
+ that.
392
+
393
+ ::
394
+
395
+ sage: v = Sequence(range(10), ZZ, immutable=True)
396
+ sage: hash(v) == hash(tuple(range(10)))
397
+ True
398
+
399
+
400
+ If you really know what you are doing, you can circumvent the type
401
+ checking (for an efficiency gain)::
402
+
403
+ sage: list.__setitem__(v, int(1), 2/3) # bad circumvention
404
+ sage: v
405
+ [0, 2/3, 2, 3, 4, 5, 6, 7, 8, 9]
406
+ sage: list.__setitem__(v, int(1), int(2)) # not so bad circumvention
407
+
408
+ You can make a sequence with a new universe from an old sequence.
409
+
410
+ ::
411
+
412
+ sage: w = Sequence(v, QQ)
413
+ sage: w
414
+ [0, 2, 2, 3, 4, 5, 6, 7, 8, 9]
415
+ sage: w.universe()
416
+ Rational Field
417
+ sage: w[1] = 2/3
418
+ sage: w
419
+ [0, 2/3, 2, 3, 4, 5, 6, 7, 8, 9]
420
+
421
+ The default universe for any sequence, if no compatible parent structure
422
+ can be found, is the universe of all Sage objects.
423
+
424
+ This example illustrates how every element of a list is taken into account
425
+ when constructing a sequence.
426
+
427
+ ::
428
+
429
+ sage: v = Sequence([1, 7, 6, GF(5)(3)]); v
430
+ [1, 2, 1, 3]
431
+ sage: v.universe()
432
+ Finite Field of size 5
433
+ """
434
+ def __init__(self, x, universe=None, check=True, immutable=False,
435
+ cr=False, cr_str=None, use_sage_types=False):
436
+ r"""
437
+ Create a sequence.
438
+
439
+ EXAMPLES::
440
+
441
+ sage: Sequence([1..5])
442
+ [1, 2, 3, 4, 5]
443
+ sage: a = Sequence([1..3], universe=QQ, check=False, immutable=True, cr=True, cr_str=False, use_sage_types=True)
444
+ sage: a
445
+ [1, 2, 3]
446
+ sage: a = Sequence([1..5], universe=QQ, check=False, immutable=True, cr_str=True, use_sage_types=True)
447
+ sage: a
448
+ [1, 2, 3, 4, 5]
449
+ sage: a._Sequence_generic__cr_str
450
+ True
451
+ sage: a.__str__()
452
+ '[\n1,\n2,\n3,\n4,\n5\n]'
453
+ """
454
+ self.__hash = None
455
+
456
+ self.__cr = cr
457
+ if cr_str is None:
458
+ self.__cr_str = cr
459
+ else:
460
+ self.__cr_str = cr_str
461
+
462
+ if isinstance(x, Sequence_generic):
463
+ if universe is None or universe == x.__universe:
464
+ list.__init__(self, x)
465
+ self.__universe = x.__universe
466
+ self._is_immutable = immutable
467
+ return
468
+
469
+ self.__universe = universe
470
+ if check:
471
+ x = list(x)
472
+ for i in range(len(x)):
473
+ try:
474
+ x[i] = universe(x[i])
475
+ except TypeError:
476
+ raise TypeError("unable to convert {} to an element of {}"
477
+ .format(x[i], universe))
478
+ list.__init__(self, x)
479
+ self._is_immutable = immutable
480
+
481
+ def reverse(self):
482
+ """
483
+ Reverse the elements of self, in place.
484
+
485
+ EXAMPLES::
486
+
487
+ sage: B = Sequence([1,2,3])
488
+ sage: B.reverse(); B
489
+ [3, 2, 1]
490
+ """
491
+ self._require_mutable()
492
+ list.reverse(self)
493
+
494
+ def __setitem__(self, n, value):
495
+ """
496
+ EXAMPLES::
497
+
498
+ sage: a = Sequence([1..5])
499
+ sage: a[2] = 19
500
+ sage: a
501
+ [1, 2, 19, 4, 5]
502
+ sage: a[2] = 'hello'
503
+ Traceback (most recent call last):
504
+ ...
505
+ TypeError: unable to convert 'hello' to an integer
506
+ sage: a[2] = '5'
507
+ sage: a
508
+ [1, 2, 5, 4, 5]
509
+ sage: v = Sequence([1,2,3,4], immutable=True)
510
+ sage: v[1:3] = [5,7]
511
+ Traceback (most recent call last):
512
+ ...
513
+ ValueError: object is immutable; please change a copy instead.
514
+ sage: v = Sequence([1,2,3,4])
515
+ sage: v[1:3] = [5, 3/1]
516
+ sage: v
517
+ [1, 5, 3, 4]
518
+ sage: type(v[2])
519
+ <class 'sage.rings.integer.Integer'>
520
+ """
521
+ self._require_mutable()
522
+ if isinstance(n, slice):
523
+ y = [self.__universe(x) for x in value]
524
+ else:
525
+ y = self.__universe(value)
526
+ list.__setitem__(self, n, y)
527
+ self.__hash = None
528
+
529
+ def __getitem__(self, n):
530
+ """
531
+ EXAMPLES::
532
+
533
+ sage: v = Sequence([1,2,3,4], immutable=True)
534
+ sage: w = v[2:]
535
+ sage: w
536
+ [3, 4]
537
+ sage: type(w)
538
+ <class 'sage.structure.sequence.Sequence_generic'>
539
+ sage: w[0] = 5; w
540
+ [5, 4]
541
+ sage: v
542
+ [1, 2, 3, 4]
543
+ """
544
+ if isinstance(n, slice):
545
+ return Sequence(list.__getitem__(self, n),
546
+ universe=self.__universe,
547
+ check=False,
548
+ immutable=False,
549
+ cr=self.__cr)
550
+
551
+ return list.__getitem__(self, n)
552
+
553
+ # We have to define the *slice functions as long as Sage uses Python 2.*
554
+ # otherwise the inherited *slice functions from list are called
555
+ def __getslice__(self, i, j):
556
+ return self.__getitem__(slice(i, j))
557
+
558
+ def __setslice__(self, i, j, value):
559
+ return self.__setitem__(slice(i, j), value)
560
+
561
+ def append(self, x):
562
+ """
563
+ EXAMPLES::
564
+
565
+ sage: v = Sequence([1,2,3,4], immutable=True)
566
+ sage: v.append(34)
567
+ Traceback (most recent call last):
568
+ ...
569
+ ValueError: object is immutable; please change a copy instead.
570
+ sage: v = Sequence([1/3,2,3,4])
571
+ sage: v.append(4)
572
+ sage: type(v[4])
573
+ <class 'sage.rings.rational.Rational'>
574
+ """
575
+ self._require_mutable()
576
+ y = self.__universe(x)
577
+ list.append(self, y)
578
+
579
+ def extend(self, iterable):
580
+ """
581
+ Extend list by appending elements from the iterable.
582
+
583
+ EXAMPLES::
584
+
585
+ sage: B = Sequence([1,2,3])
586
+ sage: B.extend(range(4))
587
+ sage: B
588
+ [1, 2, 3, 0, 1, 2, 3]
589
+ """
590
+ self._require_mutable()
591
+ v = [self.__universe(x) for x in iterable]
592
+ list.extend(self, v)
593
+
594
+ def insert(self, index, object):
595
+ """
596
+ Insert object before index.
597
+
598
+ EXAMPLES::
599
+
600
+ sage: B = Sequence([1,2,3])
601
+ sage: B.insert(10, 5)
602
+ sage: B
603
+ [1, 2, 3, 5]
604
+ """
605
+ self._require_mutable()
606
+ list.insert(self, index, self.__universe(object))
607
+
608
+ def pop(self, index=-1):
609
+ """
610
+ Remove and return item at index ``index`` (default: last).
611
+
612
+ EXAMPLES::
613
+
614
+ sage: B = Sequence([1,2,3])
615
+ sage: B.pop(1)
616
+ 2
617
+ sage: B
618
+ [1, 3]
619
+ """
620
+ self._require_mutable()
621
+ return list.pop(self, index)
622
+
623
+ def remove(self, value):
624
+ """
625
+ Remove first occurrence of ``value``.
626
+
627
+ EXAMPLES::
628
+
629
+ sage: B = Sequence([1,2,3])
630
+ sage: B.remove(2)
631
+ sage: B
632
+ [1, 3]
633
+ """
634
+ self._require_mutable()
635
+ list.remove(self, value)
636
+
637
+ def sort(self, key=None, reverse=False):
638
+ """
639
+ Sort this list *IN PLACE*.
640
+
641
+ INPUT:
642
+
643
+ - ``key`` -- see Python ``list sort``
644
+
645
+ - ``reverse`` -- see Python ``list sort``
646
+
647
+ EXAMPLES::
648
+
649
+ sage: B = Sequence([3,2,1/5])
650
+ sage: B.sort()
651
+ sage: B
652
+ [1/5, 2, 3]
653
+ sage: B.sort(reverse=True); B
654
+ [3, 2, 1/5]
655
+ """
656
+ self._require_mutable()
657
+ list.sort(self, key=key, reverse=reverse)
658
+
659
+ def __hash__(self):
660
+ """
661
+ EXAMPLES::
662
+
663
+ sage: a = Sequence([1..5])
664
+ sage: a.__hash__()
665
+ Traceback (most recent call last):
666
+ ...
667
+ ValueError: mutable sequences are unhashable
668
+ sage: a[0] = 10
669
+ sage: a.set_immutable()
670
+ sage: a.__hash__() == hash(a) == hash(tuple(a))
671
+ True
672
+ """
673
+ if not self._is_immutable:
674
+ raise ValueError("mutable sequences are unhashable")
675
+ if self.__hash is None:
676
+ self.__hash = hash(tuple(self))
677
+ return self.__hash
678
+
679
+ def _repr_(self):
680
+ """
681
+ Return a string representation of this sequence.
682
+ Typically, :meth:`_repr_pretty_` is used instead of this method.
683
+
684
+ EXAMPLES::
685
+
686
+ sage: Sequence([1,2/3,-2/5])._repr_()
687
+ '[1, 2/3, -2/5]'
688
+ sage: print(Sequence([1,2/3,-2/5], cr=True)._repr_())
689
+ [
690
+ 1,
691
+ 2/3,
692
+ -2/5
693
+ ]
694
+ """
695
+ if self.__cr:
696
+ return '[\n' + ',\n'.join(repr(x) for x in self) + '\n]'
697
+ else:
698
+ return list.__repr__(self)
699
+
700
+ def _repr_pretty_(self, p, cycle):
701
+ """
702
+ For pretty printing in the Sage command prompt.
703
+
704
+ Since ``Sequence`` inherits from ``list``, we just use IPython's built-in
705
+ ``list`` pretty printer.
706
+ When :issue:`36801` is fixed, this function will be redundant.
707
+
708
+ EXAMPLES::
709
+
710
+ sage: Sequence([1,2/3,-2/5]) # indirect doctest
711
+ [1, 2/3, -2/5]
712
+ """
713
+ p.pretty(list(self))
714
+
715
+ def _latex_(self):
716
+ r"""
717
+ TESTS::
718
+
719
+ sage: t= Sequence([sqrt(x), exp(x), x^(x-1)], universe=SR); t # needs sage.symbolic
720
+ [sqrt(x), e^x, x^(x - 1)]
721
+ sage: t._latex_() # needs sage.symbolic
722
+ '\\left[\\sqrt{x}, e^{x}, x^{x - 1}\\right]'
723
+ sage: latex(t) # needs sage.symbolic
724
+ \left[\sqrt{x}, e^{x}, x^{x - 1}\right]
725
+ """
726
+ from sage.misc.latex import list_function as list_latex_function
727
+ return list_latex_function(self)
728
+
729
+ def __str__(self):
730
+ r"""
731
+ EXAMPLES::
732
+
733
+ sage: s = Sequence([1,2,3], cr=False)
734
+ sage: str(s)
735
+ '[1, 2, 3]'
736
+ sage: repr(s)
737
+ '[1, 2, 3]'
738
+ sage: print(s)
739
+ [1, 2, 3]
740
+ sage: s = Sequence([1,2,3], cr=True)
741
+ sage: str(s)
742
+ '[\n1,\n2,\n3\n]'
743
+ """
744
+ if self.__cr_str:
745
+ return '[\n' + ',\n'.join(str(x) for x in self) + '\n]'
746
+ else:
747
+ return list.__str__(self)
748
+
749
+ def universe(self):
750
+ """
751
+ Return the universe of the sequence.
752
+
753
+ EXAMPLES::
754
+
755
+ sage: Sequence([1, 2/3, -2/5]).universe()
756
+ Rational Field
757
+ sage: Sequence([1, 2/3, '-2/5']).universe()
758
+ Category of objects
759
+ """
760
+ return self.__universe
761
+
762
+ def _require_mutable(self):
763
+ """
764
+ EXAMPLES::
765
+
766
+ sage: a = Sequence([1,2/3,'-2/5'])
767
+ sage: a._require_mutable()
768
+ sage: a.set_immutable()
769
+ sage: a._require_mutable()
770
+ Traceback (most recent call last):
771
+ ...
772
+ ValueError: object is immutable; please change a copy instead.
773
+ """
774
+ if self._is_immutable:
775
+ raise ValueError("object is immutable; please change a copy instead.")
776
+
777
+ def set_immutable(self):
778
+ """
779
+ Make this object immutable, so it can never again be changed.
780
+
781
+ EXAMPLES::
782
+
783
+ sage: v = Sequence([1, 2, 3, 4/5])
784
+ sage: v[0] = 5
785
+ sage: v
786
+ [5, 2, 3, 4/5]
787
+ sage: v.set_immutable()
788
+ sage: v[3] = 7
789
+ Traceback (most recent call last):
790
+ ...
791
+ ValueError: object is immutable; please change a copy instead.
792
+ """
793
+ self._is_immutable = True
794
+
795
+ def is_immutable(self):
796
+ """
797
+ Return ``True`` if this object is immutable (can not be changed)
798
+ and ``False`` if it is not.
799
+
800
+ To make this object immutable use :meth:`set_immutable`.
801
+
802
+ EXAMPLES::
803
+
804
+ sage: v = Sequence([1, 2, 3, 4/5])
805
+ sage: v[0] = 5
806
+ sage: v
807
+ [5, 2, 3, 4/5]
808
+ sage: v.is_immutable()
809
+ False
810
+ sage: v.set_immutable()
811
+ sage: v.is_immutable()
812
+ True
813
+ """
814
+ try:
815
+ return self._is_immutable
816
+ except AttributeError:
817
+ return False
818
+
819
+ def is_mutable(self):
820
+ """
821
+ EXAMPLES::
822
+
823
+ sage: a = Sequence([1, 2/3, -2/5])
824
+ sage: a.is_mutable()
825
+ True
826
+ sage: a[0] = 100
827
+ sage: type(a[0])
828
+ <class 'sage.rings.rational.Rational'>
829
+ sage: a.set_immutable()
830
+ sage: a[0] = 50
831
+ Traceback (most recent call last):
832
+ ...
833
+ ValueError: object is immutable; please change a copy instead.
834
+ sage: a.is_mutable()
835
+ False
836
+ """
837
+ try:
838
+ return not self._is_immutable
839
+ except AttributeError:
840
+ return True
841
+
842
+ def __reduce__(self):
843
+ """
844
+ Implement pickling for sequences.
845
+
846
+ TESTS::
847
+
848
+ sage: v = Sequence([1..5])
849
+ sage: w = loads(dumps(v))
850
+ sage: v == w
851
+ True
852
+ sage: w.is_mutable()
853
+ True
854
+ sage: v.set_immutable()
855
+ sage: w = loads(dumps(v))
856
+ sage: w.is_mutable()
857
+ False
858
+ """
859
+ args = (list(self), self.__universe, False,
860
+ self._is_immutable, self.__cr_str)
861
+ return type(self), args
862
+
863
+ def __copy__(self):
864
+ """
865
+ Return a copy of this sequence.
866
+
867
+ EXAMPLES::
868
+
869
+ sage: s = seq(range(10))
870
+ sage: t = copy(s)
871
+ sage: t == s
872
+ True
873
+ sage: t.is_immutable() == s.is_immutable()
874
+ True
875
+ sage: t.is_mutable() == s.is_mutable()
876
+ True
877
+ """
878
+ return Sequence(self, universe=self.__universe,
879
+ check=False,
880
+ immutable=self._is_immutable,
881
+ cr=self.__cr_str)
882
+
883
+ def __getattr__(self, name):
884
+ """
885
+ Strictly for unpickling old 'Sequences'.
886
+
887
+ INPUT:
888
+
889
+ - ``name`` -- some string
890
+
891
+ TESTS::
892
+
893
+ sage: S = Sequence([])
894
+ sage: del S._Sequence_generic__universe
895
+ sage: S.universe()
896
+ Traceback (most recent call last):
897
+ ...
898
+ AttributeError: 'Sequence_generic' object has no attribute '_Sequence_generic__universe'...
899
+ sage: S._Sequence__universe = 'foobar'
900
+ sage: S.universe()
901
+ 'foobar'
902
+
903
+ We test that :issue:`13998` is fixed::
904
+
905
+ sage: S = Sequence([])
906
+ sage: S.set_immutable()
907
+ sage: del S._Sequence_generic__hash
908
+ sage: hash(S)
909
+ Traceback (most recent call last):
910
+ ...
911
+ AttributeError: 'Sequence_generic' object has no attribute '_Sequence_generic__hash'...
912
+ sage: S._Sequence__hash = int(34)
913
+ sage: hash(S)
914
+ 34
915
+ """
916
+ if name == "_Sequence_generic__cr" and hasattr(self, "_Sequence__cr"):
917
+ self.__cr = self._Sequence__cr
918
+ return self.__cr
919
+ if name == "_Sequence_generic__cr_str" and hasattr(self, "_Sequence__cr_str"):
920
+ self.__cr_str = self._Sequence__cr_str
921
+ return self.__cr_str
922
+ if name == "_Sequence_generic__immutable" and hasattr(self, "_Sequence__immutable"):
923
+ self.__immutable = self._Sequence__immutable
924
+ return self.__immutable
925
+ if name == "_Sequence_generic__universe" and hasattr(self, "_Sequence__universe"):
926
+ self.__universe = self._Sequence__universe
927
+ return self.__universe
928
+ if name == "_Sequence_generic__hash" and hasattr(self, "_Sequence__hash"):
929
+ self.__hash = self._Sequence__hash
930
+ return self.__hash
931
+
932
+ raise AttributeError("'Sequence_generic' object has no attribute '%s'" % name)
933
+
934
+
935
+ seq = Sequence
936
+
937
+ register_unpickle_override('sage.structure.sequence', 'Sequence', Sequence_generic)