source: git/ntl/doc/GF2E.txt @ 199b5c

fieker-DuValspielwiese
Last change on this file since 199b5c was 2cfffe, checked in by Hans Schönemann <hannes@…>, 22 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: 8.9 KB
Line 
1
2
3/**************************************************************************\
4
5MODULE: GF2E
6
7SUMMARY:
8
9The class GF2E is used to represent polynomials in F_2[X] modulo a
10polynomial P.  The modulus P may be any polynomial with deg(P) > 0,
11not necessarily irreducible. 
12
13Objects of the class GF2E are represented as a GF2X of degree < deg(P).
14
15An executing program maintains a "current modulus", which is set to P
16using GF2E::init(P).  The current modulus *must* be initialized before
17any GF2E constructors are invoked.
18
19The modulus may be changed, and a mechanism is provided for saving and
20restoring a modulus (see classes GF2EBak and GF2EContext below).
21
22
23NOTE: if P is a trinomial X^n + X^k + 1, or a pentanomial
24X^n + X^k3 + X^k2 + X^k1 + 1, or of the form X^n + g, where
25g has low degree, then performance will be somewhat improved.
26Such polynomials are constructed by the routines
27BuildSparseIrred and BuildIrred in GF2XFactoring.
28
29
30\**************************************************************************/
31
32#include <NTL/GF2X.h>
33
34class GF2E {
35public:
36   
37   GF2E(); // initial value 0
38
39   GF2E(const GF2E& a); // copy constructor
40   
41   GF2E& operator=(const GF2E& a); // assignment
42   GF2E& operator=(GF2 a); // assignment
43   GF2E& operator=(long a); // assignment
44   
45   ~GF2E(); // destructor
46
47   void init(const GF2X& P);
48   // GF2E::init(P) initializes the current modulus to P;
49   // required: deg(P) >= 1.
50   
51   static const GF2XModulus& modulus();
52   // GF2E::modulus() yields read-only reference to the current modulus
53
54   static long degree();
55   // GF2E::degree() returns deg(P)
56};
57
58
59const GF2X& rep(const GF2E& a); // read-only access to representation of a
60
61
62
63/**************************************************************************\
64
65                                  Comparison
66
67\**************************************************************************/
68
69long operator==(const GF2E& a, const GF2E& b);
70long operator!=(const GF2E& a, const GF2E& b);
71
72long IsZero(const GF2E& a);  // test for 0
73long IsOne(const GF2E& a);  // test for 1
74
75// PROMOTIONS: ==, != promote {long, GF2} to GF2E on (a, b).
76
77
78/**************************************************************************\
79
80                                    Addition
81
82\**************************************************************************/
83
84// operator notation:
85
86GF2E operator+(const GF2E& a, const GF2E& b);
87
88GF2E operator-(const GF2E& a, const GF2E& b);
89GF2E operator-(const GF2E& a);
90
91GF2E& operator+=(GF2E& x, const GF2E& a);
92GF2E& operator+=(GF2E& x, GF2 a);
93GF2E& operator+=(GF2E& x, long a);
94
95GF2E& operator++(GF2E& x); // prefix
96void operator++(GF2E& x, int); // postfix
97
98GF2E& operator-=(GF2E& x, const GF2E& a);
99GF2E& operator-=(GF2E& x, GF2 a);
100GF2E& operator-=(GF2E& x, long a);
101
102GF2E& operator--(GF2E& x); // prefix
103void operator--(GF2E& x, int); // postfix
104
105// procedural versions:
106
107void add(GF2E& x, const GF2E& a, const GF2E& b); // x = a + b
108void sub(GF2E& x, const GF2E& a, const GF2E& b); // x = a - b = a + b
109void negate(GF2E& x, const GF2E& a); // x = - a = a
110
111// PROMOTIONS: +, -, add, sub promote {long, GF2} to GF2E on (a, b).
112
113
114/**************************************************************************\
115
116                                  Multiplication
117
118\**************************************************************************/
119
120
121// operator notation:
122
123GF2E operator*(const GF2E& a, const GF2E& b);
124
125GF2E& operator*=(GF2E& x, const GF2E& a);
126GF2E& operator*=(GF2E& x, GF2 a);
127GF2E& operator*=(GF2E& x, long a);
128
129// procedural versions:
130
131
132void mul(GF2E& x, const GF2E& a, const GF2E& b); // x = a * b
133
134void sqr(GF2E& x, const GF2E& a); // x = a^2
135GF2E sqr(const GF2E& a);
136
137// PROMOTIONS: *, mul promote {long, GF2} to GF2E on (a, b).
138
139
140/**************************************************************************\
141
142                                     Division
143
144\**************************************************************************/
145
146
147// operator notation:
148
149GF2E operator/(const GF2E& a, const GF2E& b);
150
151GF2E& operator/=(GF2E& x, const GF2E& a);
152GF2E& operator/=(GF2E& x, GF2 a);
153GF2E& operator/=(GF2E& x, long a);
154
155
156// procedural versions:
157
158void div(GF2E& x, const GF2E& a, const GF2E& b);
159// x = a/b.  If b is not invertible, an error is raised.
160
161void inv(GF2E& x, const GF2E& a);
162GF2E inv(const GF2E& a);
163// x = 1/a
164
165PROMOTIONS: /, div promote {long, GF2} to GF2E on (a, b).
166
167
168/**************************************************************************\
169
170                                  Exponentiation
171
172\**************************************************************************/
173
174
175
176void power(GF2E& x, const GF2E& a, const ZZ& e);
177GF2E power(const GF2E& a, const ZZ& e);
178
179void power(GF2E& x, const GF2E& a, long e);
180GF2E power(const GF2E& a, long e);
181
182// x = a^e (e may be negative)
183
184
185
186/**************************************************************************\
187
188                               Random Elements
189
190\**************************************************************************/
191
192
193void random(GF2E& x);
194GF2E random_GF2E();
195// x = random element in GF2E.
196
197/**************************************************************************\
198
199                                  Traces
200
201\**************************************************************************/
202
203
204void trace(GF2& x, const GF2E& a);  // x = trace of a
205GF2 trace(const GF2E& a);
206
207
208
209/**************************************************************************\
210
211                                Input/Output
212
213\**************************************************************************/
214
215
216ostream& operator<<(ostream& s, const GF2E& a);
217
218istream& operator>>(istream& s, GF2E& x);
219// a GF2X is read and reduced mod p
220
221
222/**************************************************************************\
223
224                       Modulus Switching
225
226A class GF2EBak is provided for "backing up" the current modulus.
227
228Here is what you do to save the current modulus, temporarily
229set it to something new, and then restore it:
230
231   GF2EBak bak;
232   bak.save();   // save current modulus (if any)
233
234   GF2E::init(P);  // set modulus to desired value P
235
236      // ...
237
238   bak.restore(); // restore old modulus (if any)
239
240Note that between the save and restore, you may have several calls to
241GF2E::init, each of which simply clobbers the previous modulus.
242
243The GF2EBak interface is good for implementing simple stack-like
244modulus "context switching".  For more general context switching,
245see GF2EContext below.
246
247..........................................................................
248
249When the current modulus is changed, there may be extant
250GF2E objects. If the old modulus was saved and then later restored,
251these objects can be used again as if the modulus had never changed. 
252Note, however, that if a GF2E object is created under one modulus
253and then used in any way (except destroyed) under another,
254program behavior is not predictable.  This condition is not
255explicitly checked for, but an error is likely to be raised.
256One should also not presume that things will work properly
257if the modulus is changed, but its value happens to be the same---
258one should restore the same "context", from either a GF2EBak
259or a GF2EContext object.  This is anyway more efficient.
260
261\**************************************************************************/
262
263
264
265
266class GF2EBak {
267public:
268
269   // To describe this logic, think of a GF2EBak object
270   // of having two components: a modulus Q (possibly "null") and
271   // an "auto-restore bit" b.
272
273   // There is also a global current modulus P (initially "null").
274
275   GF2EBak();  // Q = "null", b = 0
276
277   ~GF2EBak();  // if (b) P = Q
278
279   void save();  // Q = P, b = 1
280   void restore();  // P = Q, b = 0
281
282
283private:
284   GF2EBak(const GF2EBak&);  // copy disabled
285   void operator=(const GF2EBak&);  // assignment disabled
286};
287
288
289// more general context switching:
290
291class GF2EContext {
292
293// A GF2EContext object has a modulus Q (possibly "null"),
294// but has no auto-restore bit like a GF2EBak object.
295// However, these objects can be initialized and copied with
296// complete generality.
297
298// As above, P is the current global modulus (initially "null")
299
300public:
301
302GF2EContext(); // Q = "null"
303GF2EContext(const GF2X& new_Q); // Q = new_Q
304
305void save(); // Q = P
306void restore() const; // P = Q
307
308GF2EContext(const GF2EContext&);  // copy
309GF2EContext& operator=(const GF2EContext&); // assignment
310~GF2EContext(); // destructor
311
312
313};
314
315
316/**************************************************************************\
317
318                               Miscellany
319
320\**************************************************************************/
321
322void clear(GF2E& x); // x = 0
323void set(GF2E& x); // x = 1
324
325static const GF2E& GF2E::zero();
326// GF2E::zero() yields a read-only reference to zero
327
328static long GF2X::WordLength();
329// GF2E::size() returns # of words needed to store a polynomial of
330// degree < GF2E::degree()
331
332void swap(GF2E& x, GF2E& y);
333// swap x and y (done by "pointer swapping", if possible).
334
335static ZZ& GF2E::cardinality();
336// yields the cardinality, i.e., 2^{GF2E::degree()}
337
Note: See TracBrowser for help on using the repository browser.