version 1.1, 1999/10/08 02:12:02 |
version 1.6, 2005/07/03 11:08:53 |
|
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/gbGM.c,v 1.5 2005/06/16 06:54:55 takayama Exp $ */ |
/* gbGM.c GM=Gebauer and Moller |
/* gbGM.c GM=Gebauer and Moller |
*/ |
*/ |
|
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
#include "matrix.h" |
#include "matrix.h" |
Line 41 struct polySet_gm enlargePolySet_gm(struct polySet_gm |
|
Line 43 struct polySet_gm enlargePolySet_gm(struct polySet_gm |
|
struct pairSet deletePair_gm(struct pairSet d,int index); |
struct pairSet deletePair_gm(struct pairSet d,int index); |
int minPair_gm(struct pairSet d); |
int minPair_gm(struct pairSet d); |
struct pairSet updatePair_gm(struct pairSet d,int t, |
struct pairSet updatePair_gm(struct pairSet d,int t, |
struct polySet_gm g,POLY gt); |
struct polySet_gm g,POLY gt); |
struct polySet_gm markRedundant_gm(struct polySet_gm g,int j); |
struct polySet_gm markRedundant_gm(struct polySet_gm g,int j); |
/* |
/* |
struct gradedPolySet *groebner_gm(struct arrayOfPOLY f, |
struct gradedPolySet *groebner_gm(struct arrayOfPOLY f, |
int needBack, |
int needBack, |
int needSyz, struct pair **grP); |
int needSyz, struct pair **grP); |
*/ |
*/ |
void outputPairSet(struct pairSet d); |
void outputPairSet(struct pairSet d); |
void outputPolySet_gm(struct polySet_gm g); |
void outputPolySet_gm(struct polySet_gm g); |
Line 70 int CountI[2*N0]; |
|
Line 72 int CountI[2*N0]; |
|
#endif |
#endif |
|
|
struct polySet_gm newPolySet_gm(n) |
struct polySet_gm newPolySet_gm(n) |
int n; |
int n; |
{ |
{ |
struct polySet_gm g; |
struct polySet_gm g; |
int i; |
int i; |
|
|
} |
} |
|
|
struct pairSet newPairSet(n) |
struct pairSet newPairSet(n) |
int n; |
int n; |
{ |
{ |
struct pairSet g; |
struct pairSet g; |
int i; |
int i; |
|
|
} |
} |
|
|
int pairSetSize(d) |
int pairSetSize(d) |
struct pairSet d; |
struct pairSet d; |
{ |
{ |
int s,i; |
int s,i; |
s = 0; |
s = 0; |
Line 113 struct pairSet d; |
|
Line 115 struct pairSet d; |
|
} |
} |
|
|
struct pairSet pairSetJoin(a,b) |
struct pairSet pairSetJoin(a,b) |
struct pairSet a,b; |
struct pairSet a,b; |
{ |
{ |
int m,n,k,i; |
int m,n,k,i; |
struct pairSet ans; |
struct pairSet ans; |
Line 137 struct pairSet a,b; |
|
Line 139 struct pairSet a,b; |
|
} |
} |
|
|
struct polySet_gm enlargePolySet_gm(g) |
struct polySet_gm enlargePolySet_gm(g) |
struct polySet_gm g; |
struct polySet_gm g; |
{ |
{ |
int i; |
int i; |
struct polySet_gm ans; |
struct polySet_gm ans; |
Line 153 struct polySet_gm g; |
|
Line 155 struct polySet_gm g; |
|
} |
} |
|
|
struct pairSet deletePair_gm(d,index) |
struct pairSet deletePair_gm(d,index) |
struct pairSet d; |
struct pairSet d; |
int index; |
int index; |
/* delete d[index] */ |
/* delete d[index] */ |
{ |
{ |
int i; |
int i; |
d.del[index] = 0; |
d.del[index] = 0; |
|
|
} |
} |
|
|
int minPair_gm(d) |
int minPair_gm(d) |
struct pairSet d; |
struct pairSet d; |
{ |
{ |
POLY min; |
POLY min; |
int index,i; |
int index,i; |
Line 183 struct pairSet d; |
|
Line 185 struct pairSet d; |
|
} |
} |
|
|
struct pairSet updatePair_gm(d,t,g,gt) |
struct pairSet updatePair_gm(d,t,g,gt) |
struct pairSet d; |
struct pairSet d; |
int t; |
int t; |
struct polySet_gm g; |
struct polySet_gm g; |
POLY gt; |
POLY gt; |
{ |
{ |
int i,j,k; |
int i,j,k; |
struct pairSet new; |
struct pairSet new; |
|
|
} |
} |
#ifdef DEBUG |
#ifdef DEBUG |
/*printf("\nnew is ..."); |
/*printf("\nnew is ..."); |
outputPairSet(new);*/ |
outputPairSet(new);*/ |
#endif |
#endif |
|
|
/* Candel in D=d all (i,j) such that B_t(i,j) */ |
/* Candel in D=d all (i,j) such that B_t(i,j) */ |
|
|
/* check T(it) != T(i,j) != T(j,t) */ |
/* check T(it) != T(i,j) != T(j,t) */ |
i = d.p[k].i; j = d.p[k].j; |
i = d.p[k].i; j = d.p[k].j; |
if ((new.del[i] == 1) || (new.del[j] == 1)) { |
if ((new.del[i] == 1) || (new.del[j] == 1)) { |
/* fprintf(stderr,"Warning in updatepair_gm(): i=%d, j=%d; rewriting new.\n",i,j); */ |
/* fprintf(stderr,"Warning in updatepair_gm(): i=%d, j=%d; rewriting new.\n",i,j); */ |
if (new.del[i] == 1) { |
if (new.del[i] == 1) { |
new.p[i].lcm = (*lcm)(g.g[i],gt); |
new.p[i].lcm = (*lcm)(g.g[i],gt); |
} |
} |
if (new.del[j] == 1) { |
if (new.del[j] == 1) { |
new.p[j].lcm = (*lcm)(g.g[j],gt); |
new.p[j].lcm = (*lcm)(g.g[j],gt); |
} |
} |
} |
} |
if (((*mmLarger)((new.p[i].lcm),(new.p[j].lcm)) != 2) && |
if (((*mmLarger)((new.p[i].lcm),(new.p[j].lcm)) != 2) && |
((*mmLarger)((new.p[i].lcm),(d.p[k].lcm)) != 2) && |
((*mmLarger)((new.p[i].lcm),(d.p[k].lcm)) != 2) && |
((*mmLarger)((new.p[j].lcm),(d.p[k].lcm)) != 2)) { |
((*mmLarger)((new.p[j].lcm),(d.p[k].lcm)) != 2)) { |
/* delete T(i,j) in d */ |
/* delete T(i,j) in d */ |
d.del[k] = 1; |
d.del[k] = 1; |
if (Verbose >= 2) printf("B%d(%d,%d) ",t,i,j); |
if (Verbose >= 2) printf("B%d(%d,%d) ",t,i,j); |
Criterion2B++; |
Criterion2B++; |
} |
} |
} |
} |
} |
} |
|
|
for (i=0; i<g.size; i++) { |
for (i=0; i<g.size; i++) { |
for (j=i+1; j<g.size; j++) { |
for (j=i+1; j<g.size; j++) { |
if ((g.del[i] == 0) && (g.del[j] == 0)) { |
if ((g.del[i] == 0) && (g.del[j] == 0)) { |
it = new.p[i].lcm; |
it = new.p[i].lcm; |
jt = new.p[j].lcm; |
jt = new.p[j].lcm; |
switch ( (*mmLarger)(it,jt)) { |
switch ( (*mmLarger)(it,jt)) { |
case 2: |
case 2: |
/* F(j,t), i<j */ |
/* F(j,t), i<j */ |
new.del[j] = 1; |
new.del[j] = 1; |
if (Verbose >= 2) printf("F%d(%d,%d) ",i,j,t); |
if (Verbose >= 2) printf("F%d(%d,%d) ",i,j,t); |
Criterion2F++; |
Criterion2F++; |
break; |
break; |
case 1: |
case 1: |
/* g[i] > g[j], M(i,t) */ |
/* g[i] > g[j], M(i,t) */ |
if ((*isReducible)(it,jt)) { |
if ((*isReducible)(it,jt)) { |
new.del[i] = 1; |
new.del[i] = 1; |
if (Verbose >=2) printf("M%d(%d,%d) ",j,i,t); |
if (Verbose >=2) printf("M%d(%d,%d) ",j,i,t); |
Criterion2M++; |
Criterion2M++; |
} |
} |
break; |
break; |
case 0: /* M(j,t) */ |
case 0: /* M(j,t) */ |
if ((*isReducible)(jt,it)) { |
if ((*isReducible)(jt,it)) { |
new.del[j] = 1; |
new.del[j] = 1; |
if (Verbose >=2) printf("M%d(%d,%d) ",i,j,t); |
if (Verbose >=2) printf("M%d(%d,%d) ",i,j,t); |
Criterion2M++; |
Criterion2M++; |
} |
} |
break; |
break; |
|
|
} |
} |
} |
} |
} |
} |
} |
} |
|
|
if (UseCriterion1) { |
if (UseCriterion1) { |
for (i=0; i<g.size; i++) { |
for (i=0; i<g.size; i++) { |
if (new.del[i] == 0) { |
if (new.del[i] == 0) { |
if (criterion1(g.g[i],gt,new.p[i].lcm)) { |
if (criterion1(g.g[i],gt,new.p[i].lcm)) { |
new.del[i] = 1; |
new.del[i] = 1; |
if (Verbose >=2) printf("1(%d,%d) ",i,t); |
if (Verbose >=2) printf("1(%d,%d) ",i,t); |
Criterion1++; |
Criterion1++; |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
|
|
|
|
struct polySet_gm markRedundant_gm(g,j) |
struct polySet_gm markRedundant_gm(g,j) |
struct polySet_gm g; |
struct polySet_gm g; |
int j; |
int j; |
/* compare only with g[j] */ |
/* compare only with g[j] */ |
{ |
{ |
int i; |
int i; |
for (i=0; i<g.size; i++) { |
for (i=0; i<g.size; i++) { |
if ((g.del[i] == 0) && (i != j)) { |
if ((g.del[i] == 0) && (i != j)) { |
if (g.del[j] == 0) { |
if (g.del[j] == 0) { |
switch((*mmLarger)((g.g[i]),(g.g[j]))) { |
switch((*mmLarger)((g.g[i]),(g.g[j]))) { |
case 2: |
case 2: |
g.del[j] = 1; |
g.del[j] = 1; |
break; |
break; |
case 1: |
case 1: |
if ((*isReducible)((g.g[i]),(g.g[j]))) { |
if ((*isReducible)((g.g[i]),(g.g[j]))) { |
g.del[i] = 1; |
g.del[i] = 1; |
} |
} |
break; |
break; |
case 0: |
case 0: |
if ((*isReducible)((g.g[j]),(g.g[i]))) { |
if ((*isReducible)((g.g[j]),(g.g[i]))) { |
g.del[j] = 1; |
g.del[j] = 1; |
} |
} |
break; |
break; |
} |
} |
} |
} |
} |
} |
} |
} |
#ifdef DEBUG |
#ifdef DEBUG |
/*printf("\nend of markRedundant_gm..."); |
/*printf("\nend of markRedundant_gm..."); |
outputPolySet_gm(g);*/ |
outputPolySet_gm(g);*/ |
#endif |
#endif |
return(enlargePolySet_gm(g)); |
return(enlargePolySet_gm(g)); |
} |
} |
|
|
|
|
|
|
struct gradedPolySet *groebner_gm(f,needBack,needSyz,grP,countDown,forceReduction) |
struct gradedPolySet *groebner_gm(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; |
struct pair **grP; |
int countDown; |
int countDown; |
int forceReduction; |
int forceReduction; |
|
int reduceOnly; |
|
int gbCheck; |
{ |
{ |
int r; |
int r; |
struct pair_gm top; |
struct pair_gm top; |
Line 364 int forceReduction; |
|
Line 368 int forceReduction; |
|
if (needBack || needSyz) { |
if (needBack || needSyz) { |
fprintf(stderr,"Warning: groebner_gm() does not compute the backward transformation and syzygies.\n"); |
fprintf(stderr,"Warning: groebner_gm() does not compute the backward transformation and syzygies.\n"); |
} |
} |
|
if (reduceOnly || gbCheck) { |
|
fprintf(stderr,"Warning: groebner_gm() does not implement reduceOnly/gbCheck.\n"); |
|
} |
|
|
#ifdef STATISTICS |
#ifdef STATISTICS |
CountE = 0; |
CountE = 0; |
Line 413 int forceReduction; |
|
Line 420 int forceReduction; |
|
|
|
if (!(h ISZERO)) { |
if (!(h ISZERO)) { |
if (ReduceLowerTerms) { |
if (ReduceLowerTerms) { |
h = mReductionCdrBySet(h,g.g,g.size); |
h = mReductionCdrBySet(h,g.g,g.size); |
} |
} |
d = updatePair_gm(d,r,g,h); |
d = updatePair_gm(d,r,g,h); |
g.g[r] = h; g.del[r] = 0; |
g.g[r] = h; g.del[r] = 0; |
Line 442 int forceReduction; |
|
Line 449 int forceReduction; |
|
#endif |
#endif |
|
|
ans = newGradedPolySet(1); |
ans = newGradedPolySet(1); |
|
ans->gb = 1; |
for (i=0; i<ans->lim; i++) { |
for (i=0; i<ans->lim; i++) { |
ans->polys[i] = newPolySet(1); |
ans->polys[i] = newPolySet(1); |
} |
} |
Line 459 int forceReduction; |
|
Line 467 int forceReduction; |
|
|
|
|
|
void outputPairSet(d) |
void outputPairSet(d) |
struct pairSet d; |
struct pairSet d; |
{ int i; |
{ int i; |
printf("\nOutput struct pairSet. "); |
printf("\nOutput struct pairSet. "); |
printf(".size=%d, .lim=%d :\n",d.size,d.lim); |
printf(".size=%d, .lim=%d :\n",d.size,d.lim); |
for (i=0; i<d.size; i++) { |
for (i=0; i<d.size; i++) { |
printf("%d[%d] i=%d,j=%d, lcm=%s ",i,d.del[i],d.p[i].i,d.p[i].j, |
printf("%d[%d] i=%d,j=%d, lcm=%s ",i,d.del[i],d.p[i].i,d.p[i].j, |
POLYToString(d.p[i].lcm,' ',0)); |
POLYToString(d.p[i].lcm,' ',0)); |
} |
} |
printf("\n"); fflush(stdout); |
printf("\n"); fflush(stdout); |
} |
} |
|
|
void outputPolySet_gm(g) |
void outputPolySet_gm(g) |
struct polySet_gm g; |
struct polySet_gm g; |
{ int i; |
{ int i; |
printf("\nOutput struct polySet_gm. "); |
printf("\nOutput struct polySet_gm. "); |
printf(".size=%d, .lim=%d :\n",g.size,g.lim); |
printf(".size=%d, .lim=%d :\n",g.size,g.lim); |
for (i=0; i<g.size; i++) { |
for (i=0; i<g.size; i++) { |
printf("%d[%d] %s\n",i,g.del[i],POLYToString(g.g[i],' ',0)); |
printf("%d[%d] %s\n",i,g.del[i],POLYToString(g.g[i],' ',0)); |
} |
} |
printf("\n"); fflush(stdout); |
printf("\n"); fflush(stdout); |
} |
} |
|
|
int criterion1(f0,g0,lc0) |
int criterion1(f0,g0,lc0) |
POLY f0; |
POLY f0; |
POLY g0; |
POLY g0; |
POLY lc0; |
POLY lc0; |
{ |
{ |
/* This is used only for commutative case. */ |
/* This is used only for commutative case. */ |
register int i; |
register int i; |
|
|
|
|
|
|
POLY mReductionBySet(f,s,size) |
POLY mReductionBySet(f,s,size) |
POLY f; |
POLY f; |
POLY *s; |
POLY *s; |
int size; |
int size; |
{ |
{ |
int reduced1; |
int reduced1; |
int i; |
int i; |
|
|
for (i=0; i<size; i++) { |
for (i=0; i<size; i++) { |
if (f ISZERO) goto ss; |
if (f ISZERO) goto ss; |
if ((*isReducible)(f,s[i])) { |
if ((*isReducible)(f,s[i])) { |
f = (*reduction1)(f,s[i],0,&cc,&cg); |
f = (*reduction1)(f,s[i],0,&cc,&cg); |
reduced1 = 1; |
reduced1 = 1; |
} |
} |
} |
} |
} while (reduced1 != 0); |
} while (reduced1 != 0); |
|
|
} |
} |
|
|
POLY mReductionCdrBySet(f,s,size) |
POLY mReductionCdrBySet(f,s,size) |
POLY f; |
POLY f; |
POLY *s; |
POLY *s; |
int size; |
int size; |
{ |
{ |
int reduced1; |
int reduced1; |
int i; |
int i; |
|
|
for (i=0; i<size; i++) { |
for (i=0; i<size; i++) { |
if (f ISZERO) goto ss; |
if (f ISZERO) goto ss; |
if ((fs=(*isCdrReducible)(f,s[i])) != ZERO) { |
if ((fs=(*isCdrReducible)(f,s[i])) != ZERO) { |
f = (*reduction1Cdr)(f,fs,s[i],0,&cc,&cg); |
f = (*reduction1Cdr)(f,fs,s[i],0,&cc,&cg); |
reduced1 = 1; |
reduced1 = 1; |
} |
} |
} |
} |
} while (reduced1 != 0); |
} while (reduced1 != 0); |
|
|
|
|
|
|
void errorGBGM(s) |
void errorGBGM(s) |
char *s; |
char *s; |
{ |
{ |
fprintf(stderr,"Fatal error in yaGbasis.c: %s \n",s); |
fprintf(stderr,"Fatal error in yaGbasis.c: %s \n",s); |
exit(10); |
exit(10); |