Annotation of OpenXM_contrib2/asir2000/builtin/dp-supp.c, Revision 1.4
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.4 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/dp-supp.c,v 1.3 2000/08/22 05:03:57 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: void dp_ptozp_d_old(dist,ndist,p,rp)
599: NODE dist;
600: int ndist;
601: DP p,*rp;
602: {
603: DP d,s,u,su;
604: MP m,mr,mr0;
605: MP *w0,*w;
606: Q *g;
607: int i,n,nv,nsep;
608: P t;
609: NODE tn,n0,n1,n2;
610: struct oVECT v;
611: int id,sindex;
612: Obj dmy;
613: Q gcd;
614: STRING cont,div;
615:
616: if ( !p )
617: *rp = 0;
618: else {
619: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
620: nsep = ndist + 1;
621: if ( n <= nsep ) {
622: dp_ptozp(p,rp); return;
623: }
624: nv = p->nv;
625: w0 = (MP *)MALLOC(nsep*sizeof(MP)); bzero(w0,nsep*sizeof(MP));
626: w = (MP *)MALLOC(nsep*sizeof(MP)); bzero(w,nsep*sizeof(MP));
627: g = (Q *)MALLOC(nsep*sizeof(Q)); bzero(g,nsep*sizeof(Q));
628: for ( m = BDY(p), i = 0; m; m = NEXT(m), i++, i %= nsep ) {
629: NEXTMP(w0[i],w[i]); w[i]->c = m->c; w[i]->dl = m->dl;
630: }
631: MKSTR(cont,"reg_dp_cont"); MKSTR(div,"reg_dp_idiv");
632:
633: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
634: NEXT(w[i]) = 0; MKDP(nv,w0[i],d); d->sugar = p->sugar;
635: MKNODE(n2,d,0); MKNODE(n1,cont,n2); MKNODE(n0,BDY(tn),n1);
636: Pox_rpc(n0,&dmy);
637: }
638: NEXT(w[i]) = 0; MKDP(nv,w0[i],d); d->sugar = p->sugar;
639: dp_cont(d,&g[i]);
640:
641: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) )
642: Pox_pop_local(tn,&g[i]);
643: v.id = O_VECT; v.len = nsep; v.body = (pointer *)g; igcdv(&v,&gcd);
644:
645: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
646: MKNODE(n2,gcd,0); MKNODE(n1,div,n2); MKNODE(n0,BDY(tn),n1);
647: Pox_rpc(n0,&dmy);
648: }
649: dp_idiv(d,gcd,&s);
650:
651: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
652: Pox_pop_local(tn,&u);
653: addd(CO,s,u,&su); s = su;
654: }
655: *rp = s;
656: }
657: }
658:
659: void dp_ptozp_d(dist,ndist,p,rp)
660: NODE dist;
661: int ndist;
662: DP p,*rp;
663: {
664: int i,j,k,l,n,nsep;
665: MP m;
666: NODE tn,n0,n1,n2,n3;
667: struct oVECT v;
668: VECT c,cs;
669: VECT qi,ri;
670: LIST *qr;
671: int s,id;
672: Obj dmy;
673: Q d0,d1,gcd,a,u,u1;
674: Q *q,*r;
675: STRING iqr_v;
676: pointer *b;
677: N qn,gn;
678: double get_rtime();
679: int blen;
680: double t0;
681: double t_e,t_d,t_d1,t_c;
682:
683: if ( !p )
684: *rp = 0;
685: else {
686: for ( m = BDY(p), n = 0; m; m = NEXT(m), n++ );
687: nsep = ndist + 1;
688: if ( n <= nsep ) {
689: dp_ptozp(p,rp); return;
690: }
691: t0 = get_rtime();
692: dp_dtov(p,&c);
693: igcdv_estimate(c,&d0);
694: t_e = get_rtime()-t0;
695: t0 = get_rtime();
696: dp_dtov(p,&c);
697: sepvect(c,nsep,&cs);
698: MKSTR(iqr_v,"iqr");
699: qr = (LIST *)CALLOC(nsep,sizeof(LIST));
700: q = (Q *)CALLOC(n,sizeof(Q));
701: r = (Q *)CALLOC(n,sizeof(Q));
702: for ( i = 0, tn = dist, b = BDY(cs); i < ndist; i++, tn = NEXT(tn) ) {
703: MKNODE(n3,d0,0); MKNODE(n2,b[i],n3);
704: MKNODE(n1,iqr_v,n2); MKNODE(n0,BDY(tn),n1);
705: Pox_rpc(n0,&dmy);
706: }
707: iqrv(b[i],d0,&qr[i]);
708: dp_dtov(p,&c);
709: for ( i = 0, tn = dist; i < ndist; i++, tn = NEXT(tn) ) {
710: Pox_pop_local(tn,&qr[i]);
711: if ( OID(qr[i]) == O_ERR ) {
712: printexpr(CO,(Obj)qr[i]);
713: error("dp_ptozp_d : aborted");
714: }
715: }
716: t_d = get_rtime()-t0;
717: t_d1 = t_d/n;
718: t0 = get_rtime();
719: for ( i = j = 0; i < nsep; i++ ) {
720: tn = BDY(qr[i]); qi = (VECT)BDY(tn); ri = (VECT)BDY(NEXT(tn));
721: for ( k = 0, l = qi->len; k < l; k++, j++ ) {
722: q[j] = (Q)BDY(qi)[k]; r[j] = (Q)BDY(ri)[k];
723: }
724: }
725: v.id = O_VECT; v.len = n; v.body = (pointer *)r; igcdv(&v,&d1);
726: if ( d1 ) {
727: gcdn(NM(d0),NM(d1),&gn); NTOQ(gn,1,gcd);
728: divsn(NM(d0),gn,&qn); NTOQ(qn,1,a);
729: for ( i = 0; i < n; i++ ) {
730: mulq(a,q[i],&u);
731: if ( r[i] ) {
732: divsn(NM(r[i]),gn,&qn); NTOQ(qn,SGN(r[i]),u1);
733: addq(u,u1,&q[i]);
734: } else
735: q[i] = u;
736: }
737: } else
738: gcd = d0;
739: dp_vtod(q,p,rp);
740: t_c = get_rtime()-t0;
741: blen=p_mag((P)gcd);
742: pz_t_e += t_e; pz_t_d += t_d; pz_t_d1 += t_d1; pz_t_c += t_c;
743: if ( 0 )
744: fprintf(stderr,"(%d,%d)",p_mag((P)d0)-blen,blen);
745: }
746: }
747:
748: void dp_ptozp2_d(dist,ndist,p0,p1,hp,rp)
749: NODE dist;
750: int ndist;
751: DP p0,p1;
752: DP *hp,*rp;
753: {
754: DP t,s,h,r;
755: MP m,mr,mr0,m0;
756:
757: addd(CO,p0,p1,&t); dp_ptozp_d(dist,ndist,t,&s);
758: if ( !p0 ) {
759: h = 0; r = s;
760: } else if ( !p1 ) {
761: h = s; r = 0;
762: } else {
763: for ( mr0 = 0, m = BDY(s), m0 = BDY(p0); m0;
764: m = NEXT(m), m0 = NEXT(m0) ) {
765: NEXTMP(mr0,mr); mr->c = m->c; mr->dl = m->dl;
766: }
767: NEXT(mr) = 0; MKDP(p0->nv,mr0,h); MKDP(p0->nv,m,r);
768: }
769: if ( h )
770: h->sugar = p0->sugar;
771: if ( r )
772: r->sugar = p1->sugar;
773: *hp = h; *rp = r;
774: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>