version 1.6, 2001/06/25 06:05:16 |
version 1.16, 2001/09/03 01:04:26 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.5 2001/06/25 04:11:42 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.15 2001/08/02 03:59:15 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
|
|
Line 13 void lnfsf(int,UM,UM,struct p_pair *,UM,UM); |
|
Line 13 void lnfsf(int,UM,UM,struct p_pair *,UM,UM); |
|
void minipolysf(UM,UM,UM); |
void minipolysf(UM,UM,UM); |
void czsfum(UM,UM *); |
void czsfum(UM,UM *); |
void gensqfrsfum(UM,DUM); |
void gensqfrsfum(UM,DUM); |
|
void sfbmtop(BM,V,V,P *); |
|
void cont_pp_sfp(VL,P,P *,P *); |
|
void sfcsump(VL,P,P *); |
|
void mulsfbmarray(int,BM,ML,int,int *,V,V,P *); |
|
void const_term(P,UM); |
|
|
|
void sfbsqfr(P,V,V,DCP *); |
|
void sfusqfr(P,DCP *); |
|
|
|
int comp_dum(a,b) |
|
DUM a,b; |
|
{ |
|
if ( DEG(a->f) > DEG(b->f) ) |
|
return -1; |
|
else if ( DEG(a->f) < DEG(b->f) ) |
|
return 1; |
|
else |
|
return 0; |
|
} |
|
|
void fctrsf(p,dcp) |
void fctrsf(p,dcp) |
P p; |
P p; |
DCP *dcp; |
DCP *dcp; |
|
|
} |
} |
} |
} |
udc = udc1; |
udc = udc1; |
|
for ( i = 0; udc[i].f; i++ ); |
|
qsort(udc,i,sizeof(struct oDUM), |
|
(int (*)(const void *,const void *))comp_dum); |
|
|
NEWDC(dc0); COEF(dc0) = lc; DEG(dc0) = ONE; dc = dc0; |
NEWDC(dc0); COEF(dc0) = lc; DEG(dc0) = ONE; dc = dc0; |
for ( n = 0; udc[n].f; n++ ) { |
for ( n = 0; udc[n].f; n++ ) { |
NEWDC(NEXT(dc)); dc = NEXT(dc); |
NEWDC(NEXT(dc)); dc = NEXT(dc); |
|
|
|
|
int sfberle(VL,P,int,GFS *,DCP *); |
int sfberle(VL,P,int,GFS *,DCP *); |
void sfgcdgen(P,ML,ML *); |
void sfgcdgen(P,ML,ML *); |
void sfhenmain(LUM,ML,ML,ML *); |
|
void ptosflum(int,P,LUM); |
|
void sfhenmain2(BM,UM,UM,int,BM *); |
void sfhenmain2(BM,UM,UM,int,BM *); |
void ptosfbm(int,P,BM); |
void ptosfbm(int,P,BM); |
|
|
/* f = f(x,y) */ |
/* f = f(x,y) */ |
|
|
void sfhensel(count,f,x,listp) |
void sfhensel(count,f,x,evp,sfp,listp) |
int count; |
int count; |
P f; |
P f; |
V x; |
V x; |
|
GFS *evp; |
|
P *sfp; |
ML *listp; |
ML *listp; |
{ |
{ |
int i,j; |
int i,j; |
int fn,n,bound; |
int fn,n; |
ML rlist; |
ML rlist; |
BM fl; |
BM fl; |
VL vl,nvl; |
VL vl,nvl; |
V y; |
V y; |
int dx,dy,mev; |
int dx,dy,mev; |
GFS ev; |
GFS ev; |
P f1,t,yev,c; |
P f1,t,yev,c,sf; |
DCP dc; |
DCP dc; |
UM w,w1,q,fm,hm; |
UM w,w1,q,fm,hm; |
UM *gm; |
UM *gm; |
|
struct oEGT tmp0,tmp1,eg_hensel,eg_hensel_t; |
|
|
clctv(CO,f,&vl); |
clctv(CO,f,&vl); |
if ( vl->v != x ) { |
if ( vl->v != x ) { |
|
|
ptosfum(dc->c,gm[i]); |
ptosfum(dc->c,gm[i]); |
} |
} |
|
|
bound = dy+1; |
|
/* f(x,y) -> f(x,y+ev) */ |
/* f(x,y) -> f(x,y+ev) */ |
fl = BMALLOC(dx,bound); |
fl = BMALLOC(dx,dy); |
ptosfbm(bound,f,fl); |
ptosfbm(dy,f,fl); |
shiftsfbm(bound,fl,FTOIF(CONT(ev))); |
if ( ev ) shiftsfbm(fl,FTOIF(CONT(ev))); |
|
|
|
/* sf = f(x+ev) */ |
|
sfbmtop(fl,x,y,&sf); |
|
|
/* fm = fl mod y */ |
/* fm = fl mod y */ |
fm = W_UMALLOC(dx); |
fm = W_UMALLOC(dx); |
cpyum(COEF(fl)[0],fm); |
cpyum(COEF(fl)[0],fm); |
hm = W_UMALLOC(dx); |
hm = W_UMALLOC(dx); |
|
|
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 = dy; |
for ( i = fn-1; i >= 1; i-- ) { |
fprintf(asir_out,"%d candidates\n",fn); |
fprintf(stderr,"%d\n",i); |
init_eg(&eg_hensel); |
|
for ( i = 0; i < fn-1; i++ ) { |
|
fprintf(asir_out,"deg(fm) = %d, deg(gm[%d]) = %d\n", |
|
DEG(fm),i,DEG(gm[i])); |
|
init_eg(&eg_hensel_t); |
|
get_eg(&tmp0); |
/* fl = gm[i]*hm mod y */ |
/* fl = gm[i]*hm mod y */ |
divsfum(fm,gm[i],hm); |
divsfum(fm,gm[i],hm); |
/* fl is replaced by the cofactor of gk mod y^bound */ |
/* fl is replaced by the cofactor of gk mod y^dy */ |
/* rlist->c[i] = gk */ |
/* rlist->c[i] = gk */ |
sfhenmain2(fl,gm[i],hm,bound,(BM *)&rlist->c[i]); |
sfhenmain2(fl,gm[i],hm,dy,(BM *)&rlist->c[i]); |
cpyum(hm,fm); |
cpyum(hm,fm); |
|
get_eg(&tmp1); add_eg(&eg_hensel_t,&tmp0,&tmp1); |
|
add_eg(&eg_hensel,&tmp0,&tmp1); |
|
print_eg("Hensel",&eg_hensel_t); |
|
fprintf(asir_out,"\n"); |
} |
} |
/* finally, fl must be the lift of gm[0] */ |
print_eg("Hensel total",&eg_hensel); |
|
fprintf(asir_out,"\n"); |
|
/* finally, fl must be the lift of gm[fn-1] */ |
rlist->c[i] = fl; |
rlist->c[i] = fl; |
|
|
|
#if 0 |
/* y -> y-a */ |
/* y -> y-a */ |
w = W_UMALLOC(bound); |
|
w1 = W_UMALLOC(bound); |
|
mev = _chsgnsf(FTOIF(CONT(ev))); |
mev = _chsgnsf(FTOIF(CONT(ev))); |
for ( i = 0; i < fn; i++ ) |
for ( i = 0; i < fn; i++ ) |
shiftsfbm(bound,(BM)(rlist->c[i]),mev); |
shiftsfbm((BM)(rlist->c[i]),mev); |
|
#endif |
|
*evp = ev; |
|
*sfp = sf; |
*listp = rlist; |
*listp = rlist; |
} |
} |
|
|
Line 706 ML blist,*clistp; |
|
Line 745 ML blist,*clistp; |
|
} |
} |
} |
} |
|
|
/* |
/* f = g0*h0 mod y -> f = gk*hk mod y^(dy+1), f is replaced by hk */ |
sfhenmain(fl,bqlist,cqlist,listp) |
|
*/ |
|
|
|
void sfhenmain(f,bqlist,cqlist,listp) |
void sfhenmain2(f,g0,h0,dy,gp) |
LUM f; |
|
ML bqlist,cqlist,*listp; |
|
{ |
|
int i,j,k; |
|
int *px,*py; |
|
int **pp,**pp1; |
|
int n,np,bound,dr,tmp; |
|
UM wt,wq0,wq,wr,wm,wm0,wa,q; |
|
LUM wb0,wb1,tlum; |
|
UM *b,*c; |
|
LUM *l; |
|
ML list; |
|
|
|
n = DEG(f); np = bqlist->n; bound = bqlist->bound; |
|
*listp = list = MLALLOC(n); |
|
list->n = np; list->bound = bound; |
|
W_LUMALLOC(n,bound,wb0); W_LUMALLOC(n,bound,wb1); |
|
wt = W_UMALLOC(n); wq0 = W_UMALLOC(n); wq = W_UMALLOC(n); |
|
wr = W_UMALLOC(n); wm = W_UMALLOC(2*n); wm0 = W_UMALLOC(2*n); |
|
wa = W_UMALLOC(2*n); q = W_UMALLOC(2*n); |
|
b = (UM *)bqlist->c; c = (UM *)cqlist->c; l = (LUM *)list->c; |
|
for ( i = 0; i < np; i++ ) { |
|
l[i] = LUMALLOC(DEG(b[i]),bound); |
|
for ( j = DEG(b[i]), pp = COEF(l[i]), px = COEF(b[i]); j >= 0; j-- ) |
|
pp[j][0] = px[j]; |
|
} |
|
for ( i = 1; i < bound; i++ ) { |
|
fprintf(stderr,"."); |
|
/* at this point, f = l[0]*l[1]*...*l[np-1] mod y^i */ |
|
mulsflum(i+1,l[0],l[1],wb0); |
|
for ( j = 2; j < np; j++ ) { |
|
mulsflum(i+1,l[j],wb0,wb1); |
|
tlum = wb0; wb0 = wb1; wb1 = tlum; |
|
} |
|
#if 0 |
|
/* check */ |
|
for ( j = 0, pp = COEF(f), pp1 = COEF(wb0); j <= n; j++ ) |
|
for ( k = 0; k < i; k++ ) |
|
if ( pp[j][k] != pp1[j][k] ) |
|
error("henmain : cannot happen"); |
|
#endif |
|
for ( j = n, px = COEF(wt); j >= 0; j-- ) |
|
px[j] = 0; |
|
for ( j = n, pp = COEF(f), pp1 = COEF(wb0); j >= 0; j-- ) |
|
COEF(wt)[j] = _subsf(pp[j][i],pp1[j][i]); |
|
degum(wt,n); |
|
for ( j = n, px = COEF(wq0); j >= 0; j-- ) |
|
px[j] = 0; |
|
for ( j = 1; j < np; j++ ) { |
|
mulsfum(wt,c[j],wm); dr = divsfum(wm,b[j],q); |
|
for ( k = DEG(q), px = COEF(wq0), py = COEF(q); k >= 0; k-- ) |
|
px[k] = _addsf(px[k],py[k]); |
|
for ( k = dr, pp = COEF(l[j]), px = COEF(wm); k >= 0; k-- ) |
|
pp[k][i] = px[k]; |
|
} |
|
degum(wq0,n); mulsfum(wq0,b[0],wm); |
|
mulsfum(wt,c[0],wm0); addsfum(wm,wm0,wa); |
|
for ( j = DEG(wa), pp = COEF(l[0]), px = COEF(wa); j >= 0; j-- ) |
|
pp[j][i] = px[j]; |
|
for ( j = n, px = COEF(wq0); j >= 0; j-- ) |
|
px[j] = 0; |
|
} |
|
fprintf(stderr,"\n"); |
|
} |
|
|
|
/* f = g0*h0 mod y -> f = gk*hk mod y^bound, f is replaced by hk */ |
|
|
|
void sfhenmain2(f,g0,h0,bound,gp) |
|
BM f; |
BM f; |
UM g0,h0; |
UM g0,h0; |
int bound; |
int dy; |
BM *gp; |
BM *gp; |
{ |
{ |
int i,j,k,l; |
int i,j,k,l; |
int *px,*py; |
int *px,*py; |
int **pp,**pp1; |
int **pp,**pp1; |
int n,np,dr,tmp; |
int dx,np,dr,tmp; |
UM wt,wa,wb,wq,wm,q,w1,w2,wh1,wg1,ws; |
UM wt,wa,wb,wm,q,w1,w2,wh1,wg1,ws; |
UM wc,wd,we,wz; |
UM wc,wd,we,wz; |
BM wb0,wb1; |
BM wb0,wb1; |
int ng,nh; |
int dg,dh; |
BM fk,gk,hk; |
BM fk,gk,hk; |
|
|
n = f->d; |
if ( DEG(f) < dy ) |
ng = g0->d; |
error("sfhenmain2 : invalid input"); |
nh = h0->d; |
|
|
|
W_BMALLOC(n,bound,wb0); W_BMALLOC(n,bound,wb1); |
dx = degbm(f); |
wt = W_UMALLOC(n); ws = W_UMALLOC(n); |
dg = DEG(g0); |
wq = W_UMALLOC(n); q = W_UMALLOC(2*n); |
dh = DEG(h0); |
wg1 = W_UMALLOC(2*n); wh1 = W_UMALLOC(2*n); |
|
|
|
|
W_BMALLOC(dx,dy,wb0); W_BMALLOC(dx,dy,wb1); |
|
wt = W_UMALLOC(dx); ws = W_UMALLOC(dx); q = W_UMALLOC(2*dx); |
|
wg1 = W_UMALLOC(2*dx); wh1 = W_UMALLOC(2*dx); |
|
|
/* fk = gk*hk mod y^k */ |
/* fk = gk*hk mod y^k */ |
W_BMALLOC(n,bound,fk); cpyum(COEF(f)[0],COEF(fk)[0]); |
W_BMALLOC(dx,dy,fk); |
gk = BMALLOC(ng,bound); cpyum(g0,COEF(gk)[0]); |
cpyum(COEF(f)[0],COEF(fk)[0]); |
W_BMALLOC(nh,bound,hk); |
gk = BMALLOC(dg,dy); |
|
cpyum(g0,COEF(gk)[0]); |
|
W_BMALLOC(dh,dy,hk); |
cpyum(h0,COEF(hk)[0]); |
cpyum(h0,COEF(hk)[0]); |
|
|
wc = W_UMALLOC(2*n); wd = W_UMALLOC(2*n); |
wc = W_UMALLOC(2*dx); wd = W_UMALLOC(2*dx); |
we = W_UMALLOC(2*n); wz = W_UMALLOC(2*n); |
we = W_UMALLOC(2*dx); wz = W_UMALLOC(2*dx); |
|
|
/* compute wa,wb s.t. wa*g0+wb*h0 = 1 mod y */ |
/* compute wa,wb s.t. wa*g0+wb*h0 = 1 mod y */ |
w1 = W_UMALLOC(ng); cpyum(g0,w1); |
w1 = W_UMALLOC(dg); cpyum(g0,w1); |
w2 = W_UMALLOC(nh); cpyum(h0,w2); |
w2 = W_UMALLOC(dh); cpyum(h0,w2); |
wa = W_UMALLOC(2*n); wb = W_UMALLOC(2*n); /* XXX */ |
wa = W_UMALLOC(2*dx); wb = W_UMALLOC(2*dx); /* XXX */ |
eucsfum(w1,w2,wa,wb); |
eucsfum(w1,w2,wa,wb); |
|
|
#if 0 |
fprintf(stderr,"dy=%d\n",dy); |
mulsfum(wa,g0,wc); mulsfum(wb,h0,wd); addsfum(wc,wd,we); |
for ( k = 1; k <= dy; k++ ) { |
if ( DEG(we) != 0 || COEF(we)[0] != _onesf() ) |
|
error("henmain2 : cannot happen(euc)"); |
|
#endif |
|
|
|
fprintf(stderr,"bound=%d\n",bound); |
|
for ( k = 1; k < bound; k++ ) { |
|
fprintf(stderr,"."); |
fprintf(stderr,"."); |
|
|
/* at this point, f = gk*hk mod y^k */ |
/* at this point, f = gk*hk mod y^k */ |
#if 0 |
|
for ( j = 0; j < k; j++ ) |
|
if ( !isequalum(COEF(f)[j],COEF(fk)[j]) ) |
|
error("henmain2 : cannot happen(history)"); |
|
#endif |
|
|
|
/* clear wt */ |
/* clear wt */ |
bzero(COEF(wt),(n+1)*sizeof(int)); |
clearum(wt,dx); |
|
|
/* wt = (f-gk*hk)/y^k */ |
/* wt = (f-gk*hk)/y^k */ |
subsfum(COEF(f)[k],COEF(fk)[k],wt); |
subsfum(COEF(f)[k],COEF(fk)[k],wt); |
|
|
/* clear wq */ |
|
bzero(COEF(wq),(n+1)*sizeof(int)); |
|
|
|
/* compute wf1,wg1 s.t. wh1*g0+wg1*h0 = wt */ |
/* compute wf1,wg1 s.t. wh1*g0+wg1*h0 = wt */ |
mulsfum(wa,wt,wh1); DEG(wh1) = divsfum(wh1,h0,q); |
mulsfum(wa,wt,wh1); DEG(wh1) = divsfum(wh1,h0,q); |
mulsfum(wh1,g0,wc); subsfum(wt,wc,wd); DEG(wd) = divsfum(wd,h0,wg1); |
mulsfum(wh1,g0,wc); subsfum(wt,wc,wd); DEG(wd) = divsfum(wd,h0,wg1); |
|
|
error("henmain2 : cannot happen"); |
error("henmain2 : cannot happen"); |
#endif |
#endif |
|
|
/* fk += ((wg1*hk+wh1*gk)*y^k+wg1*wh1*y^(2*k) mod y^bound */ |
/* fk += ((wg1*hk+wh1*gk)*y^k+wg1*wh1*y^(2*k) mod y^(dy+1) */ |
/* wb0 = wh1*y^k */ |
/* wb0 = wh1*y^k */ |
clearsfbm(bound,n,wb0); |
clearbm(dx,wb0); |
DEG(wb0) = bound; |
|
cpyum(wh1,COEF(wb0)[k]); |
cpyum(wh1,COEF(wb0)[k]); |
|
|
/* wb1 = gk*wb0 mod y^bound */ |
/* wb1 = gk*wb0 mod y^(dy+1) */ |
clearsfbm(bound,n,wb1); |
clearbm(dx,wb1); |
mulsfbm(bound,gk,wb0,wb1); |
mulsfbm(gk,wb0,wb1); |
/* fk += wb1 */ |
/* fk += wb1 */ |
addtosfbm(bound,wb1,fk); |
addtosfbm(wb1,fk); |
|
|
/* wb0 = wg1*y^k */ |
/* wb0 = wg1*y^k */ |
clearsfbm(bound,n,wb0); |
clearbm(dx,wb0); |
DEG(wb0) = bound; |
|
cpyum(wg1,COEF(wb0)[k]); |
cpyum(wg1,COEF(wb0)[k]); |
|
|
/* wb1 = hk*wb0 mod y^bound */ |
/* wb1 = hk*wb0 mod y^(dy+1) */ |
clearsfbm(bound,n,wb1); |
clearbm(dx,wb1); |
mulsfbm(bound,hk,wb0,wb1); |
mulsfbm(hk,wb0,wb1); |
/* fk += wb1 */ |
/* fk += wb1 */ |
addtosfbm(bound,wb1,fk); |
addtosfbm(wb1,fk); |
|
|
/* fk += wg1*wh1*y^(2*k) mod y^bound */ |
/* fk += wg1*wh1*y^(2*k) mod y^(dy+1) */ |
if ( 2*k < bound ) { |
if ( 2*k <= dy ) { |
mulsfum(wg1,wh1,wt); addsfum(COEF(fk)[2*k],wt,ws); |
mulsfum(wg1,wh1,wt); addsfum(COEF(fk)[2*k],wt,ws); |
cpyum(ws,COEF(fk)[2*k]); |
cpyum(ws,COEF(fk)[2*k]); |
} |
} |
|
|
} |
} |
fprintf(stderr,"\n"); |
fprintf(stderr,"\n"); |
*gp = gk; |
*gp = gk; |
DEG(f) = bound; |
DEG(f) = dy; |
for ( i = 0; i < bound; i++ ) |
for ( i = 0; i <= dy; i++ ) |
cpyum(COEF(hk)[i],COEF(f)[i]); |
cpyum(COEF(hk)[i],COEF(f)[i]); |
} |
} |
|
|
void ptosflum(bound,f,fl) |
|
int bound; |
|
P f; |
|
LUM fl; |
|
{ |
|
DCP dc; |
|
int **pp; |
|
int d; |
|
UM t; |
|
|
|
t = UMALLOC(bound); |
|
for ( dc = DC(f), pp = COEF(fl); dc; dc = NEXT(dc) ) { |
|
d = QTOS(DEG(dc)); |
|
ptosfum(COEF(dc),t); |
|
bcopy(t->c,pp[d],(t->d+1)*sizeof(int)); |
|
} |
|
} |
|
|
|
/* fl->c[i] = coef_y(f,i) */ |
/* fl->c[i] = coef_y(f,i) */ |
|
|
void ptosfbm(bound,f,fl) |
void ptosfbm(dy,f,fl) |
int bound; |
int dy; |
P f; |
P f; |
BM fl; |
BM fl; |
{ |
{ |
DCP dc; |
DCP dc; |
int d,i,n; |
int d,i,dx; |
UM t; |
UM t; |
|
|
DEG(fl) = bound; |
dx = QTOS(DEG(DC(f))); |
t = UMALLOC(bound); |
if ( DEG(fl) < dy ) |
|
error("ptosfbm : invalid input"); |
|
DEG(fl) = dy; |
|
clearbm(dx,fl); |
|
t = UMALLOC(dy); |
for ( dc = DC(f); dc; dc = NEXT(dc) ) { |
for ( dc = DC(f); dc; dc = NEXT(dc) ) { |
d = QTOS(DEG(dc)); |
d = QTOS(DEG(dc)); |
ptosfum(COEF(dc),t); |
ptosfum(COEF(dc),t); |
for ( i = 0; i <= DEG(t); i++ ) |
for ( i = 0; i <= DEG(t); i++ ) |
COEF(COEF(fl)[i])[d] = COEF(t)[i]; |
COEF(COEF(fl)[i])[d] = COEF(t)[i]; |
} |
} |
n = UDEG(f); |
for ( i = 0; i <= dy; i++ ) |
for ( i = 0; i <= n; i++ ) |
degum(COEF(fl)[i],dx); |
degum(COEF(fl)[i],n); |
|
} |
} |
|
|
/* x : main variable */ |
/* x : main variable */ |
|
|
void sflumtop(bound,fl,x,y,fp) |
void sfbmtop(f,x,y,fp) |
int bound; |
BM f; |
LUM fl; |
|
V x,y; |
V x,y; |
P *fp; |
P *fp; |
{ |
{ |
int i,j,n; |
UM *c; |
int **c; |
int i,j,d,a,dy; |
UM w; |
GFS b; |
int *coef; |
DCP dc0,dc,dct; |
|
|
|
dy = DEG(f); |
|
c = COEF(f); |
|
d = degbm(f); |
|
|
|
dc0 = 0; |
|
for ( i = 0; i <= d; i++ ) { |
|
dc = 0; |
|
for ( j = 0; j <= dy; j++ ) { |
|
if ( DEG(c[j]) >= i && (a = COEF(c[j])[i]) ) { |
|
NEWDC(dct); |
|
STOQ(j,DEG(dct)); |
|
MKGFS(IFTOF(a),b); |
|
COEF(dct) = (P)b; |
|
NEXT(dct) = dc; |
|
dc = dct; |
|
} |
|
} |
|
if ( dc ) { |
|
NEWDC(dct); |
|
STOQ(i,DEG(dct)); |
|
MKP(y,dc,COEF(dct)); |
|
NEXT(dct) = dc0; |
|
dc0 = dct; |
|
} |
|
} |
|
if ( dc0 ) |
|
MKP(x,dc0,*fp); |
|
else |
|
*fp = 0; |
|
} |
|
|
|
void sfsqfr(f,dcp) |
|
P f; |
|
DCP *dcp; |
|
{ |
|
P g; |
|
V x; |
|
DCP dc; |
|
VL vl; |
|
|
|
simp_ff(f,&g); f = g; |
|
clctv(CO,f,&vl); |
|
if ( !vl ) { |
|
/* f is a const */ |
|
NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; *dcp = dc; |
|
} else if ( !NEXT(vl) ) |
|
sfusqfr(f,dcp); |
|
else if ( !NEXT(NEXT(vl)) ) |
|
sfbsqfr(f,x,NEXT(vl)->v,dcp); |
|
else |
|
error("sfsqfr : not implemented yet"); |
|
} |
|
|
|
void sfusqfr(f,dcp) |
|
P f; |
|
DCP *dcp; |
|
{ |
DCP dc,dct; |
DCP dc,dct; |
|
struct oDUM *udc; |
|
V x; |
|
P lc; |
|
int n,i; |
|
UM mf; |
|
|
n = fl->d; |
x = VR(f); |
c = fl->c; |
n = getdeg(x,f); |
w = W_UMALLOC(bound); |
mf = W_UMALLOC(n); |
for ( i = 0, dc = 0; i <= n; i++ ) { |
ptosfum(f,mf); |
coef = c[i]; |
lc = COEF(DC(f)); |
for ( j = bound-1; j >= 0 && coef[j] == 0; j-- ); |
if ( !_isonesf(COEF(mf)[n]) ) { |
if ( j < 0 ) |
monicsfum(mf); |
continue; |
|
DEG(w) = j; bcopy(coef,COEF(w),(j+1)*sizeof(int)); |
|
NEWDC(dct); STOQ(i,DEG(dct)); |
|
sfumtop(y,w,&COEF(dct)); NEXT(dct) = dc; dc = dct; |
|
} |
} |
MKP(x,dc,*fp); |
W_CALLOC(n+1,struct oDUM,udc); |
|
gensqfrsfum(mf,udc); |
|
for ( i = 0, dc = 0; udc[i].f; i++ ) { |
|
NEWDC(dct); STOQ(udc[i].n,DEG(dct)); |
|
sfumtop(x,udc[i].f,&COEF(dct)); |
|
NEXT(dct) = dc; dc = dct; |
|
} |
|
NEWDC(dct); DEG(dct) = ONE; COEF(dct) = (P)lc; NEXT(dct) = dc; |
|
*dcp = dct; |
} |
} |
|
|
/* x : main variable */ |
void sfbsqfr(f,x,y,dcp) |
|
P f; |
|
V x,y; |
|
DCP *dcp; |
|
{ |
|
P t,rf,cx,cy; |
|
VL vl,rvl; |
|
DCP dcx,dcy; |
|
struct oVL vl0,vl1; |
|
|
void sfbmtop(vl,bound,f,x,y,fp) |
/* vl = [x,y] */ |
|
vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0; |
|
/* cy(y) = cont(f,x), f /= cx */ |
|
cont_pp_sfp(vl,f,&cy,&t); f = t; |
|
/* rvl = [y,x] */ |
|
reordvar(vl,y,&rvl); reorderp(rvl,vl,f,&rf); |
|
/* cx(x) = cont(rf,y), Rf /= cy */ |
|
cont_pp_sfp(rvl,rf,&cx,&t); rf = t; |
|
reorderp(vl,rvl,rf,&f); |
|
|
|
/* f -> cx*cy*f */ |
|
sfusqfr(cx,&dcx); |
|
sfusqfr(cy,&dcy); |
|
} |
|
|
|
void sfdtest(P,ML,V,V,DCP *); |
|
|
|
void sfbfctr(f,x,y,dcp) |
|
P f; |
|
V x,y; |
|
DCP *dcp; |
|
{ |
|
ML list; |
|
P sf; |
|
GFS ev; |
|
DCP dc,dct; |
|
BM fl; |
|
int dx,dy; |
|
|
|
/* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ |
|
sfhensel(5,f,x,&ev,&sf,&list); |
|
if ( list->n == 0 ) |
|
error("sfbfctr : short of evaluation points"); |
|
else if ( list->n == 1 ) { |
|
/* f is irreducible */ |
|
NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; |
|
*dcp = dc; |
|
return; |
|
} |
|
sfdtest(sf,list,x,y,&dc); |
|
if ( ev ) { |
|
dx = getdeg(x,sf); |
|
dy = getdeg(y,sf); |
|
W_BMALLOC(dx,dy,fl); |
|
for ( dct = dc; dct; dct = NEXT(dct) ) { |
|
ptosfbm(dy,COEF(dct),fl); |
|
shiftsfbm(fl,_chsgnsf(FTOIF(CONT(ev)))); |
|
sfbmtop(fl,x,y,&COEF(dct)); |
|
} |
|
} |
|
*dcp = dc; |
|
} |
|
|
|
/* f = f(x,y) = list->c[0]*list->c[1]*... mod y^(list->bound+1) */ |
|
|
|
void sfdtest(f,list,x,y,dcp) |
|
P f; |
|
ML list; |
|
V x,y; |
|
DCP *dcp; |
|
{ |
|
int np,dx,dy; |
|
int i,j,k; |
|
int *win; |
|
P g,lcg,factor,cofactor,lcyx; |
|
P t,csum; |
|
DCP dcf,dcf0,dc; |
|
BM *c; |
|
BM lcy; |
|
UM lcg0; |
|
ML wlist; |
|
struct oVL vl1,vl0; |
|
VL vl; |
|
int z; |
|
|
|
/* vl = [x,y] */ |
|
vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0; |
|
|
|
/* setup various structures and arrays */ |
|
dx = getdeg(x,f); |
|
dy = getdeg(y,f); |
|
np = list->n; |
|
win = W_ALLOC(np+1); |
|
wlist = W_MLALLOC(np); |
|
wlist->n = list->n; |
|
wlist->bound = dy; |
|
c = (BM *)COEF(wlist); |
|
bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np)); |
|
|
|
lcg0 = W_UMALLOC(2*dy); |
|
|
|
/* initialize g by f */ |
|
g = f; |
|
|
|
/* initialize lcg */ |
|
mulp(vl,g,COEF(DC(g)),&lcg); |
|
|
|
/* initialize lcg0 */ |
|
const_term(lcg,lcg0); |
|
|
|
/* initialize csum = lcg(1) */ |
|
sfcsump(vl,lcg,&csum); |
|
|
|
/* initialize lcy by LC(f) */ |
|
W_BMALLOC(0,dy,lcy); |
|
NEWDC(dc); COEF(dc) = COEF(DC(g)); DEG(dc) = 0; |
|
NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc; |
|
ptosfbm(dy,lcyx,lcy); |
|
|
|
fprintf(stderr,"np = %d\n",np); |
|
for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) { |
|
if ( !(z % 1000) ) fprintf(stderr,"."); |
|
if ( sfdtestmain(vl,lcg,lcg0,lcy,csum,wlist,k,win,&factor,&cofactor) ) { |
|
NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor; |
|
g = cofactor; |
|
|
|
/* update lcg */ |
|
mulp(vl,g,COEF(DC(g)),&lcg); |
|
|
|
/* update lcg0 */ |
|
const_term(lcg,lcg0); |
|
|
|
/* update csum */ |
|
sfcsump(vl,lcg,&csum); |
|
|
|
/* update lcy */ |
|
clearbm(0,lcy); |
|
COEF(dc) = COEF(DC(g)); |
|
ptosfbm(dy,lcyx,lcy); |
|
|
|
for ( i = 0; i < k - 1; i++ ) |
|
for ( j = win[i] + 1; j < win[i + 1]; j++ ) |
|
c[j-i-1] = c[j]; |
|
for ( j = win[k-1] + 1; j <= np; j++ ) |
|
c[j-k] = c[j]; |
|
if ( ( np -= k ) < k ) |
|
break; |
|
if ( np - win[0] + 1 < k ) |
|
if ( ++k > np ) |
|
break; |
|
else |
|
for ( i = 0; i < k; i++ ) |
|
win[i] = i + 1; |
|
else |
|
for ( i = 1; i < k; i++ ) |
|
win[i] = win[0] + i; |
|
} else if ( !ncombi(1,np,k,win) ) |
|
if ( k == np ) |
|
break; |
|
else |
|
for ( i = 0, ++k; i < k; i++ ) |
|
win[i] = i + 1; |
|
} |
|
fprintf(stderr,"\n"); |
|
NEXTDC(dcf0,dcf); COEF(dcf) = g; |
|
DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0; |
|
} |
|
|
|
/* lcy = LC(g), lcg = lcy*g, lcg0 = const part of lcg */ |
|
int sfdtestmain(vl,lcg,lcg0,lcy,csum,list,k,in,fp,cofp) |
VL vl; |
VL vl; |
int bound; |
P lcg; |
|
UM lcg0; |
|
BM lcy; |
|
P csum; |
|
ML list; |
|
int k; |
|
int *in; |
|
P *fp,*cofp; |
|
{ |
|
P fmul,csumg,q,cont; |
|
V x,y; |
|
|
|
x = vl->v; |
|
y = vl->next->v; |
|
if (!sfctest(lcg0,lcy,list,k,in)) |
|
return 0; |
|
mulsfbmarray(UDEG(lcg),lcy,list,k,in,x,y,&fmul); |
|
if ( csum ) { |
|
sfcsump(vl,fmul,&csumg); |
|
if ( csumg ) { |
|
if ( !divtp(vl,csum,csumg,&q) ) |
|
return 0; |
|
} |
|
} |
|
if ( divtp_by_sfbm(vl,lcg,fmul,&q) ) { |
|
cont_pp_sfp(vl,fmul,&cont,fp); |
|
cont_pp_sfp(vl,q,&cont,cofp); |
|
return 1; |
|
} else |
|
return 0; |
|
} |
|
|
|
void const_term(f,c) |
|
P f; |
|
UM c; |
|
{ |
|
DCP dc; |
|
|
|
for ( dc = DC(f); dc && DEG(dc); dc = NEXT(dc) ); |
|
if ( dc ) |
|
ptosfum(COEF(dc),c); |
|
else |
|
DEG(c) = -1; |
|
} |
|
|
|
void const_term_sfbm(f,c) |
BM f; |
BM f; |
|
UM c; |
|
{ |
|
int i,dy; |
|
|
|
dy = DEG(f); |
|
for ( i = 0; i <= dy; i++ ) |
|
if ( DEG(COEF(f)[i]) >= 0 ) |
|
COEF(c)[i] = COEF(COEF(f)[i])[0]; |
|
else |
|
COEF(c)[i] = 0; |
|
degum(c,dy); |
|
} |
|
|
|
/* lcy*(product of const part) | lcg0 ? */ |
|
|
|
int sfctest(lcg0,lcy,list,k,in) |
|
UM lcg0; |
|
BM lcy; |
|
ML list; |
|
int k; |
|
int *in; |
|
{ |
|
DCP dc; |
|
int dy,i,dr; |
|
UM t,s,u,w; |
|
BM *l; |
|
|
|
dy = list->bound; |
|
t = W_UMALLOC(2*dy); |
|
s = W_UMALLOC(2*dy); |
|
u = W_UMALLOC(2*dy); |
|
const_term_sfbm(lcy,t); |
|
if ( DEG(t) < 0 ) |
|
return 1; |
|
|
|
l = (BM *)list->c; |
|
for ( i = 0; i < k; i++ ) { |
|
const_term_sfbm(l[in[i]],s); |
|
mulsfum(t,s,u); |
|
if ( DEG(u) > dy ) |
|
degum(u,dy); |
|
w = t; t = u; u = w; |
|
} |
|
cpyum(lcg0,s); |
|
dr = divsfum(s,t,u); |
|
if ( dr >= 0 ) |
|
return 0; |
|
else |
|
return 1; |
|
} |
|
|
|
/* main var of f is x */ |
|
|
|
void mulsfbmarray(dx,lcy,list,k,in,x,y,g) |
|
int dx; |
|
BM lcy; |
|
ML list; |
|
int k; |
|
int *in; |
V x,y; |
V x,y; |
P *fp; |
P *g; |
{ |
{ |
UM *c; |
int dy,i; |
P yv,r,s,t,u,yvd; |
BM wb0,wb1,t,lcbm; |
Q d; |
BM *l; |
int i; |
|
|
|
c = f->c; |
dy = list->bound; |
MKV(y,yv); |
W_BMALLOC(dx,dy,wb0); W_BMALLOC(dx,dy,wb1); |
r = 0; |
l = (BM *)list->c; |
for ( i = 0; i < bound; i++ ) { |
clearbm(dx,wb0); |
STOQ(i,d); sfumtop(x,c[i],&t); |
mulsfbm(lcy,l[in[0]],wb0); |
pwrp(vl,yv,d,&yvd); |
for ( i = 1; i < k; i++ ) { |
mulp(vl,t,yvd,&s); |
clearbm(dx,wb1); |
addp(vl,r,s,&u); r = u; |
mulsfbm(l[in[i]],wb0,wb1); |
|
t = wb0; wb0 = wb1; wb1 = t; |
} |
} |
*fp = r; |
sfbmtop(wb0,x,y,g); |
|
} |
|
|
|
void sfcsump(vl,f,s) |
|
VL vl; |
|
P f; |
|
P *s; |
|
{ |
|
P t,u; |
|
DCP dc; |
|
|
|
for ( dc = DC(f), t = 0; dc; dc = NEXT(dc) ) { |
|
addp(vl,COEF(dc),t,&u); t = u; |
|
} |
|
*s = t; |
|
} |
|
|
|
/* *fp = primitive part of f w.r.t. x */ |
|
|
|
void cont_pp_sfp(vl,f,cp,fp) |
|
VL vl; |
|
P f; |
|
P *cp,*fp; |
|
{ |
|
V x,y; |
|
int d; |
|
UM t,s,gcd; |
|
DCP dc; |
|
GFS g; |
|
|
|
x = vl->v; |
|
y = vl->next->v; |
|
d = getdeg(y,f); |
|
if ( d == 0 ) { |
|
MKGFS(0,g); |
|
*cp = (P)g; |
|
*fp = f; /* XXX */ |
|
} else { |
|
t = W_UMALLOC(2*d); |
|
s = W_UMALLOC(2*d); |
|
gcd = W_UMALLOC(2*d); |
|
dc = DC(f); |
|
ptosfum(COEF(dc),gcd); |
|
for ( dc = NEXT(dc); dc; dc = NEXT(dc) ) { |
|
ptosfum(COEF(dc),t); |
|
gcdsfum(gcd,t,s); |
|
cpyum(s,gcd); |
|
} |
|
sfumtop(y,gcd,cp); |
|
divsp(vl,f,*cp,fp); |
|
} |
|
} |
|
|
|
int divtp_by_sfbm(vl,f,g,qp) |
|
VL vl; |
|
P f,g; |
|
P *qp; |
|
{ |
|
V x,y; |
|
int fx,fy,gx,gy; |
|
BM fl,gl,ql; |
|
UM *cf,*cg,*cq; |
|
UM hg,q,t,s; |
|
int i,j,dr; |
|
|
|
x = vl->v; y = vl->next->v; |
|
fx = getdeg(x,f); fy = getdeg(y,f); |
|
gx = getdeg(x,g); gy = getdeg(y,g); |
|
|
|
if ( fx < gx || fy < gy ) |
|
return 0; |
|
W_BMALLOC(fx,fy,fl); ptosfbm(fy,f,fl); cf = COEF(fl); |
|
W_BMALLOC(gx,gy,gl); ptosfbm(gy,g,gl); cg = COEF(gl); |
|
W_BMALLOC(fx-gx,fy-gy,ql); cq = COEF(ql); |
|
|
|
hg = cg[gy]; |
|
q = W_UMALLOC(fx); t = W_UMALLOC(fx); s = W_UMALLOC(fx); |
|
|
|
for ( i = fy; i >= gy; i-- ) { |
|
if ( DEG(cf[i]) < 0 ) |
|
continue; |
|
dr = divsfum(cf[i],hg,q); |
|
if ( dr >= 0 ) |
|
return 0; |
|
if ( DEG(q) > fx-gx ) |
|
return 0; |
|
cpyum(q,cq[i-gy]); |
|
for ( j = 0; j <= gy; j++ ) { |
|
mulsfum(cg[j],q,t); |
|
subsfum(cf[j+i-gy],t,s); |
|
cpyum(s,cf[j+i-gy]); |
|
} |
|
} |
|
for ( j = gy-1; j >= 0 && DEG(cf[j]) < 0; j-- ); |
|
if ( j >= 0 ) |
|
return 0; |
|
sfbmtop(ql,x,y,qp); |
|
} |
|
|
|
/* XXX generate an irreducible poly of degree n */ |
|
|
|
void generate_defpoly_sfum(n,dp) |
|
int n; |
|
UM *dp; |
|
{ |
} |
} |