version 1.11, 2003/07/18 10:13:13 |
version 1.16, 2003/07/22 10:11:43 |
|
|
* 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.10 2002/01/28 00:54:43 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/distm.c,v 1.15 2003/07/22 10:00:51 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_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 948 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 972 void _ND_alloc(); |
|
Line 981 void _ND_alloc(); |
|
int ndl_td(unsigned int *d); |
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_sp(ND_pairs p); |
ND nd_mul_term(ND p,int td,unsigned int *d); |
ND nd_reducer(ND p1,ND p2); |
int nd_sp(ND_pairs p,ND *nf); |
ND nd_nf(NODE b,ND g,ND *ps,int full); |
int nd_find_reducer(ND g,ND *red); |
|
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_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 993 void _NM_alloc() |
|
Line 1015 void _NM_alloc() |
|
NM p; |
NM p; |
int i; |
int i; |
|
|
for ( i = 0; i < 1024; 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 1015 void _NDP_alloc() |
|
Line 1037 void _NDP_alloc() |
|
ND_pairs p; |
ND_pairs p; |
int i; |
int i; |
|
|
for ( i = 0; i < 1024; i++ ) { |
for ( i = 0; i < 10240; i++ ) { |
p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs) |
p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs) |
+(nd_wpd-1)*sizeof(unsigned int)); |
+(nd_wpd-1)*sizeof(unsigned int)); |
p->next = _ndp_free_list; _ndp_free_list = p; |
p->next = _ndp_free_list; _ndp_free_list = p; |
Line 1038 INLINE nd_length(ND p) |
|
Line 1060 INLINE nd_length(ND p) |
|
INLINE int ndl_reducible(unsigned int *d1,unsigned int *d2) |
INLINE int ndl_reducible(unsigned int *d1,unsigned int *d2) |
{ |
{ |
unsigned int u1,u2; |
unsigned int u1,u2; |
int i; |
int i,j; |
|
|
switch ( nd_bpe ) { |
switch ( nd_bpe ) { |
case 4: |
case 4: |
Line 1055 INLINE int ndl_reducible(unsigned int *d1,unsigned int |
|
Line 1077 INLINE int ndl_reducible(unsigned int *d1,unsigned int |
|
} |
} |
return 1; |
return 1; |
break; |
break; |
|
case 6: |
|
for ( i = 0; i < nd_wpd; i++ ) { |
|
u1 = d1[i]; u2 = d2[i]; |
|
if ( (u1&0x3f000000) < (u2&0x3f000000) ) return 0; |
|
if ( (u1&0xfc0000) < (u2&0xfc0000) ) return 0; |
|
if ( (u1&0x3f000) < (u2&0x3f000) ) return 0; |
|
if ( (u1&0xfc0) < (u2&0xfc0) ) return 0; |
|
if ( (u1&0x3f) < (u2&0x3f) ) return 0; |
|
} |
|
return 1; |
|
break; |
case 8: |
case 8: |
for ( i = 0; i < nd_wpd; i++ ) { |
for ( i = 0; i < nd_wpd; i++ ) { |
u1 = d1[i]; u2 = d2[i]; |
u1 = d1[i]; u2 = d2[i]; |
Line 1079 INLINE int ndl_reducible(unsigned int *d1,unsigned int |
|
Line 1112 INLINE int ndl_reducible(unsigned int *d1,unsigned int |
|
return 1; |
return 1; |
break; |
break; |
default: |
default: |
error("ndl_reducible : not implemented yet"); |
for ( i = 0; i < nd_wpd; i++ ) { |
|
u1 = d1[i]; u2 = d2[i]; |
|
for ( j = 0; j < nd_epw; j++ ) |
|
if ( (u1&nd_mask[j]) < (u2&nd_mask[j]) ) return 0; |
|
} |
|
return 1; |
} |
} |
} |
} |
|
|
INLINE void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned int *d) |
void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned int *d) |
{ |
{ |
unsigned int t1,t2,u,u1,u2; |
unsigned int t1,t2,u,u1,u2; |
int i; |
int i,j; |
|
|
switch ( nd_bpe ) { |
switch ( nd_bpe ) { |
case 4: |
case 4: |
Line 1103 INLINE void ndl_lcm(unsigned int *d1,unsigned *d2,unsi |
|
Line 1141 INLINE void ndl_lcm(unsigned int *d1,unsigned *d2,unsi |
|
d[i] = u; |
d[i] = u; |
} |
} |
break; |
break; |
|
case 6: |
|
for ( i = 0; i < nd_wpd; i++ ) { |
|
u1 = d1[i]; u2 = d2[i]; |
|
t1 = (u1&0x3f000000); t2 = (u2&0x3f000000); u = t1>t2?t1:t2; |
|
t1 = (u1&0xfc0000); t2 = (u2&0xfc0000); u |= t1>t2?t1:t2; |
|
t1 = (u1&0x3f000); t2 = (u2&0x3f000); u |= t1>t2?t1:t2; |
|
t1 = (u1&0xfc0); t2 = (u2&0xfc0); u |= t1>t2?t1:t2; |
|
t1 = (u1&0x3f); t2 = (u2&0x3f); u |= t1>t2?t1:t2; |
|
d[i] = u; |
|
} |
|
break; |
case 8: |
case 8: |
for ( i = 0; i < nd_wpd; i++ ) { |
for ( i = 0; i < nd_wpd; i++ ) { |
u1 = d1[i]; u2 = d2[i]; |
u1 = d1[i]; u2 = d2[i]; |
Line 1128 INLINE void ndl_lcm(unsigned int *d1,unsigned *d2,unsi |
|
Line 1177 INLINE void ndl_lcm(unsigned int *d1,unsigned *d2,unsi |
|
} |
} |
break; |
break; |
default: |
default: |
error("ndl_lcm : not implemented yet"); |
for ( i = 0; i < nd_wpd; i++ ) { |
|
u1 = d1[i]; u2 = d2[i]; |
|
for ( j = 0, u = 0; j < nd_epw; j++ ) { |
|
t1 = (u1&nd_mask[j]); t2 = (u2&nd_mask[j]); u |= t1>t2?t1:t2; |
|
} |
|
d[i] = u; |
|
} |
|
break; |
} |
} |
} |
} |
|
|
INLINE int ndl_td(unsigned int *d) |
int ndl_td(unsigned int *d) |
{ |
{ |
unsigned int t,u; |
unsigned int t,u; |
int i; |
int i,j; |
|
|
switch ( nd_bpe ) { |
for ( t = 0, i = 0; i < nd_wpd; i++ ) { |
case 4: |
u = d[i]; |
for ( t = 0, i = 0; i < nd_wpd; i++ ) { |
for ( j = 0; j < nd_epw; j++, u>>=nd_bpe ) |
u = d[i]; |
t += (u&nd_mask0); |
t += ((u&0xf0000000)>>28)+((u&0xf000000)>>24) |
|
+((u&0xf00000)>>20)+((u&0xf0000)>>16) |
|
+((u&0xf000)>>12)+((u&0xf00)>>8)+((u&0xf0)>>4)+(u&0xf); |
|
} |
|
break; |
|
case 8: |
|
for ( t = 0, i = 0; i < nd_wpd; i++ ) { |
|
u = d[i]; |
|
t += ((u&0xff000000)>>24)+((u&0xff0000)>>16) |
|
+((u&0xff00)>>8)+(u&0xff); |
|
} |
|
break; |
|
case 16: |
|
for ( t = 0, i = 0; i < nd_wpd; i++ ) { |
|
u = d[i]; |
|
t += ((u&0xffff0000)>>16)+(u&0xffff); |
|
} |
|
break; |
|
case 32: |
|
for ( t = 0, i = 0; i < nd_wpd; i++ ) |
|
t += d[i]; |
|
break; |
|
default: |
|
error("ndl_td : not implemented yet"); |
|
} |
} |
return t; |
return t; |
} |
} |
Line 1173 INLINE int ndl_compare(unsigned int *d1,unsigned int * |
|
Line 1205 INLINE int ndl_compare(unsigned int *d1,unsigned int * |
|
{ |
{ |
int i; |
int i; |
|
|
for ( i = 0; i < nd_wpd; i++ ) |
for ( i = 0; i < nd_wpd; i++, d1++, d2++ ) |
if ( d1[i] > d2[i] ) |
if ( *d1 > *d2 ) |
return is_rlex ? -1 : 1; |
return is_rlex ? -1 : 1; |
else if ( d1[i] < d2[i] ) |
else if ( *d1 < *d2 ) |
return is_rlex ? 1 : -1; |
return is_rlex ? 1 : -1; |
return 0; |
return 0; |
} |
} |
Line 1195 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]; |
|
} |
} |
} |
|
|
INLINE void ndl_sub(unsigned int *d1,unsigned int *d2,unsigned int *d) |
void ndl_sub(unsigned int *d1,unsigned int *d2,unsigned int *d) |
{ |
{ |
int i; |
int i; |
|
|
Line 1207 INLINE void ndl_sub(unsigned int *d1,unsigned int *d2, |
|
Line 1240 INLINE void ndl_sub(unsigned int *d1,unsigned int *d2, |
|
d[i] = d1[i]-d2[i]; |
d[i] = d1[i]-d2[i]; |
} |
} |
|
|
INLINE int ndl_disjoint(unsigned int *d1,unsigned int *d2) |
int ndl_disjoint(unsigned int *d1,unsigned int *d2) |
{ |
{ |
unsigned int t1,t2,u,u1,u2; |
unsigned int t1,t2,u,u1,u2; |
int i; |
int i,j; |
|
|
switch ( nd_bpe ) { |
switch ( nd_bpe ) { |
case 4: |
case 4: |
Line 1227 INLINE int ndl_disjoint(unsigned int *d1,unsigned int |
|
Line 1260 INLINE int ndl_disjoint(unsigned int *d1,unsigned int |
|
} |
} |
return 1; |
return 1; |
break; |
break; |
|
case 6: |
|
for ( i = 0; i < nd_wpd; i++ ) { |
|
u1 = d1[i]; u2 = d2[i]; |
|
t1 = u1&0x3f000000; t2 = u2&0x3f000000; if ( t1&&t2 ) return 0; |
|
t1 = u1&0xfc0000; t2 = u2&0xfc0000; if ( t1&&t2 ) return 0; |
|
t1 = u1&0x3f000; t2 = u2&0x3f000; if ( t1&&t2 ) return 0; |
|
t1 = u1&0xfc0; t2 = u2&0xfc0; if ( t1&&t2 ) return 0; |
|
t1 = u1&0x3f; t2 = u2&0x3f; if ( t1&&t2 ) return 0; |
|
} |
|
return 1; |
|
break; |
case 8: |
case 8: |
for ( i = 0; i < nd_wpd; i++ ) { |
for ( i = 0; i < nd_wpd; i++ ) { |
u1 = d1[i]; u2 = d2[i]; |
u1 = d1[i]; u2 = d2[i]; |
Line 1251 INLINE int ndl_disjoint(unsigned int *d1,unsigned int |
|
Line 1295 INLINE int ndl_disjoint(unsigned int *d1,unsigned int |
|
return 1; |
return 1; |
break; |
break; |
default: |
default: |
error("ndl_disjoint : not implemented yet"); |
for ( i = 0; i < nd_wpd; i++ ) { |
|
u1 = d1[i]; u2 = d2[i]; |
|
for ( j = 0; j < nd_epw; j++ ) { |
|
if ( (u1&nd_mask0) && (u2&nd_mask0) ) return 0; |
|
u1 >>= nd_bpe; u2 >>= nd_bpe; |
|
} |
|
} |
|
return 1; |
|
break; |
} |
} |
} |
} |
|
|
ND nd_add(ND p1,ND p2) |
ND nd_reduce(ND p1,ND p2) |
{ |
{ |
int n,c; |
int c,c1,c2,t,td,td2,mul; |
int t; |
NM m2,prev,head,cur,new; |
ND r; |
unsigned int *d; |
NM m1,m2,mr0,mr,s; |
|
|
|
if ( !p1 ) |
if ( !p1 ) |
return p2; |
return 0; |
else if ( !p2 ) |
|
return p1; |
|
else { |
else { |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) { |
c2 = invm(HC(p2),nd_mod); |
if ( m1->td > m2->td ) |
c1 = nd_mod-HC(p1); |
|
DMAR(c1,c2,0,nd_mod,mul); |
|
td = HTD(p1)-HTD(p2); |
|
d = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
|
ndl_sub(HDL(p1),HDL(p2),d); |
|
prev = 0; head = cur = BDY(p1); |
|
NEWNM(new); |
|
for ( m2 = BDY(p2); m2; ) { |
|
td2 = new->td = m2->td+td; |
|
ndl_add(m2->dl,d,new->dl); |
|
if ( !cur ) { |
|
c1 = C(m2); |
|
DMAR(c1,mul,0,nd_mod,c2); |
|
C(new) = c2; |
|
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; |
c = 1; |
else if ( m1->td < m2->td ) |
else if ( cur->td < td2 ) |
c = -1; |
c = -1; |
else |
else |
c = ndl_compare(m1->dl,m2->dl); |
c = ndl_compare(cur->dl,new->dl); |
switch ( c ) { |
switch ( c ) { |
case 0: |
case 0: |
t = ((C(m1))+(C(m2))) - nd_mod; |
c2 = C(m2); |
if ( t < 0 ) |
c1 = C(cur); |
t += nd_mod; |
DMAR(c2,mul,c1,nd_mod,t); |
s = m1; m1 = NEXT(m1); |
if ( t ) |
if ( t ) { |
C(cur) = t; |
NEXTNM2(mr0,mr,s); C(mr) = (t); |
else if ( !prev ) { |
|
head = NEXT(cur); |
|
FREENM(cur); |
|
cur = head; |
} else { |
} else { |
FREENM(s); |
NEXT(prev) = NEXT(cur); |
|
FREENM(cur); |
|
cur = NEXT(prev); |
} |
} |
s = m2; m2 = NEXT(m2); FREENM(s); |
m2 = NEXT(m2); |
break; |
break; |
case 1: |
case 1: |
s = m1; m1 = NEXT(m1); NEXTNM2(mr0,mr,s); |
prev = cur; |
|
cur = NEXT(cur); |
break; |
break; |
case -1: |
case -1: |
s = m2; m2 = NEXT(m2); NEXTNM2(mr0,mr,s); |
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; |
break; |
} |
} |
} |
} |
if ( !mr0 ) |
FREENM(new); |
if ( m1 ) |
if ( head ) { |
mr0 = m1; |
BDY(p1) = head; |
else if ( m2 ) |
p1->sugar = MAX(p1->sugar,p2->sugar+td); |
mr0 = m2; |
return p1; |
else |
} else { |
return 0; |
FREEND(p1); |
else if ( m1 ) |
return 0; |
NEXT(mr) = m1; |
|
else if ( m2 ) |
|
NEXT(mr) = m2; |
|
else |
|
NEXT(mr) = 0; |
|
BDY(p1) = mr0; |
|
p1->sugar = MAX(p1->sugar,p2->sugar); |
|
FREEND(p2); |
|
return p1; |
|
} |
|
} |
|
|
|
INLINE ND nd_mul_nm(ND p,NM m0) |
|
{ |
|
NM m,mr,mr0; |
|
unsigned int *d,*dt,*dm; |
|
int c,n,td; |
|
int *pt,*p1,*p2; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
mr0 = 0; |
|
for ( ; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
|
C(mr) = (C(m)*c)%nd_mod; |
|
mr->td = m->td+td; |
|
ndl_add(m->dl,d,mr->dl); |
|
} |
} |
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
} |
} |
} |
|
|
ND nd_reduce(ND p1,ND p2) |
/* HDL(p1) = HDL(p2) */ |
|
|
|
ND nd_reduce_special(ND p1,ND p2) |
{ |
{ |
int c,t,td,td2,mul; |
int c,c1,c2,t,td,td2,mul; |
NM m2,prev,head,cur,new; |
NM m2,prev,head,cur,new; |
unsigned int *d; |
|
|
|
if ( !p1 ) |
if ( !p1 ) |
return 0; |
return 0; |
else { |
else { |
mul = ((nd_mod-HC(p1))*invm(HC(p2),nd_mod))%nd_mod; |
c2 = invm(HC(p2),nd_mod); |
td = HTD(p1)-HTD(p2); |
c1 = nd_mod-HC(p1); |
d = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int)); |
DMAR(c1,c2,0,nd_mod,mul); |
ndl_sub(HDL(p1),HDL(p2),d); |
|
prev = 0; head = cur = BDY(p1); |
prev = 0; head = cur = BDY(p1); |
NEWNM(new); |
NEWNM(new); |
for ( m2 = BDY(p2); m2; ) { |
for ( m2 = BDY(p2); m2; ) { |
td2 = new->td = m2->td+td; |
td2 = new->td = m2->td; |
ndl_add(m2->dl,d,new->dl); |
|
if ( !cur ) { |
if ( !cur ) { |
C(new) = (C(m2)*mul)%nd_mod; |
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 ) { |
if ( !prev ) { |
prev = new; |
prev = new; |
NEXT(prev) = 0; |
NEXT(prev) = 0; |
Line 1380 ND nd_reduce(ND p1,ND p2) |
|
Line 1447 ND nd_reduce(ND p1,ND p2) |
|
else if ( cur->td < td2 ) |
else if ( cur->td < td2 ) |
c = -1; |
c = -1; |
else |
else |
c = ndl_compare(cur->dl,new->dl); |
c = ndl_compare(cur->dl,m2->dl); |
switch ( c ) { |
switch ( c ) { |
case 0: |
case 0: |
t = (C(cur)+C(m2)*mul)%nd_mod; |
c2 = C(m2); |
|
c1 = C(cur); |
|
DMAR(c2,mul,c1,nd_mod,t); |
if ( t ) |
if ( t ) |
C(cur) = t; |
C(cur) = t; |
else if ( !prev ) { |
else if ( !prev ) { |
Line 1402 ND nd_reduce(ND p1,ND p2) |
|
Line 1471 ND nd_reduce(ND p1,ND p2) |
|
cur = NEXT(cur); |
cur = NEXT(cur); |
break; |
break; |
case -1: |
case -1: |
|
bcopy(m2->dl,new->dl,nd_wpd*sizeof(unsigned int)); |
if ( !prev ) { |
if ( !prev ) { |
/* cur = head */ |
/* cur = head */ |
prev = new; |
prev = new; |
C(prev) = (C(m2)*mul)%nd_mod; |
c2 = C(m2); |
|
DMAR(c2,mul,0,nd_mod,c1); |
|
C(prev) = c1; |
NEXT(prev) = head; |
NEXT(prev) = head; |
head = prev; |
head = prev; |
} else { |
} else { |
C(new) = (C(m2)*mul)%nd_mod; |
c2 = C(m2); |
|
DMAR(c2,mul,0,nd_mod,c1); |
|
C(new) = c1; |
NEXT(prev) = new; |
NEXT(prev) = new; |
NEXT(new) = cur; |
NEXT(new) = cur; |
prev = new; |
prev = new; |
Line 1432 ND nd_reduce(ND p1,ND p2) |
|
Line 1506 ND nd_reduce(ND p1,ND p2) |
|
} |
} |
} |
} |
|
|
ND nd_sp(ND_pairs p) |
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_reducer(ND p1,ND p2) |
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; |
ND r,p; |
|
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++ ) { |
|
p = nd_ps[i]; |
|
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
|
index = i; |
|
append = 1; |
|
nd_create++; |
|
goto found; |
|
} |
|
} |
|
return 0; |
|
|
|
found: |
NEWNM(m); |
NEWNM(m); |
C(m) = ((nd_mod-HC(p1))*invm(HC(p2),nd_mod))%nd_mod; |
p = nd_ps[index]; |
m->td = HTD(p1)-HTD(p2); |
ndl_sub(HDL(g),HDL(p),m->dl); |
ndl_sub(HDL(p1),HDL(p2),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; |
NEXT(m) = 0; |
r = nd_mul_nm(p2,m); |
*rp = r = nd_mul_nm(p,m); |
FREENM(m); |
FREENM(m); |
return r; |
|
|
if ( append ) nd_append_red(HDL(g),HTD(g),i); |
|
return 1; |
} |
} |
|
|
|
ND nd_find_monic_reducer(ND g) |
|
{ |
|
int *d; |
|
ND p,r; |
|
int i; |
|
|
|
for ( i = 0; i < nd_psn; i++ ) { |
|
p = nd_ps[i]; |
|
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
|
d = (int *)ALLOCA(nd_wpd*sizeof(int)); |
|
ndl_sub(HDL(g),HDL(p),d); |
|
r = nd_mul_term(p,HTD(g)-HTD(p),d); |
|
return r; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
ND nd_add(ND p1,ND p2) |
|
{ |
|
int n,c; |
|
int t; |
|
ND r; |
|
NM m1,m2,mr0,mr,s; |
|
|
|
if ( !p1 ) |
|
return p2; |
|
else if ( !p2 ) |
|
return p1; |
|
else { |
|
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) { |
|
if ( m1->td > m2->td ) |
|
c = 1; |
|
else if ( m1->td < m2->td ) |
|
c = -1; |
|
else |
|
c = ndl_compare(m1->dl,m2->dl); |
|
switch ( c ) { |
|
case 0: |
|
t = ((C(m1))+(C(m2))) - nd_mod; |
|
if ( t < 0 ) |
|
t += nd_mod; |
|
s = m1; m1 = NEXT(m1); |
|
if ( t ) { |
|
NEXTNM2(mr0,mr,s); C(mr) = (t); |
|
} else { |
|
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; |
|
p1->sugar = MAX(p1->sugar,p2->sugar); |
|
FREEND(p2); |
|
return p1; |
|
} |
|
} |
|
|
|
ND nd_mul_nm(ND p,NM m0) |
|
{ |
|
NM m,mr,mr0; |
|
unsigned int *d,*dt,*dm; |
|
int c,n,td,i,c1,c2; |
|
int *pt,*p1,*p2; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
mr0 = 0; |
|
for ( ; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
|
c1 = C(m); |
|
DMAR(c1,c,0,nd_mod,c2); |
|
C(mr) = c2; |
|
mr->td = m->td+td; |
|
ndl_add(m->dl,d,mr->dl); |
|
} |
|
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
|
} |
|
|
|
ND nd_mul_term(ND p,int td,unsigned int *d) |
|
{ |
|
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+td; |
|
ndl_add(m->dl,d,mr->dl); |
|
} |
|
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
|
} |
|
|
#if 1 |
#if 1 |
ND nd_nf(NODE b,ND g,ND *ps,int full) |
/* ret=1 : success, ret=0 : overflow */ |
|
int nd_nf(ND g,int full,ND *rp) |
{ |
{ |
ND u,p,d,red; |
ND p,d,red; |
NODE l; |
NM m,mrd,tail; |
NM m,mrd; |
int n,sugar,psugar,stat; |
int sugar,psugar,n,h_reducible; |
|
|
|
if ( !g ) { |
if ( !g ) { |
return 0; |
*rp = 0; |
|
return 1; |
} |
} |
sugar = g->sugar; |
sugar = g->sugar; |
n = g->nv; |
n = NV(g); |
for ( d = 0; g; ) { |
for ( d = 0; g; ) { |
for ( h_reducible = 0, l = b; l; l = NEXT(l) ) { |
/* stat=1 : found, stat=0 : not found, stat=-1 : overflow */ |
p = ps[(int)BDY(l)]; |
stat = nd_find_reducer(g,&red); |
if ( HTD(g)>=HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
if ( stat == 1 ) { |
h_reducible = 1; |
#if 1 |
psugar = HTD(g)-HTD(p) + p->sugar; |
g = nd_add(g,red); |
#if 0 |
sugar = MAX(sugar,red->sugar); |
red = nd_reducer(g,p); |
|
g = nd_add(g,red); |
|
#else |
#else |
g = nd_reduce(g,p); |
psugar = (HTD(g)-HTD(red))+red->sugar; |
|
g = nd_reduce(g,red); |
|
sugar = MAX(sugar,psugar); |
#endif |
#endif |
sugar = MAX(sugar,psugar); |
} else if ( stat == -1 ) { |
if ( !g ) { |
nd_free(g); |
if ( d ) |
nd_free(d); |
d->sugar = sugar; |
return 0; |
return d; |
} else if ( !full ) { |
} |
*rp = g; |
break; |
return 1; |
|
} else { |
|
m = BDY(g); |
|
if ( NEXT(m) ) { |
|
BDY(g) = NEXT(m); NEXT(m) = 0; |
|
} else { |
|
FREEND(g); g = 0; |
} |
} |
} |
if ( d ) { |
if ( !h_reducible ) { |
NEXT(tail)=m; |
/* head term is not reducible */ |
tail=m; |
if ( !full ) { |
|
if ( g ) |
|
g->sugar = sugar; |
|
return g; |
|
} else { |
} else { |
m = BDY(g); |
MKND(n,m,d); |
if ( NEXT(m) ) { |
tail = BDY(d); |
BDY(g) = NEXT(m); NEXT(m) = 0; |
|
} else { |
|
FREEND(g); g = 0; |
|
} |
|
if ( d ) { |
|
for ( mrd = BDY(d); NEXT(mrd); mrd = NEXT(mrd) ); |
|
NEXT(mrd) = m; |
|
} else { |
|
MKND(n,m,d); |
|
} |
|
} |
} |
} |
} |
} |
} |
if ( d ) |
if ( d ) |
d->sugar = sugar; |
d->sugar = sugar; |
return d; |
*rp = d; |
|
return 1; |
} |
} |
#else |
#else |
|
|
Line 1632 ND normalize_pbucket(PGeoBucket g) |
|
Line 1902 ND normalize_pbucket(PGeoBucket g) |
|
return r; |
return r; |
} |
} |
|
|
ND nd_nf(NODE b,ND g,ND *ps,int full) |
ND nd_nf(ND g,int full) |
{ |
{ |
ND u,p,d,red; |
ND u,p,d,red; |
NODE l; |
NODE l; |
Line 1656 ND nd_nf(NODE b,ND g,ND *ps,int full) |
|
Line 1926 ND nd_nf(NODE b,ND g,ND *ps,int full) |
|
return d; |
return d; |
} |
} |
g = bucket->body[h]; |
g = bucket->body[h]; |
for ( h_reducible = 0, l = b; l; l = NEXT(l) ) { |
red = nd_find_reducer(g); |
p = ps[(int)BDY(l)]; |
if ( red ) { |
if ( ndl_reducible(HDL(g),HDL(p)) ) { |
bucket->body[h] = nd_remove_head(g); |
h_reducible = 1; |
red = nd_remove_head(red); |
psugar = HTD(g)-HTD(p) + p->sugar; |
add_pbucket(bucket,red); |
red = nd_reducer(g,p); |
sugar = MAX(sugar,red->sugar); |
bucket->body[h] = nd_remove_head(g); |
} else if ( !full ) { |
red = nd_remove_head(red); |
g = normalize_pbucket(bucket); |
add_pbucket(bucket,red); |
if ( g ) |
sugar = MAX(sugar,psugar); |
g->sugar = sugar; |
break; |
return g; |
|
} else { |
|
m = BDY(g); |
|
if ( NEXT(m) ) { |
|
BDY(g) = NEXT(m); NEXT(m) = 0; |
|
} else { |
|
FREEND(g); g = 0; |
} |
} |
} |
bucket->body[h] = g; |
if ( !h_reducible ) { |
NEXT(m) = 0; |
/* head term is not reducible */ |
if ( d ) { |
if ( !full ) { |
for ( mrd = BDY(d); NEXT(mrd); mrd = NEXT(mrd) ); |
g = normalize_pbucket(bucket); |
NEXT(mrd) = m; |
if ( g ) |
|
g->sugar = sugar; |
|
return g; |
|
} else { |
} else { |
m = BDY(g); |
MKND(n,m,d); |
if ( NEXT(m) ) { |
|
BDY(g) = NEXT(m); NEXT(m) = 0; |
|
} else { |
|
FREEND(g); g = 0; |
|
} |
|
bucket->body[h] = g; |
|
NEXT(m) = 0; |
|
if ( d ) { |
|
for ( mrd = BDY(d); NEXT(mrd); mrd = NEXT(mrd) ); |
|
NEXT(mrd) = m; |
|
} else { |
|
MKND(n,m,d); |
|
} |
|
} |
} |
} |
} |
} |
} |
Line 1699 ND nd_nf(NODE b,ND g,ND *ps,int full) |
|
Line 1959 ND nd_nf(NODE b,ND g,ND *ps,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 1711 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(gall,h,nps,!Top); |
sugar = l->sugar; |
if ( nf ) { |
fprintf(asir_out,"%d",sugar); |
|
} |
|
stat = nd_sp(l,&h); |
|
if ( !stat ) { |
|
NEXT(l) = d; d = l; |
|
d = nd_reconstruct(d); |
|
goto again; |
|
} |
|
stat = nd_nf(h,!Top,&nf); |
|
if ( !stat ) { |
|
NEXT(l) = d; d = l; |
|
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 1736 NODE nd_gb(NODE f) |
|
Line 2007 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 1746 ND_pairs update_pairs( ND_pairs d, NODE /* of index */ |
|
Line 2017 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 1774 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 2047 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 1792 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 2065 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 1859 ND_pairs crit_M( ND_pairs d1 ) |
|
Line 2134 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 1893 ND_pairs crit_F( ND_pairs d1 ) |
|
Line 2183 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 1927 NODE update_base(NODE nd,int ndp) |
|
Line 2217 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 1958 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 2248 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 1970 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 2260 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 1998 int nd_newps(ND a) |
|
Line 2288 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); |
|
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 2072 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
Line 2370 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 2085 void dltondl(int n,DL dl,unsigned int *r) |
|
Line 2385 void dltondl(int n,DL dl,unsigned int *r) |
|
int i; |
int i; |
|
|
d = dl->d; |
d = dl->d; |
|
bzero(r,nd_wpd*sizeof(unsigned int)); |
if ( is_rlex ) |
if ( is_rlex ) |
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
r[(n-1-i)/nd_epw] |= (d[i]<<((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe)); |
r[(n-1-i)/nd_epw] |= (d[i]<<((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe)); |
Line 2206 void ndp_print(ND_pairs d) |
|
Line 2507 void ndp_print(ND_pairs d) |
|
|
|
void nd_monic(ND p) |
void nd_monic(ND p) |
{ |
{ |
int mul; |
if ( !p ) |
|
return; |
|
else |
|
nd_mul_c(p,invm(HC(p),nd_mod)); |
|
} |
|
|
|
void nd_mul_c(ND p,int mul) |
|
{ |
NM m; |
NM m; |
|
int c,c1; |
|
|
if ( !p ) |
if ( !p ) |
return; |
return; |
mul = invm(HC(p),nd_mod); |
for ( m = BDY(p); m; m = NEXT(m) ) { |
for ( m = BDY(p); m; m = NEXT(m) ) |
c1 = C(m); |
C(m) = (C(m)*mul)%nd_mod; |
DMAR(c1,mul,0,nd_mod,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; |
|
} |
} |
} |