source: git/Singular/kbuckets.h @ 50cbdc

spielwiese
Last change on this file since 50cbdc was 2f436b, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* version 1-3-13: sparsemat improivements git-svn-id: file:///usr/local/Singular/svn/trunk@5003 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.7 KB
Line 
1#ifndef KBUCKETS_H
2#define KBUCKETS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: kbuckets.h,v 1.14 2000-12-31 15:14:32 obachman Exp $ */
7#include "structs.h"
8#include "p_Procs.h"
9#include "pShallowCopyDelete.h"
10
11/////////////////////////////////////////////////////////////////////////
12// configuration
13//
14
15// define to not really use the bucket feature
16// #define HAVE_PSEUDO_BUCKETS
17
18//////////////////////////////////////////////////////////////////////////
19// Creation/Destruction of buckets
20//
21kBucket_pt kBucketCreate(ring r = currRing);
22// only free memory allocated for bucket
23void kBucketDestroy(kBucket_pt *bucket);
24// frees polys/monomials in bucket and destroys bucket
25void kBucketDeleteAndDestroy(kBucket_pt *bucket);
26
27
28/////////////////////////////////////////////////////////////////////////////
29// Convertion from/to Bpolys
30//
31
32// Converts p into a bucket poly (Bpoly) and destroys p
33// Assumes length <= 0 || pLength(p) == length
34void kBucketInit(kBucket_pt bucket, poly p, int length);
35
36// Converts Bpoly into a poly and clears bucket
37// i.e., afterwards Bpoly == 0
38void kBucketClear(kBucket_pt bucket, poly *p, int *length);
39inline poly kBucketClear(kBucket_pt bucket)
40{
41  int dummy;
42  poly p;
43  kBucketClear(bucket, &p, &dummy);
44  return p;
45}
46
47// Canonicalizes Bpoly, i.e. converts polys of buckets into one poly in
48// one bucket: Returns number of bucket into which it is canonicalized
49int kBucketCanonicalize(kBucket_pt bucket);
50
51/////////////////////////////////////////////////////////////////////////////
52// Gets leading monom of bucket, does NOT change Bpoly!!!!!
53// Returned monom is READ ONLY, i.e. no manipulations are allowed !!!!
54//
55inline const poly kBucketGetLm(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// Reduces Bpoly (say, q) with p, i.e.:
72// q = (Lc(p) / gcd(Lc(p), Lc(q)))*q - (Lc(q)/gcd(Lc(p),Lc(q)))*p*(Lm(q)/Lm(p))
73// Assumes p1 != NULL, Bpoly != NULL
74//         Lm(p1) divides Lm(Bpoly)
75//         pLength(p1) == l1
76// Returns: Lc(p) / gcd(Lc(p), Lc(q))
77number kBucketPolyRed(kBucket_pt bucket,
78                      poly p, int l,
79                      poly spNoether);
80
81
82/////////////////////////////////////////////////////////////////////////////
83//
84// Extract all monomials from bucket with component comp
85// Return as a polynomial *p with length *l
86// In other words, afterwards
87// Bpoly == Bpoly - (poly consisting of all monomials with component comp)
88// and components of monomials of *p are all 0
89
90void kBucketTakeOutComp(kBucket_pt bucket,
91                        Exponent_t comp,
92                        poly *p, int *l);
93
94// Here we only extract such monoms which have component == comp and
95// degree == order
96// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
97//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
98void kBucketDecrOrdTakeOutComp(kBucket_pt bucket,
99                               Exponent_t comp, Order_t order,
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  int  buckets_length[MAX_BUCKET + 1]; // length if i-th poly
189  int buckets_used;                    // max number of used bucket
190#endif
191  ring bucket_ring;
192};
193
194inline void kBucketAdjustBucketsUsed(kBucket_pt bucket)
195{
196  while ( bucket->buckets_used > 0 &&
197          bucket->buckets[bucket->buckets_used] == NULL)
198    (bucket->buckets_used)--;
199}
200
201inline const poly kBucketGetLm(kBucket_pt bucket)
202{
203  if (bucket->buckets[0] == NULL)
204    bucket->bucket_ring->p_Procs->p_kBucketSetLm(bucket);
205  return bucket->buckets[0];
206}
207
208inline poly kBucketExtractLm(kBucket_pt bucket)
209{
210  poly lm = kBucketGetLm(bucket);
211  bucket->buckets[0] = NULL;
212  bucket->buckets_length[0] = 0;
213  return lm;
214}
215
216#endif /* KBUCKETS_H */
Note: See TracBrowser for help on using the repository browser.