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