Changeset 9c0326 in git
- Timestamp:
- Sep 10, 2014, 5:43:31 PM (9 years ago)
- Branches:
- (u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
- Children:
- b71400abefd0c9c66c0009063f40ddd5b1f1c4c7
- Parents:
- eacb78146504ca284c1888c739cb1aade67c8520
- git-author:
- Yue Ren <ren@mathematik.uni-kl.de>2014-09-10 17:43:31+02:00
- git-committer:
- Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:04+01:00
- Files:
-
- 1 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/gfanlib/bbcone.cc
reacb781 r9c0326 1607 1607 WerrorS("facetContaining: unexpected parameters"); 1608 1608 return TRUE; 1609 } 1610 1611 1612 BOOLEAN memleaktest(leftv res, leftv args) 1613 { 1614 bigintmat* ineq = NULL; 1615 if (args->Typ() == INTMAT_CMD) 1616 { 1617 intvec* ineq0 = (intvec*) args->Data(); 1618 ineq = iv2bim(ineq0,coeffs_BIGINT); 1619 } 1620 else 1621 ineq = (bigintmat*) args->Data(); 1622 gfan::ZMatrix* zm = bigintmatToZMatrix(ineq); 1623 gfan::ZCone* zc = new gfan::ZCone(*zm, gfan::ZMatrix(0, zm->getWidth())); 1624 delete zm; 1625 if (args->Typ() == INTMAT_CMD) 1626 delete ineq; 1627 res->rtyp = coneID; 1628 res->data = (void*) zc; 1629 return FALSE; 1609 1630 } 1610 1631 … … 1664 1685 p->iiAddCproc("","listOfFacets",FALSE,listOfFacets); 1665 1686 p->iiAddCproc("","facetContaining",FALSE,facetContaining); 1687 p->iiAddCproc("","memleaktest",FALSE,memleaktest); 1666 1688 coneID=setBlackboxStuff(b,"cone"); 1667 1689 } -
Singular/dyn_modules/gfanlib/flip.cc
reacb781 r9c0326 38 38 * (2) Is is a Groebner basis of the same ideal with respect to the ordering on s 39 39 **/ 40 std::pair<ideal,ring> flip 0(const ideal I, const ring r,41 42 43 44 40 std::pair<ideal,ring> flip(const ideal I, const ring r, 41 const gfan::ZVector interiorPoint, 42 const gfan::ZVector facetNormal, 43 const gfan::ZVector adjustedInteriorPoint, 44 const gfan::ZVector adjustedFacetNormal) 45 45 { 46 46 /* create a ring with weighted ordering */ … … 78 78 rChangeCurrRing(sAdjusted); 79 79 ideal inIsAdjustedGB = kStd(inIsAdjusted,currRing->qideal,testHomog,&nullVector); 80 ideal IsAdjustedGB = lift(I,r,inIsAdjustedGB,sAdjusted); 80 81 id_Delete(&inIsAdjusted,sAdjusted); 81 ideal IsAdjustedGB = lift(I,r,inIsAdjustedGB,sAdjusted);82 82 id_Delete(&inIsAdjustedGB,sAdjusted); 83 83 -
Singular/dyn_modules/gfanlib/flip.h
reacb781 r9c0326 6 6 #include <gfanlib/gfanlib_vector.h> 7 7 8 std::pair<ideal,ring> flip 0(const ideal I, const ring r,9 10 11 12 8 std::pair<ideal,ring> flip(const ideal I, const ring r, 9 const gfan::ZVector interiorPoint, 10 const gfan::ZVector facetNormal, 11 const gfan::ZVector adjustedInteriorPoint, 12 const gfan::ZVector adjustedFacetNormal); 13 13 14 14 #endif -
Singular/dyn_modules/gfanlib/groebnerCone.cc
reacb781 r9c0326 12 12 #include <gfanlib/gfanlib_matrix.h> 13 13 14 #include <initial.h> 14 15 #include <tropicalStrategy.h> 15 16 #include <groebnerCone.h> … … 57 58 groebnerCone::groebnerCone(): 58 59 polynomialIdeal(NULL), 60 reducedPolynomialIdeal(NULL), 61 initialPolynomialIdeal(NULL), 59 62 polynomialRing(NULL), 60 63 polyhedralCone(gfan::ZCone(0)), … … 66 69 groebnerCone::groebnerCone(const ideal I, const ring r, const tropicalStrategy& currentCase): 67 70 polynomialIdeal(NULL), 71 reducedPolynomialIdeal(NULL), 72 initialPolynomialIdeal(NULL), 68 73 polynomialRing(NULL), 69 74 currentStrategy(¤tCase) 70 75 { 71 76 assume(checkPolynomialInput(I,r)); 72 if (I) polynomialIdeal = id_Copy(I,r); 77 if (I) 78 { 79 polynomialIdeal = id_Copy(I,r); 80 reducedPolynomialIdeal = id_Copy(I,r); 81 } 73 82 if (r) polynomialRing = rCopy(r); 74 currentCase.reduce( I,r);83 currentCase.reduce(reducedPolynomialIdeal,polynomialRing); 75 84 76 85 int n = rVar(polynomialRing); … … 81 90 gfan::ZVector tailexpw = gfan::ZVector(n); 82 91 gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); 83 for (int i=0; i<idSize( polynomialIdeal); i++)84 { 85 g = I->m[i];92 for (int i=0; i<idSize(reducedPolynomialIdeal); i++) 93 { 94 g = reducedPolynomialIdeal->m[i]; 86 95 if (g) 87 96 { … … 110 119 polyhedralCone.canonicalize(); 111 120 interiorPoint = polyhedralCone.getRelativeInteriorPoint(); 121 initialPolynomialIdeal = sloppyInitial(reducedPolynomialIdeal,polynomialRing,interiorPoint); 112 122 assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); 113 123 } … … 122 132 groebnerCone::groebnerCone(const ideal I, const ring r, const gfan::ZVector& w, const tropicalStrategy& currentCase): 123 133 polynomialIdeal(NULL), 134 reducedPolynomialIdeal(NULL), 135 initialPolynomialIdeal(NULL), 124 136 polynomialRing(NULL), 125 137 currentStrategy(¤tCase) 126 138 { 127 139 assume(checkPolynomialInput(I,r)); 128 if (I) polynomialIdeal = id_Copy(I,r); 140 if (I) 141 { 142 polynomialIdeal = id_Copy(I,r); 143 reducedPolynomialIdeal = id_Copy(I,r); 144 } 129 145 if (r) polynomialRing = rCopy(r); 130 currentCase.reduce( I,r);131 132 int n = rVar( r);146 currentCase.reduce(reducedPolynomialIdeal,polynomialRing); 147 148 int n = rVar(polynomialRing); 133 149 gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); 134 150 gfan::ZMatrix equations = gfan::ZMatrix(0,n); 135 151 int* expv = (int*) omAlloc((n+1)*sizeof(int)); 136 for (int i=0; i<idSize( polynomialIdeal); i++)137 { 138 poly g = polynomialIdeal->m[i];152 for (int i=0; i<idSize(reducedPolynomialIdeal); i++) 153 { 154 poly g = reducedPolynomialIdeal->m[i]; 139 155 if (g) 140 156 { … … 167 183 polyhedralCone.canonicalize(); 168 184 interiorPoint = polyhedralCone.getRelativeInteriorPoint(); 185 initialPolynomialIdeal = sloppyInitial(reducedPolynomialIdeal,polynomialRing,interiorPoint); 169 186 assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); 170 187 } … … 176 193 groebnerCone::groebnerCone(const ideal I, const ring r, const gfan::ZVector& u, const gfan::ZVector& w, const tropicalStrategy& currentCase): 177 194 polynomialIdeal(NULL), 195 reducedPolynomialIdeal(NULL), 196 initialPolynomialIdeal(NULL), 178 197 polynomialRing(NULL), 179 198 currentStrategy(¤tCase) 180 199 { 181 200 assume(checkPolynomialInput(I,r)); 182 if (I) polynomialIdeal = id_Copy(I,r); 201 if (I) 202 { 203 polynomialIdeal = id_Copy(I,r); 204 reducedPolynomialIdeal = id_Copy(I,r); 205 } 183 206 if (r) polynomialRing = rCopy(r); 184 currentCase.reduce( I,r);185 186 int n = rVar( r);207 currentCase.reduce(reducedPolynomialIdeal,polynomialRing); 208 209 int n = rVar(polynomialRing); 187 210 gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); 188 211 gfan::ZMatrix equations = gfan::ZMatrix(0,n); 189 212 int* expv = (int*) omAlloc((n+1)*sizeof(int)); 190 for (int i=0; i<idSize( polynomialIdeal); i++)191 { 192 poly g = polynomialIdeal->m[i];213 for (int i=0; i<idSize(reducedPolynomialIdeal); i++) 214 { 215 poly g = reducedPolynomialIdeal->m[i]; 193 216 if (g) 194 217 { … … 222 245 polyhedralCone.canonicalize(); 223 246 interiorPoint = polyhedralCone.getRelativeInteriorPoint(); 247 initialPolynomialIdeal = sloppyInitial(reducedPolynomialIdeal,polynomialRing,interiorPoint); 224 248 assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); 225 249 } … … 228 252 groebnerCone::groebnerCone(const ideal I, const ideal inI, const ring r, const tropicalStrategy& currentCase): 229 253 polynomialIdeal(id_Copy(I,r)), 254 reducedPolynomialIdeal(id_Copy(I,r)), 255 initialPolynomialIdeal(id_Copy(inI,r)), 230 256 polynomialRing(rCopy(r)), 231 257 currentStrategy(¤tCase) … … 233 259 assume(checkPolynomialInput(I,r)); 234 260 assume(checkPolynomialInput(inI,r)); 261 currentStrategy->reduce(reducedPolynomialIdeal,polynomialRing); 262 // currentStrategy->reduce(initialPolynomialIdeal,polynomialRing); 263 235 264 int n = rVar(r); 236 265 gfan::ZMatrix equations = gfan::ZMatrix(0,n); 237 266 int* expv = (int*) omAlloc((n+1)*sizeof(int)); 238 for (int i=0; i<idSize(in I); i++)239 { 240 poly g = in I->m[i];267 for (int i=0; i<idSize(initialPolynomialIdeal); i++) 268 { 269 poly g = initialPolynomialIdeal->m[i]; 241 270 if (g) 242 271 { … … 252 281 } 253 282 gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); 254 for (int i=0; i<idSize( I); i++)255 { 256 poly g = I->m[i];283 for (int i=0; i<idSize(reducedPolynomialIdeal); i++) 284 { 285 poly g = reducedPolynomialIdeal->m[i]; 257 286 if (g) 258 287 { … … 283 312 groebnerCone::groebnerCone(const groebnerCone &sigma): 284 313 polynomialIdeal(NULL), 314 reducedPolynomialIdeal(NULL), 315 initialPolynomialIdeal(NULL), 285 316 polynomialRing(NULL), 286 317 polyhedralCone(gfan::ZCone(sigma.getPolyhedralCone())), … … 292 323 assume(checkPolyhedralInput(sigma.getPolyhedralCone(),sigma.getInteriorPoint())); 293 324 if (sigma.getPolynomialIdeal()) polynomialIdeal = id_Copy(sigma.getPolynomialIdeal(),sigma.getPolynomialRing()); 325 if (sigma.getReducedPolynomialIdeal()) reducedPolynomialIdeal = id_Copy(sigma.getReducedPolynomialIdeal(),sigma.getPolynomialRing()); 326 if (sigma.getInitialPolynomialIdeal()) initialPolynomialIdeal = id_Copy(sigma.getInitialPolynomialIdeal(),sigma.getPolynomialRing()); 294 327 if (sigma.getPolynomialRing()) polynomialRing = rCopy(sigma.getPolynomialRing()); 295 328 } … … 333 366 { 334 367 assume(!currentStrategy->restrictToLowerHalfSpace() || R[i][0].sign()<=0); 368 if (currentStrategy->restrictToLowerHalfSpace() && R[i][0].sign()==0) 369 continue; 335 370 poly s = currentStrategy->checkInitialIdealForMonomial(I,r,R[i]); 336 371 if (s==NULL) … … 355 390 return false; 356 391 } 392 if (polyhedralCone.containsRelatively(interiorPoint)) 393 { 394 std::cout << "ERROR: interiorPoint is contained in the interior of the maximal Groebner cone!" << std::endl 395 << "cone: " << std::endl 396 << toString(&polyhedralCone) 397 << "interiorPoint:" << std::endl 398 << interiorPoint << std::endl; 399 return false; 400 } 357 401 gfan::ZCone hopefullyAFacet = polyhedralCone.faceContaining(interiorPoint); 358 402 if (hopefullyAFacet.dimension()!=(polyhedralCone.dimension()-1)) … … 379 423 } 380 424 381 /** *425 /** 382 426 * Given an interior point on the facet and the outer normal factor on the facet, 383 427 * returns the adjacent groebnerCone sharing that facet 384 * */428 */ 385 429 groebnerCone groebnerCone::flipCone(const gfan::ZVector interiorPoint, const gfan::ZVector facetNormal) const 386 430 { … … 391 435 * to obtain an initial form with respect to interiorPoint+e*facetNormal, 392 436 * for e>0 sufficiently small */ 393 std::pair<ideal,ring> flipped = currentStrategy->flip(polynomialIdeal,polynomialRing,interiorPoint,facetNormal); 394 std::cout << "finished flip" << std::endl; 437 std::pair<ideal,ring> flipped = currentStrategy->flip(reducedPolynomialIdeal,polynomialRing,interiorPoint,facetNormal); 395 438 assume(checkPolynomialInput(flipped.first,flipped.second)); 396 439 groebnerCone flippedCone(flipped.first, flipped.second, interiorPoint, facetNormal, *currentStrategy); … … 464 507 for (int i=0; i<interiorPoints.getHeight(); i++) 465 508 { 466 std::cout << "performing flip " << i << " out of " << interiorPoints.getHeight() << std::endl; 509 gfan::ZVector w = interiorPoints[i]; 510 gfan::ZVector v = facetNormals[i]; 511 if (currentStrategy->restrictToLowerHalfSpace()) 512 { 513 assume(w[0].sign()<=0); 514 if (w[0].sign()==0 && v[0].sign()>0) 515 continue; 516 } 467 517 neighbours.insert(this->flipCone(interiorPoints[i],facetNormals[i])); 468 518 } -
Singular/dyn_modules/gfanlib/groebnerCone.h
reacb781 r9c0326 35 35 ideal polynomialIdeal; 36 36 /** 37 * reduced form of the ideal from which the equations and inequalities can be read 38 */ 39 ideal reducedPolynomialIdeal; 40 /** 41 * generators of the initial ideal 42 */ 43 ideal initialPolynomialIdeal; 44 /** 37 45 * ring in which the ideal exists 38 46 */ … … 40 48 gfan::ZCone polyhedralCone; 41 49 gfan::ZVector interiorPoint; 42 gfan::ZVector negativePointInLineality;43 50 const tropicalStrategy* currentStrategy; 44 51 … … 67 74 68 75 ideal getPolynomialIdeal() const { return polynomialIdeal; }; 76 ideal getReducedPolynomialIdeal() const { return reducedPolynomialIdeal; }; 77 ideal getInitialPolynomialIdeal() const { return initialPolynomialIdeal; }; 69 78 ring getPolynomialRing() const { return polynomialRing; }; 70 79 gfan::ZCone getPolyhedralCone() const { return polyhedralCone; }; 71 80 gfan::ZVector getInteriorPoint() const { return interiorPoint; }; 72 gfan::ZVector getNegativePointInLineality() const { return negativePointInLineality; };73 81 const tropicalStrategy* getTropicalStrategy() const {return currentStrategy; }; 74 82 -
Singular/dyn_modules/gfanlib/initial.cc
reacb781 r9c0326 39 39 } 40 40 41 /** *41 /** 42 42 * Checks if p is sorted with respect to w. 43 * */43 */ 44 44 static bool checkSloppyInput(const poly p, const ring r, const gfan::ZVector w) 45 45 { -
Singular/dyn_modules/gfanlib/lift.cc
reacb781 r9c0326 9 9 * the ordering of s. 10 10 **/ 11 ideal lift(const ideal I, const ring r, const ideal inI, const ring s) 11 // ideal lift(const ideal I, const ring r, const ideal inI, const ring s) 12 // { 13 // nMapFunc identity = n_SetMap(r->cf,s->cf); 14 // int k = idSize(I); ideal Is = idInit(k); 15 // for (int i=0; i<k; i++) 16 // Is->m[i] = p_PermPoly(I->m[i],NULL,r,s,identity,NULL,0); 17 // ideal J = idInit(k); 18 // for (int i=0; i<k; i++) 19 // J->m[i] = witness(inI->m[i],Is,inI,s); 20 // id_Delete(&Is,s); 21 // return J; 22 // } 23 24 ideal lift(const ideal J, const ring r, const ideal inI, const ring s) 12 25 { 13 nMapFunc identity = n_SetMap( r->cf,s->cf);14 int k = idSize( I); ideal Is= idInit(k);26 nMapFunc identity = n_SetMap(s->cf,r->cf); 27 int k = idSize(inI); ideal inIr = idInit(k); 15 28 for (int i=0; i<k; i++) 16 Is->m[i] = p_PermPoly(I->m[i],NULL,r,s,identity,NULL,0); 17 ideal J = idInit(k); 29 inIr->m[i] = p_PermPoly(inI->m[i],NULL,s,r,identity,NULL,0); 30 ideal Ir = witness(inIr,J,r); 31 32 identity = n_SetMap(r->cf,s->cf); 33 ideal Is = idInit(k); 18 34 for (int i=0; i<k; i++) 19 J->m[i] = witness(inI->m[i],Is,inI,s); 20 id_Delete(&Is,s); 21 return J; 35 Is->m[i] = p_PermPoly(Ir->m[i],NULL,r,s,identity,NULL,0); 36 37 id_Delete(&inIr,r); 38 id_Delete(&Ir,r); 39 return Is; 22 40 } -
Singular/dyn_modules/gfanlib/startingCone.cc
reacb781 r9c0326 457 457 458 458 ideal J = lift(I,r,inI,s); 459 // currentStrategy.reduce(J,s); 459 460 groebnerCone startingCone(J,inI,s,currentStrategy); 460 461 id_Delete(&inI,s); -
Singular/dyn_modules/gfanlib/tropicalStrategy.cc
reacb781 r9c0326 4 4 #include <ttinitialReduction.h> 5 5 #include <tropical.h> 6 #include <std_wrapper.h> 6 7 7 8 // for various commands in dim(ideal I, ring r): … … 23 24 { 24 25 int i = idPosConstant(I); 25 if ((i != -1) && (n_IsUnit(p GetCoeff(I->m[i]),currRing->cf)))26 if ((i != -1) && (n_IsUnit(p_GetCoeff(I->m[i],currRing->cf),currRing->cf))) 26 27 return -1; 27 28 ideal vv = id_Head(I,currRing); … … 66 67 { 67 68 assume(rField_is_Q(r) || rField_is_Zp(r)); 69 startingIdeal = gfanlib_kStd_wrapper(startingIdeal,startingRing); 68 70 if (!completelyHomogeneous) 69 71 { … … 174 176 startingIdeal->m[i+1] = p_PermPoly(J->m[i],shiftByOne,originalRing,startingRing,nMap,NULL,0); 175 177 omFreeSize(shiftByOne,(n+1)*sizeof(int)); 178 startingIdeal = gfanlib_kStd_wrapper(startingIdeal,startingRing); 176 179 177 180 linealitySpace = homogeneitySpace(startingIdeal,startingRing); … … 247 250 return *this; 248 251 } 252 253 bool tropicalStrategy::reduce(ideal I, const ring r) const 254 { 255 rTest(r); 256 id_Test(I,r); 257 nMapFunc nMap = n_SetMap(startingRing->cf,r->cf); 258 number p = nMap(uniformizingParameter,startingRing->cf,r->cf); 259 bool b = this->extraReductionAlgorithm(I,r,p); 260 n_Delete(&p,r->cf); 261 return b; 262 } 263 264 ring tropicalStrategy::getShortcutRingPrependingWeight(const ring r, const gfan::ZVector v) const 265 { 266 ring rShortcut = rCopy0(r); 267 268 // save old ordering 269 int* order = rShortcut->order; 270 int* block0 = rShortcut->block0; 271 int* block1 = rShortcut->block1; 272 int** wvhdl = rShortcut->wvhdl; 273 274 // adjust weight and create new ordering 275 gfan::ZVector w = adjustWeightForHomogeneity(v); 276 int h = rBlocks(r); int n = rVar(r); 277 rShortcut->order = (int*) omAlloc0((h+1)*sizeof(int)); 278 rShortcut->block0 = (int*) omAlloc0((h+1)*sizeof(int)); 279 rShortcut->block1 = (int*) omAlloc0((h+1)*sizeof(int)); 280 rShortcut->wvhdl = (int**) omAlloc0((h+1)*sizeof(int*)); 281 rShortcut->order[0] = ringorder_a; 282 rShortcut->block0[0] = 1; 283 rShortcut->block1[0] = n; 284 bool overflow; 285 rShortcut->wvhdl[0] = ZVectorToIntStar(w,overflow); 286 for (int i=1; i<=h; i++) 287 { 288 rShortcut->order[i] = order[i-1]; 289 rShortcut->block0[i] = block0[i-1]; 290 rShortcut->block1[i] = block1[i-1]; 291 rShortcut->wvhdl[i] = wvhdl[i-1]; 292 } 293 294 // if valuation non-trivial, change coefficient ring to residue field 295 if (valuationIsNonTrivial()) 296 { 297 nKillChar(rShortcut->cf); 298 rShortcut->cf = nCopyCoeff(shortcutRing->cf); 299 } 300 rComplete(rShortcut); 301 rTest(rShortcut); 302 303 // delete old ordering 304 omFree(order); 305 omFree(block0); 306 omFree(block1); 307 omFree(wvhdl); 308 309 return rShortcut; 310 } 311 312 poly tropicalStrategy::checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w) const 313 { 314 // prepend extra weight for homogeneity 315 // switch to residue field if valuation is non trivial 316 ring rShortcut = getShortcutRingPrependingWeight(r,w); 317 318 // compute the initial ideal and map it into the constructed ring 319 // if switched to residue field, remove possibly 0 elements 320 ideal inI = initial(I,r,w); 321 int k = idSize(inI); 322 ideal inIShortcut = idInit(k); 323 nMapFunc intoShortcut = n_SetMap(r->cf,rShortcut->cf); 324 for (int i=0; i<k; i++) 325 inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,intoShortcut,NULL,0); 326 if (isValuationNonTrivial()) 327 idSkipZeroes(inIShortcut); 328 329 // check initial ideal for monomial and 330 // if it exsists, return a copy of the monomial in the input ring 331 poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut); 332 poly monomial = NULL; 333 if (p!=NULL) 334 { 335 monomial=p_One(r); 336 for (int i=1; i<n; i++) 337 p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r); 338 p_Delete(&p,rShortcut); 339 } 340 id_Delete(&inI,r); 341 id_Delete(&inIShortcut,rShortcut); 342 rDelete(rShortcut); 343 return monomial; 344 } 345 346 ring tropicalStrategy::copyAndChangeCoefficientRing(const ring r) const 347 { 348 ring rShortcut = rCopy0(r); 349 nKillChar(rShortcut->cf); 350 rShortcut->cf = nCopyCoeff(shortcutRing->cf); 351 rComplete(rShortcut); 352 rTest(rShortcut); 353 return rShortcut; 354 } 355 356 ideal getWitness(const ideal inJ, const ideal inI, const ideal I, const ring r) const 357 { 358 // if the valuation is trivial and the ring and ideal have not been extended, 359 // then it is sufficient to return the difference between the elements of inJ 360 // and their normal forms with respect to I and r 361 if (isValuationTrivial()) 362 return witness(inJ,I,r); 363 // if the valuation is non-trivial and the ring and ideal have been extended, 364 // then we can make a shortcut through the residue field 365 else 366 { 367 checkFirstGenerator(I,r); 368 assume(idSize(inI)==idSize(I)); 369 /** 370 * change ground ring into finite field 371 * and map the data into it 372 */ 373 ring rShortcut = copyAndChangeCoefficientRing(r); 374 375 int k = idSize(inI); 376 int l = idSize(I); 377 ideal inJShortcut = idInit(k); 378 ideal inIShortcut = idInit(l); 379 nMapFunc takingResidues = n_SetMap(r->cf,rShortcut->cf); 380 for (int i=0; i<k; i++) 381 inJShortcut->m[i] = p_PermPoly(inJ->m[i],NULL,r,rShortcut,takingResidues,NULL,0); 382 for (int j=0; j<l; j++) 383 inIShortcut->m[j] = p_PermPoly(inI->m[j],NULL,r,rShortcut,takingResidues,NULL,0); 384 id_Test(inJShortcut,rShortcut); 385 id_Test(inIShortcut,rShortcut); 386 387 /** 388 * Compute a division with remainder over the finite field 389 * and map the result back to r 390 */ 391 matrix QShortcut = divisionDiscardingRemainder(inJShortcut,inIShortcut,rShortcut); 392 matrix Q = mpNew(k,l); 393 nMapFunc takingRepresentatives = n_SetMap(rShortcut->cf,r->cf); 394 for (int ij=k*l-1; ij>=0; ij--) 395 Q->m[ij] = p_PermPoly(Q->m[ij],NULL,rShortcut,r,takingRepresentatives,NULL,0); 396 397 /** 398 * Compute the normal forms 399 */ 400 ideal J = idInit(k); 401 for (int j=0; j<l; j++) 402 { 403 poly q0 = p_Copy(inJ->m[j],r); 404 for (int i=1; i<k; i++) 405 q0 = p_Add_q(q0,p_Neg(p_Mult_q(p_Copy(MATELEM(Q,i,j),r),p_Copy(inI->m[i],r),r),r),r); 406 J->m[j] = p_Mult_q(q0,p_Copy(J->m[0],r),r); 407 q0 = NULL; 408 for (int i=1; i<k; i++) 409 J->m[j] = p_Add_q(I->m[j],p_Mult_q(p_Copy(MATELEM(Q,i,j),r),p_Copy(I->m[i],r),r),r); 410 } 411 412 return J; 413 } 414 } 415 416 ideal tropicalStrategy::getStdOfInitialIdeal(const ideal inI, const ring r) const 417 { 418 ideal inJ; 419 if (isValuationTrivial()) 420 // if valuation trivial, then compute std as usual 421 inJ = gfanlib_kStd_wrapper(inI,r); 422 else 423 { 424 // if valuation non-trivial, then uniformizing parameter is in ideal 425 // so switch to residue field first and compute standard basis over the residue field 426 ring rShortcut = copyAndChangeCoefficientRing(r); 427 nMapFunc takingResidues = n_SetMap(r->cf,rShortcut->cf); 428 int k = idSize(inI); 429 ideal inIShortcut = idInit(k); 430 for (int i=0; i<k; i++) 431 inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,takingResidues,NULL,0); 432 ideal inJShortcut = gfanlib_kStd_wrapper(inIShortcut,rShortcut); 433 434 // and lift the result back to the ring with valuation 435 nMapFunc takingRepresentatives = n_SetMap(rShortcut->cf,r->cf); 436 k = idSize(inJShortcut); 437 inJ = idInit(k+1); 438 inJ->m[0] = p_One(r); 439 p_SetCoeff(inJ->m[0],nMap(uniformizingParameter,startingRing->cf,r->cf),r); 440 for (int i=0; i<k; i++) 441 inJ->m[i+1] = p_PermPoly(inJShortcut->m[i],NULL,rShortcut,r,takingRepresentatives,NULL,0); 442 } 443 return inJ; 444 } 445 446 ring tropicalStrategy::copyAndChangeOrderingWP(const ring r, const gfan::ZVector w, const gfan::ZVector v) 447 { 448 // copy shortcutRing and change to desired ordering 449 bool ok; 450 ring s = rCopy0(r); 451 int n = rVar(s); 452 deleteOrdering(s); 453 gfan::ZVector wAdjusted = adjustWeightForHomogeneity(w); 454 gfan::ZVector vAdjusted = adjustWeightUnderHomogeneity(wAdjusted,v); 455 s->order = (int*) omAlloc0(4*sizeof(int)); 456 s->block0 = (int*) omAlloc0(4*sizeof(int)); 457 s->block1 = (int*) omAlloc0(4*sizeof(int)); 458 s->wvhdl = (int**) omAlloc0(4*sizeof(int**)); 459 s->order[0] = ringorder_a; 460 s->block0[0] = 1; 461 s->block1[0] = n; 462 s->wvhdl[0] = ZVectorToIntStar(adjustedInteriorPoint,ok); 463 s->order[1] = ringorder_wp; 464 s->block0[1] = 1; 465 s->block1[1] = n; 466 s->wvhdl[1] = ZVectorToIntStar(adjustedFacetNormal,ok); 467 s->order[2] = ringorder_C; 468 rComplete(s); 469 rTest(s); 470 471 return s; 472 } 473 474 ring tropicalStrategy::copyAndChangeOrderingDP(const ring r, const gfan::ZVector w, const gfan::ZVector v) 475 { 476 // copy shortcutRing and change to desired ordering 477 bool ok; 478 ring s = rCopy0(r); 479 int n = rVar(s); 480 deleteOrdering(s); 481 gfan::ZVector wAdjusted = adjustWeightForHomogeneity(w); 482 gfan::ZVector vAdjusted = adjustWeightUnderHomogeneity(wAdjusted,v); 483 s->order = (int*) omAlloc0(5*sizeof(int)); 484 s->block0 = (int*) omAlloc0(5*sizeof(int)); 485 s->block1 = (int*) omAlloc0(5*sizeof(int)); 486 s->wvhdl = (int**) omAlloc0(5*sizeof(int**)); 487 s->order[0] = ringorder_a; 488 s->block0[0] = 1; 489 s->block1[0] = n; 490 s->wvhdl[0] = ZVectorToIntStar(adjustedInteriorPoint,ok); 491 s->order[1] = ringorder_a; 492 s->block0[1] = 1; 493 s->block1[1] = n; 494 s->wvhdl[1] = ZVectorToIntStar(adjustedFacetNormal,ok); 495 s->order[2] = ringorder_dp; 496 s->block0[2] = 1; 497 s->block1[2] = n; 498 s->order[3] = ringorder_C; 499 rComplete(s); 500 rTest(s); 501 502 return s; 503 } 504 505 506 std::pair<ideal,ring> tropicalStrategy::getFlip(const ideal I, const ring r, 507 const gfan::ZVector interiorPoint, 508 const gfan::ZVector facetNormal) const 509 { 510 assume(isValuationTrivial() || interiorPoint[0].sign()<0); 511 assume(checkFirstGenerators(I,r)); 512 513 // get a generating system of the initial ideal 514 // and compute a standard basis with respect to adjacent ordering 515 ideal inIr = initial(I,r,interiorPoint); 516 ring sAdjusted = copyAndChangeOrderingWP(r,interiorPoint,facetNormal); 517 nMapFunc identity = n_SetMap(r->cf,sAdjusted->cf); 518 int k = idSize(I); ideal inIs = idInit(k); 519 for (int i=0; i<k; i++) 520 inIsAdjusted->m[i] = p_PermPoly(inIr->m[i],NULL,r,sAdjusted,identity,NULL,0); 521 ideal inJsAdjusted = getStdOfInitialIdeal(inIsAdjusted,sShortcut); 522 523 // find witnesses of the new standard basis elements of the initial ideal 524 // with the help of the old standard basis of the ideal 525 k = idSize(inJsAdjusted); 526 ideal inJr = idInit(k); 527 identity = n_SetMap(sAdjusted->cf,r->cf); 528 for (int i=0; i<k; i++) 529 inJr->m[i] = p_PermPoly(inJsAdjusted->m[i],NULL,sAdjusted,r,identity,NULL,0); 530 531 ideal Jr = getWitness(inJr,inIr,I,r); 532 ring s = copyAndChangeOrderingDP(r,interiorPoint,facetNormal); 533 identity = n_SetMap(r->cf,s->cf); 534 for (int i=0; i<k; i++) 535 Js->m[i] = p_PermPoly(inJsAdjusted->m[i],NULL,r,s,identity,NULL,0); 536 537 return std::make_pair(Js,s); 538 } -
Singular/dyn_modules/gfanlib/tropicalStrategy.h
reacb781 r9c0326 11 11 #include <flip.h> 12 12 #include <initial.h> 13 #include <witness.h> 13 14 14 15 /** \file … … 119 120 return b; 120 121 } 122 bool isValuationTrivial() const 123 { 124 bool b = (uniformizingParameter==NULL); 125 return b; 126 } 127 bool isValuationNonTrivial() const 128 { 129 bool b = (uniformizingParameter!=NULL); 130 return b; 131 } 121 132 122 133 /** … … 224 235 225 236 /** 237 * If valuation trivial, returns a copy of r with a positive weight prepended, 238 * such that any ideal homogeneous with respect to w is homogeneous with respect to that weight. 239 * If valuation non-trivial, changes the coefficient ring to the residue field. 240 */ 241 ring getShortcutRingPrependingWeight(const ring r, const gfan::ZVector w) const; 242 243 /** 244 * Returns a copy of the shortcutRing which is weighted with respect to w first and v second. 245 * If valuation trivial, the coefficient ring will be the field with valuation. 246 * If valuation non-trivial, the coefficient ring will be the residue field. 247 */ 248 ring getShortcutRingDoublyWeighted(const gfan::ZVector w, const gfan::ZVector v) const; 249 250 /** 251 * copies r and prepends extra weight w 252 */ 253 ring copyAndPrependWeight(const ring r, const gfan::ZVector w) const; 254 255 /** 256 * changes the coefficient ring of r to be the residue field 257 */ 258 void changeCoefficientToResidueField(ring r) const; 259 260 261 262 /** 226 263 * reduces the generators of an ideal I so that 227 264 * the inequalities and equations of the Groebner cone can be read off. 228 265 */ 229 bool reduce(ideal I, const ring r) const 230 { 231 rTest(r); id_Test(I,r); 232 nMapFunc nMap = n_SetMap(startingRing->cf,r->cf); 233 number p = nMap(uniformizingParameter,startingRing->cf,r->cf); 234 bool b = this->extraReductionAlgorithm(I,r,p); 235 n_Delete(&p,r->cf); 236 return b; 237 } 266 bool reduce(ideal I, const ring r) const; 238 267 239 268 /** … … 241 270 * returns false otherwise. 242 271 **/ 243 poly checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w) const 244 { 245 gfan::ZVector v = adjustWeightForHomogeneity(w); 246 if (isConstantCoefficientCase()) 247 { 248 ring rShortcut = rCopy0(r); 249 bool overflow; 250 /** 251 * prepend extra weight vector for homogeneity 252 */ 253 int* order = rShortcut->order; 254 int* block0 = rShortcut->block0; 255 int* block1 = rShortcut->block1; 256 int** wvhdl = rShortcut->wvhdl; 257 int h = rBlocks(r); int n = rVar(r); 258 rShortcut->order = (int*) omAlloc0((h+1)*sizeof(int)); 259 rShortcut->block0 = (int*) omAlloc0((h+1)*sizeof(int)); 260 rShortcut->block1 = (int*) omAlloc0((h+1)*sizeof(int)); 261 rShortcut->wvhdl = (int**) omAlloc0((h+1)*sizeof(int*)); 262 rShortcut->order[0] = ringorder_a; 263 rShortcut->block0[0] = 1; 264 rShortcut->block1[0] = n; 265 rShortcut->wvhdl[0] = ZVectorToIntStar(v,overflow); 266 for (int i=1; i<=h; i++) 272 poly checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector w) const; 273 274 /** 275 * suppose w a weight in maximal groebner cone of > 276 * suppose I (initially) reduced standard basis w.r.t. > and inI initial forms of its elements w.r.t. w 277 * suppose inJ elements of initial ideal that are homogeneous w.r.t w 278 * returns J elements of ideal whose initial form w.r.t. w are inI 279 * in particular, if w lies also inthe maximal groebner cone of another ordering >' 280 * and inJ is a standard basis of the initial ideal w.r.t. >' 281 * then the returned J will be a standard baiss of the ideal w.r.t. >' 282 */ 283 ideal getWitness(const ideal inJ, const ideal inI, const ideal I, const ring r) const; 284 285 /** 286 * given generators of the initial ideal, computes its standard basis 287 */ 288 ideal getStdOfInitialIdeal(const ideal inI, const ring r) const; 289 290 /** 291 * given an interior point of a groebner cone 292 * computes the groebner cone adjacent to it 293 */ 294 std::pair<ideal,ring> getFlip(const ideal I, const ring r, const gfan::ZVector interiorPoint, const gfan::ZVector facetNormal) const; 295 296 /** 297 * checks whether the first elements of I is p-t 298 */ 299 static bool checkFirstGenerator(ideal I, ring r) 300 { 301 // check for correct size of ideal and first generator 302 if (idSize(I)==0) 303 { 304 WerrorS("checkFirstElement: ideal empty"); 305 return false; 306 } 307 poly p = I->m[0]; 308 if (size(p)!=2) 309 { 310 WerrorS("checkFirstElement: no binomial"); 311 return false; 312 } 313 314 // check first term 315 int n = rVar(r); 316 if (!n_IsUnit(p_GetCoeff(p,r->cf),r->cf)) 317 { 318 WerrorS("checkFirstElement: wrong coefficient"); 319 return false; 320 } 321 for (int i=1; i<=n; i++) 322 { 323 if (p_GetExp(p,i,r)!=0) 267 324 { 268 rShortcut->order[i] = order[i-1]; 269 rShortcut->block0[i] = block0[i-1]; 270 rShortcut->block1[i] = block1[i-1]; 271 rShortcut->wvhdl[i] = wvhdl[i-1]; 325 WerrorS("checkFirstElement: wrong exponent vector"); 326 return false; 272 327 } 273 rComplete(rShortcut);274 rTest(rShortcut); 275 omFree(order);276 omFree(block0);277 omFree(block1);278 omFree(wvhdl);279 280 ideal inI = initial(I,r,w);281 int k = idSize(inI);282 ideal inIShortcut = idInit(k);283 nMapFunc identity = n_SetMap(r->cf,rShortcut->cf);284 for (int i=0; i<k; i++)285 inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,identity,NULL,0);286 287 poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut);288 poly monomial = NULL;289 if (p !=NULL)328 } 329 330 // check second term 331 pIter(p); 332 if (!n_IsOne(p_GetCoeff(p,r->cf),r->cf)) 333 { 334 WerrorS("checkFirstElement: wrong coefficient"); 335 return false; 336 } 337 if (p_GetExp(p,1,r)!=1) 338 { 339 WerrorS("checkFirstElement: wrong exponent vector"); 340 return false; 341 } 342 for (int i=2; i<=n; i++) 343 { 344 if (p_GetExp(p,i,r)!=0) 290 345 { 291 monomial=p_One(r); 292 for (int i=1; i<n; i++) 293 p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r); 294 p_Delete(&p,rShortcut); 346 WerrorS("checkFirstElement: wrong exponent vector"); 347 return false; 295 348 } 296 id_Delete(&inI,r); 297 id_Delete(&inIShortcut,rShortcut); 298 rDelete(rShortcut); 299 return monomial; 300 } 301 else 302 { 303 ring rShortcut = rCopy0(r); 304 bool overflow; 305 /** 306 * prepend extra weight vector for homogeneity 307 */ 308 int* order = rShortcut->order; 309 int* block0 = rShortcut->block0; 310 int* block1 = rShortcut->block1; 311 int** wvhdl = rShortcut->wvhdl; 312 int h = rBlocks(r); int n = rVar(r); 313 rShortcut->order = (int*) omAlloc0((h+1)*sizeof(int)); 314 rShortcut->block0 = (int*) omAlloc0((h+1)*sizeof(int)); 315 rShortcut->block1 = (int*) omAlloc0((h+1)*sizeof(int)); 316 rShortcut->wvhdl = (int**) omAlloc0((h+1)*sizeof(int*)); 317 rShortcut->order[0] = ringorder_a; 318 rShortcut->block0[0] = 1; 319 rShortcut->block1[0] = n; 320 rShortcut->wvhdl[0] = ZVectorToIntStar(v,overflow); 321 for (int i=1; i<=h; i++) 322 { 323 rShortcut->order[i] = order[i-1]; 324 rShortcut->block0[i] = block0[i-1]; 325 rShortcut->block1[i] = block1[i-1]; 326 rShortcut->wvhdl[i] = wvhdl[i-1]; 327 } 328 omFree(order); 329 omFree(block0); 330 omFree(block1); 331 omFree(wvhdl); 332 /** 333 * change ground domain into finite field 334 */ 335 nKillChar(rShortcut->cf); 336 rShortcut->cf = nCopyCoeff(shortcutRing->cf); 337 rComplete(rShortcut); 338 rTest(rShortcut); 339 340 ideal inI = initial(I,r,w); 341 int k = idSize(inI); 342 ideal inIShortcut = idInit(k); 343 nMapFunc takingResidues = n_SetMap(r->cf,rShortcut->cf); 344 for (int i=0; i<k; i++) 345 inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,takingResidues,NULL,0); 346 347 idSkipZeroes(inIShortcut); 348 poly p = checkForMonomialViaSuddenSaturation(inIShortcut,rShortcut); 349 poly monomial = NULL; 350 if (p!=NULL) 351 { 352 monomial=p_One(r); 353 for (int i=1; i<n; i++) 354 p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r); 355 p_Delete(&p,rShortcut); 356 } 357 id_Delete(&inI,r); 358 id_Delete(&inIShortcut,rShortcut); 359 rDelete(rShortcut); 360 return monomial; 361 } 362 } 363 std::pair<ideal,ring> flip(const ideal I, const ring r, 364 const gfan::ZVector interiorPoint, 365 const gfan::ZVector facetNormal) const 366 { 367 gfan::ZVector adjustedInteriorPoint = adjustWeightForHomogeneity(interiorPoint); 368 gfan::ZVector adjustedFacetNormal = adjustWeightUnderHomogeneity(facetNormal,adjustedInteriorPoint); 369 return flip0(I,r,interiorPoint,facetNormal,adjustedInteriorPoint,adjustedFacetNormal); 349 } 350 351 return true; 370 352 } 371 353 }; -
Singular/dyn_modules/gfanlib/witness.cc
reacb781 r9c0326 14 14 * Returns an error if this is not possible. 15 15 **/ 16 staticmatrix divisionDiscardingRemainder(const poly f, const ideal G, const ring r)16 matrix divisionDiscardingRemainder(const poly f, const ideal G, const ring r) 17 17 { 18 18 ring origin = currRing; … … 20 20 ideal F = idInit(1); F->m[0]=f; 21 21 ideal m = idLift(G,F); 22 // ideal m = idLift(G,F,NULL,FALSE,TRUE);23 22 F->m[0]=NULL; id_Delete(&F, currRing); 23 matrix Q = id_Module2formatedMatrix(m,IDELEMS(G),1,currRing); 24 if (origin != r) rChangeCurrRing(origin); 25 return Q; 26 } 27 28 /** 29 * Given F[0],...,F[l] and G[0],...,G[k], 30 * computes Q[i,j] for i=0,..,k and j=0,...,l such that 31 * F[j] = Q[0,j]*G[0]+...+Q[k,j]*G[k]. 32 */ 33 matrix divisionDiscardingRemainder(const ideal F, const ideal G, const ring r) 34 { 35 ring origin = currRing; 36 if (origin != r) rChangeCurrRing(r); 37 ideal m = idLift(G,F); 24 38 matrix Q = id_Module2formatedMatrix(m,IDELEMS(G),1,currRing); 25 39 if (origin != r) rChangeCurrRing(origin); … … 89 103 } 90 104 #endif 105 106 /*** 107 * Let w be the uppermost weight vector in the matrix defining the ordering on r. 108 * Let I be a Groebner basis of an ideal in r, inI its initial form with respect w. 109 * Given an w-homogeneous element m of inI, computes a witness g of m in I, 110 * i.e. g in I such that in_w(g)=m. 111 **/ 112 ideal witness(const ideal inI, const ideal J, const ring r) 113 { 114 ring origin = currRing; 115 if (origin!=r) 116 rChangeCurrRing(r); 117 ideal NFinI = kNF(J,r->qideal,inI); 118 if (origin!=r) 119 rChangeCurrRing(origin); 120 121 int k = idSize(inI); 122 ideal I = idInit(k); 123 for (int i=0; i<k; i++) 124 { 125 I->m[i] = p_Add_q(p_Copy(inI->m[i],r),p_Neg(NFinI->m[i],r),r); 126 NFinI->m[i] = NULL; 127 } 128 129 return I; 130 } -
Singular/dyn_modules/gfanlib/witness.h
reacb781 r9c0326 5 5 #include <libpolys/polys/simpleideals.h> 6 6 7 matrix divisionDiscardingRemainder(const poly f, const ideal G, const ring r); 8 matrix divisionDiscardingRemainder(const ideal F, const ideal G, const ring r); 7 9 poly witness(const poly m, const ideal I, const ideal inI, const ring r); 10 ideal witness(const ideal inI, const ideal J, const ring r); 8 11 9 12 #ifndef NDEBUG -
gfanlib/gfanlib_matrix.h
reacb781 r9c0326 39 39 { 40 40 Matrix ret(1,v.size()); 41 for( inti=0;i<v.size();i++)ret[0][i]=v[i];41 for(unsigned i=0;i<v.size();i++)ret[0][i]=v[i]; 42 42 return ret; 43 43 } … … 331 331 int retSwaps=0; 332 332 int currentRow=0; 333 334 if (height<2)335 return 0;336 333 337 334 for(int i=0;i<width;i++) -
gfanlib/gfanlib_vector.h
reacb781 r9c0326 85 85 unsigned int size()const{return v.size();}; 86 86 void resize(int n){v.resize(n,typ());}; 87 void grow(int i){if( size()<i)resize(i);}87 void grow(int i){if((int)size()<i)resize(i);} 88 88 void push_back(typ a) 89 89 {
Note: See TracChangeset
for help on using the changeset viewer.