[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.32

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

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