source: git/factory/canonicalform.h @ c1b9927

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