[3a67ea7] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[cb0fbe] | 4 | /* $Id: shiftgb.cc,v 1.2 2007-06-24 16:44:41 levandov Exp $ */ |
---|
[3a67ea7] | 5 | /* |
---|
| 6 | * ABSTRACT: kernel: utils for shift GB and free GB |
---|
| 7 | */ |
---|
| 8 | |
---|
[cb0fbe] | 9 | #include "mod2.h" |
---|
| 10 | #include "febase.h" |
---|
| 11 | #include "ring.h" |
---|
| 12 | #include "polys.h" |
---|
| 13 | #include "numbers.h" |
---|
| 14 | #include "ideals.h" |
---|
| 15 | #include "matpol.h" |
---|
| 16 | #include "kbuckets.h" |
---|
| 17 | #include "kstd1.h" |
---|
| 18 | #include "sbuckets.h" |
---|
| 19 | #include "p_Mult_q.h" |
---|
| 20 | #include "kutil.h" |
---|
| 21 | #include "structs.h" |
---|
| 22 | #include "omalloc.h" |
---|
| 23 | #include "khstd.h" |
---|
| 24 | #include "kbuckets.h" |
---|
| 25 | #include "weight.h" |
---|
| 26 | #include "intvec.h" |
---|
| 27 | #include "structs.h" |
---|
| 28 | #include "kInline.cc" |
---|
| 29 | #include "stairc.h" |
---|
| 30 | #include "weight.h" |
---|
| 31 | #include "intvec.h" |
---|
| 32 | #include "timer.h" |
---|
| 33 | #include "shiftgb.h" |
---|
| 34 | #include "sca.h" |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | #define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int)) |
---|
[3a67ea7] | 38 | |
---|
| 39 | poly pLPshift(poly p, int sh, int uptodeg, int lV) |
---|
| 40 | { |
---|
| 41 | /* assume shift takes place */ |
---|
[cb0fbe] | 42 | /* shifts the poly p by sh */ |
---|
| 43 | |
---|
| 44 | /* assume sh and uptodeg agree */ |
---|
[3a67ea7] | 45 | |
---|
| 46 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 47 | |
---|
[cb0fbe] | 48 | poly q = NULL; |
---|
| 49 | poly pp = pCopy(p); |
---|
| 50 | while (pp!=NULL) |
---|
[3a67ea7] | 51 | { |
---|
[cb0fbe] | 52 | q = p_Add_q(q, pmLPshift(pp,sh,uptodeg,lV),currRing); |
---|
| 53 | pIter(pp); |
---|
[3a67ea7] | 54 | } |
---|
[cb0fbe] | 55 | /* delete pp? */ |
---|
[3a67ea7] | 56 | /* int version: returns TRUE if it was successful */ |
---|
[cb0fbe] | 57 | return(q); |
---|
[3a67ea7] | 58 | } |
---|
| 59 | |
---|
| 60 | poly pmLPshift(poly p, int sh, int uptodeg, int lV) |
---|
| 61 | { |
---|
| 62 | /* pm is a monomial */ |
---|
| 63 | |
---|
| 64 | if (sh == 0) return(p); /* the zero shift */ |
---|
| 65 | |
---|
[cb0fbe] | 66 | if (sh < 0 ) |
---|
| 67 | { |
---|
| 68 | #ifdef PDEBUG |
---|
| 69 | Print("pmLPshift: negative shift requested"); |
---|
| 70 | #endif |
---|
| 71 | return(NULL); /* violation, 2check */ |
---|
| 72 | } |
---|
| 73 | |
---|
[3a67ea7] | 74 | int L = pmLastVblock(p,lV); |
---|
[cb0fbe] | 75 | if (L+sh-1 > uptodeg) |
---|
[3a67ea7] | 76 | { |
---|
[cb0fbe] | 77 | #ifdef PDEBUG |
---|
| 78 | Print("pmLPshift: too big shift requested"); |
---|
| 79 | #endif |
---|
[3a67ea7] | 80 | return(NULL); /* violation, 2check */ |
---|
| 81 | } |
---|
[cb0fbe] | 82 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
| 83 | int *s=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
[3a67ea7] | 84 | pGetExpV(p,e); |
---|
| 85 | number c = pGetCoeff(p); |
---|
[cb0fbe] | 86 | int j; |
---|
| 87 | for (j=1; j<=currRing->N; j++) |
---|
[3a67ea7] | 88 | { |
---|
| 89 | if (e[j]) |
---|
| 90 | { |
---|
[cb0fbe] | 91 | s[j + (sh*lV)] = e[j]; /* actually 1 */ |
---|
[3a67ea7] | 92 | } |
---|
| 93 | } |
---|
| 94 | poly m = pOne(); |
---|
| 95 | pSetExpV(m,s); |
---|
[cb0fbe] | 96 | /* pSetm(m); */ /* done in the pSetExpV */ |
---|
[3a67ea7] | 97 | pSetCoeff0(m,c); |
---|
| 98 | freeT(e, currRing->N); |
---|
| 99 | freeT(s, currRing->N); |
---|
| 100 | return(m); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | int pLastVblock(poly p, int lV) |
---|
| 104 | { |
---|
| 105 | /* returns the number of maximal block */ |
---|
| 106 | /* appearing among the monomials of p */ |
---|
| 107 | poly q = pCopy(p); /* need it ? */ |
---|
[cb0fbe] | 108 | int ans = 0; |
---|
| 109 | int ansnew = 0; |
---|
[3a67ea7] | 110 | while (q!=NULL) |
---|
| 111 | { |
---|
| 112 | ansnew = pmLastVblock(q,lV); |
---|
[cb0fbe] | 113 | ans = si_max(ans,ansnew); |
---|
[3a67ea7] | 114 | pIter(q); |
---|
| 115 | } |
---|
[cb0fbe] | 116 | /* do not need to delete q */ |
---|
[3a67ea7] | 117 | return(ans); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | int pmLastVblock(poly p, int lV) |
---|
| 121 | { |
---|
| 122 | /* for a monomial p, returns the number of the last block */ |
---|
| 123 | /* where a nonzero exponent is sitting */ |
---|
[cb0fbe] | 124 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
[3a67ea7] | 125 | pGetExpV(p,e); |
---|
| 126 | int j,b; |
---|
[cb0fbe] | 127 | j = currRing->N; |
---|
[3a67ea7] | 128 | while ( (!e[j]) && (j>=1) ) j--; |
---|
[cb0fbe] | 129 | if (j==0) |
---|
| 130 | { |
---|
| 131 | #ifdef PDEBUG |
---|
| 132 | Print("pmLastVblock: unexpected zero exponent"); |
---|
| 133 | #endif |
---|
| 134 | return(j); |
---|
| 135 | } |
---|
| 136 | b = (int)(j/lV) + 1; /* the number of the block, >=1 */ |
---|
[3a67ea7] | 137 | return (b); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | int isInV(poly p, int lV) |
---|
| 141 | { |
---|
[cb0fbe] | 142 | if (lV <= 0) return(0); |
---|
[3a67ea7] | 143 | /* returns 1 iff p is in V */ |
---|
[cb0fbe] | 144 | /* that is in each block up to a certain one there is only one nonzero exponent */ |
---|
[3a67ea7] | 145 | /* lV = the length of V = the number of orig vars */ |
---|
[cb0fbe] | 146 | int *e = (int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
[3a67ea7] | 147 | int b = (int)(currRing->N)/lV; /* the number of blocks */ |
---|
[cb0fbe] | 148 | int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */ |
---|
[3a67ea7] | 149 | pGetExpV(p,e); |
---|
| 150 | int i,j; |
---|
| 151 | for (j=1; j<=b; j++) |
---|
| 152 | { |
---|
| 153 | /* we go through all the vars */ |
---|
| 154 | /* by blocks in lV vars */ |
---|
| 155 | for (i=(j-1)*lV + 1; i<= j*lV; i++) |
---|
| 156 | { |
---|
| 157 | if (!e[i]) B[j] = B[j]+1; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | j = b; |
---|
| 161 | while ( (!B[j]) && (j>=1)) j--; |
---|
| 162 | if (j==0) |
---|
| 163 | { |
---|
| 164 | /* it is a zero exp vector, which is in V */ |
---|
| 165 | return(1); |
---|
| 166 | } |
---|
| 167 | /* now B[j] != 0 */ |
---|
| 168 | for (j; j>=1; j--) |
---|
| 169 | { |
---|
| 170 | if (B[j]!=1) |
---|
| 171 | { |
---|
| 172 | return(0); |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | return(1); |
---|
| 176 | } |
---|
| 177 | |
---|
[cb0fbe] | 178 | /* shiftgb stuff */ |
---|
[3a67ea7] | 179 | |
---|
[cb0fbe] | 180 | void initBbaShift(ideal F,kStrategy strat) |
---|
[3a67ea7] | 181 | { |
---|
[cb0fbe] | 182 | int i; |
---|
| 183 | idhdl h; |
---|
| 184 | /* setting global variables ------------------- */ |
---|
| 185 | strat->enterS = enterSBba; |
---|
| 186 | |
---|
| 187 | strat->red = redFirstShift; |
---|
| 188 | |
---|
| 189 | /* perhaps the following? |
---|
| 190 | * strat->LazyPass *=4; |
---|
| 191 | * strat->red = redHomogShift; |
---|
| 192 | */ |
---|
| 193 | |
---|
| 194 | /* strat->red = redHoney; |
---|
| 195 | * if (strat->honey) |
---|
| 196 | * strat->red = redHoney; |
---|
| 197 | * else if (pLexOrder && !strat->homog) |
---|
| 198 | * strat->red = redLazy; |
---|
| 199 | * else |
---|
| 200 | * { |
---|
| 201 | * strat->LazyPass *=4; |
---|
| 202 | * strat->red = redHomog; |
---|
| 203 | * } |
---|
| 204 | *#ifdef HAVE_RINGS //TODO Oliver |
---|
| 205 | * if (rField_is_Ring(currRing)) { |
---|
| 206 | * strat->red = redRing2toM; |
---|
| 207 | * } |
---|
| 208 | *#endif |
---|
[3a67ea7] | 209 | */ |
---|
[cb0fbe] | 210 | |
---|
| 211 | if (pLexOrder && strat->honey) |
---|
| 212 | strat->initEcart = initEcartNormal; |
---|
[3a67ea7] | 213 | else |
---|
[cb0fbe] | 214 | strat->initEcart = initEcartBBA; |
---|
| 215 | if (strat->honey) |
---|
| 216 | strat->initEcartPair = initEcartPairMora; |
---|
[3a67ea7] | 217 | else |
---|
[cb0fbe] | 218 | strat->initEcartPair = initEcartPairBba; |
---|
| 219 | strat->kIdeal = NULL; |
---|
| 220 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
| 221 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
| 222 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
| 223 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
| 224 | { |
---|
| 225 | //interred machen Aenderung |
---|
| 226 | pFDegOld=pFDeg; |
---|
| 227 | pLDegOld=pLDeg; |
---|
| 228 | //h=ggetid("ecart"); |
---|
| 229 | //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/) |
---|
| 230 | //{ |
---|
| 231 | // ecartWeights=iv2array(IDINTVEC(h)); |
---|
| 232 | //} |
---|
| 233 | //else |
---|
| 234 | { |
---|
| 235 | ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short)); |
---|
| 236 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
| 237 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
| 238 | } |
---|
| 239 | pRestoreDegProcs(totaldegreeWecart, maxdegreeWecart); |
---|
| 240 | if (TEST_OPT_PROT) |
---|
| 241 | { |
---|
| 242 | for(i=1; i<=pVariables; i++) |
---|
| 243 | Print(" %d",ecartWeights[i]); |
---|
| 244 | PrintLn(); |
---|
| 245 | mflush(); |
---|
[3a67ea7] | 246 | } |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|