Annotation of OpenXM_contrib2/asir2000/builtin/gr.c, Revision 1.31
1.8 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.9 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.8 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.31 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/gr.c,v 1.30 2001/09/17 01:18:34 noro Exp $
1.8 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "base.h"
53: #include "ox.h"
54:
1.27 noro 55: #if defined(__GNUC__)
56: #define INLINE inline
57: #elif defined(VISUAL)
58: #define INLINE __inline
59: #else
60: #define INLINE
61: #endif
62:
1.1 noro 63: #define ITOS(p) (((unsigned int)(p))&0x7fffffff)
64: #define STOI(i) ((P)((unsigned int)(i)|0x80000000))
65:
66: #define NEXTVL(r,c) \
67: if(!(r)){NEWVL(r);(c)=(r);}else{NEWVL(NEXT(c));(c)=NEXT(c);}
68:
69: #define HMAG(p) (p_mag(BDY(p)->c))
70:
71: struct dp_pairs {
72: int dp1, dp2;
73: DL lcm;
74: int sugar;
75: struct dp_pairs *next;
76: };
77:
78: typedef struct dp_pairs *DP_pairs;
79:
80: #define NEWDPP(a) ((a)=(DP_pairs)MALLOC(sizeof(struct dp_pairs)))
81:
82: #define NEXTDPP(r,c) \
83: if(!(r)){NEWDPP(r);(c)=(r);}else{NEWDPP(NEXT(c));(c)=NEXT(c);}
84:
1.14 noro 85: struct oEGT eg_nf,eg_nfm;
86: struct oEGT eg_znfm,eg_pz,eg_np,eg_ra,eg_mc,eg_gc;
1.1 noro 87: int TP,NBP,NMP,NFP,NDP,ZR,NZR;
88:
89: #define NEWDP_pairs ((DP_pairs)MALLOC(sizeof(struct dp_pairs)))
90:
91: extern int (*cmpdl)();
1.5 noro 92: extern int do_weyl;
1.1 noro 93:
1.13 noro 94: extern DP_Print;
95:
1.30 noro 96: void _tf_to_vect_compress(NODE,DL *,CDP *);
97: NODE mul_dllist(DL,DP);
1.14 noro 98: void dp_imul_d(DP,Q,DP *);
1.1 noro 99: void print_stat(void);
100: void init_stat(void);
101: int dp_load_t(int,DP *);
102: void dp_load(int,DP *);
1.7 noro 103: void dp_save(int,Obj,char *);
1.1 noro 104: void dp_make_flaglist(LIST *);
105: void dp_set_flag(Obj,Obj);
106: int membercheck(NODE,NODE);
107: int gbcheck(NODE);
108: int dl_redble(DL,DL);
109: NODE remove_reducibles(NODE,int);
110: NODE updbase(NODE,int);
111: DP_pairs criterion_F(DP_pairs);
112: int criterion_2(int,int);
113: static DP_pairs collect_pairs_of_hdlcm(DP_pairs,DP_pairs *);
114: DP_pairs criterion_M(DP_pairs);
115: DP_pairs criterion_B(DP_pairs,int);
116: DP_pairs newpairs(NODE,int);
117: DP_pairs updpairs(DP_pairs,NODE,int);
1.16 noro 118: void _dp_nf(NODE,DP,DP *,int,DP *);
1.21 noro 119: void _dp_nf_z(NODE,DP,DP *,int,int,DP *);
1.1 noro 120: NODE gb_mod(NODE,int);
121: NODE gbd(NODE,int,NODE,NODE);
122: NODE gb(NODE,int,NODE);
123: NODE gb_f4(NODE);
124: NODE gb_f4_mod(NODE,int);
125: DP_pairs minp(DP_pairs, DP_pairs *);
126: void minsugar(DP_pairs,DP_pairs *,DP_pairs *);
127: NODE append_one(NODE,int);
128: void reducebase_dehomo(NODE,NODE *);
129: int newps_mod(DP,int);
130: int newps_nosave(DP,int,NODE);
131: int newps(DP,int,NODE);
132: void reduceall_mod(NODE,int,NODE *);
133: void reduceall(NODE,NODE *);
134: NODE NODE_sortbi(NODE,int);
135: NODE NODE_sortbi_insert(int, NODE,int);
136: NODE NODE_sortb(NODE,int);
137: NODE NODE_sortb_insert(DP,NODE,int);
138: void prim_part(DP,int,DP *);
139: void setup_arrays(NODE,int,NODE *);
140: int validhc(P,int,NODE);
141: void vlminus(VL,VL,VL *);
142: void printsubst(NODE);
143: void makesubst(VL,NODE *);
144: void pltovl(LIST,VL *);
145: void printdl(DL);
146: int DPPlength(DP_pairs);
147: void dp_gr_mod_main(LIST,LIST,Num,int,struct order_spec *,LIST *);
1.21 noro 148: void dp_gr_main(LIST,LIST,Num,int,int,struct order_spec *,LIST *);
1.22 noro 149: void dp_f4_main(LIST,LIST,struct order_spec *,LIST *);
1.1 noro 150: void dp_f4_mod_main(LIST,LIST,int,struct order_spec *,LIST *);
151: double get_rtime();
152: void _dpmod_to_vect(DP,DL *,int *);
153: void dp_to_vect(DP,DL *,Q *);
1.12 noro 154: NODE dp_dllist(DP f);
155: NODE symb_merge(NODE,NODE,int),_symb_merge(NODE,NODE,int);
1.1 noro 156: extern int dp_nelim;
157: extern int dp_fcoeffs;
158: static DP *ps,*psm;
159: static DL *psh;
160: static P *psc;
161:
162: static int *pss;
163: static int psn,pslen;
1.16 noro 164: static int NVars,CNVars;
1.1 noro 165: static VL VC;
1.14 noro 166:
1.16 noro 167: int PCoeffs;
1.14 noro 168: int DP_Print = 0;
169: int DP_Multiple = 0;
1.16 noro 170: int DP_NFStat = 0;
1.14 noro 171: LIST Dist = 0;
172: int NoGCD = 0;
173: int GenTrace = 0;
174: int OXCheck = -1;
175:
1.1 noro 176: static int NoSugar = 0;
177: static int NoCriB = 0;
178: static int NoGC = 0;
179: static int NoMC = 0;
180: static int NoRA = 0;
1.12 noro 181: static int DP_PrintShort = 0;
1.1 noro 182: static int ShowMag = 0;
183: static int Stat = 0;
184: static int Denominator = 1;
185: static int Top = 0;
186: static int Reverse = 0;
187: static int Max_mag = 0;
188: static char *Demand = 0;
189: static int PtozpRA = 0;
1.14 noro 190:
1.1 noro 191: int doing_f4;
1.7 noro 192: NODE TraceList;
1.23 noro 193: NODE AllTraceList;
1.1 noro 194:
1.27 noro 195: INLINE int eqdl(nv,dl1,dl2)
1.1 noro 196: int nv;
197: DL dl1,dl2;
198: {
199: int i;
200: int *b1,*b2;
201:
202: if ( dl1->td != dl2->td )
203: return 0;
204: for ( i = 0, b1 = dl1->d, b2 = dl2->d; i < nv; i++ )
205: if ( b1[i] != b2[i] )
206: break;
207: if ( i == nv )
208: return 1;
209: else
210: return 0;
211: }
212:
1.5 noro 213: /* b[] should be cleared */
214:
1.1 noro 215: void _dpmod_to_vect(f,at,b)
216: DP f;
217: DL *at;
218: int *b;
219: {
220: int i,nv;
221: MP m;
222:
223: nv = f->nv;
224: for ( m = BDY(f), i = 0; m; m = NEXT(m), i++ ) {
225: for ( ; !eqdl(nv,m->dl,at[i]); i++ );
226: b[i] = ITOS(m->c);
227: }
228: }
229:
1.24 noro 230: /* create compressed poly */
231:
232: void _dpmod_to_vect_compress(f,at,b)
233: DP f;
234: DL *at;
235: CDP *b;
236: {
237: int i,j,nv,len;
238: MP m;
239: CDP r;
240:
241: nv = f->nv;
242: for ( m = BDY(f), len = 0; m; m = NEXT(m), len++ );
243: r = (CDP)MALLOC(sizeof(struct oCDP));
244: r->len = len;
1.30 noro 245: r->body = (CM)MALLOC_ATOMIC(sizeof(struct oCM)*len);
1.24 noro 246:
247: for ( m = BDY(f), i = j = 0; m; m = NEXT(m), j++ ) {
248: for ( ; !eqdl(nv,m->dl,at[i]); i++ );
249: r->body[j].index = i;
250: r->body[j].c = ITOS(m->c);
251: }
252: *b = r;
253: }
254:
1.30 noro 255: /* [t,findex] -> tf -> compressed vector */
256:
257: void _tf_to_vect_compress(tf,at,b)
258: NODE tf;
259: DL *at;
260: CDP *b;
261: {
262: int i,j,k,nv,len;
263: DL t,s,d1;
264: DP f;
265: MP m;
266: CDP r;
267:
268: t = (DL)BDY(tf);
269: f = ps[(int)BDY(NEXT(tf))];
270:
271: nv = f->nv;
272: for ( m = BDY(f), len = 0; m; m = NEXT(m), len++ );
273: r = (CDP)MALLOC(sizeof(struct oCDP));
274: r->len = len;
275: r->body = (CM)MALLOC_ATOMIC(sizeof(struct oCM)*len);
276:
277: NEWDL(s,nv);
278: for ( m = BDY(f), i = j = 0; m; m = NEXT(m), j++ ) {
279: d1 = m->dl;
280: s->td = t->td+d1->td;
281: for ( k = 0; k < nv; k++ )
282: s->d[k] = t->d[k]+d1->d[k];
283: for ( ; !eqdl(nv,s,at[i]); i++ );
284: r->body[j].index = i;
285: r->body[j].c = ITOS(m->c);
286: }
287: *b = r;
288: }
289:
1.25 noro 290: /* dense vector -> CDP */
291: void compress_vect(a,n,rp)
292: int *a;
293: int n;
294: CDP *rp;
295: {
296: int i,j,nz;
297: CDP r;
298:
299: for ( i = 0, nz = 0; i < n; i++ )
300: if ( a[i] ) nz++;
301: *rp = r = (CDP)MALLOC(sizeof(struct oCDP));
302: r->len = nz;
1.26 noro 303: r->body = (CM)MALLOC(sizeof(struct oCM)*nz);
1.25 noro 304: for ( i = 0, j = 0; i < n; i++ ) {
305: if ( a[i] ) {
306: r->body[j].index = i;
307: r->body[j].c = ITOS(a[i]);
308: j++;
309: }
310: }
311: }
312:
1.1 noro 313: void dp_to_vect(f,at,b)
314: DP f;
315: DL *at;
316: Q *b;
317: {
318: int i,nv;
319: MP m;
320:
321: nv = f->nv;
322: for ( m = BDY(f), i = 0; m; m = NEXT(m), i++ ) {
323: for ( ; !eqdl(nv,m->dl,at[i]); i++ );
324: b[i] =(Q)m->c;
325: }
326: }
327:
1.2 noro 328: NODE dp_dllist(f)
1.1 noro 329: DP f;
330: {
1.2 noro 331: MP m;
332: NODE mp,mp0;
1.1 noro 333:
1.2 noro 334: if ( !f )
335: return 0;
1.1 noro 336: mp0 = 0;
337: for ( m = BDY(f); m; m = NEXT(m) ) {
1.2 noro 338: NEXTNODE(mp0,mp); BDY(mp) = (pointer)m->dl;
1.1 noro 339: }
340: NEXT(mp) = 0;
1.2 noro 341: return mp0;
342: }
343:
1.30 noro 344: NODE mul_dllist(d,f)
345: DL d;
346: DP f;
347: {
348: MP m;
349: NODE mp,mp0;
350: DL t,d1;
351: int i,nv;
352:
353: if ( !f )
354: return 0;
355: nv = NV(f);
356: mp0 = 0;
357: for ( m = BDY(f); m; m = NEXT(m) ) {
358: NEXTNODE(mp0,mp);
359: NEWDL(t,nv);
360: d1 = m->dl;
361: t->td = d->td+d1->td;
362: for ( i = 0; i < nv; i++ )
363: t->d[i] = d->d[i]+d1->d[i];
364: BDY(mp) = (pointer)t;
365: }
366: NEXT(mp) = 0;
367: return mp0;
368: }
369:
1.2 noro 370: void pdl(f)
371: NODE f;
372: {
373: while ( f ) {
374: printdl(BDY(f)); f = NEXT(f);
375: }
376: fflush(stdout);
377: printf("\n");
1.1 noro 378: }
379:
1.21 noro 380: void dp_gr_main(f,v,homo,modular,field,ord,rp)
1.1 noro 381: LIST f,v;
382: Num homo;
1.21 noro 383: int modular,field;
1.1 noro 384: struct order_spec *ord;
385: LIST *rp;
386: {
387: int i,mindex,m,nochk;
388: struct order_spec ord1;
1.23 noro 389: Q q;
1.1 noro 390: VL fv,vv,vc;
391: NODE fd,fd0,fi,fi0,r,r0,t,subst,x,s,xx;
1.23 noro 392: NODE ind,ind0;
393: LIST trace,gbindex;
1.1 noro 394:
1.21 noro 395: mindex = 0; nochk = 0; dp_fcoeffs = field;
1.1 noro 396: get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&vc);
397: NVars = length((NODE)vv); PCoeffs = vc ? 1 : 0; VC = vc;
398: CNVars = homo ? NVars+1 : NVars;
399: if ( ord->id && NVars != ord->nv )
400: error("dp_gr_main : invalid order specification");
401: initd(ord);
402: if ( homo ) {
403: homogenize_order(ord,NVars,&ord1);
404: for ( fd0 = fi0 = 0, t = BDY(f); t; t = NEXT(t) ) {
405: NEXTNODE(fd0,fd); NEXTNODE(fi0,fi);
406: ptod(CO,vv,(P)BDY(t),(DP *)&BDY(fi)); dp_homo((DP)BDY(fi),(DP *)&BDY(fd));
407: }
408: if ( fd0 ) NEXT(fd) = 0;
409: if ( fi0 ) NEXT(fi) = 0;
410: initd(&ord1);
411: } else {
412: for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) {
413: NEXTNODE(fd0,fd); ptod(CO,vv,(P)BDY(t),(DP *)&BDY(fd));
414: }
415: if ( fd0 ) NEXT(fd) = 0;
416: fi0 = fd0;
417: }
418: if ( modular < 0 ) {
419: modular = -modular; nochk = 1;
420: }
421: if ( modular )
1.19 noro 422: m = modular > 1 ? modular : get_lprime(mindex);
1.1 noro 423: else
424: m = 0;
425: makesubst(vc,&subst);
426: setup_arrays(fd0,0,&s);
427: init_stat();
428: while ( 1 ) {
429: if ( homo ) {
430: initd(&ord1); CNVars = NVars+1;
431: }
1.12 noro 432: if ( DP_Print && modular ) {
1.1 noro 433: fprintf(asir_out,"mod= %d, eval = ",m); printsubst(subst);
434: }
435: x = gb(s,m,subst);
436: if ( x ) {
437: if ( homo ) {
438: reducebase_dehomo(x,&xx); x = xx;
439: initd(ord); CNVars = NVars;
440: }
441: reduceall(x,&xx); x = xx;
442: if ( modular ) {
443: if ( nochk || (membercheck(fi0,x) && gbcheck(x)) )
444: break;
445: } else
446: break;
447: }
448: if ( modular )
449: if ( modular > 1 ) {
450: *rp = 0; return;
451: } else
1.19 noro 452: m = get_lprime(++mindex);
1.1 noro 453: makesubst(vc,&subst);
454: psn = length(s);
455: for ( i = psn; i < pslen; i++ ) {
456: pss[i] = 0; psh[i] = 0; psc[i] = 0; ps[i] = 0;
457: }
458: }
1.23 noro 459: for ( r0 = 0, ind0 = 0; x; x = NEXT(x) ) {
1.1 noro 460: NEXTNODE(r0,r); dp_load((int)BDY(x),&ps[(int)BDY(x)]);
461: dtop(CO,vv,ps[(int)BDY(x)],(P *)&BDY(r));
1.23 noro 462: NEXTNODE(ind0,ind);
463: STOQ((int)BDY(x),q); BDY(ind) = q;
1.1 noro 464: }
465: if ( r0 ) NEXT(r) = 0;
1.23 noro 466: if ( ind0 ) NEXT(ind) = 0;
1.1 noro 467: MKLIST(*rp,r0);
1.23 noro 468: MKLIST(gbindex,ind0);
469:
470: if ( GenTrace && OXCheck < 0 ) {
471:
472: x = AllTraceList;
473: for ( r = 0; x; x = NEXT(x) ) {
474: MKNODE(r0,BDY(x),r); r = r0;
475: }
476: MKLIST(trace,r);
477: r0 = mknode(3,*rp,gbindex,trace);
478: MKLIST(*rp,r0);
479: }
1.1 noro 480: print_stat();
481: if ( ShowMag )
482: fprintf(asir_out,"\nMax_mag=%d\n",Max_mag);
483: }
484:
485: void dp_gr_mod_main(f,v,homo,m,ord,rp)
486: LIST f,v;
487: Num homo;
488: int m;
489: struct order_spec *ord;
490: LIST *rp;
491: {
492: struct order_spec ord1;
493: VL fv,vv,vc;
494: NODE fd,fd0,r,r0,t,x,s,xx;
495: DP a,b,c;
1.17 noro 496: extern struct oEGT eg_red_mod;
1.1 noro 497:
498: get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&vc);
499: NVars = length((NODE)vv); PCoeffs = vc ? 1 : 0; VC = vc;
500: CNVars = homo ? NVars+1 : NVars;
501: if ( ord->id && NVars != ord->nv )
502: error("dp_gr_mod_main : invalid order specification");
503: initd(ord);
504: if ( homo ) {
505: for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) {
506: ptod(CO,vv,(P)BDY(t),&a); dp_homo(a,&b);
507: if ( PCoeffs )
508: dp_mod(b,m,0,&c);
509: else
510: _dp_mod(b,m,(NODE)0,&c);
511: if ( c ) {
512: NEXTNODE(fd0,fd); BDY(fd) = (pointer)c;
513: }
514: }
515: homogenize_order(ord,NVars,&ord1); initd(&ord1);
516: } else {
517: for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) {
518: ptod(CO,vv,(P)BDY(t),&b);
519: if ( PCoeffs )
520: dp_mod(b,m,0,&c);
521: else
522: _dp_mod(b,m,0,&c);
523: if ( c ) {
524: NEXTNODE(fd0,fd); BDY(fd) = (pointer)c;
525: }
526: }
527: }
528: if ( fd0 ) NEXT(fd) = 0;
529: setup_arrays(fd0,m,&s);
530: init_stat();
531: if ( homo ) {
532: initd(&ord1); CNVars = NVars+1;
533: }
1.17 noro 534: /* init_eg(&eg_red_mod); */
1.1 noro 535: x = gb_mod(s,m);
1.17 noro 536: /* print_eg("Red_mod",&eg_red_mod); */
1.1 noro 537: if ( homo ) {
538: reducebase_dehomo(x,&xx); x = xx;
539: initd(ord); CNVars = NVars;
540: }
541: reduceall_mod(x,m,&xx); x = xx;
542: if ( PCoeffs )
543: for ( r0 = 0; x; x = NEXT(x) ) {
544: NEXTNODE(r0,r); mdtop(CO,m,vv,ps[(int)BDY(x)],(P *)&BDY(r));
545: }
546: else
547: for ( r0 = 0; x; x = NEXT(x) ) {
548: NEXTNODE(r0,r); _dtop_mod(CO,vv,ps[(int)BDY(x)],(P *)&BDY(r));
549: }
550: print_stat();
551: if ( r0 ) NEXT(r) = 0;
552: MKLIST(*rp,r0);
553: }
554:
1.22 noro 555: void dp_f4_main(f,v,ord,rp)
1.1 noro 556: LIST f,v;
557: struct order_spec *ord;
558: LIST *rp;
559: {
1.27 noro 560: int i,mindex,m,nochk,homogen;
1.1 noro 561: struct order_spec ord1;
562: VL fv,vv,vc;
563: NODE fd,fd0,fi,fi0,r,r0,t,subst,x,s,xx;
564:
1.22 noro 565: dp_fcoeffs = 0;
1.1 noro 566: get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&vc);
567: NVars = length((NODE)vv); PCoeffs = vc ? 1 : 0; VC = vc;
568: CNVars = NVars;
569: if ( ord->id && NVars != ord->nv )
570: error("dp_f4_main : invalid order specification");
571: initd(ord);
1.27 noro 572: for ( fd0 = 0, t = BDY(f), homogen = 1; t; t = NEXT(t) ) {
1.1 noro 573: NEXTNODE(fd0,fd); ptod(CO,vv,(P)BDY(t),(DP *)&BDY(fd));
1.27 noro 574: if ( homogen )
575: homogen = dp_homogeneous(BDY(fd));
1.1 noro 576: }
577: if ( fd0 ) NEXT(fd) = 0;
578: setup_arrays(fd0,0,&s);
579: x = gb_f4(s);
1.27 noro 580: if ( !homogen ) {
581: reduceall(x,&xx); x = xx;
582: }
1.1 noro 583: for ( r0 = 0; x; x = NEXT(x) ) {
584: NEXTNODE(r0,r); dp_load((int)BDY(x),&ps[(int)BDY(x)]);
585: dtop(CO,vv,ps[(int)BDY(x)],(P *)&BDY(r));
586: }
587: if ( r0 ) NEXT(r) = 0;
588: MKLIST(*rp,r0);
589: }
590:
591: void dp_f4_mod_main(f,v,m,ord,rp)
592: LIST f,v;
593: int m;
594: struct order_spec *ord;
595: LIST *rp;
596: {
1.27 noro 597: int i,homogen;
1.1 noro 598: struct order_spec ord1;
599: VL fv,vv,vc;
1.5 noro 600: DP b,c,c1;
1.1 noro 601: NODE fd,fd0,fi,fi0,r,r0,t,subst,x,s,xx;
602:
603: dp_fcoeffs = 0;
604: get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&vc);
605: NVars = length((NODE)vv); PCoeffs = vc ? 1 : 0; VC = vc;
606: CNVars = NVars;
607: if ( ord->id && NVars != ord->nv )
608: error("dp_f4_mod_main : invalid order specification");
609: initd(ord);
1.27 noro 610: for ( fd0 = 0, t = BDY(f), homogen = 1; t; t = NEXT(t) ) {
1.1 noro 611: ptod(CO,vv,(P)BDY(t),&b);
1.27 noro 612: if ( homogen )
613: homogen = dp_homogeneous(b);
1.1 noro 614: _dp_mod(b,m,0,&c);
1.5 noro 615: _dp_monic(c,m,&c1);
1.1 noro 616: if ( c ) {
1.5 noro 617: NEXTNODE(fd0,fd); BDY(fd) = (pointer)c1;
1.1 noro 618: }
619: }
620: if ( fd0 ) NEXT(fd) = 0;
621: setup_arrays(fd0,m,&s);
622: x = gb_f4_mod(s,m);
1.27 noro 623: if ( !homogen ) {
624: reduceall_mod(x,m,&xx); x = xx;
625: }
1.1 noro 626: for ( r0 = 0; x; x = NEXT(x) ) {
627: NEXTNODE(r0,r); _dtop_mod(CO,vv,ps[(int)BDY(x)],(P *)&BDY(r));
628: }
629: if ( r0 ) NEXT(r) = 0;
630: MKLIST(*rp,r0);
631: }
632:
633: NODE gb_f4(f)
634: NODE f;
635: {
636: int i,j,k,nh,row,col,nv;
637: NODE r,g,gall;
1.2 noro 638: NODE s,s0;
1.1 noro 639: DP_pairs d,dm,dr,t;
1.2 noro 640: DP h,nf,nf1,f1,f2,f21,f21r,sp,sp1,sd,sdm,tdp;
1.1 noro 641: MP mp,mp0;
642: NODE blist,bt,nt;
643: DL *ht,*at;
644: MAT mat,nm;
645: int *colstat;
646: int *rind,*cind;
647: int rank,nred;
648: Q dn;
649: struct oEGT tmp0,tmp1,tmp2,eg_split_symb,eg_split_elim;
650: extern struct oEGT eg_mod,eg_elim,eg_chrem,eg_gschk,eg_intrat,eg_symb;
651:
652: init_eg(&eg_mod); init_eg(&eg_elim); init_eg(&eg_chrem);
653: init_eg(&eg_gschk); init_eg(&eg_intrat); init_eg(&eg_symb);
654:
655: doing_f4 = 1;
656: for ( gall = g = 0, d = 0, r = f; r; r = NEXT(r) ) {
657: i = (int)BDY(r);
658: d = updpairs(d,g,i);
659: g = updbase(g,i);
660: gall = append_one(gall,i);
661: }
662: if ( gall )
663: nv = ((DP)ps[(int)BDY(gall)])->nv;
664: while ( d ) {
665: get_eg(&tmp0);
666: minsugar(d,&dm,&dr); d = dr;
1.12 noro 667: if ( DP_Print )
1.1 noro 668: fprintf(asir_out,"sugar=%d\n",dm->sugar);
669: blist = 0; s0 = 0;
670: /* asph : sum of all head terms of spoly */
671: for ( t = dm; t; t = NEXT(t) ) {
672: dp_sp(ps[t->dp1],ps[t->dp2],&sp);
673: if ( sp ) {
674: MKNODE(bt,sp,blist); blist = bt;
1.2 noro 675: s0 = symb_merge(s0,dp_dllist(sp),nv);
1.1 noro 676: }
677: }
678: /* s0 : all the terms appeared in symbolic redunction */
1.2 noro 679: for ( s = s0, nred = 0; s; s = NEXT(s) ) {
1.1 noro 680: for ( r = gall; r; r = NEXT(r) )
1.2 noro 681: if ( _dl_redble(BDY(ps[(int)BDY(r)])->dl,BDY(s),nv) )
1.1 noro 682: break;
683: if ( r ) {
1.2 noro 684: dltod(BDY(s),nv,&tdp);
685: dp_subd(tdp,ps[(int)BDY(r)],&sd);
1.5 noro 686: muld(CO,sd,ps[(int)BDY(r)],&f2);
1.1 noro 687: MKNODE(bt,f2,blist); blist = bt;
1.2 noro 688: s = symb_merge(s,dp_dllist(f2),nv);
1.1 noro 689: nred++;
690: }
691: }
692:
693: /* the first nred polys in blist are reducers */
694: /* row = the number of all the polys */
695: for ( r = blist, row = 0; r; r = NEXT(r), row++ );
696: ht = (DL *)MALLOC(nred*sizeof(DL));
697: for ( r = blist, i = 0; i < nred; r = NEXT(r), i++ )
698: ht[i] = BDY((DP)BDY(r))->dl;
1.2 noro 699: for ( s = s0, col = 0; s; s = NEXT(s), col++ );
1.1 noro 700: at = (DL *)MALLOC(col*sizeof(DL));
1.2 noro 701: for ( s = s0, i = 0; i < col; s = NEXT(s), i++ )
702: at[i] = (DL)BDY(s);
1.1 noro 703: MKMAT(mat,row,col);
704: for ( i = 0, r = blist; i < row; r = NEXT(r), i++ )
705: dp_to_vect(BDY(r),at,(Q *)mat->body[i]);
706: get_eg(&tmp1); add_eg(&eg_symb,&tmp0,&tmp1);
707: init_eg(&eg_split_symb); add_eg(&eg_split_symb,&tmp0,&tmp1);
1.12 noro 708: if ( DP_Print ) {
1.1 noro 709: print_eg("Symb",&eg_split_symb);
710: fprintf(asir_out,"mat : %d x %d",row,col);
711: fflush(asir_out);
712: }
1.3 noro 713: #if 0
714: rank = generic_gauss_elim_hensel(mat,&nm,&dn,&rind,&cind);
715: #else
1.1 noro 716: rank = generic_gauss_elim(mat,&nm,&dn,&rind,&cind);
1.3 noro 717: #endif
1.12 noro 718: if ( DP_Print )
1.1 noro 719: fprintf(asir_out,"done rank = %d\n",rank,row,col);
720: for ( i = 0; i < rank; i++ ) {
721: for ( k = 0; k < nred; k++ )
722: if ( !cmpdl(nv,at[rind[i]],ht[k]) )
723: break;
724: if ( k == nred ) {
725: /* this is a new base */
726: mp0 = 0;
727: NEXTMP(mp0,mp); mp->dl = at[rind[i]]; mp->c = (P)dn;
728: for ( k = 0; k < col-rank; k++ )
729: if ( nm->body[i][k] ) {
730: NEXTMP(mp0,mp); mp->dl = at[cind[k]];
731: mp->c = (P)nm->body[i][k];
732: }
733: NEXT(mp) = 0;
734: MKDP(nv,mp0,nf); nf->sugar = dm->sugar;
735: dp_ptozp(nf,&nf1);
736: nh = newps(nf1,0,0);
737: d = updpairs(d,g,nh);
738: g = updbase(g,nh);
739: gall = append_one(gall,nh);
740: }
741: }
742: }
1.12 noro 743: if ( DP_Print ) {
1.1 noro 744: print_eg("Symb",&eg_symb);
745: print_eg("Mod",&eg_mod); print_eg("GaussElim",&eg_elim);
746: print_eg("ChRem",&eg_chrem); print_eg("IntToRat",&eg_intrat);
747: print_eg("Check",&eg_gschk);
748: }
749: return g;
750: }
751:
1.5 noro 752: /* initial bases are monic */
753:
1.1 noro 754: NODE gb_f4_mod(f,m)
755: NODE f;
756: int m;
757: {
758: int i,j,k,nh,row,col,nv;
759: NODE r,g,gall;
1.29 noro 760: NODE s,s0;
1.1 noro 761: DP_pairs d,dm,dr,t;
1.2 noro 762: DP h,nf,f1,f2,f21,f21r,sp,sp1,sd,sdm,tdp;
1.1 noro 763: MP mp,mp0;
1.30 noro 764: NODE blist,bt,nt,bt1,dt,rhtlist;
1.5 noro 765: DL *ht,*at,*st;
1.24 noro 766: int **spmat;
767: CDP *redmat;
1.25 noro 768: int *colstat,*w,*w1;
1.5 noro 769: int rank,nred,nsp,nonzero,spcol;
1.24 noro 770: int *indred,*isred;
771: CDP ri;
1.5 noro 772: struct oEGT tmp0,tmp1,tmp2,eg_split_symb,eg_split_elim1,eg_split_elim2;
773: extern struct oEGT eg_symb,eg_elim1,eg_elim2;
1.1 noro 774:
1.5 noro 775: init_eg(&eg_symb); init_eg(&eg_elim1); init_eg(&eg_elim2);
1.1 noro 776: for ( gall = g = 0, d = 0, r = f; r; r = NEXT(r) ) {
777: i = (int)BDY(r);
778: d = updpairs(d,g,i);
779: g = updbase(g,i);
780: gall = append_one(gall,i);
781: }
782: if ( gall )
783: nv = ((DP)ps[(int)BDY(gall)])->nv;
784: while ( d ) {
785: get_eg(&tmp0);
786: minsugar(d,&dm,&dr); d = dr;
1.12 noro 787: if ( DP_Print )
1.1 noro 788: fprintf(asir_out,"sugar=%d\n",dm->sugar);
789: blist = 0; s0 = 0;
790: /* asph : sum of all head terms of spoly */
791: for ( t = dm; t; t = NEXT(t) ) {
1.13 noro 792: _dp_sp_mod(ps[t->dp1],ps[t->dp2],m,&sp);
1.1 noro 793: if ( sp ) {
794: MKNODE(bt,sp,blist); blist = bt;
1.29 noro 795: s0 = symb_merge(s0,dp_dllist(sp),nv);
1.1 noro 796: }
797: }
1.24 noro 798: /* s0 : all the terms appeared in symbolic reduction */
1.2 noro 799: for ( s = s0, nred = 0; s; s = NEXT(s) ) {
1.29 noro 800: for ( r = gall; r; r = NEXT(r) )
801: if ( _dl_redble(BDY(ps[(int)BDY(r)])->dl,BDY(s),nv) )
802: break;
803: if ( r ) {
804: dltod(BDY(s),nv,&tdp);
805: dp_subd(tdp,ps[(int)BDY(r)],&sd);
1.30 noro 806: dt = mul_dllist(BDY(sd)->dl,ps[(int)BDY(r)]);
807: /* list of [t,f] */
808: bt1 = mknode(2,BDY(sd)->dl,BDY(r));
809: MKNODE(bt,bt1,blist); blist = bt;
810: symb_merge(s,dt,nv);
1.29 noro 811: nred++;
1.1 noro 812: }
813: }
814:
815: /* the first nred polys in blist are reducers */
816: /* row = the number of all the polys */
817: for ( r = blist, row = 0; r; r = NEXT(r), row++ );
1.5 noro 818:
819: /* col = number of all terms */
1.29 noro 820: for ( s = s0, col = 0; s; s = NEXT(s), col++ );
1.5 noro 821:
822: /* head terms of all terms */
1.1 noro 823: at = (DL *)MALLOC(col*sizeof(DL));
1.29 noro 824: for ( s = s0, i = 0; i < col; s = NEXT(s), i++ )
825: at[i] = (DL)BDY(s);
1.5 noro 826:
827: /* store coefficients separately in spmat and redmat */
828: nsp = row-nred;
829:
830: /* reducer matrix */
1.25 noro 831: /* indred : register the position of the head term */
1.24 noro 832: redmat = (CDP *)MALLOC(nred*sizeof(CDP));
1.5 noro 833: for ( i = 0, r = blist; i < nred; r = NEXT(r), i++ )
1.30 noro 834: _tf_to_vect_compress(BDY(r),at,&redmat[i]);
1.5 noro 835: /* XXX */
836: /* reduce_reducers_mod(redmat,nred,col,m); */
837: /* register the position of the head term */
1.31 ! noro 838: indred = (int *)MALLOC_ATOMIC(nred*sizeof(int));
1.5 noro 839: bzero(indred,nred*sizeof(int));
1.31 ! noro 840: isred = (int *)MALLOC_ATOMIC(col*sizeof(int));
1.5 noro 841: bzero(isred,col*sizeof(int));
842: for ( i = 0; i < nred; i++ ) {
843: ri = redmat[i];
1.24 noro 844: indred[i] = ri->body[0].index;
845: isred[indred[i]] = 1;
1.5 noro 846: }
847:
848: spcol = col-nred;
849: /* head terms not in ht */
850: st = (DL *)MALLOC(spcol*sizeof(DL));
851: for ( j = 0, k = 0; j < col; j++ )
852: if ( !isred[j] )
853: st[k++] = at[j];
1.30 noro 854: get_eg(&tmp1); add_eg(&eg_symb,&tmp0,&tmp1);
855: init_eg(&eg_split_symb); add_eg(&eg_split_symb,&tmp0,&tmp1);
1.5 noro 856:
1.24 noro 857: get_eg(&tmp1);
1.5 noro 858: /* spoly matrix; stored in reduced form; terms in ht[] are omitted */
1.25 noro 859: spmat = (int **)MALLOC(nsp*sizeof(int *));
1.31 ! noro 860: w = (int *)MALLOC_ATOMIC(col*sizeof(int));
1.25 noro 861:
862: /* skip reducers in blist */
863: for ( i = 0, r = blist; i < nred; r = NEXT(r), i++ );
864: for ( i = 0; r; r = NEXT(r) ) {
1.5 noro 865: bzero(w,col*sizeof(int));
866: _dpmod_to_vect(BDY(r),at,w);
1.24 noro 867: reduce_sp_by_red_mod_compress(w,redmat,indred,nred,col,m);
1.25 noro 868: for ( j = 0; j < col; j++ )
869: if ( w[j] )
870: break;
871: if ( j < col ) {
872: w1 = (int *)MALLOC_ATOMIC(spcol*sizeof(int));
873: for ( j = 0, k = 0; j < col; j++ )
874: if ( !isred[j] )
875: w1[k++] = w[j];
876: spmat[i] = w1;
877: i++;
878: }
1.5 noro 879: }
1.25 noro 880: /* update nsp */
881: nsp = i;
1.5 noro 882:
1.30 noro 883: /* XXX free redmat explicitly */
884: for ( k = 0; k < nred; k++ ) {
885: GC_free(BDY(redmat[k]));
886: GC_free(redmat[k]);
887: }
888:
1.5 noro 889: get_eg(&tmp0); add_eg(&eg_elim1,&tmp1,&tmp0);
890: init_eg(&eg_split_elim1); add_eg(&eg_split_elim1,&tmp1,&tmp0);
891:
892: colstat = (int *)MALLOC_ATOMIC(spcol*sizeof(int));
1.25 noro 893: bzero(colstat,spcol*sizeof(int));
1.5 noro 894: for ( i = 0, nonzero=0; i < nsp; i++ )
895: for ( j = 0; j < spcol; j++ )
896: if ( spmat[i][j] )
1.1 noro 897: nonzero++;
1.17 noro 898: if ( DP_Print && nsp )
1.5 noro 899: fprintf(asir_out,"spmat : %d x %d (nonzero=%f%%)...",
900: nsp,spcol,((double)nonzero*100)/(nsp*spcol));
1.17 noro 901: if ( nsp )
902: rank = generic_gauss_elim_mod(spmat,nsp,spcol,m,colstat);
903: else
904: rank = 0;
1.5 noro 905: get_eg(&tmp1); add_eg(&eg_elim2,&tmp0,&tmp1);
906: init_eg(&eg_split_elim2); add_eg(&eg_split_elim2,&tmp0,&tmp1);
907:
1.12 noro 908: if ( DP_Print ) {
1.1 noro 909: fprintf(asir_out,"done rank = %d\n",rank,row,col);
910: print_eg("Symb",&eg_split_symb);
1.5 noro 911: print_eg("Elim1",&eg_split_elim1);
912: print_eg("Elim2",&eg_split_elim2);
1.1 noro 913: fprintf(asir_out,"\n");
914: }
1.25 noro 915:
916: if ( !rank )
917: continue;
918:
1.5 noro 919: for ( j = 0, i = 0; j < spcol; j++ )
1.1 noro 920: if ( colstat[j] ) {
1.5 noro 921: mp0 = 0;
1.13 noro 922: NEXTMP(mp0,mp); mp->dl = st[j]; mp->c = STOI(1);
1.5 noro 923: for ( k = j+1; k < spcol; k++ )
924: if ( !colstat[k] && spmat[i][k] ) {
1.13 noro 925: NEXTMP(mp0,mp); mp->dl = st[k];
1.5 noro 926: mp->c = STOI(spmat[i][k]);
1.1 noro 927: }
1.5 noro 928: NEXT(mp) = 0;
929: MKDP(nv,mp0,nf); nf->sugar = dm->sugar;
930: nh = newps_mod(nf,m);
931: d = updpairs(d,g,nh);
932: g = updbase(g,nh);
933: gall = append_one(gall,nh);
1.1 noro 934: i++;
935: }
1.30 noro 936:
937: /* XXX free spmat[] explicitly */
938: for ( j = 0; j < nsp; j++ ) {
939: GC_free(spmat[j]);
940: }
1.1 noro 941: }
1.12 noro 942: if ( DP_Print ) {
1.1 noro 943: print_eg("Symb",&eg_symb);
1.5 noro 944: print_eg("Elim1",&eg_elim1);
945: print_eg("Elim2",&eg_elim2);
1.1 noro 946: fflush(asir_out);
947: }
948: return g;
949: }
950:
951: int DPPlength(n)
952: DP_pairs n;
953: {
954: int i;
955:
956: for ( i = 0; n; n = NEXT(n), i++ );
957: return i;
958: }
959:
960: void printdl(dl)
961: DL dl;
962: {
963: int i;
964:
965: fprintf(asir_out,"<<");
966: for ( i = 0; i < CNVars-1; i++ )
967: fprintf(asir_out,"%d,",dl->d[i]);
968: fprintf(asir_out,"%d>>",dl->d[i]);
969: }
970:
971: void pltovl(l,vl)
972: LIST l;
973: VL *vl;
974: {
975: NODE n;
976: VL r,r0;
977:
978: n = BDY(l);
979: for ( r0 = 0; n; n = NEXT(n) ) {
980: NEXTVL(r0,r); r->v = VR((P)BDY(n));
981: }
982: if ( r0 ) NEXT(r) = 0;
983: *vl = r0;
984: }
985:
986: void makesubst(v,s)
987: VL v;
988: NODE *s;
989: {
990: NODE r,r0;
991: Q q;
992: unsigned int n;
993:
994: for ( r0 = 0; v; v = NEXT(v) ) {
995: NEXTNODE(r0,r); BDY(r) = (pointer)v->v;
996: #if defined(_PA_RISC1_1)
997: n = mrand48()&BMASK; UTOQ(n,q);
998: #else
999: n = random(); UTOQ(n,q);
1000: #endif
1001: NEXTNODE(r0,r); BDY(r) = (pointer)q;
1002: }
1003: if ( r0 ) NEXT(r) = 0;
1004: *s = r0;
1005: }
1006:
1007: void printsubst(s)
1008: NODE s;
1009: {
1010: fputc('[',asir_out);
1011: while ( s ) {
1012: printv(CO,(V)BDY(s)); s = NEXT(s);
1013: fprintf(asir_out,"->%d",QTOS((Q)BDY(s)));
1014: if ( NEXT(s) ) {
1015: fputc(',',asir_out); s = NEXT(s);
1016: } else
1017: break;
1018: }
1019: fprintf(asir_out,"]\n"); return;
1020: }
1021:
1022: void vlminus(v,w,d)
1023: VL v,w,*d;
1024: {
1025: int i,j,n,m;
1026: V *va,*wa;
1027: V a;
1028: VL r,r0;
1029: VL t;
1030:
1031: for ( n = 0, t = v; t; t = NEXT(t), n++ );
1032: va = (V *)ALLOCA(n*sizeof(V));
1033: for ( i = 0, t = v; t; t = NEXT(t), i++ )
1034: va[i] = t->v;
1035: for ( m = 0, t = w; t; t = NEXT(t), m++ );
1036: wa = (V *)ALLOCA(m*sizeof(V));
1037: for ( i = 0, t = w; t; t = NEXT(t), i++ )
1038: wa[i] = t->v;
1039: for ( i = 0; i < n; i++ ) {
1040: a = va[i];
1041: for ( j = 0; j < m; j++ )
1042: if ( a == wa[j] )
1043: break;
1044: if ( j < m )
1045: va[i] = 0;
1046: }
1047: for ( r0 = 0, i = 0; i < n; i++ )
1048: if ( va[i] ) { NEXTVL(r0,r); r->v = va[i]; }
1049: if ( r0 ) NEXT(r) = 0;
1050: *d = r0;
1051: }
1052:
1053: int validhc(a,m,s)
1054: P a;
1055: int m;
1056: NODE s;
1057: {
1058: P c,c1;
1059: V v;
1060:
1061: if ( !a )
1062: return 0;
1063: for ( c = a; s; s = NEXT(s) ) {
1064: v = (V)BDY(s); s = NEXT(s);
1065: substp(CO,c,v,(P)BDY(s),&c1); c = c1;
1066: }
1067: ptomp(m,c,&c1);
1068: return c1 ? 1 : 0;
1069: }
1070:
1071: void setup_arrays(f,m,r)
1072: NODE f,*r;
1073: int m;
1074: {
1075: int i;
1.7 noro 1076: NODE s,s0,f0;
1.1 noro 1077:
1.17 noro 1078: #if 1
1.7 noro 1079: f0 = f = NODE_sortb(f,1);
1.17 noro 1080: #else
1081: f0 = f;
1082: #endif
1.1 noro 1083: psn = length(f); pslen = 2*psn;
1084: ps = (DP *)MALLOC(pslen*sizeof(DP));
1085: psh = (DL *)MALLOC(pslen*sizeof(DL));
1086: pss = (int *)MALLOC(pslen*sizeof(int));
1087: psc = (P *)MALLOC(pslen*sizeof(P));
1088: for ( i = 0; i < psn; i++, f = NEXT(f) ) {
1089: prim_part((DP)BDY(f),m,&ps[i]);
1090: if ( Demand )
1.7 noro 1091: dp_save(i,(Obj)ps[i],0);
1.1 noro 1092: psh[i] = BDY(ps[i])->dl;
1093: pss[i] = ps[i]->sugar;
1094: psc[i] = BDY(ps[i])->c;
1095: }
1.23 noro 1096: if ( GenTrace ) {
1.7 noro 1097: Q q;
1098: STRING fname;
1099: LIST input;
1.23 noro 1100: NODE arg,t,t1;
1.7 noro 1101: Obj dmy;
1.23 noro 1102:
1103: t = 0;
1104: for ( i = psn-1; i >= 0; i-- ) {
1105: MKNODE(t1,ps[i],t);
1106: t = t1;
1107: }
1108: MKLIST(input,t);
1.7 noro 1109:
1.23 noro 1110: if ( OXCheck >= 0 ) {
1111: STOQ(OXCheck,q);
1112: MKSTR(fname,"register_input");
1113: arg = mknode(3,q,fname,input);
1114: Pox_cmo_rpc(arg,&dmy);
1115: } else if ( OXCheck < 0 ) {
1116: MKNODE(AllTraceList,input,0);
1117: }
1.7 noro 1118: }
1.1 noro 1119: for ( s0 = 0, i = 0; i < psn; i++ ) {
1120: NEXTNODE(s0,s); BDY(s) = (pointer)i;
1121: }
1122: if ( s0 ) NEXT(s) = 0;
1123: *r = s0;
1124: }
1125:
1126: void prim_part(f,m,r)
1127: DP f,*r;
1128: int m;
1129: {
1.7 noro 1130: P d,t;
1131:
1.1 noro 1132: if ( m > 0 ) {
1133: if ( PCoeffs )
1134: dp_prim_mod(f,m,r);
1135: else
1136: *r = f;
1137: } else {
1138: if ( dp_fcoeffs )
1139: *r = f;
1140: else if ( PCoeffs )
1141: dp_prim(f,r);
1142: else
1143: dp_ptozp(f,r);
1.7 noro 1144: if ( GenTrace && TraceList ) {
1.23 noro 1145: /* adust the denominator according to the final
1146: content reduction */
1.7 noro 1147: divsp(CO,BDY(f)->c,BDY(*r)->c,&d);
1148: mulp(CO,(P)ARG3(BDY((LIST)BDY(TraceList))),d,&t);
1149: ARG3(BDY((LIST)BDY(TraceList))) = t;
1150: }
1.1 noro 1151: }
1152: }
1153:
1154: NODE /* of DP */ NODE_sortb_insert( newdp, nd, dec )
1155: DP newdp;
1156: NODE /* of DP */ nd;
1157: int dec;
1158: {
1159: register NODE last, p;
1160: register DL newdl = BDY(newdp)->dl;
1161: register int (*cmpfun)() = cmpdl, nv = CNVars;
1162: NODE newnd;
1163: int sgn = dec ? 1 : -1;
1164: MKNODE( newnd, newdp, 0 );
1165: if ( !(last = nd) || sgn*(*cmpfun)( nv, newdl, BDY((DP) BDY(last))->dl ) > 0 ) {
1166: NEXT(newnd) = last;
1167: return newnd;
1168: }
1169: for ( ; p = NEXT(last); last = p )
1170: if ( sgn*(*cmpfun)( nv, newdl, BDY((DP) BDY(p))->dl ) > 0 ) break;
1171: if ( p ) NEXT(NEXT(last) = newnd) = p;
1172: else NEXT(last) = newnd;
1173: return nd;
1174: }
1175:
1176: NODE NODE_sortb( node, dec )
1177: NODE node;
1178: int dec;
1179: {
1180: register NODE nd, ans;
1181:
1182: for ( ans = 0, nd = node; nd; nd = NEXT(nd) )
1183: ans = NODE_sortb_insert( (DP) BDY(nd), ans, dec );
1184: return ans;
1185: }
1186:
1187: NODE /* of index */ NODE_sortbi_insert( newdpi, nd, dec )
1188: int newdpi;
1189: NODE /* of index */ nd;
1190: int dec;
1191: {
1192: register NODE last, p;
1193: register DL newdl = psh[newdpi];
1194: register int (*cmpfun)() = cmpdl, nv = CNVars;
1195: NODE newnd;
1196: int sgn = dec ? 1 : -1;
1197: MKNODE( newnd, newdpi, 0 );
1198: if ( !(last = nd) || sgn*(*cmpfun)( nv, newdl, psh[(int)BDY(last)] ) > 0 ) {
1199: NEXT(newnd) = last;
1200: return newnd;
1201: }
1202: for ( ; p = NEXT(last); last = p )
1203: if ( sgn*(*cmpfun)( nv, newdl, psh[(int)BDY(p)] ) > 0 ) break;
1204: if ( p ) NEXT(NEXT(last) = newnd) = p;
1205: else NEXT(last) = newnd;
1206: return nd;
1207: }
1208:
1209: NODE NODE_sortbi( node, dec )
1210: NODE node;
1211: int dec;
1212: {
1213: register NODE nd, ans;
1214:
1215: for ( ans = 0, nd = node; nd; nd = NEXT(nd) )
1216: ans = NODE_sortbi_insert( (int) BDY(nd), ans, dec );
1217: return ans;
1218: }
1219:
1220: void reduceall(in,h)
1221: NODE in;
1222: NODE *h;
1223: {
1224: NODE r,t,top;
1225: int n,i,j;
1226: int *w;
1227: DP g,g1;
1228: struct oEGT tmp0,tmp1;
1229:
1230: if ( NoRA ) {
1231: *h = in; return;
1232: }
1.12 noro 1233: if ( DP_Print || DP_PrintShort ) {
1.1 noro 1234: fprintf(asir_out,"reduceall\n"); fflush(asir_out);
1235: }
1236: r = NODE_sortbi(in,0);
1237: n = length(r);
1238: w = (int *)ALLOCA(n*sizeof(int));
1239: for ( i = 0, t = r; i < n; i++, t = NEXT(t) )
1240: w[i] = (int)BDY(t);
1241: for ( i = 0; i < n; i++ ) {
1242: for ( top = 0, j = n-1; j >= 0; j-- )
1243: if ( j != i ) {
1244: MKNODE(t,(pointer)w[j],top); top = t;
1245: }
1246: get_eg(&tmp0);
1247: dp_load(w[i],&ps[w[i]]);
1248:
1.7 noro 1249: if ( GenTrace ) {
1250: Q q;
1251: NODE node;
1252: LIST hist;
1253:
1254: STOQ(w[i],q);
1255: node = mknode(4,ONE,q,ONE,ONE);
1256: MKLIST(hist,node);
1257: MKNODE(TraceList,hist,0);
1258: }
1.16 noro 1259: _dp_nf(top,ps[w[i]],ps,1,&g);
1.1 noro 1260: prim_part(g,0,&g1);
1261: get_eg(&tmp1); add_eg(&eg_ra,&tmp0,&tmp1);
1.12 noro 1262: if ( DP_Print || DP_PrintShort ) {
1.1 noro 1263: fprintf(asir_out,"."); fflush(asir_out);
1264: }
1265: w[i] = newps(g1,0,(NODE)0);
1266: }
1267: for ( top = 0, j = n-1; j >= 0; j-- ) {
1268: MKNODE(t,(pointer)w[j],top); top = t;
1269: }
1270: *h = top;
1.12 noro 1271: if ( DP_Print || DP_PrintShort )
1.1 noro 1272: fprintf(asir_out,"\n");
1273: }
1274:
1275: void reduceall_mod(in,m,h)
1276: NODE in;
1277: int m;
1278: NODE *h;
1279: {
1280: NODE r,t,top;
1281: int n,i,j;
1282: int *w;
1.12 noro 1283: DP g,p;
1.1 noro 1284: struct oEGT tmp0,tmp1;
1285:
1286: if ( NoRA ) {
1287: *h = in; return;
1288: }
1.12 noro 1289: if ( DP_Print || DP_PrintShort ) {
1.1 noro 1290: fprintf(asir_out,"reduceall\n"); fflush(asir_out);
1291: }
1292: r = NODE_sortbi(in,0);
1293: n = length(r);
1294: w = (int *)ALLOCA(n*sizeof(int));
1295: for ( i = 0, t = r; i < n; i++, t = NEXT(t) )
1296: w[i] = (int)BDY(t);
1297: for ( i = 0; i < n; i++ ) {
1298: for ( top = 0, j = n-1; j >= 0; j-- )
1299: if ( j != i ) {
1300: MKNODE(t,(pointer)w[j],top); top = t;
1301: }
1302: get_eg(&tmp0);
1303: if ( PCoeffs )
1304: dp_nf_mod(top,ps[w[i]],ps,m,1,&g);
1.12 noro 1305: else {
1306: dpto_dp(ps[w[i]],&p);
1307: _dp_nf_mod_destructive(top,p,ps,m,1,&g);
1308: }
1.1 noro 1309: get_eg(&tmp1); add_eg(&eg_ra,&tmp0,&tmp1);
1.12 noro 1310: if ( DP_Print || DP_PrintShort ) {
1.1 noro 1311: fprintf(asir_out,"."); fflush(asir_out);
1312: }
1313: w[i] = newps_mod(g,m);
1314: }
1315: for ( top = 0, j = n-1; j >= 0; j-- ) {
1316: MKNODE(t,(pointer)w[j],top); top = t;
1317: }
1318: *h = top;
1.12 noro 1319: if ( DP_Print || DP_PrintShort )
1.1 noro 1320: fprintf(asir_out,"\n");
1321: }
1322:
1323: int newps(a,m,subst)
1324: DP a;
1325: int m;
1326: NODE subst;
1327: {
1328: if ( m && !validhc(!a?0:BDY(a)->c,m,subst) )
1329: return -1;
1330: if ( psn == pslen ) {
1331: pslen *= 2;
1332: ps = (DP *)REALLOC((char *)ps,pslen*sizeof(DP));
1333: psh = (DL *)REALLOC((char *)psh,pslen*sizeof(DL));
1334: pss = (int *)REALLOC((char *)pss,pslen*sizeof(int));
1335: psc = (P *)REALLOC((char *)psc,pslen*sizeof(P));
1336: if ( m )
1337: psm = (DP *)REALLOC((char *)psm,pslen*sizeof(DP));
1338: }
1339: if ( Demand ) {
1340: if ( doing_f4 )
1341: ps[psn] = a;
1342: else
1343: ps[psn] = 0;
1.7 noro 1344: dp_save(psn,(Obj)a,0);
1.1 noro 1345: } else
1346: ps[psn] = a;
1347: psh[psn] = BDY(a)->dl;
1348: pss[psn] = a->sugar;
1349: psc[psn] = BDY(a)->c;
1350: if ( m )
1351: _dp_mod(a,m,subst,&psm[psn]);
1.7 noro 1352: if ( GenTrace ) {
1353: NODE tn,tr,tr1;
1.23 noro 1354: LIST trace,trace1;
1355: NODE arg;
1356: Q q1,q2;
1357: STRING fname;
1358: Obj dmy;
1.7 noro 1359:
1360: /* reverse the TraceList */
1361: tn = TraceList;
1362: for ( tr = 0; tn; tn = NEXT(tn) ) {
1363: MKNODE(tr1,BDY(tn),tr); tr = tr1;
1364: }
1365: MKLIST(trace,tr);
1366: if ( OXCheck >= 0 ) {
1367: STOQ(OXCheck,q1);
1368: MKSTR(fname,"check_trace");
1369: STOQ(psn,q2);
1370: arg = mknode(5,q1,fname,a,q2,trace);
1371: Pox_cmo_rpc(arg,&dmy);
1.23 noro 1372: } else if ( OXCheck < 0 ) {
1373: STOQ(psn,q1);
1374: tn = mknode(2,q1,trace);
1375: MKLIST(trace1,tn);
1376: MKNODE(tr,trace1,AllTraceList);
1377: AllTraceList = tr;
1.7 noro 1378: } else
1379: dp_save(psn,(Obj)trace,"t");
1380: TraceList = 0;
1381: }
1.1 noro 1382: return psn++;
1383: }
1384:
1385: int newps_nosave(a,m,subst)
1386: DP a;
1387: int m;
1388: NODE subst;
1389: {
1390: if ( m && !validhc(!a?0:BDY(a)->c,m,subst) )
1391: return -1;
1392: if ( psn == pslen ) {
1393: pslen *= 2;
1394: ps = (DP *)REALLOC((char *)ps,pslen*sizeof(DP));
1395: psh = (DL *)REALLOC((char *)psh,pslen*sizeof(DL));
1396: pss = (int *)REALLOC((char *)pss,pslen*sizeof(int));
1397: psc = (P *)REALLOC((char *)psc,pslen*sizeof(P));
1398: if ( m )
1399: psm = (DP *)REALLOC((char *)psm,pslen*sizeof(DP));
1400: }
1401: ps[psn] = 0;
1402: psh[psn] = BDY(a)->dl;
1403: pss[psn] = a->sugar;
1404: psc[psn] = BDY(a)->c;
1405: if ( m )
1406: _dp_mod(a,m,subst,&psm[psn]);
1407: return psn++;
1408: }
1409:
1410: int newps_mod(a,m)
1411: DP a;
1412: int m;
1413: {
1414: if ( psn == pslen ) {
1415: pslen *= 2;
1416: ps = (DP *)REALLOC((char *)ps,pslen*sizeof(DP));
1417: psh = (DL *)REALLOC((char *)psh,pslen*sizeof(DL));
1418: pss = (int *)REALLOC((char *)pss,pslen*sizeof(int));
1419: psc = (P *)REALLOC((char *)psc,pslen*sizeof(P)); /* XXX */
1420: }
1421: ps[psn] = a;
1422: psh[psn] = BDY(ps[psn])->dl;
1423: pss[psn] = ps[psn]->sugar;
1424: return psn++;
1425: }
1426:
1427: void reducebase_dehomo(f,g)
1428: NODE f,*g;
1429: {
1430: int n,i,j,k;
1431: int *r;
1432: DL *w,d;
1433: DP u;
1434: NODE t,top;
1435:
1436: n = length(f);
1437: w = (DL *)ALLOCA(n*sizeof(DL));
1438: r = (int *)ALLOCA(n*sizeof(int));
1439: for ( i = 0, t = f; i < n; i++, t = NEXT(t) ) {
1440: r[i] = (int)BDY(t); w[i] = psh[r[i]];
1441: }
1442: for ( i = 0; i < n; i++ ) {
1443: for ( j = 0, d = w[i]; j < n; j++ ) {
1444: if ( j != i ) {
1445: for ( k = 0; k < NVars; k++ )
1446: if ( d->d[k] < w[j]->d[k] )
1447: break;
1448: if ( k == NVars )
1449: break;
1450: }
1451: }
1452: if ( j != n )
1453: r[i] = -1;
1454: }
1455: for ( top = 0, i = n-1; i >= 0; i-- )
1456: if ( r[i] >= 0 ) {
1.7 noro 1457: dp_load(r[i],&ps[r[i]]); dp_dehomo(ps[r[i]],&u);
1458: if ( GenTrace ) {
1459: Q q;
1460: LIST hist;
1461: NODE node;
1462:
1463: STOQ(r[i],q);
1464: node = mknode(4,0,q,0,0);
1465: MKLIST(hist,node);
1466: MKNODE(TraceList,hist,0);
1467: }
1468: j = newps(u,0,0);
1.1 noro 1469: MKNODE(t,j,top); top = t;
1470: }
1471: *g = top;
1472: }
1473:
1474: NODE append_one(f,n)
1475: NODE f;
1476: int n;
1477: {
1478: NODE t;
1479:
1480: if ( Reverse || !f ) {
1481: MKNODE(t,(pointer)n,f); return t;
1482: } else {
1483: for ( t = f; NEXT(t); t = NEXT(t) );
1484: MKNODE(NEXT(t),(pointer)n,0);
1485: return f;
1486: }
1487: }
1488:
1489: DP_pairs minp( d, prest )
1490: DP_pairs d, *prest;
1491: {
1492: register DP_pairs m, ml, p, l;
1493: register DL lcm;
1494: register int s, nv = CNVars;
1495: register int (*cmpfun)() = cmpdl;
1496:
1497: if ( !(p = NEXT(m = d)) ) {
1498: *prest = p;
1499: NEXT(m) = 0;
1500: return m;
1501: }
1502: for ( lcm = m->lcm, s = m->sugar, ml = 0, l = m; p; p = NEXT(l = p) )
1503: if ( NoSugar ? (*cmpfun)( nv, lcm, p->lcm ) >= 0 :
1504: (s > p->sugar || s == p->sugar && (*cmpfun)( nv, lcm, p->lcm ) >= 0) )
1505: ml = l, lcm = (m = p)->lcm, s = p->sugar;
1506: if ( !ml ) *prest = NEXT(m);
1507: else {
1508: NEXT(ml) = NEXT(m);
1509: *prest = d;
1510: }
1511: NEXT(m) = 0;
1512: return m;
1513: }
1514:
1515: void minsugar(d,dm,dr)
1516: DP_pairs d;
1517: DP_pairs *dm,*dr;
1518: {
1519: int msugar;
1520: DP_pairs t,dm0,dr0,dmt,drt;
1521:
1522: for ( msugar = d->sugar, t = NEXT(d); t; t = NEXT(t) )
1523: if ( t->sugar < msugar )
1524: msugar = t->sugar;
1525: dm0 = 0; dr0 = 0;
1526: for ( t = d; t; t = NEXT(t) ) {
1527: if ( t->sugar == msugar ) {
1528: NEXTDPP(dm0,dmt);
1529: dmt->dp1 = t->dp1; dmt->dp2 = t->dp2;
1530: dmt->lcm = t->lcm; dmt->sugar = t->sugar;
1531: } else {
1532: NEXTDPP(dr0,drt);
1533: drt->dp1 = t->dp1; drt->dp2 = t->dp2;
1534: drt->lcm = t->lcm; drt->sugar = t->sugar;
1535: }
1536: }
1537: if ( dm0 ) NEXT(dmt) = 0;
1538: if ( dr0 ) NEXT(drt) = 0;
1539: *dm = dm0; *dr = dr0;
1540: }
1541:
1542: NODE gb(f,m,subst)
1543: NODE f;
1544: int m;
1545: NODE subst;
1546: {
1547: int i,nh,prev,mag;
1548: NODE r,g,gall;
1549: DP_pairs d,d1;
1550: DP_pairs l;
1551: DP h,nf,nfm,dp1,dp2;
1552: MP mp;
1553: struct oEGT tnf0,tnf1,tnfm0,tnfm1,tpz0,tpz1,tsp0,tsp1,tspm0,tspm1,tnp0,tnp1,tmp0,tmp1;
1554: int skip_nf_flag;
1555: double t_0;
1.7 noro 1556: Q q;
1.6 noro 1557: int new_sugar;
1.1 noro 1558: static prev_sugar = -1;
1559:
1560: Max_mag = 0;
1561: prev = 1;
1562: doing_f4 = 0;
1563: if ( m ) {
1564: psm = (DP *)MALLOC(pslen*sizeof(DP));
1565: for ( i = 0; i < psn; i++ )
1566: if ( psh[i] && !validhc(psc[i],m,subst) )
1567: return 0;
1568: else
1569: _dp_mod(ps[i],m,subst,&psm[i]);
1570: }
1571: for ( gall = g = 0, d = 0, r = f; r; r = NEXT(r) ) {
1572: i = (int)BDY(r);
1573: d = updpairs(d,g,i);
1574: g = updbase(g,i);
1575: gall = append_one(gall,i);
1576: }
1577: while ( d ) {
1.14 noro 1578: l = minp(d,&d);
1.1 noro 1579: if ( m ) {
1.6 noro 1580: _dp_sp_mod_dup(psm[l->dp1],psm[l->dp2],m,&h);
1.10 noro 1581: if ( h )
1582: new_sugar = h->sugar;
1.1 noro 1583: get_eg(&tnfm0);
1.6 noro 1584: _dp_nf_mod_destructive(gall,h,psm,m,0,&nfm);
1.1 noro 1585: get_eg(&tnfm1); add_eg(&eg_nfm,&tnfm0,&tnfm1);
1586: } else
1587: nfm = (DP)1;
1588: if ( nfm ) {
1589: if ( Demand ) {
1590: if ( dp_load_t(psn,&nf) ) {
1591: skip_nf_flag = 1;
1.14 noro 1592: tnf1=tsp1;
1.1 noro 1593: goto skip_nf;
1594: } else {
1595: skip_nf_flag = 0;
1596: dp_load(l->dp1,&dp1); dp_load(l->dp2,&dp2);
1597: dp_sp(dp1,dp2,&h);
1598: }
1599: } else
1600: dp_sp(ps[l->dp1],ps[l->dp2],&h);
1.7 noro 1601: if ( GenTrace ) {
1602: STOQ(l->dp1,q); ARG1(BDY((LIST)BDY(NEXT(TraceList)))) = q;
1603: STOQ(l->dp2,q); ARG1(BDY((LIST)BDY(TraceList))) = q;
1604: }
1.10 noro 1605: if ( h )
1606: new_sugar = h->sugar;
1.1 noro 1607: get_eg(&tnf0);
1608: t_0 = get_rtime();
1.18 noro 1609: if ( PCoeffs || dp_fcoeffs )
1.16 noro 1610: _dp_nf(gall,h,ps,!Top,&nf);
1611: else
1.21 noro 1612: _dp_nf_z(gall,h,ps,!Top,DP_Multiple,&nf);
1.12 noro 1613: if ( DP_Print )
1.1 noro 1614: fprintf(asir_out,"(%.3g)",get_rtime()-t_0);
1615: get_eg(&tnf1); add_eg(&eg_nf,&tnf0,&tnf1);
1616: } else
1617: nf = 0;
1618: skip_nf:
1619: if ( nf ) {
1620: NZR++;
1621: get_eg(&tpz0);
1622: prim_part(nf,0,&h);
1623: get_eg(&tpz1); add_eg(&eg_pz,&tpz0,&tpz1);
1624: get_eg(&tnp0);
1625: if ( Demand && skip_nf_flag )
1626: nh = newps_nosave(h,m,subst);
1627: else
1628: nh = newps(h,m,subst);
1629: get_eg(&tnp1); add_eg(&eg_np,&tnp0,&tnp1);
1630: if ( nh < 0 )
1631: return 0;
1632: d = updpairs(d,g,nh);
1633: g = updbase(g,nh);
1634: gall = append_one(gall,nh);
1635: if ( !dp_fcoeffs && ShowMag ) {
1636: for ( mag = 0, mp = BDY(h); mp; mp = NEXT(mp) )
1637: mag += p_mag((P)mp->c);
1638: Max_mag = MAX(Max_mag,mag);
1639: }
1.12 noro 1640: if ( DP_Print ) {
1.1 noro 1641: if ( !prev )
1642: fprintf(asir_out,"\n");
1643: print_split_e(&tnf0,&tnf1); print_split_e(&tpz0,&tpz1);
1644: printdl(psh[nh]);
1645: fprintf(asir_out,"(%d,%d),nb=%d,nab=%d,rp=%d,sugar=%d",
1646: l->dp1,l->dp2,length(g),length(gall),DPPlength(d),
1647: pss[nh]);
1648: if ( ShowMag )
1649: fprintf(asir_out,",mag=%d",mag);
1650: fprintf(asir_out,"\n"); fflush(asir_out);
1.12 noro 1651: } else if ( DP_PrintShort ) {
1.1 noro 1652: fprintf(asir_out,"+"); fflush(asir_out);
1653: }
1654: prev = 1;
1655: } else {
1656: if ( m )
1657: add_eg(&eg_znfm,&tnfm0,&tnfm1);
1658: ZR++;
1.12 noro 1659: if ( DP_Print || DP_PrintShort ) {
1.6 noro 1660: if ( new_sugar != prev_sugar ) {
1661: fprintf(asir_out,"[%d]",new_sugar);
1662: prev_sugar = new_sugar;
1.1 noro 1663: }
1664: fprintf(asir_out,"."); fflush(asir_out); prev = 0;
1665: }
1666: }
1667: }
1.12 noro 1668: if ( DP_Print || DP_PrintShort )
1.1 noro 1669: fprintf(asir_out,"gb done\n");
1670: return g;
1671: }
1672:
1673: NODE gb_mod(f,m)
1674: NODE f;
1675: int m;
1676: {
1677: int i,nh,prev;
1678: NODE r,g,gall;
1679: DP_pairs d,d1;
1680: DP_pairs l;
1681: DP h,nf;
1682: struct oEGT tnfm0,tnfm1,tspm0,tspm1,tmp0,tmp1,tpz0,tpz1;
1683:
1684: prev = 1;
1685: for ( gall = g = 0, d = 0, r = f; r; r = NEXT(r) ) {
1686: i = (int)BDY(r);
1687: d = updpairs(d,g,i);
1688: g = updbase(g,i);
1689: gall = append_one(gall,i);
1690: }
1691: while ( d ) {
1.14 noro 1692: l = minp(d,&d);
1.1 noro 1693: if ( PCoeffs ) {
1694: dp_sp_mod(ps[l->dp1],ps[l->dp2],m,&h);
1.14 noro 1695: get_eg(&tnfm0);
1.1 noro 1696: dp_nf_mod(gall,h,ps,m,!Top,&nf);
1697: } else {
1.6 noro 1698: _dp_sp_mod_dup(ps[l->dp1],ps[l->dp2],m,&h);
1.14 noro 1699: get_eg(&tnfm0);
1.6 noro 1700: _dp_nf_mod_destructive(gall,h,ps,m,!Top,&nf);
1.1 noro 1701: }
1702: get_eg(&tnfm1); add_eg(&eg_nfm,&tnfm0,&tnfm1);
1703: if ( nf ) {
1704: NZR++;
1705: get_eg(&tpz0);
1706: prim_part(nf,m,&h);
1707: get_eg(&tpz1); add_eg(&eg_pz,&tpz0,&tpz1);
1708: nh = newps_mod(h,m);
1709: if ( nh < 0 )
1710: return 0;
1711: d = updpairs(d,g,nh);
1712: g = updbase(g,nh);
1713: gall = append_one(gall,nh);
1.12 noro 1714: if ( DP_Print ) {
1.1 noro 1715: if ( !prev )
1716: fprintf(asir_out,"\n");
1717: print_split_eg(&tnfm0,&tnfm1); fflush(asir_out);
1718: fprintf(asir_out,"(%d,%d),nb=%d,nab=%d,rp=%d,sugar=%d",l->dp1,l->dp2,length(g),length(gall),DPPlength(d),pss[nh]);
1719: printdl(psh[nh]); fprintf(asir_out,"\n"); fflush(asir_out);
1.12 noro 1720: } else if ( DP_PrintShort ) {
1.6 noro 1721: fprintf(asir_out,"+"); fflush(asir_out);
1.1 noro 1722: }
1723: prev = 1;
1724: } else {
1725: add_eg(&eg_znfm,&tnfm0,&tnfm1);
1726: ZR++;
1.12 noro 1727: if ( DP_Print || DP_PrintShort ) {
1.1 noro 1728: fprintf(asir_out,"."); fflush(asir_out); prev = 0;
1729: }
1730: }
1731: }
1.12 noro 1732: if ( DP_Print || DP_PrintShort )
1.1 noro 1733: fprintf(asir_out,"gb_mod done\n");
1734: return g;
1735: }
1736:
1.14 noro 1737: DP_pairs updpairs( d, g, t)
1738: DP_pairs d;
1739: NODE /* of index */ g;
1740: int t;
1.1 noro 1741: {
1.14 noro 1742: register DP_pairs d1, dd, nd;
1743: struct oEGT tup0,tup1;
1744: int dl,dl1;
1.1 noro 1745:
1.14 noro 1746: if ( !g ) return d;
1747: if ( !NoCriB && d ) {
1748: dl = DPPlength(d);
1749: d = criterion_B( d, t );
1750: dl -= DPPlength(d); NBP += dl;
1.1 noro 1751: }
1.14 noro 1752: d1 = newpairs( g, t );
1753: if ( NEXT(d1) ) {
1754: dl = DPPlength(d1); TP += dl;
1755: d1 = criterion_M( d1 );
1756: dl1 = DPPlength(d1); NMP += (dl-dl1); dl = dl1;
1757: d1 = criterion_F( d1 );
1758: dl1 = DPPlength(d1); NFP += (dl-dl1); dl = dl1;
1759: } else
1760: dl = 1;
1761: if ( !do_weyl )
1762: for ( dd = 0; d1; d1 = nd ) {
1763: nd = NEXT(d1);
1764: if ( !criterion_2( d1->dp1, d1->dp2 ) ) {
1765: NEXT(d1) = dd;
1766: dd = d1;
1.1 noro 1767: }
1768: }
1.14 noro 1769: else
1770: dd = d1;
1771: dl1 = DPPlength(dd); NDP += (dl-dl1);
1772: if ( !(nd = d) ) return dd;
1773: while ( nd = NEXT(d1 = nd) ) ;
1774: NEXT(d1) = dd;
1775: return d;
1.1 noro 1776: }
1777:
1.14 noro 1778: DP_pairs newpairs( g, t )
1779: NODE /* of index */ g;
1780: register int t;
1781: {
1782: register NODE r;
1783: register DL tdl = psh[t];
1784: register int ts;
1785: register DP_pairs p, last;
1786: int dp;
1787: register DL dl;
1788: register int s;
1.1 noro 1789:
1.14 noro 1790: ts = pss[t] - tdl->td;
1791: for ( last = 0, r = g; r; r = NEXT(r) ) {
1792: NEXT(p = NEWDP_pairs) = last;
1793: last = p;
1794: dp = p->dp1 = (int)BDY(r); p->dp2 = t;
1795: p->lcm = lcm_of_DL(CNVars, dl = psh[dp], tdl, (DL)0 );
1796: #if 0
1797: if ( do_weyl )
1798: p->sugar = dl_weight(p->lcm);
1799: else
1800: #endif
1801: p->sugar = (ts > (s = pss[dp] - dl->td) ? ts : s) + p->lcm->td;
1802: }
1803: return last;
1804: }
1.1 noro 1805:
1.14 noro 1806: DP_pairs criterion_B( d, s )
1807: register DP_pairs d;
1808: int s;
1.1 noro 1809: {
1.14 noro 1810: register DP_pairs dd, p;
1811: register DL tij, t = psh[s], dltmp;
1.1 noro 1812:
1.14 noro 1813: if ( !d ) return 0;
1814: NEWDL( dltmp, CNVars );
1815: for ( dd = 0; d; d = p ) {
1816: p = NEXT(d),
1817: tij = d->lcm;
1818: if ( tij->td != lcm_of_DL(CNVars, tij, t, dltmp )->td
1819: || !dl_equal(CNVars, tij, dltmp )
1820: || (tij->td == lcm_of_DL(CNVars, psh[d->dp1], t, dltmp )->td
1821: && dl_equal(CNVars, dltmp, tij ))
1822: || (tij->td == lcm_of_DL(CNVars, psh[d->dp2], t, dltmp )->td
1823: && dl_equal(CNVars, dltmp, tij )) ) {
1824: NEXT(d) = dd;
1825: dd = d;
1826: }
1.1 noro 1827: }
1.14 noro 1828: return dd;
1829: }
1.1 noro 1830:
1.14 noro 1831: DP_pairs criterion_M( d1 )
1832: DP_pairs d1;
1833: {
1834: register DP_pairs dd, e, d3, d2, p;
1835: register DL itdl, jtdl;
1836: register int itdltd, jtdltd;
1.1 noro 1837:
1.14 noro 1838: for ( dd = 0, e = d1; e; e = d3 ) {
1839: if ( !(d2 = NEXT(e)) ) {
1840: NEXT(e) = dd;
1841: return e;
1842: }
1843: itdltd = (itdl = e->lcm)->td;
1844: for ( d3 = 0; d2; d2 = p ) {
1845: p = NEXT(d2),
1846: jtdltd = (jtdl = d2->lcm)->td;
1847: if ( jtdltd == itdltd )
1848: if ( dl_equal(CNVars, itdl, jtdl ) ) ;
1849: else if ( dl_redble( jtdl, itdl ) ) continue;
1850: else if ( dl_redble( itdl, jtdl ) ) goto delit;
1851: else ;
1852: else if ( jtdltd > itdltd )
1853: if ( dl_redble( jtdl, itdl ) ) continue;
1.1 noro 1854: else ;
1855: else if ( dl_redble( itdl, jtdl ) ) goto delit;
1856: NEXT(d2) = d3;
1857: d3 = d2;
1858: }
1859: NEXT(e) = dd;
1860: dd = e;
1861: continue;
1862: /**/
1863: delit: NEXT(d2) = d3;
1864: d3 = d2;
1865: for ( ; p; p = d2 ) {
1866: d2 = NEXT(p);
1867: NEXT(p) = d3;
1868: d3 = p;
1869: }
1870: }
1871: return dd;
1872: }
1873:
1874: static DP_pairs collect_pairs_of_hdlcm( d1, prest )
1875: DP_pairs d1, *prest;
1876: {
1877: register DP_pairs w, p, r, s;
1878: register DL ti;
1879: register int td;
1880:
1881: td = (ti = (w = d1)->lcm)->td;
1882: s = NEXT(w);
1883: NEXT(w) = 0;
1884: for ( r = 0; s; s = p ) {
1885: p = NEXT(s);
1886: if ( td == s->lcm->td && dl_equal(CNVars, ti, s->lcm ) )
1887: {
1888: NEXT(s) = w;
1889: w = s;
1890: } else {
1891: NEXT(s) = r;
1892: r = s;
1893: }
1894: }
1895: *prest = r;
1896: return w;
1897: }
1898:
1899: int criterion_2( dp1, dp2 )
1900: int dp1, dp2;
1901: {
1902: register int i, *d1, *d2;
1903:
1904: d1 = psh[dp1]->d, d2 = psh[dp2]->d;
1905: for ( i = CNVars; --i >= 0; d1++, d2++ )
1906: if ( (*d1 <= *d2 ? *d1 : *d2) > 0 ) return 0;
1907: return 1;
1908: }
1909:
1910: DP_pairs criterion_F( d1 )
1911: DP_pairs d1;
1912: {
1913: DP_pairs rest, head;
1914: register DP_pairs last, p, r, w;
1915: register int s;
1916:
1917: for ( head = last = 0, p = d1; NEXT(p); ) {
1918: s = (r = w = collect_pairs_of_hdlcm( p, &rest ))->sugar;
1919: while ( w = NEXT(w) )
1920: if ( criterion_2( w->dp1, w->dp2 ) ) {
1921: r = w;
1922: break;
1923: } else if ( w->sugar < s ) s = (r = w)->sugar;
1924: if ( last ) NEXT(last) = r;
1925: else head = r;
1926: NEXT(last = r) = 0;
1927: if ( !(p = rest) ) return head;
1928: }
1929: if ( !last ) return p;
1930: NEXT(last) = p;
1931: return head;
1932: }
1933:
1934: NODE updbase(g,t)
1935: NODE g;
1936: int t;
1937: {
1938: g = remove_reducibles(g,t);
1939: g = append_one(g,t);
1940: return g;
1941: }
1942:
1943: NODE /* of index */ remove_reducibles( nd, newdp )
1944: NODE /* of index */ nd;
1945: int newdp;
1946: {
1947: register DL dl, dln;
1948: register NODE last, p, head;
1949: register int td;
1950:
1951: dl = psh[newdp];
1952: td = dl->td;
1953: for ( head = last = 0, p = nd; p; ) {
1954: dln = psh[(int)BDY(p)];
1955: if ( dln->td >= td && dl_redble( dln, dl ) ) {
1956: p = NEXT(p);
1957: if ( last ) NEXT(last) = p;
1958: } else {
1959: if ( !last ) head = p;
1960: p = NEXT(last = p);
1961: }
1962: }
1963: return head;
1964: }
1965:
1966: int dl_redble( dl1, dl2 )
1967: DL dl1, dl2;
1968: {
1969: register int n, *d1, *d2;
1970:
1971: for ( d1 = dl1->d, d2 = dl2->d, n = CNVars; --n >= 0; d1++, d2++ )
1972: if ( *d1 < *d2 ) return 0;
1973: return 1;
1.5 noro 1974: }
1975:
1976: int dl_weight(dl)
1977: DL dl;
1978: {
1979: int n,w,i;
1980:
1981: n = CNVars/2;
1982: for ( i = 0, w = 0; i < n; i++ )
1983: w += (-dl->d[i]+dl->d[n+i]);
1984: return w;
1.1 noro 1985: }
1986:
1987: int gbcheck(f)
1988: NODE f;
1989: {
1990: int i;
1991: NODE r,g,gall;
1992: DP_pairs d,l;
1993: DP h,nf,dp1,dp2;
1994: struct oEGT tmp0,tmp1;
1995:
1996: if ( NoGC )
1997: return 1;
1998: for ( gall = g = 0, d = 0, r = f; r; r = NEXT(r) ) {
1999: i = (int)BDY(r);
2000: d = updpairs(d,g,i);
2001: g = updbase(g,i);
2002: gall = append_one(gall,i);
2003: }
1.12 noro 2004: if ( DP_Print || DP_PrintShort ) {
1.1 noro 2005: fprintf(asir_out,"gbcheck total %d pairs\n",DPPlength(d)); fflush(asir_out);
2006: }
2007: while ( d ) {
2008: l = d; d = NEXT(d);
2009: get_eg(&tmp0);
1.17 noro 2010: dp_load(l->dp1,&dp1); dp_load(l->dp2,&dp2);
2011: dp_sp(dp1,dp2,&h);
2012: /* fprintf(stderr,"{%d,%d}",l->dp1,l->dp2); */
1.16 noro 2013: _dp_nf(gall,h,ps,1,&nf);
1.1 noro 2014: get_eg(&tmp1); add_eg(&eg_gc,&tmp0,&tmp1);
1.12 noro 2015: if ( DP_Print || DP_PrintShort ) {
1.1 noro 2016: fprintf(asir_out,"."); fflush(asir_out);
2017: }
2018: if ( nf )
2019: return 0;
2020: }
1.12 noro 2021: if ( DP_Print || DP_PrintShort )
1.1 noro 2022: fprintf(asir_out,"\n");
2023: return 1;
2024: }
2025:
2026: int membercheck(f,x)
2027: NODE f,x;
2028: {
2029: DP g;
2030: struct oEGT tmp0,tmp1;
2031:
2032: if ( NoMC )
2033: return 1;
1.12 noro 2034: if ( DP_Print || DP_PrintShort ) {
1.1 noro 2035: fprintf(asir_out,"membercheck\n"); fflush(asir_out);
2036: }
2037: for ( ; f; f = NEXT(f) ) {
2038: get_eg(&tmp0);
1.16 noro 2039: _dp_nf(x,(DP)BDY(f),ps,1,&g);
1.1 noro 2040: get_eg(&tmp1); add_eg(&eg_mc,&tmp0,&tmp1);
1.12 noro 2041: if ( DP_Print ) {
1.1 noro 2042: print_split_eg(&tmp0,&tmp1); fflush(asir_out);
1.12 noro 2043: } else if ( DP_PrintShort ) {
1.1 noro 2044: fprintf(asir_out,"."); fflush(asir_out);
2045: }
2046: if ( g )
2047: return 0;
2048: }
1.12 noro 2049: if ( DP_Print || DP_PrintShort )
1.1 noro 2050: fprintf(asir_out,"\n");
2051: return 1;
2052: }
2053:
2054: void dp_set_flag(name,value)
2055: Obj name,value;
2056: {
2057: char *n;
2058: int v;
2059:
2060: if ( OID(name) != O_STR )
2061: return;
2062: n = BDY((STRING)name);
2063: if ( !strcmp(n,"Demand") ) {
2064: Demand = value ? BDY((STRING)value) : 0; return;
2065: }
2066: if ( !strcmp(n,"Dist") ) {
2067: Dist = (LIST)value; return;
2068: }
2069: if ( value && OID(value) != O_N )
2070: return;
2071: v = QTOS((Q)value);
2072: if ( !strcmp(n,"NoSugar") )
2073: NoSugar = v;
2074: else if ( !strcmp(n,"NoCriB") )
2075: NoCriB = v;
2076: else if ( !strcmp(n,"NoGC") )
2077: NoGC = v;
2078: else if ( !strcmp(n,"NoMC") )
2079: NoMC = v;
2080: else if ( !strcmp(n,"NoRA") )
2081: NoRA = v;
2082: else if ( !strcmp(n,"NoGCD") )
2083: NoGCD = v;
2084: else if ( !strcmp(n,"Top") )
2085: Top = v;
2086: else if ( !strcmp(n,"ShowMag") )
2087: ShowMag = v;
1.14 noro 2088: else if ( !strcmp(n,"PrintShort") )
1.12 noro 2089: DP_PrintShort = v;
1.14 noro 2090: else if ( !strcmp(n,"Print") )
1.12 noro 2091: DP_Print = v;
1.14 noro 2092: else if ( !strcmp(n,"NFStat") )
2093: DP_NFStat = v;
1.1 noro 2094: else if ( !strcmp(n,"Stat") )
2095: Stat = v;
2096: else if ( !strcmp(n,"Reverse") )
2097: Reverse = v;
2098: else if ( !strcmp(n,"Multiple") )
1.14 noro 2099: DP_Multiple = v;
1.1 noro 2100: else if ( !strcmp(n,"Denominator") )
2101: Denominator = v;
2102: else if ( !strcmp(n,"PtozpRA") )
2103: PtozpRA = v;
1.7 noro 2104: else if ( !strcmp(n,"GenTrace") )
2105: GenTrace = v;
2106: else if ( !strcmp(n,"OXCheck") )
2107: OXCheck = v;
1.1 noro 2108: }
2109:
2110: void dp_make_flaglist(list)
2111: LIST *list;
2112: {
2113: Q v;
2114: STRING name,path;
2115: NODE n,n1;
2116:
1.14 noro 2117: STOQ(DP_Multiple,v); MKNODE(n,v,0); MKSTR(name,"DP_Multiple"); MKNODE(n1,name,n); n = n1;
1.1 noro 2118: STOQ(Denominator,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Denominator"); MKNODE(n1,name,n); n = n1;
2119: MKNODE(n1,Dist,n); n = n1; MKSTR(name,"Dist"); MKNODE(n1,name,n); n = n1;
2120: STOQ(Reverse,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Reverse"); MKNODE(n1,name,n); n = n1;
2121: STOQ(Stat,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Stat"); MKNODE(n1,name,n); n = n1;
1.14 noro 2122: STOQ(DP_Print,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Print"); MKNODE(n1,name,n); n = n1;
1.20 noro 2123: STOQ(DP_PrintShort,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"PrintShort"); MKNODE(n1,name,n); n = n1;
1.14 noro 2124: STOQ(DP_NFStat,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NFStat"); MKNODE(n1,name,n); n = n1;
1.7 noro 2125: STOQ(OXCheck,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"OXCheck"); MKNODE(n1,name,n); n = n1;
2126: STOQ(GenTrace,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"GenTrace"); MKNODE(n1,name,n); n = n1;
1.1 noro 2127: STOQ(PtozpRA,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"PtozpRA"); MKNODE(n1,name,n); n = n1;
2128: STOQ(ShowMag,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"ShowMag"); MKNODE(n1,name,n); n = n1;
2129: STOQ(Top,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Top"); MKNODE(n1,name,n); n = n1;
2130: STOQ(NoGCD,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NoGCD"); MKNODE(n1,name,n); n = n1;
2131: STOQ(NoRA,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NoRA"); MKNODE(n1,name,n); n = n1;
2132: STOQ(NoMC,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NoMC"); MKNODE(n1,name,n); n = n1;
2133: STOQ(NoGC,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NoGC"); MKNODE(n1,name,n); n = n1;
2134: STOQ(NoCriB,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NoCriB"); MKNODE(n1,name,n); n = n1;
2135: STOQ(NoSugar,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NoSugar"); MKNODE(n1,name,n); n = n1;
2136: if ( Demand )
2137: MKSTR(path,Demand);
2138: else
2139: path = 0;
2140: MKNODE(n1,path,n); n = n1; MKSTR(name,"Demand"); MKNODE(n1,name,n); n = n1;
2141: MKLIST(*list,n);
2142: }
2143:
2144: #define DELIM '/'
2145:
1.7 noro 2146: void dp_save(index,p,prefix)
1.1 noro 2147: int index;
1.7 noro 2148: Obj p;
2149: char *prefix;
1.1 noro 2150: {
2151: FILE *fp;
2152: char path[BUFSIZ];
2153:
1.7 noro 2154: if ( prefix )
2155: sprintf(path,"%s%c%s%d",Demand,DELIM,prefix,index);
2156: else
2157: sprintf(path,"%s%c%d",Demand,DELIM,index);
1.1 noro 2158: if ( !(fp = fopen(path,"wb") ) )
2159: error("dp_save : cannot open a file");
1.7 noro 2160: savevl(fp,VC); saveobj(fp,p); fclose(fp);
1.1 noro 2161: }
2162:
2163: void dp_load(index,p)
2164: int index;
2165: DP *p;
2166: {
2167: FILE *fp;
2168: char path[BUFSIZ];
2169:
2170: if ( !Demand || ps[index] )
2171: *p = ps[index];
2172: else {
2173: sprintf(path,"%s%c%d",Demand,DELIM,index);
2174: if ( !(fp = fopen(path,"rb") ) )
2175: error("dp_load : cannot open a file");
2176: skipvl(fp); loadobj(fp,(Obj *)p); fclose(fp);
2177: }
2178: }
2179:
2180: int dp_load_t(index,p)
2181: int index;
2182: DP *p;
2183: {
2184: FILE *fp;
2185: char path[BUFSIZ];
2186:
2187: sprintf(path,"%s%c%d",Demand,DELIM,index);
2188: if ( !(fp = fopen(path,"rb") ) )
2189: return 0;
2190: else {
2191: skipvl(fp); loadobj(fp,(Obj *)p); fclose(fp); return 1;
2192: }
2193: }
2194:
2195: void init_stat() {
2196: init_eg(&eg_nf); init_eg(&eg_nfm); init_eg(&eg_znfm);
1.14 noro 2197: init_eg(&eg_pz); init_eg(&eg_np);
1.1 noro 2198: init_eg(&eg_ra); init_eg(&eg_mc); init_eg(&eg_gc);
1.14 noro 2199: ZR = NZR = TP = NBP = NFP = NDP = 0;
1.1 noro 2200: }
2201:
2202: void print_stat() {
1.12 noro 2203: if ( !DP_Print && !Stat )
1.1 noro 2204: return;
2205: print_eg("NF",&eg_nf); print_eg("NFM",&eg_nfm); print_eg("ZNFM",&eg_znfm);
1.14 noro 2206: print_eg("PZ",&eg_pz); print_eg("NP",&eg_np);
1.1 noro 2207: print_eg("RA",&eg_ra); print_eg("MC",&eg_mc); print_eg("GC",&eg_gc);
2208: fprintf(asir_out,"T=%d,B=%d M=%d F=%d D=%d ZR=%d NZR=%d\n",TP,NBP,NMP,NFP,NDP,ZR,NZR);
2209: }
1.14 noro 2210:
2211: /*
2212: * dp_nf used in gb()
2213: *
2214: */
2215:
2216: double pz_t_e, pz_t_d, pz_t_d1, pz_t_c, im_t_s, im_t_r;
2217:
2218: extern int GenTrace;
2219: extern NODE TraceList;
1.15 noro 2220: extern int mpi_mag;
2221:
2222: void dp_mulc_d(p,c,r)
2223: DP p;
2224: P c;
2225: DP *r;
2226: {
2227: if ( Dist && BDY(Dist)
2228: && HMAG(p) > mpi_mag
2229: && p_mag((P)c) > mpi_mag ) {
2230: if ( DP_NFStat ) fprintf(asir_out,"~");
2231: dp_imul_d(p,(Q)c,r);
2232: } else {
2233: if ( DP_NFStat ) fprintf(asir_out,"_");
2234: muldc(CO,p,c,r);
2235: }
2236: }
1.14 noro 2237:
1.16 noro 2238: void _dp_nf(b,g,ps,full,rp)
2239: NODE b;
2240: DP g;
2241: DP *ps;
2242: int full;
2243: DP *rp;
2244: {
2245: DP u,p,d,s,t,mult;
2246: P coef;
2247: NODE l;
2248: MP m,mr;
2249: int sugar,psugar;
2250:
2251: if ( !g ) {
2252: *rp = 0; return;
2253: }
2254: sugar = g->sugar;
2255: for ( d = 0; g; ) {
2256: for ( u = 0, l = b; l; l = NEXT(l) ) {
2257: if ( dl_redble(BDY(g)->dl,psh[(int)BDY(l)]) ) {
2258: dp_load((int)BDY(l),&p);
2259: /* t+u = coef*(d+g) - mult*p (t = coef*d) */
2260: dp_red(d,g,p,&t,&u,&coef,&mult);
2261: psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar;
2262: sugar = MAX(sugar,psugar);
2263: if ( GenTrace ) {
2264: LIST hist;
2265: Q cq;
2266: NODE node,node0;
2267:
2268: STOQ((int)BDY(l),cq);
2269: node0 = mknode(4,coef,cq,mult,ONE);
2270: MKLIST(hist,node0);
2271: MKNODE(node,hist,TraceList); TraceList = node;
2272: }
2273: if ( !u ) {
2274: if ( d )
2275: d->sugar = sugar;
2276: *rp = d; return;
2277: }
2278: d = t;
2279: break;
2280: }
2281: }
2282: if ( u )
2283: g = u;
2284: else if ( !full ) {
2285: if ( g ) {
2286: MKDP(g->nv,BDY(g),t); t->sugar = sugar; g = t;
2287: }
2288: *rp = g; return;
2289: } else {
2290: m = BDY(g); NEWMP(mr); mr->dl = m->dl; mr->c = m->c;
2291: NEXT(mr) = 0; MKDP(g->nv,mr,t); t->sugar = mr->dl->td;
2292: addd(CO,d,t,&s); d = s;
2293: dp_rest(g,&t); g = t;
2294: }
2295: }
2296: if ( d )
2297: d->sugar = sugar;
2298: *rp = d;
2299: }
2300:
1.21 noro 2301: void _dp_nf_z(b,g,ps,full,multiple,r)
1.14 noro 2302: NODE b;
2303: DP g;
2304: DP *ps;
2305: int full,multiple;
2306: DP *r;
2307: {
2308: DP u,dp,rp,t,t1,t2,red,shift;
2309: Q dc,rc,dcq,rcq,cont,hr,hred,cr,cred,mcred,c,gcd,cq;
2310: N gn,tn,cn;
2311: NODE l;
2312: MP m,mr;
2313: int hmag,denom;
2314: int sugar,psugar;
2315: NODE dist;
2316: STRING imul;
2317: int kara_bit;
2318: double get_rtime();
1.15 noro 2319: double t_0,t_00,tt,ttt,t_p,t_m,t_g,t_a;
1.14 noro 2320: LIST hist;
2321: NODE node;
2322: Q rcred,mrcred;
2323:
2324: if ( !g ) {
2325: *r = 0; return;
2326: }
2327: pz_t_e = pz_t_d = pz_t_d1 = pz_t_c = 0;
1.15 noro 2328: t_p = t_m = t_g = t_a = 0;
1.14 noro 2329:
2330: denom = Denominator?Denominator:1;
2331: hmag = multiple*HMAG(g)/denom;
2332: sugar = g->sugar;
2333:
2334: dc = 0; dp = 0; rc = ONE; rp = g;
2335: MKSTR(imul,"dp_imul_index");
2336:
2337: /* g = dc*dp+rc*rp */
2338: for ( ; rp; ) {
2339: for ( u = 0, l = b; l; l = NEXT(l) ) {
2340: if ( dl_redble(BDY(rp)->dl,psh[(int)BDY(l)]) ) {
2341: t_0 = get_rtime();
2342: dp_load((int)BDY(l),&red);
2343: hr = (Q)BDY(rp)->c; hred = (Q)BDY(red)->c;
2344: igcd_cofactor((Q)BDY(rp)->c,(Q)BDY(red)->c,&gcd,&cred,&cr);
1.15 noro 2345: tt = get_rtime(); t_p += tt-t_0;
1.14 noro 2346:
2347: dp_subd(rp,red,&shift);
1.15 noro 2348: dp_mulc_d(rp,cr,&t);
1.14 noro 2349: chsgnp((P)cred,(P *)&mcred);
1.15 noro 2350: dp_mulc_d(red,mcred,&t1);
2351: muld(CO,shift,t1,&t1);
2352: addd(CO,t,t1,&u);
2353: t_m += get_rtime()-tt;
1.14 noro 2354:
2355: psugar = (BDY(rp)->dl->td - BDY(red)->dl->td) + red->sugar;
2356: sugar = MAX(sugar,psugar);
1.15 noro 2357:
1.14 noro 2358: if ( GenTrace ) {
2359: /* u = cr*rp + (-cred)*shift*red */
2360: STOQ((int)BDY(l),cq);
2361: node = mknode(4,cr,cq,0,0);
2362: mulq(cred,rc,&rcred);
2363: chsgnnum((Num)rcred,(Num *)&mrcred);
2364: muldc(CO,shift,(P)mrcred,(DP *)&ARG2(node));
2365: MKLIST(hist,node);
2366: }
1.15 noro 2367:
1.14 noro 2368: if ( !u ) {
2369: if ( dp )
2370: dp->sugar = sugar;
2371: *r = dp;
2372: if ( GenTrace ) {
2373: ARG3(BDY(hist)) = ONE;
2374: MKNODE(node,hist,TraceList); TraceList = node;
2375: }
2376: goto final;
2377: }
2378: break;
2379: }
2380: }
2381: if ( u ) {
2382: if ( multiple && HMAG(u) > hmag ) {
2383: t_0 = get_rtime();
1.16 noro 2384: dp_ptozp_d(u,&rp);
1.15 noro 2385: tt = get_rtime(); t_g += tt-t_0;
2386:
2387: divsq((Q)BDY(u)->c,(Q)BDY(rp)->c,&cont);
1.14 noro 2388: if ( !dp_fcoeffs && DP_NFStat ) {
1.15 noro 2389: fprintf(asir_out,
2390: "(%d)",p_mag((P)cont)*100/p_mag((P)BDY(u)->c));
1.14 noro 2391: fflush(asir_out);
2392: }
1.15 noro 2393: mulq(cr,dc,&dcq); mulq(cont,rc,&rcq);
1.14 noro 2394: igcd_cofactor(dcq,rcq,&gcd,&dc,&rc);
1.15 noro 2395: t_a = get_rtime()-tt;
2396:
1.14 noro 2397: hmag = multiple*HMAG(rp)/denom;
2398: if ( GenTrace ) {
2399: ARG3(BDY(hist)) = (pointer)gcd;
2400: MKNODE(node,hist,TraceList); TraceList = node;
2401: }
2402: } else {
1.15 noro 2403: rp = u;
1.14 noro 2404: t_0 = get_rtime();
1.15 noro 2405: mulq(cr,dc,&dc);
2406: t_a += get_rtime()-t_0;
1.14 noro 2407: if ( GenTrace ) {
2408: ARG3(BDY(hist)) = (pointer)ONE;
2409: MKNODE(node,hist,TraceList); TraceList = node;
2410: }
2411: }
2412: } else if ( !full ) {
2413: if ( rp ) {
2414: MKDP(rp->nv,BDY(rp),t); t->sugar = sugar; rp = t;
2415: }
2416: *r = rp;
2417: goto final;
2418: } else {
2419: t_0 = get_rtime();
2420: mulq((Q)BDY(rp)->c,rc,&c);
1.15 noro 2421: igcd_cofactor(dc,c,&dc,&dcq,&cq);
2422: muldc(CO,dp,(P)dcq,&t);
2423: dp_hm(rp,&t1); BDY(t1)->c = (P)cq; addd(CO,t,t1,&dp);
2424: dp_rest(rp,&rp);
2425: t_a += get_rtime()-t_0;
1.14 noro 2426: }
2427: }
2428: if ( GenTrace ) {
2429: mulq(ARG3(BDY((LIST)BDY(TraceList))),dc,&cq);
2430: ARG3(BDY((LIST)BDY(TraceList))) = (pointer)cq;
2431: }
2432: if ( dp )
2433: dp->sugar = sugar;
2434: *r = dp;
2435: final:
2436: if ( DP_NFStat )
1.15 noro 2437: fprintf(asir_out,
2438: "(%.3g %.3g %.3g %.3g %.3g %.3g %.3g %.3g)",
2439: t_p,t_m,t_g,t_a,
1.14 noro 2440: pz_t_e, pz_t_d, pz_t_d1, pz_t_c);
2441: }
2442:
2443: void imulv();
2444:
2445: void dp_imul_d(p,q,rp)
2446: DP p;
2447: Q q;
2448: DP *rp;
2449: {
2450: int nsep,ndist,i,j,k,l,n;
2451: double t0,t1,t2;
2452: Q *s;
2453: pointer *b;
2454: VECT c,cs,ri;
2455: VECT *r;
2456: MP m;
2457: NODE tn,dist,n0,n1,n2;
2458: Obj dmy;
2459: STRING imul;
2460: extern LIST Dist;
2461:
2462: if ( !p || !q ) {
2463: *rp = 0; return;
2464: }
2465: dist = BDY(Dist);
2466: for ( tn = dist, ndist = 0; tn; tn = NEXT(tn), ndist++ );
2467: nsep = ndist + 1;
2468: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
2469: if ( n <= nsep ) {
2470: muldc(CO,p,(P)q,rp); return;
2471: }
2472: MKSTR(imul,"imulv");
2473: t0 = get_rtime();
2474: dp_dtov(p,&c);
2475: sepvect(c,nsep,&cs);
2476: r = (VECT *)CALLOC(nsep,sizeof(VECT *));
2477: for ( i = 0, tn = dist, b = BDY(cs); i < ndist; i++, tn = NEXT(tn) ) {
2478: n0 = mknode(4,BDY(tn),imul,b[i],q);
2479: Pox_rpc(n0,&dmy);
2480: }
2481: t1 = get_rtime();
2482: im_t_s += t1 - t0;
2483: imulv(b[i],q,&r[i]);
2484: t1 = get_rtime();
2485: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
2486: MKNODE(n0,BDY(tn),0);
2487: Pox_pop_local(n0,&r[i]);
2488: if ( OID(r[i]) == O_ERR ) {
2489: printexpr(CO,(Obj)r[i]);
2490: error("dp_imul_d : aborted");
2491: }
2492: }
2493: t2 = get_rtime();
2494: im_t_r += t2 - t1;
2495: s = (Q *)CALLOC(n,sizeof(Q));
2496: for ( i = j = 0; i < nsep; i++ ) {
2497: for ( k = 0, ri = r[i], l = ri->len; k < l; k++, j++ ) {
2498: s[j] = (Q)BDY(ri)[k];
2499: }
2500: }
2501: dp_vtod(s,p,rp);
2502: }
2503:
2504: void imulv(w,c,rp)
2505: VECT w;
2506: Q c;
2507: VECT *rp;
2508: {
2509: int n,i;
2510: VECT r;
2511:
2512: n = w->len;
2513: MKVECT(r,n); *rp = r;
2514: for ( i = 0; i < n; i++ )
2515: mulq((Q)BDY(w)[i],(Q)c,(Q *)&BDY(r)[i]);
2516: }
2517:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>