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