| version 1.7, 2002/10/30 08:07:11 |
version 1.12, 2002/11/26 07:09:45 |
|
|
| /* $OpenXM: OpenXM_contrib2/asir2000/engine/Fgfs.c,v 1.6 2002/10/25 02:43:40 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Fgfs.c,v 1.11 2002/11/22 08:44:57 noro Exp $ */ |
| |
|
| #include "ca.h" |
#include "ca.h" |
| |
|
| void cont_pp_mv_sf(VL vl,VL rvl,P p,P *c,P *pp); |
void cont_pp_mv_sf(VL vl,VL rvl,P p,P *c,P *pp); |
| void gcdsf_main(VL vl,P *pa,int m,P *r); |
void gcdsf_main(VL vl,P *pa,int m,P *r); |
| void ugcdsf(P *pa,int m,P *r); |
void ugcdsf(P *pa,int m,P *r); |
| void head_monomial(V v,P p,P *coef,P *term); |
void head_monomial(VL vl,V v,P p,P *coef,P *term); |
| void sqfrsfmain(VL vl,P f,DCP *dcp); |
void sqfrsfmain(VL vl,P f,DCP *dcp); |
| void pthrootsf(P f,Q m,P *r); |
void pthrootsf(P f,Q m,P *r); |
| void partial_sqfrsf(VL vl,V v,P f,P *r,DCP *dcp); |
void partial_sqfrsf(VL vl,V v,P f,P *r,DCP *dcp); |
| void gcdsf(VL vl,P *pa,int k,P *r); |
void gcdsf(VL vl,P *pa,int k,P *r); |
| void mfctrsfmain(VL vl, P f, DCP *dcp); |
void mfctrsfmain(VL vl, P f, DCP *dcp); |
| void next_evaluation_point(int *mev,int n); |
void next_evaluation_point(int *mev,int n); |
| void estimatelc_sf(VL vl,VL rvl,P c,DCP dc,P *lcp); |
void estimatelc_sf(VL vl,VL rvl,P c,DCP dc,int *mev,P *lcp); |
| void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P lcu,P lcv,P *up); |
void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P lcu,P lcv,int *mev,P *up); |
| void substvp_sf(VL vl,VL rvl,P f,int *mev,P *r); |
void substvp_sf(VL vl,VL rvl,P f,int *mev,P *r); |
| void shift_sf(VL vl, VL rvl, P f, int *mev, int sgn, P *r); |
void shift_sf(VL vl, VL rvl, P f, int *mev, int sgn, P *r); |
| void adjust_coef_sf(VL vl,VL rvl,P lcu,P u0,P *r); |
void adjust_coef_sf(VL vl,VL rvl,P lcu,P u0,int *mev,P *r); |
| void extended_gcd_modyk(P u0,P v0,P *cu,P *cv); |
void extended_gcd_modyk(P u0,P v0,V x,V y,int dy,P *cu,P *cv); |
| void poly_to_gfsn_poly(VL vl,P f,V v,P *r); |
void poly_to_gfsn_poly(VL vl,P f,V v,P *r); |
| void gfsn_poly_to_poly(VL vl,P f,V v,P *r); |
void gfsn_poly_to_poly(VL vl,P f,V v,P *r); |
| |
void poly_to_gfsn_poly_main(P f,V v,P *r); |
| |
void gfsn_poly_to_poly_main(P f,V v,P *r); |
| |
void gfsn_univariate_to_sfbm(P f,int dy,BM *r); |
| |
void sfbm_to_gfsn_univariate(BM f,V x,V y,P *r); |
| |
|
| void lex_lc(P f,P *c) |
void lex_lc(P f,P *c) |
| { |
{ |
| Line 347 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
| Line 351 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
| for ( i = 0; i < m; i++ ) { |
for ( i = 0; i < m; i++ ) { |
| reorderp(nvl,vl,pa[i],&t); |
reorderp(nvl,vl,pa[i],&t); |
| cont_pp_mv_sf(nvl,rvl,t,&pc[i],&ps[i]); |
cont_pp_mv_sf(nvl,rvl,t,&pc[i],&ps[i]); |
| head_monomial(vmin,ps[i],&ph[i],&t); |
head_monomial(nvl,vmin,ps[i],&ph[i],&t); |
| } |
} |
| ugcdsf(pc,m,&cont); |
ugcdsf(pc,m,&cont); |
| ugcdsf(ph,m,&hg); |
ugcdsf(ph,m,&hg); |
| Line 373 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
| Line 377 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
| substp(nvl,ps[i],vmin,s,&ph[i]); |
substp(nvl,ps[i],vmin,s,&ph[i]); |
| /* ge = GCD(ps[0]|x=s,...,ps[m-1]|x=s) */ |
/* ge = GCD(ps[0]|x=s,...,ps[m-1]|x=s) */ |
| gcdsf(nvl,ph,m,&ge); |
gcdsf(nvl,ph,m,&ge); |
| head_monomial(vmin,ge,&ce,&he); |
head_monomial(nvl,vmin,ge,&ce,&he); |
| if ( NUM(he) ) { |
if ( NUM(he) ) { |
| *r = cont; |
*r = cont; |
| return; |
return; |
| Line 440 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
| Line 444 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
| } |
} |
| } |
} |
| |
|
| void head_monomial(V v,P p,P *coef,P *term) |
void head_monomial(VL vl,V v,P p,P *coef,P *term) |
| { |
{ |
| P t,s,u; |
P t,s,u; |
| DCP dc; |
DCP dc; |
| GFS one; |
GFS one; |
| VL vl; |
|
| |
|
| itogfs(1,&one); |
itogfs(1,&one); |
| t = (P)one; |
t = (P)one; |
| Line 476 void cont_pp_mv_sf(VL vl,VL rvl,P p,P *c,P *pp) |
|
| Line 479 void cont_pp_mv_sf(VL vl,VL rvl,P p,P *c,P *pp) |
|
| ps = (P *)ALLOCA(m*sizeof(P)); |
ps = (P *)ALLOCA(m*sizeof(P)); |
| for ( t = BDY(dp), i = 0; t; t = NEXT(t), i++ ) |
for ( t = BDY(dp), i = 0; t; t = NEXT(t), i++ ) |
| ps[i] = C(t); |
ps[i] = C(t); |
| ugcdsf(ps,m,c); |
gcdsf(vl,ps,m,c); |
| divsp(vl,p,*c,pp); |
divsp(vl,p,*c,pp); |
| } |
} |
| |
|
| Line 511 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 514 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| P *l,*tl; |
P *l,*tl; |
| P gcd,g,df,dfmin; |
P gcd,g,df,dfmin; |
| P pa[2]; |
P pa[2]; |
| P g0,pp0,spp0,c,c0,x,y,u,v,lcf,lcu,lcv,u0,v0,t,s; |
P f0,pp0,spp0,c,c0,x,y,u,v,lcf,lcu,lcv,u0,v0,t,s; |
| P ype,yme; |
P ype,yme,fin; |
| GFS ev,evy; |
GFS ev,evy; |
| P *fp0; |
P *fp0; |
| int *mev,*win; |
int *mev,*win; |
| Line 553 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 556 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| } |
} |
| pa[0] = f; |
pa[0] = f; |
| pa[1] = dfmin; |
pa[1] = dfmin; |
| gcdsf_main(vl,pa,2,&gcd); |
gcdsf(vl,pa,2,&gcd); |
| if ( !NUM(gcd) ) { |
if ( !NUM(gcd) ) { |
| /* f = gcd * f/gcd */ |
/* f = gcd * f/gcd */ |
| mfctrsfmain(vl,gcd,&dc1); |
mfctrsfmain(vl,gcd,&dc1); |
| Line 575 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 578 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| } |
} |
| NEXT(tvl) = 0; |
NEXT(tvl) = 0; |
| |
|
| reorderp(nvl,vl,f,&g); |
fin = f; |
| |
reorderp(nvl,vl,f,&g); f = g; |
| vx = nvl->v; |
vx = nvl->v; |
| vy = NEXT(nvl)->v; |
vy = NEXT(nvl)->v; |
| MKV(vx,x); |
MKV(vx,x); |
| Line 584 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 588 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| rvl = NEXT(NEXT(nvl)); |
rvl = NEXT(NEXT(nvl)); |
| if ( !rvl ) { |
if ( !rvl ) { |
| /* bivariate */ |
/* bivariate */ |
| sfbfctr(g,vx,vy,getdeg(vx,g),&dc1); |
sfbfctr(f,vx,vy,getdeg(vx,f),&dc1); |
| for ( dc0 = 0; dc1; dc1 = NEXT(dc1) ) { |
for ( dc0 = 0; dc1; dc1 = NEXT(dc1) ) { |
| NEXTDC(dc0,dc); |
NEXTDC(dc0,dc); |
| DEG(dc) = ONE; |
DEG(dc) = ONE; |
| Line 598 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 602 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| /* find good evaluation pt for X */ |
/* find good evaluation pt for X */ |
| mev = (int *)CALLOC(n-2,sizeof(int)); |
mev = (int *)CALLOC(n-2,sizeof(int)); |
| while ( 1 ) { |
while ( 1 ) { |
| substvp_sf(nvl,rvl,g,mev,&g0); |
/* lcf(mev)=0 => invalid */ |
| pa[0] = g0; |
substvp_sf(nvl,rvl,COEF(DC(f)),mev,&t); |
| diffp(nvl,g0,vx,&pa[1]); |
if ( t ) { |
| if ( pa[1] ) { |
substvp_sf(nvl,rvl,f,mev,&f0); |
| gcdsf(nvl,pa,2,&gcd); |
pa[0] = f0; |
| |
diffp(nvl,f0,vx,&pa[1]); |
| |
if ( pa[1] ) { |
| |
gcdsf(nvl,pa,2,&gcd); |
| /* XXX maybe we have to accept the case where gcd is a poly of y */ |
/* XXX maybe we have to accept the case where gcd is a poly of y */ |
| if ( NUM(gcd) ) |
if ( NUM(gcd) ) |
| break; |
break; |
| |
} |
| } |
} |
| /* XXX if generated indices exceed q of GF(q) => error in indextogfs */ |
/* XXX if generated indices exceed q of GF(q) => error in indextogfs */ |
| next_evaluation_point(mev,n-2); |
next_evaluation_point(mev,n-2); |
| } |
} |
| /* g0 = g(x,y,mev) */ |
/* f0 = f(x,y,mev) */ |
| /* separate content; g0 may have the content wrt x */ |
/* separate content; f0 may have the content wrt x */ |
| cont_pp_sfp(nvl,g0,&c0,&pp0); |
cont_pp_sfp(nvl,f0,&c0,&pp0); |
| |
|
| /* factorize pp0; pp0 = pp0(x,y+evy) = prod dc */ |
/* factorize pp0; pp0 = pp0(x,y+evy) = prod dc */ |
| sfbfctr_shift(pp0,vx,vy,getdeg(vx,pp0),&evy,&spp0,&dc); pp0 = spp0; |
sfbfctr_shift(pp0,vx,vy,getdeg(vx,pp0),&evy,&spp0,&dc); pp0 = spp0; |
| |
|
| if ( !NEXT(dc) ) { |
if ( !NEXT(dc) ) { |
| /* f is irreducible */ |
/* f is irreducible */ |
| NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; |
NEWDC(dc); DEG(dc) = ONE; COEF(dc) = fin; NEXT(dc) = 0; |
| *dcp = dc; |
*dcp = dc; |
| return; |
return; |
| } |
} |
| Line 638 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 646 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| lcf = COEF(DC(f)); |
lcf = COEF(DC(f)); |
| mfctrsf(nvl,lcf,&dct); |
mfctrsf(nvl,lcf,&dct); |
| /* skip the first element (= a number) */ |
/* skip the first element (= a number) */ |
| dct = NEXT(dct); |
lcfdc = NEXT(dct); |
| |
|
| /* shift lcfdc; c <- c(X+mev) */ |
|
| for ( lcfdc = 0; dct; dct = NEXT(dct) ) { |
|
| NEXTDC(lcfdc,dcs); |
|
| DEG(dcs) = DEG(dct); |
|
| shift_sf(nvl,rvl,COEF(dct),mev,1,&COEF(dcs)); |
|
| } |
|
| NEXT(dcs) = 0; |
|
| |
|
| /* np = number of bivariate factors */ |
/* np = number of bivariate factors */ |
| for ( np = 0, dct = dc; dct; dct = NEXT(dct), np++ ); |
for ( np = 0, dct = dc; dct; dct = NEXT(dct), np++ ); |
| fp0 = (P *)ALLOCA((np+1)*sizeof(P)); |
fp0 = (P *)ALLOCA((np+1)*sizeof(P)); |
| Line 657 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 657 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| l = tl = (P *)ALLOCA((np+1)*sizeof(P)); |
l = tl = (P *)ALLOCA((np+1)*sizeof(P)); |
| win = W_ALLOC(np+1); |
win = W_ALLOC(np+1); |
| |
|
| /* f <- f(X+mev) */ |
|
| shift_sf(nvl,rvl,f,mev,1,&s); f = s; |
|
| |
|
| for ( k = 1, win[0] = 1, --np; ; ) { |
for ( k = 1, win[0] = 1, --np; ; ) { |
| itogfs(1,&u0); |
itogfs(1,&u0); |
| /* u0 = product of selected factors */ |
/* u0 = product of selected factors */ |
| Line 667 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 664 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| mulp(nvl,u0,fp0[win[i]],&t); u0 = t; |
mulp(nvl,u0,fp0[win[i]],&t); u0 = t; |
| } |
} |
| /* we have to consider the content */ |
/* we have to consider the content */ |
| /* g0 = c0*u0*v0 */ |
/* f0 = c0*u0*v0 */ |
| mulp(nvl,LC(u0),c0,&c); estimatelc_sf(nvl,rvl,c,lcfdc,&lcu); |
mulp(nvl,LC(u0),c0,&c); estimatelc_sf(nvl,rvl,c,lcfdc,mev,&lcu); |
| divsp(nvl,pp0,u0,&v0); |
divsp(nvl,pp0,u0,&v0); |
| mulp(nvl,LC(v0),c0,&c); estimatelc_sf(nvl,rvl,c,lcfdc,&lcv); |
mulp(nvl,LC(v0),c0,&c); estimatelc_sf(nvl,rvl,c,lcfdc,mev,&lcv); |
| mfctrsf_hensel(nvl,rvl,f,pp0,u0,v0,lcu,lcv,&u); |
mfctrsf_hensel(nvl,rvl,f,pp0,u0,v0,lcu,lcv,mev,&u); |
| if ( u ) { |
if ( u ) { |
| /* save the factor */ |
/* save the factor */ |
| reorderp(vl,nvl,u,&t); |
reorderp(vl,nvl,u,&t); |
| /* x -> x-mev, y -> y-evy */ |
/* y -> y-evy */ |
| shift_sf(vl,rvl,t,mev,-1,&s); substp(vl,s,vy,yme,tl++); |
substp(vl,t,vy,yme,tl++); |
| |
|
| /* update f,pp0 */ |
/* update f,pp0 */ |
| divsp(nvl,f,u,&t); f = t; |
divsp(nvl,f,u,&t); f = t; |
| Line 705 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| Line 702 void mfctrsfmain(VL vl, P f, DCP *dcp) |
|
| for ( i = 0, ++k; i < k; i++ ) |
for ( i = 0, ++k; i < k; i++ ) |
| win[i] = i + 1; |
win[i] = i + 1; |
| } |
} |
| reorderp(vl,nvl,f,&t); |
|
| /* x -> x-mev, y -> y-evy */ |
|
| shift_sf(vl,rvl,t,mev,-1,&s); substp(vl,s,vy,yme,tl++); |
|
| *tl = 0; |
|
| |
|
| for ( dc0 = 0, i = 0; l[i]; i++ ) { |
|
| NEXTDC(dc0,dc); DEG(dc) = ONE; COEF(dc) = l[i]; |
|
| } |
|
| NEXT(dc) = 0; *dcp = dc0; |
|
| } |
} |
| |
reorderp(vl,nvl,f,&t); |
| |
/* y -> y-evy */ |
| |
substp(vl,t,vy,yme,tl++); |
| |
*tl = 0; |
| |
for ( dc0 = 0, i = 0; l[i]; i++ ) { |
| |
NEXTDC(dc0,dc); DEG(dc) = ONE; COEF(dc) = l[i]; |
| |
} |
| |
NEXT(dc) = 0; *dcp = dc0; |
| } |
} |
| |
|
| void next_evaluation_point(int *e,int n) |
void next_evaluation_point(int *e,int n) |
| Line 736 void next_evaluation_point(int *e,int n) |
|
| Line 732 void next_evaluation_point(int *e,int n) |
|
| |
|
| /* |
/* |
| * dc : f1^E1*...*fk^Ek |
* dc : f1^E1*...*fk^Ek |
| * find e1,...,ek s.t. fi(0)^ei | c |
* find e1,...,ek s.t. fi(mev)^ei | c |
| * and return f1^e1*...*fk^ek |
* and return f1^e1*...*fk^ek |
| * vl = (vx,vy,rvl) |
* vl = (vx,vy,rvl) |
| */ |
*/ |
| |
|
| void estimatelc_sf(VL vl,VL rvl,P c,DCP dc,P *lcp) |
void estimatelc_sf(VL vl,VL rvl,P c,DCP dc,int *mev,P *lcp) |
| { |
{ |
| DCP dct; |
DCP dct; |
| P r,c1,c2,t,s,f; |
P r,c1,c2,t,s,f; |
| Line 752 void estimatelc_sf(VL vl,VL rvl,P c,DCP dc,P *lcp) |
|
| Line 748 void estimatelc_sf(VL vl,VL rvl,P c,DCP dc,P *lcp) |
|
| if ( NUM(COEF(dct)) ) |
if ( NUM(COEF(dct)) ) |
| continue; |
continue; |
| /* constant part */ |
/* constant part */ |
| substvp_sf(vl,rvl,COEF(dct),0,&f); |
substvp_sf(vl,rvl,COEF(dct),mev,&f); |
| d = QTOS(DEG(dct)); |
d = QTOS(DEG(dct)); |
| for ( i = 0, c1 = c; i < d; i++ ) |
for ( i = 0, c1 = c; i < d; i++ ) |
| if ( !divtp(vl,c1,f,&c2) ) |
if ( !divtp(vl,c1,f,&c2) ) |
| Line 813 void shift_sf(VL vl, VL rvl, P f, int *mev, int sgn, P |
|
| Line 809 void shift_sf(VL vl, VL rvl, P f, int *mev, int sgn, P |
|
| * pp(f(0)) = u0*v0 |
* pp(f(0)) = u0*v0 |
| */ |
*/ |
| |
|
| void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P lcu,P lcv,P *up) |
void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P lcu,P lcv,int *mev,P *up) |
| { |
{ |
| VL tvl,onevl; |
VL tvl,onevl; |
| P t,s,w,u,v,ff,si,wu,wv,fj,cont; |
P t,s,w,u,v,ff,si,wu,wv,fj,cont; |
| Line 822 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| Line 818 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| int dy,n,i,dbd,nv,j; |
int dy,n,i,dbd,nv,j; |
| int *md; |
int *md; |
| P *uh,*vh; |
P *uh,*vh; |
| P x,du0,dv0,m,q,r; |
P x,du0,dv0,m,q,r,fin; |
| P *cu,*cv; |
P *cu,*cv; |
| GFSN inv; |
GFSN inv; |
| |
|
| /* adjust coeffs */ |
/* adjust coeffs */ |
| /* u0 = am x^m+ ... -> lcu*x^m + a(m-1)*(lcu(0)/am)*x^(m-1)+... */ |
/* u0 = am x^m+ ... -> lcu*x^m + a(m-1)*(lcu(mev)/am)*x^(m-1)+... */ |
| /* v0 = bm x^l+ ... -> lcv*x^l + b(l-1)*(lcv(0)/bl)*x^(l-1)+... */ |
/* v0 = bm x^l+ ... -> lcv*x^l + b(l-1)*(lcv(mev)/bl)*x^(l-1)+... */ |
| adjust_coef_sf(vl,rvl,lcu,u0,&u); |
/* f -> lcu*lcv*x^(m+l)+... */ |
| adjust_coef_sf(vl,rvl,lcv,v0,&v); |
adjust_coef_sf(vl,rvl,lcu,u0,mev,&u); |
| |
adjust_coef_sf(vl,rvl,lcv,v0,mev,&v); |
| |
mulp(vl,lcu,lcv,&t); divsp(vl,t,LC(f),&m); mulp(vl,m,f,&t); f = t; |
| |
|
| |
/* f <- f(X+mev), u <- u(X+mev), v <- v(X+mev) */ |
| |
fin = f; |
| |
shift_sf(vl,rvl,f,mev,1,&s); f = s; |
| |
shift_sf(vl,rvl,u,mev,1,&s); u = s; |
| |
shift_sf(vl,rvl,v,mev,1,&s); v = s; |
| |
|
| vx = vl->v; vy = NEXT(vl)->v; |
vx = vl->v; vy = NEXT(vl)->v; |
| n = getdeg(vx,f); |
n = getdeg(vx,f); |
| dy = getdeg(vy,f)+1; |
dy = getdeg(vy,f)+1; |
| Line 839 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| Line 844 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| cv = (P *)ALLOCA((n+1)*sizeof(P)); |
cv = (P *)ALLOCA((n+1)*sizeof(P)); |
| |
|
| /* ydy = y^dy */ |
/* ydy = y^dy */ |
| ydy = C_UMALLOC(dy); COEF(ydy)[dy] = 1; |
ydy = C_UMALLOC(dy); DEG(ydy) = dy; COEF(ydy)[dy] = _onesf(); |
| setmod_gfsn(ydy); |
setmod_gfsn(ydy); |
| |
|
| /* (R[y]/(y^dy))[x,X] */ |
/* (R[y]/(y^dy))[x,X] */ |
| poly_to_gfsn_poly(vl,f,vy,&t); ff = t; |
poly_to_gfsn_poly(vl,f,vy,&ff); |
| poly_to_gfsn_poly(vl,u,vy,&t); u = t; |
poly_to_gfsn_poly(vl,u,vy,&t); u = t; |
| poly_to_gfsn_poly(vl,v,vy,&t); v = t; |
poly_to_gfsn_poly(vl,v,vy,&t); v = t; |
| substvp_sf(vl,rvl,u,0,&u0); |
substvp_sf(vl,rvl,u,0,&u0); |
| substvp_sf(vl,rvl,v,0,&v0); |
substvp_sf(vl,rvl,v,0,&v0); |
| |
|
| /* compute a(x,y), b(x,y) s.t. a*u0+b*v0 = 1 mod y^dy */ |
/* compute a(x,y), b(x,y) s.t. a*u0+b*v0 = 1 mod y^dy */ |
| extended_gcd_modyk(u0,v0,&cu[0],&cv[0]); |
extended_gcd_modyk(u0,v0,vx,vy,dy,&cu[0],&cv[0]); |
| |
|
| /* du0 = LC(u0)^(-1)*u0 mod y^dy */ |
|
| /* dv0 = LC(v0)^(-1)*v0 mod y^dy */ |
/* dv0 = LC(v0)^(-1)*v0 mod y^dy */ |
| invgfsn((GFSN)LC(u0),&inv); mulp(vl,u0,(P)inv,&du0); |
|
| invgfsn((GFSN)LC(v0),&inv); mulp(vl,v0,(P)inv,&dv0); |
invgfsn((GFSN)LC(v0),&inv); mulp(vl,v0,(P)inv,&dv0); |
| |
|
| /* cu[i]*u0+cv[i]*v0 = x^i mod y^dy */ |
/* cu[i]*u0+cv[i]*v0 = x^i mod y^dy */ |
| |
/* (x*cu[i])*u0+(x*cv[i])*v0 = x^(i+1) */ |
| |
/* x*cu[i] = q*dv0+r => cu[i+1] = r */ |
| |
/* cv[i+1]*v0 = x*cv[i]*v0+q*u0*dv0 = (x*cv[i]+q*u0*inv)*v0 */ |
| for ( i = 1; i <= n; i++ ) { |
for ( i = 1; i <= n; i++ ) { |
| mulp(vl,x,cu[i-1],&m); divsrp(vl,m,dv0,&q,&cu[i]); |
mulp(vl,x,cu[i-1],&m); divsrp(vl,m,dv0,&q,&cu[i]); |
| mulp(vl,x,cv[i-1],&m); divsrp(vl,m,du0,&q,&cv[i]); |
mulp(vl,x,cv[i-1],&m); mulp(vl,q,(P)inv,&t); |
| |
mulp(vl,t,u0,&s); |
| |
addp(vl,m,s,&cv[i]); |
| } |
} |
| |
|
| |
#if 0 |
| |
/* XXX : check */ |
| |
for ( i = 0; i <= n; i++ ) { |
| |
mulp(vl,cu[i],u0,&m); mulp(vl,cv[i],v0,&s); |
| |
addp(vl,m,s,&w); |
| |
printexpr(vl,w); |
| |
fprintf(asir_out,"\n"); |
| |
} |
| |
#endif |
| |
|
| dbd = dbound(vx,f)+1; |
dbd = dbound(vx,f)+1; |
| |
|
| /* extract homogeneous parts */ |
/* extract homogeneous parts */ |
| Line 874 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| Line 893 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| for ( nv = 0, tvl = rvl; tvl; tvl = NEXT(tvl), nv++ ); |
for ( nv = 0, tvl = rvl; tvl; tvl = NEXT(tvl), nv++ ); |
| md = (int *)ALLOCA(nv*sizeof(int)); |
md = (int *)ALLOCA(nv*sizeof(int)); |
| for ( i = 0, tvl = rvl; i < nv; tvl = NEXT(tvl), i++ ) |
for ( i = 0, tvl = rvl; i < nv; tvl = NEXT(tvl), i++ ) |
| md[i] = getdeg(tvl->v,ff); |
md[i] = getdeg(tvl->v,f); |
| |
|
| /* XXX for removing content of factor wrt vx */ |
/* XXX for removing content of factor wrt vx */ |
| NEWVL(onevl); onevl->v = vx; NEXT(onevl) = 0; |
NEWVL(onevl); onevl->v = vx; NEXT(onevl) = 0; |
| Line 888 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| Line 907 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| for ( i = 0, t = 0; i <= j; i++ ) { |
for ( i = 0, t = 0; i <= j; i++ ) { |
| mulp(vl,uh[i],vh[j-i],&s); addp(vl,s,t,&w); t = w; |
mulp(vl,uh[i],vh[j-i],&s); addp(vl,s,t,&w); t = w; |
| } |
} |
| |
|
| /* s = degree j part of (f-uv) */ |
/* s = degree j part of (f-uv) */ |
| exthpc(vl,vx,ff,j,&fj); subp(vl,fj,t,&s); |
exthpc(vl,vx,ff,j,&fj); subp(vl,fj,t,&s); |
| for ( i = 0, wu = 0, wv = 0; i <= n; i++ ) { |
for ( i = 0, wu = 0, wv = 0; i <= n; i++ ) { |
| if ( s ) |
if ( !s ) |
| si = 0; |
si = 0; |
| else if ( VR(s) == vx ) |
else if ( VR(s) == vx ) |
| coefp(s,i,&si); |
coefp(s,i,&si); |
| Line 900 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| Line 920 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| else |
else |
| si = 0; |
si = 0; |
| if ( si ) { |
if ( si ) { |
| mulp(vl,si,cu[i],&m); addp(vl,wu,m,&t); wu = t; |
mulp(vl,si,cv[i],&m); addp(vl,wu,m,&t); wu = t; |
| mulp(vl,si,cv[i],&m); addp(vl,wv,m,&t); wv = t; |
mulp(vl,si,cu[i],&m); addp(vl,wv,m,&t); wv = t; |
| } |
} |
| } |
} |
| if ( !wu ) { |
if ( !wu ) { |
| gfsn_poly_to_poly(vl,u,vy,&t); u = t; |
gfsn_poly_to_poly(vl,u,vy,&t); |
| if ( divtp(vl,f,u,&q) ) { |
shift_sf(vl,rvl,t,mev,-1,&s); |
| cont_pp_mv_sf(vl,onevl,u,&cont,up); |
if ( divtp(vl,fin,s,&q) ) { |
| |
cont_pp_mv_sf(vl,onevl,s,&cont,up); |
| return; |
return; |
| } |
} |
| } |
} |
| if ( !wv ) { |
if ( !wv ) { |
| gfsn_poly_to_poly(vl,v,vy,&t); v = t; |
gfsn_poly_to_poly(vl,v,vy,&t); |
| if ( divtp(vl,f,u,&q) ) { |
shift_sf(vl,rvl,t,mev,-1,&s); |
| |
if ( divtp(vl,fin,s,&q) ) { |
| cont_pp_mv_sf(vl,onevl,q,&cont,up); |
cont_pp_mv_sf(vl,onevl,q,&cont,up); |
| return; |
return; |
| } |
} |
| Line 925 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| Line 947 void mfctrsf_hensel(VL vl,VL rvl,P f,P pp0,P u0,P v0,P |
|
| } |
} |
| } |
} |
| |
|
| void adjust_coef_sf(VL vl,VL rvl,P lcu,P u0,P *r) |
void adjust_coef_sf(VL vl,VL rvl,P lcu,P u0,int *mev,P *r) |
| { |
{ |
| P lcu0,cu; |
P lcu0,cu; |
| DCP dc0,dcu,dc; |
DCP dc0,dcu,dc; |
| |
|
| substvp_sf(vl,rvl,lcu,0,&lcu0); |
substvp_sf(vl,rvl,lcu,mev,&lcu0); |
| divsp(vl,lcu0,LC(u0),&cu); |
divsp(vl,lcu0,LC(u0),&cu); |
| for ( dc0 = 0, dcu = DC(u0); dcu; dcu = NEXT(dcu) ) { |
for ( dc0 = 0, dcu = DC(u0); dcu; dcu = NEXT(dcu) ) { |
| if ( !dc0 ) { |
if ( !dc0 ) { |
| Line 946 void adjust_coef_sf(VL vl,VL rvl,P lcu,P u0,P *r) |
|
| Line 968 void adjust_coef_sf(VL vl,VL rvl,P lcu,P u0,P *r) |
|
| MKP(VR(u0),dc0,*r); |
MKP(VR(u0),dc0,*r); |
| } |
} |
| |
|
| void extended_gcd_modyk(P u0,P v0,P *cu,P *cv) |
void extended_gcd_modyk(P u0,P v0,V x,V y,int dy,P *cu,P *cv) |
| { |
{ |
| |
BM g,h,a,b; |
| |
|
| |
gfsn_univariate_to_sfbm(u0,dy,&g); |
| |
gfsn_univariate_to_sfbm(v0,dy,&h); |
| |
sfexgcd_by_hensel(g,h,dy,&a,&b); |
| |
sfbm_to_gfsn_univariate(a,x,y,cu); |
| |
sfbm_to_gfsn_univariate(b,x,y,cv); |
| } |
} |
| |
|
| |
/* (F[y])[x] -> F[x][y] */ |
| |
|
| |
void gfsn_univariate_to_sfbm(P f,int dy,BM *r) |
| |
{ |
| |
int dx,d,i; |
| |
BM b; |
| |
UM cy; |
| |
DCP dc; |
| |
|
| |
dx = getdeg(VR(f),f); |
| |
b = BMALLOC(dx,dy); |
| |
DEG(b) = dy; |
| |
for ( dc = DC(f); dc; dc = NEXT(dc) ) { |
| |
/* d : degree in x, cy : poly in y */ |
| |
d = QTOS(DEG(dc)); |
| |
cy = BDY((GFSN)COEF(dc)); |
| |
for ( i = DEG(cy); i >= 0; i-- ) |
| |
COEF(COEF(b)[i])[d] = COEF(cy)[i]; |
| |
} |
| |
for ( i = 0; i <= dy; i++ ) |
| |
degum(COEF(b)[i],dx); |
| |
*r = b; |
| |
} |
| |
|
| |
void sfbm_to_gfsn_univariate(BM f,V x,V y,P *r) |
| |
{ |
| |
P g; |
| |
VL vl; |
| |
|
| |
sfbmtop(f,x,y,&g); |
| |
NEWVL(vl); vl->v = x; |
| |
NEWVL(NEXT(vl)); NEXT(vl)->v = y; |
| |
NEXT(NEXT(vl)) = 0; |
| |
poly_to_gfsn_poly(vl,g,y,r); |
| |
} |
| |
|
| void poly_to_gfsn_poly(VL vl,P f,V v,P *r) |
void poly_to_gfsn_poly(VL vl,P f,V v,P *r) |
| { |
{ |
| |
VL tvl,nvl0,nvl; |
| |
P g; |
| |
|
| |
/* (x,y,...,v,...) -> (x,y,...,v) */ |
| |
for ( nvl0 = 0, tvl = vl; tvl; tvl = NEXT(tvl) ) { |
| |
if ( tvl->v != v ) { |
| |
NEXTVL(nvl0,nvl); |
| |
nvl->v = tvl->v; |
| |
} |
| |
} |
| |
NEXTVL(nvl0,nvl); |
| |
nvl->v = v; |
| |
NEXT(nvl) = 0; |
| |
reorderp(nvl0,vl,f,&g); |
| |
poly_to_gfsn_poly_main(g,v,r); |
| } |
} |
| |
|
| |
void poly_to_gfsn_poly_main(P f,V v,P *r) |
| |
{ |
| |
int d; |
| |
UM u; |
| |
GFSN g; |
| |
DCP dc,dct,dc0; |
| |
|
| |
if ( !f ) |
| |
*r = f; |
| |
else if ( NUM(f) || VR(f) == v ) { |
| |
d = getdeg(v,f); |
| |
u = UMALLOC(d); |
| |
ptosfum(f,u); |
| |
MKGFSN(u,g); |
| |
*r = (P)g; |
| |
} else { |
| |
for ( dc0 = 0, dct = DC(f); dct; dct = NEXT(dct) ) { |
| |
NEXTDC(dc0,dc); |
| |
DEG(dc) = DEG(dct); |
| |
poly_to_gfsn_poly_main(COEF(dct),v,&COEF(dc)); |
| |
} |
| |
NEXT(dc) = 0; |
| |
MKP(VR(f),dc0,*r); |
| |
} |
| |
} |
| |
|
| void gfsn_poly_to_poly(VL vl,P f,V v,P *r) |
void gfsn_poly_to_poly(VL vl,P f,V v,P *r) |
| { |
{ |
| |
VL tvl,nvl0,nvl; |
| |
P g; |
| |
|
| |
gfsn_poly_to_poly_main(f,v,&g); |
| |
/* (x,y,...,v,...) -> (x,y,...,v) */ |
| |
for ( nvl0 = 0, tvl = vl; tvl; tvl = NEXT(tvl) ) { |
| |
if ( tvl->v != v ) { |
| |
NEXTVL(nvl0,nvl); |
| |
nvl->v = tvl->v; |
| |
} |
| |
} |
| |
NEXTVL(nvl0,nvl); |
| |
nvl->v = v; |
| |
NEXT(nvl) = 0; |
| |
reorderp(vl,nvl0,g,r); |
| } |
} |
| |
|
| |
void gfsn_poly_to_poly_main(P f,V v,P *r) |
| |
{ |
| |
DCP dc,dc0,dct; |
| |
|
| |
if ( !f ) |
| |
*r = f; |
| |
else if ( NUM(f) ) { |
| |
if ( NID((Num)f) == N_GFSN ) |
| |
sfumtop(v,BDY((GFSN)f),r); |
| |
else |
| |
*r = f; |
| |
} else { |
| |
for ( dc0 = 0, dct = DC(f); dct; dct = NEXT(dct) ) { |
| |
NEXTDC(dc0,dc); |
| |
DEG(dc) = DEG(dct); |
| |
gfsn_poly_to_poly_main(COEF(dct),v,&COEF(dc)); |
| |
} |
| |
NEXT(dc) = 0; |
| |
MKP(VR(f),dc0,*r); |
| |
} |
| |
} |
| |
|
| |
void printsfum(UM f) |
| |
{ |
| |
int i; |
| |
|
| |
for ( i = DEG(f); i >= 0; i-- ) { |
| |
printf("+("); |
| |
printf("%d",IFTOF(COEF(f)[i])); |
| |
printf(")*y^%d",i); |
| |
} |
| |
} |
| |
|
| |
void printsfbm(BM f) |
| |
{ |
| |
int i; |
| |
|
| |
for ( i = DEG(f); i >= 0; i-- ) { |
| |
printf("+("); |
| |
printsfum(COEF(f)[i]); |
| |
printf(")*y^%d",i); |
| |
} |
| |
} |
| |
|