1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: canonicalform.h,v 1.1 1996-06-24 11:26:36 stobbe Exp $ |
---|
3 | |
---|
4 | #ifndef INCL_CANONICALFORM_H |
---|
5 | #define INCL_CANONICALFORM_H |
---|
6 | |
---|
7 | /* |
---|
8 | $Log: not supported by cvs2svn $ |
---|
9 | Revision 1.0 1996/05/17 10:59:37 stobbe |
---|
10 | Initial revision |
---|
11 | |
---|
12 | */ |
---|
13 | |
---|
14 | #include <iostream.h> |
---|
15 | |
---|
16 | #include "cf_defs.h" |
---|
17 | #include "variable.h" |
---|
18 | #include "templates/list.h" |
---|
19 | #include "templates/array.h" |
---|
20 | #include "templates/factor.h" |
---|
21 | #include "templates/matrix.h" |
---|
22 | |
---|
23 | /*BEGINPUBLIC*/ |
---|
24 | |
---|
25 | int initCanonicalForm( void ); |
---|
26 | |
---|
27 | static int cf_is_initialized_now = initCanonicalForm(); |
---|
28 | |
---|
29 | class InternalCF; |
---|
30 | |
---|
31 | class CanonicalForm { |
---|
32 | private: |
---|
33 | InternalCF *value; |
---|
34 | public: |
---|
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 | int sign() const; |
---|
48 | |
---|
49 | bool isOne() const; |
---|
50 | bool isZero() const; |
---|
51 | bool isImm() const; |
---|
52 | |
---|
53 | int intval() const; |
---|
54 | |
---|
55 | CanonicalForm lc() const; |
---|
56 | CanonicalForm LC() const; |
---|
57 | CanonicalForm LC( const Variable & v ) const; |
---|
58 | |
---|
59 | int degree() const; |
---|
60 | int degree( const Variable & v ) const; |
---|
61 | |
---|
62 | CanonicalForm tailcoeff() const; |
---|
63 | int taildegree() const; |
---|
64 | |
---|
65 | int level() const; |
---|
66 | Variable mvar() const; |
---|
67 | |
---|
68 | CanonicalForm num() const; |
---|
69 | CanonicalForm den() const; |
---|
70 | |
---|
71 | CanonicalForm deepCopy() const; |
---|
72 | |
---|
73 | bool isFFinGF() const; |
---|
74 | bool hasGcd() const { return false; } |
---|
75 | CanonicalForm gcd( const CanonicalForm & f ) const; |
---|
76 | CanonicalForm deriv() const; |
---|
77 | CanonicalForm deriv( const Variable & x ) const; |
---|
78 | CanonicalForm sqrt() const; |
---|
79 | static CanonicalForm genCoeff( int what, int i = 0 ); |
---|
80 | |
---|
81 | CanonicalForm genZero() const; |
---|
82 | CanonicalForm genOne() const; |
---|
83 | |
---|
84 | bool isUnivariate() const; |
---|
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 | CanonicalForm mapinto () const; |
---|
98 | |
---|
99 | CanonicalForm operator () ( const CanonicalForm & f ) const; |
---|
100 | CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const; |
---|
101 | CanonicalForm operator [] ( int i ) const; |
---|
102 | CanonicalForm& operator = ( const CanonicalForm& ); |
---|
103 | CanonicalForm& operator = ( const int ); |
---|
104 | |
---|
105 | CanonicalForm& operator += ( const CanonicalForm& ); |
---|
106 | CanonicalForm& operator -= ( const CanonicalForm& ); |
---|
107 | CanonicalForm& operator *= ( const CanonicalForm& ); |
---|
108 | CanonicalForm& operator /= ( const CanonicalForm& ); |
---|
109 | CanonicalForm& operator %= ( const CanonicalForm& ); |
---|
110 | CanonicalForm& div ( const CanonicalForm& ); |
---|
111 | CanonicalForm& mod ( const CanonicalForm& ); |
---|
112 | |
---|
113 | friend CanonicalForm operator - ( const CanonicalForm& ); |
---|
114 | |
---|
115 | friend CanonicalForm operator + ( const CanonicalForm&, const CanonicalForm& ); |
---|
116 | friend CanonicalForm operator - ( const CanonicalForm&, const CanonicalForm& ); |
---|
117 | friend CanonicalForm operator * ( const CanonicalForm&, const CanonicalForm& ); |
---|
118 | friend CanonicalForm operator / ( const CanonicalForm&, const CanonicalForm& ); |
---|
119 | friend CanonicalForm operator % ( const CanonicalForm&, const CanonicalForm& ); |
---|
120 | |
---|
121 | friend CanonicalForm div ( const CanonicalForm&, const CanonicalForm& ); |
---|
122 | friend CanonicalForm mod ( const CanonicalForm&, const CanonicalForm& ); |
---|
123 | |
---|
124 | friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
125 | friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
126 | |
---|
127 | void print( ostream&, char * ) const; |
---|
128 | friend ostream& operator << ( ostream&, const CanonicalForm& ); |
---|
129 | friend istream& operator >> ( istream&, CanonicalForm& ); |
---|
130 | |
---|
131 | friend bool operator == ( const CanonicalForm&, const CanonicalForm& ); |
---|
132 | friend bool operator != ( const CanonicalForm&, const CanonicalForm& ); |
---|
133 | friend bool operator > ( const CanonicalForm&, const CanonicalForm& ); |
---|
134 | friend bool operator < ( const CanonicalForm&, const CanonicalForm& ); |
---|
135 | |
---|
136 | friend class CFIterator; |
---|
137 | }; |
---|
138 | |
---|
139 | // some useful functions |
---|
140 | |
---|
141 | inline CanonicalForm |
---|
142 | lc ( const CanonicalForm & f ) { return f.lc(); } |
---|
143 | |
---|
144 | inline CanonicalForm |
---|
145 | LC ( const CanonicalForm & f ) { return f.LC(); } |
---|
146 | |
---|
147 | inline CanonicalForm |
---|
148 | LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); } |
---|
149 | |
---|
150 | inline int |
---|
151 | degree ( const CanonicalForm & f ) { return f.degree(); } |
---|
152 | |
---|
153 | inline int |
---|
154 | degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); } |
---|
155 | |
---|
156 | int totaldegree ( const CanonicalForm & f ); |
---|
157 | |
---|
158 | int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 ); |
---|
159 | |
---|
160 | inline int |
---|
161 | taildegree ( const CanonicalForm & f ) { return f.taildegree(); } |
---|
162 | |
---|
163 | inline CanonicalForm |
---|
164 | tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); } |
---|
165 | |
---|
166 | CanonicalForm power ( const CanonicalForm & f, int n ); |
---|
167 | |
---|
168 | CanonicalForm power ( const Variable & v, int n ); |
---|
169 | |
---|
170 | inline CanonicalForm |
---|
171 | head ( const CanonicalForm & f ) |
---|
172 | { |
---|
173 | if ( f.level() > 0 ) |
---|
174 | return power( f.mvar(), f.degree() ) * f.LC(); |
---|
175 | else |
---|
176 | return f; |
---|
177 | } |
---|
178 | |
---|
179 | inline int |
---|
180 | headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); } |
---|
181 | |
---|
182 | inline int |
---|
183 | level ( const CanonicalForm & f ) { return f.level(); } |
---|
184 | |
---|
185 | inline CanonicalForm |
---|
186 | mvar ( const CanonicalForm & f ) { return f.mvar(); } |
---|
187 | |
---|
188 | inline CanonicalForm |
---|
189 | num ( const CanonicalForm & f ) { return f.num(); } |
---|
190 | |
---|
191 | inline CanonicalForm |
---|
192 | den ( const CanonicalForm & f ) { return f.den(); } |
---|
193 | |
---|
194 | inline CanonicalForm |
---|
195 | mapinto ( const CanonicalForm & f ) { return f.mapinto(); } |
---|
196 | |
---|
197 | CanonicalForm swapvar ( const CanonicalForm&, const Variable&, const Variable& ); |
---|
198 | |
---|
199 | CanonicalForm resultant( const CanonicalForm & f, const CanonicalForm& g, const Variable & x ); |
---|
200 | |
---|
201 | CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& ); |
---|
202 | |
---|
203 | CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
204 | |
---|
205 | CanonicalForm iextgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& ); |
---|
206 | |
---|
207 | CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& ); |
---|
208 | |
---|
209 | CanonicalForm common_den ( const CanonicalForm& ); |
---|
210 | |
---|
211 | CanonicalForm pp ( const CanonicalForm& ); |
---|
212 | |
---|
213 | CanonicalForm content ( const CanonicalForm& ); |
---|
214 | |
---|
215 | CanonicalForm content ( const CanonicalForm&, const Variable& ); |
---|
216 | |
---|
217 | CanonicalForm icontent ( const CanonicalForm & f ); |
---|
218 | |
---|
219 | CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ); |
---|
220 | |
---|
221 | CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ); |
---|
222 | |
---|
223 | bool divides ( const CanonicalForm & f, const CanonicalForm & g ); |
---|
224 | |
---|
225 | inline CanonicalForm |
---|
226 | deriv ( const CanonicalForm & f, const Variable & x ) |
---|
227 | { |
---|
228 | return f.deriv(x); |
---|
229 | } |
---|
230 | |
---|
231 | inline CanonicalForm |
---|
232 | abs ( const CanonicalForm & f ) |
---|
233 | { |
---|
234 | if ( f < 0 ) |
---|
235 | return -f; |
---|
236 | else |
---|
237 | return f; |
---|
238 | } |
---|
239 | |
---|
240 | inline CanonicalForm |
---|
241 | sqrt ( const CanonicalForm & a ) |
---|
242 | { |
---|
243 | return a.sqrt(); |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | CanonicalForm psr ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
248 | |
---|
249 | CanonicalForm psq ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
250 | |
---|
251 | void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r, const Variable & x ); |
---|
252 | |
---|
253 | int getNumVars( const CanonicalForm & f ); |
---|
254 | CanonicalForm getVars( const CanonicalForm & f ); |
---|
255 | |
---|
256 | int * degrees ( const CanonicalForm & f, int * degs = 0 ); |
---|
257 | |
---|
258 | //CanonicalForm norm( const CanonicalForm & ); |
---|
259 | |
---|
260 | //CanonicalForm igcd( const CanonicalForm & ); |
---|
261 | |
---|
262 | //CanonicalForm ff2z( const CanonicalForm & ); |
---|
263 | //CanonicalForm z2ff( const CanonicalForm & ); |
---|
264 | |
---|
265 | void setCharacteristic( int c ); // -> Fp && Q |
---|
266 | void setCharacteristic( int c, int n ); // -> PrimePower |
---|
267 | void setCharacteristic( int c, int n, char name ); // -> GF(q) |
---|
268 | |
---|
269 | int getCharacteristic(); |
---|
270 | int getGFDegree(); |
---|
271 | |
---|
272 | CanonicalForm getGFGenerator(); |
---|
273 | |
---|
274 | // misc template stuff for inst file |
---|
275 | |
---|
276 | typedef Factor<CanonicalForm> CFFactor; |
---|
277 | typedef List<CFFactor> CFFList; |
---|
278 | typedef ListIterator<CFFactor> CFFListIterator; |
---|
279 | typedef List<CanonicalForm> CFList; |
---|
280 | typedef ListIterator<CanonicalForm> CFListIterator; |
---|
281 | typedef Array<CanonicalForm> CFArray; |
---|
282 | typedef Matrix<CanonicalForm> CFMatrix; |
---|
283 | |
---|
284 | CFFList sqrFree( const CanonicalForm & f ); |
---|
285 | |
---|
286 | bool isSqrFree( const CanonicalForm & f ); |
---|
287 | |
---|
288 | CFFList factorize( const CanonicalForm & f, bool issqrfree = false ); |
---|
289 | |
---|
290 | CFFList factorize( const CanonicalForm & f, const Variable & alpha ); |
---|
291 | |
---|
292 | // calculate the determinant of the n'th minor of M |
---|
293 | |
---|
294 | CanonicalForm determinant( const CFMatrix & M, int n ); |
---|
295 | |
---|
296 | void On( int ); |
---|
297 | void Off( int ); |
---|
298 | bool isOn( int ); |
---|
299 | |
---|
300 | /*ENDPUBLIC*/ |
---|
301 | |
---|
302 | #endif /* INCL_CANONICALFORM_H */ |
---|