version 1.1.1.1, 1999/10/08 02:12:02 |
version 1.4, 2001/05/04 01:06:25 |
|
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/red.c,v 1.3 2000/02/24 00:27:12 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
Line 9 int DebugReductionRed = 0; |
|
Line 10 int DebugReductionRed = 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 146 POLY *h; /* set */ |
|
Line 147 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 170 POLY *h; /* set */ |
|
Line 171 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 181 POLY *h; /* set */ |
|
Line 182 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 196 POLY *h; /* set */ |
|
Line 197 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 219 POLY *h; /* set */ |
|
Line 220 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 233 POLY *h; /* set */ |
|
Line 234 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 246 POLY *h; /* set */ |
|
Line 247 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 296 POLY *h; /* set */ |
|
Line 297 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 337 struct syz0 *syzp; /* set */ |
|
Line 338 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) { |
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 368 struct syz0 *syzp; /* set */ |
|
Line 369 struct syz0 *syzp; /* set */ |
|
} |
} |
|
|
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 396 struct syz0 *syzp; /* set */ |
|
Line 397 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 423 struct syz0 *syzp; /* set */ |
|
Line 424 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 451 struct syz0 *syzp; /* set */ |
|
Line 452 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 482 struct syz0 *syzp; /* set */ |
|
Line 483 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 612 void initSyzRingp() { |
|
Line 613 void initSyzRingp() { |
|
SyzRingp->name = ringName; |
SyzRingp->name = ringName; |
} |
} |
|
|
|
POLY reductionCdr_except_grd_i(POLY f,struct gradedPolySet *gset, |
|
int needSyz,struct syz0 *syzp, |
|
int skipGrd,int skipi, int *reducedp) |
|
{ |
|
int reduced,reduced1,reduced2; |
|
int grd; |
|
struct polySet *set; |
|
POLY cf,syz; |
|
int i; |
|
POLY cc,cg; |
|
POLY fs; |
|
|
|
extern struct ring *CurrentRingp; |
|
struct ring *rp; |
|
|
|
*reducedp = 0; |
|
if (needSyz) { |
|
if (f ISZERO) { rp = CurrentRingp; } else {rp = f->m->ringp; } |
|
cf = cxx(1,0,0,rp); |
|
syz = ZERO; |
|
} |
|
|
|
reduced = 0; /* no */ |
|
do { |
|
reduced1 = 0; /* no */ |
|
grd = 0; |
|
while (grd < gset->maxGrade) { |
|
/* |
|
if (!Sugar) { |
|
if (grd > (*grade)(f)) break; |
|
} |
|
*/ |
|
set = gset->polys[grd]; |
|
do { |
|
reduced2 = 0; /* no */ |
|
for (i=0; i<set->size; i++) { |
|
if (f ISZERO) goto ss; |
|
if ((!((grd == skipGrd) && (i == skipi))) && (set->del[i]==0)) { |
|
/* Do not use deleted element.*/ |
|
if ((fs =(*isCdrReducible)(f,set->g[i])) != ZERO) { |
|
f = (*reduction1Cdr)(f,fs,set->g[i],needSyz,&cc,&cg); |
|
/* What is cg? */ |
|
if (needSyz) { |
|
cf = ppMult(cc,cf); |
|
syz = cpMult(toSyzCoeff(cc),syz); |
|
syz = ppAddv(syz,toSyzPoly(cg,grd,i)); |
|
} |
|
*reducedp = reduced = reduced1 = reduced2 = 1; /* yes */ |
|
} |
|
} |
|
} |
|
} while (reduced2 != 0); |
|
grd++; |
|
} |
|
}while (reduced1 != 0); |
|
|
|
ss: ; |
|
if (needSyz) { |
|
syzp->cf = cf; |
|
syzp->syz = syz; |
|
} |
|
return(f); |
|
} |