Changeset c3a392 in git
- Timestamp:
- Sep 26, 2016, 8:49:01 AM (8 years ago)
- Branches:
- (u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
- Children:
- 70d2a203860fff2701035ef95b6bac7f2ee45fe5
- Parents:
- d805061e0c8d387c3c70ce3171f03902c27f6aaf
- git-author:
- Yue <ren@mathematik.uni-kl.de>2016-09-26 08:49:01+02:00
- git-committer:
- Yue <ren@mathematik.uni-kl.de>2016-09-27 07:29:55+02:00
- Location:
- Singular/dyn_modules/gfanlib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/gfanlib/containsMonomial.cc
rd80506 rc3a392 1 #include <bbcone.h>2 1 #include <kernel/polys.h> 3 2 #include <kernel/GBEngine/kstd1.h> 4 3 #include <polys/prCopy.h> 4 5 #include <callgfanlib_conversion.h> 6 #include <bbcone.h> 7 #include <std_wrapper.h> 5 8 6 9 poly checkForMonomialViaSuddenSaturation(const ideal I, const ring r) … … 50 53 } 51 54 55 poly searchForMonomialViaStepwiseSaturation(const ideal I, const ring r, const gfan::ZVector w0) 56 { 57 gfan::ZVector w = w0; 58 59 ring origin = currRing; 60 if (currRing != r) 61 rChangeCurrRing(r); 62 63 // copy ring including qideal but without ordering 64 // set ordering to be wp(w) 65 int n = rVar(r); 66 ring rGraded = rCopy0(r,TRUE,FALSE); 67 rGraded->order = (int*) omAlloc0(3*sizeof(int)); 68 rGraded->block0 = (int*) omAlloc0(3*sizeof(int)); 69 rGraded->block1 = (int*) omAlloc0(3*sizeof(int)); 70 rGraded->wvhdl = (int**) omAlloc0(3*sizeof(int**)); 71 rGraded->order[0] = ringorder_wp; 72 rGraded->block0[0] = 1; 73 rGraded->block1[0] = n; 74 bool overflow; 75 rGraded->wvhdl[0] = ZVectorToIntStar(w,overflow); 76 rGraded->order[1] = ringorder_C; 77 rComplete(rGraded); 78 rTest(rGraded); 79 80 // map I into the new ring so that it becomes a graded ideal 81 int k = IDELEMS(I); 82 nMapFunc identity = n_SetMap(r->cf,rGraded->cf); 83 ideal Jold = idInit(k); 84 for (int i=0; i<k; i++) 85 Jold->m[i] = p_PermPoly(I->m[i],NULL,r,rGraded,identity,NULL,0); 86 87 // compute std and check whether result contains a monomial, 88 // wrap up computation if it does 89 ideal Jnew = gfanlib_monomialabortStd_wrapper(Jold,rGraded); 90 id_Delete(&Jold,rGraded); 91 k = IDELEMS(Jnew); 92 for (int i=0; i<k; i++) 93 { 94 poly g = Jnew->m[i]; 95 if (g!=NULL && pNext(g)==NULL && n_IsUnit(p_GetCoeff(g,r),r->cf)) 96 { 97 poly monomial = p_One(r); 98 for (int j=1; j<=rVar(r); j++) 99 p_SetExp(monomial,j,p_GetExp(g,j,rGraded),r); 100 p_Setm(monomial,r); 101 102 id_Delete(&Jnew,rGraded); 103 rDelete(rGraded); 104 if (currRing != origin) 105 rChangeCurrRing(origin); 106 return monomial; 107 } 108 } 109 110 // prepare permutation to cycle all variables 111 int* cycleAllVariables = (int*) omAlloc0((n+1)*sizeof(int)); 112 for (int i=1; i<n; i++) 113 cycleAllVariables[i]=i+1; 114 cycleAllVariables[n]=1; 115 // prepare storage of maximal powers that are being divided with 116 int* maxPowers = (int*) omAlloc0((n+1)*sizeof(int)); 117 118 for(int currentSaturationVariable=n-1; currentSaturationVariable>0; currentSaturationVariable--) 119 { 120 // divide out the maximal power in the last variable, 121 // storing the maximum of all powers. 122 for (int i=0; i<k; i++) 123 { 124 poly g = Jnew->m[i]; 125 int d = p_GetExp(g,n,rGraded); 126 if (d>0) 127 { 128 for (; g!=NULL; pIter(g)) 129 { 130 p_SubExp(g,n,d,rGraded); 131 p_Setm(g,rGraded); 132 } 133 if (d>maxPowers[currentSaturationVariable+1]) 134 maxPowers[currentSaturationVariable+1]=d; 135 } 136 } 137 138 // cycle all variables, i.e. x_1->x_2, x_2->x_3, ..., x_n->x_1 139 // so that a new variable is at the last position 140 gfan::Integer cache = w[n-1]; 141 for (int i=n-1; i>0; i--) 142 w[i] = w[i-1]; 143 w[0] = cache; 144 145 ring rGradedNew = rCopy0(r,TRUE,FALSE); 146 rGradedNew->order = (int*) omAlloc0(3*sizeof(int)); 147 rGradedNew->block0 = (int*) omAlloc0(3*sizeof(int)); 148 rGradedNew->block1 = (int*) omAlloc0(3*sizeof(int)); 149 rGradedNew->wvhdl = (int**) omAlloc0(3*sizeof(int**)); 150 rGradedNew->order[0] = ringorder_wp; 151 rGradedNew->block0[0] = 1; 152 rGradedNew->block1[0] = n; 153 bool overflow; 154 rGradedNew->wvhdl[0] = ZVectorToIntStar(w,overflow); 155 rGradedNew->order[1] = ringorder_C; 156 rComplete(rGradedNew); 157 rTest(rGradedNew); 158 159 identity = n_SetMap(rGraded->cf,rGradedNew->cf); 160 Jold = idInit(k); 161 for (int i=0; i<k; i++) 162 Jold->m[i] = p_PermPoly(Jnew->m[i],cycleAllVariables,rGraded,rGradedNew,identity,NULL,0); 163 id_Delete(&Jnew,rGraded); 164 rDelete(rGraded); 165 166 rGraded = rGradedNew; 167 rGradedNew = NULL; 168 169 // compute std and check whether result contains a monomial, 170 // wrap up computation if it does 171 // adjust for the powers already divided out of the ideal 172 // and the shift of variables! 173 Jnew = gfanlib_monomialabortStd_wrapper(Jold,rGraded); 174 id_Delete(&Jold,rGraded); 175 176 k = IDELEMS(Jnew); 177 for (int i=0; i<k; i++) 178 { 179 poly g = Jnew->m[i]; 180 if (g!=NULL && pNext(g)==NULL && n_IsUnit(p_GetCoeff(g,rGraded),rGraded->cf)) 181 { 182 poly monomial = p_One(r); 183 for (int j=1; j<=rVar(r); j++) 184 { 185 int jDeshifted = (j-currentSaturationVariable)%n; 186 if (jDeshifted<=0) jDeshifted = jDeshifted+n; 187 p_SetExp(monomial,j,p_GetExp(g,jDeshifted,rGraded)+maxPowers[j],r); 188 } 189 p_Setm(monomial,r); 190 191 id_Delete(&Jnew,rGraded); 192 rDelete(rGraded); 193 omFree(cycleAllVariables); 194 omFree(maxPowers); 195 if (currRing != origin) 196 rChangeCurrRing(origin); 197 return monomial; 198 } 199 } 200 } 201 202 if (currRing != origin) 203 rChangeCurrRing(origin); 204 205 id_Delete(&Jnew,rGraded); 206 rDelete(rGraded); 207 omFree(cycleAllVariables); 208 omFree(maxPowers); 209 return NULL; 210 } 52 211 53 212 BOOLEAN checkForMonomial(leftv res, leftv args) … … 73 232 } 74 233 75 #if 0 76 // /*** 77 // * Creates an int* representing the transposition of the last two variables 78 // **/ 79 // static inline int* createPermutationVectorForSaturation(static const ring &r) 80 // { 81 // int* w = (int*) omAlloc0((rVar(r)+1)*sizeof(int)); 82 // for (int i=1; i<=rVar(r)-2; i++) 83 // w[i] = i; 84 // w[rVar(r)-1] = rVar(r); 85 // w[rVar(r)] = rVar(r)-1; 86 // } 87 88 89 /*** 90 * Creates an int* representing the permutation 91 * 1 -> 1, ..., i-1 -> i-1, i -> n, i+1 -> n-1, ... , n -> i 92 **/ 93 static inline int* createPermutationVectorForSaturation(const ring &r, const int i) 94 { 95 int* sigma = (int*) omAlloc0((rVar(r)+1)*sizeof(int)); 96 int j; 97 for (j=1; j<i; j++) 98 sigma[j] = j; 99 for (; j<=rVar(r); j++) 100 sigma[j] = rVar(r)-j+i; 101 return(sigma); 102 } 103 104 105 /*** 106 * Changes the int* representing the permutation 107 * 1 -> 1, ..., i -> i, i+1 -> n, i+2 -> n-1, ... , n -> i+1 108 * to an int* representing the permutation 109 * 1 -> 1, ..., i-1 -> i-1, i -> n, i+1 -> n-1, ... , n -> i 110 **/ 111 static void changePermutationVectorForSaturation(int* sigma, const ring &r, const int i) 112 { 113 for (int j=i; j<rVar(r); j++) 114 sigma[j] = rVar(r)-j+i; 115 sigma[rVar(r)] = i; 116 } 117 118 119 /*** 120 * returns a ring in which the weights of the ring variables are permuted 121 * if handed over a poly in which the variables are permuted, this is basically 122 * as good as permuting the variables of the ring itself. 123 **/ 124 static ring permuteWeighstOfRingVariables(const ring &r, const int* const sigma) 125 { 126 ring s = rCopy0(r); 127 for (int j=0; j<rVar(r); j++) 128 { 129 s->wvhdl[0][j] = r->wvhdl[0][sigma[j+1]]; 130 s->wvhdl[1][j] = r->wvhdl[1][sigma[j+1]]; 131 } 132 rComplete(s,1); 133 rTest(s); 134 return s; 135 } 136 137 138 /*** 139 * creates a ring s that is a copy of r except with ordering wp(w) 140 **/ 141 static inline ring createInitialRingForSaturation(const ring &r, const gfan::ZVector &w, bool &ok) 142 { 143 assume(rVar(r) == (int) w.size()); 144 145 ring s = rCopy0(r); int i; 146 for (i=0; s->order[i]; i++) 147 omFreeSize(s->wvhdl[i],rVar(r)*sizeof(int)); 148 i++; 149 omFreeSize(s->order,i*sizeof(int)); 150 s->order = (int*) omAlloc0(3*sizeof(int)); 151 omFreeSize(s->block0,i*sizeof(int)); 152 s->block0 = (int*) omAlloc0(3*sizeof(int)); 153 omFreeSize(s->block1,i*sizeof(int)); 154 s->block1 = (int*) omAlloc0(3*sizeof(int)); 155 omFreeSize(s->wvhdl,i*sizeof(int*)); 156 s->wvhdl = (int**) omAlloc0(3*sizeof(int*)); 157 158 s->order[0] = ringorder_wp; 159 s->block0[0] = 1; 160 s->block1[0] = rVar(r); 161 s->wvhdl[0] = ZVectorToIntStar(w,ok); 162 s->order[1]=ringorder_C; 163 164 rComplete(s,1); 165 rTest(s); 166 return s; 167 } 168 169 170 /*** 171 * Given an weighted homogeneous ideal I with respect to weight w 172 * that in standard basis form with respect to the ordering ws(-w), 173 * derives the standard basis of I:<x_n>^\infty 174 * and returns a long k such that I:<x_n>^\infty=I:<x_n>^k 175 **/ 176 static long deriveStandardBasisOfSaturation(ideal &I, ring &r) 177 { 178 long k=0, l; poly current; 179 for (int i=0; i<IDELEMS(I); i++) 180 { 181 current = I->m[i]; 182 l = p_GetExp(current,rVar(r),r); 183 if (k<l) k=l; 184 while (current) 185 { 186 p_SubExp(current,rVar(r),l,r); p_Setm(current,r); 187 pIter(current); 188 } 189 } 190 return k; 191 } 192 193 194 /*** 195 * Given a weighted homogeneous ideal I with respect to weight w 196 * with constant first element, 197 * returns NULL if I does not contain a monomial 198 * otherwise returns the monomial contained in I 199 **/ 200 poly checkForMonomialsViaStepwiseSaturation(const ideal &I, const gfan::ZVector &w) 201 { 202 // assume(rField_is_Ring_Z(currRing)); 203 204 // first we switch to the ground field currRing->cf / I->m[0] 205 ring r = rCopy0(currRing); 206 nKillChar(r->cf); 207 r->cf = nInitChar(n_Zp,(void*)(long)n_Int(p_GetCoeff(I->m[0],currRing),currRing->cf)); 208 rComplete(r); 209 rTest(r); 210 211 ideal J = id_Copy(I, currRing); poly cache; number temp; 212 for (int i=0; i<IDELEMS(I); i++) 213 { 214 cache = J->m[i]; 215 while (cache) 216 { 217 // TODO: temp = npMapGMP(p_GetCoeff(cache,currRing),currRing->cf,r->cf); 218 p_SetCoeff(cache,temp,r); pIter(cache); 219 } 220 } 221 222 J = kStd(J,NULL,isHomog,NULL); 223 224 bool b = false; 225 ring s = createInitialRingForSaturation(currRing, w, b); 226 if (b) 227 { 228 WerrorS("containsMonomial: overflow in weight vector"); 229 return NULL; 230 } 231 232 return NULL; 233 } 234 #endif //0 234 BOOLEAN searchForMonomialViaStepwiseSaturation(leftv res, leftv args) 235 { 236 leftv u = args; 237 if ((u != NULL) && (u->Typ() == IDEAL_CMD)) 238 { 239 leftv v = u->next; 240 if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) 241 { 242 ideal I = (ideal) u->Data(); 243 bigintmat* w0=NULL; 244 if (v->Typ() == INTVEC_CMD) 245 { 246 intvec* w00 = (intvec*) v->Data(); 247 bigintmat* w0t = iv2bim(w00,coeffs_BIGINT); 248 w0 = w0t->transpose(); 249 delete w0t; 250 } 251 else 252 w0 = (bigintmat*) v->Data(); 253 gfan::ZVector* w = bigintmatToZVector(w0); 254 255 res->rtyp = POLY_CMD; 256 res->data = (char*) searchForMonomialViaStepwiseSaturation(I,currRing,*w); 257 delete w; 258 if (v->Typ() == INTVEC_CMD) 259 delete w0; 260 261 return FALSE; 262 } 263 } 264 WerrorS("searchForMonomialViaStepwiseSaturation: unexpected parameters"); 265 return TRUE; 266 } -
Singular/dyn_modules/gfanlib/containsMonomial.h
rd80506 rc3a392 7 7 8 8 poly checkForMonomialViaSuddenSaturation(const ideal I, const ring r); 9 poly searchForMonomialViaStepwiseSaturation(const ideal I, const ring r, const gfan::ZVector w); 9 10 BOOLEAN checkForMonomial(leftv res, leftv args); 11 BOOLEAN searchForMonomialViaStepwiseSaturation(leftv res, leftv args); 10 12 11 13 #endif -
Singular/dyn_modules/gfanlib/std_wrapper.cc
rd80506 rc3a392 45 45 return stdI; 46 46 } 47 48 ideal gfanlib_monomialabortStd_wrapper(ideal I, ring r, tHomog h=testHomog) 49 { 50 ring origin = currRing; 51 if (origin != r) 52 rChangeCurrRing(r); 53 54 ideal stdI = kStd(I,currRing->qideal,h,NULL,NULL,0,0,NULL,abort_if_monomial_sp); 55 id_DelDiv(stdI,currRing); 56 idSkipZeroes(stdI); 57 58 if (origin != r) 59 rChangeCurrRing(origin); 60 61 return stdI; 62 } -
Singular/dyn_modules/gfanlib/std_wrapper.h
rd80506 rc3a392 7 7 ideal gfanlib_kStd_wrapper(ideal I, ring r, tHomog h=testHomog); 8 8 ideal gfanlib_satStd_wrapper(ideal I, ring r, tHomog h=testHomog); 9 ideal gfanlib_monomialabortStd_wrapper(ideal I, ring r, tHomog h=testHomog); 9 10 10 11 #endif -
Singular/dyn_modules/gfanlib/tropicalStrategy.cc
rd80506 rc3a392 8 8 #include <tropicalCurves.h> 9 9 #include <tropicalDebug.h> 10 #include <containsMonomial.h> 10 11 11 12 … … 525 526 } 526 527 528 gfan::ZCone C0 = homogeneitySpace(inIShortcut,rShortcut); 529 gfan::ZCone pos = gfan::ZCone::positiveOrthant(C0.ambientDimension()); 530 gfan::ZCone C0pos = intersection(C0,pos); 531 C0pos.canonicalize(); 532 gfan::ZVector wpos = C0pos.getRelativeInteriorPoint(); 533 assume(checkForNonPositiveEntries(wpos)); 534 527 535 // check initial ideal for monomial and 528 536 // if it exsists, return a copy of the monomial in the input ring 529 poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut);537 poly p = searchForMonomialViaStepwiseSaturation(inIShortcut,rShortcut,wpos); 530 538 poly monomial = NULL; 531 539 if (p!=NULL)
Note: See TracChangeset
for help on using the changeset viewer.