[3a67ea7] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[341696] | 4 | /* $Id$ */ |
---|
[3a67ea7] | 5 | /* |
---|
| 6 | * ABSTRACT: kernel: utils for shift GB and free GB |
---|
| 7 | */ |
---|
| 8 | |
---|
[599326] | 9 | #include <kernel/mod2.h> |
---|
[07625cb] | 10 | |
---|
[037df4] | 11 | #ifdef HAVE_SHIFTBBA |
---|
[599326] | 12 | #include <kernel/febase.h> |
---|
[210e07] | 13 | #include <polys/monomials/ring.h> |
---|
[737a68] | 14 | #include <kernel/polys.h> |
---|
[0f401f] | 15 | #include <coeffs/numbers.h> |
---|
[599326] | 16 | #include <kernel/ideals.h> |
---|
[76cfef] | 17 | #include <polys/matpol.h> |
---|
[210e07] | 18 | #include <polys/kbuckets.h> |
---|
[599326] | 19 | #include <kernel/kstd1.h> |
---|
[76cfef] | 20 | #include <polys/sbuckets.h> |
---|
| 21 | #include <polys/operations/p_Mult_q.h> |
---|
[599326] | 22 | #include <kernel/kutil.h> |
---|
| 23 | #include <kernel/structs.h> |
---|
[b1dfaf] | 24 | #include <omalloc/omalloc.h> |
---|
[599326] | 25 | #include <kernel/khstd.h> |
---|
[210e07] | 26 | #include <polys/kbuckets.h> |
---|
[76cfef] | 27 | #include <polys/weight.h> |
---|
[210e07] | 28 | #include <misc/intvec.h> |
---|
[599326] | 29 | #include <kernel/structs.h> |
---|
[c6e80e] | 30 | #include <kernel/kInline.h> |
---|
[599326] | 31 | #include <kernel/stairc.h> |
---|
[76cfef] | 32 | #include <polys/weight.h> |
---|
[210e07] | 33 | #include <misc/intvec.h> |
---|
[599326] | 34 | #include <kernel/timer.h> |
---|
| 35 | #include <kernel/shiftgb.h> |
---|
[76cfef] | 36 | #include <polys/nc/sca.h> |
---|
[cb0fbe] | 37 | |
---|
| 38 | |
---|
| 39 | #define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int)) |
---|
[3a67ea7] | 40 | |
---|
[4d2ab5c] | 41 | |
---|
| 42 | /* TODO: write p* stuff as instances of p_* for all the functions */ |
---|
[ad1c3b] | 43 | /* p_* functions are new, p* are old */ |
---|
[4d2ab5c] | 44 | |
---|
| 45 | poly p_LPshiftT(poly p, int sh, int uptodeg, int lV, kStrategy strat, const ring r) |
---|
| 46 | { |
---|
| 47 | /* assume shift takes place, shifts the poly p by sh */ |
---|
| 48 | /* p is like TObject: lm in currRing = r, tail in tailRing */ |
---|
| 49 | |
---|
| 50 | if (p==NULL) return(p); |
---|
| 51 | |
---|
| 52 | assume(p_LmCheckIsFromRing(p,r)); |
---|
| 53 | assume(p_CheckIsFromRing(pNext(p),strat->tailRing)); |
---|
| 54 | |
---|
[ad1c3b] | 55 | /* assume sh and uptodeg agree TODO check */ |
---|
[4d2ab5c] | 56 | |
---|
| 57 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 58 | |
---|
| 59 | poly q = NULL; |
---|
| 60 | poly s = p_mLPshift(p, sh, uptodeg, lV, r); // lm in currRing |
---|
| 61 | poly pp = pNext(p); |
---|
[a41623] | 62 | |
---|
[4d2ab5c] | 63 | while (pp != NULL) |
---|
| 64 | { |
---|
| 65 | q = p_Add_q(q, p_mLPshift(pp,sh,uptodeg,lV,strat->tailRing),strat->tailRing); |
---|
| 66 | pIter(pp); |
---|
| 67 | } |
---|
| 68 | pNext(s) = q; |
---|
| 69 | /* int version: returns TRUE if it was successful */ |
---|
| 70 | return(s); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | poly p_LPshift(poly p, int sh, int uptodeg, int lV, const ring r) |
---|
| 75 | { |
---|
| 76 | /* assume shift takes place */ |
---|
[ad1c3b] | 77 | /* shifts the poly p from the ring r by sh */ |
---|
[4d2ab5c] | 78 | |
---|
[ad1c3b] | 79 | /* assume sh and uptodeg agree TODO check */ |
---|
[4d2ab5c] | 80 | |
---|
| 81 | if (p==NULL) return(p); |
---|
| 82 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 83 | |
---|
| 84 | poly q = NULL; |
---|
[ad1c3b] | 85 | poly pp = p; // do not take copies |
---|
[4d2ab5c] | 86 | while (pp!=NULL) |
---|
| 87 | { |
---|
| 88 | q = p_Add_q(q, p_mLPshift(pp,sh,uptodeg,lV,r),r); |
---|
| 89 | pIter(pp); |
---|
| 90 | } |
---|
| 91 | return(q); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | poly p_mLPshift(poly p, int sh, int uptodeg, int lV, const ring r) |
---|
| 95 | { |
---|
[ad1c3b] | 96 | /* p is a monomial from the ring r */ |
---|
[4d2ab5c] | 97 | |
---|
| 98 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 99 | |
---|
| 100 | if (sh < 0 ) |
---|
| 101 | { |
---|
| 102 | #ifdef PDEBUG |
---|
[a610ee] | 103 | PrintS("pmLPshift: negative shift requested\n"); |
---|
[4d2ab5c] | 104 | #endif |
---|
| 105 | return(NULL); /* violation, 2check */ |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | int L = p_mLastVblock(p,lV,r); |
---|
| 109 | if (L+sh-1 > uptodeg) |
---|
| 110 | { |
---|
| 111 | #ifdef PDEBUG |
---|
[a610ee] | 112 | PrintS("p_mLPshift: too big shift requested\n"); |
---|
[4d2ab5c] | 113 | #endif |
---|
| 114 | return(NULL); /* violation, 2check */ |
---|
| 115 | } |
---|
| 116 | int *e=(int *)omAlloc0((r->N+1)*sizeof(int)); |
---|
| 117 | int *s=(int *)omAlloc0((r->N+1)*sizeof(int)); |
---|
| 118 | p_GetExpV(p,e,r); |
---|
[ad1c3b] | 119 | |
---|
[4d2ab5c] | 120 | int j; |
---|
[a41623] | 121 | // for (j=1; j<=r->N; j++) |
---|
[4d2ab5c] | 122 | // L*lV gives the last position of the last block |
---|
| 123 | for (j=1; j<= L*lV ; j++) |
---|
| 124 | { |
---|
| 125 | if (e[j]==1) |
---|
| 126 | { |
---|
| 127 | s[j + (sh*lV)] = e[j]; /* actually 1 */ |
---|
[ad1c3b] | 128 | #ifdef PDEBUG |
---|
[4d2ab5c] | 129 | omCheckAddr(s); |
---|
[ad1c3b] | 130 | #endif |
---|
[4d2ab5c] | 131 | } |
---|
[ad1c3b] | 132 | #ifdef PDEBUG |
---|
[a41623] | 133 | else |
---|
[4d2ab5c] | 134 | { |
---|
| 135 | if (e[j]!=0) |
---|
| 136 | { |
---|
[a41623] | 137 | // Print("p_mLPshift: ex[%d]=%d\n",j,e[j]); |
---|
[4d2ab5c] | 138 | } |
---|
| 139 | } |
---|
[ad1c3b] | 140 | #endif |
---|
[4d2ab5c] | 141 | } |
---|
[b902246] | 142 | poly m = p_One(r); |
---|
[4d2ab5c] | 143 | p_SetExpV(m,s,r); |
---|
| 144 | freeT(e, r->N); |
---|
| 145 | freeT(s, r->N); |
---|
[ad1c3b] | 146 | /* pSetm(m); */ /* done in the pSetExpV */ |
---|
| 147 | /* think on the component and coefficient */ |
---|
| 148 | // number c = pGetCoeff(p); |
---|
| 149 | // p_SetCoeff0(m,p_GetCoeff(p,r),r); |
---|
| 150 | p_SetComp(m,p_GetComp(p,r),r); // component is preserved |
---|
[a41623] | 151 | p_SetCoeff0(m,p_GetCoeff(p,r),r); // coeff is preserved |
---|
[4d2ab5c] | 152 | return(m); |
---|
| 153 | } |
---|
| 154 | |
---|
[3a67ea7] | 155 | poly pLPshift(poly p, int sh, int uptodeg, int lV) |
---|
| 156 | { |
---|
| 157 | /* assume shift takes place */ |
---|
[cb0fbe] | 158 | /* shifts the poly p by sh */ |
---|
[37a4c3] | 159 | /* deletes p */ |
---|
[cb0fbe] | 160 | |
---|
| 161 | /* assume sh and uptodeg agree */ |
---|
[3a67ea7] | 162 | |
---|
| 163 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 164 | |
---|
[cb0fbe] | 165 | poly q = NULL; |
---|
[37a4c3] | 166 | poly pp = p; // pCopy(p); |
---|
[cb0fbe] | 167 | while (pp!=NULL) |
---|
[3a67ea7] | 168 | { |
---|
[cb0fbe] | 169 | q = p_Add_q(q, pmLPshift(pp,sh,uptodeg,lV),currRing); |
---|
| 170 | pIter(pp); |
---|
[3a67ea7] | 171 | } |
---|
[cb0fbe] | 172 | /* delete pp? */ |
---|
[3a67ea7] | 173 | /* int version: returns TRUE if it was successful */ |
---|
[cb0fbe] | 174 | return(q); |
---|
[3a67ea7] | 175 | } |
---|
| 176 | |
---|
| 177 | poly pmLPshift(poly p, int sh, int uptodeg, int lV) |
---|
| 178 | { |
---|
[4d2ab5c] | 179 | /* TODO: use a shortcut with p_ version */ |
---|
[3a67ea7] | 180 | /* pm is a monomial */ |
---|
| 181 | |
---|
| 182 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 183 | |
---|
[cb0fbe] | 184 | if (sh < 0 ) |
---|
| 185 | { |
---|
| 186 | #ifdef PDEBUG |
---|
[a610ee] | 187 | PrintS("pmLPshift: negative shift requested\n"); |
---|
[cb0fbe] | 188 | #endif |
---|
| 189 | return(NULL); /* violation, 2check */ |
---|
| 190 | } |
---|
| 191 | |
---|
[3a67ea7] | 192 | int L = pmLastVblock(p,lV); |
---|
[cb0fbe] | 193 | if (L+sh-1 > uptodeg) |
---|
[3a67ea7] | 194 | { |
---|
[cb0fbe] | 195 | #ifdef PDEBUG |
---|
[a610ee] | 196 | PrintS("pmLPshift: too big shift requested\n"); |
---|
[cb0fbe] | 197 | #endif |
---|
[3a67ea7] | 198 | return(NULL); /* violation, 2check */ |
---|
| 199 | } |
---|
[cb0fbe] | 200 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
| 201 | int *s=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
[3a67ea7] | 202 | pGetExpV(p,e); |
---|
| 203 | number c = pGetCoeff(p); |
---|
[cb0fbe] | 204 | int j; |
---|
| 205 | for (j=1; j<=currRing->N; j++) |
---|
[3a67ea7] | 206 | { |
---|
[ad1c3b] | 207 | if (e[j]==1) |
---|
[3a67ea7] | 208 | { |
---|
[cb0fbe] | 209 | s[j + (sh*lV)] = e[j]; /* actually 1 */ |
---|
[3a67ea7] | 210 | } |
---|
| 211 | } |
---|
| 212 | poly m = pOne(); |
---|
| 213 | pSetExpV(m,s); |
---|
[cb0fbe] | 214 | /* pSetm(m); */ /* done in the pSetExpV */ |
---|
[37a4c3] | 215 | /* think on the component */ |
---|
[3a67ea7] | 216 | pSetCoeff0(m,c); |
---|
| 217 | freeT(e, currRing->N); |
---|
| 218 | freeT(s, currRing->N); |
---|
| 219 | return(m); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | int pLastVblock(poly p, int lV) |
---|
| 223 | { |
---|
| 224 | /* returns the number of maximal block */ |
---|
| 225 | /* appearing among the monomials of p */ |
---|
[37a4c3] | 226 | /* the 0th block is the 1st one */ |
---|
[4d2ab5c] | 227 | poly q = p; //p_Copy(p,currRing); /* need it ? */ |
---|
[a41623] | 228 | int ans = 0; |
---|
[cb0fbe] | 229 | int ansnew = 0; |
---|
[3a67ea7] | 230 | while (q!=NULL) |
---|
| 231 | { |
---|
| 232 | ansnew = pmLastVblock(q,lV); |
---|
[cb0fbe] | 233 | ans = si_max(ans,ansnew); |
---|
[3a67ea7] | 234 | pIter(q); |
---|
| 235 | } |
---|
[cb0fbe] | 236 | /* do not need to delete q */ |
---|
[3a67ea7] | 237 | return(ans); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | int pmLastVblock(poly p, int lV) |
---|
| 241 | { |
---|
| 242 | /* for a monomial p, returns the number of the last block */ |
---|
| 243 | /* where a nonzero exponent is sitting */ |
---|
[4d2ab5c] | 244 | if (pIsConstantPoly(p)) |
---|
| 245 | { |
---|
| 246 | return(int(0)); |
---|
| 247 | } |
---|
[cb0fbe] | 248 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
[3a67ea7] | 249 | pGetExpV(p,e); |
---|
| 250 | int j,b; |
---|
[cb0fbe] | 251 | j = currRing->N; |
---|
[3a67ea7] | 252 | while ( (!e[j]) && (j>=1) ) j--; |
---|
[a41623] | 253 | if (j==0) |
---|
[cb0fbe] | 254 | { |
---|
| 255 | #ifdef PDEBUG |
---|
[a610ee] | 256 | PrintS("pmLastVblock: unexpected zero exponent vector\n"); |
---|
[a41623] | 257 | #endif |
---|
[cb0fbe] | 258 | return(j); |
---|
| 259 | } |
---|
| 260 | b = (int)(j/lV) + 1; /* the number of the block, >=1 */ |
---|
[3a67ea7] | 261 | return (b); |
---|
| 262 | } |
---|
| 263 | |
---|
[4d2ab5c] | 264 | int p_LastVblockT(poly p, int lV, kStrategy strat, const ring r) |
---|
| 265 | { |
---|
| 266 | /* returns the number of maximal block */ |
---|
| 267 | /* appearing among the monomials of p */ |
---|
| 268 | /* the 0th block is the 1st one */ |
---|
| 269 | |
---|
| 270 | /* p is like TObject: lm in currRing = r, tail in tailRing */ |
---|
| 271 | assume(p_LmCheckIsFromRing(p,r)); |
---|
| 272 | assume(p_CheckIsFromRing(pNext(p),strat->tailRing)); |
---|
| 273 | |
---|
| 274 | int ans = p_mLastVblock(p, lV, r); // Block of LM |
---|
[a41623] | 275 | poly q = pNext(p); |
---|
[4d2ab5c] | 276 | int ansnew = 0; |
---|
| 277 | while (q != NULL) |
---|
| 278 | { |
---|
| 279 | ansnew = p_mLastVblock(q, lV, strat->tailRing); |
---|
| 280 | ans = si_max(ans,ansnew); |
---|
| 281 | pIter(q); |
---|
| 282 | } |
---|
| 283 | /* do not need to delete q */ |
---|
| 284 | return(ans); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | int p_LastVblock(poly p, int lV, const ring r) |
---|
| 288 | { |
---|
| 289 | /* returns the number of maximal block */ |
---|
| 290 | /* appearing among the monomials of p */ |
---|
| 291 | /* the 0th block is the 1st one */ |
---|
| 292 | poly q = p; //p_Copy(p,currRing); /* need it ? */ |
---|
[a41623] | 293 | int ans = 0; |
---|
[4d2ab5c] | 294 | int ansnew = 0; |
---|
| 295 | while (q!=NULL) |
---|
| 296 | { |
---|
| 297 | ansnew = p_mLastVblock(q, lV, r); |
---|
| 298 | ans = si_max(ans,ansnew); |
---|
| 299 | pIter(q); |
---|
| 300 | } |
---|
| 301 | /* do not need to delete q */ |
---|
| 302 | return(ans); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | int p_mLastVblock(poly p, int lV, const ring r) |
---|
| 306 | { |
---|
| 307 | /* for a monomial p, returns the number of the last block */ |
---|
| 308 | /* where a nonzero exponent is sitting */ |
---|
| 309 | if (p_LmIsConstant(p,r)) |
---|
| 310 | { |
---|
| 311 | return(0); |
---|
| 312 | } |
---|
| 313 | int *e=(int *)omAlloc0((r->N+1)*sizeof(int)); |
---|
| 314 | p_GetExpV(p,e,r); |
---|
| 315 | int j,b; |
---|
| 316 | j = r->N; |
---|
| 317 | while ( (!e[j]) && (j>=1) ) j--; |
---|
[a41623] | 318 | if (j==0) |
---|
[4d2ab5c] | 319 | { |
---|
| 320 | #ifdef PDEBUG |
---|
[a610ee] | 321 | PrintS("pmLastVblock: unexpected zero exponent vector\n"); |
---|
[a41623] | 322 | #endif |
---|
[4d2ab5c] | 323 | return(j); |
---|
| 324 | } |
---|
| 325 | b = (int)((j+lV-1)/lV); /* the number of the block, >=1 */ |
---|
| 326 | freeT(e,r->N); |
---|
| 327 | return (b); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | int pFirstVblock(poly p, int lV) |
---|
| 331 | { |
---|
| 332 | /* returns the number of maximal block */ |
---|
| 333 | /* appearing among the monomials of p */ |
---|
| 334 | /* the 0th block is the 1st one */ |
---|
| 335 | poly q = p; //p_Copy(p,currRing); /* need it ? */ |
---|
[a41623] | 336 | int ans = 0; |
---|
[4d2ab5c] | 337 | int ansnew = 0; |
---|
| 338 | while (q!=NULL) |
---|
| 339 | { |
---|
| 340 | ansnew = pmFirstVblock(q,lV); |
---|
| 341 | ans = si_min(ans,ansnew); |
---|
| 342 | pIter(q); |
---|
| 343 | } |
---|
| 344 | /* do not need to delete q */ |
---|
| 345 | return(ans); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | int pmFirstVblock(poly p, int lV) |
---|
| 349 | { |
---|
| 350 | if (pIsConstantPoly(p)) |
---|
| 351 | { |
---|
| 352 | return(int(0)); |
---|
| 353 | } |
---|
| 354 | /* for a monomial p, returns the number of the first block */ |
---|
| 355 | /* where a nonzero exponent is sitting */ |
---|
| 356 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
| 357 | pGetExpV(p,e); |
---|
| 358 | int j,b; |
---|
| 359 | j = 1; |
---|
| 360 | while ( (!e[j]) && (j<=currRing->N-1) ) j++; |
---|
[a41623] | 361 | if (j==currRing->N + 1) |
---|
[4d2ab5c] | 362 | { |
---|
| 363 | #ifdef PDEBUG |
---|
[a610ee] | 364 | PrintS("pmFirstVblock: unexpected zero exponent vector\n"); |
---|
[a41623] | 365 | #endif |
---|
[4d2ab5c] | 366 | return(j); |
---|
| 367 | } |
---|
| 368 | b = (int)(j/lV)+1; /* the number of the block, 1<= N <= currRing->N */ |
---|
| 369 | return (b); |
---|
| 370 | } |
---|
| 371 | |
---|
[1c473f] | 372 | /* there should be two routines: */ |
---|
[ad1c3b] | 373 | /* 1. test place-squarefreeness: in homog this suffices: isInV */ |
---|
[1c473f] | 374 | /* 2. test the presence of a hole -> in the tail??? */ |
---|
[4d2ab5c] | 375 | |
---|
[3a67ea7] | 376 | int isInV(poly p, int lV) |
---|
| 377 | { |
---|
[ad1c3b] | 378 | /* investigate only the leading monomial of p in currRing */ |
---|
[dabe365] | 379 | if ( pIsConstant(p) ) return(1); |
---|
[cb0fbe] | 380 | if (lV <= 0) return(0); |
---|
[3a67ea7] | 381 | /* returns 1 iff p is in V */ |
---|
[cb0fbe] | 382 | /* that is in each block up to a certain one there is only one nonzero exponent */ |
---|
[3a67ea7] | 383 | /* lV = the length of V = the number of orig vars */ |
---|
[cb0fbe] | 384 | int *e = (int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
[ad1c3b] | 385 | int b = (int)((currRing->N +lV-1)/lV); /* the number of blocks */ |
---|
[a41623] | 386 | //int b = (int)(currRing->N)/lV; |
---|
[cb0fbe] | 387 | int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */ |
---|
[3a67ea7] | 388 | pGetExpV(p,e); |
---|
| 389 | int i,j; |
---|
| 390 | for (j=1; j<=b; j++) |
---|
| 391 | { |
---|
| 392 | /* we go through all the vars */ |
---|
| 393 | /* by blocks in lV vars */ |
---|
| 394 | for (i=(j-1)*lV + 1; i<= j*lV; i++) |
---|
| 395 | { |
---|
[4d2ab5c] | 396 | if (e[i]) B[j] = B[j]+1; |
---|
[3a67ea7] | 397 | } |
---|
| 398 | } |
---|
[ad1c3b] | 399 | // j = b; |
---|
[37a4c3] | 400 | // while ( (!B[j]) && (j>=1)) j--; |
---|
| 401 | for (j=b; j>=1; j--) |
---|
| 402 | { |
---|
| 403 | if (B[j]!=0) break; |
---|
| 404 | } |
---|
[ad1c3b] | 405 | /* do not need e anymore */ |
---|
| 406 | freeT(e, currRing->N); |
---|
[37a4c3] | 407 | |
---|
[ad1c3b] | 408 | if (j==0) goto ret_true; |
---|
| 409 | // { |
---|
| 410 | // /* it is a zero exp vector, which is in V */ |
---|
| 411 | // freeT(B, b); |
---|
| 412 | // return(1); |
---|
| 413 | // } |
---|
| 414 | /* now B[j] != 0 and we test place-squarefreeness */ |
---|
[a41623] | 415 | for (; j>=1; j--) |
---|
[3a67ea7] | 416 | { |
---|
| 417 | if (B[j]!=1) |
---|
| 418 | { |
---|
[ad1c3b] | 419 | freeT(B, b); |
---|
[3a67ea7] | 420 | return(0); |
---|
| 421 | } |
---|
| 422 | } |
---|
[ad1c3b] | 423 | ret_true: |
---|
| 424 | freeT(B, b); |
---|
[3a67ea7] | 425 | return(1); |
---|
| 426 | } |
---|
| 427 | |
---|
[dabe365] | 428 | int poly_isInV(poly p, int lV) |
---|
| 429 | { |
---|
| 430 | /* tests whether the whole polynomial p in in V */ |
---|
| 431 | poly q = p; |
---|
| 432 | while (q!=NULL) |
---|
| 433 | { |
---|
| 434 | if ( !isInV(q,lV) ) |
---|
| 435 | { |
---|
| 436 | return(0); |
---|
| 437 | } |
---|
| 438 | q = pNext(q); |
---|
| 439 | } |
---|
| 440 | return(1); |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | int ideal_isInV(ideal I, int lV) |
---|
| 444 | { |
---|
| 445 | /* tests whether each polynomial of an ideal I lies in in V */ |
---|
| 446 | int i; |
---|
| 447 | int s = IDELEMS(I)-1; |
---|
| 448 | for(i = 0; i <= s; i++) |
---|
| 449 | { |
---|
| 450 | if ( !poly_isInV(I->m[i],lV) ) |
---|
| 451 | { |
---|
| 452 | return(0); |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | return(1); |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | |
---|
[4d2ab5c] | 459 | int itoInsert(poly p, int uptodeg, int lV, const ring r) |
---|
| 460 | { |
---|
| 461 | /* for poly in lmCR/tailTR presentation */ |
---|
[ad1c3b] | 462 | /* the below situation (commented out) might happen! */ |
---|
[4d2ab5c] | 463 | // if (r == currRing) |
---|
| 464 | // { |
---|
| 465 | // "Current ring is not expected in toInsert"; |
---|
| 466 | // return(0); |
---|
| 467 | // } |
---|
| 468 | /* compute the number of insertions */ |
---|
| 469 | int i = p_mLastVblock(p, lV, currRing); |
---|
| 470 | if (pNext(p) != NULL) |
---|
| 471 | { |
---|
| 472 | i = si_max(i, p_LastVblock(pNext(p), lV, r) ); |
---|
| 473 | } |
---|
[a41623] | 474 | // i = uptodeg - i +1; |
---|
| 475 | i = uptodeg - i; |
---|
[1c473f] | 476 | // p_wrp(p,currRing,r); Print("----i:%d",i); PrintLn(); |
---|
[4d2ab5c] | 477 | return(i); |
---|
| 478 | } |
---|
| 479 | |
---|
[ad1c3b] | 480 | poly p_ShrinkT(poly p, int lV, kStrategy strat, const ring r) |
---|
| 481 | //poly p_Shrink(poly p, int uptodeg, int lV, kStrategy strat, const ring r) |
---|
| 482 | { |
---|
| 483 | /* p is like TObject: lm in currRing = r, tail in tailRing */ |
---|
| 484 | /* proc shrinks the poly p in ring r */ |
---|
| 485 | /* lV = the length of V = the number of orig vars */ |
---|
| 486 | /* check assumes/exceptions */ |
---|
| 487 | /* r->N is a multiple of lV */ |
---|
| 488 | |
---|
| 489 | if (p==NULL) return(p); |
---|
| 490 | |
---|
| 491 | assume(p_LmCheckIsFromRing(p,r)); |
---|
| 492 | assume(p_CheckIsFromRing(pNext(p),strat->tailRing)); |
---|
| 493 | |
---|
| 494 | poly q = NULL; |
---|
| 495 | poly s = p_mShrink(p, lV, r); // lm in currRing |
---|
| 496 | poly pp = pNext(p); |
---|
[a41623] | 497 | |
---|
[ad1c3b] | 498 | while (pp != NULL) |
---|
| 499 | { |
---|
| 500 | // q = p_Add_q(q, p_mShrink(pp,uptodeg,lV,strat->tailRing),strat->tailRing); |
---|
| 501 | q = p_Add_q(q, p_mShrink(pp,lV,strat->tailRing),strat->tailRing); |
---|
| 502 | pIter(pp); |
---|
| 503 | } |
---|
| 504 | pNext(s) = q; |
---|
| 505 | return(s); |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | poly p_Shrink(poly p, int lV, const ring r) |
---|
| 509 | { |
---|
| 510 | /* proc shrinks the poly p in ring r */ |
---|
| 511 | /* lV = the length of V = the number of orig vars */ |
---|
| 512 | /* check assumes/exceptions */ |
---|
| 513 | /* r->N is a multiple of lV */ |
---|
| 514 | |
---|
| 515 | if (p==NULL) return(p); |
---|
| 516 | assume(p_CheckIsFromRing(p,r)); |
---|
| 517 | poly q = NULL; |
---|
| 518 | poly pp = p; |
---|
[a41623] | 519 | |
---|
[ad1c3b] | 520 | while (pp != NULL) |
---|
| 521 | { |
---|
| 522 | q = p_Add_q(q, p_mShrink(pp,lV,r),r); |
---|
| 523 | pIter(pp); |
---|
| 524 | } |
---|
| 525 | return(q); |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | poly p_mShrink(poly p, int lV, const ring r) |
---|
| 529 | { |
---|
| 530 | /* shrinks the monomial p in ring r */ |
---|
| 531 | /* lV = the length of V = the number of orig vars */ |
---|
| 532 | |
---|
| 533 | /* check assumes/exceptions */ |
---|
| 534 | /* r->N is a multiple of lV */ |
---|
| 535 | |
---|
| 536 | int *e = (int *)omAlloc0((r->N+1)*sizeof(int)); |
---|
| 537 | int b = (int)((r->N +lV-1)/lV); /* the number of blocks */ |
---|
| 538 | // int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */ |
---|
| 539 | int *S = (int *)omAlloc0((r->N+1)*sizeof(int)); /* the shrinked exponent */ |
---|
| 540 | p_GetExpV(p,e,r); |
---|
| 541 | int i,j; int cnt = 1; //counter for blocks in S |
---|
| 542 | for (j=1; j<=b; j++) |
---|
| 543 | { |
---|
| 544 | /* we go through all the vars */ |
---|
| 545 | /* by blocks in lV vars */ |
---|
| 546 | for (i=(j-1)*lV + 1; i<= j*lV; i++) |
---|
| 547 | { |
---|
[a41623] | 548 | if (e[i]==1) |
---|
[ad1c3b] | 549 | { |
---|
[a41623] | 550 | // B[j] = B[j]+1; // for control in V? |
---|
[ad1c3b] | 551 | S[(cnt-1)*lV + (i - (j-1)*lV)] = e[i]; |
---|
| 552 | /* assuming we are in V, can interrupt here */ |
---|
| 553 | cnt++; |
---|
| 554 | // break; //results in incomplete shrink! |
---|
| 555 | i = j*lV; // manual break under assumption p is in V |
---|
| 556 | } |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | #ifdef PDEBUG |
---|
| 560 | // Print("p_mShrink: cnt = [%d], b = %d\n",cnt,b); |
---|
| 561 | #endif |
---|
| 562 | // cnt -1 <= b must hold! |
---|
| 563 | // freeT(B, b); |
---|
[b902246] | 564 | poly s = p_One(r); |
---|
[ad1c3b] | 565 | p_SetExpV(s,S,r); |
---|
| 566 | freeT(e, r->N); |
---|
| 567 | freeT(S, r->N); |
---|
| 568 | /* p_Setm(s,r); // done by p_SetExpV */ |
---|
| 569 | p_SetComp(s,p_GetComp(p,r),r); // component is preserved |
---|
[a41623] | 570 | p_SetCoeff(s,p_GetCoeff(p,r),r); // coeff is preserved |
---|
[ad1c3b] | 571 | #ifdef PDEBUG |
---|
| 572 | // Print("p_mShrink: from "); p_wrp(p,r); Print(" to "); p_wrp(s,r); PrintLn(); |
---|
| 573 | #endif |
---|
| 574 | return(s); |
---|
| 575 | } |
---|
[4d2ab5c] | 576 | |
---|
[cb0fbe] | 577 | /* shiftgb stuff */ |
---|
[3a67ea7] | 578 | |
---|
[37a4c3] | 579 | |
---|
[4c4979] | 580 | /*2 |
---|
| 581 | *if the leading term of p |
---|
| 582 | *divides the leading term of some T[i] it will be canceled |
---|
| 583 | */ |
---|
| 584 | // static inline void clearSShift (poly p, unsigned long p_sev,int l, int* at, int* k, |
---|
| 585 | // kStrategy strat) |
---|
| 586 | // { |
---|
| 587 | // assume(p_sev == pGetShortExpVector(p)); |
---|
| 588 | // if (!pLmShortDivisibleBy(p,p_sev, strat->T[*at].p, ~ strat->sevT[*at])) return; |
---|
| 589 | // // if (l>=strat->lenS[*at]) return; |
---|
| 590 | // if (TEST_OPT_PROT) |
---|
| 591 | // PrintS("!"); |
---|
| 592 | // mflush(); |
---|
| 593 | // //pDelete(&strat->S[*at]); |
---|
| 594 | // deleteInS((*at),strat); |
---|
| 595 | // (*at)--; |
---|
| 596 | // (*k)--; |
---|
| 597 | // // assume(lenS_correct(strat)); |
---|
| 598 | // } |
---|
| 599 | |
---|
[37a4c3] | 600 | /* remarks: cleanT : just deletion |
---|
| 601 | enlargeT: just reallocation */ |
---|
| 602 | |
---|
[07625cb] | 603 | #endif |
---|