source: git/factory/canonicalform.h @ afa00e

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