source: git/kernel/p_kBucketSetLm__T.cc @ 57bfa2

spielwiese
Last change on this file since 57bfa2 was 18057e, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: nlInpAdd etc. git-svn-id: file:///usr/local/Singular/svn/trunk@10961 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • 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 *  Version: $Id: p_kBucketSetLm__T.cc,v 1.5 2008-08-07 15:08:22 Singular Exp $
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  BOOLEAN zero = FALSE;
33  ring r = bucket->bucket_ring;
34  assume(bucket->buckets[0] == NULL && bucket->buckets_length[0] == 0);
35  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
36  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
37  poly p;
38
39  do
40  {
41    j = 0;
42    for (int i = 1; i<=bucket->buckets_used; i++)
43    {
44      if (bucket->buckets[i] != NULL)
45      {
46        MULTIPLY_BUCKET(bucket,i);
47        p =  bucket->buckets[j];
48        if (j == 0)
49        {
50          if (p != NULL) goto Greater;
51          j = i;
52          goto Continue;
53        }
54        assume(p != NULL);
55        p_MemCmp(bucket->buckets[i]->exp, p->exp, length, ordsgn, goto Equal, goto Greater, goto Continue);
56
57        Greater:
58        {
59          if (n_IsZero(pGetCoeff(p), r))
60          {
61            n_Delete(&pGetCoeff(p), r);
62            pIter(bucket->buckets[j]);
63            p_FreeBinAddr(p, r);
64            (bucket->buckets_length[j])--;
65          }
66          j = i;
67          goto Continue;
68        }
69
70        Equal:
71        {
72          MULTIPLY_BUCKET(bucket,i);
73          number tn = pGetCoeff(p);
74          #if 0
75          pSetCoeff0(p, n_Add(pGetCoeff(bucket->buckets[i]), tn, r));
76          n_Delete(&tn, r);
77          #else
78          pSetCoeff0(p, n_InpAdd(tn,pGetCoeff(bucket->buckets[i]), r));
79          #endif
80          p = bucket->buckets[i];
81          pIter(bucket->buckets[i]);
82          n_Delete(&pGetCoeff(p), r);
83          p_FreeBinAddr(p, r);
84          (bucket->buckets_length[i])--;
85        }
86
87        Continue:;
88      }
89    }
90    p = bucket->buckets[j];
91    if (j > 0 && n_IsZero(pGetCoeff(p), r))
92    {
93      n_Delete(&pGetCoeff(p), r);
94      pIter(bucket->buckets[j]);
95      p_FreeBinAddr(p, r);
96      (bucket->buckets_length[j])--;
97      j = -1;
98    }
99  }
100  while (j < 0);
101
102  if (j == 0)
103  {
104    return;
105  }
106
107  assume(bucket->buckets[j] != NULL);
108  lt = bucket->buckets[j];
109  bucket->buckets[j] = pNext(lt);
110  bucket->buckets_length[j]--;
111  pNext(lt) = NULL;
112  bucket->buckets[0] = lt;
113  bucket->buckets_length[0] = 1;
114
115  kBucketAdjustBucketsUsed(bucket);
116}
117#else
118LINKAGE void p_kBucketSetLm(kBucket_pt bucket)
119{
120  //int j = 0;
121  poly lt;
122  BOOLEAN zero = FALSE;
123  ring r = bucket->bucket_ring;
124  assume((bucket->buckets[0] == NULL) && (bucket->buckets_length[0] == 0) && (bucket->coef[0]==0));
125  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
126  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
127  poly p=NULL;
128  while(p==NULL){
129      int found=-1000;
130       for (int i = 1; i<=bucket->buckets_used; i++)
131        {
132          if (bucket->buckets[i] != NULL)
133          {
134           
135            if (p == NULL)
136            {
137                p=bucket->buckets[i];
138                found=i;
139                continue;
140            }
141            assume(p != NULL);
142            p_MemCmp(bucket->buckets[i]->exp, p->exp, length, ordsgn, goto Continue, goto Greater, goto Continue);
143            //assume(p_LmCmp(bucket->buckets[i],p,r)==1);
144          Greater:
145            //if (p_LmCmp(bucket->buckets[i],p,r)!=1) continue;
146            found=i;
147            p=bucket->buckets[i];
148          Continue:;
149          }
150        }
151     
152     
153      if (found<0) return;
154      assume(p==bucket->buckets[found]);
155      assume(p!=NULL);
156     
157      p=kBucketExtractLmOfBucket(bucket, found);
158      assume(p!=NULL);
159      p_Test(p,r);
160      poly copy=p_LmInit(p, r);
161     
162      for (int i = found+1; i<=bucket->buckets_used; i++)
163        {
164         
165          if (bucket->buckets[i] != NULL)
166          {
167            if(p_LmEqual(bucket->buckets[i], copy,r)){
168                poly q=kBucketExtractLmOfBucket(bucket,i);
169                assume(p!=q);
170                p=p_Add_q(p, q,r);
171                assume(pLength(bucket->buckets[i])==bucket->buckets_length[i]);
172            }
173           
174   
175           
176          }
177        }
178        p_Delete(&copy, r);
179  }
180 
181  //assume(bucket->buckets[j] != NULL);
182  assume(pLength(p)==1);
183  lt = p;
184 
185  bucket->buckets[0] = lt;
186  bucket->buckets_length[0] = 1;
187
188  kBucketAdjustBucketsUsed(bucket);
189  kbTest(bucket);
190  }
191#endif
Note: See TracBrowser for help on using the repository browser.