passagemath-ntl 10.6.33__cp313-cp313-musllinux_1_2_x86_64.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.

Files changed (163) hide show
  1. passagemath_ntl-10.6.33.dist-info/METADATA +122 -0
  2. passagemath_ntl-10.6.33.dist-info/RECORD +163 -0
  3. passagemath_ntl-10.6.33.dist-info/WHEEL +5 -0
  4. passagemath_ntl-10.6.33.dist-info/top_level.txt +2 -0
  5. passagemath_ntl.libs/libgcc_s-0cd532bd.so.1 +0 -0
  6. passagemath_ntl.libs/libgf2x-9e30c3e3.so.3.0.0 +0 -0
  7. passagemath_ntl.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
  8. passagemath_ntl.libs/libmpfi-2153e8c2.so.0.0.0 +0 -0
  9. passagemath_ntl.libs/libmpfr-aaecbfc0.so.6.2.1 +0 -0
  10. passagemath_ntl.libs/libntl-26885ca2.so.44.0.1 +0 -0
  11. passagemath_ntl.libs/libstdc++-5d72f927.so.6.0.33 +0 -0
  12. sage/all__sagemath_ntl.py +7 -0
  13. sage/libs/all__sagemath_ntl.py +3 -0
  14. sage/libs/mpfi/__init__.pxd +287 -0
  15. sage/libs/mpfi/types.pxd +10 -0
  16. sage/libs/ntl/GF2.pxd +18 -0
  17. sage/libs/ntl/GF2E.pxd +28 -0
  18. sage/libs/ntl/GF2EX.pxd +12 -0
  19. sage/libs/ntl/GF2X.pxd +81 -0
  20. sage/libs/ntl/ZZ.pxd +93 -0
  21. sage/libs/ntl/ZZX.pxd +85 -0
  22. sage/libs/ntl/ZZ_p.pxd +28 -0
  23. sage/libs/ntl/ZZ_pE.pxd +37 -0
  24. sage/libs/ntl/ZZ_pEX.pxd +106 -0
  25. sage/libs/ntl/ZZ_pX.pxd +122 -0
  26. sage/libs/ntl/__init__.py +4 -0
  27. sage/libs/ntl/all.py +72 -0
  28. sage/libs/ntl/conversion.pxd +106 -0
  29. sage/libs/ntl/convert.cpython-313-x86_64-linux-musl.so +0 -0
  30. sage/libs/ntl/convert.pxd +7 -0
  31. sage/libs/ntl/convert.pyx +38 -0
  32. sage/libs/ntl/decl.pxi +18 -0
  33. sage/libs/ntl/error.cpython-313-x86_64-linux-musl.so +0 -0
  34. sage/libs/ntl/error.pyx +63 -0
  35. sage/libs/ntl/lzz_p.pxd +20 -0
  36. sage/libs/ntl/lzz_pX.pxd +59 -0
  37. sage/libs/ntl/mat_GF2.pxd +30 -0
  38. sage/libs/ntl/mat_GF2E.pxd +30 -0
  39. sage/libs/ntl/mat_ZZ.pxd +59 -0
  40. sage/libs/ntl/misc.pxi +33 -0
  41. sage/libs/ntl/ntl_GF2.cpython-313-x86_64-linux-musl.so +0 -0
  42. sage/libs/ntl/ntl_GF2.pxd +5 -0
  43. sage/libs/ntl/ntl_GF2.pyx +281 -0
  44. sage/libs/ntl/ntl_GF2E.cpython-313-x86_64-linux-musl.so +0 -0
  45. sage/libs/ntl/ntl_GF2E.pxd +8 -0
  46. sage/libs/ntl/ntl_GF2E.pyx +488 -0
  47. sage/libs/ntl/ntl_GF2EContext.cpython-313-x86_64-linux-musl.so +0 -0
  48. sage/libs/ntl/ntl_GF2EContext.pxd +9 -0
  49. sage/libs/ntl/ntl_GF2EContext.pyx +134 -0
  50. sage/libs/ntl/ntl_GF2EX.cpython-313-x86_64-linux-musl.so +0 -0
  51. sage/libs/ntl/ntl_GF2EX.pxd +10 -0
  52. sage/libs/ntl/ntl_GF2EX.pyx +251 -0
  53. sage/libs/ntl/ntl_GF2X.cpython-313-x86_64-linux-musl.so +0 -0
  54. sage/libs/ntl/ntl_GF2X.pxd +5 -0
  55. sage/libs/ntl/ntl_GF2X.pyx +771 -0
  56. sage/libs/ntl/ntl_GF2X_linkage.pxi +404 -0
  57. sage/libs/ntl/ntl_ZZ.cpython-313-x86_64-linux-musl.so +0 -0
  58. sage/libs/ntl/ntl_ZZ.pxd +7 -0
  59. sage/libs/ntl/ntl_ZZ.pyx +541 -0
  60. sage/libs/ntl/ntl_ZZX.cpython-313-x86_64-linux-musl.so +0 -0
  61. sage/libs/ntl/ntl_ZZX.pxd +7 -0
  62. sage/libs/ntl/ntl_ZZX.pyx +1206 -0
  63. sage/libs/ntl/ntl_ZZ_p.cpython-313-x86_64-linux-musl.so +0 -0
  64. sage/libs/ntl/ntl_ZZ_p.pxd +10 -0
  65. sage/libs/ntl/ntl_ZZ_p.pyx +509 -0
  66. sage/libs/ntl/ntl_ZZ_pContext.cpython-313-x86_64-linux-musl.so +0 -0
  67. sage/libs/ntl/ntl_ZZ_pContext.pxd +22 -0
  68. sage/libs/ntl/ntl_ZZ_pContext.pyx +201 -0
  69. sage/libs/ntl/ntl_ZZ_pE.cpython-313-x86_64-linux-musl.so +0 -0
  70. sage/libs/ntl/ntl_ZZ_pE.pxd +11 -0
  71. sage/libs/ntl/ntl_ZZ_pE.pyx +349 -0
  72. sage/libs/ntl/ntl_ZZ_pEContext.cpython-313-x86_64-linux-musl.so +0 -0
  73. sage/libs/ntl/ntl_ZZ_pEContext.pxd +23 -0
  74. sage/libs/ntl/ntl_ZZ_pEContext.pyx +226 -0
  75. sage/libs/ntl/ntl_ZZ_pEX.cpython-313-x86_64-linux-musl.so +0 -0
  76. sage/libs/ntl/ntl_ZZ_pEX.pxd +10 -0
  77. sage/libs/ntl/ntl_ZZ_pEX.pyx +1255 -0
  78. sage/libs/ntl/ntl_ZZ_pEX_linkage.pxi +420 -0
  79. sage/libs/ntl/ntl_ZZ_pX.cpython-313-x86_64-linux-musl.so +0 -0
  80. sage/libs/ntl/ntl_ZZ_pX.pxd +17 -0
  81. sage/libs/ntl/ntl_ZZ_pX.pyx +1532 -0
  82. sage/libs/ntl/ntl_lzz_p.cpython-313-x86_64-linux-musl.so +0 -0
  83. sage/libs/ntl/ntl_lzz_p.pxd +8 -0
  84. sage/libs/ntl/ntl_lzz_p.pyx +440 -0
  85. sage/libs/ntl/ntl_lzz_pContext.cpython-313-x86_64-linux-musl.so +0 -0
  86. sage/libs/ntl/ntl_lzz_pContext.pxd +7 -0
  87. sage/libs/ntl/ntl_lzz_pContext.pyx +137 -0
  88. sage/libs/ntl/ntl_lzz_pX.cpython-313-x86_64-linux-musl.so +0 -0
  89. sage/libs/ntl/ntl_lzz_pX.pxd +10 -0
  90. sage/libs/ntl/ntl_lzz_pX.pyx +902 -0
  91. sage/libs/ntl/ntl_mat_GF2.cpython-313-x86_64-linux-musl.so +0 -0
  92. sage/libs/ntl/ntl_mat_GF2.pxd +8 -0
  93. sage/libs/ntl/ntl_mat_GF2.pyx +612 -0
  94. sage/libs/ntl/ntl_mat_GF2E.cpython-313-x86_64-linux-musl.so +0 -0
  95. sage/libs/ntl/ntl_mat_GF2E.pxd +10 -0
  96. sage/libs/ntl/ntl_mat_GF2E.pyx +752 -0
  97. sage/libs/ntl/ntl_mat_ZZ.cpython-313-x86_64-linux-musl.so +0 -0
  98. sage/libs/ntl/ntl_mat_ZZ.pxd +6 -0
  99. sage/libs/ntl/ntl_mat_ZZ.pyx +1523 -0
  100. sage/libs/ntl/ntl_tools.pxd +3 -0
  101. sage/libs/ntl/ntlwrap.h +53 -0
  102. sage/libs/ntl/ntlwrap_impl.h +743 -0
  103. sage/libs/ntl/types.pxd +157 -0
  104. sage/libs/ntl/vec_GF2.pxd +26 -0
  105. sage/libs/ntl/vec_GF2E.pxd +2 -0
  106. sage/matrix/all__sagemath_ntl.py +1 -0
  107. sage/matrix/matrix_modn_dense_double.pxd +10 -0
  108. sage/matrix/matrix_modn_dense_float.pxd +9 -0
  109. sage/matrix/matrix_modn_dense_template.pxi +3257 -0
  110. sage/matrix/matrix_modn_dense_template_header.pxi +15 -0
  111. sage/matrix/matrix_modn_sparse.pxd +8 -0
  112. sage/misc/all__sagemath_ntl.py +1 -0
  113. sage/rings/all__sagemath_ntl.py +7 -0
  114. sage/rings/bernmm.cpython-313-x86_64-linux-musl.so +0 -0
  115. sage/rings/bernmm.pyx +161 -0
  116. sage/rings/bernoulli_mod_p.cpython-313-x86_64-linux-musl.so +0 -0
  117. sage/rings/bernoulli_mod_p.pyx +313 -0
  118. sage/rings/finite_rings/all__sagemath_ntl.py +1 -0
  119. sage/rings/finite_rings/finite_field_ntl_gf2e.py +305 -0
  120. sage/rings/finite_rings/residue_field_ntl_gf2e.cpython-313-x86_64-linux-musl.so +0 -0
  121. sage/rings/finite_rings/residue_field_ntl_gf2e.pyx +140 -0
  122. sage/rings/padics/all__sagemath_ntl.py +5 -0
  123. sage/rings/padics/padic_ZZ_pX_CA_element.cpython-313-x86_64-linux-musl.so +0 -0
  124. sage/rings/padics/padic_ZZ_pX_CA_element.pxd +25 -0
  125. sage/rings/padics/padic_ZZ_pX_CA_element.pyx +2368 -0
  126. sage/rings/padics/padic_ZZ_pX_CR_element.cpython-313-x86_64-linux-musl.so +0 -0
  127. sage/rings/padics/padic_ZZ_pX_CR_element.pxd +33 -0
  128. sage/rings/padics/padic_ZZ_pX_CR_element.pyx +3277 -0
  129. sage/rings/padics/padic_ZZ_pX_FM_element.cpython-313-x86_64-linux-musl.so +0 -0
  130. sage/rings/padics/padic_ZZ_pX_FM_element.pxd +12 -0
  131. sage/rings/padics/padic_ZZ_pX_FM_element.pyx +1739 -0
  132. sage/rings/padics/padic_ZZ_pX_element.cpython-313-x86_64-linux-musl.so +0 -0
  133. sage/rings/padics/padic_ZZ_pX_element.pxd +6 -0
  134. sage/rings/padics/padic_ZZ_pX_element.pyx +919 -0
  135. sage/rings/padics/padic_ext_element.cpython-313-x86_64-linux-musl.so +0 -0
  136. sage/rings/padics/padic_ext_element.pxd +38 -0
  137. sage/rings/padics/padic_ext_element.pyx +512 -0
  138. sage/rings/padics/pow_computer_ext.cpython-313-x86_64-linux-musl.so +0 -0
  139. sage/rings/padics/pow_computer_ext.pxd +107 -0
  140. sage/rings/padics/pow_computer_ext.pyx +2401 -0
  141. sage/rings/polynomial/all__sagemath_ntl.py +1 -0
  142. sage/rings/polynomial/evaluation_ntl.cpython-313-x86_64-linux-musl.so +0 -0
  143. sage/rings/polynomial/evaluation_ntl.pxd +7 -0
  144. sage/rings/polynomial/evaluation_ntl.pyx +70 -0
  145. sage/rings/polynomial/polynomial_gf2x.cpython-313-x86_64-linux-musl.so +0 -0
  146. sage/rings/polynomial/polynomial_gf2x.pxd +10 -0
  147. sage/rings/polynomial/polynomial_gf2x.pyx +364 -0
  148. sage/rings/polynomial/polynomial_integer_dense_ntl.cpython-313-x86_64-linux-musl.so +0 -0
  149. sage/rings/polynomial/polynomial_integer_dense_ntl.pxd +8 -0
  150. sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +1128 -0
  151. sage/rings/polynomial/polynomial_modn_dense_ntl.cpython-313-x86_64-linux-musl.so +0 -0
  152. sage/rings/polynomial/polynomial_modn_dense_ntl.pxd +36 -0
  153. sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +2049 -0
  154. sage/rings/polynomial/polynomial_template.pxi +842 -0
  155. sage/rings/polynomial/polynomial_template_header.pxi +11 -0
  156. sage/rings/polynomial/polynomial_zz_pex.cpython-313-x86_64-linux-musl.so +0 -0
  157. sage/rings/polynomial/polynomial_zz_pex.pxd +12 -0
  158. sage/rings/polynomial/polynomial_zz_pex.pyx +778 -0
  159. sage/rings/real_mpfi.pxd +50 -0
  160. sage/schemes/all__sagemath_ntl.py +1 -0
  161. sage/schemes/hyperelliptic_curves/all__sagemath_ntl.py +1 -0
  162. sage/schemes/hyperelliptic_curves/hypellfrob.cpython-313-x86_64-linux-musl.so +0 -0
  163. sage/schemes/hyperelliptic_curves/hypellfrob.pyx +252 -0
@@ -0,0 +1 @@
1
+ # sage_setup: distribution = sagemath-ntl
@@ -0,0 +1,7 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ from sage.libs.ntl.types cimport ZZX_c
3
+ from sage.libs.mpfr.types cimport mpfr_t
4
+ from sage.libs.mpfi.types cimport mpfi_t
5
+
6
+ cdef ZZX_evaluation_mpfr(mpfr_t res, ZZX_c poly, const mpfr_t a)
7
+ cdef ZZX_evaluation_mpfi(mpfi_t res, ZZX_c poly, const mpfi_t a)
@@ -0,0 +1,70 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ # distutils: libraries = NTL_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
+ r"""
9
+ Fast evaluation of polynomials (Horner's rule)
10
+
11
+ This file provides fast evaluation of integer polynomials with a real value. We
12
+ consider NTL polynomials and values mpfr_t and mpfi_t.
13
+
14
+ The code in this file is mostly Sage agnostic and only does library calls.
15
+
16
+ For appropriate testing see
17
+ :mod:`~sage.rings.polynomial.polynomial_integer_dense_ntl`.
18
+
19
+ .. TODO::
20
+
21
+ Integrate these functions into
22
+ :mod:`~sage.rings.polynomial.polynomial_compiled`
23
+ """
24
+ #*****************************************************************************
25
+ # Copyright (C) 2016 Vincent Delecroix <20100.delecroix@gmail.com>
26
+ #
27
+ # This program is free software: you can redistribute it and/or modify
28
+ # it under the terms of the GNU General Public License as published by
29
+ # the Free Software Foundation, either version 2 of the License, or
30
+ # (at your option) any later version.
31
+ # http://www.gnu.org/licenses/
32
+ #*****************************************************************************
33
+
34
+ from sage.libs.mpfr cimport *
35
+ from sage.libs.mpfi cimport *
36
+ from sage.libs.gmp.mpz cimport *
37
+ from sage.libs.gmp.mpq cimport *
38
+ from sage.libs.ntl.ZZ cimport *
39
+ from sage.libs.ntl.ZZX cimport *
40
+
41
+
42
+ cdef ZZX_evaluation_mpfr(mpfr_t res, ZZX_c poly, const mpfr_t a):
43
+ cdef mpz_t c
44
+ cdef long i
45
+
46
+ mpfr_set_ui(res, 0, MPFR_RNDN)
47
+ mpz_init(c)
48
+
49
+ for i in range(ZZX_deg(poly), -1, -1):
50
+ mpfr_mul(res, res, a, MPFR_RNDN)
51
+ if not ZZ_IsZero(ZZX_coeff(poly, i)):
52
+ ZZX_getitem_as_mpz(c, &poly, i)
53
+ mpfr_add_z(res, res, c, MPFR_RNDN)
54
+
55
+ mpz_clear(c)
56
+
57
+ cdef ZZX_evaluation_mpfi(mpfi_t res, ZZX_c poly, const mpfi_t a):
58
+ cdef mpz_t c
59
+ cdef long i
60
+
61
+ mpfi_set_ui(res, 0)
62
+ mpz_init(c)
63
+
64
+ for i in range(ZZX_deg(poly), -1, -1):
65
+ mpfi_mul(res, res, a)
66
+ if not ZZ_IsZero(ZZX_coeff(poly, i)):
67
+ ZZX_getitem_as_mpz(c, &poly, i)
68
+ mpfi_add_z(res, res, c)
69
+
70
+ mpz_clear(c)
@@ -0,0 +1,10 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ from sage.libs.ntl.GF2X cimport GF2X_c
3
+
4
+ ctypedef GF2X_c celement
5
+ ctypedef long cparent
6
+
7
+ include "polynomial_template_header.pxi"
8
+
9
+ cdef class Polynomial_GF2X(Polynomial_template):
10
+ pass
@@ -0,0 +1,364 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ # distutils: libraries = gmp NTL_LIBRARIES
3
+ # distutils: library_dirs = NTL_LIBDIR
4
+ # distutils: extra_link_args = NTL_LIBEXTRA
5
+ # distutils: extra_compile_args = NTL_CFLAGS M4RI_CFLAGS
6
+ # distutils: include_dirs = NTL_INCDIR M4RI_INCDIR
7
+ # distutils: language = c++
8
+ # sage.doctest: needs sage.libs.linbox
9
+ """
10
+ Univariate Polynomials over GF(2) via NTL's GF2X
11
+
12
+ AUTHOR:
13
+ - Martin Albrecht (2008-10) initial implementation
14
+ """
15
+
16
+
17
+ # We need to define this stuff before including the templating stuff
18
+ # to make sure the function get_cparent is found since it is used in
19
+ # 'polynomial_template.pxi'.
20
+
21
+ cdef inline cparent get_cparent(parent) noexcept:
22
+ return 0
23
+
24
+ # first we include the definitions
25
+ include "sage/libs/ntl/decl.pxi"
26
+ include "sage/libs/ntl/ntl_GF2X_linkage.pxi"
27
+
28
+ # and then the interface
29
+ include "polynomial_template.pxi"
30
+
31
+ from sage.libs.m4ri cimport mzd_write_bit, mzd_read_bit
32
+ from sage.matrix.matrix_mod2_dense cimport Matrix_mod2_dense
33
+
34
+ from sage.misc.cachefunc import cached_method
35
+
36
+ cdef class Polynomial_GF2X(Polynomial_template):
37
+ r"""
38
+ Univariate Polynomials over `\GF{2}` via NTL's GF2X.
39
+
40
+ EXAMPLES::
41
+
42
+ sage: P.<x> = GF(2)[]
43
+ sage: x^3 + x^2 + 1
44
+ x^3 + x^2 + 1
45
+ """
46
+ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False):
47
+ r"""
48
+ Create a new univariate polynomials over `\GF{2}`.
49
+
50
+ EXAMPLES::
51
+
52
+ sage: P.<x> = GF(2)[]
53
+ sage: x^3 + x^2 + 1
54
+ x^3 + x^2 + 1
55
+
56
+ We check that the bug noted at :issue:`12724` is fixed::
57
+
58
+ sage: R.<x> = Zmod(2)[]
59
+ sage: R([2^80])
60
+ 0
61
+ """
62
+ try:
63
+ if (isinstance(x, int)
64
+ or isinstance(x, Integer)):
65
+ x = int(x % 2)
66
+ elif (x.parent() is parent.base_ring()
67
+ or x.parent() == parent.base_ring()):
68
+ x = int(x)
69
+ except AttributeError:
70
+ pass
71
+ Polynomial_template.__init__(self, parent, x, check, is_gen, construct)
72
+
73
+ cdef get_unsafe(self, Py_ssize_t i):
74
+ """
75
+ Return the `i`-th coefficient of ``self``.
76
+
77
+ EXAMPLES::
78
+
79
+ sage: P.<x> = GF(2)[]
80
+ sage: f = x^3 + x^2 + 1; f
81
+ x^3 + x^2 + 1
82
+ sage: f[0]
83
+ 1
84
+ sage: f[1]
85
+ 0
86
+ sage: f[:50] == f
87
+ True
88
+ sage: f[:3]
89
+ x^2 + 1
90
+ """
91
+ cdef long c = GF2_conv_to_long(GF2X_coeff(self.x, i))
92
+ return self._parent._base(c)
93
+
94
+ def __pari__(self, variable=None):
95
+ """
96
+ EXAMPLES::
97
+
98
+ sage: P.<x> = GF(2)[]
99
+ sage: f = x^3 + x^2 + 1
100
+ sage: pari(f)
101
+ Mod(1, 2)*x^3 + Mod(1, 2)*x^2 + Mod(1, 2)
102
+ """
103
+ from sage.libs.pari import pari
104
+ # TODO: put this in a superclass
105
+ parent = self._parent
106
+ if variable is None:
107
+ variable = parent.variable_name()
108
+ return pari(self.list()).Polrev(variable) * pari(1).Mod(2)
109
+
110
+ def modular_composition(Polynomial_GF2X self, Polynomial_GF2X g, Polynomial_GF2X h, algorithm=None):
111
+ r"""
112
+ Compute `f(g) \pmod h`.
113
+
114
+ Both implementations use Brent-Kung's Algorithm 2.1 (*Fast Algorithms
115
+ for Manipulation of Formal Power Series*, JACM 1978).
116
+
117
+ INPUT:
118
+
119
+ - ``g`` -- a polynomial
120
+ - ``h`` -- a polynomial
121
+ - ``algorithm`` -- either ``'native'`` or ``'ntl'`` (default: ``'native'``)
122
+
123
+ EXAMPLES::
124
+
125
+ sage: P.<x> = GF(2)[]
126
+ sage: r = 279
127
+ sage: f = x^r + x +1
128
+ sage: g = x^r
129
+ sage: g.modular_composition(g, f) == g(g) % f
130
+ True
131
+
132
+ sage: P.<x> = GF(2)[]
133
+ sage: f = x^29 + x^24 + x^22 + x^21 + x^20 + x^16 + x^15 + x^14 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^2
134
+ sage: g = x^31 + x^30 + x^28 + x^26 + x^24 + x^21 + x^19 + x^18 + x^11 + x^10 + x^9 + x^8 + x^5 + x^2 + 1
135
+ sage: h = x^30 + x^28 + x^26 + x^25 + x^24 + x^22 + x^21 + x^18 + x^17 + x^15 + x^13 + x^12 + x^11 + x^10 + x^9 + x^4
136
+ sage: f.modular_composition(g, h) == f(g) % h
137
+ True
138
+
139
+ AUTHORS:
140
+
141
+ - Paul Zimmermann (2008-10) initial implementation
142
+ - Martin Albrecht (2008-10) performance improvements
143
+ """
144
+ if g.parent() is not self.parent() or h.parent() is not self.parent():
145
+ raise TypeError("Parents of the first three parameters must match.")
146
+
147
+ from sage.misc.timing import cputime
148
+ from sage.misc.verbose import verbose
149
+ from sage.arith.misc import integer_ceil as ceil
150
+ from sage.matrix.constructor import Matrix
151
+ from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
152
+
153
+ cdef Polynomial_GF2X res
154
+ cdef GF2XModulus_c modulus
155
+ GF2XModulus_build(modulus, (<Polynomial_GF2X>h).x)
156
+
157
+ res = <Polynomial_GF2X>Polynomial_GF2X.__new__(Polynomial_GF2X)
158
+ res._parent = self._parent
159
+ res._cparent = self._cparent
160
+
161
+ if algorithm == "ntl":
162
+ t = cputime()
163
+ sig_on()
164
+ GF2X_CompMod(res.x, self.x, g.x, modulus)
165
+ sig_off()
166
+ verbose("NTL %5.3f s" % cputime(t), level=1)
167
+ return res
168
+
169
+ cdef Py_ssize_t i, j, k, l, n, maxlength
170
+ cdef Matrix_mod2_dense F, G, H
171
+
172
+ if g.degree() >= h.degree():
173
+ g = g % h
174
+
175
+ cdef GF2X_c _f = (<Polynomial_GF2X>self).x
176
+ cdef GF2X_c _g = (<Polynomial_GF2X>g).x
177
+ cdef GF2X_c gpow, g2, tt
178
+ GF2X_conv_long(gpow, 1)
179
+
180
+ maxlength = GF2X_NumBits(_f)
181
+
182
+ t = cputime()
183
+
184
+ n = h.degree()
185
+
186
+ k = ceil(Integer(n+1).sqrt(prec=Integer(n).log(2,prec=30)+1))
187
+ l = ceil((self.degree() + 1) / k)
188
+
189
+ # we store all matrices transposed for performance reasons
190
+ G = <Matrix_mod2_dense>Matrix(GF(2), k, n)
191
+
192
+ # first compute g^j mod h, 2 <= j < k
193
+ # first deal with j=0
194
+ for i from 0 <= i < GF2X_NumBits(gpow):
195
+ mzd_write_bit(G._entries, 0, i, GF2_conv_to_long(GF2X_coeff(gpow, i)))
196
+ # precompute g^2
197
+ GF2X_SqrMod_pre(g2, _g, modulus)
198
+ gpow = _g
199
+ for j in range(1, k, 2):
200
+ if j > 1:
201
+ GF2X_MulMod_pre(gpow, gpow, g2, modulus) # gpow = g^j
202
+ for i from 0 <= i < GF2X_NumBits(gpow):
203
+ mzd_write_bit(G._entries, j, i, GF2_conv_to_long(GF2X_coeff(gpow, i)))
204
+ # we now process 2j, 4j, 8j, ... by squaring each time
205
+ if 2*j < k:
206
+ tt = gpow
207
+ jj = j
208
+ while 2*jj < k:
209
+ GF2X_SqrMod_pre(tt, tt, modulus)
210
+ jj = 2*jj
211
+ for i from 0 <= i < GF2X_NumBits(tt):
212
+ mzd_write_bit(G._entries, jj, i, GF2_conv_to_long(GF2X_coeff(tt, i)))
213
+ # we need that gpow = g^k at the end
214
+ if k % 2 == 1: # k is odd, last j is k-2
215
+ GF2X_MulMod_pre(gpow, gpow, g2, modulus)
216
+ else: # k is even, last j is k-1
217
+ GF2X_MulMod_pre(gpow, gpow, _g, modulus)
218
+ verbose("G %d x %d %5.3f s" % (G.nrows(), G.ncols(), cputime(t)),
219
+ level=1)
220
+
221
+ # split f in chunks of degree < k
222
+ t = cputime()
223
+ F = <Matrix_mod2_dense>Matrix(GF(2), l, k)
224
+ for j in range(0, l):
225
+ if j*k+k <= maxlength:
226
+ for i from j*k <= i < j*k+k:
227
+ mzd_write_bit(F._entries, j, i-j*k, GF2_conv_to_long(GF2X_coeff(_f, i)))
228
+ else:
229
+ for i from j*k <= i < maxlength:
230
+ mzd_write_bit(F._entries, j, i-j*k, GF2_conv_to_long(GF2X_coeff(_f, i)))
231
+
232
+ verbose("F %d x %d %5.3f s" % (F.nrows(), F.ncols(), cputime(t)),
233
+ level=1)
234
+
235
+ t = cputime()
236
+ H = <Matrix_mod2_dense>(F * G)
237
+ verbose("H %d x %d %5.3f s" % (H.nrows(), H.ncols(), cputime(t)),
238
+ level=1)
239
+
240
+ t = cputime()
241
+ # H is a n x l matrix now H[i,j] = sum(G[i,m]*F[m,j],
242
+ # m=0..k-1) = sum(g^m[i] * f[j*k+m], m=0..k-1) where g^m[i] is
243
+ # the coefficient of degree i in g^m and f[j*k+m] is the
244
+ # coefficient of degree j*k+m in f thus f[j*k+m]*g^m[i] should
245
+ # be multiplied by g^(j*k) gpow = (g^k) % h
246
+
247
+ GF2X_conv_long(res.x, 0)
248
+ j = l - 1
249
+ while j >= 0:
250
+ #res = (res * gpow) % h
251
+ GF2X_MulMod_pre(res.x, res.x, gpow, modulus)
252
+
253
+ # res = res + parent([H[j,i] for i in range(0,n)])
254
+ GF2X_conv_long(tt, 0)
255
+ for i from 0<= i < n:
256
+ GF2X_SetCoeff_long(tt, i, mzd_read_bit(H._entries, j, i))
257
+ GF2X_add(res.x, res.x, tt)
258
+ j = j - 1
259
+
260
+ verbose("Res %5.3f s" % cputime(t), level=1)
261
+ return res
262
+
263
+ # Other polynomials have compose_mod as methods following the naming of
264
+ # NTL/Flint bindings but the above method predates these. We expose
265
+ # compose_mod here so all polynomial ring elements which support this can
266
+ # use either name
267
+ compose_mod = modular_composition
268
+
269
+ @cached_method
270
+ def is_irreducible(self):
271
+ r"""
272
+ Return whether this polynomial is irreducible over `\GF{2}`.
273
+
274
+ EXAMPLES::
275
+
276
+ sage: R.<x> = GF(2)[]
277
+ sage: (x^2 + 1).is_irreducible()
278
+ False
279
+ sage: (x^3 + x + 1).is_irreducible()
280
+ True
281
+
282
+ Test that caching works::
283
+
284
+ sage: R.<x> = GF(2)[]
285
+ sage: f = x^2 + 1
286
+ sage: f.is_irreducible()
287
+ False
288
+ sage: f.is_irreducible.cache
289
+ False
290
+ """
291
+ return 0 != GF2X_IterIrredTest(self.x)
292
+
293
+
294
+ # The three functions below are used in polynomial_ring.py, but are in
295
+ # this Cython file since they call C++ functions. They return
296
+ # polynomials as lists so that no variable has to be specified.
297
+ # AUTHOR: Peter Bruin (June 2013)
298
+
299
+ def GF2X_BuildIrred_list(n):
300
+ """
301
+ Return the list of coefficients of the lexicographically smallest
302
+ irreducible polynomial of degree `n` over the field of 2 elements.
303
+
304
+ EXAMPLES::
305
+
306
+ sage: from sage.rings.polynomial.polynomial_gf2x import GF2X_BuildIrred_list
307
+ sage: GF2X_BuildIrred_list(2)
308
+ [1, 1, 1]
309
+ sage: GF2X_BuildIrred_list(3)
310
+ [1, 1, 0, 1]
311
+ sage: GF2X_BuildIrred_list(4)
312
+ [1, 1, 0, 0, 1]
313
+ sage: GF(2)['x'](GF2X_BuildIrred_list(33))
314
+ x^33 + x^6 + x^3 + x + 1
315
+ """
316
+ from sage.rings.finite_rings.finite_field_constructor import FiniteField
317
+ cdef GF2X_c f
318
+ GF2 = FiniteField(2)
319
+ GF2X_BuildIrred(f, int(n))
320
+ return [GF2(not GF2_IsZero(GF2X_coeff(f, i))) for i in range(n + 1)]
321
+
322
+
323
+ def GF2X_BuildSparseIrred_list(n):
324
+ """
325
+ Return the list of coefficients of an irreducible polynomial of
326
+ degree `n` of minimal weight over the field of 2 elements.
327
+
328
+ EXAMPLES::
329
+
330
+ sage: from sage.rings.polynomial.polynomial_gf2x import GF2X_BuildIrred_list, GF2X_BuildSparseIrred_list
331
+ sage: all([GF2X_BuildSparseIrred_list(n) == GF2X_BuildIrred_list(n)
332
+ ....: for n in range(1,33)])
333
+ True
334
+ sage: GF(2)['x'](GF2X_BuildSparseIrred_list(33))
335
+ x^33 + x^10 + 1
336
+ """
337
+ from sage.rings.finite_rings.finite_field_constructor import FiniteField
338
+ cdef GF2X_c f
339
+ GF2 = FiniteField(2)
340
+ GF2X_BuildSparseIrred(f, int(n))
341
+ return [GF2(not GF2_IsZero(GF2X_coeff(f, i))) for i in range(n + 1)]
342
+
343
+
344
+ def GF2X_BuildRandomIrred_list(n):
345
+ """
346
+ Return the list of coefficients of an irreducible polynomial of
347
+ degree `n` of minimal weight over the field of 2 elements.
348
+
349
+ EXAMPLES::
350
+
351
+ sage: from sage.rings.polynomial.polynomial_gf2x import GF2X_BuildRandomIrred_list
352
+ sage: GF2X_BuildRandomIrred_list(2)
353
+ [1, 1, 1]
354
+ sage: GF2X_BuildRandomIrred_list(3) in [[1, 1, 0, 1], [1, 0, 1, 1]]
355
+ True
356
+ """
357
+ from sage.misc.randstate import current_randstate
358
+ from sage.rings.finite_rings.finite_field_constructor import FiniteField
359
+ cdef GF2X_c tmp, f
360
+ GF2 = FiniteField(2)
361
+ current_randstate().set_seed_ntl(False)
362
+ GF2X_BuildSparseIrred(tmp, int(n))
363
+ GF2X_BuildRandomIrred(f, tmp)
364
+ return [GF2(not GF2_IsZero(GF2X_coeff(f, i))) for i in range(n + 1)]
@@ -0,0 +1,8 @@
1
+ # sage_setup: distribution = sagemath-ntl
2
+ from sage.libs.ntl.types cimport ZZX_c
3
+ from sage.rings.polynomial.polynomial_element cimport Polynomial
4
+
5
+ cdef class Polynomial_integer_dense_ntl(Polynomial):
6
+ cdef ZZX_c _poly
7
+
8
+ cdef Polynomial_integer_dense_ntl _new(self)