Changeset 4d2ab5c in git for kernel/shiftgb.cc
- Timestamp:
- Feb 23, 2008, 9:12:53 PM (15 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 51e69e6599c603806d7fea8cc97d5e9f1bec09e9
- Parents:
- 8c35baa560440cca9bb7bbb44be0232fce1c79c9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/shiftgb.cc
r8c35ba r4d2ab5c 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: shiftgb.cc,v 1. 4 2008-02-15 17:14:23 levandov Exp $ */4 /* $Id: shiftgb.cc,v 1.5 2008-02-23 20:12:53 levandov Exp $ */ 5 5 /* 6 6 * ABSTRACT: kernel: utils for shift GB and free GB … … 39 39 #define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int)) 40 40 41 poly pLPshift(poly p, int sh, int uptodeg, int lV) 41 42 /* TODO: write p* stuff as instances of p_* for all the functions */ 43 44 poly p_LPshiftT(poly p, int sh, int uptodeg, int lV, kStrategy strat, const ring r) 45 { 46 /* assume shift takes place, shifts the poly p by sh */ 47 /* p is like TObject: lm in currRing = r, tail in tailRing */ 48 49 if (p==NULL) return(p); 50 51 assume(p_LmCheckIsFromRing(p,r)); 52 assume(p_CheckIsFromRing(pNext(p),strat->tailRing)); 53 54 /* assume sh and uptodeg agree */ 55 56 if (sh == 0) return(p); /* the zero shift */ 57 58 poly q = NULL; 59 poly s = p_mLPshift(p, sh, uptodeg, lV, r); // lm in currRing 60 poly pp = pNext(p); 61 62 while (pp != NULL) 63 { 64 q = p_Add_q(q, p_mLPshift(pp,sh,uptodeg,lV,strat->tailRing),strat->tailRing); 65 pIter(pp); 66 } 67 pNext(s) = q; 68 /* int version: returns TRUE if it was successful */ 69 return(s); 70 } 71 72 73 poly p_LPshift(poly p, int sh, int uptodeg, int lV, const ring r) 42 74 { 43 75 /* assume shift takes place */ … … 47 79 /* assume sh and uptodeg agree */ 48 80 81 if (p==NULL) return(p); 49 82 if (sh == 0) return(p); /* the zero shift */ 50 83 … … 53 86 while (pp!=NULL) 54 87 { 55 q = p_Add_q(q, p mLPshift(pp,sh,uptodeg,lV),currRing);88 q = p_Add_q(q, p_mLPshift(pp,sh,uptodeg,lV,r),r); 56 89 pIter(pp); 57 90 } … … 61 94 } 62 95 96 poly p_mLPshift(poly p, int sh, int uptodeg, int lV, const ring r) 97 { 98 /* pm is a monomial */ 99 100 if (sh == 0) return(p); /* the zero shift */ 101 102 if (sh < 0 ) 103 { 104 #ifdef PDEBUG 105 Print("pmLPshift: negative shift requested"); 106 #endif 107 return(NULL); /* violation, 2check */ 108 } 109 110 int L = p_mLastVblock(p,lV,r); 111 if (L+sh-1 > uptodeg) 112 { 113 #ifdef PDEBUG 114 Print("p_mLPshift: too big shift requested"); 115 #endif 116 return(NULL); /* violation, 2check */ 117 } 118 int *e=(int *)omAlloc0((r->N+1)*sizeof(int)); 119 int *s=(int *)omAlloc0((r->N+1)*sizeof(int)); 120 p_GetExpV(p,e,r); 121 number c = pGetCoeff(p); 122 int j; 123 // for (j=1; j<=r->N; j++) 124 // L*lV gives the last position of the last block 125 for (j=1; j<= L*lV ; j++) 126 { 127 if (e[j]==1) 128 { 129 s[j + (sh*lV)] = e[j]; /* actually 1 */ 130 omCheckAddr(s); 131 } 132 else 133 { 134 if (e[j]!=0) 135 { 136 #ifdef PDEBUG 137 Print("p_mLPshift: ex[%d]=%d\n",j,e[j]); 138 #endif 139 } 140 } 141 } 142 poly m = p_ISet(1,r); 143 p_SetExpV(m,s,r); 144 /* pSetm(m); */ /* done in the pSetExpV */ 145 /* think on the component */ 146 pSetCoeff0(m,c); 147 freeT(e, r->N); 148 freeT(s, r->N); 149 return(m); 150 } 151 152 poly pLPshift(poly p, int sh, int uptodeg, int lV) 153 { 154 /* assume shift takes place */ 155 /* shifts the poly p by sh */ 156 /* deletes p */ 157 158 /* assume sh and uptodeg agree */ 159 160 if (sh == 0) return(p); /* the zero shift */ 161 162 poly q = NULL; 163 poly pp = p; // pCopy(p); 164 while (pp!=NULL) 165 { 166 q = p_Add_q(q, pmLPshift(pp,sh,uptodeg,lV),currRing); 167 pIter(pp); 168 } 169 /* delete pp? */ 170 /* int version: returns TRUE if it was successful */ 171 return(q); 172 } 173 63 174 poly pmLPshift(poly p, int sh, int uptodeg, int lV) 64 175 { 176 /* TODO: use a shortcut with p_ version */ 65 177 /* pm is a monomial */ 66 178 … … 110 222 /* appearing among the monomials of p */ 111 223 /* the 0th block is the 1st one */ 112 poly q = p _Copy(p,currRing); /* need it ? */224 poly q = p; //p_Copy(p,currRing); /* need it ? */ 113 225 int ans = 0; 114 226 int ansnew = 0; … … 127 239 /* for a monomial p, returns the number of the last block */ 128 240 /* where a nonzero exponent is sitting */ 241 if (pIsConstantPoly(p)) 242 { 243 return(int(0)); 244 } 129 245 int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); 130 246 pGetExpV(p,e); … … 143 259 return (b); 144 260 } 261 262 int p_LastVblockT(poly p, int lV, kStrategy strat, const ring r) 263 { 264 /* returns the number of maximal block */ 265 /* appearing among the monomials of p */ 266 /* the 0th block is the 1st one */ 267 268 /* p is like TObject: lm in currRing = r, tail in tailRing */ 269 assume(p_LmCheckIsFromRing(p,r)); 270 assume(p_CheckIsFromRing(pNext(p),strat->tailRing)); 271 272 int ans = p_mLastVblock(p, lV, r); // Block of LM 273 poly q = pNext(p); 274 int ansnew = 0; 275 while (q != NULL) 276 { 277 ansnew = p_mLastVblock(q, lV, strat->tailRing); 278 ans = si_max(ans,ansnew); 279 pIter(q); 280 } 281 /* do not need to delete q */ 282 return(ans); 283 } 284 285 int p_LastVblock(poly p, int lV, const ring r) 286 { 287 /* returns the number of maximal block */ 288 /* appearing among the monomials of p */ 289 /* the 0th block is the 1st one */ 290 poly q = p; //p_Copy(p,currRing); /* need it ? */ 291 int ans = 0; 292 int ansnew = 0; 293 while (q!=NULL) 294 { 295 ansnew = p_mLastVblock(q, lV, r); 296 ans = si_max(ans,ansnew); 297 pIter(q); 298 } 299 /* do not need to delete q */ 300 return(ans); 301 } 302 303 int p_mLastVblock(poly p, int lV, const ring r) 304 { 305 /* for a monomial p, returns the number of the last block */ 306 /* where a nonzero exponent is sitting */ 307 if (p_LmIsConstant(p,r)) 308 { 309 return(0); 310 } 311 int *e=(int *)omAlloc0((r->N+1)*sizeof(int)); 312 p_GetExpV(p,e,r); 313 int j,b; 314 j = r->N; 315 while ( (!e[j]) && (j>=1) ) j--; 316 if (j==0) 317 { 318 #ifdef PDEBUG 319 Print("pmLastVblock: unexpected zero exponent vector"); 320 PrintLn(); 321 #endif 322 return(j); 323 } 324 b = (int)((j+lV-1)/lV); /* the number of the block, >=1 */ 325 freeT(e,r->N); 326 return (b); 327 } 328 329 int pFirstVblock(poly p, int lV) 330 { 331 /* returns the number of maximal block */ 332 /* appearing among the monomials of p */ 333 /* the 0th block is the 1st one */ 334 poly q = p; //p_Copy(p,currRing); /* need it ? */ 335 int ans = 0; 336 int ansnew = 0; 337 while (q!=NULL) 338 { 339 ansnew = pmFirstVblock(q,lV); 340 ans = si_min(ans,ansnew); 341 pIter(q); 342 } 343 /* do not need to delete q */ 344 return(ans); 345 } 346 347 int pmFirstVblock(poly p, int lV) 348 { 349 if (pIsConstantPoly(p)) 350 { 351 return(int(0)); 352 } 353 /* for a monomial p, returns the number of the first block */ 354 /* where a nonzero exponent is sitting */ 355 int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); 356 pGetExpV(p,e); 357 int j,b; 358 j = 1; 359 while ( (!e[j]) && (j<=currRing->N-1) ) j++; 360 if (j==currRing->N + 1) 361 { 362 #ifdef PDEBUG 363 Print("pmFirstVblock: unexpected zero exponent vector"); 364 PrintLn(); 365 #endif 366 return(j); 367 } 368 b = (int)(j/lV)+1; /* the number of the block, 1<= N <= currRing->N */ 369 return (b); 370 } 371 145 372 146 373 int isInV(poly p, int lV) … … 161 388 for (i=(j-1)*lV + 1; i<= j*lV; i++) 162 389 { 163 if ( !e[i]) B[j] = B[j]+1;390 if (e[i]) B[j] = B[j]+1; 164 391 } 165 392 } … … 187 414 } 188 415 416 int itoInsert(poly p, int uptodeg, int lV, const ring r) 417 { 418 /* for poly in lmCR/tailTR presentation */ 419 /* the below situation might happen! */ 420 // if (r == currRing) 421 // { 422 // "Current ring is not expected in toInsert"; 423 // return(0); 424 // } 425 /* compute the number of insertions */ 426 int i = p_mLastVblock(p, lV, currRing); 427 if (pNext(p) != NULL) 428 { 429 i = si_max(i, p_LastVblock(pNext(p), lV, r) ); 430 } 431 // i = uptodeg - i +1; 432 i = uptodeg - i; 433 p_wrp(p,currRing,r); Print("----i:%d",i); PrintLn(); 434 return(i); 435 } 436 437 189 438 /* shiftgb stuff */ 190 439
Note: See TracChangeset
for help on using the changeset viewer.