source: git/ntl/doc/ZZ_pEX.txt @ 6ce030f

spielwiese
Last change on this file since 6ce030f 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/ZZ_pE.h>
16#include <NTL/vec_ZZ_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/ZZ_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.