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