source: git/factory/canonicalform.h @ 26da1d

spielwiese
Last change on this file since 26da1d was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.6 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4#ifndef INCL_CANONICALFORM_H
5#define INCL_CANONICALFORM_H
6
7#include <config.h>
8
9#ifndef NOSTREAMIO
10#ifdef HAVE_IOSTREAM
11#include <iostream>
12#define OSTREAM std::ostream
13#define ISTREAM std::istream
14#elif defined(HAVE_IOSTREAM_H)
15#include <iostream.h>
16#define OSTREAM ostream
17#define ISTREAM istream
18#endif
19#endif /* NOSTREAMIO */
20
21#include "cf_defs.h"
22#include "variable.h"
23#include "ftmpl_list.h"
24#include "ftmpl_array.h"
25#include "ftmpl_factor.h"
26#include "ftmpl_matrix.h"
27
28/*BEGINPUBLIC*/
29
30#undef CF_INLINE
31#define CF_INLINE
32#undef CF_NO_INLINE
33#define CF_NO_INLINE
34
35/*ENDPUBLIC*/
36
37#ifdef CF_USE_INLINE
38#undef CF_INLINE
39#define CF_INLINE inline
40#else
41#undef CF_INLINE
42#define CF_INLINE
43#endif
44
45/*BEGINPUBLIC*/
46
47class InternalCF;
48
49inline int is_imm ( const InternalCF * const ptr )
50{
51    // returns 0 if ptr is not immediate       
52    return ( ((int)((long)ptr)) & 3 );
53}
54
55
56int initCanonicalForm( void );
57
58static int cf_is_initialized_now = initCanonicalForm();
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    int taildegree () const;
115
116    int level () const;
117    Variable mvar () const;
118
119    CanonicalForm num () const;
120    CanonicalForm den () const;
121
122    // assignment operators
123    CF_NO_INLINE CanonicalForm& operator = ( const CanonicalForm& );
124    CF_NO_INLINE CanonicalForm& operator = ( const int );
125
126    CanonicalForm& operator += ( const CanonicalForm& );
127    CanonicalForm& operator -= ( const CanonicalForm& );
128    CanonicalForm& operator *= ( const CanonicalForm& );
129    CanonicalForm& operator /= ( const CanonicalForm& );
130    CanonicalForm& operator %= ( const CanonicalForm& );
131    CanonicalForm& div ( const CanonicalForm& );
132    CanonicalForm& mod ( const CanonicalForm& );
133
134    // evaluation operators
135    CanonicalForm operator () ( const CanonicalForm & f ) const;
136    CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const;
137
138    CanonicalForm operator [] ( int i ) const;
139
140    CanonicalForm deriv() const;
141    CanonicalForm deriv( const Variable & x ) const;
142
143    int sign() const;
144    CanonicalForm sqrt() const;
145    int ilog2() const;
146
147    // comparison operators
148    friend bool operator == ( const CanonicalForm&, const CanonicalForm& );
149    friend bool operator != ( const CanonicalForm&, const CanonicalForm& );
150    friend bool operator > ( const CanonicalForm&, const CanonicalForm& );
151    friend bool operator < ( const CanonicalForm&, const CanonicalForm& );
152
153    // arithmetic operators
154    friend CF_NO_INLINE CanonicalForm operator - ( const CanonicalForm& );
155
156    friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
157    friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
158
159    friend CanonicalForm bgcd ( const CanonicalForm &, const CanonicalForm & );
160    friend CanonicalForm bextgcd ( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm & );
161
162    // input/output
163#ifndef NOSTREAMIO
164    void print( OSTREAM&, char * ) const;
165    void print( OSTREAM& ) const;
166    friend OSTREAM& operator << ( OSTREAM&, const CanonicalForm& );
167    friend ISTREAM& operator >> ( ISTREAM&, CanonicalForm& );
168#endif /* NOSTREAMIO */
169
170    // obsolete methods
171    static CanonicalForm genCoeff( int what, int i = 0 );
172    CanonicalForm genZero() const;
173    CanonicalForm genOne() const;
174
175    friend class CFIterator;
176};
177//}}}
178
179CF_INLINE CanonicalForm
180operator + ( const CanonicalForm&, const CanonicalForm& );
181
182CF_NO_INLINE CanonicalForm
183operator - ( const CanonicalForm&, const CanonicalForm& );
184
185CF_INLINE CanonicalForm
186operator * ( const CanonicalForm&, const CanonicalForm& );
187
188CF_NO_INLINE CanonicalForm
189operator / ( const CanonicalForm&, const CanonicalForm& );
190
191CF_NO_INLINE CanonicalForm
192operator % ( const CanonicalForm&, const CanonicalForm& );
193
194CF_NO_INLINE CanonicalForm
195div ( const CanonicalForm&, const CanonicalForm& );
196
197CF_NO_INLINE CanonicalForm
198mod ( const CanonicalForm&, const CanonicalForm& );
199
200/*ENDPUBLIC*/
201
202#ifdef CF_USE_INLINE
203#include "cf_inline.cc"
204#endif
205
206/*BEGINPUBLIC*/
207
208//{{{ function declarations from canonicalform.cc
209CanonicalForm blcm ( const CanonicalForm & f, const CanonicalForm & g );
210
211CanonicalForm power ( const CanonicalForm & f, int n );
212
213CanonicalForm power ( const Variable & v, int n );
214//}}}
215
216//{{{ function declarations from cf_gcd.cc
217CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& );
218
219CanonicalForm gcd_poly ( const CanonicalForm & f, const CanonicalForm & g );
220
221CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
222
223CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
224
225CanonicalForm pp ( const CanonicalForm& );
226
227CanonicalForm content ( const CanonicalForm& );
228
229CanonicalForm content ( const CanonicalForm&, const Variable& );
230
231CanonicalForm icontent ( const CanonicalForm & f );
232
233CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
234//}}}
235
236//{{{ function declarations from cf_ops.cc
237CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
238
239CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
240
241int getNumVars( const CanonicalForm & f );
242
243CanonicalForm getVars( const CanonicalForm & f );
244
245CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
246
247CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
248
249int * degrees ( const CanonicalForm & f, int * degs = 0 );
250
251int totaldegree ( const CanonicalForm & f );
252
253int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
254
255int size ( const CanonicalForm & f, const Variable & v );
256
257int size ( const CanonicalForm & f );
258//}}}
259
260//{{{ inline functions corresponding to CanonicalForm methods
261//{{{ docu
262//
263// - inline functions corresponding to CanonicalForm methods.
264//
265// These function exist for convenience only and because it is
266// more beautiful to write 'degree( f )' than 'f.degree()'.
267//
268//}}}
269inline CanonicalForm
270lc ( const CanonicalForm & f ) { return f.lc(); }
271
272inline CanonicalForm
273Lc ( const CanonicalForm & f ) { return f.Lc(); }
274
275inline CanonicalForm
276LC ( const CanonicalForm & f ) { return f.LC(); }
277
278inline CanonicalForm
279LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
280
281inline int
282degree ( const CanonicalForm & f ) { return f.degree(); }
283
284inline int
285degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
286
287inline int
288taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
289
290inline CanonicalForm
291tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
292
293inline int
294level ( const CanonicalForm & f ) { return f.level(); }
295
296inline Variable
297mvar ( const CanonicalForm & f ) { return f.mvar(); }
298
299inline CanonicalForm
300num ( const CanonicalForm & f ) { return f.num(); }
301
302inline CanonicalForm
303den ( const CanonicalForm & f ) { return f.den(); }
304
305inline int
306sign ( const CanonicalForm & a ) { return a.sign(); }
307
308inline CanonicalForm
309deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
310
311inline CanonicalForm
312sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
313
314inline int
315ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
316
317inline CanonicalForm
318mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
319//}}}
320
321//{{{ inline functions
322inline CanonicalForm
323head ( const CanonicalForm & f )
324{
325    if ( f.level() > 0 )
326        return power( f.mvar(), f.degree() ) * f.LC();
327    else
328        return f;
329}
330
331inline int
332headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
333
334
335//}}}
336
337//{{{ other function declarations
338void setCharacteristic( int c ); // -> Fp && Q
339void setCharacteristic( int c, int n ); // -> PrimePower
340void setCharacteristic( int c, int n, char name ); // -> GF(q)
341
342int getCharacteristic();
343int getGFDegree();
344CanonicalForm getGFGenerator();
345
346void On( int );
347void Off( int );
348bool isOn( int );
349//}}}
350
351//{{{ type definitions
352typedef Factor<CanonicalForm> CFFactor;
353typedef List<CFFactor> CFFList;
354typedef ListIterator<CFFactor> CFFListIterator;
355typedef List<CanonicalForm> CFList;
356typedef ListIterator<CanonicalForm> CFListIterator;
357typedef Array<CanonicalForm> CFArray;
358typedef Matrix<CanonicalForm> CFMatrix;
359//}}}
360
361/*ENDPUBLIC*/
362
363#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.