passagemath-ntl 10.6.38__cp314-cp314-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.38.dist-info/METADATA +122 -0
- passagemath_ntl-10.6.38.dist-info/RECORD +162 -0
- passagemath_ntl-10.6.38.dist-info/WHEEL +6 -0
- passagemath_ntl-10.6.38.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-1bc30f7e.so.45.0.0 +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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-gnu.so +0 -0
- sage/rings/bernmm.pyx +161 -0
- sage/rings/bernoulli_mod_p.cpython-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-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-314-aarch64-linux-gnu.so +0 -0
- sage/schemes/hyperelliptic_curves/hypellfrob.pyx +252 -0
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
from sage.libs.ntl.types cimport ZZ_p_c
|
|
3
|
+
from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class
|
|
4
|
+
|
|
5
|
+
cdef class ntl_ZZ_p():
|
|
6
|
+
cdef ZZ_p_c x
|
|
7
|
+
cdef ntl_ZZ_pContext_class c
|
|
8
|
+
cdef int get_as_int(ntl_ZZ_p self) noexcept
|
|
9
|
+
cdef void set_from_int(ntl_ZZ_p self, int value) noexcept
|
|
10
|
+
cdef ntl_ZZ_p _new(self)
|
|
@@ -0,0 +1,509 @@
|
|
|
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 cpython.object cimport Py_EQ, Py_NE
|
|
31
|
+
from sage.rings.integer import Integer
|
|
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.rings.rational cimport Rational
|
|
36
|
+
|
|
37
|
+
from sage.libs.ntl.ntl_ZZ import unpickle_class_args
|
|
38
|
+
from sage.libs.ntl.convert cimport PyLong_to_ZZ, mpz_to_ZZ
|
|
39
|
+
|
|
40
|
+
from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class
|
|
41
|
+
from sage.libs.ntl.ntl_ZZ_pContext import ntl_ZZ_pContext
|
|
42
|
+
|
|
43
|
+
from sage.misc.randstate cimport current_randstate
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
ZZ_sage = IntegerRing()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def ntl_ZZ_p_random_element(v):
|
|
50
|
+
"""
|
|
51
|
+
Return a random number modulo p.
|
|
52
|
+
|
|
53
|
+
EXAMPLES::
|
|
54
|
+
|
|
55
|
+
sage: a = sage.libs.ntl.ntl_ZZ_p.ntl_ZZ_p_random_element(17)
|
|
56
|
+
sage: type(a)
|
|
57
|
+
<class 'sage.libs.ntl.ntl_ZZ_p.ntl_ZZ_p'>
|
|
58
|
+
sage: a.modulus()
|
|
59
|
+
17
|
|
60
|
+
"""
|
|
61
|
+
current_randstate().set_seed_ntl(False)
|
|
62
|
+
|
|
63
|
+
cdef ntl_ZZ_p y
|
|
64
|
+
v = ntl_ZZ_pContext(v)
|
|
65
|
+
y = ntl_ZZ_p(0,v)
|
|
66
|
+
sig_on()
|
|
67
|
+
ZZ_p_random(y.x)
|
|
68
|
+
sig_off()
|
|
69
|
+
return y
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
##############################################################################
|
|
73
|
+
#
|
|
74
|
+
# ZZ_p_c: integers modulo p
|
|
75
|
+
#
|
|
76
|
+
##############################################################################
|
|
77
|
+
cdef class ntl_ZZ_p():
|
|
78
|
+
r"""
|
|
79
|
+
The \class{ZZ_p} class is used to represent integers modulo `p`.
|
|
80
|
+
The modulus `p` may be any positive integer, not necessarily prime.
|
|
81
|
+
|
|
82
|
+
Objects of the class \class{ZZ_p} are represented as a \code{ZZ} in the
|
|
83
|
+
range `0, \ldots, p-1`.
|
|
84
|
+
|
|
85
|
+
Each \class{ZZ_p} contains a pointer of a \class{ZZ_pContext} which
|
|
86
|
+
contains pre-computed data for NTL. These can be explicitly constructed
|
|
87
|
+
and passed to the constructor of a \class{ZZ_p} or the \class{ZZ_pContext}
|
|
88
|
+
method \code{ZZ_p} can be used to construct a \class{ZZ_p} element.
|
|
89
|
+
|
|
90
|
+
This class takes care of making sure that the C++ library NTL global
|
|
91
|
+
variable is set correctly before performing any arithmetic.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
def __init__(self, v=None, modulus=None):
|
|
95
|
+
r"""
|
|
96
|
+
Initialize an NTL integer mod p.
|
|
97
|
+
|
|
98
|
+
EXAMPLES::
|
|
99
|
+
|
|
100
|
+
sage: c = ntl.ZZ_pContext(11)
|
|
101
|
+
sage: ntl.ZZ_p(12r, c)
|
|
102
|
+
1
|
|
103
|
+
sage: ntl.ZZ_p(Integer(95413094), c)
|
|
104
|
+
7
|
|
105
|
+
sage: ntl.ZZ_p('-1', c)
|
|
106
|
+
10
|
|
107
|
+
|
|
108
|
+
AUTHOR: Joel B. Mohler (2007-06-14)
|
|
109
|
+
"""
|
|
110
|
+
if modulus is None:
|
|
111
|
+
raise ValueError("You must specify a modulus when creating a ZZ_p.")
|
|
112
|
+
|
|
113
|
+
# self.c._assert_is_current_modulus() # The context was restored in __new__
|
|
114
|
+
|
|
115
|
+
cdef ZZ_c temp, num, den
|
|
116
|
+
cdef long failed
|
|
117
|
+
if v is not None:
|
|
118
|
+
if isinstance(v, ntl_ZZ_p):
|
|
119
|
+
self.x = (<ntl_ZZ_p>v).x
|
|
120
|
+
elif isinstance(v, int):
|
|
121
|
+
PyLong_to_ZZ(&temp, v)
|
|
122
|
+
self.x = ZZ_to_ZZ_p(temp)
|
|
123
|
+
elif isinstance(v, Integer):
|
|
124
|
+
mpz_to_ZZ(&temp, (<Integer>v).value)
|
|
125
|
+
self.x = ZZ_to_ZZ_p(temp)
|
|
126
|
+
elif isinstance(v, Rational):
|
|
127
|
+
mpz_to_ZZ(&num, (<Integer>v.numerator()).value)
|
|
128
|
+
mpz_to_ZZ(&den, (<Integer>v.denominator()).value)
|
|
129
|
+
ZZ_p_div(self.x, ZZ_to_ZZ_p(num), ZZ_to_ZZ_p(den))
|
|
130
|
+
else:
|
|
131
|
+
str_v = str(v) # can cause modulus to change; Issue #25790
|
|
132
|
+
self.c.restore_c()
|
|
133
|
+
ccreadstr(self.x, str_v)
|
|
134
|
+
|
|
135
|
+
def __cinit__(self, v=None, modulus=None):
|
|
136
|
+
#################### WARNING ###################
|
|
137
|
+
## Before creating a ZZ_p, you must create a ##
|
|
138
|
+
## ZZ_pContext, and restore it. In Python, ##
|
|
139
|
+
## the error checking in __init__ will prevent##
|
|
140
|
+
## you from constructing an ntl_ZZ_p ##
|
|
141
|
+
## inappropriately. However, from Cython, you##
|
|
142
|
+
## could do r = ntl_ZZ_p.__new__(ntl_ZZ_p) without
|
|
143
|
+
## first restoring a ZZ_pContext, which could ##
|
|
144
|
+
## have unfortunate consequences. See _new ##
|
|
145
|
+
## defined below for an example of the right ##
|
|
146
|
+
## way to short-circuit __init__ (or just call##
|
|
147
|
+
## _new in your own code). ##
|
|
148
|
+
################################################
|
|
149
|
+
if modulus is None:
|
|
150
|
+
return
|
|
151
|
+
if isinstance(modulus, ntl_ZZ_pContext_class):
|
|
152
|
+
self.c = <ntl_ZZ_pContext_class>modulus
|
|
153
|
+
self.c.restore_c()
|
|
154
|
+
else:
|
|
155
|
+
self.c = <ntl_ZZ_pContext_class>ntl_ZZ_pContext(modulus)
|
|
156
|
+
self.c.restore_c()
|
|
157
|
+
|
|
158
|
+
cdef ntl_ZZ_p _new(self):
|
|
159
|
+
cdef ntl_ZZ_p r
|
|
160
|
+
self.c.restore_c()
|
|
161
|
+
r = ntl_ZZ_p.__new__(ntl_ZZ_p)
|
|
162
|
+
r.c = self.c
|
|
163
|
+
return r
|
|
164
|
+
|
|
165
|
+
def __reduce__(self):
|
|
166
|
+
"""
|
|
167
|
+
EXAMPLES::
|
|
168
|
+
|
|
169
|
+
sage: a = ntl.ZZ_p(4,7)
|
|
170
|
+
sage: loads(dumps(a)) == a
|
|
171
|
+
True
|
|
172
|
+
"""
|
|
173
|
+
return unpickle_class_args, (ntl_ZZ_p, (self.lift(), self.modulus_context()))
|
|
174
|
+
|
|
175
|
+
def modulus_context(self):
|
|
176
|
+
"""
|
|
177
|
+
Return the modulus for ``self``.
|
|
178
|
+
|
|
179
|
+
EXAMPLES::
|
|
180
|
+
|
|
181
|
+
sage: x = ntl.ZZ_p(5,17)
|
|
182
|
+
sage: c = x.modulus_context()
|
|
183
|
+
sage: y = ntl.ZZ_p(3,c)
|
|
184
|
+
sage: x+y
|
|
185
|
+
8
|
|
186
|
+
sage: c == y.modulus_context()
|
|
187
|
+
True
|
|
188
|
+
sage: c == ntl.ZZ_p(7,17).modulus_context()
|
|
189
|
+
True
|
|
190
|
+
"""
|
|
191
|
+
return self.c
|
|
192
|
+
|
|
193
|
+
def __repr__(self):
|
|
194
|
+
"""
|
|
195
|
+
Return the string representation of ``self``.
|
|
196
|
+
|
|
197
|
+
EXAMPLES::
|
|
198
|
+
|
|
199
|
+
sage: ntl.ZZ_p(7,192).__repr__()
|
|
200
|
+
'7'
|
|
201
|
+
"""
|
|
202
|
+
self.c.restore_c()
|
|
203
|
+
return ccrepr(self.x)
|
|
204
|
+
|
|
205
|
+
def __richcmp__(ntl_ZZ_p self, other, int op):
|
|
206
|
+
r"""
|
|
207
|
+
Compare ``self`` to ``other``.
|
|
208
|
+
|
|
209
|
+
EXAMPLES::
|
|
210
|
+
|
|
211
|
+
sage: c = ntl.ZZ_pContext(11)
|
|
212
|
+
sage: ntl.ZZ_p(12r, c) == ntl.ZZ_p(1, c)
|
|
213
|
+
True
|
|
214
|
+
sage: ntl.ZZ_p(35r, c) == ntl.ZZ_p(1, c)
|
|
215
|
+
False
|
|
216
|
+
sage: "2" == ntl.ZZ_p(35r, c)
|
|
217
|
+
True
|
|
218
|
+
sage: ntl.ZZ_p(35r, c) == 2
|
|
219
|
+
True
|
|
220
|
+
"""
|
|
221
|
+
self.c.restore_c()
|
|
222
|
+
|
|
223
|
+
if op != Py_EQ and op != Py_NE:
|
|
224
|
+
raise TypeError("integers mod p are not ordered")
|
|
225
|
+
|
|
226
|
+
cdef ntl_ZZ_p b
|
|
227
|
+
try:
|
|
228
|
+
b = <ntl_ZZ_p?>other
|
|
229
|
+
except TypeError:
|
|
230
|
+
b = ntl_ZZ_p(other, self.c)
|
|
231
|
+
|
|
232
|
+
return (op == Py_EQ) == (self.x == b.x)
|
|
233
|
+
|
|
234
|
+
def __invert__(ntl_ZZ_p self):
|
|
235
|
+
r"""
|
|
236
|
+
EXAMPLES::
|
|
237
|
+
|
|
238
|
+
sage: c=ntl.ZZ_pContext(11)
|
|
239
|
+
sage: ~ntl.ZZ_p(2r,modulus=c)
|
|
240
|
+
6
|
|
241
|
+
"""
|
|
242
|
+
cdef ntl_ZZ_p r = self._new()
|
|
243
|
+
sig_on()
|
|
244
|
+
self.c.restore_c()
|
|
245
|
+
ZZ_p_inv(r.x, self.x)
|
|
246
|
+
sig_off()
|
|
247
|
+
return r
|
|
248
|
+
|
|
249
|
+
def __mul__(ntl_ZZ_p self, other):
|
|
250
|
+
"""
|
|
251
|
+
EXAMPLES::
|
|
252
|
+
|
|
253
|
+
sage: x = ntl.ZZ_p(5,31) ; y = ntl.ZZ_p(8,31)
|
|
254
|
+
sage: x*y ## indirect doctest
|
|
255
|
+
9
|
|
256
|
+
"""
|
|
257
|
+
cdef ntl_ZZ_p y
|
|
258
|
+
cdef ntl_ZZ_p r = self._new()
|
|
259
|
+
if not isinstance(other, ntl_ZZ_p):
|
|
260
|
+
other = ntl_ZZ_p(other,self.c)
|
|
261
|
+
elif self.c is not (<ntl_ZZ_p>other).c:
|
|
262
|
+
raise ValueError("You cannot perform arithmetic with elements of different moduli.")
|
|
263
|
+
y = other
|
|
264
|
+
self.c.restore_c()
|
|
265
|
+
ZZ_p_mul(r.x, self.x, y.x)
|
|
266
|
+
return r
|
|
267
|
+
|
|
268
|
+
def __sub__(ntl_ZZ_p self, other):
|
|
269
|
+
"""
|
|
270
|
+
EXAMPLES::
|
|
271
|
+
|
|
272
|
+
sage: x = ntl.ZZ_p(5,31) ; y = ntl.ZZ_p(8,31)
|
|
273
|
+
sage: x-y ## indirect doctest
|
|
274
|
+
28
|
|
275
|
+
sage: y-x
|
|
276
|
+
3
|
|
277
|
+
"""
|
|
278
|
+
if not isinstance(other, ntl_ZZ_p):
|
|
279
|
+
other = ntl_ZZ_p(other,self.c)
|
|
280
|
+
elif self.c is not (<ntl_ZZ_p>other).c:
|
|
281
|
+
raise ValueError("You cannot perform arithmetic with elements of different moduli.")
|
|
282
|
+
cdef ntl_ZZ_p r = self._new()
|
|
283
|
+
self.c.restore_c()
|
|
284
|
+
ZZ_p_sub(r.x, self.x, (<ntl_ZZ_p>other).x)
|
|
285
|
+
return r
|
|
286
|
+
|
|
287
|
+
def __add__(ntl_ZZ_p self, other):
|
|
288
|
+
"""
|
|
289
|
+
EXAMPLES::
|
|
290
|
+
|
|
291
|
+
sage: x = ntl.ZZ_p(5,31) ; y = ntl.ZZ_p(8,31)
|
|
292
|
+
sage: x+y ## indirect doctest
|
|
293
|
+
13
|
|
294
|
+
"""
|
|
295
|
+
cdef ntl_ZZ_p y
|
|
296
|
+
cdef ntl_ZZ_p r = ntl_ZZ_p(modulus=self.c)
|
|
297
|
+
if not isinstance(other, ntl_ZZ_p):
|
|
298
|
+
other = ntl_ZZ_p(other,modulus=self.c)
|
|
299
|
+
elif self.c is not (<ntl_ZZ_p>other).c:
|
|
300
|
+
raise ValueError("You cannot perform arithmetic with elements of different moduli.")
|
|
301
|
+
y = other
|
|
302
|
+
sig_on()
|
|
303
|
+
self.c.restore_c()
|
|
304
|
+
ZZ_p_add(r.x, self.x, y.x)
|
|
305
|
+
sig_off()
|
|
306
|
+
return r
|
|
307
|
+
|
|
308
|
+
def __neg__(ntl_ZZ_p self):
|
|
309
|
+
"""
|
|
310
|
+
EXAMPLES::
|
|
311
|
+
|
|
312
|
+
sage: x = ntl.ZZ_p(5,31)
|
|
313
|
+
sage: -x ## indirect doctest
|
|
314
|
+
26
|
|
315
|
+
"""
|
|
316
|
+
cdef ntl_ZZ_p r = ntl_ZZ_p(modulus=self.c)
|
|
317
|
+
sig_on()
|
|
318
|
+
self.c.restore_c()
|
|
319
|
+
ZZ_p_negate(r.x, self.x)
|
|
320
|
+
sig_off()
|
|
321
|
+
return r
|
|
322
|
+
|
|
323
|
+
def __pow__(ntl_ZZ_p self, long e, ignored):
|
|
324
|
+
"""
|
|
325
|
+
EXAMPLES::
|
|
326
|
+
|
|
327
|
+
sage: x = ntl.ZZ_p(5,31)
|
|
328
|
+
sage: x**3 ## indirect doctest
|
|
329
|
+
1
|
|
330
|
+
"""
|
|
331
|
+
cdef ntl_ZZ_p r = ntl_ZZ_p(modulus=self.c)
|
|
332
|
+
sig_on()
|
|
333
|
+
self.c.restore_c()
|
|
334
|
+
ZZ_p_power(r.x, self.x, e)
|
|
335
|
+
sig_off()
|
|
336
|
+
return r
|
|
337
|
+
|
|
338
|
+
def __int__(self):
|
|
339
|
+
"""
|
|
340
|
+
Return ``self`` as an int.
|
|
341
|
+
|
|
342
|
+
EXAMPLES::
|
|
343
|
+
|
|
344
|
+
sage: x = ntl.ZZ_p(3,8)
|
|
345
|
+
sage: x.__int__()
|
|
346
|
+
3
|
|
347
|
+
sage: type(x.__int__())
|
|
348
|
+
<... 'int'>
|
|
349
|
+
"""
|
|
350
|
+
return self.get_as_int()
|
|
351
|
+
|
|
352
|
+
cdef int get_as_int(ntl_ZZ_p self) noexcept:
|
|
353
|
+
r"""
|
|
354
|
+
Return value as C int.
|
|
355
|
+
Return value is only valid if the result fits into an int.
|
|
356
|
+
|
|
357
|
+
AUTHOR: David Harvey (2006-08-05)
|
|
358
|
+
"""
|
|
359
|
+
self.c.restore_c()
|
|
360
|
+
return ZZ_p_to_int(self.x)
|
|
361
|
+
|
|
362
|
+
def _get_as_int_doctest(self):
|
|
363
|
+
r"""
|
|
364
|
+
This method exists solely for automated testing of get_as_int().
|
|
365
|
+
|
|
366
|
+
EXAMPLES::
|
|
367
|
+
|
|
368
|
+
sage: c = ntl.ZZ_pContext(20)
|
|
369
|
+
sage: x = ntl.ZZ_p(42,modulus=c)
|
|
370
|
+
sage: i = x._get_as_int_doctest()
|
|
371
|
+
sage: i
|
|
372
|
+
2
|
|
373
|
+
sage: type(i)
|
|
374
|
+
<... 'int'>
|
|
375
|
+
"""
|
|
376
|
+
self.c.restore_c()
|
|
377
|
+
return self.get_as_int()
|
|
378
|
+
|
|
379
|
+
cdef void set_from_int(ntl_ZZ_p self, int value) noexcept:
|
|
380
|
+
r"""
|
|
381
|
+
Set the value from a C int.
|
|
382
|
+
|
|
383
|
+
AUTHOR: David Harvey (2006-08-05)
|
|
384
|
+
"""
|
|
385
|
+
self.c.restore_c()
|
|
386
|
+
self.x = int_to_ZZ_p(value)
|
|
387
|
+
|
|
388
|
+
def _set_from_int_doctest(self, value):
|
|
389
|
+
r"""
|
|
390
|
+
This method exists solely for automated testing of set_from_int().
|
|
391
|
+
|
|
392
|
+
EXAMPLES::
|
|
393
|
+
|
|
394
|
+
sage: c=ntl.ZZ_pContext(ntl.ZZ(20))
|
|
395
|
+
sage: x = ntl.ZZ_p(modulus=c)
|
|
396
|
+
sage: x._set_from_int_doctest(42)
|
|
397
|
+
sage: x
|
|
398
|
+
2
|
|
399
|
+
sage: x = ntl.ZZ_p(7,81)
|
|
400
|
+
sage: x._set_from_int_doctest(int(3))
|
|
401
|
+
sage: x
|
|
402
|
+
3
|
|
403
|
+
"""
|
|
404
|
+
self.c.restore_c()
|
|
405
|
+
self.set_from_int(int(value))
|
|
406
|
+
|
|
407
|
+
def lift(self):
|
|
408
|
+
"""
|
|
409
|
+
Return a lift of ``self`` as an ntl.ZZ object.
|
|
410
|
+
|
|
411
|
+
EXAMPLES::
|
|
412
|
+
|
|
413
|
+
sage: x = ntl.ZZ_p(8,18)
|
|
414
|
+
sage: x.lift()
|
|
415
|
+
8
|
|
416
|
+
sage: type(x.lift())
|
|
417
|
+
<class 'sage.libs.ntl.ntl_ZZ.ntl_ZZ'>
|
|
418
|
+
"""
|
|
419
|
+
cdef ntl_ZZ r = ntl_ZZ()
|
|
420
|
+
self.c.restore_c()
|
|
421
|
+
r.x = ZZ_p_rep(self.x)
|
|
422
|
+
return r
|
|
423
|
+
|
|
424
|
+
def modulus(self):
|
|
425
|
+
r"""
|
|
426
|
+
Return the modulus as an NTL ZZ.
|
|
427
|
+
|
|
428
|
+
EXAMPLES::
|
|
429
|
+
|
|
430
|
+
sage: c = ntl.ZZ_pContext(ntl.ZZ(20))
|
|
431
|
+
sage: n = ntl.ZZ_p(2983,c)
|
|
432
|
+
sage: n.modulus()
|
|
433
|
+
20
|
|
434
|
+
"""
|
|
435
|
+
cdef ntl_ZZ r = ntl_ZZ()
|
|
436
|
+
self.c.restore_c()
|
|
437
|
+
ZZ_p_modulus( &r.x, &self.x )
|
|
438
|
+
return r
|
|
439
|
+
|
|
440
|
+
def lift_centered(self):
|
|
441
|
+
"""
|
|
442
|
+
Compute a representative of ``self`` in `(-n/2 , n/2]` as an
|
|
443
|
+
``ntl.ZZ`` object.
|
|
444
|
+
|
|
445
|
+
OUTPUT:
|
|
446
|
+
|
|
447
|
+
- A ``ntl.ZZ`` object `r` such that `-n/2 < r \\leq n/2` and `Mod(r, n) == self`.
|
|
448
|
+
|
|
449
|
+
EXAMPLES::
|
|
450
|
+
|
|
451
|
+
sage: x = ntl.ZZ_p(8, 18)
|
|
452
|
+
sage: x.lift_centered()
|
|
453
|
+
8
|
|
454
|
+
sage: type(x.lift_centered())
|
|
455
|
+
<class 'sage.libs.ntl.ntl_ZZ.ntl_ZZ'>
|
|
456
|
+
sage: x = ntl.ZZ_p(12, 18)
|
|
457
|
+
sage: x.lift_centered()
|
|
458
|
+
-6
|
|
459
|
+
sage: type(x.lift_centered())
|
|
460
|
+
<class 'sage.libs.ntl.ntl_ZZ.ntl_ZZ'>
|
|
461
|
+
"""
|
|
462
|
+
cdef ntl_ZZ r = self.lift()
|
|
463
|
+
cdef ntl_ZZ m = self.modulus()
|
|
464
|
+
if r*2 > m:
|
|
465
|
+
r -= m
|
|
466
|
+
return r
|
|
467
|
+
|
|
468
|
+
def _integer_(self, ZZ=None):
|
|
469
|
+
"""
|
|
470
|
+
Return a lift of ``self`` as a Sage integer.
|
|
471
|
+
|
|
472
|
+
EXAMPLES::
|
|
473
|
+
|
|
474
|
+
sage: x = ntl.ZZ_p(8,188)
|
|
475
|
+
sage: x._integer_()
|
|
476
|
+
8
|
|
477
|
+
|
|
478
|
+
sage: type(x._integer_())
|
|
479
|
+
<class 'sage.rings.integer.Integer'>
|
|
480
|
+
"""
|
|
481
|
+
self.c.restore_c()
|
|
482
|
+
cdef ZZ_c rep = ZZ_p_rep(self.x)
|
|
483
|
+
cdef Integer ans = Integer.__new__(Integer)
|
|
484
|
+
ZZ_to_mpz(ans.value, &rep)
|
|
485
|
+
return ans
|
|
486
|
+
|
|
487
|
+
def _sage_(self):
|
|
488
|
+
r"""
|
|
489
|
+
Return the value as a sage IntegerModRing.
|
|
490
|
+
|
|
491
|
+
EXAMPLES::
|
|
492
|
+
|
|
493
|
+
sage: c = ntl.ZZ_pContext(20)
|
|
494
|
+
sage: n = ntl.ZZ_p(2983, c)
|
|
495
|
+
sage: type(n._sage_())
|
|
496
|
+
<class 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
|
|
497
|
+
sage: n
|
|
498
|
+
3
|
|
499
|
+
|
|
500
|
+
AUTHOR: Joel B. Mohler
|
|
501
|
+
"""
|
|
502
|
+
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
|
|
503
|
+
|
|
504
|
+
cdef ZZ_c rep
|
|
505
|
+
self.c.restore_c()
|
|
506
|
+
rep = ZZ_p_rep(self.x)
|
|
507
|
+
cdef Integer ans = Integer.__new__(Integer)
|
|
508
|
+
ZZ_to_mpz(ans.value, &rep)
|
|
509
|
+
return IntegerModRing(self.modulus()._integer_())(ans)
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
from sage.libs.ntl.types cimport ZZ_pContext_c
|
|
3
|
+
from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ
|
|
4
|
+
from sage.libs.ntl.types cimport ZZ_c
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
cdef class ntl_ZZ_pContext_class():
|
|
8
|
+
cdef ZZ_pContext_c x
|
|
9
|
+
cdef void restore_c(self) noexcept
|
|
10
|
+
cdef ntl_ZZ p
|
|
11
|
+
cdef double p_bits
|
|
12
|
+
cdef object __weakref__
|
|
13
|
+
cpdef void _assert_is_current_modulus(self) except *
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
cdef class ntl_ZZ_pContext_factory():
|
|
17
|
+
cdef object context_dict
|
|
18
|
+
cdef ntl_ZZ_pContext_class make_c(self, ntl_ZZ v)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
cdef extern from "ntlwrap.h":
|
|
22
|
+
cdef const ZZ_c& ntl_ZZ_p_current_modulus "ZZ_p::modulus"()
|