version 1.17, 2003/09/10 07:41:25 |
version 1.20, 2003/09/21 02:19:43 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.16 2003/08/27 03:11:12 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.19 2003/09/20 09:57:29 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
Line 45 struct ring *TraceLift_ringmod; |
|
Line 45 struct ring *TraceLift_ringmod; |
|
extern DoCancel; |
extern DoCancel; |
int DebugReductionEcart = 0; |
int DebugReductionEcart = 0; |
extern DebugContentReduction; |
extern DebugContentReduction; |
|
extern int Sugar; |
|
|
/* This is used for goHomogenization */ |
/* This is used for goHomogenization */ |
extern int DegreeShifto_size; |
extern int DegreeShifto_size; |
extern int *DegreeShifto_vec; |
extern int *DegreeShifto_vec; |
|
int Ecart_sugarGrade; |
|
|
/* It is used reduction_ecart() and ecartFindReducer() |
/* It is used reduction_ecart() and ecartFindReducer() |
to determine if we homogenize in this function */ |
to determine if we homogenize in this function */ |
Line 163 static struct ecartPolyArray *ecartPutPolyInG(POLY g,s |
|
Line 165 static struct ecartPolyArray *ecartPutPolyInG(POLY g,s |
|
return eparray; |
return eparray; |
} |
} |
|
|
|
#ifndef EXPERIMENT |
static struct ecartReducer ecartFindReducer(POLY r,struct gradedPolySet *gset, |
static struct ecartReducer ecartFindReducer(POLY r,struct gradedPolySet *gset, |
struct ecartPolyArray *epa) |
struct ecartPolyArray *epa) |
{ |
{ |
Line 208 static struct ecartReducer ecartFindReducer(POLY r,str |
|
Line 211 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) { |
if (ell1 == LARGE) { |
if (ell1 == LARGE) { |
er.ell = -1; |
er.ell = -1; |
Line 229 static struct ecartReducer ecartFindReducer(POLY r,str |
|
Line 233 static struct ecartReducer ecartFindReducer(POLY r,str |
|
return er; |
return er; |
} |
} |
} |
} |
|
#endif |
|
|
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) |
Line 364 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 369 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
|
|
if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1); |
if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1); |
|
|
if (DebugReductionEcart&1) printf("--------------------------------------\n"); |
if (DebugReductionEcart&1) printf("reduction_ecart0--------------------------------------\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 413 static POLY reduction_ecart0(r,gset,needSyz,syzp) |
|
Line 418 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) { |
Line 482 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 487 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 508 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 514 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
/* 1 means homogenize only s */ |
/* 1 means homogenize only s */ |
if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1); |
if (DoCancel && (r != POLYNULL)) shouldReduceContent(r,1); |
|
|
if (DebugReductionEcart&1) printf("=======================================\n"); |
if (DebugReductionEcart&1) printf("reduction_ecart1=======================================\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); |
Line 531 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 537 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
pp = (gg->pa)[ells.ggi]; |
pp = (gg->pa)[ells.ggi]; |
} |
} |
if (ell > 0) r = ppMult(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 559 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 578 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); |
Line 690 static struct ecartReducer ecartFindReducer_mod(POLY r |
|
Line 709 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 724 static POLY reduction_ecart1_mod(r,gset) |
|
Line 743 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 751 static POLY reduction_ecart1_mod(r,gset) |
|
Line 771 static POLY reduction_ecart1_mod(r,gset) |
|
|
|
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 768 static POLY reduction_ecart1_mod(r,gset) |
|
Line 788 static POLY reduction_ecart1_mod(r,gset) |
|
pp = (gg->pa)[ells.ggi]; |
pp = (gg->pa)[ells.ggi]; |
} |
} |
if (ell > 0) r = ppMult(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^? */ |
} |
} |
Line 780 static POLY reduction_ecart1_mod(r,gset) |
|
Line 816 static POLY reduction_ecart1_mod(r,gset) |
|
|
|
return(r); |
return(r); |
} |
} |
|
|
|
#ifdef EXPERIMENT |
|
static struct ecartReducer ecartFindReducer(POLY r,struct gradedPolySet *gset, |
|
struct ecartPolyArray *epa) |
|
{ |
|
int grd; |
|
struct polySet *set; |
|
int minGrade = 0; |
|
int minGseti = 0; |
|
int minGgi = 0; |
|
int ell1 = LARGE; |
|
int ell2 = LARGE; |
|
int ell; |
|
int i; |
|
struct ecartReducer er; |
|
int ellmin ; |
|
ell1 = ell2 = ellmin = LARGE; |
|
/* Try to find a reducer in gset; */ |
|
grd = 0; |
|
while (grd < gset->maxGrade) { |
|
set = gset->polys[grd]; |
|
for (i=0; i<set->size; i++) { |
|
if (set->gh[i] == POLYNULL) { |
|
/* goHomogenize set->gh[i] */ |
|
if (EcartAutomaticHomogenization) { |
|
set->gh[i] = goHomogenize11(set->g[i],DegreeShifto_vec,DegreeShifto_size,-1,1); |
|
}else{ |
|
set->gh[i] = set->g[i]; |
|
} |
|
} |
|
ell = ecartGetEll(r,set->gh[i]); |
|
if ((ell>=0) && (ell < ell1)) { |
|
ell1 = ell; |
|
minGrade = grd; minGseti=i; |
|
} |
|
} |
|
grd++; |
|
} |
|
if (epa != NULL) { |
|
/* Try to find in the second group. */ |
|
for (i=0; i< epa->size; i++) { |
|
ell = ecartGetEll(r,(epa->pa)[i]); |
|
if ((ell>=0) && (ell < ell2)) { |
|
ell2 = ell; |
|
minGgi = i; |
|
} |
|
} |
|
} |
|
|
|
if ((DebugReductionRed&1) || (DebugReductionEcart&1)) { |
|
printf("ecartFindReducer(): ell1=%d, ell2=%d, minGrade=%d, minGseti=%d, minGgi=%d\n",ell1,ell2,minGrade,minGseti,minGgi); |
|
} |
|
|
|
#ifdef EXPERIMENTAL1 |
|
if (Sugar) { /* experimental */ |
|
if (ell1 <= ell2) { |
|
if (ell1 == LARGE) { |
|
er.ell = -1; |
|
return er; |
|
}else{ |
|
int new_s; |
|
er.ell = ell1; |
|
er.first = 1; |
|
er.grade = minGrade; |
|
er.gseti = minGseti; |
|
/* reduce if and only if Ecart_sugarGrade does not increase. */ |
|
new_s = grade_gen(r)-grade_gen(gset->polys[minGrade]->gh[minGseti]); |
|
if (new_s + minGrade <= Ecart_sugarGrade+1) { |
|
return er; |
|
}else{ |
|
printf("new_s=%d, minGrade=%d, sugarGrade=%d\n",new_s,minGrade, |
|
Ecart_sugarGrade); |
|
er.ell = -1; |
|
return er; |
|
} |
|
} |
|
}else{ |
|
er.ell = ell2; |
|
er.first = 0; |
|
er.ggi = minGgi; |
|
return er; |
|
} |
|
} |
|
#endif |
|
|
|
if ((ell1 == LARGE) && (ell2 == LARGE)) { |
|
er.ell = -1; |
|
return er; |
|
} |
|
|
|
if (ell1 < ell2) { |
|
ellmin = ell1; |
|
}else{ |
|
ellmin = ell2; |
|
} |
|
{ |
|
#define M 100 |
|
int aminGrade[M]; |
|
int aminGseti[M]; |
|
int aminGgi[M]; |
|
int sp1,sp2; |
|
int i; |
|
int gmin; |
|
int gtmp; |
|
sp1 = sp2 = 0; |
|
|
|
if (ell1 == ellmin) { |
|
grd = 0; |
|
while (grd < gset->maxGrade) { |
|
set = gset->polys[grd]; |
|
for (i=0; i<set->size; i++) { |
|
ell = ecartGetEll(r,set->gh[i]); |
|
if (ell == ellmin) { |
|
aminGrade[sp1] = grd; aminGseti[sp1]=i; |
|
sp1++; |
|
if (sp1 >= M) { |
|
fprintf(stderr,"aminGrade, buffer overflow. sp1 is set to 1.\n"); |
|
sp1 = 1; |
|
} |
|
} |
|
} |
|
grd++; |
|
} |
|
} |
|
if (ell2 == ellmin) { |
|
if (epa != NULL) { |
|
for (i=0; i< epa->size; i++) { |
|
ell = ecartGetEll(r,(epa->pa)[i]); |
|
if (ell == ellmin) { |
|
aminGgi[sp2] = i; |
|
sp2++; |
|
if (sp2 >= M) { |
|
fprintf(stderr,"aminGgi, buffer overflow. sp2 is set to 1.\n"); |
|
sp2 = 1; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
/* print summary */ |
|
printf("summary -----------------------\n"); |
|
for (i=0; i<sp1; i++) { |
|
printf("i=%d: minGrade=%d, minGseti=%d,",i,aminGrade[i],aminGseti[i]); |
|
printf("grade=%d\n",grade_gen(gset->polys[aminGrade[i]]->gh[aminGseti[i]])); |
|
} |
|
gmin = LARGE; |
|
for (i=0; i<sp2; i++) { |
|
printf("i=%d: minGgi=%d,",i,aminGgi[i]); |
|
gtmp = grade_gen((epa->pa)[aminGgi[i]]); |
|
printf("grade=%d\n",gtmp); |
|
if (gtmp < gmin) { |
|
gmin = gtmp; |
|
minGgi = aminGgi[i]; |
|
} |
|
} |
|
|
|
if (ell1 <= ell2) { |
|
er.ell = ell1; |
|
er.first = 1; |
|
er.grade = minGrade; |
|
er.gseti = minGseti; |
|
return er; |
|
}else{ |
|
er.ell = ell2; |
|
er.first = 0; |
|
er.ggi = minGgi; |
|
return er; |
|
} |
|
|
|
} |
|
|
|
if (ell1 <= ell2) { |
|
er.ell = ell1; |
|
er.first = 1; |
|
er.grade = minGrade; |
|
er.gseti = minGseti; |
|
return er; |
|
}else{ |
|
er.ell = ell2; |
|
er.first = 0; |
|
er.ggi = minGgi; |
|
return er; |
|
} |
|
} |
|
#endif |
|
|