source: git/ntl/include/NTL/lzz_pE.h @ 77902f

spielwiese
Last change on this file since 77902f was 77902f, checked in by Hans Schönemann <hannes@…>, 21 years ago
*hannes: iostream adaption git-svn-id: file:///usr/local/Singular/svn/trunk@6321 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 11.1 KB
Line 
1
2#ifndef NTL_zz_pE__H
3#define NTL_zz_pE__H
4
5#include <NTL/vector.h>
6#include <NTL/matrix.h>
7#include <NTL/vec_long.h>
8#include <NTL/lzz_pX.h>
9
10NTL_OPEN_NNS
11
12
13
14class zz_pEInfoT {
15private:
16   zz_pEInfoT();                       // disabled
17   zz_pEInfoT(const zz_pEInfoT&);   // disabled
18   void operator=(const zz_pEInfoT&);  // disabled
19public:
20   long ref_count;
21
22   zz_pEInfoT(const zz_pX&);
23   ~zz_pEInfoT() { }
24
25   zz_pXModulus p;
26
27   ZZ   _card;
28   long _card_init;
29   long _card_base;
30   long _card_exp;
31
32
33};
34
35extern zz_pEInfoT *zz_pEInfo; // info for current modulus, initially null
36
37
38
39
40class zz_pEContext {
41private:
42zz_pEInfoT *ptr;
43
44public:
45void save();
46void restore() const;
47
48zz_pEContext() { ptr = 0; }
49zz_pEContext(const zz_pX& p);
50
51zz_pEContext(const zz_pEContext&); 
52
53
54zz_pEContext& operator=(const zz_pEContext&); 
55
56
57~zz_pEContext();
58
59
60};
61
62
63class zz_pEBak {
64private:
65long MustRestore;
66zz_pEInfoT *ptr;
67
68zz_pEBak(const zz_pEBak&); // disabled
69void operator=(const zz_pEBak&); // disabled
70
71public:
72void save();
73void restore();
74
75zz_pEBak() { MustRestore = 0; ptr = 0; }
76
77~zz_pEBak();
78
79
80};
81
82
83
84struct zz_pE_NoAlloc_type { zz_pE_NoAlloc_type() { } };
85const zz_pE_NoAlloc_type zz_pE_NoAlloc = zz_pE_NoAlloc_type();
86
87
88
89class zz_pE {
90
91public:
92
93zz_pX _zz_pE__rep;
94
95
96static long DivCross() { return 16; }
97static long ModCross() { return 8; }
98
99
100// ****** constructors and assignment
101
102zz_pE();
103
104zz_pE(const zz_pE& a)  { _zz_pE__rep.SetMaxLength(zz_pE::degree()); _zz_pE__rep = a._zz_pE__rep; }
105
106zz_pE(zz_pE_NoAlloc_type) { }  // allocates no space
107
108~zz_pE() { } 
109
110zz_pE& operator=(const zz_pE& a) { _zz_pE__rep = a._zz_pE__rep; return *this; }
111
112zz_pE(zz_pE& x, INIT_TRANS_TYPE) : _zz_pE__rep(x._zz_pE__rep, INIT_TRANS) { }
113
114
115// You can always access the _zz_pE__representation directly...if you dare.
116zz_pX& LoopHole() { return _zz_pE__rep; }
117
118
119static const zz_pXModulus& modulus() { return zz_pEInfo->p; }
120
121static long degree() { return deg(zz_pEInfo->p); }
122
123static const ZZ& cardinality();
124
125static const zz_pE& zero();
126
127static long initialized() { return (zz_pEInfo != 0); }
128
129static void init(const zz_pX&);
130
131inline zz_pE& operator=(long a);
132inline zz_pE& operator=(const zz_p& a);
133
134 
135};
136
137inline const zz_pX& _zz_pE__rep(const zz_pE& a) { return a._zz_pE__rep; }
138
139inline void clear(zz_pE& x)
140// x = 0
141   { clear(x._zz_pE__rep); }
142
143inline void set(zz_pE& x)
144// x = 1
145   { set(x._zz_pE__rep); }
146
147inline void swap(zz_pE& x, zz_pE& y)
148// swap x and y
149
150   { swap(x._zz_pE__rep, y._zz_pE__rep); }
151
152// ****** addition
153
154inline void add(zz_pE& x, const zz_pE& a, const zz_pE& b)
155// x = a + b
156
157   { add(x._zz_pE__rep, a._zz_pE__rep, b._zz_pE__rep); }
158
159inline void sub(zz_pE& x, const zz_pE& a, const zz_pE& b)
160// x = a - b
161
162   { sub(x._zz_pE__rep, a._zz_pE__rep, b._zz_pE__rep); }
163
164
165inline void negate(zz_pE& x, const zz_pE& a) 
166
167   { negate(x._zz_pE__rep, a._zz_pE__rep); }
168
169
170inline void add(zz_pE& x, const zz_pE& a, long b)
171   { add(x._zz_pE__rep, a._zz_pE__rep, b); }
172
173inline void add(zz_pE& x, const zz_pE& a, const zz_p& b)
174   { add(x._zz_pE__rep, a._zz_pE__rep, b); }
175
176inline void add(zz_pE& x, long a, const zz_pE& b)
177   { add(x._zz_pE__rep, a, b._zz_pE__rep); }
178
179inline void add(zz_pE& x, const zz_p& a, const zz_pE& b)
180   { add(x._zz_pE__rep, a, b._zz_pE__rep); }
181
182
183
184
185
186inline void sub(zz_pE& x, const zz_pE& a, long b)
187   { sub(x._zz_pE__rep, a._zz_pE__rep, b); }
188
189inline void sub(zz_pE& x, const zz_pE& a, const zz_p& b)
190   { sub(x._zz_pE__rep, a._zz_pE__rep, b); }
191
192inline void sub(zz_pE& x, long a, const zz_pE& b)
193   { sub(x._zz_pE__rep, a, b._zz_pE__rep); }
194
195inline void sub(zz_pE& x, const zz_p& a, const zz_pE& b)
196   { sub(x._zz_pE__rep, a, b._zz_pE__rep); }
197
198
199
200
201
202// ****** multiplication
203
204inline void mul(zz_pE& x, const zz_pE& a, const zz_pE& b)
205// x = a*b
206
207   { MulMod(x._zz_pE__rep, a._zz_pE__rep, b._zz_pE__rep, zz_pE::modulus()); }
208
209
210inline void sqr(zz_pE& x, const zz_pE& a)
211// x = a^2
212
213   { SqrMod(x._zz_pE__rep, a._zz_pE__rep, zz_pE::modulus()); }
214
215inline zz_pE sqr(const zz_pE& a)
216   { zz_pE x; sqr(x, a); NTL_OPT_RETURN(zz_pE, x); }
217
218
219inline void mul(zz_pE& x, const zz_pE& a, long b)
220   { mul(x._zz_pE__rep, a._zz_pE__rep, b); }
221
222inline void mul(zz_pE& x, const zz_pE& a, const zz_p& b)
223   { mul(x._zz_pE__rep, a._zz_pE__rep, b); }
224
225inline void mul(zz_pE& x, long a, const zz_pE& b)
226   { mul(x._zz_pE__rep, a, b._zz_pE__rep); }
227
228inline void mul(zz_pE& x, const zz_p& a, const zz_pE& b)
229   { mul(x._zz_pE__rep, a, b._zz_pE__rep); }
230
231
232// ****** division
233
234
235
236void div(zz_pE& x, const zz_pE& a, const zz_pE& b);
237void div(zz_pE& x, const zz_pE& a, long b);
238void div(zz_pE& x, const zz_pE& a, const zz_p& b);
239void div(zz_pE& x, long a, const zz_pE& b);
240void div(zz_pE& x, const zz_p& a, const zz_pE& b);
241
242void inv(zz_pE& x, const zz_pE& a);
243
244inline zz_pE inv(const zz_pE& a)
245   { zz_pE x; inv(x, a); NTL_OPT_RETURN(zz_pE, x); }
246
247
248
249// ****** exponentiation
250
251inline void power(zz_pE& x, const zz_pE& a, const ZZ& e)
252// x = a^e
253
254   { PowerMod(x._zz_pE__rep, a._zz_pE__rep, e, zz_pE::modulus()); }
255
256inline zz_pE power(const zz_pE& a, const ZZ& e)
257   { zz_pE x; power(x, a, e); NTL_OPT_RETURN(zz_pE, x); }
258
259inline void power(zz_pE& x, const zz_pE& a, long e)
260   { power(x, a, ZZ_expo(e)); }
261
262inline zz_pE power(const zz_pE& a, long e)
263   { zz_pE x; power(x, a, e); NTL_OPT_RETURN(zz_pE, x); }
264
265
266
267
268// ****** conversion
269
270inline void conv(zz_pE& x, const zz_pX& a)
271   { rem(x._zz_pE__rep, a, zz_pE::modulus()); }
272
273inline void conv(zz_pE& x, long a)
274   { conv(x._zz_pE__rep, a); }
275
276inline void conv(zz_pE& x, const zz_p& a)
277   { conv(x._zz_pE__rep, a); }
278
279inline void conv(zz_pE& x, const ZZ& a)
280   { conv(x._zz_pE__rep, a); }
281
282inline zz_pE to_zz_pE(const zz_pX& a) 
283   { zz_pE x; conv(x, a); NTL_OPT_RETURN(zz_pE, x); }
284
285inline zz_pE to_zz_pE(long a) 
286   { zz_pE x; conv(x, a); NTL_OPT_RETURN(zz_pE, x); }
287
288inline zz_pE to_zz_pE(const zz_p& a) 
289   { zz_pE x; conv(x, a); NTL_OPT_RETURN(zz_pE, x); }
290
291inline zz_pE to_zz_pE(const ZZ& a) 
292   { zz_pE x; conv(x, a); NTL_OPT_RETURN(zz_pE, x); }
293
294
295
296// ****** comparison
297
298inline long IsZero(const zz_pE& a)
299   { return IsZero(a._zz_pE__rep); }
300
301inline long IsOne(const zz_pE& a)
302   { return IsOne(a._zz_pE__rep); }
303
304inline long operator==(const zz_pE& a, const zz_pE& b)
305   { return a._zz_pE__rep == b._zz_pE__rep; }
306inline long operator==(const zz_pE& a, long b)
307   { return a._zz_pE__rep == b; }
308inline long operator==(const zz_pE& a, const zz_p& b)
309   { return a._zz_pE__rep == b; }
310inline long operator==(long a, const zz_pE& b)
311   { return a == b._zz_pE__rep; }
312inline long operator==(const zz_p& a, const zz_pE& b)
313   { return a == b._zz_pE__rep; }
314
315inline long operator!=(const zz_pE& a, const zz_pE& b)
316   { return !(a == b); }
317inline long operator!=(const zz_pE& a, long b)
318   { return !(a == b); }
319inline long operator!=(const zz_pE& a, const zz_p& b)
320   { return !(a == b); }
321inline long operator!=(long a, const zz_pE& b)
322   { return !(a == b); }
323inline long operator!=(const zz_p& a, const zz_pE& b)
324   { return !(a == b); }
325
326
327// ****** norm and trace
328
329inline void trace(zz_p& x, const zz_pE& a)
330   { TraceMod(x, a._zz_pE__rep, zz_pE::modulus()); }
331inline zz_p trace(const zz_pE& a)
332   { return TraceMod(a._zz_pE__rep, zz_pE::modulus()); }
333
334inline void norm(zz_p& x, const zz_pE& a)
335   { NormMod(x, a._zz_pE__rep, zz_pE::modulus()); }
336inline zz_p norm(const zz_pE& a)
337   { return NormMod(a._zz_pE__rep, zz_pE::modulus()); }
338
339
340// ****** random numbers
341
342inline void random(zz_pE& x)
343// x = random element in zz_pE
344
345   { random(x._zz_pE__rep, zz_pE::degree()); }
346
347inline zz_pE random_zz_pE()
348   { zz_pE x; random(x); NTL_OPT_RETURN(zz_pE, x); }
349
350
351// ****** input/output
352inline const zz_pX& rep(const zz_pE& a) { return a._zz_pE__rep; }
353
354
355
356inline zz_pE& zz_pE::operator=(long a) { conv(*this, a); return *this; }
357inline zz_pE& zz_pE::operator=(const zz_p& a) { conv(*this, a); return *this; }
358
359
360
361
362inline zz_pE operator+(const zz_pE& a, const zz_pE& b) 
363   { zz_pE x; add(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
364
365inline zz_pE operator+(const zz_pE& a, const zz_p& b) 
366   { zz_pE x; add(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
367
368inline zz_pE operator+(const zz_pE& a, long b) 
369   { zz_pE x; add(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
370
371inline zz_pE operator+(const zz_p& a, const zz_pE& b) 
372   { zz_pE x; add(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
373
374inline zz_pE operator+(long a, const zz_pE& b) 
375   { zz_pE x; add(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
376
377
378inline zz_pE operator-(const zz_pE& a, const zz_pE& b) 
379   { zz_pE x; sub(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
380
381inline zz_pE operator-(const zz_pE& a, const zz_p& b) 
382   { zz_pE x; sub(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
383
384inline zz_pE operator-(const zz_pE& a, long b) 
385   { zz_pE x; sub(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
386
387inline zz_pE operator-(const zz_p& a, const zz_pE& b) 
388   { zz_pE x; sub(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
389
390inline zz_pE operator-(long a, const zz_pE& b) 
391   { zz_pE x; sub(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
392
393inline zz_pE operator-(const zz_pE& a)
394   { zz_pE x; negate(x, a); NTL_OPT_RETURN(zz_pE, x); } 
395
396
397inline zz_pE& operator+=(zz_pE& x, const zz_pE& b)
398   { add(x, x, b); return x; }
399
400inline zz_pE& operator+=(zz_pE& x, const zz_p& b)
401   { add(x, x, b); return x; }
402
403inline zz_pE& operator+=(zz_pE& x, long b)
404   { add(x, x, b); return x; }
405
406
407inline zz_pE& operator-=(zz_pE& x, const zz_pE& b)
408   { sub(x, x, b); return x; }
409
410inline zz_pE& operator-=(zz_pE& x, const zz_p& b)
411   { sub(x, x, b); return x; }
412
413inline zz_pE& operator-=(zz_pE& x, long b)
414   { sub(x, x, b); return x; }
415
416
417inline zz_pE& operator++(zz_pE& x) { add(x, x, 1); return x; }
418
419inline void operator++(zz_pE& x, int) { add(x, x, 1); }
420
421inline zz_pE& operator--(zz_pE& x) { sub(x, x, 1); return x; }
422
423inline void operator--(zz_pE& x, int) { sub(x, x, 1); }
424
425
426
427inline zz_pE operator*(const zz_pE& a, const zz_pE& b) 
428   { zz_pE x; mul(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
429
430inline zz_pE operator*(const zz_pE& a, const zz_p& b) 
431   { zz_pE x; mul(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
432
433inline zz_pE operator*(const zz_pE& a, long b) 
434   { zz_pE x; mul(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
435
436inline zz_pE operator*(const zz_p& a, const zz_pE& b) 
437   { zz_pE x; mul(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
438
439inline zz_pE operator*(long a, const zz_pE& b) 
440   { zz_pE x; mul(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
441
442
443inline zz_pE& operator*=(zz_pE& x, const zz_pE& b)
444   { mul(x, x, b); return x; }
445
446inline zz_pE& operator*=(zz_pE& x, const zz_p& b)
447   { mul(x, x, b); return x; }
448
449inline zz_pE& operator*=(zz_pE& x, long b)
450   { mul(x, x, b); return x; }
451
452
453
454
455inline zz_pE operator/(const zz_pE& a, const zz_pE& b) 
456   { zz_pE x; div(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
457
458inline zz_pE operator/(const zz_pE& a, const zz_p& b) 
459   { zz_pE x; div(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
460
461inline zz_pE operator/(const zz_pE& a, long b) 
462   { zz_pE x; div(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
463
464inline zz_pE operator/(const zz_p& a, const zz_pE& b) 
465   { zz_pE x; div(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
466
467inline zz_pE operator/(long a, const zz_pE& b) 
468   { zz_pE x; div(x, a, b); NTL_OPT_RETURN(zz_pE, x); }
469
470
471inline zz_pE& operator/=(zz_pE& x, const zz_pE& b)
472   { div(x, x, b); return x; }
473
474inline zz_pE& operator/=(zz_pE& x, const zz_p& b)
475   { div(x, x, b); return x; }
476
477inline zz_pE& operator/=(zz_pE& x, long b)
478   { div(x, x, b); return x; }
479
480NTL_CLOSE_NNS
481
482#endif
Note: See TracBrowser for help on using the repository browser.