passagemath-flint 10.6.1rc10__cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_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 (360) hide show
  1. passagemath_flint-10.6.1rc10.dist-info/METADATA +122 -0
  2. passagemath_flint-10.6.1rc10.dist-info/RECORD +360 -0
  3. passagemath_flint-10.6.1rc10.dist-info/WHEEL +6 -0
  4. passagemath_flint-10.6.1rc10.dist-info/top_level.txt +2 -0
  5. passagemath_flint.libs/libflint-3701249d.so.21.0.0 +0 -0
  6. passagemath_flint.libs/libgf2x-fbd36f80.so.3.0.0 +0 -0
  7. passagemath_flint.libs/libgfortran-8a9a71bc.so.5.0.0 +0 -0
  8. passagemath_flint.libs/libgmp-93ebf16a.so.10.5.0 +0 -0
  9. passagemath_flint.libs/libgsl-e3525837.so.28.0.0 +0 -0
  10. passagemath_flint.libs/libmpfi-ad12a86d.so.0.0.0 +0 -0
  11. passagemath_flint.libs/libmpfr-e0f11cf3.so.6.2.1 +0 -0
  12. passagemath_flint.libs/libntl-1004113e.so.44.0.1 +0 -0
  13. passagemath_flint.libs/libopenblasp-r0-4c5b64b1.3.29.so +0 -0
  14. sage/all__sagemath_flint.py +29 -0
  15. sage/combinat/all__sagemath_flint.py +1 -0
  16. sage/combinat/posets/all__sagemath_flint.py +1 -0
  17. sage/combinat/posets/hasse_cython_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  18. sage/combinat/posets/hasse_cython_flint.pyx +194 -0
  19. sage/data_structures/all__sagemath_flint.py +1 -0
  20. sage/data_structures/bounded_integer_sequences.cpython-312-aarch64-linux-gnu.so +0 -0
  21. sage/data_structures/bounded_integer_sequences.pxd +62 -0
  22. sage/data_structures/bounded_integer_sequences.pyx +1418 -0
  23. sage/graphs/all__sagemath_flint.py +1 -0
  24. sage/graphs/chrompoly.cpython-312-aarch64-linux-gnu.so +0 -0
  25. sage/graphs/chrompoly.pyx +555 -0
  26. sage/graphs/matchpoly.cpython-312-aarch64-linux-gnu.so +0 -0
  27. sage/graphs/matchpoly.pyx +412 -0
  28. sage/libs/all__sagemath_flint.py +17 -0
  29. sage/libs/arb/__init__.py +1 -0
  30. sage/libs/arb/acb.pxd +154 -0
  31. sage/libs/arb/acb_calc.pxd +9 -0
  32. sage/libs/arb/acb_elliptic.pxd +25 -0
  33. sage/libs/arb/acb_hypgeom.pxd +74 -0
  34. sage/libs/arb/acb_mat.pxd +62 -0
  35. sage/libs/arb/acb_modular.pxd +17 -0
  36. sage/libs/arb/acb_poly.pxd +216 -0
  37. sage/libs/arb/arb.pxd +240 -0
  38. sage/libs/arb/arb_fmpz_poly.pxd +21 -0
  39. sage/libs/arb/arb_hypgeom.pxd +83 -0
  40. sage/libs/arb/arb_wrap.h +34 -0
  41. sage/libs/arb/arf.pxd +131 -0
  42. sage/libs/arb/arith.cpython-312-aarch64-linux-gnu.so +0 -0
  43. sage/libs/arb/arith.pyx +87 -0
  44. sage/libs/arb/bernoulli.pxd +6 -0
  45. sage/libs/arb/mag.pxd +77 -0
  46. sage/libs/arb/types.pxd +37 -0
  47. sage/libs/flint/__init__.py +1 -0
  48. sage/libs/flint/acb.pxd +270 -0
  49. sage/libs/flint/acb_calc.pxd +22 -0
  50. sage/libs/flint/acb_dft.pxd +51 -0
  51. sage/libs/flint/acb_dirichlet.pxd +112 -0
  52. sage/libs/flint/acb_elliptic.pxd +42 -0
  53. sage/libs/flint/acb_hypgeom.pxd +169 -0
  54. sage/libs/flint/acb_macros.pxd +9 -0
  55. sage/libs/flint/acb_mat.pxd +136 -0
  56. sage/libs/flint/acb_mat_macros.pxd +10 -0
  57. sage/libs/flint/acb_modular.pxd +62 -0
  58. sage/libs/flint/acb_poly.pxd +251 -0
  59. sage/libs/flint/acb_poly_macros.pxd +8 -0
  60. sage/libs/flint/acb_theta.pxd +124 -0
  61. sage/libs/flint/acf.pxd +32 -0
  62. sage/libs/flint/aprcl.pxd +84 -0
  63. sage/libs/flint/arb.pxd +382 -0
  64. sage/libs/flint/arb_calc.pxd +31 -0
  65. sage/libs/flint/arb_fmpz_poly.pxd +34 -0
  66. sage/libs/flint/arb_fpwrap.pxd +215 -0
  67. sage/libs/flint/arb_hypgeom.pxd +147 -0
  68. sage/libs/flint/arb_macros.pxd +9 -0
  69. sage/libs/flint/arb_mat.pxd +140 -0
  70. sage/libs/flint/arb_mat_macros.pxd +10 -0
  71. sage/libs/flint/arb_poly.pxd +237 -0
  72. sage/libs/flint/arf.pxd +167 -0
  73. sage/libs/flint/arith.cpython-312-aarch64-linux-gnu.so +0 -0
  74. sage/libs/flint/arith.pxd +76 -0
  75. sage/libs/flint/arith.pyx +77 -0
  76. sage/libs/flint/arith_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  77. sage/libs/flint/arith_sage.pyx +308 -0
  78. sage/libs/flint/bernoulli.pxd +28 -0
  79. sage/libs/flint/bool_mat.pxd +52 -0
  80. sage/libs/flint/ca.pxd +203 -0
  81. sage/libs/flint/ca_ext.pxd +34 -0
  82. sage/libs/flint/ca_field.pxd +32 -0
  83. sage/libs/flint/ca_mat.pxd +117 -0
  84. sage/libs/flint/ca_poly.pxd +104 -0
  85. sage/libs/flint/ca_vec.pxd +46 -0
  86. sage/libs/flint/calcium.pxd +27 -0
  87. sage/libs/flint/d_mat.pxd +39 -0
  88. sage/libs/flint/d_vec.pxd +32 -0
  89. sage/libs/flint/dirichlet.pxd +57 -0
  90. sage/libs/flint/dlog.pxd +53 -0
  91. sage/libs/flint/double_extras.pxd +24 -0
  92. sage/libs/flint/double_interval.pxd +36 -0
  93. sage/libs/flint/fexpr.pxd +104 -0
  94. sage/libs/flint/fexpr_builtin.pxd +20 -0
  95. sage/libs/flint/fft.pxd +66 -0
  96. sage/libs/flint/flint.pxd +36 -0
  97. sage/libs/flint/flint_ntl_wrap.h +35 -0
  98. sage/libs/flint/flint_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  99. sage/libs/flint/flint_sage.pyx +163 -0
  100. sage/libs/flint/flint_wrap.h +190 -0
  101. sage/libs/flint/fmpq.pxd +137 -0
  102. sage/libs/flint/fmpq_mat.pxd +105 -0
  103. sage/libs/flint/fmpq_mat_macros.pxd +10 -0
  104. sage/libs/flint/fmpq_mpoly.pxd +165 -0
  105. sage/libs/flint/fmpq_mpoly_factor.pxd +30 -0
  106. sage/libs/flint/fmpq_poly.pxd +241 -0
  107. sage/libs/flint/fmpq_poly_macros.pxd +9 -0
  108. sage/libs/flint/fmpq_poly_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  109. sage/libs/flint/fmpq_poly_sage.pxd +31 -0
  110. sage/libs/flint/fmpq_poly_sage.pyx +48 -0
  111. sage/libs/flint/fmpq_vec.pxd +27 -0
  112. sage/libs/flint/fmpz.pxd +256 -0
  113. sage/libs/flint/fmpz_extras.pxd +32 -0
  114. sage/libs/flint/fmpz_factor.pxd +42 -0
  115. sage/libs/flint/fmpz_factor_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  116. sage/libs/flint/fmpz_factor_sage.pxd +4 -0
  117. sage/libs/flint/fmpz_factor_sage.pyx +29 -0
  118. sage/libs/flint/fmpz_lll.pxd +49 -0
  119. sage/libs/flint/fmpz_macros.pxd +8 -0
  120. sage/libs/flint/fmpz_mat.pxd +184 -0
  121. sage/libs/flint/fmpz_mat_macros.pxd +10 -0
  122. sage/libs/flint/fmpz_mod.pxd +46 -0
  123. sage/libs/flint/fmpz_mod_mat.pxd +71 -0
  124. sage/libs/flint/fmpz_mod_mpoly.pxd +161 -0
  125. sage/libs/flint/fmpz_mod_mpoly_factor.pxd +28 -0
  126. sage/libs/flint/fmpz_mod_poly.pxd +249 -0
  127. sage/libs/flint/fmpz_mod_poly_factor.pxd +46 -0
  128. sage/libs/flint/fmpz_mod_vec.pxd +27 -0
  129. sage/libs/flint/fmpz_mpoly.pxd +224 -0
  130. sage/libs/flint/fmpz_mpoly_factor.pxd +29 -0
  131. sage/libs/flint/fmpz_mpoly_q.pxd +57 -0
  132. sage/libs/flint/fmpz_poly.cpython-312-aarch64-linux-gnu.so +0 -0
  133. sage/libs/flint/fmpz_poly.pxd +407 -0
  134. sage/libs/flint/fmpz_poly.pyx +19 -0
  135. sage/libs/flint/fmpz_poly_factor.pxd +33 -0
  136. sage/libs/flint/fmpz_poly_macros.pxd +8 -0
  137. sage/libs/flint/fmpz_poly_mat.pxd +71 -0
  138. sage/libs/flint/fmpz_poly_q.pxd +55 -0
  139. sage/libs/flint/fmpz_poly_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  140. sage/libs/flint/fmpz_poly_sage.pxd +20 -0
  141. sage/libs/flint/fmpz_poly_sage.pyx +500 -0
  142. sage/libs/flint/fmpz_vec.pxd +80 -0
  143. sage/libs/flint/fmpzi.pxd +52 -0
  144. sage/libs/flint/fq.pxd +97 -0
  145. sage/libs/flint/fq_default.pxd +84 -0
  146. sage/libs/flint/fq_default_mat.pxd +70 -0
  147. sage/libs/flint/fq_default_poly.pxd +97 -0
  148. sage/libs/flint/fq_default_poly_factor.pxd +39 -0
  149. sage/libs/flint/fq_embed.pxd +28 -0
  150. sage/libs/flint/fq_mat.pxd +83 -0
  151. sage/libs/flint/fq_nmod.pxd +95 -0
  152. sage/libs/flint/fq_nmod_embed.pxd +28 -0
  153. sage/libs/flint/fq_nmod_mat.pxd +83 -0
  154. sage/libs/flint/fq_nmod_mpoly.pxd +130 -0
  155. sage/libs/flint/fq_nmod_mpoly_factor.pxd +28 -0
  156. sage/libs/flint/fq_nmod_poly.pxd +202 -0
  157. sage/libs/flint/fq_nmod_poly_factor.pxd +47 -0
  158. sage/libs/flint/fq_nmod_vec.pxd +33 -0
  159. sage/libs/flint/fq_poly.pxd +204 -0
  160. sage/libs/flint/fq_poly_factor.pxd +47 -0
  161. sage/libs/flint/fq_vec.pxd +33 -0
  162. sage/libs/flint/fq_zech.pxd +99 -0
  163. sage/libs/flint/fq_zech_embed.pxd +28 -0
  164. sage/libs/flint/fq_zech_mat.pxd +78 -0
  165. sage/libs/flint/fq_zech_poly.pxd +198 -0
  166. sage/libs/flint/fq_zech_poly_factor.pxd +47 -0
  167. sage/libs/flint/fq_zech_vec.pxd +33 -0
  168. sage/libs/flint/gr.pxd +174 -0
  169. sage/libs/flint/gr_generic.pxd +215 -0
  170. sage/libs/flint/gr_mat.pxd +161 -0
  171. sage/libs/flint/gr_mpoly.pxd +68 -0
  172. sage/libs/flint/gr_poly.pxd +276 -0
  173. sage/libs/flint/gr_special.pxd +237 -0
  174. sage/libs/flint/gr_vec.pxd +120 -0
  175. sage/libs/flint/hypgeom.pxd +24 -0
  176. sage/libs/flint/long_extras.pxd +23 -0
  177. sage/libs/flint/mag.pxd +131 -0
  178. sage/libs/flint/mag_macros.pxd +8 -0
  179. sage/libs/flint/mpf_mat.pxd +36 -0
  180. sage/libs/flint/mpf_vec.pxd +34 -0
  181. sage/libs/flint/mpfr_mat.pxd +27 -0
  182. sage/libs/flint/mpfr_vec.pxd +25 -0
  183. sage/libs/flint/mpn_extras.pxd +41 -0
  184. sage/libs/flint/mpoly.pxd +72 -0
  185. sage/libs/flint/nf.pxd +19 -0
  186. sage/libs/flint/nf_elem.pxd +74 -0
  187. sage/libs/flint/nmod.pxd +35 -0
  188. sage/libs/flint/nmod_mat.pxd +104 -0
  189. sage/libs/flint/nmod_mpoly.pxd +144 -0
  190. sage/libs/flint/nmod_mpoly_factor.pxd +28 -0
  191. sage/libs/flint/nmod_poly.pxd +339 -0
  192. sage/libs/flint/nmod_poly_factor.pxd +44 -0
  193. sage/libs/flint/nmod_poly_linkage.pxi +710 -0
  194. sage/libs/flint/nmod_poly_mat.pxd +76 -0
  195. sage/libs/flint/nmod_vec.pxd +40 -0
  196. sage/libs/flint/ntl_interface.pxd +17 -0
  197. sage/libs/flint/padic.pxd +93 -0
  198. sage/libs/flint/padic_mat.pxd +64 -0
  199. sage/libs/flint/padic_poly.pxd +88 -0
  200. sage/libs/flint/partitions.pxd +23 -0
  201. sage/libs/flint/perm.pxd +26 -0
  202. sage/libs/flint/profiler.pxd +24 -0
  203. sage/libs/flint/qadic.pxd +77 -0
  204. sage/libs/flint/qfb.pxd +44 -0
  205. sage/libs/flint/qqbar.pxd +172 -0
  206. sage/libs/flint/qsieve.cpython-312-aarch64-linux-gnu.so +0 -0
  207. sage/libs/flint/qsieve.pxd +41 -0
  208. sage/libs/flint/qsieve.pyx +21 -0
  209. sage/libs/flint/qsieve_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  210. sage/libs/flint/qsieve_sage.pyx +67 -0
  211. sage/libs/flint/thread_pool.pxd +25 -0
  212. sage/libs/flint/types.pxd +2076 -0
  213. sage/libs/flint/ulong_extras.cpython-312-aarch64-linux-gnu.so +0 -0
  214. sage/libs/flint/ulong_extras.pxd +141 -0
  215. sage/libs/flint/ulong_extras.pyx +21 -0
  216. sage/libs/flint/ulong_extras_sage.cpython-312-aarch64-linux-gnu.so +0 -0
  217. sage/libs/flint/ulong_extras_sage.pyx +21 -0
  218. sage/matrix/all__sagemath_flint.py +1 -0
  219. sage/matrix/change_ring.cpython-312-aarch64-linux-gnu.so +0 -0
  220. sage/matrix/change_ring.pyx +43 -0
  221. sage/matrix/matrix_complex_ball_dense.cpython-312-aarch64-linux-gnu.so +0 -0
  222. sage/matrix/matrix_complex_ball_dense.pxd +14 -0
  223. sage/matrix/matrix_complex_ball_dense.pyx +973 -0
  224. sage/matrix/matrix_cyclo_dense.cpython-312-aarch64-linux-gnu.so +0 -0
  225. sage/matrix/matrix_cyclo_dense.pxd +16 -0
  226. sage/matrix/matrix_cyclo_dense.pyx +1761 -0
  227. sage/matrix/matrix_integer_dense.cpython-312-aarch64-linux-gnu.so +0 -0
  228. sage/matrix/matrix_integer_dense.pxd +32 -0
  229. sage/matrix/matrix_integer_dense.pyx +5801 -0
  230. sage/matrix/matrix_integer_dense_hnf.py +1294 -0
  231. sage/matrix/matrix_integer_dense_saturation.py +346 -0
  232. sage/matrix/matrix_integer_sparse.cpython-312-aarch64-linux-gnu.so +0 -0
  233. sage/matrix/matrix_integer_sparse.pxd +9 -0
  234. sage/matrix/matrix_integer_sparse.pyx +1090 -0
  235. sage/matrix/matrix_rational_dense.cpython-312-aarch64-linux-gnu.so +0 -0
  236. sage/matrix/matrix_rational_dense.pxd +23 -0
  237. sage/matrix/matrix_rational_dense.pyx +2995 -0
  238. sage/matrix/matrix_rational_sparse.cpython-312-aarch64-linux-gnu.so +0 -0
  239. sage/matrix/matrix_rational_sparse.pxd +11 -0
  240. sage/matrix/matrix_rational_sparse.pyx +789 -0
  241. sage/matrix/misc_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  242. sage/matrix/misc_flint.pyx +109 -0
  243. sage/modular/all__sagemath_flint.py +1 -0
  244. sage/modular/modform/all__sagemath_flint.py +1 -0
  245. sage/modular/modform/eis_series_cython.cpython-312-aarch64-linux-gnu.so +0 -0
  246. sage/modular/modform/eis_series_cython.pyx +226 -0
  247. sage/modular/modsym/all__sagemath_flint.py +1 -0
  248. sage/modular/modsym/apply.cpython-312-aarch64-linux-gnu.so +0 -0
  249. sage/modular/modsym/apply.pxd +6 -0
  250. sage/modular/modsym/apply.pyx +113 -0
  251. sage/modular/modsym/heilbronn.cpython-312-aarch64-linux-gnu.so +0 -0
  252. sage/modular/modsym/heilbronn.pyx +966 -0
  253. sage/modular/pollack_stevens/all__sagemath_flint.py +1 -0
  254. sage/modular/pollack_stevens/dist.cpython-312-aarch64-linux-gnu.so +0 -0
  255. sage/modular/pollack_stevens/dist.pxd +38 -0
  256. sage/modular/pollack_stevens/dist.pyx +1439 -0
  257. sage/quivers/algebra.py +691 -0
  258. sage/quivers/algebra_elements.cpython-312-aarch64-linux-gnu.so +0 -0
  259. sage/quivers/algebra_elements.pxd +97 -0
  260. sage/quivers/algebra_elements.pxi +1324 -0
  261. sage/quivers/algebra_elements.pyx +1424 -0
  262. sage/quivers/all.py +1 -0
  263. sage/quivers/ar_quiver.py +917 -0
  264. sage/quivers/homspace.py +640 -0
  265. sage/quivers/morphism.py +1282 -0
  266. sage/quivers/path_semigroup.py +1155 -0
  267. sage/quivers/paths.cpython-312-aarch64-linux-gnu.so +0 -0
  268. sage/quivers/paths.pxd +13 -0
  269. sage/quivers/paths.pyx +809 -0
  270. sage/quivers/representation.py +2975 -0
  271. sage/rings/all__sagemath_flint.py +37 -0
  272. sage/rings/cif.py +4 -0
  273. sage/rings/complex_arb.cpython-312-aarch64-linux-gnu.so +0 -0
  274. sage/rings/complex_arb.pxd +29 -0
  275. sage/rings/complex_arb.pyx +5176 -0
  276. sage/rings/complex_interval.cpython-312-aarch64-linux-gnu.so +0 -0
  277. sage/rings/complex_interval.pxd +30 -0
  278. sage/rings/complex_interval.pyx +2475 -0
  279. sage/rings/complex_interval_field.py +711 -0
  280. sage/rings/convert/all.py +1 -0
  281. sage/rings/convert/mpfi.cpython-312-aarch64-linux-gnu.so +0 -0
  282. sage/rings/convert/mpfi.pxd +6 -0
  283. sage/rings/convert/mpfi.pyx +576 -0
  284. sage/rings/factorint_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  285. sage/rings/factorint_flint.pyx +99 -0
  286. sage/rings/fraction_field_FpT.cpython-312-aarch64-linux-gnu.so +0 -0
  287. sage/rings/fraction_field_FpT.pxd +28 -0
  288. sage/rings/fraction_field_FpT.pyx +2043 -0
  289. sage/rings/imaginary_unit.py +5 -0
  290. sage/rings/monomials.py +73 -0
  291. sage/rings/number_field/S_unit_solver.py +2870 -0
  292. sage/rings/number_field/all__sagemath_flint.py +7 -0
  293. sage/rings/number_field/bdd_height.py +664 -0
  294. sage/rings/number_field/class_group.py +762 -0
  295. sage/rings/number_field/galois_group.py +1307 -0
  296. sage/rings/number_field/homset.py +612 -0
  297. sage/rings/number_field/maps.py +687 -0
  298. sage/rings/number_field/morphism.py +272 -0
  299. sage/rings/number_field/number_field.py +12820 -0
  300. sage/rings/number_field/number_field_element.cpython-312-aarch64-linux-gnu.so +0 -0
  301. sage/rings/number_field/number_field_element.pxd +59 -0
  302. sage/rings/number_field/number_field_element.pyx +5735 -0
  303. sage/rings/number_field/number_field_element_quadratic.cpython-312-aarch64-linux-gnu.so +0 -0
  304. sage/rings/number_field/number_field_element_quadratic.pxd +34 -0
  305. sage/rings/number_field/number_field_element_quadratic.pyx +3185 -0
  306. sage/rings/number_field/number_field_ideal_rel.py +925 -0
  307. sage/rings/number_field/number_field_morphisms.cpython-312-aarch64-linux-gnu.so +0 -0
  308. sage/rings/number_field/number_field_morphisms.pyx +781 -0
  309. sage/rings/number_field/number_field_rel.py +2734 -0
  310. sage/rings/number_field/order.py +2981 -0
  311. sage/rings/number_field/order_ideal.py +804 -0
  312. sage/rings/number_field/selmer_group.py +715 -0
  313. sage/rings/number_field/small_primes_of_degree_one.py +242 -0
  314. sage/rings/number_field/splitting_field.py +606 -0
  315. sage/rings/number_field/structure.py +380 -0
  316. sage/rings/number_field/unit_group.py +721 -0
  317. sage/rings/padics/all__sagemath_flint.py +3 -0
  318. sage/rings/polynomial/all__sagemath_flint.py +1 -0
  319. sage/rings/polynomial/complex_roots.py +312 -0
  320. sage/rings/polynomial/evaluation_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  321. sage/rings/polynomial/evaluation_flint.pxd +7 -0
  322. sage/rings/polynomial/evaluation_flint.pyx +68 -0
  323. sage/rings/polynomial/hilbert.cpython-312-aarch64-linux-gnu.so +0 -0
  324. sage/rings/polynomial/hilbert.pyx +602 -0
  325. sage/rings/polynomial/polynomial_complex_arb.cpython-312-aarch64-linux-gnu.so +0 -0
  326. sage/rings/polynomial/polynomial_complex_arb.pxd +7 -0
  327. sage/rings/polynomial/polynomial_complex_arb.pyx +963 -0
  328. sage/rings/polynomial/polynomial_integer_dense_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  329. sage/rings/polynomial/polynomial_integer_dense_flint.pxd +13 -0
  330. sage/rings/polynomial/polynomial_integer_dense_flint.pyx +1881 -0
  331. sage/rings/polynomial/polynomial_number_field.cpython-312-aarch64-linux-gnu.so +0 -0
  332. sage/rings/polynomial/polynomial_number_field.pyx +345 -0
  333. sage/rings/polynomial/polynomial_rational_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  334. sage/rings/polynomial/polynomial_rational_flint.pxd +20 -0
  335. sage/rings/polynomial/polynomial_rational_flint.pyx +2598 -0
  336. sage/rings/polynomial/polynomial_zmod_flint.cpython-312-aarch64-linux-gnu.so +0 -0
  337. sage/rings/polynomial/polynomial_zmod_flint.pxd +20 -0
  338. sage/rings/polynomial/polynomial_zmod_flint.pyx +1063 -0
  339. sage/rings/polynomial/real_roots.cpython-312-aarch64-linux-gnu.so +0 -0
  340. sage/rings/polynomial/real_roots.pxd +81 -0
  341. sage/rings/polynomial/real_roots.pyx +4704 -0
  342. sage/rings/polynomial/refine_root.cpython-312-aarch64-linux-gnu.so +0 -0
  343. sage/rings/polynomial/refine_root.pyx +142 -0
  344. sage/rings/polynomial/weil/all.py +4 -0
  345. sage/rings/polynomial/weil/power_sums.h +46 -0
  346. sage/rings/polynomial/weil/weil_polynomials.cpython-312-aarch64-linux-gnu.so +0 -0
  347. sage/rings/polynomial/weil/weil_polynomials.pyx +596 -0
  348. sage/rings/qqbar.py +9025 -0
  349. sage/rings/real_arb.cpython-312-aarch64-linux-gnu.so +0 -0
  350. sage/rings/real_arb.pxd +21 -0
  351. sage/rings/real_arb.pyx +4065 -0
  352. sage/rings/real_interval_absolute.cpython-312-aarch64-linux-gnu.so +0 -0
  353. sage/rings/real_interval_absolute.pyx +1073 -0
  354. sage/rings/real_mpfi.cpython-312-aarch64-linux-gnu.so +0 -0
  355. sage/rings/real_mpfi.pyx +5428 -0
  356. sage/schemes/all__sagemath_flint.py +1 -0
  357. sage/schemes/elliptic_curves/all__sagemath_flint.py +1 -0
  358. sage/schemes/elliptic_curves/descent_two_isogeny.cpython-312-aarch64-linux-gnu.so +0 -0
  359. sage/schemes/elliptic_curves/descent_two_isogeny.pyx +1387 -0
  360. sage/schemes/elliptic_curves/descent_two_isogeny_pari.pxd +5 -0
@@ -0,0 +1,4065 @@
1
+ # sage_setup: distribution = sagemath-flint
2
+ r"""
3
+ Arbitrary precision real balls
4
+
5
+ This is a binding to the `arb module of FLINT <https://flintlib.org/doc/arb.html>`_.
6
+ It may be useful to refer to its documentation for more details.
7
+
8
+ Parts of the documentation for this module are copied or adapted from Arb's
9
+ (now FLINT's) own documentation, licenced (at the time) under the GNU General
10
+ Public License version 2, or later.
11
+
12
+ .. SEEALSO::
13
+
14
+ - :mod:`Complex balls <sage.rings.complex_arb>`
15
+ - :mod:`Real intervals using MPFI <sage.rings.real_mpfi>`
16
+
17
+ Data Structure
18
+ ==============
19
+
20
+ Ball arithmetic, also known as mid-rad interval arithmetic, is an extension of
21
+ floating-point arithmetic in which an error bound is attached to each variable.
22
+ This allows doing rigorous computations over the real numbers, while avoiding
23
+ the overhead of traditional (inf-sup) interval arithmetic at high precision,
24
+ and eliminating much of the need for time-consuming and bug-prone manual error
25
+ analysis associated with standard floating-point arithmetic.
26
+
27
+ Sage :class:`RealBall` objects wrap FLINT objects of type ``arb_t``. A real
28
+ ball represents a ball over the real numbers, that is, an interval `[m-r,m+r]`
29
+ where the midpoint `m` and the radius `r` are (extended) real numbers::
30
+
31
+ sage: RBF(pi) # needs sage.symbolic
32
+ [3.141592653589793 +/- ...e-16]
33
+ sage: RBF(pi).mid(), RBF(pi).rad() # needs sage.symbolic
34
+ (3.14159265358979, ...e-16)
35
+
36
+ The midpoint is represented as an arbitrary-precision floating-point number
37
+ with arbitrary-precision exponent. The radius is a floating-point number with
38
+ fixed-precision mantissa and arbitrary-precision exponent. ::
39
+
40
+ sage: RBF(2)^(2^100)
41
+ [2.285367694229514e+381600854690147056244358827360 +/- ...e+381600854690147056244358827344]
42
+
43
+ :class:`RealBallField` objects (the parents of real balls) model the field of
44
+ real numbers represented by balls on which computations are carried out with a
45
+ certain precision::
46
+
47
+ sage: RBF
48
+ Real ball field with 53 bits of precision
49
+
50
+ It is possible to construct a ball whose parent is the real ball field with
51
+ precision `p` but whose midpoint does not fit on `p` bits. However, the results
52
+ of operations involving such a ball will (usually) be rounded to its parent's
53
+ precision::
54
+
55
+ sage: RBF(factorial(50)).mid(), RBF(factorial(50)).rad()
56
+ (3.0414093201713378043612608166064768844377641568961e64, 0.00000000)
57
+ sage: (RBF(factorial(50)) + 0).mid()
58
+ 3.04140932017134e64
59
+
60
+ Comparison
61
+ ==========
62
+
63
+ .. WARNING::
64
+
65
+ In accordance with the semantics of FLINT/Arb, identical :class:`RealBall`
66
+ objects are understood to give permission for algebraic simplification.
67
+ This assumption is made to improve performance. For example, setting ``z =
68
+ x*x`` may set `z` to a ball enclosing the set `\{t^2 : t \in x\}` and not
69
+ the (generally larger) set `\{tu : t \in x, u \in x\}`.
70
+
71
+ Two elements are equal if and only if they are exact and equal (in spite of the
72
+ above warning, inexact balls are not considered equal to themselves)::
73
+
74
+ sage: a = RBF(1)
75
+ sage: b = RBF(1)
76
+ sage: a is b
77
+ False
78
+ sage: a == a
79
+ True
80
+ sage: a == b
81
+ True
82
+
83
+ ::
84
+
85
+ sage: a = RBF(1/3)
86
+ sage: b = RBF(1/3)
87
+ sage: a.is_exact()
88
+ False
89
+ sage: b.is_exact()
90
+ False
91
+ sage: a is b
92
+ False
93
+ sage: a == a
94
+ False
95
+ sage: a == b
96
+ False
97
+
98
+ A ball is nonzero in the sense of comparison if and only if it does not
99
+ contain zero. ::
100
+
101
+ sage: a = RBF(RIF(-0.5, 0.5))
102
+ sage: a != 0
103
+ False
104
+ sage: b = RBF(1/3)
105
+ sage: b != 0
106
+ True
107
+
108
+ However, ``bool(b)`` returns ``False`` for a ball ``b`` only if ``b`` is exactly
109
+ zero::
110
+
111
+ sage: bool(a)
112
+ True
113
+ sage: bool(b)
114
+ True
115
+ sage: bool(RBF.zero())
116
+ False
117
+
118
+ A ball ``left`` is less than a ball ``right`` if all elements of
119
+ ``left`` are less than all elements of ``right``. ::
120
+
121
+ sage: a = RBF(RIF(1, 2))
122
+ sage: b = RBF(RIF(3, 4))
123
+ sage: a < b
124
+ True
125
+ sage: a <= b
126
+ True
127
+ sage: a > b
128
+ False
129
+ sage: a >= b
130
+ False
131
+ sage: a = RBF(RIF(1, 3))
132
+ sage: b = RBF(RIF(2, 4))
133
+ sage: a < b
134
+ False
135
+ sage: a <= b
136
+ False
137
+ sage: a > b
138
+ False
139
+ sage: a >= b
140
+ False
141
+
142
+ Comparisons with Sage symbolic infinities work with some limitations::
143
+
144
+ sage: -infinity < RBF(1) < +infinity
145
+ True
146
+ sage: -infinity < RBF(infinity)
147
+ True
148
+ sage: RBF(infinity) < infinity
149
+ False
150
+ sage: RBF(NaN) < infinity # needs sage.symbolic
151
+ Traceback (most recent call last):
152
+ ...
153
+ ValueError: infinite but not with +/- phase
154
+ sage: 1/RBF(0) <= infinity
155
+ Traceback (most recent call last):
156
+ ...
157
+ ValueError: infinite but not with +/- phase
158
+
159
+ Comparisons between elements of real ball fields, however, support special
160
+ values and should be preferred::
161
+
162
+ sage: RBF(NaN) < RBF(infinity) # needs sage.symbolic
163
+ False
164
+ sage: RBF(0).add_error(infinity) <= RBF(infinity)
165
+ True
166
+
167
+ TESTS::
168
+
169
+ sage: (RBF(pi) * identity_matrix(QQ, 3)).parent() # needs sage.symbolic
170
+ Full MatrixSpace of 3 by 3 dense matrices over Real ball field
171
+ with 53 bits of precision
172
+
173
+ sage: polygen(RBF, 'x')^3
174
+ x^3
175
+
176
+ ::
177
+
178
+ sage: SR.coerce(RBF(0.42)) # needs sage.symbolic
179
+ [0.4200000000000000 +/- ...e-17]
180
+ sage: RBF(0.42) + SR(1) # needs sage.symbolic
181
+ [1.420000000000000 +/- ...e-16]
182
+ sage: _.parent() # needs sage.symbolic
183
+ Symbolic Ring
184
+
185
+ Classes and Methods
186
+ ===================
187
+ """
188
+
189
+ # ****************************************************************************
190
+ # Copyright (C) 2014 Clemens Heuberger <clemens.heuberger@aau.at>
191
+ # 2017 Vincent Delecroix <20100.delecroix@gmail.com>
192
+ #
193
+ # This program is free software: you can redistribute it and/or modify
194
+ # it under the terms of the GNU General Public License as published by
195
+ # the Free Software Foundation, either version 2 of the License, or
196
+ # (at your option) any later version.
197
+ # https://www.gnu.org/licenses/
198
+ # ****************************************************************************
199
+
200
+ from cysignals.signals cimport sig_on, sig_str, sig_off
201
+
202
+ from cpython.float cimport PyFloat_AS_DOUBLE
203
+ from cpython.long cimport PyLong_AsLong
204
+ from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
205
+ from libc.stdlib cimport abort
206
+
207
+ from sage.libs.flint.arb cimport *
208
+ from sage.libs.flint.arb_hypgeom cimport *
209
+ from sage.libs.flint.arf cimport *
210
+ from sage.libs.flint.arf cimport *
211
+ from sage.libs.flint.mag cimport *
212
+ from sage.libs.flint.flint cimport flint_free
213
+ from sage.libs.flint.fmpz cimport *
214
+ from sage.libs.flint.fmpq cimport *
215
+ from sage.libs.gmp.mpz cimport *
216
+ from sage.libs.mpfi cimport *
217
+ from sage.libs.mpfr cimport *
218
+ from sage.libs.mpfr cimport MPFR_RNDN, MPFR_RNDU, MPFR_RNDD, MPFR_RNDZ
219
+
220
+ from sage.structure.element cimport Element, RingElement
221
+ from sage.rings.ring cimport Field
222
+ import sage.rings.abc
223
+ from sage.rings.integer cimport Integer
224
+ from sage.rings.rational cimport Rational
225
+ from sage.rings.real_mpfr cimport RealField_class, RealField, RealNumber
226
+ from sage.arith.long cimport is_small_python_int
227
+
228
+ import operator
229
+
230
+ import sage.categories.fields
231
+
232
+ from sage.misc.lazy_string import lazy_string
233
+ from sage.rings.integer_ring import ZZ
234
+ from sage.rings.rational_field import QQ
235
+ from sage.rings.real_mpfi import RealIntervalField, RealIntervalField_class
236
+ from sage.structure.unique_representation import UniqueRepresentation
237
+ from sage.cpython.string cimport char_to_str, str_to_bytes
238
+
239
+ cdef void mpfi_to_arb(arb_t target, const mpfi_t source, const long precision) noexcept:
240
+ r"""
241
+ Convert an MPFI interval to an Arb ball.
242
+
243
+ INPUT:
244
+
245
+ - ``target`` -- an ``arb_t``
246
+
247
+ - ``source`` -- an ``mpfi_t``
248
+
249
+ - ``precision`` -- integer `\ge 2`
250
+
251
+ TESTS::
252
+
253
+ sage: RBF(RIF(infinity)).endpoints()
254
+ (+infinity, +infinity)
255
+ sage: RBF(RIF(-infinity)).endpoints()
256
+ (-infinity, -infinity)
257
+ sage: RBF(RIF(-infinity, infinity)).endpoints()
258
+ (-infinity, +infinity)
259
+ sage: RIF(RBF(infinity)).endpoints()
260
+ (+infinity, +infinity)
261
+ sage: RIF(RBF(-infinity)).endpoints()
262
+ (-infinity, -infinity)
263
+ """
264
+ cdef mpfr_t left
265
+ cdef mpfr_t right
266
+
267
+ mpfr_init2(left, precision)
268
+ mpfr_init2(right, precision)
269
+
270
+ if _do_sig(precision): sig_on()
271
+ mpfi_get_left(left, source)
272
+ mpfi_get_right(right, source)
273
+ if mpfr_inf_p(left) and mpfr_inf_p(right) and mpfr_sgn(left) < 0 < mpfr_sgn(right):
274
+ # Work around a weakness of arb_set_interval_mpfr(tgt, -inf, inf)
275
+ arb_zero_pm_inf(target)
276
+ else:
277
+ arb_set_interval_mpfr(target, left, right, precision)
278
+ if _do_sig(precision): sig_off()
279
+
280
+ mpfr_clear(left)
281
+ mpfr_clear(right)
282
+
283
+ cdef int arb_to_mpfi(mpfi_t target, arb_t source, const long precision) except -1:
284
+ r"""
285
+ Convert an Arb ball to an MPFI interval.
286
+
287
+ INPUT:
288
+
289
+ - ``target`` -- an ``mpfi_t``
290
+
291
+ - ``source`` -- an ``arb_t``
292
+
293
+ - ``precision`` -- integer `\ge 2`
294
+
295
+ EXAMPLES::
296
+
297
+ sage: RIF(RBF(2)**(2**100))
298
+ [5.8756537891115869e1388255822130839282 .. +infinity] # 64-bit
299
+ [2.098... .. +infinity] # 32-bit
300
+ """
301
+ cdef mpfr_t left
302
+ cdef mpfr_t right
303
+
304
+ mpfr_init2(left, precision)
305
+ mpfr_init2(right, precision)
306
+
307
+ try:
308
+ sig_on()
309
+ arb_get_interval_mpfr(left, right, source)
310
+ mpfi_interv_fr(target, left, right)
311
+ sig_off()
312
+ except RuntimeError:
313
+ raise ArithmeticError("Error converting arb to mpfi. Overflow?")
314
+ finally:
315
+ mpfr_clear(left)
316
+ mpfr_clear(right)
317
+
318
+
319
+ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField):
320
+ r"""
321
+ An approximation of the field of real numbers using mid-rad intervals, also
322
+ known as balls.
323
+
324
+ INPUT:
325
+
326
+ - ``precision`` -- integer `\ge 2`
327
+
328
+ EXAMPLES::
329
+
330
+ sage: RBF = RealBallField() # indirect doctest
331
+ sage: RBF(1)
332
+ 1.000000000000000
333
+
334
+ ::
335
+
336
+ sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, 'x') # needs sage.symbolic
337
+ x + [0.914213562373095 +/- ...e-16]
338
+
339
+ TESTS::
340
+
341
+ sage: RBF.bracket(RBF(1/2), RBF(1/3))
342
+ [+/- ...e-17]
343
+ sage: RBF.cardinality()
344
+ +Infinity
345
+ sage: RBF.cartesian_product(QQ).an_element()**2
346
+ ([1.440000000000000 +/- ...e-16], 1/4)
347
+ sage: RBF.coerce_embedding() is None
348
+ True
349
+ sage: RBF['x'].gens_dict_recursive()
350
+ {'x': x}
351
+ sage: RBF.is_finite()
352
+ False
353
+ sage: RBF.is_zero()
354
+ False
355
+ sage: RBF.one()
356
+ 1.000000000000000
357
+ sage: RBF.zero()
358
+ 0
359
+
360
+ sage: NF.<sqrt2> = QuadraticField(2, embedding=AA(2).sqrt()) # needs sage.rings.number_field
361
+ sage: a = (sqrt2 - 1)^1000 # needs sage.rings.number_field
362
+ sage: RBF(a) # needs sage.rings.number_field
363
+ [1.676156872756536e-383 +/- ...e-399]
364
+
365
+ sage: RealBallField().is_finite()
366
+ False
367
+
368
+ sage: loads(dumps(RealBallField(60))) is RealBallField(60)
369
+ True
370
+
371
+ .. SEEALSO::
372
+
373
+ - :mod:`sage.rings.real_arb`
374
+ - :mod:`sage.rings.real_mpfr`
375
+ - :mod:`sage.rings.real_mpfi` (real intervals represented by their
376
+ endpoints)
377
+ - :mod:`sage.rings.complex_arb`
378
+ """
379
+ Element = RealBall
380
+
381
+ @staticmethod
382
+ def __classcall__(cls, long precision=53):
383
+ r"""
384
+ Normalize the arguments for caching.
385
+
386
+ TESTS::
387
+
388
+ sage: RealBallField(53) is RealBallField() is RBF
389
+ True
390
+ """
391
+ return super().__classcall__(cls, precision)
392
+
393
+ def __init__(self, long precision=53):
394
+ r"""
395
+ Initialize the real ball field.
396
+
397
+ INPUT:
398
+
399
+ - ``precision`` -- integer `\ge 2`
400
+
401
+ EXAMPLES::
402
+
403
+ sage: RBF = RealBallField()
404
+ sage: RBF(1)
405
+ 1.000000000000000
406
+ sage: RealBallField(0)
407
+ Traceback (most recent call last):
408
+ ...
409
+ ValueError: precision must be at least 2
410
+ sage: RealBallField(1)
411
+ Traceback (most recent call last):
412
+ ...
413
+ ValueError: precision must be at least 2
414
+
415
+ TESTS::
416
+
417
+ sage: RBF.base()
418
+ Real ball field with 53 bits of precision
419
+ sage: RBF.base_ring()
420
+ Real ball field with 53 bits of precision
421
+ """
422
+ if precision < 2:
423
+ raise ValueError("precision must be at least 2")
424
+ Field.__init__(self,
425
+ base_ring=self,
426
+ category=sage.categories.fields.Fields().Infinite())
427
+ self._prec = precision
428
+ from sage.rings.real_lazy import RLF
429
+ self._populate_coercion_lists_(coerce_list=[ZZ, QQ], convert_method_name='_arb_')
430
+
431
+ def _repr_(self):
432
+ r"""
433
+ String representation of ``self``.
434
+
435
+ EXAMPLES::
436
+
437
+ sage: RealBallField()
438
+ Real ball field with 53 bits of precision
439
+ sage: RealBallField(106)
440
+ Real ball field with 106 bits of precision
441
+ """
442
+ return "Real ball field with {} bits of precision".format(self._prec)
443
+
444
+ def _coerce_map_from_(self, other):
445
+ r"""
446
+ Parents that canonically coerce into real ball fields include:
447
+
448
+ - some exact or lazy parents representing subsets of the reals, such as
449
+ ``ZZ``, ``QQ``, ``AA``, and ``RLF``;
450
+
451
+ - real ball fields with a larger precision.
452
+
453
+ TESTS::
454
+
455
+ sage: RealBallField().has_coerce_map_from(RealBallField(54))
456
+ True
457
+ sage: RealBallField().has_coerce_map_from(RealBallField(52))
458
+ False
459
+ sage: RealBallField().has_coerce_map_from(RIF)
460
+ False
461
+ sage: RealBallField().has_coerce_map_from(SR) # needs sage.symbolic
462
+ False
463
+ sage: RealBallField().has_coerce_map_from(RR)
464
+ False
465
+
466
+ sage: # needs sage.rings.number_field
467
+ sage: K = QuadraticField(2, embedding=AA(2).sqrt())
468
+ sage: RBF.has_coerce_map_from(K)
469
+ True
470
+ sage: RBF.has_coerce_map_from(QuadraticField(2, embedding=None))
471
+ False
472
+ sage: RBF.has_coerce_map_from(QuadraticField(-2))
473
+ False
474
+
475
+ Check that the map goes through the ``_arb_`` method::
476
+
477
+ sage: # needs sage.rings.number_field
478
+ sage: RBF.coerce_map_from(QuadraticField(2, embedding=AA(2).sqrt()))
479
+ Conversion via _arb_ method map:
480
+ ...
481
+ sage: RBF.convert_map_from(QuadraticField(2))
482
+ Conversion via _arb_ method map:
483
+ ...
484
+ sage: RBF.coerce_map_from(AA)
485
+ Conversion via _arb_ method map:
486
+ ...
487
+ sage: RBF.convert_map_from(QQbar)
488
+ Conversion via _arb_ method map:
489
+ ...
490
+ """
491
+ if isinstance(other, RealBallField):
492
+ return other._prec >= self._prec
493
+
494
+ from sage.rings.qqbar import AA
495
+ from sage.rings.real_lazy import RLF
496
+ if other in [AA, RLF]:
497
+ return True
498
+
499
+ from sage.rings.number_field.number_field_base import NumberField
500
+ if isinstance(other, NumberField):
501
+ emb = other.coerce_embedding()
502
+ return emb is not None and self.has_coerce_map_from(emb.codomain())
503
+
504
+ def _element_constructor_(self, mid=None, rad=None):
505
+ """
506
+ Convert ``mid`` to an element of this real ball field, perhaps
507
+ non-canonically.
508
+
509
+ In addition to the inputs supported by :meth:`RealBall.__init__`,
510
+ elements that can be coerced to real intervals can also be used to
511
+ construct a real ball::
512
+
513
+ sage: RBF(RIF(0, 1)) # indirect doctest
514
+ [+/- 1.01]
515
+ sage: RBF(1)
516
+ 1.000000000000000
517
+ sage: RBF(x) # needs sage.symbolic
518
+ Traceback (most recent call last):
519
+ ...
520
+ TypeError: unable to convert x to a RealBall
521
+
522
+ Various symbolic constants are supported::
523
+
524
+ sage: RBF(e) # needs sage.symbolic
525
+ [2.718281828459045 +/- ...e-16]
526
+ sage: RBF(pi) # needs sage.symbolic
527
+ [3.141592653589793 +/- ...e-16]
528
+
529
+ Symbolic expressions are parsed ::
530
+
531
+ sage: RBF(4*zeta(3)) # needs sage.symbolic
532
+ [4.8082276126383...]
533
+ sage: RBF(exp(1), 0.01) # needs sage.symbolic
534
+ [2.7 +/- ...]
535
+
536
+ TESTS:
537
+
538
+ The following conversions used to yield incorrect results::
539
+
540
+ sage: RBF(airy_ai(1)) # needs sage.symbolic
541
+ [0.135292416312881...]
542
+ sage: v = RBF(zetaderiv(1, 3/2)); v # needs sage.symbolic
543
+ [-3.932239737431101 +/- 5.58e-16]
544
+ sage: v.overlaps(RealBallField(100)(3/2).zetaderiv(1)) # needs sage.symbolic
545
+ True
546
+ """
547
+ # Symbolic expressions are handled in a special way, see
548
+ # Expression._arb_(). A call like RBF(expr, rad) converts expr to a
549
+ # ball using its _arb_() method and sends us the result to adjust the
550
+ # radius thanks to the general mechanism implemented in
551
+ # NamedConvertMap.
552
+ try:
553
+ return self.element_class(self, mid, rad)
554
+ except TypeError:
555
+ pass
556
+ try:
557
+ _mid = RealIntervalField(self._prec)(mid)
558
+ return self.element_class(self, _mid, rad)
559
+ except (TypeError, ValueError):
560
+ pass
561
+ raise TypeError(lazy_string("unable to convert %s to a RealBall", mid))
562
+
563
+ def _repr_option(self, key):
564
+ """
565
+ Declare that real balls print atomically.
566
+
567
+ TESTS::
568
+
569
+ sage: RBF._repr_option('element_is_atomic')
570
+ True
571
+ sage: RBF['x']([-2,-2,-2/3])
572
+ [-0.666666666666667 +/- ...e-16]*x^2 - 2.000000000000000*x
573
+ - 2.000000000000000
574
+ sage: RBF._repr_option('element_is_atomic_typo')
575
+ Traceback (most recent call last):
576
+ ...
577
+ KeyError: 'element_is_atomic_typo'
578
+ """
579
+ if key == 'element_is_atomic':
580
+ return True
581
+
582
+ return super()._repr_option(key)
583
+
584
+ def gens(self) -> tuple:
585
+ r"""
586
+ EXAMPLES::
587
+
588
+ sage: RBF.gens()
589
+ (1.000000000000000,)
590
+ sage: RBF.gens_dict()
591
+ {'1.000000000000000': 1.000000000000000}
592
+ """
593
+ return (self.one(),)
594
+
595
+ def construction(self):
596
+ """
597
+ Return the construction of a real ball field as a completion of the
598
+ rationals.
599
+
600
+ EXAMPLES::
601
+
602
+ sage: RBF = RealBallField(42)
603
+ sage: functor, base = RBF.construction()
604
+ sage: functor, base
605
+ (Completion[+Infinity, prec=42], Rational Field)
606
+ sage: functor(base) is RBF
607
+ True
608
+ """
609
+ from sage.categories.pushout import CompletionFunctor
610
+ functor = CompletionFunctor(sage.rings.infinity.Infinity,
611
+ self._prec,
612
+ {'type': 'Ball'})
613
+ return functor, QQ
614
+
615
+ def complex_field(self):
616
+ """
617
+ Return the complex ball field with the same precision.
618
+
619
+ EXAMPLES::
620
+
621
+ sage: from sage.rings.complex_arb import ComplexBallField
622
+ sage: RBF.complex_field()
623
+ Complex ball field with 53 bits of precision
624
+ sage: RealBallField(3).algebraic_closure()
625
+ Complex ball field with 3 bits of precision
626
+ """
627
+ from sage.rings.complex_arb import ComplexBallField
628
+ return ComplexBallField(self._prec)
629
+
630
+ algebraic_closure = complex_field
631
+
632
+ def precision(self):
633
+ """
634
+ Return the bit precision used for operations on elements of this field.
635
+
636
+ EXAMPLES::
637
+
638
+ sage: RealBallField().precision()
639
+ 53
640
+ """
641
+ return self._prec
642
+
643
+ prec = precision
644
+
645
+ def is_exact(self):
646
+ """
647
+ Real ball fields are not exact.
648
+
649
+ EXAMPLES::
650
+
651
+ sage: RealBallField().is_exact()
652
+ False
653
+ """
654
+ return False
655
+
656
+ def characteristic(self):
657
+ """
658
+ Real ball fields have characteristic zero.
659
+
660
+ EXAMPLES::
661
+
662
+ sage: RealBallField().characteristic()
663
+ 0
664
+ """
665
+ return 0
666
+
667
+ def some_elements(self):
668
+ """
669
+ Real ball fields contain exact balls, inexact balls, infinities, and
670
+ more.
671
+
672
+ EXAMPLES::
673
+
674
+ sage: RBF.some_elements()
675
+ [0, 1.000000000000000, [0.3333333333333333 +/- ...e-17],
676
+ [-4.733045976388941e+363922934236666733021124 +/- ...e+363922934236666733021108],
677
+ [+/- inf], [+/- inf], [+/- inf], nan]
678
+ """
679
+ inf = self(sage.rings.infinity.Infinity)
680
+ elements = [self(0), self(1), self(1)/3, -self(2)**(Integer(2)**80),
681
+ inf, -inf, self.zero().add_error(inf)]
682
+ try:
683
+ from sage.symbolic.constants import NotANumber
684
+ except ImportError:
685
+ pass
686
+ else:
687
+ elements.append(self.element_class(self, NotANumber()))
688
+ return elements
689
+
690
+ def _sum_of_products(self, terms):
691
+ r"""
692
+ Compute a sum of product of real balls without creating temporary
693
+ Python objects
694
+
695
+ The input objects should be real balls, but need not belong to this
696
+ parent. The computation is performed at the precision of this parent.
697
+
698
+ EXAMPLES::
699
+
700
+ sage: Pol.<x> = RealBallField(1000)[]
701
+ sage: pol = (x + 1/3)^100
702
+ sage: RBF._sum_of_products((c, c) for c in pol)
703
+ [6.3308767660842e+23 +/- ...e+9]
704
+
705
+ TESTS::
706
+
707
+ sage: RBF._sum_of_products([])
708
+ 0
709
+ sage: RBF._sum_of_products([[]])
710
+ 1.000000000000000
711
+ sage: RBF._sum_of_products([["a"]])
712
+ Traceback (most recent call last):
713
+ ...
714
+ TypeError: Cannot convert str to sage.rings.real_arb.RealBall
715
+ """
716
+ cdef RealBall res = RealBall.__new__(RealBall)
717
+ cdef RealBall factor
718
+ cdef arb_t tmp
719
+ res._parent = self
720
+ arb_zero(res.value)
721
+ arb_init(tmp)
722
+ try:
723
+ for term in terms:
724
+ arb_one(tmp)
725
+ for factor in term:
726
+ arb_mul(tmp, tmp, factor.value, self._prec)
727
+ arb_add(res.value, res.value, tmp, self._prec)
728
+ finally:
729
+ arb_clear(tmp)
730
+ return res
731
+ # Constants
732
+
733
+ def pi(self):
734
+ r"""
735
+ Return a ball enclosing `\pi`.
736
+
737
+ EXAMPLES::
738
+
739
+ sage: RBF.pi()
740
+ [3.141592653589793 +/- ...e-16]
741
+ sage: RealBallField(128).pi()
742
+ [3.1415926535897932384626433832795028842 +/- ...e-38]
743
+ """
744
+ cdef RealBall res = RealBall.__new__(RealBall)
745
+ res._parent = self
746
+ if _do_sig(self._prec): sig_on()
747
+ arb_const_pi(res.value, self._prec)
748
+ if _do_sig(self._prec): sig_off()
749
+ return res
750
+
751
+ def log2(self):
752
+ r"""
753
+ Return a ball enclosing `\log(2)`.
754
+
755
+ EXAMPLES::
756
+
757
+ sage: RBF.log2()
758
+ [0.6931471805599453 +/- ...e-17]
759
+ sage: RealBallField(128).log2()
760
+ [0.69314718055994530941723212145817656807 +/- ...e-39]
761
+ """
762
+ cdef RealBall res = RealBall.__new__(RealBall)
763
+ res._parent = self
764
+ if _do_sig(self._prec): sig_on()
765
+ arb_const_log2(res.value, self._prec)
766
+ if _do_sig(self._prec): sig_off()
767
+ return res
768
+
769
+ def euler_constant(self):
770
+ r"""
771
+ Return a ball enclosing the Euler constant.
772
+
773
+ EXAMPLES::
774
+
775
+ sage: RBF.euler_constant() # abs tol 1e-15
776
+ [0.5772156649015329 +/- 9.00e-17]
777
+ sage: RealBallField(128).euler_constant()
778
+ [0.57721566490153286060651209008240243104 +/- ...e-39]
779
+ """
780
+ cdef RealBall res = RealBall.__new__(RealBall)
781
+ res._parent = self
782
+ if _do_sig(self._prec): sig_on()
783
+ arb_const_euler(res.value, self._prec)
784
+ if _do_sig(self._prec): sig_off()
785
+ return res
786
+
787
+ def catalan_constant(self):
788
+ r"""
789
+ Return a ball enclosing the Catalan constant.
790
+
791
+ EXAMPLES::
792
+
793
+ sage: RBF.catalan_constant()
794
+ [0.915965594177219 +/- ...e-16]
795
+ sage: RealBallField(128).catalan_constant()
796
+ [0.91596559417721901505460351493238411077 +/- ...e-39]
797
+ """
798
+ cdef RealBall res = RealBall.__new__(RealBall)
799
+ res._parent = self
800
+ if _do_sig(self._prec): sig_on()
801
+ arb_const_catalan(res.value, self._prec)
802
+ if _do_sig(self._prec): sig_off()
803
+ return res
804
+
805
+ # Ball functions of non-ball arguments
806
+
807
+ def sinpi(self, x):
808
+ r"""
809
+ Return a ball enclosing `\sin(\pi x)`.
810
+
811
+ This works even if ``x`` itself is not a ball, and may be faster or
812
+ more accurate where ``x`` is a rational number.
813
+
814
+ EXAMPLES::
815
+
816
+ sage: RBF.sinpi(1)
817
+ 0
818
+ sage: RBF.sinpi(1/3)
819
+ [0.866025403784439 +/- ...e-16]
820
+ sage: RBF.sinpi(1 + 2^(-100))
821
+ [-2.478279624546525e-30 +/- ...e-46]
822
+
823
+ .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBall.sin`
824
+
825
+ TESTS::
826
+
827
+ sage: RBF.sinpi(RLF(sqrt(2))) # needs sage.symbolic
828
+ [-0.963902532849877 +/- ...e-16]
829
+ """
830
+ cdef RealBall res, x_as_ball
831
+ cdef Rational x_as_Rational
832
+ cdef fmpq_t tmpq
833
+ res = self.element_class(self)
834
+ try:
835
+ x_as_Rational = QQ.coerce(x)
836
+ try:
837
+ if _do_sig(self._prec): sig_on()
838
+ fmpq_init(tmpq)
839
+ fmpq_set_mpq(tmpq, x_as_Rational.value)
840
+ arb_sin_pi_fmpq(res.value, tmpq, self._prec)
841
+ if _do_sig(self._prec): sig_off()
842
+ finally:
843
+ fmpq_clear(tmpq)
844
+ return res
845
+ except TypeError:
846
+ pass
847
+ x_as_ball = self.coerce(x)
848
+ if _do_sig(self._prec): sig_on()
849
+ arb_sin_pi(res.value, x_as_ball.value, self._prec)
850
+ if _do_sig(self._prec): sig_off()
851
+ return res
852
+
853
+ def cospi(self, x):
854
+ r"""
855
+ Return a ball enclosing `\cos(\pi x)`.
856
+
857
+ This works even if ``x`` itself is not a ball, and may be faster or
858
+ more accurate where ``x`` is a rational number.
859
+
860
+ EXAMPLES::
861
+
862
+ sage: RBF.cospi(1)
863
+ -1.000000000000000
864
+ sage: RBF.cospi(1/3)
865
+ 0.5000000000000000
866
+
867
+ .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBall.cos`
868
+
869
+ TESTS::
870
+
871
+ sage: RBF.cospi(RLF(sqrt(2))) # needs sage.symbolic
872
+ [-0.26625534204142 +/- ...e-15]
873
+ """
874
+ cdef RealBall res, x_as_ball
875
+ cdef Rational x_as_Rational
876
+ cdef fmpq_t tmpq
877
+ res = self.element_class(self)
878
+ try:
879
+ x_as_Rational = QQ.coerce(x)
880
+ try:
881
+ if _do_sig(self._prec): sig_on()
882
+ fmpq_init(tmpq)
883
+ fmpq_set_mpq(tmpq, x_as_Rational.value)
884
+ arb_cos_pi_fmpq(res.value, tmpq, self._prec)
885
+ if _do_sig(self._prec): sig_off()
886
+ finally:
887
+ fmpq_clear(tmpq)
888
+ return res
889
+ except TypeError:
890
+ pass
891
+ x_as_ball = self.coerce(x)
892
+ if _do_sig(self._prec): sig_on()
893
+ arb_cos_pi(res.value, x_as_ball.value, self._prec)
894
+ if _do_sig(self._prec): sig_off()
895
+ return res
896
+
897
+ def gamma(self, x):
898
+ """
899
+ Return a ball enclosing the gamma function of ``x``.
900
+
901
+ This works even if ``x`` itself is not a ball, and may be more
902
+ efficient in the case where ``x`` is an integer or a rational number.
903
+
904
+ EXAMPLES::
905
+
906
+ sage: RBF.gamma(5)
907
+ 24.00000000000000
908
+ sage: RBF.gamma(10**20)
909
+ [1.932849514310098...+1956570551809674817225 +/- ...]
910
+ sage: RBF.gamma(1/3)
911
+ [2.678938534707747 +/- ...e-16]
912
+ sage: RBF.gamma(-5)
913
+ nan
914
+
915
+ .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBall.gamma`
916
+
917
+ TESTS::
918
+
919
+ sage: RBF.gamma(RLF(pi)) # abs tol 1e-13 # needs sage.symbolic
920
+ [2.28803779534003 +/- 4.12e-15]
921
+ """
922
+ cdef RealBall res
923
+ cdef Integer x_as_Integer
924
+ cdef Rational x_as_Rational
925
+ cdef fmpz_t tmpz
926
+ cdef fmpq_t tmpq
927
+ res = self.element_class(self)
928
+ try:
929
+ x_as_Integer = ZZ.coerce(x)
930
+ try:
931
+ if _do_sig(self._prec): sig_on()
932
+ fmpz_init(tmpz)
933
+ fmpz_set_mpz(tmpz, x_as_Integer.value)
934
+ arb_gamma_fmpz(res.value, tmpz, self._prec)
935
+ if _do_sig(self._prec): sig_off()
936
+ finally:
937
+ fmpz_clear(tmpz)
938
+ return res
939
+ except TypeError:
940
+ pass
941
+ try:
942
+ x_as_Rational = QQ.coerce(x)
943
+ try:
944
+ if _do_sig(self._prec): sig_on()
945
+ fmpq_init(tmpq)
946
+ fmpq_set_mpq(tmpq, x_as_Rational.value)
947
+ arb_gamma_fmpq(res.value, tmpq, self._prec)
948
+ if _do_sig(self._prec): sig_off()
949
+ finally:
950
+ fmpq_clear(tmpq)
951
+ return res
952
+ except TypeError:
953
+ pass
954
+ return self.coerce(x).gamma()
955
+
956
+ def zeta(self, s):
957
+ """
958
+ Return a ball enclosing the Riemann zeta function of ``s``.
959
+
960
+ This works even if ``s`` itself is not a ball, and may be more
961
+ efficient in the case where ``s`` is an integer.
962
+
963
+ EXAMPLES::
964
+
965
+ sage: RBF.zeta(3)
966
+ [1.202056903159594 +/- ...e-16]
967
+ sage: RBF.zeta(1)
968
+ nan
969
+ sage: RBF.zeta(1/2)
970
+ [-1.460354508809587 +/- ...e-16]
971
+
972
+ .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBall.zeta`
973
+ """
974
+ cdef RealBall res
975
+ cdef Integer s_as_Integer
976
+ try:
977
+ s_as_Integer = ZZ.coerce(s)
978
+ if mpz_fits_ulong_p(s_as_Integer.value):
979
+ res = self.element_class(self)
980
+ if _do_sig(self._prec): sig_on()
981
+ arb_zeta_ui(res.value, mpz_get_ui(s_as_Integer.value), self._prec)
982
+ if _do_sig(self._prec): sig_off()
983
+ return res
984
+ except TypeError:
985
+ pass
986
+ return self.coerce(s).zeta()
987
+
988
+ def bernoulli(self, n):
989
+ """
990
+ Return a ball enclosing the ``n``-th Bernoulli number.
991
+
992
+ EXAMPLES::
993
+
994
+ sage: [RBF.bernoulli(n) for n in range(4)]
995
+ [1.000000000000000, -0.5000000000000000, [0.1666666666666667 +/- ...e-17], 0]
996
+ sage: RBF.bernoulli(2**20)
997
+ [-1.823002872104961e+5020717 +/- ...e+5020701]
998
+ sage: RBF.bernoulli(2**1000)
999
+ Traceback (most recent call last):
1000
+ ...
1001
+ ValueError: argument too large
1002
+
1003
+ TESTS::
1004
+
1005
+ sage: RBF.bernoulli(2r)
1006
+ [0.1666666666666667 +/- ...e-17]
1007
+ sage: RBF.bernoulli(2/3)
1008
+ Traceback (most recent call last):
1009
+ ...
1010
+ TypeError: no canonical coercion from Rational Field to Integer Ring
1011
+ sage: RBF.bernoulli(-1)
1012
+ Traceback (most recent call last):
1013
+ ...
1014
+ ValueError: expected a nonnegative index
1015
+ """
1016
+ cdef RealBall res
1017
+ cdef Integer n_as_Integer = ZZ.coerce(n)
1018
+ if mpz_fits_ulong_p(n_as_Integer.value):
1019
+ res = self.element_class(self)
1020
+ if _do_sig(self._prec): sig_on()
1021
+ arb_bernoulli_ui(res.value, mpz_get_ui(n_as_Integer.value), self._prec)
1022
+ if _do_sig(self._prec): sig_off()
1023
+ return res
1024
+ elif n_as_Integer < 0:
1025
+ raise ValueError("expected a nonnegative index")
1026
+ else:
1027
+ # TODO: Fall back to a Sage implementation in this case?
1028
+ raise ValueError("argument too large")
1029
+
1030
+ def fibonacci(self, n):
1031
+ """
1032
+ Return a ball enclosing the ``n``-th Fibonacci number.
1033
+
1034
+ EXAMPLES::
1035
+
1036
+ sage: [RBF.fibonacci(n) for n in range(7)]
1037
+ [0,
1038
+ 1.000000000000000,
1039
+ 1.000000000000000,
1040
+ 2.000000000000000,
1041
+ 3.000000000000000,
1042
+ 5.000000000000000,
1043
+ 8.000000000000000]
1044
+ sage: RBF.fibonacci(-2)
1045
+ -1.000000000000000
1046
+ sage: RBF.fibonacci(10**20)
1047
+ [3.78202087472056e+20898764024997873376 +/- ...e+20898764024997873361]
1048
+ """
1049
+ cdef fmpz_t tmpz
1050
+ cdef RealBall res = self.element_class(self)
1051
+ cdef Integer n_as_Integer = ZZ.coerce(n)
1052
+ try:
1053
+ if _do_sig(self._prec): sig_on()
1054
+ fmpz_init(tmpz)
1055
+ fmpz_set_mpz(tmpz, n_as_Integer.value)
1056
+ arb_fib_fmpz(res.value, tmpz, self._prec)
1057
+ if _do_sig(self._prec): sig_off()
1058
+ finally:
1059
+ fmpz_clear(tmpz)
1060
+ return res
1061
+
1062
+ def bell_number(self, n):
1063
+ """
1064
+ Return a ball enclosing the ``n``-th Bell number.
1065
+
1066
+ EXAMPLES::
1067
+
1068
+ sage: [RBF.bell_number(n) for n in range(7)]
1069
+ [1.000000000000000,
1070
+ 1.000000000000000,
1071
+ 2.000000000000000,
1072
+ 5.000000000000000,
1073
+ 15.00000000000000,
1074
+ 52.00000000000000,
1075
+ 203.0000000000000]
1076
+ sage: RBF.bell_number(-1)
1077
+ Traceback (most recent call last):
1078
+ ...
1079
+ ValueError: expected a nonnegative index
1080
+ sage: RBF.bell_number(10**20)
1081
+ [5.38270113176282e+1794956117137290721328 +/- ...e+1794956117137290721313]
1082
+ """
1083
+ cdef fmpz_t tmpz
1084
+ cdef RealBall res = self.element_class(self)
1085
+ cdef Integer n_as_Integer = ZZ.coerce(n)
1086
+ if n_as_Integer < 0:
1087
+ raise ValueError("expected a nonnegative index")
1088
+ try:
1089
+ if _do_sig(self._prec): sig_on()
1090
+ fmpz_init(tmpz)
1091
+ fmpz_set_mpz(tmpz, n_as_Integer.value)
1092
+ arb_bell_fmpz(res.value, tmpz, self._prec)
1093
+ if _do_sig(self._prec): sig_off()
1094
+ finally:
1095
+ fmpz_clear(tmpz)
1096
+ return res
1097
+
1098
+ def double_factorial(self, n):
1099
+ """
1100
+ Return a ball enclosing the ``n``-th double factorial.
1101
+
1102
+ EXAMPLES::
1103
+
1104
+ sage: [RBF.double_factorial(n) for n in range(7)]
1105
+ [1.000000000000000,
1106
+ 1.000000000000000,
1107
+ 2.000000000000000,
1108
+ 3.000000000000000,
1109
+ 8.000000000000000,
1110
+ 15.00000000000000,
1111
+ 48.00000000000000]
1112
+ sage: RBF.double_factorial(2**20)
1113
+ [1.448372990...e+2928836 +/- ...]
1114
+ sage: RBF.double_factorial(2**1000)
1115
+ Traceback (most recent call last):
1116
+ ...
1117
+ ValueError: argument too large
1118
+ sage: RBF.double_factorial(-1)
1119
+ Traceback (most recent call last):
1120
+ ...
1121
+ ValueError: expected a nonnegative index
1122
+ """
1123
+ cdef RealBall res
1124
+ cdef Integer n_as_Integer = ZZ.coerce(n)
1125
+ if mpz_fits_ulong_p(n_as_Integer.value):
1126
+ res = self.element_class(self)
1127
+ if _do_sig(self._prec): sig_on()
1128
+ arb_doublefac_ui(res.value, mpz_get_ui(n_as_Integer.value), self._prec)
1129
+ if _do_sig(self._prec): sig_off()
1130
+ return res
1131
+ elif n_as_Integer < 0:
1132
+ raise ValueError("expected a nonnegative index")
1133
+ else:
1134
+ # TODO: Fall back to a Sage implementation in this case?
1135
+ raise ValueError("argument too large")
1136
+
1137
+ def maximal_accuracy(self):
1138
+ r"""
1139
+ Return the relative accuracy of exact elements measured in bits.
1140
+
1141
+ OUTPUT: integer
1142
+
1143
+ EXAMPLES::
1144
+
1145
+ sage: RBF.maximal_accuracy()
1146
+ 9223372036854775807 # 64-bit
1147
+ 2147483647 # 32-bit
1148
+
1149
+ .. SEEALSO:: :meth:`RealBall.accuracy`
1150
+ """
1151
+ return ARF_PREC_EXACT
1152
+
1153
+
1154
+ cdef inline bint _do_sig(long prec) noexcept:
1155
+ """
1156
+ Whether signal handlers should be installed for calls to FLINT.
1157
+
1158
+ TESTS::
1159
+
1160
+ sage: _ = RealBallField()(1).psi() # indirect doctest
1161
+ sage: _ = RealBallField(1500)(1).psi()
1162
+ """
1163
+ return (prec > 1000)
1164
+
1165
+ cdef inline long prec(RealBall ball) noexcept:
1166
+ return ball._parent._prec
1167
+
1168
+
1169
+ def create_RealBall(parent, serialized):
1170
+ r"""
1171
+ Create a RealBall from a serialized representation.
1172
+
1173
+ TESTS::
1174
+
1175
+ sage: from sage.rings.real_arb import create_RealBall
1176
+ sage: create_RealBall(RBF, b'15555555555555 -36 1 -36')
1177
+ [0.3333333333333333 +/- 7.04e-17]
1178
+ sage: create_RealBall(RBF, b'foo')
1179
+ Traceback (most recent call last):
1180
+ ...
1181
+ ValueError: incorrect format
1182
+ """
1183
+ cdef RealBall res = RealBall.__new__(RealBall)
1184
+ res._parent = parent
1185
+ sig_on()
1186
+ cdef bint error = arb_load_str(res.value, serialized)
1187
+ sig_off()
1188
+ if error:
1189
+ raise ValueError("incorrect format")
1190
+ else:
1191
+ return res
1192
+
1193
+
1194
+ cdef class RealBall(RingElement):
1195
+ """
1196
+ Hold one ``arb_t``.
1197
+
1198
+ EXAMPLES::
1199
+
1200
+ sage: a = RealBallField()(RIF(1)) # indirect doctest
1201
+ sage: b = a.psi()
1202
+ sage: b # abs tol 1e-15
1203
+ [-0.5772156649015329 +/- 4.84e-17]
1204
+ sage: RIF(b)
1205
+ -0.577215664901533?
1206
+ """
1207
+
1208
+ def __cinit__(self):
1209
+ """
1210
+ Initialize the parent and allocate memory.
1211
+
1212
+ EXAMPLES::
1213
+
1214
+ sage: RealBallField()(RIF(1)) # indirect doctest
1215
+ 1.000000000000000
1216
+ """
1217
+ arb_init(self.value)
1218
+
1219
+ def __dealloc__(self):
1220
+ """
1221
+ Deallocate memory of the encapsulated value.
1222
+
1223
+ EXAMPLES::
1224
+
1225
+ sage: a = RealBallField()(RIF(1)) # indirect doctest
1226
+ sage: del a
1227
+ """
1228
+ arb_clear(self.value)
1229
+
1230
+ def __init__(self, parent, mid=None, rad=None):
1231
+ """
1232
+ Initialize the :class:`RealBall`.
1233
+
1234
+ INPUT:
1235
+
1236
+ - ``parent`` -- a :class:`RealBallField`
1237
+
1238
+ - ``mid`` -- (optional) ball midpoint, see examples below. If omitted,
1239
+ initialize the ball to zero, ignoring the ``rad`` argument.
1240
+
1241
+ - ``rad`` -- (optional) a :class:`RealNumber` or a Python float, ball
1242
+ radius. If the midpoint is not exactly representable in
1243
+ floating-point, the radius is adjusted to account for the roundoff
1244
+ error.
1245
+
1246
+ EXAMPLES::
1247
+
1248
+ sage: RBF = RealBallField()
1249
+ sage: RBF()
1250
+ 0
1251
+
1252
+ One can create exact real balls using elements of various exact parents,
1253
+ or using floating-point numbers::
1254
+
1255
+ sage: RBF(3)
1256
+ 3.000000000000000
1257
+ sage: RBF(3r)
1258
+ 3.000000000000000
1259
+ sage: RBF(1/3)
1260
+ [0.3333333333333333 +/- ...e-17]
1261
+ sage: RBF(3.14)
1262
+ [3.140000000000000 +/- ...e-16]
1263
+
1264
+ ::
1265
+
1266
+ sage: RBF(3, 0.125)
1267
+ [3e+0 +/- 0.126]
1268
+ sage: RBF(pi, 0.125r) # needs sage.symbolic
1269
+ [3e+0 +/- 0.267]
1270
+ sage: RBF(3, 1/8)
1271
+ [3e+0 +/- 0.126]
1272
+ sage: RBF(13, 1)
1273
+ [1e+1 +/- 4.01]
1274
+
1275
+ ::
1276
+
1277
+ sage: NF.<sqrt2> = QuadraticField(2) # needs sage.rings.number_field
1278
+ sage: RBF(1/5 + sqrt2/2) # needs sage.rings.number_field
1279
+ [0.907106781186547 +/- ...e-16]
1280
+
1281
+ Note that integers and floating-point numbers are ''not'' rounded to
1282
+ the parent's precision::
1283
+
1284
+ sage: b = RBF(11111111111111111111111111111111111111111111111); b
1285
+ [1.111111111111111e+46 +/- ...e+30]
1286
+ sage: b.mid().exact_rational()
1287
+ 11111111111111111111111111111111111111111111111
1288
+
1289
+ Similarly, converting a real ball from one real ball field to another
1290
+ (with a different precision) only changes the way it is displayed and
1291
+ the precision of operations involving it, not the actual representation
1292
+ of its center::
1293
+
1294
+ sage: RBF100 = RealBallField(100)
1295
+ sage: b100 = RBF100(1/3); b100
1296
+ [0.333333333333333333333333333333 +/- ...e-31]
1297
+ sage: b53 = RBF(b100); b53
1298
+ [0.3333333333333333 +/- ...e-17]
1299
+ sage: RBF100(b53)
1300
+ [0.333333333333333333333333333333 +/- ...e-31]
1301
+
1302
+ Special values are supported::
1303
+
1304
+ sage: RBF(oo).mid(), RBF(-oo).mid(), RBF(unsigned_infinity).mid()
1305
+ (+infinity, -infinity, 0.000000000000000)
1306
+ sage: RBF(NaN)
1307
+ nan
1308
+
1309
+ Strings can be given as input. Strings must contain decimal
1310
+ floating-point literals. A valid string must consist of a midpoint,
1311
+ a midpoint and a radius separated by "+/-", or just a
1312
+ radius prefixed by "+/-". Optionally, the whole string can be enclosed
1313
+ in square brackets. In general, the string representation of a
1314
+ real ball as returned by ``str()`` can be parsed back (the result
1315
+ will be larger than the original ball if rounding occurs).
1316
+ A few examples::
1317
+
1318
+ sage: RBF("1.1")
1319
+ [1.100000000000000 +/- ...e-16]
1320
+ sage: RBF(str(RBF("1.1")))
1321
+ [1.100000000000000 +/- ...e-16]
1322
+ sage: RBF("3.25")
1323
+ 3.250000000000000
1324
+ sage: RBF("-3.1 +/- 1e-10")
1325
+ [-3.100000000 +/- ...e-10]
1326
+ sage: RBF("[+/-1]")
1327
+ [+/- 1.01]
1328
+ sage: RBF("inf +/- inf")
1329
+ [+/- inf]
1330
+
1331
+ .. SEEALSO:: :meth:`RealBallField._element_constructor_`
1332
+
1333
+ TESTS::
1334
+
1335
+ sage: from sage.rings.real_arb import RealBall
1336
+ sage: RealBall(RBF, sage.symbolic.constants.Pi())
1337
+ [3.141592653589793 +/- ...e-16]
1338
+ sage: RealBall(RBF, sage.symbolic.constants.Log2())
1339
+ [0.6931471805599453 +/- ...e-17]
1340
+ sage: RealBall(RBF, sage.symbolic.constants.Catalan())
1341
+ [0.915965594177219 +/- ...e-16]
1342
+ sage: RealBall(RBF, sage.symbolic.constants.Khinchin())
1343
+ [2.685452001065306 +/- ...e-16]
1344
+ sage: RealBall(RBF, sage.symbolic.constants.Glaisher())
1345
+ [1.282427129100623 +/- ...e-16]
1346
+ sage: RealBall(RBF, sage.symbolic.constants.e)
1347
+ [2.718281828459045 +/- ...e-16]
1348
+ sage: RealBall(RBF, sage.symbolic.constants.EulerGamma()) # abs tol 1e-15
1349
+ [0.5772156649015329 +/- 9.00e-17]
1350
+ sage: RBF("1 +/- 0.001")
1351
+ [1.00 +/- ...e-3]
1352
+ sage: RBF("2.3e10000000000000000000000 +/- 0.00005e10000000000000000000000")
1353
+ [2.3000e+10000000000000000000000 +/- ...e+9999999999999999999995]
1354
+ sage: RBF("0.3 +/- 0.2 +/- 0.1")
1355
+ Traceback (most recent call last):
1356
+ ...
1357
+ ValueError: unsupported string format
1358
+
1359
+ sage: # needs sage.rings.number_field
1360
+ sage: NF.<a> = QuadraticField(2, embedding=AA(2).sqrt())
1361
+ sage: RBF.coerce(a)
1362
+ [1.414213562373095 +/- ...e-16]
1363
+ sage: NF.<a> = QuadraticField(2, embedding=-AA(2).sqrt())
1364
+ sage: RBF.coerce(a)
1365
+ [-1.414213562373095 +/- ...e-16]
1366
+ sage: NF.<a> = QuadraticField(2, embedding=None)
1367
+ sage: RBF.coerce(a)
1368
+ Traceback (most recent call last):
1369
+ ...
1370
+ TypeError: no canonical coercion ...
1371
+ sage: QQi.<i> = QuadraticField(-1)
1372
+ sage: RBF(QQi(3))
1373
+ 3.000000000000000
1374
+ sage: RBF(i)
1375
+ Traceback (most recent call last):
1376
+ ...
1377
+ ValueError: nonzero imaginary part
1378
+ sage: RBF.coerce(QQi(3))
1379
+ Traceback (most recent call last):
1380
+ ...
1381
+ TypeError: no canonical coercion...
1382
+ """
1383
+ cdef fmpz_t tmpz
1384
+ cdef fmpq_t tmpq
1385
+ cdef arf_t tmpr
1386
+ cdef mag_t tmpm
1387
+
1388
+ Element.__init__(self, parent)
1389
+
1390
+ if mid is None:
1391
+ return
1392
+
1393
+ elif isinstance(mid, RealBall):
1394
+ arb_set(self.value, (<RealBall> mid).value) # no rounding!
1395
+ elif is_small_python_int(mid):
1396
+ arb_set_si(self.value, PyLong_AsLong(mid)) # no rounding!
1397
+ elif isinstance(mid, Integer):
1398
+ if _do_sig(prec(self)): sig_on()
1399
+ fmpz_init(tmpz)
1400
+ fmpz_set_mpz(tmpz, (<Integer> mid).value)
1401
+ arb_set_fmpz(self.value, tmpz) # no rounding!
1402
+ fmpz_clear(tmpz)
1403
+ if _do_sig(prec(self)): sig_off()
1404
+ elif isinstance(mid, Rational):
1405
+ if _do_sig(prec(self)): sig_on()
1406
+ fmpq_init(tmpq)
1407
+ fmpq_set_mpq(tmpq, (<Rational> mid).value)
1408
+ arb_set_fmpq(self.value, tmpq, prec(self))
1409
+ fmpq_clear(tmpq)
1410
+ if _do_sig(prec(self)): sig_off()
1411
+ elif isinstance(mid, RealNumber):
1412
+ if _do_sig(prec(self)): sig_on()
1413
+ arf_init(tmpr)
1414
+ arf_set_mpfr(tmpr, (<RealNumber> mid).value)
1415
+ arb_set_arf(self.value, tmpr) # no rounding!
1416
+ arf_clear(tmpr)
1417
+ if _do_sig(prec(self)): sig_off()
1418
+ elif isinstance(mid, RealIntervalFieldElement):
1419
+ mpfi_to_arb(self.value,
1420
+ (<RealIntervalFieldElement> mid).value,
1421
+ prec(self))
1422
+ elif isinstance(mid, str):
1423
+ if arb_set_str(self.value, str_to_bytes(mid), prec(self)) != 0:
1424
+ raise ValueError("unsupported string format")
1425
+ else:
1426
+ # the initializers that trigger imports
1427
+ import sage.rings.infinity
1428
+ if isinstance(mid, sage.rings.infinity.AnInfinity):
1429
+ if isinstance(mid, sage.rings.infinity.PlusInfinity):
1430
+ arb_pos_inf(self.value)
1431
+ elif isinstance(mid, sage.rings.infinity.MinusInfinity):
1432
+ arb_neg_inf(self.value)
1433
+ else:
1434
+ arb_zero_pm_inf(self.value)
1435
+ else:
1436
+ try:
1437
+ import sage.symbolic.constants
1438
+ import sage.symbolic.expression
1439
+ except ImportError:
1440
+ raise TypeError("unsupported midpoint type")
1441
+ if isinstance(mid, sage.symbolic.constants.Constant):
1442
+ if _do_sig(prec(self)): sig_on()
1443
+ try:
1444
+ if isinstance(mid, sage.symbolic.constants.NotANumber):
1445
+ arb_indeterminate(self.value)
1446
+ elif isinstance(mid, sage.symbolic.constants.Pi):
1447
+ arb_const_pi(self.value, prec(self))
1448
+ elif isinstance(mid, sage.symbolic.constants.Log2):
1449
+ arb_const_log2(self.value, prec(self))
1450
+ elif isinstance(mid, sage.symbolic.constants.Catalan):
1451
+ arb_const_catalan(self.value, prec(self))
1452
+ elif isinstance(mid, sage.symbolic.constants.Khinchin):
1453
+ arb_const_khinchin(self.value, prec(self))
1454
+ elif isinstance(mid, sage.symbolic.constants.Glaisher):
1455
+ arb_const_glaisher(self.value, prec(self))
1456
+ elif isinstance(mid, sage.symbolic.constants.EulerGamma):
1457
+ arb_const_euler(self.value, prec(self))
1458
+ else:
1459
+ raise TypeError("unsupported constant")
1460
+ finally:
1461
+ if _do_sig(prec(self)): sig_off()
1462
+ elif isinstance(mid, sage.symbolic.expression.E):
1463
+ if _do_sig(prec(self)): sig_on()
1464
+ arb_const_e(self.value, prec(self))
1465
+ if _do_sig(prec(self)): sig_off()
1466
+ else:
1467
+ raise TypeError("unsupported midpoint type")
1468
+
1469
+ if rad is not None:
1470
+ mag_init(tmpm)
1471
+ if isinstance(rad, RealNumber):
1472
+ arf_init(tmpr)
1473
+ arf_set_mpfr(tmpr, (<RealNumber> rad).value)
1474
+ arf_get_mag(tmpm, tmpr)
1475
+ arf_clear(tmpr)
1476
+ elif isinstance(rad, Integer):
1477
+ arf_init(tmpr)
1478
+ arf_set_mpz(tmpr, (<Integer> rad).value)
1479
+ arf_get_mag(tmpm, tmpr)
1480
+ arf_clear(tmpr)
1481
+ elif isinstance(rad, Rational):
1482
+ arf_init(tmpr)
1483
+ arf_set_mpz(tmpr, (<Integer> rad.numerator()).value)
1484
+ fmpz_init(tmpz)
1485
+ fmpz_set_mpz(tmpz, (<Integer> rad.denominator()).value)
1486
+ arf_div_fmpz(tmpr, tmpr, tmpz, prec(self), ARF_RND_UP)
1487
+ arf_get_mag(tmpm, tmpr)
1488
+ arf_clear(tmpr)
1489
+ elif isinstance(rad, float):
1490
+ mag_set_d(tmpm, PyFloat_AS_DOUBLE(rad))
1491
+ else:
1492
+ raise TypeError("rad should be a RealNumber or a Python float")
1493
+ mag_add(arb_radref(self.value), arb_radref(self.value), tmpm)
1494
+ mag_clear(tmpm)
1495
+
1496
+ def __hash__(self):
1497
+ """
1498
+ TESTS::
1499
+
1500
+ sage: hash(RealBallField(10)(1)) == hash(RealBallField(20)(1))
1501
+ True
1502
+ sage: hash(RBF(1/3)) == hash(RBF(1/3, rad=.1))
1503
+ False
1504
+ sage: vals = [0, 1, 3/4, 5/8, 7/8, infinity, 'nan', 2^1000 - 1]
1505
+ sage: len({hash(RBF(v)) for v in vals}) == len(vals)
1506
+ True
1507
+ """
1508
+ cdef arf_t mid = arb_midref(self.value)
1509
+ cdef fmpz_t mant, expo
1510
+ fmpz_init(mant)
1511
+ fmpz_init(expo)
1512
+ arf_get_fmpz_2exp(mant, expo, mid)
1513
+ cdef long h = (
1514
+ fmpz_fdiv_ui(mant, 1073741789)
1515
+ ^ fmpz_fdiv_ui(expo, 2**30)
1516
+ ^ (arf_abs_bound_lt_2exp_si(mid) << 10)
1517
+ ^ arb_rel_error_bits(self.value) << 20)
1518
+ fmpz_clear(expo)
1519
+ fmpz_clear(mant)
1520
+ return h
1521
+
1522
+ def _repr_(self):
1523
+ """
1524
+ Return a string representation of ``self``.
1525
+
1526
+ OUTPUT: string
1527
+
1528
+ EXAMPLES::
1529
+
1530
+ sage: RealBallField()(RIF(1.9, 2))
1531
+ [2e+0 +/- 0.101]
1532
+ """
1533
+ cdef char* c_result
1534
+
1535
+ c_result = arb_get_str(self.value, (prec(self) * 31) // 100, 0)
1536
+ try:
1537
+ py_string = char_to_str(c_result)
1538
+ finally:
1539
+ flint_free(c_result)
1540
+
1541
+ return py_string
1542
+
1543
+ def __reduce__(self):
1544
+ r"""
1545
+ Serialize a RealBall.
1546
+
1547
+ TESTS::
1548
+
1549
+ sage: [loads(dumps(b)).identical(b)
1550
+ ....: for b in [RealBallField(60).pi(), RBF(infinity)]]
1551
+ [True, True]
1552
+ sage: b = RBF(NaN); loads(dumps(b)).identical(b) # needs sage.symbolic
1553
+ True
1554
+ """
1555
+ cdef bytes py_val
1556
+ sig_on()
1557
+ cdef char* c_val = arb_dump_str(self.value)
1558
+ sig_off()
1559
+ try:
1560
+ py_val = <bytes> c_val
1561
+ finally:
1562
+ flint_free(c_val)
1563
+ return create_RealBall, (self._parent, py_val)
1564
+
1565
+ # Conversions
1566
+
1567
+ cpdef RealIntervalFieldElement _real_mpfi_(self, RealIntervalField_class parent):
1568
+ """
1569
+ Return a :mod:`real interval <sage.rings.real_mpfi>` containing this ball.
1570
+
1571
+ OUTPUT: a :class:`~sage.rings.real_mpfi.RealIntervalFieldElement`
1572
+
1573
+ EXAMPLES::
1574
+
1575
+ sage: a = RealBallField()(RIF(2))
1576
+ sage: RIF(a) # indirect doctest
1577
+ 2
1578
+ """
1579
+ cdef RealIntervalFieldElement result
1580
+ result = parent(0)
1581
+ arb_to_mpfi(result.value, self.value, prec(self))
1582
+ return result
1583
+
1584
+ def _integer_(self, _):
1585
+ """
1586
+ Check that this ball contains a single integer and return that integer.
1587
+
1588
+ EXAMPLES::
1589
+
1590
+ sage: ZZ(RBF(1, rad=0.1r))
1591
+ 1
1592
+ sage: ZZ(RBF(1, rad=1.0r))
1593
+ Traceback (most recent call last):
1594
+ ...
1595
+ ValueError: [+/- 2.01] does not contain a unique integer
1596
+ sage: ZZ(RBF(pi)) # needs sage.symbolic
1597
+ Traceback (most recent call last):
1598
+ ...
1599
+ ValueError: [3.141592653589793 +/- ...e-16] does not contain a unique integer
1600
+ """
1601
+ cdef Integer res
1602
+ cdef fmpz_t tmp
1603
+ fmpz_init(tmp)
1604
+ try:
1605
+ if arb_get_unique_fmpz(tmp, self.value):
1606
+ res = Integer.__new__(Integer)
1607
+ fmpz_get_mpz(res.value, tmp)
1608
+ else:
1609
+ raise ValueError("{} does not contain a unique integer".format(self))
1610
+ finally:
1611
+ fmpz_clear(tmp)
1612
+ return res
1613
+
1614
+ def _rational_(self):
1615
+ """
1616
+ Check that this ball contains a single rational number and return that
1617
+ number.
1618
+
1619
+ EXAMPLES::
1620
+
1621
+ sage: QQ(RBF(123456/2^12))
1622
+ 1929/64
1623
+ sage: QQ(RBF(1/3))
1624
+ Traceback (most recent call last):
1625
+ ...
1626
+ ValueError: [0.3333333333333333 +/- ...e-17] does not contain a unique rational number
1627
+ """
1628
+ if arb_is_exact(self.value):
1629
+ return self.mid().exact_rational()
1630
+ else:
1631
+ raise ValueError("{} does not contain a unique rational number".format(self))
1632
+
1633
+ def _mpfr_(self, RealField_class field):
1634
+ """
1635
+ Convert this real ball to a real number.
1636
+
1637
+ This attempts to do something sensible for all rounding modes, as
1638
+ illustrated below.
1639
+
1640
+ EXAMPLES::
1641
+
1642
+ sage: # needs sage.symbolic
1643
+ sage: mypi = RBF(pi)
1644
+ sage: RR(mypi)
1645
+ 3.14159265358979
1646
+ sage: Reals(rnd='RNDU')(mypi)
1647
+ 3.14159265358980
1648
+ sage: Reals(rnd='RNDD')(mypi)
1649
+ 3.14159265358979
1650
+ sage: Reals(rnd='RNDZ')(mypi)
1651
+ 3.14159265358979
1652
+ sage: Reals(rnd='RNDZ')(-mypi)
1653
+ -3.14159265358979
1654
+ sage: Reals(rnd='RNDU')(-mypi)
1655
+ -3.14159265358979
1656
+
1657
+ ::
1658
+
1659
+ sage: b = RBF(RIF(-1/2, 1))
1660
+ sage: RR(b)
1661
+ 0.250000000000000
1662
+ sage: Reals(rnd='RNDU')(b)
1663
+ 1.00000000093133
1664
+ sage: Reals(rnd='RNDD')(b)
1665
+ -0.500000000931323
1666
+ sage: Reals(rnd='RNDZ')(b)
1667
+ 0.250000000000000
1668
+ """
1669
+ cdef RealNumber left, mid, right
1670
+ cdef int sl, sr
1671
+ if (field.rnd == MPFR_RNDN or
1672
+ field.rnd == MPFR_RNDZ and arb_contains_zero(self.value)):
1673
+ mid = RealNumber(field, None)
1674
+ sig_str("unable to convert to MPFR (exponent out of range?)")
1675
+ arf_get_mpfr(mid.value, arb_midref(self.value), field.rnd)
1676
+ sig_off()
1677
+ return mid
1678
+ else:
1679
+ left = RealNumber(field, None)
1680
+ right = RealNumber(field, None)
1681
+ sig_str("unable to convert to MPFR (exponent out of range?)")
1682
+ arb_get_interval_mpfr(left.value, right.value, self.value)
1683
+ sig_off()
1684
+ if field.rnd == MPFR_RNDD:
1685
+ return left
1686
+ elif field.rnd == MPFR_RNDU:
1687
+ return right
1688
+ elif field.rnd == MPFR_RNDZ:
1689
+ sl, sr = mpfr_sgn(left.value), mpfr_sgn(left.value)
1690
+ if sr > 0 and sl > 0:
1691
+ return left
1692
+ elif sr < 0 and sl < 0:
1693
+ return right
1694
+ else:
1695
+ return field(0)
1696
+ raise ValueError("unknown rounding mode")
1697
+
1698
+ def __float__(self):
1699
+ """
1700
+ Convert ``self`` to a ``float``.
1701
+
1702
+ EXAMPLES::
1703
+
1704
+ sage: float(RBF(1))
1705
+ 1.0
1706
+ """
1707
+ return float(self.n(prec(self)))
1708
+
1709
+ def __complex__(self):
1710
+ """
1711
+ Convert ``self`` to a ``complex``.
1712
+
1713
+ EXAMPLES::
1714
+
1715
+ sage: complex(RBF(1))
1716
+ (1+0j)
1717
+ """
1718
+ return complex(self.n(prec(self)))
1719
+
1720
+ # Center and radius, absolute value, endpoints
1721
+
1722
+ def mid(self):
1723
+ """
1724
+ Return the center of this ball.
1725
+
1726
+ EXAMPLES::
1727
+
1728
+ sage: RealBallField(16)(1/3).mid()
1729
+ 0.3333
1730
+ sage: RealBallField(16)(1/3).mid().parent()
1731
+ Real Field with 16 bits of precision
1732
+ sage: RealBallField(16)(RBF(1/3)).mid().parent()
1733
+ Real Field with 53 bits of precision
1734
+ sage: RBF('inf').mid()
1735
+ +infinity
1736
+
1737
+ ::
1738
+
1739
+ sage: b = RBF(2)^(2^1000)
1740
+ sage: b.mid()
1741
+ +infinity
1742
+
1743
+ .. SEEALSO:: :meth:`rad`, :meth:`squash`
1744
+ """
1745
+ cdef long mid_prec = max(arb_bits(self.value), prec(self))
1746
+ if mid_prec < MPFR_PREC_MIN:
1747
+ mid_prec = MPFR_PREC_MIN
1748
+ cdef RealField_class mid_field = RealField(mid_prec)
1749
+ return self._mpfr_(mid_field)
1750
+
1751
+ center = mid
1752
+
1753
+ def rad(self):
1754
+ """
1755
+ Return the radius of this ball.
1756
+
1757
+ EXAMPLES::
1758
+
1759
+ sage: RBF(1/3).rad()
1760
+ 5.5511151e-17
1761
+ sage: RBF(1/3).rad().parent()
1762
+ Real Field with 30 bits of precision
1763
+
1764
+ .. SEEALSO:: :meth:`mid`, :meth:`rad_as_ball`, :meth:`diameter`
1765
+
1766
+ TESTS::
1767
+
1768
+ sage: (RBF(1, rad=.1) << (2^64)).rad()
1769
+ Traceback (most recent call last):
1770
+ ...
1771
+ RuntimeError: unable to convert the radius to MPFR (exponent out of range?)
1772
+ """
1773
+ # Should we return a real number with rounding towards +∞ (or away from
1774
+ # zero if/when implemented)?
1775
+ cdef RealField_class rad_field = RealField(MAG_BITS)
1776
+ cdef RealNumber rad = RealNumber(rad_field, None)
1777
+ cdef arf_t tmp
1778
+ arf_init(tmp)
1779
+ sig_str("unable to convert the radius to MPFR (exponent out of range?)")
1780
+ arf_set_mag(tmp, arb_radref(self.value))
1781
+ if arf_get_mpfr(rad.value, tmp, MPFR_RNDN):
1782
+ abort()
1783
+ sig_off()
1784
+ arf_clear(tmp)
1785
+ return rad
1786
+
1787
+ def diameter(self):
1788
+ r"""
1789
+ Return the diameter of this ball.
1790
+
1791
+ EXAMPLES::
1792
+
1793
+ sage: RBF(1/3).diameter()
1794
+ 1.1102230e-16
1795
+ sage: RBF(1/3).diameter().parent()
1796
+ Real Field with 30 bits of precision
1797
+ sage: RBF(RIF(1.02, 1.04)).diameter()
1798
+ 0.020000000
1799
+
1800
+ .. SEEALSO:: :meth:`rad`, :meth:`rad_as_ball`, :meth:`mid`
1801
+ """
1802
+ return 2 * self.rad()
1803
+
1804
+ def squash(self):
1805
+ """
1806
+ Return an exact ball with the same center as this ball.
1807
+
1808
+ EXAMPLES::
1809
+
1810
+ sage: mid = RealBallField(16)(1/3).squash()
1811
+ sage: mid
1812
+ [0.3333 +/- ...e-5]
1813
+ sage: mid.is_exact()
1814
+ True
1815
+ sage: mid.parent()
1816
+ Real ball field with 16 bits of precision
1817
+
1818
+ .. SEEALSO:: :meth:`mid`, :meth:`rad_as_ball`
1819
+ """
1820
+ cdef RealBall res = self._new()
1821
+ arf_set(arb_midref(res.value), arb_midref(self.value))
1822
+ mag_zero(arb_radref(res.value))
1823
+ return res
1824
+
1825
+ def rad_as_ball(self):
1826
+ """
1827
+ Return an exact ball with center equal to the radius of this ball.
1828
+
1829
+ EXAMPLES::
1830
+
1831
+ sage: rad = RBF(1/3).rad_as_ball()
1832
+ sage: rad
1833
+ [5.55111512e-17 +/- ...e-26]
1834
+ sage: rad.is_exact()
1835
+ True
1836
+ sage: rad.parent()
1837
+ Real ball field with 30 bits of precision
1838
+
1839
+ .. SEEALSO:: :meth:`squash`, :meth:`rad`
1840
+ """
1841
+ cdef RealBall res = self._parent.element_class(RealBallField(MAG_BITS))
1842
+ arf_set_mag(arb_midref(res.value), arb_radref(self.value))
1843
+ mag_zero(arb_radref(res.value))
1844
+ return res
1845
+
1846
+ def __abs__(self):
1847
+ """
1848
+ Return the absolute value of this ball.
1849
+
1850
+ EXAMPLES::
1851
+
1852
+ sage: RBF(-1/3).abs() # indirect doctest
1853
+ [0.3333333333333333 +/- ...e-17]
1854
+ sage: abs(RBF(-1))
1855
+ 1.000000000000000
1856
+ """
1857
+ cdef RealBall r = self._new()
1858
+ arb_abs(r.value, self.value)
1859
+ return r
1860
+
1861
+ def below_abs(self, test_zero=False):
1862
+ """
1863
+ Return a lower bound for the absolute value of this ball.
1864
+
1865
+ INPUT:
1866
+
1867
+ - ``test_zero`` -- boolean (default: ``False``); if ``True``,
1868
+ make sure that the returned lower bound is positive, raising
1869
+ an error if the ball contains zero.
1870
+
1871
+ OUTPUT: a ball with zero radius
1872
+
1873
+ EXAMPLES::
1874
+
1875
+ sage: RealBallField(8)(1/3).below_abs()
1876
+ [0.33 +/- ...e-5]
1877
+ sage: b = RealBallField(8)(1/3).below_abs()
1878
+ sage: b
1879
+ [0.33 +/- ...e-5]
1880
+ sage: b.is_exact()
1881
+ True
1882
+ sage: QQ(b)
1883
+ 169/512
1884
+
1885
+ sage: RBF(0).below_abs()
1886
+ 0
1887
+ sage: RBF(0).below_abs(test_zero=True)
1888
+ Traceback (most recent call last):
1889
+ ...
1890
+ ValueError: ball contains zero
1891
+
1892
+ .. SEEALSO:: :meth:`above_abs`
1893
+ """
1894
+ cdef RealBall res = self._new()
1895
+ arb_get_abs_lbound_arf(arb_midref(res.value), self.value, prec(self))
1896
+ if test_zero and arb_contains_zero(res.value):
1897
+ assert arb_contains_zero(self.value)
1898
+ raise ValueError("ball contains zero")
1899
+ return res
1900
+
1901
+ def above_abs(self):
1902
+ """
1903
+ Return an upper bound for the absolute value of this ball.
1904
+
1905
+ OUTPUT: a ball with zero radius
1906
+
1907
+ EXAMPLES::
1908
+
1909
+ sage: b = RealBallField(8)(1/3).above_abs()
1910
+ sage: b
1911
+ [0.33 +/- ...e-3]
1912
+ sage: b.is_exact()
1913
+ True
1914
+ sage: QQ(b)
1915
+ 171/512
1916
+
1917
+ .. SEEALSO:: :meth:`below_abs`
1918
+ """
1919
+ cdef RealBall res = self._new()
1920
+ arb_get_abs_ubound_arf(arb_midref(res.value), self.value, prec(self))
1921
+ return res
1922
+
1923
+ def upper(self, rnd=None):
1924
+ """
1925
+ Return the right endpoint of this ball, rounded upwards.
1926
+
1927
+ INPUT:
1928
+
1929
+ - ``rnd`` -- string; rounding mode for the parent of the result (does
1930
+ not affect its value!), see
1931
+ :meth:`sage.rings.real_mpfi.RealIntervalFieldElement.upper`
1932
+
1933
+ OUTPUT: a real number
1934
+
1935
+ EXAMPLES::
1936
+
1937
+ sage: RBF(-1/3).upper()
1938
+ -0.333333333333333
1939
+ sage: RBF(-1/3).upper().parent()
1940
+ Real Field with 53 bits of precision and rounding RNDU
1941
+
1942
+ .. SEEALSO::
1943
+
1944
+ :meth:`lower`, :meth:`endpoints`
1945
+ """
1946
+ # naive and slow
1947
+ return self._real_mpfi_(RealIntervalField(prec(self))).upper(rnd)
1948
+
1949
+ def lower(self, rnd=None):
1950
+ """
1951
+ Return the right endpoint of this ball, rounded downwards.
1952
+
1953
+ INPUT:
1954
+
1955
+ - ``rnd`` -- string; rounding mode for the parent of the result (does
1956
+ not affect its value!), see
1957
+ :meth:`sage.rings.real_mpfi.RealIntervalFieldElement.lower`
1958
+
1959
+ OUTPUT: a real number
1960
+
1961
+ EXAMPLES::
1962
+
1963
+ sage: RBF(-1/3).lower()
1964
+ -0.333333333333334
1965
+ sage: RBF(-1/3).lower().parent()
1966
+ Real Field with 53 bits of precision and rounding RNDD
1967
+
1968
+ .. SEEALSO:: :meth:`upper`, :meth:`endpoints`
1969
+ """
1970
+ # naive and slow
1971
+ return self._real_mpfi_(RealIntervalField(prec(self))).lower(rnd)
1972
+
1973
+ def endpoints(self, rnd=None):
1974
+ """
1975
+ Return the endpoints of this ball, rounded outwards.
1976
+
1977
+ INPUT:
1978
+
1979
+ - ``rnd`` -- string; rounding mode for the parent of the resulting
1980
+ floating-point numbers (does not affect their values!), see
1981
+ :meth:`sage.rings.real_mpfi.RealIntervalFieldElement.upper`
1982
+
1983
+ OUTPUT: a pair of real numbers
1984
+
1985
+ EXAMPLES::
1986
+
1987
+ sage: RBF(-1/3).endpoints()
1988
+ (-0.333333333333334, -0.333333333333333)
1989
+
1990
+ .. SEEALSO:: :meth:`lower`, :meth:`upper`
1991
+ """
1992
+ # naive and slow
1993
+ return self._real_mpfi_(RealIntervalField(prec(self))).endpoints(rnd)
1994
+
1995
+ def union(self, other):
1996
+ r"""
1997
+ Return a ball containing the convex hull of ``self`` and ``other``.
1998
+
1999
+ EXAMPLES::
2000
+
2001
+ sage: RBF(0).union(1).endpoints()
2002
+ (-9.31322574615479e-10, 1.00000000093133)
2003
+ """
2004
+ cdef RealBall my_other = self._parent.coerce(other)
2005
+ cdef RealBall res = self._new()
2006
+ if _do_sig(prec(self)): sig_on()
2007
+ arb_union(res.value, self.value, my_other.value, prec(self))
2008
+ if _do_sig(prec(self)): sig_off()
2009
+ return res
2010
+
2011
+ def real(self):
2012
+ r"""
2013
+ Return the real part of this ball.
2014
+
2015
+ EXAMPLES::
2016
+
2017
+ sage: RBF(1/3).real()
2018
+ [0.3333333333333333 +/- 7.04e-17]
2019
+ """
2020
+ return self
2021
+
2022
+ def imag(self):
2023
+ r"""
2024
+ Return the imaginary part of this ball.
2025
+
2026
+ EXAMPLES::
2027
+
2028
+ sage: RBF(1/3).imag()
2029
+ 0
2030
+ """
2031
+ return self._parent.zero()
2032
+
2033
+ # Precision and accuracy
2034
+
2035
+ def nbits(self):
2036
+ r"""
2037
+ Return the minimum precision sufficient to represent this ball exactly.
2038
+
2039
+ In other words, return the number of bits needed to represent the
2040
+ absolute value of the mantissa of the midpoint of this ball. The result
2041
+ is 0 if the midpoint is a special value.
2042
+
2043
+ EXAMPLES::
2044
+
2045
+ sage: RBF(1/3).nbits()
2046
+ 53
2047
+ sage: RBF(1023, .1).nbits()
2048
+ 10
2049
+ sage: RBF(1024, .1).nbits()
2050
+ 1
2051
+ sage: RBF(0).nbits()
2052
+ 0
2053
+ sage: RBF(infinity).nbits()
2054
+ 0
2055
+ """
2056
+ return arb_bits(self.value)
2057
+
2058
+ def round(self):
2059
+ """
2060
+ Return a copy of this ball with center rounded to the precision of the
2061
+ parent.
2062
+
2063
+ EXAMPLES:
2064
+
2065
+ It is possible to create balls whose midpoint is more precise than
2066
+ their parent's nominal precision (see :mod:`~sage.rings.real_arb` for
2067
+ more information)::
2068
+
2069
+ sage: b = RBF(pi.n(100)) # needs sage.symbolic
2070
+ sage: b.mid() # needs sage.symbolic
2071
+ 3.141592653589793238462643383
2072
+
2073
+ The ``round()`` method rounds such a ball to its parent's precision::
2074
+
2075
+ sage: b.round().mid() # needs sage.symbolic
2076
+ 3.14159265358979
2077
+
2078
+ .. SEEALSO:: :meth:`trim`
2079
+ """
2080
+ cdef RealBall res = self._new()
2081
+ if _do_sig(prec(self)): sig_on()
2082
+ arb_set_round(res.value, self.value, prec(self))
2083
+ if _do_sig(prec(self)): sig_off()
2084
+ return res
2085
+
2086
+ def accuracy(self):
2087
+ """
2088
+ Return the effective relative accuracy of this ball measured in bits.
2089
+
2090
+ The accuracy is defined as the difference between the position of the
2091
+ top bit in the midpoint and the top bit in the radius, minus one.
2092
+ The result is clamped between plus/minus
2093
+ :meth:`~RealBallField.maximal_accuracy`.
2094
+
2095
+ EXAMPLES::
2096
+
2097
+ sage: RBF(pi).accuracy() # needs sage.symbolic
2098
+ 52
2099
+ sage: RBF(1).accuracy() == RBF.maximal_accuracy()
2100
+ True
2101
+ sage: RBF(NaN).accuracy() == -RBF.maximal_accuracy() # needs sage.symbolic
2102
+ True
2103
+
2104
+ .. SEEALSO:: :meth:`~RealBallField.maximal_accuracy`
2105
+ """
2106
+ return arb_rel_accuracy_bits(self.value)
2107
+
2108
+ def trim(self):
2109
+ """
2110
+ Return a trimmed copy of this ball.
2111
+
2112
+ Round ``self`` to a number of bits equal to the :meth:`accuracy` of
2113
+ ``self`` (as indicated by its radius), plus a few guard bits. The
2114
+ resulting ball is guaranteed to contain ``self``, but is more economical
2115
+ if ``self`` has less than full accuracy.
2116
+
2117
+ EXAMPLES::
2118
+
2119
+ sage: b = RBF(0.11111111111111, rad=.001)
2120
+ sage: b.mid()
2121
+ 0.111111111111110
2122
+ sage: b.trim().mid()
2123
+ 0.111111104488373
2124
+
2125
+ .. SEEALSO:: :meth:`round`
2126
+ """
2127
+ cdef RealBall res = self._new()
2128
+ if _do_sig(prec(self)): sig_on()
2129
+ arb_trim(res.value, self.value)
2130
+ if _do_sig(prec(self)): sig_off()
2131
+ return res
2132
+
2133
+ def add_error(self, ampl):
2134
+ """
2135
+ Increase the radius of this ball by (an upper bound on) ``ampl``.
2136
+
2137
+ If ``ampl`` is negative, the radius is unchanged.
2138
+
2139
+ INPUT:
2140
+
2141
+ - ``ampl`` -- a real ball (or an object that can be coerced to a real
2142
+ ball)
2143
+
2144
+ OUTPUT: a new real ball
2145
+
2146
+ EXAMPLES::
2147
+
2148
+ sage: err = RBF(10^-16)
2149
+ sage: RBF(1).add_error(err)
2150
+ [1.000000000000000 +/- ...e-16]
2151
+
2152
+ TESTS::
2153
+
2154
+ sage: RBF(1).add_error(-1)
2155
+ 1.000000000000000
2156
+ sage: RBF(0).add_error(RBF(1, rad=2.)).endpoints()
2157
+ (-3.00000000745059, 3.00000000745059)
2158
+ """
2159
+ cdef RealBall res = self._new()
2160
+ cdef RealBall my_ampl = self._parent(ampl)
2161
+ if my_ampl < 0:
2162
+ my_ampl = self._parent.zero()
2163
+ arb_set(res.value, self.value)
2164
+ arb_add_error(res.value, my_ampl.value)
2165
+ return res
2166
+
2167
+ # Comparisons and predicates
2168
+
2169
+ def is_zero(self):
2170
+ """
2171
+ Return ``True`` iff the midpoint and radius of this ball are both zero.
2172
+
2173
+ EXAMPLES::
2174
+
2175
+ sage: RBF = RealBallField()
2176
+ sage: RBF(0).is_zero()
2177
+ True
2178
+ sage: RBF(RIF(-0.5, 0.5)).is_zero()
2179
+ False
2180
+
2181
+ .. SEEALSO:: :meth:`is_nonzero`
2182
+ """
2183
+ return arb_is_zero(self.value)
2184
+
2185
+ def is_nonzero(self):
2186
+ """
2187
+ Return ``True`` iff zero is not contained in the interval represented
2188
+ by this ball.
2189
+
2190
+ .. NOTE::
2191
+
2192
+ This method is not the negation of :meth:`is_zero`: it only
2193
+ returns ``True`` if zero is known not to be contained in the ball.
2194
+
2195
+ Use ``bool(b)`` (or, equivalently, ``not b.is_zero()``) to check if
2196
+ a ball ``b`` **may** represent a nonzero number (for instance, to
2197
+ determine the “degree” of a polynomial with ball coefficients).
2198
+
2199
+ EXAMPLES::
2200
+
2201
+ sage: RBF = RealBallField()
2202
+ sage: RBF(pi).is_nonzero() # needs sage.symbolic
2203
+ True
2204
+ sage: RBF(RIF(-0.5, 0.5)).is_nonzero()
2205
+ False
2206
+
2207
+ .. SEEALSO:: :meth:`is_zero`
2208
+ """
2209
+ return arb_is_nonzero(self.value)
2210
+
2211
+ def __bool__(self):
2212
+ """
2213
+ Return ``True`` iff this ball is not the zero ball, i.e. if it its
2214
+ midpoint and radius are not both zero.
2215
+
2216
+ This is the preferred way, for instance, to determine the “degree” of a
2217
+ polynomial with ball coefficients.
2218
+
2219
+ .. WARNING::
2220
+
2221
+ A “nonzero” ball in the sense of this method may represent the
2222
+ value zero. Use :meth:`is_nonzero` to check that a real number
2223
+ represented by a ``RealBall`` object is known to be nonzero.
2224
+
2225
+ EXAMPLES::
2226
+
2227
+ sage: bool(RBF(0)) # indirect doctest
2228
+ False
2229
+ sage: bool(RBF(1/3))
2230
+ True
2231
+ sage: bool(RBF(RIF(-0.5, 0.5)))
2232
+ True
2233
+ """
2234
+ return not arb_is_zero(self.value)
2235
+
2236
+ def is_exact(self):
2237
+ """
2238
+ Return ``True`` iff the radius of this ball is zero.
2239
+
2240
+ EXAMPLES::
2241
+
2242
+ sage: RBF = RealBallField()
2243
+ sage: RBF(1).is_exact()
2244
+ True
2245
+ sage: RBF(RIF(0.1, 0.2)).is_exact()
2246
+ False
2247
+ """
2248
+ return arb_is_exact(self.value)
2249
+
2250
+ cpdef _richcmp_(left, right, int op):
2251
+ """
2252
+ Compare ``left`` and ``right``.
2253
+
2254
+ For more information, see :mod:`sage.rings.real_arb`.
2255
+
2256
+ EXAMPLES::
2257
+
2258
+ sage: RBF = RealBallField()
2259
+ sage: a = RBF(1)
2260
+ sage: b = RBF(1)
2261
+ sage: a is b
2262
+ False
2263
+ sage: a == b
2264
+ True
2265
+ sage: a = RBF(1/3)
2266
+ sage: a.is_exact()
2267
+ False
2268
+ sage: b = RBF(1/3)
2269
+ sage: b.is_exact()
2270
+ False
2271
+ sage: a == b
2272
+ False
2273
+
2274
+ TESTS:
2275
+
2276
+ Balls whose intersection consists of one point::
2277
+
2278
+ sage: a = RBF(RIF(1, 2))
2279
+ sage: b = RBF(RIF(2, 4))
2280
+ sage: a < b
2281
+ False
2282
+ sage: a > b
2283
+ False
2284
+ sage: a <= b
2285
+ False
2286
+ sage: a >= b
2287
+ False
2288
+ sage: a == b
2289
+ False
2290
+ sage: a != b
2291
+ False
2292
+
2293
+ Balls with non-trivial intersection::
2294
+
2295
+ sage: a = RBF(RIF(1, 4))
2296
+ sage: a = RBF(RIF(2, 5))
2297
+ sage: a < b
2298
+ False
2299
+ sage: a <= b
2300
+ False
2301
+ sage: a > b
2302
+ False
2303
+ sage: a >= b
2304
+ False
2305
+ sage: a == b
2306
+ False
2307
+ sage: a != b
2308
+ False
2309
+
2310
+ One ball contained in another::
2311
+
2312
+ sage: a = RBF(RIF(1, 4))
2313
+ sage: b = RBF(RIF(2, 3))
2314
+ sage: a < b
2315
+ False
2316
+ sage: a <= b
2317
+ False
2318
+ sage: a > b
2319
+ False
2320
+ sage: a >= b
2321
+ False
2322
+ sage: a == b
2323
+ False
2324
+ sage: a != b
2325
+ False
2326
+
2327
+ Disjoint balls::
2328
+
2329
+ sage: a = RBF(1/3)
2330
+ sage: b = RBF(1/2)
2331
+ sage: a < b
2332
+ True
2333
+ sage: a <= b
2334
+ True
2335
+ sage: a > b
2336
+ False
2337
+ sage: a >= b
2338
+ False
2339
+ sage: a == b
2340
+ False
2341
+ sage: a != b
2342
+ True
2343
+
2344
+ Exact elements::
2345
+
2346
+ sage: a = RBF(2)
2347
+ sage: b = RBF(2)
2348
+ sage: a.is_exact()
2349
+ True
2350
+ sage: b.is_exact()
2351
+ True
2352
+ sage: a < b
2353
+ False
2354
+ sage: a <= b
2355
+ True
2356
+ sage: a > b
2357
+ False
2358
+ sage: a >= b
2359
+ True
2360
+ sage: a == b
2361
+ True
2362
+ sage: a != b
2363
+ False
2364
+
2365
+ Special values::
2366
+
2367
+ sage: inf = RBF(+infinity)
2368
+ sage: other_inf = RBF(+infinity, 42.r)
2369
+ sage: neg_inf = RBF(-infinity)
2370
+ sage: extended_line = RBF(0).add_error(infinity)
2371
+ sage: exact_nan = inf - inf
2372
+ sage: exact_nan.mid(), exact_nan.rad()
2373
+ (NaN, 0.00000000)
2374
+ sage: other_exact_nan = inf - inf
2375
+
2376
+ ::
2377
+
2378
+ sage: exact_nan == exact_nan, exact_nan <= exact_nan, exact_nan >= exact_nan
2379
+ (False, False, False)
2380
+ sage: exact_nan != exact_nan, exact_nan < exact_nan, exact_nan > exact_nan
2381
+ (False, False, False)
2382
+ sage: from operator import eq, ne, le, lt, ge, gt
2383
+ sage: ops = [eq, ne, le, lt, ge, gt]
2384
+ sage: any(op(exact_nan, other_exact_nan) for op in ops)
2385
+ False
2386
+ sage: any(op(exact_nan, b) for op in ops for b in [RBF(1), extended_line, inf, neg_inf])
2387
+ False
2388
+
2389
+ ::
2390
+
2391
+ sage: neg_inf < a < inf and inf > a > neg_inf
2392
+ True
2393
+ sage: neg_inf <= b <= inf and inf >= b >= neg_inf
2394
+ True
2395
+ sage: neg_inf <= extended_line <= inf and inf >= extended_line >= neg_inf
2396
+ True
2397
+ sage: neg_inf < extended_line or extended_line < inf
2398
+ False
2399
+ sage: inf > extended_line or extended_line > neg_inf
2400
+ False
2401
+
2402
+ ::
2403
+
2404
+ sage: all(b <= b == b >= b and not (b < b or b != b or b > b)
2405
+ ....: for b in [inf, neg_inf, other_inf])
2406
+ True
2407
+ sage: any(b1 == b2 for b1 in [inf, neg_inf, a, extended_line]
2408
+ ....: for b2 in [inf, neg_inf, a, extended_line]
2409
+ ....: if not b1 is b2)
2410
+ False
2411
+ sage: all(b1 != b2 and not b1 == b2
2412
+ ....: for b1 in [inf, neg_inf, a]
2413
+ ....: for b2 in [inf, neg_inf, a]
2414
+ ....: if not b1 is b2)
2415
+ True
2416
+ sage: neg_inf <= -other_inf == neg_inf == -other_inf < other_inf == inf <= other_inf
2417
+ True
2418
+ sage: any(inf < b or b > inf
2419
+ ....: for b in [inf, other_inf, a, extended_line])
2420
+ False
2421
+ sage: any(inf <= b or b >= inf for b in [a, extended_line])
2422
+ False
2423
+ """
2424
+ cdef RealBall lt, rt
2425
+
2426
+ lt = left
2427
+ rt = right
2428
+
2429
+ if op == Py_EQ:
2430
+ return arb_eq(lt.value, rt.value)
2431
+ if op == Py_NE:
2432
+ return arb_ne(lt.value, rt.value)
2433
+ if op == Py_GT:
2434
+ return arb_gt(lt.value, rt.value)
2435
+ if op == Py_LT:
2436
+ return arb_lt(lt.value, rt.value)
2437
+ if op == Py_GE:
2438
+ return arb_ge(lt.value, rt.value)
2439
+ if op == Py_LE:
2440
+ return arb_le(lt.value, rt.value)
2441
+
2442
+ def min(self, *others):
2443
+ """
2444
+ Return a ball containing the minimum of this ball and the
2445
+ remaining arguments.
2446
+
2447
+ EXAMPLES::
2448
+
2449
+ sage: RBF(1, rad=.5).min(0)
2450
+ 0
2451
+
2452
+ sage: RBF(0, rad=2.).min(RBF(0, rad=1.)).endpoints()
2453
+ (-2.00000000651926, 1.00000000465662)
2454
+
2455
+ sage: RBF(infinity).min(3, 1/3)
2456
+ [0.3333333333333333 +/- ...e-17]
2457
+
2458
+ sage: RBF('nan').min(0)
2459
+ nan
2460
+
2461
+ .. SEEALSO:: :meth:`max`
2462
+
2463
+ TESTS::
2464
+
2465
+ sage: RBF(0).min()
2466
+ 0
2467
+ sage: RBF(infinity).min().rad()
2468
+ 0.00000000
2469
+ """
2470
+ cdef RealBall res = self._new()
2471
+ cdef long p = prec(self)
2472
+ arb_set(res.value, self.value)
2473
+ for b in others:
2474
+ if not isinstance(b, RealBall):
2475
+ b = self._parent.coerce(b)
2476
+ arb_min(res.value, res.value, (<RealBall> b).value, p)
2477
+ return res
2478
+
2479
+ def max(self, *others):
2480
+ """
2481
+ Return a ball containing the maximum of this ball and the
2482
+ remaining arguments.
2483
+
2484
+ EXAMPLES::
2485
+
2486
+ sage: RBF(-1, rad=.5).max(0)
2487
+ 0
2488
+
2489
+ sage: RBF(0, rad=2.).max(RBF(0, rad=1.)).endpoints()
2490
+ (-1.00000000465662, 2.00000000651926)
2491
+
2492
+ sage: RBF(-infinity).max(-3, 1/3)
2493
+ [0.3333333333333333 +/- ...e-17]
2494
+
2495
+ sage: RBF('nan').max(0)
2496
+ nan
2497
+
2498
+ .. SEEALSO:: :meth:`min`
2499
+
2500
+ TESTS::
2501
+
2502
+ sage: RBF(0).max()
2503
+ 0
2504
+ """
2505
+ cdef RealBall res = self._new()
2506
+ cdef long p = prec(self)
2507
+ arb_set(res.value, self.value)
2508
+ for b in others:
2509
+ if not isinstance(b, RealBall):
2510
+ b = self._parent.coerce(b)
2511
+ arb_max(res.value, res.value, (<RealBall> b).value, p)
2512
+ return res
2513
+
2514
+ def is_finite(self):
2515
+ """
2516
+ Return ``True`` iff the midpoint and radius of this ball are both
2517
+ finite floating-point numbers, i.e. not infinities or NaN.
2518
+
2519
+ EXAMPLES::
2520
+
2521
+ sage: (RBF(2)^(2^1000)).is_finite()
2522
+ True
2523
+ sage: RBF(oo).is_finite()
2524
+ False
2525
+ """
2526
+ return arb_is_finite(self.value)
2527
+
2528
+ def identical(self, RealBall other):
2529
+ """
2530
+ Return ``True`` iff ``self`` and ``other`` are equal as balls, i.e.
2531
+ have both the same midpoint and radius.
2532
+
2533
+ Note that this is not the same thing as testing whether both ``self``
2534
+ and ``other`` certainly represent the same real number, unless either
2535
+ ``self`` or ``other`` is exact (and neither contains NaN). To test
2536
+ whether both operands might represent the same mathematical quantity,
2537
+ use :meth:`overlaps` or :meth:`contains`, depending on the
2538
+ circumstance.
2539
+
2540
+ EXAMPLES::
2541
+
2542
+ sage: RBF(1).identical(RBF(3)-RBF(2))
2543
+ True
2544
+ sage: RBF(1, rad=0.25r).identical(RBF(1, rad=0.25r))
2545
+ True
2546
+ sage: RBF(1).identical(RBF(1, rad=0.25r))
2547
+ False
2548
+ """
2549
+ return arb_equal(self.value, other.value)
2550
+
2551
+ def overlaps(self, RealBall other):
2552
+ """
2553
+ Return ``True`` iff ``self`` and ``other`` have some point in common.
2554
+
2555
+ If either ``self`` or ``other`` contains NaN, this method always
2556
+ returns nonzero (as a NaN could be anything, it could in particular
2557
+ contain any number that is included in the other operand).
2558
+
2559
+ EXAMPLES::
2560
+
2561
+ sage: RBF(pi).overlaps(RBF(pi) + 2**(-100)) # needs sage.symbolic
2562
+ True
2563
+ sage: RBF(pi).overlaps(RBF(3)) # needs sage.symbolic
2564
+ False
2565
+ """
2566
+ return arb_overlaps(self.value, other.value)
2567
+
2568
+ def contains_exact(self, other):
2569
+ """
2570
+ Return ``True`` *iff* the given number (or ball) ``other`` is contained
2571
+ in the interval represented by ``self``.
2572
+
2573
+ If ``self`` contains NaN, this function always returns ``True`` (as
2574
+ it could represent anything, and in particular could represent all the
2575
+ points included in ``other``). If ``other`` contains NaN and ``self``
2576
+ does not, it always returns ``False``.
2577
+
2578
+ Use ``other in self`` for a test that works for a wider range of inputs
2579
+ but may return false negatives.
2580
+
2581
+ EXAMPLES::
2582
+
2583
+ sage: b = RBF(1)
2584
+ sage: b.contains_exact(1)
2585
+ True
2586
+ sage: b.contains_exact(QQ(1))
2587
+ True
2588
+ sage: b.contains_exact(1.)
2589
+ True
2590
+ sage: b.contains_exact(b)
2591
+ True
2592
+
2593
+ ::
2594
+
2595
+ sage: RBF(1/3).contains_exact(1/3)
2596
+ True
2597
+ sage: RBF(sqrt(2)).contains_exact(sqrt(2)) # needs sage.symbolic
2598
+ Traceback (most recent call last):
2599
+ ...
2600
+ TypeError: unsupported type: <class 'sage.symbolic.expression.Expression'>
2601
+
2602
+ TESTS::
2603
+
2604
+ sage: b.contains_exact(1r)
2605
+ True
2606
+ """
2607
+ cdef fmpz_t tmpz
2608
+ cdef fmpq_t tmpq
2609
+ if _do_sig(prec(self)): sig_on()
2610
+ try:
2611
+ if isinstance(other, RealBall):
2612
+ res = arb_contains(self.value, (<RealBall> other).value)
2613
+ elif is_small_python_int(other):
2614
+ res = arb_contains_si(self.value, PyLong_AsLong(other))
2615
+ elif isinstance(other, Integer):
2616
+ fmpz_init(tmpz)
2617
+ fmpz_set_mpz(tmpz, (<Integer> other).value)
2618
+ res = arb_contains_fmpz(self.value, tmpz)
2619
+ fmpz_clear(tmpz)
2620
+ elif isinstance(other, Rational):
2621
+ fmpq_init(tmpq)
2622
+ fmpq_set_mpq(tmpq, (<Rational> other).value)
2623
+ res = arb_contains_fmpq(self.value, tmpq)
2624
+ fmpq_clear(tmpq)
2625
+ elif isinstance(other, RealNumber):
2626
+ res = arb_contains_mpfr(self.value, (<RealNumber> other).value)
2627
+ else:
2628
+ raise TypeError("unsupported type: " + str(type(other)))
2629
+ finally:
2630
+ if _do_sig(prec(self)): sig_off()
2631
+ return res
2632
+
2633
+ def __contains__(self, other):
2634
+ """
2635
+ Return ``True`` if ``other`` can be verified to be contained in ``self``.
2636
+
2637
+ The test is done using interval arithmetic with a precision determined
2638
+ by the parent of ``self`` and may return false negatives.
2639
+
2640
+ EXAMPLES::
2641
+
2642
+ sage: sqrt(2) in RBF(sqrt(2)) # needs sage.symbolic
2643
+ True
2644
+
2645
+ A false negative::
2646
+
2647
+ sage: sqrt(2) in RBF(RealBallField(100)(sqrt(2))) # needs sage.symbolic
2648
+ False
2649
+
2650
+ .. SEEALSO:: :meth:`contains_exact`
2651
+ """
2652
+ return self.contains_exact(self._parent(other))
2653
+
2654
+ def contains_zero(self):
2655
+ """
2656
+ Return ``True`` iff this ball contains zero.
2657
+
2658
+ EXAMPLES::
2659
+
2660
+ sage: RBF(0).contains_zero()
2661
+ True
2662
+ sage: RBF(RIF(-1, 1)).contains_zero()
2663
+ True
2664
+ sage: RBF(1/3).contains_zero()
2665
+ False
2666
+ """
2667
+ return arb_contains_zero(self.value)
2668
+
2669
+ def contains_integer(self):
2670
+ """
2671
+ Return ``True`` iff this ball contains any integer.
2672
+
2673
+ EXAMPLES::
2674
+
2675
+ sage: RBF(3.1, 0.1).contains_integer()
2676
+ True
2677
+ sage: RBF(3.1, 0.05).contains_integer()
2678
+ False
2679
+ """
2680
+ return arb_contains_int(self.value)
2681
+
2682
+ def is_negative_infinity(self):
2683
+ """
2684
+ Return ``True`` if this ball is the point -∞.
2685
+
2686
+ EXAMPLES::
2687
+
2688
+ sage: RBF(-infinity).is_negative_infinity()
2689
+ True
2690
+ """
2691
+ return (arf_is_neg_inf(arb_midref(self.value))
2692
+ and mag_is_finite(arb_radref(self.value)))
2693
+
2694
+ def is_positive_infinity(self):
2695
+ """
2696
+ Return ``True`` if this ball is the point +∞.
2697
+
2698
+ EXAMPLES::
2699
+
2700
+ sage: RBF(infinity).is_positive_infinity()
2701
+ True
2702
+ """
2703
+ return (arf_is_pos_inf(arb_midref(self.value))
2704
+ and mag_is_finite(arb_radref(self.value)))
2705
+
2706
+ def is_infinity(self):
2707
+ """
2708
+ Return ``True`` if this ball contains or may represent a point at
2709
+ infinity.
2710
+
2711
+ This is the exact negation of :meth:`is_finite`, used in comparisons
2712
+ with Sage symbolic infinities.
2713
+
2714
+ .. WARNING::
2715
+
2716
+ Contrary to the usual convention, a return value of ``True`` does
2717
+ not imply that all points of the ball satisfy the predicate.
2718
+ This is due to the way comparisons with symbolic infinities work in
2719
+ sage.
2720
+
2721
+ EXAMPLES::
2722
+
2723
+ sage: RBF(infinity).is_infinity()
2724
+ True
2725
+ sage: RBF(-infinity).is_infinity()
2726
+ True
2727
+ sage: RBF(NaN).is_infinity() # needs sage.symbolic
2728
+ True
2729
+ sage: (~RBF(0)).is_infinity()
2730
+ True
2731
+ sage: RBF(42, rad=1.r).is_infinity()
2732
+ False
2733
+ """
2734
+ return not self.is_finite()
2735
+
2736
+ def is_NaN(self):
2737
+ """
2738
+ Return ``True`` if this ball is not-a-number.
2739
+
2740
+ EXAMPLES::
2741
+
2742
+ sage: RBF(NaN).is_NaN() # needs sage.symbolic
2743
+ True
2744
+ sage: RBF(-5).gamma().is_NaN()
2745
+ True
2746
+ sage: RBF(infinity).is_NaN()
2747
+ False
2748
+ sage: RBF(42, rad=1.r).is_NaN()
2749
+ False
2750
+ """
2751
+ return arf_is_nan(arb_midref(self.value))
2752
+
2753
+ # Arithmetic
2754
+
2755
+ def __neg__(self):
2756
+ """
2757
+ Return the opposite of this ball.
2758
+
2759
+ EXAMPLES::
2760
+
2761
+ sage: -RBF(1/3)
2762
+ [-0.3333333333333333 +/- ...e-17]
2763
+ """
2764
+ cdef RealBall res = self._new()
2765
+ arb_neg(res.value, self.value)
2766
+ return res
2767
+
2768
+ def __invert__(self):
2769
+ """
2770
+ Return the inverse of this ball.
2771
+
2772
+ The result is guaranteed to contain the inverse of any point of the
2773
+ input ball.
2774
+
2775
+ EXAMPLES::
2776
+
2777
+ sage: ~RBF(5)
2778
+ [0.2000000000000000 +/- ...e-17]
2779
+ sage: ~RBF(0)
2780
+ nan
2781
+ sage: RBF(RIF(-0.1,0.1))
2782
+ [+/- 0.101]
2783
+ """
2784
+ cdef RealBall res = self._new()
2785
+ if _do_sig(prec(self)): sig_on()
2786
+ arb_inv(res.value, self.value, prec(self))
2787
+ if _do_sig(prec(self)): sig_off()
2788
+ return res
2789
+
2790
+ cpdef _add_(self, other):
2791
+ """
2792
+ Return the sum of two balls, rounded to the ambient field's precision.
2793
+
2794
+ The resulting ball is guaranteed to contain the sums of any two points
2795
+ of the respective input balls.
2796
+
2797
+ EXAMPLES::
2798
+
2799
+ sage: RBF(1) + RBF(1/3)
2800
+ [1.333333333333333 +/- ...e-16]
2801
+ """
2802
+ cdef RealBall res = self._new()
2803
+ if _do_sig(prec(self)): sig_on()
2804
+ arb_add(res.value, self.value, (<RealBall> other).value, prec(self))
2805
+ if _do_sig(prec(self)): sig_off()
2806
+ return res
2807
+
2808
+ cpdef _sub_(self, other):
2809
+ """
2810
+ Return the difference of two balls, rounded to the ambient field's
2811
+ precision.
2812
+
2813
+ The resulting ball is guaranteed to contain the differences of any two
2814
+ points of the respective input balls.
2815
+
2816
+ EXAMPLES::
2817
+
2818
+ sage: RBF(1) - RBF(1/3)
2819
+ [0.666666666666667 +/- ...e-16]
2820
+ """
2821
+ cdef RealBall res = self._new()
2822
+ if _do_sig(prec(self)): sig_on()
2823
+ arb_sub(res.value, self.value, (<RealBall> other).value, prec(self))
2824
+ if _do_sig(prec(self)): sig_off()
2825
+ return res
2826
+
2827
+ cpdef _mul_(self, other):
2828
+ """
2829
+ Return the product of two balls, rounded to the ambient field's
2830
+ precision.
2831
+
2832
+ The resulting ball is guaranteed to contain the products of any two
2833
+ points of the respective input balls.
2834
+
2835
+ EXAMPLES::
2836
+
2837
+ sage: RBF(-2) * RBF(1/3)
2838
+ [-0.666666666666667 +/- ...e-16]
2839
+ """
2840
+ cdef RealBall res = self._new()
2841
+ if _do_sig(prec(self)): sig_on()
2842
+ arb_mul(res.value, self.value, (<RealBall> other).value, prec(self))
2843
+ if _do_sig(prec(self)): sig_off()
2844
+ return res
2845
+
2846
+ cpdef _div_(self, other):
2847
+ """
2848
+ Return the quotient of two balls, rounded to the ambient field's
2849
+ precision.
2850
+
2851
+ The resulting ball is guaranteed to contain the quotients of any two
2852
+ points of the respective input balls.
2853
+
2854
+ EXAMPLES::
2855
+
2856
+ sage: RBF(pi)/RBF(e) # needs sage.symbolic
2857
+ [1.155727349790922 +/- ...e-16]
2858
+ sage: RBF(2)/RBF(0)
2859
+ nan
2860
+ """
2861
+ cdef RealBall res = self._new()
2862
+ if _do_sig(prec(self)): sig_on()
2863
+ arb_div(res.value, self.value, (<RealBall> other).value, prec(self))
2864
+ if _do_sig(prec(self)): sig_off()
2865
+ return res
2866
+
2867
+ def __pow__(base, expo, _):
2868
+ """
2869
+ EXAMPLES::
2870
+
2871
+ sage: # needs sage.symbolic
2872
+ sage: RBF(e)^17
2873
+ [24154952.7535753 +/- ...e-8]
2874
+ sage: RBF(e)^(-1)
2875
+ [0.367879441171442 +/- ...e-16]
2876
+ sage: RBF(e)^(1/2)
2877
+ [1.648721270700128 +/- ...e-16]
2878
+ sage: RBF(e)^RBF(pi)
2879
+ [23.1406926327793 +/- ...e-14]
2880
+
2881
+ ::
2882
+
2883
+ sage: RBF(-1)^(1/3)
2884
+ nan
2885
+ sage: RBF(0)^(-1)
2886
+ nan
2887
+ sage: RBF(-e)**RBF(pi) # needs sage.symbolic
2888
+ nan
2889
+
2890
+ TESTS::
2891
+
2892
+ sage: RBF(e)**(2r) # needs sage.symbolic
2893
+ [7.38905609893065 +/- ...e-15]
2894
+ sage: RBF(e)**(-1r) # needs sage.symbolic
2895
+ [0.367879441171442 +/- ...e-16]
2896
+ """
2897
+ cdef fmpz_t tmpz
2898
+ if not isinstance(base, RealBall):
2899
+ return sage.structure.element.bin_op(base, expo, operator.pow)
2900
+ cdef RealBall self = base
2901
+ cdef RealBall res = self._new()
2902
+ if is_small_python_int(expo) and expo > 0:
2903
+ if _do_sig(prec(self)): sig_on()
2904
+ arb_pow_ui(res.value, self.value, PyLong_AsLong(expo), prec(self))
2905
+ if _do_sig(prec(self)): sig_off()
2906
+ elif isinstance(expo, Integer):
2907
+ if _do_sig(prec(self)): sig_on()
2908
+ fmpz_init(tmpz)
2909
+ fmpz_set_mpz(tmpz, (<Integer> expo).value)
2910
+ arb_pow_fmpz(res.value, self.value, tmpz, prec(self))
2911
+ fmpz_clear(tmpz)
2912
+ if _do_sig(prec(self)): sig_off()
2913
+ elif isinstance(expo, RealBall):
2914
+ if _do_sig(prec(self)): sig_on()
2915
+ arb_pow(res.value, self.value, (<RealBall> expo).value, prec(self))
2916
+ if _do_sig(prec(self)): sig_off()
2917
+ else:
2918
+ return sage.structure.element.bin_op(base, expo, operator.pow)
2919
+ return res
2920
+
2921
+ def sqrt(self):
2922
+ """
2923
+ Return the square root of this ball.
2924
+
2925
+ EXAMPLES::
2926
+
2927
+ sage: RBF(2).sqrt()
2928
+ [1.414213562373095 +/- ...e-16]
2929
+ sage: RBF(-1/3).sqrt()
2930
+ nan
2931
+ """
2932
+ cdef RealBall res = self._new()
2933
+ if _do_sig(prec(self)): sig_on()
2934
+ arb_sqrt(res.value, self.value, prec(self))
2935
+ if _do_sig(prec(self)): sig_off()
2936
+ return res
2937
+
2938
+ def sqrtpos(self):
2939
+ """
2940
+ Return the square root of this ball, assuming that it represents a
2941
+ nonnegative number.
2942
+
2943
+ Any negative numbers in the input interval are discarded.
2944
+
2945
+ EXAMPLES::
2946
+
2947
+ sage: RBF(2).sqrtpos()
2948
+ [1.414213562373095 +/- ...e-16]
2949
+ sage: RBF(-1/3).sqrtpos()
2950
+ 0
2951
+ sage: RBF(0, rad=2.r).sqrtpos()
2952
+ [+/- 1.42]
2953
+ """
2954
+ cdef RealBall res = self._new()
2955
+ if _do_sig(prec(self)): sig_on()
2956
+ arb_sqrtpos(res.value, self.value, prec(self))
2957
+ if _do_sig(prec(self)): sig_off()
2958
+ return res
2959
+
2960
+ def rsqrt(self):
2961
+ """
2962
+ Return the reciprocal square root of ``self``.
2963
+
2964
+ At high precision, this is faster than computing a square root.
2965
+
2966
+ EXAMPLES::
2967
+
2968
+ sage: RBF(2).rsqrt()
2969
+ [0.707106781186547 +/- ...e-16]
2970
+ sage: RBF(0).rsqrt()
2971
+ nan
2972
+ """
2973
+ cdef RealBall res = self._new()
2974
+ if _do_sig(prec(self)): sig_on()
2975
+ arb_rsqrt(res.value, self.value, prec(self))
2976
+ if _do_sig(prec(self)): sig_off()
2977
+ return res
2978
+
2979
+ def sqrt1pm1(self):
2980
+ r"""
2981
+ Return `\sqrt{1+\mathrm{self}}-1`, computed accurately when ``self`` is
2982
+ close to zero.
2983
+
2984
+ EXAMPLES::
2985
+
2986
+ sage: eps = RBF(10^(-20))
2987
+ sage: (1 + eps).sqrt() - 1
2988
+ [+/- ...e-16]
2989
+ sage: eps.sqrt1pm1()
2990
+ [5.00000000000000e-21 +/- ...e-36]
2991
+ """
2992
+ cdef RealBall res = self._new()
2993
+ if _do_sig(prec(self)): sig_on()
2994
+ arb_sqrt1pm1(res.value, self.value, prec(self))
2995
+ if _do_sig(prec(self)): sig_off()
2996
+ return res
2997
+
2998
+ # Floor, ceil, etc.
2999
+
3000
+ def floor(self):
3001
+ """
3002
+ Return the floor of this ball.
3003
+
3004
+ EXAMPLES::
3005
+
3006
+ sage: RBF(1000+1/3, rad=1.r).floor()
3007
+ [1.00e+3 +/- 1.01]
3008
+ """
3009
+ cdef RealBall res = self._new()
3010
+ if _do_sig(prec(self)): sig_on()
3011
+ arb_floor(res.value, self.value, prec(self))
3012
+ if _do_sig(prec(self)): sig_off()
3013
+ return res
3014
+
3015
+ def ceil(self):
3016
+ """
3017
+ Return the ceil of this ball.
3018
+
3019
+ EXAMPLES::
3020
+
3021
+ sage: RBF(1000+1/3, rad=1.r).ceil()
3022
+ [1.00e+3 +/- 2.01]
3023
+ """
3024
+ cdef RealBall res = self._new()
3025
+ if _do_sig(prec(self)): sig_on()
3026
+ arb_ceil(res.value, self.value, prec(self))
3027
+ if _do_sig(prec(self)): sig_off()
3028
+ return res
3029
+
3030
+ def __lshift__(val, shift):
3031
+ r"""
3032
+ If ``val`` is a ``RealBall`` and ``shift`` is an integer, return the
3033
+ ball obtained by shifting the center and radius of ``val`` to the left
3034
+ by ``shift`` bits.
3035
+
3036
+ INPUT:
3037
+
3038
+ - ``shift`` -- integer; may be negative
3039
+
3040
+ EXAMPLES::
3041
+
3042
+ sage: RBF(1/3) << 2 # indirect doctest
3043
+ [1.333333333333333 +/- ...e-16]
3044
+ sage: RBF(1) << -1
3045
+ 0.5000000000000000
3046
+
3047
+ TESTS::
3048
+
3049
+ sage: RBF(1) << (2^100)
3050
+ [2.285367694229514e+381600854690147056244358827360 +/- ...e+381600854690147056244358827344]
3051
+ sage: RBF(1) << (-2^100)
3052
+ [4.375663498372584e-381600854690147056244358827361 +/- ...e-381600854690147056244358827378]
3053
+
3054
+ sage: "a" << RBF(1/3)
3055
+ Traceback (most recent call last):
3056
+ ...
3057
+ TypeError: unsupported operand type(s) for <<: 'str' and 'RealBall'
3058
+ sage: RBF(1) << RBF(1/3)
3059
+ Traceback (most recent call last):
3060
+ ...
3061
+ TypeError: shift should be an integer
3062
+ """
3063
+ cdef fmpz_t tmpz
3064
+ # the RealBall might be shift, not val
3065
+ if not isinstance(val, RealBall):
3066
+ raise TypeError("unsupported operand type(s) for <<: '{}' and '{}'"
3067
+ .format(type(val).__name__, type(shift).__name__))
3068
+ cdef RealBall self = val
3069
+ cdef RealBall res = self._new()
3070
+ if is_small_python_int(shift):
3071
+ arb_mul_2exp_si(res.value, self.value, PyLong_AsLong(shift))
3072
+ elif isinstance(shift, Integer):
3073
+ sig_on()
3074
+ fmpz_init(tmpz)
3075
+ fmpz_set_mpz(tmpz, (<Integer> shift).value)
3076
+ arb_mul_2exp_fmpz(res.value, self.value, tmpz)
3077
+ fmpz_clear(tmpz)
3078
+ sig_off()
3079
+ else:
3080
+ raise TypeError("shift should be an integer")
3081
+ return res
3082
+
3083
+ def __rshift__(val, shift):
3084
+ r"""
3085
+ If ``val`` is a ``RealBall`` and ``shift`` is an integer, return the
3086
+ ball obtained by shifting the center and radius of ``val`` to the right
3087
+ by ``shift`` bits.
3088
+
3089
+ INPUT:
3090
+
3091
+ - ``shift`` -- integer; may be negative
3092
+
3093
+ EXAMPLES::
3094
+
3095
+ sage: RBF(4) >> 2
3096
+ 1.000000000000000
3097
+ sage: RBF(1/3) >> -2
3098
+ [1.333333333333333 +/- ...e-16]
3099
+
3100
+ TESTS::
3101
+
3102
+ sage: "a" >> RBF(1/3)
3103
+ Traceback (most recent call last):
3104
+ ...
3105
+ TypeError: unsupported operand type(s) for >>: 'str' and 'RealBall'
3106
+ """
3107
+ # the RealBall might be shift, not val
3108
+ if isinstance(val, RealBall):
3109
+ return val << (-shift)
3110
+ else:
3111
+ raise TypeError("unsupported operand type(s) for >>: '{}' and '{}'"
3112
+ .format(type(val).__name__, type(shift).__name__))
3113
+
3114
+ def conjugate(self):
3115
+ r"""
3116
+ Return the conjugate of this ball.
3117
+
3118
+ EXAMPLES::
3119
+
3120
+ sage: RBF(1).conjugate()
3121
+ 1.000000000000000
3122
+ """
3123
+ return self
3124
+
3125
+ # Elementary functions
3126
+
3127
+ def log(self, base=None):
3128
+ """
3129
+ Return the logarithm of this ball.
3130
+
3131
+ INPUT:
3132
+
3133
+ - ``base`` -- (optional) positive real ball or number; if ``None``,
3134
+ return the natural logarithm ``ln(self)``, otherwise, return the
3135
+ general logarithm ``ln(self)/ln(base)``
3136
+
3137
+ EXAMPLES::
3138
+
3139
+ sage: RBF(3).log()
3140
+ [1.098612288668110 +/- ...e-16]
3141
+ sage: RBF(3).log(2)
3142
+ [1.58496250072116 +/- ...e-15]
3143
+ sage: log(RBF(5), 2)
3144
+ [2.32192809488736 +/- ...e-15]
3145
+
3146
+ sage: RBF(-1/3).log()
3147
+ nan
3148
+ sage: RBF(3).log(-1)
3149
+ nan
3150
+ sage: RBF(2).log(0)
3151
+ nan
3152
+ """
3153
+ cdef RealBall cst
3154
+ cdef RealBall res = self._new()
3155
+ if _do_sig(prec(self)): sig_on()
3156
+ arb_log(res.value, self.value, prec(self))
3157
+ if _do_sig(prec(self)): sig_off()
3158
+ if base is not None:
3159
+ cst = self._parent.coerce(base).log()
3160
+ if _do_sig(prec(self)): sig_on()
3161
+ arb_div(res.value, res.value, cst.value, prec(self))
3162
+ if _do_sig(prec(self)): sig_off()
3163
+ return res
3164
+
3165
+ def log1p(self):
3166
+ """
3167
+ Return ``log(1 + self)``, computed accurately when ``self`` is close to
3168
+ zero.
3169
+
3170
+ EXAMPLES::
3171
+
3172
+ sage: eps = RBF(1e-30)
3173
+ sage: (1 + eps).log()
3174
+ [+/- ...e-16]
3175
+ sage: eps.log1p()
3176
+ [1.00000000000000e-30 +/- ...e-46]
3177
+ """
3178
+ cdef RealBall res = self._new()
3179
+ if _do_sig(prec(self)): sig_on()
3180
+ arb_log1p(res.value, self.value, prec(self))
3181
+ if _do_sig(prec(self)): sig_off()
3182
+ return res
3183
+
3184
+ def exp(self):
3185
+ """
3186
+ Return the exponential of this ball.
3187
+
3188
+ EXAMPLES::
3189
+
3190
+ sage: RBF(1).exp()
3191
+ [2.718281828459045 +/- ...e-16]
3192
+ """
3193
+ cdef RealBall res = self._new()
3194
+ if _do_sig(prec(self)): sig_on()
3195
+ arb_exp(res.value, self.value, prec(self))
3196
+ if _do_sig(prec(self)): sig_off()
3197
+ return res
3198
+
3199
+ def expm1(self):
3200
+ """
3201
+ Return ``exp(self) - 1``, computed accurately when ``self`` is close to
3202
+ zero.
3203
+
3204
+ EXAMPLES::
3205
+
3206
+ sage: eps = RBF(1e-30)
3207
+ sage: exp(eps) - 1
3208
+ [+/- ...e-30]
3209
+ sage: eps.expm1()
3210
+ [1.000000000000000e-30 +/- ...e-47]
3211
+ """
3212
+ cdef RealBall res = self._new()
3213
+ if _do_sig(prec(self)): sig_on()
3214
+ arb_expm1(res.value, self.value, prec(self))
3215
+ if _do_sig(prec(self)): sig_off()
3216
+ return res
3217
+
3218
+ def sin(self):
3219
+ """
3220
+ Return the sine of this ball.
3221
+
3222
+ EXAMPLES::
3223
+
3224
+ sage: RBF(pi).sin() # needs sage.symbolic
3225
+ [+/- ...e-16]
3226
+
3227
+ .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBallField.sinpi`
3228
+ """
3229
+ cdef RealBall res = self._new()
3230
+ if _do_sig(prec(self)): sig_on()
3231
+ arb_sin(res.value, self.value, prec(self))
3232
+ if _do_sig(prec(self)): sig_off()
3233
+ return res
3234
+
3235
+ def cos(self):
3236
+ """
3237
+ Return the cosine of this ball.
3238
+
3239
+ EXAMPLES::
3240
+
3241
+ sage: RBF(pi).cos() # needs sage.symbolic
3242
+ [-1.00000000000000 +/- ...e-16]
3243
+
3244
+ .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBallField.cospi`
3245
+ """
3246
+ cdef RealBall res = self._new()
3247
+ if _do_sig(prec(self)): sig_on()
3248
+ arb_cos(res.value, self.value, prec(self))
3249
+ if _do_sig(prec(self)): sig_off()
3250
+ return res
3251
+
3252
+ def tan(self):
3253
+ """
3254
+ Return the tangent of this ball.
3255
+
3256
+ EXAMPLES::
3257
+
3258
+ sage: RBF(1).tan()
3259
+ [1.557407724654902 +/- ...e-16]
3260
+ sage: RBF(pi/2).tan() # needs sage.symbolic
3261
+ nan
3262
+ """
3263
+ cdef RealBall res = self._new()
3264
+ if _do_sig(prec(self)): sig_on()
3265
+ arb_tan(res.value, self.value, prec(self))
3266
+ if _do_sig(prec(self)): sig_off()
3267
+ return res
3268
+
3269
+ def cot(self):
3270
+ """
3271
+ Return the cotangent of this ball.
3272
+
3273
+ EXAMPLES::
3274
+
3275
+ sage: RBF(1).cot()
3276
+ [0.642092615934331 +/- ...e-16]
3277
+ sage: RBF(pi).cot() # needs sage.symbolic
3278
+ nan
3279
+ """
3280
+ cdef RealBall res = self._new()
3281
+ if _do_sig(prec(self)): sig_on()
3282
+ arb_cot(res.value, self.value, prec(self))
3283
+ if _do_sig(prec(self)): sig_off()
3284
+ return res
3285
+
3286
+ def sec(self):
3287
+ """
3288
+ Return the secant of this ball.
3289
+
3290
+ EXAMPLES::
3291
+
3292
+ sage: RBF(1).sec()
3293
+ [1.850815717680925 +/- ...e-16]
3294
+ """
3295
+ cdef RealBall res = self._new()
3296
+ if _do_sig(prec(self)): sig_on()
3297
+ arb_sec(res.value, self.value, prec(self))
3298
+ if _do_sig(prec(self)): sig_off()
3299
+ return res
3300
+
3301
+ def csc(self):
3302
+ """
3303
+ Return the cosecant of this ball.
3304
+
3305
+ EXAMPLES::
3306
+
3307
+ sage: RBF(1).csc()
3308
+ [1.188395105778121 +/- ...e-16]
3309
+ """
3310
+ cdef RealBall res = self._new()
3311
+ if _do_sig(prec(self)): sig_on()
3312
+ arb_csc(res.value, self.value, prec(self))
3313
+ if _do_sig(prec(self)): sig_off()
3314
+ return res
3315
+
3316
+ def arcsin(self):
3317
+ """
3318
+ Return the arcsine of this ball.
3319
+
3320
+ EXAMPLES::
3321
+
3322
+ sage: RBF(1).arcsin()
3323
+ [1.570796326794897 +/- ...e-16]
3324
+ sage: RBF(1, rad=.125r).arcsin()
3325
+ nan
3326
+ """
3327
+ cdef RealBall res = self._new()
3328
+ if _do_sig(prec(self)): sig_on()
3329
+ arb_asin(res.value, self.value, prec(self))
3330
+ if _do_sig(prec(self)): sig_off()
3331
+ return res
3332
+
3333
+ def arccos(self):
3334
+ """
3335
+ Return the arccosine of this ball.
3336
+
3337
+ EXAMPLES::
3338
+
3339
+ sage: RBF(1).arccos()
3340
+ 0
3341
+ sage: RBF(1, rad=.125r).arccos()
3342
+ nan
3343
+ """
3344
+ cdef RealBall res = self._new()
3345
+ if _do_sig(prec(self)): sig_on()
3346
+ arb_acos(res.value, self.value, prec(self))
3347
+ if _do_sig(prec(self)): sig_off()
3348
+ return res
3349
+
3350
+ def arctan(self):
3351
+ """
3352
+ Return the arctangent of this ball.
3353
+
3354
+ EXAMPLES::
3355
+
3356
+ sage: RBF(1).arctan()
3357
+ [0.7853981633974483 +/- ...e-17]
3358
+ """
3359
+ cdef RealBall res = self._new()
3360
+ if _do_sig(prec(self)): sig_on()
3361
+ arb_atan(res.value, self.value, prec(self))
3362
+ if _do_sig(prec(self)): sig_off()
3363
+ return res
3364
+
3365
+ def sinh(self):
3366
+ """
3367
+ Return the hyperbolic sine of this ball.
3368
+
3369
+ EXAMPLES::
3370
+
3371
+ sage: RBF(1).sinh()
3372
+ [1.175201193643801 +/- ...e-16]
3373
+ """
3374
+ cdef RealBall res = self._new()
3375
+ if _do_sig(prec(self)): sig_on()
3376
+ arb_sinh(res.value, self.value, prec(self))
3377
+ if _do_sig(prec(self)): sig_off()
3378
+ return res
3379
+
3380
+ def cosh(self):
3381
+ """
3382
+ Return the hyperbolic cosine of this ball.
3383
+
3384
+ EXAMPLES::
3385
+
3386
+ sage: RBF(1).cosh()
3387
+ [1.543080634815244 +/- ...e-16]
3388
+ """
3389
+ cdef RealBall res = self._new()
3390
+ if _do_sig(prec(self)): sig_on()
3391
+ arb_cosh(res.value, self.value, prec(self))
3392
+ if _do_sig(prec(self)): sig_off()
3393
+ return res
3394
+
3395
+ def tanh(self):
3396
+ """
3397
+ Return the hyperbolic tangent of this ball.
3398
+
3399
+ EXAMPLES::
3400
+
3401
+ sage: RBF(1).tanh()
3402
+ [0.761594155955765 +/- ...e-16]
3403
+ """
3404
+ cdef RealBall res = self._new()
3405
+ if _do_sig(prec(self)): sig_on()
3406
+ arb_tanh(res.value, self.value, prec(self))
3407
+ if _do_sig(prec(self)): sig_off()
3408
+ return res
3409
+
3410
+ def coth(self):
3411
+ """
3412
+ Return the hyperbolic cotangent of this ball.
3413
+
3414
+ EXAMPLES::
3415
+
3416
+ sage: RBF(1).coth()
3417
+ [1.313035285499331 +/- ...e-16]
3418
+ sage: RBF(0).coth()
3419
+ nan
3420
+ """
3421
+ cdef RealBall res = self._new()
3422
+ if _do_sig(prec(self)): sig_on()
3423
+ arb_coth(res.value, self.value, prec(self))
3424
+ if _do_sig(prec(self)): sig_off()
3425
+ return res
3426
+
3427
+ def sech(self):
3428
+ """
3429
+ Return the hyperbolic secant of this ball.
3430
+
3431
+ EXAMPLES::
3432
+
3433
+ sage: RBF(1).sech()
3434
+ [0.648054273663885 +/- ...e-16]
3435
+ """
3436
+ cdef RealBall res = self._new()
3437
+ if _do_sig(prec(self)): sig_on()
3438
+ arb_sech(res.value, self.value, prec(self))
3439
+ if _do_sig(prec(self)): sig_off()
3440
+ return res
3441
+
3442
+ def csch(self):
3443
+ """
3444
+ Return the hyperbolic cosecant of this ball.
3445
+
3446
+ EXAMPLES::
3447
+
3448
+ sage: RBF(1).csch()
3449
+ [0.850918128239321 +/- ...e-16]
3450
+ """
3451
+ cdef RealBall res = self._new()
3452
+ if _do_sig(prec(self)): sig_on()
3453
+ arb_csch(res.value, self.value, prec(self))
3454
+ if _do_sig(prec(self)): sig_off()
3455
+ return res
3456
+
3457
+ def arcsinh(self):
3458
+ """
3459
+ Return the inverse hyperbolic sine of this ball.
3460
+
3461
+ EXAMPLES::
3462
+
3463
+ sage: RBF(1).arcsinh()
3464
+ [0.881373587019543 +/- ...e-16]
3465
+ sage: RBF(0).arcsinh()
3466
+ 0
3467
+ """
3468
+ cdef RealBall res = self._new()
3469
+ if _do_sig(prec(self)): sig_on()
3470
+ arb_asinh(res.value, self.value, prec(self))
3471
+ if _do_sig(prec(self)): sig_off()
3472
+ return res
3473
+
3474
+ def arccosh(self):
3475
+ """
3476
+ Return the inverse hyperbolic cosine of this ball.
3477
+
3478
+ EXAMPLES::
3479
+
3480
+ sage: RBF(2).arccosh()
3481
+ [1.316957896924817 +/- ...e-16]
3482
+ sage: RBF(1).arccosh()
3483
+ 0
3484
+ sage: RBF(0).arccosh()
3485
+ nan
3486
+ """
3487
+ cdef RealBall res = self._new()
3488
+ if _do_sig(prec(self)): sig_on()
3489
+ arb_acosh(res.value, self.value, prec(self))
3490
+ if _do_sig(prec(self)): sig_off()
3491
+ return res
3492
+
3493
+ def arctanh(self):
3494
+ """
3495
+ Return the inverse hyperbolic tangent of this ball.
3496
+
3497
+ EXAMPLES::
3498
+
3499
+ sage: RBF(0).arctanh()
3500
+ 0
3501
+ sage: RBF(1/2).arctanh()
3502
+ [0.549306144334055 +/- ...e-16]
3503
+ sage: RBF(1).arctanh()
3504
+ nan
3505
+ """
3506
+ cdef RealBall res = self._new()
3507
+ if _do_sig(prec(self)): sig_on()
3508
+ arb_atanh(res.value, self.value, prec(self))
3509
+ if _do_sig(prec(self)): sig_off()
3510
+ return res
3511
+
3512
+ # Special functions
3513
+
3514
+ def erf(self):
3515
+ """
3516
+ Error function.
3517
+
3518
+ EXAMPLES::
3519
+
3520
+ sage: RBF(1/2).erf() # abs tol 1e-16
3521
+ [0.520499877813047 +/- 6.10e-16]
3522
+ """
3523
+ cdef RealBall res = self._new()
3524
+ if _do_sig(prec(self)): sig_on()
3525
+ arb_hypgeom_erf(res.value, self.value, prec(self))
3526
+ if _do_sig(prec(self)): sig_off()
3527
+ return res
3528
+
3529
+ def erfi(self):
3530
+ """
3531
+ Imaginary error function.
3532
+
3533
+ EXAMPLES::
3534
+
3535
+ sage: RBF(1/2).erfi()
3536
+ [0.614952094696511 +/- 2.22e-16]
3537
+ """
3538
+ cdef RealBall res = self._new()
3539
+ if _do_sig(prec(self)): sig_on()
3540
+ arb_hypgeom_erfi(res.value, self.value, prec(self))
3541
+ if _do_sig(prec(self)): sig_off()
3542
+ return res
3543
+
3544
+ def Ei(self):
3545
+ """
3546
+ Exponential integral.
3547
+
3548
+ EXAMPLES::
3549
+
3550
+ sage: RBF(1).Ei() # abs tol 5e-15
3551
+ [1.89511781635594 +/- 4.94e-15]
3552
+
3553
+ TESTS::
3554
+
3555
+ sage: RBF(Ei(1)) # abs tol 5e-15 # needs sage.symbolic
3556
+ [1.89511781635594 +/- 4.94e-15]
3557
+ """
3558
+ cdef RealBall res = self._new()
3559
+ if _do_sig(prec(self)): sig_on()
3560
+ arb_hypgeom_ei(res.value, self.value, prec(self))
3561
+ if _do_sig(prec(self)): sig_off()
3562
+ return res
3563
+
3564
+ def Si(self):
3565
+ """
3566
+ Sine integral.
3567
+
3568
+ EXAMPLES::
3569
+
3570
+ sage: RBF(1).Si() # abs tol 1e-15
3571
+ [0.946083070367183 +/- 9.22e-16]
3572
+
3573
+ TESTS::
3574
+
3575
+ sage: RBF(Si(1)) # abs tol 1e-15 # needs sage.symbolic
3576
+ [0.946083070367183 +/- 9.22e-16]
3577
+ """
3578
+ cdef RealBall res = self._new()
3579
+ if _do_sig(prec(self)): sig_on()
3580
+ arb_hypgeom_si(res.value, self.value, prec(self))
3581
+ if _do_sig(prec(self)): sig_off()
3582
+ return res
3583
+
3584
+ sin_integral = Si
3585
+
3586
+ def Ci(self):
3587
+ """
3588
+ Cosine integral.
3589
+
3590
+ EXAMPLES::
3591
+
3592
+ sage: RBF(1).Ci() # abs tol 5e-16
3593
+ [0.337403922900968 +/- 3.25e-16]
3594
+
3595
+ TESTS::
3596
+
3597
+ sage: RBF(Ci(1)) # abs tol 5e-16 # needs sage.symbolic
3598
+ [0.337403922900968 +/- 3.25e-16]
3599
+ """
3600
+ cdef RealBall res = self._new()
3601
+ if _do_sig(prec(self)): sig_on()
3602
+ arb_hypgeom_ci(res.value, self.value, prec(self))
3603
+ if _do_sig(prec(self)): sig_off()
3604
+ return res
3605
+
3606
+ cos_integral = Ci
3607
+
3608
+ def Shi(self):
3609
+ """
3610
+ Hyperbolic sine integral.
3611
+
3612
+ EXAMPLES::
3613
+
3614
+ sage: RBF(1).Shi() # abs tol 5e-15
3615
+ [1.05725087537573 +/- 2.77e-15]
3616
+
3617
+ TESTS::
3618
+
3619
+ sage: RBF(Shi(1)) # abs tol 5e-15 # needs sage.symbolic
3620
+ [1.05725087537573 +/- 2.77e-15]
3621
+ """
3622
+ cdef RealBall res = self._new()
3623
+ if _do_sig(prec(self)): sig_on()
3624
+ arb_hypgeom_shi(res.value, self.value, prec(self))
3625
+ if _do_sig(prec(self)): sig_off()
3626
+ return res
3627
+
3628
+ sinh_integral = Shi
3629
+
3630
+ def Chi(self):
3631
+ """
3632
+ Hyperbolic cosine integral.
3633
+
3634
+ EXAMPLES::
3635
+
3636
+ sage: RBF(1).Chi() # abs tol 5e-16
3637
+ [0.837866940980208 +/- 4.72e-16]
3638
+
3639
+ TESTS::
3640
+
3641
+ sage: RBF(Chi(1)) # abs tol 5e-16 # needs sage.symbolic
3642
+ [0.837866940980208 +/- 4.72e-16]
3643
+ """
3644
+ cdef RealBall res = self._new()
3645
+ if _do_sig(prec(self)): sig_on()
3646
+ arb_hypgeom_chi(res.value, self.value, prec(self))
3647
+ if _do_sig(prec(self)): sig_off()
3648
+ return res
3649
+
3650
+ cosh_integral = Chi
3651
+
3652
+ def li(self):
3653
+ """
3654
+ Logarithmic integral.
3655
+
3656
+ EXAMPLES::
3657
+
3658
+ sage: RBF(3).li() # abs tol 5e-15
3659
+ [2.16358859466719 +/- 4.72e-15]
3660
+
3661
+ TESTS::
3662
+
3663
+ sage: RBF(li(0)) # needs sage.symbolic
3664
+ 0
3665
+ sage: RBF(Li(0)) # abs tol 5e-15 # needs sage.symbolic
3666
+ [-1.04516378011749 +/- 4.23e-15]
3667
+ """
3668
+ cdef RealBall res = self._new()
3669
+ if _do_sig(prec(self)): sig_on()
3670
+ arb_hypgeom_li(res.value, self.value, False, prec(self))
3671
+ if _do_sig(prec(self)): sig_off()
3672
+ return res
3673
+
3674
+ log_integral = li
3675
+
3676
+ def Li(self):
3677
+ """
3678
+ Offset logarithmic integral.
3679
+
3680
+ EXAMPLES::
3681
+
3682
+ sage: RBF(3).Li() # abs tol 5e-15
3683
+ [1.11842481454970 +/- 7.61e-15]
3684
+ """
3685
+ cdef RealBall res = self._new()
3686
+ if _do_sig(prec(self)): sig_on()
3687
+ arb_hypgeom_li(res.value, self.value, True, prec(self))
3688
+ if _do_sig(prec(self)): sig_off()
3689
+ return res
3690
+
3691
+ log_integral_offset = Li
3692
+
3693
+ def beta(self, a, z=1):
3694
+ """
3695
+ (Incomplete) beta function.
3696
+
3697
+ INPUT:
3698
+
3699
+ - ``a``, ``z`` -- (optional) real balls
3700
+
3701
+ OUTPUT:
3702
+
3703
+ The lower incomplete beta function `B(self, a, z)`.
3704
+
3705
+ With the default value of ``z``, the complete beta function `B(self, a)`.
3706
+
3707
+ EXAMPLES::
3708
+
3709
+ sage: RBF(sin(3)).beta(RBF(2/3).sqrt()) # abs tol 1e-13 # needs sage.symbolic
3710
+ [7.407661629415 +/- 1.07e-13]
3711
+ sage: RealBallField(100)(7/2).beta(1) # abs tol 1e-30
3712
+ [0.28571428571428571428571428571 +/- 5.23e-30]
3713
+ sage: RealBallField(100)(7/2).beta(1, 1/2)
3714
+ [0.025253813613805268728601584361 +/- 2.53e-31]
3715
+
3716
+ .. TODO::
3717
+
3718
+ At the moment RBF(beta(a,b)) does not work, one needs
3719
+ RBF(a).beta(b) for this to work. See :issue:`32851`
3720
+ and :issue:`24641`.
3721
+ """
3722
+ cdef RealBall a_ball, z_ball
3723
+ cdef RealBall res = self._new()
3724
+ if _do_sig(prec(self)): sig_on()
3725
+ a_ball = self._parent.coerce(a)
3726
+ z_ball = self._parent.coerce(z)
3727
+ arb_hypgeom_beta_lower(res.value, self.value, a_ball.value,
3728
+ z_ball.value, False, prec(self))
3729
+ if _do_sig(prec(self)): sig_off()
3730
+ return res
3731
+
3732
+ def gamma(self, a=None):
3733
+ r"""
3734
+ Image of this ball by the (upper incomplete) Euler Gamma function.
3735
+
3736
+ For `a` real, return the upper incomplete Gamma function
3737
+ `\Gamma(self,a)`.
3738
+
3739
+ For integer and rational arguments,
3740
+ :meth:`~sage.rings.real_arb.RealBallField.gamma` may be faster.
3741
+
3742
+ EXAMPLES::
3743
+
3744
+ sage: RBF(1/2).gamma()
3745
+ [1.772453850905516 +/- ...e-16]
3746
+ sage: RBF(gamma(3/2, RBF(2).sqrt())) # abs tol 2e-17
3747
+ [0.37118875695353 +/- 3.00e-15]
3748
+ sage: RBF(3/2).gamma_inc(RBF(2).sqrt()) # abs tol 2e-17
3749
+ [0.37118875695353 +/- 3.00e-15]
3750
+
3751
+ .. SEEALSO::
3752
+ :meth:`~sage.rings.real_arb.RealBallField.gamma`
3753
+
3754
+ TESTS::
3755
+
3756
+ sage: RealBallField(100).gamma(1/2)
3757
+ [1.77245385090551602729816748334 +/- 1.90e-30]
3758
+ """
3759
+ cdef RealBall a_ball
3760
+ cdef RealBall res = self._new()
3761
+ if a is None:
3762
+ if _do_sig(prec(self)): sig_on()
3763
+ arb_gamma(res.value, self.value, prec(self))
3764
+ if _do_sig(prec(self)): sig_off()
3765
+ else:
3766
+ if _do_sig(prec(self)): sig_on()
3767
+ a_ball = self._parent.coerce(a)
3768
+ arb_hypgeom_gamma_upper(res.value, self.value, a_ball.value, 0, prec(self))
3769
+ if _do_sig(prec(self)): sig_off()
3770
+ return res
3771
+
3772
+ gamma_inc = gamma
3773
+
3774
+ def gamma_inc_lower(self, a):
3775
+ r"""
3776
+ Image of this ball by the lower incomplete Euler Gamma function.
3777
+
3778
+ For `a` real, return the lower incomplete Gamma function
3779
+ of `\Gamma(self,a)`.
3780
+
3781
+ EXAMPLES::
3782
+
3783
+ sage: RBF(gamma_inc_lower(1/2, RBF(2).sqrt()))
3784
+ [1.608308637729248 +/- 8.14e-16]
3785
+ sage: RealBallField(100)(7/2).gamma_inc_lower(5)
3786
+ [2.6966551541863035516887949614 +/- 8.91e-29]
3787
+ """
3788
+ cdef RealBall a_ball
3789
+ cdef RealBall res = self._new()
3790
+ if _do_sig(prec(self)): sig_on()
3791
+ a_ball = RBF(a)
3792
+ arb_hypgeom_gamma_lower(res.value, self.value, a_ball.value, 0, prec(self))
3793
+ if _do_sig(prec(self)): sig_off()
3794
+ return res
3795
+
3796
+ def log_gamma(self):
3797
+ """
3798
+ Return the image of this ball by the logarithmic Gamma function.
3799
+
3800
+ The complex branch structure is assumed, so if ``self <= 0``, the result
3801
+ is an indeterminate interval.
3802
+
3803
+ EXAMPLES::
3804
+
3805
+ sage: RBF(1/2).log_gamma()
3806
+ [0.572364942924700 +/- ...e-16]
3807
+ """
3808
+ cdef RealBall res = self._new()
3809
+ if _do_sig(prec(self)): sig_on()
3810
+ arb_lgamma(res.value, self.value, prec(self))
3811
+ if _do_sig(prec(self)): sig_off()
3812
+ return res
3813
+
3814
+ def rgamma(self):
3815
+ """
3816
+ Return the image of this ball by the function 1/Γ, avoiding division by
3817
+ zero at the poles of the gamma function.
3818
+
3819
+ EXAMPLES::
3820
+
3821
+ sage: RBF(-1).rgamma()
3822
+ 0
3823
+ sage: RBF(3).rgamma()
3824
+ 0.5000000000000000
3825
+ """
3826
+ cdef RealBall res = self._new()
3827
+ if _do_sig(prec(self)): sig_on()
3828
+ arb_rgamma(res.value, self.value, prec(self))
3829
+ if _do_sig(prec(self)): sig_off()
3830
+ return res
3831
+
3832
+ def rising_factorial(self, n):
3833
+ r"""
3834
+ Return the ``n``-th rising factorial of this ball.
3835
+
3836
+ The `n`-th rising factorial of `x` is equal to `x (x+1) \cdots (x+n-1)`.
3837
+
3838
+ For real `n`, it is a quotient of gamma functions.
3839
+
3840
+ EXAMPLES::
3841
+
3842
+ sage: RBF(1).rising_factorial(5)
3843
+ 120.0000000000000
3844
+ sage: RBF(1/2).rising_factorial(1/3) # abs tol 1e-14
3845
+ [0.636849884317974 +/- 8.98e-16]
3846
+ """
3847
+ cdef RealBall result = self._new()
3848
+ cdef RealBall my_n = self._parent.coerce(n)
3849
+ if _do_sig(prec(self)): sig_on()
3850
+ arb_rising(result.value, self.value, my_n.value, prec(self))
3851
+ if _do_sig(prec(self)): sig_off()
3852
+ return result
3853
+
3854
+ cpdef RealBall psi(self):
3855
+ """
3856
+ Compute the digamma function with argument ``self``.
3857
+
3858
+ EXAMPLES::
3859
+
3860
+ sage: RBF(1).psi() # abs tol 1e-15
3861
+ [-0.5772156649015329 +/- 4.84e-17]
3862
+ """
3863
+
3864
+ cdef RealBall result = self._new()
3865
+ if _do_sig(prec(self)): sig_on()
3866
+ arb_digamma(result.value, self.value, prec(self))
3867
+ if _do_sig(prec(self)): sig_off()
3868
+ return result
3869
+
3870
+ def zeta(self, a=None):
3871
+ """
3872
+ Return the image of this ball by the Hurwitz zeta function.
3873
+
3874
+ For ``a = 1`` (or ``a = None``), this computes the Riemann zeta function.
3875
+
3876
+ Otherwise, it computes the Hurwitz zeta function.
3877
+
3878
+ Use :meth:`RealBallField.zeta` to compute the Riemann zeta function of
3879
+ a small integer without first converting it to a real ball.
3880
+
3881
+ EXAMPLES::
3882
+
3883
+ sage: RBF(-1).zeta()
3884
+ [-0.0833333333333333 +/- ...e-17]
3885
+ sage: RBF(-1).zeta(1)
3886
+ [-0.0833333333333333 +/- ...e-17]
3887
+ sage: RBF(-1).zeta(2)
3888
+ [-1.083333333333333 +/- ...e-16]
3889
+ """
3890
+ cdef RealBall a_ball
3891
+ cdef RealBall res = self._new()
3892
+ if a is None:
3893
+ if _do_sig(prec(self)): sig_on()
3894
+ arb_zeta(res.value, self.value, prec(self))
3895
+ if _do_sig(prec(self)): sig_off()
3896
+ else:
3897
+ a_ball = self._parent.coerce(a)
3898
+ if _do_sig(prec(self)): sig_on()
3899
+ arb_hurwitz_zeta(res.value, self.value, a_ball.value, prec(self))
3900
+ if _do_sig(prec(self)): sig_off()
3901
+ return res
3902
+
3903
+ def zetaderiv(self, k):
3904
+ r"""
3905
+ Return the image of this ball by the `k`-th derivative of the Riemann
3906
+ zeta function.
3907
+
3908
+ For a more flexible interface, see the low-level method
3909
+ ``_zeta_series`` of polynomials with complex ball coefficients.
3910
+
3911
+ EXAMPLES::
3912
+
3913
+ sage: RBF(1/2).zetaderiv(1)
3914
+ [-3.92264613920915...]
3915
+ sage: RBF(2).zetaderiv(3)
3916
+ [-6.0001458028430...]
3917
+ """
3918
+ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
3919
+ Pol = PolynomialRing(self._parent.complex_field(), 'x')
3920
+ ser = Pol([self, 1])._zeta_series(k + 1)
3921
+ return ser[k].real()*ZZ.coerce(k).factorial()
3922
+
3923
+ def lambert_w(self):
3924
+ r"""
3925
+ Return the image of this ball by the Lambert W function.
3926
+
3927
+ EXAMPLES::
3928
+
3929
+ sage: RBF(1).lambert_w()
3930
+ [0.5671432904097...]
3931
+ """
3932
+ cdef RealBall res = self._new()
3933
+ sig_on()
3934
+ arb_lambertw(res.value, self.value, 0, prec(self))
3935
+ sig_off()
3936
+ return res
3937
+
3938
+ def polylog(self, s):
3939
+ r"""
3940
+ Return the polylogarithm `\operatorname{Li}_s(\mathrm{self})`.
3941
+
3942
+ EXAMPLES::
3943
+
3944
+ sage: polylog(0, -1) # needs sage.symbolic
3945
+ -1/2
3946
+ sage: RBF(-1).polylog(0)
3947
+ [-0.50000000000000 +/- ...e-16]
3948
+ sage: polylog(1, 1/2) # needs sage.symbolic
3949
+ -log(1/2)
3950
+ sage: RBF(1/2).polylog(1)
3951
+ [0.69314718055995 +/- ...e-15]
3952
+ sage: RBF(1/3).polylog(1/2)
3953
+ [0.44210883528067 +/- 6.7...e-15]
3954
+ sage: RBF(1/3).polylog(RLF(pi)) # needs sage.symbolic
3955
+ [0.34728895057225 +/- ...e-15]
3956
+
3957
+ TESTS::
3958
+
3959
+ sage: RBF(1/3).polylog(2r)
3960
+ [0.366213229977063 +/- ...e-16]
3961
+ """
3962
+ cdef RealBall s_as_ball
3963
+ cdef Integer s_as_Integer
3964
+ cdef RealBall res = self._new()
3965
+ try:
3966
+ s_as_Integer = ZZ.coerce(s)
3967
+ if mpz_fits_slong_p(s_as_Integer.value):
3968
+ if _do_sig(prec(self)): sig_on()
3969
+ arb_polylog_si(res.value, mpz_get_si(s_as_Integer.value), self.value, prec(self))
3970
+ if _do_sig(prec(self)): sig_off()
3971
+ return res
3972
+ except TypeError:
3973
+ pass
3974
+ s_as_ball = self._parent.coerce(s)
3975
+ if _do_sig(prec(self)): sig_on()
3976
+ arb_polylog(res.value, s_as_ball.value, self.value, prec(self))
3977
+ if _do_sig(prec(self)): sig_off()
3978
+ return res
3979
+
3980
+ def chebyshev_T(self, n):
3981
+ """
3982
+ Evaluate the Chebyshev polynomial of the first kind ``T_n`` at this
3983
+ ball.
3984
+
3985
+ EXAMPLES::
3986
+
3987
+ sage: # needs sage.symbolic
3988
+ sage: RBF(pi).chebyshev_T(0)
3989
+ 1.000000000000000
3990
+ sage: RBF(pi).chebyshev_T(1)
3991
+ [3.141592653589793 +/- ...e-16]
3992
+ sage: RBF(pi).chebyshev_T(10**20)
3993
+ Traceback (most recent call last):
3994
+ ...
3995
+ ValueError: index too large
3996
+ sage: RBF(pi).chebyshev_T(-1)
3997
+ Traceback (most recent call last):
3998
+ ...
3999
+ ValueError: expected a nonnegative index
4000
+ """
4001
+ cdef RealBall res = self._new()
4002
+ cdef Integer n_as_Integer = ZZ.coerce(n)
4003
+ if mpz_fits_ulong_p(n_as_Integer.value):
4004
+ if _do_sig(prec(self)): sig_on()
4005
+ arb_chebyshev_t_ui(res.value, mpz_get_ui(n_as_Integer.value), self.value, prec(self))
4006
+ if _do_sig(prec(self)): sig_off()
4007
+ return res
4008
+ elif n_as_Integer < 0:
4009
+ raise ValueError("expected a nonnegative index")
4010
+ else:
4011
+ raise ValueError("index too large")
4012
+
4013
+ def chebyshev_U(self, n):
4014
+ """
4015
+ Evaluate the Chebyshev polynomial of the second kind ``U_n`` at this
4016
+ ball.
4017
+
4018
+ EXAMPLES::
4019
+
4020
+ sage: # needs sage.symbolic
4021
+ sage: RBF(pi).chebyshev_U(0)
4022
+ 1.000000000000000
4023
+ sage: RBF(pi).chebyshev_U(1)
4024
+ [6.283185307179586 +/- ...e-16]
4025
+ sage: RBF(pi).chebyshev_U(10**20)
4026
+ Traceback (most recent call last):
4027
+ ...
4028
+ ValueError: index too large
4029
+ sage: RBF(pi).chebyshev_U(-1)
4030
+ Traceback (most recent call last):
4031
+ ...
4032
+ ValueError: expected a nonnegative index
4033
+ """
4034
+ cdef RealBall res = self._new()
4035
+ cdef Integer n_as_Integer = ZZ.coerce(n)
4036
+ if mpz_fits_ulong_p(n_as_Integer.value):
4037
+ if _do_sig(prec(self)): sig_on()
4038
+ arb_chebyshev_u_ui(res.value, mpz_get_ui(n_as_Integer.value), self.value, prec(self))
4039
+ if _do_sig(prec(self)): sig_off()
4040
+ return res
4041
+ elif n_as_Integer < 0:
4042
+ raise ValueError("expected a nonnegative index")
4043
+ else:
4044
+ raise ValueError("index too large")
4045
+
4046
+ def agm(self, other):
4047
+ """
4048
+ Return the arithmetic-geometric mean of ``self`` and ``other``.
4049
+
4050
+ EXAMPLES::
4051
+
4052
+ sage: RBF(1).agm(1)
4053
+ 1.000000000000000
4054
+ sage: RBF(sqrt(2)).agm(1)^(-1) # needs sage.symbolic
4055
+ [0.8346268416740...]
4056
+ """
4057
+ cdef RealBall other_as_ball
4058
+ cdef RealBall res = self._new()
4059
+ other_as_ball = self._parent.coerce(other)
4060
+ if _do_sig(prec(self)): sig_on()
4061
+ arb_agm(res.value, self.value, other_as_ball.value, prec(self))
4062
+ if _do_sig(prec(self)): sig_off()
4063
+ return res
4064
+
4065
+ RBF = RealBallField()