source: git/polys/templates/p_kBucketSetLm__T.cc @ 879cc3c

spielwiese
Last change on this file since 879cc3c was 879cc3c, checked in by Mohamed Barakat <mohamed.barakat@…>, 14 years ago
monmials: . data structures, allocation/deallocation, comparing monomials tests for monomials, Setm, Degree operations: . operations on polynomials as lists (e.g. length, Maps, Sort, ...) templates: . templates for inline procedures and code to generate them ext_fields: . quotient fields of polynomial rings and algebraic extensions
  • Property mode set to 100644
File size: 5.0 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 *  Version: $Id$
10 *******************************************************************/
11#undef USE_COEF_BUCKETS
12#ifdef HAVE_COEF_BUCKETS
13#define USE_COEF_BUCKETS
14#endif
15
16#ifdef USE_COEF_BUCKETS
17#define MULTIPLY_BUCKET(B,I) do                                        \
18  { if (B->coef[I]!=NULL)                                              \
19    {                                                                  \
20      B->buckets[I]=p_Mult_q(B->buckets[I],B->coef[I],B->bucket_ring); \
21      B->coef[I]=NULL;                                                 \
22    }                                                                  \
23  } while(0)
24#else
25#define MULTIPLY_BUCKET(B,I)
26#endif
27#ifndef USE_COEF_BUCKETS
28LINKAGE void p_kBucketSetLm(kBucket_pt bucket)
29{
30  int j = 0;
31  poly lt;
32  ring r = bucket->bucket_ring;
33  assume(bucket->buckets[0] == NULL && bucket->buckets_length[0] == 0);
34  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
35  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
36  poly p;
37
38  do
39  {
40    j = 0;
41    for (int i = 1; i<=bucket->buckets_used; i++)
42    {
43      if (bucket->buckets[i] != NULL)
44      {
45        MULTIPLY_BUCKET(bucket,i);
46        p =  bucket->buckets[j];
47        if (j == 0)
48        {
49          if (p != NULL) goto Greater;
50          j = i;
51          goto Continue;
52        }
53        assume(p != NULL);
54        p_MemCmp(bucket->buckets[i]->exp, p->exp, length, ordsgn, goto Equal, goto Greater, goto Continue);
55
56        Greater:
57        {
58          if (n_IsZero(pGetCoeff(p), r))
59          {
60            n_Delete(&pGetCoeff(p), r);
61            pIter(bucket->buckets[j]);
62            p_FreeBinAddr(p, r);
63            (bucket->buckets_length[j])--;
64          }
65          j = i;
66          goto Continue;
67        }
68
69        Equal:
70        {
71          MULTIPLY_BUCKET(bucket,i);
72          number tn = pGetCoeff(p);
73          #if 0
74          pSetCoeff0(p, n_Add(pGetCoeff(bucket->buckets[i]), tn, r));
75          n_Delete(&tn, r);
76          #else
77          pSetCoeff0(p, n_InpAdd(tn,pGetCoeff(bucket->buckets[i]), r));
78          #endif
79          p = bucket->buckets[i];
80          pIter(bucket->buckets[i]);
81          n_Delete(&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(pGetCoeff(p), r))
91    {
92      n_Delete(&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(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(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.