passagemath-categories 10.6.31rc3__cp314-cp314-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.31rc3.dist-info/METADATA +156 -0
  2. passagemath_categories-10.6.31rc3.dist-info/RECORD +719 -0
  3. passagemath_categories-10.6.31rc3.dist-info/WHEEL +5 -0
  4. passagemath_categories-10.6.31rc3.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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-musl.so +0 -0
  391. sage/misc/callable_dict.pyx +89 -0
  392. sage/misc/citation.cpython-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-musl.so +0 -0
  447. sage/rings/factorint.pyx +295 -0
  448. sage/rings/fast_arith.cpython-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-musl.so +0 -0
  509. sage/rings/integer.pxd +45 -0
  510. sage/rings/integer.pyx +7871 -0
  511. sage/rings/integer_ring.cpython-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-musl.so +0 -0
  622. sage/rings/real_double.pxd +16 -0
  623. sage/rings/real_double.pyx +2215 -0
  624. sage/rings/real_lazy.cpython-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-musl.so +0 -0
  710. sage/tests/cython.pyx +37 -0
  711. sage/tests/stl_vector.cpython-314-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,2215 @@
1
+ # sage_setup: distribution = sagemath-categories
2
+ r"""
3
+ Double precision floating point real numbers
4
+
5
+ EXAMPLES:
6
+
7
+ We create the real double vector space of dimension `3`::
8
+
9
+ sage: V = RDF^3; V # needs sage.modules
10
+ Vector space of dimension 3 over Real Double Field
11
+
12
+ Notice that this space is unique::
13
+
14
+ sage: V is RDF^3 # needs sage.modules
15
+ True
16
+ sage: V is FreeModule(RDF, 3) # needs sage.modules
17
+ True
18
+ sage: V is VectorSpace(RDF, 3) # needs sage.modules
19
+ True
20
+
21
+ Also, you can instantly create a space of large dimension::
22
+
23
+ sage: V = RDF^10000 # needs sage.modules
24
+
25
+ TESTS:
26
+
27
+ Test NumPy conversions::
28
+
29
+ sage: RDF(1).__array_interface__
30
+ {'typestr': '=f8'}
31
+ sage: import numpy # needs numpy
32
+ sage: numpy.array([RDF.pi()]).dtype # needs numpy
33
+ dtype('float64')
34
+ """
35
+
36
+ # ****************************************************************************
37
+ # This program is free software: you can redistribute it and/or modify
38
+ # it under the terms of the GNU General Public License as published by
39
+ # the Free Software Foundation, either version 2 of the License, or
40
+ # (at your option) any later version.
41
+ # https://www.gnu.org/licenses/
42
+ # ****************************************************************************
43
+
44
+ cimport libc.math
45
+ from libc.string cimport memcpy
46
+ from cpython.object cimport *
47
+ from cpython.float cimport *
48
+
49
+ from sage.ext.stdsage cimport PY_NEW
50
+ from sage.cpython.python_debug cimport if_Py_TRACE_REFS_then_PyObject_INIT
51
+
52
+ import math
53
+
54
+ import sage.arith.misc
55
+ import sage.rings.integer
56
+ import sage.rings.rational
57
+
58
+ from sage.rings.integer cimport Integer
59
+ from sage.rings.integer_ring import ZZ
60
+
61
+ from sage.categories.morphism cimport Morphism
62
+ from sage.structure.coerce cimport is_numpy_type
63
+ from sage.misc.randstate cimport randstate, current_randstate
64
+ from sage.structure.richcmp cimport rich_to_bool
65
+ from sage.arith.constants cimport *
66
+
67
+ cimport gmpy2
68
+
69
+
70
+ new_gen_from_real_double_element = None
71
+
72
+
73
+ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField):
74
+ """
75
+ An approximation to the field of real numbers using double
76
+ precision floating point numbers. Answers derived from calculations
77
+ in this approximation may differ from what they would be if those
78
+ calculations were performed in the true field of real numbers. This
79
+ is due to the rounding errors inherent to finite precision
80
+ calculations.
81
+
82
+ EXAMPLES::
83
+
84
+ sage: RR == RDF # needs sage.rings.real_mpfr
85
+ False
86
+ sage: RDF == RealDoubleField() # RDF is the shorthand
87
+ True
88
+
89
+ ::
90
+
91
+ sage: RDF(1)
92
+ 1.0
93
+ sage: RDF(2/3)
94
+ 0.6666666666666666
95
+
96
+ A :exc:`TypeError` is raised if the coercion doesn't make sense::
97
+
98
+ sage: RDF(QQ['x'].0)
99
+ Traceback (most recent call last):
100
+ ...
101
+ TypeError: cannot convert nonconstant polynomial
102
+ sage: RDF(QQ['x'](3))
103
+ 3.0
104
+
105
+ One can convert back and forth between double precision real
106
+ numbers and higher-precision ones, though of course there may be
107
+ loss of precision::
108
+
109
+ sage: # needs sage.rings.real_mpfr
110
+ sage: a = RealField(200)(2).sqrt(); a
111
+ 1.4142135623730950488016887242096980785696718753769480731767
112
+ sage: b = RDF(a); b
113
+ 1.4142135623730951
114
+ sage: a.parent()(b)
115
+ 1.4142135623730951454746218587388284504413604736328125000000
116
+ sage: a.parent()(b) == b
117
+ True
118
+ sage: b == RR(a)
119
+ True
120
+
121
+ TESTS::
122
+
123
+ sage: RDF.is_finite()
124
+ False
125
+ """
126
+ def __init__(self):
127
+ """
128
+ Initialize ``self``.
129
+
130
+ TESTS::
131
+
132
+ sage: R = RealDoubleField()
133
+ sage: TestSuite(R).run()
134
+ """
135
+ from sage.categories.fields import Fields
136
+ Field.__init__(self, self,
137
+ category=Fields().Infinite().Metric().Complete())
138
+ self._populate_coercion_lists_(init_no_parent=True,
139
+ convert_method_name='_real_double_')
140
+
141
+ _element_constructor_ = RealDoubleElement
142
+
143
+ def __reduce__(self):
144
+ """
145
+ For pickling.
146
+
147
+ EXAMPLES::
148
+
149
+ sage: loads(dumps(RDF)) is RDF
150
+ True
151
+ """
152
+ return RealDoubleField, ()
153
+
154
+ cpdef bint is_exact(self) except -2:
155
+ """
156
+ Return ``False``, because doubles are not exact.
157
+
158
+ EXAMPLES::
159
+
160
+ sage: RDF.is_exact()
161
+ False
162
+ """
163
+ return False
164
+
165
+ def _latex_(self):
166
+ r"""
167
+ Return a latex representation of ``self``.
168
+
169
+ EXAMPLES::
170
+
171
+ sage: latex(RDF) # indirect doctest
172
+ \Bold{R}
173
+ """
174
+ return "\\Bold{R}"
175
+
176
+ def _sage_input_(self, sib, coerced):
177
+ r"""
178
+ Produce an expression which will reproduce this value when evaluated.
179
+
180
+ EXAMPLES::
181
+
182
+ sage: sage_input(RDF, verify=True)
183
+ # Verified
184
+ RDF
185
+ sage: from sage.misc.sage_input import SageInputBuilder
186
+ sage: RDF._sage_input_(SageInputBuilder(), False)
187
+ {atomic:RDF}
188
+ """
189
+ return sib.name('RDF')
190
+
191
+ def __repr__(self):
192
+ """
193
+ Return a string representation of ``self``.
194
+
195
+ EXAMPLES::
196
+
197
+ sage: RealDoubleField() # indirect doctest
198
+ Real Double Field
199
+ sage: RDF
200
+ Real Double Field
201
+ """
202
+ return "Real Double Field"
203
+
204
+ def _repr_option(self, key):
205
+ """
206
+ Metadata about the :meth:`_repr_` output.
207
+
208
+ See :meth:`sage.structure.parent._repr_option` for details.
209
+
210
+ EXAMPLES::
211
+
212
+ sage: RDF._repr_option('element_is_atomic')
213
+ True
214
+ """
215
+ if key == 'element_is_atomic':
216
+ return True
217
+ return super()._repr_option(key)
218
+
219
+ def __richcmp__(self, x, op):
220
+ """
221
+ Compare ``self`` to ``x``.
222
+
223
+ EXAMPLES::
224
+
225
+ sage: RDF == 5
226
+ False
227
+ sage: loads(dumps(RDF)) == RDF
228
+ True
229
+ """
230
+ if isinstance(x, RealDoubleField_class):
231
+ return rich_to_bool(op, 0)
232
+ if op == Py_NE:
233
+ return True
234
+ return NotImplemented
235
+
236
+ def construction(self):
237
+ r"""
238
+ Return the functorial construction of ``self``, namely, completion of
239
+ the rational numbers with respect to the prime at `\infty`.
240
+
241
+ Also preserves other information that makes this field unique (i.e.
242
+ the Real Double Field).
243
+
244
+ EXAMPLES::
245
+
246
+ sage: c, S = RDF.construction(); S
247
+ Rational Field
248
+ sage: RDF == c(S)
249
+ True
250
+ """
251
+ from sage.categories.pushout import CompletionFunctor
252
+ return (CompletionFunctor(sage.rings.infinity.Infinity,
253
+ 53,
254
+ {'type': 'RDF'}),
255
+ sage.rings.rational_field.QQ)
256
+
257
+ def complex_field(self):
258
+ """
259
+ Return the complex field with the same precision as ``self``, i.e.,
260
+ the complex double field.
261
+
262
+ EXAMPLES::
263
+
264
+ sage: RDF.complex_field() # needs sage.rings.complex_double
265
+ Complex Double Field
266
+ """
267
+ from sage.rings.complex_double import CDF
268
+ return CDF
269
+
270
+ def algebraic_closure(self):
271
+ """
272
+ Return the algebraic closure of ``self``, i.e., the complex double
273
+ field.
274
+
275
+ EXAMPLES::
276
+
277
+ sage: RDF.algebraic_closure() # needs sage.rings.complex_double
278
+ Complex Double Field
279
+ """
280
+ from sage.rings.complex_double import CDF
281
+ return CDF
282
+
283
+ cpdef _coerce_map_from_(self, S):
284
+ """
285
+ Canonical coercion of ``S`` to the real double field.
286
+
287
+ The rings that canonically coerce to the real double field are:
288
+
289
+ - the real double field itself
290
+ - int, long, integer, and rational rings
291
+ - numpy integers and floatings
292
+ - the real lazy field
293
+ - the MPFR real field with at least 53 bits of precision
294
+
295
+ EXAMPLES::
296
+
297
+ sage: RDF.coerce(5) # indirect doctest
298
+ 5.0
299
+ sage: RDF.coerce(9499294r)
300
+ 9499294.0
301
+ sage: RDF.coerce(61/3)
302
+ 20.333333333333332
303
+ sage: parent(RDF(3) + CDF(5)) # needs sage.rings.complex_double
304
+ Complex Double Field
305
+ sage: parent(CDF(5) + RDF(3)) # needs sage.rings.complex_double
306
+ Complex Double Field
307
+ sage: CDF.gen(0) + 5.0 # needs sage.rings.complex_double
308
+ 5.0 + 1.0*I
309
+ sage: RLF(2/3) + RDF(1)
310
+ 1.6666666666666665
311
+
312
+ sage: import numpy # needs numpy
313
+ sage: RDF.coerce(numpy.int8('1')) # needs numpy
314
+ 1.0
315
+ sage: RDF.coerce(numpy.float64('1')) # needs numpy
316
+ 1.0
317
+
318
+ sage: RDF.coerce(pi) # needs sage.symbolic
319
+ Traceback (most recent call last):
320
+ ...
321
+ TypeError: no canonical coercion from Symbolic Ring to Real Double Field
322
+
323
+ Test that :issue:`15695` is fixed (see also :issue:`18076`)::
324
+
325
+ sage: 1j + numpy.float64(2) # needs numpy
326
+ 2.00000000000000 + 1.00000000000000*I
327
+ sage: parent(_) # needs numpy
328
+ Complex Field with 53 bits of precision
329
+ """
330
+ if S is int or S is float:
331
+ return ToRDF(S)
332
+
333
+ from sage.rings.rational_field import QQ
334
+ try:
335
+ from sage.rings.real_lazy import RLF
336
+ except ImportError:
337
+ RLF = None
338
+
339
+ if S is ZZ or S is QQ or S is RLF:
340
+ return ToRDF(S)
341
+
342
+ if isinstance(S, sage.rings.abc.RealField):
343
+ if S.prec() >= 53:
344
+ return ToRDF(S)
345
+ else:
346
+ return None
347
+ elif is_numpy_type(S):
348
+ import numpy
349
+ if issubclass(S, numpy.integer) or issubclass(S, numpy.floating):
350
+ return ToRDF(S)
351
+ else:
352
+ return None
353
+
354
+ try:
355
+ from sage.rings.real_mpfr import RR
356
+ except ImportError:
357
+ pass
358
+ else:
359
+ connecting = RR._internal_coerce_map_from(S)
360
+ if connecting is not None:
361
+ return ToRDF(RR) * connecting
362
+
363
+ def _magma_init_(self, magma):
364
+ r"""
365
+ Return a string representation of ``self`` in the Magma language.
366
+
367
+ EXAMPLES:
368
+
369
+ Magma handles precision in decimal digits, so we lose a bit::
370
+
371
+ sage: magma(RDF) # indirect doctest # optional - magma
372
+ Real field of precision 15
373
+ sage: 10^15 < 2^53 < 10^16
374
+ True
375
+
376
+ When we convert back from Magma, we convert to a generic real field
377
+ that has 53 bits of precision::
378
+
379
+ sage: magma(RDF).sage() # optional - magma
380
+ Real Field with 53 bits of precision
381
+ """
382
+ return "RealField(%s : Bits := true)" % self.prec()
383
+
384
+ def _fricas_init_(self):
385
+ r"""
386
+ Return the FriCAS representation of the real double field.
387
+
388
+ EXAMPLES::
389
+
390
+ sage: fricas(RDF) # indirect doctest # optional - fricas
391
+ DoubleFloat
392
+ """
393
+ return "DoubleFloat"
394
+
395
+ def _polymake_init_(self):
396
+ r"""
397
+ Return the polymake representation of the real double field.
398
+
399
+ EXAMPLES::
400
+
401
+ sage: polymake(RDF) # indirect doctest # optional - jupymake
402
+ Float
403
+ """
404
+ return '"Float"'
405
+
406
+ def precision(self):
407
+ """
408
+ Return the precision of this real double field in bits.
409
+
410
+ Always returns 53.
411
+
412
+ EXAMPLES::
413
+
414
+ sage: RDF.precision()
415
+ 53
416
+ """
417
+ return 53
418
+
419
+ prec = precision
420
+
421
+ def to_prec(self, prec):
422
+ """
423
+ Return the real field to the specified precision. As doubles have
424
+ fixed precision, this will only return a real double field if ``prec``
425
+ is exactly 53.
426
+
427
+ EXAMPLES::
428
+
429
+ sage: RDF.to_prec(52) # needs sage.rings.real_mpfr
430
+ Real Field with 52 bits of precision
431
+ sage: RDF.to_prec(53)
432
+ Real Double Field
433
+ """
434
+ if prec == 53:
435
+ return self
436
+ from sage.rings.real_mpfr import RealField
437
+ return RealField(prec)
438
+
439
+ def gen(self, n=0):
440
+ """
441
+ Return the generator of the real double field.
442
+
443
+ EXAMPLES::
444
+
445
+ sage: RDF.0
446
+ 1.0
447
+ sage: RDF.gens()
448
+ (1.0,)
449
+ """
450
+ if n != 0:
451
+ raise ValueError("only 1 generator")
452
+ return RealDoubleElement(1)
453
+
454
+ def ngens(self):
455
+ """
456
+ Return the number of generators which is always 1.
457
+
458
+ EXAMPLES::
459
+
460
+ sage: RDF.ngens()
461
+ 1
462
+ """
463
+ return 1
464
+
465
+ def characteristic(self):
466
+ """
467
+ Return 0, since the field of real numbers has characteristic 0.
468
+
469
+ EXAMPLES::
470
+
471
+ sage: RDF.characteristic()
472
+ 0
473
+ """
474
+ return Integer(0)
475
+
476
+ cdef _new_c(self, double value):
477
+ cdef RealDoubleElement x
478
+ x = PY_NEW(RealDoubleElement)
479
+ x._value = value
480
+ return x
481
+
482
+ def random_element(self, double min=-1, double max=1):
483
+ """
484
+ Return a random element of this real double field in the interval
485
+ ``[min, max]``.
486
+
487
+ EXAMPLES::
488
+
489
+ sage: RDF.random_element().parent() is RDF
490
+ True
491
+ sage: -1 <= RDF.random_element() <= 1
492
+ True
493
+ sage: 100 <= RDF.random_element(min=100, max=110) <= 110
494
+ True
495
+ """
496
+ cdef randstate rstate = current_randstate()
497
+
498
+ return self._new_c((max-min)*rstate.c_rand_double() + min)
499
+
500
+ def name(self):
501
+ """
502
+ The name of ``self``.
503
+
504
+ EXAMPLES::
505
+
506
+ sage: RDF.name()
507
+ 'RealDoubleField'
508
+ """
509
+ return "RealDoubleField"
510
+
511
+ def __hash__(self):
512
+ """
513
+ Return the hash value of ``self``.
514
+
515
+ This class is intended for use as a singleton so any instance
516
+ of it should be equivalent from a hashing perspective.
517
+
518
+ TESTS::
519
+
520
+ sage: from sage.rings.real_double import RealDoubleField_class
521
+ sage: hash(RDF) == hash(RealDoubleField_class())
522
+ True
523
+ """
524
+ return 1157042230
525
+
526
+ def pi(self):
527
+ r"""
528
+ Return `\pi` to double-precision.
529
+
530
+ EXAMPLES::
531
+
532
+ sage: RDF.pi()
533
+ 3.141592653589793
534
+ sage: RDF.pi().sqrt()/2
535
+ 0.8862269254527579
536
+ """
537
+ return self(M_PI)
538
+
539
+ def euler_constant(self):
540
+ """
541
+ Return Euler's gamma constant to double precision.
542
+
543
+ EXAMPLES::
544
+
545
+ sage: RDF.euler_constant()
546
+ 0.5772156649015329
547
+ """
548
+ return self(M_EULER)
549
+
550
+ def log2(self):
551
+ r"""
552
+ Return `\log(2)` to the precision of this field.
553
+
554
+ EXAMPLES::
555
+
556
+ sage: RDF.log2()
557
+ 0.6931471805599453
558
+ sage: RDF(2).log()
559
+ 0.6931471805599453
560
+ """
561
+ return self(M_LN2)
562
+
563
+ def factorial(self, int n):
564
+ """
565
+ Return the factorial of the integer `n` as a real number.
566
+
567
+ EXAMPLES::
568
+
569
+ sage: RDF.factorial(100)
570
+ 9.332621544394415e+157
571
+ """
572
+ return global_dummy_element._factorial(n)
573
+
574
+ def zeta(self, n=2):
575
+ """
576
+ Return an `n`-th root of unity in the real field, if one
577
+ exists, or raise a :exc:`ValueError` otherwise.
578
+
579
+ EXAMPLES::
580
+
581
+ sage: RDF.zeta()
582
+ -1.0
583
+ sage: RDF.zeta(1)
584
+ 1.0
585
+ sage: RDF.zeta(5)
586
+ Traceback (most recent call last):
587
+ ...
588
+ ValueError: No 5th root of unity in self
589
+ """
590
+ if n == 1:
591
+ return self(1)
592
+ elif n == 2:
593
+ return self(-1)
594
+ raise ValueError("No %sth root of unity in self" % n)
595
+
596
+ def NaN(self):
597
+ """
598
+ Return Not-a-Number ``NaN``.
599
+
600
+ EXAMPLES::
601
+
602
+ sage: RDF.NaN()
603
+ NaN
604
+ """
605
+ return self(0)/self(0)
606
+
607
+ nan = NaN
608
+
609
+ def _factor_univariate_polynomial(self, f):
610
+ """
611
+ Factor the univariate polynomial ``f``.
612
+
613
+ INPUT:
614
+
615
+ - ``f`` -- a univariate polynomial defined over the double precision
616
+ real numbers
617
+
618
+ OUTPUT:
619
+
620
+ - A factorization of ``f`` over the double precision real numbers
621
+ into a unit and monic irreducible factors
622
+
623
+ .. NOTE::
624
+
625
+ This is a helper method for
626
+ :meth:`sage.rings.polynomial.polynomial_element.Polynomial.factor`.
627
+
628
+ TESTS::
629
+
630
+ sage: # needs numpy
631
+ sage: R.<x> = RDF[]
632
+ sage: RDF._factor_univariate_polynomial(x)
633
+ x
634
+ sage: RDF._factor_univariate_polynomial(2*x)
635
+ (2.0) * x
636
+ sage: RDF._factor_univariate_polynomial(x^2)
637
+ x^2
638
+ sage: RDF._factor_univariate_polynomial(x^2 + 1)
639
+ x^2 + 1.0
640
+ sage: RDF._factor_univariate_polynomial(x^2 - 1)
641
+ (x - 1.0) * (x + 1.0)
642
+
643
+ The implementation relies on the ``roots()`` method which often reports
644
+ roots not to be real even though they are::
645
+
646
+ sage: f = (x-1)^3 # needs numpy
647
+ sage: f.roots(ring=CDF) # abs tol 2e-5 # needs numpy
648
+ [(1.0000065719436413, 1),
649
+ (0.9999967140281792 - 5.691454546815028e-06*I, 1),
650
+ (0.9999967140281792 + 5.691454546815028e-06*I, 1)]
651
+
652
+ This leads to the following incorrect factorization::
653
+
654
+ sage: f.factor() # abs tol 2e-5 # needs numpy
655
+ (x - 1.0000065719436413) * (x^2 - 1.9999934280563585*x + 0.9999934280995487)
656
+ """
657
+ from sage.rings.complex_double import CDF
658
+ roots = f.roots(CDF)
659
+
660
+ # collect real roots and conjugate pairs of non-real roots
661
+ real_roots = [(r, e) for r, e in roots if r.imag().is_zero()]
662
+ non_real_roots = {r: e for r, e in roots if not r.imag().is_zero()}
663
+ assert all(non_real_roots[r.conj()] == e for r, e in non_real_roots.items()), "Bug in root finding code over RDF - roots must always come in conjugate pairs"
664
+ non_real_roots = [(r, e) for r, e in non_real_roots.items() if r.imag() > 0]
665
+
666
+ # turn the roots into irreducible factors
667
+ x = f.parent().gen()
668
+ real_factors = [(x - r.real(), e) for r, e in real_roots]
669
+ non_real_factors = [(x**2 - (r + r.conj()).real()*x + (r*r.conj()).real(), e) for r, e in non_real_roots]
670
+
671
+ # make the factors monic
672
+ from sage.structure.factorization import Factorization
673
+ return Factorization([(g.monic(), e) for g, e in real_factors + non_real_factors], f.leading_coefficient())
674
+
675
+
676
+ cdef class RealDoubleElement(FieldElement):
677
+ """
678
+ An approximation to a real number using double precision floating
679
+ point numbers. Answers derived from calculations with such
680
+ approximations may differ from what they would be if those
681
+ calculations were performed with true real numbers. This is due to
682
+ the rounding errors inherent to finite precision calculations.
683
+ """
684
+
685
+ __array_interface__ = {'typestr': '=f8'}
686
+
687
+ def __cinit__(self):
688
+ """
689
+ Initialize ``self`` for cython.
690
+
691
+ EXAMPLES::
692
+
693
+ sage: RDF(2.3) # indirect doctest
694
+ 2.3
695
+ """
696
+ (<Element>self)._parent = _RDF
697
+
698
+ def __init__(self, x):
699
+ """
700
+ Create a new ``RealDoubleElement`` with value ``x``.
701
+
702
+ EXAMPLES::
703
+
704
+ sage: RDF(10^100)
705
+ 1e+100
706
+
707
+ TESTS::
708
+
709
+ sage: from gmpy2 import *
710
+ sage: RDF(mpz(42))
711
+ 42.0
712
+ sage: RDF(mpq(3/4))
713
+ 0.75
714
+ sage: RDF(mpq('4.1'))
715
+ 4.1
716
+ """
717
+ self._value = float(x)
718
+
719
+ def _magma_init_(self, magma):
720
+ r"""
721
+ Return a string representation of ``self`` in the Magma language.
722
+
723
+ EXAMPLES::
724
+
725
+ sage: RDF(10.5)
726
+ 10.5
727
+ sage: magma(RDF(10.5)) # indirect doctest # optional - magma
728
+ 10.5000000000000
729
+ """
730
+ return "%s!%s" % (self.parent()._magma_init_(magma), self)
731
+
732
+ def __reduce__(self):
733
+ """
734
+ For pickling.
735
+
736
+ EXAMPLES::
737
+
738
+ sage: a = RDF(-2.7)
739
+ sage: loads(dumps(a)) == a
740
+ True
741
+ """
742
+ return RealDoubleElement, (self._value, )
743
+
744
+ cdef _new_c(self, double value):
745
+ cdef RealDoubleElement x
746
+ x = PY_NEW(RealDoubleElement)
747
+ x._value = value
748
+ return x
749
+
750
+ def prec(self):
751
+ """
752
+ Return the precision of this number in bits.
753
+
754
+ Always returns 53.
755
+
756
+ EXAMPLES::
757
+
758
+ sage: RDF(0).prec()
759
+ 53
760
+ """
761
+ return 53
762
+
763
+ def ulp(self):
764
+ """
765
+ Return the unit of least precision of ``self``, which is the
766
+ weight of the least significant bit of ``self``. This is always
767
+ a strictly positive number. It is also the gap between this
768
+ number and the closest number with larger absolute value that
769
+ can be represented.
770
+
771
+ EXAMPLES::
772
+
773
+ sage: a = RDF(pi) # needs sage.symbolic
774
+ sage: a.ulp() # needs sage.symbolic
775
+ 4.440892098500626e-16
776
+ sage: b = a + a.ulp() # needs sage.symbolic
777
+
778
+ Adding or subtracting an ulp always gives a different number::
779
+
780
+ sage: # needs sage.symbolic
781
+ sage: a + a.ulp() == a
782
+ False
783
+ sage: a - a.ulp() == a
784
+ False
785
+ sage: b + b.ulp() == b
786
+ False
787
+ sage: b - b.ulp() == b
788
+ False
789
+
790
+ Since the default rounding mode is round-to-nearest, adding or
791
+ subtracting something less than half an ulp always gives the
792
+ same number, unless the result has a smaller ulp. The latter
793
+ can only happen if the input number is (up to sign) exactly a
794
+ power of 2::
795
+
796
+ sage: # needs sage.symbolic
797
+ sage: a - a.ulp()/3 == a
798
+ True
799
+ sage: a + a.ulp()/3 == a
800
+ True
801
+ sage: b - b.ulp()/3 == b
802
+ True
803
+ sage: b + b.ulp()/3 == b
804
+ True
805
+
806
+ sage: c = RDF(1)
807
+ sage: c - c.ulp()/3 == c
808
+ False
809
+ sage: c.ulp()
810
+ 2.220446049250313e-16
811
+ sage: (c - c.ulp()).ulp()
812
+ 1.1102230246251565e-16
813
+
814
+ The ulp is always positive::
815
+
816
+ sage: RDF(-1).ulp()
817
+ 2.220446049250313e-16
818
+
819
+ The ulp of zero is the smallest positive number in RDF::
820
+
821
+ sage: RDF(0).ulp()
822
+ 5e-324
823
+ sage: RDF(0).ulp()/2
824
+ 0.0
825
+
826
+ Some special values::
827
+
828
+ sage: a = RDF(1)/RDF(0); a
829
+ +infinity
830
+ sage: a.ulp()
831
+ +infinity
832
+ sage: (-a).ulp()
833
+ +infinity
834
+ sage: a = RDF('nan')
835
+ sage: a.ulp() is a
836
+ True
837
+
838
+ The ulp method works correctly with small numbers::
839
+
840
+ sage: u = RDF(0).ulp()
841
+ sage: u.ulp() == u
842
+ True
843
+ sage: x = u * (2^52-1) # largest denormal number
844
+ sage: x.ulp() == u
845
+ True
846
+ sage: x = u * 2^52 # smallest normal number
847
+ sage: x.ulp() == u
848
+ True
849
+ """
850
+ # First, check special values
851
+ if self._value == 0:
852
+ return RealDoubleElement(libc.math.ldexp(1.0, -1074))
853
+ if libc.math.isnan(self._value):
854
+ return self
855
+ if libc.math.isinf(self._value):
856
+ return self.abs()
857
+
858
+ # Normal case
859
+ cdef int e
860
+ libc.math.frexp(self._value, &e)
861
+ e -= 53
862
+ # Correction for denormals
863
+ if e < -1074:
864
+ e = -1074
865
+ return RealDoubleElement(libc.math.ldexp(1.0, e))
866
+
867
+ def real(self):
868
+ """
869
+ Return ``self`` - we are already real.
870
+
871
+ EXAMPLES::
872
+
873
+ sage: a = RDF(3)
874
+ sage: a.real()
875
+ 3.0
876
+ """
877
+ return self
878
+
879
+ def imag(self):
880
+ """
881
+ Return the imaginary part of this number, which is zero.
882
+
883
+ EXAMPLES::
884
+
885
+ sage: a = RDF(3)
886
+ sage: a.imag()
887
+ 0.0
888
+ """
889
+ return RealDoubleElement(0)
890
+
891
+ def __complex__(self):
892
+ """
893
+ Return ``self`` as a python complex number.
894
+
895
+ EXAMPLES::
896
+
897
+ sage: a = 2303
898
+ sage: RDF(a)
899
+ 2303.0
900
+ sage: complex(RDF(a))
901
+ (2303+0j)
902
+ """
903
+ return complex(self._value, 0)
904
+
905
+ def _integer_(self, ZZ=None):
906
+ """
907
+ If this floating-point number is actually an integer, return
908
+ that integer. Otherwise, raise an exception.
909
+
910
+ EXAMPLES::
911
+
912
+ sage: ZZ(RDF(237.0)) # indirect doctest
913
+ 237
914
+ sage: ZZ(RDF(0.0/0.0))
915
+ Traceback (most recent call last):
916
+ ...
917
+ ValueError: cannot convert float NaN to integer
918
+ sage: ZZ(RDF(1.0/0.0))
919
+ Traceback (most recent call last):
920
+ ...
921
+ OverflowError: cannot convert float infinity to integer
922
+ sage: ZZ(RDF(-123456789.0))
923
+ -123456789
924
+ sage: ZZ(RDF((2.0))^290)
925
+ 1989292945639146568621528992587283360401824603189390869761855907572637988050133502132224
926
+ sage: ZZ(RDF(-2345.67))
927
+ Traceback (most recent call last):
928
+ ...
929
+ TypeError: cannot convert non-integral float to integer
930
+ """
931
+ return Integer(self._value)
932
+
933
+ def __mpfr__(self):
934
+ """
935
+ Convert Sage ``RealDoubleElement`` to gmpy2 ``mpfr``.
936
+
937
+ EXAMPLES::
938
+
939
+ sage: RDF(42.2).__mpfr__()
940
+ mpfr('42.200000000000003')
941
+ sage: from gmpy2 import mpfr
942
+ sage: mpfr(RDF(5.1))
943
+ mpfr('5.0999999999999996')
944
+
945
+ TESTS::
946
+
947
+ sage: RDF().__mpfr__(); raise NotImplementedError("gmpy2 is not installed")
948
+ Traceback (most recent call last):
949
+ ...
950
+ NotImplementedError: gmpy2 is not installed
951
+ """
952
+ return gmpy2.mpfr(self._value)
953
+
954
+ def _interface_init_(self, I=None):
955
+ """
956
+ Return ``self`` formatted as a string, suitable as input to another
957
+ computer algebra system. (This is the default function used for
958
+ exporting to other computer algebra systems.)
959
+
960
+ EXAMPLES::
961
+
962
+ sage: s1 = RDF(sin(1)); s1 # needs sage.symbolic
963
+ 0.8414709848078965
964
+ sage: s1._interface_init_() # needs sage.symbolic
965
+ '0.8414709848078965'
966
+ sage: s1 == RDF(gp(s1)) # needs sage.libs.pari sage.symbolic
967
+ True
968
+ """
969
+ return repr(self._value)
970
+
971
+ def _mathematica_init_(self):
972
+ """
973
+ TESTS:
974
+
975
+ Check that :issue:`28814` is fixed::
976
+
977
+ sage: mathematica(RDF(1e25)) # optional - mathematica
978
+ 1.*^25
979
+ sage: mathematica(RDF(1e-25)) # optional - mathematica
980
+ 1.*^-25
981
+ """
982
+ from sage.rings.real_mpfr import RR
983
+ return RR(self._value)._mathematica_init_()
984
+
985
+ def _sage_input_(self, sib, coerced):
986
+ r"""
987
+ Produce an expression which will reproduce this value when evaluated.
988
+
989
+ EXAMPLES::
990
+
991
+ sage: sage_input(RDF(NaN)) # needs sage.symbolic
992
+ RDF(NaN)
993
+ sage: sage_input(RDF(-infinity), verify=True)
994
+ # Verified
995
+ -RDF(infinity)
996
+ sage: sage_input(RDF(-infinity)*polygen(RDF))
997
+ R.<x> = RDF[]
998
+ -RDF(infinity)*x + RDF(NaN)
999
+ sage: sage_input(RDF(pi), verify=True) # needs sage.symbolic
1000
+ # Verified
1001
+ RDF(3.1415926535897931)
1002
+ sage: sage_input(RDF(-e), verify=True, preparse=False) # needs sage.symbolic
1003
+ # Verified
1004
+ -RDF(2.718281828459045...)
1005
+ sage: sage_input(RDF(pi)*polygen(RDF), verify=True, preparse=None) # needs sage.symbolic
1006
+ # Verified
1007
+ R = RDF['x']
1008
+ x = R.gen()
1009
+ 3.1415926535897931*x
1010
+ sage: from sage.misc.sage_input import SageInputBuilder
1011
+ sage: sib = SageInputBuilder()
1012
+ sage: RDF(22/7)._sage_input_(sib, True) # needs sage.sage.rings.real_mpfr
1013
+ {atomic:3.1428571428571428}
1014
+ sage: RDF(22/7)._sage_input_(sib, False) # needs sage.sage.rings.real_mpfr
1015
+ {call: {atomic:RDF}({atomic:3.1428571428571428})}
1016
+ """
1017
+ cdef bint isinf = libc.math.isinf(self._value)
1018
+ cdef bint isnan = libc.math.isnan(self._value)
1019
+ if isinf or isnan:
1020
+ if isnan:
1021
+ v = sib.name('NaN')
1022
+ else:
1023
+ v = sib.name('infinity')
1024
+ v = sib(self.parent())(v)
1025
+ if self._value < 0:
1026
+ v = -v
1027
+ return v
1028
+
1029
+ from sage.rings.integer_ring import ZZ
1030
+ from sage.rings.real_mpfr import RR
1031
+
1032
+ cdef bint negative = self._value < 0
1033
+ if negative:
1034
+ self = -self
1035
+
1036
+ # There are five possibilities for printing this floating-point
1037
+ # number, ordered from prettiest to ugliest (IMHO).
1038
+ # 1) An integer: 42
1039
+ # 2) A simple literal: 3.14159
1040
+ # 3) A coerced integer: RDF(42)
1041
+ # 4) A coerced literal: RDF(3.14159)
1042
+ # 5) A coerced RR value: RDF(RR('3.14159'))
1043
+
1044
+ # str(self) works via libc, which we don't necessarily trust
1045
+ # to produce the best possible answer. So this function prints
1046
+ # via RR/MPFR. Without the preparser, input works via libc as
1047
+ # well, but we don't have a choice about that.
1048
+
1049
+ # To use choice 1 or choice 3, this number must be an integer.
1050
+ cdef bint can_use_int_literal = \
1051
+ self.abs() < (Integer(1) << self.prec()) and self in ZZ
1052
+
1053
+ self_str = RR(self._value).str(truncate=False, skip_zeroes=True)
1054
+
1055
+ # To use choice 2 or choice 4, we must be able to read
1056
+ # numbers of this precision as a literal.
1057
+ cdef bint can_use_float_literal = \
1058
+ (sib.preparse() or float(self_str) == self)
1059
+
1060
+ if can_use_int_literal or can_use_float_literal:
1061
+ if can_use_int_literal:
1062
+ v = sib.int(self._integer_())
1063
+ else:
1064
+ v = sib.float_str(self_str)
1065
+ else:
1066
+ v = sib(RR(self))
1067
+ if not coerced:
1068
+ v = sib(self.parent())(v)
1069
+
1070
+ if negative:
1071
+ v = -v
1072
+
1073
+ return v
1074
+
1075
+ def _repr_(self):
1076
+ """
1077
+ Return the string representation of ``self``.
1078
+
1079
+ EXAMPLES::
1080
+
1081
+ sage: RDF(-2/3)
1082
+ -0.6666666666666666
1083
+ sage: a = RDF(2); a
1084
+ 2.0
1085
+ sage: a^2
1086
+ 4.0
1087
+ sage: RDF("nan")
1088
+ NaN
1089
+ sage: RDF(1)/RDF(0)
1090
+ +infinity
1091
+ sage: RDF(-1)/RDF(0)
1092
+ -infinity
1093
+ """
1094
+ return double_repr(self._value)
1095
+
1096
+ def __format__(self, format_spec):
1097
+ """
1098
+ Return a formatted string representation of this real number.
1099
+
1100
+ EXAMPLES::
1101
+
1102
+ sage: format(RDF(32/3), '.4f')
1103
+ '10.6667'
1104
+ sage: '{:.4e}'.format(RDF(2/3))
1105
+ '6.6667e-01'
1106
+ """
1107
+ return format(float(self), format_spec)
1108
+
1109
+ def _latex_(self):
1110
+ r"""
1111
+ Return a latex representation of ``self``.
1112
+
1113
+ EXAMPLES::
1114
+
1115
+ sage: latex(RDF(3.4)) # indirect doctest
1116
+ 3.4
1117
+ sage: latex(RDF(2e-100)) # indirect doctest
1118
+ 2 \times 10^{-100}
1119
+ """
1120
+ s = self.str()
1121
+ parts = s.split('e')
1122
+ if len(parts) > 1:
1123
+ # scientific notation
1124
+ if parts[1][0] == '+':
1125
+ parts[1] = parts[1][1:]
1126
+ s = "%s \\times 10^{%s}" % (parts[0], parts[1])
1127
+ return s
1128
+
1129
+ def __hash__(self):
1130
+ """
1131
+ Return the hash of ``self``, which coincides with the python float
1132
+ (and often int) type.
1133
+
1134
+ EXAMPLES::
1135
+
1136
+ sage: hash(RDF(1.2)) == hash(1.2r)
1137
+ True
1138
+ """
1139
+ return hash(self._value)
1140
+
1141
+ def _im_gens_(self, codomain, im_gens, base_map=None):
1142
+ """
1143
+ Return the image of ``self`` under the homomorphism from the rational
1144
+ field to ``codomain``.
1145
+
1146
+ This always just returns ``self`` coerced into the ``codomain``.
1147
+
1148
+ EXAMPLES::
1149
+
1150
+ sage: RDF(2.1)._im_gens_(RR, [RR(1)])
1151
+ 2.10000000000000
1152
+ sage: R = RealField(20) # needs sage.rings.real_mpfr
1153
+ sage: RDF(2.1)._im_gens_(R, [R(1)]) # needs sage.rings.real_mpfr
1154
+ 2.1000
1155
+ """
1156
+ return codomain(self) # since 1 |--> 1
1157
+
1158
+ def str(self):
1159
+ """
1160
+ Return the informal string representation of ``self``.
1161
+
1162
+ EXAMPLES::
1163
+
1164
+ sage: a = RDF('4.5'); a.str()
1165
+ '4.5'
1166
+ sage: a = RDF('49203480923840.2923904823048'); a.str()
1167
+ '49203480923840.29'
1168
+ sage: a = RDF(1)/RDF(0); a.str()
1169
+ '+infinity'
1170
+ sage: a = -RDF(1)/RDF(0); a.str()
1171
+ '-infinity'
1172
+ sage: a = RDF(0)/RDF(0); a.str()
1173
+ 'NaN'
1174
+
1175
+ We verify consistency with ``RR`` (mpfr reals)::
1176
+
1177
+ sage: str(RR(RDF(1)/RDF(0))) == str(RDF(1)/RDF(0))
1178
+ True
1179
+ sage: str(RR(-RDF(1)/RDF(0))) == str(-RDF(1)/RDF(0))
1180
+ True
1181
+ sage: str(RR(RDF(0)/RDF(0))) == str(RDF(0)/RDF(0))
1182
+ True
1183
+ """
1184
+ return double_repr(self._value)
1185
+
1186
+ def __copy__(self):
1187
+ """
1188
+ Return copy of ``self``, which since ``self`` is immutable, is just
1189
+ ``self``.
1190
+
1191
+ EXAMPLES::
1192
+
1193
+ sage: r = RDF('-1.6')
1194
+ sage: r.__copy__() is r
1195
+ True
1196
+ """
1197
+ return self
1198
+
1199
+ def __deepcopy__(self, memo):
1200
+ """
1201
+ EXAMPLES::
1202
+
1203
+ sage: r = RDF('-1.6')
1204
+ sage: deepcopy(r) is r
1205
+ True
1206
+ """
1207
+ return self
1208
+
1209
+ def integer_part(self):
1210
+ """
1211
+ If in decimal this number is written ``n.defg``, returns ``n``.
1212
+
1213
+ EXAMPLES::
1214
+
1215
+ sage: r = RDF('-1.6')
1216
+ sage: a = r.integer_part(); a
1217
+ -1
1218
+ sage: type(a)
1219
+ <class 'sage.rings.integer.Integer'>
1220
+ sage: r = RDF(0.0/0.0)
1221
+ sage: a = r.integer_part()
1222
+ Traceback (most recent call last):
1223
+ ...
1224
+ TypeError: Attempt to get integer part of NaN
1225
+ """
1226
+ if libc.math.isnan(self._value):
1227
+ raise TypeError("Attempt to get integer part of NaN")
1228
+ else:
1229
+ return Integer(int(self._value))
1230
+
1231
+ def sign_mantissa_exponent(self):
1232
+ r"""
1233
+ Return the sign, mantissa, and exponent of ``self``.
1234
+
1235
+ In Sage (as in MPFR), floating-point numbers of precision `p`
1236
+ are of the form `s m 2^{e-p}`, where `s \in \{-1, 1\}`,
1237
+ `2^{p-1} \leq m < 2^p`, and `-2^{30} + 1 \leq e \leq 2^{30} -
1238
+ 1`; plus the special values ``+0``, ``-0``, ``+infinity``,
1239
+ ``-infinity``, and ``NaN`` (which stands for Not-a-Number).
1240
+
1241
+ This function returns `s`, `m`, and `e-p`. For the special values:
1242
+
1243
+ - ``+0`` returns ``(1, 0, 0)``
1244
+ - ``-0`` returns ``(-1, 0, 0)``
1245
+ - the return values for ``+infinity``, ``-infinity``, and ``NaN`` are
1246
+ not specified.
1247
+
1248
+ EXAMPLES::
1249
+
1250
+ sage: # needs sage.symbolic
1251
+ sage: a = RDF(exp(1.0)); a
1252
+ 2.718281828459045
1253
+ sage: sign, mantissa, exponent = RDF(exp(1.0)).sign_mantissa_exponent()
1254
+ sage: sign, mantissa, exponent
1255
+ (1, 6121026514868073, -51)
1256
+ sage: sign*mantissa*(2**exponent) == a
1257
+ True
1258
+
1259
+ The mantissa is always a nonnegative number::
1260
+
1261
+ sage: RDF(-1).sign_mantissa_exponent() # needs sage.rings.real_mpfr
1262
+ (-1, 4503599627370496, -52)
1263
+
1264
+ TESTS::
1265
+
1266
+ sage: RDF('+0').sign_mantissa_exponent() # needs sage.rings.real_mpfr
1267
+ (1, 0, 0)
1268
+ sage: RDF('-0').sign_mantissa_exponent() # needs sage.rings.real_mpfr
1269
+ (-1, 0, 0)
1270
+ """
1271
+ from sage.rings.real_mpfr import RR
1272
+ return RR(self._value).sign_mantissa_exponent()
1273
+
1274
+ def as_integer_ratio(self):
1275
+ """
1276
+ Return a coprime pair of integers ``(a, b)`` such that ``self``
1277
+ equals ``a / b`` exactly.
1278
+
1279
+ EXAMPLES::
1280
+
1281
+ sage: RDF(0).as_integer_ratio()
1282
+ (0, 1)
1283
+ sage: RDF(1/3).as_integer_ratio()
1284
+ (6004799503160661, 18014398509481984)
1285
+ sage: RDF(37/16).as_integer_ratio()
1286
+ (37, 16)
1287
+ sage: RDF(3^60).as_integer_ratio()
1288
+ (42391158275216203520420085760, 1)
1289
+ """
1290
+ nd = float.as_integer_ratio(self._value)
1291
+ return (Integer(nd[0]), Integer(nd[1]))
1292
+
1293
+ ########################
1294
+ # Basic Arithmetic
1295
+ ########################
1296
+ def __invert__(self):
1297
+ """
1298
+ Compute the multiplicative inverse of ``self``.
1299
+
1300
+ EXAMPLES::
1301
+
1302
+ sage: a = RDF(-1.5)*RDF(2.5)
1303
+ sage: a.__invert__()
1304
+ -0.26666666666666666
1305
+ sage: ~a
1306
+ -0.26666666666666666
1307
+ """
1308
+ cdef RealDoubleElement x = <RealDoubleElement>PY_NEW(RealDoubleElement)
1309
+ x._value = 1.0 / self._value
1310
+ return x
1311
+
1312
+ cpdef _add_(self, right):
1313
+ """
1314
+ Add two real numbers with the same parent.
1315
+
1316
+ EXAMPLES::
1317
+
1318
+ sage: RDF('-1.5') + RDF('2.5') # indirect doctest
1319
+ 1.0
1320
+ """
1321
+ cdef RealDoubleElement x = <RealDoubleElement>PY_NEW(RealDoubleElement)
1322
+ x._value = self._value + (<RealDoubleElement>right)._value
1323
+ return x
1324
+
1325
+ cpdef _sub_(self, right):
1326
+ """
1327
+ Subtract two real numbers with the same parent.
1328
+
1329
+ EXAMPLES::
1330
+
1331
+ sage: RDF('-1.5') - RDF('2.5') # indirect doctest
1332
+ -4.0
1333
+ """
1334
+ cdef RealDoubleElement x = <RealDoubleElement>PY_NEW(RealDoubleElement)
1335
+ x._value = self._value - (<RealDoubleElement>right)._value
1336
+ return x
1337
+
1338
+ cpdef _mul_(self, right):
1339
+ """
1340
+ Multiply two real numbers with the same parent.
1341
+
1342
+ EXAMPLES::
1343
+
1344
+ sage: RDF('-1.5') * RDF('2.5') # indirect doctest
1345
+ -3.75
1346
+ """
1347
+ cdef RealDoubleElement x = <RealDoubleElement>PY_NEW(RealDoubleElement)
1348
+ x._value = self._value * (<RealDoubleElement>right)._value
1349
+ return x
1350
+
1351
+ cpdef _div_(self, right):
1352
+ """
1353
+ Divide ``self`` by ``right``.
1354
+
1355
+ EXAMPLES::
1356
+
1357
+ sage: RDF('-1.5') / RDF('2.5') # indirect doctest
1358
+ -0.6
1359
+ sage: RDF(1)/RDF(0)
1360
+ +infinity
1361
+ """
1362
+ cdef RealDoubleElement x = <RealDoubleElement>PY_NEW(RealDoubleElement)
1363
+ x._value = self._value / (<RealDoubleElement>right)._value
1364
+ return x
1365
+
1366
+ def __neg__(self):
1367
+ """
1368
+ Negate ``self``.
1369
+
1370
+ EXAMPLES::
1371
+
1372
+ sage: -RDF('-1.5')
1373
+ 1.5
1374
+ """
1375
+ cdef RealDoubleElement x = <RealDoubleElement>PY_NEW(RealDoubleElement)
1376
+ x._value = -self._value
1377
+ return x
1378
+
1379
+ def conjugate(self):
1380
+ r"""
1381
+ Return the complex conjugate of this real number, which is
1382
+ the real number itself.
1383
+
1384
+ EXAMPLES::
1385
+
1386
+ sage: RDF(4).conjugate()
1387
+ 4.0
1388
+ """
1389
+ return self
1390
+
1391
+ def __abs__(self):
1392
+ """
1393
+ Return the absolute value of ``self``.
1394
+
1395
+ EXAMPLES::
1396
+
1397
+ sage: abs(RDF(1.5))
1398
+ 1.5
1399
+ sage: abs(RDF(-1.5))
1400
+ 1.5
1401
+ sage: abs(RDF(0.0))
1402
+ 0.0
1403
+ sage: abs(RDF(-0.0))
1404
+ 0.0
1405
+ """
1406
+ # Use signbit instead of >= to handle -0.0 correctly
1407
+ if not libc.math.signbit(self._value):
1408
+ return self
1409
+ else:
1410
+ return self._new_c(-self._value)
1411
+
1412
+ cpdef RealDoubleElement abs(RealDoubleElement self):
1413
+ """
1414
+ Return the absolute value of ``self``.
1415
+
1416
+ EXAMPLES::
1417
+
1418
+ sage: RDF(1e10).abs()
1419
+ 10000000000.0
1420
+ sage: RDF(-1e10).abs()
1421
+ 10000000000.0
1422
+ """
1423
+ if self._value >= 0:
1424
+ return self
1425
+ else:
1426
+ return self._new_c(-self._value)
1427
+
1428
+ def __lshift__(x, y):
1429
+ """
1430
+ LShifting a double is not supported; nor is lshifting a
1431
+ :class:`RealDoubleElement`.
1432
+
1433
+ TESTS::
1434
+
1435
+ sage: RDF(2) << 3
1436
+ Traceback (most recent call last):
1437
+ ...
1438
+ TypeError: unsupported operand type(s) for <<
1439
+ """
1440
+ raise TypeError("unsupported operand type(s) for <<")
1441
+
1442
+ def __rshift__(x, y):
1443
+ """
1444
+ RShifting a double is not supported; nor is rshifting a
1445
+ :class:`RealDoubleElement`.
1446
+
1447
+ TESTS::
1448
+
1449
+ sage: RDF(2) >> 3
1450
+ Traceback (most recent call last):
1451
+ ...
1452
+ TypeError: unsupported operand type(s) for >>
1453
+ """
1454
+ raise TypeError("unsupported operand type(s) for >>")
1455
+
1456
+ def multiplicative_order(self):
1457
+ r"""
1458
+ Return `n` such that ``self^n == 1``.
1459
+
1460
+ Only `\pm 1` have finite multiplicative order.
1461
+
1462
+ EXAMPLES::
1463
+
1464
+ sage: RDF(1).multiplicative_order()
1465
+ 1
1466
+ sage: RDF(-1).multiplicative_order()
1467
+ 2
1468
+ sage: RDF(3).multiplicative_order()
1469
+ +Infinity
1470
+ """
1471
+ if self._value == 1:
1472
+ return 1
1473
+ elif self._value == -1:
1474
+ return 2
1475
+ return sage.rings.infinity.infinity
1476
+
1477
+ def sign(self):
1478
+ """
1479
+ Return -1, 0, or 1 if ``self`` is negative, zero, or positive;
1480
+ respectively.
1481
+
1482
+ EXAMPLES::
1483
+
1484
+ sage: RDF(-1.5).sign()
1485
+ -1
1486
+ sage: RDF(0).sign()
1487
+ 0
1488
+ sage: RDF(2.5).sign()
1489
+ 1
1490
+ """
1491
+ if not self._value:
1492
+ return 0
1493
+ if self._value > 0:
1494
+ return 1
1495
+ return -1
1496
+
1497
+ ###################
1498
+ # Rounding etc
1499
+ ###################
1500
+
1501
+ def round(self):
1502
+ """
1503
+ Round ``self`` to the nearest integer.
1504
+
1505
+ This uses the convention of rounding half to even
1506
+ (i.e., if the fractional part of ``self`` is `0.5`, then it
1507
+ is rounded to the nearest even integer).
1508
+
1509
+ EXAMPLES::
1510
+
1511
+ sage: RDF(0.49).round()
1512
+ 0
1513
+ sage: a=RDF(0.51).round(); a
1514
+ 1
1515
+ sage: RDF(0.5).round()
1516
+ 0
1517
+ sage: RDF(1.5).round()
1518
+ 2
1519
+ """
1520
+ return Integer(round(self._value))
1521
+
1522
+ def floor(self):
1523
+ """
1524
+ Return the floor of ``self``.
1525
+
1526
+ EXAMPLES::
1527
+
1528
+ sage: RDF(2.99).floor()
1529
+ 2
1530
+ sage: RDF(2.00).floor()
1531
+ 2
1532
+ sage: RDF(-5/2).floor()
1533
+ -3
1534
+ """
1535
+ return Integer(math.floor(self._value))
1536
+
1537
+ def ceil(self):
1538
+ """
1539
+ Return the ceiling of ``self``.
1540
+
1541
+ EXAMPLES::
1542
+
1543
+ sage: RDF(2.99).ceil()
1544
+ 3
1545
+ sage: RDF(2.00).ceil()
1546
+ 2
1547
+ sage: RDF(-5/2).ceil()
1548
+ -2
1549
+ """
1550
+ return Integer(math.ceil(self._value))
1551
+
1552
+ ceiling = ceil
1553
+
1554
+ def trunc(self):
1555
+ """
1556
+ Truncates this number (returns integer part).
1557
+
1558
+ EXAMPLES::
1559
+
1560
+ sage: RDF(2.99).trunc()
1561
+ 2
1562
+ sage: RDF(-2.00).trunc()
1563
+ -2
1564
+ sage: RDF(0.00).trunc()
1565
+ 0
1566
+ """
1567
+ return Integer(int(self._value))
1568
+
1569
+ def frac(self):
1570
+ """
1571
+ Return a real number in `(-1, 1)`. It satisfies the relation:
1572
+ ``x = x.trunc() + x.frac()``
1573
+
1574
+ EXAMPLES::
1575
+
1576
+ sage: RDF(2.99).frac()
1577
+ 0.9900000000000002
1578
+ sage: RDF(2.50).frac()
1579
+ 0.5
1580
+ sage: RDF(-2.79).frac()
1581
+ -0.79
1582
+ """
1583
+ return self._new_c(self._value - int(self._value))
1584
+
1585
+ ###########################################
1586
+ # Conversions
1587
+ ###########################################
1588
+
1589
+ def __float__(self):
1590
+ """
1591
+ Return ``self`` as a python float.
1592
+
1593
+ EXAMPLES::
1594
+
1595
+ sage: float(RDF(1.5))
1596
+ 1.5
1597
+ sage: type(float(RDF(1.5)))
1598
+ <... 'float'>
1599
+ """
1600
+ return self._value
1601
+
1602
+ def _rpy_(self):
1603
+ """
1604
+ Return ``self.__float__()`` for rpy to convert into the
1605
+ appropriate R object.
1606
+
1607
+ EXAMPLES::
1608
+
1609
+ sage: n = RDF(2.0)
1610
+ sage: n._rpy_()
1611
+ 2.0
1612
+ sage: type(n._rpy_())
1613
+ <... 'float'>
1614
+ """
1615
+ return self.__float__()
1616
+
1617
+ def __int__(self):
1618
+ """
1619
+ Return integer truncation of this real number.
1620
+
1621
+ EXAMPLES::
1622
+
1623
+ sage: int(RDF(2.99))
1624
+ 2
1625
+ sage: int(RDF(-2.99))
1626
+ -2
1627
+ """
1628
+ return int(self._value)
1629
+
1630
+ def _complex_mpfr_field_(self, CC):
1631
+ """
1632
+ EXAMPLES::
1633
+
1634
+ sage: a = RDF(1/3)
1635
+ sage: CC(a) # needs sage.rings.real_mpfr
1636
+ 0.333333333333333
1637
+ sage: a._complex_mpfr_field_(CC) # needs sage.rings.real_mpfr
1638
+ 0.333333333333333
1639
+
1640
+ If we coerce to a higher-precision field the extra bits appear
1641
+ random; they are actually 0s in base 2.
1642
+
1643
+ ::
1644
+
1645
+ sage: a._complex_mpfr_field_(ComplexField(100)) # needs sage.rings.real_mpfr
1646
+ 0.33333333333333331482961625625
1647
+ sage: a._complex_mpfr_field_(ComplexField(100)).str(2) # needs sage.rings.real_mpfr
1648
+ '0.01010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000'
1649
+ """
1650
+ return CC(self._value)
1651
+
1652
+ def _complex_double_(self, CDF):
1653
+ """
1654
+ Return ``self`` as a complex double.
1655
+
1656
+ EXAMPLES::
1657
+
1658
+ sage: CDF(RDF(1/3)) # indirect doctest # needs sage.rings.complex_double
1659
+ 0.3333333333333333
1660
+ """
1661
+ return CDF(self._value)
1662
+
1663
+ def __pari__(self):
1664
+ """
1665
+ Return a PARI representation of ``self``.
1666
+
1667
+ EXAMPLES::
1668
+
1669
+ sage: RDF(1.5).__pari__() # needs sage.libs.pari
1670
+ 1.50000000000000
1671
+ """
1672
+ global new_gen_from_real_double_element
1673
+ if new_gen_from_real_double_element is None:
1674
+ from sage.libs.pari.convert_sage_real_double import new_gen_from_real_double_element
1675
+ return new_gen_from_real_double_element(self)
1676
+
1677
+ ###########################################
1678
+ # Comparisons: ==, !=, <, <=, >, >=
1679
+ ###########################################
1680
+
1681
+ def is_NaN(self):
1682
+ """
1683
+ Check if ``self`` is ``NaN``.
1684
+
1685
+ EXAMPLES::
1686
+
1687
+ sage: RDF(1).is_NaN()
1688
+ False
1689
+ sage: a = RDF(0)/RDF(0)
1690
+ sage: a.is_NaN()
1691
+ True
1692
+ """
1693
+ return bool(libc.math.isnan(self._value))
1694
+
1695
+ def is_positive_infinity(self):
1696
+ r"""
1697
+ Check if ``self`` is `+\infty`.
1698
+
1699
+ EXAMPLES::
1700
+
1701
+ sage: a = RDF(1)/RDF(0)
1702
+ sage: a.is_positive_infinity()
1703
+ True
1704
+ sage: a = RDF(-1)/RDF(0)
1705
+ sage: a.is_positive_infinity()
1706
+ False
1707
+ """
1708
+ if not libc.math.isinf(self._value):
1709
+ return False
1710
+ return self._value > 0
1711
+
1712
+ def is_negative_infinity(self):
1713
+ r"""
1714
+ Check if ``self`` is `-\infty`.
1715
+
1716
+ EXAMPLES::
1717
+
1718
+ sage: a = RDF(2)/RDF(0)
1719
+ sage: a.is_negative_infinity()
1720
+ False
1721
+ sage: a = RDF(-3)/RDF(0)
1722
+ sage: a.is_negative_infinity()
1723
+ True
1724
+ """
1725
+ if not libc.math.isinf(self._value):
1726
+ return False
1727
+ return self._value < 0
1728
+
1729
+ def is_infinity(self):
1730
+ r"""
1731
+ Check if ``self`` is `\infty`.
1732
+
1733
+ EXAMPLES::
1734
+
1735
+ sage: a = RDF(2); b = RDF(0)
1736
+ sage: (a/b).is_infinity()
1737
+ True
1738
+ sage: (b/a).is_infinity()
1739
+ False
1740
+ """
1741
+ return bool(libc.math.isinf(self._value))
1742
+
1743
+ cpdef _richcmp_(left, right, int op):
1744
+ """
1745
+ Rich comparison of ``left`` and ``right``.
1746
+
1747
+ EXAMPLES::
1748
+
1749
+ sage: RDF(2) < RDF(0)
1750
+ False
1751
+ sage: RDF(2) == RDF(4/2)
1752
+ True
1753
+ sage: RDF(-2) > RDF(-4)
1754
+ True
1755
+
1756
+ TESTS:
1757
+
1758
+ Check comparisons with ``NaN`` (:issue:`16515`)::
1759
+
1760
+ sage: n = RDF('NaN')
1761
+ sage: n == n
1762
+ False
1763
+ sage: n == RDF(1)
1764
+ False
1765
+ """
1766
+ # We really need to use the correct operators, to deal
1767
+ # correctly with NaNs.
1768
+ cdef double x = (<RealDoubleElement>left)._value
1769
+ cdef double y = (<RealDoubleElement>right)._value
1770
+ if op == Py_LT:
1771
+ return x < y
1772
+ elif op == Py_LE:
1773
+ return x <= y
1774
+ elif op == Py_EQ:
1775
+ return x == y
1776
+ elif op == Py_NE:
1777
+ return x != y
1778
+ elif op == Py_GT:
1779
+ return x > y
1780
+ else:
1781
+ return x >= y
1782
+
1783
+ ############################
1784
+ # Special Functions
1785
+ ############################
1786
+
1787
+ def NaN(self):
1788
+ """
1789
+ Return Not-a-Number ``NaN``.
1790
+
1791
+ EXAMPLES::
1792
+
1793
+ sage: RDF.NaN()
1794
+ NaN
1795
+ """
1796
+ return self(0)/self(0)
1797
+
1798
+ nan = NaN
1799
+
1800
+ def sqrt(self, extend=True, all=False):
1801
+ """
1802
+ The square root function.
1803
+
1804
+ INPUT:
1805
+
1806
+ - ``extend`` -- boolean (default: ``True``); if ``True``, return a
1807
+ square root in a complex field if necessary if ``self`` is negative.
1808
+ Otherwise raise a :exc:`ValueError`.
1809
+
1810
+ - ``all`` -- boolean (default: ``False``); if ``True``, return a
1811
+ list of all square roots
1812
+
1813
+ EXAMPLES::
1814
+
1815
+ sage: r = RDF(4.0)
1816
+ sage: r.sqrt()
1817
+ 2.0
1818
+ sage: r.sqrt()^2 == r
1819
+ True
1820
+
1821
+ ::
1822
+
1823
+ sage: r = RDF(4344)
1824
+ sage: r.sqrt()
1825
+ 65.90902821313632
1826
+ sage: r.sqrt()^2 - r
1827
+ 0.0
1828
+
1829
+ ::
1830
+
1831
+ sage: r = RDF(-2.0)
1832
+ sage: r.sqrt() # needs sage.rings.complex_double
1833
+ 1.4142135623730951*I
1834
+
1835
+ ::
1836
+
1837
+ sage: RDF(2).sqrt(all=True)
1838
+ [1.4142135623730951, -1.4142135623730951]
1839
+ sage: RDF(0).sqrt(all=True)
1840
+ [0.0]
1841
+ sage: RDF(-2).sqrt(all=True) # needs sage.rings.complex_double
1842
+ [1.4142135623730951*I, -1.4142135623730951*I]
1843
+ """
1844
+ if self._value >= 0:
1845
+ x = self._new_c(libc.math.sqrt(self._value))
1846
+ if all:
1847
+ if x.is_zero():
1848
+ return [x]
1849
+ else:
1850
+ return [x, -x]
1851
+ else:
1852
+ return x
1853
+ if not extend:
1854
+ raise ValueError("negative number %s does not have a square root in the real field" % self)
1855
+ import sage.rings.complex_double
1856
+ return self._complex_double_(sage.rings.complex_double.CDF).sqrt(all=all)
1857
+
1858
+ def is_square(self):
1859
+ """
1860
+ Return whether or not this number is a square in this field. For
1861
+ the real numbers, this is ``True`` if and only if ``self`` is
1862
+ nonnegative.
1863
+
1864
+ EXAMPLES::
1865
+
1866
+ sage: RDF(3.5).is_square()
1867
+ True
1868
+ sage: RDF(0).is_square()
1869
+ True
1870
+ sage: RDF(-4).is_square()
1871
+ False
1872
+ """
1873
+ return self._value >= 0
1874
+
1875
+ def is_integer(self):
1876
+ """
1877
+ Return ``True`` if this number is a integer.
1878
+
1879
+ EXAMPLES::
1880
+
1881
+ sage: RDF(3.5).is_integer()
1882
+ False
1883
+ sage: RDF(3).is_integer()
1884
+ True
1885
+ """
1886
+ return self._value in ZZ
1887
+
1888
+ def cube_root(self):
1889
+ """
1890
+ Return the cubic root (defined over the real numbers) of ``self``.
1891
+
1892
+ EXAMPLES::
1893
+
1894
+ sage: r = RDF(125.0); r.cube_root()
1895
+ 5.000000000000001
1896
+ sage: r = RDF(-119.0)
1897
+ sage: r.cube_root()^3 - r # rel tol 1
1898
+ -1.4210854715202004e-14
1899
+ """
1900
+ return self.nth_root(3)
1901
+
1902
+ def agm(self, other):
1903
+ r"""
1904
+ Return the arithmetic-geometric mean of ``self`` and ``other``. The
1905
+ arithmetic-geometric mean is the common limit of the sequences
1906
+ `u_n` and `v_n`, where `u_0` is ``self``,
1907
+ `v_0` is other, `u_{n+1}` is the arithmetic mean
1908
+ of `u_n` and `v_n`, and `v_{n+1}` is the
1909
+ geometric mean of `u_n` and `v_n`. If any operand is negative, the
1910
+ return value is ``NaN``.
1911
+
1912
+ EXAMPLES::
1913
+
1914
+ sage: a = RDF(1.5)
1915
+ sage: b = RDF(2.3)
1916
+ sage: a.agm(b)
1917
+ 1.8786484558146697
1918
+
1919
+ The arithmetic-geometric mean always lies between the geometric and
1920
+ arithmetic mean::
1921
+
1922
+ sage: sqrt(a*b) < a.agm(b) < (a+b)/2
1923
+ True
1924
+ """
1925
+ cdef double a = self._value
1926
+ cdef double b = other
1927
+ cdef double eps = 2.0**-51
1928
+ if a < 0 or b < 0:
1929
+ return self._parent.nan()
1930
+ while True:
1931
+ a1 = (a+b)/2
1932
+ b1 = libc.math.sqrt(a*b)
1933
+ if abs((b1/a1)-1) < eps:
1934
+ return self._new_c(a1)
1935
+ a, b = a1, b1
1936
+
1937
+ def algebraic_dependency(self, n):
1938
+ """
1939
+ Return a polynomial of degree at most `n` which is
1940
+ approximately satisfied by this number.
1941
+
1942
+ .. NOTE::
1943
+
1944
+ The resulting polynomial need not be irreducible, and indeed
1945
+ usually won't be if this number is a good approximation to an
1946
+ algebraic number of degree less than `n`.
1947
+
1948
+ ALGORITHM:
1949
+
1950
+ Uses the PARI C-library :pari:`algdep` command.
1951
+
1952
+ EXAMPLES::
1953
+
1954
+ sage: r = sqrt(RDF(2)); r
1955
+ 1.4142135623730951
1956
+ sage: r.algebraic_dependency(5) # needs sage.libs.pari
1957
+ x^2 - 2
1958
+ """
1959
+ return sage.arith.misc.algebraic_dependency(self, n)
1960
+
1961
+ algdep = algebraic_dependency
1962
+
1963
+ cdef class ToRDF(Morphism):
1964
+ def __init__(self, R):
1965
+ """
1966
+ Fast morphism from anything with a ``__float__`` method to an ``RDF``
1967
+ element.
1968
+
1969
+ EXAMPLES::
1970
+
1971
+ sage: f = RDF.coerce_map_from(ZZ); f
1972
+ Native morphism:
1973
+ From: Integer Ring
1974
+ To: Real Double Field
1975
+ sage: f(4)
1976
+ 4.0
1977
+ sage: f = RDF.coerce_map_from(QQ); f
1978
+ Native morphism:
1979
+ From: Rational Field
1980
+ To: Real Double Field
1981
+ sage: f(1/2)
1982
+ 0.5
1983
+ sage: f = RDF.coerce_map_from(int); f
1984
+ Native morphism:
1985
+ From: Set of Python objects of class 'int'
1986
+ To: Real Double Field
1987
+ sage: f(3r)
1988
+ 3.0
1989
+ sage: f = RDF.coerce_map_from(float); f
1990
+ Native morphism:
1991
+ From: Set of Python objects of class 'float'
1992
+ To: Real Double Field
1993
+ sage: f(3.5)
1994
+ 3.5
1995
+ """
1996
+ from sage.categories.homset import Hom
1997
+ if isinstance(R, type):
1998
+ from sage.sets.pythonclass import Set_PythonType
1999
+ R = Set_PythonType(R)
2000
+ Morphism.__init__(self, Hom(R, RDF))
2001
+
2002
+ cpdef Element _call_(self, x):
2003
+ """
2004
+ Send ``x`` to the image under this map.
2005
+
2006
+ EXAMPLES::
2007
+
2008
+ sage: f = RDF.coerce_map_from(float)
2009
+ sage: f(3.5) # indirect doctest
2010
+ 3.5
2011
+ """
2012
+ cdef RealDoubleElement r = <RealDoubleElement>PY_NEW(RealDoubleElement)
2013
+ r._value = PyFloat_AsDouble(x)
2014
+ return r
2015
+
2016
+ def _repr_type(self):
2017
+ """
2018
+ Return the representation type of ``self``.
2019
+
2020
+ EXAMPLES::
2021
+
2022
+ sage: RDF.coerce_map_from(float)._repr_type()
2023
+ 'Native'
2024
+ """
2025
+ return "Native"
2026
+
2027
+
2028
+ #####################################################
2029
+ # unique objects
2030
+ #####################################################
2031
+ cdef RealDoubleField_class _RDF
2032
+ _RDF = RealDoubleField_class()
2033
+
2034
+ RDF = _RDF # external interface
2035
+
2036
+
2037
+ def RealDoubleField():
2038
+ """
2039
+ Return the unique instance of the
2040
+ :class:`real double field<RealDoubleField_class>`.
2041
+
2042
+ EXAMPLES::
2043
+
2044
+ sage: RealDoubleField() is RealDoubleField()
2045
+ True
2046
+ """
2047
+ global _RDF
2048
+ return _RDF
2049
+
2050
+
2051
+ def is_RealDoubleElement(x):
2052
+ """
2053
+ Check if ``x`` is an element of the real double field.
2054
+
2055
+ EXAMPLES::
2056
+
2057
+ sage: from sage.rings.real_double import is_RealDoubleElement
2058
+ sage: is_RealDoubleElement(RDF(3))
2059
+ doctest:warning...
2060
+ DeprecationWarning: The function is_RealDoubleElement is deprecated;
2061
+ use 'isinstance(..., RealDoubleElement)' instead.
2062
+ See https://github.com/sagemath/sage/issues/38128 for details.
2063
+ True
2064
+ sage: is_RealDoubleElement(RIF(3)) # needs sage.rings.real_interval_field
2065
+ False
2066
+ """
2067
+ from sage.misc.superseded import deprecation_cython
2068
+ deprecation_cython(38128,
2069
+ "The function is_RealDoubleElement is deprecated; "
2070
+ "use 'isinstance(..., RealDoubleElement)' instead.")
2071
+ return isinstance(x, RealDoubleElement)
2072
+
2073
+
2074
+ # ################ FAST CREATION CODE ######################
2075
+ # Based on fast integer creation code
2076
+ # There is nothing to see here, move along
2077
+
2078
+ # We use a global element to steal all the references
2079
+ # from. DO NOT INITIALIZE IT AGAIN and DO NOT REFERENCE IT!
2080
+ cdef RealDoubleElement global_dummy_element
2081
+
2082
+ try:
2083
+ from sage.rings.real_double_element_gsl import RealDoubleElement_gsl
2084
+ except ImportError:
2085
+ global_dummy_element = RealDoubleElement(0)
2086
+ else:
2087
+ global_dummy_element = RealDoubleElement_gsl(0)
2088
+
2089
+ # A global pool for performance when elements are rapidly created and destroyed.
2090
+ # It operates on the following principles:
2091
+ #
2092
+ # - The pool starts out empty.
2093
+ # - When a new element is needed, one from the pool is returned
2094
+ # if available, otherwise a new RealDoubleElement object is created
2095
+ # - When an element is collected, it will add it to the pool
2096
+ # if there is room, otherwise it will be deallocated.
2097
+ DEF element_pool_size = 50
2098
+
2099
+ cdef PyObject* element_pool[element_pool_size]
2100
+ cdef int element_pool_count = 0
2101
+
2102
+ # used for profiling the pool
2103
+ cdef int total_alloc = 0
2104
+ cdef int use_pool = 0
2105
+
2106
+
2107
+ cdef PyObject* fast_tp_new(type t, args, kwds) noexcept:
2108
+ global element_pool, element_pool_count, total_alloc, use_pool
2109
+
2110
+ cdef PyObject* new
2111
+
2112
+ # for profiling pool usage
2113
+ # total_alloc += 1
2114
+
2115
+ # If there is a ready real double in the pool, we will
2116
+ # decrement the counter and return that.
2117
+
2118
+ if element_pool_count > 0:
2119
+
2120
+ # for profiling pool usage
2121
+ # use_pool += 1
2122
+
2123
+ element_pool_count -= 1
2124
+ new = <PyObject *> element_pool[element_pool_count]
2125
+
2126
+ # Otherwise, we have to create one.
2127
+
2128
+ else:
2129
+
2130
+ # allocate enough room for the RealDoubleElement,
2131
+ # sizeof_RealDoubleElement is sizeof(RealDoubleElement).
2132
+ # The use of PyObject_Malloc directly assumes
2133
+ # that RealDoubleElements are not garbage collected, i.e.
2134
+ # they do not possess references to other Python
2135
+ # objects (As indicated by the Py_TPFLAGS_HAVE_GC flag).
2136
+ # See below for a more detailed description.
2137
+
2138
+ new = <PyObject*>PyObject_Malloc(sizeof(RealDoubleElement))
2139
+
2140
+ # Now set every member as set in z, the global dummy RealDoubleElement
2141
+ # created before this tp_new started to operate.
2142
+
2143
+ memcpy(new, (<void*>global_dummy_element), sizeof(RealDoubleElement))
2144
+
2145
+ # This line is only needed if Python is compiled in debugging mode
2146
+ # './configure --with-pydebug' or SAGE_DEBUG=yes. If that is the
2147
+ # case a Python object has a bunch of debugging fields which are
2148
+ # initialized with this macro.
2149
+ if_Py_TRACE_REFS_then_PyObject_INIT(
2150
+ new, Py_TYPE(global_dummy_element))
2151
+
2152
+ # The global_dummy_element may have a reference count larger than
2153
+ # one, but it is expected that newly created objects have a
2154
+ # reference count of one. This is potentially unneeded if
2155
+ # everybody plays nice, because the global_dummy_element has only
2156
+ # one reference in that case.
2157
+
2158
+ # Objects from the pool have reference count zero, so this
2159
+ # needs to be set in this case.
2160
+
2161
+ new.ob_refcnt = 1
2162
+
2163
+ return new
2164
+
2165
+ cdef void fast_tp_dealloc(PyObject* o) noexcept:
2166
+
2167
+ # If there is room in the pool for a used integer object,
2168
+ # then put it in rather than deallocating it.
2169
+
2170
+ global element_pool, element_pool_count
2171
+
2172
+ if element_pool_count < element_pool_size:
2173
+
2174
+ # And add it to the pool.
2175
+ element_pool[element_pool_count] = o
2176
+ element_pool_count += 1
2177
+ return
2178
+
2179
+ # Free the object. This assumes that Py_TPFLAGS_HAVE_GC is not
2180
+ # set. If it was set another free function would need to be
2181
+ # called.
2182
+
2183
+ PyObject_Free(o)
2184
+
2185
+
2186
+ from sage.misc.allocator cimport hook_tp_functions, hook_tp_functions_type
2187
+ hook_tp_functions(global_dummy_element, <newfunc>(&fast_tp_new), <destructor>(&fast_tp_dealloc), False)
2188
+ try:
2189
+ from sage.rings.real_double_element_gsl import RealDoubleElement_gsl
2190
+ except Exception:
2191
+ pass
2192
+ else:
2193
+ # global_dummy_element is of type RealDoubleElement_gsl,
2194
+ # so hook the base class now.
2195
+ hook_tp_functions_type(RealDoubleElement, <newfunc>(&fast_tp_new), <destructor>(&fast_tp_dealloc), False)
2196
+ # From here on, calling PY_NEW(RealDoubleElement) actually creates an instance of RealDoubleElement_gsl
2197
+
2198
+
2199
+ cdef double_repr(double x):
2200
+ """
2201
+ Convert a double to a string with maximum precision.
2202
+ """
2203
+ if libc.math.isfinite(x):
2204
+ return repr(x)
2205
+ if libc.math.isinf(x):
2206
+ if x > 0:
2207
+ return "+infinity"
2208
+ if x < 0:
2209
+ return "-infinity"
2210
+ return "NaN"
2211
+
2212
+
2213
+ # Support Python's numbers abstract base class
2214
+ import numbers
2215
+ numbers.Real.register(RealDoubleElement)