Annotation of OpenXM_contrib2/asir2000/engine/Hgfs.c, Revision 1.9
1.9 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.8 2001/06/25 10:01:28 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);
1.8 noro 16: void sfbmtop(int,BM,V,V,P *);
17: void pp_sfp(VL,P,P *);
18: void sfcsump(VL,P,P *);
19: void mulsfbmarray(int,BM,ML,int,int *,V,V,P *);
1.9 ! noro 20: void const_term(P,UM);
1.1 noro 21:
22: void fctrsf(p,dcp)
23: P p;
24: DCP *dcp;
25: {
26: int n,i,j,k;
27: DCP dc,dc0;
28: P lc;
29: P zp;
30: UM mp;
31: UM *tl;
32: struct oDUM *udc,*udc1;
33:
34: simp_ff(p,&zp); p = zp;
35: if ( !p ) {
36: *dcp = 0; return;
37: }
38: mp = W_UMALLOC(UDEG(p));
39: ptosfum(p,mp);
40: if ( (n = DEG(mp)) < 0 ) {
41: *dcp = 0; return;
42: } else if ( n == 0 ) {
43: NEWDC(dc); COEF(dc) = p; DEG(dc) = ONE;
44: NEXT(dc) = 0; *dcp = dc;
45: return;
46: }
47: lc = COEF(DC(p));
48: if ( !_isonesf(COEF(mp)[n]) ) {
49: monicsfum(mp);
50: }
51:
52: W_CALLOC(n+1,struct oDUM,udc);
53: gensqfrsfum(mp,udc);
54:
55: tl = (UM *)ALLOCA((n+1)*sizeof(UM));
56: W_CALLOC(DEG(mp)+1,struct oDUM,udc1);
57:
58: for ( i = 0,j = 0; udc[i].f; i++ )
59: if ( DEG(udc[i].f) == 1 ) {
60: udc1[j].f = udc[i].f; udc1[j].n = udc[i].n; j++;
61: } else {
62: bzero((char *)tl,(n+1)*sizeof(UM));
63: czsfum(udc[i].f,tl);
64: for ( k = 0; tl[k]; k++, j++ ) {
65: udc1[j].f = tl[k]; udc1[j].n = udc[i].n;
66: }
67: }
68: udc = udc1;
69: NEWDC(dc0); COEF(dc0) = lc; DEG(dc0) = ONE; dc = dc0;
70: for ( n = 0; udc[n].f; n++ ) {
71: NEWDC(NEXT(dc)); dc = NEXT(dc);
72: STOQ(udc[n].n,DEG(dc)); sfumtop(VR(p),udc[n].f,&COEF(dc));
73: }
74: NEXT(dc) = 0; *dcp = dc0;
75: }
76:
77: void gensqfrsfum(p,dc)
78: UM p;
79: struct oDUM *dc;
80: {
81: int n,i,j,d,mod;
82: UM t,s,g,f,f1,b;
83:
84: if ( (n = DEG(p)) == 1 ) {
85: dc[0].f = UMALLOC(DEG(p)); cpyum(p,dc[0].f); dc[0].n = 1;
86: return;
87: }
88: t = W_UMALLOC(n); s = W_UMALLOC(n); g = W_UMALLOC(n);
89: f = W_UMALLOC(n); f1 = W_UMALLOC(n); b = W_UMALLOC(n);
90: diffsfum(p,t); cpyum(p,s); gcdsfum(t,s,g);
91: if ( !DEG(g) ) {
92: dc[0].f = UMALLOC(DEG(p)); cpyum(p,dc[0].f); dc[0].n = 1;
93: return;
94: }
95: cpyum(p,b); cpyum(p,t); divsfum(t,g,f);
96: for ( i = 0, d = 0; DEG(f); i++ ) {
97: while ( 1 ) {
98: cpyum(b,t);
99: if ( divsfum(t,f,s) >= 0 )
100: break;
101: else {
102: cpyum(s,b); d++;
103: }
104: }
105: cpyum(b,t); cpyum(f,s); gcdsfum(t,s,f1);
106: divsfum(f,f1,s); cpyum(f1,f);
107: dc[i].f = UMALLOC(DEG(s)); cpyum(s,dc[i].f); dc[i].n = d;
108: }
109: mod = characteristic_sf();
110: if ( DEG(b) > 0 ) {
111: d = 1;
112: while ( 1 ) {
113: cpyum(b,t);
114: for ( j = DEG(t); j >= 0; j-- )
115: if ( COEF(t)[j] && (j % mod) )
116: break;
117: if ( j >= 0 )
118: break;
119: else {
120: DEG(s) = DEG(t)/mod;
121: for ( j = 0; j <= DEG(t); j++ )
122: COEF(s)[j] = COEF(t)[j*mod];
123: cpyum(s,b); d *= mod;
124: }
125: }
126: gensqfrsfum(b,dc+i);
127: for ( j = i; dc[j].f; j++ )
128: dc[j].n *= d;
129: }
130: }
131:
132: void randsfum(d,p)
133: int d;
134: UM p;
135: {
136: int i;
137:
1.2 noro 138: for ( i = 0; i < d; i++ )
1.1 noro 139: COEF(p)[i] = _randomsf();
1.2 noro 140: for ( i = d-1; i >= 0 && !COEF(p)[i]; i-- );
141: p->d = i;
1.1 noro 142: }
143:
144: void pwrmodsfum(p,e,f,pr)
145: int e;
146: UM p,f,pr;
147: {
148: UM wt,ws,q;
149:
150: if ( e == 0 ) {
151: DEG(pr) = 0; COEF(pr)[0] = _onesf();
152: } else if ( DEG(p) < 0 )
153: DEG(pr) = -1;
154: else if ( e == 1 ) {
155: q = W_UMALLOC(DEG(p)); cpyum(p,pr);
156: DEG(pr) = divsfum(pr,f,q);
157: } else if ( DEG(p) == 0 ) {
158: DEG(pr) = 0; COEF(pr)[0] = _pwrsf(COEF(p)[0],e);
159: } else {
160: wt = W_UMALLOC(2*DEG(f)); ws = W_UMALLOC(2*DEG(f));
161: q = W_UMALLOC(2*DEG(f));
162: pwrmodsfum(p,e/2,f,wt);
163: if ( !(e%2) ) {
164: mulsfum(wt,wt,pr); DEG(pr) = divsfum(pr,f,q);
165: } else {
166: mulsfum(wt,wt,ws);
167: DEG(ws) = divsfum(ws,f,q);
168: mulsfum(ws,p,pr);
169: DEG(pr) = divsfum(pr,f,q);
170: }
171: }
172: }
173:
1.2 noro 174: void spwrsfum(m,f,e,r)
1.1 noro 175: UM f,m,r;
176: N e;
177: {
178: UM t,s,q;
179: N e1;
180: int a;
181:
182: if ( !e ) {
183: DEG(r) = 0; COEF(r)[0] = _onesf();
184: } else if ( UNIN(e) )
185: cpyum(f,r);
186: else {
187: a = divin(e,2,&e1);
1.2 noro 188: t = W_UMALLOC(2*DEG(m)); spwrsfum(m,f,e1,t);
1.1 noro 189: s = W_UMALLOC(2*DEG(m)); q = W_UMALLOC(2*DEG(m));
190: mulsfum(t,t,s); DEG(s) = divsfum(s,m,q);
191: if ( a ) {
192: mulsfum(s,f,t); DEG(t) = divsfum(t,m,q); cpyum(t,r);
193: } else
194: cpyum(s,r);
195: }
196: }
197:
1.2 noro 198: void tracemodsfum(m,f,e,r)
199: UM f,m,r;
200: int e;
201: {
202: UM t,s,q,u;
203: int i;
204:
205: q = W_UMALLOC(2*DEG(m)+DEG(f)); /* XXX */
206: t = W_UMALLOC(2*DEG(m));
207: s = W_UMALLOC(2*DEG(m));
208: u = W_UMALLOC(2*DEG(m));
209: DEG(f) = divsfum(f,m,q);
210: cpyum(f,s);
211: cpyum(f,t);
212: for ( i = 1; i < e; i++ ) {
213: mulsfum(t,t,u);
214: DEG(u) = divsfum(u,m,q); cpyum(u,t);
215: addsfum(t,s,u); cpyum(u,s);
216: }
217: cpyum(s,r);
218: }
219:
1.1 noro 220: void make_qmatsf(p,tab,mp)
221: UM p;
222: UM *tab;
223: int ***mp;
224: {
225: int n,i,j;
226: int *c;
227: UM q,r;
228: int **mat;
229: int one;
230:
231: n = DEG(p);
232: *mp = mat = almat(n,n);
233: for ( j = 0; j < n; j++ ) {
234: r = W_UMALLOC(DEG(tab[j])); q = W_UMALLOC(DEG(tab[j]));
235: cpyum(tab[j],r); DEG(r) = divsfum(r,p,q);
236: for ( i = 0, c = COEF(r); i <= DEG(r); i++ )
237: mat[i][j] = c[i];
238: }
239: one = _onesf();
240: for ( i = 0; i < n; i++ )
241: mat[i][i] = _subsf(mat[i][i],one);
242: }
243:
244: void nullsf(mat,n,ind)
245: int **mat;
246: int *ind;
247: int n;
248: {
249: int i,j,l,s,h,inv;
250: int *t,*u;
251:
252: bzero((char *)ind,n*sizeof(int));
253: ind[0] = 0;
254: for ( i = j = 0; j < n; i++, j++ ) {
255: for ( ; j < n; j++ ) {
256: for ( l = i; l < n; l++ )
257: if ( mat[l][j] )
258: break;
259: if ( l < n ) {
260: t = mat[i]; mat[i] = mat[l]; mat[l] = t; break;
261: } else
262: ind[j] = 1;
263: }
264: if ( j == n )
265: break;
266: inv = _invsf(mat[i][j]);
267: for ( s = j, t = mat[i]; s < n; s++ )
268: t[s] = _mulsf(t[s],inv);
269: for ( l = 0; l < n; l++ ) {
270: if ( l == i )
271: continue;
272: u = mat[l]; h = _chsgnsf(u[j]);
273: for ( s = j; s < n; s++ )
274: u[s] = _addsf(_mulsf(h,t[s]),u[s]);
275: }
276: }
277: }
278:
279: void null_to_solsf(mat,ind,n,r)
280: int **mat;
281: int *ind;
282: int n;
283: UM *r;
284: {
285: int i,j,k,l;
286: int *c;
287: UM w;
288:
289: for ( i = 0, l = 0; i < n; i++ ) {
290: if ( !ind[i] )
291: continue;
292: w = UMALLOC(n);
293: for ( j = k = 0, c = COEF(w); j < n; j++ )
294: if ( ind[j] )
295: c[j] = 0;
296: else
297: c[j] = mat[k++][i];
298: c[i] = _chsgnsf(_onesf());
299: for ( j = n; j >= 0; j-- )
300: if ( c[j] )
301: break;
302: DEG(w) = j;
303: r[l++] = w;
304: }
305: }
306: /*
307: make_qmatsf(p,tab,mp)
308: nullsf(mat,n,ind)
309: null_to_solsf(ind,n,r)
310: */
311:
312: void czsfum(f,r)
313: UM f,*r;
314: {
315: int i,j;
316: int d,n,ord;
317: UM s,t,u,v,w,g,x,m,q;
318: UM *base;
319:
320: n = DEG(f); base = (UM *)ALLOCA(n*sizeof(UM));
321: bzero((char *)base,n*sizeof(UM));
322:
323: w = W_UMALLOC(2*n); q = W_UMALLOC(2*n); m = W_UMALLOC(2*n);
324:
325: base[0] = W_UMALLOC(0); DEG(base[0]) = 0; COEF(base[0])[0] = _onesf();
326:
327: t = W_UMALLOC(1); DEG(t) = 1; COEF(t)[0] = 0; COEF(t)[1] = _onesf();
328:
329: ord = field_order_sf();
330: pwrmodsfum(t,ord,f,w);
331: base[1] = W_UMALLOC(DEG(w));
332: cpyum(w,base[1]);
333:
334: for ( i = 2; i < n; i++ ) {
335: mulsfum(base[i-1],base[1],m);
336: DEG(m) = divsfum(m,f,q);
337: base[i] = W_UMALLOC(DEG(m)); cpyum(m,base[i]);
338: }
339:
340: v = W_UMALLOC(n); cpyum(f,v);
341: DEG(w) = 1; COEF(w)[0] = 0; COEF(w)[1] = _onesf();
342: x = W_UMALLOC(1); DEG(x) = 1; COEF(x)[0] = 0; COEF(x)[1] = _onesf();
343: t = W_UMALLOC(n); s = W_UMALLOC(n); u = W_UMALLOC(n); g = W_UMALLOC(n);
344:
345: for ( j = 0, d = 1; 2*d <= DEG(v); d++ ) {
346: for ( DEG(t) = -1, i = 0; i <= DEG(w); i++ )
347: if ( COEF(w)[i] ) {
348: mulssfum(base[i],COEF(w)[i],s);
349: addsfum(s,t,u); cpyum(u,t);
350: }
351: cpyum(t,w); cpyum(v,s); subsfum(w,x,t);
352: gcdsfum(s,t,g);
353: if ( DEG(g) >= 1 ) {
354: berlekampsf(g,d,base,r+j); j += DEG(g)/d;
355: divsfum(v,g,q); cpyum(q,v);
356: DEG(w) = divsfum(w,v,q);
357: for ( i = 0; i < DEG(v); i++ )
358: DEG(base[i]) = divsfum(base[i],v,q);
359: }
360: }
361: if ( DEG(v) ) {
362: r[j] = UMALLOC(DEG(v)); cpyum(v,r[j]); j++;
363: }
364: r[j] = 0;
365: }
366:
367: int berlekampsf(p,df,tab,r)
368: UM p;
369: int df;
370: UM *tab,*r;
371: {
372: int n,i,j,k,nf,d,nr;
373: int **mat;
374: int *ind;
375: UM mp,w,q,gcd,w1,w2;
376: UM *u;
377: int *root;
378:
379: n = DEG(p);
380: ind = ALLOCA(n*sizeof(int));
381: make_qmatsf(p,tab,&mat);
382: nullsf(mat,n,ind);
383: for ( i = 0, d = 0; i < n; i++ )
384: if ( ind[i] )
385: d++;
386: if ( d == 1 ) {
387: r[0] = UMALLOC(n); cpyum(p,r[0]); return 1;
388: }
389: u = ALLOCA(d*sizeof(UM *));
390: r[0] = UMALLOC(n); cpyum(p,r[0]);
391: null_to_solsf(mat,ind,n,u);
392: root = ALLOCA(d*sizeof(int));
393: w = W_UMALLOC(n); mp = W_UMALLOC(d);
394: w1 = W_UMALLOC(n); w2 = W_UMALLOC(n);
395: for ( i = 1, nf = 1; i < d; i++ ) {
396: minipolysf(u[i],p,mp);
397: nr = find_rootsf(mp,root);
398: for ( j = 0; j < nf; j++ ) {
399: if ( DEG(r[j]) == df )
400: continue;
401: for ( k = 0; k < nr; k++ ) {
402: cpyum(u[i],w1); cpyum(r[j],w2);
403: COEF(w1)[0] = _chsgnsf(root[k]);
404: gcdsfum(w1,w2,w);
405: if ( DEG(w) > 0 && DEG(w) < DEG(r[j]) ) {
406: gcd = UMALLOC(DEG(w));
407: q = UMALLOC(DEG(r[j])-DEG(w));
408: cpyum(w,gcd); divsfum(r[j],w,q);
409: r[j] = q; r[nf++] = gcd;
410: }
411: if ( nf == d )
412: return d;
413: }
414: }
415: }
416: }
417:
418: void minipolysf(f,p,mp)
419: UM f,p,mp;
420: {
421: struct p_pair *list,*l,*l1,*lprev;
422: int n,d;
423: UM u,p0,p1,np0,np1,q,w;
424:
425: list = (struct p_pair *)MALLOC(sizeof(struct p_pair));
426: list->p0 = u = W_UMALLOC(0); DEG(u) = 0; COEF(u)[0] = _onesf();
427: list->p1 = W_UMALLOC(0); cpyum(list->p0,list->p1);
428: list->next = 0;
429: n = DEG(p); w = UMALLOC(2*n);
430: p0 = UMALLOC(2*n); cpyum(list->p0,p0);
431: p1 = UMALLOC(2*n); cpyum(list->p1,p1);
432: q = W_UMALLOC(2*n);
433: while ( 1 ) {
434: COEF(p0)[DEG(p0)] = 0; DEG(p0)++; COEF(p0)[DEG(p0)] = _onesf();
435: mulsfum(f,p1,w); DEG(w) = divsfum(w,p,q); cpyum(w,p1);
436: np0 = UMALLOC(n); np1 = UMALLOC(n);
437: lnfsf(n,p0,p1,list,np0,np1);
438: if ( DEG(np1) < 0 ) {
439: cpyum(np0,mp); return;
440: } else {
441: l1 = (struct p_pair *)MALLOC(sizeof(struct p_pair));
442: l1->p0 = np0; l1->p1 = np1;
443: for ( l = list, lprev = 0, d = DEG(np1);
444: l && (DEG(l->p1) > d); lprev = l, l = l->next );
445: if ( lprev ) {
446: lprev->next = l1; l1->next = l;
447: } else {
448: l1->next = list; list = l1;
449: }
450: }
451: }
452: }
453:
454: void lnfsf(n,p0,p1,list,np0,np1)
455: int n;
456: UM p0,p1;
457: struct p_pair *list;
458: UM np0,np1;
459: {
460: int inv,h,d1;
461: UM t0,t1,s0,s1;
462: struct p_pair *l;
463:
464: cpyum(p0,np0); cpyum(p1,np1);
465: t0 = W_UMALLOC(n); t1 = W_UMALLOC(n);
466: s0 = W_UMALLOC(n); s1 = W_UMALLOC(n);
467: for ( l = list; l; l = l->next ) {
468: d1 = DEG(np1);
469: if ( d1 == DEG(l->p1) ) {
470: h = _divsf(COEF(np1)[d1],_chsgnsf(COEF(l->p1)[d1]));
471: mulssfum(l->p0,h,t0); addsfum(np0,t0,s0); cpyum(s0,np0);
472: mulssfum(l->p1,h,t1); addsfum(np1,t1,s1); cpyum(s1,np1);
473: }
474: }
475: }
476:
477: int find_rootsf(p,root)
478: UM p;
479: int *root;
480: {
481: UM *r;
482: int i,j,n;
483:
484: n = DEG(p);
485: r = ALLOCA((DEG(p))*sizeof(UM));
486: canzassf(p,1,r);
487: for ( i = 0; i < n; i++ )
488: root[i] = _chsgnsf(COEF(r[i])[0]);
489: return n;
490: }
491:
492: void canzassf(f,d,r)
493: UM f,*r;
494: int d;
495: {
496: UM t,s,u,w,g,o;
497: N n1,n2,n3,n4,n5;
498: UM *b;
1.2 noro 499: int n,m,i,q,ed;
1.1 noro 500:
501: if ( DEG(f) == d ) {
502: r[0] = UMALLOC(d); cpyum(f,r[0]);
503: return;
504: } else {
505: n = DEG(f); b = (UM *)ALLOCA(n*sizeof(UM));
506: bzero((char *)b,n*sizeof(UM));
507:
508: t = W_UMALLOC(2*d);
509: s = W_UMALLOC(DEG(f)); u = W_UMALLOC(DEG(f));
510: w = W_UMALLOC(DEG(f)); g = W_UMALLOC(DEG(f));
511: o = W_UMALLOC(0); DEG(o) = 0; COEF(o)[0] = _onesf();
512: q = field_order_sf();
1.2 noro 513: if ( q % 2 ) {
514: STON(q,n1); pwrn(n1,d,&n2); subn(n2,ONEN,&n3);
515: STON(2,n4); divsn(n3,n4,&n5);
516: } else
517: ed = d*extdeg_sf();
1.1 noro 518: while ( 1 ) {
1.2 noro 519: randsfum(2*d,t);
520: if ( q % 2 ) {
521: spwrsfum(f,t,n5,s); subsfum(s,o,u);
522: } else
523: tracemodsfum(f,t,ed,u);
524: cpyum(f,w);
525: gcdsfum(w,u,g);
1.1 noro 526: if ( (DEG(g) >= 1) && (DEG(g) < DEG(f)) ) {
527: canzassf(g,d,r);
528: cpyum(f,w); divsfum(w,g,s);
529: canzassf(s,d,r+DEG(g)/d);
530: return;
531: }
532: }
533: }
534: }
535:
1.3 noro 536: /* Hensel related functions */
537:
538: int sfberle(VL,P,int,GFS *,DCP *);
539: void sfgcdgen(P,ML,ML *);
540: void sfhenmain(LUM,ML,ML,ML *);
541: void ptosflum(int,P,LUM);
1.5 noro 542: void sfhenmain2(BM,UM,UM,int,BM *);
543: void ptosfbm(int,P,BM);
1.3 noro 544:
545: /* f = f(x,y) */
546:
1.8 noro 547: void sfhensel(count,f,x,evp,sfp,listp)
1.3 noro 548: int count;
549: P f;
550: V x;
1.8 noro 551: GFS *evp;
552: P *sfp;
1.3 noro 553: ML *listp;
554: {
555: int i,j;
556: int fn,n,bound;
1.4 noro 557: ML rlist;
1.5 noro 558: BM fl;
1.3 noro 559: VL vl,nvl;
560: V y;
1.4 noro 561: int dx,dy,mev;
1.3 noro 562: GFS ev;
1.8 noro 563: P f1,t,yev,c,sf;
1.3 noro 564: DCP dc;
1.4 noro 565: UM w,w1,q,fm,hm;
566: UM *gm;
1.3 noro 567:
568: clctv(CO,f,&vl);
569: if ( vl->v != x ) {
570: reordvar(vl,x,&nvl); reorderp(nvl,vl,f,&f1);
571: vl = nvl; f = f1;
572: }
573: y = vl->next->v;
574: dx = getdeg(x,f);
575: dy = getdeg(y,f);
576: if ( dx == 1 ) {
1.4 noro 577: *listp = rlist = MLALLOC(1); rlist->n = 1; rlist->c[0] = 0;
1.3 noro 578: return;
579: }
580: fn = sfberle(vl,f,count,&ev,&dc);
581: if ( fn <= 1 ) {
582: /* fn == 0 => short of evaluation points */
1.4 noro 583: *listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0;
1.3 noro 584: return;
585: }
586: /* pass the the leading coeff. to the first element */
587: c = dc->c; dc = NEXT(dc);
588: mulp(vl,dc->c,c,&t); dc->c = t;
1.4 noro 589:
590: /* convert mod y-a factors into UM */
591: gm = (UM *)ALLOCA(fn*sizeof(UM));
1.3 noro 592: for ( i = 0; i < fn; i++, dc = NEXT(dc) ) {
1.4 noro 593: gm[i] = W_UMALLOC(UDEG(dc->c));
594: ptosfum(dc->c,gm[i]);
1.3 noro 595: }
1.4 noro 596:
597: bound = dy+1;
598: /* f(x,y) -> f(x,y+ev) */
1.5 noro 599: fl = BMALLOC(dx,bound);
600: ptosfbm(bound,f,fl);
601: shiftsfbm(bound,fl,FTOIF(CONT(ev)));
1.4 noro 602:
1.8 noro 603: /* sf = f(x+ev) */
604: sfbmtop(bound,fl,x,y,&sf);
605:
1.4 noro 606: /* fm = fl mod y */
607: fm = W_UMALLOC(dx);
1.5 noro 608: cpyum(COEF(fl)[0],fm);
1.4 noro 609: hm = W_UMALLOC(dx);
610:
611: q = W_UMALLOC(dx);
612: rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = bound;
1.7 noro 613: for ( i = 0; i < fn-1; i++ ) {
1.4 noro 614: fprintf(stderr,"%d\n",i);
615: /* fl = gm[i]*hm mod y */
616: divsfum(fm,gm[i],hm);
617: /* fl is replaced by the cofactor of gk mod y^bound */
618: /* rlist->c[i] = gk */
1.5 noro 619: sfhenmain2(fl,gm[i],hm,bound,(BM *)&rlist->c[i]);
1.4 noro 620: cpyum(hm,fm);
621: }
1.7 noro 622: /* finally, fl must be the lift of gm[fn-1] */
1.4 noro 623: rlist->c[i] = fl;
624:
1.8 noro 625: #if 0
1.4 noro 626: /* y -> y-a */
627: mev = _chsgnsf(FTOIF(CONT(ev)));
628: for ( i = 0; i < fn; i++ )
1.5 noro 629: shiftsfbm(bound,(BM)(rlist->c[i]),mev);
1.8 noro 630: #endif
631: *evp = ev;
632: *sfp = sf;
1.4 noro 633: *listp = rlist;
1.3 noro 634: }
635:
636: /* main variable of f = x */
637:
638: int sfberle(vl,f,count,ev,dcp)
639: VL vl;
640: P f;
641: int count;
642: GFS *ev;
643: DCP *dcp;
644: {
645: UM wf,wf1,wf2,wfs,gcd;
646: ML flist;
647: int fn,fn1,n;
648: GFS m,fm;
649: DCP dc,dct,dc0;
650: VL nvl;
651: V x,y;
652: P g,lc,lc0,f0;
653: int j,q1,index,i;
654:
655: clctv(vl,f,&nvl); vl = nvl;
656: x = vl->v; y = vl->next->v;
657: simp_ff(f,&g); g = f;
658: n = QTOS(DEG(DC(f)));
659: wf = W_UMALLOC(n); wf1 = W_UMALLOC(n); wf2 = W_UMALLOC(n);
660: wfs = W_UMALLOC(n); gcd = W_UMALLOC(n);
661: q1 = field_order_sf()-1;
662: lc = DC(f)->c;
663: for ( j = 0, fn = n + 1, index = 0;
1.4 noro 664: index < q1 && j < count && fn > 1; index++ ) {
1.3 noro 665: MKGFS(index,m);
666: substp(vl,lc,y,(P)m,&lc0);
667: if ( lc0 ) {
668: substp(vl,f,y,(P)m,&f0);
1.4 noro 669: ptosfum(f0,wf); cpyum(wf,wf1);
670: diffsfum(wf1,wf2); gcdsfum(wf1,wf2,gcd);
1.3 noro 671: if ( DEG(gcd) == 0 ) {
672: fctrsf(f0,&dc);
673: for ( dct = NEXT(dc), i = 0; dct; dct = NEXT(dct), i++ );
674: if ( i < fn ) {
675: dc0 = dc; fn = i; fm = m;
676: }
677: j++;
678: }
679: }
680: }
681: if ( index == q1 )
682: return 0;
683: else if ( fn == 1 )
684: return 1;
685: else {
686: *dcp = dc0;
687: *ev = fm;
688: return fn;
689: }
690: }
691:
692: void sfgcdgen(f,blist,clistp)
693: P f;
694: ML blist,*clistp;
695: {
696: int i;
697: int n,d,np;
698: UM wf,wm,wx,wy,wu,wv,wa,wb,wg,q,tum;
699: UM *in,*out;
700: ML clist;
701:
702: n = UDEG(f); np = blist->n;
703: d = 2*n;
704: q = W_UMALLOC(d); wf = W_UMALLOC(d);
705: wm = W_UMALLOC(d); wx = W_UMALLOC(d);
706: wy = W_UMALLOC(d); wu = W_UMALLOC(d);
707: wv = W_UMALLOC(d); wg = W_UMALLOC(d);
708: wa = W_UMALLOC(d); wb = W_UMALLOC(d);
709: ptosfum(f,wf); DEG(wg) = 0; COEF(wg)[0] = _onesf();
710: *clistp = clist = MLALLOC(np); clist->n = np;
711: for ( i = 0, in = (UM *)blist->c, out = (UM *)clist->c; i < np; i++ ) {
712: divsfum(wf,in[i],q); tum = wf; wf = q; q = tum;
713: cpyum(wf,wx); cpyum(in[i],wy);
714: eucsfum(wx,wy,wa,wb); mulsfum(wa,wg,wm);
715: DEG(wm) = divsfum(wm,in[i],q); out[i] = UMALLOC(DEG(wm));
716: cpyum(wm,out[i]); mulsfum(q,wf,wu);
717: mulsfum(wg,wb,wv); addsfum(wu,wv,wg);
718: }
719: }
720:
721: /*
722: sfhenmain(fl,bqlist,cqlist,listp)
723: */
724:
725: void sfhenmain(f,bqlist,cqlist,listp)
726: LUM f;
727: ML bqlist,cqlist,*listp;
728: {
729: int i,j,k;
730: int *px,*py;
731: int **pp,**pp1;
732: int n,np,bound,dr,tmp;
733: UM wt,wq0,wq,wr,wm,wm0,wa,q;
734: LUM wb0,wb1,tlum;
735: UM *b,*c;
736: LUM *l;
737: ML list;
738:
739: n = DEG(f); np = bqlist->n; bound = bqlist->bound;
740: *listp = list = MLALLOC(n);
741: list->n = np; list->bound = bound;
742: W_LUMALLOC(n,bound,wb0); W_LUMALLOC(n,bound,wb1);
743: wt = W_UMALLOC(n); wq0 = W_UMALLOC(n); wq = W_UMALLOC(n);
744: wr = W_UMALLOC(n); wm = W_UMALLOC(2*n); wm0 = W_UMALLOC(2*n);
745: wa = W_UMALLOC(2*n); q = W_UMALLOC(2*n);
746: b = (UM *)bqlist->c; c = (UM *)cqlist->c; l = (LUM *)list->c;
747: for ( i = 0; i < np; i++ ) {
748: l[i] = LUMALLOC(DEG(b[i]),bound);
749: for ( j = DEG(b[i]), pp = COEF(l[i]), px = COEF(b[i]); j >= 0; j-- )
750: pp[j][0] = px[j];
751: }
752: for ( i = 1; i < bound; i++ ) {
1.4 noro 753: fprintf(stderr,".");
754: /* at this point, f = l[0]*l[1]*...*l[np-1] mod y^i */
1.3 noro 755: mulsflum(i+1,l[0],l[1],wb0);
756: for ( j = 2; j < np; j++ ) {
757: mulsflum(i+1,l[j],wb0,wb1);
758: tlum = wb0; wb0 = wb1; wb1 = tlum;
759: }
1.5 noro 760: #if 0
1.4 noro 761: /* check */
762: for ( j = 0, pp = COEF(f), pp1 = COEF(wb0); j <= n; j++ )
763: for ( k = 0; k < i; k++ )
764: if ( pp[j][k] != pp1[j][k] )
765: error("henmain : cannot happen");
766: #endif
1.3 noro 767: for ( j = n, px = COEF(wt); j >= 0; j-- )
768: px[j] = 0;
769: for ( j = n, pp = COEF(f), pp1 = COEF(wb0); j >= 0; j-- )
770: COEF(wt)[j] = _subsf(pp[j][i],pp1[j][i]);
771: degum(wt,n);
772: for ( j = n, px = COEF(wq0); j >= 0; j-- )
773: px[j] = 0;
774: for ( j = 1; j < np; j++ ) {
775: mulsfum(wt,c[j],wm); dr = divsfum(wm,b[j],q);
776: for ( k = DEG(q), px = COEF(wq0), py = COEF(q); k >= 0; k-- )
777: px[k] = _addsf(px[k],py[k]);
778: for ( k = dr, pp = COEF(l[j]), px = COEF(wm); k >= 0; k-- )
779: pp[k][i] = px[k];
780: }
781: degum(wq0,n); mulsfum(wq0,b[0],wm);
782: mulsfum(wt,c[0],wm0); addsfum(wm,wm0,wa);
783: for ( j = DEG(wa), pp = COEF(l[0]), px = COEF(wa); j >= 0; j-- )
784: pp[j][i] = px[j];
785: for ( j = n, px = COEF(wq0); j >= 0; j-- )
786: px[j] = 0;
787: }
1.4 noro 788: fprintf(stderr,"\n");
789: }
790:
791: /* f = g0*h0 mod y -> f = gk*hk mod y^bound, f is replaced by hk */
792:
793: void sfhenmain2(f,g0,h0,bound,gp)
1.5 noro 794: BM f;
1.4 noro 795: UM g0,h0;
796: int bound;
1.5 noro 797: BM *gp;
1.4 noro 798: {
799: int i,j,k,l;
800: int *px,*py;
801: int **pp,**pp1;
802: int n,np,dr,tmp;
1.5 noro 803: UM wt,wa,wb,wq,wm,q,w1,w2,wh1,wg1,ws;
1.4 noro 804: UM wc,wd,we,wz;
1.5 noro 805: BM wb0,wb1;
1.4 noro 806: int ng,nh;
1.5 noro 807: BM fk,gk,hk;
1.4 noro 808:
1.8 noro 809: n = degsfbm(bound,f);
1.4 noro 810: ng = g0->d;
811: nh = h0->d;
812:
1.5 noro 813: W_BMALLOC(n,bound,wb0); W_BMALLOC(n,bound,wb1);
814: wt = W_UMALLOC(n); ws = W_UMALLOC(n);
815: wq = W_UMALLOC(n); q = W_UMALLOC(2*n);
1.4 noro 816: wg1 = W_UMALLOC(2*n); wh1 = W_UMALLOC(2*n);
1.5 noro 817:
1.4 noro 818: /* fk = gk*hk mod y^k */
1.8 noro 819: W_BMALLOC(n,bound,fk);
820: cpyum(COEF(f)[0],COEF(fk)[0]);
821: gk = BMALLOC(ng,bound);
822: cpyum(g0,COEF(gk)[0]);
1.5 noro 823: W_BMALLOC(nh,bound,hk);
824: cpyum(h0,COEF(hk)[0]);
1.4 noro 825:
1.5 noro 826: wc = W_UMALLOC(2*n); wd = W_UMALLOC(2*n);
827: we = W_UMALLOC(2*n); wz = W_UMALLOC(2*n);
1.4 noro 828:
829: /* compute wa,wb s.t. wa*g0+wb*h0 = 1 mod y */
830: w1 = W_UMALLOC(ng); cpyum(g0,w1);
831: w2 = W_UMALLOC(nh); cpyum(h0,w2);
832: wa = W_UMALLOC(2*n); wb = W_UMALLOC(2*n); /* XXX */
833: eucsfum(w1,w2,wa,wb);
834:
835: #if 0
836: mulsfum(wa,g0,wc); mulsfum(wb,h0,wd); addsfum(wc,wd,we);
837: if ( DEG(we) != 0 || COEF(we)[0] != _onesf() )
1.5 noro 838: error("henmain2 : cannot happen(euc)");
1.4 noro 839: #endif
840:
841: fprintf(stderr,"bound=%d\n",bound);
842: for ( k = 1; k < bound; k++ ) {
843: fprintf(stderr,".");
844:
845: /* at this point, f = gk*hk mod y^k */
846: #if 0
1.5 noro 847: for ( j = 0; j < k; j++ )
848: if ( !isequalum(COEF(f)[j],COEF(fk)[j]) )
849: error("henmain2 : cannot happen(history)");
1.4 noro 850: #endif
851:
852: /* clear wt */
853: bzero(COEF(wt),(n+1)*sizeof(int));
854:
855: /* wt = (f-gk*hk)/y^k */
1.5 noro 856: subsfum(COEF(f)[k],COEF(fk)[k],wt);
1.4 noro 857:
858: /* clear wq */
859: bzero(COEF(wq),(n+1)*sizeof(int));
860:
861: /* compute wf1,wg1 s.t. wh1*g0+wg1*h0 = wt */
862: mulsfum(wa,wt,wh1); DEG(wh1) = divsfum(wh1,h0,q);
863: mulsfum(wh1,g0,wc); subsfum(wt,wc,wd); DEG(wd) = divsfum(wd,h0,wg1);
864:
865: /* check */
866: #if 0
867: if ( DEG(wd) >= 0 || DEG(wg1) > ng )
1.5 noro 868: error("henmain2 : cannot happen(adj)");
1.4 noro 869:
870: mulsfum(wg1,h0,wc); mulsfum(wh1,g0,wd); addsfum(wc,wd,we);
871: subsfum(we,wt,wz);
872: if ( DEG(wz) >= 0 )
873: error("henmain2 : cannot happen");
874: #endif
875:
876: /* fk += ((wg1*hk+wh1*gk)*y^k+wg1*wh1*y^(2*k) mod y^bound */
877: /* wb0 = wh1*y^k */
1.5 noro 878: clearsfbm(bound,n,wb0);
879: DEG(wb0) = bound;
880: cpyum(wh1,COEF(wb0)[k]);
881:
1.4 noro 882: /* wb1 = gk*wb0 mod y^bound */
1.5 noro 883: clearsfbm(bound,n,wb1);
884: mulsfbm(bound,gk,wb0,wb1);
1.4 noro 885: /* fk += wb1 */
1.5 noro 886: addtosfbm(bound,wb1,fk);
1.4 noro 887:
888: /* wb0 = wg1*y^k */
1.5 noro 889: clearsfbm(bound,n,wb0);
890: DEG(wb0) = bound;
891: cpyum(wg1,COEF(wb0)[k]);
892:
1.4 noro 893: /* wb1 = hk*wb0 mod y^bound */
1.5 noro 894: clearsfbm(bound,n,wb1);
895: mulsfbm(bound,hk,wb0,wb1);
1.4 noro 896: /* fk += wb1 */
1.5 noro 897: addtosfbm(bound,wb1,fk);
1.4 noro 898:
899: /* fk += wg1*wh1*y^(2*k) mod y^bound */
900: if ( 2*k < bound ) {
1.5 noro 901: mulsfum(wg1,wh1,wt); addsfum(COEF(fk)[2*k],wt,ws);
902: cpyum(ws,COEF(fk)[2*k]);
1.4 noro 903: }
904:
905: /* gk += wg1*y^k, hk += wh1*y^k */
1.5 noro 906: cpyum(wg1,COEF(gk)[k]);
907: cpyum(wh1,COEF(hk)[k]);
1.4 noro 908: }
909: fprintf(stderr,"\n");
910: *gp = gk;
1.5 noro 911: DEG(f) = bound;
912: for ( i = 0; i < bound; i++ )
913: cpyum(COEF(hk)[i],COEF(f)[i]);
1.3 noro 914: }
915:
916: void ptosflum(bound,f,fl)
917: int bound;
918: P f;
919: LUM fl;
920: {
921: DCP dc;
922: int **pp;
923: int d;
924: UM t;
925:
926: t = UMALLOC(bound);
927: for ( dc = DC(f), pp = COEF(fl); dc; dc = NEXT(dc) ) {
928: d = QTOS(DEG(dc));
929: ptosfum(COEF(dc),t);
930: bcopy(t->c,pp[d],(t->d+1)*sizeof(int));
931: }
1.4 noro 932: }
933:
1.5 noro 934: /* fl->c[i] = coef_y(f,i) */
935:
936: void ptosfbm(bound,f,fl)
937: int bound;
938: P f;
939: BM fl;
940: {
941: DCP dc;
942: int d,i,n;
943: UM t;
944:
945: DEG(fl) = bound;
946: t = UMALLOC(bound);
947: for ( dc = DC(f); dc; dc = NEXT(dc) ) {
948: d = QTOS(DEG(dc));
949: ptosfum(COEF(dc),t);
950: for ( i = 0; i <= DEG(t); i++ )
951: COEF(COEF(fl)[i])[d] = COEF(t)[i];
952: }
1.8 noro 953: n = QTOS(DEG(DC(f)));
954: for ( i = 0; i < bound; i++ )
1.5 noro 955: degum(COEF(fl)[i],n);
956: }
957:
1.4 noro 958: /* x : main variable */
959:
960: void sflumtop(bound,fl,x,y,fp)
961: int bound;
962: LUM fl;
963: V x,y;
964: P *fp;
965: {
966: int i,j,n;
967: int **c;
968: UM w;
969: int *coef;
970: DCP dc,dct;
971:
972: n = fl->d;
973: c = fl->c;
974: w = W_UMALLOC(bound);
975: for ( i = 0, dc = 0; i <= n; i++ ) {
976: coef = c[i];
977: for ( j = bound-1; j >= 0 && coef[j] == 0; j-- );
978: if ( j < 0 )
979: continue;
980: DEG(w) = j; bcopy(coef,COEF(w),(j+1)*sizeof(int));
981: NEWDC(dct); STOQ(i,DEG(dct));
982: sfumtop(y,w,&COEF(dct)); NEXT(dct) = dc; dc = dct;
983: }
984: MKP(x,dc,*fp);
1.5 noro 985: }
986:
987: /* x : main variable */
988:
1.8 noro 989: void sfbmtop(bound,f,x,y,fp)
1.5 noro 990: int bound;
991: BM f;
992: V x,y;
993: P *fp;
994: {
995: UM *c;
1.8 noro 996: int i,j,d,a;
997: GFS b;
998: DCP dc0,dc,dct;
999:
1000: c = COEF(f);
1001: d = DEG(c[0]);
1002: for ( i = 1; i < bound; i++ )
1003: d = MAX(DEG(c[i]),d);
1004:
1005: dc0 = 0;
1006: for ( i = 0; i <= d; i++ ) {
1007: dc = 0;
1008: for ( j = 0; j < bound; j++ ) {
1009: if ( DEG(c[j]) >= i && (a = COEF(c[j])[i]) ) {
1010: NEWDC(dct);
1011: STOQ(j,DEG(dct));
1012: MKGFS(IFTOF(a),b);
1013: COEF(dct) = (P)b;
1014: NEXT(dct) = dc;
1015: dc = dct;
1016: }
1017: }
1018: if ( dc ) {
1019: NEWDC(dct);
1020: STOQ(i,DEG(dct));
1021: MKP(y,dc,COEF(dct));
1022: NEXT(dct) = dc0;
1023: dc0 = dct;
1024: }
1025: }
1026: if ( dc0 )
1027: MKP(x,dc0,*fp);
1028: else
1029: *fp = 0;
1030: }
1031:
1032: void sfdtest(P,ML,V,V,DCP *);
1033:
1.9 ! noro 1034: void sfbfctr(f,x,y,dcp)
1.8 noro 1035: P f;
1036: V x,y;
1037: DCP *dcp;
1038: {
1039: ML list;
1040: P sf;
1.9 ! noro 1041: GFS ev;
! 1042: DCP dc,dct;
! 1043: BM fl;
! 1044: int n,bound;
1.8 noro 1045:
1046: /* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */
1.9 ! noro 1047: sfhensel(5,f,x,&ev,&sf,&list);
! 1048: sfdtest(sf,list,x,y,&dc);
! 1049: n = getdeg(x,sf);
! 1050: bound = list->bound;
! 1051: W_BMALLOC(n,bound,fl);
! 1052: for ( dct = dc; dct; dct = NEXT(dct) ) {
! 1053: ptosfbm(bound,COEF(dct),fl);
! 1054: shiftsfbm(bound,fl,_chsgnsf(FTOIF(CONT(ev))));
! 1055: sfbmtop(bound,fl,x,y,&COEF(dct));
! 1056: }
! 1057: *dcp = dc;
1.8 noro 1058: }
1059:
1060: /* f = f(x,y) = list->c[0]*list->c[1]*... mod y^list->bound */
1061:
1062: void sfdtest(f,list,x,y,dcp)
1063: P f;
1064: ML list;
1065: V x,y;
1066: DCP *dcp;
1067: {
1068: int n,np,bound;
1069: int i,j,k;
1070: int *win;
1071: P g,lcg,factor,cofactor,lcyx;
1.9 ! noro 1072: P t,csum;
1.8 noro 1073: DCP dcf,dcf0,dc;
1074: BM *c;
1075: BM lcy;
1.9 ! noro 1076: UM lcg0;
1.8 noro 1077: ML wlist;
1078: struct oVL vl1,vl0;
1079: VL vl;
1080: int z;
1081:
1082: /* vl = [x,y] */
1083: vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0;
1084:
1.9 ! noro 1085: /* setup various structures and arrays */
1.8 noro 1086: n = UDEG(f); np = list->n; bound = list->bound; win = W_ALLOC(np+1);
1087: wlist = W_MLALLOC(np); wlist->n = list->n;
1088: wlist->bound = list->bound;
1089: c = (BM *)COEF(wlist);
1090: bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np));
1091:
1.9 ! noro 1092: lcg0 = W_UMALLOC(2*bound);
! 1093:
1.8 noro 1094: /* initialize g by f */
1.9 ! noro 1095: g = f;
! 1096:
! 1097: /* initialize lcg */
! 1098: mulp(vl,g,COEF(DC(g)),&lcg);
! 1099:
! 1100: /* initialize lcg0 */
! 1101: const_term(lcg,lcg0);
! 1102:
! 1103: /* initialize csum = lcg(1) */
! 1104: sfcsump(vl,lcg,&csum);
1.8 noro 1105:
1106: /* initialize lcy by LC(f) */
1107: W_BMALLOC(0,bound,lcy);
1.9 ! noro 1108: NEWDC(dc); COEF(dc) = COEF(DC(g)); DEG(dc) = 0;
1.8 noro 1109: NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc;
1110: ptosfbm(bound,lcyx,lcy);
1111:
1112: fprintf(stderr,"np = %d\n",np);
1113: for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) {
1114: if ( !(z % 1000) ) fprintf(stderr,".");
1.9 ! noro 1115: if ( sfdtestmain(vl,lcg,lcg0,lcy,csum,wlist,k,win,&factor,&cofactor) ) {
1.8 noro 1116: NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor;
1117: g = cofactor;
1118:
1119: /* update lcg */
1120: mulp(vl,g,COEF(DC(g)),&lcg);
1121:
1.9 ! noro 1122: /* update lcg0 */
! 1123: const_term(lcg,lcg0);
! 1124:
! 1125: /* update csum */
! 1126: sfcsump(vl,lcg,&csum);
! 1127:
1.8 noro 1128: /* update lcy */
1129: clearsfbm(bound,0,lcy);
1130: COEF(dc) = COEF(DC(g)); ptosfbm(bound,lcyx,lcy);
1131:
1132: for ( i = 0; i < k - 1; i++ )
1133: for ( j = win[i] + 1; j < win[i + 1]; j++ )
1134: c[j-i-1] = c[j];
1135: for ( j = win[k-1] + 1; j <= np; j++ )
1136: c[j-k] = c[j];
1137: if ( ( np -= k ) < k )
1138: break;
1139: if ( np - win[0] + 1 < k )
1140: if ( ++k > np )
1141: break;
1142: else
1143: for ( i = 0; i < k; i++ )
1144: win[i] = i + 1;
1145: else
1146: for ( i = 1; i < k; i++ )
1147: win[i] = win[0] + i;
1148: } else if ( !ncombi(1,np,k,win) )
1149: if ( k == np )
1150: break;
1151: else
1152: for ( i = 0, ++k; i < k; i++ )
1153: win[i] = i + 1;
1154: }
1155: fprintf(stderr,"\n");
1156: NEXTDC(dcf0,dcf); COEF(dcf) = g;
1157: DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0;
1158: }
1159:
1.9 ! noro 1160: /* lcy = LC(g), lcg = lcy*g, lcg0 = const part of lcg */
! 1161: int sfdtestmain(vl,lcg,lcg0,lcy,csum,list,k,in,fp,cofp)
1.8 noro 1162: VL vl;
1163: P lcg;
1.9 ! noro 1164: UM lcg0;
1.8 noro 1165: BM lcy;
1166: P csum;
1167: ML list;
1168: int k;
1169: int *in;
1170: P *fp,*cofp;
1171: {
1172: P fmul,csumg,q;
1173: V x,y;
1174:
1175: x = vl->v;
1176: y = vl->next->v;
1.9 ! noro 1177: if (!sfctest(lcg0,lcy,list,k,in))
1.8 noro 1178: return 0;
1179: mulsfbmarray(UDEG(lcg),lcy,list,k,in,x,y,&fmul);
1180: if ( csum ) {
1181: sfcsump(vl,fmul,&csumg);
1182: if ( csumg ) {
1183: if ( !divtp(vl,csum,csumg,&q) )
1184: return 0;
1185: }
1186: }
1187: if ( divtp(vl,lcg,fmul,&q) ) {
1188: pp_sfp(vl,fmul,fp);
1189: pp_sfp(vl,q,cofp);
1190: return 1;
1191: } else
1192: return 0;
1193: }
1194:
1.9 ! noro 1195: void const_term(f,c)
! 1196: P f;
! 1197: UM c;
! 1198: {
! 1199: DCP dc;
! 1200:
! 1201: for ( dc = DC(f); dc && DEG(dc); dc = NEXT(dc) );
! 1202: if ( dc )
! 1203: ptosfum(COEF(dc),c);
! 1204: else
! 1205: DEG(c) = -1;
! 1206: }
! 1207:
! 1208: void const_term_sfbm(f,bound,c)
! 1209: BM f;
! 1210: int bound;
! 1211: UM c;
! 1212: {
! 1213: int i;
! 1214:
! 1215: for ( i = 0; i < bound; i++ )
! 1216: if ( DEG(COEF(f)[i]) >= 0 )
! 1217: COEF(c)[i] = COEF(COEF(f)[i])[0];
! 1218: else
! 1219: COEF(c)[i] = 0;
! 1220: degum(c,bound-1);
! 1221: }
! 1222:
! 1223: /* lcy*(product of const part) | lcg0 ? */
! 1224:
! 1225: int sfctest(lcg0,lcy,list,k,in)
! 1226: UM lcg0;
! 1227: BM lcy;
1.8 noro 1228: ML list;
1229: int k;
1230: int *in;
1231: {
1232: DCP dc;
1.9 ! noro 1233: int bound,i,dr;
! 1234: UM t,s,u,w;
! 1235: BM *l;
! 1236:
! 1237: bound = list->bound;
! 1238: t = W_UMALLOC(2*bound);
! 1239: s = W_UMALLOC(2*bound);
! 1240: u = W_UMALLOC(2*bound);
! 1241: const_term_sfbm(lcy,bound,t);
! 1242: if ( DEG(t) < 0 )
! 1243: return 1;
1.8 noro 1244:
1.9 ! noro 1245: l = (BM *)list->c;
! 1246: for ( i = 0; i < k; i++ ) {
! 1247: const_term_sfbm(l[in[i]],bound,s);
! 1248: mulsfum(t,s,u);
! 1249: if ( DEG(u) >= bound )
! 1250: degum(u,bound-1);
! 1251: w = t; t = u; u = w;
! 1252: }
! 1253: cpyum(lcg0,s);
! 1254: dr = divsfum(s,t,u);
! 1255: if ( dr >= 0 )
! 1256: return 0;
! 1257: else
1.8 noro 1258: return 1;
1259: }
1260:
1261: /* main var of f is x */
1262:
1263: void mulsfbmarray(n,lcy,list,k,in,x,y,g)
1264: int n;
1265: BM lcy;
1266: ML list;
1267: int k;
1268: int *in;
1269: V x,y;
1270: P *g;
1271: {
1272: int bound,i;
1273: BM wb0,wb1,t,lcbm;
1274: BM *l;
1275:
1276: bound = list->bound;
1277: W_BMALLOC(n,bound,wb0); W_BMALLOC(n,bound,wb1);
1278: l = (BM *)list->c;
1279: clearsfbm(bound,n,wb0);
1280: mulsfbm(bound,lcy,l[in[0]],wb0);
1281: for ( i = 1; i < k; i++ ) {
1282: clearsfbm(bound,n,wb1);
1283: mulsfbm(bound,l[in[i]],wb0,wb1);
1284: t = wb0; wb0 = wb1; wb1 = t;
1285: }
1286: sfbmtop(bound,wb0,x,y,g);
1287: }
1288:
1289: void sfcsump(vl,f,s)
1290: VL vl;
1291: P f;
1292: P *s;
1293: {
1294: P t,u;
1295: DCP dc;
1296:
1297: for ( dc = DC(f), t = 0; dc; dc = NEXT(dc) ) {
1298: addp(vl,COEF(dc),t,&u); t = u;
1299: }
1300: *s = t;
1301: }
1302:
1303: /* *fp = primitive part of f w.r.t. x */
1304:
1305: void pp_sfp(vl,f,fp)
1306: VL vl;
1307: P f;
1308: P *fp;
1309: {
1310: V x,y;
1311: int d;
1312: UM t,s,gcd;
1313: DCP dc;
1314: P dvr;
1.5 noro 1315:
1.8 noro 1316: x = vl->v;
1317: y = vl->next->v;
1318: d = getdeg(y,f);
1319: if ( d == 0 )
1320: *fp = f; /* XXX */
1321: else {
1322: t = W_UMALLOC(2*d);
1323: s = W_UMALLOC(2*d);
1324: gcd = W_UMALLOC(2*d);
1325: dc = DC(f);
1326: ptosfum(COEF(dc),gcd);
1327: for ( dc = NEXT(dc); dc; dc = NEXT(dc) ) {
1328: ptosfum(COEF(dc),t);
1329: gcdsfum(gcd,t,s);
1330: cpyum(s,gcd);
1331: }
1332: sfumtop(y,gcd,&dvr);
1333: divsp(vl,f,dvr,fp);
1.5 noro 1334: }
1.3 noro 1335: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>