[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[341696] | 4 | /* $Id$ */ |
---|
[35aab3] | 5 | |
---|
| 6 | /* |
---|
| 7 | * ABSTRACT - all basic methods to manipulate polynomials |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /* includes */ |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <string.h> |
---|
| 13 | #include <ctype.h> |
---|
| 14 | #include "mod2.h" |
---|
| 15 | #include "structs.h" |
---|
| 16 | #include "omalloc.h" |
---|
| 17 | #include "febase.h" |
---|
| 18 | #include "numbers.h" |
---|
| 19 | #include "polys.h" |
---|
| 20 | #include "ring.h" |
---|
| 21 | |
---|
[68349d] | 22 | #ifdef HAVE_PLURAL |
---|
| 23 | #include "gring.h" |
---|
[5d7a3b] | 24 | #include "sca.h" |
---|
[68349d] | 25 | #endif |
---|
| 26 | |
---|
[35aab3] | 27 | /* ----------- global variables, set by pSetGlobals --------------------- */ |
---|
| 28 | /* computes length and maximal degree of a POLYnomial */ |
---|
| 29 | pLDegProc pLDeg; |
---|
| 30 | /* computes the degree of the initial term, used for std */ |
---|
| 31 | pFDegProc pFDeg; |
---|
| 32 | /* the monomial ordering of the head monomials a and b */ |
---|
| 33 | /* returns -1 if a comes before b, 0 if a=b, 1 otherwise */ |
---|
| 34 | |
---|
| 35 | int pVariables; // number of variables |
---|
| 36 | |
---|
| 37 | /* 1 for polynomial ring, -1 otherwise */ |
---|
| 38 | int pOrdSgn; |
---|
| 39 | // it is of type int, not BOOLEAN because it is also in ip |
---|
| 40 | /* TRUE if the monomial ordering is not compatible with pFDeg */ |
---|
| 41 | BOOLEAN pLexOrder; |
---|
| 42 | |
---|
| 43 | /* ----------- global variables, set by procedures from hecke/kstd1 ----- */ |
---|
| 44 | /* the highest monomial below pHEdge */ |
---|
| 45 | poly ppNoether = NULL; |
---|
| 46 | |
---|
| 47 | /* -------------------------------------------------------- */ |
---|
| 48 | /*2 |
---|
| 49 | * change all global variables to fit the description of the new ring |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | |
---|
[8c5988] | 53 | void pSetGlobals(const ring r, BOOLEAN complete) |
---|
[35aab3] | 54 | { |
---|
| 55 | int i; |
---|
| 56 | if (ppNoether!=NULL) pDelete(&ppNoether); |
---|
| 57 | pVariables = r->N; |
---|
| 58 | pOrdSgn = r->OrdSgn; |
---|
| 59 | pFDeg=r->pFDeg; |
---|
| 60 | pLDeg=r->pLDeg; |
---|
| 61 | pLexOrder=r->LexOrder; |
---|
| 62 | |
---|
| 63 | if (complete) |
---|
| 64 | { |
---|
| 65 | test &= ~ TEST_RINGDEP_OPTS; |
---|
| 66 | test |= r->options; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | // resets the pFDeg and pLDeg: if pLDeg is not given, it is |
---|
| 71 | // set to currRing->pLDegOrig, i.e. to the respective LDegProc which |
---|
| 72 | // only uses pFDeg (and not pDeg, or pTotalDegree, etc) |
---|
| 73 | void pSetDegProcs(pFDegProc new_FDeg, pLDegProc new_lDeg) |
---|
| 74 | { |
---|
| 75 | assume(new_FDeg != NULL); |
---|
| 76 | pFDeg = new_FDeg; |
---|
| 77 | currRing->pFDeg = new_FDeg; |
---|
| 78 | |
---|
| 79 | if (new_lDeg == NULL) |
---|
| 80 | new_lDeg = currRing->pLDegOrig; |
---|
| 81 | |
---|
| 82 | pLDeg = new_lDeg; |
---|
| 83 | currRing->pLDeg = new_lDeg; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | // restores pFDeg and pLDeg: |
---|
| 88 | extern void pRestoreDegProcs(pFDegProc old_FDeg, pLDegProc old_lDeg) |
---|
| 89 | { |
---|
| 90 | assume(old_FDeg != NULL && old_lDeg != NULL); |
---|
| 91 | pFDeg = old_FDeg; |
---|
| 92 | currRing->pFDeg = old_FDeg; |
---|
| 93 | pLDeg = old_lDeg; |
---|
| 94 | currRing->pLDeg = old_lDeg; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /*2 |
---|
| 98 | * assumes that the head term of b is a multiple of the head term of a |
---|
| 99 | * and return the multiplicant *m |
---|
| 100 | */ |
---|
| 101 | poly pDivide(poly a, poly b) |
---|
| 102 | { |
---|
| 103 | int i; |
---|
| 104 | poly result = pInit(); |
---|
| 105 | |
---|
| 106 | for(i=(int)pVariables; i; i--) |
---|
| 107 | pSetExp(result,i, pGetExp(a,i)- pGetExp(b,i)); |
---|
| 108 | pSetComp(result, pGetComp(a) - pGetComp(b)); |
---|
| 109 | pSetm(result); |
---|
| 110 | return result; |
---|
| 111 | } |
---|
| 112 | |
---|
[206e158] | 113 | #ifdef HAVE_RINGS //TODO Oliver |
---|
[8251cc] | 114 | #define pDiv_nn(p, n) p_Div_nn(p, n, currRing) |
---|
| 115 | |
---|
| 116 | poly p_Div_nn(poly p, const number n, const ring r) |
---|
| 117 | { |
---|
| 118 | pAssume(!n_IsZero(n,r)); |
---|
| 119 | p_Test(p, r); |
---|
| 120 | |
---|
| 121 | poly q = p; |
---|
| 122 | while (p != NULL) |
---|
| 123 | { |
---|
| 124 | number nc = pGetCoeff(p); |
---|
| 125 | pSetCoeff0(p, n_Div(nc, n, r)); |
---|
| 126 | n_Delete(&nc, r); |
---|
| 127 | pIter(p); |
---|
| 128 | } |
---|
| 129 | p_Test(q, r); |
---|
| 130 | return q; |
---|
| 131 | } |
---|
| 132 | #endif |
---|
| 133 | |
---|
[35aab3] | 134 | /*2 |
---|
| 135 | * divides a by the monomial b, ignores monomials which are not divisible |
---|
| 136 | * assumes that b is not NULL |
---|
| 137 | */ |
---|
| 138 | poly pDivideM(poly a, poly b) |
---|
| 139 | { |
---|
| 140 | if (a==NULL) return NULL; |
---|
| 141 | poly result=a; |
---|
| 142 | poly prev=NULL; |
---|
| 143 | int i; |
---|
[009d80] | 144 | #ifdef HAVE_RINGS |
---|
| 145 | number inv=pGetCoeff(b); |
---|
[8251cc] | 146 | #else |
---|
[35aab3] | 147 | number inv=nInvers(pGetCoeff(b)); |
---|
[8251cc] | 148 | #endif |
---|
[35aab3] | 149 | |
---|
| 150 | while (a!=NULL) |
---|
| 151 | { |
---|
| 152 | if (pDivisibleBy(b,a)) |
---|
| 153 | { |
---|
| 154 | for(i=(int)pVariables; i; i--) |
---|
| 155 | pSubExp(a,i, pGetExp(b,i)); |
---|
| 156 | pSubComp(a, pGetComp(b)); |
---|
| 157 | pSetm(a); |
---|
| 158 | prev=a; |
---|
| 159 | pIter(a); |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
| 163 | if (prev==NULL) |
---|
| 164 | { |
---|
| 165 | pDeleteLm(&result); |
---|
| 166 | a=result; |
---|
| 167 | } |
---|
| 168 | else |
---|
| 169 | { |
---|
| 170 | pDeleteLm(&pNext(prev)); |
---|
| 171 | a=pNext(prev); |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | } |
---|
[009d80] | 175 | #ifdef HAVE_RINGS |
---|
[b547dc] | 176 | if (nIsUnit(inv)) |
---|
| 177 | { |
---|
[ec1744b] | 178 | inv = nInvers(inv); |
---|
[b547dc] | 179 | pMult_nn(result,inv); |
---|
| 180 | nDelete(&inv); |
---|
| 181 | } |
---|
| 182 | else |
---|
| 183 | { |
---|
| 184 | pDiv_nn(result,inv); |
---|
| 185 | } |
---|
[009d80] | 186 | #else |
---|
[35aab3] | 187 | pMult_nn(result,inv); |
---|
| 188 | nDelete(&inv); |
---|
[b1f3b55] | 189 | #endif |
---|
[35aab3] | 190 | pDelete(&b); |
---|
| 191 | return result; |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /*2 |
---|
| 195 | * returns the LCM of the head terms of a and b in *m |
---|
| 196 | */ |
---|
| 197 | void pLcm(poly a, poly b, poly m) |
---|
| 198 | { |
---|
| 199 | int i; |
---|
| 200 | for (i=pVariables; i; i--) |
---|
| 201 | { |
---|
| 202 | pSetExp(m,i, si_max( pGetExp(a,i), pGetExp(b,i))); |
---|
| 203 | } |
---|
| 204 | pSetComp(m, si_max(pGetComp(a), pGetComp(b))); |
---|
| 205 | /* Don't do a pSetm here, otherwise hres/lres chockes */ |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | /*2 |
---|
| 209 | * convert monomial given as string to poly, e.g. 1x3y5z |
---|
| 210 | */ |
---|
[107986] | 211 | const char * p_Read(const char *st, poly &rc, const ring r) |
---|
[35aab3] | 212 | { |
---|
| 213 | if (r==NULL) { rc=NULL;return st;} |
---|
| 214 | int i,j; |
---|
| 215 | rc = p_Init(r); |
---|
[85e68dd] | 216 | const char *s = r->cf->nRead(st,&(rc->coef)); |
---|
[35aab3] | 217 | if (s==st) |
---|
| 218 | /* i.e. it does not start with a coeff: test if it is a ringvar*/ |
---|
| 219 | { |
---|
| 220 | j = r_IsRingVar(s,r); |
---|
| 221 | if (j >= 0) |
---|
| 222 | { |
---|
| 223 | p_IncrExp(rc,1+j,r); |
---|
| 224 | while (*s!='\0') s++; |
---|
| 225 | goto done; |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | while (*s!='\0') |
---|
| 229 | { |
---|
| 230 | char ss[2]; |
---|
| 231 | ss[0] = *s++; |
---|
| 232 | ss[1] = '\0'; |
---|
| 233 | j = r_IsRingVar(ss,r); |
---|
| 234 | if (j >= 0) |
---|
| 235 | { |
---|
[85e68dd] | 236 | const char *s_save=s; |
---|
[35aab3] | 237 | s = eati(s,&i); |
---|
[ded4ee] | 238 | if (((unsigned long)i) > r->bitmask) |
---|
| 239 | { |
---|
[9b10a76] | 240 | // exponent to large: it is not a monomial |
---|
[b529d9] | 241 | p_DeleteLm(&rc,r); |
---|
[ded4ee] | 242 | return s_save; |
---|
| 243 | } |
---|
[35aab3] | 244 | p_AddExp(rc,1+j, (Exponent_t)i, r); |
---|
| 245 | } |
---|
| 246 | else |
---|
| 247 | { |
---|
[b529d9] | 248 | // 1st char of is not a varname |
---|
| 249 | p_DeleteLm(&rc,r); |
---|
[35aab3] | 250 | s--; |
---|
| 251 | return s; |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | done: |
---|
| 255 | if (r->cf->nIsZero(pGetCoeff(rc))) p_DeleteLm(&rc,r); |
---|
| 256 | else |
---|
| 257 | { |
---|
[5d7a3b] | 258 | #ifdef HAVE_PLURAL |
---|
[9b10a76] | 259 | // in super-commutative ring |
---|
| 260 | // squares of anti-commutative variables are zeroes! |
---|
| 261 | if(rIsSCA(r)) |
---|
| 262 | { |
---|
| 263 | const unsigned int iFirstAltVar = scaFirstAltVar(r); |
---|
| 264 | const unsigned int iLastAltVar = scaLastAltVar(r); |
---|
| 265 | |
---|
| 266 | assume(rc != NULL); |
---|
| 267 | |
---|
| 268 | for(unsigned int k = iFirstAltVar; k <= iLastAltVar; k++) |
---|
| 269 | if( p_GetExp(rc, k, r) > 1 ) |
---|
| 270 | { |
---|
| 271 | p_DeleteLm(&rc, r); |
---|
| 272 | goto finish; |
---|
| 273 | } |
---|
[5d7a3b] | 274 | } |
---|
| 275 | #endif |
---|
[9b10a76] | 276 | |
---|
[35aab3] | 277 | p_Setm(rc,r); |
---|
| 278 | } |
---|
[9b10a76] | 279 | finish: |
---|
[35aab3] | 280 | return s; |
---|
| 281 | } |
---|
| 282 | |
---|
[85e68dd] | 283 | poly pmInit(const char *st, BOOLEAN &ok) |
---|
[35aab3] | 284 | { |
---|
| 285 | poly p; |
---|
[85e68dd] | 286 | const char *s=p_Read(st,p,currRing); |
---|
[35aab3] | 287 | if (*s!='\0') |
---|
| 288 | { |
---|
| 289 | if ((s!=st)&&isdigit(st[0])) |
---|
| 290 | { |
---|
| 291 | errorreported=TRUE; |
---|
| 292 | } |
---|
| 293 | ok=FALSE; |
---|
| 294 | pDelete(&p); |
---|
| 295 | return NULL; |
---|
| 296 | } |
---|
| 297 | ok=!errorreported; |
---|
| 298 | return p; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | /*2 |
---|
| 302 | *make p homogeneous by multiplying the monomials by powers of x_varnum |
---|
[5ef9d3] | 303 | *assume: deg(var(varnum))==1 |
---|
[35aab3] | 304 | */ |
---|
| 305 | poly pHomogen (poly p, int varnum) |
---|
| 306 | { |
---|
[37318d] | 307 | pFDegProc deg; |
---|
| 308 | if (pLexOrder && (currRing->order[0]==ringorder_lp)) |
---|
| 309 | deg=pTotaldegree; |
---|
| 310 | else |
---|
| 311 | deg=pFDeg; |
---|
| 312 | |
---|
[35aab3] | 313 | poly q=NULL, qn; |
---|
| 314 | int o,ii; |
---|
| 315 | sBucket_pt bp; |
---|
| 316 | |
---|
| 317 | if (p!=NULL) |
---|
| 318 | { |
---|
| 319 | if ((varnum < 1) || (varnum > pVariables)) |
---|
| 320 | { |
---|
| 321 | return NULL; |
---|
| 322 | } |
---|
[37318d] | 323 | o=deg(p,currRing); |
---|
[35aab3] | 324 | q=pNext(p); |
---|
| 325 | while (q != NULL) |
---|
| 326 | { |
---|
[37318d] | 327 | ii=deg(q,currRing); |
---|
[35aab3] | 328 | if (ii>o) o=ii; |
---|
| 329 | pIter(q); |
---|
| 330 | } |
---|
| 331 | q = pCopy(p); |
---|
| 332 | bp = sBucketCreate(currRing); |
---|
| 333 | while (q != NULL) |
---|
| 334 | { |
---|
[37318d] | 335 | ii = o-deg(q,currRing); |
---|
[35aab3] | 336 | if (ii!=0) |
---|
| 337 | { |
---|
| 338 | pAddExp(q,varnum, (Exponent_t)ii); |
---|
| 339 | pSetm(q); |
---|
| 340 | } |
---|
| 341 | qn = pNext(q); |
---|
| 342 | pNext(q) = NULL; |
---|
| 343 | sBucket_Add_p(bp, q, 1); |
---|
| 344 | q = qn; |
---|
| 345 | } |
---|
| 346 | sBucketDestroyAdd(bp, &q, &ii); |
---|
| 347 | } |
---|
| 348 | return q; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | /*2 |
---|
| 352 | *replaces the maximal powers of the leading monomial of p2 in p1 by |
---|
| 353 | *the same powers of n, utility for dehomogenization |
---|
| 354 | */ |
---|
| 355 | poly pDehomogen (poly p1,poly p2,number n) |
---|
| 356 | { |
---|
| 357 | polyset P; |
---|
| 358 | int SizeOfSet=5; |
---|
| 359 | int i; |
---|
| 360 | poly p; |
---|
| 361 | number nn; |
---|
| 362 | |
---|
| 363 | P = (polyset)omAlloc0(5*sizeof(poly)); |
---|
| 364 | //for (i=0; i<5; i++) |
---|
| 365 | //{ |
---|
| 366 | // P[i] = NULL; |
---|
| 367 | //} |
---|
| 368 | pCancelPolyByMonom(p1,p2,&P,&SizeOfSet); |
---|
| 369 | p = P[0]; |
---|
| 370 | //P[0] = NULL ;// for safety, may be removed later |
---|
| 371 | for (i=1; i<SizeOfSet; i++) |
---|
| 372 | { |
---|
| 373 | if (P[i] != NULL) |
---|
| 374 | { |
---|
| 375 | nPower(n,i,&nn); |
---|
| 376 | pMult_nn(P[i],nn); |
---|
| 377 | p = pAdd(p,P[i]); |
---|
| 378 | //P[i] =NULL; // for safety, may be removed later |
---|
| 379 | nDelete(&nn); |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | omFreeSize((ADDRESS)P,SizeOfSet*sizeof(poly)); |
---|
| 383 | return p; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | /*4 |
---|
| 387 | *Returns the exponent of the maximal power of the leading monomial of |
---|
| 388 | *p2 in that of p1 |
---|
| 389 | */ |
---|
| 390 | static int pGetMaxPower (poly p1,poly p2) |
---|
| 391 | { |
---|
| 392 | int i,k,res = 32000; /*a very large integer*/ |
---|
| 393 | |
---|
| 394 | if (p1 == NULL) return 0; |
---|
| 395 | for (i=1; i<=pVariables; i++) |
---|
| 396 | { |
---|
| 397 | if ( pGetExp(p2,i) != 0) |
---|
| 398 | { |
---|
| 399 | k = pGetExp(p1,i) / pGetExp(p2,i); |
---|
| 400 | if (k < res) res = k; |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | return res; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | /*2 |
---|
| 407 | *Returns as i-th entry of P the coefficient of the (i-1) power of |
---|
| 408 | *the leading monomial of p2 in p1 |
---|
| 409 | */ |
---|
| 410 | void pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet) |
---|
| 411 | { |
---|
| 412 | int maxPow; |
---|
| 413 | poly p,qp,Coeff; |
---|
| 414 | |
---|
| 415 | if (*P == NULL) |
---|
| 416 | { |
---|
| 417 | *P = (polyset) omAlloc(5*sizeof(poly)); |
---|
| 418 | *SizeOfSet = 5; |
---|
| 419 | } |
---|
| 420 | p = pCopy(p1); |
---|
| 421 | while (p != NULL) |
---|
| 422 | { |
---|
| 423 | qp = p->next; |
---|
| 424 | p->next = NULL; |
---|
| 425 | maxPow = pGetMaxPower(p,p2); |
---|
| 426 | Coeff = pDivByMonom(p,p2); |
---|
| 427 | if (maxPow > *SizeOfSet) |
---|
| 428 | { |
---|
| 429 | pEnlargeSet(P,*SizeOfSet,maxPow+1-*SizeOfSet); |
---|
| 430 | *SizeOfSet = maxPow+1; |
---|
| 431 | } |
---|
| 432 | (*P)[maxPow] = pAdd((*P)[maxPow],Coeff); |
---|
| 433 | pDelete(&p); |
---|
| 434 | p = qp; |
---|
| 435 | } |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | /*2 |
---|
| 439 | *returns the leading monomial of p1 divided by the maximal power of that |
---|
| 440 | *of p2 |
---|
| 441 | */ |
---|
| 442 | poly pDivByMonom (poly p1,poly p2) |
---|
| 443 | { |
---|
| 444 | int k, i; |
---|
| 445 | |
---|
| 446 | if (p1 == NULL) return NULL; |
---|
| 447 | k = pGetMaxPower(p1,p2); |
---|
| 448 | if (k == 0) |
---|
| 449 | return pHead(p1); |
---|
| 450 | else |
---|
| 451 | { |
---|
| 452 | number n; |
---|
| 453 | poly p = pInit(); |
---|
| 454 | |
---|
| 455 | p->next = NULL; |
---|
| 456 | for (i=1; i<=pVariables; i++) |
---|
| 457 | { |
---|
| 458 | pSetExp(p,i, pGetExp(p1,i)-k* pGetExp(p2,i)); |
---|
| 459 | } |
---|
| 460 | nPower(p2->coef,k,&n); |
---|
| 461 | pSetCoeff0(p,nDiv(p1->coef,n)); |
---|
| 462 | nDelete(&n); |
---|
| 463 | pSetm(p); |
---|
| 464 | return p; |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | /*----------utilities for syzygies--------------*/ |
---|
| 468 | poly pTakeOutComp(poly * p, int k) |
---|
| 469 | { |
---|
| 470 | poly q = *p,qq=NULL,result = NULL; |
---|
| 471 | |
---|
| 472 | if (q==NULL) return NULL; |
---|
[2b87ac9] | 473 | BOOLEAN use_setmcomp=rOrd_SetCompRequiresSetm(currRing); |
---|
[35aab3] | 474 | if (pGetComp(q)==k) |
---|
| 475 | { |
---|
| 476 | result = q; |
---|
[0ef842] | 477 | do |
---|
[35aab3] | 478 | { |
---|
| 479 | pSetComp(q,0); |
---|
[2b87ac9] | 480 | if (use_setmcomp) pSetmComp(q); |
---|
[35aab3] | 481 | qq = q; |
---|
| 482 | pIter(q); |
---|
| 483 | } |
---|
[0ef842] | 484 | while ((q!=NULL) && (pGetComp(q)==k)); |
---|
[35aab3] | 485 | *p = q; |
---|
| 486 | pNext(qq) = NULL; |
---|
| 487 | } |
---|
| 488 | if (q==NULL) return result; |
---|
| 489 | if (pGetComp(q) > k) |
---|
| 490 | { |
---|
| 491 | pDecrComp(q); |
---|
[2b87ac9] | 492 | if (use_setmcomp) pSetmComp(q); |
---|
[35aab3] | 493 | } |
---|
| 494 | poly pNext_q; |
---|
| 495 | while ((pNext_q=pNext(q))!=NULL) |
---|
| 496 | { |
---|
| 497 | if (pGetComp(pNext_q)==k) |
---|
| 498 | { |
---|
| 499 | if (result==NULL) |
---|
| 500 | { |
---|
| 501 | result = pNext_q; |
---|
| 502 | qq = result; |
---|
| 503 | } |
---|
| 504 | else |
---|
| 505 | { |
---|
| 506 | pNext(qq) = pNext_q; |
---|
| 507 | pIter(qq); |
---|
| 508 | } |
---|
| 509 | pNext(q) = pNext(pNext_q); |
---|
| 510 | pNext(qq) =NULL; |
---|
| 511 | pSetComp(qq,0); |
---|
[2b87ac9] | 512 | if (use_setmcomp) pSetmComp(qq); |
---|
[35aab3] | 513 | } |
---|
| 514 | else |
---|
| 515 | { |
---|
| 516 | /*pIter(q);*/ q=pNext_q; |
---|
| 517 | if (pGetComp(q) > k) |
---|
| 518 | { |
---|
| 519 | pDecrComp(q); |
---|
[2b87ac9] | 520 | if (use_setmcomp) pSetmComp(q); |
---|
[35aab3] | 521 | } |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | return result; |
---|
| 525 | } |
---|
| 526 | |
---|
| 527 | // Splits *p into two polys: *q which consists of all monoms with |
---|
| 528 | // component == comp and *p of all other monoms *lq == pLength(*q) |
---|
| 529 | void pTakeOutComp(poly *r_p, Exponent_t comp, poly *r_q, int *lq) |
---|
| 530 | { |
---|
| 531 | spolyrec pp, qq; |
---|
| 532 | poly p, q, p_prev; |
---|
| 533 | int l = 0; |
---|
| 534 | |
---|
| 535 | #ifdef HAVE_ASSUME |
---|
| 536 | int lp = pLength(*r_p); |
---|
| 537 | #endif |
---|
| 538 | |
---|
| 539 | pNext(&pp) = *r_p; |
---|
| 540 | p = *r_p; |
---|
| 541 | p_prev = &pp; |
---|
| 542 | q = &qq; |
---|
| 543 | |
---|
| 544 | while(p != NULL) |
---|
| 545 | { |
---|
| 546 | while (pGetComp(p) == comp) |
---|
| 547 | { |
---|
| 548 | pNext(q) = p; |
---|
| 549 | pIter(q); |
---|
| 550 | pSetComp(p, 0); |
---|
| 551 | pSetmComp(p); |
---|
| 552 | pIter(p); |
---|
| 553 | l++; |
---|
| 554 | if (p == NULL) |
---|
| 555 | { |
---|
| 556 | pNext(p_prev) = NULL; |
---|
| 557 | goto Finish; |
---|
| 558 | } |
---|
| 559 | } |
---|
| 560 | pNext(p_prev) = p; |
---|
| 561 | p_prev = p; |
---|
| 562 | pIter(p); |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | Finish: |
---|
| 566 | pNext(q) = NULL; |
---|
| 567 | *r_p = pNext(&pp); |
---|
| 568 | *r_q = pNext(&qq); |
---|
| 569 | *lq = l; |
---|
| 570 | #ifdef HAVE_ASSUME |
---|
| 571 | assume(pLength(*r_p) + pLength(*r_q) == lp); |
---|
| 572 | #endif |
---|
| 573 | pTest(*r_p); |
---|
| 574 | pTest(*r_q); |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | void pDecrOrdTakeOutComp(poly *r_p, Exponent_t comp, Order_t order, |
---|
| 578 | poly *r_q, int *lq) |
---|
| 579 | { |
---|
| 580 | spolyrec pp, qq; |
---|
| 581 | poly p, q, p_prev; |
---|
| 582 | int l = 0; |
---|
| 583 | |
---|
| 584 | pNext(&pp) = *r_p; |
---|
| 585 | p = *r_p; |
---|
| 586 | p_prev = &pp; |
---|
| 587 | q = &qq; |
---|
| 588 | |
---|
| 589 | #ifdef HAVE_ASSUME |
---|
| 590 | if (p != NULL) |
---|
| 591 | { |
---|
| 592 | while (pNext(p) != NULL) |
---|
| 593 | { |
---|
| 594 | assume(pGetOrder(p) >= pGetOrder(pNext(p))); |
---|
| 595 | pIter(p); |
---|
| 596 | } |
---|
| 597 | } |
---|
| 598 | p = *r_p; |
---|
| 599 | #endif |
---|
| 600 | |
---|
| 601 | while (p != NULL && pGetOrder(p) > order) pIter(p); |
---|
| 602 | |
---|
| 603 | while(p != NULL && pGetOrder(p) == order) |
---|
| 604 | { |
---|
| 605 | while (pGetComp(p) == comp) |
---|
| 606 | { |
---|
| 607 | pNext(q) = p; |
---|
| 608 | pIter(q); |
---|
| 609 | pIter(p); |
---|
| 610 | pSetComp(p, 0); |
---|
| 611 | pSetmComp(p); |
---|
| 612 | l++; |
---|
| 613 | if (p == NULL || pGetOrder(p) != order) |
---|
| 614 | { |
---|
| 615 | pNext(p_prev) = p; |
---|
| 616 | goto Finish; |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | pNext(p_prev) = p; |
---|
| 620 | p_prev = p; |
---|
| 621 | pIter(p); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | Finish: |
---|
| 625 | pNext(q) = NULL; |
---|
| 626 | *r_p = pNext(&pp); |
---|
| 627 | *r_q = pNext(&qq); |
---|
| 628 | *lq = l; |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | #if 1 |
---|
| 632 | poly pTakeOutComp1(poly * p, int k) |
---|
| 633 | { |
---|
| 634 | poly q = *p; |
---|
| 635 | |
---|
| 636 | if (q==NULL) return NULL; |
---|
| 637 | |
---|
| 638 | poly qq=NULL,result = NULL; |
---|
| 639 | |
---|
| 640 | if (pGetComp(q)==k) |
---|
| 641 | { |
---|
| 642 | result = q; /* *p */ |
---|
| 643 | while ((q!=NULL) && (pGetComp(q)==k)) |
---|
| 644 | { |
---|
| 645 | pSetComp(q,0); |
---|
| 646 | pSetmComp(q); |
---|
| 647 | qq = q; |
---|
| 648 | pIter(q); |
---|
| 649 | } |
---|
| 650 | *p = q; |
---|
| 651 | pNext(qq) = NULL; |
---|
| 652 | } |
---|
| 653 | if (q==NULL) return result; |
---|
| 654 | // if (pGetComp(q) > k) pGetComp(q)--; |
---|
| 655 | while (pNext(q)!=NULL) |
---|
| 656 | { |
---|
| 657 | if (pGetComp(pNext(q))==k) |
---|
| 658 | { |
---|
| 659 | if (result==NULL) |
---|
| 660 | { |
---|
| 661 | result = pNext(q); |
---|
| 662 | qq = result; |
---|
| 663 | } |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | pNext(qq) = pNext(q); |
---|
| 667 | pIter(qq); |
---|
| 668 | } |
---|
| 669 | pNext(q) = pNext(pNext(q)); |
---|
| 670 | pNext(qq) =NULL; |
---|
| 671 | pSetComp(qq,0); |
---|
| 672 | pSetmComp(qq); |
---|
| 673 | } |
---|
| 674 | else |
---|
| 675 | { |
---|
| 676 | pIter(q); |
---|
| 677 | // if (pGetComp(q) > k) pGetComp(q)--; |
---|
| 678 | } |
---|
| 679 | } |
---|
| 680 | return result; |
---|
| 681 | } |
---|
| 682 | #endif |
---|
| 683 | |
---|
| 684 | void pDeleteComp(poly * p,int k) |
---|
| 685 | { |
---|
| 686 | poly q; |
---|
| 687 | |
---|
| 688 | while ((*p!=NULL) && (pGetComp(*p)==k)) pDeleteLm(p); |
---|
| 689 | if (*p==NULL) return; |
---|
| 690 | q = *p; |
---|
| 691 | if (pGetComp(q)>k) |
---|
| 692 | { |
---|
| 693 | pDecrComp(q); |
---|
| 694 | pSetmComp(q); |
---|
| 695 | } |
---|
| 696 | while (pNext(q)!=NULL) |
---|
| 697 | { |
---|
| 698 | if (pGetComp(pNext(q))==k) |
---|
| 699 | pDeleteLm(&(pNext(q))); |
---|
| 700 | else |
---|
| 701 | { |
---|
| 702 | pIter(q); |
---|
| 703 | if (pGetComp(q)>k) |
---|
| 704 | { |
---|
| 705 | pDecrComp(q); |
---|
| 706 | pSetmComp(q); |
---|
| 707 | } |
---|
| 708 | } |
---|
| 709 | } |
---|
| 710 | } |
---|
| 711 | /*----------end of utilities for syzygies--------------*/ |
---|
| 712 | |
---|
| 713 | /*2 |
---|
| 714 | * pair has no common factor ? or is no polynomial |
---|
| 715 | */ |
---|
| 716 | BOOLEAN pHasNotCF(poly p1, poly p2) |
---|
| 717 | { |
---|
| 718 | |
---|
[1c35568] | 719 | if (pGetComp(p1) > 0 || pGetComp(p2) > 0) |
---|
| 720 | return FALSE; |
---|
[d2fb9b7] | 721 | int i = pVariables; |
---|
[35aab3] | 722 | loop |
---|
| 723 | { |
---|
| 724 | if ((pGetExp(p1, i) > 0) && (pGetExp(p2, i) > 0)) return FALSE; |
---|
[d2fb9b7] | 725 | i--; |
---|
| 726 | if (i == 0) return TRUE; |
---|
[35aab3] | 727 | } |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | /*2 |
---|
| 731 | *divides p1 by its leading coefficient |
---|
| 732 | */ |
---|
| 733 | void pNorm(poly p1) |
---|
| 734 | { |
---|
[009d80] | 735 | #ifdef HAVE_RINGS |
---|
| 736 | if (rField_is_Ring(currRing)) |
---|
[585bbcb] | 737 | { |
---|
[521349] | 738 | Werror("pNorm not possible in the case of coefficient rings."); |
---|
[585bbcb] | 739 | } |
---|
[994445] | 740 | else |
---|
[f92547] | 741 | #endif |
---|
[35aab3] | 742 | if (p1!=NULL) |
---|
| 743 | { |
---|
[5e8fe91] | 744 | if (pNext(p1)==NULL) |
---|
| 745 | { |
---|
[98938c] | 746 | pSetCoeff(p1,nInit(1)); |
---|
[5e8fe91] | 747 | return; |
---|
| 748 | } |
---|
[521349] | 749 | poly h; |
---|
[35aab3] | 750 | if (!nIsOne(pGetCoeff(p1))) |
---|
| 751 | { |
---|
[521349] | 752 | number k, c; |
---|
[35aab3] | 753 | nNormalize(pGetCoeff(p1)); |
---|
[585bbcb] | 754 | k = pGetCoeff(p1); |
---|
[35aab3] | 755 | c = nInit(1); |
---|
| 756 | pSetCoeff0(p1,c); |
---|
| 757 | h = pNext(p1); |
---|
| 758 | while (h!=NULL) |
---|
| 759 | { |
---|
| 760 | c=nDiv(pGetCoeff(h),k); |
---|
[7ba059] | 761 | // no need to normalize: Z/p, R |
---|
| 762 | // normalize already in nDiv: Q_a, Z/p_a |
---|
| 763 | // remains: Q |
---|
| 764 | if (rField_is_Q() && (!nIsOne(c))) nNormalize(c); |
---|
[35aab3] | 765 | pSetCoeff(h,c); |
---|
| 766 | pIter(h); |
---|
| 767 | } |
---|
| 768 | nDelete(&k); |
---|
| 769 | } |
---|
| 770 | else |
---|
| 771 | { |
---|
| 772 | if (nNormalize != nDummy2) |
---|
| 773 | { |
---|
| 774 | h = pNext(p1); |
---|
| 775 | while (h!=NULL) |
---|
| 776 | { |
---|
| 777 | nNormalize(pGetCoeff(h)); |
---|
| 778 | pIter(h); |
---|
| 779 | } |
---|
| 780 | } |
---|
| 781 | } |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | /*2 |
---|
| 786 | *normalize all coefficients |
---|
| 787 | */ |
---|
[107986] | 788 | void p_Normalize(poly p,const ring r) |
---|
[35aab3] | 789 | { |
---|
| 790 | if (rField_has_simple_inverse(r)) return; /* Z/p, GF(p,n), R, long R/C */ |
---|
| 791 | while (p!=NULL) |
---|
| 792 | { |
---|
[47b2b2d] | 793 | #ifdef LDEBUG |
---|
[35aab3] | 794 | if (currRing==r) {nTest(pGetCoeff(p));} |
---|
[47b2b2d] | 795 | #endif |
---|
[35aab3] | 796 | n_Normalize(pGetCoeff(p),r); |
---|
| 797 | pIter(p); |
---|
| 798 | } |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | // splits p into polys with Exp(n) == 0 and Exp(n) != 0 |
---|
| 802 | // Poly with Exp(n) != 0 is reversed |
---|
| 803 | static void pSplitAndReversePoly(poly p, int n, poly *non_zero, poly *zero) |
---|
| 804 | { |
---|
| 805 | if (p == NULL) |
---|
| 806 | { |
---|
| 807 | *non_zero = NULL; |
---|
| 808 | *zero = NULL; |
---|
| 809 | return; |
---|
| 810 | } |
---|
| 811 | spolyrec sz; |
---|
| 812 | poly z, n_z, next; |
---|
| 813 | z = &sz; |
---|
| 814 | n_z = NULL; |
---|
| 815 | |
---|
| 816 | while(p != NULL) |
---|
| 817 | { |
---|
| 818 | next = pNext(p); |
---|
| 819 | if (pGetExp(p, n) == 0) |
---|
| 820 | { |
---|
| 821 | pNext(z) = p; |
---|
| 822 | pIter(z); |
---|
| 823 | } |
---|
| 824 | else |
---|
| 825 | { |
---|
| 826 | pNext(p) = n_z; |
---|
| 827 | n_z = p; |
---|
| 828 | } |
---|
| 829 | p = next; |
---|
| 830 | } |
---|
| 831 | pNext(z) = NULL; |
---|
| 832 | *zero = pNext(&sz); |
---|
| 833 | *non_zero = n_z; |
---|
| 834 | return; |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | /*3 |
---|
| 838 | * substitute the n-th variable by 1 in p |
---|
| 839 | * destroy p |
---|
| 840 | */ |
---|
| 841 | static poly pSubst1 (poly p,int n) |
---|
| 842 | { |
---|
[788529d] | 843 | poly qq=NULL, result = NULL; |
---|
| 844 | poly zero=NULL, non_zero=NULL; |
---|
[35aab3] | 845 | |
---|
| 846 | // reverse, so that add is likely to be linear |
---|
| 847 | pSplitAndReversePoly(p, n, &non_zero, &zero); |
---|
| 848 | |
---|
| 849 | while (non_zero != NULL) |
---|
| 850 | { |
---|
| 851 | assume(pGetExp(non_zero, n) != 0); |
---|
| 852 | qq = non_zero; |
---|
| 853 | pIter(non_zero); |
---|
| 854 | qq->next = NULL; |
---|
| 855 | pSetExp(qq,n,0); |
---|
| 856 | pSetm(qq); |
---|
| 857 | result = pAdd(result,qq); |
---|
| 858 | } |
---|
| 859 | p = pAdd(result, zero); |
---|
| 860 | pTest(p); |
---|
| 861 | return p; |
---|
| 862 | } |
---|
| 863 | |
---|
| 864 | /*3 |
---|
| 865 | * substitute the n-th variable by number e in p |
---|
| 866 | * destroy p |
---|
| 867 | */ |
---|
| 868 | static poly pSubst2 (poly p,int n, number e) |
---|
| 869 | { |
---|
| 870 | assume( ! nIsZero(e) ); |
---|
| 871 | poly qq,result = NULL; |
---|
| 872 | number nn, nm; |
---|
| 873 | poly zero, non_zero; |
---|
| 874 | |
---|
| 875 | // reverse, so that add is likely to be linear |
---|
| 876 | pSplitAndReversePoly(p, n, &non_zero, &zero); |
---|
| 877 | |
---|
| 878 | while (non_zero != NULL) |
---|
| 879 | { |
---|
| 880 | assume(pGetExp(non_zero, n) != 0); |
---|
| 881 | qq = non_zero; |
---|
| 882 | pIter(non_zero); |
---|
| 883 | qq->next = NULL; |
---|
| 884 | nPower(e, pGetExp(qq, n), &nn); |
---|
| 885 | nm = nMult(nn, pGetCoeff(qq)); |
---|
[67dbdb] | 886 | #ifdef HAVE_RINGS |
---|
| 887 | if (nIsZero(nm)) |
---|
| 888 | { |
---|
| 889 | pLmFree(&qq); |
---|
| 890 | nDelete(&nm); |
---|
| 891 | } |
---|
| 892 | else |
---|
| 893 | #endif |
---|
| 894 | { |
---|
| 895 | pSetCoeff(qq, nm); |
---|
| 896 | pSetExp(qq, n, 0); |
---|
| 897 | pSetm(qq); |
---|
| 898 | result = pAdd(result,qq); |
---|
| 899 | } |
---|
[35aab3] | 900 | nDelete(&nn); |
---|
| 901 | } |
---|
| 902 | p = pAdd(result, zero); |
---|
| 903 | pTest(p); |
---|
| 904 | return p; |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | |
---|
| 908 | /* delete monoms whose n-th exponent is different from zero */ |
---|
| 909 | poly pSubst0(poly p, int n) |
---|
| 910 | { |
---|
| 911 | spolyrec res; |
---|
| 912 | poly h = &res; |
---|
| 913 | pNext(h) = p; |
---|
| 914 | |
---|
| 915 | while (pNext(h)!=NULL) |
---|
| 916 | { |
---|
| 917 | if (pGetExp(pNext(h),n)!=0) |
---|
| 918 | { |
---|
| 919 | pDeleteLm(&pNext(h)); |
---|
| 920 | } |
---|
| 921 | else |
---|
| 922 | { |
---|
| 923 | pIter(h); |
---|
| 924 | } |
---|
| 925 | } |
---|
| 926 | pTest(pNext(&res)); |
---|
| 927 | return pNext(&res); |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | /*2 |
---|
| 931 | * substitute the n-th variable by e in p |
---|
| 932 | * destroy p |
---|
| 933 | */ |
---|
| 934 | poly pSubst(poly p, int n, poly e) |
---|
| 935 | { |
---|
| 936 | if (e == NULL) return pSubst0(p, n); |
---|
| 937 | |
---|
| 938 | if (pIsConstant(e)) |
---|
| 939 | { |
---|
| 940 | if (nIsOne(pGetCoeff(e))) return pSubst1(p,n); |
---|
| 941 | else return pSubst2(p, n, pGetCoeff(e)); |
---|
| 942 | } |
---|
| 943 | |
---|
[68349d] | 944 | #ifdef HAVE_PLURAL |
---|
| 945 | if (rIsPluralRing(currRing)) |
---|
| 946 | { |
---|
| 947 | return nc_pSubst(p,n,e); |
---|
| 948 | } |
---|
| 949 | #endif |
---|
| 950 | |
---|
[35aab3] | 951 | int exponent,i; |
---|
| 952 | poly h, res, m; |
---|
| 953 | int *me,*ee; |
---|
| 954 | number nu,nu1; |
---|
| 955 | |
---|
| 956 | me=(int *)omAlloc((pVariables+1)*sizeof(int)); |
---|
| 957 | ee=(int *)omAlloc((pVariables+1)*sizeof(int)); |
---|
| 958 | if (e!=NULL) pGetExpV(e,ee); |
---|
| 959 | res=NULL; |
---|
| 960 | h=p; |
---|
| 961 | while (h!=NULL) |
---|
| 962 | { |
---|
| 963 | if ((e!=NULL) || (pGetExp(h,n)==0)) |
---|
| 964 | { |
---|
| 965 | m=pHead(h); |
---|
| 966 | pGetExpV(m,me); |
---|
| 967 | exponent=me[n]; |
---|
| 968 | me[n]=0; |
---|
| 969 | for(i=pVariables;i>0;i--) |
---|
| 970 | me[i]+=exponent*ee[i]; |
---|
| 971 | pSetExpV(m,me); |
---|
| 972 | if (e!=NULL) |
---|
| 973 | { |
---|
| 974 | nPower(pGetCoeff(e),exponent,&nu); |
---|
| 975 | nu1=nMult(pGetCoeff(m),nu); |
---|
| 976 | nDelete(&nu); |
---|
| 977 | pSetCoeff(m,nu1); |
---|
| 978 | } |
---|
| 979 | res=pAdd(res,m); |
---|
| 980 | } |
---|
| 981 | pDeleteLm(&h); |
---|
| 982 | } |
---|
| 983 | omFreeSize((ADDRESS)me,(pVariables+1)*sizeof(int)); |
---|
| 984 | omFreeSize((ADDRESS)ee,(pVariables+1)*sizeof(int)); |
---|
| 985 | return res; |
---|
| 986 | } |
---|
| 987 | |
---|
[a2466f] | 988 | /* Returns TRUE if |
---|
| 989 | * LM(p) | LM(lcm) |
---|
| 990 | * LC(p) | LC(lcm) only if ring |
---|
| 991 | * Exists i, j: |
---|
| 992 | * LE(p, i) != LE(lcm, i) |
---|
| 993 | * LE(p1, i) != LE(lcm, i) ==> LCM(p1, p) != lcm |
---|
| 994 | * LE(p, j) != LE(lcm, j) |
---|
| 995 | * LE(p2, j) != LE(lcm, j) ==> LCM(p2, p) != lcm |
---|
| 996 | */ |
---|
[35aab3] | 997 | BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm) |
---|
| 998 | { |
---|
| 999 | int k, j; |
---|
| 1000 | |
---|
| 1001 | if (lcm==NULL) return FALSE; |
---|
| 1002 | |
---|
| 1003 | for (j=pVariables; j; j--) |
---|
| 1004 | if ( pGetExp(p,j) > pGetExp(lcm,j)) return FALSE; |
---|
| 1005 | if ( pGetComp(p) != pGetComp(lcm)) return FALSE; |
---|
| 1006 | for (j=pVariables; j; j--) |
---|
| 1007 | { |
---|
| 1008 | if (pGetExp(p1,j)!=pGetExp(lcm,j)) |
---|
| 1009 | { |
---|
| 1010 | if (pGetExp(p,j)!=pGetExp(lcm,j)) |
---|
| 1011 | { |
---|
| 1012 | for (k=pVariables; k>j; k--) |
---|
| 1013 | { |
---|
| 1014 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1015 | && (pGetExp(p2,k)!=pGetExp(lcm,k))) |
---|
| 1016 | return TRUE; |
---|
| 1017 | } |
---|
| 1018 | for (k=j-1; k; k--) |
---|
| 1019 | { |
---|
| 1020 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1021 | && (pGetExp(p2,k)!=pGetExp(lcm,k))) |
---|
| 1022 | return TRUE; |
---|
| 1023 | } |
---|
| 1024 | return FALSE; |
---|
| 1025 | } |
---|
| 1026 | } |
---|
| 1027 | else if (pGetExp(p2,j)!=pGetExp(lcm,j)) |
---|
| 1028 | { |
---|
| 1029 | if (pGetExp(p,j)!=pGetExp(lcm,j)) |
---|
| 1030 | { |
---|
| 1031 | for (k=pVariables; k>j; k--) |
---|
| 1032 | { |
---|
| 1033 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1034 | && (pGetExp(p1,k)!=pGetExp(lcm,k))) |
---|
| 1035 | return TRUE; |
---|
| 1036 | } |
---|
| 1037 | for (k=j-1; k!=0 ; k--) |
---|
| 1038 | { |
---|
| 1039 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1040 | && (pGetExp(p1,k)!=pGetExp(lcm,k))) |
---|
| 1041 | return TRUE; |
---|
| 1042 | } |
---|
| 1043 | return FALSE; |
---|
| 1044 | } |
---|
| 1045 | } |
---|
| 1046 | } |
---|
| 1047 | return FALSE; |
---|
| 1048 | } |
---|
[27e750] | 1049 | #ifdef HAVE_RATGRING |
---|
[107986] | 1050 | BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm) |
---|
| 1051 | { |
---|
| 1052 | int k, j; |
---|
| 1053 | |
---|
| 1054 | if (lcm==NULL) return FALSE; |
---|
| 1055 | |
---|
| 1056 | for (j=currRing->real_var_end; j>=currRing->real_var_start; j--) |
---|
| 1057 | if ( pGetExp(p,j) > pGetExp(lcm,j)) return FALSE; |
---|
| 1058 | if ( pGetComp(p) != pGetComp(lcm)) return FALSE; |
---|
| 1059 | for (j=currRing->real_var_end; j>=currRing->real_var_start; j--) |
---|
| 1060 | { |
---|
| 1061 | if (pGetExp(p1,j)!=pGetExp(lcm,j)) |
---|
| 1062 | { |
---|
| 1063 | if (pGetExp(p,j)!=pGetExp(lcm,j)) |
---|
| 1064 | { |
---|
| 1065 | for (k=pVariables; k>j; k--) |
---|
| 1066 | for (k=currRing->real_var_end; k>j; k--) |
---|
| 1067 | { |
---|
| 1068 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1069 | && (pGetExp(p2,k)!=pGetExp(lcm,k))) |
---|
| 1070 | return TRUE; |
---|
| 1071 | } |
---|
| 1072 | for (k=j-1; k>=currRing->real_var_start; k--) |
---|
| 1073 | { |
---|
| 1074 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1075 | && (pGetExp(p2,k)!=pGetExp(lcm,k))) |
---|
| 1076 | return TRUE; |
---|
| 1077 | } |
---|
| 1078 | return FALSE; |
---|
| 1079 | } |
---|
| 1080 | } |
---|
| 1081 | else if (pGetExp(p2,j)!=pGetExp(lcm,j)) |
---|
| 1082 | { |
---|
| 1083 | if (pGetExp(p,j)!=pGetExp(lcm,j)) |
---|
| 1084 | { |
---|
| 1085 | for (k=currRing->real_var_end; k>j; k--) |
---|
| 1086 | { |
---|
| 1087 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1088 | && (pGetExp(p1,k)!=pGetExp(lcm,k))) |
---|
| 1089 | return TRUE; |
---|
| 1090 | } |
---|
| 1091 | for (k=j-1; k>=currRing->real_var_start; k--) |
---|
| 1092 | { |
---|
| 1093 | if ((pGetExp(p,k)!=pGetExp(lcm,k)) |
---|
| 1094 | && (pGetExp(p1,k)!=pGetExp(lcm,k))) |
---|
| 1095 | return TRUE; |
---|
| 1096 | } |
---|
| 1097 | return FALSE; |
---|
| 1098 | } |
---|
| 1099 | } |
---|
| 1100 | } |
---|
| 1101 | return FALSE; |
---|
| 1102 | } |
---|
[27e750] | 1103 | #endif |
---|
[7ba059] | 1104 | |
---|
| 1105 | int pSize(poly p) |
---|
| 1106 | { |
---|
| 1107 | int count = 0; |
---|
| 1108 | while ( p != NULL ) |
---|
| 1109 | { |
---|
| 1110 | count+= nSize( pGetCoeff( p ) ); |
---|
| 1111 | pIter( p ); |
---|
| 1112 | } |
---|
| 1113 | return count; |
---|
| 1114 | } |
---|
| 1115 | |
---|
[48884f2] | 1116 | /*2 |
---|
| 1117 | * returns the length of a (numbers of monomials) |
---|
| 1118 | * respect syzComp |
---|
| 1119 | */ |
---|
| 1120 | poly pLast(poly a, int &l) |
---|
| 1121 | { |
---|
| 1122 | if (a == NULL) |
---|
| 1123 | { |
---|
| 1124 | l = 0; |
---|
| 1125 | return NULL; |
---|
| 1126 | } |
---|
| 1127 | l = 1; |
---|
| 1128 | if (! rIsSyzIndexRing(currRing)) |
---|
| 1129 | { |
---|
| 1130 | while (pNext(a)!=NULL) |
---|
| 1131 | { |
---|
| 1132 | pIter(a); |
---|
| 1133 | l++; |
---|
| 1134 | } |
---|
| 1135 | } |
---|
| 1136 | else |
---|
| 1137 | { |
---|
| 1138 | int curr_limit = rGetCurrSyzLimit(currRing); |
---|
| 1139 | poly pp = a; |
---|
| 1140 | while ((a=pNext(a))!=NULL) |
---|
| 1141 | { |
---|
| 1142 | if (pGetComp(a)<=curr_limit/*syzComp*/) |
---|
| 1143 | l++; |
---|
| 1144 | else break; |
---|
| 1145 | pp = a; |
---|
| 1146 | } |
---|
| 1147 | a=pp; |
---|
| 1148 | } |
---|
| 1149 | return a; |
---|
| 1150 | } |
---|
| 1151 | |
---|