passagemath-ntl 10.6.37__cp311-cp311-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.
- passagemath_ntl/__init__.py +3 -0
- passagemath_ntl-10.6.37.dist-info/METADATA +122 -0
- passagemath_ntl-10.6.37.dist-info/RECORD +162 -0
- passagemath_ntl-10.6.37.dist-info/WHEEL +6 -0
- passagemath_ntl-10.6.37.dist-info/top_level.txt +3 -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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-aarch64-linux-gnu.so +0 -0
- sage/rings/bernmm.pyx +161 -0
- sage/rings/bernoulli_mod_p.cpython-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-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-311-aarch64-linux-gnu.so +0 -0
- sage/schemes/hyperelliptic_curves/hypellfrob.pyx +252 -0
sage/libs/ntl/ntl_ZZ.pyx
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
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
|
+
# https://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 sage.rings.integer cimport Integer
|
|
31
|
+
from sage.libs.ntl.convert cimport PyLong_to_ZZ, mpz_to_ZZ
|
|
32
|
+
from sage.misc.randstate cimport current_randstate
|
|
33
|
+
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
cdef make_ZZ(ZZ_c* x):
|
|
37
|
+
cdef ntl_ZZ y
|
|
38
|
+
y = ntl_ZZ()
|
|
39
|
+
y.x = x[0]
|
|
40
|
+
del x
|
|
41
|
+
sig_off()
|
|
42
|
+
return y
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
##############################################################################
|
|
46
|
+
# ZZ: Arbitrary precision integers
|
|
47
|
+
##############################################################################
|
|
48
|
+
|
|
49
|
+
cdef class ntl_ZZ():
|
|
50
|
+
r"""
|
|
51
|
+
The \class{ZZ} class is used to represent signed, arbitrary length integers.
|
|
52
|
+
|
|
53
|
+
Routines are provided for all of the basic arithmetic operations, as
|
|
54
|
+
well as for some more advanced operations such as primality testing.
|
|
55
|
+
Space is automatically managed by the constructors and destructors.
|
|
56
|
+
|
|
57
|
+
This module also provides routines for generating small primes, and
|
|
58
|
+
fast routines for performing modular arithmetic on single-precision
|
|
59
|
+
numbers.
|
|
60
|
+
"""
|
|
61
|
+
# See ntl.pxd for definition of data members
|
|
62
|
+
def __init__(self, v=None):
|
|
63
|
+
r"""
|
|
64
|
+
Initialize and NTL integer.
|
|
65
|
+
|
|
66
|
+
EXAMPLES::
|
|
67
|
+
|
|
68
|
+
sage: ntl.ZZ(12r)
|
|
69
|
+
12
|
|
70
|
+
sage: ntl.ZZ(Integer(95413094))
|
|
71
|
+
95413094
|
|
72
|
+
sage: ntl.ZZ('-1')
|
|
73
|
+
-1
|
|
74
|
+
sage: ntl.ZZ('1L')
|
|
75
|
+
1
|
|
76
|
+
sage: ntl.ZZ('-1r')
|
|
77
|
+
-1
|
|
78
|
+
|
|
79
|
+
TESTS::
|
|
80
|
+
|
|
81
|
+
sage: ntl.ZZ(int(2**40))
|
|
82
|
+
1099511627776
|
|
83
|
+
|
|
84
|
+
AUTHOR: Joel B. Mohler (2007-06-14)
|
|
85
|
+
"""
|
|
86
|
+
if isinstance(v, ntl_ZZ):
|
|
87
|
+
self.x = (<ntl_ZZ>v).x
|
|
88
|
+
elif isinstance(v, int):
|
|
89
|
+
PyLong_to_ZZ(&self.x, v)
|
|
90
|
+
elif isinstance(v, Integer):
|
|
91
|
+
self.set_from_sage_int(v)
|
|
92
|
+
elif v is not None:
|
|
93
|
+
v = str(v)
|
|
94
|
+
if not v:
|
|
95
|
+
v = '0'
|
|
96
|
+
if not ((v[0].isdigit() or v[0] == '-') and
|
|
97
|
+
(v[1:-1].isdigit() or (len(v) <= 2)) and
|
|
98
|
+
(v[-1].isdigit() or (v[-1].lower() in ['l','r']))):
|
|
99
|
+
raise ValueError("invalid integer: %s" % v)
|
|
100
|
+
ccreadstr(self.x, v)
|
|
101
|
+
|
|
102
|
+
def __repr__(self):
|
|
103
|
+
"""
|
|
104
|
+
Return the string representation of ``self``.
|
|
105
|
+
|
|
106
|
+
EXAMPLES::
|
|
107
|
+
|
|
108
|
+
sage: ntl.ZZ(5).__repr__()
|
|
109
|
+
'5'
|
|
110
|
+
"""
|
|
111
|
+
return ccrepr(self.x)
|
|
112
|
+
|
|
113
|
+
def __reduce__(self):
|
|
114
|
+
"""
|
|
115
|
+
sage: from sage.libs.ntl.ntl_ZZ import ntl_ZZ
|
|
116
|
+
sage: a = ntl_ZZ(-7)
|
|
117
|
+
sage: loads(dumps(a))
|
|
118
|
+
-7
|
|
119
|
+
"""
|
|
120
|
+
return unpickle_class_value, (ntl_ZZ, self._integer_())
|
|
121
|
+
|
|
122
|
+
def __richcmp__(ntl_ZZ self, other, int op):
|
|
123
|
+
"""
|
|
124
|
+
Compare ``self`` to ``other``.
|
|
125
|
+
|
|
126
|
+
EXAMPLES::
|
|
127
|
+
|
|
128
|
+
sage: f = ntl.ZZ(1)
|
|
129
|
+
sage: g = ntl.ZZ(2)
|
|
130
|
+
sage: h = ntl.ZZ(2)
|
|
131
|
+
sage: w = ntl.ZZ(7)
|
|
132
|
+
sage: h == g
|
|
133
|
+
True
|
|
134
|
+
sage: g >= h
|
|
135
|
+
True
|
|
136
|
+
sage: f == g
|
|
137
|
+
False
|
|
138
|
+
sage: h > w
|
|
139
|
+
False
|
|
140
|
+
sage: h < w
|
|
141
|
+
True
|
|
142
|
+
sage: h <= 3
|
|
143
|
+
True
|
|
144
|
+
"""
|
|
145
|
+
cdef ntl_ZZ b
|
|
146
|
+
try:
|
|
147
|
+
b = <ntl_ZZ?>other
|
|
148
|
+
except TypeError:
|
|
149
|
+
b = ntl_ZZ(other)
|
|
150
|
+
|
|
151
|
+
if op == Py_EQ:
|
|
152
|
+
return self.x == b.x
|
|
153
|
+
if op == Py_NE:
|
|
154
|
+
return self.x != b.x
|
|
155
|
+
if op == Py_LT:
|
|
156
|
+
return self.x < b.x
|
|
157
|
+
if op == Py_LE:
|
|
158
|
+
return self.x <= b.x
|
|
159
|
+
if op == Py_GT:
|
|
160
|
+
return self.x > b.x
|
|
161
|
+
if op == Py_GE:
|
|
162
|
+
return self.x >= b.x
|
|
163
|
+
|
|
164
|
+
def __hash__(self):
|
|
165
|
+
"""
|
|
166
|
+
Return the hash of this integer.
|
|
167
|
+
|
|
168
|
+
Agrees with the hash of the corresponding sage integer.
|
|
169
|
+
"""
|
|
170
|
+
cdef Integer v = Integer.__new__(Integer)
|
|
171
|
+
ZZ_to_mpz(v.value, &self.x)
|
|
172
|
+
return v.hash_c()
|
|
173
|
+
|
|
174
|
+
def __mul__(self, other):
|
|
175
|
+
"""
|
|
176
|
+
EXAMPLES::
|
|
177
|
+
|
|
178
|
+
sage: n=ntl.ZZ(2983)*ntl.ZZ(2)
|
|
179
|
+
sage: n
|
|
180
|
+
5966
|
|
181
|
+
"""
|
|
182
|
+
cdef ntl_ZZ r = ntl_ZZ.__new__(ntl_ZZ)
|
|
183
|
+
if not isinstance(self, ntl_ZZ):
|
|
184
|
+
self = ntl_ZZ(self)
|
|
185
|
+
if not isinstance(other, ntl_ZZ):
|
|
186
|
+
other = ntl_ZZ(other)
|
|
187
|
+
sig_on()
|
|
188
|
+
ZZ_mul(r.x, (<ntl_ZZ>self).x, (<ntl_ZZ>other).x)
|
|
189
|
+
sig_off()
|
|
190
|
+
return r
|
|
191
|
+
|
|
192
|
+
def __sub__(self, other):
|
|
193
|
+
"""
|
|
194
|
+
EXAMPLES::
|
|
195
|
+
|
|
196
|
+
sage: n=ntl.ZZ(2983)-ntl.ZZ(2)
|
|
197
|
+
sage: n
|
|
198
|
+
2981
|
|
199
|
+
sage: ntl.ZZ(2983)-2
|
|
200
|
+
2981
|
|
201
|
+
"""
|
|
202
|
+
cdef ntl_ZZ r = ntl_ZZ.__new__(ntl_ZZ)
|
|
203
|
+
if not isinstance(self, ntl_ZZ):
|
|
204
|
+
self = ntl_ZZ(self)
|
|
205
|
+
if not isinstance(other, ntl_ZZ):
|
|
206
|
+
other = ntl_ZZ(other)
|
|
207
|
+
ZZ_sub(r.x, (<ntl_ZZ>self).x, (<ntl_ZZ>other).x)
|
|
208
|
+
return r
|
|
209
|
+
|
|
210
|
+
def __add__(self, other):
|
|
211
|
+
"""
|
|
212
|
+
EXAMPLES::
|
|
213
|
+
|
|
214
|
+
sage: n=ntl.ZZ(2983)+ntl.ZZ(2)
|
|
215
|
+
sage: n
|
|
216
|
+
2985
|
|
217
|
+
sage: ntl.ZZ(23)+2
|
|
218
|
+
25
|
|
219
|
+
"""
|
|
220
|
+
cdef ntl_ZZ r = ntl_ZZ.__new__(ntl_ZZ)
|
|
221
|
+
if not isinstance(self, ntl_ZZ):
|
|
222
|
+
self = ntl_ZZ(self)
|
|
223
|
+
if not isinstance(other, ntl_ZZ):
|
|
224
|
+
other = ntl_ZZ(other)
|
|
225
|
+
ZZ_add(r.x, (<ntl_ZZ>self).x, (<ntl_ZZ>other).x)
|
|
226
|
+
return r
|
|
227
|
+
|
|
228
|
+
def __neg__(ntl_ZZ self):
|
|
229
|
+
"""
|
|
230
|
+
EXAMPLES::
|
|
231
|
+
|
|
232
|
+
sage: x = ntl.ZZ(38)
|
|
233
|
+
sage: -x
|
|
234
|
+
-38
|
|
235
|
+
sage: x.__neg__()
|
|
236
|
+
-38
|
|
237
|
+
"""
|
|
238
|
+
cdef ntl_ZZ r = ntl_ZZ.__new__(ntl_ZZ)
|
|
239
|
+
ZZ_negate(r.x, self.x)
|
|
240
|
+
return r
|
|
241
|
+
|
|
242
|
+
def __pow__(ntl_ZZ self, long e, ignored):
|
|
243
|
+
"""
|
|
244
|
+
EXAMPLES::
|
|
245
|
+
|
|
246
|
+
sage: ntl.ZZ(23)^50
|
|
247
|
+
122008981252869411022491112993141891091036959856659100591281395343249
|
|
248
|
+
"""
|
|
249
|
+
cdef ntl_ZZ r = ntl_ZZ()
|
|
250
|
+
sig_on()
|
|
251
|
+
ZZ_power(r.x, self.x, e)
|
|
252
|
+
sig_off()
|
|
253
|
+
return r
|
|
254
|
+
|
|
255
|
+
def __int__(self):
|
|
256
|
+
"""
|
|
257
|
+
Return ``self`` as an int.
|
|
258
|
+
|
|
259
|
+
EXAMPLES::
|
|
260
|
+
|
|
261
|
+
sage: ntl.ZZ(22).__int__()
|
|
262
|
+
22
|
|
263
|
+
sage: type(ntl.ZZ(22).__int__())
|
|
264
|
+
<... 'int'>
|
|
265
|
+
|
|
266
|
+
sage: ntl.ZZ(10^30).__int__()
|
|
267
|
+
1000000000000000000000000000000
|
|
268
|
+
sage: type(ntl.ZZ(10^30).__int__())
|
|
269
|
+
<class 'int'>
|
|
270
|
+
"""
|
|
271
|
+
return int(self._integer_())
|
|
272
|
+
|
|
273
|
+
cdef int get_as_int(ntl_ZZ self) noexcept:
|
|
274
|
+
r"""
|
|
275
|
+
Return value as C int.
|
|
276
|
+
|
|
277
|
+
Return value is only valid if the result fits into an int.
|
|
278
|
+
|
|
279
|
+
AUTHOR: David Harvey (2006-08-05)
|
|
280
|
+
"""
|
|
281
|
+
cdef int ans = 0
|
|
282
|
+
ZZ_conv_to_int(ans, self.x)
|
|
283
|
+
return ans
|
|
284
|
+
|
|
285
|
+
def get_as_int_doctest(self):
|
|
286
|
+
r"""
|
|
287
|
+
This method exists solely for automated testing of get_as_int().
|
|
288
|
+
|
|
289
|
+
EXAMPLES::
|
|
290
|
+
|
|
291
|
+
sage: x = ntl.ZZ(42)
|
|
292
|
+
sage: i = x.get_as_int_doctest()
|
|
293
|
+
sage: i
|
|
294
|
+
42
|
|
295
|
+
sage: type(i)
|
|
296
|
+
<... 'int'>
|
|
297
|
+
"""
|
|
298
|
+
return self.get_as_int()
|
|
299
|
+
|
|
300
|
+
def _integer_(self, ZZ=None):
|
|
301
|
+
r"""
|
|
302
|
+
Get the value as a sage int.
|
|
303
|
+
|
|
304
|
+
EXAMPLES::
|
|
305
|
+
|
|
306
|
+
sage: n=ntl.ZZ(2983)
|
|
307
|
+
sage: type(n._integer_())
|
|
308
|
+
<class 'sage.rings.integer.Integer'>
|
|
309
|
+
|
|
310
|
+
AUTHOR: Joel B. Mohler
|
|
311
|
+
"""
|
|
312
|
+
cdef Integer ans = Integer.__new__(Integer)
|
|
313
|
+
ZZ_to_mpz(ans.value, &self.x)
|
|
314
|
+
return ans
|
|
315
|
+
|
|
316
|
+
cdef void set_from_int(ntl_ZZ self, int value) noexcept:
|
|
317
|
+
r"""
|
|
318
|
+
Set the value from a C int.
|
|
319
|
+
|
|
320
|
+
AUTHOR: David Harvey (2006-08-05)
|
|
321
|
+
"""
|
|
322
|
+
ZZ_conv_from_int(self.x, value)
|
|
323
|
+
|
|
324
|
+
def set_from_sage_int(self, Integer value):
|
|
325
|
+
r"""
|
|
326
|
+
Set the value from a sage int.
|
|
327
|
+
|
|
328
|
+
EXAMPLES::
|
|
329
|
+
|
|
330
|
+
sage: n=ntl.ZZ(2983)
|
|
331
|
+
sage: n
|
|
332
|
+
2983
|
|
333
|
+
sage: n.set_from_sage_int(1234)
|
|
334
|
+
sage: n
|
|
335
|
+
1234
|
|
336
|
+
|
|
337
|
+
AUTHOR: Joel B. Mohler
|
|
338
|
+
"""
|
|
339
|
+
sig_on()
|
|
340
|
+
mpz_to_ZZ(&self.x, value.value)
|
|
341
|
+
sig_off()
|
|
342
|
+
|
|
343
|
+
def set_from_int_doctest(self, value):
|
|
344
|
+
r"""
|
|
345
|
+
This method exists solely for automated testing of set_from_int().
|
|
346
|
+
|
|
347
|
+
EXAMPLES::
|
|
348
|
+
|
|
349
|
+
sage: x = ntl.ZZ()
|
|
350
|
+
sage: x.set_from_int_doctest(42)
|
|
351
|
+
sage: x
|
|
352
|
+
42
|
|
353
|
+
"""
|
|
354
|
+
self.set_from_int(int(value))
|
|
355
|
+
|
|
356
|
+
def valuation(self, ntl_ZZ prime):
|
|
357
|
+
"""
|
|
358
|
+
Uses code in ``ntlwrap_impl.h`` to compute the number of times
|
|
359
|
+
prime divides ``self``.
|
|
360
|
+
|
|
361
|
+
EXAMPLES::
|
|
362
|
+
|
|
363
|
+
sage: a = ntl.ZZ(5^7*3^4)
|
|
364
|
+
sage: p = ntl.ZZ(5)
|
|
365
|
+
sage: a.valuation(p)
|
|
366
|
+
7
|
|
367
|
+
sage: a.valuation(-p)
|
|
368
|
+
7
|
|
369
|
+
sage: b = ntl.ZZ(0)
|
|
370
|
+
sage: b.valuation(p)
|
|
371
|
+
+Infinity
|
|
372
|
+
"""
|
|
373
|
+
cdef ntl_ZZ ans = ntl_ZZ.__new__(ntl_ZZ)
|
|
374
|
+
cdef ntl_ZZ unit = ntl_ZZ.__new__(ntl_ZZ)
|
|
375
|
+
cdef long valuation
|
|
376
|
+
if ZZ_IsZero(self.x):
|
|
377
|
+
from sage.rings.infinity import infinity
|
|
378
|
+
return infinity
|
|
379
|
+
sig_on()
|
|
380
|
+
valuation = ZZ_remove(unit.x, self.x, prime.x)
|
|
381
|
+
sig_off()
|
|
382
|
+
ZZ_conv_from_long(ans.x, valuation)
|
|
383
|
+
return ans
|
|
384
|
+
|
|
385
|
+
def val_unit(self, ntl_ZZ prime):
|
|
386
|
+
"""
|
|
387
|
+
Uses code in ``ntlwrap_impl.h`` to compute `p`-adic valuation and
|
|
388
|
+
unit of ``self``.
|
|
389
|
+
|
|
390
|
+
EXAMPLES::
|
|
391
|
+
|
|
392
|
+
sage: a = ntl.ZZ(5^7*3^4)
|
|
393
|
+
sage: p = ntl.ZZ(-5)
|
|
394
|
+
sage: a.val_unit(p)
|
|
395
|
+
(7, -81)
|
|
396
|
+
sage: a.val_unit(ntl.ZZ(-3))
|
|
397
|
+
(4, 78125)
|
|
398
|
+
sage: a.val_unit(ntl.ZZ(2))
|
|
399
|
+
(0, 6328125)
|
|
400
|
+
"""
|
|
401
|
+
cdef ntl_ZZ val = ntl_ZZ.__new__(ntl_ZZ)
|
|
402
|
+
cdef ntl_ZZ unit = ntl_ZZ.__new__(ntl_ZZ)
|
|
403
|
+
cdef long valuation
|
|
404
|
+
sig_on()
|
|
405
|
+
valuation = ZZ_remove(unit.x, self.x, prime.x)
|
|
406
|
+
sig_off()
|
|
407
|
+
ZZ_conv_from_long(val.x, valuation)
|
|
408
|
+
return val, unit
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def unpickle_class_value(cls, x):
|
|
412
|
+
"""
|
|
413
|
+
Here for unpickling.
|
|
414
|
+
|
|
415
|
+
EXAMPLES::
|
|
416
|
+
|
|
417
|
+
sage: sage.libs.ntl.ntl_ZZ.unpickle_class_value(ntl.ZZ, 3)
|
|
418
|
+
3
|
|
419
|
+
sage: type(sage.libs.ntl.ntl_ZZ.unpickle_class_value(ntl.ZZ, 3))
|
|
420
|
+
<class 'sage.libs.ntl.ntl_ZZ.ntl_ZZ'>
|
|
421
|
+
"""
|
|
422
|
+
return cls(x)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def unpickle_class_args(cls, x):
|
|
426
|
+
"""
|
|
427
|
+
Here for unpickling.
|
|
428
|
+
|
|
429
|
+
EXAMPLES::
|
|
430
|
+
|
|
431
|
+
sage: sage.libs.ntl.ntl_ZZ.unpickle_class_args(ntl.ZZ, [3])
|
|
432
|
+
3
|
|
433
|
+
sage: type(sage.libs.ntl.ntl_ZZ.unpickle_class_args(ntl.ZZ, [3]))
|
|
434
|
+
<class 'sage.libs.ntl.ntl_ZZ.ntl_ZZ'>
|
|
435
|
+
"""
|
|
436
|
+
return cls(*x)
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
# Random-number generation
|
|
440
|
+
def ntl_setSeed(x=None):
|
|
441
|
+
r"""
|
|
442
|
+
Seed the NTL random number generator.
|
|
443
|
+
|
|
444
|
+
This is automatically called when you set the main Sage random
|
|
445
|
+
number seed, then call any NTL routine requiring random numbers;
|
|
446
|
+
so you should never need to call this directly.
|
|
447
|
+
|
|
448
|
+
If for some reason you do need to call this directly, then
|
|
449
|
+
you need to get a random number from NTL (so that Sage will
|
|
450
|
+
seed NTL), then call this function and Sage will not notice.
|
|
451
|
+
|
|
452
|
+
EXAMPLES:
|
|
453
|
+
|
|
454
|
+
This is automatically seeded from the main Sage random number seed::
|
|
455
|
+
|
|
456
|
+
sage: set_random_seed(0)
|
|
457
|
+
sage: ntl.ZZ_random(1000)
|
|
458
|
+
979
|
|
459
|
+
|
|
460
|
+
Now you can call this function, and it will not be overridden until
|
|
461
|
+
the next time the main Sage random number seed is changed::
|
|
462
|
+
|
|
463
|
+
sage: ntl.ntl_setSeed(10)
|
|
464
|
+
sage: ntl.ZZ_random(1000)
|
|
465
|
+
935
|
|
466
|
+
"""
|
|
467
|
+
cdef ntl_ZZ seed = ntl_ZZ(1)
|
|
468
|
+
if x is None:
|
|
469
|
+
from random import randint
|
|
470
|
+
seed = ntl_ZZ(randint(0,int(2)**64))
|
|
471
|
+
else:
|
|
472
|
+
seed = ntl_ZZ(x)
|
|
473
|
+
sig_on()
|
|
474
|
+
ZZ_SetSeed(seed.x)
|
|
475
|
+
sig_off()
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
ntl_setSeed()
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def randomBnd(q):
|
|
482
|
+
r"""
|
|
483
|
+
Return a random number in the range `[0, n)`.
|
|
484
|
+
|
|
485
|
+
According to the NTL documentation, these numbers are
|
|
486
|
+
"cryptographically strong"; of course, that depends in part on
|
|
487
|
+
how they are seeded.
|
|
488
|
+
|
|
489
|
+
EXAMPLES::
|
|
490
|
+
|
|
491
|
+
sage: n = 99999
|
|
492
|
+
sage: l = [ntl.ZZ_random(n) for i in range(5)]
|
|
493
|
+
sage: all(type(m) is sage.libs.ntl.ntl_ZZ.ntl_ZZ for m in l)
|
|
494
|
+
True
|
|
495
|
+
sage: all(0 <= m < n for m in l)
|
|
496
|
+
True
|
|
497
|
+
|
|
498
|
+
AUTHOR:
|
|
499
|
+
|
|
500
|
+
- Didier Deshommes <dfdeshom@gmail.com>
|
|
501
|
+
"""
|
|
502
|
+
current_randstate().set_seed_ntl(False)
|
|
503
|
+
|
|
504
|
+
cdef ntl_ZZ w
|
|
505
|
+
|
|
506
|
+
if not isinstance(q, ntl_ZZ):
|
|
507
|
+
q = ntl_ZZ(q)
|
|
508
|
+
w = q
|
|
509
|
+
cdef ntl_ZZ ans
|
|
510
|
+
ans = ntl_ZZ.__new__(ntl_ZZ)
|
|
511
|
+
sig_on()
|
|
512
|
+
ZZ_RandomBnd(ans.x, w.x)
|
|
513
|
+
sig_off()
|
|
514
|
+
return ans
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def randomBits(long n):
|
|
518
|
+
r"""
|
|
519
|
+
Return a pseudo-random number in the range `[0, 2^n)`.
|
|
520
|
+
|
|
521
|
+
EXAMPLES::
|
|
522
|
+
|
|
523
|
+
sage: l = [ntl.ZZ_random_bits(20) for i in range(3)]
|
|
524
|
+
sage: all(0 <= m < 2^20 for m in l)
|
|
525
|
+
True
|
|
526
|
+
sage: l = [ntl.ZZ_random_bits(3) for i in range(10)]
|
|
527
|
+
sage: all(0 <= m < 8 for m in l)
|
|
528
|
+
True
|
|
529
|
+
|
|
530
|
+
AUTHOR:
|
|
531
|
+
|
|
532
|
+
- Didier Deshommes <dfdeshom@gmail.com>
|
|
533
|
+
"""
|
|
534
|
+
current_randstate().set_seed_ntl(False)
|
|
535
|
+
|
|
536
|
+
cdef ntl_ZZ ans
|
|
537
|
+
ans = ntl_ZZ.__new__(ntl_ZZ)
|
|
538
|
+
sig_on()
|
|
539
|
+
ZZ_RandomBits(ans.x, n)
|
|
540
|
+
sig_off()
|
|
541
|
+
return ans
|
|
Binary file
|