Annotation of OpenXM_contrib2/asir2000/builtin/dp-supp.c, Revision 1.3
1.2 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.3 ! noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 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.3 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/dp-supp.c,v 1.2 2000/08/21 08:31:19 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "base.h"
52: #include "parse.h"
53: #include "ox.h"
54:
55: extern int (*cmpdl)();
56: double pz_t_e,pz_t_d,pz_t_d1,pz_t_c;
57:
58: void Pdp_mbase(),Pdp_lnf_mod(),Pdp_nf_tab_mod(),Pdp_mdtod();
59: void Pdp_vtoe(), Pdp_etov(), Pdp_dtov(), Pdp_idiv(), Pdp_sep();
60: void Pdp_cont(), Pdp_igcdv_hist(), Pdp_idivv_hist();
61:
62: struct ftab dp_supp_tab[] = {
63: {"dp_mbase",Pdp_mbase,1},
64: {"dp_lnf_mod",Pdp_lnf_mod,3},
65: {"dp_nf_tab_mod",Pdp_nf_tab_mod,3},
66: {"dp_etov",Pdp_etov,1},
67: {"dp_vtoe",Pdp_vtoe,1},
68: {"dp_dtov",Pdp_dtov,1},
69: {"dp_idiv",Pdp_idiv,2},
70: {"dp_cont",Pdp_cont,1},
71: {"dp_sep",Pdp_sep,2},
72: {"dp_mdtod",Pdp_mdtod,1},
73: {"dp_igcdv_hist",Pdp_igcdv_hist,1},
74: {"dp_idivv_hist",Pdp_idivv_hist,1},
75: {0,0,0}
76: };
77:
78: void Pdp_mdtod(arg,rp)
79: NODE arg;
80: DP *rp;
81: {
82: MP m,mr,mr0;
83: DP p;
84: P t;
85:
86: p = (DP)ARG0(arg);
87: if ( !p )
88: *rp = 0;
89: else {
90: for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
91: mptop(m->c,&t); NEXTMP(mr0,mr); mr->c = t; mr->dl = m->dl;
92: }
93: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar;
94: }
95: }
96:
97: void Pdp_sep(arg,rp)
98: NODE arg;
99: VECT *rp;
100: {
101: DP p,r;
102: MP m,t;
103: MP *w0,*w;
104: int i,n,d,nv,sugar;
105: VECT v;
106: pointer *pv;
107:
108: p = (DP)ARG0(arg); m = BDY(p);
109: d = QTOS((Q)ARG1(arg));
110: for ( t = m, n = 0; t; t = NEXT(t), n++ );
111: if ( d > n )
112: d = n;
113: MKVECT(v,d); *rp = v;
114: pv = BDY(v); nv = p->nv; sugar = p->sugar;
115: w0 = (MP *)MALLOC(d*sizeof(MP)); bzero(w0,d*sizeof(MP));
116: w = (MP *)MALLOC(d*sizeof(MP)); bzero(w,d*sizeof(MP));
117: for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, i %= d ) {
118: NEXTMP(w0[i],w[i]); w[i]->c = t->c; w[i]->dl = t->dl;
119: }
120: for ( i = 0; i < d; i++ ) {
121: NEXT(w[i]) = 0; MKDP(nv,w0[i],r); r->sugar = sugar;
122: pv[i] = (pointer)r;
123: }
124: }
125:
126: void Pdp_idiv(arg,rp)
127: NODE arg;
128: DP *rp;
129: {
130: dp_idiv((DP)ARG0(arg),(Q)ARG1(arg),rp);
131: }
132:
133: void Pdp_cont(arg,rp)
134: NODE arg;
135: Q *rp;
136: {
137: dp_cont((DP)ARG0(arg),rp);
138: }
139:
140: void Pdp_dtov(arg,rp)
141: NODE arg;
142: VECT *rp;
143: {
144: dp_dtov((DP)ARG0(arg),rp);
145: }
146:
147: void Pdp_mbase(arg,rp)
148: NODE arg;
149: LIST *rp;
150: {
151: NODE mb;
152:
153: asir_assert(ARG0(arg),O_LIST,"dp_mbase");
154: dp_mbase(BDY((LIST)ARG0(arg)),&mb);
155: MKLIST(*rp,mb);
156: }
157:
158: void Pdp_etov(arg,rp)
159: NODE arg;
160: VECT *rp;
161: {
162: DP dp;
163: int n,i;
164: int *d;
165: VECT v;
166: Q t;
167:
168: dp = (DP)ARG0(arg);
169: asir_assert(dp,O_DP,"dp_etov");
170: n = dp->nv; d = BDY(dp)->dl->d;
171: MKVECT(v,n);
172: for ( i = 0; i < n; i++ ) {
173: STOQ(d[i],t); v->body[i] = (pointer)t;
174: }
175: *rp = v;
176: }
177:
178: void Pdp_vtoe(arg,rp)
179: NODE arg;
180: DP *rp;
181: {
182: DP dp;
183: DL dl;
184: MP m;
185: int n,i,td;
186: int *d;
187: VECT v;
188:
189: v = (VECT)ARG0(arg);
190: asir_assert(v,O_VECT,"dp_vtoe");
191: n = v->len;
192: NEWDL(dl,n); d = dl->d;
193: for ( i = 0, td = 0; i < n; i++ ) {
194: d[i] = QTOS((Q)(v->body[i])); td += d[i];
195: }
196: dl->td = td;
197: NEWMP(m); m->dl = dl; m->c = (P)ONE; NEXT(m) = 0;
198: MKDP(n,m,dp); dp->sugar = td;
199: *rp = dp;
200: }
201:
202: void Pdp_lnf_mod(arg,rp)
203: NODE arg;
204: LIST *rp;
205: {
206: DP r1,r2;
207: NODE b,g,n;
208: int mod;
209:
210: asir_assert(ARG0(arg),O_LIST,"dp_lnf_mod");
211: asir_assert(ARG1(arg),O_LIST,"dp_lnf_mod");
212: asir_assert(ARG2(arg),O_N,"dp_lnf_mod");
213: b = BDY((LIST)ARG0(arg)); g = BDY((LIST)ARG1(arg));
214: mod = QTOS((Q)ARG2(arg));
215: dp_lnf_mod((DP)BDY(b),(DP)BDY(NEXT(b)),g,mod,&r1,&r2);
216: NEWNODE(n); BDY(n) = (pointer)r1;
217: NEWNODE(NEXT(n)); BDY(NEXT(n)) = (pointer)r2;
218: NEXT(NEXT(n)) = 0; MKLIST(*rp,n);
219: }
220:
221: void Pdp_nf_tab_mod(arg,rp)
222: NODE arg;
223: DP *rp;
224: {
225: asir_assert(ARG0(arg),O_DP,"dp_nf_tab_mod");
226: asir_assert(ARG1(arg),O_VECT,"dp_nf_tab_mod");
227: asir_assert(ARG2(arg),O_N,"dp_nf_tab_mod");
228: dp_nf_tab_mod((DP)ARG0(arg),(LIST *)BDY((VECT)ARG1(arg)),
229: QTOS((Q)ARG2(arg)),rp);
230: }
231:
232: void Pdp_igcdv_hist(arg,rp)
233: NODE arg;
234: Q *rp;
235: {
236: dp_igcdv_hist((DP)ARG0(arg),rp);
237: }
238:
239: void Pdp_idivv_hist(arg,rp)
240: NODE arg;
241: DP *rp;
242: {
243: dp_idivv_hist((Q)ARG0(arg),rp);
244: }
245:
246: void dp_idiv(p,c,rp)
247: DP p;
248: Q c;
249: DP *rp;
250: {
251: Q t;
252: N nm,q;
253: int sgn,s;
254: MP mr0,m,mr;
255:
256: if ( !p )
257: *rp = 0;
258: else if ( MUNIQ((Q)c) )
259: *rp = p;
260: else if ( MUNIQ((Q)c) )
261: chsgnd(p,rp);
262: else {
263: nm = NM(c); sgn = SGN(c);
264: for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
265: NEXTMP(mr0,mr);
266:
267: divsn(NM((Q)(m->c)),nm,&q);
268: s = sgn*SGN((Q)(m->c));
269: NTOQ(q,s,t);
270: mr->c = (P)t;
271: mr->dl = m->dl;
272: }
273: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp);
274: if ( *rp )
275: (*rp)->sugar = p->sugar;
276: }
277: }
278:
279: void dp_cont(p,rp)
280: DP p;
281: Q *rp;
282: {
283: VECT v;
284:
285: dp_dtov(p,&v); igcdv(v,rp);
286: }
287:
288: void dp_dtov(dp,rp)
289: DP dp;
290: VECT *rp;
291: {
292: MP m,t;
293: int i,n;
294: VECT v;
295: pointer *p;
296:
297: m = BDY(dp);
298: for ( t = m, n = 0; t; t = NEXT(t), n++ );
299: MKVECT(v,n);
300: for ( i = 0, p = BDY(v), t = m; i < n; t = NEXT(t), i++ )
301: p[i] = (pointer)(t->c);
302: *rp = v;
303: }
304:
305: void dp_mbase(hlist,mbase)
306: NODE hlist;
307: NODE *mbase;
308: {
309: DL *dl;
310: DL d;
311: int i,j,n,nvar,td;
312:
313: n = length(hlist); nvar = ((DP)BDY(hlist))->nv;
314: dl = (DL *)MALLOC(n*sizeof(DL));
315: for ( i = 0; i < n; i++, hlist = NEXT(hlist) )
316: dl[i] = BDY((DP)BDY(hlist))->dl;
317: NEWDL(d,nvar); *mbase = 0;
318: while ( 1 ) {
319: insert_to_node(d,mbase,nvar);
320: for ( i = nvar-1; i >= 0; ) {
321: d->d[i]++; d->td++;
322: for ( j = 0; j < n; j++ ) {
323: if ( _dl_redble(dl[j],d,nvar) )
324: break;
325: }
326: if ( j < n ) {
327: for ( j = nvar-1; j >= i; j-- )
328: d->d[j] = 0;
329: for ( j = 0, td = 0; j < i; j++ )
330: td += d->d[j];
331: d->td = td;
332: i--;
333: } else
334: break;
335: }
336: if ( i < 0 )
337: break;
338: }
339: }
340:
341: int _dl_redble(d1,d2,nvar)
342: DL d1,d2;
343: int nvar;
344: {
345: int i;
346:
347: if ( d1->td > d2->td )
348: return 0;
349: for ( i = 0; i < nvar; i++ )
350: if ( d1->d[i] > d2->d[i] )
351: break;
352: if ( i < nvar )
353: return 0;
354: else
355: return 1;
356: }
357:
358: void insert_to_node(d,n,nvar)
359: DL d;
360: NODE *n;
361: int nvar;
362: {
363: DL d1;
364: MP m;
365: DP dp;
366: NODE n0,n1,n2;
367:
368: NEWDL(d1,nvar); d1->td = d->td;
369: bcopy((char *)d->d,(char *)d1->d,nvar*sizeof(int));
370: NEWMP(m); m->dl = d1; m->c = (P)ONE; NEXT(m) = 0;
371: MKDP(nvar,m,dp); dp->sugar = d->td;
372: if ( !(*n) ) {
373: MKNODE(n1,dp,0); *n = n1;
374: } else {
375: for ( n1 = *n, n0 = 0; n1; n0 = n1, n1 = NEXT(n1) )
376: if ( (*cmpdl)(nvar,d,BDY((DP)BDY(n1))->dl) > 0 ) {
377: MKNODE(n2,dp,n1);
378: if ( !n0 )
379: *n = n2;
380: else
381: NEXT(n0) = n2;
382: break;
383: }
384: if ( !n1 ) {
385: MKNODE(n2,dp,0); NEXT(n0) = n2;
386: }
387: }
388: }
389:
390: void dp_lnf_mod(p1,p2,g,mod,r1p,r2p)
391: DP p1,p2;
392: NODE g;
393: int mod;
394: DP *r1p,*r2p;
395: {
396: DP r1,r2,b1,b2,t,s;
397: P c;
398: MQ c1,c2;
399: NODE l,b;
400: int n;
401:
402: if ( !p1 ) {
403: *r1p = p1; *r2p = p2; return;
404: }
405: n = p1->nv;
406: for ( l = g, r1 = p1, r2 = p2; l; l = NEXT(l) ) {
407: if ( !r1 ) {
408: *r1p = r1; *r2p = r2; return;
409: }
410: b = BDY((LIST)BDY(l)); b1 = (DP)BDY(b);
411: if ( dl_equal(n,BDY(r1)->dl,BDY(b1)->dl) ) {
412: b2 = (DP)BDY(NEXT(b));
413: invmq(mod,(MQ)BDY(b1)->c,&c1);
414: mulmq(mod,c1,(MQ)BDY(r1)->c,&c2); chsgnmp(mod,(P)c2,&c);
415: mulmdc(CO,mod,b1,c,&t); addmd(CO,mod,r1,t,&s); r1 = s;
416: mulmdc(CO,mod,b2,c,&t); addmd(CO,mod,r2,t,&s); r2 = s;
417: }
418: }
419: *r1p = r1; *r2p = r2;
420: }
421:
422: void dp_nf_tab_mod(p,tab,mod,rp)
423: DP p;
424: LIST *tab;
425: int mod;
426: DP *rp;
427: {
428: DP s,t,u;
429: MP m;
430: DL h;
431: int i,n;
432:
433: if ( !p ) {
434: *rp = p; return;
435: }
436: n = p->nv;
437: for ( s = 0, i = 0, m = BDY(p); m; m = NEXT(m) ) {
438: h = m->dl;
439: while ( !dl_equal(n,h,BDY((DP)BDY(BDY(tab[i])))->dl ) )
440: i++;
441: mulmdc(CO,mod,(DP)BDY(NEXT(BDY(tab[i]))),m->c,&t);
442: addmd(CO,mod,s,t,&u); s = u;
443: }
444: *rp = s;
445: }
446:
447: void dp_ptozp(p,rp)
448: DP p,*rp;
449: {
450: MP m,mr,mr0;
451: int i,n;
452: Q *w;
453: Q dvr;
454: P t;
455:
456: if ( !p )
457: *rp = 0;
458: else {
459: for ( m =BDY(p), n = 0; m; m = NEXT(m), n++ );
460: w = (Q *)ALLOCA(n*sizeof(Q));
461: for ( m =BDY(p), i = 0; i < n; m = NEXT(m), i++ )
462: if ( NUM(m->c) )
463: w[i] = (Q)m->c;
464: else
465: ptozp(m->c,1,&w[i],&t);
466: sortbynm(w,n);
467: qltozl(w,n,&dvr);
468: for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) {
469: NEXTMP(mr0,mr); divsp(CO,m->c,(P)dvr,&mr->c); mr->dl = m->dl;
470: }
471: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar;
472: }
473: }
474:
475: void dp_ptozp2(p0,p1,hp,rp)
476: DP p0,p1;
477: DP *hp,*rp;
478: {
479: DP t,s,h,r;
480: MP m,mr,mr0,m0;
481:
482: addd(CO,p0,p1,&t); dp_ptozp(t,&s);
483: if ( !p0 ) {
484: h = 0; r = s;
485: } else if ( !p1 ) {
486: h = s; r = 0;
487: } else {
488: for ( mr0 = 0, m = BDY(s), m0 = BDY(p0); m0;
489: m = NEXT(m), m0 = NEXT(m0) ) {
490: NEXTMP(mr0,mr); mr->c = m->c; mr->dl = m->dl;
491: }
492: NEXT(mr) = 0; MKDP(p0->nv,mr0,h); MKDP(p0->nv,m,r);
493: }
494: if ( h )
495: h->sugar = p0->sugar;
496: if ( r )
497: r->sugar = p1->sugar;
498: *hp = h; *rp = r;
499: }
500:
501: struct igcdv_hist {
502: int len;
503: DP dp;
504: Q d,d1;
505: Q *q,*q1;
506: };
507:
508: static struct igcdv_hist current_igcdv_hist;
509:
510: void dp_igcdv_hist(p,rp)
511: DP p;
512: Q *rp;
513: {
514: VECT c;
515: Q *a,*q,*r,*q1,*r1;
516: int i,n,nz;
517: Q d,d1;
518: N qn,rn,gn;
519: struct oVECT v;
520:
521: dp_dtov(p,&c); a = (Q *)c->body;
522: n = c->len;
523: q = (Q *)MALLOC(n*sizeof(Q)); r = (Q *)MALLOC(n*sizeof(Q));
524: igcdv_estimate(c,&d);
525: for ( i = 0, nz = 0; i < n; i++ ) {
526: divn(NM(a[i]),NM(d),&qn,&rn);
527: NTOQ(qn,SGN(a[i]),q[i]); NTOQ(rn,SGN(a[i]),r[i]);
528: if ( r[i] )
529: nz = 1;
530: }
531: current_igcdv_hist.len = n;
532: current_igcdv_hist.dp = p;
533: current_igcdv_hist.d = d;
534: current_igcdv_hist.q = q;
535: if ( nz ) {
536: v.id = O_VECT; v.len = n; v.body = (pointer *)r;
537: igcdv(&v,&d1);
538: q1 = (Q *)MALLOC(n*sizeof(Q)); r1 = (Q *)MALLOC(n*sizeof(Q));
539: for ( i = 0; i < n; i++ ) {
540: if ( r[i] )
541: divn(NM(r[i]),NM(d1),&qn,&rn);
542: else {
543: qn = rn = 0;
544: }
545: NTOQ(qn,SGN(r[i]),q1[i]); NTOQ(rn,SGN(r[i]),r1[i]);
546: }
547: gcdn(NM(d),NM(d1),&gn); NTOQ(gn,1,*rp);
548: } else {
549: d1 = 0; q1 = 0; *rp = d;
550: }
551: current_igcdv_hist.d1 = d1;
552: current_igcdv_hist.q1 = q1;
553: }
554:
555: void dp_idivv_hist(g,rp)
556: Q g;
557: DP *rp;
558: {
559: int i,n;
560: Q *q,*q1,*s;
561: Q t,u,m;
562: N qn;
563:
564: n = current_igcdv_hist.len;
565: q = current_igcdv_hist.q; q1 = current_igcdv_hist.q1;
566: divsn(NM(current_igcdv_hist.d),NM(g),&qn); NTOQ(qn,1,m);
567: s = (Q *)MALLOC(n*sizeof(Q));
568: for ( i = 0; i < n; i++ )
569: mulq(m,q[i],&s[i]);
570: if ( q1 ) {
571: divsn(NM(current_igcdv_hist.d1),NM(g),&qn); NTOQ(qn,1,m);
572: for ( i = 0; i < n; i++ ) {
573: mulq(m,q1[i],&t); addq(t,s[i],&u); s[i] = u;
574: }
575: }
576: dp_vtod(s,current_igcdv_hist.dp,rp);
577: }
578:
579: void dp_vtod(c,p,rp)
580: Q *c;
581: DP p;
582: DP *rp;
583: {
584: MP mr0,m,mr;
585: int i;
586:
587: if ( !p )
588: *rp = 0;
589: else {
590: for ( mr0 = 0, m = BDY(p), i = 0; m; m = NEXT(m), i++ ) {
591: NEXTMP(mr0,mr); mr->c = (P)c[i]; mr->dl = m->dl;
592: }
593: NEXT(mr) = 0; MKDP(p->nv,mr0,*rp);
594: (*rp)->sugar = p->sugar;
595: }
596: }
597:
598: #if INET
599: void dp_ptozp_d_old(dist,ndist,p,rp)
600: NODE dist;
601: int ndist;
602: DP p,*rp;
603: {
604: DP d,s,u,su;
605: MP m,mr,mr0;
606: MP *w0,*w;
607: Q *g;
608: int i,n,nv,nsep;
609: P t;
610: NODE tn,n0,n1,n2;
611: struct oVECT v;
612: int id,sindex;
613: Obj dmy;
614: Q gcd;
615: STRING cont,div;
616:
617: if ( !p )
618: *rp = 0;
619: else {
620: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
621: nsep = ndist + 1;
622: if ( n <= nsep ) {
623: dp_ptozp(p,rp); return;
624: }
625: nv = p->nv;
626: w0 = (MP *)MALLOC(nsep*sizeof(MP)); bzero(w0,nsep*sizeof(MP));
627: w = (MP *)MALLOC(nsep*sizeof(MP)); bzero(w,nsep*sizeof(MP));
628: g = (Q *)MALLOC(nsep*sizeof(Q)); bzero(g,nsep*sizeof(Q));
629: for ( m = BDY(p), i = 0; m; m = NEXT(m), i++, i %= nsep ) {
630: NEXTMP(w0[i],w[i]); w[i]->c = m->c; w[i]->dl = m->dl;
631: }
632: MKSTR(cont,"reg_dp_cont"); MKSTR(div,"reg_dp_idiv");
633:
634: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
635: NEXT(w[i]) = 0; MKDP(nv,w0[i],d); d->sugar = p->sugar;
636: MKNODE(n2,d,0); MKNODE(n1,cont,n2); MKNODE(n0,BDY(tn),n1);
637: Pox_rpc(n0,&dmy);
638: }
639: NEXT(w[i]) = 0; MKDP(nv,w0[i],d); d->sugar = p->sugar;
640: dp_cont(d,&g[i]);
641:
642: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) )
643: Pox_pop_local(tn,&g[i]);
644: v.id = O_VECT; v.len = nsep; v.body = (pointer *)g; igcdv(&v,&gcd);
645:
646: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
647: MKNODE(n2,gcd,0); MKNODE(n1,div,n2); MKNODE(n0,BDY(tn),n1);
648: Pox_rpc(n0,&dmy);
649: }
650: dp_idiv(d,gcd,&s);
651:
652: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
653: Pox_pop_local(tn,&u);
654: addd(CO,s,u,&su); s = su;
655: }
656: *rp = s;
657: }
658: }
659:
660: void dp_ptozp_d(dist,ndist,p,rp)
661: NODE dist;
662: int ndist;
663: DP p,*rp;
664: {
665: int i,j,k,l,n,nsep;
666: MP m;
667: NODE tn,n0,n1,n2,n3;
668: struct oVECT v;
669: VECT c,cs;
670: VECT qi,ri;
671: LIST *qr;
672: int s,id;
673: Obj dmy;
674: Q d0,d1,gcd,a,u,u1;
675: Q *q,*r;
676: STRING iqr_v;
677: pointer *b;
678: N qn,gn;
679: double get_rtime();
680: int blen;
681: double t0;
682: double t_e,t_d,t_d1,t_c;
683:
684: if ( !p )
685: *rp = 0;
686: else {
687: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
688: nsep = ndist + 1;
689: if ( n <= nsep ) {
690: dp_ptozp(p,rp); return;
691: }
692: t0 = get_rtime();
693: dp_dtov(p,&c);
694: igcdv_estimate(c,&d0);
695: t_e = get_rtime()-t0;
696: t0 = get_rtime();
697: dp_dtov(p,&c);
698: sepvect(c,nsep,&cs);
699: MKSTR(iqr_v,"iqr");
700: qr = (LIST *)CALLOC(nsep,sizeof(LIST));
701: q = (Q *)CALLOC(n,sizeof(Q));
702: r = (Q *)CALLOC(n,sizeof(Q));
703: for ( i = 0, tn = dist, b = BDY(cs); i < ndist; i++, tn = NEXT(tn) ) {
704: MKNODE(n3,d0,0); MKNODE(n2,b[i],n3);
705: MKNODE(n1,iqr_v,n2); MKNODE(n0,BDY(tn),n1);
706: Pox_rpc(n0,&dmy);
707: }
708: iqrv(b[i],d0,&qr[i]);
709: dp_dtov(p,&c);
710: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
711: Pox_pop_local(tn,&qr[i]);
712: if ( OID(qr[i]) == O_ERR ) {
713: printexpr(CO,(Obj)qr[i]);
714: error("dp_ptozp_d : aborted");
715: }
716: }
717: t_d = get_rtime()-t0;
718: t_d1 = t_d/n;
719: t0 = get_rtime();
720: for ( i = j = 0; i < nsep; i++ ) {
721: tn = BDY(qr[i]); qi = (VECT)BDY(tn); ri = (VECT)BDY(NEXT(tn));
722: for ( k = 0, l = qi->len; k < l; k++, j++ ) {
723: q[j] = (Q)BDY(qi)[k]; r[j] = (Q)BDY(ri)[k];
724: }
725: }
726: v.id = O_VECT; v.len = n; v.body = (pointer *)r; igcdv(&v,&d1);
727: if ( d1 ) {
728: gcdn(NM(d0),NM(d1),&gn); NTOQ(gn,1,gcd);
729: divsn(NM(d0),gn,&qn); NTOQ(qn,1,a);
730: for ( i = 0; i < n; i++ ) {
731: mulq(a,q[i],&u);
732: if ( r[i] ) {
733: divsn(NM(r[i]),gn,&qn); NTOQ(qn,SGN(r[i]),u1);
734: addq(u,u1,&q[i]);
735: } else
736: q[i] = u;
737: }
738: } else
739: gcd = d0;
740: dp_vtod(q,p,rp);
741: t_c = get_rtime()-t0;
742: blen=p_mag((P)gcd);
743: pz_t_e += t_e; pz_t_d += t_d; pz_t_d1 += t_d1; pz_t_c += t_c;
744: if ( 0 )
745: fprintf(stderr,"(%d,%d)",p_mag((P)d0)-blen,blen);
746: }
747: }
748:
749: void dp_ptozp2_d(dist,ndist,p0,p1,hp,rp)
750: NODE dist;
751: int ndist;
752: DP p0,p1;
753: DP *hp,*rp;
754: {
755: DP t,s,h,r;
756: MP m,mr,mr0,m0;
757:
758: addd(CO,p0,p1,&t); dp_ptozp_d(dist,ndist,t,&s);
759: if ( !p0 ) {
760: h = 0; r = s;
761: } else if ( !p1 ) {
762: h = s; r = 0;
763: } else {
764: for ( mr0 = 0, m = BDY(s), m0 = BDY(p0); m0;
765: m = NEXT(m), m0 = NEXT(m0) ) {
766: NEXTMP(mr0,mr); mr->c = m->c; mr->dl = m->dl;
767: }
768: NEXT(mr) = 0; MKDP(p0->nv,mr0,h); MKDP(p0->nv,m,r);
769: }
770: if ( h )
771: h->sugar = p0->sugar;
772: if ( r )
773: r->sugar = p1->sugar;
774: *hp = h; *rp = r;
775: }
776: #endif
777:
778: /*
779: * Old codes
780: */
781:
782: #if 0
783: void Pdp_sep(arg,rp)
784: NODE arg;
785: VECT *rp;
786: {
787: DP p,s;
788: MP m,t,mr,mr0;
789: int i,j,n,d,r,q,q1,nv;
790: VECT w;
791: pointer *pw;
792:
793: p = (DP)ARG0(arg); m = BDY(p);
794: d = QTOS((Q)ARG1(arg));
795: for ( t = m, n = 0; t; t = NEXT(t), n++ );
796: if ( d > n )
797: d = n;
798: q = n/d; r = n%d; q1 = q+1;
799: MKVECT(w,d); *rp = w;
800: t = m; pw = BDY(w); nv = p->nv;
801: for ( i = 0; i < r; i++ ) {
802: for ( mr0 = 0, j = 0; j < q1; j++, t = NEXT(t) ) {
803: NEXTMP(mr0,mr);
804: mr->c = t->c;
805: mr->dl = t->dl;
806: }
807: NEXT(mr) = 0; MKDP(nv,mr0,s); s->sugar = p->sugar;
808: pw[i] = (pointer)s;
809: }
810: for ( ; i < d; i++ ) {
811: for ( mr0 = 0, j = 0; j < q; j++, t = NEXT(t) ) {
812: NEXTMP(mr0,mr);
813: mr->c = t->c;
814: mr->dl = t->dl;
815: }
816: NEXT(mr) = 0; MKDP(nv,mr0,s); s->sugar = p->sugar;
817: pw[i] = (pointer)s;
818: }
819: }
820:
821: void dp_ptozp_mpi(dist,ndist,p,rp)
822: NODE dist;
823: int ndist;
824: DP p,*rp;
825: {
826: int i,j,k,l,n,nsep;
827: MP m;
828: NODE tn,n0,n1,n2,n3;
829: struct oVECT v;
830: VECT c,cs;
831: VECT qi,ri;
832: LIST *qr;
833: int id;
834: Obj dmy;
835: Q d0,d1,gcd,a,u,u1;
836: Q *q,*r;
837: STRING iqr_v;
838: pointer *b;
839: N qn,gn;
840: double get_rtime();
841: int blen;
842: double t0;
843: double t_e,t_d,t_d1,t_c;
844:
845: if ( !p )
846: *rp = 0;
847: else {
848: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
849: nsep = ndist + 1;
850: if ( n <= nsep ) {
851: dp_ptozp(p,rp); return;
852: }
853: t0 = get_rtime();
854: dp_dtov(p,&c);
855: igcdv_estimate(c,&d0);
856: t_e = get_rtime()-t0;
857: t0 = get_rtime();
858: dp_dtov(p,&c);
859: sepvect(c,nsep,&cs);
860: MKSTR(iqr_v,"iqr");
861: qr = (LIST *)CALLOC(nsep,sizeof(LIST));
862: q = (Q *)CALLOC(n,sizeof(Q));
863: r = (Q *)CALLOC(n,sizeof(Q));
864: for ( i = 0, tn = dist, b = BDY(cs); i < ndist;
865: i++, tn = NEXT(tn) ) {
866: div_vect_mpi(QTOS((Q)BDY(tn)),b[i],d0);
867: }
868: iqrv(b[i],d0,&qr[i]);
869: dp_dtov(p,&c);
870: for ( i = j = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
871: get_div_vect_mpi(QTOS((Q)BDY(tn)),&qr[i]);
872: }
873: t_d = get_rtime()-t0;
874: t_d1 = t_d/n;
875: t0 = get_rtime();
876: for ( i = j = 0; i < nsep; i++ ) {
877: tn = BDY(qr[i]); qi = (VECT)BDY(tn); ri = (VECT)BDY(NEXT(tn));
878: for ( k = 0, l = qi->len; k < l; k++, j++ ) {
879: q[j] = (Q)BDY(qi)[k]; r[j] = (Q)BDY(ri)[k];
880: }
881: }
882: v.id = O_VECT; v.len = n; v.body = (pointer *)r; igcdv(&v,&d1);
883: if ( d1 ) {
884: gcdn(NM(d0),NM(d1),&gn); NTOQ(gn,1,gcd);
885: divsn(NM(d0),gn,&qn); NTOQ(qn,1,a);
886: for ( i = 0; i < n; i++ ) {
887: mulq(a,q[i],&u);
888: if ( r[i] ) {
889: divsn(NM(r[i]),gn,&qn); NTOQ(qn,SGN(r[i]),u1);
890: addq(u,u1,&q[i]);
891: } else
892: q[i] = u;
893: }
894: } else
895: gcd = d0;
896: dp_vtod(q,p,rp);
897: t_c = get_rtime()-t0;
898: blen=p_mag(gcd);
899: pz_t_e += t_e; pz_t_d += t_d; pz_t_d1 += t_d1; pz_t_c += t_c;
900: if ( 0 )
901: fprintf(stderr,"(%d,%d)",p_mag(d0)-blen,blen);
902: }
903: }
904:
905: void dp_ptozp_d(dist,ndist,p,rp)
906: NODE dist;
907: int ndist;
908: DP p,*rp;
909: {
910: DP d,s,u,su;
911: MP m,mr,mr0;
912: MP *w0,*w;
913: Q *g;
914: int i,n,nv,nsep;
915: P t;
916: NODE tn,n0,n1,n2;
917: struct oVECT v;
918: int sindex,id;
919: Obj dmy;
920: Q gcd;
921: STRING gcd_h,div_h;
922:
923: if ( !p )
924: *rp = 0;
925: else {
926: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
927: nsep = ndist + 1;
928: if ( n <= nsep ) {
929: dp_ptozp(p,rp); return;
930: }
931: nv = p->nv;
932: w0 = (MP *)MALLOC(nsep*sizeof(MP)); bzero(w0,nsep*sizeof(MP));
933: w = (MP *)MALLOC(nsep*sizeof(MP)); bzero(w,nsep*sizeof(MP));
934: g = (Q *)MALLOC(nsep*sizeof(Q)); bzero(g,nsep*sizeof(Q));
935: for ( m = BDY(p), i = 0; m; m = NEXT(m), i++, i %= nsep ) {
936: NEXTMP(w0[i],w[i]); w[i]->c = m->c; w[i]->dl = m->dl;
937: }
938: MKSTR(gcd_h,"dp_igcdv_hist"); MKSTR(div_h,"dp_idivv_hist");
939:
940: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
941: NEXT(w[i]) = 0; MKDP(nv,w0[i],d); d->sugar = p->sugar;
942: MKNODE(n2,d,0); MKNODE(n1,gcd_h,n2); MKNODE(n0,BDY(tn),n1);
943: Pox_rpc(n0,&dmy);
944: }
945: NEXT(w[i]) = 0; MKDP(nv,w0[i],d); d->sugar = p->sugar;
946: dp_igcdv_hist(d,&g[i]);
947:
948: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) )
949: Pox_pop_local(tn,&g[i]);
950: v.id = O_VECT; v.len = nsep; v.body = (pointer *)g; igcdv(&v,&gcd);
951:
952: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
953: MKNODE(n2,gcd,0); MKNODE(n1,div_h,n2); MKNODE(n0,BDY(tn),n1);
954: Pox_rpc(n0,&dmy);
955: }
956: dp_idivv_hist(gcd,&s);
957:
958: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
959: Pox_pop_local(tn,&u);
960: addd(CO,s,u,&su); s = su;
961: }
962: *rp = s;
963: }
964: }
965: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>