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,743 @@
1
+ /* sage_setup: distribution = sagemath-ntl
2
+ */
3
+ #ifndef _SAGE_NTLWRAP_CPP
4
+ #define _SAGE_NTLWRAP_CPP
5
+ #include "ntlwrap.h"
6
+
7
+ #ifdef __cplusplus
8
+
9
+ #include <iostream>
10
+ #include <sstream>
11
+ #include <gmp.h>
12
+
13
+ #include <NTL/ZZ_limbs.h>
14
+
15
+ //////// ZZ //////////
16
+
17
+ /* Return value is only valid if the result should fit into an int.
18
+ AUTHOR: David Harvey (2008-06-08) */
19
+ static CYTHON_INLINE int ZZ_to_int(const ZZ* x)
20
+ {
21
+ return to_int(*x);
22
+ }
23
+
24
+ /* Copies the ZZ into the mpz_t
25
+ Assumes output has been mpz_init'd.
26
+ AUTHOR: David Harvey
27
+ Joel B. Mohler moved the ZZX_getitem_as_mpz code out to this function (2007-03-13) */
28
+ static void ZZ_to_mpz(mpz_t output, const struct ZZ* x)
29
+ {
30
+ mpz_import(output, x->size(), -1, sizeof(mp_limb_t), 0, 0, ZZ_limbs_get(*x));
31
+ if (sign(*x) < 0)
32
+ mpz_neg(output, output);
33
+ }
34
+
35
+ /* Copies the mpz_t into the ZZ
36
+ AUTHOR: Joel B. Mohler (2007-03-15) */
37
+ static void mpz_to_ZZ(struct ZZ* output, mpz_srcptr x)
38
+ {
39
+ unsigned char stack_bytes[4096];
40
+ size_t size = (mpz_sizeinbase(x, 2) + 7) / 8;
41
+ int use_heap = (size > sizeof(stack_bytes));
42
+ void* bytes = use_heap ? malloc(size) : stack_bytes;
43
+ size_t words_written;
44
+ mpz_export(bytes, &words_written, -1, 1, 0, 0, x);
45
+ clear(*output);
46
+ ZZFromBytes(*output, (unsigned char *)bytes, words_written);
47
+ if (mpz_sgn(x) < 0)
48
+ NTL::negate(*output, *output);
49
+ if (use_heap)
50
+ free(bytes);
51
+ }
52
+
53
+ static long ZZ_remove(struct ZZ &dest, const struct ZZ &src, const struct ZZ &f)
54
+ {
55
+ // Based on the code for mpz_remove
56
+ ZZ fpow[40]; // inexaustible...until year 2020 or so
57
+ ZZ x, rem;
58
+ long pwr;
59
+ int p;
60
+
61
+ if (compare(f, 1) <= 0 && compare(f, -1) >= 0)
62
+ Error("Division by zero");
63
+
64
+ if (compare(src, 0) == 0)
65
+ {
66
+ if (src != dest)
67
+ dest = src;
68
+ return 0;
69
+ }
70
+
71
+ if (compare(f, 2) == 0)
72
+ {
73
+ dest = src;
74
+ return MakeOdd(dest);
75
+ }
76
+
77
+ /* We could perhaps compute mpz_scan1(src,0)/mpz_scan1(f,0). It is an
78
+ upper bound of the result we're seeking. We could also shift down the
79
+ operands so that they become odd, to make intermediate values smaller. */
80
+
81
+ pwr = 0;
82
+ fpow[0] = ZZ(f);
83
+ dest = src;
84
+ rem = ZZ();
85
+ x = ZZ();
86
+
87
+ /* Divide by f, f^2, ..., f^(2^k) until we get a remainder for f^(2^k). */
88
+ for (p = 0;;p++)
89
+ {
90
+ DivRem(x, rem, dest, fpow[p]);
91
+ if (compare(rem, 0) != 0)
92
+ break;
93
+ fpow[p+1] = ZZ();
94
+ NTL::mul(fpow[p+1], fpow[p], fpow[p]);
95
+ dest = x;
96
+ }
97
+
98
+ pwr = (1 << p) - 1;
99
+
100
+ /* Divide by f^(2^(k-1)), f^(2^(k-2)), ..., f for all divisors that give a
101
+ zero remainder. */
102
+ while (--p >= 0)
103
+ {
104
+ DivRem(x, rem, dest, fpow[p]);
105
+ if (compare(rem, 0) == 0)
106
+ {
107
+ pwr += 1 << p;
108
+ dest = x;
109
+ }
110
+ }
111
+ return pwr;
112
+ }
113
+
114
+ //////// ZZ_p //////////
115
+
116
+ /* Return value is only valid if the result should fit into an int.
117
+ AUTHOR: David Harvey (2008-06-08) */
118
+ static CYTHON_INLINE int ZZ_p_to_int(const ZZ_p& x )
119
+ {
120
+ return ZZ_to_int(&rep(x));
121
+ }
122
+
123
+
124
+ static CYTHON_INLINE void ZZ_p_modulus(struct ZZ* mod, const struct ZZ_p* x)
125
+ {
126
+ (*mod) = x->modulus();
127
+ }
128
+
129
+
130
+ ///////////////////////////////////////////////
131
+ //////// ZZX //////////
132
+ ///////////////////////////////////////////////
133
+
134
+ static char* ZZX_repr(struct ZZX* x)
135
+ {
136
+ std::ostringstream instore;
137
+ instore << (*x);
138
+ int n = strlen(instore.str().data());
139
+ char* buf = new char[n+1];
140
+ strcpy(buf, instore.str().data());
141
+ return buf;
142
+ }
143
+
144
+ static CYTHON_INLINE struct ZZX* ZZX_copy(struct ZZX* x) {
145
+ return new ZZX(*x);
146
+ }
147
+
148
+ /* Sets ith coefficient of x to value.
149
+ AUTHOR: David Harvey (2006-06-08) */
150
+ static CYTHON_INLINE void ZZX_setitem_from_int(struct ZZX* x, long i, int value)
151
+ {
152
+ SetCoeff(*x, i, value);
153
+ }
154
+
155
+ /* Returns ith coefficient of x.
156
+ Return value is only valid if the result should fit into an int.
157
+ AUTHOR: David Harvey (2006-06-08) */
158
+ static CYTHON_INLINE int ZZX_getitem_as_int(struct ZZX* x, long i)
159
+ {
160
+ return ZZ_to_int(&coeff(*x, i));
161
+ }
162
+
163
+ /* Copies ith coefficient of x to output.
164
+ Assumes output has been mpz_init'd.
165
+ AUTHOR: David Harvey (2007-02) */
166
+ static CYTHON_INLINE void ZZX_getitem_as_mpz(mpz_t output, struct ZZX* x, long i)
167
+ {
168
+ const ZZ& z = coeff(*x, i);
169
+ ZZ_to_mpz(output, &z);
170
+ }
171
+
172
+ static CYTHON_INLINE struct ZZX* ZZX_div(struct ZZX* x, struct ZZX* y, int* divisible)
173
+ {
174
+ struct ZZX* z = new ZZX();
175
+ *divisible = divide(*z, *x, *y);
176
+ return z;
177
+ }
178
+
179
+
180
+ static CYTHON_INLINE void ZZX_quo_rem(struct ZZX* x, struct ZZX* other, struct ZZX** r, struct ZZX** q)
181
+ {
182
+ struct ZZX *qq = new ZZX(), *rr = new ZZX();
183
+ DivRem(*qq, *rr, *x, *other);
184
+ *r = rr; *q = qq;
185
+ }
186
+
187
+
188
+ static CYTHON_INLINE struct ZZX* ZZX_square(struct ZZX* x)
189
+ {
190
+ struct ZZX* s = new ZZX();
191
+ sqr(*s, *x);
192
+ return s;
193
+ }
194
+
195
+
196
+ static CYTHON_INLINE struct ZZX* ZZX_neg(struct ZZX* x)
197
+ {
198
+ struct ZZX* y = new ZZX();
199
+ *y = -*x;
200
+ return y;
201
+ }
202
+
203
+
204
+ static CYTHON_INLINE struct ZZX* ZZX_left_shift(struct ZZX* x, long n)
205
+ {
206
+ struct ZZX* y = new ZZX();
207
+ LeftShift(*y, *x, n);
208
+ return y;
209
+ }
210
+
211
+
212
+ static CYTHON_INLINE struct ZZX* ZZX_right_shift(struct ZZX* x, long n)
213
+ {
214
+ struct ZZX* y = new ZZX();
215
+ RightShift(*y, *x, n);
216
+ return y;
217
+ }
218
+
219
+ static CYTHON_INLINE struct ZZX* ZZX_primitive_part(struct ZZX* x)
220
+ {
221
+ struct ZZX* p = new ZZX();
222
+ PrimitivePart(*p, *x);
223
+ return p;
224
+ }
225
+
226
+
227
+ static CYTHON_INLINE void ZZX_pseudo_quo_rem(struct ZZX* x, struct ZZX* y, struct ZZX** r, struct ZZX** q)
228
+ {
229
+ *r = new ZZX();
230
+ *q = new ZZX();
231
+ PseudoDivRem(**q, **r, *x, *y);
232
+ }
233
+
234
+
235
+ static CYTHON_INLINE struct ZZX* ZZX_gcd(struct ZZX* x, struct ZZX* y)
236
+ {
237
+ struct ZZX* g = new ZZX();
238
+ GCD(*g, *x, *y);
239
+ return g;
240
+ }
241
+
242
+
243
+ static CYTHON_INLINE void ZZX_xgcd(struct ZZX* x, struct ZZX* y, struct ZZ** r, struct ZZX** s,
244
+ struct ZZX** t, int proof)
245
+ {
246
+ *r = new ZZ();
247
+ *s = new ZZX();
248
+ *t = new ZZX();
249
+ XGCD(**r, **s, **t, *x, *y, proof);
250
+ }
251
+
252
+
253
+ static CYTHON_INLINE void ZZX_set_x(struct ZZX* x)
254
+ {
255
+ SetX(*x);
256
+ }
257
+
258
+
259
+ static CYTHON_INLINE int ZZX_is_x(struct ZZX* x)
260
+ {
261
+ return IsX(*x);
262
+ }
263
+
264
+
265
+ static CYTHON_INLINE struct ZZX* ZZX_derivative(struct ZZX* x)
266
+ {
267
+ ZZX* d = new ZZX();
268
+ diff(*d, *x);
269
+ return d;
270
+ }
271
+
272
+
273
+ static CYTHON_INLINE struct ZZX* ZZX_reverse(struct ZZX* x)
274
+ {
275
+ ZZX* r = new ZZX();
276
+ reverse(*r, *x);
277
+ return r;
278
+ }
279
+
280
+ static CYTHON_INLINE struct ZZX* ZZX_reverse_hi(struct ZZX* x, int hi)
281
+ {
282
+ ZZX* r = new ZZX();
283
+ reverse(*r, *x, hi);
284
+ return r;
285
+ }
286
+
287
+
288
+ static CYTHON_INLINE struct ZZX* ZZX_truncate(struct ZZX* x, long m)
289
+ {
290
+ ZZX* t = new ZZX();
291
+ trunc(*t, *x, m);
292
+ return t;
293
+ }
294
+
295
+
296
+ static CYTHON_INLINE struct ZZX* ZZX_multiply_and_truncate(struct ZZX* x, struct ZZX* y, long m)
297
+ {
298
+ ZZX* t = new ZZX();
299
+ MulTrunc(*t, *x, *y, m);
300
+ return t;
301
+ }
302
+
303
+
304
+ static CYTHON_INLINE struct ZZX* ZZX_square_and_truncate(struct ZZX* x, long m)
305
+ {
306
+ ZZX* t = new ZZX();
307
+ SqrTrunc(*t, *x, m);
308
+ return t;
309
+ }
310
+
311
+
312
+ static CYTHON_INLINE struct ZZX* ZZX_invert_and_truncate(struct ZZX* x, long m)
313
+ {
314
+ ZZX* t = new ZZX();
315
+ InvTrunc(*t, *x, m);
316
+ return t;
317
+ }
318
+
319
+
320
+ static CYTHON_INLINE struct ZZX* ZZX_multiply_mod(struct ZZX* x, struct ZZX* y, struct ZZX* modulus)
321
+ {
322
+ ZZX* p = new ZZX();
323
+ MulMod(*p, *x, *y, *modulus);
324
+ return p;
325
+ }
326
+
327
+
328
+ static CYTHON_INLINE struct ZZ* ZZX_trace_mod(struct ZZX* x, struct ZZX* y)
329
+ {
330
+ ZZ* p = new ZZ();
331
+ TraceMod(*p, *x, *y);
332
+ return p;
333
+ }
334
+
335
+
336
+ static char* ZZX_trace_list(struct ZZX* x)
337
+ {
338
+ vec_ZZ v;
339
+ TraceVec(v, *x);
340
+ std::ostringstream instore;
341
+ instore << v;
342
+ int n = strlen(instore.str().data());
343
+ char* buf = new char[n+1];
344
+ strcpy(buf, instore.str().data());
345
+ return buf;
346
+ }
347
+
348
+
349
+ static CYTHON_INLINE struct ZZ* ZZX_resultant(struct ZZX* x, struct ZZX* y, int proof)
350
+ {
351
+ ZZ* res = new ZZ();
352
+ resultant(*res, *x, *y, proof);
353
+ return res;
354
+ }
355
+
356
+
357
+ static CYTHON_INLINE struct ZZ* ZZX_norm_mod(struct ZZX* x, struct ZZX* y, int proof)
358
+ {
359
+ ZZ* res = new ZZ();
360
+ NormMod(*res, *x, *y, proof);
361
+ return res;
362
+ }
363
+
364
+
365
+ static CYTHON_INLINE struct ZZ* ZZX_discriminant(struct ZZX* x, int proof)
366
+ {
367
+ ZZ* d = new ZZ();
368
+ discriminant(*d, *x, proof);
369
+ return d;
370
+ }
371
+
372
+
373
+ static CYTHON_INLINE struct ZZX* ZZX_charpoly_mod(struct ZZX* x, struct ZZX* y, int proof)
374
+ {
375
+ ZZX* f = new ZZX();
376
+ CharPolyMod(*f, *x, *y, proof);
377
+ return f;
378
+ }
379
+
380
+
381
+ static CYTHON_INLINE struct ZZX* ZZX_minpoly_mod(struct ZZX* x, struct ZZX* y)
382
+ {
383
+ ZZX* f = new ZZX();
384
+ MinPolyMod(*f, *x, *y);
385
+ return f;
386
+ }
387
+
388
+
389
+ static CYTHON_INLINE void ZZX_clear(struct ZZX* x)
390
+ {
391
+ clear(*x);
392
+ }
393
+
394
+
395
+ static CYTHON_INLINE void ZZX_preallocate_space(struct ZZX* x, long n)
396
+ {
397
+ x->SetMaxLength(n);
398
+ }
399
+
400
+ static void ZZX_squarefree_decomposition(struct ZZX*** v, long** e, long* n, struct ZZX* x)
401
+ {
402
+ vec_pair_ZZX_long factors;
403
+ SquareFreeDecomp(factors, *x);
404
+ *n = factors.length();
405
+ *v = (ZZX**) malloc(sizeof(ZZX*) * (*n));
406
+ *e = (long*) malloc(sizeof(long) * (*n));
407
+ for (long i = 0; i < (*n); i++) {
408
+ (*v)[i] = new ZZX(factors[i].a);
409
+ (*e)[i] = factors[i].b;
410
+ }
411
+ }
412
+
413
+ ///////////////////////////////////////////////
414
+ //////// ZZ_pX //////////
415
+ ///////////////////////////////////////////////
416
+
417
+ static char* ZZ_pX_trace_list(struct ZZ_pX* x)
418
+ {
419
+ vec_ZZ_p v;
420
+ TraceVec(v, *x);
421
+ std::ostringstream instore;
422
+ instore << v;
423
+ int n = strlen(instore.str().data());
424
+ char* buf = new char[n+1];
425
+ strcpy(buf, instore.str().data());
426
+ return buf;
427
+ }
428
+
429
+ static void ZZ_pX_factor(struct ZZ_pX*** v, long** e, long* n, struct ZZ_pX* x, long verbose)
430
+ {
431
+ long i;
432
+ vec_pair_ZZ_pX_long factors;
433
+ berlekamp(factors, *x, verbose);
434
+ *n = factors.length();
435
+ *v = (ZZ_pX**) malloc(sizeof(ZZ_pX*) * (*n));
436
+ *e = (long*) malloc(sizeof(long)*(*n));
437
+ for (i=0; i<(*n); i++) {
438
+ (*v)[i] = new ZZ_pX(factors[i].a);
439
+ (*e)[i] = factors[i].b;
440
+ }
441
+ }
442
+
443
+ static void ZZ_pX_linear_roots(struct ZZ_p*** v, long* n, struct ZZ_pX* f)
444
+ {
445
+ long i;
446
+ vec_ZZ_p w;
447
+ FindRoots(w, *f);
448
+ *n = w.length();
449
+ (*v) = (ZZ_p**) malloc(sizeof(ZZ_p*)*(*n));
450
+ for (i=0; i<(*n); i++) {
451
+ (*v)[i] = new ZZ_p(w[i]);
452
+ }
453
+ }
454
+
455
+ /////////// ZZ_pE //////////////
456
+
457
+ static CYTHON_INLINE struct ZZ_pX ZZ_pE_to_ZZ_pX(struct ZZ_pE x)
458
+ {
459
+ return ZZ_pX(rep(x));
460
+ }
461
+
462
+ //////// mat_ZZ //////////
463
+
464
+ static CYTHON_INLINE void mat_ZZ_setitem(mat_ZZ* x, int i, int j, const struct ZZ* z)
465
+ {
466
+ (*x)[i][j] = *z;
467
+
468
+ }
469
+
470
+ static CYTHON_INLINE struct ZZ* mat_ZZ_getitem(const mat_ZZ* x, int i, int j)
471
+ {
472
+ return new ZZ((*x)(i,j));
473
+ }
474
+
475
+ static CYTHON_INLINE struct ZZ* mat_ZZ_determinant(const mat_ZZ* x, long deterministic)
476
+ {
477
+ ZZ* d = new ZZ();
478
+ determinant(*d, *x, deterministic);
479
+ return d;
480
+ }
481
+
482
+ static CYTHON_INLINE mat_ZZ* mat_ZZ_HNF(const mat_ZZ* A, const struct ZZ* D)
483
+ {
484
+ mat_ZZ* W = new mat_ZZ();
485
+ HNF(*W, *A, *D);
486
+ return W;
487
+ }
488
+
489
+ static CYTHON_INLINE long mat_ZZ_LLL(struct ZZ **det, mat_ZZ *x, long a, long b, long verbose)
490
+ {
491
+ *det = new ZZ();
492
+ return LLL(**det, *x, a, b, verbose);
493
+ }
494
+
495
+ static CYTHON_INLINE long mat_ZZ_LLL_U(struct ZZ **det, mat_ZZ *x, mat_ZZ *U, long a, long b, long verbose)
496
+ {
497
+ *det = new ZZ();
498
+ return LLL(**det, *x, *U, a, b, verbose);
499
+ }
500
+
501
+
502
+ static CYTHON_INLINE void mat_GF2E_setitem(mat_GF2E* x, int i, int j, const struct GF2E* z)
503
+ {
504
+ (*x)[i][j] = *z;
505
+ }
506
+
507
+ static CYTHON_INLINE void mat_GF2_setitem(mat_GF2* x, int i, int j, const struct GF2* z)
508
+ {
509
+ (*x)[i][j] = *z;
510
+ }
511
+
512
+ // Functions for using ZZ_pX's for p-adic extensions
513
+
514
+ static void ZZ_pX_conv_modulus(ZZ_pX &fout, const ZZ_pX &fin, const ZZ_pContext &modout)
515
+ {
516
+ // Changes the modulus of fin to modout, and puts the result in fout.
517
+ long i, n;
518
+
519
+ n = fin.rep.length();
520
+ fout.rep.SetLength(n);
521
+
522
+ ZZ_p* xp = fout.rep.elts();
523
+ const ZZ_p* ap = fin.rep.elts();
524
+
525
+ // I think it's enough to just restore modout once.
526
+ // This should be true as long as the function rep taking a ZZ_p as an argument
527
+ // and returning a ZZ works when the ZZ_p::modulus is incorrect.
528
+ modout.restore();
529
+
530
+ for (i = 0; i < n; i++)
531
+ {
532
+ conv(xp[i], rep(ap[i]));
533
+ }
534
+
535
+ // We may have set a leading coefficient to 0, so we have to normalize
536
+ fout.normalize();
537
+ }
538
+
539
+ static void ZZ_pEX_conv_modulus(ZZ_pEX &fout, const ZZ_pEX &fin, const ZZ_pContext &modout)
540
+ {
541
+ // Changes the modulus of fin to modout, and puts the result in fout.
542
+ long i, n, j, m;
543
+
544
+ n = fin.rep.length();
545
+ fout.rep.SetLength(n);
546
+
547
+ ZZ_pE* outpe = fout.rep.elts();
548
+ const ZZ_pE* inpe = fin.rep.elts();
549
+
550
+ ZZ_p* xp;
551
+ const ZZ_p* ap;
552
+ // I think it's enough to just restore modout once
553
+ // This should be true as long as Loophole() offers access to
554
+ // the underlying ZZ_pX representations of ZZ_pEs,
555
+ // and rep of a ZZ_p (giving a ZZ) works even if the ZZ_p::modulus is
556
+ // incorrect
557
+ modout.restore();
558
+
559
+ for (i = 0; i < n; i++)
560
+ {
561
+ m = rep(inpe[i]).rep.length();
562
+ outpe[i]._ZZ_pE__rep.rep.SetLength(m);
563
+
564
+ xp = outpe[i]._ZZ_pE__rep.rep.elts();
565
+ ap = rep(inpe[i]).rep.elts();
566
+
567
+ for (j = 0; j < m; j++)
568
+ conv(xp[j], rep(ap[j]));
569
+
570
+ // We may have set a leading coefficient to 0, so we have to normalize
571
+ outpe[i]._ZZ_pE__rep.normalize();
572
+ }
573
+ // We may have set a leading coefficient to 0, so we have to normalize
574
+ fout.normalize();
575
+ }
576
+
577
+ static void ZZ_pX_min_val_coeff(long & valuation, long &index, const struct ZZ_pX &f, const struct ZZ &p)
578
+ {
579
+ // Sets index, where the indexth coefficient of f has the minimum p-adic valuation.
580
+ // Sets valuation to be this valuation.
581
+ // If there are ties, index will be the lowest of the tied indices
582
+ // This only makes mathematical sense when p divides the modulus of f.
583
+ long i, n, v;
584
+
585
+ n = f.rep.length();
586
+ if (n == 0)
587
+ {
588
+ index = -1;
589
+ return;
590
+ }
591
+
592
+ const ZZ_p* fp = f.rep.elts();
593
+ ZZ *u = new ZZ();
594
+
595
+ valuation = -1;
596
+ i = 0;
597
+
598
+ while (valuation == -1)
599
+ {
600
+ if (rep(fp[i]) != 0)
601
+ {
602
+ index = i;
603
+ valuation = ZZ_remove(*u, rep(fp[i]), p);
604
+ }
605
+ i++;
606
+ }
607
+ for (; i < n; i++)
608
+ {
609
+ if (rep(fp[i]) != 0)
610
+ {
611
+ v = ZZ_remove(*u, rep(fp[i]), p);
612
+ if (v < valuation)
613
+ {
614
+ valuation = v;
615
+ index = i;
616
+ }
617
+ }
618
+ }
619
+ delete u;
620
+ }
621
+
622
+ static CYTHON_INLINE long ZZ_pX_get_val_coeff(const struct ZZ_pX &f, const struct ZZ &p, long i)
623
+ {
624
+ // Gets the p-adic valuation of the ith coefficient of f.
625
+ ZZ *u = new ZZ();
626
+ long ans = ZZ_remove(*u, rep(coeff(f, i)), p);
627
+ delete u;
628
+ return ans;
629
+ }
630
+
631
+ static void ZZ_pX_left_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c)
632
+ {
633
+ // Multiplies each coefficient by pn, and sets the context of the answer to c.
634
+
635
+ long i, n;
636
+
637
+ n = a.rep.length();
638
+ x.rep.SetLength(n);
639
+
640
+ ZZ_p* xp = x.rep.elts();
641
+ const ZZ_p* ap = a.rep.elts();
642
+
643
+ // I think it's enough to just restore modout once.
644
+ // This should be true as long as the function rep taking a ZZ_p as an argument
645
+ // and returning a ZZ works when the ZZ_p::modulus is incorrect.
646
+ c.restore();
647
+
648
+ for (i = 0; i < n; i++)
649
+ {
650
+ conv(xp[i], rep(ap[i]) * pn);
651
+ }
652
+
653
+ // We may have set a leading coefficient to 0, so we have to normalize
654
+ x.normalize();
655
+ }
656
+
657
+ static void ZZ_pX_right_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c)
658
+ {
659
+ // Divides each coefficient by pn, and sets the context of the answer to c.
660
+
661
+ long i, n;
662
+
663
+ n = a.rep.length();
664
+ x.rep.SetLength(n);
665
+
666
+ ZZ_p* xp = x.rep.elts();
667
+ const ZZ_p* ap = a.rep.elts();
668
+
669
+ // I think it's enough to just restore modout once.
670
+ // This should be true as long as the function rep taking a ZZ_p as an argument
671
+ // and returning a ZZ works when the ZZ_p::modulus is incorrect.
672
+ c.restore();
673
+
674
+ for (i = 0; i < n; i++)
675
+ {
676
+ conv(xp[i], rep(ap[i]) / pn);
677
+ }
678
+
679
+ // We may have set a leading coefficient to 0, so we have to normalize
680
+ x.normalize();
681
+ }
682
+
683
+ static void ZZ_pX_InvMod_newton_unram(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ_pXModulus &F, const struct ZZ_pContext &cpn, const struct ZZ_pContext &cp)
684
+ {
685
+ //int j;
686
+ cp.restore();
687
+ ZZ_pX *amodp = new ZZ_pX();
688
+ ZZ_pX *xmodp = new ZZ_pX();
689
+ ZZ_pX *fmodp = new ZZ_pX();
690
+ ZZ_pX_conv_modulus(*amodp, a, cp);
691
+ ZZ_pX_conv_modulus(*fmodp, F.val(), cp);
692
+ InvMod(*xmodp, *amodp, *fmodp);
693
+ //cout << "xmodp: " << *xmodp << "\namodp: " << *amodp << "\nfmodp: " << *fmodp << "\n";
694
+ cpn.restore();
695
+ ZZ_pX *minusa = new ZZ_pX();
696
+ ZZ_pX *xn = new ZZ_pX();
697
+ ZZ_pX_conv_modulus(*xn, *xmodp, cpn);
698
+ NTL::negate(*minusa, a);
699
+ while (1 > 0)
700
+ {
701
+ // x_n = 2*x_{n-1} - a*x_{n-1}^2 = (2 - a*x_{n-1})*x_{n-1}
702
+ MulMod(x, *minusa, *xn, F);
703
+ SetCoeff(x, 0, ConstTerm(x) + 2);
704
+ MulMod(x, x, *xn, F);
705
+ if (x == *xn)
706
+ break;
707
+ *xn = x;
708
+ //cout << "x: " << x << "\nxn: " << *xn << "\n";
709
+ //cin >> j;
710
+ }
711
+ delete amodp;
712
+ delete xmodp;
713
+ delete fmodp;
714
+ delete minusa;
715
+ delete xn;
716
+ }
717
+
718
+ static void ZZ_pX_InvMod_newton_ram(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ_pXModulus &F, const struct ZZ_pContext &cpn)
719
+ {
720
+ //int j;
721
+ cpn.restore();
722
+ ZZ_pX *minusa = new ZZ_pX();
723
+ ZZ_pX *xn = new ZZ_pX();
724
+ SetCoeff(*xn, 0, inv(ConstTerm(a)));
725
+ NTL::negate(*minusa, a);
726
+ while (1 > 0)
727
+ {
728
+ // x_n = 2*x_{n-1} - a*x_{n-1}^2 = (2 - a*x_{n-1})*x_{n-1}
729
+ MulMod(x, *minusa, *xn, F);
730
+ SetCoeff(x, 0, ConstTerm(x) + 2);
731
+ MulMod(x, x, *xn, F);
732
+ //cout << "x: " << x << "\nxn: " << *xn << "\n";
733
+ if (x == *xn)
734
+ break;
735
+ *xn = x;
736
+ //cin >> j;
737
+ }
738
+ delete minusa;
739
+ delete xn;
740
+ }
741
+
742
+ #endif /* #ifdef __cplusplus */
743
+ #endif /* #ifndef _SAGE_NTLWRAP_CPP */