version 1.1, 1999/10/08 02:12:02 |
version 1.13, 2005/07/07 02:59:47 |
|
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/gb.c,v 1.12 2005/06/30 08:35:07 takayama Exp $ */ |
|
/* untabify on May 4, 2001 */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
|
|
|
|
#define INITGRADE 4 |
#define INITGRADE 4 |
#define INITSIZE 2 |
#define INITSIZE 2 |
|
#define DMAX 100 |
|
|
int KanGBmessage = 1; |
int KanGBmessage = 1; |
|
|
static int Debug = 0; |
static int Debug = 0; |
static int sugarGrade(struct pair *inode,struct gradedPolySet *grG, |
static int sugarGrade(struct pair *inode,struct gradedPolySet *grG, |
POLY gt,int gtSugarGrade); |
POLY gt,int gtSugarGrade); |
extern int Sugar; |
extern int Sugar; |
extern int Statistics; |
extern int Statistics; |
extern int Criterion1; |
extern int Criterion1; |
Line 19 extern int UseCriterion1; |
|
Line 22 extern int UseCriterion1; |
|
extern int UseCriterion2B; |
extern int UseCriterion2B; |
extern int Spairs; |
extern int Spairs; |
extern int Criterion2B, Criterion2F, Criterion2M; |
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 *updatePairs(grD,gt,gtGrade,t,grG) |
struct gradedPairs *grD; /* set of pairs */ |
struct gradedPairs *grD; /* set of pairs */ |
POLY gt; /* new polynomial */ |
POLY gt; /* new polynomial */ |
int gtGrade; |
int gtGrade; |
int t; |
int t; |
struct gradedPolySet *grG; /* (f,gt), f \in grG, should be added to grD. */ |
struct gradedPolySet *grG; /* (f,gt), f \in grG, should be added to grD. */ |
{ |
{ |
int gmax,newGrade; |
int gmax,newGrade; |
struct pair *node,*new,*inode,*jnode; |
struct pair *node,*new,*inode,*jnode; |
Line 48 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
Line 55 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
g = grG->polys[k]; |
g = grG->polys[k]; |
for (i=0; i<g->size; i++) { |
for (i=0; i<g->size; i++) { |
if (g->del[i] == 0 && (gtGrade != k || t != i)) { |
if (g->del[i] == 0 && (gtGrade != k || t != i)) { |
lcmp = (*lcm)(g->g[i],gt); |
lcmp = (*lcm)(g->g[i],gt); |
if (lcmp == ZERO) { |
if (lcmp == ZERO) { |
|
|
}else { |
}else { |
new->del = 0; |
new->del = 0; |
new->next = newPair(new); |
new->next = newPair(new); |
new = new->next; |
new = new->next; |
new->lcm = lcmp; |
new->lcm = lcmp; |
new->ig = k; new->ii = i; /* g->g[i] */ |
new->ig = k; new->ii = i; /* g->g[i] */ |
new->jg = gtGrade; new->ji = t; /* gt */ |
new->jg = gtGrade; new->ji = t; /* gt */ |
new->grade = -1; /* one do not need to set grade here. */ |
new->grade = -1; /* one do not need to set grade here. */ |
} |
} |
} |
} |
} |
} |
} |
} |
Line 69 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
Line 76 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
/* See Gebauer and Mora, 1988, Journal of Symbolic Computation |
/* See Gebauer and Mora, 1988, Journal of Symbolic Computation |
279. We must not use the test T(i)T(j) = T(i,j) because it |
279. We must not use the test T(i)T(j) = T(i,j) because it |
does not hold in the ring of diff op. |
does not hold in the ring of diff op. |
*/ |
*/ |
|
|
inode = node->next; |
inode = node->next; |
while (inode != (struct pair *)NULL) { |
while (inode != (struct pair *)NULL) { |
Line 78 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
Line 85 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
it = inode->lcm; |
it = inode->lcm; |
jt = jnode->lcm; |
jt = jnode->lcm; |
if ((*mmLarger)(it,jt) == 2) { |
if ((*mmLarger)(it,jt) == 2) { |
/* F(j,t), i<j */ |
/* F(j,t), i<j */ |
jnode->del = 1; |
jnode->del = 1; |
if (Verbose) printf("F[%d,%d]([%d,%d],[%d,%d]) ", |
if (Verbose) printf("F[%d,%d]([%d,%d],[%d,%d]) ", |
inode->ig,inode->ii, |
inode->ig,inode->ii, |
jnode->ig,jnode->ii, |
jnode->ig,jnode->ii, |
gtGrade,t); |
gtGrade,t); |
Criterion2F++; |
Criterion2F++; |
}else { |
}else { |
/* g[i] > g[j] ?, M(i,t) */ |
/* g[i] > g[j] ?, M(i,t) */ |
if ((*isReducible)(it,jt)) { |
if ((*isReducible)(it,jt)) { |
inode->del = 1; |
inode->del = 1; |
if (Verbose) printf("M[%d,%d]([%d,%d],[%d,%d]) ", |
if (Verbose) printf("M[%d,%d]([%d,%d],[%d,%d]) ", |
jnode->ig,jnode->ii, |
jnode->ig,jnode->ii, |
inode->ig,inode->ii, |
inode->ig,inode->ii, |
gtGrade,t); |
gtGrade,t); |
Criterion2M++; |
Criterion2M++; |
} |
} |
/* M(j,t) */ |
/* M(j,t) */ |
if ((*isReducible)(jt,it)) { |
if ((*isReducible)(jt,it)) { |
jnode->del = 1; |
jnode->del = 1; |
if (Verbose) printf("M[%d,%d]([%d,%d],[%d,%d]) ", |
if (Verbose) printf("M[%d,%d]([%d,%d],[%d,%d]) ", |
inode->ig,inode->ii, |
inode->ig,inode->ii, |
jnode->ig,jnode->ii, |
jnode->ig,jnode->ii, |
gtGrade,t); |
gtGrade,t); |
Criterion2M++; |
Criterion2M++; |
} |
} |
} |
} |
jnode = jnode->next; |
jnode = jnode->next; |
} |
} |
inode = inode->next; |
inode = inode->next; |
} |
} |
|
|
if (UseCriterion1) { |
if (UseCriterion1) { |
inode = node->next; |
inode = node->next; |
while (inode != NULL) { |
while (inode != NULL) { |
if (inode->del == 0) { |
if (inode->del == 0) { |
if (criterion1(gt,grG->polys[inode->ig]->g[inode->ii],inode->lcm)) { |
if (criterion1(gt,grG->polys[inode->ig]->g[inode->ii],inode->lcm)) { |
inode->del = 1; |
inode->del = 1; |
if (Verbose) printf("Criterion1([%d,%d],[%d,%d]) ", |
if (Verbose) printf("Criterion1([%d,%d],[%d,%d]) ", |
inode->ig,inode->ii, |
inode->ig,inode->ii, |
gtGrade,t); |
gtGrade,t); |
Criterion1++; |
Criterion1++; |
} |
} |
} |
} |
inode = inode->next; |
inode = inode->next; |
} |
} |
Line 136 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
Line 143 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
while (inode != (struct pair *)NULL) { |
while (inode != (struct pair *)NULL) { |
if (inode->del == 0) { |
if (inode->del == 0) { |
if (Sugar) { |
if (Sugar) { |
inode->grade = sugarGrade(inode,grG,gt,gtGrade); |
inode->grade = sugarGrade(inode,grG,gt,gtGrade); |
}else{ |
}else{ |
inode->grade = (*grade)(inode->lcm); |
inode->grade = (*grade)(inode->lcm); |
} |
} |
if (grD->lim <= inode->grade) { |
if (grD->lim <= inode->grade) { |
grD = enlargeGradedPairs(2*(inode->grade)+1,grD); |
grD = enlargeGradedPairs(2*(inode->grade)+1,grD); |
} |
} |
insertPair(inode,grD->pairs[inode->grade]); |
insertPair(inode,grD->pairs[inode->grade]); |
grD->maxGrade = max(grD->maxGrade,inode->grade+1); /* don't forget */ |
grD->maxGrade = max(grD->maxGrade,inode->grade+1); /* don't forget */ |
Line 155 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
Line 162 struct gradedPolySet *grG; /* (f,gt), f \in grG, shoul |
|
return(grD); |
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; |
struct arrayOfPOLY *f; |
int needBack; |
int needBack; |
int needSyz; |
int needSyz; |
struct pair **grP; /* if (needSyz), it is set. */ |
struct pair **grP; /* if (needSyz), it is set. */ |
int countDown; |
int countDown; |
int forceReduction; |
int forceReduction; |
|
int reduceOnly; |
|
int gbCheck; |
{ |
{ |
int r; |
int r; |
struct gradedPolySet *g; |
struct gradedPolySet *g; |
Line 186 int forceReduction; |
|
Line 195 int forceReduction; |
|
extern int StopDegree; |
extern int StopDegree; |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
extern char *F_mpMult; |
extern char *F_mpMult; |
|
extern int Homogenize; |
struct ring *rp; |
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; i<DMAX; i++) MaxLength[i] = SpNumber[i] = 0; |
|
} |
r = f->n; |
r = f->n; |
if (r<=0) return((struct gradedPolySet *)NULL); |
if (r<=0) return((struct gradedPolySet *)NULL); |
if (UseCriterion1) { |
if (UseCriterion1) { |
Line 201 int forceReduction; |
|
Line 220 int forceReduction; |
|
|
|
Spairs = Criterion1 = Criterion2B = Criterion2F = Criterion2M = 0; |
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); |
d = newGradedPairs(INITGRADE*2); |
for (i=0; i<g->lim; i++) { |
for (i=0; i<g->lim; i++) { |
g->polys[i] = newPolySet(INITSIZE); |
g->polys[i] = newPolySet(INITSIZE); |
} |
} |
|
|
|
first = 1; |
for (i=0; i<r; i++) { |
for (i=0; i<r; i++) { |
gt = getArrayOfPOLY(f,i); |
gt = getArrayOfPOLY(f,i); |
if (gt ISZERO) { rp = CurrentRingp; } else { rp = gt->m->ringp; } |
if (gt ISZERO) { rp = CurrentRingp; } else { rp = gt->m->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); |
grade = -1; whereInG(g,gt,&grade,&indx,Sugar); |
if (KanGBmessage == 2) { |
if (KanGBmessage == 2) { |
printf("init=%s, ",POLYToString(head(gt),'*',1)); |
printf("init=%s, ",POLYToString(head(gt),'*',1)); |
Line 219 int forceReduction; |
|
Line 245 int forceReduction; |
|
serial = i; |
serial = i; |
if (!needBack) { |
if (!needBack) { |
g = putPolyInG(g,gt,grade,indx, |
g = putPolyInG(g,gt,grade,indx, |
(struct syz0 *)NULL,1,serial); |
(struct syz0 *)NULL,1,serial); |
}else { |
}else { |
syzp = newSyz0(); |
syzp = newSyz0(); |
syzp->cf = cxx(1,0,0,rp); |
syzp->cf = cxx(1,0,0,rp); |
Line 227 int forceReduction; |
|
Line 253 int forceReduction; |
|
g = putPolyInG(g,gt,grade,indx,syzp,1,serial); |
g = putPolyInG(g,gt,grade,indx,syzp,1,serial); |
} |
} |
|
|
markRedundant0(g,grade,indx); |
/* markRedundant0(g,grade,indx); ?*/ |
|
markGeneratorInG(g,grade,indx); /*?*/ |
if (Debug) { |
if (Debug) { |
outputGradedPairs(d); outputGradedPolySet(g,needSyz); |
outputGradedPairs(d); outputGradedPolySet(g,needSyz); |
} |
} |
Line 240 int forceReduction; |
|
Line 267 int forceReduction; |
|
while ((top = getPair(d)) != (struct pair *)NULL) { |
while ((top = getPair(d)) != (struct pair *)NULL) { |
ig = top->ig; ii = top->ii; /* [ig,ii] */ |
ig = top->ig; ii = top->ii; /* [ig,ii] */ |
jg = top->jg; ji = top->ji; /* [jg,ji] */ |
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]; |
gi = g->polys[ig]->g[ii]; |
gj = g->polys[jg]->g[ji]; |
gj = g->polys[jg]->g[ji]; |
|
|
Spairs++; |
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)); |
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) { |
if (!Sugar || forceReduction) { |
rd = (*reduction)(rd,g,needBack,&syz); |
rd = (*reduction)(rd,g,needBack,&syz); |
}else{ |
}else{ |
Line 256 int forceReduction; |
|
Line 301 int forceReduction; |
|
|
|
if (KanGBmessage) { |
if (KanGBmessage) { |
if (KanGBmessage == 2) { |
if (KanGBmessage == 2) { |
printf("sp([%d,%d],[%d,%d]), ",ig,ii,jg,ji); |
printf("sp([%d,%d],[%d,%d]), ",ig,ii,jg,ji); |
if (rd ISZERO) { |
if (rd ISZERO) { |
printf(" 0 \n"); |
printf(" 0 \n"); |
} else{ |
} else{ |
printf(" terms=%d, grade=%d, ",pLength(rd),top->grade); |
printf(" terms=%d, grade=%d, ",pLength(rd),top->grade); |
printf(" init=%s, ",POLYToString(head(rd),'*',1)); |
printf(" init=%s, ",POLYToString(head(rd),'*',1)); |
} |
} |
}else{ |
}else{ |
if (pgrade != top->grade) { |
if (pgrade != top->grade) { |
pgrade = top->grade; |
pgrade = top->grade; |
printf(" %d",pgrade); |
printf(" %d",pgrade); |
fflush(stdout); |
fflush(stdout); |
} |
} |
if (rd ISZERO) { |
if (rd ISZERO) { |
printf("o"); fflush(stdout); |
printf("o"); fflush(stdout); |
}else{ |
}else{ |
printf("."); fflush(stdout); |
printf("."); fflush(stdout); |
} |
} |
} |
} |
} |
} |
|
|
if (!(rd ISZERO)) { |
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) { |
if (needBack || needSyz) { |
syzp = newSyz0(); |
syzp = newSyz0(); |
syzp->cf = syzCf; /* no meaning */ |
syzp->cf = syzCf; /* no meaning */ |
syzp->syz = ppAdd(toSyzPoly(h.a,ig,ii),toSyzPoly(h.b,jg,ji)); |
syzp->syz = ppAdd(toSyzPoly(h.a,ig,ii),toSyzPoly(h.b,jg,ji)); |
syzp->syz = cpMult(toSyzCoeff(syzCf),syzp->syz); |
syzp->syz = cpMult(toSyzCoeff(syzCf),syzp->syz); |
syzp->syz = ppAdd(syzp->syz,syzPoly); |
syzp->syz = ppAdd(syzp->syz,syzPoly); |
} |
} |
|
|
if (ReduceLowerTerms && !(Sugar)) { |
if (ReduceLowerTerms && !(Sugar)) { |
rd = (*reductionCdr)(rd,g,needBack,&syz); |
rd = (*reductionCdr)(rd,g,needBack,&syz); |
if (needBack || needSyz) { |
if (needBack || needSyz) { |
/* syzp->cf = ppMult(syz.cf,syzp->cf); no meaning */ |
/* syzp->cf = ppMult(syz.cf,syzp->cf); no meaning */ |
syzp->syz = ppAdd(syz.syz, |
syzp->syz = ppAdd(syz.syz, |
cpMult(toSyzCoeff(syz.cf),syzp->syz)); |
cpMult(toSyzCoeff(syz.cf),syzp->syz)); |
} |
} |
} |
} |
|
|
if(Sugar && (!forceReduction)){grade=top->grade;}else{grade=-1;}whereInG(g,rd,&grade,&indx,Sugar); |
if(Sugar && (!forceReduction)){grade=top->grade;}else{grade=-1;}whereInG(g,rd,&grade,&indx,Sugar); |
if (KanGBmessage == 2) { |
if (KanGBmessage == 2) { |
printf("(gr,indx)=(%d,%d).\n",grade,indx); |
printf("(gr,indx)=(%d,%d).\n",grade,indx); |
/* |
/* |
printf("sp(%s,%s)-->%s\n",POLYToString(gi,' ',1), |
printf("sp(%s,%s)-->%s\n",POLYToString(gi,' ',1), |
POLYToString(gj,' ',1), |
POLYToString(gj,' ',1), |
POLYToString(rd,' ',1)); |
POLYToString(rd,' ',1)); |
*/ |
*/ |
} |
} |
|
|
d = updatePairs(d,rd,grade,indx,g); |
d = updatePairs(d,rd,grade,indx,g); |
g = putPolyInG(g,rd,grade,indx,syzp,0,-1); |
g = putPolyInG(g,rd,grade,indx,syzp,0,-1); |
if (Sugar) { markRedundant0(g,grade,indx);} |
if (Sugar) { markRedundant0(g,grade,indx);} |
else {markRedundant(g,rd,grade,indx,Sugar);} |
else {markRedundant(g,rd,grade,indx,Sugar);} |
|
|
if (KanGBmessage && (StopDegree < pgrade)) { |
|
printf("Computation of the Groebner basis is suspended bacause of StopDegree < computing grade.\n"); |
|
printf("Note that the result is NOT groebner basis.\n"); |
|
break; |
|
} |
|
if (countDown) { |
if (countDown) { |
if (eliminated(rd) == 1) { |
if (eliminated(rd) == 1) { |
--countDown; |
--countDown; |
printf("x"); fflush(stdout); |
printf("x"); fflush(stdout); |
if (countDown == 0) { |
if (countDown == 0) { |
printf("\nThe computation of the Groebner basis is suspended because of countDown==0.\n"); |
printf("\nThe computation of the Groebner basis is suspended because of countDown==0.\n"); |
printf("Note that the result is NOT groebner basis.\n"); |
printf("Note that the result is NOT groebner basis.\n"); |
break; |
g->gb = 0; |
} |
break; |
} |
} |
|
} |
} |
} |
if (Debug) { |
if (Debug) { |
outputGradedPairs(d); outputGradedPolySet(g,needSyz); |
outputGradedPairs(d); outputGradedPolySet(g,needSyz); |
} |
} |
}else{ |
}else{ |
if (needSyz) { |
if (needSyz) { |
top->syz = ppAdd(toSyzPoly(h.a,ig,ii),toSyzPoly(h.b,jg,ji)); |
top->syz = ppAdd(toSyzPoly(h.a,ig,ii),toSyzPoly(h.b,jg,ji)); |
top->syz = cpMult(toSyzCoeff(syzCf),top->syz); |
top->syz = cpMult(toSyzCoeff(syzCf),top->syz); |
top->syz = ppAdd(top->syz,syzPoly); |
top->syz = ppAdd(top->syz,syzPoly); |
listP->next = top; top->prev = listP; listP = listP->next; |
listP->next = top; top->prev = listP; listP = listP->next; |
} |
} |
} |
} |
|
if (StopDegree < pgrade) { |
|
fprintf(stderr,"Obtained a partial GB (StopDegree=%d)\n",StopDegree); |
|
if (KanGBmessage) { |
|
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; |
|
} |
} |
} |
|
|
if (KanGBmessage == 2) { |
if (KanGBmessage == 2) { |
Line 355 int forceReduction; |
|
Line 414 int forceReduction; |
|
printf("Criterion1 is applied %d times.\n",Criterion1); |
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); |
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; |
Spairs = Criterion1 = Criterion2M = Criterion2F = Criterion2B = 0; |
|
|
|
printf("degree(number of spolys): maximal polynomial size\n"); |
|
statisticsCount = 0; |
|
for (i=0; i<DMAX; i++) { |
|
if (SpNumber[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 || reduceOnly) { |
|
toReducedBasis(g,needBack,needSyz); |
|
} |
|
|
return(g); |
return(g); |
} |
} |
|
|
|
|
static int sugarGrade(struct pair *inode,struct gradedPolySet *grG, |
static int sugarGrade(struct pair *inode,struct gradedPolySet *grG, |
POLY gt,int gtSugarGrade) |
POLY gt,int gtSugarGrade) |
{ |
{ |
int a,b,ans; |
int a,b,ans; |
int debug = 0; |
int debug = 0; |
Line 371 static int sugarGrade(struct pair *inode,struct graded |
|
Line 446 static int sugarGrade(struct pair *inode,struct graded |
|
b = grade_gen(inode->lcm)-grade_gen(gt); |
b = grade_gen(inode->lcm)-grade_gen(gt); |
/* inode = lcm(f_i, gt) = p f_i = q gt modulo lower order terms. |
/* inode = lcm(f_i, gt) = p f_i = q gt modulo lower order terms. |
a = tdeg(p), b = tdeg(gt); |
a = tdeg(p), b = tdeg(gt); |
*/ |
*/ |
if (debug) { |
if (debug) { |
printf("Sugar grade of sp([%d,%d],[%d,%d]) ",inode->ig,inode->ii, |
printf("Sugar grade of sp([%d,%d],[%d,%d]) ",inode->ig,inode->ii, |
inode->jg,inode->ji); |
inode->jg,inode->ji); |
printf("is max(%d+%d,%d+%d)\n",a,inode->ig,b,gtSugarGrade); |
printf("is max(%d+%d,%d+%d)\n",a,inode->ig,b,gtSugarGrade); |
} |
} |
a = a+(inode->ig); /* new sugar degree of p f_i. */ |
a = a+(inode->ig); /* new sugar degree of p f_i. */ |
Line 382 static int sugarGrade(struct pair *inode,struct graded |
|
Line 457 static int sugarGrade(struct pair *inode,struct graded |
|
return( a > b ? a : b); |
return( a > b ? a : b); |
} |
} |
|
|
|
void toReducedBasis(struct gradedPolySet *grP,int needBack, int needSyz) |
|
{ |
|
int changed, grd, i, reduced, grade,indx; |
|
struct syz0 syz; |
|
struct syz0 *syzp; |
|
POLY f; |
|
POLY rd; |
|
struct polySet *set; |
|
|
|
/* KanGBmessage=1; */ |
|
do { |
|
if (KanGBmessage) { |
|
printf("s"); fflush(stdout); |
|
} |
|
changed = 0; |
|
grd = 0; |
|
while (grd < grP->maxGrade) { |
|
set = grP->polys[grd]; |
|
for (i=0; i<set->size; i++) { |
|
if (set->del[i] == 0) { |
|
f = set->g[i]; |
|
if (KanGBmessage) { |
|
/* printf("(%d,%d)",grd,i); */ |
|
fflush(stdout); |
|
} |
|
rd = reductionCdr_except_grd_i(f,grP,needBack,&syz,grd,i,&reduced); |
|
if (KanGBmessage) { |
|
if (reduced) { |
|
printf("."); |
|
}else{ |
|
printf("o"); |
|
} |
|
fflush(stdout); |
|
} |
|
if (reduced) { |
|
changed = 1; |
|
set->del[i] = 1; |
|
if (rd != ZERO) { |
|
if (needSyz) { |
|
syzp = newSyz0(); |
|
syzp->cf = syz.cf; /* no meaning */ |
|
syzp->syz = toSyzPoly(cxx(1,0,0,rd->m->ringp),grd,i); |
|
syzp->syz = cpMult(toSyzCoeff(syz.cf),syzp->syz); |
|
syzp->syz = ppAdd(syzp->syz,syz.syz); |
|
/* rd = c*f + \sum c_{d,i} g_{d,i} |
|
c : syz.cf, \sum c_{d,j} g_{d,j} : syz.syz. |
|
c*grade^grd*index^i + \sum c_{d,j} grade^d*index^j |
|
grP is a set of polynomials. Polynomials are indexed by |
|
grade and index. |
|
*/ |
|
/* printf("%s, ",POLYToString(syzp->cf,' ',1)); |
|
printf("%s\n",POLYToString(syzp->syz,' ',1)); */ |
|
}else{ |
|
syzp = NULL; |
|
} |
|
grade = -1; whereInG(grP,rd,&grade,&indx,Sugar); |
|
/* Do not forget to set grade to -1 */ |
|
/* printf("grade=%d, indx=%d, ",grade,indx); */ |
|
putPolyInG(grP,rd,grade,indx,syzp,0,-1); |
|
} |
|
} |
|
} |
|
} |
|
grd++; |
|
} |
|
} while(changed); |
|
if (KanGBmessage) { |
|
printf("Done(reduced basis)\n"); |
|
} |
|
grP->reduced = 1; |
|
} |
|
|
|
|