passagemath-pari 10.6.32__cp314-cp314-musllinux_1_2_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of passagemath-pari might be problematic. Click here for more details.

Files changed (331) hide show
  1. PARIKernel/__init__.py +2 -0
  2. PARIKernel/__main__.py +5 -0
  3. PARIKernel/io.cpython-314-x86_64-linux-musl.so +0 -0
  4. PARIKernel/io.pxd +7 -0
  5. PARIKernel/io.pyx +84 -0
  6. PARIKernel/kernel.cpython-314-x86_64-linux-musl.so +0 -0
  7. PARIKernel/kernel.pyx +260 -0
  8. PARIKernel/paridecl.pxd +95 -0
  9. PARIKernel/svg.cpython-314-x86_64-linux-musl.so +0 -0
  10. PARIKernel/svg.pyx +52 -0
  11. cypari2/__init__.py +8 -0
  12. cypari2/auto_paridecl.pxd +1070 -0
  13. cypari2/closure.cpython-314-x86_64-linux-musl.so +0 -0
  14. cypari2/closure.pxd +5 -0
  15. cypari2/closure.pyx +246 -0
  16. cypari2/convert.cpython-314-x86_64-linux-musl.so +0 -0
  17. cypari2/convert.pxd +80 -0
  18. cypari2/convert.pyx +613 -0
  19. cypari2/custom_block.cpython-314-x86_64-linux-musl.so +0 -0
  20. cypari2/custom_block.pyx +30 -0
  21. cypari2/cypari.h +13 -0
  22. cypari2/gen.cpython-314-x86_64-linux-musl.so +0 -0
  23. cypari2/gen.pxd +69 -0
  24. cypari2/gen.pyx +4819 -0
  25. cypari2/handle_error.cpython-314-x86_64-linux-musl.so +0 -0
  26. cypari2/handle_error.pxd +7 -0
  27. cypari2/handle_error.pyx +232 -0
  28. cypari2/pari_instance.cpython-314-x86_64-linux-musl.so +0 -0
  29. cypari2/pari_instance.pxd +27 -0
  30. cypari2/pari_instance.pyx +1438 -0
  31. cypari2/paridecl.pxd +5353 -0
  32. cypari2/paripriv.pxd +34 -0
  33. cypari2/pycore_long.h +98 -0
  34. cypari2/pycore_long.pxd +9 -0
  35. cypari2/stack.cpython-314-x86_64-linux-musl.so +0 -0
  36. cypari2/stack.pxd +27 -0
  37. cypari2/stack.pyx +278 -0
  38. cypari2/string_utils.cpython-314-x86_64-linux-musl.so +0 -0
  39. cypari2/string_utils.pxd +29 -0
  40. cypari2/string_utils.pyx +65 -0
  41. cypari2/types.pxd +147 -0
  42. passagemath_pari-10.6.32.data/data/etc/jupyter/nbconfig/notebook.d/gp-mode.json +5 -0
  43. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/pari_jupyter/kernel.js +28 -0
  44. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/pari_jupyter/kernel.json +6 -0
  45. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/pari_jupyter/logo-64x64.png +0 -0
  46. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/kernel.json +13 -0
  47. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/logo-32x32.png +0 -0
  48. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/logo-64x64.png +0 -0
  49. passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/logo-svg.svg +75 -0
  50. passagemath_pari-10.6.32.data/data/share/jupyter/nbextensions/gp-mode/gp.js +284 -0
  51. passagemath_pari-10.6.32.data/data/share/jupyter/nbextensions/gp-mode/main.js +15 -0
  52. passagemath_pari-10.6.32.dist-info/METADATA +209 -0
  53. passagemath_pari-10.6.32.dist-info/RECORD +331 -0
  54. passagemath_pari-10.6.32.dist-info/WHEEL +5 -0
  55. passagemath_pari-10.6.32.dist-info/top_level.txt +4 -0
  56. passagemath_pari.libs/libcrypto-f04afe95.so.3 +0 -0
  57. passagemath_pari.libs/libflint-fd6f12fc.so.21.0.0 +0 -0
  58. passagemath_pari.libs/libgcc_s-0cd532bd.so.1 +0 -0
  59. passagemath_pari.libs/libgf2x-9e30c3e3.so.3.0.0 +0 -0
  60. passagemath_pari.libs/libgfortran-2c33b284.so.5.0.0 +0 -0
  61. passagemath_pari.libs/libgivaro-9a94c711.so.9.2.1 +0 -0
  62. passagemath_pari.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
  63. passagemath_pari.libs/libgmpxx-9e08595c.so.4.7.0 +0 -0
  64. passagemath_pari.libs/libgsl-42cda06f.so.28.0.0 +0 -0
  65. passagemath_pari.libs/libmpfr-aaecbfc0.so.6.2.1 +0 -0
  66. passagemath_pari.libs/libncursesw-9c9e32c3.so.6.5 +0 -0
  67. passagemath_pari.libs/libntl-26885ca2.so.44.0.1 +0 -0
  68. passagemath_pari.libs/libopenblasp-r0-905cb27d.3.29.so +0 -0
  69. passagemath_pari.libs/libpari-gmp-tls-f31f908f.so.2.17.2 +0 -0
  70. passagemath_pari.libs/libquadmath-bb76a5fc.so.0.0.0 +0 -0
  71. passagemath_pari.libs/libreadline-06542304.so.8.2 +0 -0
  72. passagemath_pari.libs/libstdc++-5d72f927.so.6.0.33 +0 -0
  73. passagemath_pari.libs/libuuid-f3770415.so.1.3.0 +0 -0
  74. passagemath_pari.libs/libxeus-735780ff.so.13.1.0 +0 -0
  75. passagemath_pari.libs/libxeus-zmq-c68577b4.so.6.0.1 +0 -0
  76. passagemath_pari.libs/libzmq-1ba9a3da.so.5.2.5 +0 -0
  77. sage/all__sagemath_pari.py +26 -0
  78. sage/databases/all__sagemath_pari.py +7 -0
  79. sage/databases/conway.py +274 -0
  80. sage/ext/all__sagemath_pari.py +1 -0
  81. sage/ext/memory.cpython-314-x86_64-linux-musl.so +0 -0
  82. sage/ext/memory.pyx +98 -0
  83. sage/ext_data/pari/buzzard/DimensionSk.g +286 -0
  84. sage/ext_data/pari/buzzard/Tpprog.g +179 -0
  85. sage/ext_data/pari/buzzard/genusn.g +129 -0
  86. sage/ext_data/pari/dokchitser/computel.gp +740 -0
  87. sage/ext_data/pari/dokchitser/computel.gp.template +740 -0
  88. sage/ext_data/pari/dokchitser/ex-bsw +43 -0
  89. sage/ext_data/pari/dokchitser/ex-chgen +48 -0
  90. sage/ext_data/pari/dokchitser/ex-chqua +37 -0
  91. sage/ext_data/pari/dokchitser/ex-delta +35 -0
  92. sage/ext_data/pari/dokchitser/ex-eisen +30 -0
  93. sage/ext_data/pari/dokchitser/ex-gen2 +38 -0
  94. sage/ext_data/pari/dokchitser/ex-gen3 +49 -0
  95. sage/ext_data/pari/dokchitser/ex-gen4 +54 -0
  96. sage/ext_data/pari/dokchitser/ex-nf +48 -0
  97. sage/ext_data/pari/dokchitser/ex-shin +50 -0
  98. sage/ext_data/pari/dokchitser/ex-tau2 +30 -0
  99. sage/ext_data/pari/dokchitser/ex-zeta +27 -0
  100. sage/ext_data/pari/dokchitser/ex-zeta2 +47 -0
  101. sage/ext_data/pari/dokchitser/testall +13 -0
  102. sage/ext_data/pari/simon/ell.gp +2129 -0
  103. sage/ext_data/pari/simon/ellQ.gp +2151 -0
  104. sage/ext_data/pari/simon/ellcommon.gp +126 -0
  105. sage/ext_data/pari/simon/qfsolve.gp +722 -0
  106. sage/ext_data/pari/simon/resultant3.gp +306 -0
  107. sage/groups/all__sagemath_pari.py +3 -0
  108. sage/groups/pari_group.py +175 -0
  109. sage/interfaces/all__sagemath_pari.py +1 -0
  110. sage/interfaces/genus2reduction.py +464 -0
  111. sage/interfaces/gp.py +1114 -0
  112. sage/libs/all__sagemath_pari.py +2 -0
  113. sage/libs/linkages/__init__.py +1 -0
  114. sage/libs/linkages/padics/API.pxi +617 -0
  115. sage/libs/linkages/padics/Polynomial_ram.pxi +388 -0
  116. sage/libs/linkages/padics/Polynomial_shared.pxi +554 -0
  117. sage/libs/linkages/padics/__init__.py +1 -0
  118. sage/libs/linkages/padics/fmpz_poly_unram.pxi +869 -0
  119. sage/libs/linkages/padics/mpz.pxi +691 -0
  120. sage/libs/linkages/padics/relaxed/API.pxi +518 -0
  121. sage/libs/linkages/padics/relaxed/__init__.py +1 -0
  122. sage/libs/linkages/padics/relaxed/flint.pxi +543 -0
  123. sage/libs/linkages/padics/unram_shared.pxi +247 -0
  124. sage/libs/pari/__init__.py +210 -0
  125. sage/libs/pari/all.py +5 -0
  126. sage/libs/pari/convert_flint.cpython-314-x86_64-linux-musl.so +0 -0
  127. sage/libs/pari/convert_flint.pxd +14 -0
  128. sage/libs/pari/convert_flint.pyx +159 -0
  129. sage/libs/pari/convert_gmp.cpython-314-x86_64-linux-musl.so +0 -0
  130. sage/libs/pari/convert_gmp.pxd +14 -0
  131. sage/libs/pari/convert_gmp.pyx +210 -0
  132. sage/libs/pari/convert_sage.cpython-314-x86_64-linux-musl.so +0 -0
  133. sage/libs/pari/convert_sage.pxd +16 -0
  134. sage/libs/pari/convert_sage.pyx +588 -0
  135. sage/libs/pari/convert_sage_complex_double.cpython-314-x86_64-linux-musl.so +0 -0
  136. sage/libs/pari/convert_sage_complex_double.pxd +14 -0
  137. sage/libs/pari/convert_sage_complex_double.pyx +132 -0
  138. sage/libs/pari/convert_sage_matrix.cpython-314-x86_64-linux-musl.so +0 -0
  139. sage/libs/pari/convert_sage_matrix.pyx +106 -0
  140. sage/libs/pari/convert_sage_real_double.cpython-314-x86_64-linux-musl.so +0 -0
  141. sage/libs/pari/convert_sage_real_double.pxd +5 -0
  142. sage/libs/pari/convert_sage_real_double.pyx +14 -0
  143. sage/libs/pari/convert_sage_real_mpfr.cpython-314-x86_64-linux-musl.so +0 -0
  144. sage/libs/pari/convert_sage_real_mpfr.pxd +7 -0
  145. sage/libs/pari/convert_sage_real_mpfr.pyx +108 -0
  146. sage/libs/pari/misc.cpython-314-x86_64-linux-musl.so +0 -0
  147. sage/libs/pari/misc.pxd +4 -0
  148. sage/libs/pari/misc.pyx +26 -0
  149. sage/libs/pari/tests.py +1848 -0
  150. sage/matrix/all__sagemath_pari.py +1 -0
  151. sage/matrix/matrix_integer_pari.cpython-314-x86_64-linux-musl.so +0 -0
  152. sage/matrix/matrix_integer_pari.pyx +187 -0
  153. sage/matrix/matrix_rational_pari.cpython-314-x86_64-linux-musl.so +0 -0
  154. sage/matrix/matrix_rational_pari.pyx +160 -0
  155. sage/quadratic_forms/all__sagemath_pari.py +10 -0
  156. sage/quadratic_forms/genera/all.py +9 -0
  157. sage/quadratic_forms/genera/genus.py +3506 -0
  158. sage/quadratic_forms/genera/normal_form.py +1519 -0
  159. sage/quadratic_forms/genera/spinor_genus.py +243 -0
  160. sage/quadratic_forms/qfsolve.py +255 -0
  161. sage/quadratic_forms/quadratic_form__automorphisms.py +427 -0
  162. sage/quadratic_forms/quadratic_form__genus.py +141 -0
  163. sage/quadratic_forms/quadratic_form__local_density_interfaces.py +140 -0
  164. sage/quadratic_forms/quadratic_form__local_normal_form.py +421 -0
  165. sage/quadratic_forms/quadratic_form__local_representation_conditions.py +889 -0
  166. sage/quadratic_forms/quadratic_form__mass.py +69 -0
  167. sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py +663 -0
  168. sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py +373 -0
  169. sage/quadratic_forms/quadratic_form__siegel_product.py +198 -0
  170. sage/quadratic_forms/special_values.py +323 -0
  171. sage/rings/all__sagemath_pari.py +15 -0
  172. sage/rings/factorint_pari.cpython-314-x86_64-linux-musl.so +0 -0
  173. sage/rings/factorint_pari.pyx +80 -0
  174. sage/rings/finite_rings/all__sagemath_pari.py +1 -0
  175. sage/rings/finite_rings/element_givaro.cpython-314-x86_64-linux-musl.so +0 -0
  176. sage/rings/finite_rings/element_givaro.pxd +91 -0
  177. sage/rings/finite_rings/element_givaro.pyx +1769 -0
  178. sage/rings/finite_rings/element_ntl_gf2e.cpython-314-x86_64-linux-musl.so +0 -0
  179. sage/rings/finite_rings/element_ntl_gf2e.pxd +22 -0
  180. sage/rings/finite_rings/element_ntl_gf2e.pyx +1333 -0
  181. sage/rings/finite_rings/element_pari_ffelt.cpython-314-x86_64-linux-musl.so +0 -0
  182. sage/rings/finite_rings/element_pari_ffelt.pxd +13 -0
  183. sage/rings/finite_rings/element_pari_ffelt.pyx +1441 -0
  184. sage/rings/finite_rings/finite_field_givaro.py +612 -0
  185. sage/rings/finite_rings/finite_field_pari_ffelt.py +238 -0
  186. sage/rings/finite_rings/hom_finite_field_givaro.cpython-314-x86_64-linux-musl.so +0 -0
  187. sage/rings/finite_rings/hom_finite_field_givaro.pxd +28 -0
  188. sage/rings/finite_rings/hom_finite_field_givaro.pyx +280 -0
  189. sage/rings/finite_rings/residue_field_givaro.cpython-314-x86_64-linux-musl.so +0 -0
  190. sage/rings/finite_rings/residue_field_givaro.pyx +133 -0
  191. sage/rings/finite_rings/residue_field_pari_ffelt.cpython-314-x86_64-linux-musl.so +0 -0
  192. sage/rings/finite_rings/residue_field_pari_ffelt.pyx +128 -0
  193. sage/rings/function_field/all__sagemath_pari.py +1 -0
  194. sage/rings/function_field/valuation.py +1450 -0
  195. sage/rings/function_field/valuation_ring.py +212 -0
  196. sage/rings/number_field/all__sagemath_pari.py +14 -0
  197. sage/rings/number_field/totallyreal.cpython-314-x86_64-linux-musl.so +0 -0
  198. sage/rings/number_field/totallyreal.pyx +509 -0
  199. sage/rings/number_field/totallyreal_data.cpython-314-x86_64-linux-musl.so +0 -0
  200. sage/rings/number_field/totallyreal_data.pxd +26 -0
  201. sage/rings/number_field/totallyreal_data.pyx +928 -0
  202. sage/rings/number_field/totallyreal_phc.py +144 -0
  203. sage/rings/number_field/totallyreal_rel.py +1018 -0
  204. sage/rings/padics/CA_template.pxi +1847 -0
  205. sage/rings/padics/CA_template_header.pxi +50 -0
  206. sage/rings/padics/CR_template.pxi +2563 -0
  207. sage/rings/padics/CR_template_header.pxi +57 -0
  208. sage/rings/padics/FM_template.pxi +1575 -0
  209. sage/rings/padics/FM_template_header.pxi +50 -0
  210. sage/rings/padics/FP_template.pxi +2176 -0
  211. sage/rings/padics/FP_template_header.pxi +57 -0
  212. sage/rings/padics/all.py +3 -0
  213. sage/rings/padics/all__sagemath_pari.py +11 -0
  214. sage/rings/padics/common_conversion.cpython-314-x86_64-linux-musl.so +0 -0
  215. sage/rings/padics/common_conversion.pxd +15 -0
  216. sage/rings/padics/common_conversion.pyx +508 -0
  217. sage/rings/padics/eisenstein_extension_generic.py +232 -0
  218. sage/rings/padics/factory.py +3623 -0
  219. sage/rings/padics/generic_nodes.py +1615 -0
  220. sage/rings/padics/lattice_precision.py +2889 -0
  221. sage/rings/padics/morphism.cpython-314-x86_64-linux-musl.so +0 -0
  222. sage/rings/padics/morphism.pxd +11 -0
  223. sage/rings/padics/morphism.pyx +366 -0
  224. sage/rings/padics/padic_base_generic.py +467 -0
  225. sage/rings/padics/padic_base_leaves.py +1235 -0
  226. sage/rings/padics/padic_capped_absolute_element.cpython-314-x86_64-linux-musl.so +0 -0
  227. sage/rings/padics/padic_capped_absolute_element.pxd +15 -0
  228. sage/rings/padics/padic_capped_absolute_element.pyx +520 -0
  229. sage/rings/padics/padic_capped_relative_element.cpython-314-x86_64-linux-musl.so +0 -0
  230. sage/rings/padics/padic_capped_relative_element.pxd +14 -0
  231. sage/rings/padics/padic_capped_relative_element.pyx +614 -0
  232. sage/rings/padics/padic_extension_generic.py +990 -0
  233. sage/rings/padics/padic_extension_leaves.py +738 -0
  234. sage/rings/padics/padic_fixed_mod_element.cpython-314-x86_64-linux-musl.so +0 -0
  235. sage/rings/padics/padic_fixed_mod_element.pxd +15 -0
  236. sage/rings/padics/padic_fixed_mod_element.pyx +584 -0
  237. sage/rings/padics/padic_floating_point_element.cpython-314-x86_64-linux-musl.so +0 -0
  238. sage/rings/padics/padic_floating_point_element.pxd +14 -0
  239. sage/rings/padics/padic_floating_point_element.pyx +447 -0
  240. sage/rings/padics/padic_generic_element.cpython-314-x86_64-linux-musl.so +0 -0
  241. sage/rings/padics/padic_generic_element.pxd +48 -0
  242. sage/rings/padics/padic_generic_element.pyx +4642 -0
  243. sage/rings/padics/padic_lattice_element.py +1342 -0
  244. sage/rings/padics/padic_printing.cpython-314-x86_64-linux-musl.so +0 -0
  245. sage/rings/padics/padic_printing.pxd +38 -0
  246. sage/rings/padics/padic_printing.pyx +1505 -0
  247. sage/rings/padics/padic_relaxed_element.cpython-314-x86_64-linux-musl.so +0 -0
  248. sage/rings/padics/padic_relaxed_element.pxd +56 -0
  249. sage/rings/padics/padic_relaxed_element.pyx +18 -0
  250. sage/rings/padics/padic_relaxed_errors.cpython-314-x86_64-linux-musl.so +0 -0
  251. sage/rings/padics/padic_relaxed_errors.pxd +11 -0
  252. sage/rings/padics/padic_relaxed_errors.pyx +71 -0
  253. sage/rings/padics/padic_template_element.pxi +1212 -0
  254. sage/rings/padics/padic_template_element_header.pxi +50 -0
  255. sage/rings/padics/padic_valuation.py +1423 -0
  256. sage/rings/padics/pow_computer_flint.cpython-314-x86_64-linux-musl.so +0 -0
  257. sage/rings/padics/pow_computer_flint.pxd +38 -0
  258. sage/rings/padics/pow_computer_flint.pyx +641 -0
  259. sage/rings/padics/pow_computer_relative.cpython-314-x86_64-linux-musl.so +0 -0
  260. sage/rings/padics/pow_computer_relative.pxd +29 -0
  261. sage/rings/padics/pow_computer_relative.pyx +415 -0
  262. sage/rings/padics/qadic_flint_CA.cpython-314-x86_64-linux-musl.so +0 -0
  263. sage/rings/padics/qadic_flint_CA.pxd +21 -0
  264. sage/rings/padics/qadic_flint_CA.pyx +130 -0
  265. sage/rings/padics/qadic_flint_CR.cpython-314-x86_64-linux-musl.so +0 -0
  266. sage/rings/padics/qadic_flint_CR.pxd +13 -0
  267. sage/rings/padics/qadic_flint_CR.pyx +172 -0
  268. sage/rings/padics/qadic_flint_FM.cpython-314-x86_64-linux-musl.so +0 -0
  269. sage/rings/padics/qadic_flint_FM.pxd +14 -0
  270. sage/rings/padics/qadic_flint_FM.pyx +111 -0
  271. sage/rings/padics/qadic_flint_FP.cpython-314-x86_64-linux-musl.so +0 -0
  272. sage/rings/padics/qadic_flint_FP.pxd +12 -0
  273. sage/rings/padics/qadic_flint_FP.pyx +165 -0
  274. sage/rings/padics/relative_extension_leaves.py +429 -0
  275. sage/rings/padics/relative_ramified_CA.cpython-314-x86_64-linux-musl.so +0 -0
  276. sage/rings/padics/relative_ramified_CA.pxd +9 -0
  277. sage/rings/padics/relative_ramified_CA.pyx +33 -0
  278. sage/rings/padics/relative_ramified_CR.cpython-314-x86_64-linux-musl.so +0 -0
  279. sage/rings/padics/relative_ramified_CR.pxd +8 -0
  280. sage/rings/padics/relative_ramified_CR.pyx +33 -0
  281. sage/rings/padics/relative_ramified_FM.cpython-314-x86_64-linux-musl.so +0 -0
  282. sage/rings/padics/relative_ramified_FM.pxd +9 -0
  283. sage/rings/padics/relative_ramified_FM.pyx +33 -0
  284. sage/rings/padics/relative_ramified_FP.cpython-314-x86_64-linux-musl.so +0 -0
  285. sage/rings/padics/relative_ramified_FP.pxd +8 -0
  286. sage/rings/padics/relative_ramified_FP.pyx +33 -0
  287. sage/rings/padics/relaxed_template.pxi +4229 -0
  288. sage/rings/padics/relaxed_template_header.pxi +160 -0
  289. sage/rings/padics/tests.py +35 -0
  290. sage/rings/padics/tutorial.py +341 -0
  291. sage/rings/padics/unramified_extension_generic.py +335 -0
  292. sage/rings/padics/witt_vector.py +917 -0
  293. sage/rings/padics/witt_vector_ring.py +934 -0
  294. sage/rings/pari_ring.py +235 -0
  295. sage/rings/polynomial/all__sagemath_pari.py +1 -0
  296. sage/rings/polynomial/padics/all.py +1 -0
  297. sage/rings/polynomial/padics/polynomial_padic.py +360 -0
  298. sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py +1324 -0
  299. sage/rings/polynomial/padics/polynomial_padic_flat.py +72 -0
  300. sage/rings/power_series_pari.cpython-314-x86_64-linux-musl.so +0 -0
  301. sage/rings/power_series_pari.pxd +6 -0
  302. sage/rings/power_series_pari.pyx +934 -0
  303. sage/rings/tate_algebra.py +1282 -0
  304. sage/rings/tate_algebra_element.cpython-314-x86_64-linux-musl.so +0 -0
  305. sage/rings/tate_algebra_element.pxd +49 -0
  306. sage/rings/tate_algebra_element.pyx +3464 -0
  307. sage/rings/tate_algebra_ideal.cpython-314-x86_64-linux-musl.so +0 -0
  308. sage/rings/tate_algebra_ideal.pxd +7 -0
  309. sage/rings/tate_algebra_ideal.pyx +1307 -0
  310. sage/rings/valuation/all.py +7 -0
  311. sage/rings/valuation/augmented_valuation.py +2118 -0
  312. sage/rings/valuation/developing_valuation.py +362 -0
  313. sage/rings/valuation/gauss_valuation.py +812 -0
  314. sage/rings/valuation/inductive_valuation.py +1686 -0
  315. sage/rings/valuation/limit_valuation.py +946 -0
  316. sage/rings/valuation/mapped_valuation.py +656 -0
  317. sage/rings/valuation/scaled_valuation.py +322 -0
  318. sage/rings/valuation/trivial_valuation.py +382 -0
  319. sage/rings/valuation/valuation.py +1119 -0
  320. sage/rings/valuation/valuation_space.py +1615 -0
  321. sage/rings/valuation/valuations_catalog.py +10 -0
  322. sage/rings/valuation/value_group.py +697 -0
  323. sage/schemes/all__sagemath_pari.py +1 -0
  324. sage/schemes/elliptic_curves/all__sagemath_pari.py +1 -0
  325. sage/schemes/elliptic_curves/descent_two_isogeny_pari.cpython-314-x86_64-linux-musl.so +0 -0
  326. sage/schemes/elliptic_curves/descent_two_isogeny_pari.pyx +46 -0
  327. sage_wheels/bin/gp +0 -0
  328. sage_wheels/bin/gp2c +0 -0
  329. sage_wheels/bin/gp2c-run +57 -0
  330. sage_wheels/bin/xeus-gp +0 -0
  331. sage_wheels/share/gp2c/func.dsc +18414 -0
@@ -0,0 +1,1324 @@
1
+ # sage_setup: distribution = sagemath-pari
2
+ # sage.doctest: needs sage.libs.ntl
3
+ """
4
+ `p`-adic Capped Relative Dense Polynomials
5
+ """
6
+
7
+ # ****************************************************************************
8
+ # Distributed under the terms of the GNU General Public License (GPL)
9
+ # as published by the Free Software Foundation; either version 2 of
10
+ # the License, or (at your option) any later version.
11
+ # https://www.gnu.org/licenses/
12
+ # ****************************************************************************
13
+
14
+ import sage.rings.polynomial.polynomial_element_generic
15
+ from sage.rings.polynomial.polynomial_element import Polynomial
16
+ from sage.rings.polynomial.padics.polynomial_padic import Polynomial_padic
17
+ import sage.rings.polynomial.polynomial_integer_dense_ntl
18
+ import sage.rings.integer
19
+ import sage.rings.integer_ring
20
+ import sage.rings.padics.misc as misc
21
+ import sage.rings.padics.precision_error as precision_error
22
+ from sage.rings.fraction_field_element import FractionFieldElement
23
+ import copy
24
+
25
+ from sage.libs.pari import pari
26
+ from cypari2.gen import Gen as pari_gen
27
+ from sage.misc.lazy_import import lazy_import
28
+ from sage.rings.infinity import infinity
29
+
30
+ lazy_import('sage.libs.ntl.all', 'ZZX')
31
+
32
+ min = misc.min
33
+ ZZ = sage.rings.integer_ring.ZZ
34
+ PrecisionError = precision_error.PrecisionError
35
+ Integer = sage.rings.integer.Integer
36
+ Polynomial_integer_dense = sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl
37
+ Polynomial_generic_cdv = sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdv
38
+
39
+
40
+ class Polynomial_padic_capped_relative_dense(Polynomial_generic_cdv, Polynomial_padic):
41
+ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, absprec=infinity, relprec=infinity):
42
+ """
43
+ TESTS::
44
+
45
+ sage: K = Qp(13,7)
46
+ sage: R.<t> = K[]
47
+ sage: R([K(13), K(1)])
48
+ (1 + O(13^7))*t + 13 + O(13^8)
49
+ sage: T.<t> = ZZ[]
50
+ sage: R(t + 2)
51
+ (1 + O(13^7))*t + 2 + O(13^7)
52
+
53
+ Check that :issue:`13620` has been fixed::
54
+
55
+ sage: f = R.zero()
56
+ sage: R(f.monomial_coefficients())
57
+ 0
58
+
59
+ Check that :issue:`29829` has been fixed::
60
+
61
+ sage: R.<x> = PolynomialRing(ZZ)
62
+ sage: f = x + 5
63
+ sage: S.<y> = PolynomialRing(Qp(5))
64
+ sage: g2 = S(f)
65
+ sage: 25*g2
66
+ (5^2 + O(5^22))*y + 5^3 + O(5^23)
67
+ """
68
+ Polynomial.__init__(self, parent, is_gen=is_gen)
69
+ self._polygon = None
70
+ parentbr = parent.base_ring()
71
+ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
72
+ if construct:
73
+ (self._poly, self._valbase, self._relprecs, self._normalized, self._valaddeds, self._list) = x # the last two of these may be None
74
+ return
75
+ elif is_gen:
76
+ self._poly = PolynomialRing(ZZ, parent.variable_name()).gen()
77
+ self._valbase = 0
78
+ self._valaddeds = [infinity, 0]
79
+ self._relprecs = [infinity, parentbr.precision_cap()]
80
+ self._normalized = True
81
+ self._list = None
82
+ return
83
+
84
+ # First we list the types that are turned into Polynomials
85
+ if isinstance(x, ZZX):
86
+ x = Polynomial_integer_dense(PolynomialRing(ZZ, parent.variable_name()), x, construct=True)
87
+ elif isinstance(x, FractionFieldElement) and x.denominator() == 1:
88
+ # Currently we ignore precision information in the denominator. This should be changed eventually
89
+ x = x.numerator()
90
+
91
+ # We now coerce various types into lists of coefficients. There are fast pathways for some types of polynomials
92
+ if isinstance(x, Polynomial):
93
+ if x.parent() is self.parent():
94
+ if absprec is not infinity or relprec is not infinity:
95
+ x._normalize()
96
+ self._poly = x._poly
97
+ self._valbase = x._valbase
98
+ self._valaddeds = x._valaddeds
99
+ self._relprecs = x._relprecs
100
+ self._normalized = x._normalized
101
+ self._list = x._list
102
+ if absprec is not infinity or relprec is not infinity:
103
+ self._adjust_prec_info(absprec, relprec)
104
+ return
105
+ elif x.base_ring() is ZZ:
106
+ self._poly = PolynomialRing(ZZ, parent.variable_name())(x)
107
+ self._valbase = Integer(0)
108
+ p = parentbr.prime()
109
+ self._relprecs = [c.valuation(p) + parentbr.precision_cap() for c in x.list()]
110
+ self._comp_valaddeds()
111
+ self._normalized = not self._valaddeds or min(self._valaddeds) == 0
112
+ self._list = None
113
+ if absprec is not infinity or relprec is not infinity:
114
+ self._adjust_prec_info(absprec, relprec)
115
+ return
116
+ else:
117
+ x = [parentbr(a) for a in x.list()]
118
+ check = False
119
+ elif isinstance(x, dict):
120
+ zero = parentbr.zero()
121
+ n = max(x) if x else 0
122
+ v = [zero] * (n + 1)
123
+ for i, z in x.items():
124
+ v[i] = z
125
+ x = v
126
+ elif isinstance(x, pari_gen):
127
+ x = [parentbr(w) for w in x.list()]
128
+ check = False
129
+ # The default behavior, if we haven't already figured out what
130
+ # the type is, is to assume it coerces into the base_ring as a
131
+ # constant polynomial
132
+ elif not isinstance(x, list):
133
+ x = [x] # constant polynomial
134
+
135
+ # In contrast to other polynomials, the zero element is not distinguished
136
+ # by having its list empty. Instead, it has list [0]
137
+ if not x:
138
+ x = [parentbr.zero()]
139
+ if check:
140
+ x = [parentbr(z) for z in x]
141
+
142
+ # Remove this -- for p-adics this is terrible, since it kills any non exact zero.
143
+ # if len(x) == 1 and not x[0]:
144
+ # x = []
145
+
146
+ self._list = x
147
+ self._valaddeds = [a.valuation() for a in x]
148
+ self._valbase = sage.rings.padics.misc.min(self._valaddeds)
149
+ if self._valbase is infinity:
150
+ self._valaddeds = []
151
+ self._relprecs = []
152
+ self._poly = PolynomialRing(ZZ, parent.variable_name())()
153
+ self._normalized = True
154
+ if absprec is not infinity or relprec is not infinity:
155
+ self._adjust_prec_info(absprec, relprec)
156
+ else:
157
+ self._valaddeds = [c - self._valbase for c in self._valaddeds]
158
+ self._relprecs = [a.precision_absolute() - self._valbase for a in x]
159
+ self._poly = PolynomialRing(ZZ, parent.variable_name())([a >> self._valbase for a in x])
160
+ self._normalized = True
161
+ if absprec is not infinity or relprec is not infinity:
162
+ self._adjust_prec_info(absprec, relprec)
163
+
164
+ def _new_constant_poly(self, a, P):
165
+ """
166
+ Create a new constant polynomial in parent P with value a.
167
+
168
+ ASSUMPTION:
169
+
170
+ The value a must be an element of the base ring of P. That
171
+ assumption is not verified.
172
+
173
+ EXAMPLES::
174
+
175
+ sage: R.<t> = Zp(5)[]
176
+ sage: t._new_constant_poly(O(5),R)
177
+ O(5)
178
+ """
179
+ return self.__class__(P, [a], check=False)
180
+
181
+ def _normalize(self):
182
+ # Currently slow: need to optimize
183
+ if not self._normalized:
184
+ if self._valaddeds is None:
185
+ self._comp_valaddeds()
186
+ val = sage.rings.padics.misc.min(self._valaddeds)
187
+ prime_pow = self.base_ring().prime_pow
188
+ selflist = self._poly.list()
189
+ if val is infinity:
190
+ pass
191
+ elif val != 0:
192
+ self._relprecs = [max(prec - val, 0) for prec in self._relprecs]
193
+ v = [Integer(0) if (e is infinity) else ((c // prime_pow(val)) % prime_pow(e)) for c, e in zip(selflist, self._relprecs)]
194
+ self._poly = self._poly.parent()(v, check=False)
195
+ self._valbase += val
196
+ self._valaddeds = [c - val for c in self._valaddeds]
197
+ else:
198
+ self._poly = self._poly.parent()([Integer(0) if (e is infinity) else (c % prime_pow(e)) for c, e in zip(selflist, self._relprecs)], check=False)
199
+ self._normalized = True
200
+
201
+ def _reduce_poly(self):
202
+ selflist = self._poly.list()
203
+ prime_pow = self.base_ring().prime_pow
204
+ self._poly = self._poly.parent()([Integer(0) if (e is infinity) else (c % prime_pow(e)) for (c, e) in zip(selflist, self._relprecs)], check=False)
205
+
206
+ def __reduce__(self):
207
+ """
208
+ For pickling. This function is here because the relative precisions were getting screwed up for some reason.
209
+ """
210
+ return make_padic_poly, (self.parent(), (self._poly, self._valbase, self._relprecs, self._normalized, self._valaddeds, self._list), 0)
211
+
212
+ def _comp_list(self):
213
+ """
214
+ Recomputes the list of coefficients.
215
+
216
+ EXAMPLES::
217
+
218
+ sage: K = Qp(13,7)
219
+ sage: R.<t> = K[]
220
+ sage: a = t[:1]
221
+ sage: a._comp_list()
222
+ sage: a
223
+ 0
224
+ """
225
+ if self.degree() == -1 and self._valbase == infinity:
226
+ self._list = []
227
+ polylist = self._poly.list()
228
+ polylen = len(polylist)
229
+ self._list = [self.base_ring()(polylist[i], absprec=self._relprecs[i]) << self._valbase for i in range(polylen)] \
230
+ + [self.base_ring()(0, absprec=self._relprecs[i] + self._valbase) for i in range(polylen, len(self._relprecs))]
231
+ while self._list and self._list[-1]._is_exact_zero():
232
+ self._list.pop()
233
+
234
+ def _comp_valaddeds(self):
235
+ self._valaddeds = []
236
+ prime = self.parent().base_ring().prime()
237
+ for i, pli in enumerate(self._poly.list()):
238
+ tmp = pli.valuation(prime)
239
+ if tmp is infinity or tmp > self._relprecs[i]:
240
+ self._valaddeds.append(self._relprecs[i])
241
+ else:
242
+ self._valaddeds.append(tmp)
243
+ for i in range(self._poly.degree() + 1, len(self._relprecs)):
244
+ self._valaddeds.append(self._relprecs[i])
245
+
246
+ def _adjust_prec_info(self, absprec=infinity, relprec=infinity):
247
+ r"""
248
+ Assumes that self._poly, self._val and self._relprec are set initially and adjusts self._val and self._relprec to the termwise minimum of absprec and relprec.
249
+ """
250
+ return
251
+
252
+ # min = sage.rings.padics.misc.min
253
+ # slen = len(self._relprec)
254
+ # if isinstance(absprec, list):
255
+ # alen = len(absprec)
256
+ # elif absprec is infinity:
257
+ # alen = 0
258
+ # absprec = []
259
+ # else:
260
+ # alen = 1
261
+ # if isinstance(relprec, list):
262
+ # rlen = len(relprec)
263
+ # elif relprec is infinity:
264
+ # rlen = 0
265
+ # relprec = []
266
+ # else:
267
+ # rlen = 1
268
+ # preclen = max(slen, rlen, alen)
269
+ # if not isinstance(absprec, list):
270
+ # absprec = [absprec] * preclen
271
+ # if not isinstance(relprec, list):
272
+ # relprec = [relprec] * preclen
273
+ # vallist = [c.valuation(self.base_ring().prime()) + self._val for c in self._poly.list()] #######
274
+ # vmin = min(vallist)
275
+ # amin = min(absprec)
276
+ # if amin < vmin:
277
+ # vmin = amin
278
+ # if vmin < self._val:
279
+ # vadjust =
280
+
281
+ # if not isinstance(absprec, list):
282
+ # self._val = min(vallist + [absprec])
283
+ # absprec = [absprec] * preclen
284
+ # else:
285
+ # self._val = padics.misc.min(vallist + absprec)
286
+ # absprec = absprec + [infinity] * (preclen - len(absprec))
287
+ # if self._val is infinity:
288
+ # self._relprec = []
289
+ # return
290
+ # if not isinstance(relprec, list):
291
+ # relprec = [relprec] * preclen
292
+ # else:
293
+ # relprec = relprec + [parent.base_ring().precision_cap()] * (preclen - len(relprec))
294
+ # self._relprec = [min(a, v + r) - self._val for (a, r, v) in zip(absprec, relprec, vallist)]
295
+ # Remember to normalize at the end if self._normalized is true because you need to reduce mod p^n
296
+
297
+ def _getprecpoly(self, n):
298
+ one = Integer(1)
299
+ return self._poly.parent()([(0 if (c is infinity) else (one << (n * c))) for c in self._relprecs])
300
+
301
+ def _getvalpoly(self, n):
302
+ one = Integer(1)
303
+ if self._valaddeds is None:
304
+ self._comp_valaddeds()
305
+ return self._poly.parent()([(0 if (c is infinity) else (one << (n * c))) for c in self._valaddeds] +
306
+ [(0 if (c is infinity) else (one << (n * c))) for c in self._relprecs[len(self._valaddeds):]])
307
+
308
+ def list(self, copy=True):
309
+ """
310
+ Return a list of coefficients of ``self``.
311
+
312
+ .. NOTE::
313
+
314
+ The length of the list returned may be greater
315
+ than expected since it includes any leading zeros
316
+ that have finite absolute precision.
317
+
318
+ EXAMPLES::
319
+
320
+ sage: K = Qp(13,7)
321
+ sage: R.<t> = K[]
322
+ sage: a = 2*t^3 + 169*t - 1
323
+ sage: a
324
+ (2 + O(13^7))*t^3 + (13^2 + O(13^9))*t + 12 + 12*13 + 12*13^2 + 12*13^3 + 12*13^4 + 12*13^5 + 12*13^6 + O(13^7)
325
+ sage: a.list()
326
+ [12 + 12*13 + 12*13^2 + 12*13^3 + 12*13^4 + 12*13^5 + 12*13^6 + O(13^7),
327
+ 13^2 + O(13^9),
328
+ 0,
329
+ 2 + O(13^7)]
330
+ """
331
+ if self._list is None:
332
+ self._comp_list()
333
+ if copy:
334
+ return list(self._list)
335
+ else:
336
+ return self._list
337
+
338
+ def lift(self):
339
+ """
340
+ Return an integer polynomial congruent to this one modulo the
341
+ precision of each coefficient.
342
+
343
+ .. NOTE::
344
+
345
+ The lift that is returned will not necessarily be the same
346
+ for polynomials with the same coefficients (i.e. same values
347
+ and precisions): it will depend on how the polynomials are
348
+ created.
349
+
350
+ EXAMPLES::
351
+
352
+ sage: K = Qp(13,7)
353
+ sage: R.<t> = K[]
354
+ sage: a = 13^7*t^3 + K(169,4)*t - 13^4
355
+ sage: a.lift()
356
+ 62748517*t^3 + 169*t - 28561
357
+ """
358
+ return self.base_ring().prime_pow(self._valbase) * self._poly
359
+
360
+ def __getitem__(self, n):
361
+ """
362
+ Return the `n`-th coefficient of ``self``.
363
+
364
+ This returns the coefficient of `x^n` if `n` is an integer,
365
+ and returns the monomials of ``self`` of degree
366
+ in slice `n` if `n` is a slice ``[:k]``.
367
+
368
+ EXAMPLES::
369
+
370
+ sage: K = Qp(13,7)
371
+ sage: R.<t> = K[]
372
+ sage: a = 13^7*t^3 + K(169,4)*t - 13^4
373
+ sage: a[1]
374
+ 13^2 + O(13^4)
375
+
376
+ Slices can be used to truncate polynomials::
377
+
378
+ sage: a[:2]
379
+ (13^2 + O(13^4))*t + 12*13^4 + 12*13^5 + 12*13^6 + 12*13^7 + 12*13^8 + 12*13^9 + 12*13^10 + O(13^11)
380
+
381
+ Any other kind of slicing is an error, see :issue:`18940`::
382
+
383
+ sage: a[1:3]
384
+ Traceback (most recent call last):
385
+ ...
386
+ IndexError: polynomial slicing with a start is not defined
387
+
388
+ sage: a[1:3:2]
389
+ Traceback (most recent call last):
390
+ ...
391
+ IndexError: polynomial slicing with a step is not defined
392
+ """
393
+ d = len(self._relprecs) # = degree + 1
394
+ if isinstance(n, slice):
395
+ start, stop, step = n.start, n.stop, n.step
396
+ if step is not None:
397
+ raise IndexError("polynomial slicing with a step is not defined")
398
+ if start is not None:
399
+ raise IndexError("polynomial slicing with a start is not defined")
400
+ if stop is None or stop > d:
401
+ stop = d
402
+ values = [self[i] for i in range(stop)]
403
+ return self.parent()(values)
404
+
405
+ try:
406
+ n = n.__index__()
407
+ except AttributeError:
408
+ raise TypeError("list indices must be integers, not {0}".format(type(n).__name__))
409
+
410
+ if n < 0 or n >= d:
411
+ return self.base_ring().zero()
412
+ if self._list is not None:
413
+ return self._list[n]
414
+ return self.base_ring()(self.base_ring().prime_pow(self._valbase)
415
+ * self._poly[n], absprec=self._valbase + self._relprecs[n])
416
+
417
+ def _add_(self, right):
418
+ """
419
+ Return the sum of ``self`` and ``right``.
420
+
421
+ EXAMPLES::
422
+
423
+ sage: K = Qp(13,7)
424
+ sage: R.<t> = K[]
425
+ sage: a = t^4 + 17*t^2 + 1
426
+ sage: b = -t^4 + 9*t^2 + 13*t - 1
427
+ sage: c = a + b; c
428
+ O(13^7)*t^4 + (2*13 + O(13^7))*t^2 + (13 + O(13^8))*t + O(13^7)
429
+ sage: c.list()
430
+ [O(13^7), 13 + O(13^8), 2*13 + O(13^7), 0, O(13^7)]
431
+ """
432
+ selfpoly = self._poly
433
+ rightpoly = right._poly
434
+ if self._valbase > right._valbase:
435
+ selfpoly = selfpoly * self.base_ring().prime_pow(self._valbase - right._valbase)
436
+ baseval = right._valbase
437
+ elif self._valbase < right._valbase:
438
+ rightpoly = rightpoly * self.base_ring().prime_pow(right._valbase - self._valbase)
439
+ baseval = self._valbase
440
+ else:
441
+ baseval = self._valbase
442
+ # Currently we don't reduce the coefficients of the answer modulo the appropriate power of p or normalize
443
+ return Polynomial_padic_capped_relative_dense(self.parent(),
444
+ (selfpoly + rightpoly,
445
+ baseval,
446
+ [min(a + self._valbase - baseval, b + right._valbase - baseval)
447
+ for (a, b) in zip(_extend_by_infinity(self._relprecs, max(len(self._relprecs), len(right._relprecs))),
448
+ _extend_by_infinity(right._relprecs, max(len(self._relprecs), len(right._relprecs))))],
449
+ False, None, None), construct=True)
450
+
451
+ def _sub_(self, right):
452
+ """
453
+ Return the difference of ``self`` and ``right``.
454
+
455
+ EXAMPLES::
456
+
457
+ sage: K = Qp(13,7)
458
+ sage: R.<t> = K[]
459
+ sage: a = t^4 + 17*t^2 + 1
460
+ sage: b = t^4 - 9*t^2 - 13*t + 1
461
+ sage: c = a - b; c
462
+ O(13^7)*t^4 + (2*13 + O(13^7))*t^2 + (13 + O(13^8))*t + O(13^7)
463
+ sage: c.list()
464
+ [O(13^7), 13 + O(13^8), 2*13 + O(13^7), 0, O(13^7)]
465
+ """
466
+ selfpoly = self._poly
467
+ rightpoly = right._poly
468
+ if self._valbase > right._valbase:
469
+ selfpoly = selfpoly * self.base_ring().prime_pow(self._valbase - right._valbase)
470
+ baseval = right._valbase
471
+ elif self._valbase < right._valbase:
472
+ rightpoly = rightpoly * self.base_ring().prime_pow(right._valbase - self._valbase)
473
+ baseval = self._valbase
474
+ else:
475
+ baseval = self._valbase
476
+ # Currently we don't reduce the coefficients of the answer modulo the appropriate power of p or normalize
477
+ return Polynomial_padic_capped_relative_dense(self.parent(),
478
+ (selfpoly - rightpoly,
479
+ baseval,
480
+ [min(a + self._valbase - baseval, b + right._valbase - baseval)
481
+ for (a, b) in zip(_extend_by_infinity(self._relprecs, max(len(self._relprecs), len(right._relprecs))),
482
+ _extend_by_infinity(right._relprecs, max(len(self._relprecs), len(right._relprecs))))],
483
+ False, None, None), construct=True)
484
+
485
+ def _mul_(self, right):
486
+ r"""
487
+ Multiply ``self`` and ``right``.
488
+
489
+ ALGORITHM: We use an algorithm thought up by Joe Wetherell to
490
+ find the precisions of the product. It works as follows:
491
+ Suppose `f = \sum_i a_i x^i` and `g = \sum_j b_j x^j`. Let `N
492
+ = \max(\deg f, \deg g) + 1` (in the actual implementation we
493
+ use `N = 2^{\lfloor \log_2\max(\deg f, \deg g)\rfloor + 1}`).
494
+ The valuations and absolute precisions of each coefficient
495
+ contribute to the absolute precision of the `k`-th coefficient of
496
+ the product in the following way: for each `i + j = k`, you
497
+ take the valuation of `a_i` plus the absolute precision of
498
+ `b_j`, and then take the valuation of `b_j` plus the absolute
499
+ precision of `a_i`, take the minimum of those two, and then
500
+ take the minimum over all `i`, `j` summing to `k`.
501
+
502
+ You can simulate this as follows. Construct new polynomials of
503
+ degree `N`:
504
+
505
+ \begin{align*}
506
+ A &= \sum_i N^{\mbox{valuation of $a_i$}} x^i \\
507
+ B &= \sum_j N^{\mbox{absolute precision of $b_j$}} x^j \\
508
+ C &= \sum_i N^{\mbox{absolute precision of $a_i$}} x^i \\
509
+ D &= \sum_j N^{\mbox{valuation of $b_j$}} x^j \\
510
+ \end{align*}
511
+
512
+ Now you compute AB and CD. Because you're representing things
513
+ 'N-adically', you don't get any 'overflow', and you can just
514
+ read off what the precisions of the product are. In fact it
515
+ tells you more, it tells you exactly how many terms of each
516
+ combination of valuation modulus contribute to each term of
517
+ the product (though this feature is not currently exposed in
518
+ our implementation.
519
+
520
+ Since we're working 'N-adically' we can just consider
521
+ `N^{\infty} = 0`.
522
+
523
+ NOTE: The timing of normalization in arithmetic operations
524
+ may very well change as we do more tests on the relative time
525
+ requirements of these operations.
526
+
527
+ EXAMPLES::
528
+
529
+ sage: K = Qp(13,7)
530
+ sage: R.<t> = K[]
531
+ sage: a = t^4 + 17*t^2 + 1
532
+ sage: b = -t^4 + 9*t^2 + 13*t - 1
533
+ sage: c = a + b; c
534
+ O(13^7)*t^4 + (2*13 + O(13^7))*t^2 + (13 + O(13^8))*t + O(13^7)
535
+ sage: d = R([K(1,4), K(2, 6), K(1, 5)]); d
536
+ (1 + O(13^5))*t^2 + (2 + O(13^6))*t + 1 + O(13^4)
537
+ sage: e = c * d; e
538
+ O(13^7)*t^6 + O(13^7)*t^5 + (2*13 + O(13^6))*t^4 + (5*13 + O(13^6))*t^3 + (4*13 + O(13^5))*t^2 + (13 + O(13^5))*t + O(13^7)
539
+ sage: e.list()
540
+ [O(13^7),
541
+ 13 + O(13^5),
542
+ 4*13 + O(13^5),
543
+ 5*13 + O(13^6),
544
+ 2*13 + O(13^6),
545
+ O(13^7),
546
+ O(13^7)]
547
+ """
548
+ self._normalize()
549
+ right._normalize()
550
+ zzpoly = self._poly * right._poly
551
+ if not self._relprecs or len(right._relprecs) == 0:
552
+ return self.parent()(0)
553
+ n = Integer(len(self._relprecs) + len(right._relprecs) - 1).exact_log(2) + 1
554
+ precpoly1 = self._getprecpoly(n) * right._getvalpoly(n)
555
+ precpoly2 = self._getvalpoly(n) * right._getprecpoly(n)
556
+ # These two will be the same length
557
+ tn = Integer(1) << n
558
+ preclist = [min(a.valuation(tn), b.valuation(tn)) for (a, b) in zip(precpoly1.list(), precpoly2.list())]
559
+ answer = Polynomial_padic_capped_relative_dense(self.parent(), (zzpoly, self._valbase + right._valbase, preclist, False, None, None), construct=True)
560
+ answer._reduce_poly()
561
+ return answer
562
+
563
+ def _lmul_(self, right):
564
+ return self._rmul_(right)
565
+
566
+ def _rmul_(self, left):
567
+ """
568
+ Return ``self`` multiplied by a constant.
569
+
570
+ EXAMPLES::
571
+
572
+ sage: K = Qp(13,7)
573
+ sage: R.<t> = K[]
574
+ sage: a = t^4 + K(13,5)*t^2 + 13
575
+ sage: K(13,7) * a
576
+ (13 + O(13^7))*t^4 + (13^2 + O(13^6))*t^2 + 13^2 + O(13^8)
577
+ """
578
+ return None
579
+ # The code below has never been tested and is somehow subtly broken.
580
+
581
+ if self._valaddeds is None:
582
+ self._comp_valaddeds()
583
+ if left != 0:
584
+ val, unit = left.val_unit()
585
+ left_rprec = left.precision_relative()
586
+ relprecs = [min(left_rprec + self._valaddeds[i], self._relprecs[i]) for i in range(len(self._relprecs))]
587
+ elif left._is_exact_zero():
588
+ return Polynomial_padic_capped_relative_dense(self.parent(), [])
589
+ else:
590
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly.parent()(0), self._valbase + left.valuation(), self._valaddeds, False, self._valaddeds, None), construct=True)
591
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly._rmul_(unit), self._valbase + val, relprecs, False, self._valaddeds, None), construct=True)
592
+
593
+ def _neg_(self):
594
+ """
595
+ Return the negation of ``self``.
596
+
597
+ EXAMPLES::
598
+
599
+ sage: K = Qp(13,2)
600
+ sage: R.<t> = K[]
601
+ sage: a = t^4 + 13*t^2 + 4
602
+ sage: -a
603
+ (12 + 12*13 + O(13^2))*t^4 + (12*13 + 12*13^2 + O(13^3))*t^2 + 9 + 12*13 + O(13^2)
604
+ """
605
+ return Polynomial_padic_capped_relative_dense(self.parent(), (-self._poly, self._valbase, self._relprecs, False, self._valaddeds, None), construct=True)
606
+
607
+ def lshift_coeffs(self, shift, no_list=False):
608
+ """
609
+ Return a new polynomials whose coefficients are multiplied by p^shift.
610
+
611
+ EXAMPLES::
612
+
613
+ sage: K = Qp(13, 4)
614
+ sage: R.<t> = K[]
615
+ sage: a = t + 52
616
+ sage: a.lshift_coeffs(3)
617
+ (13^3 + O(13^7))*t + 4*13^4 + O(13^8)
618
+ """
619
+ if shift < 0:
620
+ return self.rshift_coeffs(-shift, no_list)
621
+ if no_list or self._list is None:
622
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase + shift, self._relprecs, False, self._valaddeds, None), construct=True)
623
+ else:
624
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase + shift, self._relprecs, False, self._valaddeds, [c.__lshift__(shift) for c in self._list]), construct=True)
625
+
626
+ def rshift_coeffs(self, shift, no_list=False):
627
+ """
628
+ Return a new polynomial whose coefficients are `p`-adically
629
+ shifted to the right by ``shift``.
630
+
631
+ .. NOTE::
632
+
633
+ Type ``Qp(5)(0).__rshift__?`` for more information.
634
+
635
+ EXAMPLES::
636
+
637
+ sage: K = Zp(13, 4)
638
+ sage: R.<t> = K[]
639
+ sage: a = t^2 + K(13,3)*t + 169; a
640
+ (1 + O(13^4))*t^2 + (13 + O(13^3))*t + 13^2 + O(13^6)
641
+ sage: b = a.rshift_coeffs(1); b
642
+ O(13^3)*t^2 + (1 + O(13^2))*t + 13 + O(13^5)
643
+ sage: b.list()
644
+ [13 + O(13^5), 1 + O(13^2), O(13^3)]
645
+ sage: b = a.rshift_coeffs(2); b
646
+ O(13^2)*t^2 + O(13)*t + 1 + O(13^4)
647
+ sage: b.list()
648
+ [1 + O(13^4), O(13), O(13^2)]
649
+ """
650
+ if shift < 0:
651
+ return self.lshift_coeffs(-shift, no_list) # We can't just absorb this into the next if statement because we allow rshift to preserve _normalized
652
+ if self.base_ring().is_field() or shift <= self._valbase:
653
+ if no_list or self._list is None:
654
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase - shift, self._relprecs, self._normalized, self._valaddeds, None), construct=True)
655
+ else:
656
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly, self._valbase - shift, self._relprecs, self._normalized, self._valaddeds, [c.__rshift__(shift) for c in self._list]), construct=True)
657
+ else:
658
+ shift = shift - self._valbase
659
+ fdiv = self.base_ring().prime_pow(shift)
660
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly // fdiv, 0, [0 if a <= shift else a - shift for a in self._relprecs], False, None, None), construct=True)
661
+
662
+ # def __floordiv__(self, right):
663
+ # if isinstance(right, Polynomial) and right.is_constant() and right[0] in self.base_ring():
664
+ # d = self.base_ring()(right[0])
665
+ # elif (right in self.base_ring()):
666
+ # d = self.base_ring()(right)
667
+ # else:
668
+ # raise NotImplementedError
669
+ # return self._rmul_(self.base_ring()(~d.unit_part())).rshift_coeffs(d.valuation())
670
+
671
+ def _unsafe_mutate(self, n, value):
672
+ """
673
+ It's a really bad idea to use this function for `p`-adic
674
+ polynomials. There are speed issues, and it may not be
675
+ bug-free currently.
676
+ """
677
+ n = int(n)
678
+ value = self.base_ring()(value)
679
+ if self.is_gen():
680
+ raise ValueError("cannot modify generator")
681
+ if n < 0:
682
+ raise IndexError("n must be >= 0")
683
+ if self._valbase is infinity:
684
+ if value._is_exact_zero():
685
+ return
686
+ self._valbase = value.valuation()
687
+ if value != 0:
688
+ self._poly._unsafe_mutate(self, n, value.unit_part().lift())
689
+ self._relprecs = [infinity] * n + [value.precision_relative()]
690
+ else:
691
+ self._relprecs = [infinity] * n + [0]
692
+ self._valaddeds = [infinity] * n + [0]
693
+ zero = self.base_ring()(0)
694
+ self._list = [zero] * n + [value]
695
+ self._normalized = True
696
+ elif value.valuation() >= self._valbase:
697
+ # _valbase and _normalized stay the same
698
+ if value != 0:
699
+ self._poly._unsafe_mutate(self, n, (value.__rshift__(self._valbase)).lift())
700
+ else:
701
+ self._poly._unsafe_mutate(self, n, 0)
702
+ if n < len(self._relprecs):
703
+ self._relprecs[n] = value.precision_absolute() - self._valbase
704
+ if self._valaddeds is not None:
705
+ self._valaddeds[n] = value.valuation() - self._valbase
706
+ if self._list is not None:
707
+ self._list[n] = value
708
+ else:
709
+ self._relprecs.extend([infinity] * (n - len(self._relprecs)) + [value.precision_absolute() - self._valbase])
710
+ if self._valaddeds is not None:
711
+ self._valaddeds.extend([infinity] * (n - len(self._relprecs)) + [value.valuation() - self._valbase])
712
+ if self._list is not None:
713
+ zero = self.base_ring()(0)
714
+ self._list.extend([zero] * (n - len(self._relprecs)) + [value])
715
+ else:
716
+ basediff = self._valbase - value.valuation()
717
+ self._valbase = value.valuation()
718
+ if self._valaddeds is not None:
719
+ self._valaddeds = [c + basediff for c in self._valaddeds]
720
+ self._poly = self._poly * self.base_ring().prime_pow(basediff)
721
+ if value != 0:
722
+ self._poly._unsafe_mutate(self, n, value.unit_part().lift())
723
+ else:
724
+ self._poly._unsafe_mutate(self, n, 0)
725
+ if n < len(self._relprecs):
726
+ self._relprecs[n] = value.precision_relative()
727
+ else:
728
+ self._relprecs.extend([infinity] * (n - len(self._relprecs)) + [value.precision_relative()])
729
+ self._normalized = False
730
+ if self._list is not None:
731
+ if n < len(self._list):
732
+ self._list[n] = value
733
+ else:
734
+ zero = self._base_ring()(0)
735
+ self._list.extend([zero] * (n - len(self._list)) + [value])
736
+
737
+ def __pari__(self, variable=None):
738
+ """
739
+ Return ``self`` as a PARI object.
740
+ """
741
+ if variable is None:
742
+ variable = self.parent().variable_name()
743
+ return pari(self.list()).Polrev(variable)
744
+
745
+ def __copy__(self):
746
+ """
747
+ Return a copy of ``self``.
748
+ """
749
+ return Polynomial_padic_capped_relative_dense(self.parent(), (copy.copy(self._poly), self._valbase, copy.copy(self._relprecs), self._normalized, copy.copy(self._valaddeds), copy.copy(self._list)), construct=True)
750
+
751
+ def degree(self, secure=False):
752
+ """
753
+ Return the degree of ``self``.
754
+
755
+ INPUT:
756
+
757
+ - ``secure`` -- boolean (default: ``False``)
758
+
759
+ If ``secure`` is ``True`` and the degree of this polynomial
760
+ is not determined (because the leading coefficient is
761
+ indistinguishable from 0), an error is raised.
762
+
763
+ If ``secure`` is ``False``, the returned value is the largest
764
+ `n` so that the coefficient of `x^n` does not compare equal
765
+ to `0`.
766
+
767
+ EXAMPLES::
768
+
769
+ sage: K = Qp(3,10)
770
+ sage: R.<T> = K[]
771
+ sage: f = T + 2; f
772
+ (1 + O(3^10))*T + 2 + O(3^10)
773
+ sage: f.degree()
774
+ 1
775
+ sage: (f-T).degree()
776
+ 0
777
+ sage: (f-T).degree(secure=True)
778
+ Traceback (most recent call last):
779
+ ...
780
+ PrecisionError: the leading coefficient is indistinguishable from 0
781
+
782
+ sage: x = O(3^5)
783
+ sage: li = [3^i * x for i in range(0,5)]; li
784
+ [O(3^5), O(3^6), O(3^7), O(3^8), O(3^9)]
785
+ sage: f = R(li); f
786
+ O(3^9)*T^4 + O(3^8)*T^3 + O(3^7)*T^2 + O(3^6)*T + O(3^5)
787
+ sage: f.degree()
788
+ -1
789
+ sage: f.degree(secure=True)
790
+ Traceback (most recent call last):
791
+ ...
792
+ PrecisionError: the leading coefficient is indistinguishable from 0
793
+ """
794
+ self._normalize()
795
+ deg = Integer(self._poly.degree())
796
+ if secure and deg < self.prec_degree():
797
+ raise PrecisionError("the leading coefficient is "
798
+ "indistinguishable from 0")
799
+ return deg
800
+
801
+ def prec_degree(self):
802
+ """
803
+ Return the largest `n` so that precision information is
804
+ stored about the coefficient of `x^n`.
805
+
806
+ Always greater than or equal to degree.
807
+
808
+ EXAMPLES::
809
+
810
+ sage: K = Qp(3,10)
811
+ sage: R.<T> = K[]
812
+ sage: f = T + 2; f
813
+ (1 + O(3^10))*T + 2 + O(3^10)
814
+ sage: f.prec_degree()
815
+ 1
816
+ """
817
+ return len(self._relprecs) - 1
818
+
819
+ def precision_absolute(self, n=None):
820
+ """
821
+ Return absolute precision information about ``self``.
822
+
823
+ INPUT:
824
+
825
+ - ``self`` -- a `p`-adic polynomial
826
+
827
+ - ``n`` -- ``None`` or integer (default: ``None``)
828
+
829
+ OUTPUT:
830
+
831
+ If ``n`` is ``None``, returns a list of absolute precisions of
832
+ coefficients. Otherwise, returns the absolute precision of
833
+ the coefficient of `x^n`.
834
+
835
+ EXAMPLES::
836
+
837
+ sage: K = Qp(3,10)
838
+ sage: R.<T> = K[]
839
+ sage: f = T + 2; f
840
+ (1 + O(3^10))*T + 2 + O(3^10)
841
+ sage: f.precision_absolute()
842
+ [10, 10]
843
+ """
844
+ if n is None:
845
+ return [c + self._valbase for c in self._relprecs]
846
+ return self._relprecs[n] + self._valbase
847
+
848
+ def precision_relative(self, n=None):
849
+ """
850
+ Return relative precision information about ``self``.
851
+
852
+ INPUT:
853
+
854
+ - ``self`` -- a `p`-adic polynomial
855
+
856
+ - ``n`` -- ``None`` or integer (default: ``None``)
857
+
858
+ OUTPUT:
859
+
860
+ If ``n`` is ``None``, returns a list of relative precisions of
861
+ coefficients. Otherwise, returns the relative precision of
862
+ the coefficient of `x^n`.
863
+
864
+ EXAMPLES::
865
+
866
+ sage: K = Qp(3,10)
867
+ sage: R.<T> = K[]
868
+ sage: f = T + 2; f
869
+ (1 + O(3^10))*T + 2 + O(3^10)
870
+ sage: f.precision_relative()
871
+ [10, 10]
872
+ """
873
+ if n is None:
874
+ self._normalize()
875
+ return copy.copy(self._relprecs)
876
+ n = int(n)
877
+ if n < 0 or n >= len(self._relprecs) or self._relprecs[n] is infinity:
878
+ return Integer(0)
879
+ if self._valaddeds is None:
880
+ return self._relprecs[n] - self._poly[n].valuation(self.base_ring().prime())
881
+ else:
882
+ return self._relprecs[n] - self._valaddeds[n]
883
+
884
+ def valuation_of_coefficient(self, n=None):
885
+ """
886
+ Return valuation information about ``self``'s coefficients.
887
+
888
+ INPUT:
889
+
890
+ - ``self`` -- a `p`-adic polynomial
891
+
892
+ - ``n`` -- ``None`` or integer (default: ``None``)
893
+
894
+ OUTPUT:
895
+
896
+ If ``n`` is ``None``, returns a list of valuations of coefficients. Otherwise,
897
+ returns the valuation of the coefficient of `x^n`.
898
+
899
+ EXAMPLES::
900
+
901
+ sage: K = Qp(3,10)
902
+ sage: R.<T> = K[]
903
+ sage: f = T + 2; f
904
+ (1 + O(3^10))*T + 2 + O(3^10)
905
+ sage: f.valuation_of_coefficient(1)
906
+ 0
907
+ """
908
+ if self._valaddeds is None:
909
+ self._comp_valaddeds()
910
+ if n is None:
911
+ self._normalize()
912
+ return [c + self._valbase for c in self._valaddeds]
913
+ n = int(n)
914
+ if n < 0 or n >= len(self._relprecs):
915
+ return infinity
916
+ return self._valbase + self._valaddeds[n]
917
+
918
+ def valuation(self, val_of_var=None):
919
+ """
920
+ Return the valuation of ``self``.
921
+
922
+ INPUT:
923
+
924
+ - ``self`` -- a `p`-adic polynomial
925
+
926
+ - ``val_of_var`` -- ``None`` or a rational (default: ``None``)
927
+
928
+ OUTPUT:
929
+
930
+ If ``val_of_var`` is ``None``, returns the largest power of the
931
+ variable dividing ``self``. Otherwise, returns the valuation of
932
+ ``self`` where the variable is assigned valuation ``val_of_var``
933
+
934
+ EXAMPLES::
935
+
936
+ sage: K = Qp(3,10)
937
+ sage: R.<T> = K[]
938
+ sage: f = T + 2; f
939
+ (1 + O(3^10))*T + 2 + O(3^10)
940
+ sage: f.valuation()
941
+ 0
942
+ """
943
+ if val_of_var is None:
944
+ return self._poly.valuation()
945
+ if self._valaddeds is None:
946
+ self._comp_valaddeds()
947
+ return self._valbase + min([self._valaddeds[i] + val_of_var * i for i in range(len(self._valaddeds))])
948
+
949
+ def reverse(self, degree=None):
950
+ """
951
+ Return the reverse of the input polynomial, thought as a polynomial of
952
+ degree ``degree``.
953
+
954
+ If `f` is a degree-`d` polynomial, its reverse is `x^d f(1/x)`.
955
+
956
+ INPUT:
957
+
958
+ - ``degree`` -- ``None`` or integer; if specified, truncate or zero
959
+ pad the list of coefficients to this degree before reversing it
960
+
961
+ EXAMPLES::
962
+
963
+ sage: K = Qp(13,7)
964
+ sage: R.<t> = K[]
965
+ sage: f = t^3 + 4*t; f
966
+ (1 + O(13^7))*t^3 + (4 + O(13^7))*t
967
+ sage: f.reverse()
968
+ 0*t^3 + (4 + O(13^7))*t^2 + 1 + O(13^7)
969
+ sage: f.reverse(3)
970
+ 0*t^3 + (4 + O(13^7))*t^2 + 1 + O(13^7)
971
+ sage: f.reverse(2)
972
+ 0*t^2 + (4 + O(13^7))*t
973
+ sage: f.reverse(4)
974
+ 0*t^4 + (4 + O(13^7))*t^3 + (1 + O(13^7))*t
975
+ sage: f.reverse(6)
976
+ 0*t^6 + (4 + O(13^7))*t^5 + (1 + O(13^7))*t^3
977
+
978
+ TESTS:
979
+
980
+ Check that this implementation is compatible with the generic one::
981
+
982
+ sage: all(f.reverse(d) == Polynomial.reverse(f, d)
983
+ ....: for d in [None,0,1,2,3,4,5])
984
+ True
985
+ """
986
+ n = self._poly.degree() if degree is None else degree
987
+ zzlist = self._poly.list()[:(n + 1)] + [0] * (n - self._poly.degree())
988
+ zzlist.reverse()
989
+ relprec = self._relprecs[:(n + 1)] + [infinity] * (n - self.prec_degree())
990
+ relprec.reverse()
991
+ if self._valaddeds is None:
992
+ valadded = None
993
+ else:
994
+ valadded = self._valaddeds[:(n + 1)] + [infinity] * (n - self.prec_degree())
995
+ valadded.reverse()
996
+ if self._list is None:
997
+ L = None
998
+ else:
999
+ L = self._list[:(n + 1)] + [self.base_ring()(0)] * (n - self.prec_degree())
1000
+ L.reverse()
1001
+ return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly.parent()(zzlist), self._valbase, relprec, self._normalized, valadded, L), construct=True)
1002
+
1003
+ def rescale(self, a):
1004
+ r"""
1005
+ Return `f(a\cdot x)`.
1006
+
1007
+ .. TODO::
1008
+
1009
+ Need to write this function for integer polynomials before
1010
+ this works.
1011
+
1012
+ EXAMPLES::
1013
+
1014
+ sage: K = Zp(13, 5)
1015
+ sage: R.<t> = K[]
1016
+ sage: f = t^3 + K(13, 3) * t
1017
+ sage: f.rescale(2) # not implemented
1018
+ """
1019
+ negval = False
1020
+ try:
1021
+ a = self.base_ring()(a)
1022
+ except ValueError as msg:
1023
+ if msg == "element has negative valuation.":
1024
+ negval = True
1025
+ else:
1026
+ raise ValueError(msg)
1027
+ if negval:
1028
+ return self.parent().base_extend(self.base_ring().fraction_field())(self).rescale(a)
1029
+ if self.base_ring().is_field() and a.valuation() < 0:
1030
+ D = self.prec_degree()
1031
+ return a**D * self.reverse(D).rescale(~a).reverse(D)
1032
+ aval = a.valuation()
1033
+ arprec = a.precision_relative()
1034
+ if self._valaddeds is None:
1035
+ self._comp_valaddeds()
1036
+ valadded = [self._valaddeds[i] + aval * i for i in range(len(self._valaddeds))]
1037
+ relprec = [infinity if (self._relprecs[i] is infinity) else (min(self._relprecs[i] - self._valaddeds[i], arprec) + aval * i + self._valaddeds[i]) for i in range(len(self._relprecs))]
1038
+ relprec[0] = self._relprecs[0]
1039
+ if a == 0:
1040
+ zzpoly = self._poly.parent()(0)
1041
+ else:
1042
+ zzpoly = self._poly.rescale(Integer(a))
1043
+ return Polynomial_padic_capped_relative_dense(self.parent(), (zzpoly, self._valbase, relprec, False, valadded, None), construct=True)
1044
+
1045
+ def quo_rem(self, right, secure=False):
1046
+ """
1047
+ Return the quotient and remainder in division of ``self`` by ``right``.
1048
+
1049
+ EXAMPLES::
1050
+
1051
+ sage: K = Qp(3,10)
1052
+ sage: R.<T> = K[]
1053
+ sage: f = T + 2
1054
+ sage: g = T**4 + 3*T+22
1055
+ sage: g.quo_rem(f)
1056
+ ((1 + O(3^10))*T^3 + (1 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + O(3^10))*T^2 + (1 + 3 + O(3^10))*T + 1 + 3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + O(3^10),
1057
+ 2 + 3 + 3^3 + O(3^10))
1058
+
1059
+ TESTS:
1060
+
1061
+ Verify that :issue:`15188` has been resolved::
1062
+
1063
+ sage: R.<x> = Qp(3)[]
1064
+ sage: x.quo_rem(x)
1065
+ (1 + O(3^20), 0)
1066
+ """
1067
+ return self._quo_rem_list(right, secure=secure)
1068
+
1069
+ def _quo_rem_naive(self, right):
1070
+ """
1071
+ An implementation of quo_rem that does not have good run-time
1072
+ or precision characteristics.
1073
+
1074
+ A better one is :meth:`_quo_rem_list`.
1075
+ """
1076
+ K = self.base_ring().fraction_field()
1077
+ f = self.base_extend(K)
1078
+ g = right.base_extend(K)
1079
+ if g == 0:
1080
+ raise ZeroDivisionError("cannot divide by a polynomial "
1081
+ "indistinguishable from 0")
1082
+ x = f.parent().gen()
1083
+ quo = f.parent()(0)
1084
+ while f.degree() >= g.degree():
1085
+ a = f.leading_coefficient() / g.leading_coefficient()
1086
+ quo = quo + a * (x ** (f.degree() - g.degree()))
1087
+ f = f - a * (x ** (f.degree() - g.degree())) * g
1088
+ return (quo, f)
1089
+
1090
+ def _quo_rem_list(self, right, secure):
1091
+ """
1092
+ An implementation of :meth:`quo_rem` using lists of coefficients.
1093
+
1094
+ Faster than :meth:`_quo_rem_naive`.
1095
+
1096
+ AUTHOR:
1097
+
1098
+ - Xavier Caruso (2013-03)
1099
+ """
1100
+ if right.is_zero():
1101
+ raise ZeroDivisionError("cannot divide by a polynomial "
1102
+ "indistinguishable from 0")
1103
+ a = self.list()
1104
+ da = len(a) - 1
1105
+ b = right.list()
1106
+ db = right.degree(secure=secure)
1107
+ inv = ~b[db]
1108
+ q = []
1109
+ for i in range(da, db - 1, -1):
1110
+ c = inv * a[i]
1111
+ q.append(c)
1112
+ for j in range(db):
1113
+ a[j + i - db] -= c * b[j]
1114
+ q.reverse()
1115
+ K = self.base_ring().fraction_field()
1116
+ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
1117
+ parent = PolynomialRing(K, name=self.parent().variable_name())
1118
+ return parent(q), parent(a[:db])
1119
+
1120
+ # def gcd(self, right):
1121
+ # raise NotImplementedError
1122
+
1123
+ # def lcm(self, right):
1124
+ # raise NotImplementedError
1125
+
1126
+ # def discriminant(self):
1127
+ # raise NotImplementedError
1128
+
1129
+ def disc(self):
1130
+ return self.discriminant()
1131
+
1132
+ # def resultant(self):
1133
+ # raise NotImplementedError
1134
+
1135
+ def newton_polygon(self):
1136
+ r"""
1137
+ Return the Newton polygon of this polynomial.
1138
+
1139
+ .. NOTE::
1140
+
1141
+ If some coefficients have not enough precision an error is raised.
1142
+
1143
+ OUTPUT: a :class:`NewtonPolygon`
1144
+
1145
+ EXAMPLES::
1146
+
1147
+ sage: K = Qp(2, prec=5)
1148
+ sage: P.<x> = K[]
1149
+ sage: f = x^4 + 2^3*x^3 + 2^13*x^2 + 2^21*x + 2^37
1150
+ sage: f.newton_polygon() # needs sage.geometry.polyhedron
1151
+ Finite Newton polygon with 4 vertices: (0, 37), (1, 21), (3, 3), (4, 0)
1152
+
1153
+ sage: K = Qp(5)
1154
+ sage: R.<t> = K[]
1155
+ sage: f = 5 + 3*t + t^4 + 25*t^10
1156
+ sage: f.newton_polygon() # needs sage.geometry.polyhedron
1157
+ Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2)
1158
+
1159
+ Here is an example where the computation fails because precision is
1160
+ not sufficient::
1161
+
1162
+ sage: g = f + K(0,0)*t^4; g
1163
+ (5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21)
1164
+ sage: g.newton_polygon() # needs sage.geometry.polyhedron
1165
+ Traceback (most recent call last):
1166
+ ...
1167
+ PrecisionError: The coefficient of t^4 has not enough precision
1168
+
1169
+ TESTS::
1170
+
1171
+ sage: (5*f).newton_polygon() # needs sage.geometry.polyhedron
1172
+ Finite Newton polygon with 4 vertices: (0, 2), (1, 1), (4, 1), (10, 3)
1173
+
1174
+ AUTHOR:
1175
+
1176
+ - Xavier Caruso (2013-03-20)
1177
+ """
1178
+ if self._valaddeds is None:
1179
+ self._comp_valaddeds()
1180
+ from sage.geometry.newton_polygon import NewtonPolygon
1181
+ valbase = self._valbase
1182
+ polygon = NewtonPolygon([(x, val + valbase)
1183
+ for x, val in enumerate(self._valaddeds)])
1184
+ polygon_prec = NewtonPolygon([(x, val + valbase)
1185
+ for x, val in enumerate(self._relprecs)])
1186
+ vertices = polygon.vertices(copy=False)
1187
+ vertices_prec = polygon_prec.vertices(copy=False)
1188
+
1189
+ # The two following tests should always fail (i.e. the corresponding errors
1190
+ # should never be raised). However, it's probably safer to keep them.
1191
+ if vertices[0][0] > vertices_prec[0][0]:
1192
+ raise PrecisionError("The constant coefficient has not enough precision")
1193
+ if vertices[-1][0] < vertices_prec[-1][0]:
1194
+ raise PrecisionError("The leading coefficient has not enough precision")
1195
+
1196
+ for (x, y) in vertices:
1197
+ if polygon_prec(x) <= y:
1198
+ raise PrecisionError("The coefficient of %s^%s has not enough precision" % (self.parent().variable_name(), x))
1199
+ return polygon
1200
+
1201
+ def is_eisenstein(self, secure=False):
1202
+ """
1203
+ Return ``True`` if this polynomial is an Eisenstein polynomial.
1204
+
1205
+ EXAMPLES::
1206
+
1207
+ sage: K = Qp(5)
1208
+ sage: R.<t> = K[]
1209
+ sage: f = 5 + 5*t + t^4
1210
+ sage: f.is_eisenstein()
1211
+ True
1212
+
1213
+ TESTS::
1214
+
1215
+ sage: f = R([K(5,1),0,0,1]); f
1216
+ (1 + O(5^20))*t^3 + O(5)
1217
+ sage: f.is_eisenstein()
1218
+ Traceback (most recent call last):
1219
+ ...
1220
+ PrecisionError: Not enough precision on the constant coefficient
1221
+
1222
+ sage: g = R([5,K(0,0),0,1]); g
1223
+ (1 + O(5^20))*t^3 + O(5^0)*t + 5 + O(5^21)
1224
+ sage: g.is_eisenstein()
1225
+ True
1226
+ sage: g.is_eisenstein(secure=True)
1227
+ Traceback (most recent call last):
1228
+ ...
1229
+ PrecisionError: Not enough precision on the coefficient of t
1230
+
1231
+ AUTHOR:
1232
+
1233
+ - Xavier Caruso (2013-03)
1234
+ """
1235
+ deg = self.degree()
1236
+ if secure and self.prec_degree() > deg:
1237
+ raise PrecisionError("The degree of the polynomial is not determined")
1238
+ if self._valaddeds is None:
1239
+ self._comp_valaddeds()
1240
+ compval = 1 - self._valbase
1241
+ valaddeds = self._valaddeds
1242
+ relprecs = self._relprecs
1243
+ if relprecs[0] <= compval: # not enough precision
1244
+ if valaddeds[0] < relprecs[0]:
1245
+ return False
1246
+ raise PrecisionError("Not enough precision on the constant coefficient")
1247
+ else:
1248
+ if valaddeds[0] != compval:
1249
+ return False
1250
+ for i in range(1, deg):
1251
+ if relprecs[i] < compval: # not enough precision
1252
+ if valaddeds[i] < relprecs[i]:
1253
+ return False
1254
+ if secure:
1255
+ if i == 1:
1256
+ raise PrecisionError("Not enough precision on the coefficient of %s" % self.variable_name())
1257
+ else:
1258
+ raise PrecisionError("Not enough precision on the coefficient of %s^%s" % (self.variable_name(), i))
1259
+ else:
1260
+ if valaddeds[i] < compval:
1261
+ return False
1262
+ if valaddeds[deg] != -self._valbase:
1263
+ return False
1264
+ return True
1265
+
1266
+ def newton_slopes(self, repetition=True):
1267
+ """
1268
+ Return a list of the Newton slopes of this polynomial.
1269
+
1270
+ These are the valuations of the roots of this polynomial.
1271
+
1272
+ If ``repetition`` is ``True``, each slope is repeated a number of
1273
+ times equal to its multiplicity. Otherwise it appears only one time.
1274
+
1275
+ INPUT:
1276
+
1277
+ - ``repetition`` -- boolean (default: ``True``)
1278
+
1279
+ OUTPUT: list of rationals
1280
+
1281
+ EXAMPLES::
1282
+
1283
+ sage: K = Qp(5)
1284
+ sage: R.<t> = K[]
1285
+ sage: f = 5 + 3*t + t^4 + 25*t^10
1286
+ sage: f.newton_polygon() # needs sage.geometry.polyhedron
1287
+ Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0),
1288
+ (10, 2)
1289
+ sage: f.newton_slopes() # needs sage.geometry.polyhedron
1290
+ [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
1291
+
1292
+ sage: f.newton_slopes(repetition=False) # needs sage.geometry.polyhedron
1293
+ [1, 0, -1/3]
1294
+
1295
+ AUTHOR:
1296
+
1297
+ - Xavier Caruso (2013-03-20)
1298
+ """
1299
+ polygon = self.newton_polygon()
1300
+ return [-s for s in polygon.slopes(repetition=repetition)]
1301
+
1302
+ def factor_mod(self):
1303
+ r"""
1304
+ Return the factorization of ``self`` modulo `p`.
1305
+ """
1306
+ self._normalize()
1307
+ if self._valbase < 0:
1308
+ raise ValueError("Polynomial does not have integral coefficients")
1309
+ elif self._valbase > 0:
1310
+ raise ValueError("Factorization of the zero polynomial not defined")
1311
+ elif min(self._relprecs) <= 0:
1312
+ raise PrecisionError("Polynomial is not known to high enough precision")
1313
+ return self._poly.factor_mod(self.base_ring().prime())
1314
+
1315
+
1316
+ def _extend_by_infinity(L, n):
1317
+ return L + [infinity] * (n - len(L))
1318
+
1319
+
1320
+ def make_padic_poly(parent, x, version):
1321
+ if version == 0:
1322
+ return parent(x, construct=True)
1323
+ else:
1324
+ raise ValueError("unknown pickling version")