passagemath-ntl 10.6.36__cp314-cp314t-manylinux_2_24_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 (161) hide show
  1. passagemath_ntl-10.6.36.dist-info/METADATA +122 -0
  2. passagemath_ntl-10.6.36.dist-info/RECORD +161 -0
  3. passagemath_ntl-10.6.36.dist-info/WHEEL +6 -0
  4. passagemath_ntl-10.6.36.dist-info/top_level.txt +2 -0
  5. passagemath_ntl.libs/libgf2x-fbd36f80.so.3.0.0 +0 -0
  6. passagemath_ntl.libs/libgmp-93ebf16a.so.10.5.0 +0 -0
  7. passagemath_ntl.libs/libmpfi-ad12a86d.so.0.0.0 +0 -0
  8. passagemath_ntl.libs/libmpfr-9d41ebf1.so.6.2.1 +0 -0
  9. passagemath_ntl.libs/libntl-0043a3a2.so.44.0.1 +0 -0
  10. sage/all__sagemath_ntl.py +7 -0
  11. sage/libs/all__sagemath_ntl.py +3 -0
  12. sage/libs/mpfi/__init__.pxd +287 -0
  13. sage/libs/mpfi/types.pxd +10 -0
  14. sage/libs/ntl/GF2.pxd +18 -0
  15. sage/libs/ntl/GF2E.pxd +28 -0
  16. sage/libs/ntl/GF2EX.pxd +12 -0
  17. sage/libs/ntl/GF2X.pxd +81 -0
  18. sage/libs/ntl/ZZ.pxd +93 -0
  19. sage/libs/ntl/ZZX.pxd +85 -0
  20. sage/libs/ntl/ZZ_p.pxd +28 -0
  21. sage/libs/ntl/ZZ_pE.pxd +37 -0
  22. sage/libs/ntl/ZZ_pEX.pxd +106 -0
  23. sage/libs/ntl/ZZ_pX.pxd +122 -0
  24. sage/libs/ntl/__init__.py +4 -0
  25. sage/libs/ntl/all.py +72 -0
  26. sage/libs/ntl/conversion.pxd +106 -0
  27. sage/libs/ntl/convert.cpython-314t-aarch64-linux-gnu.so +0 -0
  28. sage/libs/ntl/convert.pxd +7 -0
  29. sage/libs/ntl/convert.pyx +38 -0
  30. sage/libs/ntl/decl.pxi +18 -0
  31. sage/libs/ntl/error.cpython-314t-aarch64-linux-gnu.so +0 -0
  32. sage/libs/ntl/error.pyx +63 -0
  33. sage/libs/ntl/lzz_p.pxd +20 -0
  34. sage/libs/ntl/lzz_pX.pxd +59 -0
  35. sage/libs/ntl/mat_GF2.pxd +30 -0
  36. sage/libs/ntl/mat_GF2E.pxd +30 -0
  37. sage/libs/ntl/mat_ZZ.pxd +59 -0
  38. sage/libs/ntl/misc.pxi +33 -0
  39. sage/libs/ntl/ntl_GF2.cpython-314t-aarch64-linux-gnu.so +0 -0
  40. sage/libs/ntl/ntl_GF2.pxd +5 -0
  41. sage/libs/ntl/ntl_GF2.pyx +281 -0
  42. sage/libs/ntl/ntl_GF2E.cpython-314t-aarch64-linux-gnu.so +0 -0
  43. sage/libs/ntl/ntl_GF2E.pxd +8 -0
  44. sage/libs/ntl/ntl_GF2E.pyx +488 -0
  45. sage/libs/ntl/ntl_GF2EContext.cpython-314t-aarch64-linux-gnu.so +0 -0
  46. sage/libs/ntl/ntl_GF2EContext.pxd +9 -0
  47. sage/libs/ntl/ntl_GF2EContext.pyx +134 -0
  48. sage/libs/ntl/ntl_GF2EX.cpython-314t-aarch64-linux-gnu.so +0 -0
  49. sage/libs/ntl/ntl_GF2EX.pxd +10 -0
  50. sage/libs/ntl/ntl_GF2EX.pyx +251 -0
  51. sage/libs/ntl/ntl_GF2X.cpython-314t-aarch64-linux-gnu.so +0 -0
  52. sage/libs/ntl/ntl_GF2X.pxd +5 -0
  53. sage/libs/ntl/ntl_GF2X.pyx +771 -0
  54. sage/libs/ntl/ntl_GF2X_linkage.pxi +404 -0
  55. sage/libs/ntl/ntl_ZZ.cpython-314t-aarch64-linux-gnu.so +0 -0
  56. sage/libs/ntl/ntl_ZZ.pxd +7 -0
  57. sage/libs/ntl/ntl_ZZ.pyx +541 -0
  58. sage/libs/ntl/ntl_ZZX.cpython-314t-aarch64-linux-gnu.so +0 -0
  59. sage/libs/ntl/ntl_ZZX.pxd +7 -0
  60. sage/libs/ntl/ntl_ZZX.pyx +1206 -0
  61. sage/libs/ntl/ntl_ZZ_p.cpython-314t-aarch64-linux-gnu.so +0 -0
  62. sage/libs/ntl/ntl_ZZ_p.pxd +10 -0
  63. sage/libs/ntl/ntl_ZZ_p.pyx +509 -0
  64. sage/libs/ntl/ntl_ZZ_pContext.cpython-314t-aarch64-linux-gnu.so +0 -0
  65. sage/libs/ntl/ntl_ZZ_pContext.pxd +22 -0
  66. sage/libs/ntl/ntl_ZZ_pContext.pyx +201 -0
  67. sage/libs/ntl/ntl_ZZ_pE.cpython-314t-aarch64-linux-gnu.so +0 -0
  68. sage/libs/ntl/ntl_ZZ_pE.pxd +11 -0
  69. sage/libs/ntl/ntl_ZZ_pE.pyx +349 -0
  70. sage/libs/ntl/ntl_ZZ_pEContext.cpython-314t-aarch64-linux-gnu.so +0 -0
  71. sage/libs/ntl/ntl_ZZ_pEContext.pxd +23 -0
  72. sage/libs/ntl/ntl_ZZ_pEContext.pyx +226 -0
  73. sage/libs/ntl/ntl_ZZ_pEX.cpython-314t-aarch64-linux-gnu.so +0 -0
  74. sage/libs/ntl/ntl_ZZ_pEX.pxd +10 -0
  75. sage/libs/ntl/ntl_ZZ_pEX.pyx +1255 -0
  76. sage/libs/ntl/ntl_ZZ_pEX_linkage.pxi +420 -0
  77. sage/libs/ntl/ntl_ZZ_pX.cpython-314t-aarch64-linux-gnu.so +0 -0
  78. sage/libs/ntl/ntl_ZZ_pX.pxd +17 -0
  79. sage/libs/ntl/ntl_ZZ_pX.pyx +1532 -0
  80. sage/libs/ntl/ntl_lzz_p.cpython-314t-aarch64-linux-gnu.so +0 -0
  81. sage/libs/ntl/ntl_lzz_p.pxd +8 -0
  82. sage/libs/ntl/ntl_lzz_p.pyx +440 -0
  83. sage/libs/ntl/ntl_lzz_pContext.cpython-314t-aarch64-linux-gnu.so +0 -0
  84. sage/libs/ntl/ntl_lzz_pContext.pxd +7 -0
  85. sage/libs/ntl/ntl_lzz_pContext.pyx +137 -0
  86. sage/libs/ntl/ntl_lzz_pX.cpython-314t-aarch64-linux-gnu.so +0 -0
  87. sage/libs/ntl/ntl_lzz_pX.pxd +10 -0
  88. sage/libs/ntl/ntl_lzz_pX.pyx +902 -0
  89. sage/libs/ntl/ntl_mat_GF2.cpython-314t-aarch64-linux-gnu.so +0 -0
  90. sage/libs/ntl/ntl_mat_GF2.pxd +8 -0
  91. sage/libs/ntl/ntl_mat_GF2.pyx +612 -0
  92. sage/libs/ntl/ntl_mat_GF2E.cpython-314t-aarch64-linux-gnu.so +0 -0
  93. sage/libs/ntl/ntl_mat_GF2E.pxd +10 -0
  94. sage/libs/ntl/ntl_mat_GF2E.pyx +752 -0
  95. sage/libs/ntl/ntl_mat_ZZ.cpython-314t-aarch64-linux-gnu.so +0 -0
  96. sage/libs/ntl/ntl_mat_ZZ.pxd +6 -0
  97. sage/libs/ntl/ntl_mat_ZZ.pyx +1523 -0
  98. sage/libs/ntl/ntl_tools.pxd +3 -0
  99. sage/libs/ntl/ntlwrap.h +53 -0
  100. sage/libs/ntl/ntlwrap_impl.h +743 -0
  101. sage/libs/ntl/types.pxd +157 -0
  102. sage/libs/ntl/vec_GF2.pxd +26 -0
  103. sage/libs/ntl/vec_GF2E.pxd +2 -0
  104. sage/matrix/all__sagemath_ntl.py +1 -0
  105. sage/matrix/matrix_modn_dense_double.pxd +10 -0
  106. sage/matrix/matrix_modn_dense_float.pxd +9 -0
  107. sage/matrix/matrix_modn_dense_template.pxi +3257 -0
  108. sage/matrix/matrix_modn_dense_template_header.pxi +15 -0
  109. sage/matrix/matrix_modn_sparse.pxd +8 -0
  110. sage/misc/all__sagemath_ntl.py +1 -0
  111. sage/rings/all__sagemath_ntl.py +7 -0
  112. sage/rings/bernmm.cpython-314t-aarch64-linux-gnu.so +0 -0
  113. sage/rings/bernmm.pyx +161 -0
  114. sage/rings/bernoulli_mod_p.cpython-314t-aarch64-linux-gnu.so +0 -0
  115. sage/rings/bernoulli_mod_p.pyx +313 -0
  116. sage/rings/finite_rings/all__sagemath_ntl.py +1 -0
  117. sage/rings/finite_rings/finite_field_ntl_gf2e.py +305 -0
  118. sage/rings/finite_rings/residue_field_ntl_gf2e.cpython-314t-aarch64-linux-gnu.so +0 -0
  119. sage/rings/finite_rings/residue_field_ntl_gf2e.pyx +140 -0
  120. sage/rings/padics/all__sagemath_ntl.py +5 -0
  121. sage/rings/padics/padic_ZZ_pX_CA_element.cpython-314t-aarch64-linux-gnu.so +0 -0
  122. sage/rings/padics/padic_ZZ_pX_CA_element.pxd +25 -0
  123. sage/rings/padics/padic_ZZ_pX_CA_element.pyx +2368 -0
  124. sage/rings/padics/padic_ZZ_pX_CR_element.cpython-314t-aarch64-linux-gnu.so +0 -0
  125. sage/rings/padics/padic_ZZ_pX_CR_element.pxd +33 -0
  126. sage/rings/padics/padic_ZZ_pX_CR_element.pyx +3277 -0
  127. sage/rings/padics/padic_ZZ_pX_FM_element.cpython-314t-aarch64-linux-gnu.so +0 -0
  128. sage/rings/padics/padic_ZZ_pX_FM_element.pxd +12 -0
  129. sage/rings/padics/padic_ZZ_pX_FM_element.pyx +1739 -0
  130. sage/rings/padics/padic_ZZ_pX_element.cpython-314t-aarch64-linux-gnu.so +0 -0
  131. sage/rings/padics/padic_ZZ_pX_element.pxd +6 -0
  132. sage/rings/padics/padic_ZZ_pX_element.pyx +919 -0
  133. sage/rings/padics/padic_ext_element.cpython-314t-aarch64-linux-gnu.so +0 -0
  134. sage/rings/padics/padic_ext_element.pxd +38 -0
  135. sage/rings/padics/padic_ext_element.pyx +512 -0
  136. sage/rings/padics/pow_computer_ext.cpython-314t-aarch64-linux-gnu.so +0 -0
  137. sage/rings/padics/pow_computer_ext.pxd +107 -0
  138. sage/rings/padics/pow_computer_ext.pyx +2401 -0
  139. sage/rings/polynomial/all__sagemath_ntl.py +1 -0
  140. sage/rings/polynomial/evaluation_ntl.cpython-314t-aarch64-linux-gnu.so +0 -0
  141. sage/rings/polynomial/evaluation_ntl.pxd +7 -0
  142. sage/rings/polynomial/evaluation_ntl.pyx +70 -0
  143. sage/rings/polynomial/polynomial_gf2x.cpython-314t-aarch64-linux-gnu.so +0 -0
  144. sage/rings/polynomial/polynomial_gf2x.pxd +10 -0
  145. sage/rings/polynomial/polynomial_gf2x.pyx +364 -0
  146. sage/rings/polynomial/polynomial_integer_dense_ntl.cpython-314t-aarch64-linux-gnu.so +0 -0
  147. sage/rings/polynomial/polynomial_integer_dense_ntl.pxd +8 -0
  148. sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +1128 -0
  149. sage/rings/polynomial/polynomial_modn_dense_ntl.cpython-314t-aarch64-linux-gnu.so +0 -0
  150. sage/rings/polynomial/polynomial_modn_dense_ntl.pxd +36 -0
  151. sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +2049 -0
  152. sage/rings/polynomial/polynomial_template.pxi +842 -0
  153. sage/rings/polynomial/polynomial_template_header.pxi +11 -0
  154. sage/rings/polynomial/polynomial_zz_pex.cpython-314t-aarch64-linux-gnu.so +0 -0
  155. sage/rings/polynomial/polynomial_zz_pex.pxd +12 -0
  156. sage/rings/polynomial/polynomial_zz_pex.pyx +778 -0
  157. sage/rings/real_mpfi.pxd +50 -0
  158. sage/schemes/all__sagemath_ntl.py +1 -0
  159. sage/schemes/hyperelliptic_curves/all__sagemath_ntl.py +1 -0
  160. sage/schemes/hyperelliptic_curves/hypellfrob.cpython-314t-aarch64-linux-gnu.so +0 -0
  161. sage/schemes/hyperelliptic_curves/hypellfrob.pyx +252 -0
@@ -0,0 +1,919 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ # distutils: libraries = NTL_LIBRARIES gmp M_LIBRARIES
3
+ # distutils: extra_compile_args = NTL_CFLAGS
4
+ # distutils: include_dirs = NTL_INCDIR
5
+ # distutils: library_dirs = NTL_LIBDIR
6
+ # distutils: extra_link_args = NTL_LIBEXTRA
7
+ # distutils: language = c++
8
+ # sage.doctest: needs sage.rings.padics
9
+ r"""
10
+ `p`-adic ``ZZ_pX Element``
11
+
12
+ A common superclass implementing features shared by all elements that
13
+ use NTL's ``ZZ_pX`` as the fundamental data type.
14
+
15
+ AUTHORS:
16
+
17
+ - David Roe
18
+ """
19
+
20
+ #*****************************************************************************
21
+ # Copyright (C) 2008 David Roe <roed.math@gmail.com>
22
+ # William Stein <wstein@gmail.com>
23
+ #
24
+ # Distributed under the terms of the GNU General Public License (GPL)
25
+ # as published by the Free Software Foundation; either version 2 of
26
+ # the License, or (at your option) any later version.
27
+ #
28
+ # http://www.gnu.org/licenses/
29
+ #*****************************************************************************
30
+
31
+ from sage.ext.stdsage cimport PY_NEW
32
+ from cpython.list cimport *
33
+ include "sage/libs/ntl/decl.pxi"
34
+
35
+ from sage.libs.gmp.mpz cimport *
36
+ from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ
37
+ from sage.libs.ntl.ntl_ZZ_p cimport ntl_ZZ_p
38
+ from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX
39
+ from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX
40
+ from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class
41
+ from sage.libs.ntl.ntl_ZZ_pContext import ntl_ZZ_pContext
42
+ from sage.rings.integer cimport Integer
43
+ from sage.rings.rational cimport Rational
44
+ from sage.rings.padics.padic_generic_element cimport pAdicGenericElement
45
+ from sage.rings.finite_rings.integer_mod import IntegerMod_abstract
46
+ from sage.rings.padics.padic_printing cimport pAdicPrinter_class
47
+ from sage.rings.padics.pow_computer_ext cimport PowComputer_ext
48
+ from sage.rings.rational_field import QQ
49
+
50
+ zero = Integer(0)
51
+ one = Integer(1)
52
+ two = Integer(2)
53
+ big = two**128 + one
54
+ #this should not fit in a long, since it's supposed to be bigger than any valid absolute precision.
55
+
56
+ cdef class pAdicZZpXElement(pAdicExtElement):
57
+ def __init__(self, parent):
58
+ """
59
+ Initialization.
60
+
61
+ EXAMPLES::
62
+
63
+ sage: A = Zp(next_prime(50000),10)
64
+ sage: S.<x> = A[]
65
+ sage: B.<t> = A.ext(x^2 + next_prime(50000)) # indirect doctest
66
+ """
67
+ self.prime_pow = <PowComputer_ZZ_pX>parent.prime_pow
68
+ pAdicExtElement.__init__(self, parent)
69
+
70
+ cdef int _set_from_list(self, L) except -1:
71
+ """
72
+ Set ``self`` from a list.
73
+
74
+ The list can contain integers, ``IntegerMods``, rationals, or
75
+ `p`-adic base elements
76
+
77
+ INPUT:
78
+
79
+ - ``L`` -- list
80
+
81
+ EXAMPLES::
82
+
83
+ sage: R = ZpFM(5,5)
84
+ sage: S.<x> = ZZ[]
85
+ sage: W.<w> = R.ext(x^5 + 25*x^3 - 15*x - 5)
86
+ sage: W([1,2,3,4]) # indirect doctest
87
+ 1 + 2*w + 3*w^2 + 4*w^3
88
+ sage: W([5,10,15,20])
89
+ w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + w^16 + 2*w^17 + 2*w^18 + w^19 + 4*w^20 + w^21 + 4*w^22 + 4*w^23 + 2*w^24
90
+ """
91
+ cdef ntl_ZZ_pContext_class ctx
92
+ L, min_val, ctx = preprocess_list(self, L)
93
+ if ctx is None:
94
+ self._set_from_ZZX((<ntl_ZZX>ntl_ZZX(L)).x)
95
+ else:
96
+ self._set_from_ZZ_pX(&(<ntl_ZZ_pX>ntl_ZZ_pX(L, ctx)).x, ctx)
97
+ self._pshift_self(mpz_get_si((<Integer>min_val).value))
98
+
99
+ cdef int _set_from_list_rel(self, L, long relprec) except -1:
100
+ """
101
+ Set ``self`` from a list.
102
+
103
+ The list can contain integers, ``IntegerMods``, rationals, or
104
+ `p`-adic base elements
105
+
106
+ INPUT:
107
+
108
+ - ``L`` -- list
109
+
110
+ - ``relprec`` -- integer; capping the relative precision of ``self``
111
+
112
+ EXAMPLES::
113
+
114
+ sage: R = Zp(5,5)
115
+ sage: S.<x> = ZZ[]
116
+ sage: W.<w> = R.ext(x^5 + 25*x^3 - 15*x - 5)
117
+ sage: W([1,2,3,4]) # indirect doctest
118
+ 1 + 2*w + 3*w^2 + 4*w^3 + O(w^25)
119
+ sage: W([5,10,15,20], relprec=16)
120
+ w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + w^16 + 2*w^17 + 2*w^18 + w^19 + 4*w^20 + O(w^21)
121
+ """
122
+ cdef ntl_ZZ_pContext_class ctx
123
+ L, min_val, ctx = preprocess_list(self, L)
124
+ if ctx is None:
125
+ self._set_from_ZZX_rel((<ntl_ZZX>ntl_ZZX(L)).x, relprec)
126
+ else:
127
+ self._set_from_ZZ_pX_rel(&(<ntl_ZZ_pX>ntl_ZZ_pX(L, ctx)).x, ctx, relprec)
128
+ self._pshift_self(mpz_get_si((<Integer>min_val).value))
129
+
130
+ cdef int _set_from_list_abs(self, L, long absprec) except -1:
131
+ """
132
+ Set this element from a list.
133
+
134
+ INPUT:
135
+
136
+ - ``L`` -- list of integers, ``IntegerMod``s, rationals, or `p`-adic
137
+ base elements
138
+
139
+ - ``absprec`` -- integer at which the absolute precision of the
140
+ result will be capped
141
+
142
+ EXAMPLES::
143
+
144
+ sage: R = ZpCA(5,5)
145
+ sage: S.<x> = ZZ[]
146
+ sage: W.<w> = R.ext(x^5 + 25*x^3 - 15*x - 5)
147
+ sage: W([1,2,3,4])
148
+ 1 + 2*w + 3*w^2 + 4*w^3 + O(w^25)
149
+ sage: W([5,10,15,20], absprec=16) # indirect doctest
150
+ w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + O(w^16)
151
+ """
152
+ cdef ntl_ZZ_pContext_class ctx
153
+ L, min_val, ctx = preprocess_list(self, L)
154
+ if ctx is None:
155
+ self._set_from_ZZX_abs((<ntl_ZZX>ntl_ZZX(L)).x, absprec)
156
+ else:
157
+ self._set_from_ZZ_pX_abs(&(<ntl_ZZ_pX>ntl_ZZ_pX(L, ctx)).x, ctx, absprec - (min_val * self.parent().e()))
158
+ self._pshift_self(mpz_get_si((<Integer>min_val).value))
159
+
160
+ cdef int _set_from_list_both(self, L, long absprec, long relprec) except -1:
161
+ """
162
+ Set this element from a list.
163
+
164
+ The list can contain integers, ``IntegerMods``, rationals, or
165
+ `p`-adic base elements
166
+
167
+ INPUT:
168
+
169
+ - ``L`` -- list of integers, ``IntegerMod``s, rationals, or `p`-adic
170
+ base elements
171
+
172
+ - ``absprec`` -- integer at which the absolute precision of the result will be capped
173
+
174
+ - ``relprec`` -- integer at which the relative precision of the result will be capped
175
+
176
+ EXAMPLES::
177
+
178
+ sage: R = Zp(5,5)
179
+ sage: S.<x> = ZZ[]
180
+ sage: W.<w> = R.ext(x^5 + 25*x^3 - 15*x - 5)
181
+ sage: W([1,2,3,4])
182
+ 1 + 2*w + 3*w^2 + 4*w^3 + O(w^25)
183
+ sage: W([5,10,15,20], absprec=16) # indirect doctest
184
+ w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + O(w^16)
185
+ sage: T.<a> = Qp(5).extension(x^2 - 5)
186
+ sage: T([5^-2], absprec=-1)
187
+ a^-4 + O(a^-1)
188
+ sage: G.<g> = Qp(5).extension(x^2 - 5)
189
+ sage: G(a^-41)
190
+ g^-41 + O(g^-2)
191
+ """
192
+ cdef ntl_ZZ_pContext_class ctx
193
+ L, min_val, ctx = preprocess_list(self, L)
194
+ if ctx is None:
195
+ self._set_from_ZZX_both((<ntl_ZZX>ntl_ZZX(L)).x, absprec, relprec)
196
+ else:
197
+ self._set_from_ZZ_pX_both(&(<ntl_ZZ_pX>ntl_ZZ_pX(L, ctx)).x, ctx, absprec - (min_val * self.parent().e()), relprec)
198
+ self._pshift_self(mpz_get_si((<Integer>min_val).value))
199
+
200
+ cdef long _check_ZZ_pContext(self, ntl_ZZ_pContext_class ctx) except -1:
201
+ """
202
+ Check that the given ``ntl_ZZ_pContext`` is actually a power
203
+ of the relevant prime. If so, returns the exponent.
204
+
205
+ INPUT:
206
+
207
+ - ``ctx`` -- an ``ntl_ZZ_pContext_class``
208
+
209
+ OUTPUT:
210
+
211
+ - ``val`` -- if ``ctx`` is a context for `p^n`, returns `n`.
212
+ Otherwise, raises an error.
213
+
214
+ EXAMPLES::
215
+
216
+ sage: R = Zp(5,5)
217
+ sage: S.<x> = R[]
218
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
219
+ sage: W.<w> = R.ext(f)
220
+ sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest
221
+ 4 + w + w^2 + 3*w^7 + w^9 + O(w^10)
222
+ """
223
+ cdef ZZ_c leftover
224
+ cdef long val = ZZ_remove(leftover, ctx.p.x, self.prime_pow.pow_ZZ_tmp(1)[0])
225
+ if ZZ_IsOne(leftover):
226
+ return val
227
+ else:
228
+ raise ValueError("context must be a power of the appropriate prime")
229
+
230
+ cdef ext_p_list_precs(self, bint pos, long prec):
231
+ """
232
+ Return a list giving a series representation of ``self``.
233
+
234
+ - The returned list will consist of:
235
+
236
+ + integers (in the Eisenstein case) or
237
+
238
+ + lists of integers (in the unramified case).
239
+
240
+ - ``self`` can be reconstructed as
241
+
242
+ + a sum of elements of the list times powers of the
243
+ uniformiser (in the Eisenstein case), or
244
+
245
+ + as a sum of powers of the `p` times polynomials in the
246
+ generator (in the unramified case).
247
+
248
+ Note that zeros are truncated from the returned list, so you
249
+ must use the valuation() function to completely recover ``self``.
250
+
251
+ INPUT:
252
+
253
+ - ``pos`` -- bint; if ``True``, all integers will be in
254
+ the range `[0,p-1]`, otherwise they will be in the range
255
+ `[(1-p)/2, p/2]`
256
+
257
+ - ``prec`` -- how many terms to return in the list. This is
258
+ important since shifting in the Eisenstein case can
259
+ introduce random high order bits. Thus the process would
260
+ not otherwise necessarily terminate at the right point.
261
+
262
+ OUTPUT:
263
+
264
+ - ``L`` -- list of integers or list of lists giving the
265
+ series expansion of ``self``
266
+
267
+ EXAMPLES::
268
+
269
+ sage: R = Zp(5,5)
270
+ sage: S.<x> = R[]
271
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
272
+ sage: W.<w> = R.ext(f)
273
+ sage: y = W(775, 19); y
274
+ w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19)
275
+ sage: y._ext_p_list(True) # indirect doctest
276
+ [1, 0, 4, 0, 2, 1, 2, 4, 1]
277
+ sage: y._ext_p_list(False)
278
+ [1, 0, -1, 0, 2, 1, 2, 0, 1]
279
+ """
280
+ ans = []
281
+ cdef ntl_ZZ ZZ_coeff = ntl_ZZ()
282
+ cdef Integer coeff = PY_NEW(Integer)
283
+ cdef Integer zero = Integer(0)
284
+ cdef Integer list_elt
285
+ cdef ZZ_c halfp
286
+ cdef Py_ssize_t i, j
287
+ self.prime_pow.restore_top_context()
288
+ ###ZZ_p_construct(&const_term_holder)
289
+ cdef ntl_ZZ holder = ntl_ZZ()
290
+ cdef ZZ_p_c tmp
291
+ cdef pAdicPrinter_class printer = <pAdicPrinter_class>self.parent()._printer
292
+ cdef ZZ_pX_c shifter = (<ntl_ZZ_pX>self._ntl_rep()).x
293
+
294
+ #cdef ntl_ZZ_pContext_class cup = self.prime_pow.get_context(self.prime_pow.prec_cap + (<PowComputer_ZZ_pX_FM_Eis>self.prime_pow).low_length)
295
+ #cdef ntl_ZZ_pX printer = ntl_ZZ_pX([], cup)
296
+ #printer.x = ((<PowComputer_ZZ_pX_FM_Eis>self.prime_pow).low_shifter[0]).val()
297
+ #print(printer)
298
+
299
+ if self.prime_pow.e == 1:
300
+ for j from 0 <= j < self.prime_pow.prec_cap:
301
+ ans.append([])
302
+ for i from 0 <= i < self.prime_pow.deg:
303
+ ZZ_coeff.x = ZZ_p_rep(ZZ_pX_coeff(shifter, i))
304
+ ZZ_to_mpz(coeff.value, &ZZ_coeff.x)
305
+ L = printer.base_p_list(coeff, pos)
306
+ for j from 0 <= j < prec:
307
+ if j < len(L):
308
+ ans[j].append(L[j])
309
+ else:
310
+ ans[j].append(zero)
311
+ for j from 0 <= j < prec:
312
+ while ans[j]:
313
+ if ans[j][-1] == 0:
314
+ ans[j].pop()
315
+ else:
316
+ break
317
+ zerotest = []
318
+ else:
319
+ halfp = self.prime_pow.pow_ZZ_tmp(1)[0]
320
+ ZZ_DivRem_long(halfp, halfp, 2)
321
+ i = 0
322
+ while True:
323
+ # It's important that one doesn't normalize in between shifting (for capped relative elements):
324
+ # _const_term doesn't normalize and thus we pick up the zeros
325
+ # since we're throwing away leading zeros, it doesn't matter if we start normalized or not.
326
+ for j from 0 <= j < self.prime_pow.e:
327
+ list_elt = PY_NEW(Integer)
328
+ if i + j == prec:
329
+ break
330
+ ZZ_rem(holder.x, ZZ_p_rep(ZZ_pX_coeff(shifter, j)), self.prime_pow.pow_ZZ_tmp(1)[0])
331
+ if not pos and not ZZ_IsZero(holder.x) and ZZ_compare(holder.x, halfp) > 0:
332
+ ZZ_sub(holder.x, self.prime_pow.pow_ZZ_tmp(1)[0], holder.x)
333
+ ZZ_p_add(tmp, ZZ_to_ZZ_p(holder.x), ZZ_pX_coeff(shifter, j))
334
+ ZZ_pX_SetCoeff(shifter, j, tmp)
335
+ ZZ_negate(holder.x, holder.x)
336
+ ZZ_to_mpz(list_elt.value, &holder.x)
337
+ ans.append(list_elt)
338
+ i += self.prime_pow.e
339
+ if i >= prec:
340
+ break
341
+ self.prime_pow.eis_shift(&shifter, &shifter, self.prime_pow.e, self.prime_pow.capdiv(prec - i))
342
+ zerotest = 0
343
+ while ans:
344
+ if ans[-1] == zerotest:
345
+ ans.pop()
346
+ else:
347
+ break
348
+ while ans:
349
+ if ans[0] == zerotest:
350
+ ans.pop(0)
351
+ else:
352
+ break
353
+ return ans
354
+
355
+ def norm(self, base=None):
356
+ r"""
357
+ Return the absolute or relative norm of this element.
358
+
359
+ .. NOTE::
360
+
361
+ This is not the `p`-adic absolute value. This is a
362
+ field theoretic norm down to a ground ring. If you want the
363
+ `p`-adic absolute value, use the ``abs()`` function instead.
364
+
365
+ If ``base`` is given then ``base`` must be a subfield of the
366
+ parent `L` of ``self``, in which case the norm is the relative
367
+ norm from L to ``base``.
368
+
369
+ In all other cases, the norm is the absolute norm down to
370
+ `\QQ_p` or `\ZZ_p`.
371
+
372
+ EXAMPLES::
373
+
374
+ sage: R = ZpCR(5,5)
375
+ sage: S.<x> = R[]
376
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
377
+ sage: W.<w> = R.ext(f)
378
+ sage: ((1+2*w)^5).norm()
379
+ 1 + 5^2 + O(5^5)
380
+ sage: ((1+2*w)).norm()^5
381
+ 1 + 5^2 + O(5^5)
382
+
383
+ TESTS::
384
+
385
+ sage: R = ZpCA(5,5)
386
+ sage: S.<x> = ZZ[]
387
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
388
+ sage: W.<w> = R.ext(f)
389
+ sage: ((1+2*w)^5).norm() # needs sage.geometry.polyhedron
390
+ 1 + 5^2 + O(5^5)
391
+ sage: ((1+2*w)).norm()^5 # needs sage.geometry.polyhedron
392
+ 1 + 5^2 + O(5^5)
393
+ sage: R = ZpFM(5,5)
394
+ sage: S.<x> = ZZ[]
395
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
396
+ sage: W.<w> = R.ext(f)
397
+ sage: ((1+2*w)^5).norm() # needs sage.geometry.polyhedron
398
+ 1 + 5^2
399
+ sage: ((1+2*w)).norm()^5 # needs sage.geometry.polyhedron
400
+ 1 + 5^2
401
+
402
+ Check that :issue:`11586` has been resolved::
403
+
404
+ sage: R.<x> = QQ[]
405
+ sage: f = x^2 + 3*x + 1
406
+ sage: M.<a> = Qp(7).extension(f)
407
+ sage: M(7).norm()
408
+ 7^2 + O(7^22)
409
+ sage: b = 7*a + 35
410
+ sage: b.norm()
411
+ 4*7^2 + 7^3 + O(7^22)
412
+ sage: b*b.frobenius()
413
+ 4*7^2 + 7^3 + O(7^22)
414
+ """
415
+ if base is not None:
416
+ if base is self.parent():
417
+ return self
418
+ else:
419
+ raise NotImplementedError
420
+ if self._is_exact_zero():
421
+ return self.parent().ground_ring()(0)
422
+ elif self._is_inexact_zero():
423
+ return self.ground_ring(0, self.valuation())
424
+ if self.valuation() == 0:
425
+ return self.parent().ground_ring()(self.matrix_mod_pn().det())
426
+ else:
427
+ if self.parent().e() == 1:
428
+ norm_of_uniformizer = self.parent().ground_ring().uniformizer_pow(self.parent().degree())
429
+ else:
430
+ norm_of_uniformizer = (-1)**self.parent().degree() * self.parent().defining_polynomial()[0]
431
+ return self.parent().ground_ring()(self.unit_part().matrix_mod_pn().det()) * norm_of_uniformizer**self.valuation()
432
+
433
+ def trace(self, base=None):
434
+ r"""
435
+ Return the absolute or relative trace of this element.
436
+
437
+ If ``base`` is given then ``base`` must be a subfield of the
438
+ parent `L` of ``self``, in which case the norm is the relative
439
+ norm from `L` to ``base``.
440
+
441
+ In all other cases, the norm is the absolute norm down to
442
+ `\QQ_p` or `\ZZ_p`.
443
+
444
+ EXAMPLES::
445
+
446
+ sage: R = ZpCR(5,5)
447
+ sage: S.<x> = R[]
448
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
449
+ sage: W.<w> = R.ext(f)
450
+ sage: a = (2+3*w)^7
451
+ sage: b = (6+w^3)^5
452
+ sage: a.trace()
453
+ 3*5 + 2*5^2 + 3*5^3 + 2*5^4 + O(5^5)
454
+ sage: a.trace() + b.trace()
455
+ 4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5)
456
+ sage: (a+b).trace()
457
+ 4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5)
458
+
459
+ TESTS::
460
+
461
+ sage: # needs sage.geometry.polyhedron
462
+ sage: R = ZpCA(5,5)
463
+ sage: S.<x> = ZZ[]
464
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
465
+ sage: W.<w> = R.ext(f)
466
+ sage: a = (2+3*w)^7
467
+ sage: b = (6+w^3)^5
468
+ sage: a.trace()
469
+ 3*5 + 2*5^2 + 3*5^3 + 2*5^4 + O(5^5)
470
+ sage: a.trace() + b.trace()
471
+ 4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5)
472
+ sage: (a+b).trace()
473
+ 4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5)
474
+ sage: R = ZpFM(5,5)
475
+ sage: S.<x> = R[]
476
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
477
+ sage: W.<w> = R.ext(f)
478
+ sage: a = (2+3*w)^7
479
+ sage: b = (6+w^3)^5
480
+ sage: a.trace()
481
+ 3*5 + 2*5^2 + 3*5^3 + 2*5^4
482
+ sage: a.trace() + b.trace()
483
+ 4*5 + 5^2 + 5^3 + 2*5^4
484
+ sage: (a+b).trace()
485
+ 4*5 + 5^2 + 5^3 + 2*5^4
486
+
487
+ TESTS:
488
+
489
+ We check that :issue:`32072` is resolved::
490
+
491
+ sage: F = Qp(2)
492
+ sage: S.<x> = F[]
493
+ sage: L.<w> = F.ext(x^2 - 2)
494
+ sage: L(0, 20).trace()
495
+ O(2^10)
496
+ """
497
+ if base is not None:
498
+ if base is self.parent():
499
+ return self
500
+ else:
501
+ raise NotImplementedError
502
+ if self._is_exact_zero():
503
+ return self.parent().ground_ring()(0)
504
+ elif self._is_inexact_zero():
505
+ return self.parent().ground_ring()(0, (self.valuation() - 1) // self.parent().e() + 1)
506
+ if self.valuation() >= 0:
507
+ return self.parent().ground_ring()(self.matrix_mod_pn().trace())
508
+ else:
509
+ shift = -(self.valuation() // self.parent().e())
510
+ return self.parent().ground_ring()((self * self.parent().prime() ** shift).matrix_mod_pn().trace()) / self.parent().prime()**shift
511
+
512
+ def _rational_(self):
513
+ """
514
+ Return a rational approximation of ``self``.
515
+
516
+ This does not try to optimize which rational is picked: see
517
+ ``algebraic_dependency`` for another option.
518
+
519
+ EXAMPLES::
520
+
521
+ sage: QQ(Qq(125,names='a')(-1/5)) # indirect doctest
522
+ -1/5
523
+ """
524
+ if self.valuation() < 0:
525
+ pk = self.parent().prime()**(-self.ordp()).ceil()
526
+ return (self * pk)._integer_() / pk
527
+ else:
528
+ return QQ(self._integer_())
529
+
530
+ def _prime_pow(self):
531
+ """
532
+ Provides access to ``self``'s ``prime_pow``.
533
+
534
+ EXAMPLES::
535
+
536
+ sage: R = ZpCR(5,5)
537
+ sage: S.<x> = R[]
538
+ sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5
539
+ sage: W.<w> = R.ext(f)
540
+ sage: w._prime_pow()
541
+ PowComputer_ext for 5, with polynomial [3120 125 3110 75 0 1]
542
+ """
543
+ return self.prime_pow
544
+
545
+ cdef int _pshift_self(self, long shift) except -1:
546
+ """
547
+ Multiply this element by ``p^shift``.
548
+
549
+ TESTS:
550
+
551
+ Check that :issue:`13647` has been fixed::
552
+
553
+ sage: # needs sage.libs.flint
554
+ sage: K = ZpCA(3)
555
+ sage: R.<u> = K[]
556
+ sage: L.<u> = K.extension(u^2 + 1)
557
+ sage: L(R.gen())
558
+ u + O(3^20)
559
+ sage: K = ZpFM(3)
560
+ sage: R.<u> = K[]
561
+ sage: L.<u> = K.extension(u^2 + 1)
562
+ sage: L(R.gen())
563
+ u
564
+ """
565
+ if shift != 0:
566
+ raise NotImplementedError
567
+
568
+
569
+ def _test_preprocess_list(R, L):
570
+ r"""
571
+ Given a list of elements convertible to ``ntl_ZZ_p``s, find the
572
+ appropriate absolute precision and return a list of either
573
+ ``ntl_ZZs`` or ``ntl_ZZ_ps``.
574
+
575
+ INPUT:
576
+
577
+ - ``R`` -- a `p`-adic extension ring
578
+
579
+ - ``L`` -- list of rationals, integers, ints, longs,
580
+ ``ntl_ZZ_ps``, ``ntl_ZZs``, ``IntegerMods`` or `p`-adic base
581
+ elements
582
+
583
+ OUTPUT:
584
+
585
+ - ``LL`` -- if all inputs are integral, a list of ``ntl_ZZs``;
586
+ otherwise, a list of ``ntl_ZZ_ps``, modulo `p^n` which is
587
+ determined by the precision cap of ``R`` and the precisions of
588
+ the elements in ``L``
589
+
590
+ - ``min_val`` -- a valuation by which to multiply the elements of
591
+ ``LL`` in order to recover the input elements of ``L``
592
+
593
+ - ``ctx`` -- an ``ntl_ZZ_p_Context`` giving the power of `p`
594
+ modulo which the elements in ``LL`` are defined; if ``None``,
595
+ then the elements of ``LL`` are ``ntl_ZZs``.
596
+
597
+ EXAMPLES::
598
+
599
+ sage: from sage.rings.padics.padic_ZZ_pX_element import _test_preprocess_list
600
+ sage: from sage.libs.ntl.all import ZZ as ntl_ZZ, ZZ_p as ntl_ZZ_p
601
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1,2,3])
602
+ ([1, 2, 3], 0, None)
603
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [10,20,30])
604
+ ([10, 20, 30], 0, None)
605
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,2/5,3])
606
+ ([1, 2, 15], -1, NTL modulus 95367431640625)
607
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,mod(2,625),3])
608
+ ([1, 10, 15], -1, NTL modulus 3125)
609
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,mod(2,625),ntl_ZZ_p(3,25)])
610
+ ([1, 10, 15], -1, NTL modulus 125)
611
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,mod(2,625),Zp(5)(5,3)])
612
+ ([1, 10, 25], -1, NTL modulus 625)
613
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,mod(2,625),Zp(5)(5,3),0])
614
+ ([1, 10, 25, 0], -1, NTL modulus 625)
615
+ sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,mod(2,625),Zp(5)(5,3),mod(0,3125)])
616
+ ([1, 10, 25, 0], -1, NTL modulus 625)
617
+ sage: x = polygen(ZZ, 'x')
618
+ sage: T.<a> = Qp(5).extension(x^2 - 5)
619
+ sage: _test_preprocess_list(T, [5^-1 + O(5)])
620
+ ([1], -1, NTL modulus 25)
621
+ """
622
+ return preprocess_list(R(0), L)
623
+
624
+
625
+ cdef preprocess_list(pAdicZZpXElement elt, L):
626
+ """
627
+ See the documentation for :func:`_test_preprocess_list`.
628
+ """
629
+ cdef Py_ssize_t i
630
+ cdef ZZ_c tmp
631
+ cdef ntl_ZZ_pContext_class ctx
632
+ cdef ntl_ZZ pshift_z
633
+ cdef Integer pshift_m
634
+ cdef ntl_ZZ py_tmp
635
+ if not isinstance(L, list):
636
+ raise TypeError("L must be a list")
637
+ min_val, min_aprec, total_type = find_val_aprec(elt.prime_pow, L)
638
+ #return "a","b","c"
639
+ if total_type == two:
640
+ # all integers
641
+ return [ntl_ZZ(a) for a in L], zero, None
642
+ if min_val < 0 and not elt.prime_pow.in_field:
643
+ raise ValueError("negative valuation")
644
+ if total_type == one:
645
+ # rationals and integers
646
+ py_tmp = ntl_ZZ.__new__(ntl_ZZ)
647
+ py_tmp.x = elt.prime_pow.pow_ZZ_top()[0]
648
+ ctx = ntl_ZZ_pContext(py_tmp)
649
+ else:
650
+ # integers, rationals and things with finite precision
651
+ # note that min_val will be nonpositive since things with finite precision return nonpositive valuation from get_val_prec
652
+ py_tmp = ntl_ZZ.__new__(ntl_ZZ)
653
+ py_tmp.x = elt.prime_pow.pow_ZZ_tmp(mpz_get_ui((<Integer>(min_aprec - min_val)).value))[0]
654
+ ctx = ntl_ZZ_pContext(py_tmp)
655
+ if min_val < 0:
656
+ pshift_z = ntl_ZZ.__new__(ntl_ZZ)
657
+ pshift_z.x = elt.prime_pow.pow_ZZ_tmp(-mpz_get_si((<Integer>min_val).value))[0]
658
+ pshift_m = elt.prime_pow.pow_Integer(-mpz_get_si((<Integer>min_val).value))
659
+ for i from 0 <= i < len(L):
660
+ if isinstance(L[i], ntl_ZZ):
661
+ L[i] = ntl_ZZ_p(L[i]*pshift_z, ctx)
662
+ elif isinstance(L[i], (Integer, Rational, int)):
663
+ L[i] = ntl_ZZ_p(L[i]*pshift_m, ctx)
664
+ elif isinstance(L[i], pAdicGenericElement) and L[i]._is_base_elt(elt.prime_pow.prime):
665
+ L[i] = ntl_ZZ_p((L[i] >> min_val).lift(), ctx)
666
+ elif isinstance(L[i], IntegerMod_abstract):
667
+ L[i] = ntl_ZZ_p(L[i].lift()*pshift_m, ctx)
668
+ elif (L[i].modulus_context() is not ctx) or min_val != zero:
669
+ L[i] = ntl_ZZ_p(L[i].lift()*pshift_z, ctx)
670
+ elif elt.parent().is_capped_relative() and min_val > 0:
671
+ pshift_z = ntl_ZZ.__new__(ntl_ZZ)
672
+ pshift_z.x = elt.prime_pow.pow_ZZ_tmp(mpz_get_ui((<Integer>min_val).value))[0]
673
+ pshift_m = elt.prime_pow.pow_Integer(mpz_get_ui((<Integer>min_val).value))
674
+ for i from 0 <= i < len(L):
675
+ if isinstance(L[i], ntl_ZZ):
676
+ ZZ_div(tmp, (<ntl_ZZ>L[i]).x, pshift_z.x)
677
+ py_tmp = ntl_ZZ.__new__(ntl_ZZ)
678
+ py_tmp.x = tmp
679
+ L[i] = ntl_ZZ_p(py_tmp, ctx)
680
+ elif isinstance(L[i], (Integer, Rational, int)):
681
+ L[i] = ntl_ZZ_p(L[i]//pshift_m, ctx)
682
+ elif isinstance(L[i], pAdicGenericElement) and L[i]._is_base_elt(elt.prime_pow.prime):
683
+ L[i] = ntl_ZZ_p((L[i] >> min_val).lift(), ctx)
684
+ elif isinstance(L[i], IntegerMod_abstract):
685
+ L[i] = ntl_ZZ_p(L[i].lift()//pshift_m, ctx)
686
+ elif (L[i].modulus_context() is not ctx) or min_val != zero:
687
+ ZZ_div(tmp, (<ntl_ZZ>L[i].lift()).x, pshift_z.x)
688
+ py_tmp = ntl_ZZ.__new__(ntl_ZZ)
689
+ py_tmp.x = tmp
690
+ L[i] = ntl_ZZ_p(py_tmp, ctx)
691
+ else:
692
+ for i from 0 <= i < len(L):
693
+ if isinstance(L[i], (ntl_ZZ, Integer, Rational, int)):
694
+ L[i] = ntl_ZZ_p(L[i], ctx)
695
+ elif (isinstance(L[i], pAdicGenericElement) and L[i]._is_base_elt(elt.prime_pow.prime)) or isinstance(L[i], IntegerMod_abstract) or (L[i].modulus_context() is not ctx):
696
+ L[i] = ntl_ZZ_p(L[i].lift(), ctx)
697
+ return L, min_val, ctx
698
+
699
+
700
+ def _find_val_aprec_test(R, L):
701
+ r"""
702
+ Given a list ``L``, finds the minimum valuation, minimum absolute
703
+ precision and minimum common type of the elements.
704
+
705
+ INPUT:
706
+
707
+ - ``R`` -- a `p`-adic extension
708
+ - ``L`` -- list of integers, rationals, ``IntegerMods``, etc.
709
+
710
+ OUTPUT: ``min_val`` -- the minimum valuation of any element in the list
711
+
712
+ - ``min_aprec`` -- the minimum absolute precision of any element
713
+ in the list; if infinite, a predefined constant ``big`` is
714
+ returned instead
715
+
716
+ - ``total_type`` --
717
+
718
+ * if all elements are integers or ints: 2
719
+
720
+ * if all elements are rationals or integers: 1
721
+
722
+ * if some elements have finite precision: 0
723
+
724
+ EXAMPLES::
725
+
726
+ sage: from sage.rings.padics.padic_ZZ_pX_element import _find_val_aprec_test
727
+ sage: from sage.libs.ntl.all import ZZ as ntl_ZZ, ZZ_p as ntl_ZZ_p
728
+ sage: _find_val_aprec_test(Zq(25,names='a',implementation="NTL"), [15, int(75), ntl_ZZ(625)])
729
+ (1, 340282366920938463463374607431768211457, 2)
730
+ sage: _find_val_aprec_test(Zq(25,names='a',implementation="NTL"), [5, int(25), 7/25])
731
+ (-2, 340282366920938463463374607431768211457, 1)
732
+ sage: _find_val_aprec_test(Zq(25,names='a',implementation="NTL"), [mod(4,125), Zp(5)(5,5), ntl_ZZ_p(16,625), 4/125])
733
+ (-3, 3, 0)
734
+ sage: _find_val_aprec_test(Zq(25,names='a',implementation="NTL"), [mod(25,125), Zp(5)(5,5), ntl_ZZ_p(15,625)])
735
+ (0, 3, 0)
736
+ """
737
+ return find_val_aprec(R.prime_pow, L)
738
+
739
+
740
+ cdef find_val_aprec(PowComputer_ext pp, L):
741
+ r"""
742
+ Given a list ``L``, finds the minimum valuation, minimum absolute
743
+ precision and minimum common type of the elements.
744
+
745
+ INPUT:
746
+
747
+ - ``pp`` -- a PowComputer_ext for the element that this list is
748
+ being initialized into
749
+
750
+ - ``L`` -- list of integers, rationals, ``IntegerMods``, etc.
751
+
752
+ See the documentation for :func:`_find_val_aprec_test` for more details.
753
+ """
754
+ cdef Py_ssize_t i
755
+ min_val = big
756
+ min_aprec = big
757
+ total_type = two # we begin by defaulting to the list elements being integers
758
+ for i from 0 <= i < len(L):
759
+ cur_val, cur_aprec, cur_type = get_val_prec(pp, L[i])
760
+ #return "a","b","c"
761
+ # proc_type == 0 indicates something with finite precision
762
+ # proc_type == 1 indicates a rational, or something that cannot be coerced to an integer
763
+ # proc_type == 2 indicates an integer, or something that can be coerced to an integer
764
+ # but can be coerced to Z/p^n for any n.
765
+ if cur_aprec < min_aprec:
766
+ min_aprec = cur_aprec
767
+ if cur_val < min_val:
768
+ min_val = cur_val
769
+ if cur_type < total_type:
770
+ total_type = cur_type
771
+ return min_val, min_aprec, total_type
772
+
773
+
774
+ def _test_get_val_prec(R, a):
775
+ """
776
+ Return valuation, absolute precision and type of an input
777
+ element.
778
+
779
+ INPUT:
780
+
781
+ - ``R`` -- a `p`-adic extension ring to provide a ``PowComputer_ext``
782
+
783
+ - ``a`` -- rational, integer, int, long, ``ntl_ZZ_p``,
784
+ ``ntl_ZZ``, ``IntegerMod`` or `p`-adic base element
785
+
786
+ OUTPUT:
787
+
788
+ - ``val`` -- if ``a`` is exact, ``a.valuation(p)``, otherwise
789
+ ``min(0, a.valuation())``
790
+
791
+ - ``aprec`` -- the absolute precision of ``a``; if ``a`` is
792
+ exact, a large predefined constant
793
+
794
+ - type --
795
+
796
+ * 2 - if ``a`` is an integer, int or long
797
+
798
+ * 1 - if ``a`` is a rational
799
+
800
+ * 0 - if ``a`` has finite precision
801
+
802
+ EXAMPLES::
803
+
804
+ sage: from sage.rings.padics.padic_ZZ_pX_element import _test_get_val_prec
805
+ sage: from sage.libs.ntl.all import ZZ as ntl_ZZ, ZZ_p as ntl_ZZ_p
806
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), 15)
807
+ (1, 340282366920938463463374607431768211457, 2)
808
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), ntl_ZZ(15))
809
+ (1, 340282366920938463463374607431768211457, 2)
810
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), int(15))
811
+ (1, 340282366920938463463374607431768211457, 2)
812
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), 1/15)
813
+ (-1, 340282366920938463463374607431768211457, 1)
814
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), Zp(5)(15,4))
815
+ (0, 4, 0)
816
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), Qp(5)(1/15,4))
817
+ (-1, 4, 0)
818
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), mod(15,625))
819
+ (0, 4, 0)
820
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), ntl_ZZ_p(15,625))
821
+ (0, 4, 0)
822
+
823
+ TESTS::
824
+
825
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), 0) # indirect doctest
826
+ (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 2)
827
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), ntl_ZZ(0))
828
+ (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 2)
829
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), int(0))
830
+ (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 2)
831
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), 0/1)
832
+ (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 1)
833
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), Zp(5)(25,4))
834
+ (0, 4, 0)
835
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), Qp(5)(1/25,4))
836
+ (-2, 4, 0)
837
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), Zp(5)(0))
838
+ (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 1)
839
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), mod(0,625))
840
+ (0, 4, 0)
841
+ sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), ntl_ZZ_p(0,625))
842
+ (0, 4, 0)
843
+ """
844
+ return get_val_prec(R.prime_pow, a)
845
+
846
+
847
+ cdef get_val_prec(PowComputer_ext pp, a):
848
+ r"""
849
+ Return valuation, absolute precision and type of an input element.
850
+
851
+ INPUT:
852
+
853
+ - ``pp`` -- a ``PowComputer_ext``
854
+
855
+ - ``a`` -- rational, integer, int, long, ``ntl_ZZ_p``,
856
+ ``ntl_ZZ``, ``IntegerMod`` or `p`-adic base element
857
+
858
+ See :func:`_test_get_val_prec` for more details.
859
+ """
860
+ cdef ntl_ZZ py_tmp
861
+ if isinstance(a, Integer):
862
+ if a == 0:
863
+ return (big, big, two)
864
+ return (a.valuation(pp.prime), big, two)
865
+ if isinstance(a, ntl_ZZ):
866
+ if ZZ_IsZero((<ntl_ZZ>a).x):
867
+ return (big, big, two)
868
+ py_tmp = ntl_ZZ.__new__(ntl_ZZ)
869
+ py_tmp.x = pp.pow_ZZ_tmp(1)[0]
870
+ return (Integer(a.valuation(py_tmp)), big, two)
871
+ if isinstance(a, int):
872
+ if a == 0:
873
+ return (big, big, two)
874
+ return (Integer(a).valuation(pp.prime), big, two)
875
+ if isinstance(a, Rational):
876
+ if a == 0:
877
+ return (big, big, one)
878
+ val = a.valuation(pp.prime)
879
+ return (val, big, one)
880
+ if isinstance(a, pAdicGenericElement) and a._is_base_elt(pp.prime):
881
+ if a.parent().prime() == pp.prime:
882
+ if a._is_exact_zero():
883
+ return (big, big, one)
884
+ val = a.valuation()
885
+ return (val if val < zero else zero, a.precision_absolute(), zero)
886
+ else:
887
+ raise TypeError("primes must match")
888
+ cdef mpz_t leftover
889
+ cdef long long_val
890
+ cdef Integer Integer_val
891
+ if isinstance(a, IntegerMod_abstract):
892
+ mpz_init(leftover)
893
+ long_val = mpz_remove(leftover, (<Integer>a.modulus()).value, pp.prime.value)
894
+ if long_val > 0 and mpz_cmp_ui(leftover, 1) == 0:
895
+ mpz_clear(leftover)
896
+ Integer_val = PY_NEW(Integer)
897
+ mpz_set_ui(Integer_val.value, long_val)
898
+ # Since we're guaranteed to be in type 0, we don't care about computing the actual valuation
899
+ return (zero, Integer_val, zero)
900
+ else:
901
+ mpz_clear(leftover)
902
+ raise TypeError("modulus must be a positive power of the appropriate prime")
903
+ cdef ZZ_c leftover_z
904
+ if isinstance(a, ntl_ZZ_p):
905
+ long_val = ZZ_remove(leftover_z, (<ntl_ZZ_p>a).c.p.x, pp.pow_ZZ_tmp(1)[0])
906
+ if long_val > 0 and ZZ_IsOne(leftover_z):
907
+ Integer_val = PY_NEW(Integer)
908
+ mpz_set_ui(Integer_val.value, long_val)
909
+ # Since we're guaranteed to be in type 0, we don't care about computing the actual valuation
910
+ return (zero, Integer_val, zero)
911
+ else:
912
+ print(long_val)
913
+ py_tmp = ntl_ZZ.__new__(ntl_ZZ)
914
+ py_tmp.x = (<ntl_ZZ_p>a).c.p.x
915
+ print(py_tmp)
916
+ py_tmp.x = leftover_z
917
+ print(py_tmp)
918
+ raise TypeError("modulus must be a positive power of the appropriate prime")
919
+ raise TypeError("unsupported type for list element: %s" % type(a))