source: git/ntl/doc/GF2EX.txt @ 2cfffe

spielwiese
Last change on this file since 2cfffe was 2cfffe, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6316, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6317 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 25.0 KB
Line 
1
2/**************************************************************************\
3
4MODULE: GF2EX
5
6SUMMARY:
7
8The class GF2EX represents polynomials over GF2E,
9and so can be used, for example, for arithmentic in GF(2^n)[X].
10However, except where mathematically necessary (e.g., GCD computations),
11GF2E need not be a field.
12
13\**************************************************************************/
14
15#include <NTL/GF2E.h>
16#include <NTL/vec_GF2E.h>
17
18class GF2EX {
19public:
20
21   GF2EX(); // initial value 0
22
23   GF2EX(const GF2EX& a); // copy
24
25   GF2EX& operator=(const GF2EX& a); // assignment
26   GF2EX& operator=(const GF2E& a);
27   GF2EX& operator=(GF2 a);
28   GF2EX& operator=(long a);
29
30   ~GF2EX(); // destructor
31
32   GF2EX(long i, const GF2E& c); // initilaize to X^i*c
33   GF2EX(long i, GF2 c);
34   GF2EX(long i, long c);
35
36   
37};
38
39
40
41
42
43
44/**************************************************************************\
45
46                                  Comparison
47
48\**************************************************************************/
49
50
51long operator==(const GF2EX& a, const GF2EX& b);
52long operator!=(const GF2EX& a, const GF2EX& b);
53
54long IsZero(const GF2EX& a); // test for 0
55long IsOne(const GF2EX& a); // test for 1
56
57// PROMOTIONS: ==, != promote {long,GF2,GF2E} to GF2EX on (a, b).
58
59/**************************************************************************\
60
61                                   Addition
62
63\**************************************************************************/
64
65// operator notation:
66
67GF2EX operator+(const GF2EX& a, const GF2EX& b);
68GF2EX operator-(const GF2EX& a, const GF2EX& b);
69GF2EX operator-(const GF2EX& a);
70
71GF2EX& operator+=(GF2EX& x, const GF2EX& a);
72GF2EX& operator+=(GF2EX& x, const GF2E& a);
73GF2EX& operator+=(GF2EX& x, GF2 a);
74GF2EX& operator+=(GF2EX& x, long a);
75
76
77GF2EX& operator++(GF2EX& x);  // prefix
78void operator++(GF2EX& x, int);  // postfix
79
80GF2EX& operator-=(GF2EX& x, const GF2EX& a);
81GF2EX& operator-=(GF2EX& x, const GF2E& a);
82GF2EX& operator-=(GF2EX& x, GF2 a);
83GF2EX& operator-=(GF2EX& x, long a);
84
85GF2EX& operator--(GF2EX& x);  // prefix
86void operator--(GF2EX& x, int);  // postfix
87
88// procedural versions:
89
90void add(GF2EX& x, const GF2EX& a, const GF2EX& b); // x = a + b
91void sub(GF2EX& x, const GF2EX& a, const GF2EX& b); // x = a - b
92void negate(GF2EX& x, const GF2EX& a); // x = - a
93
94// PROMOTIONS: +, -, add, sub promote {long,GF2,GF2E} to GF2EX on (a, b).
95
96
97
98/**************************************************************************\
99
100                               Multiplication
101
102\**************************************************************************/
103
104// operator notation:
105
106GF2EX operator*(const GF2EX& a, const GF2EX& b);
107
108GF2EX& operator*=(GF2EX& x, const GF2EX& a);
109GF2EX& operator*=(GF2EX& x, const GF2E& a);
110GF2EX& operator*=(GF2EX& x, GF2 a);
111GF2EX& operator*=(GF2EX& x, long a);
112
113
114// procedural versions:
115
116
117void mul(GF2EX& x, const GF2EX& a, const GF2EX& b); // x = a * b
118
119void sqr(GF2EX& x, const GF2EX& a); // x = a^2
120GF2EX sqr(const GF2EX& a);
121
122// PROMOTIONS: *, mul promote {long,GF2,GF2E} to GF2EX on (a, b).
123
124void power(GF2EX& x, const GF2EX& a, long e);  // x = a^e (e >= 0)
125GF2EX power(const GF2EX& a, long e);
126
127
128/**************************************************************************\
129
130                               Shift Operations
131
132LeftShift by n means multiplication by X^n
133RightShift by n means division by X^n
134
135A negative shift amount reverses the direction of the shift.
136
137\**************************************************************************/
138
139// operator notation:
140
141GF2EX operator<<(const GF2EX& a, long n);
142GF2EX operator>>(const GF2EX& a, long n);
143
144GF2EX& operator<<=(GF2EX& x, long n);
145GF2EX& operator>>=(GF2EX& x, long n);
146
147// procedural versions:
148
149void LeftShift(GF2EX& x, const GF2EX& a, long n);
150GF2EX LeftShift(const GF2EX& a, long n);
151
152void RightShift(GF2EX& x, const GF2EX& a, long n);
153GF2EX RightShift(const GF2EX& a, long n);
154
155
156
157/**************************************************************************\
158
159                                  Division
160
161\**************************************************************************/
162
163// operator notation:
164
165GF2EX operator/(const GF2EX& a, const GF2EX& b);
166GF2EX operator/(const GF2EX& a, const GF2E& b);
167GF2EX operator/(const GF2EX& a, GF2 b);
168GF2EX operator/(const GF2EX& a, long b);
169
170GF2EX operator%(const GF2EX& a, const GF2EX& b);
171
172GF2EX& operator/=(GF2EX& x, const GF2EX& a);
173GF2EX& operator/=(GF2EX& x, const GF2E& a);
174GF2EX& operator/=(GF2EX& x, GF2 a);
175GF2EX& operator/=(GF2EX& x, long a);
176
177GF2EX& operator%=(GF2EX& x, const GF2EX& a);
178
179// procedural versions:
180
181
182void DivRem(GF2EX& q, GF2EX& r, const GF2EX& a, const GF2EX& b);
183// q = a/b, r = a%b
184
185void div(GF2EX& q, const GF2EX& a, const GF2EX& b);
186void div(GF2EX& q, const GF2EX& a, const GF2E& b);
187void div(GF2EX& q, const GF2EX& a, GF2 b);
188void div(GF2EX& q, const GF2EX& a, long b);
189// q = a/b
190
191void rem(GF2EX& r, const GF2EX& a, const GF2EX& b);
192// r = a%b
193
194long divide(GF2EX& q, const GF2EX& a, const GF2EX& b);
195// if b | a, sets q = a/b and returns 1; otherwise returns 0
196
197long divide(const GF2EX& a, const GF2EX& b);
198// if b | a, sets q = a/b and returns 1; otherwise returns 0
199
200
201/**************************************************************************\
202
203                                   GCD's
204
205These routines are intended for use when GF2E is a field.
206
207\**************************************************************************/
208
209
210void GCD(GF2EX& x, const GF2EX& a, const GF2EX& b);
211GF2EX GCD(const GF2EX& a, const GF2EX& b);
212// x = GCD(a, b),  x is always monic (or zero if a==b==0).
213
214
215void XGCD(GF2EX& d, GF2EX& s, GF2EX& t, const GF2EX& a, const GF2EX& b);
216// d = gcd(a,b), a s + b t = d
217
218
219/**************************************************************************\
220
221                                  Input/Output
222
223I/O format:
224
225   [a_0 a_1 ... a_n],
226
227represents the polynomial a_0 + a_1*X + ... + a_n*X^n.
228
229On output, all coefficients will be polynomials of degree < GF2E::degree() and
230a_n not zero (the zero polynomial is [ ]).  On input, the coefficients
231are arbitrary polynomials which are reduced modulo GF2E::modulus(), and leading
232zeros stripped.
233
234\**************************************************************************/
235
236istream& operator>>(istream& s, GF2EX& x);
237ostream& operator<<(ostream& s, const GF2EX& a);
238
239
240/**************************************************************************\
241
242                              Some utility routines
243
244\**************************************************************************/
245
246long deg(const GF2EX& a);  // return deg(a); deg(0) == -1.
247
248const GF2E& coeff(const GF2EX& a, long i);
249// returns a read-only reference to the coefficient of X^i, or zero if
250// i not in range
251
252const GF2E& LeadCoeff(const GF2EX& a);
253// read-only reference to leading term of a, or zero if a == 0
254
255const GF2E& ConstTerm(const GF2EX& a);
256// read-only reference to constant term of a, or zero if a == 0
257
258void SetCoeff(GF2EX& x, long i, const GF2E& a);
259void SetCoeff(GF2EX& x, long i, GF2 a);
260void SetCoeff(GF2EX& x, long i, long a);
261// makes coefficient of X^i equal to a;  error is raised if i < 0
262
263void SetCoeff(GF2EX& x, long i);
264// makes coefficient of X^i equal to 1;  error is raised if i < 0
265
266void SetX(GF2EX& x); // x is set to the monomial X
267
268long IsX(const GF2EX& a); // test if x = X
269
270void diff(GF2EX& x, const GF2EX& a); // x = derivative of a
271GF2EX diff(const GF2EX& a);
272
273void MakeMonic(GF2EX& x);
274// if x != 0 makes x into its monic associate; LeadCoeff(x) must be
275// invertible in this case
276
277void reverse(GF2EX& x, const GF2EX& a, long hi);
278GF2EX reverse(const GF2EX& a, long hi);
279
280void reverse(GF2EX& x, const GF2EX& a);
281GF2EX reverse(const GF2EX& a);
282
283// x = reverse of a[0]..a[hi] (hi >= -1);
284// hi defaults to deg(a) in second version
285
286void VectorCopy(vec_GF2E& x, const GF2EX& a, long n);
287vec_GF2E VectorCopy(const GF2EX& a, long n);
288// x = copy of coefficient vector of a of length exactly n.
289// input is truncated or padded with zeroes as appropriate.
290
291
292
293
294/**************************************************************************\
295
296                             Random Polynomials
297
298\**************************************************************************/
299
300void random(GF2EX& x, long n);
301GF2EX random_GF2EX(long n);
302// x = random polynomial of degree < n
303
304
305/**************************************************************************\
306
307                    Polynomial Evaluation and related problems
308
309\**************************************************************************/
310
311
312void BuildFromRoots(GF2EX& x, const vec_GF2E& a);
313GF2EX BuildFromRoots(const vec_GF2E& a);
314// computes the polynomial (X-a[0]) ... (X-a[n-1]), where n = a.length()
315
316void eval(GF2E& b, const GF2EX& f, const GF2E& a);
317GF2E eval(const GF2EX& f, const GF2E& a);
318// b = f(a)
319
320void eval(GF2E& b, const GF2X& f, const GF2E& a);
321GF2E eval(const GF2EX& f, const GF2E& a);
322// b = f(a); uses ModComp algorithm for GF2X
323
324void eval(vec_GF2E& b, const GF2EX& f, const vec_GF2E& a);
325vec_GF2E eval(const GF2EX& f, const vec_GF2E& a);
326//  b.SetLength(a.length()); b[i] = f(a[i]) for 0 <= i < a.length()
327
328void interpolate(GF2EX& f, const vec_GF2E& a, const vec_GF2E& b);
329GF2EX interpolate(const vec_GF2E& a, const vec_GF2E& b);
330// interpolates the polynomial f satisfying f(a[i]) = b[i]. 
331
332/**************************************************************************\
333
334                       Arithmetic mod X^n
335
336Required: n >= 0; otherwise, an error is raised.
337
338\**************************************************************************/
339
340void trunc(GF2EX& x, const GF2EX& a, long n); // x = a % X^n
341GF2EX trunc(const GF2EX& a, long n);
342
343void MulTrunc(GF2EX& x, const GF2EX& a, const GF2EX& b, long n);
344GF2EX MulTrunc(const GF2EX& a, const GF2EX& b, long n);
345// x = a * b % X^n
346
347void SqrTrunc(GF2EX& x, const GF2EX& a, long n);
348GF2EX SqrTrunc(const GF2EX& a, long n);
349// x = a^2 % X^n
350
351void InvTrunc(GF2EX& x, const GF2EX& a, long n);
352GF2EX InvTrunc(GF2EX& x, const GF2EX& a, long n);
353// computes x = a^{-1} % X^m.  Must have ConstTerm(a) invertible.
354
355/**************************************************************************\
356
357                Modular Arithmetic (without pre-conditioning)
358
359Arithmetic mod f.
360
361All inputs and outputs are polynomials of degree less than deg(f), and
362deg(f) > 0.
363
364
365NOTE: if you want to do many computations with a fixed f, use the
366GF2EXModulus data structure and associated routines below for better
367performance.
368
369\**************************************************************************/
370
371void MulMod(GF2EX& x, const GF2EX& a, const GF2EX& b, const GF2EX& f);
372GF2EX MulMod(const GF2EX& a, const GF2EX& b, const GF2EX& f);
373// x = (a * b) % f
374
375void SqrMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
376GF2EX SqrMod(const GF2EX& a, const GF2EX& f);
377// x = a^2 % f
378
379void MulByXMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
380GF2EX MulByXMod(const GF2EX& a, const GF2EX& f);
381// x = (a * X) mod f
382
383void InvMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
384GF2EX InvMod(const GF2EX& a, const GF2EX& f);
385// x = a^{-1} % f, error is a is not invertible
386
387long InvModStatus(GF2EX& x, const GF2EX& a, const GF2EX& f);
388// if (a, f) = 1, returns 0 and sets x = a^{-1} % f; otherwise,
389// returns 1 and sets x = (a, f)
390
391
392/**************************************************************************\
393
394                     Modular Arithmetic with Pre-Conditioning
395
396If you need to do a lot of arithmetic modulo a fixed f, build
397GF2EXModulus F for f.  This pre-computes information about f that
398speeds up subsequent computations.
399
400As an example, the following routine the product modulo f of a vector
401of polynomials.
402
403#include <NTL/GF2EX.h>
404
405void product(GF2EX& x, const vec_GF2EX& v, const GF2EX& f)
406{
407   GF2EXModulus F(f);
408   GF2EX res;
409   res = 1;
410   long i;
411   for (i = 0; i < v.length(); i++)
412      MulMod(res, res, v[i], F);
413   x = res;
414}
415
416NOTE: A GF2EX may be used wherever a GF2EXModulus is required,
417and a GF2EXModulus may be used wherever a GF2EX is required.
418
419
420\**************************************************************************/
421
422class GF2EXModulus {
423public:
424   GF2EXModulus(); // initially in an unusable state
425
426   GF2EXModulus(const GF2EX& f); // initialize with f, deg(f) > 0
427
428   GF2EXModulus(const GF2EXModulus&); // copy
429
430   GF2EXModulus& operator=(const GF2EXModulus&); // assignment
431
432   ~GF2EXModulus(); // destructor
433
434   operator const GF2EX& () const; // implicit read-only access to f
435
436   const GF2EX& val() const; // explicit read-only access to f
437};
438
439void build(GF2EXModulus& F, const GF2EX& f);
440// pre-computes information about f and stores it in F.  Must have
441// deg(f) > 0.  Note that the declaration GF2EXModulus F(f) is
442// equivalent to GF2EXModulus F; build(F, f).
443
444// In the following, f refers to the polynomial f supplied to the
445// build routine, and n = deg(f).
446
447
448long deg(const GF2EXModulus& F);  // return n=deg(f)
449
450void MulMod(GF2EX& x, const GF2EX& a, const GF2EX& b, const GF2EXModulus& F);
451GF2EX MulMod(const GF2EX& a, const GF2EX& b, const GF2EXModulus& F);
452// x = (a * b) % f; deg(a), deg(b) < n
453
454void SqrMod(GF2EX& x, const GF2EX& a, const GF2EXModulus& F);
455GF2EX SqrMod(const GF2EX& a, const GF2EXModulus& F);
456// x = a^2 % f; deg(a) < n
457
458void PowerMod(GF2EX& x, const GF2EX& a, const ZZ& e, const GF2EXModulus& F);
459GF2EX PowerMod(const GF2EX& a, const ZZ& e, const GF2EXModulus& F);
460
461void PowerMod(GF2EX& x, const GF2EX& a, long e, const GF2EXModulus& F);
462GF2EX PowerMod(const GF2EX& a, long e, const GF2EXModulus& F);
463
464// x = a^e % f; e >= 0, deg(a) < n.  Uses a sliding window algorithm.
465// (e may be negative)
466
467void PowerXMod(GF2EX& x, const ZZ& e, const GF2EXModulus& F);
468GF2EX PowerXMod(const ZZ& e, const GF2EXModulus& F);
469
470void PowerXMod(GF2EX& x, long e, const GF2EXModulus& F);
471GF2EX PowerXMod(long e, const GF2EXModulus& F);
472
473// x = X^e % f (e may be negative)
474
475void rem(GF2EX& x, const GF2EX& a, const GF2EXModulus& F);
476// x = a % f
477
478void DivRem(GF2EX& q, GF2EX& r, const GF2EX& a, const GF2EXModulus& F);
479// q = a/f, r = a%f
480
481void div(GF2EX& q, const GF2EX& a, const GF2EXModulus& F);
482// q = a/f
483
484// operator notation:
485
486GF2EX operator/(const GF2EX& a, const GF2EXModulus& F);
487GF2EX operator%(const GF2EX& a, const GF2EXModulus& F);
488
489GF2EX& operator/=(GF2EX& x, const GF2EXModulus& F);
490GF2EX& operator%=(GF2EX& x, const GF2EXModulus& F);
491
492
493
494/**************************************************************************\
495
496                             vectors of GF2EX's
497
498\**************************************************************************/
499
500NTL_vector_decl(GF2EX,vec_GF2EX)
501// vec_GF2EX
502
503NTL_eq_vector_decl(GF2EX,vec_GF2EX)
504// == and !=
505
506NTL_io_vector_decl(GF2EX,vec_GF2EX)
507// I/O operators
508
509
510
511/**************************************************************************\
512
513                              Modular Composition
514
515Modular composition is the problem of computing g(h) mod f for
516polynomials f, g, and h.
517
518The algorithm employed is that of Brent & Kung (Fast algorithms for
519manipulating formal power series, JACM 25:581-595, 1978), which uses
520O(n^{1/2}) modular polynomial multiplications, and O(n^2) scalar
521operations.
522
523
524\**************************************************************************/
525
526void CompMod(GF2EX& x, const GF2EX& g, const GF2EX& h, const GF2EXModulus& F);
527GF2EX CompMod(const GF2EX& g, const GF2EX& h,
528                    const GF2EXModulus& F);
529
530// x = g(h) mod f; deg(h) < n
531
532void Comp2Mod(GF2EX& x1, GF2EX& x2, const GF2EX& g1, const GF2EX& g2,
533              const GF2EX& h, const GF2EXModulus& F);
534// xi = gi(h) mod f (i=1,2); deg(h) < n.
535
536
537void Comp3Mod(GF2EX& x1, GF2EX& x2, GF2EX& x3,
538              const GF2EX& g1, const GF2EX& g2, const GF2EX& g3,
539              const GF2EX& h, const GF2EXModulus& F);
540// xi = gi(h) mod f (i=1..3); deg(h) < n.
541
542
543
544/**************************************************************************\
545
546                     Composition with Pre-Conditioning
547
548If a single h is going to be used with many g's then you should build
549a GF2EXArgument for h, and then use the compose routine below.  The
550routine build computes and stores h, h^2, ..., h^m mod f.  After this
551pre-computation, composing a polynomial of degree roughly n with h
552takes n/m multiplies mod f, plus n^2 scalar multiplies.  Thus,
553increasing m increases the space requirement and the pre-computation
554time, but reduces the composition time.
555
556\**************************************************************************/
557
558
559struct GF2EXArgument {
560   vec_GF2EX H;
561};
562
563void build(GF2EXArgument& H, const GF2EX& h, const GF2EXModulus& F, long m);
564// Pre-Computes information about h.  m > 0, deg(h) < n.
565
566void CompMod(GF2EX& x, const GF2EX& g, const GF2EXArgument& H,
567             const GF2EXModulus& F);
568
569GF2EX CompMod(const GF2EX& g, const GF2EXArgument& H,
570                    const GF2EXModulus& F);
571
572extern long GF2EXArgBound;
573
574// Initially 0.  If this is set to a value greater than zero, then
575// composition routines will allocate a table of no than about
576// GF2EXArgBound KB.  Setting this value affects all compose routines
577// and the power projection and minimal polynomial routines below,
578// and indirectly affects many routines in GF2EXFactoring.
579
580/**************************************************************************\
581
582                     power projection routines
583
584\**************************************************************************/
585
586void project(GF2E& x, const GF2EVector& a, const GF2EX& b);
587GF2E project(const GF2EVector& a, const GF2EX& b);
588// x = inner product of a with coefficient vector of b
589
590
591void ProjectPowers(vec_GF2E& x, const vec_GF2E& a, long k,
592                   const GF2EX& h, const GF2EXModulus& F);
593
594vec_GF2E ProjectPowers(const vec_GF2E& a, long k,
595                   const GF2EX& h, const GF2EXModulus& F);
596
597// Computes the vector
598
599//    project(a, 1), project(a, h), ..., project(a, h^{k-1} % f). 
600
601// This operation is the "transpose" of the modular composition operation.
602
603void ProjectPowers(vec_GF2E& x, const vec_GF2E& a, long k,
604                   const GF2EXArgument& H, const GF2EXModulus& F);
605
606vec_GF2E ProjectPowers(const vec_GF2E& a, long k,
607                   const GF2EXArgument& H, const GF2EXModulus& F);
608
609// same as above, but uses a pre-computed GF2EXArgument
610
611class GF2EXTransMultiplier { /* ... */ };
612
613void build(GF2EXTransMultiplier& B, const GF2EX& b, const GF2EXModulus& F);
614
615
616
617void UpdateMap(vec_GF2E& x, const vec_GF2E& a,
618               const GF2EXMultiplier& B, const GF2EXModulus& F);
619
620vec_GF2E UpdateMap(const vec_GF2E& a,
621               const GF2EXMultiplier& B, const GF2EXModulus& F);
622
623// Computes the vector
624
625//    project(a, b), project(a, (b*X)%f), ..., project(a, (b*X^{n-1})%f)
626
627// Restriction: a.length() <= deg(F), deg(b) < deg(F).
628// This is "transposed" MulMod by B.
629// Input may have "high order" zeroes stripped.
630// Output always has high order zeroes stripped.
631
632
633/**************************************************************************\
634
635                              Minimum Polynomials
636
637These routines should be used only when GF2E is a field.
638
639All of these routines implement the algorithm from [Shoup, J. Symbolic
640Comp. 17:371-391, 1994] and [Shoup, J. Symbolic Comp. 20:363-397,
6411995], based on transposed modular composition and the
642Berlekamp/Massey algorithm.
643
644\**************************************************************************/
645
646
647void MinPolySeq(GF2EX& h, const vec_GF2E& a, long m);
648GF2EX MinPolySeq(const vec_GF2E& a, long m);
649// computes the minimum polynomial of a linealy generated sequence; m
650// is a bound on the degree of the polynomial; required: a.length() >=
651// 2*m
652
653
654void ProbMinPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F, long m);
655GF2EX ProbMinPolyMod(const GF2EX& g, const GF2EXModulus& F, long m);
656
657void ProbMinPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F);
658GF2EX ProbMinPolyMod(const GF2EX& g, const GF2EXModulus& F);
659
660// computes the monic minimal polynomial if (g mod f).  m = a bound on
661// the degree of the minimal polynomial; in the second version, this
662// argument defaults to n.  The algorithm is probabilistic, always
663// returns a divisor of the minimal polynomial, and returns a proper
664// divisor with probability at most m/2^{GF2E::degree()}.
665
666void MinPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F, long m);
667GF2EX MinPolyMod(const GF2EX& g, const GF2EXModulus& F, long m);
668
669void MinPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F);
670GF2EX MinPolyMod(const GF2EX& g, const GF2EXModulus& F);
671
672// same as above, but guarantees that result is correct
673
674void IrredPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F, long m);
675GF2EX IrredPolyMod(const GF2EX& g, const GF2EXModulus& F, long m);
676
677void IrredPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F);
678GF2EX IrredPolyMod(const GF2EX& g, const GF2EXModulus& F);
679
680// same as above, but assumes that f is irreducible, or at least that
681// the minimal poly of g is itself irreducible.  The algorithm is
682// deterministic (and is always correct).
683
684
685/**************************************************************************\
686
687           Composition and Minimal Polynomials in towers
688
689These are implementations of algorithms that will be described
690and analyzed in a forthcoming paper.
691
692GF2E need not be a field.
693
694\**************************************************************************/
695
696
697void CompTower(GF2EX& x, const GF2X& g, const GF2EXArgument& h,
698             const GF2EXModulus& F);
699
700GF2EX CompTower(const GF2X& g, const GF2EXArgument& h,
701             const GF2EXModulus& F);
702
703void CompTower(GF2EX& x, const GF2X& g, const GF2EX& h,
704             const GF2EXModulus& F);
705
706GF2EX CompTower(const GF2X& g, const GF2EX& h,
707             const GF2EXModulus& F);
708
709
710// x = g(h) mod f
711
712
713void ProbMinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
714                      long m);
715
716GF2X ProbMinPolyTower(const GF2EX& g, const GF2EXModulus& F, long m);
717
718void ProbMinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F);
719
720GF2X ProbMinPolyTower(const GF2EX& g, const GF2EXModulus& F);
721
722// Uses a probabilistic algorithm to compute the minimal
723// polynomial of (g mod f) over GF2.
724// The parameter m is a bound on the degree of the minimal polynomial
725// (default = deg(f)*GF2E::degree()).
726// In general, the result will be a divisor of the true minimimal
727// polynomial.  For correct results, use the MinPoly routines below.
728
729
730
731void MinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F, long m);
732
733GF2X MinPolyTower(const GF2EX& g, const GF2EXModulus& F, long m);
734
735void MinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F);
736
737GF2X MinPolyTower(const GF2EX& g, const GF2EXModulus& F);
738
739// Same as above, but result is always correct.
740
741
742void IrredPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F, long m);
743
744GF2X IrredPolyTower(const GF2EX& g, const GF2EXModulus& F, long m);
745
746void IrredPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F);
747
748GF2X IrredPolyTower(const GF2EX& g, const GF2EXModulus& F);
749
750// Same as above, but assumes the minimal polynomial is
751// irreducible, and uses a slightly faster, deterministic algorithm.
752
753
754
755/**************************************************************************\
756
757                   Traces, norms, resultants
758
759\**************************************************************************/
760
761
762void TraceMod(GF2E& x, const GF2EX& a, const GF2EXModulus& F);
763GF2E TraceMod(const GF2EX& a, const GF2EXModulus& F);
764
765void TraceMod(GF2E& x, const GF2EX& a, const GF2EX& f);
766GF2E TraceMod(const GF2EX& a, const GF2EXModulus& f);
767// x = Trace(a mod f); deg(a) < deg(f)
768
769
770void TraceVec(vec_GF2E& S, const GF2EX& f);
771vec_GF2E TraceVec(const GF2EX& f);
772// S[i] = Trace(X^i mod f), i = 0..deg(f)-1; 0 < deg(f)
773
774// The above trace routines implement the asymptotically fast trace
775// algorithm from [von zur Gathen and Shoup, Computational Complexity,
776// 1992].
777
778void NormMod(GF2E& x, const GF2EX& a, const GF2EX& f);
779GF2E NormMod(const GF2EX& a, const GF2EX& f);
780// x = Norm(a mod f); 0 < deg(f), deg(a) < deg(f)
781
782void resultant(GF2E& x, const GF2EX& a, const GF2EX& b);
783GF2E resultant(const GF2EX& a, const GF2EX& b);
784// x = resultant(a, b)
785
786// NormMod and resultant require that GF2E is a field.
787
788
789
790/**************************************************************************\
791
792                           Miscellany
793
794A GF2EX f is represented as a vec_GF2E, which can be accessed as
795f.rep.  The constant term is f.rep[0] and the leading coefficient is
796f.rep[f.rep.length()-1], except if f is zero, in which case
797f.rep.length() == 0.  Note that the leading coefficient is always
798nonzero (unless f is zero).  One can freely access and modify f.rep,
799but one should always ensure that the leading coefficient is nonzero,
800which can be done by invoking f.normalize().
801
802
803\**************************************************************************/
804
805
806void clear(GF2EX& x) // x = 0
807void set(GF2EX& x); // x = 1
808
809void GF2EX::normalize(); 
810// f.normalize() strips leading zeros from f.rep.
811
812void GF2EX::SetMaxLength(long n);
813// f.SetMaxLength(n) pre-allocate spaces for n coefficients.  The
814// polynomial that f represents is unchanged.
815
816void GF2EX::kill();
817// f.kill() sets f to 0 and frees all memory held by f.  Equivalent to
818// f.rep.kill().
819
820GF2EX::GF2EX(INIT_SIZE_TYPE, long n);
821// GF2EX(INIT_SIZE, n) initializes to zero, but space is pre-allocated
822// for n coefficients
823
824static const GF2EX& zero();
825// GF2EX::zero() is a read-only reference to 0
826
827void swap(GF2EX& x, GF2EX& y);
828// swap x and y (via "pointer swapping")
829
Note: See TracBrowser for help on using the repository browser.