===================================================================
RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/nd.c,v
retrieving revision 1.37
retrieving revision 1.41
diff -u -p -r1.37 -r1.41
--- OpenXM_contrib2/asir2000/engine/nd.c 2003/08/20 08:38:20 1.37
+++ OpenXM_contrib2/asir2000/engine/nd.c 2003/08/21 07:39:25 1.41
@@ -1,4 +1,4 @@
-/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.36 2003/08/20 07:55:45 noro Exp $ */
+/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.40 2003/08/21 04:44:36 noro Exp $ */
#include "ca.h"
#include "inline.h"
@@ -15,11 +15,14 @@
#define REDTAB_LEN 32003
+/* GeoBucket for polynomial addition */
+
typedef struct oPGeoBucket {
int m;
struct oND *body[32];
} *PGeoBucket;
+/* distributed polynomial; linked list rep. */
typedef struct oND {
struct oNM *body;
int nv;
@@ -27,6 +30,7 @@ typedef struct oND {
int sugar;
} *ND;
+/* distributed polynomial; array rep. */
typedef struct oNDV {
struct oNMV *body;
int nv;
@@ -34,6 +38,7 @@ typedef struct oNDV {
int sugar;
} *NDV;
+/* monomial; linked list rep. */
typedef struct oNM {
struct oNM *next;
union {
@@ -43,6 +48,7 @@ typedef struct oNM {
unsigned int dl[1];
} *NM;
+/* monomial; array rep. */
typedef struct oNMV {
union {
int m;
@@ -51,6 +57,7 @@ typedef struct oNMV {
unsigned int dl[1];
} *NMV;
+/* history of reducer */
typedef struct oRHist {
struct oRHist *next;
int index;
@@ -58,6 +65,7 @@ typedef struct oRHist {
unsigned int dl[1];
} *RHist;
+/* S-pair list */
typedef struct oND_pairs {
struct oND_pairs *next;
int i1,i2;
@@ -69,9 +77,10 @@ int (*nd_compare_function)(unsigned int *a1,unsigned i
double nd_scale=2;
static unsigned int **nd_bound;
+struct order_spec *nd_ord;
int nd_nvar;
int nd_isrlex;
-int nd_epw,nd_bpe,nd_wpd;
+int nd_epw,nd_bpe,nd_wpd,nd_exporigin;
unsigned int nd_mask[32];
unsigned int nd_mask0,nd_mask1;
@@ -85,7 +94,6 @@ RHist *nd_psh;
int nd_psn,nd_pslen;
RHist *nd_red;
-int nd_red_len;
int nd_found,nd_create,nd_notfirst;
int nm_adv;
@@ -94,6 +102,7 @@ int nd_dcomp;
extern int Top,Reverse,dp_nelim;
+/* fundamental macros */
#define TD(d) (d[0])
#define HDL(d) ((d)->body->dl)
#define HTD(d) (TD(HDL(d)))
@@ -106,15 +115,15 @@ extern int Top,Reverse,dp_nelim;
#define LEN(a) ((a)->len)
#define LCM(a) ((a)->lcm)
+/* macros for term comparison */
#define TD_DL_COMPARE(d1,d2)\
-(TD(d1)>TD(d2)?1:(TD(d1)
TD(d2)?1:(TD(d1) | next = _nm_free_list; _nm_free_list = p;
}
}
@@ -270,7 +313,7 @@ void _NDP_alloc()
for ( i = 0; i < 1024; i++ ) {
p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs)
- +nd_wpd*sizeof(unsigned int));
+ +(nd_wpd-1)*sizeof(unsigned int));
p->next = _ndp_free_list; _ndp_free_list = p;
}
}
@@ -296,7 +339,7 @@ INLINE int ndl_reducible(unsigned int *d1,unsigned int
if ( TD(d1) < TD(d2) ) return 0;
switch ( nd_bpe ) {
case 4:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( (u1&0xf0000000) < (u2&0xf0000000) ) return 0;
if ( (u1&0xf000000) < (u2&0xf000000) ) return 0;
@@ -310,7 +353,7 @@ INLINE int ndl_reducible(unsigned int *d1,unsigned int
return 1;
break;
case 6:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( (u1&0x3f000000) < (u2&0x3f000000) ) return 0;
if ( (u1&0xfc0000) < (u2&0xfc0000) ) return 0;
@@ -321,7 +364,7 @@ INLINE int ndl_reducible(unsigned int *d1,unsigned int
return 1;
break;
case 8:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( (u1&0xff000000) < (u2&0xff000000) ) return 0;
if ( (u1&0xff0000) < (u2&0xff0000) ) return 0;
@@ -331,7 +374,7 @@ INLINE int ndl_reducible(unsigned int *d1,unsigned int
return 1;
break;
case 16:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( (u1&0xffff0000) < (u2&0xffff0000) ) return 0;
if ( (u1&0xffff) < (u2&0xffff) ) return 0;
@@ -339,12 +382,12 @@ INLINE int ndl_reducible(unsigned int *d1,unsigned int
return 1;
break;
case 32:
- for ( i = 1; i <= nd_wpd; i++ )
+ for ( i = nd_exporigin; i < nd_wpd; i++ )
if ( d1[i] < d2[i] ) return 0;
return 1;
break;
default:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; 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;
@@ -361,22 +404,22 @@ void ndl_dehomogenize(unsigned int *d)
if ( nd_isrlex ) {
if ( nd_bpe == 32 ) {
- h = d[1];
- for ( i = 2; i <= nd_wpd; i++ )
+ h = d[nd_exporigin];
+ for ( i = nd_exporigin+1; i < nd_wpd; i++ )
d[i-1] = d[i];
d[i-1] = 0;
TD(d) -= h;
} else {
bits = nd_epw*nd_bpe;
mask = bits==32?0xffffffff:((1<<(nd_epw*nd_bpe))-1);
- h = (d[1]>>((nd_epw-1)*nd_bpe))&nd_mask0;
- for ( i = 1; i <= nd_wpd; i++ )
+ h = (d[nd_exporigin]>>((nd_epw-1)*nd_bpe))&nd_mask0;
+ for ( i = nd_exporigin; i < nd_wpd; i++ )
d[i] = ((d[i]<>((nd_epw-1)*nd_bpe))&nd_mask0):0);
+ |(i+1>((nd_epw-1)*nd_bpe))&nd_mask0):0);
TD(d) -= h;
}
} else
- TD(d) -= ((d[(nd_nvar-1)/nd_epw+1]>>
+ TD(d) -= ((d[(nd_nvar-1)/nd_epw+nd_exporigin]>>
((nd_epw-((nd_nvar-1)%nd_epw)-1)*nd_bpe))&((1<t2?t1:t2;
t1 = (u1&0xf000000); t2 = (u2&0xf000000); u |= t1>t2?t1:t2;
@@ -401,7 +444,7 @@ void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned in
}
break;
case 6:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; 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;
@@ -412,7 +455,7 @@ void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned in
}
break;
case 8:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
t1 = (u1&0xff000000); t2 = (u2&0xff000000); u = t1>t2?t1:t2;
t1 = (u1&0xff0000); t2 = (u2&0xff0000); u |= t1>t2?t1:t2;
@@ -422,7 +465,7 @@ void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned in
}
break;
case 16:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
t1 = (u1&0xffff0000); t2 = (u2&0xffff0000); u = t1>t2?t1:t2;
t1 = (u1&0xffff); t2 = (u2&0xffff); u |= t1>t2?t1:t2;
@@ -430,13 +473,13 @@ void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned in
}
break;
case 32:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
d[i] = u1>u2?u1:u2;
}
break;
default:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; 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;
@@ -445,15 +488,15 @@ void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned in
}
break;
}
- TD(d) = ndl_td(d);
+ TD(d) = ndl_weight(d);
}
-int ndl_td(unsigned int *d)
+int ndl_weight(unsigned int *d)
{
unsigned int t,u;
int i,j;
- for ( t = 0, i = 1; i <= nd_wpd; i++ ) {
+ for ( t = 0, i = nd_exporigin; i < nd_wpd; i++ ) {
u = d[i];
for ( j = 0; j < nd_epw; j++, u>>=nd_bpe )
t += (u&nd_mask0);
@@ -465,7 +508,9 @@ INLINE int ndl_lex_compare(unsigned int *d1,unsigned i
{
int i;
- for ( i = 0; i < nd_wpd; i++, d1++, d2++ )
+ d1 += nd_exporigin;
+ d2 += nd_exporigin;
+ for ( i = nd_exporigin; i < nd_wpd; i++, d1++, d2++ )
if ( *d1 > *d2 )
return nd_isrlex ? -1 : 1;
else if ( *d1 < *d2 )
@@ -477,8 +522,7 @@ INLINE int ndl_equal(unsigned int *d1,unsigned int *d2
{
int i;
- if ( *d1++ != *d2++ ) return 0;
- for ( i = 1; i <= nd_wpd; i++ )
+ for ( i = 0; i < nd_wpd; i++ )
if ( *d1++ != *d2++ )
return 0;
return 1;
@@ -489,17 +533,17 @@ INLINE void ndl_copy(unsigned int *d1,unsigned int *d2
int i;
switch ( nd_wpd ) {
- case 1:
+ case 2:
TD(d2) = TD(d1);
d2[1] = d1[1];
break;
- case 2:
+ case 3:
TD(d2) = TD(d1);
d2[1] = d1[1];
d2[2] = d1[2];
break;
default:
- for ( i = 0; i <= nd_wpd; i++ )
+ for ( i = 0; i < nd_wpd; i++ )
d2[i] = d1[i];
break;
}
@@ -509,17 +553,18 @@ INLINE void ndl_add(unsigned int *d1,unsigned int *d2,
{
int i;
- TD(d) = TD(d1)+TD(d2);
switch ( nd_wpd ) {
- case 1:
+ case 2:
+ TD(d) = TD(d1)+TD(d2);
d[1] = d1[1]+d2[1];
break;
- case 2:
+ case 3:
+ TD(d) = TD(d1)+TD(d2);
d[1] = d1[1]+d2[1];
d[2] = d1[2]+d2[2];
break;
default:
- for ( i = 1; i <= nd_wpd; i++ )
+ for ( i = 0; i < nd_wpd; i++ )
d[i] = d1[i]+d2[i];
break;
}
@@ -529,7 +574,7 @@ INLINE void ndl_sub(unsigned int *d1,unsigned int *d2,
{
int i;
- for ( i = 0; i <= nd_wpd; i++ )
+ for ( i = 0; i < nd_wpd; i++ )
d[i] = d1[i]-d2[i];
}
@@ -540,7 +585,7 @@ int ndl_disjoint(unsigned int *d1,unsigned int *d2)
switch ( nd_bpe ) {
case 4:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
t1 = u1&0xf0000000; t2 = u2&0xf0000000; if ( t1&&t2 ) return 0;
t1 = u1&0xf000000; t2 = u2&0xf000000; if ( t1&&t2 ) return 0;
@@ -554,7 +599,7 @@ int ndl_disjoint(unsigned int *d1,unsigned int *d2)
return 1;
break;
case 6:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; 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;
@@ -565,7 +610,7 @@ int ndl_disjoint(unsigned int *d1,unsigned int *d2)
return 1;
break;
case 8:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
t1 = u1&0xff000000; t2 = u2&0xff000000; if ( t1&&t2 ) return 0;
t1 = u1&0xff0000; t2 = u2&0xff0000; if ( t1&&t2 ) return 0;
@@ -575,7 +620,7 @@ int ndl_disjoint(unsigned int *d1,unsigned int *d2)
return 1;
break;
case 16:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
t1 = u1&0xffff0000; t2 = u2&0xffff0000; if ( t1&&t2 ) return 0;
t1 = u1&0xffff; t2 = u2&0xffff; if ( t1&&t2 ) return 0;
@@ -583,12 +628,12 @@ int ndl_disjoint(unsigned int *d1,unsigned int *d2)
return 1;
break;
case 32:
- for ( i = 1; i <= nd_wpd; i++ )
+ for ( i = nd_exporigin; i < nd_wpd; i++ )
if ( d1[i] && d2[i] ) return 0;
return 1;
break;
default:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; 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;
@@ -610,7 +655,7 @@ int ndl_check_bound2(int index,unsigned int *d2)
ind = 0;
switch ( nd_bpe ) {
case 4:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u2 = d2[i];
if ( d1[ind++]+((u2>>28)&0xf) >= 0x10 ) return 1;
if ( d1[ind++]+((u2>>24)&0xf) >= 0x10 ) return 1;
@@ -624,7 +669,7 @@ int ndl_check_bound2(int index,unsigned int *d2)
return 0;
break;
case 6:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u2 = d2[i];
if ( d1[ind++]+((u2>>24)&0x3f) >= 0x40 ) return 1;
if ( d1[ind++]+((u2>>18)&0x3f) >= 0x40 ) return 1;
@@ -635,7 +680,7 @@ int ndl_check_bound2(int index,unsigned int *d2)
return 0;
break;
case 8:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u2 = d2[i];
if ( d1[ind++]+((u2>>24)&0xff) >= 0x100 ) return 1;
if ( d1[ind++]+((u2>>16)&0xff) >= 0x100 ) return 1;
@@ -645,7 +690,7 @@ int ndl_check_bound2(int index,unsigned int *d2)
return 0;
break;
case 16:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u2 = d2[i];
if ( d1[ind++]+((u2>>16)&0xffff) > 0x10000 ) return 1;
if ( d1[ind++]+(u2&0xffff) > 0x10000 ) return 1;
@@ -653,12 +698,12 @@ int ndl_check_bound2(int index,unsigned int *d2)
return 0;
break;
case 32:
- for ( i = 1; i <= nd_wpd; i++ )
+ for ( i = nd_exporigin; i < nd_wpd; i++ )
if ( d1[i]+d2[i]>28)&0xf)+((u2>>28)&0xf) >= 0x10 ) return 1;
if ( ((u1>>24)&0xf)+((u2>>24)&0xf) >= 0x10 ) return 1;
@@ -690,7 +735,7 @@ int ndl_check_bound2_direct(unsigned int *d1,unsigned
return 0;
break;
case 6:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( ((u1>>24)&0x3f)+((u2>>24)&0x3f) >= 0x40 ) return 1;
if ( ((u1>>18)&0x3f)+((u2>>18)&0x3f) >= 0x40 ) return 1;
@@ -701,7 +746,7 @@ int ndl_check_bound2_direct(unsigned int *d1,unsigned
return 0;
break;
case 8:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( ((u1>>24)&0xff)+((u2>>24)&0xff) >= 0x100 ) return 1;
if ( ((u1>>16)&0xff)+((u2>>16)&0xff) >= 0x100 ) return 1;
@@ -711,7 +756,7 @@ int ndl_check_bound2_direct(unsigned int *d1,unsigned
return 0;
break;
case 16:
- for ( i = 1; i <= nd_wpd; i++ ) {
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) {
u1 = d1[i]; u2 = d2[i];
if ( ((u1>>16)&0xffff)+((u2>>16)&0xffff) > 0x10000 ) return 1;
if ( (u2&0xffff)+(u2&0xffff) > 0x10000 ) return 1;
@@ -719,12 +764,12 @@ int ndl_check_bound2_direct(unsigned int *d1,unsigned
return 0;
break;
case 32:
- for ( i = 1; i <= nd_wpd; i++ )
+ for ( i = nd_exporigin; i < nd_wpd; i++ )
if ( d1[i]+d2[i]index;
}
}
+#endif
if ( Reverse )
for ( i = nd_psn-1; i >= 0; i-- ) {
r = nd_psh[i];
@@ -925,7 +972,7 @@ int nd_nf(int mod,ND g,int full,ND *rp)
sugar0 = sugar = SG(g);
n = NV(g);
- mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
+ mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int));
for ( d = 0; g; ) {
index = nd_find_reducer(g);
if ( index >= 0 ) {
@@ -997,7 +1044,7 @@ int nd_nf_pbucket(int mod,ND g,int full,ND *rp)
bucket = create_pbucket();
add_pbucket(mod,bucket,g);
d = 0;
- mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
+ mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int));
while ( 1 ) {
hindex = mod?head_pbucket(mod,bucket):head_pbucket_q(bucket);
if ( hindex < 0 ) {
@@ -1095,7 +1142,7 @@ int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full
sugar0 = sugar = SG(g);
n = NV(g);
- mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
+ mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int));
for ( d = 0; g; ) {
index = nd_find_reducer_direct(g,ps,len);
if ( index >= 0 ) {
@@ -1171,7 +1218,7 @@ int nd_nf_direct_pbucket(int mod,ND g,NDV *ps,int len,
bucket = create_pbucket();
add_pbucket(mod,bucket,g);
d = 0;
- mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
+ mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int));
while ( 1 ) {
hindex = mod?head_pbucket(mod,bucket):head_pbucket_q(bucket);
if ( hindex < 0 ) {
@@ -1249,7 +1296,7 @@ int nd_check_candidate(NODE input,NODE cand)
ND nf,d;
NODE t;
- nd_setup(0,cand);
+ nd_setup(0,0,cand);
n = length(cand);
/* membercheck : list is a subset of Id(cand) ? */
@@ -1450,7 +1497,11 @@ again:
d = nd_reconstruct(m,0,d);
goto again;
}
+#if USE_GEOBUCKET
stat = m?nd_nf_pbucket(m,h,!Top,&nf):nd_nf(m,h,!Top,&nf);
+#else
+ stat = nd_nf(m,h,!Top,&nf);
+#endif
if ( !stat ) {
NEXT(l) = d; d = l;
d = nd_reconstruct(m,0,d);
@@ -1458,7 +1509,7 @@ again:
} else if ( nf ) {
if ( checkonly ) return 0;
printf("+"); fflush(stdout);
- nh = nd_newps(m,nf);
+ nh = m?nd_newps(m,nf,0):nd_newps(m,0,nf);
d = update_pairs(d,g,nh);
g = update_base(g,nh);
FREENDP(l);
@@ -1501,7 +1552,11 @@ again:
d = nd_reconstruct(m,1,d);
goto again;
}
+#if USE_GEOBUCKET
stat = nd_nf_pbucket(m,h,!Top,&nf);
+#else
+ stat = nd_nf(m,h,!Top,&nf);
+#endif
if ( !stat ) {
NEXT(l) = d; d = l;
d = nd_reconstruct(m,1,d);
@@ -1512,9 +1567,9 @@ again:
nd_nf(0,h,!Top,&nfq);
if ( nfq ) {
printf("+"); fflush(stdout);
- nh = nd_newps_trace(m,nf,nfq);
+ nh = nd_newps(m,nf,nfq);
/* failure; m|HC(nfq) */
- if ( nf < 0 ) return 0;
+ if ( nh < 0 ) return 0;
d = update_pairs(d,g,nh);
g = update_base(g,nh);
} else {
@@ -1642,7 +1697,7 @@ ND_pairs crit_B( ND_pairs d, int s )
t = DL(nd_psh[s]);
prev = 0;
head = cur = d;
- lcm = (unsigned int *)ALLOCA((nd_wpd+1)*sizeof(unsigned int));
+ lcm = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int));
while ( cur ) {
tl = cur->lcm;
if ( ndl_reducible(tl,t)
@@ -1750,7 +1805,7 @@ int crit_2( int dp1, int dp2 )
return ndl_disjoint(DL(nd_psh[dp1]),DL(nd_psh[dp2]));
}
-static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest )
+ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest )
{
ND_pairs w,p,r,s;
unsigned int *d;
@@ -1762,11 +1817,9 @@ static ND_pairs equivalent_pairs( ND_pairs d1, ND_pair
for ( r = 0; s; s = p ) {
p = NEXT(s);
if ( ndl_equal(d,LCM(s)) ) {
- NEXT(s) = w;
- w = s;
+ NEXT(s) = w; w = s;
} else {
- NEXT(s) = r;
- r = s;
+ NEXT(s) = r; r = s;
}
}
*prest = r;
@@ -1808,9 +1861,7 @@ ND_pairs nd_minp( ND_pairs d, ND_pairs *prest )
for ( ml = 0, l = m; p; p = NEXT(l = p) )
if ( (SG(p) < s)
|| ((SG(p) == s) && (DL_COMPARE(LCM(p),LCM(m)) < 0)) ) {
- ml = l;
- m = p;
- s = SG(m);
+ ml = l; m = p; s = SG(m);
}
if ( !ml ) *prest = NEXT(m);
else {
@@ -1821,7 +1872,7 @@ ND_pairs nd_minp( ND_pairs d, ND_pairs *prest )
return m;
}
-int nd_newps(int mod,ND a)
+int nd_newps(int mod,ND a,ND aq)
{
int len;
RHist r;
@@ -1835,95 +1886,30 @@ int nd_newps(int mod,ND a)
nd_bound = (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); ndl_copy(HDL(a),DL(r));
- nd_psh[nd_psn] = r;
- b = ndtondv(mod,a);
- len = LEN(b);
- if ( mod )
- nd_ps[nd_psn] = b;
- else
- nd_psq[nd_psn] = b;
- nd_free(a);
- 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_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 *));
+ if ( a && aq ) {
+ /* trace lifting */
+ if ( !rem(NM(HCQ(aq)),mod) ) return -1;
}
- if ( !rem(NM(HCQ(nfq)),mod) ) return -1;
- 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); ndl_copy(HDL(nf),DL(r));
- nd_psh[nd_psn] = r;
- nd_free(nf); nd_free(nfq);
- return nd_psn++;
-}
-
-void nd_setup(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_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);
+ NEWRHist(r); nd_psh[nd_psn] = r;
+ if ( aq ) {
+ nd_removecont(0,aq);
+ nd_psq[nd_psn] = ndtondv(0,aq);
+ nd_bound[nd_psn] = nd_compute_bound(aq);
+ SG(r) = SG(aq); ndl_copy(HDL(aq),DL(r));
}
- 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) ) {
- NEWRHist(r);
- a = dptondv(mod,(DP)BDY(f));
- ndv_removecont(mod,a);
- len = MAX(len,LEN(a));
- SG(r) = HTD(a); ndl_copy(HDL(a),DL(r));
- if ( mod ) nd_ps[i] = a;
- else nd_psq[i] = a;
- nd_psh[i] = r;
+ if ( a ) {
+ nd_removecont(mod,a);
+ nd_ps[nd_psn] = ndtondv(mod,a);
+ if ( !aq ) {
+ nd_bound[nd_psn] = nd_compute_bound(a);
+ SG(r) = SG(a); ndl_copy(HDL(a),DL(r));
+ }
}
+ nd_free(a); nd_free(aq);
+ return nd_psn++;
}
-void nd_setup_trace(int mod,NODE f)
+void nd_setup(int mod,int trace,NODE f)
{
int i,j,td,len,max;
NODE s,s0,f0;
@@ -1956,13 +1942,19 @@ void nd_setup_trace(int mod,NODE f)
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));
+ a = dptondv(mod,(DP)BDY(f)); ndv_removecont(mod,a);
SG(r) = HTD(a); ndl_copy(HDL(a),DL(r));
+
+ if ( trace ) {
+ nd_ps[i] = a;
+ a = dptondv(0,(DP)BDY(f)); ndv_removecont(0,a);
+ nd_psq[i] = a;
+ } else {
+ if ( mod ) nd_ps[i] = a;
+ else nd_psq[i] = a;
+ }
nd_psh[i] = r;
}
}
@@ -1984,7 +1976,7 @@ void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,
NEXTNODE(fd0,fd); BDY(fd) = (pointer)b;
}
if ( fd0 ) NEXT(fd) = 0;
- nd_setup(m,fd0);
+ nd_setup(m,0,fd0);
x = nd_gb(m,0);
fprintf(asir_out,"found=%d,notfirst=%d,create=%d\n",
nd_found,nd_notfirst,nd_create);
@@ -2040,7 +2032,7 @@ void nd_gr_trace(LIST f,LIST v,int m,int homo,struct o
nd_init_ord(ord);
}
do {
- nd_setup_trace(m,fd0);
+ nd_setup(m,1,fd0);
cand = nd_gb_trace(m);
if ( !cand ) continue;
if ( homo ) {
@@ -2077,14 +2069,14 @@ void dltondl(int n,DL dl,unsigned int *r)
int i;
d = dl->d;
- for ( i = 0; i <= nd_wpd; i++ ) r[i] = 0;
+ for ( i = 0; i < nd_wpd; i++ ) r[i] = 0;
if ( nd_isrlex )
for ( i = 0; i < n; i++ )
- r[(n-1-i)/nd_epw+1] |= (d[i]<<((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe));
+ r[(n-1-i)/nd_epw+nd_exporigin] |= (d[i]<<((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe));
else
for ( i = 0; i < n; i++ )
- r[i/nd_epw+1] |= d[i]<<((nd_epw-(i%nd_epw)-1)*nd_bpe);
- TD(r) = ndl_td(r);
+ r[i/nd_epw+nd_exporigin] |= d[i]<<((nd_epw-(i%nd_epw)-1)*nd_bpe);
+ TD(r) = ndl_weight(r);
}
DL ndltodl(int n,unsigned int *ndl)
@@ -2098,11 +2090,11 @@ DL ndltodl(int n,unsigned int *ndl)
d = dl->d;
if ( nd_isrlex )
for ( i = 0; i < n; i++ )
- d[i] = (ndl[(n-1-i)/nd_epw+1]>>((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe))
+ d[i] = (ndl[(n-1-i)/nd_epw+nd_exporigin]>>((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe))
&((1<>((nd_epw-(i%nd_epw)-1)*nd_bpe))
+ d[i] = (ndl[i/nd_epw+nd_exporigin]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))
&((1<>((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe))
+ (dl[(n-1-i)/nd_epw+nd_exporigin]>>((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe))
&((1<>((nd_epw-(i%nd_epw)-1)*nd_bpe))
+ (dl[i/nd_epw+nd_exporigin]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))
&((1<>");
}
@@ -2293,12 +2285,12 @@ void ndv_dehomogenize(NDV p)
len = p->len;
newnvar = nd_nvar-1;
- newwpd = newnvar/nd_epw+(newnvar%nd_epw?1:0);
+ newwpd = newnvar/nd_epw+(newnvar%nd_epw?1:0)+nd_exporigin;
for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ )
ndl_dehomogenize(DL(m));
if ( newwpd != nd_wpd ) {
- d = (unsigned int *)ALLOCA((newwpd+1)*sizeof(unsigned int));
- newadv = sizeof(struct oNMV)+newwpd*sizeof(unsigned int);
+ d = (unsigned int *)ALLOCA(newwpd*sizeof(unsigned int));
+ newadv = sizeof(struct oNMV)+(newwpd-1)*sizeof(unsigned int);
for ( m = r = BDY(p), i = 0; i < len; NMV_ADV(m), NEWADV(r), i++ ) {
CQ(r) = CQ(m); ndl_copy(DL(m),d); ndl_copy(d,DL(r));
}
@@ -2442,7 +2434,7 @@ unsigned int *nd_compute_bound(ND p)
t = (unsigned int *)MALLOC_ATOMIC(l*sizeof(unsigned int));
for ( i = 0; i < l; i++ ) t[i] = 0;
for ( i = 0; i < nd_nvar; i++ )
- t[i] = (d1[i/nd_epw+1]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))&nd_mask0;
+ t[i] = (d1[i/nd_epw+nd_exporigin]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))&nd_mask0;
for ( ; i < l; i++ ) t[i] = 0;
return t;
}
@@ -2452,6 +2444,19 @@ void nd_setup_parameters() {
nd_epw = (sizeof(unsigned int)*8)/nd_bpe;
nd_wpd = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0);
+ switch ( nd_ord->id ) {
+ case 0:
+ nd_exporigin = 1;
+ break;
+ case 1:
+ /* block order */
+ nd_exporigin = nd_ord->ord.block.length;
+ break;
+ case 2:
+ error("nd_setup_parameters : matrix order is not supported yet.");
+ break;
+ }
+ nd_wpd += nd_exporigin;
if ( nd_bpe < 32 ) {
nd_mask0 = (1< realloc nd_ps and pd_psq */
-
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
{
int i,obpe,oadv,h;
@@ -2502,7 +2505,7 @@ ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
s->i1 = t->i1;
s->i2 = t->i2;
SG(s) = SG(t);
- ndl_dup(obpe,LCM(t),LCM(s));
+ ndl_reconstruct(obpe,LCM(t),LCM(s));
}
old_red = (RHist *)ALLOCA(REDTAB_LEN*sizeof(RHist));
@@ -2515,7 +2518,7 @@ ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
NEWRHist(mr);
mr->index = r->index;
SG(mr) = SG(r);
- ndl_dup(obpe,DL(r),DL(mr));
+ ndl_reconstruct(obpe,DL(r),DL(mr));
h = ndl_hash_value(DL(mr));
NEXT(mr) = nd_red[h];
nd_red[h] = mr;
@@ -2524,7 +2527,7 @@ ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
old_red = 0;
for ( i = 0; i < nd_psn; i++ ) {
NEWRHist(r); SG(r) = SG(nd_psh[i]);
- ndl_dup(obpe,DL(nd_psh[i]),DL(r));
+ ndl_reconstruct(obpe,DL(nd_psh[i]),DL(r));
nd_psh[i] = r;
}
if ( s0 ) NEXT(s) = 0;
@@ -2556,8 +2559,7 @@ void nd_reconstruct_direct(int mod,NDV *ps,int len)
prev_nm_free_list = _nm_free_list;
prev_ndp_free_list = _ndp_free_list;
_nm_free_list = 0; _ndp_free_list = 0;
- if ( mod != 0 )
- for ( i = len-1; i >= 0; i-- ) ndv_realloc(ps[i],obpe,oadv);
+ for ( i = len-1; i >= 0; i-- ) ndv_realloc(ps[i],obpe,oadv);
old_red = (RHist *)ALLOCA(REDTAB_LEN*sizeof(RHist));
for ( i = 0; i < REDTAB_LEN; i++ ) {
old_red[i] = nd_red[i];
@@ -2568,7 +2570,7 @@ void nd_reconstruct_direct(int mod,NDV *ps,int len)
NEWRHist(mr);
mr->index = r->index;
SG(mr) = SG(r);
- ndl_dup(obpe,DL(r),DL(mr));
+ ndl_reconstruct(obpe,DL(r),DL(mr));
h = ndl_hash_value(DL(mr));
NEXT(mr) = nd_red[h];
nd_red[h] = mr;
@@ -2580,7 +2582,7 @@ void nd_reconstruct_direct(int mod,NDV *ps,int len)
GC_gcollect();
}
-void ndl_dup(int obpe,unsigned int *d,unsigned int *r)
+void ndl_reconstruct(int obpe,unsigned int *d,unsigned int *r)
{
int n,i,ei,oepw,cepw,cbpe;
@@ -2589,18 +2591,18 @@ void ndl_dup(int obpe,unsigned int *d,unsigned int *r)
cepw = nd_epw;
cbpe = nd_bpe;
TD(r) = TD(d);
- for ( i = 1; i <= nd_wpd; i++ ) r[i] = 0;
+ for ( i = nd_exporigin; i < nd_wpd; i++ ) r[i] = 0;
if ( nd_isrlex )
for ( i = 0; i < n; i++ ) {
- ei = (d[(n-1-i)/oepw+1]>>((oepw-((n-1-i)%oepw)-1)*obpe))
+ ei = (d[(n-1-i)/oepw+nd_exporigin]>>((oepw-((n-1-i)%oepw)-1)*obpe))
&((1<>((oepw-(i%oepw)-1)*obpe))
+ ei = (d[i/oepw+nd_exporigin]>>((oepw-(i%oepw)-1)*obpe))
&((1< |