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