1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: canonicalform.h,v 1.32 2006-05-15 09:03:04 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 | |
---|
47 | class InternalCF; |
---|
48 | |
---|
49 | inline int is_imm ( const InternalCF * const ptr ) |
---|
50 | { |
---|
51 | // returns 0 if ptr is not immediate |
---|
52 | return ( (long)ptr & 3 ); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | int initCanonicalForm( void ); |
---|
57 | |
---|
58 | static int cf_is_initialized_now = initCanonicalForm(); |
---|
59 | |
---|
60 | //{{{ class CanonicalForm |
---|
61 | class CanonicalForm |
---|
62 | { |
---|
63 | private: |
---|
64 | InternalCF *value; |
---|
65 | public: |
---|
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 | |
---|
179 | CF_INLINE CanonicalForm |
---|
180 | operator + ( const CanonicalForm&, const CanonicalForm& ); |
---|
181 | |
---|
182 | CF_NO_INLINE CanonicalForm |
---|
183 | operator - ( const CanonicalForm&, const CanonicalForm& ); |
---|
184 | |
---|
185 | CF_INLINE CanonicalForm |
---|
186 | operator * ( const CanonicalForm&, const CanonicalForm& ); |
---|
187 | |
---|
188 | CF_NO_INLINE CanonicalForm |
---|
189 | operator / ( const CanonicalForm&, const CanonicalForm& ); |
---|
190 | |
---|
191 | CF_NO_INLINE CanonicalForm |
---|
192 | operator % ( const CanonicalForm&, const CanonicalForm& ); |
---|
193 | |
---|
194 | CF_NO_INLINE CanonicalForm |
---|
195 | div ( const CanonicalForm&, const CanonicalForm& ); |
---|
196 | |
---|
197 | CF_NO_INLINE CanonicalForm |
---|
198 | mod ( 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 |
---|
209 | CanonicalForm blcm ( const CanonicalForm & f, const CanonicalForm & g ); |
---|
210 | |
---|
211 | CanonicalForm power ( const CanonicalForm & f, int n ); |
---|
212 | |
---|
213 | CanonicalForm power ( const Variable & v, int n ); |
---|
214 | //}}} |
---|
215 | |
---|
216 | //{{{ function declarations from cf_gcd.cc |
---|
217 | CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& ); |
---|
218 | |
---|
219 | CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
220 | |
---|
221 | CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& ); |
---|
222 | |
---|
223 | CanonicalForm pp ( const CanonicalForm& ); |
---|
224 | |
---|
225 | CanonicalForm content ( const CanonicalForm& ); |
---|
226 | |
---|
227 | CanonicalForm content ( const CanonicalForm&, const Variable& ); |
---|
228 | |
---|
229 | CanonicalForm icontent ( const CanonicalForm & f ); |
---|
230 | |
---|
231 | CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x ); |
---|
232 | //}}} |
---|
233 | |
---|
234 | //{{{ function declarations from cf_ops.cc |
---|
235 | CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
236 | |
---|
237 | CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
238 | |
---|
239 | int getNumVars( const CanonicalForm & f ); |
---|
240 | |
---|
241 | CanonicalForm getVars( const CanonicalForm & f ); |
---|
242 | |
---|
243 | CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ); |
---|
244 | |
---|
245 | CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ); |
---|
246 | |
---|
247 | int * degrees ( const CanonicalForm & f, int * degs = 0 ); |
---|
248 | |
---|
249 | int totaldegree ( const CanonicalForm & f ); |
---|
250 | |
---|
251 | int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 ); |
---|
252 | |
---|
253 | int size ( const CanonicalForm & f, const Variable & v ); |
---|
254 | |
---|
255 | int 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 | //}}} |
---|
267 | inline CanonicalForm |
---|
268 | lc ( const CanonicalForm & f ) { return f.lc(); } |
---|
269 | |
---|
270 | inline CanonicalForm |
---|
271 | Lc ( const CanonicalForm & f ) { return f.Lc(); } |
---|
272 | |
---|
273 | inline CanonicalForm |
---|
274 | LC ( const CanonicalForm & f ) { return f.LC(); } |
---|
275 | |
---|
276 | inline CanonicalForm |
---|
277 | LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); } |
---|
278 | |
---|
279 | inline int |
---|
280 | degree ( const CanonicalForm & f ) { return f.degree(); } |
---|
281 | |
---|
282 | inline int |
---|
283 | degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); } |
---|
284 | |
---|
285 | inline int |
---|
286 | taildegree ( const CanonicalForm & f ) { return f.taildegree(); } |
---|
287 | |
---|
288 | inline CanonicalForm |
---|
289 | tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); } |
---|
290 | |
---|
291 | inline int |
---|
292 | level ( const CanonicalForm & f ) { return f.level(); } |
---|
293 | |
---|
294 | inline Variable |
---|
295 | mvar ( const CanonicalForm & f ) { return f.mvar(); } |
---|
296 | |
---|
297 | inline CanonicalForm |
---|
298 | num ( const CanonicalForm & f ) { return f.num(); } |
---|
299 | |
---|
300 | inline CanonicalForm |
---|
301 | den ( const CanonicalForm & f ) { return f.den(); } |
---|
302 | |
---|
303 | inline int |
---|
304 | sign ( const CanonicalForm & a ) { return a.sign(); } |
---|
305 | |
---|
306 | inline CanonicalForm |
---|
307 | deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); } |
---|
308 | |
---|
309 | inline CanonicalForm |
---|
310 | sqrt ( const CanonicalForm & a ) { return a.sqrt(); } |
---|
311 | |
---|
312 | inline int |
---|
313 | ilog2 ( const CanonicalForm & a ) { return a.ilog2(); } |
---|
314 | |
---|
315 | inline CanonicalForm |
---|
316 | mapinto ( const CanonicalForm & f ) { return f.mapinto(); } |
---|
317 | //}}} |
---|
318 | |
---|
319 | //{{{ inline functions |
---|
320 | inline CanonicalForm |
---|
321 | head ( 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 | |
---|
329 | inline int |
---|
330 | headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); } |
---|
331 | |
---|
332 | |
---|
333 | //}}} |
---|
334 | |
---|
335 | //{{{ other function declarations |
---|
336 | void setCharacteristic( int c ); // -> Fp && Q |
---|
337 | void setCharacteristic( int c, int n ); // -> PrimePower |
---|
338 | void setCharacteristic( int c, int n, char name ); // -> GF(q) |
---|
339 | |
---|
340 | int getCharacteristic(); |
---|
341 | int getGFDegree(); |
---|
342 | CanonicalForm getGFGenerator(); |
---|
343 | |
---|
344 | void On( int ); |
---|
345 | void Off( int ); |
---|
346 | bool isOn( int ); |
---|
347 | //}}} |
---|
348 | |
---|
349 | //{{{ type definitions |
---|
350 | typedef Factor<CanonicalForm> CFFactor; |
---|
351 | typedef List<CFFactor> CFFList; |
---|
352 | typedef ListIterator<CFFactor> CFFListIterator; |
---|
353 | typedef List<CanonicalForm> CFList; |
---|
354 | typedef ListIterator<CanonicalForm> CFListIterator; |
---|
355 | typedef Array<CanonicalForm> CFArray; |
---|
356 | typedef Matrix<CanonicalForm> CFMatrix; |
---|
357 | //}}} |
---|
358 | |
---|
359 | /*ENDPUBLIC*/ |
---|
360 | |
---|
361 | #endif /* ! INCL_CANONICALFORM_H */ |
---|