=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/Hgfs.c,v retrieving revision 1.6 retrieving revision 1.11 diff -u -p -r1.6 -r1.11 --- OpenXM_contrib2/asir2000/engine/Hgfs.c 2001/06/25 06:05:16 1.6 +++ OpenXM_contrib2/asir2000/engine/Hgfs.c 2001/06/26 09:47:05 1.11 @@ -1,4 +1,4 @@ -/* $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.10 2001/06/26 08:52:59 noro Exp $ */ #include "ca.h" @@ -13,6 +13,11 @@ void lnfsf(int,UM,UM,struct p_pair *,UM,UM); void minipolysf(UM,UM,UM); void czsfum(UM,UM *); void gensqfrsfum(UM,DUM); +void sfbmtop(int,BM,V,V,P *); +void pp_sfp(VL,P,P *); +void sfcsump(VL,P,P *); +void mulsfbmarray(int,BM,ML,int,int *,V,V,P *); +void const_term(P,UM); void fctrsf(p,dcp) P p; @@ -539,10 +544,12 @@ void ptosfbm(int,P,BM); /* f = f(x,y) */ -void sfhensel(count,f,x,listp) +void sfhensel(count,f,x,evp,sfp,listp) int count; P f; V x; +GFS *evp; +P *sfp; ML *listp; { int i,j; @@ -553,7 +560,7 @@ ML *listp; V y; int dx,dy,mev; GFS ev; - P f1,t,yev,c; + P f1,t,yev,c,sf; DCP dc; UM w,w1,q,fm,hm; UM *gm; @@ -593,6 +600,9 @@ ML *listp; ptosfbm(bound,f,fl); shiftsfbm(bound,fl,FTOIF(CONT(ev))); + /* sf = f(x+ev) */ + sfbmtop(bound,fl,x,y,&sf); + /* fm = fl mod y */ fm = W_UMALLOC(dx); cpyum(COEF(fl)[0],fm); @@ -600,7 +610,7 @@ ML *listp; q = W_UMALLOC(dx); rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = bound; - for ( i = fn-1; i >= 1; i-- ) { + for ( i = 0; i < fn-1; i++ ) { fprintf(stderr,"%d\n",i); /* fl = gm[i]*hm mod y */ divsfum(fm,gm[i],hm); @@ -609,15 +619,17 @@ ML *listp; sfhenmain2(fl,gm[i],hm,bound,(BM *)&rlist->c[i]); cpyum(hm,fm); } - /* finally, fl must be the lift of gm[0] */ + /* finally, fl must be the lift of gm[fn-1] */ rlist->c[i] = fl; +#if 0 /* 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); +#endif + *evp = ev; + *sfp = sf; *listp = rlist; } @@ -794,7 +806,7 @@ BM *gp; int ng,nh; BM fk,gk,hk; - n = f->d; + n = degsfbm(bound,f); ng = g0->d; nh = h0->d; @@ -804,8 +816,10 @@ BM *gp; 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(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]); @@ -928,6 +942,8 @@ BM fl; int d,i,n; UM t; + n = QTOS(DEG(DC(f))); + clearsfbm(bound,n,fl); DEG(fl) = bound; t = UMALLOC(bound); for ( dc = DC(f); dc; dc = NEXT(dc) ) { @@ -936,8 +952,7 @@ BM fl; for ( i = 0; i <= DEG(t); i++ ) COEF(COEF(fl)[i])[d] = COEF(t)[i]; } - n = UDEG(f); - for ( i = 0; i <= n; i++ ) + for ( i = 0; i < bound; i++ ) degum(COEF(fl)[i],n); } @@ -972,26 +987,396 @@ P *fp; /* x : main variable */ -void sfbmtop(vl,bound,f,x,y,fp) -VL vl; +void sfbmtop(bound,f,x,y,fp) int bound; BM f; V x,y; P *fp; { UM *c; - P yv,r,s,t,u,yvd; - Q d; + int i,j,d,a; + GFS b; + DCP dc0,dc,dct; + + c = COEF(f); + d = DEG(c[0]); + for ( i = 1; i < bound; i++ ) + d = MAX(DEG(c[i]),d); + + dc0 = 0; + for ( i = 0; i <= d; i++ ) { + dc = 0; + for ( j = 0; j < bound; 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 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 n,bound; + + /* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ + sfhensel(5,f,x,&ev,&sf,&list); + 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 */ + +void sfdtest(f,list,x,y,dcp) +P f; +ML list; +V x,y; +DCP *dcp; +{ + int n,np,bound; + 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 */ + n = UDEG(f); np = list->n; bound = list->bound; win = W_ALLOC(np+1); + wlist = W_MLALLOC(np); wlist->n = list->n; + wlist->bound = list->bound; + c = (BM *)COEF(wlist); + bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np)); + + lcg0 = W_UMALLOC(2*bound); + + /* 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,bound,lcy); + NEWDC(dc); COEF(dc) = COEF(DC(g)); DEG(dc) = 0; + NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc; + ptosfbm(bound,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 */ + clearsfbm(bound,0,lcy); + COEF(dc) = COEF(DC(g)); ptosfbm(bound,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; +P lcg; +UM lcg0; +BM lcy; +P csum; +ML list; +int k; +int *in; +P *fp,*cofp; +{ + P fmul,csumg,q; + 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) ) { + pp_sfp(vl,fmul,fp); + pp_sfp(vl,q,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,bound,c) +BM f; +int bound; +UM c; +{ 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; + 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; +int k; +int *in; +{ + DCP dc; + int bound,i,dr; + UM t,s,u,w; + BM *l; + + bound = list->bound; + t = W_UMALLOC(2*bound); + s = W_UMALLOC(2*bound); + u = W_UMALLOC(2*bound); + const_term_sfbm(lcy,bound,t); + if ( DEG(t) < 0 ) + return 1; + + l = (BM *)list->c; + for ( i = 0; i < k; i++ ) { + const_term_sfbm(l[in[i]],bound,s); + mulsfum(t,s,u); + if ( DEG(u) >= bound ) + degum(u,bound-1); + w = t; t = u; u = w; } - *fp = r; + cpyum(lcg0,s); + dr = divsfum(s,t,u); + if ( dr >= 0 ) + return 0; + else + return 1; +} + +/* main var of f is x */ + +void mulsfbmarray(n,lcy,list,k,in,x,y,g) +int n; +BM lcy; +ML list; +int k; +int *in; +V x,y; +P *g; +{ + int bound,i; + BM wb0,wb1,t,lcbm; + BM *l; + + bound = list->bound; + W_BMALLOC(n,bound,wb0); W_BMALLOC(n,bound,wb1); + l = (BM *)list->c; + clearsfbm(bound,n,wb0); + mulsfbm(bound,lcy,l[in[0]],wb0); + for ( i = 1; i < k; i++ ) { + clearsfbm(bound,n,wb1); + mulsfbm(bound,l[in[i]],wb0,wb1); + t = wb0; wb0 = wb1; wb1 = t; + } + sfbmtop(bound,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 pp_sfp(vl,f,fp) +VL vl; +P f; +P *fp; +{ + V x,y; + int d; + UM t,s,gcd; + DCP dc; + P dvr; + + x = vl->v; + y = vl->next->v; + d = getdeg(y,f); + if ( d == 0 ) + *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,&dvr); + 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); }