[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[cbc7e3] | 4 | /* $Id: ideals.cc,v 1.44 2007-06-13 15:01:50 Singular Exp $ */ |
---|
[35aab3] | 5 | /* |
---|
| 6 | * ABSTRACT - all basic methods to manipulate ideals |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* includes */ |
---|
| 10 | #include "mod2.h" |
---|
| 11 | #include "structs.h" |
---|
| 12 | #include "omalloc.h" |
---|
| 13 | #include "febase.h" |
---|
| 14 | #include "numbers.h" |
---|
[bba835] | 15 | #include "longrat.h" |
---|
[35aab3] | 16 | #include "polys.h" |
---|
| 17 | #include "ring.h" |
---|
| 18 | #include "kstd1.h" |
---|
| 19 | #include "matpol.h" |
---|
| 20 | #include "weight.h" |
---|
| 21 | #include "intvec.h" |
---|
| 22 | #include "syz.h" |
---|
| 23 | #include "sparsmat.h" |
---|
| 24 | #include "ideals.h" |
---|
| 25 | #include "prCopy.h" |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | /* #define WITH_OLD_MINOR */ |
---|
| 29 | #define pCopy_noCheck(p) pCopy(p) |
---|
| 30 | |
---|
| 31 | static poly * idpower; |
---|
| 32 | /*collects the monomials in makemonoms, must be allocated befor*/ |
---|
| 33 | static int idpowerpoint; |
---|
| 34 | /*index of the actual monomial in idpower*/ |
---|
| 35 | static poly * givenideal; |
---|
| 36 | /*the ideal from which a power is computed*/ |
---|
| 37 | |
---|
| 38 | /*0 implementation*/ |
---|
| 39 | |
---|
| 40 | /*2 |
---|
| 41 | * initialise an ideal |
---|
| 42 | */ |
---|
| 43 | #ifdef PDEBUG |
---|
| 44 | ideal idDBInit(int idsize, int rank, char *f, int l) |
---|
| 45 | #else |
---|
| 46 | ideal idInit(int idsize, int rank) |
---|
| 47 | #endif |
---|
| 48 | { |
---|
| 49 | /*- initialise an ideal -*/ |
---|
| 50 | ideal hh = (ideal )omAllocBin(sip_sideal_bin); |
---|
| 51 | hh->nrows = 1; |
---|
| 52 | hh->rank = rank; |
---|
| 53 | IDELEMS(hh) = idsize; |
---|
| 54 | if (idsize>0) |
---|
| 55 | { |
---|
| 56 | hh->m = (poly *)omAlloc0(idsize*sizeof(poly)); |
---|
| 57 | } |
---|
| 58 | else |
---|
| 59 | hh->m=NULL; |
---|
| 60 | return hh; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | //#ifndef __OPTIMIZE__ |
---|
| 64 | // this is mainly for outputting an ideal within the debugger |
---|
| 65 | void idShow(ideal id) |
---|
| 66 | { |
---|
| 67 | Print("Module of rank %d,real rank %d and %d generators.\n", |
---|
| 68 | id->rank,idRankFreeModule(id),IDELEMS(id)); |
---|
| 69 | for (int i=0;i<id->ncols*id->nrows;i++) |
---|
| 70 | { |
---|
| 71 | if (id->m[i]!=NULL) |
---|
| 72 | { |
---|
| 73 | Print("generator %d: ",i);pWrite(id->m[i]); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | //#endif |
---|
| 78 | |
---|
| 79 | /*2 |
---|
| 80 | * initialise the maximal ideal (at 0) |
---|
| 81 | */ |
---|
| 82 | ideal idMaxIdeal (void) |
---|
| 83 | { |
---|
| 84 | int l; |
---|
| 85 | ideal hh=NULL; |
---|
| 86 | |
---|
| 87 | hh=idInit(pVariables,1); |
---|
| 88 | for (l=0; l<pVariables; l++) |
---|
| 89 | { |
---|
| 90 | hh->m[l] = pOne(); |
---|
| 91 | pSetExp(hh->m[l],l+1,1); |
---|
| 92 | pSetm(hh->m[l]); |
---|
| 93 | } |
---|
| 94 | return hh; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /*2 |
---|
| 98 | * deletes an ideal/matrix |
---|
| 99 | */ |
---|
| 100 | void id_Delete (ideal * h, ring r) |
---|
| 101 | { |
---|
| 102 | int j,elems; |
---|
| 103 | if (*h == NULL) |
---|
| 104 | return; |
---|
| 105 | elems=j=(*h)->nrows*(*h)->ncols; |
---|
| 106 | if (j>0) |
---|
| 107 | { |
---|
| 108 | do |
---|
| 109 | { |
---|
| 110 | p_Delete(&((*h)->m[--j]), r); |
---|
| 111 | } |
---|
| 112 | while (j>0); |
---|
| 113 | omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems); |
---|
| 114 | } |
---|
| 115 | omFreeBin((ADDRESS)*h, sip_sideal_bin); |
---|
| 116 | *h=NULL; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | /*2 |
---|
| 121 | * Shallowdeletes an ideal/matrix |
---|
| 122 | */ |
---|
| 123 | void id_ShallowDelete (ideal *h, ring r) |
---|
| 124 | { |
---|
| 125 | int j,elems; |
---|
| 126 | if (*h == NULL) |
---|
| 127 | return; |
---|
| 128 | elems=j=(*h)->nrows*(*h)->ncols; |
---|
| 129 | if (j>0) |
---|
| 130 | { |
---|
| 131 | do |
---|
| 132 | { |
---|
| 133 | p_ShallowDelete(&((*h)->m[--j]), r); |
---|
| 134 | } |
---|
| 135 | while (j>0); |
---|
| 136 | omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems); |
---|
| 137 | } |
---|
| 138 | omFreeBin((ADDRESS)*h, sip_sideal_bin); |
---|
| 139 | *h=NULL; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /*2 |
---|
| 143 | *gives an ideal the minimal possible size |
---|
| 144 | */ |
---|
| 145 | void idSkipZeroes (ideal ide) |
---|
| 146 | { |
---|
| 147 | int k; |
---|
| 148 | int j = -1; |
---|
| 149 | BOOLEAN change=FALSE; |
---|
| 150 | for (k=0; k<IDELEMS(ide); k++) |
---|
| 151 | { |
---|
| 152 | if (ide->m[k] != NULL) |
---|
| 153 | { |
---|
| 154 | j++; |
---|
| 155 | if (change) |
---|
| 156 | { |
---|
| 157 | ide->m[j] = ide->m[k]; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | else |
---|
| 161 | { |
---|
| 162 | change=TRUE; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | if (change) |
---|
| 166 | { |
---|
| 167 | if (j == -1) |
---|
| 168 | j = 0; |
---|
| 169 | else |
---|
| 170 | { |
---|
| 171 | for (k=j+1; k<IDELEMS(ide); k++) |
---|
| 172 | ide->m[k] = NULL; |
---|
| 173 | } |
---|
| 174 | pEnlargeSet(&(ide->m),IDELEMS(ide),j+1-IDELEMS(ide)); |
---|
| 175 | IDELEMS(ide) = j+1; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | /*2 |
---|
| 180 | * ideal id = (id[i]) |
---|
| 181 | * result is leadcoeff(id[i]) = 1 |
---|
| 182 | */ |
---|
| 183 | void idNorm(ideal id) |
---|
| 184 | { |
---|
[699567] | 185 | for (int i=IDELEMS(id)-1; i>=0; i--) |
---|
[35aab3] | 186 | { |
---|
| 187 | if (id->m[i] != NULL) |
---|
| 188 | { |
---|
| 189 | pNorm(id->m[i]); |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /*2 |
---|
| 195 | * ideal id = (id[i]), c any number |
---|
| 196 | * if id[i] = c*id[j] then id[j] is deleted for j > i |
---|
| 197 | */ |
---|
| 198 | void idDelMultiples(ideal id) |
---|
| 199 | { |
---|
[699567] | 200 | int i, j; |
---|
| 201 | int k = IDELEMS(id)-1; |
---|
| 202 | for (i=k; i>=0; i--) |
---|
[35aab3] | 203 | { |
---|
| 204 | if (id->m[i]!=NULL) |
---|
| 205 | { |
---|
[699567] | 206 | for (j=k; j>i; j--) |
---|
[35aab3] | 207 | { |
---|
[699567] | 208 | if ((id->m[j]!=NULL) |
---|
| 209 | && (pComparePolys(id->m[i], id->m[j]))) |
---|
[35aab3] | 210 | { |
---|
[699567] | 211 | pDelete(&id->m[j]); |
---|
[35aab3] | 212 | } |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /*2 |
---|
| 219 | * ideal id = (id[i]) |
---|
| 220 | * if id[i] = id[j] then id[j] is deleted for j > i |
---|
| 221 | */ |
---|
| 222 | void idDelEquals(ideal id) |
---|
| 223 | { |
---|
[7ac29f] | 224 | int i, j; |
---|
| 225 | int k = IDELEMS(id)-1; |
---|
| 226 | for (i=k; i>=0; i--) |
---|
[35aab3] | 227 | { |
---|
[7ac29f] | 228 | if (id->m[i]!=NULL) |
---|
[35aab3] | 229 | { |
---|
[7ac29f] | 230 | for (j=k; j>i; j--) |
---|
[35aab3] | 231 | { |
---|
[7ac29f] | 232 | if ((id->m[j]!=NULL) |
---|
| 233 | && (pEqualPolys(id->m[i], id->m[j]))) |
---|
| 234 | { |
---|
| 235 | pDelete(&id->m[j]); |
---|
| 236 | } |
---|
[35aab3] | 237 | } |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | // |
---|
| 243 | // Delete id[j], if Lm(j) == Lm(i) and j > i |
---|
| 244 | // |
---|
| 245 | void idDelLmEquals(ideal id) |
---|
| 246 | { |
---|
[7ac29f] | 247 | int i, j; |
---|
| 248 | int k = IDELEMS(id)-1; |
---|
| 249 | for (i=k; i>=0; i--) |
---|
[35aab3] | 250 | { |
---|
[73df93] | 251 | if (id->m[i] != NULL) |
---|
[35aab3] | 252 | { |
---|
[7ac29f] | 253 | for (j=k; j>i; j--) |
---|
[35aab3] | 254 | { |
---|
[7ac29f] | 255 | if ((id->m[j] != NULL) |
---|
[73df93] | 256 | && pLmEqual(id->m[i], id->m[j])) |
---|
[35aab3] | 257 | { |
---|
[73df93] | 258 | pDelete(&id->m[j]); |
---|
[35aab3] | 259 | } |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | void idDelDiv(ideal id) |
---|
| 266 | { |
---|
[7ac29f] | 267 | int i, j; |
---|
| 268 | int k = IDELEMS(id)-1; |
---|
| 269 | for (i=k; i>=0; i--) |
---|
[35aab3] | 270 | { |
---|
[73df93] | 271 | if (id->m[i] != NULL) |
---|
[35aab3] | 272 | { |
---|
[7ac29f] | 273 | for (j=k; j>i; j--) |
---|
[35aab3] | 274 | { |
---|
[7ac29f] | 275 | if (id->m[j]!=NULL) |
---|
[35aab3] | 276 | { |
---|
[7ac29f] | 277 | if(pDivisibleBy(id->m[i], id->m[j])) |
---|
| 278 | { |
---|
| 279 | pDelete(&id->m[j]); |
---|
| 280 | } |
---|
| 281 | else if(pDivisibleBy(id->m[j], id->m[i])) |
---|
| 282 | { |
---|
| 283 | pDelete(&id->m[i]); |
---|
| 284 | break; |
---|
| 285 | } |
---|
[35aab3] | 286 | } |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | /*2 |
---|
| 293 | *test if the ideal has only constant polynomials |
---|
| 294 | */ |
---|
| 295 | BOOLEAN idIsConstant(ideal id) |
---|
| 296 | { |
---|
| 297 | int k; |
---|
| 298 | for (k = IDELEMS(id)-1; k>=0; k--) |
---|
| 299 | { |
---|
| 300 | if (pIsConstantPoly(id->m[k]) == FALSE) |
---|
| 301 | return FALSE; |
---|
| 302 | } |
---|
| 303 | return TRUE; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | /*2 |
---|
| 307 | * copy an ideal |
---|
| 308 | */ |
---|
| 309 | #ifdef PDEBUG |
---|
| 310 | ideal idDBCopy(ideal h1,char *f,int l) |
---|
| 311 | { |
---|
| 312 | int i; |
---|
| 313 | ideal h2; |
---|
| 314 | |
---|
| 315 | idDBTest(h1,PDEBUG,f,l); |
---|
| 316 | //#ifdef TEST |
---|
| 317 | if (h1 == NULL) |
---|
| 318 | { |
---|
| 319 | h2=idDBInit(1,1,f,l); |
---|
| 320 | } |
---|
| 321 | else |
---|
| 322 | //#endif |
---|
| 323 | { |
---|
| 324 | h2=idDBInit(IDELEMS(h1),h1->rank,f,l); |
---|
| 325 | for (i=IDELEMS(h1)-1; i>=0; i--) |
---|
| 326 | h2->m[i] = pCopy(h1->m[i]); |
---|
| 327 | } |
---|
| 328 | return h2; |
---|
| 329 | } |
---|
[d523f3] | 330 | #endif |
---|
| 331 | |
---|
| 332 | ideal id_Copy (ideal h1, const ring r) |
---|
| 333 | { |
---|
| 334 | int i; |
---|
| 335 | ideal h2; |
---|
| 336 | |
---|
| 337 | //#ifdef TEST |
---|
| 338 | if (h1 == NULL) |
---|
| 339 | { |
---|
| 340 | h2=idInit(1,1); |
---|
| 341 | } |
---|
| 342 | else |
---|
| 343 | //#endif |
---|
| 344 | { |
---|
| 345 | h2=idInit(IDELEMS(h1),h1->rank); |
---|
| 346 | for (i=IDELEMS(h1)-1; i>=0; i--) |
---|
| 347 | h2->m[i] = p_Copy(h1->m[i],r); |
---|
| 348 | } |
---|
| 349 | return h2; |
---|
| 350 | } |
---|
[35aab3] | 351 | |
---|
| 352 | #ifdef PDEBUG |
---|
| 353 | void idDBTest(ideal h1, int level, char *f,int l) |
---|
| 354 | { |
---|
| 355 | int i; |
---|
| 356 | |
---|
| 357 | if (h1 != NULL) |
---|
| 358 | { |
---|
| 359 | // assume(IDELEMS(h1) > 0); for ideal/module, does not apply to matrix |
---|
| 360 | omCheckAddrSize(h1,sizeof(*h1)); |
---|
| 361 | omdebugAddrSize(h1->m,h1->ncols*h1->nrows*sizeof(poly)); |
---|
| 362 | /* to be able to test matrices: */ |
---|
| 363 | for (i=(h1->ncols*h1->nrows)-1; i>=0; i--) |
---|
| 364 | _p_Test(h1->m[i], currRing, level); |
---|
| 365 | int new_rk=idRankFreeModule(h1); |
---|
| 366 | if(new_rk > h1->rank) |
---|
| 367 | { |
---|
| 368 | dReportError("wrong rank %d (should be %d) in %s:%d\n", |
---|
| 369 | h1->rank, new_rk, f,l); |
---|
| 370 | omPrintAddrInfo(stderr, h1, " for ideal"); |
---|
| 371 | h1->rank=new_rk; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | #endif |
---|
| 376 | |
---|
| 377 | /*3 |
---|
| 378 | * for idSort: compare a and b revlex inclusive module comp. |
---|
| 379 | */ |
---|
| 380 | static int pComp_RevLex(poly a, poly b,BOOLEAN nolex) |
---|
| 381 | { |
---|
| 382 | if (b==NULL) return 1; |
---|
| 383 | if (a==NULL) return -1; |
---|
| 384 | |
---|
| 385 | if (nolex) return pLmCmp(a,b); |
---|
| 386 | int l=pVariables; |
---|
| 387 | while ((l>0) && (pGetExp(a,l)==pGetExp(b,l))) l--; |
---|
| 388 | if (l==0) |
---|
| 389 | { |
---|
| 390 | if (pGetComp(a)==pGetComp(b)) return 0; |
---|
| 391 | if (pGetComp(a)>pGetComp(b)) return 1; |
---|
| 392 | } |
---|
| 393 | else if (pGetExp(a,l)>pGetExp(b,l)) |
---|
| 394 | return 1; |
---|
| 395 | return -1; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | /*2 |
---|
| 399 | *sorts the ideal w.r.t. the actual ringordering |
---|
| 400 | *uses lex-ordering when nolex = FALSE |
---|
| 401 | */ |
---|
| 402 | intvec *idSort(ideal id,BOOLEAN nolex) |
---|
| 403 | { |
---|
| 404 | poly p,q; |
---|
| 405 | intvec * result = new intvec(IDELEMS(id)); |
---|
| 406 | int i, j, actpos=0, newpos, l; |
---|
| 407 | int diff, olddiff, lastcomp, newcomp; |
---|
| 408 | BOOLEAN notFound; |
---|
| 409 | |
---|
| 410 | for (i=0;i<IDELEMS(id);i++) |
---|
| 411 | { |
---|
| 412 | if (id->m[i]!=NULL) |
---|
| 413 | { |
---|
| 414 | notFound = TRUE; |
---|
| 415 | newpos = actpos / 2; |
---|
| 416 | diff = (actpos+1) / 2; |
---|
| 417 | diff = (diff+1) / 2; |
---|
| 418 | lastcomp = pComp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex); |
---|
| 419 | if (lastcomp<0) |
---|
| 420 | { |
---|
| 421 | newpos -= diff; |
---|
| 422 | } |
---|
| 423 | else if (lastcomp>0) |
---|
| 424 | { |
---|
| 425 | newpos += diff; |
---|
| 426 | } |
---|
| 427 | else |
---|
| 428 | { |
---|
| 429 | notFound = FALSE; |
---|
| 430 | } |
---|
| 431 | //while ((newpos>=0) && (newpos<actpos) && (notFound)) |
---|
| 432 | while (notFound && (newpos>=0) && (newpos<actpos)) |
---|
| 433 | { |
---|
| 434 | newcomp = pComp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex); |
---|
| 435 | olddiff = diff; |
---|
| 436 | if (diff>1) |
---|
| 437 | { |
---|
| 438 | diff = (diff+1) / 2; |
---|
| 439 | if ((newcomp==1) |
---|
| 440 | && (actpos-newpos>1) |
---|
| 441 | && (diff>1) |
---|
| 442 | && (newpos+diff>=actpos)) |
---|
| 443 | { |
---|
| 444 | diff = actpos-newpos-1; |
---|
| 445 | } |
---|
| 446 | else if ((newcomp==-1) |
---|
| 447 | && (diff>1) |
---|
| 448 | && (newpos<diff)) |
---|
| 449 | { |
---|
| 450 | diff = newpos; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | if (newcomp<0) |
---|
| 454 | { |
---|
| 455 | if ((olddiff==1) && (lastcomp>0)) |
---|
| 456 | notFound = FALSE; |
---|
| 457 | else |
---|
| 458 | newpos -= diff; |
---|
| 459 | } |
---|
| 460 | else if (newcomp>0) |
---|
| 461 | { |
---|
| 462 | if ((olddiff==1) && (lastcomp<0)) |
---|
| 463 | { |
---|
| 464 | notFound = FALSE; |
---|
| 465 | newpos++; |
---|
| 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
| 469 | newpos += diff; |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | else |
---|
| 473 | { |
---|
| 474 | notFound = FALSE; |
---|
| 475 | } |
---|
| 476 | lastcomp = newcomp; |
---|
| 477 | if (diff==0) notFound=FALSE; /*hs*/ |
---|
| 478 | } |
---|
| 479 | if (newpos<0) newpos = 0; |
---|
| 480 | if (newpos>actpos) newpos = actpos; |
---|
| 481 | while ((newpos<actpos) && (pComp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex)==0)) |
---|
| 482 | newpos++; |
---|
| 483 | for (j=actpos;j>newpos;j--) |
---|
| 484 | { |
---|
| 485 | (*result)[j] = (*result)[j-1]; |
---|
| 486 | } |
---|
| 487 | (*result)[newpos] = i; |
---|
| 488 | actpos++; |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | for (j=0;j<actpos;j++) (*result)[j]++; |
---|
| 492 | return result; |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | /*2 |
---|
| 496 | * concat the lists h1 and h2 without zeros |
---|
| 497 | */ |
---|
| 498 | ideal idSimpleAdd (ideal h1,ideal h2) |
---|
| 499 | { |
---|
| 500 | int i,j,r,l; |
---|
| 501 | ideal result; |
---|
| 502 | |
---|
| 503 | if (h1==NULL) return idCopy(h2); |
---|
| 504 | if (h2==NULL) return idCopy(h1); |
---|
| 505 | j = IDELEMS(h1)-1; |
---|
| 506 | while ((j >= 0) && (h1->m[j] == NULL)) j--; |
---|
| 507 | i = IDELEMS(h2)-1; |
---|
| 508 | while ((i >= 0) && (h2->m[i] == NULL)) i--; |
---|
| 509 | r = si_max(h1->rank,h2->rank); |
---|
| 510 | if (i+j==(-2)) |
---|
| 511 | return idInit(1,r); |
---|
| 512 | else |
---|
| 513 | result=idInit(i+j+2,r); |
---|
| 514 | for (l=j; l>=0; l--) |
---|
| 515 | { |
---|
| 516 | result->m[l] = pCopy(h1->m[l]); |
---|
| 517 | } |
---|
| 518 | r = i+j+1; |
---|
| 519 | for (l=i; l>=0; l--, r--) |
---|
| 520 | { |
---|
| 521 | result->m[r] = pCopy(h2->m[l]); |
---|
| 522 | } |
---|
| 523 | return result; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | /*2 |
---|
| 527 | * h1 + h2 |
---|
| 528 | */ |
---|
| 529 | ideal idAdd (ideal h1,ideal h2) |
---|
| 530 | { |
---|
| 531 | ideal result = idSimpleAdd(h1,h2); |
---|
[10ea45f] | 532 | idCompactify(result); |
---|
[35c62a9] | 533 | return result; |
---|
[35aab3] | 534 | } |
---|
| 535 | |
---|
| 536 | /*2 |
---|
| 537 | * h1 * h2 |
---|
| 538 | */ |
---|
| 539 | ideal idMult (ideal h1,ideal h2) |
---|
| 540 | { |
---|
| 541 | int i,j,k; |
---|
| 542 | ideal hh; |
---|
| 543 | |
---|
| 544 | j = IDELEMS(h1); |
---|
| 545 | while ((j > 0) && (h1->m[j-1] == NULL)) j--; |
---|
| 546 | i = IDELEMS(h2); |
---|
| 547 | while ((i > 0) && (h2->m[i-1] == NULL)) i--; |
---|
| 548 | j = j * i; |
---|
| 549 | if (j == 0) |
---|
| 550 | hh = idInit(1,1); |
---|
| 551 | else |
---|
| 552 | hh=idInit(j,1); |
---|
| 553 | if (h1->rank<h2->rank) |
---|
| 554 | hh->rank = h2->rank; |
---|
| 555 | else |
---|
| 556 | hh->rank = h1->rank; |
---|
| 557 | if (j==0) return hh; |
---|
| 558 | k = 0; |
---|
| 559 | for (i=0; i<IDELEMS(h1); i++) |
---|
| 560 | { |
---|
| 561 | if (h1->m[i] != NULL) |
---|
| 562 | { |
---|
| 563 | for (j=0; j<IDELEMS(h2); j++) |
---|
| 564 | { |
---|
| 565 | if (h2->m[j] != NULL) |
---|
| 566 | { |
---|
| 567 | hh->m[k] = ppMult_qq(h1->m[i],h2->m[j]); |
---|
| 568 | k++; |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | } |
---|
| 573 | { |
---|
[10ea45f] | 574 | idCompactify(hh); |
---|
| 575 | return hh; |
---|
[35aab3] | 576 | } |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | /*2 |
---|
| 580 | *returns true if h is the zero ideal |
---|
| 581 | */ |
---|
| 582 | BOOLEAN idIs0 (ideal h) |
---|
| 583 | { |
---|
| 584 | int i; |
---|
| 585 | |
---|
| 586 | if (h == NULL) return TRUE; |
---|
[9dd6270] | 587 | i = IDELEMS(h)-1; |
---|
| 588 | while ((i >= 0) && (h->m[i] == NULL)) |
---|
[35aab3] | 589 | { |
---|
| 590 | i--; |
---|
| 591 | } |
---|
[9dd6270] | 592 | if (i < 0) |
---|
[35aab3] | 593 | return TRUE; |
---|
| 594 | else |
---|
| 595 | return FALSE; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | /*2 |
---|
| 599 | * return the maximal component number found in any polynomial in s |
---|
| 600 | */ |
---|
| 601 | long idRankFreeModule (ideal s, ring lmRing, ring tailRing) |
---|
| 602 | { |
---|
| 603 | if (s!=NULL) |
---|
| 604 | { |
---|
| 605 | int j=0; |
---|
| 606 | |
---|
| 607 | if (rRing_has_Comp(tailRing) && rRing_has_Comp(lmRing)) |
---|
| 608 | { |
---|
| 609 | int l=IDELEMS(s); |
---|
| 610 | poly *p=s->m; |
---|
| 611 | int k; |
---|
| 612 | for (; l != 0; l--) |
---|
| 613 | { |
---|
| 614 | if (*p!=NULL) |
---|
| 615 | { |
---|
| 616 | pp_Test(*p, lmRing, tailRing); |
---|
| 617 | k = p_MaxComp(*p, lmRing, tailRing); |
---|
| 618 | if (k>j) j = k; |
---|
| 619 | } |
---|
| 620 | p++; |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | return j; |
---|
| 624 | } |
---|
| 625 | return -1; |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | BOOLEAN idIsModule(ideal id, ring r) |
---|
| 629 | { |
---|
| 630 | if (id != NULL && rRing_has_Comp(r)) |
---|
| 631 | { |
---|
| 632 | int j, l = IDELEMS(id); |
---|
| 633 | for (j=0; j<l; j++) |
---|
| 634 | { |
---|
| 635 | if (id->m[j] != NULL && p_GetComp(id->m[j], r) > 0) return TRUE; |
---|
| 636 | } |
---|
| 637 | } |
---|
| 638 | return FALSE; |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | /*2 |
---|
| 643 | *returns true if id is homogenous with respect to the aktual weights |
---|
| 644 | */ |
---|
| 645 | BOOLEAN idHomIdeal (ideal id, ideal Q) |
---|
| 646 | { |
---|
| 647 | int i; |
---|
| 648 | BOOLEAN b; |
---|
| 649 | if ((id == NULL) || (IDELEMS(id) == 0)) return TRUE; |
---|
| 650 | i = 0; |
---|
| 651 | b = TRUE; |
---|
| 652 | while ((i < IDELEMS(id)) && b) |
---|
| 653 | { |
---|
| 654 | b = pIsHomogeneous(id->m[i]); |
---|
| 655 | i++; |
---|
| 656 | } |
---|
| 657 | if ((b) && (Q!=NULL) && (IDELEMS(Q)>0)) |
---|
| 658 | { |
---|
| 659 | i=0; |
---|
| 660 | while ((i < IDELEMS(Q)) && b) |
---|
| 661 | { |
---|
| 662 | b = pIsHomogeneous(Q->m[i]); |
---|
| 663 | i++; |
---|
| 664 | } |
---|
| 665 | } |
---|
| 666 | return b; |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | /*2 |
---|
| 670 | *returns a minimized set of generators of h1 |
---|
| 671 | */ |
---|
| 672 | ideal idMinBase (ideal h1) |
---|
| 673 | { |
---|
| 674 | ideal h2, h3,h4,e; |
---|
| 675 | int j,k; |
---|
| 676 | int i,l,ll; |
---|
| 677 | intvec * wth; |
---|
| 678 | BOOLEAN homog; |
---|
| 679 | |
---|
| 680 | homog = idHomModule(h1,currQuotient,&wth); |
---|
| 681 | if ((currRing->OrdSgn == 1) && (!homog)) |
---|
| 682 | { |
---|
| 683 | Warn("minbase applies only to the local or homogeneous case"); |
---|
| 684 | e=idCopy(h1); |
---|
| 685 | return e; |
---|
| 686 | } |
---|
| 687 | if ((currRing->OrdSgn == 1) && (homog)) |
---|
| 688 | { |
---|
| 689 | ideal re=kMin_std(h1,currQuotient,(tHomog)homog,&wth,h2,NULL,0,3); |
---|
| 690 | idDelete(&re); |
---|
| 691 | return h2; |
---|
| 692 | } |
---|
| 693 | e=idInit(1,h1->rank); |
---|
| 694 | if (idIs0(h1)) |
---|
| 695 | { |
---|
| 696 | return e; |
---|
| 697 | } |
---|
| 698 | pEnlargeSet(&(e->m),IDELEMS(e),15); |
---|
| 699 | IDELEMS(e) = 16; |
---|
| 700 | h2 = kStd(h1,currQuotient,isNotHomog,NULL); |
---|
| 701 | h3 = idMaxIdeal(); |
---|
| 702 | h4=idMult(h2,h3); |
---|
| 703 | idDelete(&h3); |
---|
| 704 | h3=kStd(h4,currQuotient,isNotHomog,NULL); |
---|
| 705 | k = IDELEMS(h3); |
---|
| 706 | while ((k > 0) && (h3->m[k-1] == NULL)) k--; |
---|
| 707 | j = -1; |
---|
| 708 | l = IDELEMS(h2); |
---|
| 709 | while ((l > 0) && (h2->m[l-1] == NULL)) l--; |
---|
| 710 | for (i=l-1; i>=0; i--) |
---|
| 711 | { |
---|
| 712 | if (h2->m[i] != NULL) |
---|
| 713 | { |
---|
| 714 | ll = 0; |
---|
| 715 | while ((ll < k) && ((h3->m[ll] == NULL) |
---|
| 716 | || !pDivisibleBy(h3->m[ll],h2->m[i]))) |
---|
| 717 | ll++; |
---|
| 718 | if (ll >= k) |
---|
| 719 | { |
---|
| 720 | j++; |
---|
| 721 | if (j > IDELEMS(e)-1) |
---|
| 722 | { |
---|
| 723 | pEnlargeSet(&(e->m),IDELEMS(e),16); |
---|
| 724 | IDELEMS(e) += 16; |
---|
| 725 | } |
---|
| 726 | e->m[j] = pCopy(h2->m[i]); |
---|
| 727 | } |
---|
| 728 | } |
---|
| 729 | } |
---|
| 730 | idDelete(&h2); |
---|
| 731 | idDelete(&h3); |
---|
| 732 | idDelete(&h4); |
---|
| 733 | if (currQuotient!=NULL) |
---|
| 734 | { |
---|
| 735 | h3=idInit(1,e->rank); |
---|
| 736 | h2=kNF(h3,currQuotient,e); |
---|
| 737 | idDelete(&h3); |
---|
| 738 | idDelete(&e); |
---|
| 739 | e=h2; |
---|
| 740 | } |
---|
| 741 | idSkipZeroes(e); |
---|
| 742 | return e; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | /*2 |
---|
| 746 | *the minimal index of used variables - 1 |
---|
| 747 | */ |
---|
| 748 | int pLowVar (poly p) |
---|
| 749 | { |
---|
| 750 | int k,l,lex; |
---|
| 751 | |
---|
| 752 | if (p == NULL) return -1; |
---|
| 753 | |
---|
| 754 | k = 32000;/*a very large dummy value*/ |
---|
| 755 | while (p != NULL) |
---|
| 756 | { |
---|
| 757 | l = 1; |
---|
| 758 | lex = pGetExp(p,l); |
---|
| 759 | while ((l < pVariables) && (lex == 0)) |
---|
| 760 | { |
---|
| 761 | l++; |
---|
| 762 | lex = pGetExp(p,l); |
---|
| 763 | } |
---|
| 764 | l--; |
---|
| 765 | if (l < k) k = l; |
---|
| 766 | pIter(p); |
---|
| 767 | } |
---|
| 768 | return k; |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | /*3 |
---|
| 772 | *multiplies p with t (!cas) or (t-1) |
---|
| 773 | *the index of t is:1, so we have to shift all variables |
---|
| 774 | *p is NOT in the actual ring, it has no t |
---|
| 775 | */ |
---|
| 776 | static poly pMultWithT (poly p,BOOLEAN cas) |
---|
| 777 | { |
---|
| 778 | /*qp is the working pointer in p*/ |
---|
| 779 | /*result is the result, qresult is the working pointer*/ |
---|
| 780 | /*pp is p in the actual ring(shifted), qpp the working pointer*/ |
---|
| 781 | poly result,qp,pp; |
---|
| 782 | poly qresult=NULL; |
---|
| 783 | poly qpp=NULL; |
---|
| 784 | int i,j,lex; |
---|
| 785 | number n; |
---|
| 786 | |
---|
| 787 | pp = NULL; |
---|
| 788 | result = NULL; |
---|
| 789 | qp = p; |
---|
| 790 | while (qp != NULL) |
---|
| 791 | { |
---|
| 792 | i = 0; |
---|
| 793 | if (result == NULL) |
---|
| 794 | {/*first monomial*/ |
---|
| 795 | result = pInit(); |
---|
| 796 | qresult = result; |
---|
| 797 | } |
---|
| 798 | else |
---|
| 799 | { |
---|
| 800 | qresult->next = pInit(); |
---|
| 801 | pIter(qresult); |
---|
| 802 | } |
---|
| 803 | for (j=pVariables-1; j>0; j--) |
---|
| 804 | { |
---|
| 805 | lex = pGetExp(qp,j); |
---|
| 806 | pSetExp(qresult,j+1,lex);/*copy all variables*/ |
---|
| 807 | } |
---|
| 808 | lex = pGetComp(qp); |
---|
| 809 | pSetComp(qresult,lex); |
---|
| 810 | n=nCopy(pGetCoeff(qp)); |
---|
| 811 | pSetCoeff0(qresult,n); |
---|
| 812 | qresult->next = NULL; |
---|
| 813 | pSetm(qresult); |
---|
| 814 | /*qresult is now qp brought into the actual ring*/ |
---|
| 815 | if (cas) |
---|
| 816 | { /*case: mult with t-1*/ |
---|
| 817 | pSetExp(qresult,1,0); |
---|
| 818 | pSetm(qresult); |
---|
| 819 | if (pp == NULL) |
---|
| 820 | { /*first monomial*/ |
---|
| 821 | pp = pCopy(qresult); |
---|
| 822 | qpp = pp; |
---|
| 823 | } |
---|
| 824 | else |
---|
| 825 | { |
---|
| 826 | qpp->next = pCopy(qresult); |
---|
| 827 | pIter(qpp); |
---|
| 828 | } |
---|
| 829 | pGetCoeff(qpp)=nNeg(pGetCoeff(qpp)); |
---|
| 830 | /*now qpp contains -1*qp*/ |
---|
| 831 | } |
---|
| 832 | pSetExp(qresult,1,1);/*this is mult. by t*/ |
---|
| 833 | pSetm(qresult); |
---|
| 834 | pIter(qp); |
---|
| 835 | } |
---|
| 836 | /* |
---|
| 837 | *now p is processed: |
---|
| 838 | *result contains t*p |
---|
| 839 | * if cas: pp contains -1*p (in the new ring) |
---|
| 840 | */ |
---|
| 841 | if (cas) qresult->next = pp; |
---|
| 842 | /* else qresult->next = NULL;*/ |
---|
| 843 | return result; |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | /*2 |
---|
| 847 | *dehomogenized the generators of the ideal id1 with the leading |
---|
| 848 | *monomial of p replaced by n |
---|
| 849 | */ |
---|
| 850 | ideal idDehomogen (ideal id1,poly p,number n) |
---|
| 851 | { |
---|
| 852 | int i; |
---|
| 853 | ideal result; |
---|
| 854 | |
---|
| 855 | if (idIs0(id1)) |
---|
| 856 | { |
---|
| 857 | return idInit(1,id1->rank); |
---|
| 858 | } |
---|
| 859 | result=idInit(IDELEMS(id1),id1->rank); |
---|
| 860 | for (i=0; i<IDELEMS(id1); i++) |
---|
| 861 | { |
---|
| 862 | result->m[i] = pDehomogen(id1->m[i],p,n); |
---|
| 863 | } |
---|
| 864 | return result; |
---|
| 865 | } |
---|
| 866 | |
---|
| 867 | /*2 |
---|
| 868 | * verschiebt die Indizees der Modulerzeugenden um i |
---|
| 869 | */ |
---|
| 870 | void pShift (poly * p,int i) |
---|
| 871 | { |
---|
| 872 | poly qp1 = *p,qp2 = *p;/*working pointers*/ |
---|
| 873 | int j = pMaxComp(*p),k = pMinComp(*p); |
---|
| 874 | |
---|
| 875 | if (j+i < 0) return ; |
---|
| 876 | while (qp1 != NULL) |
---|
| 877 | { |
---|
| 878 | if ((pGetComp(qp1)+i > 0) || ((j == -i) && (j == k))) |
---|
| 879 | { |
---|
| 880 | pSetComp(qp1,pGetComp(qp1)+i); |
---|
| 881 | pSetmComp(qp1); |
---|
| 882 | qp2 = qp1; |
---|
| 883 | pIter(qp1); |
---|
| 884 | } |
---|
| 885 | else |
---|
| 886 | { |
---|
| 887 | if (qp2 == *p) |
---|
| 888 | { |
---|
| 889 | pIter(*p); |
---|
| 890 | pDeleteLm(&qp2); |
---|
| 891 | qp2 = *p; |
---|
| 892 | qp1 = *p; |
---|
| 893 | } |
---|
| 894 | else |
---|
| 895 | { |
---|
| 896 | qp2->next = qp1->next; |
---|
| 897 | pDeleteLm(&qp1); |
---|
| 898 | qp1 = qp2->next; |
---|
| 899 | } |
---|
| 900 | } |
---|
| 901 | } |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | /*2 |
---|
| 905 | *initialized a field with r numbers between beg and end for the |
---|
| 906 | *procedure idNextChoise |
---|
| 907 | */ |
---|
| 908 | void idInitChoise (int r,int beg,int end,BOOLEAN *endch,int * choise) |
---|
| 909 | { |
---|
| 910 | /*returns the first choise of r numbers between beg and end*/ |
---|
| 911 | int i; |
---|
| 912 | for (i=0; i<r; i++) |
---|
| 913 | { |
---|
| 914 | choise[i] = 0; |
---|
| 915 | } |
---|
| 916 | if (r <= end-beg+1) |
---|
| 917 | for (i=0; i<r; i++) |
---|
| 918 | { |
---|
| 919 | choise[i] = beg+i; |
---|
| 920 | } |
---|
| 921 | if (r > end-beg+1) |
---|
| 922 | *endch = TRUE; |
---|
| 923 | else |
---|
| 924 | *endch = FALSE; |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | /*2 |
---|
| 928 | *returns the next choise of r numbers between beg and end |
---|
| 929 | */ |
---|
| 930 | void idGetNextChoise (int r,int end,BOOLEAN *endch,int * choise) |
---|
| 931 | { |
---|
| 932 | int i = r-1,j; |
---|
| 933 | while ((i >= 0) && (choise[i] == end)) |
---|
| 934 | { |
---|
| 935 | i--; |
---|
| 936 | end--; |
---|
| 937 | } |
---|
| 938 | if (i == -1) |
---|
| 939 | *endch = TRUE; |
---|
| 940 | else |
---|
| 941 | { |
---|
| 942 | choise[i]++; |
---|
| 943 | for (j=i+1; j<r; j++) |
---|
| 944 | { |
---|
| 945 | choise[j] = choise[i]+j-i; |
---|
| 946 | } |
---|
| 947 | *endch = FALSE; |
---|
| 948 | } |
---|
| 949 | } |
---|
| 950 | |
---|
| 951 | /*2 |
---|
| 952 | *takes the field choise of d numbers between beg and end, cancels the t-th |
---|
| 953 | *entree and searches for the ordinal number of that d-1 dimensional field |
---|
| 954 | * w.r.t. the algorithm of construction |
---|
| 955 | */ |
---|
| 956 | int idGetNumberOfChoise(int t, int d, int begin, int end, int * choise) |
---|
| 957 | { |
---|
| 958 | int * localchoise,i,result=0; |
---|
| 959 | BOOLEAN b=FALSE; |
---|
| 960 | |
---|
| 961 | if (d<=1) return 1; |
---|
| 962 | localchoise=(int*)omAlloc((d-1)*sizeof(int)); |
---|
| 963 | idInitChoise(d-1,begin,end,&b,localchoise); |
---|
| 964 | while (!b) |
---|
| 965 | { |
---|
| 966 | result++; |
---|
| 967 | i = 0; |
---|
| 968 | while ((i<t) && (localchoise[i]==choise[i])) i++; |
---|
| 969 | if (i>=t) |
---|
| 970 | { |
---|
| 971 | i = t+1; |
---|
| 972 | while ((i<d) && (localchoise[i-1]==choise[i])) i++; |
---|
| 973 | if (i>=d) |
---|
| 974 | { |
---|
| 975 | omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int)); |
---|
| 976 | return result; |
---|
| 977 | } |
---|
| 978 | } |
---|
| 979 | idGetNextChoise(d-1,end,&b,localchoise); |
---|
| 980 | } |
---|
| 981 | omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int)); |
---|
| 982 | return 0; |
---|
| 983 | } |
---|
| 984 | |
---|
| 985 | /*2 |
---|
| 986 | *computes the binomial coefficient |
---|
| 987 | */ |
---|
| 988 | int binom (int n,int r) |
---|
| 989 | { |
---|
| 990 | int i,result; |
---|
| 991 | |
---|
| 992 | if (r==0) return 1; |
---|
| 993 | if (n-r<r) return binom(n,n-r); |
---|
| 994 | result = n-r+1; |
---|
| 995 | for (i=2;i<=r;i++) |
---|
| 996 | { |
---|
| 997 | result *= n-r+i; |
---|
| 998 | if (result<0) |
---|
| 999 | { |
---|
| 1000 | WarnS("overflow in binomials"); |
---|
| 1001 | return 0; |
---|
| 1002 | } |
---|
| 1003 | result /= i; |
---|
| 1004 | } |
---|
| 1005 | return result; |
---|
| 1006 | } |
---|
| 1007 | |
---|
| 1008 | /*2 |
---|
| 1009 | *the free module of rank i |
---|
| 1010 | */ |
---|
| 1011 | ideal idFreeModule (int i) |
---|
| 1012 | { |
---|
| 1013 | int j; |
---|
| 1014 | ideal h; |
---|
| 1015 | |
---|
| 1016 | h=idInit(i,i); |
---|
| 1017 | for (j=0; j<i; j++) |
---|
| 1018 | { |
---|
| 1019 | h->m[j] = pOne(); |
---|
| 1020 | pSetComp(h->m[j],j+1); |
---|
| 1021 | pSetmComp(h->m[j]); |
---|
| 1022 | } |
---|
| 1023 | return h; |
---|
| 1024 | } |
---|
| 1025 | |
---|
| 1026 | /*2 |
---|
| 1027 | * h3 := h1 intersect h2 |
---|
| 1028 | */ |
---|
| 1029 | ideal idSect (ideal h1,ideal h2) |
---|
| 1030 | { |
---|
| 1031 | ideal first=h2,second=h1,temp,temp1,result; |
---|
| 1032 | int i,j,k,flength,slength,length,rank=si_min(h1->rank,h2->rank); |
---|
| 1033 | intvec *w; |
---|
| 1034 | poly p,q; |
---|
| 1035 | |
---|
| 1036 | if ((idIs0(h1)) && (idIs0(h2))) return idInit(1,rank); |
---|
| 1037 | if (IDELEMS(h1)<IDELEMS(h2)) |
---|
| 1038 | { |
---|
| 1039 | first = h1; |
---|
| 1040 | second = h2; |
---|
| 1041 | } |
---|
| 1042 | flength = idRankFreeModule(first); |
---|
| 1043 | slength = idRankFreeModule(second); |
---|
| 1044 | length = si_max(flength,slength); |
---|
| 1045 | if (length==0) |
---|
| 1046 | { |
---|
| 1047 | length = 1; |
---|
| 1048 | } |
---|
| 1049 | j = IDELEMS(first); |
---|
| 1050 | temp = idInit(j /*IDELEMS(first)*/,length+j); |
---|
| 1051 | |
---|
| 1052 | ring orig_ring=currRing; |
---|
| 1053 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 1054 | rSetSyzComp(length); |
---|
| 1055 | |
---|
| 1056 | while ((j>0) && (first->m[j-1]==NULL)) j--; |
---|
| 1057 | k = 0; |
---|
| 1058 | for (i=0;i<j;i++) |
---|
| 1059 | { |
---|
| 1060 | if (first->m[i]!=NULL) |
---|
| 1061 | { |
---|
| 1062 | if (syz_ring==orig_ring) |
---|
| 1063 | temp->m[k] = pCopy(first->m[i]); |
---|
| 1064 | else |
---|
[4d13e7] | 1065 | temp->m[k] = prCopyR(first->m[i], orig_ring); |
---|
[35aab3] | 1066 | q = pOne(); |
---|
| 1067 | pSetComp(q,i+1+length); |
---|
| 1068 | pSetmComp(q); |
---|
| 1069 | if (flength==0) pShift(&(temp->m[k]),1); |
---|
| 1070 | p = temp->m[k]; |
---|
| 1071 | while (pNext(p)!=NULL) pIter(p); |
---|
| 1072 | pNext(p) = q; |
---|
| 1073 | k++; |
---|
| 1074 | } |
---|
| 1075 | } |
---|
| 1076 | pEnlargeSet(&(temp->m),IDELEMS(temp),j+IDELEMS(second)-IDELEMS(temp)); |
---|
| 1077 | IDELEMS(temp) = j+IDELEMS(second); |
---|
| 1078 | for (i=0;i<IDELEMS(second);i++) |
---|
| 1079 | { |
---|
| 1080 | if (second->m[i]!=NULL) |
---|
| 1081 | { |
---|
| 1082 | if (syz_ring==orig_ring) |
---|
| 1083 | temp->m[k] = pCopy(second->m[i]); |
---|
| 1084 | else |
---|
[4d13e7] | 1085 | temp->m[k] = prCopyR(second->m[i], orig_ring); |
---|
[35aab3] | 1086 | if (slength==0) pShift(&(temp->m[k]),1); |
---|
| 1087 | k++; |
---|
| 1088 | } |
---|
| 1089 | } |
---|
| 1090 | temp1 = kStd(temp,currQuotient,testHomog,&w,NULL,length); |
---|
| 1091 | if (w!=NULL) delete w; |
---|
| 1092 | idDelete(&temp); |
---|
| 1093 | |
---|
| 1094 | if(syz_ring!=orig_ring) |
---|
| 1095 | rChangeCurrRing(orig_ring); |
---|
| 1096 | |
---|
| 1097 | result = idInit(IDELEMS(temp1),rank); |
---|
| 1098 | j = 0; |
---|
| 1099 | for (i=0;i<IDELEMS(temp1);i++) |
---|
| 1100 | { |
---|
| 1101 | if ((temp1->m[i]!=NULL) |
---|
| 1102 | && (p_GetComp(temp1->m[i],syz_ring)>length)) |
---|
| 1103 | { |
---|
| 1104 | if(syz_ring==orig_ring) |
---|
[4d13e7] | 1105 | p = pCopy(temp1->m[i]); |
---|
[35aab3] | 1106 | else |
---|
[4d13e7] | 1107 | p = prCopyR(temp1->m[i], syz_ring); |
---|
[35aab3] | 1108 | while (p!=NULL) |
---|
| 1109 | { |
---|
| 1110 | q = pNext(p); |
---|
| 1111 | pNext(p) = NULL; |
---|
| 1112 | k = pGetComp(p)-1-length; |
---|
| 1113 | pSetComp(p,0); |
---|
| 1114 | pSetmComp(p); |
---|
[4d13e7] | 1115 | /* Warning! multiply only from the left! it's very important for Plural */ |
---|
[99b206] | 1116 | result->m[j] = pAdd(result->m[j],pMult(p,pCopy(first->m[k]))); |
---|
[35aab3] | 1117 | p = q; |
---|
| 1118 | } |
---|
| 1119 | j++; |
---|
| 1120 | } |
---|
| 1121 | } |
---|
| 1122 | if(syz_ring!=orig_ring) |
---|
| 1123 | { |
---|
| 1124 | rChangeCurrRing(syz_ring); |
---|
| 1125 | idDelete(&temp1); |
---|
| 1126 | rChangeCurrRing(orig_ring); |
---|
| 1127 | rKill(syz_ring); |
---|
| 1128 | } |
---|
| 1129 | else |
---|
| 1130 | { |
---|
| 1131 | idDelete(&temp1); |
---|
| 1132 | } |
---|
| 1133 | |
---|
| 1134 | idSkipZeroes(result); |
---|
| 1135 | return result; |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | /*2 |
---|
| 1139 | * ideal/module intersection for a list of objects |
---|
| 1140 | * given as 'resolvente' |
---|
| 1141 | */ |
---|
| 1142 | ideal idMultSect(resolvente arg, int length) |
---|
| 1143 | { |
---|
| 1144 | int i,j=0,k=0,syzComp,l,maxrk=-1,realrki; |
---|
| 1145 | ideal bigmat,tempstd,result; |
---|
| 1146 | poly p; |
---|
| 1147 | int isIdeal=0; |
---|
| 1148 | intvec * w=NULL; |
---|
| 1149 | |
---|
| 1150 | /* find 0-ideals and max rank -----------------------------------*/ |
---|
| 1151 | for (i=0;i<length;i++) |
---|
| 1152 | { |
---|
| 1153 | if (!idIs0(arg[i])) |
---|
| 1154 | { |
---|
| 1155 | realrki=idRankFreeModule(arg[i]); |
---|
| 1156 | k++; |
---|
| 1157 | j += IDELEMS(arg[i]); |
---|
| 1158 | if (realrki>maxrk) maxrk = realrki; |
---|
| 1159 | } |
---|
| 1160 | else |
---|
| 1161 | { |
---|
| 1162 | if (arg[i]!=NULL) |
---|
| 1163 | { |
---|
| 1164 | return idInit(1,arg[i]->rank); |
---|
| 1165 | } |
---|
| 1166 | } |
---|
| 1167 | } |
---|
| 1168 | if (maxrk == 0) |
---|
| 1169 | { |
---|
| 1170 | isIdeal = 1; |
---|
| 1171 | maxrk = 1; |
---|
| 1172 | } |
---|
| 1173 | /* init -----------------------------------------------------------*/ |
---|
| 1174 | j += maxrk; |
---|
| 1175 | syzComp = k*maxrk; |
---|
| 1176 | |
---|
| 1177 | ring orig_ring=currRing; |
---|
| 1178 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 1179 | rSetSyzComp(syzComp); |
---|
| 1180 | |
---|
| 1181 | bigmat = idInit(j,(k+1)*maxrk); |
---|
| 1182 | /* create unit matrices ------------------------------------------*/ |
---|
| 1183 | for (i=0;i<maxrk;i++) |
---|
| 1184 | { |
---|
| 1185 | for (j=0;j<=k;j++) |
---|
| 1186 | { |
---|
| 1187 | p = pOne(); |
---|
| 1188 | pSetComp(p,i+1+j*maxrk); |
---|
| 1189 | pSetmComp(p); |
---|
| 1190 | bigmat->m[i] = pAdd(bigmat->m[i],p); |
---|
| 1191 | } |
---|
| 1192 | } |
---|
| 1193 | /* enter given ideals ------------------------------------------*/ |
---|
| 1194 | i = maxrk; |
---|
| 1195 | k = 0; |
---|
| 1196 | for (j=0;j<length;j++) |
---|
| 1197 | { |
---|
| 1198 | if (arg[j]!=NULL) |
---|
| 1199 | { |
---|
| 1200 | for (l=0;l<IDELEMS(arg[j]);l++) |
---|
| 1201 | { |
---|
| 1202 | if (arg[j]->m[l]!=NULL) |
---|
| 1203 | { |
---|
| 1204 | if (syz_ring==orig_ring) |
---|
| 1205 | bigmat->m[i] = pCopy(arg[j]->m[l]); |
---|
| 1206 | else |
---|
| 1207 | bigmat->m[i] = prCopyR(arg[j]->m[l], orig_ring); |
---|
| 1208 | pShift(&(bigmat->m[i]),k*maxrk+isIdeal); |
---|
| 1209 | i++; |
---|
| 1210 | } |
---|
| 1211 | } |
---|
| 1212 | k++; |
---|
| 1213 | } |
---|
| 1214 | } |
---|
| 1215 | /* std computation --------------------------------------------*/ |
---|
| 1216 | tempstd = kStd(bigmat,currQuotient,testHomog,&w,NULL,syzComp); |
---|
| 1217 | if (w!=NULL) delete w; |
---|
| 1218 | idDelete(&bigmat); |
---|
| 1219 | |
---|
| 1220 | if(syz_ring!=orig_ring) |
---|
| 1221 | rChangeCurrRing(orig_ring); |
---|
| 1222 | |
---|
| 1223 | /* interprete result ----------------------------------------*/ |
---|
| 1224 | result = idInit(8,maxrk); |
---|
| 1225 | k = 0; |
---|
| 1226 | for (j=0;j<IDELEMS(tempstd);j++) |
---|
| 1227 | { |
---|
| 1228 | if ((tempstd->m[j]!=NULL) && (p_GetComp(tempstd->m[j],syz_ring)>syzComp)) |
---|
| 1229 | { |
---|
| 1230 | if (k>=IDELEMS(result)) |
---|
| 1231 | { |
---|
| 1232 | pEnlargeSet(&(result->m),IDELEMS(result),8); |
---|
| 1233 | IDELEMS(result) += 8; |
---|
| 1234 | } |
---|
| 1235 | if (syz_ring==orig_ring) |
---|
| 1236 | p = pCopy(tempstd->m[j]); |
---|
| 1237 | else |
---|
| 1238 | p = prCopyR(tempstd->m[j], syz_ring); |
---|
| 1239 | pShift(&p,-syzComp-isIdeal); |
---|
| 1240 | result->m[k] = p; |
---|
| 1241 | k++; |
---|
| 1242 | } |
---|
| 1243 | } |
---|
| 1244 | /* clean up ----------------------------------------------------*/ |
---|
| 1245 | if(syz_ring!=orig_ring) |
---|
| 1246 | rChangeCurrRing(syz_ring); |
---|
| 1247 | idDelete(&tempstd); |
---|
| 1248 | if(syz_ring!=orig_ring) |
---|
| 1249 | { |
---|
| 1250 | rChangeCurrRing(orig_ring); |
---|
| 1251 | rKill(syz_ring); |
---|
| 1252 | } |
---|
| 1253 | idSkipZeroes(result); |
---|
| 1254 | return result; |
---|
| 1255 | } |
---|
| 1256 | |
---|
| 1257 | /*2 |
---|
| 1258 | *computes syzygies of h1, |
---|
| 1259 | *if quot != NULL it computes in the quotient ring modulo "quot" |
---|
| 1260 | *works always in a ring with ringorder_s |
---|
| 1261 | */ |
---|
| 1262 | static ideal idPrepare (ideal h1, tHomog h, int syzcomp, intvec **w) |
---|
| 1263 | { |
---|
| 1264 | ideal h2, h3; |
---|
| 1265 | int i; |
---|
| 1266 | int j,jj=0,k; |
---|
| 1267 | poly p,q; |
---|
| 1268 | |
---|
| 1269 | if (idIs0(h1)) return NULL; |
---|
| 1270 | k = idRankFreeModule(h1); |
---|
| 1271 | h2=idCopy(h1); |
---|
| 1272 | i = IDELEMS(h2)-1; |
---|
| 1273 | if (k == 0) |
---|
| 1274 | { |
---|
| 1275 | for (j=0; j<=i; j++) pShift(&(h2->m[j]),1); |
---|
| 1276 | k = 1; |
---|
| 1277 | } |
---|
| 1278 | if (syzcomp<k) |
---|
| 1279 | { |
---|
| 1280 | Warn("syzcomp too low, should be %d instead of %d",k,syzcomp); |
---|
| 1281 | syzcomp = k; |
---|
| 1282 | rSetSyzComp(k); |
---|
| 1283 | } |
---|
| 1284 | h2->rank = syzcomp+i+1; |
---|
| 1285 | for (j=0; j<=i; j++) |
---|
| 1286 | { |
---|
| 1287 | p = h2->m[j]; |
---|
| 1288 | q = pOne(); |
---|
| 1289 | pSetComp(q,syzcomp+1+j); |
---|
| 1290 | pSetmComp(q); |
---|
| 1291 | if (p!=NULL) |
---|
| 1292 | { |
---|
| 1293 | while (pNext(p)) pIter(p); |
---|
| 1294 | p->next = q; |
---|
| 1295 | } |
---|
| 1296 | else |
---|
| 1297 | h2->m[j]=q; |
---|
| 1298 | } |
---|
| 1299 | |
---|
| 1300 | #ifdef PDEBUG |
---|
| 1301 | for(j=0;j<IDELEMS(h2);j++) pTest(h2->m[j]); |
---|
| 1302 | #endif |
---|
| 1303 | h3=kStd(h2,currQuotient,h,w,NULL,syzcomp); |
---|
| 1304 | idDelete(&h2); |
---|
| 1305 | return h3; |
---|
| 1306 | } |
---|
| 1307 | |
---|
| 1308 | /*2 |
---|
| 1309 | * compute the syzygies of h1 in R/quot, |
---|
| 1310 | * weights of components are in w |
---|
| 1311 | * if setRegularity, return the regularity in deg |
---|
| 1312 | * do not change h1, w |
---|
| 1313 | */ |
---|
| 1314 | ideal idSyzygies (ideal h1, tHomog h,intvec **w, BOOLEAN setSyzComp, |
---|
| 1315 | BOOLEAN setRegularity, int *deg) |
---|
| 1316 | { |
---|
| 1317 | ideal s_h1; |
---|
| 1318 | poly p; |
---|
[43ebb1] | 1319 | int j, k, length=0,reg; |
---|
[35aab3] | 1320 | BOOLEAN isMonomial=TRUE; |
---|
[43ebb1] | 1321 | int ii, idElemens_h1; |
---|
[35aab3] | 1322 | |
---|
[43ebb1] | 1323 | idElemens_h1=IDELEMS(h1); |
---|
[35aab3] | 1324 | #ifdef PDEBUG |
---|
[43ebb1] | 1325 | for(ii=0;ii<idElemens_h1 /*IDELEMS(h1)*/;ii++) pTest(h1->m[ii]); |
---|
[35aab3] | 1326 | #endif |
---|
| 1327 | if (idIs0(h1)) |
---|
| 1328 | { |
---|
[43ebb1] | 1329 | ideal result=idFreeModule(idElemens_h1/*IDELEMS(h1)*/); |
---|
[35aab3] | 1330 | int curr_syz_limit=rGetCurrSyzLimit(); |
---|
| 1331 | if (curr_syz_limit>0) |
---|
[43ebb1] | 1332 | for (ii=0;ii<idElemens_h1/*IDELEMS(h1)*/;ii++) |
---|
[35aab3] | 1333 | { |
---|
| 1334 | if (h1->m[ii]!=NULL) |
---|
| 1335 | pShift(&h1->m[ii],curr_syz_limit); |
---|
| 1336 | } |
---|
| 1337 | return result; |
---|
| 1338 | } |
---|
[43ebb1] | 1339 | int slength=(int)idRankFreeModule(h1); |
---|
| 1340 | k=si_max(1,slength /*idRankFreeModule(h1)*/); |
---|
[35aab3] | 1341 | |
---|
| 1342 | assume(currRing != NULL); |
---|
| 1343 | ring orig_ring=currRing; |
---|
| 1344 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 1345 | |
---|
| 1346 | if (setSyzComp) |
---|
| 1347 | rSetSyzComp(k); |
---|
| 1348 | |
---|
| 1349 | if (orig_ring != syz_ring) |
---|
| 1350 | { |
---|
| 1351 | s_h1=idrCopyR_NoSort(h1,orig_ring); |
---|
| 1352 | } |
---|
| 1353 | else |
---|
| 1354 | { |
---|
| 1355 | s_h1 = h1; |
---|
| 1356 | } |
---|
| 1357 | |
---|
| 1358 | ideal s_h3=idPrepare(s_h1,h,k,w); |
---|
| 1359 | |
---|
| 1360 | if (s_h3==NULL) |
---|
| 1361 | { |
---|
[43ebb1] | 1362 | return idFreeModule( idElemens_h1 /*IDELEMS(h1)*/); |
---|
[35aab3] | 1363 | } |
---|
| 1364 | |
---|
| 1365 | if (orig_ring != syz_ring) |
---|
| 1366 | { |
---|
| 1367 | idDelete(&s_h1); |
---|
| 1368 | for (j=0; j<IDELEMS(s_h3); j++) |
---|
| 1369 | { |
---|
| 1370 | if (s_h3->m[j] != NULL) |
---|
| 1371 | { |
---|
| 1372 | if (p_MinComp(s_h3->m[j],syz_ring) > k) |
---|
| 1373 | pShift(&s_h3->m[j], -k); |
---|
| 1374 | else |
---|
| 1375 | pDelete(&s_h3->m[j]); |
---|
| 1376 | } |
---|
| 1377 | } |
---|
| 1378 | idSkipZeroes(s_h3); |
---|
| 1379 | s_h3->rank -= k; |
---|
| 1380 | rChangeCurrRing(orig_ring); |
---|
| 1381 | s_h3 = idrMoveR_NoSort(s_h3, syz_ring); |
---|
| 1382 | rKill(syz_ring); |
---|
| 1383 | idTest(s_h3); |
---|
| 1384 | return s_h3; |
---|
| 1385 | } |
---|
| 1386 | |
---|
| 1387 | ideal e = idInit(IDELEMS(s_h3), s_h3->rank); |
---|
| 1388 | |
---|
| 1389 | for (j=0; j<IDELEMS(s_h3); j++) |
---|
| 1390 | { |
---|
| 1391 | if (s_h3->m[j] != NULL) |
---|
| 1392 | { |
---|
| 1393 | if (p_MinComp(s_h3->m[j],syz_ring) <= k) |
---|
| 1394 | { |
---|
| 1395 | e->m[j] = s_h3->m[j]; |
---|
| 1396 | isMonomial=isMonomial && (pNext(s_h3->m[j])==NULL); |
---|
| 1397 | pDelete(&pNext(s_h3->m[j])); |
---|
| 1398 | s_h3->m[j] = NULL; |
---|
| 1399 | } |
---|
| 1400 | } |
---|
| 1401 | } |
---|
| 1402 | |
---|
| 1403 | idSkipZeroes(s_h3); |
---|
| 1404 | idSkipZeroes(e); |
---|
| 1405 | |
---|
| 1406 | if ((deg != NULL) |
---|
| 1407 | && (!isMonomial) |
---|
| 1408 | && (!TEST_OPT_NOTREGULARITY) |
---|
| 1409 | && (setRegularity) |
---|
| 1410 | && (h==isHomog) |
---|
| 1411 | && (!rIsPluralRing(currRing)) |
---|
| 1412 | ) |
---|
| 1413 | { |
---|
| 1414 | ring dp_C_ring = rCurrRingAssure_dp_C(); |
---|
| 1415 | if (dp_C_ring != syz_ring) |
---|
| 1416 | e = idrMoveR_NoSort(e, syz_ring); |
---|
| 1417 | resolvente res = sySchreyerResolvente(e,-1,&length,TRUE, TRUE); |
---|
| 1418 | intvec * dummy = syBetti(res,length,®, *w); |
---|
| 1419 | *deg = reg+2; |
---|
| 1420 | delete dummy; |
---|
| 1421 | for (j=0;j<length;j++) |
---|
| 1422 | { |
---|
| 1423 | if (res[j]!=NULL) idDelete(&(res[j])); |
---|
| 1424 | } |
---|
| 1425 | omFreeSize((ADDRESS)res,length*sizeof(ideal)); |
---|
| 1426 | idDelete(&e); |
---|
| 1427 | if (dp_C_ring != syz_ring) |
---|
| 1428 | { |
---|
| 1429 | rChangeCurrRing(syz_ring); |
---|
| 1430 | rKill(dp_C_ring); |
---|
| 1431 | } |
---|
| 1432 | } |
---|
| 1433 | else |
---|
| 1434 | { |
---|
| 1435 | idDelete(&e); |
---|
| 1436 | } |
---|
| 1437 | idTest(s_h3); |
---|
| 1438 | if (currQuotient != NULL) |
---|
| 1439 | { |
---|
| 1440 | ideal ts_h3=kStd(s_h3,currQuotient,h,w); |
---|
| 1441 | idDelete(&s_h3); |
---|
| 1442 | s_h3 = ts_h3; |
---|
| 1443 | } |
---|
| 1444 | return s_h3; |
---|
| 1445 | } |
---|
| 1446 | |
---|
| 1447 | /*2 |
---|
| 1448 | */ |
---|
| 1449 | ideal idXXX (ideal h1, int k) |
---|
| 1450 | { |
---|
| 1451 | ideal s_h1; |
---|
| 1452 | int j; |
---|
| 1453 | intvec *w=NULL; |
---|
| 1454 | |
---|
| 1455 | assume(currRing != NULL); |
---|
| 1456 | ring orig_ring=currRing; |
---|
| 1457 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 1458 | |
---|
| 1459 | rSetSyzComp(k); |
---|
| 1460 | |
---|
| 1461 | if (orig_ring != syz_ring) |
---|
| 1462 | { |
---|
| 1463 | s_h1=idrCopyR_NoSort(h1,orig_ring); |
---|
| 1464 | } |
---|
| 1465 | else |
---|
| 1466 | { |
---|
| 1467 | s_h1 = h1; |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | ideal s_h3=kStd(s_h1,NULL,testHomog,&w,NULL,k); |
---|
| 1471 | |
---|
| 1472 | if (s_h3==NULL) |
---|
| 1473 | { |
---|
| 1474 | return idFreeModule(IDELEMS(h1)); |
---|
| 1475 | } |
---|
| 1476 | |
---|
| 1477 | if (orig_ring != syz_ring) |
---|
| 1478 | { |
---|
| 1479 | idDelete(&s_h1); |
---|
| 1480 | idSkipZeroes(s_h3); |
---|
| 1481 | rChangeCurrRing(orig_ring); |
---|
| 1482 | s_h3 = idrMoveR_NoSort(s_h3, syz_ring); |
---|
| 1483 | rKill(syz_ring); |
---|
| 1484 | idTest(s_h3); |
---|
| 1485 | return s_h3; |
---|
| 1486 | } |
---|
| 1487 | |
---|
| 1488 | idSkipZeroes(s_h3); |
---|
| 1489 | idTest(s_h3); |
---|
| 1490 | return s_h3; |
---|
| 1491 | } |
---|
| 1492 | |
---|
| 1493 | /* |
---|
| 1494 | *computes a standard basis for h1 and stores the transformation matrix |
---|
| 1495 | * in ma |
---|
| 1496 | */ |
---|
| 1497 | ideal idLiftStd (ideal h1, matrix* ma, tHomog h) |
---|
| 1498 | { |
---|
| 1499 | int i, j, k, t, inputIsIdeal=idRankFreeModule(h1); |
---|
| 1500 | poly p=NULL, q, qq; |
---|
| 1501 | intvec *w=NULL; |
---|
| 1502 | |
---|
| 1503 | idDelete((ideal*)ma); |
---|
| 1504 | *ma=mpNew(1,0); |
---|
| 1505 | if (idIs0(h1)) |
---|
| 1506 | return idInit(1,h1->rank); |
---|
[225d94] | 1507 | |
---|
| 1508 | BITSET save_verbose=verbose; |
---|
| 1509 | |
---|
[62dd9b] | 1510 | k=si_max(1,(int)idRankFreeModule(h1)); |
---|
[35aab3] | 1511 | |
---|
[225d94] | 1512 | if (k==1) verbose |=Sy_bit(V_IDLIFT); |
---|
| 1513 | |
---|
[35aab3] | 1514 | ring orig_ring=currRing; |
---|
| 1515 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 1516 | rSetSyzComp(k); |
---|
| 1517 | |
---|
| 1518 | ideal s_h1=h1; |
---|
| 1519 | |
---|
| 1520 | if (orig_ring != syz_ring) |
---|
| 1521 | s_h1 = idrCopyR_NoSort(h1,orig_ring); |
---|
| 1522 | else |
---|
| 1523 | s_h1 = h1; |
---|
| 1524 | |
---|
| 1525 | ideal s_h3=idPrepare(s_h1,h,k,&w); |
---|
| 1526 | ideal s_h2 = idInit(IDELEMS(s_h3), s_h3->rank); |
---|
| 1527 | |
---|
| 1528 | if (w!=NULL) delete w; |
---|
| 1529 | i = 0; |
---|
| 1530 | for (j=0; j<IDELEMS(s_h3); j++) |
---|
| 1531 | { |
---|
| 1532 | if ((s_h3->m[j] != NULL) && (p_MinComp(s_h3->m[j],syz_ring) <= k)) |
---|
| 1533 | { |
---|
| 1534 | i++; |
---|
| 1535 | q = s_h3->m[j]; |
---|
| 1536 | while (pNext(q) != NULL) |
---|
| 1537 | { |
---|
| 1538 | if (pGetComp(pNext(q)) > k) |
---|
| 1539 | { |
---|
| 1540 | s_h2->m[j] = pNext(q); |
---|
| 1541 | pNext(q) = NULL; |
---|
| 1542 | } |
---|
| 1543 | else |
---|
| 1544 | { |
---|
| 1545 | pIter(q); |
---|
| 1546 | } |
---|
| 1547 | } |
---|
| 1548 | if (!inputIsIdeal) pShift(&(s_h3->m[j]), -1); |
---|
| 1549 | } |
---|
| 1550 | else |
---|
| 1551 | { |
---|
| 1552 | pDelete(&(s_h3->m[j])); |
---|
| 1553 | } |
---|
| 1554 | } |
---|
| 1555 | |
---|
| 1556 | idSkipZeroes(s_h3); |
---|
| 1557 | j = IDELEMS(s_h1); |
---|
| 1558 | |
---|
| 1559 | if (syz_ring!=orig_ring) |
---|
| 1560 | { |
---|
| 1561 | idDelete(&s_h1); |
---|
| 1562 | rChangeCurrRing(orig_ring); |
---|
| 1563 | } |
---|
| 1564 | |
---|
| 1565 | idDelete((ideal*)ma); |
---|
| 1566 | *ma = mpNew(j,i); |
---|
| 1567 | |
---|
| 1568 | i = 1; |
---|
| 1569 | for (j=0; j<IDELEMS(s_h2); j++) |
---|
| 1570 | { |
---|
| 1571 | if (s_h2->m[j] != NULL) |
---|
| 1572 | { |
---|
| 1573 | q = prMoveR( s_h2->m[j], syz_ring); |
---|
| 1574 | s_h2->m[j] = NULL; |
---|
| 1575 | |
---|
| 1576 | while (q != NULL) |
---|
| 1577 | { |
---|
| 1578 | p = q; |
---|
| 1579 | pIter(q); |
---|
| 1580 | pNext(p) = NULL; |
---|
| 1581 | t=pGetComp(p); |
---|
| 1582 | pSetComp(p,0); |
---|
| 1583 | pSetmComp(p); |
---|
| 1584 | MATELEM(*ma,t-k,i) = pAdd(MATELEM(*ma,t-k,i),p); |
---|
| 1585 | } |
---|
| 1586 | i++; |
---|
| 1587 | } |
---|
| 1588 | } |
---|
| 1589 | idDelete(&s_h2); |
---|
| 1590 | |
---|
| 1591 | for (i=0; i<IDELEMS(s_h3); i++) |
---|
| 1592 | { |
---|
| 1593 | s_h3->m[i] = prMoveR_NoSort(s_h3->m[i], syz_ring); |
---|
| 1594 | } |
---|
| 1595 | |
---|
| 1596 | if (syz_ring!=orig_ring) rKill(syz_ring); |
---|
[225d94] | 1597 | verbose = save_verbose; |
---|
[35aab3] | 1598 | return s_h3; |
---|
| 1599 | } |
---|
| 1600 | |
---|
| 1601 | static void idPrepareStd(ideal s_temp, int k) |
---|
| 1602 | { |
---|
| 1603 | int j,rk=idRankFreeModule(s_temp); |
---|
| 1604 | poly p,q; |
---|
| 1605 | |
---|
| 1606 | if (rk == 0) |
---|
| 1607 | { |
---|
| 1608 | for (j=0; j<IDELEMS(s_temp); j++) |
---|
| 1609 | { |
---|
| 1610 | if (s_temp->m[j]!=NULL) pSetCompP(s_temp->m[j],1); |
---|
| 1611 | } |
---|
| 1612 | k = si_max(k,1); |
---|
| 1613 | } |
---|
| 1614 | for (j=0; j<IDELEMS(s_temp); j++) |
---|
| 1615 | { |
---|
| 1616 | if (s_temp->m[j]!=NULL) |
---|
| 1617 | { |
---|
| 1618 | p = s_temp->m[j]; |
---|
| 1619 | q = pOne(); |
---|
| 1620 | //pGetCoeff(q)=nNeg(pGetCoeff(q)); //set q to -1 |
---|
| 1621 | pSetComp(q,k+1+j); |
---|
| 1622 | pSetmComp(q); |
---|
| 1623 | while (pNext(p)) pIter(p); |
---|
| 1624 | pNext(p) = q; |
---|
| 1625 | } |
---|
| 1626 | } |
---|
| 1627 | } |
---|
| 1628 | |
---|
| 1629 | /*2 |
---|
| 1630 | *computes a representation of the generators of submod with respect to those |
---|
| 1631 | * of mod |
---|
| 1632 | */ |
---|
| 1633 | |
---|
| 1634 | ideal idLift(ideal mod, ideal submod,ideal *rest, BOOLEAN goodShape, |
---|
| 1635 | BOOLEAN isSB, BOOLEAN divide, matrix *unit) |
---|
| 1636 | { |
---|
| 1637 | int lsmod =idRankFreeModule(submod), i, j, k; |
---|
| 1638 | int comps_to_add=0; |
---|
| 1639 | poly p; |
---|
| 1640 | |
---|
| 1641 | if (idIs0(submod)) |
---|
| 1642 | { |
---|
| 1643 | if (unit!=NULL) |
---|
| 1644 | { |
---|
| 1645 | *unit=mpNew(1,1); |
---|
| 1646 | MATELEM(*unit,1,1)=pOne(); |
---|
| 1647 | } |
---|
| 1648 | if (rest!=NULL) |
---|
| 1649 | { |
---|
| 1650 | *rest=idInit(1,mod->rank); |
---|
| 1651 | } |
---|
| 1652 | return idInit(1,mod->rank); |
---|
| 1653 | } |
---|
| 1654 | if (idIs0(mod)) |
---|
| 1655 | { |
---|
| 1656 | if (unit!=NULL) |
---|
| 1657 | { |
---|
| 1658 | i=IDELEMS(submod); |
---|
| 1659 | *unit=mpNew(i,i); |
---|
| 1660 | for (j=i;j>0;j--) |
---|
| 1661 | { |
---|
| 1662 | MATELEM(*unit,j,j)=pOne(); |
---|
| 1663 | } |
---|
| 1664 | } |
---|
| 1665 | if (rest!=NULL) |
---|
| 1666 | { |
---|
| 1667 | *rest=idCopy(submod); |
---|
| 1668 | } |
---|
| 1669 | return idInit(1,mod->rank); |
---|
| 1670 | } |
---|
| 1671 | if (unit!=NULL) |
---|
| 1672 | { |
---|
| 1673 | comps_to_add = IDELEMS(submod); |
---|
| 1674 | while ((comps_to_add>0) && (submod->m[comps_to_add-1]==NULL)) |
---|
| 1675 | comps_to_add--; |
---|
| 1676 | } |
---|
| 1677 | k=idRankFreeModule(mod); |
---|
| 1678 | if ((k!=0) && (lsmod==0)) lsmod=1; |
---|
| 1679 | k=si_max(k,1); |
---|
| 1680 | |
---|
| 1681 | ring orig_ring=currRing; |
---|
| 1682 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 1683 | rSetSyzComp(k); |
---|
| 1684 | |
---|
| 1685 | ideal s_mod, s_temp; |
---|
| 1686 | if (orig_ring != syz_ring) |
---|
| 1687 | { |
---|
| 1688 | s_mod = idrCopyR_NoSort(mod,orig_ring); |
---|
| 1689 | s_temp = idrCopyR_NoSort(submod,orig_ring); |
---|
| 1690 | } |
---|
| 1691 | else |
---|
| 1692 | { |
---|
| 1693 | s_mod = mod; |
---|
| 1694 | s_temp = idCopy(submod); |
---|
| 1695 | } |
---|
| 1696 | ideal s_h3; |
---|
| 1697 | if (isSB) |
---|
| 1698 | { |
---|
| 1699 | s_h3 = idCopy(s_mod); |
---|
| 1700 | idPrepareStd(s_h3, k+comps_to_add); |
---|
| 1701 | } |
---|
| 1702 | else |
---|
| 1703 | { |
---|
| 1704 | s_h3 = idPrepare(s_mod,(tHomog)FALSE,k+comps_to_add,NULL); |
---|
| 1705 | } |
---|
| 1706 | if (!goodShape) |
---|
| 1707 | { |
---|
| 1708 | for (j=0;j<IDELEMS(s_h3);j++) |
---|
| 1709 | { |
---|
| 1710 | if ((s_h3->m[j] != NULL) && (pMinComp(s_h3->m[j]) > k)) |
---|
| 1711 | pDelete(&(s_h3->m[j])); |
---|
| 1712 | } |
---|
| 1713 | } |
---|
| 1714 | idSkipZeroes(s_h3); |
---|
| 1715 | if (lsmod==0) |
---|
| 1716 | { |
---|
| 1717 | for (j=IDELEMS(s_temp);j>0;j--) |
---|
| 1718 | { |
---|
| 1719 | if (s_temp->m[j-1]!=NULL) |
---|
| 1720 | pShift(&(s_temp->m[j-1]),1); |
---|
| 1721 | } |
---|
| 1722 | } |
---|
| 1723 | if (unit!=NULL) |
---|
| 1724 | { |
---|
| 1725 | for(j = 0;j<comps_to_add;j++) |
---|
| 1726 | { |
---|
| 1727 | p = s_temp->m[j]; |
---|
| 1728 | if (p!=NULL) |
---|
| 1729 | { |
---|
| 1730 | while (pNext(p)!=NULL) pIter(p); |
---|
| 1731 | pNext(p) = pOne(); |
---|
| 1732 | pIter(p); |
---|
| 1733 | pSetComp(p,1+j+k); |
---|
| 1734 | pSetmComp(p); |
---|
| 1735 | p = pNeg(p); |
---|
| 1736 | } |
---|
| 1737 | } |
---|
| 1738 | } |
---|
| 1739 | ideal s_result = kNF(s_h3,currQuotient,s_temp,k); |
---|
| 1740 | s_result->rank = s_h3->rank; |
---|
| 1741 | ideal s_rest = idInit(IDELEMS(s_result),k); |
---|
| 1742 | idDelete(&s_h3); |
---|
| 1743 | idDelete(&s_temp); |
---|
| 1744 | |
---|
| 1745 | for (j=0;j<IDELEMS(s_result);j++) |
---|
| 1746 | { |
---|
| 1747 | if (s_result->m[j]!=NULL) |
---|
| 1748 | { |
---|
| 1749 | if (pGetComp(s_result->m[j])<=k) |
---|
| 1750 | { |
---|
| 1751 | if (!divide) |
---|
| 1752 | { |
---|
| 1753 | if (isSB) |
---|
| 1754 | { |
---|
| 1755 | WarnS("first module not a standardbasis\n" |
---|
| 1756 | "// ** or second not a proper submodule"); |
---|
| 1757 | } |
---|
| 1758 | else |
---|
[5b02a5] | 1759 | WerrorS("2nd module does not lies in the first"); |
---|
[35aab3] | 1760 | idDelete(&s_result); |
---|
| 1761 | idDelete(&s_rest); |
---|
| 1762 | s_result=idInit(IDELEMS(submod),submod->rank); |
---|
| 1763 | break; |
---|
| 1764 | } |
---|
| 1765 | else |
---|
| 1766 | { |
---|
| 1767 | p = s_rest->m[j] = s_result->m[j]; |
---|
| 1768 | while ((pNext(p)!=NULL) && (pGetComp(pNext(p))<=k)) pIter(p); |
---|
| 1769 | s_result->m[j] = pNext(p); |
---|
| 1770 | pNext(p) = NULL; |
---|
| 1771 | } |
---|
| 1772 | } |
---|
| 1773 | pShift(&(s_result->m[j]),-k); |
---|
| 1774 | pNeg(s_result->m[j]); |
---|
| 1775 | } |
---|
| 1776 | } |
---|
| 1777 | if ((lsmod==0) && (!idIs0(s_rest))) |
---|
| 1778 | { |
---|
| 1779 | for (j=IDELEMS(s_rest);j>0;j--) |
---|
| 1780 | { |
---|
| 1781 | if (s_rest->m[j-1]!=NULL) |
---|
| 1782 | { |
---|
| 1783 | pShift(&(s_rest->m[j-1]),-1); |
---|
| 1784 | s_rest->m[j-1] = s_rest->m[j-1]; |
---|
| 1785 | } |
---|
| 1786 | } |
---|
| 1787 | } |
---|
| 1788 | if(syz_ring!=orig_ring) |
---|
| 1789 | { |
---|
| 1790 | idDelete(&s_mod); |
---|
| 1791 | rChangeCurrRing(orig_ring); |
---|
| 1792 | s_result = idrMoveR_NoSort(s_result, syz_ring); |
---|
| 1793 | s_rest = idrMoveR_NoSort(s_rest, syz_ring); |
---|
| 1794 | rKill(syz_ring); |
---|
| 1795 | } |
---|
| 1796 | if (rest!=NULL) |
---|
| 1797 | *rest = s_rest; |
---|
| 1798 | else |
---|
| 1799 | idDelete(&s_rest); |
---|
| 1800 | //idPrint(s_result); |
---|
| 1801 | if (unit!=NULL) |
---|
| 1802 | { |
---|
| 1803 | *unit=mpNew(comps_to_add,comps_to_add); |
---|
| 1804 | int i; |
---|
| 1805 | for(i=0;i<IDELEMS(s_result);i++) |
---|
| 1806 | { |
---|
| 1807 | poly p=s_result->m[i]; |
---|
| 1808 | poly q=NULL; |
---|
| 1809 | while(p!=NULL) |
---|
| 1810 | { |
---|
| 1811 | if(pGetComp(p)<=comps_to_add) |
---|
| 1812 | { |
---|
| 1813 | pSetComp(p,0); |
---|
| 1814 | if (q!=NULL) |
---|
| 1815 | { |
---|
| 1816 | pNext(q)=pNext(p); |
---|
| 1817 | } |
---|
| 1818 | else |
---|
| 1819 | { |
---|
| 1820 | pIter(s_result->m[i]); |
---|
| 1821 | } |
---|
| 1822 | pNext(p)=NULL; |
---|
| 1823 | MATELEM(*unit,i+1,i+1)=pAdd(MATELEM(*unit,i+1,i+1),p); |
---|
| 1824 | if(q!=NULL) p=pNext(q); |
---|
| 1825 | else p=s_result->m[i]; |
---|
| 1826 | } |
---|
| 1827 | else |
---|
| 1828 | { |
---|
| 1829 | q=p; |
---|
| 1830 | pIter(p); |
---|
| 1831 | } |
---|
| 1832 | } |
---|
| 1833 | pShift(&s_result->m[i],-comps_to_add); |
---|
| 1834 | } |
---|
| 1835 | } |
---|
| 1836 | return s_result; |
---|
| 1837 | } |
---|
| 1838 | |
---|
| 1839 | /*2 |
---|
| 1840 | *computes division of P by Q with remainder up to (w-weighted) degree n |
---|
| 1841 | *P, Q, and w are not changed |
---|
| 1842 | */ |
---|
| 1843 | void idLiftW(ideal P,ideal Q,int n,matrix &T, ideal &R,short *w) |
---|
| 1844 | { |
---|
[62dd9b] | 1845 | long N=0; |
---|
[35aab3] | 1846 | int i; |
---|
| 1847 | for(i=IDELEMS(Q)-1;i>=0;i--) |
---|
| 1848 | if(w==NULL) |
---|
| 1849 | N=si_max(N,pDeg(Q->m[i])); |
---|
| 1850 | else |
---|
| 1851 | N=si_max(N,pDegW(Q->m[i],w)); |
---|
| 1852 | N+=n; |
---|
| 1853 | |
---|
| 1854 | T=mpNew(IDELEMS(Q),IDELEMS(P)); |
---|
| 1855 | R=idInit(IDELEMS(P),P->rank); |
---|
| 1856 | |
---|
| 1857 | for(i=IDELEMS(P)-1;i>=0;i--) |
---|
| 1858 | { |
---|
| 1859 | poly p; |
---|
| 1860 | if(w==NULL) |
---|
| 1861 | p=ppJet(P->m[i],N); |
---|
| 1862 | else |
---|
| 1863 | p=ppJetW(P->m[i],N,w); |
---|
| 1864 | |
---|
| 1865 | int j=IDELEMS(Q)-1; |
---|
| 1866 | while(p!=NULL) |
---|
| 1867 | { |
---|
| 1868 | if(pDivisibleBy(Q->m[j],p)) |
---|
| 1869 | { |
---|
| 1870 | poly p0=pDivideM(pHead(p),pHead(Q->m[j])); |
---|
| 1871 | if(w==NULL) |
---|
| 1872 | p=pJet(pSub(p,ppMult_mm(Q->m[j],p0)),N); |
---|
| 1873 | else |
---|
| 1874 | p=pJetW(pSub(p,ppMult_mm(Q->m[j],p0)),N,w); |
---|
| 1875 | pNormalize(p); |
---|
| 1876 | if(w==NULL&&pDeg(p0)>n||w!=NULL&&pDegW(p0,w)>n) |
---|
| 1877 | pDelete(&p0); |
---|
| 1878 | else |
---|
| 1879 | MATELEM(T,j+1,i+1)=pAdd(MATELEM(T,j+1,i+1),p0); |
---|
| 1880 | j=IDELEMS(Q)-1; |
---|
| 1881 | } |
---|
| 1882 | else |
---|
| 1883 | { |
---|
| 1884 | if(j==0) |
---|
| 1885 | { |
---|
| 1886 | poly p0=p; |
---|
| 1887 | pIter(p); |
---|
| 1888 | pNext(p0)=NULL; |
---|
| 1889 | if(w==NULL&&pDeg(p0)>n||w!=NULL&&pDegW(p0,w)>n) |
---|
| 1890 | pDelete(&p0); |
---|
| 1891 | else |
---|
| 1892 | R->m[i]=pAdd(R->m[i],p0); |
---|
| 1893 | j=IDELEMS(Q)-1; |
---|
| 1894 | } |
---|
| 1895 | else |
---|
| 1896 | j--; |
---|
| 1897 | } |
---|
| 1898 | } |
---|
| 1899 | } |
---|
| 1900 | } |
---|
| 1901 | |
---|
| 1902 | /*2 |
---|
[e90187] | 1903 | *computes the quotient of h1,h2 : internal routine for idQuot |
---|
| 1904 | *BEWARE: the returned ideals may contain incorrectly ordered polys ! |
---|
[35aab3] | 1905 | * |
---|
| 1906 | */ |
---|
| 1907 | static ideal idInitializeQuot (ideal h1, ideal h2, BOOLEAN h1IsStb, |
---|
| 1908 | BOOLEAN *addOnlyOne, int *kkmax) |
---|
| 1909 | { |
---|
| 1910 | ideal temph1; |
---|
| 1911 | poly p,q = NULL; |
---|
| 1912 | int i,l,ll,k,kkk,kmax; |
---|
| 1913 | int j = 0; |
---|
| 1914 | int k1 = idRankFreeModule(h1); |
---|
| 1915 | int k2 = idRankFreeModule(h2); |
---|
| 1916 | tHomog hom=isNotHomog; |
---|
| 1917 | |
---|
| 1918 | k=si_max(k1,k2); |
---|
| 1919 | if (k==0) |
---|
| 1920 | k = 1; |
---|
| 1921 | if ((k2==0) && (k>1)) *addOnlyOne = FALSE; |
---|
| 1922 | |
---|
| 1923 | intvec * weights; |
---|
| 1924 | hom = (tHomog)idHomModule(h1,currQuotient,&weights); |
---|
| 1925 | if (addOnlyOne && (!h1IsStb)) |
---|
| 1926 | temph1 = kStd(h1,currQuotient,hom,&weights,NULL); |
---|
| 1927 | else |
---|
| 1928 | temph1 = idCopy(h1); |
---|
| 1929 | if (weights!=NULL) delete weights; |
---|
| 1930 | idTest(temph1); |
---|
| 1931 | /*--- making a single vector from h2 ---------------------*/ |
---|
| 1932 | for (i=0; i<IDELEMS(h2); i++) |
---|
| 1933 | { |
---|
| 1934 | if (h2->m[i] != NULL) |
---|
| 1935 | { |
---|
| 1936 | p = pCopy(h2->m[i]); |
---|
| 1937 | if (k2 == 0) |
---|
| 1938 | pShift(&p,j*k+1); |
---|
| 1939 | else |
---|
| 1940 | pShift(&p,j*k); |
---|
| 1941 | q = pAdd(q,p); |
---|
| 1942 | j++; |
---|
| 1943 | } |
---|
| 1944 | } |
---|
| 1945 | *kkmax = kmax = j*k+1; |
---|
| 1946 | /*--- adding a monomial for the result (syzygy) ----------*/ |
---|
| 1947 | p = q; |
---|
| 1948 | while (pNext(p)!=NULL) pIter(p); |
---|
| 1949 | pNext(p) = pOne(); |
---|
| 1950 | pIter(p); |
---|
| 1951 | pSetComp(p,kmax); |
---|
| 1952 | pSetmComp(p); |
---|
| 1953 | /*--- constructing the big matrix ------------------------*/ |
---|
| 1954 | ideal h4 = idInit(16,kmax+k-1); |
---|
| 1955 | h4->m[0] = q; |
---|
| 1956 | if (k2 == 0) |
---|
| 1957 | { |
---|
| 1958 | if (k > IDELEMS(h4)) |
---|
| 1959 | { |
---|
| 1960 | pEnlargeSet(&(h4->m),IDELEMS(h4),k-IDELEMS(h4)); |
---|
| 1961 | IDELEMS(h4) = k; |
---|
| 1962 | } |
---|
| 1963 | for (i=1; i<k; i++) |
---|
| 1964 | { |
---|
| 1965 | p = pCopy_noCheck(h4->m[i-1]); |
---|
| 1966 | pShift(&p,1); |
---|
| 1967 | h4->m[i] = p; |
---|
| 1968 | } |
---|
| 1969 | } |
---|
| 1970 | |
---|
| 1971 | kkk = IDELEMS(h4); |
---|
| 1972 | i = IDELEMS(temph1); |
---|
| 1973 | while ((i>0) && (temph1->m[i-1]==NULL)) i--; |
---|
| 1974 | for (l=0; l<i; l++) |
---|
| 1975 | { |
---|
| 1976 | if(temph1->m[l]!=NULL) |
---|
| 1977 | { |
---|
| 1978 | for (ll=0; ll<j; ll++) |
---|
| 1979 | { |
---|
| 1980 | p = pCopy(temph1->m[l]); |
---|
| 1981 | if (k1 == 0) |
---|
| 1982 | pShift(&p,ll*k+1); |
---|
| 1983 | else |
---|
| 1984 | pShift(&p,ll*k); |
---|
| 1985 | if (kkk >= IDELEMS(h4)) |
---|
| 1986 | { |
---|
| 1987 | pEnlargeSet(&(h4->m),IDELEMS(h4),16); |
---|
| 1988 | IDELEMS(h4) += 16; |
---|
| 1989 | } |
---|
| 1990 | h4->m[kkk] = p; |
---|
| 1991 | kkk++; |
---|
| 1992 | } |
---|
| 1993 | } |
---|
| 1994 | } |
---|
| 1995 | /*--- if h2 goes in as single vector - the h1-part is just SB ---*/ |
---|
| 1996 | if (*addOnlyOne) |
---|
| 1997 | { |
---|
| 1998 | p = h4->m[0]; |
---|
| 1999 | for (i=0;i<IDELEMS(h4)-1;i++) |
---|
| 2000 | { |
---|
| 2001 | h4->m[i] = h4->m[i+1]; |
---|
| 2002 | } |
---|
| 2003 | h4->m[IDELEMS(h4)-1] = p; |
---|
| 2004 | idSkipZeroes(h4); |
---|
| 2005 | test |= Sy_bit(OPT_SB_1); |
---|
| 2006 | } |
---|
| 2007 | idDelete(&temph1); |
---|
| 2008 | return h4; |
---|
| 2009 | } |
---|
| 2010 | /*2 |
---|
| 2011 | *computes the quotient of h1,h2 |
---|
| 2012 | */ |
---|
| 2013 | ideal idQuot (ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN resultIsIdeal) |
---|
| 2014 | { |
---|
| 2015 | // first check for special case h1:(0) |
---|
| 2016 | if (idIs0(h2)) |
---|
| 2017 | { |
---|
| 2018 | ideal res; |
---|
| 2019 | if (resultIsIdeal) |
---|
| 2020 | { |
---|
| 2021 | res = idInit(1,1); |
---|
| 2022 | res->m[0] = pOne(); |
---|
| 2023 | } |
---|
| 2024 | else |
---|
| 2025 | res = idFreeModule(h1->rank); |
---|
| 2026 | return res; |
---|
| 2027 | } |
---|
| 2028 | BITSET old_test=test; |
---|
| 2029 | poly p,q = NULL; |
---|
| 2030 | int i,l,ll,k,kkk,kmax; |
---|
| 2031 | BOOLEAN addOnlyOne=TRUE; |
---|
| 2032 | tHomog hom=isNotHomog; |
---|
| 2033 | intvec * weights1; |
---|
| 2034 | |
---|
| 2035 | ideal s_h4 = idInitializeQuot (h1,h2,h1IsStb,&addOnlyOne,&kmax); |
---|
| 2036 | |
---|
| 2037 | hom = (tHomog)idHomModule(s_h4,currQuotient,&weights1); |
---|
| 2038 | |
---|
| 2039 | ring orig_ring=currRing; |
---|
| 2040 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 2041 | rSetSyzComp(kmax-1); |
---|
| 2042 | if (orig_ring!=syz_ring) |
---|
| 2043 | // s_h4 = idrMoveR_NoSort(s_h4,orig_ring); |
---|
| 2044 | s_h4 = idrMoveR(s_h4,orig_ring); |
---|
| 2045 | idTest(s_h4); |
---|
| 2046 | ideal s_h3; |
---|
| 2047 | if (addOnlyOne) |
---|
| 2048 | { |
---|
| 2049 | s_h3 = kStd(s_h4,currQuotient,hom,&weights1,NULL,kmax-1,IDELEMS(s_h4)-1); |
---|
| 2050 | } |
---|
| 2051 | else |
---|
| 2052 | { |
---|
| 2053 | s_h3 = kStd(s_h4,currQuotient,hom,&weights1,NULL,kmax-1); |
---|
| 2054 | } |
---|
| 2055 | idTest(s_h3); |
---|
| 2056 | if (weights1!=NULL) delete weights1; |
---|
| 2057 | idDelete(&s_h4); |
---|
| 2058 | |
---|
| 2059 | |
---|
| 2060 | for (i=0;i<IDELEMS(s_h3);i++) |
---|
| 2061 | { |
---|
| 2062 | if ((s_h3->m[i]!=NULL) && (pGetComp(s_h3->m[i])>=kmax)) |
---|
| 2063 | { |
---|
| 2064 | if (resultIsIdeal) |
---|
| 2065 | pShift(&s_h3->m[i],-kmax); |
---|
| 2066 | else |
---|
| 2067 | pShift(&s_h3->m[i],-kmax+1); |
---|
| 2068 | } |
---|
| 2069 | else |
---|
| 2070 | pDelete(&s_h3->m[i]); |
---|
| 2071 | } |
---|
| 2072 | if (resultIsIdeal) |
---|
| 2073 | s_h3->rank = 1; |
---|
| 2074 | else |
---|
| 2075 | s_h3->rank = h1->rank; |
---|
| 2076 | if(syz_ring!=orig_ring) |
---|
| 2077 | { |
---|
| 2078 | // pDelete(&q); |
---|
| 2079 | rChangeCurrRing(orig_ring); |
---|
| 2080 | s_h3 = idrMoveR_NoSort(s_h3, syz_ring); |
---|
| 2081 | rKill(syz_ring); |
---|
| 2082 | } |
---|
| 2083 | idSkipZeroes(s_h3); |
---|
| 2084 | test = old_test; |
---|
| 2085 | idTest(s_h3); |
---|
| 2086 | return s_h3; |
---|
| 2087 | } |
---|
| 2088 | |
---|
| 2089 | /*2 |
---|
| 2090 | *computes recursively all monomials of a certain degree |
---|
| 2091 | *in every step the actvar-th entry in the exponential |
---|
| 2092 | *vector is incremented and the other variables are |
---|
| 2093 | *computed by recursive calls of makemonoms |
---|
| 2094 | *if the last variable is reached, the difference to the |
---|
| 2095 | *degree is computed directly |
---|
| 2096 | *vars is the number variables |
---|
| 2097 | *actvar is the actual variable to handle |
---|
| 2098 | *deg is the degree of the monomials to compute |
---|
| 2099 | *monomdeg is the actual degree of the monomial in consideration |
---|
| 2100 | */ |
---|
| 2101 | static void makemonoms(int vars,int actvar,int deg,int monomdeg) |
---|
| 2102 | { |
---|
| 2103 | poly p; |
---|
| 2104 | int i=0; |
---|
| 2105 | |
---|
| 2106 | if ((idpowerpoint == 0) && (actvar ==1)) |
---|
| 2107 | { |
---|
| 2108 | idpower[idpowerpoint] = pOne(); |
---|
| 2109 | monomdeg = 0; |
---|
| 2110 | } |
---|
| 2111 | while (i<=deg) |
---|
| 2112 | { |
---|
| 2113 | if (deg == monomdeg) |
---|
| 2114 | { |
---|
| 2115 | pSetm(idpower[idpowerpoint]); |
---|
| 2116 | idpowerpoint++; |
---|
| 2117 | return; |
---|
| 2118 | } |
---|
| 2119 | if (actvar == vars) |
---|
| 2120 | { |
---|
| 2121 | pSetExp(idpower[idpowerpoint],actvar,deg-monomdeg); |
---|
| 2122 | pSetm(idpower[idpowerpoint]); |
---|
| 2123 | pTest(idpower[idpowerpoint]); |
---|
| 2124 | idpowerpoint++; |
---|
| 2125 | return; |
---|
| 2126 | } |
---|
| 2127 | else |
---|
| 2128 | { |
---|
| 2129 | p = pCopy(idpower[idpowerpoint]); |
---|
| 2130 | makemonoms(vars,actvar+1,deg,monomdeg); |
---|
| 2131 | idpower[idpowerpoint] = p; |
---|
| 2132 | } |
---|
| 2133 | monomdeg++; |
---|
| 2134 | pSetExp(idpower[idpowerpoint],actvar,pGetExp(idpower[idpowerpoint],actvar)+1); |
---|
| 2135 | pSetm(idpower[idpowerpoint]); |
---|
| 2136 | pTest(idpower[idpowerpoint]); |
---|
| 2137 | i++; |
---|
| 2138 | } |
---|
| 2139 | } |
---|
| 2140 | |
---|
| 2141 | /*2 |
---|
| 2142 | *returns the deg-th power of the maximal ideal of 0 |
---|
| 2143 | */ |
---|
| 2144 | ideal idMaxIdeal(int deg) |
---|
| 2145 | { |
---|
| 2146 | if (deg < 0) |
---|
| 2147 | { |
---|
| 2148 | WarnS("maxideal: power must be non-negative"); |
---|
| 2149 | } |
---|
| 2150 | if (deg < 1) |
---|
| 2151 | { |
---|
| 2152 | ideal I=idInit(1,1); |
---|
| 2153 | I->m[0]=pOne(); |
---|
| 2154 | return I; |
---|
| 2155 | } |
---|
| 2156 | if (deg == 1) |
---|
| 2157 | { |
---|
| 2158 | return idMaxIdeal(); |
---|
| 2159 | } |
---|
| 2160 | |
---|
| 2161 | int vars = currRing->N; |
---|
| 2162 | int i = binom(vars+deg-1,deg); |
---|
| 2163 | if (i<=0) return idInit(1,1); |
---|
| 2164 | ideal id=idInit(i,1); |
---|
| 2165 | idpower = id->m; |
---|
| 2166 | idpowerpoint = 0; |
---|
| 2167 | makemonoms(vars,1,deg,0); |
---|
| 2168 | idpower = NULL; |
---|
| 2169 | idpowerpoint = 0; |
---|
| 2170 | return id; |
---|
| 2171 | } |
---|
| 2172 | |
---|
| 2173 | /*2 |
---|
| 2174 | *computes recursively all generators of a certain degree |
---|
| 2175 | *of the ideal "givenideal" |
---|
| 2176 | *elms is the number elements in the given ideal |
---|
| 2177 | *actelm is the actual element to handle |
---|
| 2178 | *deg is the degree of the power to compute |
---|
| 2179 | *gendeg is the actual degree of the generator in consideration |
---|
| 2180 | */ |
---|
| 2181 | static void makepotence(int elms,int actelm,int deg,int gendeg) |
---|
| 2182 | { |
---|
| 2183 | poly p; |
---|
| 2184 | int i=0; |
---|
| 2185 | |
---|
| 2186 | if ((idpowerpoint == 0) && (actelm ==1)) |
---|
| 2187 | { |
---|
| 2188 | idpower[idpowerpoint] = pOne(); |
---|
| 2189 | gendeg = 0; |
---|
| 2190 | } |
---|
| 2191 | while (i<=deg) |
---|
| 2192 | { |
---|
| 2193 | if (deg == gendeg) |
---|
| 2194 | { |
---|
| 2195 | idpowerpoint++; |
---|
| 2196 | return; |
---|
| 2197 | } |
---|
| 2198 | if (actelm == elms) |
---|
| 2199 | { |
---|
| 2200 | p=pPower(pCopy(givenideal[actelm-1]),deg-gendeg); |
---|
| 2201 | idpower[idpowerpoint]=pMult(idpower[idpowerpoint],p); |
---|
| 2202 | idpowerpoint++; |
---|
| 2203 | return; |
---|
| 2204 | } |
---|
| 2205 | else |
---|
| 2206 | { |
---|
| 2207 | p = pCopy(idpower[idpowerpoint]); |
---|
| 2208 | makepotence(elms,actelm+1,deg,gendeg); |
---|
| 2209 | idpower[idpowerpoint] = p; |
---|
| 2210 | } |
---|
| 2211 | gendeg++; |
---|
| 2212 | idpower[idpowerpoint]=pMult(idpower[idpowerpoint],pCopy(givenideal[actelm-1])); |
---|
| 2213 | i++; |
---|
| 2214 | } |
---|
| 2215 | } |
---|
| 2216 | |
---|
| 2217 | /*2 |
---|
| 2218 | *returns the deg-th power of the ideal gid |
---|
| 2219 | */ |
---|
| 2220 | //ideal idPower(ideal gid,int deg) |
---|
| 2221 | //{ |
---|
| 2222 | // int i; |
---|
| 2223 | // ideal id; |
---|
| 2224 | // |
---|
| 2225 | // if (deg < 1) deg = 1; |
---|
| 2226 | // i = binom(IDELEMS(gid)+deg-1,deg); |
---|
| 2227 | // id=idInit(i,1); |
---|
| 2228 | // idpower = id->m; |
---|
| 2229 | // givenideal = gid->m; |
---|
| 2230 | // idpowerpoint = 0; |
---|
| 2231 | // makepotence(IDELEMS(gid),1,deg,0); |
---|
| 2232 | // idpower = NULL; |
---|
| 2233 | // givenideal = NULL; |
---|
| 2234 | // idpowerpoint = 0; |
---|
| 2235 | // return id; |
---|
| 2236 | //} |
---|
| 2237 | static void idNextPotence(ideal given, ideal result, |
---|
| 2238 | int begin, int end, int deg, int restdeg, poly ap) |
---|
| 2239 | { |
---|
| 2240 | poly p; |
---|
| 2241 | int i; |
---|
| 2242 | |
---|
| 2243 | p = pPower(pCopy(given->m[begin]),restdeg); |
---|
| 2244 | i = result->nrows; |
---|
| 2245 | result->m[i] = pMult(pCopy(ap),p); |
---|
| 2246 | //PrintS("."); |
---|
| 2247 | (result->nrows)++; |
---|
| 2248 | if (result->nrows >= IDELEMS(result)) |
---|
| 2249 | { |
---|
| 2250 | pEnlargeSet(&(result->m),IDELEMS(result),16); |
---|
| 2251 | IDELEMS(result) += 16; |
---|
| 2252 | } |
---|
| 2253 | if (begin == end) return; |
---|
| 2254 | for (i=restdeg-1;i>0;i--) |
---|
| 2255 | { |
---|
| 2256 | p = pPower(pCopy(given->m[begin]),i); |
---|
| 2257 | p = pMult(pCopy(ap),p); |
---|
| 2258 | idNextPotence(given, result, begin+1, end, deg, restdeg-i, p); |
---|
| 2259 | pDelete(&p); |
---|
| 2260 | } |
---|
| 2261 | idNextPotence(given, result, begin+1, end, deg, restdeg, ap); |
---|
| 2262 | } |
---|
| 2263 | |
---|
| 2264 | ideal idPower(ideal given,int exp) |
---|
| 2265 | { |
---|
| 2266 | ideal result,temp; |
---|
| 2267 | poly p1; |
---|
| 2268 | int i; |
---|
| 2269 | |
---|
| 2270 | if (idIs0(given)) return idInit(1,1); |
---|
| 2271 | temp = idCopy(given); |
---|
| 2272 | idSkipZeroes(temp); |
---|
| 2273 | i = binom(IDELEMS(temp)+exp-1,exp); |
---|
| 2274 | result = idInit(i,1); |
---|
| 2275 | result->nrows = 0; |
---|
| 2276 | //Print("ideal contains %d elements\n",i); |
---|
| 2277 | p1=pOne(); |
---|
| 2278 | idNextPotence(temp,result,0,IDELEMS(temp)-1,exp,exp,p1); |
---|
| 2279 | pDelete(&p1); |
---|
| 2280 | idDelete(&temp); |
---|
| 2281 | result->nrows = 1; |
---|
| 2282 | idDelEquals(result); |
---|
[ff2fd1] | 2283 | idSkipZeroes(result); |
---|
[35aab3] | 2284 | return result; |
---|
| 2285 | } |
---|
| 2286 | |
---|
| 2287 | /*2 |
---|
| 2288 | * eliminate delVar (product of vars) in h1 |
---|
| 2289 | */ |
---|
| 2290 | ideal idElimination (ideal h1,poly delVar,intvec *hilb) |
---|
| 2291 | { |
---|
| 2292 | int i,j=0,k,l; |
---|
| 2293 | ideal h,hh, h3; |
---|
| 2294 | int *ord,*block0,*block1; |
---|
| 2295 | int ordersize=2; |
---|
| 2296 | int **wv; |
---|
| 2297 | tHomog hom; |
---|
| 2298 | intvec * w; |
---|
| 2299 | sip_sring tmpR; |
---|
| 2300 | ring origR = currRing; |
---|
| 2301 | |
---|
| 2302 | if (delVar==NULL) |
---|
| 2303 | { |
---|
| 2304 | return idCopy(h1); |
---|
| 2305 | } |
---|
| 2306 | if (currQuotient!=NULL) |
---|
| 2307 | { |
---|
| 2308 | WerrorS("cannot eliminate in a qring"); |
---|
| 2309 | return idCopy(h1); |
---|
| 2310 | } |
---|
| 2311 | if (idIs0(h1)) return idInit(1,h1->rank); |
---|
| 2312 | #ifdef HAVE_PLURAL |
---|
| 2313 | if (rIsPluralRing(currRing)) |
---|
| 2314 | /* in the NC case, we have to check the admissibility of */ |
---|
| 2315 | /* the subalgebra to be intersected with */ |
---|
| 2316 | { |
---|
[86016d] | 2317 | if (ncRingType(currRing)!=nc_skew) /* in (quasi)-commutative algebras every subalgebra is admissible */ |
---|
[35aab3] | 2318 | { |
---|
[ea68ed] | 2319 | if (nc_CheckSubalgebra(delVar,currRing)) |
---|
[35aab3] | 2320 | { |
---|
| 2321 | WerrorS("no elimination is possible: subalgebra is not admissible"); |
---|
| 2322 | return idCopy(h1); |
---|
| 2323 | } |
---|
| 2324 | } |
---|
| 2325 | } |
---|
| 2326 | #endif |
---|
| 2327 | hom=(tHomog)idHomModule(h1,NULL,&w); //sets w to weight vector or NULL |
---|
| 2328 | h3=idInit(16,h1->rank); |
---|
| 2329 | for (k=0;; k++) |
---|
| 2330 | { |
---|
| 2331 | if (currRing->order[k]!=0) ordersize++; |
---|
| 2332 | else break; |
---|
| 2333 | } |
---|
| 2334 | ord=(int*)omAlloc0(ordersize*sizeof(int)); |
---|
| 2335 | block0=(int*)omAlloc(ordersize*sizeof(int)); |
---|
| 2336 | block1=(int*)omAlloc(ordersize*sizeof(int)); |
---|
| 2337 | for (k=0;; k++) |
---|
| 2338 | { |
---|
| 2339 | if (currRing->order[k]!=0) |
---|
| 2340 | { |
---|
| 2341 | block0[k+1] = currRing->block0[k]; |
---|
| 2342 | block1[k+1] = currRing->block1[k]; |
---|
| 2343 | ord[k+1] = currRing->order[k]; |
---|
| 2344 | } |
---|
| 2345 | else |
---|
| 2346 | break; |
---|
| 2347 | } |
---|
| 2348 | block0[0] = 1; |
---|
| 2349 | block1[0] = pVariables; |
---|
| 2350 | wv=(int**) omAlloc0(ordersize*sizeof(int**)); |
---|
| 2351 | memcpy4(wv+1,currRing->wvhdl,(ordersize-1)*sizeof(int**)); |
---|
| 2352 | wv[0]=(int*)omAlloc((pVariables+1)*sizeof(int)); |
---|
| 2353 | memset(wv[0],0,(pVariables+1)*sizeof(int)); |
---|
| 2354 | for (j=0;j<pVariables;j++) |
---|
| 2355 | if (pGetExp(delVar,j+1)!=0) wv[0][j]=1; |
---|
| 2356 | // use this special ordering: like ringorder_a, except that pFDeg, pWeights |
---|
| 2357 | // ignore it |
---|
| 2358 | ord[0] = ringorder_aa; |
---|
| 2359 | |
---|
| 2360 | // fill in tmp ring to get back the data later on |
---|
| 2361 | tmpR = *origR; |
---|
| 2362 | tmpR.order = ord; |
---|
| 2363 | tmpR.block0 = block0; |
---|
| 2364 | tmpR.block1 = block1; |
---|
| 2365 | tmpR.wvhdl = wv; |
---|
| 2366 | rComplete(&tmpR, 1); |
---|
| 2367 | |
---|
[ea68ed] | 2368 | #ifdef HAVE_PLURAL |
---|
[e5fc4d4] | 2369 | /* update nc structure on tmpR */ |
---|
[8ebd1a0] | 2370 | if (rIsPluralRing(currRing)) |
---|
[e5fc4d4] | 2371 | { |
---|
[d76b58] | 2372 | BOOLEAN bBAD = FALSE; |
---|
[4d13e7] | 2373 | if ( nc_rComplete(origR, &tmpR) ) |
---|
[e5fc4d4] | 2374 | { |
---|
[8ebd1a0] | 2375 | Werror("error in nc_rComplete"); |
---|
[d76b58] | 2376 | bBAD = TRUE; |
---|
[e5fc4d4] | 2377 | } |
---|
[d76b58] | 2378 | if (!bBAD) |
---|
[8ebd1a0] | 2379 | { |
---|
| 2380 | /* tests the admissibility of the new elim. ordering */ |
---|
| 2381 | if ( nc_CheckOrdCondition( (&tmpR)->nc->D, &tmpR) ) |
---|
| 2382 | { |
---|
| 2383 | Werror("no elimination is possible: ordering condition is violated"); |
---|
[d76b58] | 2384 | bBAD = TRUE; |
---|
[8ebd1a0] | 2385 | } |
---|
| 2386 | } |
---|
[d76b58] | 2387 | if (bBAD) |
---|
[e5fc4d4] | 2388 | { |
---|
[8ebd1a0] | 2389 | // cleanup |
---|
| 2390 | omFree((ADDRESS)wv[0]); |
---|
| 2391 | omFreeSize((ADDRESS)wv,ordersize*sizeof(int**)); |
---|
| 2392 | omFreeSize((ADDRESS)ord,ordersize*sizeof(int)); |
---|
| 2393 | omFreeSize((ADDRESS)block0,ordersize*sizeof(int)); |
---|
| 2394 | omFreeSize((ADDRESS)block1,ordersize*sizeof(int)); |
---|
| 2395 | rUnComplete(&tmpR); |
---|
[4d13e7] | 2396 | if (w!=NULL) |
---|
[8ebd1a0] | 2397 | { |
---|
| 2398 | delete w; |
---|
| 2399 | } |
---|
| 2400 | return idCopy(h1); |
---|
[e5fc4d4] | 2401 | } |
---|
[ea68ed] | 2402 | } |
---|
| 2403 | #endif |
---|
[35aab3] | 2404 | // change into the new ring |
---|
| 2405 | //pChangeRing(pVariables,currRing->OrdSgn,ord,block0,block1,wv); |
---|
| 2406 | rChangeCurrRing(&tmpR); |
---|
[ea68ed] | 2407 | |
---|
[35aab3] | 2408 | h = idInit(IDELEMS(h1),h1->rank); |
---|
| 2409 | // fetch data from the old ring |
---|
| 2410 | for (k=0;k<IDELEMS(h1);k++) h->m[k] = prCopyR( h1->m[k], origR); |
---|
| 2411 | // compute kStd |
---|
[cbc7e3] | 2412 | #if 1 |
---|
[35aab3] | 2413 | hh = kStd(h,NULL,hom,&w,hilb); |
---|
| 2414 | idDelete(&h); |
---|
[cbc7e3] | 2415 | #else |
---|
| 2416 | extern ideal kGroebner(ideal F, ideal Q); |
---|
| 2417 | hh=kGroebner(h,NULL); |
---|
| 2418 | #endif |
---|
[35aab3] | 2419 | // go back to the original ring |
---|
| 2420 | rChangeCurrRing(origR); |
---|
| 2421 | i = IDELEMS(hh)-1; |
---|
| 2422 | while ((i >= 0) && (hh->m[i] == NULL)) i--; |
---|
| 2423 | j = -1; |
---|
| 2424 | // fetch data from temp ring |
---|
| 2425 | for (k=0; k<=i; k++) |
---|
| 2426 | { |
---|
| 2427 | l=pVariables; |
---|
| 2428 | while ((l>0) && (p_GetExp( hh->m[k],l,&tmpR)*pGetExp(delVar,l)==0)) l--; |
---|
| 2429 | if (l==0) |
---|
| 2430 | { |
---|
| 2431 | j++; |
---|
| 2432 | if (j >= IDELEMS(h3)) |
---|
| 2433 | { |
---|
| 2434 | pEnlargeSet(&(h3->m),IDELEMS(h3),16); |
---|
| 2435 | IDELEMS(h3) += 16; |
---|
| 2436 | } |
---|
| 2437 | h3->m[j] = prCopyR( hh->m[k], &tmpR); |
---|
| 2438 | } |
---|
| 2439 | } |
---|
| 2440 | id_Delete(&hh, &tmpR); |
---|
| 2441 | idSkipZeroes(h3); |
---|
| 2442 | omFree((ADDRESS)wv[0]); |
---|
| 2443 | omFreeSize((ADDRESS)wv,ordersize*sizeof(int**)); |
---|
| 2444 | omFreeSize((ADDRESS)ord,ordersize*sizeof(int)); |
---|
| 2445 | omFreeSize((ADDRESS)block0,ordersize*sizeof(int)); |
---|
| 2446 | omFreeSize((ADDRESS)block1,ordersize*sizeof(int)); |
---|
| 2447 | rUnComplete(&tmpR); |
---|
| 2448 | if (w!=NULL) |
---|
| 2449 | delete w; |
---|
| 2450 | return h3; |
---|
| 2451 | } |
---|
| 2452 | |
---|
| 2453 | #ifdef WITH_OLD_MINOR |
---|
| 2454 | /*2 |
---|
| 2455 | * compute all ar-minors of the matrix a |
---|
| 2456 | */ |
---|
| 2457 | ideal idMinors(matrix a, int ar, ideal R) |
---|
| 2458 | { |
---|
| 2459 | int i,j,k,size; |
---|
| 2460 | int *rowchoise,*colchoise; |
---|
| 2461 | BOOLEAN rowch,colch; |
---|
| 2462 | ideal result; |
---|
| 2463 | matrix tmp; |
---|
| 2464 | poly p,q; |
---|
| 2465 | |
---|
| 2466 | i = binom(a->rows(),ar); |
---|
| 2467 | j = binom(a->cols(),ar); |
---|
| 2468 | |
---|
| 2469 | rowchoise=(int *)omAlloc(ar*sizeof(int)); |
---|
| 2470 | colchoise=(int *)omAlloc(ar*sizeof(int)); |
---|
| 2471 | if ((i>512) || (j>512) || (i*j >512)) size=512; |
---|
| 2472 | else size=i*j; |
---|
| 2473 | result=idInit(size,1); |
---|
| 2474 | tmp=mpNew(ar,ar); |
---|
| 2475 | k = 0; /* the index in result*/ |
---|
| 2476 | idInitChoise(ar,1,a->rows(),&rowch,rowchoise); |
---|
| 2477 | while (!rowch) |
---|
| 2478 | { |
---|
| 2479 | idInitChoise(ar,1,a->cols(),&colch,colchoise); |
---|
| 2480 | while (!colch) |
---|
| 2481 | { |
---|
| 2482 | for (i=1; i<=ar; i++) |
---|
| 2483 | { |
---|
| 2484 | for (j=1; j<=ar; j++) |
---|
| 2485 | { |
---|
| 2486 | MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]); |
---|
| 2487 | } |
---|
| 2488 | } |
---|
| 2489 | p = mpDetBareiss(tmp); |
---|
| 2490 | if (p!=NULL) |
---|
| 2491 | { |
---|
| 2492 | if (R!=NULL) |
---|
| 2493 | { |
---|
| 2494 | q = p; |
---|
| 2495 | p = kNF(R,currQuotient,q); |
---|
| 2496 | pDelete(&q); |
---|
| 2497 | } |
---|
| 2498 | if (p!=NULL) |
---|
| 2499 | { |
---|
| 2500 | if (k>=size) |
---|
| 2501 | { |
---|
| 2502 | pEnlargeSet(&result->m,size,32); |
---|
| 2503 | size += 32; |
---|
| 2504 | } |
---|
| 2505 | result->m[k] = p; |
---|
| 2506 | k++; |
---|
| 2507 | } |
---|
| 2508 | } |
---|
| 2509 | idGetNextChoise(ar,a->cols(),&colch,colchoise); |
---|
| 2510 | } |
---|
| 2511 | idGetNextChoise(ar,a->rows(),&rowch,rowchoise); |
---|
| 2512 | } |
---|
| 2513 | /*delete the matrix tmp*/ |
---|
| 2514 | for (i=1; i<=ar; i++) |
---|
| 2515 | { |
---|
| 2516 | for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL; |
---|
| 2517 | } |
---|
| 2518 | idDelete((ideal*)&tmp); |
---|
| 2519 | if (k==0) |
---|
| 2520 | { |
---|
| 2521 | k=1; |
---|
| 2522 | result->m[0]=NULL; |
---|
| 2523 | } |
---|
| 2524 | omFreeSize((ADDRESS)rowchoise,ar*sizeof(int)); |
---|
| 2525 | omFreeSize((ADDRESS)colchoise,ar*sizeof(int)); |
---|
| 2526 | pEnlargeSet(&result->m,size,k-size); |
---|
| 2527 | IDELEMS(result) = k; |
---|
| 2528 | return (result); |
---|
| 2529 | } |
---|
| 2530 | #else |
---|
| 2531 | /*2 |
---|
| 2532 | * compute all ar-minors of the matrix a |
---|
| 2533 | * the caller of mpRecMin |
---|
| 2534 | * the elements of the result are not in R (if R!=NULL) |
---|
| 2535 | */ |
---|
| 2536 | ideal idMinors(matrix a, int ar, ideal R) |
---|
| 2537 | { |
---|
| 2538 | int elems=0; |
---|
| 2539 | int r=a->nrows,c=a->ncols; |
---|
| 2540 | int i; |
---|
| 2541 | matrix b; |
---|
| 2542 | ideal result,h; |
---|
| 2543 | ring origR; |
---|
| 2544 | sip_sring tmpR; |
---|
| 2545 | Exponent_t bound; |
---|
| 2546 | |
---|
| 2547 | if((ar<=0) || (ar>r) || (ar>c)) |
---|
| 2548 | { |
---|
| 2549 | Werror("%d-th minor, matrix is %dx%d",ar,r,c); |
---|
| 2550 | return NULL; |
---|
| 2551 | } |
---|
| 2552 | h = idMatrix2Module(mpCopy(a)); |
---|
| 2553 | bound = smExpBound(h,c,r,ar); |
---|
| 2554 | idDelete(&h); |
---|
| 2555 | smRingChange(&origR,tmpR,bound); |
---|
| 2556 | b = mpNew(r,c); |
---|
| 2557 | for (i=r*c-1;i>=0;i--) |
---|
| 2558 | { |
---|
| 2559 | if (a->m[i]) |
---|
| 2560 | b->m[i] = prCopyR(a->m[i],origR); |
---|
| 2561 | } |
---|
| 2562 | if (R) R = idrCopyR(R,origR); |
---|
| 2563 | result=idInit(32,1); |
---|
| 2564 | if(ar>1) mpRecMin(ar-1,result,elems,b,r,c,NULL,R); |
---|
| 2565 | else mpMinorToResult(result,elems,b,r,c,R); |
---|
| 2566 | idDelete((ideal *)&b); |
---|
| 2567 | if (R) idDelete(&R); |
---|
| 2568 | idSkipZeroes(result); |
---|
| 2569 | rChangeCurrRing(origR); |
---|
| 2570 | result = idrMoveR(result,&tmpR); |
---|
| 2571 | smRingClean(origR,tmpR); |
---|
| 2572 | idTest(result); |
---|
| 2573 | return result; |
---|
| 2574 | } |
---|
| 2575 | #endif |
---|
| 2576 | |
---|
| 2577 | /*2 |
---|
| 2578 | *skips all zeroes and double elements, searches also for units |
---|
| 2579 | */ |
---|
[10ea45f] | 2580 | void idCompactify(ideal id) |
---|
[35aab3] | 2581 | { |
---|
| 2582 | int i,j; |
---|
| 2583 | BOOLEAN b=FALSE; |
---|
| 2584 | |
---|
| 2585 | i = IDELEMS(id)-1; |
---|
| 2586 | while ((! b) && (i>=0)) |
---|
| 2587 | { |
---|
| 2588 | b=pIsUnit(id->m[i]); |
---|
| 2589 | i--; |
---|
| 2590 | } |
---|
| 2591 | if (b) |
---|
| 2592 | { |
---|
[10ea45f] | 2593 | for(i=IDELEMS(id)-1;i>=0;i--) pDelete(&id->m[i]); |
---|
| 2594 | id->m[0]=pOne(); |
---|
[35aab3] | 2595 | } |
---|
| 2596 | else |
---|
| 2597 | { |
---|
[10ea45f] | 2598 | idDelMultiples(id); |
---|
[35aab3] | 2599 | } |
---|
[962de7] | 2600 | idSkipZeroes(id); |
---|
[35aab3] | 2601 | } |
---|
| 2602 | |
---|
| 2603 | /*2 |
---|
| 2604 | *returns TRUE if id1 is a submodule of id2 |
---|
| 2605 | */ |
---|
| 2606 | BOOLEAN idIsSubModule(ideal id1,ideal id2) |
---|
| 2607 | { |
---|
| 2608 | int i; |
---|
| 2609 | poly p; |
---|
| 2610 | |
---|
| 2611 | if (idIs0(id1)) return TRUE; |
---|
| 2612 | for (i=0;i<IDELEMS(id1);i++) |
---|
| 2613 | { |
---|
| 2614 | if (id1->m[i] != NULL) |
---|
| 2615 | { |
---|
| 2616 | p = kNF(id2,currQuotient,id1->m[i]); |
---|
| 2617 | if (p != NULL) |
---|
| 2618 | { |
---|
| 2619 | pDelete(&p); |
---|
| 2620 | return FALSE; |
---|
| 2621 | } |
---|
| 2622 | } |
---|
| 2623 | } |
---|
| 2624 | return TRUE; |
---|
| 2625 | } |
---|
| 2626 | |
---|
| 2627 | /*2 |
---|
| 2628 | * returns the ideals of initial terms |
---|
| 2629 | */ |
---|
| 2630 | ideal idHead(ideal h) |
---|
| 2631 | { |
---|
| 2632 | ideal m = idInit(IDELEMS(h),h->rank); |
---|
| 2633 | int i; |
---|
| 2634 | |
---|
| 2635 | for (i=IDELEMS(h)-1;i>=0; i--) |
---|
| 2636 | { |
---|
| 2637 | if (h->m[i]!=NULL) m->m[i]=pHead(h->m[i]); |
---|
| 2638 | } |
---|
| 2639 | return m; |
---|
| 2640 | } |
---|
| 2641 | |
---|
| 2642 | ideal idHomogen(ideal h, int varnum) |
---|
| 2643 | { |
---|
| 2644 | ideal m = idInit(IDELEMS(h),h->rank); |
---|
| 2645 | int i; |
---|
| 2646 | |
---|
| 2647 | for (i=IDELEMS(h)-1;i>=0; i--) |
---|
| 2648 | { |
---|
| 2649 | m->m[i]=pHomogen(h->m[i],varnum); |
---|
| 2650 | } |
---|
| 2651 | return m; |
---|
| 2652 | } |
---|
| 2653 | |
---|
| 2654 | /*------------------type conversions----------------*/ |
---|
| 2655 | ideal idVec2Ideal(poly vec) |
---|
| 2656 | { |
---|
| 2657 | ideal result=idInit(1,1); |
---|
| 2658 | omFree((ADDRESS)result->m); |
---|
| 2659 | result->m=NULL; // remove later |
---|
| 2660 | pVec2Polys(vec, &(result->m), &(IDELEMS(result))); |
---|
| 2661 | return result; |
---|
| 2662 | } |
---|
| 2663 | |
---|
[ca3e7b] | 2664 | #define NEW_STUFF |
---|
[35aab3] | 2665 | #ifndef NEW_STUFF |
---|
| 2666 | // converts mat to module, destroys mat |
---|
| 2667 | ideal idMatrix2Module(matrix mat) |
---|
| 2668 | { |
---|
| 2669 | int mc=MATCOLS(mat); |
---|
| 2670 | int mr=MATROWS(mat); |
---|
| 2671 | ideal result = idInit(si_max(mc,1),si_max(mr,1)); |
---|
| 2672 | int i,j; |
---|
| 2673 | poly h; |
---|
| 2674 | |
---|
| 2675 | for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */ |
---|
| 2676 | { |
---|
| 2677 | for (i=1;i<=mr /*MATROWS(mat)*/;i++) |
---|
| 2678 | { |
---|
| 2679 | h = MATELEM(mat,i,j+1); |
---|
| 2680 | if (h!=NULL) |
---|
| 2681 | { |
---|
| 2682 | MATELEM(mat,i,j+1)=NULL; |
---|
| 2683 | pSetCompP(h,i); |
---|
| 2684 | result->m[j] = pAdd(result->m[j],h); |
---|
| 2685 | } |
---|
| 2686 | } |
---|
| 2687 | } |
---|
| 2688 | // obachman: need to clean this up |
---|
| 2689 | idDelete((ideal*) &mat); |
---|
| 2690 | return result; |
---|
| 2691 | } |
---|
| 2692 | #else |
---|
| 2693 | |
---|
| 2694 | #include "sbuckets.h" |
---|
| 2695 | |
---|
| 2696 | // converts mat to module, destroys mat |
---|
| 2697 | ideal idMatrix2Module(matrix mat) |
---|
| 2698 | { |
---|
| 2699 | int mc=MATCOLS(mat); |
---|
| 2700 | int mr=MATROWS(mat); |
---|
| 2701 | ideal result = idInit(si_max(mc,1),si_max(mr,1)); |
---|
| 2702 | int i,j, l; |
---|
| 2703 | poly h; |
---|
| 2704 | poly p; |
---|
[cbeafc2] | 2705 | sBucket_pt bucket = sBucketCreate(currRing); |
---|
[35aab3] | 2706 | |
---|
| 2707 | for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */ |
---|
| 2708 | { |
---|
| 2709 | for (i=1;i<=mr /*MATROWS(mat)*/;i++) |
---|
| 2710 | { |
---|
| 2711 | h = MATELEM(mat,i,j+1); |
---|
| 2712 | if (h!=NULL) |
---|
| 2713 | { |
---|
[ca3e7b] | 2714 | l=pLength(h); |
---|
[35aab3] | 2715 | MATELEM(mat,i,j+1)=NULL; |
---|
[cbeafc2] | 2716 | p_SetCompP(h,i, currRing); |
---|
[35aab3] | 2717 | sBucket_Merge_p(bucket, h, l); |
---|
| 2718 | } |
---|
| 2719 | } |
---|
| 2720 | sBucketClearMerge(bucket, &(result->m[j]), &l); |
---|
| 2721 | } |
---|
[cbeafc2] | 2722 | sBucketDestroy(&bucket); |
---|
[35aab3] | 2723 | |
---|
| 2724 | // obachman: need to clean this up |
---|
| 2725 | idDelete((ideal*) &mat); |
---|
| 2726 | return result; |
---|
| 2727 | } |
---|
| 2728 | #endif |
---|
| 2729 | |
---|
| 2730 | /*2 |
---|
| 2731 | * converts a module into a matrix, destroyes the input |
---|
| 2732 | */ |
---|
| 2733 | matrix idModule2Matrix(ideal mod) |
---|
| 2734 | { |
---|
| 2735 | matrix result = mpNew(mod->rank,IDELEMS(mod)); |
---|
| 2736 | int i,cp; |
---|
| 2737 | poly p,h; |
---|
| 2738 | |
---|
| 2739 | for(i=0;i<IDELEMS(mod);i++) |
---|
| 2740 | { |
---|
| 2741 | p=mod->m[i]; |
---|
| 2742 | mod->m[i]=NULL; |
---|
| 2743 | while (p!=NULL) |
---|
| 2744 | { |
---|
| 2745 | h=p; |
---|
| 2746 | pIter(p); |
---|
| 2747 | pNext(h)=NULL; |
---|
| 2748 | // cp = si_max(1,pGetComp(h)); // if used for ideals too |
---|
| 2749 | cp = pGetComp(h); |
---|
| 2750 | pSetComp(h,0); |
---|
| 2751 | pSetmComp(h); |
---|
| 2752 | #ifdef TEST |
---|
| 2753 | if (cp>mod->rank) |
---|
| 2754 | { |
---|
| 2755 | Print("## inv. rank %d -> %d\n",mod->rank,cp); |
---|
| 2756 | int k,l,o=mod->rank; |
---|
| 2757 | mod->rank=cp; |
---|
| 2758 | matrix d=mpNew(mod->rank,IDELEMS(mod)); |
---|
| 2759 | for (l=1; l<=o; l++) |
---|
| 2760 | { |
---|
| 2761 | for (k=1; k<=IDELEMS(mod); k++) |
---|
| 2762 | { |
---|
| 2763 | MATELEM(d,l,k)=MATELEM(result,l,k); |
---|
| 2764 | MATELEM(result,l,k)=NULL; |
---|
| 2765 | } |
---|
| 2766 | } |
---|
| 2767 | idDelete((ideal *)&result); |
---|
| 2768 | result=d; |
---|
| 2769 | } |
---|
| 2770 | #endif |
---|
| 2771 | MATELEM(result,cp,i+1) = pAdd(MATELEM(result,cp,i+1),h); |
---|
| 2772 | } |
---|
| 2773 | } |
---|
| 2774 | // obachman 10/99: added the following line, otherwise memory leack! |
---|
| 2775 | idDelete(&mod); |
---|
| 2776 | return result; |
---|
| 2777 | } |
---|
| 2778 | |
---|
| 2779 | matrix idModule2formatedMatrix(ideal mod,int rows, int cols) |
---|
| 2780 | { |
---|
| 2781 | matrix result = mpNew(rows,cols); |
---|
| 2782 | int i,cp,r=idRankFreeModule(mod),c=IDELEMS(mod); |
---|
| 2783 | poly p,h; |
---|
| 2784 | |
---|
| 2785 | if (r>rows) r = rows; |
---|
| 2786 | if (c>cols) c = cols; |
---|
| 2787 | for(i=0;i<c;i++) |
---|
| 2788 | { |
---|
| 2789 | p=mod->m[i]; |
---|
| 2790 | mod->m[i]=NULL; |
---|
| 2791 | while (p!=NULL) |
---|
| 2792 | { |
---|
| 2793 | h=p; |
---|
| 2794 | pIter(p); |
---|
| 2795 | pNext(h)=NULL; |
---|
| 2796 | cp = pGetComp(h); |
---|
| 2797 | if (cp<=r) |
---|
| 2798 | { |
---|
| 2799 | pSetComp(h,0); |
---|
| 2800 | pSetmComp(h); |
---|
| 2801 | MATELEM(result,cp,i+1) = pAdd(MATELEM(result,cp,i+1),h); |
---|
| 2802 | } |
---|
| 2803 | else |
---|
| 2804 | pDelete(&h); |
---|
| 2805 | } |
---|
| 2806 | } |
---|
| 2807 | idDelete(&mod); |
---|
| 2808 | return result; |
---|
| 2809 | } |
---|
| 2810 | |
---|
| 2811 | /*2 |
---|
| 2812 | * substitute the n-th variable by the monomial e in id |
---|
| 2813 | * destroy id |
---|
| 2814 | */ |
---|
| 2815 | ideal idSubst(ideal id, int n, poly e) |
---|
| 2816 | { |
---|
| 2817 | int k=MATROWS((matrix)id)*MATCOLS((matrix)id); |
---|
| 2818 | ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id)); |
---|
| 2819 | |
---|
| 2820 | res->rank = id->rank; |
---|
| 2821 | for(k--;k>=0;k--) |
---|
| 2822 | { |
---|
| 2823 | res->m[k]=pSubst(id->m[k],n,e); |
---|
| 2824 | id->m[k]=NULL; |
---|
| 2825 | } |
---|
| 2826 | idDelete(&id); |
---|
| 2827 | return res; |
---|
| 2828 | } |
---|
| 2829 | |
---|
| 2830 | BOOLEAN idHomModule(ideal m, ideal Q, intvec **w) |
---|
| 2831 | { |
---|
| 2832 | if (w!=NULL) *w=NULL; |
---|
| 2833 | if ((Q!=NULL) && (!idHomIdeal(Q,NULL))) return FALSE; |
---|
[43ebb1] | 2834 | if (idIs0(m)) |
---|
| 2835 | { |
---|
[a12776] | 2836 | if (w!=NULL) (*w)=new intvec(m->rank); |
---|
[43ebb1] | 2837 | return TRUE; |
---|
| 2838 | } |
---|
[35aab3] | 2839 | |
---|
| 2840 | int i,j,cmax=2,order=0,ord,* diff,* iscom,diffmin=32000; |
---|
| 2841 | poly p=NULL; |
---|
| 2842 | int length=IDELEMS(m); |
---|
| 2843 | polyset P=m->m; |
---|
| 2844 | polyset F=(polyset)omAlloc(length*sizeof(poly)); |
---|
| 2845 | for (i=length-1;i>=0;i--) |
---|
| 2846 | { |
---|
| 2847 | p=F[i]=P[i]; |
---|
[62dd9b] | 2848 | cmax=si_max(cmax,(int)pMaxComp(p)+1); |
---|
[35aab3] | 2849 | } |
---|
| 2850 | diff = (int *)omAlloc0(cmax*sizeof(int)); |
---|
| 2851 | if (w!=NULL) *w=new intvec(cmax-1); |
---|
| 2852 | iscom = (int *)omAlloc0(cmax*sizeof(int)); |
---|
| 2853 | i=0; |
---|
| 2854 | while (i<=length) |
---|
| 2855 | { |
---|
| 2856 | if (i<length) |
---|
| 2857 | { |
---|
| 2858 | p=F[i]; |
---|
| 2859 | while ((p!=NULL) && (!iscom[pGetComp(p)])) pIter(p); |
---|
| 2860 | } |
---|
| 2861 | if ((p==NULL) && (i<length)) |
---|
| 2862 | { |
---|
| 2863 | i++; |
---|
| 2864 | } |
---|
| 2865 | else |
---|
| 2866 | { |
---|
| 2867 | if (p==NULL) |
---|
| 2868 | { |
---|
| 2869 | i=0; |
---|
| 2870 | while ((i<length) && (F[i]==NULL)) i++; |
---|
| 2871 | if (i>=length) break; |
---|
| 2872 | p = F[i]; |
---|
| 2873 | } |
---|
[d0c9ea] | 2874 | if (pLexOrder && (currRing->order[0]==ringorder_lp)) |
---|
[35aab3] | 2875 | order=pTotaldegree(p); |
---|
| 2876 | else |
---|
| 2877 | // order = p->order; |
---|
[b130fb] | 2878 | order = pFDeg(p,currRing); |
---|
[35aab3] | 2879 | order += diff[pGetComp(p)]; |
---|
| 2880 | p = F[i]; |
---|
| 2881 | //Print("Actual p=F[%d]: ",i);pWrite(p); |
---|
| 2882 | F[i] = NULL; |
---|
| 2883 | i=0; |
---|
| 2884 | } |
---|
| 2885 | while (p!=NULL) |
---|
| 2886 | { |
---|
| 2887 | //if (pLexOrder) |
---|
| 2888 | // ord=pTotaldegree(p); |
---|
| 2889 | //else |
---|
| 2890 | // ord = p->order; |
---|
[b130fb] | 2891 | ord = pFDeg(p,currRing); |
---|
[35aab3] | 2892 | if (!iscom[pGetComp(p)]) |
---|
| 2893 | { |
---|
| 2894 | diff[pGetComp(p)] = order-ord; |
---|
| 2895 | iscom[pGetComp(p)] = 1; |
---|
| 2896 | /* |
---|
| 2897 | *PrintS("new diff: "); |
---|
| 2898 | *for (j=0;j<cmax;j++) Print("%d ",diff[j]); |
---|
| 2899 | *PrintLn(); |
---|
| 2900 | *PrintS("new iscom: "); |
---|
| 2901 | *for (j=0;j<cmax;j++) Print("%d ",iscom[j]); |
---|
| 2902 | *PrintLn(); |
---|
| 2903 | *Print("new set %d, order %d, ord %d, diff %d\n",pGetComp(p),order,ord,diff[pGetComp(p)]); |
---|
| 2904 | */ |
---|
| 2905 | } |
---|
| 2906 | else |
---|
| 2907 | { |
---|
| 2908 | /* |
---|
| 2909 | *PrintS("new diff: "); |
---|
| 2910 | *for (j=0;j<cmax;j++) Print("%d ",diff[j]); |
---|
| 2911 | *PrintLn(); |
---|
| 2912 | *Print("order %d, ord %d, diff %d\n",order,ord,diff[pGetComp(p)]); |
---|
| 2913 | */ |
---|
| 2914 | if (order != ord+diff[pGetComp(p)]) |
---|
| 2915 | { |
---|
| 2916 | omFreeSize((ADDRESS) iscom,cmax*sizeof(int)); |
---|
| 2917 | omFreeSize((ADDRESS) diff,cmax*sizeof(int)); |
---|
| 2918 | omFreeSize((ADDRESS) F,length*sizeof(poly)); |
---|
| 2919 | delete *w;*w=NULL; |
---|
| 2920 | return FALSE; |
---|
| 2921 | } |
---|
| 2922 | } |
---|
| 2923 | pIter(p); |
---|
| 2924 | } |
---|
| 2925 | } |
---|
| 2926 | omFreeSize((ADDRESS) iscom,cmax*sizeof(int)); |
---|
| 2927 | omFreeSize((ADDRESS) F,length*sizeof(poly)); |
---|
| 2928 | for (i=1;i<cmax;i++) (**w)[i-1]=diff[i]; |
---|
| 2929 | for (i=1;i<cmax;i++) |
---|
| 2930 | { |
---|
| 2931 | if (diff[i]<diffmin) diffmin=diff[i]; |
---|
| 2932 | } |
---|
| 2933 | if (w!=NULL) |
---|
| 2934 | { |
---|
| 2935 | for (i=1;i<cmax;i++) |
---|
| 2936 | { |
---|
| 2937 | (**w)[i-1]=diff[i]-diffmin; |
---|
| 2938 | } |
---|
| 2939 | } |
---|
| 2940 | omFreeSize((ADDRESS) diff,cmax*sizeof(int)); |
---|
| 2941 | return TRUE; |
---|
| 2942 | } |
---|
| 2943 | |
---|
[30b8381] | 2944 | BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w) |
---|
| 2945 | { |
---|
| 2946 | if ((Q!=NULL) && (!idHomIdeal(Q,NULL))) { PrintS(" Q not hom\n"); return FALSE;} |
---|
| 2947 | if (idIs0(m)) return TRUE; |
---|
| 2948 | |
---|
| 2949 | int cmax=-1; |
---|
| 2950 | int i; |
---|
| 2951 | poly p=NULL; |
---|
| 2952 | int length=IDELEMS(m); |
---|
| 2953 | polyset P=m->m; |
---|
| 2954 | for (i=length-1;i>=0;i--) |
---|
| 2955 | { |
---|
| 2956 | p=P[i]; |
---|
| 2957 | if (p!=NULL) cmax=si_max(cmax,(int)pMaxComp(p)+1); |
---|
| 2958 | } |
---|
[8324cc] | 2959 | if (w != NULL) |
---|
[30b8381] | 2960 | if (w->length()+1 < cmax) |
---|
[4d13e7] | 2961 | { |
---|
[30b8381] | 2962 | // Print("length: %d - %d \n", w->length(),cmax); |
---|
| 2963 | return FALSE; |
---|
| 2964 | } |
---|
[8324cc] | 2965 | |
---|
| 2966 | if(w!=NULL) |
---|
| 2967 | pSetModDeg(w); |
---|
| 2968 | |
---|
[30b8381] | 2969 | for (i=length-1;i>=0;i--) |
---|
| 2970 | { |
---|
| 2971 | p=P[i]; |
---|
| 2972 | poly q=p; |
---|
| 2973 | if (p!=NULL) |
---|
| 2974 | { |
---|
[b130fb] | 2975 | int d=pFDeg(p,currRing); |
---|
[30b8381] | 2976 | loop |
---|
| 2977 | { |
---|
| 2978 | pIter(p); |
---|
| 2979 | if (p==NULL) break; |
---|
[4d13e7] | 2980 | if (d!=pFDeg(p,currRing)) |
---|
[30b8381] | 2981 | { |
---|
[4d13e7] | 2982 | //pWrite(q); wrp(p); Print(" -> %d - %d\n",d,pFDeg(p,currRing)); |
---|
[8324cc] | 2983 | if(w!=NULL) |
---|
| 2984 | pSetModDeg(NULL); |
---|
[4d13e7] | 2985 | return FALSE; |
---|
[30b8381] | 2986 | } |
---|
| 2987 | } |
---|
| 2988 | } |
---|
| 2989 | } |
---|
[cbc7e3] | 2990 | |
---|
[8324cc] | 2991 | if(w!=NULL) |
---|
| 2992 | pSetModDeg(NULL); |
---|
[cbc7e3] | 2993 | |
---|
[30b8381] | 2994 | return TRUE; |
---|
| 2995 | } |
---|
| 2996 | |
---|
[35aab3] | 2997 | ideal idJet(ideal i,int d) |
---|
| 2998 | { |
---|
| 2999 | ideal r=idInit((i->nrows)*(i->ncols),i->rank); |
---|
| 3000 | r->nrows = i-> nrows; |
---|
| 3001 | r->ncols = i-> ncols; |
---|
| 3002 | //r->rank = i-> rank; |
---|
| 3003 | int k; |
---|
| 3004 | for(k=(i->nrows)*(i->ncols)-1;k>=0; k--) |
---|
| 3005 | { |
---|
| 3006 | r->m[k]=ppJet(i->m[k],d); |
---|
| 3007 | } |
---|
| 3008 | return r; |
---|
| 3009 | } |
---|
| 3010 | |
---|
| 3011 | ideal idJetW(ideal i,int d, intvec * iv) |
---|
| 3012 | { |
---|
| 3013 | ideal r=idInit(IDELEMS(i),i->rank); |
---|
| 3014 | if (ecartWeights!=NULL) |
---|
| 3015 | { |
---|
| 3016 | WerrorS("cannot compute weighted jets now"); |
---|
| 3017 | } |
---|
| 3018 | else |
---|
| 3019 | { |
---|
| 3020 | short *w=iv2array(iv); |
---|
| 3021 | int k; |
---|
| 3022 | for(k=0; k<IDELEMS(i); k++) |
---|
| 3023 | { |
---|
| 3024 | r->m[k]=ppJetW(i->m[k],d,w); |
---|
| 3025 | } |
---|
| 3026 | omFreeSize((ADDRESS)w,(pVariables+1)*sizeof(short)); |
---|
| 3027 | } |
---|
| 3028 | return r; |
---|
| 3029 | } |
---|
| 3030 | |
---|
| 3031 | int idMinDegW(ideal M,intvec *w) |
---|
| 3032 | { |
---|
| 3033 | int d=-1; |
---|
| 3034 | for(int i=0;i<IDELEMS(M);i++) |
---|
| 3035 | { |
---|
| 3036 | int d0=pMinDeg(M->m[i],w); |
---|
| 3037 | if(-1<d0&&(d0<d||d==-1)) |
---|
| 3038 | d=d0; |
---|
| 3039 | } |
---|
| 3040 | return d; |
---|
| 3041 | } |
---|
| 3042 | |
---|
| 3043 | ideal idSeries(int n,ideal M,matrix U,intvec *w) |
---|
| 3044 | { |
---|
| 3045 | for(int i=IDELEMS(M)-1;i>=0;i--) |
---|
| 3046 | { |
---|
| 3047 | if(U==NULL) |
---|
| 3048 | M->m[i]=pSeries(n,M->m[i],NULL,w); |
---|
| 3049 | else |
---|
| 3050 | { |
---|
| 3051 | M->m[i]=pSeries(n,M->m[i],MATELEM(U,i+1,i+1),w); |
---|
| 3052 | MATELEM(U,i+1,i+1)=NULL; |
---|
| 3053 | } |
---|
| 3054 | } |
---|
| 3055 | if(U!=NULL) |
---|
| 3056 | idDelete((ideal*)&U); |
---|
| 3057 | return M; |
---|
| 3058 | } |
---|
| 3059 | |
---|
| 3060 | matrix idDiff(matrix i, int k) |
---|
| 3061 | { |
---|
| 3062 | int e=MATCOLS(i)*MATROWS(i); |
---|
| 3063 | matrix r=mpNew(MATROWS(i),MATCOLS(i)); |
---|
| 3064 | int j; |
---|
| 3065 | for(j=0; j<e; j++) |
---|
| 3066 | { |
---|
| 3067 | r->m[j]=pDiff(i->m[j],k); |
---|
| 3068 | } |
---|
| 3069 | return r; |
---|
| 3070 | } |
---|
| 3071 | |
---|
| 3072 | matrix idDiffOp(ideal I, ideal J,BOOLEAN multiply) |
---|
| 3073 | { |
---|
| 3074 | matrix r=mpNew(IDELEMS(I),IDELEMS(J)); |
---|
| 3075 | int i,j; |
---|
| 3076 | for(i=0; i<IDELEMS(I); i++) |
---|
| 3077 | { |
---|
| 3078 | for(j=0; j<IDELEMS(J); j++) |
---|
| 3079 | { |
---|
| 3080 | MATELEM(r,i+1,j+1)=pDiffOp(I->m[i],J->m[j],multiply); |
---|
| 3081 | } |
---|
| 3082 | } |
---|
| 3083 | return r; |
---|
| 3084 | } |
---|
| 3085 | |
---|
| 3086 | /*3 |
---|
| 3087 | *handles for some ideal operations the ring/syzcomp managment |
---|
| 3088 | *returns all syzygies (componentwise-)shifted by -syzcomp |
---|
| 3089 | *or -syzcomp-1 (in case of ideals as input) |
---|
| 3090 | static ideal idHandleIdealOp(ideal arg,int syzcomp,int isIdeal=FALSE) |
---|
| 3091 | { |
---|
| 3092 | ring orig_ring=currRing; |
---|
| 3093 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 3094 | rSetSyzComp(length); |
---|
| 3095 | |
---|
| 3096 | ideal s_temp; |
---|
| 3097 | if (orig_ring!=syz_ring) |
---|
| 3098 | s_temp=idrMoveR_NoSort(arg,orig_ring); |
---|
| 3099 | else |
---|
| 3100 | s_temp=arg; |
---|
| 3101 | |
---|
| 3102 | ideal s_temp1 = kStd(s_temp,currQuotient,testHomog,&w,NULL,length); |
---|
| 3103 | if (w!=NULL) delete w; |
---|
| 3104 | |
---|
| 3105 | if (syz_ring!=orig_ring) |
---|
| 3106 | { |
---|
| 3107 | idDelete(&s_temp); |
---|
| 3108 | rChangeCurrRing(orig_ring); |
---|
| 3109 | } |
---|
| 3110 | |
---|
| 3111 | idDelete(&temp); |
---|
| 3112 | ideal temp1=idRingCopy(s_temp1,syz_ring); |
---|
| 3113 | |
---|
| 3114 | if (syz_ring!=orig_ring) |
---|
| 3115 | { |
---|
| 3116 | rChangeCurrRing(syz_ring); |
---|
| 3117 | idDelete(&s_temp1); |
---|
| 3118 | rChangeCurrRing(orig_ring); |
---|
| 3119 | rKill(syz_ring); |
---|
| 3120 | } |
---|
| 3121 | |
---|
| 3122 | for (i=0;i<IDELEMS(temp1);i++) |
---|
| 3123 | { |
---|
| 3124 | if ((temp1->m[i]!=NULL) |
---|
| 3125 | && (pGetComp(temp1->m[i])<=length)) |
---|
| 3126 | { |
---|
| 3127 | pDelete(&(temp1->m[i])); |
---|
| 3128 | } |
---|
| 3129 | else |
---|
| 3130 | { |
---|
| 3131 | pShift(&(temp1->m[i]),-length); |
---|
| 3132 | } |
---|
| 3133 | } |
---|
| 3134 | temp1->rank = rk; |
---|
| 3135 | idSkipZeroes(temp1); |
---|
| 3136 | |
---|
| 3137 | return temp1; |
---|
| 3138 | } |
---|
| 3139 | */ |
---|
| 3140 | /*2 |
---|
| 3141 | * represents (h1+h2)/h2=h1/(h1 intersect h2) |
---|
| 3142 | */ |
---|
[cf108d] | 3143 | //ideal idModulo (ideal h2,ideal h1) |
---|
| 3144 | ideal idModulo (ideal h2,ideal h1, tHomog hom, intvec ** w) |
---|
[35aab3] | 3145 | { |
---|
[cf108d] | 3146 | intvec *wtmp=NULL; |
---|
| 3147 | |
---|
[35aab3] | 3148 | int i,j,k,rk,flength=0,slength,length; |
---|
| 3149 | poly p,q; |
---|
| 3150 | |
---|
| 3151 | if (idIs0(h2)) |
---|
| 3152 | return idFreeModule(si_max(1,h2->ncols)); |
---|
| 3153 | if (!idIs0(h1)) |
---|
| 3154 | flength = idRankFreeModule(h1); |
---|
| 3155 | slength = idRankFreeModule(h2); |
---|
| 3156 | length = si_max(flength,slength); |
---|
| 3157 | if (length==0) |
---|
| 3158 | { |
---|
| 3159 | length = 1; |
---|
| 3160 | } |
---|
| 3161 | ideal temp = idInit(IDELEMS(h2),length+IDELEMS(h2)); |
---|
[cf108d] | 3162 | if ((w!=NULL)&&((*w)!=NULL)) |
---|
| 3163 | { |
---|
| 3164 | //Print("input weights:");(*w)->show(1);PrintLn(); |
---|
| 3165 | int d; |
---|
| 3166 | int k; |
---|
| 3167 | wtmp=new intvec(length+IDELEMS(h2)); |
---|
| 3168 | for (i=0;i<length;i++) |
---|
| 3169 | ((*wtmp)[i])=(**w)[i]; |
---|
| 3170 | for (i=0;i<IDELEMS(h2);i++) |
---|
| 3171 | { |
---|
[43ebb1] | 3172 | poly p=h2->m[i]; |
---|
| 3173 | if (p!=NULL) |
---|
| 3174 | { |
---|
| 3175 | d = pDeg(p); |
---|
| 3176 | k= pGetComp(p); |
---|
| 3177 | if (slength>0) k--; |
---|
| 3178 | d +=((**w)[k]); |
---|
| 3179 | ((*wtmp)[i+length]) = d; |
---|
| 3180 | } |
---|
[cf108d] | 3181 | } |
---|
| 3182 | //Print("weights:");wtmp->show(1);PrintLn(); |
---|
| 3183 | } |
---|
[35aab3] | 3184 | for (i=0;i<IDELEMS(h2);i++) |
---|
| 3185 | { |
---|
| 3186 | temp->m[i] = pCopy(h2->m[i]); |
---|
| 3187 | q = pOne(); |
---|
| 3188 | pSetComp(q,i+1+length); |
---|
| 3189 | pSetmComp(q); |
---|
| 3190 | if(temp->m[i]!=NULL) |
---|
| 3191 | { |
---|
| 3192 | if (slength==0) pShift(&(temp->m[i]),1); |
---|
| 3193 | p = temp->m[i]; |
---|
| 3194 | while (pNext(p)!=NULL) pIter(p); |
---|
| 3195 | pNext(p) = q; |
---|
| 3196 | } |
---|
| 3197 | else |
---|
| 3198 | temp->m[i]=q; |
---|
| 3199 | } |
---|
| 3200 | rk = k = IDELEMS(h2); |
---|
| 3201 | if (!idIs0(h1)) |
---|
| 3202 | { |
---|
| 3203 | pEnlargeSet(&(temp->m),IDELEMS(temp),IDELEMS(h1)); |
---|
| 3204 | IDELEMS(temp) += IDELEMS(h1); |
---|
| 3205 | for (i=0;i<IDELEMS(h1);i++) |
---|
| 3206 | { |
---|
| 3207 | if (h1->m[i]!=NULL) |
---|
| 3208 | { |
---|
| 3209 | temp->m[k] = pCopy(h1->m[i]); |
---|
| 3210 | if (flength==0) pShift(&(temp->m[k]),1); |
---|
| 3211 | k++; |
---|
| 3212 | } |
---|
| 3213 | } |
---|
| 3214 | } |
---|
| 3215 | |
---|
| 3216 | ring orig_ring=currRing; |
---|
| 3217 | ring syz_ring=rCurrRingAssure_SyzComp(); |
---|
| 3218 | rSetSyzComp(length); |
---|
| 3219 | ideal s_temp; |
---|
| 3220 | |
---|
| 3221 | if (syz_ring != orig_ring) |
---|
| 3222 | { |
---|
| 3223 | s_temp = idrMoveR_NoSort(temp, orig_ring); |
---|
| 3224 | } |
---|
| 3225 | else |
---|
| 3226 | { |
---|
| 3227 | s_temp = temp; |
---|
| 3228 | } |
---|
| 3229 | |
---|
| 3230 | idTest(s_temp); |
---|
[cf108d] | 3231 | ideal s_temp1 = kStd(s_temp,currQuotient,hom,&wtmp,NULL,length); |
---|
| 3232 | |
---|
| 3233 | //if (wtmp!=NULL) Print("output weights:");wtmp->show(1);PrintLn(); |
---|
| 3234 | if ((w!=NULL) && (*w !=NULL) && (wtmp!=NULL)) |
---|
| 3235 | { |
---|
| 3236 | delete *w; |
---|
| 3237 | *w=new intvec(IDELEMS(h2)); |
---|
| 3238 | for (i=0;i<IDELEMS(h2);i++) |
---|
| 3239 | ((**w)[i])=(*wtmp)[i+length]; |
---|
| 3240 | } |
---|
| 3241 | if (wtmp!=NULL) delete wtmp; |
---|
[35aab3] | 3242 | |
---|
| 3243 | for (i=0;i<IDELEMS(s_temp1);i++) |
---|
| 3244 | { |
---|
| 3245 | if ((s_temp1->m[i]!=NULL) |
---|
| 3246 | && (pGetComp(s_temp1->m[i])<=length)) |
---|
| 3247 | { |
---|
| 3248 | pDelete(&(s_temp1->m[i])); |
---|
| 3249 | } |
---|
| 3250 | else |
---|
| 3251 | { |
---|
| 3252 | pShift(&(s_temp1->m[i]),-length); |
---|
| 3253 | } |
---|
| 3254 | } |
---|
| 3255 | s_temp1->rank = rk; |
---|
| 3256 | idSkipZeroes(s_temp1); |
---|
| 3257 | |
---|
| 3258 | if (syz_ring!=orig_ring) |
---|
| 3259 | { |
---|
| 3260 | rChangeCurrRing(orig_ring); |
---|
| 3261 | s_temp1 = idrMoveR_NoSort(s_temp1, syz_ring); |
---|
| 3262 | rKill(syz_ring); |
---|
| 3263 | // Hmm ... here seems to be a memory leak |
---|
| 3264 | // However, simply deleting it causes memory trouble |
---|
| 3265 | // idDelete(&s_temp); |
---|
| 3266 | } |
---|
| 3267 | else |
---|
| 3268 | { |
---|
| 3269 | idDelete(&temp); |
---|
| 3270 | } |
---|
| 3271 | idTest(s_temp1); |
---|
| 3272 | return s_temp1; |
---|
| 3273 | } |
---|
| 3274 | |
---|
[b3930d] | 3275 | int idElem(const ideal F) |
---|
[35aab3] | 3276 | { |
---|
[b3930d] | 3277 | int i=0,j=IDELEMS(F)-1; |
---|
[35aab3] | 3278 | |
---|
[b3930d] | 3279 | while(j>=0) |
---|
[35aab3] | 3280 | { |
---|
[b3930d] | 3281 | if ((F->m)[j]!=NULL) i++; |
---|
| 3282 | j--; |
---|
[35aab3] | 3283 | } |
---|
| 3284 | return i; |
---|
| 3285 | } |
---|
| 3286 | |
---|
| 3287 | /* |
---|
| 3288 | *computes module-weights for liftings of homogeneous modules |
---|
| 3289 | */ |
---|
| 3290 | intvec * idMWLift(ideal mod,intvec * weights) |
---|
| 3291 | { |
---|
| 3292 | if (idIs0(mod)) return new intvec(2); |
---|
| 3293 | int i=IDELEMS(mod); |
---|
| 3294 | while ((i>0) && (mod->m[i-1]==NULL)) i--; |
---|
| 3295 | intvec *result = new intvec(i+1); |
---|
| 3296 | while (i>0) |
---|
| 3297 | { |
---|
[b130fb] | 3298 | (*result)[i]=pFDeg(mod->m[i],currRing)+(*weights)[pGetComp(mod->m[i])]; |
---|
[35aab3] | 3299 | } |
---|
| 3300 | return result; |
---|
| 3301 | } |
---|
| 3302 | |
---|
| 3303 | /*2 |
---|
| 3304 | *sorts the kbase for idCoef* in a special way (lexicographically |
---|
| 3305 | *with x_max,...,x_1) |
---|
| 3306 | */ |
---|
| 3307 | ideal idCreateSpecialKbase(ideal kBase,intvec ** convert) |
---|
| 3308 | { |
---|
| 3309 | int i; |
---|
| 3310 | ideal result; |
---|
| 3311 | |
---|
| 3312 | if (idIs0(kBase)) return NULL; |
---|
| 3313 | result = idInit(IDELEMS(kBase),kBase->rank); |
---|
| 3314 | *convert = idSort(kBase,FALSE); |
---|
| 3315 | for (i=0;i<(*convert)->length();i++) |
---|
| 3316 | { |
---|
| 3317 | result->m[i] = pCopy(kBase->m[(**convert)[i]-1]); |
---|
| 3318 | } |
---|
| 3319 | return result; |
---|
| 3320 | } |
---|
| 3321 | |
---|
| 3322 | /*2 |
---|
| 3323 | *returns the index of a given monom in the list of the special kbase |
---|
| 3324 | */ |
---|
| 3325 | int idIndexOfKBase(poly monom, ideal kbase) |
---|
| 3326 | { |
---|
| 3327 | int j=IDELEMS(kbase); |
---|
| 3328 | |
---|
| 3329 | while ((j>0) && (kbase->m[j-1]==NULL)) j--; |
---|
| 3330 | if (j==0) return -1; |
---|
| 3331 | int i=pVariables; |
---|
| 3332 | while (i>0) |
---|
| 3333 | { |
---|
| 3334 | loop |
---|
| 3335 | { |
---|
| 3336 | if (pGetExp(monom,i)>pGetExp(kbase->m[j-1],i)) return -1; |
---|
| 3337 | if (pGetExp(monom,i)==pGetExp(kbase->m[j-1],i)) break; |
---|
| 3338 | j--; |
---|
| 3339 | if (j==0) return -1; |
---|
| 3340 | } |
---|
| 3341 | if (i==1) |
---|
| 3342 | { |
---|
| 3343 | while(j>0) |
---|
| 3344 | { |
---|
| 3345 | if (pGetComp(monom)==pGetComp(kbase->m[j-1])) return j-1; |
---|
| 3346 | if (pGetComp(monom)>pGetComp(kbase->m[j-1])) return -1; |
---|
| 3347 | j--; |
---|
| 3348 | } |
---|
| 3349 | } |
---|
| 3350 | i--; |
---|
| 3351 | } |
---|
| 3352 | return -1; |
---|
| 3353 | } |
---|
| 3354 | |
---|
| 3355 | /*2 |
---|
| 3356 | *decomposes the monom in a part of coefficients described by the |
---|
| 3357 | *complement of how and a monom in variables occuring in how, the |
---|
| 3358 | *index of which in kbase is returned as integer pos (-1 if it don't |
---|
| 3359 | *exists) |
---|
| 3360 | */ |
---|
| 3361 | poly idDecompose(poly monom, poly how, ideal kbase, int * pos) |
---|
| 3362 | { |
---|
| 3363 | int i; |
---|
| 3364 | poly coeff=pOne(), base=pOne(); |
---|
| 3365 | |
---|
| 3366 | for (i=1;i<=pVariables;i++) |
---|
| 3367 | { |
---|
| 3368 | if (pGetExp(how,i)>0) |
---|
| 3369 | { |
---|
| 3370 | pSetExp(base,i,pGetExp(monom,i)); |
---|
| 3371 | } |
---|
| 3372 | else |
---|
| 3373 | { |
---|
| 3374 | pSetExp(coeff,i,pGetExp(monom,i)); |
---|
| 3375 | } |
---|
| 3376 | } |
---|
| 3377 | pSetComp(base,pGetComp(monom)); |
---|
| 3378 | pSetm(base); |
---|
| 3379 | pSetCoeff(coeff,nCopy(pGetCoeff(monom))); |
---|
| 3380 | pSetm(coeff); |
---|
| 3381 | *pos = idIndexOfKBase(base,kbase); |
---|
| 3382 | if (*pos<0) |
---|
| 3383 | pDelete(&coeff); |
---|
| 3384 | pDelete(&base); |
---|
| 3385 | return coeff; |
---|
| 3386 | } |
---|
| 3387 | |
---|
| 3388 | /*2 |
---|
| 3389 | *returns a matrix A of coefficients with kbase*A=arg |
---|
| 3390 | *if all monomials in variables of how occur in kbase |
---|
| 3391 | *the other are deleted |
---|
| 3392 | */ |
---|
| 3393 | matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how) |
---|
| 3394 | { |
---|
| 3395 | matrix result; |
---|
| 3396 | ideal tempKbase; |
---|
| 3397 | poly p,q; |
---|
| 3398 | intvec * convert; |
---|
| 3399 | int i=IDELEMS(kbase),j=IDELEMS(arg),k,pos; |
---|
| 3400 | #if 0 |
---|
| 3401 | while ((i>0) && (kbase->m[i-1]==NULL)) i--; |
---|
| 3402 | if (idIs0(arg)) |
---|
| 3403 | return mpNew(i,1); |
---|
| 3404 | while ((j>0) && (arg->m[j-1]==NULL)) j--; |
---|
| 3405 | result = mpNew(i,j); |
---|
| 3406 | #else |
---|
| 3407 | result = mpNew(i, j); |
---|
| 3408 | while ((j>0) && (arg->m[j-1]==NULL)) j--; |
---|
| 3409 | #endif |
---|
| 3410 | |
---|
| 3411 | tempKbase = idCreateSpecialKbase(kbase,&convert); |
---|
| 3412 | for (k=0;k<j;k++) |
---|
| 3413 | { |
---|
| 3414 | p = arg->m[k]; |
---|
| 3415 | while (p!=NULL) |
---|
| 3416 | { |
---|
| 3417 | q = idDecompose(p,how,tempKbase,&pos); |
---|
| 3418 | if (pos>=0) |
---|
| 3419 | { |
---|
| 3420 | MATELEM(result,(*convert)[pos],k+1) = |
---|
| 3421 | pAdd(MATELEM(result,(*convert)[pos],k+1),q); |
---|
| 3422 | } |
---|
| 3423 | else |
---|
| 3424 | pDelete(&q); |
---|
| 3425 | pIter(p); |
---|
| 3426 | } |
---|
| 3427 | } |
---|
| 3428 | idDelete(&tempKbase); |
---|
| 3429 | return result; |
---|
| 3430 | } |
---|
| 3431 | |
---|
| 3432 | /*3 |
---|
| 3433 | * searches for units in the components of the module arg and |
---|
| 3434 | * returns the first one |
---|
| 3435 | */ |
---|
| 3436 | static int idReadOutUnits(ideal arg,int* comp) |
---|
| 3437 | { |
---|
[1d138c] | 3438 | if (idIs0(arg)) return -1; |
---|
[8421b8] | 3439 | int i=0,j, generator=-1; |
---|
| 3440 | int rk_arg=arg->rank; //idRankFreeModule(arg); |
---|
| 3441 | int * componentIsUsed =(int *)omAlloc((rk_arg+1)*sizeof(int)); |
---|
[35aab3] | 3442 | poly p,q; |
---|
| 3443 | |
---|
[8421b8] | 3444 | while ((generator<0) && (i<IDELEMS(arg))) |
---|
[35aab3] | 3445 | { |
---|
[8421b8] | 3446 | memset(componentIsUsed,0,(rk_arg+1)*sizeof(int)); |
---|
[35aab3] | 3447 | p = arg->m[i]; |
---|
| 3448 | while (p!=NULL) |
---|
| 3449 | { |
---|
| 3450 | j = pGetComp(p); |
---|
[8421b8] | 3451 | if (componentIsUsed[j]==0) |
---|
[35aab3] | 3452 | { |
---|
| 3453 | if (pLmIsConstantComp(p)) |
---|
| 3454 | { |
---|
| 3455 | generator = i; |
---|
[8421b8] | 3456 | componentIsUsed[j] = 1; |
---|
[35aab3] | 3457 | } |
---|
| 3458 | else |
---|
| 3459 | { |
---|
[8421b8] | 3460 | componentIsUsed[j] = -1; |
---|
[35aab3] | 3461 | } |
---|
| 3462 | } |
---|
[8421b8] | 3463 | else if (componentIsUsed[j]>0) |
---|
[35aab3] | 3464 | { |
---|
[8421b8] | 3465 | (componentIsUsed[j])++; |
---|
[35aab3] | 3466 | } |
---|
| 3467 | pIter(p); |
---|
| 3468 | } |
---|
| 3469 | i++; |
---|
| 3470 | } |
---|
| 3471 | i = 0; |
---|
| 3472 | *comp = -1; |
---|
| 3473 | for (j=0;j<=rk_arg;j++) |
---|
| 3474 | { |
---|
[8421b8] | 3475 | if (componentIsUsed[j]>0) |
---|
[35aab3] | 3476 | { |
---|
[8421b8] | 3477 | if ((*comp==-1) || (componentIsUsed[j]<i)) |
---|
[35aab3] | 3478 | { |
---|
| 3479 | *comp = j; |
---|
[8421b8] | 3480 | i= componentIsUsed[j]; |
---|
[35aab3] | 3481 | } |
---|
| 3482 | } |
---|
| 3483 | } |
---|
[8421b8] | 3484 | omFree(componentIsUsed); |
---|
[35aab3] | 3485 | return generator; |
---|
| 3486 | } |
---|
| 3487 | |
---|
[955025] | 3488 | #if 0 |
---|
[35aab3] | 3489 | static void idDeleteComp(ideal arg,int red_comp) |
---|
| 3490 | { |
---|
| 3491 | int i,j; |
---|
| 3492 | poly p; |
---|
| 3493 | |
---|
| 3494 | for (i=IDELEMS(arg)-1;i>=0;i--) |
---|
| 3495 | { |
---|
| 3496 | p = arg->m[i]; |
---|
| 3497 | while (p!=NULL) |
---|
| 3498 | { |
---|
| 3499 | j = pGetComp(p); |
---|
| 3500 | if (j>red_comp) |
---|
| 3501 | { |
---|
| 3502 | pSetComp(p,j-1); |
---|
| 3503 | pSetm(p); |
---|
| 3504 | } |
---|
| 3505 | pIter(p); |
---|
| 3506 | } |
---|
| 3507 | } |
---|
| 3508 | (arg->rank)--; |
---|
| 3509 | } |
---|
[955025] | 3510 | #endif |
---|
| 3511 | |
---|
| 3512 | static void idDeleteComps(ideal arg,int* red_comp,int del) |
---|
| 3513 | // red_comp is an array [0..args->rank] |
---|
| 3514 | { |
---|
| 3515 | int i,j; |
---|
| 3516 | poly p; |
---|
| 3517 | |
---|
| 3518 | for (i=IDELEMS(arg)-1;i>=0;i--) |
---|
| 3519 | { |
---|
| 3520 | p = arg->m[i]; |
---|
| 3521 | while (p!=NULL) |
---|
| 3522 | { |
---|
| 3523 | j = pGetComp(p); |
---|
| 3524 | if (red_comp[j]!=j) |
---|
| 3525 | { |
---|
| 3526 | pSetComp(p,red_comp[j]); |
---|
| 3527 | pSetmComp(p); |
---|
| 3528 | } |
---|
| 3529 | pIter(p); |
---|
| 3530 | } |
---|
| 3531 | } |
---|
| 3532 | (arg->rank) -= del; |
---|
| 3533 | } |
---|
[35aab3] | 3534 | |
---|
| 3535 | /*2 |
---|
| 3536 | * returns the presentation of an isomorphic, minimally |
---|
| 3537 | * embedded module (arg represents the quotient!) |
---|
| 3538 | */ |
---|
[cf108d] | 3539 | ideal idMinEmbedding(ideal arg,BOOLEAN inPlace, intvec **w) |
---|
[35aab3] | 3540 | { |
---|
| 3541 | if (idIs0(arg)) return idInit(1,arg->rank); |
---|
[3504d7] | 3542 | int i,next_gen,next_comp; |
---|
[35aab3] | 3543 | ideal res=arg; |
---|
| 3544 | |
---|
| 3545 | if (!inPlace) res = idCopy(arg); |
---|
[8421b8] | 3546 | res->rank=si_max(res->rank,idRankFreeModule(res)); |
---|
[955025] | 3547 | int *red_comp=(int*)omAlloc((res->rank+1)*sizeof(int)); |
---|
| 3548 | for (i=res->rank;i>=0;i--) red_comp[i]=i; |
---|
[8421b8] | 3549 | |
---|
[07b3e1] | 3550 | int del=0; |
---|
[35aab3] | 3551 | loop |
---|
| 3552 | { |
---|
| 3553 | next_gen = idReadOutUnits(res,&next_comp); |
---|
| 3554 | if (next_gen<0) break; |
---|
[07b3e1] | 3555 | del++; |
---|
[35aab3] | 3556 | syGaussForOne(res,next_gen,next_comp,0,IDELEMS(res)); |
---|
[955025] | 3557 | for(i=next_comp+1;i<=arg->rank;i++) red_comp[i]--; |
---|
[cf108d] | 3558 | if ((w !=NULL)&&(*w!=NULL)) |
---|
| 3559 | { |
---|
[07b3e1] | 3560 | for(i=next_comp;i<(*w)->length();i++) (**w)[i-1]=(**w)[i]; |
---|
[3504d7] | 3561 | } |
---|
| 3562 | } |
---|
[955025] | 3563 | |
---|
| 3564 | idDeleteComps(res,red_comp,del); |
---|
| 3565 | idSkipZeroes(res); |
---|
| 3566 | omFree(red_comp); |
---|
| 3567 | |
---|
[07b3e1] | 3568 | if ((w !=NULL)&&(*w!=NULL) &&(del>0)) |
---|
[3504d7] | 3569 | { |
---|
[07b3e1] | 3570 | intvec *wtmp=new intvec((*w)->length()-del); |
---|
| 3571 | for(i=0;i<res->rank;i++) (*wtmp)[i]=(**w)[i]; |
---|
[3504d7] | 3572 | delete *w; |
---|
| 3573 | *w=wtmp; |
---|
[35aab3] | 3574 | } |
---|
| 3575 | return res; |
---|
| 3576 | } |
---|
| 3577 | |
---|
| 3578 | /*2 |
---|
| 3579 | * transpose a module |
---|
| 3580 | */ |
---|
| 3581 | ideal idTransp(ideal a) |
---|
| 3582 | { |
---|
| 3583 | int r = a->rank, c = IDELEMS(a); |
---|
| 3584 | ideal b = idInit(r,c); |
---|
| 3585 | |
---|
| 3586 | for (int i=c; i>0; i--) |
---|
| 3587 | { |
---|
| 3588 | poly p=a->m[i-1]; |
---|
| 3589 | while(p!=NULL) |
---|
| 3590 | { |
---|
| 3591 | poly h=pHead(p); |
---|
| 3592 | int co=pGetComp(h)-1; |
---|
| 3593 | pSetComp(h,i); |
---|
| 3594 | pSetmComp(h); |
---|
| 3595 | b->m[co]=pAdd(b->m[co],h); |
---|
| 3596 | pIter(p); |
---|
| 3597 | } |
---|
| 3598 | } |
---|
| 3599 | return b; |
---|
| 3600 | } |
---|
| 3601 | |
---|
| 3602 | intvec * idQHomWeight(ideal id) |
---|
| 3603 | { |
---|
| 3604 | poly head, tail; |
---|
| 3605 | int k; |
---|
| 3606 | int in=IDELEMS(id)-1, ready=0, all=0, |
---|
| 3607 | coldim=pVariables, rowmax=2*coldim; |
---|
| 3608 | if (in<0) return NULL; |
---|
| 3609 | intvec *imat=new intvec(rowmax+1,coldim,0); |
---|
| 3610 | |
---|
| 3611 | do |
---|
| 3612 | { |
---|
| 3613 | head = id->m[in--]; |
---|
| 3614 | if (head!=NULL) |
---|
| 3615 | { |
---|
| 3616 | tail = pNext(head); |
---|
| 3617 | while (tail!=NULL) |
---|
| 3618 | { |
---|
| 3619 | all++; |
---|
| 3620 | for (k=1;k<=coldim;k++) |
---|
| 3621 | IMATELEM(*imat,all,k) = pGetExpDiff(head,tail,k); |
---|
| 3622 | if (all==rowmax) |
---|
| 3623 | { |
---|
| 3624 | ivTriangIntern(imat, ready, all); |
---|
| 3625 | if (ready==coldim) |
---|
| 3626 | { |
---|
| 3627 | delete imat; |
---|
| 3628 | return NULL; |
---|
| 3629 | } |
---|
| 3630 | } |
---|
| 3631 | pIter(tail); |
---|
| 3632 | } |
---|
| 3633 | } |
---|
| 3634 | } while (in>=0); |
---|
| 3635 | if (all>ready) |
---|
| 3636 | { |
---|
| 3637 | ivTriangIntern(imat, ready, all); |
---|
| 3638 | if (ready==coldim) |
---|
| 3639 | { |
---|
| 3640 | delete imat; |
---|
| 3641 | return NULL; |
---|
| 3642 | } |
---|
| 3643 | } |
---|
| 3644 | intvec *result = ivSolveKern(imat, ready); |
---|
| 3645 | delete imat; |
---|
| 3646 | return result; |
---|
| 3647 | } |
---|
| 3648 | |
---|
| 3649 | BOOLEAN idIsZeroDim(ideal I) |
---|
| 3650 | { |
---|
| 3651 | BOOLEAN *UsedAxis=(BOOLEAN *)omAlloc0(pVariables*sizeof(BOOLEAN)); |
---|
| 3652 | int i,n; |
---|
| 3653 | poly po; |
---|
| 3654 | BOOLEAN res=TRUE; |
---|
| 3655 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
| 3656 | { |
---|
| 3657 | po=I->m[i]; |
---|
| 3658 | if ((po!=NULL) &&((n=pIsPurePower(po))!=0)) UsedAxis[n-1]=TRUE; |
---|
| 3659 | } |
---|
| 3660 | for(i=pVariables-1;i>=0;i--) |
---|
| 3661 | { |
---|
| 3662 | if(UsedAxis[i]==FALSE) {res=FALSE; break;} // not zero-dim. |
---|
| 3663 | } |
---|
| 3664 | omFreeSize(UsedAxis,pVariables*sizeof(BOOLEAN)); |
---|
| 3665 | return res; |
---|
| 3666 | } |
---|
| 3667 | |
---|
| 3668 | void idNormalize(ideal I) |
---|
| 3669 | { |
---|
| 3670 | if (rField_has_simple_inverse()) return; /* Z/p, GF(p,n), R, long R/C */ |
---|
| 3671 | int i; |
---|
| 3672 | poly p; |
---|
| 3673 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
| 3674 | { |
---|
| 3675 | p=I->m[i] ; |
---|
| 3676 | while(p!=NULL) |
---|
| 3677 | { |
---|
| 3678 | nNormalize(pGetCoeff(p)); |
---|
| 3679 | pIter(p); |
---|
| 3680 | } |
---|
| 3681 | } |
---|
| 3682 | } |
---|
[225d94] | 3683 | |
---|
| 3684 | #include "clapsing.h" |
---|
| 3685 | |
---|
| 3686 | poly id_GCD(poly f, poly g, const ring r) |
---|
| 3687 | { |
---|
| 3688 | ring save_r=currRing; |
---|
| 3689 | rChangeCurrRing(r); |
---|
| 3690 | ideal I=idInit(2,1); I->m[0]=f; I->m[1]=g; |
---|
| 3691 | intvec *w = NULL; |
---|
| 3692 | ideal S=idSyzygies(I,testHomog,&w); |
---|
| 3693 | if (w!=NULL) delete w; |
---|
| 3694 | poly gg=pTakeOutComp(&(S->m[0]),2); |
---|
| 3695 | idDelete(&S); |
---|
| 3696 | poly gcd_p=singclap_pdivide(f,gg); |
---|
| 3697 | pDelete(&gg); |
---|
| 3698 | rChangeCurrRing(save_r); |
---|
| 3699 | return gcd_p; |
---|
| 3700 | } |
---|
[bba835] | 3701 | |
---|
| 3702 | /*2 |
---|
| 3703 | * xx,q: arrays of length 0..rl-1 |
---|
| 3704 | * xx[i]: SB mod q[i] |
---|
| 3705 | * assume: char=0 |
---|
| 3706 | * assume: q[i]!=0 |
---|
| 3707 | * destroys xx |
---|
| 3708 | */ |
---|
| 3709 | ideal idChineseRemainder(ideal *xx, number *q, int rl) |
---|
| 3710 | { |
---|
| 3711 | ideal result=idInit(IDELEMS(xx[0]),1); |
---|
| 3712 | int i,j; |
---|
[cbc7e3] | 3713 | poly r,h,hh,res_p; |
---|
[bba835] | 3714 | number *x=(number *)omAlloc(rl*sizeof(number)); |
---|
| 3715 | for(i=IDELEMS(result)-1;i>=0;i--) |
---|
| 3716 | { |
---|
| 3717 | res_p=NULL; |
---|
| 3718 | loop |
---|
| 3719 | { |
---|
| 3720 | r=NULL; |
---|
| 3721 | for(j=rl-1;j>=0;j--) |
---|
| 3722 | { |
---|
| 3723 | h=xx[j]->m[i]; |
---|
| 3724 | if ((r==NULL)||(pLmCmp(r,h)==-1)) r=h; |
---|
| 3725 | } |
---|
| 3726 | if (r==NULL) break; |
---|
[cbc7e3] | 3727 | h=pHead(r); |
---|
[bba835] | 3728 | for(j=rl-1;j>=0;j--) |
---|
| 3729 | { |
---|
[cbc7e3] | 3730 | hh=xx[j]->m[i]; |
---|
| 3731 | if ((hh!=NULL) && (pLmCmp(r,hh)==0)) |
---|
| 3732 | { |
---|
| 3733 | x[j]=pGetCoeff(hh); |
---|
| 3734 | hh=pLmFreeAndNext(hh); |
---|
| 3735 | xx[j]->m[i]=hh; |
---|
[bba835] | 3736 | } |
---|
| 3737 | else |
---|
| 3738 | x[j]=nlInit(0); |
---|
| 3739 | } |
---|
| 3740 | number n=nlChineseRemainder(x,q,rl); |
---|
| 3741 | for(j=rl-1;j>=0;j--) |
---|
| 3742 | { |
---|
| 3743 | nlDelete(&(x[j]),currRing); |
---|
| 3744 | } |
---|
| 3745 | pSetCoeff(h,n); |
---|
[cbc7e3] | 3746 | //Print("new mon:");pWrite(h); |
---|
[bba835] | 3747 | res_p=pAdd(res_p,h); |
---|
| 3748 | } |
---|
| 3749 | result->m[i]=res_p; |
---|
| 3750 | } |
---|
| 3751 | omFree(x); |
---|
| 3752 | for(i=rl-1;i>=0;i--) idDelete(&(xx[i])); |
---|
| 3753 | omFree(xx); |
---|
| 3754 | return result; |
---|
| 3755 | } |
---|
[94eaef] | 3756 | ideal idChineseRemainder(ideal *xx, intvec *iv) |
---|
| 3757 | { |
---|
| 3758 | int rl=iv->length(); |
---|
| 3759 | number *q=(number *)omAlloc(rl*sizeof(number)); |
---|
| 3760 | int i; |
---|
| 3761 | for(i=0; i<rl; i++) |
---|
| 3762 | { |
---|
| 3763 | q[i]=nInit((*iv)[i]); |
---|
| 3764 | } |
---|
| 3765 | return idChineseRemainder(xx,q,rl); |
---|
[cbc7e3] | 3766 | } |
---|