[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | |
---|
| 5 | /* |
---|
| 6 | * ABSTRACT: resolutions |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | |
---|
[9f7665] | 10 | |
---|
| 11 | |
---|
| 12 | |
---|
[599326] | 13 | #include <kernel/mod2.h> |
---|
[0f401f] | 14 | #include <misc/options.h> |
---|
[b1dfaf] | 15 | #include <omalloc/omalloc.h> |
---|
[737a68] | 16 | #include <kernel/polys.h> |
---|
[57fa2c4] | 17 | #include <kernel/GBEngine/kstd1.h> |
---|
| 18 | #include <kernel/GBEngine/kutil.h> |
---|
[922890] | 19 | #include <kernel/combinatorics/stairc.h> |
---|
[210e07] | 20 | #include <misc/intvec.h> |
---|
[0f401f] | 21 | #include <coeffs/numbers.h> |
---|
[599326] | 22 | #include <kernel/ideals.h> |
---|
[210e07] | 23 | #include <misc/intvec.h> |
---|
| 24 | #include <polys/monomials/ring.h> |
---|
[57fa2c4] | 25 | #include <kernel/GBEngine/syz.h> |
---|
[76cfef] | 26 | #include <polys/prCopy.h> |
---|
[35aab3] | 27 | |
---|
[76cfef] | 28 | #include <polys/nc/sca.h> |
---|
[35aab3] | 29 | |
---|
| 30 | static intvec * syPrepareModComp(ideal arg,intvec ** w) |
---|
| 31 | { |
---|
| 32 | intvec *w1 = NULL; |
---|
| 33 | int i; |
---|
| 34 | BOOLEAN isIdeal=FALSE; |
---|
| 35 | |
---|
| 36 | if ((w==NULL) || (*w==NULL)) return w1; |
---|
| 37 | int maxxx = (*w)->length(); |
---|
| 38 | if (maxxx==1) |
---|
| 39 | { |
---|
| 40 | maxxx = 2; |
---|
| 41 | isIdeal = TRUE; |
---|
| 42 | } |
---|
| 43 | w1 = new intvec(maxxx+IDELEMS(arg)); |
---|
| 44 | if (!isIdeal) |
---|
| 45 | { |
---|
| 46 | for (i=0;i<maxxx;i++) |
---|
| 47 | { |
---|
| 48 | (*w1)[i] = (**w)[i]; |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | for (i=maxxx;i<maxxx+IDELEMS(arg);i++) |
---|
| 52 | { |
---|
| 53 | if (arg->m[i-maxxx]!=NULL) |
---|
| 54 | { |
---|
[b50590] | 55 | (*w1)[i] = p_FDeg(arg->m[i-maxxx],currRing); |
---|
[35aab3] | 56 | if (pGetComp(arg->m[i-maxxx])!=0) |
---|
| 57 | { |
---|
| 58 | (*w1)[i]+=(**w)[pGetComp(arg->m[i-maxxx])-1]; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | delete (*w); |
---|
| 63 | *w = new intvec(IDELEMS(arg)+1); |
---|
| 64 | for (i=0;i<IDELEMS(arg);i++) |
---|
| 65 | { |
---|
| 66 | (**w)[i+1] = (*w1)[i+maxxx]; |
---|
| 67 | } |
---|
| 68 | return w1; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | static void syDeleteAbove(ideal up, int k) |
---|
| 72 | { |
---|
| 73 | if (up!=NULL) |
---|
| 74 | { |
---|
| 75 | for (int i=0;i<IDELEMS(up);i++) |
---|
| 76 | { |
---|
| 77 | if (up->m[i]!=NULL) |
---|
| 78 | pDeleteComp(&(up->m[i]),k+1); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /*2 |
---|
| 84 | *minimizes the module mod and cancel superfluous syzygies |
---|
| 85 | *from syz |
---|
| 86 | */ |
---|
| 87 | static void syMinStep(ideal mod,ideal syz,BOOLEAN final=FALSE,ideal up=NULL, |
---|
| 88 | tHomog h=isNotHomog) |
---|
| 89 | { |
---|
| 90 | ideal deg0=NULL; |
---|
| 91 | poly Unit1,Unit2,actWith; |
---|
| 92 | int len,i,j,ModComp,m,k,l; |
---|
| 93 | BOOLEAN searchUnit,existsUnit; |
---|
| 94 | |
---|
| 95 | if (TEST_OPT_PROT) PrintS("m"); |
---|
| 96 | if ((final) && (h==isHomog)) |
---|
| 97 | /*minim is TRUE, we are in the module: maxlength, maxlength <>0*/ |
---|
| 98 | { |
---|
[e511e0] | 99 | deg0=id_Jet(syz,0,currRing); |
---|
[35aab3] | 100 | idSkipZeroes(deg0); |
---|
| 101 | syz=deg0; |
---|
| 102 | } |
---|
| 103 | /*--cancels empty entees and their related components above--*/ |
---|
| 104 | j = IDELEMS(syz); |
---|
| 105 | while ((j>0) && (!syz->m[j-1])) j--; |
---|
| 106 | k = 0; |
---|
| 107 | while (k<j) |
---|
| 108 | { |
---|
| 109 | if (syz->m[k]!=NULL) |
---|
| 110 | k++; |
---|
| 111 | else |
---|
| 112 | { |
---|
| 113 | if (TEST_OPT_PROT) PrintS("."); |
---|
| 114 | for (l=k;l<j-1;l++) syz->m[l] = syz->m[l+1]; |
---|
| 115 | syz->m[j-1] = NULL; |
---|
| 116 | syDeleteAbove(up,k); |
---|
| 117 | j--; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | /*--searches for syzygies coming from superfluous elements |
---|
| 121 | * in the module below--*/ |
---|
| 122 | searchUnit = TRUE; |
---|
[b50590] | 123 | int curr_syz_limit = rGetCurrSyzLimit(currRing); |
---|
[35aab3] | 124 | while (searchUnit) |
---|
| 125 | { |
---|
| 126 | i=0; |
---|
| 127 | j=IDELEMS(syz); |
---|
| 128 | while ((j>0) && (syz->m[j-1]==NULL)) j--; |
---|
| 129 | existsUnit = FALSE; |
---|
[753f9d2] | 130 | if (rHasGlobalOrdering_currRing()) |
---|
[35aab3] | 131 | { |
---|
| 132 | while ((i<j) && (!existsUnit)) |
---|
| 133 | { |
---|
| 134 | existsUnit = pVectorHasUnitB(syz->m[i],&ModComp); |
---|
| 135 | i++; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { |
---|
| 140 | int I=0; |
---|
| 141 | l = 0; |
---|
| 142 | len=0; |
---|
| 143 | for (i=0;i<IDELEMS(syz);i++) |
---|
| 144 | { |
---|
| 145 | if (syz->m[i]!=NULL) |
---|
| 146 | { |
---|
| 147 | pVectorHasUnit(syz->m[i],&m, &l); |
---|
| 148 | if ((len==0) ||((l>0) && (l<len))) |
---|
| 149 | { |
---|
| 150 | len = l; |
---|
| 151 | ModComp = m; |
---|
| 152 | I = i; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | //Print("Laenge ist: %d\n",len); |
---|
| 157 | if (len>0) existsUnit = TRUE; |
---|
| 158 | i = I+1; |
---|
| 159 | } |
---|
| 160 | if (existsUnit) |
---|
| 161 | { |
---|
| 162 | i--; |
---|
| 163 | //--takes out the founded syzygy-- |
---|
| 164 | if (TEST_OPT_PROT) PrintS("f"); |
---|
| 165 | actWith = syz->m[i]; |
---|
[3342df] | 166 | if (!rField_has_simple_inverse(currRing)) p_Cleardenom(actWith, currRing); |
---|
[35aab3] | 167 | //Print("actWith: ");pWrite(actWith); |
---|
| 168 | syz->m[i] = NULL; |
---|
| 169 | for (k=i;k<j-1;k++) syz->m[k] = syz->m[k+1]; |
---|
| 170 | syz->m[j-1] = NULL; |
---|
| 171 | syDeleteAbove(up,i); |
---|
| 172 | j--; |
---|
| 173 | //--makes Gauss alg. for the column ModComp-- |
---|
| 174 | Unit1 = pTakeOutComp(&(actWith), ModComp); |
---|
| 175 | //PrintS("actWith now: ");pWrite(actWith); |
---|
| 176 | //Print("Unit1: ");pWrite(Unit1); |
---|
| 177 | k=0; |
---|
| 178 | //Print("j= %d",j); |
---|
| 179 | while (k<j) |
---|
| 180 | { |
---|
| 181 | if (syz->m[k]!=NULL) |
---|
| 182 | { |
---|
| 183 | Unit2 = pTakeOutComp(&(syz->m[k]), ModComp); |
---|
| 184 | //Print("element %d: ",k);pWrite(syz->m[k]); |
---|
| 185 | //PrintS("Unit2: ");pWrite(Unit2); |
---|
[8049ad] | 186 | syz->m[k] = pMult(pCopy(Unit1),syz->m[k]); |
---|
[35aab3] | 187 | syz->m[k] = pSub(syz->m[k], |
---|
| 188 | pMult(Unit2,pCopy(actWith))); |
---|
| 189 | if (syz->m[k]==NULL) |
---|
| 190 | { |
---|
| 191 | for (l=k;l<j-1;l++) |
---|
| 192 | syz->m[l] = syz->m[l+1]; |
---|
| 193 | syz->m[j-1] = NULL; |
---|
| 194 | j--; |
---|
| 195 | syDeleteAbove(up,k); |
---|
| 196 | k--; |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | k++; |
---|
| 200 | } |
---|
| 201 | pDelete(&actWith); |
---|
| 202 | pDelete(&Unit1); |
---|
| 203 | //--deletes superfluous elements from the module below--- |
---|
| 204 | pDelete(&(mod->m[ModComp-1 - curr_syz_limit])); |
---|
| 205 | for (k=ModComp-1 - curr_syz_limit;k<IDELEMS(mod)-1;k++) |
---|
| 206 | mod->m[k] = mod->m[k+1]; |
---|
| 207 | mod->m[IDELEMS(mod)-1] = NULL; |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | searchUnit = FALSE; |
---|
| 211 | } |
---|
| 212 | if (TEST_OPT_PROT) PrintLn(); |
---|
| 213 | idSkipZeroes(mod); |
---|
| 214 | idSkipZeroes(syz); |
---|
| 215 | if (deg0!=NULL) |
---|
| 216 | idDelete(°0); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | /*2 |
---|
| 220 | * make Gauss with the element elnum in the module component ModComp |
---|
| 221 | * for the generators from - till |
---|
| 222 | */ |
---|
| 223 | void syGaussForOne(ideal syz, int elnum, int ModComp,int from,int till) |
---|
| 224 | { |
---|
[6909cfb] | 225 | int /*k,j,i,*/lu; |
---|
[35aab3] | 226 | poly unit1,unit2; |
---|
| 227 | poly actWith=syz->m[elnum]; |
---|
| 228 | |
---|
| 229 | if (from<0) from = 0; |
---|
| 230 | if ((till<=0) || (till>IDELEMS(syz))) till = IDELEMS(syz); |
---|
| 231 | syz->m[elnum] = NULL; |
---|
[3342df] | 232 | if (!rField_has_simple_inverse(currRing)) p_Cleardenom(actWith, currRing); |
---|
[35aab3] | 233 | /*--makes Gauss alg. for the column ModComp--*/ |
---|
| 234 | pTakeOutComp(&(actWith), ModComp, &unit1, &lu); |
---|
| 235 | while (from<till) |
---|
| 236 | { |
---|
[3705d5c] | 237 | poly tmp=syz->m[from]; |
---|
| 238 | if (/*syz->m[from]*/ tmp!=NULL) |
---|
[35aab3] | 239 | { |
---|
[3705d5c] | 240 | pTakeOutComp(&(tmp), ModComp, &unit2, &lu); |
---|
| 241 | tmp = pMult(pCopy(unit1),tmp); |
---|
| 242 | syz->m[from] = pSub(tmp, |
---|
[b6201e] | 243 | pMult(unit2,pCopy(actWith))); |
---|
[35aab3] | 244 | } |
---|
| 245 | from++; |
---|
| 246 | } |
---|
| 247 | pDelete(&actWith); |
---|
| 248 | pDelete(&unit1); |
---|
| 249 | } |
---|
| 250 | static void syDeleteAbove1(ideal up, int k) |
---|
| 251 | { |
---|
[6909cfb] | 252 | poly p/*,pp*/; |
---|
[35aab3] | 253 | if (up!=NULL) |
---|
| 254 | { |
---|
| 255 | for (int i=0;i<IDELEMS(up);i++) |
---|
| 256 | { |
---|
| 257 | p = up->m[i]; |
---|
| 258 | while ((p!=NULL) && (pGetComp(p)==k)) |
---|
| 259 | { |
---|
[fe3266] | 260 | /* |
---|
[35aab3] | 261 | pp = pNext(p); |
---|
| 262 | pNext(p) = NULL; |
---|
| 263 | pDelete(&p); |
---|
| 264 | p = pp; |
---|
[fe3266] | 265 | */ |
---|
| 266 | pLmDelete(&p); |
---|
[35aab3] | 267 | } |
---|
| 268 | up->m[i] = p; |
---|
| 269 | if (p!=NULL) |
---|
| 270 | { |
---|
| 271 | while (pNext(p)!=NULL) |
---|
| 272 | { |
---|
| 273 | if (pGetComp(pNext(p))==k) |
---|
| 274 | { |
---|
[fe3266] | 275 | /* |
---|
[35aab3] | 276 | pp = pNext(pNext(p)); |
---|
| 277 | pNext(pNext(p)) = NULL; |
---|
| 278 | pDelete(&pNext(p)); |
---|
| 279 | pNext(p) = pp; |
---|
[fe3266] | 280 | */ |
---|
| 281 | pLmDelete(&pNext(p)); |
---|
[35aab3] | 282 | } |
---|
| 283 | else |
---|
| 284 | pIter(p); |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | /*2 |
---|
| 291 | *minimizes the resolution res |
---|
| 292 | *assumes homogeneous or local case |
---|
| 293 | */ |
---|
| 294 | static void syMinStep1(resolvente res, int length) |
---|
| 295 | { |
---|
[d30a399] | 296 | int i,j,k,index=0; |
---|
[35aab3] | 297 | poly p; |
---|
| 298 | ideal deg0=NULL,reddeg0=NULL; |
---|
| 299 | intvec *have_del=NULL,*to_del=NULL; |
---|
| 300 | |
---|
| 301 | while ((index<length) && (res[index]!=NULL)) |
---|
| 302 | { |
---|
| 303 | /*---we take out dependend elements from syz---------------------*/ |
---|
| 304 | if (res[index+1]!=NULL) |
---|
| 305 | { |
---|
[e511e0] | 306 | deg0 = id_Jet(res[index+1],0,currRing); |
---|
[e7c6b22] | 307 | reddeg0 = kInterRedOld(deg0); |
---|
[35aab3] | 308 | idDelete(°0); |
---|
| 309 | have_del = new intvec(IDELEMS(res[index])); |
---|
| 310 | for (i=0;i<IDELEMS(reddeg0);i++) |
---|
| 311 | { |
---|
| 312 | if (reddeg0->m[i]!=NULL) |
---|
| 313 | { |
---|
| 314 | j = pGetComp(reddeg0->m[i]); |
---|
| 315 | pDelete(&(res[index]->m[j-1])); |
---|
[fe3266] | 316 | /*res[index]->m[j-1] = NULL;*/ |
---|
[35aab3] | 317 | (*have_del)[j-1] = 1; |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | idDelete(&reddeg0); |
---|
| 321 | } |
---|
| 322 | if (index>0) |
---|
| 323 | { |
---|
| 324 | /*--- we search for units and perform Gaussian elimination------*/ |
---|
| 325 | j = to_del->length(); |
---|
| 326 | while (j>0) |
---|
| 327 | { |
---|
| 328 | if ((*to_del)[j-1]==1) |
---|
| 329 | { |
---|
| 330 | k = 0; |
---|
| 331 | while (k<IDELEMS(res[index])) |
---|
| 332 | { |
---|
| 333 | p = res[index]->m[k]; |
---|
[0338ae9] | 334 | while ((p!=NULL) && ((!pLmIsConstantComp(p)) || (pGetComp(p)!=j))) |
---|
[35aab3] | 335 | pIter(p); |
---|
[0338ae9] | 336 | if ((p!=NULL) && (pLmIsConstantComp(p)) && (pGetComp(p)==j)) break; |
---|
[35aab3] | 337 | k++; |
---|
| 338 | } |
---|
| 339 | if (k>=IDELEMS(res[index])) |
---|
| 340 | { |
---|
| 341 | PrintS("out of range\n"); |
---|
| 342 | } |
---|
| 343 | syGaussForOne(res[index],k,j); |
---|
| 344 | if (res[index+1]!=NULL) |
---|
| 345 | syDeleteAbove1(res[index+1],k+1); |
---|
| 346 | (*to_del)[j-1] = 0; |
---|
| 347 | } |
---|
| 348 | j--; |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | if (to_del!=NULL) delete to_del; |
---|
| 352 | to_del = have_del; |
---|
| 353 | have_del = NULL; |
---|
| 354 | index++; |
---|
| 355 | } |
---|
| 356 | if (TEST_OPT_PROT) PrintLn(); |
---|
| 357 | syKillEmptyEntres(res,length); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | void syMinimizeResolvente(resolvente res, int length, int first) |
---|
| 361 | { |
---|
| 362 | int syzIndex=first; |
---|
| 363 | intvec *dummy; |
---|
| 364 | |
---|
| 365 | if (syzIndex<1) syzIndex=1; |
---|
[ac00e2f] | 366 | if ((syzIndex==1) && (idHomModule(res[0],currRing->qideal,&dummy)) && (!rIsPluralRing(currRing))) |
---|
[35aab3] | 367 | { |
---|
| 368 | syMinStep1(res,length); |
---|
| 369 | delete dummy; |
---|
| 370 | return; |
---|
| 371 | } |
---|
| 372 | while ((syzIndex<length-1) && (res[syzIndex]!=NULL) && (res[syzIndex+1]!=NULL)) |
---|
| 373 | { |
---|
| 374 | syMinStep(res[syzIndex-1],res[syzIndex],FALSE,res[syzIndex+1]); |
---|
| 375 | syzIndex++; |
---|
| 376 | } |
---|
| 377 | if (res[syzIndex]!=NULL) |
---|
| 378 | syMinStep(res[syzIndex-1],res[syzIndex]); |
---|
| 379 | if (!idIs0(res[0])) |
---|
| 380 | idMinEmbedding(res[0],TRUE); |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | /*2 |
---|
| 384 | * resolution of ideal/module arg, <=maxlength steps, (r[0..maxlength]) |
---|
| 385 | * no limitation in length if maxlength==0 |
---|
| 386 | * input:arg |
---|
| 387 | * minim: TRUE means mres cmd, FALSE nres cmd. |
---|
| 388 | * if *len!=0: module weights: weights[0] |
---|
| 389 | * (and weights is defined:weights[0..len-1] |
---|
| 390 | * |
---|
| 391 | * output:resolvente r[0..length-1], |
---|
| 392 | * module weights: weights[0..length-1] |
---|
| 393 | */ |
---|
| 394 | resolvente syResolvente(ideal arg, int maxlength, int * length, |
---|
| 395 | intvec *** weights, BOOLEAN minim) |
---|
| 396 | { |
---|
[d30a399] | 397 | BITSET save1; |
---|
| 398 | SI_SAVE_OPT1(save1); |
---|
[35aab3] | 399 | resolvente res; |
---|
| 400 | resolvente newres; |
---|
| 401 | tHomog hom=isNotHomog; |
---|
| 402 | ideal temp=NULL; |
---|
| 403 | intvec *w = NULL,**tempW; |
---|
[7b25fe] | 404 | int i,k,syzIndex = 0,j,rk_arg=si_max(1,(int)id_RankFreeModule(arg,currRing)); |
---|
[35aab3] | 405 | int Kstd1_OldDeg=Kstd1_deg; |
---|
| 406 | BOOLEAN completeMinim; |
---|
| 407 | BOOLEAN oldDegBound=TEST_OPT_DEGBOUND; |
---|
| 408 | BOOLEAN setRegularity=TRUE; |
---|
| 409 | int wlength=*length; |
---|
| 410 | |
---|
| 411 | if (maxlength!=-1) *length = maxlength+1; |
---|
| 412 | else *length = 5; |
---|
| 413 | if ((wlength!=0) && (*length!=wlength)) |
---|
| 414 | { |
---|
| 415 | intvec **wtmp = (intvec**)omAlloc0((*length)*sizeof(intvec*)); |
---|
| 416 | wtmp[0]=(*weights)[0]; |
---|
| 417 | omFreeSize((ADDRESS)*weights,wlength*sizeof(intvec*)); |
---|
| 418 | *weights=wtmp; |
---|
| 419 | } |
---|
| 420 | res = (resolvente)omAlloc0((*length)*sizeof(ideal)); |
---|
| 421 | |
---|
| 422 | /*--- initialize the syzygy-ring -----------------------------*/ |
---|
| 423 | ring origR = currRing; |
---|
[7e53d9] | 424 | ring syz_ring = rAssure_SyzComp(origR, TRUE); // will do rChangeCurrRing if needed |
---|
[23c7a8] | 425 | rSetSyzComp(rk_arg, syz_ring); |
---|
[35aab3] | 426 | |
---|
| 427 | if (syz_ring != origR) |
---|
| 428 | { |
---|
[1b420fd] | 429 | rChangeCurrRing(syz_ring); |
---|
| 430 | res[0] = idrCopyR_NoSort(arg, origR, syz_ring); |
---|
[35aab3] | 431 | } |
---|
| 432 | else |
---|
| 433 | { |
---|
| 434 | res[0] = idCopy(arg); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | /*--- creating weights for the module components ---------------*/ |
---|
[a63c24] | 438 | if ((weights!=NULL) && (*weights!=NULL)&& ((*weights)[0]!=NULL)) |
---|
| 439 | { |
---|
[ac00e2f] | 440 | if (!idTestHomModule(res[0],currRing->qideal,(*weights)[0])) |
---|
[a63c24] | 441 | { |
---|
[e6a019] | 442 | WarnS("wrong weights given(1):"); (*weights)[0]->show();PrintLn(); |
---|
[ac00e2f] | 443 | idHomModule(res[0],currRing->qideal,&w); |
---|
[a63c24] | 444 | w->show();PrintLn(); |
---|
| 445 | *weights=NULL; |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | |
---|
[35aab3] | 449 | if ((weights==NULL) || (*weights==NULL) || ((*weights)[0]==NULL)) |
---|
| 450 | { |
---|
[ac00e2f] | 451 | hom=(tHomog)idHomModule(res[0],currRing->qideal,&w); |
---|
[35aab3] | 452 | if (hom==isHomog) |
---|
| 453 | { |
---|
| 454 | *weights = (intvec**)omAlloc0((*length)*sizeof(intvec*)); |
---|
| 455 | if (w!=NULL) (*weights)[0] = ivCopy(w); |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | else |
---|
| 459 | { |
---|
| 460 | if ((weights!=NULL) && (*weights!=NULL)&& ((*weights)[0]!=NULL)) |
---|
| 461 | { |
---|
| 462 | w = ivCopy((*weights)[0]); |
---|
| 463 | hom = isHomog; |
---|
| 464 | } |
---|
| 465 | } |
---|
[b1dfaf] | 466 | |
---|
| 467 | #ifdef HAVE_PLURAL |
---|
[d07546] | 468 | if (rIsPluralRing(currRing) && !rIsSCA(currRing) ) |
---|
[750e70] | 469 | { |
---|
[d07546] | 470 | // quick solution; need theory to apply homog GB stuff for G-Algebras |
---|
| 471 | hom = isNotHomog; |
---|
| 472 | } |
---|
[b1dfaf] | 473 | #endif // HAVE_PLURAL |
---|
| 474 | |
---|
[35aab3] | 475 | if (hom==isHomog) |
---|
| 476 | { |
---|
| 477 | intvec *w1 = syPrepareModComp(res[0],&w); |
---|
| 478 | if (w!=NULL) { delete w;w=NULL; } |
---|
| 479 | w = w1; |
---|
| 480 | j = 0; |
---|
| 481 | while ((j<IDELEMS(res[0])) && (res[0]->m[j]==NULL)) j++; |
---|
| 482 | if (j<IDELEMS(res[0])) |
---|
| 483 | { |
---|
[b50590] | 484 | if (p_FDeg(res[0]->m[j],currRing)!=pTotaldegree(res[0]->m[j])) |
---|
[35aab3] | 485 | setRegularity = FALSE; |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | else |
---|
| 489 | { |
---|
| 490 | setRegularity = FALSE; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | /*--- the main loop --------------------------------------*/ |
---|
[9e8bfa] | 494 | while ((res[syzIndex]!=NULL) && (!idIs0(res[syzIndex])) && |
---|
[35aab3] | 495 | ((maxlength==-1) || (syzIndex<=maxlength))) |
---|
| 496 | // (syzIndex<maxlength+(int)minim))) |
---|
| 497 | /*--- compute one step more for minimizing-----------------*/ |
---|
| 498 | { |
---|
| 499 | if (Kstd1_deg!=0) Kstd1_deg++; |
---|
| 500 | if (syzIndex+1==*length) |
---|
| 501 | { |
---|
| 502 | newres = (resolvente)omAlloc0((*length+5)*sizeof(ideal)); |
---|
| 503 | tempW = (intvec**)omAlloc0((*length+5)*sizeof(intvec*)); |
---|
| 504 | for (j=0;j<*length;j++) |
---|
| 505 | { |
---|
| 506 | newres[j] = res[j]; |
---|
| 507 | if (*weights!=NULL) tempW[j] = (*weights)[j]; |
---|
| 508 | /*else tempW[j] = NULL;*/ |
---|
| 509 | } |
---|
| 510 | omFreeSize((ADDRESS)res,*length*sizeof(ideal)); |
---|
| 511 | if (*weights != NULL) omFreeSize((ADDRESS)*weights,*length*sizeof(intvec*)); |
---|
| 512 | *length += 5; |
---|
| 513 | res=newres; |
---|
| 514 | *weights = tempW; |
---|
| 515 | } |
---|
| 516 | /*--- interreducing first -----------------------------------*/ |
---|
| 517 | if (syzIndex>0) |
---|
| 518 | { |
---|
[7b25fe] | 519 | int rkI=id_RankFreeModule(res[syzIndex],currRing); |
---|
[23c7a8] | 520 | rSetSyzComp(rkI, currRing); |
---|
[35aab3] | 521 | } |
---|
[750e70] | 522 | if(! TEST_OPT_NO_SYZ_MINIM ) |
---|
[35aab3] | 523 | if (minim || (syzIndex!=0)) |
---|
| 524 | { |
---|
[ac00e2f] | 525 | temp = kInterRedOld(res[syzIndex],currRing->qideal); |
---|
[35aab3] | 526 | idDelete(&res[syzIndex]); |
---|
| 527 | idSkipZeroes(temp); |
---|
| 528 | res[syzIndex] = temp; |
---|
| 529 | } |
---|
| 530 | temp = NULL; |
---|
| 531 | /*--- computing the syzygy modules --------------------------------*/ |
---|
[ac00e2f] | 532 | if ((currRing->qideal==NULL)&&(syzIndex==0)&& (!TEST_OPT_DEGBOUND)) |
---|
[35aab3] | 533 | { |
---|
| 534 | res[/*syzIndex+*/1] = idSyzygies(res[0/*syzIndex*/],hom,&w,FALSE,setRegularity,&Kstd1_deg); |
---|
[7069f2] | 535 | if ((!TEST_OPT_NOTREGULARITY) && (Kstd1_deg>0) |
---|
| 536 | #ifdef HAVE_RINGS |
---|
[2505ad] | 537 | && (!rField_is_Ring(currRing)) |
---|
[7069f2] | 538 | #endif |
---|
| 539 | ) si_opt_1 |= Sy_bit(OPT_DEGBOUND); |
---|
[35aab3] | 540 | } |
---|
| 541 | else |
---|
| 542 | { |
---|
| 543 | res[syzIndex+1] = idSyzygies(res[syzIndex],hom,&w,FALSE); |
---|
| 544 | } |
---|
| 545 | completeMinim=(syzIndex!=maxlength) || (maxlength ==-1) || (hom!=isHomog); |
---|
| 546 | syzIndex++; |
---|
| 547 | if (TEST_OPT_PROT) Print("[%d]\n",syzIndex); |
---|
[750e70] | 548 | |
---|
| 549 | if(! TEST_OPT_NO_SYZ_MINIM ) |
---|
[35aab3] | 550 | { |
---|
[750e70] | 551 | if ((minim)||(syzIndex>1)) |
---|
| 552 | syMinStep(res[syzIndex-1],res[syzIndex],!completeMinim,NULL,hom); |
---|
| 553 | if (!completeMinim) |
---|
| 554 | /*minim is TRUE, we are in the module: maxlength, maxlength <>0*/ |
---|
| 555 | { |
---|
| 556 | idDelete(&res[syzIndex]); |
---|
| 557 | } |
---|
[35aab3] | 558 | } |
---|
| 559 | /*---creating the iterated weights for module components ---------*/ |
---|
[9e8bfa] | 560 | if ((hom == isHomog) && (res[syzIndex]!=NULL) && (!idIs0(res[syzIndex]))) |
---|
[35aab3] | 561 | { |
---|
| 562 | //Print("die %d Modulegewichte sind:\n",w1->length()); |
---|
| 563 | //w1->show(); |
---|
| 564 | //PrintLn(); |
---|
[7b25fe] | 565 | int max_comp = id_RankFreeModule(res[syzIndex],currRing); |
---|
[b50590] | 566 | k = max_comp - rGetCurrSyzLimit(currRing); |
---|
[35aab3] | 567 | assume(w != NULL); |
---|
| 568 | if (w != NULL) |
---|
| 569 | w->resize(max_comp+IDELEMS(res[syzIndex])); |
---|
| 570 | else |
---|
| 571 | w = new intvec(max_comp+IDELEMS(res[syzIndex])); |
---|
| 572 | (*weights)[syzIndex] = new intvec(k); |
---|
| 573 | for (i=0;i<k;i++) |
---|
| 574 | { |
---|
| 575 | if (res[syzIndex-1]->m[i]!=NULL) // hs |
---|
| 576 | { |
---|
[b50590] | 577 | (*w)[i + rGetCurrSyzLimit(currRing)] = p_FDeg(res[syzIndex-1]->m[i],currRing); |
---|
[35aab3] | 578 | if (pGetComp(res[syzIndex-1]->m[i])>0) |
---|
[b50590] | 579 | (*w)[i + rGetCurrSyzLimit(currRing)] |
---|
[35aab3] | 580 | += (*w)[pGetComp(res[syzIndex-1]->m[i])-1]; |
---|
[b50590] | 581 | (*((*weights)[syzIndex]))[i] = (*w)[i+rGetCurrSyzLimit(currRing)]; |
---|
[35aab3] | 582 | } |
---|
| 583 | } |
---|
| 584 | for (i=k;i<k+IDELEMS(res[syzIndex]);i++) |
---|
| 585 | { |
---|
| 586 | if (res[syzIndex]->m[i-k]!=NULL) |
---|
[b50590] | 587 | (*w)[i+rGetCurrSyzLimit(currRing)] = p_FDeg(res[syzIndex]->m[i-k],currRing) |
---|
[35aab3] | 588 | +(*w)[pGetComp(res[syzIndex]->m[i-k])-1]; |
---|
| 589 | } |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | /*--- end of the main loop --------------------------------------*/ |
---|
| 593 | /*--- deleting the temporare data structures --------------------*/ |
---|
| 594 | if ((syzIndex!=0) && (res[syzIndex]!=NULL) && (idIs0(res[syzIndex]))) |
---|
| 595 | idDelete(&res[syzIndex]); |
---|
| 596 | if (w !=NULL) delete w; |
---|
| 597 | |
---|
| 598 | Kstd1_deg=Kstd1_OldDeg; |
---|
| 599 | if (!oldDegBound) |
---|
[d30a399] | 600 | si_opt_1 &= ~Sy_bit(OPT_DEGBOUND); |
---|
[35aab3] | 601 | |
---|
| 602 | for (i=1; i<=syzIndex; i++) |
---|
| 603 | { |
---|
[9e8bfa] | 604 | if ((res[i]!=NULL) && ! idIs0(res[i])) |
---|
[35aab3] | 605 | { |
---|
[741464] | 606 | id_Shift(res[i],-rGetMaxSyzComp(i, currRing),currRing); |
---|
[35aab3] | 607 | } |
---|
| 608 | } |
---|
| 609 | /*--- going back to the original ring -------------------------*/ |
---|
| 610 | if (origR != syz_ring) |
---|
| 611 | { |
---|
[1b420fd] | 612 | rChangeCurrRing(origR); // should not be needed now? |
---|
[35aab3] | 613 | for (i=0; i<=syzIndex; i++) |
---|
| 614 | { |
---|
[1b420fd] | 615 | res[i] = idrMoveR_NoSort(res[i], syz_ring, origR); |
---|
[35aab3] | 616 | } |
---|
[5fe834] | 617 | rDelete(syz_ring); |
---|
[35aab3] | 618 | } |
---|
[d30a399] | 619 | SI_RESTORE_OPT1(save1); |
---|
[35aab3] | 620 | return res; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | syStrategy syResolution(ideal arg, int maxlength,intvec * w, BOOLEAN minim) |
---|
| 624 | { |
---|
[8b09ef] | 625 | |
---|
[90adb6a] | 626 | #ifdef HAVE_PLURAL |
---|
[8b09ef] | 627 | |
---|
[57bfa2] | 628 | const ideal idSaveCurrRingQuotient = currRing->qideal; |
---|
[8b09ef] | 629 | |
---|
[90adb6a] | 630 | if( rIsSCA(currRing) ) |
---|
| 631 | { |
---|
[e65ce5] | 632 | |
---|
| 633 | #ifdef RDEBUG |
---|
| 634 | // rWrite(currRing); |
---|
| 635 | // rDebugPrint(currRing); |
---|
| 636 | #endif |
---|
[8b09ef] | 637 | |
---|
[57bfa2] | 638 | if( ncExtensions(TESTSYZSCAMASK) ) |
---|
| 639 | { |
---|
[ac00e2f] | 640 | currRing->qideal = SCAQuotient(currRing); |
---|
[57bfa2] | 641 | } |
---|
[90adb6a] | 642 | |
---|
| 643 | const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing); |
---|
| 644 | const unsigned int m_iLastAltVar = scaLastAltVar(currRing); |
---|
[750e70] | 645 | |
---|
[e2efe91] | 646 | arg = id_KillSquares(arg, m_iFirstAltVar, m_iLastAltVar, currRing, false); // kill suares in input! |
---|
[90adb6a] | 647 | } |
---|
| 648 | #endif |
---|
[750e70] | 649 | |
---|
[35aab3] | 650 | syStrategy result=(syStrategy)omAlloc0(sizeof(ssyStrategy)); |
---|
| 651 | |
---|
[ac00e2f] | 652 | if ((w!=NULL) && (!idTestHomModule(arg,currRing->qideal,w))) // is this right in SCA case??? |
---|
[a63c24] | 653 | { |
---|
[e6a019] | 654 | WarnS("wrong weights given(2):");w->show();PrintLn(); |
---|
[ac00e2f] | 655 | idHomModule(arg,currRing->qideal,&w); |
---|
[a63c24] | 656 | w->show();PrintLn(); |
---|
| 657 | w=NULL; |
---|
| 658 | } |
---|
[35aab3] | 659 | if (w!=NULL) |
---|
| 660 | { |
---|
[835d83] | 661 | result->weights = (intvec**)omAlloc0Bin(char_ptr_bin); |
---|
[35aab3] | 662 | (result->weights)[0] = ivCopy(w); |
---|
| 663 | result->length = 1; |
---|
| 664 | } |
---|
| 665 | resolvente fr = syResolvente(arg,maxlength,&(result->length),&(result->weights),minim),fr1; |
---|
| 666 | if (minim) |
---|
| 667 | { |
---|
| 668 | result->minres = (resolvente)omAlloc0((result->length+1)*sizeof(ideal)); |
---|
| 669 | fr1 = result->minres; |
---|
| 670 | } |
---|
| 671 | else |
---|
| 672 | { |
---|
| 673 | result->fullres = (resolvente)omAlloc0((result->length+1)*sizeof(ideal)); |
---|
| 674 | fr1 = result->fullres; |
---|
| 675 | } |
---|
| 676 | for (int i=result->length-1;i>=0;i--) |
---|
| 677 | { |
---|
| 678 | if (fr[i]!=NULL) |
---|
| 679 | fr1[i] = fr[i]; |
---|
| 680 | fr[i] = NULL; |
---|
| 681 | } |
---|
| 682 | omFreeSize((ADDRESS)fr,(result->length)*sizeof(ideal)); |
---|
[90adb6a] | 683 | |
---|
| 684 | |
---|
| 685 | #ifdef HAVE_PLURAL |
---|
| 686 | if( rIsSCA(currRing) ) |
---|
| 687 | { |
---|
[8b09ef] | 688 | |
---|
[57bfa2] | 689 | if( ncExtensions(TESTSYZSCAMASK) ) |
---|
| 690 | { |
---|
| 691 | currRing->qideal = idSaveCurrRingQuotient; |
---|
| 692 | } |
---|
[90adb6a] | 693 | |
---|
| 694 | id_Delete(&arg, currRing); |
---|
| 695 | } |
---|
| 696 | #endif |
---|
| 697 | |
---|
| 698 | |
---|
[35aab3] | 699 | return result; |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | static poly sypCopyConstant(poly inp) |
---|
| 703 | { |
---|
| 704 | poly outp=NULL,q; |
---|
| 705 | |
---|
| 706 | while (inp!=NULL) |
---|
| 707 | { |
---|
| 708 | if (pLmIsConstantComp(inp)) |
---|
| 709 | { |
---|
| 710 | if (outp==NULL) |
---|
| 711 | { |
---|
| 712 | q = outp = pHead(inp); |
---|
| 713 | } |
---|
| 714 | else |
---|
| 715 | { |
---|
| 716 | pNext(q) = pHead(inp); |
---|
| 717 | pIter(q); |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | pIter(inp); |
---|
| 721 | } |
---|
| 722 | return outp; |
---|
| 723 | } |
---|
| 724 | int syDetect(ideal id,int index,BOOLEAN homog,int * degrees,int * tocancel) |
---|
| 725 | { |
---|
[d30a399] | 726 | int i, j, k, subFromRank=0; |
---|
[35aab3] | 727 | ideal temp; |
---|
| 728 | |
---|
| 729 | if (idIs0(id)) return 0; |
---|
| 730 | temp = idInit(IDELEMS(id),id->rank); |
---|
| 731 | for (i=0;i<IDELEMS(id);i++) |
---|
| 732 | { |
---|
| 733 | temp->m[i] = sypCopyConstant(id->m[i]); |
---|
| 734 | } |
---|
| 735 | i = IDELEMS(id); |
---|
| 736 | while ((i>0) && (temp->m[i-1]==NULL)) i--; |
---|
| 737 | if (i==0) |
---|
| 738 | { |
---|
| 739 | idDelete(&temp); |
---|
| 740 | return 0; |
---|
| 741 | } |
---|
| 742 | j = 0; |
---|
| 743 | while ((j<i) && (temp->m[j]==NULL)) j++; |
---|
| 744 | while (j<i) |
---|
| 745 | { |
---|
| 746 | if (homog) |
---|
| 747 | { |
---|
[b50590] | 748 | if (index==0) k = p_FDeg(temp->m[j],currRing)+degrees[pGetComp(temp->m[j])]; |
---|
[b130fb] | 749 | else k = degrees[pGetComp(temp->m[j])]; |
---|
[35aab3] | 750 | if (k>=index) tocancel[k-index]++; |
---|
| 751 | if ((k>=0) && (index==0)) subFromRank++; |
---|
| 752 | } |
---|
| 753 | else |
---|
| 754 | { |
---|
| 755 | tocancel[0]--; |
---|
| 756 | } |
---|
| 757 | syGaussForOne(temp,j,pGetComp(temp->m[j]),j+1,i); |
---|
| 758 | j++; |
---|
| 759 | while ((j<i) && (temp->m[j]==NULL)) j++; |
---|
| 760 | } |
---|
| 761 | idDelete(&temp); |
---|
| 762 | return subFromRank; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | void syDetect(ideal id,int index,int rsmin, BOOLEAN homog, |
---|
| 766 | intvec * degrees,intvec * tocancel) |
---|
| 767 | { |
---|
| 768 | int * deg=NULL; |
---|
| 769 | int * tocan=(int*) omAlloc0(tocancel->length()*sizeof(int)); |
---|
| 770 | int i; |
---|
| 771 | |
---|
| 772 | if (homog) |
---|
| 773 | { |
---|
| 774 | deg = (int*) omAlloc0(degrees->length()*sizeof(int)); |
---|
| 775 | for (i=degrees->length();i>0;i--) |
---|
| 776 | deg[i-1] = (*degrees)[i-1]-rsmin; |
---|
| 777 | } |
---|
[d30a399] | 778 | syDetect(id,index,homog,deg,tocan); |
---|
[35aab3] | 779 | for (i=tocancel->length();i>0;i--) |
---|
| 780 | (*tocancel)[i-1] = tocan[i-1]; |
---|
| 781 | if (homog) |
---|
| 782 | omFreeSize((ADDRESS)deg,degrees->length()*sizeof(int)); |
---|
| 783 | omFreeSize((ADDRESS)tocan,tocancel->length()*sizeof(int)); |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | /*2 |
---|
| 787 | * computes the betti numbers from a given resolution |
---|
| 788 | * of length 'length' (0..length-1), not necessairily minimal, |
---|
| 789 | * (if weights are given, they are used) |
---|
| 790 | * returns the int matrix of betti numbers |
---|
| 791 | * and the regularity |
---|
| 792 | */ |
---|
| 793 | intvec * syBetti(resolvente res,int length, int * regularity, |
---|
| 794 | intvec* weights,BOOLEAN tomin,int * row_shift) |
---|
| 795 | { |
---|
| 796 | //#define BETTI_WITH_ZEROS |
---|
| 797 | //tomin = FALSE; |
---|
| 798 | int i,j=0,k=0,l,rows,cols,mr; |
---|
| 799 | int *temp1,*temp2,*temp3;/*used to compute degrees*/ |
---|
| 800 | int *tocancel; /*(BOOLEAN)tocancel[i]=element is superfluous*/ |
---|
| 801 | int r0_len; |
---|
| 802 | |
---|
| 803 | /*------ compute size --------------*/ |
---|
| 804 | *regularity = -1; |
---|
| 805 | cols = length; |
---|
| 806 | while ((cols>0) |
---|
| 807 | && ((res[cols-1]==NULL) |
---|
| 808 | || (idIs0(res[cols-1])))) |
---|
| 809 | { |
---|
| 810 | cols--; |
---|
| 811 | } |
---|
| 812 | intvec * result; |
---|
| 813 | if (idIs0(res[0])) |
---|
| 814 | { |
---|
| 815 | if (res[0]==NULL) |
---|
| 816 | result = new intvec(1,1,1); |
---|
| 817 | else |
---|
| 818 | result = new intvec(1,1,res[0]->rank); |
---|
| 819 | return result; |
---|
| 820 | } |
---|
| 821 | intvec *w=NULL; |
---|
[a63c24] | 822 | if (weights!=NULL) |
---|
| 823 | { |
---|
[ac00e2f] | 824 | if (!idTestHomModule(res[0],currRing->qideal,weights)) |
---|
[a63c24] | 825 | { |
---|
[e6a019] | 826 | WarnS("wrong weights given(3):");weights->show();PrintLn(); |
---|
[ac00e2f] | 827 | idHomModule(res[0],currRing->qideal,&w); |
---|
[a63c24] | 828 | if (w!=NULL) { w->show();PrintLn();} |
---|
| 829 | weights=NULL; |
---|
| 830 | } |
---|
| 831 | } |
---|
[8ebd1a0] | 832 | #if 0 |
---|
[ac00e2f] | 833 | if (idHomModule(res[0],currRing->qideal,&w)!=isHomog) |
---|
[8ebd1a0] | 834 | { |
---|
| 835 | Warn("betti-command: Input is not homogeneous!"); |
---|
| 836 | weights=NULL; |
---|
| 837 | } |
---|
| 838 | #endif |
---|
[a63c24] | 839 | if (weights==NULL) weights=w; |
---|
| 840 | else delete w; |
---|
| 841 | r0_len=IDELEMS(res[0]); |
---|
| 842 | while ((r0_len>0) && (res[0]->m[r0_len-1]==NULL)) r0_len--; |
---|
| 843 | #ifdef SHOW_W |
---|
[192b522] | 844 | PrintS("weights:");if (weights!=NULL) weights->show(); else Print("NULL"); PrintLn(); |
---|
[a63c24] | 845 | #endif |
---|
[7b25fe] | 846 | int rkl=l = si_max(id_RankFreeModule(res[0],currRing),res[0]->rank); |
---|
[35aab3] | 847 | i = 0; |
---|
| 848 | while ((i<length) && (res[i]!=NULL)) |
---|
| 849 | { |
---|
| 850 | if (IDELEMS(res[i])>l) l = IDELEMS(res[i]); |
---|
| 851 | i++; |
---|
| 852 | } |
---|
| 853 | temp1 = (int*)omAlloc0((l+1)*sizeof(int)); |
---|
| 854 | temp2 = (int*)omAlloc((l+1)*sizeof(int)); |
---|
| 855 | rows = 1; |
---|
| 856 | mr = 1; |
---|
| 857 | cols++; |
---|
| 858 | for (i=0;i<cols-1;i++) |
---|
| 859 | { |
---|
[b44f5e] | 860 | if ((i==0) && (weights!=NULL)) p_SetModDeg(weights, currRing); |
---|
[35aab3] | 861 | memset(temp2,0,(l+1)*sizeof(int)); |
---|
| 862 | for (j=0;j<IDELEMS(res[i]);j++) |
---|
| 863 | { |
---|
| 864 | if (res[i]->m[j]!=NULL) |
---|
| 865 | { |
---|
[0338ae9] | 866 | if ((pGetComp(res[i]->m[j])>l) |
---|
[1c1d660] | 867 | // usual resolutions do not the following, but artifulal built may: (tr. #763) |
---|
| 868 | //|| ((i>1) && (res[i-1]->m[pGetComp(res[i]->m[j])-1]==NULL)) |
---|
| 869 | ) |
---|
[35aab3] | 870 | { |
---|
| 871 | WerrorS("input not a resolvent"); |
---|
| 872 | omFreeSize((ADDRESS)temp1,(l+1)*sizeof(int)); |
---|
| 873 | omFreeSize((ADDRESS)temp2,(l+1)*sizeof(int)); |
---|
| 874 | return NULL; |
---|
| 875 | } |
---|
[b50590] | 876 | temp2[j+1] = p_FDeg(res[i]->m[j],currRing)+temp1[pGetComp(res[i]->m[j])]; |
---|
[35aab3] | 877 | if (temp2[j+1]-i>rows) rows = temp2[j+1]-i; |
---|
| 878 | if (temp2[j+1]-i<mr) mr = temp2[j+1]-i; |
---|
| 879 | } |
---|
| 880 | } |
---|
[b44f5e] | 881 | if ((i==0) && (weights!=NULL)) p_SetModDeg(NULL, currRing); |
---|
[35aab3] | 882 | temp3 = temp1; |
---|
| 883 | temp1 = temp2; |
---|
| 884 | temp2 = temp3; |
---|
| 885 | } |
---|
| 886 | mr--; |
---|
[3e1bc9] | 887 | if (weights!=NULL) |
---|
| 888 | { |
---|
| 889 | for(j=0;j<weights->length();j++) |
---|
| 890 | { |
---|
| 891 | if (rows <(*weights)[j]+1) rows=(-mr)+(*weights)[j]+1; |
---|
| 892 | } |
---|
| 893 | } |
---|
[35aab3] | 894 | /*------ computation betti numbers --------------*/ |
---|
| 895 | rows -= mr; |
---|
[a63c24] | 896 | result = new intvec(rows+1,cols,0); |
---|
| 897 | if (weights!=NULL) |
---|
| 898 | { |
---|
| 899 | for(j=0;j<weights->length();j++) |
---|
| 900 | { |
---|
| 901 | IMATELEM((*result),(-mr)+(*weights)[j]+1,1) ++; |
---|
[192b522] | 902 | //Print("imat(%d,%d)++ -> %d\n",(-mr)+(*weights)[j]+1, 1, IMATELEM((*result),(-mr)+(*weights)[j]+1,1)); |
---|
[a63c24] | 903 | } |
---|
| 904 | } |
---|
| 905 | else |
---|
| 906 | { |
---|
| 907 | (*result)[(-mr)*cols] = /*idRankFreeModule(res[0])*/ rkl; |
---|
| 908 | if ((!idIs0(res[0])) && ((*result)[(-mr)*cols]==0)) |
---|
| 909 | (*result)[(-mr)*cols] = 1; |
---|
| 910 | } |
---|
[35aab3] | 911 | tocancel = (int*)omAlloc0((rows+1)*sizeof(int)); |
---|
| 912 | memset(temp1,0,(l+1)*sizeof(int)); |
---|
[a63c24] | 913 | if (weights!=NULL) |
---|
| 914 | { |
---|
| 915 | memset(temp2,0,l*sizeof(int)); |
---|
[b44f5e] | 916 | p_SetModDeg(weights, currRing); |
---|
[a63c24] | 917 | } |
---|
| 918 | else |
---|
| 919 | memset(temp2,0,l*sizeof(int)); |
---|
[d30a399] | 920 | syDetect(res[0],0,TRUE,temp2,tocancel); |
---|
[b44f5e] | 921 | if (weights!=NULL) p_SetModDeg(NULL, currRing); |
---|
[35aab3] | 922 | if (tomin) |
---|
[a63c24] | 923 | { |
---|
| 924 | //(*result)[(-mr)*cols] -= dummy; |
---|
| 925 | for(j=0;j<=rows+mr;j++) |
---|
| 926 | { |
---|
[192b522] | 927 | //Print("tocancel[%d]=%d imat(%d,%d)=%d\n",j,tocancel[j],(-mr)+j+1,1,IMATELEM((*result),(-mr)+j+1,1)); |
---|
[a63c24] | 928 | IMATELEM((*result),(-mr)+j+1,1) -= tocancel[j]; |
---|
| 929 | } |
---|
| 930 | } |
---|
[35aab3] | 931 | for (i=0;i<cols-1;i++) |
---|
| 932 | { |
---|
[b44f5e] | 933 | if ((i==0) && (weights!=NULL)) p_SetModDeg(weights, currRing); |
---|
[35aab3] | 934 | memset(temp2,0,l*sizeof(int)); |
---|
| 935 | for (j=0;j<IDELEMS(res[i]);j++) |
---|
| 936 | { |
---|
| 937 | if (res[i]->m[j]!=NULL) |
---|
| 938 | { |
---|
[b50590] | 939 | temp2[j+1] = p_FDeg(res[i]->m[j],currRing)+temp1[pGetComp(res[i]->m[j])]; |
---|
[35aab3] | 940 | //(*result)[i+1+(temp2[j+1]-i-1)*cols]++; |
---|
| 941 | //if (temp2[j+1]>i) IMATELEM((*result),temp2[j+1]-i-mr,i+2)++; |
---|
| 942 | IMATELEM((*result),temp2[j+1]-i-mr,i+2)++; |
---|
| 943 | } |
---|
| 944 | else if (i==0) |
---|
| 945 | { |
---|
| 946 | if (j<r0_len) IMATELEM((*result),-mr,2)++; |
---|
| 947 | } |
---|
| 948 | } |
---|
| 949 | /*------ computation betti numbers, if res not minimal --------------*/ |
---|
| 950 | if (tomin) |
---|
| 951 | { |
---|
| 952 | for (j=mr;j<rows+mr;j++) |
---|
| 953 | { |
---|
| 954 | //(*result)[i+1+j*cols] -= tocancel[j+1]; |
---|
| 955 | IMATELEM((*result),j+1-mr,i+2) -= tocancel[j+1]; |
---|
| 956 | } |
---|
| 957 | if ((i<length-1) && (res[i+1]!=NULL)) |
---|
| 958 | { |
---|
| 959 | memset(tocancel,0,(rows+1)*sizeof(int)); |
---|
[d30a399] | 960 | syDetect(res[i+1],i+1,TRUE,temp2,tocancel); |
---|
[35aab3] | 961 | for (j=0;j<rows;j++) |
---|
| 962 | { |
---|
| 963 | //(*result)[i+1+j*cols] -= tocancel[j]; |
---|
| 964 | IMATELEM((*result),j+1,i+2) -= tocancel[j]; |
---|
| 965 | } |
---|
| 966 | } |
---|
| 967 | } |
---|
| 968 | temp3 = temp1; |
---|
| 969 | temp1 = temp2; |
---|
| 970 | temp2 = temp3; |
---|
[a63c24] | 971 | for (j=0;j<=rows;j++) |
---|
[35aab3] | 972 | { |
---|
| 973 | // if (((*result)[i+1+j*cols]!=0) && (j>*regularity)) *regularity = j; |
---|
| 974 | if ((IMATELEM((*result),j+1,i+2)!=0) && (j>*regularity)) *regularity = j; |
---|
| 975 | } |
---|
[b44f5e] | 976 | if ((i==0) && (weights!=NULL)) p_SetModDeg(NULL, currRing); |
---|
[35aab3] | 977 | } |
---|
[a63c24] | 978 | // Print("nach minim:\n"); result->show(); PrintLn(); |
---|
[35aab3] | 979 | /*------ clean up --------------*/ |
---|
| 980 | omFreeSize((ADDRESS)tocancel,(rows+1)*sizeof(int)); |
---|
| 981 | omFreeSize((ADDRESS)temp1,(l+1)*sizeof(int)); |
---|
| 982 | omFreeSize((ADDRESS)temp2,(l+1)*sizeof(int)); |
---|
| 983 | if ((tomin) && (mr<0)) // deletes the first (zero) line |
---|
| 984 | { |
---|
[a63c24] | 985 | for (j=1;j<=rows+mr+1;j++) |
---|
[35aab3] | 986 | { |
---|
| 987 | for (k=1;k<=cols;k++) |
---|
| 988 | { |
---|
| 989 | IMATELEM((*result),j,k) = IMATELEM((*result),j-mr,k); |
---|
| 990 | } |
---|
| 991 | } |
---|
[a63c24] | 992 | for (j=rows+mr+1;j<=rows+1;j++) |
---|
[35aab3] | 993 | { |
---|
| 994 | for (k=1;k<=cols;k++) |
---|
| 995 | { |
---|
| 996 | IMATELEM((*result),j,k) = 0; |
---|
| 997 | } |
---|
| 998 | } |
---|
| 999 | } |
---|
| 1000 | j = 0; |
---|
| 1001 | k = 0; |
---|
[a63c24] | 1002 | for (i=1;i<=result->rows();i++) |
---|
[35aab3] | 1003 | { |
---|
[a63c24] | 1004 | for(l=1;l<=result->cols();l++) |
---|
| 1005 | if (IMATELEM((*result),i,l) != 0) |
---|
[35aab3] | 1006 | { |
---|
[a63c24] | 1007 | j = si_max(j, i-1); |
---|
| 1008 | k = si_max(k, l-1); |
---|
[35aab3] | 1009 | } |
---|
| 1010 | } |
---|
| 1011 | intvec * exactresult=new intvec(j+1,k+1,0); |
---|
| 1012 | for (i=0;i<exactresult->rows();i++) |
---|
| 1013 | { |
---|
| 1014 | for (j=0;j<exactresult->cols();j++) |
---|
| 1015 | { |
---|
| 1016 | IMATELEM(*exactresult,i+1,j+1) = IMATELEM(*result,i+1,j+1); |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | if (row_shift!=NULL) *row_shift = mr; |
---|
| 1020 | delete result; |
---|
| 1021 | return exactresult; |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | /*2 |
---|
| 1025 | * minbare via syzygies |
---|
| 1026 | */ |
---|
| 1027 | ideal syMinBase(ideal arg) |
---|
| 1028 | { |
---|
| 1029 | intvec ** weights=NULL; |
---|
| 1030 | int leng; |
---|
| 1031 | if (idIs0(arg)) return idInit(1,arg->rank); |
---|
| 1032 | resolvente res=syResolvente(arg,1,&leng,&weights,TRUE); |
---|
| 1033 | ideal result=res[0]; |
---|
| 1034 | omFreeSize((ADDRESS)res,leng*sizeof(ideal)); |
---|
| 1035 | if (weights!=NULL) |
---|
| 1036 | { |
---|
| 1037 | if (*weights!=NULL) |
---|
| 1038 | { |
---|
| 1039 | delete (*weights); |
---|
| 1040 | *weights=NULL; |
---|
| 1041 | } |
---|
| 1042 | if ((leng>=1) && (*(weights+1)!=NULL)) |
---|
| 1043 | { |
---|
| 1044 | delete *(weights+1); |
---|
| 1045 | *(weights+1)=NULL; |
---|
| 1046 | } |
---|
| 1047 | } |
---|
| 1048 | idSkipZeroes(result); |
---|
| 1049 | return result; |
---|
| 1050 | } |
---|
| 1051 | |
---|
[f815bd7] | 1052 | #if 0 /* currently used: syBetti */ |
---|
[35aab3] | 1053 | /*2 |
---|
| 1054 | * computes Betti-numbers from a resolvente of |
---|
| 1055 | * (non-)homogeneous objects |
---|
| 1056 | * the numbers of entrees !=NULL in res and weights must be equal |
---|
| 1057 | * and < length |
---|
| 1058 | */ |
---|
| 1059 | intvec * syNewBetti(resolvente res, intvec ** weights, int length) |
---|
| 1060 | { |
---|
| 1061 | intvec * result,*tocancel; |
---|
| 1062 | int i,j,k,rsmin=0,rsmax=0,rs=0; |
---|
| 1063 | BOOLEAN homog=TRUE; |
---|
| 1064 | |
---|
| 1065 | if (weights!=NULL) //---homogeneous Betti numbers |
---|
| 1066 | { |
---|
| 1067 | /*--------------computes size of the field----------------------*/ |
---|
| 1068 | for (i=1;i<length;i++) |
---|
| 1069 | { |
---|
| 1070 | if (weights[i] != NULL) |
---|
| 1071 | { |
---|
| 1072 | for (j=1;j<(weights[i])->length();j++) |
---|
| 1073 | { |
---|
| 1074 | if ((*(weights[i]))[j]-i<rsmin) rsmin = (*(weights[i]))[j]-i; |
---|
| 1075 | if ((*(weights[i]))[j]-i>rsmax) rsmax = (*(weights[i]))[j]-i; |
---|
| 1076 | } |
---|
| 1077 | } |
---|
| 1078 | } |
---|
| 1079 | i = 0; |
---|
| 1080 | while (weights[i] != NULL) i++; |
---|
| 1081 | i--; |
---|
| 1082 | for (j=0;j<IDELEMS(res[i]);j++) |
---|
| 1083 | { |
---|
| 1084 | if (res[i]->m[j]!=NULL) |
---|
| 1085 | { |
---|
[b50590] | 1086 | k = p_FDeg(res[i]->m[j],currRing)+(*(weights[i]))[pGetComp(res[i]->m[j])]-i-1; |
---|
[35aab3] | 1087 | if (k>rsmax) rsmax = k; |
---|
| 1088 | if (k<rsmin) rsmin = k; |
---|
| 1089 | } |
---|
| 1090 | } |
---|
| 1091 | for (j=1;j<(weights[0])->length();j++) |
---|
| 1092 | { |
---|
| 1093 | if ((*weights[0])[j]>rsmax) rsmax = (*weights[0])[j]; |
---|
| 1094 | if ((*weights[0])[j]<rsmin) rsmin = (*weights[0])[j]; |
---|
| 1095 | } |
---|
| 1096 | //Print("rsmax = %d\n",rsmax); |
---|
| 1097 | //Print("rsmin = %d\n",rsmin); |
---|
| 1098 | rs = rsmax-rsmin+1; |
---|
| 1099 | result = new intvec(rs,i+2,0); |
---|
| 1100 | tocancel = new intvec(rs); |
---|
| 1101 | /*-----------enter the Betti numbers-------------------------------*/ |
---|
| 1102 | if (/*idRankFreeModule(res[0])*/ res[0]->rank==0) |
---|
| 1103 | { |
---|
| 1104 | IMATELEM(*result,1-rsmin,1)=1; |
---|
| 1105 | } |
---|
| 1106 | else |
---|
| 1107 | { |
---|
| 1108 | for (i=1;i<(weights[0])->length();i++) |
---|
| 1109 | IMATELEM(*result,(*weights[0])[i]+1-rsmin,1)++; |
---|
| 1110 | } |
---|
| 1111 | i = 1; |
---|
| 1112 | while (weights[i]!=NULL) |
---|
| 1113 | { |
---|
| 1114 | for (j=1;j<(weights[i])->length();j++) |
---|
| 1115 | { |
---|
| 1116 | IMATELEM(*result,(*(weights[i]))[j]-i+1-rsmin,i+1)++; |
---|
| 1117 | } |
---|
| 1118 | i++; |
---|
| 1119 | } |
---|
| 1120 | i--; |
---|
| 1121 | for (j=0;j<IDELEMS(res[i]);j++) |
---|
| 1122 | { |
---|
| 1123 | if (res[i]->m[j]!=NULL) |
---|
| 1124 | { |
---|
[b50590] | 1125 | k = p_FDeg(res[i]->m[j],currRing)+(*(weights[i]))[pGetComp(res[i]->m[j])]-i; |
---|
[35aab3] | 1126 | IMATELEM(*result,k-rsmin,i+2)++; |
---|
| 1127 | } |
---|
| 1128 | } |
---|
| 1129 | } |
---|
| 1130 | else //-----the non-homgeneous case |
---|
| 1131 | { |
---|
| 1132 | homog = FALSE; |
---|
| 1133 | tocancel = new intvec(1); |
---|
| 1134 | k = length; |
---|
| 1135 | while ((k>0) && (idIs0(res[k-1]))) k--; |
---|
| 1136 | result = new intvec(1,k+1,0); |
---|
| 1137 | (*result)[0] = res[0]->rank; |
---|
| 1138 | for (i=0;i<length;i++) |
---|
| 1139 | { |
---|
| 1140 | if (res[i]!=NULL) |
---|
| 1141 | { |
---|
| 1142 | for (j=0;j<IDELEMS(res[i]);j++) |
---|
| 1143 | { |
---|
| 1144 | if (res[i]->m[j]!=NULL) (*result)[i+1]++; |
---|
| 1145 | } |
---|
| 1146 | } |
---|
| 1147 | } |
---|
| 1148 | } |
---|
| 1149 | /*--------computes the Betti numbers for the minimized reolvente----*/ |
---|
| 1150 | |
---|
| 1151 | i = 1; |
---|
| 1152 | while ((res[i]!=NULL) && (weights[i]!=NULL)) |
---|
| 1153 | { |
---|
| 1154 | syDetect(res[i],i,rsmin,homog,weights[i],tocancel); |
---|
| 1155 | if (homog) |
---|
| 1156 | { |
---|
| 1157 | for (j=0;j<rs-1;j++) |
---|
| 1158 | { |
---|
| 1159 | IMATELEM((*result),j+1,i+1) -= (*tocancel)[j]; |
---|
| 1160 | IMATELEM((*result),j+1,i+2) -= (*tocancel)[j+1]; |
---|
| 1161 | } |
---|
| 1162 | IMATELEM((*result),rs,i+1) -= (*tocancel)[rs-1]; |
---|
| 1163 | } |
---|
| 1164 | else |
---|
| 1165 | { |
---|
| 1166 | (*result)[i+1] -= (*tocancel)[0]; |
---|
| 1167 | (*result)[i+2] -= (*tocancel)[0]; |
---|
| 1168 | } |
---|
| 1169 | i++; |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | /*--------print Betti numbers for control---------------------------*/ |
---|
| 1173 | for(i=rsmin;i<=rsmax;i++) |
---|
| 1174 | { |
---|
| 1175 | Print("%2d:",i); |
---|
| 1176 | for(j=1;j<=result->cols();j++) |
---|
| 1177 | { |
---|
| 1178 | Print(" %5d",IMATELEM(*result,i-rsmin+1,j)); |
---|
| 1179 | } |
---|
| 1180 | PrintLn(); |
---|
| 1181 | } |
---|
| 1182 | return result; |
---|
| 1183 | } |
---|
[f815bd7] | 1184 | #endif |
---|
| 1185 | |
---|