=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/gb.c,v retrieving revision 1.5 retrieving revision 1.13 diff -u -p -r1.5 -r1.13 --- OpenXM/src/kan96xx/Kan/gb.c 2001/05/04 01:06:23 1.5 +++ OpenXM/src/kan96xx/Kan/gb.c 2005/07/07 02:59:47 1.13 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/gb.c,v 1.4 2000/03/15 01:31:17 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/gb.c,v 1.12 2005/06/30 08:35:07 takayama Exp $ */ /* untabify on May 4, 2001 */ #include #include "datatype.h" @@ -8,6 +8,7 @@ #define INITGRADE 4 #define INITSIZE 2 +#define DMAX 100 int KanGBmessage = 1; @@ -22,8 +23,11 @@ extern int UseCriterion2B; extern int Spairs; extern int Criterion2B, Criterion2F, Criterion2M; extern int AutoReduce; +extern int TraceLift; +extern struct ring *TraceLift_ringmod; +static int MaxLength[DMAX]; +static int SpNumber[DMAX]; - struct gradedPairs *updatePairs(grD,gt,gtGrade,t,grG) struct gradedPairs *grD; /* set of pairs */ POLY gt; /* new polynomial */ @@ -158,13 +162,15 @@ struct gradedPairs *updatePairs(grD,gt,gtGrade,t,grG) return(grD); } -struct gradedPolySet *groebner_gen(f,needBack,needSyz,grP,countDown,forceReduction) +struct gradedPolySet *groebner_gen(f,needBack,needSyz,grP,countDown,forceReduction,reduceOnly,gbCheck) struct arrayOfPOLY *f; int needBack; int needSyz; struct pair **grP; /* if (needSyz), it is set. */ int countDown; int forceReduction; + int reduceOnly; + int gbCheck; { int r; struct gradedPolySet *g; @@ -189,8 +195,18 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, extern int StopDegree; extern struct ring *CurrentRingp; extern char *F_mpMult; + extern int Homogenize; struct ring *rp; + int first; + int statisticsPL, statisticsCount; + if (KanGBmessage) { + printf("Homogenize=%d, countDown=%d, forceReduction=%d, reduceOnly=%d, gbCheck=%d\n", + Homogenize,countDown, forceReduction, reduceOnly, gbCheck); + } + if (Statistics) { + for (i=0; in; if (r<=0) return((struct gradedPolySet *)NULL); if (UseCriterion1) { @@ -204,15 +220,22 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, Spairs = Criterion1 = Criterion2B = Criterion2F = Criterion2M = 0; - g = newGradedPolySet(INITGRADE); + g = newGradedPolySet(INITGRADE); g->gb = 1; + if (reduceOnly) g->gb = 2; /* unknown */ d = newGradedPairs(INITGRADE*2); for (i=0; ilim; i++) { g->polys[i] = newPolySet(INITSIZE); } + first = 1; for (i=0; im->ringp; } + if (TraceLift && (!(gt ISZERO)) && first) { + TraceLift_ringmod = newRingOverFp(rp,getPrime(TraceLift)); first = 0; + if (KanGBmessage) printf("Prime number for the trace lift is %d.\n", + TraceLift_ringmod->p); + } grade = -1; whereInG(g,gt,&grade,&indx,Sugar); if (KanGBmessage == 2) { printf("init=%s, ",POLYToString(head(gt),'*',1)); @@ -230,7 +253,8 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, g = putPolyInG(g,gt,grade,indx,syzp,1,serial); } - markRedundant0(g,grade,indx); + /* markRedundant0(g,grade,indx); ?*/ + markGeneratorInG(g,grade,indx); /*?*/ if (Debug) { outputGradedPairs(d); outputGradedPolySet(g,needSyz); } @@ -243,12 +267,30 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, while ((top = getPair(d)) != (struct pair *)NULL) { ig = top->ig; ii = top->ii; /* [ig,ii] */ jg = top->jg; ji = top->ji; /* [jg,ji] */ + /* + if (g->polys[ig]->del[ii] || g->polys[jg]->del[ji]) { + if (KanGBmessage) printf("p"); + continue; + } Don't do this. + */ gi = g->polys[ig]->g[ii]; gj = g->polys[jg]->g[ji]; Spairs++; - h = (*sp)(gi,gj); + if (reduceOnly && (!needSyz) && (!needBack)) h = spZero(); /* rd = 0 */ + else h = (*sp)(gi,gj); rd = ppAddv(ppMult(h.a,gi),ppMult(h.b,gj)); + + if (Statistics) { + if (top->grade >=0 && top->grade < DMAX) { + statisticsPL = pLength(rd); + SpNumber[top->grade]++; + if (MaxLength[top->grade] < statisticsPL) { + MaxLength[top->grade] = statisticsPL; + } + } + } + if (!Sugar || forceReduction) { rd = (*reduction)(rd,g,needBack,&syz); }else{ @@ -281,6 +323,15 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, } if (!(rd ISZERO)) { + if (gbCheck) { + /* Abort the calculation. */ + g->gb = 0; + if (KanGBmessage) { + printf("gbCheck failed. \n"); + printf("Note that the result is NOT groebner basis.\n"); + } + break; + } if (needBack || needSyz) { syzp = newSyz0(); syzp->cf = syzCf; /* no meaning */ @@ -320,6 +371,7 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, if (countDown == 0) { printf("\nThe computation of the Groebner basis is suspended because of countDown==0.\n"); printf("Note that the result is NOT groebner basis.\n"); + g->gb = 0; break; } } @@ -341,6 +393,7 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, printf("Computation of the Groebner basis is suspended bacause of StopDegree < computing grade.\n"); printf("Note that the result is NOT groebner basis.\n"); } + g->gb = 0; break; } } @@ -361,9 +414,22 @@ struct gradedPolySet *groebner_gen(f,needBack,needSyz, printf("Criterion1 is applied %d times.\n",Criterion1); printf("Criterions M,F and B are applied M=%d, F=%d, B=%d times.\n",Criterion2M,Criterion2F,Criterion2B); Spairs = Criterion1 = Criterion2M = Criterion2F = Criterion2B = 0; + + printf("degree(number of spolys): maximal polynomial size\n"); + statisticsCount = 0; + for (i=0; i 0) { + printf("%3d(%3d): %5d, ",i,SpNumber[i],MaxLength[i]); + if (statisticsCount % 4 == 3) { + printf("\n"); + statisticsCount = 0; + }else{ statisticsCount++; } + } + } + printf("\n"); } - if (AutoReduce) { + if (AutoReduce || reduceOnly) { toReducedBasis(g,needBack,needSyz); } @@ -460,6 +526,7 @@ void toReducedBasis(struct gradedPolySet *grP,int need if (KanGBmessage) { printf("Done(reduced basis)\n"); } + grP->reduced = 1; }