source: git/factory/canonicalform.h @ f55f39

spielwiese
Last change on this file since f55f39 was 3ace5b6, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: new command to get tail coeff wrt. given variable
  • Property mode set to 100644
File size: 10.2 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    CanonicalForm tailcoeff ( const Variable & v ) const;
115    int taildegree () const;
116
117    int level () const;
118    Variable mvar () const;
119
120    CanonicalForm num () const;
121    CanonicalForm den () const;
122
123    // assignment operators
124    CF_NO_INLINE CanonicalForm& operator = ( const CanonicalForm& );
125    CF_NO_INLINE CanonicalForm& operator = ( const int );
126
127    CanonicalForm& operator += ( const CanonicalForm& );
128    CanonicalForm& operator -= ( const CanonicalForm& );
129    CanonicalForm& operator *= ( const CanonicalForm& );
130    CanonicalForm& operator /= ( const CanonicalForm& );
131    CanonicalForm& operator %= ( const CanonicalForm& );
132    CanonicalForm& div ( const CanonicalForm& );
133    CanonicalForm& tryDiv (const CanonicalForm&, const CanonicalForm&, bool& );
134    CanonicalForm& mod ( const CanonicalForm& );
135
136    // evaluation operators
137    CanonicalForm operator () ( const CanonicalForm & f ) const;
138    CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const;
139
140    CanonicalForm operator [] ( int i ) const;
141
142    CanonicalForm deriv() const;
143    CanonicalForm deriv( const Variable & x ) const;
144
145    int sign() const;
146    CanonicalForm sqrt() const;
147    int ilog2() const;
148
149    // comparison operators
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    friend bool operator < ( const CanonicalForm&, const CanonicalForm& );
154
155    // arithmetic operators
156    friend CF_NO_INLINE CanonicalForm operator - ( const CanonicalForm& );
157
158    friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
159    friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
160    friend bool tryDivremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm&, const CanonicalForm&, bool& );
161
162    friend CanonicalForm bgcd ( const CanonicalForm &, const CanonicalForm & );
163    friend CanonicalForm bextgcd ( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm & );
164
165    // input/output
166#ifndef NOSTREAMIO
167   void print( OSTREAM&, char * ) const;
168   void print( OSTREAM& ) const;
169   friend OSTREAM& operator << ( OSTREAM&, const CanonicalForm& );
170   friend ISTREAM& operator >> ( ISTREAM&, CanonicalForm& );
171#endif /* NOSTREAMIO */
172
173    // obsolete methods
174    static CanonicalForm genCoeff( int what, int i = 0 );
175    CanonicalForm genZero() const;
176    CanonicalForm genOne() const;
177
178    friend class CFIterator;
179};
180//}}}
181
182CF_INLINE CanonicalForm
183operator + ( const CanonicalForm&, const CanonicalForm& );
184
185CF_NO_INLINE CanonicalForm
186operator - ( const CanonicalForm&, const CanonicalForm& );
187
188CF_INLINE CanonicalForm
189operator * ( const CanonicalForm&, const CanonicalForm& );
190
191CF_NO_INLINE CanonicalForm
192operator / ( const CanonicalForm&, const CanonicalForm& );
193
194CF_NO_INLINE CanonicalForm
195operator % ( const CanonicalForm&, const CanonicalForm& );
196
197CF_NO_INLINE CanonicalForm
198div ( const CanonicalForm&, const CanonicalForm& );
199
200CF_NO_INLINE CanonicalForm
201mod ( const CanonicalForm&, const CanonicalForm& );
202
203/*ENDPUBLIC*/
204
205#ifdef CF_USE_INLINE
206#include "cf_inline.cc"
207#endif
208
209/*BEGINPUBLIC*/
210
211//{{{ function declarations from canonicalform.cc
212CanonicalForm blcm ( const CanonicalForm & f, const CanonicalForm & g );
213
214CanonicalForm power ( const CanonicalForm & f, int n );
215
216CanonicalForm power ( const Variable & v, int n );
217//}}}
218
219//{{{ function declarations from cf_gcd.cc
220CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& );
221
222CanonicalForm gcd_poly ( const CanonicalForm & f, const CanonicalForm & g );
223
224CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
225
226CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
227
228CanonicalForm pp ( const CanonicalForm& );
229
230CanonicalForm content ( const CanonicalForm& );
231
232CanonicalForm content ( const CanonicalForm&, const Variable& );
233
234CanonicalForm icontent ( const CanonicalForm & f );
235
236CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
237//}}}
238
239//{{{ function declarations from cf_ops.cc
240CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
241
242CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
243
244int getNumVars( const CanonicalForm & f );
245
246CanonicalForm getVars( const CanonicalForm & f );
247
248CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
249
250CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
251
252int * degrees ( const CanonicalForm & f, int * degs = 0 );
253
254int totaldegree ( const CanonicalForm & f );
255
256int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
257
258int size ( const CanonicalForm & f, const Variable & v );
259
260int size ( const CanonicalForm & f );
261
262CanonicalForm reduce ( const CanonicalForm& f, const CanonicalForm & M);
263//}}}
264
265//{{{ inline functions corresponding to CanonicalForm methods
266//{{{ docu
267//
268// - inline functions corresponding to CanonicalForm methods.
269//
270// These function exist for convenience only and because it is
271// more beautiful to write 'degree( f )' than 'f.degree()'.
272//
273//}}}
274inline CanonicalForm
275lc ( const CanonicalForm & f ) { return f.lc(); }
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, const Variable & v ) { return f.LC( v ); }
285
286inline int
287degree ( const CanonicalForm & f ) { return f.degree(); }
288
289inline int
290degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
291
292inline int
293taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
294
295inline CanonicalForm
296tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
297
298inline CanonicalForm
299tailcoeff (const CanonicalForm& f, const Variable& v) { return f.tailcoeff(v); }
300
301inline int
302level ( const CanonicalForm & f ) { return f.level(); }
303
304inline Variable
305mvar ( const CanonicalForm & f ) { return f.mvar(); }
306
307inline CanonicalForm
308num ( const CanonicalForm & f ) { return f.num(); }
309
310inline CanonicalForm
311den ( const CanonicalForm & f ) { return f.den(); }
312
313inline int
314sign ( const CanonicalForm & a ) { return a.sign(); }
315
316inline CanonicalForm
317deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
318
319inline CanonicalForm
320sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
321
322inline int
323ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
324
325inline CanonicalForm
326mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
327//}}}
328
329//{{{ inline functions
330inline CanonicalForm
331head ( const CanonicalForm & f )
332{
333    if ( f.level() > 0 )
334        return power( f.mvar(), f.degree() ) * f.LC();
335    else
336        return f;
337}
338
339inline int
340headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
341
342
343//}}}
344
345//{{{ other function declarations
346void setCharacteristic( int c ); // -> Fp && Q
347void setCharacteristic( int c, int n ); // -> PrimePower
348void setCharacteristic( int c, int n, char name ); // -> GF(q)
349
350int getCharacteristic();
351int getGFDegree();
352CanonicalForm getGFGenerator();
353
354void On( int );
355void Off( int );
356bool isOn( int );
357//}}}
358
359//{{{ type definitions
360typedef Factor<CanonicalForm> CFFactor;
361typedef List<CFFactor> CFFList;
362typedef ListIterator<CFFactor> CFFListIterator;
363typedef List<CanonicalForm> CFList;
364typedef ListIterator<CanonicalForm> CFListIterator;
365typedef Array<CanonicalForm> CFArray;
366typedef Matrix<CanonicalForm> CFMatrix;
367//}}}
368
369/*ENDPUBLIC*/
370
371#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.