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