source: git/factory/canonicalform.h @ 740d7f

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