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
@@ -0,0 +1,2385 @@
1
+ # sage_setup: distribution = sagemath-categories
2
+ r"""
3
+ Bitsets
4
+
5
+ A Python interface to the fast bitsets in Sage. Bitsets are fast
6
+ binary sets that store elements by toggling bits in an array of
7
+ numbers. A bitset can store values between `0` and ``capacity - 1``,
8
+ inclusive (where ``capacity`` is finite, but arbitrary). The storage cost is
9
+ linear in ``capacity``.
10
+
11
+ .. warning::
12
+
13
+ This class is most likely to be useful as a way to store Cython
14
+ bitsets in Python data structures, acting on them using the Cython
15
+ inline functions. If you want to use these classes for a Python
16
+ set type, the Python ``set`` or ``frozenset`` data types may be
17
+ faster.
18
+ """
19
+
20
+ # ****************************************************************************
21
+ # Copyright (C) 2009 Jason Grout <jason-sage@creativetrax.com>
22
+ #
23
+ # Distributed under the terms of the GNU General Public License (GPL)
24
+ #
25
+ # This code is distributed in the hope that it will be useful,
26
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ # General Public License for more details.
29
+ #
30
+ # The full text of the GPL is available at:
31
+ #
32
+ # https://www.gnu.org/licenses/
33
+ # ****************************************************************************
34
+
35
+ from sage.data_structures.bitset_base cimport *
36
+ from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
37
+
38
+
39
+ cdef class FrozenBitset:
40
+ r"""
41
+ A frozen bitset class which leverages inline Cython functions for
42
+ creating and manipulating bitsets.
43
+
44
+ A bitset can be thought of in two ways. First, as a set of elements
45
+ from the universe of the `n` natural numbers `0, 1, \dots, n-1` (where
46
+ the capacity `n` can be specified), with typical set operations such as
47
+ intersection, union, symmetric difference, etc. Secondly, a bitset can
48
+ be thought of as a binary vector with typical binary operations such as
49
+ ``and``, ``or``, ``xor``, etc. This class supports both interfaces.
50
+
51
+ The interface in this class mirrors the interface in the ``frozenset``
52
+ data type of Python. See the Python documentation on `set types
53
+ <https://docs.python.org/library/stdtypes.html#set-types-set-frozenset>`_
54
+ for more details on Python's ``set`` and ``frozenset`` classes.
55
+
56
+ .. warning::
57
+
58
+ This class is most likely to be useful as a way to store
59
+ Cython bitsets in Python data structures, acting on them using
60
+ the Cython inline functions. If you want to use this class
61
+ for a Python set type, the Python ``frozenset`` data type may
62
+ be faster.
63
+
64
+ INPUT:
65
+
66
+ - ``iter`` -- initialization parameter (default: ``None``); valid inputs
67
+ are:
68
+
69
+ - :class:`Bitset` and :class:`FrozenBitset` -- If this is a
70
+ :class:`Bitset` or :class:`FrozenBitset`, then it is copied
71
+
72
+ - ``None`` -- if ``None``, then the bitset is set to the empty set
73
+
74
+ - ``string`` -- if a nonempty string, then the bitset is initialized by
75
+ including an element if the index of the string is ``1``. If the
76
+ string is empty, then raise a :exc:`ValueError`.
77
+
78
+ - ``iterable`` -- if an iterable, then it is assumed to contain a list of
79
+ nonnegative integers and those integers are placed in the set
80
+
81
+ - ``capacity`` -- (default: ``None``) the maximum capacity of the bitset.
82
+ If this is not specified, then it is automatically calculated from the
83
+ passed iterable. It must be at least one.
84
+
85
+ OUTPUT: none
86
+
87
+ The string representation of a :class:`FrozenBitset` ``FB`` can be
88
+ understood as follows. Let `B = b_0 b_1 b_2 \cdots b_k` be the string
89
+ representation of the bitset ``FB``, where each `b_i \in \{0, 1\}`. We
90
+ read the `b_i` from left to right. If `b_i = 1`, then the nonnegative
91
+ integer `i` is in the bitset ``FB``. Similarly, if `b_i = 0`, then `i`
92
+ is not in ``FB``. In other words, ``FB`` is a subset of
93
+ `\{0, 1, 2, \dots, k\}` and the membership in ``FB`` of each `i` is
94
+ determined by the binary value `b_i`.
95
+
96
+ .. SEEALSO::
97
+
98
+ - :class:`Bitset`
99
+
100
+ - Python's `set types <https://docs.python.org/library/stdtypes.html#set-types-set-frozenset>`_
101
+
102
+ EXAMPLES:
103
+
104
+ The default bitset, which has capacity 1::
105
+
106
+ sage: FrozenBitset()
107
+ 0
108
+ sage: FrozenBitset(None)
109
+ 0
110
+
111
+ Trying to create an empty bitset fails::
112
+
113
+ sage: FrozenBitset([])
114
+ Traceback (most recent call last):
115
+ ...
116
+ ValueError: Bitsets must not be empty
117
+ sage: FrozenBitset(list())
118
+ Traceback (most recent call last):
119
+ ...
120
+ ValueError: Bitsets must not be empty
121
+ sage: FrozenBitset(())
122
+ Traceback (most recent call last):
123
+ ...
124
+ ValueError: Bitsets must not be empty
125
+ sage: FrozenBitset(tuple())
126
+ Traceback (most recent call last):
127
+ ...
128
+ ValueError: Bitsets must not be empty
129
+ sage: FrozenBitset("")
130
+ Traceback (most recent call last):
131
+ ...
132
+ ValueError: Bitsets must not be empty
133
+
134
+ We can create the all-zero bitset as follows::
135
+
136
+ sage: FrozenBitset(capacity=10)
137
+ 0000000000
138
+ sage: FrozenBitset([], capacity=10)
139
+ 0000000000
140
+
141
+ We can initialize a :class:`FrozenBitset` with a :class:`Bitset` or
142
+ another :class:`FrozenBitset`, and compare them for equality. As they
143
+ are logically the same bitset, the equality test should return ``True``.
144
+ Furthermore, each bitset is a subset of the other. ::
145
+
146
+ sage: def bitcmp(a, b, c): # custom function for comparing bitsets
147
+ ....: print(a == b == c)
148
+ ....: print((a <= b, b <= c, a <= c))
149
+ ....: print((a >= b, b >= c, a >= c))
150
+ ....: print((a != b, b != c, a != c))
151
+ sage: a = Bitset("1010110"); b = FrozenBitset(a); c = FrozenBitset(b)
152
+ sage: a; b; c
153
+ 1010110
154
+ 1010110
155
+ 1010110
156
+ sage: a < b, b < c, a < c
157
+ (False, False, False)
158
+ sage: a > b, b > c, a > c
159
+ (False, False, False)
160
+ sage: bitcmp(a, b, c)
161
+ True
162
+ (True, True, True)
163
+ (True, True, True)
164
+ (False, False, False)
165
+
166
+ Try a random bitset::
167
+
168
+ sage: a = Bitset(randint(0, 1) for n in range(randint(1, 10^4)))
169
+ sage: b = FrozenBitset(a); c = FrozenBitset(b)
170
+ sage: bitcmp(a, b, c)
171
+ True
172
+ (True, True, True)
173
+ (True, True, True)
174
+ (False, False, False)
175
+
176
+ A bitset with a hard-coded bitstring::
177
+
178
+ sage: FrozenBitset('101')
179
+ 101
180
+
181
+ For a string, only those positions with ``1`` would be initialized to ``1``
182
+ in the corresponding position in the bitset. All other characters in the
183
+ string, including ``0``, are set to ``0`` in the resulting bitset. ::
184
+
185
+ sage: FrozenBitset('a')
186
+ 0
187
+ sage: FrozenBitset('abc')
188
+ 000
189
+ sage: FrozenBitset('abc1')
190
+ 0001
191
+ sage: FrozenBitset('0abc1')
192
+ 00001
193
+ sage: FrozenBitset('0abc10')
194
+ 000010
195
+ sage: FrozenBitset('0a*c10')
196
+ 000010
197
+
198
+ Represent the first 10 primes as a bitset. The primes are stored as a
199
+ list and as a tuple. We then recover the primes from its bitset
200
+ representation, and query the bitset for its length (how many elements
201
+ it contains) and whether an element is in the bitset. Note that the
202
+ length of a bitset is different from its capacity. The length counts
203
+ the number of elements currently in the bitset, while the capacity
204
+ is the number of elements that the bitset can hold. ::
205
+
206
+ sage: p = primes_first_n(10); p # needs sage.libs.pari
207
+ [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
208
+ sage: tuple(p) # needs sage.libs.pari
209
+ (2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
210
+ sage: F = FrozenBitset(p); F; FrozenBitset(tuple(p)) # needs sage.libs.pari
211
+ 001101010001010001010001000001
212
+ 001101010001010001010001000001
213
+
214
+ Recover the primes from the bitset::
215
+
216
+ sage: for b in F: # needs sage.libs.pari
217
+ ....: print(b)
218
+ 2
219
+ 3
220
+ ...
221
+ 29
222
+ sage: list(F) # needs sage.libs.pari
223
+ [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
224
+
225
+ Query the bitset::
226
+
227
+ sage: # needs sage.libs.pari
228
+ sage: len(F)
229
+ 10
230
+ sage: len(list(F))
231
+ 10
232
+ sage: F.capacity()
233
+ 30
234
+ sage: s = str(F); len(s)
235
+ 30
236
+ sage: 2 in F
237
+ True
238
+ sage: 1 in F
239
+ False
240
+
241
+ A random iterable, with all duplicate elements removed::
242
+
243
+ sage: L = [randint(0, 100) for n in range(randint(1, 10^4))]
244
+ sage: FrozenBitset(L) == FrozenBitset(list(set(L)))
245
+ True
246
+ sage: FrozenBitset(tuple(L)) == FrozenBitset(tuple(set(L)))
247
+ True
248
+
249
+ TESTS:
250
+
251
+ Loading and dumping objects::
252
+
253
+ sage: a = FrozenBitset('1101')
254
+ sage: loads(dumps(a)) == a
255
+ True
256
+ sage: a = FrozenBitset('1101' * 64)
257
+ sage: loads(dumps(a)) == a
258
+ True
259
+
260
+ If ``iter`` is a nonempty string and ``capacity`` is specified, then
261
+ ``capacity`` must match the number of elements in ``iter``::
262
+
263
+ sage: FrozenBitset("110110", capacity=3)
264
+ Traceback (most recent call last):
265
+ ...
266
+ ValueError: bitset capacity does not match passed string
267
+ sage: FrozenBitset("110110", capacity=100)
268
+ Traceback (most recent call last):
269
+ ...
270
+ ValueError: bitset capacity does not match passed string
271
+
272
+ The parameter ``capacity`` must be positive::
273
+
274
+ sage: FrozenBitset("110110", capacity=0)
275
+ Traceback (most recent call last):
276
+ ...
277
+ ValueError: bitset capacity must be greater than 0
278
+ sage: FrozenBitset("110110", capacity=-2)
279
+ Traceback (most recent call last):
280
+ ...
281
+ OverflowError: can...t convert negative value to mp_bitcnt_t
282
+ """
283
+ def __cinit__(self, iter=None, capacity=None):
284
+ """
285
+ Allocate the bitset, which is initially empty.
286
+
287
+ See the class documentation of :class:`FrozenBitset` for details
288
+ on the parameters.
289
+
290
+ EXAMPLES::
291
+
292
+ sage: FrozenBitset('1101')
293
+ 1101
294
+ sage: FrozenBitset('1101' * 32)
295
+ 11011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101
296
+ """
297
+ if capacity is None:
298
+ bitset_init(self._bitset, 1)
299
+ else:
300
+ bitset_init(self._bitset, <mp_bitcnt_t> capacity)
301
+
302
+ def __dealloc__(self):
303
+ """
304
+ Deallocate the C bitset data structure.
305
+
306
+ EXAMPLES::
307
+
308
+ sage: a = FrozenBitset('11010')
309
+ sage: del a
310
+ sage: b = FrozenBitset('11010' * 64)
311
+ sage: del b
312
+ """
313
+ bitset_free(self._bitset)
314
+
315
+ def __init__(self, iter=None, capacity=None):
316
+ """
317
+ Initialize a bitset.
318
+
319
+ See the class documentation of ``FrozenBitset`` for details on the
320
+ parameters.
321
+
322
+ EXAMPLES::
323
+
324
+ sage: FrozenBitset(capacity=3)
325
+ 000
326
+ sage: FrozenBitset('11011')
327
+ 11011
328
+ sage: FrozenBitset('110' * 32)
329
+ 110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110
330
+ sage: FrozenBitset([0,3,2])
331
+ 1011
332
+ sage: FrozenBitset(set([0,3,2]))
333
+ 1011
334
+ sage: FrozenBitset(FrozenBitset('11011'))
335
+ 11011
336
+ sage: FrozenBitset([0,3,2], capacity=10)
337
+ 1011000000
338
+ sage: FrozenBitset([i for i in range(100) if i % 2 == 0])
339
+ 101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
340
+
341
+ TESTS:
342
+
343
+ The capacity must be at least one::
344
+
345
+ sage: FrozenBitset()
346
+ 0
347
+
348
+ If capacity is specified, it must match up with the
349
+ initialization items::
350
+
351
+ sage: FrozenBitset('10', capacity=3)
352
+ Traceback (most recent call last):
353
+ ...
354
+ ValueError: bitset capacity does not match passed string
355
+ sage: FrozenBitset([0,3,2], capacity=2)
356
+ Traceback (most recent call last):
357
+ ...
358
+ ValueError: bitset capacity does not allow storing the passed iterable
359
+ sage: FrozenBitset(FrozenBitset('1101'), capacity=2)
360
+ Traceback (most recent call last):
361
+ ...
362
+ ValueError: bitset capacity does not match passed bitset
363
+ sage: FrozenBitset(FrozenBitset('1101'), capacity=5)
364
+ Traceback (most recent call last):
365
+ ...
366
+ ValueError: bitset capacity does not match passed bitset
367
+ """
368
+ cdef unsigned long n
369
+ cdef FrozenBitset b
370
+ if iter is not None and not isinstance(iter, (str, tuple, list, FrozenBitset, Bitset)):
371
+ iter = list(iter)
372
+
373
+ if iter is None:
374
+ pass # Leave bitset empty
375
+ elif isinstance(iter, (FrozenBitset, Bitset)):
376
+ b = iter
377
+ if capacity is None:
378
+ bitset_realloc(self._bitset, b._bitset.size)
379
+ elif self._bitset.size != b._bitset.size:
380
+ raise ValueError("bitset capacity does not match passed bitset")
381
+ bitset_copy(self._bitset, b._bitset)
382
+ elif isinstance(iter, str):
383
+ if len(iter) == 0:
384
+ raise ValueError("Bitsets must not be empty")
385
+ if capacity is None:
386
+ bitset_realloc(self._bitset, len(iter))
387
+ elif self._bitset.size != <mp_bitcnt_t>len(iter):
388
+ raise ValueError("bitset capacity does not match passed string")
389
+ bitset_from_str(self._bitset, iter)
390
+ else: # an iterable
391
+ iter = list(iter)
392
+ if iter:
393
+ need_capacity = max(iter) + 1
394
+ else:
395
+ need_capacity = 0
396
+ if capacity is None:
397
+ if need_capacity == 0:
398
+ raise ValueError("Bitsets must not be empty")
399
+ bitset_realloc(self._bitset, need_capacity)
400
+ elif self._bitset.size < need_capacity:
401
+ raise ValueError("bitset capacity does not allow storing the passed iterable")
402
+ bitset_clear(self._bitset)
403
+ for n in iter:
404
+ bitset_add(self._bitset, n)
405
+
406
+ cdef FrozenBitset _new(self, long int capacity):
407
+ r"""
408
+ Return an object of the same type as ``self``, initialized with a
409
+ bitset of capacity ``capacity``.
410
+ """
411
+ cdef FrozenBitset b
412
+ b = FrozenBitset.__new__(FrozenBitset, None, capacity)
413
+ return b
414
+
415
+ def __getstate__(self):
416
+ """
417
+ Return the current state of the object as a bytes string.
418
+
419
+ EXAMPLES::
420
+
421
+ sage: FrozenBitset('1101').__getstate__() == b'1101'
422
+ True
423
+ sage: FrozenBitset('110'*32).__getstate__() == (b'110' * 32)
424
+ True
425
+ """
426
+ return bytes(self)
427
+
428
+ def __setstate__(self, state):
429
+ """
430
+ Set the state of the object from the string state.
431
+
432
+ EXAMPLES::
433
+
434
+ sage: a = FrozenBitset()
435
+ sage: a.__setstate__(b'1101')
436
+ sage: a
437
+ 1101
438
+ sage: a.__setstate__(b'110'*32)
439
+ sage: a
440
+ 110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110
441
+ """
442
+ bitset_realloc(self._bitset, len(state))
443
+ bitset_from_char(self._bitset, state)
444
+
445
+ def __iter__(self):
446
+ """
447
+ Return an iterator over ``self``.
448
+
449
+ EXAMPLES::
450
+
451
+ sage: list(FrozenBitset('11011'))
452
+ [0, 1, 3, 4]
453
+ sage: list(FrozenBitset('00001' * 20))
454
+ [4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99]
455
+ sage: set(FrozenBitset('11011'))
456
+ {0, 1, 3, 4}
457
+ """
458
+ return iter(bitset_list(self._bitset))
459
+
460
+ def __reversed__(self):
461
+ """
462
+ Return an iterator over ``self``, starting with the largest element.
463
+
464
+ EXAMPLES::
465
+
466
+ sage: list(reversed(FrozenBitset('11011')))
467
+ [4, 3, 1, 0]
468
+ sage: list(reversed(FrozenBitset('00001' * 20)))
469
+ [99, 94, 89, 84, 79, 74, 69, 64, 59, 54, 49, 44, 39, 34, 29, 24, 19, 14, 9, 4]
470
+ """
471
+ return reversed(bitset_list(self._bitset))
472
+
473
+ cpdef FrozenBitset _larger_capacity_(self, long capacity):
474
+ """
475
+ Return a copy of ``self`` where the bitset has the maximum of the
476
+ current capacity and the capacity passed. If no resizing is needed,
477
+ return ``self``.
478
+
479
+ This function is mainly used to satisfy the assumption of the
480
+ underlying bitset functions that all bitsets are of the same
481
+ capacity.
482
+
483
+ INPUT:
484
+
485
+ - ``capacity`` -- the underlying bitset of the returned bitset
486
+ will have this capacity if it is bigger than the current
487
+ capacity.
488
+
489
+ EXAMPLES::
490
+
491
+ sage: a = FrozenBitset('11010')
492
+ sage: a.capacity()
493
+ 5
494
+ sage: a._larger_capacity_(4) is a
495
+ True
496
+ sage: a._larger_capacity_(5) is a
497
+ True
498
+ sage: b = a._larger_capacity_(6)
499
+ sage: b
500
+ 110100
501
+ sage: b is a
502
+ False
503
+ sage: b.capacity()
504
+ 6
505
+ sage: c = a._larger_capacity_(98)
506
+ sage: c
507
+ 11010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
508
+ sage: c.capacity()
509
+ 98
510
+ """
511
+ cdef FrozenBitset temp
512
+ if self._bitset.size >= <mp_bitcnt_t>capacity:
513
+ return self
514
+ else:
515
+ temp = self._new(self._bitset.size)
516
+ bitset_copy(temp._bitset, self._bitset)
517
+ bitset_realloc(temp._bitset, capacity)
518
+ return temp
519
+
520
+ cpdef long capacity(self) noexcept:
521
+ """
522
+ Return the size of the underlying bitset.
523
+
524
+ The maximum value that can be stored in the current underlying
525
+ bitset is ``self.capacity() - 1``.
526
+
527
+ EXAMPLES::
528
+
529
+ sage: FrozenBitset('11000').capacity()
530
+ 5
531
+ sage: FrozenBitset('110' * 32).capacity()
532
+ 96
533
+ sage: FrozenBitset(range(20), capacity=450).capacity()
534
+ 450
535
+ """
536
+ return self._bitset.size
537
+
538
+ def __hash__(self):
539
+ """
540
+ Return a hash value for a bitset.
541
+
542
+ EXAMPLES::
543
+
544
+ sage: hash(FrozenBitset(capacity=5))
545
+ 0
546
+ sage: hash(FrozenBitset('10110'))
547
+ 13
548
+ sage: hash(FrozenBitset('10110' + '0' * 120, capacity=125))
549
+ 13
550
+ """
551
+ cdef long hash
552
+ hash = bitset_hash(self._bitset)
553
+ if hash == -1:
554
+ return 0
555
+ else:
556
+ return hash
557
+
558
+ cpdef bint isempty(self) noexcept:
559
+ """
560
+ Test if the bitset is empty.
561
+
562
+ OUTPUT: boolean
563
+
564
+ EXAMPLES::
565
+
566
+ sage: FrozenBitset().isempty()
567
+ True
568
+ sage: FrozenBitset([1]).isempty()
569
+ False
570
+ sage: FrozenBitset([], capacity=110).isempty()
571
+ True
572
+ sage: FrozenBitset(range(99)).isempty()
573
+ False
574
+ """
575
+ return bitset_isempty(self._bitset)
576
+
577
+ def __richcmp__(FrozenBitset self, FrozenBitset other not None, int op):
578
+ """
579
+ Implement comparisons, using the Cython richcmp convention.
580
+ Comparison is done by inclusion. That is, a set ``A`` is less than
581
+ another set ``B``, written ``A < B``, if ``A`` is a subset of ``B``.
582
+
583
+ EXAMPLES::
584
+
585
+ sage: FrozenBitset('11') < FrozenBitset('101')
586
+ False
587
+ sage: FrozenBitset('11') <= FrozenBitset('110')
588
+ True
589
+ sage: FrozenBitset('11') != FrozenBitset('10')
590
+ True
591
+ sage: FrozenBitset('11') == FrozenBitset('10')
592
+ False
593
+ sage: FrozenBitset('11') == FrozenBitset('110')
594
+ True
595
+ sage: FrozenBitset('11') > FrozenBitset('10')
596
+ True
597
+ sage: FrozenBitset('11') >= FrozenBitset('10')
598
+ True
599
+ sage: FrozenBitset('11') < FrozenBitset('110' * 32)
600
+ True
601
+
602
+ TESTS:
603
+
604
+ When performing comparison, ``other`` cannot be ``None``. ::
605
+
606
+ sage: F = FrozenBitset('11')
607
+ sage: F < None
608
+ Traceback (most recent call last):
609
+ ...
610
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
611
+ sage: F <= None
612
+ Traceback (most recent call last):
613
+ ...
614
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
615
+ sage: F > None
616
+ Traceback (most recent call last):
617
+ ...
618
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
619
+ sage: F >= None
620
+ Traceback (most recent call last):
621
+ ...
622
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
623
+ sage: F == None
624
+ Traceback (most recent call last):
625
+ ...
626
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
627
+ sage: F != None
628
+ Traceback (most recent call last):
629
+ ...
630
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
631
+ sage: None < F
632
+ Traceback (most recent call last):
633
+ ...
634
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
635
+ sage: None <= F
636
+ Traceback (most recent call last):
637
+ ...
638
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
639
+ sage: None > F
640
+ Traceback (most recent call last):
641
+ ...
642
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
643
+ sage: None >= F
644
+ Traceback (most recent call last):
645
+ ...
646
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
647
+ sage: None == F
648
+ Traceback (most recent call last):
649
+ ...
650
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
651
+ sage: None != F
652
+ Traceback (most recent call last):
653
+ ...
654
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
655
+ """
656
+ cdef FrozenBitset left, right
657
+
658
+ if self._bitset.size == other._bitset.size:
659
+ left = self
660
+ right = other
661
+ elif self._bitset.size < other._bitset.size:
662
+ left = self._larger_capacity_(other._bitset.size)
663
+ right = other
664
+ else:
665
+ left = self
666
+ right = other._larger_capacity_(self._bitset.size)
667
+
668
+ if op == Py_EQ:
669
+ return bitset_eq(left._bitset, right._bitset)
670
+ elif op == Py_NE:
671
+ return not bitset_eq(left._bitset, right._bitset)
672
+ elif op == Py_LT:
673
+ return bitset_issubset(left._bitset, right._bitset) and not bitset_eq(left._bitset, right._bitset)
674
+ elif op == Py_LE:
675
+ return bitset_issubset(left._bitset, right._bitset)
676
+ elif op == Py_GT:
677
+ return bitset_issuperset(left._bitset, right._bitset) and not bitset_eq(left._bitset, right._bitset)
678
+ elif op == Py_GE:
679
+ return bitset_issuperset(left._bitset, right._bitset)
680
+
681
+ cpdef bint issubset(self, FrozenBitset other) except -1:
682
+ """
683
+ Test to see if ``self`` is a subset of ``other``.
684
+
685
+ EXAMPLES::
686
+
687
+ sage: FrozenBitset('11').issubset(FrozenBitset('01'))
688
+ False
689
+ sage: FrozenBitset('01').issubset(FrozenBitset('11'))
690
+ True
691
+ sage: FrozenBitset('01').issubset(FrozenBitset('01' * 45))
692
+ True
693
+
694
+ TESTS::
695
+
696
+ sage: FrozenBitset('11').issubset(None)
697
+ Traceback (most recent call last):
698
+ ...
699
+ ValueError: other cannot be None
700
+ """
701
+ if other is None:
702
+ raise ValueError("other cannot be None")
703
+ cdef FrozenBitset left, right
704
+ if self._bitset.size <= other._bitset.size:
705
+ left = self
706
+ right = other
707
+ else:
708
+ left = self
709
+ right = other._larger_capacity_(self._bitset.size)
710
+
711
+ # Assumes ``left.size <= right.size``.
712
+ return bitset_issubset(left._bitset, right._bitset)
713
+
714
+ cpdef bint issuperset(self, FrozenBitset other) except -1:
715
+ """
716
+ Test to see if ``self`` is a superset of ``other``.
717
+
718
+ EXAMPLES::
719
+
720
+ sage: FrozenBitset('11').issuperset(FrozenBitset('01'))
721
+ True
722
+ sage: FrozenBitset('01').issuperset(FrozenBitset('11'))
723
+ False
724
+ sage: FrozenBitset('01').issuperset(FrozenBitset('10' * 45))
725
+ False
726
+
727
+ TESTS::
728
+
729
+ sage: FrozenBitset('11').issuperset(None)
730
+ Traceback (most recent call last):
731
+ ...
732
+ ValueError: other cannot be None
733
+ """
734
+ if other is None:
735
+ raise ValueError("other cannot be None")
736
+ cdef FrozenBitset left, right
737
+ if self._bitset.size >= other._bitset.size:
738
+ left = self
739
+ right = other
740
+ else:
741
+ left = self._larger_capacity_(other._bitset.size)
742
+ right = other
743
+
744
+ # Assumes ``left.size >= right.size``.
745
+ return bitset_issuperset(left._bitset, right._bitset)
746
+
747
+ cpdef bint isdisjoint(self, FrozenBitset other) except -1:
748
+ """
749
+ Test to see if ``self`` is disjoint from ``other``.
750
+
751
+ EXAMPLES::
752
+
753
+ sage: FrozenBitset('11').isdisjoint(FrozenBitset('01'))
754
+ False
755
+ sage: FrozenBitset('01').isdisjoint(FrozenBitset('001'))
756
+ True
757
+ sage: FrozenBitset('00101').isdisjoint(FrozenBitset('110' * 35))
758
+ False
759
+
760
+ TESTS::
761
+
762
+ sage: FrozenBitset('11').isdisjoint(None)
763
+ Traceback (most recent call last):
764
+ ...
765
+ ValueError: other cannot be None
766
+ """
767
+ if other is None:
768
+ raise ValueError("other cannot be None")
769
+ cdef FrozenBitset left, right
770
+
771
+ if self._bitset.size <= other._bitset.size:
772
+ left = self
773
+ right = other
774
+ else:
775
+ left = other
776
+ right = self
777
+
778
+ # Assumes ``left.size <= right.size``.
779
+ return bitset_are_disjoint(left._bitset, right._bitset)
780
+
781
+ def __contains__(self, unsigned long n) -> bool:
782
+ """
783
+ Test to see if ``n`` is in ``self``.
784
+
785
+ EXAMPLES::
786
+
787
+ sage: 0 in FrozenBitset([0,1])
788
+ True
789
+ sage: 0 in FrozenBitset([1,2])
790
+ False
791
+ sage: 10 in FrozenBitset([0,1])
792
+ False
793
+ sage: 121 in FrozenBitset('110' * 50)
794
+ True
795
+ sage: 122 in FrozenBitset('110' * 50)
796
+ False
797
+
798
+ TESTS::
799
+
800
+ sage: None in FrozenBitset([0,1])
801
+ Traceback (most recent call last):
802
+ ...
803
+ TypeError: an integer is required
804
+ """
805
+ if n < self._bitset.size:
806
+ return bitset_in(self._bitset, n)
807
+ else:
808
+ return False
809
+
810
+ def __len__(self):
811
+ """
812
+ Return the number of elements in the bitset (which may be
813
+ different from the capacity of the bitset).
814
+
815
+ EXAMPLES::
816
+
817
+ sage: len(FrozenBitset([0,1], capacity=10))
818
+ 2
819
+ sage: len(FrozenBitset(range(98)))
820
+ 98
821
+ """
822
+ return bitset_len(self._bitset)
823
+
824
+ def __str__(self) -> str:
825
+ """
826
+ Return a string representing the bitset as a binary vector.
827
+
828
+ EXAMPLES::
829
+
830
+ sage: a = FrozenBitset('10110')
831
+ sage: str(a)
832
+ '10110'
833
+ sage: str(FrozenBitset('110' * 32))
834
+ '110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110'
835
+ """
836
+ return bitset_string(self._bitset)
837
+
838
+ def __bytes__(self):
839
+ """
840
+ Return a bytes object representing the bitset as a binary vector.
841
+
842
+ EXAMPLES::
843
+
844
+ sage: a = FrozenBitset('10110')
845
+ sage: bytes(a) == b'10110'
846
+ True
847
+ sage: bytes(FrozenBitset('110' * 32)) == b'110' * 32
848
+ True
849
+ """
850
+ return bitset_bytes(self._bitset)
851
+
852
+ def __repr__(self):
853
+ """
854
+ Return a string representing the bitset as a binary vector.
855
+
856
+ EXAMPLES::
857
+
858
+ sage: a = FrozenBitset('10110')
859
+ sage: repr(a)
860
+ '10110'
861
+ sage: repr(FrozenBitset('110' * 32))
862
+ '110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110'
863
+ """
864
+ return str(self)
865
+
866
+ cpdef _union(self, FrozenBitset other):
867
+ """
868
+ Return the union of ``self`` and ``other``.
869
+
870
+ In order to get a Cython "union" function, we have to use the
871
+ underscore since "union" is a C keyword.
872
+
873
+ EXAMPLES::
874
+
875
+ sage: FrozenBitset('10101')._union(FrozenBitset('11100'))
876
+ 11101
877
+ sage: FrozenBitset('10101' * 10)._union(FrozenBitset('01010' * 10))
878
+ 11111111111111111111111111111111111111111111111111
879
+
880
+ TESTS::
881
+
882
+ sage: set(FrozenBitset('10101' * 10)._union(FrozenBitset('01010' * 10))) == set(FrozenBitset('10101' * 10)).union(FrozenBitset('01010' * 10))
883
+ True
884
+ sage: set(FrozenBitset('10101')._union(FrozenBitset('01010' * 20))) == set(FrozenBitset('10101')).union(FrozenBitset('01010' * 20))
885
+ True
886
+ sage: set(FrozenBitset('10101' * 20)._union(FrozenBitset('01010'))) == set(FrozenBitset('10101' * 20)).union(FrozenBitset('01010'))
887
+ True
888
+ sage: FrozenBitset('10101' * 10)._union(None)
889
+ Traceback (most recent call last):
890
+ ...
891
+ ValueError: other cannot be None
892
+ """
893
+ if other is None:
894
+ raise ValueError("other cannot be None")
895
+ cdef FrozenBitset temp, smaller, larger
896
+ if self._bitset.size <= other._bitset.size:
897
+ smaller = self
898
+ larger = other
899
+ else:
900
+ smaller = other
901
+ larger = self
902
+
903
+ temp = self._new(smaller._bitset.size)
904
+ bitset_copy(temp._bitset, smaller._bitset)
905
+ bitset_realloc(temp._bitset, larger._bitset.size)
906
+ bitset_union(temp._bitset, temp._bitset, larger._bitset)
907
+ return temp
908
+
909
+ def union(self, FrozenBitset other):
910
+ """
911
+ Return the union of ``self`` and ``other``.
912
+
913
+ EXAMPLES::
914
+
915
+ sage: FrozenBitset('10101').union(FrozenBitset('11100'))
916
+ 11101
917
+ sage: FrozenBitset('10101' * 10).union(FrozenBitset('01010' * 10))
918
+ 11111111111111111111111111111111111111111111111111
919
+
920
+ TESTS::
921
+
922
+ sage: set(FrozenBitset('10101' * 10).union(FrozenBitset('01010' * 10))) == set(FrozenBitset('10101' * 10)).union(FrozenBitset('01010' * 10))
923
+ True
924
+ sage: set(FrozenBitset('10101').union(FrozenBitset('01010' * 20))) == set(FrozenBitset('10101')).union(FrozenBitset('01010' * 20))
925
+ True
926
+ sage: set(FrozenBitset('10101' * 20).union(FrozenBitset('01010'))) == set(FrozenBitset('10101' * 20)).union(FrozenBitset('01010'))
927
+ True
928
+ sage: FrozenBitset('10101' * 10).union(None)
929
+ Traceback (most recent call last):
930
+ ...
931
+ ValueError: other cannot be None
932
+ """
933
+ return self._union(other)
934
+
935
+ def __or__(self, FrozenBitset other not None):
936
+ """
937
+ Return the union of ``self`` and ``other``.
938
+
939
+ EXAMPLES::
940
+
941
+ sage: FrozenBitset('10101') | FrozenBitset('11100')
942
+ 11101
943
+ sage: FrozenBitset('10101' * 10) | FrozenBitset('01010' * 10)
944
+ 11111111111111111111111111111111111111111111111111
945
+
946
+ TESTS::
947
+
948
+ sage: set(FrozenBitset('10101' * 10) | FrozenBitset('01010' * 10)) == set(FrozenBitset('10101' * 10)) | set(FrozenBitset('01010' * 10))
949
+ True
950
+ sage: set(FrozenBitset('10101') | FrozenBitset('01010' * 20)) == set(FrozenBitset('10101')) | set(FrozenBitset('01010' * 20))
951
+ True
952
+ sage: set(FrozenBitset('10101' * 20) | FrozenBitset('01010')) == set(FrozenBitset('10101' * 20)) | set(FrozenBitset('01010'))
953
+ True
954
+ sage: FrozenBitset('10101') | None
955
+ Traceback (most recent call last):
956
+ ...
957
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
958
+ sage: None | FrozenBitset('10101')
959
+ Traceback (most recent call last):
960
+ ...
961
+ AttributeError: 'NoneType' object has no attribute '_union'...
962
+ """
963
+ return self._union(other)
964
+
965
+ cpdef intersection(self, FrozenBitset other):
966
+ """
967
+ Return the intersection of ``self`` and ``other``.
968
+
969
+ EXAMPLES::
970
+
971
+ sage: FrozenBitset('10101').intersection(FrozenBitset('11100'))
972
+ 10100
973
+ sage: FrozenBitset('11111' * 10).intersection(FrozenBitset('010101' * 10))
974
+ 010101010101010101010101010101010101010101010101010000000000
975
+
976
+ TESTS::
977
+
978
+ sage: set(FrozenBitset('11111' * 10).intersection(FrozenBitset('010101' * 10))) == set(FrozenBitset('11111' * 10)).intersection(FrozenBitset('010101' * 10))
979
+ True
980
+ sage: set(FrozenBitset('1' * 5).intersection(FrozenBitset('01010' * 20))) == set(FrozenBitset('1' * 5)).intersection(FrozenBitset('01010' * 20))
981
+ True
982
+ sage: set(FrozenBitset('10101' * 20).intersection(FrozenBitset('1' * 5))) == set(FrozenBitset('10101' * 20)).intersection(FrozenBitset('1' * 5))
983
+ True
984
+ sage: FrozenBitset("101011").intersection(None)
985
+ Traceback (most recent call last):
986
+ ...
987
+ ValueError: other cannot be None
988
+ """
989
+ if other is None:
990
+ raise ValueError("other cannot be None")
991
+ cdef FrozenBitset temp, smaller, larger
992
+ if self._bitset.size <= other._bitset.size:
993
+ smaller = self
994
+ larger = other
995
+ else:
996
+ smaller = other
997
+ larger = self
998
+
999
+ temp = self._new(smaller._bitset.size)
1000
+ bitset_copy(temp._bitset, smaller._bitset)
1001
+ bitset_realloc(temp._bitset, larger._bitset.size)
1002
+ bitset_intersection(temp._bitset, temp._bitset, larger._bitset)
1003
+ return temp
1004
+
1005
+ def __and__(self, FrozenBitset other not None):
1006
+ """
1007
+ Return the intersection of ``self`` and ``other``.
1008
+
1009
+ EXAMPLES::
1010
+
1011
+ sage: FrozenBitset('10101') & FrozenBitset('11100')
1012
+ 10100
1013
+ sage: FrozenBitset('11111' * 10) & FrozenBitset('010101' * 10)
1014
+ 010101010101010101010101010101010101010101010101010000000000
1015
+
1016
+ TESTS::
1017
+
1018
+ sage: set(FrozenBitset('11111' * 10) & FrozenBitset('010101' * 10)) == set(FrozenBitset('11111' * 10)) & set(FrozenBitset('010101' * 10))
1019
+ True
1020
+ sage: set(FrozenBitset('1' * 5) & FrozenBitset('01010' * 20)) == set(FrozenBitset('1' * 5)) & set(FrozenBitset('01010' * 20))
1021
+ True
1022
+ sage: set(FrozenBitset('10101' * 20) & FrozenBitset('1' * 5)) == set(FrozenBitset('10101' * 20)) & set(FrozenBitset('1' * 5))
1023
+ True
1024
+ sage: FrozenBitset("101011") & None
1025
+ Traceback (most recent call last):
1026
+ ...
1027
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1028
+ sage: None & FrozenBitset("101011")
1029
+ Traceback (most recent call last):
1030
+ ...
1031
+ AttributeError: 'NoneType' object has no attribute 'intersection'...
1032
+ """
1033
+ return self.intersection(other)
1034
+
1035
+ cpdef difference(self, FrozenBitset other):
1036
+ """
1037
+ Return the difference of ``self`` and ``other``.
1038
+
1039
+ EXAMPLES::
1040
+
1041
+ sage: FrozenBitset('10101').difference(FrozenBitset('11100'))
1042
+ 00001
1043
+ sage: FrozenBitset('11111' * 10).difference(FrozenBitset('010101' * 10))
1044
+ 101010101010101010101010101010101010101010101010100000000000
1045
+
1046
+ TESTS::
1047
+
1048
+ sage: set(FrozenBitset('11111' * 10).difference(FrozenBitset('010101' * 10))) == set(FrozenBitset('11111' * 10)).difference(FrozenBitset('010101' * 10))
1049
+ True
1050
+ sage: set(FrozenBitset('1' * 5).difference(FrozenBitset('01010' * 20))) == set(FrozenBitset('1' * 5)).difference(FrozenBitset('01010' * 20))
1051
+ True
1052
+ sage: set(FrozenBitset('10101' * 20).difference(FrozenBitset('1' * 5))) == set(FrozenBitset('10101' * 20)).difference(FrozenBitset('1' * 5))
1053
+ True
1054
+ sage: FrozenBitset('10101').difference(None)
1055
+ Traceback (most recent call last):
1056
+ ...
1057
+ ValueError: other cannot be None
1058
+ """
1059
+ if other is None:
1060
+ raise ValueError("other cannot be None")
1061
+ cdef FrozenBitset temp = self._new(self._bitset.size)
1062
+ bitset_copy(temp._bitset, self._bitset)
1063
+
1064
+ if temp._bitset.size == other._bitset.size:
1065
+ bitset_difference(temp._bitset, temp._bitset, other._bitset)
1066
+ elif temp._bitset.size < other._bitset.size:
1067
+ bitset_realloc(temp._bitset, other._bitset.size)
1068
+ bitset_difference(temp._bitset, temp._bitset, other._bitset)
1069
+ else:
1070
+ bitset_difference(temp._bitset, temp._bitset, other._larger_capacity_(temp._bitset.size)._bitset)
1071
+
1072
+ return temp
1073
+
1074
+ def __sub__(self, FrozenBitset other not None):
1075
+ """
1076
+ Return the difference of ``self`` and ``other``.
1077
+
1078
+ EXAMPLES::
1079
+
1080
+ sage: FrozenBitset('10101') - FrozenBitset('11100')
1081
+ 00001
1082
+ sage: FrozenBitset('11111' * 10)-FrozenBitset('010101' * 10)
1083
+ 101010101010101010101010101010101010101010101010100000000000
1084
+
1085
+ TESTS::
1086
+
1087
+ sage: set(FrozenBitset('11111' * 10)-FrozenBitset('010101' * 10)) == set(FrozenBitset('11111' * 10))-set(FrozenBitset('010101' * 10))
1088
+ True
1089
+ sage: set(FrozenBitset('1' * 5)-FrozenBitset('01010' * 20)) == set(FrozenBitset('1' * 5))-set(FrozenBitset('01010' * 20))
1090
+ True
1091
+ sage: set(FrozenBitset('10101' * 20)-FrozenBitset('1' * 5)) == set(FrozenBitset('10101' * 20))-set(FrozenBitset('1' * 5))
1092
+ True
1093
+ sage: FrozenBitset('10101') - None
1094
+ Traceback (most recent call last):
1095
+ ...
1096
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1097
+ sage: None - FrozenBitset('10101')
1098
+ Traceback (most recent call last):
1099
+ ...
1100
+ AttributeError: 'NoneType' object has no attribute 'difference'...
1101
+ """
1102
+ return self.difference(other)
1103
+
1104
+ cpdef symmetric_difference(self, FrozenBitset other):
1105
+ """
1106
+ Return the symmetric difference of ``self`` and ``other``.
1107
+
1108
+ EXAMPLES::
1109
+
1110
+ sage: FrozenBitset('10101').symmetric_difference(FrozenBitset('11100'))
1111
+ 01001
1112
+ sage: FrozenBitset('11111' * 10).symmetric_difference(FrozenBitset('010101' * 10))
1113
+ 101010101010101010101010101010101010101010101010100101010101
1114
+
1115
+ TESTS::
1116
+
1117
+ sage: set(FrozenBitset('11111' * 10).symmetric_difference(FrozenBitset('010101' * 10))) == set(FrozenBitset('11111' * 10)).symmetric_difference(FrozenBitset('010101' * 10))
1118
+ True
1119
+ sage: set(FrozenBitset('1' * 5).symmetric_difference(FrozenBitset('01010' * 20))) == set(FrozenBitset('1' * 5)).symmetric_difference(FrozenBitset('01010' * 20))
1120
+ True
1121
+ sage: set(FrozenBitset('10101' * 20).symmetric_difference(FrozenBitset('1' * 5))) == set(FrozenBitset('10101' * 20)).symmetric_difference(FrozenBitset('1' * 5))
1122
+ True
1123
+ sage: FrozenBitset('11111' * 10).symmetric_difference(None)
1124
+ Traceback (most recent call last):
1125
+ ...
1126
+ ValueError: other cannot be None
1127
+ """
1128
+ if other is None:
1129
+ raise ValueError("other cannot be None")
1130
+ cdef FrozenBitset temp, smaller, larger
1131
+ if self._bitset.size <= other._bitset.size:
1132
+ smaller = self
1133
+ larger = other
1134
+ else:
1135
+ smaller = other
1136
+ larger = self
1137
+
1138
+ temp = self._new(smaller._bitset.size)
1139
+ bitset_copy(temp._bitset, smaller._bitset)
1140
+ bitset_realloc(temp._bitset, larger._bitset.size)
1141
+ bitset_symmetric_difference(temp._bitset, temp._bitset, larger._bitset)
1142
+ return temp
1143
+
1144
+ def __xor__(self, FrozenBitset other not None):
1145
+ """
1146
+ Return the symmetric difference of ``self`` and ``other``.
1147
+
1148
+ Note that because of the Sage preprocessor, in Sage, ``^^`` is the
1149
+ exclusive or, rather than ``^``.
1150
+
1151
+ EXAMPLES::
1152
+
1153
+ sage: FrozenBitset('10101') ^^ FrozenBitset('11100')
1154
+ 01001
1155
+ sage: FrozenBitset('11111' * 10) ^^ FrozenBitset('010101' * 10)
1156
+ 101010101010101010101010101010101010101010101010100101010101
1157
+
1158
+ TESTS::
1159
+
1160
+ sage: set(FrozenBitset('11111' * 10) ^^ FrozenBitset('010101' * 10)) == set(FrozenBitset('11111' * 10)) ^^ set(FrozenBitset('010101' * 10))
1161
+ True
1162
+ sage: set(FrozenBitset('1' * 5) ^^ FrozenBitset('01010' * 20)) == set(FrozenBitset('1' * 5)) ^^ set(FrozenBitset('01010' * 20))
1163
+ True
1164
+ sage: set(FrozenBitset('10101' * 20) ^^ FrozenBitset('1' * 5)) == set(FrozenBitset('10101' * 20)) ^^ set(FrozenBitset('1' * 5))
1165
+ True
1166
+ sage: FrozenBitset('11111' * 10) ^^ None
1167
+ Traceback (most recent call last):
1168
+ ...
1169
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1170
+ sage: None ^^ FrozenBitset('11111' * 10)
1171
+ Traceback (most recent call last):
1172
+ ...
1173
+ AttributeError: 'NoneType' object has no attribute 'symmetric_difference'...
1174
+ """
1175
+ return self.symmetric_difference(other)
1176
+
1177
+ cpdef complement(self):
1178
+ """
1179
+ Return the complement of ``self``.
1180
+
1181
+ EXAMPLES::
1182
+
1183
+ sage: ~FrozenBitset('10101')
1184
+ 01010
1185
+ sage: ~FrozenBitset('11111'*10)
1186
+ 00000000000000000000000000000000000000000000000000
1187
+ sage: x = FrozenBitset('10'*40)
1188
+ sage: x == ~x
1189
+ False
1190
+ sage: x == ~~x
1191
+ True
1192
+ sage: x|(~x) == FrozenBitset('11'*40)
1193
+ True
1194
+ sage: ~x == FrozenBitset('01'*40)
1195
+ True
1196
+ """
1197
+ cdef FrozenBitset temp = self._new(self._bitset.size)
1198
+ bitset_complement(temp._bitset, self._bitset)
1199
+ return temp
1200
+
1201
+ def __invert__(self):
1202
+ """
1203
+ Return the complement of ``self``.
1204
+
1205
+ EXAMPLES::
1206
+
1207
+ sage: ~FrozenBitset('10101')
1208
+ 01010
1209
+ sage: ~FrozenBitset('11111'*10)
1210
+ 00000000000000000000000000000000000000000000000000
1211
+ sage: x = FrozenBitset('10'*40)
1212
+ sage: x == ~x
1213
+ False
1214
+ sage: x == ~~x
1215
+ True
1216
+ sage: x|(~x) == FrozenBitset('11'*40)
1217
+ True
1218
+ sage: ~x == FrozenBitset('01'*40)
1219
+ True
1220
+ """
1221
+ return self.complement()
1222
+
1223
+ cpdef __copy__(self):
1224
+ """
1225
+ Return ``self`` (since ``self`` is immutable).
1226
+
1227
+ EXAMPLES::
1228
+
1229
+ sage: a = FrozenBitset('10101')
1230
+ sage: from copy import copy
1231
+ sage: b = copy(a)
1232
+ sage: b is a
1233
+ True
1234
+ sage: c = FrozenBitset('1010' * 32)
1235
+ sage: d = copy(c)
1236
+ sage: d is c
1237
+ True
1238
+ """
1239
+ return self
1240
+
1241
+ cdef class Bitset(FrozenBitset):
1242
+ r"""
1243
+ A bitset class which leverages inline Cython functions for creating
1244
+ and manipulating bitsets. See the class documentation of
1245
+ :class:`FrozenBitset` for details on the parameters of the constructor
1246
+ and how to interpret the string representation of a :class:`Bitset`.
1247
+
1248
+ A bitset can be thought of in two ways. First, as a set of elements
1249
+ from the universe of the `n` natural numbers `0, 1, \dots, n-1` (where
1250
+ the capacity `n` can be specified), with typical set operations such as
1251
+ intersection, union, symmetric difference, etc. Secondly, a bitset can
1252
+ be thought of as a binary vector with typical binary operations such as
1253
+ ``and``, ``or``, ``xor``, etc. This class supports both interfaces.
1254
+
1255
+ The interface in this class mirrors the interface in the ``set``
1256
+ data type of Python.
1257
+
1258
+ .. warning::
1259
+
1260
+ This class is most likely to be useful as a way to store
1261
+ Cython bitsets in Python data structures, acting on them using
1262
+ the Cython inline functions. If you want to use this class
1263
+ for a Python set type, the Python ``set`` data type may be
1264
+ faster.
1265
+
1266
+ .. SEEALSO::
1267
+
1268
+ - :class:`FrozenBitset`
1269
+ - Python's `set types <https://docs.python.org/library/stdtypes.html#set-types-set-frozenset>`_
1270
+
1271
+ EXAMPLES::
1272
+
1273
+ sage: a = Bitset('1101')
1274
+ sage: loads(dumps(a)) == a
1275
+ True
1276
+ sage: a = Bitset('1101' * 32)
1277
+ sage: loads(dumps(a)) == a
1278
+ True
1279
+ """
1280
+
1281
+ cpdef __copy__(self):
1282
+ """
1283
+ Return a copy of ``self``.
1284
+
1285
+ EXAMPLES::
1286
+
1287
+ sage: a = Bitset('10101')
1288
+ sage: from copy import copy
1289
+ sage: b = copy(a)
1290
+ sage: b is a
1291
+ False
1292
+ sage: b == a
1293
+ True
1294
+ sage: c = Bitset('1010' * 32)
1295
+ sage: d = copy(c)
1296
+ sage: d is c
1297
+ False
1298
+ sage: d == c
1299
+ True
1300
+ """
1301
+ cdef FrozenBitset temp = self._new(self._bitset.size)
1302
+ bitset_copy(temp._bitset, self._bitset)
1303
+ return temp
1304
+
1305
+ def __hash__(self):
1306
+ """
1307
+ Raise an error, since mutable ``Bitset``s are not hashable.
1308
+
1309
+ EXAMPLES::
1310
+
1311
+ sage: hash(Bitset('110'))
1312
+ Traceback (most recent call last):
1313
+ ...
1314
+ TypeError: Bitset objects are unhashable; use FrozenBitset
1315
+ """
1316
+ raise TypeError("Bitset objects are unhashable; use FrozenBitset")
1317
+
1318
+ def __richcmp__(FrozenBitset self, FrozenBitset other not None, int op):
1319
+ """
1320
+ Implement comparisons, using the Cython richcmp convention.
1321
+ Comparison is done by inclusion. That is, a set ``A`` is less than
1322
+ another set ``B``, written ``A < B``, if ``A`` is a subset of ``B``.
1323
+
1324
+ EXAMPLES::
1325
+
1326
+ sage: Bitset('11') < Bitset('101')
1327
+ False
1328
+ sage: Bitset('11') <= Bitset('110')
1329
+ True
1330
+ sage: Bitset('11') != Bitset('10')
1331
+ True
1332
+ sage: Bitset('11') == Bitset('10')
1333
+ False
1334
+ sage: Bitset('11') == Bitset('110')
1335
+ True
1336
+ sage: Bitset('11') > Bitset('10')
1337
+ True
1338
+ sage: Bitset('11') >= Bitset('10')
1339
+ True
1340
+ sage: FrozenBitset('11') < FrozenBitset('110' * 32)
1341
+ True
1342
+
1343
+ TESTS:
1344
+
1345
+ During comparison, ``other`` cannot be ``None``. ::
1346
+
1347
+ sage: Bitset('11') < None
1348
+ Traceback (most recent call last):
1349
+ ...
1350
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1351
+ sage: Bitset('11') <= None
1352
+ Traceback (most recent call last):
1353
+ ...
1354
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1355
+ sage: Bitset('11') > None
1356
+ Traceback (most recent call last):
1357
+ ...
1358
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1359
+ sage: Bitset('11') >= None
1360
+ Traceback (most recent call last):
1361
+ ...
1362
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1363
+ sage: Bitset('11') == None
1364
+ Traceback (most recent call last):
1365
+ ...
1366
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1367
+ sage: Bitset('11') != None
1368
+ Traceback (most recent call last):
1369
+ ...
1370
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1371
+ sage: None < Bitset('11')
1372
+ Traceback (most recent call last):
1373
+ ...
1374
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1375
+ sage: None <= Bitset('11')
1376
+ Traceback (most recent call last):
1377
+ ...
1378
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1379
+ sage: None > Bitset('11')
1380
+ Traceback (most recent call last):
1381
+ ...
1382
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1383
+ sage: None >= Bitset('11')
1384
+ Traceback (most recent call last):
1385
+ ...
1386
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1387
+ sage: None == Bitset('11')
1388
+ Traceback (most recent call last):
1389
+ ...
1390
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1391
+ sage: None != Bitset('11')
1392
+ Traceback (most recent call last):
1393
+ ...
1394
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1395
+ """
1396
+ cdef FrozenBitset left, right
1397
+
1398
+ if self._bitset.size == other._bitset.size:
1399
+ left = self
1400
+ right = other
1401
+ elif self._bitset.size < other._bitset.size:
1402
+ left = self._larger_capacity_(other._bitset.size)
1403
+ right = other
1404
+ else:
1405
+ left = self
1406
+ right = other._larger_capacity_(self._bitset.size)
1407
+
1408
+ if op == Py_EQ:
1409
+ return bitset_eq(left._bitset, right._bitset)
1410
+ elif op == Py_NE:
1411
+ return not bitset_eq(left._bitset, right._bitset)
1412
+ elif op == Py_LT:
1413
+ return bitset_issubset(left._bitset, right._bitset) and not bitset_eq(left._bitset, right._bitset)
1414
+ elif op == Py_LE:
1415
+ return bitset_issubset(left._bitset, right._bitset)
1416
+ elif op == Py_GT:
1417
+ return bitset_issuperset(left._bitset, right._bitset) and not bitset_eq(left._bitset, right._bitset)
1418
+ elif op == Py_GE:
1419
+ return bitset_issuperset(left._bitset, right._bitset)
1420
+
1421
+ cdef FrozenBitset _new(self, long int capacity):
1422
+ """
1423
+ Return an object of the same type as ``self``, initialized with a
1424
+ bitset of capacity ``capacity``.
1425
+ """
1426
+ cdef Bitset b
1427
+ b = Bitset.__new__(Bitset, None, capacity)
1428
+ return b
1429
+
1430
+ cpdef update(self, FrozenBitset other):
1431
+ """
1432
+ Update the bitset to include items in ``other``.
1433
+
1434
+ EXAMPLES::
1435
+
1436
+ sage: a = Bitset('110')
1437
+ sage: a.update(Bitset('0101'))
1438
+ sage: a
1439
+ 1101
1440
+ sage: a_set = set(a)
1441
+ sage: a.update(Bitset('00011' * 25))
1442
+ sage: a
1443
+ 11011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011
1444
+ sage: a_set.update(Bitset('00011' * 25))
1445
+ sage: set(a) == a_set
1446
+ True
1447
+
1448
+ TESTS:
1449
+
1450
+ During update, ``other`` cannot be ``None``. ::
1451
+
1452
+ sage: a = Bitset('1101')
1453
+ sage: a.update(None)
1454
+ Traceback (most recent call last):
1455
+ ...
1456
+ TypeError: other cannot be None
1457
+ """
1458
+ if other is None:
1459
+ raise TypeError("other cannot be None")
1460
+ cdef bitset_t temp
1461
+ if self._bitset.size == other._bitset.size:
1462
+ bitset_union(self._bitset, self._bitset, other._bitset)
1463
+ elif self._bitset.size < other._bitset.size:
1464
+ bitset_realloc(self._bitset, other._bitset.size)
1465
+ bitset_union(self._bitset, self._bitset, other._bitset)
1466
+ else:
1467
+ bitset_init(temp, other._bitset.size)
1468
+ bitset_copy(temp, other._bitset)
1469
+ bitset_realloc(temp, self._bitset.size)
1470
+ bitset_union(self._bitset, self._bitset, temp)
1471
+ bitset_free(temp)
1472
+
1473
+ def __ior__(self, FrozenBitset other not None):
1474
+ """
1475
+ Update the bitset to include items in ``other``.
1476
+
1477
+ EXAMPLES::
1478
+
1479
+ sage: a = Bitset('110')
1480
+ sage: a |= Bitset('0101')
1481
+ sage: a
1482
+ 1101
1483
+ sage: a_set = set(a)
1484
+ sage: a |= Bitset('00011' * 25)
1485
+ sage: a
1486
+ 11011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011000110001100011
1487
+ sage: a_set |= set(Bitset('00011' * 25))
1488
+ sage: set(a) == a_set
1489
+ True
1490
+
1491
+ TESTS::
1492
+
1493
+ sage: a = Bitset('110')
1494
+ sage: a |= None
1495
+ Traceback (most recent call last):
1496
+ ...
1497
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1498
+ """
1499
+ self.update(other)
1500
+ return self
1501
+
1502
+ cpdef intersection_update(self, FrozenBitset other):
1503
+ """
1504
+ Update the bitset to the intersection of ``self`` and ``other``.
1505
+
1506
+ EXAMPLES::
1507
+
1508
+ sage: a = Bitset('110')
1509
+ sage: a.intersection_update(Bitset('0101'))
1510
+ sage: a
1511
+ 0100
1512
+ sage: a_set = set(a)
1513
+ sage: a.intersection_update(Bitset('0110' * 25))
1514
+ sage: a
1515
+ 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1516
+ sage: a_set.intersection_update(Bitset('0110' * 25))
1517
+ sage: set(a) == a_set
1518
+ True
1519
+
1520
+ TESTS::
1521
+
1522
+ sage: Bitset('110').intersection_update(None)
1523
+ Traceback (most recent call last):
1524
+ ...
1525
+ TypeError: other cannot be None
1526
+ """
1527
+ if other is None:
1528
+ raise TypeError("other cannot be None")
1529
+ cdef bitset_t temp
1530
+ if self._bitset.size == other._bitset.size:
1531
+ bitset_intersection(self._bitset, self._bitset, other._bitset)
1532
+ elif self._bitset.size < other._bitset.size:
1533
+ bitset_realloc(self._bitset, other._bitset.size)
1534
+ bitset_intersection(self._bitset, self._bitset, other._bitset)
1535
+ else:
1536
+ bitset_init(temp, other._bitset.size)
1537
+ bitset_copy(temp, other._bitset)
1538
+ bitset_realloc(temp, self._bitset.size)
1539
+ bitset_intersection(self._bitset, self._bitset, temp)
1540
+ bitset_free(temp)
1541
+
1542
+ def __iand__(self, FrozenBitset other not None):
1543
+ """
1544
+ Update the bitset to the intersection of ``self`` and ``other``.
1545
+
1546
+ EXAMPLES::
1547
+
1548
+ sage: a = Bitset('110')
1549
+ sage: a &= Bitset('0101')
1550
+ sage: a
1551
+ 0100
1552
+ sage: a_set = set(a)
1553
+ sage: a &= Bitset('0110' * 25)
1554
+ sage: a
1555
+ 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1556
+ sage: a_set &= set(Bitset('0110' * 25))
1557
+ sage: a_set == set(a)
1558
+ True
1559
+
1560
+ TESTS::
1561
+
1562
+ sage: a = Bitset('110')
1563
+ sage: a &= None
1564
+ Traceback (most recent call last):
1565
+ ...
1566
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1567
+ """
1568
+ self.intersection_update(other)
1569
+ return self
1570
+
1571
+ cpdef difference_update(self, FrozenBitset other):
1572
+ """
1573
+ Update the bitset to the difference of ``self`` and ``other``.
1574
+
1575
+ EXAMPLES::
1576
+
1577
+ sage: a = Bitset('110')
1578
+ sage: a.difference_update(Bitset('0101'))
1579
+ sage: a
1580
+ 1000
1581
+ sage: a_set = set(a)
1582
+ sage: a.difference_update(FrozenBitset('010101' * 10)); a
1583
+ 100000000000000000000000000000000000000000000000000000000000
1584
+ sage: a_set.difference_update(FrozenBitset('010101' * 10))
1585
+ sage: a_set == set(a)
1586
+ True
1587
+ sage: a.difference_update(FrozenBitset('110'))
1588
+ sage: a_set.difference_update(FrozenBitset('110'))
1589
+ sage: a_set == set(a)
1590
+ True
1591
+ sage: a.difference_update(FrozenBitset('01010' * 20)); a
1592
+ 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1593
+ sage: a_set.difference_update(FrozenBitset('01010' * 20))
1594
+ sage: a_set == set(a)
1595
+ True
1596
+ sage: b = Bitset('10101' * 20)
1597
+ sage: b_set = set(b)
1598
+ sage: b.difference_update(FrozenBitset('1' * 5)); b
1599
+ 0000010101101011010110101101011010110101101011010110101101011010110101101011010110101101011010110101
1600
+ sage: b_set.difference_update(FrozenBitset('1' * 5))
1601
+ sage: b_set == set(b)
1602
+ True
1603
+
1604
+ TESTS::
1605
+
1606
+ sage: Bitset('110').difference_update(None)
1607
+ Traceback (most recent call last):
1608
+ ...
1609
+ TypeError: other cannot be None
1610
+ """
1611
+ if other is None:
1612
+ raise TypeError("other cannot be None")
1613
+ cdef bitset_t temp
1614
+ if self._bitset.size == other._bitset.size:
1615
+ bitset_difference(self._bitset, self._bitset, other._bitset)
1616
+ elif self._bitset.size < other._bitset.size:
1617
+ bitset_realloc(self._bitset, other._bitset.size)
1618
+ bitset_difference(self._bitset, self._bitset, other._bitset)
1619
+ else:
1620
+ bitset_init(temp, other._bitset.size)
1621
+ bitset_copy(temp, other._bitset)
1622
+ bitset_realloc(temp, self._bitset.size)
1623
+ bitset_difference(self._bitset, self._bitset, temp)
1624
+ bitset_free(temp)
1625
+
1626
+ def __isub__(self, FrozenBitset other not None):
1627
+ """
1628
+ Update the bitset to the difference of ``self`` and ``other``.
1629
+
1630
+ EXAMPLES::
1631
+
1632
+ sage: a = Bitset('110')
1633
+ sage: a -= Bitset('0101')
1634
+ sage: a
1635
+ 1000
1636
+ sage: a_set = set(a)
1637
+ sage: a -= FrozenBitset('010101' * 10); a
1638
+ 100000000000000000000000000000000000000000000000000000000000
1639
+ sage: a_set -= set(FrozenBitset('010101' * 10))
1640
+ sage: a_set == set(a)
1641
+ True
1642
+ sage: a = Bitset('110')
1643
+ sage: a_set = set(a)
1644
+ sage: a -= FrozenBitset('01010' * 20); a
1645
+ 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1646
+ sage: a_set -= set(FrozenBitset('01010' * 20))
1647
+ sage: a_set == set(a)
1648
+ True
1649
+ sage: b = FrozenBitset('10101' * 20)
1650
+ sage: b_set = set(b)
1651
+ sage: b -= FrozenBitset('1' * 5); b
1652
+ 0000010101101011010110101101011010110101101011010110101101011010110101101011010110101101011010110101
1653
+ sage: b_set -= FrozenBitset('1' * 5)
1654
+ sage: b_set == set(b)
1655
+ True
1656
+
1657
+ TESTS::
1658
+
1659
+ sage: a = Bitset('110')
1660
+ sage: a -= None
1661
+ Traceback (most recent call last):
1662
+ ...
1663
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1664
+ """
1665
+ self.difference_update(other)
1666
+ return self
1667
+
1668
+ cpdef symmetric_difference_update(self, FrozenBitset other):
1669
+ """
1670
+ Update the bitset to the symmetric difference of ``self`` and
1671
+ ``other``.
1672
+
1673
+ EXAMPLES::
1674
+
1675
+ sage: a = Bitset('110')
1676
+ sage: a.symmetric_difference_update(Bitset('0101'))
1677
+ sage: a
1678
+ 1001
1679
+ sage: a_set = set(a)
1680
+ sage: a.symmetric_difference_update(FrozenBitset('010101' * 10)); a
1681
+ 110001010101010101010101010101010101010101010101010101010101
1682
+ sage: a_set.symmetric_difference_update(FrozenBitset('010101' * 10))
1683
+ sage: a_set == set(a)
1684
+ True
1685
+ sage: a.symmetric_difference_update(FrozenBitset('01010' * 20)); a
1686
+ 1001011111000001111100000111110000011111000001111100000111110101001010010100101001010010100101001010
1687
+ sage: a_set.symmetric_difference_update(FrozenBitset('01010' * 20))
1688
+ sage: a_set == set(a)
1689
+ True
1690
+ sage: b = Bitset('10101' * 20)
1691
+ sage: b_set = set(b)
1692
+ sage: b.symmetric_difference_update( FrozenBitset('1' * 5)); b
1693
+ 0101010101101011010110101101011010110101101011010110101101011010110101101011010110101101011010110101
1694
+ sage: b_set.symmetric_difference_update( FrozenBitset('1' * 5))
1695
+ sage: b_set == set(b)
1696
+ True
1697
+
1698
+ TESTS::
1699
+
1700
+ sage: Bitset('110').symmetric_difference_update(None)
1701
+ Traceback (most recent call last):
1702
+ ...
1703
+ TypeError: other cannot be None
1704
+ """
1705
+ if other is None:
1706
+ raise TypeError("other cannot be None")
1707
+ cdef bitset_t temp
1708
+ if self._bitset.size == other._bitset.size:
1709
+ bitset_symmetric_difference(self._bitset, self._bitset, other._bitset)
1710
+ elif self._bitset.size < other._bitset.size:
1711
+ bitset_realloc(self._bitset, other._bitset.size)
1712
+ bitset_symmetric_difference(self._bitset, self._bitset, other._bitset)
1713
+ else:
1714
+ bitset_init(temp, other._bitset.size)
1715
+ bitset_copy(temp, other._bitset)
1716
+ bitset_realloc(temp, self._bitset.size)
1717
+ bitset_symmetric_difference(self._bitset, self._bitset, temp)
1718
+ bitset_free(temp)
1719
+
1720
+ def __ixor__(self, FrozenBitset other not None):
1721
+ """
1722
+ Update the bitset to the symmetric difference of ``self`` and
1723
+ ``other``.
1724
+
1725
+ EXAMPLES::
1726
+
1727
+ sage: a = Bitset('110')
1728
+ sage: a ^^=Bitset('0101')
1729
+ sage: a
1730
+ 1001
1731
+ sage: a_set = set(a)
1732
+ sage: a ^^= FrozenBitset('010101' * 10); a
1733
+ 110001010101010101010101010101010101010101010101010101010101
1734
+ sage: a_set ^^= set(FrozenBitset('010101' * 10))
1735
+ sage: a_set == set(a)
1736
+ True
1737
+ sage: a ^^= FrozenBitset('01010' * 20); a
1738
+ 1001011111000001111100000111110000011111000001111100000111110101001010010100101001010010100101001010
1739
+ sage: a_set ^^= set(FrozenBitset('01010' * 20))
1740
+ sage: a_set == set(a)
1741
+ True
1742
+ sage: b = Bitset('10101' * 20)
1743
+ sage: b_set = set(b)
1744
+ sage: b ^^= FrozenBitset('1' * 5); b
1745
+ 0101010101101011010110101101011010110101101011010110101101011010110101101011010110101101011010110101
1746
+ sage: b_set ^^= set(FrozenBitset('1' * 5))
1747
+ sage: b_set == set(b)
1748
+ True
1749
+
1750
+ TESTS::
1751
+
1752
+ sage: a = Bitset('110')
1753
+ sage: a ^^= None
1754
+ Traceback (most recent call last):
1755
+ ...
1756
+ TypeError: Argument 'other' has incorrect type (expected sage.data_structures.bitset.FrozenBitset, got NoneType)
1757
+ """
1758
+ self.symmetric_difference_update(other)
1759
+ return self
1760
+
1761
+ cpdef add(self, unsigned long n):
1762
+ """
1763
+ Update the bitset by adding ``n``.
1764
+
1765
+ EXAMPLES::
1766
+
1767
+ sage: a = Bitset('110')
1768
+ sage: a.add(5)
1769
+ sage: a
1770
+ 110001
1771
+ sage: a.add(100)
1772
+ sage: sorted(list(a))
1773
+ [0, 1, 5, 100]
1774
+ sage: a.capacity()
1775
+ 101
1776
+
1777
+ TESTS:
1778
+
1779
+ The input ``n`` must be an integer. ::
1780
+
1781
+ sage: Bitset('110').add(None)
1782
+ Traceback (most recent call last):
1783
+ ...
1784
+ TypeError: an integer is required
1785
+ """
1786
+ if n >= self._bitset.size:
1787
+ bitset_realloc(self._bitset, n + 1)
1788
+ bitset_add(self._bitset, n)
1789
+
1790
+ cpdef remove(self, unsigned long n):
1791
+ """
1792
+ Update the bitset by removing ``n``.
1793
+
1794
+ This raises a :exc:`KeyError` if ``n`` is not contained
1795
+ in the bitset.
1796
+
1797
+ EXAMPLES::
1798
+
1799
+ sage: a = Bitset('110')
1800
+ sage: a.remove(1)
1801
+ sage: a
1802
+ 100
1803
+ sage: a.remove(2)
1804
+ Traceback (most recent call last):
1805
+ ...
1806
+ KeyError: 2
1807
+ sage: a.remove(4)
1808
+ Traceback (most recent call last):
1809
+ ...
1810
+ KeyError: 4
1811
+ sage: a
1812
+ 100
1813
+ sage: a = Bitset('000001' * 15); sorted(list(a))
1814
+ [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89]
1815
+ sage: a.remove(83); sorted(list(a))
1816
+ [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 89]
1817
+
1818
+ TESTS:
1819
+
1820
+ The input ``n`` must be an integer. ::
1821
+
1822
+ sage: Bitset('110').remove(None)
1823
+ Traceback (most recent call last):
1824
+ ...
1825
+ TypeError: an integer is required
1826
+ """
1827
+ if n >= self._bitset.size:
1828
+ raise KeyError(n)
1829
+ else:
1830
+ bitset_remove(self._bitset, n)
1831
+
1832
+ cpdef discard(self, unsigned long n):
1833
+ """
1834
+ Update the bitset by removing ``n``.
1835
+
1836
+ EXAMPLES::
1837
+
1838
+ sage: a = Bitset('110')
1839
+ sage: a.discard(1)
1840
+ sage: a
1841
+ 100
1842
+ sage: a.discard(2)
1843
+ sage: a.discard(4)
1844
+ sage: a
1845
+ 100
1846
+ sage: a = Bitset('000001' * 15); sorted(list(a))
1847
+ [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89]
1848
+ sage: a.discard(83); sorted(list(a))
1849
+ [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 89]
1850
+ sage: a.discard(82); sorted(list(a))
1851
+ [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 89]
1852
+
1853
+ TESTS:
1854
+
1855
+ The input ``n`` must be an integer. ::
1856
+
1857
+ sage: Bitset('110').discard(None)
1858
+ Traceback (most recent call last):
1859
+ ...
1860
+ TypeError: an integer is required
1861
+ """
1862
+ if n < self._bitset.size:
1863
+ bitset_discard(self._bitset, n)
1864
+
1865
+ cpdef pop(self):
1866
+ """
1867
+ Remove and return an arbitrary element from the set.
1868
+
1869
+ This raises a :exc:`KeyError` if the set is empty.
1870
+
1871
+ EXAMPLES::
1872
+
1873
+ sage: a = Bitset('011')
1874
+ sage: a.pop()
1875
+ 1
1876
+ sage: a
1877
+ 001
1878
+ sage: a.pop()
1879
+ 2
1880
+ sage: a
1881
+ 000
1882
+ sage: a.pop()
1883
+ Traceback (most recent call last):
1884
+ ...
1885
+ KeyError: 'pop from an empty set'
1886
+ sage: a = Bitset('0001'*32)
1887
+ sage: a.pop()
1888
+ 3
1889
+ sage: [a.pop() for _ in range(20)]
1890
+ [7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83]
1891
+ """
1892
+ return bitset_pop(self._bitset)
1893
+
1894
+ cpdef clear(self):
1895
+ """
1896
+ Remove all elements from the bitset.
1897
+
1898
+ EXAMPLES::
1899
+
1900
+ sage: a = Bitset('011')
1901
+ sage: a.clear()
1902
+ sage: a
1903
+ 000
1904
+ sage: a = Bitset('011' * 32)
1905
+ sage: a.clear()
1906
+ sage: set(a)
1907
+ set()
1908
+ """
1909
+ bitset_clear(self._bitset)
1910
+
1911
+
1912
+ #############################################################################
1913
+ # Bitset Testing: test basic Cython bitsets
1914
+ #############################################################################
1915
+
1916
+ def test_bitset(py_a, py_b, long n):
1917
+ """
1918
+ Test the Cython bitset functions so we can have some relevant doctests.
1919
+
1920
+ TESTS::
1921
+
1922
+ sage: from sage.data_structures.bitset import test_bitset
1923
+ sage: test_bitset('00101', '01110', 4)
1924
+ a 00101
1925
+ list a [2, 4]
1926
+ a.size 5
1927
+ len(a) 2
1928
+ a.limbs 1
1929
+ b 01110
1930
+ a.in(n) True
1931
+ a.not_in(n) False
1932
+ a.add(n) 00101
1933
+ a.discard(n) 00100
1934
+ a.set_to(n) 00101
1935
+ a.flip(n) 00100
1936
+ a.set_first_n(n) 11110
1937
+ a.first_in_complement() 4
1938
+ a.isempty() False
1939
+ a.eq(b) False
1940
+ a.cmp(b) 1
1941
+ a.lex_cmp(b) -1
1942
+ a.issubset(b) False
1943
+ a.issuperset(b) False
1944
+ a.copy() 00101
1945
+ r.clear() 00000
1946
+ complement a 11010
1947
+ a intersect b 00100
1948
+ a union b 01111
1949
+ a minus b 00001
1950
+ a symmetric_difference b 01011
1951
+ a.rshift(n) 10000
1952
+ a.lshift(n) 00000
1953
+ a.first() 2
1954
+ a.next(n) 4
1955
+ a.first_diff(b) 1
1956
+ a.next_diff(b, n) 4
1957
+ a.hamming_weight() 2
1958
+ a.map(m) 10100
1959
+ a == loads(dumps(a)) True
1960
+ reallocating a 00101
1961
+ to size 4 0010
1962
+ to size 8 00100000
1963
+ to original size 00100
1964
+
1965
+ ::
1966
+
1967
+ sage: test_bitset('11101', '11001', 2)
1968
+ a 11101
1969
+ list a [0, 1, 2, 4]
1970
+ a.size 5
1971
+ len(a) 4
1972
+ a.limbs 1
1973
+ b 11001
1974
+ a.in(n) True
1975
+ a.not_in(n) False
1976
+ a.add(n) 11101
1977
+ a.discard(n) 11001
1978
+ a.set_to(n) 11101
1979
+ a.flip(n) 11001
1980
+ a.set_first_n(n) 11000
1981
+ a.first_in_complement() 2
1982
+ a.isempty() False
1983
+ a.eq(b) False
1984
+ a.cmp(b) 1
1985
+ a.lex_cmp(b) 1
1986
+ a.issubset(b) False
1987
+ a.issuperset(b) True
1988
+ a.copy() 11101
1989
+ r.clear() 00000
1990
+ complement a 00010
1991
+ a intersect b 11001
1992
+ a union b 11101
1993
+ a minus b 00100
1994
+ a symmetric_difference b 00100
1995
+ a.rshift(n) 10100
1996
+ a.lshift(n) 00111
1997
+ a.first() 0
1998
+ a.next(n) 2
1999
+ a.first_diff(b) 2
2000
+ a.next_diff(b, n) 2
2001
+ a.hamming_weight() 4
2002
+ a.map(m) 10111
2003
+ a == loads(dumps(a)) True
2004
+ reallocating a 11101
2005
+ to size 2 11
2006
+ to size 4 1100
2007
+ to original size 11000
2008
+
2009
+ Test a corner-case: a bitset that is a multiple of words::
2010
+
2011
+ sage: test_bitset('00'*64, '01'*64, 127)
2012
+ a 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2013
+ list a []
2014
+ a.size 128
2015
+ len(a) 0
2016
+ a.limbs ...
2017
+ b 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
2018
+ a.in(n) False
2019
+ a.not_in(n) True
2020
+ a.add(n) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2021
+ a.discard(n) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2022
+ a.set_to(n) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2023
+ a.flip(n) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
2024
+ a.set_first_n(n) 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110
2025
+ a.first_in_complement() 127
2026
+ a.isempty() True
2027
+ a.eq(b) False
2028
+ a.cmp(b) -1
2029
+ a.lex_cmp(b) -1
2030
+ a.issubset(b) True
2031
+ a.issuperset(b) False
2032
+ a.copy() 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2033
+ r.clear() 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2034
+ complement a 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
2035
+ a intersect b 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2036
+ a union b 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
2037
+ a minus b 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2038
+ a symmetric_difference b 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
2039
+ a.rshift(n) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2040
+ a.lshift(n) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2041
+ a.first() -1
2042
+ a.next(n) -1
2043
+ a.first_diff(b) 1
2044
+ a.next_diff(b, n) 127
2045
+ a.hamming_weight() 0
2046
+ a.map(m) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2047
+ a == loads(dumps(a)) True
2048
+ rshifts add True
2049
+ lshifts add True
2050
+ intersection commutes True
2051
+ union commutes True
2052
+ not not = id True
2053
+ flipped bit 127
2054
+ add bit 127
2055
+ discard bit 127
2056
+ lshift add unset ok True
2057
+ rshift set unset ok True
2058
+ reallocating a 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2059
+ to size 127 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2060
+ to size 254 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2061
+ to original size 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2062
+
2063
+ Large enough to span multiple limbs. We don't explicitly check the number of limbs below because it will be different in the 32 bit versus 64 bit cases::
2064
+
2065
+ sage: test_bitset('111001'*25, RealField(151)(pi).str(2)[2:], 69) # needs sage.symbolic
2066
+ a 111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001
2067
+ list a [0, 1, 2, 5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20, 23, 24, 25, 26, 29, 30, 31, 32, 35, 36, 37, 38, 41, 42, 43, 44, 47, 48, 49, 50, 53, 54, 55, 56, 59, 60, 61, 62, 65, 66, 67, 68, 71, 72, 73, 74, 77, 78, 79, 80, 83, 84, 85, 86, 89, 90, 91, 92, 95, 96, 97, 98, 101, 102, 103, 104, 107, 108, 109, 110, 113, 114, 115, 116, 119, 120, 121, 122, 125, 126, 127, 128, 131, 132, 133, 134, 137, 138, 139, 140, 143, 144, 145, 146, 149]
2068
+ a.size 150
2069
+ len(a) 100
2070
+ a.limbs ...
2071
+ b 000100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111
2072
+ a.in(n) False
2073
+ a.not_in(n) True
2074
+ a.add(n) 111001111001111001111001111001111001111001111001111001111001111001111101111001111001111001111001111001111001111001111001111001111001111001111001111001
2075
+ a.discard(n) 111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001
2076
+ a.set_to(n) 111001111001111001111001111001111001111001111001111001111001111001111101111001111001111001111001111001111001111001111001111001111001111001111001111001
2077
+ a.flip(n) 111001111001111001111001111001111001111001111001111001111001111001111101111001111001111001111001111001111001111001111001111001111001111001111001111001
2078
+ a.set_first_n(n) 111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000
2079
+ a.first_in_complement() 69
2080
+ a.isempty() False
2081
+ a.eq(b) False
2082
+ a.cmp(b) -1
2083
+ a.lex_cmp(b) 1
2084
+ a.issubset(b) False
2085
+ a.issuperset(b) False
2086
+ a.copy() 111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001
2087
+ r.clear() 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2088
+ complement a 000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110000110
2089
+ a intersect b 000000100001111000110001010001000000001001010001100001000000100000001001100001001000010000010001000000011001100000111001101000100001001000000000100001
2090
+ a union b 111101111001111111111101111001111101111011111001111001111111111111111001111011111101111101111111111001111011111001111001111001111101111001111101111111
2091
+ a minus b 111001011000000001001000101000111001110000101000011000111001011001110000011000110001101001101000111001100000011001000000010001011000110001111001011000
2092
+ a symmetric_difference b 111101011000000111001100101000111101110010101000011000111111011111110000011010110101101101101110111001100010011001000000010001011100110001111101011110
2093
+ a.rshift(n) 001111001111001111001111001111001111001111001111001111001111001111001111001111001000000000000000000000000000000000000000000000000000000000000000000000
2094
+ a.lshift(n) 000000000000000000000000000000000000000000000000000000000000000000000111001111001111001111001111001111001111001111001111001111001111001111001111001111
2095
+ a.first() 0
2096
+ a.next(n) 71
2097
+ a.first_diff(b) 0
2098
+ a.next_diff(b, n) 73
2099
+ a.hamming_weight() 100
2100
+ a.map(m) 100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111100111
2101
+ a == loads(dumps(a)) True
2102
+ rshifts add True
2103
+ lshifts add True
2104
+ intersection commutes True
2105
+ union commutes True
2106
+ not not = id True
2107
+ flipped bit 69
2108
+ add bit 69
2109
+ discard bit 69
2110
+ lshift add unset ok True
2111
+ rshift set unset ok True
2112
+ reallocating a 111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001111001
2113
+ to size 69 111001111001111001111001111001111001111001111001111001111001111001111
2114
+ to size 138 111001111001111001111001111001111001111001111001111001111001111001111000000000000000000000000000000000000000000000000000000000000000000000
2115
+ to original size 111001111001111001111001111001111001111001111001111001111001111001111000000000000000000000000000000000000000000000000000000000000000000000000000000000
2116
+ """
2117
+ cdef bint bit = True
2118
+ cdef bitset_t a, b, r
2119
+
2120
+ bitset_from_str(a, py_a)
2121
+ bitset_from_str(b, py_b)
2122
+
2123
+ if a.size != b.size:
2124
+ raise ValueError("inputs must have same size")
2125
+
2126
+ print("a", bitset_string(a))
2127
+ print("list a", bitset_list(a))
2128
+ print("a.size", a.size)
2129
+ print("len(a)", bitset_len(a))
2130
+ print("a.limbs", a.limbs)
2131
+ print("b", bitset_string(b))
2132
+ print("a.in(n) ", bitset_in(a, n))
2133
+ print("a.not_in(n) ", bitset_not_in(a, n))
2134
+ bitset_add(a, n)
2135
+ print("a.add(n) ", bitset_string(a))
2136
+ bitset_from_str(a, py_a)
2137
+ bitset_discard(a, n)
2138
+ print("a.discard(n) ", bitset_string(a))
2139
+ bitset_from_str(a, py_a)
2140
+ bitset_set_to(a, n, bit)
2141
+ print("a.set_to(n) ", bitset_string(a))
2142
+ bitset_from_str(a, py_a)
2143
+ bitset_flip(a, n)
2144
+ print("a.flip(n) ", bitset_string(a))
2145
+ bitset_set_first_n(a, n)
2146
+ print("a.set_first_n(n) ", bitset_string(a))
2147
+ print("a.first_in_complement() ", bitset_first_in_complement(a))
2148
+
2149
+ bitset_from_str(a, py_a)
2150
+ bitset_from_str(b, py_b)
2151
+ print("a.isempty() ", bitset_isempty(a))
2152
+ print("a.eq(b) ", bitset_eq(a, b))
2153
+ print("a.cmp(b) ", bitset_cmp(a, b))
2154
+ print("a.lex_cmp(b)", bitset_lex_cmp(a, b))
2155
+ print("a.issubset(b)", bitset_issubset(a, b))
2156
+ print("a.issuperset(b)", bitset_issuperset(a, b))
2157
+
2158
+ bitset_from_str(a, py_a)
2159
+ bitset_from_str(b, py_b)
2160
+
2161
+ bitset_init(r, a.size)
2162
+ bitset_copy(r, a)
2163
+ print("a.copy() ", bitset_string(r))
2164
+ bitset_clear(r)
2165
+ print("r.clear() ", bitset_string(r))
2166
+ bitset_complement(r, a)
2167
+ print("complement a ", bitset_string(r))
2168
+ bitset_intersection(r, a, b)
2169
+ print("a intersect b ", bitset_string(r))
2170
+ bitset_union(r, a, b)
2171
+ print("a union b ", bitset_string(r))
2172
+ bitset_difference(r, a, b)
2173
+ print("a minus b ", bitset_string(r))
2174
+ bitset_symmetric_difference(r, a, b)
2175
+ print("a symmetric_difference b ", bitset_string(r))
2176
+
2177
+ bitset_rshift(r, a, n)
2178
+ print("a.rshift(n) ", bitset_string(r))
2179
+
2180
+ bitset_lshift(r, a, n)
2181
+ print("a.lshift(n) ", bitset_string(r))
2182
+
2183
+ print("a.first() ", bitset_first(a))
2184
+ print("a.next(n) ", bitset_next(a, n))
2185
+ print("a.first_diff(b) ", bitset_first_diff(a, b))
2186
+ print("a.next_diff(b, n) ", bitset_next_diff(a, b, n))
2187
+
2188
+ print("a.hamming_weight() ", bitset_hamming_weight(a))
2189
+
2190
+ morphism = {i: a.size - i - 1 for i in range(a.size)}
2191
+ bitset_map(r, a, morphism)
2192
+ print("a.map(m) ", bitset_string(r))
2193
+
2194
+ data = bitset_pickle(a)
2195
+ bitset_unpickle(r, data)
2196
+ print("a == loads(dumps(a)) ", bitset_eq(r, a))
2197
+
2198
+ cdef bitset_t s
2199
+ bitset_init(s, a.size)
2200
+
2201
+ if a.size > 100:
2202
+ bitset_rshift(r, b, 3)
2203
+ bitset_rshift(r, r, 77)
2204
+ bitset_rshift(s, b, 80)
2205
+ print("rshifts add ", bitset_eq(s, r))
2206
+
2207
+ bitset_lshift(r, b, 69)
2208
+ bitset_lshift(r, r, 6)
2209
+ bitset_lshift(s, b, 75)
2210
+ print("lshifts add ", bitset_eq(s, r))
2211
+
2212
+ bitset_intersection(r, a, b)
2213
+ bitset_intersection(s, b, a)
2214
+ print("intersection commutes", bitset_eq(s, r))
2215
+
2216
+ bitset_union(r, a, b)
2217
+ bitset_union(s, b, a)
2218
+ print("union commutes ", bitset_eq(s, r))
2219
+
2220
+ bitset_complement(r, b)
2221
+ bitset_complement(s, r)
2222
+ print("not not = id", bitset_eq(s, b))
2223
+
2224
+ bitset_copy(r, b)
2225
+ bitset_flip(r, n)
2226
+ print("flipped bit ", bitset_first_diff(b, r))
2227
+
2228
+ bitset_clear(r)
2229
+ bitset_add(r, n)
2230
+ print("add bit ", bitset_first(r))
2231
+
2232
+ bitset_clear(r)
2233
+ bitset_complement(r, r)
2234
+ bitset_discard(r, n)
2235
+ bitset_complement(r, r)
2236
+ print("discard bit ", bitset_first(r))
2237
+
2238
+ bitset_clear(r)
2239
+ bitset_add(r, 10)
2240
+ bitset_lshift(r, r, 68)
2241
+ bitset_flip(r, 78)
2242
+ print("lshift add unset ok", bitset_isempty(r))
2243
+
2244
+ bitset_clear(r)
2245
+ bitset_add(r, 19)
2246
+ bitset_rshift(r, r, 8)
2247
+ bitset_discard(r, 11)
2248
+ print("rshift set unset ok", bitset_isempty(r))
2249
+
2250
+ print("reallocating a ", bitset_string(a))
2251
+ bitset_realloc(a, n)
2252
+ print("to size %d " % n, bitset_string(a))
2253
+ bitset_realloc(a, 2 * n)
2254
+ print("to size %d " % (2 * n), bitset_string(a))
2255
+ bitset_realloc(a, b.size)
2256
+ print("to original size ", bitset_string(a))
2257
+
2258
+ bitset_free(a)
2259
+ bitset_free(b)
2260
+ bitset_free(r)
2261
+ bitset_free(s)
2262
+
2263
+
2264
+ def test_bitset_set_first_n(py_a, long n):
2265
+ """
2266
+ Test the bitset function set_first_n.
2267
+
2268
+ TESTS::
2269
+
2270
+ sage: from sage.data_structures.bitset import test_bitset_set_first_n
2271
+ sage: test_bitset_set_first_n('00'*64, 128)
2272
+ a.set_first_n(n) 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
2273
+ """
2274
+ cdef bitset_t a
2275
+
2276
+ bitset_from_str(a, py_a)
2277
+ bitset_set_first_n(a, n)
2278
+ print("a.set_first_n(n) ", bitset_string(a))
2279
+ bitset_free(a)
2280
+
2281
+
2282
+ def test_bitset_remove(py_a, long n):
2283
+ """
2284
+ Test the bitset_remove function.
2285
+
2286
+ TESTS::
2287
+
2288
+ sage: from sage.data_structures.bitset import test_bitset_remove
2289
+ sage: test_bitset_remove('01', 0)
2290
+ Traceback (most recent call last):
2291
+ ...
2292
+ KeyError: 0
2293
+ sage: test_bitset_remove('01', 1)
2294
+ a 01
2295
+ a.size 2
2296
+ a.limbs 1
2297
+ n 1
2298
+ a.remove(n) 00
2299
+ """
2300
+ cdef bitset_t a
2301
+ bitset_from_str(a, py_a)
2302
+
2303
+ print("a", bitset_string(a))
2304
+ print("a.size", a.size)
2305
+ print("a.limbs", a.limbs)
2306
+ print("n", n)
2307
+
2308
+ bitset_remove(a, n)
2309
+ print("a.remove(n) ", bitset_string(a))
2310
+
2311
+ bitset_free(a)
2312
+
2313
+
2314
+ def test_bitset_pop(py_a):
2315
+ """
2316
+ Test for the bitset_pop function.
2317
+
2318
+ TESTS::
2319
+
2320
+ sage: from sage.data_structures.bitset import test_bitset_pop
2321
+ sage: test_bitset_pop('0101')
2322
+ a.pop() 1
2323
+ new set: 0001
2324
+ sage: test_bitset_pop('0000')
2325
+ Traceback (most recent call last):
2326
+ ...
2327
+ KeyError: 'pop from an empty set'
2328
+ """
2329
+ cdef bitset_t a
2330
+ bitset_from_str(a, py_a)
2331
+ i = bitset_pop(a)
2332
+ print("a.pop() ", i)
2333
+ print("new set: ", bitset_string(a))
2334
+ bitset_free(a)
2335
+
2336
+
2337
+ def test_bitset_unpickle(data):
2338
+ """
2339
+ This (artificially) tests pickling of bitsets across systems.
2340
+
2341
+ INPUT:
2342
+
2343
+ - ``data`` -- tuple of data as would be produced by the internal,
2344
+ Cython-only, method ``bitset_pickle``
2345
+
2346
+ OUTPUT: list form of the bitset corresponding to the pickled data
2347
+
2348
+ EXAMPLES:
2349
+
2350
+ We compare 64-bit and 32-bit encoding. Both should unpickle on any system::
2351
+
2352
+ sage: from sage.data_structures.bitset import test_bitset_unpickle
2353
+ sage: test_bitset_unpickle((0, 100, 2, 8, (33, 6001)))
2354
+ [0, 5, 64, 68, 69, 70, 72, 73, 74, 76]
2355
+ sage: test_bitset_unpickle((0, 100, 4, 4, (33, 0, 6001, 0)))
2356
+ [0, 5, 64, 68, 69, 70, 72, 73, 74, 76]
2357
+ """
2358
+ cdef bitset_t bs
2359
+ bitset_init(bs, 1)
2360
+ bitset_unpickle(bs, data)
2361
+ L = bitset_list(bs)
2362
+ bitset_free(bs)
2363
+ return L
2364
+
2365
+
2366
+ def test_bitset_copy_flex(py_a):
2367
+ """
2368
+ TESTS:
2369
+
2370
+ Check that :issue:`33012` is fixed::
2371
+
2372
+ sage: from sage.data_structures.bitset import test_bitset_copy_flex
2373
+ sage: test_bitset_copy_flex('0101'*100)
2374
+ """
2375
+ cdef bitset_t a, b
2376
+
2377
+ bitset_from_str(a, py_a)
2378
+ bitset_init(b, a.size*2)
2379
+
2380
+ bitset_copy_flex(b, a)
2381
+ if not bitset_list(b) == bitset_list(a):
2382
+ raise ValueError
2383
+
2384
+ bitset_free(a)
2385
+ bitset_free(b)