1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: canonicalform.h,v 1.16 1997-09-09 08:40:54 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 | private: |
---|
37 | InternalCF *value; |
---|
38 | public: |
---|
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 | |
---|
148 | inline CanonicalForm |
---|
149 | lc ( const CanonicalForm & f ) { return f.lc(); } |
---|
150 | |
---|
151 | inline CanonicalForm |
---|
152 | LC ( const CanonicalForm & f ) { return f.LC(); } |
---|
153 | |
---|
154 | inline CanonicalForm |
---|
155 | LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); } |
---|
156 | |
---|
157 | inline int |
---|
158 | degree ( const CanonicalForm & f ) { return f.degree(); } |
---|
159 | |
---|
160 | inline int |
---|
161 | degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); } |
---|
162 | |
---|
163 | int totaldegree ( const CanonicalForm & f ); |
---|
164 | |
---|
165 | int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 ); |
---|
166 | |
---|
167 | inline int |
---|
168 | taildegree ( const CanonicalForm & f ) { return f.taildegree(); } |
---|
169 | |
---|
170 | inline CanonicalForm |
---|
171 | tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); } |
---|
172 | |
---|
173 | CanonicalForm power ( const CanonicalForm & f, int n ); |
---|
174 | |
---|
175 | CanonicalForm power ( const Variable & v, int n ); |
---|
176 | |
---|
177 | inline CanonicalForm |
---|
178 | head ( 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 | |
---|
186 | inline int |
---|
187 | headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); } |
---|
188 | |
---|
189 | inline int |
---|
190 | level ( const CanonicalForm & f ) { return f.level(); } |
---|
191 | |
---|
192 | inline CanonicalForm |
---|
193 | mvar ( const CanonicalForm & f ) { return f.mvar(); } |
---|
194 | |
---|
195 | inline CanonicalForm |
---|
196 | num ( const CanonicalForm & f ) { return f.num(); } |
---|
197 | |
---|
198 | inline CanonicalForm |
---|
199 | den ( const CanonicalForm & f ) { return f.den(); } |
---|
200 | |
---|
201 | inline CanonicalForm |
---|
202 | mapinto ( const CanonicalForm & f ) { return f.mapinto(); } |
---|
203 | |
---|
204 | CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
205 | |
---|
206 | CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & ); |
---|
207 | |
---|
208 | CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& ); |
---|
209 | |
---|
210 | CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
211 | |
---|
212 | CanonicalForm iextgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
213 | |
---|
214 | CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& ); |
---|
215 | |
---|
216 | CanonicalForm pp ( const CanonicalForm& ); |
---|
217 | |
---|
218 | CanonicalForm content ( const CanonicalForm& ); |
---|
219 | |
---|
220 | CanonicalForm content ( const CanonicalForm&, const Variable& ); |
---|
221 | |
---|
222 | CanonicalForm icontent ( const CanonicalForm & f ); |
---|
223 | |
---|
224 | CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ); |
---|
225 | |
---|
226 | CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ); |
---|
227 | |
---|
228 | bool divides ( const CanonicalForm & f, const CanonicalForm & g ); |
---|
229 | |
---|
230 | //{{{ inline CanonicalForm deriv ( const CanonicalForm & f, const Variable & x ) |
---|
231 | //{{{ docu |
---|
232 | // |
---|
233 | // deriv() - inline function version of method deriv(). |
---|
234 | // |
---|
235 | //}}} |
---|
236 | inline CanonicalForm |
---|
237 | deriv ( const CanonicalForm & f, const Variable & x ) |
---|
238 | { |
---|
239 | return f.deriv(x); |
---|
240 | } |
---|
241 | //}}} |
---|
242 | |
---|
243 | inline CanonicalForm |
---|
244 | abs ( const CanonicalForm & f ) |
---|
245 | { |
---|
246 | if ( f < 0 ) |
---|
247 | return -f; |
---|
248 | else |
---|
249 | return f; |
---|
250 | } |
---|
251 | |
---|
252 | //{{{ inline CanonicalForm sqrt ( const CanonicalForm & a ) |
---|
253 | //{{{ docu |
---|
254 | // |
---|
255 | // sqrt() - inline function version of method sqrt(). |
---|
256 | // |
---|
257 | //}}} |
---|
258 | inline CanonicalForm |
---|
259 | sqrt ( const CanonicalForm & a ) |
---|
260 | { |
---|
261 | return a.sqrt(); |
---|
262 | } |
---|
263 | //}}} |
---|
264 | |
---|
265 | //{{{ inline int ilog2 ( const CanonicalForm & a ) |
---|
266 | //{{{ docu |
---|
267 | // |
---|
268 | // ilog2() - inline function version of method ilog(). |
---|
269 | // |
---|
270 | //}}} |
---|
271 | inline int |
---|
272 | ilog2 ( const CanonicalForm & a ) |
---|
273 | { |
---|
274 | return a.ilog2(); |
---|
275 | } |
---|
276 | //}}} |
---|
277 | |
---|
278 | int getNumVars( const CanonicalForm & f ); |
---|
279 | CanonicalForm getVars( const CanonicalForm & f ); |
---|
280 | |
---|
281 | int * degrees ( const CanonicalForm & f, int * degs = 0 ); |
---|
282 | |
---|
283 | //CanonicalForm norm( const CanonicalForm & ); |
---|
284 | |
---|
285 | //CanonicalForm igcd( const CanonicalForm & ); |
---|
286 | |
---|
287 | //CanonicalForm ff2z( const CanonicalForm & ); |
---|
288 | //CanonicalForm z2ff( const CanonicalForm & ); |
---|
289 | |
---|
290 | void setCharacteristic( int c ); // -> Fp && Q |
---|
291 | void setCharacteristic( int c, int n ); // -> PrimePower |
---|
292 | void setCharacteristic( int c, int n, char name ); // -> GF(q) |
---|
293 | |
---|
294 | int getCharacteristic(); |
---|
295 | int getGFDegree(); |
---|
296 | |
---|
297 | CanonicalForm getGFGenerator(); |
---|
298 | |
---|
299 | // misc template stuff for inst file |
---|
300 | |
---|
301 | typedef Factor<CanonicalForm> CFFactor; |
---|
302 | typedef List<CFFactor> CFFList; |
---|
303 | typedef ListIterator<CFFactor> CFFListIterator; |
---|
304 | typedef List<CanonicalForm> CFList; |
---|
305 | typedef ListIterator<CanonicalForm> CFListIterator; |
---|
306 | typedef Array<CanonicalForm> CFArray; |
---|
307 | typedef Matrix<CanonicalForm> CFMatrix; |
---|
308 | |
---|
309 | void On( int ); |
---|
310 | void Off( int ); |
---|
311 | bool isOn( int ); |
---|
312 | |
---|
313 | /*ENDPUBLIC*/ |
---|
314 | |
---|
315 | #endif /* ! INCL_CANONICALFORM_H */ |
---|