My Project
Loading...
Searching...
No Matches
p_kBucketSetLm__T.cc
Go to the documentation of this file.
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
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->cf))
58 {
59 n_Delete__T(&pGetCoeff(p), r->cf);
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->cf));
74 n_Delete__T(&tn, r->cf);
75 #else
76 n_InpAdd__T(tn,pGetCoeff(bucket->buckets[i]), r->cf);
77 pSetCoeff0(p, tn);
78 #endif
79 p = bucket->buckets[i];
80 pIter(bucket->buckets[i]);
81 n_Delete__T(&pGetCoeff(p), r->cf);
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->cf))
91 {
92 n_Delete__T(&pGetCoeff(p), r->cf);
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
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
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
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
bool found
Definition: facFactorize.cc:55
CFArray copy(const CFList &list)
write elements of list into an array
int j
Definition: facHensel.cc:110
static BOOLEAN Equal(number a, number b, const coeffs)
Definition: flintcf_Q.cc:324
static bool Greater(mono_type m1, mono_type m2)
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:257
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:197
poly kBucketExtractLmOfBucket(kBucket_pt bucket, int i)
Definition: kbuckets.cc:1455
ring bucket_ring
Definition: kbuckets.h:196
#define assume(x)
Definition: mod2.h:389
#define LINKAGE
Definition: mod2.h:140
#define p_FreeBinAddr(p, r)
Definition: monomials.h:255
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
#define pSetCoeff0(p, n)
Definition: monomials.h:59
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define NULL
Definition: omList.c:12
LINKAGE void p_kBucketSetLm__T(kBucket_pt bucket)
#define MULTIPLY_BUCKET(B, I)
#define n_Delete__T(n, r)
Definition: p_polys.cc:4841
static int pLength(poly a)
Definition: p_polys.h:188
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:934
static poly p_LmInit(poly p, const ring r)
Definition: p_polys.h:1333
#define p_LmEqual(p1, p2, r)
Definition: p_polys.h:1721
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:899
#define p_Test(p, r)
Definition: p_polys.h:159