source: git/libpolys/polys/kbuckets.h @ aec5c9

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