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.
- passagemath_ntl-10.6.36.dist-info/METADATA +122 -0
- passagemath_ntl-10.6.36.dist-info/RECORD +161 -0
- passagemath_ntl-10.6.36.dist-info/WHEEL +6 -0
- passagemath_ntl-10.6.36.dist-info/top_level.txt +2 -0
- passagemath_ntl.libs/libgf2x-fbd36f80.so.3.0.0 +0 -0
- passagemath_ntl.libs/libgmp-93ebf16a.so.10.5.0 +0 -0
- passagemath_ntl.libs/libmpfi-ad12a86d.so.0.0.0 +0 -0
- passagemath_ntl.libs/libmpfr-9d41ebf1.so.6.2.1 +0 -0
- passagemath_ntl.libs/libntl-0043a3a2.so.44.0.1 +0 -0
- sage/all__sagemath_ntl.py +7 -0
- sage/libs/all__sagemath_ntl.py +3 -0
- sage/libs/mpfi/__init__.pxd +287 -0
- sage/libs/mpfi/types.pxd +10 -0
- sage/libs/ntl/GF2.pxd +18 -0
- sage/libs/ntl/GF2E.pxd +28 -0
- sage/libs/ntl/GF2EX.pxd +12 -0
- sage/libs/ntl/GF2X.pxd +81 -0
- sage/libs/ntl/ZZ.pxd +93 -0
- sage/libs/ntl/ZZX.pxd +85 -0
- sage/libs/ntl/ZZ_p.pxd +28 -0
- sage/libs/ntl/ZZ_pE.pxd +37 -0
- sage/libs/ntl/ZZ_pEX.pxd +106 -0
- sage/libs/ntl/ZZ_pX.pxd +122 -0
- sage/libs/ntl/__init__.py +4 -0
- sage/libs/ntl/all.py +72 -0
- sage/libs/ntl/conversion.pxd +106 -0
- sage/libs/ntl/convert.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/convert.pxd +7 -0
- sage/libs/ntl/convert.pyx +38 -0
- sage/libs/ntl/decl.pxi +18 -0
- sage/libs/ntl/error.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/error.pyx +63 -0
- sage/libs/ntl/lzz_p.pxd +20 -0
- sage/libs/ntl/lzz_pX.pxd +59 -0
- sage/libs/ntl/mat_GF2.pxd +30 -0
- sage/libs/ntl/mat_GF2E.pxd +30 -0
- sage/libs/ntl/mat_ZZ.pxd +59 -0
- sage/libs/ntl/misc.pxi +33 -0
- sage/libs/ntl/ntl_GF2.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_GF2.pxd +5 -0
- sage/libs/ntl/ntl_GF2.pyx +281 -0
- sage/libs/ntl/ntl_GF2E.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_GF2E.pxd +8 -0
- sage/libs/ntl/ntl_GF2E.pyx +488 -0
- sage/libs/ntl/ntl_GF2EContext.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_GF2EContext.pxd +9 -0
- sage/libs/ntl/ntl_GF2EContext.pyx +134 -0
- sage/libs/ntl/ntl_GF2EX.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_GF2EX.pxd +10 -0
- sage/libs/ntl/ntl_GF2EX.pyx +251 -0
- sage/libs/ntl/ntl_GF2X.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_GF2X.pxd +5 -0
- sage/libs/ntl/ntl_GF2X.pyx +771 -0
- sage/libs/ntl/ntl_GF2X_linkage.pxi +404 -0
- sage/libs/ntl/ntl_ZZ.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ.pxd +7 -0
- sage/libs/ntl/ntl_ZZ.pyx +541 -0
- sage/libs/ntl/ntl_ZZX.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZX.pxd +7 -0
- sage/libs/ntl/ntl_ZZX.pyx +1206 -0
- sage/libs/ntl/ntl_ZZ_p.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ_p.pxd +10 -0
- sage/libs/ntl/ntl_ZZ_p.pyx +509 -0
- sage/libs/ntl/ntl_ZZ_pContext.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ_pContext.pxd +22 -0
- sage/libs/ntl/ntl_ZZ_pContext.pyx +201 -0
- sage/libs/ntl/ntl_ZZ_pE.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ_pE.pxd +11 -0
- sage/libs/ntl/ntl_ZZ_pE.pyx +349 -0
- sage/libs/ntl/ntl_ZZ_pEContext.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ_pEContext.pxd +23 -0
- sage/libs/ntl/ntl_ZZ_pEContext.pyx +226 -0
- sage/libs/ntl/ntl_ZZ_pEX.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ_pEX.pxd +10 -0
- sage/libs/ntl/ntl_ZZ_pEX.pyx +1255 -0
- sage/libs/ntl/ntl_ZZ_pEX_linkage.pxi +420 -0
- sage/libs/ntl/ntl_ZZ_pX.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_ZZ_pX.pxd +17 -0
- sage/libs/ntl/ntl_ZZ_pX.pyx +1532 -0
- sage/libs/ntl/ntl_lzz_p.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_lzz_p.pxd +8 -0
- sage/libs/ntl/ntl_lzz_p.pyx +440 -0
- sage/libs/ntl/ntl_lzz_pContext.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_lzz_pContext.pxd +7 -0
- sage/libs/ntl/ntl_lzz_pContext.pyx +137 -0
- sage/libs/ntl/ntl_lzz_pX.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_lzz_pX.pxd +10 -0
- sage/libs/ntl/ntl_lzz_pX.pyx +902 -0
- sage/libs/ntl/ntl_mat_GF2.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_mat_GF2.pxd +8 -0
- sage/libs/ntl/ntl_mat_GF2.pyx +612 -0
- sage/libs/ntl/ntl_mat_GF2E.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_mat_GF2E.pxd +10 -0
- sage/libs/ntl/ntl_mat_GF2E.pyx +752 -0
- sage/libs/ntl/ntl_mat_ZZ.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/libs/ntl/ntl_mat_ZZ.pxd +6 -0
- sage/libs/ntl/ntl_mat_ZZ.pyx +1523 -0
- sage/libs/ntl/ntl_tools.pxd +3 -0
- sage/libs/ntl/ntlwrap.h +53 -0
- sage/libs/ntl/ntlwrap_impl.h +743 -0
- sage/libs/ntl/types.pxd +157 -0
- sage/libs/ntl/vec_GF2.pxd +26 -0
- sage/libs/ntl/vec_GF2E.pxd +2 -0
- sage/matrix/all__sagemath_ntl.py +1 -0
- sage/matrix/matrix_modn_dense_double.pxd +10 -0
- sage/matrix/matrix_modn_dense_float.pxd +9 -0
- sage/matrix/matrix_modn_dense_template.pxi +3257 -0
- sage/matrix/matrix_modn_dense_template_header.pxi +15 -0
- sage/matrix/matrix_modn_sparse.pxd +8 -0
- sage/misc/all__sagemath_ntl.py +1 -0
- sage/rings/all__sagemath_ntl.py +7 -0
- sage/rings/bernmm.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/bernmm.pyx +161 -0
- sage/rings/bernoulli_mod_p.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/bernoulli_mod_p.pyx +313 -0
- sage/rings/finite_rings/all__sagemath_ntl.py +1 -0
- sage/rings/finite_rings/finite_field_ntl_gf2e.py +305 -0
- sage/rings/finite_rings/residue_field_ntl_gf2e.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/finite_rings/residue_field_ntl_gf2e.pyx +140 -0
- sage/rings/padics/all__sagemath_ntl.py +5 -0
- sage/rings/padics/padic_ZZ_pX_CA_element.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/padics/padic_ZZ_pX_CA_element.pxd +25 -0
- sage/rings/padics/padic_ZZ_pX_CA_element.pyx +2368 -0
- sage/rings/padics/padic_ZZ_pX_CR_element.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/padics/padic_ZZ_pX_CR_element.pxd +33 -0
- sage/rings/padics/padic_ZZ_pX_CR_element.pyx +3277 -0
- sage/rings/padics/padic_ZZ_pX_FM_element.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/padics/padic_ZZ_pX_FM_element.pxd +12 -0
- sage/rings/padics/padic_ZZ_pX_FM_element.pyx +1739 -0
- sage/rings/padics/padic_ZZ_pX_element.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/padics/padic_ZZ_pX_element.pxd +6 -0
- sage/rings/padics/padic_ZZ_pX_element.pyx +919 -0
- sage/rings/padics/padic_ext_element.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/padics/padic_ext_element.pxd +38 -0
- sage/rings/padics/padic_ext_element.pyx +512 -0
- sage/rings/padics/pow_computer_ext.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/padics/pow_computer_ext.pxd +107 -0
- sage/rings/padics/pow_computer_ext.pyx +2401 -0
- sage/rings/polynomial/all__sagemath_ntl.py +1 -0
- sage/rings/polynomial/evaluation_ntl.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/polynomial/evaluation_ntl.pxd +7 -0
- sage/rings/polynomial/evaluation_ntl.pyx +70 -0
- sage/rings/polynomial/polynomial_gf2x.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/polynomial/polynomial_gf2x.pxd +10 -0
- sage/rings/polynomial/polynomial_gf2x.pyx +364 -0
- sage/rings/polynomial/polynomial_integer_dense_ntl.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/polynomial/polynomial_integer_dense_ntl.pxd +8 -0
- sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +1128 -0
- sage/rings/polynomial/polynomial_modn_dense_ntl.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/polynomial/polynomial_modn_dense_ntl.pxd +36 -0
- sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +2049 -0
- sage/rings/polynomial/polynomial_template.pxi +842 -0
- sage/rings/polynomial/polynomial_template_header.pxi +11 -0
- sage/rings/polynomial/polynomial_zz_pex.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/rings/polynomial/polynomial_zz_pex.pxd +12 -0
- sage/rings/polynomial/polynomial_zz_pex.pyx +778 -0
- sage/rings/real_mpfi.pxd +50 -0
- sage/schemes/all__sagemath_ntl.py +1 -0
- sage/schemes/hyperelliptic_curves/all__sagemath_ntl.py +1 -0
- sage/schemes/hyperelliptic_curves/hypellfrob.cpython-314t-aarch64-linux-gnu.so +0 -0
- sage/schemes/hyperelliptic_curves/hypellfrob.pyx +252 -0
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
|
|
9
|
+
#*****************************************************************************
|
|
10
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
11
|
+
#
|
|
12
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
13
|
+
#
|
|
14
|
+
# This code is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17
|
+
# General Public License for more details.
|
|
18
|
+
#
|
|
19
|
+
# The full text of the GPL is available at:
|
|
20
|
+
#
|
|
21
|
+
# http://www.gnu.org/licenses/
|
|
22
|
+
#*****************************************************************************
|
|
23
|
+
|
|
24
|
+
include 'misc.pxi'
|
|
25
|
+
include 'decl.pxi'
|
|
26
|
+
import weakref
|
|
27
|
+
|
|
28
|
+
from sage.ext.cplusplus cimport ccrepr
|
|
29
|
+
from sage.rings.integer cimport Integer
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
cdef class ntl_ZZ_pContext_class():
|
|
33
|
+
def __init__(self, ntl_ZZ v):
|
|
34
|
+
"""
|
|
35
|
+
EXAMPLES::
|
|
36
|
+
|
|
37
|
+
# You can construct contexts manually.
|
|
38
|
+
sage: c = ntl.ZZ_pContext(11)
|
|
39
|
+
sage: n1 = ntl.ZZ_p(12,c)
|
|
40
|
+
sage: n1
|
|
41
|
+
1
|
|
42
|
+
|
|
43
|
+
# or You can construct contexts implicitly.
|
|
44
|
+
sage: n2 = ntl.ZZ_p(12, 7)
|
|
45
|
+
sage: n2
|
|
46
|
+
5
|
|
47
|
+
sage: ntl.ZZ_p(2,3)+ntl.ZZ_p(1,3)
|
|
48
|
+
0
|
|
49
|
+
sage: n2+n1 # Mismatched moduli: It will go BOOM!
|
|
50
|
+
Traceback (most recent call last):
|
|
51
|
+
...
|
|
52
|
+
ValueError: You cannot perform arithmetic with elements of different moduli.
|
|
53
|
+
"""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
def __cinit__(self, ntl_ZZ v):
|
|
57
|
+
self.x = ZZ_pContext_c(v.x)
|
|
58
|
+
self.p = v
|
|
59
|
+
self.p_bits = self.p._integer_().nbits()
|
|
60
|
+
|
|
61
|
+
def __reduce__(self):
|
|
62
|
+
"""
|
|
63
|
+
EXAMPLES::
|
|
64
|
+
|
|
65
|
+
sage: c = ntl.ZZ_pContext(13)
|
|
66
|
+
sage: loads(dumps(c)) is c
|
|
67
|
+
True
|
|
68
|
+
"""
|
|
69
|
+
return ntl_ZZ_pContext, (self.p,)
|
|
70
|
+
|
|
71
|
+
def __repr__(self) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Return a print representation of ``self``.
|
|
74
|
+
|
|
75
|
+
EXAMPLES::
|
|
76
|
+
|
|
77
|
+
sage: c = ntl.ZZ_pContext(7)
|
|
78
|
+
sage: c
|
|
79
|
+
NTL modulus 7
|
|
80
|
+
"""
|
|
81
|
+
return "NTL modulus %s" % (self.p)
|
|
82
|
+
|
|
83
|
+
def __hash__(self):
|
|
84
|
+
return hash(self.p)
|
|
85
|
+
|
|
86
|
+
def modulus(self):
|
|
87
|
+
"""
|
|
88
|
+
Return the current modulus associated to this
|
|
89
|
+
context.
|
|
90
|
+
|
|
91
|
+
EXAMPLES::
|
|
92
|
+
|
|
93
|
+
sage: c = ntl.ZZ_pContext(7)
|
|
94
|
+
sage: c.modulus()
|
|
95
|
+
7
|
|
96
|
+
|
|
97
|
+
sage: c = ntl.ZZ_pContext(10^30)
|
|
98
|
+
sage: type(c.modulus())
|
|
99
|
+
<class 'sage.rings.integer.Integer'>
|
|
100
|
+
sage: c.modulus() == 10^30
|
|
101
|
+
True
|
|
102
|
+
"""
|
|
103
|
+
return Integer(self.p)
|
|
104
|
+
|
|
105
|
+
def restore(self):
|
|
106
|
+
"""
|
|
107
|
+
EXAMPLES::
|
|
108
|
+
|
|
109
|
+
sage: c1 = ntl.ZZ_p(5,92) ; c2 = ntl.ZZ_p(7,92)
|
|
110
|
+
sage: c1+c2
|
|
111
|
+
12
|
|
112
|
+
sage: d1 = ntl.ZZ_p(38,91) ; d2 = ntl.ZZ_p(3,91)
|
|
113
|
+
sage: d1*d2 ## indirect doctest
|
|
114
|
+
23
|
|
115
|
+
"""
|
|
116
|
+
self.restore_c()
|
|
117
|
+
|
|
118
|
+
cdef void restore_c(self) noexcept:
|
|
119
|
+
self.x.restore()
|
|
120
|
+
|
|
121
|
+
cpdef void _assert_is_current_modulus(self) except *:
|
|
122
|
+
"""
|
|
123
|
+
Assert that is currently-set NTL modulus.
|
|
124
|
+
|
|
125
|
+
Mostly for debugging purposes. If false, an assertion is raised. This method segfaults if
|
|
126
|
+
the NTL modulus has never been set before.
|
|
127
|
+
|
|
128
|
+
EXAMPLES::
|
|
129
|
+
|
|
130
|
+
sage: c1 = ntl.ZZ_pContext(7)
|
|
131
|
+
sage: c2 = ntl.ZZ_pContext(5)
|
|
132
|
+
sage: c1.restore()
|
|
133
|
+
sage: c1._assert_is_current_modulus()
|
|
134
|
+
sage: c2._assert_is_current_modulus()
|
|
135
|
+
Traceback (most recent call last):
|
|
136
|
+
...
|
|
137
|
+
AssertionError: modulus mismatch: 5 != 7
|
|
138
|
+
sage: c2.restore()
|
|
139
|
+
sage: c1._assert_is_current_modulus()
|
|
140
|
+
Traceback (most recent call last):
|
|
141
|
+
...
|
|
142
|
+
AssertionError: modulus mismatch: 7 != 5
|
|
143
|
+
sage: c2._assert_is_current_modulus()
|
|
144
|
+
sage: ntl.ZZ_pContext(3).restore()
|
|
145
|
+
sage: c1._assert_is_current_modulus()
|
|
146
|
+
Traceback (most recent call last):
|
|
147
|
+
...
|
|
148
|
+
AssertionError: modulus mismatch: 7 != 3
|
|
149
|
+
sage: c2._assert_is_current_modulus()
|
|
150
|
+
Traceback (most recent call last):
|
|
151
|
+
...
|
|
152
|
+
AssertionError: modulus mismatch: 5 != 3
|
|
153
|
+
"""
|
|
154
|
+
if self.p.x == ntl_ZZ_p_current_modulus():
|
|
155
|
+
return
|
|
156
|
+
raise AssertionError('modulus mismatch: {} != {}'.format(
|
|
157
|
+
self.p,
|
|
158
|
+
ccrepr(ntl_ZZ_p_current_modulus())))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
cdef class ntl_ZZ_pContext_factory():
|
|
162
|
+
|
|
163
|
+
def __init__(self):
|
|
164
|
+
self.context_dict = {}
|
|
165
|
+
|
|
166
|
+
cdef ntl_ZZ_pContext_class make_c(self, ntl_ZZ v):
|
|
167
|
+
"""
|
|
168
|
+
Create a new ZZ_pContext.
|
|
169
|
+
|
|
170
|
+
INPUT:
|
|
171
|
+
|
|
172
|
+
- ``v`` -- an ntl_ZZ
|
|
173
|
+
"""
|
|
174
|
+
cdef ntl_ZZ_pContext_class context
|
|
175
|
+
if v in self.context_dict:
|
|
176
|
+
context = <ntl_ZZ_pContext_class> self.context_dict[v]()
|
|
177
|
+
if context is not None:
|
|
178
|
+
return context
|
|
179
|
+
context = ntl_ZZ_pContext_class(v)
|
|
180
|
+
self.context_dict[v] = weakref.ref(context)
|
|
181
|
+
return context
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
ZZ_pContext_factory = ntl_ZZ_pContext_factory()
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def ntl_ZZ_pContext( v ):
|
|
188
|
+
"""
|
|
189
|
+
Create a new ZZ_pContext.
|
|
190
|
+
|
|
191
|
+
EXAMPLES::
|
|
192
|
+
|
|
193
|
+
sage: c = ntl.ZZ_pContext(178)
|
|
194
|
+
sage: n1 = ntl.ZZ_p(212,c)
|
|
195
|
+
sage: n1
|
|
196
|
+
34
|
|
197
|
+
"""
|
|
198
|
+
v = ntl_ZZ(v)
|
|
199
|
+
if (v < ntl_ZZ(2)):
|
|
200
|
+
raise ValueError("%s is not a valid modulus." % v)
|
|
201
|
+
return (<ntl_ZZ_pContext_factory>ZZ_pContext_factory).make_c(v)
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
from sage.libs.ntl.types cimport ZZ_pE_c
|
|
3
|
+
from sage.libs.ntl.ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class
|
|
4
|
+
from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX
|
|
5
|
+
|
|
6
|
+
cdef class ntl_ZZ_pE():
|
|
7
|
+
cdef ZZ_pE_c x
|
|
8
|
+
cdef ntl_ZZ_pEContext_class c
|
|
9
|
+
cdef ntl_ZZ_pX get_as_ZZ_pX(ntl_ZZ_pE self)
|
|
10
|
+
cdef void set_from_ZZ_pX(ntl_ZZ_pE self, ntl_ZZ_pX value) noexcept
|
|
11
|
+
cdef ntl_ZZ_pE _new(self)
|
|
@@ -0,0 +1,349 @@
|
|
|
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
|
+
|
|
9
|
+
#*****************************************************************************
|
|
10
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
11
|
+
#
|
|
12
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
13
|
+
#
|
|
14
|
+
# This code is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17
|
+
# General Public License for more details.
|
|
18
|
+
#
|
|
19
|
+
# The full text of the GPL is available at:
|
|
20
|
+
#
|
|
21
|
+
# http://www.gnu.org/licenses/
|
|
22
|
+
#*****************************************************************************
|
|
23
|
+
|
|
24
|
+
from cysignals.signals cimport sig_on, sig_off
|
|
25
|
+
from sage.ext.cplusplus cimport ccrepr, ccreadstr
|
|
26
|
+
|
|
27
|
+
include 'misc.pxi'
|
|
28
|
+
include 'decl.pxi'
|
|
29
|
+
|
|
30
|
+
from cpython.object cimport Py_EQ, Py_NE
|
|
31
|
+
|
|
32
|
+
from sage.rings.integer_ring import IntegerRing
|
|
33
|
+
from sage.rings.integer cimport Integer
|
|
34
|
+
from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ
|
|
35
|
+
from sage.libs.ntl.ntl_ZZ_p cimport ntl_ZZ_p
|
|
36
|
+
from sage.rings.integer cimport Integer
|
|
37
|
+
|
|
38
|
+
from sage.libs.ntl.convert cimport PyLong_to_ZZ, mpz_to_ZZ
|
|
39
|
+
|
|
40
|
+
from sage.libs.ntl.ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class
|
|
41
|
+
from sage.libs.ntl.ntl_ZZ_pEContext import ntl_ZZ_pEContext
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
ZZ_sage = IntegerRing()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
##############################################################################
|
|
48
|
+
#
|
|
49
|
+
# ZZ_pE_c: An extension of the integers modulo p
|
|
50
|
+
#
|
|
51
|
+
##############################################################################
|
|
52
|
+
cdef class ntl_ZZ_pE():
|
|
53
|
+
r"""
|
|
54
|
+
The \class{ZZ_pE} class is used to model `\Z / p\Z [x] / (f(x))`.
|
|
55
|
+
The modulus `p` may be any positive integer, not necessarily prime,
|
|
56
|
+
and the modulus f is not required to be irreducible.
|
|
57
|
+
|
|
58
|
+
Objects of the class \class{ZZ_pE} are represented as a \code{ZZ_pX} of
|
|
59
|
+
degree less than the degree of `f`.
|
|
60
|
+
|
|
61
|
+
Each \class{ZZ_pE} contains a pointer of a \class{ZZ_pEContext} which
|
|
62
|
+
contains pre-computed data for NTL. These can be explicitly constructed
|
|
63
|
+
and passed to the constructor of a \class{ZZ_pE} or the \class{ZZ_pEContext}
|
|
64
|
+
method \code{ZZ_pE} can be used to construct a \class{ZZ_pE} element.
|
|
65
|
+
|
|
66
|
+
This class takes care of making sure that the C++ library NTL global
|
|
67
|
+
variable is set correctly before performing any arithmetic.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
def __init__(self, v=None, modulus=None):
|
|
71
|
+
r"""
|
|
72
|
+
Initialize an ntl ZZ_pE.
|
|
73
|
+
|
|
74
|
+
EXAMPLES::
|
|
75
|
+
|
|
76
|
+
sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1],11))
|
|
77
|
+
sage: c.ZZ_pE([13,4,1])
|
|
78
|
+
[1 3]
|
|
79
|
+
sage: c.ZZ_pE(Integer(95413094))
|
|
80
|
+
[7]
|
|
81
|
+
sage: c.ZZ_pE('[1]')
|
|
82
|
+
[1]
|
|
83
|
+
|
|
84
|
+
AUTHOR: David Roe (2007-9-25)
|
|
85
|
+
"""
|
|
86
|
+
if isinstance(modulus, ntl_ZZ_pEContext_class):
|
|
87
|
+
self.c = <ntl_ZZ_pEContext_class>modulus
|
|
88
|
+
elif isinstance(modulus, ntl_ZZ_pX):
|
|
89
|
+
modulus.get_modulus_context().restore()
|
|
90
|
+
self.c = <ntl_ZZ_pEContext_class>ntl_ZZ_pEContext(<ntl_ZZ_pX>modulus)
|
|
91
|
+
elif isinstance(v, ntl_ZZ_pE):
|
|
92
|
+
self.c = (<ntl_ZZ_pE>v).c
|
|
93
|
+
elif isinstance(v, tuple) and len(v) == 2 and isinstance(v[1], ntl_ZZ_pEContext_class):
|
|
94
|
+
self.c = v[1]
|
|
95
|
+
v = v[0]
|
|
96
|
+
else:
|
|
97
|
+
raise ValueError("You must specify a modulus when creating a ZZ_pE.")
|
|
98
|
+
self.c.restore_c()
|
|
99
|
+
|
|
100
|
+
cdef ZZ_c temp
|
|
101
|
+
cdef ntl_ZZ_pX tmp_zzpx
|
|
102
|
+
if v is not None:
|
|
103
|
+
if isinstance(v, ntl_ZZ_pE):
|
|
104
|
+
if (<ntl_ZZ_pE>v).c is not self.c:
|
|
105
|
+
raise ValueError("You cannot cast between rings with different moduli")
|
|
106
|
+
self.x = (<ntl_ZZ_pE>v).x
|
|
107
|
+
elif isinstance(v, ntl_ZZ_pX):
|
|
108
|
+
if (<ntl_ZZ_pX>v).c is not self.c.pc:
|
|
109
|
+
raise ValueError("You cannot cast between rings with different moduli")
|
|
110
|
+
self.x = ZZ_pX_to_ZZ_pE((<ntl_ZZ_pX>v).x)
|
|
111
|
+
elif isinstance(v, (list, tuple)):
|
|
112
|
+
tmp_zzpx = <ntl_ZZ_pX>ntl_ZZ_pX(v, self.c.pc)
|
|
113
|
+
self.c.restore_c() # allocating tmp_zzpx can change the current modulus; Issue #25790
|
|
114
|
+
self.x = ZZ_pX_to_ZZ_pE(tmp_zzpx.x)
|
|
115
|
+
elif isinstance(v, int):
|
|
116
|
+
PyLong_to_ZZ(&temp, v)
|
|
117
|
+
self.x = ZZ_to_ZZ_pE(temp)
|
|
118
|
+
elif isinstance(v, ntl_ZZ_p):
|
|
119
|
+
self.x = ZZ_p_to_ZZ_pE((<ntl_ZZ_p>v).x)
|
|
120
|
+
elif isinstance(v, ntl_ZZ):
|
|
121
|
+
self.x = ZZ_to_ZZ_pE((<ntl_ZZ>v).x)
|
|
122
|
+
elif isinstance(v, Integer):
|
|
123
|
+
mpz_to_ZZ(&temp, (<Integer>v).value)
|
|
124
|
+
self.x = ZZ_to_ZZ_pE(temp)
|
|
125
|
+
else:
|
|
126
|
+
str_v = str(v) # can cause modulus to change; Issue #25790
|
|
127
|
+
self.c.restore_c()
|
|
128
|
+
ccreadstr(self.x, str_v)
|
|
129
|
+
|
|
130
|
+
def __cinit__(ntl_ZZ_pE self, v=None, modulus=None):
|
|
131
|
+
#################### WARNING ###################
|
|
132
|
+
## Before creating a ZZ_pE, you must create a ##
|
|
133
|
+
## ZZ_pEContext, and restore it. In Python, ##
|
|
134
|
+
## the error checking in __init__ will prevent##
|
|
135
|
+
## you from constructing an ntl_ZZ_pE ##
|
|
136
|
+
## inappropriately. However, from Cython, you##
|
|
137
|
+
## could do r = ntl_ZZ_pE.__new__(ntl_ZZ_pE) without
|
|
138
|
+
## first restoring a ZZ_pEContext, which could##
|
|
139
|
+
## have unfortunate consequences. See _new ##
|
|
140
|
+
## defined below for an example of the right ##
|
|
141
|
+
## way to short-circuit __init__ (or just call##
|
|
142
|
+
## _new in your own code). ##
|
|
143
|
+
################################################
|
|
144
|
+
if modulus is None:
|
|
145
|
+
return
|
|
146
|
+
if isinstance(modulus, ntl_ZZ_pEContext_class):
|
|
147
|
+
self.c = <ntl_ZZ_pEContext_class>modulus
|
|
148
|
+
self.c.restore_c()
|
|
149
|
+
else:
|
|
150
|
+
self.c = <ntl_ZZ_pEContext_class>ntl_ZZ_pEContext(modulus)
|
|
151
|
+
self.c.restore_c()
|
|
152
|
+
|
|
153
|
+
cdef ntl_ZZ_pE _new(self):
|
|
154
|
+
cdef ntl_ZZ_pE r
|
|
155
|
+
self.c.restore_c()
|
|
156
|
+
r = ntl_ZZ_pE.__new__(ntl_ZZ_pE)
|
|
157
|
+
r.c = self.c
|
|
158
|
+
return r
|
|
159
|
+
|
|
160
|
+
def __reduce__(self):
|
|
161
|
+
"""
|
|
162
|
+
EXAMPLES::
|
|
163
|
+
|
|
164
|
+
sage: a = ntl.ZZ_pE([4],ntl.ZZ_pX([1,1,1],ntl.ZZ(7)))
|
|
165
|
+
sage: loads(dumps(a)) == a
|
|
166
|
+
True
|
|
167
|
+
"""
|
|
168
|
+
return make_ZZ_pE, (self.get_as_ZZ_pX(), self.get_modulus_context())
|
|
169
|
+
|
|
170
|
+
def get_modulus_context(self):
|
|
171
|
+
return self.c
|
|
172
|
+
|
|
173
|
+
def __repr__(self):
|
|
174
|
+
self.c.restore_c()
|
|
175
|
+
return ccrepr(self.x)
|
|
176
|
+
|
|
177
|
+
def __richcmp__(ntl_ZZ_pE self, other, int op):
|
|
178
|
+
r"""
|
|
179
|
+
Compare ``self`` to ``other``.
|
|
180
|
+
|
|
181
|
+
EXAMPLES::
|
|
182
|
+
|
|
183
|
+
sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1],11))
|
|
184
|
+
sage: c.ZZ_pE([13,1,1])==c.ZZ_pE(1)
|
|
185
|
+
True
|
|
186
|
+
sage: c.ZZ_pE(35r)==c.ZZ_pE(1)
|
|
187
|
+
False
|
|
188
|
+
sage: c.ZZ_pE(35r) == 2
|
|
189
|
+
True
|
|
190
|
+
"""
|
|
191
|
+
self.c.restore_c()
|
|
192
|
+
|
|
193
|
+
if op != Py_EQ and op != Py_NE:
|
|
194
|
+
raise TypeError("integers mod p are not ordered")
|
|
195
|
+
|
|
196
|
+
cdef ntl_ZZ_pE b
|
|
197
|
+
try:
|
|
198
|
+
b = <ntl_ZZ_pE?>other
|
|
199
|
+
except TypeError:
|
|
200
|
+
b = ntl_ZZ_pE(other, self.c)
|
|
201
|
+
|
|
202
|
+
return (op == Py_EQ) == (self.x == b.x)
|
|
203
|
+
|
|
204
|
+
def __invert__(ntl_ZZ_pE self):
|
|
205
|
+
r"""
|
|
206
|
+
EXAMPLES::
|
|
207
|
+
|
|
208
|
+
sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([2,7,1],11))
|
|
209
|
+
sage: ~ntl.ZZ_pE([1,1],modulus=c)
|
|
210
|
+
[7 3]
|
|
211
|
+
"""
|
|
212
|
+
cdef ntl_ZZ_pE r = self._new()
|
|
213
|
+
sig_on()
|
|
214
|
+
self.c.restore_c()
|
|
215
|
+
ZZ_pE_inv(r.x, self.x)
|
|
216
|
+
sig_off()
|
|
217
|
+
return r
|
|
218
|
+
|
|
219
|
+
def __mul__(ntl_ZZ_pE self, other):
|
|
220
|
+
cdef ntl_ZZ_pE y
|
|
221
|
+
cdef ntl_ZZ_pE r = self._new()
|
|
222
|
+
if not isinstance(other, ntl_ZZ_pE):
|
|
223
|
+
other = ntl_ZZ_pE(other,self.c)
|
|
224
|
+
elif self.c is not (<ntl_ZZ_pE>other).c:
|
|
225
|
+
raise ValueError("You cannot perform arithmetic with elements of different moduli.")
|
|
226
|
+
y = other
|
|
227
|
+
self.c.restore_c()
|
|
228
|
+
ZZ_pE_mul(r.x, self.x, y.x)
|
|
229
|
+
return r
|
|
230
|
+
|
|
231
|
+
def __sub__(ntl_ZZ_pE self, other):
|
|
232
|
+
if not isinstance(other, ntl_ZZ_pE):
|
|
233
|
+
other = ntl_ZZ_pE(other,self.c)
|
|
234
|
+
elif self.c is not (<ntl_ZZ_pE>other).c:
|
|
235
|
+
raise ValueError("You cannot perform arithmetic with elements of different moduli.")
|
|
236
|
+
cdef ntl_ZZ_pE r = self._new()
|
|
237
|
+
self.c.restore_c()
|
|
238
|
+
ZZ_pE_sub(r.x, self.x, (<ntl_ZZ_pE>other).x)
|
|
239
|
+
return r
|
|
240
|
+
|
|
241
|
+
def __add__(ntl_ZZ_pE self, other):
|
|
242
|
+
cdef ntl_ZZ_pE y
|
|
243
|
+
cdef ntl_ZZ_pE r = self._new()
|
|
244
|
+
if not isinstance(other, ntl_ZZ_pE):
|
|
245
|
+
other = ntl_ZZ_pE(other,modulus=self.c)
|
|
246
|
+
elif self.c is not (<ntl_ZZ_pE>other).c:
|
|
247
|
+
raise ValueError("You cannot perform arithmetic with elements of different moduli.")
|
|
248
|
+
y = other
|
|
249
|
+
sig_on()
|
|
250
|
+
self.c.restore_c()
|
|
251
|
+
ZZ_pE_add(r.x, self.x, y.x)
|
|
252
|
+
sig_off()
|
|
253
|
+
return r
|
|
254
|
+
|
|
255
|
+
def __neg__(ntl_ZZ_pE self):
|
|
256
|
+
cdef ntl_ZZ_pE r = self._new()
|
|
257
|
+
sig_on()
|
|
258
|
+
self.c.restore_c()
|
|
259
|
+
ZZ_pE_negate(r.x, self.x)
|
|
260
|
+
sig_off()
|
|
261
|
+
return r
|
|
262
|
+
|
|
263
|
+
def __pow__(ntl_ZZ_pE self, long e, ignored):
|
|
264
|
+
cdef ntl_ZZ_pE r = self._new()
|
|
265
|
+
sig_on()
|
|
266
|
+
self.c.restore_c()
|
|
267
|
+
ZZ_pE_power(r.x, self.x, e)
|
|
268
|
+
sig_off()
|
|
269
|
+
return r
|
|
270
|
+
|
|
271
|
+
cdef ntl_ZZ_pX get_as_ZZ_pX(ntl_ZZ_pE self):
|
|
272
|
+
r"""
|
|
273
|
+
Return value as ntl_ZZ_pX.
|
|
274
|
+
"""
|
|
275
|
+
self.c.restore_c()
|
|
276
|
+
cdef ntl_ZZ_pX y = ntl_ZZ_pX.__new__(ntl_ZZ_pX)
|
|
277
|
+
y.c = self.c.pc
|
|
278
|
+
sig_on()
|
|
279
|
+
y.x = ZZ_pE_to_ZZ_pX(self.x)
|
|
280
|
+
sig_off()
|
|
281
|
+
return y
|
|
282
|
+
|
|
283
|
+
def get_as_ZZ_pX_doctest(self):
|
|
284
|
+
r"""
|
|
285
|
+
This method exists solely for automated testing of get_as_ZZ_pX().
|
|
286
|
+
|
|
287
|
+
sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1],11))
|
|
288
|
+
sage: x = ntl.ZZ_pE([42,1],modulus=c)
|
|
289
|
+
sage: i = x.get_as_ZZ_pX_doctest()
|
|
290
|
+
sage: i
|
|
291
|
+
[9 1]
|
|
292
|
+
sage: type(i)
|
|
293
|
+
<class 'sage.libs.ntl.ntl_ZZ_pX.ntl_ZZ_pX'>
|
|
294
|
+
"""
|
|
295
|
+
return self.get_as_ZZ_pX()
|
|
296
|
+
|
|
297
|
+
cdef void set_from_ZZ_pX(ntl_ZZ_pE self, ntl_ZZ_pX value) noexcept:
|
|
298
|
+
r"""
|
|
299
|
+
Set the value from a ZZ_pX.
|
|
300
|
+
"""
|
|
301
|
+
self.c.restore_c()
|
|
302
|
+
self.x = ZZ_pX_to_ZZ_pE(value.x)
|
|
303
|
+
|
|
304
|
+
def set_from_ZZ_pX_doctest(self, value):
|
|
305
|
+
r"""
|
|
306
|
+
This method exists solely for automated testing of set_from_ZZ_pX().
|
|
307
|
+
|
|
308
|
+
sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1],11))
|
|
309
|
+
sage: x = ntl.ZZ_pE(modulus=c)
|
|
310
|
+
sage: x.set_from_ZZ_pX_doctest(ntl.ZZ_pX([5,2,1],11))
|
|
311
|
+
sage: x
|
|
312
|
+
[4 1]
|
|
313
|
+
"""
|
|
314
|
+
self.set_from_ZZ_pX(value)
|
|
315
|
+
|
|
316
|
+
#def lift(self):
|
|
317
|
+
# cdef ntl_ZZ r = ntl_ZZ()
|
|
318
|
+
# self.c.restore_c()
|
|
319
|
+
# r.x = rep(self.x)
|
|
320
|
+
# return r
|
|
321
|
+
|
|
322
|
+
def modulus(self):
|
|
323
|
+
r"""
|
|
324
|
+
Return the modulus as an NTL ZZ_pX.
|
|
325
|
+
|
|
326
|
+
sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1],11))
|
|
327
|
+
sage: n=ntl.ZZ_pE([2983,233],c)
|
|
328
|
+
sage: n.modulus()
|
|
329
|
+
[1 1 1]
|
|
330
|
+
"""
|
|
331
|
+
self.c.restore_c()
|
|
332
|
+
cdef ntl_ZZ_pX r = ntl_ZZ_pX(v=None, modulus=self.c.pc)
|
|
333
|
+
r.x = (<ntl_ZZ_pX>self.c.f).x
|
|
334
|
+
return r
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def make_ZZ_pE(x, c):
|
|
338
|
+
"""
|
|
339
|
+
Here for unpickling.
|
|
340
|
+
|
|
341
|
+
EXAMPLES::
|
|
342
|
+
|
|
343
|
+
sage: c = ntl.ZZ_pEContext(ntl.ZZ_pX([-5,0,1],25))
|
|
344
|
+
sage: sage.libs.ntl.ntl_ZZ_pE.make_ZZ_pE([4,3], c)
|
|
345
|
+
[4 3]
|
|
346
|
+
sage: type(sage.libs.ntl.ntl_ZZ_pE.make_ZZ_pE([4,3], c))
|
|
347
|
+
<class 'sage.libs.ntl.ntl_ZZ_pE.ntl_ZZ_pE'>
|
|
348
|
+
"""
|
|
349
|
+
return ntl_ZZ_pE(x, c)
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
from sage.libs.ntl.types cimport ZZ_pContext_c, ZZ_pEContext_c
|
|
3
|
+
from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class
|
|
4
|
+
from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX
|
|
5
|
+
from sage.libs.ntl.types cimport ZZ_pX_Modulus_c
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
cdef struct ZZ_pEContext_ptrs:
|
|
9
|
+
ZZ_pEContext_c *zzpec
|
|
10
|
+
ZZ_pContext_c *zzpc
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
cdef class ntl_ZZ_pEContext_class():
|
|
14
|
+
cdef ZZ_pEContext_ptrs ptrs
|
|
15
|
+
cdef ZZ_pEContext_c x
|
|
16
|
+
cdef ntl_ZZ_pContext_class pc
|
|
17
|
+
cdef void restore_c(self) noexcept
|
|
18
|
+
cdef ntl_ZZ_pX f
|
|
19
|
+
cpdef void _assert_is_current_modulus(self) except *
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
cdef extern from "ntlwrap.h":
|
|
23
|
+
cdef ZZ_pX_Modulus_c& ZZ_pE_current_modulus "ZZ_pE::modulus"()
|