source: git/libpolys/polys/kbuckets.h @ 83f55f

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