version 1.7, 2001/10/01 01:58:03 |
version 1.12, 2004/09/14 09:25:48 |
|
|
* 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.6 2001/06/07 04:54:40 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/PU.c,v 1.11 2004/09/14 07:23:34 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 detp(VL vl,P **rmat,int n,P *dp) |
VL vl; |
|
P **rmat; |
|
int n; |
|
P *dp; |
|
{ |
{ |
int i,j,k,sgn; |
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 invmatp(vl,rmat,n,imatp,dnp) |
void invmatp(VL vl,P **rmat,int n,P ***imatp,P *dnp) |
VL vl; |
|
P **rmat; |
|
int n; |
|
P ***imatp; |
|
P *dnp; |
|
{ |
{ |
int i,j,k,l,n2; |
int i,j,k,l,n2; |
P mjj,mij,t,s,u,d; |
P mjj,mij,t,s,u,d; |
|
|
*dnp = d; |
*dnp = d; |
} |
} |
|
|
void reordvar(vl,v,nvlp) |
void reordvar(VL vl,V v,VL *nvlp) |
VL vl; |
|
V v; |
|
VL *nvlp; |
|
{ |
{ |
VL nvl,nvl0; |
VL 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; |
|
|
*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; |
|
|
*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; |
|
|
} |
} |
} |
} |
|
|
void ptozp0(p,pr) |
void ptozp0(P p,P *pr) |
P p; |
|
P *pr; |
|
{ |
{ |
Q c; |
Q c; |
|
|
|
|
*pr = p; |
*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; |