version 1.20, 2001/10/30 10:24:35 |
version 1.28, 2002/11/22 07:32:10 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.19 2001/10/30 07:25:58 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.27 2002/11/01 05:43:35 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
|
#include "inline.h" |
|
|
void lnfsf(int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1); |
void lnfsf(int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1); |
void extractcoefbm(BM f,int dx,UM r); |
void extractcoefbm(BM f,int dx,UM r); |
Line 15 int comp_dum(DUM a,DUM b) |
|
Line 16 int comp_dum(DUM a,DUM b) |
|
return 0; |
return 0; |
} |
} |
|
|
void fctrsf(P p,DCP *dcp) |
void ufctrsf(P p,DCP *dcp) |
{ |
{ |
int n,i,j,k; |
int n,i,j,k; |
DCP dc,dc0; |
DCP dc,dc0; |
Line 27 void fctrsf(P p,DCP *dcp) |
|
Line 28 void fctrsf(P p,DCP *dcp) |
|
|
|
simp_ff((Obj)p,&obj); p = (P)obj; |
simp_ff((Obj)p,&obj); p = (P)obj; |
if ( !p ) { |
if ( !p ) { |
*dcp = 0; return; |
NEWDC(dc); COEF(dc) = 0; DEG(dc) = ONE; |
|
NEXT(dc) = 0; *dcp = dc; |
|
return; |
} |
} |
mp = W_UMALLOC(UDEG(p)); |
mp = W_UMALLOC(UDEG(p)); |
ptosfum(p,mp); |
ptosfum(p,mp); |
Line 503 void canzassf(UM f,int d,UM *r) |
|
Line 506 void canzassf(UM f,int d,UM *r) |
|
|
|
/* Hensel related functions */ |
/* Hensel related functions */ |
|
|
int sfberle(VL,P,int,GFS *,DCP *); |
int sfberle(V,V,P,int,GFS *,DCP *); |
void sfgcdgen(P,ML,ML *); |
void sfgcdgen(P,ML,ML *); |
void sfhenmain2(BM,UM,UM,int,BM *); |
void sfhenmain2(BM,UM,UM,int,BM *); |
void ptosfbm(int,P,BM); |
void ptosfbm(int,P,BM); |
|
void sfhensel(int count,P f,V x,V y,int degbound,GFS *evp,P *sfp,ML *listp); |
|
|
/* f = f(x,y) */ |
/* f = f(x,y) */ |
|
|
void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *listp) |
void sfhensel(int count,P f,V x,V y,int degbound,GFS *evp,P *sfp,ML *listp) |
{ |
{ |
int i; |
int i; |
int fn; |
int fn; |
ML rlist; |
ML rlist; |
BM fl; |
BM fl; |
VL vl,nvl; |
VL vl,nvl; |
V y; |
|
int dx,dy,bound; |
int dx,dy,bound; |
GFS ev; |
GFS ev; |
P f1,t,c,sf; |
P f1,t,c,sf; |
DCP dc; |
DCP dc,dct,dc0; |
UM q,fm,hm; |
UM q,fm,hm; |
UM *gm; |
UM *gm; |
struct oEGT tmp0,tmp1,eg_hensel,eg_hensel_t; |
struct oEGT tmp0,tmp1,eg_hensel,eg_hensel_t; |
Line 531 void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li |
|
Line 534 void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li |
|
reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1); |
reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1); |
vl = nvl; f = f1; |
vl = nvl; f = f1; |
} |
} |
y = vl->next->v; |
if ( vl->next ) |
|
y = vl->next->v; |
dx = getdeg(x,f); |
dx = getdeg(x,f); |
dy = getdeg(y,f); |
dy = getdeg(y,f); |
if ( dx == 1 ) { |
if ( dx == 1 ) { |
*listp = rlist = MLALLOC(1); rlist->n = 1; rlist->c[0] = 0; |
*listp = rlist = MLALLOC(1); rlist->n = 1; rlist->c[0] = 0; |
return; |
return; |
} |
} |
fn = sfberle(vl,f,count,&ev,&dc); |
fn = sfberle(x,y,f,count,&ev,&dc); |
if ( fn <= 1 ) { |
if ( fn <= 1 ) { |
/* fn == 0 => short of evaluation points */ |
/* fn == 0 => short of evaluation points */ |
*listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0; |
*listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0; |
return; |
return; |
} |
} |
/* pass the the leading coeff. to the first element */ |
if ( degbound >= 0 ) { |
c = dc->c; dc = NEXT(dc); |
/* |
mulp(vl,dc->c,c,&t); dc->c = t; |
* reconstruct dc so that |
|
* dc[1],... : factors satisfy degree bound |
|
* dc[0] : product of others |
|
*/ |
|
c = dc->c; dc = NEXT(dc); |
|
dc0 = 0; |
|
fn = 0; |
|
while ( dc ) { |
|
if ( getdeg(x,COEF(dc)) <= degbound ) { |
|
dct = NEXT(dc); NEXT(dc) = dc0; dc0 = dc; dc = dct; |
|
fn++; |
|
} else { |
|
mulp(vl,COEF(dc),c,&t); c = t; |
|
dc = NEXT(dc); |
|
} |
|
} |
|
if ( OID(c) == O_P ) { |
|
NEWDC(dc); COEF(dc) = c; DEG(dc) = ONE; NEXT(dc) = dc0; |
|
fn++; |
|
} else { |
|
mulp(vl,dc0->c,c,&t); dc0->c = t; dc = dc0; |
|
} |
|
} else { |
|
/* 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 */ |
/* convert mod y-a factors into UM */ |
gm = (UM *)ALLOCA(fn*sizeof(UM)); |
gm = (UM *)ALLOCA(fn*sizeof(UM)); |
Line 611 void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li |
|
Line 641 void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li |
|
|
|
/* main variable of f = x */ |
/* main variable of f = x */ |
|
|
int sfberle(VL vl,P f,int count,GFS *ev,DCP *dcp) |
int sfberle(V x,V y,P f,int count,GFS *ev,DCP *dcp) |
{ |
{ |
UM wf,wf1,wf2,wfs,gcd; |
UM wf,wf1,wf2,wfs,gcd; |
int fn,n; |
int fn,n; |
GFS m,fm; |
GFS m,fm; |
DCP dc,dct,dc0; |
DCP dc,dct,dc0; |
VL nvl; |
VL vl; |
V x,y; |
|
P lc,lc0,f0; |
P lc,lc0,f0; |
Obj obj; |
Obj obj; |
int j,q1,index,i; |
int j,q,index,i; |
|
|
clctv(vl,f,&nvl); vl = nvl; |
NEWVL(vl); vl->v = x; |
x = vl->v; y = vl->next->v; |
NEWVL(NEXT(vl)); NEXT(vl)->v = y; |
|
NEXT(NEXT(vl)) =0; |
simp_ff((Obj)f,&obj); f = (P)obj; |
simp_ff((Obj)f,&obj); f = (P)obj; |
n = QTOS(DEG(DC(f))); |
n = QTOS(DEG(DC(f))); |
wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n); |
wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n); |
wfs = W_UMALLOC(n); gcd = W_UMALLOC(n); |
wfs = W_UMALLOC(n); gcd = W_UMALLOC(n); |
q1 = field_order_sf()-1; |
q = field_order_sf(); |
lc = DC(f)->c; |
lc = DC(f)->c; |
for ( j = 0, fn = n + 1, index = 0; |
for ( j = 0, fn = n + 1, index = 0; |
index < q1 && j < count && fn > 1; index++ ) { |
index < q && j < count && fn > 1; index++ ) { |
MKGFS(index,m); |
indextogfs(index,&m); |
substp(vl,lc,y,(P)m,&lc0); |
substp(vl,lc,y,(P)m,&lc0); |
if ( lc0 ) { |
if ( lc0 ) { |
substp(vl,f,y,(P)m,&f0); |
substp(vl,f,y,(P)m,&f0); |
ptosfum(f0,wf); cpyum(wf,wf1); |
ptosfum(f0,wf); cpyum(wf,wf1); |
diffsfum(wf1,wf2); gcdsfum(wf1,wf2,gcd); |
diffsfum(wf1,wf2); gcdsfum(wf1,wf2,gcd); |
if ( DEG(gcd) == 0 ) { |
if ( DEG(gcd) == 0 ) { |
fctrsf(f0,&dc); |
ufctrsf(f0,&dc); |
for ( dct = NEXT(dc), i = 0; dct; dct = NEXT(dct), i++ ); |
for ( dct = NEXT(dc), i = 0; dct; dct = NEXT(dct), i++ ); |
if ( i < fn ) { |
if ( i < fn ) { |
dc0 = dc; fn = i; fm = m; |
dc0 = dc; fn = i; fm = m; |
Line 649 int sfberle(VL vl,P f,int count,GFS *ev,DCP *dcp) |
|
Line 679 int sfberle(VL vl,P f,int count,GFS *ev,DCP *dcp) |
|
} |
} |
} |
} |
} |
} |
if ( index == q1 ) |
if ( index == q ) |
return 0; |
return 0; |
else if ( fn == 1 ) |
else if ( fn == 1 ) |
return 1; |
return 1; |
Line 792 void sfhenmain2(BM f,UM g0,UM h0,int dy,BM *gp) |
|
Line 822 void sfhenmain2(BM f,UM g0,UM h0,int dy,BM *gp) |
|
cpyum(COEF(hk)[i],COEF(f)[i]); |
cpyum(COEF(hk)[i],COEF(f)[i]); |
} |
} |
|
|
|
/* a0*g+b0*h = 1 mod y -> a*g+b*h = 1 mod y^(dy+1) */ |
|
|
|
void sfexgcd_by_hensel(BM g,BM h,int dy,BM *ap,BM *bp) |
|
{ |
|
int i,k; |
|
int dx; |
|
UM wt,wa,wb,q,w1,w2,ws; |
|
UM wc,wd,we,wz,wa1,wb1; |
|
BM wz0,wz1; |
|
int dg,dh; |
|
BM a,b,c; |
|
|
|
dg = degbm(g); |
|
dh = degbm(h); |
|
dx = dg+dh; |
|
|
|
a = BMALLOC(dh,dy); |
|
b = BMALLOC(dg,dy); |
|
/* c holds a*g+b*h-1 */ |
|
c = BMALLOC(dg+dh,dy); |
|
|
|
W_BMALLOC(dx,dy,wz0); W_BMALLOC(dx,dy,wz1); |
|
|
|
wt = W_UMALLOC(dx); ws = W_UMALLOC(dx); q = W_UMALLOC(2*dx); |
|
wa1 = W_UMALLOC(2*dx); wb1 = W_UMALLOC(2*dx); |
|
wc = W_UMALLOC(2*dx); wd = W_UMALLOC(2*dx); |
|
we = W_UMALLOC(2*dx); wz = W_UMALLOC(2*dx); |
|
|
|
/* compute wa,wb s.t. wa*g0+wb*h0 = 1 mod y */ |
|
w1 = W_UMALLOC(dg); cpyum(COEF(g)[0],w1); |
|
w2 = W_UMALLOC(dh); cpyum(COEF(h)[0],w2); |
|
wa = W_UMALLOC(2*dx); wb = W_UMALLOC(2*dx); /* XXX */ |
|
eucsfum(w1,w2,wa,wb); |
|
cpyum(wa,COEF(a)[0]); cpyum(wb,COEF(b)[0]); |
|
|
|
/* initialize c to a*g+b*h-1 */ |
|
mulsfbm(a,g,c); mulsfbm(b,h,wz0); addtosfbm(wz0,c); |
|
COEF(COEF(c)[0])[0] = 0; |
|
|
|
fprintf(stderr,"dy=%d\n",dy); |
|
for ( k = 1; k <= dy; k++ ) { |
|
fprintf(stderr,"."); |
|
|
|
/* at this point, a*g+b*h = 1 mod y^k, c = a*g+b*h-1 */ |
|
|
|
/* wt = -((a*g+b*h-1)/y^k) */ |
|
cpyum(COEF(c)[k],wt); |
|
for ( i = DEG(wt); i >= 0; i-- ) |
|
COEF(wt)[i] = _chsgnsf(COEF(wt)[i]); |
|
|
|
/* compute wa1,wb1 s.t. wa1*g0+wb1*h0 = wt */ |
|
mulsfum(wa,wt,wa1); DEG(wa1) = divsfum(wa1,COEF(h)[0],q); |
|
mulsfum(wa1,COEF(g)[0],wc); subsfum(wt,wc,wd); |
|
DEG(wd) = divsfum(wd,COEF(h)[0],wb1); |
|
|
|
/* c += ((wa1*g+wb1*h)*y^k mod y^(dy+1) */ |
|
/* wz0 = wa1*y^k */ |
|
clearbm(dx,wz0); |
|
cpyum(wa1,COEF(wz0)[k]); |
|
|
|
/* wz1 = wz0*g mod y^(dy+1) */ |
|
clearbm(dx,wz1); |
|
mulsfbm(g,wz0,wz1); |
|
/* c += wz1 */ |
|
addtosfbm(wz1,c); |
|
|
|
/* wz0 = wb1*y^k */ |
|
clearbm(dx,wz0); |
|
cpyum(wb1,COEF(wz0)[k]); |
|
|
|
/* wz1 = wz0*h mod y^(dy+1) */ |
|
clearbm(dx,wz1); |
|
mulsfbm(h,wz0,wz1); |
|
/* c += wz1 */ |
|
addtosfbm(wz1,c); |
|
|
|
/* a += wa1*y^k, b += wb1*y^k */ |
|
cpyum(wa1,COEF(a)[k]); |
|
cpyum(wb1,COEF(b)[k]); |
|
} |
|
fprintf(stderr,"\n"); |
|
DEG(a) = dy; |
|
DEG(b) = dy; |
|
*ap = a; |
|
*bp = b; |
|
} |
|
|
/* fl->c[i] = coef_y(f,i) */ |
/* fl->c[i] = coef_y(f,i) */ |
|
|
void ptosfbm(int dy,P f,BM fl) |
void ptosfbm(int dy,P f,BM fl) |
Line 836 void sfbmtop(BM f,V x,V y,P *fp) |
|
Line 953 void sfbmtop(BM f,V x,V y,P *fp) |
|
if ( DEG(c[j]) >= i && (a = COEF(c[j])[i]) ) { |
if ( DEG(c[j]) >= i && (a = COEF(c[j])[i]) ) { |
NEWDC(dct); |
NEWDC(dct); |
STOQ(j,DEG(dct)); |
STOQ(j,DEG(dct)); |
MKGFS(IFTOF(a),b); |
iftogfs(a,&b); |
COEF(dct) = (P)b; |
COEF(dct) = (P)b; |
NEXT(dct) = dc; |
NEXT(dct) = dc; |
dc = dct; |
dc = dct; |
Line 869 void sfsqfr(P f,DCP *dcp) |
|
Line 986 void sfsqfr(P f,DCP *dcp) |
|
NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; *dcp = dc; |
NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; *dcp = dc; |
} else if ( !NEXT(vl) ) |
} else if ( !NEXT(vl) ) |
sfusqfr(f,dcp); |
sfusqfr(f,dcp); |
else if ( !NEXT(NEXT(vl)) ) |
|
sfbsqfr(f,vl->v,NEXT(vl)->v,dcp); |
|
else |
else |
error("sfsqfr : not implemented yet"); |
sqfrsf(f,dcp); |
} |
} |
|
|
void sfusqfr(P f,DCP *dcp) |
void sfusqfr(P f,DCP *dcp) |
Line 903 void sfusqfr(P f,DCP *dcp) |
|
Line 1018 void sfusqfr(P f,DCP *dcp) |
|
*dcp = dct; |
*dcp = dct; |
} |
} |
|
|
|
#if 0 |
|
void sfbsqfrmain(P f,V x,V y,DCP *dcp) |
|
{ |
|
/* XXX*/ |
|
} |
|
|
|
/* f is bivariate */ |
|
|
void sfbsqfr(P f,V x,V y,DCP *dcp) |
void sfbsqfr(P f,V x,V y,DCP *dcp) |
{ |
{ |
P t,rf,cx,cy; |
P t,rf,cx,cy; |
VL vl,rvl; |
VL vl,rvl; |
DCP dcx,dcy; |
DCP dcx,dcy,dct,dc; |
struct oVL vl0,vl1; |
struct oVL vl0,vl1; |
|
|
/* vl = [x,y] */ |
/* cy(y) = cont(f,x), f /= cy */ |
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; |
cont_pp_sfp(vl,f,&cy,&t); f = t; |
/* rvl = [y,x] */ |
/* rvl = [y,x] */ |
reordvar(vl,y,&rvl); reorderp(rvl,vl,f,&rf); |
reordvar(vl,y,&rvl); reorderp(rvl,vl,f,&rf); |
Line 921 void sfbsqfr(P f,V x,V y,DCP *dcp) |
|
Line 1042 void sfbsqfr(P f,V x,V y,DCP *dcp) |
|
reorderp(vl,rvl,rf,&f); |
reorderp(vl,rvl,rf,&f); |
|
|
/* f -> cx*cy*f */ |
/* f -> cx*cy*f */ |
sfusqfr(cx,&dcx); |
sfsqfr(cx,&dcx); dcx = NEXT(dcx); |
sfusqfr(cy,&dcy); |
sfsqfr(cy,&dcy); dcy = NEXT(dcy); |
|
if ( dcx ) { |
|
for ( dct = dcx; NEXT(dct); dct = NEXT(dct) ); |
|
NEXT(dct) = dcy; |
|
} else |
|
dcx = dcy; |
|
if ( OID(f) == O_N ) |
|
*dcp = dcx; |
|
else { |
|
/* f must be bivariate */ |
|
sfbsqfrmain(f,x,y,&dc); |
|
if ( dcx ) { |
|
for ( dct = dcx; NEXT(dct); dct = NEXT(dct) ); |
|
NEXT(dct) = dc; |
|
} else |
|
dcx = dc; |
|
*dcp = dcx; |
|
} |
} |
} |
|
#endif |
|
|
void sfdtest(P,ML,V,V,DCP *); |
void sfdtest(P,ML,V,V,DCP *); |
|
|
void sfbfctr(P f,V x,V y,DCP *dcp) |
/* if degbound >= 0 find factor s.t. deg_x(factor) <= degbound */ |
|
|
|
void sfbfctr(P f,V x,V y,int degbound,DCP *dcp) |
{ |
{ |
ML list; |
ML list; |
P sf; |
P sf; |
Line 937 void sfbfctr(P f,V x,V y,DCP *dcp) |
|
Line 1078 void sfbfctr(P f,V x,V y,DCP *dcp) |
|
int dx,dy; |
int dx,dy; |
|
|
/* 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,&ev,&sf,&list); |
sfhensel(5,f,x,y,degbound,&ev,&sf,&list); |
if ( list->n == 0 ) |
if ( list->n == 0 ) |
error("sfbfctr : short of evaluation points"); |
error("sfbfctr : short of evaluation points"); |
else if ( list->n == 1 ) { |
else if ( list->n == 1 ) { |
Line 960 void sfbfctr(P f,V x,V y,DCP *dcp) |
|
Line 1101 void sfbfctr(P f,V x,V y,DCP *dcp) |
|
*dcp = dc; |
*dcp = dc; |
} |
} |
|
|
|
/* returns shifted f, shifted factors and the eval pt */ |
|
|
|
void sfbfctr_shift(P f,V x,V y,int degbound,GFS *evp,P *sfp,DCP *dcp) |
|
{ |
|
ML list; |
|
P sf; |
|
GFS ev; |
|
DCP dc,dct; |
|
int dx,dy; |
|
|
|
/* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */ |
|
sfhensel(5,f,x,y,degbound,&ev,&sf,&list); |
|
if ( list->n == 0 ) |
|
error("sfbfctr_shift : short of evaluation points"); |
|
else if ( list->n == 1 ) { |
|
/* f is irreducible */ |
|
NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; |
|
*evp = 0; |
|
*sfp = f; |
|
*dcp = dc; |
|
} else { |
|
sfdtest(sf,list,x,y,dcp); |
|
*evp = ev; |
|
*sfp = sf; |
|
} |
|
} |
|
|
/* f = f(x,y) = list->c[0]*list->c[1]*... mod y^(list->bound+1) */ |
/* f = f(x,y) = list->c[0]*list->c[1]*... mod y^(list->bound+1) */ |
|
|
void sfdtest(P f,ML list,V x,V y,DCP *dcp) |
void sfdtest(P f,ML list,V x,V y,DCP *dcp) |
Line 1267 void cont_pp_sfp(VL vl,P f,P *cp,P *fp) |
|
Line 1435 void cont_pp_sfp(VL vl,P f,P *cp,P *fp) |
|
y = vl->next->v; |
y = vl->next->v; |
d = getdeg(y,f); |
d = getdeg(y,f); |
if ( d == 0 ) { |
if ( d == 0 ) { |
MKGFS(0,g); |
itogfs(1,&g); |
*cp = (P)g; |
*cp = (P)g; |
*fp = f; /* XXX */ |
*fp = f; /* XXX */ |
} else { |
} else { |
Line 1333 int divtp_by_sfbm(VL vl,P f,P g,P *qp) |
|
Line 1501 int divtp_by_sfbm(VL vl,P f,P g,P *qp) |
|
/* XXX generate an irreducible poly of degree n */ |
/* XXX generate an irreducible poly of degree n */ |
|
|
extern int current_gfs_q1; |
extern int current_gfs_q1; |
|
extern int *current_gfs_ntoi; |
|
|
void generate_defpoly_sfum(int n,UM *dp) |
void generate_defpoly_sfum(int n,UM *dp) |
{ |
{ |
Line 1360 void generate_defpoly_sfum(int n,UM *dp) |
|
Line 1529 void generate_defpoly_sfum(int n,UM *dp) |
|
for ( j = 0; j < i; j++ ) |
for ( j = 0; j < i; j++ ) |
w[j] = 0; |
w[j] = 0; |
w[i]++; |
w[i]++; |
for ( i = 0; i < n; i++ ) |
if ( !current_gfs_ntoi ) |
c[i] = w[i]?FTOIF(w[i]-1):0; |
for ( i = 0; i < n; i++ ) |
|
c[i] = w[i]?FTOIF(w[i]):0; |
|
else |
|
for ( i = 0; i < n; i++ ) |
|
c[i] = w[i]?FTOIF(w[i]-1):0; |
if ( !c[0] ) |
if ( !c[0] ) |
continue; |
continue; |
diffsfum(r,dr); cpyum(r,t); gcdsfum(t,dr,g); |
diffsfum(r,dr); cpyum(r,t); gcdsfum(t,dr,g); |