Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/c_lib/include/ntl_wrap.h
4045 views
1
#ifdef __cplusplus
2
#include <NTL/ZZ.h>
3
#include <NTL/ZZX.h>
4
#include <NTL/ZZ_pXFactoring.h>
5
#include <NTL/ZZXFactoring.h>
6
#include <NTL/ZZ_p.h>
7
#include <NTL/ZZ_pX.h>
8
#include <NTL/ZZ_pE.h>
9
#include <NTL/ZZ_pEX.h>
10
#include <NTL/ZZ_pEXFactoring.h>
11
#include <NTL/lzz_p.h>
12
#include <NTL/lzz_pX.h>
13
#include <NTL/mat_ZZ.h>
14
#include <NTL/mat_poly_ZZ.h>
15
#include <NTL/GF2E.h>
16
#include <NTL/GF2X.h>
17
#include <NTL/GF2XFactoring.h>
18
#include <NTL/GF2EX.h>
19
#include <NTL/mat_GF2.h>
20
#include <NTL/mat_GF2E.h>
21
#include <NTL/HNF.h>
22
#include <NTL/LLL.h>
23
#include <gmp.h>
24
using namespace NTL;
25
#endif
26
27
#ifdef __cplusplus
28
#define EXTERN extern "C"
29
#else
30
#define EXTERN
31
#endif
32
33
#include "Python.h"
34
#include "ccobject.h"
35
36
EXTERN void del_charstar(char*);
37
38
EXTERN void setup_NTL_error_callback(void (*function)(const char*, void*), void* context);
39
40
//////// ZZ //////////
41
42
#ifndef __cplusplus
43
struct ZZ;
44
#endif
45
46
EXTERN int ZZ_to_int(const struct ZZ* x);
47
EXTERN struct ZZ* int_to_ZZ(int value);
48
EXTERN void ZZ_to_mpz(mpz_t* output, const struct ZZ* x);
49
EXTERN void mpz_to_ZZ(struct ZZ *output, const mpz_t* x);
50
EXTERN void ZZ_set_from_int(struct ZZ* x, int value);
51
/*Random-number generation */
52
//EXTERN void setSeed(const struct ZZ* n);
53
//EXTERN struct ZZ* ZZ_randomBnd(const struct ZZ* x);
54
//EXTERN struct ZZ* ZZ_randomBits(long n);
55
56
#ifdef __cplusplus
57
EXTERN long ZZ_remove(struct ZZ& x, const struct ZZ& a, const struct ZZ& p);
58
#endif
59
60
//////// ZZ_p //////////
61
62
#ifndef __cplusplus
63
struct ZZ_p;
64
#endif
65
66
#ifdef __cplusplus // sorry, if you want a C version, feel free to add it
67
EXTERN int ZZ_p_to_int(const ZZ_p& x);
68
EXTERN ZZ_p int_to_ZZ_p(int value);
69
#endif
70
EXTERN void ZZ_p_set_from_int(struct ZZ_p* x, int value);
71
EXTERN struct ZZ_p* ZZ_p_pow(const struct ZZ_p* x, long e);
72
EXTERN void ntl_ZZ_set_modulus(struct ZZ* x);
73
EXTERN struct ZZ_p* ZZ_p_inv(struct ZZ_p* x);
74
EXTERN struct ZZ_p* ZZ_p_neg(struct ZZ_p* x);
75
EXTERN struct ZZ_p* ZZ_p_random(void);
76
EXTERN void ZZ_p_modulus(struct ZZ* mod, const struct ZZ_p* x);
77
78
79
EXTERN struct ZZ_pContext* ZZ_pContext_new(struct ZZ* p);
80
EXTERN struct ZZ_pContext* ZZ_pContext_construct(void* mem, struct ZZ* p);
81
82
//////// ZZX //////////
83
#ifndef __cplusplus
84
struct ZZX;
85
#endif
86
87
EXTERN char* ZZX_repr(struct ZZX* x);
88
EXTERN struct ZZX* ZZX_copy(struct ZZX* x);
89
EXTERN void ZZX_setitem_from_int(struct ZZX* x, long i, int value);
90
EXTERN int ZZX_getitem_as_int(struct ZZX* x, long i);
91
EXTERN void ZZX_getitem_as_mpz(mpz_t* output, struct ZZX* x, long i);
92
EXTERN struct ZZX* ZZX_div(struct ZZX* x, struct ZZX* y, int* divisible);
93
EXTERN void ZZX_quo_rem(struct ZZX* x, struct ZZX* other, struct ZZX** r, struct ZZX** q);
94
EXTERN struct ZZX* ZZX_square(struct ZZX* x);
95
EXTERN int ZZX_equal(struct ZZX* x, struct ZZX* y);
96
EXTERN int ZZX_is_monic(struct ZZX* x);
97
EXTERN struct ZZX* ZZX_neg(struct ZZX* x);
98
EXTERN struct ZZX* ZZX_left_shift(struct ZZX* x, long n);
99
EXTERN struct ZZX* ZZX_right_shift(struct ZZX* x, long n);
100
EXTERN char* ZZX_content(struct ZZX* x);
101
EXTERN struct ZZX* ZZX_primitive_part(struct ZZX* x);
102
EXTERN void ZZX_pseudo_quo_rem(struct ZZX* x, struct ZZX* y, struct ZZX** r, struct ZZX** q);
103
EXTERN struct ZZX* ZZX_gcd(struct ZZX* x, struct ZZX* y);
104
EXTERN void ZZX_xgcd(struct ZZX* x, struct ZZX* y, struct ZZ** r, struct ZZX** s, struct ZZX** t, int proof);
105
EXTERN long ZZX_degree(struct ZZX* x);
106
EXTERN struct ZZ* ZZX_leading_coefficient(struct ZZX* x);
107
EXTERN char* ZZX_constant_term(struct ZZX* x);
108
EXTERN void ZZX_set_x(struct ZZX* x);
109
EXTERN int ZZX_is_x(struct ZZX* x);
110
EXTERN struct ZZX* ZZX_derivative(struct ZZX* x);
111
EXTERN struct ZZX* ZZX_reverse(struct ZZX* x);
112
EXTERN struct ZZX* ZZX_reverse_hi(struct ZZX* x, int hi);
113
EXTERN struct ZZX* ZZX_truncate(struct ZZX* x, long m);
114
EXTERN struct ZZX* ZZX_multiply_and_truncate(struct ZZX* x, struct ZZX* y, long m);
115
EXTERN struct ZZX* ZZX_square_and_truncate(struct ZZX* x, long m);
116
EXTERN struct ZZX* ZZX_invert_and_truncate(struct ZZX* x, long m);
117
EXTERN struct ZZX* ZZX_multiply_mod(struct ZZX* x, struct ZZX* y, struct ZZX* modulus);
118
EXTERN struct ZZ* ZZX_trace_mod(struct ZZX* x, struct ZZX* y);
119
/* EXTERN struct ZZ* ZZX_polyeval(struct ZZX* f, struct ZZ* a); */
120
EXTERN char* ZZX_trace_list(struct ZZX* x);
121
EXTERN struct ZZ* ZZX_resultant(struct ZZX* x, struct ZZX* y, int proof);
122
EXTERN struct ZZ* ZZX_norm_mod(struct ZZX* x, struct ZZX* y, int proof);
123
EXTERN struct ZZ* ZZX_discriminant(struct ZZX* x, int proof);
124
EXTERN struct ZZX* ZZX_charpoly_mod(struct ZZX* x, struct ZZX* y, int proof);
125
EXTERN struct ZZX* ZZX_minpoly_mod(struct ZZX* x, struct ZZX* y);
126
EXTERN void ZZX_clear(struct ZZX* x);
127
EXTERN void ZZX_preallocate_space(struct ZZX* x, long n);
128
129
//////// ZZXFactoring //////////
130
131
// OUTPUT: v -- pointer to list of n ZZX elements (the squarefree factors)
132
// e -- point to list of e longs (the exponents)
133
// n -- length of above two lists
134
// The lists v and e are mallocd, and must be freed by the calling code.
135
EXTERN void ZZX_squarefree_decomposition(struct ZZX*** v, long** e, long* n, struct ZZX* x);
136
137
138
//////// ZZ_pX //////////
139
#ifndef __cplusplus
140
struct ZZ_pX;
141
#endif
142
143
EXTERN struct ZZ_pX* ZZ_pX_init();
144
//EXTERN char* ZZ_pX_repr(struct ZZ_pX* x);
145
/* EXTERN struct ZZ_pX* ZZ_pX_copy(struct ZZ_pX* x); */
146
/* EXTERN void ZZ_pX_setitem_from_int(struct ZZ_pX* x, long i, int value); */
147
/* EXTERN int ZZ_pX_getitem_as_int(struct ZZ_pX* x, long i); */
148
/* EXTERN struct ZZ_pX* ZZ_pX_div(struct ZZ_pX* x, struct ZZ_pX* y, int* divisible); */
149
/* EXTERN struct ZZ_pX* ZZ_pX_mod(struct ZZ_pX* x, struct ZZ_pX* y); */
150
/* EXTERN void ZZ_pX_quo_rem(struct ZZ_pX* x, struct ZZ_pX* other, struct ZZ_pX** r, struct ZZ_pX** q); */
151
/* EXTERN struct ZZ_pX* ZZ_pX_square(struct ZZ_pX* x); */
152
/* EXTERN int ZZ_pX_equal(struct ZZ_pX* x, struct ZZ_pX* y); */
153
/* EXTERN int ZZ_pX_is_monic(struct ZZ_pX* x); */
154
/* EXTERN struct ZZ_pX* ZZ_pX_neg(struct ZZ_pX* x); */
155
/* EXTERN struct ZZ_pX* ZZ_pX_left_shift(struct ZZ_pX* x, long n); */
156
/* EXTERN struct ZZ_pX* ZZ_pX_right_shift(struct ZZ_pX* x, long n); */
157
/* EXTERN void ZZ_pX_quo_rem(struct ZZ_pX* x, struct ZZ_pX* y, struct ZZ_pX** r, struct ZZ_pX** q); */
158
/* EXTERN struct ZZ_pX* ZZ_pX_gcd(struct ZZ_pX* x, struct ZZ_pX* y); */
159
/* EXTERN void ZZ_pX_xgcd(struct ZZ_pX** d, struct ZZ_pX** s, struct ZZ_pX** t, struct ZZ_pX* a, struct ZZ_pX* b); */
160
/* EXTERN void ZZ_pX_plain_xgcd(struct ZZ_pX** d, struct ZZ_pX** s, struct ZZ_pX** t, struct ZZ_pX* a, struct ZZ_pX* b); */
161
/* EXTERN long ZZ_pX_degree(struct ZZ_pX* x); */
162
/* EXTERN void ZZ_pX_set_x(struct ZZ_pX* x); */
163
/* EXTERN int ZZ_pX_is_x(struct ZZ_pX* x); */
164
/* EXTERN struct ZZ_pX* ZZ_pX_derivative(struct ZZ_pX* x); */
165
/* EXTERN struct ZZ_pX* ZZ_pX_reverse(struct ZZ_pX* x); */
166
/* EXTERN struct ZZ_pX* ZZ_pX_reverse_hi(struct ZZ_pX* x, int hi); */
167
/* EXTERN struct ZZ_pX* ZZ_pX_truncate(struct ZZ_pX* x, long m); */
168
/* EXTERN struct ZZ_pX* ZZ_pX_multiply_and_truncate(struct ZZ_pX* x, struct ZZ_pX* y, long m); */
169
/* EXTERN struct ZZ_pX* ZZ_pX_square_and_truncate(struct ZZ_pX* x, long m); */
170
/* EXTERN struct ZZ_pX* ZZ_pX_invert_and_truncate(struct ZZ_pX* x, long m); */
171
/* EXTERN struct ZZ_pX* ZZ_pX_multiply_mod(struct ZZ_pX* x, struct ZZ_pX* y, struct ZZ_pX* modulus); */
172
/* EXTERN struct ZZ_p* ZZ_pX_trace_mod(struct ZZ_pX* x, struct ZZ_pX* y); */
173
EXTERN char* ZZ_pX_trace_list(struct ZZ_pX* x);
174
/* EXTERN struct ZZ_p* ZZ_pX_resultant(struct ZZ_pX* x, struct ZZ_pX* y); */
175
/* EXTERN struct ZZ_p* ZZ_pX_norm_mod(struct ZZ_pX* x, struct ZZ_pX* y); */
176
/* EXTERN struct ZZ_pX* ZZ_pX_charpoly_mod(struct ZZ_pX* x, struct ZZ_pX* y); */
177
/* EXTERN struct ZZ_pX* ZZ_pX_minpoly_mod(struct ZZ_pX* x, struct ZZ_pX* y); */
178
/* EXTERN void ZZ_pX_clear(struct ZZ_pX* x); */
179
// EXTERN void ZZ_pX_preallocate_space(struct ZZ_pX* x, long n);
180
181
// Factoring elements of ZZ_pX:
182
// OUTPUT: v -- pointer to list of n ZZ_pX elements (the irred factors)
183
// e -- point to list of e longs (the exponents)
184
// n -- length of above two lists
185
// The lists v and e are mallocd, and must be freed by the calling code.
186
EXTERN void ZZ_pX_factor(struct ZZ_pX*** v, long** e, long* n, struct ZZ_pX* x, long verbose);
187
EXTERN void ZZ_pX_linear_roots(struct ZZ_p*** v, long* n, struct ZZ_pX* f);
188
189
#ifdef __cplusplus
190
EXTERN void ZZ_pX_conv_modulus(struct ZZ_pX &fout, const struct ZZ_pX &fin, const struct ZZ_pContext &mod);
191
EXTERN void ZZ_pEX_conv_modulus(struct ZZ_pEX &fout, const struct ZZ_pEX &fin, const struct ZZ_pContext &mod);
192
EXTERN void ZZ_pX_min_val_coeff(long &valuation, long &index, const struct ZZ_pX &f, const struct ZZ &p);
193
EXTERN long ZZ_pX_get_val_coeff(const struct ZZ_pX &f, const struct ZZ &p, long i);
194
EXTERN void ZZ_pX_left_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c);
195
EXTERN void ZZ_pX_right_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c);
196
EXTERN 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);
197
EXTERN 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);
198
199
#endif
200
201
//////// zz_p //////////
202
203
#ifndef __cplusplus
204
struct zz_p;
205
#endif
206
207
#define zz_p_set_from_long( obj1, obj2 )\
208
(obj1) = (obj2)
209
#define NTL_zz_p_DOUBLE_EQUALS( obj1, obj2 )\
210
(obj1) == (obj2)
211
212
EXTERN struct zz_pContext* zz_pContext_new(long p);
213
EXTERN struct zz_pContext* zz_pContext_construct(void* mem, long p);
214
EXTERN void zz_pContext_restore(struct zz_pContext* ctx);
215
216
//////// zz_pX //////////
217
218
#ifndef __cplusplus
219
struct zz_pX;
220
#endif
221
222
#define NTL_zz_pX_DOUBLE_EQUALS( obj1, obj2 )\
223
(obj1) == (obj2)
224
225
//////// ZZ_pEContext ///////////////
226
227
#ifndef __cplusplus
228
struct ZZ_pEContext;
229
#endif
230
231
EXTERN struct ZZ_pEContext* ZZ_pEContext_new(struct ZZ_pX *f);
232
EXTERN struct ZZ_pEContext* ZZ_pEContext_construct(void* mem, struct ZZ_pX *f);
233
EXTERN void ZZ_pEContext_restore(struct ZZ_pEContext* ctx);
234
235
//////// ZZ_pE ////////////
236
237
#ifndef __cplusplus
238
struct ZZ_pE;
239
#endif
240
241
EXTERN struct ZZ_pX ZZ_pE_to_ZZ_pX(struct ZZ_pE x);
242
243
//////// ZZ_pEX /////////
244
245
#ifndef __cplusplus
246
struct ZZ_pEX;
247
#endif
248
249
//////// mat_ZZ //////////
250
251
#ifndef __cplusplus
252
struct mat_ZZ;
253
#endif
254
255
EXTERN void mat_ZZ_SetDims(struct mat_ZZ* mZZ, long nrows, long ncols);
256
EXTERN struct mat_ZZ* mat_ZZ_pow(const struct mat_ZZ* x, long e);
257
EXTERN long mat_ZZ_nrows(const struct mat_ZZ* x);
258
EXTERN long mat_ZZ_ncols(const struct mat_ZZ* x);
259
EXTERN void mat_ZZ_setitem(struct mat_ZZ* x, int i, int j, const struct ZZ* z);
260
EXTERN struct ZZ* mat_ZZ_getitem(const struct mat_ZZ* x, int i, int j);
261
EXTERN struct ZZ* mat_ZZ_determinant(const struct mat_ZZ* x, long deterministic);
262
EXTERN struct mat_ZZ* mat_ZZ_HNF(const struct mat_ZZ* A, const struct ZZ* D);
263
EXTERN struct ZZX* mat_ZZ_charpoly(const struct mat_ZZ* A);
264
EXTERN long mat_ZZ_LLL(struct ZZ **det, struct mat_ZZ *x, long a, long b, long verbose);
265
EXTERN long mat_ZZ_LLL_U(struct ZZ **det, struct mat_ZZ *x, struct mat_ZZ *U, long a, long b, long verbose);
266
267
/* //////// ZZ_p ////////// */
268
/* #ifndef __cplusplus */
269
/* struct ZZ_p; */
270
/* #endif */
271
272
/* EXTERN void ZZ_p_set_modulus(const struct ZZ* p); */
273
/* EXTERN struct ZZ_p* new_ZZ_p(void); */
274
/* EXTERN void del_ZZ_p(struct ZZ_p* x); */
275
/* EXTERN struct ZZ_p* ZZ_p_add(const struct ZZ_p* x, const struct ZZ_p* y); */
276
/* EXTERN struct ZZ_p* ZZ_p_sub(const struct ZZ_p* x, const struct ZZ_p* y); */
277
/* EXTERN struct ZZ_p* ZZ_p_mul(const struct ZZ_p* x, const struct ZZ_p* y); */
278
/* EXTERN struct ZZ_p* ZZ_p_pow(const struct ZZ_p* x, long e); */
279
/* EXTERN int ZZ_p_is_zero(struct ZZ_p*x ); */
280
/* EXTERN int ZZ_p_is_one(struct ZZ_p*x ); */
281
282
283
//////// ZZ_pE //////////
284
#ifndef __cplusplus
285
struct ZZ_pE;
286
#endif
287
288
// EXTERN struct ZZ_pE* new_ZZ_pE
289
290
291
292
//////// ZZ_pEX //////////
293
294
//#ifndef __cplusplus
295
//struct ZZ_pEX;
296
//#endif
297
298
//EXTERN struct ZZ_pEX* new_ZZ_pEX
299
300
/////// GF2X ////////////////
301
#ifndef __cplusplus
302
struct GF2X;
303
#endif
304
305
/////// GF2EContext ////////////////
306
307
#ifndef __cplusplus
308
struct GF2EContext;
309
#endif
310
311
EXTERN struct GF2EContext* GF2EContext_new(struct GF2X_c* p);
312
EXTERN struct GF2EContext* GF2EContext_construct(void *mem, const struct GF2X *p);
313
314
//////// mat_GF2E //////////
315
316
#ifndef __cplusplus
317
struct mat_GF2E;
318
#endif
319
320
EXTERN void mat_GF2E_setitem(struct mat_GF2E* x, int i, int j, const struct GF2E* z);
321
322
//////// mat_GF2 //////////
323
324
#ifndef __cplusplus
325
struct mat_GF2;
326
#endif
327
328
EXTERN void mat_GF2_setitem(struct mat_GF2* x, int i, int j, const struct GF2* z);
329
330