source: git/factory/canonicalform.h

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