passagemath-categories 10.6.32__cp314-cp314t-musllinux_1_2_aarch64.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 (719) hide show
  1. passagemath_categories-10.6.32.dist-info/METADATA +156 -0
  2. passagemath_categories-10.6.32.dist-info/RECORD +719 -0
  3. passagemath_categories-10.6.32.dist-info/WHEEL +5 -0
  4. passagemath_categories-10.6.32.dist-info/top_level.txt +2 -0
  5. passagemath_categories.libs/libgcc_s-2d945d6c.so.1 +0 -0
  6. passagemath_categories.libs/libgmp-28992bcb.so.10.5.0 +0 -0
  7. passagemath_categories.libs/libstdc++-85f2cd6d.so.6.0.33 +0 -0
  8. sage/all__sagemath_categories.py +28 -0
  9. sage/arith/all.py +38 -0
  10. sage/arith/constants.pxd +27 -0
  11. sage/arith/functions.cpython-314t-aarch64-linux-musl.so +0 -0
  12. sage/arith/functions.pxd +4 -0
  13. sage/arith/functions.pyx +221 -0
  14. sage/arith/misc.py +6552 -0
  15. sage/arith/multi_modular.cpython-314t-aarch64-linux-musl.so +0 -0
  16. sage/arith/multi_modular.pxd +39 -0
  17. sage/arith/multi_modular.pyx +994 -0
  18. sage/arith/rational_reconstruction.cpython-314t-aarch64-linux-musl.so +0 -0
  19. sage/arith/rational_reconstruction.pxd +4 -0
  20. sage/arith/rational_reconstruction.pyx +115 -0
  21. sage/arith/srange.cpython-314t-aarch64-linux-musl.so +0 -0
  22. sage/arith/srange.pyx +571 -0
  23. sage/calculus/all__sagemath_categories.py +2 -0
  24. sage/calculus/functional.py +481 -0
  25. sage/calculus/functions.py +151 -0
  26. sage/categories/additive_groups.py +73 -0
  27. sage/categories/additive_magmas.py +1044 -0
  28. sage/categories/additive_monoids.py +114 -0
  29. sage/categories/additive_semigroups.py +184 -0
  30. sage/categories/affine_weyl_groups.py +238 -0
  31. sage/categories/algebra_ideals.py +95 -0
  32. sage/categories/algebra_modules.py +96 -0
  33. sage/categories/algebras.py +349 -0
  34. sage/categories/algebras_with_basis.py +377 -0
  35. sage/categories/all.py +160 -0
  36. sage/categories/aperiodic_semigroups.py +29 -0
  37. sage/categories/associative_algebras.py +47 -0
  38. sage/categories/bialgebras.py +101 -0
  39. sage/categories/bialgebras_with_basis.py +414 -0
  40. sage/categories/bimodules.py +206 -0
  41. sage/categories/chain_complexes.py +268 -0
  42. sage/categories/classical_crystals.py +480 -0
  43. sage/categories/coalgebras.py +405 -0
  44. sage/categories/coalgebras_with_basis.py +232 -0
  45. sage/categories/coercion_methods.cpython-314t-aarch64-linux-musl.so +0 -0
  46. sage/categories/coercion_methods.pyx +52 -0
  47. sage/categories/commutative_additive_groups.py +104 -0
  48. sage/categories/commutative_additive_monoids.py +45 -0
  49. sage/categories/commutative_additive_semigroups.py +48 -0
  50. sage/categories/commutative_algebra_ideals.py +87 -0
  51. sage/categories/commutative_algebras.py +94 -0
  52. sage/categories/commutative_ring_ideals.py +58 -0
  53. sage/categories/commutative_rings.py +736 -0
  54. sage/categories/complete_discrete_valuation.py +293 -0
  55. sage/categories/complex_reflection_groups.py +145 -0
  56. sage/categories/complex_reflection_or_generalized_coxeter_groups.py +1249 -0
  57. sage/categories/coxeter_group_algebras.py +186 -0
  58. sage/categories/coxeter_groups.py +3402 -0
  59. sage/categories/crystals.py +2628 -0
  60. sage/categories/cw_complexes.py +216 -0
  61. sage/categories/dedekind_domains.py +137 -0
  62. sage/categories/discrete_valuation.py +325 -0
  63. sage/categories/distributive_magmas_and_additive_magmas.py +100 -0
  64. sage/categories/division_rings.py +114 -0
  65. sage/categories/domains.py +95 -0
  66. sage/categories/drinfeld_modules.py +789 -0
  67. sage/categories/dual.py +42 -0
  68. sage/categories/enumerated_sets.py +1146 -0
  69. sage/categories/euclidean_domains.py +271 -0
  70. sage/categories/examples/algebras_with_basis.py +102 -0
  71. sage/categories/examples/all.py +1 -0
  72. sage/categories/examples/commutative_additive_monoids.py +130 -0
  73. sage/categories/examples/commutative_additive_semigroups.py +199 -0
  74. sage/categories/examples/coxeter_groups.py +8 -0
  75. sage/categories/examples/crystals.py +236 -0
  76. sage/categories/examples/cw_complexes.py +163 -0
  77. sage/categories/examples/facade_sets.py +187 -0
  78. sage/categories/examples/filtered_algebras_with_basis.py +204 -0
  79. sage/categories/examples/filtered_modules_with_basis.py +154 -0
  80. sage/categories/examples/finite_coxeter_groups.py +252 -0
  81. sage/categories/examples/finite_dimensional_algebras_with_basis.py +148 -0
  82. sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py +495 -0
  83. sage/categories/examples/finite_enumerated_sets.py +208 -0
  84. sage/categories/examples/finite_monoids.py +150 -0
  85. sage/categories/examples/finite_semigroups.py +190 -0
  86. sage/categories/examples/finite_weyl_groups.py +191 -0
  87. sage/categories/examples/graded_connected_hopf_algebras_with_basis.py +152 -0
  88. sage/categories/examples/graded_modules_with_basis.py +168 -0
  89. sage/categories/examples/graphs.py +122 -0
  90. sage/categories/examples/hopf_algebras_with_basis.py +145 -0
  91. sage/categories/examples/infinite_enumerated_sets.py +190 -0
  92. sage/categories/examples/lie_algebras.py +352 -0
  93. sage/categories/examples/lie_algebras_with_basis.py +196 -0
  94. sage/categories/examples/magmas.py +162 -0
  95. sage/categories/examples/manifolds.py +94 -0
  96. sage/categories/examples/monoids.py +144 -0
  97. sage/categories/examples/posets.py +178 -0
  98. sage/categories/examples/semigroups.py +580 -0
  99. sage/categories/examples/semigroups_cython.cpython-314t-aarch64-linux-musl.so +0 -0
  100. sage/categories/examples/semigroups_cython.pyx +221 -0
  101. sage/categories/examples/semirings.py +249 -0
  102. sage/categories/examples/sets_cat.py +706 -0
  103. sage/categories/examples/sets_with_grading.py +101 -0
  104. sage/categories/examples/with_realizations.py +542 -0
  105. sage/categories/fields.py +991 -0
  106. sage/categories/filtered_algebras.py +63 -0
  107. sage/categories/filtered_algebras_with_basis.py +548 -0
  108. sage/categories/filtered_hopf_algebras_with_basis.py +138 -0
  109. sage/categories/filtered_modules.py +210 -0
  110. sage/categories/filtered_modules_with_basis.py +1209 -0
  111. sage/categories/finite_complex_reflection_groups.py +1506 -0
  112. sage/categories/finite_coxeter_groups.py +1138 -0
  113. sage/categories/finite_crystals.py +103 -0
  114. sage/categories/finite_dimensional_algebras_with_basis.py +1860 -0
  115. sage/categories/finite_dimensional_bialgebras_with_basis.py +33 -0
  116. sage/categories/finite_dimensional_coalgebras_with_basis.py +33 -0
  117. sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py +231 -0
  118. sage/categories/finite_dimensional_hopf_algebras_with_basis.py +38 -0
  119. sage/categories/finite_dimensional_lie_algebras_with_basis.py +2774 -0
  120. sage/categories/finite_dimensional_modules_with_basis.py +1407 -0
  121. sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py +167 -0
  122. sage/categories/finite_dimensional_semisimple_algebras_with_basis.py +270 -0
  123. sage/categories/finite_enumerated_sets.py +769 -0
  124. sage/categories/finite_fields.py +252 -0
  125. sage/categories/finite_groups.py +256 -0
  126. sage/categories/finite_lattice_posets.py +242 -0
  127. sage/categories/finite_monoids.py +316 -0
  128. sage/categories/finite_permutation_groups.py +339 -0
  129. sage/categories/finite_posets.py +1994 -0
  130. sage/categories/finite_semigroups.py +136 -0
  131. sage/categories/finite_sets.py +93 -0
  132. sage/categories/finite_weyl_groups.py +39 -0
  133. sage/categories/finitely_generated_lambda_bracket_algebras.py +112 -0
  134. sage/categories/finitely_generated_lie_conformal_algebras.py +114 -0
  135. sage/categories/finitely_generated_magmas.py +57 -0
  136. sage/categories/finitely_generated_semigroups.py +214 -0
  137. sage/categories/function_fields.py +76 -0
  138. sage/categories/g_sets.py +77 -0
  139. sage/categories/gcd_domains.py +65 -0
  140. sage/categories/generalized_coxeter_groups.py +94 -0
  141. sage/categories/graded_algebras.py +85 -0
  142. sage/categories/graded_algebras_with_basis.py +258 -0
  143. sage/categories/graded_bialgebras.py +32 -0
  144. sage/categories/graded_bialgebras_with_basis.py +32 -0
  145. sage/categories/graded_coalgebras.py +65 -0
  146. sage/categories/graded_coalgebras_with_basis.py +51 -0
  147. sage/categories/graded_hopf_algebras.py +41 -0
  148. sage/categories/graded_hopf_algebras_with_basis.py +169 -0
  149. sage/categories/graded_lie_algebras.py +91 -0
  150. sage/categories/graded_lie_algebras_with_basis.py +44 -0
  151. sage/categories/graded_lie_conformal_algebras.py +74 -0
  152. sage/categories/graded_modules.py +133 -0
  153. sage/categories/graded_modules_with_basis.py +329 -0
  154. sage/categories/graphs.py +138 -0
  155. sage/categories/group_algebras.py +430 -0
  156. sage/categories/groupoid.py +94 -0
  157. sage/categories/groups.py +667 -0
  158. sage/categories/h_trivial_semigroups.py +64 -0
  159. sage/categories/hecke_modules.py +185 -0
  160. sage/categories/highest_weight_crystals.py +980 -0
  161. sage/categories/hopf_algebras.py +219 -0
  162. sage/categories/hopf_algebras_with_basis.py +309 -0
  163. sage/categories/infinite_enumerated_sets.py +115 -0
  164. sage/categories/integral_domains.py +203 -0
  165. sage/categories/j_trivial_semigroups.py +29 -0
  166. sage/categories/kac_moody_algebras.py +82 -0
  167. sage/categories/kahler_algebras.py +203 -0
  168. sage/categories/l_trivial_semigroups.py +63 -0
  169. sage/categories/lambda_bracket_algebras.py +280 -0
  170. sage/categories/lambda_bracket_algebras_with_basis.py +107 -0
  171. sage/categories/lattice_posets.py +89 -0
  172. sage/categories/left_modules.py +49 -0
  173. sage/categories/lie_algebras.py +1070 -0
  174. sage/categories/lie_algebras_with_basis.py +261 -0
  175. sage/categories/lie_conformal_algebras.py +350 -0
  176. sage/categories/lie_conformal_algebras_with_basis.py +147 -0
  177. sage/categories/lie_groups.py +73 -0
  178. sage/categories/loop_crystals.py +1290 -0
  179. sage/categories/magmas.py +1189 -0
  180. sage/categories/magmas_and_additive_magmas.py +149 -0
  181. sage/categories/magmatic_algebras.py +365 -0
  182. sage/categories/manifolds.py +352 -0
  183. sage/categories/matrix_algebras.py +40 -0
  184. sage/categories/metric_spaces.py +387 -0
  185. sage/categories/modular_abelian_varieties.py +78 -0
  186. sage/categories/modules.py +989 -0
  187. sage/categories/modules_with_basis.py +2794 -0
  188. sage/categories/monoid_algebras.py +38 -0
  189. sage/categories/monoids.py +739 -0
  190. sage/categories/noetherian_rings.py +87 -0
  191. sage/categories/number_fields.py +242 -0
  192. sage/categories/ore_modules.py +189 -0
  193. sage/categories/partially_ordered_monoids.py +49 -0
  194. sage/categories/permutation_groups.py +63 -0
  195. sage/categories/pointed_sets.py +42 -0
  196. sage/categories/polyhedra.py +74 -0
  197. sage/categories/poor_man_map.py +270 -0
  198. sage/categories/posets.py +722 -0
  199. sage/categories/principal_ideal_domains.py +270 -0
  200. sage/categories/quantum_group_representations.py +543 -0
  201. sage/categories/quotient_fields.py +728 -0
  202. sage/categories/r_trivial_semigroups.py +45 -0
  203. sage/categories/regular_crystals.py +898 -0
  204. sage/categories/regular_supercrystals.py +170 -0
  205. sage/categories/right_modules.py +49 -0
  206. sage/categories/ring_ideals.py +74 -0
  207. sage/categories/rings.py +1904 -0
  208. sage/categories/rngs.py +175 -0
  209. sage/categories/schemes.py +393 -0
  210. sage/categories/semigroups.py +1060 -0
  211. sage/categories/semirings.py +71 -0
  212. sage/categories/semisimple_algebras.py +114 -0
  213. sage/categories/sets_with_grading.py +235 -0
  214. sage/categories/shephard_groups.py +43 -0
  215. sage/categories/signed_tensor.py +120 -0
  216. sage/categories/simplicial_complexes.py +134 -0
  217. sage/categories/simplicial_sets.py +1206 -0
  218. sage/categories/super_algebras.py +149 -0
  219. sage/categories/super_algebras_with_basis.py +144 -0
  220. sage/categories/super_hopf_algebras_with_basis.py +126 -0
  221. sage/categories/super_lie_conformal_algebras.py +193 -0
  222. sage/categories/super_modules.py +229 -0
  223. sage/categories/super_modules_with_basis.py +193 -0
  224. sage/categories/supercommutative_algebras.py +99 -0
  225. sage/categories/supercrystals.py +406 -0
  226. sage/categories/tensor.py +110 -0
  227. sage/categories/topological_spaces.py +170 -0
  228. sage/categories/triangular_kac_moody_algebras.py +439 -0
  229. sage/categories/tutorial.py +58 -0
  230. sage/categories/unique_factorization_domains.py +318 -0
  231. sage/categories/unital_algebras.py +426 -0
  232. sage/categories/vector_bundles.py +159 -0
  233. sage/categories/vector_spaces.py +357 -0
  234. sage/categories/weyl_groups.py +853 -0
  235. sage/combinat/all__sagemath_categories.py +34 -0
  236. sage/combinat/backtrack.py +180 -0
  237. sage/combinat/combinat.py +2269 -0
  238. sage/combinat/combinat_cython.cpython-314t-aarch64-linux-musl.so +0 -0
  239. sage/combinat/combinat_cython.pxd +6 -0
  240. sage/combinat/combinat_cython.pyx +390 -0
  241. sage/combinat/combination.py +796 -0
  242. sage/combinat/combinatorial_map.py +416 -0
  243. sage/combinat/composition.py +2192 -0
  244. sage/combinat/dlx.py +510 -0
  245. sage/combinat/integer_lists/__init__.py +7 -0
  246. sage/combinat/integer_lists/base.cpython-314t-aarch64-linux-musl.so +0 -0
  247. sage/combinat/integer_lists/base.pxd +16 -0
  248. sage/combinat/integer_lists/base.pyx +713 -0
  249. sage/combinat/integer_lists/invlex.cpython-314t-aarch64-linux-musl.so +0 -0
  250. sage/combinat/integer_lists/invlex.pxd +4 -0
  251. sage/combinat/integer_lists/invlex.pyx +1650 -0
  252. sage/combinat/integer_lists/lists.py +328 -0
  253. sage/combinat/integer_lists/nn.py +48 -0
  254. sage/combinat/integer_vector.py +1818 -0
  255. sage/combinat/integer_vector_weighted.py +413 -0
  256. sage/combinat/matrices/all__sagemath_categories.py +5 -0
  257. sage/combinat/matrices/dancing_links.cpython-314t-aarch64-linux-musl.so +0 -0
  258. sage/combinat/matrices/dancing_links.pyx +1159 -0
  259. sage/combinat/matrices/dancing_links_c.h +380 -0
  260. sage/combinat/matrices/dlxcpp.py +136 -0
  261. sage/combinat/partition.py +10070 -0
  262. sage/combinat/partitions.cpython-314t-aarch64-linux-musl.so +0 -0
  263. sage/combinat/partitions.pyx +743 -0
  264. sage/combinat/permutation.py +10168 -0
  265. sage/combinat/permutation_cython.cpython-314t-aarch64-linux-musl.so +0 -0
  266. sage/combinat/permutation_cython.pxd +11 -0
  267. sage/combinat/permutation_cython.pyx +407 -0
  268. sage/combinat/q_analogues.py +1090 -0
  269. sage/combinat/ranker.py +268 -0
  270. sage/combinat/subset.py +1561 -0
  271. sage/combinat/subsets_hereditary.py +202 -0
  272. sage/combinat/subsets_pairwise.py +184 -0
  273. sage/combinat/tools.py +63 -0
  274. sage/combinat/tuple.py +348 -0
  275. sage/data_structures/all.py +2 -0
  276. sage/data_structures/all__sagemath_categories.py +2 -0
  277. sage/data_structures/binary_matrix.pxd +138 -0
  278. sage/data_structures/binary_search.cpython-314t-aarch64-linux-musl.so +0 -0
  279. sage/data_structures/binary_search.pxd +3 -0
  280. sage/data_structures/binary_search.pyx +66 -0
  281. sage/data_structures/bitset.cpython-314t-aarch64-linux-musl.so +0 -0
  282. sage/data_structures/bitset.pxd +40 -0
  283. sage/data_structures/bitset.pyx +2385 -0
  284. sage/data_structures/bitset_base.cpython-314t-aarch64-linux-musl.so +0 -0
  285. sage/data_structures/bitset_base.pxd +926 -0
  286. sage/data_structures/bitset_base.pyx +117 -0
  287. sage/data_structures/bitset_intrinsics.h +487 -0
  288. sage/data_structures/blas_dict.cpython-314t-aarch64-linux-musl.so +0 -0
  289. sage/data_structures/blas_dict.pxd +12 -0
  290. sage/data_structures/blas_dict.pyx +469 -0
  291. sage/data_structures/list_of_pairs.cpython-314t-aarch64-linux-musl.so +0 -0
  292. sage/data_structures/list_of_pairs.pxd +16 -0
  293. sage/data_structures/list_of_pairs.pyx +122 -0
  294. sage/data_structures/mutable_poset.py +3312 -0
  295. sage/data_structures/pairing_heap.cpython-314t-aarch64-linux-musl.so +0 -0
  296. sage/data_structures/pairing_heap.h +346 -0
  297. sage/data_structures/pairing_heap.pxd +88 -0
  298. sage/data_structures/pairing_heap.pyx +1464 -0
  299. sage/data_structures/sparse_bitset.pxd +62 -0
  300. sage/data_structures/stream.py +5070 -0
  301. sage/databases/all__sagemath_categories.py +7 -0
  302. sage/databases/sql_db.py +2236 -0
  303. sage/ext/all__sagemath_categories.py +3 -0
  304. sage/ext/fast_callable.cpython-314t-aarch64-linux-musl.so +0 -0
  305. sage/ext/fast_callable.pxd +4 -0
  306. sage/ext/fast_callable.pyx +2746 -0
  307. sage/ext/fast_eval.cpython-314t-aarch64-linux-musl.so +0 -0
  308. sage/ext/fast_eval.pxd +1 -0
  309. sage/ext/fast_eval.pyx +102 -0
  310. sage/ext/interpreters/__init__.py +1 -0
  311. sage/ext/interpreters/all__sagemath_categories.py +2 -0
  312. sage/ext/interpreters/wrapper_el.cpython-314t-aarch64-linux-musl.so +0 -0
  313. sage/ext/interpreters/wrapper_el.pxd +18 -0
  314. sage/ext/interpreters/wrapper_el.pyx +148 -0
  315. sage/ext/interpreters/wrapper_py.cpython-314t-aarch64-linux-musl.so +0 -0
  316. sage/ext/interpreters/wrapper_py.pxd +17 -0
  317. sage/ext/interpreters/wrapper_py.pyx +133 -0
  318. sage/functions/airy.py +937 -0
  319. sage/functions/all.py +97 -0
  320. sage/functions/bessel.py +2102 -0
  321. sage/functions/error.py +784 -0
  322. sage/functions/exp_integral.py +1529 -0
  323. sage/functions/gamma.py +1087 -0
  324. sage/functions/generalized.py +672 -0
  325. sage/functions/hyperbolic.py +747 -0
  326. sage/functions/hypergeometric.py +1156 -0
  327. sage/functions/jacobi.py +1705 -0
  328. sage/functions/log.py +1402 -0
  329. sage/functions/min_max.py +338 -0
  330. sage/functions/orthogonal_polys.py +3106 -0
  331. sage/functions/other.py +2303 -0
  332. sage/functions/piecewise.py +1505 -0
  333. sage/functions/prime_pi.cpython-314t-aarch64-linux-musl.so +0 -0
  334. sage/functions/prime_pi.pyx +262 -0
  335. sage/functions/special.py +1212 -0
  336. sage/functions/spike_function.py +278 -0
  337. sage/functions/transcendental.py +690 -0
  338. sage/functions/trig.py +1062 -0
  339. sage/functions/wigner.py +726 -0
  340. sage/geometry/abc.cpython-314t-aarch64-linux-musl.so +0 -0
  341. sage/geometry/abc.pyx +82 -0
  342. sage/geometry/all__sagemath_categories.py +1 -0
  343. sage/groups/all__sagemath_categories.py +11 -0
  344. sage/groups/generic.py +1733 -0
  345. sage/groups/groups_catalog.py +113 -0
  346. sage/groups/perm_gps/all__sagemath_categories.py +1 -0
  347. sage/groups/perm_gps/partn_ref/all.py +1 -0
  348. sage/groups/perm_gps/partn_ref/all__sagemath_categories.py +1 -0
  349. sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.cpython-314t-aarch64-linux-musl.so +0 -0
  350. sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd +52 -0
  351. sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx +906 -0
  352. sage/groups/perm_gps/partn_ref/canonical_augmentation.cpython-314t-aarch64-linux-musl.so +0 -0
  353. sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd +85 -0
  354. sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx +534 -0
  355. sage/groups/perm_gps/partn_ref/data_structures.cpython-314t-aarch64-linux-musl.so +0 -0
  356. sage/groups/perm_gps/partn_ref/data_structures.pxd +576 -0
  357. sage/groups/perm_gps/partn_ref/data_structures.pyx +1792 -0
  358. sage/groups/perm_gps/partn_ref/double_coset.cpython-314t-aarch64-linux-musl.so +0 -0
  359. sage/groups/perm_gps/partn_ref/double_coset.pxd +45 -0
  360. sage/groups/perm_gps/partn_ref/double_coset.pyx +739 -0
  361. sage/groups/perm_gps/partn_ref/refinement_lists.cpython-314t-aarch64-linux-musl.so +0 -0
  362. sage/groups/perm_gps/partn_ref/refinement_lists.pxd +18 -0
  363. sage/groups/perm_gps/partn_ref/refinement_lists.pyx +82 -0
  364. sage/groups/perm_gps/partn_ref/refinement_python.cpython-314t-aarch64-linux-musl.so +0 -0
  365. sage/groups/perm_gps/partn_ref/refinement_python.pxd +16 -0
  366. sage/groups/perm_gps/partn_ref/refinement_python.pyx +564 -0
  367. sage/groups/perm_gps/partn_ref/refinement_sets.cpython-314t-aarch64-linux-musl.so +0 -0
  368. sage/groups/perm_gps/partn_ref/refinement_sets.pxd +60 -0
  369. sage/groups/perm_gps/partn_ref/refinement_sets.pyx +858 -0
  370. sage/interfaces/abc.py +140 -0
  371. sage/interfaces/all.py +58 -0
  372. sage/interfaces/all__sagemath_categories.py +1 -0
  373. sage/interfaces/expect.py +1643 -0
  374. sage/interfaces/interface.py +1682 -0
  375. sage/interfaces/process.cpython-314t-aarch64-linux-musl.so +0 -0
  376. sage/interfaces/process.pxd +5 -0
  377. sage/interfaces/process.pyx +288 -0
  378. sage/interfaces/quit.py +167 -0
  379. sage/interfaces/sage0.py +604 -0
  380. sage/interfaces/sagespawn.cpython-314t-aarch64-linux-musl.so +0 -0
  381. sage/interfaces/sagespawn.pyx +308 -0
  382. sage/interfaces/tab_completion.py +101 -0
  383. sage/misc/all__sagemath_categories.py +78 -0
  384. sage/misc/allocator.cpython-314t-aarch64-linux-musl.so +0 -0
  385. sage/misc/allocator.pxd +6 -0
  386. sage/misc/allocator.pyx +47 -0
  387. sage/misc/binary_tree.cpython-314t-aarch64-linux-musl.so +0 -0
  388. sage/misc/binary_tree.pxd +29 -0
  389. sage/misc/binary_tree.pyx +537 -0
  390. sage/misc/callable_dict.cpython-314t-aarch64-linux-musl.so +0 -0
  391. sage/misc/callable_dict.pyx +89 -0
  392. sage/misc/citation.cpython-314t-aarch64-linux-musl.so +0 -0
  393. sage/misc/citation.pyx +159 -0
  394. sage/misc/converting_dict.py +293 -0
  395. sage/misc/defaults.py +129 -0
  396. sage/misc/derivative.cpython-314t-aarch64-linux-musl.so +0 -0
  397. sage/misc/derivative.pyx +223 -0
  398. sage/misc/functional.py +2005 -0
  399. sage/misc/html.py +589 -0
  400. sage/misc/latex.py +2673 -0
  401. sage/misc/latex_macros.py +236 -0
  402. sage/misc/latex_standalone.py +1833 -0
  403. sage/misc/map_threaded.py +38 -0
  404. sage/misc/mathml.py +76 -0
  405. sage/misc/method_decorator.py +88 -0
  406. sage/misc/mrange.py +755 -0
  407. sage/misc/multireplace.py +41 -0
  408. sage/misc/object_multiplexer.py +92 -0
  409. sage/misc/parser.cpython-314t-aarch64-linux-musl.so +0 -0
  410. sage/misc/parser.pyx +1107 -0
  411. sage/misc/random_testing.py +264 -0
  412. sage/misc/rest_index_of_methods.py +377 -0
  413. sage/misc/search.cpython-314t-aarch64-linux-musl.so +0 -0
  414. sage/misc/search.pxd +2 -0
  415. sage/misc/search.pyx +68 -0
  416. sage/misc/stopgap.cpython-314t-aarch64-linux-musl.so +0 -0
  417. sage/misc/stopgap.pyx +95 -0
  418. sage/misc/table.py +853 -0
  419. sage/monoids/all__sagemath_categories.py +1 -0
  420. sage/monoids/indexed_free_monoid.py +1071 -0
  421. sage/monoids/monoid.py +82 -0
  422. sage/numerical/all__sagemath_categories.py +1 -0
  423. sage/numerical/backends/all__sagemath_categories.py +1 -0
  424. sage/numerical/backends/generic_backend.cpython-314t-aarch64-linux-musl.so +0 -0
  425. sage/numerical/backends/generic_backend.pxd +61 -0
  426. sage/numerical/backends/generic_backend.pyx +1893 -0
  427. sage/numerical/backends/generic_sdp_backend.cpython-314t-aarch64-linux-musl.so +0 -0
  428. sage/numerical/backends/generic_sdp_backend.pxd +38 -0
  429. sage/numerical/backends/generic_sdp_backend.pyx +755 -0
  430. sage/parallel/all.py +6 -0
  431. sage/parallel/decorate.py +575 -0
  432. sage/parallel/map_reduce.py +1997 -0
  433. sage/parallel/multiprocessing_sage.py +76 -0
  434. sage/parallel/ncpus.py +35 -0
  435. sage/parallel/parallelism.py +364 -0
  436. sage/parallel/reference.py +47 -0
  437. sage/parallel/use_fork.py +333 -0
  438. sage/rings/abc.cpython-314t-aarch64-linux-musl.so +0 -0
  439. sage/rings/abc.pxd +31 -0
  440. sage/rings/abc.pyx +526 -0
  441. sage/rings/algebraic_closure_finite_field.py +1154 -0
  442. sage/rings/all__sagemath_categories.py +91 -0
  443. sage/rings/big_oh.py +227 -0
  444. sage/rings/continued_fraction.py +2754 -0
  445. sage/rings/continued_fraction_gosper.py +220 -0
  446. sage/rings/factorint.cpython-314t-aarch64-linux-musl.so +0 -0
  447. sage/rings/factorint.pyx +295 -0
  448. sage/rings/fast_arith.cpython-314t-aarch64-linux-musl.so +0 -0
  449. sage/rings/fast_arith.pxd +21 -0
  450. sage/rings/fast_arith.pyx +535 -0
  451. sage/rings/finite_rings/all__sagemath_categories.py +9 -0
  452. sage/rings/finite_rings/conway_polynomials.py +542 -0
  453. sage/rings/finite_rings/element_base.cpython-314t-aarch64-linux-musl.so +0 -0
  454. sage/rings/finite_rings/element_base.pxd +12 -0
  455. sage/rings/finite_rings/element_base.pyx +1176 -0
  456. sage/rings/finite_rings/finite_field_base.cpython-314t-aarch64-linux-musl.so +0 -0
  457. sage/rings/finite_rings/finite_field_base.pxd +7 -0
  458. sage/rings/finite_rings/finite_field_base.pyx +2171 -0
  459. sage/rings/finite_rings/finite_field_constructor.py +827 -0
  460. sage/rings/finite_rings/finite_field_prime_modn.py +372 -0
  461. sage/rings/finite_rings/galois_group.py +154 -0
  462. sage/rings/finite_rings/hom_finite_field.cpython-314t-aarch64-linux-musl.so +0 -0
  463. sage/rings/finite_rings/hom_finite_field.pxd +23 -0
  464. sage/rings/finite_rings/hom_finite_field.pyx +856 -0
  465. sage/rings/finite_rings/hom_prime_finite_field.cpython-314t-aarch64-linux-musl.so +0 -0
  466. sage/rings/finite_rings/hom_prime_finite_field.pxd +15 -0
  467. sage/rings/finite_rings/hom_prime_finite_field.pyx +164 -0
  468. sage/rings/finite_rings/homset.py +357 -0
  469. sage/rings/finite_rings/integer_mod.cpython-314t-aarch64-linux-musl.so +0 -0
  470. sage/rings/finite_rings/integer_mod.pxd +56 -0
  471. sage/rings/finite_rings/integer_mod.pyx +4586 -0
  472. sage/rings/finite_rings/integer_mod_limits.h +11 -0
  473. sage/rings/finite_rings/integer_mod_ring.py +2044 -0
  474. sage/rings/finite_rings/residue_field.cpython-314t-aarch64-linux-musl.so +0 -0
  475. sage/rings/finite_rings/residue_field.pxd +30 -0
  476. sage/rings/finite_rings/residue_field.pyx +1811 -0
  477. sage/rings/finite_rings/stdint.pxd +19 -0
  478. sage/rings/fraction_field.py +1452 -0
  479. sage/rings/fraction_field_element.cpython-314t-aarch64-linux-musl.so +0 -0
  480. sage/rings/fraction_field_element.pyx +1357 -0
  481. sage/rings/function_field/all.py +7 -0
  482. sage/rings/function_field/all__sagemath_categories.py +2 -0
  483. sage/rings/function_field/constructor.py +218 -0
  484. sage/rings/function_field/element.cpython-314t-aarch64-linux-musl.so +0 -0
  485. sage/rings/function_field/element.pxd +11 -0
  486. sage/rings/function_field/element.pyx +1008 -0
  487. sage/rings/function_field/element_rational.cpython-314t-aarch64-linux-musl.so +0 -0
  488. sage/rings/function_field/element_rational.pyx +513 -0
  489. sage/rings/function_field/extensions.py +230 -0
  490. sage/rings/function_field/function_field.py +1468 -0
  491. sage/rings/function_field/function_field_rational.py +1005 -0
  492. sage/rings/function_field/ideal.py +1155 -0
  493. sage/rings/function_field/ideal_rational.py +629 -0
  494. sage/rings/function_field/jacobian_base.py +826 -0
  495. sage/rings/function_field/jacobian_hess.py +1053 -0
  496. sage/rings/function_field/jacobian_khuri_makdisi.py +1027 -0
  497. sage/rings/function_field/maps.py +1039 -0
  498. sage/rings/function_field/order.py +281 -0
  499. sage/rings/function_field/order_basis.py +586 -0
  500. sage/rings/function_field/order_rational.py +576 -0
  501. sage/rings/function_field/place.py +426 -0
  502. sage/rings/function_field/place_rational.py +181 -0
  503. sage/rings/generic.py +320 -0
  504. sage/rings/homset.py +332 -0
  505. sage/rings/ideal.py +1885 -0
  506. sage/rings/ideal_monoid.py +215 -0
  507. sage/rings/infinity.py +1890 -0
  508. sage/rings/integer.cpython-314t-aarch64-linux-musl.so +0 -0
  509. sage/rings/integer.pxd +45 -0
  510. sage/rings/integer.pyx +7874 -0
  511. sage/rings/integer_ring.cpython-314t-aarch64-linux-musl.so +0 -0
  512. sage/rings/integer_ring.pxd +8 -0
  513. sage/rings/integer_ring.pyx +1693 -0
  514. sage/rings/laurent_series_ring.py +931 -0
  515. sage/rings/laurent_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
  516. sage/rings/laurent_series_ring_element.pxd +11 -0
  517. sage/rings/laurent_series_ring_element.pyx +1927 -0
  518. sage/rings/lazy_series.py +7815 -0
  519. sage/rings/lazy_series_ring.py +4356 -0
  520. sage/rings/localization.py +1043 -0
  521. sage/rings/morphism.cpython-314t-aarch64-linux-musl.so +0 -0
  522. sage/rings/morphism.pxd +39 -0
  523. sage/rings/morphism.pyx +3299 -0
  524. sage/rings/multi_power_series_ring.py +1145 -0
  525. sage/rings/multi_power_series_ring_element.py +2184 -0
  526. sage/rings/noncommutative_ideals.cpython-314t-aarch64-linux-musl.so +0 -0
  527. sage/rings/noncommutative_ideals.pyx +423 -0
  528. sage/rings/number_field/all__sagemath_categories.py +1 -0
  529. sage/rings/number_field/number_field_base.cpython-314t-aarch64-linux-musl.so +0 -0
  530. sage/rings/number_field/number_field_base.pxd +8 -0
  531. sage/rings/number_field/number_field_base.pyx +507 -0
  532. sage/rings/number_field/number_field_element_base.cpython-314t-aarch64-linux-musl.so +0 -0
  533. sage/rings/number_field/number_field_element_base.pxd +6 -0
  534. sage/rings/number_field/number_field_element_base.pyx +36 -0
  535. sage/rings/number_field/number_field_ideal.py +3550 -0
  536. sage/rings/padics/all__sagemath_categories.py +4 -0
  537. sage/rings/padics/local_generic.py +1670 -0
  538. sage/rings/padics/local_generic_element.cpython-314t-aarch64-linux-musl.so +0 -0
  539. sage/rings/padics/local_generic_element.pxd +5 -0
  540. sage/rings/padics/local_generic_element.pyx +1017 -0
  541. sage/rings/padics/misc.py +256 -0
  542. sage/rings/padics/padic_generic.py +1911 -0
  543. sage/rings/padics/pow_computer.cpython-314t-aarch64-linux-musl.so +0 -0
  544. sage/rings/padics/pow_computer.pxd +38 -0
  545. sage/rings/padics/pow_computer.pyx +671 -0
  546. sage/rings/padics/precision_error.py +24 -0
  547. sage/rings/polynomial/all__sagemath_categories.py +25 -0
  548. sage/rings/polynomial/commutative_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
  549. sage/rings/polynomial/commutative_polynomial.pxd +6 -0
  550. sage/rings/polynomial/commutative_polynomial.pyx +24 -0
  551. sage/rings/polynomial/cyclotomic.cpython-314t-aarch64-linux-musl.so +0 -0
  552. sage/rings/polynomial/cyclotomic.pyx +404 -0
  553. sage/rings/polynomial/flatten.py +711 -0
  554. sage/rings/polynomial/ideal.py +102 -0
  555. sage/rings/polynomial/infinite_polynomial_element.py +1768 -0
  556. sage/rings/polynomial/infinite_polynomial_ring.py +1653 -0
  557. sage/rings/polynomial/laurent_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
  558. sage/rings/polynomial/laurent_polynomial.pxd +18 -0
  559. sage/rings/polynomial/laurent_polynomial.pyx +2190 -0
  560. sage/rings/polynomial/laurent_polynomial_ideal.py +590 -0
  561. sage/rings/polynomial/laurent_polynomial_ring.py +832 -0
  562. sage/rings/polynomial/laurent_polynomial_ring_base.py +708 -0
  563. sage/rings/polynomial/multi_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
  564. sage/rings/polynomial/multi_polynomial.pxd +12 -0
  565. sage/rings/polynomial/multi_polynomial.pyx +3082 -0
  566. sage/rings/polynomial/multi_polynomial_element.py +2570 -0
  567. sage/rings/polynomial/multi_polynomial_ideal.py +5771 -0
  568. sage/rings/polynomial/multi_polynomial_ring.py +947 -0
  569. sage/rings/polynomial/multi_polynomial_ring_base.cpython-314t-aarch64-linux-musl.so +0 -0
  570. sage/rings/polynomial/multi_polynomial_ring_base.pxd +15 -0
  571. sage/rings/polynomial/multi_polynomial_ring_base.pyx +1855 -0
  572. sage/rings/polynomial/multi_polynomial_sequence.py +2204 -0
  573. sage/rings/polynomial/polydict.cpython-314t-aarch64-linux-musl.so +0 -0
  574. sage/rings/polynomial/polydict.pxd +45 -0
  575. sage/rings/polynomial/polydict.pyx +2701 -0
  576. sage/rings/polynomial/polynomial_compiled.cpython-314t-aarch64-linux-musl.so +0 -0
  577. sage/rings/polynomial/polynomial_compiled.pxd +59 -0
  578. sage/rings/polynomial/polynomial_compiled.pyx +509 -0
  579. sage/rings/polynomial/polynomial_element.cpython-314t-aarch64-linux-musl.so +0 -0
  580. sage/rings/polynomial/polynomial_element.pxd +64 -0
  581. sage/rings/polynomial/polynomial_element.pyx +13255 -0
  582. sage/rings/polynomial/polynomial_element_generic.py +1637 -0
  583. sage/rings/polynomial/polynomial_fateman.py +97 -0
  584. sage/rings/polynomial/polynomial_quotient_ring.py +2465 -0
  585. sage/rings/polynomial/polynomial_quotient_ring_element.py +779 -0
  586. sage/rings/polynomial/polynomial_ring.py +3784 -0
  587. sage/rings/polynomial/polynomial_ring_constructor.py +1051 -0
  588. sage/rings/polynomial/polynomial_ring_homomorphism.cpython-314t-aarch64-linux-musl.so +0 -0
  589. sage/rings/polynomial/polynomial_ring_homomorphism.pxd +5 -0
  590. sage/rings/polynomial/polynomial_ring_homomorphism.pyx +121 -0
  591. sage/rings/polynomial/polynomial_singular_interface.py +549 -0
  592. sage/rings/polynomial/symmetric_ideal.py +989 -0
  593. sage/rings/polynomial/symmetric_reduction.cpython-314t-aarch64-linux-musl.so +0 -0
  594. sage/rings/polynomial/symmetric_reduction.pxd +8 -0
  595. sage/rings/polynomial/symmetric_reduction.pyx +669 -0
  596. sage/rings/polynomial/term_order.py +2279 -0
  597. sage/rings/polynomial/toy_buchberger.py +449 -0
  598. sage/rings/polynomial/toy_d_basis.py +387 -0
  599. sage/rings/polynomial/toy_variety.py +362 -0
  600. sage/rings/power_series_mpoly.cpython-314t-aarch64-linux-musl.so +0 -0
  601. sage/rings/power_series_mpoly.pxd +9 -0
  602. sage/rings/power_series_mpoly.pyx +161 -0
  603. sage/rings/power_series_poly.cpython-314t-aarch64-linux-musl.so +0 -0
  604. sage/rings/power_series_poly.pxd +10 -0
  605. sage/rings/power_series_poly.pyx +1317 -0
  606. sage/rings/power_series_ring.py +1441 -0
  607. sage/rings/power_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
  608. sage/rings/power_series_ring_element.pxd +12 -0
  609. sage/rings/power_series_ring_element.pyx +3028 -0
  610. sage/rings/puiseux_series_ring.py +487 -0
  611. sage/rings/puiseux_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
  612. sage/rings/puiseux_series_ring_element.pxd +7 -0
  613. sage/rings/puiseux_series_ring_element.pyx +1055 -0
  614. sage/rings/qqbar_decorators.py +167 -0
  615. sage/rings/quotient_ring.py +1598 -0
  616. sage/rings/quotient_ring_element.py +979 -0
  617. sage/rings/rational.cpython-314t-aarch64-linux-musl.so +0 -0
  618. sage/rings/rational.pxd +20 -0
  619. sage/rings/rational.pyx +4284 -0
  620. sage/rings/rational_field.py +1730 -0
  621. sage/rings/real_double.cpython-314t-aarch64-linux-musl.so +0 -0
  622. sage/rings/real_double.pxd +16 -0
  623. sage/rings/real_double.pyx +2218 -0
  624. sage/rings/real_lazy.cpython-314t-aarch64-linux-musl.so +0 -0
  625. sage/rings/real_lazy.pxd +30 -0
  626. sage/rings/real_lazy.pyx +1773 -0
  627. sage/rings/ring.cpython-314t-aarch64-linux-musl.so +0 -0
  628. sage/rings/ring.pxd +30 -0
  629. sage/rings/ring.pyx +850 -0
  630. sage/rings/semirings/all.py +3 -0
  631. sage/rings/semirings/non_negative_integer_semiring.py +107 -0
  632. sage/rings/semirings/tropical_mpolynomial.py +972 -0
  633. sage/rings/semirings/tropical_polynomial.py +997 -0
  634. sage/rings/semirings/tropical_semiring.cpython-314t-aarch64-linux-musl.so +0 -0
  635. sage/rings/semirings/tropical_semiring.pyx +676 -0
  636. sage/rings/semirings/tropical_variety.py +1701 -0
  637. sage/rings/sum_of_squares.cpython-314t-aarch64-linux-musl.so +0 -0
  638. sage/rings/sum_of_squares.pxd +3 -0
  639. sage/rings/sum_of_squares.pyx +336 -0
  640. sage/rings/tests.py +504 -0
  641. sage/schemes/affine/affine_homset.py +508 -0
  642. sage/schemes/affine/affine_morphism.py +1574 -0
  643. sage/schemes/affine/affine_point.py +460 -0
  644. sage/schemes/affine/affine_rational_point.py +308 -0
  645. sage/schemes/affine/affine_space.py +1264 -0
  646. sage/schemes/affine/affine_subscheme.py +592 -0
  647. sage/schemes/affine/all.py +25 -0
  648. sage/schemes/all__sagemath_categories.py +5 -0
  649. sage/schemes/generic/algebraic_scheme.py +2092 -0
  650. sage/schemes/generic/all.py +5 -0
  651. sage/schemes/generic/ambient_space.py +400 -0
  652. sage/schemes/generic/divisor.py +465 -0
  653. sage/schemes/generic/divisor_group.py +313 -0
  654. sage/schemes/generic/glue.py +84 -0
  655. sage/schemes/generic/homset.py +820 -0
  656. sage/schemes/generic/hypersurface.py +234 -0
  657. sage/schemes/generic/morphism.py +2107 -0
  658. sage/schemes/generic/point.py +237 -0
  659. sage/schemes/generic/scheme.py +1190 -0
  660. sage/schemes/generic/spec.py +199 -0
  661. sage/schemes/product_projective/all.py +6 -0
  662. sage/schemes/product_projective/homset.py +236 -0
  663. sage/schemes/product_projective/morphism.py +517 -0
  664. sage/schemes/product_projective/point.py +568 -0
  665. sage/schemes/product_projective/rational_point.py +550 -0
  666. sage/schemes/product_projective/space.py +1301 -0
  667. sage/schemes/product_projective/subscheme.py +466 -0
  668. sage/schemes/projective/all.py +24 -0
  669. sage/schemes/projective/proj_bdd_height.py +453 -0
  670. sage/schemes/projective/projective_homset.py +718 -0
  671. sage/schemes/projective/projective_morphism.py +2792 -0
  672. sage/schemes/projective/projective_point.py +1484 -0
  673. sage/schemes/projective/projective_rational_point.py +569 -0
  674. sage/schemes/projective/projective_space.py +2571 -0
  675. sage/schemes/projective/projective_subscheme.py +1574 -0
  676. sage/sets/all.py +17 -0
  677. sage/sets/cartesian_product.py +376 -0
  678. sage/sets/condition_set.py +525 -0
  679. sage/sets/disjoint_set.cpython-314t-aarch64-linux-musl.so +0 -0
  680. sage/sets/disjoint_set.pxd +36 -0
  681. sage/sets/disjoint_set.pyx +998 -0
  682. sage/sets/disjoint_union_enumerated_sets.py +625 -0
  683. sage/sets/family.cpython-314t-aarch64-linux-musl.so +0 -0
  684. sage/sets/family.pxd +12 -0
  685. sage/sets/family.pyx +1556 -0
  686. sage/sets/finite_enumerated_set.py +406 -0
  687. sage/sets/finite_set_map_cy.cpython-314t-aarch64-linux-musl.so +0 -0
  688. sage/sets/finite_set_map_cy.pxd +34 -0
  689. sage/sets/finite_set_map_cy.pyx +708 -0
  690. sage/sets/finite_set_maps.py +591 -0
  691. sage/sets/image_set.py +448 -0
  692. sage/sets/integer_range.py +829 -0
  693. sage/sets/non_negative_integers.py +241 -0
  694. sage/sets/positive_integers.py +93 -0
  695. sage/sets/primes.py +188 -0
  696. sage/sets/real_set.py +2760 -0
  697. sage/sets/recursively_enumerated_set.cpython-314t-aarch64-linux-musl.so +0 -0
  698. sage/sets/recursively_enumerated_set.pxd +31 -0
  699. sage/sets/recursively_enumerated_set.pyx +2082 -0
  700. sage/sets/set.py +2083 -0
  701. sage/sets/set_from_iterator.py +1021 -0
  702. sage/sets/totally_ordered_finite_set.py +329 -0
  703. sage/symbolic/all__sagemath_categories.py +1 -0
  704. sage/symbolic/function.cpython-314t-aarch64-linux-musl.so +0 -0
  705. sage/symbolic/function.pxd +29 -0
  706. sage/symbolic/function.pyx +1488 -0
  707. sage/symbolic/symbols.py +56 -0
  708. sage/tests/all__sagemath_categories.py +1 -0
  709. sage/tests/cython.cpython-314t-aarch64-linux-musl.so +0 -0
  710. sage/tests/cython.pyx +37 -0
  711. sage/tests/stl_vector.cpython-314t-aarch64-linux-musl.so +0 -0
  712. sage/tests/stl_vector.pyx +171 -0
  713. sage/typeset/all.py +6 -0
  714. sage/typeset/ascii_art.py +295 -0
  715. sage/typeset/character_art.py +789 -0
  716. sage/typeset/character_art_factory.py +572 -0
  717. sage/typeset/symbols.py +334 -0
  718. sage/typeset/unicode_art.py +183 -0
  719. sage/typeset/unicode_characters.py +101 -0
sage/sets/set.py ADDED
@@ -0,0 +1,2083 @@
1
+ # sage_setup: distribution = sagemath-categories
2
+ """
3
+ Sets
4
+
5
+ AUTHORS:
6
+
7
+ - William Stein (2005) - first version
8
+
9
+ - William Stein (2006-02-16) - large number of documentation and
10
+ examples; improved code
11
+
12
+ - Mike Hansen (2007-3-25) - added differences and symmetric
13
+ differences; fixed operators
14
+
15
+ - Florent Hivert (2010-06-17) - Adapted to categories
16
+
17
+ - Nicolas M. Thiery (2011-03-15) - Added subset and superset methods
18
+
19
+ - Julian Rueth (2013-04-09) - Collected common code in
20
+ :class:`Set_object_binary`, fixed ``__hash__``.
21
+ """
22
+
23
+ # ****************************************************************************
24
+ # Copyright (C) 2005 William Stein <wstein@gmail.com>
25
+ # 2013 Julian Rueth <julian.rueth@fsfe.org>
26
+ #
27
+ # Distributed under the terms of the GNU General Public License (GPL)
28
+ #
29
+ # This code is distributed in the hope that it will be useful,
30
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
31
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32
+ # General Public License for more details.
33
+ #
34
+ # The full text of the GPL is available at:
35
+ #
36
+ # https://www.gnu.org/licenses/
37
+ # ****************************************************************************
38
+
39
+ from sage.misc.latex import latex
40
+ from sage.misc.prandom import choice
41
+ from sage.misc.cachefunc import cached_method
42
+
43
+ from sage.structure.category_object import CategoryObject
44
+ from sage.structure.element import Element
45
+ from sage.structure.parent import Parent, Set_generic
46
+ from sage.structure.richcmp import richcmp_method, richcmp, rich_to_bool
47
+ from sage.misc.classcall_metaclass import ClasscallMetaclass
48
+
49
+ from sage.categories.sets_cat import Sets
50
+ from sage.categories.enumerated_sets import EnumeratedSets
51
+ from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
52
+
53
+ import sage.rings.infinity
54
+
55
+
56
+ def has_finite_length(obj) -> bool:
57
+ """
58
+ Return ``True`` if ``obj`` is known to have finite length.
59
+
60
+ This is mainly meant for pure Python types, so we do not call any
61
+ Sage-specific methods.
62
+
63
+ EXAMPLES::
64
+
65
+ sage: from sage.sets.set import has_finite_length
66
+ sage: has_finite_length(tuple(range(10)))
67
+ True
68
+ sage: has_finite_length(list(range(10)))
69
+ True
70
+ sage: has_finite_length(set(range(10)))
71
+ True
72
+ sage: has_finite_length(iter(range(10)))
73
+ False
74
+ sage: has_finite_length(GF(17^127)) # needs sage.rings.finite_rings
75
+ True
76
+ sage: has_finite_length(ZZ)
77
+ False
78
+ """
79
+ try:
80
+ len(obj)
81
+ except OverflowError:
82
+ return True
83
+ except Exception:
84
+ return False
85
+ else:
86
+ return True
87
+
88
+
89
+ def Set(X=None, category=None):
90
+ r"""
91
+ Create the underlying set of ``X``.
92
+
93
+ If ``X`` is a list, tuple, Python set, or ``X.is_finite()`` is
94
+ ``True``, this returns a wrapper around Python's enumerated immutable
95
+ ``frozenset`` type with extra functionality. Otherwise it returns a
96
+ more formal wrapper.
97
+
98
+ If you need the functionality of mutable sets, use Python's
99
+ builtin set type.
100
+
101
+ EXAMPLES::
102
+
103
+ sage: # needs sage.rings.finite_rings
104
+ sage: X = Set(GF(9, 'a'))
105
+ sage: X
106
+ {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2}
107
+ sage: type(X)
108
+ <class 'sage.sets.set.Set_object_enumerated_with_category'>
109
+ sage: Y = X.union(Set(QQ))
110
+ sage: Y
111
+ Set-theoretic union of
112
+ {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} and
113
+ Set of elements of Rational Field
114
+ sage: type(Y)
115
+ <class 'sage.sets.set.Set_object_union_with_category'>
116
+
117
+ Usually sets can be used as dictionary keys.
118
+
119
+ ::
120
+
121
+ sage: # needs sage.symbolic
122
+ sage: d = {Set([2*I, 1 + I]): 10}
123
+ sage: d # key is randomly ordered
124
+ {{I + 1, 2*I}: 10}
125
+ sage: d[Set([1+I,2*I])]
126
+ 10
127
+ sage: d[Set((1+I,2*I))]
128
+ 10
129
+
130
+ The original object is often forgotten.
131
+
132
+ ::
133
+
134
+ sage: v = [1,2,3]
135
+ sage: X = Set(v)
136
+ sage: X
137
+ {1, 2, 3}
138
+ sage: v.append(5)
139
+ sage: X
140
+ {1, 2, 3}
141
+ sage: 5 in X
142
+ False
143
+
144
+ Set also accepts iterators, but be careful to only give *finite*
145
+ sets::
146
+
147
+ sage: sorted(Set(range(1,6)))
148
+ [1, 2, 3, 4, 5]
149
+ sage: sorted(Set(list(range(1,6))))
150
+ [1, 2, 3, 4, 5]
151
+ sage: sorted(Set(iter(range(1,6))))
152
+ [1, 2, 3, 4, 5]
153
+
154
+ We can also create sets from different types::
155
+
156
+ sage: sorted(Set([Sequence([3,1], immutable=True), 5, QQ, Partition([3,1,1])]), key=str)
157
+ [5, Rational Field, [3, 1, 1], [3, 1]]
158
+
159
+ Sets with unhashable objects work, but with less functionality::
160
+
161
+ sage: A = Set([QQ, (3, 1), 5]) # hashable
162
+ sage: sorted(A.list(), key=repr)
163
+ [(3, 1), 5, Rational Field]
164
+ sage: type(A)
165
+ <class 'sage.sets.set.Set_object_enumerated_with_category'>
166
+ sage: B = Set([QQ, [3, 1], 5]) # unhashable
167
+ sage: sorted(B.list(), key=repr)
168
+ Traceback (most recent call last):
169
+ ...
170
+ AttributeError: 'Set_object_with_category' object has no attribute 'list'...
171
+ sage: type(B)
172
+ <class 'sage.sets.set.Set_object_with_category'>
173
+
174
+ TESTS::
175
+
176
+ sage: Set(Primes())
177
+ Set of all prime numbers: 2, 3, 5, 7, ...
178
+ sage: Set(Subsets([1,2,3])).cardinality()
179
+ 8
180
+ sage: S = Set(iter([1,2,3])); S
181
+ {1, 2, 3}
182
+ sage: type(S)
183
+ <class 'sage.sets.set.Set_object_enumerated_with_category'>
184
+ sage: S = Set([])
185
+ sage: TestSuite(S).run()
186
+
187
+ Check that :issue:`16090` is fixed::
188
+
189
+ sage: Set()
190
+ {}
191
+ """
192
+ if X is None:
193
+ X = []
194
+ elif isinstance(X, CategoryObject):
195
+ if isinstance(X, Set_generic) and category is None:
196
+ return X
197
+ elif X in Sets().Finite():
198
+ return Set_object_enumerated(X, category=category)
199
+ else:
200
+ return Set_object(X, category=category)
201
+
202
+ if isinstance(X, Element) and not isinstance(X, Set_base):
203
+ raise TypeError("Element has no defined underlying set")
204
+
205
+ try:
206
+ X = frozenset(X)
207
+ except TypeError:
208
+ return Set_object(X, category=category)
209
+ else:
210
+ return Set_object_enumerated(X, category=category)
211
+
212
+
213
+ class Set_base:
214
+ r"""
215
+ Abstract base class for sets, not necessarily parents.
216
+ """
217
+
218
+ def union(self, X):
219
+ """
220
+ Return the union of ``self`` and ``X``.
221
+
222
+ EXAMPLES::
223
+
224
+ sage: Set(QQ).union(Set(ZZ))
225
+ Set-theoretic union of
226
+ Set of elements of Rational Field and
227
+ Set of elements of Integer Ring
228
+ sage: Set(QQ) + Set(ZZ)
229
+ Set-theoretic union of
230
+ Set of elements of Rational Field and
231
+ Set of elements of Integer Ring
232
+ sage: X = Set(QQ).union(Set(GF(3))); X
233
+ Set-theoretic union of
234
+ Set of elements of Rational Field and
235
+ {0, 1, 2}
236
+ sage: 2/3 in X
237
+ True
238
+ sage: GF(3)(2) in X # needs sage.libs.pari
239
+ True
240
+ sage: GF(5)(2) in X
241
+ False
242
+ sage: sorted(Set(GF(7)) + Set(GF(3)), key=int)
243
+ [0, 0, 1, 1, 2, 2, 3, 4, 5, 6]
244
+ """
245
+ if isinstance(X, (Set_generic, Set_base)):
246
+ if self is X:
247
+ return self
248
+ return Set_object_union(self, X)
249
+ raise TypeError("X (=%s) must be a Set" % X)
250
+
251
+ def intersection(self, X):
252
+ r"""
253
+ Return the intersection of ``self`` and ``X``.
254
+
255
+ EXAMPLES::
256
+
257
+ sage: X = Set(ZZ).intersection(Primes())
258
+ sage: 4 in X
259
+ False
260
+ sage: 3 in X
261
+ True
262
+
263
+ sage: 2/1 in X
264
+ True
265
+
266
+ sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))); X # needs sage.rings.finite_rings
267
+ {}
268
+
269
+ sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))); X # needs sage.rings.finite_rings
270
+ {}
271
+ """
272
+ if isinstance(X, (Set_generic, Set_base)):
273
+ if self is X:
274
+ return self
275
+ return Set_object_intersection(self, X)
276
+ raise TypeError("X (=%s) must be a Set" % X)
277
+
278
+ def difference(self, X):
279
+ r"""
280
+ Return the set difference ``self - X``.
281
+
282
+ EXAMPLES::
283
+
284
+ sage: X = Set(ZZ).difference(Primes())
285
+ sage: 4 in X
286
+ True
287
+ sage: 3 in X
288
+ False
289
+
290
+ sage: 4/1 in X
291
+ True
292
+
293
+ sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))); X # needs sage.rings.finite_rings
294
+ {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2}
295
+
296
+ sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))); X # needs sage.rings.finite_rings
297
+ {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2}
298
+ """
299
+ if isinstance(X, (Set_generic, Set_base)):
300
+ if self is X:
301
+ return Set([])
302
+ return Set_object_difference(self, X)
303
+ raise TypeError("X (=%s) must be a Set" % X)
304
+
305
+ def symmetric_difference(self, X):
306
+ r"""
307
+ Return the symmetric difference of ``self`` and ``X``.
308
+
309
+ EXAMPLES::
310
+
311
+ sage: X = Set([1,2,3]).symmetric_difference(Set([3,4]))
312
+ sage: X
313
+ {1, 2, 4}
314
+ """
315
+ if isinstance(X, (Set_generic, Set_base)):
316
+ if self is X:
317
+ return Set([])
318
+ return Set_object_symmetric_difference(self, X)
319
+ raise TypeError("X (=%s) must be a Set" % X)
320
+
321
+ def _test_as_set_object(self, tester=None, **options):
322
+ r"""
323
+ Run the test suite of ``Set(self)`` unless it is identical to ``self``.
324
+
325
+ EXAMPLES:
326
+
327
+ Nothing is tested for instances of :class`Set_generic` (constructed
328
+ with the :func:`Set` constructor)::
329
+
330
+ sage: Set(ZZ)._test_as_set_object(verbose=True)
331
+
332
+ Instances of other subclasses of :class:`Set_base` run this method::
333
+
334
+ sage: Polyhedron()._test_as_set_object(verbose=True) # needs sage.geometry.polyhedron
335
+ Running the test suite of Set(self)
336
+ running ._test_an_element() . . . pass
337
+ ...
338
+ running ._test_some_elements() . . . pass
339
+ """
340
+ if tester is None:
341
+ tester = self._tester(**options)
342
+ set_self = Set(self)
343
+ if set_self is not self:
344
+ from sage.misc.sage_unittest import TestSuite
345
+ tester.info("\n Running the test suite of Set(self)")
346
+ TestSuite(set_self).run(skip='_test_pickling', # see Issue #32025
347
+ verbose=tester._verbose,
348
+ prefix=tester._prefix + " ")
349
+ tester.info(tester._prefix + " ", newline=False)
350
+
351
+
352
+ class Set_boolean_operators:
353
+ r"""
354
+ Mix-in class providing the Boolean operators ``__or__``, ``__and__``, ``__xor__``.
355
+
356
+ The operators delegate to the methods ``union``, ``intersection``, and
357
+ ``symmetric_difference``, which need to be implemented by the class.
358
+ """
359
+
360
+ def __or__(self, X):
361
+ """
362
+ Return the union of ``self`` and ``X``.
363
+
364
+ EXAMPLES::
365
+
366
+ sage: Set([2,3]) | Set([3,4])
367
+ {2, 3, 4}
368
+ sage: Set(ZZ) | Set(QQ)
369
+ Set-theoretic union of Set of elements of Integer Ring and Set of elements of Rational Field
370
+ """
371
+ return self.union(X)
372
+
373
+ def __and__(self, X):
374
+ """
375
+ Return the intersection of ``self`` and ``X``.
376
+
377
+ EXAMPLES::
378
+
379
+ sage: Set([2,3]) & Set([3,4])
380
+ {3}
381
+ sage: Set(ZZ) & Set(QQ)
382
+ Set-theoretic intersection of Set of elements of Integer Ring and Set of elements of Rational Field
383
+ """
384
+ return self.intersection(X)
385
+
386
+ def __xor__(self, X):
387
+ """
388
+ Return the symmetric difference of ``self`` and ``X``.
389
+
390
+ EXAMPLES::
391
+
392
+ sage: X = Set([1,2,3,4])
393
+ sage: Y = Set([1,2])
394
+ sage: X.symmetric_difference(Y)
395
+ {3, 4}
396
+ sage: X.__xor__(Y)
397
+ {3, 4}
398
+ """
399
+ return self.symmetric_difference(X)
400
+
401
+
402
+ class Set_add_sub_operators:
403
+ r"""
404
+ Mix-in class providing the operators ``__add__`` and ``__sub__``.
405
+
406
+ The operators delegate to the methods ``union`` and ``intersection``,
407
+ which need to be implemented by the class.
408
+ """
409
+
410
+ def __add__(self, X):
411
+ """
412
+ Return the union of ``self`` and ``X``.
413
+
414
+ EXAMPLES::
415
+
416
+ sage: Set(RealField()) + Set(QQ^5) # needs sage.modules
417
+ Set-theoretic union of
418
+ Set of elements of Real Field with 53 bits of precision and
419
+ Set of elements of Vector space of dimension 5 over Rational Field
420
+ sage: Set(GF(3)) + Set(GF(2))
421
+ {0, 1, 2, 0, 1}
422
+ sage: Set(GF(2)) + Set(GF(4,'a')) # needs sage.rings.finite_rings
423
+ {0, 1, a, a + 1}
424
+ sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) # needs sage.rings.finite_rings
425
+ [0, 0, 1, 1, a, a + 1, b, b + 1, b^2, b^2 + 1, b^2 + b, b^2 + b + 1]
426
+ """
427
+ return self.union(X)
428
+
429
+ def __sub__(self, X):
430
+ """
431
+ Return the difference of ``self`` and ``X``.
432
+
433
+ EXAMPLES::
434
+
435
+ sage: X = Set(ZZ).difference(Primes())
436
+ sage: Y = Set(ZZ) - Primes()
437
+ sage: X == Y
438
+ True
439
+ """
440
+ return self.difference(X)
441
+
442
+
443
+ @richcmp_method
444
+ class Set_object(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_operators):
445
+ r"""
446
+ A set attached to an almost arbitrary object.
447
+
448
+ EXAMPLES::
449
+
450
+ sage: K = GF(19)
451
+ sage: Set(K)
452
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
453
+ sage: S = Set(K)
454
+
455
+ sage: latex(S)
456
+ \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\}
457
+ sage: TestSuite(S).run()
458
+
459
+ sage: latex(Set(ZZ))
460
+ \Bold{Z}
461
+
462
+ TESTS:
463
+
464
+ See :issue:`14486`::
465
+
466
+ sage: 0 == Set([1]), Set([1]) == 0
467
+ (False, False)
468
+ sage: 1 == Set([0]), Set([0]) == 1
469
+ (False, False)
470
+ """
471
+
472
+ def __init__(self, X, category=None):
473
+ """
474
+ Create a Set_object.
475
+
476
+ This function is called by the Set function; users
477
+ shouldn't call this directly.
478
+
479
+ EXAMPLES::
480
+
481
+ sage: type(Set(QQ))
482
+ <class 'sage.sets.set.Set_object_with_category'>
483
+ sage: Set(QQ).category()
484
+ Category of infinite sets
485
+
486
+ TESTS::
487
+
488
+ sage: _a, _b = get_coercion_model().canonical_coercion(Set([0]), 0)
489
+ Traceback (most recent call last):
490
+ ...
491
+ TypeError: no common canonical parent for objects with parents:
492
+ '<class 'sage.sets.set.Set_object_enumerated_with_category'>'
493
+ and 'Integer Ring'
494
+ """
495
+ from sage.rings.integer import Integer
496
+ if isinstance(X, (int, Integer)):
497
+ # The coercion model will try to call Set_object(0)
498
+ raise ValueError('underlying object cannot be an integer')
499
+
500
+ if category is None:
501
+ category = Sets()
502
+
503
+ if isinstance(X, CategoryObject):
504
+ if X in Sets().Finite():
505
+ category = category.Finite()
506
+ elif X in Sets().Infinite():
507
+ category = category.Infinite()
508
+ if X in Sets().Enumerated():
509
+ category = category.Enumerated()
510
+
511
+ Parent.__init__(self, category=category)
512
+ self.__object = X
513
+
514
+ def __hash__(self):
515
+ """
516
+ Return the hash value of ``self``.
517
+
518
+ EXAMPLES::
519
+
520
+ sage: hash(Set(QQ)) == hash(QQ)
521
+ True
522
+ """
523
+ return hash(self.__object)
524
+
525
+ def _latex_(self):
526
+ r"""
527
+ Return latex representation of this set.
528
+
529
+ This is often the same as the latex representation of this
530
+ object when the object is infinite.
531
+
532
+ EXAMPLES::
533
+
534
+ sage: latex(Set(QQ))
535
+ \Bold{Q}
536
+
537
+ When the object is finite or a special set then the latex
538
+ representation can be more interesting.
539
+
540
+ ::
541
+
542
+ sage: print(latex(Primes()))
543
+ \text{\texttt{Set{ }of{ }all{ }prime{ }numbers:{ }2,{ }3,{ }5,{ }7,{ }...}}
544
+ sage: print(latex(Set([1,1,1,5,6])))
545
+ \left\{1, 5, 6\right\}
546
+ """
547
+ return latex(self.__object)
548
+
549
+ def _repr_(self):
550
+ """
551
+ Print representation of this set.
552
+
553
+ EXAMPLES::
554
+
555
+ sage: X = Set(ZZ)
556
+ sage: X
557
+ Set of elements of Integer Ring
558
+ sage: X.rename('{ integers }')
559
+ sage: X
560
+ { integers }
561
+ """
562
+ return "Set of elements of " + repr(self.__object)
563
+
564
+ def __iter__(self):
565
+ """
566
+ Iterate over the elements of this set.
567
+
568
+ EXAMPLES::
569
+
570
+ sage: X = Set(ZZ)
571
+ sage: I = X.__iter__()
572
+ sage: next(I)
573
+ 0
574
+ sage: next(I)
575
+ 1
576
+ sage: next(I)
577
+ -1
578
+ sage: next(I)
579
+ 2
580
+ """
581
+ return iter(self.__object)
582
+
583
+ _an_element_from_iterator = EnumeratedSets.ParentMethods.__dict__['_an_element_from_iterator']
584
+
585
+ def _an_element_(self):
586
+ """
587
+ Return an element of ``self``.
588
+
589
+ EXAMPLES::
590
+
591
+ sage: R = Set(RR)
592
+ sage: R.an_element() # indirect doctest # needs sage.rings.real_mpfr
593
+ 1.00000000000000
594
+
595
+ sage: F = Set([1, 2, 3])
596
+ sage: F.an_element()
597
+ 1
598
+ """
599
+ if self.__object is not self:
600
+ try:
601
+ return self.__object.an_element()
602
+ except (AttributeError, NotImplementedError):
603
+ pass
604
+ return self._an_element_from_iterator()
605
+
606
+ def __contains__(self, x):
607
+ """
608
+ Return ``True`` if `x` is in ``self``.
609
+
610
+ EXAMPLES::
611
+
612
+ sage: X = Set(ZZ)
613
+ sage: 5 in X
614
+ True
615
+ sage: GF(7)(3) in X # needs sage.libs.pari
616
+ True
617
+ sage: 2/1 in X
618
+ True
619
+ sage: 2/1 in ZZ
620
+ True
621
+ sage: 2/3 in X
622
+ False
623
+
624
+ Finite fields better illustrate the difference between
625
+ ``__contains__`` for objects and their underlying sets::
626
+
627
+ sage: X = Set(GF(7))
628
+ sage: X
629
+ {0, 1, 2, 3, 4, 5, 6}
630
+ sage: 5/3 in X
631
+ False
632
+ sage: 5/3 in GF(7)
633
+ False
634
+ sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int)
635
+ [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6]
636
+ sage: Set(GF(7)).intersection(Set(GF(5)))
637
+ {}
638
+ """
639
+ return x in self.__object
640
+
641
+ def __richcmp__(self, right, op):
642
+ r"""
643
+ Compare ``self`` and ``right``.
644
+
645
+ If ``right`` is not a :class:`Set_object`, return ``NotImplemented``.
646
+ If ``right`` is also a :class:`Set_object`, returns comparison
647
+ on the underlying objects.
648
+
649
+ .. NOTE::
650
+
651
+ If `X < Y` is true this does *not* necessarily mean
652
+ that `X` is a subset of `Y`. Also, any two sets can be
653
+ compared still, but the result need not be meaningful
654
+ if they are not equal.
655
+
656
+ EXAMPLES::
657
+
658
+ sage: Set(ZZ) == Set(QQ)
659
+ False
660
+ sage: Set(ZZ) < Set(QQ)
661
+ True
662
+ sage: Primes() == Set(QQ)
663
+ False
664
+ """
665
+ if not isinstance(right, Set_object):
666
+ return NotImplemented
667
+ return richcmp(self.__object, right.__object, op)
668
+
669
+ def cardinality(self):
670
+ """
671
+ Return the cardinality of this set, which is either an integer or
672
+ ``Infinity``.
673
+
674
+ EXAMPLES::
675
+
676
+ sage: Set(ZZ).cardinality()
677
+ +Infinity
678
+ sage: Primes().cardinality()
679
+ +Infinity
680
+ sage: Set(GF(5)).cardinality()
681
+ 5
682
+ sage: Set(GF(5^2,'a')).cardinality() # needs sage.rings.finite_rings
683
+ 25
684
+ """
685
+ if self in Sets().Infinite():
686
+ return sage.rings.infinity.infinity
687
+
688
+ if not self.is_finite():
689
+ return sage.rings.infinity.infinity
690
+
691
+ if self is not self.__object:
692
+ try:
693
+ return self.__object.cardinality()
694
+ except (AttributeError, NotImplementedError):
695
+ pass
696
+ from sage.rings.integer import Integer
697
+ try:
698
+ return Integer(len(self.__object))
699
+ except TypeError:
700
+ pass
701
+
702
+ return super().cardinality()
703
+
704
+ def is_empty(self):
705
+ """
706
+ Return boolean representing emptiness of the set.
707
+
708
+ OUTPUT: ``True`` if the set is empty, ``False`` otherwise
709
+
710
+ EXAMPLES::
711
+
712
+ sage: Set([]).is_empty()
713
+ True
714
+ sage: Set([0]).is_empty()
715
+ False
716
+ sage: Set([1..100]).is_empty()
717
+ False
718
+ sage: Set(SymmetricGroup(2).list()).is_empty() # needs sage.groups
719
+ False
720
+ sage: Set(ZZ).is_empty()
721
+ False
722
+
723
+ TESTS::
724
+
725
+ sage: Set([]).is_empty()
726
+ True
727
+ sage: Set([1,2,3]).is_empty()
728
+ False
729
+ sage: Set([1..100]).is_empty()
730
+ False
731
+ sage: Set(DihedralGroup(4).list()).is_empty() # needs sage.groups
732
+ False
733
+ sage: Set(QQ).is_empty()
734
+ False
735
+ """
736
+ return not self
737
+
738
+ def is_finite(self):
739
+ """
740
+ Return ``True`` if ``self`` is finite.
741
+
742
+ EXAMPLES::
743
+
744
+ sage: Set(QQ).is_finite()
745
+ False
746
+ sage: Set(GF(250037)).is_finite() # needs sage.rings.finite_rings
747
+ True
748
+ sage: Set(Integers(2^1000000)).is_finite()
749
+ True
750
+ sage: Set([1,'a',ZZ]).is_finite()
751
+ True
752
+ """
753
+ if self in Sets().Finite():
754
+ return True
755
+ if self in Sets().Infinite():
756
+ return False
757
+ obj = self.__object
758
+ try:
759
+ is_finite = obj.is_finite
760
+ except AttributeError:
761
+ return has_finite_length(obj)
762
+ else:
763
+ return is_finite()
764
+
765
+ def object(self):
766
+ """
767
+ Return underlying object.
768
+
769
+ EXAMPLES::
770
+
771
+ sage: X = Set(QQ)
772
+ sage: X.object()
773
+ Rational Field
774
+ sage: X = Primes()
775
+ sage: X.object()
776
+ Set of all prime numbers: 2, 3, 5, 7, ...
777
+ """
778
+ return self.__object
779
+
780
+ def subsets(self, size=None):
781
+ """
782
+ Return the :class:`Subsets` object representing the subsets of a set.
783
+ If size is specified, return the subsets of that size.
784
+
785
+ EXAMPLES::
786
+
787
+ sage: X = Set([1, 2, 3])
788
+ sage: list(X.subsets())
789
+ [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}]
790
+ sage: list(X.subsets(2))
791
+ [{1, 2}, {1, 3}, {2, 3}]
792
+ """
793
+ from sage.combinat.subset import Subsets
794
+ return Subsets(self, size)
795
+
796
+ def subsets_lattice(self):
797
+ """
798
+ Return the lattice of subsets ordered by containment.
799
+
800
+ EXAMPLES::
801
+
802
+ sage: X = Set([1,2,3])
803
+ sage: X.subsets_lattice() # needs sage.graphs
804
+ Finite lattice containing 8 elements
805
+ sage: Y = Set()
806
+ sage: Y.subsets_lattice() # needs sage.graphs
807
+ Finite lattice containing 1 elements
808
+ """
809
+ if not self.is_finite():
810
+ raise NotImplementedError(
811
+ "this method is only implemented for finite sets")
812
+ from sage.combinat.posets.lattices import FiniteLatticePoset
813
+ from sage.graphs.digraph import DiGraph
814
+ from sage.rings.integer import Integer
815
+ n = self.cardinality()
816
+ # list, contains at position 0 <= i < 2^n
817
+ # the i-th subset of self
818
+ subset_of_index = [Set([self[i] for i in range(n) if v & (1 << i)])
819
+ for v in range(2**n)]
820
+ # list, contains at position 0 <= i < 2^n
821
+ # the list of indices of all immediate supersets
822
+ upper_covers = [[Integer(x | (1 << y)) for y in range(n) if not x & (1 << y)]
823
+ for x in range(2**n)]
824
+ # DiGraph, every subset points to all immediate supersets
825
+ D = DiGraph({subset_of_index[v]:
826
+ [subset_of_index[w] for w in upper_covers[v]]
827
+ for v in range(2**n)})
828
+ # Lattice poset, defined by hasse diagram D
829
+ L = FiniteLatticePoset(hasse_diagram=D)
830
+ return L
831
+
832
+ @cached_method
833
+ def _sympy_(self):
834
+ """
835
+ Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``.
836
+
837
+ EXAMPLES::
838
+
839
+ sage: X = Set(ZZ); X
840
+ Set of elements of Integer Ring
841
+ sage: X._sympy_() # needs sympy
842
+ Integers
843
+ """
844
+ from sage.interfaces.sympy import sympy_init
845
+ sympy_init()
846
+ return self.__object._sympy_()
847
+
848
+
849
+ class Set_object_enumerated(Set_object):
850
+ """
851
+ A finite enumerated set.
852
+ """
853
+ def __init__(self, X, category=None):
854
+ r"""
855
+ Initialize ``self``.
856
+
857
+ EXAMPLES::
858
+
859
+ sage: S = Set(GF(19)); S
860
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
861
+ sage: S.category()
862
+ Category of finite enumerated sets
863
+ sage: print(latex(S))
864
+ \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\}
865
+ sage: TestSuite(S).run()
866
+ """
867
+ Set_object.__init__(self, X, category=FiniteEnumeratedSets().or_subcategory(category))
868
+
869
+ def random_element(self):
870
+ r"""
871
+ Return a random element in this set.
872
+
873
+ EXAMPLES::
874
+
875
+ sage: Set([1,2,3]).random_element() # random
876
+ 2
877
+ """
878
+ try:
879
+ return self.object().random_element()
880
+ except AttributeError:
881
+ # TODO: this very slow!
882
+ return choice(self.list())
883
+
884
+ def is_finite(self):
885
+ r"""
886
+ Return ``True`` as this is a finite set.
887
+
888
+ EXAMPLES::
889
+
890
+ sage: Set(GF(19)).is_finite()
891
+ True
892
+ """
893
+ return True
894
+
895
+ def cardinality(self):
896
+ """
897
+ Return the cardinality of ``self``.
898
+
899
+ EXAMPLES::
900
+
901
+ sage: Set([1,1]).cardinality()
902
+ 1
903
+ """
904
+ from sage.rings.integer import Integer
905
+ return Integer(len(self.set()))
906
+
907
+ def __len__(self):
908
+ """
909
+ EXAMPLES::
910
+
911
+ sage: len(Set([1,1]))
912
+ 1
913
+ """
914
+ return len(self.set())
915
+
916
+ def __iter__(self):
917
+ r"""
918
+ Iterating through the elements of ``self``.
919
+
920
+ EXAMPLES::
921
+
922
+ sage: S = Set(GF(19))
923
+ sage: I = iter(S)
924
+ sage: next(I)
925
+ 0
926
+ sage: next(I)
927
+ 1
928
+ sage: next(I)
929
+ 2
930
+ sage: next(I)
931
+ 3
932
+ """
933
+ return iter(self.set())
934
+
935
+ def _latex_(self):
936
+ r"""
937
+ Return the LaTeX representation of ``self``.
938
+
939
+ EXAMPLES::
940
+
941
+ sage: S = Set(GF(2))
942
+ sage: latex(S)
943
+ \left\{0, 1\right\}
944
+ """
945
+ return '\\left\\{' + ', '.join(latex(x) for x in self.set()) + '\\right\\}'
946
+
947
+ def _repr_(self):
948
+ r"""
949
+ Return the string representation of ``self``.
950
+
951
+ EXAMPLES::
952
+
953
+ sage: S = Set(GF(2))
954
+ sage: S
955
+ {0, 1}
956
+
957
+ TESTS::
958
+
959
+ sage: Set()
960
+ {}
961
+ """
962
+ py_set = self.set()
963
+ if not py_set:
964
+ return "{}"
965
+ return repr(py_set)
966
+
967
+ def list(self):
968
+ """
969
+ Return the elements of ``self``, as a list.
970
+
971
+ EXAMPLES::
972
+
973
+ sage: # needs sage.rings.finite_rings
974
+ sage: X = Set(GF(8,'c'))
975
+ sage: X
976
+ {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}
977
+ sage: X.list()
978
+ [0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]
979
+ sage: type(X.list())
980
+ <... 'list'>
981
+
982
+ .. TODO::
983
+
984
+ FIXME: What should be the order of the result?
985
+ That of ``self.object()``? Or the order given by
986
+ ``set(self.object())``? Note that :meth:`__getitem__` is
987
+ currently implemented in term of this list method, which
988
+ is really inefficient ...
989
+ """
990
+ return list(set(self.object()))
991
+
992
+ def set(self):
993
+ """
994
+ Return the Python set object associated to this set.
995
+
996
+ Python has a notion of finite set, and often Sage sets
997
+ have an associated Python set. This function returns
998
+ that set.
999
+
1000
+ EXAMPLES::
1001
+
1002
+ sage: # needs sage.rings.finite_rings
1003
+ sage: X = Set(GF(8,'c'))
1004
+ sage: X
1005
+ {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}
1006
+ sage: X.set()
1007
+ {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}
1008
+ sage: type(X.set())
1009
+ <... 'set'>
1010
+ sage: type(X)
1011
+ <class 'sage.sets.set.Set_object_enumerated_with_category'>
1012
+ """
1013
+ return set(self.object())
1014
+
1015
+ def frozenset(self):
1016
+ """
1017
+ Return the Python frozenset object associated to this set,
1018
+ which is an immutable set (hence hashable).
1019
+
1020
+ EXAMPLES::
1021
+
1022
+ sage: # needs sage.rings.finite_rings
1023
+ sage: X = Set(GF(8,'c'))
1024
+ sage: X
1025
+ {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}
1026
+ sage: s = X.set(); s
1027
+ {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}
1028
+ sage: hash(s)
1029
+ Traceback (most recent call last):
1030
+ ...
1031
+ TypeError: ...unhashable type: 'set'...
1032
+ sage: s = X.frozenset(); s
1033
+ frozenset({0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1})
1034
+
1035
+ sage: hash(s) != hash(tuple(X.set())) # needs sage.rings.finite_rings
1036
+ True
1037
+
1038
+ sage: type(s) # needs sage.rings.finite_rings
1039
+ <... 'frozenset'>
1040
+ """
1041
+ return frozenset(self.object())
1042
+
1043
+ def __hash__(self):
1044
+ """
1045
+ Return the hash of ``self`` (as a ``frozenset``).
1046
+
1047
+ EXAMPLES::
1048
+
1049
+ sage: s = Set(GF(8,'c')) # needs sage.rings.finite_rings
1050
+ sage: hash(s) == hash(s) # needs sage.rings.finite_rings
1051
+ True
1052
+ """
1053
+ return hash(self.frozenset())
1054
+
1055
+ def __richcmp__(self, other, op):
1056
+ """
1057
+ Compare the sets ``self`` and ``other``.
1058
+
1059
+ EXAMPLES::
1060
+
1061
+ sage: X = Set(GF(8,'c')) # needs sage.rings.finite_rings
1062
+ sage: X == Set(GF(8,'c')) # needs sage.rings.finite_rings
1063
+ True
1064
+ sage: X == Set(GF(4,'a')) # needs sage.rings.finite_rings
1065
+ False
1066
+ sage: Set(QQ) == Set(ZZ)
1067
+ False
1068
+ sage: Set([1]) == set([1])
1069
+ True
1070
+
1071
+ Test set equality and inequality::
1072
+
1073
+ sage: L = {0}
1074
+ sage: S = Set(L)
1075
+ sage: S == L
1076
+ True
1077
+ sage: S != L
1078
+ False
1079
+ """
1080
+ if not isinstance(other, Set_object_enumerated):
1081
+ if isinstance(other, (set, frozenset)):
1082
+ if self.set() == other:
1083
+ return rich_to_bool(op, 0)
1084
+ return NotImplemented
1085
+ if self.set() == other.set():
1086
+ return rich_to_bool(op, 0)
1087
+ return rich_to_bool(op, -1)
1088
+
1089
+ def issubset(self, other):
1090
+ r"""
1091
+ Return whether ``self`` is a subset of ``other``.
1092
+
1093
+ INPUT:
1094
+
1095
+ - ``other`` -- a finite Set
1096
+
1097
+ EXAMPLES::
1098
+
1099
+ sage: X = Set([1,3,5])
1100
+ sage: Y = Set([0,1,2,3,5,7])
1101
+ sage: X.issubset(Y)
1102
+ True
1103
+ sage: Y.issubset(X)
1104
+ False
1105
+ sage: X.issubset(X)
1106
+ True
1107
+
1108
+ TESTS::
1109
+
1110
+ sage: len([Z for Z in Y.subsets() if Z.issubset(X)])
1111
+ 8
1112
+ """
1113
+ if not isinstance(other, Set_object_enumerated):
1114
+ raise NotImplementedError
1115
+ return self.set().issubset(other.set())
1116
+
1117
+ def issuperset(self, other):
1118
+ r"""
1119
+ Return whether ``self`` is a superset of ``other``.
1120
+
1121
+ INPUT:
1122
+
1123
+ - ``other`` -- a finite Set
1124
+
1125
+ EXAMPLES::
1126
+
1127
+ sage: X = Set([1,3,5])
1128
+ sage: Y = Set([0,1,2,3,5])
1129
+ sage: X.issuperset(Y)
1130
+ False
1131
+ sage: Y.issuperset(X)
1132
+ True
1133
+ sage: X.issuperset(X)
1134
+ True
1135
+
1136
+ TESTS::
1137
+
1138
+ sage: len([Z for Z in Y.subsets() if Z.issuperset(X)])
1139
+ 4
1140
+ """
1141
+ if not isinstance(other, Set_object_enumerated):
1142
+ raise NotImplementedError
1143
+ return self.set().issuperset(other.set())
1144
+
1145
+ def union(self, other):
1146
+ """
1147
+ Return the union of ``self`` and ``other``.
1148
+
1149
+ EXAMPLES::
1150
+
1151
+ sage: # needs sage.rings.finite_rings
1152
+ sage: X = Set(GF(8,'c'))
1153
+ sage: Y = Set([GF(8,'c').0, 1, 2, 3])
1154
+ sage: X
1155
+ {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}
1156
+ sage: sorted(Y)
1157
+ [1, 2, 3, c]
1158
+ sage: sorted(X.union(Y), key=str)
1159
+ [0, 1, 2, 3, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]
1160
+ """
1161
+ if not isinstance(other, Set_object_enumerated):
1162
+ return Set_object.union(self, other)
1163
+ return Set_object_enumerated(self.set().union(other.set()))
1164
+
1165
+ def intersection(self, other):
1166
+ """
1167
+ Return the intersection of ``self`` and ``other``.
1168
+
1169
+ EXAMPLES::
1170
+
1171
+ sage: X = Set(GF(8,'c')) # needs sage.rings.finite_rings
1172
+ sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # needs sage.rings.finite_rings
1173
+ sage: sorted(X.intersection(Y), key=str) # needs sage.rings.finite_rings
1174
+ [1, c]
1175
+ """
1176
+ if not isinstance(other, Set_object_enumerated):
1177
+ return Set_object.intersection(self, other)
1178
+ return Set_object_enumerated(self.set().intersection(other.set()))
1179
+
1180
+ def difference(self, other):
1181
+ """
1182
+ Return the set difference ``self - other``.
1183
+
1184
+ EXAMPLES::
1185
+
1186
+ sage: X = Set([1,2,3,4])
1187
+ sage: Y = Set([1,2])
1188
+ sage: X.difference(Y)
1189
+ {3, 4}
1190
+ sage: Z = Set(ZZ)
1191
+ sage: W = Set([2.5, 4, 5, 6])
1192
+ sage: W.difference(Z) # needs sage.rings.real_mpfr
1193
+ {2.50000000000000}
1194
+ """
1195
+ if not isinstance(other, Set_object_enumerated):
1196
+ return Set([x for x in self if x not in other])
1197
+ return Set_object_enumerated(self.set().difference(other.set()))
1198
+
1199
+ def symmetric_difference(self, other):
1200
+ """
1201
+ Return the symmetric difference of ``self`` and ``other``.
1202
+
1203
+ EXAMPLES::
1204
+
1205
+ sage: X = Set([1,2,3,4])
1206
+ sage: Y = Set([1,2])
1207
+ sage: X.symmetric_difference(Y)
1208
+ {3, 4}
1209
+ sage: Z = Set(ZZ)
1210
+ sage: W = Set([2.5, 4, 5, 6])
1211
+ sage: U = W.symmetric_difference(Z)
1212
+ sage: 2.5 in U
1213
+ True
1214
+ sage: 4 in U
1215
+ False
1216
+ sage: V = Z.symmetric_difference(W)
1217
+ sage: V == U
1218
+ True
1219
+ sage: 2.5 in V
1220
+ True
1221
+ sage: 6 in V
1222
+ False
1223
+ """
1224
+ if not isinstance(other, Set_object_enumerated):
1225
+ return Set_object.symmetric_difference(self, other)
1226
+ return Set_object_enumerated(self.set().symmetric_difference(other.set()))
1227
+
1228
+ @cached_method
1229
+ def _sympy_(self):
1230
+ """
1231
+ Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``.
1232
+
1233
+ EXAMPLES::
1234
+
1235
+ sage: X = Set({1, 2, 3}); X
1236
+ {1, 2, 3}
1237
+ sage: sX = X._sympy_(); sX # needs sympy
1238
+ Set(1, 2, 3)
1239
+ sage: sX.is_empty is None # needs sympy
1240
+ True
1241
+
1242
+ sage: Empty = Set([]); Empty
1243
+ {}
1244
+ sage: sEmpty = Empty._sympy_(); sEmpty # needs sympy
1245
+ EmptySet
1246
+ sage: sEmpty.is_empty # needs sympy
1247
+ True
1248
+ """
1249
+ from sympy import Set, EmptySet
1250
+ from sage.interfaces.sympy import sympy_init
1251
+ sympy_init()
1252
+ if self.is_empty():
1253
+ return EmptySet
1254
+ return Set(*[x._sympy_() for x in self])
1255
+
1256
+
1257
+ class Set_object_binary(Set_object, metaclass=ClasscallMetaclass):
1258
+ r"""
1259
+ An abstract common base class for sets defined by a binary operation (ex.
1260
+ :class:`Set_object_union`, :class:`Set_object_intersection`,
1261
+ :class:`Set_object_difference`, and
1262
+ :class:`Set_object_symmetric_difference`).
1263
+
1264
+ INPUT:
1265
+
1266
+ - ``X``, ``Y`` -- sets, the operands to ``op``
1267
+
1268
+ - ``op`` -- string describing the binary operation
1269
+
1270
+ - ``latex_op`` -- string used for rendering this object in LaTeX
1271
+
1272
+ EXAMPLES::
1273
+
1274
+ sage: X = Set(QQ^2) # needs sage.modules
1275
+ sage: Y = Set(ZZ)
1276
+ sage: from sage.sets.set import Set_object_binary
1277
+ sage: S = Set_object_binary(X, Y, "union", "\\cup"); S # needs sage.modules
1278
+ Set-theoretic union of
1279
+ Set of elements of Vector space of dimension 2 over Rational Field and
1280
+ Set of elements of Integer Ring
1281
+ """
1282
+
1283
+ @staticmethod
1284
+ def __classcall__(cls, X, Y, *args, **kwds):
1285
+ r"""
1286
+ Convert the operands to instances of :class:`Set_object` if necessary.
1287
+
1288
+ TESTS::
1289
+
1290
+ sage: from sage.sets.set import Set_object_binary
1291
+ sage: X = QQ^2 # needs sage.modules
1292
+ sage: Y = ZZ
1293
+ sage: Set_object_binary(X, Y, "union", "\\cup") # needs sage.modules
1294
+ Set-theoretic union of
1295
+ Set of elements of Vector space of dimension 2 over Rational Field and
1296
+ Set of elements of Integer Ring
1297
+ """
1298
+ if not isinstance(X, Set_object):
1299
+ X = Set(X)
1300
+ if not isinstance(Y, Set_object):
1301
+ Y = Set(Y)
1302
+ return type.__call__(cls, X, Y, *args, **kwds)
1303
+
1304
+ def __init__(self, X, Y, op, latex_op, category=None):
1305
+ r"""
1306
+ Initialization.
1307
+
1308
+ TESTS::
1309
+
1310
+ sage: from sage.sets.set import Set_object_binary
1311
+ sage: X = Set(QQ^2) # needs sage.modules
1312
+ sage: Y = Set(ZZ)
1313
+ sage: S = Set_object_binary(X, Y, "union", "\\cup") # needs sage.modules
1314
+ sage: type(S) # needs sage.modules
1315
+ <class 'sage.sets.set.Set_object_binary_with_category'>
1316
+ """
1317
+ self._X = X
1318
+ self._Y = Y
1319
+ self._op = op
1320
+ self._latex_op = latex_op
1321
+ Set_object.__init__(self, self, category=category)
1322
+
1323
+ def _repr_(self):
1324
+ r"""
1325
+ Return a string representation of this set.
1326
+
1327
+ EXAMPLES::
1328
+
1329
+ sage: Set(ZZ).union(Set(GF(5)))
1330
+ Set-theoretic union of Set of elements of Integer Ring and {0, 1, 2, 3, 4}
1331
+ """
1332
+ return "Set-theoretic {} of {} and {}".format(self._op, self._X, self._Y)
1333
+
1334
+ def _latex_(self):
1335
+ r"""
1336
+ Return a latex representation of this set.
1337
+
1338
+ EXAMPLES::
1339
+
1340
+ sage: latex(Set(ZZ).union(Set(GF(5))))
1341
+ \Bold{Z} \cup \left\{0, 1, 2, 3, 4\right\}
1342
+ """
1343
+ return latex(self._X) + self._latex_op + latex(self._Y)
1344
+
1345
+ def __hash__(self):
1346
+ """
1347
+ The hash value of this set.
1348
+
1349
+ EXAMPLES:
1350
+
1351
+ The hash values of equal sets are in general not equal since it is not
1352
+ decidable whether two sets are equal::
1353
+
1354
+ sage: X = Set(GF(13)).intersection(Set(ZZ))
1355
+ sage: Y = Set(ZZ).intersection(Set(GF(13)))
1356
+ sage: hash(X) == hash(Y)
1357
+ False
1358
+
1359
+ TESTS:
1360
+
1361
+ Test that :issue:`14432` has been resolved::
1362
+
1363
+ sage: S = Set(ZZ).union(Set([infinity]))
1364
+ sage: T = Set(ZZ).union(Set([infinity]))
1365
+ sage: hash(S) == hash(T)
1366
+ True
1367
+ """
1368
+ return hash((self._X, self._Y, self._op))
1369
+
1370
+
1371
+ class Set_object_union(Set_object_binary):
1372
+ """
1373
+ A formal union of two sets.
1374
+ """
1375
+ def __init__(self, X, Y, category=None):
1376
+ r"""
1377
+ Initialize ``self``.
1378
+
1379
+ EXAMPLES::
1380
+
1381
+ sage: # needs sage.modules
1382
+ sage: S = Set(QQ^2)
1383
+ sage: T = Set(ZZ)
1384
+ sage: X = S.union(T); X
1385
+ Set-theoretic union of
1386
+ Set of elements of Vector space of dimension 2 over Rational Field and
1387
+ Set of elements of Integer Ring
1388
+ sage: X.category()
1389
+ Category of infinite sets
1390
+ sage: latex(X)
1391
+ \Bold{Q}^{2} \cup \Bold{Z}
1392
+ sage: TestSuite(X).run()
1393
+ """
1394
+ if category is None:
1395
+ category = Sets()
1396
+ if all(S in Sets().Enumerated() for S in (X, Y)):
1397
+ category = category.Enumerated()
1398
+ if any(S in Sets().Infinite() for S in (X, Y)):
1399
+ category = category.Infinite()
1400
+ elif all(S in Sets().Finite() for S in (X, Y)):
1401
+ category = category.Finite()
1402
+ Set_object_binary.__init__(self, X, Y, "union", "\\cup", category=category)
1403
+
1404
+ def is_finite(self):
1405
+ r"""
1406
+ Return whether this set is finite.
1407
+
1408
+ EXAMPLES::
1409
+
1410
+ sage: X = Set(range(10))
1411
+ sage: Y = Set(range(-10,0))
1412
+ sage: Z = Set(Primes())
1413
+ sage: X.union(Y).is_finite()
1414
+ True
1415
+ sage: X.union(Z).is_finite()
1416
+ False
1417
+ """
1418
+ return self._X.is_finite() and self._Y.is_finite()
1419
+
1420
+ def __richcmp__(self, right, op):
1421
+ r"""
1422
+ Try to compare ``self`` and ``right``.
1423
+
1424
+ .. NOTE::
1425
+
1426
+ Comparison is basically not implemented, or rather it could
1427
+ say sets are not equal even though they are. I don't know
1428
+ how one could implement this for a generic union of sets in
1429
+ a meaningful manner. So be careful when using this.
1430
+
1431
+ EXAMPLES::
1432
+
1433
+ sage: # needs sage.modules
1434
+ sage: Y = Set(ZZ^2).union(Set(ZZ^3))
1435
+ sage: X = Set(ZZ^3).union(Set(ZZ^2))
1436
+ sage: X == Y
1437
+ True
1438
+ sage: Y == X
1439
+ True
1440
+
1441
+ This illustrates that equality testing for formal unions
1442
+ can be misleading in general.
1443
+
1444
+ ::
1445
+
1446
+ sage: Set(ZZ).union(Set(QQ)) == Set(QQ)
1447
+ False
1448
+ """
1449
+ if not isinstance(right, Set_generic):
1450
+ return rich_to_bool(op, -1)
1451
+ if not isinstance(right, Set_object_union):
1452
+ return rich_to_bool(op, -1)
1453
+ if self._X == right._X and self._Y == right._Y or \
1454
+ self._X == right._Y and self._Y == right._X:
1455
+ return rich_to_bool(op, 0)
1456
+ return rich_to_bool(op, -1)
1457
+
1458
+ def __iter__(self):
1459
+ """
1460
+ Return iterator over the elements of ``self``.
1461
+
1462
+ EXAMPLES::
1463
+
1464
+ sage: [x for x in Set(GF(3)).union(Set(GF(2)))]
1465
+ [0, 1, 2, 0, 1]
1466
+ """
1467
+ yield from self._X
1468
+ yield from self._Y
1469
+
1470
+ def __contains__(self, x):
1471
+ """
1472
+ Return ``True`` if ``x`` is an element of ``self``.
1473
+
1474
+ EXAMPLES::
1475
+
1476
+ sage: # needs sage.rings.finite_rings
1477
+ sage: X = Set(GF(3)).union(Set(GF(2)))
1478
+ sage: GF(5)(1) in X
1479
+ False
1480
+ sage: GF(3)(2) in X
1481
+ True
1482
+ sage: GF(2)(0) in X
1483
+ True
1484
+ sage: GF(5)(0) in X
1485
+ False
1486
+ """
1487
+ return x in self._X or x in self._Y
1488
+
1489
+ def cardinality(self):
1490
+ """
1491
+ Return the cardinality of this set.
1492
+
1493
+ EXAMPLES::
1494
+
1495
+ sage: X = Set(GF(3)).union(Set(GF(2)))
1496
+ sage: X
1497
+ {0, 1, 2, 0, 1}
1498
+ sage: X.cardinality()
1499
+ 5
1500
+
1501
+ sage: X = Set(GF(3)).union(Set(ZZ))
1502
+ sage: X.cardinality()
1503
+ +Infinity
1504
+ """
1505
+ return self._X.cardinality() + self._Y.cardinality()
1506
+
1507
+ @cached_method
1508
+ def _sympy_(self):
1509
+ """
1510
+ Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``.
1511
+
1512
+ EXAMPLES::
1513
+
1514
+ sage: X = Set(ZZ).union(Set([1/2])); X
1515
+ Set-theoretic union of Set of elements of Integer Ring and {1/2}
1516
+ sage: X._sympy_() # needs sympy
1517
+ Union(Integers, Set(1/2))
1518
+ """
1519
+ from sympy import Union
1520
+ from sage.interfaces.sympy import sympy_init
1521
+ sympy_init()
1522
+ return Union(self._X._sympy_(), self._Y._sympy_())
1523
+
1524
+ def __bool__(self):
1525
+ """
1526
+ Return ``True`` if this set is not empty.
1527
+
1528
+ EXAMPLES::
1529
+
1530
+ sage: bool(Set(GF(3)).union(Set(GF(2))))
1531
+ True
1532
+ sage: bool(Set(GF(3)).intersection(Set(GF(2))))
1533
+ False
1534
+
1535
+ TESTS:
1536
+
1537
+ This should still work in the case the first set is nonempty
1538
+ and the second set has :meth:`is_empty` unimplemented::
1539
+
1540
+ sage: C = ConditionSet(QQ, lambda x: x > 0)
1541
+ sage: C.is_empty()
1542
+ Traceback (most recent call last):
1543
+ ...
1544
+ AttributeError...
1545
+ sage: C.is_finite()
1546
+ Traceback (most recent call last):
1547
+ ...
1548
+ AttributeError...
1549
+ sage: bool(Set([1]) + C)
1550
+ True
1551
+ sage: (Set([1]) + C).is_empty()
1552
+ False
1553
+ """
1554
+ return bool(self._X) or bool(self._Y)
1555
+
1556
+
1557
+ class Set_object_intersection(Set_object_binary):
1558
+ """
1559
+ Formal intersection of two sets.
1560
+ """
1561
+ def __init__(self, X, Y, category=None):
1562
+ r"""
1563
+ Initialize ``self``.
1564
+
1565
+ EXAMPLES::
1566
+
1567
+ sage: # needs sage.modules
1568
+ sage: S = Set(QQ^2)
1569
+ sage: T = Set(ZZ)
1570
+ sage: X = S.intersection(T); X
1571
+ Set-theoretic intersection of
1572
+ Set of elements of Vector space of dimension 2 over Rational Field and
1573
+ Set of elements of Integer Ring
1574
+ sage: X.category()
1575
+ Category of enumerated sets
1576
+ sage: latex(X)
1577
+ \Bold{Q}^{2} \cap \Bold{Z}
1578
+
1579
+ sage: X = Set(IntegerRange(100)).intersection(Primes())
1580
+ sage: X.is_finite()
1581
+ True
1582
+ sage: X.cardinality()
1583
+ 25
1584
+ sage: X.category()
1585
+ Category of finite enumerated sets
1586
+ sage: TestSuite(X).run()
1587
+
1588
+ sage: X = Set(Primes(), category=Sets()).intersection(Set(IntegerRange(200)))
1589
+ sage: X.cardinality()
1590
+ 46
1591
+ sage: TestSuite(X).run()
1592
+ """
1593
+ if category is None:
1594
+ category = Sets()
1595
+ if any(S in Sets().Finite() for S in (X, Y)):
1596
+ category = category.Finite()
1597
+ if any(S in Sets().Enumerated() for S in (X, Y)):
1598
+ category = category.Enumerated()
1599
+ Set_object_binary.__init__(self, X, Y, "intersection", "\\cap", category=category)
1600
+
1601
+ def is_finite(self):
1602
+ r"""
1603
+ Return whether this set is finite.
1604
+
1605
+ EXAMPLES::
1606
+
1607
+ sage: X = Set(IntegerRange(100))
1608
+ sage: Y = Set(ZZ)
1609
+ sage: X.intersection(Y).is_finite()
1610
+ True
1611
+ sage: Y.intersection(X).is_finite()
1612
+ True
1613
+ sage: Y.intersection(Set(QQ)).is_finite()
1614
+ Traceback (most recent call last):
1615
+ ...
1616
+ NotImplementedError
1617
+ """
1618
+ if self._X.is_finite():
1619
+ return True
1620
+ elif self._Y.is_finite():
1621
+ return True
1622
+ raise NotImplementedError
1623
+
1624
+ def __richcmp__(self, right, op):
1625
+ r"""
1626
+ Try to compare ``self`` and ``right``.
1627
+
1628
+ .. NOTE::
1629
+
1630
+ Comparison is basically not implemented, or rather it could
1631
+ say sets are not equal even though they are. I don't know
1632
+ how one could implement this for a generic intersection of
1633
+ sets in a meaningful manner. So be careful when using this.
1634
+
1635
+ EXAMPLES::
1636
+
1637
+ sage: Y = Set(ZZ).intersection(Set(QQ))
1638
+ sage: X = Set(QQ).intersection(Set(ZZ))
1639
+ sage: X == Y
1640
+ True
1641
+ sage: Y == X
1642
+ True
1643
+
1644
+ This illustrates that equality testing for formal unions
1645
+ can be misleading in general.
1646
+
1647
+ ::
1648
+
1649
+ sage: Set(ZZ).intersection(Set(QQ)) == Set(QQ)
1650
+ False
1651
+ """
1652
+ if not isinstance(right, Set_generic):
1653
+ return rich_to_bool(op, -1)
1654
+ if not isinstance(right, Set_object_intersection):
1655
+ return rich_to_bool(op, -1)
1656
+ if self._X == right._X and self._Y == right._Y or \
1657
+ self._X == right._Y and self._Y == right._X:
1658
+ return rich_to_bool(op, 0)
1659
+ return rich_to_bool(op, -1)
1660
+
1661
+ def __iter__(self):
1662
+ """
1663
+ Return iterator through elements of ``self``.
1664
+
1665
+ ``self`` is a formal intersection of `X` and `Y` and this function is
1666
+ implemented by iterating through the elements of `X` and for
1667
+ each checking if it is in `Y`, and if yielding it.
1668
+
1669
+ EXAMPLES::
1670
+
1671
+ sage: X = Set(ZZ).intersection(Primes())
1672
+ sage: I = X.__iter__()
1673
+ sage: next(I)
1674
+ 2
1675
+
1676
+ Check that known finite intersections have finite iterators (see
1677
+ :issue:`18159`)::
1678
+
1679
+ sage: P = Set(ZZ).intersection(Set(range(10,20)))
1680
+ sage: list(P)
1681
+ [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
1682
+ """
1683
+ X = self._X
1684
+ Y = self._Y
1685
+ if not self._X.is_finite() and self._Y.is_finite():
1686
+ X, Y = Y, X
1687
+ for x in X:
1688
+ if x in Y:
1689
+ yield x
1690
+
1691
+ def __contains__(self, x):
1692
+ """
1693
+ Return ``True`` if ``self`` contains ``x``.
1694
+
1695
+ Since ``self`` is a formal intersection of `X` and `Y` this function
1696
+ returns ``True`` if both `X` and `Y` contains ``x``.
1697
+
1698
+ EXAMPLES::
1699
+
1700
+ sage: X = Set(QQ).intersection(Set(RR))
1701
+ sage: 5 in X
1702
+ True
1703
+ sage: ComplexField().0 in X # needs sage.rings.real_mpfr
1704
+ False
1705
+
1706
+ Any specific floating-point number in Sage is to finite precision,
1707
+ hence it is rational::
1708
+
1709
+ sage: RR(sqrt(2)) in X # needs sage.rings.real_mpfr sage.symbolic
1710
+ True
1711
+
1712
+ Real constants are not rational::
1713
+
1714
+ sage: pi in X # needs sage.symbolic
1715
+ False
1716
+ """
1717
+ return x in self._X and x in self._Y
1718
+
1719
+ @cached_method
1720
+ def _sympy_(self):
1721
+ """
1722
+ Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``.
1723
+
1724
+ EXAMPLES::
1725
+
1726
+ sage: X = Set(ZZ).intersection(RealSet([3/2, 11/2])); X
1727
+ Set-theoretic intersection of
1728
+ Set of elements of Integer Ring and
1729
+ Set of elements of [3/2, 11/2]
1730
+ sage: X._sympy_() # needs sympy
1731
+ Range(2, 6, 1)
1732
+ """
1733
+ from sympy import Intersection
1734
+ from sage.interfaces.sympy import sympy_init
1735
+ sympy_init()
1736
+ return Intersection(self._X._sympy_(), self._Y._sympy_())
1737
+
1738
+
1739
+ class Set_object_difference(Set_object_binary):
1740
+ """
1741
+ Formal difference of two sets.
1742
+ """
1743
+ def __init__(self, X, Y, category=None):
1744
+ r"""
1745
+ Initialize ``self``.
1746
+
1747
+ EXAMPLES::
1748
+
1749
+ sage: S = Set(QQ)
1750
+ sage: T = Set(ZZ)
1751
+ sage: X = S.difference(T); X
1752
+ Set-theoretic difference of
1753
+ Set of elements of Rational Field and
1754
+ Set of elements of Integer Ring
1755
+ sage: X.category()
1756
+ Category of sets
1757
+ sage: latex(X)
1758
+ \Bold{Q} - \Bold{Z}
1759
+
1760
+ sage: TestSuite(X).run()
1761
+ """
1762
+ if category is None:
1763
+ category = Sets()
1764
+ if X in Sets().Enumerated():
1765
+ category = category.Enumerated()
1766
+ if X in Sets().Finite():
1767
+ category = category.Finite()
1768
+ elif X in Sets().Infinite() and Y in Sets().Finite():
1769
+ category = category.Infinite()
1770
+ Set_object_binary.__init__(self, X, Y, "difference", "-", category=category)
1771
+
1772
+ def is_finite(self):
1773
+ r"""
1774
+ Return whether this set is finite.
1775
+
1776
+ EXAMPLES::
1777
+
1778
+ sage: X = Set(range(10))
1779
+ sage: Y = Set(range(-10,5))
1780
+ sage: Z = Set(QQ)
1781
+ sage: X.difference(Y).is_finite()
1782
+ True
1783
+ sage: X.difference(Z).is_finite()
1784
+ True
1785
+ sage: Z.difference(X).is_finite()
1786
+ False
1787
+ sage: Z.difference(Set(ZZ)).is_finite()
1788
+ Traceback (most recent call last):
1789
+ ...
1790
+ NotImplementedError
1791
+ """
1792
+ if self._X.is_finite():
1793
+ return True
1794
+ elif self._Y.is_finite():
1795
+ return False
1796
+ raise NotImplementedError
1797
+
1798
+ def __richcmp__(self, right, op):
1799
+ r"""
1800
+ Try to compare ``self`` and ``right``.
1801
+
1802
+ .. NOTE::
1803
+
1804
+ Comparison is basically not implemented, or rather it could
1805
+ say sets are not equal even though they are. I don't know
1806
+ how one could implement this for a generic intersection of
1807
+ sets in a meaningful manner. So be careful when using
1808
+ this.
1809
+
1810
+ EXAMPLES::
1811
+
1812
+ sage: Y = Set(ZZ).difference(Set(QQ))
1813
+ sage: Y == Set([])
1814
+ False
1815
+ sage: X = Set(QQ).difference(Set(ZZ))
1816
+ sage: Y == X
1817
+ False
1818
+ sage: Z = X.difference(Set(ZZ))
1819
+ sage: Z == X
1820
+ False
1821
+
1822
+ This illustrates that equality testing for formal unions
1823
+ can be misleading in general.
1824
+
1825
+ ::
1826
+
1827
+ sage: X == Set(QQ).difference(Set(ZZ))
1828
+ True
1829
+ """
1830
+ if not isinstance(right, Set_generic):
1831
+ return rich_to_bool(op, -1)
1832
+ if not isinstance(right, Set_object_difference):
1833
+ return rich_to_bool(op, -1)
1834
+ if self._X == right._X and self._Y == right._Y:
1835
+ return rich_to_bool(op, 0)
1836
+ return rich_to_bool(op, -1)
1837
+
1838
+ def __iter__(self):
1839
+ """
1840
+ Return iterator through elements of ``self``.
1841
+
1842
+ ``self`` is a formal difference of `X` and `Y` and this function
1843
+ is implemented by iterating through the elements of `X` and for
1844
+ each checking if it is not in `Y`, and if yielding it.
1845
+
1846
+ EXAMPLES::
1847
+
1848
+ sage: X = Set(ZZ).difference(Primes())
1849
+ sage: I = X.__iter__()
1850
+ sage: next(I)
1851
+ 0
1852
+ sage: next(I)
1853
+ 1
1854
+ sage: next(I)
1855
+ -1
1856
+ sage: next(I)
1857
+ -2
1858
+ sage: next(I)
1859
+ -3
1860
+ """
1861
+ for x in self._X:
1862
+ if x not in self._Y:
1863
+ yield x
1864
+
1865
+ def __contains__(self, x):
1866
+ """
1867
+ Return ``True`` if ``self`` contains ``x``.
1868
+
1869
+ Since ``self`` is a formal intersection of `X` and `Y` this function
1870
+ returns ``True`` if both `X` and `Y` contains ``x``.
1871
+
1872
+ EXAMPLES::
1873
+
1874
+ sage: X = Set(QQ).difference(Set(ZZ))
1875
+ sage: 5 in X
1876
+ False
1877
+ sage: ComplexField().0 in X # needs sage.rings.real_mpfr
1878
+ False
1879
+ sage: sqrt(2) in X # since sqrt(2) is not a numerical approx # needs sage.symbolic
1880
+ False
1881
+ sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is a numerical approx # needs sage.rings.real_interval_field
1882
+ True
1883
+ sage: 5/2 in X
1884
+ True
1885
+ """
1886
+ return x in self._X and x not in self._Y
1887
+
1888
+ @cached_method
1889
+ def _sympy_(self):
1890
+ """
1891
+ Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``.
1892
+
1893
+ EXAMPLES::
1894
+
1895
+ sage: X = Set(QQ).difference(Set(ZZ)); X
1896
+ Set-theoretic difference of
1897
+ Set of elements of Rational Field and
1898
+ Set of elements of Integer Ring
1899
+ sage: X.category()
1900
+ Category of sets
1901
+ sage: X._sympy_() # needs sympy
1902
+ Complement(Rationals, Integers)
1903
+
1904
+ sage: X = Set(ZZ).difference(Set(QQ)); X
1905
+ Set-theoretic difference of
1906
+ Set of elements of Integer Ring and
1907
+ Set of elements of Rational Field
1908
+ sage: X.category()
1909
+ Category of enumerated sets
1910
+ sage: X._sympy_() # needs sympy
1911
+ EmptySet
1912
+ """
1913
+ from sympy import Complement
1914
+ from sage.interfaces.sympy import sympy_init
1915
+ sympy_init()
1916
+ return Complement(self._X._sympy_(), self._Y._sympy_())
1917
+
1918
+
1919
+ class Set_object_symmetric_difference(Set_object_binary):
1920
+ """
1921
+ Formal symmetric difference of two sets.
1922
+ """
1923
+ def __init__(self, X, Y, category=None):
1924
+ r"""
1925
+ Initialize ``self``.
1926
+
1927
+ EXAMPLES::
1928
+
1929
+ sage: S = Set(QQ)
1930
+ sage: T = Set(ZZ)
1931
+ sage: X = S.symmetric_difference(T); X
1932
+ Set-theoretic symmetric difference of Set of elements of Rational Field and Set of elements of Integer Ring
1933
+ sage: X.category()
1934
+ Category of sets
1935
+ sage: latex(X)
1936
+ \Bold{Q} \bigtriangleup \Bold{Z}
1937
+
1938
+ sage: TestSuite(X).run()
1939
+ """
1940
+ if category is None:
1941
+ category = Sets()
1942
+ if all(S in Sets().Finite() for S in (X, Y)):
1943
+ category = category.Finite()
1944
+ if all(S in Sets().Enumerated() for S in (X, Y)):
1945
+ category = category.Enumerated()
1946
+ Set_object_binary.__init__(self, X, Y, "symmetric difference", "\\bigtriangleup", category=category)
1947
+
1948
+ def is_finite(self):
1949
+ r"""
1950
+ Return whether this set is finite.
1951
+
1952
+ EXAMPLES::
1953
+
1954
+ sage: X = Set(range(10))
1955
+ sage: Y = Set(range(-10,5))
1956
+ sage: Z = Set(QQ)
1957
+ sage: X.symmetric_difference(Y).is_finite()
1958
+ True
1959
+ sage: X.symmetric_difference(Z).is_finite()
1960
+ False
1961
+ sage: Z.symmetric_difference(X).is_finite()
1962
+ False
1963
+ sage: Z.symmetric_difference(Set(ZZ)).is_finite()
1964
+ Traceback (most recent call last):
1965
+ ...
1966
+ NotImplementedError
1967
+ """
1968
+ if self._X.is_finite():
1969
+ return self._Y.is_finite()
1970
+ elif self._Y.is_finite():
1971
+ return False
1972
+ raise NotImplementedError
1973
+
1974
+ def __richcmp__(self, right, op):
1975
+ r"""
1976
+ Try to compare ``self`` and ``right``.
1977
+
1978
+ .. NOTE::
1979
+
1980
+ Comparison is basically not implemented, or rather it could
1981
+ say sets are not equal even though they are. I don't know
1982
+ how one could implement this for a generic symmetric
1983
+ difference of sets in a meaningful manner. So be careful
1984
+ when using this.
1985
+
1986
+ EXAMPLES::
1987
+
1988
+ sage: Y = Set(ZZ).symmetric_difference(Set(QQ))
1989
+ sage: X = Set(QQ).symmetric_difference(Set(ZZ))
1990
+ sage: X == Y
1991
+ True
1992
+ sage: Y == X
1993
+ True
1994
+ """
1995
+ if not isinstance(right, Set_generic):
1996
+ return rich_to_bool(op, -1)
1997
+ if not isinstance(right, Set_object_symmetric_difference):
1998
+ return rich_to_bool(op, -1)
1999
+ if self._X == right._X and self._Y == right._Y or \
2000
+ self._X == right._Y and self._Y == right._X:
2001
+ return rich_to_bool(op, 0)
2002
+ return rich_to_bool(op, -1)
2003
+
2004
+ def __iter__(self):
2005
+ """
2006
+ Return iterator through elements of ``self``.
2007
+
2008
+ This function is implemented by first iterating through the elements
2009
+ of `X` and yielding it if it is not in `Y`.
2010
+ Then it will iterate throw all the elements of `Y` and yielding it if
2011
+ it is not in `X`.
2012
+
2013
+ EXAMPLES::
2014
+
2015
+ sage: X = Set(ZZ).symmetric_difference(Primes())
2016
+ sage: I = X.__iter__()
2017
+ sage: next(I)
2018
+ 0
2019
+ sage: next(I)
2020
+ 1
2021
+ sage: next(I)
2022
+ -1
2023
+ sage: next(I)
2024
+ -2
2025
+ sage: next(I)
2026
+ -3
2027
+ """
2028
+ for x in self._X:
2029
+ if x not in self._Y:
2030
+ yield x
2031
+
2032
+ for y in self._Y:
2033
+ if y not in self._X:
2034
+ yield y
2035
+
2036
+ def __contains__(self, x):
2037
+ """
2038
+ Return ``True`` if ``self`` contains ``x``.
2039
+
2040
+ Since ``self`` is the formal symmetric difference of `X` and `Y`
2041
+ this function returns ``True`` if either `X` or `Y` (but not both)
2042
+ contains ``x``.
2043
+
2044
+ EXAMPLES::
2045
+
2046
+ sage: X = Set(QQ).symmetric_difference(Primes())
2047
+ sage: 4 in X
2048
+ True
2049
+ sage: ComplexField().0 in X # needs sage.rings.real_mpfr
2050
+ False
2051
+ sage: sqrt(2) in X # since sqrt(2) is currently symbolic # needs sage.symbolic
2052
+ False
2053
+ sage: sqrt(RR(2)) in X # since sqrt(RR(2)) is currently approximated # needs sage.rings.real_interval_field
2054
+ True
2055
+ sage: pi in X # needs sage.symbolic
2056
+ False
2057
+ sage: 5/2 in X
2058
+ True
2059
+ sage: 3 in X
2060
+ False
2061
+ """
2062
+ return ((x in self._X and x not in self._Y)
2063
+ or (x in self._Y and x not in self._X))
2064
+
2065
+ @cached_method
2066
+ def _sympy_(self):
2067
+ """
2068
+ Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``.
2069
+
2070
+ EXAMPLES::
2071
+
2072
+ sage: X = Set(ZZ).symmetric_difference(Set(srange(0, 3, 1/3))); X
2073
+ Set-theoretic symmetric difference of
2074
+ Set of elements of Integer Ring and
2075
+ {0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3}
2076
+ sage: X._sympy_() # needs sympy
2077
+ Union(Complement(Integers, Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3)),
2078
+ Complement(Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3), Integers))
2079
+ """
2080
+ from sympy import SymmetricDifference
2081
+ from sage.interfaces.sympy import sympy_init
2082
+ sympy_init()
2083
+ return SymmetricDifference(self._X._sympy_(), self._Y._sympy_())