version 1.2, 2002/09/26 09:07:42 |
version 1.4, 2002/09/30 06:13:07 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Fgfs.c,v 1.1 2002/09/26 04:33:16 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/Fgfs.c,v 1.3 2002/09/27 08:40:48 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
|
|
|
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 ugcdsf(P *pa,int m,P *r); |
|
void head_monomial(V v,P p,P *coef,P *term); |
|
void sqfrsfmain(VL vl,P f,DCP *dcp); |
|
void pthrootsf(P f,Q m,P *r); |
|
void partial_sqfrsf(VL vl,V v,P f,P *r,DCP *dcp); |
|
void gcdsf(VL vl,P *pa,int k,P *r); |
|
|
|
void lex_lc(P f,P *c) |
|
{ |
|
if ( !f || NUM(f) ) |
|
*c = f; |
|
else |
|
lex_lc(COEF(DC(f)),c); |
|
} |
|
|
|
DCP append_dc(DCP dc,DCP dct) |
|
{ |
|
DCP dcs; |
|
|
|
if ( !dc ) |
|
return dct; |
|
else { |
|
for ( dcs = dc; NEXT(dcs); dcs = NEXT(dcs) ); |
|
NEXT (dcs) = dct; |
|
return dc; |
|
} |
|
} |
|
|
|
void sqfrsf(VL vl, P f, DCP *dcp) |
|
{ |
|
DCP dc,dct; |
|
Obj obj; |
|
P t,s,c; |
|
VL tvl,nvl; |
|
|
|
simp_ff((Obj)f,&obj); f = (P)obj; |
|
lex_lc(f,&c); divsp(vl,f,c,&t); f = t; |
|
monomialfctr(vl,f,&t,&dc); f = t; |
|
clctv(vl,f,&tvl); vl = tvl; |
|
if ( !vl ) |
|
; |
|
else if ( !NEXT(vl) ) { |
|
sfusqfr(f,&dct); |
|
dc = append_dc(dc,NEXT(dct)); |
|
} else { |
|
t = f; |
|
for ( tvl = vl; tvl; tvl = NEXT(tvl) ) { |
|
reordvar(vl,tvl->v,&nvl); |
|
cont_pp_mv_sf(vl,NEXT(nvl),t,&c,&s); t = s; |
|
sqfrsf(vl,c,&dct); |
|
dc = append_dc(dc,NEXT(dct)); |
|
} |
|
sqfrsfmain(vl,t,&dct); |
|
dc = append_dc(dc,dct); |
|
} |
|
NEWDC(dct); DEG(dct) = ONE; COEF(dct) = (P)c; NEXT(dct) = dc; |
|
*dcp = dct; |
|
} |
|
|
|
void sqfrsfmain(VL vl,P f,DCP *dcp) |
|
{ |
|
VL tvl; |
|
DCP dc,dct,dcs; |
|
P t,s; |
|
Q m,m1; |
|
V v; |
|
|
|
clctv(vl,f,&tvl); vl = tvl; |
|
dc = 0; |
|
t = f; |
|
for ( tvl = vl; tvl; tvl = NEXT(tvl) ) { |
|
v = tvl->v; |
|
partial_sqfrsf(vl,v,t,&s,&dct); t = s; |
|
dc = append_dc(dc,dct); |
|
} |
|
if ( !NUM(t) ) { |
|
STOQ(characteristic_sf(),m); |
|
pthrootsf(t,m,&s); |
|
sqfrsfmain(vl,s,&dct); |
|
for ( dcs = dct; dcs; dcs = NEXT(dcs) ) { |
|
mulq(DEG(dcs),m,&m1); DEG(dcs) = m1; |
|
} |
|
dc = append_dc(dc,dct); |
|
} |
|
*dcp = dc; |
|
} |
|
|
|
void pthrootsf(P f,Q m,P *r) |
|
{ |
|
DCP dc,dc0,dct; |
|
N qn,rn; |
|
|
|
if ( NUM(f) ) |
|
pthrootgfs(f,r); |
|
else { |
|
dc = DC(f); |
|
dc0 = 0; |
|
for ( dc0 = 0; dc; dc = NEXT(dc) ) { |
|
NEXTDC(dc0,dct); |
|
pthrootsf(COEF(dc),m,&COEF(dct)); |
|
if ( DEG(dc) ) { |
|
divn(NM(DEG(dc)),NM(m),&qn,&rn); |
|
if ( rn ) |
|
error("pthrootsf : cannot happen"); |
|
NTOQ(qn,1,DEG(dct)); |
|
} else |
|
DEG(dct) = 0; |
|
} |
|
NEXT(dct) = 0; |
|
MKP(VR(f),dc0,*r); |
|
} |
|
} |
|
|
|
void partial_sqfrsf(VL vl,V v,P f,P *r,DCP *dcp) |
|
{ |
|
P ps[2]; |
|
DCP dc0,dc; |
|
int m; |
|
P t,flat,flat1,g,df,q; |
|
|
|
diffp(vl,f,v,&df); |
|
if ( !df ) { |
|
*dcp = 0; |
|
*r = f; |
|
return; |
|
} |
|
ps[0] = f; ps[1] = df; |
|
gcdsf(vl,ps,2,&g); |
|
divsp(vl,f,g,&flat); |
|
m = 0; |
|
t = f; |
|
dc0 = 0; |
|
while ( !NUM(flat) ) { |
|
while ( divtp(vl,t,flat,&q) ) { |
|
t = q; m++; |
|
} |
|
ps[0] = t; ps[1] = flat; |
|
gcdsf(vl,ps,2,&flat1); |
|
divsp(vl,flat,flat1,&g); |
|
flat = flat1; |
|
NEXTDC(dc0,dc); |
|
COEF(dc) = g; |
|
STOQ(m,DEG(dc)); |
|
} |
|
NEXT(dc) = 0; |
|
*dcp = dc0; |
|
*r = t; |
|
} |
|
|
void gcdsf(VL vl,P *pa,int k,P *r) |
void gcdsf(VL vl,P *pa,int k,P *r) |
{ |
{ |
P *ps,*pl,*pm,*cp; |
P *ps,*pl,*pm; |
|
P **cp; |
int *cn; |
int *cn; |
DCP *ml; |
DCP *ml; |
Obj obj; |
Obj obj; |
Line 17 void gcdsf(VL vl,P *pa,int k,P *r) |
|
Line 168 void gcdsf(VL vl,P *pa,int k,P *r) |
|
for ( i = 0, m = 0; i < k; i++ ) { |
for ( i = 0, m = 0; i < k; i++ ) { |
simp_ff((Obj)pa[i],&obj); |
simp_ff((Obj)pa[i],&obj); |
if ( obj ) |
if ( obj ) |
ps[m++] = obj; |
ps[m++] = (P)obj; |
} |
} |
if ( !m ) { |
if ( !m ) { |
*r = 0; |
*r = 0; |
return; |
return; |
} |
} |
if ( m == 1 ) { |
if ( m == 1 ) { |
*r = BDY(n0); |
*r = ps[0]; |
return; |
return; |
} |
} |
pl = (P *)ALLOCA(m*sizeof(P)); |
pl = (P *)ALLOCA(m*sizeof(P)); |
ml = (DCP *)ALLOCA(m*sizeof(DCP)); |
ml = (DCP *)ALLOCA(m*sizeof(DCP)); |
for ( i = 0; i < m; i++ ) |
for ( i = 0; i < m; i++ ) |
monomialfctr(vl,ps[i],&pl[i],&ml[i]); |
monomialfctr(vl,ps[i],&pl[i],&ml[i]); |
gcdmonomial(vl,ml,m,&mg); simp_ff(mg,&mgsf); |
gcdmonomial(vl,ml,m,&mg); simp_ff((Obj)mg,&obj); mgsf = (P)obj; |
for ( i = 0, nvl = vl, avl = 0; nvl && i < m; i++ ) { |
for ( i = 0, nvl = vl, avl = 0; nvl && i < m; i++ ) { |
clctv(vl,pl[i],&tvl); |
clctv(vl,pl[i],&tvl); |
intersectv(nvl,tvl,&svl); nvl = svl; |
intersectv(nvl,tvl,&svl); nvl = svl; |
Line 73 void gcdsf(VL vl,P *pa,int k,P *r) |
|
Line 224 void gcdsf(VL vl,P *pa,int k,P *r) |
|
|
|
void ugcdsf(P *pa,int m,P *r) |
void ugcdsf(P *pa,int m,P *r) |
{ |
{ |
P *pa; |
P *ps; |
int i; |
int i; |
UM w1,w2,w3,w; |
UM w1,w2,w3,w; |
int d; |
int d; |
Line 83 void ugcdsf(P *pa,int m,P *r) |
|
Line 234 void ugcdsf(P *pa,int m,P *r) |
|
*r = pa[0]; |
*r = pa[0]; |
return; |
return; |
} |
} |
|
for ( i = 0; i < m; i++ ) |
|
if ( NUM(pa[i]) ) { |
|
itogfs(1,r); |
|
return; |
|
} |
ps = (P *)ALLOCA(m*sizeof(P)); |
ps = (P *)ALLOCA(m*sizeof(P)); |
v = VR(pa[0]); |
|
sort_by_deg(m,pa,ps); |
sort_by_deg(m,pa,ps); |
d = getdeg(ps[m-1],v); |
v = VR(ps[m-1]); |
|
d = getdeg(v,ps[m-1]); |
w1 = W_UMALLOC(d); |
w1 = W_UMALLOC(d); |
w2 = W_UMALLOC(d); |
w2 = W_UMALLOC(d); |
w3 = W_UMALLOC(d); |
w3 = W_UMALLOC(d); |
Line 96 void ugcdsf(P *pa,int m,P *r) |
|
Line 252 void ugcdsf(P *pa,int m,P *r) |
|
gcdsfum(w1,w2,w3); |
gcdsfum(w1,w2,w3); |
w = w1; w1 = w3; w3 = w; |
w = w1; w1 = w3; w3 = w; |
if ( !DEG(w1) ) { |
if ( !DEG(w1) ) { |
MKGFS(0,*r); |
itogfs(1,r); |
return; |
return; |
} |
} |
} |
} |
sfumtop(v,w1,r); |
sfumtop(v,w1,r); |
} |
} |
|
|
|
/* deg(HT(p),v), where p is considered as distributed poly over F[v] */ |
|
int gethdeg(VL vl,V v,P p) |
|
{ |
|
DCP dc; |
|
Q dmax; |
|
P cmax; |
|
|
|
if ( !p ) |
|
return -1; |
|
else if ( NUM(p) ) |
|
return 0; |
|
else if ( VR(p) != v ) |
|
/* HT(p) = HT(lc(p))*x^D */ |
|
return gethdeg(vl,v,COEF(DC(p))); |
|
else { |
|
/* VR(p) = v */ |
|
dc = DC(p); dmax = DEG(dc); cmax = COEF(dc); |
|
for ( dc = NEXT(dc); dc; dc = NEXT(dc) ) |
|
if ( compp(vl,COEF(dc),cmax) > 0 ) { |
|
dmax = DEG(dc); cmax = COEF(dc); |
|
} |
|
return QTOS(dmax); |
|
} |
|
} |
|
|
/* all the pa[i]'s have the same variables (=vl) */ |
/* all the pa[i]'s have the same variables (=vl) */ |
|
|
void gcdsf_main(VL vl,P *pa,int m,P *r) |
void gcdsf_main(VL vl,P *pa,int m,P *r) |
{ |
{ |
int nv,i,i0,imin,d,d0,d1,d2; |
int nv,i,i0,imin,d,d0,d1,d2,dmin,index; |
V v0,vmin; |
V v,v0,vmin; |
VL tvl,nvl,rvl,nvl0,rvl0; |
VL tvl,nvl,rvl,nvl0,rvl0; |
P *pc, *ps, *ph; |
P *pc, *ps, *ph,*lps; |
|
P x,t,cont,hg,g,hm,mod,s; |
|
P hge,ge,ce,he,u,cof1e,mode,mod1,adj,cof1,coadj,q; |
|
GFS sf; |
|
|
for ( nv = 0, tvl = vl; tvl; tvl = NEXT(tvl), nv++); |
for ( nv = 0, tvl = vl; tvl; tvl = NEXT(tvl), nv++); |
if ( nv == 1 ) { |
if ( nv == 1 ) { |
ugcdsf(pa,m,r); |
ugcdsf(pa,m,r); |
return; |
return; |
} |
} |
/* find v s.t. min(deg(pa[i],v)) is minimal */ |
/* find v s.t. min(deg(pa[i],v)+gethdeg(pa[i],v)) is minimal */ |
tvl = vl; |
tvl = vl; |
do { |
do { |
v = tvl->v; |
v = tvl->v; |
i = 0; |
i = 0; |
do { |
do { |
d = getdeg(pa[i],v); |
d = getdeg(v,pa[i])+gethdeg(vl,v,pa[i]); |
if ( i == 0 || (d < d0) ) { |
if ( i == 0 || (d < d0) ) { |
d0 = d; i0 = i; v0 = v; |
d0 = d; i0 = i; v0 = v; |
} |
} |
Line 141 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
Line 324 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
NEXTVL(rvl0,rvl); rvl->v = tvl->v; |
NEXTVL(rvl0,rvl); rvl->v = tvl->v; |
} |
} |
/* rvl = remaining variables */ |
/* rvl = remaining variables */ |
NEXT(rvl) = 0; |
NEXT(rvl) = 0; rvl = rvl0; |
/* nvl = ...,vmin */ |
/* nvl = ...,vmin */ |
NEXTVL(nvl0,nvl); nvl->v = vmin; NEXT(nvl) = 0; |
NEXTVL(nvl0,nvl); nvl->v = vmin; NEXT(nvl) = 0; nvl = nvl0; |
MKV(vmin,x); |
MKV(vmin,x); |
|
|
/* for content and primitive part */ |
/* for content and primitive part */ |
Line 152 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
Line 335 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
ph = (P *)ALLOCA(m*sizeof(P)); |
ph = (P *)ALLOCA(m*sizeof(P)); |
/* separate the contents */ |
/* separate the contents */ |
for ( i = 0; i < m; i++ ) { |
for ( i = 0; i < m; i++ ) { |
reorderp(vl,nvl,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(vmin,ps[i],&ph[i],&t); |
} |
} |
Line 166 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
Line 349 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
|
|
while ( 1 ) { |
while ( 1 ) { |
g = 0; |
g = 0; |
cofmin = 0; |
cof1 = 0; |
hm = 0; |
hm = 0; |
MKGFS(0,mod); |
itogfs(1,&mod); |
index = 0; |
index = 0; |
while ( getdeg(mod,vmin) <= d+1 ) { |
for ( index = 0; getdeg(vmin,mod) <= d+1; index++ ) { |
/* evaluation pt */ |
/* evaluation pt */ |
MKGFS(index,s); |
indextogfs(index,&s); |
substp(nvl,hg,vmin,s,&hge); |
substp(nvl,hg,vmin,s,&hge); |
if ( !hge ) |
if ( !hge ) |
continue; |
continue; |
Line 181 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
Line 364 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
/* 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(vmin,ge,&ce,&he); |
if ( NUM(hge) ) { |
if ( NUM(he) ) { |
*r = cont; |
*r = cont; |
return; |
return; |
} |
} |
divgfs(hge,ce,&t); mulp(nvl,t,ge,&u); ge = u; |
divgfs((GFS)hge,(GFS)ce,&sf); t = (P)sf; |
|
mulp(nvl,t,ge,&u); ge = u; |
divsp(nvl,ph[imin],ge,&t); mulp(nvl,hge,t,&cof1e); |
divsp(nvl,ph[imin],ge,&t); mulp(nvl,hge,t,&cof1e); |
/* hm=0 : reset; he==hm : lucky */ |
/* hm=0 : reset; he==hm : lucky */ |
if ( !hm || !cmpp(he,hm) ) { |
if ( !hm || !compp(nvl,he,hm) ) { |
substp(nvl,mod,vmin,s,&mode); divsp(nvl,mod,mode,&mod1); |
substp(nvl,mod,vmin,s,&mode); divsp(nvl,mod,mode,&mod1); |
/* adj = mod/(mod|x=s)*(ge-g|x=s) */ |
/* adj = mod/(mod|x=s)*(ge-g|x=s) */ |
substp(nvl,g,vmin,s,&t); |
substp(nvl,g,vmin,s,&t); |
subp(nvl,ge,t,&u); mulp(nvl,mod1,u,&adj); |
subp(nvl,ge,t,&u); mulp(nvl,mod1,u,&adj); |
/* coadj = mod/(mod|vmin=s)*(cof1e-cof1e|vmin=s) */ |
/* coadj = mod/(mod|vmin=s)*(cof1e-cof1e|vmin=s) */ |
substp(nvl,cof1,vmin,s,&t); |
substp(nvl,cof1,vmin,s,&t); |
subp(nvl,cof1,t,&u); mulp(nvl,mod1,u,&coadj); |
subp(nvl,cof1e,t,&u); mulp(nvl,mod1,u,&coadj); |
if ( !adj ) { |
if ( !adj ) { |
/* adj == gcd ? */ |
/* adj == gcd ? */ |
for ( i = 0; i < m; i++ ) |
for ( i = 0; i < m; i++ ) |
if ( !divtp(nvl,lps[i],adj,&t) ) |
if ( !divtp(nvl,lps[i],g,&t) ) |
break; |
break; |
if ( i == m ) { |
if ( i == m ) { |
cont_pp_mv_sf(nvl,rvl,adj,&t,&u); |
cont_pp_mv_sf(nvl,rvl,g,&t,&u); |
mulp(nvl,cont,u,&t); |
mulp(nvl,cont,u,&t); |
reorderp(nvl,vl,t,r); |
reorderp(vl,nvl,t,r); |
return; |
return; |
} |
} |
} else if ( !coadj ) { |
} else if ( !coadj ) { |
/* ps[vmin]/coadj == gcd ? */ |
/* ps[imin]/coadj == gcd ? */ |
if ( divtp(nvl,lps[vmin],coadj,&q) ) { |
if ( divtp(nvl,lps[imin],cof1,&q) ) { |
for ( i = 0; i < m; i++ ) |
for ( i = 0; i < m; i++ ) |
if ( !divtp(nvl,lps[i],q,&t) ) |
if ( !divtp(nvl,lps[i],q,&t) ) |
break; |
break; |
if ( i == m ) { |
if ( i == m ) { |
cont_pp_mv_sf(nvl,rvl,q,&t,&u); |
cont_pp_mv_sf(nvl,rvl,q,&t,&u); |
mulp(nvl,cont,u,&t); |
mulp(nvl,cont,u,&t); |
reorderp(nvl,vl,t,r); |
reorderp(vl,nvl,t,r); |
return; |
return; |
} |
} |
} |
} |
Line 239 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
Line 423 void gcdsf_main(VL vl,P *pa,int m,P *r) |
|
/* d1==d2, but hm!=he => both are unlucky */ |
/* d1==d2, but hm!=he => both are unlucky */ |
g = 0; |
g = 0; |
cof1 = 0; |
cof1 = 0; |
MKGFS(0,mod); |
itogfs(1,&mod); |
} |
} |
} |
} |
} |
} |
Line 251 void head_monomial(V v,P p,P *coef,P *term) |
|
Line 435 void head_monomial(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; |
|
|
MKGFS(0,one); t = one; |
itogfs(1,&one); |
|
t = (P)one; |
while ( 1 ) { |
while ( 1 ) { |
if ( NUM(p) || VR(p) == v ) { |
if ( NUM(p) || VR(p) == v ) { |
*coef = p; |
*coef = p; |
*term = t; |
*term = t; |
return; |
return; |
} else { |
} else { |
NEWDC(dc); MKGFS(0,one); |
NEWDC(dc); |
COEF(dc) = one; DEG(dc) = DEG(DC(p)); |
COEF(dc) = (P)one; DEG(dc) = DEG(DC(p)); |
MKP(VR(p),dc,s); |
MKP(VR(p),dc,s); |
mulp(vl,t,s,&u); t = u; |
mulp(vl,t,s,&u); t = u; |
p = COEF(DC(p)); |
p = COEF(DC(p)); |
Line 278 void cont_pp_mv_sf(VL vl,VL rvl,P p,P *c,P *pp) |
|
Line 464 void cont_pp_mv_sf(VL vl,VL rvl,P p,P *c,P *pp) |
|
ptod(vl,rvl,p,&dp); |
ptod(vl,rvl,p,&dp); |
for ( t = BDY(dp), m = 0; t; t = NEXT(t), m++ ); |
for ( t = BDY(dp), m = 0; t; t = NEXT(t), m++ ); |
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); |
ugcdsf(ps,m,c); |
divsp(vl,p,c,pp); |
divsp(vl,p,*c,pp); |
} |
} |