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