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