version 1.8, 2001/06/25 10:01:28 |
version 1.12, 2001/06/27 04:07:57 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.7 2001/06/25 06:10:48 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.11 2001/06/26 09:47:05 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
|
|
Line 17 void sfbmtop(int,BM,V,V,P *); |
|
Line 17 void sfbmtop(int,BM,V,V,P *); |
|
void pp_sfp(VL,P,P *); |
void pp_sfp(VL,P,P *); |
void sfcsump(VL,P,P *); |
void sfcsump(VL,P,P *); |
void mulsfbmarray(int,BM,ML,int,int *,V,V,P *); |
void mulsfbmarray(int,BM,ML,int,int *,V,V,P *); |
|
void const_term(P,UM); |
|
|
|
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); |
|
|
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 ) { |
|
|
|
|
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); |
|
init_eg(&eg_hensel); |
for ( i = 0; i < fn-1; i++ ) { |
for ( i = 0; i < fn-1; i++ ) { |
fprintf(stderr,"%d\n",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^bound */ |
/* rlist->c[i] = gk */ |
/* rlist->c[i] = gk */ |
sfhenmain2(fl,gm[i],hm,bound,(BM *)&rlist->c[i]); |
sfhenmain2(fl,gm[i],hm,bound,(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"); |
} |
} |
|
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; |
|
|
|
|
int d,i,n; |
int d,i,n; |
UM t; |
UM t; |
|
|
|
n = QTOS(DEG(DC(f))); |
|
clearsfbm(bound,n,fl); |
DEG(fl) = bound; |
DEG(fl) = bound; |
t = UMALLOC(bound); |
t = UMALLOC(bound); |
for ( dc = DC(f); dc; dc = NEXT(dc) ) { |
for ( dc = DC(f); dc; dc = NEXT(dc) ) { |
|
|
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 = QTOS(DEG(DC(f))); |
|
for ( i = 0; i < bound; i++ ) |
for ( i = 0; i < bound; i++ ) |
degum(COEF(fl)[i],n); |
degum(COEF(fl)[i],n); |
} |
} |
|
|
|
|
void sfdtest(P,ML,V,V,DCP *); |
void sfdtest(P,ML,V,V,DCP *); |
|
|
void sfbfctr(f,x,y,evp,dcp) |
void sfbfctr(f,x,y,dcp) |
P f; |
P f; |
V x,y; |
V x,y; |
GFS *evp; |
|
DCP *dcp; |
DCP *dcp; |
{ |
{ |
ML list; |
ML list; |
P sf; |
P sf; |
|
GFS ev; |
|
DCP dc,dct; |
|
BM fl; |
|
int n,bound; |
|
|
/* 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,evp,&sf,&list); |
sfhensel(5,f,x,&ev,&sf,&list); |
sfdtest(sf,list,x,y,dcp); |
sfdtest(sf,list,x,y,&dc); |
|
n = getdeg(x,sf); |
|
bound = list->bound; |
|
W_BMALLOC(n,bound,fl); |
|
for ( dct = dc; dct; dct = NEXT(dct) ) { |
|
ptosfbm(bound,COEF(dct),fl); |
|
shiftsfbm(bound,fl,_chsgnsf(FTOIF(CONT(ev)))); |
|
sfbmtop(bound,fl,x,y,&COEF(dct)); |
|
} |
|
*dcp = dc; |
} |
} |
|
|
/* f = f(x,y) = list->c[0]*list->c[1]*... mod y^list->bound */ |
/* f = f(x,y) = list->c[0]*list->c[1]*... mod y^list->bound */ |
|
|
int i,j,k; |
int i,j,k; |
int *win; |
int *win; |
P g,lcg,factor,cofactor,lcyx; |
P g,lcg,factor,cofactor,lcyx; |
P csum,csumt; |
P t,csum; |
DCP dcf,dcf0,dc; |
DCP dcf,dcf0,dc; |
BM *c; |
BM *c; |
BM lcy; |
BM lcy; |
|
UM lcg0; |
ML wlist; |
ML wlist; |
struct oVL vl1,vl0; |
struct oVL vl1,vl0; |
VL vl; |
VL vl; |
|
|
/* vl = [x,y] */ |
/* vl = [x,y] */ |
vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0; |
vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0; |
|
|
|
/* setup various structures and arrays */ |
n = UDEG(f); np = list->n; bound = list->bound; win = W_ALLOC(np+1); |
n = UDEG(f); np = list->n; bound = list->bound; win = W_ALLOC(np+1); |
|
|
/* csum = lc(f)*f(1) */ |
|
sfcsump(vl,f,&csum); mulp(vl,csum,COEF(DC(f)),&csumt); csum = csumt; |
|
|
|
wlist = W_MLALLOC(np); wlist->n = list->n; |
wlist = W_MLALLOC(np); wlist->n = list->n; |
wlist->bound = list->bound; |
wlist->bound = list->bound; |
c = (BM *)COEF(wlist); |
c = (BM *)COEF(wlist); |
bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np)); |
bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np)); |
|
|
|
lcg0 = W_UMALLOC(2*bound); |
|
|
/* initialize g by f */ |
/* initialize g by f */ |
g = f; mulp(vl,g,COEF(DC(g)),&lcg); |
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) */ |
/* initialize lcy by LC(f) */ |
W_BMALLOC(0,bound,lcy); |
W_BMALLOC(0,bound,lcy); |
NEWDC(dc); COEF(dc) = COEF(DC(g)); |
NEWDC(dc); COEF(dc) = COEF(DC(g)); DEG(dc) = 0; |
DEG(dc) = 0; |
|
NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc; |
NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc; |
ptosfbm(bound,lcyx,lcy); |
ptosfbm(bound,lcyx,lcy); |
|
|
fprintf(stderr,"np = %d\n",np); |
fprintf(stderr,"np = %d\n",np); |
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 ( !(z % 1000) ) fprintf(stderr,"."); |
if ( sfdtestmain(vl,lcg,lcy,csum,wlist,k,win,&factor,&cofactor) ) { |
if ( sfdtestmain(vl,lcg,lcg0,lcy,csum,wlist,k,win,&factor,&cofactor) ) { |
NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor; |
NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor; |
g = cofactor; |
g = cofactor; |
|
|
/* update csum */ |
|
sfcsump(vl,g,&csum); mulp(vl,csum,COEF(DC(g)),&csumt); csum = csumt; |
|
|
|
/* update lcg */ |
/* update lcg */ |
mulp(vl,g,COEF(DC(g)),&lcg); |
mulp(vl,g,COEF(DC(g)),&lcg); |
|
|
|
/* update lcg0 */ |
|
const_term(lcg,lcg0); |
|
|
|
/* update csum */ |
|
sfcsump(vl,lcg,&csum); |
|
|
/* update lcy */ |
/* update lcy */ |
clearsfbm(bound,0,lcy); |
clearsfbm(bound,0,lcy); |
COEF(dc) = COEF(DC(g)); ptosfbm(bound,lcyx,lcy); |
COEF(dc) = COEF(DC(g)); ptosfbm(bound,lcyx,lcy); |
|
|
DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0; |
DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0; |
} |
} |
|
|
/* lcy = LC(g), lcg = lcy*g */ |
/* lcy = LC(g), lcg = lcy*g, lcg0 = const part of lcg */ |
int sfdtestmain(vl,lcg,lcy,csum,list,k,in,fp,cofp) |
int sfdtestmain(vl,lcg,lcg0,lcy,csum,list,k,in,fp,cofp) |
VL vl; |
VL vl; |
P lcg; |
P lcg; |
|
UM lcg0; |
BM lcy; |
BM lcy; |
P csum; |
P csum; |
ML list; |
ML list; |
|
|
|
|
x = vl->v; |
x = vl->v; |
y = vl->next->v; |
y = vl->next->v; |
#if 0 |
if (!sfctest(lcg0,lcy,list,k,in)) |
if (!sfctest(g,list,k,in)) |
|
return 0; |
return 0; |
#endif |
|
mulsfbmarray(UDEG(lcg),lcy,list,k,in,x,y,&fmul); |
mulsfbmarray(UDEG(lcg),lcy,list,k,in,x,y,&fmul); |
if ( csum ) { |
if ( csum ) { |
sfcsump(vl,fmul,&csumg); |
sfcsump(vl,fmul,&csumg); |
|
|
return 0; |
return 0; |
} |
} |
} |
} |
if ( divtp(vl,lcg,fmul,&q) ) { |
if ( divtp_by_sfbm(vl,lcg,fmul,&q) ) { |
pp_sfp(vl,fmul,fp); |
pp_sfp(vl,fmul,fp); |
pp_sfp(vl,q,cofp); |
pp_sfp(vl,q,cofp); |
return 1; |
return 1; |
|
|
return 0; |
return 0; |
} |
} |
|
|
#if 0 |
void const_term(f,c) |
int sfctest(g,list,k,in) |
P f; |
P g; |
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,bound,c) |
|
BM f; |
|
int bound; |
|
UM c; |
|
{ |
|
int i; |
|
|
|
for ( i = 0; i < bound; i++ ) |
|
if ( DEG(COEF(f)[i]) >= 0 ) |
|
COEF(c)[i] = COEF(COEF(f)[i])[0]; |
|
else |
|
COEF(c)[i] = 0; |
|
degum(c,bound-1); |
|
} |
|
|
|
/* lcy*(product of const part) | lcg0 ? */ |
|
|
|
int sfctest(lcg0,lcy,list,k,in) |
|
UM lcg0; |
|
BM lcy; |
ML list; |
ML list; |
int k; |
int k; |
int *in; |
int *in; |
{ |
{ |
register int i; |
|
int q,bound; |
|
int *wm,*wm1,*tmpp; |
|
DCP dc; |
DCP dc; |
Q dvr; |
int bound,i,dr; |
N lcn,cstn,dndn,dmyn,rn; |
UM t,s,u,w; |
LUM *l; |
BM *l; |
|
|
for ( dc = DC(g); dc && DEG(dc); dc = NEXT(dc) ); |
bound = list->bound; |
if ( dc ) |
t = W_UMALLOC(2*bound); |
cstn = NM((Q)COEF(dc)); |
s = W_UMALLOC(2*bound); |
else |
u = W_UMALLOC(2*bound); |
|
const_term_sfbm(lcy,bound,t); |
|
if ( DEG(t) < 0 ) |
return 1; |
return 1; |
q = list->mod; bound = list->bound; |
|
ntobn(q,NM((Q)COEF(DC(g))),&lcn);; |
l = (BM *)list->c; |
W_CALLOC(bound+1,int,wm); W_CALLOC(bound+1,int,wm1); |
for ( i = 0; i < k; i++ ) { |
for ( i = 0; i < PL(lcn); i++ ) |
const_term_sfbm(l[in[i]],bound,s); |
wm[i] = BD(lcn)[i]; |
mulsfum(t,s,u); |
for ( i = 0, l = (LUM *)list->c; i < k; i++ ) { |
if ( DEG(u) >= bound ) |
mulpadic(q,bound,wm,COEF(l[in[i]])[0],wm1); |
degum(u,bound-1); |
tmpp = wm; wm = wm1; wm1 = tmpp; |
w = t; t = u; u = w; |
} |
} |
padictoq(q,bound,wm,&dvr); |
cpyum(lcg0,s); |
kmuln(NM((Q)COEF(DC(g))),cstn,&dndn); divn(dndn,NM(dvr),&dmyn,&rn); |
dr = divsfum(s,t,u); |
return rn ? 0 : 1; |
if ( dr >= 0 ) |
|
return 0; |
|
else |
|
return 1; |
} |
} |
#endif |
|
|
|
/* main var of f is x */ |
/* main var of f is x */ |
|
|
|
|
sfumtop(y,gcd,&dvr); |
sfumtop(y,gcd,&dvr); |
divsp(vl,f,dvr,fp); |
divsp(vl,f,dvr,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+1,fl); ptosfbm(fy+1,f,fl); cf = COEF(fl); |
|
W_BMALLOC(gx,gy+1,gl); ptosfbm(gy+1,g,gl); cg = COEF(gl); |
|
W_BMALLOC(fx-gx,fy-gy+1,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(DEG(ql),ql,x,y,qp); |
} |
} |