Annotation of OpenXM_contrib2/asir2000/engine/Hgfs.c, Revision 1.3
1.3 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.2 2001/06/21 07:47:02 noro Exp $ */
1.1 noro 2:
3: #include "ca.h"
4:
5: struct p_pair {
6: UM p0;
7: UM p1;
8: struct p_pair *next;
9: };
10:
11: void canzassf(UM,int,UM *);
12: void lnfsf(int,UM,UM,struct p_pair *,UM,UM);
13: void minipolysf(UM,UM,UM);
14: void czsfum(UM,UM *);
15: void gensqfrsfum(UM,DUM);
16:
17: void fctrsf(p,dcp)
18: P p;
19: DCP *dcp;
20: {
21: int n,i,j,k;
22: DCP dc,dc0;
23: P lc;
24: P zp;
25: UM mp;
26: UM *tl;
27: struct oDUM *udc,*udc1;
28:
29: simp_ff(p,&zp); p = zp;
30: if ( !p ) {
31: *dcp = 0; return;
32: }
33: mp = W_UMALLOC(UDEG(p));
34: ptosfum(p,mp);
35: if ( (n = DEG(mp)) < 0 ) {
36: *dcp = 0; return;
37: } else if ( n == 0 ) {
38: NEWDC(dc); COEF(dc) = p; DEG(dc) = ONE;
39: NEXT(dc) = 0; *dcp = dc;
40: return;
41: }
42: lc = COEF(DC(p));
43: if ( !_isonesf(COEF(mp)[n]) ) {
44: monicsfum(mp);
45: }
46:
47: W_CALLOC(n+1,struct oDUM,udc);
48: gensqfrsfum(mp,udc);
49:
50: tl = (UM *)ALLOCA((n+1)*sizeof(UM));
51: W_CALLOC(DEG(mp)+1,struct oDUM,udc1);
52:
53: for ( i = 0,j = 0; udc[i].f; i++ )
54: if ( DEG(udc[i].f) == 1 ) {
55: udc1[j].f = udc[i].f; udc1[j].n = udc[i].n; j++;
56: } else {
57: bzero((char *)tl,(n+1)*sizeof(UM));
58: czsfum(udc[i].f,tl);
59: for ( k = 0; tl[k]; k++, j++ ) {
60: udc1[j].f = tl[k]; udc1[j].n = udc[i].n;
61: }
62: }
63: udc = udc1;
64: NEWDC(dc0); COEF(dc0) = lc; DEG(dc0) = ONE; dc = dc0;
65: for ( n = 0; udc[n].f; n++ ) {
66: NEWDC(NEXT(dc)); dc = NEXT(dc);
67: STOQ(udc[n].n,DEG(dc)); sfumtop(VR(p),udc[n].f,&COEF(dc));
68: }
69: NEXT(dc) = 0; *dcp = dc0;
70: }
71:
72: void gensqfrsfum(p,dc)
73: UM p;
74: struct oDUM *dc;
75: {
76: int n,i,j,d,mod;
77: UM t,s,g,f,f1,b;
78:
79: if ( (n = DEG(p)) == 1 ) {
80: dc[0].f = UMALLOC(DEG(p)); cpyum(p,dc[0].f); dc[0].n = 1;
81: return;
82: }
83: t = W_UMALLOC(n); s = W_UMALLOC(n); g = W_UMALLOC(n);
84: f = W_UMALLOC(n); f1 = W_UMALLOC(n); b = W_UMALLOC(n);
85: diffsfum(p,t); cpyum(p,s); gcdsfum(t,s,g);
86: if ( !DEG(g) ) {
87: dc[0].f = UMALLOC(DEG(p)); cpyum(p,dc[0].f); dc[0].n = 1;
88: return;
89: }
90: cpyum(p,b); cpyum(p,t); divsfum(t,g,f);
91: for ( i = 0, d = 0; DEG(f); i++ ) {
92: while ( 1 ) {
93: cpyum(b,t);
94: if ( divsfum(t,f,s) >= 0 )
95: break;
96: else {
97: cpyum(s,b); d++;
98: }
99: }
100: cpyum(b,t); cpyum(f,s); gcdsfum(t,s,f1);
101: divsfum(f,f1,s); cpyum(f1,f);
102: dc[i].f = UMALLOC(DEG(s)); cpyum(s,dc[i].f); dc[i].n = d;
103: }
104: mod = characteristic_sf();
105: if ( DEG(b) > 0 ) {
106: d = 1;
107: while ( 1 ) {
108: cpyum(b,t);
109: for ( j = DEG(t); j >= 0; j-- )
110: if ( COEF(t)[j] && (j % mod) )
111: break;
112: if ( j >= 0 )
113: break;
114: else {
115: DEG(s) = DEG(t)/mod;
116: for ( j = 0; j <= DEG(t); j++ )
117: COEF(s)[j] = COEF(t)[j*mod];
118: cpyum(s,b); d *= mod;
119: }
120: }
121: gensqfrsfum(b,dc+i);
122: for ( j = i; dc[j].f; j++ )
123: dc[j].n *= d;
124: }
125: }
126:
127: void randsfum(d,p)
128: int d;
129: UM p;
130: {
131: int i;
132:
1.2 noro 133: for ( i = 0; i < d; i++ )
1.1 noro 134: COEF(p)[i] = _randomsf();
1.2 noro 135: for ( i = d-1; i >= 0 && !COEF(p)[i]; i-- );
136: p->d = i;
1.1 noro 137: }
138:
139: void pwrmodsfum(p,e,f,pr)
140: int e;
141: UM p,f,pr;
142: {
143: UM wt,ws,q;
144:
145: if ( e == 0 ) {
146: DEG(pr) = 0; COEF(pr)[0] = _onesf();
147: } else if ( DEG(p) < 0 )
148: DEG(pr) = -1;
149: else if ( e == 1 ) {
150: q = W_UMALLOC(DEG(p)); cpyum(p,pr);
151: DEG(pr) = divsfum(pr,f,q);
152: } else if ( DEG(p) == 0 ) {
153: DEG(pr) = 0; COEF(pr)[0] = _pwrsf(COEF(p)[0],e);
154: } else {
155: wt = W_UMALLOC(2*DEG(f)); ws = W_UMALLOC(2*DEG(f));
156: q = W_UMALLOC(2*DEG(f));
157: pwrmodsfum(p,e/2,f,wt);
158: if ( !(e%2) ) {
159: mulsfum(wt,wt,pr); DEG(pr) = divsfum(pr,f,q);
160: } else {
161: mulsfum(wt,wt,ws);
162: DEG(ws) = divsfum(ws,f,q);
163: mulsfum(ws,p,pr);
164: DEG(pr) = divsfum(pr,f,q);
165: }
166: }
167: }
168:
1.2 noro 169: void spwrsfum(m,f,e,r)
1.1 noro 170: UM f,m,r;
171: N e;
172: {
173: UM t,s,q;
174: N e1;
175: int a;
176:
177: if ( !e ) {
178: DEG(r) = 0; COEF(r)[0] = _onesf();
179: } else if ( UNIN(e) )
180: cpyum(f,r);
181: else {
182: a = divin(e,2,&e1);
1.2 noro 183: t = W_UMALLOC(2*DEG(m)); spwrsfum(m,f,e1,t);
1.1 noro 184: s = W_UMALLOC(2*DEG(m)); q = W_UMALLOC(2*DEG(m));
185: mulsfum(t,t,s); DEG(s) = divsfum(s,m,q);
186: if ( a ) {
187: mulsfum(s,f,t); DEG(t) = divsfum(t,m,q); cpyum(t,r);
188: } else
189: cpyum(s,r);
190: }
191: }
192:
1.2 noro 193: void tracemodsfum(m,f,e,r)
194: UM f,m,r;
195: int e;
196: {
197: UM t,s,q,u;
198: int i;
199:
200: q = W_UMALLOC(2*DEG(m)+DEG(f)); /* XXX */
201: t = W_UMALLOC(2*DEG(m));
202: s = W_UMALLOC(2*DEG(m));
203: u = W_UMALLOC(2*DEG(m));
204: DEG(f) = divsfum(f,m,q);
205: cpyum(f,s);
206: cpyum(f,t);
207: for ( i = 1; i < e; i++ ) {
208: mulsfum(t,t,u);
209: DEG(u) = divsfum(u,m,q); cpyum(u,t);
210: addsfum(t,s,u); cpyum(u,s);
211: }
212: cpyum(s,r);
213: }
214:
1.1 noro 215: void make_qmatsf(p,tab,mp)
216: UM p;
217: UM *tab;
218: int ***mp;
219: {
220: int n,i,j;
221: int *c;
222: UM q,r;
223: int **mat;
224: int one;
225:
226: n = DEG(p);
227: *mp = mat = almat(n,n);
228: for ( j = 0; j < n; j++ ) {
229: r = W_UMALLOC(DEG(tab[j])); q = W_UMALLOC(DEG(tab[j]));
230: cpyum(tab[j],r); DEG(r) = divsfum(r,p,q);
231: for ( i = 0, c = COEF(r); i <= DEG(r); i++ )
232: mat[i][j] = c[i];
233: }
234: one = _onesf();
235: for ( i = 0; i < n; i++ )
236: mat[i][i] = _subsf(mat[i][i],one);
237: }
238:
239: void nullsf(mat,n,ind)
240: int **mat;
241: int *ind;
242: int n;
243: {
244: int i,j,l,s,h,inv;
245: int *t,*u;
246:
247: bzero((char *)ind,n*sizeof(int));
248: ind[0] = 0;
249: for ( i = j = 0; j < n; i++, j++ ) {
250: for ( ; j < n; j++ ) {
251: for ( l = i; l < n; l++ )
252: if ( mat[l][j] )
253: break;
254: if ( l < n ) {
255: t = mat[i]; mat[i] = mat[l]; mat[l] = t; break;
256: } else
257: ind[j] = 1;
258: }
259: if ( j == n )
260: break;
261: inv = _invsf(mat[i][j]);
262: for ( s = j, t = mat[i]; s < n; s++ )
263: t[s] = _mulsf(t[s],inv);
264: for ( l = 0; l < n; l++ ) {
265: if ( l == i )
266: continue;
267: u = mat[l]; h = _chsgnsf(u[j]);
268: for ( s = j; s < n; s++ )
269: u[s] = _addsf(_mulsf(h,t[s]),u[s]);
270: }
271: }
272: }
273:
274: void null_to_solsf(mat,ind,n,r)
275: int **mat;
276: int *ind;
277: int n;
278: UM *r;
279: {
280: int i,j,k,l;
281: int *c;
282: UM w;
283:
284: for ( i = 0, l = 0; i < n; i++ ) {
285: if ( !ind[i] )
286: continue;
287: w = UMALLOC(n);
288: for ( j = k = 0, c = COEF(w); j < n; j++ )
289: if ( ind[j] )
290: c[j] = 0;
291: else
292: c[j] = mat[k++][i];
293: c[i] = _chsgnsf(_onesf());
294: for ( j = n; j >= 0; j-- )
295: if ( c[j] )
296: break;
297: DEG(w) = j;
298: r[l++] = w;
299: }
300: }
301: /*
302: make_qmatsf(p,tab,mp)
303: nullsf(mat,n,ind)
304: null_to_solsf(ind,n,r)
305: */
306:
307: void czsfum(f,r)
308: UM f,*r;
309: {
310: int i,j;
311: int d,n,ord;
312: UM s,t,u,v,w,g,x,m,q;
313: UM *base;
314:
315: n = DEG(f); base = (UM *)ALLOCA(n*sizeof(UM));
316: bzero((char *)base,n*sizeof(UM));
317:
318: w = W_UMALLOC(2*n); q = W_UMALLOC(2*n); m = W_UMALLOC(2*n);
319:
320: base[0] = W_UMALLOC(0); DEG(base[0]) = 0; COEF(base[0])[0] = _onesf();
321:
322: t = W_UMALLOC(1); DEG(t) = 1; COEF(t)[0] = 0; COEF(t)[1] = _onesf();
323:
324: ord = field_order_sf();
325: pwrmodsfum(t,ord,f,w);
326: base[1] = W_UMALLOC(DEG(w));
327: cpyum(w,base[1]);
328:
329: for ( i = 2; i < n; i++ ) {
330: mulsfum(base[i-1],base[1],m);
331: DEG(m) = divsfum(m,f,q);
332: base[i] = W_UMALLOC(DEG(m)); cpyum(m,base[i]);
333: }
334:
335: v = W_UMALLOC(n); cpyum(f,v);
336: DEG(w) = 1; COEF(w)[0] = 0; COEF(w)[1] = _onesf();
337: x = W_UMALLOC(1); DEG(x) = 1; COEF(x)[0] = 0; COEF(x)[1] = _onesf();
338: t = W_UMALLOC(n); s = W_UMALLOC(n); u = W_UMALLOC(n); g = W_UMALLOC(n);
339:
340: for ( j = 0, d = 1; 2*d <= DEG(v); d++ ) {
341: for ( DEG(t) = -1, i = 0; i <= DEG(w); i++ )
342: if ( COEF(w)[i] ) {
343: mulssfum(base[i],COEF(w)[i],s);
344: addsfum(s,t,u); cpyum(u,t);
345: }
346: cpyum(t,w); cpyum(v,s); subsfum(w,x,t);
347: gcdsfum(s,t,g);
348: if ( DEG(g) >= 1 ) {
349: berlekampsf(g,d,base,r+j); j += DEG(g)/d;
350: divsfum(v,g,q); cpyum(q,v);
351: DEG(w) = divsfum(w,v,q);
352: for ( i = 0; i < DEG(v); i++ )
353: DEG(base[i]) = divsfum(base[i],v,q);
354: }
355: }
356: if ( DEG(v) ) {
357: r[j] = UMALLOC(DEG(v)); cpyum(v,r[j]); j++;
358: }
359: r[j] = 0;
360: }
361:
362: int berlekampsf(p,df,tab,r)
363: UM p;
364: int df;
365: UM *tab,*r;
366: {
367: int n,i,j,k,nf,d,nr;
368: int **mat;
369: int *ind;
370: UM mp,w,q,gcd,w1,w2;
371: UM *u;
372: int *root;
373:
374: n = DEG(p);
375: ind = ALLOCA(n*sizeof(int));
376: make_qmatsf(p,tab,&mat);
377: nullsf(mat,n,ind);
378: for ( i = 0, d = 0; i < n; i++ )
379: if ( ind[i] )
380: d++;
381: if ( d == 1 ) {
382: r[0] = UMALLOC(n); cpyum(p,r[0]); return 1;
383: }
384: u = ALLOCA(d*sizeof(UM *));
385: r[0] = UMALLOC(n); cpyum(p,r[0]);
386: null_to_solsf(mat,ind,n,u);
387: root = ALLOCA(d*sizeof(int));
388: w = W_UMALLOC(n); mp = W_UMALLOC(d);
389: w1 = W_UMALLOC(n); w2 = W_UMALLOC(n);
390: for ( i = 1, nf = 1; i < d; i++ ) {
391: minipolysf(u[i],p,mp);
392: nr = find_rootsf(mp,root);
393: for ( j = 0; j < nf; j++ ) {
394: if ( DEG(r[j]) == df )
395: continue;
396: for ( k = 0; k < nr; k++ ) {
397: cpyum(u[i],w1); cpyum(r[j],w2);
398: COEF(w1)[0] = _chsgnsf(root[k]);
399: gcdsfum(w1,w2,w);
400: if ( DEG(w) > 0 && DEG(w) < DEG(r[j]) ) {
401: gcd = UMALLOC(DEG(w));
402: q = UMALLOC(DEG(r[j])-DEG(w));
403: cpyum(w,gcd); divsfum(r[j],w,q);
404: r[j] = q; r[nf++] = gcd;
405: }
406: if ( nf == d )
407: return d;
408: }
409: }
410: }
411: }
412:
413: void minipolysf(f,p,mp)
414: UM f,p,mp;
415: {
416: struct p_pair *list,*l,*l1,*lprev;
417: int n,d;
418: UM u,p0,p1,np0,np1,q,w;
419:
420: list = (struct p_pair *)MALLOC(sizeof(struct p_pair));
421: list->p0 = u = W_UMALLOC(0); DEG(u) = 0; COEF(u)[0] = _onesf();
422: list->p1 = W_UMALLOC(0); cpyum(list->p0,list->p1);
423: list->next = 0;
424: n = DEG(p); w = UMALLOC(2*n);
425: p0 = UMALLOC(2*n); cpyum(list->p0,p0);
426: p1 = UMALLOC(2*n); cpyum(list->p1,p1);
427: q = W_UMALLOC(2*n);
428: while ( 1 ) {
429: COEF(p0)[DEG(p0)] = 0; DEG(p0)++; COEF(p0)[DEG(p0)] = _onesf();
430: mulsfum(f,p1,w); DEG(w) = divsfum(w,p,q); cpyum(w,p1);
431: np0 = UMALLOC(n); np1 = UMALLOC(n);
432: lnfsf(n,p0,p1,list,np0,np1);
433: if ( DEG(np1) < 0 ) {
434: cpyum(np0,mp); return;
435: } else {
436: l1 = (struct p_pair *)MALLOC(sizeof(struct p_pair));
437: l1->p0 = np0; l1->p1 = np1;
438: for ( l = list, lprev = 0, d = DEG(np1);
439: l && (DEG(l->p1) > d); lprev = l, l = l->next );
440: if ( lprev ) {
441: lprev->next = l1; l1->next = l;
442: } else {
443: l1->next = list; list = l1;
444: }
445: }
446: }
447: }
448:
449: void lnfsf(n,p0,p1,list,np0,np1)
450: int n;
451: UM p0,p1;
452: struct p_pair *list;
453: UM np0,np1;
454: {
455: int inv,h,d1;
456: UM t0,t1,s0,s1;
457: struct p_pair *l;
458:
459: cpyum(p0,np0); cpyum(p1,np1);
460: t0 = W_UMALLOC(n); t1 = W_UMALLOC(n);
461: s0 = W_UMALLOC(n); s1 = W_UMALLOC(n);
462: for ( l = list; l; l = l->next ) {
463: d1 = DEG(np1);
464: if ( d1 == DEG(l->p1) ) {
465: h = _divsf(COEF(np1)[d1],_chsgnsf(COEF(l->p1)[d1]));
466: mulssfum(l->p0,h,t0); addsfum(np0,t0,s0); cpyum(s0,np0);
467: mulssfum(l->p1,h,t1); addsfum(np1,t1,s1); cpyum(s1,np1);
468: }
469: }
470: }
471:
472: int find_rootsf(p,root)
473: UM p;
474: int *root;
475: {
476: UM *r;
477: int i,j,n;
478:
479: n = DEG(p);
480: r = ALLOCA((DEG(p))*sizeof(UM));
481: canzassf(p,1,r);
482: for ( i = 0; i < n; i++ )
483: root[i] = _chsgnsf(COEF(r[i])[0]);
484: return n;
485: }
486:
487: void canzassf(f,d,r)
488: UM f,*r;
489: int d;
490: {
491: UM t,s,u,w,g,o;
492: N n1,n2,n3,n4,n5;
493: UM *b;
1.2 noro 494: int n,m,i,q,ed;
1.1 noro 495:
496: if ( DEG(f) == d ) {
497: r[0] = UMALLOC(d); cpyum(f,r[0]);
498: return;
499: } else {
500: n = DEG(f); b = (UM *)ALLOCA(n*sizeof(UM));
501: bzero((char *)b,n*sizeof(UM));
502:
503: t = W_UMALLOC(2*d);
504: s = W_UMALLOC(DEG(f)); u = W_UMALLOC(DEG(f));
505: w = W_UMALLOC(DEG(f)); g = W_UMALLOC(DEG(f));
506: o = W_UMALLOC(0); DEG(o) = 0; COEF(o)[0] = _onesf();
507: q = field_order_sf();
1.2 noro 508: if ( q % 2 ) {
509: STON(q,n1); pwrn(n1,d,&n2); subn(n2,ONEN,&n3);
510: STON(2,n4); divsn(n3,n4,&n5);
511: } else
512: ed = d*extdeg_sf();
1.1 noro 513: while ( 1 ) {
1.2 noro 514: randsfum(2*d,t);
515: if ( q % 2 ) {
516: spwrsfum(f,t,n5,s); subsfum(s,o,u);
517: } else
518: tracemodsfum(f,t,ed,u);
519: cpyum(f,w);
520: gcdsfum(w,u,g);
1.1 noro 521: if ( (DEG(g) >= 1) && (DEG(g) < DEG(f)) ) {
522: canzassf(g,d,r);
523: cpyum(f,w); divsfum(w,g,s);
524: canzassf(s,d,r+DEG(g)/d);
525: return;
526: }
527: }
528: }
529: }
530:
1.3 ! noro 531: /* Hensel related functions */
! 532:
! 533: int sfberle(VL,P,int,GFS *,DCP *);
! 534: void sfgcdgen(P,ML,ML *);
! 535: void sfhenmain(LUM,ML,ML,ML *);
! 536: void ptosflum(int,P,LUM);
! 537:
! 538: /* f = f(x,y) */
! 539:
! 540: void sfhensel(count,f,x,listp)
! 541: int count;
! 542: P f;
! 543: V x;
! 544: ML *listp;
! 545: {
! 546: int i,j;
! 547: int fn,n,bound;
! 548: int *p;
! 549: int **pp;
! 550: ML blist,clist,rlist;
! 551: UM *b;
! 552: LUM fl,tl;
! 553: LUM *l;
! 554: VL vl,nvl;
! 555: V y;
! 556: int dx,dy;
! 557: GFS ev;
! 558: P f1,g,g0,t,yev,c;
! 559: DCP dc;
! 560: LUM gl;
! 561:
! 562: clctv(CO,f,&vl);
! 563: if ( vl->v != x ) {
! 564: reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1);
! 565: vl = nvl; f = f1;
! 566: }
! 567: y = vl->next->v;
! 568: dx = getdeg(x,f);
! 569: dy = getdeg(y,f);
! 570: if ( dx == 1 ) {
! 571: *listp = blist = MLALLOC(1); blist->n = 1; blist->c[0] = 0;
! 572: return;
! 573: }
! 574: fn = sfberle(vl,f,count,&ev,&dc);
! 575: if ( fn <= 1 ) {
! 576: /* fn == 0 => short of evaluation points */
! 577: *listp = blist = MLALLOC(1); blist->n = fn; blist->c[0] = 0;
! 578: return;
! 579: }
! 580: /* pass the the leading coeff. to the first element */
! 581: c = dc->c; dc = NEXT(dc);
! 582: mulp(vl,dc->c,c,&t); dc->c = t;
! 583: blist = MLALLOC(n);
! 584: blist->n = fn;
! 585: for ( i = 0; i < fn; i++, dc = NEXT(dc) ) {
! 586: blist->c[i] = W_UMALLOC(UDEG(dc->c));
! 587: ptosfum(dc->c,blist->c[i]);
! 588: }
! 589: /* f(x,y) -> g = f(x,y+ev) */
! 590: MKV(y,t); addp(vl,t,(P)ev,&yev);
! 591: substp(vl,f,y,yev,&g);
! 592: substp(vl,g,y,0,&g0);
! 593:
! 594: sfgcdgen(g0,blist,&clist);
! 595: blist->bound = clist->bound = dy;
! 596: W_LUMALLOC(dx,bound,gl);
! 597: ptosflum(bound,g,gl);
! 598: sfhenmain(gl,blist,clist,listp);
! 599: }
! 600:
! 601: /* main variable of f = x */
! 602:
! 603: int sfberle(vl,f,count,ev,dcp)
! 604: VL vl;
! 605: P f;
! 606: int count;
! 607: GFS *ev;
! 608: DCP *dcp;
! 609: {
! 610: UM wf,wf1,wf2,wfs,gcd;
! 611: ML flist;
! 612: int fn,fn1,n;
! 613: GFS m,fm;
! 614: DCP dc,dct,dc0;
! 615: VL nvl;
! 616: V x,y;
! 617: P g,lc,lc0,f0;
! 618: int j,q1,index,i;
! 619:
! 620: clctv(vl,f,&nvl); vl = nvl;
! 621: x = vl->v; y = vl->next->v;
! 622: simp_ff(f,&g); g = f;
! 623: n = QTOS(DEG(DC(f)));
! 624: wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n);
! 625: wfs = W_UMALLOC(n); gcd = W_UMALLOC(n);
! 626: q1 = field_order_sf()-1;
! 627: lc = DC(f)->c;
! 628: for ( j = 0, fn = n + 1, index = 0;
! 629: index < q1 && j < count && fn > 1; ) {
! 630: MKGFS(index,m);
! 631: substp(vl,lc,y,(P)m,&lc0);
! 632: if ( lc0 ) {
! 633: substp(vl,f,y,(P)m,&f0);
! 634: ptosfum(m,f,wf); cpyum(wf,wf1);
! 635: diffsfum(m,wf1,wf2); gcdsfum(m,wf1,wf2,gcd);
! 636: if ( DEG(gcd) == 0 ) {
! 637: fctrsf(f0,&dc);
! 638: for ( dct = NEXT(dc), i = 0; dct; dct = NEXT(dct), i++ );
! 639: if ( i < fn ) {
! 640: dc0 = dc; fn = i; fm = m;
! 641: }
! 642: j++;
! 643: }
! 644: }
! 645: }
! 646: if ( index == q1 )
! 647: return 0;
! 648: else if ( fn == 1 )
! 649: return 1;
! 650: else {
! 651: *dcp = dc0;
! 652: *ev = fm;
! 653: return fn;
! 654: }
! 655: }
! 656:
! 657: void sfgcdgen(f,blist,clistp)
! 658: P f;
! 659: ML blist,*clistp;
! 660: {
! 661: int i;
! 662: int n,d,np;
! 663: UM wf,wm,wx,wy,wu,wv,wa,wb,wg,q,tum;
! 664: UM *in,*out;
! 665: ML clist;
! 666:
! 667: n = UDEG(f); np = blist->n;
! 668: d = 2*n;
! 669: q = W_UMALLOC(d); wf = W_UMALLOC(d);
! 670: wm = W_UMALLOC(d); wx = W_UMALLOC(d);
! 671: wy = W_UMALLOC(d); wu = W_UMALLOC(d);
! 672: wv = W_UMALLOC(d); wg = W_UMALLOC(d);
! 673: wa = W_UMALLOC(d); wb = W_UMALLOC(d);
! 674: ptosfum(f,wf); DEG(wg) = 0; COEF(wg)[0] = _onesf();
! 675: *clistp = clist = MLALLOC(np); clist->n = np;
! 676: for ( i = 0, in = (UM *)blist->c, out = (UM *)clist->c; i < np; i++ ) {
! 677: divsfum(wf,in[i],q); tum = wf; wf = q; q = tum;
! 678: cpyum(wf,wx); cpyum(in[i],wy);
! 679: eucsfum(wx,wy,wa,wb); mulsfum(wa,wg,wm);
! 680: DEG(wm) = divsfum(wm,in[i],q); out[i] = UMALLOC(DEG(wm));
! 681: cpyum(wm,out[i]); mulsfum(q,wf,wu);
! 682: mulsfum(wg,wb,wv); addsfum(wu,wv,wg);
! 683: }
! 684: }
! 685:
! 686: /*
! 687: sfhenmain(fl,bqlist,cqlist,listp)
! 688: */
! 689:
! 690: void sfhenmain(f,bqlist,cqlist,listp)
! 691: LUM f;
! 692: ML bqlist,cqlist,*listp;
! 693: {
! 694: int i,j,k;
! 695: int *px,*py;
! 696: int **pp,**pp1;
! 697: int n,np,bound,dr,tmp;
! 698: UM wt,wq0,wq,wr,wm,wm0,wa,q;
! 699: LUM wb0,wb1,tlum;
! 700: UM *b,*c;
! 701: LUM *l;
! 702: ML list;
! 703:
! 704: n = DEG(f); np = bqlist->n; bound = bqlist->bound;
! 705: *listp = list = MLALLOC(n);
! 706: list->n = np; list->bound = bound;
! 707: W_LUMALLOC(n,bound,wb0); W_LUMALLOC(n,bound,wb1);
! 708: wt = W_UMALLOC(n); wq0 = W_UMALLOC(n); wq = W_UMALLOC(n);
! 709: wr = W_UMALLOC(n); wm = W_UMALLOC(2*n); wm0 = W_UMALLOC(2*n);
! 710: wa = W_UMALLOC(2*n); q = W_UMALLOC(2*n);
! 711: b = (UM *)bqlist->c; c = (UM *)cqlist->c; l = (LUM *)list->c;
! 712: for ( i = 0; i < np; i++ ) {
! 713: l[i] = LUMALLOC(DEG(b[i]),bound);
! 714: for ( j = DEG(b[i]), pp = COEF(l[i]), px = COEF(b[i]); j >= 0; j-- )
! 715: pp[j][0] = px[j];
! 716: }
! 717: for ( i = 1; i < bound; i++ ) {
! 718: mulsflum(i+1,l[0],l[1],wb0);
! 719: for ( j = 2; j < np; j++ ) {
! 720: mulsflum(i+1,l[j],wb0,wb1);
! 721: tlum = wb0; wb0 = wb1; wb1 = tlum;
! 722: }
! 723: for ( j = n, px = COEF(wt); j >= 0; j-- )
! 724: px[j] = 0;
! 725: for ( j = n, pp = COEF(f), pp1 = COEF(wb0); j >= 0; j-- )
! 726: COEF(wt)[j] = _subsf(pp[j][i],pp1[j][i]);
! 727: degum(wt,n);
! 728: for ( j = n, px = COEF(wq0); j >= 0; j-- )
! 729: px[j] = 0;
! 730: for ( j = 1; j < np; j++ ) {
! 731: mulsfum(wt,c[j],wm); dr = divsfum(wm,b[j],q);
! 732: for ( k = DEG(q), px = COEF(wq0), py = COEF(q); k >= 0; k-- )
! 733: px[k] = _addsf(px[k],py[k]);
! 734: for ( k = dr, pp = COEF(l[j]), px = COEF(wm); k >= 0; k-- )
! 735: pp[k][i] = px[k];
! 736: }
! 737: degum(wq0,n); mulsfum(wq0,b[0],wm);
! 738: mulsfum(wt,c[0],wm0); addsfum(wm,wm0,wa);
! 739: for ( j = DEG(wa), pp = COEF(l[0]), px = COEF(wa); j >= 0; j-- )
! 740: pp[j][i] = px[j];
! 741: for ( j = n, px = COEF(wq0); j >= 0; j-- )
! 742: px[j] = 0;
! 743: }
! 744: }
! 745:
! 746: void ptosflum(bound,f,fl)
! 747: int bound;
! 748: P f;
! 749: LUM fl;
! 750: {
! 751: DCP dc;
! 752: int **pp;
! 753: int d;
! 754: UM t;
! 755:
! 756: t = UMALLOC(bound);
! 757: for ( dc = DC(f), pp = COEF(fl); dc; dc = NEXT(dc) ) {
! 758: d = QTOS(DEG(dc));
! 759: ptosfum(COEF(dc),t);
! 760: bcopy(t->c,pp[d],(t->d+1)*sizeof(int));
! 761: }
! 762: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>