source: git/libpolys/polys/kbuckets.h @ 78eba1

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