source: git/ntl/include/NTL/GF2EX.h @ 92c0ac

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