=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/nd.c,v retrieving revision 1.161 retrieving revision 1.165 diff -u -p -r1.161 -r1.165 --- OpenXM_contrib2/asir2000/engine/nd.c 2009/01/05 02:08:18 1.161 +++ OpenXM_contrib2/asir2000/engine/nd.c 2009/02/02 02:40:42 1.165 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.160 2009/01/05 01:47:30 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.164 2009/01/07 05:33:18 noro Exp $ */ #include "nd.h" @@ -217,7 +217,7 @@ INLINE int ndl_reducible(UINT *d1,UINT *d2) * order is either 0 or 2. */ -void ndl_homogenize(UINT *d,UINT *r,int obpe,EPOS oepos,int weight) +void ndl_homogenize(UINT *d,UINT *r,int obpe,EPOS oepos,int ompos,int weight) { int w,i,e,n,omask0; @@ -230,9 +230,9 @@ void ndl_homogenize(UINT *d,UINT *r,int obpe,EPOS oepo } w = TD(d); PUT_EXP(r,nd_nvar-1,weight-w); + if ( nd_module ) MPOS(r) = d[ompos]; TD(r) = weight; if ( nd_blockmask ) ndl_weight_mask(r); - if ( nd_module ) MPOS(r) = MPOS(d); } void ndl_dehomogenize(UINT *d) @@ -364,9 +364,9 @@ void ndl_lcm(UINT *d1,unsigned *d2,UINT *d) d[i] = u; } #endif + if ( nd_module ) MPOS(d) = MPOS(d1); TD(d) = ndl_weight(d); if ( nd_blockmask ) ndl_weight_mask(d); - if ( nd_module ) MPOS(d) = MPOS(d1); } void ndl_max(UINT *d1,unsigned *d2,UINT *d) @@ -568,7 +568,7 @@ int ndl_ww_lex_compare(UINT *d1,UINT *d2) int ndl_module_grlex_compare(UINT *d1,UINT *d2) { - int i; + int i,c; if ( nd_ispot ) { if ( MPOS(d1) < MPOS(d2) ) return 1; @@ -576,9 +576,7 @@ int ndl_module_grlex_compare(UINT *d1,UINT *d2) } if ( TD(d1) > TD(d2) ) return 1; else if ( TD(d1) < TD(d2) ) return -1; - for ( i = nd_nvar-1; i >= 0; i-- ) - if ( GET_EXP(d1,i) < GET_EXP(d2,i) ) return 1; - else if ( GET_EXP(d1,i) > GET_EXP(d2,i) ) return -1; + if ( c = ndl_lex_compare(d1,d2) ) return c; if ( !nd_ispot ) { if ( MPOS(d1) < MPOS(d2) ) return 1; else if ( MPOS(d1) > MPOS(d2) ) return -1; @@ -588,7 +586,7 @@ int ndl_module_grlex_compare(UINT *d1,UINT *d2) int ndl_module_glex_compare(UINT *d1,UINT *d2) { - int i; + int i,c; if ( nd_ispot ) { if ( MPOS(d1) < MPOS(d2) ) return 1; @@ -596,9 +594,7 @@ int ndl_module_glex_compare(UINT *d1,UINT *d2) } if ( TD(d1) > TD(d2) ) return 1; else if ( TD(d1) < TD(d2) ) return -1; - for ( i = 0; i < nd_nvar; i++ ) - if ( GET_EXP(d1,i) > GET_EXP(d2,i) ) return 1; - else if ( GET_EXP(d1,i) < GET_EXP(d2,i) ) return -1; + if ( c = ndl_lex_compare(d1,d2) ) return c; if ( !nd_ispot ) { if ( MPOS(d1) < MPOS(d2) ) return 1; else if ( MPOS(d1) > MPOS(d2) ) return -1; @@ -608,15 +604,13 @@ int ndl_module_glex_compare(UINT *d1,UINT *d2) int ndl_module_lex_compare(UINT *d1,UINT *d2) { - int i; + int i,c; if ( nd_ispot ) { if ( MPOS(d1) < MPOS(d2) ) return 1; else if ( MPOS(d1) > MPOS(d2) ) return -1; } - for ( i = 0; i < nd_nvar; i++ ) - if ( GET_EXP(d1,i) > GET_EXP(d2,i) ) return 1; - else if ( GET_EXP(d1,i) < GET_EXP(d2,i) ) return -1; + if ( c = ndl_lex_compare(d1,d2) ) return c; if ( !nd_ispot ) { if ( MPOS(d1) < MPOS(d2) ) return 1; else if ( MPOS(d1) > MPOS(d2) ) return -1; @@ -727,6 +721,10 @@ INLINE void ndl_add(UINT *d1,UINT *d2,UINT *d) { int i; + if ( nd_module ) { + if ( MPOS(d1) && MPOS(d2) && (MPOS(d1) != MPOS(d2)) ) + error("ndl_add : invalid operation"); + } #if 1 switch ( nd_wpd ) { case 2: @@ -745,11 +743,6 @@ INLINE void ndl_add(UINT *d1,UINT *d2,UINT *d) #else for ( i = 0; i < nd_wpd; i++ ) d[i] = d1[i]+d2[i]; #endif - if ( nd_module ) { - if ( MPOS(d1) && MPOS(d2) && (MPOS(d1) != MPOS(d2)) ) - error("ndl_add : invalid operation"); - MPOS(d) = MPOS(d1); - } } /* d1 += d2 */ @@ -757,6 +750,10 @@ INLINE void ndl_addto(UINT *d1,UINT *d2) { int i; + if ( nd_module ) { + if ( MPOS(d1) && MPOS(d2) && (MPOS(d1) != MPOS(d2)) ) + error("ndl_addto : invalid operation"); + } #if 1 switch ( nd_wpd ) { case 2: @@ -775,11 +772,6 @@ INLINE void ndl_addto(UINT *d1,UINT *d2) #else for ( i = 0; i < nd_wpd; i++ ) d1[i] += d2[i]; #endif - if ( nd_module ) { - if ( MPOS(d1) && MPOS(d2) && (MPOS(d1) != MPOS(d2)) ) - error("ndl_addto : invalid operation"); - MPOS(d1) = MPOS(d2); - } } INLINE void ndl_sub(UINT *d1,UINT *d2,UINT *d) @@ -2211,16 +2203,24 @@ ND_pairs crit_B( ND_pairs d, int s ) lcm = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); while ( cur ) { tl = cur->lcm; - if ( ndl_reducible(tl,t) - && (ndl_lcm(DL(nd_psh[cur->i1]),t,lcm),!ndl_equal(lcm,tl)) - && (ndl_lcm(DL(nd_psh[cur->i2]),t,lcm),!ndl_equal(lcm,tl)) ) { - remove = cur; - if ( !prev ) { - head = cur = NEXT(cur); - } else { - cur = NEXT(prev) = NEXT(cur); - } - FREENDP(remove); + if ( ndl_reducible(tl,t) ) { + ndl_lcm(DL(nd_psh[cur->i1]),t,lcm); + if ( !ndl_equal(lcm,tl) ) { + ndl_lcm(DL(nd_psh[cur->i2]),t,lcm); + if (!ndl_equal(lcm,tl)) { + remove = cur; + if ( !prev ) { + head = cur = NEXT(cur); + } else { + cur = NEXT(prev) = NEXT(cur); + } + FREENDP(remove); + } else { + prev = cur; cur = NEXT(cur); + } + } else { + prev = cur; cur = NEXT(cur); + } } else { prev = cur; cur = NEXT(cur); } @@ -2639,6 +2639,7 @@ void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe NumberField nf; struct order_spec *ord1; + nd_module = 0; if ( !m && Demand ) nd_demand = 1; else nd_demand = 0; @@ -2816,7 +2817,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int P p,zp; Q dmy; EPOS oepos; - int obpe,oadv,wmax,i,len,cbpe,ishomo,nalg,mrank,trank; + int obpe,oadv,wmax,i,len,cbpe,ishomo,nalg,mrank,trank,ompos; Alg alpha,dp; P poly; LIST f1,f2,zpl; @@ -2825,6 +2826,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int struct order_spec *ord1; struct oEGT eg_check,eg0,eg1; + nd_module = 0; if ( DP_Multiple ) nd_scale = ((double)DP_Multiple)/(double)(Denominator?Denominator:1); @@ -2881,7 +2883,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int } } nd_setup_parameters(nvar,max); - obpe = nd_bpe; oadv = nmv_adv; oepos = nd_epos; + obpe = nd_bpe; oadv = nmv_adv; oepos = nd_epos; ompos = nd_mpos; ishomo = 1; for ( in0 = 0, fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { if ( nd_module ) { @@ -2910,7 +2912,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int nd_init_ord(ord1); nd_setup_parameters(nvar+1,wmax); for ( t = fd0; t; t = NEXT(t) ) - ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos); + ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos); } while ( 1 ) { if ( Demand ) @@ -3172,7 +3174,7 @@ void ndv_removecont(int mod,NDV p) /* koko */ -void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos) +void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos,int ompos) { int len,i,max; NMV m,mr0,mr,t; @@ -3185,7 +3187,7 @@ void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos mr = (NMV)((char *)mr0+(len-1)*nmv_adv); t = (NMV)ALLOCA(nmv_adv); for ( i = 0; i < len; i++, NMV_OPREV(m), NMV_PREV(mr) ) { - ndl_homogenize(DL(m),DL(t),obpe,oepos,max); + ndl_homogenize(DL(m),DL(t),obpe,oepos,ompos,max); CQ(mr) = CQ(m); ndl_copy(DL(t),DL(mr)); } @@ -3195,7 +3197,8 @@ void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos void ndv_dehomogenize(NDV p,struct order_spec *ord) { - int i,j,adj,len,newnvar,newwpd,newadv,newexporigin; + int i,j,adj,len,newnvar,newwpd,newadv,newexporigin,newmpos; + int pos; Q *w; Q dvr,t; NMV m,r; @@ -3203,6 +3206,7 @@ void ndv_dehomogenize(NDV p,struct order_spec *ord) len = p->len; newnvar = nd_nvar-1; newexporigin = nd_get_exporigin(ord); + if ( nd_module ) newmpos = newexporigin-1; newwpd = newnvar/nd_epw+(newnvar%nd_epw?1:0)+newexporigin; for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) ndl_dehomogenize(DL(m)); @@ -3210,9 +3214,13 @@ void ndv_dehomogenize(NDV p,struct order_spec *ord) newadv = ROUND_FOR_ALIGN(sizeof(struct oNMV)+(newwpd-1)*sizeof(UINT)); for ( m = r = BDY(p), i = 0; i < len; NMV_ADV(m), NDV_NADV(r), i++ ) { CQ(r) = CQ(m); + if ( nd_module ) pos = MPOS(DL(m)); for ( j = 0; j < newexporigin; j++ ) DL(r)[j] = DL(m)[j]; adj = nd_exporigin-newexporigin; for ( ; j < newwpd; j++ ) DL(r)[j] = DL(m)[j+adj]; + if ( nd_module ) { + DL(r)[newmpos] = pos; + } } } NV(p)--; @@ -3775,6 +3783,7 @@ void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta } if ( nd_module ) { mpos = MPOS(d1); + TD(d1) = ndl_weight(d1); if ( MPOS(d0) ) error("weyl_mul_nm_nmv : invalid operation"); } tab[0] = m; @@ -3790,6 +3799,10 @@ void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta if ( t = tab[j] ) { dt = DL(t); PUT_EXP(dt,i,a); PUT_EXP(dt,n2+i,b); TD(dt) += s; + if ( nd_module ) { + MPOS(dt) = mpos; + TD(dt) = ndl_weight(dt); + } if ( nd_blockmask ) ndl_weight_mask(dt); } curlen *= k+1; @@ -3811,8 +3824,11 @@ void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta TD(d) = s; PUT_EXP(d,n-1,s-h); } else TD(d) = h; + if ( nd_module ) { + MPOS(d) = mpos; + TD(d) = ndl_weight(d); + } if ( nd_blockmask ) ndl_weight_mask(d); - if ( nd_module ) MPOS(d) = mpos; if ( mod ) c = ctab[j]; else q = ctab_q[j]; p = tab+curlen*j; @@ -4152,9 +4168,12 @@ NDV pltondv(VL vl,VL dvl,LIST p) r = 0; for ( i = 1, t = BDY(p); t; t = NEXT(t), i++ ) { ri = ptond(vl,dvl,(P)BDY(t)); - if ( ri ) - for ( m = BDY(ri); m; m = NEXT(m) ) - MPOS(DL(m)) = i; + if ( ri ) + for ( m = BDY(ri); m; m = NEXT(m) ) { + MPOS(DL(m)) = i; + TD(DL(m)) = ndl_weight(DL(m)); + if ( nd_blockmask ) ndl_weight_mask(DL(m)); + } r = nd_add(0,r,ri); } return ndtondv(0,r); @@ -4457,15 +4476,17 @@ void nd_init_ord(struct order_spec *ord) case 256: nd_ispot = ord->ispot; nd_dcomp = -1; - nd_isrlex = 0; switch ( ord->ord.simple ) { case 0: + nd_isrlex = 1; ndl_compare_function = ndl_module_grlex_compare; break; case 1: + nd_isrlex = 0; ndl_compare_function = ndl_module_glex_compare; break; case 2: + nd_isrlex = 0; ndl_compare_function = ndl_module_lex_compare; break; default: @@ -4499,7 +4520,7 @@ BlockMask nd_create_blockmask(struct order_spec *ord) BlockMask bm; /* we only create mask table for block order */ - if ( ord->id != 1 ) + if ( ord->id != 1 && ord->id != 257 ) return 0; n = ord->ord.block.length; bm = (BlockMask)MALLOC(sizeof(struct oBlockMask)); @@ -4523,7 +4544,7 @@ EPOS nd_create_epos(struct order_spec *ord) epos = (EPOS)MALLOC_ATOMIC(nd_nvar*sizeof(struct oEPOS)); switch ( ord->id ) { - case 0: + case 0: case 256: if ( nd_isrlex ) { for ( i = 0; i < nd_nvar; i++ ) { epos[i].i = nd_exporigin + (nd_nvar-1-i)/nd_epw; @@ -4536,7 +4557,7 @@ EPOS nd_create_epos(struct order_spec *ord) } } break; - case 1: + case 1: case 257: /* block order */ l = ord->ord.block.length; op = ord->ord.block.order_pair; @@ -6418,9 +6439,9 @@ int nd_monic(int mod,ND *p) PUT_EXP(DL(mr),i+nd_ntrans,e); td += MUL_WEIGHT(e,i+nd_ntrans); } + if ( nd_module ) MPOS(DL(mr)) = MPOS(DL(m)); TD(DL(mr)) = td; if ( nd_blockmask) ndl_weight_mask(DL(mr)); - if ( nd_module ) MPOS(DL(mr)) = MPOS(DL(m)); } } NEXT(mr) = 0;