version 1.3, 2000/02/24 00:27:12 |
version 1.6, 2003/08/21 02:30:23 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/red.c,v 1.2 2000/01/16 07:55:41 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/red.c,v 1.5 2003/07/30 09:00:52 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
|
|
#define mymax(p,q) (p>q?p:q) |
#define mymax(p,q) (p>q?p:q) |
|
|
int DebugReductionRed = 0; |
int DebugReductionRed = 0; |
|
int DebugContentReduction = 0; |
extern int Sugar; |
extern int Sugar; |
|
|
struct spValue sp_gen(f,g) |
struct spValue sp_gen(f,g) |
POLY f; |
POLY f; |
POLY g; |
POLY g; |
/* the results may be rewritten. */ |
/* the results may be rewritten. */ |
{ |
{ |
struct spValue r; |
struct spValue r; |
POLY a; |
POLY a; |
|
|
if (ell-c > 0) { /* q-case */ |
if (ell-c > 0) { /* q-case */ |
amodify = 0; |
amodify = 0; |
for (i=c; i<ell; i++) { |
for (i=c; i<ell; i++) { |
amodify += (tb->e[i].D)*(tg->e[i].x); |
amodify += (tb->e[i].D)*(tg->e[i].x); |
} |
} |
bmodify = 0; |
bmodify = 0; |
for (i=c; i<ell; i++) { |
for (i=c; i<ell; i++) { |
bmodify += (ta->e[i].D)*(tf->e[i].x); |
bmodify += (ta->e[i].D)*(tf->e[i].x); |
} |
} |
if (amodify > bmodify) { |
if (amodify > bmodify) { |
amodify = amodify-bmodify; |
amodify = amodify-bmodify; |
bmodify = 0; |
bmodify = 0; |
}else{ |
}else{ |
bmodify = bmodify - amodify; |
bmodify = bmodify - amodify; |
amodify = 0; |
amodify = 0; |
} |
} |
} |
} |
if (amodify) { |
if (amodify) { |
|
|
|
|
|
|
POLY reduction1_gen_debug(f,g,needSyz,c,h) |
POLY reduction1_gen_debug(f,g,needSyz,c,h) |
POLY f; |
POLY f; |
POLY g; |
POLY g; |
int needSyz; |
int needSyz; |
POLY *c; /* set */ |
POLY *c; /* set */ |
POLY *h; /* set */ |
POLY *h; /* set */ |
/* f must be reducible by g. r = c*f + h*g */ |
/* f must be reducible by g. r = c*f + h*g */ |
{ |
{ |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
struct ring *rp; |
struct ring *rp; |
Line 147 POLY *h; /* set */ |
|
Line 148 POLY *h; /* set */ |
|
printf("error in reduction1."); |
printf("error in reduction1."); |
printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1), |
printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1), |
POLYToString(sv.b,'*',1),POLYToString(g,'*',1)); |
POLYToString(sv.b,'*',1),POLYToString(g,'*',1)); |
getchar(); |
getchar(); |
getchar(); |
getchar(); |
} |
} |
Line 171 POLY *h; /* set */ |
|
Line 172 POLY *h; /* set */ |
|
if (!isOrdered(f)) { |
if (!isOrdered(f)) { |
printf("\nf is not ordered polynomial."); |
printf("\nf is not ordered polynomial."); |
}else if (!isOrdered(f)) { |
}else if (!isOrdered(f)) { |
printf("\nf2 is not ordered polynomial."); |
printf("\nf2 is not ordered polynomial."); |
} |
} |
printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
printf("f=%s,\nf2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
getchar(); |
getchar(); |
Line 182 POLY *h; /* set */ |
|
Line 183 POLY *h; /* set */ |
|
printf("error in reduction1."); |
printf("error in reduction1."); |
printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
printf("f=%s --> f2=%s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1), |
printf("f2 = (%s)*f+(%s)*(%s)\n",POLYToString(sv.a,'*',1), |
POLYToString(sv.b,'*',1), |
POLYToString(sv.b,'*',1), |
POLYToString(g,'*',1)); |
POLYToString(g,'*',1)); |
getchar(); |
getchar(); |
getchar(); |
getchar(); |
} |
} |
Line 197 POLY *h; /* set */ |
|
Line 198 POLY *h; /* set */ |
|
} |
} |
|
|
POLY reduction1_gen(f,g,needSyz,c,h) |
POLY reduction1_gen(f,g,needSyz,c,h) |
POLY f; |
POLY f; |
POLY g; |
POLY g; |
int needSyz; |
int needSyz; |
POLY *c; /* set */ |
POLY *c; /* set */ |
POLY *h; /* set */ |
POLY *h; /* set */ |
/* f must be reducible by g. r = c*f + h*g */ |
/* f must be reducible by g. r = c*f + h*g */ |
{ |
{ |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
struct ring *rp; |
struct ring *rp; |
Line 220 POLY *h; /* set */ |
|
Line 221 POLY *h; /* set */ |
|
f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g)); |
f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g)); |
if (DebugReductionRed) { |
if (DebugReductionRed) { |
printf("c=%s, d=%s, g=%s: f --> c*f + d*g.\n", |
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)); |
printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
} |
} |
f = f2; |
f = f2; |
Line 234 POLY *h; /* set */ |
|
Line 235 POLY *h; /* set */ |
|
f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g)); |
f2 = ppAddv(cpMult((sv.a)->coeffp,f),ppMult(sv.b,g)); |
if (DebugReductionRed) { |
if (DebugReductionRed) { |
printf("! c=%s, d=%s, g=%s: f --> c*f + d*g.\n", |
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)); |
printf("%s --> %s\n",POLYToString(f,'*',1),POLYToString(f2,'*',1)); |
} |
} |
f = f2; |
f = f2; |
Line 247 POLY *h; /* set */ |
|
Line 248 POLY *h; /* set */ |
|
} |
} |
|
|
POLY reduction1Cdr_gen(f,fs,g,needSyz,c,h) |
POLY reduction1Cdr_gen(f,fs,g,needSyz,c,h) |
POLY f; |
POLY f; |
POLY fs; |
POLY fs; |
POLY g; |
POLY g; |
int needSyz; |
int needSyz; |
POLY *c; /* set */ |
POLY *c; /* set */ |
POLY *h; /* set */ |
POLY *h; /* set */ |
/* f must be reducible by g. r = c*f + h*g */ |
/* f must be reducible by g. r = c*f + h*g */ |
{ |
{ |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
struct ring *rp; |
struct ring *rp; |
Line 297 POLY *h; /* set */ |
|
Line 298 POLY *h; /* set */ |
|
|
|
/* for debug */ |
/* for debug */ |
int isOrdered(f) |
int isOrdered(f) |
POLY f; |
POLY f; |
{ POLY g; |
{ POLY g; |
if (f ISZERO) return(1); |
if (f ISZERO) return(1); |
g = f->next; |
g = f->next; |
while (g != POLYNULL) { |
while (g != POLYNULL) { |
if ((*mmLarger)(g,f)>=1) return(0); |
if ((*mmLarger)(g,f)>=1) return(0); |
f = g; |
f = g; |
g = f->next; |
g = f->next; |
} |
} |
return(1); |
return(1); |
} |
} |
|
|
|
|
POLY reduction_gen(f,gset,needSyz,syzp) |
POLY reduction_gen(f,gset,needSyz,syzp) |
POLY f; |
POLY f; |
struct gradedPolySet *gset; |
struct gradedPolySet *gset; |
int needSyz; |
int needSyz; |
struct syz0 *syzp; /* set */ |
struct syz0 *syzp; /* set */ |
{ |
{ |
int reduced,reduced1,reduced2; |
int reduced,reduced1,reduced2; |
int grd; |
int grd; |
Line 325 struct syz0 *syzp; /* set */ |
|
Line 326 struct syz0 *syzp; /* set */ |
|
|
|
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
struct ring *rp; |
struct ring *rp; |
|
extern DoCancel; |
|
|
if (needSyz) { |
if (needSyz) { |
if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; } |
if (f ISZERO) { rp = CurrentRingp; } else { rp = f->m->ringp; } |
cf = cxx(1,0,0,rp); |
cf = cxx(1,0,0,rp); |
syz = ZERO; |
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 */ |
reduced = 0; /* no */ |
do { |
do { |
Line 338 struct syz0 *syzp; /* set */ |
|
Line 345 struct syz0 *syzp; /* set */ |
|
grd = 0; |
grd = 0; |
while (grd < gset->maxGrade) { |
while (grd < gset->maxGrade) { |
if (!Sugar) { |
if (!Sugar) { |
if (grd > (*grade)(f)) break; |
if (grd > (*grade)(f)) break; |
} |
} |
set = gset->polys[grd]; |
set = gset->polys[grd]; |
do { |
do { |
reduced2 = 0; /* no */ |
reduced2 = 0; /* no */ |
for (i=0; i<set->size; i++) { |
for (i=0; i<set->size; i++) { |
if (f ISZERO) goto ss; |
if (f ISZERO) goto ss; |
if ((*isReducible)(f,set->g[i])) { |
if ((*isReducible)(f,set->g[i])) { |
f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg); |
f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg); |
if (needSyz) { |
|
cf = ppMult(cc,cf); |
if (DoCancel && (f != POLYNULL)) { |
syz = cpMult(toSyzCoeff(cc),syz); |
if (shouldReduceContent(f,0)) { |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
struct coeff *cont; |
} |
f = reduceContentOfPoly(f,&cont); |
reduced = reduced1 = reduced2 = 1; /* yes */ |
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); |
} while (reduced2 != 0); |
grd++; |
grd++; |
} |
} |
}while (reduced1 != 0); |
}while (reduced1 != 0); |
|
|
ss: ; |
ss: ; |
if (needSyz) { |
if (needSyz) { |
syzp->cf = cf; /* cf is in the CurrentRingp */ |
syzp->cf = cf; /* cf is in the CurrentRingp */ |
syzp->syz = syz; /* syz is in the SyzRingp */ |
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); |
return(f); |
} |
} |
|
|
POLY reduction_gen_rev(f,gset,needSyz,syzp) |
POLY reduction_gen_rev(f,gset,needSyz,syzp) |
POLY f; |
POLY f; |
struct gradedPolySet *gset; |
struct gradedPolySet *gset; |
int needSyz; |
int needSyz; |
struct syz0 *syzp; /* set */ |
struct syz0 *syzp; /* set */ |
{ |
{ |
int reduced,reduced1,reduced2; |
int reduced,reduced1,reduced2; |
int grd; |
int grd; |
Line 397 struct syz0 *syzp; /* set */ |
|
Line 423 struct syz0 *syzp; /* set */ |
|
while (grd >= 0) { /* reverse order for reduction */ |
while (grd >= 0) { /* reverse order for reduction */ |
set = gset->polys[grd]; |
set = gset->polys[grd]; |
do { |
do { |
reduced2 = 0; /* no */ |
reduced2 = 0; /* no */ |
for (i=0; i<set->size; i++) { |
for (i=0; i<set->size; i++) { |
if (f ISZERO) goto ss; |
if (f ISZERO) goto ss; |
if ((*isReducible)(f,set->g[i])) { |
if ((*isReducible)(f,set->g[i])) { |
f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg); |
f = (*reduction1)(f,set->g[i],needSyz,&cc,&cg); |
if (needSyz) { |
if (needSyz) { |
cf = ppMult(cc,cf); |
cf = ppMult(cc,cf); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
} |
} |
reduced = reduced1 = reduced2 = 1; /* yes */ |
reduced = reduced1 = reduced2 = 1; /* yes */ |
} |
} |
} |
} |
} while (reduced2 != 0); |
} while (reduced2 != 0); |
grd--; |
grd--; |
} |
} |
}while (reduced1 != 0); |
}while (reduced1 != 0); |
|
|
ss: ; |
ss: ; |
if (needSyz) { |
if (needSyz) { |
syzp->cf = cf; /* cf is in the CurrentRingp */ |
syzp->cf = cf; /* cf is in the CurrentRingp */ |
syzp->syz = syz; /* syz is in the SyzRingp */ |
syzp->syz = syz; /* syz is in the SyzRingp */ |
Line 424 struct syz0 *syzp; /* set */ |
|
Line 450 struct syz0 *syzp; /* set */ |
|
} |
} |
|
|
POLY reductionCdr_gen(f,gset,needSyz,syzp) |
POLY reductionCdr_gen(f,gset,needSyz,syzp) |
POLY f; |
POLY f; |
struct gradedPolySet *gset; |
struct gradedPolySet *gset; |
int needSyz; |
int needSyz; |
struct syz0 *syzp; /* set */ |
struct syz0 *syzp; /* set */ |
{ |
{ |
int reduced,reduced1,reduced2; |
int reduced,reduced1,reduced2; |
int grd; |
int grd; |
Line 452 struct syz0 *syzp; /* set */ |
|
Line 478 struct syz0 *syzp; /* set */ |
|
grd = 0; |
grd = 0; |
while (grd < gset->maxGrade) { |
while (grd < gset->maxGrade) { |
if (!Sugar) { |
if (!Sugar) { |
if (grd > (*grade)(f)) break; |
if (grd > (*grade)(f)) break; |
} |
} |
set = gset->polys[grd]; |
set = gset->polys[grd]; |
do { |
do { |
reduced2 = 0; /* no */ |
reduced2 = 0; /* no */ |
for (i=0; i<set->size; i++) { |
for (i=0; i<set->size; i++) { |
if (f ISZERO) goto ss; |
if (f ISZERO) goto ss; |
if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) { |
if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) { |
f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg); |
f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg); |
if (needSyz) { |
if (needSyz) { |
cf = ppMult(cc,cf); |
cf = ppMult(cc,cf); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
} |
} |
reduced = reduced1 = reduced2 = 1; /* yes */ |
reduced = reduced1 = reduced2 = 1; /* yes */ |
} |
} |
} |
} |
} while (reduced2 != 0); |
} while (reduced2 != 0); |
grd++; |
grd++; |
} |
} |
}while (reduced1 != 0); |
}while (reduced1 != 0); |
|
|
ss: ; |
ss: ; |
if (needSyz) { |
if (needSyz) { |
syzp->cf = cf; |
syzp->cf = cf; |
syzp->syz = syz; |
syzp->syz = syz; |
Line 483 struct syz0 *syzp; /* set */ |
|
Line 509 struct syz0 *syzp; /* set */ |
|
} |
} |
|
|
int isReducible_gen(f,g) |
int isReducible_gen(f,g) |
POLY f; |
POLY f; |
POLY g; |
POLY g; |
{ |
{ |
int n,i; |
int n,i; |
MONOMIAL tf; |
MONOMIAL tf; |
|
|
} |
} |
|
|
POLY isCdrReducible_gen(f,g) |
POLY isCdrReducible_gen(f,g) |
POLY f; |
POLY f; |
POLY g; |
POLY g; |
{ |
{ |
while (f != POLYNULL) { |
while (f != POLYNULL) { |
if ((*isReducible)(f,g)) { |
if ((*isReducible)(f,g)) { |
|
|
} |
} |
|
|
POLY lcm_gen(f,g) |
POLY lcm_gen(f,g) |
POLY f; |
POLY f; |
POLY g; |
POLY g; |
{ |
{ |
MONOMIAL tf,tg; |
MONOMIAL tf,tg; |
MONOMIAL lcm; |
MONOMIAL lcm; |
|
|
} |
} |
|
|
int grade_gen(f) |
int grade_gen(f) |
POLY f; |
POLY f; |
{ |
{ |
int r; |
int r; |
int i,n; |
int i,n; |
|
|
|
|
/* constructors */ |
/* constructors */ |
POLY toSyzPoly(cg,grd,index) |
POLY toSyzPoly(cg,grd,index) |
POLY cg; |
POLY cg; |
int grd; |
int grd; |
int index; |
int index; |
/* the result is read only. */ |
/* the result is read only. */ |
{ |
{ |
extern struct ring *SyzRingp; |
extern struct ring *SyzRingp; |
POLY r; |
POLY r; |
|
|
} |
} |
|
|
struct coeff *toSyzCoeff(f) |
struct coeff *toSyzCoeff(f) |
POLY f; |
POLY f; |
{ |
{ |
extern struct ring *SyzRingp; |
extern struct ring *SyzRingp; |
struct coeff *c; |
struct coeff *c; |
Line 614 void initSyzRingp() { |
|
Line 640 void initSyzRingp() { |
|
} |
} |
|
|
POLY reductionCdr_except_grd_i(POLY f,struct gradedPolySet *gset, |
POLY reductionCdr_except_grd_i(POLY f,struct gradedPolySet *gset, |
int needSyz,struct syz0 *syzp, |
int needSyz,struct syz0 *syzp, |
int skipGrd,int skipi, int *reducedp) |
int skipGrd,int skipi, int *reducedp) |
{ |
{ |
int reduced,reduced1,reduced2; |
int reduced,reduced1,reduced2; |
int grd; |
int grd; |
Line 641 POLY reductionCdr_except_grd_i(POLY f,struct gradedPol |
|
Line 667 POLY reductionCdr_except_grd_i(POLY f,struct gradedPol |
|
grd = 0; |
grd = 0; |
while (grd < gset->maxGrade) { |
while (grd < gset->maxGrade) { |
/* |
/* |
if (!Sugar) { |
if (!Sugar) { |
if (grd > (*grade)(f)) break; |
if (grd > (*grade)(f)) break; |
} |
} |
*/ |
*/ |
set = gset->polys[grd]; |
set = gset->polys[grd]; |
do { |
do { |
reduced2 = 0; /* no */ |
reduced2 = 0; /* no */ |
for (i=0; i<set->size; i++) { |
for (i=0; i<set->size; i++) { |
if (f ISZERO) goto ss; |
if (f ISZERO) goto ss; |
if ((!((grd == skipGrd) && (i == skipi))) && (set->del[i]==0)) { |
if ((!((grd == skipGrd) && (i == skipi))) && (set->del[i]==0)) { |
/* Do not use deleted element.*/ |
/* Do not use deleted element.*/ |
if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) { |
if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) { |
f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg); |
f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg); |
/* What is cg? */ |
/* What is cg? */ |
if (needSyz) { |
if (needSyz) { |
cf = ppMult(cc,cf); |
cf = ppMult(cc,cf); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
} |
} |
*reducedp = reduced = reduced1 = reduced2 = 1; /* yes */ |
*reducedp = reduced = reduced1 = reduced2 = 1; /* yes */ |
} |
} |
} |
} |
} |
} |
} while (reduced2 != 0); |
} while (reduced2 != 0); |
grd++; |
grd++; |
} |
} |
}while (reduced1 != 0); |
}while (reduced1 != 0); |
|
|
ss: ; |
ss: ; |
if (needSyz) { |
if (needSyz) { |
syzp->cf = cf; |
syzp->cf = cf; |
syzp->syz = syz; |
syzp->syz = syz; |