version 1.2, 2001/06/21 07:47:02 |
version 1.7, 2001/06/25 06:10:48 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.1 2001/06/20 09:32:13 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.6 2001/06/25 06:05:16 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
|
|
|
|
} |
} |
} |
} |
|
|
|
/* Hensel related functions */ |
|
|
|
int sfberle(VL,P,int,GFS *,DCP *); |
|
void sfgcdgen(P,ML,ML *); |
|
void sfhenmain(LUM,ML,ML,ML *); |
|
void ptosflum(int,P,LUM); |
|
void sfhenmain2(BM,UM,UM,int,BM *); |
|
void ptosfbm(int,P,BM); |
|
|
|
/* f = f(x,y) */ |
|
|
|
void sfhensel(count,f,x,listp) |
|
int count; |
|
P f; |
|
V x; |
|
ML *listp; |
|
{ |
|
int i,j; |
|
int fn,n,bound; |
|
ML rlist; |
|
BM fl; |
|
VL vl,nvl; |
|
V y; |
|
int dx,dy,mev; |
|
GFS ev; |
|
P f1,t,yev,c; |
|
DCP dc; |
|
UM w,w1,q,fm,hm; |
|
UM *gm; |
|
|
|
clctv(CO,f,&vl); |
|
if ( vl->v != x ) { |
|
reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1); |
|
vl = nvl; f = f1; |
|
} |
|
y = vl->next->v; |
|
dx = getdeg(x,f); |
|
dy = getdeg(y,f); |
|
if ( dx == 1 ) { |
|
*listp = rlist = MLALLOC(1); rlist->n = 1; rlist->c[0] = 0; |
|
return; |
|
} |
|
fn = sfberle(vl,f,count,&ev,&dc); |
|
if ( fn <= 1 ) { |
|
/* fn == 0 => short of evaluation points */ |
|
*listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0; |
|
return; |
|
} |
|
/* pass the the leading coeff. to the first element */ |
|
c = dc->c; dc = NEXT(dc); |
|
mulp(vl,dc->c,c,&t); dc->c = t; |
|
|
|
/* convert mod y-a factors into UM */ |
|
gm = (UM *)ALLOCA(fn*sizeof(UM)); |
|
for ( i = 0; i < fn; i++, dc = NEXT(dc) ) { |
|
gm[i] = W_UMALLOC(UDEG(dc->c)); |
|
ptosfum(dc->c,gm[i]); |
|
} |
|
|
|
bound = dy+1; |
|
/* f(x,y) -> f(x,y+ev) */ |
|
fl = BMALLOC(dx,bound); |
|
ptosfbm(bound,f,fl); |
|
shiftsfbm(bound,fl,FTOIF(CONT(ev))); |
|
|
|
/* fm = fl mod y */ |
|
fm = W_UMALLOC(dx); |
|
cpyum(COEF(fl)[0],fm); |
|
hm = W_UMALLOC(dx); |
|
|
|
q = W_UMALLOC(dx); |
|
rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = bound; |
|
for ( i = 0; i < fn-1; i++ ) { |
|
fprintf(stderr,"%d\n",i); |
|
/* fl = gm[i]*hm mod y */ |
|
divsfum(fm,gm[i],hm); |
|
/* fl is replaced by the cofactor of gk mod y^bound */ |
|
/* rlist->c[i] = gk */ |
|
sfhenmain2(fl,gm[i],hm,bound,(BM *)&rlist->c[i]); |
|
cpyum(hm,fm); |
|
} |
|
/* finally, fl must be the lift of gm[fn-1] */ |
|
rlist->c[i] = fl; |
|
|
|
/* y -> y-a */ |
|
w = W_UMALLOC(bound); |
|
w1 = W_UMALLOC(bound); |
|
mev = _chsgnsf(FTOIF(CONT(ev))); |
|
for ( i = 0; i < fn; i++ ) |
|
shiftsfbm(bound,(BM)(rlist->c[i]),mev); |
|
*listp = rlist; |
|
} |
|
|
|
/* main variable of f = x */ |
|
|
|
int sfberle(vl,f,count,ev,dcp) |
|
VL vl; |
|
P f; |
|
int count; |
|
GFS *ev; |
|
DCP *dcp; |
|
{ |
|
UM wf,wf1,wf2,wfs,gcd; |
|
ML flist; |
|
int fn,fn1,n; |
|
GFS m,fm; |
|
DCP dc,dct,dc0; |
|
VL nvl; |
|
V x,y; |
|
P g,lc,lc0,f0; |
|
int j,q1,index,i; |
|
|
|
clctv(vl,f,&nvl); vl = nvl; |
|
x = vl->v; y = vl->next->v; |
|
simp_ff(f,&g); g = f; |
|
n = QTOS(DEG(DC(f))); |
|
wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n); |
|
wfs = W_UMALLOC(n); gcd = W_UMALLOC(n); |
|
q1 = field_order_sf()-1; |
|
lc = DC(f)->c; |
|
for ( j = 0, fn = n + 1, index = 0; |
|
index < q1 && j < count && fn > 1; index++ ) { |
|
MKGFS(index,m); |
|
substp(vl,lc,y,(P)m,&lc0); |
|
if ( lc0 ) { |
|
substp(vl,f,y,(P)m,&f0); |
|
ptosfum(f0,wf); cpyum(wf,wf1); |
|
diffsfum(wf1,wf2); gcdsfum(wf1,wf2,gcd); |
|
if ( DEG(gcd) == 0 ) { |
|
fctrsf(f0,&dc); |
|
for ( dct = NEXT(dc), i = 0; dct; dct = NEXT(dct), i++ ); |
|
if ( i < fn ) { |
|
dc0 = dc; fn = i; fm = m; |
|
} |
|
j++; |
|
} |
|
} |
|
} |
|
if ( index == q1 ) |
|
return 0; |
|
else if ( fn == 1 ) |
|
return 1; |
|
else { |
|
*dcp = dc0; |
|
*ev = fm; |
|
return fn; |
|
} |
|
} |
|
|
|
void sfgcdgen(f,blist,clistp) |
|
P f; |
|
ML blist,*clistp; |
|
{ |
|
int i; |
|
int n,d,np; |
|
UM wf,wm,wx,wy,wu,wv,wa,wb,wg,q,tum; |
|
UM *in,*out; |
|
ML clist; |
|
|
|
n = UDEG(f); np = blist->n; |
|
d = 2*n; |
|
q = W_UMALLOC(d); wf = W_UMALLOC(d); |
|
wm = W_UMALLOC(d); wx = W_UMALLOC(d); |
|
wy = W_UMALLOC(d); wu = W_UMALLOC(d); |
|
wv = W_UMALLOC(d); wg = W_UMALLOC(d); |
|
wa = W_UMALLOC(d); wb = W_UMALLOC(d); |
|
ptosfum(f,wf); DEG(wg) = 0; COEF(wg)[0] = _onesf(); |
|
*clistp = clist = MLALLOC(np); clist->n = np; |
|
for ( i = 0, in = (UM *)blist->c, out = (UM *)clist->c; i < np; i++ ) { |
|
divsfum(wf,in[i],q); tum = wf; wf = q; q = tum; |
|
cpyum(wf,wx); cpyum(in[i],wy); |
|
eucsfum(wx,wy,wa,wb); mulsfum(wa,wg,wm); |
|
DEG(wm) = divsfum(wm,in[i],q); out[i] = UMALLOC(DEG(wm)); |
|
cpyum(wm,out[i]); mulsfum(q,wf,wu); |
|
mulsfum(wg,wb,wv); addsfum(wu,wv,wg); |
|
} |
|
} |
|
|
|
/* |
|
sfhenmain(fl,bqlist,cqlist,listp) |
|
*/ |
|
|
|
void sfhenmain(f,bqlist,cqlist,listp) |
|
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; |
|
UM g0,h0; |
|
int bound; |
|
BM *gp; |
|
{ |
|
int i,j,k,l; |
|
int *px,*py; |
|
int **pp,**pp1; |
|
int n,np,dr,tmp; |
|
UM wt,wa,wb,wq,wm,q,w1,w2,wh1,wg1,ws; |
|
UM wc,wd,we,wz; |
|
BM wb0,wb1; |
|
int ng,nh; |
|
BM fk,gk,hk; |
|
|
|
n = f->d; |
|
ng = g0->d; |
|
nh = h0->d; |
|
|
|
W_BMALLOC(n,bound,wb0); W_BMALLOC(n,bound,wb1); |
|
wt = W_UMALLOC(n); ws = W_UMALLOC(n); |
|
wq = W_UMALLOC(n); q = W_UMALLOC(2*n); |
|
wg1 = W_UMALLOC(2*n); wh1 = W_UMALLOC(2*n); |
|
|
|
/* fk = gk*hk mod y^k */ |
|
W_BMALLOC(n,bound,fk); cpyum(COEF(f)[0],COEF(fk)[0]); |
|
gk = BMALLOC(ng,bound); cpyum(g0,COEF(gk)[0]); |
|
W_BMALLOC(nh,bound,hk); |
|
cpyum(h0,COEF(hk)[0]); |
|
|
|
wc = W_UMALLOC(2*n); wd = W_UMALLOC(2*n); |
|
we = W_UMALLOC(2*n); wz = W_UMALLOC(2*n); |
|
|
|
/* compute wa,wb s.t. wa*g0+wb*h0 = 1 mod y */ |
|
w1 = W_UMALLOC(ng); cpyum(g0,w1); |
|
w2 = W_UMALLOC(nh); cpyum(h0,w2); |
|
wa = W_UMALLOC(2*n); wb = W_UMALLOC(2*n); /* XXX */ |
|
eucsfum(w1,w2,wa,wb); |
|
|
|
#if 0 |
|
mulsfum(wa,g0,wc); mulsfum(wb,h0,wd); addsfum(wc,wd,we); |
|
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,"."); |
|
|
|
/* 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 */ |
|
bzero(COEF(wt),(n+1)*sizeof(int)); |
|
|
|
/* wt = (f-gk*hk)/y^k */ |
|
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 */ |
|
mulsfum(wa,wt,wh1); DEG(wh1) = divsfum(wh1,h0,q); |
|
mulsfum(wh1,g0,wc); subsfum(wt,wc,wd); DEG(wd) = divsfum(wd,h0,wg1); |
|
|
|
/* check */ |
|
#if 0 |
|
if ( DEG(wd) >= 0 || DEG(wg1) > ng ) |
|
error("henmain2 : cannot happen(adj)"); |
|
|
|
mulsfum(wg1,h0,wc); mulsfum(wh1,g0,wd); addsfum(wc,wd,we); |
|
subsfum(we,wt,wz); |
|
if ( DEG(wz) >= 0 ) |
|
error("henmain2 : cannot happen"); |
|
#endif |
|
|
|
/* fk += ((wg1*hk+wh1*gk)*y^k+wg1*wh1*y^(2*k) mod y^bound */ |
|
/* wb0 = wh1*y^k */ |
|
clearsfbm(bound,n,wb0); |
|
DEG(wb0) = bound; |
|
cpyum(wh1,COEF(wb0)[k]); |
|
|
|
/* wb1 = gk*wb0 mod y^bound */ |
|
clearsfbm(bound,n,wb1); |
|
mulsfbm(bound,gk,wb0,wb1); |
|
/* fk += wb1 */ |
|
addtosfbm(bound,wb1,fk); |
|
|
|
/* wb0 = wg1*y^k */ |
|
clearsfbm(bound,n,wb0); |
|
DEG(wb0) = bound; |
|
cpyum(wg1,COEF(wb0)[k]); |
|
|
|
/* wb1 = hk*wb0 mod y^bound */ |
|
clearsfbm(bound,n,wb1); |
|
mulsfbm(bound,hk,wb0,wb1); |
|
/* fk += wb1 */ |
|
addtosfbm(bound,wb1,fk); |
|
|
|
/* fk += wg1*wh1*y^(2*k) mod y^bound */ |
|
if ( 2*k < bound ) { |
|
mulsfum(wg1,wh1,wt); addsfum(COEF(fk)[2*k],wt,ws); |
|
cpyum(ws,COEF(fk)[2*k]); |
|
} |
|
|
|
/* gk += wg1*y^k, hk += wh1*y^k */ |
|
cpyum(wg1,COEF(gk)[k]); |
|
cpyum(wh1,COEF(hk)[k]); |
|
} |
|
fprintf(stderr,"\n"); |
|
*gp = gk; |
|
DEG(f) = bound; |
|
for ( i = 0; i < bound; 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) */ |
|
|
|
void ptosfbm(bound,f,fl) |
|
int bound; |
|
P f; |
|
BM fl; |
|
{ |
|
DCP dc; |
|
int d,i,n; |
|
UM t; |
|
|
|
DEG(fl) = bound; |
|
t = UMALLOC(bound); |
|
for ( dc = DC(f); dc; dc = NEXT(dc) ) { |
|
d = QTOS(DEG(dc)); |
|
ptosfum(COEF(dc),t); |
|
for ( i = 0; i <= DEG(t); i++ ) |
|
COEF(COEF(fl)[i])[d] = COEF(t)[i]; |
|
} |
|
n = UDEG(f); |
|
for ( i = 0; i <= n; i++ ) |
|
degum(COEF(fl)[i],n); |
|
} |
|
|
|
/* x : main variable */ |
|
|
|
void sflumtop(bound,fl,x,y,fp) |
|
int bound; |
|
LUM fl; |
|
V x,y; |
|
P *fp; |
|
{ |
|
int i,j,n; |
|
int **c; |
|
UM w; |
|
int *coef; |
|
DCP dc,dct; |
|
|
|
n = fl->d; |
|
c = fl->c; |
|
w = W_UMALLOC(bound); |
|
for ( i = 0, dc = 0; i <= n; i++ ) { |
|
coef = c[i]; |
|
for ( j = bound-1; j >= 0 && coef[j] == 0; j-- ); |
|
if ( j < 0 ) |
|
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); |
|
} |
|
|
|
/* x : main variable */ |
|
|
|
void sfbmtop(vl,bound,f,x,y,fp) |
|
VL vl; |
|
int bound; |
|
BM f; |
|
V x,y; |
|
P *fp; |
|
{ |
|
UM *c; |
|
P yv,r,s,t,u,yvd; |
|
Q d; |
|
int i; |
|
|
|
c = f->c; |
|
MKV(y,yv); |
|
r = 0; |
|
for ( i = 0; i < bound; i++ ) { |
|
STOQ(i,d); sfumtop(x,c[i],&t); |
|
pwrp(vl,yv,d,&yvd); |
|
mulp(vl,t,yvd,&s); |
|
addp(vl,r,s,&u); r = u; |
|
} |
|
*fp = r; |
|
} |