=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/syz0.c,v retrieving revision 1.1.1.1 retrieving revision 1.5 diff -u -p -r1.1.1.1 -r1.5 --- OpenXM/src/kan96xx/Kan/syz0.c 1999/10/08 02:12:02 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/syz0.c 2005/07/03 11:08:54 1.5 @@ -1,4 +1,6 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/syz0.c,v 1.4 2003/08/27 03:11:12 takayama Exp $ */ #include +#include #include "datatype.h" #include "extern2.h" #include "matrix.h" @@ -17,7 +19,7 @@ static int getSize00OfGradedSet(struct gradedPolySet * static int positionInPairs(struct pair *top,struct pair *pairs); /* if the top is not in the list pairs, it returns -1. */ static struct pair *oldPairsToNewPairs(struct pair *opairs, - int *table,int size); + int *table,int size); /* In the function getSyzygy(), reduced Grobner basis *grBases is constructed from grG by deleting unnecessary elements. The array <> gives the correspondence between the index @@ -28,7 +30,7 @@ static struct pair *oldPairsToNewPairs(struct pair *op Note that the <> fields are not set properly. */ struct matrixOfPOLY *getSyzygy01(struct gradedPolySet *reducedBasis, - struct pair *excludedPairs); + struct pair *excludedPairs); /* When <> is NULL, this function computes all syzygies for the <>. @@ -41,8 +43,8 @@ struct matrixOfPOLY *getSyzygy01(struct gradedPolySet /* if (mark[j]), then the simplification is done. */ void getBackwardTransformation(grG) -struct gradedPolySet *grG; -/* grG->polys[i]->mark[j],syz[j] are modified. */ + struct gradedPolySet *grG; + /* grG->polys[i]->mark[j],syz[j] are modified. */ { int i,j; struct polySet *ps; @@ -52,16 +54,16 @@ struct gradedPolySet *grG; ps = grG->polys[i]; for (j=0; jsize; j++) { if (ps->mark[j] == 0 && ps->del[j] == 0) { - simplifyBT(i,j,grG); + simplifyBT(i,j,grG); } } } } void simplifyBT(grd,index,grG) -int grd; -int index; -struct gradedPolySet *grG; + int grd; + int index; + struct gradedPolySet *grG; { POLY s,r; int g0,i0; @@ -88,9 +90,9 @@ struct gradedPolySet *grG; static POLY getFactor0(grG,grd,index) -struct gradedPolySet *grG; -int grd; -int index; + struct gradedPolySet *grG; + int grd; + int index; { POLY ans; int i,j; @@ -101,7 +103,7 @@ int index; ps = grG->polys[i]; for (j=0; jsize; j++) { if (ps->mark[j] && !(i == grd && j == index)) { - ans = ppMult(ps->syz[j]->cf,ans); + ans = ppMult(ps->syz[j]->cf,ans); } } } @@ -109,8 +111,8 @@ int index; } struct arrayOfPOLY *getSyzygy0(grG,zeroPairs) -struct gradedPolySet *grG; -struct pair *zeroPairs; + struct gradedPolySet *grG; + struct pair *zeroPairs; { struct pair *tmp; int size,k,i; @@ -149,10 +151,10 @@ struct pair *zeroPairs; } struct matrixOfPOLY *getSyzygy(grG,zeroPairs,grBasesp,backwardMatp) -struct gradedPolySet *grG; -struct pair *zeroPairs; -struct gradedPolySet **grBasesp; -struct matrixOfPOLY **backwardMatp; + struct gradedPolySet *grG; + struct pair *zeroPairs; + struct gradedPolySet **grBasesp; + struct matrixOfPOLY **backwardMatp; { int serial; int i,j,kk; @@ -186,13 +188,13 @@ struct matrixOfPOLY **backwardMatp; ps = grG->polys[i]; for (j=0; jsize; j++) { if (ps->del[j] == 0) { - fi = ps->g[j]; - grd = -1;whereInG(*grBasesp,fi,&grd,&indx,Sugar); - *grBasesp = - putPolyInG(*grBasesp,fi,grd,indx,newSyz0(),0,serial); - table[4*serial] = i; table[4*serial+1] = j; - table[4*serial+2] = grd; table[4*serial+3] = indx; - serial++; + fi = ps->g[j]; + grd = -1;whereInG(*grBasesp,fi,&grd,&indx,Sugar); + *grBasesp = + putPolyInG(*grBasesp,fi,grd,indx,newSyz0(),0,serial); + table[4*serial] = i; table[4*serial+1] = j; + table[4*serial+2] = grd; table[4*serial+3] = indx; + serial++; } } } @@ -228,7 +230,7 @@ struct matrixOfPOLY **backwardMatp; printf("zeroPairs = "); outputNode(zeroPairs); for (i=0; in = %d, serial=%d \n",ap->n, serial); - printf("\nmp = \n"); printMatrixOfPOLY(mp); */ + printf("\nmp = \n"); printMatrixOfPOLY(mp); */ if (KanGBmessage) {printf(";"); fflush(stdout);} m1 = aaMult(mp,b); @@ -274,7 +277,7 @@ struct matrixOfPOLY **backwardMatp; for (i=0; im; i++) { if (!isZeroRow(m0,i)) { for (j=0; jn; j++) { - getMatrixOfPOLY(ans,kk,j) = getMatrixOfPOLY(m0,i,j); + getMatrixOfPOLY(ans,kk,j) = getMatrixOfPOLY(m0,i,j); } kk++; } @@ -282,7 +285,7 @@ struct matrixOfPOLY **backwardMatp; for (i=0; im; i++) { if (!isZeroRow(m1,i)) { for (j=0; jn; j++) { - getMatrixOfPOLY(ans,kk,j) = getMatrixOfPOLY(m1,i,j); + getMatrixOfPOLY(ans,kk,j) = getMatrixOfPOLY(m1,i,j); } kk++; } @@ -290,7 +293,7 @@ struct matrixOfPOLY **backwardMatp; for (i=0; im; i++) { if (!isZeroRow(m2,i)) { for (j=0; jn; j++) { - getMatrixOfPOLY(ans,kk,j) = getMatrixOfPOLY(m2,i,j); + getMatrixOfPOLY(ans,kk,j) = getMatrixOfPOLY(m2,i,j); } kk++; if (KanGBmessage) printf("*"); } @@ -299,7 +302,7 @@ struct matrixOfPOLY **backwardMatp; ans2 = newMatrixOfPOLY(kk,ans->n); for (i=0; in; j++) { - getMatrixOfPOLY(ans2,i,j) = getMatrixOfPOLY(ans,i,j); + getMatrixOfPOLY(ans2,i,j) = getMatrixOfPOLY(ans,i,j); } } return(ans2); @@ -310,8 +313,8 @@ struct matrixOfPOLY **backwardMatp; } POLY getSyzPolyFromSp(spij,grG) -struct pair *spij; -struct gradedPolySet *grG; + struct pair *spij; + struct gradedPolySet *grG; { int ig,ii,jg,ji; POLY dk; @@ -347,7 +350,7 @@ struct gradedPolySet *grG; } static void clearMark(grG) -struct gradedPolySet *grG; + struct gradedPolySet *grG; { int i,j; struct polySet *ps; @@ -361,9 +364,9 @@ struct gradedPolySet *grG; struct arrayOfPOLY *syzPolyToArrayOfPOLY(size,f,grG) -int size; -POLY f; /* f is in the SyzRingp */ -struct gradedPolySet *grG; + int size; + POLY f; /* f is in the SyzRingp */ + struct gradedPolySet *grG; { struct arrayOfPOLY *ap; int i,g0,i0,serial; @@ -415,11 +418,11 @@ struct matrixOfPOLY *getBackwardMatrixOfPOLY(struct gr ps = grG->polys[i]; for (j=0; jsize; j++) { if (ps->del[j] == 0) { - vec = syzPolyToArrayOfPOLY(inputSize,ps->syz[j]->syz,grG); - for (p=0; psyz[j]->syz,grG); + for (p=0; ppolys[i]; for (j=0; jsize; j++) { if (ps->serial[j] >= 0) { - ii = ps->serial[j]; - vec = syzPolyToArrayOfPOLY(n,ps->syz[j]->syz,grBases); - for (k=0; kserial[j]; + vec = syzPolyToArrayOfPOLY(n,ps->syz[j]->syz,grBases); + for (k=0; kpolys[i]; for (j=0; jsize; j++) { if (ps->serial[j] >= 0) { - ii = ps->serial[j]; - getArrayOfPOLY(mat,ii) = ps->syz[j]->cf; + ii = ps->serial[j]; + getArrayOfPOLY(mat,ii) = ps->syz[j]->cf; } } } @@ -498,9 +501,9 @@ struct gradedPolySet *newG; /* F is stored and index /* Syzygy from E-CB */ struct matrixOfPOLY *getSyzygy1(b,nc,dc) -struct matrixOfPOLY *b; -struct matrixOfPOLY *nc; -struct arrayOfPOLY *dc; + struct matrixOfPOLY *b; + struct matrixOfPOLY *nc; + struct arrayOfPOLY *dc; { int m,n2,n; struct matrixOfPOLY *mat; @@ -516,11 +519,11 @@ struct arrayOfPOLY *dc; for (j=0; jn; @@ -541,15 +544,15 @@ int i; } void errorSyz0(s) -char *s; + char *s; { fprintf(stderr,"Error(syz0.c): %s \n",s); exit(10); } - + static void printMatrixOfPOLY(mat) -struct matrixOfPOLY *mat; + struct matrixOfPOLY *mat; { int n,m,i,j; POLY f; @@ -565,7 +568,7 @@ struct matrixOfPOLY *mat; } static void printArrayOfPOLY(mat) -struct arrayOfPOLY *mat; + struct arrayOfPOLY *mat; { int n,m,i,j; POLY f; @@ -578,7 +581,7 @@ struct arrayOfPOLY *mat; } struct matrixOfPOLY *getSyzygy01(struct gradedPolySet *reducedBasis, - struct pair *excludePairs) + struct pair *excludePairs) { int r; struct gradedPolySet *g; @@ -624,7 +627,7 @@ struct matrixOfPOLY *getSyzygy01(struct gradedPolySet d = updatePairs(d,gt,grade,indx,g); g = putPolyInG(g,gt,grade,indx,newSyz0(),1,ps->serial[j]); if (Debugsyz0) { - outputGradedPairs(d); outputGradedPolySet(g,1); + outputGradedPairs(d); outputGradedPolySet(g,1); } } } @@ -646,28 +649,28 @@ struct matrixOfPOLY *getSyzygy01(struct gradedPolySet syzCf = syz.cf; if (KanGBmessage) { - if (pgrade != top->grade) { - pgrade = top->grade; - printf(" %d",pgrade); - fflush(stdout); - }else{ - if (rd ISZERO) { - printf("o"); fflush(stdout); - }else{ - printf("."); fflush(stdout); - } - } + if (pgrade != top->grade) { + pgrade = top->grade; + printf(" %d",pgrade); + fflush(stdout); + }else{ + if (rd ISZERO) { + printf("o"); fflush(stdout); + }else{ + printf("."); fflush(stdout); + } + } } if (!(rd ISZERO)) { - fprintf(stderr,"The given argument of getSyzygy01 is not a g-basis.\n"); - return((struct matrixOfPOLY *)NULL); + fprintf(stderr,"The given argument of getSyzygy01 is not a g-basis.\n"); + return((struct matrixOfPOLY *)NULL); }else{ - top->syz = ppAdd(toSyzPoly(h.a,ig,ii),toSyzPoly(h.b,jg,ji)); - top->syz = cpMult(toSyzCoeff(syzCf),top->syz); - top->syz = ppAdd(top->syz,syzPoly); - listP->next = top; top->prev = listP; listP = listP->next; - listPsize++; + top->syz = ppAdd(toSyzPoly(h.a,ig,ii),toSyzPoly(h.b,jg,ji)); + top->syz = cpMult(toSyzCoeff(syzCf),top->syz); + top->syz = ppAdd(top->syz,syzPoly); + listP->next = top; top->prev = listP; listP = listP->next; + listPsize++; } } } @@ -699,7 +702,7 @@ static int getSize00OfGradedSet(struct gradedPolySet * ps = g->polys[i]; for (j=0; jsize; j++) { if (ps->del[j] == 0) { - size += 1; + size += 1; } } } @@ -714,9 +717,9 @@ static int positionInPairs(struct pair *top, struct pa if (top == (struct pair *)NULL) return(-1); while (tmp != (struct pair *)NULL) { if (((top->ig == tmp->ig) && (top->ii == tmp->ii) && - (top->jg == tmp->jg) && (top->ji == tmp->ji)) || - ((top->ig == tmp->jg) && (top->ii == tmp->ji) && - (top->jg == tmp->ig) && (top->ji == tmp->ii))) { + (top->jg == tmp->jg) && (top->ji == tmp->ji)) || + ((top->ig == tmp->jg) && (top->ii == tmp->ji) && + (top->jg == tmp->ig) && (top->ji == tmp->ii))) { return(pos); } pos++; @@ -726,7 +729,7 @@ static int positionInPairs(struct pair *top, struct pa } static struct pair *oldPairsToNewPairs(struct pair *opairs, - int *table,int size) { + int *table,int size) { /* Never loop up prev field. */ int ig,ii,jg,ji; int p,q; @@ -738,15 +741,15 @@ static struct pair *oldPairsToNewPairs(struct pair *op for (p=0; pprev = NULL; - ans->ig = table[4*p+2]; ans->ii = table[4*p+3]; - ans->jg = table[4*q+2]; ans->ji = table[4*q+3]; - ans->next = oldPairsToNewPairs(opairs->next,table,size); - return(ans); - } + if (table[4*q] == jg && table[4*q+1] == ji) { + ans = newPair(NULL); + *ans = *opairs; + ans->prev = NULL; + ans->ig = table[4*p+2]; ans->ii = table[4*p+3]; + ans->jg = table[4*q+2]; ans->ji = table[4*q+3]; + ans->next = oldPairsToNewPairs(opairs->next,table,size); + return(ans); + } } } }