source: git/libpolys/polys/templates/p_kBucketSetLm__T.cc @ 6909cfb

spielwiese
Last change on this file since 6909cfb was f224d85, checked in by Hans Schoenemann <hannes@…>, 12 years ago
fix: removing last from p_*templates and k* routines
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    p_KBucketSetLm__Template.cc
6 *  Purpose: template for setting the Lm of a bucket
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 12/00
9 *******************************************************************/
10#undef USE_COEF_BUCKETS
11#ifdef HAVE_COEF_BUCKETS
12#define USE_COEF_BUCKETS
13#endif
14
15#ifdef USE_COEF_BUCKETS
16#define MULTIPLY_BUCKET(B,I) do                                        \
17  { if (B->coef[I]!=NULL)                                              \
18    {                                                                  \
19      B->buckets[I]=p_Mult_q(B->buckets[I],B->coef[I],B->bucket_ring); \
20      B->coef[I]=NULL;                                                 \
21    }                                                                  \
22  } while(0)
23#else
24#define MULTIPLY_BUCKET(B,I)
25#endif
26#ifndef USE_COEF_BUCKETS
27LINKAGE void p_kBucketSetLm__T(kBucket_pt bucket)
28{
29  int j = 0;
30  poly lt;
31  ring r = bucket->bucket_ring;
32  assume(bucket->buckets[0] == NULL && bucket->buckets_length[0] == 0);
33  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
34  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
35  poly p;
36
37  do
38  {
39    j = 0;
40    for (int i = 1; i<=bucket->buckets_used; i++)
41    {
42      if (bucket->buckets[i] != NULL)
43      {
44        MULTIPLY_BUCKET(bucket,i);
45        p =  bucket->buckets[j];
46        if (j == 0)
47        {
48          if (p != NULL) goto Greater;
49          j = i;
50          goto Continue;
51        }
52        assume(p != NULL);
53        p_MemCmp__T(bucket->buckets[i]->exp, p->exp, length, ordsgn, goto Equal, goto Greater, goto Continue);
54
55        Greater:
56        {
57          if (n_IsZero__T(pGetCoeff(p), r))
58          {
59            n_Delete__T(&pGetCoeff(p), r);
60            pIter(bucket->buckets[j]);
61            p_FreeBinAddr(p, r);
62            (bucket->buckets_length[j])--;
63          }
64          j = i;
65          goto Continue;
66        }
67
68        Equal:
69        {
70          MULTIPLY_BUCKET(bucket,i);
71          number tn = pGetCoeff(p);
72          #if 0
73          pSetCoeff0(p, n_Add__T(pGetCoeff(bucket->buckets[i]), tn, r));
74          n_Delete__T(&tn, r);
75          #else
76          n_InpAdd__T(tn,pGetCoeff(bucket->buckets[i]), r);
77          pSetCoeff0(p, tn);
78          #endif
79          p = bucket->buckets[i];
80          pIter(bucket->buckets[i]);
81          n_Delete__T(&pGetCoeff(p), r);
82          p_FreeBinAddr(p, r);
83          (bucket->buckets_length[i])--;
84        }
85
86        Continue:;
87      }
88    }
89    p = bucket->buckets[j];
90    if (j > 0 && n_IsZero__T(pGetCoeff(p), r))
91    {
92      n_Delete__T(&pGetCoeff(p), r);
93      pIter(bucket->buckets[j]);
94      p_FreeBinAddr(p, r);
95      (bucket->buckets_length[j])--;
96      j = -1;
97    }
98  }
99  while (j < 0);
100
101  if (j == 0)
102  {
103    return;
104  }
105
106  assume(bucket->buckets[j] != NULL);
107  lt = bucket->buckets[j];
108  bucket->buckets[j] = pNext(lt);
109  bucket->buckets_length[j]--;
110  pNext(lt) = NULL;
111  bucket->buckets[0] = lt;
112  bucket->buckets_length[0] = 1;
113
114  kBucketAdjustBucketsUsed(bucket);
115}
116#else
117LINKAGE void p_kBucketSetLm__T(kBucket_pt bucket)
118{
119  //int j = 0;
120  poly lt;
121  ring r = bucket->bucket_ring;
122  assume((bucket->buckets[0] == NULL) && (bucket->buckets_length[0] == 0) && (bucket->coef[0]==0));
123  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
124  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
125  poly p=NULL;
126  while(p==NULL)
127  {
128    int found=-1000;
129    for (int i = 1; i<=bucket->buckets_used; i++)
130    {
131      if (bucket->buckets[i] != NULL)
132      {
133        if (p == NULL)
134        {
135          p=bucket->buckets[i];
136          found=i;
137          continue;
138        }
139        assume(p != NULL);
140        p_MemCmp__T(bucket->buckets[i]->exp, p->exp, length, ordsgn, goto Continue, goto Greater, goto Continue);
141        //assume(p_LmCmp(bucket->buckets[i],p,r)==1);
142        Greater:
143        //if (p_LmCmp(bucket->buckets[i],p,r)!=1) continue;
144        found=i;
145        p=bucket->buckets[i];
146        Continue:;
147      }
148    }
149    if (found<0) return;
150    assume(p==bucket->buckets[found]);
151    assume(p!=NULL);
152
153    p=kBucketExtractLmOfBucket(bucket, found);
154    assume(p!=NULL);
155    p_Test(p,r);
156    poly copy=p_LmInit(p, r);
157
158    for (int i = found+1; i<=bucket->buckets_used; i++)
159    {
160      if (bucket->buckets[i] != NULL)
161      {
162        if(p_LmEqual(bucket->buckets[i], copy,r))
163        {
164          poly q=kBucketExtractLmOfBucket(bucket,i);
165          assume(p!=q);
166          p=p_Add_q(p, q,r);
167          assume(pLength(bucket->buckets[i])==bucket->buckets_length[i]);
168        }
169      }
170    }
171    p_Delete(&copy, r);
172  }
173
174  //assume(bucket->buckets[j] != NULL);
175  assume(pLength(lt)==1);
176
177  bucket->buckets[0] = lt;
178  bucket->buckets_length[0] = 1;
179
180  kBucketAdjustBucketsUsed(bucket);
181  kbTest(bucket);
182}
183#endif
Note: See TracBrowser for help on using the repository browser.