version 1.19, 2003/07/31 07:30:27 |
version 1.20, 2003/08/01 05:03:15 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.18 2003/07/31 05:42:22 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.19 2003/07/31 07:30:27 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 53 typedef struct oNMV { |
|
Line 53 typedef struct oNMV { |
|
typedef struct oRHist { |
typedef struct oRHist { |
struct oRHist *next; |
struct oRHist *next; |
int index; |
int index; |
int td; |
int td,sugar; |
unsigned int dl[1]; |
unsigned int dl[1]; |
} *RHist; |
} *RHist; |
|
|
|
|
int nd_epw,nd_bpe,nd_wpd; |
int nd_epw,nd_bpe,nd_wpd; |
unsigned int nd_mask[32]; |
unsigned int nd_mask[32]; |
unsigned int nd_mask0,nd_mask1; |
unsigned int nd_mask0,nd_mask1; |
|
|
NM _nm_free_list; |
NM _nm_free_list; |
ND _nd_free_list; |
ND _nd_free_list; |
ND_pairs _ndp_free_list; |
ND_pairs _ndp_free_list; |
|
|
|
static NDV *nd_ps; |
|
static NDV *nd_psq; |
|
int *nd_psl; |
|
RHist *nd_psh; |
|
int nd_psn,nd_pslen; |
|
|
RHist *nd_red; |
RHist *nd_red; |
int nd_red_len; |
int nd_red_len; |
|
|
extern int Top,Reverse; |
|
int nd_psn,nd_pslen; |
|
int nd_found,nd_create,nd_notfirst; |
int nd_found,nd_create,nd_notfirst; |
int *nd_psl; |
|
RHist *nd_psh; |
|
int nm_adv; |
int nm_adv; |
#define NM_ADV(m) (m = (NM)(((char *)m)+nm_adv)) |
int nmv_adv; |
|
int nmv_len; |
|
NDV ndv_red; |
|
|
void GC_gcollect(); |
extern int Top,Reverse; |
NODE append_one(NODE,int); |
|
|
|
#define HTD(d) ((d)->body->td) |
#define HTD(d) ((d)->body->td) |
#define HDL(d) ((d)->body->dl) |
#define HDL(d) ((d)->body->dl) |
Line 98 NODE append_one(NODE,int); |
|
Line 103 NODE append_one(NODE,int); |
|
#define SG(a) ((a)->sugar) |
#define SG(a) ((a)->sugar) |
#define LEN(a) ((a)->len) |
#define LEN(a) ((a)->len) |
|
|
|
#define NM_ADV(m) (m = (NM)(((char *)m)+nm_adv)) |
#define NEWRHist(r) \ |
#define NEWRHist(r) \ |
((r)=(RHist)MALLOC(sizeof(struct oRHist)+(nd_wpd-1)*sizeof(unsigned int))) |
((r)=(RHist)MALLOC(sizeof(struct oRHist)+(nd_wpd-1)*sizeof(unsigned int))) |
#define NEWND_pairs(m) if(!_ndp_free_list)_NDP_alloc(); (m)=_ndp_free_list; _ndp_free_list = NEXT(_ndp_free_list) |
#define NEWND_pairs(m) if(!_ndp_free_list)_NDP_alloc(); (m)=_ndp_free_list; _ndp_free_list = NEXT(_ndp_free_list) |
Line 117 if(!(r)){(c)=(r)=(s);}else{NEXT(c)=(s);(c)=(s);} |
|
Line 123 if(!(r)){(c)=(r)=(s);}else{NEXT(c)=(s);(c)=(s);} |
|
#define NEXTND_pairs(r,c) \ |
#define NEXTND_pairs(r,c) \ |
if(!(r)){NEWND_pairs(r);(c)=(r);}else{NEWND_pairs(NEXT(c));(c)=NEXT(c);} |
if(!(r)){NEWND_pairs(r);(c)=(r);}else{NEWND_pairs(NEXT(c));(c)=NEXT(c);} |
|
|
void nd_removecont(ND p); |
void nd_removecont(int mod,ND p); |
void ndv_removecont(NDV p); |
void ndv_removecont(int mod,NDV p); |
void ndv_mul_c_q(NDV p,Q mul); |
void ndv_mul_c_q(NDV p,Q mul); |
void nd_mul_c_q(ND p,Q mul); |
void nd_mul_c_q(ND p,Q mul); |
|
|
|
void GC_gcollect(); |
|
NODE append_one(NODE,int); |
|
|
ND_pairs crit_B( ND_pairs d, int s ); |
ND_pairs crit_B( ND_pairs d, int s ); |
void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp); |
void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp); |
|
void nd_gr_trace(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp); |
NODE nd_setup(int mod,NODE f); |
NODE nd_setup(int mod,NODE f); |
int nd_newps(int mod,ND a); |
int nd_newps(int mod,ND a); |
|
int nd_newps_trace(int mod,ND nf,ND nfq); |
ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ); |
ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ); |
NODE update_base(NODE nd,int ndp); |
NODE update_base(NODE nd,int ndp); |
static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest ); |
static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest ); |
Line 135 ND_pairs crit_M( ND_pairs d1 ); |
|
Line 146 ND_pairs crit_M( ND_pairs d1 ); |
|
ND_pairs nd_newpairs( NODE g, int t ); |
ND_pairs nd_newpairs( NODE g, int t ); |
ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t); |
ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t); |
NODE nd_gb(int m,NODE f); |
NODE nd_gb(int m,NODE f); |
|
NODE nd_gb_trace(int m,NODE f); |
void nd_free_private_storage(); |
void nd_free_private_storage(); |
void _NM_alloc(); |
void _NM_alloc(); |
void _ND_alloc(); |
void _ND_alloc(); |
Line 156 void ndv_print(NDV p); |
|
Line 168 void ndv_print(NDV p); |
|
void ndv_print_q(NDV p); |
void ndv_print_q(NDV p); |
void ndp_print(ND_pairs d); |
void ndp_print(ND_pairs d); |
int nd_length(ND p); |
int nd_length(ND p); |
void nd_monic(int mod,ND p); |
|
void nd_mul_c(int mod,ND p,int mul); |
void nd_mul_c(int mod,ND p,int mul); |
void nd_free_redlist(); |
void nd_free_redlist(); |
void nd_append_red(unsigned int *d,int td,int i); |
void nd_append_red(unsigned int *d,int td,int i); |
unsigned int *nd_compute_bound(ND p); |
unsigned int *nd_compute_bound(ND p); |
unsigned int *dp_compute_bound(DP p); |
unsigned int *dp_compute_bound(DP p); |
ND_pairs nd_reconstruct(ND_pairs); |
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs ndp); |
void nd_setup_parameters(); |
void nd_setup_parameters(); |
void nd_realloc(ND p,int obpe); |
void nd_realloc(ND p,int obpe); |
ND nd_copy(ND p); |
ND nd_copy(ND p); |
void ndl_dup(int obpe,unsigned int *d,unsigned int *r); |
void ndl_dup(int obpe,unsigned int *d,unsigned int *r); |
|
|
static NDV *nd_ps; |
|
|
|
#define NMV_ADV(m) (m = (NMV)(((char *)m)+nmv_adv)) |
#define NMV_ADV(m) (m = (NMV)(((char *)m)+nmv_adv)) |
#define NEWNDV(d) ((d)=(NDV)MALLOC(sizeof(struct oNDV))) |
#define NEWNDV(d) ((d)=(NDV)MALLOC(sizeof(struct oNDV))) |
#define MKNDV(n,m,l,d) NEWNDV(d); NV(d)=(n); BDY(d)=(m); LEN(d) = l; |
#define MKNDV(n,m,l,d) NEWNDV(d); NV(d)=(n); BDY(d)=(m); LEN(d) = l; |
|
|
int nmv_adv; |
|
int nmv_len; |
|
NDV ndv_red; |
|
|
|
void ndv_mul_c(int mod,NDV p,int mul); |
void ndv_mul_c(int mod,NDV p,int mul); |
ND ndv_add(int mod,ND p1,NDV p2); |
ND ndv_add(int mod,ND p1,NDV p2); |
ND ndv_add_q(ND p1,NDV p2); |
ND ndv_add_q(ND p1,NDV p2); |
Line 816 int nd_nf(int mod,ND g,int full,ND *rp) |
|
Line 820 int nd_nf(int mod,ND g,int full,ND *rp) |
|
p = nd_ps[index]; |
p = nd_ps[index]; |
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; |
ndv_mul_nm(mod,p,mul,ndv_red); |
|
g = ndv_add(mod,g,ndv_red); |
|
} else { |
} else { |
p = nd_ps[index]; |
p = nd_psq[index]; |
igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred); |
igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred); |
chsgnq(cg,&CQ(mul)); |
chsgnq(cg,&CQ(mul)); |
nd_mul_c_q(d,cred); |
nd_mul_c_q(d,cred); nd_mul_c_q(g,cred); |
nd_mul_c_q(g,cred); |
|
ndv_mul_nm(mod,p,mul,ndv_red); |
|
g = ndv_add_q(g,ndv_red); |
|
} |
} |
|
ndv_mul_nm(mod,p,mul,ndv_red); |
|
g = ndv_add(mod,g,ndv_red); |
sugar = MAX(sugar,SG(ndv_red)); |
sugar = MAX(sugar,SG(ndv_red)); |
} else if ( !full ) { |
} else if ( !full ) { |
*rp = g; |
*rp = g; |
|
|
stat = nd_sp(m,l,&h); |
stat = nd_sp(m,l,&h); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(d); |
d = nd_reconstruct(m,0,d); |
goto again; |
goto again; |
} |
} |
stat = nd_nf(m,h,!Top,&nf); |
stat = nd_nf(m,h,!Top,&nf); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(d); |
d = nd_reconstruct(m,0,d); |
goto again; |
goto again; |
} else if ( nf ) { |
} else if ( nf ) { |
printf("+"); fflush(stdout); |
printf("+"); fflush(stdout); |
|
|
return g; |
return g; |
} |
} |
|
|
|
NODE nd_gb_trace(int m,NODE f) |
|
{ |
|
int i,nh,sugar,stat; |
|
NODE r,g,gall; |
|
ND_pairs d; |
|
ND_pairs l; |
|
ND h,nf,nfq; |
|
|
|
for ( gall = g = 0, d = 0, r = f; r; r = NEXT(r) ) { |
|
i = (int)BDY(r); |
|
d = update_pairs(d,g,i); |
|
g = update_base(g,i); |
|
gall = append_one(gall,i); |
|
} |
|
sugar = 0; |
|
while ( d ) { |
|
again: |
|
l = nd_minp(d,&d); |
|
if ( SG(l) != sugar ) { |
|
sugar = SG(l); |
|
fprintf(asir_out,"%d",sugar); |
|
} |
|
stat = nd_sp(m,l,&h); |
|
if ( !stat ) { |
|
NEXT(l) = d; d = l; |
|
d = nd_reconstruct(m,1,d); |
|
goto again; |
|
} |
|
stat = nd_nf(m,h,!Top,&nf); |
|
if ( !stat ) { |
|
NEXT(l) = d; d = l; |
|
d = nd_reconstruct(m,1,d); |
|
goto again; |
|
} else if ( nf ) { |
|
/* overflow does not occur */ |
|
nd_sp(0,l,&h); |
|
nd_nf(0,h,!Top,&nfq); |
|
if ( nfq ) { |
|
printf("+"); fflush(stdout); |
|
nh = nd_newps_trace(m,nf,nfq); |
|
d = update_pairs(d,g,nh); |
|
g = update_base(g,nh); |
|
gall = append_one(gall,nh); |
|
} else { |
|
printf("*"); fflush(stdout); |
|
} |
|
} else { |
|
printf("."); fflush(stdout); |
|
} |
|
FREENDP(l); |
|
} |
|
return g; |
|
} |
|
|
ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t) |
ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t) |
{ |
{ |
ND_pairs d1,nd,cur,head,prev,remove; |
ND_pairs d1,nd,cur,head,prev,remove; |
Line 1103 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 1158 ND_pairs nd_newpairs( NODE g, int t ) |
|
int td,ts,s; |
int td,ts,s; |
ND_pairs r,r0; |
ND_pairs r,r0; |
|
|
dl = HDL(nd_ps[t]); |
dl = DL(nd_psh[t]); |
td = HTD(nd_ps[t]); |
td = TD(nd_psh[t]); |
ts = SG(nd_ps[t]) - td; |
ts = SG(nd_psh[t]) - td; |
for ( r0 = 0, h = g; h; h = NEXT(h) ) { |
for ( r0 = 0, h = g; h; h = NEXT(h) ) { |
NEXTND_pairs(r0,r); |
NEXTND_pairs(r0,r); |
r->i1 = (int)BDY(h); |
r->i1 = (int)BDY(h); |
r->i2 = t; |
r->i2 = t; |
ndl_lcm(HDL(nd_ps[r->i1]),dl,r->lcm); |
ndl_lcm(DL(nd_psh[r->i1]),dl,r->lcm); |
TD(r) = ndl_td(r->lcm); |
TD(r) = ndl_td(r->lcm); |
s = SG(nd_ps[r->i1])-HTD(nd_ps[r->i1]); |
s = SG(nd_psh[r->i1])-TD(nd_psh[r->i1]); |
SG(r) = MAX(s,ts) + TD(r); |
SG(r) = MAX(s,ts) + TD(r); |
} |
} |
NEXT(r) = 0; |
NEXT(r) = 0; |
Line 1126 ND_pairs crit_B( ND_pairs d, int s ) |
|
Line 1181 ND_pairs crit_B( ND_pairs d, int s ) |
|
int td,tdl; |
int td,tdl; |
|
|
if ( !d ) return 0; |
if ( !d ) return 0; |
t = HDL(nd_ps[s]); |
t = DL(nd_psh[s]); |
prev = 0; |
prev = 0; |
head = cur = d; |
head = cur = d; |
lcm = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
lcm = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
while ( cur ) { |
while ( cur ) { |
tl = cur->lcm; |
tl = cur->lcm; |
if ( ndl_reducible(tl,t) |
if ( ndl_reducible(tl,t) |
&& (ndl_lcm(HDL(nd_ps[cur->i1]),t,lcm),!ndl_equal(lcm,tl)) |
&& (ndl_lcm(DL(nd_psh[cur->i1]),t,lcm),!ndl_equal(lcm,tl)) |
&& (ndl_lcm(HDL(nd_ps[cur->i2]),t,lcm),!ndl_equal(lcm,tl)) ) { |
&& (ndl_lcm(DL(nd_psh[cur->i2]),t,lcm),!ndl_equal(lcm,tl)) ) { |
remove = cur; |
remove = cur; |
if ( !prev ) { |
if ( !prev ) { |
head = cur = NEXT(cur); |
head = cur = NEXT(cur); |
Line 1239 ND_pairs crit_F( ND_pairs d1 ) |
|
Line 1294 ND_pairs crit_F( ND_pairs d1 ) |
|
|
|
int crit_2( int dp1, int dp2 ) |
int crit_2( int dp1, int dp2 ) |
{ |
{ |
return ndl_disjoint(HDL(nd_ps[dp1]),HDL(nd_ps[dp2])); |
return ndl_disjoint(DL(nd_psh[dp1]),DL(nd_psh[dp2])); |
} |
} |
|
|
static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest ) |
static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest ) |
Line 1273 NODE update_base(NODE nd,int ndp) |
|
Line 1328 NODE update_base(NODE nd,int ndp) |
|
NODE last, p, head; |
NODE last, p, head; |
int td,tdn; |
int td,tdn; |
|
|
dl = HDL(nd_ps[ndp]); |
dl = DL(nd_psh[ndp]); |
td = HTD(nd_ps[ndp]); |
td = TD(nd_psh[ndp]); |
for ( head = last = 0, p = nd; p; ) { |
for ( head = last = 0, p = nd; p; ) { |
dln = HDL(nd_ps[(int)BDY(p)]); |
dln = DL(nd_psh[(int)BDY(p)]); |
tdn = HTD(nd_ps[(int)BDY(p)]); |
tdn = TD(nd_psh[(int)BDY(p)]); |
if ( tdn >= td && ndl_reducible( dln, dl ) ) { |
if ( tdn >= td && ndl_reducible( dln, dl ) ) { |
p = NEXT(p); |
p = NEXT(p); |
if ( last ) NEXT(last) = p; |
if ( last ) NEXT(last) = p; |
Line 1346 int nd_newps(int mod,ND a) |
|
Line 1401 int nd_newps(int mod,ND a) |
|
{ |
{ |
int len; |
int len; |
RHist r; |
RHist r; |
|
NDV b; |
|
|
if ( nd_psn == nd_pslen ) { |
if ( nd_psn == nd_pslen ) { |
nd_pslen *= 2; |
nd_pslen *= 2; |
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
|
nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV)); |
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
nd_bound = (unsigned int **) |
nd_bound = (unsigned int **) |
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *)); |
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *)); |
} |
} |
|
nd_removecont(mod,a); |
|
nd_bound[nd_psn] = nd_compute_bound(a); |
|
NEWRHist(r); SG(r) = SG(a); TD(r) = HTD(a); ndl_copy(HDL(a),DL(r)); |
|
nd_psh[nd_psn] = r; |
|
b = ndtondv(mod,a); |
|
len = LEN(b); |
if ( mod ) |
if ( mod ) |
nd_monic(mod,a); |
nd_ps[nd_psn] = b; |
else |
else |
nd_removecont(a); |
nd_psq[nd_psn] = b; |
nd_bound[nd_psn] = nd_compute_bound(a); |
nd_psl[nd_psn] = len; |
NEWRHist(r); TD(r) = HTD(a); ndl_copy(HDL(a),DL(r)); nd_psh[nd_psn] = r; |
|
nd_ps[nd_psn]= ndtondv(mod,a); |
|
nd_free(a); |
nd_free(a); |
nd_psl[nd_psn] = len = LEN(nd_ps[nd_psn]); |
|
if ( len > nmv_len ) { |
if ( len > nmv_len ) { |
nmv_len = 2*len; |
nmv_len = 2*len; |
BDY(ndv_red) = (NMV)REALLOC(BDY(ndv_red),nmv_len*nmv_adv); |
BDY(ndv_red) = (NMV)REALLOC(BDY(ndv_red),nmv_len*nmv_adv); |
Line 1371 int nd_newps(int mod,ND a) |
|
Line 1431 int nd_newps(int mod,ND a) |
|
return nd_psn++; |
return nd_psn++; |
} |
} |
|
|
|
int nd_newps_trace(int mod,ND nf,ND nfq) |
|
{ |
|
int len; |
|
RHist r; |
|
NDV b; |
|
|
|
if ( nd_psn == nd_pslen ) { |
|
nd_pslen *= 2; |
|
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
|
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
|
nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV)); |
|
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
|
nd_bound = (unsigned int **) |
|
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *)); |
|
} |
|
nd_removecont(mod,nf); |
|
nd_ps[nd_psn] = ndtondv(mod,nf); |
|
|
|
nd_removecont(0,nfq); |
|
nd_psq[nd_psn] = ndtondv(0,nfq); |
|
|
|
nd_bound[nd_psn] = nd_compute_bound(nfq); |
|
NEWRHist(r); SG(r) = SG(nf); TD(r) = HTD(nf); ndl_copy(HDL(nf),DL(r)); |
|
nd_psh[nd_psn] = r; |
|
|
|
len = LEN(nd_psq[nd_psn]); |
|
nd_psl[nd_psn] = len; |
|
|
|
nd_free(nf); nd_free(nfq); |
|
if ( len > nmv_len ) { |
|
nmv_len = 2*len; |
|
BDY(ndv_red) = (NMV)REALLOC(BDY(ndv_red),nmv_len*nmv_adv); |
|
} |
|
return nd_psn++; |
|
} |
|
|
NODE nd_setup(int mod,NODE f) |
NODE nd_setup(int mod,NODE f) |
{ |
{ |
int i,j,td,len,max; |
int i,j,td,len,max; |
NODE s,s0,f0; |
NODE s,s0,f0; |
unsigned int *d; |
unsigned int *d; |
RHist r; |
RHist r; |
|
NDV a; |
|
|
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
|
|
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
|
nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *)); |
nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *)); |
for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) { |
for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) { |
Line 1411 NODE nd_setup(int mod,NODE f) |
|
Line 1509 NODE nd_setup(int mod,NODE f) |
|
nd_free_private_storage(); |
nd_free_private_storage(); |
len = 0; |
len = 0; |
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
nd_ps[i] = dptondv(mod,(DP)BDY(f)); |
NEWRHist(r); |
|
a = dptondv(mod,(DP)BDY(f)); |
|
ndv_removecont(mod,a); |
|
len = MAX(len,LEN(a)); |
|
SG(r) = HTD(a); TD(r) = HTD(a); ndl_copy(HDL(a),DL(r)); |
if ( mod ) |
if ( mod ) |
ndv_mul_c(mod,nd_ps[i],invm(HCM(nd_ps[i]),mod)); |
nd_ps[i] = a; |
else |
else |
ndv_removecont(nd_ps[i]); |
nd_psq[i] = a; |
len = MAX(len,LEN(nd_ps[i])); |
|
NEWRHist(r); TD(r) = HTD(nd_ps[i]); ndl_copy(HDL(nd_ps[i]),DL(r)); |
|
nd_psh[i] = r; |
nd_psh[i] = r; |
} |
} |
nmv_len = 16*len; |
nmv_len = 16*len; |
Line 1433 NODE nd_setup(int mod,NODE f) |
|
Line 1533 NODE nd_setup(int mod,NODE f) |
|
return s0; |
return s0; |
} |
} |
|
|
|
NODE nd_setup_trace(int mod,NODE f) |
|
{ |
|
int i,j,td,len,max; |
|
NODE s,s0,f0; |
|
unsigned int *d; |
|
RHist r; |
|
NDV a; |
|
|
|
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
|
|
|
nd_psn = length(f); nd_pslen = 2*nd_psn; |
|
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
|
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
|
nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
|
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
|
nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *)); |
|
for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) { |
|
nd_bound[i] = d = dp_compute_bound((DP)BDY(s)); |
|
for ( j = 0; j < nd_nvar; j++ ) |
|
max = MAX(d[j],max); |
|
} |
|
if ( !nd_red ) |
|
nd_red = (RHist *)MALLOC(REDTAB_LEN*sizeof(RHist)); |
|
bzero(nd_red,REDTAB_LEN*sizeof(RHist)); |
|
|
|
if ( max < 2 ) |
|
nd_bpe = 2; |
|
else if ( max < 4 ) |
|
nd_bpe = 4; |
|
else if ( max < 64 ) |
|
nd_bpe = 6; |
|
else if ( max < 256 ) |
|
nd_bpe = 8; |
|
else if ( max < 65536 ) |
|
nd_bpe = 16; |
|
else |
|
nd_bpe = 32; |
|
|
|
nd_setup_parameters(); |
|
nd_free_private_storage(); |
|
len = 0; |
|
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
|
a = dptondv(mod,(DP)BDY(f)); ndv_removecont(mod,a); nd_ps[i] = a; |
|
a = dptondv(0,(DP)BDY(f)); ndv_removecont(0,a); nd_psq[i] = a; |
|
NEWRHist(r); |
|
len = MAX(len,LEN(a)); |
|
SG(r) = HTD(a); TD(r) = HTD(a); ndl_copy(HDL(a),DL(r)); |
|
nd_psh[i] = r; |
|
} |
|
nmv_len = 16*len; |
|
NEWNDV(ndv_red); |
|
BDY(ndv_red) = (NMV)MALLOC(nmv_len*nmv_adv); |
|
for ( s0 = 0, i = 0; i < nd_psn; i++ ) { |
|
NEXTNODE(s0,s); BDY(s) = (pointer)i; |
|
} |
|
if ( s0 ) NEXT(s) = 0; |
|
return s0; |
|
} |
|
|
void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp) |
void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp) |
{ |
{ |
struct order_spec ord1; |
struct order_spec ord1; |
Line 1457 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
Line 1616 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
initd(ord); |
initd(ord); |
for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
ptod(CO,vv,(P)BDY(t),&b); |
ptod(CO,vv,(P)BDY(t),&b); |
if ( m ) |
NEXTNODE(fd0,fd); BDY(fd) = (pointer)b; |
_dp_mod(b,m,0,&c); |
|
else |
|
c = b; |
|
if ( c ) { |
|
NEXTNODE(fd0,fd); BDY(fd) = (pointer)c; |
|
} |
|
} |
} |
if ( fd0 ) NEXT(fd) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
s = nd_setup(m,fd0); |
s = nd_setup(m,fd0); |
Line 1473 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
Line 1626 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
#endif |
#endif |
for ( r0 = 0; x; x = NEXT(x) ) { |
for ( r0 = 0; x; x = NEXT(x) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
a = ndvtodp(m,nd_ps[(int)BDY(x)]); |
if ( m ) { |
if ( m ) |
a = ndvtodp(m,nd_ps[(int)BDY(x)]); |
_dtop_mod(CO,vv,a,(P *)&BDY(r)); |
_dtop_mod(CO,vv,a,(P *)&BDY(r)); |
else |
} else { |
|
a = ndvtodp(m,nd_psq[(int)BDY(x)]); |
dtop(CO,vv,a,(P *)&BDY(r)); |
dtop(CO,vv,a,(P *)&BDY(r)); |
|
} |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKLIST(*rp,r0); |
MKLIST(*rp,r0); |
Line 1485 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
Line 1640 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
nd_found,nd_notfirst,nd_create); |
nd_found,nd_notfirst,nd_create); |
} |
} |
|
|
|
void nd_gr_trace(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp) |
|
{ |
|
struct order_spec ord1; |
|
VL fv,vv,vc; |
|
NODE fd,fd0,r,r0,t,x,s,xx; |
|
DP a,b,c; |
|
|
|
get_vars((Obj)f,&fv); pltovl(v,&vv); |
|
nd_nvar = length(vv); |
|
if ( ord->id ) |
|
error("nd_gr : unsupported order"); |
|
switch ( ord->ord.simple ) { |
|
case 0: |
|
is_rlex = 1; |
|
break; |
|
case 1: |
|
is_rlex = 0; |
|
break; |
|
default: |
|
error("nd_gr : unsupported order"); |
|
} |
|
initd(ord); |
|
for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
|
ptod(CO,vv,(P)BDY(t),&c); |
|
if ( c ) { |
|
NEXTNODE(fd0,fd); BDY(fd) = (pointer)c; |
|
} |
|
} |
|
if ( fd0 ) NEXT(fd) = 0; |
|
/* setup over GF(m) */ |
|
s = nd_setup_trace(m,fd0); |
|
x = nd_gb_trace(m,s); |
|
#if 0 |
|
x = nd_reduceall(x,m); |
|
#endif |
|
for ( r0 = 0; x; x = NEXT(x) ) { |
|
NEXTNODE(r0,r); |
|
a = ndvtodp(0,nd_psq[(int)BDY(x)]); |
|
dtop(CO,vv,a,(P *)&BDY(r)); |
|
} |
|
if ( r0 ) NEXT(r) = 0; |
|
MKLIST(*rp,r0); |
|
fprintf(asir_out,"found=%d,notfirst=%d,create=%d\n", |
|
nd_found,nd_notfirst,nd_create); |
|
} |
|
|
void dltondl(int n,DL dl,unsigned int *r) |
void dltondl(int n,DL dl,unsigned int *r) |
{ |
{ |
unsigned int *d; |
unsigned int *d; |
Line 1634 void ndp_print(ND_pairs d) |
|
Line 1835 void ndp_print(ND_pairs d) |
|
printf("\n"); |
printf("\n"); |
} |
} |
|
|
void nd_removecont(ND p) |
void nd_removecont(int mod,ND p) |
{ |
{ |
int i,n; |
int i,n; |
Q *w; |
Q *w; |
Q dvr,t; |
Q dvr,t; |
NM m; |
NM m; |
|
|
for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ ); |
if ( mod ) |
w = (Q *)ALLOCA(n*sizeof(Q)); |
nd_mul_c(mod,p,invm(HCM(p),mod)); |
for ( m = BDY(p), i = 0; i < n; m = NEXT(m), i++ ) |
else { |
w[i] = CQ(m); |
for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ ); |
sortbynm(w,n); |
w = (Q *)ALLOCA(n*sizeof(Q)); |
qltozl(w,n,&dvr); |
for ( m = BDY(p), i = 0; i < n; m = NEXT(m), i++ ) |
for ( m = BDY(p); m; m = NEXT(m) ) { |
w[i] = CQ(m); |
divq(CQ(m),dvr,&t); CQ(m) = t; |
sortbynm(w,n); |
|
qltozl(w,n,&dvr); |
|
for ( m = BDY(p); m; m = NEXT(m) ) { |
|
divq(CQ(m),dvr,&t); CQ(m) = t; |
|
} |
} |
} |
} |
} |
|
|
void ndv_removecont(NDV p) |
void ndv_removecont(int mod,NDV p) |
{ |
{ |
int i,len; |
int i,len; |
Q *w; |
Q *w; |
Q dvr,t; |
Q dvr,t; |
NMV m; |
NMV m; |
|
|
len = p->len; |
if ( mod ) |
w = (Q *)ALLOCA(len*sizeof(Q)); |
ndv_mul_c(mod,p,invm(HCM(p),mod)); |
for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) |
else { |
w[i] = CQ(m); |
len = p->len; |
sortbynm(w,len); |
w = (Q *)ALLOCA(len*sizeof(Q)); |
qltozl(w,len,&dvr); |
for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) |
for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) { |
w[i] = CQ(m); |
divq(CQ(m),dvr,&t); CQ(m) = t; |
sortbynm(w,len); |
|
qltozl(w,len,&dvr); |
|
for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) { |
|
divq(CQ(m),dvr,&t); CQ(m) = t; |
|
} |
} |
} |
} |
} |
|
|
void nd_monic(int mod,ND p) |
|
{ |
|
if ( !p ) |
|
return; |
|
else |
|
nd_mul_c(mod,p,invm(HCM(p),mod)); |
|
} |
|
|
|
void nd_mul_c(int mod,ND p,int mul) |
void nd_mul_c(int mod,ND p,int mul) |
{ |
{ |
NM m; |
NM m; |
Line 1801 void nd_setup_parameters() { |
|
Line 2002 void nd_setup_parameters() { |
|
nmv_adv = sizeof(struct oNMV)+(nd_wpd-1)*sizeof(unsigned int); |
nmv_adv = sizeof(struct oNMV)+(nd_wpd-1)*sizeof(unsigned int); |
} |
} |
|
|
ND_pairs nd_reconstruct(ND_pairs d) |
/* mod < 0 => realloc nd_ps and pd_psq */ |
|
|
|
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d) |
{ |
{ |
int i,obpe,oadv; |
int i,obpe,oadv; |
NM prev_nm_free_list; |
NM prev_nm_free_list; |
Line 1829 ND_pairs nd_reconstruct(ND_pairs d) |
|
Line 2032 ND_pairs nd_reconstruct(ND_pairs d) |
|
prev_ndp_free_list = _ndp_free_list; |
prev_ndp_free_list = _ndp_free_list; |
_nm_free_list = 0; |
_nm_free_list = 0; |
_ndp_free_list = 0; |
_ndp_free_list = 0; |
for ( i = nd_psn-1; i >= 0; i-- ) { |
if ( mod != 0 ) |
ndv_realloc(nd_ps[i],obpe,oadv); |
for ( i = nd_psn-1; i >= 0; i-- ) |
} |
ndv_realloc(nd_ps[i],obpe,oadv); |
|
if ( !mod || trace ) |
|
for ( i = nd_psn-1; i >= 0; i-- ) |
|
ndv_realloc(nd_psq[i],obpe,oadv); |
s0 = 0; |
s0 = 0; |
for ( t = d; t; t = NEXT(t) ) { |
for ( t = d; t; t = NEXT(t) ) { |
NEXTND_pairs(s0,s); |
NEXTND_pairs(s0,s); |
Line 1845 ND_pairs nd_reconstruct(ND_pairs d) |
|
Line 2051 ND_pairs nd_reconstruct(ND_pairs d) |
|
for ( mr0 = 0, r = nd_red[i]; r; r = NEXT(r) ) { |
for ( mr0 = 0, r = nd_red[i]; r; r = NEXT(r) ) { |
NEXTRHist(mr0,mr); |
NEXTRHist(mr0,mr); |
mr->index = r->index; |
mr->index = r->index; |
|
SG(mr) = SG(r); |
TD(mr) = TD(r); |
TD(mr) = TD(r); |
ndl_dup(obpe,DL(r),DL(mr)); |
ndl_dup(obpe,DL(r),DL(mr)); |
} |
} |
Line 1852 ND_pairs nd_reconstruct(ND_pairs d) |
|
Line 2059 ND_pairs nd_reconstruct(ND_pairs d) |
|
nd_red[i] = mr0; |
nd_red[i] = mr0; |
} |
} |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
NEWRHist(r); TD(r) = TD(nd_psh[i]); ndl_dup(obpe,DL(nd_psh[i]),DL(r)); |
NEWRHist(r); SG(r) = SG(nd_psh[i]); |
|
TD(r) = TD(nd_psh[i]); ndl_dup(obpe,DL(nd_psh[i]),DL(r)); |
nd_psh[i] = r; |
nd_psh[i] = r; |
} |
} |
if ( s0 ) NEXT(s) = 0; |
if ( s0 ) NEXT(s) = 0; |
Line 1935 int nd_sp(int mod,ND_pairs p,ND *rp) |
|
Line 2143 int nd_sp(int mod,ND_pairs p,ND *rp) |
|
unsigned int *lcm; |
unsigned int *lcm; |
int td; |
int td; |
|
|
p1 = nd_ps[p->i1]; |
if ( mod ) { |
p2 = nd_ps[p->i2]; |
p1 = nd_ps[p->i1]; p2 = nd_ps[p->i2]; |
|
} else { |
|
p1 = nd_psq[p->i1]; p2 = nd_psq[p->i2]; |
|
} |
lcm = p->lcm; |
lcm = p->lcm; |
td = TD(p); |
td = TD(p); |
NEWNM(m); |
NEWNM(m); |
if ( mod ) CM(m) = HCM(p2); |
CQ(m) = HCQ(p2); |
else CQ(m) = HCQ(p2); |
|
TD(m) = td-HTD(p1); ndl_sub(lcm,HDL(p1),DL(m)); |
TD(m) = td-HTD(p1); ndl_sub(lcm,HDL(p1),DL(m)); |
if ( ndl_check_bound2(p->i1,DL(m)) ) |
if ( ndl_check_bound2(p->i1,DL(m)) ) |
return 0; |
return 0; |
Line 1957 int nd_sp(int mod,ND_pairs p,ND *rp) |
|
Line 2167 int nd_sp(int mod,ND_pairs p,ND *rp) |
|
} |
} |
ndv_mul_nm(mod,p2,m,ndv_red); |
ndv_mul_nm(mod,p2,m,ndv_red); |
FREENM(m); |
FREENM(m); |
if ( mod ) |
*rp = ndv_add(mod,t1,ndv_red); |
*rp = ndv_add(mod,t1,ndv_red); |
|
else |
|
*rp = ndv_add_q(t1,ndv_red); |
|
return 1; |
return 1; |
} |
} |
|
|
Line 2079 ND ndv_add(int mod,ND p1,NDV p2) |
|
Line 2286 ND ndv_add(int mod,ND p1,NDV p2) |
|
|
|
if ( !p1 ) |
if ( !p1 ) |
return 0; |
return 0; |
|
else if ( !mod ) |
|
return ndv_add_q(p1,p2); |
else { |
else { |
prev = 0; head = cur = BDY(p1); |
prev = 0; head = cur = BDY(p1); |
NEWNM(new); len = LEN(p2); |
NEWNM(new); len = LEN(p2); |
Line 2277 NDV dptondv(int mod,DP p) |
|
Line 2486 NDV dptondv(int mod,DP p) |
|
NDV d; |
NDV d; |
NMV m0,m; |
NMV m0,m; |
MP t; |
MP t; |
|
DP q; |
int l,i,n; |
int l,i,n; |
|
|
if ( !p ) |
if ( !p ) |
return 0; |
return 0; |
for ( t = BDY(p), l = 0; t; t = NEXT(t), l++ ); |
for ( t = BDY(p), l = 0; t; t = NEXT(t), l++ ); |
if ( mod ) |
if ( mod ) { |
|
_dp_mod(p,mod,0,&q); p = q; |
m0 = m = (NMV)MALLOC_ATOMIC(l*nmv_adv); |
m0 = m = (NMV)MALLOC_ATOMIC(l*nmv_adv); |
else |
} else |
m0 = m = (NMV)MALLOC(l*nmv_adv); |
m0 = m = (NMV)MALLOC(l*nmv_adv); |
n = NV(p); |
n = NV(p); |
for ( t = BDY(p), i = 0; i < l; i++, t = NEXT(t), NMV_ADV(m) ) { |
for ( t = BDY(p), i = 0; i < l; i++, t = NEXT(t), NMV_ADV(m) ) { |