Changeset 5f24ec in git
- Timestamp:
- May 15, 2015, 3:29:47 PM (9 years ago)
- Branches:
- (u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
- Children:
- 794d7ba210aeabf2fc6caef7b75934cab4be8acf
- Parents:
- 7fc7218d475bdaf643d2aa7e73ce714d3cd81101
- git-author:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2015-05-15 15:29:47+02:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2015-05-27 17:34:53+02:00
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/syzextra/mod_main.cc
r7fc721 r5f24ec 67 67 BEGIN_NAMESPACE_NONAME 68 68 69 // returns TRUE, if idRankFreeModule(m) > 0 ??? 70 /// test whether this input has vectors among entries or no enties 71 /// result must be FALSE for only 0-entries 72 static BOOLEAN id_IsModule(ideal id, ring r) 73 { 74 id_Test(id, r); 75 76 if( id->rank != 1 ) return TRUE; 77 78 if (rRing_has_Comp(r)) 79 { 80 const int l = IDELEMS(id); 81 82 for (int j=0; j<l; j++) 83 if (id->m[j] != NULL && p_GetComp(id->m[j], r) > 0) 84 return TRUE; 85 86 return FALSE; // rank: 1, only zero or no entries? can be an ideal OR module... BUT in the use-case should better be an ideal! 87 } 88 89 return FALSE; 90 } 91 92 93 69 94 70 95 static inline void NoReturn(leftv& res) … … 1525 1550 const int iLimit = r->typ[pos].data.is.limit; 1526 1551 const ideal F = r->typ[pos].data.is.F; 1552 1527 1553 ideal FF = id_Copy(F, r); 1528 1529 1530 1554 1531 1555 lists l=(lists)omAllocBin(slists_bin); … … 1538 1562 // l->m[1].rtyp = MODUL_CMD; 1539 1563 1540 if( id IsModule(FF, r) )1564 if( id_IsModule(FF, r) ) // ??? 1541 1565 { 1542 1566 l->m[1].rtyp = MODUL_CMD; -
kernel/ideals.h
r7fc721 r5f24ec 104 104 BOOLEAN idIs0 (ideal h); 105 105 106 // returns TRUE, if idRankFreeModule(m) > 0107 BOOLEAN idIsModule(ideal m, const ring r);108 109 106 inline BOOLEAN idHomIdeal (ideal id, ideal Q=NULL) 110 107 { -
libpolys/polys/simpleideals.cc
r7fc721 r5f24ec 35 35 /*index of the actual monomial in idpower*/ 36 36 37 /*2 38 * initialise an ideal 39 */ 37 /// initialise an ideal / module 40 38 ideal idInit(int idsize, int rank) 41 39 { 42 /*- initialise an ideal/module -*/ 43 ideal hh = (ideal )omAllocBin(sip_sideal_bin); 44 hh->nrows = 1; 45 hh->rank = rank; 46 IDELEMS(hh) = idsize; 40 assume( idsize >= 0 && rank >= 0 ); 41 42 ideal hh = (ideal)omAllocBin(sip_sideal_bin); 43 44 IDELEMS(hh) = idsize; // ncols 45 hh->nrows = 1; // ideal/module! 46 47 hh->rank = rank; // ideal: 1, module: >= 0! 48 47 49 if (idsize>0) 48 {49 50 hh->m = (poly *)omAlloc0(idsize*sizeof(poly)); 50 }51 51 else 52 hh->m=NULL; 52 hh->m = NULL; 53 53 54 return hh; 54 55 } … … 97 98 } 98 99 99 /*2 100 * initialise the maximal ideal (at 0) 101 */ 100 /// initialise the maximal ideal (at 0) 102 101 ideal id_MaxIdeal (const ring r) 103 102 { 104 int l; 105 ideal hh=NULL; 106 107 hh=idInit(rVar(r),1); 108 for (l=0; l<rVar(r); l++) 103 const int N = rVar(r); 104 ideal hh = idInit(N, 1); 105 for (int l=0; l < N; l++) 109 106 { 110 107 hh->m[l] = p_One(r); … … 112 109 p_Setm(hh->m[l],r); 113 110 } 111 id_Test(hh, r); 114 112 return hh; 115 113 } 116 114 117 /*2 118 * deletes an ideal/matrix 119 */ 115 /// deletes an ideal/module/matrix 120 116 void id_Delete (ideal * h, ring r) 121 117 { 122 int j,elems;123 118 if (*h == NULL) 124 119 return; 125 elems=j=(*h)->nrows*(*h)->ncols; 126 if (j>0) 127 { 120 121 id_Test(*h, r); 122 123 const int elems = (*h)->nrows * (*h)->ncols; 124 125 if ( elems > 0 ) 126 { 127 assume( (*h)->m != NULL ); 128 129 int j = elems; 128 130 do 129 131 { … … 132 134 if (pp!=NULL) p_Delete(&pp, r); 133 135 } 136 while (j>0); 137 138 omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems); 139 } 140 141 omFreeBin((ADDRESS)*h, sip_sideal_bin); 142 *h=NULL; 143 } 144 145 146 /// Shallowdeletes an ideal/matrix 147 void id_ShallowDelete (ideal *h, ring r) 148 { 149 id_Test(*h, r); 150 151 if (*h == NULL) 152 return; 153 154 int j,elems; 155 elems=j=(*h)->nrows*(*h)->ncols; 156 if (j>0) 157 { 158 assume( (*h)->m != NULL ); 159 do 160 { 161 p_ShallowDelete(&((*h)->m[--j]), r); 162 } 134 163 while (j>0); 135 164 omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems); … … 139 168 } 140 169 141 142 /*2 143 * Shallowdeletes an ideal/matrix 144 */ 145 void id_ShallowDelete (ideal *h, ring r) 146 { 147 int j,elems; 148 if (*h == NULL) 149 return; 150 elems=j=(*h)->nrows*(*h)->ncols; 151 if (j>0) 152 { 153 do 154 { 155 p_ShallowDelete(&((*h)->m[--j]), r); 156 } 157 while (j>0); 158 omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems); 159 } 160 omFreeBin((ADDRESS)*h, sip_sideal_bin); 161 *h=NULL; 162 } 163 164 /*2 165 *gives an ideal the minimal possible size 166 */ 170 /// gives an ideal/module the minimal possible size 167 171 void idSkipZeroes (ideal ide) 168 172 { 173 assume (ide != NULL); 174 169 175 int k; 170 176 int j = -1; 171 BOOLEAN change=FALSE; 177 BOOLEAN change=FALSE; 178 172 179 for (k=0; k<IDELEMS(ide); k++) 173 180 { … … 199 206 } 200 207 208 /// count non-zero elements 201 209 int idElem(const ideal F) 202 210 { 211 assume (F != NULL); 212 203 213 int i=0,j=IDELEMS(F)-1; 204 214 … … 211 221 } 212 222 213 /*2 214 * copies the first k (>= 1) entries of the given ideal 215 * and returns these as a new ideal 216 * (Note that the copied polynomials may be zero.) 217 */ 223 /// copies the first k (>= 1) entries of the given ideal/module 224 /// and returns these as a new ideal/module 225 /// (Note that the copied entries may be zero.) 218 226 ideal id_CopyFirstK (const ideal ide, const int k,const ring r) 219 227 { 220 ideal newI = idInit(k, 0); 228 id_Test(ide, r); 229 230 assume( ide != NULL ); 231 assume( k <= IDELEMS(ide) ); 232 233 ideal newI = idInit(k, ide->rank); 234 221 235 for (int i = 0; i < k; i++) 222 236 newI->m[i] = p_Copy(ide->m[i],r); 237 223 238 return newI; 224 239 } 225 240 226 /*2 227 * ideal id = (id[i]) 228 * result is leadcoeff(id[i]) = 1 229 */ 241 /// ideal id = (id[i]), result is leadcoeff(id[i]) = 1 230 242 void id_Norm(ideal id, const ring r) 231 243 { 244 id_Test(id, r); 232 245 for (int i=IDELEMS(id)-1; i>=0; i--) 233 246 { … … 239 252 } 240 253 241 /*2 242 * ideal id = (id[i]), c any unit 243 * if id[i] = c*id[j] then id[j] is deleted for j > i 244 */ 254 /// ideal id = (id[i]), c any unit 255 /// if id[i] = c*id[j] then id[j] is deleted for j > i 245 256 void id_DelMultiples(ideal id, const ring r) 246 257 { 258 id_Test(id, r); 259 247 260 int i, j; 248 261 int k = IDELEMS(id)-1; … … 278 291 } 279 292 280 /*2 281 * ideal id = (id[i]) 282 * if id[i] = id[j] then id[j] is deleted for j > i 283 */ 293 /// ideal id = (id[i]) 294 /// if id[i] = id[j] then id[j] is deleted for j > i 284 295 void id_DelEquals(ideal id, const ring r) 285 296 { 297 id_Test(id, r); 298 286 299 int i, j; 287 300 int k = IDELEMS(id)-1; … … 302 315 } 303 316 304 // 305 // Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i 306 // 317 /// Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i 307 318 void id_DelLmEquals(ideal id, const ring r) 308 319 { 320 id_Test(id, r); 321 309 322 int i, j; 310 323 int k = IDELEMS(id)-1; … … 329 342 } 330 343 331 // 332 // delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., 333 // delete id[i], if LT(i) == coeff*mon*LT(j) 334 // 344 /// delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., 345 /// delete id[i], if LT(i) == coeff*mon*LT(j) 335 346 void id_DelDiv(ideal id, const ring r) 336 347 { 348 id_Test(id, r); 349 337 350 int i, j; 338 351 int k = IDELEMS(id)-1; … … 380 393 } 381 394 382 /*2 383 *test if the ideal has only constant polynomials 384 */ 395 /// test if the ideal has only constant polynomials 396 /// NOTE: zero ideal/module is also constant 385 397 BOOLEAN id_IsConstant(ideal id, const ring r) 386 398 { 387 int k; 388 for (k = IDELEMS(id)-1; k>=0; k--) 399 id_Test(id, r); 400 401 for (int k = IDELEMS(id)-1; k>=0; k--) 389 402 { 390 403 if (!p_IsConstantPoly(id->m[k],r)) … … 394 407 } 395 408 396 /*2 397 * copy an ideal 398 */ 409 /// copy an ideal 399 410 ideal id_Copy(ideal h1, const ring r) 400 411 { 401 int i; 402 ideal h2 =idInit(IDELEMS(h1),h1->rank); 403 for (i=IDELEMS(h1)-1; i>=0; i--) 412 id_Test(h1, r); 413 414 ideal h2 = idInit(IDELEMS(h1), h1->rank); 415 for (int i=IDELEMS(h1)-1; i>=0; i--) 404 416 h2->m[i] = p_Copy(h1->m[i],r); 405 417 return h2; … … 407 419 408 420 #ifdef PDEBUG 421 /// Internal verification for ideals/modules and dense matrices! 409 422 void id_DBTest(ideal h1, int level, const char *f,const int l, const ring r, const ring tailRing) 410 423 { 411 int i;412 413 424 if (h1 != NULL) 414 { 425 { 415 426 // assume(IDELEMS(h1) > 0); for ideal/module, does not apply to matrix 416 427 omCheckAddrSize(h1,sizeof(*h1)); 417 omdebugAddrSize(h1->m,h1->ncols*h1->nrows*sizeof(poly)); 428 429 assume( h1->ncols >= 0 ); 430 assume( h1->nrows >= 0 ); // matrix case! 431 432 assume( h1->rank >= 0 ); 433 434 const int n = (h1->ncols * h1->nrows); 435 436 assume( !( n > 0 && h1->m == NULL) ); 437 438 if( h1->m != NULL && n > 0 ) 439 omdebugAddrSize(h1->m, n * sizeof(poly)); 440 441 long new_rk = 0; // inlining id_RankFreeModule(h1, r, tailRing); 418 442 419 443 /* to be able to test matrices: */ 420 for (i=(h1->ncols*h1->nrows)-1; i>=0; i--) 444 for (int i=n - 1; i >= 0; i--) 445 { 421 446 _pp_Test(h1->m[i], r, tailRing, level); 422 423 int new_rk=id_RankFreeModule(h1, r, tailRing); 447 const long k = p_MaxComp(h1->m[i], r, tailRing); 448 if (k > new_rk) new_rk = k; 449 } 450 451 // dense matrices only contain polynomials: 452 // h1->nrows == h1->rank > 1 && new_rk == 0! 453 assume( !( h1->nrows == h1->rank && h1->nrows > 1 && new_rk > 0 ) ); // 454 424 455 if(new_rk > h1->rank) 425 456 { … … 427 458 h1->rank, new_rk, f,l); 428 459 omPrintAddrInfo(stderr, h1, " for ideal"); 429 h1->rank =new_rk;460 h1->rank = new_rk; 430 461 } 431 462 } 432 463 else 464 { 433 465 Print("error: ideal==NULL in %s:%d\n",f,l); 466 assume( h1 != NULL ); 467 } 434 468 } 435 469 #endif 436 470 437 /// 3for idSort: compare a and b revlex inclusive module comp.471 /// for idSort: compare a and b revlex inclusive module comp. 438 472 static int p_Comp_RevLex(poly a, poly b,BOOLEAN nolex, const ring R) 439 473 { … … 472 506 intvec *id_Sort(const ideal id, const BOOLEAN nolex, const ring r) 473 507 { 508 id_Test(id, r); 509 474 510 intvec * result = new intvec(IDELEMS(id)); 475 511 int i, j, actpos=0, newpos; … … 562 598 } 563 599 564 /*2 565 * concat the lists h1 and h2 without zeros 566 */ 600 /// concat the lists h1 and h2 without zeros 567 601 ideal id_SimpleAdd (ideal h1,ideal h2, const ring R) 568 602 { 569 int i,j,r,l; 570 ideal result; 571 572 j = IDELEMS(h1)-1; 603 id_Test(h1, R); 604 id_Test(h2, R); 605 606 if ( idIs0(h1) ) return id_Copy(h2,R); 607 if ( idIs0(h2) ) return id_Copy(h1,R); 608 609 int j = IDELEMS(h1)-1; 573 610 while ((j >= 0) && (h1->m[j] == NULL)) j--; 574 i = IDELEMS(h2)-1; 611 612 int i = IDELEMS(h2)-1; 575 613 while ((i >= 0) && (h2->m[i] == NULL)) i--; 576 r = si_max(h1->rank,h2->rank); 577 if (i+j==(-2)) 578 return idInit(1,r); 579 else 580 result=idInit(i+j+2,r); 614 615 const int r = si_max(h1->rank, h2->rank); 616 617 ideal result = idInit(i+j+2,r); 618 619 int l; 620 581 621 for (l=j; l>=0; l--) 582 {583 622 result->m[l] = p_Copy(h1->m[l],R); 584 } 585 r = i+j+1; 586 for (l=i; l>=0; l--, r--) 587 { 588 result->m[r] = p_Copy(h2->m[l],R); 589 } 623 624 j = i+j+1; 625 for (l=i; l>=0; l--, j--) 626 result->m[j] = p_Copy(h2->m[l],R); 627 590 628 return result; 591 629 } 592 630 593 /*2 594 * insert h2 into h1 (if h2 is not the zero polynomial) 595 * return TRUE iff h2 was indeed inserted 596 */ 631 /// insert h2 into h1 (if h2 is not the zero polynomial) 632 /// return TRUE iff h2 was indeed inserted 597 633 BOOLEAN idInsertPoly (ideal h1, poly h2) 598 634 { 599 635 if (h2==NULL) return FALSE; 600 int j = IDELEMS(h1)-1; 636 assume (h1 != NULL); 637 638 int j = IDELEMS(h1) - 1; 639 601 640 while ((j >= 0) && (h1->m[j] == NULL)) j--; 602 641 j++; … … 610 649 } 611 650 612 /*2 613 *insert h2 into h1 depending on the two boolean parameters:614 * - if zeroOk is true, then h2 will also be inserted when it is zero615 * - if duplicateOk is true, then h2 will also be inserted when it is616 * already present in h1617 * return TRUE iff h2 was indeed inserted618 */651 652 /*! insert h2 into h1 depending on the two boolean parameters: 653 * - if zeroOk is true, then h2 will also be inserted when it is zero 654 * - if duplicateOk is true, then h2 will also be inserted when it is 655 * already present in h1 656 * return TRUE iff h2 was indeed inserted 657 */ 619 658 BOOLEAN id_InsertPolyWithTests (ideal h1, const int validEntries, 620 659 const poly h2, const bool zeroOk, const bool duplicateOk, const ring r) 621 660 { 661 id_Test(h1, r); 662 p_Test(h2, r); 663 622 664 if ((!zeroOk) && (h2 == NULL)) return FALSE; 623 665 if (!duplicateOk) … … 641 683 } 642 684 643 /*2 644 * h1 + h2 645 */ 685 /// h1 + h2 646 686 ideal id_Add (ideal h1,ideal h2, const ring r) 647 687 { 688 id_Test(h1, r); 689 id_Test(h2, r); 690 648 691 ideal result = id_SimpleAdd(h1,h2,r); 649 692 id_Compactify(result,r); … … 651 694 } 652 695 653 / *2654 * h1 * h2 655 */ 696 /// h1 * h2 697 /// h1 must be an ideal (with at least one column) 698 /// h2 may be a module (with no columns at all) 656 699 ideal id_Mult (ideal h1,ideal h2, const ring r) 657 700 { 658 int i,j,k; 659 ideal hh; 660 661 j = IDELEMS(h1); 701 id_Test(h1, r); 702 id_Test(h2, r); 703 704 assume( h1->rank == 1 ); 705 706 int j = IDELEMS(h1); 662 707 while ((j > 0) && (h1->m[j-1] == NULL)) j--; 663 i = IDELEMS(h2); 708 709 int i = IDELEMS(h2); 664 710 while ((i > 0) && (h2->m[i-1] == NULL)) i--; 711 665 712 j = j * i; 666 if (j == 0) 667 hh = idInit(1,1); 668 else 669 hh=idInit(j,1); 670 if (h1->rank<h2->rank) 671 hh->rank = h2->rank; 672 else 673 hh->rank = h1->rank; 713 714 ideal hh = idInit(j, si_max( h2->rank, h1->rank )); 715 674 716 if (j==0) return hh; 675 k = 0; 717 718 int k = 0; 676 719 for (i=0; i<IDELEMS(h1); i++) 677 720 { … … 688 731 } 689 732 } 690 { 691 id_Compactify(hh,r); 692 return hh; 693 } 694 } 695 696 /*2 697 *returns true if h is the zero ideal 698 */ 733 734 id_Compactify(hh,r); 735 return hh; 736 } 737 738 /// returns true if h is the zero ideal 699 739 BOOLEAN idIs0 (ideal h) 700 740 { 701 int i; 702 703 i = IDELEMS(h)-1; 704 while ((i >= 0) && (h->m[i] == NULL)) 705 { 706 i--; 707 } 708 if (i < 0) 709 return TRUE; 710 else 711 return FALSE; 712 } 713 714 /*2 715 * return the maximal component number found in any polynomial in s 716 */ 741 assume (h != NULL); // will fail :( 742 // if (h == NULL) return TRUE; 743 744 for( int i = IDELEMS(h)-1; i >= 0; i-- ) 745 if(h->m[i] != NULL) 746 return FALSE; 747 748 return TRUE; 749 750 } 751 752 /// return the maximal component number found in any polynomial in s 717 753 long id_RankFreeModule (ideal s, ring lmRing, ring tailRing) 718 754 { 719 long j=0; 755 id_TestTail(s, lmRing, tailRing); 756 757 long j = 0; 720 758 721 759 if (rRing_has_Comp(tailRing) && rRing_has_Comp(lmRing)) … … 723 761 poly *p=s->m; 724 762 for (unsigned int l=IDELEMS(s); l > 0; --l, ++p) 725 { 726 if (*p!=NULL) 763 if (*p != NULL) 727 764 { 728 765 pp_Test(*p, lmRing, tailRing); … … 730 767 if (k>j) j = k; 731 768 } 732 } 733 } 734 return j; 735 } 736 737 BOOLEAN idIsModule(ideal id, ring r) 738 { 739 if (rRing_has_Comp(r)) 740 { 741 int j, l = IDELEMS(id); 742 for (j=0; j<l; j++) 743 { 744 if (id->m[j] != NULL && p_GetComp(id->m[j], r) > 0) return TRUE; 745 } 746 } 747 return FALSE; 748 } 749 769 } 770 771 return j; // return -1; 772 } 750 773 751 774 /*2 … … 879 902 } 880 903 881 /*2 882 *the free module of rank i 883 */ 904 905 /// the free module of rank i 884 906 ideal id_FreeModule (int i, const ring r) 885 907 { 886 int j; 887 ideal h; 888 889 h=idInit(i,i); 890 for (j=0; j<i; j++) 908 assume(i >= 0); 909 ideal h = idInit(i, i); 910 911 for (int j=0; j<i; j++) 891 912 { 892 913 h->m[j] = p_One(r); … … 894 915 p_SetmComp(h->m[j],r); 895 916 } 917 896 918 return h; 897 919 } … … 1057 1079 } 1058 1080 1059 /*2 1060 * returns the ideals of initial terms 1061 */ 1081 /// returns the ideals of initial terms 1062 1082 ideal id_Head(ideal h,const ring r) 1063 1083 { 1064 1084 ideal m = idInit(IDELEMS(h),h->rank); 1065 int i; 1066 1067 for (i=IDELEMS(h)-1;i>=0; i--) 1068 { 1069 if (h->m[i]!=NULL) m->m[i]=p_Head(h->m[i],r); 1070 } 1085 1086 for (int i=IDELEMS(h)-1;i>=0; i--) 1087 if (h->m[i]!=NULL) 1088 m->m[i]=p_Head(h->m[i],r); 1089 1071 1090 return m; 1072 1091 } … … 1356 1375 r->ncols = i-> ncols; 1357 1376 //r->rank = i-> rank; 1358 int k; 1359 for(k=(i->nrows)*(i->ncols)-1;k>=0; k--) 1360 { 1377 1378 for(int k=(i->nrows)*(i->ncols)-1;k>=0; k--) 1361 1379 r->m[k]=pp_Jet(i->m[k],d,R); 1362 }1380 1363 1381 return r; 1364 1382 } … … 1722 1740 void id_Shift(ideal M, int s, const ring r) 1723 1741 { 1742 // id_Test( M, r ); 1743 1744 // assume( s >= 0 ); // negative is also possible // TODO: verify input ideal in such a case!? 1745 1724 1746 for(int i=IDELEMS(M)-1; i>=0;i--) 1725 {1726 1747 p_Shift(&(M->m[i]),s,r); 1727 }1748 1728 1749 M->rank += s; 1729 } 1750 1751 // id_Test( M, r ); 1752 } -
libpolys/polys/simpleideals.h
r7fc721 r5f24ec 11 11 #include <polys/matpol.h> 12 12 13 /// The following sip_sideal structure has many different uses 14 /// thoughout Singular. Basic use-cases for it are: 15 /// * ideal/module: nrows = 1, ncols >=0 and rank:1 for ideals, rank>=0 for modules 16 /// * matrix: nrows, ncols >=0, rank == nrows! see mp_* procedures 17 /// NOTE: the m member point to memory chunk of size (ncols*nrows*sizeof(poly)) or is NULL 13 18 struct sip_sideal 14 19 { … … 52 57 extern omBin sip_sideal_bin; 53 58 54 / *- creates an ideal -*/59 /// creates an ideal / module 55 60 ideal idInit (int size, int rank=1); 56 61 … … 91 96 static inline long id_RankFreeModule(ideal m, ring r) 92 97 {return id_RankFreeModule(m, r, r);} 93 // returns TRUE, if idRankFreeModule(m) > 0 94 BOOLEAN id_IsModule(ideal m, ring r); 98 95 99 ideal id_FreeModule (int i, const ring r); 96 100 int idElem(const ideal F);
Note: See TracChangeset
for help on using the changeset viewer.