source: git/kernel/kbuckets.h @ 788529d

spielwiese
Last change on this file since 788529d was 35aab3, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6879, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6880 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.9 KB
Line 
1#ifndef KBUCKETS_H
2#define KBUCKETS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: kbuckets.h,v 1.1.1.1 2003-10-06 12:15:56 Singular Exp $ */
7#include "structs.h"
8#include "p_Procs.h"
9#include "pShallowCopyDelete.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 = currRing);
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// 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                        Exponent_t comp,
94                        poly *p, int *l);
95
96// Here we only extract such monoms which have component == comp and
97// degree == order
98// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
99//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
100void kBucketDecrOrdTakeOutComp(kBucket_pt bucket,
101                               Exponent_t comp, Order_t order,
102                               poly *p, int *l);
103
104//////////////////////////////////////////////////////////////////////////
105///
106/// Multiply Bucket by number ,i.e. Bpoly == n*Bpoly
107///
108void kBucket_Mult_n(kBucket_pt bucket, number n);
109
110//////////////////////////////////////////////////////////////////////////
111///
112/// Extract all monomials of bucket which are larger than q
113/// Append those to append, and return last monomial of append
114poly kBucket_ExtractLarger(kBucket_pt bucket, poly q, poly append);
115
116
117//////////////////////////////////////////////////////////////////////////
118///
119/// Add to Bucket a poly ,i.e. Bpoly == Bpoly + q
120///
121void kBucket_Add_q(kBucket_pt bucket, poly q, int* lq);
122
123// first, do ExtractLarger
124// then add q
125inline poly
126kBucket_ExtractLarger_Add_q(kBucket_pt bucket, poly append, poly q, int *lq)
127{
128  append = kBucket_ExtractLarger(bucket, q, append);
129  kBucket_Add_q(bucket, q, lq);
130  return append;
131}
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_Minus_m_Mult_p(kBucket_pt bucket, poly m, poly p, int *l,
139                            poly spNother = NULL);
140
141//////////////////////////////////////////////////////////////////////////
142///
143/// Bpoly == Bpoly + m*p; where m is a monom
144/// Does not destroy p and m
145/// assume (l <= 0 || pLength(p) == l)
146void kBucket_Plus_mm_Mult_pp(kBucket_pt bucket, poly m, poly p, int l);
147
148//////////////////////////////////////////////////////////////////////////
149///
150/// For changing the ring of the Bpoly to new_tailBin
151///
152void kBucketShallowCopyDelete(kBucket_pt bucket,
153                              ring new_tailRing, omBin new_tailBin,
154                              pShallowCopyDeleteProc p_shallow_copy_delete);
155
156//////////////////////////////////////////////////////////////////////////
157///
158/// Tests
159///
160///
161#ifdef KDEBUG
162BOOLEAN kbTest(kBucket_pt bucket);
163#else
164#define kbTest(bucket)  ((void)0)
165#endif
166
167//////////////////////////////////////////////////////////////////////////
168///
169/// Bucket definition (should be no one elses business, though)
170///
171
172// define this if length of bucket polys are 2, 4, 8, etc
173// instead of 4, 16, 64 ... --
174// this seems to be less efficient, both, in theory and in practice
175// #define BUCKET_TWO_BASE
176#ifdef BUCKET_TWO_BASE
177#define MAX_BUCKET 28
178#else
179#define MAX_BUCKET 14 // suitable for polys up to a length of 4^14 = 2^28
180#endif
181
182class kBucket
183{
184public:
185#ifdef HAVE_PSEUDO_BUCKETS
186  poly p;
187  int l;
188#else
189  poly buckets[MAX_BUCKET + 1];        // polys in bucket
190#ifdef HAVE_COEF_BUCKETS
191  poly coef[MAX_BUCKET + 1];        // coeff of polys in bucket or NULL : 2..max
192#endif
193  int  buckets_length[MAX_BUCKET + 1]; // length if i-th poly
194  int buckets_used;                    // max number of used bucket
195#endif
196  ring bucket_ring;
197};
198
199inline void kBucketAdjustBucketsUsed(kBucket_pt bucket)
200{
201  while ( bucket->buckets_used > 0 &&
202          bucket->buckets[bucket->buckets_used] == NULL)
203    (bucket->buckets_used)--;
204}
205
206inline const poly kBucketGetLm(kBucket_pt bucket)
207{
208  if (bucket->buckets[0] == NULL)
209    bucket->bucket_ring->p_Procs->p_kBucketSetLm(bucket);
210  return bucket->buckets[0];
211}
212
213inline poly kBucketExtractLm(kBucket_pt bucket)
214{
215  poly lm = kBucketGetLm(bucket);
216  bucket->buckets[0] = NULL;
217  bucket->buckets_length[0] = 0;
218  return lm;
219}
220
221#endif /* KBUCKETS_H */
Note: See TracBrowser for help on using the repository browser.