Changeset e858e7 in git
- Timestamp:
- Jun 28, 1999, 6:06:34 PM (24 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 6035d5fe0c5ee43d9a8eb9a890ecdfb7fd03236f
- Parents:
- 0f5091ea1879ab5dca9d221f9cfc0b248090d973
- Files:
-
- 3 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/clapsing.cc
r0f5091 re858e7 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 // $Id: clapsing.cc,v 1.5 2 1999-06-15 08:32:31Singular Exp $5 // $Id: clapsing.cc,v 1.53 1999-06-28 16:06:22 Singular Exp $ 6 6 /* 7 7 * ABSTRACT: interface between Singular and factory … … 639 639 { 640 640 (*v)=new intvec(1); 641 (* v)[1]=1;641 (**v)[0]=1; 642 642 } 643 643 return res; … … 1138 1138 ideal f=singclap_factorize((poly)(u->Data()), &v, 0); 1139 1139 if (f==NULL) return TRUE; 1140 #ifdef MDEBUG 1141 v->ivTEST(); 1142 #endif 1140 1143 lists l=(lists)Alloc(sizeof(slists)); 1141 1144 l->Init(2); -
Singular/intvec.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: intvec.cc,v 1.1 2 1999-04-17 12:30:17Singular Exp $ */4 /* $Id: intvec.cc,v 1.13 1999-06-28 16:06:23 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: class intvec: lists/vectors of integers … … 82 82 if ((col == 1)&&(mat!=INTMAT_CMD)) 83 83 { 84 int i ;85 for ( i=0; i<row-1; i++)84 int i=0; 85 for (; i<row-1; i++) 86 86 { 87 87 StringAppend("%d,",v[i]); -
Singular/intvec.h
r0f5091 re858e7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: intvec.h,v 1. 7 1999-04-16 07:53:34 obachmanExp $ */6 /* $Id: intvec.h,v 1.8 1999-06-28 16:06:23 Singular Exp $ */ 7 7 /* 8 8 * ABSTRACT: class intvec: lists/vectors of integers … … 32 32 int range(int i, int j) 33 33 { return ((i<row) && (i>=0) && (j<col) && (j>=0)); } 34 int& operator[](int i) { 34 int& operator[](int i) 35 { 36 #ifndef NDEBUG 35 37 if((i<0)||(i>=row*col)) 36 38 { 37 39 Werror("wrong intvec index:%d\n",i); 38 40 } 39 return v[i];} 41 #endif 42 return v[i]; 43 } 40 44 #define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1] 41 45 void operator+=(int intop); … … 68 72 } 69 73 } 74 void ivTEST() 75 { 76 #ifdef MDEBUG 77 mmTestL(this); 78 mmTest((ADDRESS)v,sizeof(int)*row*col); 79 #endif 80 } 70 81 }; 71 82 intvec * ivCopy(intvec * o); -
Singular/mpr_base.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mpr_base.cc,v 1. 1 1999-06-28 12:48:11 wenkExp $ */5 6 /* 4 /* $Id: mpr_base.cc,v 1.2 1999-06-28 16:06:24 Singular Exp $ */ 5 6 /* 7 7 * ABSTRACT - multipolynomial resultants - resultant matrices 8 8 * ( sparse, dense, u-resultant solver ) … … 53 53 #define MINVDIST 0.0 54 54 #define RVMULT 0.00005 // 0.000000005 55 #define MAXVARS 100 55 #define MAXVARS 100 56 56 //<- 57 57 … … 62 62 63 63 /* Linear Program stuff */ 64 struct linProg { // Linear Program stuff 65 mprfloat **LiPM; 66 int *izrov, *iposv; 67 int LiPM_cols,LiPM_rows; 64 struct linProg 65 { 66 mprfloat **LiPM; 67 int *izrov, *iposv; 68 int LiPM_cols,LiPM_rows; 68 69 }; 69 70 … … 89 90 90 91 const poly getUDet( const number* evpoint ); 91 92 92 93 private: 93 94 resMatrixSparse( const resMatrixSparse & ); … … 102 103 103 104 /* Remaps a result of LP to the according point set Qi. 104 * Returns false iff remaping was not possible, otherwise true. 105 * Returns false iff remaping was not possible, otherwise true. 105 106 */ 106 107 bool remapXiToPoint( const int indx, pointSet **pQ, int *set, int *vtx ); … … 120 121 private: 121 122 ideal gls; 122 123 123 124 int n, idelem; // number of variables, polynoms 124 125 int numSet0; // number of elements in S0 125 126 int msize; // size of matrix 126 127 127 128 intvec *uRPos; 128 129 129 130 ideal rmat; // sparse matrix representation 130 131 131 132 linProg LP; 132 133 }; … … 138 139 typedef unsigned int Coord_t; 139 140 140 struct setID { 141 struct setID 142 { 141 143 int set; 142 144 int pnt; 143 145 }; 144 146 145 struct onePoint { 147 struct onePoint 148 { 146 149 Coord_t * point; // point[0] is unused, maxial dimension is MAXVARS+1 147 150 setID rc; // filled in by Row Content Function … … 151 154 typedef struct onePoint * onePointP; 152 155 153 /* sparse matrix entry */ 154 struct _entry { 156 /* sparse matrix entry */ 157 struct _entry 158 { 155 159 number num; 156 160 int col; … … 162 166 163 167 //-> class pointSet 164 class pointSet { 168 class pointSet 169 { 165 170 private: 166 171 onePointP *points; // set of onePoint's, index [1..num], supports of monoms … … 218 223 /* Returns index of supp(LT(p)) in pointSet. */ 219 224 int getExpPos( const poly p ); 220 225 221 226 /** sort lex 222 227 */ … … 252 257 //-> class convexHull 253 258 /* Compute convex hull of given exponent set */ 254 class convexHull { 259 class convexHull 260 { 255 261 public: 256 262 convexHull( linProgP _pLP ) : pLP(_pLP) {} … … 264 270 265 271 private: 266 /** Returns true iff the support of poly pointPoly is inside the 272 /** Returns true iff the support of poly pointPoly is inside the 267 273 * convex hull of all points given by the support of poly p. 268 274 */ … … 278 284 //-> class mayanPyramidAlg 279 285 /* Compute all lattice points in a given convex hull */ 280 class mayanPyramidAlg { 286 class mayanPyramidAlg 287 { 281 288 public: 282 289 mayanPyramidAlg( linProgP _pLP ) : n(pVariables), pLP(_pLP) {} … … 290 297 private: 291 298 292 /** Recursive Mayan Pyramid algorithm for directly computing MinkowskiSum 293 * lattice points for (n+1)-fold MinkowskiSum of given point sets Qi[]. 299 /** Recursive Mayan Pyramid algorithm for directly computing MinkowskiSum 300 * lattice points for (n+1)-fold MinkowskiSum of given point sets Qi[]. 294 301 * Recursively for range of dim: dim in [0..n); acoords[0..var) fixed. 295 302 * Stores only MinkowskiSum points of udist > 0: done by storeMinkowskiSumPoints. … … 299 306 /** Compute v-distance via Linear Programing 300 307 * Linear Program finds the v-distance of the point in accords[]. 301 * The v-distance is the distance along the direction v to boundary of 308 * The v-distance is the distance along the direction v to boundary of 302 309 * Minkowski Sum of Qi (here vector v is represented by shift[]). 303 310 * Returns the v-distance or -1.0 if an error occured. … … 307 314 /** LP for finding min/max coord in MinkowskiSum, given previous coors. 308 315 * Assume MinkowskiSum in non-negative quadrants 309 * coor in [0,n); fixed coords in acoords[0..coor) 316 * coor in [0,n); fixed coords in acoords[0..coor) 310 317 */ 311 318 void mn_mx_MinkowskiSum( int dim, Coord_t *minR, Coord_t *maxR ); … … 315 322 */ 316 323 bool storeMinkowskiSumPoint(); 317 324 318 325 private: 319 326 pointSet **Qi; … … 335 342 int i, j; 336 343 337 for (i = 1; i <= maxrow; i++) { 344 for (i = 1; i <= maxrow; i++) 345 { 338 346 Print("["); 339 347 for (j = 1; j <= maxcol; j++) Print("% 7.2f, ", a[i][j]); … … 346 354 347 355 printf("Output matrix from LinProg"); 348 for (i = 1; i <= nrows; i++) { 356 for (i = 1; i <= nrows; i++) 357 { 349 358 printf("\n[ "); 350 359 if (i == 1) printf(" "); … … 360 369 { 361 370 int i; 362 for ( i= 1; i <= n; i++ ) { 371 for ( i= 1; i <= n; i++ ) 372 { 363 373 Print(" %d",vert->point[i] ); 364 374 #ifdef LONG_OUTPUT … … 372 382 int val; 373 383 Print(" matrix m[%d][%d]=(\n",MATROWS( omat ),MATCOLS( omat )); 374 for ( i= 1; i <= MATROWS( omat ); i++ ) { 375 for ( j= 1; j <= MATCOLS( omat ); j++ ) { 376 if ( MATELEM( omat, i, j) && pGetCoeff( MATELEM( omat, i, j) ) ) { 377 val= nInt(pGetCoeff( MATELEM( omat, i, j) )); 378 if ( i==MATROWS(omat) && j==MATCOLS(omat) ) { 379 if ( !val ) Print(" 0 "); 380 else Print("%d ",val); 381 } else { 382 if ( !val ) Print(" 0, "); 383 else Print("%d, ",val); 384 } 385 } else { 386 if ( i==MATROWS(omat) && j==MATCOLS(omat) ) { 387 Print(" 0"); 388 } else { 389 Print(" 0, "); 390 } 384 for ( i= 1; i <= MATROWS( omat ); i++ ) 385 { 386 for ( j= 1; j <= MATCOLS( omat ); j++ ) 387 { 388 if ( MATELEM( omat, i, j) && pGetCoeff( MATELEM( omat, i, j) ) ) 389 { 390 val= nInt(pGetCoeff( MATELEM( omat, i, j) )); 391 if ( i==MATROWS(omat) && j==MATCOLS(omat) ) 392 { 393 if ( !val ) Print(" 0 "); 394 else Print("%d ",val); 395 } 396 else 397 { 398 if ( !val ) Print(" 0, "); 399 else Print("%d, ",val); 400 } 401 } 402 else 403 { 404 if ( i==MATROWS(omat) && j==MATCOLS(omat) ) 405 { 406 Print(" 0"); 407 } 408 else 409 { 410 Print(" 0, "); 411 } 391 412 } 392 413 } … … 394 415 } 395 416 Print(");\n"); 396 } 417 } 397 418 #endif 398 419 //<- … … 404 425 int i; 405 426 points = (onePointP *)Alloc( (count+1) * sizeof(onePointP) ); 406 for ( i= 0; i <= max; i++ ) { 427 for ( i= 0; i <= max; i++ ) 428 { 407 429 points[i]= (onePointP)Alloc( sizeof(onePoint) ); 408 430 points[i]->point= (Coord_t *)Alloc0( (dim+2) * sizeof(Coord_t) ); … … 415 437 int i; 416 438 int fdim= lifted ? dim+1 : dim+2; 417 for ( i= 0; i <= max; i++ ) { 439 for ( i= 0; i <= max; i++ ) 440 { 418 441 Free( (ADDRESS) points[i]->point, fdim * sizeof(Coord_t) ); 419 442 Free( (ADDRESS) points[i], sizeof(onePoint) ); … … 430 453 inline bool pointSet::checkMem() 431 454 { 432 if ( num >= max ) { 455 if ( num >= max ) 456 { 433 457 int i; 434 458 int fdim= lifted ? dim+1 : dim+2; 435 points= (onePointP*)ReAlloc( points, 436 (max+1) * sizeof(onePointP), 437 (2*max + 1) * sizeof(onePointP) ); 438 for ( i= max+1; i <= max*2; i++ ) { 459 points= (onePointP*)ReAlloc( points, 460 (max+1) * sizeof(onePointP), 461 (2*max + 1) * sizeof(onePointP) ); 462 for ( i= max+1; i <= max*2; i++ ) 463 { 439 464 points[i]= (onePointP)Alloc( sizeof(struct onePoint) ); 440 465 points[i]->point= (Coord_t *)Alloc0( fdim * sizeof(Coord_t) ); … … 483 508 { 484 509 assume( indx > 0 && indx <= num ); 485 if ( indx != num ) { 510 if ( indx != num ) 511 { 486 512 onePointP tmp; 487 513 tmp= points[indx]; … … 498 524 int i,j; 499 525 500 for ( i= 1; i <= num; i++ ) { 526 for ( i= 1; i <= num; i++ ) 527 { 501 528 for ( j= 1; j <= dim; j++ ) 502 529 if ( points[i]->point[j] != vert->point[j] ) break; 503 530 if ( j > dim ) break; 504 531 } 505 506 if ( i > num ) { 532 533 if ( i > num ) 534 { 507 535 addPoint( vert ); 508 536 return true; … … 515 543 int i,j; 516 544 517 for ( i= 1; i <= num; i++ ) { 545 for ( i= 1; i <= num; i++ ) 546 { 518 547 for ( j= 1; j <= dim; j++ ) 519 548 if ( points[i]->point[j] != (Coord_t) vert[j] ) break; 520 549 if ( j > dim ) break; 521 550 } 522 523 if ( i > num ) { 551 552 if ( i > num ) 553 { 524 554 addPoint( vert ); 525 555 return true; … … 535 565 vert= (Exponent_t *)Alloc( (dim+1) * sizeof(Exponent_t) ); 536 566 537 while ( piter ) { 567 while ( piter ) 568 { 538 569 pGetExpV( piter, vert ); 539 570 540 for ( i= 1; i <= num; i++ ) { 571 for ( i= 1; i <= num; i++ ) 572 { 541 573 for ( j= 1; j <= dim; j++ ) 542 574 if ( points[i]->point[j] != (Coord_t) vert[j] ) break; 543 575 if ( j > dim ) break; 544 576 } 545 577 546 if ( i > num ) { 578 if ( i > num ) 579 { 547 580 addPoint( vert ); 548 581 } … … 562 595 563 596 pGetExpV( p, vert ); 564 for ( i= 1; i <= num; i++ ) { 597 for ( i= 1; i <= num; i++ ) 598 { 565 599 for ( j= 1; j <= dim; j++ ) 566 600 if ( points[i]->point[j] != (Coord_t) vert[j] ) break; … … 586 620 { 587 621 int i; 588 589 for ( i= 1; i <= dim; i++ ) { 590 if ( points[a]->point[i] > points[b]->point[i] ) { 622 623 for ( i= 1; i <= dim; i++ ) 624 { 625 if ( points[a]->point[i] > points[b]->point[i] ) 626 { 591 627 return false; 592 628 } 593 if ( points[a]->point[i] < points[b]->point[i] ) { 629 if ( points[a]->point[i] < points[b]->point[i] ) 630 { 594 631 return true; 595 632 } … … 602 639 { 603 640 int i; 604 605 for ( i= 1; i <= dim; i++ ) { 606 if ( points[a]->point[i] < points[b]->point[i] ) { 641 642 for ( i= 1; i <= dim; i++ ) 643 { 644 if ( points[a]->point[i] < points[b]->point[i] ) 645 { 607 646 return false; 608 647 } 609 if ( points[a]->point[i] > points[b]->point[i] ) { 648 if ( points[a]->point[i] > points[b]->point[i] ) 649 { 610 650 return true; 611 651 } … … 621 661 onePointP tmp; 622 662 623 while ( found ) { 663 while ( found ) 664 { 624 665 found= false; 625 for ( i= 1; i < num; i++ ) { 626 if ( larger( i, i+1 ) ) { 627 tmp= points[i]; 628 points[i]= points[i+1]; 629 points[i+1]= tmp; 630 631 found= true; 666 for ( i= 1; i < num; i++ ) 667 { 668 if ( larger( i, i+1 ) ) 669 { 670 tmp= points[i]; 671 points[i]= points[i+1]; 672 points[i+1]= tmp; 673 674 found= true; 632 675 } 633 676 } … … 642 685 643 686 time_t *tp = NULL; 644 seed = ((int)time(tp) % MAXSEED) + index; // secs since 1/1/70 ->[1,MAXSEED] 687 seed = ((int)time(tp) % MAXSEED) + index; // secs since 1/1/70 ->[1,MAXSEED] 645 688 //seed= 100+index; 646 689 647 690 dim++; 648 691 649 if ( !l ) { 692 if ( l==NULL ) 693 { 650 694 outerL= false; 651 695 l= (int *)Alloc( (dim+1) * sizeof(int) ); // [1..dim-1] 652 696 653 697 srand48( (long)(seed*(index+MAXSEED*18)) ); // index+MAXSEED*MAXVARS 654 for(i = 1; i < dim; i++) { 698 for(i = 1; i < dim; i++) 699 { 655 700 l[i]= 1 + ((unsigned int) mrand48()) % LIFT_COOR; 656 701 } 657 702 } 658 for ( j=1; j <= num; j++ ) { 703 for ( j=1; j <= num; j++ ) 704 { 659 705 sum= 0; 660 for ( i=1; i < dim; i++ ) { 706 for ( i=1; i < dim; i++ ) 707 { 661 708 sum += (int)points[j]->point[i] * l[i]; 662 709 } 663 710 points[j]->point[dim]= sum; 664 711 } 665 712 666 713 #ifdef mprDEBUG_ALL 667 714 Print(" lift vector: "); … … 670 717 #ifdef mprDEBUG_ALL 671 718 Print(" lifted points: \n"); 672 for ( j=1; j <= num; j++ ) { 719 for ( j=1; j <= num; j++ ) 720 { 673 721 Print("%d: <",j);print_exp(points[j],dim);Print(">\n"); 674 722 } … … 698 746 { 699 747 int i, j, col, icase; 700 int numcons; // num of constraints 701 int numpts; // num of pts in defining support 702 int numcols; // tot number of cols 703 704 numcons = n+1; 705 numpts = m-1; 706 numcols = numpts+1; // this includes col of cts 707 708 pLP->LiPM[1][1] = +0.0; pLP->LiPM[1][2] = +1.0; // optimize (arbitrary) var 709 pLP->LiPM[2][1] = +1.0; pLP->LiPM[2][2] = -1.0; // lambda vars sum up to 1 710 for ( j=3; j<=numcols; j++) { 748 int numcons; // num of constraints 749 int numpts; // num of pts in defining support 750 int numcols; // tot number of cols 751 752 numcons = n+1; 753 numpts = m-1; 754 numcols = numpts+1; // this includes col of cts 755 756 pLP->LiPM[1][1] = +0.0; pLP->LiPM[1][2] = +1.0; // optimize (arbitrary) var 757 pLP->LiPM[2][1] = +1.0; pLP->LiPM[2][2] = -1.0; // lambda vars sum up to 1 758 for ( j=3; j<=numcols; j++) 759 { 711 760 pLP->LiPM[1][j] = +0.0; pLP->LiPM[2][j] = -1.0; 712 761 } 713 762 714 for( i= 1; i <= n; i++) { // each row constraints one coor763 for( i= 1; i <= n; i++) { // each row constraints one coor 715 764 pLP->LiPM[i+2][1] = (mprfloat)pGetExp(pointPoly,i); 716 765 col = 2; 717 for( j= 1; j <= m; j++ ) { 718 if( j != site ) { 766 for( j= 1; j <= m; j++ ) 767 { 768 if( j != site ) 769 { 719 770 pLP->LiPM[i+2][col] = -(mprfloat)pGetExp( monomAt(p,j), i ); 720 771 col++; … … 728 779 #endif 729 780 #if 1 730 if ( numcons + 1 > pLP->LiPM_rows ) Werror("convexHull::inHull: #rows > #pLP->LiPM_rows!"); 731 if ( numcols + 1 > pLP->LiPM_cols ) Werror("convexHull::inHull: #cols > #pLP->LiPM_cols!"); 781 if ( numcons + 1 > pLP->LiPM_rows ) 782 WerrorS("convexHull::inHull: #rows > #pLP->LiPM_rows!"); 783 if ( numcols + 1 > pLP->LiPM_cols ) 784 WerrorS("convexHull::inHull: #cols > #pLP->LiPM_cols!"); 732 785 #endif 733 786 734 787 simplx( pLP->LiPM, numcons, numcols-1, 0, 0, numcons, &icase, pLP->izrov, pLP->iposv); 735 788 736 return (icase == 0); 789 return (icase == 0); 737 790 } 738 791 … … 747 800 Exponent_t * vert; 748 801 749 n= pVariables; 802 n= pVariables; 750 803 vert= (Exponent_t *)Alloc( (idelem+1) * sizeof(Exponent_t) ); 751 804 752 Q = (pointSet **)Alloc( idelem * sizeof(pointSet*) ); // support hulls805 Q = (pointSet **)Alloc( idelem * sizeof(pointSet*) ); // support hulls 753 806 for ( i= 0; i < idelem; i++ ) 754 807 Q[i] = new pointSet( pVariables, i+1, pLength((gls->m)[i])+1 ); 755 808 756 for( i= 0; i < idelem; i++ ) { 809 for( i= 0; i < idelem; i++ ) 810 { 757 811 k=1; 758 812 m = pLength( (gls->m)[i] ); 759 813 760 814 poly p= (gls->m)[i]; 761 for( j= 1; j <= m; j++) { // für jeden Exponentvektor 762 if( !inHull( (gls->m)[i], p, m, j ) ) { 763 pGetExpV( p, vert ); 815 for( j= 1; j <= m; j++) { // für jeden Exponentvektor 816 if( !inHull( (gls->m)[i], p, m, j ) ) 817 { 818 pGetExpV( p, vert ); 764 819 Q[i]->addPoint( vert ); 765 k++; 766 mprSTICKYPROT(ST_SPARSE_VADD); 767 } else { 768 mprSTICKYPROT(ST_SPARSE_VREJ); 820 k++; 821 mprSTICKYPROT(ST_SPARSE_VADD); 822 } 823 else 824 { 825 mprSTICKYPROT(ST_SPARSE_VREJ); 769 826 } 770 827 pIter( p ); … … 777 834 #ifdef mprDEBUG_PROT 778 835 PrintLn(); 779 for( i= 0; i < idelem; i++ ) { 836 for( i= 0; i < idelem; i++ ) 837 { 780 838 Print(" \\Conv(Qi[%d]): #%d\n", i,Q[i]->num ); 781 for ( j=1; j <= Q[i]->num; j++ ) { 839 for ( j=1; j <= Q[i]->num; j++ ) 840 { 782 841 Print("%d: <",j);print_exp( (*Q[i])[j] , pVariables );Print(">\n"); 783 842 } … … 815 874 816 875 numverts = 0; 817 for( i=0; i<=n; i++) { 876 for( i=0; i<=n; i++) 877 { 818 878 numverts += Qi[i]->num; 819 879 } 820 cols = numverts + 2; 821 822 //if( dim < 1 || dim > n ) Werror("mayanPyramidAlg::vDistance: Known coords dim off range"); 823 824 pLP->LiPM[1][1] = 0.0; 825 pLP->LiPM[1][2] = 1.0; // maximize 880 cols = numverts + 2; 881 882 //if( dim < 1 || dim > n ) 883 // WerrorS("mayanPyramidAlg::vDistance: Known coords dim off range"); 884 885 pLP->LiPM[1][1] = 0.0; 886 pLP->LiPM[1][2] = 1.0; // maximize 826 887 for( j=3; j<=cols; j++) pLP->LiPM[1][j] = 0.0; 827 888 828 for( i=0; i <= n; i++ ) { 889 for( i=0; i <= n; i++ ) { 829 890 pLP->LiPM[i+2][1] = 1.0; 830 891 pLP->LiPM[i+2][2] = 0.0; 831 892 } 832 for( i=1; i<=dim; i++) { 893 for( i=1; i<=dim; i++) { 833 894 pLP->LiPM[n+2+i][1] = (mprfloat)(acoords[i-1]); 834 895 pLP->LiPM[n+2+i][2] = -shift[i]; … … 837 898 ii = -1; 838 899 col = 2; 839 for ( i= 0; i <= n; i++ ) { 900 for ( i= 0; i <= n; i++ ) { 840 901 ii++; 841 for( k= 1; k <= Qi[ii]->num; k++ ) { 902 for( k= 1; k <= Qi[ii]->num; k++ ) 903 { 842 904 col++; 843 for ( r= 0; r <= n; r++ ) { 844 if ( r == i ) pLP->LiPM[r+2][col] = -1.0; 845 else pLP->LiPM[r+2][col] = 0.0; 905 for ( r= 0; r <= n; r++ ) 906 { 907 if ( r == i ) pLP->LiPM[r+2][col] = -1.0; 908 else pLP->LiPM[r+2][col] = 0.0; 846 909 } 847 910 for( r= 1; r <= dim; r++ ) pLP->LiPM[r+n+2][col] = -(mprfloat)((*Qi[ii])[k]->point[r]); … … 849 912 } 850 913 851 if( col != cols) Werror("mayanPyramidAlg::vDistance:" 852 "setting up matrix for udist: col %d != cols %d",col,cols); 853 constr = n+dim+1; 914 if( col != cols) 915 Werror("mayanPyramidAlg::vDistance:" 916 "setting up matrix for udist: col %d != cols %d",col,cols); 917 constr = n+dim+1; 854 918 855 919 #ifdef mprDEBUG_ALL … … 861 925 862 926 #if 1 863 if ( constr + 1 > pLP->LiPM_rows ) Werror("mayanPyramidAlg::vDistance: #rows > #pLP->LiPM_rows!"); 864 if ( cols + 1 > pLP->LiPM_cols ) Werror("mayanPyramidAlg::vDistance: #cols > #pLP->LiPM_cols!"); 927 if ( constr + 1 > pLP->LiPM_rows ) 928 WerrorS("mayanPyramidAlg::vDistance: #rows > #pLP->LiPM_rows!"); 929 if ( cols + 1 > pLP->LiPM_cols ) 930 WerrorS("mayanPyramidAlg::vDistance: #cols > #pLP->LiPM_cols!"); 865 931 #endif 866 932 … … 873 939 print_bmat( pLP->LiPM, constr+1, cols+1-constr, cols, pLP->iposv); 874 940 #endif 875 941 876 942 if( icase != 0 ) { // check for errors 877 Werror("mayanPyramidAlg::vDistance: \n"); 878 if( icase == 1 ) Werror(" vDistance: Unbounded v-distance: probably 1st v-coor=0"); 879 if( icase == -1 ) Werror(" vDistance: Infeasible v-distance"); 943 WerrorS("mayanPyramidAlg::vDistance:"); 944 if( icase == 1 ) 945 WerrorS(" vDistance: Unbounded v-distance: probably 1st v-coor=0"); 946 if( icase == -1 ) 947 WerrorS(" vDistance: Infeasible v-distance"); 880 948 return -1.0; 881 949 } … … 895 963 896 964 // common part of the matrix 897 pLP->LiPM[1][1] = 0.0; 898 for( i=2; i<=n+2; i++) { 899 pLP->LiPM[i][1] = 1.0; // 1st col900 pLP->LiPM[i][2] = 0.0; // 2nd col965 pLP->LiPM[1][1] = 0.0; 966 for( i=2; i<=n+2; i++) { 967 pLP->LiPM[i][1] = 1.0; // 1st col 968 pLP->LiPM[i][2] = 0.0; // 2nd col 901 969 } 902 970 903 971 la_cons_row = 1; 904 972 cols = 2; 905 for( i=0; i<=n; i++) { 973 for( i=0; i<=n; i++) 974 { 906 975 la_cons_row++; 907 for( j=1; j<= Qi[i]->num; j++) { 976 for( j=1; j<= Qi[i]->num; j++) 977 { 908 978 cols++; 909 pLP->LiPM[1][cols] = 0.0; 979 pLP->LiPM[1][cols] = 0.0; // set 1st row 0 910 980 for( k=2; k<=n+2; k++) { // lambdas sum up to 1 911 912 981 if( k != la_cons_row) pLP->LiPM[k][cols] = 0.0; 982 else pLP->LiPM[k][cols] = -1.0; 913 983 } 914 984 for( k=1; k<=n; k++) pLP->LiPM[k+n+2][cols] = -(mprfloat)((*Qi[i])[j]->point[k]); … … 916 986 } // i 917 987 918 for( i= 0; i < dim; i++ ) { 988 for( i= 0; i < dim; i++ ) { // fixed coords 919 989 pLP->LiPM[i+n+3][1] = acoords[i]; 920 990 pLP->LiPM[i+n+3][2] = 0.0; … … 922 992 pLP->LiPM[dim+n+3][1] = 0.0; 923 993 924 925 pLP->LiPM[1][2] = -1.0; 994 995 pLP->LiPM[1][2] = -1.0; // minimize 926 996 pLP->LiPM[dim+n+3][2] = 1.0; 927 997 … … 934 1004 935 1005 #if 1 936 if ( cons + 1 > pLP->LiPM_rows ) Werror(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!"); 937 if ( cols + 1 > pLP->LiPM_cols ) Werror(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!"); 1006 if ( cons + 1 > pLP->LiPM_rows ) 1007 WerrorS(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!"); 1008 if ( cols + 1 > pLP->LiPM_cols ) 1009 WerrorS(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!"); 938 1010 #endif 939 1011 940 1012 // simplx finds MIN for obj.fnc, puts it in [1,1] 941 1013 simplx(pLP->LiPM, cons, cols-1, 0, 0, cons, &icase, pLP->izrov, pLP->iposv); 942 1014 943 1015 if ( icase != 0 ) { // check for errors 944 if( icase < 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: minR: infeasible"); 945 if( icase > 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: minR: unbounded"); 1016 if( icase < 0) 1017 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: minR: infeasible"); 1018 else if( icase > 0) 1019 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: minR: unbounded"); 946 1020 } 947 1021 … … 952 1026 953 1027 // common part of the matrix again 954 pLP->LiPM[1][1] = 0.0; 955 for( i=2; i<=n+2; i++) { 956 pLP->LiPM[i][1] = 1.0; 957 pLP->LiPM[i][2] = 0.0; 1028 pLP->LiPM[1][1] = 0.0; 1029 for( i=2; i<=n+2; i++) { 1030 pLP->LiPM[i][1] = 1.0; 1031 pLP->LiPM[i][2] = 0.0; 958 1032 } 959 1033 la_cons_row = 1; 960 1034 cols = 2; 961 for( i=0; i<=n; i++) { 1035 for( i=0; i<=n; i++) 1036 { 962 1037 la_cons_row++; 963 for( j=1; j<=Qi[i]->num; j++) { 1038 for( j=1; j<=Qi[i]->num; j++) 1039 { 964 1040 cols++; 965 pLP->LiPM[1][cols] = 0.0; 966 for( k=2; k<=n+2; k++) { 967 968 1041 pLP->LiPM[1][cols] = 0.0; 1042 for( k=2; k<=n+2; k++) { 1043 if( k != la_cons_row) pLP->LiPM[k][cols] = 0.0; 1044 else pLP->LiPM[k][cols] = -1.0; 969 1045 } 970 1046 for( k=1; k<=n; k++) pLP->LiPM[k+n+2][cols] = -(mprfloat)((*Qi[i])[j]->point[k]); … … 972 1048 } // i 973 1049 974 for( i= 0; i < dim; i++ ) { // fixed coords1050 for( i= 0; i < dim; i++ ) { // fixed coords 975 1051 pLP->LiPM[i+n+3][1] = acoords[i]; 976 1052 pLP->LiPM[i+n+3][2] = 0.0; … … 978 1054 pLP->LiPM[dim+n+3][1] = 0.0; 979 1055 980 pLP->LiPM[1][2] = 1.0; // maximize981 pLP->LiPM[dim+n+3][2] = 1.0; // var = sum of pnt coords1056 pLP->LiPM[1][2] = 1.0; // maximize 1057 pLP->LiPM[dim+n+3][2] = 1.0; // var = sum of pnt coords 982 1058 983 1059 #ifdef mprDEBUG_ALL … … 987 1063 988 1064 #if 1 989 if ( cons + 1 > pLP->LiPM_rows ) Werror(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!"); 990 if ( cols + 1 > pLP->LiPM_cols ) Werror(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!"); 1065 if ( cons + 1 > pLP->LiPM_rows ) 1066 WerrorS(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!"); 1067 if ( cols + 1 > pLP->LiPM_cols ) 1068 WerrorS(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!"); 991 1069 #endif 992 1070 … … 994 1072 simplx(pLP->LiPM, cons, cols-1, 0, 0, cons, &icase, pLP->izrov, pLP->iposv); 995 1073 996 if ( icase != 0 ) { 997 if( icase < 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: maxR: infeasible"); 998 if( icase > 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: maxR: unbounded"); 999 } 1000 1001 *maxR = (Coord_t)( pLP->LiPM[1][1] + SIMPLEX_EPS ); 1074 if ( icase != 0 ) 1075 { 1076 if( icase < 0) 1077 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: maxR: infeasible"); 1078 else if( icase > 0) 1079 WerrorS(" mn_mx_MinkowskiSum: LinearProgram: maxR: unbounded"); 1080 } 1081 1082 *maxR = (Coord_t)( pLP->LiPM[1][1] + SIMPLEX_EPS ); 1002 1083 1003 1084 #ifdef mprDEBUG_ALL … … 1007 1088 1008 1089 // mprSTICKYPROT: 1009 // ST_SPARSE_VREJ: rejected point 1010 // ST_SPARSE_VADD: added point to set 1090 // ST_SPARSE_VREJ: rejected point 1091 // ST_SPARSE_VADD: added point to set 1011 1092 bool mayanPyramidAlg::storeMinkowskiSumPoint() 1012 1093 { … … 1016 1097 dist= vDistance( &(acoords[0]), n ); 1017 1098 1018 // store only points with v-distance > minVdist 1019 if( dist <= MINVDIST + SIMPLEX_EPS ) { 1099 // store only points with v-distance > minVdist 1100 if( dist <= MINVDIST + SIMPLEX_EPS ) 1101 { 1020 1102 mprSTICKYPROT(ST_SPARSE_VREJ); 1021 1103 return false; … … 1024 1106 E->addPoint( &(acoords[0]) ); 1025 1107 mprSTICKYPROT(ST_SPARSE_VADD); 1026 1027 return true; 1108 1109 return true; 1028 1110 } 1029 1111 … … 1047 1129 1048 1130 // step 5 -> terminate 1049 if( dim == n-1 ) { 1050 int lastKilled = 0; 1131 if( dim == n-1 ) { 1132 int lastKilled = 0; 1051 1133 // insert points 1052 1134 acoords[dim] = minR; 1053 while( acoords[dim] <= maxR ) { 1135 while( acoords[dim] <= maxR ) 1136 { 1054 1137 if( !storeMinkowskiSumPoint() ) lastKilled++; 1055 1138 acoords[dim]++; … … 1060 1143 1061 1144 // step 4 -> recurse at step 3 1062 acoords[dim] = minR; 1063 while ( acoords[dim] <= maxR ) { 1145 acoords[dim] = minR; 1146 while ( acoords[dim] <= maxR ) 1147 { 1064 1148 if ( (acoords[dim] > minR) && (acoords[dim] <= maxR) ) { // acoords[dim] >= minR ?? 1065 1149 mprSTICKYPROT(ST_SPARSE_MREC1); 1066 1150 runMayanPyramid( dim + 1 ); // recurse with higer dimension 1067 } else { 1151 } else { 1068 1152 // get v-distance of pt 1069 1153 dist= vDistance( &(acoords[0]), dim + 1 );// dim+1 == known coordinates 1070 1154 1071 if( dist >= SIMPLEX_EPS ) { 1072 mprSTICKYPROT(ST_SPARSE_MREC2); 1073 runMayanPyramid( dim + 1 ); // recurse with higer dimension 1155 if( dist >= SIMPLEX_EPS ) 1156 { 1157 mprSTICKYPROT(ST_SPARSE_MREC2); 1158 runMayanPyramid( dim + 1 ); // recurse with higer dimension 1074 1159 } 1075 1160 } … … 1086 1171 int i,n= pVariables; 1087 1172 int loffset= 0; 1088 for ( i= 0; i <= n; i++ ) { 1089 if ( (loffset < indx) && (indx <= pQ[i]->num + loffset) ) { 1173 for ( i= 0; i <= n; i++ ) 1174 { 1175 if ( (loffset < indx) && (indx <= pQ[i]->num + loffset) ) 1176 { 1090 1177 *set= i; 1091 1178 *pnt= indx-loffset; … … 1113 1200 1114 1201 // fill in LP matrix 1115 for ( i= 0; i <= n; i++ ) { 1202 for ( i= 0; i <= n; i++ ) 1203 { 1116 1204 size= pQ[i]->num; 1117 for ( k= 1; k <= size; k++ ) { 1205 for ( k= 1; k <= size; k++ ) 1206 { 1118 1207 ncols++; 1119 1208 1120 1209 // objective funtion, minimize 1121 1210 LP.LiPM[1][ncols] = - ( (mprfloat) (*pQ[i])[k]->point[pQ[i]->dim] / SCALEDOWN ); 1122 1211 1123 1212 // lambdas sum up to 1 1124 for ( j = 0; j <= n; j++ ) 1125 1126 1127 1128 1213 for ( j = 0; j <= n; j++ ) 1214 if ( i==j ) 1215 LP.LiPM[j+2][ncols] = -1.0; 1216 else 1217 LP.LiPM[j+2][ncols] = 0.0; 1129 1218 1130 1219 // the points 1131 for ( j = 1; j <= n; j++ ) { 1132 LP.LiPM[j+n+2][ncols] = - ( (mprfloat) (*pQ[i])[k]->point[j] ); 1133 } 1134 } 1135 } 1136 1137 for ( j = 0; j <= n; j++ ) LP.LiPM[j+2][1] = 1.0; 1138 for ( j= 1; j <= n; j++ ) { 1220 for ( j = 1; j <= n; j++ ) 1221 { 1222 LP.LiPM[j+n+2][ncols] = - ( (mprfloat) (*pQ[i])[k]->point[j] ); 1223 } 1224 } 1225 } 1226 1227 for ( j = 0; j <= n; j++ ) LP.LiPM[j+2][1] = 1.0; 1228 for ( j= 1; j <= n; j++ ) 1229 { 1139 1230 LP.LiPM[j+n+2][1]= (mprfloat)(*E)[vert]->point[j] - shift[j]; 1140 1231 } … … 1146 1237 PrintLn(); 1147 1238 Print(" n= %d, NumCons=M= %d, ncols=N= %d\n",n,NumCons,ncols); 1148 print_mat(LP.LiPM, NumCons+1, ncols+1); 1149 #endif 1239 print_mat(LP.LiPM, NumCons+1, ncols+1); 1240 #endif 1150 1241 1151 1242 #if 1 1152 if ( NumCons + 1 > LP.LiPM_rows ) Werror("resMatrixSparse::RC: #rows > #LP.LiPM_rows!"); 1153 if ( ncols + 1 > LP.LiPM_cols ) Werror("resMatrixSparse::RC: #cols > #LP.LiPM_cols!"); 1243 if ( NumCons + 1 > LP.LiPM_rows ) 1244 WerrorS("resMatrixSparse::RC: #rows > #LP.LiPM_rows!"); 1245 if ( ncols + 1 > LP.LiPM_cols ) 1246 WerrorS("resMatrixSparse::RC: #cols > #LP.LiPM_cols!"); 1154 1247 #endif 1155 1248 … … 1157 1250 simplx(LP.LiPM, NumCons, ncols, 0, 0, NumCons, &icase, LP.izrov, LP.iposv); 1158 1251 1159 if (icase < 0) { 1252 if (icase < 0) 1253 { 1160 1254 // infeasibility: the point does not lie in a cell -> remove it 1161 1255 return -1; … … 1170 1264 //print_mat(LP.LiPM, NumCons+1, ncols); 1171 1265 #endif 1172 1266 1173 1267 #if 1 1174 1268 // sort LP results 1175 while (found) { 1269 while (found) 1270 { 1176 1271 found=false; 1177 for ( i= 1; i < NumCons; i++ ) { 1178 if ( LP.iposv[i] > LP.iposv[i+1] ) { 1179 1180 c= LP.iposv[i]; 1181 LP.iposv[i]=LP.iposv[i+1]; 1182 LP.iposv[i+1]=c; 1183 1184 cd=LP.LiPM[i+1][1]; 1185 LP.LiPM[i+1][1]=LP.LiPM[i+2][1]; 1186 LP.LiPM[i+2][1]=cd; 1187 1188 found= true; 1272 for ( i= 1; i < NumCons; i++ ) 1273 { 1274 if ( LP.iposv[i] > LP.iposv[i+1] ) 1275 { 1276 1277 c= LP.iposv[i]; 1278 LP.iposv[i]=LP.iposv[i+1]; 1279 LP.iposv[i+1]=c; 1280 1281 cd=LP.LiPM[i+1][1]; 1282 LP.LiPM[i+1][1]=LP.LiPM[i+2][1]; 1283 LP.LiPM[i+2][1]=cd; 1284 1285 found= true; 1189 1286 } 1190 1287 } … … 1203 1300 c=0; 1204 1301 optSum= (setID*)Alloc( (NumCons) * sizeof(struct setID) ); 1205 for ( i= 0; i < NumCons; i++ ) { 1302 for ( i= 0; i < NumCons; i++ ) 1303 { 1206 1304 //Print("% .15f\n",LP.LiPM[i+2][1]); 1207 if ( LP.LiPM[i+2][1] > 1e-12 ) { 1208 if ( !remapXiToPoint( LP.iposv[i+1], pQ, &(optSum[c].set), &(optSum[c].pnt) ) ) { 1209 Werror(" resMatrixSparse::RC: Found bad solution in LP: %d!",LP.iposv[i+1]); 1210 Werror(" resMatrixSparse::RC: remapXiToPoint faild!"); 1211 return -1; 1305 if ( LP.LiPM[i+2][1] > 1e-12 ) 1306 { 1307 if ( !remapXiToPoint( LP.iposv[i+1], pQ, &(optSum[c].set), &(optSum[c].pnt) ) ) 1308 { 1309 Werror(" resMatrixSparse::RC: Found bad solution in LP: %d!",LP.iposv[i+1]); 1310 WerrorS(" resMatrixSparse::RC: remapXiToPoint faild!"); 1311 return -1; 1212 1312 } 1213 1313 bucket[optSum[c].set]++; … … 1219 1319 // find last min in bucket[]: maximum i such that Fi is a point 1220 1320 c= 0; 1221 for ( i= 1; i < E->dim; i++ ) { 1222 if ( bucket[c] >= bucket[i] ) { 1321 for ( i= 1; i < E->dim; i++ ) 1322 { 1323 if ( bucket[c] >= bucket[i] ) 1324 { 1223 1325 c= i; 1224 1326 } 1225 1327 } 1226 1328 // find matching point set 1227 for ( i= onum - 1; i >= 0; i-- ) { 1228 if ( optSum[i].set == c ) 1329 for ( i= onum - 1; i >= 0; i-- ) 1330 { 1331 if ( optSum[i].set == c ) 1229 1332 break; 1230 1333 } … … 1233 1336 (*E)[vert]->rc.pnt= optSum[i].pnt; 1234 1337 (*E)[vert]->rcPnt= (*pQ[c])[optSum[i].pnt]; 1235 // count 1338 // count 1236 1339 if ( (*E)[vert]->rc.set == linPolyS ) numSet0++; 1237 1340 1238 1341 #ifdef mprDEBUG_PROT 1239 1342 Print("\n Point E[%d] was <",vert);print_exp((*E)[vert],E->dim-1);Print(">, bucket={"); 1240 for ( j= 0; j < E->dim; j++ ) { 1343 for ( j= 0; j < E->dim; j++ ) 1344 { 1241 1345 Print(" %d",bucket[j]); 1242 1346 } 1243 1347 Print(" }\n optimal Sum: Qi "); 1244 for ( j= 0; j < NumCons; j++ ) { 1348 for ( j= 0; j < NumCons; j++ ) 1349 { 1245 1350 Print(" [ %d, %d ]",optSum[j].set,optSum[j].pnt); 1246 1351 } … … 1253 1358 mprSTICKYPROT(ST_SPARSE_RC); 1254 1359 1255 return (int)(-LP.LiPM[1][1] * SCALEDOWN); 1360 return (int)(-LP.LiPM[1][1] * SCALEDOWN); 1256 1361 } 1257 1362 … … 1290 1395 for ( i= 1; i <= E->num; i++ ) { // for every row 1291 1396 E->getRowMP( i, epp_mon ); // compute (p-a[ij]), (i,j) = RC(p) 1292 pSetExpV( epp, epp_mon ); 1293 1294 // 1397 pSetExpV( epp, epp_mon ); 1398 1399 // 1295 1400 rowp= pMult( pCopy(epp), pCopy((gls->m)[(*E)[i]->rc.set]) ); // x^(p-a[ij]) * f(i) 1296 1401 pSetm( rowp ); … … 1299 1404 // get column for every monomial in rowp and store it 1300 1405 iterp= rowp; 1301 while ( iterp ) { 1406 while ( iterp ) 1407 { 1302 1408 epos= E->getExpPos( iterp ); 1303 if ( epos == 0 ) { 1304 // this can happen, if the shift vektor or the lift funktions 1305 // are not generically choosen. 1306 Werror("resMatrixSparse::createMatrix: Found exponent not in E, id %d, set [%d, %d]!", 1307 i,(*E)[i]->rc.set,(*E)[i]->rc.pnt); 1308 return i; 1409 if ( epos == 0 ) 1410 { 1411 // this can happen, if the shift vektor or the lift funktions 1412 // are not generically choosen. 1413 Werror("resMatrixSparse::createMatrix: Found exponent not in E, id %d, set [%d, %d]!", 1414 i,(*E)[i]->rc.set,(*E)[i]->rc.pnt); 1415 return i; 1309 1416 } 1310 1417 pSetExpV(iterp,eexp); 1311 1418 pSetComp(iterp, epos ); 1312 1419 if ( (*E)[i]->rc.set == linPolyS ) { // store coeff positions 1313 1314 1420 IMATELEM(*uRPos,rp,cp)= epos; 1421 cp++; 1315 1422 } 1316 1423 pIter( iterp ); … … 1329 1436 1330 1437 #ifdef mprDEBUG_ALL 1331 if ( E->num <= 40 ) { 1438 if ( E->num <= 40 ) 1439 { 1332 1440 matrix mout= idModule2Matrix( idCopy(rmat) ); 1333 1441 print_matrix(mout); 1334 1442 } 1335 for ( i= 1; i <= numSet0; i++ ) { 1443 for ( i= 1; i <= numSet0; i++ ) 1444 { 1336 1445 Print(" row %d contains coeffs of f_%d\n",IMATELEM(*uRPos,i,1),linPolyS); 1337 1446 } … … 1351 1460 srand((long)(((int)time(tp) % MAXSEED)+MAXSEED*18)); 1352 1461 1353 while ( i <= dim ) { 1462 while ( i <= dim ) 1463 { 1354 1464 shift[i]= (mprfloat) (RVMULT*rand()/(RAND_MAX+1.0)); 1355 1465 i++; 1356 for ( j= 1; j < i-1; j++ ) { 1357 if ( (shift[j] < shift[i-1] + SIMPLEX_EPS) && (shift[j] > shift[i-1] - SIMPLEX_EPS) ) { 1358 i--; 1359 break; 1466 for ( j= 1; j < i-1; j++ ) 1467 { 1468 if ( (shift[j] < shift[i-1] + SIMPLEX_EPS) && (shift[j] > shift[i-1] - SIMPLEX_EPS) ) 1469 { 1470 i--; 1471 break; 1360 1472 } 1361 1473 } … … 1373 1485 vs= new pointSet( dim ); 1374 1486 1375 for ( j= 1; j <= Q1->num; j++ ) { 1376 for ( k= 1; k <= Q2->num; k++ ) { 1377 for ( l= 1; l <= dim; l++ ) { 1378 vert.point[l]= (*Q1)[j]->point[l] + (*Q2)[k]->point[l]; 1487 for ( j= 1; j <= Q1->num; j++ ) 1488 { 1489 for ( k= 1; k <= Q2->num; k++ ) 1490 { 1491 for ( l= 1; l <= dim; l++ ) 1492 { 1493 vert.point[l]= (*Q1)[j]->point[l] + (*Q2)[k]->point[l]; 1379 1494 } 1380 1495 vs->mergeWithExp( &vert ); … … 1397 1512 for ( j= 1; j <= pQ[0]->num; j++ ) vs->addPoint( (*pQ[0])[j] ); 1398 1513 1399 for ( j= 1; j < numq; j++ ) { 1514 for ( j= 1; j < numq; j++ ) 1515 { 1400 1516 vs_old= vs; 1401 1517 vs= minkSumTwo( vs_old, pQ[j], dim ); … … 1419 1535 mprfloat shift[MAXVARS+2]; // shiftvector delta, index [1..dim] 1420 1536 1421 if ( pVariables > MAXVARS ) { 1422 Werror("resMatrixSparse::resMatrixSparse: To many variables!"); 1537 if ( pVariables > MAXVARS ) 1538 { 1539 WerrorS("resMatrixSparse::resMatrixSparse: To many variables!"); 1423 1540 return; 1424 1541 } … … 1447 1564 1448 1565 // need AllocAligned since we allocate mem for type double 1449 LP.LiPM = (mprfloat **)Alloc( LP.LiPM_rows * sizeof(mprfloat *) ); // LP matrix 1450 for( i= 0; i < LP.LiPM_rows; i++ ) { 1566 LP.LiPM = (mprfloat **)Alloc( LP.LiPM_rows * sizeof(mprfloat *) ); // LP matrix 1567 for( i= 0; i < LP.LiPM_rows; i++ ) 1568 { 1451 1569 // Mem must be allocated aligned, also for type double! 1452 1570 LP.LiPM[i] = (mprfloat *)AllocAligned0( LP.LiPM_cols * sizeof(mprfloat) ); … … 1475 1593 1476 1594 #ifdef mprMINKSUM 1477 E= minkSumAll( Qi, n+1, n); 1595 E= minkSumAll( Qi, n+1, n); 1478 1596 #else 1479 1597 // get inner points … … 1487 1605 #endif 1488 1606 Print("\n E = (Q_0 + ... + Q_n) \\cap \\N :\n"); 1489 for ( pnt= 1; pnt <= E->num; pnt++ ) { 1607 for ( pnt= 1; pnt <= E->num; pnt++ ) 1608 { 1490 1609 Print("%d: <",pnt);print_exp( (*E)[pnt], E->dim );Print(">\n"); 1491 1610 } … … 1495 1614 #ifdef mprTEST 1496 1615 int lift[5][5]; 1497 lift[0][1]=3; lift[0][2]=4; lift[0][3]=8; lift[0][4]=2; 1498 lift[1][1]=6; lift[1][2]=1; lift[1][3]=7; lift[1][4]=4; 1616 lift[0][1]=3; lift[0][2]=4; lift[0][3]=8; lift[0][4]=2; 1617 lift[1][1]=6; lift[1][2]=1; lift[1][3]=7; lift[1][4]=4; 1499 1618 lift[2][1]=2; lift[2][2]=5; lift[2][3]=9; lift[2][4]=6; 1500 1619 lift[3][1]=2; lift[3][2]=1; lift[3][3]=9; lift[3][4]=5; … … 1510 1629 1511 1630 // run Row Content Function for every point in E 1512 for ( pnt= 1; pnt <= E->num; pnt++ ) { 1631 for ( pnt= 1; pnt <= E->num; pnt++ ) 1632 { 1513 1633 RC( Qi, E, pnt, shift ); 1514 1634 } … … 1516 1636 // remove points not in cells 1517 1637 k= E->num; 1518 for ( pnt= k; pnt > 0; pnt-- ) { 1519 if ( (*E)[pnt]->rcPnt == NULL ) { 1638 for ( pnt= k; pnt > 0; pnt-- ) 1639 { 1640 if ( (*E)[pnt]->rcPnt == NULL ) 1641 { 1520 1642 E->removePoint(pnt); 1521 1643 mprSTICKYPROT(ST_SPARSE_RCRJ); … … 1526 1648 #ifdef mprDEBUG_PROT 1527 1649 Print(" points which lie in a cell:\n"); 1528 for ( pnt= 1; pnt <= E->num; pnt++ ) { 1650 for ( pnt= 1; pnt <= E->num; pnt++ ) 1651 { 1529 1652 Print("%d: <",pnt);print_exp( (*E)[pnt], E->dim );Print(">\n"); 1530 1653 } … … 1539 1662 #ifdef mprDEBUG_PROT 1540 1663 Print(" points with a[ij] (%d):\n",E->num); 1541 for ( pnt= 1; pnt <= E->num; pnt++ ) { 1664 for ( pnt= 1; pnt <= E->num; pnt++ ) 1665 { 1542 1666 Print("Punkt p \\in E[%d]: <",pnt);print_exp( (*E)[pnt], E->dim ); 1543 1667 Print(">, RC(p) = (i:%d, j:%d), a[i,j] = <",(*E)[pnt]->rc.set,(*E)[pnt]->rc.pnt); … … 1548 1672 1549 1673 // now create matrix 1550 if ( createMatrix( E ) != E->num ) { 1674 if ( createMatrix( E ) != E->num ) 1675 { 1551 1676 // this can happen if the shiftvector shift is to large or not generic 1552 1677 istate= resMatrixBase::fatalError; 1553 Werror ("resMatrixSparse::resMatrixSparse: Error in resMatrixSparse::createMatrix!");1678 WerrorS("resMatrixSparse::resMatrixSparse: Error in resMatrixSparse::createMatrix!"); 1554 1679 goto theEnd; 1555 1680 //return; … … 1558 1683 theEnd: 1559 1684 // clean up 1560 for ( i= 0; i < idelem; i++ ) { 1685 for ( i= 0; i < idelem; i++ ) 1686 { 1561 1687 delete Qi[i]; 1562 1688 } … … 1565 1691 delete E; 1566 1692 1567 for( i= 0; i < LP.LiPM_rows; i++ ) { 1693 for( i= 0; i < LP.LiPM_rows; i++ ) 1694 { 1568 1695 FreeAligned( (ADDRESS) LP.LiPM[i], LP.LiPM_cols * sizeof(mprfloat) ); 1569 1696 // Free( (ADDRESS) LP.LiPM[i], LP.LiPM_cols * sizeof(mprfloat) ); 1570 1697 } 1571 Free( (ADDRESS) LP.LiPM, LP.LiPM_rows * sizeof(mprfloat *) ); 1698 Free( (ADDRESS) LP.LiPM, LP.LiPM_rows * sizeof(mprfloat *) ); 1572 1699 1573 1700 Free( (ADDRESS) LP.iposv, (idelem * MAXPOINTS) * sizeof(int) ); … … 1592 1719 1593 1720 // now fill in coeffs of f0 1594 for ( i= 1; i <= numSet0; i++ ) { 1721 for ( i= 1; i <= numSet0; i++ ) 1722 { 1595 1723 1596 1724 pgls= (gls->m)[0]; // f0 … … 1605 1733 // u_1,..,u_k 1606 1734 cp=2; 1607 while ( pNext(pgls) ) { 1735 while ( pNext(pgls) ) 1736 { 1608 1737 phelp= pOne(); 1609 1738 pSetCoeff( phelp, nCopy(pGetCoeff(pgls)) ); 1610 1739 pSetComp( phelp, IMATELEM(*uRPos,i,cp) ); 1611 if ( piter ) { 1612 pNext(piter)= phelp; 1613 piter= phelp; 1614 } else { 1615 pp= phelp; 1616 piter= phelp; 1740 if ( piter ) 1741 { 1742 pNext(piter)= phelp; 1743 piter= phelp; 1744 } 1745 else 1746 { 1747 pp= phelp; 1748 piter= phelp; 1617 1749 } 1618 1750 cp++; … … 1643 1775 mprPROTnl("smCallDet"); 1644 1776 1645 for ( i= 1; i <= numSet0; i++ ) { 1777 for ( i= 1; i <= numSet0; i++ ) 1778 { 1646 1779 pp= (rmat->m)[IMATELEM(*uRPos,i,1)]; 1647 1780 pDelete( &pp ); … … 1650 1783 piter= NULL; 1651 1784 // u_1,..,u_n 1652 for ( cp= 2; cp <= idelem; cp++ ) { 1653 if ( !nIsZero(evpoint[cp-1]) ) { 1654 phelp= pOne(); 1655 pSetCoeff( phelp, nCopy(evpoint[cp-1]) ); 1656 pSetComp( phelp, IMATELEM(*uRPos,i,cp) ); 1657 if ( piter ) { 1658 pNext(piter)= phelp; 1659 piter= phelp; 1660 } else { 1661 pp= phelp; 1662 piter= phelp; 1663 } 1785 for ( cp= 2; cp <= idelem; cp++ ) 1786 { 1787 if ( !nIsZero(evpoint[cp-1]) ) 1788 { 1789 phelp= pOne(); 1790 pSetCoeff( phelp, nCopy(evpoint[cp-1]) ); 1791 pSetComp( phelp, IMATELEM(*uRPos,i,cp) ); 1792 if ( piter ) 1793 { 1794 pNext(piter)= phelp; 1795 piter= phelp; 1796 } 1797 else 1798 { 1799 pp= phelp; 1800 piter= phelp; 1801 } 1664 1802 } 1665 1803 } … … 1695 1833 mprPROTnl("smCallDet"); 1696 1834 1697 for ( i= 1; i <= numSet0; i++ ) { 1835 for ( i= 1; i <= numSet0; i++ ) 1836 { 1698 1837 pp= (rmat->m)[IMATELEM(*uRPos,i,1)]; 1699 1838 pDelete( &pp ); … … 1702 1841 piter= NULL; 1703 1842 for ( cp= 2; cp <= idelem; cp++ ) { // u1 .. un 1704 if ( !nIsZero(evpoint[cp-1]) ) { 1705 phelp= pOne(); 1706 pSetCoeff( phelp, nCopy(evpoint[cp-1]) ); 1707 pSetComp( phelp, IMATELEM(*uRPos,i,cp) ); 1708 if ( piter ) { 1709 pNext(piter)= phelp; 1710 piter= phelp; 1711 } else { 1712 pp= phelp; 1713 piter= phelp; 1714 } 1843 if ( !nIsZero(evpoint[cp-1]) ) 1844 { 1845 phelp= pOne(); 1846 pSetCoeff( phelp, nCopy(evpoint[cp-1]) ); 1847 pSetComp( phelp, IMATELEM(*uRPos,i,cp) ); 1848 if ( piter ) 1849 { 1850 pNext(piter)= phelp; 1851 piter= phelp; 1852 } 1853 else 1854 { 1855 pp= phelp; 1856 piter= phelp; 1857 } 1715 1858 } 1716 1859 } … … 1748 1891 * _gls: system of multivariate polynoms 1749 1892 * special: -1 -> resMatrixDense is a symbolic matrix 1750 * 0,1, ... -> resMatrixDense ist eine u-Resultante, wobei special das 1893 * 0,1, ... -> resMatrixDense ist eine u-Resultante, wobei special das 1751 1894 * lineare u-Polynom angibt 1752 1895 */ … … 1774 1917 */ 1775 1918 const number getSubDet(); 1776 1919 1777 1920 private: 1778 1921 /** deactivated copy constructor */ … … 1789 1932 void generateMonomData( int deg, intvec* polyDegs , intvec* iVO ); 1790 1933 1791 /** Recursively generate all homogeneous monoms of 1934 /** Recursively generate all homogeneous monoms of 1792 1935 * pVariables variables of degree deg. 1793 1936 */ … … 1812 1955 //<- 1813 1956 1814 //-> struct resVector 1957 //-> struct resVector 1815 1958 /* Holds a row vector of the dense resultant matrix */ 1816 1959 struct resVector 1817 1960 { 1818 1961 public: 1819 void init() { 1962 void init() 1963 { 1820 1964 isReduced = FALSE; 1821 elementOfS = SFREE; 1965 elementOfS = SFREE; 1822 1966 mon = NULL; 1823 1967 } 1824 void init( const poly m ) { 1968 void init( const poly m ) 1969 { 1825 1970 isReduced = FALSE; 1826 elementOfS = SFREE; 1827 mon = m; 1971 elementOfS = SFREE; 1972 mon = m; 1828 1973 } 1829 1974 1830 1975 /** index von 0 ... numVectors-1 */ 1831 poly getElem( const int i ); 1976 poly getElem( const int i ); 1832 1977 1833 1978 /** index von 0 ... numVectors-1 */ … … 1842 1987 int elementOfS; 1843 1988 1844 /** holds the index of u0, u1, ..., un, if (elementOfS == linPolyS) 1845 * the size is given by pVariables 1989 /** holds the index of u0, u1, ..., un, if (elementOfS == linPolyS) 1990 * the size is given by pVariables 1846 1991 */ 1847 int *numColParNr; 1992 int *numColParNr; 1848 1993 1849 1994 /** holds the column vector if (elementOfS != linPolyS) */ 1850 number *numColVector; 1995 number *numColVector; 1851 1996 1852 1997 /** size of numColVector */ 1853 int numColVectorSize; 1998 int numColVectorSize; 1854 1999 1855 2000 number *numColVecCopy; … … 1859 2004 //-> resVector::* 1860 2005 poly resVector::getElem( const int i ) // inline ??? 1861 { 2006 { 1862 2007 assume( 0 < i || i > numColVectorSize ); 1863 2008 poly out= pOne(); 1864 2009 pSetCoeff( out, numColVector[i] ); 1865 2010 pTest( out ); 1866 return( out ); 2011 return( out ); 1867 2012 } 1868 2013 … … 1870 2015 { 1871 2016 assume( i >= 0 && i < numColVectorSize ); 1872 return( numColVector[i] ); 2017 return( numColVector[i] ); 1873 2018 } 1874 2019 //<- … … 1877 2022 resMatrixDense::resMatrixDense( const ideal _gls, const int special ) 1878 2023 : resMatrixBase() 1879 { 2024 { 1880 2025 int i; 1881 2026 1882 2027 sourceRing=currRing; 1883 2028 gls= idCopy( _gls ); … … 1886 2031 1887 2032 // init all 1888 generateBaseData(); 2033 generateBaseData(); 1889 2034 1890 2035 totDeg= 1; 1891 for ( i= 0; i < IDELEMS(gls); i++ ) { 2036 for ( i= 0; i < IDELEMS(gls); i++ ) 2037 { 1892 2038 totDeg*=pTotaldegree( (gls->m)[i] ); 1893 2039 } … … 1897 2043 istate= resMatrixBase::ready; 1898 2044 } 1899 2045 1900 2046 resMatrixDense::~resMatrixDense() 1901 2047 { 1902 2048 int i,j; 1903 for (i=0; i < numVectors; i++) 1904 { 1905 pDelete( &resVectorList[i].mon ); 1906 pDelete( &resVectorList[i].dividedBy ); 1907 for ( j=0; j < resVectorList[i].numColVectorSize; j++ ) { 1908 nDelete( resVectorList[i].numColVector+j ); 1909 } 1910 Free( (ADDRESS)resVectorList[i].numColVector, numVectors*sizeof( number ) ); 1911 Free( (ADDRESS)resVectorList[i].numColParNr, (pVariables+1) * sizeof(int) ); 1912 } 1913 2049 for (i=0; i < numVectors; i++) 2050 { 2051 pDelete( &resVectorList[i].mon ); 2052 pDelete( &resVectorList[i].dividedBy ); 2053 for ( j=0; j < resVectorList[i].numColVectorSize; j++ ) 2054 { 2055 nDelete( resVectorList[i].numColVector+j ); 2056 } 2057 Free( (ADDRESS)resVectorList[i].numColVector, numVectors*sizeof( number ) ); 2058 Free( (ADDRESS)resVectorList[i].numColParNr, (pVariables+1) * sizeof(int) ); 2059 } 2060 1914 2061 Free( (ADDRESS)resVectorList, veclistmax*sizeof( resVector ) ); 1915 2062 1916 // free matrix m 1917 if ( m != NULL ) { 2063 // free matrix m 2064 if ( m != NULL ) 2065 { 1918 2066 for ( i= 1; i <= numVectors; i++ ) 1919 2067 for ( j= 1; j <= numVectors; j++ ) 1920 2068 pDelete( &MATELEM(m , i, j) ); 1921 2069 Free( (ADDRESS)m->m, numVectors * numVectors * sizeof(poly) ); 1922 2070 Free( (ADDRESS)m, sizeof(ip_smatrix) ); … … 1931 2079 int k,i,j; 1932 2080 resVector *vecp; 1933 2081 1934 2082 m= mpNew( numVectors, numVectors ); 1935 1936 for ( i= 1; i <= MATROWS( m ); i++ ) 1937 for ( j= 1; j <= MATCOLS( m ); j++ ) { 2083 2084 for ( i= 1; i <= MATROWS( m ); i++ ) 2085 for ( j= 1; j <= MATCOLS( m ); j++ ) 2086 { 1938 2087 MATELEM(m,i,j)= pInit(); 1939 2088 pSetCoeff0( MATELEM(m,i,j), nInit(0) ); 1940 2089 } 1941 1942 1943 for ( k= 0; k <= numVectors - 1; k++ ) { 1944 if ( linPolyS == getMVector(k)->elementOfS ) { 2090 2091 2092 for ( k= 0; k <= numVectors - 1; k++ ) 2093 { 2094 if ( linPolyS == getMVector(k)->elementOfS ) 2095 { 1945 2096 mprSTICKYPROT(ST_DENSE_FR); 1946 for ( i= 0; i < pVariables; i++ ) { 1947 MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i])= pInit(); 1948 } 1949 } else { 2097 for ( i= 0; i < pVariables; i++ ) 2098 { 2099 MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i])= pInit(); 2100 } 2101 } 2102 else 2103 { 1950 2104 mprSTICKYPROT(ST_DENSE_NR); 1951 2105 vecp= getMVector(k); 1952 for ( i= 0; i < numVectors; i++) 1953 if ( !nIsZero( vecp->getElemNum(i) ) ) { 1954 MATELEM(m,numVectors - k,i + 1)= pInit(); 1955 pSetCoeff( MATELEM(m,numVectors - k,i + 1), nCopy(vecp->getElemNum(i)) ); 1956 } 2106 for ( i= 0; i < numVectors; i++) 2107 if ( !nIsZero( vecp->getElemNum(i) ) ) 2108 { 2109 MATELEM(m,numVectors - k,i + 1)= pInit(); 2110 pSetCoeff( MATELEM(m,numVectors - k,i + 1), nCopy(vecp->getElemNum(i)) ); 2111 } 1957 2112 } 1958 2113 } // for 1959 2114 mprSTICKYPROT("\n"); 1960 2115 1961 2116 #ifdef mprDEBUG_ALL 1962 for ( k= numVectors - 1; k >= 0; k-- ) 1963 if ( linPolyS == getMVector(k)->elementOfS ) { 1964 for ( i=0; i < pVariables; i++ ) { 1965 Print(" %d ",(getMVector(k)->numColParNr)[i]); 2117 for ( k= numVectors - 1; k >= 0; k-- ) 2118 if ( linPolyS == getMVector(k)->elementOfS ) 2119 { 2120 for ( i=0; i < pVariables; i++ ) 2121 { 2122 Print(" %d ",(getMVector(k)->numColParNr)[i]); 1966 2123 } 1967 2124 PrintLn(); 1968 2125 } 1969 for (i=1; i <= numVectors; i++) { 1970 for (j=1; j <= numVectors; j++ ) { 2126 for (i=1; i <= numVectors; i++) 2127 { 2128 for (j=1; j <= numVectors; j++ ) 2129 { 1971 2130 pWrite0(MATELEM(m,i,j));Print(" "); 1972 2131 } … … 1984 2143 poly mon = pCopy( m ); 1985 2144 pSetm( mon ); 1986 1987 if ( numVectors == veclistmax ) { 1988 resVectorList= (resVector * )ReAlloc( resVectorList, 1989 (veclistmax) * sizeof( resVector ), 1990 (veclistmax + veclistblock) * sizeof( resVector ) ); 2145 2146 if ( numVectors == veclistmax ) 2147 { 2148 resVectorList= (resVector * )ReAlloc( resVectorList, 2149 (veclistmax) * sizeof( resVector ), 2150 (veclistmax + veclistblock) * sizeof( resVector ) ); 1991 2151 int k; 1992 for ( k= veclistmax; k < (veclistmax + veclistblock); k++ ) 1993 2152 for ( k= veclistmax; k < (veclistmax + veclistblock); k++ ) 2153 resVectorList[k].init(); 1994 2154 veclistmax+= veclistblock; 1995 2155 mprSTICKYPROT(ST_DENSE_MEM); … … 1998 2158 resVectorList[numVectors].init( mon ); 1999 2159 numVectors++; 2000 mprSTICKYPROT(ST_DENSE_NMON); 2160 mprSTICKYPROT(ST_DENSE_NMON); 2001 2161 return; 2002 } else { 2162 } 2163 else 2164 { 2003 2165 if ( var == pVariables+1 ) return; 2004 2166 poly newm = pCopy( m ); 2005 while ( deg >= 0 ) { 2167 while ( deg >= 0 ) 2168 { 2006 2169 generateMonoms( newm, var+1, deg ); 2007 2170 pIncrExp( newm, var ); … … 2011 2174 pDelete( & newm ); 2012 2175 } 2013 2176 2014 2177 return; 2015 2178 } … … 2023 2186 veclistmax= veclistblock; 2024 2187 resVectorList= (resVector *)Alloc( veclistmax*sizeof( resVector ) ); 2025 2188 2026 2189 // Init resVector()s 2027 2190 for ( j= veclistmax - 1; j >= 0; j-- ) resVectorList[j].init(); 2028 2191 numVectors= 0; 2029 2192 2030 // Generate all monoms of degree deg 2193 // Generate all monoms of degree deg 2031 2194 poly start= pOne(); 2032 2195 generateMonoms( start, 1, deg ); … … 2034 2197 2035 2198 mprSTICKYPROT("\n"); 2036 2199 2037 2200 // Check for reduced monoms 2038 2201 // First generate polyDegs.rows() monoms 2039 2202 // x(k)^(polyDegs[k]), 0 <= k < polyDegs.rows() 2040 2203 ideal pDegDiv= idInit( polyDegs->rows(), 1 ); 2041 for ( k= 0; k < polyDegs->rows(); k++ ) { 2204 for ( k= 0; k < polyDegs->rows(); k++ ) 2205 { 2042 2206 poly p= pOne(); 2043 2207 pSetExp( p, k + 1, (*polyDegs)[k] ); … … 2050 2214 // exactly one x(k)^(polyDegs[k]) that divides the monom. 2051 2215 int divCount; 2052 for ( j= numVectors - 1; j >= 0; j-- ) { 2216 for ( j= numVectors - 1; j >= 0; j-- ) 2217 { 2053 2218 divCount= 0; 2054 for ( k= 0; k < IDELEMS(pDegDiv); k++ ) 2055 if ( pDivisibleBy2( (pDegDiv->m)[k], resVectorList[j].mon ) ) 2056 2219 for ( k= 0; k < IDELEMS(pDegDiv); k++ ) 2220 if ( pDivisibleBy2( (pDegDiv->m)[k], resVectorList[j].mon ) ) 2221 divCount++; 2057 2222 resVectorList[j].isReduced= (divCount == 1); 2058 2223 } 2059 2224 2060 2225 // create the sets S(k)s 2061 // a monom x(i)^deg, deg given, is element of the set S(i) 2226 // a monom x(i)^deg, deg given, is element of the set S(i) 2062 2227 // if all x(0)^(polyDegs[0]) ... x(i-1)^(polyDegs[i-1]) DONT divide 2063 2228 // x(i)^deg and only x(i)^(polyDegs[i]) divides x(i)^deg 2064 2229 bool doInsert; 2065 for ( k= 0; k < iVO->rows(); k++) { 2230 for ( k= 0; k < iVO->rows(); k++) 2231 { 2066 2232 //mprPROTInl(" ------------ var:",(*iVO)[k]); 2067 for ( j= numVectors - 1; j >= 0; j-- ) { 2233 for ( j= numVectors - 1; j >= 0; j-- ) 2234 { 2068 2235 //mprPROTPnl("testing monom",resVectorList[j].mon); 2069 if ( resVectorList[j].elementOfS == SFREE ) { 2070 //mprPROTnl("\tfree"); 2071 if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[k] ], resVectorList[j].mon ) ) { 2072 //mprPROTPnl("\tdivisible by ",(pDegDiv->m)[ (*iVO)[k] ]); 2073 doInsert=TRUE; 2074 for ( i= 0; i < k; i++ ) { 2075 //mprPROTPnl("\tchecking db ",(pDegDiv->m)[ (*iVO)[i] ]); 2076 if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[i] ], resVectorList[j].mon ) ) { 2077 //mprPROTPnl("\t and divisible by",(pDegDiv->m)[ (*iVO)[i] ]); 2078 doInsert=FALSE; 2079 break; 2080 } 2081 } 2082 if ( doInsert ) { 2083 //mprPROTInl("\t------------------> S ",(*iVO)[k]); 2084 resVectorList[j].elementOfS= (*iVO)[k]; 2085 resVectorList[j].dividedBy= pCopy( (pDegDiv->m)[ (*iVO)[i] ] ); 2086 pSetm( resVectorList[j].dividedBy ); 2087 } 2088 } 2236 if ( resVectorList[j].elementOfS == SFREE ) 2237 { 2238 //mprPROTnl("\tfree"); 2239 if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[k] ], resVectorList[j].mon ) ) 2240 { 2241 //mprPROTPnl("\tdivisible by ",(pDegDiv->m)[ (*iVO)[k] ]); 2242 doInsert=TRUE; 2243 for ( i= 0; i < k; i++ ) 2244 { 2245 //mprPROTPnl("\tchecking db ",(pDegDiv->m)[ (*iVO)[i] ]); 2246 if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[i] ], resVectorList[j].mon ) ) 2247 { 2248 //mprPROTPnl("\t and divisible by",(pDegDiv->m)[ (*iVO)[i] ]); 2249 doInsert=FALSE; 2250 break; 2251 } 2252 } 2253 if ( doInsert ) 2254 { 2255 //mprPROTInl("\t------------------> S ",(*iVO)[k]); 2256 resVectorList[j].elementOfS= (*iVO)[k]; 2257 resVectorList[j].dividedBy= pCopy( (pDegDiv->m)[ (*iVO)[i] ] ); 2258 pSetm( resVectorList[j].dividedBy ); 2259 } 2260 } 2089 2261 } 2090 2262 } … … 2095 2267 subSize= 0; 2096 2268 int sub; 2097 for ( i= 0; i < polyDegs->rows(); i++ ) { 2269 for ( i= 0; i < polyDegs->rows(); i++ ) 2270 { 2098 2271 sub= 1; 2099 for ( k= 0; k < polyDegs->rows(); k++ ) 2272 for ( k= 0; k < polyDegs->rows(); k++ ) 2100 2273 if ( i != k ) sub*= (*polyDegs)[k]; 2101 2274 subSize+= sub; … … 2109 2282 // Print a list of monoms and their properties 2110 2283 Print("// \n"); 2111 for ( j= numVectors - 1; j >= 0; j-- ) { 2284 for ( j= numVectors - 1; j >= 0; j-- ) 2285 { 2112 2286 Print("// %s, S(%d), db ", 2113 2114 2115 pWrite0(resVectorList[j].dividedBy); 2287 resVectorList[j].isReduced?"reduced":"nonreduced", 2288 resVectorList[j].elementOfS); 2289 pWrite0(resVectorList[j].dividedBy); 2116 2290 Print(" monom "); 2117 2291 pWrite(resVectorList[j].mon); … … 2136 2310 // make sure that the homogenization variable goes last! 2137 2311 intvec iVO( pVariables ); 2138 if ( linPolyS != SNONE ) { 2312 if ( linPolyS != SNONE ) 2313 { 2139 2314 iVO[pVariables - 1]= linPolyS; 2140 2315 int p=0; 2141 for ( k= pVariables - 1; k >= 0; k-- ) { 2142 if ( k != linPolyS ) { 2143 iVO[p]= k; 2144 p++; 2145 } 2146 } 2147 } else { 2316 for ( k= pVariables - 1; k >= 0; k-- ) 2317 { 2318 if ( k != linPolyS ) 2319 { 2320 iVO[p]= k; 2321 p++; 2322 } 2323 } 2324 } 2325 else 2326 { 2148 2327 linPolyS= 0; 2149 for ( k= 0; k < pVariables; k++ ) 2328 for ( k= 0; k < pVariables; k++ ) 2150 2329 iVO[k]= pVariables - k - 1; 2151 2330 } … … 2161 2340 2162 2341 // generate "matrix" 2163 for ( k= numVectors - 1; k >= 0; k-- ) { 2164 if ( resVectorList[k].elementOfS != linPolyS ) { 2342 for ( k= numVectors - 1; k >= 0; k-- ) 2343 { 2344 if ( resVectorList[k].elementOfS != linPolyS ) 2345 { 2165 2346 // column k is a normal column with numerical or symbolic entries 2166 2347 // init stuff … … 2177 2358 2178 2359 // fill in "matrix" 2179 while ( pi ) { 2180 matEntry= nCopy(pGetCoeff(pi)); 2181 pmatchPos= pHead0( pi ); 2182 pSetCoeff( pmatchPos, nInit(1) ); 2183 pSetm( pmatchPos ); 2184 2185 for ( i= 0; i < numVectors; i++) 2186 if ( pEqual( pmatchPos, resVectorList[i].mon ) ) 2187 break; 2188 2189 resVectorList[k].numColVector[numVectors - i - 1] = nCopy(matEntry); 2190 2191 pDelete( &pmatchPos ); 2192 nDelete( &matEntry ); 2193 2194 pIter( pi ); 2360 while ( pi ) 2361 { 2362 matEntry= nCopy(pGetCoeff(pi)); 2363 pmatchPos= pHead0( pi ); 2364 pSetCoeff( pmatchPos, nInit(1) ); 2365 pSetm( pmatchPos ); 2366 2367 for ( i= 0; i < numVectors; i++) 2368 if ( pEqual( pmatchPos, resVectorList[i].mon ) ) 2369 break; 2370 2371 resVectorList[k].numColVector[numVectors - i - 1] = nCopy(matEntry); 2372 2373 pDelete( &pmatchPos ); 2374 nDelete( &matEntry ); 2375 2376 pIter( pi ); 2195 2377 } 2196 2378 pDelete( &pi ); 2197 } else { 2379 } 2380 else 2381 { 2198 2382 // column is a special column, i.e. is generated by S0 and F0 2199 2383 // safe only the positions of the ui's in the column … … 2209 2393 j=0; 2210 2394 while ( pi ) { // fill in "matrix" 2211 2212 2213 2214 for ( i= 0; i < numVectors; i++) 2215 2216 2217 2218 2219 2220 2221 2395 pmp= pMult( pHead( pi ), pCopy( factor ) ); 2396 pSetm( pmp );pTest( pi ); 2397 2398 for ( i= 0; i < numVectors; i++) 2399 if ( pEqual( pmp, resVectorList[i].mon ) ) 2400 break; 2401 2402 resVectorList[k].numColParNr[j]= i; 2403 pDelete( &pmp ); 2404 pIter( pi ); 2405 j++; 2222 2406 } 2223 2407 pDelete( &pi ); … … 2233 2417 } 2234 2418 2235 resVector *resMatrixDense::getMVector(int i) 2236 { 2419 resVector *resMatrixDense::getMVector(int i) 2420 { 2237 2421 assume( i >= 0 && i < numVectors ); 2238 return &resVectorList[i]; 2422 return &resVectorList[i]; 2239 2423 } 2240 2424 2241 2425 const ideal resMatrixDense::getMatrix() 2242 { 2426 { 2243 2427 int k,i,j; 2244 2428 2245 2429 // copy matrix 2246 2430 matrix resmat= mpNew(numVectors,numVectors); 2247 for (i=1; i <= numVectors; i++) { 2248 for (j=1; j <= numVectors; j++ ) { 2249 if ( MATELEM(m,i,j) && pGetCoeff(MATELEM(m,i,j)) ) { 2250 MATELEM(resmat,i,j)= pCopy( MATELEM(m,i,j) ); 2251 } 2252 } 2253 } 2254 for (i=0; i < numVectors; i++) { 2255 if ( resVectorList[i].elementOfS == linPolyS ) { 2256 for (j=1; j <= pVariables; j++ ) { 2257 if ( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) ) 2258 pDelete( &MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) ); 2259 MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1])= pOne(); 2260 // FIX ME 2261 if ( true ) { 2262 pSetCoeff( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), nPar(j) ); 2263 } else { 2264 pSetExp( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), j, 1 ); 2265 } 2431 for (i=1; i <= numVectors; i++) 2432 { 2433 for (j=1; j <= numVectors; j++ ) 2434 { 2435 if ( MATELEM(m,i,j) && pGetCoeff(MATELEM(m,i,j)) ) 2436 { 2437 MATELEM(resmat,i,j)= pCopy( MATELEM(m,i,j) ); 2438 } 2439 } 2440 } 2441 for (i=0; i < numVectors; i++) 2442 { 2443 if ( resVectorList[i].elementOfS == linPolyS ) 2444 { 2445 for (j=1; j <= pVariables; j++ ) 2446 { 2447 if ( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) ) 2448 pDelete( &MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) ); 2449 MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1])= pOne(); 2450 // FIX ME 2451 if ( true ) 2452 { 2453 pSetCoeff( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), nPar(j) ); 2454 } 2455 else 2456 { 2457 pSetExp( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), j, 1 ); 2458 } 2266 2459 } 2267 2460 } … … 2270 2463 ideal resmod= idMatrix2Module(resmat); 2271 2464 2272 if ( resmat != NULL ) { 2465 if ( resmat != NULL ) 2466 { 2273 2467 for ( i= 1; i <= numVectors; i++ ) 2274 2468 for ( j= 1; j <= numVectors; j++ ) 2275 2469 pDelete( &MATELEM(resmat , i, j) ); 2276 2470 Free( (ADDRESS)resmat->m, numVectors * numVectors * sizeof(poly) ); 2277 2471 Free( (ADDRESS)resmat, sizeof(ip_smatrix) ); … … 2290 2484 2291 2485 j=1; 2292 for ( k= numVectors - 1; k >= 0; k-- ) { 2486 for ( k= numVectors - 1; k >= 0; k-- ) 2487 { 2293 2488 vecp= getMVector(k); 2294 2489 if ( vecp->isReduced ) continue; 2295 2490 l=1; 2296 for ( i= numVectors - 1; i >= 0; i-- ) { 2491 for ( i= numVectors - 1; i >= 0; i-- ) 2492 { 2297 2493 if ( getMVector(i)->isReduced ) continue; 2298 if ( !nIsZero(vecp->getElemNum(numVectors - i - 1)) ) { 2299 MATELEM(resmat,j,l)= pInit(); 2300 MATELEM(resmat,j,l)= pCopy( vecp->getElem(numVectors-i-1) ); 2494 if ( !nIsZero(vecp->getElemNum(numVectors - i - 1)) ) 2495 { 2496 MATELEM(resmat,j,l)= pInit(); 2497 MATELEM(resmat,j,l)= pCopy( vecp->getElem(numVectors-i-1) ); 2301 2498 } 2302 2499 l++; 2303 2500 } 2304 2501 j++; 2305 } 2502 } 2306 2503 2307 2504 ideal resmod= idMatrix2Module(resmat); 2308 2505 2309 if ( resmat != NULL ) { 2506 if ( resmat != NULL ) 2507 { 2310 2508 for ( i= 1; i <= numVectors; i++ ) 2311 2509 for ( j= 1; j <= numVectors; j++ ) 2312 2510 pDelete( &MATELEM(resmat , i, j) ); 2313 2511 Free( (ADDRESS)resmat->m, numVectors * numVectors * sizeof(poly) ); 2314 2512 Free( (ADDRESS)resmat, sizeof(ip_smatrix) ); … … 2324 2522 // copy evaluation point into matrix 2325 2523 // p0, p1, ..., pn replace u0, u1, ..., un 2326 for ( k= numVectors - 1; k >= 0; k-- ) { 2327 if ( linPolyS == getMVector(k)->elementOfS ) { 2328 for ( i= 0; i < pVariables; i++ ) { 2329 pSetCoeff( MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i]), 2330 nCopy(evpoint[i]) ); 2524 for ( k= numVectors - 1; k >= 0; k-- ) 2525 { 2526 if ( linPolyS == getMVector(k)->elementOfS ) 2527 { 2528 for ( i= 0; i < pVariables; i++ ) 2529 { 2530 pSetCoeff( MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i]), 2531 nCopy(evpoint[i]) ); 2331 2532 } 2332 2533 } … … 2340 2541 // avoid errors for det==0 2341 2542 number numres; 2342 if ( res && pGetCoeff( res ) ) { 2543 if ( res && pGetCoeff( res ) ) 2544 { 2343 2545 numres= nCopy( pGetCoeff( res ) ); 2344 } else { 2546 } 2547 else 2548 { 2345 2549 numres= nInit(0); 2346 2550 mprPROT("0"); 2347 2551 } 2348 pDelete( &res ); 2552 pDelete( &res ); 2349 2553 2350 2554 mprSTICKYPROT(ST__DET); … … 2361 2565 matrix mat= mpNew( subSize, subSize ); 2362 2566 2363 for ( i= 1; i <= MATROWS( mat ); i++ ) { 2364 for ( j= 1; j <= MATCOLS( mat ); j++ ) { 2567 for ( i= 1; i <= MATROWS( mat ); i++ ) 2568 { 2569 for ( j= 1; j <= MATCOLS( mat ); j++ ) 2570 { 2365 2571 MATELEM(mat,i,j)= pInit(); 2366 2572 pSetCoeff0( MATELEM(mat,i,j), nInit(0) ); … … 2368 2574 } 2369 2575 j=1; 2370 for ( k= numVectors - 1; k >= 0; k-- ) { 2576 for ( k= numVectors - 1; k >= 0; k-- ) 2577 { 2371 2578 vecp= getMVector(k); 2372 2579 if ( vecp->isReduced ) continue; 2373 2580 l=1; 2374 for ( i= numVectors - 1; i >= 0; i-- ) { 2581 for ( i= numVectors - 1; i >= 0; i-- ) 2582 { 2375 2583 if ( getMVector(i)->isReduced ) continue; 2376 if ( vecp->getElemNum(numVectors - i - 1) && !nIsZero(vecp->getElemNum(numVectors - i - 1)) ) { 2377 pSetCoeff(MATELEM(mat, j , l ), nCopy(vecp->getElemNum(numVectors - i - 1))); 2378 } /* else { 2379 MATELEM(mat, j , l )= pOne(); 2380 pSetCoeff(MATELEM(mat, j , l ), nInit(0) ); 2381 } 2382 */ 2584 if ( vecp->getElemNum(numVectors - i - 1) && !nIsZero(vecp->getElemNum(numVectors - i - 1)) ) 2585 { 2586 pSetCoeff(MATELEM(mat, j , l ), nCopy(vecp->getElemNum(numVectors - i - 1))); 2587 } 2588 /* else 2589 { 2590 MATELEM(mat, j , l )= pOne(); 2591 pSetCoeff(MATELEM(mat, j , l ), nInit(0) ); 2592 } 2593 */ 2383 2594 l++; 2384 2595 } 2385 2596 j++; 2386 } 2597 } 2387 2598 2388 2599 poly res= singclap_det( mat ); 2389 2600 2390 2601 number numres; 2391 if ( res && pGetCoeff( res ) ) { 2602 if ( res && pGetCoeff( res ) ) 2603 { 2392 2604 numres= nCopy(pGetCoeff( res )); 2393 pDelete( &res ); 2394 } else { 2605 pDelete( &res ); 2606 } 2607 else 2608 { 2395 2609 numres= nInit(0); 2396 2610 } … … 2416 2630 mpz_init(md);mpz_set_ui(md,1); 2417 2631 mpz_init(mn);mpz_set_ui(mn,1); 2418 2632 2419 2633 mpz_fac_ui(m,n+d); 2420 2634 mpz_fac_ui(md,d); … … 2436 2650 uResultant::uResultant( const ideal _gls, const resMatType _rmt, BOOLEAN extIdeal ) 2437 2651 : rmt( _rmt ) 2438 { 2439 if ( extIdeal ) { 2652 { 2653 if ( extIdeal ) 2654 { 2440 2655 // extend given ideal by linear poly F0=u0x0 + u1x1 +...+ unxn 2441 2656 gls= extendIdeal( _gls, linearPoly( rmt ), rmt ); 2442 2657 n= IDELEMS( gls ); 2443 } else 2658 } else 2444 2659 gls= idCopy( _gls ); 2445 2660 2446 switch ( rmt ) { 2661 switch ( rmt ) 2662 { 2447 2663 case sparseResMat: 2448 2664 resMat= new resMatrixSparse( gls ); … … 2452 2668 break; 2453 2669 default: 2454 Werror ("uResultant::uResultant: Unknown resultant matrix type choosen!");2670 WerrorS("uResultant::uResultant: Unknown resultant matrix type choosen!"); 2455 2671 } 2456 2672 } … … 2464 2680 { 2465 2681 ideal newGls= idCopy( gls ); 2466 newGls->m= (poly *)ReAlloc( newGls->m, 2467 IDELEMS(gls) * sizeof(poly), 2468 2682 newGls->m= (poly *)ReAlloc( newGls->m, 2683 IDELEMS(gls) * sizeof(poly), 2684 (IDELEMS(gls) + 1) * sizeof(poly) ); 2469 2685 IDELEMS(newGls)++; 2470 2471 switch ( rmt ) { 2686 2687 switch ( rmt ) 2688 { 2472 2689 case sparseResMat: 2473 2690 case denseResMat: 2474 2691 { 2475 2692 int i; 2476 for ( i= IDELEMS(newGls)-1; i > 0; i-- ) { 2477 newGls->m[i]= newGls->m[i-1]; 2693 for ( i= IDELEMS(newGls)-1; i > 0; i-- ) 2694 { 2695 newGls->m[i]= newGls->m[i-1]; 2478 2696 } 2479 2697 newGls->m[0]= linPoly; … … 2481 2699 break; 2482 2700 default: 2483 Werror ("uResultant::extendIdeal: Unknown resultant matrix type choosen!");2484 } 2485 2701 WerrorS("uResultant::extendIdeal: Unknown resultant matrix type choosen!"); 2702 } 2703 2486 2704 return( newGls ); 2487 2705 } … … 2494 2712 poly actlp, rootlp= newlp; 2495 2713 2496 for ( i= 1; i <= pVariables; i++ ) { 2714 for ( i= 1; i <= pVariables; i++ ) 2715 { 2497 2716 actlp= newlp; 2498 2717 pSetExp( actlp, i, 1 ); … … 2504 2723 pDelete( &newlp ); 2505 2724 2506 if ( rmt == sparseResMat ) { 2725 if ( rmt == sparseResMat ) 2726 { 2507 2727 newlp= pOne(); 2508 2728 actlp->next= newlp; … … 2524 2744 // long mdg= (facul(tdg+n-1) / facul( tdg )) / facul( n - 1 ); 2525 2745 long mdg= over( n-1, tdg ); 2526 2746 2527 2747 // maxiaml number of terms in a polynom of degree tdg 2528 2748 long l=(long)pow( tdg+1, n ); … … 2534 2754 #endif 2535 2755 2536 // we need mdg results of D(p0,p1,...,pn) 2756 // we need mdg results of D(p0,p1,...,pn) 2537 2757 number *presults; 2538 2758 presults= (number *)Alloc( mdg * sizeof( number ) ); … … 2546 2766 // initial evaluatoin point 2547 2767 p=1; 2548 for (i=0; i < n; i++) { 2549 // init pevpoint with primes 3,5,7,11, ... 2768 for (i=0; i < n; i++) 2769 { 2770 // init pevpoint with primes 3,5,7,11, ... 2550 2771 p= nextPrime( p ); 2551 2772 pevpoint[i]=nInit( p ); … … 2556 2777 // evaluate the determinant in the points pev^0, pev^1, ..., pev^mdg 2557 2778 mprPROTnl("// evaluating:"); 2558 for ( i=0; i < mdg; i++ ) { 2559 for (j=0; j < n; j++) { 2779 for ( i=0; i < mdg; i++ ) 2780 { 2781 for (j=0; j < n; j++) 2782 { 2560 2783 nDelete( &pev[j] ); 2561 2784 nPower(pevpoint[j],i,&pev[j]); … … 2574 2797 mprPROTnl("// interpolating:"); 2575 2798 number *ncpoly; 2576 { 2799 { 2577 2800 vandermonde vm( mdg, n, tdg, pevpoint ); 2578 2801 ncpoly= vm.interpolateDense( presults ); … … 2581 2804 if ( subDetVal != NULL ) { // divide by common factor 2582 2805 number detdiv; 2583 for ( i= 0; i <= mdg; i++ ) { 2584 detdiv= nDiv( ncpoly[i], subDetVal ); 2585 nNormalize( detdiv ); 2586 nDelete( &ncpoly[i] ); 2587 ncpoly[i]= detdiv; 2588 } 2589 } 2590 2806 for ( i= 0; i <= mdg; i++ ) 2807 { 2808 detdiv= nDiv( ncpoly[i], subDetVal ); 2809 nNormalize( detdiv ); 2810 nDelete( &ncpoly[i] ); 2811 ncpoly[i]= detdiv; 2812 } 2813 } 2814 2591 2815 #ifdef mprDEBUG_ALL 2592 2816 PrintLn(); 2593 for ( i=0; i < mdg; i++ ) { 2594 nPrint(ncpoly[i]); Print(" --- "); 2817 for ( i=0; i < mdg; i++ ) 2818 { 2819 nPrint(ncpoly[i]); Print(" --- "); 2595 2820 } 2596 2821 PrintLn(); … … 2599 2824 // prepare ncpoly for later use 2600 2825 number nn=nInit(0); 2601 for ( i=0; i < mdg; i++ ) { 2602 if ( nEqual(ncpoly[i],nn) ) { 2826 for ( i=0; i < mdg; i++ ) 2827 { 2828 if ( nEqual(ncpoly[i],nn) ) 2829 { 2603 2830 nDelete( &ncpoly[i] ); 2604 2831 ncpoly[i]=NULL; … … 2616 2843 long c=0; 2617 2844 2618 for ( i=0; i < l; i++ ) { 2619 if ( sum == tdg ) { 2620 if ( ncpoly[c] ) { 2621 poly p= pOne(); 2622 if ( rmt == denseResMat ) { 2623 for ( j= 0; j < n; j++ ) pSetExp( p, j+1, exp[j] ); 2624 } else if ( rmt == sparseResMat ) { 2625 for ( j= 1; j < n; j++ ) pSetExp( p, j, exp[j] ); 2626 } 2627 pSetCoeff( p, ncpoly[c] ); 2628 pSetm( p ); 2629 if (result) result= pAdd( pCopy(result), pCopy(p) ); 2630 else result= pCopy( p ); 2631 pDelete( &p ); 2845 for ( i=0; i < l; i++ ) 2846 { 2847 if ( sum == tdg ) 2848 { 2849 if ( ncpoly[c] ) 2850 { 2851 poly p= pOne(); 2852 if ( rmt == denseResMat ) 2853 { 2854 for ( j= 0; j < n; j++ ) pSetExp( p, j+1, exp[j] ); 2855 } 2856 else if ( rmt == sparseResMat ) 2857 { 2858 for ( j= 1; j < n; j++ ) pSetExp( p, j, exp[j] ); 2859 } 2860 pSetCoeff( p, ncpoly[c] ); 2861 pSetm( p ); 2862 if (result) result= pAdd( pCopy(result), pCopy(p) ); 2863 else result= pCopy( p ); 2864 pDelete( &p ); 2632 2865 } 2633 2866 c++; … … 2635 2868 sum=0; 2636 2869 exp[0]++; 2637 for ( j= 0; j < n - 1; j++ ) { 2638 if ( exp[j] > tdg ) { 2639 exp[j]= 0; 2640 exp[j + 1]++; 2870 for ( j= 0; j < n - 1; j++ ) 2871 { 2872 if ( exp[j] > tdg ) 2873 { 2874 exp[j]= 0; 2875 exp[j + 1]++; 2641 2876 } 2642 2877 sum+=exp[j]; 2643 } 2878 } 2644 2879 sum+=exp[n-1]; 2645 } 2646 2880 } 2881 2647 2882 pSetm( result ); 2648 2883 pTest( result ); 2649 2884 2650 2885 return result; 2651 2886 } … … 2662 2897 2663 2898 // evaluate D in tdg+1 distinct points, so 2664 // we need tdg+1 results of D(p0,1,0,...,0) = 2899 // we need tdg+1 results of D(p0,1,0,...,0) = 2665 2900 // c(0)*u0^tdg + c(1)*u0^tdg-1 + ... + c(tdg-1)*u0 + c(tdg) 2666 2901 number *presults; … … 2682 2917 // this gives us n-1 evaluations 2683 2918 p=3; 2684 for ( uvar= 0; uvar < loops; uvar++ ) { 2919 for ( uvar= 0; uvar < loops; uvar++ ) 2920 { 2685 2921 // generate initial evaluation point 2686 if ( matchUp ) { 2687 for (i=0; i < n; i++) { 2688 // prime(random number) between 1 and MAXEVPOINT 2689 nDelete( &pevpoint[i] ); 2690 if ( i == 0 ) { 2691 //p= nextPrime( p ); 2692 pevpoint[i]= nInit( p ); 2693 } else 2694 if ( i <= uvar + 2 ) { 2695 pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0)))); 2696 //pevpoint[i]=nInit(383); 2697 } else pevpoint[i]=nInit(0); 2698 mprPROTNnl(" ",pevpoint[i]); 2699 } 2700 } else { 2701 for (i=0; i < n; i++) { 2702 // init pevpoint with prime,0,...0,1,0,...,0 2703 nDelete( &pevpoint[i] ); 2704 if ( i == 0 ) { 2705 //p=nextPrime( p ); 2706 pevpoint[i]=nInit( p ); 2707 } 2708 else 2709 if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1); 2710 else pevpoint[i]= nInit(0); 2711 mprPROTNnl(" ",pevpoint[i]); 2922 if ( matchUp ) 2923 { 2924 for (i=0; i < n; i++) 2925 { 2926 // prime(random number) between 1 and MAXEVPOINT 2927 nDelete( &pevpoint[i] ); 2928 if ( i == 0 ) 2929 { 2930 //p= nextPrime( p ); 2931 pevpoint[i]= nInit( p ); 2932 } 2933 else if ( i <= uvar + 2 ) 2934 { 2935 pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0)))); 2936 //pevpoint[i]=nInit(383); 2937 } 2938 else 2939 pevpoint[i]=nInit(0); 2940 mprPROTNnl(" ",pevpoint[i]); 2941 } 2942 } 2943 else 2944 { 2945 for (i=0; i < n; i++) 2946 { 2947 // init pevpoint with prime,0,...0,1,0,...,0 2948 nDelete( &pevpoint[i] ); 2949 if ( i == 0 ) 2950 { 2951 //p=nextPrime( p ); 2952 pevpoint[i]=nInit( p ); 2953 } 2954 else 2955 if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1); 2956 else pevpoint[i]= nInit(0); 2957 mprPROTNnl(" ",pevpoint[i]); 2712 2958 } 2713 2959 } 2714 2960 2715 2961 // prepare aktual evaluation point 2716 for (i=0; i < n; i++) { 2962 for (i=0; i < n; i++) 2963 { 2717 2964 nDelete( &pev[i] ); 2718 2965 pev[i]= nCopy( pevpoint[i] ); 2719 2966 } 2720 2967 // evaluate the determinant in the points pev^0, pev^1, ..., pev^tdg 2721 for ( i=0; i <= tdg; i++ ) { 2968 for ( i=0; i <= tdg; i++ ) 2969 { 2722 2970 nDelete( &pev[0] ); 2723 2971 nPower(pevpoint[0],i,&pev[0]); // new evpoint … … 2733 2981 mprSTICKYPROT("\n"); 2734 2982 2735 // now interpolate 2983 // now interpolate 2736 2984 vandermonde vm( tdg + 1, 1, tdg, pevpoint, FALSE ); 2737 2985 number *ncpoly= vm.interpolateDense( presults ); … … 2739 2987 if ( subDetVal != NULL ) { // divide by common factor 2740 2988 number detdiv; 2741 for ( i= 0; i <= tdg; i++ ) { 2742 detdiv= nDiv( ncpoly[i], subDetVal ); 2743 nNormalize( detdiv ); 2744 nDelete( &ncpoly[i] ); 2745 ncpoly[i]= detdiv; 2989 for ( i= 0; i <= tdg; i++ ) 2990 { 2991 detdiv= nDiv( ncpoly[i], subDetVal ); 2992 nNormalize( detdiv ); 2993 nDelete( &ncpoly[i] ); 2994 ncpoly[i]= detdiv; 2746 2995 } 2747 2996 } … … 2749 2998 #ifdef mprDEBUG_ALL 2750 2999 PrintLn(); 2751 for ( i=0; i <= tdg; i++ ) { 2752 nPrint(ncpoly[i]); Print(" --- "); 3000 for ( i=0; i <= tdg; i++ ) 3001 { 3002 nPrint(ncpoly[i]); Print(" --- "); 2753 3003 } 2754 3004 PrintLn(); … … 2756 3006 2757 3007 // save results 2758 roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg, 2759 2760 3008 roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg, 3009 (matchUp?rootContainer::cspecialmu:rootContainer::cspecial), 3010 loops ); 2761 3011 } 2762 3012 … … 2792 3042 // or D(u0,k1,k2,0,...,0), D(u0,k1,k2,k3,0,...,0), ..., D(u0,k1,k2,k3,...,kn) 2793 3043 p=3; 2794 for ( uvar= 0; uvar < loops; uvar++ ) { 3044 for ( uvar= 0; uvar < loops; uvar++ ) 3045 { 2795 3046 // generate initial evaluation point 2796 if ( matchUp ) { 2797 for (i=0; i < n; i++) { 2798 // prime(random number) between 1 and MAXEVPOINT 2799 nDelete( &pevpoint[i] ); 2800 if ( i <= uvar + 2 ) { 2801 pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0)))); 2802 //pevpoint[i]=nInit(383); 2803 } else pevpoint[i]=nInit(0); 2804 mprPROTNnl(" ",pevpoint[i]); 2805 } 2806 } else { 2807 for (i=0; i < n; i++) { 2808 // init pevpoint with prime,0,...0,-1,0,...,0 2809 nDelete( &(pevpoint[i]) ); 2810 if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1); 2811 else pevpoint[i]= nInit(0); 2812 mprPROTNnl(" ",pevpoint[i]); 3047 if ( matchUp ) 3048 { 3049 for (i=0; i < n; i++) 3050 { 3051 // prime(random number) between 1 and MAXEVPOINT 3052 nDelete( &pevpoint[i] ); 3053 if ( i <= uvar + 2 ) 3054 { 3055 pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0)))); 3056 //pevpoint[i]=nInit(383); 3057 } else pevpoint[i]=nInit(0); 3058 mprPROTNnl(" ",pevpoint[i]); 3059 } 3060 } 3061 else 3062 { 3063 for (i=0; i < n; i++) 3064 { 3065 // init pevpoint with prime,0,...0,-1,0,...,0 3066 nDelete( &(pevpoint[i]) ); 3067 if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1); 3068 else pevpoint[i]= nInit(0); 3069 mprPROTNnl(" ",pevpoint[i]); 2813 3070 } 2814 3071 } … … 2819 3076 2820 3077 piter= pures; 2821 for ( i= tdg; i >= 0; i-- ) { 3078 for ( i= tdg; i >= 0; i-- ) 3079 { 2822 3080 //if ( piter ) Print("deg %d, pDeg(piter) %d\n",i,pTotaldegree(piter)); 2823 if ( piter && pTotaldegree(piter) == i ) { 2824 ncpoly[i]= nCopy( pGetCoeff( piter ) ); 2825 pIter( piter ); 2826 } else { 2827 ncpoly[i]= nInit(0); 3081 if ( piter && pTotaldegree(piter) == i ) 3082 { 3083 ncpoly[i]= nCopy( pGetCoeff( piter ) ); 3084 pIter( piter ); 3085 } 3086 else 3087 { 3088 ncpoly[i]= nInit(0); 2828 3089 } 2829 3090 mprPROTNnl("", ncpoly[i] ); 2830 } 2831 3091 } 3092 2832 3093 mprSTICKYPROT(ST_BASE_EV); // . 2833 3094 2834 3095 if ( subDetVal != NULL ) { // divide by common factor 2835 3096 number detdiv; 2836 for ( i= 0; i <= tdg; i++ ) { 2837 detdiv= nDiv( ncpoly[i], subDetVal ); 2838 nNormalize( detdiv ); 2839 nDelete( &ncpoly[i] ); 2840 ncpoly[i]= detdiv; 3097 for ( i= 0; i <= tdg; i++ ) 3098 { 3099 detdiv= nDiv( ncpoly[i], subDetVal ); 3100 nNormalize( detdiv ); 3101 nDelete( &ncpoly[i] ); 3102 ncpoly[i]= detdiv; 2841 3103 } 2842 3104 } … … 2845 3107 2846 3108 // save results 2847 roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg, 2848 2849 3109 roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg, 3110 (matchUp?rootContainer::cspecialmu:rootContainer::cspecial), 3111 loops ); 2850 3112 } 2851 3113 … … 2864 3126 i+=2; 2865 3127 int j= IsPrime( i ); 2866 while ( j <= init ) { 3128 while ( j <= init ) 3129 { 2867 3130 i+=2; 2868 3131 j= IsPrime( i ); … … 2879 3142 // compile-command-1: "make installg" *** 2880 3143 // compile-command-2: "make install" *** 2881 // End: *** 3144 // End: *** 2882 3145 2883 3146 // in folding: C-c x -
Singular/mpr_base.h
r0f5091 re858e7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_base.h,v 1. 1 1999-06-28 12:48:12 wenkExp $ */6 /* $Id: mpr_base.h,v 1.2 1999-06-28 16:06:25 Singular Exp $ */ 7 7 8 /* 8 /* 9 9 * ABSTRACT - multipolynomial resultants - resultant matrices 10 10 * ( sparse, dense, u-resultant solver ) … … 21 21 * Base class for sparse and dense u-Resultant computation 22 22 */ 23 class resMatrixBase { 23 class resMatrixBase 24 { 24 25 public: 25 26 /* state of the resultant */ … … 37 38 virtual const number getSubDet() { return NULL; } 38 39 39 virtual const long getDetDeg() const { return totDeg; } 40 virtual const long getDetDeg() const { return totDeg; } 40 41 41 virtual const IStateType initState() const { return istate; } 42 virtual const IStateType initState() const { return istate; } 42 43 43 44 protected: … … 49 50 50 51 int totDeg; 51 52 52 53 private: 53 54 /* disables the copy constructor */ … … 60 61 * Base class for solving 0-dim poly systems using u-resultant 61 62 */ 62 class uResultant { 63 class uResultant 64 { 63 65 public: 64 66 enum resMatType { none, sparseResMat, denseResMat }; … … 75 77 rootContainer ** specializeInU( BOOLEAN matchUp= false, const number subDetVal= NULL ); 76 78 77 resMatrixBase * accessResMat() { return resMat; } 79 resMatrixBase * accessResMat() { return resMat; } 78 80 79 81 private: 80 82 /* deactivated copy constructor */ 81 83 uResultant( const uResultant & ); 82 84 83 85 ideal extendIdeal( const ideal gls, poly linPoly, const resMatType rmt ); 84 86 poly linearPoly( const resMatType rmt ); … … 99 101 // compile-command-2: "make install" *** 100 102 // compile-command: "make installg" *** 101 // End: *** 102 103 104 105 106 107 108 109 110 103 // End: *** -
Singular/mpr_complex.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mpr_complex.cc,v 1. 7 1999-06-28 12:48:12 wenkExp $ */4 /* $Id: mpr_complex.cc,v 1.8 1999-06-28 16:06:26 Singular Exp $ */ 5 5 6 6 /* … … 199 199 gmp_float r; 200 200 201 if ( rField_is_Q() ) { 201 if ( rField_is_Q() ) 202 { 202 203 if ( num != NULL ) 204 { 205 if (SR_HDL(num) & SR_INT) 203 206 { 204 if (SR_HDL(num) & SR_INT) 205 { 206 r= SR_TO_INT(num); 207 } 208 else 209 { 210 if ( num->s == 0 ) 211 { 212 nlNormalize( num ); 213 } 214 if (SR_HDL(num) & SR_INT) 215 { 216 r= SR_TO_INT(num); 217 } 218 else 219 { 220 if ( num->s != 3 ) 221 { 222 r= &num->z; 223 r/= (gmp_float)&num->n; 224 } 225 else 226 { 227 r= &num->z; 228 } 229 } 230 } 207 r= SR_TO_INT(num); 231 208 } 209 else 210 { 211 if ( num->s == 0 ) 212 { 213 nlNormalize( num ); 214 } 215 if (SR_HDL(num) & SR_INT) 216 { 217 r= SR_TO_INT(num); 218 } 219 else 220 { 221 if ( num->s != 3 ) 222 { 223 r= &num->z; 224 r/= (gmp_float)&num->n; 225 } 226 else 227 { 228 r= &num->z; 229 } 230 } 231 } 232 } 232 233 else 233 { 234 r= 0.0; 235 } 236 } else if (rField_is_long_R() || rField_is_long_C()) { 234 { 235 r= 0.0; 236 } 237 } 238 else if (rField_is_long_R() || rField_is_long_C()) 239 { 237 240 r= *(gmp_float*)num; 238 } else if ( rField_is_R() ) { 241 } 242 else if ( rField_is_R() ) 243 { 239 244 // Add some code here :-) 240 Werror("Ground field not implemented!"); 241 } else { 242 Werror("Ground field not implemented!"); 245 WerrorS("Ground field not implemented!"); 246 } 247 else 248 { 249 WerrorS("Ground field not implemented!"); 243 250 } 244 251 … … 499 506 in_real=floatToStr( c.real(), oprec ); // get real part 500 507 in_imag=floatToStr( abs(c.imag()), oprec ); // get imaginary part 501 502 if (rField_is_long_C()) { 508 509 if (rField_is_long_C()) 510 { 503 511 out=(char*)AllocL((strlen(in_real)+strlen(in_imag)+5+strlen(currRing->parameter[0]))*sizeof(char)); 504 512 sprintf(out,"%s%s%s*%s",in_real,c.imag().sign()>=0?"+":"-",currRing->parameter[0],in_imag); 505 } else { 513 } 514 else 515 { 506 516 out=(char*)AllocL( (strlen(in_real)+strlen(in_imag)+8) * sizeof(char)); 507 517 sprintf(out,"%s%s%s",in_real,c.imag().sign()>=0?" + I ":" - I ",in_imag); -
Singular/mpr_complex.h
r0f5091 re858e7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_complex.h,v 1. 5 1999-06-28 12:48:13 wenkExp $ */7 8 /* 6 /* $Id: mpr_complex.h,v 1.6 1999-06-28 16:06:26 Singular Exp $ */ 7 8 /* 9 9 * ABSTRACT - multipolynomial resultants - real floating-point numbers using gmp 10 10 * and complex numbers based on pairs of real floating-point numbers 11 * 11 * 12 12 */ 13 13 14 14 //-> include & define stuff 15 15 // must have gmp version >= 2 16 extern "C" { 16 extern "C" { 17 17 #include <gmp.h> 18 18 } … … 106 106 107 107 inline bool setFromStr( char * in ); 108 109 // access 108 109 // access 110 110 inline const mpf_t *mpfp() const; 111 111 … … 117 117 118 118 public: 119 static void setPrecision( const unsigned long int prec ) { 120 gmp_default_prec_bits= prec; 121 } 122 static void setEqualBits( const unsigned long int prec ) { 123 gmp_needequal_bits= prec; 124 } 125 126 static const unsigned long int getPrecision() { 127 return gmp_default_prec_bits; 128 } 129 static const unsigned long int getEqualBits() { 130 return gmp_needequal_bits; 119 static void setPrecision( const unsigned long int prec ) { 120 gmp_default_prec_bits= prec; 121 } 122 static void setEqualBits( const unsigned long int prec ) { 123 gmp_needequal_bits= prec; 124 } 125 126 static const unsigned long int getPrecision() { 127 return gmp_default_prec_bits; 128 } 129 static const unsigned long int getEqualBits() { 130 return gmp_needequal_bits; 131 131 } 132 132 … … 270 270 //-> class gmp_complex 271 271 /** 272 * @short gmp_complex numbers based on 272 * @short gmp_complex numbers based on 273 273 */ 274 274 class gmp_complex … … 306 306 307 307 // gmp_complex <operator> real 308 inline friend gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d ); 308 inline friend gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d ); 309 309 inline friend gmp_complex operator - ( const gmp_complex & a, const gmp_float b_d ); 310 310 inline friend gmp_complex operator * ( const gmp_complex & a, const gmp_float b_d ); … … 388 388 // compile-command-1: "make installg" *** 389 389 // compile-command-2: "make install" *** 390 // End: *** 391 392 393 394 395 390 // End: *** -
Singular/mpr_global.h
r0f5091 re858e7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_global.h,v 1. 3 1999-06-28 12:48:14 wenkExp $ */6 /* $Id: mpr_global.h,v 1.4 1999-06-28 16:06:27 Singular Exp $ */ 7 7 8 /* 9 * ABSTRACT - multipolynomial resultants - 8 /* 9 * ABSTRACT - multipolynomial resultants - 10 10 * global definitions and debugging stuff 11 11 */ … … 36 36 #define mprPROT(msg) Print("%s",msg) 37 37 #define mprPROTnl(msg) Print("%s\n",msg) 38 #define mprPROTP(msg,poly) Print("%s",msg);pWrite0(poly) 39 #define mprPROTPnl(msg,poly) Print("%s",msg);pWrite(poly) 38 #define mprPROTP(msg,poly) Print("%s",msg);pWrite0(poly) 39 #define mprPROTPnl(msg,poly) Print("%s",msg);pWrite(poly) 40 40 #define mprPROTI(msg,intval) Print("%s%d",msg,intval) 41 41 #define mprPROTInl(msg,intval) Print("%s%d\n",msg,intval) 42 42 #define mprPROTN(msg,nval) Print("%s",msg);nPrint(nval); 43 43 #define mprPROTNnl(msg,nval) Print("%s",msg);nPrint(nval);PrintLn(); 44 #else 45 #define mprPROT(msg) 44 #else 45 #define mprPROT(msg) 46 46 #define mprPROTnl(msg) 47 47 #define mprPROTP(msg,poly) … … 93 93 // compile-command-1: "make installg" *** 94 94 // compile-command-2: "make install" *** 95 // End: *** 96 97 98 95 // End: *** -
Singular/mpr_inout.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mpr_inout.cc,v 1. 1 1999-06-28 12:48:14 wenkExp $ */5 6 /* 4 /* $Id: mpr_inout.cc,v 1.2 1999-06-28 16:06:28 Singular Exp $ */ 5 6 /* 7 7 * ABSTRACT - multipolynomial resultant 8 8 */ … … 14 14 #include "tok.h" 15 15 #include "structs.h" 16 #include "subexpr.h" 16 #include "subexpr.h" 17 17 #include "polys.h" 18 18 #include "ideals.h" … … 47 47 #define TIMING_EPR(t,msg) TIMING_END_AND_PRINT(t,msg);TIMING_RESET(t); 48 48 49 enum mprState{ 50 mprOk, 49 enum mprState 50 { 51 mprOk, 51 52 mprWrongRType, 52 mprHasOne, 53 mprHasOne, 53 54 mprInfNumOfVars, 54 55 mprNotReduced, … … 61 62 //<- 62 63 63 //-> nPrint(number n) 64 //-> nPrint(number n) 64 65 void nPrint(number n) 65 66 { … … 76 77 void mprPrintError( mprState state, const char * name ) 77 78 { 78 switch (state) { 79 switch (state) 80 { 79 81 case mprWrongRType: 80 Werror ("Unknown resultant matrix type choosen!");82 WerrorS("Unknown resultant matrix type choosen!"); 81 83 break; 82 84 case mprHasOne: … … 85 87 case mprInfNumOfVars: 86 88 Werror("Numer of elements in given ideal %s must be equal to %d!", 87 89 name,pVariables+1); 88 90 break; 89 91 case mprNotZeroDim: … … 92 94 case mprNotHomog: 93 95 Werror("The given ideal %s has to be homogeneous in" 94 96 " the first ring variable!",name); 95 97 break; 96 98 case mprNotReduced: … … 98 100 break; 99 101 case mprUnSupField: 100 Werror ("Ground field not implemented!");102 WerrorS("Ground field not implemented!"); 101 103 break; 102 104 default: … … 107 109 108 110 //-> mprState mprIdealCheck() 109 mprState mprIdealCheck( const ideal theIdeal, 110 const char * name, 111 uResultant::resMatType mtype, 112 111 mprState mprIdealCheck( const ideal theIdeal, 112 const char * name, 113 uResultant::resMatType mtype, 114 BOOLEAN rmatrix= false ) 113 115 { 114 116 mprState state = mprOk; 115 117 int power; 116 int k; 118 int k; 117 119 118 120 int numOfVars= mtype == uResultant::denseResMat?pVariables-1:pVariables; 119 121 if ( rmatrix ) numOfVars++; 120 122 121 if ( mtype == uResultant::none ) 123 if ( mtype == uResultant::none ) 122 124 state= mprWrongRType; 123 125 … … 125 127 state= mprInfNumOfVars; 126 128 127 for ( k= IDELEMS(theIdeal) - 1; (state == mprOk) && (k >= 0); k-- ) { 129 for ( k= IDELEMS(theIdeal) - 1; (state == mprOk) && (k >= 0); k-- ) 130 { 128 131 poly p = (theIdeal->m)[k]; 129 132 if ( pIsConstant(p) ) state= mprHasOne; 130 else 131 if ( (mtype == uResultant::denseResMat) && !pIsHomogeneous(p) ) 133 else 134 if ( (mtype == uResultant::denseResMat) && !pIsHomogeneous(p) ) 132 135 state=mprNotHomog; 133 136 } 134 137 135 138 if ( !(rField_is_R()|| 136 137 138 139 (rmatrix && rField_is_Q_a())) ) 139 rField_is_Q()|| 140 rField_is_long_R()|| 141 rField_is_long_C()|| 142 (rmatrix && rField_is_Q_a())) ) 140 143 state= mprUnSupField; 141 144 … … 149 152 uResultant::resMatType determineMType( int imtype ) 150 153 { 151 switch ( imtype ) { 154 switch ( imtype ) 155 { 152 156 case MPR_DENSE: 153 157 return uResultant::denseResMat; … … 181 185 res->rtyp = LIST_CMD; 182 186 res->data= (void *)emptylist; 183 187 184 188 TIMING_START(mpr_overall); 185 189 186 190 // check input ideal ( = polynomial system ) 187 if ( mprIdealCheck( gls, arg1->Name(), mtype ) != mprOk ) { 191 if ( mprIdealCheck( gls, arg1->Name(), mtype ) != mprOk ) 192 { 188 193 return TRUE; 189 194 } … … 197 202 TIMING_START(mpr_constr); 198 203 ures= new uResultant( gls, mtype ); 199 if ( ures->accessResMat()->initState() != resMatrixBase::ready ) { 200 Werror("Error occurred during matrix setup!"); 204 if ( ures->accessResMat()->initState() != resMatrixBase::ready ) 205 { 206 WerrorS("Error occurred during matrix setup!"); 201 207 return TRUE; 202 208 } … … 205 211 // if dense resultant, check if minor nonsingular 206 212 TIMING_START(mpr_check); 207 if ( mtype == uResultant::denseResMat ) { 213 if ( mtype == uResultant::denseResMat ) 214 { 208 215 smv= ures->accessResMat()->getSubDet(); 209 216 #ifdef mprDEBUG_PROT 210 217 Print("// Determinant of submatrix: ");nPrint(smv);PrintLn(); 211 218 #endif 212 if ( nIsZero(smv) ) { 213 Werror("Unsuitable input ideal: Minor of resultant matrix is singular!"); 219 if ( nIsZero(smv) ) 220 { 221 WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!"); 214 222 return TRUE; 215 223 } … … 220 228 TIMING_START(mpr_ures); 221 229 if ( interpolate_det ) 222 iproots= ures->interpolateDenseSP( false, smv ); 223 else 230 iproots= ures->interpolateDenseSP( false, smv ); 231 else 224 232 iproots= ures->specializeInU( false, smv ); 225 233 TIMING_EPR(mpr_ures, "interpolation ures\t") … … 227 235 // main task 3: Interpolate specialized resultant polynomials 228 236 TIMING_START(mpr_mures); 229 if ( interpolate_det ) 237 if ( interpolate_det ) 230 238 muiproots= ures->interpolateDenseSP( true, smv ); 231 else 239 else 232 240 muiproots= ures->specializeInU( true, smv ); 233 241 TIMING_EPR(mpr_mures, "interpolation mures\t") … … 245 253 arranger->solve_all(); 246 254 TIMING_EPR(mpr_solver, "solver time\t\t"); 247 255 248 256 // get list of roots 249 if ( arranger->success() ) { 257 if ( arranger->success() ) 258 { 250 259 TIMING_START(mpr_arrange); 251 260 arranger->arrange(); 252 261 TIMING_EPR(mpr_arrange, "arrange time\t\t"); 253 262 listofroots= arranger->listOfRoots( gmp_output_digits ); 254 } else { 255 Werror("Solver was unable to find any root!"); 263 } 264 else 265 { 266 WerrorS("Solver was unable to find any root!"); 256 267 return TRUE; 257 268 } … … 273 284 emptylist->Clean(); 274 285 //Free( (ADDRESS) emptylist, sizeof(slists) ); 275 286 276 287 TIMING_EPR(mpr_overall,"overall time\t\t") 277 288 … … 290 301 291 302 // check input ideal ( = polynomial system ) 292 if ( mprIdealCheck( gls, arg1->Name(), mtype, true ) != mprOk ) { 303 if ( mprIdealCheck( gls, arg1->Name(), mtype, true ) != mprOk ) 304 { 293 305 return TRUE; 294 306 } … … 300 312 301 313 delete resMat; 302 314 303 315 return FALSE; 304 316 } … … 312 324 gls= (poly)(arg1->Data()); 313 325 int howclean= (int)arg2->Data(); 314 326 315 327 int deg= pTotaldegree( gls ); 316 328 // int deg= pDeg( gls ); … … 325 337 326 338 if ( !(rField_is_R() || 327 rField_is_Q() || 328 rField_is_long_R() || 329 rField_is_long_C()) ) { 330 Werror("Ground field not implemented!\n"); 331 return TRUE; 332 } 333 334 if ( pVariables > 1 ) { 339 rField_is_Q() || 340 rField_is_long_R() || 341 rField_is_long_C()) ) 342 { 343 WerrorS("Ground field not implemented!"); 344 return TRUE; 345 } 346 347 if ( pVariables > 1 ) 348 { 335 349 piter= gls; 336 for ( i= 1; i <= pVariables; i++ ) 337 if ( pGetExp( piter, i ) ) { 338 vpos= i; 339 break; 350 for ( i= 1; i <= pVariables; i++ ) 351 if ( pGetExp( piter, i ) ) 352 { 353 vpos= i; 354 break; 340 355 } 341 while ( piter ) { 342 for ( i= 1; i <= pVariables; i++ ) 343 if ( (vpos != i) && (pGetExp( piter, i ) != 0) ) { 344 Werror("The polynomial %s must be univariate!",arg1->Name()); 345 return TRUE; 346 } 356 while ( piter ) 357 { 358 for ( i= 1; i <= pVariables; i++ ) 359 if ( (vpos != i) && (pGetExp( piter, i ) != 0) ) 360 { 361 Werror("The polynomial %s must be univariate!",arg1->Name()); 362 return TRUE; 363 } 347 364 pIter( piter ); 348 365 } … … 352 369 number * pcoeffs= (number *)Alloc( (deg+1) * sizeof( number ) ); 353 370 piter= gls; 354 for ( i= deg; i >= 0; i-- ) { 371 for ( i= deg; i >= 0; i-- ) 372 { 355 373 //if ( piter ) Print("deg %d, pDeg(piter) %d\n",i,pTotaldegree(piter)); 356 if ( piter && pTotaldegree(piter) == i ) { 374 if ( piter && pTotaldegree(piter) == i ) 375 { 357 376 pcoeffs[i]= nCopy( pGetCoeff( piter ) ); 358 377 //nPrint( pcoeffs[i] );Print(" "); 359 378 pIter( piter ); 360 } else { 379 } 380 else 381 { 361 382 pcoeffs[i]= nInit(0); 362 383 } 363 } 384 } 364 385 365 386 #ifdef mprDEBUG_PROT 366 for (i=deg; i >= 0; i--) { 387 for (i=deg; i >= 0; i--) 388 { 367 389 nPrint( pcoeffs[i] );Print(" "); 368 390 } … … 383 405 rlist->Init( elem ); 384 406 385 if (rField_is_long_C()) { 386 for ( j= 0; j < elem; j++ ) { 407 if (rField_is_long_C()) 408 { 409 for ( j= 0; j < elem; j++ ) 410 { 387 411 rlist->m[j].rtyp=NUMBER_CMD; 388 412 rlist->m[j].data=(void *)nCopy((number)(roots->getRoot(j))); 389 413 //rlist->m[j].data=(void *)(number)(roots->getRoot(j)); 390 414 } 391 } else { 392 for ( j= 0; j < elem; j++ ) { 415 } 416 else 417 { 418 for ( j= 0; j < elem; j++ ) 419 { 393 420 dummy = complexToStr( (*roots)[j], gmp_output_digits ); 394 421 rlist->m[j].rtyp=STRING_CMD; … … 423 450 // p can be a vector of numbers (multivariate polynom) 424 451 // or one number (univariate polynom) 425 // tdg = deg(f) 426 427 int n= IDELEMS( p ); 452 // tdg = deg(f) 453 454 int n= IDELEMS( p ); 428 455 int m= IDELEMS( w ); 429 456 int tdg= (int)arg3->Data(); 430 457 431 458 res->data= (void*)NULL; 432 459 433 460 // check the input 434 if ( tdg < 1 ) { 435 Werror("Last input parameter must be > 0!"); 436 return TRUE; 437 } 438 if ( n != pVariables ) { 439 Werror("Size of first input ideal must be equal to %d!\n",pVariables); 440 return TRUE; 441 } 442 if ( m != (int)pow((double)tdg+1,(int)n) ) { 443 Werror("Size of second input ideal must be equal to %d!\n",(int)pow((double)tdg+1,(int)n)); 461 if ( tdg < 1 ) 462 { 463 WerrorS("Last input parameter must be > 0!"); 464 return TRUE; 465 } 466 if ( n != pVariables ) 467 { 468 Werror("Size of first input ideal must be equal to %d!",pVariables); 469 return TRUE; 470 } 471 if ( m != (int)pow((double)tdg+1,(int)n) ) 472 { 473 Werror("Size of second input ideal must be equal to %d!", 474 (int)pow((double)tdg+1,(int)n)); 444 475 return TRUE; 445 476 } 446 477 if ( !(rField_is_Q() /* || 447 rField_is_R() || rField_is_long_R() || 448 rField_is_long_C()*/ ) ) { 449 Werror("Ground field not implemented!\n"); 478 rField_is_R() || rField_is_long_R() || 479 rField_is_long_C()*/ ) ) 480 { 481 WerrorS("Ground field not implemented!"); 450 482 return TRUE; 451 483 } … … 453 485 number tmp; 454 486 number *pevpoint= (number *)Alloc( n * sizeof( number ) ); 455 for ( i= 0; i < n; i++ ) { 487 for ( i= 0; i < n; i++ ) 488 { 456 489 pevpoint[i]=nInit(0); 457 if ( (p->m)[i] ) { 490 if ( (p->m)[i] ) 491 { 458 492 tmp = pGetCoeff( (p->m)[i] ); 459 if ( nIsZero(tmp) || nIsOne(tmp) || nIsMOne(tmp) ) { 460 Free( (ADDRESS)pevpoint, n * sizeof( number ) ); 461 Werror("Elements of first input ideal must not be equal to -1, 0, 1!"); 462 return TRUE; 493 if ( nIsZero(tmp) || nIsOne(tmp) || nIsMOne(tmp) ) 494 { 495 Free( (ADDRESS)pevpoint, n * sizeof( number ) ); 496 WerrorS("Elements of first input ideal must not be equal to -1, 0, 1!"); 497 return TRUE; 463 498 } 464 499 } else tmp= NULL; 465 if ( !nIsZero(tmp) ) { 466 if ( !pIsConstant((p->m)[i])) { 467 Free( (ADDRESS)pevpoint, n * sizeof( number ) ); 468 Werror("Elements of first input ideal must be numbers!"); 469 return TRUE; 500 if ( !nIsZero(tmp) ) 501 { 502 if ( !pIsConstant((p->m)[i])) 503 { 504 Free( (ADDRESS)pevpoint, n * sizeof( number ) ); 505 WerrorS("Elements of first input ideal must be numbers!"); 506 return TRUE; 470 507 } 471 508 pevpoint[i]= nCopy( tmp ); … … 474 511 475 512 number *wresults= (number *)Alloc( m * sizeof( number ) ); 476 for ( i= 0; i < m; i++ ) { 513 for ( i= 0; i < m; i++ ) 514 { 477 515 wresults[i]= nInit(0); 478 if ( (w->m)[i] && !nIsZero(pGetCoeff((w->m)[i])) ) { 479 if ( !pIsConstant((w->m)[i])) { 480 Free( (ADDRESS)pevpoint, n * sizeof( number ) ); 481 Free( (ADDRESS)wresults, m * sizeof( number ) ); 482 Werror("Elements of second input ideal must be numbers!"); 483 return TRUE; 516 if ( (w->m)[i] && !nIsZero(pGetCoeff((w->m)[i])) ) 517 { 518 if ( !pIsConstant((w->m)[i])) 519 { 520 Free( (ADDRESS)pevpoint, n * sizeof( number ) ); 521 Free( (ADDRESS)wresults, m * sizeof( number ) ); 522 WerrorS("Elements of second input ideal must be numbers!"); 523 return TRUE; 484 524 } 485 525 wresults[i]= nCopy(pGetCoeff((w->m)[i])); … … 500 540 //<- 501 541 502 //-> function u_resultant_det 542 //-> function u_resultant_det 503 543 poly u_resultant_det( ideal gls, int imtype ) 504 544 { … … 511 551 512 552 // check input ideal ( = polynomial system ) 513 if ( mprIdealCheck( gls, "", mtype ) != mprOk ) { 553 if ( mprIdealCheck( gls, "", mtype ) != mprOk ) 554 { 514 555 return emptypoly; 515 556 } … … 523 564 524 565 // if dense resultant, check if minor nonsingular 525 if ( mtype == uResultant::denseResMat ) { 566 if ( mtype == uResultant::denseResMat ) 567 { 526 568 smv= ures->accessResMat()->getSubDet(); 527 569 #ifdef mprDEBUG_PROT 528 570 Print("// Determinant of submatrix: ");nPrint(smv); PrintLn(); 529 571 #endif 530 if ( nIsZero(smv) ) { 531 Werror("Unsuitable input ideal: Minor of resultant matrix is singular!"); 572 if ( nIsZero(smv) ) 573 { 574 WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!"); 532 575 return emptypoly; 533 576 } … … 558 601 // compile-command-1: "make installg" *** 559 602 // compile-command-2: "make install" *** 560 // End: *** 603 // End: *** 561 604 562 605 // in folding: C-c x -
Singular/mpr_inout.h
r0f5091 re858e7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_inout.h,v 1. 1 1999-06-28 12:48:15 wenkExp $ */6 /* $Id: mpr_inout.h,v 1.2 1999-06-28 16:06:28 Singular Exp $ */ 7 7 8 /* 8 /* 9 9 * ABSTRACT - multipolynomial resultants - interface to Singular 10 * 10 * 11 11 */ 12 12 … … 18 18 /** solve a multipolynomial system using the u-resultant 19 19 * Input ideal must be 0-dimensional and pVariables == IDELEMS(ideal). 20 * Resultant method can be MPR_DENSE, which uses Macaulay Resultant (good for 21 * dense homogeneous polynoms) or MPR_SPARSE, which uses Sparse Resultant 20 * Resultant method can be MPR_DENSE, which uses Macaulay Resultant (good for 21 * dense homogeneous polynoms) or MPR_SPARSE, which uses Sparse Resultant 22 22 * (Gelfand, Kapranov, Zelevinsky). 23 * If interpolate == true then the determinant of the u-resultant will be 24 * numerically interpolatet using a Vandermonde System. 23 * If interpolate == true then the determinant of the u-resultant will be 24 * numerically interpolatet using a Vandermonde System. 25 25 * Otherwise, the Sparse Bareiss will be used (faster!). 26 26 * Returns a list containing the roots of the system. … … 34 34 35 35 /** find the (complex) roots an univariate polynomial 36 * Determines the roots of an univariate polynomial using Laguerres' 36 * Determines the roots of an univariate polynomial using Laguerres' 37 37 * root-solver. Good for polynomials with low and middle degree (<40). 38 38 * Returns a list containing the roots of the polynomial. … … 50 50 // compile-command-1: "make installg" *** 51 51 // compile-command-2: "make install" *** 52 // End: *** 52 // End: *** -
Singular/mpr_numeric.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mpr_numeric.cc,v 1. 1 1999-06-28 12:48:16 wenkExp $ */5 6 /* 4 /* $Id: mpr_numeric.cc,v 1.2 1999-06-28 16:06:29 Singular Exp $ */ 5 6 /* 7 7 * ABSTRACT - multipolynomial resultants - numeric stuff 8 * ( root finder, vandermonde system solver, simplex ) 8 * ( root finder, vandermonde system solver, simplex ) 9 9 */ 10 10 … … 40 40 41 41 //-> vandermonde::* 42 vandermonde::vandermonde( const long _cn, const long _n, const long _maxdeg, 43 42 vandermonde::vandermonde( const long _cn, const long _n, const long _maxdeg, 43 number *_p, const bool _homog ) 44 44 : n(_n), cn(_cn), maxdeg(_maxdeg), p(_p), homog(_homog) 45 45 { … … 70 70 for ( j= 0; j < n; j++ ) exp[j]=0; 71 71 72 for ( i= 0; i < l; i++ ) { 73 if ( !homog || (sum == maxdeg) ) { 74 for ( j= 0; j < n; j++ ) { 75 nPower( p[j], exp[j], &tmp ); 76 tmp1 = nMult( tmp, x[c] ); 77 x[c]= tmp1; 78 nDelete( &tmp ); 72 for ( i= 0; i < l; i++ ) 73 { 74 if ( !homog || (sum == maxdeg) ) 75 { 76 for ( j= 0; j < n; j++ ) 77 { 78 nPower( p[j], exp[j], &tmp ); 79 tmp1 = nMult( tmp, x[c] ); 80 x[c]= tmp1; 81 nDelete( &tmp ); 79 82 } 80 83 c++; … … 82 85 exp[0]++; 83 86 sum=0; 84 for ( j= 0; j < n - 1; j++ ) { 85 if ( exp[j] > maxdeg ) { 86 exp[j]= 0; 87 exp[j + 1]++; 88 } 87 for ( j= 0; j < n - 1; j++ ) 88 { 89 if ( exp[j] > maxdeg ) 90 { 91 exp[j]= 0; 92 exp[j + 1]++; 93 } 89 94 sum+= exp[j]; 90 95 } … … 108 113 for ( j= 0; j < n+1; j++ ) exp[j]=0; 109 114 110 for ( i= 0; i < l; i++ ) { 111 if ( (!homog || (sum == maxdeg)) && q[i] && !nIsZero(q[i]) ) { 115 for ( i= 0; i < l; i++ ) 116 { 117 if ( (!homog || (sum == maxdeg)) && q[i] && !nIsZero(q[i]) ) 118 { 112 119 pnew= pOne(); 113 120 pSetCoeff(pnew,q[i]); 114 121 pSetExpV(pnew,exp); 115 if ( pit ) { 116 pNext(pnew)= pit; 117 pit= pnew; 118 } else { 119 pit= pnew; 120 pNext(pnew)= NULL; 121 } 122 if ( pit ) 123 { 124 pNext(pnew)= pit; 125 pit= pnew; 126 } 127 else 128 { 129 pit= pnew; 130 pNext(pnew)= NULL; 131 } 122 132 pSetm(pit); 123 133 } 124 134 exp[1]++; 125 135 sum=0; 126 for ( j= 1; j < n; j++ ) { 127 if ( exp[j] > maxdeg ) { 128 exp[j]= 0; 129 exp[j + 1]++; 130 } 136 for ( j= 1; j < n; j++ ) 137 { 138 if ( exp[j] > maxdeg ) 139 { 140 exp[j]= 0; 141 exp[j + 1]++; 142 } 131 143 sum+= exp[j]; 132 144 } … … 135 147 136 148 Free( (ADDRESS) exp, (n+1) * sizeof(Exponent_t) ); 137 149 138 150 pOrdPolyMerge(pit); 139 151 return pit; … … 152 164 w= (number *)Alloc( cn * sizeof(number) ); 153 165 c= (number *)Alloc( cn * sizeof(number) ); 154 for ( j= 0; j < cn; j++ ) { 166 for ( j= 0; j < cn; j++ ) 167 { 155 168 w[j]= nInit(0); 156 169 c[j]= nInit(0); 157 170 } 158 171 159 if ( cn == 1 ) { 172 if ( cn == 1 ) 173 { 160 174 nDelete( &w[0] ); 161 175 w[0]= nCopy(q[0]); 162 } else { 176 } 177 else 178 { 163 179 nDelete( &c[cn-1] ); 164 180 c[cn-1]= nCopy(x[0]); … … 171 187 172 188 for ( j= (cn-i-1); j <= (cn-2); j++) { // j=(cn+1-i); j <= (cn-1) 173 174 175 176 177 189 nDelete( &tmp1 ); 190 tmp1= nMult( xx, c[j+1] ); // c[j]= c[j] + (xx * c[j+1]) 191 newnum= nAdd( c[j], tmp1 ); 192 nDelete( &c[j] ); 193 c[j]= newnum; 178 194 } 179 195 … … 187 203 xx= nCopy(x[i]); // xx= x[i] 188 204 189 nDelete( &t ); 205 nDelete( &t ); 190 206 t= nInit( 1 ); // t= b= 1 191 207 nDelete( &b ); 192 b= nInit( 1 ); 208 b= nInit( 1 ); 193 209 nDelete( &s ); // s= q[cn-1] 194 210 s= nCopy( q[cn-1] ); 195 211 196 212 for ( k= cn-1; k >= 1; k-- ) { // k=cn; k >= 2 197 198 199 200 b= nAdd( c[k], tmp1 ); 201 202 203 204 205 206 207 208 209 210 211 212 213 nDelete( &tmp1 ); 214 tmp1= nMult( xx, b ); // b= c[k] + (xx * b) 215 nDelete( &b ); 216 b= nAdd( c[k], tmp1 ); 217 218 nDelete( &tmp1 ); 219 tmp1= nMult( q[k-1], b ); // s= s + (q[k-1] * b) 220 newnum= nAdd( s, tmp1 ); 221 nDelete( &s ); 222 s= newnum; 223 224 nDelete( &tmp1 ); 225 tmp1= nMult( xx, t ); // t= (t * xx) + b 226 newnum= nAdd( tmp1, b ); 227 nDelete( &t ); 228 t= newnum; 213 229 } 214 230 … … 245 261 //-> definitions 246 262 #define MR 8 // never change this value 247 #define MT 20 263 #define MT 20 248 264 #define MAXIT (MT*MR) // max number of iterations in laguer root finder 249 265 … … 252 268 //<- 253 269 254 //-> rootContainer::rootContainer() 270 //-> rootContainer::rootContainer() 255 271 rootContainer::rootContainer() 256 272 { … … 265 281 //<- 266 282 267 //-> rootContainer::~rootContainer() 283 //-> rootContainer::~rootContainer() 268 284 rootContainer::~rootContainer() 269 285 { … … 272 288 273 289 // free coeffs, ievpoint 274 if ( ievpoint != NULL ) { 290 if ( ievpoint != NULL ) 291 { 275 292 for ( i=0; i < anz+2; i++ ) nDelete( ievpoint + i ); 276 293 Free( (ADDRESS)ievpoint, (anz+2) * sizeof( number ) ); … … 283 300 for ( i=0; i < tdg; i++ ) delete theroots[i]; 284 301 Free( (ADDRESS) theroots, (tdg)*sizeof(gmp_complex*) ); 285 302 286 303 mprPROTnl("~rootContainer()"); 287 304 } 288 305 //<- 289 306 290 //-> void rootContainer::fillContainer( ... ) 291 void rootContainer::fillContainer( number *_coeffs, number *_ievpoint, 292 const int _var, const int _tdg, 293 307 //-> void rootContainer::fillContainer( ... ) 308 void rootContainer::fillContainer( number *_coeffs, number *_ievpoint, 309 const int _var, const int _tdg, 310 const rootType _rt, const int _anz ) 294 311 { 295 312 int i; … … 301 318 anz=_anz; 302 319 303 for ( i=0; i <= tdg; i++ ) { 304 if ( nEqual(coeffs[i],nn) ) { 320 for ( i=0; i <= tdg; i++ ) 321 { 322 if ( nEqual(coeffs[i],nn) ) 323 { 305 324 nDelete( &coeffs[i] ); 306 325 coeffs[i]=NULL; … … 312 331 ievpoint= (number *)Alloc( (anz+2) * sizeof( number ) ); 313 332 for (i=0; i < anz+2; i++) ievpoint[i]= nCopy( _ievpoint[i] ); 314 } 333 } 315 334 316 335 theroots= NULL; … … 319 338 //<- 320 339 321 //-> poly rootContainer::getPoly() 340 //-> poly rootContainer::getPoly() 322 341 poly rootContainer::getPoly() 323 342 { … … 327 346 poly ppos; 328 347 329 if ( (rt == cspecial) || ( rt == cspecialmu ) ) { 330 for ( i= tdg; i >= 0; i-- ) { 331 if ( coeffs[i] ) { 332 poly p= pOne(); 333 //pSetExp( p, var+1, i); 334 pSetExp( p, 1, i); 335 pSetCoeff( p, nCopy( coeffs[i] ) ); 336 pSetm( p ); 337 if (result) { 338 ppos->next=p; 339 ppos=ppos->next; 340 } else { 341 result=p; 342 ppos=p; 343 } 344 348 if ( (rt == cspecial) || ( rt == cspecialmu ) ) 349 { 350 for ( i= tdg; i >= 0; i-- ) 351 { 352 if ( coeffs[i] ) 353 { 354 poly p= pOne(); 355 //pSetExp( p, var+1, i); 356 pSetExp( p, 1, i); 357 pSetCoeff( p, nCopy( coeffs[i] ) ); 358 pSetm( p ); 359 if (result) 360 { 361 ppos->next=p; 362 ppos=ppos->next; 363 } 364 else 365 { 366 result=p; 367 ppos=p; 368 } 369 345 370 } 346 371 } 347 372 pSetm( result ); 348 } 373 } 349 374 350 375 return result; … … 352 377 //<- 353 378 354 //-> const gmp_complex & rootContainer::opterator[] ( const int i ) 379 //-> const gmp_complex & rootContainer::opterator[] ( const int i ) 355 380 // this is now inline! 356 381 // gmp_complex & rootContainer::operator[] ( const int i ) 357 382 // { 358 // if ( found_roots && ( i >= 0) && ( i < tdg ) ) { 383 // if ( found_roots && ( i >= 0) && ( i < tdg ) ) 384 // { 359 385 // return *theroots[i]; 360 // } 386 // } 361 387 // // warning 362 388 // Werror("rootContainer::getRoot: Wrong index %d, found_roots %s",i,found_roots?"true":"false"); … … 366 392 //<- 367 393 368 //-> gmp_complex & rootContainer::evPointCoord( int i ) 394 //-> gmp_complex & rootContainer::evPointCoord( int i ) 369 395 gmp_complex & rootContainer::evPointCoord( const int i ) 370 396 { 371 397 if (! ((i >= 0) && (i < anz+2) ) ) 372 Werror ("rootContainer::evPointCoord: index out of range");398 WerrorS("rootContainer::evPointCoord: index out of range"); 373 399 if (ievpoint == NULL) 374 Werror ("rootContainer::evPointCoord: ievpoint == NULL");400 WerrorS("rootContainer::evPointCoord: ievpoint == NULL"); 375 401 376 402 if ( (rt == cspecialmu) && found_roots ) { // FIX ME 377 if ( ievpoint[i] != NULL ) { 403 if ( ievpoint[i] != NULL ) 404 { 378 405 gmp_complex *tmp= new gmp_complex(); 379 406 *tmp= numberToGmp_Complex(ievpoint[i]); 380 407 return *tmp; 381 } else { 408 } 409 else 410 { 382 411 Werror("rootContainer::evPointCoord: NULL index %d",i); 383 412 } 384 413 } 385 414 386 415 // warning 387 416 Werror("rootContainer::evPointCoord: Wrong index %d, found_roots %s",i,found_roots?"true":"false"); … … 391 420 //<- 392 421 393 //-> bool rootContainer::changeRoots( int from, int to ) 422 //-> bool rootContainer::changeRoots( int from, int to ) 394 423 bool rootContainer::swapRoots( const int from, const int to ) 395 424 { 396 if ( found_roots && ( from >= 0) && ( from < tdg ) && ( to >= 0) && ( to < tdg ) ) { 397 if ( to != from ) { 425 if ( found_roots && ( from >= 0) && ( from < tdg ) && ( to >= 0) && ( to < tdg ) ) 426 { 427 if ( to != from ) 428 { 398 429 gmp_complex tmp( *theroots[from] ); 399 430 *theroots[from]= *theroots[to]; … … 401 432 } 402 433 return true; 403 } 404 434 } 435 405 436 // warning 406 437 Werror(" rootContainer::changeRoots: Wrong index %d, %d",from,to); … … 409 440 //<- 410 441 411 //-> void rootContainer::solver() 442 //-> void rootContainer::solver() 412 443 bool rootContainer::solver( const int polishmode ) 413 444 { … … 420 451 // copy the coefficients of type number to type gmp_complex 421 452 gmp_complex **ad= (gmp_complex**)Alloc( (tdg+1)*sizeof(gmp_complex*) ); 422 for ( i=0; i <= tdg; i++ ) { 453 for ( i=0; i <= tdg; i++ ) 454 { 423 455 ad[i]= new gmp_complex(); 424 456 if ( coeffs[i] ) *ad[i] = numberToGmp_Complex( coeffs[i] ); … … 426 458 427 459 // now solve 428 switch (polishmode) { 460 switch (polishmode) 461 { 429 462 case PM_NONE: 430 463 case PM_POLISH: 431 464 found_roots= laguer_driver( ad, theroots, polishmode == PM_POLISH ); 432 if (!found_roots) { 433 Werror("rootContainer::solver: No roots found!"); 465 if (!found_roots) 466 { 467 WerrorS("rootContainer::solver: No roots found!"); 434 468 goto solverend; 435 469 } 436 470 break; 437 471 case PM_CORRUPT: 438 found_roots= laguer_driver( ad, theroots, false ); 472 found_roots= laguer_driver( ad, theroots, false ); 439 473 // corrupt the roots 440 474 for ( i= 0; i < tdg; i++ ) 441 475 *theroots[i]= *theroots[i] * (gmp_float)(1.0+0.01*(mprfloat)i); 442 // and interpolate again 476 // and interpolate again 443 477 found_roots= laguer_driver( ad, theroots, true ); 444 if (!found_roots) { 445 Werror("rootContainer::solver: No roots found!"); 478 if (!found_roots) 479 { 480 WerrorS("rootContainer::solver: No roots found!"); 446 481 goto solverend; 447 482 } … … 460 495 //<- 461 496 462 //-> gmp_complex* rootContainer::laguer_driver( bool polish ) 497 //-> gmp_complex* rootContainer::laguer_driver( bool polish ) 463 498 bool rootContainer::laguer_driver(gmp_complex ** a, gmp_complex ** roots, bool polish ) 464 499 { … … 471 506 for ( i=0; i <= tdg; i++ ) ad[i]= new gmp_complex( *a[i] ); 472 507 473 for ( j= tdg; j >= 1; j-- ) { 508 for ( j= tdg; j >= 1; j-- ) 509 { 474 510 x= gmp_complex(); 475 511 … … 479 515 mprSTICKYPROT(ST_ROOTS_LGSTEP); 480 516 if ( its > MAXIT ) { // error 481 Werror ("rootContainer::laguer_driver: To many iterations!");517 WerrorS("rootContainer::laguer_driver: To many iterations!"); 482 518 ret= false; 483 519 goto theend; 484 520 } 485 if ( abs(x.imag()) <= (gmp_float)(2.0*EPS)*abs(x.real())) { 521 if ( abs(x.imag()) <= (gmp_float)(2.0*EPS)*abs(x.real())) 522 { 486 523 x= gmp_complex( x.real() ); 487 524 } 488 525 *roots[j-1]= x; 489 526 b= *ad[j]; 490 for ( jj= j-1; jj >= 0; jj-- ) { 527 for ( jj= j-1; jj >= 0; jj-- ) 528 { 491 529 c= *ad[jj]; 492 530 *ad[jj]= b; … … 495 533 } 496 534 497 if ( polish ) { 535 if ( polish ) 536 { 498 537 mprSTICKYPROT(ST_ROOTS_LGPOLISH); 499 538 for ( i=0; i <= tdg; i++ ) *ad[i]=*a[i]; 500 539 501 for ( j= 1; j <= tdg; j++ ) { 540 for ( j= 1; j <= tdg; j++ ) 541 { 502 542 // run laguer alg with corrupted roots 503 543 laguer( ad, tdg, roots[j-1], &its ); 504 544 505 545 mprSTICKYPROT(ST_ROOTS_LGSTEP); 506 if ( its > MAXIT ) { // error 507 Werror("rootContainer::laguer_driver: To many iterations!"); 508 ret= false; 509 goto theend; 510 } 511 } 512 for ( j= 2; j <= tdg; j++ ) { 546 if ( its > MAXIT ) 547 { // error 548 WerrorS("rootContainer::laguer_driver: To many iterations!"); 549 ret= false; 550 goto theend; 551 } 552 } 553 for ( j= 2; j <= tdg; j++ ) 554 { 513 555 // sort root by their absolute real parts by straight insertion 514 556 x= *roots[j-1]; 515 for ( i= j-1; i >= 1; i-- ) { 516 if ( abs(roots[i-1]->real()) <= abs(x.real()) ) break; 517 *roots[i]= *roots[i-1]; 557 for ( i= j-1; i >= 1; i-- ) 558 { 559 if ( abs(roots[i-1]->real()) <= abs(x.real()) ) break; 560 *roots[i]= *roots[i-1]; 518 561 } 519 562 *roots[i]= x; … … 530 573 //<- 531 574 532 //-> void rootContainer::laguer(...) 575 //-> void rootContainer::laguer(...) 533 576 void rootContainer::laguer(gmp_complex ** a, int m, gmp_complex *x, int *its) 534 577 { … … 540 583 gmp_float epss(1.0/pow(10.0,(int)(gmp_output_digits+gmp_output_digits/4))); 541 584 542 for ( iter= 1; iter <= MAXIT; iter++ ) { 585 for ( iter= 1; iter <= MAXIT; iter++ ) 586 { 543 587 mprSTICKYPROT(ST_ROOTS_LG); 544 588 … … 546 590 547 591 b= *a[m]; 548 err_g= abs(b); 592 err_g= abs(b); 549 593 d= gmp_complex(); 550 594 f= gmp_complex(); 551 abx_g= abs(*x); 552 553 for ( j= m-1; j >= 0; j-- ) { 595 abx_g= abs(*x); 596 597 for ( j= m-1; j >= 0; j-- ) 598 { 554 599 f= ( *x * f ) + d; 555 600 d= ( *x * d ) + b; 556 601 b= ( *x * b ) + *a[j]; 557 err_g= abs( b ) + ( abx_g * err_g ); 602 err_g= abs( b ) + ( abx_g * err_g ); 558 603 } 559 604 560 605 err_g *= epss; // EPSS; 561 606 562 if ( abs(b) <= err_g ) return; 607 if ( abs(b) <= err_g ) return; 563 608 564 609 g= d / b; … … 568 613 gp= g + sq; 569 614 gm= g - sq; 570 abp_g= abs( gp ); 571 abm_g= abs( gm ); 615 abp_g= abs( gp ); 616 abm_g= abs( gm ); 572 617 573 618 if ( abp_g < abm_g ) gp= gm; 574 619 575 dx = ( (max(abp_g,abm_g) > (gmp_float)0.0) 576 ? ( gmp_complex( (mprfloat)m ) / gp ) 577 : ( gmp_complex( cos((mprfloat)iter),sin((mprfloat)iter)) 578 579 620 dx = ( (max(abp_g,abm_g) > (gmp_float)0.0) 621 ? ( gmp_complex( (mprfloat)m ) / gp ) 622 : ( gmp_complex( cos((mprfloat)iter),sin((mprfloat)iter)) 623 * exp(log((gmp_float)1.0+abx_g))) ); 624 580 625 x1= *x - dx; 581 626 … … 596 641 //----------------------------------------------------------------------------- 597 642 598 //-> rootArranger::rootArranger(...) 599 rootArranger::rootArranger( rootContainer ** _roots, 600 rootContainer ** _mu, 601 643 //-> rootArranger::rootArranger(...) 644 rootArranger::rootArranger( rootContainer ** _roots, 645 rootContainer ** _mu, 646 const int _howclean ) 602 647 : roots(_roots), mu(_mu), howclean(_howclean) 603 648 { … … 614 659 // find roots of polys given by coeffs in roots 615 660 rc= roots[0]->getAnzElems(); 616 for ( i= 0; i < rc; i++ ) 617 if ( !roots[i]->solver( howclean ) ) { 661 for ( i= 0; i < rc; i++ ) 662 if ( !roots[i]->solver( howclean ) ) 663 { 618 664 found_roots= false; 619 665 return; … … 621 667 // find roots of polys given by coeffs in mu 622 668 mc= mu[0]->getAnzElems(); 623 for ( i= 0; i < mc; i++ ) 624 if ( ! mu[i]->solver( howclean ) ) { 669 for ( i= 0; i < mc; i++ ) 670 if ( ! mu[i]->solver( howclean ) ) 671 { 625 672 found_roots= false; 626 673 return; … … 629 676 //<- 630 677 631 //-> void rootArranger::arrange() 678 //-> void rootArranger::arrange() 632 679 void rootArranger::arrange() 633 680 { … … 641 688 642 689 for ( xkoord= 0; xkoord < anzm; xkoord++ ) { // für x1,x2, x1,x2,x3, x1,x2,...,xn 643 for ( r= 0; r < anzr; r++ ) { // für jede Nullstelle 644 // (x1-koordinate) * evp[1] + (x2-koordinate) * evp[2] + 690 for ( r= 0; r < anzr; r++ ) { // für jede Nullstelle 691 // (x1-koordinate) * evp[1] + (x2-koordinate) * evp[2] + 645 692 // ... + (xkoord-koordinate) * evp[xkoord] 646 693 tmp= gmp_complex(); 647 for ( xk =0; xk <= xkoord; xk++ ){ 648 tmp -= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1); //xk+1 694 for ( xk =0; xk <= xkoord; xk++ ) 695 { 696 tmp -= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1); //xk+1 649 697 } 650 698 found= false; 651 for ( rtest= r; rtest < anzr; rtest++ ) { // für jede Nullstelle 652 zwerg = tmp - (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xk+1, xkoord+2 653 for ( mtest= 0; mtest < anzr; mtest++ ) { 654 // if ( tmp == (*mu[xkoord])[mtest] ) { 655 if ( ((zwerg.real() <= (*mu[xkoord])[mtest].real() + mprec) && 656 (zwerg.real() >= (*mu[xkoord])[mtest].real() - mprec)) && 657 ((zwerg.imag() <= (*mu[xkoord])[mtest].imag() + mprec) && 658 (zwerg.imag() >= (*mu[xkoord])[mtest].imag() - mprec)) ) { 659 roots[xk]->swapRoots( r, rtest ); 660 found= true; 661 break; 662 } 663 } 699 for ( rtest= r; rtest < anzr; rtest++ ) { // für jede Nullstelle 700 zwerg = tmp - (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xk+1, xkoord+2 701 for ( mtest= 0; mtest < anzr; mtest++ ) 702 { 703 // if ( tmp == (*mu[xkoord])[mtest] ) 704 // { 705 if ( ((zwerg.real() <= (*mu[xkoord])[mtest].real() + mprec) && 706 (zwerg.real() >= (*mu[xkoord])[mtest].real() - mprec)) && 707 ((zwerg.imag() <= (*mu[xkoord])[mtest].imag() + mprec) && 708 (zwerg.imag() >= (*mu[xkoord])[mtest].imag() - mprec)) ) 709 { 710 roots[xk]->swapRoots( r, rtest ); 711 found= true; 712 break; 713 } 714 } 664 715 } // rtest 665 if ( !found ) { 666 Werror("rootArranger::arrange: No match? coord %d, root %d.",xkoord,r); 716 if ( !found ) 717 { 718 Werror("rootArranger::arrange: No match? coord %d, root %d.",xkoord,r); 667 719 #ifdef mprDEBUG_PROT 668 Werror("One of these ..."); 669 for ( rtest= r; rtest < anzr; rtest++ ) { 670 tmp= gmp_complex(); 671 for ( xk =0; xk <= xkoord; xk++ ){ 672 tmp-= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1); 673 } 674 tmp-= (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xkoord+2 675 Werror(" %s",complexToStr(tmp,gmp_output_digits+1),rtest); 676 } 677 Werror(" ... must match to one of these:"); 678 for ( mtest= 0; mtest < anzr; mtest++ ) { 679 Werror(" %s",complexToStr((*mu[xkoord])[mtest],gmp_output_digits+1)); 680 } 720 WerrorS("One of these ..."); 721 for ( rtest= r; rtest < anzr; rtest++ ) 722 { 723 tmp= gmp_complex(); 724 for ( xk =0; xk <= xkoord; xk++ ) 725 { 726 tmp-= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1); 727 } 728 tmp-= (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xkoord+2 729 Werror(" %s",complexToStr(tmp,gmp_output_digits+1),rtest); 730 } 731 WerrorS(" ... must match to one of these:"); 732 for ( mtest= 0; mtest < anzr; mtest++ ) 733 { 734 Werror(" %s",complexToStr((*mu[xkoord])[mtest],gmp_output_digits+1)); 735 } 681 736 #endif 682 737 } … … 686 741 //<- 687 742 688 //-> lists rootArranger::listOfRoots( int oprec ) 743 //-> lists rootArranger::listOfRoots( int oprec ) 689 744 lists rootArranger::listOfRoots( const unsigned int oprec ) 690 745 { … … 695 750 lists listofroots= (lists)Alloc( sizeof(slists) ); // must be done this way! 696 751 697 if ( found_roots ) { 752 if ( found_roots ) 753 { 698 754 listofroots->Init( count ); 699 700 for (i=0; i < count; i++) { 755 756 for (i=0; i < count; i++) 757 { 701 758 lists onepoint= (lists)Alloc(sizeof(slists)); // must be done this way! 702 759 onepoint->Init(elem); 703 for ( j= 0; j < elem; j++ ) { 704 if ( !rField_is_long_C() ) { 705 onepoint->m[j].rtyp=STRING_CMD; 706 onepoint->m[j].data=(void *)complexToStr((*roots[j])[i],oprec); 707 } else { 708 onepoint->m[j].rtyp=NUMBER_CMD; 709 onepoint->m[j].data=(void *)nCopy((number)(roots[j]->getRoot(i))); 710 } 711 onepoint->m[j].next= NULL; 712 onepoint->m[j].name= NULL; 760 for ( j= 0; j < elem; j++ ) 761 { 762 if ( !rField_is_long_C() ) 763 { 764 onepoint->m[j].rtyp=STRING_CMD; 765 onepoint->m[j].data=(void *)complexToStr((*roots[j])[i],oprec); 766 } 767 else 768 { 769 onepoint->m[j].rtyp=NUMBER_CMD; 770 onepoint->m[j].data=(void *)nCopy((number)(roots[j]->getRoot(i))); 771 } 772 onepoint->m[j].next= NULL; 773 onepoint->m[j].name= NULL; 713 774 } 714 775 listofroots->m[i].rtyp=LIST_CMD; … … 718 779 } 719 780 720 } else { 781 } 782 else 783 { 721 784 listofroots->Init( 0 ); 722 785 } … … 743 806 int i,ip,ir,is,k,kh,kp,m12,nl1,nl2; 744 807 int *l1,*l2,*l3; 745 mprfloat q1, bmax; 746 747 if ( m != (m1+m2+m3)) { 808 mprfloat q1, bmax; 809 810 if ( m != (m1+m2+m3)) 811 { 748 812 // error: bad input 749 error(Werror (" bad input constraint counts in simplex ");)813 error(WerrorS(" bad input constraint counts in simplex ");) 750 814 *icase=-2; 751 815 return; … … 759 823 for ( k=1; k<=n; k++ ) l1[k]=izrov[k]=k; 760 824 nl2=m; 761 for ( i=1; i<=m; i++ ) { 762 if ( a[i+1][1] < 0.0 ) { 825 for ( i=1; i<=m; i++ ) 826 { 827 if ( a[i+1][1] < 0.0 ) 828 { 763 829 // error: bad input 764 error(Werror (" bad input tableau in simplex ");)830 error(WerrorS(" bad input tableau in simplex ");) 765 831 *icase=-2; 766 832 // free mem l1,l2,l3; … … 775 841 for ( i=1; i<=m2; i++) l3[i]= 1; 776 842 ir= 0; 777 if (m2+m3) { 843 if (m2+m3) 844 { 778 845 ir=1; 779 for ( k=1; k <= (n+1); k++ ) { 846 for ( k=1; k <= (n+1); k++ ) 847 { 780 848 q1=0.0; 781 849 for ( i=m1+1; i <= m; i++ ) q1+= a[i+1][k]; … … 783 851 } 784 852 785 do { 853 do 854 { 786 855 simp1(a,m+1,l1,nl1,0,&kp,&bmax); 787 if ( bmax <= SIMPLEX_EPS && a[m+2][1] < -SIMPLEX_EPS ) { 788 *icase= -1; // no solution found 789 // free mem l1,l2,l3; 790 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); 791 Free( (ADDRESS) l2, (m+1) * sizeof(int) ); 792 Free( (ADDRESS) l1, (n+1) * sizeof(int) ); 793 return; 794 } else if ( bmax <= SIMPLEX_EPS && a[m+2][1] <= SIMPLEX_EPS ) { 795 m12= m1+m2+1; 796 if ( m12 <= m ) { 797 for ( ip= m12; ip <= m; ip++ ) { 798 if ( iposv[ip] == (ip+n) ) { 799 simp1(a,ip,l1,nl1,1,&kp,&bmax); 800 if ( fabs(bmax) >= SIMPLEX_EPS) 801 goto one; 802 } 803 } 804 } 805 ir= 0; 806 --m12; 807 if ( m1+1 <= m12 ) 808 for ( i=m1+1; i <= m12; i++ ) 809 if ( l3[i-m1] == 1 ) 810 for ( k=1; k <= n+1; k++ ) 811 a[i+1][k] = -a[i+1][k]; 812 break; 856 if ( bmax <= SIMPLEX_EPS && a[m+2][1] < -SIMPLEX_EPS ) 857 { 858 *icase= -1; // no solution found 859 // free mem l1,l2,l3; 860 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); 861 Free( (ADDRESS) l2, (m+1) * sizeof(int) ); 862 Free( (ADDRESS) l1, (n+1) * sizeof(int) ); 863 return; 864 } 865 else if ( bmax <= SIMPLEX_EPS && a[m+2][1] <= SIMPLEX_EPS ) 866 { 867 m12= m1+m2+1; 868 if ( m12 <= m ) 869 { 870 for ( ip= m12; ip <= m; ip++ ) 871 { 872 if ( iposv[ip] == (ip+n) ) 873 { 874 simp1(a,ip,l1,nl1,1,&kp,&bmax); 875 if ( fabs(bmax) >= SIMPLEX_EPS) 876 goto one; 877 } 878 } 879 } 880 ir= 0; 881 --m12; 882 if ( m1+1 <= m12 ) 883 for ( i=m1+1; i <= m12; i++ ) 884 if ( l3[i-m1] == 1 ) 885 for ( k=1; k <= n+1; k++ ) 886 a[i+1][k] = -a[i+1][k]; 887 break; 813 888 } 814 889 //#if DEBUG … … 816 891 //#endif 817 892 simp2(a,n,l2,nl2,&ip,kp,&q1); 818 if ( ip == 0 ) { 819 *icase = -1; // no solution found 820 // free mem l1,l2,l3; 821 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); 822 Free( (ADDRESS) l2, (m+1) * sizeof(int) ); 823 Free( (ADDRESS) l1, (n+1) * sizeof(int) ); 824 return; 893 if ( ip == 0 ) 894 { 895 *icase = -1; // no solution found 896 // free mem l1,l2,l3; 897 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); 898 Free( (ADDRESS) l2, (m+1) * sizeof(int) ); 899 Free( (ADDRESS) l1, (n+1) * sizeof(int) ); 900 return; 825 901 } 826 902 one: simp3(a,m+1,n,ip,kp); … … 828 904 // print_bmat(a,m+2,n+3); 829 905 // #endif 830 if ( iposv[ip] >= (n+m1+m2+1)) { 831 for ( k=1; k<= nl1; k++ ) 832 if ( l1[k] == kp ) break; 833 --nl1; 834 for ( is=k; is <= nl1; is++ ) l1[is]= l1[is+1]; 835 ++a[m+2][kp+1]; 836 for ( i= 1; i <= m+2; i++ ) a[i][kp+1] = -a[i][kp+1]; 837 } else { 838 if ( iposv[ip] >= (n+m1+1) ) { 839 kh= iposv[ip]-m1-n; 840 if ( l3[kh] ) { 841 l3[kh]= 0; 842 ++a[m+2][kp+1]; 843 for ( i=1; i<= m+2; i++ ) 844 a[i][kp+1] = -a[i][kp+1]; 845 } 846 } 906 if ( iposv[ip] >= (n+m1+m2+1)) 907 { 908 for ( k=1; k<= nl1; k++ ) 909 if ( l1[k] == kp ) break; 910 --nl1; 911 for ( is=k; is <= nl1; is++ ) l1[is]= l1[is+1]; 912 ++a[m+2][kp+1]; 913 for ( i= 1; i <= m+2; i++ ) a[i][kp+1] = -a[i][kp+1]; 914 } 915 else 916 { 917 if ( iposv[ip] >= (n+m1+1) ) 918 { 919 kh= iposv[ip]-m1-n; 920 if ( l3[kh] ) 921 { 922 l3[kh]= 0; 923 ++a[m+2][kp+1]; 924 for ( i=1; i<= m+2; i++ ) 925 a[i][kp+1] = -a[i][kp+1]; 926 } 927 } 847 928 } 848 929 is= izrov[kp]; … … 852 933 } 853 934 /* end of phase 1, have feasible sol, now optimize it */ 854 for (;;) { 935 loop 936 { 855 937 // #if DEBUG 856 938 // print_bmat( a, m+1, n+5); 857 939 // #endif 858 940 simp1(a,0,l1,nl1,0,&kp,&bmax); 859 if (bmax <= /*SIMPLEX_EPS*/0.0) { 941 if (bmax <= /*SIMPLEX_EPS*/0.0) 942 { 860 943 *icase=0; // finite solution found 861 944 // free mem l1,l2,l3 … … 866 949 } 867 950 simp2(a,n,l2,nl2,&ip,kp,&q1); 868 if (ip == 0) { 951 if (ip == 0) 952 { 869 953 //printf("Unbounded:"); 870 954 // #if DEBUG 871 955 // print_bmat( a, m+1, n+1); 872 956 // #endif 873 *icase=1; 957 *icase=1; /* unbounded */ 874 958 // free mem 875 959 Free( (ADDRESS) l3, (m+1) * sizeof(int) ); … … 881 965 is= izrov[kp]; 882 966 izrov[kp]= iposv[ip]; 883 iposv[ip]= is; 967 iposv[ip]= is; 884 968 }/*for ;;*/ 885 969 } … … 890 974 mprfloat test; 891 975 892 if( nll <= 0) { /* init'tion: fixed */ 976 if( nll <= 0) 977 { /* init'tion: fixed */ 893 978 *bmax = 0.0; 894 979 return; … … 896 981 *kp=ll[1]; 897 982 *bmax=a[mm+1][*kp+1]; 898 for (k=2;k<=nll;k++) { 899 if (iabf == 0) { 983 for (k=2;k<=nll;k++) 984 { 985 if (iabf == 0) 986 { 900 987 test=a[mm+1][ll[k]+1]-(*bmax); 901 if (test > 0.0) { 902 *bmax=a[mm+1][ll[k]+1]; 903 *kp=ll[k]; 904 } 905 } else { /* abs values: have fixed it */ 988 if (test > 0.0) 989 { 990 *bmax=a[mm+1][ll[k]+1]; 991 *kp=ll[k]; 992 } 993 } 994 else 995 { /* abs values: have fixed it */ 906 996 test=fabs(a[mm+1][ll[k]+1])-fabs(*bmax); 907 if (test > 0.0) { 908 *bmax=a[mm+1][ll[k]+1]; 909 *kp=ll[k]; 997 if (test > 0.0) 998 { 999 *bmax=a[mm+1][ll[k]+1]; 1000 *kp=ll[k]; 910 1001 } 911 1002 } … … 919 1010 920 1011 *ip= 0; 921 for ( i=1; i <= nl2; i++ ) { 922 if ( a[l2[i]+1][kp+1] < -SIMPLEX_EPS ) { 1012 for ( i=1; i <= nl2; i++ ) 1013 { 1014 if ( a[l2[i]+1][kp+1] < -SIMPLEX_EPS ) 1015 { 923 1016 *q1= -a[l2[i]+1][1] / a[l2[i]+1][kp+1]; 924 1017 *ip= l2[i]; 925 for ( i= i+1; i <= nl2; i++ ) { 926 ii= l2[i]; 927 if (a[ii+1][kp+1] < -SIMPLEX_EPS) { 928 q= -a[ii+1][1] / a[ii+1][kp+1]; 929 if (q - *q1 < -SIMPLEX_EPS) { 930 *ip=ii; 931 *q1=q; 932 } else if (q - *q1 < SIMPLEX_EPS) { 933 for ( k=1; k<= n; k++ ) { 934 qp= -a[*ip+1][k+1]/a[*ip+1][kp+1]; 935 q0= -a[ii+1][k+1]/a[ii+1][kp+1]; 936 if ( q0 != qp ) break; 937 } 938 if ( q0 < qp ) *ip= ii; 939 } 940 } 1018 for ( i= i+1; i <= nl2; i++ ) 1019 { 1020 ii= l2[i]; 1021 if (a[ii+1][kp+1] < -SIMPLEX_EPS) 1022 { 1023 q= -a[ii+1][1] / a[ii+1][kp+1]; 1024 if (q - *q1 < -SIMPLEX_EPS) 1025 { 1026 *ip=ii; 1027 *q1=q; 1028 } 1029 else if (q - *q1 < SIMPLEX_EPS) 1030 { 1031 for ( k=1; k<= n; k++ ) 1032 { 1033 qp= -a[*ip+1][k+1]/a[*ip+1][kp+1]; 1034 q0= -a[ii+1][k+1]/a[ii+1][kp+1]; 1035 if ( q0 != qp ) break; 1036 } 1037 if ( q0 < qp ) *ip= ii; 1038 } 1039 } 941 1040 } 942 1041 } … … 950 1049 951 1050 piv= 1.0 / a[ip+1][kp+1]; 952 for ( ii=1; ii <= i1+1; ii++ ) 953 if ( ii -1 != ip ) { 1051 for ( ii=1; ii <= i1+1; ii++ ) 1052 { 1053 if ( ii -1 != ip ) 1054 { 954 1055 a[ii][kp+1] *= piv; 955 for ( kk=1; kk <= k1+1; kk++ ) 956 if ( kk-1 != kp ) 957 a[ii][kk] -= a[ip+1][kk] * a[ii][kp+1]; 958 } 959 for ( kk=1; kk<= k1+1; kk++ ) 1056 for ( kk=1; kk <= k1+1; kk++ ) 1057 if ( kk-1 != kp ) 1058 a[ii][kk] -= a[ip+1][kk] * a[ii][kp+1]; 1059 } 1060 } 1061 for ( kk=1; kk<= k1+1; kk++ ) 960 1062 if ( kk-1 != kp ) a[ip+1][kk] *= -piv; 961 1063 a[ip+1][kp+1]= piv; … … 972 1074 // compile-command-2: "make install" *** 973 1075 // End: *** 974 975 976 -
Singular/mpr_numeric.h
r0f5091 re858e7 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_numeric.h,v 1. 1 1999-06-28 12:48:16 wenkExp $ */6 /* $Id: mpr_numeric.h,v 1.2 1999-06-28 16:06:30 Singular Exp $ */ 7 7 8 /* 8 /* 9 9 * ABSTRACT - multipolynomial resultants - numeric stuff 10 * ( root finder, vandermonde system solver, simplex ) 10 * ( root finder, vandermonde system solver, simplex ) 11 11 */ 12 12 … … 17 17 18 18 // define polish mode when finding roots 19 #define PM_NONE 1 19 #define PM_NONE 1 20 20 #define PM_POLISH 2 21 21 #define PM_CORRUPT 3 … … 29 29 { 30 30 public: 31 vandermonde( const long _cn, const long _n, 31 vandermonde( const long _cn, const long _n, 32 32 const long _maxdeg, number *_p, const bool _homog = true ); 33 33 ~vandermonde(); 34 35 /** Solves the Vandermode linear system 36 * \sum_{i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n. 34 35 /** Solves the Vandermode linear system 36 * \sum_{i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n. 37 37 * Any computations are done using type number to get high pecision results. 38 38 * @param q n-tuple of results (right hand of equations) … … 71 71 ~rootContainer(); 72 72 73 void fillContainer( number *_coeffs, number *_ievpoint, 74 const int _var, const int _tdg, 73 void fillContainer( number *_coeffs, number *_ievpoint, 74 const int _var, const int _tdg, 75 75 const rootType _rt, const int _anz ); 76 76 … … 98 98 rootContainer( const rootContainer & v ); 99 99 100 /** Given the degree tdg and the tdg+1 complex coefficients ad[0..tdg] 100 /** Given the degree tdg and the tdg+1 complex coefficients ad[0..tdg] 101 101 * (generated from the number coefficients coeffs[0..tdg]) of the polynomial 102 * this routine successively calls "laguer" and finds all m complex roots in 102 * this routine successively calls "laguer" and finds all m complex roots in 103 103 * roots[0..tdg]. The bool var "polish" should be input as "true" if polishing 104 104 * (also by "laguer") is desired, "false" if the roots will be subsequently … … 114 114 */ 115 115 void laguer(gmp_complex ** a, int m, gmp_complex * x, int * its); 116 116 117 117 int var; 118 118 int tdg; … … 123 123 124 124 gmp_complex ** theroots; 125 125 126 126 int anz; 127 127 bool found_roots; … … 130 130 131 131 //-> class rootArranger 132 class rootArranger 132 class rootArranger 133 133 { 134 public: 135 rootArranger( rootContainer ** _roots, 136 rootContainer ** _mu, 134 public: 135 rootArranger( rootContainer ** _roots, 136 rootContainer ** _mu, 137 137 const int _howclean = PM_CORRUPT ); 138 138 ~rootArranger() {} … … 170 170 // compile-command-1: "make installg" *** 171 171 // compile-command-2: "make install" *** 172 // End: *** 173 174 175 172 // End: *** -
Singular/pcv.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: pcv.cc,v 1.2 5 1999-06-11 17:13:40 mschulzeExp $ */4 /* $Id: pcv.cc,v 1.26 1999-06-28 16:06:30 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: conversion between polys and coef vectors … … 41 41 l0->m[i].data=pCopy((poly)l1->m[i].data); 42 42 if(i<=l2->nr&&l2->m[i].rtyp==l1->m[i].rtyp) 43 l0->m[i].data=pAdd( l0->m[i].data,pCopy((poly)l2->m[i].data));43 l0->m[i].data=pAdd((poly)l0->m[i].data,pCopy((poly)l2->m[i].data)); 44 44 } 45 45 else … … 231 231 { 232 232 k=j; 233 for(j=0; j<pcvMaxDegree&&pcvIndex[i][j]<=n;j++);233 for(j=0; (j<pcvMaxDegree) && (pcvIndex[i][j]<=(unsigned)n); j++); 234 234 j--; 235 235 n-=pcvIndex[i][j]; -
Singular/shortfl.cc
r0f5091 re858e7 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: shortfl.cc,v 1. 8 1999-05-10 15:10:55Singular Exp $ */4 /* $Id: shortfl.cc,v 1.9 1999-06-28 16:06:31 Singular Exp $ */ 5 5 6 6 /* … … 339 339 if(i>4) 340 340 { 341 Werror ("float overflow");341 WerrorS("float overflow"); 342 342 return nf(rr).N(); 343 343 } … … 369 369 { 370 370 if(j==s) 371 Werror ("float overflow");371 WerrorS("float overflow"); 372 372 return nf(rr).N(); 373 373 } … … 382 382 MPZ_CLEAR(g); 383 383 if(j==s) 384 Werror ("float overflow");384 WerrorS("float overflow"); 385 385 return nf(rr).N(); 386 386 }
Note: See TracChangeset
for help on using the changeset viewer.