source: git/factory/canonicalform.h @ 362fc67

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