version 1.18, 2003/09/12 02:52:50 |
version 1.23, 2020/10/06 11:33:46 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.17 2003/09/10 07:41:25 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/ecart.c,v 1.22 2005/07/03 11:08:53 ohara Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
#include "datatype.h" |
#include "datatype.h" |
|
// #include "extern.h" |
#include "extern2.h" |
#include "extern2.h" |
#include "gradedset.h" |
#include "gradedset.h" |
|
|
#define outofmemory(a) if (a == NULL) {fprintf(stderr,"ecart.c: out of memory.\n"); exit(10);} |
#define outofmemory(a) if (a == NULL) {fprintf(stderr,"ecart.c: out of memory.\n"); exit(10);} |
|
|
|
int errorKan1(char *s,char *m); /* defined in extern.h */ |
|
|
/* Local structures */ |
/* Local structures */ |
struct ecartReducer { |
struct ecartReducer { |
int ell; /* s^\ell */ |
int ell; /* s^\ell */ |
Line 26 static int ecartCheckPoly(POLY f); /* check if it doe |
|
Line 31 static int ecartCheckPoly(POLY f); /* check if it doe |
|
static int ecartCheckEnv(); /* check if the environment is OK for ecart div*/ |
static int ecartCheckEnv(); /* check if the environment is OK for ecart div*/ |
static struct ecartPolyArray *ecartPutPolyInG(POLY g,struct ecartPolyArray *eparray,POLY cf, POLY syz); |
static struct ecartPolyArray *ecartPutPolyInG(POLY g,struct ecartPolyArray *eparray,POLY cf, POLY syz); |
static int ecartGetEll(POLY r,POLY g); |
static int ecartGetEll(POLY r,POLY g); |
|
static int ecartGetEllPartial(POLY r,POLY g); |
static POLY ecartDivideSv(POLY r,int *d); |
static POLY ecartDivideSv(POLY r,int *d); |
/* No automatic homogenization and s is used as a standart var. */ |
/* No automatic homogenization and s is used as a standart var. */ |
static POLY reduction_ecart0(POLY r,struct gradedPolySet *gset, |
static POLY reduction_ecart0(POLY r,struct gradedPolySet *gset, |
Line 42 static void ecartCheckSyz0_printinfo(POLY cf,POLY r_0 |
|
Line 48 static void ecartCheckSyz0_printinfo(POLY cf,POLY r_0 |
|
extern int DebugReductionRed; |
extern int DebugReductionRed; |
extern int TraceLift; |
extern int TraceLift; |
struct ring *TraceLift_ringmod; |
struct ring *TraceLift_ringmod; |
extern DoCancel; |
extern int DoCancel; |
int DebugReductionEcart = 0; |
int DebugReductionEcart = 0; |
extern DebugContentReduction; |
extern int 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 115 static int ecartGetEll(POLY f,POLY g) { |
|
Line 123 static int ecartGetEll(POLY f,POLY g) { |
|
else return(-p); |
else return(-p); |
} |
} |
|
|
|
static int ecartGetEllPartial(POLY f,POLY g) { |
|
int n,i,p; |
|
MONOMIAL tf; |
|
MONOMIAL tg; |
|
int nglob; int *glob; int k; |
|
|
|
if (f ISZERO) return(-1); |
|
if (g ISZERO) return(-1); |
|
|
|
checkRingIsR(f,g); |
|
|
|
if (!isSameComponent_x(f,g)) return(-1); |
|
tf = f->m; tg = g->m; n = tf->ringp->n; |
|
for (i=1; i<n; i++) { |
|
if (tf->e[i].x < tg->e[i].x) return(-1); |
|
if (tf->e[i].D < tg->e[i].D) return(-1); |
|
} |
|
if (tf->e[0].D < tg->e[0].D) return(-1); /* h */ |
|
|
|
/* Find u and ell s.t. s^\ell f = u g. |
|
When u contains variables in glob (index x var), then returns -1. |
|
x' = glob, x'' = complement of glob. Division in Q(x'')[x']. |
|
*/ |
|
nglob = tf->ringp->partialEcart; |
|
glob = tf->ringp->partialEcartGlobalVarX; |
|
for (i=0; i<nglob; i++) { |
|
k = glob[i]; |
|
if (tf->e[k].x > tg->e[k].x) return(-1); |
|
} |
|
|
|
p = tf->e[0].x - tg->e[0].x; /* H, s */ |
|
if (p >=0 ) return 0; |
|
else return(-p); |
|
} |
|
|
|
|
#define EP_SIZE 10 |
#define EP_SIZE 10 |
static struct ecartPolyArray *ecartPutPolyInG(POLY g,struct ecartPolyArray *eparray,POLY cf,POLY syz) |
static struct ecartPolyArray *ecartPutPolyInG(POLY g,struct ecartPolyArray *eparray,POLY cf,POLY syz) |
{ |
{ |
Line 163 static struct ecartPolyArray *ecartPutPolyInG(POLY g,s |
|
Line 206 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 200 static struct ecartReducer ecartFindReducer(POLY r,str |
|
Line 244 static struct ecartReducer ecartFindReducer(POLY r,str |
|
if (epa != NULL) { |
if (epa != NULL) { |
/* Try to find in the second group. */ |
/* Try to find in the second group. */ |
for (i=0; i< epa->size; i++) { |
for (i=0; i< epa->size; i++) { |
ell = ecartGetEll(r,(epa->pa)[i]); |
ell = ecartGetEllPartial(r,(epa->pa)[i]); |
if ((ell>=0) && (ell < ell2)) { |
if ((ell>=0) && (ell < ell2)) { |
ell2 = ell; |
ell2 = ell; |
minGgi = i; |
minGgi = i; |
Line 211 static struct ecartReducer ecartFindReducer(POLY r,str |
|
Line 255 static struct ecartReducer ecartFindReducer(POLY r,str |
|
if ((DebugReductionRed&1) || (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 274 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 410 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&1) 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)); |
Line 509 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 555 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 & 1) 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)); |
Line 517 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
Line 563 static POLY reduction_ecart1(r,gset,needSyz,syzp) |
|
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{ |
Line 696 static struct ecartReducer ecartFindReducer_mod(POLY r |
|
Line 742 static struct ecartReducer ecartFindReducer_mod(POLY r |
|
if (epa != NULL) { |
if (epa != NULL) { |
/* Try to find in the second group. */ |
/* Try to find in the second group. */ |
for (i=0; i< epa->size; i++) { |
for (i=0; i< epa->size; i++) { |
ell = ecartGetEll(r,(epa->pa)[i]); |
ell = ecartGetEllPartial(r,(epa->pa)[i]); |
if ((ell>=0) && (ell < ell2)) { |
if ((ell>=0) && (ell < ell2)) { |
ell2 = ell; |
ell2 = ell; |
minGgi = i; |
minGgi = i; |
Line 772 static POLY reduction_ecart1_mod(r,gset) |
|
Line 818 static POLY reduction_ecart1_mod(r,gset) |
|
ells = ecartFindReducer_mod(r,gset,gg); |
ells = ecartFindReducer_mod(r,gset,gg); |
ell = ells.ell; |
ell = ells.ell; |
if (ell > 0) { |
if (ell > 0) { |
if (DebugReductionEcart & 2) printf("%"); |
if (DebugReductionEcart & 2) printf("%%"); |
gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL); |
gg = ecartPutPolyInG(r,gg,POLYNULL,POLYNULL); |
} |
} |
if (ell >= 0) { |
if (ell >= 0) { |
Line 811 static POLY reduction_ecart1_mod(r,gset) |
|
Line 857 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 |
|
|