source: git/factory/canonicalform.h @ 90c9e3

spielwiese
Last change on this file since 90c9e3 was f224fda, checked in by Martin Lee <martinlee84@…>, 11 years ago
chg: added new templates to hold absolute factors Conflicts: factory/canonicalform.h factory/ftmpl_inst.cc
  • Property mode set to 100644
File size: 10.4 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifndef INCL_CANONICALFORM_H
4#define INCL_CANONICALFORM_H
5
6// #include "config.h"
7
8#ifndef NOSTREAMIO
9# ifdef HAVE_IOSTREAM
10#  include <iostream>
11#  define OSTREAM std::ostream
12#  define ISTREAM std::istream
13# elif defined(HAVE_IOSTREAM_H)
14#  include <iostream.h>
15#  define OSTREAM ostream
16#  define ISTREAM istream
17# endif
18#endif /* NOSTREAMIO */
19
20#include "cf_defs.h"
21#include "variable.h"
22#include <factory/cf_gmp.h>
23#include <factory/templates/ftmpl_list.h>
24#include <factory/templates/ftmpl_array.h>
25#include <factory/templates/ftmpl_afactor.h>
26#include <factory/templates/ftmpl_factor.h>
27#include <factory/templates/ftmpl_matrix.h>
28
29/*BEGINPUBLIC*/
30
31#undef CF_INLINE
32#define CF_INLINE
33#undef CF_NO_INLINE
34#define CF_NO_INLINE
35
36/*ENDPUBLIC*/
37
38#ifdef CF_USE_INLINE
39#undef CF_INLINE
40#define CF_INLINE inline
41#else
42#undef CF_INLINE
43#define CF_INLINE
44#endif
45
46/*BEGINPUBLIC*/
47
48class InternalCF;
49
50inline int is_imm ( const InternalCF * const ptr )
51{
52    // returns 0 if ptr is not immediate
53    return ( ((int)((long)ptr)) & 3 );
54}
55
56
57int initCanonicalForm( void );
58#ifndef SI_DONT_HAVE_GLOBAL_VARS
59static int cf_is_initialized_now = initCanonicalForm();
60#endif
61
62//{{{ class CanonicalForm
63class CanonicalForm
64{
65private:
66    InternalCF *value;
67public:
68    // constructors, destructors, selectors
69    CF_INLINE CanonicalForm();
70    CF_INLINE CanonicalForm( const CanonicalForm& );
71    CF_INLINE CanonicalForm( InternalCF* );
72    CF_INLINE CanonicalForm( const int );
73    CF_INLINE CanonicalForm( const long );
74    CF_INLINE CanonicalForm( const Variable & );
75    CF_INLINE CanonicalForm( const Variable &, int );
76    CanonicalForm( const char *, const int base=10 ); // use with caution - does only handle integers !!!
77
78    CF_NO_INLINE ~CanonicalForm();
79
80    InternalCF* getval() const; // use with caution !!!
81
82    CanonicalForm deepCopy() const;
83
84    void mpzval(mpz_t val) const;
85    // predicates
86    CF_NO_INLINE bool isOne() const;
87    CF_NO_INLINE bool isZero() const;
88    inline bool isImm() const { return is_imm( value ); };
89
90    bool inZ() const;
91    bool inQ() const;
92    bool inFF() const;
93    bool inGF() const;
94    bool inPP() const;
95    bool inBaseDomain() const;
96    bool inExtension() const;
97    bool inCoeffDomain() const;
98    bool inPolyDomain() const;
99    bool inQuotDomain() const;
100
101    bool isFFinGF() const;
102    bool isUnivariate() const;
103    bool isHomogeneous() const;
104
105    // conversion functions
106    long intval() const;
107    CanonicalForm mapinto () const;
108
109    CanonicalForm lc () const;
110    CanonicalForm Lc () const;
111    CanonicalForm LC () const;
112    CanonicalForm LC ( const Variable & v ) const;
113
114    int degree () const;
115    int degree ( const Variable & v ) const;
116
117    CanonicalForm tailcoeff () const;
118    CanonicalForm tailcoeff ( const Variable & v ) const;
119    int taildegree () const;
120
121    int level () const;
122    Variable mvar () const;
123
124    CanonicalForm num () const;
125    CanonicalForm den () const;
126
127    // assignment operators
128    CF_NO_INLINE CanonicalForm& operator = ( const CanonicalForm& );
129    CF_NO_INLINE CanonicalForm& operator = ( const long );
130
131    CanonicalForm& operator += ( const CanonicalForm& );
132    CanonicalForm& operator -= ( const CanonicalForm& );
133    CanonicalForm& operator *= ( const CanonicalForm& );
134    CanonicalForm& operator /= ( const CanonicalForm& );
135    CanonicalForm& operator %= ( const CanonicalForm& );
136    CanonicalForm& div ( const CanonicalForm& );
137    CanonicalForm& tryDiv (const CanonicalForm&, const CanonicalForm&, bool& );
138    CanonicalForm& mod ( const CanonicalForm& );
139
140    // evaluation operators
141    CanonicalForm operator () ( const CanonicalForm & f ) const;
142    CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const;
143
144    CanonicalForm operator [] ( int i ) const;
145
146    CanonicalForm deriv() const;
147    CanonicalForm deriv( const Variable & x ) const;
148
149    int sign() const;
150    CanonicalForm sqrt() const;
151    int ilog2() const;
152
153    // comparison operators
154    friend bool operator == ( const CanonicalForm&, const CanonicalForm& );
155    friend bool operator != ( const CanonicalForm&, const CanonicalForm& );
156    friend bool operator > ( const CanonicalForm&, const CanonicalForm& );
157    friend bool operator < ( const CanonicalForm&, const CanonicalForm& );
158
159    // arithmetic operators
160    friend CF_NO_INLINE CanonicalForm operator - ( const CanonicalForm& );
161
162    friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
163    friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
164    friend bool tryDivremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm&, const CanonicalForm&, bool& );
165
166    friend CanonicalForm bgcd ( const CanonicalForm &, const CanonicalForm & );
167    friend CanonicalForm bextgcd ( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm & );
168
169    // input/output
170#ifndef NOSTREAMIO
171   void print( OSTREAM&, char * ) const;
172   void print( OSTREAM& ) const;
173   friend OSTREAM& operator << ( OSTREAM&, const CanonicalForm& );
174   friend ISTREAM& operator >> ( ISTREAM&, CanonicalForm& );
175#endif /* NOSTREAMIO */
176
177    // obsolete methods
178    CanonicalForm genZero() const;
179    CanonicalForm genOne() const;
180
181    friend class CFIterator;
182};
183//}}}
184
185CF_INLINE CanonicalForm
186operator + ( const CanonicalForm&, const CanonicalForm& );
187
188CF_NO_INLINE CanonicalForm
189operator - ( const CanonicalForm&, const CanonicalForm& );
190
191CF_INLINE CanonicalForm
192operator * ( const CanonicalForm&, const CanonicalForm& );
193
194CF_NO_INLINE CanonicalForm
195operator / ( const CanonicalForm&, const CanonicalForm& );
196
197CF_NO_INLINE CanonicalForm
198operator % ( const CanonicalForm&, const CanonicalForm& );
199
200CF_NO_INLINE CanonicalForm
201div ( const CanonicalForm&, const CanonicalForm& );
202
203CF_NO_INLINE CanonicalForm
204mod ( const CanonicalForm&, const CanonicalForm& );
205
206/*ENDPUBLIC*/
207
208#ifdef CF_USE_INLINE
209#include "cf_inline.cc"
210#endif
211
212/*BEGINPUBLIC*/
213
214//{{{ function declarations from canonicalform.cc
215CanonicalForm blcm ( const CanonicalForm & f, const CanonicalForm & g );
216
217CanonicalForm power ( const CanonicalForm & f, int n );
218
219CanonicalForm power ( const Variable & v, int n );
220//}}}
221
222//{{{ function declarations from cf_gcd.cc
223CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& );
224
225CanonicalForm gcd_poly ( const CanonicalForm & f, const CanonicalForm & g );
226
227CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
228
229CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
230
231CanonicalForm pp ( const CanonicalForm& );
232
233CanonicalForm content ( const CanonicalForm& );
234
235CanonicalForm content ( const CanonicalForm&, const Variable& );
236
237CanonicalForm icontent ( const CanonicalForm & f );
238
239CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
240//}}}
241
242//{{{ function declarations from cf_ops.cc
243CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
244
245CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
246
247int getNumVars( const CanonicalForm & f );
248
249CanonicalForm getVars( const CanonicalForm & f );
250
251CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
252
253CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
254
255int * degrees ( const CanonicalForm & f, int * degs = 0 );
256
257int totaldegree ( const CanonicalForm & f );
258
259int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
260
261int size ( const CanonicalForm & f, const Variable & v );
262
263int size ( const CanonicalForm & f );
264
265CanonicalForm reduce ( const CanonicalForm& f, const CanonicalForm & M);
266//}}}
267
268//{{{ inline functions corresponding to CanonicalForm methods
269//{{{ docu
270//
271// - inline functions corresponding to CanonicalForm methods.
272//
273// These function exist for convenience only and because it is
274// more beautiful to write 'degree( f )' than 'f.degree()'.
275//
276//}}}
277inline CanonicalForm
278lc ( const CanonicalForm & f ) { return f.lc(); }
279
280inline CanonicalForm
281Lc ( const CanonicalForm & f ) { return f.Lc(); }
282
283inline CanonicalForm
284LC ( const CanonicalForm & f ) { return f.LC(); }
285
286inline CanonicalForm
287LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
288
289inline int
290degree ( const CanonicalForm & f ) { return f.degree(); }
291
292inline int
293degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
294
295inline int
296taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
297
298inline CanonicalForm
299tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
300
301inline CanonicalForm
302tailcoeff (const CanonicalForm& f, const Variable& v) { return f.tailcoeff(v); }
303
304inline int
305level ( const CanonicalForm & f ) { return f.level(); }
306
307inline Variable
308mvar ( const CanonicalForm & f ) { return f.mvar(); }
309
310inline CanonicalForm
311num ( const CanonicalForm & f ) { return f.num(); }
312
313inline CanonicalForm
314den ( const CanonicalForm & f ) { return f.den(); }
315
316inline int
317sign ( const CanonicalForm & a ) { return a.sign(); }
318
319inline CanonicalForm
320deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
321
322inline CanonicalForm
323sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
324
325inline int
326ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
327
328inline CanonicalForm
329mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
330//}}}
331
332//{{{ inline functions
333inline CanonicalForm
334head ( const CanonicalForm & f )
335{
336    if ( f.level() > 0 )
337        return power( f.mvar(), f.degree() ) * f.LC();
338    else
339        return f;
340}
341
342inline int
343headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
344
345
346//}}}
347
348//{{{ other function declarations
349void setCharacteristic( int c ); // -> Fp && Q
350void setCharacteristic( int c, int n ); // -> PrimePower
351void setCharacteristic( int c, int n, char name ); // -> GF(q)
352
353int getCharacteristic();
354int getGFDegree();
355CanonicalForm getGFGenerator();
356
357void On( int );
358void Off( int );
359bool isOn( int );
360//}}}
361
362//{{{ type definitions
363typedef AFactor<CanonicalForm> CFAFactor;
364typedef List <CFAFactor> CFAFList;
365typedef ListIterator<CFAFactor> CFAFListIterator;
366typedef Factor<CanonicalForm> CFFactor;
367typedef List<CFFactor> CFFList;
368typedef ListIterator<CFFactor> CFFListIterator;
369typedef List<CanonicalForm> CFList;
370typedef ListIterator<CanonicalForm> CFListIterator;
371typedef Array<CanonicalForm> CFArray;
372typedef Matrix<CanonicalForm> CFMatrix;
373//}}}
374
375/*ENDPUBLIC*/
376
377#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.