Changeset 5d9aa6 in git
- Timestamp:
- Apr 13, 2011, 8:49:42 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
- Children:
- 503a31399a9b66dd3306a8251a9a5042a4509f5c
- Parents:
- 0a3a629f65533731dfccd53a13103d906918010b
- git-author:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-04-13 20:49:42+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:12:33+01:00
- Location:
- libpolys/polys
- Files:
-
- 3 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/Makefile.am
r0a3a629 r5d9aa6 36 36 pDebug.cc pInline0.cc polys0.cc prCopy.cc \ 37 37 kbuckets.cc sbuckets.cc ${USE_P_PROCS_STATIC_CC} ${USE_P_PROCS_DYNAMIC_CC} weight.cc \ 38 simpleideals.cc matpol.cc 38 simpleideals.cc matpol.cc sparsmat.cc 39 39 40 40 BUILT_SOURCES = templates/p_Procs.inc … … 44 44 include_HEADERS = \ 45 45 monomials/ring.h nc/nc.h \ 46 nc/sca.h nc/summator.h nc/ncSAFormula.h nc/ncSACache.h nc/ncSAMult.h \ 46 47 pInline0.h operations/pShallowCopyDelete.h \ 47 48 templates/p_MemAdd.h templates/p_MemCmp.h templates/p_MemCopy.h operations/p_Mult_q.h \ … … 49 50 templates/p_Procs_Dynamic.h templates/p_Procs_Impl.h templates/p_Procs_Set.h templates/p_Procs_Static.h \ 50 51 monomials/p_polys.h monomials/polys-impl.h monomials/maps.h polys.h prCopy.h prCopyMacros.h \ 51 kbuckets.h sbuckets.h simpleideals.h weight.h 52 kbuckets.h sbuckets.h simpleideals.h weight.h \ 53 matpol.h sparsmat.h 52 54 53 55 P_PROCS_CPPFLAGS_COMMON = -DHAVE_CONFIG_H -DDYNAMIC_VERSION -
libpolys/polys/matpol.cc
r0a3a629 r5d9aa6 37 37 #include "prCopy.h" 38 38 39 #include "sparsmat.h" 40 39 41 //omBin ip_smatrix_bin = omGetSpecBin(sizeof(ip_smatrix)); 40 42 #define ip_smatrix_bin sip_sideal_bin … … 45 47 static void mpReplace(int j, int n, int &sign, int *perm); 46 48 static int mpNextperm(perm * z, int max); 47 static poly mpLeibnitz(matrix a); 48 static poly minuscopy (poly p); 49 static poly pInsert(poly p1, poly p2); 50 static poly mpExdiv ( poly m, poly d, poly vars); 51 static poly mpSelect (poly fro, poly what); 52 53 static void mpPartClean(matrix, int, int); 54 static void mpFinalClean(matrix); 55 static int mpPrepareRow (matrix, int, int); 56 static int mpPreparePiv (matrix, int, int); 57 static int mpPivBar(matrix, int, int); 58 static int mpPivRow(matrix, int, int); 59 static float mpPolyWeight(poly); 60 static void mpSwapRow(matrix, int, int, int); 61 static void mpSwapCol(matrix, int, int, int); 62 static void mpElimBar(matrix, matrix, poly, int, int); 63 64 /*2 65 * create a r x c zero-matrix 66 */ 49 static poly mp_Leibnitz(matrix a, const ring); 50 static poly minuscopy (poly p, const ring); 51 static poly p_Insert(poly p1, poly p2, const ring); 52 static poly mp_Exdiv ( poly m, poly d, poly vars, const ring); 53 static poly mp_Select (poly fro, poly what, const ring); 54 55 static void mp_PartClean(matrix, int, int, const ring); 56 static void mp_FinalClean(matrix, const ring); 57 static int mp_PrepareRow (matrix, int, int, const ring); 58 static int mp_PreparePiv (matrix, int, int, const ring); 59 static int mp_PivBar(matrix, int, int, const ring); 60 static int mp_PivRow(matrix, int, int, const ring); 61 static float mp_PolyWeight(poly, const ring); 62 static void mp_SwapRow(matrix, int, int, int, const ring); 63 static void mp_SwapCol(matrix, int, int, int, const ring); 64 static void mp_ElimBar(matrix, matrix, poly, int, int, const ring); 65 66 /// create a r x c zero-matrix 67 67 matrix mpNew(int r, int c) 68 68 { … … 80 80 { 81 81 int s=r*c*sizeof(poly); 82 rc->m = (poly set)omAlloc0(s);82 rc->m = (poly*)omAlloc0(s); 83 83 //if (rc->m==NULL) 84 84 //{ … … 90 90 } 91 91 92 /// copies matrix a to b93 matrix mp Copy (matrix a, const ring r)94 { 95 id Test((ideal)a);92 /// copies matrix a (from ring r to r) 93 matrix mp_Copy (matrix a, const ring r) 94 { 95 id_Test((ideal)a, r); 96 96 poly t; 97 97 int i, m=MATROWS(a), n=MATCOLS(a); … … 103 103 if (t!=NULL) 104 104 { 105 p Normalize(t);106 b->m[i] = p Copy(t);105 p_Normalize(t, r); 106 b->m[i] = p_Copy(t, r); 107 107 } 108 108 } … … 111 111 } 112 112 113 /*2 114 *copies matrix a from rSrc into rDst 115 */ 116 matrix mpCopy(const matrix a, const ring rSrc, const ring rDst) 117 { 118 const ring save = currRing; 119 120 #ifndef NDEBUG 121 if( currRing != rSrc ) 122 rChangeCurrRing(rSrc); 123 idTest((ideal)a); 124 #endif 113 /// copies matrix a from rSrc into rDst 114 matrix mp_Copy(const matrix a, const ring rSrc, const ring rDst) 115 { 116 id_Test((ideal)a, rSrc); 125 117 126 118 poly t; … … 140 132 b->rank=a->rank; 141 133 142 #ifndef NDEBUG 143 if( currRing != rDst ) 144 rChangeCurrRing(rDst); 145 idTest((ideal)b); 146 #endif 147 148 if( save != currRing ) 149 rChangeCurrRing(save); 134 id_Test((ideal)b, rDst); 150 135 151 136 return b; … … 154 139 155 140 156 /*2 157 * make it a p * unit matrix 158 */ 159 matrix mpInitP(int r, int c, poly p) 141 /// make it a p * unit matrix 142 matrix mp_InitP(int r, int c, poly p, const ring _R) 160 143 { 161 144 matrix rc = mpNew(r,c); 162 145 int i=si_min(r,c), n = c*(i-1)+i-1, inc = c+1; 163 146 164 p Normalize(p);147 p_Normalize(p, _R); 165 148 while (n>0) 166 149 { 167 rc->m[n] = p Copy(p);150 rc->m[n] = p_Copy(p, _R); 168 151 n -= inc; 169 152 } … … 172 155 } 173 156 174 /*2 175 * make it a v * unit matrix 176 */ 177 matrix mpInitI(int r, int c, int v) 178 { 179 return mpInitP(r,c,pISet(v)); 180 } 181 182 /*2 183 * c = f*a 184 */ 185 matrix mpMultI(matrix a, int f) 157 /// make it a v * unit matrix 158 matrix mp_InitI(int r, int c, int v, const ring R) 159 { 160 return mp_InitP(r, c, p_ISet(v, R), R); 161 } 162 163 /// c = f*a 164 matrix mp_MultI(matrix a, int f, const ring R) 186 165 { 187 166 int k, n = a->nrows, m = a->ncols; 188 poly p = p ISet(f);167 poly p = p_ISet(f, R); 189 168 matrix c = mpNew(n,m); 190 169 191 170 for (k=m*n-1; k>0; k--) 192 c->m[k] = pp Mult_qq(a->m[k], p);193 c->m[0] = p Mult(pCopy(a->m[0]), p);171 c->m[k] = pp_Mult_qq(a->m[k], p, R); 172 c->m[0] = p_Mult_q(p_Copy(a->m[0], R), p, R); 194 173 return c; 195 174 } 196 175 197 /*2 198 * multiply a matrix 'a' by a poly 'p', destroy the args 199 */ 200 matrix mpMultP(matrix a, poly p) 176 /// multiply a matrix 'a' by a poly 'p', destroy the args 177 matrix mp_MultP(matrix a, poly p, const ring R) 201 178 { 202 179 int k, n = a->nrows, m = a->ncols; 203 180 204 p Normalize(p);181 p_Normalize(p, R); 205 182 for (k=m*n-1; k>0; k--) 206 183 { 207 184 if (a->m[k]!=NULL) 208 a->m[k] = p Mult(a->m[k], pCopy(p));209 } 210 a->m[0] = p Mult(a->m[0], p);185 a->m[k] = p_Mult_q(a->m[k], p_Copy(p, R), R); 186 } 187 a->m[0] = p_Mult_q(a->m[0], p, R); 211 188 return a; 212 189 } … … 215 192 * multiply a poly 'p' by a matrix 'a', destroy the args 216 193 */ 217 matrix pMultMp(poly p, matrix a )194 matrix pMultMp(poly p, matrix a, const ring R) 218 195 { 219 196 int k, n = a->nrows, m = a->ncols; 220 197 221 p Normalize(p);198 p_Normalize(p, R); 222 199 for (k=m*n-1; k>0; k--) 223 200 { 224 201 if (a->m[k]!=NULL) 225 a->m[k] = p Mult(pCopy(p), a->m[k]);226 } 227 a->m[0] = p Mult(p, a->m[0]);202 a->m[k] = p_Mult_q(p_Copy(p, R), a->m[k], R); 203 } 204 a->m[0] = p_Mult_q(p, a->m[0], R); 228 205 return a; 229 206 } 230 207 231 matrix mp Add(matrix a, matrix b)208 matrix mp_Add(matrix a, matrix b, const ring R) 232 209 { 233 210 int k, n = a->nrows, m = a->ncols; … … 242 219 matrix c = mpNew(n,m); 243 220 for (k=m*n-1; k>=0; k--) 244 c->m[k] = p Add(pCopy(a->m[k]), pCopy(b->m[k]));221 c->m[k] = p_Add_q(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R); 245 222 return c; 246 223 } 247 224 248 matrix mp Sub(matrix a, matrix b)225 matrix mp_Sub(matrix a, matrix b, const ring R) 249 226 { 250 227 int k, n = a->nrows, m = a->ncols; … … 259 236 matrix c = mpNew(n,m); 260 237 for (k=m*n-1; k>=0; k--) 261 c->m[k] = p Sub(pCopy(a->m[k]), pCopy(b->m[k]));238 c->m[k] = p_Sub(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R); 262 239 return c; 263 240 } 264 241 265 matrix mp Mult(matrix a, matrix b)242 matrix mp_Mult(matrix a, matrix b, const ring R) 266 243 { 267 244 int i, j, k; … … 293 270 { 294 271 poly *cij=&(MATELEM(c,i,j)); 295 poly s = pp Mult_qq(aik /*MATELEM(a,i,k)*/, bkj/*MATELEM(b,k,j)*/);272 poly s = pp_Mult_qq(aik /*MATELEM(a,i,k)*/, bkj/*MATELEM(b,k,j)*/, R); 296 273 if (/*MATELEM(c,i,j)*/ (*cij)==NULL) (*cij)=s; 297 else (*cij) = p Add((*cij) /*MATELEM(c,i,j)*/ ,s);274 else (*cij) = p_Add_q((*cij) /*MATELEM(c,i,j)*/ ,s, R); 298 275 } 299 276 } … … 303 280 } 304 281 } 305 for(i=m*q-1;i>=0;i--) p Normalize(c->m[i]);282 for(i=m*q-1;i>=0;i--) p_Normalize(c->m[i], R); 306 283 return c; 307 284 } 308 285 309 matrix mp Transp(matrix a)286 matrix mp_Transp(matrix a, const ring R) 310 287 { 311 288 int i, j, r = MATROWS(a), c = MATCOLS(a); … … 318 295 for (j=0; j<r; j++) 319 296 { 320 if (a->m[j*c+i]!=NULL) *p = p Copy(a->m[j*c+i]);297 if (a->m[j*c+i]!=NULL) *p = p_Copy(a->m[j*c+i], R); 321 298 p++; 322 299 } … … 328 305 *returns the trace of matrix a 329 306 */ 330 poly mp Trace ( matrix a)307 poly mp_Trace ( matrix a, const ring R) 331 308 { 332 309 int i; … … 335 312 336 313 for (i=1; i<=n; i++) 337 t = p Add(t, pCopy(MATELEM(a,i,i)));314 t = p_Add_q(t, p_Copy(MATELEM(a,i,i), R), R); 338 315 return t; 339 316 } … … 342 319 *returns the trace of the product of a and b 343 320 */ 344 poly TraceOfProd ( matrix a, matrix b, int n )321 poly TraceOfProd ( matrix a, matrix b, int n, const ring _R) 345 322 { 346 323 int i, j; … … 351 328 for (j=1; j<=n; j++) 352 329 { 353 p = pp Mult_qq(MATELEM(a,i,j), MATELEM(b,j,i));354 t = p Add(t, p);330 p = pp_Mult_qq(MATELEM(a,i,j), MATELEM(b,j,i), _R); 331 t = p_Add_q(t, p, _R); 355 332 } 356 333 } … … 388 365 int *qrow, *qcol; 389 366 poly *Xarray; 367 ring _R; 368 390 369 void mpInitMat(); 391 370 poly * mpRowAdr(int); … … 396 375 void mpColSwap(int, int); 397 376 public: 398 mp_permmatrix() : a_m(0) {}399 mp_permmatrix(matrix );377 mp_permmatrix() : a_m(0), _R(NULL) {} 378 mp_permmatrix(matrix, const ring); 400 379 mp_permmatrix(mp_permmatrix *); 401 380 ~mp_permmatrix(); … … 421 400 #define SIZE_OF_SYSTEM_PAGE 4096 422 401 #endif 423 /*2 424 * entries of a are minors and go to result (only if not in R) 425 */ 426 void mp MinorToResult(ideal result, int &elems, matrix a, int r, int c,427 ideal R )402 403 /* 404 /// entries of a are minors and go to result (only if not in R) 405 void mp_MinorToResult(ideal result, int &elems, matrix a, int r, int c, 406 ideal R, const ring _R) 428 407 { 429 408 poly *q1; … … 471 450 } 472 451 473 /*2 474 * produces recursively the ideal of all arxar-minors of a 475 */ 476 void mpRecMin(int ar,ideal result,int &elems,matrix a,int lr,int lc, 477 poly barDiv, ideal R) 452 /// produces recursively the ideal of all arxar-minors of a 453 void mp_RecMin(int ar,ideal result,int &elems,matrix a,int lr,int lc, 454 poly barDiv, ideal R, const ring _R) 478 455 { 479 456 int k; … … 483 460 loop 484 461 { 485 / *--- look for an optimal row and bring it to last position ------------*/462 // --- look for an optimal row and bring it to last position ------------ 486 463 if(mpPrepareRow(a,lr,lc)==0) break; 487 / *--- now take all pivots from the last row ------------*/464 // --- now take all pivots from the last row ------------ 488 465 k = lc; 489 466 loop … … 501 478 } 502 479 if (ar>=kr) break; 503 / *--- now we have to take out the last row...------------*/480 // --- now we have to take out the last row...------------ 504 481 lr = kr; 505 482 kr--; … … 507 484 mpFinalClean(nextLevel); 508 485 } 486 */ 487 509 488 510 489 /*2 … … 512 491 *uses Bareiss algorithm 513 492 */ 514 poly mp DetBareiss (matrix a)493 poly mp_DetBareiss (matrix a, const ring R) 515 494 { 516 495 int s; … … 521 500 return NULL; 522 501 } 523 matrix c = mp Copy(a);524 mp_permmatrix *Bareiss = new mp_permmatrix(c );502 matrix c = mp_Copy(a, R); 503 mp_permmatrix *Bareiss = new mp_permmatrix(c, R); 525 504 row_col_weight w(Bareiss->mpGetRdim(), Bareiss->mpGetCdim()); 526 505 … … 541 520 res = MATELEM(c,1,1); 542 521 MATELEM(c,1,1) = NULL; 543 id Delete((ideal *)&c);522 id_Delete((ideal *)&c, R); 544 523 if (s < 0) 545 res = p Neg(res);524 res = p_Neg(res, R); 546 525 return res; 547 526 } … … 551 530 *uses Newtons formulea for symmetric functions 552 531 */ 553 poly mp Det (matrix m)532 poly mp_Det (matrix m, const ring R) 554 533 { 555 534 int i,j,k,n; … … 565 544 return NULL; 566 545 } 567 k=rChar( );546 k=rChar(R); 568 547 if ((k > 0) && (k <= n)) 569 return mp Leibnitz(m);570 ONE = n Init(1);571 ma[1]=mp Copy(m);548 return mp_Leibnitz(m, R); 549 ONE = n_Init(1, R); 550 ma[1]=mp_Copy(m, R); 572 551 k = (n+1) / 2; 573 552 s = mpNew(1, n); 574 MATELEM(s,1,1) = mp Trace(m);553 MATELEM(s,1,1) = mp_Trace(m, R); 575 554 for (i=2; i<=k; i++) 576 555 { 577 556 //ma[i] = mpNew(n,n); 578 ma[i]=mp Mult(ma[i-1], ma[1]);579 MATELEM(s,1,i) = mp Trace(ma[i]);580 p Test(MATELEM(s,1,i));557 ma[i]=mp_Mult(ma[i-1], ma[1], R); 558 MATELEM(s,1,i) = mp_Trace(ma[i], R); 559 p_Test(MATELEM(s,1,i), R); 581 560 } 582 561 for (i=k+1; i<=n; i++) 583 562 { 584 MATELEM(s,1,i) = TraceOfProd(ma[i / 2], ma[(i+1) / 2], n );585 p Test(MATELEM(s,1,i));563 MATELEM(s,1,i) = TraceOfProd(ma[i / 2], ma[(i+1) / 2], n, R); 564 p_Test(MATELEM(s,1,i), R); 586 565 } 587 566 for (i=1; i<=k; i++) 588 id Delete((ideal *)&(ma[i]));567 id_Delete((ideal *)&(ma[i]), R); 589 568 /* the array s contains the traces of the powers of the matrix m, 590 569 * these are the power sums of the eigenvalues of m */ 591 570 a = mpNew(1,n); 592 MATELEM(a,1,1) = minuscopy(MATELEM(s,1,1) );571 MATELEM(a,1,1) = minuscopy(MATELEM(s,1,1), R); 593 572 for (i=2; i<=n; i++) 594 573 { 595 p = p Copy(MATELEM(s,1,i));574 p = p_Copy(MATELEM(s,1,i), R); 596 575 for (j=i-1; j>=1; j--) 597 576 { 598 q = pp Mult_qq(MATELEM(s,1,j), MATELEM(a,1,i-j));599 p Test(q);600 p = p Add(p,q);577 q = pp_Mult_qq(MATELEM(s,1,j), MATELEM(a,1,i-j), R); 578 p_Test(q, R); 579 p = p_Add_q(p,q, R); 601 580 } 602 581 // c= -1/i 603 d = n Init(-(int)i);604 c = n Div(ONE, d);605 n Delete(&d);606 607 p Mult_nn(p, c);608 p Test(p);582 d = n_Init(-(int)i, R); 583 c = n_Div(ONE, d, R); 584 n_Delete(&d, R); 585 586 p_Mult_nn(p, c, R); 587 p_Test(p, R); 609 588 MATELEM(a,1,i) = p; 610 n Delete(&c);589 n_Delete(&c, R); 611 590 } 612 591 /* the array a contains the elementary symmetric functions of the … … 614 593 for (i=1; i<=n-1; i++) 615 594 { 616 //p Delete(&(MATELEM(a,1,i)));617 p Delete(&(MATELEM(s,1,i)));618 } 619 p Delete(&(MATELEM(s,1,n)));595 //p_Delete(&(MATELEM(a,1,i)), R); 596 p_Delete(&(MATELEM(s,1,i)), R); 597 } 598 p_Delete(&(MATELEM(s,1,n)), R); 620 599 /* up to a sign, the determinant is the n-th elementary symmetric function */ 621 600 if ((n/2)*2 < n) 622 601 { 623 d = n Init(-1);624 p Mult_nn(MATELEM(a,1,n), d);625 n Delete(&d);626 } 627 n Delete(&ONE);628 id Delete((ideal *)&s);602 d = n_Init(-1, R); 603 p_Mult_nn(MATELEM(a,1,n), d, R); 604 n_Delete(&d, R); 605 } 606 n_Delete(&ONE, R); 607 id_Delete((ideal *)&s, R); 629 608 poly result=MATELEM(a,1,n); 630 609 MATELEM(a,1,n)=NULL; 631 id Delete((ideal *)&a);610 id_Delete((ideal *)&a, R); 632 611 return result; 633 612 } … … 636 615 * compute all ar-minors of the matrix a 637 616 */ 638 matrix mp Wedge(matrix a, int ar)617 matrix mp_Wedge(matrix a, int ar, const ring R) 639 618 { 640 619 int i,j,k,l; … … 699 678 // { 700 679 // p=pHomogen(MATELEM(a,i,j),v); 701 // p Delete(&(MATELEM(a,i,j)));680 // p_Delete(&(MATELEM(a,i,j)), ?); 702 681 // MATELEM(a,i,j)=p; 703 682 // } … … 710 689 * var has to be the number of a variable 711 690 */ 712 matrix mp Coeffs (ideal I, int var)691 matrix mp_Coeffs (ideal I, int var, const ring R) 713 692 { 714 693 poly h,f; … … 721 700 while (f!=NULL) 722 701 { 723 l=p GetExp(f,var);702 l=p_GetExp(f,var, R); 724 703 if (l>m) m=l; 725 704 pIter(f); … … 735 714 while (f!=NULL) 736 715 { 737 l=p GetExp(f,var);738 p SetExp(f,var,0);739 c=si_max((int)p GetComp(f),1);740 p SetComp(f,0);741 p Setm(f);716 l=p_GetExp(f,var, R); 717 p_SetExp(f,var,0, R); 718 c=si_max((int)p_GetComp(f, R),1); 719 p_SetComp(f,0, R); 720 p_Setm(f, R); 742 721 /* now add the resulting monomial to co*/ 743 722 h=pNext(f); 744 723 pNext(f)=NULL; 745 724 //MATELEM(co,c*(m+1)-l,i+1) 746 // =p Add(MATELEM(co,c*(m+1)-l,i+1),f);725 // =p_Add_q(MATELEM(co,c*(m+1)-l,i+1),f, R); 747 726 MATELEM(co,(c-1)*(m+1)+l+1,i+1) 748 =p Add(MATELEM(co,(c-1)*(m+1)+l+1,i+1),f);727 =p_Add_q(MATELEM(co,(c-1)*(m+1)+l+1,i+1),f, R); 749 728 /* iterate f*/ 750 729 f=h; 751 730 } 752 731 } 753 id Delete(&I);732 id_Delete(&I, R); 754 733 return co; 755 734 } … … 760 739 * build the matrix of the corresponding monomials in m 761 740 */ 762 void mp Monomials(matrix c, int r, int var, matrix m)741 void mp_Monomials(matrix c, int r, int var, matrix m, const ring R) 763 742 { 764 743 /* clear contents of m*/ … … 768 747 for(l=MATCOLS(m);l>0;l--) 769 748 { 770 p Delete(&MATELEM(m,k,l));749 p_Delete(&MATELEM(m,k,l), R); 771 750 } 772 751 } … … 780 759 int p=MATCOLS(m)/r-1; 781 760 /* fill in the powers of x_var=h*/ 782 poly h=p One();761 poly h=p_One(R); 783 762 for(k=r;k>0; k--) 784 763 { 785 MATELEM(m,k,k*(p+1))=p One();764 MATELEM(m,k,k*(p+1))=p_One(R); 786 765 } 787 766 for(l=p;l>=0; l--) … … 791 770 for(k=r;k>0; k--) 792 771 { 793 MATELEM(m,k,k*(p+1)-l)=p Copy(h);794 } 795 } 796 p Delete(&h);797 } 798 799 matrix mp CoeffProc (poly f, poly vars)772 MATELEM(m,k,k*(p+1)-l)=p_Copy(h, R); 773 } 774 } 775 p_Delete(&h), R; 776 } 777 778 matrix mp_CoeffProc (poly f, poly vars, const ring R) 800 779 { 801 780 assume(vars!=NULL); … … 808 787 { 809 788 co = mpNew(2, 1); 810 MATELEM(co,1,1) = p One();789 MATELEM(co,1,1) = p_One(R); 811 790 MATELEM(co,2,1) = NULL; 812 791 return co; … … 849 828 if (h!=NULL) 850 829 { 851 MATELEM(co,2,i) = p Add(MATELEM(co,2,i), h);830 MATELEM(co,2,i) = p_Add_q(MATELEM(co,2,i), h, R); 852 831 break; 853 832 } … … 861 840 if (h!=NULL) 862 841 { 863 MATELEM(co,2,pos_of_1) = p Add(MATELEM(co,2,pos_of_1), h);842 MATELEM(co,2,pos_of_1) = p_Add_q(MATELEM(co,2,pos_of_1), h, R); 864 843 } 865 844 } … … 878 857 * consider all variables in vars 879 858 */ 880 static poly mp Exdiv ( poly m, poly d, poly vars)859 static poly mp_Exdiv ( poly m, poly d, poly vars, const ring _R) 881 860 { 882 861 int i; … … 888 867 if (pGetExp(d,i) != pGetExp(h,i)) 889 868 { 890 p Delete(&h);869 p_Delete(&h, _R); 891 870 return NULL; 892 871 } … … 898 877 } 899 878 900 void mp Coef2(poly v, poly mon, matrix *c, matrix *m)879 void mp_Coef2(poly v, poly mon, matrix *c, matrix *m, const ring _R) 901 880 { 902 881 polyset s; … … 947 926 { 948 927 pSetComp(h,0); 949 MATELEM(*c,j,i) = p Add(MATELEM(*c,j,i), h);928 MATELEM(*c,j,i) = p_Add_q(MATELEM(*c,j,i), h, _R); 950 929 break; 951 930 } … … 961 940 962 941 963 BOOLEAN mp Equal(matrix a, matrix b)942 BOOLEAN mp_Equal(matrix a, matrix b, const ring _R) 964 943 { 965 944 if ((MATCOLS(a)!=MATCOLS(b)) || (MATROWS(a)!=MATROWS(b))) … … 974 953 else 975 954 if (b->m[i]==NULL) return FALSE; 976 else if (p Cmp(a->m[i],b->m[i])!=0) return FALSE;955 else if (p_Cmp(a->m[i],b->m[i], _R)!=0) return FALSE; 977 956 i--; 978 957 } … … 981 960 { 982 961 #if 0 983 poly tt=p Sub(pCopy(a->m[i]),pCopy(b->m[i]));962 poly tt=p_Sub(p_Copy(a->m[i], _R),p_Copy(b->m[i], _R), _R); 984 963 if (tt!=NULL) 985 964 { 986 p Delete(&tt);965 p_Delete(&tt, _R); 987 966 return FALSE; 988 967 } 989 968 #else 990 if(!p EqualPolys(a->m[i],b->m[i])) return FALSE;969 if(!p_EqualPolys(a->m[i],b->m[i], _R)) return FALSE; 991 970 #endif 992 971 i--; … … 1014 993 } 1015 994 1016 mp_permmatrix::mp_permmatrix(matrix A ) : sign(1)995 mp_permmatrix::mp_permmatrix(matrix A, const ring r) : sign(1), _R(r) 1017 996 { 1018 997 a_m = A->nrows; … … 1030 1009 a_n = M->s_n; 1031 1010 sign = M->sign; 1011 _R = M->_R; 1012 1032 1013 this->mpInitMat(); 1033 1014 Xarray = (poly *)omAlloc0(a_m*a_n*sizeof(poly)); … … 1058 1039 { 1059 1040 for (k=a_m*a_n-1; k>=0; k--) 1060 p Delete(&Xarray[k]);1041 p_Delete(&Xarray[k], _R); 1061 1042 omFreeSize((ADDRESS)Xarray,a_m*a_n*sizeof(poly)); 1062 1043 } … … 1086 1067 void mp_permmatrix::mpDelElem(int r, int c) 1087 1068 { 1088 p Delete(&Xarray[a_n*qrow[r]+qcol[c]]);1069 p_Delete(&Xarray[a_n*qrow[r]+qcol[c]], _R); 1089 1070 } 1090 1071 … … 1116 1097 { 1117 1098 q1 = SM_MULT(a[jj], piv, div); 1118 p Delete(&a[jj]);1119 q2 = p Add(q2, q1);1099 p_Delete(&a[jj]), _R; 1100 q2 = p_Add_q(q2, q1, _R); 1120 1101 } 1121 1102 } … … 1128 1109 a[jj] = q2; 1129 1110 } 1130 p Delete(&a[qcol[s_n]]);1111 p_Delete(&a[qcol[s_n]], _R); 1131 1112 } 1132 1113 else … … 1138 1119 { 1139 1120 q2 = SM_MULT(a[jj], piv, div); 1140 p Delete(&a[jj]);1121 p_Delete(&a[jj], _R); 1141 1122 if (div) 1142 1123 SM_DIV(q2, div); … … 1178 1159 fo = f1; 1179 1160 if (iopt >= 0) 1180 p Delete(&(this->mpRowAdr(iopt)[qcol[0]]));1161 p_Delete(&(this->mpRowAdr(iopt)[qcol[0]]), _R); 1181 1162 iopt = i; 1182 1163 } 1183 1164 else 1184 p Delete(&(this->mpRowAdr(i)[qcol[0]]));1165 p_Delete(&(this->mpRowAdr(i)[qcol[0]]), _R); 1185 1166 } 1186 1167 } … … 1257 1238 fo = f1; 1258 1239 if (iopt >= 0) 1259 p Delete(&(this->mpRowAdr(iopt)[qcol[0]]));1240 p_Delete(&(this->mpRowAdr(iopt)[qcol[0]]), _R); 1260 1241 iopt = row; 1261 1242 } 1262 1243 else 1263 p Delete(&(this->mpRowAdr(row)[qcol[0]]));1244 p_Delete(&(this->mpRowAdr(row)[qcol[0]]), _R); 1264 1245 } 1265 1246 if (iopt >= 0) … … 1458 1439 } 1459 1440 1460 /* 1461 * perform replacement for pivot strategy in Bareiss algorithm 1462 * change sign of determinant 1463 */ 1441 /// perform replacement for pivot strategy in Bareiss algorithm 1442 /// change sign of determinant 1464 1443 static void mpReplace(int j, int n, int &sign, int *perm) 1465 1444 { … … 1527 1506 } 1528 1507 1529 static poly mp Leibnitz(matrix a)1508 static poly mp_Leibnitz(matrix a, const ring _R) 1530 1509 { 1531 1510 int i, e, n; … … 1535 1514 n = MATROWS(a); 1536 1515 memset(&z,0,(n+2)*sizeof(int)); 1537 p = p One();1516 p = p_One(_R); 1538 1517 for (i=1; i <= n; i++) 1539 p = p Mult(p, pCopy(MATELEM(a, i, i)));1518 p = p_Mult_q(p, p_Copy(MATELEM(a, i, i), _R), _R); 1540 1519 d = p; 1541 1520 for (i=1; i<= n; i++) … … 1548 1527 { 1549 1528 e = mpNextperm((perm *)&z, n); 1550 p = p One();1529 p = p_One(_R); 1551 1530 for (i = 1; i <= n; i++) 1552 p = p Mult(p, pCopy(MATELEM(a, i, z[i])));1531 p = p_Mult_q(p, p_Copy(MATELEM(a, i, z[i]), _R), _R); 1553 1532 if (z[0] > 0) 1554 d = p Add(d, p);1533 d = p_Add_q(d, p, _R); 1555 1534 else 1556 d = p Sub(d, p);1535 d = p_Sub_q(d, p, _R); 1557 1536 } 1558 1537 } … … 1560 1539 } 1561 1540 1562 static poly minuscopy (poly p )1541 static poly minuscopy (poly p, const ring R) 1563 1542 { 1564 1543 poly w; 1565 1544 number e; 1566 e = n Init(-1);1567 w = p Copy(p);1568 p Mult_nn(w, e);1569 n Delete(&e);1545 e = n_Init(-1, R); 1546 w = p_Copy(p, R); 1547 p_Mult_nn(w, e, R); 1548 n_Delete(&e, R); 1570 1549 return w; 1571 1550 } … … 1575 1554 * arguments are destroyed 1576 1555 */ 1577 static poly p Insert(poly p1, poly p2)1556 static poly p_Insert(poly p1, poly p2, const ring R) 1578 1557 { 1579 1558 poly a1, p, a2, a; … … 1584 1563 a1 = p1; 1585 1564 a2 = p2; 1586 a = p = p One();1565 a = p = p_One(R); 1587 1566 loop 1588 1567 { … … 1633 1612 * x^i*y^j (i, j >= 0) that appear in fro 1634 1613 */ 1635 static poly mp Select (poly fro, poly what)1614 static poly mp_Select (poly fro, poly what, const ring _R) 1636 1615 { 1637 1616 int i; … … 1640 1619 while (fro!=NULL) 1641 1620 { 1642 h = p One();1621 h = p_One(_R); 1643 1622 for (i=1; i<=pVariables; i++) 1644 p SetExp(h,i, pGetExp(fro,i) * pGetExp(what, i));1645 p SetComp(h, pGetComp(fro));1646 p Setm(h);1647 res = p Insert(h, res);1623 p_SetExp(h,i, p_GetExp(fro,i, _R) * p_GetExp(what, i, _R), _R); 1624 p_SetComp(h, p_GetComp(fro, _R), _R); 1625 p_Setm(h, _R); 1626 res = p_Insert(h, res, _R); 1648 1627 fro = fro->next; 1649 1628 } … … 1667 1646 */ 1668 1647 1669 static void mp PartClean(matrix a, int lr, int lc)1648 static void mp_PartClean(matrix a, int lr, int lc, const ring _R) 1670 1649 { 1671 1650 poly *q1; … … 1675 1654 { 1676 1655 q1 = &(a->m)[i*a->ncols]; 1677 for (j=lc-1;j>=0;j--) if(q1[j]) p Delete(&q1[j]);1678 } 1679 } 1680 1681 static void mp FinalClean(matrix a)1656 for (j=lc-1;j>=0;j--) if(q1[j]) p_Delete(&q1[j], _R); 1657 } 1658 } 1659 1660 static void mp_FinalClean(matrix a, const ring _R) 1682 1661 { 1683 1662 omFreeSize((ADDRESS)a->m,a->nrows*a->ncols*sizeof(poly)); … … 1689 1668 * for application in minor 1690 1669 */ 1691 static int mp PrepareRow (matrix a, int lr, int lc)1670 static int mp_PrepareRow (matrix a, int lr, int lc, const ring _R) 1692 1671 { 1693 1672 int r; 1694 1673 1695 r = mp PivBar(a,lr,lc);1674 r = mp_PivBar(a,lr,lc, _R); 1696 1675 if(r==0) return 0; 1697 if(r<lr) mp SwapRow(a, r, lr, lc);1676 if(r<lr) mp_SwapRow(a, r, lr, lc, _R); 1698 1677 return 1; 1699 1678 } … … 1703 1682 * for application in minor 1704 1683 */ 1705 static int mp PreparePiv (matrix a, int lr, int lc)1684 static int mp_PreparePiv (matrix a, int lr, int lc, const ring _R) 1706 1685 { 1707 1686 int c; 1708 1687 1709 c = mp PivRow(a, lr, lc);1688 c = mp_PivRow(a, lr, lc, _R); 1710 1689 if(c==0) return 0; 1711 if(c<lc) mp SwapCol(a, c, lr, lc);1690 if(c<lc) mp_SwapCol(a, c, lr, lc, _R); 1712 1691 return 1; 1713 1692 } … … 1716 1695 * find best row 1717 1696 */ 1718 static int mp PivBar(matrix a, int lr, int lc)1697 static int mp_PivBar(matrix a, int lr, int lc, const ring _R) 1719 1698 { 1720 1699 float f1, f2; … … 1731 1710 { 1732 1711 if (q1[j]!=NULL) 1733 f2 += mp PolyWeight(q1[j]);1712 f2 += mp_PolyWeight(q1[j], _R); 1734 1713 } 1735 1714 if ((f2!=0.0) && (f2<f1)) … … 1746 1725 * find pivot in the last row 1747 1726 */ 1748 static int mp PivRow(matrix a, int lr, int lc)1727 static int mp_PivRow(matrix a, int lr, int lc, const ring _R) 1749 1728 { 1750 1729 float f1, f2; … … 1759 1738 if (q1[j]!=NULL) 1760 1739 { 1761 f2 = mp PolyWeight(q1[j]);1740 f2 = mp_PolyWeight(q1[j], _R); 1762 1741 if (f2<f1) 1763 1742 { … … 1774 1753 * weigth of a polynomial, for pivot strategy 1775 1754 */ 1776 static float mp PolyWeight(poly p)1755 static float mp_PolyWeight(poly p, const ring _R) 1777 1756 { 1778 1757 int i; … … 1781 1760 if (pNext(p) == NULL) 1782 1761 { 1783 res = (float)n Size(pGetCoeff(p));1762 res = (float)n_Size(p_GetCoeff(p, _R), _R); 1784 1763 for (i=pVariables;i>0;i--) 1785 1764 { 1786 if(p GetExp(p,i)!=0)1765 if(p_GetExp(p,i, _R)!=0) 1787 1766 { 1788 1767 res += 2.0; … … 1796 1775 do 1797 1776 { 1798 res += (float)n Size(pGetCoeff(p))+2.0;1777 res += (float)n_Size(p_GetCoeff(p, _R), _R) + 2.0; 1799 1778 pIter(p); 1800 1779 } … … 1808 1787 poly sw; 1809 1788 int j; 1810 poly seta2 = a->m, a1 = &a2[a->ncols*(pos-1)];1789 poly* a2 = a->m, a1 = &a2[a->ncols*(pos-1)]; 1811 1790 1812 1791 a2 = &a2[a->ncols*(lr-1)]; … … 1823 1802 poly sw; 1824 1803 int j; 1825 poly seta2 = a->m, a1 = &a2[pos-1];1804 poly* a2 = a->m, a1 = &a2[pos-1]; 1826 1805 1827 1806 a2 = &a2[lc-1]; … … 1834 1813 } 1835 1814 1836 static void mp ElimBar(matrix a0, matrix re, poly div, int lr, int lc)1815 static void mp_ElimBar(matrix a0, matrix re, poly div, int lr, int lc, const ring _R) 1837 1816 { 1838 1817 int r=lr-1, c=lc-1; … … 1861 1840 { 1862 1841 q2 = SM_MULT(ap[j], elim, div); 1863 q1 = p Add(q1,q2);1842 q1 = p_Add_q(q1,q2, _R); 1864 1843 } 1865 1844 } … … 1890 1869 } 1891 1870 1892 BOOLEAN mp IsDiagUnit(matrix U)1871 BOOLEAN mp_IsDiagUnit(matrix U, const ring _R) 1893 1872 { 1894 1873 if(MATROWS(U)!=MATCOLS(U)) … … 1900 1879 if (i==j) 1901 1880 { 1902 if (!p IsUnit(MATELEM(U,i,i))) return FALSE;1881 if (!p_IsUnit(MATELEM(U,i,i), _R)) return FALSE; 1903 1882 } 1904 1883 else if (MATELEM(U,i,j)!=NULL) return FALSE; … … 1908 1887 } 1909 1888 1910 void iiWriteMatrix(matrix im, const char *n, int dim, int spaces)1889 void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces) 1911 1890 { 1912 1891 int i,ii = MATROWS(im)-1; … … 1923 1902 else if (dim == 1) Print("%s[%u]=",n,j+1); 1924 1903 else if (dim == 0) Print("%s=",n); 1925 if ((i<ii)||(j<jj)) p Write(*pp++);1926 else p Write0(*pp);1927 } 1928 } 1929 } 1930 1931 char * iiStringMatrix(matrix im, int dim, char ch)1904 if ((i<ii)||(j<jj)) p_Write(*pp++, r); 1905 else p_Write0(*pp, r); 1906 } 1907 } 1908 } 1909 1910 char * iiStringMatrix(matrix im, int dim, , const ring r, char ch) 1932 1911 { 1933 1912 int i,ii = MATROWS(im); … … 1940 1919 for (j=0; j<jj; j++) 1941 1920 { 1942 p String0(*pp++);1921 p_String0(*pp++, r); 1943 1922 s=StringAppend("%c",ch); 1944 1923 if (dim > 1) s = StringAppendS("\n"); … … 1949 1928 } 1950 1929 1951 void mp Delete(matrix* a, const ring r)1930 void mp_Delete(matrix* a, const ring r) 1952 1931 { 1953 1932 id_Delete((ideal *) a, r); -
libpolys/polys/simpleideals.h
r0a3a629 r5d9aa6 102 102 intvec *id_Sort(ideal id,BOOLEAN nolex, const ring r); 103 103 104 105 int binom (int n,int r); 106 104 107 #endif
Note: See TracChangeset
for help on using the changeset viewer.