[BACK]Return to nd.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Annotation of OpenXM_contrib2/asir2000/engine/nd.c, Revision 1.40

1.40    ! noro        1: /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.39 2003/08/21 03:13:01 noro Exp $ */
1.2       noro        2:
1.1       noro        3: #include "ca.h"
                      4: #include "inline.h"
                      5:
                      6: #if defined(__GNUC__)
                      7: #define INLINE inline
                      8: #elif defined(VISUAL)
                      9: #define INLINE __inline
                     10: #else
                     11: #define INLINE
                     12: #endif
                     13:
1.28      noro       14: #define USE_GEOBUCKET 1
                     15:
1.1       noro       16: #define REDTAB_LEN 32003
                     17:
1.40    ! noro       18: /* GeoBucket for polynomial addition */
        !            19:
1.1       noro       20: typedef struct oPGeoBucket {
                     21:        int m;
                     22:        struct oND *body[32];
                     23: } *PGeoBucket;
                     24:
1.40    ! noro       25: /* distributed polynomial; linked list rep. */
1.1       noro       26: typedef struct oND {
                     27:        struct oNM *body;
                     28:        int nv;
1.31      noro       29:        int len;
1.1       noro       30:        int sugar;
                     31: } *ND;
                     32:
1.40    ! noro       33: /* distributed polynomial; array rep. */
1.3       noro       34: typedef struct oNDV {
                     35:        struct oNMV *body;
                     36:        int nv;
1.31      noro       37:        int len;
1.3       noro       38:        int sugar;
                     39: } *NDV;
                     40:
1.40    ! noro       41: /* monomial; linked list rep. */
1.1       noro       42: typedef struct oNM {
                     43:        struct oNM *next;
1.14      noro       44:        union {
                     45:                int m;
                     46:                Q z;
                     47:        } c;
1.1       noro       48:        unsigned int dl[1];
                     49: } *NM;
                     50:
1.40    ! noro       51: /* monomial; array rep. */
1.3       noro       52: typedef struct oNMV {
1.14      noro       53:        union {
                     54:                int m;
                     55:                Q z;
                     56:        } c;
1.3       noro       57:        unsigned int dl[1];
                     58: } *NMV;
                     59:
1.40    ! noro       60: /* history of reducer */
1.13      noro       61: typedef struct oRHist {
                     62:        struct oRHist *next;
                     63:        int index;
1.34      noro       64:        int sugar;
1.13      noro       65:        unsigned int dl[1];
                     66: } *RHist;
                     67:
1.40    ! noro       68: /* S-pair list */
1.1       noro       69: typedef struct oND_pairs {
                     70:        struct oND_pairs *next;
                     71:        int i1,i2;
1.34      noro       72:        int sugar;
1.1       noro       73:        unsigned int lcm[1];
                     74: } *ND_pairs;
                     75:
1.34      noro       76: int (*nd_compare_function)(unsigned int *a1,unsigned int *a2);
1.32      noro       77:
1.21      noro       78: double nd_scale=2;
1.1       noro       79: static unsigned int **nd_bound;
1.19      noro       80: int nd_nvar;
1.32      noro       81: int nd_isrlex;
1.1       noro       82: int nd_epw,nd_bpe,nd_wpd;
                     83: unsigned int nd_mask[32];
                     84: unsigned int nd_mask0,nd_mask1;
1.20      noro       85:
1.1       noro       86: NM _nm_free_list;
                     87: ND _nd_free_list;
                     88: ND_pairs _ndp_free_list;
1.20      noro       89:
                     90: static NDV *nd_ps;
                     91: static NDV *nd_psq;
                     92: RHist *nd_psh;
                     93: int nd_psn,nd_pslen;
                     94:
1.13      noro       95: RHist *nd_red;
1.1       noro       96:
                     97: int nd_found,nd_create,nd_notfirst;
1.13      noro       98: int nm_adv;
1.20      noro       99: int nmv_adv;
1.34      noro      100: int nd_dcomp;
1.1       noro      101:
1.34      noro      102: extern int Top,Reverse,dp_nelim;
1.1       noro      103:
1.40    ! noro      104: /* fundamental macros */
1.34      noro      105: #define TD(d) (d[0])
1.1       noro      106: #define HDL(d) ((d)->body->dl)
1.34      noro      107: #define HTD(d) (TD(HDL(d)))
1.14      noro      108: #define HCM(d) ((d)->body->c.m)
1.16      noro      109: #define HCQ(d) ((d)->body->c.z)
1.14      noro      110: #define CM(a) ((a)->c.m)
1.16      noro      111: #define CQ(a) ((a)->c.z)
1.14      noro      112: #define DL(a) ((a)->dl)
                    113: #define SG(a) ((a)->sugar)
                    114: #define LEN(a) ((a)->len)
1.33      noro      115: #define LCM(a) ((a)->lcm)
1.1       noro      116:
1.40    ! noro      117: /* macros for term comparison */
1.34      noro      118: #define TD_DL_COMPARE(d1,d2)\
                    119: (TD(d1)>TD(d2)?1:(TD(d1)<TD(d2)?-1:ndl_lex_compare(d1+1,d2+1)))
                    120: #define DL_COMPARE(d1,d2)\
                    121: (nd_dcomp?TD_DL_COMPARE(d1,d2):(*nd_compare_function)(d1,d2))
                    122:
1.40    ! noro      123: /* allocators */
1.15      noro      124: #define NEWRHist(r) \
1.34      noro      125: ((r)=(RHist)MALLOC(sizeof(struct oRHist)+nd_wpd*sizeof(unsigned int)))
                    126: #define NEWND_pairs(m) \
                    127: if(!_ndp_free_list)_NDP_alloc();\
                    128: (m)=_ndp_free_list; _ndp_free_list = NEXT(_ndp_free_list)
                    129: #define NEWNM(m)\
                    130: if(!_nm_free_list)_NM_alloc();\
                    131: (m)=_nm_free_list; _nm_free_list = NEXT(_nm_free_list)
                    132: #define MKND(n,m,len,d)\
                    133: if(!_nd_free_list)_ND_alloc();\
                    134: (d)=_nd_free_list; _nd_free_list = (ND)BDY(_nd_free_list);\
                    135: NV(d)=(n); LEN(d)=(len); BDY(d)=(m)
1.40    ! noro      136: #define NEWNDV(d) ((d)=(NDV)MALLOC(sizeof(struct oNDV)))
        !           137: #define MKNDV(n,m,l,d) NEWNDV(d); NV(d)=(n); BDY(d)=(m); LEN(d) = l;
1.1       noro      138:
1.40    ! noro      139: /* allocate and link a new object */
1.13      noro      140: #define NEXTRHist(r,c) \
                    141: if(!(r)){NEWRHist(r);(c)=(r);}else{NEWRHist(NEXT(c));(c)=NEXT(c);}
1.1       noro      142: #define NEXTNM(r,c) \
                    143: if(!(r)){NEWNM(r);(c)=(r);}else{NEWNM(NEXT(c));(c)=NEXT(c);}
                    144: #define NEXTNM2(r,c,s) \
                    145: if(!(r)){(c)=(r)=(s);}else{NEXT(c)=(s);(c)=(s);}
1.40    ! noro      146: #define NEXTND_pairs(r,c) \
        !           147: if(!(r)){NEWND_pairs(r);(c)=(r);}else{NEWND_pairs(NEXT(c));(c)=NEXT(c);}
1.34      noro      148:
1.40    ! noro      149: /* deallocators */
1.1       noro      150: #define FREENM(m) NEXT(m)=_nm_free_list; _nm_free_list=(m)
                    151: #define FREENDP(m) NEXT(m)=_ndp_free_list; _ndp_free_list=(m)
                    152: #define FREEND(m) BDY(m)=(NM)_nd_free_list; _nd_free_list=(m)
                    153:
1.40    ! noro      154: /* macro for increasing pointer to NMV */
        !           155: #define NMV_ADV(m) (m = (NMV)(((char *)m)+nmv_adv))
        !           156:
        !           157: /* external functions */
        !           158: void GC_gcollect();
        !           159: NODE append_one(NODE,int);
1.1       noro      160:
1.40    ! noro      161: /* manipulation of coefficients */
1.20      noro      162: void nd_removecont(int mod,ND p);
1.21      noro      163: void nd_removecont2(ND p1,ND p2);
1.40    ! noro      164: void removecont_array(Q *c,int n);
        !           165:
        !           166: /* GeoBucket functions */
1.25      noro      167: ND normalize_pbucket(int mod,PGeoBucket g);
                    168: int head_pbucket(int mod,PGeoBucket g);
1.26      noro      169: int head_pbucket_q(PGeoBucket g);
1.31      noro      170: void add_pbucket(int mod,PGeoBucket g,ND d);
1.25      noro      171: void free_pbucket(PGeoBucket b);
1.26      noro      172: void mulq_pbucket(PGeoBucket g,Q c);
1.25      noro      173: PGeoBucket create_pbucket();
1.20      noro      174:
1.40    ! noro      175: /* manipulation of pairs and bases */
1.39      noro      176: int nd_newps(int mod,ND a,ND aq);
1.40    ! noro      177: ND_pairs nd_newpairs( NODE g, int t );
1.1       noro      178: ND_pairs nd_minp( ND_pairs d, ND_pairs *prest );
                    179: NODE update_base(NODE nd,int ndp);
1.40    ! noro      180: ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t);
        !           181: ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest );
        !           182: ND_pairs crit_B( ND_pairs d, int s );
        !           183: ND_pairs crit_M( ND_pairs d1 );
        !           184: ND_pairs crit_F( ND_pairs d1 );
1.1       noro      185: int crit_2( int dp1, int dp2 );
1.40    ! noro      186:
        !           187: /* top level functions */
        !           188: void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp);
        !           189: void nd_gr_trace(LIST f,LIST v,int m,int homo,struct order_spec *ord,LIST *rp);
1.27      noro      190: NODE nd_gb(int m,int checkonly);
1.23      noro      191: NODE nd_gb_trace(int m);
1.40    ! noro      192:
        !           193: /* ndl functions */
1.39      noro      194: int ndl_weight(unsigned int *d);
1.34      noro      195: void ndl_dehomogenize(unsigned int *p);
1.40    ! noro      196: void ndl_reconstruct(int obpe,unsigned int *d,unsigned int *r);
        !           197: INLINE int nd_length(ND p);
        !           198: INLINE int ndl_reducible(unsigned int *d1,unsigned int *d2);
        !           199: INLINE int ndl_lex_compare(unsigned int *d1,unsigned int *d2);
        !           200: INLINE int ndl_equal(unsigned int *d1,unsigned int *d2);
        !           201: INLINE void ndl_copy(unsigned int *d1,unsigned int *d2);
        !           202: INLINE void ndl_add(unsigned int *d1,unsigned int *d2,unsigned int *d);
        !           203: INLINE void ndl_sub(unsigned int *d1,unsigned int *d2,unsigned int *d);
        !           204: INLINE int ndl_hash_value(unsigned int *d);
        !           205: INLINE int nd_find_reducer(ND g);
        !           206: INLINE int nd_find_reducer_direct(ND g,NDV *ps,int len);
        !           207:
        !           208: /* normal forms */
1.16      noro      209: int nd_sp(int mod,ND_pairs p,ND *nf);
1.6       noro      210: int nd_find_reducer(ND g);
1.23      noro      211: int nd_find_reducer_direct(ND g,NDV *ps,int len);
1.16      noro      212: int nd_nf(int mod,ND g,int full,ND *nf);
1.30      noro      213: int nd_nf_pbucket(int mod,ND g,int full,ND *nf);
                    214: int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full,ND *rp);
                    215: int nd_nf_direct_pbucket(int mod,ND g,NDV *ps,int len,int full,ND *rp);
1.40    ! noro      216:
        !           217: /* finalizers */
        !           218: NODE nd_reducebase(NODE x);
1.23      noro      219: NODE nd_reduceall(int m,NODE f);
1.27      noro      220: int nd_gbcheck(int m,NODE f);
                    221: int nd_membercheck(int m,NODE f);
1.40    ! noro      222:
        !           223: /* allocators */
        !           224: void nd_free_private_storage();
        !           225: void _NM_alloc();
        !           226: void _ND_alloc();
1.1       noro      227: void nd_free(ND p);
1.40    ! noro      228: void nd_realloc(ND p,int obpe);
        !           229: void nd_free_redlist();
        !           230:
        !           231: /* printing */
1.1       noro      232: void ndl_print(unsigned int *dl);
                    233: void nd_print(ND p);
1.16      noro      234: void nd_print_q(ND p);
1.1       noro      235: void ndp_print(ND_pairs d);
1.40    ! noro      236:
        !           237:
        !           238: /* setup, reconstruct */
        !           239: void nd_init_ord(struct order_spec *spec);
        !           240: ND_pairs nd_reconstruct(int mod,int trace,ND_pairs ndp);
        !           241: void nd_reconstruct_direct(int mod,NDV *ps,int len);
        !           242: void nd_setup(int mod,int trace,NODE f);
        !           243: void nd_setup_parameters();
        !           244:
        !           245: /* ND functions */
        !           246: int nd_check_candidate(NODE input,NODE cand);
        !           247: void nd_mul_c(int mod,ND p,int mul);
        !           248: void nd_mul_c_q(ND p,Q mul);
        !           249: ND nd_remove_head(ND p);
1.1       noro      250: int nd_length(ND p);
1.34      noro      251: void nd_append_red(unsigned int *d,int i);
1.1       noro      252: unsigned int *nd_compute_bound(ND p);
1.5       noro      253: unsigned int *dp_compute_bound(DP p);
1.6       noro      254: ND nd_copy(ND p);
1.40    ! noro      255: ND nd_add(int mod,ND p1,ND p2);
        !           256: ND nd_add_q(ND p1,ND p2);
1.4       noro      257:
1.40    ! noro      258: /* NDV functions */
1.19      noro      259: void ndv_mul_c(int mod,NDV p,int mul);
1.40    ! noro      260: void ndv_mul_c_q(NDV p,Q mul);
        !           261: void ndv_realloc(NDV p,int obpe,int oadv);
        !           262: ND ndv_mul_nm(int mod,NDV p,NM m0);
        !           263: void ndv_dehomogenize(NDV p);
        !           264: void ndv_removecont(int mod,NDV p);
        !           265: void ndv_print(NDV p);
        !           266: void ndv_print_q(NDV p);
        !           267: void ndv_free(NDV p);
        !           268:
        !           269: /* converters */
1.16      noro      270: NDV ndtondv(int mod,ND p);
1.23      noro      271: ND ndvtond(int mod,NDV p);
1.16      noro      272: NDV dptondv(int,DP);
                    273: DP ndvtodp(int,NDV);
1.17      noro      274: ND dptond(int,DP);
                    275: DP ndtodp(int,ND);
1.1       noro      276:
                    277: void nd_free_private_storage()
                    278: {
                    279:        _nd_free_list = 0;
                    280:        _nm_free_list = 0;
1.5       noro      281:        _ndp_free_list = 0;
1.13      noro      282:        bzero(nd_red,sizeof(REDTAB_LEN*sizeof(RHist)));
1.1       noro      283:        GC_gcollect();
                    284: }
                    285:
                    286: void _NM_alloc()
                    287: {
                    288:        NM p;
                    289:        int i;
                    290:
1.11      noro      291:        for ( i = 0; i < 1024; i++ ) {
1.34      noro      292:                p = (NM)GC_malloc(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
1.1       noro      293:                p->next = _nm_free_list; _nm_free_list = p;
                    294:        }
                    295: }
                    296:
                    297: void _ND_alloc()
                    298: {
                    299:        ND p;
                    300:        int i;
                    301:
                    302:        for ( i = 0; i < 1024; i++ ) {
                    303:                p = (ND)GC_malloc(sizeof(struct oND));
                    304:                p->body = (NM)_nd_free_list; _nd_free_list = p;
                    305:        }
                    306: }
                    307:
                    308: void _NDP_alloc()
                    309: {
                    310:        ND_pairs p;
                    311:        int i;
                    312:
1.11      noro      313:        for ( i = 0; i < 1024; i++ ) {
1.1       noro      314:                p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs)
1.34      noro      315:                        +nd_wpd*sizeof(unsigned int));
1.1       noro      316:                p->next = _ndp_free_list; _ndp_free_list = p;
                    317:        }
                    318: }
                    319:
1.30      noro      320: INLINE int nd_length(ND p)
1.1       noro      321: {
                    322:        NM m;
                    323:        int i;
                    324:
                    325:        if ( !p )
                    326:                return 0;
                    327:        else {
                    328:                for ( i = 0, m = BDY(p); m; m = NEXT(m), i++ );
                    329:                return i;
                    330:        }
                    331: }
                    332:
1.35      noro      333: INLINE int ndl_reducible(unsigned int *d1,unsigned int *d2)
1.1       noro      334: {
                    335:        unsigned int u1,u2;
                    336:        int i,j;
                    337:
1.34      noro      338:        if ( TD(d1) < TD(d2) ) return 0;
1.1       noro      339:        switch ( nd_bpe ) {
                    340:                case 4:
1.34      noro      341:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      342:                                u1 = d1[i]; u2 = d2[i];
                    343:                                if ( (u1&0xf0000000) < (u2&0xf0000000) ) return 0;
                    344:                                if ( (u1&0xf000000) < (u2&0xf000000) ) return 0;
                    345:                                if ( (u1&0xf00000) < (u2&0xf00000) ) return 0;
                    346:                                if ( (u1&0xf0000) < (u2&0xf0000) ) return 0;
                    347:                                if ( (u1&0xf000) < (u2&0xf000) ) return 0;
                    348:                                if ( (u1&0xf00) < (u2&0xf00) ) return 0;
                    349:                                if ( (u1&0xf0) < (u2&0xf0) ) return 0;
                    350:                                if ( (u1&0xf) < (u2&0xf) ) return 0;
                    351:                        }
                    352:                        return 1;
                    353:                        break;
                    354:                case 6:
1.34      noro      355:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      356:                                u1 = d1[i]; u2 = d2[i];
                    357:                                if ( (u1&0x3f000000) < (u2&0x3f000000) ) return 0;
                    358:                                if ( (u1&0xfc0000) < (u2&0xfc0000) ) return 0;
                    359:                                if ( (u1&0x3f000) < (u2&0x3f000) ) return 0;
                    360:                                if ( (u1&0xfc0) < (u2&0xfc0) ) return 0;
                    361:                                if ( (u1&0x3f) < (u2&0x3f) ) return 0;
                    362:                        }
                    363:                        return 1;
                    364:                        break;
                    365:                case 8:
1.34      noro      366:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      367:                                u1 = d1[i]; u2 = d2[i];
                    368:                                if ( (u1&0xff000000) < (u2&0xff000000) ) return 0;
                    369:                                if ( (u1&0xff0000) < (u2&0xff0000) ) return 0;
                    370:                                if ( (u1&0xff00) < (u2&0xff00) ) return 0;
                    371:                                if ( (u1&0xff) < (u2&0xff) ) return 0;
                    372:                        }
                    373:                        return 1;
                    374:                        break;
                    375:                case 16:
1.34      noro      376:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      377:                                u1 = d1[i]; u2 = d2[i];
                    378:                                if ( (u1&0xffff0000) < (u2&0xffff0000) ) return 0;
                    379:                                if ( (u1&0xffff) < (u2&0xffff) ) return 0;
                    380:                        }
                    381:                        return 1;
                    382:                        break;
                    383:                case 32:
1.34      noro      384:                        for ( i = 1; i <= nd_wpd; i++ )
1.1       noro      385:                                if ( d1[i] < d2[i] ) return 0;
                    386:                        return 1;
                    387:                        break;
                    388:                default:
1.34      noro      389:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      390:                                u1 = d1[i]; u2 = d2[i];
                    391:                                for ( j = 0; j < nd_epw; j++ )
                    392:                                        if ( (u1&nd_mask[j]) < (u2&nd_mask[j]) ) return 0;
                    393:                        }
                    394:                        return 1;
                    395:        }
                    396: }
                    397:
1.34      noro      398: void ndl_dehomogenize(unsigned int *d)
1.23      noro      399: {
                    400:        unsigned int mask;
                    401:        unsigned int h;
1.31      noro      402:        int i,bits;
1.23      noro      403:
1.32      noro      404:        if ( nd_isrlex ) {
1.23      noro      405:                if ( nd_bpe == 32 ) {
1.34      noro      406:                        h = d[1];
                    407:                        for ( i = 2; i <= nd_wpd; i++ )
1.23      noro      408:                                d[i-1] = d[i];
                    409:                        d[i-1] = 0;
1.34      noro      410:                        TD(d) -= h;
1.23      noro      411:                } else {
1.31      noro      412:                        bits = nd_epw*nd_bpe;
                    413:                        mask = bits==32?0xffffffff:((1<<(nd_epw*nd_bpe))-1);
1.34      noro      414:                        h = (d[1]>>((nd_epw-1)*nd_bpe))&nd_mask0;
                    415:                        for ( i = 1; i <= nd_wpd; i++ )
1.23      noro      416:                                d[i] = ((d[i]<<nd_bpe)&mask)
1.36      noro      417:                                        |(i+1<=nd_wpd?((d[i+1]>>((nd_epw-1)*nd_bpe))&nd_mask0):0);
1.34      noro      418:                        TD(d) -= h;
1.23      noro      419:                }
1.34      noro      420:        } else
                    421:                TD(d) -= ((d[(nd_nvar-1)/nd_epw+1]>>
                    422:                        ((nd_epw-((nd_nvar-1)%nd_epw)-1)*nd_bpe))&((1<<nd_bpe)-1));
1.23      noro      423: }
                    424:
1.1       noro      425: void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned int *d)
                    426: {
                    427:        unsigned int t1,t2,u,u1,u2;
                    428:        int i,j;
                    429:
                    430:        switch ( nd_bpe ) {
                    431:                case 4:
1.34      noro      432:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      433:                                u1 = d1[i]; u2 = d2[i];
                    434:                                t1 = (u1&0xf0000000); t2 = (u2&0xf0000000); u = t1>t2?t1:t2;
                    435:                                t1 = (u1&0xf000000); t2 = (u2&0xf000000); u |= t1>t2?t1:t2;
                    436:                                t1 = (u1&0xf00000); t2 = (u2&0xf00000); u |= t1>t2?t1:t2;
                    437:                                t1 = (u1&0xf0000); t2 = (u2&0xf0000); u |= t1>t2?t1:t2;
                    438:                                t1 = (u1&0xf000); t2 = (u2&0xf000); u |= t1>t2?t1:t2;
                    439:                                t1 = (u1&0xf00); t2 = (u2&0xf00); u |= t1>t2?t1:t2;
                    440:                                t1 = (u1&0xf0); t2 = (u2&0xf0); u |= t1>t2?t1:t2;
                    441:                                t1 = (u1&0xf); t2 = (u2&0xf); u |= t1>t2?t1:t2;
                    442:                                d[i] = u;
                    443:                        }
                    444:                        break;
                    445:                case 6:
1.34      noro      446:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      447:                                u1 = d1[i]; u2 = d2[i];
                    448:                                t1 = (u1&0x3f000000); t2 = (u2&0x3f000000); u = t1>t2?t1:t2;
                    449:                                t1 = (u1&0xfc0000); t2 = (u2&0xfc0000); u |= t1>t2?t1:t2;
                    450:                                t1 = (u1&0x3f000); t2 = (u2&0x3f000); u |= t1>t2?t1:t2;
                    451:                                t1 = (u1&0xfc0); t2 = (u2&0xfc0); u |= t1>t2?t1:t2;
                    452:                                t1 = (u1&0x3f); t2 = (u2&0x3f); u |= t1>t2?t1:t2;
                    453:                                d[i] = u;
                    454:                        }
                    455:                        break;
                    456:                case 8:
1.34      noro      457:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      458:                                u1 = d1[i]; u2 = d2[i];
                    459:                                t1 = (u1&0xff000000); t2 = (u2&0xff000000); u = t1>t2?t1:t2;
                    460:                                t1 = (u1&0xff0000); t2 = (u2&0xff0000); u |= t1>t2?t1:t2;
                    461:                                t1 = (u1&0xff00); t2 = (u2&0xff00); u |= t1>t2?t1:t2;
                    462:                                t1 = (u1&0xff); t2 = (u2&0xff); u |= t1>t2?t1:t2;
                    463:                                d[i] = u;
                    464:                        }
                    465:                        break;
                    466:                case 16:
1.34      noro      467:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      468:                                u1 = d1[i]; u2 = d2[i];
                    469:                                t1 = (u1&0xffff0000); t2 = (u2&0xffff0000); u = t1>t2?t1:t2;
                    470:                                t1 = (u1&0xffff); t2 = (u2&0xffff); u |= t1>t2?t1:t2;
                    471:                                d[i] = u;
                    472:                        }
                    473:                        break;
                    474:                case 32:
1.34      noro      475:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      476:                                u1 = d1[i]; u2 = d2[i];
                    477:                                d[i] = u1>u2?u1:u2;
                    478:                        }
                    479:                        break;
                    480:                default:
1.34      noro      481:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      482:                                u1 = d1[i]; u2 = d2[i];
                    483:                                for ( j = 0, u = 0; j < nd_epw; j++ ) {
                    484:                                        t1 = (u1&nd_mask[j]); t2 = (u2&nd_mask[j]); u |= t1>t2?t1:t2;
                    485:                                }
                    486:                                d[i] = u;
                    487:                        }
                    488:                        break;
                    489:        }
1.39      noro      490:        TD(d) = ndl_weight(d);
1.1       noro      491: }
                    492:
1.39      noro      493: int ndl_weight(unsigned int *d)
1.1       noro      494: {
                    495:        unsigned int t,u;
                    496:        int i,j;
                    497:
1.34      noro      498:        for ( t = 0, i = 1; i <= nd_wpd; i++ ) {
1.1       noro      499:                u = d[i];
                    500:                for ( j = 0; j < nd_epw; j++, u>>=nd_bpe )
                    501:                        t += (u&nd_mask0);
                    502:        }
                    503:        return t;
                    504: }
                    505:
1.34      noro      506: INLINE int ndl_lex_compare(unsigned int *d1,unsigned int *d2)
1.1       noro      507: {
                    508:        int i;
                    509:
                    510:        for ( i = 0; i < nd_wpd; i++, d1++, d2++ )
                    511:                if ( *d1 > *d2 )
1.32      noro      512:                        return nd_isrlex ? -1 : 1;
1.1       noro      513:                else if ( *d1 < *d2 )
1.32      noro      514:                        return nd_isrlex ? 1 : -1;
1.1       noro      515:        return 0;
                    516: }
                    517:
                    518: INLINE int ndl_equal(unsigned int *d1,unsigned int *d2)
                    519: {
                    520:        int i;
                    521:
1.34      noro      522:        if ( *d1++ != *d2++ ) return 0;
                    523:        for ( i = 1; i <= nd_wpd; i++ )
                    524:                if ( *d1++ != *d2++ )
1.1       noro      525:                        return 0;
                    526:        return 1;
                    527: }
                    528:
1.6       noro      529: INLINE void ndl_copy(unsigned int *d1,unsigned int *d2)
                    530: {
                    531:        int i;
                    532:
                    533:        switch ( nd_wpd ) {
                    534:                case 1:
1.34      noro      535:                        TD(d2) = TD(d1);
                    536:                        d2[1] = d1[1];
1.6       noro      537:                        break;
                    538:                case 2:
1.34      noro      539:                        TD(d2) = TD(d1);
1.6       noro      540:                        d2[1] = d1[1];
1.34      noro      541:                        d2[2] = d1[2];
1.6       noro      542:                        break;
                    543:                default:
1.34      noro      544:                        for ( i = 0; i <= nd_wpd; i++ )
1.6       noro      545:                                d2[i] = d1[i];
                    546:                        break;
                    547:        }
                    548: }
                    549:
1.1       noro      550: INLINE void ndl_add(unsigned int *d1,unsigned int *d2,unsigned int *d)
                    551: {
                    552:        int i;
                    553:
1.36      noro      554:        TD(d) = TD(d1)+TD(d2);
1.6       noro      555:        switch ( nd_wpd ) {
                    556:                case 1:
1.34      noro      557:                        d[1] = d1[1]+d2[1];
1.6       noro      558:                        break;
                    559:                case 2:
                    560:                        d[1] = d1[1]+d2[1];
1.34      noro      561:                        d[2] = d1[2]+d2[2];
1.6       noro      562:                        break;
                    563:                default:
1.34      noro      564:                        for ( i = 1; i <= nd_wpd; i++ )
1.6       noro      565:                                d[i] = d1[i]+d2[i];
                    566:                        break;
                    567:        }
                    568: }
                    569:
1.34      noro      570: INLINE void ndl_sub(unsigned int *d1,unsigned int *d2,unsigned int *d)
1.6       noro      571: {
                    572:        int i;
                    573:
1.34      noro      574:        for ( i = 0; i <= nd_wpd; i++ )
1.1       noro      575:                d[i] = d1[i]-d2[i];
                    576: }
                    577:
                    578: int ndl_disjoint(unsigned int *d1,unsigned int *d2)
                    579: {
                    580:        unsigned int t1,t2,u,u1,u2;
                    581:        int i,j;
                    582:
                    583:        switch ( nd_bpe ) {
                    584:                case 4:
1.34      noro      585:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      586:                                u1 = d1[i]; u2 = d2[i];
                    587:                                t1 = u1&0xf0000000; t2 = u2&0xf0000000; if ( t1&&t2 ) return 0;
                    588:                                t1 = u1&0xf000000; t2 = u2&0xf000000; if ( t1&&t2 ) return 0;
                    589:                                t1 = u1&0xf00000; t2 = u2&0xf00000; if ( t1&&t2 ) return 0;
                    590:                                t1 = u1&0xf0000; t2 = u2&0xf0000; if ( t1&&t2 ) return 0;
                    591:                                t1 = u1&0xf000; t2 = u2&0xf000; if ( t1&&t2 ) return 0;
                    592:                                t1 = u1&0xf00; t2 = u2&0xf00; if ( t1&&t2 ) return 0;
                    593:                                t1 = u1&0xf0; t2 = u2&0xf0; if ( t1&&t2 ) return 0;
                    594:                                t1 = u1&0xf; t2 = u2&0xf; if ( t1&&t2 ) return 0;
                    595:                        }
                    596:                        return 1;
                    597:                        break;
                    598:                case 6:
1.34      noro      599:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      600:                                u1 = d1[i]; u2 = d2[i];
                    601:                                t1 = u1&0x3f000000; t2 = u2&0x3f000000; if ( t1&&t2 ) return 0;
                    602:                                t1 = u1&0xfc0000; t2 = u2&0xfc0000; if ( t1&&t2 ) return 0;
                    603:                                t1 = u1&0x3f000; t2 = u2&0x3f000; if ( t1&&t2 ) return 0;
                    604:                                t1 = u1&0xfc0; t2 = u2&0xfc0; if ( t1&&t2 ) return 0;
                    605:                                t1 = u1&0x3f; t2 = u2&0x3f; if ( t1&&t2 ) return 0;
                    606:                        }
                    607:                        return 1;
                    608:                        break;
                    609:                case 8:
1.34      noro      610:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      611:                                u1 = d1[i]; u2 = d2[i];
                    612:                                t1 = u1&0xff000000; t2 = u2&0xff000000; if ( t1&&t2 ) return 0;
                    613:                                t1 = u1&0xff0000; t2 = u2&0xff0000; if ( t1&&t2 ) return 0;
                    614:                                t1 = u1&0xff00; t2 = u2&0xff00; if ( t1&&t2 ) return 0;
                    615:                                t1 = u1&0xff; t2 = u2&0xff; if ( t1&&t2 ) return 0;
                    616:                        }
                    617:                        return 1;
                    618:                        break;
                    619:                case 16:
1.34      noro      620:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      621:                                u1 = d1[i]; u2 = d2[i];
                    622:                                t1 = u1&0xffff0000; t2 = u2&0xffff0000; if ( t1&&t2 ) return 0;
                    623:                                t1 = u1&0xffff; t2 = u2&0xffff; if ( t1&&t2 ) return 0;
                    624:                        }
                    625:                        return 1;
                    626:                        break;
                    627:                case 32:
1.34      noro      628:                        for ( i = 1; i <= nd_wpd; i++ )
1.1       noro      629:                                if ( d1[i] && d2[i] ) return 0;
                    630:                        return 1;
                    631:                        break;
                    632:                default:
1.34      noro      633:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.1       noro      634:                                u1 = d1[i]; u2 = d2[i];
                    635:                                for ( j = 0; j < nd_epw; j++ ) {
                    636:                                        if ( (u1&nd_mask0) && (u2&nd_mask0) ) return 0;
                    637:                                        u1 >>= nd_bpe; u2 >>= nd_bpe;
                    638:                                }
                    639:                        }
                    640:                        return 1;
                    641:                        break;
                    642:        }
                    643: }
                    644:
1.5       noro      645: int ndl_check_bound2(int index,unsigned int *d2)
1.1       noro      646: {
1.5       noro      647:        unsigned int u2;
                    648:        unsigned int *d1;
                    649:        int i,j,ind,k;
1.1       noro      650:
1.5       noro      651:        d1 = nd_bound[index];
                    652:        ind = 0;
                    653:        switch ( nd_bpe ) {
                    654:                case 4:
1.34      noro      655:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.5       noro      656:                                u2 = d2[i];
                    657:                                if ( d1[ind++]+((u2>>28)&0xf) >= 0x10 ) return 1;
                    658:                                if ( d1[ind++]+((u2>>24)&0xf) >= 0x10 ) return 1;
                    659:                                if ( d1[ind++]+((u2>>20)&0xf) >= 0x10 ) return 1;
                    660:                                if ( d1[ind++]+((u2>>16)&0xf) >= 0x10 ) return 1;
                    661:                                if ( d1[ind++]+((u2>>12)&0xf) >= 0x10 ) return 1;
                    662:                                if ( d1[ind++]+((u2>>8)&0xf) >= 0x10 ) return 1;
                    663:                                if ( d1[ind++]+((u2>>4)&0xf) >= 0x10 ) return 1;
                    664:                                if ( d1[ind++]+(u2&0xf) >= 0x10 ) return 1;
                    665:                        }
                    666:                        return 0;
                    667:                        break;
                    668:                case 6:
1.34      noro      669:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.5       noro      670:                                u2 = d2[i];
                    671:                                if ( d1[ind++]+((u2>>24)&0x3f) >= 0x40 ) return 1;
                    672:                                if ( d1[ind++]+((u2>>18)&0x3f) >= 0x40 ) return 1;
                    673:                                if ( d1[ind++]+((u2>>12)&0x3f) >= 0x40 ) return 1;
                    674:                                if ( d1[ind++]+((u2>>6)&0x3f) >= 0x40 ) return 1;
                    675:                                if ( d1[ind++]+(u2&0x3f) >= 0x40 ) return 1;
                    676:                        }
                    677:                        return 0;
                    678:                        break;
                    679:                case 8:
1.34      noro      680:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.5       noro      681:                                u2 = d2[i];
                    682:                                if ( d1[ind++]+((u2>>24)&0xff) >= 0x100 ) return 1;
                    683:                                if ( d1[ind++]+((u2>>16)&0xff) >= 0x100 ) return 1;
                    684:                                if ( d1[ind++]+((u2>>8)&0xff) >= 0x100 ) return 1;
                    685:                                if ( d1[ind++]+(u2&0xff) >= 0x100 ) return 1;
                    686:                        }
                    687:                        return 0;
                    688:                        break;
                    689:                case 16:
1.34      noro      690:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.5       noro      691:                                u2 = d2[i];
                    692:                                if ( d1[ind++]+((u2>>16)&0xffff) > 0x10000 ) return 1;
                    693:                                if ( d1[ind++]+(u2&0xffff) > 0x10000 ) return 1;
                    694:                        }
                    695:                        return 0;
                    696:                        break;
                    697:                case 32:
1.34      noro      698:                        for ( i = 1; i <= nd_wpd; i++ )
1.5       noro      699:                                if ( d1[i]+d2[i]<d1[i] ) return 1;
                    700:                        return 0;
                    701:                        break;
                    702:                default:
1.34      noro      703:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.5       noro      704:                                u2 = d2[i];
                    705:                                k = (nd_epw-1)*nd_bpe;
                    706:                                for ( j = 0; j < nd_epw; j++, k -= nd_bpe )
                    707:                                        if ( d1[ind++]+((u2>>k)&nd_mask0) > nd_mask0 ) return 1;
                    708:                        }
                    709:                        return 0;
                    710:                        break;
                    711:        }
1.1       noro      712: }
                    713:
1.23      noro      714: int ndl_check_bound2_direct(unsigned int *d1,unsigned int *d2)
                    715: {
                    716:        unsigned int u1,u2;
                    717:        int i,j,k;
                    718:
                    719:        switch ( nd_bpe ) {
                    720:                case 4:
1.34      noro      721:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.23      noro      722:                                u1 = d1[i]; u2 = d2[i];
                    723:                                if ( ((u1>>28)&0xf)+((u2>>28)&0xf) >= 0x10 ) return 1;
                    724:                                if ( ((u1>>24)&0xf)+((u2>>24)&0xf) >= 0x10 ) return 1;
                    725:                                if ( ((u1>>20)&0xf)+((u2>>20)&0xf) >= 0x10 ) return 1;
                    726:                                if ( ((u1>>16)&0xf)+((u2>>16)&0xf) >= 0x10 ) return 1;
                    727:                                if ( ((u1>>12)&0xf)+((u2>>12)&0xf) >= 0x10 ) return 1;
                    728:                                if ( ((u1>>8)&0xf)+((u2>>8)&0xf) >= 0x10 ) return 1;
                    729:                                if ( ((u1>>4)&0xf)+((u2>>4)&0xf) >= 0x10 ) return 1;
                    730:                                if ( (u1&0xf)+(u2&0xf) >= 0x10 ) return 1;
                    731:                        }
                    732:                        return 0;
                    733:                        break;
                    734:                case 6:
1.34      noro      735:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.23      noro      736:                                u1 = d1[i]; u2 = d2[i];
                    737:                                if ( ((u1>>24)&0x3f)+((u2>>24)&0x3f) >= 0x40 ) return 1;
                    738:                                if ( ((u1>>18)&0x3f)+((u2>>18)&0x3f) >= 0x40 ) return 1;
                    739:                                if ( ((u1>>12)&0x3f)+((u2>>12)&0x3f) >= 0x40 ) return 1;
                    740:                                if ( ((u1>>6)&0x3f)+((u2>>6)&0x3f) >= 0x40 ) return 1;
                    741:                                if ( (u1&0x3f)+(u2&0x3f) >= 0x40 ) return 1;
                    742:                        }
                    743:                        return 0;
                    744:                        break;
                    745:                case 8:
1.34      noro      746:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.23      noro      747:                                u1 = d1[i]; u2 = d2[i];
                    748:                                if ( ((u1>>24)&0xff)+((u2>>24)&0xff) >= 0x100 ) return 1;
                    749:                                if ( ((u1>>16)&0xff)+((u2>>16)&0xff) >= 0x100 ) return 1;
                    750:                                if ( ((u1>>8)&0xff)+((u2>>8)&0xff) >= 0x100 ) return 1;
                    751:                                if ( (u1&0xff)+(u2&0xff) >= 0x100 ) return 1;
                    752:                        }
                    753:                        return 0;
                    754:                        break;
                    755:                case 16:
1.34      noro      756:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.23      noro      757:                                u1 = d1[i]; u2 = d2[i];
                    758:                                        if ( ((u1>>16)&0xffff)+((u2>>16)&0xffff) > 0x10000 ) return 1;
                    759:                                        if ( (u2&0xffff)+(u2&0xffff) > 0x10000 ) return 1;
                    760:                        }
                    761:                        return 0;
                    762:                        break;
                    763:                case 32:
1.34      noro      764:                        for ( i = 1; i <= nd_wpd; i++ )
1.23      noro      765:                                if ( d1[i]+d2[i]<d1[i] ) return 1;
                    766:                        return 0;
                    767:                        break;
                    768:                default:
1.34      noro      769:                        for ( i = 1; i <= nd_wpd; i++ ) {
1.23      noro      770:                                u1 = d1[i]; u2 = d2[i];
                    771:                                k = (nd_epw-1)*nd_bpe;
                    772:                                for ( j = 0; j < nd_epw; j++, k -= nd_bpe )
                    773:                                        if ( ((u1>>k)&nd_mask0)+((u2>>k)&nd_mask0) > nd_mask0 )
                    774:                                                return 1;
                    775:                        }
                    776:                        return 0;
                    777:                        break;
                    778:        }
                    779: }
                    780:
1.34      noro      781: INLINE int ndl_hash_value(unsigned int *d)
1.1       noro      782: {
                    783:        int i;
                    784:        int r;
                    785:
1.34      noro      786:        r = 0;
                    787:        for ( i = 0; i <= nd_wpd; i++ )
1.1       noro      788:                r = ((r<<16)+d[i])%REDTAB_LEN;
                    789:        return r;
                    790: }
                    791:
1.9       noro      792: INLINE int nd_find_reducer(ND g)
1.1       noro      793: {
1.13      noro      794:        RHist r;
1.34      noro      795:        unsigned int *dg;
1.6       noro      796:        int d,k,i;
1.1       noro      797:
1.34      noro      798:        dg = HDL(g);
1.39      noro      799: #if 1
1.34      noro      800:        d = ndl_hash_value(HDL(g));
1.13      noro      801:        for ( r = nd_red[d], k = 0; r; r = NEXT(r), k++ ) {
1.34      noro      802:                if ( ndl_equal(dg,DL(r)) ) {
1.1       noro      803:                        if ( k > 0 ) nd_notfirst++;
                    804:                        nd_found++;
1.13      noro      805:                        return r->index;
1.1       noro      806:                }
                    807:        }
1.39      noro      808: #endif
1.13      noro      809:        if ( Reverse )
                    810:                for ( i = nd_psn-1; i >= 0; i-- ) {
                    811:                        r = nd_psh[i];
1.34      noro      812:                        if ( ndl_reducible(dg,DL(r)) ) {
1.13      noro      813:                                nd_create++;
1.34      noro      814:                                nd_append_red(dg,i);
1.13      noro      815:                                return i;
                    816:                        }
                    817:                }
                    818:        else
                    819:                for ( i = 0; i < nd_psn; i++ ) {
                    820:                        r = nd_psh[i];
1.34      noro      821:                        if ( ndl_reducible(dg,DL(r)) ) {
1.13      noro      822:                                nd_create++;
1.34      noro      823:                                nd_append_red(dg,i);
1.13      noro      824:                                return i;
                    825:                        }
1.1       noro      826:                }
1.6       noro      827:        return -1;
1.1       noro      828: }
                    829:
1.23      noro      830: INLINE int nd_find_reducer_direct(ND g,NDV *ps,int len)
                    831: {
                    832:        NDV r;
1.31      noro      833:        RHist s;
                    834:        int d,k,i;
1.23      noro      835:
                    836:        if ( Reverse )
                    837:                for ( i = len-1; i >= 0; i-- ) {
                    838:                        r = ps[i];
1.34      noro      839:                        if ( ndl_reducible(HDL(g),HDL(r)) ) {
                    840:                                nd_append_red(HDL(g),i);
1.23      noro      841:                                return i;
                    842:                        }
                    843:                }
                    844:        else
                    845:                for ( i = 0; i < len; i++ ) {
                    846:                        r = ps[i];
1.34      noro      847:                        if ( ndl_reducible(HDL(g),HDL(r)) ) {
                    848:                                nd_append_red(HDL(g),i);
1.23      noro      849:                                return i;
                    850:                        }
                    851:                }
                    852:        return -1;
                    853: }
                    854:
1.31      noro      855: ND nd_add(int mod,ND p1,ND p2)
1.1       noro      856: {
                    857:        int n,c;
1.34      noro      858:        int t,can,td1,td2;
1.1       noro      859:        ND r;
                    860:        NM m1,m2,mr0,mr,s;
                    861:
1.34      noro      862:        if ( !p1 ) return p2;
                    863:        else if ( !p2 ) return p1;
                    864:        else if ( !mod ) return nd_add_q(p1,p2);
1.1       noro      865:        else {
1.30      noro      866:                can = 0;
1.1       noro      867:                for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) {
1.34      noro      868:                        c = DL_COMPARE(DL(m1),DL(m2));
1.1       noro      869:                        switch ( c ) {
                    870:                                case 0:
1.19      noro      871:                                        t = ((CM(m1))+(CM(m2))) - mod;
1.34      noro      872:                                        if ( t < 0 ) t += mod;
1.1       noro      873:                                        s = m1; m1 = NEXT(m1);
                    874:                                        if ( t ) {
1.34      noro      875:                                                can++; NEXTNM2(mr0,mr,s); CM(mr) = (t);
1.1       noro      876:                                        } else {
1.34      noro      877:                                                can += 2; FREENM(s);
1.1       noro      878:                                        }
                    879:                                        s = m2; m2 = NEXT(m2); FREENM(s);
                    880:                                        break;
                    881:                                case 1:
                    882:                                        s = m1; m1 = NEXT(m1); NEXTNM2(mr0,mr,s);
                    883:                                        break;
                    884:                                case -1:
                    885:                                        s = m2; m2 = NEXT(m2); NEXTNM2(mr0,mr,s);
                    886:                                        break;
                    887:                        }
                    888:                }
                    889:                if ( !mr0 )
1.34      noro      890:                        if ( m1 ) mr0 = m1;
                    891:                        else if ( m2 ) mr0 = m2;
                    892:                        else return 0;
                    893:                else if ( m1 ) NEXT(mr) = m1;
                    894:                else if ( m2 ) NEXT(mr) = m2;
                    895:                else NEXT(mr) = 0;
1.1       noro      896:                BDY(p1) = mr0;
1.14      noro      897:                SG(p1) = MAX(SG(p1),SG(p2));
1.31      noro      898:                LEN(p1) = LEN(p1)+LEN(p2)-can;
1.1       noro      899:                FREEND(p2);
                    900:                return p1;
                    901:        }
                    902: }
                    903:
1.31      noro      904: ND nd_add_q(ND p1,ND p2)
1.17      noro      905: {
1.30      noro      906:        int n,c,can;
1.17      noro      907:        ND r;
                    908:        NM m1,m2,mr0,mr,s;
                    909:        Q t;
                    910:
1.34      noro      911:        if ( !p1 ) return p2;
                    912:        else if ( !p2 ) return p1;
1.31      noro      913:        else {
1.30      noro      914:                can = 0;
1.17      noro      915:                for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) {
1.34      noro      916:                        c = DL_COMPARE(DL(m1),DL(m2));
1.17      noro      917:                        switch ( c ) {
                    918:                                case 0:
                    919:                                        addq(CQ(m1),CQ(m2),&t);
                    920:                                        s = m1; m1 = NEXT(m1);
                    921:                                        if ( t ) {
1.34      noro      922:                                                can++; NEXTNM2(mr0,mr,s); CQ(mr) = (t);
1.17      noro      923:                                        } else {
1.34      noro      924:                                                can += 2; FREENM(s);
1.17      noro      925:                                        }
                    926:                                        s = m2; m2 = NEXT(m2); FREENM(s);
                    927:                                        break;
                    928:                                case 1:
                    929:                                        s = m1; m1 = NEXT(m1); NEXTNM2(mr0,mr,s);
                    930:                                        break;
                    931:                                case -1:
                    932:                                        s = m2; m2 = NEXT(m2); NEXTNM2(mr0,mr,s);
                    933:                                        break;
                    934:                        }
                    935:                }
                    936:                if ( !mr0 )
1.34      noro      937:                        if ( m1 ) mr0 = m1;
                    938:                        else if ( m2 ) mr0 = m2;
                    939:                        else return 0;
                    940:                else if ( m1 ) NEXT(mr) = m1;
                    941:                else if ( m2 ) NEXT(mr) = m2;
                    942:                else NEXT(mr) = 0;
1.17      noro      943:                BDY(p1) = mr0;
                    944:                SG(p1) = MAX(SG(p1),SG(p2));
1.31      noro      945:                LEN(p1) = LEN(p1)+LEN(p2)-can;
1.17      noro      946:                FREEND(p2);
                    947:                return p1;
                    948:        }
                    949: }
                    950:
1.1       noro      951: /* ret=1 : success, ret=0 : overflow */
1.16      noro      952: int nd_nf(int mod,ND g,int full,ND *rp)
1.1       noro      953: {
1.11      noro      954:        ND d;
1.1       noro      955:        NM m,mrd,tail;
1.7       noro      956:        NM mul;
1.10      noro      957:        int n,sugar,psugar,sugar0,stat,index;
1.30      noro      958:        int c,c1,c2,dummy;
1.17      noro      959:        RHist h;
1.11      noro      960:        NDV p,red;
1.16      noro      961:        Q cg,cred,gcd;
1.21      noro      962:        double hmag;
1.1       noro      963:
                    964:        if ( !g ) {
                    965:                *rp = 0;
                    966:                return 1;
                    967:        }
1.34      noro      968:        if ( !mod ) hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
1.21      noro      969:
1.14      noro      970:        sugar0 = sugar = SG(g);
1.1       noro      971:        n = NV(g);
1.34      noro      972:        mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
1.1       noro      973:        for ( d = 0; g; ) {
1.6       noro      974:                index = nd_find_reducer(g);
                    975:                if ( index >= 0 ) {
1.17      noro      976:                        h = nd_psh[index];
                    977:                        ndl_sub(HDL(g),DL(h),DL(mul));
1.14      noro      978:                        if ( ndl_check_bound2(index,DL(mul)) ) {
1.6       noro      979:                                nd_free(g); nd_free(d);
                    980:                                return 0;
                    981:                        }
1.16      noro      982:                        if ( mod ) {
1.17      noro      983:                                p = nd_ps[index];
1.19      noro      984:                                c1 = invm(HCM(p),mod); c2 = mod-HCM(g);
                    985:                                DMAR(c1,c2,0,mod,c); CM(mul) = c;
1.16      noro      986:                        } else {
1.20      noro      987:                                p = nd_psq[index];
1.17      noro      988:                                igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred);
1.16      noro      989:                                chsgnq(cg,&CQ(mul));
1.20      noro      990:                                nd_mul_c_q(d,cred); nd_mul_c_q(g,cred);
1.16      noro      991:                        }
1.31      noro      992:                        g = nd_add(mod,g,ndv_mul_nm(mod,p,mul));
1.34      noro      993:                        sugar = MAX(sugar,SG(p)+TD(DL(mul)));
1.22      noro      994:                        if ( !mod && hmag && g && ((double)(p_mag((P)HCQ(g))) > hmag) ) {
1.21      noro      995:                                nd_removecont2(d,g);
                    996:                                hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
                    997:                        }
1.1       noro      998:                } else if ( !full ) {
                    999:                        *rp = g;
                   1000:                        return 1;
                   1001:                } else {
                   1002:                        m = BDY(g);
                   1003:                        if ( NEXT(m) ) {
1.34      noro     1004:                                BDY(g) = NEXT(m); NEXT(m) = 0; LEN(g)--;
1.1       noro     1005:                        } else {
                   1006:                                FREEND(g); g = 0;
                   1007:                        }
                   1008:                        if ( d ) {
1.34      noro     1009:                                NEXT(tail)=m; tail=m; LEN(d)++;
1.1       noro     1010:                        } else {
1.34      noro     1011:                                MKND(n,m,1,d); tail = BDY(d);
1.1       noro     1012:                        }
                   1013:                }
                   1014:        }
1.34      noro     1015:        if ( d ) SG(d) = sugar;
1.1       noro     1016:        *rp = d;
                   1017:        return 1;
                   1018: }
1.28      noro     1019:
1.30      noro     1020: int nd_nf_pbucket(int mod,ND g,int full,ND *rp)
1.25      noro     1021: {
                   1022:        int hindex,index;
                   1023:        NDV p;
                   1024:        ND u,d,red;
                   1025:        NODE l;
1.31      noro     1026:        NM mul,m,mrd,tail;
1.25      noro     1027:        int sugar,psugar,n,h_reducible;
                   1028:        PGeoBucket bucket;
                   1029:        int c,c1,c2;
1.26      noro     1030:        Q cg,cred,gcd,zzz;
1.25      noro     1031:        RHist h;
1.28      noro     1032:        double hmag,gmag;
1.25      noro     1033:
                   1034:        if ( !g ) {
                   1035:                *rp = 0;
                   1036:                return 1;
                   1037:        }
                   1038:        sugar = SG(g);
                   1039:        n = NV(g);
1.34      noro     1040:        if ( !mod ) hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
1.25      noro     1041:        bucket = create_pbucket();
1.31      noro     1042:        add_pbucket(mod,bucket,g);
1.25      noro     1043:        d = 0;
1.34      noro     1044:        mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
1.25      noro     1045:        while ( 1 ) {
1.26      noro     1046:                hindex = mod?head_pbucket(mod,bucket):head_pbucket_q(bucket);
1.25      noro     1047:                if ( hindex < 0 ) {
1.34      noro     1048:                        if ( d ) SG(d) = sugar;
1.25      noro     1049:                        *rp = d;
                   1050:                        return 1;
                   1051:                }
                   1052:                g = bucket->body[hindex];
                   1053:                index = nd_find_reducer(g);
                   1054:                if ( index >= 0 ) {
                   1055:                        h = nd_psh[index];
                   1056:                        ndl_sub(HDL(g),DL(h),DL(mul));
                   1057:                        if ( ndl_check_bound2(index,DL(mul)) ) {
1.26      noro     1058:                                nd_free(d);
1.25      noro     1059:                                free_pbucket(bucket);
                   1060:                                *rp = 0;
                   1061:                                return 0;
                   1062:                        }
                   1063:                        if ( mod ) {
                   1064:                                p = nd_ps[index];
                   1065:                                c1 = invm(HCM(p),mod); c2 = mod-HCM(g);
                   1066:                                DMAR(c1,c2,0,mod,c); CM(mul) = c;
                   1067:                        } else {
                   1068:                                p = nd_psq[index];
                   1069:                                igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred);
                   1070:                                chsgnq(cg,&CQ(mul));
1.26      noro     1071:                                nd_mul_c_q(d,cred);
                   1072:                                mulq_pbucket(bucket,cred);
                   1073:                                g = bucket->body[hindex];
1.28      noro     1074:                                gmag = (double)p_mag((P)HCQ(g));
1.25      noro     1075:                        }
                   1076:                        red = ndv_mul_nm(mod,p,mul);
                   1077:                        bucket->body[hindex] = nd_remove_head(g);
                   1078:                        red = nd_remove_head(red);
1.31      noro     1079:                        add_pbucket(mod,bucket,red);
1.34      noro     1080:                        psugar = SG(p)+TD(DL(mul));
                   1081:                        sugar = MAX(sugar,psugar);
1.28      noro     1082:                        if ( !mod && hmag && (gmag > hmag) ) {
                   1083:                                g = normalize_pbucket(mod,bucket);
                   1084:                                if ( !g ) {
1.34      noro     1085:                                        if ( d ) SG(d) = sugar;
1.28      noro     1086:                                        *rp = d;
                   1087:                                        return 1;
                   1088:                                }
                   1089:                                nd_removecont2(d,g);
                   1090:                                hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
1.31      noro     1091:                                add_pbucket(mod,bucket,g);
1.28      noro     1092:                        }
1.25      noro     1093:                } else if ( !full ) {
                   1094:                        g = normalize_pbucket(mod,bucket);
1.34      noro     1095:                        if ( g ) SG(g) = sugar;
1.25      noro     1096:                        *rp = g;
                   1097:                        return 1;
                   1098:                } else {
                   1099:                        m = BDY(g);
                   1100:                        if ( NEXT(m) ) {
1.34      noro     1101:                                BDY(g) = NEXT(m); NEXT(m) = 0; LEN(g)--;
1.25      noro     1102:                        } else {
                   1103:                                FREEND(g); g = 0;
                   1104:                        }
                   1105:                        bucket->body[hindex] = g;
                   1106:                        NEXT(m) = 0;
                   1107:                        if ( d ) {
1.34      noro     1108:                                NEXT(tail)=m; tail=m; LEN(d)++;
1.25      noro     1109:                        } else {
1.34      noro     1110:                                MKND(n,m,1,d); tail = BDY(d);
1.25      noro     1111:                        }
                   1112:                }
                   1113:        }
                   1114: }
1.27      noro     1115:
1.23      noro     1116: int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full,ND *rp)
                   1117: {
1.30      noro     1118:        ND d;
                   1119:        NM m,mrd,tail;
                   1120:        NM mul;
                   1121:        int n,sugar,psugar,sugar0,stat,index;
1.31      noro     1122:        int c,c1,c2;
1.30      noro     1123:        RHist h;
                   1124:        NDV p,red;
                   1125:        Q cg,cred,gcd;
                   1126:        double hmag;
                   1127:
                   1128:        if ( !g ) {
                   1129:                *rp = 0;
                   1130:                return 1;
                   1131:        }
                   1132: #if 0
                   1133:        if ( !mod )
                   1134:                hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
                   1135: #else
                   1136:        /* XXX */
                   1137:        hmag = 0;
                   1138: #endif
                   1139:
                   1140:        sugar0 = sugar = SG(g);
                   1141:        n = NV(g);
1.34      noro     1142:        mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
1.30      noro     1143:        for ( d = 0; g; ) {
                   1144:                index = nd_find_reducer_direct(g,ps,len);
                   1145:                if ( index >= 0 ) {
                   1146:                        p = ps[index];
                   1147:                        ndl_sub(HDL(g),HDL(p),DL(mul));
                   1148:                        if ( ndl_check_bound2_direct(HDL(p),DL(mul)) ) {
                   1149:                                nd_free(g); nd_free(d);
                   1150:                                return 0;
                   1151:                        }
                   1152:                        if ( mod ) {
                   1153:                                c1 = invm(HCM(p),mod); c2 = mod-HCM(g);
                   1154:                                DMAR(c1,c2,0,mod,c); CM(mul) = c;
                   1155:                        } else {
                   1156:                                igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred);
                   1157:                                chsgnq(cg,&CQ(mul));
                   1158:                                nd_mul_c_q(d,cred); nd_mul_c_q(g,cred);
                   1159:                        }
1.31      noro     1160:                        g = nd_add(mod,g,ndv_mul_nm(mod,p,mul));
1.34      noro     1161:                        sugar = MAX(sugar,SG(p)+TD(DL(mul)));
1.30      noro     1162:                        if ( !mod && hmag && g && ((double)(p_mag((P)HCQ(g))) > hmag) ) {
                   1163:                                nd_removecont2(d,g);
                   1164:                                hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
                   1165:                        }
                   1166:                } else if ( !full ) {
                   1167:                        *rp = g;
                   1168:                        return 1;
                   1169:                } else {
                   1170:                        m = BDY(g);
                   1171:                        if ( NEXT(m) ) {
1.34      noro     1172:                                BDY(g) = NEXT(m); NEXT(m) = 0; LEN(g)--;
1.30      noro     1173:                        } else {
                   1174:                                FREEND(g); g = 0;
                   1175:                        }
                   1176:                        if ( d ) {
1.34      noro     1177:                                NEXT(tail)=m; tail=m; LEN(d)++;
1.30      noro     1178:                        } else {
1.34      noro     1179:                                MKND(n,m,1,d); tail = BDY(d);
1.30      noro     1180:                        }
                   1181:                }
                   1182:        }
1.34      noro     1183:        if ( d ) SG(d) = sugar;
1.30      noro     1184:        *rp = d;
                   1185:        return 1;
                   1186: }
                   1187:
                   1188: int nd_nf_direct_pbucket(int mod,ND g,NDV *ps,int len,int full,ND *rp)
                   1189: {
1.28      noro     1190:        int hindex,index;
                   1191:        NDV p;
                   1192:        ND u,d,red;
                   1193:        NODE l;
1.31      noro     1194:        NM mul,m,mrd,tail;
1.28      noro     1195:        int sugar,psugar,n,h_reducible;
                   1196:        PGeoBucket bucket;
1.23      noro     1197:        int c,c1,c2;
1.28      noro     1198:        Q cg,cred,gcd,zzz;
1.23      noro     1199:        RHist h;
1.28      noro     1200:        double hmag,gmag;
1.23      noro     1201:
                   1202:        if ( !g ) {
                   1203:                *rp = 0;
                   1204:                return 1;
                   1205:        }
1.28      noro     1206:        sugar = SG(g);
                   1207:        n = NV(g);
1.23      noro     1208: #if 0
                   1209:        if ( !mod )
                   1210:                hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
                   1211: #else
                   1212:        /* XXX */
                   1213:        hmag = 0;
                   1214: #endif
1.28      noro     1215:        bucket = create_pbucket();
1.31      noro     1216:        add_pbucket(mod,bucket,g);
1.28      noro     1217:        d = 0;
1.34      noro     1218:        mul = (NM)ALLOCA(sizeof(struct oNM)+nd_wpd*sizeof(unsigned int));
1.28      noro     1219:        while ( 1 ) {
                   1220:                hindex = mod?head_pbucket(mod,bucket):head_pbucket_q(bucket);
                   1221:                if ( hindex < 0 ) {
                   1222:                        if ( d )
                   1223:                                SG(d) = sugar;
                   1224:                        *rp = d;
                   1225:                        return 1;
                   1226:                }
                   1227:                g = bucket->body[hindex];
1.23      noro     1228:                index = nd_find_reducer_direct(g,ps,len);
                   1229:                if ( index >= 0 ) {
                   1230:                        p = ps[index];
                   1231:                        ndl_sub(HDL(g),HDL(p),DL(mul));
                   1232:                        if ( ndl_check_bound2_direct(HDL(p),DL(mul)) ) {
1.28      noro     1233:                                nd_free(d);
                   1234:                                free_pbucket(bucket);
                   1235:                                *rp = 0;
1.23      noro     1236:                                return 0;
                   1237:                        }
1.28      noro     1238:                        if ( mod ) {
1.23      noro     1239:                                c1 = invm(HCM(p),mod); c2 = mod-HCM(g);
                   1240:                                DMAR(c1,c2,0,mod,c); CM(mul) = c;
                   1241:                        } else {
                   1242:                                igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred);
                   1243:                                chsgnq(cg,&CQ(mul));
1.28      noro     1244:                                nd_mul_c_q(d,cred);
                   1245:                                mulq_pbucket(bucket,cred);
                   1246:                                g = bucket->body[hindex];
                   1247:                                gmag = (double)p_mag((P)HCQ(g));
1.23      noro     1248:                        }
1.28      noro     1249:                        red = ndv_mul_nm(mod,p,mul);
                   1250:                        bucket->body[hindex] = nd_remove_head(g);
                   1251:                        red = nd_remove_head(red);
1.31      noro     1252:                        add_pbucket(mod,bucket,red);
1.34      noro     1253:                        sugar = MAX(sugar,SG(p)+TD(DL(mul)));
1.28      noro     1254:                        if ( !mod && hmag && (gmag > hmag) ) {
                   1255:                                g = normalize_pbucket(mod,bucket);
                   1256:                                if ( !g ) {
1.34      noro     1257:                                        if ( d ) SG(d) = sugar;
1.28      noro     1258:                                        *rp = d;
                   1259:                                        return 1;
                   1260:                                }
1.23      noro     1261:                                nd_removecont2(d,g);
                   1262:                                hmag = ((double)p_mag((P)HCQ(g)))*nd_scale;
1.31      noro     1263:                                add_pbucket(mod,bucket,g);
1.23      noro     1264:                        }
                   1265:                } else if ( !full ) {
1.28      noro     1266:                        g = normalize_pbucket(mod,bucket);
1.34      noro     1267:                        if ( g ) SG(g) = sugar;
1.23      noro     1268:                        *rp = g;
                   1269:                        return 1;
                   1270:                } else {
                   1271:                        m = BDY(g);
                   1272:                        if ( NEXT(m) ) {
1.34      noro     1273:                                BDY(g) = NEXT(m); NEXT(m) = 0; LEN(g)--;
1.23      noro     1274:                        } else {
                   1275:                                FREEND(g); g = 0;
                   1276:                        }
1.28      noro     1277:                        bucket->body[hindex] = g;
                   1278:                        NEXT(m) = 0;
1.23      noro     1279:                        if ( d ) {
1.34      noro     1280:                                NEXT(tail)=m; tail=m; LEN(d)++;
1.23      noro     1281:                        } else {
1.34      noro     1282:                                MKND(n,m,1,d); tail = BDY(d);
1.23      noro     1283:                        }
                   1284:                }
                   1285:        }
1.28      noro     1286: }
                   1287:
                   1288: /* input : list of DP, cand : list of DP */
                   1289:
                   1290: int nd_check_candidate(NODE input,NODE cand)
                   1291: {
                   1292:        int n,i,stat;
                   1293:        ND nf,d;
                   1294:        NODE t;
                   1295:
1.39      noro     1296:        nd_setup(0,0,cand);
1.31      noro     1297:        n = length(cand);
1.28      noro     1298:
                   1299:        /* membercheck : list is a subset of Id(cand) ? */
                   1300:        for ( t = input; t; t = NEXT(t) ) {
                   1301:                d = dptond(0,(DP)BDY(t));
                   1302:                stat = nd_nf_direct(0,d,nd_psq,n,0,&nf);
1.34      noro     1303:                if ( !stat ) nd_reconstruct_direct(0,nd_psq,n);
                   1304:                else if ( nf ) return 0;
1.28      noro     1305:        }
                   1306:        /* gbcheck : cand is a GB of Id(cand) ? */
1.34      noro     1307:        if ( !nd_gb(0,1) ) return 0;
1.28      noro     1308:        /* XXX */
1.23      noro     1309:        return 1;
                   1310: }
1.1       noro     1311:
                   1312: ND nd_remove_head(ND p)
                   1313: {
                   1314:        NM m;
                   1315:
                   1316:        m = BDY(p);
                   1317:        if ( !NEXT(m) ) {
1.34      noro     1318:                FREEND(p); p = 0;
1.31      noro     1319:        } else {
1.34      noro     1320:                BDY(p) = NEXT(m); LEN(p)--;
1.31      noro     1321:        }
1.1       noro     1322:        FREENM(m);
                   1323:        return p;
                   1324: }
                   1325:
                   1326: PGeoBucket create_pbucket()
                   1327: {
                   1328:     PGeoBucket g;
                   1329:
                   1330:        g = CALLOC(1,sizeof(struct oPGeoBucket));
                   1331:        g->m = -1;
                   1332:        return g;
                   1333: }
                   1334:
1.25      noro     1335: void free_pbucket(PGeoBucket b) {
                   1336:        int i;
                   1337:
1.26      noro     1338:        for ( i = 0; i <= b->m; i++ )
1.25      noro     1339:                if ( b->body[i] ) {
                   1340:                        nd_free(b->body[i]);
                   1341:                        b->body[i] = 0;
                   1342:                }
                   1343:        GC_free(b);
                   1344: }
                   1345:
1.31      noro     1346: void add_pbucket(int mod,PGeoBucket g,ND d)
1.1       noro     1347: {
1.31      noro     1348:        int l,i,k,m;
1.1       noro     1349:
1.31      noro     1350:        if ( !d )
                   1351:                return;
                   1352:        l = LEN(d);
1.29      noro     1353:        for ( k = 0, m = 1; l > m; k++, m <<= 1 );
                   1354:        /* 2^(k-1) < l <= 2^k (=m) */
1.31      noro     1355:        d = nd_add(mod,g->body[k],d);
                   1356:        for ( ; d && LEN(d) > m; k++, m <<= 1 ) {
1.1       noro     1357:                g->body[k] = 0;
1.31      noro     1358:                d = nd_add(mod,g->body[k+1],d);
1.1       noro     1359:        }
                   1360:        g->body[k] = d;
                   1361:        g->m = MAX(g->m,k);
                   1362: }
                   1363:
1.26      noro     1364: void mulq_pbucket(PGeoBucket g,Q c)
                   1365: {
                   1366:        int k;
                   1367:
                   1368:        for ( k = 0; k <= g->m; k++ )
                   1369:                nd_mul_c_q(g->body[k],c);
                   1370: }
                   1371:
1.19      noro     1372: int head_pbucket(int mod,PGeoBucket g)
1.1       noro     1373: {
                   1374:        int j,i,c,k,nv,sum;
                   1375:        unsigned int *di,*dj;
                   1376:        ND gi,gj;
                   1377:
                   1378:        k = g->m;
                   1379:        while ( 1 ) {
                   1380:                j = -1;
                   1381:                for ( i = 0; i <= k; i++ ) {
                   1382:                        if ( !(gi = g->body[i]) )
                   1383:                                continue;
                   1384:                        if ( j < 0 ) {
                   1385:                                j = i;
                   1386:                                gj = g->body[j];
                   1387:                                dj = HDL(gj);
1.14      noro     1388:                                sum = HCM(gj);
1.1       noro     1389:                        } else {
1.34      noro     1390:                                c = DL_COMPARE(HDL(gi),dj);
1.1       noro     1391:                                if ( c > 0 ) {
1.34      noro     1392:                                        if ( sum ) HCM(gj) = sum;
                   1393:                                        else g->body[j] = nd_remove_head(gj);
1.1       noro     1394:                                        j = i;
                   1395:                                        gj = g->body[j];
                   1396:                                        dj = HDL(gj);
1.14      noro     1397:                                        sum = HCM(gj);
1.1       noro     1398:                                } else if ( c == 0 ) {
1.19      noro     1399:                                        sum = sum+HCM(gi)-mod;
1.34      noro     1400:                                        if ( sum < 0 ) sum += mod;
1.1       noro     1401:                                        g->body[i] = nd_remove_head(gi);
                   1402:                                }
                   1403:                        }
                   1404:                }
1.34      noro     1405:                if ( j < 0 ) return -1;
1.1       noro     1406:                else if ( sum ) {
1.14      noro     1407:                        HCM(gj) = sum;
1.26      noro     1408:                        return j;
1.31      noro     1409:                } else
1.26      noro     1410:                        g->body[j] = nd_remove_head(gj);
                   1411:        }
                   1412: }
                   1413:
                   1414: int head_pbucket_q(PGeoBucket g)
                   1415: {
                   1416:        int j,i,c,k,nv;
                   1417:        Q sum,t;
                   1418:        ND gi,gj;
                   1419:
                   1420:        k = g->m;
                   1421:        while ( 1 ) {
                   1422:                j = -1;
                   1423:                for ( i = 0; i <= k; i++ ) {
1.34      noro     1424:                        if ( !(gi = g->body[i]) ) continue;
1.26      noro     1425:                        if ( j < 0 ) {
                   1426:                                j = i;
                   1427:                                gj = g->body[j];
                   1428:                                sum = HCQ(gj);
                   1429:                        } else {
                   1430:                                nv = NV(gi);
1.34      noro     1431:                                c = DL_COMPARE(HDL(gi),HDL(gj));
1.26      noro     1432:                                if ( c > 0 ) {
1.34      noro     1433:                                        if ( sum ) HCQ(gj) = sum;
                   1434:                                        else g->body[j] = nd_remove_head(gj);
1.26      noro     1435:                                        j = i;
                   1436:                                        gj = g->body[j];
                   1437:                                        sum = HCQ(gj);
                   1438:                                } else if ( c == 0 ) {
                   1439:                                        addq(sum,HCQ(gi),&t);
                   1440:                                        sum = t;
                   1441:                                        g->body[i] = nd_remove_head(gi);
                   1442:                                }
                   1443:                        }
                   1444:                }
1.34      noro     1445:                if ( j < 0 ) return -1;
1.26      noro     1446:                else if ( sum ) {
                   1447:                        HCQ(gj) = sum;
1.1       noro     1448:                        return j;
1.31      noro     1449:                } else
1.1       noro     1450:                        g->body[j] = nd_remove_head(gj);
                   1451:        }
                   1452: }
                   1453:
1.25      noro     1454: ND normalize_pbucket(int mod,PGeoBucket g)
1.1       noro     1455: {
1.31      noro     1456:        int i;
1.1       noro     1457:        ND r,t;
                   1458:
                   1459:        r = 0;
1.28      noro     1460:        for ( i = 0; i <= g->m; i++ ) {
1.31      noro     1461:                r = nd_add(mod,r,g->body[i]);
1.28      noro     1462:                g->body[i] = 0;
                   1463:        }
                   1464:        g->m = -1;
1.1       noro     1465:        return r;
                   1466: }
                   1467:
1.27      noro     1468: /* return value = 0 => input is not a GB */
                   1469:
                   1470: NODE nd_gb(int m,int checkonly)
1.1       noro     1471: {
                   1472:        int i,nh,sugar,stat;
1.23      noro     1473:        NODE r,g,t;
1.1       noro     1474:        ND_pairs d;
                   1475:        ND_pairs l;
                   1476:        ND h,nf;
                   1477:
1.23      noro     1478:        g = 0; d = 0;
                   1479:        for ( i = 0; i < nd_psn; i++ ) {
1.1       noro     1480:                d = update_pairs(d,g,i);
                   1481:                g = update_base(g,i);
                   1482:        }
                   1483:        sugar = 0;
                   1484:        while ( d ) {
                   1485: again:
                   1486:                l = nd_minp(d,&d);
1.14      noro     1487:                if ( SG(l) != sugar ) {
                   1488:                        sugar = SG(l);
1.1       noro     1489:                        fprintf(asir_out,"%d",sugar);
                   1490:                }
1.16      noro     1491:                stat = nd_sp(m,l,&h);
1.1       noro     1492:                if ( !stat ) {
                   1493:                        NEXT(l) = d; d = l;
1.20      noro     1494:                        d = nd_reconstruct(m,0,d);
1.1       noro     1495:                        goto again;
                   1496:                }
1.30      noro     1497:                stat = m?nd_nf_pbucket(m,h,!Top,&nf):nd_nf(m,h,!Top,&nf);
1.1       noro     1498:                if ( !stat ) {
                   1499:                        NEXT(l) = d; d = l;
1.20      noro     1500:                        d = nd_reconstruct(m,0,d);
1.1       noro     1501:                        goto again;
                   1502:                } else if ( nf ) {
1.27      noro     1503:                        if ( checkonly ) return 0;
1.1       noro     1504:                        printf("+"); fflush(stdout);
1.39      noro     1505:                        nh = m?nd_newps(m,nf,0):nd_newps(m,0,nf);
1.1       noro     1506:                        d = update_pairs(d,g,nh);
                   1507:                        g = update_base(g,nh);
                   1508:                        FREENDP(l);
                   1509:                } else {
                   1510:                        printf("."); fflush(stdout);
                   1511:                        FREENDP(l);
                   1512:                }
                   1513:        }
1.23      noro     1514:        if ( m )
1.34      noro     1515:                for ( t = g; t; t = NEXT(t) ) BDY(t) = (pointer)nd_ps[(int)BDY(t)];
1.23      noro     1516:        else
1.34      noro     1517:                for ( t = g; t; t = NEXT(t) ) BDY(t) = (pointer)nd_psq[(int)BDY(t)];
1.1       noro     1518:        return g;
                   1519: }
                   1520:
1.23      noro     1521: NODE nd_gb_trace(int m)
1.20      noro     1522: {
                   1523:        int i,nh,sugar,stat;
1.23      noro     1524:        NODE r,g,t;
1.20      noro     1525:        ND_pairs d;
                   1526:        ND_pairs l;
                   1527:        ND h,nf,nfq;
                   1528:
1.23      noro     1529:        g = 0; d = 0;
                   1530:        for ( i = 0; i < nd_psn; i++ ) {
1.20      noro     1531:                d = update_pairs(d,g,i);
                   1532:                g = update_base(g,i);
                   1533:        }
                   1534:        sugar = 0;
                   1535:        while ( d ) {
                   1536: again:
                   1537:                l = nd_minp(d,&d);
                   1538:                if ( SG(l) != sugar ) {
                   1539:                        sugar = SG(l);
                   1540:                        fprintf(asir_out,"%d",sugar);
                   1541:                }
                   1542:                stat = nd_sp(m,l,&h);
                   1543:                if ( !stat ) {
                   1544:                        NEXT(l) = d; d = l;
                   1545:                        d = nd_reconstruct(m,1,d);
                   1546:                        goto again;
                   1547:                }
1.30      noro     1548:                stat = nd_nf_pbucket(m,h,!Top,&nf);
1.20      noro     1549:                if ( !stat ) {
                   1550:                        NEXT(l) = d; d = l;
                   1551:                        d = nd_reconstruct(m,1,d);
                   1552:                        goto again;
                   1553:                } else if ( nf ) {
                   1554:                        /* overflow does not occur */
                   1555:                        nd_sp(0,l,&h);
                   1556:                        nd_nf(0,h,!Top,&nfq);
                   1557:                        if ( nfq ) {
                   1558:                                printf("+"); fflush(stdout);
1.39      noro     1559:                                nh = nd_newps(m,nf,nfq);
1.27      noro     1560:                                /* failure; m|HC(nfq) */
1.38      noro     1561:                                if ( nh < 0 ) return 0;
1.20      noro     1562:                                d = update_pairs(d,g,nh);
                   1563:                                g = update_base(g,nh);
                   1564:                        } else {
                   1565:                                printf("*"); fflush(stdout);
                   1566:                        }
                   1567:                } else {
                   1568:                        printf("."); fflush(stdout);
                   1569:                }
                   1570:                FREENDP(l);
                   1571:        }
1.23      noro     1572:        for ( t = g; t; t = NEXT(t) )
                   1573:                BDY(t) = (pointer)nd_psq[(int)BDY(t)];
1.20      noro     1574:        return g;
                   1575: }
                   1576:
1.23      noro     1577: int ndv_compare(NDV *p1,NDV *p2)
                   1578: {
1.34      noro     1579:        return DL_COMPARE(HDL(*p1),HDL(*p2));
1.23      noro     1580: }
                   1581:
                   1582: int ndv_compare_rev(NDV *p1,NDV *p2)
                   1583: {
1.34      noro     1584:        return -DL_COMPARE(HDL(*p1),HDL(*p2));
1.23      noro     1585: }
                   1586:
                   1587: NODE nd_reduceall(int m,NODE f)
                   1588: {
                   1589:        int i,j,n,stat;
                   1590:        NDV *w,*ps;
                   1591:        ND nf,g;
                   1592:        NODE t,a0,a;
                   1593:
                   1594:        for ( n = 0, t = f; t; t = NEXT(t), n++ );
                   1595:        ps = (NDV *)ALLOCA(n*sizeof(NDV));
                   1596:        for ( i = 0, t = f; i < n; i++, t = NEXT(t) )
                   1597:                ps[i] = (NDV)BDY(t);
                   1598:        qsort(ps,n,sizeof(NDV),(int (*)(const void *,const void *))ndv_compare);
                   1599:        w = (NDV *)ALLOCA((n-1)*sizeof(NDV));
                   1600:        for ( i = 0; i < n; i++ ) {
1.34      noro     1601:                for ( j = 0; j < i; j++ ) w[j] = (NDV)ps[j];
                   1602:                for ( j = i+1; j < n; j++ ) w[j-1] = ps[j];
1.23      noro     1603:                g = ndvtond(m,ps[i]);
                   1604:                stat = nd_nf_direct(m,g,w,n-1,1,&nf);
                   1605:                if ( !stat )
                   1606:                        nd_reconstruct_direct(m,ps,n);
                   1607:                else if ( !nf ) {
                   1608:                        printf("."); fflush(stdout);
                   1609:                        ndv_free(ps[i]);
1.34      noro     1610:                        for ( j = i+1; j < n; j++ ) ps[j-1] = ps[j];
1.23      noro     1611:                        n--;
                   1612:                } else {
                   1613:                        printf("."); fflush(stdout);
                   1614:                        ndv_free(ps[i]);
1.24      noro     1615:                        nd_removecont(m,nf);
1.23      noro     1616:                        ps[i] = ndtondv(m,nf);
                   1617:                        nd_free(nf);
                   1618:                }
                   1619:        }
                   1620:        for ( a0 = 0, i = 0; i < n; i++ ) {
                   1621:                NEXTNODE(a0,a);
                   1622:                BDY(a) = (pointer)ps[i];
                   1623:        }
                   1624:        NEXT(a) = 0;
                   1625:        return a0;
                   1626: }
                   1627:
1.1       noro     1628: ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t)
                   1629: {
                   1630:        ND_pairs d1,nd,cur,head,prev,remove;
                   1631:
                   1632:        if ( !g ) return d;
                   1633:        d = crit_B(d,t);
                   1634:        d1 = nd_newpairs(g,t);
                   1635:        d1 = crit_M(d1);
                   1636:        d1 = crit_F(d1);
                   1637:        prev = 0; cur = head = d1;
                   1638:        while ( cur ) {
                   1639:                if ( crit_2( cur->i1,cur->i2 ) ) {
                   1640:                        remove = cur;
1.34      noro     1641:                        if ( !prev ) head = cur = NEXT(cur);
                   1642:                        else cur = NEXT(prev) = NEXT(cur);
1.1       noro     1643:                        FREENDP(remove);
                   1644:                } else {
1.34      noro     1645:                        prev = cur; cur = NEXT(cur);
1.1       noro     1646:                }
                   1647:        }
                   1648:        if ( !d )
                   1649:                return head;
                   1650:        else {
                   1651:                nd = d;
1.34      noro     1652:                while ( NEXT(nd) ) nd = NEXT(nd);
1.1       noro     1653:                NEXT(nd) = head;
                   1654:                return d;
                   1655:        }
                   1656: }
                   1657:
                   1658: ND_pairs nd_newpairs( NODE g, int t )
                   1659: {
                   1660:        NODE h;
                   1661:        unsigned int *dl;
1.34      noro     1662:        int ts,s;
1.1       noro     1663:        ND_pairs r,r0;
                   1664:
1.20      noro     1665:        dl = DL(nd_psh[t]);
1.34      noro     1666:        ts = SG(nd_psh[t]) - TD(dl);
1.1       noro     1667:        for ( r0 = 0, h = g; h; h = NEXT(h) ) {
                   1668:                NEXTND_pairs(r0,r);
                   1669:                r->i1 = (int)BDY(h);
                   1670:                r->i2 = t;
1.20      noro     1671:                ndl_lcm(DL(nd_psh[r->i1]),dl,r->lcm);
1.34      noro     1672:                s = SG(nd_psh[r->i1])-TD(DL(nd_psh[r->i1]));
                   1673:                SG(r) = MAX(s,ts) + TD(LCM(r));
1.1       noro     1674:        }
                   1675:        NEXT(r) = 0;
                   1676:        return r0;
                   1677: }
                   1678:
                   1679: ND_pairs crit_B( ND_pairs d, int s )
                   1680: {
                   1681:        ND_pairs cur,head,prev,remove;
                   1682:        unsigned int *t,*tl,*lcm;
                   1683:        int td,tdl;
                   1684:
                   1685:        if ( !d ) return 0;
1.20      noro     1686:        t = DL(nd_psh[s]);
1.1       noro     1687:        prev = 0;
                   1688:        head = cur = d;
1.34      noro     1689:        lcm = (unsigned int *)ALLOCA((nd_wpd+1)*sizeof(unsigned int));
1.1       noro     1690:        while ( cur ) {
                   1691:                tl = cur->lcm;
                   1692:                if ( ndl_reducible(tl,t)
1.20      noro     1693:                        && (ndl_lcm(DL(nd_psh[cur->i1]),t,lcm),!ndl_equal(lcm,tl))
                   1694:                        && (ndl_lcm(DL(nd_psh[cur->i2]),t,lcm),!ndl_equal(lcm,tl)) ) {
1.1       noro     1695:                        remove = cur;
                   1696:                        if ( !prev ) {
                   1697:                                head = cur = NEXT(cur);
                   1698:                        } else {
                   1699:                                cur = NEXT(prev) = NEXT(cur);
                   1700:                        }
                   1701:                        FREENDP(remove);
                   1702:                } else {
1.34      noro     1703:                        prev = cur; cur = NEXT(cur);
1.1       noro     1704:                }
                   1705:        }
                   1706:        return head;
                   1707: }
                   1708:
1.34      noro     1709: /* XXX : check is necessary */
                   1710:
1.1       noro     1711: ND_pairs crit_M( ND_pairs d1 )
                   1712: {
                   1713:        ND_pairs e,d2,d3,dd,p;
                   1714:        unsigned int *id,*jd;
                   1715:
                   1716:        for ( dd = 0, e = d1; e; e = d3 ) {
                   1717:                if ( !(d2 = NEXT(e)) ) {
                   1718:                        NEXT(e) = dd;
                   1719:                        return e;
                   1720:                }
1.34      noro     1721:                id = LCM(e);
1.1       noro     1722:                for ( d3 = 0; d2; d2 = p ) {
1.34      noro     1723:                        p = NEXT(d2);
                   1724:                        jd = LCM(d2);
                   1725:                        if ( ndl_equal(jd,id) )
                   1726:                                ;
                   1727:                        else if ( TD(jd) > TD(id) )
1.1       noro     1728:                                if ( ndl_reducible(jd,id) ) continue;
                   1729:                                else ;
1.34      noro     1730:                        else if ( ndl_reducible(id,jd) ) goto delit;
1.1       noro     1731:                        NEXT(d2) = d3;
                   1732:                        d3 = d2;
                   1733:                }
                   1734:                NEXT(e) = dd;
                   1735:                dd = e;
                   1736:                continue;
                   1737:                /**/
                   1738:        delit:  NEXT(d2) = d3;
                   1739:                d3 = d2;
                   1740:                for ( ; p; p = d2 ) {
                   1741:                        d2 = NEXT(p);
                   1742:                        NEXT(p) = d3;
                   1743:                        d3 = p;
                   1744:                }
                   1745:                FREENDP(e);
                   1746:        }
                   1747:        return dd;
                   1748: }
                   1749:
                   1750: ND_pairs crit_F( ND_pairs d1 )
                   1751: {
                   1752:        ND_pairs rest, head,remove;
                   1753:        ND_pairs last, p, r, w;
                   1754:        int s;
                   1755:
                   1756:        for ( head = last = 0, p = d1; NEXT(p); ) {
                   1757:                r = w = equivalent_pairs(p,&rest);
1.14      noro     1758:                s = SG(r);
1.1       noro     1759:                w = NEXT(w);
                   1760:                while ( w ) {
                   1761:                        if ( crit_2(w->i1,w->i2) ) {
                   1762:                                r = w;
                   1763:                                w = NEXT(w);
                   1764:                                while ( w ) {
                   1765:                                        remove = w;
                   1766:                                        w = NEXT(w);
                   1767:                                        FREENDP(remove);
                   1768:                                }
                   1769:                                break;
1.14      noro     1770:                        } else if ( SG(w) < s ) {
1.1       noro     1771:                                FREENDP(r);
                   1772:                                r = w;
1.14      noro     1773:                                s = SG(r);
1.1       noro     1774:                                w = NEXT(w);
                   1775:                        } else {
                   1776:                                remove = w;
                   1777:                                w = NEXT(w);
                   1778:                                FREENDP(remove);
                   1779:                        }
                   1780:                }
                   1781:                if ( last ) NEXT(last) = r;
                   1782:                else head = r;
                   1783:                NEXT(last = r) = 0;
                   1784:                p = rest;
                   1785:                if ( !p ) return head;
                   1786:        }
                   1787:        if ( !last ) return p;
                   1788:        NEXT(last) = p;
                   1789:        return head;
                   1790: }
                   1791:
                   1792: int crit_2( int dp1, int dp2 )
                   1793: {
1.20      noro     1794:        return ndl_disjoint(DL(nd_psh[dp1]),DL(nd_psh[dp2]));
1.1       noro     1795: }
                   1796:
1.40    ! noro     1797: ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest )
1.1       noro     1798: {
                   1799:        ND_pairs w,p,r,s;
                   1800:        unsigned int *d;
                   1801:
                   1802:        w = d1;
1.34      noro     1803:        d = LCM(w);
1.1       noro     1804:        s = NEXT(w);
                   1805:        NEXT(w) = 0;
                   1806:        for ( r = 0; s; s = p ) {
                   1807:                p = NEXT(s);
1.34      noro     1808:                if ( ndl_equal(d,LCM(s)) ) {
1.39      noro     1809:                        NEXT(s) = w; w = s;
1.1       noro     1810:                } else {
1.39      noro     1811:                        NEXT(s) = r; r = s;
1.1       noro     1812:                }
                   1813:        }
                   1814:        *prest = r;
                   1815:        return w;
                   1816: }
                   1817:
                   1818: NODE update_base(NODE nd,int ndp)
                   1819: {
                   1820:        unsigned int *dl, *dln;
                   1821:        NODE last, p, head;
                   1822:
1.20      noro     1823:        dl = DL(nd_psh[ndp]);
1.1       noro     1824:        for ( head = last = 0, p = nd; p; ) {
1.20      noro     1825:                dln = DL(nd_psh[(int)BDY(p)]);
1.34      noro     1826:                if ( ndl_reducible( dln, dl ) ) {
1.1       noro     1827:                        p = NEXT(p);
                   1828:                        if ( last ) NEXT(last) = p;
                   1829:                } else {
                   1830:                        if ( !last ) head = p;
                   1831:                        p = NEXT(last = p);
                   1832:                }
                   1833:        }
                   1834:        head = append_one(head,ndp);
                   1835:        return head;
                   1836: }
                   1837:
                   1838: ND_pairs nd_minp( ND_pairs d, ND_pairs *prest )
                   1839: {
                   1840:        ND_pairs m,ml,p,l;
                   1841:        unsigned int *lcm;
1.33      noro     1842:        int s,td,len,tlen,c,c1;
1.1       noro     1843:
                   1844:        if ( !(p = NEXT(m = d)) ) {
                   1845:                *prest = p;
                   1846:                NEXT(m) = 0;
                   1847:                return m;
                   1848:        }
1.14      noro     1849:        s = SG(m);
1.33      noro     1850:        for ( ml = 0, l = m; p; p = NEXT(l = p) )
1.34      noro     1851:                if ( (SG(p) < s)
                   1852:                        || ((SG(p) == s) && (DL_COMPARE(LCM(p),LCM(m)) < 0)) ) {
1.39      noro     1853:                        ml = l; m = p; s = SG(m);
1.1       noro     1854:                }
                   1855:        if ( !ml ) *prest = NEXT(m);
                   1856:        else {
                   1857:                NEXT(ml) = NEXT(m);
                   1858:                *prest = d;
                   1859:        }
                   1860:        NEXT(m) = 0;
                   1861:        return m;
                   1862: }
                   1863:
1.39      noro     1864: int nd_newps(int mod,ND a,ND aq)
1.1       noro     1865: {
1.3       noro     1866:        int len;
1.13      noro     1867:        RHist r;
1.20      noro     1868:        NDV b;
1.3       noro     1869:
1.1       noro     1870:        if ( nd_psn == nd_pslen ) {
                   1871:                nd_pslen *= 2;
1.11      noro     1872:                nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV));
1.20      noro     1873:                nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV));
1.13      noro     1874:                nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist));
1.1       noro     1875:                nd_bound = (unsigned int **)
                   1876:                        REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *));
                   1877:        }
1.39      noro     1878:        if ( a && aq ) {
                   1879:                /* trace lifting */
                   1880:                if ( !rem(NM(HCQ(aq)),mod) ) return -1;
                   1881:        }
                   1882:        NEWRHist(r); nd_psh[nd_psn] = r;
                   1883:        if ( aq ) {
                   1884:                nd_removecont(0,aq);
                   1885:                nd_psq[nd_psn] = ndtondv(0,aq);
                   1886:                nd_bound[nd_psn] = nd_compute_bound(aq);
                   1887:                SG(r) = SG(aq); ndl_copy(HDL(aq),DL(r));
                   1888:        }
                   1889:        if ( a ) {
                   1890:                nd_removecont(mod,a);
                   1891:                nd_ps[nd_psn] = ndtondv(mod,a);
                   1892:                if ( !aq ) {
                   1893:                        nd_bound[nd_psn] = nd_compute_bound(a);
                   1894:                        SG(r) = SG(a); ndl_copy(HDL(a),DL(r));
                   1895:                }
1.20      noro     1896:        }
1.39      noro     1897:        nd_free(a); nd_free(aq);
1.1       noro     1898:        return nd_psn++;
                   1899: }
                   1900:
1.39      noro     1901: void nd_setup(int mod,int trace,NODE f)
1.1       noro     1902: {
1.5       noro     1903:        int i,j,td,len,max;
1.1       noro     1904:        NODE s,s0,f0;
1.5       noro     1905:        unsigned int *d;
1.13      noro     1906:        RHist r;
1.20      noro     1907:        NDV a;
1.11      noro     1908:
                   1909:        nd_found = 0; nd_notfirst = 0; nd_create = 0;
1.1       noro     1910:
                   1911:        nd_psn = length(f); nd_pslen = 2*nd_psn;
1.11      noro     1912:        nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV));
1.20      noro     1913:        nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV));
1.13      noro     1914:        nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist));
1.1       noro     1915:        nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *));
1.5       noro     1916:        for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) {
                   1917:                nd_bound[i] = d = dp_compute_bound((DP)BDY(s));
                   1918:                for ( j = 0; j < nd_nvar; j++ )
                   1919:                        max = MAX(d[j],max);
                   1920:        }
1.11      noro     1921:        if ( !nd_red )
1.13      noro     1922:                nd_red = (RHist *)MALLOC(REDTAB_LEN*sizeof(RHist));
                   1923:        bzero(nd_red,REDTAB_LEN*sizeof(RHist));
1.5       noro     1924:
1.34      noro     1925:        if ( max < 2 ) nd_bpe = 2;
                   1926:        else if ( max < 4 ) nd_bpe = 4;
                   1927:        else if ( max < 64 ) nd_bpe = 6;
                   1928:        else if ( max < 256 ) nd_bpe = 8;
                   1929:        else if ( max < 65536 ) nd_bpe = 16;
                   1930:        else nd_bpe = 32;
1.13      noro     1931:
1.1       noro     1932:        nd_setup_parameters();
                   1933:        nd_free_private_storage();
                   1934:        for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) {
1.20      noro     1935:                NEWRHist(r);
1.39      noro     1936:                a = dptondv(mod,(DP)BDY(f)); ndv_removecont(mod,a);
1.34      noro     1937:                SG(r) = HTD(a); ndl_copy(HDL(a),DL(r));
1.1       noro     1938:
1.39      noro     1939:                if ( trace ) {
                   1940:                        nd_ps[i] = a;
                   1941:                        a = dptondv(0,(DP)BDY(f)); ndv_removecont(0,a);
                   1942:                        nd_psq[i] = a;
                   1943:                } else {
                   1944:                        if ( mod ) nd_ps[i] = a;
                   1945:                        else nd_psq[i] = a;
                   1946:                }
1.20      noro     1947:                nd_psh[i] = r;
                   1948:        }
                   1949: }
                   1950:
1.1       noro     1951: void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,LIST *rp)
                   1952: {
                   1953:        struct order_spec ord1;
                   1954:        VL fv,vv,vc;
                   1955:        NODE fd,fd0,r,r0,t,x,s,xx;
                   1956:        DP a,b,c;
                   1957:
                   1958:        get_vars((Obj)f,&fv); pltovl(v,&vv);
                   1959:        nd_nvar = length(vv);
1.32      noro     1960:        nd_init_ord(ord);
                   1961:        /* XXX for DP */
1.1       noro     1962:        initd(ord);
                   1963:        for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) {
                   1964:                ptod(CO,vv,(P)BDY(t),&b);
1.20      noro     1965:                NEXTNODE(fd0,fd); BDY(fd) = (pointer)b;
1.1       noro     1966:        }
                   1967:        if ( fd0 ) NEXT(fd) = 0;
1.39      noro     1968:        nd_setup(m,0,fd0);
1.27      noro     1969:        x = nd_gb(m,0);
1.25      noro     1970:        fprintf(asir_out,"found=%d,notfirst=%d,create=%d\n",
                   1971:                nd_found,nd_notfirst,nd_create);
1.23      noro     1972:        x = nd_reduceall(m,x);
                   1973:        for ( r0 = 0, t = x; t; t = NEXT(t) ) {
1.1       noro     1974:                NEXTNODE(r0,r);
1.20      noro     1975:                if ( m ) {
1.23      noro     1976:                        a = ndvtodp(m,BDY(t));
1.16      noro     1977:                        _dtop_mod(CO,vv,a,(P *)&BDY(r));
1.20      noro     1978:                } else {
1.23      noro     1979:                        a = ndvtodp(m,BDY(t));
1.16      noro     1980:                        dtop(CO,vv,a,(P *)&BDY(r));
1.20      noro     1981:                }
                   1982:        }
                   1983:        if ( r0 ) NEXT(r) = 0;
                   1984:        MKLIST(*rp,r0);
                   1985: }
                   1986:
1.23      noro     1987: void nd_gr_trace(LIST f,LIST v,int m,int homo,struct order_spec *ord,LIST *rp)
1.20      noro     1988: {
                   1989:        struct order_spec ord1;
                   1990:        VL fv,vv,vc;
1.27      noro     1991:        NODE fd,fd0,in0,in,r,r0,t,s,cand;
1.23      noro     1992:        DP a,b,c,h;
1.27      noro     1993:        P p;
1.20      noro     1994:
                   1995:        get_vars((Obj)f,&fv); pltovl(v,&vv);
                   1996:        nd_nvar = length(vv);
                   1997:        initd(ord);
1.23      noro     1998:        if ( homo ) {
                   1999:                homogenize_order(ord,nd_nvar,&ord1);
1.27      noro     2000:                for ( fd0 = 0, in0 = 0, t = BDY(f); t; t = NEXT(t) ) {
1.23      noro     2001:                        ptod(CO,vv,(P)BDY(t),&c);
                   2002:                        if ( c ) {
                   2003:                                dp_homo(c,&h); NEXTNODE(fd0,fd); BDY(fd) = (pointer)h;
1.27      noro     2004:                                NEXTNODE(in0,in); BDY(in) = (pointer)c;
1.23      noro     2005:                        }
                   2006:                }
                   2007:                if ( fd0 ) NEXT(fd) = 0;
1.27      noro     2008:                if ( in0 ) NEXT(in) = 0;
1.32      noro     2009:                nd_init_ord(&ord1);
1.23      noro     2010:                initd(&ord1);
                   2011:                nd_nvar++;
1.25      noro     2012:        } else {
                   2013:                for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) {
                   2014:                        ptod(CO,vv,(P)BDY(t),&c);
                   2015:                        if ( c ) {
                   2016:                                NEXTNODE(fd0,fd); BDY(fd) = (pointer)c;
1.23      noro     2017:                        }
                   2018:                }
1.25      noro     2019:                if ( fd0 ) NEXT(fd) = 0;
1.27      noro     2020:                in0 = fd0;
1.33      noro     2021:                nd_init_ord(ord);
1.27      noro     2022:        }
                   2023:        do {
1.39      noro     2024:                nd_setup(m,1,fd0);
1.27      noro     2025:                cand = nd_gb_trace(m);
                   2026:                if ( !cand ) continue;
                   2027:                if ( homo ) {
                   2028:                        /* dehomogenization */
                   2029:                        for ( t = cand; t; t = NEXT(t) )
                   2030:                                ndv_dehomogenize((NDV)BDY(t));
                   2031:                        nd_nvar--;
                   2032:                        nd_setup_parameters();
                   2033:                        initd(ord);
                   2034:                        cand = nd_reducebase(cand);
                   2035:                }
                   2036:                fprintf(asir_out,"found=%d,notfirst=%d,create=%d\n",
                   2037:                        nd_found,nd_notfirst,nd_create);
                   2038:                cand = nd_reduceall(0,cand);
                   2039:                initd(ord);
                   2040:                for ( r0 = 0; cand; cand = NEXT(cand) ) {
                   2041:                        NEXTNODE(r0,r);
                   2042:                        BDY(r) = (pointer)ndvtodp(0,(NDV)BDY(cand));
                   2043:                }
                   2044:                if ( r0 ) NEXT(r) = 0;
                   2045:                cand = r0;
                   2046:        } while ( !nd_check_candidate(in0,cand) );
                   2047:        /* dp->p */
                   2048:        for ( r = cand; r; r = NEXT(r) ) {
                   2049:                dtop(CO,vv,BDY(r),&p);
                   2050:                BDY(r) = (pointer)p;
1.23      noro     2051:        }
1.27      noro     2052:        MKLIST(*rp,cand);
1.1       noro     2053: }
                   2054:
                   2055: void dltondl(int n,DL dl,unsigned int *r)
                   2056: {
                   2057:        unsigned int *d;
                   2058:        int i;
                   2059:
                   2060:        d = dl->d;
1.35      noro     2061:        for ( i = 0; i <= nd_wpd; i++ ) r[i] = 0;
1.32      noro     2062:        if ( nd_isrlex )
1.1       noro     2063:                for ( i = 0; i < n; i++ )
1.34      noro     2064:                        r[(n-1-i)/nd_epw+1] |= (d[i]<<((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe));
1.1       noro     2065:        else
                   2066:                for ( i = 0; i < n; i++ )
1.34      noro     2067:                        r[i/nd_epw+1] |= d[i]<<((nd_epw-(i%nd_epw)-1)*nd_bpe);
1.39      noro     2068:        TD(r) = ndl_weight(r);
1.1       noro     2069: }
                   2070:
1.34      noro     2071: DL ndltodl(int n,unsigned int *ndl)
1.1       noro     2072: {
                   2073:        DL dl;
                   2074:        int *d;
                   2075:        int i;
                   2076:
                   2077:        NEWDL(dl,n);
1.34      noro     2078:        dl->td = TD(ndl);
1.1       noro     2079:        d = dl->d;
1.32      noro     2080:        if ( nd_isrlex )
1.1       noro     2081:                for ( i = 0; i < n; i++ )
1.34      noro     2082:                        d[i] = (ndl[(n-1-i)/nd_epw+1]>>((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe))
1.1       noro     2083:                                &((1<<nd_bpe)-1);
                   2084:        else
                   2085:                for ( i = 0; i < n; i++ )
1.34      noro     2086:                        d[i] = (ndl[i/nd_epw+1]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))
1.1       noro     2087:                                &((1<<nd_bpe)-1);
                   2088:        return dl;
                   2089: }
                   2090:
1.17      noro     2091: ND dptond(int mod,DP p)
1.1       noro     2092: {
                   2093:        ND d;
                   2094:        NM m0,m;
                   2095:        MP t;
1.31      noro     2096:        int n,l;
1.1       noro     2097:
                   2098:        if ( !p )
                   2099:                return 0;
                   2100:        n = NV(p);
                   2101:        m0 = 0;
1.31      noro     2102:        for ( t = BDY(p), l = 0; t; t = NEXT(t), l++ ) {
1.1       noro     2103:                NEXTNM(m0,m);
1.34      noro     2104:                if ( mod ) CM(m) = ITOS(C(t));
                   2105:                else CQ(m) = (Q)C(t);
1.14      noro     2106:                dltondl(n,DL(t),DL(m));
1.1       noro     2107:        }
                   2108:        NEXT(m) = 0;
1.31      noro     2109:        MKND(n,m0,l,d);
1.14      noro     2110:        SG(d) = SG(p);
1.1       noro     2111:        return d;
                   2112: }
                   2113:
1.17      noro     2114: DP ndtodp(int mod,ND p)
1.1       noro     2115: {
                   2116:        DP d;
                   2117:        MP m0,m;
                   2118:        NM t;
                   2119:        int n;
                   2120:
                   2121:        if ( !p )
                   2122:                return 0;
                   2123:        n = NV(p);
                   2124:        m0 = 0;
                   2125:        for ( t = BDY(p); t; t = NEXT(t) ) {
                   2126:                NEXTMP(m0,m);
1.34      noro     2127:                if ( mod ) C(m) = STOI(CM(t));
                   2128:                else C(m) = (P)CQ(t);
                   2129:                DL(m) = ndltodl(n,DL(t));
1.1       noro     2130:        }
                   2131:        NEXT(m) = 0;
                   2132:        MKDP(n,m0,d);
1.14      noro     2133:        SG(d) = SG(p);
1.1       noro     2134:        return d;
                   2135: }
                   2136:
                   2137: void ndl_print(unsigned int *dl)
                   2138: {
                   2139:        int n;
                   2140:        int i;
                   2141:
                   2142:        n = nd_nvar;
                   2143:        printf("<<");
1.32      noro     2144:        if ( nd_isrlex )
1.1       noro     2145:                for ( i = 0; i < n; i++ )
                   2146:                        printf(i==n-1?"%d":"%d,",
1.34      noro     2147:                                (dl[(n-1-i)/nd_epw+1]>>((nd_epw-((n-1-i)%nd_epw)-1)*nd_bpe))
1.1       noro     2148:                                        &((1<<nd_bpe)-1));
                   2149:        else
                   2150:                for ( i = 0; i < n; i++ )
                   2151:                        printf(i==n-1?"%d":"%d,",
1.34      noro     2152:                                (dl[i/nd_epw+1]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))
1.1       noro     2153:                                        &((1<<nd_bpe)-1));
                   2154:        printf(">>");
                   2155: }
                   2156:
                   2157: void nd_print(ND p)
                   2158: {
                   2159:        NM m;
                   2160:
                   2161:        if ( !p )
                   2162:                printf("0\n");
                   2163:        else {
                   2164:                for ( m = BDY(p); m; m = NEXT(m) ) {
1.14      noro     2165:                        printf("+%d*",CM(m));
                   2166:                        ndl_print(DL(m));
1.1       noro     2167:                }
                   2168:                printf("\n");
                   2169:        }
                   2170: }
                   2171:
1.16      noro     2172: void nd_print_q(ND p)
                   2173: {
                   2174:        NM m;
                   2175:
                   2176:        if ( !p )
                   2177:                printf("0\n");
                   2178:        else {
                   2179:                for ( m = BDY(p); m; m = NEXT(m) ) {
                   2180:                        printf("+");
                   2181:                        printexpr(CO,CQ(m));
                   2182:                        printf("*");
                   2183:                        ndl_print(DL(m));
                   2184:                }
                   2185:                printf("\n");
                   2186:        }
                   2187: }
                   2188:
1.1       noro     2189: void ndp_print(ND_pairs d)
                   2190: {
                   2191:        ND_pairs t;
                   2192:
1.34      noro     2193:        for ( t = d; t; t = NEXT(t) ) printf("%d,%d ",t->i1,t->i2);
1.1       noro     2194:        printf("\n");
                   2195: }
                   2196:
1.20      noro     2197: void nd_removecont(int mod,ND p)
1.16      noro     2198: {
                   2199:        int i,n;
                   2200:        Q *w;
                   2201:        Q dvr,t;
                   2202:        NM m;
1.21      noro     2203:        struct oVECT v;
                   2204:        N q,r;
1.16      noro     2205:
1.34      noro     2206:        if ( mod ) nd_mul_c(mod,p,invm(HCM(p),mod));
1.20      noro     2207:        else {
                   2208:                for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
                   2209:                w = (Q *)ALLOCA(n*sizeof(Q));
1.21      noro     2210:                v.len = n;
                   2211:                v.body = (pointer *)w;
1.34      noro     2212:                for ( m = BDY(p), i = 0; i < n; m = NEXT(m), i++ ) w[i] = CQ(m);
1.21      noro     2213:                removecont_array(w,n);
                   2214:                for ( m = BDY(p), i = 0; i < n; m = NEXT(m), i++ ) CQ(m) = w[i];
1.16      noro     2215:        }
                   2216: }
                   2217:
1.21      noro     2218: void nd_removecont2(ND p1,ND p2)
                   2219: {
                   2220:        int i,n1,n2,n;
                   2221:        Q *w;
                   2222:        Q dvr,t;
                   2223:        NM m;
                   2224:        struct oVECT v;
                   2225:        N q,r;
                   2226:
                   2227:        if ( !p1 ) {
                   2228:                nd_removecont(0,p2); return;
                   2229:        } else if ( !p2 ) {
                   2230:                nd_removecont(0,p1); return;
                   2231:        }
                   2232:        n1 = nd_length(p1);
                   2233:        n2 = nd_length(p2);
                   2234:        n = n1+n2;
                   2235:        w = (Q *)ALLOCA(n*sizeof(Q));
                   2236:        v.len = n;
                   2237:        v.body = (pointer *)w;
1.34      noro     2238:        for ( m = BDY(p1), i = 0; i < n1; m = NEXT(m), i++ ) w[i] = CQ(m);
                   2239:        for ( m = BDY(p2); i < n; m = NEXT(m), i++ ) w[i] = CQ(m);
1.21      noro     2240:        removecont_array(w,n);
                   2241:        for ( m = BDY(p1), i = 0; i < n1; m = NEXT(m), i++ ) CQ(m) = w[i];
                   2242:        for ( m = BDY(p2); i < n; m = NEXT(m), i++ ) CQ(m) = w[i];
                   2243: }
                   2244:
1.20      noro     2245: void ndv_removecont(int mod,NDV p)
1.16      noro     2246: {
                   2247:        int i,len;
                   2248:        Q *w;
                   2249:        Q dvr,t;
                   2250:        NMV m;
                   2251:
1.20      noro     2252:        if ( mod )
                   2253:                ndv_mul_c(mod,p,invm(HCM(p),mod));
                   2254:        else {
                   2255:                len = p->len;
                   2256:                w = (Q *)ALLOCA(len*sizeof(Q));
1.34      noro     2257:                for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) w[i] = CQ(m);
1.20      noro     2258:                sortbynm(w,len);
                   2259:                qltozl(w,len,&dvr);
                   2260:                for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ ) {
                   2261:                        divq(CQ(m),dvr,&t); CQ(m) = t;
                   2262:                }
1.16      noro     2263:        }
1.21      noro     2264: }
                   2265:
1.23      noro     2266: void ndv_dehomogenize(NDV p)
                   2267: {
                   2268:        int i,len,newnvar,newwpd,newadv;
                   2269:        Q *w;
                   2270:        Q dvr,t;
                   2271:        NMV m,r;
                   2272:        unsigned int *d;
                   2273: #define NEWADV(m) (m = (NMV)(((char *)m)+newadv))
                   2274:
                   2275:        len = p->len;
                   2276:        newnvar = nd_nvar-1;
                   2277:        newwpd = newnvar/nd_epw+(newnvar%nd_epw?1:0);
                   2278:        for ( m = BDY(p), i = 0; i < len; NMV_ADV(m), i++ )
1.34      noro     2279:                ndl_dehomogenize(DL(m));
1.23      noro     2280:        if ( newwpd != nd_wpd ) {
1.34      noro     2281:                d = (unsigned int *)ALLOCA((newwpd+1)*sizeof(unsigned int));
                   2282:                newadv = sizeof(struct oNMV)+newwpd*sizeof(unsigned int);
1.23      noro     2283:                for ( m = r = BDY(p), i = 0; i < len; NMV_ADV(m), NEWADV(r), i++ ) {
1.34      noro     2284:                        CQ(r) = CQ(m); ndl_copy(DL(m),d); ndl_copy(d,DL(r));
1.23      noro     2285:                }
                   2286:        }
                   2287:        NV(p)--;
                   2288: }
                   2289:
1.21      noro     2290: void removecont_array(Q *c,int n)
                   2291: {
                   2292:        struct oVECT v;
                   2293:        Q d0,d1,a,u,u1,gcd;
                   2294:        int i;
                   2295:        N qn,rn,gn;
                   2296:        Q *q,*r;
                   2297:
                   2298:        q = (Q *)ALLOCA(n*sizeof(Q));
                   2299:        r = (Q *)ALLOCA(n*sizeof(Q));
                   2300:        v.id = O_VECT; v.len = n; v.body = (pointer *)c;
                   2301:        igcdv_estimate(&v,&d0);
                   2302:        for ( i = 0; i < n; i++ ) {
                   2303:                divn(NM(c[i]),NM(d0),&qn,&rn);
                   2304:                NTOQ(qn,SGN(c[i])*SGN(d0),q[i]);
                   2305:                NTOQ(rn,SGN(c[i]),r[i]);
                   2306:        }
1.34      noro     2307:        for ( i = 0; i < n; i++ ) if ( r[i] ) break;
1.21      noro     2308:        if ( i < n ) {
                   2309:                v.id = O_VECT; v.len = n; v.body = (pointer *)r;
                   2310:                igcdv(&v,&d1);
                   2311:                gcdn(NM(d0),NM(d1),&gn); NTOQ(gn,1,gcd);
                   2312:                divsn(NM(d0),gn,&qn); NTOQ(qn,1,a);
                   2313:                for ( i = 0; i < n; i++ ) {
                   2314:                        mulq(a,q[i],&u);
                   2315:                        if ( r[i] ) {
                   2316:                                divsn(NM(r[i]),gn,&qn); NTOQ(qn,SGN(r[i]),u1);
                   2317:                                addq(u,u1,&q[i]);
                   2318:                        } else
                   2319:                                q[i] = u;
                   2320:                }
                   2321:        }
1.34      noro     2322:        for ( i = 0; i < n; i++ ) c[i] = q[i];
1.16      noro     2323: }
                   2324:
1.19      noro     2325: void nd_mul_c(int mod,ND p,int mul)
1.1       noro     2326: {
                   2327:        NM m;
                   2328:        int c,c1;
                   2329:
1.34      noro     2330:        if ( !p ) return;
1.1       noro     2331:        for ( m = BDY(p); m; m = NEXT(m) ) {
1.14      noro     2332:                c1 = CM(m);
1.19      noro     2333:                DMAR(c1,mul,0,mod,c);
1.14      noro     2334:                CM(m) = c;
1.1       noro     2335:        }
                   2336: }
                   2337:
1.16      noro     2338: void nd_mul_c_q(ND p,Q mul)
                   2339: {
                   2340:        NM m;
                   2341:        Q c;
                   2342:
1.34      noro     2343:        if ( !p ) return;
1.16      noro     2344:        for ( m = BDY(p); m; m = NEXT(m) ) {
                   2345:                mulq(CQ(m),mul,&c); CQ(m) = c;
                   2346:        }
                   2347: }
                   2348:
1.1       noro     2349: void nd_free(ND p)
                   2350: {
                   2351:        NM t,s;
                   2352:
1.34      noro     2353:        if ( !p ) return;
1.1       noro     2354:        t = BDY(p);
                   2355:        while ( t ) {
                   2356:                s = NEXT(t);
                   2357:                FREENM(t);
                   2358:                t = s;
                   2359:        }
                   2360:        FREEND(p);
                   2361: }
                   2362:
1.23      noro     2363: void ndv_free(NDV p)
                   2364: {
                   2365:        GC_free(BDY(p));
                   2366: }
                   2367:
1.34      noro     2368: void nd_append_red(unsigned int *d,int i)
1.1       noro     2369: {
1.13      noro     2370:        RHist m,m0;
1.1       noro     2371:        int h;
                   2372:
1.13      noro     2373:        NEWRHist(m);
1.34      noro     2374:        h = ndl_hash_value(d);
1.13      noro     2375:        m->index = i;
1.14      noro     2376:        ndl_copy(d,DL(m));
1.1       noro     2377:        NEXT(m) = nd_red[h];
                   2378:        nd_red[h] = m;
                   2379: }
                   2380:
1.5       noro     2381: unsigned int *dp_compute_bound(DP p)
                   2382: {
                   2383:        unsigned int *d,*d1,*d2,*t;
                   2384:        MP m;
1.7       noro     2385:        int i,l;
1.5       noro     2386:
                   2387:        if ( !p )
                   2388:                return 0;
                   2389:        d1 = (unsigned int *)ALLOCA(nd_nvar*sizeof(unsigned int));
                   2390:        d2 = (unsigned int *)ALLOCA(nd_nvar*sizeof(unsigned int));
                   2391:        m = BDY(p);
1.35      noro     2392:        d = DL(m)->d;
                   2393:        for ( i = 0; i < nd_nvar; i++ ) d1[i] = d[i];
1.5       noro     2394:        for ( m = NEXT(BDY(p)); m; m = NEXT(m) ) {
1.14      noro     2395:                d = DL(m)->d;
1.5       noro     2396:                for ( i = 0; i < nd_nvar; i++ )
                   2397:                        d2[i] = d[i] > d1[i] ? d[i] : d1[i];
                   2398:                t = d1; d1 = d2; d2 = t;
                   2399:        }
1.13      noro     2400:        l = (nd_nvar+31);
1.7       noro     2401:        t = (unsigned int *)MALLOC_ATOMIC(l*sizeof(unsigned int));
1.35      noro     2402:        for ( i = 0; i < nd_nvar; i++ ) t[i] = d1[i];
                   2403:        for ( ; i < l; i++ ) t[i] = 0;
1.5       noro     2404:        return t;
                   2405: }
                   2406:
1.1       noro     2407: unsigned int *nd_compute_bound(ND p)
                   2408: {
                   2409:        unsigned int *d1,*d2,*t;
1.9       noro     2410:        int i,l;
1.1       noro     2411:        NM m;
                   2412:
                   2413:        if ( !p )
                   2414:                return 0;
                   2415:        d1 = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int));
                   2416:        d2 = (unsigned int *)ALLOCA(nd_wpd*sizeof(unsigned int));
1.35      noro     2417:        ndl_copy(HDL(p),d1);
1.1       noro     2418:        for ( m = NEXT(BDY(p)); m; m = NEXT(m) ) {
1.14      noro     2419:                ndl_lcm(DL(m),d1,d2);
1.1       noro     2420:                t = d1; d1 = d2; d2 = t;
                   2421:        }
1.12      noro     2422:        l = nd_nvar+31;
1.9       noro     2423:        t = (unsigned int *)MALLOC_ATOMIC(l*sizeof(unsigned int));
1.35      noro     2424:        for ( i = 0; i < l; i++ ) t[i] = 0;
1.5       noro     2425:        for ( i = 0; i < nd_nvar; i++ )
1.34      noro     2426:                t[i] = (d1[i/nd_epw+1]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))&nd_mask0;
1.35      noro     2427:        for ( ; i < l; i++ ) t[i] = 0;
1.1       noro     2428:        return t;
                   2429: }
                   2430:
                   2431: void nd_setup_parameters() {
                   2432:        int i;
                   2433:
                   2434:        nd_epw = (sizeof(unsigned int)*8)/nd_bpe;
                   2435:        nd_wpd = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0);
                   2436:        if ( nd_bpe < 32 ) {
                   2437:                nd_mask0 = (1<<nd_bpe)-1;
                   2438:        } else {
                   2439:                nd_mask0 = 0xffffffff;
                   2440:        }
                   2441:        bzero(nd_mask,sizeof(nd_mask));
                   2442:        nd_mask1 = 0;
                   2443:        for ( i = 0; i < nd_epw; i++ ) {
                   2444:                nd_mask[nd_epw-i-1] = (nd_mask0<<(i*nd_bpe));
                   2445:                nd_mask1 |= (1<<(nd_bpe-1))<<(i*nd_bpe);
                   2446:        }
1.34      noro     2447:        nm_adv = sizeof(struct oNM)+nd_wpd*sizeof(unsigned int);
                   2448:        nmv_adv = sizeof(struct oNMV)+nd_wpd*sizeof(unsigned int);
1.1       noro     2449: }
                   2450:
1.20      noro     2451: /* mod < 0 => realloc nd_ps and pd_psq */
                   2452:
                   2453: ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
1.1       noro     2454: {
1.37      noro     2455:        int i,obpe,oadv,h;
1.13      noro     2456:        NM prev_nm_free_list;
                   2457:        RHist mr0,mr;
                   2458:        RHist r;
1.37      noro     2459:        RHist *old_red;
1.1       noro     2460:        ND_pairs s0,s,t,prev_ndp_free_list;
1.15      noro     2461:
1.1       noro     2462:        obpe = nd_bpe;
1.11      noro     2463:        oadv = nmv_adv;
1.34      noro     2464:        if ( obpe < 4 ) nd_bpe = 4;
                   2465:        else if ( obpe < 6 ) nd_bpe = 6;
                   2466:        else if ( obpe < 8 ) nd_bpe = 8;
                   2467:        else if ( obpe < 16 ) nd_bpe = 16;
                   2468:        else if ( obpe < 32 ) nd_bpe = 32;
                   2469:        else error("nd_reconstruct : exponent too large");
1.5       noro     2470:
1.1       noro     2471:        nd_setup_parameters();
                   2472:        prev_nm_free_list = _nm_free_list;
                   2473:        prev_ndp_free_list = _ndp_free_list;
                   2474:        _nm_free_list = 0;
                   2475:        _ndp_free_list = 0;
1.20      noro     2476:        if ( mod != 0 )
1.34      noro     2477:                for ( i = nd_psn-1; i >= 0; i-- ) ndv_realloc(nd_ps[i],obpe,oadv);
1.20      noro     2478:        if ( !mod || trace )
1.34      noro     2479:                for ( i = nd_psn-1; i >= 0; i-- ) ndv_realloc(nd_psq[i],obpe,oadv);
1.1       noro     2480:        s0 = 0;
                   2481:        for ( t = d; t; t = NEXT(t) ) {
                   2482:                NEXTND_pairs(s0,s);
                   2483:                s->i1 = t->i1;
                   2484:                s->i2 = t->i2;
1.14      noro     2485:                SG(s) = SG(t);
1.40    ! noro     2486:                ndl_reconstruct(obpe,LCM(t),LCM(s));
1.1       noro     2487:        }
1.37      noro     2488:
                   2489:        old_red = (RHist *)ALLOCA(REDTAB_LEN*sizeof(RHist));
1.6       noro     2490:        for ( i = 0; i < REDTAB_LEN; i++ ) {
1.37      noro     2491:                old_red[i] = nd_red[i];
                   2492:                nd_red[i] = 0;
                   2493:        }
                   2494:        for ( i = 0; i < REDTAB_LEN; i++ )
                   2495:                for ( r = old_red[i]; r; r = NEXT(r) ) {
                   2496:                        NEWRHist(mr);
1.13      noro     2497:                        mr->index = r->index;
1.20      noro     2498:                        SG(mr) = SG(r);
1.40    ! noro     2499:                        ndl_reconstruct(obpe,DL(r),DL(mr));
1.37      noro     2500:                        h = ndl_hash_value(DL(mr));
                   2501:                        NEXT(mr) = nd_red[h];
                   2502:                        nd_red[h] = mr;
1.6       noro     2503:                }
1.37      noro     2504:        for ( i = 0; i < REDTAB_LEN; i++ ) old_red[i] = 0;
                   2505:        old_red = 0;
1.11      noro     2506:        for ( i = 0; i < nd_psn; i++ ) {
1.20      noro     2507:                NEWRHist(r); SG(r) = SG(nd_psh[i]);
1.40    ! noro     2508:                ndl_reconstruct(obpe,DL(nd_psh[i]),DL(r));
1.13      noro     2509:                nd_psh[i] = r;
1.11      noro     2510:        }
1.1       noro     2511:        if ( s0 ) NEXT(s) = 0;
                   2512:        prev_nm_free_list = 0;
                   2513:        prev_ndp_free_list = 0;
                   2514:        GC_gcollect();
                   2515:        return s0;
                   2516: }
                   2517:
1.23      noro     2518: void nd_reconstruct_direct(int mod,NDV *ps,int len)
                   2519: {
1.37      noro     2520:        int i,obpe,oadv,h;
1.23      noro     2521:        NM prev_nm_free_list;
                   2522:        RHist mr0,mr;
                   2523:        RHist r;
1.37      noro     2524:        RHist *old_red;
1.23      noro     2525:        ND_pairs s0,s,t,prev_ndp_free_list;
                   2526:
                   2527:        obpe = nd_bpe;
                   2528:        oadv = nmv_adv;
1.34      noro     2529:        if ( obpe < 4 ) nd_bpe = 4;
                   2530:        else if ( obpe < 6 ) nd_bpe = 6;
                   2531:        else if ( obpe < 8 ) nd_bpe = 8;
                   2532:        else if ( obpe < 16 ) nd_bpe = 16;
                   2533:        else if ( obpe < 32 ) nd_bpe = 32;
                   2534:        else error("nd_reconstruct_direct : exponent too large");
1.23      noro     2535:
                   2536:        nd_setup_parameters();
                   2537:        prev_nm_free_list = _nm_free_list;
                   2538:        prev_ndp_free_list = _ndp_free_list;
1.34      noro     2539:        _nm_free_list = 0; _ndp_free_list = 0;
1.23      noro     2540:        if ( mod != 0 )
1.34      noro     2541:                for ( i = len-1; i >= 0; i-- ) ndv_realloc(ps[i],obpe,oadv);
1.37      noro     2542:        old_red = (RHist *)ALLOCA(REDTAB_LEN*sizeof(RHist));
1.31      noro     2543:        for ( i = 0; i < REDTAB_LEN; i++ ) {
1.37      noro     2544:                old_red[i] = nd_red[i];
                   2545:                nd_red[i] = 0;
                   2546:        }
                   2547:        for ( i = 0; i < REDTAB_LEN; i++ )
                   2548:                for ( r = old_red[i]; r; r = NEXT(r) ) {
                   2549:                        NEWRHist(mr);
1.31      noro     2550:                        mr->index = r->index;
                   2551:                        SG(mr) = SG(r);
1.40    ! noro     2552:                        ndl_reconstruct(obpe,DL(r),DL(mr));
1.37      noro     2553:                        h = ndl_hash_value(DL(mr));
                   2554:                        NEXT(mr) = nd_red[h];
                   2555:                        nd_red[h] = mr;
1.31      noro     2556:                }
1.37      noro     2557:        for ( i = 0; i < REDTAB_LEN; i++ ) old_red[i] = 0;
                   2558:        old_red = 0;
1.23      noro     2559:        prev_nm_free_list = 0;
                   2560:        prev_ndp_free_list = 0;
                   2561:        GC_gcollect();
                   2562: }
                   2563:
1.40    ! noro     2564: void ndl_reconstruct(int obpe,unsigned int *d,unsigned int *r)
1.1       noro     2565: {
                   2566:        int n,i,ei,oepw,cepw,cbpe;
                   2567:
                   2568:        n = nd_nvar;
                   2569:        oepw = (sizeof(unsigned int)*8)/obpe;
                   2570:        cepw = nd_epw;
                   2571:        cbpe = nd_bpe;
1.34      noro     2572:        TD(r) = TD(d);
                   2573:        for ( i = 1; i <= nd_wpd; i++ ) r[i] = 0;
1.32      noro     2574:        if ( nd_isrlex )
1.1       noro     2575:                for ( i = 0; i < n; i++ ) {
1.34      noro     2576:                        ei = (d[(n-1-i)/oepw+1]>>((oepw-((n-1-i)%oepw)-1)*obpe))
1.1       noro     2577:                                &((1<<obpe)-1);
1.34      noro     2578:                        r[(n-1-i)/cepw+1] |= (ei<<((cepw-((n-1-i)%cepw)-1)*cbpe));
1.1       noro     2579:                }
                   2580:        else
                   2581:                for ( i = 0; i < n; i++ ) {
1.34      noro     2582:                        ei = (d[i/oepw+1]>>((oepw-(i%oepw)-1)*obpe))
1.1       noro     2583:                                &((1<<obpe)-1);
1.34      noro     2584:                        r[i/cepw+1] |= (ei<<((cepw-(i%cepw)-1)*cbpe));
1.1       noro     2585:                }
                   2586: }
                   2587:
1.11      noro     2588: void nd_realloc(ND p,int obpe)
1.1       noro     2589: {
                   2590:        NM m,mr,mr0;
                   2591:
1.11      noro     2592:        if ( p ) {
                   2593:                m = BDY(p);
1.1       noro     2594:                for ( mr0 = 0; m; m = NEXT(m) ) {
                   2595:                        NEXTNM(mr0,mr);
1.14      noro     2596:                        CM(mr) = CM(m);
1.40    ! noro     2597:                        ndl_reconstruct(obpe,DL(m),DL(mr));
1.1       noro     2598:                }
                   2599:                NEXT(mr) = 0;
1.11      noro     2600:                BDY(p) = mr0;
1.1       noro     2601:        }
                   2602: }
1.3       noro     2603:
1.6       noro     2604: ND nd_copy(ND p)
                   2605: {
                   2606:        NM m,mr,mr0;
                   2607:        int c,n,s;
                   2608:        ND r;
                   2609:
                   2610:        if ( !p )
                   2611:                return 0;
                   2612:        else {
1.34      noro     2613:                s = sizeof(struct oNM)+nd_wpd*sizeof(unsigned int);
1.6       noro     2614:                for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
                   2615:                        NEXTNM(mr0,mr);
1.14      noro     2616:                        CM(mr) = CM(m);
                   2617:                        ndl_copy(DL(m),DL(mr));
1.6       noro     2618:                }
                   2619:                NEXT(mr) = 0;
1.31      noro     2620:                MKND(NV(p),mr0,LEN(p),r);
1.14      noro     2621:                SG(r) = SG(p);
1.6       noro     2622:                return r;
                   2623:        }
                   2624: }
                   2625:
1.16      noro     2626: int nd_sp(int mod,ND_pairs p,ND *rp)
1.11      noro     2627: {
                   2628:        NM m;
                   2629:        NDV p1,p2;
                   2630:        ND t1,t2;
                   2631:        unsigned int *lcm;
1.31      noro     2632:        int td;
1.11      noro     2633:
1.20      noro     2634:        if ( mod ) {
                   2635:                p1 = nd_ps[p->i1]; p2 = nd_ps[p->i2];
                   2636:        } else {
                   2637:                p1 = nd_psq[p->i1]; p2 = nd_psq[p->i2];
                   2638:        }
1.34      noro     2639:        lcm = LCM(p);
1.11      noro     2640:        NEWNM(m);
1.20      noro     2641:        CQ(m) = HCQ(p2);
1.34      noro     2642:        ndl_sub(lcm,HDL(p1),DL(m));
                   2643:        if ( ndl_check_bound2(p->i1,DL(m)) ) return 0;
1.25      noro     2644:        t1 = ndv_mul_nm(mod,p1,m);
1.34      noro     2645:        if ( mod ) CM(m) = mod-HCM(p1);
                   2646:        else chsgnq(HCQ(p1),&CQ(m));
                   2647:        ndl_sub(lcm,HDL(p2),DL(m));
1.14      noro     2648:        if ( ndl_check_bound2(p->i2,DL(m)) ) {
1.11      noro     2649:                nd_free(t1);
                   2650:                return 0;
                   2651:        }
1.25      noro     2652:        t2 = ndv_mul_nm(mod,p2,m);
1.31      noro     2653:        *rp = nd_add(mod,t1,t2);
1.11      noro     2654:        FREENM(m);
                   2655:        return 1;
                   2656: }
                   2657:
1.19      noro     2658: void ndv_mul_c(int mod,NDV p,int mul)
1.11      noro     2659: {
                   2660:        NMV m;
                   2661:        int c,c1,len,i;
                   2662:
1.34      noro     2663:        if ( !p ) return;
1.14      noro     2664:        len = LEN(p);
1.11      noro     2665:        for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) {
1.34      noro     2666:                c1 = CM(m); DMAR(c1,mul,0,mod,c); CM(m) = c;
1.11      noro     2667:        }
                   2668: }
                   2669:
1.16      noro     2670: void ndv_mul_c_q(NDV p,Q mul)
                   2671: {
                   2672:        NMV m;
                   2673:        Q c;
                   2674:        int len,i;
                   2675:
1.34      noro     2676:        if ( !p ) return;
1.16      noro     2677:        len = LEN(p);
                   2678:        for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) {
                   2679:                mulq(CQ(m),mul,&c); CQ(m) = c;
                   2680:        }
                   2681: }
                   2682:
1.25      noro     2683: ND ndv_mul_nm(int mod,NDV p,NM m0)
1.9       noro     2684: {
                   2685:        NM mr,mr0;
                   2686:        NMV m;
                   2687:        unsigned int *d,*dt,*dm;
                   2688:        int c,n,td,i,c1,c2,len;
1.16      noro     2689:        Q q;
1.9       noro     2690:        ND r;
                   2691:
1.34      noro     2692:        if ( !p ) return 0;
1.9       noro     2693:        else {
                   2694:                n = NV(p); m = BDY(p);
1.34      noro     2695:                d = DL(m0);
1.14      noro     2696:                len = LEN(p);
1.9       noro     2697:                mr0 = 0;
1.34      noro     2698:                td = TD(d);
1.16      noro     2699:                if ( mod ) {
                   2700:                        c = CM(m0);
                   2701:                        for ( i = 0; i < len; i++, NMV_ADV(m) ) {
                   2702:                                NEXTNM(mr0,mr);
                   2703:                                c1 = CM(m);
1.19      noro     2704:                                DMAR(c1,c,0,mod,c2);
1.16      noro     2705:                                CM(mr) = c2;
                   2706:                                ndl_add(DL(m),d,DL(mr));
                   2707:                        }
                   2708:                } else {
                   2709:                        q = CQ(m0);
                   2710:                        for ( i = 0; i < len; i++, NMV_ADV(m) ) {
                   2711:                                NEXTNM(mr0,mr);
                   2712:                                mulq(CQ(m),q,&CQ(mr));
                   2713:                                ndl_add(DL(m),d,DL(mr));
                   2714:                        }
1.4       noro     2715:                }
1.9       noro     2716:                NEXT(mr) = 0;
1.31      noro     2717:                MKND(NV(p),mr0,len,r);
1.34      noro     2718:                SG(r) = SG(p) + TD(d);
1.9       noro     2719:                return r;
1.4       noro     2720:        }
                   2721: }
                   2722:
1.11      noro     2723: void ndv_realloc(NDV p,int obpe,int oadv)
                   2724: {
1.13      noro     2725:        NMV m,mr,mr0,t;
                   2726:        int len,i,k;
1.11      noro     2727:
1.13      noro     2728: #define NMV_OPREV(m) (m = (NMV)(((char *)m)-oadv))
                   2729: #define NMV_PREV(m) (m = (NMV)(((char *)m)-nmv_adv))
1.11      noro     2730:
                   2731:        if ( p ) {
1.14      noro     2732:                m = BDY(p); len = LEN(p);
1.34      noro     2733:                mr0 = nmv_adv>oadv?(NMV)REALLOC(BDY(p),len*nmv_adv):BDY(p);
1.13      noro     2734:                m = (NMV)((char *)mr0+(len-1)*oadv);
                   2735:                mr = (NMV)((char *)mr0+(len-1)*nmv_adv);
                   2736:                t = (NMV)ALLOCA(nmv_adv);
                   2737:                for ( i = 0; i < len; i++, NMV_OPREV(m), NMV_PREV(mr) ) {
1.16      noro     2738:                        CQ(t) = CQ(m);
1.14      noro     2739:                        for ( k = 0; k < nd_wpd; k++ ) DL(t)[k] = 0;
1.40    ! noro     2740:                        ndl_reconstruct(obpe,DL(m),DL(t));
1.16      noro     2741:                        CQ(mr) = CQ(t);
1.14      noro     2742:                        ndl_copy(DL(t),DL(mr));
1.11      noro     2743:                }
                   2744:                BDY(p) = mr0;
                   2745:        }
                   2746: }
                   2747:
1.16      noro     2748: NDV ndtondv(int mod,ND p)
1.3       noro     2749: {
                   2750:        NDV d;
                   2751:        NMV m,m0;
                   2752:        NM t;
                   2753:        int i,len;
                   2754:
1.34      noro     2755:        if ( !p ) return 0;
1.31      noro     2756:        len = LEN(p);
1.34      noro     2757:        m0 = m = (NMV)(mod?MALLOC_ATOMIC(len*nmv_adv):MALLOC(len*nmv_adv));
1.3       noro     2758:        for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, NMV_ADV(m) ) {
1.14      noro     2759:                ndl_copy(DL(t),DL(m));
1.16      noro     2760:                CQ(m) = CQ(t);
1.3       noro     2761:        }
                   2762:        MKNDV(NV(p),m0,len,d);
1.23      noro     2763:        SG(d) = SG(p);
                   2764:        return d;
                   2765: }
                   2766:
                   2767: ND ndvtond(int mod,NDV p)
                   2768: {
                   2769:        ND d;
                   2770:        NM m,m0;
                   2771:        NMV t;
                   2772:        int i,len;
                   2773:
1.34      noro     2774:        if ( !p ) return 0;
1.23      noro     2775:        m0 = 0;
                   2776:        len = p->len;
                   2777:        for ( t = BDY(p), i = 0; i < len; NMV_ADV(t), i++ ) {
                   2778:                NEXTNM(m0,m);
                   2779:                ndl_copy(DL(t),DL(m));
                   2780:                CQ(m) = CQ(t);
                   2781:        }
                   2782:        NEXT(m) = 0;
1.31      noro     2783:        MKND(NV(p),m0,len,d);
1.14      noro     2784:        SG(d) = SG(p);
1.3       noro     2785:        return d;
                   2786: }
                   2787:
1.16      noro     2788: NDV dptondv(int mod,DP p)
1.11      noro     2789: {
                   2790:        NDV d;
                   2791:        NMV m0,m;
                   2792:        MP t;
1.20      noro     2793:        DP q;
1.11      noro     2794:        int l,i,n;
                   2795:
1.34      noro     2796:        if ( !p ) return 0;
1.11      noro     2797:        for ( t = BDY(p), l = 0; t; t = NEXT(t), l++ );
1.20      noro     2798:        if ( mod ) {
                   2799:                _dp_mod(p,mod,0,&q); p = q;
1.16      noro     2800:                m0 = m = (NMV)MALLOC_ATOMIC(l*nmv_adv);
1.20      noro     2801:        } else
1.16      noro     2802:                m0 = m = (NMV)MALLOC(l*nmv_adv);
1.11      noro     2803:        n = NV(p);
1.17      noro     2804:        for ( t = BDY(p), i = 0; i < l; i++, t = NEXT(t), NMV_ADV(m) ) {
1.34      noro     2805:                if ( mod ) CM(m) = ITOS(C(t));
                   2806:                else CQ(m) = (Q)C(t);
1.17      noro     2807:                dltondl(n,DL(t),DL(m));
1.11      noro     2808:        }
                   2809:        MKNDV(n,m0,l,d);
1.14      noro     2810:        SG(d) = SG(p);
1.11      noro     2811:        return d;
                   2812: }
                   2813:
1.16      noro     2814: DP ndvtodp(int mod,NDV p)
1.11      noro     2815: {
                   2816:        DP d;
                   2817:        MP m0,m;
                   2818:        NMV t;
                   2819:        int len,i,n;
                   2820:
1.34      noro     2821:        if ( !p ) return 0;
1.11      noro     2822:        m0 = 0;
1.14      noro     2823:        len = LEN(p);
1.11      noro     2824:        n = NV(p);
1.17      noro     2825:        for ( t = BDY(p), i = 0; i < len; i++, NMV_ADV(t) ) {
                   2826:                NEXTMP(m0,m);
1.34      noro     2827:                if ( mod ) C(m) = STOI(CM(t));
                   2828:                else C(m) = (P)CQ(t);
                   2829:                DL(m) = ndltodl(n,DL(t));
1.11      noro     2830:        }
                   2831:        NEXT(m) = 0;
                   2832:        MKDP(NV(p),m0,d);
1.14      noro     2833:        SG(d) = SG(p);
1.11      noro     2834:        return d;
                   2835: }
                   2836:
1.3       noro     2837: void ndv_print(NDV p)
                   2838: {
                   2839:        NMV m;
                   2840:        int i,len;
                   2841:
1.34      noro     2842:        if ( !p ) printf("0\n");
1.3       noro     2843:        else {
1.14      noro     2844:                len = LEN(p);
1.3       noro     2845:                for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) {
1.14      noro     2846:                        printf("+%d*",CM(m));
1.16      noro     2847:                        ndl_print(DL(m));
                   2848:                }
                   2849:                printf("\n");
                   2850:        }
                   2851: }
                   2852:
                   2853: void ndv_print_q(NDV p)
                   2854: {
                   2855:        NMV m;
                   2856:        int i,len;
                   2857:
1.34      noro     2858:        if ( !p ) printf("0\n");
1.16      noro     2859:        else {
                   2860:                len = LEN(p);
                   2861:                for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) {
                   2862:                        printf("+");
                   2863:                        printexpr(CO,CQ(m));
                   2864:                        printf("*");
1.14      noro     2865:                        ndl_print(DL(m));
1.3       noro     2866:                }
                   2867:                printf("\n");
                   2868:        }
1.25      noro     2869: }
                   2870:
1.27      noro     2871: NODE nd_reducebase(NODE x)
                   2872: {
                   2873:        int len,i,j;
                   2874:        NDV *w;
                   2875:        NODE t,t0;
                   2876:
                   2877:        len = length(x);
                   2878:        w = (NDV *)ALLOCA(len*sizeof(NDV));
                   2879:        for ( i = 0, t = x; i < len; i++, t = NEXT(t) ) w[i] = BDY(t);
                   2880:        for ( i = 0; i < len; i++ ) {
                   2881:                for ( j = 0; j < i; j++ ) {
                   2882:                        if ( w[i] && w[j] )
                   2883:                                if ( ndl_reducible(HDL(w[i]),HDL(w[j])) ) w[i] = 0;
                   2884:                                else if ( ndl_reducible(HDL(w[j]),HDL(w[i])) ) w[j] = 0;
                   2885:                }
                   2886:        }
                   2887:        for ( i = len-1, t0 = 0; i >= 0; i-- ) {
                   2888:                if ( w[i] ) { NEXTNODE(t0,t); BDY(t) = (pointer)w[i]; }
                   2889:        }
                   2890:        NEXT(t) = 0; x = t0;
                   2891:        return x;
1.11      noro     2892: }
1.32      noro     2893:
                   2894: void nd_init_ord(struct order_spec *ord)
                   2895: {
                   2896:        if ( ord->id )
                   2897:                error("nd_gr : unsupported order");
1.34      noro     2898:        nd_dcomp = 0;
1.32      noro     2899:        switch ( ord->ord.simple ) {
                   2900:                case 0:
1.34      noro     2901:                        nd_dcomp = 1;
1.32      noro     2902:                        nd_isrlex = 1;
                   2903:                        break;
                   2904:                case 1:
1.34      noro     2905:                        nd_dcomp = 1;
1.32      noro     2906:                        nd_isrlex = 0;
1.34      noro     2907:                        break;
                   2908:                case 9:
                   2909:                        /* td1->td->rlex */
                   2910:                        nd_dcomp = -dp_nelim;
                   2911:                        nd_isrlex = 1;
1.32      noro     2912:                        break;
                   2913:                default:
                   2914:                        error("nd_gr : unsupported order");
                   2915:        }
                   2916: }
                   2917:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>