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