version 1.13, 2003/07/21 01:57:51 |
version 1.15, 2003/07/22 10:00:51 |
|
|
* 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/distm.c,v 1.12 2003/07/20 08:55:23 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/distm.c,v 1.14 2003/07/22 07:12:41 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 896 void adddl_dup(int n,DL d1,DL d2,DL *dr) |
|
Line 896 void adddl_dup(int n,DL d1,DL d2,DL *dr) |
|
#define INLINE |
#define INLINE |
#endif |
#endif |
|
|
|
#define REDTAB_LEN 32003 |
|
|
typedef struct oPGeoBucket { |
typedef struct oPGeoBucket { |
int m; |
int m; |
struct oND *body[32]; |
struct oND *body[32]; |
Line 921 typedef struct oND_pairs { |
|
Line 923 typedef struct oND_pairs { |
|
unsigned int lcm[1]; |
unsigned int lcm[1]; |
} *ND_pairs; |
} *ND_pairs; |
|
|
static ND *nps; |
static ND *nd_ps; |
|
static unsigned int **nd_bound; |
int nd_mod,nd_nvar; |
int nd_mod,nd_nvar; |
int is_rlex; |
int is_rlex; |
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; |
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; |
|
NM *nd_red; |
|
int nd_red_len; |
|
|
extern int Top,Reverse; |
extern int Top,Reverse; |
int nd_psn,nd_pslen; |
int nd_psn,nd_pslen; |
|
int nd_found,nd_create,nd_notfirst; |
|
|
void GC_gcollect(); |
void GC_gcollect(); |
NODE append_one(NODE,int); |
NODE append_one(NODE,int); |
Line 950 if(!(r)){NEWNM(r);(c)=(r);}else{NEWNM(NEXT(c));(c)=NEX |
|
Line 956 if(!(r)){NEWNM(r);(c)=(r);}else{NEWNM(NEXT(c));(c)=NEX |
|
#define NEXTNM2(r,c,s) \ |
#define NEXTNM2(r,c,s) \ |
if(!(r)){(c)=(r)=(s);}else{NEXT(c)=(s);(c)=(s);} |
if(!(r)){(c)=(r)=(s);}else{NEXT(c)=(s);(c)=(s);} |
#define FREENM(m) NEXT(m)=_nm_free_list; _nm_free_list=(m) |
#define FREENM(m) NEXT(m)=_nm_free_list; _nm_free_list=(m) |
|
#define FREENDP(m) NEXT(m)=_ndp_free_list; _ndp_free_list=(m) |
#define FREEND(m) BDY(m)=(NM)_nd_free_list; _nd_free_list=(m) |
#define FREEND(m) BDY(m)=(NM)_nd_free_list; _nd_free_list=(m) |
|
|
#define NEXTND_pairs(r,c) \ |
#define NEXTND_pairs(r,c) \ |
Line 975 int ndl_td(unsigned int *d); |
|
Line 982 int ndl_td(unsigned int *d); |
|
ND nd_add(ND p1,ND p2); |
ND nd_add(ND p1,ND p2); |
ND nd_mul_nm(ND p,NM m0); |
ND nd_mul_nm(ND p,NM m0); |
ND nd_mul_term(ND p,int td,unsigned int *d); |
ND nd_mul_term(ND p,int td,unsigned int *d); |
ND nd_sp(ND_pairs p); |
int nd_sp(ND_pairs p,ND *nf); |
ND nd_find_reducer(ND g); |
int nd_find_reducer(ND g,ND *red); |
ND nd_nf(ND g,int full); |
int nd_nf(ND g,int full,ND *nf); |
|
ND nd_reduce(ND p1,ND p2); |
|
ND nd_reduce_special(ND p1,ND p2); |
|
void nd_free(ND p); |
void ndl_print(unsigned int *dl); |
void ndl_print(unsigned int *dl); |
void nd_print(ND p); |
void nd_print(ND 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(ND p); |
void nd_monic(ND p); |
void nd_mul_c(ND p,int mul); |
void nd_mul_c(ND p,int mul); |
|
void nd_free_redlist(); |
|
void nd_append_red(unsigned int *d,int td,int i); |
|
unsigned int *nd_compute_bound(ND p); |
|
ND_pairs nd_reconstruct(ND_pairs); |
|
void nd_setup_parameters(); |
|
ND nd_dup(ND p,int obpe); |
|
void ndl_dup(int obpe,unsigned int *d,unsigned int *r); |
|
|
void nd_free_private_storage() |
void nd_free_private_storage() |
{ |
{ |
_nd_free_list = 0; |
_nd_free_list = 0; |
_nm_free_list = 0; |
_nm_free_list = 0; |
|
nd_red = 0; |
GC_gcollect(); |
GC_gcollect(); |
} |
} |
|
|
Line 997 void _NM_alloc() |
|
Line 1015 void _NM_alloc() |
|
NM p; |
NM p; |
int i; |
int i; |
|
|
for ( i = 0; i < 10240; i++ ) { |
for ( i = 0; i < 16; i++ ) { |
p = (NM)GC_malloc(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
p = (NM)GC_malloc(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
p->next = _nm_free_list; _nm_free_list = p; |
p->next = _nm_free_list; _nm_free_list = p; |
} |
} |
Line 1209 INLINE void ndl_add(unsigned int *d1,unsigned int *d2, |
|
Line 1227 INLINE void ndl_add(unsigned int *d1,unsigned int *d2, |
|
{ |
{ |
int i; |
int i; |
|
|
for ( i = 0; i < nd_wpd; i++ ) |
for ( i = 0; i < nd_wpd; i++ ) { |
d[i] = d1[i]+d2[i]; |
d[i] = d1[i]+d2[i]; |
|
} |
} |
} |
|
|
void ndl_sub(unsigned int *d1,unsigned int *d2,unsigned int *d) |
void ndl_sub(unsigned int *d1,unsigned int *d2,unsigned int *d) |
Line 1388 ND nd_reduce(ND p1,ND p2) |
|
Line 1407 ND nd_reduce(ND p1,ND p2) |
|
} |
} |
} |
} |
|
|
ND nd_sp(ND_pairs p) |
/* HDL(p1) = HDL(p2) */ |
|
|
|
ND nd_reduce_special(ND p1,ND p2) |
{ |
{ |
|
int c,c1,c2,t,td,td2,mul; |
|
NM m2,prev,head,cur,new; |
|
|
|
if ( !p1 ) |
|
return 0; |
|
else { |
|
c2 = invm(HC(p2),nd_mod); |
|
c1 = nd_mod-HC(p1); |
|
DMAR(c1,c2,0,nd_mod,mul); |
|
prev = 0; head = cur = BDY(p1); |
|
NEWNM(new); |
|
for ( m2 = BDY(p2); m2; ) { |
|
td2 = new->td = m2->td; |
|
if ( !cur ) { |
|
c1 = C(m2); |
|
DMAR(c1,mul,0,nd_mod,c2); |
|
C(new) = c2; |
|
bcopy(m2->dl,new->dl,nd_wpd*sizeof(unsigned int)); |
|
if ( !prev ) { |
|
prev = new; |
|
NEXT(prev) = 0; |
|
head = prev; |
|
} else { |
|
NEXT(prev) = new; |
|
NEXT(new) = 0; |
|
prev = new; |
|
} |
|
m2 = NEXT(m2); |
|
NEWNM(new); |
|
continue; |
|
} |
|
if ( cur->td > td2 ) |
|
c = 1; |
|
else if ( cur->td < td2 ) |
|
c = -1; |
|
else |
|
c = ndl_compare(cur->dl,m2->dl); |
|
switch ( c ) { |
|
case 0: |
|
c2 = C(m2); |
|
c1 = C(cur); |
|
DMAR(c2,mul,c1,nd_mod,t); |
|
if ( t ) |
|
C(cur) = t; |
|
else if ( !prev ) { |
|
head = NEXT(cur); |
|
FREENM(cur); |
|
cur = head; |
|
} else { |
|
NEXT(prev) = NEXT(cur); |
|
FREENM(cur); |
|
cur = NEXT(prev); |
|
} |
|
m2 = NEXT(m2); |
|
break; |
|
case 1: |
|
prev = cur; |
|
cur = NEXT(cur); |
|
break; |
|
case -1: |
|
bcopy(m2->dl,new->dl,nd_wpd*sizeof(unsigned int)); |
|
if ( !prev ) { |
|
/* cur = head */ |
|
prev = new; |
|
c2 = C(m2); |
|
DMAR(c2,mul,0,nd_mod,c1); |
|
C(prev) = c1; |
|
NEXT(prev) = head; |
|
head = prev; |
|
} else { |
|
c2 = C(m2); |
|
DMAR(c2,mul,0,nd_mod,c1); |
|
C(new) = c1; |
|
NEXT(prev) = new; |
|
NEXT(new) = cur; |
|
prev = new; |
|
} |
|
NEWNM(new); |
|
m2 = NEXT(m2); |
|
break; |
|
} |
|
} |
|
FREENM(new); |
|
if ( head ) { |
|
BDY(p1) = head; |
|
p1->sugar = MAX(p1->sugar,p2->sugar+td); |
|
return p1; |
|
} else { |
|
FREEND(p1); |
|
return 0; |
|
} |
|
|
|
} |
|
} |
|
|
|
INLINE int ndl_check_bound(unsigned int *d) |
|
{ |
|
int i; |
|
|
|
for ( i = 0; i < nd_wpd; i++ ) |
|
if ( d[i] & nd_mask1 ) |
|
return 1; |
|
return 0; |
|
} |
|
|
|
int nd_sp(ND_pairs p,ND *rp) |
|
{ |
NM m; |
NM m; |
ND p1,p2,t1,t2; |
ND p1,p2,t1,t2; |
unsigned int *lcm; |
unsigned int *lcm,*check; |
int td; |
int td; |
|
|
p1 = nps[p->i1]; |
check = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
p2 = nps[p->i2]; |
p1 = nd_ps[p->i1]; |
|
p2 = nd_ps[p->i2]; |
lcm = p->lcm; |
lcm = p->lcm; |
td = p->td; |
td = p->td; |
NEWNM(m); |
NEWNM(m); |
C(m) = HC(p2); m->td = td-HTD(p1); ndl_sub(lcm,HDL(p1),m->dl); NEXT(m) = 0; |
C(m) = HC(p2); m->td = td-HTD(p1); ndl_sub(lcm,HDL(p1),m->dl); NEXT(m) = 0; |
|
ndl_add(nd_bound[p->i1],m->dl,check); |
|
if ( ndl_check_bound(check) ) |
|
return 0; |
t1 = nd_mul_nm(p1,m); |
t1 = nd_mul_nm(p1,m); |
C(m) = nd_mod-HC(p1); m->td = td-HTD(p2); ndl_sub(lcm,HDL(p2),m->dl); |
C(m) = nd_mod-HC(p1); m->td = td-HTD(p2); ndl_sub(lcm,HDL(p2),m->dl); |
|
ndl_add(nd_bound[p->i2],m->dl,check); |
|
if ( ndl_check_bound(check) ) { |
|
nd_free(t1); |
|
return 0; |
|
} |
t2 = nd_mul_nm(p2,m); |
t2 = nd_mul_nm(p2,m); |
FREENM(m); |
FREENM(m); |
return nd_add(t1,t2); |
*rp = nd_add(t1,t2); |
|
return 1; |
} |
} |
|
|
ND nd_find_reducer(ND g) |
int ndl_hash_value(int td,unsigned int *d) |
{ |
{ |
|
int i; |
|
int r; |
|
|
|
r = td; |
|
for ( i = 0; i < nd_wpd; i++ ) |
|
r = ((r<<16)+d[i])%REDTAB_LEN; |
|
return r; |
|
} |
|
|
|
int nd_find_reducer(ND g, ND *rp) |
|
{ |
NM m; |
NM m; |
ND r,p; |
ND r,p; |
int i,c1,c2,c; |
int i,c1,c2,c; |
|
int d,k,append,index; |
|
unsigned int *check; |
|
NM t; |
|
|
|
d = ndl_hash_value(HTD(g),HDL(g)); |
|
for ( m = nd_red[d], k = 0; m; m = NEXT(m), k++ ) { |
|
if ( HTD(g) == m->td && ndl_equal(HDL(g),m->dl) ) { |
|
if ( k > 0 ) nd_notfirst++; |
|
index = m->c; |
|
append = 0; |
|
nd_found++; |
|
goto found; |
|
} |
|
} |
|
|
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
p = nps[i]; |
p = nd_ps[i]; |
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
#if 1 |
index = i; |
NEWNM(m); |
append = 1; |
c1 = invm(HC(p),nd_mod); |
nd_create++; |
c2 = nd_mod-HC(g); |
goto found; |
DMAR(c1,c2,0,nd_mod,c); |
|
C(m) = c; |
|
m->td = HTD(g)-HTD(p); |
|
ndl_sub(HDL(g),HDL(p),m->dl); |
|
NEXT(m) = 0; |
|
r = nd_mul_nm(p,m); |
|
FREENM(m); |
|
r->sugar = m->td + p->sugar; |
|
return r; |
|
#else |
|
return p; |
|
#endif |
|
} |
} |
} |
} |
return 0; |
return 0; |
|
|
|
found: |
|
NEWNM(m); |
|
p = nd_ps[index]; |
|
ndl_sub(HDL(g),HDL(p),m->dl); |
|
|
|
check = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
|
ndl_add(nd_bound[index],m->dl,check); |
|
if ( ndl_check_bound(check) ) { |
|
FREENM(m); |
|
return -1; |
|
} |
|
|
|
c1 = invm(HC(p),nd_mod); |
|
c2 = nd_mod-HC(g); |
|
DMAR(c1,c2,0,nd_mod,c); |
|
C(m) = c; |
|
m->td = HTD(g)-HTD(p); |
|
NEXT(m) = 0; |
|
*rp = r = nd_mul_nm(p,m); |
|
FREENM(m); |
|
|
|
if ( append ) nd_append_red(HDL(g),HTD(g),i); |
|
return 1; |
} |
} |
|
|
ND nd_find_monic_reducer(ND g) |
ND nd_find_monic_reducer(ND g) |
Line 1445 ND nd_find_monic_reducer(ND g) |
|
Line 1620 ND nd_find_monic_reducer(ND g) |
|
int i; |
int i; |
|
|
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
p = nps[i]; |
p = nd_ps[i]; |
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
d = (int *)ALLOCA(nd_wpd*sizeof(int)); |
d = (int *)ALLOCA(nd_wpd*sizeof(int)); |
ndl_sub(HDL(g),HDL(p),d); |
ndl_sub(HDL(g),HDL(p),d); |
Line 1555 ND nd_mul_term(ND p,int td,unsigned int *d) |
|
Line 1730 ND nd_mul_term(ND p,int td,unsigned int *d) |
|
return 0; |
return 0; |
else { |
else { |
n = NV(p); m = BDY(p); |
n = NV(p); m = BDY(p); |
mr0 = 0; |
for ( mr0 = 0; m; m = NEXT(m) ) { |
for ( ; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
NEXTNM(mr0,mr); |
C(mr) = C(m); |
C(mr) = C(m); |
mr->td = m->td+td; |
mr->td = m->td+td; |
Line 1570 ND nd_mul_term(ND p,int td,unsigned int *d) |
|
Line 1744 ND nd_mul_term(ND p,int td,unsigned int *d) |
|
} |
} |
|
|
#if 1 |
#if 1 |
ND nd_nf(ND g,int full) |
/* ret=1 : success, ret=0 : overflow */ |
|
int nd_nf(ND g,int full,ND *rp) |
{ |
{ |
ND p,d,red; |
ND p,d,red; |
NM m,mrd,tail; |
NM m,mrd,tail; |
int n,sugar,psugar; |
int n,sugar,psugar,stat; |
|
|
if ( !g ) |
if ( !g ) { |
return 0; |
*rp = 0; |
|
return 1; |
|
} |
sugar = g->sugar; |
sugar = g->sugar; |
n = NV(g); |
n = NV(g); |
for ( d = 0; g; ) { |
for ( d = 0; g; ) { |
red = nd_find_reducer(g); |
/* stat=1 : found, stat=0 : not found, stat=-1 : overflow */ |
if ( red ) { |
stat = nd_find_reducer(g,&red); |
|
if ( stat == 1 ) { |
#if 1 |
#if 1 |
g = nd_add(g,red); |
g = nd_add(g,red); |
sugar = MAX(sugar,red->sugar); |
sugar = MAX(sugar,red->sugar); |
Line 1591 ND nd_nf(ND g,int full) |
|
Line 1769 ND nd_nf(ND g,int full) |
|
g = nd_reduce(g,red); |
g = nd_reduce(g,red); |
sugar = MAX(sugar,psugar); |
sugar = MAX(sugar,psugar); |
#endif |
#endif |
} else if ( !full ) |
} else if ( stat == -1 ) { |
return g; |
nd_free(g); |
else { |
nd_free(d); |
|
return 0; |
|
} else if ( !full ) { |
|
*rp = g; |
|
return 1; |
|
} else { |
m = BDY(g); |
m = BDY(g); |
if ( NEXT(m) ) { |
if ( NEXT(m) ) { |
BDY(g) = NEXT(m); NEXT(m) = 0; |
BDY(g) = NEXT(m); NEXT(m) = 0; |
Line 1611 ND nd_nf(ND g,int full) |
|
Line 1794 ND nd_nf(ND g,int full) |
|
} |
} |
if ( d ) |
if ( d ) |
d->sugar = sugar; |
d->sugar = sugar; |
return d; |
*rp = d; |
|
return 1; |
} |
} |
#else |
#else |
|
|
Line 1775 ND nd_nf(ND g,int full) |
|
Line 1959 ND nd_nf(ND g,int full) |
|
|
|
NODE nd_gb(NODE f) |
NODE nd_gb(NODE f) |
{ |
{ |
int i,nh; |
int i,nh,sugar,stat; |
NODE r,g,gall; |
NODE r,g,gall; |
ND_pairs d; |
ND_pairs d; |
ND_pairs l; |
ND_pairs l; |
Line 1787 NODE nd_gb(NODE f) |
|
Line 1971 NODE nd_gb(NODE f) |
|
g = update_base(g,i); |
g = update_base(g,i); |
gall = append_one(gall,i); |
gall = append_one(gall,i); |
} |
} |
|
sugar = 0; |
while ( d ) { |
while ( d ) { |
#if 0 |
again: |
ndp_print(d); |
|
#endif |
|
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
h = nd_sp(l); |
if ( l->sugar != sugar ) { |
nf = nd_nf(h,!Top); |
sugar = l->sugar; |
if ( nf ) { |
fprintf(asir_out,"%d",sugar); |
|
} |
|
stat = nd_sp(l,&h); |
|
if ( !stat ) { |
|
d = nd_reconstruct(d); |
|
goto again; |
|
} |
|
stat = nd_nf(h,!Top,&nf); |
|
if ( !stat ) { |
|
d = nd_reconstruct(d); |
|
goto again; |
|
} else if ( nf ) { |
printf("+"); fflush(stdout); |
printf("+"); fflush(stdout); |
#if 0 |
|
ndl_print(HDL(nf)); fflush(stdout); |
|
#endif |
|
nh = nd_newps(nf); |
nh = nd_newps(nf); |
d = update_pairs(d,g,nh); |
d = update_pairs(d,g,nh); |
g = update_base(g,nh); |
g = update_base(g,nh); |
gall = append_one(gall,nh); |
gall = append_one(gall,nh); |
|
FREENDP(l); |
} else { |
} else { |
printf("."); fflush(stdout); |
printf("."); fflush(stdout); |
|
FREENDP(l); |
} |
} |
} |
} |
return g; |
return g; |
Line 1812 NODE nd_gb(NODE f) |
|
Line 2005 NODE nd_gb(NODE f) |
|
|
|
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; |
ND_pairs d1,nd,cur,head,prev,remove; |
|
|
if ( !g ) return d; |
if ( !g ) return d; |
d = crit_B(d,t); |
d = crit_B(d,t); |
Line 1822 ND_pairs update_pairs( ND_pairs d, NODE /* of index */ |
|
Line 2015 ND_pairs update_pairs( ND_pairs d, NODE /* of index */ |
|
prev = 0; cur = head = d1; |
prev = 0; cur = head = d1; |
while ( cur ) { |
while ( cur ) { |
if ( crit_2( cur->i1,cur->i2 ) ) { |
if ( crit_2( cur->i1,cur->i2 ) ) { |
|
remove = cur; |
if ( !prev ) { |
if ( !prev ) { |
head = cur = NEXT(cur); |
head = cur = NEXT(cur); |
} else { |
} else { |
cur = NEXT(prev) = NEXT(cur); |
cur = NEXT(prev) = NEXT(cur); |
} |
} |
|
FREENDP(remove); |
} else { |
} else { |
prev = cur; |
prev = cur; |
cur = NEXT(cur); |
cur = NEXT(cur); |
Line 1850 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 2045 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(nps[t]); |
dl = HDL(nd_ps[t]); |
td = HTD(nps[t]); |
td = HTD(nd_ps[t]); |
ts = nps[t]->sugar - td; |
ts = nd_ps[t]->sugar - 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(nps[r->i1]),dl,r->lcm); |
ndl_lcm(HDL(nd_ps[r->i1]),dl,r->lcm); |
r->td = ndl_td(r->lcm); |
r->td = ndl_td(r->lcm); |
s = nps[r->i1]->sugar-HTD(nps[r->i1]); |
s = nd_ps[r->i1]->sugar-HTD(nd_ps[r->i1]); |
r->sugar = MAX(s,ts) + r->td; |
r->sugar = MAX(s,ts) + r->td; |
} |
} |
NEXT(r) = 0; |
NEXT(r) = 0; |
Line 1868 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 2063 ND_pairs nd_newpairs( NODE g, int t ) |
|
|
|
ND_pairs crit_B( ND_pairs d, int s ) |
ND_pairs crit_B( ND_pairs d, int s ) |
{ |
{ |
ND_pairs cur,head,prev; |
ND_pairs cur,head,prev,remove; |
unsigned int *t,*tl,*lcm; |
unsigned int *t,*tl,*lcm; |
int td,tdl; |
int td,tdl; |
|
|
if ( !d ) return 0; |
if ( !d ) return 0; |
t = HDL(nps[s]); |
t = HDL(nd_ps[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(nps[cur->i1]),t,lcm),!ndl_equal(lcm,tl)) |
&& (ndl_lcm(HDL(nd_ps[cur->i1]),t,lcm),!ndl_equal(lcm,tl)) |
&& (ndl_lcm(HDL(nps[cur->i2]),t,lcm),!ndl_equal(lcm,tl)) ) { |
&& (ndl_lcm(HDL(nd_ps[cur->i2]),t,lcm),!ndl_equal(lcm,tl)) ) { |
|
remove = cur; |
if ( !prev ) { |
if ( !prev ) { |
head = cur = NEXT(cur); |
head = cur = NEXT(cur); |
} else { |
} else { |
cur = NEXT(prev) = NEXT(cur); |
cur = NEXT(prev) = NEXT(cur); |
} |
} |
|
FREENDP(remove); |
} else { |
} else { |
prev = cur; |
prev = cur; |
cur = NEXT(cur); |
cur = NEXT(cur); |
Line 1935 ND_pairs crit_M( ND_pairs d1 ) |
|
Line 2132 ND_pairs crit_M( ND_pairs d1 ) |
|
NEXT(p) = d3; |
NEXT(p) = d3; |
d3 = p; |
d3 = p; |
} |
} |
|
FREENDP(e); |
} |
} |
return dd; |
return dd; |
} |
} |
|
|
ND_pairs crit_F( ND_pairs d1 ) |
ND_pairs crit_F( ND_pairs d1 ) |
{ |
{ |
ND_pairs rest, head; |
ND_pairs rest, head,remove; |
ND_pairs last, p, r, w; |
ND_pairs last, p, r, w; |
int s; |
int s; |
|
|
for ( head = last = 0, p = d1; NEXT(p); ) { |
for ( head = last = 0, p = d1; NEXT(p); ) { |
r = w = equivalent_pairs(p,&rest); |
r = w = equivalent_pairs(p,&rest); |
s = r->sugar; |
s = r->sugar; |
while ( w = NEXT(w) ) |
w = NEXT(w); |
|
while ( w ) { |
if ( crit_2(w->i1,w->i2) ) { |
if ( crit_2(w->i1,w->i2) ) { |
r = w; |
r = w; |
|
w = NEXT(w); |
|
while ( w ) { |
|
remove = w; |
|
w = NEXT(w); |
|
FREENDP(remove); |
|
} |
break; |
break; |
} else if ( w->sugar < s ) { |
} else if ( w->sugar < s ) { |
|
FREENDP(r); |
r = w; |
r = w; |
s = r->sugar; |
s = r->sugar; |
|
w = NEXT(w); |
|
} else { |
|
remove = w; |
|
w = NEXT(w); |
|
FREENDP(remove); |
} |
} |
|
} |
if ( last ) NEXT(last) = r; |
if ( last ) NEXT(last) = r; |
else head = r; |
else head = r; |
NEXT(last = r) = 0; |
NEXT(last = r) = 0; |
Line 1969 ND_pairs crit_F( ND_pairs d1 ) |
|
Line 2181 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(nps[dp1]),HDL(nps[dp2])); |
return ndl_disjoint(HDL(nd_ps[dp1]),HDL(nd_ps[dp2])); |
} |
} |
|
|
static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest ) |
static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest ) |
Line 2003 NODE update_base(NODE nd,int ndp) |
|
Line 2215 NODE update_base(NODE nd,int ndp) |
|
NODE last, p, head; |
NODE last, p, head; |
int td,tdn; |
int td,tdn; |
|
|
dl = HDL(nps[ndp]); |
dl = HDL(nd_ps[ndp]); |
td = HTD(nps[ndp]); |
td = HTD(nd_ps[ndp]); |
for ( head = last = 0, p = nd; p; ) { |
for ( head = last = 0, p = nd; p; ) { |
dln = HDL(nps[(int)BDY(p)]); |
dln = HDL(nd_ps[(int)BDY(p)]); |
tdn = HTD(nps[(int)BDY(p)]); |
tdn = HTD(nd_ps[(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 2034 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 2246 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
lcm = m->lcm; |
lcm = m->lcm; |
s = m->sugar; |
s = m->sugar; |
td = m->td; |
td = m->td; |
len = nd_length(nps[m->i1])+nd_length(nps[m->i2]); |
len = nd_length(nd_ps[m->i1])+nd_length(nd_ps[m->i2]); |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) { |
for ( ml = 0, l = m; p; p = NEXT(l = p) ) { |
if (p->sugar < s) |
if (p->sugar < s) |
goto find; |
goto find; |
Line 2046 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 2258 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
if ( c < 0 ) |
if ( c < 0 ) |
goto find; |
goto find; |
else if ( c == 0 ) { |
else if ( c == 0 ) { |
tlen = nd_length(nps[p->i1])+nd_length(nps[p->i2]); |
tlen = nd_length(nd_ps[p->i1])+nd_length(nd_ps[p->i2]); |
if ( tlen < len ) |
if ( tlen < len ) |
goto find; |
goto find; |
} |
} |
Line 2074 int nd_newps(ND a) |
|
Line 2286 int nd_newps(ND a) |
|
{ |
{ |
if ( nd_psn == nd_pslen ) { |
if ( nd_psn == nd_pslen ) { |
nd_pslen *= 2; |
nd_pslen *= 2; |
nps = (ND *)REALLOC((char *)nps,nd_pslen*sizeof(ND)); |
nd_ps = (ND *)REALLOC((char *)nd_ps,nd_pslen*sizeof(ND)); |
|
nd_bound = (unsigned int **) |
|
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *)); |
} |
} |
nd_monic(a); |
nd_monic(a); |
nps[nd_psn] = a; |
nd_ps[nd_psn] = a; |
|
nd_bound[nd_psn] = nd_compute_bound(a); |
return nd_psn++; |
return nd_psn++; |
} |
} |
|
|
|
|
|
|
NODE nd_setup(NODE f) |
NODE nd_setup(NODE f) |
{ |
{ |
int i; |
int i,td; |
NODE s,s0,f0; |
NODE s,s0,f0; |
|
|
|
nd_found = 0; |
|
nd_notfirst = 0; |
|
nd_create = 0; |
#if 0 |
#if 0 |
f0 = f = NODE_sortb(f,1); |
f0 = f = NODE_sortb(f,1); |
#endif |
#endif |
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nps = (ND *)MALLOC(nd_pslen*sizeof(ND)); |
nd_ps = (ND *)MALLOC(nd_pslen*sizeof(ND)); |
|
nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *)); |
nd_bpe = 4; |
nd_bpe = 4; |
nd_epw = (sizeof(unsigned int)*8)/nd_bpe; |
nd_setup_parameters(); |
nd_wpd = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); |
|
if ( nd_bpe < 32 ) { |
|
nd_mask0 = (1<<nd_bpe)-1; |
|
} else { |
|
nd_mask0 = 0xffffffff; |
|
} |
|
bzero(nd_mask,sizeof(nd_mask)); |
|
for ( i = 0; i < nd_epw; i++ ) |
|
nd_mask[nd_epw-i-1] = (nd_mask0<<(i*nd_bpe)); |
|
nd_free_private_storage(); |
nd_free_private_storage(); |
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
nps[i] = dptond((DP)BDY(f)); |
nd_ps[i] = dptond((DP)BDY(f)); |
nd_monic(nps[i]); |
nd_monic(nd_ps[i]); |
|
nd_bound[i] = nd_compute_bound(nd_ps[i]); |
} |
} |
|
nd_red = (NM *)MALLOC(REDTAB_LEN*sizeof(NM)); |
for ( s0 = 0, i = 0; i < nd_psn; i++ ) { |
for ( s0 = 0, i = 0; i < nd_psn; i++ ) { |
NEXTNODE(s0,s); BDY(s) = (pointer)i; |
NEXTNODE(s0,s); BDY(s) = (pointer)i; |
} |
} |
Line 2156 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
Line 2368 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 = ndtodp(nps[(int)BDY(x)]); |
a = ndtodp(nd_ps[(int)BDY(x)]); |
_dtop_mod(CO,vv,a,(P *)&BDY(r)); |
_dtop_mod(CO,vv,a,(P *)&BDY(r)); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKLIST(*rp,r0); |
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) |
Line 2308 void nd_mul_c(ND p,int mul) |
|
Line 2522 void nd_mul_c(ND p,int mul) |
|
c1 = C(m); |
c1 = C(m); |
DMAR(c1,mul,0,nd_mod,c); |
DMAR(c1,mul,0,nd_mod,c); |
C(m) = c; |
C(m) = c; |
|
} |
|
} |
|
|
|
void nd_free(ND p) |
|
{ |
|
NM t,s; |
|
|
|
if ( !p ) |
|
return; |
|
t = BDY(p); |
|
while ( t ) { |
|
s = NEXT(t); |
|
FREENM(t); |
|
t = s; |
|
} |
|
FREEND(p); |
|
} |
|
|
|
void nd_append_red(unsigned int *d,int td,int i) |
|
{ |
|
NM m,m0; |
|
int h; |
|
|
|
NEWNM(m); |
|
h = ndl_hash_value(td,d); |
|
m->c = i; |
|
m->td = td; |
|
bcopy(d,m->dl,nd_wpd*sizeof(unsigned int)); |
|
NEXT(m) = nd_red[h]; |
|
nd_red[h] = m; |
|
} |
|
|
|
unsigned int *nd_compute_bound(ND p) |
|
{ |
|
unsigned int *d1,*d2,*t; |
|
NM m; |
|
|
|
if ( !p ) |
|
return 0; |
|
d1 = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
|
d2 = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
|
bcopy(HDL(p),d1,nd_wpd*sizeof(unsigned int)); |
|
for ( m = NEXT(BDY(p)); m; m = NEXT(m) ) { |
|
ndl_lcm(m->dl,d1,d2); |
|
t = d1; d1 = d2; d2 = t; |
|
} |
|
t = (unsigned int *)MALLOC_ATOMIC(nd_wpd*sizeof(unsigned int)); |
|
bcopy(d1,t,nd_wpd*sizeof(unsigned int)); |
|
return t; |
|
} |
|
|
|
void nd_setup_parameters() { |
|
int i; |
|
|
|
nd_epw = (sizeof(unsigned int)*8)/nd_bpe; |
|
nd_wpd = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); |
|
if ( nd_bpe < 32 ) { |
|
nd_mask0 = (1<<nd_bpe)-1; |
|
} else { |
|
nd_mask0 = 0xffffffff; |
|
} |
|
bzero(nd_mask,sizeof(nd_mask)); |
|
nd_mask1 = 0; |
|
for ( i = 0; i < nd_epw; i++ ) { |
|
nd_mask[nd_epw-i-1] = (nd_mask0<<(i*nd_bpe)); |
|
nd_mask1 |= (1<<(nd_bpe-1))<<(i*nd_bpe); |
|
} |
|
} |
|
|
|
ND_pairs nd_reconstruct(ND_pairs d) |
|
{ |
|
int i,obpe; |
|
NM prev_nm_free_list; |
|
ND_pairs s0,s,t,prev_ndp_free_list; |
|
|
|
obpe = nd_bpe; |
|
switch ( nd_bpe ) { |
|
case 4: nd_bpe = 6; break; |
|
case 6: nd_bpe = 8; break; |
|
case 8: nd_bpe = 16; break; |
|
case 16: nd_bpe = 32; break; |
|
} |
|
nd_setup_parameters(); |
|
prev_nm_free_list = _nm_free_list; |
|
prev_ndp_free_list = _ndp_free_list; |
|
_nm_free_list = 0; |
|
_ndp_free_list = 0; |
|
for ( i = 0; i < nd_psn; i++ ) { |
|
nd_ps[i] = nd_dup(nd_ps[i],obpe); |
|
nd_bound[i] = nd_compute_bound(nd_ps[i]); |
|
} |
|
s0 = 0; |
|
for ( t = d; t; t = NEXT(t) ) { |
|
NEXTND_pairs(s0,s); |
|
s->i1 = t->i1; |
|
s->i2 = t->i2; |
|
s->td = t->td; |
|
s->sugar = t->sugar; |
|
ndl_dup(obpe,t->lcm,s->lcm); |
|
} |
|
if ( s0 ) NEXT(s) = 0; |
|
prev_nm_free_list = 0; |
|
prev_ndp_free_list = 0; |
|
GC_gcollect(); |
|
return s0; |
|
} |
|
|
|
void ndl_dup(int obpe,unsigned int *d,unsigned int *r) |
|
{ |
|
int n,i,ei,oepw,cepw,cbpe; |
|
|
|
n = nd_nvar; |
|
oepw = (sizeof(unsigned int)*8)/obpe; |
|
cepw = nd_epw; |
|
cbpe = nd_bpe; |
|
if ( is_rlex ) |
|
for ( i = 0; i < n; i++ ) { |
|
ei = (d[(n-1-i)/oepw]>>((oepw-((n-1-i)%oepw)-1)*obpe)) |
|
&((1<<obpe)-1); |
|
r[(n-1-i)/cepw] |= (ei<<((cepw-((n-1-i)%cepw)-1)*cbpe)); |
|
} |
|
else |
|
for ( i = 0; i < n; i++ ) { |
|
ei = (d[i/oepw]>>((oepw-(i%oepw)-1)*obpe)) |
|
&((1<<obpe)-1); |
|
r[i/cepw] |= (ei<<((cepw-(i%cepw)-1)*cbpe)); |
|
} |
|
} |
|
|
|
ND nd_dup(ND p,int obpe) |
|
{ |
|
NM m,mr,mr0; |
|
int c,n; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
for ( mr0 = 0; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
|
C(mr) = C(m); |
|
mr->td = m->td; |
|
ndl_dup(obpe,m->dl,mr->dl); |
|
} |
|
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar; |
|
return r; |
} |
} |
} |
} |