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