source: git/ntl/include/NTL/GF2EX.h @ 77902f

spielwiese
Last change on this file since 77902f was 77902f, checked in by Hans Schönemann <hannes@…>, 21 years ago
*hannes: iostream adaption git-svn-id: file:///usr/local/Singular/svn/trunk@6321 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 28.7 KB
Line 
1
2
3#ifndef NTL_GF2EX__H
4#define NTL_GF2EX__H
5
6#include <NTL/vector.h>
7#include <NTL/GF2E.h>
8#include <NTL/vec_GF2E.h>
9#include <NTL/FFT.h>
10#include <NTL/GF2XVec.h>
11
12
13NTL_OPEN_NNS
14
15
16class GF2EX {
17
18public:
19
20vec_GF2E rep;
21
22
23/***************************************************************
24
25          Constructors, Destructors, and Assignment
26
27****************************************************************/
28
29
30GF2EX() { }
31
32
33GF2EX(INIT_SIZE_TYPE, long n) { rep.SetMaxLength(n); }
34
35GF2EX(const GF2EX& a) : rep(a.rep) { }
36
37
38GF2EX& operator=(const GF2EX& a) 
39   { rep = a.rep; return *this; }
40
41~GF2EX() { }
42
43void normalize();
44// strip leading zeros
45
46void SetMaxLength(long n) 
47// pre-allocate space for n coefficients.
48// Value is unchanged
49
50   { rep.SetMaxLength(n); }
51
52
53void kill() 
54// free space held by this polynomial.  Value becomes 0.
55
56   { rep.kill(); }
57
58static const GF2EX& zero();
59
60
61
62inline GF2EX& operator=(long a);
63inline GF2EX& operator=(GF2 a);
64inline GF2EX& operator=(const GF2E& a);
65
66inline GF2EX(long i, long a);
67inline GF2EX(long i, GF2 a);
68inline GF2EX(long i, const GF2E& a);
69
70GF2EX(GF2EX& x, INIT_TRANS_TYPE) : rep(x.rep, INIT_TRANS) { }
71
72
73};
74
75
76
77
78/********************************************************************
79
80                           input and output
81
82*********************************************************************/
83
84
85/**********************************************************
86
87                   Some utility routines
88
89***********************************************************/
90
91
92inline long deg(const GF2EX& a) { return a.rep.length() - 1; }
93
94const GF2E& coeff(const GF2EX& a, long i);
95// zero if i not in range
96
97void GetCoeff(GF2E& x, const GF2EX& a, long i);
98// x = a[i], or zero if i not in range
99
100const GF2E& LeadCoeff(const GF2EX& a);
101// zero if a == 0
102
103const GF2E& ConstTerm(const GF2EX& a);
104// zero if a == 0
105
106void SetCoeff(GF2EX& x, long i, const GF2E& a);
107void SetCoeff(GF2EX& x, long i, GF2 a);
108void SetCoeff(GF2EX& x, long i, long a);
109// x[i] = a, error is raised if i < 0
110
111inline GF2EX::GF2EX(long i, const GF2E& a) { SetCoeff(*this, i, a); }
112inline GF2EX::GF2EX(long i, GF2 a) { SetCoeff(*this, i, a); }
113inline GF2EX::GF2EX(long i, long a) { SetCoeff(*this, i, a); }
114
115void SetCoeff(GF2EX& x, long i);
116// x[i] = 1, error is raised if i < 0
117
118void SetX(GF2EX& x);
119// x is set to the monomial X
120
121long IsX(const GF2EX& a);
122// test if x = X
123
124inline void clear(GF2EX& x) 
125// x = 0
126
127   { x.rep.SetLength(0); }
128
129inline void set(GF2EX& x)
130// x = 1
131
132   { x.rep.SetLength(1); set(x.rep[0]); }
133
134inline void swap(GF2EX& x, GF2EX& y)
135// swap x & y (only pointers are swapped)
136
137   { swap(x.rep, y.rep); }
138
139void random(GF2EX& x, long n);
140inline GF2EX random_GF2EX(long n)
141   { GF2EX x; random(x, n); NTL_OPT_RETURN(GF2EX, x); }
142// generate a random polynomial of degree < n
143
144void trunc(GF2EX& x, const GF2EX& a, long m);
145inline GF2EX trunc(const GF2EX& a, long m)
146   { GF2EX x; trunc(x, a, m); NTL_OPT_RETURN(GF2EX, x); }
147// x = a % X^m
148
149void RightShift(GF2EX& x, const GF2EX& a, long n);
150inline GF2EX RightShift(const GF2EX& a, long n)
151   { GF2EX x; RightShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
152// x = a/X^n
153
154void LeftShift(GF2EX& x, const GF2EX& a, long n);
155inline GF2EX LeftShift(const GF2EX& a, long n)
156   { GF2EX x; LeftShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
157// x = a*X^n
158
159#ifndef NTL_TRANSITION
160
161inline GF2EX operator>>(const GF2EX& a, long n)
162   { GF2EX x; RightShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
163
164inline GF2EX operator<<(const GF2EX& a, long n)
165   { GF2EX x; LeftShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
166
167inline GF2EX& operator<<=(GF2EX& x, long n)
168   { LeftShift(x, x, n); return x; }
169
170inline GF2EX& operator>>=(GF2EX& x, long n)
171   { RightShift(x, x, n); return x; }
172
173#endif
174
175
176
177void diff(GF2EX& x, const GF2EX& a);
178inline GF2EX diff(const GF2EX& a)
179   { GF2EX x; diff(x, a); NTL_OPT_RETURN(GF2EX, x); }
180// x = derivative of a
181
182
183
184void MakeMonic(GF2EX& x);
185
186void reverse(GF2EX& c, const GF2EX& a, long hi);
187
188inline GF2EX reverse(const GF2EX& a, long hi)
189   { GF2EX x; reverse(x, a, hi); NTL_OPT_RETURN(GF2EX, x); }
190
191inline void reverse(GF2EX& c, const GF2EX& a)
192{  reverse(c, a, deg(a)); }
193
194inline GF2EX reverse(const GF2EX& a)
195   { GF2EX x; reverse(x, a); NTL_OPT_RETURN(GF2EX, x); }
196
197inline void VectorCopy(vec_GF2E& x, const GF2EX& a, long n)
198   { VectorCopy(x, a.rep, n); }
199
200inline vec_GF2E VectorCopy(const GF2EX& a, long n)
201   { return VectorCopy(a.rep, n); }
202
203
204
205
206/*******************************************************************
207
208                        conversion routines
209
210********************************************************************/
211
212
213
214void conv(GF2EX& x, long a);
215void conv(GF2EX& x, GF2 a);
216void conv(GF2EX& x, const GF2E& a);
217void conv(GF2EX& x, const ZZ& a);
218
219#ifndef NTL_TRANSITION
220void conv(GF2EX& x, const GF2X& a);
221#endif
222
223void conv(GF2EX& x, const vec_GF2E& a);
224
225inline GF2EX to_GF2EX(long a)
226   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
227
228inline GF2EX to_GF2EX(GF2 a)
229   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
230
231inline GF2EX to_GF2EX(const GF2E& a)
232   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
233
234inline GF2EX to_GF2EX(const ZZ& a)
235   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
236
237#ifndef NTL_TRANSITION
238inline GF2EX to_GF2EX(GF2X& a)
239   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
240#endif
241
242inline GF2EX to_GF2EX(const vec_GF2E& a)
243   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
244
245inline GF2EX& GF2EX::operator=(const GF2E& a) { conv(*this, a); return *this; }
246inline GF2EX& GF2EX::operator=(GF2 a) { conv(*this, a); return *this; }
247inline GF2EX& GF2EX::operator=(long a) { conv(*this, a); return *this; }
248
249
250
251
252/*************************************************************
253
254                        Comparison
255
256**************************************************************/
257
258long IsZero(const GF2EX& a); 
259
260long IsOne(const GF2EX& a);
261
262inline long operator==(const GF2EX& a, const GF2EX& b)
263   { return a.rep == b.rep; }
264
265long operator==(const GF2EX& a, const GF2E& b);
266long operator==(const GF2EX& a, GF2 b);
267long operator==(const GF2EX& a, long b);
268
269inline long operator==(const GF2E& a, const GF2EX& b) { return b == a; }
270inline long operator==(GF2 a, const GF2EX& b) { return b == a; }
271inline long operator==(long a, const GF2EX& b) { return b == a; }
272
273inline long operator!=(const GF2EX& a, const GF2EX& b) { return !(a == b); }
274
275inline long operator!=(const GF2EX& a, const GF2E& b) { return !(a == b); }
276inline long operator!=(const GF2EX& a, GF2 b) { return !(a == b); }
277inline long operator!=(const GF2EX& a, long b) { return !(a == b); }
278
279inline long operator!=(const GF2E& a, const GF2EX& b) { return !(a == b); }
280inline long operator!=(GF2 a, const GF2EX& b) { return !(a == b); }
281inline long operator!=(long a, const GF2EX& b) { return !(a == b); }
282
283
284/***************************************************************
285
286                         Addition
287
288****************************************************************/
289
290void add(GF2EX& x, const GF2EX& a, const GF2EX& b);
291// x = a + b
292
293void add(GF2EX& x, const GF2EX& a, const GF2E& b);
294void add(GF2EX& x, const GF2EX& a, GF2 b);
295void add(GF2EX& x, const GF2EX& a, long);
296
297inline void add(GF2EX& x, const GF2E& a, const GF2EX& b) { add(x, b, a); }
298inline void add(GF2EX& x, GF2 a, const GF2EX& b) { add(x, b, a); }
299inline void add(GF2EX& x, long a, const GF2EX& b) { add(x, b, a); }
300
301inline void sub(GF2EX& x, const GF2EX& a, const GF2EX& b) { add(x, a, b); }
302
303inline void sub(GF2EX& x, const GF2EX& a, const GF2E& b) { add(x, a, b); }
304inline void sub(GF2EX& x, const GF2EX& a, GF2 b) { add(x, a, b); }
305inline void sub(GF2EX& x, const GF2EX& a, long b) { add(x, a, b); }
306
307inline void sub(GF2EX& x, const GF2E& a, const GF2EX& b) { add(x, a, b); }
308inline void sub(GF2EX& x, GF2 a, const GF2EX& b) { add(x, a, b); }
309inline void sub(GF2EX& x, long a, const GF2EX& b) { add(x, a, b); }
310
311inline void negate(GF2EX& x, const GF2EX& a) { x = a; }
312
313
314
315
316inline GF2EX operator+(const GF2EX& a, const GF2EX& b)
317   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
318
319inline GF2EX operator+(const GF2EX& a, const GF2E& b)
320   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
321
322inline GF2EX operator+(const GF2EX& a, GF2 b)
323   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
324
325inline GF2EX operator+(const GF2EX& a, long b)
326   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
327
328inline GF2EX operator+(const GF2E& a, const GF2EX& b)
329   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
330
331inline GF2EX operator+(GF2 a, const GF2EX& b)
332   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
333
334inline GF2EX operator+(long a, const GF2EX& b)
335   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
336
337
338inline GF2EX operator-(const GF2EX& a, const GF2EX& b)
339   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
340
341inline GF2EX operator-(const GF2EX& a, const GF2E& b)
342   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
343
344inline GF2EX operator-(const GF2EX& a, GF2 b)
345   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
346
347inline GF2EX operator-(const GF2EX& a, long b)
348   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
349
350inline GF2EX operator-(const GF2E& a, const GF2EX& b)
351   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
352
353inline GF2EX operator-(GF2 a, const GF2EX& b)
354   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
355
356inline GF2EX operator-(long a, const GF2EX& b)
357   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
358
359
360inline GF2EX& operator+=(GF2EX& x, const GF2EX& b)
361   { add(x, x, b); return x; }
362
363inline GF2EX& operator+=(GF2EX& x, const GF2E& b)
364   { add(x, x, b); return x; }
365
366inline GF2EX& operator+=(GF2EX& x, GF2 b)
367   { add(x, x, b); return x; }
368
369inline GF2EX& operator+=(GF2EX& x, long b)
370   { add(x, x, b); return x; }
371
372inline GF2EX& operator-=(GF2EX& x, const GF2EX& b)
373   { sub(x, x, b); return x; }
374
375inline GF2EX& operator-=(GF2EX& x, const GF2E& b)
376   { sub(x, x, b); return x; }
377
378inline GF2EX& operator-=(GF2EX& x, GF2 b)
379   { sub(x, x, b); return x; }
380
381inline GF2EX& operator-=(GF2EX& x, long b)
382   { sub(x, x, b); return x; }
383
384
385inline GF2EX operator-(const GF2EX& a) 
386   { GF2EX x; negate(x, a); NTL_OPT_RETURN(GF2EX, x); }
387
388inline GF2EX& operator++(GF2EX& x) { add(x, x, 1); return x; }
389inline void operator++(GF2EX& x, int) { add(x, x, 1); }
390inline GF2EX& operator--(GF2EX& x) { sub(x, x, 1); return x; }
391inline void operator--(GF2EX& x, int) { sub(x, x, 1); }
392
393
394/*****************************************************************
395
396                        Multiplication
397
398******************************************************************/
399
400
401void mul(GF2EX& x, const GF2EX& a, const GF2EX& b);
402// x = a * b
403
404void sqr(GF2EX& x, const GF2EX& a);
405inline GF2EX sqr(const GF2EX& a)
406   { GF2EX x; sqr(x, a); NTL_OPT_RETURN(GF2EX, x); }
407// x = a^2
408
409void mul(GF2EX & x, const GF2EX& a, const GF2E& b);
410void mul(GF2EX & x, const GF2EX& a, GF2 b);
411void mul(GF2EX & x, const GF2EX& a, long b);
412
413inline void mul(GF2EX& x, const GF2E& a, const GF2EX& b) { mul(x, b, a); }
414inline void mul(GF2EX& x, GF2 a, const GF2EX& b) { mul(x, b, a); }
415inline void mul(GF2EX& x, long a, const GF2EX& b) { mul(x, b, a); }
416
417void MulTrunc(GF2EX& x, const GF2EX& a, const GF2EX& b, long n);
418inline GF2EX MulTrunc(const GF2EX& a, const GF2EX& b, long n)
419   { GF2EX x; MulTrunc(x, a, b, n); NTL_OPT_RETURN(GF2EX, x); }
420// x = a * b % X^n
421
422void SqrTrunc(GF2EX& x, const GF2EX& a, long n);
423inline GF2EX SqrTrunc(const GF2EX& a, long n)
424   { GF2EX x; SqrTrunc(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
425// x = a*a % X^n
426
427
428inline GF2EX operator*(const GF2EX& a, const GF2EX& b)
429   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
430
431inline GF2EX operator*(const GF2EX& a, const GF2E& b)
432   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
433
434inline GF2EX operator*(const GF2EX& a, GF2 b)
435   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
436
437inline GF2EX operator*(const GF2EX& a, long b)
438   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
439
440inline GF2EX operator*(const GF2E& a, const GF2EX& b)
441   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
442
443inline GF2EX operator*(GF2 a, const GF2EX& b)
444   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
445
446inline GF2EX operator*(long a, const GF2EX& b)
447   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
448
449inline GF2EX& operator*=(GF2EX& x, const GF2EX& b)
450   { mul(x, x, b); return x; }
451
452inline GF2EX& operator*=(GF2EX& x, const GF2E& b)
453   { mul(x, x, b); return x; }
454
455inline GF2EX& operator*=(GF2EX& x, GF2 b)
456   { mul(x, x, b); return x; }
457
458inline GF2EX& operator*=(GF2EX& x, long b)
459   { mul(x, x, b); return x; }
460
461
462void power(GF2EX& x, const GF2EX& a, long e);
463inline GF2EX power(const GF2EX& a, long e)
464   { GF2EX x; power(x, a, e); NTL_OPT_RETURN(GF2EX, x); }
465
466
467
468
469/*************************************************************
470
471                      Division
472
473**************************************************************/
474
475void DivRem(GF2EX& q, GF2EX& r, const GF2EX& a, const GF2EX& b);
476// q = a/b, r = a%b
477
478void div(GF2EX& q, const GF2EX& a, const GF2EX& b);
479void div(GF2EX& q, const GF2EX& a, const GF2E& b);
480void div(GF2EX& q, const GF2EX& a, GF2 b);
481void div(GF2EX& q, const GF2EX& a, long b);
482// q = a/b
483
484void rem(GF2EX& r, const GF2EX& a, const GF2EX& b);
485// r = a%b
486
487long divide(GF2EX& q, const GF2EX& a, const GF2EX& b);
488// if b | a, sets q = a/b and returns 1; otherwise returns 0
489
490long divide(const GF2EX& a, const GF2EX& b);
491// if b | a, sets q = a/b and returns 1; otherwise returns 0
492
493void InvTrunc(GF2EX& x, const GF2EX& a, long m);
494inline GF2EX InvTrunc(const GF2EX& a, long m)
495   { GF2EX x; InvTrunc(x, a, m); NTL_OPT_RETURN(GF2EX, x); }
496
497// computes x = a^{-1} % X^m
498// constant term must be non-zero
499
500
501
502inline GF2EX operator/(const GF2EX& a, const GF2EX& b)
503   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
504
505inline GF2EX operator/(const GF2EX& a, const GF2E& b)
506   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
507
508inline GF2EX operator/(const GF2EX& a, GF2 b)
509   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
510
511inline GF2EX operator/(const GF2EX& a, long b)
512   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
513
514inline GF2EX& operator/=(GF2EX& x, const GF2EX& b)
515   { div(x, x, b); return x; }
516
517inline GF2EX& operator/=(GF2EX& x, const GF2E& b)
518   { div(x, x, b); return x; }
519
520inline GF2EX& operator/=(GF2EX& x, GF2 b)
521   { div(x, x, b); return x; }
522
523inline GF2EX& operator/=(GF2EX& x, long b)
524   { div(x, x, b); return x; }
525
526
527inline GF2EX operator%(const GF2EX& a, const GF2EX& b)
528   { GF2EX x; rem(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
529
530inline GF2EX& operator%=(GF2EX& x, const GF2EX& b)
531   { rem(x, x, b); return x; }
532
533
534
535
536/***********************************************************
537
538                         GCD's
539
540************************************************************/
541
542
543void GCD(GF2EX& x, const GF2EX& a, const GF2EX& b);
544inline GF2EX GCD(const GF2EX& a, const GF2EX& b)
545   { GF2EX x; GCD(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
546
547// x = GCD(a, b),  x is always monic (or zero if a==b==0).
548
549void XGCD(GF2EX& d, GF2EX& s, GF2EX& t, const GF2EX& a, const GF2EX& b);
550// d = gcd(a,b), a s + b t = d
551
552
553/*************************************************************
554
555             Modular Arithmetic without pre-conditioning
556
557**************************************************************/
558
559// arithmetic mod f.
560// all inputs and outputs are polynomials of degree less than deg(f).
561// ASSUMPTION: f is assumed monic, and deg(f) > 0.
562// NOTE: if you want to do many computations with a fixed f,
563//       use the GF2EXModulus data structure and associated routines below.
564
565
566
567void MulMod(GF2EX& x, const GF2EX& a, const GF2EX& b, const GF2EX& f);
568inline GF2EX MulMod(const GF2EX& a, const GF2EX& b, const GF2EX& f)
569   { GF2EX x; MulMod(x, a, b, f); NTL_OPT_RETURN(GF2EX, x); }
570// x = (a * b) % f
571
572void SqrMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
573inline GF2EX SqrMod(const GF2EX& a, const GF2EX& f)
574   { GF2EX x; SqrMod(x, a, f); NTL_OPT_RETURN(GF2EX, x); }
575// x = a^2 % f
576
577void MulByXMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
578inline GF2EX MulByXMod(const GF2EX& a, const GF2EX& f)
579   { GF2EX x; MulByXMod(x, a, f); NTL_OPT_RETURN(GF2EX, x); }
580// x = (a * X) mod f
581
582void InvMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
583inline GF2EX InvMod(const GF2EX& a, const GF2EX& f)
584   { GF2EX x; InvMod(x, a, f); NTL_OPT_RETURN(GF2EX, x); }
585// x = a^{-1} % f, error is a is not invertible
586
587long InvModStatus(GF2EX& x, const GF2EX& a, const GF2EX& f);
588// if (a, f) = 1, returns 0 and sets x = a^{-1} % f
589// otherwise, returns 1 and sets x = (a, f)
590
591
592
593
594
595/******************************************************************
596
597        Modular Arithmetic with Pre-conditioning
598
599*******************************************************************/
600
601
602// If you need to do a lot of arithmetic modulo a fixed f,
603// build GF2EXModulus F for f.  This pre-computes information about f
604// that speeds up the computation a great deal.
605
606class GF2EXModulus {
607public:
608   GF2EXModulus();
609   ~GF2EXModulus() { }
610
611   GF2EXModulus(const GF2EX& ff);
612
613   GF2EX f;   // the modulus
614
615   operator const GF2EX& () const { return f; }
616   const GF2EX& val() const { return f; }
617
618   long n; //  deg(f)
619
620   long method; // GF2EX_MOD_PLAIN or GF2EX_MOD_MUL
621
622   GF2EX h0;
623   GF2E hlc;
624   GF2EX f0;
625
626   vec_GF2E tracevec;
627
628}; 
629
630
631inline long deg(const GF2EXModulus& F) { return F.n; }
632
633void build(GF2EXModulus& F, const GF2EX& f);
634
635
636
637void rem(GF2EX& r, const GF2EX& a, const GF2EXModulus& F);
638   
639void DivRem(GF2EX& q, GF2EX& r, const GF2EX& a, const GF2EXModulus& F);
640
641void div(GF2EX& q, const GF2EX& a, const GF2EXModulus& F);
642
643void MulMod(GF2EX& c, const GF2EX& a, const GF2EX& b, const GF2EXModulus& F);
644inline GF2EX MulMod(const GF2EX& a, const GF2EX& b, const GF2EXModulus& F)
645   { GF2EX x; MulMod(x, a, b, F); NTL_OPT_RETURN(GF2EX, x); }
646
647void SqrMod(GF2EX& c, const GF2EX& a, const GF2EXModulus& F);
648inline GF2EX SqrMod(const GF2EX& a, const GF2EXModulus& F)
649   { GF2EX x; SqrMod(x, a, F); NTL_OPT_RETURN(GF2EX, x); }
650
651
652void PowerMod(GF2EX& h, const GF2EX& g, const ZZ& e, const GF2EXModulus& F);
653
654inline void PowerMod(GF2EX& h, const GF2EX& g, long e, const GF2EXModulus& F)
655   { PowerMod(h, g, ZZ_expo(e), F); }
656
657inline GF2EX PowerMod(const GF2EX& g, const ZZ& e, const GF2EXModulus& F)
658   { GF2EX x; PowerMod(x, g, e, F);  NTL_OPT_RETURN(GF2EX, x); }
659
660inline GF2EX PowerMod(const GF2EX& g, long e, const GF2EXModulus& F)
661   { GF2EX x; PowerMod(x, g, e, F);  NTL_OPT_RETURN(GF2EX, x); }
662
663void PowerXMod(GF2EX& hh, const ZZ& e, const GF2EXModulus& F);
664
665inline void PowerXMod(GF2EX& h, long e, const GF2EXModulus& F)
666   { PowerXMod(h, ZZ_expo(e), F); }
667
668
669inline GF2EX PowerXMod(const ZZ& e, const GF2EXModulus& F)
670   { GF2EX x; PowerXMod(x, e, F);  NTL_OPT_RETURN(GF2EX, x); }
671
672inline GF2EX PowerXMod(long e, const GF2EXModulus& F)
673   { GF2EX x; PowerXMod(x, e, F);  NTL_OPT_RETURN(GF2EX, x); }
674
675inline GF2EX operator%(const GF2EX& a, const GF2EXModulus& F)
676   { GF2EX x; rem(x, a, F); NTL_OPT_RETURN(GF2EX, x); }
677
678inline GF2EX& operator%=(GF2EX& x, const GF2EXModulus& F)
679   { rem(x, x, F); return x; }
680
681inline GF2EX operator/(const GF2EX& a, const GF2EXModulus& F)
682   { GF2EX x; div(x, a, F); NTL_OPT_RETURN(GF2EX, x); }
683
684inline GF2EX& operator/=(GF2EX& x, const GF2EXModulus& F)
685   { div(x, x, F); return x; }
686
687
688
689/*****************************************************************
690
691                       vectors of GF2EX's
692
693*****************************************************************/
694
695
696
697NTL_vector_decl(GF2EX,vec_GF2EX)
698
699NTL_eq_vector_decl(GF2EX,vec_GF2EX)
700
701
702
703/*******************************************************
704
705              Evaluation and related problems
706
707********************************************************/
708
709
710void BuildFromRoots(GF2EX& x, const vec_GF2E& a);
711inline GF2EX BuildFromRoots(const vec_GF2E& a)
712   { GF2EX x; BuildFromRoots(x, a); NTL_OPT_RETURN(GF2EX, x); }
713// computes the polynomial (X-a[0]) ... (X-a[n-1]), where n = a.length()
714
715
716void eval(GF2E& b, const GF2EX& f, const GF2E& a);
717inline GF2E eval(const GF2EX& f, const GF2E& a)
718   { GF2E x; eval(x, f, a); NTL_OPT_RETURN(GF2E, x); }
719// b = f(a)
720
721void eval(vec_GF2E& b, const GF2EX& f, const vec_GF2E& a);
722inline vec_GF2E eval(const GF2EX& f, const vec_GF2E& a)
723   { vec_GF2E x; eval(x, f, a); NTL_OPT_RETURN(vec_GF2E, x); }
724//  b[i] = f(a[i])
725
726inline void eval(GF2E& b, const GF2X& f, const GF2E& a)
727   { conv(b, CompMod(f, rep(a), GF2E::modulus())); }
728   
729inline GF2E eval(const GF2X& f, const GF2E& a)
730   { GF2E x; eval(x, f, a); NTL_OPT_RETURN(GF2E, x); }
731// b = f(a)
732
733
734void interpolate(GF2EX& f, const vec_GF2E& a, const vec_GF2E& b);
735inline GF2EX interpolate(const vec_GF2E& a, const vec_GF2E& b)
736   { GF2EX x; interpolate(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
737// computes f such that f(a[i]) = b[i]
738
739
740
741
742/**********************************************************
743
744         Modular Composition and Minimal Polynomials
745
746***********************************************************/
747
748
749// algorithms for computing g(h) mod f
750
751
752
753
754void CompMod(GF2EX& x, const GF2EX& g, const GF2EX& h, const GF2EXModulus& F);
755inline GF2EX
756CompMod(const GF2EX& g, const GF2EX& h, const GF2EXModulus& F)
757   { GF2EX x; CompMod(x, g, h, F); NTL_OPT_RETURN(GF2EX, x); }
758// x = g(h) mod f
759
760void Comp2Mod(GF2EX& x1, GF2EX& x2, const GF2EX& g1, const GF2EX& g2,
761              const GF2EX& h, const GF2EXModulus& F);
762// xi = gi(h) mod f (i=1,2)
763
764void Comp3Mod(GF2EX& x1, GF2EX& x2, GF2EX& x3, 
765              const GF2EX& g1, const GF2EX& g2, const GF2EX& g3,
766              const GF2EX& h, const GF2EXModulus& F);
767// xi = gi(h) mod f (i=1..3)
768
769
770
771// The routine build (see below) which is implicitly called
772// by the various compose and UpdateMap routines builds a table
773// of polynomials. 
774// If GF2EXArgBound > 0, then the table is limited in
775// size to approximamtely that many KB.
776// If GF2EXArgBound <= 0, then it is ignored, and space is allocated
777// so as to maximize speed.
778// Initially, GF2EXArgBound = 0.
779
780
781// If a single h is going to be used with many g's
782// then you should build a GF2EXArgument for h,
783// and then use the compose routine below.
784// build computes and stores h, h^2, ..., h^m mod f.
785// After this pre-computation, composing a polynomial of degree
786// roughly n with h takes n/m multiplies mod f, plus n^2
787// scalar multiplies.
788// Thus, increasing m increases the space requirement and the pre-computation
789// time, but reduces the composition time.
790// If GF2EXArgBound > 0, a table of size less than m may be built.
791
792struct GF2EXArgument {
793   vec_GF2EX H;
794};
795
796extern long GF2EXArgBound;
797
798
799void build(GF2EXArgument& H, const GF2EX& h, const GF2EXModulus& F, long m);
800
801// m must be > 0, otherwise an error is raised
802
803void CompMod(GF2EX& x, const GF2EX& g, const GF2EXArgument& H, 
804             const GF2EXModulus& F);
805
806inline GF2EX
807CompMod(const GF2EX& g, const GF2EXArgument& H, const GF2EXModulus& F)
808   { GF2EX x; CompMod(x, g, H, F); NTL_OPT_RETURN(GF2EX, x); }
809   
810
811
812
813void MinPolySeq(GF2EX& h, const vec_GF2E& a, long m);
814inline GF2EX MinPolySeq(const vec_GF2E& a, long m)
815   { GF2EX x; MinPolySeq(x, a, m); NTL_OPT_RETURN(GF2EX, x); }
816
817
818void MinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F);
819inline GF2EX MinPolyMod(const GF2EX& g, const GF2EXModulus& F)
820   { GF2EX x; MinPolyMod(x, g, F); NTL_OPT_RETURN(GF2EX, x); }
821
822
823void MinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F, long m);
824inline GF2EX MinPolyMod(const GF2EX& g, const GF2EXModulus& F, long m)
825   { GF2EX x; MinPolyMod(x, g, F, m); NTL_OPT_RETURN(GF2EX, x); }
826
827void ProbMinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F);
828inline GF2EX ProbMinPolyMod(const GF2EX& g, const GF2EXModulus& F)
829   { GF2EX x; ProbMinPolyMod(x, g, F); NTL_OPT_RETURN(GF2EX, x); }
830
831void ProbMinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F, long m);
832inline GF2EX ProbMinPolyMod(const GF2EX& g, const GF2EXModulus& F, long m)
833   { GF2EX x; ProbMinPolyMod(x, g, F, m); NTL_OPT_RETURN(GF2EX, x); }
834
835void IrredPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F);
836inline GF2EX IrredPolyMod(const GF2EX& g, const GF2EXModulus& F)
837   { GF2EX x; IrredPolyMod(x, g, F); NTL_OPT_RETURN(GF2EX, x); }
838
839void IrredPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F, long m);
840inline GF2EX IrredPolyMod(const GF2EX& g, const GF2EXModulus& F, long m)
841   { GF2EX x; IrredPolyMod(x, g, F, m); NTL_OPT_RETURN(GF2EX, x); }
842
843
844struct GF2EXTransMultiplier {
845   GF2EX f0, fbi, b;
846   long shamt, shamt_fbi, shamt_b;
847};
848
849void build(GF2EXTransMultiplier& B, const GF2EX& b, const GF2EXModulus& F);
850
851void TransMulMod(GF2EX& x, const GF2EX& a, const GF2EXTransMultiplier& B,
852               const GF2EXModulus& F);
853
854void UpdateMap(vec_GF2E& x, const vec_GF2E& a, 
855         const GF2EXTransMultiplier& B, const GF2EXModulus& F);
856
857inline vec_GF2E UpdateMap(const vec_GF2E& a,
858         const GF2EXTransMultiplier& B, const GF2EXModulus& F)
859   { vec_GF2E x; UpdateMap(x, a, B, F); NTL_OPT_RETURN(vec_GF2E, x); }
860
861void ProjectPowers(vec_GF2E& x, const vec_GF2E& a, long k, 
862                   const GF2EXArgument& H, const GF2EXModulus& F);
863inline vec_GF2E ProjectPowers(const vec_GF2E& a, long k, 
864                   const GF2EXArgument& H, const GF2EXModulus& F)
865   { vec_GF2E x; ProjectPowers(x, a, k, H, F); NTL_OPT_RETURN(vec_GF2E, x); }
866
867void ProjectPowers(vec_GF2E& x, const vec_GF2E& a, long k, const GF2EX& h, 
868                   const GF2EXModulus& F);
869inline vec_GF2E ProjectPowers(const vec_GF2E& a, long k, 
870                   const GF2EX& H, const GF2EXModulus& F)
871   { vec_GF2E x; ProjectPowers(x, a, k, H, F); NTL_OPT_RETURN(vec_GF2E, x); }
872
873inline void project(GF2E& x, const vec_GF2E& a, const GF2EX& b)
874   { InnerProduct(x, a, b.rep); }
875
876inline GF2E project(const vec_GF2E& a, const GF2EX& b)
877   { GF2E x; InnerProduct(x, a, b.rep); NTL_OPT_RETURN(GF2E, x); }
878
879/**********************************************************
880
881         Modular Composition and Minimal Polynomials
882                         in towers
883
884***********************************************************/
885
886// composition
887
888void CompTower(GF2EX& x, const GF2X& g, const GF2EXArgument& A,
889             const GF2EXModulus& F);
890
891inline GF2EX CompTower(const GF2X& g, const GF2EXArgument& A,
892             const GF2EXModulus& F)
893   { GF2EX x; CompTower(x, g, A, F); NTL_OPT_RETURN(GF2EX, x); }
894
895void CompTower(GF2EX& x, const GF2X& g, const GF2EX& h,
896             const GF2EXModulus& F);
897
898inline GF2EX CompTower(const GF2X& g, const GF2EX& h,
899             const GF2EXModulus& F)
900   { GF2EX x; CompTower(x, g, h, F); NTL_OPT_RETURN(GF2EX, x); }
901
902// prob min poly
903
904void ProbMinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
905                      long m);
906
907inline GF2X ProbMinPolyTower(const GF2EX& g, const GF2EXModulus& F,
908                      long m)
909   { GF2X x; ProbMinPolyTower(x, g, F, m); NTL_OPT_RETURN(GF2X, x); }
910
911inline void ProbMinPolyTower(GF2X& h, const GF2EX& g, 
912                             const GF2EXModulus& F)
913   { ProbMinPolyTower(h, g, F, deg(F)*GF2E::degree()); }
914
915inline GF2X ProbMinPolyTower(const GF2EX& g, const GF2EXModulus& F)
916   { GF2X x; ProbMinPolyTower(x, g, F); NTL_OPT_RETURN(GF2X, x); }
917
918
919// min poly
920
921
922void MinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
923                      long m);
924
925inline GF2X MinPolyTower(const GF2EX& g, const GF2EXModulus& F,
926                      long m)
927   { GF2X x; MinPolyTower(x, g, F, m); NTL_OPT_RETURN(GF2X, x); }
928
929inline void MinPolyTower(GF2X& h, const GF2EX& g, 
930                             const GF2EXModulus& F)
931   { MinPolyTower(h, g, F, deg(F)*GF2E::degree()); }
932
933inline GF2X MinPolyTower(const GF2EX& g, const GF2EXModulus& F)
934   { GF2X x; MinPolyTower(x, g, F); NTL_OPT_RETURN(GF2X, x); }
935
936// irred poly
937
938
939void IrredPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
940                      long m);
941
942inline GF2X IrredPolyTower(const GF2EX& g, const GF2EXModulus& F,
943                      long m)
944   { GF2X x; IrredPolyTower(x, g, F, m); NTL_OPT_RETURN(GF2X, x); }
945
946inline void IrredPolyTower(GF2X& h, const GF2EX& g, 
947                             const GF2EXModulus& F)
948   { IrredPolyTower(h, g, F, deg(F)*GF2E::degree()); }
949
950inline GF2X IrredPolyTower(const GF2EX& g, const GF2EXModulus& F)
951   { GF2X x; IrredPolyTower(x, g, F); NTL_OPT_RETURN(GF2X, x); }
952
953
954
955/*****************************************************************
956
957                   Traces, norms, resultants
958
959******************************************************************/
960
961void TraceVec(vec_GF2E& S, const GF2EX& f);
962
963inline vec_GF2E TraceVec(const GF2EX& f)
964   { vec_GF2E x; TraceVec(x, f); NTL_OPT_RETURN(vec_GF2E, x); }
965
966
967void TraceMod(GF2E& x, const GF2EX& a, const GF2EXModulus& F);
968
969inline GF2E TraceMod(const GF2EX& a, const GF2EXModulus& F)
970   { GF2E x; TraceMod(x, a, F); NTL_OPT_RETURN(GF2E, x); }
971
972void TraceMod(GF2E& x, const GF2EX& a, const GF2EX& f);
973
974inline GF2E TraceMod(const GF2EX& a, const GF2EX& f)
975   { GF2E x; TraceMod(x, a, f); NTL_OPT_RETURN(GF2E, x); }
976
977
978
979
980
981void NormMod(GF2E& x, const GF2EX& a, const GF2EX& f);
982
983inline GF2E NormMod(const GF2EX& a, const GF2EX& f)
984   { GF2E x; NormMod(x, a, f); NTL_OPT_RETURN(GF2E, x); }
985
986void resultant(GF2E& rres, const GF2EX& a, const GF2EX& b);
987
988inline GF2E resultant(const GF2EX& a, const GF2EX& b)
989   { GF2E x; resultant(x, a, b); NTL_OPT_RETURN(GF2E, x); }
990
991
992NTL_CLOSE_NNS
993
994#endif
Note: See TracBrowser for help on using the repository browser.