1 | #ifndef KBUCKETS_H |
---|
2 | #define KBUCKETS_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: kbuckets.h,v 1.3 1999-05-26 16:20:18 obachman Exp $ */ |
---|
7 | #include "mod2.h" |
---|
8 | #include "mmheap.h" |
---|
9 | #include "kbPolyProcs.h" |
---|
10 | |
---|
11 | ///////////////////////////////////////////////////////////////////////// |
---|
12 | // configuration |
---|
13 | // |
---|
14 | |
---|
15 | // define to enable buckets |
---|
16 | #define HAVE_BUCKETS |
---|
17 | |
---|
18 | // define to not really use the bucket feature |
---|
19 | // #define HAVE_PSEUDO_BUCKETS |
---|
20 | |
---|
21 | #ifdef HAVE_BUCKETS |
---|
22 | ////////////////////////////////////////////////////////////////////////// |
---|
23 | // Creation/Destruction of buckets |
---|
24 | // |
---|
25 | kBucket_pt kBucketCreate(); |
---|
26 | void kBucketDestroy(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 | // Monoms of p are from heap |
---|
36 | // Uses heap for intermediate monom allocations |
---|
37 | // pprocs for polynomial operations |
---|
38 | void kBucketInit(kBucket_pt bucket, poly p, int length, kbPolyProcs_pt pprocs, |
---|
39 | memHeap heap = NULL); |
---|
40 | |
---|
41 | // Converts Bpoly into a poly and clears bucket |
---|
42 | // i.e., afterwards Bpoly == 0 |
---|
43 | void kBucketClear(kBucket_pt bucket, poly *p, int *length); |
---|
44 | |
---|
45 | |
---|
46 | ///////////////////////////////////////////////////////////////////////////// |
---|
47 | // Gets leading monom of bucket, does NOT change Bpoly!!!!! |
---|
48 | // Returned monom is READ ONLY, i.e. no manipulations are allowed !!!! |
---|
49 | // |
---|
50 | const poly kBucketGetLm(kBucket_pt bucket); |
---|
51 | |
---|
52 | ///////////////////////////////////////////////////////////////////////////// |
---|
53 | // Extracts lm of Bpoly, i.e. Bpoly is changed s.t. |
---|
54 | // Bpoly == Bpoly - Lm(Bpoly) |
---|
55 | // |
---|
56 | poly kBucketExtractLm(kBucket_pt bucket); |
---|
57 | |
---|
58 | ///////////////////////////////////////////////////////////////////////////// |
---|
59 | // Reduces Bpoly (say, q) with p, i.e.: |
---|
60 | // q = (Lc(p) / gcd(Lc(p), Lc(q)))*q - (Lc(q)/gcd(Lc(p),Lc(q)))*p*(Lm(q)/Lm(p)) |
---|
61 | // Assumes p1 != NULL, Bpoly != NULL |
---|
62 | // Lm(p1) divides Lm(Bpoly) |
---|
63 | // pLength(p1) == l1 |
---|
64 | // Returns: Lc(p) / gcd(Lc(p), Lc(q)) |
---|
65 | number kBucketPolyRed(kBucket_pt bucket, |
---|
66 | poly p, int l, |
---|
67 | poly spNoether); |
---|
68 | |
---|
69 | |
---|
70 | ///////////////////////////////////////////////////////////////////////////// |
---|
71 | // |
---|
72 | // Extract all monomials from bucket with component comp |
---|
73 | // Return as a polynomial *p with length *l |
---|
74 | // In other words, afterwards |
---|
75 | // Bpoly == Bpoly - (poly consisting of all monomials with component comp) |
---|
76 | // and components of monomials of *p are all 0 |
---|
77 | |
---|
78 | void kBucketTakeOutComp(kBucket_pt bucket, |
---|
79 | Exponent_t comp, |
---|
80 | poly *p, int *l); |
---|
81 | |
---|
82 | // Here we only extract such monoms which have component == comp and |
---|
83 | // degree == order |
---|
84 | // ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then |
---|
85 | // m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2) |
---|
86 | void kBucketDecrOrdTakeOutComp(kBucket_pt bucket, |
---|
87 | Exponent_t comp, Order_t order, |
---|
88 | poly *p, int *l); |
---|
89 | |
---|
90 | ////////////////////////////////////////////////////////////////////////// |
---|
91 | /// |
---|
92 | /// Multiply Bucket by number ,i.e. Bpoly == n*Bpoly |
---|
93 | /// |
---|
94 | void kBucket_Mult_n(kBucket_pt bucket, number n); |
---|
95 | |
---|
96 | |
---|
97 | ////////////////////////////////////////////////////////////////////////// |
---|
98 | /// |
---|
99 | /// Bpoly == Bpoly - m*p; where m is a monom |
---|
100 | /// Does not destroy p and m |
---|
101 | /// assume (*l <= 0 || pLength(p) == *l) |
---|
102 | void kBucket_Minus_m_Mult_p(kBucket_pt bucket, poly m, poly p, int *l, |
---|
103 | poly spNother = NULL); |
---|
104 | |
---|
105 | |
---|
106 | ////////////////////////////////////////////////////////////////////////// |
---|
107 | /// |
---|
108 | /// Bucket definition (should be no one elses business, though) |
---|
109 | /// |
---|
110 | |
---|
111 | |
---|
112 | #define MAX_BUCKET 14 // suitable for polys up to a length of 4^14 = 2^28 |
---|
113 | class kBucket |
---|
114 | { |
---|
115 | public: |
---|
116 | #ifdef HAVE_PSEUDO_BUCKETS |
---|
117 | poly p; |
---|
118 | int l; |
---|
119 | #else |
---|
120 | poly buckets[MAX_BUCKET + 1]; // polys in bucket |
---|
121 | int buckets_length[MAX_BUCKET + 1]; // length if i-th poly |
---|
122 | int buckets_used; // max number of used bucket |
---|
123 | #endif |
---|
124 | kbPolyProcs_pt pprocs; // procs for poly arithmetic |
---|
125 | memHeap heap; // used heap |
---|
126 | }; |
---|
127 | |
---|
128 | /*************************************************************** |
---|
129 | * |
---|
130 | * Memory Management |
---|
131 | * |
---|
132 | * |
---|
133 | ***************************************************************/ |
---|
134 | #define kb_pNew(p, heap) AllocHeap(p, mm_specHeap) |
---|
135 | #define kb_pFree1(p, heap) FreeHeap(p, mm_specHeap) |
---|
136 | |
---|
137 | #define kb_pFree1AndAdvance(p, heap) \ |
---|
138 | do \ |
---|
139 | { \ |
---|
140 | poly __p = p; \ |
---|
141 | p = pNext(__p); \ |
---|
142 | kb_pFree1(__p, heap); \ |
---|
143 | } \ |
---|
144 | while(0) |
---|
145 | |
---|
146 | #define kb_pDelete1AndAdvance(p,heap) \ |
---|
147 | do \ |
---|
148 | { \ |
---|
149 | nDelete(&(pGetCoeff(p))); \ |
---|
150 | kb_pFree1AndAdvance(p,heap); \ |
---|
151 | } \ |
---|
152 | while (0) |
---|
153 | |
---|
154 | #define kb_pDelete1(p, heap) \ |
---|
155 | do \ |
---|
156 | { \ |
---|
157 | nDelete(&(pGetCoeff(p))); \ |
---|
158 | kb_pFree1(p, heap); \ |
---|
159 | } \ |
---|
160 | while (0) |
---|
161 | |
---|
162 | |
---|
163 | #endif /* HAVE_BUCKETS */ |
---|
164 | |
---|
165 | #endif /* KBUCKETS_H */ |
---|