version 1.1.1.1, 1999/10/08 02:12:02 |
version 1.5, 2003/07/30 09:00:52 |
|
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/gradedset.c,v 1.4 2003/07/17 07:33:03 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
|
|
static int Debug=0; |
static int Debug=0; |
|
|
struct polySet *newPolySet(n) |
struct polySet *newPolySet(n) |
int n; |
int n; |
{ |
{ |
struct polySet *g; |
struct polySet *g; |
int i; |
int i; |
g = (struct polySet *)sGC_malloc(sizeof(struct polySet)); |
g = (struct polySet *)sGC_malloc(sizeof(struct polySet)); |
g->g = (POLY *)sGC_malloc(sizeof(POLY)*(n+1)); |
g->g = (POLY *)sGC_malloc(sizeof(POLY)*(n+1)); |
|
g->gh = (POLY *)sGC_malloc(sizeof(POLY)*(n+1)); |
|
g->gen = (int *)sGC_malloc(sizeof(int)*(n+1)); |
g->del = (int *)sGC_malloc(sizeof(int)*(n+1)); |
g->del = (int *)sGC_malloc(sizeof(int)*(n+1)); |
g->syz = (struct syz0 **)sGC_malloc(sizeof(struct syz0 *)*(n+1)); |
g->syz = (struct syz0 **)sGC_malloc(sizeof(struct syz0 *)*(n+1)); |
g->mark = (int *)sGC_malloc(sizeof(int)*(n+1)); |
g->mark = (int *)sGC_malloc(sizeof(int)*(n+1)); |
g->serial = (int *)sGC_malloc(sizeof(int)*(n+1)); |
g->serial = (int *)sGC_malloc(sizeof(int)*(n+1)); |
if (g->g == (POLY *)NULL || g->del == (int *)NULL || |
if (g->g == (POLY *)NULL || g->del == (int *)NULL || |
|
g->gh == (POLY *)NULL || g->gen == (int *)NULL || |
g->syz == (struct syz0 **)NULL || g->mark == (int *)NULL || |
g->syz == (struct syz0 **)NULL || g->mark == (int *)NULL || |
g->serial == (int *)NULL) { |
g->serial == (int *)NULL) { |
errorGradedSet("No more memory."); |
errorGradedSet("No more memory."); |
|
|
} |
} |
|
|
struct pair *newPair(prev) |
struct pair *newPair(prev) |
struct pair *prev; |
struct pair *prev; |
{ |
{ |
struct pair *g; |
struct pair *g; |
int i; |
int i; |
Line 46 struct pair *prev; |
|
Line 50 struct pair *prev; |
|
} |
} |
|
|
struct gradedPolySet *newGradedPolySet(n) |
struct gradedPolySet *newGradedPolySet(n) |
int n; |
int n; |
{ |
{ |
struct gradedPolySet *g; |
struct gradedPolySet *g; |
g = (struct gradedPolySet *)sGC_malloc(sizeof(struct gradedPolySet)); |
g = (struct gradedPolySet *)sGC_malloc(sizeof(struct gradedPolySet)); |
|
|
} |
} |
|
|
struct gradedPairs *newGradedPairs(n) |
struct gradedPairs *newGradedPairs(n) |
int n; |
int n; |
{ |
{ |
struct gradedPairs *g; |
struct gradedPairs *g; |
int i; |
int i; |
Line 85 struct syz0 *newSyz0() { |
|
Line 89 struct syz0 *newSyz0() { |
|
} |
} |
|
|
struct pair *pairCopy(node) |
struct pair *pairCopy(node) |
struct pair *node; |
struct pair *node; |
{ |
{ |
struct pair *r; |
struct pair *r; |
r = newPair(node->prev); |
r = newPair(node->prev); |
Line 94 struct pair *node; |
|
Line 98 struct pair *node; |
|
} |
} |
|
|
struct gradedPairs *enlargeGradedPairs(size,grD) |
struct gradedPairs *enlargeGradedPairs(size,grD) |
int size; |
int size; |
struct gradedPairs *grD; |
struct gradedPairs *grD; |
{ |
{ |
struct gradedPairs *new; |
struct gradedPairs *new; |
int i; |
int i; |
Line 107 struct gradedPairs *grD; |
|
Line 111 struct gradedPairs *grD; |
|
} |
} |
|
|
void insertPair(inode,before) |
void insertPair(inode,before) |
struct pair *inode; |
struct pair *inode; |
struct pair *before; |
struct pair *before; |
{ |
{ |
struct pair *q; |
struct pair *q; |
inode = pairCopy(inode); |
inode = pairCopy(inode); |
Line 124 struct pair *before; |
|
Line 128 struct pair *before; |
|
} |
} |
|
|
struct pair *deletePair(p) |
struct pair *deletePair(p) |
struct pair *p; |
struct pair *p; |
{ |
{ |
struct pair *q; |
struct pair *q; |
struct pair *r; |
struct pair *r; |
|
|
} |
} |
|
|
struct pair *getPair_org(grD) |
struct pair *getPair_org(grD) |
struct gradedPairs *grD; |
struct gradedPairs *grD; |
{ |
{ |
int gmax,i; |
int gmax,i; |
struct pair *pair; |
struct pair *pair; |
Line 156 struct gradedPairs *grD; |
|
Line 160 struct gradedPairs *grD; |
|
} |
} |
|
|
struct pair *getPair(grD) |
struct pair *getPair(grD) |
struct gradedPairs *grD; |
struct gradedPairs *grD; |
{ |
{ |
int gmax,i; |
int gmax,i; |
struct pair *pair; |
struct pair *pair; |
Line 170 struct gradedPairs *grD; |
|
Line 174 struct gradedPairs *grD; |
|
minnode = node; |
minnode = node; |
node = node->next; |
node = node->next; |
while (node != (struct pair *)NULL) { |
while (node != (struct pair *)NULL) { |
if ((*mmLarger)(minp,node->lcm) >= 1) { |
if ((*mmLarger)(minp,node->lcm) >= 1) { |
minnode = node; |
minnode = node; |
minp = minnode->lcm; |
minp = minnode->lcm; |
} |
} |
node = node->next; |
node = node->next; |
} |
} |
pair = deletePair(minnode->prev); |
pair = deletePair(minnode->prev); |
return(pair); |
return(pair); |
Line 183 struct gradedPairs *grD; |
|
Line 187 struct gradedPairs *grD; |
|
return((struct pair *)NULL); |
return((struct pair *)NULL); |
} |
} |
|
|
|
|
void whereInG(g,fi,gradep,indexp,sugar) |
void whereInG(g,fi,gradep,indexp,sugar) |
struct gradedPolySet *g; |
struct gradedPolySet *g; |
POLY fi; |
POLY fi; |
int *gradep; |
int *gradep; |
int *indexp; |
int *indexp; |
int sugar; |
int sugar; |
{ |
{ |
if (sugar) { |
if (sugar) { |
if (*gradep < 0 ) { |
if (*gradep < 0 ) { |
/* if sugar and *gradep < 0, then compute the grade. |
/* if sugar and *gradep < 0, then compute the grade. |
Otherwise, grade is given by the caller. */ |
Otherwise, grade is given by the caller. */ |
*gradep = grade_sugar(fi); |
*gradep = grade_sugar(fi); |
} |
} |
}else{ |
}else{ |
|
|
} |
} |
|
|
struct gradedPolySet *putPolyInG(g,fi,grade,index,syz,mark,serial) |
struct gradedPolySet *putPolyInG(g,fi,grade,index,syz,mark,serial) |
struct gradedPolySet *g; |
struct gradedPolySet *g; |
POLY fi; |
POLY fi; |
int grade; |
int grade; |
int index; |
int index; |
struct syz0 *syz; |
struct syz0 *syz; |
int mark; |
int mark; |
int serial; |
int serial; |
{ |
{ |
int i,j; |
int i,j; |
struct polySet *polysNew; |
struct polySet *polysNew; |
|
|
struct polySet *ps; |
struct polySet *ps; |
|
|
/*printf("--------------------\n"); |
/*printf("--------------------\n"); |
outputGradedPolySet(g,0);*/ |
outputGradedPolySet(g,0);*/ |
|
|
if (grade < 0) { |
if (grade < 0) { |
warningGradedSet("putPolyInG(): the grade is -1. The element is ignored."); |
warningGradedSet("putPolyInG(): the grade is -1. The element is ignored."); |
|
|
polysNew = newPolySet(index*2+1); |
polysNew = newPolySet(index*2+1); |
for (i=0; i<g->polys[grade]->lim; i++) { |
for (i=0; i<g->polys[grade]->lim; i++) { |
polysNew->g[i] = g->polys[grade]->g[i]; |
polysNew->g[i] = g->polys[grade]->g[i]; |
|
polysNew->gh[i] = g->polys[grade]->gh[i]; |
|
polysNew->gen[i] = g->polys[grade]->gen[i]; |
polysNew->del[i] = g->polys[grade]->del[i]; |
polysNew->del[i] = g->polys[grade]->del[i]; |
polysNew->syz[i] = g->polys[grade]->syz[i]; |
polysNew->syz[i] = g->polys[grade]->syz[i]; |
polysNew->mark[i] = g->polys[grade]->mark[i]; |
polysNew->mark[i] = g->polys[grade]->mark[i]; |
|
|
|
|
g->polys[grade]->size = index+1; |
g->polys[grade]->size = index+1; |
g->polys[grade]->g[index] = fi; |
g->polys[grade]->g[index] = fi; |
|
g->polys[grade]->gh[index] = POLYNULL; |
|
g->polys[grade]->gen[index] = 0; |
g->polys[grade]->del[index] = 0; |
g->polys[grade]->del[index] = 0; |
g->polys[grade]->syz[index] = syz; |
g->polys[grade]->syz[index] = syz; |
g->polys[grade]->mark[index] = mark; |
g->polys[grade]->mark[index] = mark; |
|
|
if (g->maxGrade < grade+1) g->maxGrade = grade+1; |
if (g->maxGrade < grade+1) g->maxGrade = grade+1; |
|
|
/*printf("grade=%d, index=%d\n",grade,index); |
/*printf("grade=%d, index=%d\n",grade,index); |
outputGradedPolySet(g,0);*/ |
outputGradedPolySet(g,0);*/ |
return(g); |
return(g); |
} |
} |
|
|
void markRedundant(g,fi,grade,index,sugar) |
void markRedundant(g,fi,grade,index,sugar) |
struct gradedPolySet *g; |
struct gradedPolySet *g; |
POLY fi; |
POLY fi; |
int grade,index; |
int grade,index; |
int sugar; |
int sugar; |
{ |
{ |
int i,j; |
int i,j; |
struct polySet *ps; |
struct polySet *ps; |
|
|
for (j=0; j<ps->size; j++) { |
for (j=0; j<ps->size; j++) { |
if (i == grade && j == index) { |
if (i == grade && j == index) { |
}else if ((*isReducible)(ps->g[j],fi)) { |
}else if ((*isReducible)(ps->g[j],fi)) { |
ps->del[j] = 1; |
if (! ps->gen[j]) ps->del[j] = 1; /*?*/ |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
void markRedundant0(g,grade,index) |
void markRedundant0(g,grade,index) |
struct gradedPolySet *g; |
struct gradedPolySet *g; |
int grade,index; |
int grade,index; |
{ |
{ |
int i,j; |
int i,j; |
struct polySet *ps; |
struct polySet *ps; |
Line 313 int grade,index; |
|
Line 322 int grade,index; |
|
for (j=0; j<ps->size; j++) { |
for (j=0; j<ps->size; j++) { |
if (i == grade && j == index) { |
if (i == grade && j == index) { |
}else if ((*isReducible)(ps->g[j],fi)) { |
}else if ((*isReducible)(ps->g[j],fi)) { |
ps->del[j] = 1; |
if (! ps->gen[j] ) ps->del[j] = 1; /*?*/ |
}else if ((*isReducible)(fi,ps->g[j])) { |
}else if ((*isReducible)(fi,ps->g[j])) { |
g->polys[grade]->del[index] = 1; |
if (! g->polys[grade]->gen[index] ) g->polys[grade]->del[index] = 1; /*?*/ |
return; |
return; |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
struct gradedPairs *putPairInGradedPairs(struct gradedPairs *grP, |
struct gradedPairs *putPairInGradedPairs(struct gradedPairs *grP, |
struct pair *top) |
struct pair *top) |
{ |
{ |
if (grP == (struct gradedPairs *)NULL) { |
if (grP == (struct gradedPairs *)NULL) { |
grP = newGradedPairs(top->grade +1); |
grP = newGradedPairs(top->grade +1); |
Line 337 struct gradedPairs *putPairInGradedPairs(struct graded |
|
Line 346 struct gradedPairs *putPairInGradedPairs(struct graded |
|
} |
} |
|
|
void errorGradedSet(s) |
void errorGradedSet(s) |
char *s; |
char *s; |
{ |
{ |
fprintf(stderr,"Error in gradedset.c, red.c, gb.c: %s\n",s); |
fprintf(stderr,"Error in gradedset.c, red.c, gb.c: %s\n",s); |
exit(23); |
exit(23); |
} |
} |
|
|
void warningGradedSet(s) |
void warningGradedSet(s) |
char *s; |
char *s; |
{ |
{ |
fprintf(stderr,"Warning in gradedset.c, red.c, gb.c: %s\n",s); |
fprintf(stderr,"Warning in gradedset.c, red.c, gb.c: %s\n",s); |
} |
} |
|
|
|
|
void outputGradedPolySet(grG,needSyz) |
void outputGradedPolySet(grG,needSyz) |
struct gradedPolySet *grG; |
struct gradedPolySet *grG; |
int needSyz; |
int needSyz; |
{ |
{ |
int i,j; |
int i,j; |
struct polySet *set; |
struct polySet *set; |
|
extern Ecart; |
printf("======== gradedPolySet ==========\n"); |
printf("======== gradedPolySet ==========\n"); |
printf("maxGrade=%d\n",grG->maxGrade); |
printf("maxGrade=%d\n",grG->maxGrade); |
for (i=0; i<grG->maxGrade; i++) { |
for (i=0; i<grG->maxGrade; i++) { |
|
|
printf("grade=%d, size=%d\n",i,set->size); |
printf("grade=%d, size=%d\n",i,set->size); |
for (j=0; j<set->size; j++) { |
for (j=0; j<set->size; j++) { |
printf("j=%d, del=%d, g=%s\n",j,set->del[j],POLYToString(set->g[j],'*',1)); |
printf("j=%d, del=%d, g=%s\n",j,set->del[j],POLYToString(set->g[j],'*',1)); |
|
if (Ecart) printf(" gh=%s\n",POLYToString(set->gh[j],'*',1)); |
if (needSyz) { |
if (needSyz) { |
printf("mark=%d,serial=%d, syz.cf=%s, syz.syz=%s\n",set->mark[j], |
printf("mark=%d,serial=%d, syz.cf=%s, syz.syz=%s\n",set->mark[j], |
set->serial[j],POLYToString(set->syz[j]->cf,'*',1), |
set->serial[j],POLYToString(set->syz[j]->cf,'*',1), |
POLYToString(set->syz[j]->syz,'*',1)); |
POLYToString(set->syz[j]->syz,'*',1)); |
}else{ |
}else{ |
printf("mark=%d,serial=%d\n",set->mark[j], |
printf("mark=%d,serial=%d\n",set->mark[j], |
set->serial[j]); |
set->serial[j]); |
} |
} |
} |
} |
} |
} |
|
|
} |
} |
|
|
int countGradedPolySet(grG) |
int countGradedPolySet(grG) |
struct gradedPolySet *grG; |
struct gradedPolySet *grG; |
{ |
{ |
int i,j; |
int i,j; |
struct polySet *set; |
struct polySet *set; |
Line 391 struct gradedPolySet *grG; |
|
Line 402 struct gradedPolySet *grG; |
|
|
|
|
|
void outputGradedPairs(grP) |
void outputGradedPairs(grP) |
struct gradedPairs *grP; |
struct gradedPairs *grP; |
{ |
{ |
int i,j; |
int i,j; |
struct pair *pair; |
struct pair *pair; |
Line 411 struct gradedPairs *grP; |
|
Line 422 struct gradedPairs *grP; |
|
} |
} |
|
|
void outputNode(pair) |
void outputNode(pair) |
struct pair *pair; |
struct pair *pair; |
{ |
{ |
int i = 0; |
int i = 0; |
printf("=== list === \n"); |
printf("=== list === \n"); |
Line 431 struct pair *pair; |
|
Line 442 struct pair *pair; |
|
|
|
|
|
int countPairs(grD) |
int countPairs(grD) |
struct gradedPairs *grD; |
struct gradedPairs *grD; |
{ |
{ |
int i; |
int i; |
int c; |
int c; |
Line 449 struct gradedPairs *grD; |
|
Line 460 struct gradedPairs *grD; |
|
} |
} |
|
|
struct gradedPolySet *gradedPolySetCopy(grG) |
struct gradedPolySet *gradedPolySetCopy(grG) |
struct gradedPolySet *grG; |
struct gradedPolySet *grG; |
{ |
{ |
int i,j; |
int i,j; |
struct polySet *ps,*psOld; |
struct polySet *ps,*psOld; |
Line 473 struct gradedPolySet *grG; |
|
Line 484 struct gradedPolySet *grG; |
|
} |
} |
|
|
int deletePairByCriterion2B(struct gradedPairs *grD,POLY gt, |
int deletePairByCriterion2B(struct gradedPairs *grD,POLY gt, |
struct gradedPolySet *grG) |
struct gradedPolySet *grG) |
{ |
{ |
int gmax,i; |
int gmax,i; |
struct pair *node; |
struct pair *node; |
Line 488 int deletePairByCriterion2B(struct gradedPairs *grD,PO |
|
Line 499 int deletePairByCriterion2B(struct gradedPairs *grD,PO |
|
if ((grD->pairs[i])->next != (struct pair *)NULL) { |
if ((grD->pairs[i])->next != (struct pair *)NULL) { |
node = grD->pairs[i]->next; |
node = grD->pairs[i]->next; |
while (node != (struct pair *)NULL) { |
while (node != (struct pair *)NULL) { |
ig = node->ig; ii = node->ii; |
ig = node->ig; ii = node->ii; |
jg = node->jg; ji = node->ji; |
jg = node->jg; ji = node->ji; |
if ((*isReducible)(node->lcm,gt)) { |
if ((*isReducible)(node->lcm,gt)) { |
ig = node->ig; ii = node->ii; |
ig = node->ig; ii = node->ii; |
jg = node->jg; ji = node->ji; |
jg = node->jg; ji = node->ji; |
it = (*lcm)(grG->polys[ig]->g[ii],gt); |
it = (*lcm)(grG->polys[ig]->g[ii],gt); |
ij = (*lcm)(grG->polys[ig]->g[ii],grG->polys[jg]->g[ji]); |
ij = (*lcm)(grG->polys[ig]->g[ii],grG->polys[jg]->g[ji]); |
jt = (*lcm)(grG->polys[jg]->g[ji],gt); |
jt = (*lcm)(grG->polys[jg]->g[ji],gt); |
if ((*mmLarger)(it,ij) != 2 && |
if ((*mmLarger)(it,ij) != 2 && |
(*mmLarger)(it,jt) != 2 && |
(*mmLarger)(it,jt) != 2 && |
(*mmLarger)(ij,jt) != 2) { |
(*mmLarger)(ij,jt) != 2) { |
node = deletePair(node->prev); |
node = deletePair(node->prev); |
count++; |
count++; |
} |
} |
} |
} |
node = node->next; |
node = node->next; |
} |
} |
} |
} |
} |
} |
return(count); |
return(count); |
|
} |
|
|
|
int markGeneratorInG(struct gradedPolySet *g,int grade,int index) |
|
{ |
|
g->polys[grade]->gen[index] = 1; |
|
return 1; |
} |
} |