passagemath-objects 10.6.47__cp311-cp311-macosx_13_0_x86_64.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 (280) hide show
  1. passagemath_objects/.dylibs/libgmp.10.dylib +0 -0
  2. passagemath_objects/__init__.py +3 -0
  3. passagemath_objects-10.6.47.dist-info/METADATA +115 -0
  4. passagemath_objects-10.6.47.dist-info/RECORD +280 -0
  5. passagemath_objects-10.6.47.dist-info/WHEEL +6 -0
  6. passagemath_objects-10.6.47.dist-info/top_level.txt +3 -0
  7. sage/all__sagemath_objects.py +37 -0
  8. sage/arith/all__sagemath_objects.py +5 -0
  9. sage/arith/long.pxd +411 -0
  10. sage/arith/numerical_approx.cpython-311-darwin.so +0 -0
  11. sage/arith/numerical_approx.pxd +35 -0
  12. sage/arith/numerical_approx.pyx +75 -0
  13. sage/arith/power.cpython-311-darwin.so +0 -0
  14. sage/arith/power.pxd +31 -0
  15. sage/arith/power.pyx +127 -0
  16. sage/categories/action.cpython-311-darwin.so +0 -0
  17. sage/categories/action.pxd +29 -0
  18. sage/categories/action.pyx +641 -0
  19. sage/categories/algebra_functor.py +745 -0
  20. sage/categories/all__sagemath_objects.py +33 -0
  21. sage/categories/basic.py +62 -0
  22. sage/categories/cartesian_product.py +295 -0
  23. sage/categories/category.py +3401 -0
  24. sage/categories/category_cy_helper.cpython-311-darwin.so +0 -0
  25. sage/categories/category_cy_helper.pxd +8 -0
  26. sage/categories/category_cy_helper.pyx +322 -0
  27. sage/categories/category_singleton.cpython-311-darwin.so +0 -0
  28. sage/categories/category_singleton.pxd +3 -0
  29. sage/categories/category_singleton.pyx +342 -0
  30. sage/categories/category_types.py +637 -0
  31. sage/categories/category_with_axiom.py +2876 -0
  32. sage/categories/covariant_functorial_construction.py +703 -0
  33. sage/categories/facade_sets.py +228 -0
  34. sage/categories/functor.cpython-311-darwin.so +0 -0
  35. sage/categories/functor.pxd +7 -0
  36. sage/categories/functor.pyx +691 -0
  37. sage/categories/homset.py +1338 -0
  38. sage/categories/homsets.py +364 -0
  39. sage/categories/isomorphic_objects.py +73 -0
  40. sage/categories/map.cpython-311-darwin.so +0 -0
  41. sage/categories/map.pxd +34 -0
  42. sage/categories/map.pyx +2106 -0
  43. sage/categories/morphism.cpython-311-darwin.so +0 -0
  44. sage/categories/morphism.pxd +14 -0
  45. sage/categories/morphism.pyx +895 -0
  46. sage/categories/objects.py +167 -0
  47. sage/categories/primer.py +1696 -0
  48. sage/categories/pushout.py +4834 -0
  49. sage/categories/quotients.py +64 -0
  50. sage/categories/realizations.py +200 -0
  51. sage/categories/sets_cat.py +3290 -0
  52. sage/categories/sets_with_partial_maps.py +52 -0
  53. sage/categories/subobjects.py +64 -0
  54. sage/categories/subquotients.py +21 -0
  55. sage/categories/with_realizations.py +311 -0
  56. sage/cpython/__init__.py +19 -0
  57. sage/cpython/_py2_random.py +619 -0
  58. sage/cpython/all.py +3 -0
  59. sage/cpython/atexit.cpython-311-darwin.so +0 -0
  60. sage/cpython/atexit.pyx +269 -0
  61. sage/cpython/builtin_types.cpython-311-darwin.so +0 -0
  62. sage/cpython/builtin_types.pyx +7 -0
  63. sage/cpython/cython_metaclass.cpython-311-darwin.so +0 -0
  64. sage/cpython/cython_metaclass.h +117 -0
  65. sage/cpython/cython_metaclass.pxd +3 -0
  66. sage/cpython/cython_metaclass.pyx +130 -0
  67. sage/cpython/debug.cpython-311-darwin.so +0 -0
  68. sage/cpython/debug.pyx +302 -0
  69. sage/cpython/dict_del_by_value.cpython-311-darwin.so +0 -0
  70. sage/cpython/dict_del_by_value.pxd +9 -0
  71. sage/cpython/dict_del_by_value.pyx +191 -0
  72. sage/cpython/dict_internal.h +245 -0
  73. sage/cpython/getattr.cpython-311-darwin.so +0 -0
  74. sage/cpython/getattr.pxd +9 -0
  75. sage/cpython/getattr.pyx +439 -0
  76. sage/cpython/pycore_long.h +97 -0
  77. sage/cpython/pycore_long.pxd +10 -0
  78. sage/cpython/python_debug.h +44 -0
  79. sage/cpython/python_debug.pxd +47 -0
  80. sage/cpython/pyx_visit.h +13 -0
  81. sage/cpython/string.cpython-311-darwin.so +0 -0
  82. sage/cpython/string.pxd +76 -0
  83. sage/cpython/string.pyx +34 -0
  84. sage/cpython/string_impl.h +60 -0
  85. sage/cpython/type.cpython-311-darwin.so +0 -0
  86. sage/cpython/type.pxd +2 -0
  87. sage/cpython/type.pyx +40 -0
  88. sage/cpython/wrapperdescr.pxd +67 -0
  89. sage/ext/all__sagemath_objects.py +3 -0
  90. sage/ext/ccobject.h +64 -0
  91. sage/ext/cplusplus.pxd +17 -0
  92. sage/ext/mod_int.h +30 -0
  93. sage/ext/mod_int.pxd +24 -0
  94. sage/ext/stdsage.pxd +39 -0
  95. sage/groups/all__sagemath_objects.py +1 -0
  96. sage/groups/group.cpython-311-darwin.so +0 -0
  97. sage/groups/group.pxd +14 -0
  98. sage/groups/group.pyx +322 -0
  99. sage/groups/old.cpython-311-darwin.so +0 -0
  100. sage/groups/old.pxd +14 -0
  101. sage/groups/old.pyx +219 -0
  102. sage/libs/all__sagemath_objects.py +3 -0
  103. sage/libs/gmp/__init__.py +1 -0
  104. sage/libs/gmp/all.pxd +6 -0
  105. sage/libs/gmp/binop.pxd +23 -0
  106. sage/libs/gmp/misc.pxd +8 -0
  107. sage/libs/gmp/mpf.pxd +88 -0
  108. sage/libs/gmp/mpn.pxd +57 -0
  109. sage/libs/gmp/mpq.pxd +57 -0
  110. sage/libs/gmp/mpz.pxd +202 -0
  111. sage/libs/gmp/pylong.cpython-311-darwin.so +0 -0
  112. sage/libs/gmp/pylong.pxd +12 -0
  113. sage/libs/gmp/pylong.pyx +150 -0
  114. sage/libs/gmp/random.pxd +25 -0
  115. sage/libs/gmp/randomize.pxd +59 -0
  116. sage/libs/gmp/types.pxd +53 -0
  117. sage/libs/gmpxx.pxd +19 -0
  118. sage/misc/abstract_method.py +276 -0
  119. sage/misc/all__sagemath_objects.py +43 -0
  120. sage/misc/bindable_class.py +253 -0
  121. sage/misc/c3_controlled.cpython-311-darwin.so +0 -0
  122. sage/misc/c3_controlled.pxd +2 -0
  123. sage/misc/c3_controlled.pyx +1402 -0
  124. sage/misc/cachefunc.cpython-311-darwin.so +0 -0
  125. sage/misc/cachefunc.pxd +43 -0
  126. sage/misc/cachefunc.pyx +3781 -0
  127. sage/misc/call.py +188 -0
  128. sage/misc/classcall_metaclass.cpython-311-darwin.so +0 -0
  129. sage/misc/classcall_metaclass.pxd +14 -0
  130. sage/misc/classcall_metaclass.pyx +599 -0
  131. sage/misc/constant_function.cpython-311-darwin.so +0 -0
  132. sage/misc/constant_function.pyx +130 -0
  133. sage/misc/decorators.py +747 -0
  134. sage/misc/fast_methods.cpython-311-darwin.so +0 -0
  135. sage/misc/fast_methods.pxd +20 -0
  136. sage/misc/fast_methods.pyx +351 -0
  137. sage/misc/flatten.py +90 -0
  138. sage/misc/fpickle.cpython-311-darwin.so +0 -0
  139. sage/misc/fpickle.pyx +177 -0
  140. sage/misc/function_mangling.cpython-311-darwin.so +0 -0
  141. sage/misc/function_mangling.pxd +11 -0
  142. sage/misc/function_mangling.pyx +308 -0
  143. sage/misc/inherit_comparison.cpython-311-darwin.so +0 -0
  144. sage/misc/inherit_comparison.pxd +5 -0
  145. sage/misc/inherit_comparison.pyx +105 -0
  146. sage/misc/instancedoc.cpython-311-darwin.so +0 -0
  147. sage/misc/instancedoc.pyx +331 -0
  148. sage/misc/lazy_attribute.cpython-311-darwin.so +0 -0
  149. sage/misc/lazy_attribute.pyx +607 -0
  150. sage/misc/lazy_format.py +135 -0
  151. sage/misc/lazy_import.cpython-311-darwin.so +0 -0
  152. sage/misc/lazy_import.pyx +1299 -0
  153. sage/misc/lazy_import_cache.py +36 -0
  154. sage/misc/lazy_list.cpython-311-darwin.so +0 -0
  155. sage/misc/lazy_list.pxd +19 -0
  156. sage/misc/lazy_list.pyx +1187 -0
  157. sage/misc/lazy_string.cpython-311-darwin.so +0 -0
  158. sage/misc/lazy_string.pxd +7 -0
  159. sage/misc/lazy_string.pyx +546 -0
  160. sage/misc/misc.py +1066 -0
  161. sage/misc/misc_c.cpython-311-darwin.so +0 -0
  162. sage/misc/misc_c.pxd +3 -0
  163. sage/misc/misc_c.pyx +766 -0
  164. sage/misc/namespace_package.py +37 -0
  165. sage/misc/nested_class.cpython-311-darwin.so +0 -0
  166. sage/misc/nested_class.pxd +3 -0
  167. sage/misc/nested_class.pyx +394 -0
  168. sage/misc/persist.cpython-311-darwin.so +0 -0
  169. sage/misc/persist.pyx +1251 -0
  170. sage/misc/prandom.py +418 -0
  171. sage/misc/randstate.cpython-311-darwin.so +0 -0
  172. sage/misc/randstate.pxd +30 -0
  173. sage/misc/randstate.pyx +1059 -0
  174. sage/misc/repr.py +203 -0
  175. sage/misc/reset.cpython-311-darwin.so +0 -0
  176. sage/misc/reset.pyx +196 -0
  177. sage/misc/sage_ostools.cpython-311-darwin.so +0 -0
  178. sage/misc/sage_ostools.pyx +323 -0
  179. sage/misc/sage_timeit.py +275 -0
  180. sage/misc/sage_timeit_class.cpython-311-darwin.so +0 -0
  181. sage/misc/sage_timeit_class.pyx +120 -0
  182. sage/misc/sage_unittest.py +637 -0
  183. sage/misc/sageinspect.py +2768 -0
  184. sage/misc/session.cpython-311-darwin.so +0 -0
  185. sage/misc/session.pyx +392 -0
  186. sage/misc/superseded.py +557 -0
  187. sage/misc/test_nested_class.py +228 -0
  188. sage/misc/timing.py +264 -0
  189. sage/misc/unknown.py +222 -0
  190. sage/misc/verbose.py +253 -0
  191. sage/misc/weak_dict.cpython-311-darwin.so +0 -0
  192. sage/misc/weak_dict.pxd +15 -0
  193. sage/misc/weak_dict.pyx +1231 -0
  194. sage/modules/all__sagemath_objects.py +1 -0
  195. sage/modules/module.cpython-311-darwin.so +0 -0
  196. sage/modules/module.pxd +5 -0
  197. sage/modules/module.pyx +329 -0
  198. sage/rings/all__sagemath_objects.py +3 -0
  199. sage/rings/integer_fake.h +22 -0
  200. sage/rings/integer_fake.pxd +55 -0
  201. sage/sets/all__sagemath_objects.py +3 -0
  202. sage/sets/pythonclass.cpython-311-darwin.so +0 -0
  203. sage/sets/pythonclass.pxd +9 -0
  204. sage/sets/pythonclass.pyx +247 -0
  205. sage/structure/__init__.py +4 -0
  206. sage/structure/all.py +30 -0
  207. sage/structure/category_object.cpython-311-darwin.so +0 -0
  208. sage/structure/category_object.pxd +28 -0
  209. sage/structure/category_object.pyx +1087 -0
  210. sage/structure/coerce.cpython-311-darwin.so +0 -0
  211. sage/structure/coerce.pxd +44 -0
  212. sage/structure/coerce.pyx +2107 -0
  213. sage/structure/coerce_actions.cpython-311-darwin.so +0 -0
  214. sage/structure/coerce_actions.pxd +27 -0
  215. sage/structure/coerce_actions.pyx +988 -0
  216. sage/structure/coerce_dict.cpython-311-darwin.so +0 -0
  217. sage/structure/coerce_dict.pxd +51 -0
  218. sage/structure/coerce_dict.pyx +1557 -0
  219. sage/structure/coerce_exceptions.py +23 -0
  220. sage/structure/coerce_maps.cpython-311-darwin.so +0 -0
  221. sage/structure/coerce_maps.pxd +28 -0
  222. sage/structure/coerce_maps.pyx +718 -0
  223. sage/structure/debug_options.cpython-311-darwin.so +0 -0
  224. sage/structure/debug_options.pxd +6 -0
  225. sage/structure/debug_options.pyx +54 -0
  226. sage/structure/dynamic_class.py +541 -0
  227. sage/structure/element.cpython-311-darwin.so +0 -0
  228. sage/structure/element.pxd +272 -0
  229. sage/structure/element.pyx +4772 -0
  230. sage/structure/element_wrapper.cpython-311-darwin.so +0 -0
  231. sage/structure/element_wrapper.pxd +12 -0
  232. sage/structure/element_wrapper.pyx +582 -0
  233. sage/structure/factorization.py +1422 -0
  234. sage/structure/factorization_integer.py +105 -0
  235. sage/structure/factory.cpython-311-darwin.so +0 -0
  236. sage/structure/factory.pyx +786 -0
  237. sage/structure/formal_sum.py +489 -0
  238. sage/structure/gens_py.py +73 -0
  239. sage/structure/global_options.py +1743 -0
  240. sage/structure/indexed_generators.py +863 -0
  241. sage/structure/list_clone.cpython-311-darwin.so +0 -0
  242. sage/structure/list_clone.pxd +65 -0
  243. sage/structure/list_clone.pyx +1867 -0
  244. sage/structure/list_clone_demo.cpython-311-darwin.so +0 -0
  245. sage/structure/list_clone_demo.pyx +248 -0
  246. sage/structure/list_clone_timings.py +179 -0
  247. sage/structure/list_clone_timings_cy.cpython-311-darwin.so +0 -0
  248. sage/structure/list_clone_timings_cy.pyx +86 -0
  249. sage/structure/mutability.cpython-311-darwin.so +0 -0
  250. sage/structure/mutability.pxd +21 -0
  251. sage/structure/mutability.pyx +348 -0
  252. sage/structure/nonexact.py +69 -0
  253. sage/structure/parent.cpython-311-darwin.so +0 -0
  254. sage/structure/parent.pxd +112 -0
  255. sage/structure/parent.pyx +3093 -0
  256. sage/structure/parent_base.cpython-311-darwin.so +0 -0
  257. sage/structure/parent_base.pxd +13 -0
  258. sage/structure/parent_base.pyx +44 -0
  259. sage/structure/parent_gens.cpython-311-darwin.so +0 -0
  260. sage/structure/parent_gens.pxd +22 -0
  261. sage/structure/parent_gens.pyx +377 -0
  262. sage/structure/parent_old.cpython-311-darwin.so +0 -0
  263. sage/structure/parent_old.pxd +25 -0
  264. sage/structure/parent_old.pyx +294 -0
  265. sage/structure/proof/__init__.py +1 -0
  266. sage/structure/proof/all.py +243 -0
  267. sage/structure/proof/proof.py +300 -0
  268. sage/structure/richcmp.cpython-311-darwin.so +0 -0
  269. sage/structure/richcmp.pxd +213 -0
  270. sage/structure/richcmp.pyx +495 -0
  271. sage/structure/sage_object.cpython-311-darwin.so +0 -0
  272. sage/structure/sage_object.pxd +3 -0
  273. sage/structure/sage_object.pyx +988 -0
  274. sage/structure/sage_object_test.py +19 -0
  275. sage/structure/sequence.py +937 -0
  276. sage/structure/set_factories.py +1178 -0
  277. sage/structure/set_factories_example.py +527 -0
  278. sage/structure/support_view.py +179 -0
  279. sage/structure/test_factory.py +56 -0
  280. sage/structure/unique_representation.py +1359 -0
sage/libs/gmp/mpf.pxd ADDED
@@ -0,0 +1,88 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ # distutils: libraries = gmp
3
+
4
+ from sage.libs.gmp.types cimport *
5
+
6
+ cdef extern from "gmp.h":
7
+
8
+ ### Floating-point Functions ###
9
+
10
+ # Initialization Functions
11
+ void mpf_set_default_prec (unsigned long int prec)
12
+ unsigned long int mpf_get_default_prec ()
13
+ void mpf_init (mpf_t x)
14
+ void mpf_init2 (mpf_t x, unsigned long int prec)
15
+ void mpf_clear (mpf_t x)
16
+ unsigned long int mpf_get_prec (mpf_t op)
17
+ void mpf_set_prec (mpf_t rop, unsigned long int prec)
18
+ void mpf_set_prec_raw (mpf_t rop, unsigned long int prec)
19
+
20
+ # Assignment Functions
21
+ void mpf_set (mpf_t rop, mpf_t op)
22
+ void mpf_set_ui (mpf_t rop, unsigned long int op)
23
+ void mpf_set_si (mpf_t rop, signed long int op)
24
+ void mpf_set_d (mpf_t rop, double op)
25
+ void mpf_set_z (mpf_t rop, mpz_t op)
26
+ void mpf_set_q (mpf_t rop, mpq_t op)
27
+ int mpf_set_str (mpf_t rop, char *str, int base)
28
+ void mpf_swap (mpf_t rop1, mpf_t rop2)
29
+
30
+ # Combined Initialization and Assignment Functions
31
+ void mpf_init_set (mpf_t rop, mpf_t op)
32
+ void mpf_init_set_ui (mpf_t rop, unsigned long int op)
33
+ void mpf_init_set_si (mpf_t rop, signed long int op)
34
+ void mpf_init_set_d (mpf_t rop, double op)
35
+ int mpf_init_set_str (mpf_t rop, char *str, int base)
36
+
37
+ # Conversion Functions
38
+ double mpf_get_d (mpf_t op)
39
+ double mpf_get_d_2exp (signed long int *exp, mpf_t op)
40
+ long mpf_get_si (mpf_t op)
41
+ unsigned long mpf_get_ui (mpf_t op)
42
+ char * mpf_get_str (char *str, mp_exp_t *expptr, int base, size_t n_digits, mpf_t op)
43
+
44
+ # Arithmetic Functions
45
+ void mpf_add (mpf_t rop, mpf_t op1, mpf_t op2)
46
+ void mpf_add_ui (mpf_t rop, mpf_t op1, unsigned long int op2)
47
+ void mpf_sub (mpf_t rop, mpf_t op1, mpf_t op2)
48
+ void mpf_ui_sub (mpf_t rop, unsigned long int op1, mpf_t op2)
49
+ void mpf_sub_ui (mpf_t rop, mpf_t op1, unsigned long int op2)
50
+ void mpf_mul (mpf_t rop, mpf_t op1, mpf_t op2)
51
+ void mpf_mul_ui (mpf_t rop, mpf_t op1, unsigned long int op2)
52
+ void mpf_div (mpf_t rop, mpf_t op1, mpf_t op2)
53
+ void mpf_ui_div (mpf_t rop, unsigned long int op1, mpf_t op2)
54
+ void mpf_div_ui (mpf_t rop, mpf_t op1, unsigned long int op2)
55
+ void mpf_sqrt (mpf_t rop, mpf_t op)
56
+ void mpf_sqrt_ui (mpf_t rop, unsigned long int op)
57
+ void mpf_pow_ui (mpf_t rop, mpf_t op1, unsigned long int op2)
58
+ void mpf_neg (mpf_t rop, mpf_t op)
59
+ void mpf_abs (mpf_t rop, mpf_t op)
60
+ void mpf_mul_2exp (mpf_t rop, mpf_t op1, unsigned long int op2)
61
+ void mpf_div_2exp (mpf_t rop, mpf_t op1, unsigned long int op2)
62
+
63
+ # Comparison Functions
64
+ int mpf_cmp (mpf_t op1, mpf_t op2)
65
+ int mpf_cmp_d (mpf_t op1, double op2)
66
+ int mpf_cmp_ui (mpf_t op1, unsigned long int op2)
67
+ int mpf_cmp_si (mpf_t op1, signed long int op2)
68
+ int mpf_eq (mpf_t op1, mpf_t op2, unsigned long int op3)
69
+ void mpf_reldiff (mpf_t rop, mpf_t op1, mpf_t op2)
70
+ int mpf_sgn (mpf_t op)
71
+
72
+ # Input and Output Functions
73
+ # size_t mpf_out_str (file *stream, int base, size_t n_digits, mpf_t op)
74
+ # size_t mpf_inp_str (mpf_t rop, file *stream, int base)
75
+
76
+ # Miscellaneous Functions
77
+ void mpf_ceil (mpf_t rop, mpf_t op)
78
+ void mpf_floor (mpf_t rop, mpf_t op)
79
+ void mpf_trunc (mpf_t rop, mpf_t op)
80
+ bint mpf_integer_p (mpf_t op)
81
+ bint mpf_fits_ulong_p (mpf_t op)
82
+ bint mpf_fits_slong_p (mpf_t op)
83
+ bint mpf_fits_uint_p (mpf_t op)
84
+ bint mpf_fits_sint_p (mpf_t op)
85
+ bint mpf_fits_ushort_p (mpf_t op)
86
+ bint mpf_fits_sshort_p (mpf_t op)
87
+ void mpf_urandomb (mpf_t rop, gmp_randstate_t state, unsigned long int nbits)
88
+ void mpf_random2 (mpf_t rop, mp_size_t max_size, mp_exp_t exp)
sage/libs/gmp/mpn.pxd ADDED
@@ -0,0 +1,57 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ # distutils: libraries = gmp
3
+
4
+ from sage.libs.gmp.types cimport *
5
+
6
+ cdef extern from "gmp.h":
7
+
8
+ ### Low-level Functions ###
9
+
10
+ mp_limb_t mpn_add_n (mp_limb_t *rp, mp_limb_t *s1p, mp_limb_t *s2p, mp_size_t n)
11
+ mp_limb_t mpn_add_1 (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t n, mp_limb_t s2limb)
12
+ mp_limb_t mpn_add (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t s1n, mp_limb_t *s2p, mp_size_t s2n)
13
+ mp_limb_t mpn_sub_n (mp_limb_t *rp, mp_limb_t *s1p, mp_limb_t *s2p, mp_size_t n)
14
+ mp_limb_t mpn_sub_1 (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t n, mp_limb_t s2limb)
15
+ mp_limb_t mpn_sub (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t s1n, mp_limb_t *s2p, mp_size_t s2n)
16
+ void mpn_mul_n (mp_limb_t *rp, mp_limb_t *s1p, mp_limb_t *s2p, mp_size_t n)
17
+ mp_limb_t mpn_mul_1 (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t n, mp_limb_t s2limb)
18
+ mp_limb_t mpn_addmul_1 (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t n, mp_limb_t s2limb)
19
+ mp_limb_t mpn_submul_1 (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t n, mp_limb_t s2limb)
20
+ mp_limb_t mpn_mul (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t s1n, mp_limb_t *s2p, mp_size_t s2n)
21
+ void mpn_tdiv_qr (mp_limb_t *qp, mp_limb_t *rp, mp_size_t qxn, mp_limb_t *np, mp_size_t nn, mp_limb_t *dp, mp_size_t dn)
22
+ mp_limb_t mpn_divrem (mp_limb_t *r1p, mp_size_t qxn, mp_limb_t *rs2p, mp_size_t rs2n, mp_limb_t *s3p, mp_size_t s3n)
23
+ mp_limb_t mpn_divrem_1 (mp_limb_t *r1p, mp_size_t qxn, mp_limb_t *s2p, mp_size_t s2n, mp_limb_t s3limb)
24
+ mp_limb_t mpn_divmod_1 (mp_limb_t *r1p, mp_limb_t *s2p, mp_size_t s2n, mp_limb_t s3limb)
25
+ mp_limb_t mpn_divmod (mp_limb_t *r1p, mp_limb_t *rs2p, mp_size_t rs2n, mp_limb_t *s3p, mp_size_t s3n)
26
+ mp_limb_t mpn_divexact_by3 (mp_limb_t *rp, mp_limb_t *sp, mp_size_t n)
27
+ mp_limb_t mpn_divexact_by3c (mp_limb_t *rp, mp_limb_t *sp, mp_size_t n, mp_limb_t carry)
28
+ mp_limb_t mpn_mod_1 (mp_limb_t *s1p, mp_size_t s1n, mp_limb_t s2limb)
29
+ mp_limb_t mpn_bdivmod (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t s1n, mp_limb_t *s2p, mp_size_t s2n, unsigned long int d)
30
+ mp_limb_t mpn_lshift (mp_limb_t *rp, mp_limb_t *sp, mp_size_t n, unsigned int count)
31
+ mp_limb_t mpn_rshift (mp_limb_t *rp, mp_limb_t *sp, mp_size_t n, unsigned int count)
32
+ int mpn_cmp (mp_limb_t *s1p, mp_limb_t *s2p, mp_size_t n)
33
+ mp_size_t mpn_gcd (mp_limb_t *rp, mp_limb_t *s1p, mp_size_t s1n, mp_limb_t *s2p, mp_size_t s2n)
34
+ mp_limb_t mpn_gcd_1 (mp_limb_t *s1p, mp_size_t s1n, mp_limb_t s2limb)
35
+ mp_size_t mpn_gcdext (mp_limb_t *r1p, mp_limb_t *r2p, mp_size_t *r2n, mp_limb_t *s1p, mp_size_t s1n, mp_limb_t *s2p, mp_size_t s2n)
36
+ mp_size_t mpn_sqrtrem (mp_limb_t *r1p, mp_limb_t *r2p, mp_limb_t *sp, mp_size_t n)
37
+ mp_size_t mpn_get_str (unsigned char *str, int base, mp_limb_t *s1p, mp_size_t s1n)
38
+ mp_size_t mpn_set_str (mp_limb_t *rp, unsigned char *str, size_t strsize, int base)
39
+ unsigned long int mpn_scan0 (mp_limb_t *s1p, unsigned long int bit)
40
+ unsigned long int mpn_scan1 (mp_limb_t *s1p, unsigned long int bit)
41
+ void mpn_random (mp_limb_t *r1p, mp_size_t r1n)
42
+ void mpn_random2 (mp_limb_t *r1p, mp_size_t r1n)
43
+ unsigned long int mpn_popcount (mp_limb_t *s1p, mp_size_t n)
44
+ unsigned long int mpn_hamdist (mp_limb_t *s1p, mp_limb_t *s2p, mp_size_t n)
45
+ int mpn_perfect_square_p (mp_limb_t *s1p, mp_size_t n)
46
+ void mpn_and_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
47
+ void mpn_andn_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
48
+ void mpn_nand_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
49
+ void mpn_ior_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
50
+ void mpn_iorn_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
51
+ void mpn_nior_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
52
+ void mpn_xor_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
53
+ void mpn_xnor_n(mp_ptr rp, mp_srcptr s1p, mp_srcptr s2p, mp_size_t n)
54
+ void mpn_com(mp_ptr rp, mp_srcptr sp, mp_size_t n)
55
+ void mpn_copyi(mp_ptr rp, mp_srcptr s1p, mp_size_t n)
56
+ void mpn_copyd(mp_ptr rp, mp_srcptr s1p, mp_size_t n)
57
+ void mpn_zero(mp_ptr rp, mp_size_t n)
sage/libs/gmp/mpq.pxd ADDED
@@ -0,0 +1,57 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ # distutils: libraries = gmp
3
+
4
+ from sage.libs.gmp.types cimport *
5
+
6
+ cdef extern from "gmp.h":
7
+
8
+ ### Rational Functions ###
9
+
10
+ void mpq_canonicalize (mpq_t op)
11
+
12
+ # Initialization and Assignment Functions
13
+ void mpq_init (mpq_t dest_rational)
14
+ void mpq_clear (mpq_t rational_number)
15
+ void mpq_set (mpq_t rop, mpq_t op)
16
+ void mpq_set_z (mpq_t rop, mpz_t op)
17
+ void mpq_set_ui (mpq_t rop, unsigned long int op1, unsigned long int op2)
18
+ void mpq_set_si (mpq_t rop, signed long int op1, unsigned long int op2)
19
+ int mpq_set_str (mpq_t rop, char *str, int base)
20
+ void mpq_swap (mpq_t rop1, mpq_t rop2)
21
+
22
+ # Conversion Functions
23
+ double mpq_get_d (mpq_t op)
24
+ void mpq_set_d (mpq_t rop, double op)
25
+ void mpq_set_f (mpq_t rop, mpf_t op)
26
+ char * mpq_get_str (char *str, int base, mpq_t op)
27
+
28
+ # Arithmetic Functions
29
+ void mpq_add (mpq_t sum, mpq_t addend1, mpq_t addend2)
30
+ void mpq_sub (mpq_t difference, mpq_t minuend, mpq_t subtrahend)
31
+ void mpq_mul (mpq_t product, mpq_t multiplier, mpq_t multiplicand)
32
+ void mpq_mul_2exp (mpq_t rop, mpq_t op1, unsigned long int op2)
33
+ void mpq_div (mpq_t quotient, mpq_t dividend, mpq_t divisor)
34
+ void mpq_div_2exp (mpq_t rop, mpq_t op1, unsigned long int op2)
35
+ void mpq_neg (mpq_t negated_operand, mpq_t operand)
36
+ void mpq_abs (mpq_t rop, mpq_t op)
37
+ void mpq_inv (mpq_t inverted_number, mpq_t number)
38
+
39
+ # Comparison Functions
40
+ int mpq_cmp (mpq_t op1, mpq_t op2)
41
+ int mpq_cmp_ui (mpq_t op1, unsigned long int num2, unsigned long int den2)
42
+ int mpq_cmp_si (mpq_t op1, long int num2, unsigned long int den2)
43
+ int mpq_cmp_z (const mpq_t op1, const mpz_t op2)
44
+ int mpq_sgn (mpq_t op)
45
+ int mpq_equal (mpq_t op1, mpq_t op2)
46
+
47
+ # Applying Integer Functions to Rationals
48
+ mpz_t mpq_numref (mpq_t op)
49
+ mpz_t mpq_denref (mpq_t op)
50
+ void mpq_get_num (mpz_t numerator, mpq_t rational)
51
+ void mpq_get_den (mpz_t denominator, mpq_t rational)
52
+ void mpq_set_num (mpq_t rational, mpz_t numerator)
53
+ void mpq_set_den (mpq_t rational, mpz_t denominator)
54
+
55
+ # Input and Output Functions
56
+ # size_t mpq_out_str (file *stream, int base, mpq_t op)
57
+ # size_t mpq_inp_str (mpq_t rop, file *stream, int base)
sage/libs/gmp/mpz.pxd ADDED
@@ -0,0 +1,202 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ # distutils: libraries = gmp
3
+
4
+ from sage.libs.gmp.types cimport *
5
+ from libc.stdio cimport FILE
6
+
7
+ from libc.stdint cimport intmax_t, uintmax_t
8
+
9
+ cdef extern from "gmp.h":
10
+
11
+ ### Integer Functions ###
12
+
13
+ # Initialization Functions
14
+ void mpz_init (mpz_t integer)
15
+ void mpz_init2 (mpz_t integer, unsigned long n)
16
+ void mpz_clear (mpz_t integer)
17
+ void mpz_realloc2 (mpz_t integer, unsigned long n)
18
+
19
+ # Assignment Functions
20
+ void mpz_set (mpz_t rop, mpz_t op)
21
+ void mpz_set_ui (mpz_t rop, unsigned long int op)
22
+ void mpz_set_si (mpz_t rop, signed long int op)
23
+ void mpz_set_ux (mpz_t rop, uintmax_t op)
24
+ void mpz_set_sx (mpz_t rop, intmax_t op)
25
+ void mpz_set_d (mpz_t rop, double op)
26
+ void mpz_set_q (mpz_t rop, mpq_t op)
27
+ void mpz_set_f (mpz_t rop, mpf_t op)
28
+ int mpz_set_str (mpz_t rop, char *str, int base)
29
+ void mpz_swap (mpz_t rop1, mpz_t rop2)
30
+
31
+ # Combined Initialization and Assignment Functions
32
+ void mpz_init_set (mpz_t rop, mpz_t op)
33
+ void mpz_init_set_ui (mpz_t rop, unsigned long int op)
34
+ void mpz_init_set_si (mpz_t rop, signed long int op)
35
+ void mpz_init_set_ux (mpz_t rop, uintmax_t op)
36
+ void mpz_init_set_sx (mpz_t rop, intmax_t op)
37
+ void mpz_init_set_d (mpz_t rop, double op)
38
+ int mpz_init_set_str (mpz_t rop, char *str, int base)
39
+
40
+ # Conversion Functions
41
+ unsigned long int mpz_get_ui (mpz_t op)
42
+ signed long int mpz_get_si (mpz_t op)
43
+ uintmax_t mpz_get_ux (mpz_t op)
44
+ intmax_t mpz_get_sx (mpz_t op)
45
+ double mpz_get_d (mpz_t op)
46
+ double mpz_get_d_2exp (long int *exp, mpz_t op)
47
+ char * mpz_get_str (char *str, int base, mpz_t op)
48
+
49
+ # Arithmetic Functions
50
+ void mpz_add (mpz_t rop, mpz_t op1, mpz_t op2)
51
+ void mpz_add_ui (mpz_t rop, mpz_t op1, unsigned long int op2)
52
+ void mpz_sub (mpz_t rop, mpz_t op1, mpz_t op2)
53
+ void mpz_sub_ui (mpz_t rop, mpz_t op1, unsigned long int op2)
54
+ void mpz_ui_sub (mpz_t rop, unsigned long int op1, mpz_t op2)
55
+ void mpz_mul (mpz_t rop, mpz_t op1, mpz_t op2)
56
+ void mpz_mul_si (mpz_t rop, mpz_t op1, long int op2)
57
+ void mpz_mul_ui (mpz_t rop, mpz_t op1, unsigned long int op2)
58
+ void mpz_addmul (mpz_t rop, mpz_t op1, mpz_t op2)
59
+ void mpz_addmul_ui (mpz_t rop, mpz_t op1, unsigned long int op2)
60
+ void mpz_submul (mpz_t rop, mpz_t op1, mpz_t op2)
61
+ void mpz_submul_ui (mpz_t rop, mpz_t op1, unsigned long int op2)
62
+ void mpz_mul_2exp (mpz_t rop, mpz_t op1, unsigned long int op2)
63
+ void mpz_neg (mpz_t rop, mpz_t op)
64
+ void mpz_abs (mpz_t rop, mpz_t op)
65
+
66
+ # Division Functions
67
+ void mpz_cdiv_q (mpz_t q, mpz_t n, mpz_t d)
68
+ void mpz_cdiv_r (mpz_t r, mpz_t n, mpz_t d)
69
+ void mpz_cdiv_qr (mpz_t q, mpz_t r, mpz_t n, mpz_t d)
70
+ unsigned long int mpz_cdiv_q_ui (mpz_t q, mpz_t n, unsigned long int d)
71
+ unsigned long int mpz_cdiv_r_ui (mpz_t r, mpz_t n, unsigned long int d)
72
+ unsigned long int mpz_cdiv_qr_ui (mpz_t q, mpz_t r, mpz_t n, unsigned long int d)
73
+ unsigned long int mpz_cdiv_ui (mpz_t n, unsigned long int d)
74
+ void mpz_cdiv_q_2exp (mpz_t q, mpz_t n, unsigned long int b)
75
+ void mpz_cdiv_r_2exp (mpz_t r, mpz_t n, unsigned long int b)
76
+ void mpz_fdiv_q (mpz_t q, mpz_t n, mpz_t d)
77
+ void mpz_fdiv_r (mpz_t r, mpz_t n, mpz_t d)
78
+ void mpz_fdiv_qr (mpz_t q, mpz_t r, mpz_t n, mpz_t d)
79
+ unsigned long int mpz_fdiv_q_ui (mpz_t q, mpz_t n, unsigned long int d)
80
+ unsigned long int mpz_fdiv_r_ui (mpz_t r, mpz_t n, unsigned long int d)
81
+ unsigned long int mpz_fdiv_qr_ui (mpz_t q, mpz_t r, mpz_t n, unsigned long int d)
82
+ unsigned long int mpz_fdiv_ui (mpz_t n, unsigned long int d)
83
+ void mpz_fdiv_q_2exp (mpz_t q, mpz_t n, unsigned long int b)
84
+ void mpz_fdiv_r_2exp (mpz_t r, mpz_t n, unsigned long int b)
85
+ void mpz_tdiv_q (mpz_t q, mpz_t n, mpz_t d)
86
+ void mpz_tdiv_r (mpz_t r, mpz_t n, mpz_t d)
87
+ void mpz_tdiv_qr (mpz_t q, mpz_t r, mpz_t n, mpz_t d)
88
+ unsigned long int mpz_tdiv_q_ui (mpz_t q, mpz_t n, unsigned long int d)
89
+ unsigned long int mpz_tdiv_r_ui (mpz_t r, mpz_t n, unsigned long int d)
90
+ unsigned long int mpz_tdiv_qr_ui (mpz_t q, mpz_t r, mpz_t n, unsigned long int d)
91
+ unsigned long int mpz_tdiv_ui (mpz_t n, unsigned long int d)
92
+ void mpz_tdiv_q_2exp (mpz_t q, mpz_t n, unsigned long int b)
93
+ void mpz_tdiv_r_2exp (mpz_t r, mpz_t n, unsigned long int b)
94
+ void mpz_mod (mpz_t r, mpz_t n, mpz_t d)
95
+ unsigned long int mpz_mod_ui (mpz_t r, mpz_t n, unsigned long int d)
96
+ void mpz_divexact (mpz_t q, mpz_t n, mpz_t d)
97
+ void mpz_divexact_ui (mpz_t q, mpz_t n, unsigned long d)
98
+ bint mpz_divisible_p (mpz_t n, mpz_t d)
99
+ bint mpz_divisible_ui_p (mpz_t n, unsigned long int d)
100
+ bint mpz_divisible_2exp_p (mpz_t n, unsigned long int b)
101
+ bint mpz_congruent_p (mpz_t n, mpz_t c, mpz_t d)
102
+ bint mpz_congruent_ui_p (mpz_t n, unsigned long int c, unsigned long int d)
103
+ bint mpz_congruent_2exp_p (mpz_t n, mpz_t c, unsigned long int b)
104
+
105
+ # Exponentiation Functions
106
+ void mpz_powm (mpz_t rop, mpz_t base, mpz_t exp, mpz_t mod)
107
+ void mpz_powm_ui (mpz_t rop, mpz_t base, unsigned long int exp, mpz_t mod)
108
+ void mpz_pow_ui (mpz_t rop, mpz_t base, unsigned long int exp)
109
+ void mpz_ui_pow_ui (mpz_t rop, unsigned long int base, unsigned long int exp)
110
+
111
+ # Root Extraction Functions
112
+ int mpz_root (mpz_t rop, mpz_t op, unsigned long int n)
113
+ void mpz_rootrem (mpz_t root, mpz_t rem, mpz_t u, unsigned long int n)
114
+ void mpz_sqrt (mpz_t rop, mpz_t op)
115
+ void mpz_sqrtrem (mpz_t rop1, mpz_t rop2, mpz_t op)
116
+ bint mpz_perfect_power_p (mpz_t op)
117
+ bint mpz_perfect_square_p (mpz_t op)
118
+
119
+ # Number Theoretic Functions
120
+ bint mpz_probab_prime_p (mpz_t n, int reps)
121
+ void mpz_nextprime (mpz_t rop, mpz_t op)
122
+ void mpz_gcd (mpz_t rop, mpz_t op1, mpz_t op2)
123
+ unsigned long int mpz_gcd_ui (mpz_t rop, mpz_t op1, unsigned long int op2)
124
+ void mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, mpz_t a, mpz_t b)
125
+ void mpz_lcm (mpz_t rop, mpz_t op1, mpz_t op2)
126
+ void mpz_lcm_ui (mpz_t rop, mpz_t op1, unsigned long op2)
127
+ int mpz_invert (mpz_t rop, mpz_t op1, mpz_t op2)
128
+ int mpz_jacobi (mpz_t a, mpz_t b)
129
+ int mpz_legendre (mpz_t a, mpz_t p)
130
+ int mpz_kronecker (mpz_t a, mpz_t b)
131
+ int mpz_kronecker_si (mpz_t a, long b)
132
+ int mpz_kronecker_ui (mpz_t a, unsigned long b)
133
+ int mpz_si_kronecker (long a, mpz_t b)
134
+ int mpz_ui_kronecker (unsigned long a, mpz_t b)
135
+ unsigned long int mpz_remove (mpz_t rop, mpz_t op, mpz_t f)
136
+ void mpz_fac_ui (mpz_t rop, unsigned long int op)
137
+ void mpz_2fac_ui (mpz_t rop, unsigned long int op)
138
+ void mpz_mfac_uiui (mpz_t rop, unsigned long int n, unsigned long int m)
139
+ void mpz_bin_ui (mpz_t rop, mpz_t n, unsigned long int k)
140
+ void mpz_bin_uiui (mpz_t rop, unsigned long int n, unsigned long int k)
141
+ void mpz_fib_ui (mpz_t fn, unsigned long int n)
142
+ void mpz_fib2_ui (mpz_t fn, mpz_t fnsub1, unsigned long int n)
143
+ void mpz_lucnum_ui (mpz_t ln, unsigned long int n)
144
+ void mpz_lucnum2_ui (mpz_t ln, mpz_t lnsub1, unsigned long int n)
145
+
146
+ # Comparison Functions
147
+ int mpz_cmp (mpz_t op1, mpz_t op2)
148
+ int mpz_cmp_d (mpz_t op1, double op2)
149
+ int mpz_cmp_si (mpz_t op1, signed long int op2)
150
+ int mpz_cmp_ui (mpz_t op1, unsigned long int op2)
151
+ int mpz_cmpabs (mpz_t op1, mpz_t op2)
152
+ int mpz_cmpabs_d (mpz_t op1, double op2)
153
+ int mpz_cmpabs_ui (mpz_t op1, unsigned long int op2)
154
+ int mpz_sgn (mpz_t op)
155
+
156
+ # Logical and Bit Manipulation Functions
157
+ void mpz_and (mpz_t rop, mpz_t op1, mpz_t op2)
158
+ void mpz_ior (mpz_t rop, mpz_t op1, mpz_t op2)
159
+ void mpz_xor (mpz_t rop, mpz_t op1, mpz_t op2)
160
+ void mpz_com (mpz_t rop, mpz_t op)
161
+ unsigned long int mpz_popcount (mpz_t op)
162
+ unsigned long int mpz_hamdist (mpz_t op1, mpz_t op2)
163
+ unsigned long int mpz_scan0 (mpz_t op, unsigned long int starting_bit)
164
+ unsigned long int mpz_scan1 (mpz_t op, unsigned long int starting_bit)
165
+ void mpz_setbit (mpz_t rop, unsigned long int bit_index)
166
+ void mpz_clrbit (mpz_t rop, unsigned long int bit_index)
167
+ void mpz_combit (mpz_t rop, unsigned long int bit_index)
168
+ int mpz_tstbit (mpz_t op, unsigned long int bit_index)
169
+
170
+ # Input and Output Functions
171
+ size_t mpz_out_str (FILE *stream, int base, mpz_t op)
172
+ size_t mpz_inp_str (mpz_t rop, FILE *stream, int base)
173
+ size_t mpz_out_raw (FILE *stream, mpz_t op)
174
+ size_t mpz_inp_raw (mpz_t rop, FILE *stream)
175
+
176
+ # Random Number Functions
177
+ void mpz_urandomb (mpz_t rop, gmp_randstate_t state, unsigned long int n)
178
+ void mpz_urandomm (mpz_t rop, gmp_randstate_t state, mpz_t n)
179
+ void mpz_rrandomb (mpz_t rop, gmp_randstate_t state, unsigned long int n)
180
+ void mpz_random (mpz_t rop, mp_size_t max_size)
181
+ void mpz_random2 (mpz_t rop, mp_size_t max_size)
182
+
183
+ # Integer Import and Export
184
+ void mpz_import (mpz_t rop, size_t count, int order, int size, int endian, size_t nails, void *op)
185
+ void * mpz_export (void *rop, size_t *countp, int order, int size, int endian, size_t nails, mpz_t op)
186
+
187
+ # Miscellaneous Functions
188
+ bint mpz_fits_ulong_p (mpz_t op)
189
+ bint mpz_fits_slong_p (mpz_t op)
190
+ bint mpz_fits_uint_p (mpz_t op)
191
+ bint mpz_fits_sint_p (mpz_t op)
192
+ bint mpz_fits_ushort_p (mpz_t op)
193
+ bint mpz_fits_sshort_p (mpz_t op)
194
+ bint mpz_odd_p (mpz_t op)
195
+ bint mpz_even_p (mpz_t op)
196
+ size_t mpz_sizeinbase (mpz_t op, int base)
197
+
198
+ # Special Functions
199
+ void * _mpz_realloc (mpz_t integer, mp_size_t new_alloc)
200
+ mp_limb_t mpz_getlimbn (mpz_t op, mp_size_t n)
201
+ size_t mpz_size (mpz_t op)
202
+ mpz_srcptr mpz_roinit_n (mpz_t x, const mp_limb_t *xp, mp_size_t xs)
@@ -0,0 +1,12 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ """
3
+ Various functions to deal with conversion mpz <-> Python int/long
4
+ """
5
+
6
+ from cpython.longintrepr cimport py_long
7
+ from sage.libs.gmp.types cimport *
8
+
9
+ cdef mpz_get_pylong(mpz_srcptr z)
10
+ cdef mpz_get_pyintlong(mpz_srcptr z)
11
+ cdef int mpz_set_pylong(mpz_ptr z, py_long L) except -1
12
+ cdef Py_hash_t mpz_pythonhash(mpz_srcptr z) noexcept
@@ -0,0 +1,150 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ """
3
+ Various functions to deal with conversion mpz <-> Python int/long
4
+
5
+ For doctests, see :class:`Integer`.
6
+
7
+ AUTHORS:
8
+
9
+ - Gonzalo Tornaria (2006): initial version
10
+
11
+ - David Harvey (2007-08-18): added ``mpz_get_pyintlong`` function
12
+ (:issue:`440`)
13
+
14
+ - Jeroen Demeyer (2015-02-24): moved from c_lib, rewritten using
15
+ ``mpz_export`` and ``mpz_import`` (:issue:`17853`)
16
+ """
17
+
18
+ #*****************************************************************************
19
+ # Copyright (C) 2015 Jeroen Demeyer <jdemeyer@cage.ugent.be>
20
+ #
21
+ # This program is free software: you can redistribute it and/or modify
22
+ # it under the terms of the GNU General Public License as published by
23
+ # the Free Software Foundation, either version 2 of the License, or
24
+ # (at your option) any later version.
25
+ # https://www.gnu.org/licenses/
26
+ #*****************************************************************************
27
+
28
+ from cpython.long cimport PyLong_FromLong
29
+ from cpython.longintrepr cimport _PyLong_New, py_long, digit, PyLong_SHIFT
30
+ from sage.cpython.pycore_long cimport (ob_digit, _PyLong_IsNegative,
31
+ _PyLong_DigitCount, _PyLong_SetSignAndDigitCount)
32
+ from sage.libs.gmp.mpz cimport *
33
+
34
+ cdef extern from *:
35
+ void Py_SET_SIZE(object, Py_ssize_t)
36
+ int hash_bits """
37
+ #ifdef _PyHASH_BITS
38
+ _PyHASH_BITS /* Python 3 */
39
+ #else
40
+ (8 * sizeof(void*)) /* Python 2 */
41
+ #endif
42
+ """
43
+ int limb_bits "(8 * sizeof(mp_limb_t))"
44
+
45
+
46
+ # Unused bits in every PyLong digit
47
+ cdef size_t PyLong_nails = 8*sizeof(digit) - PyLong_SHIFT
48
+
49
+
50
+ cdef mpz_get_pylong_large(mpz_srcptr z):
51
+ """
52
+ Convert a nonzero ``mpz`` to a Python ``long``.
53
+ """
54
+ cdef size_t nbits = mpz_sizeinbase(z, 2)
55
+ cdef size_t pylong_size = (nbits + PyLong_SHIFT - 1) // PyLong_SHIFT
56
+ cdef py_long L = _PyLong_New(pylong_size)
57
+ mpz_export(ob_digit(L), NULL, -1, sizeof(digit), 0, PyLong_nails, z)
58
+ _PyLong_SetSignAndDigitCount(L, mpz_sgn(z), pylong_size)
59
+ return L
60
+
61
+
62
+ cdef mpz_get_pylong(mpz_srcptr z):
63
+ """
64
+ Convert an ``mpz`` to a Python ``long``.
65
+ """
66
+ if mpz_fits_slong_p(z):
67
+ return PyLong_FromLong(mpz_get_si(z))
68
+ return mpz_get_pylong_large(z)
69
+
70
+
71
+ cdef mpz_get_pyintlong(mpz_srcptr z):
72
+ """
73
+ Convert an ``mpz`` to a Python ``int`` if possible, or a ``long``
74
+ if the value is too large.
75
+ """
76
+ if mpz_fits_slong_p(z):
77
+ return PyLong_FromLong(mpz_get_si(z))
78
+ return mpz_get_pylong_large(z)
79
+
80
+
81
+ cdef int mpz_set_pylong(mpz_ptr z, py_long L) except -1:
82
+ """
83
+ Convert a Python ``long`` `L` to an ``mpz``.
84
+ """
85
+ cdef Py_ssize_t pylong_size = _PyLong_DigitCount(L)
86
+ mpz_import(z, pylong_size, -1, sizeof(digit), 0, PyLong_nails, ob_digit(L))
87
+ if _PyLong_IsNegative(L):
88
+ mpz_neg(z, z)
89
+
90
+
91
+ cdef Py_hash_t mpz_pythonhash(mpz_srcptr z) noexcept:
92
+ """
93
+ Hash an ``mpz``, where the hash value is the same as the hash value
94
+ of the corresponding Python ``int`` or ``long``, except that we do
95
+ not replace -1 by -2 (the Cython wrapper for ``__hash__`` does that).
96
+ """
97
+ if mpz_sgn(z) == 0:
98
+ return 0
99
+
100
+ # The hash value equals z % m where m = 2 ^ hash_bits - 1.
101
+ #
102
+ # Safely compute 2 ^ hash_bits - 1 without overflow
103
+ cdef mp_limb_t modulus = (((<mp_limb_t>(1) << (hash_bits - 1)) - 1) * 2) + 1
104
+
105
+ cdef mp_limb_t h = 0
106
+ cdef mp_limb_t x, y
107
+ cdef size_t i, n
108
+ cdef unsigned int r
109
+ n = mpz_size(z)
110
+ for i in range(n):
111
+ x = mpz_getlimbn(z, i)
112
+
113
+ # Computing modulo 2 ^ hash_bits - 1 means that the bit at
114
+ # position j is really moved to position (j % hash_bits).
115
+ # We need to shift every bit of x left by (limb_bits * i)
116
+ # and then put it in the right position to account for
117
+ # the modulo operation. Store the result in y.
118
+ if limb_bits == hash_bits:
119
+ y = x
120
+ else:
121
+ r = (limb_bits * i) % hash_bits
122
+ y = (x << r) & modulus
123
+ y += (x >> (hash_bits - r)) & modulus
124
+ # Only do this shift if we don't shift more than the size of the
125
+ # type
126
+ if r > 2 * hash_bits - limb_bits:
127
+ y += (x >> (2 * hash_bits - r))
128
+ # At this point, y <= 2 * modulus, so y did not overflow, but we
129
+ # need y <= modulus. We use > instead of >= on the line below
130
+ # because it generates more efficient code.
131
+ if y > modulus:
132
+ y -= modulus
133
+
134
+ # Safely compute h = (h + y) % modulus knowing that h < modulus
135
+ # and y <= modulus
136
+ if h < modulus - y:
137
+ h = h + y
138
+ else:
139
+ h = h - (modulus - y)
140
+
141
+ # Special case for Python 2
142
+ if limb_bits == hash_bits and h == 0:
143
+ h = -1
144
+
145
+ if mpz_sgn(z) < 0:
146
+ return -h
147
+ return h
148
+
149
+
150
+ assert hash_bits <= limb_bits <= 2 * hash_bits
@@ -0,0 +1,25 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ # distutils: libraries = gmp
3
+
4
+ from sage.libs.gmp.types cimport *
5
+
6
+ cdef extern from "gmp.h":
7
+
8
+ ### Random Number Functions ###
9
+
10
+ # Random State Initialization
11
+ void gmp_randinit_default (gmp_randstate_t state)
12
+ int gmp_randinit_mt (gmp_randstate_t state)
13
+ void gmp_randinit_lc_2exp (gmp_randstate_t state, mpz_t a, unsigned long c, unsigned long m2exp)
14
+ int gmp_randinit_lc_2exp_size (gmp_randstate_t state, unsigned long size)
15
+ int gmp_randinit_set (gmp_randstate_t rop, gmp_randstate_t op)
16
+ # void gmp_randinit (gmp_randstate_t state, gmp_randalg_t alg, ...)
17
+ void gmp_randclear (gmp_randstate_t state)
18
+
19
+ # Random State Seeding
20
+ void gmp_randseed (gmp_randstate_t state, mpz_t seed)
21
+ void gmp_randseed_ui (gmp_randstate_t state, unsigned long int seed)
22
+
23
+ # Random State Miscellaneous
24
+ unsigned long gmp_urandomb_ui (gmp_randstate_t state, unsigned long n)
25
+ unsigned long gmp_urandomm_ui (gmp_randstate_t state, unsigned long n)
@@ -0,0 +1,59 @@
1
+ # sage_setup: distribution = sagemath-objects
2
+ """
3
+ Generate random rationals in Sage
4
+ """
5
+
6
+ from sage.libs.gmp.mpz cimport *
7
+ from sage.libs.gmp.mpq cimport *
8
+ from sage.misc.randstate cimport randstate, current_randstate, SAGE_RAND_MAX
9
+
10
+ ###########################
11
+
12
+ cdef inline void mpq_randomize_entry(mpq_t x, mpz_t num_bound, mpz_t den_bound) noexcept:
13
+ cdef randstate rstate = current_randstate()
14
+ mpz_urandomm(mpq_numref(x), rstate.gmp_state, num_bound)
15
+ mpz_urandomm(mpq_denref(x), rstate.gmp_state, den_bound)
16
+ if mpz_sgn(mpq_denref(x)) == 0:
17
+ mpz_set_si(mpq_denref(x),1)
18
+ if rstate.c_random() % 2:
19
+ mpz_mul_si(mpq_numref(x), mpq_numref(x), -1)
20
+ mpq_canonicalize(x)
21
+
22
+ cdef inline void mpq_randomize_entry_nonzero(mpq_t x, mpz_t num_bound, mpz_t den_bound) noexcept:
23
+ mpq_randomize_entry(x, num_bound, den_bound)
24
+ while mpq_sgn(x) == 0:
25
+ mpq_randomize_entry(x, num_bound, den_bound)
26
+
27
+ cdef inline void mpq_randomize_entry_as_int(mpq_t x, mpz_t bound) noexcept:
28
+ cdef randstate rstate = current_randstate()
29
+ mpz_urandomm(mpq_numref(x), rstate.gmp_state, bound)
30
+ mpz_set_si(mpq_denref(x), 1)
31
+ if rstate.c_random() % 2:
32
+ mpz_mul_si(mpq_numref(x), mpq_numref(x), -1)
33
+
34
+ cdef inline void mpq_randomize_entry_as_int_nonzero(mpq_t x, mpz_t bound) noexcept:
35
+ mpq_randomize_entry_as_int(x, bound)
36
+ while mpq_sgn(x) == 0:
37
+ mpq_randomize_entry_as_int(x, bound)
38
+
39
+ cdef inline void mpq_randomize_entry_recip_uniform(mpq_t x) noexcept:
40
+ cdef randstate rstate = current_randstate()
41
+ # Numerator is selected the same way as ZZ.random_element();
42
+ # denominator is selected in a similar way, but
43
+ # modified to give only positive integers. (The corresponding
44
+ # probability distribution is $X = \mbox{trunc}(1/R)$, where R
45
+ # varies uniformly between 0 and 1.)
46
+ cdef int den = rstate.c_random() - SAGE_RAND_MAX/2
47
+ if den == 0:
48
+ den = 1
49
+ mpz_set_si(mpq_numref(x), (SAGE_RAND_MAX/5*2) / den)
50
+ den = rstate.c_random()
51
+ if den == 0:
52
+ den = 1
53
+ mpz_set_si(mpq_denref(x), SAGE_RAND_MAX / den)
54
+ mpq_canonicalize(x)
55
+
56
+ cdef inline void mpq_randomize_entry_recip_uniform_nonzero(mpq_t x) noexcept:
57
+ mpq_randomize_entry_recip_uniform(x)
58
+ while mpq_sgn(x) == 0:
59
+ mpq_randomize_entry_recip_uniform(x)