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