source: git/factory/canonicalform.h @ 91695f

fieker-DuValspielwiese
Last change on this file since 91695f was 1a4c80b, checked in by Martin Lee <martinlee84@…>, 10 years ago
chg: added leftShift of CanonicalForms chg: use leftShift in computation of cyclotomic polys
  • 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 lcm ( const CanonicalForm&, const CanonicalForm& );
235
236CanonicalForm pp ( const CanonicalForm& );
237
238CanonicalForm content ( const CanonicalForm& );
239
240CanonicalForm content ( const CanonicalForm&, const Variable& );
241
242CanonicalForm icontent ( const CanonicalForm & f );
243
244CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
245//}}}
246
247//{{{ function declarations from cf_ops.cc
248CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
249
250CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
251
252int getNumVars( const CanonicalForm & f );
253
254CanonicalForm getVars( const CanonicalForm & f );
255
256CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
257
258CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
259
260int * degrees ( const CanonicalForm & f, int * degs = 0 );
261
262int totaldegree ( const CanonicalForm & f );
263
264int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
265
266int size ( const CanonicalForm & f, const Variable & v );
267
268int size ( const CanonicalForm & f );
269
270CanonicalForm reduce ( const CanonicalForm& f, const CanonicalForm & M);
271
272bool hasFirstAlgVar( const CanonicalForm & f, Variable & a);
273
274CanonicalForm leftShift (const CanonicalForm& F, int n);
275//}}}
276
277//{{{ inline functions corresponding to CanonicalForm methods
278//{{{ docu
279//
280// - inline functions corresponding to CanonicalForm methods.
281//
282// These function exist for convenience only and because it is
283// more beautiful to write 'degree( f )' than 'f.degree()'.
284//
285//}}}
286inline CanonicalForm
287lc ( const CanonicalForm & f ) { return f.lc(); }
288
289inline CanonicalForm
290Lc ( const CanonicalForm & f ) { return f.Lc(); }
291
292inline CanonicalForm
293LC ( const CanonicalForm & f ) { return f.LC(); }
294
295inline CanonicalForm
296LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
297
298inline int
299degree ( const CanonicalForm & f ) { return f.degree(); }
300
301inline int
302degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
303
304inline int
305taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
306
307inline CanonicalForm
308tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
309
310inline CanonicalForm
311tailcoeff (const CanonicalForm& f, const Variable& v) { return f.tailcoeff(v); }
312
313inline int
314level ( const CanonicalForm & f ) { return f.level(); }
315
316inline Variable
317mvar ( const CanonicalForm & f ) { return f.mvar(); }
318
319inline CanonicalForm
320num ( const CanonicalForm & f ) { return f.num(); }
321
322inline CanonicalForm
323den ( const CanonicalForm & f ) { return f.den(); }
324
325inline int
326sign ( const CanonicalForm & a ) { return a.sign(); }
327
328inline CanonicalForm
329deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
330
331inline CanonicalForm
332sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
333
334inline int
335ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
336
337inline CanonicalForm
338mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
339//}}}
340
341//{{{ inline functions
342inline CanonicalForm
343head ( const CanonicalForm & f )
344{
345    if ( f.level() > 0 )
346        return power( f.mvar(), f.degree() ) * f.LC();
347    else
348        return f;
349}
350
351inline int
352headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
353
354
355//}}}
356
357//{{{ other function declarations
358void setCharacteristic( int c ); // -> Fp && Q
359void setCharacteristic( int c, int n ); // -> PrimePower
360void setCharacteristic( int c, int n, char name ); // -> GF(q)
361
362int getCharacteristic();
363int getGFDegree();
364CanonicalForm getGFGenerator();
365
366void On( int );
367void Off( int );
368bool isOn( int );
369//}}}
370
371//{{{ type definitions
372typedef AFactor<CanonicalForm> CFAFactor;
373typedef List <CFAFactor> CFAFList;
374typedef ListIterator<CFAFactor> CFAFListIterator;
375typedef Factor<CanonicalForm> CFFactor;
376typedef List<CFFactor> CFFList;
377typedef ListIterator<CFFactor> CFFListIterator;
378typedef List<CanonicalForm> CFList;
379typedef ListIterator<CanonicalForm> CFListIterator;
380typedef Array<CanonicalForm> CFArray;
381typedef Matrix<CanonicalForm> CFMatrix;
382typedef List<CFList> ListCFList;
383typedef ListIterator<CFList> ListCFListIterator ;
384typedef List<int> IntList;
385typedef ListIterator<int> IntListIterator;
386typedef List<Variable> Varlist;
387typedef ListIterator<Variable> VarlistIterator;
388typedef Array<int> Intarray;
389//}}}
390
391/*ENDPUBLIC*/
392
393#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.