Changeset ca326f in git
- Timestamp:
- Jan 10, 2014, 2:27:58 PM (10 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- ebb19d318b56f966c9f0bc2e03181ad64ed395f1
- Parents:
- 5222d2aaa879330d2c8daa004f176ee41aed4b78
- git-author:
- Yue Ren <ren@mathematik.uni-kl.de>2014-01-10 14:27:58+01:00
- git-committer:
- Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:03+01:00
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/gfanlib/Makefile.am
r5222d2a rca326f 1 1 ACLOCAL_AMFLAGS = -I ../../m4 2 2 3 SOURCES = bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h gfanlib.cc3 SOURCES = bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h ppinitialReduction.cc ppinitialReduction.h ttinitialReduction.cc ttinitialReduction.h containsMonomial.cc containsMonomial.h tropical.cc tropical.h gfanlib.cc 4 4 5 5 MY_CPPFLAGS = -I${top_srcdir} -I${top_builddir} \ -
Singular/dyn_modules/gfanlib/tropical.cc
r5222d2a rca326f 1 #include <kernel/polys.h> 2 #include <kernel/kstd1.h> 3 #include <libpolys/coeffs/longrat.h> 4 #include <libpolys/polys/clapsing.h> 1 #include <libpolys/polys/monomials/p_polys.h> 2 #include <libpolys/coeffs/coeffs.h> 3 5 4 #include <bbcone.h> 6 7 5 #include <ppinitialReduction.h> 8 6 #include <ttinitialReduction.h> 7 #include <containsMonomial.h> 9 8 10 9 poly initial(poly p) … … 204 203 } 205 204 206 /*** 207 * If 1, replaces all occuring t with prime p, 208 * where theoretically feasable. 209 * Also computes GCD over integers than 210 * over univariate polynomials 211 **/ 212 #define T_TO_P 0 213 214 /*** 215 * Suppose I=g_0,...,g_{n-1}. 216 * This function uses bubble sort to sorts g_1,...,g_{n-1} 217 * such that lm(g_1)>...>lm(g_{n-1}) 218 **/ 219 static inline void sortingLaterGenerators(ideal I) 220 { 221 poly cache; int i; int n=IDELEMS(I); int newn; 222 do 223 { 224 newn=0; 225 for (i=2; i<n; i++) 226 { 227 if (pLmCmp(I->m[i-1],I->m[i])<0) 228 { 229 cache=I->m[i-1]; 230 I->m[i-1]=I->m[i]; 231 I->m[i]=cache; 232 newn = i; 233 } 234 } 235 n=newn; 236 } while(n); 237 } 238 239 240 #if 0 241 /*** 242 * Given a general ring r with any ordering, 243 * changes the ordering to a(v),ws(-w) 244 **/ 245 bool changetoAWSRing(ring r, gfan::ZVector v, gfan::ZVector w) 246 { 247 omFree(r->order); 248 r->order = (int*) omAlloc0(4*sizeof(int)); 249 omFree(r->block0); 250 r->block0 = (int*) omAlloc0(4*sizeof(int)); 251 omFree(r->block1); 252 r->block1 = (int*) omAlloc0(4*sizeof(int)); 253 for (int i=0; r->wvhdl[i]; i++) 254 { omFree(r->wvhdl[i]); } 255 omFree(r->wvhdl); 256 r->wvhdl = (int**) omAlloc0(4*sizeof(int*)); 257 258 bool ok = false; 259 r->order[0] = ringorder_a; 260 r->block0[0] = 1; 261 r->block1[0] = r->N; 262 r->wvhdl[0] = ZVectorToIntStar(v,ok); 263 r->order[1] = ringorder_ws; 264 r->block0[1] = 1; 265 r->block1[1] = r->N; 266 r->wvhdl[1] = ZVectorToIntStar(w,ok); 267 r->order[2]=ringorder_C; 268 return ok; 269 } 270 271 272 /*** 273 * Given a ring with ordering a(v'),ws(w'), 274 * changes the weights to v,w 275 **/ 276 bool changeAWSWeights(ring r, gfan::ZVector v, gfan::ZVector w) 277 { 278 omFree(r->wvhdl[0]); 279 omFree(r->wvhdl[1]); 280 bool ok = false; 281 r->wvhdl[0] = ZVectorToIntStar(v,ok); 282 r->wvhdl[1] = ZVectorToIntStar(w,ok); 283 return ok; 284 } 285 286 287 // /*** 288 // * Creates an int* representing the transposition of the last two variables 289 // **/ 290 // static inline int* createPermutationVectorForSaturation(static const ring &r) 205 206 // gfan::ZCone* startingCone(ideal I) 291 207 // { 292 // int* w = (int*) omAlloc0((rVar(r)+1)*sizeof(int)); 293 // for (int i=1; i<=rVar(r)-2; i++) 294 // w[i] = i; 295 // w[rVar(r)-1] = rVar(r); 296 // w[rVar(r)] = rVar(r)-1; 208 // I = kStd(I,NULL,isNotHomog,NULL); 209 // gfan::ZCone* zc = maximalGroebnerCone(currRing,I); 210 // gfan::ZMatrix rays = zc->extremeRays(); 211 // gfan::ZVector v; 212 // for (int i=0; i<rays.getHeight(); i++) 213 // { 214 // v = rays[i]; 215 // } 216 // return zc; 297 217 // } 298 299 300 /***301 * Creates an int* representing the permutation302 * 1 -> 1, ..., i-1 -> i-1, i -> n, i+1 -> n-1, ... , n -> i303 **/304 static inline int* createPermutationVectorForSaturation(const ring &r, const int i)305 {306 int* sigma = (int*) omAlloc0((rVar(r)+1)*sizeof(int));307 int j;308 for (j=1; j<i; j++)309 sigma[j] = j;310 for (; j<=rVar(r); j++)311 sigma[j] = rVar(r)-j+i;312 return(sigma);313 }314 315 316 /***317 * Changes the int* representing the permutation318 * 1 -> 1, ..., i -> i, i+1 -> n, i+2 -> n-1, ... , n -> i+1319 * to an int* representing the permutation320 * 1 -> 1, ..., i-1 -> i-1, i -> n, i+1 -> n-1, ... , n -> i321 **/322 static void changePermutationVectorForSaturation(int* sigma, const ring &r, const int i)323 {324 for (int j=i; j<rVar(r); j++)325 sigma[j] = rVar(r)-j+i;326 sigma[rVar(r)] = i;327 }328 329 330 /***331 * returns a ring in which the weights of the ring variables are permuted332 * if handed over a poly in which the variables are permuted, this is basically333 * as good as permuting the variables of the ring itself.334 **/335 static ring permuteWeighstOfRingVariables(const ring &r, const int* const sigma)336 {337 ring s = rCopy0(r);338 for (int j=0; j<rVar(r); j++)339 {340 s->wvhdl[0][j] = r->wvhdl[0][sigma[j+1]];341 s->wvhdl[1][j] = r->wvhdl[1][sigma[j+1]];342 }343 rComplete(s,1);344 return s;345 }346 347 348 /***349 * creates a ring s that is a copy of r except with ordering wp(w)350 **/351 static inline ring createInitialRingForSaturation(const ring &r, const gfan::ZVector &w, bool &ok)352 {353 assume(rVar(r) == (int) w.size());354 355 ring s = rCopy0(r); int i;356 for (i=0; s->order[i]; i++)357 omFreeSize(s->wvhdl[i],rVar(r)*sizeof(int));358 i++;359 omFreeSize(s->order,i*sizeof(int));360 s->order = (int*) omAlloc0(3*sizeof(int));361 omFreeSize(s->block0,i*sizeof(int));362 s->block0 = (int*) omAlloc0(3*sizeof(int));363 omFreeSize(s->block1,i*sizeof(int));364 s->block1 = (int*) omAlloc0(3*sizeof(int));365 omFreeSize(s->wvhdl,i*sizeof(int*));366 s->wvhdl = (int**) omAlloc0(3*sizeof(int*));367 368 s->order[0] = ringorder_wp;369 s->block0[0] = 1;370 s->block1[0] = rVar(r);371 s->wvhdl[0] = ZVectorToIntStar(w,ok);372 s->order[1]=ringorder_C;373 374 rComplete(s,1);375 return s;376 }377 378 379 /***380 * Given an weighted homogeneous ideal I with respect to weight w381 * that in standard basis form with respect to the ordering ws(-w),382 * derives the standard basis of I:<x_n>^\infty383 * and returns a long k such that I:<x_n>^\infty=I:<x_n>^k384 **/385 static long deriveStandardBasisOfSaturation(ideal &I, ring &r)386 {387 long k=0, l; poly current;388 for (int i=0; i<IDELEMS(I); i++)389 {390 current = I->m[i];391 l = p_GetExp(current,rVar(r),r);392 if (k<l) k=l;393 while (current)394 {395 p_SubExp(current,rVar(r),l,r); p_Setm(current,r);396 pIter(current);397 }398 }399 return k;400 }401 402 403 /***404 * Given a weighted homogeneous ideal I with respect to weight w405 * with constant first element,406 * returns NULL if I does not contain a monomial407 * otherwise returns the monomial contained in I408 **/409 poly containsMonomial(const ideal &I, const gfan::ZVector &w)410 {411 assume(rField_is_Ring_Z(currRing));412 413 // first we switch to the ground field currRing->cf / I->m[0]414 ring r = rCopy0(currRing);415 nKillChar(r->cf);416 r->cf = nInitChar(n_Zp,(void*)(long)n_Int(p_GetCoeff(I->m[0],currRing),currRing->cf));417 rComplete(r);418 419 ideal J = id_Copy(I, currRing); poly cache; number temp;420 for (int i=0; i<IDELEMS(I); i++)421 {422 cache = J->m[i];423 while (cache)424 {425 // TODO: temp = npMapGMP(p_GetCoeff(cache,currRing),currRing->cf,r->cf);426 p_SetCoeff(cache,temp,r); pIter(cache);427 }428 }429 430 431 J = kStd(J,NULL,isHomog,NULL);432 433 bool b = false;434 ring s = createInitialRingForSaturation(currRing, w, b);435 if (b)436 {437 WerrorS("containsMonomial: overflow in weight vector");438 return NULL;439 }440 441 return NULL;442 }443 444 445 gfan::ZCone* startingCone(ideal I)446 {447 I = kStd(I,NULL,isNotHomog,NULL);448 gfan::ZCone* zc = maximalGroebnerCone(currRing,I);449 gfan::ZMatrix rays = zc->extremeRays();450 gfan::ZVector v;451 for (int i=0; i<rays.getHeight(); i++)452 {453 v = rays[i];454 }455 return zc;456 }457 #endif458 218 459 219 … … 464 224 p->iiAddCproc("","initial",FALSE,initial); 465 225 #ifndef NDEBUG 466 p->iiAddCproc("","pReduce",FALSE,pReduce); 467 p->iiAddCproc("","reduceInitially0",FALSE,reduceInitially0); 468 p->iiAddCproc("","reduceInitially1",FALSE,reduceInitially1); 469 p->iiAddCproc("","reduceInitially2",FALSE,reduceInitially2); 470 p->iiAddCproc("","reduceInitially3",FALSE,reduceInitially3); 471 p->iiAddCproc("","reduceInitially4",FALSE,reduceInitially4); 472 p->iiAddCproc("","ttpReduce",FALSE,pReduce); 226 p->iiAddCproc("","pppReduce",FALSE,pppReduce); 227 p->iiAddCproc("","ppreduceInitially0",FALSE,ppreduceInitially0); 228 p->iiAddCproc("","ppreduceInitially1",FALSE,ppreduceInitially1); 229 p->iiAddCproc("","ppreduceInitially2",FALSE,ppreduceInitially2); 230 p->iiAddCproc("","ppreduceInitially3",FALSE,ppreduceInitially3); 231 p->iiAddCproc("","ppreduceInitially4",FALSE,ppreduceInitially4); 232 p->iiAddCproc("","ttpReduce",FALSE,ttpReduce); 233 p->iiAddCproc("","ttreduceInitially0",FALSE,ttreduceInitially0); 234 p->iiAddCproc("","ttreduceInitially1",FALSE,ttreduceInitially1); 235 p->iiAddCproc("","ttreduceInitially2",FALSE,ttreduceInitially2); 236 p->iiAddCproc("","ttreduceInitially3",FALSE,ttreduceInitially3); 237 p->iiAddCproc("","ttreduceInitially4",FALSE,ttreduceInitially4); 473 238 #endif //NDEBUG 474 p->iiAddCproc("","reduceInitially",FALSE,reduceInitially); 239 p->iiAddCproc("","ppreduceInitially",FALSE,ppreduceInitially); 240 p->iiAddCproc("","ttreduceInitially",FALSE,ttreduceInitially); 475 241 p->iiAddCproc("","homogeneitySpace",FALSE,homogeneitySpace); 476 } 242 p->iiAddCproc("","containsMonomial",FALSE,containsMonomial); 243 } -
dyn_modules/callgfanlib/ppinitialReduction.cc
r5222d2a rca326f 72 72 73 73 #ifndef NDEBUG 74 BOOLEAN p Reduce(leftv res, leftv args)74 BOOLEAN pppReduce(leftv res, leftv args) 75 75 { 76 76 leftv u = args; … … 103 103 * assumes that h and g are in pReduced form and homogeneous in x of the same degree 104 104 **/ 105 bool reduceInitially(poly &h, const poly g)105 bool ppreduceInitially(poly &h, const poly g) 106 106 { 107 107 pTest(h); pTest(g); poly hCache; … … 129 129 130 130 #ifndef NDEBUG 131 BOOLEAN reduceInitially0(leftv res, leftv args)131 BOOLEAN ppreduceInitially0(leftv res, leftv args) 132 132 { 133 133 leftv u = args; … … 142 142 h = (poly) u->CopyD(); 143 143 g = (poly) v->CopyD(); 144 (void) reduceInitially(h,g);144 (void)ppreduceInitially(h,g); 145 145 p_Delete(&h,currRing); 146 146 p_Delete(&g,currRing); … … 149 149 h = (poly) u->CopyD(); 150 150 g = (poly) v->CopyD(); 151 (void) reduceInitially(h,g);151 (void)ppreduceInitially(h,g); 152 152 p_Delete(&g,currRing); 153 153 res->rtyp = POLY_CMD; … … 166 166 * assumes that I is generated by elements which are homogeneous in x of the same degree. 167 167 **/ 168 bool reduceInitially(ideal I, const number p)168 bool ppreduceInitially(ideal I, const number p) 169 169 { 170 170 int m=idSize(I),n=m; poly cache; … … 192 192 for (int i=0; i<m-1; i++) 193 193 for (int j=i+1; j<m; j++) 194 if ( reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;194 if (ppreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true; 195 195 196 196 /*** … … 199 199 for (int i=0; i<m-1; i++) 200 200 for (int j=i+1; j<m; j++) 201 if ( reduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true;201 if (ppreduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true; 202 202 return false; 203 203 } … … 205 205 206 206 #ifndef NDEBUG 207 BOOLEAN reduceInitially1(leftv res, leftv args)207 BOOLEAN ppreduceInitially1(leftv res, leftv args) 208 208 { 209 209 leftv u = args; … … 218 218 I = (ideal) u->CopyD(); 219 219 p = (number) v->CopyD(); 220 (void) reduceInitially(I,p);220 (void) ppreduceInitially(I,p); 221 221 id_Delete(&I,currRing); 222 222 n_Delete(&p,currRing->cf); … … 225 225 I = (ideal) u->CopyD(); 226 226 p = (number) v->CopyD(); 227 (void) reduceInitially(I,p);227 (void) ppreduceInitially(I,p); 228 228 n_Delete(&p,currRing->cf); 229 229 res->rtyp = IDEAL_CMD; … … 241 241 * assumes that I was already sorted and initially reduced in the first place 242 242 **/ 243 bool reduceInitially(ideal I, const number p, const poly g)243 bool ppreduceInitially(ideal I, const number p, const poly g) 244 244 { 245 245 int n=idSize(I); … … 263 263 **/ 264 264 for (int i=0; i<j; i++) 265 if ( reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;265 if (ppreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true; 266 266 for (int k=j+1; k<n; k++) 267 if ( reduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true;267 if (ppreduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true; 268 268 269 269 /*** … … 273 273 for (int i=0; i<j; i++) 274 274 for (int k=j; k<n; k++) 275 if ( reduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true;275 if (ppreduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true; 276 276 for (int k=j+1; k<n; k++) 277 if ( reduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true;277 if (ppreduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true; 278 278 279 279 return false; … … 282 282 283 283 #ifndef NDEBUG 284 BOOLEAN reduceInitially2(leftv res, leftv args)284 BOOLEAN ppreduceInitially2(leftv res, leftv args) 285 285 { 286 286 leftv u = args; … … 299 299 p = (number) v->CopyD(); 300 300 g = (poly) w->CopyD(); 301 (void) reduceInitially(I,p,g);301 (void) ppreduceInitially(I,p,g); 302 302 id_Delete(&I,currRing); 303 303 n_Delete(&p,currRing->cf); … … 307 307 p = (number) v->CopyD(); 308 308 g = (poly) w->CopyD(); 309 (void) reduceInitially(I,p,g);309 (void) ppreduceInitially(I,p,g); 310 310 n_Delete(&p,currRing->cf); 311 311 res->rtyp = IDEAL_CMD; … … 326 326 * assumes that the generators of G are homogeneous in x of lesser degree. 327 327 **/ 328 bool reduceInitially(ideal H, const number p, const ideal G)328 bool ppreduceInitially(ideal H, const number p, const ideal G) 329 329 { 330 330 /*** 331 331 * Step 1: reduce H initially with respect to itself and with respect to p-t 332 332 **/ 333 if ( reduceInitially(H,p)) return true;333 if (ppreduceInitially(H,p)) return true; 334 334 335 335 /*** … … 376 376 p_SetCoeff(g,n_Init(1,currRing->cf),currRing); p_Setm(g,currRing); 377 377 g = p_Mult_q(g,p_Copy(G->m[i],currRing),currRing); 378 reduceInitially(I,p,g);378 ppreduceInitially(I,p,g); 379 379 } 380 380 else … … 431 431 432 432 #ifndef NDEBUG 433 BOOLEAN reduceInitially3(leftv res, leftv args)433 BOOLEAN ppreduceInitially3(leftv res, leftv args) 434 434 { 435 435 leftv u = args; … … 448 448 p = (number) v->CopyD(); 449 449 G = (ideal) w->CopyD(); 450 (void) reduceInitially(H,p,G);450 (void) ppreduceInitially(H,p,G); 451 451 id_Delete(&H,currRing); 452 452 id_Delete(&G,currRing); … … 457 457 p = (number) v->CopyD(); 458 458 G = (ideal) w->CopyD(); 459 (void) reduceInitially(H,p,G);459 (void) ppreduceInitially(H,p,G); 460 460 n_Delete(&p,currRing->cf); 461 461 id_Delete(&G,currRing); … … 475 475 * assumes that the generators of I are homogeneous in x and that p-t is in I. 476 476 **/ 477 bool reduceInitially(ideal I)477 bool ppreduceInitially(ideal I) 478 478 { 479 479 /*** … … 512 512 **/ 513 513 it++; Hi = it->second; n--; 514 if ( reduceInitially(Hi,p)) return true;514 if (ppreduceInitially(Hi,p)) return true; 515 515 516 516 ideal G = idInit(n); int m=0; … … 550 550 } 551 551 m += l; IDELEMS(GG) = m; GG->m = &G->m[n-m]; 552 if ( reduceInitially(it->second,p,GG)) return true;552 if (ppreduceInitially(it->second,p,GG)) return true; 553 553 idShallowDelete(&Hi); Hi = it->second; 554 554 } … … 561 561 562 562 #ifndef NDEBUG 563 BOOLEAN reduceInitially4(leftv res, leftv args)563 BOOLEAN ppreduceInitially4(leftv res, leftv args) 564 564 { 565 565 leftv u = args; … … 570 570 Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); 571 571 I = (ideal) u->CopyD(); 572 (void) reduceInitially(I);572 (void) ppreduceInitially(I); 573 573 id_Delete(&I,currRing); 574 574 omUpdateInfo(); 575 575 Print("usedBytesAfter=%ld\n",om_Info.UsedBytes); 576 576 I = (ideal) u->CopyD(); 577 (void) reduceInitially(I);577 (void) ppreduceInitially(I); 578 578 res->rtyp = IDEAL_CMD; 579 579 res->data = (char*) I; … … 585 585 586 586 587 BOOLEAN reduceInitially(leftv res, leftv args)587 BOOLEAN ppreduceInitially(leftv res, leftv args) 588 588 { 589 589 leftv u = args; … … 591 591 { 592 592 ideal I = (ideal) u->CopyD(); 593 (void) reduceInitially(I);593 (void) ppreduceInitially(I); 594 594 res->rtyp = IDEAL_CMD; 595 595 res->data = (char*) I; -
dyn_modules/callgfanlib/ppinitialReduction.h
r5222d2a rca326f 1 #ifndef INITIALREDUCTION_H2 #define INITIALREDUCTION_H1 #ifndef PPINITIALREDUCTION_H 2 #define PPINITIALREDUCTION_H 3 3 4 4 #include <kernel/structs.h> 5 5 6 #ifndef N _DEBUG7 BOOLEAN p Reduce(leftv res, leftv args);8 BOOLEAN reduceInitially0(leftv res, leftv args);9 BOOLEAN reduceInitially1(leftv res, leftv args);10 BOOLEAN reduceInitially2(leftv res, leftv args);11 BOOLEAN reduceInitially3(leftv res, leftv args);12 BOOLEAN reduceInitially4(leftv res, leftv args);6 #ifndef NDEBUG 7 BOOLEAN pppReduce(leftv res, leftv args); 8 BOOLEAN ppreduceInitially0(leftv res, leftv args); 9 BOOLEAN ppreduceInitially1(leftv res, leftv args); 10 BOOLEAN ppreduceInitially2(leftv res, leftv args); 11 BOOLEAN ppreduceInitially3(leftv res, leftv args); 12 BOOLEAN ppreduceInitially4(leftv res, leftv args); 13 13 #endif 14 14 15 BOOLEAN reduceInitially(leftv res, leftv args);15 BOOLEAN ppreduceInitially(leftv res, leftv args); 16 16 17 17 #endif -
dyn_modules/callgfanlib/ttinitialReduction.cc
r5222d2a rca326f 1 #include <kernel/polys.h>2 1 #include <Singular/ipid.h> 3 2 4 3 #include <libpolys/polys/monomials/p_polys.h> 4 #include <libpolys/polys/clapsing.h> 5 5 #include <singularWishlist.h> 6 6 … … 8 8 #include <set> 9 9 10 #define KEEP_COEFF_SMALL 110 #define KEEP_COEFF_SMALL 0 11 11 12 12 /*** 13 * changes a polynomial g with the help p-t such that 14 * 1) each term of g has a distinct monomial in x 15 * 2) no term of g has a coefficient divisible by p 16 * in particular, this means that all g_\alpha can be obtained 17 * by reading the coefficients and that g is initially reduced 18 * with respect to p-t 13 * if KEEP_COEFF_SMALL is set, alters all coefficients of a polynomial g 14 * to be in range between 0 and p-1 with the help of p-t. 15 * In particular the result will be reduced with respect to p-t. 16 * if KEEP_COEFF_SMALL is not set, reduces g initially with respect to p-t. 19 17 **/ 20 18 static bool pReduce(poly g, const number p) … … 24 22 poly gCache; 25 23 26 number coeff , pPower; int power; poly subst;24 number coeff; int power; poly subst; 27 25 while(toBeChecked) 28 26 { 27 #if KEEP_COEFF_SMALL 28 if (n_Greater(p_GetCoeff(toBeChecked,currRing),p,currRing->cf) || 29 n_Equal(p_GetCoeff(toBeChecked,currRing),p,currRing->cf)) 30 { 31 coeff = n_IntDiv(p_GetCoeff(toBeChecked,currRing),p,currRing->cf); 32 p_SetCoeff(toBeChecked, 33 n_IntMod(p_GetCoeff(toBeChecked,currRing),p,currRing->cf), 34 currRing); 35 subst = p_LmInit(toBeChecked,currRing); 36 p_AddExp(subst,1,1,currRing); 37 p_SetCoeff(subst,coeff,currRing); 38 p_Setm(subst,currRing); pTest(subst); 39 pNext(toBeChecked)=p_Add_q(pNext(toBeChecked),subst,currRing); 40 pTest(toBeChecked); 41 } 42 else 43 { 44 number negcoeff = n_Neg(p_GetCoeff(toBeChecked,currRing),currRing->cf); 45 if (n_GreaterZero(negcoeff,currRing->cf)) 46 { 47 number coeffdiv = n_IntDiv(p_GetCoeff(toBeChecked,currRing),p,currRing->cf); 48 number coeffmod = n_IntMod(p_GetCoeff(toBeChecked,currRing),p,currRing->cf); 49 if (n_IsZero(coeffmod,currRing->cf)) 50 { 51 poly subst = p_LmInit(toBeChecked,currRing); 52 } 53 } 54 n_Delete(negcoeff,currRing->cf); 55 } 56 #else 29 57 for (gCache = g; gCache; pIter(gCache)) 30 58 if (p_LeadmonomDivisibleBy(gCache,toBeChecked,currRing)) break; … … 55 83 else 56 84 { 57 #ifdef KEEP_COEFF_SMALL58 if (n_Greater(p_GetCoeff(toBeChecked,currRing),p,currRing->cf))59 {60 coeff = n_IntDiv(p_GetCoeff(toBeChecked,currRing),p,currRing->cf);61 p_SetCoeff(toBeChecked,62 n_IntMod(p_GetCoeff(toBeChecked,currRing),p,currRing->cf),63 currRing);64 subst = p_LmInit(toBeChecked,currRing);65 p_AddExp(subst,1,1,currRing);66 p_SetCoeff(subst,coeff,currRing);67 p_Setm(subst,currRing); pTest(subst);68 pNext(toBeChecked)=p_Add_q(pNext(toBeChecked),subst,currRing);69 pTest(toBeChecked);70 }71 #endif72 85 pNext(gEnd)=toBeChecked; 73 86 pIter(gEnd); pIter(toBeChecked); … … 75 88 } 76 89 } 77 } 90 else 91 { 92 pNext(gEnd)=toBeChecked; 93 pIter(gEnd); pIter(toBeChecked); 94 pNext(gEnd)=NULL; 95 } 96 } 97 #endif 78 98 return false; 79 99 } … … 106 126 107 127 108 #if 0109 128 /*** 110 129 * reduces h initially with respect to g, … … 113 132 * assumes that h and g are in pReduced form and homogeneous in x of the same degree 114 133 **/ 115 bool reduceInitially(poly &h, const poly g)134 bool ttreduceInitially(poly &h, const poly g) 116 135 { 117 136 pTest(h); pTest(g); poly hCache; … … 139 158 140 159 #ifndef NDEBUG 141 BOOLEAN reduceInitially0(leftv res, leftv args)160 BOOLEAN ttreduceInitially0(leftv res, leftv args) 142 161 { 143 162 leftv u = args; … … 152 171 h = (poly) u->CopyD(); 153 172 g = (poly) v->CopyD(); 154 (void) reduceInitially(h,g);173 (void)ttreduceInitially(h,g); 155 174 p_Delete(&h,currRing); 156 175 p_Delete(&g,currRing); … … 159 178 h = (poly) u->CopyD(); 160 179 g = (poly) v->CopyD(); 161 (void) reduceInitially(h,g);180 (void)ttreduceInitially(h,g); 162 181 p_Delete(&g,currRing); 163 182 res->rtyp = POLY_CMD; … … 176 195 * assumes that I is generated by elements which are homogeneous in x of the same degree. 177 196 **/ 178 bool reduceInitially(ideal I, const number p)197 bool ttreduceInitially(ideal I, const number p) 179 198 { 180 199 int m=idSize(I),n=m; poly cache; … … 202 221 for (int i=0; i<m-1; i++) 203 222 for (int j=i+1; j<m; j++) 204 if ( reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;223 if (ttreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true; 205 224 206 225 /*** … … 209 228 for (int i=0; i<m-1; i++) 210 229 for (int j=i+1; j<m; j++) 211 if ( reduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true;230 if (ttreduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true; 212 231 return false; 213 232 } … … 215 234 216 235 #ifndef NDEBUG 217 BOOLEAN reduceInitially1(leftv res, leftv args)236 BOOLEAN ttreduceInitially1(leftv res, leftv args) 218 237 { 219 238 leftv u = args; … … 228 247 I = (ideal) u->CopyD(); 229 248 p = (number) v->CopyD(); 230 (void) reduceInitially(I,p);249 (void) ttreduceInitially(I,p); 231 250 id_Delete(&I,currRing); 232 251 n_Delete(&p,currRing->cf); … … 235 254 I = (ideal) u->CopyD(); 236 255 p = (number) v->CopyD(); 237 (void) reduceInitially(I,p);256 (void) ttreduceInitially(I,p); 238 257 n_Delete(&p,currRing->cf); 239 258 res->rtyp = IDEAL_CMD; … … 251 270 * assumes that I was already sorted and initially reduced in the first place 252 271 **/ 253 bool reduceInitially(ideal I, const number p, const poly g)272 bool ttreduceInitially(ideal I, const number p, const poly g) 254 273 { 255 274 int n=idSize(I); … … 273 292 **/ 274 293 for (int i=0; i<j; i++) 275 if ( reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;294 if (ttreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true; 276 295 for (int k=j+1; k<n; k++) 277 if ( reduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true;296 if (ttreduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true; 278 297 279 298 /*** … … 283 302 for (int i=0; i<j; i++) 284 303 for (int k=j; k<n; k++) 285 if ( reduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true;304 if (ttreduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true; 286 305 for (int k=j+1; k<n; k++) 287 if ( reduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true;306 if (ttreduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true; 288 307 289 308 return false; … … 292 311 293 312 #ifndef NDEBUG 294 BOOLEAN reduceInitially2(leftv res, leftv args)313 BOOLEAN ttreduceInitially2(leftv res, leftv args) 295 314 { 296 315 leftv u = args; … … 309 328 p = (number) v->CopyD(); 310 329 g = (poly) w->CopyD(); 311 (void) reduceInitially(I,p,g);330 (void) ttreduceInitially(I,p,g); 312 331 id_Delete(&I,currRing); 313 332 n_Delete(&p,currRing->cf); … … 317 336 p = (number) v->CopyD(); 318 337 g = (poly) w->CopyD(); 319 (void) reduceInitially(I,p,g);338 (void) ttreduceInitially(I,p,g); 320 339 n_Delete(&p,currRing->cf); 321 340 res->rtyp = IDEAL_CMD; … … 336 355 * assumes that the generators of G are homogeneous in x of lesser degree. 337 356 **/ 338 bool reduceInitially(ideal H, const number p, const ideal G)357 bool ttreduceInitially(ideal H, const number p, const ideal G) 339 358 { 340 359 /*** 341 360 * Step 1: reduce H initially with respect to itself and with respect to p-t 342 361 **/ 343 if ( reduceInitially(H,p)) return true;362 if (ttreduceInitially(H,p)) return true; 344 363 345 364 /*** … … 386 405 p_SetCoeff(g,n_Init(1,currRing->cf),currRing); p_Setm(g,currRing); 387 406 g = p_Mult_q(g,p_Copy(G->m[i],currRing),currRing); 388 reduceInitially(I,p,g);407 ttreduceInitially(I,p,g); 389 408 } 390 409 else … … 441 460 442 461 #ifndef NDEBUG 443 BOOLEAN reduceInitially3(leftv res, leftv args)462 BOOLEAN ttreduceInitially3(leftv res, leftv args) 444 463 { 445 464 leftv u = args; … … 458 477 p = (number) v->CopyD(); 459 478 G = (ideal) w->CopyD(); 460 (void) reduceInitially(H,p,G);479 (void) ttreduceInitially(H,p,G); 461 480 id_Delete(&H,currRing); 462 481 id_Delete(&G,currRing); … … 467 486 p = (number) v->CopyD(); 468 487 G = (ideal) w->CopyD(); 469 (void) reduceInitially(H,p,G);488 (void) ttreduceInitially(H,p,G); 470 489 n_Delete(&p,currRing->cf); 471 490 id_Delete(&G,currRing); … … 485 504 * assumes that the generators of I are homogeneous in x and that p-t is in I. 486 505 **/ 487 bool reduceInitially(ideal I)506 bool ttreduceInitially(ideal I) 488 507 { 489 508 /*** … … 522 541 **/ 523 542 it++; Hi = it->second; n--; 524 if ( reduceInitially(Hi,p)) return true;543 if (ttreduceInitially(Hi,p)) return true; 525 544 526 545 ideal G = idInit(n); int m=0; … … 560 579 } 561 580 m += l; IDELEMS(GG) = m; GG->m = &G->m[n-m]; 562 if ( reduceInitially(it->second,p,GG)) return true;581 if (ttreduceInitially(it->second,p,GG)) return true; 563 582 idShallowDelete(&Hi); Hi = it->second; 564 583 } … … 571 590 572 591 #ifndef NDEBUG 573 BOOLEAN reduceInitially4(leftv res, leftv args)592 BOOLEAN ttreduceInitially4(leftv res, leftv args) 574 593 { 575 594 leftv u = args; … … 580 599 Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); 581 600 I = (ideal) u->CopyD(); 582 (void) reduceInitially(I);601 (void) ttreduceInitially(I); 583 602 id_Delete(&I,currRing); 584 603 omUpdateInfo(); 585 604 Print("usedBytesAfter=%ld\n",om_Info.UsedBytes); 586 605 I = (ideal) u->CopyD(); 587 (void) reduceInitially(I);606 (void) ttreduceInitially(I); 588 607 res->rtyp = IDEAL_CMD; 589 608 res->data = (char*) I; … … 595 614 596 615 597 BOOLEAN reduceInitially(leftv res, leftv args)616 BOOLEAN ttreduceInitially(leftv res, leftv args) 598 617 { 599 618 leftv u = args; … … 601 620 { 602 621 ideal I = (ideal) u->CopyD(); 603 (void) reduceInitially(I);622 (void) ttreduceInitially(I); 604 623 res->rtyp = IDEAL_CMD; 605 624 res->data = (char*) I; … … 608 627 return TRUE; 609 628 } 610 611 #endif -
dyn_modules/callgfanlib/ttinitialReduction.h
r5222d2a rca326f 1 #ifndef INITIALREDUCTION_H2 #define INITIALREDUCTION_H1 #ifndef TTINITIALREDUCTION_H 2 #define TTINITIALREDUCTION_H 3 3 4 4 #include <kernel/structs.h> 5 5 6 #ifndef N _DEBUG6 #ifndef NDEBUG 7 7 BOOLEAN ttpReduce(leftv res, leftv args); 8 /* BOOLEAN reduceInitially0(leftv res, leftv args); */ 9 /* BOOLEAN reduceInitially1(leftv res, leftv args); */ 10 /* BOOLEAN reduceInitially2(leftv res, leftv args); */ 11 /* BOOLEAN reduceInitially3(leftv res, leftv args); */ 12 /* BOOLEAN reduceInitially4(leftv res, leftv args); */ 8 BOOLEAN ttreduceInitially0(leftv res, leftv args); 9 BOOLEAN ttreduceInitially1(leftv res, leftv args); 10 BOOLEAN ttreduceInitially2(leftv res, leftv args); 11 BOOLEAN ttreduceInitially3(leftv res, leftv args); 12 BOOLEAN ttreduceInitially4(leftv res, leftv args); 13 13 #endif 14 14 15 /* BOOLEAN reduceInitially(leftv res, leftv args); */ 15 BOOLEAN ttreduceInitially(leftv res, leftv args); 16 16 17 17 #endif
Note: See TracChangeset
for help on using the changeset viewer.