[35aab3] | 1 | #ifndef KBUCKETS_H |
---|
| 2 | #define KBUCKETS_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[341696] | 6 | /* $Id$ */ |
---|
[78eba1] | 7 | #include <polys/monomials/ring.h> |
---|
| 8 | #include <polys/templates/p_Procs.h> |
---|
[35aab3] | 9 | |
---|
[42ddd0] | 10 | //#define HAVE_COEF_BUCKETS |
---|
[35aab3] | 11 | |
---|
| 12 | ///////////////////////////////////////////////////////////////////////// |
---|
| 13 | // configuration |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | // define to not really use the bucket feature |
---|
| 17 | // #define HAVE_PSEUDO_BUCKETS |
---|
| 18 | |
---|
| 19 | ////////////////////////////////////////////////////////////////////////// |
---|
| 20 | // Creation/Destruction of buckets |
---|
| 21 | // |
---|
[71ba5b8] | 22 | kBucket_pt kBucketCreate(ring r); |
---|
[35aab3] | 23 | // only free memory allocated for bucket |
---|
| 24 | void kBucketDestroy(kBucket_pt *bucket); |
---|
| 25 | // frees polys/monomials in bucket and destroys bucket |
---|
| 26 | void kBucketDeleteAndDestroy(kBucket_pt *bucket); |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 30 | // Convertion from/to Bpolys |
---|
| 31 | // |
---|
| 32 | |
---|
| 33 | // Converts p into a bucket poly (Bpoly) and destroys p |
---|
| 34 | // Assumes length <= 0 || pLength(p) == length |
---|
| 35 | void kBucketInit(kBucket_pt bucket, poly p, int length); |
---|
| 36 | |
---|
| 37 | // Converts Bpoly into a poly and clears bucket |
---|
| 38 | // i.e., afterwards Bpoly == 0 |
---|
| 39 | void kBucketClear(kBucket_pt bucket, poly *p, int *length); |
---|
| 40 | inline poly kBucketClear(kBucket_pt bucket) |
---|
| 41 | { |
---|
| 42 | int dummy; |
---|
| 43 | poly p; |
---|
| 44 | kBucketClear(bucket, &p, &dummy); |
---|
| 45 | return p; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | // Canonicalizes Bpoly, i.e. converts polys of buckets into one poly in |
---|
| 49 | // one bucket: Returns number of bucket into which it is canonicalized |
---|
| 50 | int kBucketCanonicalize(kBucket_pt bucket); |
---|
| 51 | |
---|
| 52 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 53 | // Extracts lm of Bpoly, i.e. Bpoly is changed s.t. |
---|
| 54 | // Bpoly == Bpoly - Lm(Bpoly) |
---|
| 55 | // |
---|
| 56 | inline poly kBucketExtractLm(kBucket_pt bucket); |
---|
| 57 | |
---|
| 58 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 59 | // Sets Lm of Bpoly, i.e. Bpoly is changed s.t. |
---|
| 60 | // Bpoly = Bpoly + m |
---|
| 61 | // assumes that m is larger than all monomials of Bpoly |
---|
| 62 | void kBucketSetLm(kBucket_pt bucket, poly lm); |
---|
| 63 | |
---|
| 64 | |
---|
[cea6f3] | 65 | ////////////////////////////////////////////////////////////////////////// |
---|
| 66 | /// |
---|
| 67 | /// Bucket number i from bucket is out of length sync, resync |
---|
| 68 | /// |
---|
| 69 | void kBucketAdjust(kBucket_pt bucket, int i); |
---|
| 70 | |
---|
[35aab3] | 71 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 72 | // Reduces Bpoly (say, q) with p, i.e.: |
---|
| 73 | // q = (Lc(p) / gcd(Lc(p), Lc(q)))*q - (Lc(q)/gcd(Lc(p),Lc(q)))*p*(Lm(q)/Lm(p)) |
---|
| 74 | // Assumes p1 != NULL, Bpoly != NULL |
---|
| 75 | // Lm(p1) divides Lm(Bpoly) |
---|
| 76 | // pLength(p1) == l1 |
---|
| 77 | // Returns: Lc(p) / gcd(Lc(p), Lc(q)) |
---|
| 78 | number kBucketPolyRed(kBucket_pt bucket, |
---|
| 79 | poly p, int l, |
---|
| 80 | poly spNoether); |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 84 | // |
---|
| 85 | // Extract all monomials from bucket with component comp |
---|
| 86 | // Return as a polynomial *p with length *l |
---|
| 87 | // In other words, afterwards |
---|
| 88 | // Bpoly == Bpoly - (poly consisting of all monomials with component comp) |
---|
| 89 | // and components of monomials of *p are all 0 |
---|
| 90 | |
---|
| 91 | void kBucketTakeOutComp(kBucket_pt bucket, |
---|
[0b5e3d] | 92 | long comp, |
---|
[35aab3] | 93 | poly *p, int *l); |
---|
| 94 | |
---|
| 95 | ////////////////////////////////////////////////////////////////////////// |
---|
| 96 | /// |
---|
| 97 | /// Multiply Bucket by number ,i.e. Bpoly == n*Bpoly |
---|
| 98 | /// |
---|
| 99 | void kBucket_Mult_n(kBucket_pt bucket, number n); |
---|
| 100 | |
---|
| 101 | ////////////////////////////////////////////////////////////////////////// |
---|
| 102 | /// |
---|
| 103 | /// Extract all monomials of bucket which are larger than q |
---|
| 104 | /// Append those to append, and return last monomial of append |
---|
| 105 | poly kBucket_ExtractLarger(kBucket_pt bucket, poly q, poly append); |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | ////////////////////////////////////////////////////////////////////////// |
---|
| 109 | /// |
---|
| 110 | /// Add to Bucket a poly ,i.e. Bpoly == Bpoly + q |
---|
| 111 | /// |
---|
| 112 | void kBucket_Add_q(kBucket_pt bucket, poly q, int* lq); |
---|
| 113 | |
---|
| 114 | // first, do ExtractLarger |
---|
| 115 | // then add q |
---|
| 116 | inline poly |
---|
| 117 | kBucket_ExtractLarger_Add_q(kBucket_pt bucket, poly append, poly q, int *lq) |
---|
| 118 | { |
---|
| 119 | append = kBucket_ExtractLarger(bucket, q, append); |
---|
| 120 | kBucket_Add_q(bucket, q, lq); |
---|
| 121 | return append; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | ////////////////////////////////////////////////////////////////////////// |
---|
| 125 | /// |
---|
| 126 | /// Bpoly == Bpoly - m*p; where m is a monom |
---|
| 127 | /// Does not destroy p and m |
---|
| 128 | /// assume (*l <= 0 || pLength(p) == *l) |
---|
| 129 | void kBucket_Minus_m_Mult_p(kBucket_pt bucket, poly m, poly p, int *l, |
---|
| 130 | poly spNother = NULL); |
---|
| 131 | |
---|
| 132 | ////////////////////////////////////////////////////////////////////////// |
---|
| 133 | /// |
---|
| 134 | /// Bpoly == Bpoly + m*p; where m is a monom |
---|
| 135 | /// Does not destroy p and m |
---|
| 136 | /// assume (l <= 0 || pLength(p) == l) |
---|
| 137 | void kBucket_Plus_mm_Mult_pp(kBucket_pt bucket, poly m, poly p, int l); |
---|
| 138 | |
---|
| 139 | ////////////////////////////////////////////////////////////////////////// |
---|
| 140 | /// |
---|
| 141 | /// For changing the ring of the Bpoly to new_tailBin |
---|
| 142 | /// |
---|
| 143 | void kBucketShallowCopyDelete(kBucket_pt bucket, |
---|
| 144 | ring new_tailRing, omBin new_tailBin, |
---|
| 145 | pShallowCopyDeleteProc p_shallow_copy_delete); |
---|
| 146 | |
---|
| 147 | ////////////////////////////////////////////////////////////////////////// |
---|
| 148 | /// |
---|
| 149 | /// Tests |
---|
| 150 | /// |
---|
| 151 | /// |
---|
| 152 | #ifdef KDEBUG |
---|
| 153 | BOOLEAN kbTest(kBucket_pt bucket); |
---|
| 154 | #else |
---|
| 155 | #define kbTest(bucket) ((void)0) |
---|
| 156 | #endif |
---|
| 157 | |
---|
| 158 | ////////////////////////////////////////////////////////////////////////// |
---|
| 159 | /// |
---|
| 160 | /// Bucket definition (should be no one elses business, though) |
---|
| 161 | /// |
---|
| 162 | |
---|
| 163 | // define this if length of bucket polys are 2, 4, 8, etc |
---|
| 164 | // instead of 4, 16, 64 ... -- |
---|
| 165 | // this seems to be less efficient, both, in theory and in practice |
---|
| 166 | // #define BUCKET_TWO_BASE |
---|
| 167 | #ifdef BUCKET_TWO_BASE |
---|
| 168 | #define MAX_BUCKET 28 |
---|
| 169 | #else |
---|
| 170 | #define MAX_BUCKET 14 // suitable for polys up to a length of 4^14 = 2^28 |
---|
| 171 | #endif |
---|
| 172 | |
---|
| 173 | class kBucket |
---|
| 174 | { |
---|
| 175 | public: |
---|
| 176 | #ifdef HAVE_PSEUDO_BUCKETS |
---|
| 177 | poly p; |
---|
| 178 | int l; |
---|
| 179 | #else |
---|
| 180 | poly buckets[MAX_BUCKET + 1]; // polys in bucket |
---|
| 181 | #ifdef HAVE_COEF_BUCKETS |
---|
| 182 | poly coef[MAX_BUCKET + 1]; // coeff of polys in bucket or NULL : 2..max |
---|
| 183 | #endif |
---|
| 184 | int buckets_length[MAX_BUCKET + 1]; // length if i-th poly |
---|
| 185 | int buckets_used; // max number of used bucket |
---|
| 186 | #endif |
---|
| 187 | ring bucket_ring; |
---|
| 188 | }; |
---|
| 189 | |
---|
[ba4466] | 190 | #ifndef HAVE_PSEUDO_BUCKETS |
---|
[35aab3] | 191 | inline void kBucketAdjustBucketsUsed(kBucket_pt bucket) |
---|
| 192 | { |
---|
| 193 | while ( bucket->buckets_used > 0 && |
---|
| 194 | bucket->buckets[bucket->buckets_used] == NULL) |
---|
| 195 | (bucket->buckets_used)--; |
---|
| 196 | } |
---|
[ba4466] | 197 | #endif |
---|
[35aab3] | 198 | |
---|
[760a78f] | 199 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 200 | // Gets leading monom of bucket, does NOT change Bpoly!!!!! |
---|
| 201 | // Returned monom is READ ONLY, i.e. no manipulations are allowed !!!! |
---|
| 202 | // |
---|
| 203 | inline poly kBucketGetLm(kBucket_pt bucket) |
---|
[35aab3] | 204 | { |
---|
[42ddd0] | 205 | #ifdef HAVE_COEF_BUCKETS |
---|
[86e6577] | 206 | assume(bucket->coef[0]==NULL); |
---|
[42ddd0] | 207 | #endif |
---|
[35aab3] | 208 | if (bucket->buckets[0] == NULL) |
---|
| 209 | bucket->bucket_ring->p_Procs->p_kBucketSetLm(bucket); |
---|
[42ddd0] | 210 | #ifdef HAVE_COEF_BUCKETS |
---|
[86e6577] | 211 | assume(bucket->coef[0]==NULL); |
---|
[42ddd0] | 212 | #endif |
---|
[35aab3] | 213 | return bucket->buckets[0]; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | inline poly kBucketExtractLm(kBucket_pt bucket) |
---|
| 217 | { |
---|
| 218 | poly lm = kBucketGetLm(bucket); |
---|
[42ddd0] | 219 | #ifdef HAVE_COEF_BUCKETS |
---|
[473b74] | 220 | assume(bucket->coef[0]==NULL); |
---|
[42ddd0] | 221 | #endif |
---|
[35aab3] | 222 | bucket->buckets[0] = NULL; |
---|
| 223 | bucket->buckets_length[0] = 0; |
---|
[473b74] | 224 | |
---|
[35aab3] | 225 | return lm; |
---|
| 226 | } |
---|
[39e957] | 227 | |
---|
| 228 | poly kBucketExtractLmOfBucket(kBucket_pt bucket, int i); |
---|
[473b74] | 229 | void kBucketSimpleContent(kBucket_pt bucket); |
---|
[86e6577] | 230 | BOOLEAN kBucketIsCleared(kBucket_pt bucket); |
---|
[0ebd7e] | 231 | int ksCheckCoeff(number *a, number *b, const coeffs r); |
---|
[35aab3] | 232 | #endif /* KBUCKETS_H */ |
---|