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