Changeset 4664b3 in git
- Timestamp:
- Oct 6, 2014, 11:52:44 AM (10 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- c9641474cc5811d6eed949bf4509b30db0cbb721
- Parents:
- dffd1541cc74564f509bd5d284948852484430b0
- git-author:
- Yue Ren <ren@mathematik.uni-kl.de>2014-10-06 12:52:44+03:00
- git-committer:
- Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:05+01:00
- Location:
- Singular/dyn_modules/gfanlib
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/gfanlib/groebnerCone.cc
rdffd154 r4664b3 121 121 polyhedralCone.canonicalize(); 122 122 interiorPoint = polyhedralCone.getRelativeInteriorPoint(); 123 initialPolynomialIdeal = sloppyInitial(reducedPolynomialIdeal,polynomialRing,interiorPoint);123 initialPolynomialIdeal = initial(reducedPolynomialIdeal,polynomialRing,interiorPoint); 124 124 assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); 125 125 } … … 186 186 polyhedralCone.canonicalize(); 187 187 interiorPoint = polyhedralCone.getRelativeInteriorPoint(); 188 initialPolynomialIdeal = sloppyInitial(reducedPolynomialIdeal,polynomialRing,interiorPoint);188 initialPolynomialIdeal = initial(reducedPolynomialIdeal,polynomialRing,interiorPoint); 189 189 assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); 190 190 } … … 249 249 polyhedralCone.canonicalize(); 250 250 interiorPoint = polyhedralCone.getRelativeInteriorPoint(); 251 initialPolynomialIdeal = sloppyInitial(reducedPolynomialIdeal,polynomialRing,interiorPoint);251 initialPolynomialIdeal = initial(reducedPolynomialIdeal,polynomialRing,interiorPoint); 252 252 assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); 253 253 } -
Singular/dyn_modules/gfanlib/initial.cc
rdffd154 r4664b3 1 #include <kernel/ideals.h> 2 #include <libpolys/polys/monomials/p_polys.h> 3 1 4 #include <gfanlib/gfanlib.h> 2 5 3 #include <kernel/ideals.h>4 #include <Singular/subexpr.h>5 #include <libpolys/polys/monomials/p_polys.h>6 #include <libpolys/polys/simpleideals.h>7 8 #include <callgfanlib_conversion.h>9 #include <gfanlib_exceptions.h>10 11 6 #include <exception> 12 7 13 /***14 * Computes the weighted degree of the leading term of p with respect to w15 **/16 8 long wDeg(const poly p, const ring r, const gfan::ZVector w) 17 9 { … … 20 12 { 21 13 if (!w[i].fitsInInt()) 22 throw 0; // weightOverflow;14 throw 0; // weightOverflow; 23 15 d += p_GetExp(p,i+1,r)*w[i].toInt(); 24 16 } 25 return d;26 }27 28 /***29 * Computes the weighted multidegree of the leading term of p with respect to W.30 * The weighted multidegree is a vector whose i-th entry is the weighted degree31 * with respect to the i-th row vector of W.32 **/33 gfan::ZVector WDeg(const poly p, const ring r, const gfan::ZMatrix W)34 {35 gfan::ZVector d = gfan::ZVector(W.getHeight());36 for (int i=0; i<W.getHeight(); i++)37 d[i] = wDeg(p,r,W[i]);38 17 return d; 39 18 } … … 48 27 } 49 28 50 /** 51 * Checks if p is sorted with respect to w. 52 */ 53 static bool checkSloppyInput(const poly p, const ring r, const gfan::ZVector w) 54 { 55 long d = wDeg(p,r,w); 56 for (poly currentTerm = p->next; currentTerm; pIter(currentTerm)) 57 { 58 long e = wDeg(currentTerm,r,w); 59 if (e>d) 60 return false; 61 } 62 return true; 63 } 64 65 /*** 66 * Returns the terms of p of same weighted degree under w as the leading term. 67 * Coincides with the initial form of p with respect to w if and only if p was already 68 * sorted with respect to w in the sense that the leading term is of highest w-degree. 69 **/ 70 poly sloppyInitial(const poly p, const ring r, const gfan::ZVector w) 71 { 72 assume(checkSloppyInput(p,r,w)); 73 int n = rVar(r); 74 int* expv = (int*) omAlloc(n*sizeof(int)); 29 poly initial(const poly p, const ring r, const gfan::ZVector w) 30 { 31 if (p==NULL) 32 return NULL; 33 75 34 poly q0 = p_Head(p,r); 76 35 poly q1 = q0; … … 78 37 for (poly currentTerm = p->next; currentTerm; pIter(currentTerm)) 79 38 { 80 if (wDeg(currentTerm,r,w) == d)81 {82 pNext(q1) = p_Head(currentTerm,r);83 pIter(q1);84 }85 }86 omFreeSize(expv,n*sizeof(int));87 return q0;88 }89 90 /***91 * Runs the above procedure over all generators of an ideal.92 * Coincides with the initial ideal of I with respect to w if and only if93 * the elements of I were already sorted with respect to w and94 * I is a standard basis form with respect to w.95 **/96 ideal sloppyInitial(const ideal I, const ring r, const gfan::ZVector w)97 {98 int k = idSize(I); ideal inI = idInit(k);99 for (int i=0; i<k; i++)100 inI->m[i] = sloppyInitial(I->m[i],r,w);101 return inI;102 }103 104 /***105 * Returns the initial form of p with respect to w106 **/107 poly initial(const poly p, const ring r, const gfan::ZVector w)108 {109 poly q0 = p_Head(p,r);110 poly q1 = q0;111 long d = wDeg(p,r,w);112 for (poly currentTerm = p->next; currentTerm; pIter(currentTerm))113 {114 39 long e = wDeg(currentTerm,r,w); 115 if ( e>d)40 if (d<e) 116 41 { 117 42 p_Delete(&q0,r); … … 130 55 } 131 56 132 /***133 * Runs the above procedure over all generators of an ideal.134 * Returns the initial ideal if and only if the weight is in the maximal Groebner cone135 * of the current ordering.136 **/137 57 ideal initial(const ideal I, const ring r, const gfan::ZVector w) 138 58 { 139 idSkipZeroes(I);140 59 int k = idSize(I); ideal inI = idInit(k); 141 60 for (int i=0; i<k; i++) … … 144 63 } 145 64 146 147 /***148 * Returns the initial form of p with respect to W,149 * i.e. the sum over all terms of p with highest multidegree with respect to W.150 **/151 poly initial(const poly p, const ring r, const gfan::ZMatrix W)152 {153 int n = rVar(r);154 poly q0 = p_Head(p,r);155 poly q1 = q0;156 gfan::ZVector d = WDeg(p,r,W);157 for (poly currentTerm = p->next; currentTerm; pIter(currentTerm))158 {159 gfan::ZVector e = WDeg(currentTerm,r,W);160 if (d<e)161 {162 p_Delete(&q0,r);163 q0 = p_Head(p,r);164 q1 = q0;165 d = e;166 }167 else168 if (d==e)169 {170 pNext(q1) = p_Head(currentTerm,r);171 pIter(q1);172 }173 }174 return q0;175 }176 177 65 poly initial(const poly p, const ring r, const gfan::ZVector w, const gfan::ZMatrix W) 178 66 { 179 int n = rVar(r); 67 if (p==NULL) 68 return NULL; 69 180 70 poly q0 = p_Head(p,r); 181 71 poly q1 = q0; … … 201 91 } 202 92 203 204 /***205 * Runs the above procedure over all generators of an ideal.206 * Returns the initial ideal if and only if the weight is in the maximal Groebner cone207 * of the current ordering.208 **/209 ideal initial(const ideal I, const ring r, const gfan::ZMatrix W)210 {211 int k = idSize(I); ideal inI = idInit(k);212 for (int i=0; i<k; i++)213 inI->m[i] = initial(I->m[i],r,W);214 return inI;215 }216 217 93 ideal initial(const ideal I, const ring r, const gfan::ZVector w, const gfan::ZMatrix W) 218 94 { … … 223 99 } 224 100 225 #ifndef NDEBUG 226 BOOLEAN initial0(leftv res, leftv args) 227 { 228 leftv u = args; 229 ideal I = (ideal) u->CopyD(); 230 leftv v = u->next; 231 bigintmat* w0 = (bigintmat*) v->Data(); 232 gfan::ZVector* w = bigintmatToZVector(w0); 233 omUpdateInfo(); 234 Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); 235 ideal inI = initial(I,currRing,*w); 236 id_Delete(&I,currRing); 237 delete w; 238 res->rtyp = IDEAL_CMD; 239 res->data = (char*) inI; 240 return FALSE; 241 } 242 #endif 243 101 void initial(poly* pStar, const ring r, const gfan::ZVector w) 102 { 103 poly p = *pStar; 104 if (p==NULL) 105 return; 106 107 long d = wDeg(p,r,w); 108 poly q0 = p; 109 poly q1 = q0; 110 pNext(q1) = NULL; 111 pIter(p); 112 113 while(p) 114 { 115 long e = wDeg(p,r,w); 116 if (d<e) 117 { 118 p_Delete(&q0,r); 119 q0 = p; 120 q1 = q0; 121 pNext(q1) = NULL; 122 d = e; 123 pIter(p); 124 } 125 else 126 if (e==d) 127 { 128 pNext(q1) = p; 129 pIter(q1); 130 pNext(q1) = NULL; 131 pIter(p); 132 } 133 else 134 p = p_LmDeleteAndNext(p,r); 135 } 136 pStar = &q0; 137 return; 138 } 139 140 void initial(ideal* IStar, const ring r, const gfan::ZVector w) 141 { 142 ideal I = *IStar; 143 int k = idSize(I); 144 for (int i=0; i<k; i++) 145 initial(&I->m[i],r,w); 146 return; 147 } 148 149 void initial(poly* pStar, const ring r, const gfan::ZVector w, const gfan::ZMatrix W) 150 { 151 poly p = *pStar; 152 if (p==NULL) 153 return; 154 155 gfan::ZVector d = WDeg(p,r,w,W); 156 poly q0 = p; 157 poly q1 = q0; 158 pNext(q1) = NULL; 159 pIter(p); 160 161 while(p) 162 { 163 gfan::ZVector e = WDeg(p,r,w,W); 164 if (d<e) 165 { 166 p_Delete(&q0,r); 167 q0 = p; 168 q1 = q0; 169 pNext(q1) = NULL; 170 d = e; 171 pIter(p); 172 } 173 else 174 if (d==e) 175 { 176 pNext(q1) = p; 177 pIter(q1); 178 pNext(q1) = NULL; 179 pIter(p); 180 } 181 else 182 p = p_LmDeleteAndNext(p,r); 183 } 184 pStar = &q0; 185 return; 186 } 187 188 void initial(ideal* IStar, const ring r, const gfan::ZVector w, const gfan::ZMatrix W) 189 { 190 ideal I = *IStar; 191 int k = idSize(I); 192 for (int i=0; i<k; i++) 193 initial(&I->m[i],r,w,W); 194 return; 195 } 244 196 245 197 /*** 246 * Computes the initial form of p with respect to the first row in the order matrix198 * throwaway code 247 199 **/ 248 poly initial(const poly p, const ring r) 249 { 250 long d = p_Deg(p,r); 251 poly initialForm0 = p_Head(p,r); 252 poly initialForm1 = initialForm0; 253 poly currentTerm = p->next; 254 while (currentTerm && p_Deg(currentTerm,r)==d) 255 { 256 pNext(initialForm1) = p_Head(currentTerm,r); 257 pIter(currentTerm); pIter(initialForm1); 258 } 259 return initialForm0; 260 } 261 262 /*** 263 * Computes the initial form of all generators of I. 264 * If I is a standard basis, then this is a standard basis 265 * of the initial ideal. 266 **/ 267 ideal initial(const ideal I, const ring r) 268 { 269 int k = idSize(I); ideal inI = idInit(k); 270 for (int i=0; i<k; i++) 271 inI->m[i] = initial(I->m[i],r); 272 return inI; 273 } 274 275 BOOLEAN initial(leftv res, leftv args) 276 { 277 leftv u = args; 278 if ((u != NULL) && (u->Typ() == POLY_CMD) && (u->next == NULL)) 279 { 280 poly p = (poly) u->Data(); 281 res->rtyp = POLY_CMD; 282 res->data = (void*) initial(p, currRing); 283 return FALSE; 284 } 285 if ((u != NULL) && (u->Typ() == IDEAL_CMD) && (u->next == NULL)) 286 { 287 ideal I = (ideal) u->Data(); 288 res->rtyp = IDEAL_CMD; 289 res->data = (void*) initial(I, currRing); 290 return FALSE; 291 } 292 WerrorS("initial: unexpected parameters"); 293 return TRUE; 294 } 200 // gfan::ZVector WDeg(const poly p, const ring r, const gfan::ZMatrix W) 201 // { 202 // gfan::ZVector d = gfan::ZVector(W.getHeight()); 203 // for (int i=0; i<W.getHeight(); i++) 204 // d[i] = wDeg(p,r,W[i]); 205 // return d; 206 // } 207 208 // /** 209 // * Checks if p is sorted with respect to w. 210 // */ 211 // static bool checkSloppyInput(const poly p, const ring r, const gfan::ZVector w) 212 // { 213 // long d = wDeg(p,r,w); 214 // for (poly currentTerm = p->next; currentTerm; pIter(currentTerm)) 215 // { 216 // long e = wDeg(currentTerm,r,w); 217 // if (e>d) 218 // return false; 219 // } 220 // return true; 221 // } 222 223 // /*** 224 // * Returns the terms of p of same weighted degree under w as the leading term. 225 // * Coincides with the initial form of p with respect to w if and only if p was already 226 // * sorted with respect to w in the sense that the leading term is of highest w-degree. 227 // **/ 228 // poly sloppyInitial(const poly p, const ring r, const gfan::ZVector w) 229 // { 230 // assume(checkSloppyInput(p,r,w)); 231 // int n = rVar(r); 232 // int* expv = (int*) omAlloc(n*sizeof(int)); 233 // poly q0 = p_Head(p,r); 234 // poly q1 = q0; 235 // long d = wDeg(p,r,w); 236 // for (poly currentTerm = p->next; currentTerm; pIter(currentTerm)) 237 // { 238 // if (wDeg(currentTerm,r,w) == d) 239 // { 240 // pNext(q1) = p_Head(currentTerm,r); 241 // pIter(q1); 242 // } 243 // } 244 // omFreeSize(expv,n*sizeof(int)); 245 // return q0; 246 // } 247 248 // /*** 249 // * Runs the above procedure over all generators of an ideal. 250 // * Coincides with the initial ideal of I with respect to w if and only if 251 // * the elements of I were already sorted with respect to w and 252 // * I is a standard basis form with respect to w. 253 // **/ 254 // ideal sloppyInitial(const ideal I, const ring r, const gfan::ZVector w) 255 // { 256 // int k = idSize(I); ideal inI = idInit(k); 257 // for (int i=0; i<k; i++) 258 // inI->m[i] = sloppyInitial(I->m[i],r,w); 259 // return inI; 260 // } 261 262 // #ifndef NDEBUG 263 // BOOLEAN initial0(leftv res, leftv args) 264 // { 265 // leftv u = args; 266 // ideal I = (ideal) u->CopyD(); 267 // leftv v = u->next; 268 // bigintmat* w0 = (bigintmat*) v->Data(); 269 // gfan::ZVector* w = bigintmatToZVector(w0); 270 // omUpdateInfo(); 271 // Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); 272 // ideal inI = initial(I,currRing,*w); 273 // id_Delete(&I,currRing); 274 // delete w; 275 // res->rtyp = IDEAL_CMD; 276 // res->data = (char*) inI; 277 // return FALSE; 278 // } 279 // #endif 280 281 // poly initial(const poly p, const ring r, const gfan::ZMatrix W) 282 // { 283 // poly q0 = p_Head(p,r); 284 // poly q1 = q0; 285 // gfan::ZVector d = WDeg(p,r,W); 286 // for (poly currentTerm = p->next; currentTerm; pIter(currentTerm)) 287 // { 288 // gfan::ZVector e = WDeg(currentTerm,r,W); 289 // if (d<e) 290 // { 291 // p_Delete(&q0,r); 292 // q0 = p_Head(p,r); 293 // q1 = q0; 294 // d = e; 295 // } 296 // else 297 // if (d==e) 298 // { 299 // pNext(q1) = p_Head(currentTerm,r); 300 // pIter(q1); 301 // } 302 // } 303 // return q0; 304 // } 305 306 // ideal initial(const ideal I, const ring r, const gfan::ZMatrix W) 307 // { 308 // int k = idSize(I); ideal inI = idInit(k); 309 // for (int i=0; i<k; i++) 310 // inI->m[i] = initial(I->m[i],r,W); 311 // return inI; 312 // } 313 314 // /*** 315 // * Computes the initial form of p with respect to the first row in the order matrix 316 // **/ 317 // poly initial(const poly p, const ring r) 318 // { 319 // long d = p_Deg(p,r); 320 // poly initialForm0 = p_Head(p,r); 321 // poly initialForm1 = initialForm0; 322 // poly currentTerm = p->next; 323 // while (currentTerm && p_Deg(currentTerm,r)==d) 324 // { 325 // pNext(initialForm1) = p_Head(currentTerm,r); 326 // pIter(currentTerm); pIter(initialForm1); 327 // } 328 // return initialForm0; 329 // } 330 331 // /*** 332 // * Computes the initial form of all generators of I. 333 // * If I is a standard basis, then this is a standard basis 334 // * of the initial ideal. 335 // **/ 336 // ideal initial(const ideal I, const ring r) 337 // { 338 // int k = idSize(I); ideal inI = idInit(k); 339 // for (int i=0; i<k; i++) 340 // inI->m[i] = initial(I->m[i],r); 341 // return inI; 342 // } 343 344 // BOOLEAN initial(leftv res, leftv args) 345 // { 346 // leftv u = args; 347 // if ((u != NULL) && (u->Typ() == POLY_CMD) && (u->next == NULL)) 348 // { 349 // poly p = (poly) u->Data(); 350 // res->rtyp = POLY_CMD; 351 // res->data = (void*) initial(p, currRing); 352 // return FALSE; 353 // } 354 // if ((u != NULL) && (u->Typ() == IDEAL_CMD) && (u->next == NULL)) 355 // { 356 // ideal I = (ideal) u->Data(); 357 // res->rtyp = IDEAL_CMD; 358 // res->data = (void*) initial(I, currRing); 359 // return FALSE; 360 // } 361 // WerrorS("initial: unexpected parameters"); 362 // return TRUE; 363 // } -
Singular/dyn_modules/gfanlib/initial.h
rdffd154 r4664b3 2 2 #define INITIAL_H 3 3 4 /** *4 /** 5 5 * various functions to compute the initial form of polynomials and ideals 6 **/ 6 */ 7 #include <gfanlib/gfanlib_vector.h> 8 #include <gfanlib/gfanlib_matrix.h> 9 #include <libpolys/polys/monomials/p_polys.h> 7 10 8 #include <gfanlib/gfanlib_vector.h> 9 #include <libpolys/polys/monomials/p_polys.h> 10 #include <Singular/ipid.h> 11 12 /*** 13 * Computes the weighted degree of the leading monomial of p with respect to w 14 **/ 11 /** 12 * Returns the weighted degree of the leading term of p with respect to w 13 */ 15 14 long wDeg(const poly p, const ring r, const gfan::ZVector w); 16 15 17 /*** 18 * Computes the weighted multidegree of the leading term of p with respect to W. 19 * The weighted multidegree is a vector whose i-th entry is the weighted degree 20 * with respect to the i-th row vector of W. 21 **/ 22 gfan::ZVector WDeg(const poly p, const ring r, const gfan::ZMatrix W); 16 /** 17 * Returns the weighted multidegree of the leading term of p with respect to (w,W). 18 * The weighted multidegree is a vector of length one higher than the column vectors of W. 19 * The first entry is the weighted degree with respect to w 20 * and the i+1st entry is the weighted degree with respect to the i-th row vector of W. 21 */ 22 gfan::ZVector WDeg(const poly p, const ring r, const gfan::ZVector w, const gfan::ZMatrix W); 23 23 24 /*** 25 * Returns the first terms of p of same weighted degree under w. 26 * Coincides with the initial form of p with respect to w if and only if p was already 27 * sorted with respect to w. 28 **/ 29 poly sloppyInitial(const poly p, const ring r, const gfan::ZVector w); 24 /** 25 * Returns the initial form of p with respect to w 26 */ 27 poly initial(const poly p, const ring r, const gfan::ZVector w); 30 28 31 /*** 32 * Runs the above procedure over all generators of an ideal. 33 * Coincides with the initial ideal of I with respect to w if and only if 34 * the elements of I were already sorted with respect to w and 35 * I is a standard basis form with respect to w. 36 **/ 37 ideal sloppyInitial(const ideal I, const ring r, const gfan::ZVector w); 29 /** 30 * Returns the initial form of I with respect to w 31 */ 32 ideal initial(const ideal I, const ring r, const gfan::ZVector w); 38 33 39 poly initial(const poly p, const ring r, const gfan::ZVector w); 40 ideal initial(const ideal I, const ring r, const gfan::ZVector w); 41 poly initial(const poly p, const ring r, const gfan::ZMatrix W); 42 ideal initial(const ideal I, const ring r, const gfan::ZMatrix W); 34 /** 35 * Returns the initial form of p with respect to w and W 36 */ 43 37 poly initial(const poly p, const ring r, const gfan::ZVector w, const gfan::ZMatrix W); 38 39 /** 40 * Returns the initial form of I with respect to w and W 41 */ 44 42 ideal initial(const ideal I, const ring r, const gfan::ZVector w, const gfan::ZMatrix W); 45 43 44 /** 45 * Stores the initial form of *pStar with respect to w in pStar 46 */ 47 void initial(poly* pStar, const ring r, const gfan::ZVector w); 46 48 47 poly initial(const poly p, const ring r); 48 ideal initial(const ideal I, const ring r); 49 BOOLEAN initial(leftv res, leftv args); 50 #ifndef NDEBUG 51 BOOLEAN initial0(leftv res, leftv args); 52 #endif 49 /** 50 * Stores the initial form of *IStar with respect to w in IStar 51 */ 52 void initial(ideal* IStar, const ring r, const gfan::ZVector w); 53 54 /** 55 * Stores the initial form of *pStar with respect to w and W in pStar 56 */ 57 void initial(poly* pStar, const ring r, const gfan::ZVector w, const gfan::ZMatrix W); 58 59 /** 60 * Stores the initial form of *IStar with respect to w and W in IStar 61 */ 62 void initial(ideal* IStar, const ring r, const gfan::ZVector w, const gfan::ZMatrix W); 63 64 /* throwaway code */ 65 /* #ifndef NDEBUG */ 66 /* BOOLEAN initial0(leftv res, leftv args); */ 67 /* #endif */ 68 /* /\*** */ 69 /* * Returns the first terms of p of same weighted degree under w. */ 70 /* * Coincides with the initial form of p with respect to w if and only if p was already */ 71 /* * sorted with respect to w. */ 72 /* **\/ */ 73 /* poly sloppyInitial(const poly p, const ring r, const gfan::ZVector w); */ 74 75 /* /\*** */ 76 /* * Runs the above procedure over all generators of an ideal. */ 77 /* * Coincides with the initial ideal of I with respect to w if and only if */ 78 /* * the elements of I were already sorted with respect to w and */ 79 /* * I is a standard basis form with respect to w. */ 80 /* **\/ */ 81 /* ideal sloppyInitial(const ideal I, const ring r, const gfan::ZVector w); */ 82 /* poly initial(const poly p, const ring r, const gfan::ZMatrix W); */ 83 /* ideal initial(const ideal I, const ring r, const gfan::ZMatrix W); */ 84 /* poly initial(const poly p, const ring r); */ 85 /* ideal initial(const ideal I, const ring r); */ 86 /* BOOLEAN initial(leftv res, leftv args); */ 53 87 54 88 #endif -
Singular/dyn_modules/gfanlib/ppinitialReduction.cc
rdffd154 r4664b3 8 8 #include <map> 9 9 #include <set> 10 #include <iostream> 11 #include <exception> 12 13 #include <ppinitialReduction.h> 10 14 11 15 bool isOrderingLocalInT(const ring r) … … 29 33 * with respect to p-t 30 34 **/ 31 boolpReduce(poly &g, const number p, const ring r)35 void pReduce(poly &g, const number p, const ring r) 32 36 { 33 37 if (g==NULL) 34 return false;38 return; 35 39 p_Test(g,r); 36 40 … … 68 72 { 69 73 WerrorS("pReduce: overflow in exponent"); 70 return true;74 throw 0; 71 75 } 72 76 } … … 89 93 } 90 94 p_Test(g,r); 91 return false;95 return; 92 96 } 93 97 … … 168 172 #endif //NDEBUG 169 173 170 boolpReduce0(ideal &I, const number p, const ring r)174 void pReduce0(ideal &I, const number p, const ring r) 171 175 { 172 176 int k = idSize(I); … … 177 181 number c = p_GetCoeff(I->m[i],r); 178 182 if (!n_Equal(p,c,r->cf)) 179 if (pReduce(I->m[i],p,r)) 180 return true; 181 } 182 } 183 return false; 183 pReduce(I->m[i],p,r); 184 } 185 } 186 return; 184 187 } 185 188 … … 215 218 h = p_Add_q(q1,q2,r); 216 219 p_Test(h,r); 217 hStar = &h; 220 p_Test(g,r); 221 *hStar = h; 218 222 return true; 219 223 } 224 p_Test(h,r); 225 p_Test(g,r); 220 226 return false; 221 227 } … … 279 285 } while(n); 280 286 for (int i=0; i<m; i++) 281 if (pReduce(I->m[i],p,r)) return true;287 pReduce(I->m[i],p,r); 282 288 283 289 /*** … … 286 292 for (int i=0; i<m-1; i++) 287 293 for (int j=i+1; j<m; j++) 288 if (ppreduceInitially(&I->m[j], I->m[i], r) && pReduce(I->m[j],p,r)) return true; 294 if (ppreduceInitially(&I->m[j], I->m[i], r)) 295 pReduce(I->m[j],p,r); 289 296 290 297 /*** … … 293 300 for (int i=0; i<m-1; i++) 294 301 for (int j=i+1; j<m; j++) 295 if (ppreduceInitially(&I->m[i], I->m[j],r) && pReduce(I->m[i],p,r)) return true; 302 if (ppreduceInitially(&I->m[i], I->m[j],r)) 303 pReduce(I->m[i],p,r); 296 304 297 305 /*** … … 338 346 /*** 339 347 * inserts g into I and reduces I with respect to itself and p-t 348 * returns the position in I in which g was inserted 340 349 * assumes that I was already sorted and initially reduced in the first place 341 350 **/ 342 bool ppreduceInitially(ideal I, const number p, const poly g, const ring r) 343 { 351 int ppreduceInitially(ideal I, const number p, const poly g, const ring r) 352 { 353 id_Test(I,r); 354 p_Test(g,r); 344 355 idInsertPoly(I,g); 345 356 int n=idSize(I); … … 362 373 **/ 363 374 for (int i=0; i<j; i++) 364 if (ppreduceInitially(&I->m[j], I->m[i], r) && pReduce(I->m[j],p,r)) return true; 375 if (ppreduceInitially(&I->m[j], I->m[i], r)) 376 pReduce(I->m[j],p,r); 365 377 for (int k=j+1; k<n; k++) 366 if (ppreduceInitially(&I->m[k], I->m[j], r) && pReduce(I->m[k],p,r)) return true; 378 if (ppreduceInitially(&I->m[k], I->m[j], r)) 379 pReduce(I->m[k],p,r); 367 380 368 381 /*** … … 372 385 for (int i=0; i<j; i++) 373 386 for (int k=j; k<n; k++) 374 if (ppreduceInitially(&I->m[i], I->m[k], r) && pReduce(I->m[i],p,r)) return true; 387 if (ppreduceInitially(&I->m[i], I->m[k], r)) 388 pReduce(I->m[i],p,r); 375 389 for (int k=j+1; k<n; k++) 376 if (ppreduceInitially(&I->m[j], I->m[k], r) && pReduce(I->m[j],p,r)) return true; 390 if (ppreduceInitially(&I->m[j], I->m[k], r)) 391 pReduce(I->m[j],p,r); 377 392 378 393 /*** … … 380 395 **/ 381 396 idSkipZeroes(I); 382 return false; 397 id_Test(I,r); 398 return j; 383 399 } 384 400 … … 423 439 424 440 441 static poly ppNext(poly p, int l) 442 { 443 poly q = p; 444 for (int i=0; i<l; i++) 445 { 446 if (q==NULL) 447 break; 448 pIter(q); 449 } 450 return q; 451 } 452 453 454 static void sortMarks(const ideal H, const ring r, std::vector<mark> &T) 455 { 456 std::pair<int,int> pointerToTerm; 457 int k=T.size(); 458 do 459 { 460 int j=0; 461 for (int i=1; i<k-1; i++) 462 { 463 int generatorA = T[i-1].first; 464 int termA = T[i-1].second; 465 int generatorB = T[i].first; 466 int termB = T[i].second; 467 if (p_LmCmp(ppNext(H->m[generatorA],termA),ppNext(H->m[generatorB],termB),r)<0) 468 { 469 mark cache=T[i-1]; 470 T[i-1]=T[i]; 471 T[i]=cache; 472 j = i; 473 } 474 } 475 k=j; 476 } while(k); 477 return; 478 } 479 480 481 static poly getTerm(const ideal H, const mark ab) 482 { 483 int a = ab.first; 484 int b = ab.second; 485 return ppNext(H->m[a],b); 486 } 487 488 489 static void adjustMarks(std::vector<mark> &T, const int newEntry) 490 { 491 for (unsigned i=0; i<T.size(); i++) 492 { 493 if (T[i].first>=newEntry) 494 T[i].first = T[i].first+1; 495 } 496 return; 497 } 498 499 500 static void cleanupMarks(const ideal H, std::vector<mark> &T) 501 { 502 for (unsigned i=0; i<T.size();) 503 { 504 if (getTerm(H,T[i])==NULL) 505 T.erase(T.begin()+i); 506 else 507 i++; 508 } 509 return; 510 } 511 512 425 513 /*** 426 514 * reduces H initially with respect to itself, with respect to p-t, … … 437 525 438 526 /*** 439 * Step 2: initialize a working list T and an ideal I in which the reductions will take place 527 * Step 2: initialize an ideal I in which the reductions will take place- 528 * along the reduction it will be enlarged with elements that will be discarded at the end 529 * initialize a working list T which keeps track. 530 * the working list T is a vector of pairs of integer. 531 * if T contains a pair (i,j) then that means that in the i-th element of H 532 * term j and subsequent terms need to be checked for reduction. 533 * T is sorted by the ordering on the temrs the pairs correspond to. 440 534 **/ 441 535 int m=idSize(H),n=0; 442 ideal I = idInit(m), T = idInit(m); 536 ideal I = idInit(m); 537 std::vector<mark> T; 443 538 for (int i=0; i<m; i++) 444 539 { 445 540 I->m[i]=H->m[i]; 446 if (pNext(H->m[i])) T->m[n++]=H->m[i]; 447 } 448 poly g; int k=n; 449 do 450 { 451 int j=0; 452 for (int i=1; i<k; i++) 453 { 454 if (p_LmCmp(pNext(T->m[i-1]),pNext(T->m[i]),r)<0) 455 { 456 g=T->m[i-1]; 457 T->m[i-1]=T->m[i]; 458 T->m[i]=g; 459 j = i; 460 } 461 } 462 k=j; 463 } while(k); 541 if (pNext(I->m[i])!=NULL) 542 T.push_back(std::make_pair<int,int>(i,1)); 543 } 464 544 465 545 /*** … … 467 547 * by adding suitable elements to I and reducing it initially with respect to itself 468 548 **/ 469 k=idSize(G); 470 while (n) 471 { 549 int k=idSize(G); 550 while (T.size()>0) 551 { 552 sortMarks(I,r,T); 553 std::cout << "T.size()=" << T.size() << std::endl; 554 std::cout << "T[0] = (" << T[0].first << "," << T[0].second << ")" << std::endl; 472 555 int i=0; for (; i<k; i++) 473 if (p_LeadmonomDivisibleBy(G->m[i], pNext(T->m[0]),r)) break;556 if (p_LeadmonomDivisibleBy(G->m[i],getTerm(I,T[0]),r)) break; 474 557 if (i<k) 475 558 { 476 g = p_One(r); 559 if (T[0].first==10 && T[0].second==3) 560 { 561 std::cout << "check this" << std::endl; 562 } 563 std::cout << "reducing" << std::endl; 564 poly g = p_One(r); poly h0 = getTerm(I,T[0]); 565 assume(h0!=NULL); 477 566 for (int j=2; j<=r->N; j++) 478 p_SetExp(g,j,p_GetExp( pNext(T->m[0]),j,r)-p_GetExp(G->m[i],j,r),r);567 p_SetExp(g,j,p_GetExp(h0,j,r)-p_GetExp(G->m[i],j,r),r); 479 568 p_Setm(g,r); 480 569 g = p_Mult_q(g,p_Copy(G->m[i],r),r); 481 ppreduceInitially(I,p,g,r); 570 int newEntry = ppreduceInitially(I,p,g,r); 571 adjustMarks(T,newEntry); 482 572 } 483 573 else 484 pIter(T->m[0]); 485 for (int i=0; i<n;) 486 { 487 if (!pNext(T->m[i])) 488 { 489 for (int j=i; j<n-1; j++) 490 T->m[j]=T->m[j+1]; 491 T->m[--n]=NULL; 492 } 493 else 494 i++; 495 } 496 int l = n; 497 do 498 { 499 int j=0; 500 for (int i=1; i<l; i++) 501 { 502 if (p_LmCmp(pNext(T->m[i-1]),pNext(T->m[i]),r)<0) 503 { 504 g=T->m[i-1]; 505 T->m[i-1]=I->m[i]; 506 T->m[i]=g; 507 j = i; 508 } 509 } 510 l=j; 511 } while(l); 574 T[0].second = T[0].second+1; 575 cleanupMarks(I,T); 512 576 } 513 577 … … 528 592 } 529 593 id_Delete(&I,r); 530 id_Delete(&T,r);531 594 return false; 532 595 } … … 701 764 m += l; IDELEMS(GG) = m; GG->m = &G->m[n-m]; 702 765 // std::vector<int> synch = synchronize(I,it->second); 766 id_Test(it->second,r); 767 id_Test(GG,r); 768 if (ppreduceInitially(it->second,p,r)) return true; 703 769 if (ppreduceInitially(it->second,p,GG,r)) return true; 770 id_Test(it->second,r); 771 id_Test(GG,r); 704 772 // synchronize(I,it->second,synch); 705 773 idShallowDelete(&Hi); Hi = it->second; -
Singular/dyn_modules/gfanlib/ppinitialReduction.h
rdffd154 r4664b3 14 14 #endif 15 15 16 typedef std::pair<int,int> mark; 17 typedef std::vector<std::pair<int,int> > marks; 18 16 19 bool isOrderingLocalInT(const ring r); 17 boolpReduce0(ideal &I, const number p, const ring r);20 void pReduce0(ideal &I, const number p, const ring r); 18 21 bool ppreduceInitially(ideal I, const ring r, const number p); 19 22 BOOLEAN ppreduceInitially(leftv res, leftv args); -
Singular/dyn_modules/gfanlib/startingCone.cc
rdffd154 r4664b3 367 367 368 368 // compute the initial ideal with respect to the weight 369 inI = sloppyInitial(inI,s,startingPoint);369 inI = initial(inI,s,startingPoint); 370 370 zc = linealitySpaceOfGroebnerFan(inI,s); 371 371 } … … 417 417 inJ = ambientMaximalCone.getPolynomialIdeal(); 418 418 s = ambientMaximalCone.getPolynomialRing(); 419 inJ = sloppyInitial(inJ,s,startingPoint);419 inJ = initial(inJ,s,startingPoint); 420 420 ideal inI = initial(I,r,startingPoint); 421 421 zc = linealitySpaceOfGroebnerFan(inJ,s); … … 464 464 gfan::ZCone zd = startingConeShortcut.getPolyhedralCone(); 465 465 gfan::ZVector interiorPoint = startingConeShortcut.getInteriorPoint(); 466 inJShortcut = sloppyInitial(inJShortcut,sShortcut,interiorPoint);466 inJShortcut = initial(inJShortcut,sShortcut,interiorPoint); 467 467 inI = initial(inI,r,interiorPoint); 468 468 -
Singular/dyn_modules/gfanlib/tropical.cc
rdffd154 r4664b3 175 175 p->iiAddCproc("","groebnerCone",FALSE,groebnerCone); 176 176 p->iiAddCproc("","maximalGroebnerCone",FALSE,maximalGroebnerCone); 177 p->iiAddCproc("","initial",FALSE,initial);177 // p->iiAddCproc("","initial",FALSE,initial); 178 178 // p->iiAddCproc("","tropicalNeighbours",FALSE,tropicalNeighbours); 179 179 #ifndef NDEBUG -
Singular/dyn_modules/gfanlib/tropicalStrategy.cc
rdffd154 r4664b3 325 325 } 326 326 327 booltropicalStrategy::pReduce(ideal I, const ring r) const327 void tropicalStrategy::pReduce(ideal I, const ring r) const 328 328 { 329 329 rTest(r); … … 331 331 332 332 if (isValuationTrivial()) 333 return false;333 return; 334 334 335 335 nMapFunc identity = n_SetMap(startingRing->cf,r->cf); 336 336 number p = identity(uniformizingParameter,startingRing->cf,r->cf); 337 bool b =pReduce0(I,p,r);337 pReduce0(I,p,r); 338 338 n_Delete(&p,r->cf); 339 339 340 return b;340 return; 341 341 } 342 342 -
Singular/dyn_modules/gfanlib/tropicalStrategy.h
rdffd154 r4664b3 283 283 bool reduce(ideal I, const ring r) const; 284 284 285 boolpReduce(ideal I, const ring r) const;285 void pReduce(ideal I, const ring r) const; 286 286 287 287 /**
Note: See TracChangeset
for help on using the changeset viewer.