=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/sugar.c,v retrieving revision 1.4 retrieving revision 1.8 diff -u -p -r1.4 -r1.8 --- OpenXM/src/kan96xx/Kan/sugar.c 2003/05/01 01:58:05 1.4 +++ OpenXM/src/kan96xx/Kan/sugar.c 2020/10/06 11:33:47 1.8 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/sugar.c,v 1.3 2001/05/04 01:06:25 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/sugar.c,v 1.7 2003/09/20 09:57:29 takayama Exp $ */ #include #include "datatype.h" #include "extern2.h" @@ -8,7 +8,11 @@ /* static int DebugReduction = 0; */ -extern DebugReductionRed; +extern int DebugReductionRed; +extern int DebugContentReduction; +extern int Ecart; +extern int Ecart_sugarGrade; +static int ecart_grade_sugar(POLY f); POLY reduction_sugar(POLY f,struct gradedPolySet *gset,int needSyz, struct syz0 *syzp,int sugarGrade) @@ -24,13 +28,24 @@ POLY reduction_sugar(POLY f,struct gradedPolySet *gset extern struct ring *CurrentRingp; struct ring *rp; - + extern int DoCancel; + + if (Ecart) { + Ecart_sugarGrade = sugarGrade; + return reduction_ecart(f,gset,needSyz,syzp); + } if (needSyz) { if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; } cf = cxx(1,0,0,rp); syz = ZERO; } + if (needSyz && DoCancel) { + warningGradedSet("needSyz is not supported when DoCancel is turned on. DoCancel is set to 0.\n"); + DoCancel = 0; + } + if (DoCancel && (f != POLYNULL)) shouldReduceContent(f,1); + reduced = 0; /* no */ /* Take minimum */ gradelimit = (gset->maxGrade < sugarGrade+1 ?gset->maxGrade: sugarGrade+1); @@ -48,6 +63,16 @@ POLY reduction_sugar(POLY f,struct gradedPolySet *gset /* Reduce if and only if sugarGrade does not increase. */ if (tdegm+grd <= sugarGrade) { f = reduction1_sugar(f,set->g[i],needSyz,&cc,&cg,sugarGrade); + + if (DoCancel && (f != POLYNULL)) { + if (shouldReduceContent(f,0)) { + struct coeff *cont; + f = reduceContentOfPoly(f,&cont); + shouldReduceContent(f,1); + if (DebugContentReduction) printf("CONT=%s ",coeffToString(cont)); + } + } + if (needSyz) { cf = ppMult(cc,cf); syz = cpMult(toSyzCoeff(cc),syz); @@ -67,6 +92,15 @@ POLY reduction_sugar(POLY f,struct gradedPolySet *gset syzp->cf = cf; /* cf is in the CurrentRingp */ syzp->syz = syz; /* syz is in the SyzRingp */ } + + if (DoCancel && (f != POLYNULL)) { + if (f->m->ringp->p == 0) { + struct coeff *cont; + f = reduceContentOfPoly(f,&cont); + if (DebugContentReduction) printf("cont=%s ",coeffToString(cont)); + } + } + return(f); } @@ -138,6 +172,7 @@ int grade_sugar(f) static int nn,mm,ll,cc,n,m,l,c; static struct ring *cr = (struct ring *)NULL; + /* if (Ecart) return ecart_grade_sugar(f); */ if (f ISZERO) return(-1); tf = f->m; if (tf->ringp != cr) { @@ -172,6 +207,72 @@ int grade_sugar(f) r += tf->e[i].x; r += tf->e[i].D; } + f = f->next; + ans = (ans>r?ans:r); + } + return(ans); +} + +static int ecart_grade_sugar(POLY f) /* experimental */ +{ + int r; + int i,ans; + MONOMIAL tf; + static int nn,mm,ll,cc,n,m,l,c; + static struct ring *cr = (struct ring *)NULL; + int soffset; + int sdegree; + + if (f ISZERO) return(-1); + tf = f->m; + if (tf->ringp != cr) { + n = tf->ringp->n; + m = tf->ringp->m; + l = tf->ringp->l; + c = tf->ringp->c; + nn = tf->ringp->nn; + mm = tf->ringp->mm; + ll = tf->ringp->ll; + cc = tf->ringp->cc; + cr = tf->ringp; + } + + soffset = 0x7fffffff; /* large number */ + while (f != NULL) { + r = 0; + tf = f->m; + for (i=m; ie[i].x; + r += tf->e[i].D; + } + f = f->next; + soffset = (r < soffset? r: soffset); + } + + ans = 0; + while (f != NULL) { + r = 0; sdegree = 0; + tf = f->m; + for (i=0; ie[i].x; + r += tf->e[i].D; + } + for (i=c; ie[i].x; + r += tf->e[i].D; + } + for (i=l; ie[i].x; + r += tf->e[i].D; + } + for (i=m; ie[i].x; + r += tf->e[i].D; + sdegree -= tf->e[i].x; + sdegree += tf->e[i].D; + + } + r += sdegree-soffset; f = f->next; ans = (ans>r?ans:r); }