[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /*************************************************************** |
---|
| 5 | * File: pInline1.h |
---|
| 6 | * Purpose: implementation of poly procs which iter over ExpVector |
---|
| 7 | * Author: obachman (Olaf Bachmann) |
---|
| 8 | * Created: 8/00 |
---|
[341696] | 9 | * Version: $Id$ |
---|
[35aab3] | 10 | *******************************************************************/ |
---|
| 11 | #ifndef PINLINE1_H |
---|
| 12 | #define PINLINE1_H |
---|
| 13 | |
---|
| 14 | #ifndef PDIV_DEBUG |
---|
| 15 | // define to enable debugging/statistics of pLmShortDivisibleBy |
---|
| 16 | // #define PDIV_DEBUG |
---|
| 17 | #endif |
---|
| 18 | #include <mylimits.h> |
---|
[599326] | 19 | #include <kernel/p_MemCmp.h> |
---|
| 20 | #include <kernel/structs.h> |
---|
| 21 | #include <kernel/ring.h> |
---|
| 22 | #include <kernel/numbers.h> |
---|
[35aab3] | 23 | |
---|
| 24 | #if PDEBUG > 0 || defined(NO_PINLINE1) |
---|
| 25 | |
---|
| 26 | #define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
| 27 | do \ |
---|
| 28 | { \ |
---|
| 29 | int _cmp = p_LmCmp(p,q,r); \ |
---|
| 30 | if (_cmp == 0) actionE; \ |
---|
| 31 | if (_cmp == 1) actionG; \ |
---|
| 32 | actionS; \ |
---|
| 33 | } \ |
---|
| 34 | while(0) |
---|
| 35 | |
---|
| 36 | #else |
---|
| 37 | |
---|
| 38 | #define _p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ |
---|
| 39 | p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn, \ |
---|
| 40 | actionE, actionG, actionS) |
---|
| 41 | |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | #ifdef PDIV_DEBUG |
---|
[3f685c] | 45 | BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, const ring r_1, |
---|
| 46 | poly p2, unsigned long not_sev_2, const ring r_2); |
---|
| 47 | BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, const ring r); |
---|
[35aab3] | 48 | #define pDivAssume pAssume |
---|
| 49 | #else |
---|
| 50 | #define pDivAssume(x) ((void)0) |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | #if !defined(NO_PINLINE1) || defined(PINLINE1_CC) |
---|
| 54 | |
---|
[599326] | 55 | #include <omalloc.h> |
---|
| 56 | #include <kernel/numbers.h> |
---|
| 57 | #include <kernel/p_polys.h> |
---|
| 58 | #include <kernel/p_MemAdd.h> |
---|
| 59 | #include <kernel/p_MemCopy.h> |
---|
[35aab3] | 60 | |
---|
| 61 | /*************************************************************** |
---|
| 62 | * |
---|
| 63 | * Allocation/Initalization/Deletion |
---|
| 64 | * |
---|
| 65 | ***************************************************************/ |
---|
| 66 | // adjustments for negative weights |
---|
[3f685c] | 67 | PINLINE1 void p_MemAdd_NegWeightAdjust(poly p, const ring r) |
---|
[35aab3] | 68 | { |
---|
| 69 | if (r->NegWeightL_Offset != NULL) |
---|
| 70 | { |
---|
| 71 | for (int i=r->NegWeightL_Size-1; i>=0; i--) |
---|
| 72 | { |
---|
| 73 | p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
[3f685c] | 77 | PINLINE1 void p_MemSub_NegWeightAdjust(poly p, const ring r) |
---|
[35aab3] | 78 | { |
---|
| 79 | if (r->NegWeightL_Offset != NULL) |
---|
| 80 | { |
---|
| 81 | for (int i=r->NegWeightL_Size-1; i>=0; i--) |
---|
| 82 | { |
---|
| 83 | p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | // ExpVextor(d_p) = ExpVector(s_p) |
---|
[3f685c] | 88 | PINLINE1 void p_ExpVectorCopy(poly d_p, poly s_p, const ring r) |
---|
[35aab3] | 89 | { |
---|
| 90 | p_LmCheckPolyRing1(d_p, r); |
---|
| 91 | p_LmCheckPolyRing1(s_p, r); |
---|
| 92 | p_MemCopy_LengthGeneral(d_p->exp, s_p->exp, r->ExpL_Size); |
---|
| 93 | } |
---|
| 94 | |
---|
[3f685c] | 95 | PINLINE1 poly p_Init(const ring r, omBin bin) |
---|
[35aab3] | 96 | { |
---|
| 97 | p_CheckRing1(r); |
---|
| 98 | pAssume1(bin != NULL && r->PolyBin->sizeW == bin->sizeW); |
---|
| 99 | poly p; |
---|
| 100 | omTypeAlloc0Bin(poly, p, bin); |
---|
| 101 | p_MemAdd_NegWeightAdjust(p, r); |
---|
| 102 | p_SetRingOfLm(p, r); |
---|
| 103 | return p; |
---|
| 104 | } |
---|
[3f685c] | 105 | PINLINE1 poly p_Init(const ring r) |
---|
[35aab3] | 106 | { |
---|
| 107 | return p_Init(r, r->PolyBin); |
---|
| 108 | } |
---|
| 109 | |
---|
[3f685c] | 110 | PINLINE1 poly p_LmInit(poly p, const ring r) |
---|
[35aab3] | 111 | { |
---|
| 112 | p_LmCheckPolyRing1(p, r); |
---|
| 113 | poly np; |
---|
| 114 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
| 115 | p_SetRingOfLm(np, r); |
---|
| 116 | p_ExpVectorCopy(np, p, r); |
---|
[367c32] | 117 | pNext(np) = NULL; |
---|
| 118 | pSetCoeff0(np, NULL); |
---|
[35aab3] | 119 | return np; |
---|
| 120 | } |
---|
[3f685c] | 121 | PINLINE1 poly p_LmInit(poly s_p, const ring s_r, const ring d_r) |
---|
[35aab3] | 122 | { |
---|
| 123 | pAssume1(d_r != NULL); |
---|
| 124 | return p_LmInit(s_p, s_r, d_r, d_r->PolyBin); |
---|
| 125 | } |
---|
[3f685c] | 126 | PINLINE1 poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin) |
---|
[35aab3] | 127 | { |
---|
| 128 | p_LmCheckPolyRing1(s_p, s_r); |
---|
| 129 | p_CheckRing(d_r); |
---|
| 130 | pAssume1(d_r->N <= s_r->N); |
---|
| 131 | poly d_p = p_Init(d_r, d_bin); |
---|
| 132 | for (int i=d_r->N; i>0; i--) |
---|
| 133 | { |
---|
| 134 | p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r); |
---|
| 135 | } |
---|
| 136 | if (rRing_has_Comp(d_r)) |
---|
| 137 | { |
---|
| 138 | p_SetComp(d_p, p_GetComp(s_p,s_r), d_r); |
---|
| 139 | } |
---|
| 140 | p_Setm(d_p, d_r); |
---|
| 141 | return d_p; |
---|
| 142 | } |
---|
[3f685c] | 143 | PINLINE1 poly p_Head(poly p, const ring r) |
---|
[35aab3] | 144 | { |
---|
| 145 | if (p == NULL) return NULL; |
---|
| 146 | p_LmCheckPolyRing1(p, r); |
---|
| 147 | poly np; |
---|
| 148 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
| 149 | p_SetRingOfLm(np, r); |
---|
| 150 | p_ExpVectorCopy(np, p, r); |
---|
[367c32] | 151 | pNext(np) = NULL; |
---|
| 152 | pSetCoeff0(np, n_Copy(pGetCoeff(p), r)); |
---|
[35aab3] | 153 | return np; |
---|
| 154 | } |
---|
[b8027c] | 155 | // set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in |
---|
| 156 | // different blocks |
---|
| 157 | // set coeff to 1 |
---|
[3f685c] | 158 | PINLINE1 poly p_GetExp_k_n(poly p, int l, int k, const ring r) |
---|
[b8027c] | 159 | { |
---|
| 160 | if (p == NULL) return NULL; |
---|
| 161 | p_LmCheckPolyRing1(p, r); |
---|
| 162 | poly np; |
---|
| 163 | omTypeAllocBin(poly, np, r->PolyBin); |
---|
| 164 | p_SetRingOfLm(np, r); |
---|
| 165 | p_ExpVectorCopy(np, p, r); |
---|
[367c32] | 166 | pNext(np) = NULL; |
---|
| 167 | pSetCoeff0(np, n_Init(1, r)); |
---|
[b8027c] | 168 | int i; |
---|
| 169 | for(i=l;i<=k;i++) |
---|
| 170 | { |
---|
[9fb610] | 171 | //np->exp[(r->VarOffset[i] & 0xffffff)] =0; |
---|
| 172 | p_SetExp(np,i,0,r); |
---|
[b8027c] | 173 | } |
---|
| 174 | p_Setm(np,r); |
---|
| 175 | return np; |
---|
| 176 | } |
---|
[35aab3] | 177 | |
---|
| 178 | PINLINE1 poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin) |
---|
| 179 | { |
---|
| 180 | p_LmCheckPolyRing1(p, r); |
---|
| 181 | pAssume1(bin->sizeW == r->PolyBin->sizeW); |
---|
| 182 | poly new_p = p_New(r); |
---|
| 183 | p_MemCopy_LengthGeneral(new_p->exp, p->exp, r->ExpL_Size); |
---|
| 184 | pSetCoeff0(new_p, pGetCoeff(p)); |
---|
| 185 | pNext(new_p) = pNext(p); |
---|
| 186 | omFreeBinAddr(p); |
---|
| 187 | return new_p; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | /*************************************************************** |
---|
| 191 | * |
---|
| 192 | * Operation on ExpVectors |
---|
| 193 | * |
---|
| 194 | ***************************************************************/ |
---|
| 195 | // ExpVector(p1) += ExpVector(p2) |
---|
[3f685c] | 196 | PINLINE1 void p_ExpVectorAdd(poly p1, poly p2, const ring r) |
---|
[35aab3] | 197 | { |
---|
| 198 | p_LmCheckPolyRing1(p1, r); |
---|
| 199 | p_LmCheckPolyRing1(p2, r); |
---|
| 200 | #if PDEBUG >= 1 |
---|
| 201 | for (int i=1; i<=r->N; i++) |
---|
| 202 | pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask); |
---|
| 203 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0); |
---|
| 204 | #endif |
---|
| 205 | |
---|
| 206 | p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size); |
---|
| 207 | p_MemAdd_NegWeightAdjust(p1, r); |
---|
| 208 | } |
---|
| 209 | // ExpVector(p1) -= ExpVector(p2) |
---|
[3f685c] | 210 | PINLINE1 void p_ExpVectorSub(poly p1, poly p2, const ring r) |
---|
[35aab3] | 211 | { |
---|
| 212 | p_LmCheckPolyRing1(p1, r); |
---|
| 213 | p_LmCheckPolyRing1(p2, r); |
---|
| 214 | #if PDEBUG >= 1 |
---|
| 215 | for (int i=1; i<=r->N; i++) |
---|
| 216 | pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r)); |
---|
| 217 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 || |
---|
| 218 | p_GetComp(p1, r) == p_GetComp(p2, r)); |
---|
| 219 | #endif |
---|
| 220 | |
---|
| 221 | p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size); |
---|
| 222 | p_MemSub_NegWeightAdjust(p1, r); |
---|
| 223 | |
---|
| 224 | } |
---|
| 225 | // ExpVector(p1) += ExpVector(p2) - ExpVector(p3) |
---|
[3f685c] | 226 | PINLINE1 void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r) |
---|
[35aab3] | 227 | { |
---|
| 228 | p_LmCheckPolyRing1(p1, r); |
---|
| 229 | p_LmCheckPolyRing1(p2, r); |
---|
| 230 | p_LmCheckPolyRing1(p3, r); |
---|
| 231 | #if PDEBUG >= 1 |
---|
| 232 | for (int i=1; i<=r->N; i++) |
---|
| 233 | pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r)); |
---|
| 234 | pAssume1(p_GetComp(p1, r) == 0 || |
---|
| 235 | (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) || |
---|
| 236 | (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r))); |
---|
| 237 | #endif |
---|
| 238 | |
---|
| 239 | p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size); |
---|
| 240 | // no need to adjust in case of NegWeights |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | // ExpVector(pr) = ExpVector(p1) + ExpVector(p2) |
---|
[3f685c] | 244 | PINLINE1 void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r) |
---|
[35aab3] | 245 | { |
---|
| 246 | p_LmCheckPolyRing1(p1, r); |
---|
| 247 | p_LmCheckPolyRing1(p2, r); |
---|
| 248 | p_LmCheckPolyRing1(pr, r); |
---|
| 249 | #if PDEBUG >= 1 |
---|
| 250 | for (int i=1; i<=r->N; i++) |
---|
| 251 | pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask); |
---|
| 252 | pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0); |
---|
| 253 | #endif |
---|
| 254 | |
---|
| 255 | p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size); |
---|
[347f0c] | 256 | p_MemAdd_NegWeightAdjust(pr, r); |
---|
[35aab3] | 257 | } |
---|
| 258 | // ExpVector(pr) = ExpVector(p1) - ExpVector(p2) |
---|
[3f685c] | 259 | PINLINE1 void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r) |
---|
[35aab3] | 260 | { |
---|
| 261 | p_LmCheckPolyRing1(p1, r); |
---|
| 262 | p_LmCheckPolyRing1(p2, r); |
---|
| 263 | p_LmCheckPolyRing1(pr, r); |
---|
| 264 | #if PDEBUG >= 2 |
---|
| 265 | for (int i=1; i<=r->N; i++) |
---|
| 266 | pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r)); |
---|
| 267 | pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r)); |
---|
| 268 | #endif |
---|
| 269 | |
---|
| 270 | p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size); |
---|
[347f0c] | 271 | p_MemSub_NegWeightAdjust(pr, r); |
---|
[35aab3] | 272 | } |
---|
| 273 | |
---|
[3f685c] | 274 | PINLINE1 BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r) |
---|
[35aab3] | 275 | { |
---|
| 276 | p_LmCheckPolyRing1(p1, r); |
---|
| 277 | p_LmCheckPolyRing1(p2, r); |
---|
| 278 | |
---|
| 279 | int i = r->ExpL_Size; |
---|
| 280 | unsigned long *ep = p1->exp; |
---|
| 281 | unsigned long *eq = p2->exp; |
---|
| 282 | |
---|
| 283 | do |
---|
| 284 | { |
---|
| 285 | i--; |
---|
| 286 | if (ep[i] != eq[i]) return FALSE; |
---|
| 287 | } |
---|
| 288 | while (i); |
---|
| 289 | return TRUE; |
---|
| 290 | } |
---|
| 291 | |
---|
[99bdcf] | 292 | PINLINE1 long p_Totaldegree(poly p, const ring r) |
---|
[35aab3] | 293 | { |
---|
| 294 | p_LmCheckPolyRing1(p, r); |
---|
| 295 | unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]], |
---|
| 296 | r, |
---|
| 297 | r->MinExpPerLong); |
---|
| 298 | for (int i=r->VarL_Size-1; i>0; i--) |
---|
| 299 | { |
---|
| 300 | s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r); |
---|
| 301 | } |
---|
[99bdcf] | 302 | return (long)s; |
---|
[35aab3] | 303 | } |
---|
| 304 | |
---|
[3f685c] | 305 | PINLINE1 void p_GetExpV(poly p, int *ev, const ring r) |
---|
[35aab3] | 306 | { |
---|
| 307 | p_LmCheckPolyRing1(p, r); |
---|
| 308 | for (int j = r->N; j; j--) |
---|
| 309 | ev[j] = p_GetExp(p, j, r); |
---|
| 310 | |
---|
| 311 | ev[0] = _p_GetComp(p, r); |
---|
| 312 | } |
---|
[3f685c] | 313 | PINLINE1 void p_SetExpV(poly p, int *ev, const ring r) |
---|
[35aab3] | 314 | { |
---|
| 315 | p_LmCheckPolyRing1(p, r); |
---|
| 316 | for (int j = r->N; j; j--) |
---|
| 317 | p_SetExp(p, j, ev[j], r); |
---|
| 318 | |
---|
| 319 | p_SetComp(p, ev[0],r); |
---|
| 320 | p_Setm(p, r); |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | /*************************************************************** |
---|
| 324 | * |
---|
| 325 | * Comparison w.r.t. monomial ordering |
---|
| 326 | * |
---|
| 327 | ***************************************************************/ |
---|
[3f685c] | 328 | PINLINE1 int p_LmCmp(poly p, poly q, const ring r) |
---|
[35aab3] | 329 | { |
---|
| 330 | p_LmCheckPolyRing1(p, r); |
---|
| 331 | p_LmCheckPolyRing1(q, r); |
---|
| 332 | |
---|
| 333 | p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn, |
---|
| 334 | return 0, return 1, return -1); |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | |
---|
| 338 | /*************************************************************** |
---|
| 339 | * |
---|
| 340 | * divisibility |
---|
| 341 | * |
---|
| 342 | ***************************************************************/ |
---|
| 343 | // return: FALSE, if there exists i, such that a->exp[i] > b->exp[i] |
---|
| 344 | // TRUE, otherwise |
---|
| 345 | // (1) Consider long vars, instead of single exponents |
---|
| 346 | // (2) Clearly, if la > lb, then FALSE |
---|
| 347 | // (3) Suppose la <= lb, and consider first bits of single exponents in l: |
---|
| 348 | // if TRUE, then value of these bits is la ^ lb |
---|
| 349 | // if FALSE, then la-lb causes an "overflow" into one of those bits, i.e., |
---|
| 350 | // la ^ lb != la - lb |
---|
[3f685c] | 351 | static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r) |
---|
[35aab3] | 352 | { |
---|
| 353 | int i=r->VarL_Size - 1; |
---|
| 354 | unsigned long divmask = r->divmask; |
---|
| 355 | unsigned long la, lb; |
---|
| 356 | |
---|
| 357 | if (r->VarL_LowIndex >= 0) |
---|
| 358 | { |
---|
| 359 | i += r->VarL_LowIndex; |
---|
| 360 | do |
---|
| 361 | { |
---|
| 362 | la = a->exp[i]; |
---|
| 363 | lb = b->exp[i]; |
---|
| 364 | if ((la > lb) || |
---|
| 365 | (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))) |
---|
| 366 | { |
---|
| 367 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 368 | return FALSE; |
---|
| 369 | } |
---|
| 370 | i--; |
---|
| 371 | } |
---|
| 372 | while (i>=r->VarL_LowIndex); |
---|
| 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
| 376 | do |
---|
| 377 | { |
---|
| 378 | la = a->exp[r->VarL_Offset[i]]; |
---|
| 379 | lb = b->exp[r->VarL_Offset[i]]; |
---|
| 380 | if ((la > lb) || |
---|
| 381 | (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))) |
---|
| 382 | { |
---|
| 383 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 384 | return FALSE; |
---|
| 385 | } |
---|
| 386 | i--; |
---|
| 387 | } |
---|
| 388 | while (i>=0); |
---|
| 389 | } |
---|
[009d80] | 390 | #ifdef HAVE_RINGS |
---|
[6cb539] | 391 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r))); |
---|
[93ebe1] | 392 | return (!rField_is_Ring(r)) || nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)); |
---|
[009d80] | 393 | #else |
---|
[04d04e0] | 394 | pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE); |
---|
[35aab3] | 395 | return TRUE; |
---|
[009d80] | 396 | #endif |
---|
[35aab3] | 397 | } |
---|
| 398 | |
---|
[3f685c] | 399 | static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b) |
---|
[35aab3] | 400 | { |
---|
| 401 | int i=r_a->N; |
---|
| 402 | pAssume1(r_a->N == r_b->N); |
---|
| 403 | |
---|
| 404 | do |
---|
| 405 | { |
---|
| 406 | if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b)) |
---|
| 407 | return FALSE; |
---|
| 408 | i--; |
---|
| 409 | } |
---|
| 410 | while (i); |
---|
[009d80] | 411 | #ifdef HAVE_RINGS |
---|
| 412 | return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)); |
---|
| 413 | #else |
---|
| 414 | return TRUE; |
---|
[cea6f3] | 415 | #endif |
---|
[35aab3] | 416 | } |
---|
[585bbcb] | 417 | |
---|
[27e750] | 418 | #ifdef HAVE_RATGRING |
---|
[3f685c] | 419 | static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end) |
---|
| 420 | { |
---|
| 421 | int i=end; |
---|
| 422 | pAssume1(r_a->N == r_b->N); |
---|
| 423 | |
---|
| 424 | do |
---|
| 425 | { |
---|
| 426 | if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b)) |
---|
| 427 | return FALSE; |
---|
| 428 | i--; |
---|
| 429 | } |
---|
| 430 | while (i>=start); |
---|
| 431 | #ifdef HAVE_RINGS |
---|
| 432 | return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)); |
---|
| 433 | #else |
---|
| 434 | return TRUE; |
---|
| 435 | #endif |
---|
| 436 | } |
---|
[27e750] | 437 | static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end) |
---|
| 438 | { |
---|
| 439 | if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b)) |
---|
| 440 | return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end); |
---|
| 441 | return FALSE; |
---|
| 442 | } |
---|
| 443 | PINLINE1 BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end) |
---|
| 444 | { |
---|
| 445 | p_LmCheckPolyRing1(b, r); |
---|
| 446 | pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r)); |
---|
| 447 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
| 448 | return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end); |
---|
| 449 | return FALSE; |
---|
| 450 | } |
---|
| 451 | #endif |
---|
[3f685c] | 452 | static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r) |
---|
[35aab3] | 453 | { |
---|
| 454 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
| 455 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
| 456 | return FALSE; |
---|
| 457 | } |
---|
[3f685c] | 458 | static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
[35aab3] | 459 | { |
---|
| 460 | if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b)) |
---|
| 461 | return _p_LmDivisibleByNoComp(a, r_a, b, r_b); |
---|
| 462 | return FALSE; |
---|
| 463 | } |
---|
[3f685c] | 464 | PINLINE1 BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r) |
---|
[35aab3] | 465 | { |
---|
| 466 | p_LmCheckPolyRing1(a, r); |
---|
| 467 | p_LmCheckPolyRing1(b, r); |
---|
| 468 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
| 469 | } |
---|
[3f685c] | 470 | PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r) |
---|
[35aab3] | 471 | { |
---|
| 472 | p_LmCheckPolyRing1(b, r); |
---|
| 473 | pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r)); |
---|
| 474 | if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)) |
---|
| 475 | return _p_LmDivisibleByNoComp(a, b, r); |
---|
| 476 | return FALSE; |
---|
| 477 | } |
---|
[585bbcb] | 478 | |
---|
[3f685c] | 479 | PINLINE1 BOOLEAN p_DivisibleBy(poly a, poly b, const ring r) |
---|
[35aab3] | 480 | { |
---|
| 481 | pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r)); |
---|
| 482 | pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r)); |
---|
| 483 | |
---|
| 484 | if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))) |
---|
[cea6f3] | 485 | return _p_LmDivisibleByNoComp(a,b,r); |
---|
[35aab3] | 486 | return FALSE; |
---|
| 487 | } |
---|
[3f685c] | 488 | PINLINE1 BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
[35aab3] | 489 | { |
---|
| 490 | pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b)); |
---|
| 491 | pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a)); |
---|
[cea6f3] | 492 | if (a != NULL) { |
---|
| 493 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
| 494 | } |
---|
[35aab3] | 495 | return FALSE; |
---|
| 496 | } |
---|
[3f685c] | 497 | PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b) |
---|
[35aab3] | 498 | { |
---|
| 499 | p_LmCheckPolyRing(a, r_a); |
---|
| 500 | p_LmCheckPolyRing(b, r_b); |
---|
| 501 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
| 502 | } |
---|
| 503 | PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, |
---|
[3f685c] | 504 | poly b, unsigned long not_sev_b, const ring r) |
---|
[35aab3] | 505 | { |
---|
| 506 | p_LmCheckPolyRing1(a, r); |
---|
| 507 | p_LmCheckPolyRing1(b, r); |
---|
| 508 | #ifndef PDIV_DEBUG |
---|
[367c32] | 509 | pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r); |
---|
| 510 | pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r); |
---|
[35aab3] | 511 | |
---|
| 512 | if (sev_a & not_sev_b) |
---|
| 513 | { |
---|
| 514 | pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE); |
---|
| 515 | return FALSE; |
---|
| 516 | } |
---|
| 517 | return p_LmDivisibleBy(a, b, r); |
---|
| 518 | #else |
---|
| 519 | return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r); |
---|
| 520 | #endif |
---|
| 521 | } |
---|
| 522 | |
---|
[3f685c] | 523 | PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a, |
---|
| 524 | poly b, unsigned long not_sev_b, const ring r_b) |
---|
[35aab3] | 525 | { |
---|
| 526 | p_LmCheckPolyRing1(a, r_a); |
---|
| 527 | p_LmCheckPolyRing1(b, r_b); |
---|
| 528 | #ifndef PDIV_DEBUG |
---|
[367c32] | 529 | pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a); |
---|
| 530 | pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b); |
---|
[35aab3] | 531 | |
---|
| 532 | if (sev_a & not_sev_b) |
---|
| 533 | { |
---|
| 534 | pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE); |
---|
| 535 | return FALSE; |
---|
| 536 | } |
---|
| 537 | return _p_LmDivisibleBy(a, r_a, b, r_b); |
---|
| 538 | #else |
---|
| 539 | return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b); |
---|
| 540 | #endif |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | /*************************************************************** |
---|
| 544 | * |
---|
| 545 | * Misc things on Lm |
---|
| 546 | * |
---|
| 547 | ***************************************************************/ |
---|
| 548 | // test if the monomial is a constant as a vector component |
---|
| 549 | // i.e., test if all exponents are zero |
---|
| 550 | PINLINE1 BOOLEAN p_LmIsConstantComp(const poly p, const ring r) |
---|
| 551 | { |
---|
| 552 | //p_LmCheckPolyRing(p, r); |
---|
| 553 | int i = r->VarL_Size - 1; |
---|
| 554 | |
---|
| 555 | do |
---|
| 556 | { |
---|
| 557 | if (p->exp[r->VarL_Offset[i]] != 0) |
---|
| 558 | return FALSE; |
---|
| 559 | i--; |
---|
| 560 | } |
---|
| 561 | while (i >= 0); |
---|
| 562 | return TRUE; |
---|
| 563 | } |
---|
| 564 | // test if monomial is a constant, i.e. if all exponents and the component |
---|
| 565 | // is zero |
---|
| 566 | PINLINE1 BOOLEAN p_LmIsConstant(const poly p, const ring r) |
---|
| 567 | { |
---|
| 568 | if (p_LmIsConstantComp(p, r)) |
---|
| 569 | return (p_GetComp(p, r) == 0); |
---|
| 570 | return FALSE; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | // like the respective p_LmIs* routines, except that p might be empty |
---|
| 574 | PINLINE1 BOOLEAN p_IsConstantComp(const poly p, const ring r) |
---|
| 575 | { |
---|
| 576 | if (p == NULL) return TRUE; |
---|
| 577 | return (pNext(p)==NULL) && p_LmIsConstantComp(p, r); |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | PINLINE1 BOOLEAN p_IsConstant(const poly p, const ring r) |
---|
| 581 | { |
---|
| 582 | if (p == NULL) return TRUE; |
---|
| 583 | return (pNext(p)==NULL) && p_LmIsConstant(p, r); |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r) |
---|
| 587 | { |
---|
| 588 | if (p == NULL) return FALSE; |
---|
| 589 | return p_LmIsConstant(p, r); |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | PINLINE1 BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, |
---|
| 593 | const ring r) |
---|
| 594 | { |
---|
| 595 | p_LmCheckPolyRing(p1, r); |
---|
| 596 | p_LmCheckPolyRing(p2, r); |
---|
| 597 | unsigned long l1, l2, divmask = r->divmask; |
---|
| 598 | int i; |
---|
| 599 | |
---|
| 600 | for (i=0; i<r->VarL_Size; i++) |
---|
| 601 | { |
---|
| 602 | l1 = p1->exp[r->VarL_Offset[i]]; |
---|
| 603 | l2 = p2->exp[r->VarL_Offset[i]]; |
---|
| 604 | // do the divisiblity trick |
---|
| 605 | if ( (l1 > ULONG_MAX - l2) || |
---|
| 606 | (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask))) |
---|
| 607 | return FALSE; |
---|
| 608 | } |
---|
| 609 | return TRUE; |
---|
| 610 | } |
---|
[f1e33bb] | 611 | #else |
---|
| 612 | PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r); |
---|
[35aab3] | 613 | |
---|
| 614 | #endif // !defined(NO_PINLINE1) || defined(PINLINE1_CC) |
---|
| 615 | #endif // PINLINE1_CC |
---|