1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: factory.h,v 1.3 1997-12-08 16:43:48 schmidt Exp $ */ |
---|
3 | |
---|
4 | #ifndef INCL_FACTORY_H |
---|
5 | #define INCL_FACTORY_H |
---|
6 | |
---|
7 | //{{{ docu |
---|
8 | // |
---|
9 | // factory.template - template to generate `factory.h'. |
---|
10 | // |
---|
11 | // `factory.h' is the user interface to Factory. Created |
---|
12 | // automatically by `makeheader', it collects all important |
---|
13 | // declarations from all important Factory header files into one |
---|
14 | // overall header file leaving out all boring Factory internal |
---|
15 | // stuff. See `./bin/makeheader' for an explanation of the syntax |
---|
16 | // of this file. |
---|
17 | // |
---|
18 | // Note: In this file the order of "includes" matters (since this |
---|
19 | // are not real includes)! In general, files at the end depend |
---|
20 | // on files at the beginning. |
---|
21 | // |
---|
22 | // ---RS--- |
---|
23 | // This is the specialized version of factory.h for Windows NT |
---|
24 | // ---RS--- |
---|
25 | // |
---|
26 | //}}} |
---|
27 | |
---|
28 | #include <factoryconf.h> |
---|
29 | |
---|
30 | #ifndef NOSTREAMIO |
---|
31 | #include <iostream.h> |
---|
32 | #endif /* ! NOSTREAMIO */ |
---|
33 | |
---|
34 | #ifdef SINGULAR |
---|
35 | extern "C" { |
---|
36 | #include <gmp.h> |
---|
37 | } |
---|
38 | #endif /* SINGULAR */ |
---|
39 | |
---|
40 | #ifdef macintosh |
---|
41 | #include <::templates:ftmpl_array.h> |
---|
42 | #include <::templates:ftmpl_factor.h> |
---|
43 | #include <::templates:ftmpl_list.h> |
---|
44 | #include <::templates:ftmpl_matrix.h> |
---|
45 | #else |
---|
46 | #include <templates/ftmpl_array.h> |
---|
47 | #include <templates/ftmpl_factor.h> |
---|
48 | #include <templates/ftmpl_list.h> |
---|
49 | #include <templates/ftmpl_matrix.h> |
---|
50 | #endif |
---|
51 | |
---|
52 | extern const char factoryVersion[]; |
---|
53 | extern const char factoryConfiguration[]; |
---|
54 | |
---|
55 | int cf_getPrime( int i ); |
---|
56 | |
---|
57 | int cf_getNumPrimes(); |
---|
58 | |
---|
59 | int cf_getSmallPrime( int i ); |
---|
60 | |
---|
61 | int cf_getNumSmallPrimes(); |
---|
62 | |
---|
63 | int cf_getBigPrime( int i ); |
---|
64 | |
---|
65 | int cf_getNumBigPrimes(); |
---|
66 | |
---|
67 | #define LEVELBASE -1000000 |
---|
68 | #define LEVELTRANS -500000 |
---|
69 | #define LEVELQUOT 1000000 |
---|
70 | #define LEVELEXPR 1000001 |
---|
71 | |
---|
72 | #define UndefinedDomain 32000 |
---|
73 | #define PrimePowerDomain 5 |
---|
74 | #define GaloisFieldDomain 4 |
---|
75 | #define FiniteFieldDomain 3 |
---|
76 | #define RationalDomain 2 |
---|
77 | #define IntegerDomain 1 |
---|
78 | |
---|
79 | //{{{ constants |
---|
80 | //{{{ docu |
---|
81 | // |
---|
82 | // - factory switches. |
---|
83 | // |
---|
84 | //}}} |
---|
85 | const int SW_RATIONAL = 0; |
---|
86 | const int SW_QUOTIENT = 1; |
---|
87 | const int SW_SYMMETRIC_FF = 2; |
---|
88 | const int SW_BERLEKAMP = 3; |
---|
89 | const int SW_FAC_USE_BIG_PRIMES = 4; |
---|
90 | const int SW_FAC_QUADRATICLIFT = 5; |
---|
91 | const int SW_USE_EZGCD = 6; |
---|
92 | const int SW_USE_SPARSEMOD = 7; |
---|
93 | //}}} |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | class CanonicalForm; |
---|
98 | |
---|
99 | class Variable |
---|
100 | { |
---|
101 | private: |
---|
102 | int _level; |
---|
103 | Variable( int l, bool flag ); |
---|
104 | public: |
---|
105 | Variable() : _level(LEVELBASE) {} |
---|
106 | Variable( int l ); |
---|
107 | Variable( char name ); |
---|
108 | Variable( int l, char name ); |
---|
109 | Variable( const Variable & v ) : _level(v._level) {} |
---|
110 | ~Variable() {}; |
---|
111 | Variable& operator= ( const Variable & v ) |
---|
112 | { |
---|
113 | _level = v._level; |
---|
114 | return *this; |
---|
115 | } |
---|
116 | int level() const { return _level; } |
---|
117 | char name() const; |
---|
118 | static Variable highest() { return Variable( LEVELQUOT-1 ); } |
---|
119 | Variable next() const { return Variable( _level+1 ); } |
---|
120 | friend bool operator == ( const Variable & lhs, const Variable & rhs ) |
---|
121 | { |
---|
122 | return lhs._level == rhs._level; |
---|
123 | } |
---|
124 | friend bool operator != ( const Variable & lhs, const Variable & rhs ) |
---|
125 | { |
---|
126 | return lhs._level != rhs._level; |
---|
127 | } |
---|
128 | friend bool operator > ( const Variable & lhs, const Variable & rhs ) |
---|
129 | { |
---|
130 | return lhs._level > rhs._level; |
---|
131 | } |
---|
132 | friend bool operator < ( const Variable & lhs, const Variable & rhs ) |
---|
133 | { |
---|
134 | return lhs._level < rhs._level; |
---|
135 | } |
---|
136 | friend bool operator >= ( const Variable & lhs, const Variable & rhs ) |
---|
137 | { |
---|
138 | return lhs._level >= rhs._level; |
---|
139 | } |
---|
140 | friend bool operator <= ( const Variable & lhs, const Variable & rhs ) |
---|
141 | { |
---|
142 | return lhs._level <= rhs._level; |
---|
143 | } |
---|
144 | #ifndef NOSTREAMIO |
---|
145 | friend ostream & operator << ( ostream & os, const Variable & v ); |
---|
146 | #endif /* NOSTREAMIO */ |
---|
147 | friend Variable rootOf( const CanonicalForm &, char name = '@' ); |
---|
148 | }; |
---|
149 | |
---|
150 | inline int level( const Variable & v ) { return v.level(); } |
---|
151 | inline char name( const Variable & v ) { return v.name(); } |
---|
152 | |
---|
153 | CanonicalForm getMipo( const Variable & alpha, const Variable & x ); |
---|
154 | |
---|
155 | char getDefaultVarName(); |
---|
156 | char getDefaultExtName(); |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | int initCanonicalForm( void ); |
---|
161 | |
---|
162 | static int cf_is_initialized_now = initCanonicalForm(); |
---|
163 | |
---|
164 | class InternalCF; |
---|
165 | |
---|
166 | //{{{ class CanonicalForm |
---|
167 | class CanonicalForm |
---|
168 | { |
---|
169 | private: |
---|
170 | InternalCF *value; |
---|
171 | public: |
---|
172 | // constructors, destructors, selectors |
---|
173 | CanonicalForm(); |
---|
174 | CanonicalForm( const CanonicalForm& ); |
---|
175 | CanonicalForm( InternalCF* ); |
---|
176 | CanonicalForm( const int ); |
---|
177 | CanonicalForm( const Variable & ); |
---|
178 | CanonicalForm( const Variable &, int ); |
---|
179 | CanonicalForm( const char * ); // use with caution - does only handle integers !!! |
---|
180 | |
---|
181 | ~CanonicalForm(); |
---|
182 | |
---|
183 | InternalCF* getval() const; // use with caution !!! |
---|
184 | |
---|
185 | CanonicalForm deepCopy() const; |
---|
186 | |
---|
187 | // predicates |
---|
188 | bool isOne() const; |
---|
189 | bool isZero() const; |
---|
190 | bool isImm() const; |
---|
191 | |
---|
192 | bool inZ() const; |
---|
193 | bool inQ() const; |
---|
194 | bool inFF() const; |
---|
195 | bool inGF() const; |
---|
196 | bool inPP() const; |
---|
197 | bool inBaseDomain() const; |
---|
198 | bool inExtension() const; |
---|
199 | bool inCoeffDomain() const; |
---|
200 | bool inPolyDomain() const; |
---|
201 | bool inQuotDomain() const; |
---|
202 | |
---|
203 | bool isFFinGF() const; |
---|
204 | bool isUnivariate() const; |
---|
205 | |
---|
206 | // conversion functions |
---|
207 | int intval() const; |
---|
208 | CanonicalForm mapinto () const; |
---|
209 | |
---|
210 | CanonicalForm lc () const; |
---|
211 | CanonicalForm Lc () const; |
---|
212 | CanonicalForm LC () const; |
---|
213 | CanonicalForm LC ( const Variable & v ) const; |
---|
214 | |
---|
215 | int degree () const; |
---|
216 | int degree ( const Variable & v ) const; |
---|
217 | |
---|
218 | CanonicalForm tailcoeff () const; |
---|
219 | int taildegree () const; |
---|
220 | |
---|
221 | int level () const; |
---|
222 | Variable mvar () const; |
---|
223 | |
---|
224 | CanonicalForm num () const; |
---|
225 | CanonicalForm den () const; |
---|
226 | |
---|
227 | // assignment operators |
---|
228 | CanonicalForm& operator = ( const CanonicalForm& ); |
---|
229 | CanonicalForm& operator = ( const int ); |
---|
230 | |
---|
231 | CanonicalForm& operator += ( const CanonicalForm& ); |
---|
232 | CanonicalForm& operator -= ( const CanonicalForm& ); |
---|
233 | CanonicalForm& operator *= ( const CanonicalForm& ); |
---|
234 | CanonicalForm& operator /= ( const CanonicalForm& ); |
---|
235 | CanonicalForm& operator %= ( const CanonicalForm& ); |
---|
236 | CanonicalForm& div ( const CanonicalForm& ); |
---|
237 | CanonicalForm& mod ( const CanonicalForm& ); |
---|
238 | |
---|
239 | // evaluation operators |
---|
240 | CanonicalForm operator () ( const CanonicalForm & f ) const; |
---|
241 | CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const; |
---|
242 | |
---|
243 | CanonicalForm operator [] ( int i ) const; |
---|
244 | |
---|
245 | CanonicalForm deriv() const; |
---|
246 | CanonicalForm deriv( const Variable & x ) const; |
---|
247 | |
---|
248 | int sign() const; |
---|
249 | CanonicalForm sqrt() const; |
---|
250 | int ilog2() const; |
---|
251 | bool hasGcd() const { return false; } |
---|
252 | CanonicalForm gcd( const CanonicalForm & f ) const; |
---|
253 | |
---|
254 | // comparison operators |
---|
255 | friend bool operator == ( const CanonicalForm&, const CanonicalForm& ); |
---|
256 | friend bool operator != ( const CanonicalForm&, const CanonicalForm& ); |
---|
257 | friend bool operator > ( const CanonicalForm&, const CanonicalForm& ); |
---|
258 | friend bool operator < ( const CanonicalForm&, const CanonicalForm& ); |
---|
259 | |
---|
260 | // arithmetic operators |
---|
261 | friend CanonicalForm operator - ( const CanonicalForm& ); |
---|
262 | |
---|
263 | friend CanonicalForm operator + ( const CanonicalForm&, const CanonicalForm& ); |
---|
264 | friend CanonicalForm operator - ( const CanonicalForm&, const CanonicalForm& ); |
---|
265 | friend CanonicalForm operator * ( const CanonicalForm&, const CanonicalForm& ); |
---|
266 | friend CanonicalForm operator / ( const CanonicalForm&, const CanonicalForm& ); |
---|
267 | friend CanonicalForm operator % ( const CanonicalForm&, const CanonicalForm& ); |
---|
268 | |
---|
269 | friend CanonicalForm div ( const CanonicalForm&, const CanonicalForm& ); |
---|
270 | friend CanonicalForm mod ( const CanonicalForm&, const CanonicalForm& ); |
---|
271 | |
---|
272 | friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
273 | friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
274 | |
---|
275 | #ifndef NOSTREAMIO |
---|
276 | void print( ostream&, char * ) const; |
---|
277 | friend ostream& operator << ( ostream&, const CanonicalForm& ); |
---|
278 | friend istream& operator >> ( istream&, CanonicalForm& ); |
---|
279 | #endif /* NOSTREAMIO */ |
---|
280 | |
---|
281 | // obsolete methods |
---|
282 | static CanonicalForm genCoeff( int what, int i = 0 ); |
---|
283 | CanonicalForm genZero() const; |
---|
284 | CanonicalForm genOne() const; |
---|
285 | |
---|
286 | friend class CFIterator; |
---|
287 | }; |
---|
288 | //}}} |
---|
289 | |
---|
290 | // some useful functions |
---|
291 | |
---|
292 | //{{{ function declarations from canonicalform.cc |
---|
293 | CanonicalForm power ( const CanonicalForm & f, int n ); |
---|
294 | |
---|
295 | CanonicalForm power ( const Variable & v, int n ); |
---|
296 | |
---|
297 | bool divides ( const CanonicalForm & f, const CanonicalForm & g ); |
---|
298 | //}}} |
---|
299 | |
---|
300 | //{{{ function declarations from cf_gcd.cc |
---|
301 | CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& ); |
---|
302 | |
---|
303 | CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
304 | |
---|
305 | CanonicalForm iextgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
306 | |
---|
307 | CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& ); |
---|
308 | |
---|
309 | CanonicalForm pp ( const CanonicalForm& ); |
---|
310 | |
---|
311 | CanonicalForm content ( const CanonicalForm& ); |
---|
312 | |
---|
313 | CanonicalForm content ( const CanonicalForm&, const Variable& ); |
---|
314 | |
---|
315 | CanonicalForm icontent ( const CanonicalForm & f ); |
---|
316 | //}}} |
---|
317 | |
---|
318 | //{{{ function declarations from cf_ops.cc |
---|
319 | CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
320 | |
---|
321 | CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
322 | |
---|
323 | int getNumVars( const CanonicalForm & f ); |
---|
324 | |
---|
325 | CanonicalForm getVars( const CanonicalForm & f ); |
---|
326 | |
---|
327 | CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ); |
---|
328 | |
---|
329 | CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ); |
---|
330 | |
---|
331 | int * degrees ( const CanonicalForm & f, int * degs = 0 ); |
---|
332 | |
---|
333 | int totaldegree ( const CanonicalForm & f ); |
---|
334 | |
---|
335 | int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 ); |
---|
336 | |
---|
337 | int size ( const CanonicalForm & f, const Variable & v ); |
---|
338 | |
---|
339 | int size ( const CanonicalForm & f ); |
---|
340 | //}}} |
---|
341 | |
---|
342 | //{{{ inline functions corresponding to CanonicalForm methods |
---|
343 | //{{{ docu |
---|
344 | // |
---|
345 | // - inline functions corresponding to CanonicalForm methods. |
---|
346 | // |
---|
347 | // These function exist for convenience only and because it is |
---|
348 | // more beautiful to write 'degree( f )' than 'f.degree()'. |
---|
349 | // |
---|
350 | //}}} |
---|
351 | inline CanonicalForm |
---|
352 | lc ( const CanonicalForm & f ) { return f.lc(); } |
---|
353 | |
---|
354 | inline CanonicalForm |
---|
355 | Lc ( const CanonicalForm & f ) { return f.Lc(); } |
---|
356 | |
---|
357 | inline CanonicalForm |
---|
358 | LC ( const CanonicalForm & f ) { return f.LC(); } |
---|
359 | |
---|
360 | inline CanonicalForm |
---|
361 | LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); } |
---|
362 | |
---|
363 | inline int |
---|
364 | degree ( const CanonicalForm & f ) { return f.degree(); } |
---|
365 | |
---|
366 | inline int |
---|
367 | degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); } |
---|
368 | |
---|
369 | inline int |
---|
370 | taildegree ( const CanonicalForm & f ) { return f.taildegree(); } |
---|
371 | |
---|
372 | inline CanonicalForm |
---|
373 | tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); } |
---|
374 | |
---|
375 | inline int |
---|
376 | level ( const CanonicalForm & f ) { return f.level(); } |
---|
377 | |
---|
378 | inline CanonicalForm |
---|
379 | mvar ( const CanonicalForm & f ) { return f.mvar(); } |
---|
380 | |
---|
381 | inline CanonicalForm |
---|
382 | num ( const CanonicalForm & f ) { return f.num(); } |
---|
383 | |
---|
384 | inline CanonicalForm |
---|
385 | den ( const CanonicalForm & f ) { return f.den(); } |
---|
386 | |
---|
387 | inline CanonicalForm |
---|
388 | deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); } |
---|
389 | |
---|
390 | inline CanonicalForm |
---|
391 | sqrt ( const CanonicalForm & a ) { return a.sqrt(); } |
---|
392 | |
---|
393 | inline int |
---|
394 | ilog2 ( const CanonicalForm & a ) { return a.ilog2(); } |
---|
395 | |
---|
396 | inline CanonicalForm |
---|
397 | mapinto ( const CanonicalForm & f ) { return f.mapinto(); } |
---|
398 | //}}} |
---|
399 | |
---|
400 | //{{{ inline functions |
---|
401 | inline CanonicalForm |
---|
402 | head ( const CanonicalForm & f ) |
---|
403 | { |
---|
404 | if ( f.level() > 0 ) |
---|
405 | return power( f.mvar(), f.degree() ) * f.LC(); |
---|
406 | else |
---|
407 | return f; |
---|
408 | } |
---|
409 | |
---|
410 | inline CanonicalForm |
---|
411 | abs ( const CanonicalForm & f ) |
---|
412 | { |
---|
413 | if ( f < 0 ) |
---|
414 | return -f; |
---|
415 | else |
---|
416 | return f; |
---|
417 | } |
---|
418 | |
---|
419 | inline int |
---|
420 | headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); } |
---|
421 | //}}} |
---|
422 | |
---|
423 | //{{{ other function declarations |
---|
424 | void setCharacteristic( int c ); // -> Fp && Q |
---|
425 | void setCharacteristic( int c, int n ); // -> PrimePower |
---|
426 | void setCharacteristic( int c, int n, char name ); // -> GF(q) |
---|
427 | |
---|
428 | int getCharacteristic(); |
---|
429 | int getGFDegree(); |
---|
430 | CanonicalForm getGFGenerator(); |
---|
431 | |
---|
432 | void On( int ); |
---|
433 | void Off( int ); |
---|
434 | bool isOn( int ); |
---|
435 | //}}} |
---|
436 | |
---|
437 | //{{{ type definitions |
---|
438 | typedef Factor<CanonicalForm> CFFactor; |
---|
439 | typedef List<CFFactor> CFFList; |
---|
440 | typedef ListIterator<CFFactor> CFFListIterator; |
---|
441 | typedef List<CanonicalForm> CFList; |
---|
442 | typedef ListIterator<CanonicalForm> CFListIterator; |
---|
443 | typedef Array<CanonicalForm> CFArray; |
---|
444 | typedef Matrix<CanonicalForm> CFMatrix; |
---|
445 | //}}} |
---|
446 | |
---|
447 | |
---|
448 | CanonicalForm binomialpower ( const Variable&, const CanonicalForm&, int ); |
---|
449 | |
---|
450 | //{{{ function declarations from cf_algorithm.cc |
---|
451 | CanonicalForm psr ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
452 | |
---|
453 | CanonicalForm psq ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
454 | |
---|
455 | void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r, const Variable & x ); |
---|
456 | |
---|
457 | CanonicalForm common_den ( const CanonicalForm & f ); |
---|
458 | //}}} |
---|
459 | |
---|
460 | //{{{ function declarations from cf_chinese.cc |
---|
461 | void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2, const CanonicalForm & q2, CanonicalForm & xnew, CanonicalForm & qnew ); |
---|
462 | |
---|
463 | void chineseRemainder ( const CFArray & x, const CFArray & q, CanonicalForm & xnew, CanonicalForm & qnew ); |
---|
464 | //}}} |
---|
465 | |
---|
466 | //{{{ function declarations from cf_factor.cc |
---|
467 | CFFList factorize ( const CanonicalForm & f, bool issqrfree = false ); |
---|
468 | |
---|
469 | CFFList factorize ( const CanonicalForm & f, const Variable & alpha ); |
---|
470 | |
---|
471 | CFFList sqrFree ( const CanonicalForm & f, bool sort = false ); |
---|
472 | |
---|
473 | bool isSqrFree ( const CanonicalForm & f ); |
---|
474 | //}}} |
---|
475 | |
---|
476 | //{{{ function declarations from cf_linsys.cc |
---|
477 | bool linearSystemSolve ( CFMatrix & M ); |
---|
478 | |
---|
479 | CanonicalForm determinant ( const CFMatrix & M, int n ); |
---|
480 | //}}} |
---|
481 | |
---|
482 | //{{{ function declarations from cf_resultant.cc |
---|
483 | CFArray subResChain ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
484 | |
---|
485 | CanonicalForm resultant ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
486 | //}}} |
---|
487 | |
---|
488 | |
---|
489 | |
---|
490 | class Evaluation |
---|
491 | { |
---|
492 | protected: |
---|
493 | CFArray values; |
---|
494 | public: |
---|
495 | Evaluation() : values() {} |
---|
496 | Evaluation( int min, int max ) : values( min, max ) {} |
---|
497 | Evaluation( const Evaluation & e ) : values( e.values ) {} |
---|
498 | virtual ~Evaluation() {} |
---|
499 | Evaluation& operator= ( const Evaluation & e ); |
---|
500 | int min() const { return values.min(); } |
---|
501 | int max() const { return values.max(); } |
---|
502 | CanonicalForm operator[] ( int i ) const { return values[i]; } |
---|
503 | CanonicalForm operator[] ( const Variable & v ) const { return operator[](v.level()); } |
---|
504 | CanonicalForm operator() ( const CanonicalForm& f ) const; |
---|
505 | CanonicalForm operator() ( const CanonicalForm & f, int i, int j ) const; |
---|
506 | virtual void nextpoint(); |
---|
507 | #ifndef NOSTREAMIO |
---|
508 | friend ostream& operator<< ( ostream& s, const Evaluation &e ); |
---|
509 | #endif /* NOSTREAMIO */ |
---|
510 | }; |
---|
511 | |
---|
512 | |
---|
513 | |
---|
514 | class CFGenerator |
---|
515 | { |
---|
516 | public: |
---|
517 | CFGenerator() {} |
---|
518 | virtual ~CFGenerator() {} |
---|
519 | virtual bool hasItems() const { return false; } |
---|
520 | virtual void reset() {}; |
---|
521 | virtual CanonicalForm item() const { return 0; } |
---|
522 | virtual void next() {}; |
---|
523 | }; |
---|
524 | |
---|
525 | class FFGenerator : public CFGenerator |
---|
526 | { |
---|
527 | private: |
---|
528 | int current; |
---|
529 | public: |
---|
530 | FFGenerator() : current(0) {} |
---|
531 | ~FFGenerator() {} |
---|
532 | bool hasItems() const; |
---|
533 | void reset() { current = 0; } |
---|
534 | CanonicalForm item() const; |
---|
535 | void next(); |
---|
536 | void operator++ () { next(); } |
---|
537 | void operator++ ( int ) { next(); } |
---|
538 | }; |
---|
539 | |
---|
540 | class GFGenerator : public CFGenerator |
---|
541 | { |
---|
542 | private: |
---|
543 | int current; |
---|
544 | public: |
---|
545 | GFGenerator(); |
---|
546 | ~GFGenerator() {} |
---|
547 | bool hasItems() const; |
---|
548 | void reset(); |
---|
549 | CanonicalForm item() const; |
---|
550 | void next(); |
---|
551 | void operator++ () { next(); } |
---|
552 | void operator++ ( int ) { next(); } |
---|
553 | }; |
---|
554 | |
---|
555 | class AlgExtGenerator : public CFGenerator |
---|
556 | { |
---|
557 | private: |
---|
558 | Variable algext; |
---|
559 | CFGenerator **gens; |
---|
560 | int n; |
---|
561 | bool nomoreitems; |
---|
562 | AlgExtGenerator(); |
---|
563 | AlgExtGenerator( const AlgExtGenerator & ); |
---|
564 | AlgExtGenerator& operator= ( const AlgExtGenerator & ); |
---|
565 | public: |
---|
566 | AlgExtGenerator( const Variable & a ); |
---|
567 | ~AlgExtGenerator(); |
---|
568 | |
---|
569 | bool hasItems() const { return ! nomoreitems; } |
---|
570 | void reset(); |
---|
571 | CanonicalForm item() const; |
---|
572 | void next(); |
---|
573 | void operator++ () { next(); } |
---|
574 | void operator++ ( int ) { next(); } |
---|
575 | }; |
---|
576 | |
---|
577 | class CFGenFactory |
---|
578 | { |
---|
579 | public: |
---|
580 | static CFGenerator* generate(); |
---|
581 | }; |
---|
582 | |
---|
583 | |
---|
584 | class term; |
---|
585 | typedef term * termList; |
---|
586 | |
---|
587 | class CFIterator { |
---|
588 | private: |
---|
589 | CanonicalForm data; |
---|
590 | termList cursor; |
---|
591 | bool ispoly, hasterms; |
---|
592 | public: |
---|
593 | CFIterator (); |
---|
594 | CFIterator ( const CFIterator& ); |
---|
595 | CFIterator ( const CanonicalForm& ); |
---|
596 | CFIterator ( const CanonicalForm&, const Variable& ); |
---|
597 | |
---|
598 | ~CFIterator (); |
---|
599 | |
---|
600 | CFIterator& operator= ( const CFIterator& ); |
---|
601 | CFIterator& operator= ( const CanonicalForm& ); |
---|
602 | |
---|
603 | CFIterator& operator++ (); |
---|
604 | CFIterator& operator++ ( int ); |
---|
605 | int hasTerms () const; |
---|
606 | CanonicalForm coeff () const; |
---|
607 | int exp () const; |
---|
608 | }; |
---|
609 | |
---|
610 | |
---|
611 | |
---|
612 | |
---|
613 | class CFRandom { |
---|
614 | public: |
---|
615 | virtual ~CFRandom() {} |
---|
616 | virtual CanonicalForm generate() const { return 0; } |
---|
617 | virtual CFRandom * clone() const { return new CFRandom(); } |
---|
618 | }; |
---|
619 | |
---|
620 | class GFRandom : public CFRandom |
---|
621 | { |
---|
622 | public: |
---|
623 | GFRandom() {}; |
---|
624 | ~GFRandom() {} |
---|
625 | CanonicalForm generate() const; |
---|
626 | CFRandom * clone() const; |
---|
627 | }; |
---|
628 | |
---|
629 | class FFRandom : public CFRandom |
---|
630 | { |
---|
631 | public: |
---|
632 | FFRandom() {} |
---|
633 | ~FFRandom() {} |
---|
634 | CanonicalForm generate() const; |
---|
635 | CFRandom * clone() const; |
---|
636 | }; |
---|
637 | |
---|
638 | class IntRandom : public CFRandom |
---|
639 | { |
---|
640 | private: |
---|
641 | int max; |
---|
642 | public: |
---|
643 | IntRandom(); |
---|
644 | IntRandom( int m ); |
---|
645 | ~IntRandom(); |
---|
646 | CanonicalForm generate() const; |
---|
647 | CFRandom * clone() const; |
---|
648 | }; |
---|
649 | |
---|
650 | class AlgExtRandomF : public CFRandom { |
---|
651 | private: |
---|
652 | Variable algext; |
---|
653 | CFRandom * gen; |
---|
654 | int n; |
---|
655 | AlgExtRandomF(); |
---|
656 | AlgExtRandomF( const AlgExtRandomF & ); |
---|
657 | AlgExtRandomF( const Variable & v, CFRandom * g, int nn ); |
---|
658 | AlgExtRandomF& operator= ( const AlgExtRandomF & ); |
---|
659 | public: |
---|
660 | AlgExtRandomF( const Variable & v ); |
---|
661 | AlgExtRandomF( const Variable & v1, const Variable & v2 ); |
---|
662 | ~AlgExtRandomF(); |
---|
663 | CanonicalForm generate() const; |
---|
664 | CFRandom * clone() const; |
---|
665 | }; |
---|
666 | |
---|
667 | class CFRandomFactory { |
---|
668 | public: |
---|
669 | static CFRandom * generate(); |
---|
670 | }; |
---|
671 | |
---|
672 | int factoryrandom( int n ); |
---|
673 | |
---|
674 | void factoryseed( int s ); |
---|
675 | |
---|
676 | |
---|
677 | |
---|
678 | CanonicalForm find_irreducible ( int deg, CFRandom & gen, const Variable & x ); |
---|
679 | |
---|
680 | |
---|
681 | |
---|
682 | class modpk |
---|
683 | { |
---|
684 | private: |
---|
685 | CanonicalForm pk; |
---|
686 | CanonicalForm pkhalf; |
---|
687 | int p; |
---|
688 | int k; |
---|
689 | public: |
---|
690 | modpk(); |
---|
691 | modpk( int q, int l ); |
---|
692 | modpk( const modpk & m ); |
---|
693 | modpk& operator= ( const modpk& m ); |
---|
694 | ~modpk() {} |
---|
695 | int getp() const { return p; } |
---|
696 | int getk() const { return k; } |
---|
697 | CanonicalForm inverse( const CanonicalForm & f, bool symmetric = true ) const; |
---|
698 | CanonicalForm getpk() const { return pk; } |
---|
699 | CanonicalForm operator() ( const CanonicalForm & f, bool symmetric = true ) const; |
---|
700 | }; |
---|
701 | |
---|
702 | |
---|
703 | CanonicalForm replaceLc( const CanonicalForm & f, const CanonicalForm & c ); |
---|
704 | |
---|
705 | CanonicalForm remainder( const CanonicalForm & f, const CanonicalForm & g, const modpk & pk ); |
---|
706 | |
---|
707 | void divremainder( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & quot, CanonicalForm & rem, const modpk & pk ); |
---|
708 | |
---|
709 | CanonicalForm maxCoeff( const CanonicalForm & f ); |
---|
710 | |
---|
711 | bool Hensel ( const CanonicalForm & U, CFArray & G, const CFArray & lcG, const Evaluation & A, const modpk & bound, const Variable & x ); |
---|
712 | |
---|
713 | /* some special array functions */ |
---|
714 | |
---|
715 | CanonicalForm sum ( const CFArray & a, int f, int l ); |
---|
716 | |
---|
717 | CanonicalForm prod ( const CFArray & a, int f, int l ); |
---|
718 | |
---|
719 | CanonicalForm sum ( const CFArray & a ); |
---|
720 | |
---|
721 | CanonicalForm prod ( const CFArray & a ); |
---|
722 | |
---|
723 | CanonicalForm crossprod ( const CFArray & a, const CFArray & b ); |
---|
724 | |
---|
725 | |
---|
726 | //{{{ class MapPair |
---|
727 | //{{{ docu |
---|
728 | // |
---|
729 | // class MapPair - stores one mapping pair (Variable -> CanonicalForm). |
---|
730 | // |
---|
731 | // This class is only used to store such pairs. It has no |
---|
732 | // methods to transform a CanonicalForm as the class CFMap has. |
---|
733 | // |
---|
734 | // V, S: the pair (V -> S) |
---|
735 | // |
---|
736 | //}}} |
---|
737 | //{{{ inline method docu |
---|
738 | // |
---|
739 | // Variable var () const |
---|
740 | // CanonicalForm subst () const |
---|
741 | // |
---|
742 | // var(), subst() - selectors, return V and P, resp. |
---|
743 | // |
---|
744 | //}}} |
---|
745 | class MapPair |
---|
746 | { |
---|
747 | private: |
---|
748 | Variable V; |
---|
749 | CanonicalForm S; |
---|
750 | public: |
---|
751 | MapPair ( const Variable & v, const CanonicalForm & s ) : V(v), S(s) {} |
---|
752 | MapPair () : V(), S(1) {} |
---|
753 | MapPair ( const MapPair & p ) : V(p.V), S(p.S) {} |
---|
754 | ~MapPair () {} |
---|
755 | MapPair & operator = ( const MapPair & p ); |
---|
756 | Variable var () const { return V; } |
---|
757 | CanonicalForm subst () const { return S; } |
---|
758 | #ifndef NOSTREAMIO |
---|
759 | friend ostream & operator << ( ostream & s, const MapPair & p ); |
---|
760 | #endif /* NOSTREAMIO */ |
---|
761 | }; |
---|
762 | //}}} |
---|
763 | |
---|
764 | typedef List<MapPair> MPList; |
---|
765 | typedef ListIterator<MapPair> MPListIterator; |
---|
766 | |
---|
767 | //{{{ class CFMap |
---|
768 | //{{{ docu |
---|
769 | // |
---|
770 | // class CFMap - class to map canonical forms. |
---|
771 | // |
---|
772 | // Use an object of class CFMap to insert 'values' into canonical |
---|
773 | // form. Such a mapping is defined by a list of MapPairs (V -> S) |
---|
774 | // describing which canonical form S to insert for variable V. |
---|
775 | // Hereby, the substituted canonical forms are not subject to |
---|
776 | // further substitutions. |
---|
777 | // |
---|
778 | // P: list of MapPairs, sorted by level in descending order |
---|
779 | // |
---|
780 | //}}} |
---|
781 | class CFMap |
---|
782 | { |
---|
783 | private: |
---|
784 | MPList P; |
---|
785 | public: |
---|
786 | CFMap () {} |
---|
787 | CFMap ( const CanonicalForm & s ) : P( MapPair( Variable(), s ) ) {} |
---|
788 | CFMap ( const Variable & v ) : P( MapPair( v, 1 ) ) {} |
---|
789 | CFMap ( const Variable & v, const CanonicalForm & s ) : P( MapPair( v, s ) ) {} |
---|
790 | ~CFMap () {} |
---|
791 | CFMap ( const CFList & L ); |
---|
792 | CFMap ( const CFMap & m ) : P( m.P ) {} |
---|
793 | CFMap & operator = ( const CFMap & m ); |
---|
794 | void newpair ( const Variable & v, const CanonicalForm & s ); |
---|
795 | CanonicalForm operator () ( const CanonicalForm & f ) const; |
---|
796 | #ifndef NOSTREAMIO |
---|
797 | friend ostream & operator << ( ostream & s, const CFMap & m ); |
---|
798 | #endif /* NOSTREAMIO */ |
---|
799 | }; |
---|
800 | //}}} |
---|
801 | |
---|
802 | CanonicalForm compress ( const CanonicalForm & f, CFMap & m ); |
---|
803 | void compress ( const CFArray & a, CFMap & M, CFMap & N ); |
---|
804 | void compress ( const CanonicalForm & f, const CanonicalForm & g, CFMap & M, CFMap & N ); |
---|
805 | |
---|
806 | |
---|
807 | |
---|
808 | |
---|
809 | class REvaluation : public Evaluation |
---|
810 | { |
---|
811 | private: |
---|
812 | CFRandom * gen; |
---|
813 | public: |
---|
814 | REvaluation() : Evaluation(), gen(0) {} |
---|
815 | REvaluation( int min, int max, const CFRandom & sample ) : Evaluation( min, max ), gen( sample.clone() ) {} |
---|
816 | REvaluation( const REvaluation & e ); |
---|
817 | ~REvaluation(); |
---|
818 | REvaluation& operator= ( const REvaluation & e ); |
---|
819 | void nextpoint(); |
---|
820 | }; |
---|
821 | |
---|
822 | |
---|
823 | #ifdef SINGULAR |
---|
824 | |
---|
825 | |
---|
826 | int gf_gf2ff ( int a ); |
---|
827 | |
---|
828 | bool gf_isff ( int a ); |
---|
829 | |
---|
830 | |
---|
831 | |
---|
832 | MP_INT gmp_numerator ( const CanonicalForm & f ); |
---|
833 | |
---|
834 | MP_INT gmp_denominator ( const CanonicalForm & f ); |
---|
835 | |
---|
836 | CanonicalForm make_cf ( const MP_INT & n ); |
---|
837 | |
---|
838 | CanonicalForm make_cf ( const MP_INT & n, const MP_INT & d, bool normalize ); |
---|
839 | |
---|
840 | #endif /* SINGULAR */ |
---|
841 | |
---|
842 | #endif /* ! INCL_FACTORY_H */ |
---|