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,771 @@
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.libs.pari
9
+
10
+ # ****************************************************************************
11
+ # Copyright (C) 2005 William Stein <wstein@gmail.com>
12
+ # Copyright (C) 2007 Martin Albrecht <malb@informatik.uni-bremen.de>
13
+ #
14
+ # Distributed under the terms of the GNU General Public License (GPL)
15
+ #
16
+ # This code is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
+ # General Public License for more details.
20
+ #
21
+ # The full text of the GPL is available at:
22
+ #
23
+ # https://www.gnu.org/licenses/
24
+ # ****************************************************************************
25
+
26
+ from sage.ext.cplusplus cimport ccrepr, ccreadstr
27
+
28
+ include 'misc.pxi'
29
+ include 'decl.pxi'
30
+
31
+ from cpython.object cimport Py_EQ, Py_NE
32
+ from sage.rings.integer cimport Integer
33
+
34
+ from sage.libs.ntl.ntl_ZZ import unpickle_class_value
35
+ from sage.libs.ntl.ntl_GF2 cimport ntl_GF2
36
+
37
+
38
+ ##############################################################################
39
+ #
40
+ # ntl_GF2X: Polynomials over GF(2) via NTL
41
+ #
42
+ # AUTHORS:
43
+ # - Martin Albrecht <malb@informatik.uni-bremen.de>
44
+ # 2006-01: initial version (based on code by William Stein)
45
+ # - Martin Albrecht <malb@informatik.uni-bremen.de>
46
+ # 2007-10: adapted to new conventions
47
+ #
48
+ ##############################################################################
49
+
50
+ def GF2XHexOutput(have_hex=None):
51
+ """
52
+ Represent GF2X and GF2E elements in the more compact
53
+ hexadecimal form to the user.
54
+
55
+ If no parameter is provided the currently set value will be
56
+ returned.
57
+
58
+ INPUT:
59
+
60
+ - ``have_hex`` -- if ``True`` hex representation will be used
61
+
62
+ EXAMPLES::
63
+
64
+ sage: m = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
65
+ sage: x = ntl.GF2E([1,0,1,0,1], m) ; x
66
+ [1 0 1 0 1]
67
+
68
+ sage: ntl.GF2XHexOutput() ## indirect doctest
69
+ False
70
+ sage: ntl.GF2XHexOutput(True)
71
+ sage: ntl.GF2XHexOutput()
72
+ True
73
+
74
+ sage: x
75
+ 0x51
76
+
77
+ sage: ntl.GF2XHexOutput(False)
78
+ sage: x
79
+ [1 0 1 0 1]
80
+ """
81
+ if have_hex is None:
82
+ return bool(GF2XHexOutput_c[0])
83
+
84
+ if have_hex:
85
+ GF2XHexOutput_c[0] = 1
86
+ else:
87
+ GF2XHexOutput_c[0] = 0
88
+
89
+
90
+ cdef class ntl_GF2X():
91
+ """
92
+ Univariate Polynomials over GF(2) via NTL.
93
+ """
94
+ def __init__(self, x=[]):
95
+ """
96
+ Construct a new polynomial over GF(2).
97
+
98
+ A value may be passed to this constructor. If you pass a string
99
+ to the constructor please note that byte sequences and the hexadecimal
100
+ notation are little endian. So e.g. '[0 1]' == '0x2' == x.
101
+
102
+ Input types are ntl.ZZ_px, strings, lists of digits, FiniteFieldElements
103
+ from extension fields over GF(2), Polynomials over GF(2), Integers, and finite
104
+ extension fields over GF(2) (uses modulus).
105
+
106
+ INPUT:
107
+
108
+ - ``x`` -- value to be assigned to this element. See examples.
109
+
110
+ OUTPUT: a new ntl.GF2X element
111
+
112
+ EXAMPLES::
113
+
114
+ sage: ntl.GF2X(ntl.ZZ_pX([1,1,3],2))
115
+ [1 1 1]
116
+ sage: ntl.GF2X('0x1c')
117
+ [1 0 0 0 0 0 1 1]
118
+ sage: ntl.GF2X('[1 0 1 0]')
119
+ [1 0 1]
120
+ sage: ntl.GF2X([1,0,1,0])
121
+ [1 0 1]
122
+ sage: ntl.GF2X(GF(2**8,'a').gen()**20)
123
+ [0 0 1 0 1 1 0 1]
124
+ sage: ntl.GF2X(GF(2**8,'a'))
125
+ [1 0 1 1 1 0 0 0 1]
126
+ sage: ntl.GF2X(2)
127
+ [0 1]
128
+ sage: ntl.GF2X(ntl.GF2(1))
129
+ [1]
130
+
131
+ sage: R.<x> = GF(2)[]
132
+ sage: f = x^5+x^2+1
133
+ sage: ntl.GF2X(f)
134
+ [1 0 1 0 0 1]
135
+ """
136
+ from sage.rings.finite_rings.element_ntl_gf2e import FiniteField_ntl_gf2eElement
137
+ from sage.rings.finite_rings.finite_field_base import FiniteField
138
+
139
+ cdef long _x
140
+
141
+ if isinstance(x, ntl_GF2):
142
+ GF2X_conv_GF2(self.x,(<ntl_GF2>x).x)
143
+ return
144
+ elif isinstance(x, ntl_GF2X):
145
+ self.x = (<ntl_GF2X>x).x
146
+ return
147
+ elif isinstance(x, int):
148
+ _x = x
149
+ GF2XFromBytes(self.x, <unsigned char *>(&_x),sizeof(long))
150
+ return
151
+
152
+ if isinstance(x, Integer):
153
+ #binary repr, reversed, and "["..."]" added
154
+ x = "["+x.binary()[::-1].replace(""," ")+"]"
155
+ elif isinstance(x, FiniteField):
156
+ if x.characteristic() == 2:
157
+ x = list(x.modulus())
158
+ elif isinstance(x, FiniteField_ntl_gf2eElement):
159
+ x = x.polynomial().list()
160
+ else:
161
+ try:
162
+ from sage.rings.polynomial.polynomial_gf2x import Polynomial_GF2X
163
+ except ImportError:
164
+ pass
165
+ else:
166
+ if isinstance(x, Polynomial_GF2X):
167
+ x = x.list() # this is slow but cimport leads to circular imports
168
+ try:
169
+ from sage.rings.finite_rings.element_givaro import FiniteField_givaroElement
170
+ except ImportError:
171
+ pass
172
+ else:
173
+ if isinstance(x, FiniteField_givaroElement):
174
+ x = "0x" + hex(x.to_integer())[2:][::-1]
175
+ s = str(x).replace(","," ")
176
+ # TODO: this is very slow, but we wait until somebody complains
177
+ ccreadstr(self.x, s)
178
+
179
+ def __reduce__(self):
180
+ """
181
+ EXAMPLES::
182
+
183
+ sage: f = ntl.GF2X(ntl.ZZ_pX([1,1,3],2))
184
+ sage: loads(dumps(f)) == f
185
+ True
186
+ sage: f = ntl.GF2X('0x1c')
187
+ sage: loads(dumps(f)) == f
188
+ True
189
+ """
190
+ return unpickle_class_value, (ntl_GF2X, self.hex())
191
+
192
+ def __repr__(self):
193
+ """
194
+ Return the string representation of ``self``.
195
+
196
+ EXAMPLES::
197
+
198
+ sage: ntl.GF2X(ntl.ZZ_pX([1,1,3],2)).__repr__()
199
+ '[1 1 1]'
200
+ """
201
+ return ccrepr(self.x)
202
+
203
+ def __mul__(ntl_GF2X self, other):
204
+ """
205
+ EXAMPLES::
206
+
207
+ sage: f = ntl.GF2X([1,0,1,1]) ; g = ntl.GF2X([0,1])
208
+ sage: f*g ## indirect doctest
209
+ [0 1 0 1 1]
210
+ """
211
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
212
+ if not isinstance(other, ntl_GF2X):
213
+ other = ntl_GF2X(other)
214
+ GF2X_mul(r.x, self.x, (<ntl_GF2X>other).x)
215
+ return r
216
+
217
+ def __truediv__(ntl_GF2X self, b):
218
+ """
219
+ EXAMPLES::
220
+
221
+ sage: a = ntl.GF2X(4)
222
+ sage: a / ntl.GF2X(2)
223
+ [0 1]
224
+ sage: a / ntl.GF2X(3)
225
+ Traceback (most recent call last):
226
+ ...
227
+ ArithmeticError: self (=[0 0 1]) is not divisible by b (=[1 1])
228
+ """
229
+ cdef ntl_GF2X q = ntl_GF2X.__new__(ntl_GF2X)
230
+ cdef int divisible
231
+
232
+ if not isinstance(b, ntl_GF2X):
233
+ b = ntl_GF2X(b)
234
+
235
+ divisible = GF2X_divide(q.x, self.x, (<ntl_GF2X>b).x)
236
+ if not divisible:
237
+ raise ArithmeticError("self (=%s) is not divisible by b (=%s)" % (self, b))
238
+ return q
239
+
240
+ def DivRem(ntl_GF2X self, b):
241
+ """
242
+ EXAMPLES::
243
+
244
+ sage: a = ntl.GF2X(4)
245
+ sage: a.DivRem( ntl.GF2X(2) )
246
+ ([0 1], [])
247
+ sage: a.DivRem( ntl.GF2X(3) )
248
+ ([1 1], [1])
249
+ """
250
+ cdef ntl_GF2X q = ntl_GF2X.__new__(ntl_GF2X)
251
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
252
+
253
+ if not isinstance(b, ntl_GF2X):
254
+ b = ntl_GF2X(b)
255
+
256
+ GF2X_DivRem(q.x, r.x, self.x, (<ntl_GF2X>b).x)
257
+ return q,r
258
+
259
+ def __floordiv__(ntl_GF2X self, b):
260
+ """
261
+ EXAMPLES::
262
+
263
+ sage: a = ntl.GF2X(4)
264
+ sage: a // ntl.GF2X(2)
265
+ [0 1]
266
+ sage: a // ntl.GF2X(3)
267
+ [1 1]
268
+ """
269
+ cdef ntl_GF2X q = ntl_GF2X.__new__(ntl_GF2X)
270
+
271
+ if not isinstance(b, ntl_GF2X):
272
+ b = ntl_GF2X(b)
273
+
274
+ GF2X_div(q.x, self.x, (<ntl_GF2X>b).x)
275
+ return q
276
+
277
+ def __mod__(ntl_GF2X self, b):
278
+ """
279
+ EXAMPLES::
280
+
281
+ sage: a = ntl.GF2X(4)
282
+ sage: a % ntl.GF2X(2)
283
+ []
284
+ sage: a % ntl.GF2X(3)
285
+ [1]
286
+ """
287
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
288
+
289
+ if not isinstance(b, ntl_GF2X):
290
+ b = ntl_GF2X(b)
291
+
292
+ GF2X_rem(r.x, self.x, (<ntl_GF2X>b).x)
293
+ return r
294
+
295
+ def __sub__(ntl_GF2X self, other):
296
+ """
297
+ EXAMPLES::
298
+
299
+ sage: f = ntl.GF2X([1,0,1,1]) ; g = ntl.GF2X([0,1])
300
+ sage: f - g ## indirect doctest
301
+ [1 1 1 1]
302
+ sage: g - f
303
+ [1 1 1 1]
304
+ """
305
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
306
+ if not isinstance(other, ntl_GF2X):
307
+ other = ntl_GF2X(other)
308
+ GF2X_sub(r.x, self.x, (<ntl_GF2X>other).x)
309
+ return r
310
+
311
+ def __add__(ntl_GF2X self, other):
312
+ """
313
+ EXAMPLES::
314
+
315
+ sage: f = ntl.GF2X([1,0,1,1]) ; g = ntl.GF2X([0,1,0])
316
+ sage: f + g ## indirect doctest
317
+ [1 1 1 1]
318
+ """
319
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
320
+ if not isinstance(other, ntl_GF2X):
321
+ other = ntl_GF2X(other)
322
+ GF2X_add(r.x, self.x, (<ntl_GF2X>other).x)
323
+ return r
324
+
325
+ def __neg__(ntl_GF2X self):
326
+ """
327
+ EXAMPLES::
328
+
329
+ sage: f = ntl.GF2X([1,0,1,1])
330
+ sage: -f ## indirect doctest
331
+ [1 0 1 1]
332
+ sage: f == -f
333
+ True
334
+ """
335
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
336
+ GF2X_negate(r.x, self.x)
337
+ return r
338
+
339
+ def __pow__(ntl_GF2X self, long e, ignored):
340
+ """
341
+ EXAMPLES::
342
+
343
+ sage: f = ntl.GF2X([1,0,1,1]) ; g = ntl.GF2X([0,1,0])
344
+ sage: f**3 ## indirect doctest
345
+ [1 0 1 1 1 0 0 1 1 1]
346
+ """
347
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
348
+ GF2X_power(r.x, self.x, e)
349
+ return r
350
+
351
+ def __richcmp__(ntl_GF2X self, other, int op):
352
+ """
353
+ Compare ``self`` to ``other``.
354
+
355
+ EXAMPLES::
356
+
357
+ sage: f = ntl.GF2X([1,0,1,1])
358
+ sage: g = ntl.GF2X([0,1,0])
359
+ sage: f == g ## indirect doctest
360
+ False
361
+ sage: f == f
362
+ True
363
+ sage: g != polygen(GF(2))
364
+ False
365
+ """
366
+ if op != Py_EQ and op != Py_NE:
367
+ raise TypeError("elements of GF(2)[X] are not ordered")
368
+
369
+ cdef ntl_GF2X b
370
+ try:
371
+ b = <ntl_GF2X?>other
372
+ except TypeError:
373
+ b = ntl_GF2X(other)
374
+
375
+ return (op == Py_EQ) == (self.x == b.x)
376
+
377
+ def __lshift__(ntl_GF2X self, int i):
378
+ """
379
+ Return left shift of ``self`` by i bits ( == multiplication by
380
+ `X^i`).
381
+
382
+ INPUT:
383
+
384
+ - ``i`` -- offset/power of X
385
+
386
+ EXAMPLES::
387
+
388
+ sage: a = ntl.GF2X(4); a
389
+ [0 0 1]
390
+ sage: a << 2
391
+ [0 0 0 0 1]
392
+ """
393
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
394
+ GF2X_LeftShift(r.x, self.x, <long>i)
395
+ return r
396
+
397
+ def __rshift__(ntl_GF2X self, int offset):
398
+ """
399
+ Return right shift of ``self`` by i bits ( == floor division by
400
+ `X^i`).
401
+
402
+ INPUT:
403
+
404
+ - ``i`` -- offset/power of X
405
+
406
+ EXAMPLES::
407
+
408
+ sage: a = ntl.GF2X(4); a
409
+ [0 0 1]
410
+ sage: a >> 1
411
+ [0 1]
412
+ """
413
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
414
+ GF2X_RightShift(r.x, self.x, <long>offset)
415
+ return r
416
+
417
+ def GCD(ntl_GF2X self, other):
418
+ """
419
+ Return GCD of ``self`` and ``other``.
420
+
421
+ INPUT:
422
+
423
+ - ``other`` -- ntl.GF2X
424
+
425
+ EXAMPLES::
426
+
427
+ sage: a = ntl.GF2X(10)
428
+ sage: b = ntl.GF2X(4)
429
+ sage: a.GCD(b)
430
+ [0 1]
431
+ """
432
+ cdef ntl_GF2X gcd = ntl_GF2X.__new__(ntl_GF2X)
433
+
434
+ if not isinstance(other, ntl_GF2X):
435
+ other = ntl_GF2X(other)
436
+
437
+ GF2X_GCD(gcd.x, self.x, (<ntl_GF2X>other).x)
438
+ return gcd
439
+
440
+ def XGCD(ntl_GF2X self, other):
441
+ """
442
+ Return the extended gcd of ``self`` and ``other``, i.e., elements r, s, t such that.
443
+
444
+ r = s * self + t * other.
445
+
446
+ INPUT:
447
+
448
+ - ``other`` -- ntl.GF2X
449
+
450
+ EXAMPLES::
451
+
452
+ sage: a = ntl.GF2X(10)
453
+ sage: b = ntl.GF2X(4)
454
+ sage: r,s,t = a.XGCD(b)
455
+ sage: r == a*s + t*b
456
+ True
457
+ """
458
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
459
+ cdef ntl_GF2X s = ntl_GF2X.__new__(ntl_GF2X)
460
+ cdef ntl_GF2X t = ntl_GF2X.__new__(ntl_GF2X)
461
+
462
+ if not isinstance(other, ntl_GF2X):
463
+ other = ntl_GF2X(other)
464
+
465
+ GF2X_XGCD(r.x, s.x, t.x, self.x, (<ntl_GF2X>other).x)
466
+ return r,s,t
467
+
468
+ def deg(ntl_GF2X self):
469
+ """
470
+ Return the degree of this polynomial.
471
+
472
+ EXAMPLES::
473
+
474
+ sage: ntl.GF2X([1,0,1,1]).deg()
475
+ 3
476
+ """
477
+ return GF2X_deg(self.x)
478
+
479
+ def list(ntl_GF2X self):
480
+ """
481
+ Represent this element as a list of binary digits.
482
+
483
+ EXAMPLES::
484
+
485
+ sage: e=ntl.GF2X([0,1,1])
486
+ sage: e.list()
487
+ [0, 1, 1]
488
+ sage: e=ntl.GF2X('0xff')
489
+ sage: e.list()
490
+ [1, 1, 1, 1, 1, 1, 1, 1]
491
+
492
+ OUTPUT: list of digits representing the coefficients in this element's
493
+ polynomial representation
494
+ """
495
+ return [self[i] for i in range(GF2X_deg(self.x)+1)]
496
+
497
+ def bin(ntl_GF2X self):
498
+ r"""
499
+ Return binary representation of this element.
500
+
501
+ It is the same as setting \code{ntl.GF2XHexOutput(False)} and
502
+ representing this element afterwards. However it should be
503
+ faster and preserves the HexOutput state as opposed to the above code.
504
+
505
+ EXAMPLES::
506
+
507
+ sage: e=ntl.GF2X([1,1,0,1,1,1,0,0,1])
508
+ sage: e.bin()
509
+ '[1 1 0 1 1 1 0 0 1]'
510
+
511
+ OUTPUT:
512
+
513
+ string representing this element in binary digits
514
+ """
515
+ cdef long _hex = GF2XHexOutput_c[0]
516
+ GF2XHexOutput_c[0] = 0
517
+ s = ccrepr(self.x)
518
+ GF2XHexOutput_c[0] = _hex
519
+ return s
520
+
521
+ def hex(ntl_GF2X self):
522
+ r"""
523
+ Return a hexadecimal representation of this element.
524
+
525
+ It is the same as setting \code{ntl.GF2XHexOutput(True)} and
526
+ representing this element afterwards. However it should be faster and
527
+ preserves the HexOutput state as opposed to the above code.
528
+
529
+ OUTPUT: string representing this element in hexadecimal
530
+
531
+ EXAMPLES::
532
+
533
+ sage: e = ntl.GF2X([1,1,0,1,1,1,0,0,1])
534
+ sage: e.hex()
535
+ '0xb31'
536
+ """
537
+ cdef long _hex = GF2XHexOutput_c[0]
538
+ GF2XHexOutput_c[0] = 1
539
+ s = ccrepr(self.x)
540
+ GF2XHexOutput_c[0] = _hex
541
+ return s
542
+
543
+ def __hash__(self):
544
+ return hash(self.hex())
545
+
546
+ def _sage_(ntl_GF2X self, R=None):
547
+ """
548
+ Return a Sage polynomial over GF(2) equivalent to this element.
549
+
550
+ If a ring R is provided, it is used to construct the polynomial
551
+ in. Otherwise, an appropriate ring is generated.
552
+
553
+ INPUT:
554
+
555
+ - ``self`` -- GF2X element
556
+ - ``R`` -- PolynomialRing over GF(2)
557
+
558
+ OUTPUT: polynomial in R
559
+
560
+ EXAMPLES::
561
+
562
+ sage: f = ntl.GF2X([1,0,1,1,0,1])
563
+ sage: f._sage_()
564
+ x^5 + x^3 + x^2 + 1
565
+ sage: f._sage_(PolynomialRing(Integers(2),'y'))
566
+ y^5 + y^3 + y^2 + 1
567
+ """
568
+ if R is None:
569
+ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
570
+ from sage.rings.finite_rings.finite_field_constructor import FiniteField
571
+ R = PolynomialRing(FiniteField(2), 'x')
572
+
573
+ return R([int(c) for c in self.list()])
574
+
575
+ def coeff(self, int i):
576
+ """
577
+ Return the coefficient of the monomial `X^i` in ``self``.
578
+
579
+ INPUT:
580
+
581
+ - ``i`` -- degree of X
582
+
583
+ EXAMPLES::
584
+
585
+ sage: e = ntl.GF2X([0,1,0,1])
586
+ sage: e.coeff(0)
587
+ 0
588
+ sage: e.coeff(1)
589
+ 1
590
+ """
591
+ cdef ntl_GF2 c = ntl_GF2.__new__(ntl_GF2)
592
+ c.x = GF2X_coeff(self.x, i)
593
+ return c
594
+
595
+ def __getitem__(self, int i):
596
+ """
597
+ EXAMPLES::
598
+
599
+ sage: e = ntl.GF2X([0,1,0,1])
600
+ sage: e[0] # indirect doctest
601
+ 0
602
+ sage: e[1]
603
+ 1
604
+ """
605
+ cdef ntl_GF2 c = ntl_GF2.__new__(ntl_GF2)
606
+ c.x = GF2X_coeff(self.x, i)
607
+ return c
608
+
609
+ def LeadCoeff(self):
610
+ """
611
+ Return the leading coefficient of ``self``.
612
+
613
+ This is always 1 except when ``self == 0``.
614
+
615
+ EXAMPLES::
616
+
617
+ sage: e = ntl.GF2X([0,1])
618
+ sage: e.LeadCoeff()
619
+ 1
620
+ sage: e = ntl.GF2X(0)
621
+ sage: e.LeadCoeff()
622
+ 0
623
+ """
624
+ cdef ntl_GF2 c = ntl_GF2.__new__(ntl_GF2)
625
+ c.x = GF2X_LeadCoeff(self.x)
626
+ return c
627
+
628
+ def ConstTerm(self):
629
+ """
630
+ Return the constant term of ``self``.
631
+
632
+ EXAMPLES::
633
+
634
+ sage: e = ntl.GF2X([1,0,1])
635
+ sage: e.ConstTerm()
636
+ 1
637
+ sage: e = ntl.GF2X(0)
638
+ sage: e.ConstTerm()
639
+ 0
640
+ """
641
+ cdef ntl_GF2 c = ntl_GF2.__new__(ntl_GF2)
642
+ c.x = GF2X_ConstTerm (self.x)
643
+ return c
644
+
645
+ def SetCoeff(self, int i, a):
646
+ """
647
+ Set the value of a coefficient of ``self``.
648
+
649
+ EXAMPLES::
650
+
651
+ sage: e = ntl.GF2X([1,0,1]); e
652
+ [1 0 1]
653
+ sage: e.SetCoeff(1,1)
654
+ sage: e
655
+ [1 1 1]
656
+ """
657
+ cdef ntl_GF2 _a = ntl_GF2(a)
658
+
659
+ GF2X_SetCoeff(self.x, i, _a.x)
660
+
661
+ def __setitem__(self, int i, a):
662
+ """
663
+ EXAMPLES::
664
+
665
+ sage: e = ntl.GF2X([1,0,1]); e
666
+ [1 0 1]
667
+ sage: e[1] = 1 # indirect doctest
668
+ sage: e
669
+ [1 1 1]
670
+ """
671
+ cdef ntl_GF2 _a = ntl_GF2(a)
672
+ GF2X_SetCoeff(self.x, i, _a.x)
673
+
674
+ def diff(self):
675
+ """
676
+ Differentiate ``self``.
677
+
678
+ EXAMPLES::
679
+
680
+ sage: e = ntl.GF2X([1,0,1,1,0])
681
+ sage: e.diff()
682
+ [0 0 1]
683
+ """
684
+ cdef ntl_GF2X d = ntl_GF2X.__new__(ntl_GF2X)
685
+ d.x = GF2X_diff(self.x)
686
+ return d
687
+
688
+ def reverse(self, int hi=-2):
689
+ """
690
+ Return reverse of a[0]..a[hi] (hi >= -1)
691
+ hi defaults to deg(a)
692
+
693
+ INPUT:
694
+
695
+ - ``hi`` -- bit position until which reverse is requested
696
+
697
+ EXAMPLES::
698
+
699
+ sage: e = ntl.GF2X([1,0,1,1,0])
700
+ sage: e.reverse()
701
+ [1 1 0 1]
702
+ """
703
+ cdef ntl_GF2X r = ntl_GF2X.__new__(ntl_GF2X)
704
+ if hi < -1:
705
+ hi = GF2X_deg(self.x)
706
+ r.x = GF2X_reverse(self.x, hi)
707
+ return r
708
+
709
+ def weight(self):
710
+ """
711
+ Return the number of nonzero coefficients in ``self``.
712
+
713
+ EXAMPLES::
714
+
715
+ sage: e = ntl.GF2X([1,0,1,1,0])
716
+ sage: e.weight()
717
+ 3
718
+ """
719
+ return int(GF2X_weight(self.x))
720
+
721
+ def __int__(self):
722
+ """
723
+ EXAMPLES::
724
+
725
+ sage: e = ntl.GF2X([1,0,1,1,0])
726
+ sage: int(e)
727
+ Traceback (most recent call last):
728
+ ...
729
+ ValueError: cannot convert non-constant polynomial to integer
730
+ sage: e = ntl.GF2X([1])
731
+ sage: int(e)
732
+ 1
733
+ """
734
+ if GF2X_deg(self.x) != 0:
735
+ raise ValueError("cannot convert non-constant polynomial to integer")
736
+ else:
737
+ return GF2_conv_to_long(GF2X_coeff(self.x,0))
738
+
739
+ def NumBits(self):
740
+ """
741
+ Return the number of bits of self, i.e., deg(self) + 1.
742
+
743
+ EXAMPLES::
744
+
745
+ sage: e = ntl.GF2X([1,0,1,1,0])
746
+ sage: e.NumBits()
747
+ 4
748
+ """
749
+ return int(GF2X_NumBits(self.x))
750
+
751
+ def __len__(self):
752
+ """
753
+ EXAMPLES::
754
+
755
+ sage: e = ntl.GF2X([1,0,1,1,0])
756
+ sage: len(e)
757
+ 4
758
+ """
759
+ return int(GF2X_NumBits(self.x))
760
+
761
+ def NumBytes(self):
762
+ """
763
+ Return the number of bytes of ``self``, i.e., floor((NumBits(self)+7)/8).
764
+
765
+ EXAMPLES::
766
+
767
+ sage: e = ntl.GF2X([1,0,1,1,0,0,0,0,1,1,1,0,0,1,1,0,1,1])
768
+ sage: e.NumBytes()
769
+ 3
770
+ """
771
+ return int(GF2X_NumBytes(self.x))