version 1.4, 2000/08/22 05:04:04 |
version 1.15, 2018/02/28 03:55:38 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/engine/PU.c,v 1.3 2000/08/21 08:31:26 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/PU.c,v 1.14 2010/01/31 03:25:54 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
|
void reorderp(nvl,ovl,p,pr) |
void reorderp(VL nvl,VL ovl,P p,P *pr) |
VL nvl,ovl; |
|
P p; |
|
P *pr; |
|
{ |
{ |
DCP dc; |
DCP dc; |
P x,m,s,t,c; |
P x,m,s,t,c; |
|
|
} |
} |
} |
} |
|
|
void substp(vl,p,v0,p0,pr) |
void substp(VL vl,P p,V v0,P p0,P *pr) |
VL vl; |
|
V v0; |
|
P p,p0; |
|
P *pr; |
|
{ |
{ |
P x,t,m,c,s,a; |
P x,t,m,c,s,a; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
void detp(vl,rmat,n,dp) |
void substpp(VL vl,P p,V *vvect,P *svect,int nv,P *pr); |
VL vl; |
|
P **rmat; |
void substpp(VL vl,P p,V *vvect,P *svect,int nv,P *pr) |
int n; |
|
P *dp; |
|
{ |
{ |
int i,j,k,sgn; |
P x,t,m,c,s,a,p0,c1; |
|
DCP dc; |
|
Q d; |
|
V v; |
|
int i; |
|
|
|
if ( !p ) |
|
*pr = 0; |
|
else if ( NUM(p) ) |
|
*pr = p; |
|
else { |
|
v = VR(p); |
|
for ( i = 0; i < nv; i++ ) if ( vvect[i] == v ) break; |
|
if ( svect[i] && OID(svect[i]) < 0 ) { |
|
MKV(VR(p),x); |
|
for ( c = 0, dc = DC(p); dc; dc = NEXT(dc) ) { |
|
substpp(vl,COEF(dc),vvect,svect,nv,&t); |
|
if ( DEG(dc) ) { |
|
pwrp(vl,x,DEG(dc),&s); mulp(vl,s,t,&m); |
|
addp(vl,m,c,&a); |
|
c = a; |
|
} else { |
|
addp(vl,t,c,&a); |
|
c = a; |
|
} |
|
} |
|
*pr = c; |
|
} else { |
|
p0 = svect[i]; |
|
dc = DC(p); |
|
substpp(vl,COEF(dc),vvect,svect,nv,&c); |
|
for ( d = DEG(dc), dc = NEXT(dc); |
|
dc; d = DEG(dc), dc = NEXT(dc) ) { |
|
subq(d,DEG(dc),(Q *)&t); pwrp(vl,p0,(Q)t,&s); |
|
mulp(vl,s,c,&m); |
|
substpp(vl,COEF(dc),vvect,svect,nv,&c1); |
|
addp(vl,m,c1,&c); |
|
} |
|
if ( d ) { |
|
pwrp(vl,p0,d,&t); mulp(vl,t,c,&m); |
|
c = m; |
|
} |
|
*pr = c; |
|
} |
|
} |
|
} |
|
|
|
void detp(VL vl,P **rmat,int n,P *dp) |
|
{ |
|
int i,j,k,l,sgn,nmin,kmin,lmin,ntmp; |
P mjj,mij,t,s,u,d; |
P mjj,mij,t,s,u,d; |
P **mat; |
P **mat; |
P *mi,*mj; |
P *mi,*mj; |
|
|
if ( i == n ) { |
if ( i == n ) { |
*dp = 0; return; |
*dp = 0; return; |
} |
} |
for ( k = i; k < n; k++ ) |
nmin = nmonop(mat[i][j]); |
if ( mat[k][j] && (nmonop(mat[k][j]) < nmonop(mat[i][j]) ) ) |
kmin=i; lmin=j; |
i = k; |
for ( k = j; k < n; k++ ) |
if ( j != i ) { |
for ( l = j; l < n; l++ ) |
mj = mat[j]; mat[j] = mat[i]; mat[i] = mj; sgn = -sgn; |
if ( mat[k][l] && ((ntmp=nmonop(mat[k][l])) < nmin) ) { |
|
kmin = k; lmin = l; nmin = ntmp; |
|
} |
|
if ( kmin != j ) { |
|
mj = mat[j]; mat[j] = mat[kmin]; mat[kmin] = mj; sgn = -sgn; |
} |
} |
|
if ( lmin != j ) { |
|
for ( k = j; k < n; k++ ) { |
|
t = mat[k][j]; mat[k][j] = mat[k][lmin]; mat[k][lmin] = t; |
|
} |
|
sgn = -sgn; |
|
} |
for ( i = j + 1, mj = mat[j], mjj = mj[j]; i < n; i++ ) |
for ( i = j + 1, mj = mat[j], mjj = mj[j]; i < n; i++ ) |
for ( k = j + 1, mi = mat[i], mij = mi[j]; k < n; k++ ) { |
for ( k = j + 1, mi = mat[i], mij = mi[j]; k < n; k++ ) { |
mulp(vl,mi[k],mjj,&t); mulp(vl,mj[k],mij,&s); |
mulp(vl,mi[k],mjj,&t); mulp(vl,mj[k],mij,&s); |
|
|
*dp = d; |
*dp = d; |
} |
} |
|
|
void reordvar(vl,v,nvlp) |
void invmatp(VL vl,P **rmat,int n,P ***imatp,P *dnp) |
VL vl; |
|
V v; |
|
VL *nvlp; |
|
{ |
{ |
|
int i,j,k,l,n2; |
|
P mjj,mij,t,s,u,d; |
|
P **mat,**imat; |
|
P *mi,*mj,*w; |
|
|
|
n2 = n<<1; |
|
mat = (P **)almat_pointer(n,n2); |
|
for ( i = 0; i < n; i++ ) { |
|
for ( j = 0; j < n; j++ ) |
|
mat[i][j] = rmat[i][j]; |
|
mat[i][i+n] = (P)ONE; |
|
} |
|
for ( j = 0, d = (P)ONE; j < n; j++ ) { |
|
for ( i = j; (i < n) && !mat[i][j]; i++ ); |
|
if ( i == n ) { |
|
error("invmatp : input is singular"); |
|
} |
|
for ( k = i; k < n; k++ ) |
|
if ( mat[k][j] && (nmonop(mat[k][j]) < nmonop(mat[i][j]) ) ) |
|
i = k; |
|
if ( j != i ) { |
|
mj = mat[j]; mat[j] = mat[i]; mat[i] = mj; |
|
} |
|
for ( i = j + 1, mj = mat[j], mjj = mj[j]; i < n; i++ ) |
|
for ( k = j + 1, mi = mat[i], mij = mi[j]; k < n2; k++ ) { |
|
mulp(vl,mi[k],mjj,&t); mulp(vl,mj[k],mij,&s); |
|
subp(vl,t,s,&u); divsp(vl,u,d,&mi[k]); |
|
} |
|
d = mjj; |
|
} |
|
/* backward substitution */ |
|
w = (P *)ALLOCA(n2*sizeof(P)); |
|
for ( i = n-2; i >= 0; i-- ) { |
|
bzero(w,n2*sizeof(P)); |
|
for ( k = i+1; k < n; k++ ) |
|
for ( l = k, u = mat[i][l]; l < n2; l++ ) { |
|
mulp(vl,mat[k][l],u,&t); addp(vl,w[l],t,&s); w[l] = s; |
|
} |
|
for ( j = i, u = mat[i][j]; j < n2; j++ ) { |
|
mulp(vl,mat[i][j],d,&t); subp(vl,t,w[j],&s); |
|
divsp(vl,s,u,&mat[i][j]); |
|
} |
|
} |
|
imat = (P **)almat_pointer(n,n); |
|
for ( i = 0; i < n; i++ ) |
|
for ( j = 0; j < n; j++ ) |
|
imat[i][j] = mat[i][j+n]; |
|
*imatp = imat; |
|
*dnp = d; |
|
} |
|
|
|
void reordvar(VL vl,V v,VL *nvlp) |
|
{ |
VL nvl,nvl0; |
VL nvl,nvl0; |
|
|
for ( NEWVL(nvl0), nvl0->v = v, nvl = nvl0; |
for ( NEWVL(nvl0), nvl0->v = v, nvl = nvl0; |
|
|
*nvlp = nvl0; |
*nvlp = nvl0; |
} |
} |
|
|
void gcdprsp(vl,p1,p2,pr) |
void gcdprsp(VL vl,P p1,P p2,P *pr) |
VL vl; |
|
P p1,p2,*pr; |
|
{ |
{ |
P g1,g2,gc1,gc2,gp1,gp2,g,gc,gp,gcr; |
P g1,g2,gc1,gc2,gp1,gp2,g,gc,gp,gcr; |
V v1,v2; |
V v1,v2; |
|
|
} |
} |
} |
} |
|
|
void gcdcp(vl,p,pr) |
void gcdcp(VL vl,P p,P *pr) |
VL vl; |
|
P p,*pr; |
|
{ |
{ |
P g,g1; |
P g,g1; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
void sprs(vl,v,p1,p2,pr) |
void sprs(VL vl,V v,P p1,P p2,P *pr) |
VL vl; |
|
V v; |
|
P p1,p2,*pr; |
|
{ |
{ |
P q1,q2,m,m1,m2,x,h,r,g1,g2; |
P q1,q2,m,m1,m2,x,h,r,g1,g2; |
int d; |
int d; |
|
|
*pr = g2; |
*pr = g2; |
} |
} |
|
|
void resultp(vl,v,p1,p2,pr) |
void resultp(VL vl,V v,P p1,P p2,P *pr) |
VL vl; |
|
V v; |
|
P p1,p2,*pr; |
|
{ |
{ |
P q1,q2,m,m1,m2,lc,q,r,t,g1,g2,adj; |
P q1,q2,m,m1,m2,lc,q,r,t,g1,g2,adj; |
int d,d1,d2,j,k; |
int d,d1,d2,j,k; |
|
|
} |
} |
} |
} |
|
|
void srch2(vl,v,p1,p2,pr) |
void srch2(VL vl,V v,P p1,P p2,P *pr) |
VL vl; |
|
V v; |
|
P p1,p2,*pr; |
|
{ |
{ |
P q1,q2,m,m1,m2,lc,q,r,t,s,g1,g2,adj; |
P q1,q2,m,m1,m2,lc,q,r,t,s,g1,g2,adj; |
int d,d1,d2,j,k; |
int d,d1,d2,j,k; |
|
|
} |
} |
} |
} |
|
|
void srcr(vl,v,p1,p2,pr) |
void srcr(VL vl,V v,P p1,P p2,P *pr) |
VL vl; |
|
V v; |
|
P p1,p2,*pr; |
|
{ |
{ |
P q1,q2,c,c1; |
P q1,q2,c,c1; |
P tg,tg1,tg2,resg; |
P tg,tg1,tg2,resg; |
|
|
factorial(QTOS(n)+QTOS(m),&t); |
factorial(QTOS(n)+QTOS(m),&t); |
mulq(u,t,&s); addq(s,s,&f); |
mulq(u,t,&s); addq(s,s,&f); |
for ( index = 0, q = ONE, c = 0; cmpq(f,q) >= 0; ) { |
for ( index = 0, q = ONE, c = 0; cmpq(f,q) >= 0; ) { |
mod = lprime[index++]; |
mod = get_lprime(index++); |
if ( !mod ) |
|
error("sqfrum : lprime[] exhausted."); |
|
ptomp(mod,LC(q1),&tg); |
ptomp(mod,LC(q1),&tg); |
if ( !tg ) |
if ( !tg ) |
continue; |
continue; |
|
|
*pr = c; |
*pr = c; |
} |
} |
|
|
void res_ch_det(vl,v,p1,p2,pr) |
void res_ch_det(VL vl,V v,P p1,P p2,P *pr) |
VL vl; |
|
V v; |
|
P p1,p2,*pr; |
|
{ |
{ |
P q1,q2,c,c1; |
P q1,q2,c,c1; |
P tg,tg1,tg2,resg; |
P tg,tg1,tg2,resg; |
|
|
factorial(QTOS(n)+QTOS(m),&t); |
factorial(QTOS(n)+QTOS(m),&t); |
mulq(u,t,&s); addq(s,s,&f); |
mulq(u,t,&s); addq(s,s,&f); |
for ( index = 0, q = ONE, c = 0; cmpq(f,q) >= 0; ) { |
for ( index = 0, q = ONE, c = 0; cmpq(f,q) >= 0; ) { |
mod = lprime[index++]; |
mod = get_lprime(index++); |
if ( !mod ) |
|
error("sqfrum : lprime[] exhausted."); |
|
ptomp(mod,LC(q1),&tg); |
ptomp(mod,LC(q1),&tg); |
if ( !tg ) |
if ( !tg ) |
continue; |
continue; |
|
|
*pr = c; |
*pr = c; |
} |
} |
|
|
void res_detmp(vl,mod,v,p1,p2,dp) |
void res_detmp(VL vl,int mod,V v,P p1,P p2,P *dp) |
VL vl; |
|
int mod; |
|
V v; |
|
P p1,p2; |
|
P *dp; |
|
{ |
{ |
int n1,n2,n,sgn; |
int n1,n2,n,sgn; |
int i,j,k; |
int i,j,k; |
|
|
} |
} |
|
|
#if 0 |
#if 0 |
showmat(vl,mat,n) |
showmat(VL vl,P **mat,int n) |
VL vl; |
|
P **mat; |
|
int n; |
|
{ |
{ |
int i,j; |
int i,j; |
P t; |
P t; |
|
|
for ( i = 0; i < n; i++ ) { |
for ( i = 0; i < n; i++ ) { |
for ( j = 0; j < n; j++ ) { |
for ( j = 0; j < n; j++ ) { |
mptop(mat[i][j],&t); printp(vl,t); fprintf(out," "); |
mptop(mat[i][j],&t); asir_printp(vl,t); fprintf(out," "); |
} |
} |
fprintf(out,"\n"); |
fprintf(out,"\n"); |
} |
} |
fflush(out); |
fflush(out); |
} |
} |
|
|
showmp(vl,p) |
showmp(VL vl,P p) |
VL vl; |
|
P p; |
|
{ |
{ |
P t; |
P t; |
|
|
mptop(p,&t); printp(vl,t); fprintf(out,"\n"); |
mptop(p,&t); asir_printp(vl,t); fprintf(out,"\n"); |
} |
} |
#endif |
#endif |
|
|
void premp(vl,p1,p2,pr) |
void premp(VL vl,P p1,P p2,P *pr) |
VL vl; |
|
P p1,p2,*pr; |
|
{ |
{ |
P m,m1,m2; |
P m,m1,m2; |
P *pw; |
P *pw; |
|
|
*pr = 0; |
*pr = 0; |
else if ( ( v1 = VR(p1) ) == ( v2 = VR(p2) ) ) { |
else if ( ( v1 = VR(p1) ) == ( v2 = VR(p2) ) ) { |
n1 = deg(v1,p1); n2 = deg(v1,p2); |
n1 = deg(v1,p1); n2 = deg(v1,p2); |
|
if ( n1 < n2 ) { |
|
*pr = p1; |
|
return; |
|
} |
pw = (P *)ALLOCA((n1+1)*sizeof(P)); |
pw = (P *)ALLOCA((n1+1)*sizeof(P)); |
bzero((char *)pw,(int)((n1+1)*sizeof(P))); |
bzero((char *)pw,(int)((n1+1)*sizeof(P))); |
|
|
|
|
} |
} |
} |
} |
|
|
void ptozp0(p,pr) |
void ptozp0(P p,P *pr) |
P p; |
|
P *pr; |
|
{ |
{ |
Q c; |
Q c; |
|
|
ptozp(p,1,&c,pr); |
if ( qpcheck((Obj)p) ) |
|
ptozp(p,1,&c,pr); |
|
else |
|
*pr = p; |
} |
} |
|
|
void mindegp(vl,p,mvlp,pr) |
void mindegp(VL vl,P p,VL *mvlp,P *pr) |
VL vl,*mvlp; |
|
P p,*pr; |
|
{ |
{ |
P t; |
P t; |
VL nvl,tvl,avl; |
VL nvl,tvl,avl; |
|
|
} |
} |
} |
} |
|
|
void maxdegp(vl,p,mvlp,pr) |
void maxdegp(VL vl,P p,VL *mvlp,P *pr) |
VL vl,*mvlp; |
|
P p,*pr; |
|
{ |
{ |
P t; |
P t; |
VL nvl,tvl,avl; |
VL nvl,tvl,avl; |
|
|
} |
} |
} |
} |
|
|
void min_common_vars_in_coefp(vl,p,mvlp,pr) |
void min_common_vars_in_coefp(VL vl,P p,VL *mvlp,P *pr) |
VL vl,*mvlp; |
|
P p,*pr; |
|
{ |
{ |
P u,p0; |
P u,p0; |
VL tvl,cvl,svl,uvl,avl,vl0; |
VL tvl,cvl,svl,uvl,avl,vl0; |
|
|
*pr = p0; *mvlp = vl0; |
*pr = p0; *mvlp = vl0; |
} |
} |
|
|
void minlcdegp(vl,p,mvlp,pr) |
void minlcdegp(VL vl,P p,VL *mvlp,P *pr) |
VL vl,*mvlp; |
|
P p,*pr; |
|
{ |
{ |
P u,p0; |
P u,p0; |
VL tvl,uvl,avl,vl0; |
VL tvl,uvl,avl,vl0; |
|
|
*pr = p0; *mvlp = vl0; |
*pr = p0; *mvlp = vl0; |
} |
} |
|
|
void sort_by_deg(n,p,pr) |
void sort_by_deg(int n,P *p,P *pr) |
int n; |
|
P *p,*pr; |
|
{ |
{ |
int j,k,d,k0; |
int j,k,d,k0; |
V v; |
V v; |
|
|
} |
} |
} |
} |
|
|
void sort_by_deg_rev(n,p,pr) |
void sort_by_deg_rev(int n,P *p,P *pr) |
int n; |
|
P *p,*pr; |
|
{ |
{ |
int j,k,d,k0; |
int j,k,d,k0; |
V v; |
V v; |
|
|
} |
} |
|
|
|
|
void getmindeg(v,p,dp) |
void getmindeg(V v,P p,Q *dp) |
V v; |
|
P p; |
|
Q *dp; |
|
{ |
{ |
Q dt,d; |
Q dt,d; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
void minchdegp(vl,p,mvlp,pr) |
void minchdegp(VL vl,P p,VL *mvlp,P *pr) |
VL vl,*mvlp; |
|
P p,*pr; |
|
{ |
{ |
P t; |
P t; |
VL tvl,nvl,avl; |
VL tvl,nvl,avl; |
|
|
} |
} |
} |
} |
|
|
int getchomdeg(v,p) |
int getchomdeg(V v,P p) |
V v; |
|
P p; |
|
{ |
{ |
int m,m1; |
int m,m1; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
int getlchomdeg(v,p,d) |
int getlchomdeg(V v,P p,int *d) |
V v; |
|
P p; |
|
int *d; |
|
{ |
{ |
int m0,m1,d0,d1; |
int m0,m1,d0,d1; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
int nmonop(p) |
int nmonop(P p) |
P p; |
|
{ |
{ |
int s; |
int s; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
int qpcheck(p) |
int qpcheck(Obj p) |
Obj p; |
|
{ |
{ |
DCP dc; |
DCP dc; |
|
|
|
|
|
|
/* check if p is univariate and all coeffs are INT or LM */ |
/* check if p is univariate and all coeffs are INT or LM */ |
|
|
int uzpcheck(p) |
int uzpcheck(Obj p) |
Obj p; |
|
{ |
{ |
DCP dc; |
DCP dc; |
P c; |
P c; |
|
|
case O_P: |
case O_P: |
for ( dc = DC((P)p); dc; dc = NEXT(dc) ) { |
for ( dc = DC((P)p); dc; dc = NEXT(dc) ) { |
c = COEF(dc); |
c = COEF(dc); |
if ( !NUM(c) || !uzpcheck(c) ) |
if ( !NUM(c) || !uzpcheck((Obj)c) ) |
return 0; |
return 0; |
} |
} |
return 1; |
return 1; |
|
|
} |
} |
} |
} |
|
|
int p_mag(p) |
int p_mag(P p) |
P p; |
|
{ |
{ |
int s; |
int s; |
DCP dc; |
DCP dc; |
|
|
} |
} |
} |
} |
|
|
int maxblenp(p) |
int maxblenp(P p) |
P p; |
|
{ |
{ |
int s,t; |
int s,t; |
DCP dc; |
DCP dc; |
|
|
return n_bits(NM((Q)p))+(INT((Q)p)?0:n_bits(DN((Q)p))); |
return n_bits(NM((Q)p))+(INT((Q)p)?0:n_bits(DN((Q)p))); |
else { |
else { |
for ( dc = DC(p), s = 0; dc; dc = NEXT(dc) ) { |
for ( dc = DC(p), s = 0; dc; dc = NEXT(dc) ) { |
t = p_mag(COEF(dc)); |
t = maxblenp(COEF(dc)); |
s = MAX(t,s); |
s = MAX(t,s); |
} |
} |
return s; |
return s; |