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