version 1.27, 2002/11/01 05:43:35 |
version 1.33, 2015/08/14 13:51:54 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.26 2002/10/25 02:43:40 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.32 2015/08/08 14:19:41 fujimoto Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
|
|
|
int debug_sfbfctr; |
|
|
void lnfsf(int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1); |
void lnfsf(int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1); |
void extractcoefbm(BM f,int dx,UM r); |
void extractcoefbm(BM f,int dx,UM r); |
|
|
Line 79 void gensqfrsfum(UM p,struct oDUM *dc) |
|
Line 81 void gensqfrsfum(UM p,struct oDUM *dc) |
|
{ |
{ |
int n,i,j,d,mod; |
int n,i,j,d,mod; |
UM t,s,g,f,f1,b; |
UM t,s,g,f,f1,b; |
|
GFS u,v; |
|
|
if ( (n = DEG(p)) == 1 ) { |
if ( (n = DEG(p)) == 1 ) { |
dc[0].f = UMALLOC(DEG(p)); cpyum(p,dc[0].f); dc[0].n = 1; |
dc[0].f = UMALLOC(DEG(p)); cpyum(p,dc[0].f); dc[0].n = 1; |
Line 117 void gensqfrsfum(UM p,struct oDUM *dc) |
|
Line 120 void gensqfrsfum(UM p,struct oDUM *dc) |
|
break; |
break; |
else { |
else { |
DEG(s) = DEG(t)/mod; |
DEG(s) = DEG(t)/mod; |
for ( j = 0; j <= DEG(t); j++ ) |
for ( j = 0; j <= DEG(t); j++ ) { |
COEF(s)[j] = COEF(t)[j*mod]; |
iftogfs(COEF(t)[j*mod],&u); |
|
pthrootgfs(u,&v); |
|
COEF(s)[j] = v?FTOIF(CONT(v)):0; |
|
} |
cpyum(s,b); d *= mod; |
cpyum(s,b); d *= mod; |
} |
} |
} |
} |
Line 506 void canzassf(UM f,int d,UM *r) |
|
Line 512 void canzassf(UM f,int d,UM *r) |
|
|
|
/* Hensel related functions */ |
/* Hensel related functions */ |
|
|
int sfberle(VL,P,int,GFS *,DCP *); |
int sfberle(V,V,P,int,GFS *,DCP *); |
void sfgcdgen(P,ML,ML *); |
void sfgcdgen(P,ML,ML *); |
void sfhenmain2(BM,UM,UM,int,BM *); |
void sfhenmain2(BM,UM,UM,int,BM *); |
void ptosfbm(int,P,BM); |
void ptosfbm(int,P,BM); |
|
void sfhensel(int count,P f,V x,V y,int degbound,GFS *evp,P *sfp,ML *listp); |
|
|
/* f = f(x,y) */ |
/* f = f(x,y) */ |
|
|
void sfhensel(int count,P f,V x,int degbound,GFS *evp,P *sfp,ML *listp) |
void sfhensel(int count,P f,V x,V y,int degbound,GFS *evp,P *sfp,ML *listp) |
{ |
{ |
int i; |
int i; |
int fn; |
int fn; |
ML rlist; |
ML rlist; |
BM fl; |
BM fl; |
VL vl,nvl; |
VL vl,nvl; |
V y; |
|
int dx,dy,bound; |
int dx,dy,bound; |
GFS ev; |
GFS ev; |
P f1,t,c,sf; |
P f1,t,c,sf; |
Line 534 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
Line 540 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1); |
reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1); |
vl = nvl; f = f1; |
vl = nvl; f = f1; |
} |
} |
y = vl->next->v; |
if ( vl->next ) |
|
y = vl->next->v; |
dx = getdeg(x,f); |
dx = getdeg(x,f); |
dy = getdeg(y,f); |
dy = getdeg(y,f); |
if ( dx == 1 ) { |
if ( dx == 1 ) { |
*listp = rlist = MLALLOC(1); rlist->n = 1; rlist->c[0] = 0; |
*listp = rlist = MLALLOC(1); rlist->n = 1; rlist->c[0] = 0; |
return; |
return; |
} |
} |
fn = sfberle(vl,f,count,&ev,&dc); |
fn = sfberle(x,y,f,count,&ev,&dc); |
if ( fn <= 1 ) { |
if ( fn <= 1 ) { |
/* fn == 0 => short of evaluation points */ |
/* fn == 0 => short of evaluation points */ |
*listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0; |
*listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0; |
Line 604 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
Line 611 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
|
|
q = W_UMALLOC(dx); |
q = W_UMALLOC(dx); |
rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = bound; |
rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = bound; |
fprintf(asir_out,"%d candidates\n",fn); |
if ( debug_sfbfctr ) |
|
fprintf(asir_out,"%d candidates\n",fn); |
init_eg(&eg_hensel); |
init_eg(&eg_hensel); |
for ( i = 0; i < fn-1; i++ ) { |
for ( i = 0; i < fn-1; i++ ) { |
fprintf(asir_out,"deg(fm) = %d, deg(gm[%d]) = %d\n", |
if ( debug_sfbfctr ) |
|
fprintf(asir_out,"deg(fm) = %d, deg(gm[%d]) = %d\n", |
DEG(fm),i,DEG(gm[i])); |
DEG(fm),i,DEG(gm[i])); |
init_eg(&eg_hensel_t); |
init_eg(&eg_hensel_t); |
get_eg(&tmp0); |
get_eg(&tmp0); |
Line 619 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
Line 628 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
cpyum(hm,fm); |
cpyum(hm,fm); |
get_eg(&tmp1); add_eg(&eg_hensel_t,&tmp0,&tmp1); |
get_eg(&tmp1); add_eg(&eg_hensel_t,&tmp0,&tmp1); |
add_eg(&eg_hensel,&tmp0,&tmp1); |
add_eg(&eg_hensel,&tmp0,&tmp1); |
print_eg("Hensel",&eg_hensel_t); |
if ( debug_sfbfctr) { |
|
print_eg("Hensel",&eg_hensel_t); |
|
fprintf(asir_out,"\n"); |
|
} |
|
} |
|
if ( debug_sfbfctr) { |
|
print_eg("Hensel total",&eg_hensel); |
fprintf(asir_out,"\n"); |
fprintf(asir_out,"\n"); |
} |
} |
print_eg("Hensel total",&eg_hensel); |
|
fprintf(asir_out,"\n"); |
|
/* finally, fl must be the lift of gm[fn-1] */ |
/* finally, fl must be the lift of gm[fn-1] */ |
rlist->c[i] = fl; |
rlist->c[i] = fl; |
|
|
Line 640 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
Line 653 void sfhensel(int count,P f,V x,int degbound,GFS *evp, |
|
|
|
/* main variable of f = x */ |
/* main variable of f = x */ |
|
|
int sfberle(VL vl,P f,int count,GFS *ev,DCP *dcp) |
int sfberle(V x,V y,P f,int count,GFS *ev,DCP *dcp) |
{ |
{ |
UM wf,wf1,wf2,wfs,gcd; |
UM wf,wf1,wf2,wfs,gcd; |
int fn,n; |
int fn,n; |
GFS m,fm; |
GFS m,fm; |
DCP dc,dct,dc0; |
DCP dc,dct,dc0; |
VL nvl; |
VL vl; |
V x,y; |
|
P lc,lc0,f0; |
P lc,lc0,f0; |
Obj obj; |
Obj obj; |
int j,q,index,i; |
int j,q,index,i; |
|
|
clctv(vl,f,&nvl); vl = nvl; |
NEWVL(vl); vl->v = x; |
x = vl->v; y = vl->next->v; |
NEWVL(NEXT(vl)); NEXT(vl)->v = y; |
|
NEXT(NEXT(vl)) =0; |
simp_ff((Obj)f,&obj); f = (P)obj; |
simp_ff((Obj)f,&obj); f = (P)obj; |
n = QTOS(DEG(DC(f))); |
n = QTOS(DEG(DC(f))); |
wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n); |
wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n); |
Line 756 void sfhenmain2(BM f,UM g0,UM h0,int dy,BM *gp) |
|
Line 769 void sfhenmain2(BM f,UM g0,UM h0,int dy,BM *gp) |
|
wa = W_UMALLOC(2*dx); wb = W_UMALLOC(2*dx); /* XXX */ |
wa = W_UMALLOC(2*dx); wb = W_UMALLOC(2*dx); /* XXX */ |
eucsfum(w1,w2,wa,wb); |
eucsfum(w1,w2,wa,wb); |
|
|
fprintf(stderr,"dy=%d\n",dy); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"dy=%d\n",dy); |
for ( k = 1; k <= dy; k++ ) { |
for ( k = 1; k <= dy; k++ ) { |
fprintf(stderr,"."); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"."); |
|
|
/* at this point, f = gk*hk mod y^k */ |
/* at this point, f = gk*hk mod y^k */ |
|
|
Line 814 void sfhenmain2(BM f,UM g0,UM h0,int dy,BM *gp) |
|
Line 829 void sfhenmain2(BM f,UM g0,UM h0,int dy,BM *gp) |
|
cpyum(wg1,COEF(gk)[k]); |
cpyum(wg1,COEF(gk)[k]); |
cpyum(wh1,COEF(hk)[k]); |
cpyum(wh1,COEF(hk)[k]); |
} |
} |
fprintf(stderr,"\n"); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"\n"); |
*gp = gk; |
*gp = gk; |
DEG(f) = dy; |
DEG(f) = dy; |
for ( i = 0; i <= dy; i++ ) |
for ( i = 0; i <= dy; i++ ) |
Line 860 void sfexgcd_by_hensel(BM g,BM h,int dy,BM *ap,BM *bp) |
|
Line 876 void sfexgcd_by_hensel(BM g,BM h,int dy,BM *ap,BM *bp) |
|
mulsfbm(a,g,c); mulsfbm(b,h,wz0); addtosfbm(wz0,c); |
mulsfbm(a,g,c); mulsfbm(b,h,wz0); addtosfbm(wz0,c); |
COEF(COEF(c)[0])[0] = 0; |
COEF(COEF(c)[0])[0] = 0; |
|
|
fprintf(stderr,"dy=%d\n",dy); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"dy=%d\n",dy); |
for ( k = 1; k <= dy; k++ ) { |
for ( k = 1; k <= dy; k++ ) { |
fprintf(stderr,"."); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"."); |
|
|
/* at this point, a*g+b*h = 1 mod y^k, c = a*g+b*h-1 */ |
/* at this point, a*g+b*h = 1 mod y^k, c = a*g+b*h-1 */ |
|
|
Line 901 void sfexgcd_by_hensel(BM g,BM h,int dy,BM *ap,BM *bp) |
|
Line 919 void sfexgcd_by_hensel(BM g,BM h,int dy,BM *ap,BM *bp) |
|
cpyum(wa1,COEF(a)[k]); |
cpyum(wa1,COEF(a)[k]); |
cpyum(wb1,COEF(b)[k]); |
cpyum(wb1,COEF(b)[k]); |
} |
} |
fprintf(stderr,"\n"); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"\n"); |
DEG(a) = dy; |
DEG(a) = dy; |
DEG(b) = dy; |
DEG(b) = dy; |
*ap = a; |
*ap = a; |
Line 986 void sfsqfr(P f,DCP *dcp) |
|
Line 1005 void sfsqfr(P f,DCP *dcp) |
|
} else if ( !NEXT(vl) ) |
} else if ( !NEXT(vl) ) |
sfusqfr(f,dcp); |
sfusqfr(f,dcp); |
else |
else |
sqfrsf(f,dcp); |
sqfrsf(vl,f,dcp); |
} |
} |
|
|
void sfusqfr(P f,DCP *dcp) |
void sfusqfr(P f,DCP *dcp) |
Line 1077 void sfbfctr(P f,V x,V y,int degbound,DCP *dcp) |
|
Line 1096 void sfbfctr(P f,V x,V y,int degbound,DCP *dcp) |
|
int dx,dy; |
int dx,dy; |
|
|
/* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ |
/* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ |
sfhensel(5,f,x,degbound,&ev,&sf,&list); |
sfhensel(5,f,x,y,degbound,&ev,&sf,&list); |
if ( list->n == 0 ) |
if ( list->n == 0 ) |
error("sfbfctr : short of evaluation points"); |
error("sfbfctr : short of evaluation points"); |
else if ( list->n == 1 ) { |
else if ( list->n == 1 ) { |
Line 1111 void sfbfctr_shift(P f,V x,V y,int degbound,GFS *evp,P |
|
Line 1130 void sfbfctr_shift(P f,V x,V y,int degbound,GFS *evp,P |
|
int dx,dy; |
int dx,dy; |
|
|
/* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ |
/* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ |
sfhensel(5,f,x,degbound,&ev,&sf,&list); |
sfhensel(5,f,x,y,degbound,&ev,&sf,&list); |
if ( list->n == 0 ) |
if ( list->n == 0 ) |
error("sfbfctr_shift : short of evaluation points"); |
error("sfbfctr_shift : short of evaluation points"); |
else if ( list->n == 1 ) { |
else if ( list->n == 1 ) { |
Line 1199 void sfdtest(P f,ML list,V x,V y,DCP *dcp) |
|
Line 1218 void sfdtest(P f,ML list,V x,V y,DCP *dcp) |
|
} |
} |
} |
} |
|
|
fprintf(stderr,"np = %d\n",np); |
if ( debug_sfbfctr) |
|
fprintf(stderr,"np = %d\n",np); |
dtok = 0; |
dtok = 0; |
for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) { |
for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) { |
if ( !(z % 1000) ) fprintf(stderr,"."); |
if ( debug_sfbfctr && !(z % 1000) ) fprintf(stderr,"."); |
dt = sfdegtest(dy,bound,d1c,k,win); |
dt = sfdegtest(dy,bound,d1c,k,win); |
if ( dt ) |
if ( dt ) |
dtok++; |
dtok++; |
Line 1267 void sfdtest(P f,ML list,V x,V y,DCP *dcp) |
|
Line 1287 void sfdtest(P f,ML list,V x,V y,DCP *dcp) |
|
for ( i = 0, ++k; i < k; i++ ) |
for ( i = 0, ++k; i < k; i++ ) |
win[i] = i + 1; |
win[i] = i + 1; |
} |
} |
fprintf(stderr,"total %d, omitted by degtest %d\n",z,z-dtok); |
if ( debug_sfbfctr ) |
|
fprintf(stderr,"total %d, omitted by degtest %d\n",z,z-dtok); |
NEXTDC(dcf0,dcf); COEF(dcf) = g; |
NEXTDC(dcf0,dcf); COEF(dcf) = g; |
DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0; |
DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0; |
} |
} |