Annotation of OpenXM_contrib2/asir2000/engine/Hgfs.c, Revision 1.11
1.11 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.10 2001/06/26 08:52:59 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:
1.10 noro 945: n = QTOS(DEG(DC(f)));
946: clearsfbm(bound,n,fl);
1.5 noro 947: DEG(fl) = bound;
948: t = UMALLOC(bound);
949: for ( dc = DC(f); dc; dc = NEXT(dc) ) {
950: d = QTOS(DEG(dc));
951: ptosfum(COEF(dc),t);
952: for ( i = 0; i <= DEG(t); i++ )
953: COEF(COEF(fl)[i])[d] = COEF(t)[i];
954: }
1.8 noro 955: for ( i = 0; i < bound; i++ )
1.5 noro 956: degum(COEF(fl)[i],n);
957: }
958:
1.4 noro 959: /* x : main variable */
960:
961: void sflumtop(bound,fl,x,y,fp)
962: int bound;
963: LUM fl;
964: V x,y;
965: P *fp;
966: {
967: int i,j,n;
968: int **c;
969: UM w;
970: int *coef;
971: DCP dc,dct;
972:
973: n = fl->d;
974: c = fl->c;
975: w = W_UMALLOC(bound);
976: for ( i = 0, dc = 0; i <= n; i++ ) {
977: coef = c[i];
978: for ( j = bound-1; j >= 0 && coef[j] == 0; j-- );
979: if ( j < 0 )
980: continue;
981: DEG(w) = j; bcopy(coef,COEF(w),(j+1)*sizeof(int));
982: NEWDC(dct); STOQ(i,DEG(dct));
983: sfumtop(y,w,&COEF(dct)); NEXT(dct) = dc; dc = dct;
984: }
985: MKP(x,dc,*fp);
1.5 noro 986: }
987:
988: /* x : main variable */
989:
1.8 noro 990: void sfbmtop(bound,f,x,y,fp)
1.5 noro 991: int bound;
992: BM f;
993: V x,y;
994: P *fp;
995: {
996: UM *c;
1.8 noro 997: int i,j,d,a;
998: GFS b;
999: DCP dc0,dc,dct;
1000:
1001: c = COEF(f);
1002: d = DEG(c[0]);
1003: for ( i = 1; i < bound; i++ )
1004: d = MAX(DEG(c[i]),d);
1005:
1006: dc0 = 0;
1007: for ( i = 0; i <= d; i++ ) {
1008: dc = 0;
1009: for ( j = 0; j < bound; j++ ) {
1010: if ( DEG(c[j]) >= i && (a = COEF(c[j])[i]) ) {
1011: NEWDC(dct);
1012: STOQ(j,DEG(dct));
1013: MKGFS(IFTOF(a),b);
1014: COEF(dct) = (P)b;
1015: NEXT(dct) = dc;
1016: dc = dct;
1017: }
1018: }
1019: if ( dc ) {
1020: NEWDC(dct);
1021: STOQ(i,DEG(dct));
1022: MKP(y,dc,COEF(dct));
1023: NEXT(dct) = dc0;
1024: dc0 = dct;
1025: }
1026: }
1027: if ( dc0 )
1028: MKP(x,dc0,*fp);
1029: else
1030: *fp = 0;
1031: }
1032:
1033: void sfdtest(P,ML,V,V,DCP *);
1034:
1.9 noro 1035: void sfbfctr(f,x,y,dcp)
1.8 noro 1036: P f;
1037: V x,y;
1038: DCP *dcp;
1039: {
1040: ML list;
1041: P sf;
1.9 noro 1042: GFS ev;
1043: DCP dc,dct;
1044: BM fl;
1045: int n,bound;
1.8 noro 1046:
1047: /* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */
1.9 noro 1048: sfhensel(5,f,x,&ev,&sf,&list);
1049: sfdtest(sf,list,x,y,&dc);
1050: n = getdeg(x,sf);
1051: bound = list->bound;
1052: W_BMALLOC(n,bound,fl);
1053: for ( dct = dc; dct; dct = NEXT(dct) ) {
1054: ptosfbm(bound,COEF(dct),fl);
1055: shiftsfbm(bound,fl,_chsgnsf(FTOIF(CONT(ev))));
1056: sfbmtop(bound,fl,x,y,&COEF(dct));
1057: }
1058: *dcp = dc;
1.8 noro 1059: }
1060:
1061: /* f = f(x,y) = list->c[0]*list->c[1]*... mod y^list->bound */
1062:
1063: void sfdtest(f,list,x,y,dcp)
1064: P f;
1065: ML list;
1066: V x,y;
1067: DCP *dcp;
1068: {
1069: int n,np,bound;
1070: int i,j,k;
1071: int *win;
1072: P g,lcg,factor,cofactor,lcyx;
1.9 noro 1073: P t,csum;
1.8 noro 1074: DCP dcf,dcf0,dc;
1075: BM *c;
1076: BM lcy;
1.9 noro 1077: UM lcg0;
1.8 noro 1078: ML wlist;
1079: struct oVL vl1,vl0;
1080: VL vl;
1081: int z;
1082:
1083: /* vl = [x,y] */
1084: vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0;
1085:
1.9 noro 1086: /* setup various structures and arrays */
1.8 noro 1087: n = UDEG(f); np = list->n; bound = list->bound; win = W_ALLOC(np+1);
1088: wlist = W_MLALLOC(np); wlist->n = list->n;
1089: wlist->bound = list->bound;
1090: c = (BM *)COEF(wlist);
1091: bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np));
1092:
1.9 noro 1093: lcg0 = W_UMALLOC(2*bound);
1094:
1.8 noro 1095: /* initialize g by f */
1.9 noro 1096: g = f;
1097:
1098: /* initialize lcg */
1099: mulp(vl,g,COEF(DC(g)),&lcg);
1100:
1101: /* initialize lcg0 */
1102: const_term(lcg,lcg0);
1103:
1104: /* initialize csum = lcg(1) */
1105: sfcsump(vl,lcg,&csum);
1.8 noro 1106:
1107: /* initialize lcy by LC(f) */
1108: W_BMALLOC(0,bound,lcy);
1.9 noro 1109: NEWDC(dc); COEF(dc) = COEF(DC(g)); DEG(dc) = 0;
1.8 noro 1110: NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc;
1111: ptosfbm(bound,lcyx,lcy);
1112:
1113: fprintf(stderr,"np = %d\n",np);
1114: for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) {
1115: if ( !(z % 1000) ) fprintf(stderr,".");
1.9 noro 1116: if ( sfdtestmain(vl,lcg,lcg0,lcy,csum,wlist,k,win,&factor,&cofactor) ) {
1.8 noro 1117: NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor;
1118: g = cofactor;
1119:
1120: /* update lcg */
1121: mulp(vl,g,COEF(DC(g)),&lcg);
1122:
1.9 noro 1123: /* update lcg0 */
1124: const_term(lcg,lcg0);
1125:
1126: /* update csum */
1127: sfcsump(vl,lcg,&csum);
1128:
1.8 noro 1129: /* update lcy */
1130: clearsfbm(bound,0,lcy);
1131: COEF(dc) = COEF(DC(g)); ptosfbm(bound,lcyx,lcy);
1132:
1133: for ( i = 0; i < k - 1; i++ )
1134: for ( j = win[i] + 1; j < win[i + 1]; j++ )
1135: c[j-i-1] = c[j];
1136: for ( j = win[k-1] + 1; j <= np; j++ )
1137: c[j-k] = c[j];
1138: if ( ( np -= k ) < k )
1139: break;
1140: if ( np - win[0] + 1 < k )
1141: if ( ++k > np )
1142: break;
1143: else
1144: for ( i = 0; i < k; i++ )
1145: win[i] = i + 1;
1146: else
1147: for ( i = 1; i < k; i++ )
1148: win[i] = win[0] + i;
1149: } else if ( !ncombi(1,np,k,win) )
1150: if ( k == np )
1151: break;
1152: else
1153: for ( i = 0, ++k; i < k; i++ )
1154: win[i] = i + 1;
1155: }
1156: fprintf(stderr,"\n");
1157: NEXTDC(dcf0,dcf); COEF(dcf) = g;
1158: DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0;
1159: }
1160:
1.9 noro 1161: /* lcy = LC(g), lcg = lcy*g, lcg0 = const part of lcg */
1162: int sfdtestmain(vl,lcg,lcg0,lcy,csum,list,k,in,fp,cofp)
1.8 noro 1163: VL vl;
1164: P lcg;
1.9 noro 1165: UM lcg0;
1.8 noro 1166: BM lcy;
1167: P csum;
1168: ML list;
1169: int k;
1170: int *in;
1171: P *fp,*cofp;
1172: {
1173: P fmul,csumg,q;
1174: V x,y;
1175:
1176: x = vl->v;
1177: y = vl->next->v;
1.9 noro 1178: if (!sfctest(lcg0,lcy,list,k,in))
1.8 noro 1179: return 0;
1180: mulsfbmarray(UDEG(lcg),lcy,list,k,in,x,y,&fmul);
1181: if ( csum ) {
1182: sfcsump(vl,fmul,&csumg);
1183: if ( csumg ) {
1184: if ( !divtp(vl,csum,csumg,&q) )
1185: return 0;
1186: }
1187: }
1.11 ! noro 1188: if ( divtp_by_sfbm(vl,lcg,fmul,&q) ) {
1.8 noro 1189: pp_sfp(vl,fmul,fp);
1190: pp_sfp(vl,q,cofp);
1191: return 1;
1192: } else
1193: return 0;
1194: }
1195:
1.9 noro 1196: void const_term(f,c)
1197: P f;
1198: UM c;
1199: {
1200: DCP dc;
1201:
1202: for ( dc = DC(f); dc && DEG(dc); dc = NEXT(dc) );
1203: if ( dc )
1204: ptosfum(COEF(dc),c);
1205: else
1206: DEG(c) = -1;
1207: }
1208:
1209: void const_term_sfbm(f,bound,c)
1210: BM f;
1211: int bound;
1212: UM c;
1213: {
1214: int i;
1215:
1216: for ( i = 0; i < bound; i++ )
1217: if ( DEG(COEF(f)[i]) >= 0 )
1218: COEF(c)[i] = COEF(COEF(f)[i])[0];
1219: else
1220: COEF(c)[i] = 0;
1221: degum(c,bound-1);
1222: }
1223:
1224: /* lcy*(product of const part) | lcg0 ? */
1225:
1226: int sfctest(lcg0,lcy,list,k,in)
1227: UM lcg0;
1228: BM lcy;
1.8 noro 1229: ML list;
1230: int k;
1231: int *in;
1232: {
1233: DCP dc;
1.9 noro 1234: int bound,i,dr;
1235: UM t,s,u,w;
1236: BM *l;
1237:
1238: bound = list->bound;
1239: t = W_UMALLOC(2*bound);
1240: s = W_UMALLOC(2*bound);
1241: u = W_UMALLOC(2*bound);
1242: const_term_sfbm(lcy,bound,t);
1243: if ( DEG(t) < 0 )
1244: return 1;
1.8 noro 1245:
1.9 noro 1246: l = (BM *)list->c;
1247: for ( i = 0; i < k; i++ ) {
1248: const_term_sfbm(l[in[i]],bound,s);
1249: mulsfum(t,s,u);
1250: if ( DEG(u) >= bound )
1251: degum(u,bound-1);
1252: w = t; t = u; u = w;
1253: }
1254: cpyum(lcg0,s);
1255: dr = divsfum(s,t,u);
1256: if ( dr >= 0 )
1257: return 0;
1258: else
1.8 noro 1259: return 1;
1260: }
1261:
1262: /* main var of f is x */
1263:
1264: void mulsfbmarray(n,lcy,list,k,in,x,y,g)
1265: int n;
1266: BM lcy;
1267: ML list;
1268: int k;
1269: int *in;
1270: V x,y;
1271: P *g;
1272: {
1273: int bound,i;
1274: BM wb0,wb1,t,lcbm;
1275: BM *l;
1276:
1277: bound = list->bound;
1278: W_BMALLOC(n,bound,wb0); W_BMALLOC(n,bound,wb1);
1279: l = (BM *)list->c;
1280: clearsfbm(bound,n,wb0);
1281: mulsfbm(bound,lcy,l[in[0]],wb0);
1282: for ( i = 1; i < k; i++ ) {
1283: clearsfbm(bound,n,wb1);
1284: mulsfbm(bound,l[in[i]],wb0,wb1);
1285: t = wb0; wb0 = wb1; wb1 = t;
1286: }
1287: sfbmtop(bound,wb0,x,y,g);
1288: }
1289:
1290: void sfcsump(vl,f,s)
1291: VL vl;
1292: P f;
1293: P *s;
1294: {
1295: P t,u;
1296: DCP dc;
1297:
1298: for ( dc = DC(f), t = 0; dc; dc = NEXT(dc) ) {
1299: addp(vl,COEF(dc),t,&u); t = u;
1300: }
1301: *s = t;
1302: }
1303:
1304: /* *fp = primitive part of f w.r.t. x */
1305:
1306: void pp_sfp(vl,f,fp)
1307: VL vl;
1308: P f;
1309: P *fp;
1310: {
1311: V x,y;
1312: int d;
1313: UM t,s,gcd;
1314: DCP dc;
1315: P dvr;
1.5 noro 1316:
1.8 noro 1317: x = vl->v;
1318: y = vl->next->v;
1319: d = getdeg(y,f);
1320: if ( d == 0 )
1321: *fp = f; /* XXX */
1322: else {
1323: t = W_UMALLOC(2*d);
1324: s = W_UMALLOC(2*d);
1325: gcd = W_UMALLOC(2*d);
1326: dc = DC(f);
1327: ptosfum(COEF(dc),gcd);
1328: for ( dc = NEXT(dc); dc; dc = NEXT(dc) ) {
1329: ptosfum(COEF(dc),t);
1330: gcdsfum(gcd,t,s);
1331: cpyum(s,gcd);
1332: }
1333: sfumtop(y,gcd,&dvr);
1334: divsp(vl,f,dvr,fp);
1.5 noro 1335: }
1.11 ! noro 1336: }
! 1337:
! 1338: int divtp_by_sfbm(vl,f,g,qp)
! 1339: VL vl;
! 1340: P f,g;
! 1341: P *qp;
! 1342: {
! 1343: V x,y;
! 1344: int fx,fy,gx,gy;
! 1345: BM fl,gl,ql;
! 1346: UM *cf,*cg,*cq;
! 1347: UM hg,q,t,s;
! 1348: int i,j,dr;
! 1349:
! 1350: x = vl->v; y = vl->next->v;
! 1351: fx = getdeg(x,f); fy = getdeg(y,f);
! 1352: gx = getdeg(x,g); gy = getdeg(y,g);
! 1353:
! 1354: if ( fx < gx || fy < gy )
! 1355: return 0;
! 1356: W_BMALLOC(fx,fy+1,fl); ptosfbm(fy+1,f,fl); cf = COEF(fl);
! 1357: W_BMALLOC(gx,gy+1,gl); ptosfbm(gy+1,g,gl); cg = COEF(gl);
! 1358: W_BMALLOC(fx-gx,fy-gy+1,ql); cq = COEF(ql);
! 1359:
! 1360: hg = cg[gy];
! 1361: q = W_UMALLOC(fx); t = W_UMALLOC(fx); s = W_UMALLOC(fx);
! 1362:
! 1363: for ( i = fy; i >= gy; i-- ) {
! 1364: if ( DEG(cf[i]) < 0 )
! 1365: continue;
! 1366: dr = divsfum(cf[i],hg,q);
! 1367: if ( dr >= 0 )
! 1368: return 0;
! 1369: if ( DEG(q) > fx-gx )
! 1370: return 0;
! 1371: cpyum(q,cq[i-gy]);
! 1372: for ( j = 0; j <= gy; j++ ) {
! 1373: mulsfum(cg[j],q,t);
! 1374: subsfum(cf[j+i-gy],t,s);
! 1375: cpyum(s,cf[j+i-gy]);
! 1376: }
! 1377: }
! 1378: for ( j = gy-1; j >= 0 && DEG(cf[j]) < 0; j-- );
! 1379: if ( j >= 0 )
! 1380: return 0;
! 1381: sfbmtop(DEG(ql),ql,x,y,qp);
1.3 noro 1382: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>