version 1.15, 2003/08/26 05:52:43 |
version 1.18, 2003/09/12 02:52:50 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.14 2003/08/26 05:06:01 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.17 2003/09/10 07:41:25 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
Line 36 static POLY reduction_ecart1(POLY r,struct gradedPolyS |
|
Line 36 static POLY reduction_ecart1(POLY r,struct gradedPolyS |
|
static POLY reduction_ecart1_mod(POLY r,struct gradedPolySet *gset); |
static POLY reduction_ecart1_mod(POLY r,struct gradedPolySet *gset); |
static POLY ecartCheckSyz0(POLY cf,POLY r_0,POLY syz, |
static POLY ecartCheckSyz0(POLY cf,POLY r_0,POLY syz, |
struct gradedPolySet *gg,POLY r); |
struct gradedPolySet *gg,POLY r); |
|
static void ecartCheckSyz0_printinfo(POLY cf,POLY r_0,POLY syz, |
|
struct gradedPolySet *gg,POLY r); |
|
|
extern int DebugReductionRed; |
extern int DebugReductionRed; |
extern int TraceLift; |
extern int TraceLift; |
Line 67 static POLY ecartDivideSv(POLY r,int *d) { |
|
Line 69 static POLY ecartDivideSv(POLY r,int *d) { |
|
} |
} |
r = r->next; |
r = r->next; |
} |
} |
|
|
if (k > 0) { |
if (k > 0) { |
*d = k; |
*d = k; |
|
return ppMult(cxx(1,0,-k,f->m->ringp),f); |
|
}else{ |
|
return f; |
|
} |
|
|
|
/* Do not do the below. It caused a bug. cf. misc-2003/07/ecart/b4.sm1 test2. |
|
Note. 2003.8.26 |
|
*/ |
|
/* |
|
if (k > 0) { |
|
*d = k; |
f = r; |
f = r; |
while (r != POLYNULL) { |
while (r != POLYNULL) { |
r->m->e[0].x -= k; |
r->m->e[0].x -= k; |
Line 76 static POLY ecartDivideSv(POLY r,int *d) { |
|
Line 90 static POLY ecartDivideSv(POLY r,int *d) { |
|
} |
} |
} |
} |
return f; |
return f; |
|
*/ |
} |
} |
|
|
static int ecartGetEll(POLY f,POLY g) { |
static int ecartGetEll(POLY f,POLY g) { |
Line 193 static struct ecartReducer ecartFindReducer(POLY r,str |
|
Line 208 static struct ecartReducer ecartFindReducer(POLY r,str |
|
} |
} |
} |
} |
|
|
if (DebugReductionRed || (DebugReductionEcart&1)) { |
if ((DebugReductionRed&1) || (DebugReductionEcart&1)) { |
printf("ecartFindReducer(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d\n",ell1,ell2,minGrade,minGseti,minGgi); |
printf("ecartFindReducer(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d\n",ell1,ell2,minGrade,minGseti,minGgi); |
} |
} |
if (ell1 <= ell2) { |
if (ell1 <= ell2) { |
Line 240 static POLY ecartCheckSyz0(POLY cf,POLY r_0,POLY syz, |
|
Line 255 static POLY ecartCheckSyz0(POLY cf,POLY r_0,POLY syz, |
|
return f; |
return f; |
} |
} |
|
|
|
static void ecartCheckSyz0_printinfo(POLY cf,POLY r_0,POLY syz, |
|
struct gradedPolySet *gg,POLY r) |
|
{ |
|
POLY f; |
|
int grd,i; |
|
POLY q; |
|
struct coeff *c; |
|
fprintf(stderr,"cf=%s\n",POLYToString(cf,'*',1)); |
|
fprintf(stderr,"r_0=%s\n",POLYToString(r_0,'*',1)); |
|
fprintf(stderr,"syz=%s\n",POLYToString(syz,'*',1)); |
|
fprintf(stderr,"r=%s\n",POLYToString(r,'*',1)); |
|
f = ppMult(cf,r_0); |
|
while (syz != POLYNULL) { |
|
grd = syz->m->e[0].x; |
|
i = syz->m->e[0].D; |
|
c = syz->coeffp; |
|
if (c->tag == POLY_COEFF) { |
|
q = c->val.f; |
|
}else{ |
|
q = POLYNULL; |
|
} |
|
fprintf(stderr,"[grd,idx]=[%d,%d], %s\n",grd,i, |
|
POLYToString(((gg->polys[grd])->g)[i],'*',1)); |
|
/* f = ppAdd(f,ppMult(q,((gg->polys[grd])->g)[i])); */ |
|
syz = syz->next; |
|
} |
|
/* f = ppSub(f,r); */ |
|
} |
|
|
|
|
POLY reduction_ecart(r,gset,needSyz,syzp) |
POLY reduction_ecart(r,gset,needSyz,syzp) |
POLY r; |
POLY r; |
struct gradedPolySet *gset; |
struct gradedPolySet *gset; |
Line 322 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 366 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
|
|
if (DebugReductionEcart&1) printf("--------------------------------------\n"); |
if (DebugReductionEcart&1) printf("--------------------------------------\n"); |
do { |
do { |
if (DebugReductionRed) printf("r=%s\n",POLYToString(r,'*',1)); |
if (DebugReductionRed&1) printf("r=%s\n",POLYToString(r,'*',1)); |
if (DebugReductionEcart & 1) printf("r=%s+...\n",POLYToString(head(r),'*',1)); |
if (DebugReductionEcart & 1) printf("r=%s+...\n",POLYToString(head(r),'*',1)); |
ells = ecartFindReducer(r,gset,gg); |
ells = ecartFindReducer(r,gset,gg); |
ell = ells.ell; |
ell = ells.ell; |
Line 341 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 385 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
if (DebugReductionEcart & 4) printf("#"); |
if (DebugReductionEcart & 4) printf("#"); |
pp = (gg->pa)[ells.ggi]; |
pp = (gg->pa)[ells.ggi]; |
} |
} |
if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */ |
if (ell > 0) r = ppMult(cxx(1,0,ell,rp),r); /* r = s^ell r */ |
r = (*reduction1)(r,pp,needSyz,&cc,&cg); |
r = (*reduction1)(r,pp,needSyz,&cc,&cg); |
|
|
if (DoCancel && (r != POLYNULL)) { |
if (DoCancel && (r != POLYNULL)) { |
Line 369 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 413 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
syz = ppAdd(syz,cpMult(toSyzCoeff(cg),syz_o)); |
syz = ppAdd(syz,cpMult(toSyzCoeff(cg),syz_o)); |
/* Note. 2003.07.19 */ |
/* Note. 2003.07.19 */ |
} |
} |
if (DebugReductionRed) { |
if (DebugReductionRed && needSyz) { |
POLY tp; |
POLY tp; |
tp = ecartCheckSyz0(cf,r_0,syz,gset,r); |
tp = ecartCheckSyz0(cf,r_0,syz,gset,r); |
if (tp != POLYNULL) { |
if (tp != POLYNULL) { |
fprintf(stderr,"reduction_ecart0(): sygyzy is broken. Return the Current values.\n"); |
fprintf(stderr,"reduction_ecart0(): sygyzy is broken. Return the Current values.\n"); |
fprintf(stderr,"%s\n",POLYToString(tp,'*',1)); |
fprintf(stderr,"tp=%s\n",POLYToString(tp,'*',1)); |
|
ecartCheckSyz0_printinfo(cf,r_0,syz,gset,r); |
syzp->cf = cf; |
syzp->cf = cf; |
syzp->syz = syz; |
syzp->syz = syz; |
return r; |
return r; |
Line 388 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 433 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
if (needSyz && (se > 0)) { |
if (needSyz && (se > 0)) { |
POLY tt; |
POLY tt; |
tt = cxx(1,0,-se,rp); |
tt = cxx(1,0,-se,rp); |
cf = mpMult(tt,cf); |
cf = ppMult(tt,cf); |
syz = cpMult(toSyzCoeff(tt),syz); |
syz = cpMult(toSyzCoeff(tt),syz); |
} |
} |
|
|
Line 397 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 442 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
|
|
ss: ; |
ss: ; |
if (needSyz) { |
if (needSyz) { |
syzp->cf = cf; /* cf is in the CurrentRingp */ |
syzp->cf = cf; /* cf is in the ring of r */ |
syzp->syz = syz; /* syz is in the SyzRingp */ |
syzp->syz = syz; /* syz is in the syzRing of r */ |
} |
} |
|
|
if (DoCancel && (r != POLYNULL)) { |
if (DoCancel && (r != POLYNULL)) { |
Line 437 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 482 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
POLY cf_o; |
POLY cf_o; |
POLY syz_o; |
POLY syz_o; |
POLY r_0; |
POLY r_0; |
|
POLY r0; |
int se; |
int se; |
struct coeff *cont; |
struct coeff *cont; |
|
|
Line 465 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 511 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
|
|
if (DebugReductionEcart&1) printf("=======================================\n"); |
if (DebugReductionEcart&1) printf("=======================================\n"); |
do { |
do { |
if (DebugReductionRed) printf("(ecart1(d)) r=%s\n",POLYToString(r,'*',1)); |
if (DebugReductionRed & 1) printf("(ecart1(d)) r=%s\n",POLYToString(r,'*',1)); |
if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1)); |
if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1)); |
|
|
ells = ecartFindReducer(r,gset,gg); |
ells = ecartFindReducer(r,gset,gg); |
ell = ells.ell; |
ell = ells.ell; |
if (ell > 0) { |
if (ell > 0) { |
if (DebugReductionEcart & 2) printf("%"); |
if (DebugReductionEcart & 2) printf("%"); |
if (needSyz) { |
if (needSyz) { |
gg = ecartPutPolyInG(r,gg,cf,syz); |
gg = ecartPutPolyInG(r,gg,cf,syz); |
}else{ |
}else{ |
gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL); |
gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL); |
} |
} |
} |
} |
if (ell >= 0) { |
if (ell >= 0) { |
if (ells.first) { |
if (ells.first) { |
Line 485 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 531 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);} |
if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);} |
pp = (gg->pa)[ells.ggi]; |
pp = (gg->pa)[ells.ggi]; |
} |
} |
if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */ |
if (ell > 0) r = ppMult(cxx(1,0,ell,rp),r); /* r = s^ell r */ |
|
r0 = r; |
r = (*reduction1)(r,pp,needSyz,&cc,&cg); |
r = (*reduction1)(r,pp,needSyz,&cc,&cg); |
|
if (DebugReductionEcart & 8) { |
|
if (ell > 0) {printf("ell+ "); fflush(NULL); |
|
}else { |
|
printf("ell0 "); fflush(NULL); |
|
if ((*mmLarger)(r,r0) >= 1) { |
|
printf("error in reduction."); |
|
printf(" r0=%s\n",POLYToString(r0,'*',1)); |
|
printf("==>r=%s\n",POLYToString(r,'*',1)); |
|
getchar(); getchar(); |
|
} |
|
} |
|
} |
|
|
if (DoCancel && (r != POLYNULL)) { |
if (DoCancel && (r != POLYNULL)) { |
if (shouldReduceContent(r,0)) { |
if (shouldReduceContent(r,0)) { |
Line 498 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 557 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
|
|
if (needSyz) { |
if (needSyz) { |
if (ells.first) { |
if (ells.first) { |
if (ell > 0) cc = ppMult(cc,cxx(1,0,ell,rp)); |
if (ell > 0) cc = ppMult(cc,cxx(1,0,ell,rp)); |
cf = ppMult(cc,cf); |
cf = ppMult(cc,cf); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = cpMult(toSyzCoeff(cc),syz); |
syz = ppAddv(syz,toSyzPoly(cg,ells.grade,ells.gseti)); |
syz = ppAdd(syz,toSyzPoly(cg,ells.grade,ells.gseti)); |
}else{ |
}else{ |
if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp)); |
if (ell >0) cc = ppMult(cc,cxx(1,0,ell,rp)); |
cf_o = (gg->cf)[ells.ggi]; |
cf_o = (gg->cf)[ells.ggi]; |
Line 514 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 573 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
} |
} |
} |
} |
|
|
if (DebugReductionRed) { |
if (DebugReductionRed && needSyz) { |
POLY tp; |
POLY tp; |
tp = ecartCheckSyz0(cf,r_0,syz,gset,r); |
tp = ecartCheckSyz0(cf,r_0,syz,gset,r); |
tp = goDeHomogenizeS(tp); |
tp = goDeHomogenizeS(tp); |
if (tp != POLYNULL) { |
if (tp != POLYNULL) { |
fprintf(stderr,"reduction_ecart1(): sygyzy is broken. Return the Current values.\n"); |
fprintf(stderr,"Error: reduction_ecart1(): sygyzy is broken. Return the Current values.\n"); |
fprintf(stderr,"%s\n",POLYToString(tp,'*',1)); |
fprintf(stderr,"%s\n",POLYToString(tp,'*',1)); |
syzp->cf = cf; |
syzp->cf = cf; |
syzp->syz = syz; |
syzp->syz = syz; |
Line 530 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 589 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
if (r ISZERO) goto ss1; |
if (r ISZERO) goto ss1; |
r = ecartDivideSv(r,&se); /* r = r/s^? */ |
r = ecartDivideSv(r,&se); /* r = r/s^? */ |
|
|
if (needSyz && (se > 0)) { /* It may not necessary because of dehomo*/ |
if (needSyz && (se > 0)) { /* It may not necessary because of dehomo*/ |
POLY tt; |
POLY tt; |
/*printf("!1/H!"); fflush(NULL);*/ /* misc-2003/ecart/t1.sm1 foo4 */ |
/*printf("!1/H!"); fflush(NULL);*/ /* misc-2003/ecart/t1.sm1 foo4 */ |
tt = cxx(1,0,-se,rp); |
tt = cxx(1,0,-se,rp); |
cf = mpMult(tt,cf); |
cf = ppMult(tt,cf); |
syz = cpMult(toSyzCoeff(tt),syz); |
syz = cpMult(toSyzCoeff(tt),syz); |
} |
} |
|
|
|
/* For debug */ |
|
if (DebugReductionRed && needSyz) { |
|
POLY tp; |
|
tp = ecartCheckSyz0(cf,r_0,syz,gset,r); |
|
tp = goDeHomogenizeS(tp); |
|
if (tp != POLYNULL) { |
|
fprintf(stderr,"Error: reduction_ecart1() after divide: sygyzy is broken. Return the Current values.\n"); |
|
fprintf(stderr,"%s\n",POLYToString(tp,'*',1)); |
|
syzp->cf = cf; |
|
syzp->syz = syz; |
|
return r; |
|
} |
|
} |
|
|
} |
} |
}while (ell >= 0); |
}while (ell >= 0); |
|
|
ss1: ; |
ss1: ; |
if (needSyz) { |
if (needSyz) { |
/* dehomogenize the syzygy. BUG, this may be inefficient. */ |
/* dehomogenize the syzygy. BUG, this may be inefficient. */ |
cf = goDeHomogenizeS(cf); |
cf = goDeHomogenizeS(cf); |
syz = goDeHomogenizeS(syz); |
syz = goDeHomogenizeS(syz); |
/*printf("cf=%s\n",POLYToString(cf,'*',1)); |
/*printf("cf=%s\n",POLYToString(cf,'*',1)); |
printf("syz=%s\n",POLYToString(syz,'*',1));*/ |
printf("syz=%s\n",POLYToString(syz,'*',1));*/ |
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 555 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 628 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
r = goDeHomogenizeS(r); |
r = goDeHomogenizeS(r); |
if (DoCancel && (r != POLYNULL)) { |
if (DoCancel && (r != POLYNULL)) { |
if (r->m->ringp->p == 0) { |
if (r->m->ringp->p == 0) { |
r = reduceContentOfPoly(r,&cont); |
r = reduceContentOfPoly(r,&cont); |
if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont)); |
if (DebugReductionEcart || DebugReductionRed || DebugContentReduction) printf("cont=%s ",coeffToString(cont)); |
} |
} |
} |
} |
|
|
|
/* For debug */ |
|
if (DebugReductionRed && needSyz) { |
|
POLY tp; |
|
tp = ecartCheckSyz0(cf,r_0,syz,gset,r); |
|
tp = goDeHomogenizeS(tp); |
|
if (tp != POLYNULL) { |
|
fprintf(stderr,"Error: reduction_ecart1() last step: sygyzy is broken. Return the Current values.\n"); |
|
fprintf(stderr,"%s\n",POLYToString(tp,'*',1)); |
|
syzp->cf = cf; |
|
syzp->syz = syz; |
|
return r; |
|
} |
|
} |
|
|
return(r); |
return(r); |
} |
} |
|
|
Line 617 static struct ecartReducer ecartFindReducer_mod(POLY r |
|
Line 704 static struct ecartReducer ecartFindReducer_mod(POLY r |
|
} |
} |
} |
} |
|
|
if (DebugReductionRed || (DebugReductionEcart&1)) { |
if ((DebugReductionRed & 1)|| (DebugReductionEcart&1)) { |
printf("ecartFindReducer_mod(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d, p=%d\n",ell1,ell2,minGrade,minGseti,minGgi,TraceLift_ringmod->p); |
printf("ecartFindReducer_mod(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d, p=%d\n",ell1,ell2,minGrade,minGseti,minGgi,TraceLift_ringmod->p); |
} |
} |
if (ell1 <= ell2) { |
if (ell1 <= ell2) { |
Line 651 static POLY reduction_ecart1_mod(r,gset) |
|
Line 738 static POLY reduction_ecart1_mod(r,gset) |
|
struct ecartReducer ells; |
struct ecartReducer ells; |
struct ecartPolyArray *gg; |
struct ecartPolyArray *gg; |
POLY pp; |
POLY pp; |
|
POLY r0; |
int ell; |
int ell; |
int se; |
int se; |
|
|
Line 672 static POLY reduction_ecart1_mod(r,gset) |
|
Line 760 static POLY reduction_ecart1_mod(r,gset) |
|
KshowRing(TraceLift_ringmod); **/ |
KshowRing(TraceLift_ringmod); **/ |
|
|
r = modulop(r,TraceLift_ringmod); |
r = modulop(r,TraceLift_ringmod); |
rp = r->m->ringp; /* reset rp */ |
if (r != POLYNULL) rp = r->m->ringp; /* reset rp */ |
|
|
/* printf("r=%s (mod p)\n",POLYToString(head(r),'*',1)); **/ |
/* printf("r=%s (mod p)\n",POLYToString(head(r),'*',1)); **/ |
|
|
if (DebugReductionEcart&1) printf("=====================================mod\n"); |
if (DebugReductionEcart&1) printf("=====================================mod\n"); |
do { |
do { |
if (DebugReductionRed) printf("(ecart1_mod(d)) r=%s\n",POLYToString(r,'*',1)); |
if (DebugReductionRed & 1) printf("(ecart1_mod(d)) r=%s\n",POLYToString(r,'*',1)); |
if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1)); |
if (DebugReductionEcart & 1) printf("r=%s+,,,\n",POLYToString(head(r),'*',1)); |
|
|
ells = ecartFindReducer_mod(r,gset,gg); |
ells = ecartFindReducer_mod(r,gset,gg); |
Line 694 static POLY reduction_ecart1_mod(r,gset) |
|
Line 782 static POLY reduction_ecart1_mod(r,gset) |
|
if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);} |
if (DebugReductionEcart & 4) {printf("+"); fflush(NULL);} |
pp = (gg->pa)[ells.ggi]; |
pp = (gg->pa)[ells.ggi]; |
} |
} |
if (ell > 0) r = mpMult(cxx(1,0,ell,rp),r); /* r = s^ell r */ |
if (ell > 0) r = ppMult(cxx(1,0,ell,rp),r); /* r = s^ell r */ |
|
|
|
r0 = r; |
r = (*reduction1)(r,pp,0,&cc,&cg); |
r = (*reduction1)(r,pp,0,&cc,&cg); |
|
|
|
if (DebugReductionEcart & 8) { |
|
if (ell > 0) {printf("ell+ "); fflush(NULL); |
|
}else { |
|
printf("ell0 "); fflush(NULL); |
|
if ((*mmLarger)(r,r0) >= 1) { |
|
printf("error in reduction."); |
|
printf(" r0=%s\n",POLYToString(r0,'*',1)); |
|
printf("==>r=%s\n",POLYToString(r,'*',1)); |
|
getchar(); getchar(); |
|
} |
|
} |
|
} |
|
|
if (r ISZERO) goto ss1; |
if (r ISZERO) goto ss1; |
r = ecartDivideSv(r,&se); /* r = r/s^? */ |
r = ecartDivideSv(r,&se); /* r = r/s^? */ |
} |
} |