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,752 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
# distutils: libraries = NTL_LIBRARIES gmp M_LIBRARIES
|
|
3
|
+
# distutils: extra_compile_args = NTL_CFLAGS
|
|
4
|
+
# distutils: include_dirs = NTL_INCDIR
|
|
5
|
+
# distutils: library_dirs = NTL_LIBDIR
|
|
6
|
+
# distutils: extra_link_args = NTL_LIBEXTRA
|
|
7
|
+
# distutils: language = c++
|
|
8
|
+
# sage.doctest: needs sage.libs.pari
|
|
9
|
+
|
|
10
|
+
#*****************************************************************************
|
|
11
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
12
|
+
#
|
|
13
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
14
|
+
#
|
|
15
|
+
# This code is distributed in the hope that it will be useful,
|
|
16
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18
|
+
# General Public License for more details.
|
|
19
|
+
#
|
|
20
|
+
# The full text of the GPL is available at:
|
|
21
|
+
#
|
|
22
|
+
# http://www.gnu.org/licenses/
|
|
23
|
+
#*****************************************************************************
|
|
24
|
+
|
|
25
|
+
##############################################################################
|
|
26
|
+
#
|
|
27
|
+
# ntl_mat_GF2E: Matrices over the GF(2**x) via NTL
|
|
28
|
+
#
|
|
29
|
+
# AUTHORS:
|
|
30
|
+
# - Martin Albrecht <malb@informatik.uni-bremen.de>
|
|
31
|
+
# 2006-01: initial version (based on code by William Stein)
|
|
32
|
+
#
|
|
33
|
+
##############################################################################
|
|
34
|
+
|
|
35
|
+
from cysignals.signals cimport sig_on, sig_off
|
|
36
|
+
from sage.ext.cplusplus cimport ccrepr
|
|
37
|
+
|
|
38
|
+
include 'misc.pxi'
|
|
39
|
+
include 'decl.pxi'
|
|
40
|
+
|
|
41
|
+
from cpython.object cimport Py_EQ, Py_NE
|
|
42
|
+
from sage.libs.ntl.ntl_GF2E cimport ntl_GF2E
|
|
43
|
+
from sage.libs.ntl.ntl_GF2EContext import ntl_GF2EContext
|
|
44
|
+
from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class
|
|
45
|
+
from sage.rings.integer cimport Integer
|
|
46
|
+
from sage.misc.randstate cimport randstate, current_randstate
|
|
47
|
+
|
|
48
|
+
from sage.libs.ntl.ntl_ZZ import unpickle_class_args
|
|
49
|
+
|
|
50
|
+
cdef class ntl_mat_GF2E():
|
|
51
|
+
r"""
|
|
52
|
+
The \class{mat_GF2E} class implements arithmetic with matrices over `GF(2**x)`.
|
|
53
|
+
"""
|
|
54
|
+
def __init__(self, modulus=None, nrows=0, ncols=0, v=None):
|
|
55
|
+
"""
|
|
56
|
+
Construct a matrix over ntl.GF2E.
|
|
57
|
+
|
|
58
|
+
INPUT:
|
|
59
|
+
|
|
60
|
+
- ``modulus`` -- GF2E context
|
|
61
|
+
- ``nrows`` -- number of rows
|
|
62
|
+
- ``ncols`` -- number of columns
|
|
63
|
+
- ``v`` -- either a list or a matrix over GF(2^x)
|
|
64
|
+
|
|
65
|
+
EXAMPLES::
|
|
66
|
+
|
|
67
|
+
sage: k.<a> = GF(2^4)
|
|
68
|
+
sage: ctx = ntl.GF2EContext(k)
|
|
69
|
+
sage: ntl.GF2XHexOutput(1)
|
|
70
|
+
sage: ntl.mat_GF2E(ctx, 5,5, [0..24])
|
|
71
|
+
[[0x0 0x1 0x2 0x3 0x4]
|
|
72
|
+
[0x5 0x6 0x7 0x8 0x9]
|
|
73
|
+
[0xa 0xb 0xc 0xd 0xe]
|
|
74
|
+
[0xf 0x3 0x2 0x1 0x0]
|
|
75
|
+
[0x7 0x6 0x5 0x4 0xb]
|
|
76
|
+
]
|
|
77
|
+
sage: ntl.mat_GF2E(ctx, 5,5)
|
|
78
|
+
[[0x0 0x0 0x0 0x0 0x0]
|
|
79
|
+
[0x0 0x0 0x0 0x0 0x0]
|
|
80
|
+
[0x0 0x0 0x0 0x0 0x0]
|
|
81
|
+
[0x0 0x0 0x0 0x0 0x0]
|
|
82
|
+
[0x0 0x0 0x0 0x0 0x0]
|
|
83
|
+
]
|
|
84
|
+
sage: A = matrix(k, 5, 5, [k.from_integer(i % 2^4) for i in range(25)])
|
|
85
|
+
sage: ntl.mat_GF2E(ctx, A)
|
|
86
|
+
[[0x0 0x1 0x2 0x3 0x4]
|
|
87
|
+
[0x5 0x6 0x7 0x8 0x9]
|
|
88
|
+
[0xa 0xb 0xc 0xd 0xe]
|
|
89
|
+
[0xf 0x0 0x1 0x2 0x3]
|
|
90
|
+
[0x4 0x5 0x6 0x7 0x8]
|
|
91
|
+
]
|
|
92
|
+
"""
|
|
93
|
+
if modulus is None:
|
|
94
|
+
raise ValueError("You must specify a modulus when creating a GF2E.")
|
|
95
|
+
|
|
96
|
+
cdef unsigned long _nrows, _ncols
|
|
97
|
+
cdef unsigned long i, j
|
|
98
|
+
|
|
99
|
+
from sage.structure.element import Matrix
|
|
100
|
+
if isinstance(nrows, Matrix):
|
|
101
|
+
_nrows = nrows.nrows()
|
|
102
|
+
_ncols = nrows.ncols()
|
|
103
|
+
v = nrows.list()
|
|
104
|
+
else:
|
|
105
|
+
_nrows = nrows
|
|
106
|
+
_ncols = ncols
|
|
107
|
+
|
|
108
|
+
self.x.SetDims(_nrows, _ncols)
|
|
109
|
+
if v is not None:
|
|
110
|
+
sig_on()
|
|
111
|
+
for i from 0 <= i < _nrows:
|
|
112
|
+
for j from 0 <= j < _ncols:
|
|
113
|
+
elem = v[i*_ncols+j]
|
|
114
|
+
if not isinstance(elem, ntl_GF2E):
|
|
115
|
+
elem = ntl_GF2E(elem, modulus)
|
|
116
|
+
mat_GF2E_setitem(&self.x, i, j, &(<ntl_GF2E>elem).x)
|
|
117
|
+
sig_off()
|
|
118
|
+
|
|
119
|
+
def __cinit__(self, modulus=None, nrows=0, ncols=0, v=None):
|
|
120
|
+
#################### WARNING ###################
|
|
121
|
+
## Before creating a GF2E, you must create a ##
|
|
122
|
+
## GF2EContext, and restore it. In Python, ##
|
|
123
|
+
## the error checking in __init__ will prevent##
|
|
124
|
+
## you from constructing an ntl_GF2E ##
|
|
125
|
+
## inappropriately. However, from Cython, you##
|
|
126
|
+
## could do r = ntl_GF2E.__new__(ntl_GF2E) without
|
|
127
|
+
## first restoring a GF2EContext, which could ##
|
|
128
|
+
## have unfortunate consequences. See _new ##
|
|
129
|
+
## defined below for an example of the right ##
|
|
130
|
+
## way to short-circuit __init__ (or just call##
|
|
131
|
+
## _new in your own code). ##
|
|
132
|
+
################################################
|
|
133
|
+
if modulus is None:
|
|
134
|
+
return
|
|
135
|
+
if isinstance(modulus, ntl_GF2EContext_class):
|
|
136
|
+
self.c = <ntl_GF2EContext_class>modulus
|
|
137
|
+
self.c.restore_c()
|
|
138
|
+
else:
|
|
139
|
+
self.c = <ntl_GF2EContext_class>ntl_GF2EContext(modulus)
|
|
140
|
+
self.c.restore_c()
|
|
141
|
+
|
|
142
|
+
cdef ntl_GF2E _new_element(self):
|
|
143
|
+
cdef ntl_GF2E r
|
|
144
|
+
self.c.restore_c()
|
|
145
|
+
r = ntl_GF2E.__new__(ntl_GF2E)
|
|
146
|
+
r.c = self.c
|
|
147
|
+
return r
|
|
148
|
+
|
|
149
|
+
cdef ntl_mat_GF2E _new(self):
|
|
150
|
+
cdef ntl_mat_GF2E r
|
|
151
|
+
self.c.restore_c()
|
|
152
|
+
r = ntl_mat_GF2E.__new__(ntl_mat_GF2E)
|
|
153
|
+
r.x.SetDims(self.x.NumRows(),self.x.NumCols())
|
|
154
|
+
r.c = self.c
|
|
155
|
+
return r
|
|
156
|
+
|
|
157
|
+
def modulus_context(self):
|
|
158
|
+
"""
|
|
159
|
+
Return the structure that holds the underlying NTL GF2E modulus.
|
|
160
|
+
|
|
161
|
+
EXAMPLES::
|
|
162
|
+
|
|
163
|
+
sage: ntl.GF2XHexOutput(0)
|
|
164
|
+
sage: ctx = ntl.GF2EContext( ntl.GF2X([1,1,0,1,1,0,0,0,1]) )
|
|
165
|
+
sage: a = ntl.GF2E(ntl.ZZ_pX([1,1,3],2), ctx)
|
|
166
|
+
sage: A= ntl.mat_GF2E(ctx, 1, 1, [a])
|
|
167
|
+
sage: cty = A.modulus_context(); cty
|
|
168
|
+
NTL modulus [1 1 0 1 1 0 0 0 1]
|
|
169
|
+
sage: ctx == cty
|
|
170
|
+
True
|
|
171
|
+
"""
|
|
172
|
+
return self.c
|
|
173
|
+
|
|
174
|
+
def __reduce__(self):
|
|
175
|
+
"""
|
|
176
|
+
EXAMPLES::
|
|
177
|
+
|
|
178
|
+
sage: k.<a> = GF(2^4)
|
|
179
|
+
sage: ctx = ntl.GF2EContext(k)
|
|
180
|
+
sage: A = ntl.mat_GF2E(ctx, 5,5, [0..24])
|
|
181
|
+
sage: A == loads(dumps(A))
|
|
182
|
+
True
|
|
183
|
+
"""
|
|
184
|
+
return unpickle_class_args, (ntl_mat_GF2E, (self.modulus_context(), self.x.NumRows(), self.x.NumCols(), self.list()))
|
|
185
|
+
|
|
186
|
+
def __repr__(self):
|
|
187
|
+
"""
|
|
188
|
+
Return the string representation of ``self``.
|
|
189
|
+
|
|
190
|
+
EXAMPLES::
|
|
191
|
+
|
|
192
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
193
|
+
sage: ntl.GF2XHexOutput(1)
|
|
194
|
+
sage: ntl.mat_GF2E(ctx, 2,2,range(4)).__repr__()
|
|
195
|
+
'[[0x0 0x1]\n[0x0 0x1]\n]'
|
|
196
|
+
sage: ntl.GF2XHexOutput(0)
|
|
197
|
+
sage: ntl.mat_GF2E(ctx, 2,2,range(4)).__repr__()
|
|
198
|
+
'[[[] [1]]\n[[] [1]]\n]'
|
|
199
|
+
"""
|
|
200
|
+
self.c.restore_c()
|
|
201
|
+
return ccrepr(self.x)
|
|
202
|
+
|
|
203
|
+
def __mul__(ntl_mat_GF2E self, other):
|
|
204
|
+
"""
|
|
205
|
+
EXAMPLES::
|
|
206
|
+
|
|
207
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
208
|
+
sage: ntl.GF2XHexOutput(1)
|
|
209
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
210
|
+
sage: n = ntl.mat_GF2E(ctx, 5,5,[3..27])
|
|
211
|
+
sage: m*n # indirect doctest
|
|
212
|
+
[[0x87 0x04 0xc4 0xc7 0x87]
|
|
213
|
+
[0x32 0x84 0x17 0x63 0x73]
|
|
214
|
+
[0xa1 0x46 0x25 0xcd 0x2f]
|
|
215
|
+
[0x1 0xcf 0xfb 0xd6 0x62]
|
|
216
|
+
[0xcf 0x02 0x06 0xfd 0x79]
|
|
217
|
+
]
|
|
218
|
+
"""
|
|
219
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
220
|
+
if not isinstance(other, ntl_mat_GF2E):
|
|
221
|
+
other = ntl_mat_GF2E(other, self.c)
|
|
222
|
+
if self.c is not (<ntl_mat_GF2E>other).c:
|
|
223
|
+
raise ValueError("You cannot perform arithmetic with matrices over different fields.")
|
|
224
|
+
sig_on()
|
|
225
|
+
mat_GF2E_mul(r.x, self.x, (<ntl_mat_GF2E>other).x)
|
|
226
|
+
sig_off()
|
|
227
|
+
return r
|
|
228
|
+
|
|
229
|
+
def __sub__(ntl_mat_GF2E self, other):
|
|
230
|
+
"""
|
|
231
|
+
EXAMPLES::
|
|
232
|
+
|
|
233
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
234
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
235
|
+
sage: n = ntl.mat_GF2E(ctx, 5,5,[3..27])
|
|
236
|
+
sage: ntl.GF2XHexOutput(0)
|
|
237
|
+
sage: m-n # indirect doctest
|
|
238
|
+
[[[1 1] [1 0 1] [1 1 1] [1 0 1] [1 1]]
|
|
239
|
+
[[1 0 1 1] [1 1 1 1] [1 0 1 1] [1 1] [1 0 1]]
|
|
240
|
+
[[1 1 1] [1 0 1] [1 1] [1 0 1 1 1] [1 1 1 1 1]]
|
|
241
|
+
[[1 0 1 1 1] [1 1] [1 0 1] [1 1 1] [1 0 1]]
|
|
242
|
+
[[1 1] [1 0 1 1] [1 1 1 1] [1 0 1 1] [1 1]]
|
|
243
|
+
]
|
|
244
|
+
"""
|
|
245
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
246
|
+
if not isinstance(other, ntl_mat_GF2E):
|
|
247
|
+
other = ntl_mat_GF2E(other, self.c)
|
|
248
|
+
if self.c is not (<ntl_mat_GF2E>other).c:
|
|
249
|
+
raise ValueError("You cannot perform arithmetic with matrices over different fields.")
|
|
250
|
+
sig_on()
|
|
251
|
+
mat_GF2E_sub(r.x, self.x, (<ntl_mat_GF2E>other).x)
|
|
252
|
+
sig_off()
|
|
253
|
+
return r
|
|
254
|
+
|
|
255
|
+
def __add__(ntl_mat_GF2E self, other):
|
|
256
|
+
"""
|
|
257
|
+
EXAMPLES::
|
|
258
|
+
|
|
259
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
260
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
261
|
+
sage: n = ntl.mat_GF2E(ctx, 5,5,[3..27])
|
|
262
|
+
sage: m+n # indirect doctest
|
|
263
|
+
[[[1 1] [1 0 1] [1 1 1] [1 0 1] [1 1]]
|
|
264
|
+
[[1 0 1 1] [1 1 1 1] [1 0 1 1] [1 1] [1 0 1]]
|
|
265
|
+
[[1 1 1] [1 0 1] [1 1] [1 0 1 1 1] [1 1 1 1 1]]
|
|
266
|
+
[[1 0 1 1 1] [1 1] [1 0 1] [1 1 1] [1 0 1]]
|
|
267
|
+
[[1 1] [1 0 1 1] [1 1 1 1] [1 0 1 1] [1 1]]
|
|
268
|
+
]
|
|
269
|
+
"""
|
|
270
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
271
|
+
if not isinstance(other, ntl_mat_GF2E):
|
|
272
|
+
other = ntl_mat_GF2E(other, self.c)
|
|
273
|
+
if self.c is not (<ntl_mat_GF2E>other).c:
|
|
274
|
+
raise ValueError("You cannot perform arithmetic with matrices over different fields.")
|
|
275
|
+
sig_on()
|
|
276
|
+
mat_GF2E_add(r.x, self.x, (<ntl_mat_GF2E>other).x)
|
|
277
|
+
sig_off()
|
|
278
|
+
return r
|
|
279
|
+
|
|
280
|
+
def __neg__(ntl_mat_GF2E self):
|
|
281
|
+
"""
|
|
282
|
+
EXAMPLES::
|
|
283
|
+
|
|
284
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
285
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
286
|
+
sage: -m == m # indirect doctest
|
|
287
|
+
True
|
|
288
|
+
"""
|
|
289
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
290
|
+
sig_on()
|
|
291
|
+
mat_GF2E_negate(r.x, self.x)
|
|
292
|
+
sig_off()
|
|
293
|
+
return r
|
|
294
|
+
|
|
295
|
+
def __pow__(ntl_mat_GF2E self, long e, ignored):
|
|
296
|
+
"""
|
|
297
|
+
EXAMPLES::
|
|
298
|
+
|
|
299
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
300
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
301
|
+
sage: m**2 == m*m # indirect doctest
|
|
302
|
+
True
|
|
303
|
+
"""
|
|
304
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
305
|
+
sig_on()
|
|
306
|
+
mat_GF2E_power(r.x, self.x, e)
|
|
307
|
+
sig_off()
|
|
308
|
+
return r
|
|
309
|
+
|
|
310
|
+
def __richcmp__(ntl_mat_GF2E self, other, int op):
|
|
311
|
+
"""
|
|
312
|
+
Compare ``self`` to ``other``.
|
|
313
|
+
|
|
314
|
+
EXAMPLES::
|
|
315
|
+
|
|
316
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
317
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
318
|
+
sage: n = ntl.mat_GF2E(ctx, 5,5,[3..27])
|
|
319
|
+
sage: m == n
|
|
320
|
+
False
|
|
321
|
+
sage: m == m
|
|
322
|
+
True
|
|
323
|
+
sage: m == []
|
|
324
|
+
False
|
|
325
|
+
"""
|
|
326
|
+
self.c.restore_c()
|
|
327
|
+
|
|
328
|
+
if op != Py_EQ and op != Py_NE:
|
|
329
|
+
raise TypeError("matrices over GF(2^e) are not ordered")
|
|
330
|
+
|
|
331
|
+
cdef ntl_mat_GF2E b
|
|
332
|
+
try:
|
|
333
|
+
b = <ntl_mat_GF2E?>other
|
|
334
|
+
except TypeError:
|
|
335
|
+
return NotImplemented
|
|
336
|
+
|
|
337
|
+
return (op == Py_EQ) == (self.x == b.x)
|
|
338
|
+
|
|
339
|
+
def NumRows(self):
|
|
340
|
+
"""
|
|
341
|
+
Return the number of rows in ``self``.
|
|
342
|
+
|
|
343
|
+
EXAMPLES::
|
|
344
|
+
|
|
345
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
346
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24]) ; m.NumRows()
|
|
347
|
+
5
|
|
348
|
+
"""
|
|
349
|
+
return int(self.x.NumRows())
|
|
350
|
+
|
|
351
|
+
def NumCols(self):
|
|
352
|
+
"""
|
|
353
|
+
Return the number of columns in ``self``.
|
|
354
|
+
|
|
355
|
+
EXAMPLES::
|
|
356
|
+
|
|
357
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
358
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24]) ; m.NumCols()
|
|
359
|
+
5
|
|
360
|
+
"""
|
|
361
|
+
return int(self.x.NumCols())
|
|
362
|
+
|
|
363
|
+
def __setitem__(self, ij, x):
|
|
364
|
+
"""
|
|
365
|
+
EXAMPLES::
|
|
366
|
+
|
|
367
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
368
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
369
|
+
sage: ntl.GF2XHexOutput(0)
|
|
370
|
+
sage: m[0,0]
|
|
371
|
+
[]
|
|
372
|
+
sage: m[0,0] = 1
|
|
373
|
+
sage: m[0,0]
|
|
374
|
+
[1]
|
|
375
|
+
"""
|
|
376
|
+
cdef int i, j
|
|
377
|
+
if not isinstance(x, ntl_GF2E):
|
|
378
|
+
x = ntl_GF2E(x, self.c)
|
|
379
|
+
|
|
380
|
+
if isinstance(ij, tuple) and len(ij) == 2:
|
|
381
|
+
i, j = ij
|
|
382
|
+
elif self.x.NumCols() == 1 and isinstance(ij, (Integer, int)):
|
|
383
|
+
i = ij
|
|
384
|
+
j = 0
|
|
385
|
+
elif self.x.NumRows() == 1 and isinstance(ij, (Integer, int)):
|
|
386
|
+
i = 0
|
|
387
|
+
j = ij
|
|
388
|
+
else:
|
|
389
|
+
raise TypeError('ij is not a matrix index')
|
|
390
|
+
|
|
391
|
+
if i < 0 or i >= self.x.NumRows() or j < 0 or j >= self.x.NumCols():
|
|
392
|
+
raise IndexError("array index out of range")
|
|
393
|
+
|
|
394
|
+
if not (<ntl_GF2E>x).c is self.c:
|
|
395
|
+
raise ValueError("You cannot assign elements from different fields.")
|
|
396
|
+
|
|
397
|
+
self.c.restore_c()
|
|
398
|
+
|
|
399
|
+
mat_GF2E_setitem(&self.x, i, j, &(<ntl_GF2E>x).x)
|
|
400
|
+
|
|
401
|
+
def __getitem__(self, ij):
|
|
402
|
+
"""
|
|
403
|
+
EXAMPLES::
|
|
404
|
+
|
|
405
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
406
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
407
|
+
sage: m[0,1]
|
|
408
|
+
[1]
|
|
409
|
+
sage: m[0,0] = 0
|
|
410
|
+
sage: m[0,0]
|
|
411
|
+
[]
|
|
412
|
+
"""
|
|
413
|
+
cdef int i, j
|
|
414
|
+
if isinstance(ij, tuple) and len(ij) == 2:
|
|
415
|
+
i, j = ij
|
|
416
|
+
elif self.x.NumCols() == 1 and isinstance(ij, (Integer, int)):
|
|
417
|
+
i = ij
|
|
418
|
+
j = 0
|
|
419
|
+
elif self.x.NumRows() == 1 and isinstance(ij, (Integer, int)):
|
|
420
|
+
i = 0
|
|
421
|
+
j = ij
|
|
422
|
+
else:
|
|
423
|
+
raise TypeError('ij is not a matrix index')
|
|
424
|
+
|
|
425
|
+
if i < 0 or i >= self.x.NumRows() or j < 0 or j >= self.x.NumCols():
|
|
426
|
+
raise IndexError("array index out of range")
|
|
427
|
+
|
|
428
|
+
cdef ntl_GF2E e = self._new_element()
|
|
429
|
+
e.x = self.x.get( i+1, j+1 )
|
|
430
|
+
return e
|
|
431
|
+
|
|
432
|
+
def determinant(self):
|
|
433
|
+
"""
|
|
434
|
+
Return the determinant.
|
|
435
|
+
|
|
436
|
+
EXAMPLES::
|
|
437
|
+
|
|
438
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
439
|
+
sage: ntl.GF2XHexOutput(0)
|
|
440
|
+
sage: ntl.mat_GF2E(ctx, 5,5,[0..24]).determinant()
|
|
441
|
+
[0 1 0 1 1 1 1]
|
|
442
|
+
sage: ntl.mat_GF2E(ctx, 5,5,[3..27]).determinant()
|
|
443
|
+
[0 1 1 0 0 1]
|
|
444
|
+
"""
|
|
445
|
+
cdef ntl_GF2E r = self._new_element()
|
|
446
|
+
sig_on()
|
|
447
|
+
r.x = mat_GF2E_determinant(self.x)
|
|
448
|
+
sig_off()
|
|
449
|
+
return r
|
|
450
|
+
|
|
451
|
+
def gauss(self, ncols=-1):
|
|
452
|
+
r"""
|
|
453
|
+
Perform unitary row operations so as to bring this matrix
|
|
454
|
+
into row echelon form.
|
|
455
|
+
|
|
456
|
+
If the optional argument ``ncols`` is supplied, stops when
|
|
457
|
+
first ``ncols`` columns are in echelon form. The return value
|
|
458
|
+
is the rank (or the rank of the first ``ncols`` columns).
|
|
459
|
+
|
|
460
|
+
INPUT:
|
|
461
|
+
|
|
462
|
+
- ``ncols`` -- number of columns to process (default: all)
|
|
463
|
+
|
|
464
|
+
EXAMPLES::
|
|
465
|
+
|
|
466
|
+
sage: m = ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
|
|
467
|
+
sage: ntl.mat_GF2E(ctx, 5,5,[3..27]).gauss()
|
|
468
|
+
5
|
|
469
|
+
sage: ntl.mat_GF2E(ctx, 5,5).gauss()
|
|
470
|
+
0
|
|
471
|
+
sage: ntl.mat_GF2E(ctx, 5,5,[3..27]).gauss(3)
|
|
472
|
+
3
|
|
473
|
+
"""
|
|
474
|
+
if ncols == -1:
|
|
475
|
+
ncols = self.x.NumCols()
|
|
476
|
+
return int(mat_GF2E_gauss(self.x, int(ncols)))
|
|
477
|
+
|
|
478
|
+
def list(self):
|
|
479
|
+
"""
|
|
480
|
+
Return a list of the entries in this matrix.
|
|
481
|
+
|
|
482
|
+
EXAMPLES::
|
|
483
|
+
|
|
484
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
485
|
+
sage: m = ntl.mat_GF2E(ctx, 2,2,[ntl.GF2E_random(ctx) for x in range(2*2)])
|
|
486
|
+
sage: ntl.GF2XHexOutput(0)
|
|
487
|
+
sage: l = m.list(); l # random
|
|
488
|
+
[[1 1 0 0 1 0 1 1], [1 1 1 0 1 1 1], [0 1 1 1 1 0 0 1], [0 1 0 1 1 1]]
|
|
489
|
+
sage: len(l) == 4
|
|
490
|
+
True
|
|
491
|
+
sage: all(a.modulus_context() is ctx for a in l)
|
|
492
|
+
True
|
|
493
|
+
"""
|
|
494
|
+
return [self[i,j] for i in range(self.NumRows()) for j in range(self.x.NumCols())]
|
|
495
|
+
|
|
496
|
+
def IsZero(self):
|
|
497
|
+
"""
|
|
498
|
+
Return ``True`` if ``self`` is zero, and ``False`` otherwise.
|
|
499
|
+
|
|
500
|
+
EXAMPLES::
|
|
501
|
+
|
|
502
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
503
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
504
|
+
sage: n = ntl.mat_GF2E(ctx, 5,5)
|
|
505
|
+
sage: m.IsZero()
|
|
506
|
+
False
|
|
507
|
+
sage: n.IsZero()
|
|
508
|
+
True
|
|
509
|
+
"""
|
|
510
|
+
cdef long isZero
|
|
511
|
+
sig_on()
|
|
512
|
+
isZero = mat_GF2E_IsZero(self.x)
|
|
513
|
+
sig_off()
|
|
514
|
+
return bool(isZero)
|
|
515
|
+
|
|
516
|
+
def _sage_(ntl_mat_GF2E self, k=None):
|
|
517
|
+
"""
|
|
518
|
+
Return a ``Matrix`` over a ``FiniteField`` representation
|
|
519
|
+
of this element.
|
|
520
|
+
|
|
521
|
+
INPUT:
|
|
522
|
+
|
|
523
|
+
- ``k`` -- (optional) GF(2**deg)
|
|
524
|
+
|
|
525
|
+
OUTPUT: Matrix over k
|
|
526
|
+
|
|
527
|
+
EXAMPLES::
|
|
528
|
+
|
|
529
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1])
|
|
530
|
+
sage: m = ntl.mat_GF2E(ctx, 2,2,[3..6])
|
|
531
|
+
sage: ntl.GF2XHexOutput(0)
|
|
532
|
+
sage: m
|
|
533
|
+
[[[1 1] [0 0 1]]
|
|
534
|
+
[[1 0 1] [0 1 1]]
|
|
535
|
+
]
|
|
536
|
+
sage: m._sage_()
|
|
537
|
+
[ a + 1 a^2]
|
|
538
|
+
[a^2 + 1 a^2 + a]
|
|
539
|
+
"""
|
|
540
|
+
if k is None:
|
|
541
|
+
from sage.rings.finite_rings.finite_field_constructor import FiniteField
|
|
542
|
+
f = self.c.m._sage_()
|
|
543
|
+
e = GF2E_degree()
|
|
544
|
+
k = FiniteField(2**e, name='a', modulus=f)
|
|
545
|
+
|
|
546
|
+
l = [e._sage_(k) for e in self.list()] # we actually can do faster than this
|
|
547
|
+
|
|
548
|
+
from sage.matrix.constructor import matrix
|
|
549
|
+
return matrix(k, self.x.NumRows(), self.x.NumCols(), l)
|
|
550
|
+
|
|
551
|
+
def transpose(ntl_mat_GF2E self):
|
|
552
|
+
"""
|
|
553
|
+
Return the transposed matrix of ``self``.
|
|
554
|
+
|
|
555
|
+
EXAMPLES::
|
|
556
|
+
|
|
557
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
558
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
559
|
+
sage: n = m.transpose()
|
|
560
|
+
sage: n == m
|
|
561
|
+
False
|
|
562
|
+
sage: n.transpose() == m
|
|
563
|
+
True
|
|
564
|
+
"""
|
|
565
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
566
|
+
sig_on()
|
|
567
|
+
mat_GF2E_transpose(r.x, self.x)
|
|
568
|
+
sig_off()
|
|
569
|
+
return r
|
|
570
|
+
|
|
571
|
+
def __invert__(self):
|
|
572
|
+
"""
|
|
573
|
+
Return `X = A^{-1}`; an error is raised if A is singular.
|
|
574
|
+
|
|
575
|
+
EXAMPLES::
|
|
576
|
+
|
|
577
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
578
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
579
|
+
sage: n = ~m
|
|
580
|
+
sage: o = n*m
|
|
581
|
+
sage: o.IsIdent()
|
|
582
|
+
True
|
|
583
|
+
"""
|
|
584
|
+
cdef ntl_mat_GF2E r = self._new()
|
|
585
|
+
sig_on()
|
|
586
|
+
mat_GF2E_inv(r.x, self.x)
|
|
587
|
+
sig_off()
|
|
588
|
+
return r
|
|
589
|
+
|
|
590
|
+
def IsIdent(self, n=-1):
|
|
591
|
+
r"""
|
|
592
|
+
Test if `A` is the `n \times n` identity matrix.
|
|
593
|
+
|
|
594
|
+
EXAMPLES::
|
|
595
|
+
|
|
596
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
597
|
+
sage: m = ntl.mat_GF2E(ctx, 5,5,[0..24])
|
|
598
|
+
sage: n = ~m
|
|
599
|
+
sage: o = n*m
|
|
600
|
+
sage: o.IsIdent()
|
|
601
|
+
True
|
|
602
|
+
"""
|
|
603
|
+
if n < 0:
|
|
604
|
+
n = self.NumRows()
|
|
605
|
+
return bool(mat_GF2E_IsIdent(self.x, n))
|
|
606
|
+
|
|
607
|
+
def IsDiag(self, long n, ntl_GF2E d):
|
|
608
|
+
"""
|
|
609
|
+
Test if X is an n x n diagonal matrix with d on diagonal.
|
|
610
|
+
|
|
611
|
+
EXAMPLES::
|
|
612
|
+
|
|
613
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
614
|
+
sage: m = ntl.mat_GF2E(ctx, 3,3,[[0,1],0,0, 0,[0,1],0, 0,0,[0,1]])
|
|
615
|
+
sage: m.IsDiag(2, ntl.GF2E([0,1],ctx))
|
|
616
|
+
False
|
|
617
|
+
sage: m.IsDiag(3, ntl.GF2E([0,1],ctx))
|
|
618
|
+
True
|
|
619
|
+
"""
|
|
620
|
+
return bool(mat_GF2E_IsDiag(self.x, n, d.x))
|
|
621
|
+
|
|
622
|
+
def image(self):
|
|
623
|
+
"""
|
|
624
|
+
The rows of X are computed as basis of A's row space. X is
|
|
625
|
+
row echelon form.
|
|
626
|
+
|
|
627
|
+
EXAMPLES::
|
|
628
|
+
|
|
629
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
630
|
+
sage: m = ntl.mat_GF2E(ctx, 3,3,[0..24])
|
|
631
|
+
sage: ntl.GF2XHexOutput(1)
|
|
632
|
+
sage: m.image()
|
|
633
|
+
[[0x3 0x4 0x5]
|
|
634
|
+
[0x0 0x1 0x2]
|
|
635
|
+
[0x0 0x0 0xc1]
|
|
636
|
+
]
|
|
637
|
+
"""
|
|
638
|
+
cdef ntl_mat_GF2E X = self._new()
|
|
639
|
+
sig_on()
|
|
640
|
+
mat_GF2E_image(X.x, self.x)
|
|
641
|
+
sig_off()
|
|
642
|
+
return X
|
|
643
|
+
|
|
644
|
+
def kernel(self):
|
|
645
|
+
"""
|
|
646
|
+
Compute a basis for the kernel of the map ``x -> x*A``, where
|
|
647
|
+
``x`` is a row vector.
|
|
648
|
+
|
|
649
|
+
EXAMPLES::
|
|
650
|
+
|
|
651
|
+
sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
|
|
652
|
+
sage: m = ntl.mat_GF2E(ctx, 3,3,[0..24])
|
|
653
|
+
sage: ntl.GF2XHexOutput(1)
|
|
654
|
+
sage: m.kernel()
|
|
655
|
+
[]
|
|
656
|
+
"""
|
|
657
|
+
cdef ntl_mat_GF2E X = self._new()
|
|
658
|
+
sig_on()
|
|
659
|
+
mat_GF2E_kernel(X.x, self.x)
|
|
660
|
+
sig_off()
|
|
661
|
+
return X
|
|
662
|
+
|
|
663
|
+
def randomize(self, density=1, nonzero=False):
|
|
664
|
+
"""
|
|
665
|
+
Randomize ``density`` proportion of the entries of this matrix,
|
|
666
|
+
leaving the rest unchanged.
|
|
667
|
+
|
|
668
|
+
INPUT:
|
|
669
|
+
|
|
670
|
+
- ``density`` -- float; proportion (roughly) to be considered for
|
|
671
|
+
changes
|
|
672
|
+
- ``nonzero`` -- boolean (default: ``False``); whether the new entries
|
|
673
|
+
are forced to be nonzero
|
|
674
|
+
|
|
675
|
+
EXAMPLES::
|
|
676
|
+
|
|
677
|
+
sage: k.<a> = GF(2^4)
|
|
678
|
+
sage: ctx = ntl.GF2EContext(k)
|
|
679
|
+
sage: ntl.GF2XHexOutput(1)
|
|
680
|
+
sage: A = ntl.mat_GF2E(ctx, 100, 100)
|
|
681
|
+
sage: expected_non_zeros = 100 * 100 * (1 - 1.0/2^4)
|
|
682
|
+
sage: observed = lambda : len([e for e in A.list() if e!=0])
|
|
683
|
+
sage: n = 0; s = 0
|
|
684
|
+
sage: def add_samples():
|
|
685
|
+
....: global n, s, A
|
|
686
|
+
....: for i in range(10):
|
|
687
|
+
....: A.randomize()
|
|
688
|
+
....: n += 1
|
|
689
|
+
....: s += observed() - expected_non_zeros
|
|
690
|
+
|
|
691
|
+
sage: add_samples()
|
|
692
|
+
sage: while abs(s*1.0/n) > 10: add_samples()
|
|
693
|
+
sage: while abs(s*1.0/n) > 5: add_samples() # long time
|
|
694
|
+
|
|
695
|
+
sage: A = ntl.mat_GF2E(ctx, 100,100)
|
|
696
|
+
sage: A.randomize(nonzero=True)
|
|
697
|
+
sage: len([e for e in A.list() if e!=0])
|
|
698
|
+
10000
|
|
699
|
+
|
|
700
|
+
sage: expected_non_zeros = 1000
|
|
701
|
+
sage: n = 0; s = 0
|
|
702
|
+
sage: def add_samples():
|
|
703
|
+
....: global n, s, A
|
|
704
|
+
....: for i in range(10):
|
|
705
|
+
....: A = ntl.mat_GF2E(ctx, 100,100)
|
|
706
|
+
....: A.randomize(nonzero=True, density=0.1)
|
|
707
|
+
....: n += 1
|
|
708
|
+
....: s += observed() - expected_non_zeros
|
|
709
|
+
|
|
710
|
+
sage: add_samples()
|
|
711
|
+
sage: while abs(s*1.0/n) > 10: add_samples()
|
|
712
|
+
sage: while abs(s*1.0/n) > 5: add_samples() # long time
|
|
713
|
+
"""
|
|
714
|
+
cdef long i,j
|
|
715
|
+
cdef GF2E_c tmp
|
|
716
|
+
|
|
717
|
+
cdef float _density = density
|
|
718
|
+
cdef randstate rstate = current_randstate()
|
|
719
|
+
|
|
720
|
+
if _density <= 0:
|
|
721
|
+
return
|
|
722
|
+
if _density > 1:
|
|
723
|
+
_density = 1.0
|
|
724
|
+
|
|
725
|
+
if not nonzero:
|
|
726
|
+
if _density == 1.0:
|
|
727
|
+
for i in range(self.x.NumRows()):
|
|
728
|
+
for j in range(self.x.NumCols()):
|
|
729
|
+
tmp = GF2E_random()
|
|
730
|
+
mat_GF2E_setitem(&self.x, i, j, &tmp)
|
|
731
|
+
else:
|
|
732
|
+
for i in range(self.x.NumRows()):
|
|
733
|
+
for j in range(self.x.NumCols()):
|
|
734
|
+
if rstate.c_rand_double() <= _density:
|
|
735
|
+
tmp = GF2E_random()
|
|
736
|
+
mat_GF2E_setitem(&self.x, i, j, &tmp)
|
|
737
|
+
else:
|
|
738
|
+
if _density == 1.0:
|
|
739
|
+
for i in range(self.x.NumRows()):
|
|
740
|
+
for j in range(self.x.NumCols()):
|
|
741
|
+
tmp = GF2E_random()
|
|
742
|
+
while GF2E_IsZero(tmp):
|
|
743
|
+
tmp = GF2E_random()
|
|
744
|
+
mat_GF2E_setitem(&self.x, i, j, &tmp)
|
|
745
|
+
else:
|
|
746
|
+
for i in range(self.x.NumRows()):
|
|
747
|
+
for j in range(self.x.NumCols()):
|
|
748
|
+
if rstate.c_rand_double() <= _density:
|
|
749
|
+
tmp = GF2E_random()
|
|
750
|
+
while GF2E_IsZero(tmp):
|
|
751
|
+
tmp = GF2E_random()
|
|
752
|
+
mat_GF2E_setitem(&self.x, i, j, &tmp)
|