source: git/factory/canonicalform.h @ d953d4

spielwiese
Last change on this file since d953d4 was d953d4, checked in by Hans Schönemann <hannes@…>, 18 years ago
*hannes: x64_64 gcc fix git-svn-id: file:///usr/local/Singular/svn/trunk@9162 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: canonicalform.h,v 1.33 2006-05-26 11:50:37 Singular Exp $ */
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 extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
220
221CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
222
223CanonicalForm pp ( const CanonicalForm& );
224
225CanonicalForm content ( const CanonicalForm& );
226
227CanonicalForm content ( const CanonicalForm&, const Variable& );
228
229CanonicalForm icontent ( const CanonicalForm & f );
230
231CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
232//}}}
233
234//{{{ function declarations from cf_ops.cc
235CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
236
237CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
238
239int getNumVars( const CanonicalForm & f );
240
241CanonicalForm getVars( const CanonicalForm & f );
242
243CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
244
245CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
246
247int * degrees ( const CanonicalForm & f, int * degs = 0 );
248
249int totaldegree ( const CanonicalForm & f );
250
251int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
252
253int size ( const CanonicalForm & f, const Variable & v );
254
255int size ( const CanonicalForm & f );
256//}}}
257
258//{{{ inline functions corresponding to CanonicalForm methods
259//{{{ docu
260//
261// - inline functions corresponding to CanonicalForm methods.
262//
263// These function exist for convenience only and because it is
264// more beautiful to write 'degree( f )' than 'f.degree()'.
265//
266//}}}
267inline CanonicalForm
268lc ( const CanonicalForm & f ) { return f.lc(); }
269
270inline CanonicalForm
271Lc ( const CanonicalForm & f ) { return f.Lc(); }
272
273inline CanonicalForm
274LC ( const CanonicalForm & f ) { return f.LC(); }
275
276inline CanonicalForm
277LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
278
279inline int
280degree ( const CanonicalForm & f ) { return f.degree(); }
281
282inline int
283degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
284
285inline int
286taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
287
288inline CanonicalForm
289tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
290
291inline int
292level ( const CanonicalForm & f ) { return f.level(); }
293
294inline Variable
295mvar ( const CanonicalForm & f ) { return f.mvar(); }
296
297inline CanonicalForm
298num ( const CanonicalForm & f ) { return f.num(); }
299
300inline CanonicalForm
301den ( const CanonicalForm & f ) { return f.den(); }
302
303inline int
304sign ( const CanonicalForm & a ) { return a.sign(); }
305
306inline CanonicalForm
307deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
308
309inline CanonicalForm
310sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
311
312inline int
313ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
314
315inline CanonicalForm
316mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
317//}}}
318
319//{{{ inline functions
320inline CanonicalForm
321head ( const CanonicalForm & f )
322{
323    if ( f.level() > 0 )
324        return power( f.mvar(), f.degree() ) * f.LC();
325    else
326        return f;
327}
328
329inline int
330headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
331
332
333//}}}
334
335//{{{ other function declarations
336void setCharacteristic( int c ); // -> Fp && Q
337void setCharacteristic( int c, int n ); // -> PrimePower
338void setCharacteristic( int c, int n, char name ); // -> GF(q)
339
340int getCharacteristic();
341int getGFDegree();
342CanonicalForm getGFGenerator();
343
344void On( int );
345void Off( int );
346bool isOn( int );
347//}}}
348
349//{{{ type definitions
350typedef Factor<CanonicalForm> CFFactor;
351typedef List<CFFactor> CFFList;
352typedef ListIterator<CFFactor> CFFListIterator;
353typedef List<CanonicalForm> CFList;
354typedef ListIterator<CanonicalForm> CFListIterator;
355typedef Array<CanonicalForm> CFArray;
356typedef Matrix<CanonicalForm> CFMatrix;
357//}}}
358
359/*ENDPUBLIC*/
360
361#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.