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,842 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-ntl
|
|
2
|
+
"""
|
|
3
|
+
Polynomial Template for C/C++ Library Interfaces
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# ***************************************************************************
|
|
7
|
+
# Copyright (C) 2008 Martin Albrecht <M.R.Albrecht@rhul.ac.uk>
|
|
8
|
+
# Copyright (C) 2008 Robert Bradshaw
|
|
9
|
+
#
|
|
10
|
+
# This program is free software: you can redistribute it and/or modify
|
|
11
|
+
# it under the terms of the GNU General Public License as published by
|
|
12
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
13
|
+
# (at your option) any later version.
|
|
14
|
+
# https://www.gnu.org/licenses/
|
|
15
|
+
# ***************************************************************************
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from sage.rings.polynomial.polynomial_element cimport Polynomial
|
|
19
|
+
from sage.structure.element cimport ModuleElement, Element, RingElement
|
|
20
|
+
from sage.structure.element import coerce_binop
|
|
21
|
+
from sage.structure.richcmp cimport rich_to_bool
|
|
22
|
+
from sage.rings.fraction_field_element import FractionFieldElement
|
|
23
|
+
from sage.rings.integer cimport Integer
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
from cypari2.gen import Gen as pari_gen
|
|
27
|
+
except ImportError:
|
|
28
|
+
pari_gen = ()
|
|
29
|
+
|
|
30
|
+
import operator
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def make_element(parent, args):
|
|
34
|
+
return parent(*args)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
cdef inline Polynomial_template element_shift(self, int n):
|
|
38
|
+
if not isinstance(self, Polynomial_template):
|
|
39
|
+
if n > 0:
|
|
40
|
+
error_msg = "Cannot shift %s << %n." % (self, n)
|
|
41
|
+
else:
|
|
42
|
+
error_msg = "Cannot shift %s >> %n." % (self, n)
|
|
43
|
+
raise TypeError(error_msg)
|
|
44
|
+
|
|
45
|
+
if n == 0:
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
cdef celement *gen = celement_new((<Polynomial_template>self)._cparent)
|
|
49
|
+
celement_gen(gen, 0, (<Polynomial_template>self)._cparent)
|
|
50
|
+
celement_pow(gen, gen, abs(n), NULL, (<Polynomial_template>self)._cparent)
|
|
51
|
+
cdef type T = type(self)
|
|
52
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
53
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
54
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
55
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
56
|
+
|
|
57
|
+
if n > 0:
|
|
58
|
+
celement_mul(&r.x, &(<Polynomial_template>self).x, gen, (<Polynomial_template>self)._cparent)
|
|
59
|
+
else:
|
|
60
|
+
celement_floordiv(&r.x, &(<Polynomial_template>self).x, gen, (<Polynomial_template>self)._cparent)
|
|
61
|
+
|
|
62
|
+
celement_delete(gen, (<Polynomial_template>self)._cparent)
|
|
63
|
+
return r
|
|
64
|
+
|
|
65
|
+
cdef class Polynomial_template(Polynomial):
|
|
66
|
+
r"""
|
|
67
|
+
Template for interfacing to external C / C++ libraries for implementations of polynomials.
|
|
68
|
+
|
|
69
|
+
AUTHORS:
|
|
70
|
+
|
|
71
|
+
- Robert Bradshaw (2008-10): original idea for templating
|
|
72
|
+
- Martin Albrecht (2008-10): initial implementation
|
|
73
|
+
|
|
74
|
+
This file implements a simple templating engine for linking univariate
|
|
75
|
+
polynomials to their C/C++ library implementations. It requires a
|
|
76
|
+
'linkage' file which implements the ``celement_`` functions (see
|
|
77
|
+
:mod:`sage.libs.ntl.ntl_GF2X_linkage` for an example). Both parts are
|
|
78
|
+
then plugged together by inclusion of the linkage file when inheriting from
|
|
79
|
+
this class. See :mod:`sage.rings.polynomial.polynomial_gf2x` for an
|
|
80
|
+
example.
|
|
81
|
+
|
|
82
|
+
We illustrate the generic glueing using univariate polynomials over
|
|
83
|
+
`\mathop{\mathrm{GF}}(2)`.
|
|
84
|
+
|
|
85
|
+
.. NOTE::
|
|
86
|
+
|
|
87
|
+
Implementations using this template MUST implement coercion from base
|
|
88
|
+
ring elements and :meth:`get_unsafe`. See
|
|
89
|
+
:class:`~sage.rings.polynomial.polynomial_gf2x.Polynomial_GF2X` for an
|
|
90
|
+
example.
|
|
91
|
+
"""
|
|
92
|
+
def __init__(self, parent, x=None, check=True, is_gen=False, construct=False):
|
|
93
|
+
"""
|
|
94
|
+
EXAMPLES::
|
|
95
|
+
|
|
96
|
+
sage: P.<x> = GF(2)[]
|
|
97
|
+
sage: P(0)
|
|
98
|
+
0
|
|
99
|
+
sage: P(GF(2)(1))
|
|
100
|
+
1
|
|
101
|
+
sage: P(3)
|
|
102
|
+
1
|
|
103
|
+
sage: P([1,0,1])
|
|
104
|
+
x^2 + 1
|
|
105
|
+
sage: P(list(map(GF(2),[1,0,1])))
|
|
106
|
+
x^2 + 1
|
|
107
|
+
"""
|
|
108
|
+
cdef celement *gen
|
|
109
|
+
cdef celement *monomial
|
|
110
|
+
cdef Py_ssize_t deg
|
|
111
|
+
|
|
112
|
+
Polynomial.__init__(self, parent, is_gen=is_gen)
|
|
113
|
+
|
|
114
|
+
(<Polynomial_template>self)._cparent = get_cparent(self._parent)
|
|
115
|
+
|
|
116
|
+
if is_gen:
|
|
117
|
+
celement_construct(&self.x, (<Polynomial_template>self)._cparent)
|
|
118
|
+
celement_gen(&self.x, 0, (<Polynomial_template>self)._cparent)
|
|
119
|
+
|
|
120
|
+
elif isinstance(x, Polynomial_template):
|
|
121
|
+
try:
|
|
122
|
+
celement_construct(&self.x, (<Polynomial_template>self)._cparent)
|
|
123
|
+
celement_set(&self.x, &(<Polynomial_template>x).x, (<Polynomial_template>self)._cparent)
|
|
124
|
+
except NotImplementedError:
|
|
125
|
+
raise TypeError("%s not understood" % x)
|
|
126
|
+
|
|
127
|
+
elif isinstance(x, (int, Integer)):
|
|
128
|
+
try:
|
|
129
|
+
celement_construct(&self.x, (<Polynomial_template>self)._cparent)
|
|
130
|
+
celement_set_si(&self.x, int(x), (<Polynomial_template>self)._cparent)
|
|
131
|
+
except NotImplementedError:
|
|
132
|
+
raise TypeError("%s not understood" % x)
|
|
133
|
+
|
|
134
|
+
elif isinstance(x, (list, tuple)):
|
|
135
|
+
celement_construct(&self.x, (<Polynomial_template>self)._cparent)
|
|
136
|
+
gen = celement_new((<Polynomial_template>self)._cparent)
|
|
137
|
+
monomial = celement_new((<Polynomial_template>self)._cparent)
|
|
138
|
+
|
|
139
|
+
celement_set_si(&self.x, 0, (<Polynomial_template>self)._cparent)
|
|
140
|
+
celement_gen(gen, 0, (<Polynomial_template>self)._cparent)
|
|
141
|
+
|
|
142
|
+
deg = 0
|
|
143
|
+
for e in x:
|
|
144
|
+
# r += parent(e)*power
|
|
145
|
+
celement_pow(monomial, gen, deg, NULL, (<Polynomial_template>self)._cparent)
|
|
146
|
+
celement_mul(monomial, &(<Polynomial_template>self.__class__(parent, e)).x, monomial, (<Polynomial_template>self)._cparent)
|
|
147
|
+
celement_add(&self.x, &self.x, monomial, (<Polynomial_template>self)._cparent)
|
|
148
|
+
deg += 1
|
|
149
|
+
|
|
150
|
+
celement_delete(gen, (<Polynomial_template>self)._cparent)
|
|
151
|
+
celement_delete(monomial, (<Polynomial_template>self)._cparent)
|
|
152
|
+
|
|
153
|
+
elif isinstance(x, dict):
|
|
154
|
+
celement_construct(&self.x, (<Polynomial_template>self)._cparent)
|
|
155
|
+
gen = celement_new((<Polynomial_template>self)._cparent)
|
|
156
|
+
monomial = celement_new((<Polynomial_template>self)._cparent)
|
|
157
|
+
|
|
158
|
+
celement_set_si(&self.x, 0, (<Polynomial_template>self)._cparent)
|
|
159
|
+
celement_gen(gen, 0, (<Polynomial_template>self)._cparent)
|
|
160
|
+
|
|
161
|
+
for deg, coef in x.iteritems():
|
|
162
|
+
celement_pow(monomial, gen, deg, NULL, (<Polynomial_template>self)._cparent)
|
|
163
|
+
celement_mul(monomial, &(<Polynomial_template>self.__class__(parent, coef)).x, monomial, (<Polynomial_template>self)._cparent)
|
|
164
|
+
celement_add(&self.x, &self.x, monomial, (<Polynomial_template>self)._cparent)
|
|
165
|
+
|
|
166
|
+
celement_delete(gen, (<Polynomial_template>self)._cparent)
|
|
167
|
+
celement_delete(monomial, (<Polynomial_template>self)._cparent)
|
|
168
|
+
|
|
169
|
+
elif isinstance(x, pari_gen):
|
|
170
|
+
k = (<Polynomial_template>self)._parent.base_ring()
|
|
171
|
+
x = [k(w) for w in x.list()]
|
|
172
|
+
self.__class__.__init__(self, parent, x, check=True, is_gen=False, construct=construct)
|
|
173
|
+
elif isinstance(x, Polynomial):
|
|
174
|
+
k = (<Polynomial_template>self)._parent.base_ring()
|
|
175
|
+
x = [k(w) for w in list(x)]
|
|
176
|
+
Polynomial_template.__init__(self, parent, x, check=True, is_gen=False, construct=construct)
|
|
177
|
+
elif isinstance(x, FractionFieldElement) and (x.parent().base() is parent or x.parent().base() == parent) and x.denominator() == 1:
|
|
178
|
+
x = x.numerator()
|
|
179
|
+
self.__class__.__init__(self, parent, x, check=check, is_gen=is_gen, construct=construct)
|
|
180
|
+
else:
|
|
181
|
+
x = parent.base_ring()(x)
|
|
182
|
+
self.__class__.__init__(self, parent, x, check=check, is_gen=is_gen, construct=construct)
|
|
183
|
+
|
|
184
|
+
def get_cparent(self):
|
|
185
|
+
return <long> self._cparent
|
|
186
|
+
|
|
187
|
+
def __reduce__(self):
|
|
188
|
+
"""
|
|
189
|
+
EXAMPLES::
|
|
190
|
+
|
|
191
|
+
sage: P.<x> = GF(2)[]
|
|
192
|
+
sage: loads(dumps(x)) == x
|
|
193
|
+
True
|
|
194
|
+
"""
|
|
195
|
+
return make_element, ((<Polynomial_template>self)._parent, (self.list(), False, self.is_gen()))
|
|
196
|
+
|
|
197
|
+
cpdef list list(self, bint copy=True):
|
|
198
|
+
"""
|
|
199
|
+
EXAMPLES::
|
|
200
|
+
|
|
201
|
+
sage: P.<x> = GF(2)[]
|
|
202
|
+
sage: x.list()
|
|
203
|
+
[0, 1]
|
|
204
|
+
sage: list(x)
|
|
205
|
+
[0, 1]
|
|
206
|
+
"""
|
|
207
|
+
cdef Py_ssize_t i
|
|
208
|
+
return [self[i] for i in range(celement_len(&self.x, (<Polynomial_template>self)._cparent))]
|
|
209
|
+
|
|
210
|
+
def __dealloc__(self):
|
|
211
|
+
"""
|
|
212
|
+
EXAMPLES::
|
|
213
|
+
|
|
214
|
+
sage: P.<x> = GF(2)[]
|
|
215
|
+
sage: del x
|
|
216
|
+
|
|
217
|
+
TESTS:
|
|
218
|
+
|
|
219
|
+
The following has been a problem in a preliminary version of
|
|
220
|
+
:issue:`12313`::
|
|
221
|
+
|
|
222
|
+
sage: # needs sage.rings.finite_rings
|
|
223
|
+
sage: K.<z> = GF(4)
|
|
224
|
+
sage: P.<x> = K[]
|
|
225
|
+
sage: del P
|
|
226
|
+
sage: del x
|
|
227
|
+
sage: import gc
|
|
228
|
+
sage: _ = gc.collect()
|
|
229
|
+
"""
|
|
230
|
+
celement_destruct(&self.x, (<Polynomial_template>self)._cparent)
|
|
231
|
+
|
|
232
|
+
cpdef _add_(self, right):
|
|
233
|
+
"""
|
|
234
|
+
EXAMPLES::
|
|
235
|
+
|
|
236
|
+
sage: P.<x> = GF(2)[]
|
|
237
|
+
sage: x + 1
|
|
238
|
+
x + 1
|
|
239
|
+
"""
|
|
240
|
+
cdef type T = type(self)
|
|
241
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
242
|
+
|
|
243
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
244
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
245
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
246
|
+
celement_add(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x, (<Polynomial_template>self)._cparent)
|
|
247
|
+
#assert(r._parent(pari(self) + pari(right)) == r)
|
|
248
|
+
return r
|
|
249
|
+
|
|
250
|
+
cpdef _sub_(self, right):
|
|
251
|
+
"""
|
|
252
|
+
EXAMPLES::
|
|
253
|
+
|
|
254
|
+
sage: P.<x> = GF(2)[]
|
|
255
|
+
sage: x - 1
|
|
256
|
+
x + 1
|
|
257
|
+
"""
|
|
258
|
+
cdef type T = type(self)
|
|
259
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
260
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
261
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
262
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
263
|
+
celement_sub(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x, (<Polynomial_template>self)._cparent)
|
|
264
|
+
#assert(r._parent(pari(self) - pari(right)) == r)
|
|
265
|
+
return r
|
|
266
|
+
|
|
267
|
+
def __neg__(self):
|
|
268
|
+
"""
|
|
269
|
+
EXAMPLES::
|
|
270
|
+
|
|
271
|
+
sage: P.<x> = GF(2)[]
|
|
272
|
+
sage: -x
|
|
273
|
+
x
|
|
274
|
+
"""
|
|
275
|
+
cdef type T = type(self)
|
|
276
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
277
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
278
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
279
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
280
|
+
celement_neg(&r.x, &self.x, (<Polynomial_template>self)._cparent)
|
|
281
|
+
#assert(r._parent(-pari(self)) == r)
|
|
282
|
+
return r
|
|
283
|
+
|
|
284
|
+
cpdef _lmul_(self, Element left):
|
|
285
|
+
"""
|
|
286
|
+
EXAMPLES::
|
|
287
|
+
|
|
288
|
+
sage: P.<x> = GF(2)[]
|
|
289
|
+
sage: t = x^2 + x + 1
|
|
290
|
+
sage: 0*t
|
|
291
|
+
0
|
|
292
|
+
sage: 1*t
|
|
293
|
+
x^2 + x + 1
|
|
294
|
+
|
|
295
|
+
sage: R.<y> = GF(5)[]
|
|
296
|
+
sage: u = y^2 + y + 1
|
|
297
|
+
sage: 3*u
|
|
298
|
+
3*y^2 + 3*y + 3
|
|
299
|
+
sage: 5*u
|
|
300
|
+
0
|
|
301
|
+
sage: (2^81)*u
|
|
302
|
+
2*y^2 + 2*y + 2
|
|
303
|
+
sage: (-2^81)*u
|
|
304
|
+
3*y^2 + 3*y + 3
|
|
305
|
+
|
|
306
|
+
::
|
|
307
|
+
|
|
308
|
+
sage: P.<x> = GF(2)[]
|
|
309
|
+
sage: t = x^2 + x + 1
|
|
310
|
+
sage: t*0
|
|
311
|
+
0
|
|
312
|
+
sage: t*1
|
|
313
|
+
x^2 + x + 1
|
|
314
|
+
|
|
315
|
+
sage: R.<y> = GF(5)[]
|
|
316
|
+
sage: u = y^2 + y + 1
|
|
317
|
+
sage: u*3
|
|
318
|
+
3*y^2 + 3*y + 3
|
|
319
|
+
sage: u*5
|
|
320
|
+
0
|
|
321
|
+
"""
|
|
322
|
+
cdef type T = type(self)
|
|
323
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
324
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
325
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
326
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
327
|
+
celement_mul_scalar(&r.x, &(<Polynomial_template>self).x, left, (<Polynomial_template>self)._cparent)
|
|
328
|
+
return r
|
|
329
|
+
|
|
330
|
+
cpdef _mul_(self, right):
|
|
331
|
+
"""
|
|
332
|
+
EXAMPLES::
|
|
333
|
+
|
|
334
|
+
sage: P.<x> = GF(2)[]
|
|
335
|
+
sage: x*(x+1)
|
|
336
|
+
x^2 + x
|
|
337
|
+
"""
|
|
338
|
+
cdef type T = type(self)
|
|
339
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
340
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
341
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
342
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
343
|
+
celement_mul(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x, (<Polynomial_template>self)._cparent)
|
|
344
|
+
#assert(r._parent(pari(self) * pari(right)) == r)
|
|
345
|
+
return r
|
|
346
|
+
|
|
347
|
+
@coerce_binop
|
|
348
|
+
def gcd(self, Polynomial_template other):
|
|
349
|
+
"""
|
|
350
|
+
Return the greatest common divisor of ``self`` and ``other``.
|
|
351
|
+
|
|
352
|
+
EXAMPLES::
|
|
353
|
+
|
|
354
|
+
sage: P.<x> = GF(2)[]
|
|
355
|
+
sage: f = x*(x+1)
|
|
356
|
+
sage: f.gcd(x+1)
|
|
357
|
+
x + 1
|
|
358
|
+
sage: f.gcd(x^2)
|
|
359
|
+
x
|
|
360
|
+
|
|
361
|
+
TESTS:
|
|
362
|
+
|
|
363
|
+
Ensure non-invertible elements does not crash Sage (:issue:`37317`)::
|
|
364
|
+
|
|
365
|
+
sage: R.<x> = Zmod(4)[]
|
|
366
|
+
sage: f = R(2 * x)
|
|
367
|
+
sage: f.gcd(f)
|
|
368
|
+
Traceback (most recent call last):
|
|
369
|
+
...
|
|
370
|
+
ValueError: leading coefficient must be invertible
|
|
371
|
+
|
|
372
|
+
::
|
|
373
|
+
|
|
374
|
+
sage: f = x^2 + 3 * x + 1
|
|
375
|
+
sage: g = x^2 + x + 1
|
|
376
|
+
sage: f.gcd(g)
|
|
377
|
+
Traceback (most recent call last):
|
|
378
|
+
...
|
|
379
|
+
RuntimeError: FLINT gcd calculation failed
|
|
380
|
+
"""
|
|
381
|
+
if celement_is_zero(&self.x, (<Polynomial_template>self)._cparent):
|
|
382
|
+
return other
|
|
383
|
+
if celement_is_zero(&other.x, (<Polynomial_template>self)._cparent):
|
|
384
|
+
return self
|
|
385
|
+
if celement_equal(&self.x, &other.x, (<Polynomial_template>self)._cparent):
|
|
386
|
+
# note: gcd(g, g) "canonicalizes" the generator i.e. make polynomials monic
|
|
387
|
+
# c.f. ring/ring.pyx:445
|
|
388
|
+
return self.monic()
|
|
389
|
+
|
|
390
|
+
cdef type T = type(self)
|
|
391
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
392
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
393
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
394
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
395
|
+
celement_gcd(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>other).x, (<Polynomial_template>self)._cparent)
|
|
396
|
+
#assert(r._parent(pari(self).gcd(pari(other))) == r)
|
|
397
|
+
return r
|
|
398
|
+
|
|
399
|
+
@coerce_binop
|
|
400
|
+
def xgcd(self, Polynomial_template other):
|
|
401
|
+
"""
|
|
402
|
+
Compute extended gcd of ``self`` and ``other``.
|
|
403
|
+
|
|
404
|
+
EXAMPLES::
|
|
405
|
+
|
|
406
|
+
sage: P.<x> = GF(7)[]
|
|
407
|
+
sage: f = x*(x+1)
|
|
408
|
+
sage: f.xgcd(x+1)
|
|
409
|
+
(x + 1, 0, 1)
|
|
410
|
+
sage: f.xgcd(x^2)
|
|
411
|
+
(x, 1, 6)
|
|
412
|
+
"""
|
|
413
|
+
if(celement_is_zero(&self.x, (<Polynomial_template>self)._cparent)):
|
|
414
|
+
return other, self._parent(0), self._parent(1)
|
|
415
|
+
if(celement_is_zero(&other.x, (<Polynomial_template>self)._cparent)):
|
|
416
|
+
return self, self._parent(1), self._parent(0)
|
|
417
|
+
|
|
418
|
+
cdef type T = type(self)
|
|
419
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
420
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
421
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
422
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
423
|
+
|
|
424
|
+
cdef Polynomial_template s = <Polynomial_template>T.__new__(T)
|
|
425
|
+
celement_construct(&s.x, (<Polynomial_template>self)._cparent)
|
|
426
|
+
s._parent = (<Polynomial_template>self)._parent
|
|
427
|
+
s._cparent = (<Polynomial_template>self)._cparent
|
|
428
|
+
|
|
429
|
+
cdef Polynomial_template t = <Polynomial_template>T.__new__(T)
|
|
430
|
+
celement_construct(&t.x, (<Polynomial_template>self)._cparent)
|
|
431
|
+
t._parent = (<Polynomial_template>self)._parent
|
|
432
|
+
t._cparent = (<Polynomial_template>self)._cparent
|
|
433
|
+
|
|
434
|
+
celement_xgcd(&r.x, &s.x, &t.x, &(<Polynomial_template>self).x, &(<Polynomial_template>other).x, (<Polynomial_template>self)._cparent)
|
|
435
|
+
#rp, sp, tp = pari(self).xgcd(pari(other))
|
|
436
|
+
#assert(r._parent(rp) == r)
|
|
437
|
+
#assert(s._parent(sp) == s)
|
|
438
|
+
#assert(t._parent(tp) == t)
|
|
439
|
+
return r,s,t
|
|
440
|
+
|
|
441
|
+
cpdef _floordiv_(self, right):
|
|
442
|
+
"""
|
|
443
|
+
EXAMPLES::
|
|
444
|
+
|
|
445
|
+
sage: P.<x> = GF(2)[]
|
|
446
|
+
sage: x//(x + 1)
|
|
447
|
+
1
|
|
448
|
+
sage: (x + 1)//x
|
|
449
|
+
1
|
|
450
|
+
sage: F = GF(47)
|
|
451
|
+
sage: R.<x> = F[]
|
|
452
|
+
sage: x // 1
|
|
453
|
+
x
|
|
454
|
+
sage: x // F(1)
|
|
455
|
+
x
|
|
456
|
+
sage: 1 // x
|
|
457
|
+
0
|
|
458
|
+
sage: parent(x // 1)
|
|
459
|
+
Univariate Polynomial Ring in x over Finite Field of size 47
|
|
460
|
+
sage: parent(1 // x)
|
|
461
|
+
Univariate Polynomial Ring in x over Finite Field of size 47
|
|
462
|
+
"""
|
|
463
|
+
cdef Polynomial_template _right = <Polynomial_template>right
|
|
464
|
+
|
|
465
|
+
if celement_is_zero(&_right.x, (<Polynomial_template>self)._cparent):
|
|
466
|
+
raise ZeroDivisionError
|
|
467
|
+
cdef type T = type(self)
|
|
468
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
469
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
470
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
471
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
472
|
+
#assert(r._parent(pari(self) // pari(right)) == r)
|
|
473
|
+
celement_floordiv(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x, (<Polynomial_template>self)._cparent)
|
|
474
|
+
return r
|
|
475
|
+
|
|
476
|
+
cpdef _mod_(self, other):
|
|
477
|
+
"""
|
|
478
|
+
EXAMPLES::
|
|
479
|
+
|
|
480
|
+
sage: P.<x> = GF(2)[]
|
|
481
|
+
sage: (x^2 + 1) % x^2
|
|
482
|
+
1
|
|
483
|
+
|
|
484
|
+
TESTS:
|
|
485
|
+
|
|
486
|
+
We test that :issue:`10578` is fixed::
|
|
487
|
+
|
|
488
|
+
sage: P.<x> = GF(2)[]
|
|
489
|
+
sage: x % 1r
|
|
490
|
+
0
|
|
491
|
+
"""
|
|
492
|
+
cdef Polynomial_template _other = <Polynomial_template>other
|
|
493
|
+
|
|
494
|
+
if celement_is_zero(&_other.x, (<Polynomial_template>self)._cparent):
|
|
495
|
+
raise ZeroDivisionError
|
|
496
|
+
|
|
497
|
+
cdef type T = type(self)
|
|
498
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
499
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
500
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
501
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
502
|
+
celement_mod(&r.x, &(<Polynomial_template>self).x, &_other.x, (<Polynomial_template>self)._cparent)
|
|
503
|
+
#assert(r._parent(pari(self) % pari(other)) == r)
|
|
504
|
+
return r
|
|
505
|
+
|
|
506
|
+
@coerce_binop
|
|
507
|
+
def quo_rem(self, Polynomial_template right):
|
|
508
|
+
"""
|
|
509
|
+
EXAMPLES::
|
|
510
|
+
|
|
511
|
+
sage: P.<x> = GF(2)[]
|
|
512
|
+
sage: f = x^2 + x + 1
|
|
513
|
+
sage: f.quo_rem(x + 1)
|
|
514
|
+
(x, 1)
|
|
515
|
+
"""
|
|
516
|
+
if celement_is_zero(&right.x, (<Polynomial_template>self)._cparent):
|
|
517
|
+
raise ZeroDivisionError
|
|
518
|
+
|
|
519
|
+
cdef type T = type(self)
|
|
520
|
+
cdef Polynomial_template q = <Polynomial_template>T.__new__(T)
|
|
521
|
+
celement_construct(&q.x, (<Polynomial_template>self)._cparent)
|
|
522
|
+
q._parent = (<Polynomial_template>self)._parent
|
|
523
|
+
q._cparent = (<Polynomial_template>self)._cparent
|
|
524
|
+
|
|
525
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
526
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
527
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
528
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
529
|
+
|
|
530
|
+
celement_quorem(&q.x, &r.x, &(<Polynomial_template>self).x, &right.x, (<Polynomial_template>self)._cparent)
|
|
531
|
+
return q,r
|
|
532
|
+
|
|
533
|
+
def __bool__(self):
|
|
534
|
+
"""
|
|
535
|
+
EXAMPLES::
|
|
536
|
+
|
|
537
|
+
sage: P.<x> = GF(2)[]
|
|
538
|
+
sage: bool(x), x.is_zero()
|
|
539
|
+
(True, False)
|
|
540
|
+
sage: bool(P(0)), P(0).is_zero()
|
|
541
|
+
(False, True)
|
|
542
|
+
"""
|
|
543
|
+
return not celement_is_zero(&self.x, (<Polynomial_template>self)._cparent)
|
|
544
|
+
|
|
545
|
+
cpdef _richcmp_(self, other, int op):
|
|
546
|
+
"""
|
|
547
|
+
EXAMPLES::
|
|
548
|
+
|
|
549
|
+
sage: P.<x> = GF(2)[]
|
|
550
|
+
sage: x != 1
|
|
551
|
+
True
|
|
552
|
+
sage: x < 1
|
|
553
|
+
False
|
|
554
|
+
sage: x > 1
|
|
555
|
+
True
|
|
556
|
+
"""
|
|
557
|
+
cdef int c
|
|
558
|
+
c = celement_cmp(&self.x, &(<Polynomial_template>other).x, self._cparent)
|
|
559
|
+
return rich_to_bool(op, c)
|
|
560
|
+
|
|
561
|
+
def __hash__(self):
|
|
562
|
+
"""
|
|
563
|
+
EXAMPLES::
|
|
564
|
+
|
|
565
|
+
sage: P.<x> = GF(2)[]
|
|
566
|
+
sage: {x:1}
|
|
567
|
+
{x: 1}
|
|
568
|
+
"""
|
|
569
|
+
cdef long result = 0 # store it in a c-int and just let the overflowing additions wrap
|
|
570
|
+
cdef long result_mon
|
|
571
|
+
cdef long c_hash
|
|
572
|
+
cdef long var_name_hash
|
|
573
|
+
cdef int i
|
|
574
|
+
for i from 0<= i <= self.degree():
|
|
575
|
+
if i == 1:
|
|
576
|
+
# we delay the hashing until now to not waste it one a constant poly
|
|
577
|
+
var_name_hash = hash(self.variable_name())
|
|
578
|
+
# I'm assuming (incorrectly) that hashes of zero indicate that the element is 0.
|
|
579
|
+
# This assumption is not true, but I think it is true enough for the purposes and it
|
|
580
|
+
# it allows us to write fast code that omits terms with 0 coefficients. This is
|
|
581
|
+
# important if we want to maintain the '==' relationship with sparse polys.
|
|
582
|
+
c_hash = hash(self[i])
|
|
583
|
+
if c_hash != 0:
|
|
584
|
+
if i == 0:
|
|
585
|
+
result += c_hash
|
|
586
|
+
else:
|
|
587
|
+
# Hash (self[i], generator, i) as a tuple according to the algorithm.
|
|
588
|
+
result_mon = c_hash
|
|
589
|
+
result_mon = (1000003 * result_mon) ^ var_name_hash
|
|
590
|
+
result_mon = (1000003 * result_mon) ^ i
|
|
591
|
+
result += result_mon
|
|
592
|
+
if result == -1:
|
|
593
|
+
return -2
|
|
594
|
+
return result
|
|
595
|
+
|
|
596
|
+
def __pow__(self, ee, modulus):
|
|
597
|
+
"""
|
|
598
|
+
EXAMPLES::
|
|
599
|
+
|
|
600
|
+
sage: P.<x> = GF(2)[]
|
|
601
|
+
sage: x^1000
|
|
602
|
+
x^1000
|
|
603
|
+
sage: (x+1)^2
|
|
604
|
+
x^2 + 1
|
|
605
|
+
sage: (x+1)^(-2)
|
|
606
|
+
1/(x^2 + 1)
|
|
607
|
+
sage: f = x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x
|
|
608
|
+
sage: h = x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1
|
|
609
|
+
sage: (f^2) % h
|
|
610
|
+
x^9 + x^8 + x^7 + x^5 + x^3
|
|
611
|
+
sage: pow(f, 2, h)
|
|
612
|
+
x^9 + x^8 + x^7 + x^5 + x^3
|
|
613
|
+
|
|
614
|
+
TESTS:
|
|
615
|
+
|
|
616
|
+
Ensure modulo `0` and modulo `1` does not crash (:issue:`37169`)::
|
|
617
|
+
|
|
618
|
+
sage: R.<x> = GF(2)[]
|
|
619
|
+
sage: pow(x + 1, 2, R.zero())
|
|
620
|
+
Traceback (most recent call last):
|
|
621
|
+
...
|
|
622
|
+
ZeroDivisionError: modulus must be nonzero
|
|
623
|
+
sage: pow(x + 1, 2, R.one())
|
|
624
|
+
0
|
|
625
|
+
|
|
626
|
+
::
|
|
627
|
+
|
|
628
|
+
sage: R.<x> = GF(2^8)[]
|
|
629
|
+
sage: pow(x + 1, 2, R.zero())
|
|
630
|
+
Traceback (most recent call last):
|
|
631
|
+
...
|
|
632
|
+
ZeroDivisionError: modulus must be nonzero
|
|
633
|
+
sage: pow(x + 1, 2, R.one())
|
|
634
|
+
0
|
|
635
|
+
"""
|
|
636
|
+
if not isinstance(self, Polynomial_template):
|
|
637
|
+
raise NotImplementedError("%s^%s not defined." % (ee, self))
|
|
638
|
+
cdef bint recip = 0, do_sig
|
|
639
|
+
|
|
640
|
+
cdef long e
|
|
641
|
+
try:
|
|
642
|
+
e = ee
|
|
643
|
+
except OverflowError:
|
|
644
|
+
return Polynomial.__pow__(self, ee, modulus)
|
|
645
|
+
if e != ee:
|
|
646
|
+
raise TypeError("Only integral powers defined.")
|
|
647
|
+
elif e < 0:
|
|
648
|
+
recip = 1 # delay because powering frac field elements is slow
|
|
649
|
+
e = -e
|
|
650
|
+
|
|
651
|
+
if not self:
|
|
652
|
+
return (<Polynomial_template>self)._parent(int(not e))
|
|
653
|
+
|
|
654
|
+
cdef type T = type(self)
|
|
655
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
656
|
+
|
|
657
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
658
|
+
parent = (<Polynomial_template>self)._parent
|
|
659
|
+
r._parent = parent
|
|
660
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
661
|
+
|
|
662
|
+
if modulus is None:
|
|
663
|
+
celement_pow(&r.x, &(<Polynomial_template>self).x, e, NULL, (<Polynomial_template>self)._cparent)
|
|
664
|
+
else:
|
|
665
|
+
if parent is not (<Polynomial_template>modulus)._parent and parent != (<Polynomial_template>modulus)._parent:
|
|
666
|
+
modulus = parent.coerce(modulus)
|
|
667
|
+
if celement_is_zero(&(<Polynomial_template>modulus).x, (<Polynomial_template>self)._cparent):
|
|
668
|
+
raise ZeroDivisionError("modulus must be nonzero")
|
|
669
|
+
if celement_is_one(&(<Polynomial_template>modulus).x, (<Polynomial_template>self)._cparent):
|
|
670
|
+
return parent.zero()
|
|
671
|
+
celement_pow(&r.x, &(<Polynomial_template>self).x, e, &(<Polynomial_template>modulus).x, (<Polynomial_template>self)._cparent)
|
|
672
|
+
|
|
673
|
+
#assert(r._parent(pari(self)**ee) == r)
|
|
674
|
+
if recip:
|
|
675
|
+
return ~r
|
|
676
|
+
else:
|
|
677
|
+
return r
|
|
678
|
+
|
|
679
|
+
def __copy__(self):
|
|
680
|
+
"""
|
|
681
|
+
EXAMPLES::
|
|
682
|
+
|
|
683
|
+
sage: P.<x> = GF(2)[]
|
|
684
|
+
sage: copy(x) is x
|
|
685
|
+
False
|
|
686
|
+
sage: copy(x) == x
|
|
687
|
+
True
|
|
688
|
+
"""
|
|
689
|
+
cdef type T = type(self)
|
|
690
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
691
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
692
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
693
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
694
|
+
celement_set(&r.x, &self.x, (<Polynomial_template>self)._cparent)
|
|
695
|
+
return r
|
|
696
|
+
|
|
697
|
+
def is_gen(self):
|
|
698
|
+
"""
|
|
699
|
+
EXAMPLES::
|
|
700
|
+
|
|
701
|
+
sage: P.<x> = GF(2)[]
|
|
702
|
+
sage: x.is_gen()
|
|
703
|
+
True
|
|
704
|
+
sage: (x+1).is_gen()
|
|
705
|
+
False
|
|
706
|
+
"""
|
|
707
|
+
cdef celement *gen = celement_new((<Polynomial_template>self)._cparent)
|
|
708
|
+
celement_gen(gen, 0, (<Polynomial_template>self)._cparent)
|
|
709
|
+
cdef bint r = celement_equal(&self.x, gen, (<Polynomial_template>self)._cparent)
|
|
710
|
+
celement_delete(gen, (<Polynomial_template>self)._cparent)
|
|
711
|
+
return r
|
|
712
|
+
|
|
713
|
+
def shift(self, int n):
|
|
714
|
+
"""
|
|
715
|
+
EXAMPLES::
|
|
716
|
+
|
|
717
|
+
sage: P.<x> = GF(2)[]
|
|
718
|
+
sage: f = x^3 + x^2 + 1
|
|
719
|
+
sage: f.shift(1)
|
|
720
|
+
x^4 + x^3 + x
|
|
721
|
+
sage: f.shift(-1)
|
|
722
|
+
x^2 + x
|
|
723
|
+
"""
|
|
724
|
+
return element_shift(self, n)
|
|
725
|
+
|
|
726
|
+
def __lshift__(self, int n):
|
|
727
|
+
"""
|
|
728
|
+
EXAMPLES::
|
|
729
|
+
|
|
730
|
+
sage: P.<x> = GF(2)[]
|
|
731
|
+
sage: f = x^3 + x^2 + 1
|
|
732
|
+
sage: f << 1
|
|
733
|
+
x^4 + x^3 + x
|
|
734
|
+
sage: f << -1
|
|
735
|
+
x^2 + x
|
|
736
|
+
"""
|
|
737
|
+
return element_shift(self, n)
|
|
738
|
+
|
|
739
|
+
def __rshift__(self, int n):
|
|
740
|
+
"""
|
|
741
|
+
EXAMPLES::
|
|
742
|
+
|
|
743
|
+
sage: P.<x> = GF(2)[]
|
|
744
|
+
sage: x>>1
|
|
745
|
+
1
|
|
746
|
+
sage: (x^2 + x)>>1
|
|
747
|
+
x + 1
|
|
748
|
+
sage: (x^2 + x) >> -1
|
|
749
|
+
x^3 + x^2
|
|
750
|
+
"""
|
|
751
|
+
return element_shift(self, -n)
|
|
752
|
+
|
|
753
|
+
cpdef bint is_zero(self) except -1:
|
|
754
|
+
"""
|
|
755
|
+
EXAMPLES::
|
|
756
|
+
|
|
757
|
+
sage: P.<x> = GF(2)[]
|
|
758
|
+
sage: x.is_zero()
|
|
759
|
+
False
|
|
760
|
+
"""
|
|
761
|
+
return celement_is_zero(&self.x, (<Polynomial_template>self)._cparent)
|
|
762
|
+
|
|
763
|
+
cpdef bint is_one(self) except -1:
|
|
764
|
+
"""
|
|
765
|
+
EXAMPLES::
|
|
766
|
+
|
|
767
|
+
sage: P.<x> = GF(2)[]
|
|
768
|
+
sage: P(1).is_one()
|
|
769
|
+
True
|
|
770
|
+
"""
|
|
771
|
+
return celement_is_one(&self.x, (<Polynomial_template>self)._cparent)
|
|
772
|
+
|
|
773
|
+
def degree(self):
|
|
774
|
+
"""
|
|
775
|
+
EXAMPLES::
|
|
776
|
+
|
|
777
|
+
sage: P.<x> = GF(2)[]
|
|
778
|
+
sage: x.degree()
|
|
779
|
+
1
|
|
780
|
+
sage: P(1).degree()
|
|
781
|
+
0
|
|
782
|
+
sage: P(0).degree()
|
|
783
|
+
-1
|
|
784
|
+
"""
|
|
785
|
+
return Integer(celement_len(&self.x, (<Polynomial_template>self)._cparent)-1)
|
|
786
|
+
|
|
787
|
+
cpdef Polynomial truncate(self, long n):
|
|
788
|
+
r"""
|
|
789
|
+
Return this polynomial mod `x^n`.
|
|
790
|
+
|
|
791
|
+
EXAMPLES::
|
|
792
|
+
|
|
793
|
+
sage: R.<x> =GF(2)[]
|
|
794
|
+
sage: f = sum(x^n for n in range(10)); f
|
|
795
|
+
x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1
|
|
796
|
+
sage: f.truncate(6)
|
|
797
|
+
x^5 + x^4 + x^3 + x^2 + x + 1
|
|
798
|
+
|
|
799
|
+
If the precision is higher than the degree of the polynomial then
|
|
800
|
+
the polynomial itself is returned::
|
|
801
|
+
|
|
802
|
+
sage: f.truncate(10) is f
|
|
803
|
+
True
|
|
804
|
+
|
|
805
|
+
If the precision is negative, the zero polynomial is returned::
|
|
806
|
+
|
|
807
|
+
sage: f.truncate(-1)
|
|
808
|
+
0
|
|
809
|
+
"""
|
|
810
|
+
if n >= celement_len(&self.x, (<Polynomial_template>self)._cparent):
|
|
811
|
+
return self
|
|
812
|
+
|
|
813
|
+
cdef type T = type(self)
|
|
814
|
+
cdef Polynomial_template r = <Polynomial_template>T.__new__(T)
|
|
815
|
+
celement_construct(&r.x, (<Polynomial_template>self)._cparent)
|
|
816
|
+
r._parent = (<Polynomial_template>self)._parent
|
|
817
|
+
r._cparent = (<Polynomial_template>self)._cparent
|
|
818
|
+
if n <= 0:
|
|
819
|
+
return r
|
|
820
|
+
celement_truncate(&r.x, &self.x, n, (<Polynomial_template>self)._cparent)
|
|
821
|
+
return r
|
|
822
|
+
|
|
823
|
+
def _singular_(self, singular=None):
|
|
824
|
+
r"""
|
|
825
|
+
Return Singular representation of this polynomial.
|
|
826
|
+
|
|
827
|
+
INPUT:
|
|
828
|
+
|
|
829
|
+
- ``singular`` -- Singular interpreter (default: default interpreter)
|
|
830
|
+
|
|
831
|
+
EXAMPLES::
|
|
832
|
+
|
|
833
|
+
sage: P.<x> = PolynomialRing(GF(7))
|
|
834
|
+
sage: f = 3*x^2 + 2*x + 5
|
|
835
|
+
sage: singular(f) # needs sage.libs.singular
|
|
836
|
+
3*x^2+2*x-2
|
|
837
|
+
"""
|
|
838
|
+
if singular is None:
|
|
839
|
+
from sage.interfaces.singular import singular
|
|
840
|
+
|
|
841
|
+
self.parent()._singular_(singular).set_ring() # this is expensive
|
|
842
|
+
return singular(self._singular_init_())
|