source: git/factory/canonicalform.h @ ae5205

spielwiese
Last change on this file since ae5205 was ae5205, checked in by Jens Schmidt <schmidt@…>, 27 years ago
* canonicalform.h (sqrt): doc fix git-svn-id: file:///usr/local/Singular/svn/trunk@586 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.2 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: canonicalform.h,v 1.10 1997-07-31 13:04:37 schmidt 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#ifdef macintosh
16#include <::templates:ftmpl_list.h>
17#include <::templates:ftmpl_array.h>
18#include <::templates:ftmpl_factor.h>
19#include <::templates:ftmpl_matrix.h>
20#else
21#include "templates/ftmpl_list.h"
22#include "templates/ftmpl_array.h"
23#include "templates/ftmpl_factor.h"
24#include "templates/ftmpl_matrix.h"
25#endif
26
27/*BEGINPUBLIC*/
28
29int initCanonicalForm( void );
30
31static int cf_is_initialized_now = initCanonicalForm();
32
33class InternalCF;
34
35class CanonicalForm {
36private:
37    InternalCF *value;
38public:
39    CanonicalForm();
40    CanonicalForm( const CanonicalForm& );
41    CanonicalForm( InternalCF* );
42    CanonicalForm( const int );
43    CanonicalForm( const Variable & );
44    CanonicalForm( const Variable &, int );
45    CanonicalForm( const char * ); // use with caution - does only handle integers !!!
46
47    ~CanonicalForm();
48
49    InternalCF* getval() const; // use with caution !!!
50
51    int sign() const;
52
53    bool isOne() const;
54    bool isZero() const;
55    bool isImm() const;
56
57    int intval() const;
58
59    CanonicalForm lc() const;
60    CanonicalForm LC() const;
61    CanonicalForm LC( const Variable & v ) const;
62
63    int degree() const;
64    int degree( const Variable & v ) const;
65
66    CanonicalForm tailcoeff() const;
67    int taildegree() const;
68
69    int level() const;
70    Variable mvar() const;
71
72    CanonicalForm num() const;
73    CanonicalForm den() const;
74
75    CanonicalForm deepCopy() const;
76
77    bool isFFinGF() const;
78    bool hasGcd() const { return false; }
79    CanonicalForm gcd( const CanonicalForm & f ) const;
80    CanonicalForm deriv() const;
81    CanonicalForm deriv( const Variable & x ) const;
82    CanonicalForm sqrt() const;
83    int ilog2() const;
84    static CanonicalForm genCoeff( int what, int i = 0 );
85
86    CanonicalForm genZero() const;
87    CanonicalForm genOne() const;
88
89    bool isUnivariate() const;
90
91    bool inZ() const;
92    bool inQ() const;
93    bool inFF() const;
94    bool inGF() const;
95    bool inPP() const;
96    bool inBaseDomain() const;
97    bool inExtension() const;
98    bool inCoeffDomain() const;
99    bool inPolyDomain() const;
100    bool inQuotDomain() const;
101
102    CanonicalForm mapinto () const;
103
104    CanonicalForm operator () ( const CanonicalForm & f ) const;
105    CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const;
106    CanonicalForm operator [] ( int i ) const;
107    CanonicalForm& operator = ( const CanonicalForm& );
108    CanonicalForm& operator = ( const int );
109
110    CanonicalForm& operator += ( const CanonicalForm& );
111    CanonicalForm& operator -= ( const CanonicalForm& );
112    CanonicalForm& operator *= ( const CanonicalForm& );
113    CanonicalForm& operator /= ( const CanonicalForm& );
114    CanonicalForm& operator %= ( const CanonicalForm& );
115    CanonicalForm& div ( const CanonicalForm& );
116    CanonicalForm& mod ( const CanonicalForm& );
117
118    friend CanonicalForm operator - ( const CanonicalForm& );
119
120    friend CanonicalForm operator + ( const CanonicalForm&, const CanonicalForm& );
121    friend CanonicalForm operator - ( const CanonicalForm&, const CanonicalForm& );
122    friend CanonicalForm operator * ( const CanonicalForm&, const CanonicalForm& );
123    friend CanonicalForm operator / ( const CanonicalForm&, const CanonicalForm& );
124    friend CanonicalForm operator % ( const CanonicalForm&, const CanonicalForm& );
125
126    friend CanonicalForm div ( const CanonicalForm&, const CanonicalForm& );
127    friend CanonicalForm mod ( const CanonicalForm&, const CanonicalForm& );
128
129    friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
130    friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
131
132#ifndef NOSTREAMIO
133    void print( ostream&, char * ) const;
134    friend ostream& operator << ( ostream&, const CanonicalForm& );
135    friend istream& operator >> ( istream&, CanonicalForm& );
136#endif /* NOSTREAMIO */
137
138    friend bool operator == ( const CanonicalForm&, const CanonicalForm& );
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
143    friend class CFIterator;
144};
145
146// some useful functions
147
148inline CanonicalForm
149lc ( const CanonicalForm & f ) { return f.lc(); }
150
151inline CanonicalForm
152LC ( const CanonicalForm & f ) { return f.LC(); }
153
154inline CanonicalForm
155LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
156
157inline int
158degree ( const CanonicalForm & f ) { return f.degree(); }
159
160inline int
161degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
162
163int totaldegree ( const CanonicalForm & f );
164
165int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
166
167inline int
168taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
169
170inline CanonicalForm
171tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
172
173CanonicalForm power ( const CanonicalForm & f, int n );
174
175CanonicalForm power ( const Variable & v, int n );
176
177inline CanonicalForm
178head ( const CanonicalForm & f )
179{
180    if ( f.level() > 0 )
181        return power( f.mvar(), f.degree() ) * f.LC();
182    else
183        return f;
184}
185
186inline int
187headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
188
189inline int
190level ( const CanonicalForm & f ) { return f.level(); }
191
192inline CanonicalForm
193mvar ( const CanonicalForm & f ) { return f.mvar(); }
194
195inline CanonicalForm
196num ( const CanonicalForm & f ) { return f.num(); }
197
198inline CanonicalForm
199den ( const CanonicalForm & f ) { return f.den(); }
200
201inline CanonicalForm
202mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
203
204CanonicalForm swapvar ( const CanonicalForm&, const Variable&, const Variable& );
205
206CanonicalForm resultant( const CanonicalForm & f, const CanonicalForm& g, const Variable & x );
207
208CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& );
209
210CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
211
212CanonicalForm iextgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
213
214CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
215
216CanonicalForm common_den ( const CanonicalForm& );
217
218CanonicalForm pp ( const CanonicalForm& );
219
220CanonicalForm content ( const CanonicalForm& );
221
222CanonicalForm content ( const CanonicalForm&, const Variable& );
223
224CanonicalForm icontent ( const CanonicalForm & f );
225
226CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
227
228CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
229
230bool divides ( const CanonicalForm & f, const CanonicalForm & g );
231
232inline CanonicalForm
233deriv ( const CanonicalForm & f, const Variable & x )
234{
235    return f.deriv(x);
236}
237
238inline CanonicalForm
239abs ( const CanonicalForm & f )
240{
241    if ( f < 0 )
242        return -f;
243    else
244        return f;
245}
246
247//{{{ inline CanonicalForm sqrt ( const CanonicalForm & a )
248//{{{ docu
249//
250// sqrt() - inline function version of method sqrt().
251//
252//}}}
253inline CanonicalForm
254sqrt ( const CanonicalForm & a )
255{
256    return a.sqrt();
257}
258//}}}
259
260//{{{ inline int ilog2 ( const CanonicalForm & a )
261//{{{ docu
262//
263// ilog2() - inline function version of method ilog().
264//
265//}}}
266inline int
267ilog2 ( const CanonicalForm & a )
268{
269    return a.ilog2();
270}
271//}}}
272
273CanonicalForm psr ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x  );
274
275CanonicalForm psq ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x );
276
277void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r, const Variable & x );
278
279int getNumVars( const CanonicalForm & f );
280CanonicalForm getVars( const CanonicalForm & f );
281
282int * degrees ( const CanonicalForm & f, int * degs = 0 );
283
284//CanonicalForm norm( const CanonicalForm & );
285
286//CanonicalForm igcd( const CanonicalForm & );
287
288//CanonicalForm ff2z( const CanonicalForm & );
289//CanonicalForm z2ff( const CanonicalForm & );
290
291void setCharacteristic( int c ); // -> Fp && Q
292void setCharacteristic( int c, int n ); // -> PrimePower
293void setCharacteristic( int c, int n, char name ); // -> GF(q)
294
295int getCharacteristic();
296int getGFDegree();
297
298CanonicalForm getGFGenerator();
299
300// misc template stuff for inst file
301
302typedef Factor<CanonicalForm> CFFactor;
303typedef List<CFFactor> CFFList;
304typedef ListIterator<CFFactor> CFFListIterator;
305typedef List<CanonicalForm> CFList;
306typedef ListIterator<CanonicalForm> CFListIterator;
307typedef Array<CanonicalForm> CFArray;
308typedef Matrix<CanonicalForm> CFMatrix;
309
310CFFList sqrFree ( const CanonicalForm & f, bool sort );
311
312CFFList sqrFree( const CanonicalForm & f );
313
314bool isSqrFree( const CanonicalForm & f );
315
316CFFList factorize( const CanonicalForm & f, bool issqrfree = false );
317
318CFFList factorize( const CanonicalForm & f, const Variable & alpha );
319
320// calculate the determinant of the n'th minor of M
321
322bool linearSystemSolve( CFMatrix & M );
323
324CanonicalForm determinant( const CFMatrix & M, int n );
325
326void On( int );
327void Off( int );
328bool isOn( int );
329
330/*ENDPUBLIC*/
331
332#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.