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,612 @@
|
|
|
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
|
+
r"""
|
|
10
|
+
Matrices over the `\GF{2}` via NTL
|
|
11
|
+
|
|
12
|
+
This class is only provided to have a complete NTL interface and for
|
|
13
|
+
comparison purposes. Sage's native matrices over `F_2` are much faster
|
|
14
|
+
for many problems like matrix multiplication and Gaussian elimination.
|
|
15
|
+
|
|
16
|
+
AUTHORS:
|
|
17
|
+
|
|
18
|
+
- Martin Albrecht <malb@informatik.uni-bremen.de> 2008-09: initial version
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# ****************************************************************************
|
|
22
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
23
|
+
# Copyright (C) 2008 Martin Albrecht <malb@informatik.uni-bremen.de>
|
|
24
|
+
#
|
|
25
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
26
|
+
#
|
|
27
|
+
# This code is distributed in the hope that it will be useful,
|
|
28
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
29
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
30
|
+
# General Public License for more details.
|
|
31
|
+
#
|
|
32
|
+
# The full text of the GPL is available at:
|
|
33
|
+
#
|
|
34
|
+
# https://www.gnu.org/licenses/
|
|
35
|
+
# ****************************************************************************
|
|
36
|
+
|
|
37
|
+
from cysignals.signals cimport sig_on, sig_off
|
|
38
|
+
from sage.ext.cplusplus cimport ccrepr
|
|
39
|
+
|
|
40
|
+
include 'misc.pxi'
|
|
41
|
+
include 'decl.pxi'
|
|
42
|
+
|
|
43
|
+
from cpython.object cimport Py_EQ, Py_NE
|
|
44
|
+
from sage.libs.ntl.ntl_GF2 cimport ntl_GF2
|
|
45
|
+
from sage.rings.integer cimport Integer
|
|
46
|
+
from sage.libs.ntl.ntl_ZZ import unpickle_class_args
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
cdef class ntl_mat_GF2():
|
|
50
|
+
r"""
|
|
51
|
+
The \class{mat_GF2} class implements arithmetic with matrices over `F_2`.
|
|
52
|
+
"""
|
|
53
|
+
def __init__(self, nrows=0, ncols=0, v=None):
|
|
54
|
+
"""
|
|
55
|
+
Construct a matrix over ntl.GF2.
|
|
56
|
+
|
|
57
|
+
INPUT:
|
|
58
|
+
|
|
59
|
+
- ``nrows`` -- number of rows
|
|
60
|
+
- ``ncols`` -- number of columns
|
|
61
|
+
- ``v`` -- either a list or a matrix over GF(2^x)
|
|
62
|
+
|
|
63
|
+
EXAMPLES::
|
|
64
|
+
|
|
65
|
+
sage: A = ntl.mat_GF2(4,4); A
|
|
66
|
+
[[0 0 0 0]
|
|
67
|
+
[0 0 0 0]
|
|
68
|
+
[0 0 0 0]
|
|
69
|
+
[0 0 0 0]
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
sage: A = random_matrix(GF(2),4,4); A # random
|
|
73
|
+
[0 1 0 1]
|
|
74
|
+
[0 1 1 1]
|
|
75
|
+
[0 0 0 1]
|
|
76
|
+
[0 1 1 0]
|
|
77
|
+
|
|
78
|
+
sage: B = ntl.mat_GF2(A); B # random
|
|
79
|
+
[[0 1 0 1]
|
|
80
|
+
[0 1 1 1]
|
|
81
|
+
[0 0 0 1]
|
|
82
|
+
[0 1 1 0]
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
sage: B = ntl.mat_GF2(4, 4, A.list())
|
|
86
|
+
sage: B == A
|
|
87
|
+
True
|
|
88
|
+
"""
|
|
89
|
+
cdef Py_ssize_t _nrows, _ncols
|
|
90
|
+
cdef Py_ssize_t i, j
|
|
91
|
+
cdef GF2_c _elem
|
|
92
|
+
|
|
93
|
+
from sage.structure.element import Matrix
|
|
94
|
+
|
|
95
|
+
if isinstance(nrows, Matrix):
|
|
96
|
+
_nrows = nrows.nrows()
|
|
97
|
+
_ncols = nrows.ncols()
|
|
98
|
+
v = nrows
|
|
99
|
+
self.x.SetDims(_nrows, _ncols)
|
|
100
|
+
sig_on()
|
|
101
|
+
for i from 0 <= i < _nrows:
|
|
102
|
+
for j from 0 <= j < _ncols:
|
|
103
|
+
GF2_conv_long(_elem, int(v[i, j]) % 2)
|
|
104
|
+
mat_GF2_setitem(&self.x, i, j, &_elem)
|
|
105
|
+
sig_off()
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
_nrows = nrows
|
|
109
|
+
_ncols = ncols
|
|
110
|
+
self.x.SetDims(_nrows, _ncols)
|
|
111
|
+
|
|
112
|
+
if v is not None:
|
|
113
|
+
sig_on()
|
|
114
|
+
for i from 0 <= i < _nrows:
|
|
115
|
+
for j from 0 <= j < _ncols:
|
|
116
|
+
elem = v[i*_ncols+j]
|
|
117
|
+
if not isinstance(elem, ntl_GF2):
|
|
118
|
+
elem = ntl_GF2(elem)
|
|
119
|
+
mat_GF2_setitem(&self.x, i, j, &(<ntl_GF2>elem).x)
|
|
120
|
+
sig_off()
|
|
121
|
+
|
|
122
|
+
cdef ntl_GF2 _new_element(self):
|
|
123
|
+
cdef ntl_GF2 r
|
|
124
|
+
r = ntl_GF2.__new__(ntl_GF2)
|
|
125
|
+
return r
|
|
126
|
+
|
|
127
|
+
cdef ntl_mat_GF2 _new(self):
|
|
128
|
+
cdef ntl_mat_GF2 r
|
|
129
|
+
r = ntl_mat_GF2.__new__(ntl_mat_GF2)
|
|
130
|
+
r.x.SetDims(self.x.NumRows(),self.x.NumCols())
|
|
131
|
+
return r
|
|
132
|
+
|
|
133
|
+
def __reduce__(self):
|
|
134
|
+
"""
|
|
135
|
+
EXAMPLES::
|
|
136
|
+
|
|
137
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
138
|
+
sage: B = ntl.mat_GF2(A)
|
|
139
|
+
sage: loads(dumps(B)) == B # indirect doctest
|
|
140
|
+
True
|
|
141
|
+
"""
|
|
142
|
+
return unpickle_class_args, (ntl_mat_GF2, (self.x.NumRows(), self.x.NumCols(), self.list()))
|
|
143
|
+
|
|
144
|
+
def __repr__(self):
|
|
145
|
+
"""
|
|
146
|
+
Return the string representation of this matrix.
|
|
147
|
+
|
|
148
|
+
EXAMPLES::
|
|
149
|
+
|
|
150
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
151
|
+
sage: B = ntl.mat_GF2(A)
|
|
152
|
+
sage: B.__repr__()[1:-2] == A.__repr__()
|
|
153
|
+
True
|
|
154
|
+
"""
|
|
155
|
+
return ccrepr(self.x)
|
|
156
|
+
|
|
157
|
+
def __mul__(ntl_mat_GF2 self, other):
|
|
158
|
+
"""
|
|
159
|
+
EXAMPLES::
|
|
160
|
+
|
|
161
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
162
|
+
sage: B = random_matrix(GF(2),4,4)
|
|
163
|
+
sage: c = ntl.mat_GF2(A)*ntl.mat_GF2(B)
|
|
164
|
+
sage: c._sage_() == A*B
|
|
165
|
+
True
|
|
166
|
+
"""
|
|
167
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
168
|
+
if not isinstance(other, ntl_mat_GF2):
|
|
169
|
+
other = ntl_mat_GF2(other)
|
|
170
|
+
sig_on()
|
|
171
|
+
mat_GF2_mul(r.x, self.x, (<ntl_mat_GF2>other).x)
|
|
172
|
+
sig_off()
|
|
173
|
+
return r
|
|
174
|
+
|
|
175
|
+
def __sub__(ntl_mat_GF2 self, other):
|
|
176
|
+
"""
|
|
177
|
+
EXAMPLES::
|
|
178
|
+
|
|
179
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
180
|
+
sage: B = random_matrix(GF(2),4,4)
|
|
181
|
+
sage: c = ntl.mat_GF2(A) - ntl.mat_GF2(B)
|
|
182
|
+
sage: c._sage_() == A - B
|
|
183
|
+
True
|
|
184
|
+
"""
|
|
185
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
186
|
+
if not isinstance(other, ntl_mat_GF2):
|
|
187
|
+
other = ntl_mat_GF2(other,)
|
|
188
|
+
sig_on()
|
|
189
|
+
mat_GF2_sub(r.x, self.x, (<ntl_mat_GF2>other).x)
|
|
190
|
+
sig_off()
|
|
191
|
+
return r
|
|
192
|
+
|
|
193
|
+
def __add__(ntl_mat_GF2 self, other):
|
|
194
|
+
"""
|
|
195
|
+
EXAMPLES::
|
|
196
|
+
|
|
197
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
198
|
+
sage: B = random_matrix(GF(2),4,4)
|
|
199
|
+
sage: c = ntl.mat_GF2(A) + ntl.mat_GF2(B)
|
|
200
|
+
sage: c._sage_() == A + B
|
|
201
|
+
True
|
|
202
|
+
"""
|
|
203
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
204
|
+
if not isinstance(other, ntl_mat_GF2):
|
|
205
|
+
other = ntl_mat_GF2(other)
|
|
206
|
+
sig_on()
|
|
207
|
+
mat_GF2_add(r.x, self.x, (<ntl_mat_GF2>other).x)
|
|
208
|
+
sig_off()
|
|
209
|
+
return r
|
|
210
|
+
|
|
211
|
+
def __neg__(ntl_mat_GF2 self):
|
|
212
|
+
"""
|
|
213
|
+
EXAMPLES::
|
|
214
|
+
|
|
215
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
216
|
+
sage: (-ntl.mat_GF2(A))._sage_() == -A
|
|
217
|
+
True
|
|
218
|
+
"""
|
|
219
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
220
|
+
sig_on()
|
|
221
|
+
mat_GF2_negate(r.x, self.x)
|
|
222
|
+
sig_off()
|
|
223
|
+
return r
|
|
224
|
+
|
|
225
|
+
def __pow__(ntl_mat_GF2 self, long e, ignored):
|
|
226
|
+
"""
|
|
227
|
+
EXAMPLES::
|
|
228
|
+
|
|
229
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
230
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
231
|
+
sage: (Abar^0)._sage_() == A^0
|
|
232
|
+
True
|
|
233
|
+
sage: (Abar^1)._sage_() == A^1
|
|
234
|
+
True
|
|
235
|
+
sage: (Abar^2)._sage_() == A^2
|
|
236
|
+
True
|
|
237
|
+
sage: (Abar^3)._sage_() == A^3
|
|
238
|
+
True
|
|
239
|
+
"""
|
|
240
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
241
|
+
sig_on()
|
|
242
|
+
mat_GF2_power(r.x, self.x, e)
|
|
243
|
+
sig_off()
|
|
244
|
+
return r
|
|
245
|
+
|
|
246
|
+
def __richcmp__(ntl_mat_GF2 self, other, int op):
|
|
247
|
+
"""
|
|
248
|
+
Compare ``self`` to ``other``.
|
|
249
|
+
|
|
250
|
+
EXAMPLES::
|
|
251
|
+
|
|
252
|
+
sage: A = random_matrix(GF(2),4,4)
|
|
253
|
+
sage: A1 = ntl.mat_GF2(A)
|
|
254
|
+
sage: A2 = ntl.mat_GF2(A)
|
|
255
|
+
sage: A1 == A2
|
|
256
|
+
True
|
|
257
|
+
sage: A1[0,0] += 1
|
|
258
|
+
sage: A1 == A2
|
|
259
|
+
False
|
|
260
|
+
sage: A1 == "x"
|
|
261
|
+
False
|
|
262
|
+
"""
|
|
263
|
+
if op != Py_EQ and op != Py_NE:
|
|
264
|
+
raise TypeError("matrices over GF(2) are not ordered")
|
|
265
|
+
|
|
266
|
+
cdef ntl_mat_GF2 b
|
|
267
|
+
try:
|
|
268
|
+
b = <ntl_mat_GF2?>other
|
|
269
|
+
except TypeError:
|
|
270
|
+
return NotImplemented
|
|
271
|
+
|
|
272
|
+
return (op == Py_EQ) == (self.x == b.x)
|
|
273
|
+
|
|
274
|
+
def NumRows(self):
|
|
275
|
+
"""
|
|
276
|
+
Return the number of rows of this matrix.
|
|
277
|
+
|
|
278
|
+
EXAMPLES::
|
|
279
|
+
|
|
280
|
+
sage: A = ntl.mat_GF2(10,10)
|
|
281
|
+
sage: A.NumRows()
|
|
282
|
+
10
|
|
283
|
+
"""
|
|
284
|
+
return int(self.x.NumRows())
|
|
285
|
+
|
|
286
|
+
def NumCols(self):
|
|
287
|
+
"""
|
|
288
|
+
Return the number of columns of this matrix.
|
|
289
|
+
|
|
290
|
+
EXAMPLES::
|
|
291
|
+
|
|
292
|
+
sage: A = ntl.mat_GF2(10,10)
|
|
293
|
+
sage: A.NumCols()
|
|
294
|
+
10
|
|
295
|
+
"""
|
|
296
|
+
return int(self.x.NumCols())
|
|
297
|
+
|
|
298
|
+
def __setitem__(self, ij, x):
|
|
299
|
+
"""
|
|
300
|
+
EXAMPLES::
|
|
301
|
+
|
|
302
|
+
sage: A = ntl.mat_GF2(5,5)
|
|
303
|
+
sage: A[0,0] = 1
|
|
304
|
+
sage: A[0,2] = 1
|
|
305
|
+
sage: A
|
|
306
|
+
[[1 0 1 0 0]
|
|
307
|
+
[0 0 0 0 0]
|
|
308
|
+
[0 0 0 0 0]
|
|
309
|
+
[0 0 0 0 0]
|
|
310
|
+
[0 0 0 0 0]
|
|
311
|
+
]
|
|
312
|
+
"""
|
|
313
|
+
cdef int i, j
|
|
314
|
+
if not isinstance(x, ntl_GF2):
|
|
315
|
+
x = ntl_GF2(x)
|
|
316
|
+
|
|
317
|
+
if isinstance(ij, tuple) and len(ij) == 2:
|
|
318
|
+
i, j = ij
|
|
319
|
+
elif self.x.NumCols() == 1 and isinstance(ij, (Integer, int)):
|
|
320
|
+
i = ij
|
|
321
|
+
j = 0
|
|
322
|
+
elif self.x.NumRows() == 1 and isinstance(ij, (Integer, int)):
|
|
323
|
+
i = 0
|
|
324
|
+
j = ij
|
|
325
|
+
else:
|
|
326
|
+
raise TypeError('ij is not a matrix index')
|
|
327
|
+
|
|
328
|
+
if i < 0 or i >= self.x.NumRows() or j < 0 or j >= self.x.NumCols():
|
|
329
|
+
raise IndexError("array index out of range")
|
|
330
|
+
|
|
331
|
+
mat_GF2_setitem(&self.x, i, j, &(<ntl_GF2>x).x)
|
|
332
|
+
|
|
333
|
+
def __getitem__(self, ij):
|
|
334
|
+
"""
|
|
335
|
+
EXAMPLES::
|
|
336
|
+
|
|
337
|
+
sage: A = ntl.mat_GF2(3,3,range(9))
|
|
338
|
+
sage: A[0,0]
|
|
339
|
+
0
|
|
340
|
+
sage: A[1,2]
|
|
341
|
+
1
|
|
342
|
+
"""
|
|
343
|
+
cdef int i, j
|
|
344
|
+
if isinstance(ij, tuple) and len(ij) == 2:
|
|
345
|
+
i, j = ij
|
|
346
|
+
elif self.x.NumCols() == 1 and isinstance(ij, (Integer, int)):
|
|
347
|
+
i = ij
|
|
348
|
+
j = 0
|
|
349
|
+
elif self.x.NumRows() == 1 and isinstance(ij, (Integer, int)):
|
|
350
|
+
i = 0
|
|
351
|
+
j = ij
|
|
352
|
+
else:
|
|
353
|
+
raise TypeError('ij is not a matrix index')
|
|
354
|
+
|
|
355
|
+
if i < 0 or i >= self.x.NumRows() or j < 0 or j >= self.x.NumCols():
|
|
356
|
+
raise IndexError("array index out of range")
|
|
357
|
+
|
|
358
|
+
cdef ntl_GF2 e = self._new_element()
|
|
359
|
+
e.x = self.x.get( i+1, j+1 )
|
|
360
|
+
return e
|
|
361
|
+
|
|
362
|
+
def determinant(self):
|
|
363
|
+
"""
|
|
364
|
+
Return the determinant.
|
|
365
|
+
|
|
366
|
+
EXAMPLES::
|
|
367
|
+
|
|
368
|
+
sage: A = ntl.mat_GF2(3,3,range(9))
|
|
369
|
+
sage: A.determinant()
|
|
370
|
+
0
|
|
371
|
+
sage: A = ntl.mat_GF2(3,3,[1,0,0, 0,1,0, 0,0,1])
|
|
372
|
+
sage: A.determinant()
|
|
373
|
+
1
|
|
374
|
+
"""
|
|
375
|
+
cdef ntl_GF2 r = self._new_element()
|
|
376
|
+
sig_on()
|
|
377
|
+
r.x = mat_GF2_determinant(self.x)
|
|
378
|
+
sig_off()
|
|
379
|
+
return r
|
|
380
|
+
|
|
381
|
+
def gauss(self, ncols=-1):
|
|
382
|
+
r"""
|
|
383
|
+
Perform unitary row operations so as to bring this matrix
|
|
384
|
+
into row echelon form (not reduced!).
|
|
385
|
+
|
|
386
|
+
If the optional argument ``ncols`` is supplied, stops when
|
|
387
|
+
first ``ncols`` columns are in echelon form. The return value is
|
|
388
|
+
the rank (or the rank of the first ``ncols`` columns).
|
|
389
|
+
|
|
390
|
+
INPUT:
|
|
391
|
+
|
|
392
|
+
- ``ncols`` -- number of columns to process (default: all)
|
|
393
|
+
|
|
394
|
+
EXAMPLES::
|
|
395
|
+
|
|
396
|
+
sage: A = random_matrix(GF(2), 10, 10)
|
|
397
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
398
|
+
sage: A.rank() == Abar.gauss()
|
|
399
|
+
True
|
|
400
|
+
sage: Abar # random
|
|
401
|
+
[[1 1 1 1 0 1 0 1 1 0]
|
|
402
|
+
[0 1 1 1 0 1 1 0 0 1]
|
|
403
|
+
[0 0 1 1 1 1 0 0 0 0]
|
|
404
|
+
[0 0 0 1 0 0 1 1 1 1]
|
|
405
|
+
[0 0 0 0 1 1 0 1 0 0]
|
|
406
|
+
[0 0 0 0 0 1 1 1 0 1]
|
|
407
|
+
[0 0 0 0 0 0 0 1 0 1]
|
|
408
|
+
[0 0 0 0 0 0 0 0 0 1]
|
|
409
|
+
[0 0 0 0 0 0 0 0 0 0]
|
|
410
|
+
[0 0 0 0 0 0 0 0 0 0]
|
|
411
|
+
]
|
|
412
|
+
|
|
413
|
+
``Abar`` is in row echelon form now::
|
|
414
|
+
|
|
415
|
+
sage: first_nonzero_indices = [Abar._sage_().row(i).nonzero_positions()[0] for i in range(A.rank())]
|
|
416
|
+
sage: all(first_nonzero_indices[i] < first_nonzero_indices[i+1] for i in range(A.rank()-1))
|
|
417
|
+
True
|
|
418
|
+
|
|
419
|
+
``Abar`` is not reduced::
|
|
420
|
+
|
|
421
|
+
sage: all(Abar._sage_().row(i).nonzero_positions() == [] for i in range(A.rank(), Abar.NumRows()))
|
|
422
|
+
True
|
|
423
|
+
"""
|
|
424
|
+
if ncols == -1:
|
|
425
|
+
ncols = self.x.NumCols()
|
|
426
|
+
return int(mat_GF2_gauss(self.x, int(ncols)))
|
|
427
|
+
|
|
428
|
+
def list(self):
|
|
429
|
+
"""
|
|
430
|
+
Return a list of the entries in this matrix.
|
|
431
|
+
|
|
432
|
+
EXAMPLES::
|
|
433
|
+
|
|
434
|
+
sage: A = random_matrix(GF(2), 4, 4)
|
|
435
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
436
|
+
sage: A.list() == Abar.list()
|
|
437
|
+
True
|
|
438
|
+
"""
|
|
439
|
+
cdef Py_ssize_t i, j
|
|
440
|
+
return [self[i,j] for i in range(self.NumRows()) for j in range(self.x.NumCols())]
|
|
441
|
+
|
|
442
|
+
def IsZero(self):
|
|
443
|
+
r"""
|
|
444
|
+
Return \code{True} if this matrix contains only zeroes, and \code{False} otherwise.
|
|
445
|
+
|
|
446
|
+
EXAMPLES::
|
|
447
|
+
|
|
448
|
+
sage: A = random_matrix(GF(2), 10, 10)
|
|
449
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
450
|
+
sage: Abar.IsZero()
|
|
451
|
+
False
|
|
452
|
+
sage: Abar = ntl.mat_GF2(10,10)
|
|
453
|
+
sage: Abar.IsZero()
|
|
454
|
+
True
|
|
455
|
+
"""
|
|
456
|
+
cdef long isZero
|
|
457
|
+
sig_on()
|
|
458
|
+
isZero = mat_GF2_IsZero(self.x)
|
|
459
|
+
sig_off()
|
|
460
|
+
return bool(isZero)
|
|
461
|
+
|
|
462
|
+
def _sage_(ntl_mat_GF2 self):
|
|
463
|
+
r"""
|
|
464
|
+
Return a \class{Matrix} over GF(2).
|
|
465
|
+
|
|
466
|
+
EXAMPLES::
|
|
467
|
+
|
|
468
|
+
sage: A = random_matrix(GF(2), 6, 6)
|
|
469
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
470
|
+
sage: Abar._sage_() == A
|
|
471
|
+
True
|
|
472
|
+
"""
|
|
473
|
+
from sage.rings.finite_rings.finite_field_constructor import FiniteField
|
|
474
|
+
from sage.matrix.constructor import matrix
|
|
475
|
+
m = matrix(FiniteField(2),self.x.NumRows(),self.x.NumCols())
|
|
476
|
+
|
|
477
|
+
cdef Py_ssize_t i, j
|
|
478
|
+
|
|
479
|
+
for i from 0 <= i < self.x.NumRows():
|
|
480
|
+
for j from 0 <= j < self.x.NumCols():
|
|
481
|
+
m[i,j] = GF2_conv_to_long(self.x.get( i+1, j+1))
|
|
482
|
+
return m
|
|
483
|
+
|
|
484
|
+
def transpose(ntl_mat_GF2 self):
|
|
485
|
+
"""
|
|
486
|
+
Return the transposed matrix of this matrix.
|
|
487
|
+
|
|
488
|
+
EXAMPLES::
|
|
489
|
+
|
|
490
|
+
sage: A = random_matrix(GF(2), 10, 10)
|
|
491
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
492
|
+
sage: Abar_t = Abar.transpose()
|
|
493
|
+
sage: A_t = A.transpose()
|
|
494
|
+
sage: A_t == Abar_t._sage_()
|
|
495
|
+
True
|
|
496
|
+
"""
|
|
497
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
498
|
+
sig_on()
|
|
499
|
+
mat_GF2_transpose(r.x, self.x)
|
|
500
|
+
sig_off()
|
|
501
|
+
return r
|
|
502
|
+
|
|
503
|
+
def __invert__(self):
|
|
504
|
+
"""
|
|
505
|
+
Return `X = A^{-1}`; an error is raised if A is singular.
|
|
506
|
+
|
|
507
|
+
EXAMPLES::
|
|
508
|
+
|
|
509
|
+
sage: l = [0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, \
|
|
510
|
+
....: 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, \
|
|
511
|
+
....: 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, \
|
|
512
|
+
....: 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0]
|
|
513
|
+
sage: A = ntl.mat_GF2(8,8,l)
|
|
514
|
+
sage: E = ~A*A
|
|
515
|
+
sage: E.IsIdent()
|
|
516
|
+
True
|
|
517
|
+
"""
|
|
518
|
+
cdef ntl_mat_GF2 r = self._new()
|
|
519
|
+
sig_on()
|
|
520
|
+
mat_GF2_inv(r.x, self.x)
|
|
521
|
+
sig_off()
|
|
522
|
+
return r
|
|
523
|
+
|
|
524
|
+
def IsIdent(self, n=-1):
|
|
525
|
+
"""
|
|
526
|
+
Test if this matrix is the n x n identity matrix.
|
|
527
|
+
|
|
528
|
+
EXAMPLES::
|
|
529
|
+
|
|
530
|
+
sage: A = ntl.mat_GF2(4,4)
|
|
531
|
+
sage: A[0,0] = 1
|
|
532
|
+
sage: A[1,1] = 1
|
|
533
|
+
sage: A[2,2] = 1
|
|
534
|
+
sage: A.IsIdent()
|
|
535
|
+
False
|
|
536
|
+
sage: A[3,3] = 1
|
|
537
|
+
sage: A.IsIdent()
|
|
538
|
+
True
|
|
539
|
+
"""
|
|
540
|
+
if n < 0:
|
|
541
|
+
n = self.NumRows()
|
|
542
|
+
return bool(mat_GF2_IsIdent(self.x, n))
|
|
543
|
+
|
|
544
|
+
def IsDiag(self, long n, ntl_GF2 d):
|
|
545
|
+
"""
|
|
546
|
+
Test if X is an n x n diagonal matrix with d on diagonal.
|
|
547
|
+
|
|
548
|
+
EXAMPLES::
|
|
549
|
+
|
|
550
|
+
sage: A = ntl.mat_GF2(4,4)
|
|
551
|
+
sage: A[0,0] = 1
|
|
552
|
+
sage: A[1,1] = 1
|
|
553
|
+
sage: A[2,2] = 1
|
|
554
|
+
sage: A.IsDiag(3, ntl.GF2(1))
|
|
555
|
+
False
|
|
556
|
+
sage: A[3,3] = 1
|
|
557
|
+
sage: A.IsDiag(4, ntl.GF2(1))
|
|
558
|
+
True
|
|
559
|
+
"""
|
|
560
|
+
return bool(mat_GF2_IsDiag(self.x, n, d.x))
|
|
561
|
+
|
|
562
|
+
def image(self):
|
|
563
|
+
"""
|
|
564
|
+
If A is this matrix and X the matrix returned by this function
|
|
565
|
+
then, the rows of X are computed as basis of A's row space.
|
|
566
|
+
X is in row echelon form.
|
|
567
|
+
|
|
568
|
+
EXAMPLES::
|
|
569
|
+
|
|
570
|
+
sage: A = random_matrix(GF(2),10,10)
|
|
571
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
572
|
+
sage: A_image = A.image().matrix()
|
|
573
|
+
sage: Abar_image = Abar.image()._sage_()
|
|
574
|
+
sage: A_image.row_space() == Abar_image.row_space()
|
|
575
|
+
True
|
|
576
|
+
|
|
577
|
+
X is in row echelon form::
|
|
578
|
+
|
|
579
|
+
sage: first_nonzero_indices = [row.nonzero_positions()[0] for row in Abar_image.rows()]
|
|
580
|
+
sage: all(first_nonzero_indices[i] < first_nonzero_indices[i+1] for i in range(Abar_image.nrows() - 1))
|
|
581
|
+
True
|
|
582
|
+
"""
|
|
583
|
+
cdef ntl_mat_GF2 X = self._new()
|
|
584
|
+
sig_on()
|
|
585
|
+
mat_GF2_image(X.x, self.x)
|
|
586
|
+
sig_off()
|
|
587
|
+
return X
|
|
588
|
+
|
|
589
|
+
def kernel(self):
|
|
590
|
+
"""
|
|
591
|
+
Compute a basis for the kernel of the map x -> x*A. where x
|
|
592
|
+
is a row vector.
|
|
593
|
+
|
|
594
|
+
EXAMPLES::
|
|
595
|
+
|
|
596
|
+
sage: A = random_matrix(GF(2),10,10)
|
|
597
|
+
sage: Abar = ntl.mat_GF2(A)
|
|
598
|
+
sage: K_abar = Abar.kernel(); K_abar # random
|
|
599
|
+
[[0 0 0 1 1 0 1 0 1 0]
|
|
600
|
+
[1 1 1 0 1 1 0 1 0 0]
|
|
601
|
+
]
|
|
602
|
+
sage: (K_abar*Abar).IsZero()
|
|
603
|
+
True
|
|
604
|
+
sage: K_a = A.kernel().matrix()
|
|
605
|
+
sage: K_a.row_space() == K_abar._sage_().row_space()
|
|
606
|
+
True
|
|
607
|
+
"""
|
|
608
|
+
cdef ntl_mat_GF2 X = self._new()
|
|
609
|
+
sig_on()
|
|
610
|
+
mat_GF2_kernel(X.x, self.x)
|
|
611
|
+
sig_off()
|
|
612
|
+
return X
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
from sage.libs.ntl.types cimport mat_GF2E_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_mat_GF2E():
|
|
7
|
+
cdef mat_GF2E_c x
|
|
8
|
+
cdef ntl_GF2EContext_class c
|
|
9
|
+
cdef ntl_GF2E _new_element(self)
|
|
10
|
+
cdef ntl_mat_GF2E _new(self)
|