source: git/factory/canonicalform.h @ d87069

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