[493c477] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[ae5205] | 2 | /* $Id: canonicalform.h,v 1.10 1997-07-31 13:04:37 schmidt Exp $ */ |
---|
[2dd068] | 3 | |
---|
| 4 | #ifndef INCL_CANONICALFORM_H |
---|
| 5 | #define INCL_CANONICALFORM_H |
---|
| 6 | |
---|
[cc1367] | 7 | #include <config.h> |
---|
| 8 | |
---|
[c5323e] | 9 | #ifndef NOSTREAMIO |
---|
[2dd068] | 10 | #include <iostream.h> |
---|
[c5323e] | 11 | #endif /* NOSTREAMIO */ |
---|
[2dd068] | 12 | |
---|
| 13 | #include "cf_defs.h" |
---|
| 14 | #include "variable.h" |
---|
[23ff95] | 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 |
---|
[974ce1] | 21 | #include "templates/ftmpl_list.h" |
---|
| 22 | #include "templates/ftmpl_array.h" |
---|
| 23 | #include "templates/ftmpl_factor.h" |
---|
| 24 | #include "templates/ftmpl_matrix.h" |
---|
[23ff95] | 25 | #endif |
---|
[2dd068] | 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; |
---|
[f623b4a] | 83 | int ilog2() const; |
---|
[2dd068] | 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 | |
---|
[c5323e] | 118 | friend CanonicalForm operator - ( const CanonicalForm& ); |
---|
[2dd068] | 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 | |
---|
[c5323e] | 132 | #ifndef NOSTREAMIO |
---|
[2dd068] | 133 | void print( ostream&, char * ) const; |
---|
| 134 | friend ostream& operator << ( ostream&, const CanonicalForm& ); |
---|
| 135 | friend istream& operator >> ( istream&, CanonicalForm& ); |
---|
[c5323e] | 136 | #endif /* NOSTREAMIO */ |
---|
[2dd068] | 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 resultant( const CanonicalForm & f, const CanonicalForm& g, const Variable & x ); |
---|
| 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 common_den ( const CanonicalForm& ); |
---|
| 217 | |
---|
| 218 | CanonicalForm pp ( const CanonicalForm& ); |
---|
| 219 | |
---|
| 220 | CanonicalForm content ( const CanonicalForm& ); |
---|
| 221 | |
---|
| 222 | CanonicalForm content ( const CanonicalForm&, const Variable& ); |
---|
| 223 | |
---|
| 224 | CanonicalForm icontent ( const CanonicalForm & f ); |
---|
| 225 | |
---|
| 226 | CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ); |
---|
| 227 | |
---|
| 228 | CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ); |
---|
| 229 | |
---|
| 230 | bool divides ( const CanonicalForm & f, const CanonicalForm & g ); |
---|
| 231 | |
---|
| 232 | inline CanonicalForm |
---|
| 233 | deriv ( const CanonicalForm & f, const Variable & x ) |
---|
| 234 | { |
---|
| 235 | return f.deriv(x); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | inline CanonicalForm |
---|
| 239 | abs ( const CanonicalForm & f ) |
---|
| 240 | { |
---|
| 241 | if ( f < 0 ) |
---|
| 242 | return -f; |
---|
| 243 | else |
---|
| 244 | return f; |
---|
| 245 | } |
---|
| 246 | |
---|
[ae5205] | 247 | //{{{ inline CanonicalForm sqrt ( const CanonicalForm & a ) |
---|
| 248 | //{{{ docu |
---|
| 249 | // |
---|
| 250 | // sqrt() - inline function version of method sqrt(). |
---|
| 251 | // |
---|
| 252 | //}}} |
---|
[2dd068] | 253 | inline CanonicalForm |
---|
| 254 | sqrt ( const CanonicalForm & a ) |
---|
| 255 | { |
---|
| 256 | return a.sqrt(); |
---|
| 257 | } |
---|
[ae5205] | 258 | //}}} |
---|
[2dd068] | 259 | |
---|
[f623b4a] | 260 | //{{{ inline int ilog2 ( const CanonicalForm & a ) |
---|
| 261 | //{{{ docu |
---|
| 262 | // |
---|
| 263 | // ilog2() - inline function version of method ilog(). |
---|
| 264 | // |
---|
| 265 | //}}} |
---|
| 266 | inline int |
---|
| 267 | ilog2 ( const CanonicalForm & a ) |
---|
| 268 | { |
---|
| 269 | return a.ilog2(); |
---|
| 270 | } |
---|
| 271 | //}}} |
---|
[2dd068] | 272 | |
---|
| 273 | CanonicalForm psr ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
| 274 | |
---|
| 275 | CanonicalForm psq ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ); |
---|
| 276 | |
---|
| 277 | void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r, const Variable & x ); |
---|
| 278 | |
---|
| 279 | int getNumVars( const CanonicalForm & f ); |
---|
| 280 | CanonicalForm getVars( const CanonicalForm & f ); |
---|
| 281 | |
---|
| 282 | int * degrees ( const CanonicalForm & f, int * degs = 0 ); |
---|
| 283 | |
---|
| 284 | //CanonicalForm norm( const CanonicalForm & ); |
---|
| 285 | |
---|
| 286 | //CanonicalForm igcd( const CanonicalForm & ); |
---|
| 287 | |
---|
| 288 | //CanonicalForm ff2z( const CanonicalForm & ); |
---|
| 289 | //CanonicalForm z2ff( const CanonicalForm & ); |
---|
| 290 | |
---|
| 291 | void setCharacteristic( int c ); // -> Fp && Q |
---|
| 292 | void setCharacteristic( int c, int n ); // -> PrimePower |
---|
| 293 | void setCharacteristic( int c, int n, char name ); // -> GF(q) |
---|
| 294 | |
---|
| 295 | int getCharacteristic(); |
---|
| 296 | int getGFDegree(); |
---|
| 297 | |
---|
| 298 | CanonicalForm getGFGenerator(); |
---|
| 299 | |
---|
| 300 | // misc template stuff for inst file |
---|
| 301 | |
---|
| 302 | typedef Factor<CanonicalForm> CFFactor; |
---|
| 303 | typedef List<CFFactor> CFFList; |
---|
| 304 | typedef ListIterator<CFFactor> CFFListIterator; |
---|
| 305 | typedef List<CanonicalForm> CFList; |
---|
| 306 | typedef ListIterator<CanonicalForm> CFListIterator; |
---|
| 307 | typedef Array<CanonicalForm> CFArray; |
---|
[95f247] | 308 | typedef Matrix<CanonicalForm> CFMatrix; |
---|
[2dd068] | 309 | |
---|
[87e1de] | 310 | CFFList sqrFree ( const CanonicalForm & f, bool sort ); |
---|
| 311 | |
---|
[2dd068] | 312 | CFFList sqrFree( const CanonicalForm & f ); |
---|
| 313 | |
---|
| 314 | bool isSqrFree( const CanonicalForm & f ); |
---|
| 315 | |
---|
| 316 | CFFList factorize( const CanonicalForm & f, bool issqrfree = false ); |
---|
| 317 | |
---|
| 318 | CFFList factorize( const CanonicalForm & f, const Variable & alpha ); |
---|
| 319 | |
---|
[95f247] | 320 | // calculate the determinant of the n'th minor of M |
---|
| 321 | |
---|
[7155e1] | 322 | bool linearSystemSolve( CFMatrix & M ); |
---|
| 323 | |
---|
[95f247] | 324 | CanonicalForm determinant( const CFMatrix & M, int n ); |
---|
| 325 | |
---|
[2dd068] | 326 | void On( int ); |
---|
| 327 | void Off( int ); |
---|
| 328 | bool isOn( int ); |
---|
| 329 | |
---|
| 330 | /*ENDPUBLIC*/ |
---|
| 331 | |
---|
[493c477] | 332 | #endif /* ! INCL_CANONICALFORM_H */ |
---|