1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: canonicalform.h,v 1.22 1998-02-02 08:57:59 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 | |
---|
29 | int initCanonicalForm( void ); |
---|
30 | |
---|
31 | static int cf_is_initialized_now = initCanonicalForm(); |
---|
32 | |
---|
33 | class InternalCF; |
---|
34 | |
---|
35 | //{{{ class CanonicalForm |
---|
36 | class CanonicalForm |
---|
37 | { |
---|
38 | private: |
---|
39 | InternalCF *value; |
---|
40 | public: |
---|
41 | // constructors, destructors, selectors |
---|
42 | CanonicalForm(); |
---|
43 | CanonicalForm( const CanonicalForm& ); |
---|
44 | CanonicalForm( InternalCF* ); |
---|
45 | CanonicalForm( const int ); |
---|
46 | CanonicalForm( const Variable & ); |
---|
47 | CanonicalForm( const Variable &, int ); |
---|
48 | CanonicalForm( const char * ); // use with caution - does only handle integers !!! |
---|
49 | |
---|
50 | ~CanonicalForm(); |
---|
51 | |
---|
52 | InternalCF* getval() const; // use with caution !!! |
---|
53 | |
---|
54 | CanonicalForm deepCopy() const; |
---|
55 | |
---|
56 | // predicates |
---|
57 | bool isOne() const; |
---|
58 | bool isZero() const; |
---|
59 | bool isImm() const; |
---|
60 | |
---|
61 | bool inZ() const; |
---|
62 | bool inQ() const; |
---|
63 | bool inFF() const; |
---|
64 | bool inGF() const; |
---|
65 | bool inPP() const; |
---|
66 | bool inBaseDomain() const; |
---|
67 | bool inExtension() const; |
---|
68 | bool inCoeffDomain() const; |
---|
69 | bool inPolyDomain() const; |
---|
70 | bool inQuotDomain() const; |
---|
71 | |
---|
72 | bool isFFinGF() const; |
---|
73 | bool isUnivariate() const; |
---|
74 | |
---|
75 | // conversion functions |
---|
76 | int intval() const; |
---|
77 | CanonicalForm mapinto () const; |
---|
78 | |
---|
79 | CanonicalForm lc () const; |
---|
80 | CanonicalForm Lc () const; |
---|
81 | CanonicalForm LC () const; |
---|
82 | CanonicalForm LC ( const Variable & v ) const; |
---|
83 | |
---|
84 | int degree () const; |
---|
85 | int degree ( const Variable & v ) const; |
---|
86 | |
---|
87 | CanonicalForm tailcoeff () const; |
---|
88 | int taildegree () const; |
---|
89 | |
---|
90 | int level () const; |
---|
91 | Variable mvar () const; |
---|
92 | |
---|
93 | CanonicalForm num () const; |
---|
94 | CanonicalForm den () const; |
---|
95 | |
---|
96 | // assignment operators |
---|
97 | CanonicalForm& operator = ( const CanonicalForm& ); |
---|
98 | CanonicalForm& operator = ( const int ); |
---|
99 | |
---|
100 | CanonicalForm& operator += ( const CanonicalForm& ); |
---|
101 | CanonicalForm& operator -= ( const CanonicalForm& ); |
---|
102 | CanonicalForm& operator *= ( const CanonicalForm& ); |
---|
103 | CanonicalForm& operator /= ( const CanonicalForm& ); |
---|
104 | CanonicalForm& operator %= ( const CanonicalForm& ); |
---|
105 | CanonicalForm& div ( const CanonicalForm& ); |
---|
106 | CanonicalForm& mod ( const CanonicalForm& ); |
---|
107 | |
---|
108 | // evaluation operators |
---|
109 | CanonicalForm operator () ( const CanonicalForm & f ) const; |
---|
110 | CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const; |
---|
111 | |
---|
112 | CanonicalForm operator [] ( int i ) const; |
---|
113 | |
---|
114 | CanonicalForm deriv() const; |
---|
115 | CanonicalForm deriv( const Variable & x ) const; |
---|
116 | |
---|
117 | int sign() const; |
---|
118 | CanonicalForm sqrt() const; |
---|
119 | int ilog2() const; |
---|
120 | |
---|
121 | // comparison operators |
---|
122 | friend bool operator == ( const CanonicalForm&, const CanonicalForm& ); |
---|
123 | friend bool operator != ( const CanonicalForm&, const CanonicalForm& ); |
---|
124 | friend bool operator > ( const CanonicalForm&, const CanonicalForm& ); |
---|
125 | friend bool operator < ( const CanonicalForm&, const CanonicalForm& ); |
---|
126 | |
---|
127 | // arithmetic operators |
---|
128 | friend CanonicalForm operator - ( const CanonicalForm& ); |
---|
129 | |
---|
130 | friend CanonicalForm operator + ( const CanonicalForm&, const CanonicalForm& ); |
---|
131 | friend CanonicalForm operator - ( const CanonicalForm&, const CanonicalForm& ); |
---|
132 | friend CanonicalForm operator * ( const CanonicalForm&, const CanonicalForm& ); |
---|
133 | friend CanonicalForm operator / ( const CanonicalForm&, const CanonicalForm& ); |
---|
134 | friend CanonicalForm operator % ( const CanonicalForm&, const CanonicalForm& ); |
---|
135 | |
---|
136 | friend CanonicalForm div ( const CanonicalForm&, const CanonicalForm& ); |
---|
137 | friend CanonicalForm mod ( const CanonicalForm&, const CanonicalForm& ); |
---|
138 | |
---|
139 | friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
140 | friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
141 | |
---|
142 | friend CanonicalForm bgcd ( const CanonicalForm &, const CanonicalForm & ); |
---|
143 | friend CanonicalForm bextgcd ( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm & ); |
---|
144 | |
---|
145 | // input/output |
---|
146 | #ifndef NOSTREAMIO |
---|
147 | void print( ostream&, char * ) const; |
---|
148 | friend ostream& operator << ( ostream&, const CanonicalForm& ); |
---|
149 | friend istream& operator >> ( istream&, CanonicalForm& ); |
---|
150 | #endif /* NOSTREAMIO */ |
---|
151 | |
---|
152 | // obsolete methods |
---|
153 | static CanonicalForm genCoeff( int what, int i = 0 ); |
---|
154 | CanonicalForm genZero() const; |
---|
155 | CanonicalForm genOne() const; |
---|
156 | |
---|
157 | friend class CFIterator; |
---|
158 | }; |
---|
159 | //}}} |
---|
160 | |
---|
161 | //{{{ function declarations from canonicalform.cc |
---|
162 | CanonicalForm power ( const CanonicalForm & f, int n ); |
---|
163 | |
---|
164 | CanonicalForm power ( const Variable & v, int n ); |
---|
165 | //}}} |
---|
166 | |
---|
167 | //{{{ function declarations from cf_gcd.cc |
---|
168 | CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& ); |
---|
169 | |
---|
170 | CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
171 | |
---|
172 | CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& ); |
---|
173 | |
---|
174 | CanonicalForm pp ( const CanonicalForm& ); |
---|
175 | |
---|
176 | CanonicalForm content ( const CanonicalForm& ); |
---|
177 | |
---|
178 | CanonicalForm content ( const CanonicalForm&, const Variable& ); |
---|
179 | |
---|
180 | CanonicalForm icontent ( const CanonicalForm & f ); |
---|
181 | //}}} |
---|
182 | |
---|
183 | //{{{ function declarations from cf_ops.cc |
---|
184 | CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
185 | |
---|
186 | CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
187 | |
---|
188 | int getNumVars( const CanonicalForm & f ); |
---|
189 | |
---|
190 | CanonicalForm getVars( const CanonicalForm & f ); |
---|
191 | |
---|
192 | CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ); |
---|
193 | |
---|
194 | CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ); |
---|
195 | |
---|
196 | int * degrees ( const CanonicalForm & f, int * degs = 0 ); |
---|
197 | |
---|
198 | int totaldegree ( const CanonicalForm & f ); |
---|
199 | |
---|
200 | int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 ); |
---|
201 | |
---|
202 | int size ( const CanonicalForm & f, const Variable & v ); |
---|
203 | |
---|
204 | int size ( const CanonicalForm & f ); |
---|
205 | //}}} |
---|
206 | |
---|
207 | //{{{ inline functions corresponding to CanonicalForm methods |
---|
208 | //{{{ docu |
---|
209 | // |
---|
210 | // - inline functions corresponding to CanonicalForm methods. |
---|
211 | // |
---|
212 | // These function exist for convenience only and because it is |
---|
213 | // more beautiful to write 'degree( f )' than 'f.degree()'. |
---|
214 | // |
---|
215 | //}}} |
---|
216 | inline CanonicalForm |
---|
217 | lc ( const CanonicalForm & f ) { return f.lc(); } |
---|
218 | |
---|
219 | inline CanonicalForm |
---|
220 | Lc ( const CanonicalForm & f ) { return f.Lc(); } |
---|
221 | |
---|
222 | inline CanonicalForm |
---|
223 | LC ( const CanonicalForm & f ) { return f.LC(); } |
---|
224 | |
---|
225 | inline CanonicalForm |
---|
226 | LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); } |
---|
227 | |
---|
228 | inline int |
---|
229 | degree ( const CanonicalForm & f ) { return f.degree(); } |
---|
230 | |
---|
231 | inline int |
---|
232 | degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); } |
---|
233 | |
---|
234 | inline int |
---|
235 | taildegree ( const CanonicalForm & f ) { return f.taildegree(); } |
---|
236 | |
---|
237 | inline CanonicalForm |
---|
238 | tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); } |
---|
239 | |
---|
240 | inline int |
---|
241 | level ( const CanonicalForm & f ) { return f.level(); } |
---|
242 | |
---|
243 | inline Variable |
---|
244 | mvar ( const CanonicalForm & f ) { return f.mvar(); } |
---|
245 | |
---|
246 | inline CanonicalForm |
---|
247 | num ( const CanonicalForm & f ) { return f.num(); } |
---|
248 | |
---|
249 | inline CanonicalForm |
---|
250 | den ( const CanonicalForm & f ) { return f.den(); } |
---|
251 | |
---|
252 | inline CanonicalForm |
---|
253 | deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); } |
---|
254 | |
---|
255 | inline CanonicalForm |
---|
256 | sqrt ( const CanonicalForm & a ) { return a.sqrt(); } |
---|
257 | |
---|
258 | inline int |
---|
259 | ilog2 ( const CanonicalForm & a ) { return a.ilog2(); } |
---|
260 | |
---|
261 | inline CanonicalForm |
---|
262 | mapinto ( const CanonicalForm & f ) { return f.mapinto(); } |
---|
263 | //}}} |
---|
264 | |
---|
265 | //{{{ inline functions |
---|
266 | inline CanonicalForm |
---|
267 | head ( const CanonicalForm & f ) |
---|
268 | { |
---|
269 | if ( f.level() > 0 ) |
---|
270 | return power( f.mvar(), f.degree() ) * f.LC(); |
---|
271 | else |
---|
272 | return f; |
---|
273 | } |
---|
274 | |
---|
275 | inline CanonicalForm |
---|
276 | abs ( const CanonicalForm & f ) |
---|
277 | { |
---|
278 | if ( f < 0 ) |
---|
279 | return -f; |
---|
280 | else |
---|
281 | return f; |
---|
282 | } |
---|
283 | |
---|
284 | inline int |
---|
285 | headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); } |
---|
286 | //}}} |
---|
287 | |
---|
288 | //{{{ other function declarations |
---|
289 | void setCharacteristic( int c ); // -> Fp && Q |
---|
290 | void setCharacteristic( int c, int n ); // -> PrimePower |
---|
291 | void setCharacteristic( int c, int n, char name ); // -> GF(q) |
---|
292 | |
---|
293 | int getCharacteristic(); |
---|
294 | int getGFDegree(); |
---|
295 | CanonicalForm getGFGenerator(); |
---|
296 | |
---|
297 | void On( int ); |
---|
298 | void Off( int ); |
---|
299 | bool isOn( int ); |
---|
300 | //}}} |
---|
301 | |
---|
302 | //{{{ type definitions |
---|
303 | typedef Factor<CanonicalForm> CFFactor; |
---|
304 | typedef List<CFFactor> CFFList; |
---|
305 | typedef ListIterator<CFFactor> CFFListIterator; |
---|
306 | typedef List<CanonicalForm> CFList; |
---|
307 | typedef ListIterator<CanonicalForm> CFListIterator; |
---|
308 | typedef Array<CanonicalForm> CFArray; |
---|
309 | typedef Matrix<CanonicalForm> CFMatrix; |
---|
310 | //}}} |
---|
311 | |
---|
312 | /*ENDPUBLIC*/ |
---|
313 | |
---|
314 | #endif /* ! INCL_CANONICALFORM_H */ |
---|