source: git/libpolys/polys/templates/p_kBucketSetLm__T.cc @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 5.1 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      int found=-1000;
128       for (int i = 1; i<=bucket->buckets_used; i++)
129        {
130          if (bucket->buckets[i] != NULL)
131          {
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     
150     
151      if (found<0) return;
152      assume(p==bucket->buckets[found]);
153      assume(p!=NULL);
154     
155      p=kBucketExtractLmOfBucket(bucket, found);
156      assume(p!=NULL);
157      p_Test(p,r);
158      poly copy=p_LmInit(p, r);
159     
160      for (int i = found+1; i<=bucket->buckets_used; i++)
161        {
162         
163          if (bucket->buckets[i] != NULL)
164          {
165            if(p_LmEqual(bucket->buckets[i], copy,r)){
166                poly q=kBucketExtractLmOfBucket(bucket,i);
167                assume(p!=q);
168                p=p_Add_q(p, q,r);
169                assume(pLength(bucket->buckets[i])==bucket->buckets_length[i]);
170            }
171           
172   
173           
174          }
175        }
176        p_Delete(&copy, r);
177  }
178 
179  //assume(bucket->buckets[j] != NULL);
180  assume(pLength(p)==1);
181  lt = p;
182 
183  bucket->buckets[0] = lt;
184  bucket->buckets_length[0] = 1;
185
186  kBucketAdjustBucketsUsed(bucket);
187  kbTest(bucket);
188  }
189#endif
Note: See TracBrowser for help on using the repository browser.