source: git/ntl/include/NTL/GF2EX.h @ a703156

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