source: git/libpolys/polys/kbuckets.h @ 164e05

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