version 1.69, 2003/09/15 09:49:44 |
version 1.73, 2003/09/17 08:37:49 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.68 2003/09/12 15:07:11 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.72 2003/09/17 08:14:26 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 143 static int nmv_adv; |
|
Line 143 static int nmv_adv; |
|
static int nd_dcomp; |
static int nd_dcomp; |
|
|
extern VL CO; |
extern VL CO; |
extern int Top,Reverse,dp_nelim,do_weyl; |
extern int Top,Reverse,DP_Print,dp_nelim,do_weyl; |
extern int *current_weyl_weight_vector; |
extern int *current_weyl_weight_vector; |
|
|
/* fundamental macros */ |
/* fundamental macros */ |
Line 224 if(!(r)){NEWND_pairs(r);(c)=(r);}else{NEWND_pairs(NEXT |
|
Line 224 if(!(r)){NEWND_pairs(r);(c)=(r);}else{NEWND_pairs(NEXT |
|
#define NMV_OPREV(m) (m = (NMV)(((char *)m)-oadv)) |
#define NMV_OPREV(m) (m = (NMV)(((char *)m)-oadv)) |
|
|
/* external functions */ |
/* external functions */ |
|
#if 1 |
void GC_gcollect(); |
void GC_gcollect(); |
|
#endif |
NODE append_one(NODE,int); |
NODE append_one(NODE,int); |
|
|
/* manipulation of coefficients */ |
/* manipulation of coefficients */ |
Line 331 ND nd_copy(ND p); |
|
Line 333 ND nd_copy(ND p); |
|
ND nd_merge(ND p1,ND p2); |
ND nd_merge(ND p1,ND p2); |
ND nd_add(int mod,ND p1,ND p2); |
ND nd_add(int mod,ND p1,ND p2); |
ND nd_add_q(ND p1,ND p2); |
ND nd_add_q(ND p1,ND p2); |
|
ND nd_add_sf(ND p1,ND p2); |
INLINE int nd_length(ND p); |
INLINE int nd_length(ND p); |
|
|
/* NDV functions */ |
/* NDV functions */ |
Line 361 int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r); |
|
Line 364 int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r); |
|
|
|
void nd_free_private_storage() |
void nd_free_private_storage() |
{ |
{ |
_nd_free_list = 0; |
|
_nm_free_list = 0; |
_nm_free_list = 0; |
_ndp_free_list = 0; |
_ndp_free_list = 0; |
bzero(nd_red,sizeof(REDTAB_LEN*sizeof(RHist))); |
#if 0 |
GC_gcollect(); |
GC_gcollect(); |
|
#endif |
} |
} |
|
|
void _NM_alloc() |
void _NM_alloc() |
Line 1141 ND nd_add(int mod,ND p1,ND p2) |
|
Line 1144 ND nd_add(int mod,ND p1,ND p2) |
|
|
|
if ( !p1 ) return p2; |
if ( !p1 ) return p2; |
else if ( !p2 ) return p1; |
else if ( !p2 ) return p1; |
|
else if ( mod == -1 ) return nd_add_sf(p1,p2); |
else if ( !mod ) return nd_add_q(p1,p2); |
else if ( !mod ) return nd_add_q(p1,p2); |
else { |
else { |
can = 0; |
can = 0; |
Line 1228 ND nd_add_q(ND p1,ND p2) |
|
Line 1232 ND nd_add_q(ND p1,ND p2) |
|
} |
} |
} |
} |
|
|
|
ND nd_add_sf(ND p1,ND p2) |
|
{ |
|
int n,c,can; |
|
ND r; |
|
NM m1,m2,mr0,mr,s; |
|
int t; |
|
|
|
if ( !p1 ) return p2; |
|
else if ( !p2 ) return p1; |
|
else { |
|
can = 0; |
|
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) { |
|
c = DL_COMPARE(DL(m1),DL(m2)); |
|
switch ( c ) { |
|
case 0: |
|
t = _addsf(CM(m1),CM(m2)); |
|
s = m1; m1 = NEXT(m1); |
|
if ( t ) { |
|
can++; NEXTNM2(mr0,mr,s); CM(mr) = (t); |
|
} else { |
|
can += 2; FREENM(s); |
|
} |
|
s = m2; m2 = NEXT(m2); FREENM(s); |
|
break; |
|
case 1: |
|
s = m1; m1 = NEXT(m1); NEXTNM2(mr0,mr,s); |
|
break; |
|
case -1: |
|
s = m2; m2 = NEXT(m2); NEXTNM2(mr0,mr,s); |
|
break; |
|
} |
|
} |
|
if ( !mr0 ) |
|
if ( m1 ) mr0 = m1; |
|
else if ( m2 ) mr0 = m2; |
|
else return 0; |
|
else if ( m1 ) NEXT(mr) = m1; |
|
else if ( m2 ) NEXT(mr) = m2; |
|
else NEXT(mr) = 0; |
|
BDY(p1) = mr0; |
|
SG(p1) = MAX(SG(p1),SG(p2)); |
|
LEN(p1) = LEN(p1)+LEN(p2)-can; |
|
FREEND(p2); |
|
return p1; |
|
} |
|
} |
|
|
/* ret=1 : success, ret=0 : overflow */ |
/* ret=1 : success, ret=0 : overflow */ |
int nd_nf(int mod,ND g,NDV *ps,int full,NDC dn,ND *rp) |
int nd_nf(int mod,ND g,NDV *ps,int full,NDC dn,ND *rp) |
{ |
{ |
Line 1266 int nd_nf(int mod,ND g,NDV *ps,int full,NDC dn,ND *rp) |
|
Line 1317 int nd_nf(int mod,ND g,NDV *ps,int full,NDC dn,ND *rp) |
|
return 0; |
return 0; |
} |
} |
p = ps[index]; |
p = ps[index]; |
if ( mod ) { |
if ( mod == -1 ) |
|
CM(mul) = _mulsf(_invsf(HCM(p)),_chsgnsf(HCM(g))); |
|
else if ( mod ) { |
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
} else { |
} else { |
Line 1353 int nd_nf_pbucket(int mod,ND g,NDV *ps,int full,ND *rp |
|
Line 1406 int nd_nf_pbucket(int mod,ND g,NDV *ps,int full,ND *rp |
|
return 0; |
return 0; |
} |
} |
p = ps[index]; |
p = ps[index]; |
if ( mod ) { |
if ( mod == -1 ) |
|
CM(mul) = _mulsf(_invsf(HCM(p)),_chsgnsf(HCM(g))); |
|
else if ( mod ) { |
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
} else { |
} else { |
|
|
nd_reconstruct(0,0,0); |
nd_reconstruct(0,0,0); |
goto again; |
goto again; |
} else if ( nf ) return 0; |
} else if ( nf ) return 0; |
printf("."); fflush(stdout); |
if ( DP_Print ) { printf("."); fflush(stdout); } |
} |
} |
printf("\n"); |
if ( DP_Print ) { printf("\n"); } |
/* gbcheck : cand is a GB of Id(cand) ? */ |
/* gbcheck : cand is a GB of Id(cand) ? */ |
if ( !nd_gb(0,1) ) return 0; |
if ( !nd_gb(0,1) ) return 0; |
/* XXX */ |
/* XXX */ |
Line 1594 int head_pbucket(int mod,PGeoBucket g) |
|
Line 1649 int head_pbucket(int mod,PGeoBucket g) |
|
dj = HDL(gj); |
dj = HDL(gj); |
sum = HCM(gj); |
sum = HCM(gj); |
} else if ( c == 0 ) { |
} else if ( c == 0 ) { |
sum = sum+HCM(gi)-mod; |
if ( mod == -1 ) |
if ( sum < 0 ) sum += mod; |
sum = _addsf(sum,HCM(gi)); |
|
else { |
|
sum = sum+HCM(gi)-mod; |
|
if ( sum < 0 ) sum += mod; |
|
} |
g->body[i] = nd_remove_head(gi); |
g->body[i] = nd_remove_head(gi); |
} |
} |
} |
} |
|
|
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
if ( SG(l) != sugar ) { |
if ( SG(l) != sugar ) { |
sugar = SG(l); |
sugar = SG(l); |
fprintf(asir_out,"%d",sugar); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
} |
} |
stat = nd_sp(m,0,l,&h); |
stat = nd_sp(m,0,l,&h); |
if ( !stat ) { |
if ( !stat ) { |
|
|
goto again; |
goto again; |
} else if ( nf ) { |
} else if ( nf ) { |
if ( checkonly ) return 0; |
if ( checkonly ) return 0; |
printf("+"); fflush(stdout); |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
nd_removecont(m,nf); |
nd_removecont(m,nf); |
nfv = ndtondv(m,nf); nd_free(nf); |
nfv = ndtondv(m,nf); nd_free(nf); |
nh = ndv_newps(nfv,0); |
nh = ndv_newps(nfv,0); |
|
|
g = update_base(g,nh); |
g = update_base(g,nh); |
FREENDP(l); |
FREENDP(l); |
} else { |
} else { |
printf("."); fflush(stdout); |
if ( DP_Print ) { printf("."); fflush(stdout); } |
FREENDP(l); |
FREENDP(l); |
} |
} |
} |
} |
|
|
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
if ( SG(l) != sugar ) { |
if ( SG(l) != sugar ) { |
sugar = SG(l); |
sugar = SG(l); |
fprintf(asir_out,"%d",sugar); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
} |
} |
stat = nd_sp(m,0,l,&h); |
stat = nd_sp(m,0,l,&h); |
if ( !stat ) { |
if ( !stat ) { |
|
|
d = nd_reconstruct(m,1,d); |
d = nd_reconstruct(m,1,d); |
goto again; |
goto again; |
} else if ( nf ) { |
} else if ( nf ) { |
/* overflow does not occur */ |
if ( !nd_sp(0,1,l,&h) || !nd_nf(0,h,nd_ps_trace,!Top,0,&nfq) ) { |
nd_sp(0,1,l,&h); |
NEXT(l) = d; d = l; |
nd_nf(0,h,nd_ps_trace,!Top,0,&nfq); |
d = nd_reconstruct(m,1,d); |
|
goto again; |
|
} |
if ( nfq ) { |
if ( nfq ) { |
/* failure; m|HC(nfq) */ |
/* m|HC(nfq) => failure */ |
if ( !rem(NM(HCQ(nfq)),m) ) return 0; |
if ( !rem(NM(HCQ(nfq)),m) ) return 0; |
|
|
printf("+"); fflush(stdout); |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf); |
nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf); |
nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq); |
nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq); |
nh = ndv_newps(nfv,nfqv); |
nh = ndv_newps(nfv,nfqv); |
d = update_pairs(d,g,nh); |
d = update_pairs(d,g,nh); |
g = update_base(g,nh); |
g = update_base(g,nh); |
} else { |
} else { |
printf("*"); fflush(stdout); |
if ( DP_Print ) { printf("*"); fflush(stdout); } |
} |
} |
} else { |
} else { |
printf("."); fflush(stdout); |
if ( DP_Print ) { printf("."); fflush(stdout); } |
} |
} |
FREENDP(l); |
FREENDP(l); |
} |
} |
Line 1821 NODE ndv_reduceall(int m,NODE f) |
|
Line 1882 NODE ndv_reduceall(int m,NODE f) |
|
if ( !stat ) |
if ( !stat ) |
nd_reconstruct(m,0,0); |
nd_reconstruct(m,0,0); |
else { |
else { |
printf("."); fflush(stdout); |
if ( DP_Print ) { printf("."); fflush(stdout); } |
if ( !m ) { mulq(HCQ(head),dn.z,&q); HCQ(head) = q; } |
if ( !m ) { mulq(HCQ(head),dn.z,&q); HCQ(head) = q; } |
nf = nd_add(m,head,nf); |
nf = nd_add(m,head,nf); |
ndv_free(nd_ps[i]); |
ndv_free(nd_ps[i]); |
Line 1831 NODE ndv_reduceall(int m,NODE f) |
|
Line 1892 NODE ndv_reduceall(int m,NODE f) |
|
i++; |
i++; |
} |
} |
} |
} |
printf("\n"); |
if ( DP_Print ) { printf("\n"); } |
for ( a0 = 0, i = 0; i < n; i++ ) { |
for ( a0 = 0, i = 0; i < n; i++ ) { |
NEXTNODE(a0,a); |
NEXTNODE(a0,a); |
BDY(a) = (pointer)nd_ps[i]; |
BDY(a) = (pointer)nd_ps[i]; |
Line 2154 void ndv_setup(int mod,int trace,NODE f) |
|
Line 2215 void ndv_setup(int mod,int trace,NODE f) |
|
|
|
if ( !nd_red ) |
if ( !nd_red ) |
nd_red = (RHist *)MALLOC(REDTAB_LEN*sizeof(RHist)); |
nd_red = (RHist *)MALLOC(REDTAB_LEN*sizeof(RHist)); |
bzero(nd_red,REDTAB_LEN*sizeof(RHist)); |
for ( i = 0; i < REDTAB_LEN; i++ ) nd_red[i] = 0; |
nd_free_private_storage(); |
|
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
if ( trace ) { |
if ( trace ) { |
a = nd_ps_trace[i] = ndv_dup(0,w[i]); |
a = nd_ps_trace[i] = ndv_dup(0,w[i]); |
Line 2300 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2360 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
} |
} |
/* dp->p */ |
/* dp->p */ |
nd_bpe = cbpe; |
nd_bpe = cbpe; |
nd_setup_parameters(0,0); |
nd_setup_parameters(nd_nvar,0); |
for ( r = cand; r; r = NEXT(r) ) BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r)); |
for ( r = cand; r; r = NEXT(r) ) BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r)); |
MKLIST(*rp,cand); |
MKLIST(*rp,cand); |
} |
} |
Line 2381 void nd_print(ND p) |
|
Line 2441 void nd_print(ND p) |
|
printf("0\n"); |
printf("0\n"); |
else { |
else { |
for ( m = BDY(p); m; m = NEXT(m) ) { |
for ( m = BDY(p); m; m = NEXT(m) ) { |
printf("+%d*",CM(m)); |
if ( CM(m) & 0x80000000 ) printf("+@_%d*",IFTOF(CM(m))); |
|
else printf("+%d*",CM(m)); |
ndl_print(DL(m)); |
ndl_print(DL(m)); |
} |
} |
printf("\n"); |
printf("\n"); |
Line 2422 void nd_removecont(int mod,ND p) |
|
Line 2483 void nd_removecont(int mod,ND p) |
|
struct oVECT v; |
struct oVECT v; |
N q,r; |
N q,r; |
|
|
if ( mod ) nd_mul_c(mod,p,invm(HCM(p),mod)); |
if ( mod == -1 ) nd_mul_c(mod,p,_invsf(HCM(p))); |
|
else if ( mod ) nd_mul_c(mod,p,invm(HCM(p),mod)); |
else { |
else { |
for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ ); |
for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ ); |
w = (Q *)ALLOCA(n*sizeof(Q)); |
w = (Q *)ALLOCA(n*sizeof(Q)); |
Line 2468 void ndv_removecont(int mod,NDV p) |
|
Line 2530 void ndv_removecont(int mod,NDV p) |
|
Q dvr,t; |
Q dvr,t; |
NMV m; |
NMV m; |
|
|
if ( mod ) |
if ( mod == -1 ) |
|
ndv_mul_c(mod,p,_invsf(HCM(p))); |
|
else if ( mod ) |
ndv_mul_c(mod,p,invm(HCM(p),mod)); |
ndv_mul_c(mod,p,invm(HCM(p),mod)); |
else { |
else { |
len = p->len; |
len = p->len; |
Line 2569 void nd_mul_c(int mod,ND p,int mul) |
|
Line 2633 void nd_mul_c(int mod,ND p,int mul) |
|
int c,c1; |
int c,c1; |
|
|
if ( !p ) return; |
if ( !p ) return; |
for ( m = BDY(p); m; m = NEXT(m) ) { |
if ( mod == -1 ) |
c1 = CM(m); |
for ( m = BDY(p); m; m = NEXT(m) ) |
DMAR(c1,mul,0,mod,c); |
CM(m) = _mulsf(CM(m),mul); |
CM(m) = c; |
else |
} |
for ( m = BDY(p); m; m = NEXT(m) ) { |
|
c1 = CM(m); DMAR(c1,mul,0,mod,c); CM(m) = c; |
|
} |
} |
} |
|
|
void nd_mul_c_q(ND p,Q mul) |
void nd_mul_c_q(ND p,Q mul) |
Line 2676 int nd_get_exporigin(struct order_spec *ord) |
|
Line 2742 int nd_get_exporigin(struct order_spec *ord) |
|
void nd_setup_parameters(int nvar,int max) { |
void nd_setup_parameters(int nvar,int max) { |
int i,j,n,elen,ord_o,ord_l,l,s; |
int i,j,n,elen,ord_o,ord_l,l,s; |
struct order_pair *op; |
struct order_pair *op; |
|
int bpe; |
|
|
/* if max == 0, don't touch nd_bpe */ |
if ( !max ) bpe = nd_bpe; |
if ( max > 0 ) { |
else if ( max < 2 ) bpe = 1; |
if ( max < 2 ) nd_bpe = 1; |
else if ( max < 4 ) bpe = 2; |
if ( max < 4 ) nd_bpe = 2; |
else if ( max < 8 ) bpe = 3; |
else if ( max < 8 ) nd_bpe = 3; |
else if ( max < 16 ) bpe = 4; |
else if ( max < 16 ) nd_bpe = 4; |
else if ( max < 32 ) bpe = 5; |
else if ( max < 32 ) nd_bpe = 5; |
else if ( max < 64 ) bpe = 6; |
else if ( max < 64 ) nd_bpe = 6; |
else if ( max < 256 ) bpe = 8; |
else if ( max < 256 ) nd_bpe = 8; |
else if ( max < 1024 ) bpe = 10; |
else if ( max < 1024 ) nd_bpe = 10; |
else if ( max < 65536 ) bpe = 16; |
else if ( max < 65536 ) nd_bpe = 16; |
else bpe = 32; |
else nd_bpe = 32; |
if ( bpe != nd_bpe || nvar != nd_nvar ) |
} |
nd_free_private_storage(); |
/* nvar == 0, don't touch nd_nvar */ |
nd_bpe = bpe; |
if ( nvar > 0 ) nd_nvar = nvar; |
nd_nvar = nvar; |
|
|
nd_epw = (sizeof(UINT)*8)/nd_bpe; |
nd_epw = (sizeof(UINT)*8)/nd_bpe; |
elen = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); |
elen = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); |
|
|
Line 2719 void nd_setup_parameters(int nvar,int max) { |
|
Line 2785 void nd_setup_parameters(int nvar,int max) { |
|
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
{ |
{ |
int i,obpe,oadv,h; |
int i,obpe,oadv,h; |
NM prev_nm_free_list; |
static NM prev_nm_free_list; |
|
static ND_pairs prev_ndp_free_list; |
RHist mr0,mr; |
RHist mr0,mr; |
RHist r; |
RHist r; |
RHist *old_red; |
RHist *old_red; |
ND_pairs s0,s,t,prev_ndp_free_list; |
ND_pairs s0,s,t; |
EPOS oepos; |
EPOS oepos; |
|
|
obpe = nd_bpe; |
obpe = nd_bpe; |
Line 2740 ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
|
Line 2807 ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
|
else if ( obpe < 32 ) nd_bpe = 32; |
else if ( obpe < 32 ) nd_bpe = 32; |
else error("nd_reconstruct : exponent too large"); |
else error("nd_reconstruct : exponent too large"); |
|
|
nd_setup_parameters(0,0); |
nd_setup_parameters(nd_nvar,0); |
prev_nm_free_list = _nm_free_list; |
prev_nm_free_list = _nm_free_list; |
prev_ndp_free_list = _ndp_free_list; |
prev_ndp_free_list = _ndp_free_list; |
_nm_free_list = 0; |
_nm_free_list = 0; |
Line 2783 ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
|
Line 2850 ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
|
if ( s0 ) NEXT(s) = 0; |
if ( s0 ) NEXT(s) = 0; |
prev_nm_free_list = 0; |
prev_nm_free_list = 0; |
prev_ndp_free_list = 0; |
prev_ndp_free_list = 0; |
|
#if 0 |
GC_gcollect(); |
GC_gcollect(); |
|
#endif |
return s0; |
return s0; |
} |
} |
|
|
Line 2858 int nd_sp(int mod,int trace,ND_pairs p,ND *rp) |
|
Line 2927 int nd_sp(int mod,int trace,ND_pairs p,ND *rp) |
|
if ( ndl_check_bound2(p->i1,DL(m)) ) |
if ( ndl_check_bound2(p->i1,DL(m)) ) |
return 0; |
return 0; |
t1 = ndv_mul_nm(mod,m,p1); |
t1 = ndv_mul_nm(mod,m,p1); |
if ( mod ) CM(m) = mod-HCM(p1); |
if ( mod == -1 ) CM(m) = _chsgnsf(HCM(p1)); |
|
else if ( mod ) CM(m) = mod-HCM(p1); |
else chsgnq(HCQ(p1),&CQ(m)); |
else chsgnq(HCQ(p1),&CQ(m)); |
ndl_sub(lcm,HDL(p2),DL(m)); |
ndl_sub(lcm,HDL(p2),DL(m)); |
if ( ndl_check_bound2(p->i2,DL(m)) ) { |
if ( ndl_check_bound2(p->i2,DL(m)) ) { |
Line 2878 void ndv_mul_c(int mod,NDV p,int mul) |
|
Line 2948 void ndv_mul_c(int mod,NDV p,int mul) |
|
|
|
if ( !p ) return; |
if ( !p ) return; |
len = LEN(p); |
len = LEN(p); |
for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) { |
if ( mod == -1 ) |
c1 = CM(m); DMAR(c1,mul,0,mod,c); CM(m) = c; |
for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) |
} |
CM(m) = _mulsf(CM(m),mul); |
|
else |
|
for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) { |
|
c1 = CM(m); DMAR(c1,mul,0,mod,c); CM(m) = c; |
|
} |
} |
} |
|
|
void ndv_mul_c_q(NDV p,Q mul) |
void ndv_mul_c_q(NDV p,Q mul) |
Line 3070 ND ndv_mul_nm(int mod,NM m0,NDV p) |
|
Line 3144 ND ndv_mul_nm(int mod,NM m0,NDV p) |
|
|
|
if ( !p ) return 0; |
if ( !p ) return 0; |
else if ( do_weyl ) |
else if ( do_weyl ) |
return weyl_ndv_mul_nm(mod,m0,p); |
if ( mod == -1 ) |
|
error("ndv_mul_nm : not implemented (weyl)"); |
|
else |
|
return weyl_ndv_mul_nm(mod,m0,p); |
else { |
else { |
n = NV(p); m = BDY(p); |
n = NV(p); m = BDY(p); |
d = DL(m0); |
d = DL(m0); |
len = LEN(p); |
len = LEN(p); |
mr0 = 0; |
mr0 = 0; |
td = TD(d); |
td = TD(d); |
if ( mod ) { |
if ( mod == -1 ) { |
c = CM(m0); |
c = CM(m0); |
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
NEXTNM(mr0,mr); |
NEXTNM(mr0,mr); |
|
CM(mr) = _mulsf(CM(m),c); |
|
ndl_add(DL(m),d,DL(mr)); |
|
} |
|
} else if ( mod ) { |
|
c = CM(m0); |
|
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
|
NEXTNM(mr0,mr); |
c1 = CM(m); |
c1 = CM(m); |
DMAR(c1,c,0,mod,c2); |
DMAR(c1,c,0,mod,c2); |
CM(mr) = c2; |
CM(mr) = c2; |
Line 3185 void ndv_mod(int mod,NDV p) |
|
Line 3269 void ndv_mod(int mod,NDV p) |
|
NMV t,d; |
NMV t,d; |
int r; |
int r; |
int i,len,dlen; |
int i,len,dlen; |
|
Obj gfs; |
|
|
if ( !p ) return; |
if ( !p ) return; |
len = LEN(p); |
len = LEN(p); |
dlen = 0; |
dlen = 0; |
for ( t = d = BDY(p), i = 0; i < len; i++, NMV_ADV(t) ) { |
if ( mod == -1 ) |
r = rem(NM(CQ(t)),mod); |
for ( t = d = BDY(p), i = 0; i < len; i++, NMV_ADV(t) ) { |
if ( r ) { |
simp_ff((Obj)CP(t),&gfs); |
if ( SGN(CQ(t)) < 0 ) |
r = FTOIF(CONT((GFS)gfs)); |
r = mod-r; |
|
CM(d) = r; |
CM(d) = r; |
ndl_copy(DL(t),DL(d)); |
ndl_copy(DL(t),DL(d)); |
NMV_ADV(d); |
NMV_ADV(d); |
dlen++; |
dlen++; |
} |
} |
} |
else |
|
for ( t = d = BDY(p), i = 0; i < len; i++, NMV_ADV(t) ) { |
|
r = rem(NM(CQ(t)),mod); |
|
if ( r ) { |
|
if ( SGN(CQ(t)) < 0 ) |
|
r = mod-r; |
|
CM(d) = r; |
|
ndl_copy(DL(t),DL(d)); |
|
NMV_ADV(d); |
|
dlen++; |
|
} |
|
} |
LEN(p) = dlen; |
LEN(p) = dlen; |
} |
} |
|
|
Line 3274 P ndvtop(int mod,VL vl,VL dvl,NDV p) |
|
Line 3369 P ndvtop(int mod,VL vl,VL dvl,NDV p) |
|
P c; |
P c; |
UINT *d; |
UINT *d; |
P s,r,u,t,w; |
P s,r,u,t,w; |
|
GFS gfs; |
|
|
if ( !p ) return 0; |
if ( !p ) return 0; |
else { |
else { |
Line 3281 P ndvtop(int mod,VL vl,VL dvl,NDV p) |
|
Line 3377 P ndvtop(int mod,VL vl,VL dvl,NDV p) |
|
n = NV(p); |
n = NV(p); |
m = (NMV)(((char *)BDY(p))+nmv_adv*(len-1)); |
m = (NMV)(((char *)BDY(p))+nmv_adv*(len-1)); |
for ( j = len-1, s = 0; j >= 0; j--, NMV_PREV(m) ) { |
for ( j = len-1, s = 0; j >= 0; j--, NMV_PREV(m) ) { |
if ( mod ) { |
if ( mod == -1 ) { |
|
e = IFTOF(CM(m)); MKGFS(e,gfs); c = (P)gfs; |
|
} else if ( mod ) { |
STOQ(CM(m),q); c = (P)q; |
STOQ(CM(m),q); c = (P)q; |
} else |
} else |
c = CP(m); |
c = CP(m); |
Line 3345 void ndv_print(NDV p) |
|
Line 3443 void ndv_print(NDV p) |
|
else { |
else { |
len = LEN(p); |
len = LEN(p); |
for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) { |
for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) { |
printf("+%d*",CM(m)); |
if ( CM(m) & 0x80000000 ) printf("+@_%d*",IFTOF(CM(m))); |
|
else printf("+%d*",CM(m)); |
ndl_print(DL(m)); |
ndl_print(DL(m)); |
} |
} |
printf("\n"); |
printf("\n"); |
Line 3705 void ndv_reduce_vect(int m,UINT *svect,int col,IndArra |
|
Line 3804 void ndv_reduce_vect(int m,UINT *svect,int col,IndArra |
|
if ( svect[i] >= (UINT)m ) svect[i] %= m; |
if ( svect[i] >= (UINT)m ) svect[i] %= m; |
} |
} |
|
|
|
void ndv_reduce_vect_sf(int m,UINT *svect,int col,IndArray *imat,NODE rp0) |
|
{ |
|
int i,j,k,len,pos,prev; |
|
UINT c,c1,c2,c3,up,lo,dmy; |
|
IndArray ivect; |
|
unsigned char *ivc; |
|
unsigned short *ivs; |
|
unsigned int *ivi; |
|
NDV redv; |
|
NMV mr; |
|
NODE rp; |
|
|
|
for ( rp = rp0, i = 0; rp; i++, rp = NEXT(rp) ) { |
|
ivect = imat[i]; |
|
k = ivect->head; svect[k] %= m; |
|
if ( c = svect[k] ) { |
|
c = _chsgnsf(c); redv = nd_ps[((NM_ind_pair)BDY(rp))->index]; |
|
len = LEN(redv); mr = BDY(redv); |
|
svect[k] = 0; prev = k; |
|
switch ( ivect->width ) { |
|
case 1: |
|
ivc = ivect->index.c; |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
|
pos = prev+ivc[j]; prev = pos; |
|
svect[pos] = _addsf(_mulsf(CM(mr),c),svect[pos]); |
|
} |
|
break; |
|
case 2: |
|
ivs = ivect->index.s; |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
|
pos = prev+ivs[j]; prev = pos; |
|
svect[pos] = _addsf(_mulsf(CM(mr),c),svect[pos]); |
|
} |
|
break; |
|
case 4: |
|
ivi = ivect->index.i; |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
|
pos = prev+ivi[j]; prev = pos; |
|
svect[pos] = _addsf(_mulsf(CM(mr),c),svect[pos]); |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
|
NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhead,UINT *s0vect) |
NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhead,UINT *s0vect) |
{ |
{ |
int j,k,len; |
int j,k,len; |
Line 3780 int nd_symbolic_preproc(PGeoBucket bucket,UINT **s0vec |
|
Line 3925 int nd_symbolic_preproc(PGeoBucket bucket,UINT **s0vec |
|
} |
} |
col++; |
col++; |
} |
} |
NEXT(rp) = 0; NEXT(s) = 0; |
if ( rp0 ) NEXT(rp) = 0; |
|
NEXT(s) = 0; |
s0v = (UINT *)MALLOC_ATOMIC(col*nd_wpd*sizeof(UINT)); |
s0v = (UINT *)MALLOC_ATOMIC(col*nd_wpd*sizeof(UINT)); |
for ( i = 0, p = s0v, s = s0; i < col; |
for ( i = 0, p = s0v, s = s0; i < col; |
i++, p += nd_wpd, s = NEXT(s) ) ndl_copy(DL(s),p); |
i++, p += nd_wpd, s = NEXT(s) ) ndl_copy(DL(s),p); |
Line 3886 NODE nd_f4(int m) |
|
Line 4032 NODE nd_f4(int m) |
|
rank = generic_gauss_elim_mod(spmat,sprow,spcol,m,colstat); |
rank = generic_gauss_elim_mod(spmat,sprow,spcol,m,colstat); |
|
|
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
fprintf(asir_out,"sugar=%d,nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
if ( DP_Print ) { |
sugar,nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"sugar=%d,nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
sugar,nsp,nred,sprow,spcol,rank); |
|
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
|
} |
|
|
/* adding new bases */ |
/* adding new bases */ |
for ( i = 0; i < rank; i++ ) { |
for ( i = 0; i < rank; i++ ) { |
Line 3970 NODE nd_f4(int m) |
|
Line 4118 NODE nd_f4(int m) |
|
svect = (UINT *)MALLOC_ATOMIC(col*sizeof(UINT)); |
svect = (UINT *)MALLOC_ATOMIC(col*sizeof(UINT)); |
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
nd_to_vect(m,s0vect,col,BDY(sp),svect); |
nd_to_vect(m,s0vect,col,BDY(sp),svect); |
ndv_reduce_vect(m,svect,col,imat,rp0); |
if ( m == -1 ) ndv_reduce_vect_sf(m,svect,col,imat,rp0); |
|
else ndv_reduce_vect(m,svect,col,imat,rp0); |
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
if ( i < col ) { |
if ( i < col ) { |
spmat[sprow] = v = (UINT *)MALLOC_ATOMIC(spcol*sizeof(UINT)); |
spmat[sprow] = v = (UINT *)MALLOC_ATOMIC(spcol*sizeof(UINT)); |
Line 3984 NODE nd_f4(int m) |
|
Line 4133 NODE nd_f4(int m) |
|
|
|
/* elimination (2nd step) */ |
/* elimination (2nd step) */ |
colstat = (int *)ALLOCA(spcol*sizeof(int)); |
colstat = (int *)ALLOCA(spcol*sizeof(int)); |
rank = generic_gauss_elim_mod(spmat,sprow,spcol,m,colstat); |
if ( m == -1 ) |
|
rank = generic_gauss_elim_sf(spmat,sprow,spcol,m,colstat); |
|
else |
|
rank = generic_gauss_elim_mod(spmat,sprow,spcol,m,colstat); |
|
|
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
fprintf(asir_out,"sugar=%d,nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
if ( DP_Print ) { |
sugar,nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"sugar=%d,nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
sugar,nsp,nred,sprow,spcol,rank); |
|
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
|
} |
|
|
/* adding new bases */ |
/* adding new bases */ |
for ( i = 0; i < rank; i++ ) { |
for ( i = 0; i < rank; i++ ) { |