1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT - Kernel: factorizing alg. of Buchberger |
---|
6 | */ |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | #include <kernel/mod2.h> |
---|
12 | #include <omalloc/omalloc.h> |
---|
13 | #include <misc/options.h> |
---|
14 | #include <kernel/polys.h> |
---|
15 | #include <kernel/ideals.h> |
---|
16 | #include <kernel/GBEngine/kutil.h> |
---|
17 | #include <kernel/GBEngine/kstd1.h> |
---|
18 | #include <kernel/GBEngine/khstd.h> |
---|
19 | //#include "cntrlc.h" |
---|
20 | #include <polys/weight.h> |
---|
21 | //#include "ipshell.h" |
---|
22 | #include <misc/intvec.h> |
---|
23 | #include <polys/clapsing.h> |
---|
24 | #include <kernel/ideals.h> |
---|
25 | #include <kernel/GBEngine/kstdfac.h> |
---|
26 | |
---|
27 | #ifndef SING_NDEBUG |
---|
28 | int strat_nr=0; |
---|
29 | int strat_fac_debug=0; |
---|
30 | #endif |
---|
31 | /*3 |
---|
32 | * copy o->T to n->T, assumes that n->S is already copied |
---|
33 | */ |
---|
34 | static void copyT (kStrategy o,kStrategy n) |
---|
35 | { |
---|
36 | int i,j; |
---|
37 | poly p; |
---|
38 | TSet t=(TSet)omAlloc0(o->tmax*sizeof(TObject)); |
---|
39 | TObject** r = (TObject**)omAlloc0(o->tmax*sizeof(TObject*)); |
---|
40 | |
---|
41 | for (j=0; j<=o->tl; j++) |
---|
42 | { |
---|
43 | t[j] = o->T[j]; |
---|
44 | r[t[j].i_r] = &t[j]; |
---|
45 | p = o->T[j].p; |
---|
46 | i = -1; |
---|
47 | loop |
---|
48 | { |
---|
49 | i++; |
---|
50 | if (i>o->sl) |
---|
51 | { |
---|
52 | t[j].p=pCopy(p); |
---|
53 | break; |
---|
54 | } |
---|
55 | if (p == o->S[i]) |
---|
56 | { |
---|
57 | t[j].p=n->S[i]; |
---|
58 | break; |
---|
59 | } |
---|
60 | } |
---|
61 | t[j].t_p = NULL; // ?? or t[j].p ?? |
---|
62 | t[j].max = NULL; // ?? or p_GetMaxExpP(t[j].t_p,o->tailRing); ?? |
---|
63 | t[j].pLength = pLength(p); |
---|
64 | } |
---|
65 | n->T=t; |
---|
66 | n->R=r; |
---|
67 | } |
---|
68 | |
---|
69 | /*3 |
---|
70 | * copy o->L to n->L, assumes that n->T,n->tail is already copied |
---|
71 | */ |
---|
72 | static void copyL (kStrategy o,kStrategy n) |
---|
73 | { |
---|
74 | int i,j; |
---|
75 | poly p; |
---|
76 | LSet l=(LSet)omAlloc(o->Lmax*sizeof(LObject)); |
---|
77 | |
---|
78 | for (j=0; j<=o->Ll; j++) |
---|
79 | { |
---|
80 | l[j] = o->L[j]; |
---|
81 | // copy .p ---------------------------------------------- |
---|
82 | if (pNext(o->L[j].p)!=o->tail) |
---|
83 | l[j].p=pCopy(o->L[j].p); |
---|
84 | else |
---|
85 | { |
---|
86 | l[j].p=pHead(o->L[j].p); |
---|
87 | pNext(l[j].p)=n->tail; |
---|
88 | } |
---|
89 | // copy .lcm ---------------------------------------------- |
---|
90 | if (o->L[j].lcm!=NULL) |
---|
91 | l[j].lcm=pLmInit(o->L[j].lcm); |
---|
92 | else |
---|
93 | l[j].lcm=NULL; |
---|
94 | l[j].p1=NULL; |
---|
95 | l[j].p2=NULL; |
---|
96 | l[j].t_p = NULL; |
---|
97 | |
---|
98 | // copy .p1 , i_r1---------------------------------------------- |
---|
99 | p = o->L[j].p1; |
---|
100 | i = -1; |
---|
101 | loop |
---|
102 | { |
---|
103 | if(p==NULL) break; |
---|
104 | i++; |
---|
105 | if(i>o->tl) |
---|
106 | { |
---|
107 | Warn("poly p1 not found in T:");wrp(p);PrintLn(); |
---|
108 | l[j].p1=pCopy(p); |
---|
109 | l[j].i_r1=-1; |
---|
110 | break; |
---|
111 | } |
---|
112 | if (p == o->T[i].p) |
---|
113 | { |
---|
114 | l[j].p1=n->T[i].p; |
---|
115 | l[j].i_r1=n->T[i].i_r; |
---|
116 | break; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | // copy .p2 , i_r2---------------------------------------------- |
---|
121 | p = o->L[j].p2; |
---|
122 | i = -1; |
---|
123 | loop |
---|
124 | { |
---|
125 | if(p==NULL) break; |
---|
126 | i++; |
---|
127 | if(i>o->tl) |
---|
128 | { |
---|
129 | Warn("poly p2 not found in T:");wrp(p);PrintLn(); |
---|
130 | l[j].p2=pCopy(p); |
---|
131 | l[j].i_r2=-1; |
---|
132 | break; |
---|
133 | } |
---|
134 | if (p == o->T[i].p) |
---|
135 | { |
---|
136 | l[j].p2=n->T[i].p; |
---|
137 | l[j].i_r2=n->T[i].i_r; |
---|
138 | break; |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | // copy .ecart --------------------------------------------- |
---|
143 | l[j].ecart=o->L[j].ecart; |
---|
144 | // copy .length -------------------------------------------- |
---|
145 | l[j].length=o->L[j].length; |
---|
146 | // copy .pLength ------------------------------------------- |
---|
147 | l[j].pLength=o->L[j].pLength; |
---|
148 | // copy .sev ----------------------------------------------- |
---|
149 | l[j].sev=o->L[j].sev; |
---|
150 | l[j].i_r = o->L[j].i_r; |
---|
151 | //l[j].i_r1 = o->L[j].i_r1; |
---|
152 | //l[j].i_r2 = o->L[j].i_r2; |
---|
153 | } |
---|
154 | n->L=l; |
---|
155 | } |
---|
156 | |
---|
157 | kStrategy kStratCopy(kStrategy o) |
---|
158 | { |
---|
159 | // int i; |
---|
160 | kTest_TS(o); |
---|
161 | kStrategy s=new skStrategy; |
---|
162 | s->next=NULL; |
---|
163 | s->red=o->red; |
---|
164 | s->initEcart=o->initEcart; |
---|
165 | s->posInT=o->posInT; |
---|
166 | s->posInL=o->posInL; |
---|
167 | s->enterS=o->enterS; |
---|
168 | s->initEcartPair=o->initEcartPair; |
---|
169 | s->posInLOld=o->posInLOld; |
---|
170 | s->enterOnePair=o->enterOnePair; |
---|
171 | s->chainCrit=o->chainCrit; |
---|
172 | s->Shdl=idCopy(o->Shdl); |
---|
173 | s->S=s->Shdl->m; |
---|
174 | s->tailRing = o->tailRing; |
---|
175 | if (o->D!=NULL) s->D=idCopy(o->D); |
---|
176 | else s->D=NULL; |
---|
177 | s->ecartS=(int *)omAlloc(IDELEMS(o->Shdl)*sizeof(int)); |
---|
178 | memcpy(s->ecartS,o->ecartS,IDELEMS(o->Shdl)*sizeof(int)); |
---|
179 | s->sevS=(unsigned long *)omAlloc(IDELEMS(o->Shdl)*sizeof(unsigned long)); |
---|
180 | memcpy(s->sevS,o->sevS,IDELEMS(o->Shdl)*sizeof(unsigned long)); |
---|
181 | s->S_2_R=(int*)omAlloc(IDELEMS(o->Shdl)*sizeof(int)); |
---|
182 | memcpy(s->S_2_R,o->S_2_R,IDELEMS(o->Shdl)*sizeof(int)); |
---|
183 | s->sevT=(unsigned long *)omAlloc(o->tmax*sizeof(unsigned long)); |
---|
184 | memcpy(s->sevT,o->sevT,o->tmax*sizeof(unsigned long)); |
---|
185 | if(o->fromQ!=NULL) |
---|
186 | { |
---|
187 | s->fromQ=(int *)omAlloc(IDELEMS(o->Shdl)*sizeof(int)); |
---|
188 | memcpy(s->fromQ,o->fromQ,IDELEMS(o->Shdl)*sizeof(int)); |
---|
189 | } |
---|
190 | else |
---|
191 | s->fromQ=NULL; |
---|
192 | copyT(o,s);//s->T=... |
---|
193 | s->tail = pInit(); |
---|
194 | copyL(o,s);//s->L=... |
---|
195 | s->B=initL(); |
---|
196 | s->kHEdge=pCopy(o->kHEdge); |
---|
197 | s->kNoether=pCopy(o->kNoether); |
---|
198 | if (o->NotUsedAxis!=NULL) |
---|
199 | { |
---|
200 | s->NotUsedAxis=(BOOLEAN *)omAlloc(currRing->N*sizeof(BOOLEAN)); |
---|
201 | memcpy(s->NotUsedAxis,o->NotUsedAxis,currRing->N*sizeof(BOOLEAN)); |
---|
202 | } |
---|
203 | //s->P=s->L[s->Ll+1]; |
---|
204 | s->P.Init(o->tailRing); |
---|
205 | s->update=o->update; |
---|
206 | s->posInLOldFlag=o->posInLOldFlag; |
---|
207 | s->kModW = o->kModW; |
---|
208 | // if (o->kModW!=NULL) |
---|
209 | // s->kModW=ivCopy(o->kModW); |
---|
210 | // else |
---|
211 | // s->kModW=NULL; |
---|
212 | s->pairtest=NULL; |
---|
213 | s->sl=o->sl; |
---|
214 | s->mu=o->mu; |
---|
215 | s->tl=o->tl; |
---|
216 | s->tmax=o->tmax; |
---|
217 | s->Ll=o->Ll; |
---|
218 | s->Lmax=o->Lmax; |
---|
219 | s->Bl=-1; |
---|
220 | s->Bmax=setmaxL; |
---|
221 | s->ak=o->ak; |
---|
222 | s->syzComp=o->syzComp; |
---|
223 | s->LazyPass=o->LazyPass; |
---|
224 | s->LazyDegree=o->LazyDegree; |
---|
225 | s->HCord=o->HCord; |
---|
226 | s->lastAxis=o->lastAxis; |
---|
227 | s->interpt=o->interpt; |
---|
228 | s->homog=o->homog; |
---|
229 | s->news=o->news; |
---|
230 | s->newt=o->newt; |
---|
231 | s->kHEdgeFound=o->kHEdgeFound; |
---|
232 | s->honey=o->honey; |
---|
233 | s->sugarCrit=o->sugarCrit; |
---|
234 | s->Gebauer=o->Gebauer; |
---|
235 | s->noTailReduction=o->noTailReduction; |
---|
236 | s->fromT=o->fromT; |
---|
237 | s->noetherSet=o->noetherSet; |
---|
238 | #ifdef HAVE_SHIFTBBA |
---|
239 | s->lV=o->lV; |
---|
240 | #endif |
---|
241 | #ifdef HAVE_PLURAL |
---|
242 | s->no_prod_crit=o->no_prod_crit; |
---|
243 | #endif |
---|
244 | kTest_TS(s); |
---|
245 | return s; |
---|
246 | } |
---|
247 | |
---|
248 | BOOLEAN k_factorize(poly p,ideal &rfac, ideal &fac_copy) |
---|
249 | { |
---|
250 | int facdeg=currRing->pFDeg(p,currRing); |
---|
251 | ideal fac=singclap_factorize(pCopy(p),NULL,1,currRing); |
---|
252 | int fac_elems; |
---|
253 | fac_elems=IDELEMS(fac); |
---|
254 | rfac=fac; |
---|
255 | fac_copy=idInit(fac_elems,1); |
---|
256 | |
---|
257 | if ((fac_elems!=1)||(facdeg!=currRing->pFDeg(fac->m[0],currRing))) |
---|
258 | { |
---|
259 | if (TEST_OPT_DEBUG) |
---|
260 | { |
---|
261 | Print("-> %d factors\n",fac_elems); |
---|
262 | if (fac_elems!=1) |
---|
263 | { |
---|
264 | pWrite(p); PrintS(" ->\n"); |
---|
265 | int ii=fac_elems; |
---|
266 | while(ii>0) { ii--;pWrite(fac->m[ii]); } |
---|
267 | } |
---|
268 | } |
---|
269 | else if (TEST_OPT_PROT) |
---|
270 | { |
---|
271 | int ii=fac_elems; |
---|
272 | if (ii>1) |
---|
273 | { |
---|
274 | while(ii>0) { PrintS("F"); ii--; } |
---|
275 | } |
---|
276 | } |
---|
277 | #ifndef SING_NDEBUG |
---|
278 | else if (strat_fac_debug) |
---|
279 | { |
---|
280 | pWrite(p); |
---|
281 | Print("-> %d factors\n",fac_elems); |
---|
282 | if (fac_elems!=1) |
---|
283 | { |
---|
284 | int ii=fac_elems; |
---|
285 | while(ii>0) { ii--;pWrite(fac->m[ii]); } |
---|
286 | } |
---|
287 | } |
---|
288 | #endif |
---|
289 | return TRUE; |
---|
290 | } |
---|
291 | else |
---|
292 | { |
---|
293 | pDelete(&(fac->m[0])); |
---|
294 | fac->m[0]=pCopy(p); |
---|
295 | } |
---|
296 | return FALSE; |
---|
297 | } |
---|
298 | |
---|
299 | static void completeReduceFac (kStrategy strat, ideal_list FL) |
---|
300 | { |
---|
301 | int si; |
---|
302 | |
---|
303 | strat->noTailReduction = FALSE; |
---|
304 | if (TEST_OPT_PROT) |
---|
305 | { |
---|
306 | PrintLn(); |
---|
307 | // if (timerv) writeTime("standard base computed:"); |
---|
308 | } |
---|
309 | if (TEST_OPT_PROT) |
---|
310 | { |
---|
311 | Print("(S:%d)",strat->sl);mflush(); |
---|
312 | } |
---|
313 | for (si=strat->sl; si>0; si--) |
---|
314 | { |
---|
315 | strat->S[si] = redtailBba(strat->S[si],si-1,strat); |
---|
316 | if (TEST_OPT_INTSTRATEGY) |
---|
317 | { |
---|
318 | strat->S[si]=p_Cleardenom(strat->S[si], currRing); |
---|
319 | } |
---|
320 | if (TEST_OPT_PROT) |
---|
321 | { |
---|
322 | PrintS("-");mflush(); |
---|
323 | } |
---|
324 | int i; |
---|
325 | if (strat->redTailChange) |
---|
326 | { |
---|
327 | for(i=strat->tl;i>=0;i--) |
---|
328 | { |
---|
329 | strat->initEcart(&strat->T[i]); |
---|
330 | } |
---|
331 | } |
---|
332 | ideal fac; |
---|
333 | ideal fac_copy; |
---|
334 | |
---|
335 | if (!k_factorize(strat->S[si],fac,fac_copy)) |
---|
336 | { |
---|
337 | idDelete(&fac); |
---|
338 | idDelete(&fac_copy); |
---|
339 | continue; |
---|
340 | } |
---|
341 | |
---|
342 | deleteInS(si,strat); |
---|
343 | |
---|
344 | for(i=IDELEMS(fac)-1;i>=0;i--) |
---|
345 | { |
---|
346 | kStrategy n=strat; |
---|
347 | if (i>=1) |
---|
348 | { |
---|
349 | n=kStratCopy(strat); // includes: memset(&n->P,0,sizeof(n->P)); |
---|
350 | n->next=strat->next; |
---|
351 | strat->next=n; |
---|
352 | } |
---|
353 | else |
---|
354 | { |
---|
355 | n->P.Init(strat->tailRing); |
---|
356 | } |
---|
357 | |
---|
358 | n->P.p=fac->m[i]; |
---|
359 | n->P.pLength=0; |
---|
360 | n->initEcart(&n->P); |
---|
361 | /* enter P.p into s and L */ |
---|
362 | int pos; |
---|
363 | if (n->sl==-1) pos=0; |
---|
364 | else pos=posInS(n,n->sl,n->P.p,n->P.ecart); |
---|
365 | if (TEST_OPT_INTSTRATEGY) |
---|
366 | { |
---|
367 | n->P.p = redtailBba(n->P.p,pos-1,n); |
---|
368 | n->P.pCleardenom(); |
---|
369 | } |
---|
370 | else |
---|
371 | { |
---|
372 | pNorm(n->P.p); |
---|
373 | n->P.p = redtailBba(n->P.p,pos-1,n); |
---|
374 | } |
---|
375 | n->P.pLength=0; |
---|
376 | if (TEST_OPT_DEBUG) |
---|
377 | { |
---|
378 | PrintS("new s:"); |
---|
379 | wrp(n->P.p); |
---|
380 | PrintLn(); |
---|
381 | } |
---|
382 | enterpairs(n->P.p,n->sl,n->P.ecart,pos,n); |
---|
383 | enterT(n->P,n); |
---|
384 | n->enterS(n->P,pos,n, n->tl); |
---|
385 | |
---|
386 | /* construct D */ |
---|
387 | if (IDELEMS(fac)>1) |
---|
388 | { |
---|
389 | if (n->D==NULL) |
---|
390 | { |
---|
391 | n->D=idCopy(fac_copy); |
---|
392 | idSkipZeroes(n->D); |
---|
393 | } |
---|
394 | else |
---|
395 | { |
---|
396 | idTest(n->D); |
---|
397 | ideal r=idAdd(n->D,fac_copy); |
---|
398 | idDelete(&n->D); |
---|
399 | n->D=r; |
---|
400 | } |
---|
401 | if (TEST_OPT_DEBUG) |
---|
402 | { |
---|
403 | PrintS("new D:\n"); |
---|
404 | iiWriteMatrix((matrix)n->D,"D",1,currRing,0); |
---|
405 | PrintLn(); |
---|
406 | } |
---|
407 | } |
---|
408 | #ifndef SING_NDEBUG |
---|
409 | if(strat_fac_debug) |
---|
410 | { |
---|
411 | int ii; |
---|
412 | Print("---------------------------------------------------------------\ns(%d), set S\n",n->nr); |
---|
413 | for(ii=0;ii<n->sl;ii++) |
---|
414 | { Print("s(%d->S[%d]= ",n->nr,ii);pWrite(n->S[ii]);} |
---|
415 | Print("s(%d), set D\n",n->nr); |
---|
416 | if (n->D!=NULL) |
---|
417 | { |
---|
418 | for(ii=0;ii<IDELEMS(n->D);ii++) |
---|
419 | { Print("s(%d->D[%d]= ",n->nr,ii);pWrite(n->D->m[ii]);} |
---|
420 | } |
---|
421 | else PrintS(" empty\n"); |
---|
422 | } |
---|
423 | #endif |
---|
424 | |
---|
425 | fac_copy->m[i]=pCopy(fac->m[i]); |
---|
426 | fac->m[i]=NULL; |
---|
427 | |
---|
428 | /* check for empty sets */ |
---|
429 | if (n->D!=NULL) |
---|
430 | { |
---|
431 | int j=IDELEMS(n->D)-1; |
---|
432 | while(j>=0) |
---|
433 | { |
---|
434 | if (n->D->m[j]!=NULL) |
---|
435 | { |
---|
436 | poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM); |
---|
437 | if (r==NULL) |
---|
438 | { |
---|
439 | #ifndef SING_NDEBUG |
---|
440 | if(strat_fac_debug) |
---|
441 | { |
---|
442 | Print("empty set s(%d) because: D[%d] -> 0\n", |
---|
443 | n->nr, j); |
---|
444 | Print("s(%d)->D[%d]= ",n->nr,j);pWrite(n->D->m[j]); |
---|
445 | } |
---|
446 | #endif |
---|
447 | if (TEST_OPT_DEBUG) |
---|
448 | { |
---|
449 | PrintS("empty set because:"); |
---|
450 | wrp(n->D->m[j]); |
---|
451 | PrintLn(); |
---|
452 | messageSets(n); |
---|
453 | } |
---|
454 | while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n); |
---|
455 | while (n->tl >= 0) |
---|
456 | { |
---|
457 | int i=n->sl; |
---|
458 | while (i>=0) |
---|
459 | { |
---|
460 | if (n->S[i]==n->T[n->tl].p) |
---|
461 | { |
---|
462 | n->T[n->tl].p=NULL; n->S[i]=NULL; |
---|
463 | break; |
---|
464 | } |
---|
465 | i--; |
---|
466 | } |
---|
467 | pDelete(&n->T[n->tl].p); |
---|
468 | n->tl--; |
---|
469 | } |
---|
470 | memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly)); |
---|
471 | n->sl=-1; |
---|
472 | if (strat==n) si=-1; |
---|
473 | break; |
---|
474 | } |
---|
475 | else |
---|
476 | { |
---|
477 | pDelete(&r); |
---|
478 | } |
---|
479 | } |
---|
480 | j--; |
---|
481 | } |
---|
482 | } |
---|
483 | /* check for empty sets */ |
---|
484 | { |
---|
485 | ideal_list Lj=FL; |
---|
486 | while (Lj!=NULL) |
---|
487 | { |
---|
488 | if ((n->sl>=0)&&(n->S[0]!=NULL)) |
---|
489 | { |
---|
490 | ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM); |
---|
491 | #ifndef SING_NDEBUG |
---|
492 | if(strat_fac_debug) |
---|
493 | { |
---|
494 | Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr); |
---|
495 | PrintS("L:\n"); |
---|
496 | iiWriteMatrix((matrix)Lj->d,"L",1,currRing,0); |
---|
497 | } |
---|
498 | #endif |
---|
499 | if (idIs0(r)) |
---|
500 | { |
---|
501 | if (TEST_OPT_DEBUG) |
---|
502 | { |
---|
503 | Print("empty set because:L[%p]\n",(void *)Lj); |
---|
504 | } |
---|
505 | while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n); |
---|
506 | while (n->tl >= 0) |
---|
507 | { |
---|
508 | int i=n->sl; |
---|
509 | while (i>=0) |
---|
510 | { |
---|
511 | if (n->S[i]==n->T[n->tl].p) |
---|
512 | { |
---|
513 | n->T[n->tl].p=NULL; n->S[i]=NULL; |
---|
514 | break; |
---|
515 | } |
---|
516 | i--; |
---|
517 | } |
---|
518 | pDelete(&n->T[n->tl].p); |
---|
519 | n->tl--; |
---|
520 | } |
---|
521 | memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly)); |
---|
522 | n->sl=-1; |
---|
523 | if (strat==n) si=-1; |
---|
524 | idDelete(&r); |
---|
525 | break; |
---|
526 | } |
---|
527 | idDelete(&r); |
---|
528 | } |
---|
529 | Lj=Lj->next; |
---|
530 | } |
---|
531 | } |
---|
532 | } /* for */ |
---|
533 | for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL; |
---|
534 | idDelete(&fac); |
---|
535 | idDelete(&fac_copy); |
---|
536 | if ((strat->Ll>=0) && (strat->sl>=0)) break; |
---|
537 | else si=strat->sl+1; |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | ideal bbafac (ideal /*F*/, ideal Q,intvec */*w*/,kStrategy strat, ideal_list FL) |
---|
542 | { |
---|
543 | int olddeg,reduc=0; |
---|
544 | int red_result = 1; |
---|
545 | reduc = olddeg = 0; |
---|
546 | /* compute------------------------------------------------------- */ |
---|
547 | if ((strat->Ll==-1) && (strat->sl>=0)) |
---|
548 | { |
---|
549 | if (TEST_OPT_REDSB) completeReduceFac(strat,FL); |
---|
550 | } |
---|
551 | kTest_TS(strat); |
---|
552 | while (strat->Ll >= 0) |
---|
553 | { |
---|
554 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
555 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
556 | if (TEST_OPT_DEGBOUND |
---|
557 | && ((strat->honey |
---|
558 | && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
559 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
560 | { |
---|
561 | /* |
---|
562 | *stops computation if |
---|
563 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
564 | *a predefined number Kstd1_deg |
---|
565 | */ |
---|
566 | while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
567 | break; |
---|
568 | } |
---|
569 | /* picks the last element from the lazyset L */ |
---|
570 | strat->P = strat->L[strat->Ll]; |
---|
571 | strat->Ll--; |
---|
572 | if (pNext(strat->P.p) == strat->tail) |
---|
573 | { |
---|
574 | /* deletes the short spoly and computes */ |
---|
575 | pLmFree(strat->P.p); |
---|
576 | /* the real one */ |
---|
577 | strat->P.p = ksOldCreateSpoly(strat->P.p1, |
---|
578 | strat->P.p2, |
---|
579 | strat->kNoether); |
---|
580 | } |
---|
581 | if (strat->honey) |
---|
582 | { |
---|
583 | if (TEST_OPT_PROT) |
---|
584 | message(strat->P.ecart+currRing->pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result); |
---|
585 | } |
---|
586 | else |
---|
587 | { |
---|
588 | if (TEST_OPT_PROT) |
---|
589 | message(currRing->pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result); |
---|
590 | } |
---|
591 | /* reduction of the element chosen from L */ |
---|
592 | kTest_TS(strat); |
---|
593 | red_result = strat->red(&strat->P,strat); |
---|
594 | if (strat->P.p != NULL) |
---|
595 | { |
---|
596 | /* statistic */ |
---|
597 | if (TEST_OPT_PROT) PrintS("s"); |
---|
598 | ideal fac; |
---|
599 | ideal fac_copy; |
---|
600 | |
---|
601 | if (!k_factorize(strat->P.p,fac,fac_copy)) |
---|
602 | { |
---|
603 | if (TEST_OPT_INTSTRATEGY) |
---|
604 | { |
---|
605 | strat->P.p = redtailBba(strat->P.p,strat->sl,strat); |
---|
606 | if (strat->redTailChange) strat->P.pCleardenom(); |
---|
607 | } |
---|
608 | else |
---|
609 | { |
---|
610 | pNorm(strat->P.p); |
---|
611 | strat->P.p = redtailBba(strat->P.p,strat->sl,strat); |
---|
612 | } |
---|
613 | if (strat->redTailChange) |
---|
614 | { |
---|
615 | idDelete(&fac); |
---|
616 | idDelete(&fac_copy); |
---|
617 | if (!k_factorize(strat->P.p,fac,fac_copy)) |
---|
618 | { |
---|
619 | pDelete(&(fac->m[0])); |
---|
620 | fac->m[0]=strat->P.p; |
---|
621 | strat->P.p=NULL; |
---|
622 | } |
---|
623 | else |
---|
624 | { |
---|
625 | pDelete(&strat->P.p); |
---|
626 | } |
---|
627 | } |
---|
628 | } |
---|
629 | if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm); |
---|
630 | int i; |
---|
631 | |
---|
632 | for(i=IDELEMS(fac)-1;i>=0;i--) |
---|
633 | { |
---|
634 | int ii; |
---|
635 | kStrategy n=strat; |
---|
636 | if (i>=1) |
---|
637 | { |
---|
638 | n=kStratCopy(strat); // includes memset(&n->P,0,sizeof(n->P)); |
---|
639 | kTest_TS(n); |
---|
640 | n->next=strat->next; |
---|
641 | strat->next=n; |
---|
642 | } |
---|
643 | else |
---|
644 | { |
---|
645 | n->P.Init(strat->tailRing); |
---|
646 | } |
---|
647 | |
---|
648 | n->P.pLength=0; |
---|
649 | n->P.p=fac->m[i]; |
---|
650 | n->initEcart(&n->P); |
---|
651 | kTest_TS(n); |
---|
652 | |
---|
653 | /* enter P.p into s and L */ |
---|
654 | int pos; |
---|
655 | if (n->sl==-1) pos=0; |
---|
656 | else pos=posInS(n,n->sl,n->P.p,n->P.ecart); |
---|
657 | |
---|
658 | // we have already reduced all elements from fac.... |
---|
659 | if (TEST_OPT_INTSTRATEGY) |
---|
660 | { |
---|
661 | n->P.p = redtailBba(n->P.p,pos-1,n); |
---|
662 | if (n->redTailChange) |
---|
663 | { |
---|
664 | n->P.pCleardenom(); |
---|
665 | n->P.pLength=0; |
---|
666 | } |
---|
667 | } |
---|
668 | else |
---|
669 | { |
---|
670 | pNorm(n->P.p); |
---|
671 | n->P.p = redtailBba(n->P.p,pos-1,n); |
---|
672 | if (n->redTailChange) |
---|
673 | { |
---|
674 | n->P.pLength=0; |
---|
675 | } |
---|
676 | } |
---|
677 | kTest_TS(n); |
---|
678 | |
---|
679 | if (TEST_OPT_DEBUG) |
---|
680 | { |
---|
681 | PrintS("new s:"); |
---|
682 | wrp(n->P.p); |
---|
683 | PrintLn(); |
---|
684 | } |
---|
685 | enterpairs(n->P.p,n->sl,n->P.ecart,pos,n); |
---|
686 | enterT(n->P,n); |
---|
687 | n->enterS(n->P,pos,n, n->tl); |
---|
688 | { |
---|
689 | int i=n->Ll; |
---|
690 | for(;i>=0;i--) |
---|
691 | { |
---|
692 | n->L[i].i_r1= -1; |
---|
693 | for(ii=0; ii<=n->tl; ii++) |
---|
694 | { |
---|
695 | if (n->R[ii]->p==n->L[i].p1) { n->L[i].i_r1=ii;break; } |
---|
696 | } |
---|
697 | n->L[i].i_r2= -1; |
---|
698 | for(ii=0; ii<=n->tl; ii++) |
---|
699 | { |
---|
700 | if (n->R[ii]->p==n->L[i].p2) { n->L[i].i_r2=ii;break; } |
---|
701 | } |
---|
702 | } |
---|
703 | } |
---|
704 | kTest_TS(n); |
---|
705 | /* construct D */ |
---|
706 | if (IDELEMS(fac)>1) |
---|
707 | { |
---|
708 | if (n->D==NULL) |
---|
709 | { |
---|
710 | n->D=idCopy(fac_copy); |
---|
711 | idSkipZeroes(n->D); |
---|
712 | } |
---|
713 | else |
---|
714 | { |
---|
715 | idTest(n->D); |
---|
716 | ideal r=idAdd(n->D,fac_copy); |
---|
717 | idDelete(&n->D); |
---|
718 | n->D=r; |
---|
719 | } |
---|
720 | if (TEST_OPT_DEBUG) |
---|
721 | { |
---|
722 | PrintS("new D:\n"); |
---|
723 | iiWriteMatrix((matrix)n->D,"D",1,currRing,0); |
---|
724 | PrintLn(); |
---|
725 | } |
---|
726 | } |
---|
727 | #ifndef SING_NDEBUG |
---|
728 | if(strat_fac_debug) |
---|
729 | { |
---|
730 | int ii; |
---|
731 | Print("-------------------------------------------------------------\ns(%d), set S\n",n->nr); |
---|
732 | for(ii=0;ii<n->sl;ii++) |
---|
733 | { Print("s(%d->S[%d]= ",n->nr,ii);pWrite(n->S[ii]);} |
---|
734 | Print("s(%d), set D\n",n->nr); |
---|
735 | if (n->D!=NULL) |
---|
736 | { |
---|
737 | for(ii=0;ii<IDELEMS(n->D);ii++) |
---|
738 | { Print("s(%d->D[%d]= ",n->nr,ii);pWrite(n->D->m[ii]);} |
---|
739 | } |
---|
740 | else PrintS(" empty\n"); |
---|
741 | } |
---|
742 | #endif |
---|
743 | |
---|
744 | fac_copy->m[i]=pCopy(fac->m[i]); |
---|
745 | fac->m[i]=NULL; |
---|
746 | |
---|
747 | /* check for empty sets */ |
---|
748 | if (n->D!=NULL) |
---|
749 | { |
---|
750 | int j=IDELEMS(n->D)-1; |
---|
751 | while(j>=0) |
---|
752 | { |
---|
753 | if (n->D->m[j]!=NULL) |
---|
754 | { |
---|
755 | poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM); |
---|
756 | if (r==NULL) |
---|
757 | { |
---|
758 | #ifndef SING_NDEBUG |
---|
759 | if(strat_fac_debug) |
---|
760 | { |
---|
761 | Print("empty set s(%d) because: D[%d] -> 0\n", |
---|
762 | n->nr, j); |
---|
763 | Print("s(%d)->D[%d]= ",n->nr,j);pWrite(n->D->m[j]); |
---|
764 | } |
---|
765 | #endif |
---|
766 | if (TEST_OPT_DEBUG) |
---|
767 | { |
---|
768 | PrintS("empty set because:"); |
---|
769 | wrp(n->D->m[j]); |
---|
770 | PrintLn(); |
---|
771 | messageSets(n); |
---|
772 | } |
---|
773 | //if (n->Ll >=0) Print("Ll:%d|",n->Ll); |
---|
774 | while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n); |
---|
775 | //if (n->tl >=0) Print("tl:%d|",n->tl); |
---|
776 | while (n->tl >= 0) |
---|
777 | { |
---|
778 | int i=n->sl; |
---|
779 | while (i>=0) |
---|
780 | { |
---|
781 | if (n->S[i]==n->T[n->tl].p) |
---|
782 | { |
---|
783 | n->T[n->tl].p=NULL; n->S[i]=NULL; |
---|
784 | break; |
---|
785 | } |
---|
786 | i--; |
---|
787 | } |
---|
788 | pDelete(&n->T[n->tl].p); |
---|
789 | n->tl--; |
---|
790 | } |
---|
791 | memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly)); |
---|
792 | n->sl=-1; |
---|
793 | break; |
---|
794 | } |
---|
795 | else |
---|
796 | { |
---|
797 | pDelete(&r); |
---|
798 | } |
---|
799 | } |
---|
800 | j--; |
---|
801 | } |
---|
802 | } |
---|
803 | |
---|
804 | /* check for empty sets */ |
---|
805 | { |
---|
806 | ideal_list Lj=FL; |
---|
807 | while (Lj!=NULL) |
---|
808 | { |
---|
809 | if ((n->sl>=0)&&(n->S[0]!=NULL)) |
---|
810 | { |
---|
811 | ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM); |
---|
812 | if (idIs0(r)) |
---|
813 | { |
---|
814 | #ifndef SING_NDEBUG |
---|
815 | if(strat_fac_debug) |
---|
816 | { |
---|
817 | Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr); |
---|
818 | PrintS("L:\n"); |
---|
819 | iiWriteMatrix((matrix)Lj->d,"L",1,currRing,0); |
---|
820 | } |
---|
821 | #endif |
---|
822 | if (TEST_OPT_DEBUG) |
---|
823 | { |
---|
824 | Print("empty set because:L[%p]\n",(void*)Lj); |
---|
825 | } |
---|
826 | while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n); |
---|
827 | while (n->tl >= 0) |
---|
828 | { |
---|
829 | int i=n->sl; |
---|
830 | while (i>=0) |
---|
831 | { |
---|
832 | if (n->S[i]==n->T[n->tl].p) |
---|
833 | { |
---|
834 | n->T[n->tl].p=NULL; n->S[i]=NULL; |
---|
835 | break; |
---|
836 | } |
---|
837 | i--; |
---|
838 | } |
---|
839 | pDelete(&n->T[n->tl].p); |
---|
840 | n->tl--; |
---|
841 | } |
---|
842 | memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly)); |
---|
843 | n->sl=-1; |
---|
844 | idDelete(&r); |
---|
845 | break; |
---|
846 | } |
---|
847 | idDelete(&r); |
---|
848 | } |
---|
849 | Lj=Lj->next; |
---|
850 | } |
---|
851 | } |
---|
852 | } /* for */ |
---|
853 | for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL; |
---|
854 | idDelete(&fac); |
---|
855 | idDelete(&fac_copy); |
---|
856 | } |
---|
857 | #ifdef KDEBUG |
---|
858 | strat->P.lcm=NULL; |
---|
859 | #endif |
---|
860 | kTest_TS(strat); |
---|
861 | if ((strat->Ll==-1) && (strat->sl>=0)) |
---|
862 | { |
---|
863 | if (TEST_OPT_REDSB) completeReduceFac(strat,FL); |
---|
864 | } |
---|
865 | kTest_TS(strat); |
---|
866 | } |
---|
867 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
868 | /* complete reduction of the standard basis--------- */ |
---|
869 | /* release temp data-------------------------------- */ |
---|
870 | if (TEST_OPT_WEIGHTM) |
---|
871 | { |
---|
872 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
873 | if (ecartWeights) |
---|
874 | { |
---|
875 | omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
876 | ecartWeights=NULL; |
---|
877 | } |
---|
878 | } |
---|
879 | exitBuchMora(strat); |
---|
880 | if (TEST_OPT_PROT) { PrintLn(); messageStat(0,strat); } |
---|
881 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
882 | return (strat->Shdl); |
---|
883 | } |
---|
884 | |
---|
885 | ideal_list kStdfac(ideal F, ideal Q, tHomog h,intvec ** w,ideal D) |
---|
886 | { |
---|
887 | ideal r; |
---|
888 | BOOLEAN b=currRing->pLexOrder,toReset=FALSE; |
---|
889 | BOOLEAN delete_w=(w==NULL); |
---|
890 | kStrategy strat=new skStrategy; |
---|
891 | kStrategy orgstrat=strat; |
---|
892 | ideal_list L=NULL; |
---|
893 | |
---|
894 | if (rField_has_simple_inverse(currRing)) |
---|
895 | strat->LazyPass=20; |
---|
896 | else |
---|
897 | strat->LazyPass=2; |
---|
898 | strat->LazyDegree = 1; |
---|
899 | strat->ak = id_RankFreeModule(F,currRing); |
---|
900 | if (h==testHomog) |
---|
901 | { |
---|
902 | if (strat->ak==0) |
---|
903 | { |
---|
904 | h = (tHomog)idHomIdeal(F,Q); |
---|
905 | w=NULL; |
---|
906 | } |
---|
907 | else |
---|
908 | h = (tHomog)idHomModule(F,Q,w); |
---|
909 | } |
---|
910 | if (h==isHomog) |
---|
911 | { |
---|
912 | if ((w!=NULL) && (*w!=NULL)) |
---|
913 | { |
---|
914 | kModW = *w; |
---|
915 | strat->kModW = *w; |
---|
916 | strat->pOrigFDeg = currRing->pFDeg; |
---|
917 | strat->pOrigLDeg = currRing->pLDeg; |
---|
918 | pSetDegProcs(currRing,kModDeg); |
---|
919 | toReset = TRUE; |
---|
920 | } |
---|
921 | currRing->pLexOrder = TRUE; |
---|
922 | strat->LazyPass*=2; |
---|
923 | } |
---|
924 | strat->homog=h; |
---|
925 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
926 | initBuchMoraPos(strat); |
---|
927 | initBba(F,strat); |
---|
928 | initBuchMora(F, Q,strat); |
---|
929 | if (D!=NULL) |
---|
930 | { |
---|
931 | strat->D=idCopy(D); |
---|
932 | } |
---|
933 | // Ende der Initalisierung |
---|
934 | while (strat!=NULL) |
---|
935 | { |
---|
936 | if (TEST_OPT_DEBUG) |
---|
937 | PrintS("====================================\n"); |
---|
938 | if (w!=NULL) |
---|
939 | r=bbafac(F,Q,*w,strat,L); |
---|
940 | else |
---|
941 | r=bbafac(F,Q,NULL,strat,L); |
---|
942 | #ifdef KDEBUG |
---|
943 | int i; |
---|
944 | for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]); |
---|
945 | #endif |
---|
946 | idSkipZeroes(r); |
---|
947 | // Testausgabe: |
---|
948 | //if (!idIs0(r)) |
---|
949 | //{ |
---|
950 | // PrintS("===================================================\n"); |
---|
951 | // iiWriteMatrix((matrix)r,"S",1,currRing,0); |
---|
952 | // PrintS("\n===================================================\n"); |
---|
953 | //} |
---|
954 | //else |
---|
955 | //{ |
---|
956 | // PrintS("=========empty============================\n"); |
---|
957 | //} |
---|
958 | if(!idIs0(r)) |
---|
959 | { |
---|
960 | ideal_list LL=(ideal_list)omAlloc(sizeof(*LL)); |
---|
961 | LL->d=r; |
---|
962 | #ifndef SING_NDEBUG |
---|
963 | LL->nr=strat->nr; |
---|
964 | #endif |
---|
965 | LL->next=L; |
---|
966 | L=LL; |
---|
967 | } |
---|
968 | strat=strat->next; |
---|
969 | } |
---|
970 | /* check for empty sets */ |
---|
971 | if (L!=NULL) |
---|
972 | { |
---|
973 | ideal_list Lj=L->next; |
---|
974 | ideal_list Lj_prev=L; |
---|
975 | while (Lj!=NULL) |
---|
976 | { |
---|
977 | ideal_list Li=L; |
---|
978 | while(Li!=Lj) |
---|
979 | { |
---|
980 | ideal r=kNF(Lj->d,NULL,Li->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM); |
---|
981 | if (idIs0(r)) |
---|
982 | { |
---|
983 | #ifndef SING_NDEBUG |
---|
984 | if(strat_fac_debug) |
---|
985 | { |
---|
986 | Print("empty set L(%d) because:L(%d)\n",Lj->nr,Li->nr); |
---|
987 | } |
---|
988 | #endif |
---|
989 | if (TEST_OPT_DEBUG) |
---|
990 | { |
---|
991 | Print("empty set L[%p] because:L[%p]\n",(void*)Lj,(void*)Li); |
---|
992 | } |
---|
993 | // delete L[j], |
---|
994 | Li=L; |
---|
995 | if (Lj_prev!=NULL) |
---|
996 | { |
---|
997 | Lj=Lj_prev; |
---|
998 | if (Lj==L) Lj_prev=NULL; |
---|
999 | else |
---|
1000 | { |
---|
1001 | Lj_prev=L; |
---|
1002 | while(Lj_prev->next!=Lj) Lj_prev=Lj_prev->next; |
---|
1003 | } |
---|
1004 | } |
---|
1005 | else Lj=NULL; |
---|
1006 | } |
---|
1007 | else |
---|
1008 | { |
---|
1009 | Li=Li->next; |
---|
1010 | } |
---|
1011 | idDelete (&r); |
---|
1012 | } |
---|
1013 | if (Lj!=NULL) Lj=Lj->next; |
---|
1014 | } |
---|
1015 | } |
---|
1016 | // Ende: aufraeumen |
---|
1017 | if (toReset) |
---|
1018 | { |
---|
1019 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
1020 | kModW = NULL; |
---|
1021 | } |
---|
1022 | currRing->pLexOrder = b; |
---|
1023 | delete(strat); |
---|
1024 | strat=orgstrat; |
---|
1025 | while (strat!=NULL) |
---|
1026 | { |
---|
1027 | orgstrat=strat->next; |
---|
1028 | delete(strat); |
---|
1029 | strat=orgstrat; |
---|
1030 | } |
---|
1031 | if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w; |
---|
1032 | return L; |
---|
1033 | } |
---|