passagemath-ntl 10.6.33__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.

Potentially problematic release.


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

Files changed (161) hide show
  1. passagemath_ntl-10.6.33.dist-info/METADATA +122 -0
  2. passagemath_ntl-10.6.33.dist-info/RECORD +161 -0
  3. passagemath_ntl-10.6.33.dist-info/WHEEL +6 -0
  4. passagemath_ntl-10.6.33.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-e0f11cf3.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,488 @@
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
27
+
28
+ include 'misc.pxi'
29
+ include 'decl.pxi'
30
+
31
+ from cpython.object cimport Py_EQ, Py_NE
32
+ from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ
33
+ from sage.libs.ntl.ntl_GF2 cimport ntl_GF2
34
+ from sage.libs.ntl.ntl_GF2X cimport ntl_GF2X
35
+ from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class
36
+ from sage.libs.ntl.ntl_GF2EContext import ntl_GF2EContext
37
+ from sage.libs.ntl.ntl_ZZ import unpickle_class_args
38
+ from sage.misc.randstate cimport current_randstate
39
+
40
+
41
+ ##############################################################################
42
+ #
43
+ # ntl_GF2E: GF(2**x) via NTL
44
+ #
45
+ # AUTHORS:
46
+ # - Martin Albrecht <malb@informatik.uni-bremen.de>
47
+ # 2006-01: initial version (based on code by William Stein)
48
+ # - Martin Albrecht <malb@informatik.uni-bremen.de>
49
+ # 2007-10: adapted to new conventions
50
+ #
51
+ ##############################################################################
52
+
53
+ def ntl_GF2E_random(ntl_GF2EContext_class ctx):
54
+ """
55
+ Return a random element from GF2E modulo the current modulus.
56
+
57
+ INPUT:
58
+
59
+ - ``ctx`` -- the GF2E context for which a random element should be created
60
+
61
+ EXAMPLES::
62
+
63
+ sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
64
+ sage: ntl.GF2E_random(ctx).modulus_context() is ctx
65
+ True
66
+ """
67
+ current_randstate().set_seed_ntl(False)
68
+
69
+ cdef ntl_GF2E r
70
+ ctx.restore_c()
71
+ r = ntl_GF2E.__new__(ntl_GF2E)
72
+ r.c = ctx
73
+ r.x = GF2E_random()
74
+ return r
75
+
76
+
77
+ cdef class ntl_GF2E():
78
+ r"""
79
+ The :class:`GF2E` represents a finite extension field over GF(2)
80
+ using NTL. Elements are represented as polynomials over GF(2)
81
+ modulo a modulus.
82
+
83
+ This modulus must be set by creating a GF2EContext first and pass
84
+ that context to the constructor of all elements.
85
+ """
86
+
87
+ def __init__(self, x=None, modulus=None):
88
+ """
89
+ Construct a new finite field element in GF(2**x).
90
+
91
+ If you pass a string to the constructor please note that byte
92
+ sequences and the hexadecimal notation are Little Endian in
93
+ NTL. So e.g. '[0 1]' == '0x2' == x.
94
+
95
+ INPUT:
96
+
97
+ - ``x`` -- value to be assigned to this element. Same types as
98
+ ``ntl.GF2X()`` are accepted.
99
+ - ``modulus`` -- the context/modulus of the field
100
+
101
+ OUTPUT: a new ``ntl.GF2E`` element
102
+
103
+ EXAMPLES::
104
+
105
+ sage: k.<a> = GF(2^8)
106
+ sage: e = ntl.GF2E(a,k); e
107
+ [0 1]
108
+ sage: ctx = e.modulus_context()
109
+ sage: ntl.GF2E('0x1c', ctx)
110
+ [1 0 0 0 0 0 1 1]
111
+ sage: ntl.GF2E('[1 0 1 0]', ctx)
112
+ [1 0 1]
113
+ sage: ntl.GF2E([1,0,1,0], ctx)
114
+ [1 0 1]
115
+ sage: ntl.GF2E(ntl.GF2(1),ctx)
116
+ [1]
117
+ """
118
+ if modulus is None:
119
+ raise ValueError("You must specify a modulus when creating a GF2E.")
120
+
121
+ cdef ntl_GF2X _x
122
+
123
+ if isinstance(x, ntl_GF2X):
124
+ GF2E_conv_GF2X(self.x, (<ntl_GF2X>x).x)
125
+
126
+ elif isinstance(x, int):
127
+ GF2E_conv_long(self.x, x)
128
+
129
+ elif isinstance(x, ntl_ZZ):
130
+ GF2E_conv_ZZ(self.x, (<ntl_ZZ>x).x)
131
+
132
+ elif isinstance(x, ntl_GF2):
133
+ GF2E_conv_GF2(self.x, (<ntl_GF2>x).x)
134
+ else:
135
+ _x = ntl_GF2X(x)
136
+ GF2E_conv_GF2X(self.x, _x.x)
137
+
138
+ def __cinit__(self, x=None, modulus=None):
139
+ #################### WARNING ###################
140
+ ## Before creating a GF2E, you must create a ##
141
+ ## GF2EContext, and restore it. In Python, ##
142
+ ## the error checking in __init__ will prevent##
143
+ ## you from constructing an ntl_GF2E ##
144
+ ## inappropriately. However, from Cython, you##
145
+ ## could do r = ntl_GF2E.__new__(ntl_GF2E) without
146
+ ## first restoring a GF2EContext, which could ##
147
+ ## have unfortunate consequences. See _new ##
148
+ ## defined below for an example of the right ##
149
+ ## way to short-circuit __init__ (or just call##
150
+ ## _new in your own code). ##
151
+ ################################################
152
+ if modulus is None:
153
+ return
154
+ if isinstance(modulus, ntl_GF2EContext_class):
155
+ self.c = <ntl_GF2EContext_class>modulus
156
+ self.c.restore_c()
157
+ else:
158
+ self.c = <ntl_GF2EContext_class>ntl_GF2EContext(modulus)
159
+ self.c.restore_c()
160
+
161
+ cdef ntl_GF2E _new(self):
162
+ cdef ntl_GF2E r
163
+ self.c.restore_c()
164
+ r = ntl_GF2E.__new__(ntl_GF2E)
165
+ r.c = self.c
166
+ return r
167
+
168
+ def __reduce__(self):
169
+ """
170
+ EXAMPLES::
171
+
172
+ sage: ctx = ntl.GF2EContext( ntl.GF2X([1,1,0,1,1,0,0,0,1]) )
173
+ sage: a = ntl.GF2E(ntl.ZZ_pX([1,1,3],2), ctx)
174
+ sage: loads(dumps(a)) == a
175
+ True
176
+ """
177
+ return unpickle_class_args, (ntl_GF2E, (str(self), self.modulus_context()))
178
+
179
+ def modulus_context(self):
180
+ """
181
+ Return the structure that holds the underlying NTL GF2E modulus.
182
+
183
+ EXAMPLES::
184
+
185
+ sage: ctx = ntl.GF2EContext( ntl.GF2X([1,1,0,1,1,0,0,0,1]) )
186
+ sage: a = ntl.GF2E(ntl.ZZ_pX([1,1,3],2), ctx)
187
+ sage: cty = a.modulus_context(); cty
188
+ NTL modulus [1 1 0 1 1 0 0 0 1]
189
+ sage: ctx == cty
190
+ True
191
+ """
192
+ return self.c
193
+
194
+ def __repr__(self):
195
+ """
196
+ Return the string representation of ``self``.
197
+
198
+ EXAMPLES::
199
+
200
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
201
+ sage: ntl.GF2E([1,1,0,1], ctx) # indirect doctest
202
+ [1 1 0 1]
203
+ """
204
+ self.c.restore_c()
205
+ return ccrepr(self.x)
206
+
207
+ def __copy__(self):
208
+ """
209
+ Return a copy of ``self``.
210
+
211
+ EXAMPLES::
212
+
213
+ sage: x = ntl.GF2E([0,1,1],GF(2^4,'a'))
214
+ sage: y = copy(x)
215
+ sage: x == y
216
+ True
217
+ sage: x is y
218
+ False
219
+ """
220
+ cdef ntl_GF2E r = self._new()
221
+ r.x = self.x
222
+ return r
223
+
224
+ def __mul__(ntl_GF2E self, other):
225
+ """
226
+ EXAMPLES::
227
+
228
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
229
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([1,1,0,1,1], ctx)
230
+ sage: x*y ## indirect doctest
231
+ [0 0 1 1 1 0 1 1]
232
+ """
233
+ cdef ntl_GF2E r
234
+ if not isinstance(other, ntl_GF2E):
235
+ other = ntl_GF2E(other,self.c)
236
+ elif self.c is not (<ntl_GF2E>other).c:
237
+ raise ValueError("You cannot perform arithmetic with elements in different fields.")
238
+ r = self._new()
239
+ GF2E_mul(r.x, self.x, (<ntl_GF2E>other).x)
240
+ return r
241
+
242
+ def __sub__(ntl_GF2E self, other):
243
+ """
244
+ EXAMPLES::
245
+
246
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
247
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([1,1,0,1,1], ctx)
248
+ sage: x - y ## indirect doctest
249
+ [0 1 1 1]
250
+ """
251
+ cdef ntl_GF2E r
252
+ if not isinstance(other, ntl_GF2E):
253
+ other = ntl_GF2E(other,self.c)
254
+ elif self.c is not (<ntl_GF2E>other).c:
255
+ raise ValueError("You cannot perform arithmetic with elements in different fields.")
256
+ r = self._new()
257
+ GF2E_sub(r.x, self.x, (<ntl_GF2E>other).x)
258
+ return r
259
+
260
+ def __add__(ntl_GF2E self, other):
261
+ """
262
+ EXAMPLES::
263
+
264
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
265
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([1,1,0,1,1], ctx)
266
+ sage: x+y ## indirect doctest
267
+ [0 1 1 1]
268
+ """
269
+ cdef ntl_GF2E r
270
+ if not isinstance(other, ntl_GF2E):
271
+ other = ntl_GF2E(other,self.c)
272
+ elif self.c is not (<ntl_GF2E>other).c:
273
+ raise ValueError("You cannot perform arithmetic with elements in different fields.")
274
+ r = self._new()
275
+ GF2E_add(r.x, self.x, (<ntl_GF2E>other).x)
276
+ return r
277
+
278
+ def __truediv__(ntl_GF2E self, other):
279
+ """
280
+ EXAMPLES::
281
+
282
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
283
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([1,1,0,1,1], ctx)
284
+ sage: x/y ## indirect doctest
285
+ [1 0 1 0 0 1 0 1]
286
+ """
287
+ cdef ntl_GF2E r
288
+ if not isinstance(other, ntl_GF2E):
289
+ other = ntl_GF2E(other, self.c)
290
+ elif self.c is not (<ntl_GF2E>other).c:
291
+ raise ValueError("You cannot perform arithmetic with elements in different fields.")
292
+ r = self._new()
293
+ GF2E_div(r.x, self.x, (<ntl_GF2E>other).x)
294
+ return r
295
+
296
+ def __neg__(ntl_GF2E self):
297
+ """
298
+ EXAMPLES::
299
+
300
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
301
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx)
302
+ sage: -x ## indirect doctest
303
+ [1 0 1 0 1]
304
+ """
305
+ cdef ntl_GF2E r = self._new()
306
+ r.x = self.x
307
+ return r
308
+
309
+ def __pow__(ntl_GF2E self, long e, ignored):
310
+ """
311
+ EXAMPLES::
312
+
313
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
314
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx)
315
+ sage: x**2 ## indirect doctest
316
+ [0 1 0 1]
317
+ """
318
+ cdef ntl_GF2E r = self._new()
319
+ GF2E_power(r.x, self.x, e)
320
+ return r
321
+
322
+ def __richcmp__(ntl_GF2E self, other, int op):
323
+ r"""
324
+ Compare ``self`` to ``other``.
325
+
326
+ EXAMPLES::
327
+
328
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
329
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([1,1,0,1,1], ctx)
330
+ sage: x == x
331
+ True
332
+ sage: x == y
333
+ False
334
+ sage: ntl.GF2E(0,ctx) == 0
335
+ True
336
+ sage: a = ntl.GF2E([0,1],GF(2^2,'a'))
337
+ sage: a == x
338
+ False
339
+ """
340
+ self.c.restore_c()
341
+
342
+ if op != Py_EQ and op != Py_NE:
343
+ raise TypeError("elements of GF(2^e) are not ordered")
344
+
345
+ cdef ntl_GF2E b
346
+ try:
347
+ b = <ntl_GF2E?>other
348
+ except TypeError:
349
+ b = ntl_GF2E(other, self.c)
350
+
351
+ return (op == Py_EQ) == (self.x == b.x)
352
+
353
+ def IsZero(ntl_GF2E self):
354
+ """
355
+ Return ``True`` if this element equals zero, ``False`` otherwise.
356
+
357
+ EXAMPLES::
358
+
359
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
360
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([1,1,0,1,1,0,0,0,1], ctx)
361
+ sage: x.IsZero()
362
+ False
363
+ sage: y.IsZero()
364
+ True
365
+ """
366
+ return bool(GF2E_IsZero(self.x))
367
+
368
+ def IsOne(ntl_GF2E self):
369
+ """
370
+ Return ``True`` if this element equals one, ``False`` otherwise.
371
+
372
+ EXAMPLES::
373
+
374
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
375
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([0,1,0,1,1,0,0,0,1], ctx)
376
+ sage: x.IsOne()
377
+ False
378
+ sage: y.IsOne()
379
+ True
380
+ """
381
+ return bool(GF2E_IsOne(self.x))
382
+
383
+ def trace(ntl_GF2E self):
384
+ """
385
+ Return the trace of this element.
386
+
387
+ EXAMPLES::
388
+
389
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
390
+ sage: x = ntl.GF2E([1,0,1,0,1], ctx) ; y = ntl.GF2E([0,1,1,0,1,1], ctx)
391
+ sage: x.trace()
392
+ 0
393
+ sage: y.trace()
394
+ 1
395
+ """
396
+ cdef ntl_GF2 x = ntl_GF2.__new__(ntl_GF2)
397
+ x.x = GF2E_trace(self.x)
398
+ return x
399
+
400
+ def rep(ntl_GF2E self):
401
+ """
402
+ Return a ntl.GF2X copy of this element.
403
+
404
+ EXAMPLES::
405
+
406
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
407
+ sage: a = ntl.GF2E('0x1c', ctx)
408
+ sage: a.rep()
409
+ [1 0 0 0 0 0 1 1]
410
+ sage: type(a.rep())
411
+ <class 'sage.libs.ntl.ntl_GF2X.ntl_GF2X'>
412
+ """
413
+ cdef ntl_GF2X x = ntl_GF2X.__new__(ntl_GF2X)
414
+ x.x = GF2E_rep(self.x)
415
+ return x
416
+
417
+ def list(ntl_GF2E self):
418
+ """
419
+ Represent this element as a list of binary digits.
420
+
421
+ EXAMPLES::
422
+
423
+ sage: e=ntl.GF2E([0,1,1],GF(2^4,'a'))
424
+ sage: e.list()
425
+ [0, 1, 1]
426
+ sage: e=ntl.GF2E('0xff',GF(2^8,'a'))
427
+ sage: e.list()
428
+ [1, 1, 1, 1, 1, 1, 1, 1]
429
+
430
+ OUTPUT: list of digits representing the coefficients in this element's
431
+ polynomial representation
432
+ """
433
+ cdef int i
434
+ cdef GF2X_c x = GF2E_rep(self.x)
435
+ cdef ntl_GF2 b
436
+
437
+ l = []
438
+
439
+ for i from 0 <= i <= GF2X_deg(x):
440
+ b = ntl_GF2.__new__(ntl_GF2)
441
+ b.x = GF2X_coeff(x,i)
442
+ l.append(b)
443
+ return l
444
+
445
+ def _sage_(ntl_GF2E self, k=None):
446
+ r"""
447
+ Return a :class:`FiniteFieldElement` representation of this element.
448
+
449
+ If a :class:`FiniteField` `k` is provided, it is constructed
450
+ in this field if possible. A :class:`FiniteField` will be
451
+ constructed if none is provided.
452
+
453
+ INPUT:
454
+
455
+ - ``k`` -- (optional) a field `\GF{2^d}`
456
+
457
+ OUTPUT: :class:`FiniteFieldElement` over `k`
458
+
459
+ EXAMPLES::
460
+
461
+ sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
462
+ sage: e = ntl.GF2E([0,1], ctx)
463
+ sage: a = e._sage_(); a
464
+ a
465
+ """
466
+ cdef int i
467
+ cdef int length
468
+
469
+ self.c.restore_c()
470
+
471
+ e = GF2E_degree()
472
+
473
+ if k is None:
474
+ from sage.rings.finite_rings.finite_field_constructor import FiniteField
475
+ f = self.c.m._sage_()
476
+ k = FiniteField(2**e, name='a', modulus=f)
477
+
478
+ a=k.gen()
479
+ l = self.list()
480
+
481
+ length = len(l)
482
+ ret = 0
483
+
484
+ for i from 0 <= i < length:
485
+ if l[i]==1:
486
+ ret = ret + a**i
487
+
488
+ return ret
@@ -0,0 +1,9 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ from sage.libs.ntl.types cimport GF2EContext_c
3
+ from sage.libs.ntl.ntl_GF2X cimport ntl_GF2X
4
+
5
+ cdef class ntl_GF2EContext_class():
6
+ cdef GF2EContext_c x
7
+ cdef ntl_GF2X m
8
+ cdef void restore_c(self) noexcept
9
+ cdef object __weakref__
@@ -0,0 +1,134 @@
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
+ #
13
+ # Distributed under the terms of the GNU General Public License (GPL)
14
+ #
15
+ # This code is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ # General Public License for more details.
19
+ #
20
+ # The full text of the GPL is available at:
21
+ #
22
+ # http://www.gnu.org/licenses/
23
+ #*****************************************************************************
24
+
25
+ include 'misc.pxi'
26
+ include 'decl.pxi'
27
+ import weakref
28
+
29
+ GF2EContextDict = {}
30
+
31
+
32
+ cdef class ntl_GF2EContext_class():
33
+ def __init__(self, ntl_GF2X v):
34
+ """
35
+ EXAMPLES::
36
+
37
+ # You can construct contexts manually.
38
+ sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1]))
39
+ sage: n1 = ntl.GF2E([1,1],ctx)
40
+ sage: n1
41
+ [1 1]
42
+
43
+ # or You can construct contexts implicitly.
44
+ sage: n2 = ntl.GF2E([0,1], ntl.GF2X([1,1,0,1]))
45
+ sage: n2
46
+ [0 1]
47
+ sage: ntl.GF2E(2, GF(2^8,'a'))+ntl.GF2E([0,1],ctx)
48
+ Traceback (most recent call last):
49
+ ...
50
+ ValueError: You cannot perform arithmetic with elements in different fields.
51
+
52
+ sage: n2+n1 # Mismatched moduli: It will go BOOM!
53
+ [1]
54
+ """
55
+ pass
56
+
57
+ def __cinit__(self, ntl_GF2X v):
58
+ self.x = GF2EContext_c(v.x)
59
+ self.m = v
60
+
61
+ def __reduce__(self):
62
+ """
63
+ EXAMPLES::
64
+
65
+ sage: c = ntl.GF2EContext(GF(2^5,'b'))
66
+ sage: loads(dumps(c)) is c
67
+ True
68
+ """
69
+ return ntl_GF2EContext, (self.m,)
70
+
71
+ def __repr__(self) -> str:
72
+ """
73
+ Return a print representation of ``self``.
74
+
75
+ EXAMPLES::
76
+
77
+ sage: c = ntl.GF2EContext(GF(2^16,'a'))
78
+ sage: c
79
+ NTL modulus [1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1]
80
+ """
81
+ return "NTL modulus %s" % (self.m)
82
+
83
+ def modulus(self):
84
+ """
85
+ Return the current modulus associated to this
86
+ context.
87
+
88
+ EXAMPLES::
89
+
90
+ sage: c = ntl.GF2EContext(GF(2^7,'foo'))
91
+ sage: c.modulus()
92
+ [1 1 0 0 0 0 0 1]
93
+ """
94
+ return self.m
95
+
96
+ def restore(self):
97
+ """
98
+ EXAMPLES::
99
+
100
+ sage: c1 = ntl.GF2E([0,1],GF(2^4,'a')) ; c2 = ntl.GF2E([1,0,1],GF(2^4,'a'))
101
+ sage: c1+c2
102
+ [1 1 1]
103
+ sage: d1 = ntl.GF2E([0,1],GF(2^5,'a')) ; d2 = ntl.GF2E([0,0,1],GF(2^5,'a'))
104
+ sage: d1*d2 ## indirect doctest
105
+ [0 0 0 1]
106
+ """
107
+ self.restore_c()
108
+
109
+ cdef void restore_c(self) noexcept:
110
+ self.x.restore()
111
+
112
+
113
+ def ntl_GF2EContext( v ):
114
+ """
115
+ Create a new GF2EContext.
116
+
117
+ EXAMPLES::
118
+
119
+ sage: c = ntl.GF2EContext(GF(2^2,'a'))
120
+ sage: n1 = ntl.GF2E([0,1],c)
121
+ sage: n1
122
+ [0 1]
123
+ """
124
+ v = ntl_GF2X(v)
125
+ if (GF2X_deg((<ntl_GF2X>v).x) < 1):
126
+ raise ValueError("%s is not a valid modulus." % v)
127
+ key = hash(v)
128
+ if key in GF2EContextDict:
129
+ context = GF2EContextDict[key]()
130
+ if context is not None:
131
+ return context
132
+ context = ntl_GF2EContext_class(v)
133
+ GF2EContextDict[key] = weakref.ref(context)
134
+ return context
@@ -0,0 +1,10 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ from sage.libs.ntl.types cimport GF2EX_c
3
+ from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class
4
+ from sage.libs.ntl.ntl_GF2E cimport ntl_GF2E
5
+
6
+ cdef class ntl_GF2EX():
7
+ cdef GF2EX_c x
8
+ cdef ntl_GF2EContext_class c
9
+ cdef ntl_GF2E _new_element(self)
10
+ cdef ntl_GF2EX _new(self)