=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/sugar.c,v retrieving revision 1.1.1.1 retrieving revision 1.6 diff -u -p -r1.1.1.1 -r1.6 --- OpenXM/src/kan96xx/Kan/sugar.c 1999/10/08 02:12:02 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/sugar.c 2003/09/12 02:52:50 1.6 @@ -1,3 +1,4 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/sugar.c,v 1.5 2003/08/21 02:30:23 takayama Exp $ */ #include #include "datatype.h" #include "extern2.h" @@ -5,10 +6,14 @@ #define mymax(p,q) (p>q?p:q) -static int DebugReduction = 0; +/* static int DebugReduction = 0; +*/ +extern DebugReductionRed; +extern DebugContentReduction; +extern Ecart; POLY reduction_sugar(POLY f,struct gradedPolySet *gset,int needSyz, - struct syz0 *syzp,int sugarGrade) + struct syz0 *syzp,int sugarGrade) { int reduced,reduced1,reduced2; int grd; @@ -21,13 +26,21 @@ POLY reduction_sugar(POLY f,struct gradedPolySet *gset extern struct ring *CurrentRingp; struct ring *rp; - + extern DoCancel; + + if (Ecart) 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); @@ -37,44 +50,63 @@ POLY reduction_sugar(POLY f,struct gradedPolySet *gset while (grd < gset->maxGrade) { set = gset->polys[grd]; do { - reduced2 = 0; /* no */ - for (i=0; isize; i++) { - if (f ISZERO) goto ss; - if ((*isReducible)(f,set->g[i])) { - tdegm = grade_gen(f) - grade_gen(set->g[i]); - /* 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 (needSyz) { - cf = ppMult(cc,cf); - syz = cpMult(toSyzCoeff(cc),syz); - syz = ppAddv(syz,toSyzPoly(cg,grd,i)); - } - reduced = reduced1 = reduced2 = 1; /* yes */ - } - } - } + reduced2 = 0; /* no */ + for (i=0; isize; i++) { + if (f ISZERO) goto ss; + if ((*isReducible)(f,set->g[i])) { + tdegm = grade_gen(f) - grade_gen(set->g[i]); + /* 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); + syz = ppAddv(syz,toSyzPoly(cg,grd,i)); + } + reduced = reduced1 = reduced2 = 1; /* yes */ + } + } + } } while (reduced2 != 0); grd++; } }while (reduced1 != 0); - ss: ; + ss: ; if (needSyz) { 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); } POLY reduction1_sugar(f,g,needSyz,c,h,sugarGrade) -POLY f; -POLY g; -int needSyz; -POLY *c; /* set */ -POLY *h; /* set */ -int sugarGrade; -/* f must be reducible by g. r = c*f + h*g */ + POLY f; + POLY g; + int needSyz; + POLY *c; /* set */ + POLY *h; /* set */ + int sugarGrade; + /* f must be reducible by g. r = c*f + h*g */ { extern struct ring *CurrentRingp; struct ring *rp; @@ -91,9 +123,9 @@ int sugarGrade; sv = (*sp)(f,g); f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g)); - if (DebugReduction) { + if (DebugReductionRed) { printf("c=%s, d=%s, g=%s: f --> c*f + d*g.\n", - POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1)); + POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1)); printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); } f = f2; @@ -109,15 +141,15 @@ int sugarGrade; if (tdegm+grd <= sugarGrade) { sv = (*sp)(f,g); f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g)); - if (DebugReduction) { - printf("! c=%s, d=%s, g=%s: f --> c*f + d*g.\n", - POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1)); - printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); + if (DebugReductionRed) { + printf("! c=%s, d=%s, g=%s: f --> c*f + d*g.\n", + POLYToString(sv.a,'*',1),POLYToString(sv.b,'*',1),POLYToString(g,'*',1)); + printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); } f = f2; if (needSyz) { - *c = ppMult(sv.a,*c); - *h = ppAdd(ppMult(sv.a,*h),sv.b); + *c = ppMult(sv.a,*c); + *h = ppAdd(ppMult(sv.a,*h),sv.b); } }else{ break; @@ -127,7 +159,7 @@ int sugarGrade; } int grade_sugar(f) -POLY f; + POLY f; { int r; int i,ans;