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

Annotation of OpenXM_contrib2/asir2000/engine/nd.h, Revision 1.11

1.11    ! noro        1: /* $OpenXM$ */
1.1       noro        2: #include "ca.h"
                      3: #include "parse.h"
                      4: #include "ox.h"
                      5: #include "base.h"
                      6: #include "inline.h"
                      7: #include <time.h>
                      8:
                      9: #if defined(__GNUC__)
                     10: #define INLINE inline
                     11: #elif defined(VISUAL)
                     12: #define INLINE __inline
                     13: #else
                     14: #define INLINE
                     15: #endif
                     16:
                     17: typedef unsigned int UINT;
                     18:
                     19: #define USE_GEOBUCKET 1
                     20: #define USE_UNROLL 1
                     21:
                     22: #define REDTAB_LEN 32003
                     23:
                     24: /* GeoBucket for polynomial addition */
                     25:
                     26: typedef struct oPGeoBucket {
                     27:        int m;
                     28:        struct oND *body[32];
                     29: } *PGeoBucket;
                     30:
                     31: /* distributed polynomial; linked list rep. */
                     32: typedef struct oND {
                     33:        struct oNM *body;
                     34:        int nv;
                     35:        int len;
                     36:        int sugar;
                     37: } *ND;
                     38:
                     39: /* distributed polynomial; array rep. */
                     40: typedef struct oNDV {
                     41:        struct oNMV *body;
                     42:        int nv;
                     43:        int len;
                     44:        int sugar;
                     45: } *NDV;
                     46:
                     47: typedef union oNDC {
                     48:        int m;
1.11    ! noro       49:        Q z;
1.1       noro       50:        P p;
                     51: } *NDC;
                     52:
                     53: /* monomial; linked list rep. */
                     54: typedef struct oNM {
                     55:        struct oNM *next;
                     56:        union oNDC c;
                     57:        UINT dl[1];
                     58: } *NM;
                     59:
                     60: /* monomial; array rep. */
                     61: typedef struct oNMV {
                     62:        union oNDC c;
                     63:        UINT dl[1];
                     64: } *NMV;
                     65:
                     66: /* history of reducer */
                     67: typedef struct oRHist {
                     68:        struct oRHist *next;
                     69:        int index;
                     70:        int sugar;
                     71:        UINT dl[1];
                     72: } *RHist;
                     73:
                     74: /* S-pair list */
                     75: typedef struct oND_pairs {
                     76:        struct oND_pairs *next;
                     77:        int i1,i2;
                     78:        int sugar;
                     79:        UINT lcm[1];
                     80: } *ND_pairs;
                     81:
                     82: /* index and shift count for each exponent */
                     83: typedef struct oEPOS {
                     84:        int i; /* index */
                     85:        int s; /* shift */
                     86: } *EPOS;
                     87:
                     88: typedef struct oBlockMask {
                     89:        int n;
                     90:        struct order_pair *order_pair;
                     91:        UINT **mask;
                     92: } *BlockMask;
                     93:
                     94: typedef struct oBaseSet {
                     95:        int len;
                     96:        NDV *ps;
                     97:        UINT **bound;
                     98: } *BaseSet;
                     99:
                    100: typedef struct oNM_ind_pair
                    101: {
                    102:        NM mul;
                    103:        int index,sugar;
                    104: } *NM_ind_pair;
                    105:
                    106: typedef struct oIndArray
                    107: {
                    108:        char width;
                    109:        int head;
                    110:        union {
                    111:                unsigned char *c;
                    112:                unsigned short *s;
                    113:                unsigned int *i;
                    114:        } index;
                    115: } *IndArray;
                    116:
                    117: extern int (*ndl_compare_function)(UINT *a1,UINT *a2);
                    118: extern int nd_dcomp;
                    119:
                    120: extern NM _nm_free_list;
                    121: extern ND _nd_free_list;
                    122: extern ND_pairs _ndp_free_list;
                    123:
                    124: extern struct order_spec *dp_current_spec;
                    125: extern char *Demand;
                    126: extern VL CO;
                    127: extern int Top,Reverse,DP_Print,dp_nelim,do_weyl,NoSugar;
                    128: extern int *current_weyl_weight_vector;
                    129:
                    130: /* fundamental macros */
                    131: #define TD(d) (d[0])
                    132: #define HDL(d) ((d)->body->dl)
                    133: #define HTD(d) (TD(HDL(d)))
                    134: #define HCM(d) ((d)->body->c.m)
1.11    ! noro      135: #define HCQ(d) ((d)->body->c.z)
1.1       noro      136: #define HCP(d) ((d)->body->c.p)
                    137: #define CM(a) ((a)->c.m)
1.11    ! noro      138: #define CQ(a) ((a)->c.z)
1.1       noro      139: #define CP(a) ((a)->c.p)
                    140: #define DL(a) ((a)->dl)
                    141: #define SG(a) ((a)->sugar)
                    142: #define LEN(a) ((a)->len)
                    143: #define LCM(a) ((a)->lcm)
                    144: #define GET_EXP(d,a) (((d)[nd_epos[a].i]>>nd_epos[a].s)&nd_mask0)
                    145: #define GET_EXP_MASK(d,a,m) ((((d)[nd_epos[a].i]&(m)[nd_epos[a].i])>>nd_epos[a].s)&nd_mask0)
                    146: #define PUT_EXP(r,a,e) ((r)[nd_epos[a].i] |= ((e)<<nd_epos[a].s))
                    147: #define XOR_EXP(r,a,e) ((r)[nd_epos[a].i] ^= ((e)<<nd_epos[a].s))
                    148:
                    149: #define GET_EXP_OLD(d,a) (((d)[oepos[a].i]>>oepos[a].s)&omask0)
                    150: #define PUT_EXP_OLD(r,a,e) ((r)[oepos[a].i] |= ((e)<<oepos[a].s))
                    151:
                    152: #define ROUND_FOR_ALIGN(s) ((((s)+sizeof(void *)-1)/sizeof(void *))*sizeof(void *))
                    153:
                    154: /* macros for term comparison */
                    155: #define TD_DL_COMPARE(d1,d2)\
                    156: (TD(d1)>TD(d2)?1:(TD(d1)<TD(d2)?-1:ndl_lex_compare(d1,d2)))
                    157: #if 0
                    158: #define DL_COMPARE(d1,d2)\
                    159: (nd_dcomp>0?TD_DL_COMPARE(d1,d2)\
                    160:          :(nd_dcomp==0?ndl_lex_compare(d1,d2)\
                    161:                      :(nd_blockmask?ndl_block_compare(d1,d2)\
                    162:                                                                   :(*ndl_compare_function)(d1,d2))))
                    163: #else
                    164: #define DL_COMPARE(d1,d2)\
                    165: (nd_dcomp>0?TD_DL_COMPARE(d1,d2):(*ndl_compare_function)(d1,d2))
                    166: #endif
                    167:
                    168: /* allocators */
                    169: #define NEWRHist(r) \
                    170: ((r)=(RHist)MALLOC(sizeof(struct oRHist)+(nd_wpd-1)*sizeof(UINT)))
                    171: #define NEWND_pairs(m) \
                    172: if(!_ndp_free_list)_NDP_alloc();\
                    173: (m)=_ndp_free_list; _ndp_free_list = NEXT(_ndp_free_list)
                    174: #define NEWNM(m)\
                    175: if(!_nm_free_list)_NM_alloc();\
                    176: (m)=_nm_free_list; _nm_free_list = NEXT(_nm_free_list)
                    177: #define MKND(n,m,len,d)\
                    178: if(!_nd_free_list)_ND_alloc();\
                    179: (d)=_nd_free_list; _nd_free_list = (ND)BDY(_nd_free_list);\
                    180: NV(d)=(n); LEN(d)=(len); BDY(d)=(m)
                    181: #define NEWNDV(d) ((d)=(NDV)MALLOC(sizeof(struct oNDV)))
                    182: #define MKNDV(n,m,l,d) NEWNDV(d); NV(d)=(n); BDY(d)=(m); LEN(d) = l;
                    183: #define NEWNM_ind_pair(p)\
                    184: ((p)=(NM_ind_pair)MALLOC(sizeof(struct oNM_ind_pair)))
                    185:
                    186: /* allocate and link a new object */
                    187: #define NEXTRHist(r,c) \
                    188: if(!(r)){NEWRHist(r);(c)=(r);}else{NEWRHist(NEXT(c));(c)=NEXT(c);}
                    189: #define NEXTNM(r,c) \
                    190: if(!(r)){NEWNM(r);(c)=(r);}else{NEWNM(NEXT(c));(c)=NEXT(c);}
                    191: #define NEXTNM2(r,c,s) \
                    192: if(!(r)){(c)=(r)=(s);}else{NEXT(c)=(s);(c)=(s);}
                    193: #define NEXTND_pairs(r,c) \
                    194: if(!(r)){NEWND_pairs(r);(c)=(r);}else{NEWND_pairs(NEXT(c));(c)=NEXT(c);}
                    195: #define MKNM_ind_pair(p,m,i,s) (NEWNM_ind_pair(p),(p)->mul=(m),(p)->index=(i),(p)->sugar = (s))
                    196:
                    197: /* deallocators */
                    198: #define FREENM(m) NEXT(m)=_nm_free_list; _nm_free_list=(m)
                    199: #define FREENDP(m) NEXT(m)=_ndp_free_list; _ndp_free_list=(m)
                    200: #define FREEND(m) BDY(m)=(NM)_nd_free_list; _nd_free_list=(m)
                    201:
                    202: /* macro for increasing pointer to NMV */
                    203: #define NMV_ADV(m) (m = (NMV)(((char *)m)+nmv_adv))
                    204: #define NMV_OADV(m) (m = (NMV)(((char *)m)+oadv))
                    205: #define NDV_NADV(m) (m = (NMV)(((char *)m)+newadv))
                    206: #define NMV_PREV(m) (m = (NMV)(((char *)m)-nmv_adv))
                    207: #define NMV_OPREV(m) (m = (NMV)(((char *)m)-oadv))
                    208:
                    209: /* external functions */
                    210: #if 1
                    211: void GC_gcollect();
                    212: #endif
                    213: NODE append_one(NODE,int);
                    214:
                    215: /* manipulation of coefficients */
                    216: void nd_removecont(int mod,ND p);
                    217: void nd_removecont2(ND p1,ND p2);
1.11    ! noro      218: void removecont_array(Q *c,int n);
1.1       noro      219:
                    220: /* GeoBucket functions */
                    221: ND normalize_pbucket(int mod,PGeoBucket g);
                    222: int head_pbucket(int mod,PGeoBucket g);
1.11    ! noro      223: int head_pbucket_q(PGeoBucket g);
1.1       noro      224: void add_pbucket_symbolic(PGeoBucket g,ND d);
                    225: void add_pbucket(int mod,PGeoBucket g,ND d);
                    226: void free_pbucket(PGeoBucket b);
1.11    ! noro      227: void mulq_pbucket(PGeoBucket g,Q c);
1.1       noro      228: NM remove_head_pbucket_symbolic(PGeoBucket g);
                    229: PGeoBucket create_pbucket();
                    230:
                    231: /* manipulation of pairs and bases */
                    232: int nd_newps(int mod,ND a,ND aq);
                    233: ND_pairs nd_newpairs( NODE g, int t );
                    234: ND_pairs nd_minp( ND_pairs d, ND_pairs *prest );
                    235: ND_pairs nd_minsugarp( ND_pairs d, ND_pairs *prest );
                    236: NODE update_base(NODE nd,int ndp);
                    237: ND_pairs update_pairs( ND_pairs d, NODE /* of index */ g, int t);
                    238: ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest );
                    239: ND_pairs crit_B( ND_pairs d, int s );
                    240: ND_pairs crit_M( ND_pairs d1 );
                    241: ND_pairs crit_F( ND_pairs d1 );
                    242: int crit_2( int dp1, int dp2 );
                    243: int ndv_newps(int m,NDV a,NDV aq);
                    244:
                    245: /* top level functions */
                    246: void nd_gr(LIST f,LIST v,int m,int f4,struct order_spec *ord,LIST *rp);
                    247: void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp);
                    248: NODE nd_f4(int m);
                    249: NODE nd_gb(int m,int ishomo,int checkonly);
                    250: NODE nd_gb_trace(int m,int ishomo);
                    251:
                    252: /* ndl functions */
                    253: int ndl_weight(UINT *d);
                    254: void ndl_weight_mask(UINT *d);
                    255: void ndl_homogenize(UINT *d,UINT *r,int obpe,EPOS oepos,int weight);
                    256: void ndl_dehomogenize(UINT *p);
                    257: void ndl_reconstruct(UINT *d,UINT *r,int obpe,EPOS oepos);
                    258: INLINE int ndl_reducible(UINT *d1,UINT *d2);
                    259: INLINE int ndl_lex_compare(UINT *d1,UINT *d2);
                    260: INLINE int ndl_block_compare(UINT *d1,UINT *d2);
1.2       noro      261: INLINE int ndl_matrix_compare(UINT *d1,UINT *d2);
1.3       noro      262: INLINE int ndl_composite_compare(UINT *d1,UINT *d2);
1.1       noro      263: INLINE int ndl_equal(UINT *d1,UINT *d2);
                    264: INLINE void ndl_copy(UINT *d1,UINT *d2);
                    265: INLINE void ndl_zero(UINT *d);
                    266: INLINE void ndl_add(UINT *d1,UINT *d2,UINT *d);
                    267: INLINE void ndl_addto(UINT *d1,UINT *d2);
                    268: INLINE void ndl_sub(UINT *d1,UINT *d2,UINT *d);
                    269: INLINE int ndl_hash_value(UINT *d);
                    270:
                    271: /* normal forms */
                    272: INLINE int ndl_find_reducer(UINT *g);
                    273: int nd_sp(int mod,int trace,ND_pairs p,ND *nf);
1.11    ! noro      274: int nd_nf(int mod,ND g,NDV *ps,int full,NDC dn,ND *nf);
1.1       noro      275: int nd_nf_pbucket(int mod,ND g,NDV *ps,int full,ND *nf);
                    276:
                    277: /* finalizers */
                    278: NODE ndv_reducebase(NODE x);
                    279: NODE ndv_reduceall(int m,NODE f);
                    280:
                    281: /* allocators */
                    282: void nd_free_private_storage();
                    283: void _NM_alloc();
                    284: void _ND_alloc();
                    285: void nd_free(ND p);
                    286: void nd_free_redlist();
                    287:
                    288: /* printing */
                    289: void ndl_print(UINT *dl);
                    290: void nd_print(ND p);
1.11    ! noro      291: void nd_print_q(ND p);
1.1       noro      292: void ndp_print(ND_pairs d);
                    293:
                    294:
                    295: /* setup, reconstruct */
                    296: void nd_init_ord(struct order_spec *spec);
1.6       noro      297: ND_pairs nd_reconstruct(int trace,ND_pairs ndp);
1.1       noro      298: void ndv_setup(int mod,int trace,NODE f);
                    299: void nd_setup_parameters(int nvar,int max);
                    300: BlockMask nd_create_blockmask(struct order_spec *ord);
                    301: EPOS nd_create_epos(struct order_spec *ord);
                    302: int nd_get_exporigin(struct order_spec *ord);
                    303: void ndv_mod(int mod,NDV p);
                    304: NDV ndv_dup(int mod,NDV p);
                    305: ND nd_dup(ND p);
                    306:
                    307: /* ND functions */
                    308: int ndv_check_candidate(NODE input,int obpe,int oadv,EPOS oepos,NODE cand);
                    309: void nd_mul_c(int mod,ND p,int mul);
1.11    ! noro      310: void nd_mul_c_q(ND p,Q mul);
1.1       noro      311: void nd_mul_c_p(VL vl,ND p,P mul);
                    312: ND nd_remove_head(ND p);
                    313: ND nd_separate_head(ND p,ND *head);
                    314: int nd_length(ND p);
                    315: void nd_append_red(UINT *d,int i);
                    316: UINT *ndv_compute_bound(NDV p);
1.4       noro      317: UINT *nd_compute_bound(ND p);
1.1       noro      318: ND nd_copy(ND p);
                    319: ND nd_merge(ND p1,ND p2);
                    320: ND nd_add(int mod,ND p1,ND p2);
1.11    ! noro      321: ND nd_add_q(ND p1,ND p2);
1.1       noro      322: ND nd_add_sf(ND p1,ND p2);
1.7       noro      323: ND nd_quo(int mod,PGeoBucket p,NDV d);
1.1       noro      324: INLINE int nd_length(ND p);
                    325: NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col,NODE rp0);
                    326: NODE nd_f4_red_dist(int m,ND_pairs sp0,UINT *s0vect,int col,NODE rp0);
1.8       noro      327: NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col,
                    328:        NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred);
1.11    ! noro      329: NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vect,int col,
1.8       noro      330:        NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred);
1.1       noro      331:
                    332: /* NDV functions */
                    333: ND weyl_ndv_mul_nm(int mod,NM m0,NDV p);
                    334: void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *tab,int tlen);
                    335: void ndv_mul_c(int mod,NDV p,int mul);
1.11    ! noro      336: void ndv_mul_c_q(NDV p,Q mul);
1.1       noro      337: ND ndv_mul_nm_symbolic(NM m0,NDV p);
                    338: ND ndv_mul_nm(int mod,NM m0,NDV p);
1.5       noro      339: ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d);
1.1       noro      340: void ndv_realloc(NDV p,int obpe,int oadv,EPOS oepos);
                    341: NDV ndv_dup_realloc(NDV p,int obpe,int oadv,EPOS oepos);
                    342: void ndv_homogenize(NDV p,int obpe,int oadv,EPOS eops);
                    343: void ndv_dehomogenize(NDV p,struct order_spec *spec);
                    344: void ndv_removecont(int mod,NDV p);
                    345: void ndv_print(NDV p);
1.11    ! noro      346: void ndv_print_q(NDV p);
1.1       noro      347: void ndv_free(NDV p);
                    348: void ndv_save(NDV p,int index);
                    349: NDV ndv_load(int index);
                    350:
                    351: /* converters */
                    352: ND ptond(VL vl,VL dvl,P p);
                    353: NDV ptondv(VL vl,VL dvl,P p);
                    354: P ndvtop(int mod,VL vl,VL dvl,NDV p);
                    355: NDV ndtondv(int mod,ND p);
                    356: ND ndvtond(int mod,NDV p);
                    357: int nm_ind_pair_to_vect(int m,UINT *s0,int n,NM_ind_pair pair,UINT *r);
                    358: IndArray nm_ind_pair_to_vect_compress(int m,UINT *s0,int n,NM_ind_pair pair);
                    359: int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r);
1.11    ! noro      360: int nd_to_vect_q(UINT *s0,int n,ND d,Q *r);
        !           361: NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead,UINT *s0vect);
1.1       noro      362:
                    363: /* elimination */
                    364: int nd_gauss_elim_mod(int **mat0,int *sugar,int row,int col,int md,int *colstat);
                    365: int nd_gauss_elim_sf(int **mat0,int *sugar,int row,int col,int md,int *colstat);
1.11    ! noro      366: int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int col,int *colstat);
1.1       noro      367:
                    368: int ndl_ww_lex_compare(UINT *a1,UINT *a2);
1.8       noro      369:
1.1       noro      370:

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