My Project
Loading...
Searching...
No Matches
kLiftstd.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT - Kernel: alg. of Buchberger
6*/
7
8#include "kernel/mod2.h"
9
10// define if no buckets should be used
11// #define NO_BUCKETS
12
13#include "omalloc/omalloc.h"
15#include "misc/options.h"
16#include "kernel/polys.h"
17#include "kernel/ideals.h"
20#include "polys/kbuckets.h"
21#include "polys/prCopy.h"
22#include "polys/weight.h"
23#include "misc/intvec.h"
24#ifdef HAVE_PLURAL
25#include "polys/nc/nc.h"
26#endif
27
28static poly kSplitAt(int k,TObject* h,kStrategy strat)
29{
30 poly p;
31 if (h->t_p==NULL)
32 {
33 if (currRing!=strat->tailRing)
34 {
36 p=h->t_p;
37 }
38 else
39 p=h->p;
40 }
41 else
42 p=h->t_p;
43 if (p->next==NULL) return NULL;
44 const ring tailRing=strat->tailRing;
45 while(p_GetComp(p->next,tailRing)<=k)
46 {
47 pIter(p);
48 if ((p==NULL)||(p->next==NULL))
49 {
50 h->pLength=0; // force re-computation
51 return NULL;
52 }
53 }
54 poly t=p->next;
55 p->next=NULL;
56 h->pLength=0; // force re-computation
57 if ((h->p!=NULL) && (h->t_p!=NULL)
58 && (pNext(h->p)!=pNext(h->t_p)))
59 {
60 pNext(h->p)=pNext(h->t_p);
61 }
62 return t;
63}
64static poly kSplitAt(int k,LObject* h,kStrategy strat)
65{
66 poly p,pr,t=NULL;
67 int l;
68 if (h->bucket!=NULL)
69 {
70 kBucketClear(h->bucket,&p,&l);
71 pr=p;
72 }
73 else
74 {
75 if (h->t_p==NULL)
76 {
77 if (currRing!=strat->tailRing)
78 {
80 p=h->t_p;
81 }
82 else
83 p=h->p;
84 }
85 else
86 p=h->t_p;
87 }
88 const ring tailRing=strat->tailRing;
89 if(p==NULL) return NULL;
90 if (p_GetComp(p,tailRing)>k)
91 {
92 return p;
93 }
94 if (p->next==NULL)
95 {
96 goto finish;
97 }
98 while(p_GetComp(p->next,tailRing)<=k)
99 {
100 pIter(p);
101 if (p->next==NULL) break;
102 }
103 t=p->next;
104 p->next=NULL;
105finish:
106 if (h->bucket!=NULL)
107 {
108 l=pLength(pr);
109 kBucketInit(h->bucket,pr,l);
110 }
111 else
112 {
113 if ((h->p!=NULL) && (h->t_p!=NULL))
114 {
115 pNext(h->p)=pNext(h->t_p);
116 }
117 }
118
119 return t;
120}
121static void kAppend(poly t,TObject* h)
122{
123 poly p;
124 if (h->t_p!=NULL)
125 p=h->t_p;
126 else
127 p=h->p;
128 while(p->next!=NULL) pIter(p);
129 p->next=t;
130 if ((h->p!=NULL)&&(h->t_p!=NULL)) pNext(h->p)=pNext(h->t_p);
131}
132static poly lazyComp(number* A, poly* M,poly* T,int index,poly s,int *l,const ring tailR)
133{
134 if ((TEST_OPT_PROT) && (index>0)) { Print("<%d>",index+1); mflush(); }
137 int cnt=RED_CANONICALIZE;
138 for(int i=0;i<index;i++)
139 {
141 n_Delete(&A[i],tailR->cf);
142 poly tt=T[i];
143 if (tt!=NULL)
144 {
145 cnt--;
146 int dummy=pLength(tt);
147 kBucket_Minus_m_Mult_p(b,M[i],tt,&dummy);
148 }
149 p_Delete(&M[i],tailR);
150 if (UNLIKELY(cnt==0))
151 {
154 }
155 }
156 poly p;
157 kBucketClear(b,&p,l);
159 return p;
160}
161
162/*2
163* reduction procedure for the sugar-strategy (honey)
164* reduces h with elements from T choosing first possible
165* element in T with respect to the given ecart
166*/
168{
169 if (strat->tl<0) return 1;
170 assume(h->FDeg == h->pFDeg());
172 poly h_p;
173 int i,j,pass,ei, ii, h_d,ci;
174 unsigned long not_sev;
175 long reddeg,d;
176 #define START_REDUCE 512
177 int red_size=START_REDUCE;
178 number *A=(number*)omAlloc0(red_size*sizeof(number));
179 poly *C=(poly*)omAlloc0(red_size*sizeof(poly));
180 poly *T=(poly*)omAlloc0(red_size*sizeof(poly));
181 const ring tailRing=strat->tailRing;
182
183 pass = j = 0;
184 d = reddeg = h->GetpFDeg() + h->ecart;
185 h->SetShortExpVector();
186 int li;
187 h_p = h->GetLmTailRing();
188 not_sev = ~ h->sev;
189
190 // split h into mina part (h) and tail (h_tail)
191 poly h_tail=kSplitAt(strat->syzComp,h,strat);
192 // fix h-pLength
193 h->pLength=0;
194 h->PrepareRed(strat->use_buckets);
195 loop
196 {
197 j=kFindDivisibleByInT(strat, h);
198 if (j < 0)
199 {
200 // lazy computation:
201 int l;
202 poly p=lazyComp(A,C,T,pass,h_tail,&l,strat->tailRing);
203 kBucket_Add_q(h->bucket,p,&l);
204 omFreeSize(A,red_size*sizeof(number));
205 omFreeSize(T,red_size*sizeof(poly));
206 omFreeSize(C,red_size*sizeof(poly));
207 return 1;
208 }
209
210 ei = strat->T[j].ecart;
211 li = strat->T[j].pLength;
212 ci = nSize(pGetCoeff(strat->T[j].p));
213 ii = j;
214 /*
215 * the polynomial to reduce with (up to the moment) is;
216 * pi with ecart ei (T[ii])
217 */
218 i = j;
219 if (TEST_OPT_LENGTH)
220 {
221 if (li<=0) li=strat->T[j].GetpLength();
222 if (li>1)
223 loop
224 {
225 /*- possible with respect to ecart, minimal nSize -*/
226 i++;
227 if (i > strat->tl)
228 break;
229 //if (ei < h->ecart)
230 // break;
231 if ((((strat->T[i].ecart < ei) && (ei> h->ecart))
232 || ((strat->T[i].ecart <= h->ecart)
233 && (strat->T[i].pLength <= li)
234 && (nSize(pGetCoeff(strat->T[i].p)) <ci)))
235 &&
236 p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
237 h_p, not_sev, tailRing))
238 {
239 /*
240 * the polynomial to reduce with is now;
241 */
242 ei = strat->T[i].ecart;
243 li = strat->T[i].pLength;
244 if (li<=0) li=strat->T[i].GetpLength();
245 ii = i;
246 if (li==1) break;
247 }
248 }
249 }
250
251 /*
252 * end of search: have to reduce with pi
253 */
254#ifdef KDEBUG
255 if (TEST_OPT_DEBUG)
256 {
257 PrintS("red:");
258 h->wrp();
259 Print("\nwith T[%d]:",ii);
260 strat->T[ii].wrp();
261 }
262#endif
263 assume(strat->fromT == FALSE);
264
265 //strat->T[ii].pCleardenom();
266 // split T[ii]:
267 // remember pLength of strat->T[ii]
268 int l_orig=strat->T[ii].pLength;
269 // split strat->T[ii]
270 poly T_tail=kSplitAt(strat->syzComp,&strat->T[ii],strat);
271 h->pLength=0; // force re-computation of length
272 ksReducePoly(h,&(strat->T[ii]),NULL,&A[pass],&C[pass], strat);
273 // restore T[ii]:
274 kAppend(T_tail,&strat->T[ii]);
275 strat->T[ii].pLength=l_orig;
276 // store T_tail
277 T[pass]=T_tail;
278 // delayed computation: A[pass]*tail-M[pass]*T[pass]
279#ifdef KDEBUG
280 if (TEST_OPT_DEBUG)
281 {
282 PrintS("\nto:");
283 h->wrp();
284 PrintLn();
285 }
286#endif
287 if(h->IsNull())
288 {
289 // clean up A,C,h_tail:
290 for(int i=0;i<=pass;i++)
291 {
292 n_Delete(&A[i],tailRing->cf);
293 p_Delete(&C[i],tailRing);
294 }
295 p_Delete(&h_tail,tailRing);
296 kDeleteLcm(h);
297 h->Clear();
298 omFreeSize(A,red_size*sizeof(number));
299 omFreeSize(T,red_size*sizeof(poly));
300 omFreeSize(C,red_size*sizeof(poly));
301 return 0;
302 }
303 h->SetShortExpVector();
304 not_sev = ~ h->sev;
305 h_d = h->SetpFDeg();
306 /* compute the ecart */
307 if (ei <= h->ecart)
308 h->ecart = d-h_d;
309 else
310 h->ecart = d-h_d+ei-h->ecart;
311
312 /*
313 * try to reduce the s-polynomial h
314 *test first whether h should go to the lazyset L
315 *-if the degree jumps
316 *-if the number of pre-defined reductions jumps
317 */
318 pass++;
319 d = h_d + h->ecart;
320 if (pass%RED_CANONICALIZE==0) kBucketCanonicalize(h->bucket);
321 // if cache is to small, double its size:
322 if (pass>=red_size-1)
323 {
324 A=(number*)omRealloc0Size(A,red_size*sizeof(number),2*red_size*sizeof(number));
325 C=(poly*)omRealloc0Size(C,red_size*sizeof(poly),2*red_size*sizeof(poly));
326 T=(poly*)omRealloc0Size(T,red_size*sizeof(poly),2*red_size*sizeof(poly));
327 if(TEST_OPT_PROT) {Print("+%d+",red_size);mflush();}
328 red_size*=2;
329 }
330 }
331}
#define UNLIKELY(X)
Definition: auxiliary.h:404
#define FALSE
Definition: auxiliary.h:96
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4078
CanonicalForm b
Definition: cfModGcd.cc:4103
ring tailRing
Definition: kutil.h:343
TSet T
Definition: kutil.h:326
unsigned syzComp
Definition: kutil.h:354
int tl
Definition: kutil.h:350
unsigned long * sevT
Definition: kutil.h:325
char use_buckets
Definition: kutil.h:383
char fromT
Definition: kutil.h:379
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:452
#define Print
Definition: emacs.cc:80
const CanonicalForm int s
Definition: facAbsFact.cc:51
int j
Definition: facHensel.cc:110
STATIC_VAR jList * T
Definition: janet.cc:30
STATIC_VAR Poly * h
Definition: janet.cc:971
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:959
int redLiftstd(LObject *h, kStrategy strat)
Definition: kLiftstd.cc:167
static poly lazyComp(number *A, poly *M, poly *T, int index, poly s, int *l, const ring tailR)
Definition: kLiftstd.cc:132
static void kAppend(poly t, TObject *h)
Definition: kLiftstd.cc:121
#define START_REDUCE
static poly kSplitAt(int k, TObject *h, kStrategy strat)
Definition: kLiftstd.cc:28
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:521
void kBucket_Minus_m_Mult_p(kBucket_pt bucket, poly m, poly p, int *l, poly spNoether)
Bpoly == Bpoly - m*p; where m is a monom Does not destroy p and m assume (*l <= 0 || pLength(p) == *l...
Definition: kbuckets.cc:722
void kBucket_Mult_n(kBucket_pt bucket, number n)
Multiply Bucket by number ,i.e. Bpoly == n*Bpoly.
Definition: kbuckets.cc:598
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:216
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:493
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:209
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:660
int kBucketCanonicalize(kBucket_pt bucket)
Canonicalizes Bpoly, i.e. converts polys of buckets into one poly in one bucket: Returns number of bu...
int ksReducePoly(LObject *PR, TObject *PW, poly spNoether, number *coef, poly *mon, kStrategy strat, BOOLEAN reduce)
Definition: kspoly.cc:189
int kFindDivisibleByInT(const kStrategy strat, const LObject *L, const int start)
return -1 if no divisor is found number of first divisor in T, otherwise
Definition: kstd2.cc:321
static void kDeleteLcm(LObject *P)
Definition: kutil.h:880
#define RED_CANONICALIZE
Definition: kutil.h:36
class sTObject TObject
Definition: kutil.h:57
class sLObject LObject
Definition: kutil.h:58
#define assume(x)
Definition: mod2.h:389
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
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 nSize(n)
Definition: numbers.h:39
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
#define NULL
Definition: omList.c:12
#define TEST_OPT_IDLIFT
Definition: options.h:130
#define TEST_OPT_LENGTH
Definition: options.h:132
#define TEST_OPT_PROT
Definition: options.h:104
#define TEST_OPT_DEBUG
Definition: options.h:109
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
static int pLength(poly a)
Definition: p_polys.h:188
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1908
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:899
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
void PrintS(const char *s)
Definition: reporter.cc:284
void PrintLn()
Definition: reporter.cc:310
#define mflush()
Definition: reporter.h:58
#define A
Definition: sirandom.c:24
#define M
Definition: sirandom.c:25
#define loop
Definition: structs.h:75