| version 1.12, 2018/11/12 04:25:13 |
version 1.15, 2019/04/20 06:04:18 |
|
|
| /* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.11 2018/10/23 04:53:37 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.14 2019/03/03 05:21:17 noro Exp $ */ |
| |
|
| #include "nd.h" |
#include "nd.h" |
| |
|
| Line 78 NDV pltondv(VL vl,VL dvl,LIST p); |
|
| Line 78 NDV pltondv(VL vl,VL dvl,LIST p); |
|
| void pltozpl(LIST l,Q *cont,LIST *pp); |
void pltozpl(LIST l,Q *cont,LIST *pp); |
| void ndl_max(UINT *d1,unsigned *d2,UINT *d); |
void ndl_max(UINT *d1,unsigned *d2,UINT *d); |
| void nmtodp(int mod,NM m,DP *r); |
void nmtodp(int mod,NM m,DP *r); |
| |
void ndltodp(UINT *d,DP *r); |
| NODE reverse_node(NODE n); |
NODE reverse_node(NODE n); |
| P ndc_div(int mod,union oNDC a,union oNDC b); |
P ndc_div(int mod,union oNDC a,union oNDC b); |
| P ndctop(int mod,union oNDC c); |
P ndctop(int mod,union oNDC c); |
| Line 3224 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
| Line 3225 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
| int *perm; |
int *perm; |
| EPOS oepos; |
EPOS oepos; |
| int obpe,oadv,ompos,cbpe; |
int obpe,oadv,ompos,cbpe; |
| |
VECT hvect; |
| |
|
| nd_module = 0; |
nd_module = 0; |
| if ( !m && Demand ) nd_demand = 1; |
if ( !m && Demand ) nd_demand = 1; |
| Line 3334 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
| Line 3336 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
| if ( !x ) { |
if ( !x ) { |
| *rp = 0; return; |
*rp = 0; return; |
| } |
} |
| |
if ( nd_gentrace ) { |
| |
MKVECT(hvect,nd_psn); |
| |
for ( i = 0; i < nd_psn; i++ ) |
| |
ndltodp(nd_psh[i]->dl,(DP *)&BDY(hvect)[i]); |
| |
} |
| if ( !ishomo && homo ) { |
if ( !ishomo && homo ) { |
| /* dehomogenization */ |
/* dehomogenization */ |
| for ( t = x; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); |
for ( t = x; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); |
|
|
| if ( f4 ) { |
if ( f4 ) { |
| STOZ(16,bpe); |
STOZ(16,bpe); |
| STOZ(nd_last_nonzero,last_nonzero); |
STOZ(nd_last_nonzero,last_nonzero); |
| tr = mknode(5,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe,last_nonzero); MKLIST(*rp,tr); |
tr = mknode(6,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe,last_nonzero,hvect); MKLIST(*rp,tr); |
| |
|
| } else { |
} else { |
| tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); |
tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); |
| tl3 = reverse_node(tl3); |
tl3 = reverse_node(tl3); |
|
|
| MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3); |
MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3); |
| MKLIST(l5,tl4); |
MKLIST(l5,tl4); |
| STOZ(nd_bpe,bpe); |
STOZ(nd_bpe,bpe); |
| tr = mknode(8,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe); MKLIST(*rp,tr); |
tr = mknode(9,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe,hvect); MKLIST(*rp,tr); |
| } |
} |
| } |
} |
| #if 0 |
#if 0 |
| Line 3668 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
| Line 3674 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
| int *perm; |
int *perm; |
| int j,ret; |
int j,ret; |
| Z jq,bpe; |
Z jq,bpe; |
| |
VECT hvect; |
| |
|
| nd_module = 0; |
nd_module = 0; |
| nd_lf = 0; |
nd_lf = 0; |
| Line 3785 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
| Line 3792 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
| else m = get_lprime(++mindex); |
else m = get_lprime(++mindex); |
| continue; |
continue; |
| } |
} |
| |
if ( nd_gentrace ) { |
| |
MKVECT(hvect,nd_psn); |
| |
for ( i = 0; i < nd_psn; i++ ) |
| |
ndltodp(nd_psh[i]->dl,(DP *)&BDY(hvect)[i]); |
| |
} |
| if ( !ishomo && homo ) { |
if ( !ishomo && homo ) { |
| /* dehomogenization */ |
/* dehomogenization */ |
| for ( t = cand; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); |
for ( t = cand; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); |
| Line 3862 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
| Line 3874 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
| MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3); |
MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3); |
| MKLIST(l5,tl4); |
MKLIST(l5,tl4); |
| STOZ(nd_bpe,bpe); |
STOZ(nd_bpe,bpe); |
| tr = mknode(8,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe); MKLIST(*rp,tr); |
tr = mknode(9,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe,hvect); MKLIST(*rp,tr); |
| } |
} |
| } |
} |
| |
|
| Line 3926 void nmtodp(int mod,NM m,DP *r) |
|
| Line 3938 void nmtodp(int mod,NM m,DP *r) |
|
| *r = dp; |
*r = dp; |
| } |
} |
| |
|
| |
void ndltodp(UINT *d,DP *r) |
| |
{ |
| |
DP dp; |
| |
MP mr; |
| |
|
| |
NEWMP(mr); |
| |
mr->dl = ndltodl(nd_nvar,d); |
| |
mr->c = (Obj)ONE; |
| |
NEXT(mr) = 0; MKDP(nd_nvar,mr,dp); dp->sugar = mr->dl->td; |
| |
*r = dp; |
| |
} |
| |
|
| void ndl_print(UINT *dl) |
void ndl_print(UINT *dl) |
| { |
{ |
| int n; |
int n; |
| Line 4090 void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos |
|
| Line 4114 void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos |
|
| NMV m,mr0,mr,t; |
NMV m,mr0,mr,t; |
| |
|
| len = p->len; |
len = p->len; |
| for ( m = BDY(p), i = 0, max = 1; i < len; NMV_OADV(m), i++ ) |
for ( m = BDY(p), i = 0, max = 0; i < len; NMV_OADV(m), i++ ) |
| max = MAX(max,TD(DL(m))); |
max = MAX(max,TD(DL(m))); |
| mr0 = nmv_adv>oadv?(NMV)REALLOC(BDY(p),len*nmv_adv):BDY(p); |
mr0 = nmv_adv>oadv?(NMV)REALLOC(BDY(p),len*nmv_adv):BDY(p); |
| m = (NMV)((char *)mr0+(len-1)*oadv); |
m = (NMV)((char *)mr0+(len-1)*oadv); |
| Line 4235 void mpz_removecont_array(mpz_t *c,int n) |
|
| Line 4259 void mpz_removecont_array(mpz_t *c,int n) |
|
| { |
{ |
| mpz_t d0,a,u,u1,gcd; |
mpz_t d0,a,u,u1,gcd; |
| int i,j; |
int i,j; |
| mpz_t *q,*r; |
static mpz_t *q,*r; |
| |
static int c_len = 0; |
| |
|
| for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
| if ( mpz_sgn(c[i]) ) break; |
if ( mpz_sgn(c[i]) ) break; |
| if ( i == n ) return; |
if ( i == n ) return; |
| gcdv_mpz_estimate(d0,c,n); |
gcdv_mpz_estimate(d0,c,n); |
| q = (mpz_t *)MALLOC(n*sizeof(mpz_t)); |
if ( n > c_len ) { |
| r = (mpz_t *)MALLOC(n*sizeof(mpz_t)); |
q = (mpz_t *)MALLOC(n*sizeof(mpz_t)); |
| |
r = (mpz_t *)MALLOC(n*sizeof(mpz_t)); |
| |
c_len = n; |
| |
} |
| for ( i = 0; i < n; i++ ) { |
for ( i = 0; i < n; i++ ) { |
| mpz_init(q[i]); mpz_init(r[i]); |
mpz_init(q[i]); mpz_init(r[i]); |
| mpz_fdiv_qr(q[i],r[i],c[i],d0); |
mpz_fdiv_qr(q[i],r[i],c[i],d0); |
| Line 6056 int ndv_reduce_vect_q(Z *svect,int trace,int col,IndAr |
|
| Line 6084 int ndv_reduce_vect_q(Z *svect,int trace,int col,IndAr |
|
| int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
| { |
{ |
| int i,j,k,len,pos,prev; |
int i,j,k,len,pos,prev; |
| mpz_t *svect; |
|
| mpz_t cs,cr,gcd; |
mpz_t cs,cr,gcd; |
| IndArray ivect; |
IndArray ivect; |
| unsigned char *ivc; |
unsigned char *ivc; |
| Line 6068 int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA |
|
| Line 6095 int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA |
|
| int maxrs; |
int maxrs; |
| double hmag; |
double hmag; |
| int l; |
int l; |
| |
static mpz_t *svect; |
| |
static int svect_len=0; |
| |
|
| maxrs = 0; |
maxrs = 0; |
| for ( i = 0; i < col && !svect0[i]; i++ ); |
for ( i = 0; i < col && !svect0[i]; i++ ); |
| if ( i == col ) return maxrs; |
if ( i == col ) return maxrs; |
| hmag = p_mag((P)svect0[i])*nd_scale; |
hmag = p_mag((P)svect0[i])*nd_scale; |
| svect = (mpz_t *)MALLOC(col*sizeof(mpz_t)); |
if ( col > svect_len ) { |
| |
svect = (mpz_t *)MALLOC(col*sizeof(mpz_t)); |
| |
svect_len = col; |
| |
} |
| for ( i = 0; i < col; i++ ) { |
for ( i = 0; i < col; i++ ) { |
| mpz_init(svect[i]); |
mpz_init(svect[i]); |
| if ( svect0[i] ) |
if ( svect0[i] ) |