source: git/factory/canonicalform.h @ 276c3f

jengelh-datetimespielwiese
Last change on this file since 276c3f was 276c3f, checked in by Martin Lee <martinlee84@…>, 12 years ago
moved 'reduce' from algext.* to cf_ops.cc and canonicalform.h git-svn-id: file:///usr/local/Singular/svn/trunk@14325 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.8 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
260CanonicalForm reduce ( const CanonicalForm& f, const CanonicalForm & M);
261//}}}
262
263//{{{ inline functions corresponding to CanonicalForm methods
264//{{{ docu
265//
266// - inline functions corresponding to CanonicalForm methods.
267//
268// These function exist for convenience only and because it is
269// more beautiful to write 'degree( f )' than 'f.degree()'.
270//
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 ) { return f.LC(); }
280
281inline CanonicalForm
282LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
283
284inline int
285degree ( const CanonicalForm & f ) { return f.degree(); }
286
287inline int
288degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
289
290inline int
291taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
292
293inline CanonicalForm
294tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
295
296inline int
297level ( const CanonicalForm & f ) { return f.level(); }
298
299inline Variable
300mvar ( const CanonicalForm & f ) { return f.mvar(); }
301
302inline CanonicalForm
303num ( const CanonicalForm & f ) { return f.num(); }
304
305inline CanonicalForm
306den ( const CanonicalForm & f ) { return f.den(); }
307
308inline int
309sign ( const CanonicalForm & a ) { return a.sign(); }
310
311inline CanonicalForm
312deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
313
314inline CanonicalForm
315sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
316
317inline int
318ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
319
320inline CanonicalForm
321mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
322//}}}
323
324//{{{ inline functions
325inline CanonicalForm
326head ( const CanonicalForm & f )
327{
328    if ( f.level() > 0 )
329        return power( f.mvar(), f.degree() ) * f.LC();
330    else
331        return f;
332}
333
334inline int
335headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
336
337
338//}}}
339
340//{{{ other function declarations
341void setCharacteristic( int c ); // -> Fp && Q
342void setCharacteristic( int c, int n ); // -> PrimePower
343void setCharacteristic( int c, int n, char name ); // -> GF(q)
344
345int getCharacteristic();
346int getGFDegree();
347CanonicalForm getGFGenerator();
348
349void On( int );
350void Off( int );
351bool isOn( int );
352//}}}
353
354//{{{ type definitions
355typedef Factor<CanonicalForm> CFFactor;
356typedef List<CFFactor> CFFList;
357typedef ListIterator<CFFactor> CFFListIterator;
358typedef List<CanonicalForm> CFList;
359typedef ListIterator<CanonicalForm> CFListIterator;
360typedef Array<CanonicalForm> CFArray;
361typedef Matrix<CanonicalForm> CFMatrix;
362//}}}
363
364/*ENDPUBLIC*/
365
366#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.