source: git/ntl/doc/lzz_pEX.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.7 KB
Line 
1
2/**************************************************************************\
3
4MODULE: zz_pEX
5
6SUMMARY:
7
8The class zz_pEX represents polynomials over zz_pE,
9and so can be used, for example, for arithmentic in GF(p^n)[X].
10However, except where mathematically necessary (e.g., GCD computations),
11zz_pE need not be a field.
12
13\**************************************************************************/
14
15#include <NTL/lzz_pE.h>
16#include <NTL/vec_lzz_pE.h>
17
18class zz_pEX {
19public:
20
21   zz_pEX(); // initial value 0
22
23   zz_pEX(const zz_pEX& a); // copy
24
25   zz_pEX& operator=(const zz_pEX& a); // assignment
26   zz_pEX& operator=(const zz_pE& a);
27   zz_pEX& operator=(const zz_p& a);
28   zz_pEX& operator=(long a);
29
30   ~zz_pEX(); // destructor
31
32   zz_pEX(long i, const zz_pE& c); // initilaize to X^i*c
33   zz_pEX(long i, const zz_p& c);
34   zz_pEX(long i, long c);
35
36   
37};
38
39
40
41
42
43
44/**************************************************************************\
45
46                                  Comparison
47
48\**************************************************************************/
49
50
51long operator==(const zz_pEX& a, const zz_pEX& b);
52long operator!=(const zz_pEX& a, const zz_pEX& b);
53
54long IsZero(const zz_pEX& a); // test for 0
55long IsOne(const zz_pEX& a); // test for 1
56
57// PROMOTIONS: ==, != promote {long,zz_p,zz_pE} to zz_pEX on (a, b).
58
59/**************************************************************************\
60
61                                   Addition
62
63\**************************************************************************/
64
65// operator notation:
66
67zz_pEX operator+(const zz_pEX& a, const zz_pEX& b);
68zz_pEX operator-(const zz_pEX& a, const zz_pEX& b);
69zz_pEX operator-(const zz_pEX& a);
70
71zz_pEX& operator+=(zz_pEX& x, const zz_pEX& a);
72zz_pEX& operator+=(zz_pEX& x, const zz_pE& a);
73zz_pEX& operator+=(zz_pEX& x, const zz_p& a);
74zz_pEX& operator+=(zz_pEX& x, long a);
75
76
77zz_pEX& operator++(zz_pEX& x);  // prefix
78void operator++(zz_pEX& x, int);  // postfix
79
80zz_pEX& operator-=(zz_pEX& x, const zz_pEX& a);
81zz_pEX& operator-=(zz_pEX& x, const zz_pE& a);
82zz_pEX& operator-=(zz_pEX& x, const zz_p& a);
83zz_pEX& operator-=(zz_pEX& x, long a);
84
85zz_pEX& operator--(zz_pEX& x);  // prefix
86void operator--(zz_pEX& x, int);  // postfix
87
88// procedural versions:
89
90void add(zz_pEX& x, const zz_pEX& a, const zz_pEX& b); // x = a + b
91void sub(zz_pEX& x, const zz_pEX& a, const zz_pEX& b); // x = a - b
92void negate(zz_pEX& x, const zz_pEX& a); // x = - a
93
94// PROMOTIONS: +, -, add, sub promote {long,zz_p,zz_pE} to zz_pEX on (a, b).
95
96
97
98/**************************************************************************\
99
100                               Multiplication
101
102\**************************************************************************/
103
104// operator notation:
105
106zz_pEX operator*(const zz_pEX& a, const zz_pEX& b);
107
108zz_pEX& operator*=(zz_pEX& x, const zz_pEX& a);
109zz_pEX& operator*=(zz_pEX& x, const zz_pE& a);
110zz_pEX& operator*=(zz_pEX& x, const zz_p& a);
111zz_pEX& operator*=(zz_pEX& x, long a);
112
113
114// procedural versions:
115
116
117void mul(zz_pEX& x, const zz_pEX& a, const zz_pEX& b); // x = a * b
118
119void sqr(zz_pEX& x, const zz_pEX& a); // x = a^2
120zz_pEX sqr(const zz_pEX& a);
121
122// PROMOTIONS: *, mul promote {long,zz_p,zz_pE} to zz_pEX on (a, b).
123
124void power(zz_pEX& x, const zz_pEX& a, long e);  // x = a^e (e >= 0)
125zz_pEX power(const zz_pEX& 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
141zz_pEX operator<<(const zz_pEX& a, long n);
142zz_pEX operator>>(const zz_pEX& a, long n);
143
144zz_pEX& operator<<=(zz_pEX& x, long n);
145zz_pEX& operator>>=(zz_pEX& x, long n);
146
147// procedural versions:
148
149void LeftShift(zz_pEX& x, const zz_pEX& a, long n);
150zz_pEX LeftShift(const zz_pEX& a, long n);
151
152void RightShift(zz_pEX& x, const zz_pEX& a, long n);
153zz_pEX RightShift(const zz_pEX& a, long n);
154
155
156
157/**************************************************************************\
158
159                                  Division
160
161\**************************************************************************/
162
163// operator notation:
164
165zz_pEX operator/(const zz_pEX& a, const zz_pEX& b);
166zz_pEX operator/(const zz_pEX& a, const zz_pE& b);
167zz_pEX operator/(const zz_pEX& a, const zz_p& b);
168zz_pEX operator/(const zz_pEX& a, long b);
169
170zz_pEX operator%(const zz_pEX& a, const zz_pEX& b);
171
172zz_pEX& operator/=(zz_pEX& x, const zz_pEX& a);
173zz_pEX& operator/=(zz_pEX& x, const zz_pE& a);
174zz_pEX& operator/=(zz_pEX& x, const zz_p& a);
175zz_pEX& operator/=(zz_pEX& x, long a);
176
177zz_pEX& operator%=(zz_pEX& x, const zz_pEX& a);
178
179// procedural versions:
180
181
182void DivRem(zz_pEX& q, zz_pEX& r, const zz_pEX& a, const zz_pEX& b);
183// q = a/b, r = a%b
184
185void div(zz_pEX& q, const zz_pEX& a, const zz_pEX& b);
186void div(zz_pEX& q, const zz_pEX& a, const zz_pE& b);
187void div(zz_pEX& q, const zz_pEX& a, const zz_p& b);
188void div(zz_pEX& q, const zz_pEX& a, long b);
189// q = a/b
190
191void rem(zz_pEX& r, const zz_pEX& a, const zz_pEX& b);
192// r = a%b
193
194long divide(zz_pEX& q, const zz_pEX& a, const zz_pEX& b);
195// if b | a, sets q = a/b and returns 1; otherwise returns 0
196
197long divide(const zz_pEX& a, const zz_pEX& 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 zz_pE is a field.
206
207\**************************************************************************/
208
209
210void GCD(zz_pEX& x, const zz_pEX& a, const zz_pEX& b);
211zz_pEX GCD(const zz_pEX& a, const zz_pEX& b);
212// x = GCD(a, b),  x is always monic (or zero if a==b==0).
213
214
215void XGCD(zz_pEX& d, zz_pEX& s, zz_pEX& t, const zz_pEX& a, const zz_pEX& 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 < zz_pE::degree() and
230a_n not zero (the zero polynomial is [ ]).  On input, the coefficients
231are arbitrary polynomials which are reduced modulo zz_pE::modulus(),
232and leading zeros stripped.
233
234\**************************************************************************/
235
236istream& operator>>(istream& s, zz_pEX& x);
237ostream& operator<<(ostream& s, const zz_pEX& a);
238
239
240/**************************************************************************\
241
242                              Some utility routines
243
244\**************************************************************************/
245
246long deg(const zz_pEX& a);  // return deg(a); deg(0) == -1.
247
248const zz_pE& coeff(const zz_pEX& 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 zz_pE& LeadCoeff(const zz_pEX& a);
253// read-only reference to leading term of a, or zero if a == 0
254
255const zz_pE& ConstTerm(const zz_pEX& a);
256// read-only reference to constant term of a, or zero if a == 0
257
258void SetCoeff(zz_pEX& x, long i, const zz_pE& a);
259void SetCoeff(zz_pEX& x, long i, const zz_p& a);
260void SetCoeff(zz_pEX& x, long i, long a);
261// makes coefficient of X^i equal to a;  error is raised if i < 0
262
263void SetCoeff(zz_pEX& x, long i);
264// makes coefficient of X^i equal to 1;  error is raised if i < 0
265
266void SetX(zz_pEX& x); // x is set to the monomial X
267
268long IsX(const zz_pEX& a); // test if x = X
269
270void diff(zz_pEX& x, const zz_pEX& a); // x = derivative of a
271zz_pEX diff(const zz_pEX& a);
272
273void MakeMonic(zz_pEX& x);
274// if x != 0 makes x into its monic associate; LeadCoeff(x) must be
275// invertible in this case
276
277void reverse(zz_pEX& x, const zz_pEX& a, long hi);
278zz_pEX reverse(const zz_pEX& a, long hi);
279
280void reverse(zz_pEX& x, const zz_pEX& a);
281zz_pEX reverse(const zz_pEX& 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_zz_pE& x, const zz_pEX& a, long n);
287vec_zz_pE VectorCopy(const zz_pEX& 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(zz_pEX& x, long n);
301zz_pEX random_zz_pEX(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(zz_pEX& x, const vec_zz_pE& a);
313zz_pEX BuildFromRoots(const vec_zz_pE& a);
314// computes the polynomial (X-a[0]) ... (X-a[n-1]), where n = a.length()
315
316void eval(zz_pE& b, const zz_pEX& f, const zz_pE& a);
317zz_pE eval(const zz_pEX& f, const zz_pE& a);
318// b = f(a)
319
320void eval(zz_pE& b, const zz_pX& f, const zz_pE& a);
321zz_pE eval(const zz_pEX& f, const zz_pE& a);
322// b = f(a); uses ModComp algorithm for zz_pX
323
324void eval(vec_zz_pE& b, const zz_pEX& f, const vec_zz_pE& a);
325vec_zz_pE eval(const zz_pEX& f, const vec_zz_pE& a);
326//  b.SetLength(a.length()); b[i] = f(a[i]) for 0 <= i < a.length()
327
328void interpolate(zz_pEX& f, const vec_zz_pE& a, const vec_zz_pE& b);
329zz_pEX interpolate(const vec_zz_pE& a, const vec_zz_pE& 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(zz_pEX& x, const zz_pEX& a, long n); // x = a % X^n
341zz_pEX trunc(const zz_pEX& a, long n);
342
343void MulTrunc(zz_pEX& x, const zz_pEX& a, const zz_pEX& b, long n);
344zz_pEX MulTrunc(const zz_pEX& a, const zz_pEX& b, long n);
345// x = a * b % X^n
346
347void SqrTrunc(zz_pEX& x, const zz_pEX& a, long n);
348zz_pEX SqrTrunc(const zz_pEX& a, long n);
349// x = a^2 % X^n
350
351void InvTrunc(zz_pEX& x, const zz_pEX& a, long n);
352zz_pEX InvTrunc(zz_pEX& x, const zz_pEX& 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
366zz_pEXModulus data structure and associated routines below for better
367performance.
368
369\**************************************************************************/
370
371void MulMod(zz_pEX& x, const zz_pEX& a, const zz_pEX& b, const zz_pEX& f);
372zz_pEX MulMod(const zz_pEX& a, const zz_pEX& b, const zz_pEX& f);
373// x = (a * b) % f
374
375void SqrMod(zz_pEX& x, const zz_pEX& a, const zz_pEX& f);
376zz_pEX SqrMod(const zz_pEX& a, const zz_pEX& f);
377// x = a^2 % f
378
379void MulByXMod(zz_pEX& x, const zz_pEX& a, const zz_pEX& f);
380zz_pEX MulByXMod(const zz_pEX& a, const zz_pEX& f);
381// x = (a * X) mod f
382
383void InvMod(zz_pEX& x, const zz_pEX& a, const zz_pEX& f);
384zz_pEX InvMod(const zz_pEX& a, const zz_pEX& f);
385// x = a^{-1} % f, error is a is not invertible
386
387long InvModStatus(zz_pEX& x, const zz_pEX& a, const zz_pEX& 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
397zz_pEXModulus 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/lzz_pEX.h>
404
405void product(zz_pEX& x, const vec_zz_pEX& v, const zz_pEX& f)
406{
407   zz_pEXModulus F(f);
408   zz_pEX 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 zz_pEX may be used wherever a zz_pEXModulus is required,
417and a zz_pEXModulus may be used wherever a zz_pEX is required.
418
419
420\**************************************************************************/
421
422class zz_pEXModulus {
423public:
424   zz_pEXModulus(); // initially in an unusable state
425
426   zz_pEXModulus(const zz_pEX& f); // initialize with f, deg(f) > 0
427
428   zz_pEXModulus(const zz_pEXModulus&); // copy
429
430   zz_pEXModulus& operator=(const zz_pEXModulus&); // assignment
431
432   ~zz_pEXModulus(); // destructor
433
434   operator const zz_pEX& () const; // implicit read-only access to f
435
436   const zz_pEX& val() const; // explicit read-only access to f
437};
438
439void build(zz_pEXModulus& F, const zz_pEX& f);
440// pre-computes information about f and stores it in F.  Must have
441// deg(f) > 0.  Note that the declaration zz_pEXModulus F(f) is
442// equivalent to zz_pEXModulus 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 zz_pEXModulus& F);  // return n=deg(f)
449
450void MulMod(zz_pEX& x, const zz_pEX& a, const zz_pEX& b,
451            const zz_pEXModulus& F);
452zz_pEX MulMod(const zz_pEX& a, const zz_pEX& b, const zz_pEXModulus& F);
453// x = (a * b) % f; deg(a), deg(b) < n
454
455void SqrMod(zz_pEX& x, const zz_pEX& a, const zz_pEXModulus& F);
456zz_pEX SqrMod(const zz_pEX& a, const zz_pEXModulus& F);
457// x = a^2 % f; deg(a) < n
458
459void PowerMod(zz_pEX& x, const zz_pEX& a, const ZZ& e, const zz_pEXModulus& F);
460zz_pEX PowerMod(const zz_pEX& a, const ZZ& e, const zz_pEXModulus& F);
461
462void PowerMod(zz_pEX& x, const zz_pEX& a, long e, const zz_pEXModulus& F);
463zz_pEX PowerMod(const zz_pEX& a, long e, const zz_pEXModulus& F);
464
465// x = a^e % f; e >= 0, deg(a) < n.  Uses a sliding window algorithm.
466// (e may be negative)
467
468void PowerXMod(zz_pEX& x, const ZZ& e, const zz_pEXModulus& F);
469zz_pEX PowerXMod(const ZZ& e, const zz_pEXModulus& F);
470
471void PowerXMod(zz_pEX& x, long e, const zz_pEXModulus& F);
472zz_pEX PowerXMod(long e, const zz_pEXModulus& F);
473
474// x = X^e % f (e may be negative)
475
476void rem(zz_pEX& x, const zz_pEX& a, const zz_pEXModulus& F);
477// x = a % f
478
479void DivRem(zz_pEX& q, zz_pEX& r, const zz_pEX& a, const zz_pEXModulus& F);
480// q = a/f, r = a%f
481
482void div(zz_pEX& q, const zz_pEX& a, const zz_pEXModulus& F);
483// q = a/f
484
485// operator notation:
486
487zz_pEX operator/(const zz_pEX& a, const zz_pEXModulus& F);
488zz_pEX operator%(const zz_pEX& a, const zz_pEXModulus& F);
489
490zz_pEX& operator/=(zz_pEX& x, const zz_pEXModulus& F);
491zz_pEX& operator%=(zz_pEX& x, const zz_pEXModulus& F);
492
493
494
495/**************************************************************************\
496
497                             vectors of zz_pEX's
498
499\**************************************************************************/
500
501NTL_vector_decl(zz_pEX,vec_zz_pEX)
502// vec_zz_pEX
503
504NTL_eq_vector_decl(zz_pEX,vec_zz_pEX)
505// == and !=
506
507NTL_io_vector_decl(zz_pEX,vec_zz_pEX)
508// I/O operators
509
510
511
512/**************************************************************************\
513
514                              Modular Composition
515
516Modular composition is the problem of computing g(h) mod f for
517polynomials f, g, and h.
518
519The algorithm employed is that of Brent & Kung (Fast algorithms for
520manipulating formal power series, JACM 25:581-595, 1978), which uses
521O(n^{1/2}) modular polynomial multiplications, and O(n^2) scalar
522operations.
523
524
525\**************************************************************************/
526
527void CompMod(zz_pEX& x, const zz_pEX& g, const zz_pEX& h,
528             const zz_pEXModulus& F);
529zz_pEX CompMod(const zz_pEX& g, const zz_pEX& h,
530                    const zz_pEXModulus& F);
531
532// x = g(h) mod f; deg(h) < n
533
534void Comp2Mod(zz_pEX& x1, zz_pEX& x2, const zz_pEX& g1, const zz_pEX& g2,
535              const zz_pEX& h, const zz_pEXModulus& F);
536// xi = gi(h) mod f (i=1,2); deg(h) < n.
537
538
539void Comp3Mod(zz_pEX& x1, zz_pEX& x2, zz_pEX& x3,
540              const zz_pEX& g1, const zz_pEX& g2, const zz_pEX& g3,
541              const zz_pEX& h, const zz_pEXModulus& F);
542// xi = gi(h) mod f (i=1..3); deg(h) < n.
543
544
545
546/**************************************************************************\
547
548                     Composition with Pre-Conditioning
549
550If a single h is going to be used with many g's then you should build
551a zz_pEXArgument for h, and then use the compose routine below.  The
552routine build computes and stores h, h^2, ..., h^m mod f.  After this
553pre-computation, composing a polynomial of degree roughly n with h
554takes n/m multiplies mod f, plus n^2 scalar multiplies.  Thus,
555increasing m increases the space requirement and the pre-computation
556time, but reduces the composition time.
557
558\**************************************************************************/
559
560
561struct zz_pEXArgument {
562   vec_zz_pEX H;
563};
564
565void build(zz_pEXArgument& H, const zz_pEX& h, const zz_pEXModulus& F, long m);
566// Pre-Computes information about h.  m > 0, deg(h) < n.
567
568void CompMod(zz_pEX& x, const zz_pEX& g, const zz_pEXArgument& H,
569             const zz_pEXModulus& F);
570
571zz_pEX CompMod(const zz_pEX& g, const zz_pEXArgument& H,
572                    const zz_pEXModulus& F);
573
574extern long zz_pEXArgBound;
575
576// Initially 0.  If this is set to a value greater than zero, then
577// composition routines will allocate a table of no than about
578// zz_pEXArgBound KB.  Setting this value affects all compose routines
579// and the power projection and minimal polynomial routines below,
580// and indirectly affects many routines in zz_pEXFactoring.
581
582/**************************************************************************\
583
584                     power projection routines
585
586\**************************************************************************/
587
588void project(zz_pE& x, const zz_pEVector& a, const zz_pEX& b);
589zz_pE project(const zz_pEVector& a, const zz_pEX& b);
590// x = inner product of a with coefficient vector of b
591
592
593void ProjectPowers(vec_zz_pE& x, const vec_zz_pE& a, long k,
594                   const zz_pEX& h, const zz_pEXModulus& F);
595
596vec_zz_pE ProjectPowers(const vec_zz_pE& a, long k,
597                   const zz_pEX& h, const zz_pEXModulus& F);
598
599// Computes the vector
600
601//    project(a, 1), project(a, h), ..., project(a, h^{k-1} % f). 
602
603// This operation is the "transpose" of the modular composition operation.
604
605void ProjectPowers(vec_zz_pE& x, const vec_zz_pE& a, long k,
606                   const zz_pEXArgument& H, const zz_pEXModulus& F);
607
608vec_zz_pE ProjectPowers(const vec_zz_pE& a, long k,
609                   const zz_pEXArgument& H, const zz_pEXModulus& F);
610
611// same as above, but uses a pre-computed zz_pEXArgument
612
613
614class zz_pEXTransMultiplier { /* ... */ };
615
616void build(zz_pEXTransMultiplier& B, const zz_pEX& b, const zz_pEXModulus& F);
617
618void UpdateMap(vec_zz_pE& x, const vec_zz_pE& a,
619               const zz_pEXMultiplier& B, const zz_pEXModulus& F);
620
621vec_zz_pE UpdateMap(const vec_zz_pE& a,
622               const zz_pEXMultiplier& B, const zz_pEXModulus& F);
623
624// Computes the vector
625
626//    project(a, b), project(a, (b*X)%f), ..., project(a, (b*X^{n-1})%f)
627
628// Required: a.length() <= deg(F), deg(b) < deg(F).
629// This is "transposed" MulMod by B.
630// Input may have "high order" zeroes stripped.
631// Output always has high order zeroes stripped.
632
633
634/**************************************************************************\
635
636                              Minimum Polynomials
637
638These routines should be used only when zz_pE is a field.
639
640All of these routines implement the algorithm from [Shoup, J. Symbolic
641Comp. 17:371-391, 1994] and [Shoup, J. Symbolic Comp. 20:363-397,
6421995], based on transposed modular composition and the
643Berlekamp/Massey algorithm.
644
645\**************************************************************************/
646
647
648void MinPolySeq(zz_pEX& h, const vec_zz_pE& a, long m);
649zz_pEX MinPolySeq(const vec_zz_pE& a, long m);
650// computes the minimum polynomial of a linealy generated sequence; m
651// is a bound on the degree of the polynomial; required: a.length() >=
652// 2*m
653
654
655void ProbMinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);
656zz_pEX ProbMinPolyMod(const zz_pEX& g, const zz_pEXModulus& F, long m);
657
658void ProbMinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F);
659zz_pEX ProbMinPolyMod(const zz_pEX& g, const zz_pEXModulus& F);
660
661// computes the monic minimal polynomial if (g mod f).  m = a bound on
662// the degree of the minimal polynomial; in the second version, this
663// argument defaults to n.  The algorithm is probabilistic, always
664// returns a divisor of the minimal polynomial, and returns a proper
665// divisor with probability at most m/2^{zz_pE::degree()}.
666
667void MinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);
668zz_pEX MinPolyMod(const zz_pEX& g, const zz_pEXModulus& F, long m);
669
670void MinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F);
671zz_pEX MinPolyMod(const zz_pEX& g, const zz_pEXModulus& F);
672
673// same as above, but guarantees that result is correct
674
675void IrredPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);
676zz_pEX IrredPolyMod(const zz_pEX& g, const zz_pEXModulus& F, long m);
677
678void IrredPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F);
679zz_pEX IrredPolyMod(const zz_pEX& g, const zz_pEXModulus& F);
680
681// same as above, but assumes that f is irreducible, or at least that
682// the minimal poly of g is itself irreducible.  The algorithm is
683// deterministic (and is always correct).
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
692The routines require that p is prime, but zz_pE need not be a field.
693
694\**************************************************************************/
695
696
697void CompTower(zz_pEX& x, const zz_pX& g, const zz_pEXArgument& h,
698             const zz_pEXModulus& F);
699
700zz_pEX CompTower(const zz_pX& g, const zz_pEXArgument& h,
701             const zz_pEXModulus& F);
702
703void CompTower(zz_pEX& x, const zz_pX& g, const zz_pEX& h,
704             const zz_pEXModulus& F);
705
706zz_pEX CompTower(const zz_pX& g, const zz_pEX& h,
707             const zz_pEXModulus& F);
708
709
710// x = g(h) mod f
711
712
713void ProbMinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F,
714                      long m);
715
716zz_pX ProbMinPolyTower(const zz_pEX& g, const zz_pEXModulus& F, long m);
717
718void ProbMinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F);
719
720zz_pX ProbMinPolyTower(const zz_pEX& g, const zz_pEXModulus& F);
721
722// Uses a probabilistic algorithm to compute the minimal
723// polynomial of (g mod f) over zz_p.
724// The parameter m is a bound on the degree of the minimal polynomial
725// (default = deg(f)*zz_pE::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(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);
732
733zz_pX MinPolyTower(const zz_pEX& g, const zz_pEXModulus& F, long m);
734
735void MinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F);
736
737zz_pX MinPolyTower(const zz_pEX& g, const zz_pEXModulus& F);
738
739// Same as above, but result is always correct.
740
741
742void IrredPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);
743
744zz_pX IrredPolyTower(const zz_pEX& g, const zz_pEXModulus& F, long m);
745
746void IrredPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F);
747
748zz_pX IrredPolyTower(const zz_pEX& g, const zz_pEXModulus& 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                   Traces, norms, resultants
757
758\**************************************************************************/
759
760
761void TraceMod(zz_pE& x, const zz_pEX& a, const zz_pEXModulus& F);
762zz_pE TraceMod(const zz_pEX& a, const zz_pEXModulus& F);
763
764void TraceMod(zz_pE& x, const zz_pEX& a, const zz_pEX& f);
765zz_pE TraceMod(const zz_pEX& a, const zz_pEXModulus& f);
766// x = Trace(a mod f); deg(a) < deg(f)
767
768
769void TraceVec(vec_zz_pE& S, const zz_pEX& f);
770vec_zz_pE TraceVec(const zz_pEX& f);
771// S[i] = Trace(X^i mod f), i = 0..deg(f)-1; 0 < deg(f)
772
773// The above trace routines implement the asymptotically fast trace
774// algorithm from [von zur Gathen and Shoup, Computational Complexity,
775// 1992].
776
777void NormMod(zz_pE& x, const zz_pEX& a, const zz_pEX& f);
778zz_pE NormMod(const zz_pEX& a, const zz_pEX& f);
779// x = Norm(a mod f); 0 < deg(f), deg(a) < deg(f)
780
781void resultant(zz_pE& x, const zz_pEX& a, const zz_pEX& b);
782zz_pE resultant(const zz_pEX& a, const zz_pEX& b);
783// x = resultant(a, b)
784
785// NormMod and resultant require that zz_pE is a field.
786
787
788
789
790/**************************************************************************\
791
792                           Miscellany
793
794A zz_pEX f is represented as a vec_zz_pE, 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(zz_pEX& x) // x = 0
807void set(zz_pEX& x); // x = 1
808
809void zz_pEX::normalize(); 
810// f.normalize() strips leading zeros from f.rep.
811
812void zz_pEX::SetMaxLength(long n);
813// f.SetMaxLength(n) pre-allocate spaces for n coefficients.  The
814// polynomial that f represents is unchanged.
815
816void zz_pEX::kill();
817// f.kill() sets f to 0 and frees all memory held by f.  Equivalent to
818// f.rep.kill().
819
820zz_pEX::zz_pEX(INIT_SIZE_TYPE, long n);
821// zz_pEX(INIT_SIZE, n) initializes to zero, but space is pre-allocated
822// for n coefficients
823
824static const zz_pEX& zero();
825// zz_pEX::zero() is a read-only reference to 0
826
827void swap(zz_pEX& x, zz_pEX& y);
828// swap x and y (via "pointer swapping")
829
Note: See TracBrowser for help on using the repository browser.