version 1.103, 2004/09/15 06:06:42 |
version 1.105, 2004/09/17 05:43:22 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.102 2004/09/15 01:43:33 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.104 2004/09/17 01:27:48 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
Line 3202 ND ndv_mul_nm(int mod,NM m0,NDV p) |
|
Line 3202 ND ndv_mul_nm(int mod,NM m0,NDV p) |
|
} |
} |
} |
} |
|
|
ND nd_quo(int mod,ND p,NDV d) |
ND nd_quo(int mod,PGeoBucket bucket,NDV d) |
{ |
{ |
NM mq0,mq; |
NM mq0,mq; |
NMV tm; |
NMV tm; |
Q q; |
Q q; |
int i,nv,sg,c,c1,c2; |
int i,nv,sg,c,c1,c2,hindex; |
ND t,r; |
ND p,t,r; |
|
N tnm; |
|
|
if ( !p ) return 0; |
if ( !p ) return 0; |
else { |
else { |
nv = NV(p); |
nv = NV(d); |
sg = SG(p); |
|
mq0 = 0; |
mq0 = 0; |
tm = (NMV)ALLOCA(nmv_adv); |
tm = (NMV)ALLOCA(nmv_adv); |
while ( p ) { |
while ( 1 ) { |
|
hindex = mod?head_pbucket(mod,bucket):head_pbucket_q(bucket); |
|
if ( hindex < 0 ) break; |
|
p = bucket->body[hindex]; |
NEXTNM(mq0,mq); |
NEXTNM(mq0,mq); |
ndl_sub(HDL(p),HDL(d),DL(mq)); |
ndl_sub(HDL(p),HDL(d),DL(mq)); |
ndl_copy(DL(mq),DL(tm)); |
ndl_copy(DL(mq),DL(tm)); |
Line 3225 ND nd_quo(int mod,ND p,NDV d) |
|
Line 3228 ND nd_quo(int mod,ND p,NDV d) |
|
DMAR(c1,c2,0,mod,c); CM(mq) = c; |
DMAR(c1,c2,0,mod,c); CM(mq) = c; |
CM(tm) = mod-c; |
CM(tm) = mod-c; |
} else { |
} else { |
divq(HCQ(p),HCQ(d),&CQ(mq)); |
divsn(NM(HCQ(p)),NM(HCQ(d)),&tnm); |
|
NTOQ(tnm,SGN(HCQ(p))*SGN(HCQ(d)),CQ(mq)); |
chsgnq(CQ(mq),&CQ(tm)); |
chsgnq(CQ(mq),&CQ(tm)); |
} |
} |
t = ndv_mul_nmv_trunc(mod,tm,d,HDL(d)); |
t = ndv_mul_nmv_trunc(mod,tm,d,HDL(d)); |
p = nd_add(mod,p,t); |
bucket->body[hindex] = nd_remove_head(p); |
|
t = nd_remove_head(t); |
|
add_pbucket(mod,bucket,t); |
} |
} |
NEXT(mq) = 0; |
if ( !mq0 ) |
for ( i = 0, mq = mq0; mq; mq = NEXT(mq), i++ ); |
r = 0; |
MKND(nv,mq0,i,r); |
else { |
/* XXX */ |
NEXT(mq) = 0; |
SG(r) = sg-SG(d); |
for ( i = 0, mq = mq0; mq; mq = NEXT(mq), i++ ); |
|
MKND(nv,mq0,i,r); |
|
/* XXX */ |
|
SG(r) = HTD(r); |
|
} |
return r; |
return r; |
} |
} |
} |
} |
Line 4711 void nd_det(int mod,MAT f,P *rp) |
|
Line 4721 void nd_det(int mod,MAT f,P *rp) |
|
if ( mod ) ndv_mod(mod,d); |
if ( mod ) ndv_mod(mod,d); |
chsgnq(ONE,&mone); |
chsgnq(ONE,&mone); |
for ( j = 0, sgn = 1; j < n; j++ ) { |
for ( j = 0, sgn = 1; j < n; j++ ) { |
|
if ( DP_Print ) fprintf(stderr,"j=%d\n",j); |
for ( i = j; i < n && !dm[i][j]; i++ ); |
for ( i = j; i < n && !dm[i][j]; i++ ); |
if ( i == n ) { |
if ( i == n ) { |
*rp = 0; |
*rp = 0; |
Line 4733 void nd_det(int mod,MAT f,P *rp) |
|
Line 4744 void nd_det(int mod,MAT f,P *rp) |
|
sgn = -sgn; |
sgn = -sgn; |
} |
} |
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
|
if ( DP_Print ) fprintf(stderr," i=%d\n ",i); |
mi = dm[i]; mij = mi[j]; |
mi = dm[i]; mij = mi[j]; |
if ( mod ) |
if ( mod ) |
ndv_mul_c(mod,mij,mod-1); |
ndv_mul_c(mod,mij,mod-1); |
else |
else |
ndv_mul_c_q(mij,mone); |
ndv_mul_c_q(mij,mone); |
for ( k = j+1; k < n; k++ ) { |
for ( k = j+1; k < n; k++ ) { |
|
if ( DP_Print ) fprintf(stderr,"k=%d ",k); |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
if ( mi[k] ) |
if ( mi[k] ) { |
nmv = BDY(mjj); len = LEN(mjj); |
nmv = BDY(mjj); len = LEN(mjj); |
for ( a = 0; a < len; a++, NMV_ADV(nmv) ) { |
for ( a = 0; a < len; a++, NMV_ADV(nmv) ) { |
u = ndv_mul_nmv_trunc(mod,nmv,mi[k],DL(BDY(d))); |
u = ndv_mul_nmv_trunc(mod,nmv,mi[k],DL(BDY(d))); |
add_pbucket(mod,bucket,u); |
add_pbucket(mod,bucket,u); |
} |
} |
|
} |
if ( mj[k] && mij ) { |
if ( mj[k] && mij ) { |
nmv = BDY(mij); len = LEN(mij); |
nmv = BDY(mij); len = LEN(mij); |
for ( a = 0; a < len; a++, NMV_ADV(nmv) ) { |
for ( a = 0; a < len; a++, NMV_ADV(nmv) ) { |
Line 4753 void nd_det(int mod,MAT f,P *rp) |
|
Line 4767 void nd_det(int mod,MAT f,P *rp) |
|
add_pbucket(mod,bucket,u); |
add_pbucket(mod,bucket,u); |
} |
} |
} |
} |
u = normalize_pbucket(mod,bucket); |
u = nd_quo(mod,bucket,d); |
u = nd_quo(mod,u,d); |
|
mi[k] = ndtondv(mod,u); |
mi[k] = ndtondv(mod,u); |
} |
} |
|
if ( DP_Print ) fprintf(stderr,"\n",k); |
} |
} |
d = mjj; |
d = mjj; |
} |
} |
Line 4792 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
Line 4806 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
if ( ndl_reducible(DL(tnm),d) ) { |
if ( ndl_reducible(DL(tnm),d) ) { |
NEXTNM(mr0,mr); |
NEXTNM(mr0,mr); |
c1 = CM(m); DMAR(c1,c,0,mod,c2); CM(mr) = c2; |
c1 = CM(m); DMAR(c1,c,0,mod,c2); CM(mr) = c2; |
ndl_add(DL(m),d0,DL(mr)); |
ndl_copy(DL(tnm),DL(mr)); |
} |
} |
} |
} |
} else { |
} else { |
Line 4802 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
Line 4816 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
if ( ndl_reducible(DL(tnm),d) ) { |
if ( ndl_reducible(DL(tnm),d) ) { |
NEXTNM(mr0,mr); |
NEXTNM(mr0,mr); |
mulq(CQ(m),q,&CQ(mr)); |
mulq(CQ(m),q,&CQ(mr)); |
ndl_add(DL(m),d0,DL(mr)); |
ndl_copy(DL(tnm),DL(mr)); |
} |
} |
} |
} |
} |
} |
Line 4810 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
Line 4824 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
return 0; |
return 0; |
else { |
else { |
NEXT(mr) = 0; |
NEXT(mr) = 0; |
|
for ( len = 0, mr = mr0; mr; mr = NEXT(mr), len++ ); |
MKND(NV(p),mr0,len,r); |
MKND(NV(p),mr0,len,r); |
SG(r) = SG(p) + TD(d0); |
SG(r) = SG(p) + TD(d0); |
return r; |
return r; |