[493c477] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[341696] | 2 | /* $Id$ */ |
---|
[2dd068] | 3 | |
---|
[493c477] | 4 | #ifndef INCL_INT_POLY_H |
---|
| 5 | #define INCL_INT_POLY_H |
---|
[2dd068] | 6 | |
---|
[e4fe2b] | 7 | // #include "config.h" |
---|
[9d7aaa] | 8 | |
---|
[718e670] | 9 | #ifndef NOSTREAMIO |
---|
[1dc616] | 10 | #ifdef HAVE_IOSTREAM |
---|
| 11 | #include <iostream> |
---|
[181148] | 12 | #define OSTREAM std::ostream |
---|
[1dc616] | 13 | #elif defined(HAVE_IOSTREAM_H) |
---|
[718e670] | 14 | #include <iostream.h> |
---|
[181148] | 15 | #define OSTREAM ostream |
---|
[1dc616] | 16 | #endif |
---|
[718e670] | 17 | #endif /* NOSTREAMIO */ |
---|
| 18 | |
---|
[2dd068] | 19 | #include "cf_defs.h" |
---|
| 20 | #include "int_cf.h" |
---|
| 21 | #include "variable.h" |
---|
| 22 | #include "canonicalform.h" |
---|
| 23 | |
---|
[f79b94c] | 24 | #ifdef HAVE_OMALLOC |
---|
[1a9dc5] | 25 | #ifndef OM_NDEBUG |
---|
[ab58510] | 26 | #define OM_NDEBUG |
---|
[1a9dc5] | 27 | #endif |
---|
[b1dfaf] | 28 | # include <omalloc/omalloc.h> |
---|
[f79b94c] | 29 | #endif |
---|
[2dd068] | 30 | |
---|
| 31 | class term { |
---|
| 32 | private: |
---|
| 33 | term * next; |
---|
| 34 | CanonicalForm coeff; |
---|
| 35 | int exp; |
---|
[f79b94c] | 36 | #ifdef HAVE_OMALLOC |
---|
| 37 | static const omBin term_bin; |
---|
| 38 | #endif |
---|
[2dd068] | 39 | public: |
---|
| 40 | term() : next(0), coeff(0), exp(0) {} |
---|
| 41 | term( term * n, const CanonicalForm & c, int e ) : next(n), coeff(c), exp(e) {} |
---|
| 42 | friend class InternalPoly; |
---|
| 43 | friend class CFIterator; |
---|
[f79b94c] | 44 | #ifdef HAVE_OMALLOC |
---|
[0349c20] | 45 | void* operator new(size_t) |
---|
[f79b94c] | 46 | { |
---|
| 47 | void* addr; |
---|
| 48 | omTypeAllocBin(void*, addr, term_bin); |
---|
| 49 | return addr; |
---|
| 50 | } |
---|
[0349c20] | 51 | void operator delete(void* addr, size_t) |
---|
[f79b94c] | 52 | { |
---|
| 53 | omFreeBin(addr, term_bin); |
---|
| 54 | } |
---|
| 55 | #endif |
---|
[2dd068] | 56 | }; |
---|
| 57 | |
---|
| 58 | typedef term * termList; |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | class InternalPoly : public InternalCF { |
---|
| 62 | private: |
---|
| 63 | termList firstTerm, lastTerm; |
---|
| 64 | Variable var; |
---|
| 65 | InternalPoly( termList, termList, const Variable & ); |
---|
| 66 | |
---|
| 67 | static termList copyTermList ( termList, termList&, bool negate = false ); |
---|
| 68 | static termList deepCopyTermList ( termList, termList& ); |
---|
| 69 | static void freeTermList ( termList ); |
---|
| 70 | static void negateTermList ( termList ); |
---|
| 71 | static termList addTermList ( termList, termList, termList&, bool negate ); |
---|
| 72 | static void mulTermList ( termList, const CanonicalForm& , const int ); |
---|
[fc732a9] | 73 | static termList divideTermList ( termList, const CanonicalForm&, termList& ); |
---|
[2dd068] | 74 | static termList divTermList ( termList, const CanonicalForm&, termList& ); |
---|
[ec970e] | 75 | static termList tryDivTermList ( termList, const CanonicalForm&, termList&, const CanonicalForm&, bool& ); |
---|
[2dd068] | 76 | static termList modTermList ( termList, const CanonicalForm&, termList& ); |
---|
| 77 | static void appendTermList ( termList&, termList&, const CanonicalForm&, const int ); |
---|
| 78 | static termList mulAddTermList ( termList theList, termList aList, const CanonicalForm & c, const int exp, termList & lastTerm, bool negate ); |
---|
| 79 | static termList reduceTermList ( termList first, termList redterms, termList & last ); |
---|
| 80 | public: |
---|
| 81 | InternalPoly(); |
---|
| 82 | InternalPoly( const Variable & v, const int e, const CanonicalForm& c ); |
---|
| 83 | InternalPoly( const InternalPoly& ); |
---|
| 84 | ~InternalPoly(); |
---|
| 85 | InternalCF* deepCopyObject() const; |
---|
[c770dc] | 86 | const char * classname() const { return "InternalPoly"; } |
---|
[2dd068] | 87 | int level() const { return var.level(); } |
---|
| 88 | Variable variable() const { return var; } |
---|
| 89 | int degree(); |
---|
| 90 | CanonicalForm lc(); |
---|
[791c0a] | 91 | CanonicalForm Lc(); |
---|
[2dd068] | 92 | CanonicalForm LC(); |
---|
| 93 | int taildegree(); |
---|
| 94 | CanonicalForm tailcoeff(); |
---|
| 95 | CanonicalForm coeff( int i ); |
---|
[718e670] | 96 | #ifndef NOSTREAMIO |
---|
[181148] | 97 | void print( OSTREAM&, char* ); |
---|
[718e670] | 98 | #endif /* NOSTREAMIO */ |
---|
[2dd068] | 99 | bool inBaseDomain() const { return false; } |
---|
| 100 | bool inExtension() const { return var.level() < 0; } |
---|
| 101 | bool inCoeffDomain() const { return var.level() < 0; } |
---|
| 102 | bool inPolyDomain() const { return var.level() > 0; } |
---|
| 103 | bool inQuotDomain() const { return false; } |
---|
| 104 | InternalCF* genZero(); |
---|
| 105 | InternalCF* genOne(); |
---|
| 106 | |
---|
| 107 | bool isUnivariate() const; |
---|
| 108 | |
---|
| 109 | InternalCF* neg(); |
---|
| 110 | InternalCF* invert(); |
---|
[ec970e] | 111 | InternalCF* tryInvert( const CanonicalForm&, bool& ); |
---|
[2dd068] | 112 | int comparesame ( InternalCF* ); |
---|
| 113 | |
---|
| 114 | InternalCF* addsame( InternalCF* ); |
---|
| 115 | InternalCF* subsame( InternalCF* ); |
---|
[718e670] | 116 | InternalCF* mulsame( InternalCF* ); |
---|
[ec970e] | 117 | InternalCF* tryMulsame ( InternalCF*, const CanonicalForm&); |
---|
[2dd068] | 118 | InternalCF* dividesame( InternalCF* ); |
---|
| 119 | InternalCF* modulosame( InternalCF* ); |
---|
| 120 | InternalCF* divsame( InternalCF* ); |
---|
[ec970e] | 121 | InternalCF* tryDivsame ( InternalCF*, const CanonicalForm&, bool& ); |
---|
[2dd068] | 122 | InternalCF* modsame( InternalCF* ); |
---|
| 123 | void divremsame( InternalCF*, InternalCF*&, InternalCF*& ); |
---|
| 124 | bool divremsamet( InternalCF*, InternalCF*&, InternalCF*& ); |
---|
[ec970e] | 125 | bool tryDivremsamet( InternalCF*, InternalCF*&, InternalCF*&, const CanonicalForm&, bool& ); |
---|
[2dd068] | 126 | |
---|
| 127 | int comparecoeff ( InternalCF* ); |
---|
| 128 | |
---|
| 129 | InternalCF* addcoeff( InternalCF* ); |
---|
| 130 | InternalCF* subcoeff( InternalCF*, bool ); |
---|
[718e670] | 131 | InternalCF* mulcoeff( InternalCF* ); |
---|
| 132 | InternalCF* dividecoeff( InternalCF*, bool ); |
---|
[ec970e] | 133 | InternalCF* tryDividecoeff ( InternalCF*, bool, const CanonicalForm&, bool& ); |
---|
[718e670] | 134 | InternalCF* modulocoeff( InternalCF*, bool ); |
---|
| 135 | InternalCF* divcoeff( InternalCF*, bool ); |
---|
[ec970e] | 136 | InternalCF* tryDivcoeff ( InternalCF*, bool, const CanonicalForm&, bool& ); |
---|
[2dd068] | 137 | InternalCF* modcoeff( InternalCF*, bool ); |
---|
| 138 | void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool ); |
---|
| 139 | bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ); |
---|
[ec970e] | 140 | bool tryDivremcoefft ( InternalCF*, InternalCF*&, InternalCF*&, bool, const CanonicalForm&, bool& ); |
---|
[2dd068] | 141 | |
---|
| 142 | int sign() const; |
---|
| 143 | |
---|
[f79b94c] | 144 | #ifdef HAVE_OMALLOC |
---|
| 145 | static const omBin InternalPoly_bin; |
---|
[0349c20] | 146 | void* operator new(size_t) |
---|
[f79b94c] | 147 | { |
---|
| 148 | void* addr; |
---|
| 149 | omTypeAllocBin(void*, addr, InternalPoly_bin); |
---|
| 150 | return addr; |
---|
| 151 | } |
---|
[0349c20] | 152 | void operator delete(void* addr, size_t) |
---|
[f79b94c] | 153 | { |
---|
| 154 | omFreeBin(addr, InternalPoly_bin); |
---|
| 155 | } |
---|
| 156 | #endif |
---|
[2dd068] | 157 | friend class CFIterator; |
---|
| 158 | }; |
---|
| 159 | |
---|
[493c477] | 160 | #endif /* ! INCL_INT_POLY_H */ |
---|