Annotation of OpenXM_contrib2/asir2000/lib/primdec_mod, Revision 1.14
1.14 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/lib/primdec_mod,v 1.13 2004/02/09 23:37:12 noro Exp $ */
1.7 noro 2:
1.1 noro 3: extern Hom,GBTime$
4: extern DIVLIST,INTIDEAL,ORIGINAL,ORIGINALDIMENSION,STOP,Trials,REM$
5: extern T_GRF,T_INT,T_PD,T_MP$
6: extern BuchbergerMinipoly,PartialDecompByLex,ParallelMinipoly$
7: extern B_Win,D_Win$
8: extern COMMONCHECK_SF,CID_SF$
1.2 noro 9:
1.13 noro 10: if (!module_definedp("fff")) load("fff"); else $
11: if (!module_definedp("gr")) load("gr"); else $
1.12 takayama 12: module primdec_mod $
13: /* Empty for now. It will be used in a future. */
14: endmodule $
1.1 noro 15:
16: /*==============================================*/
17: /* prime decomposition of ideals over */
18: /* finite fields */
19: /* part 1 */
20: /* radical computation */
21: /* 28/12/2002 for Basic Small Finite Field */
22: /* 4/1/2003 for Arbitary Small Finite Field */
23: /*==============================================*/
24:
25: /*==============================================*/
26: /* radical computation of ideals over */
27: /* finite fields by Matsumoto's algorithm */
28: /* */
29: /* The radical of I is computed as the */
30: /* kernel of a power of Frobenius map. */
31: /* */
32: /* radical */
33: /* Input: a list P of polynomials */
34: /* Output: a list P1 of polynomials */
35: /* such that <P1>=rad(<P>) */
36: /* */
37: /* frobeniuskernel_main{2} */
38: /* Input: a list of polynomials P, */
39: /* a list of variables VSet, */
40: /* and a list of other variables WSet */
41: /* Output: a list of polynomials Q */
42: /* such that Q is the kernel of */
43: /* single Frobenius map: x--> x^q */
44: /* where q is the characteristic. */
45: /* version 2 uses successive kernel */
46: /* computation suggested by Matsumoto */
47: /* */
48: /* coefficientfrobeniuskernel */
49: /* Input: a list of polynomials P, */
50: /* Output: a list of polynomials Q */
51: /* such that Q is the kernel of */
52: /* single coefficient Frobenius */
53: /* map: a in GF(q) --> a^q */
54: /* where q is the characteristic. */
55: /* */
56: /* elimination */
57: /* Input: a list P of polynomials */
58: /* a list V of variables */
59: /* Output: a list P1 of polynomials */
60: /* such that P1={f\in P | */
61: /* vars(f)\cap V =\emptyset} */
62: /* */
63: /* checkequality */
64: /* Input: a list P of polynomials */
65: /* a list Q of polynomials */
66: /* Output: 1 if <P>=<Q> */
67: /* 0 otherwise */
68: /* */
69: /* */
70: /* */
71: /*==============================================*/
72:
73: def radicalideal(P,Choice,VSet)
74: {
75:
76: GBTime=0;
77: Ord=0;
78:
79: /* VSet=vars(P);*/
80: WSet=makecounterpart(VSet);
81:
82: T000=time()[0];
83: P1=dp_gr_f_main(P,VSet,Hom,Ord);
84: T001=time()[0];
85: GBTime +=T001-T000;
86:
87: if ( Choice == 3 )
88: {
89: P2=frobeniuskernel_main3(P1,VSet,WSet);
90: }
91: else if ( Choice == 2 )
92: {
93: P2=frobeniuskernel_main2(P1,VSet,WSet);
94: }
95: else if ( Choice == 4 )
96: {
97: P2=frobeniuskernel_main4(P1,VSet,WSet);
98: }
99: else
100: {
101: P2=frobeniuskernel_main(P1,VSet,WSet);
102: }
103:
104: M=checkequality(P1,P2,VSet);
105:
106: while ( M !=1 )
107: {
108: P1=P2;
109: P2=frobeniuskernel_main2(P2,VSet,WSet);
110: M=checkequality(P1,P2,VSet);
111: }
112:
113: return P1;
114: }
115:
116:
117: def frobeniuskernel_main(P,VSet,WSet)
118: {
119: NV=length(VSet);
120:
121: NewP=coefficientfrobeniuskernel(P);
122:
123: NW=length(NewP);
124:
125: TempP=NewP;
126:
127: for (K=NW-1;K>=0;K--)
128: {
129: Poly=TempP[K];
130: for (J=0;J<NV;J++)
131: {
132: Poly=subst(Poly,VSet[J],WSet[J]);
133: }
134: NewP=cons(Poly,NewP);
135: }
136:
137: XSet=append(VSet,WSet);
138: NewOrder=[[0,length(VSet)],[0,length(WSet)]];
139:
1.6 noro 140: Char=characteristic_ff();
1.1 noro 141:
142: for (I=0;I<NV;I++)
143: {
144: AddPoly=VSet[I]^Char-WSet[I];
145: NewP=cons(AddPoly,NewP);
146: }
147:
148: G=dp_gr_f_main(NewP,XSet,Hom,NewOrder);
149: PW=elimination(G,WSet);
150:
151: NW=length(PW);
152: ANS=[];
153: for (I=NW-1;I>=0;I--)
154: {
155: Poly=PW[I];
156: for (J=0;J<NV;J++)
157: {
158: Poly=subst(Poly,WSet[J],VSet[J]);
159: }
160: ANS=cons(Poly,ANS);
161: }
162: return ANS;
163: }
164:
165: def frobeniuskernel_main2(P,VSet,WSet)
166: {
167: NV=length(VSet);
168:
169: NewP=coefficientfrobeniuskernel(P);
170:
171: XSet=append(VSet,WSet);
172: NewOrder=[[0,NV],[0,NV]];
173:
1.6 noro 174: Char=characteristic_ff();
1.1 noro 175:
176: for (I=0;I<NV;I++)
177: {
178: for (J=0;J<NV;J++)
179: {
180: if ( I == J )
181: {
182: AddPoly=VSet[J]^Char-WSet[J];
183: }
184: else
185: {
186: AddPoly=VSet[J]-WSet[J];
187: }
188: NewP=cons(AddPoly,NewP);
189: }
190:
191: T000=time()[0];
192: GP=dp_gr_f_main(NewP,XSet,Hom,NewOrder);
193: T001=time()[0];
194: GBTime += T001-T000;
195:
196: PW=elimination(GP,WSet);
197: NW=length(PW);
198: NewP=[];
199: for (K=NW-1;K>=0;K--)
200: {
201: Poly=PW[K];
202: for (J=0;J<NV;J++)
203: {
204: Poly=subst(Poly,WSet[J],VSet[J]);
205: }
206: NewP=cons(Poly,NewP);
207: }
208: }
209: return NewP;
210: }
211:
212:
213: def frobeniuskernel_main4(P,VSet,WSet)
214: {
215: NV=length(VSet);
216:
217: NewP=coefficientfrobeniuskernel(P);
218:
219: XSet=append(VSet,WSet);
220: NewOrder=[[0,NV],[0,NV]];
221:
1.6 noro 222: Char=characteristic_ff();
1.1 noro 223:
224: for (I=0;I<NV;I++)
225: {
226: NW=length(NewP);
227: TempP=NewP;
228:
229: for (J=0;J<NV;J++)
230: {
231: if ( I == J )
232: {
233: AddPoly=VSet[J]^Char-WSet[J];
234: }
235: else
236: {
237: AddPoly=VSet[J]-WSet[J];
238: }
239: NewP=cons(AddPoly,NewP);
240: }
241:
242: /* for (K=NW-1;K>=0;K--)
243: {
244: Poly=TempP[K];
245: for (J=0;J<NV;J++)
246: {
247: if ( J == I )
248: {
249: Poly=subst(Poly,VSet[J],WSet[J]);
250: }
251: else
252: {
253: Poly=subst(Poly,VSet[J],WSet[J]^Char);
254: }
255: }
256: NewP=cons(Poly,NewP);
257: }*/
258: T000=time()[0];
259: GP=dp_gr_f_main(NewP,XSet,Hom,NewOrder);
260: T001=time()[0];
261: GBTime += T001-T000;
262:
263: PW=elimination(GP,WSet);
264: NW=length(PW);
265: NewP=[];
266: for (K=NW-1;K>=0;K--)
267: {
268: Poly=PW[K];
269: for (J=0;J<NV;J++)
270: {
271: Poly=subst(Poly,WSet[J],VSet[J]);
272: }
273: NewP=cons(Poly,NewP);
274: }
275: }
276: return NewP;
277: }
278:
279: def frobeniuskernel_main3(P,VSet,WSet)
280: {
281: NV=length(VSet);
282:
283: NewP=coefficientfrobeniuskernel(P);
284:
1.6 noro 285: Char=characteristic_ff();
1.1 noro 286:
287: for (I=0;I<NV;I++)
288: {
289: XWSet=[];
290: for (J=0;J<NV;J++)
291: {
292: if ( I == J )
293: {
294: AddPoly=VSet[I]^Char-WSet[I];
295: NewP=cons(AddPoly,NewP);
296: XWSet=append(XWSet,[WSet[I]]);
297: }
298: else
299: {
300: XWSet =append(XWSet,[VSet[J]]);
301: }
302: }
303:
304: XSet=cons(VSet[I],XWSet);
305:
306: NewOrder=[[0,1],[0,NV]];
307: T000=time()[0];
308: GP=dp_gr_f_main(NewP,XSet,Hom,NewOrder);
309: T001=time()[0];
310: GBTime += T001-T000;
311:
312: PW=elimination(GP,XWSet);
313: NW=length(PW);
314: NewP=[];
315: for (K=NW-1;K>=0;K--)
316: {
317: Poly=PW[K];
318: Poly=subst(Poly,WSet[I],VSet[I]);
319: NewP=cons(Poly,NewP);
320: }
321: }
322: return NewP;
323: }
324:
325: def coefficientfrobeniuskernel(P)
326: {
327: if ( setmod_ff()[1] == 0 )
328: {
329: return P;
330: }
331:
332: NP=length(P);
333: ANS=[];
334: for (I=0;I<NP;I++)
335: {
336: TEST=P[I];
337: Q=coefficientfrobeniuskernel_main(TEST);
338: ANS=append(ANS,[Q]);
339: }
340: return ANS;
341: }
342:
343: def coefficientfrobeniuskernel_main(Poly)
344: {
345: Vars=vars(Poly);
346: QP=dp_ptod(Poly,Vars);
347: ANS=0;
1.6 noro 348: FOrd=extdeg_ff();
349: Char=characteristic_ff();
1.1 noro 350: Pow=Char^(FOrd-1);
351:
352: while(QP !=0 )
353: {
354: Coef=dp_hc(QP);
355: HT=dp_ht(QP);
356:
357: ANS=ANS+Coef^Pow*dp_dtop(HT,Vars);
358:
359: QP=dp_rest(QP);
360: }
361: return ANS;
362: }
363:
364:
365: def elimination(G,V)
366: {
367: ANS=[];
368: NG=length(G);
369:
370: for (I=NG-1;I>=0;I--)
371: {
372: VSet=vars(G[I]);
373: DIFF=setminus(VSet,V);
374:
375: if ( DIFF ==[] )
376: {
377: ANS=cons(G[I],ANS);
378: }
379: }
380: return ANS;
381: }
382:
383: def setminus(A,B)
384: {
385: NA=length(A);
386: NB=length(B);
387:
388: ANS=[];
389:
390: for (I=0;I<NA;I++)
391: {
392: Flag =0;
393: for (J=0;J<NB;J++)
394: {
395: if (A[I] == B[J])
396: {
397: Flag=1;
398: break;
399: }
400: }
401:
402: if ( Flag == 0 )
403: {
404: ANS=append(ANS,[A[I]]);
405: }
406: }
407: return ANS;
408: }
409:
410: def makecounterpart(V)
411: {
412: NV=length(V);
413:
414: A="tmp";
415:
416: ANS=[];
417: for (I=NV-1;I>=0;I--)
418: {
419: T=strtov(A+rtostr(I));
420: ANS=cons(T,ANS);
421: }
422: return ANS;
423: }
424:
425: def checkequality(P,Q,VSet)
426: {
427: QQ=dp_gr_f_main(Q,VSet,Hom,Ord);
428: PP=dp_gr_f_main(P,VSet,Hom,Ord);
429:
430: NP=length(PP);
431: NQ=length(QQ);
432:
433: VarsP=vars(P);
434: VarsQ=vars(Q);
435: if ( NP != NQ || VarsP !=VarsQ )
436: {
437: return 0;
438: }
439:
440: for (I=0;I<NP;I++)
441: {
442: HCP=dp_hc(dp_ptod(PP[I],VSet));
443: HCQ=dp_hc(dp_ptod(QQ[I],VSet));
444:
445: if ( HCP*QQ[I]-HCQ*PP[I] != 0 )
446: {
447: return 0;
448: }
449: }
450:
451: return 1;
452: }
453:
454: /*==============================================*/
455: /* prime decomposition of ideals over */
456: /* finite fields */
457: /* part 2 */
458: /* ideal dimension */
459: /* 3/1/2003 */
460: /*==============================================*/
461:
462: /*==============================================*/
463: /* ideal dimension computation */
464: /* */
465: /* The dimension of I is computed as the */
466: /* maximal size of MSI sets. */
467: /* */
468: /* idealdimension */
469: /* Input: a list P of polynomials */
470: /* a list V of variables */
471: /* Output: the dimension of I */
472: /* and the MSI with max size */
473: /* */
474: /* findmsi */
475: /* Input: a list of head monomials */
476: /* and a list of variables */
477: /* Output: a list of all MSI sets */
478: /* and SI sets */
479: /* */
480: /* findmsi_main */
481: /* Input: a list P of polynomials */
482: /* a list V of variables */
483: /* Output: a list P1 of polynomials */
484: /* such that P1={f\in P | */
485: /* vars(f)\cap V =\emptyset} */
486: /* */
487: /* headtermset */
488: /* Input: a list P of polynomials */
489: /* a list V of variables */
490: /* Output: a list of head monomials */
491: /* */
492: /* */
493: /* */
494: /*==============================================*/
495:
496: def idealdimension(P,V,Ord)
497: {
498: GP=dp_gr_f_main(P,V,Hom,Ord);
499: HeadTermset=headtermset(GP,V,Ord);
500: MSIset=findmsi(HeadTermset,V);
501: if ( MSIset == [] )
502: {
503: return [0,[]];
504: }
505: Index=findmaxindex(MSIset);
506: MSI=MSIset[Index];
507: Dimension=length(MSI);
508: return [Dimension, MSI];
509: }
510:
511: def findmaxindex(S)
512: {
513: NS=length(S);
514: Index=0;
515: Defaultsize=length(S[0]);
516: for (I=1;I<NS;I++)
517: {
518: Targetsize=length(S[I]);
519:
520: if ( Targetsize > Defaultsize )
521: {
522: Index=I;
523: }
524: Defaultsize= Targetsize;
525: }
526: return Index;
527: }
528:
529: def headtermset(P,V,Ord)
530: {
531: ANS=[];
532: NP=length(P);
533: for ( I=NP-1;I>=0;I--)
534: {
535: Head=headterm(P[I],V,Ord);
536: ANS=cons(Head,ANS);
537: }
538: return ANS;
539: }
540:
541: def headterm(P,V,Ord)
542: {
543: dp_ord(Ord);
544: Q=dp_ptod(P,V);
545: Headdp=dp_hm(Q);
546: Head=dp_dtop(Headdp,V);
547: return Head;
548: }
549:
550: def findmsi_main(TermsetIndex,MSIsetIndex,Int,N)
551: {
552: ANS=[];
553: BNS=[];
554: TempMSIsetIndex=MSIsetIndex;
555:
556: if (Int == 0)
557: {
558: for ( I=0;I<N;I++)
559: {
560: TEST1=[I];
561: Check=intersection(TermsetIndex,TEST1);
562: if ( Check == 0 )
563: {
564: ANS=cons(TEST1,ANS);
565: }
566: }
567: }
568:
569: while( Int !=0 && TempMSIsetIndex != [] )
570: {
571: TEST=TempMSIsetIndex[0];
572: Flag=0;
573: for ( I=TEST[0]+1;I<N;I++)
574: {
575: TEST1=cons(I,TEST);
576: Check=intersection(TermsetIndex,TEST1);
577: if ( Check == 0 )
578: {
579: Flag=1;
580: ANS=cons(TEST1,ANS);
581: }
582: }
583: if ( Flag == 0 )
584: {
585: BNS=cons(TEST,BNS);
586: }
587: TempMSIsetIndex=cdr(TempMSIsetIndex);
588: }
589: return [ANS,BNS];
590: }
591:
592: def findmsi(Termset,Vset)
593: {
594: ANS=[];
595: MSIsetIndex=[];
596: N=length(Vset);
597: TermsetIndex=makeindex(Termset,Vset);
598:
599: for (I=0;I<N;I++)
600: {
601: Temp=findmsi_main(TermsetIndex,ANS,I,N);
602: ANS=Temp[0];
603: BNS=Temp[1];
604: MSIsetIndex=append(BNS,MSIsetIndex);
605: }
606:
607: MSIsetIndex=append(ANS,MSIsetIndex);
608: MSIset=makevarset(MSIsetIndex,Vset);
609: return MSIset;
610: }
611:
612: def makeindex(Termset,Vset)
613: {
614: ANS=[];
615:
616: N=length(Vset);
617:
618: TempTermset=Termset;
619: while( TempTermset !=[] )
620: {
621: TEST=TempTermset[0];
622: Index=[];
623: for (I=0;I<N;I++)
624: {
625: Q=srem(TEST,Vset[I]);
626: if ( Q == 0 )
627: {
628: Index=cons(I,Index);
629: }
630: }
631: ANS=cons(Index,ANS);
632: TempTermset=cdr(TempTermset);
633: }
634: return ANS;
635: }
636:
637: def makevarset(IndexSet,Vset)
638: {
639: ANS=[];
640: NI=length(IndexSet);
641:
642: for (I=0;I<NI;I++)
643: {
644: TEST=IndexSet[I];
645:
646: TestV=makevar(TEST,Vset);
647: ANS=append(ANS,[TestV]);
648: }
649: return ANS;
650: }
651:
652: def makevar(Index,Vset)
653: {
654: ANS=[];
655: TempIndex=Index;
656:
657: while( TempIndex !=[] )
658: {
659: ANS=cons(Vset[TempIndex[0]],ANS);
660: TempIndex=cdr(TempIndex);
661: }
662:
663: return ANS;
664: }
665:
666: def intersection(IndexSet,TestIndex)
667: {
668: TempIndexSet=IndexSet;
669:
670: while(TempIndexSet !=[] )
671: {
672: Sample=TempIndexSet[0];
673:
674: Inclusion=testinclusion(Sample,TestIndex);
675:
676: if ( Inclusion == 1 )
677: {
678: return 1;
679: }
680:
681: TempIndexSet=cdr(TempIndexSet);
682: }
683: return 0;
684: }
685:
686: def testinclusion(Sample,Test)
687: {
688: NS=length(Sample);
689: NT=length(Test);
690:
691: for (I=0;I<NS;I++)
692: {
693: Flag=0;
694: for (J=0;J<NT;J++)
695: {
696: if (Sample[I]==Test[J])
697: {
698: Flag=1;
699: break;
700: }
701: }
702: if ( Flag == 0 )
703: {
704: return 0;
705: }
706: }
707: return 1;
708: }
709:
710:
711: /*======================================================*/
712: /* prime decomposition of ideals over */
713: /* small finite fields */
714: /* part 3 */
715: /* prime decomposition */
716: /* 9/1/2003 1st Implementation */
717: /* 11/1/2003 Divid 3 cases in zeroprime */
718: /* decomposition (3a) */
719: /* 12/1/2003 Redundant elimination (3e) */
720: /* 13/1/2003 gr_fctr_sf version (3f) */
721: /* 14/1/2003 Flag on Early Termination */
722: /* 15/1/2002 drl version */
723: /* 17/1/2002 depth oriented search */
724: /* 17/1/2002 dimension oriented search */
725: /* */
726: /* global variables */
727: /* Hom: used in dp_gr_f_main */
728: /* DIVLIST: the set of prime ideals */
729: /* ORIGINAL: the GB of the original input ideal */
730: /* ORIGINALDIMENSION: the dimension */
731: /* STOP: the flag on terminatation */
732: /* Trials: a bound on the number of trials */
733: /* REM: the vector list of remaining ideals */
734: /* */
735: /*======================================================*/
736:
737: /*======================================================*/
738: /* prime decomposition */
739: /* */
740: /* */
741: /* primedec(P,V,Ord,F) */
742: /* Input: a list P of polynomials */
743: /* a list V of variables */
744: /* a term order Ord */
745: /* a flag F on Early Termination */
746: /* Output: 0 */
747: /* DVILIST: the set of prime divisors of <P> */
748: /* [subprocedure] */
749: /* o --gr_fctr_sf (mplex2) */
750: /* o --primedecomposition */
751: /* Remark: if F = 1, we empoly Early Termination */
752: /* */
753: /* */
754: /* primedecomposition(P,V,Ord,C,F) */
755: /* Input: a list P of polynomials */
756: /* a list V of variables */
757: /* a term order Ord */
758: /* a level C of recursive call */
759: /* a flag F on Early Termination */
760: /* Output: 0 */
761: /* DVILIST: the set of prime divisors of <P>^ec */
762: /* [subprocedure] */
763: /* o --idealdimension (part2) */
764: /* o --setminus (part1) */
765: /* o --zeroprimedecomposition */
766: /* o --extcont */
767: /* o --checkadd2 */
768: /* o --ideal_intersection_sfrat */
769: /* o --radical_equality */
770: /* */
771: /* zeroprimedecomposition(P,V,W) */
772: /* Input: a list P of polynomials */
773: /* lists V,W of variables */
774: /* such that <P> is 0-dimensional */
775: /* in K[V] and W is the original set */
776: /* of variables */
777: /* Output: the set of prime/primary */
778: /* divisors of <P> */
779: /* (P is a GB w.r.t. DRL) */
780: /* [subprocedure] */
781: /* o --partical_decomp (mplex2) */
782: /* o --checkgeneric */
783: /* o --separableclosure */
784: /* o --zerogenericprimedecomposition */
785: /* o --zeroseparableprimedecomposition */
786: /* o --convertdivisor */
787: /* o --contraction */
788: /* o --radicalideal (part1) */
789: /* */
790: /* extcont(P,V,Ord) */
791: /* Input: a list P of polynomials */
792: /* a set V of variables */
793: /* Output: a polynomial f */
794: /* such that \sqrt<P>^c=\sqrt(P:f) */
795: /* Then \sqrt<P>=\sqrt(P:f)\cap \sqrt(P+<f>) */
796: /* */
797: /* separableclosure([P,MP],V,W) */
798: /* Input: a pair [P,MP] of a list P of */
799: /* polynomials and a list MP of */
800: /* minimal polynomials of variables */
801: /* list V,W of variables */
802: /* such that <P> is 0-dimensional */
803: /* in K[V] and W is the original set */
804: /* of variables */
805: /* Output: [Q,E], a list Q of polynomials */
806: /* an exponent vector E */
807: /* such that <Q> is the separable */
808: /* closure of <P> */
809: /* [subprocedure] */
810: /* o --makecounterpart(part1) */
811: /* o --elimination(part1) */
812: /* o --checkseparable */
813: /* */
814: /* zeroseparableprimedecomposition(P,V,W) */
815: /* Input: a list P of polynomials */
816: /* lists V,W of variables */
817: /* such that <P> is 0-dimensional */
818: /* and all minimal polynomial */
819: /* are irreducible (i.e. <P> is an */
820: /* intermediate ideal in the paper */
821: /* or the output of partial_decomp) */
822: /* in K[V] and W is the original set */
823: /* of variables */
824: /* Output: the set of prime/primary */
825: /* divisors of <P> */
826: /* [subprocedure] */
827: /* o --findgeneric */
828: /* o --elimination(part1) */
829: /* */
830: /* zerogenericprimedecomposition([P,MP],M,V,W) */
831: /* Input: a pair [P,MP] of a list P of */
832: /* polynomials and a list MP of */
833: /* minimal polynomials of variables */
834: /* such that <P> is 0-dimensional */
835: /* and M is a minimal poly of a */
836: /* variable in generic position */
837: /* in K[V] and W is the original */
838: /* set of variables */
839: /* Output: the set of prime/primary */
840: /* divisors of <P> */
841: /* [subprocedure] */
842: /* */
843: /* convertdivisor(P,V,W,E) */
844: /* Input: a list P of polynomials */
845: /* list V,W of variables */
846: /* such that <P> is a primary/prime */
847: /* 0-dimensional ideal in K[V] and */
848: /* W is the original set */
849: /* of variables */
850: /* the exponent vector E */
851: /* Output: the corresponding prime ideal */
852: /* in K[W] */
853: /* [subprocedure] */
854: /* o --elimination(part1) */
855: /* */
856: /* contraction(P,V,W) */
857: /* Input: a list P of polynomials */
858: /* list V,W of variables */
859: /* such that <P> is a primary/prime */
860: /* 0-dimensional ideal in K[V] and */
861: /* W is the original set */
862: /* of variables */
863: /* Output: the contraction <P>^c in K[W] */
864: /* */
865: /* findgeneric(P,V) */
866: /* Input: a list P of polynomials */
867: /* a list V of variables */
868: /* such that <P> is a separable */
869: /* 0-dimensional ideal in K[V] */
870: /* Output: [F,Min,X], a polynomial F in */
871: /* generic position, its minimal */
872: /* polynomial Min in a new variable */
873: /* X */
874: /* [subprocedure] */
875: /* o --lineardimension */
876: /* o --makemagic */
877: /* o --minipoly_sf (mplex2) */
878: /* */
879: /*======================================================*/
880:
881: def primedec_mod(P,VSet,Ord,Mod,Strategy)
882: {
883: for ( Q = Mod, E = 1; Q < 2^14; Q *= Mod, E++ );
884: Q /= Mod;
885: E--;
886: if ( !(E%2) ) {
887: Q /= Mod;
888: E--;
889: }
890: setmod_ff(Mod,E);
891: Pq = map(simp_ff,P);
892: primedec_sf(Pq,VSet,Ord,Strategy);
893: R = convsf(DIVLIST,VSet,0,1);
894: return R;
895: }
896:
897:
898: def primedec_sf(P,VSet,Ord,Strategy)
899: {
900: /* DIVLIST = the set of all computed candidates for iredundant divisors */
901: /* INTIDEAL = the intersection of all computed candidates */
902: /* ORIGINAL = a Groebner basis of the input ideal <P> w.r.t. Ord */
903: /* ORIGINALDIMENSION = the dimension of the input ideal <P> */
904: /* STOP = the flag on termination */
905: /* REM = the list of remaining ideals */
906:
907: T0 = time();
908: T_GRF=0;
909: T_INT=0;
910: T_PD=0;
911: T_MP=0;
912: DIVLIST=[];
913: INTIDEAL=[];
914: STOP=0;
915: B_Win=0;
916: D_Win=0;
917:
918: ORIGINAL=dp_gr_f_main(P,VSet,Hom,Ord);
919:
920: Dimeset=idealdimension(ORIGINAL,VSet,Ord);
921: ORIGINALDIMENSION=Dimeset[0];
922:
923: /* REM0=newvect(ORIGINALDIMENSION+1);*/
924: REM=newvect(ORIGINALDIMENSION+1);
925:
926: for (I=0;I<ORIGINALDIMENSION+1;I++)
927: {
928: /* REM0[I]=[];*/
929: REM[I]=[];
930: }
931:
1.3 noro 932: if ( dp_gr_print() ) {
933: print("The dimension of the ideal is ",2);print(ORIGINALDIMENSION,2);
934: print(". ");
935: }
1.1 noro 936:
937: if ( ORIGINALDIMENSION == 0 )
938: {
939: Strategy = 0;
940: STOP = 0;
941: }
942:
943: ANS=gr_fctr_sf([ORIGINAL],VSet,Ord);
944: NANS=length(ANS);
1.3 noro 945: if ( dp_gr_print() ) {
946: print("There are ",2);print(NANS,2);print(" partial components. ");
947: }
1.1 noro 948: for (I=0;I<NANS;I++)
949: {
950: TempI=ANS[I];
951: DimI=idealdimension(TempI,VSet,Ord)[0];
952:
953: REM[ORIGINALDIMENSION-DimI]=cons(TempI,REM[ORIGINALDIMENSION-DimI]);
954: }
955:
956: REM[0]=ANS;
957:
958: INDEX=0;
959:
960: while ( INDEX != -1 )
961: {
962: /* print("We deal with the ",2);print(I,2);print("-th partial component. ");*/
963:
964: TESTIDEAL=car(REM[INDEX]);
965: REM[INDEX]=cdr(REM[INDEX]);
966: primedecomposition(TESTIDEAL,VSet,Ord,INDEX,Strategy);
967:
968: if (STOP == 1 )
969: {
970: DIVLIST = prime_irred_sf_by_first(DIVLIST,VSet,0);
971: DIVLIST = monic_sf_first(DIVLIST,VSet);
1.3 noro 972: if ( dp_gr_print() ) {
973: print("We finish the computation. ");
974: T_TOTAL = time()[3]-T0[3];
975: print(["T_TOTAL",T_TOTAL,"T_GRF",T_GRF,"T_PD",T_PD,"T_MP",T_MP,"T_INT",T_INT,"B_Win",B_Win,"D_Win",D_Win]);
976: }
1.1 noro 977: return 0;
978: }
979:
980: INDEX=findindex(REM);
981: }
982:
983: DIVLIST = prime_irred_sf_by_first(DIVLIST,VSet,0);
984: DIVLIST = monic_sf_first(DIVLIST,VSet);
985: T_TOTAL = time()[3]-T0[3];
1.3 noro 986: if ( dp_gr_print() ) {
987: print(["T_TOTAL",T_TOTAL,"T_GRF",T_GRF,"T_PD",T_PD,"T_MP",T_MP,"T_INT",T_INT,"B_Win",B_Win,"D_Win",D_Win]);
988: }
1.1 noro 989: return 0;
990: }
991:
992:
993:
994:
995:
996: def findindex(VECTORLIST)
997: {
998: NL=size(VECTORLIST)[0];
999:
1000: for (I=0;I<NL;I++)
1001: {
1002: if ( VECTORLIST[I] == [] )
1003: {
1004: continue;
1005: }
1006: return I;
1007: }
1008: return -1;
1009: }
1010:
1011: #if 0
1012: def checkadd2(ADD,TESTADDLIST,VSet)
1013: {
1014: /* This function will be used for eliminating redundant divisors */
1015:
1016: NTESTADDLIST=length(TESTADDLIST);
1017: for (I=0;I<NTESTADDLIST;I++)
1018: {
1019: TESTLIST=TESTADDLIST[I][0];
1020:
1021: if ( setminus(TESTLIST,ADD) == [] )
1022: {
1023: return 1;
1024: }
1025: if ( inclusion_test(TESTLIST,ADD,VSet,Ord) == 1 )
1026: {
1027: return 1;
1028: }
1029: }
1030: return 0;
1031: }
1032: #endif
1033:
1034: def checkadd2a(ADD,DIM,TESTADDLIST,VSet)
1035: {
1036: /* This function will be used for eliminating redundant divisors */
1037:
1038: NTESTADDLIST=length(TESTADDLIST);
1039: for (I=0;I<NTESTADDLIST;I++)
1040: {
1041: TESTLIST=TESTADDLIST[I][0];
1042: TESTDIM=TESTADDLIST[I][1];
1043:
1044: if (DIM > TESTDIM )
1045: {
1046: continue;
1047: }
1048:
1049: if ( setminus(TESTLIST,ADD) == [] )
1050: {
1051: return 1;
1052: }
1053: if ( inclusion_test(TESTLIST,ADD,VSet,Ord) == 1 )
1054: {
1055: return 1;
1056: }
1057: }
1058: return 0;
1059: }
1060:
1061: def checkadd3(ADD,TESTADDLIST,VSet)
1062: {
1063: /* This function will be used for eliminating redundant divisors */
1064:
1065: NTESTADDLIST=length(TESTADDLIST);
1066: for (I=0;I<NTESTADDLIST;I++)
1067: {
1068: TESTLIST=TESTADDLIST[I];
1069:
1070: if ( setminus(TESTLIST,ADD) == [] )
1071: {
1072: return 1;
1073: }
1074:
1075:
1076: /* if ( inclusion_test(TESTLIST,ADD,VSet,0) == 1 )
1077: {
1078: return 1;
1079: }*/
1080: }
1081: return 0;
1082: }
1083:
1084: def radical_equality(A,B,VSet,Ord)
1085: {
1086: /* This function will be used for checking the termination. */
1087:
1088: NA=length(A);
1089:
1090: Ord1=[[0,1],[0,length(VSet)]];
1091: Vt=newt;
1092:
1093: for (I=0;I<NA;I++)
1094: {
1095: NewB=cons(1-newt*A[I],B);
1096: GB = dp_gr_f_main(NewB,cons(Vt,VSet),0,Ord1);
1097: K=elimination(GB,VSet);
1098:
1099: if ( vars(K) !=[] )
1100: {
1101: return 0;
1102: }
1103:
1104: }
1105:
1106: return 1;
1107: }
1108:
1109: def primedecomposition(P,VSet,Ord,COUNTER,Strategy)
1110: {
1111: /* DIVLIST = the set of all computed candidates for iredundant divisors */
1112: /* INTIDEAL = the intersection of all computed candidates */
1113: /* ORIGINAL = a Groebner basis of the input ideal <P> w.r.t. Ord */
1114: /* ORIGINALDIMENSION = the dimension of the input ideal <P> */
1115:
1116: RP=P;
1117: GP=dp_gr_f_main(RP,VSet,Hom,Ord);
1118:
1119: /* First we compute the MSI and the dimension of the */
1120: /* ideal <P> in K[Vset], where K is the ground field. */
1121:
1122: Dimeset=idealdimension(GP,VSet,Ord);
1123: Dimension=Dimeset[0];
1124: MSI=Dimeset[1];
1125:
1.3 noro 1126: if ( dp_gr_print() ) {
1127: print("The dimension of the ideal is ",2); print(Dimension,2);
1128: print(".");
1129: }
1.1 noro 1130: TargetVSet=setminus(VSet,MSI);
1131: NewGP=dp_gr_f_main(GP,TargetVSet,Hom,Ord);
1132:
1133: if ( vars(NewGP) == [] )
1134: {
1135: return [];
1136: }
1137:
1138: /* Then the ideal is 0-dimension in K[TargetVSet]. */
1139:
1.3 noro 1140: if ( dp_gr_print() ) {
1141: print("We enter Zero-dimension Prime Decomposition. ",2);
1142: }
1.1 noro 1143:
1144: QP=zeroprimedecomposition(NewGP,TargetVSet,VSet);
1145:
1146: ANS=[];
1147: NQP=length(QP);
1148:
1.3 noro 1149: if ( dp_gr_print() ) {
1150: print("The number of the newly found component is ",2);
1151: print(NQP,2);print(". ",2);
1152: }
1.1 noro 1153: for (I=0;I<NQP;I++)
1154: {
1155: ZPrimeideal=QP[I];
1156: Primedivisor=ZPrimeideal;
1157: CHECKADD=checkadd2a(Primedivisor,Dimension,DIVLIST,VSet);
1158: if (CHECKADD == 0 )
1159: {
1160: DIVLIST=append(DIVLIST,[[Primedivisor,Dimension]]);
1161:
1162: if (Strategy != 1 )
1163: {
1164: /* NO-OPERATION */
1165: }
1166: else if ( COUNTER == 0 && Dimension == 0 && ORIGINALDIMENSION == 0 )
1167: {
1168: /* NO-OPERATION */
1169: }
1170: else if ( INTIDEAL == [] )
1171: {
1172: INTIDEAL=Primedivisor;
1173: }
1174: else
1175: {
1176: INTIDEAL=ideal_intersection_sfrat(Primedivisor,INTIDEAL,VSet);
1177: }
1178: }
1179: }
1180:
1181: /* We compute prime decomposition for remaining ideal */
1182: /* I+<ExtPoly> by recursive call. */
1183:
1184: if ( Strategy == 1 )
1185: {
1186: CHECK=radical_equality(INTIDEAL,ORIGINAL,VSet,Ord);
1187:
1188: if (CHECK==1)
1189: {
1.3 noro 1190: if ( dp_gr_print() ) {
1191: print("We already obtain all divisor. ");
1192: }
1.1 noro 1193: STOP = 1;
1194: return 0;
1195: }
1196: }
1197:
1198:
1199: if ( Dimension == 0 )
1200: {
1201: return 0;
1202: }
1203:
1204: Ord1 = [[0,length(TargetVSet)],[0,length(MSI)]];
1205: GP1 = dp_gr_f_main(GP,append(TargetVSet,MSI),Hom,Ord1);
1206: ExtpolyFactor=extcont_factor(GP1,TargetVSet,0);
1207:
1208: COUNTER=COUNTER+1;
1209:
1210: for ( Tmp = ExtpolyFactor; Tmp != []; Tmp = cdr(Tmp) )
1211: {
1212: AddPoly=car(Tmp);
1213:
1214: NewGP=cons(AddPoly,GP);
1215:
1216: GP1 = dp_gr_f_main(cons(AddPoly,GP),VSet,Hom,Ord);
1217:
1218: if ( Strategy == 1 )
1219: {
1220: CHECKADD=radical_equality(INTIDEAL,NewGP,VSet,Ord);
1221:
1222: if ( CHECKADD != 0 )
1223: {
1.3 noro 1224: if ( dp_gr_print() ) {
1225: print("Avoid unnecessary computation. ",2);
1226: }
1.1 noro 1227: continue;
1228: }
1229: }
1230:
1231:
1232: DimI=idealdimension(GP1,VSet,Ord)[0];
1233:
1234: if ( REM[ORIGINALDIMENSION-DimI] !=[] )
1235: {
1236: REM[ORIGINALDIMENSION-DimI]=cons(GP1,REM[ORIGINALDIMENSION-DimI]);
1237: }
1238: else
1239: {
1240: REM[ORIGINALDIMENSION-DimI]=[GP1];
1241: }
1242:
1243: /* primedecomposition(GP1,VSet,Ord,COUNTER,Strategy);
1244: if ( STOP == 1)
1245: {
1246: return 0;
1247: }*/
1248: }
1249: return 0;
1250: }
1251:
1252: /* returns 1 if Poly is a subset of Id(GB) */
1253: /* we assume GB is a gb wrt (V,Ord) */
1254:
1255: def inclusion_test(Poly,GB,V,Ord)
1256: {
1257: Len = length(GB);
1258: PS = newvect(Len);
1259: dp_ord(Ord);
1260: for ( J = 0, T = GB; T != []; T = cdr(T), J++ )
1261: PS[J] = dp_ptod(car(T),V);
1262: for ( J = Len-1, Ind = []; J >= 0; J-- )
1263: Ind = cons(J,Ind);
1264:
1265: for ( T = Poly; T != []; T = cdr(T) )
1266: if ( nf_sfrat(Ind,dp_ptod(car(T),V),1,PS)[0] )
1267: return 0;
1268: return 1;
1269: }
1270:
1271:
1272: def zeroprimedecomposition(P,TargetVSet,VSet)
1273: {
1274: /* We compute prime decomposition for an ideal <P> */
1275: /* such that <P> is 0-dimensional in K[TargetVSet]. */
1276:
1277: PD=partial_decomp(P,TargetVSet);
1278:
1279: /* each ideal in PD is an intermediate ideal, */
1280: /* i.e., all minimal polynomials are irreducible. */
1281: /* Thus, each ideal is very likely a prime ideal. */
1282: /* PD=[[P,MP],...], where P is a GB w.r.t. DRL and */
1283: /* MP is the set of all minimal polynomials. */
1284:
1285: NPD=length(PD);
1286: ANS=[];
1287:
1288: for (I=0;I<NPD;I++)
1289: {
1290: COMP=PD[I];
1291:
1292: /* check if the ideal has a variable in generic position*/
1293:
1294: CHECK=checkgeneric(COMP,TargetVSet,VSet);
1295:
1296: /* If there is a variable in generic position, then we apply a special */
1297: /* procedure (zerogenericprimedecomposition). Otherwise we apply a */
1298: /* general procedure (zeroseparableprimedecomposition). */
1299: /* */
1300: /* CHECK=[1,M], where M is the minimal polynomail of a variable x */
1301: /* such that x is in generic position, if there is such a variable x. */
1302: /* Otherwise, CHECK=0. */
1303:
1304: if (CHECK != 0 )
1305: {
1306: if ( TargetVSet != VSet )
1307: {
1308: PDiv=contraction(COMP[0],TargetVSet,VSet)[0];
1309: }
1310: else
1311: {
1312: PDiv=COMP[0];
1313: }
1314:
1315: ZDecomp=[PDiv];
1316:
1.3 noro 1317: if ( dp_gr_print() ) {
1318: print("An intermediate ideal is of generic type. ");
1319: }
1.1 noro 1320: }
1321: else
1322: {
1.3 noro 1323: if ( dp_gr_print() ) {
1324: print("An intermediate ideal is not of generic type. ",2);
1325: }
1.1 noro 1326:
1327: /* We compute the separable closure of <P> by using minimal polynomails.*/
1328: /* separableclosure outputs */
1329: /* [a GB Q of separable closure, the exponent vector]. */
1330: /* If <P> is already separable, then the exponent vector is 0. */
1331:
1332: Sep=separableclosure(COMP,TargetVSet,VSet);
1333:
1334: /* Then, we compute prime divisors of the separable closure by using */
1335: /* generic position. */
1336: /* If Sep[1]=0, COMP[0] is already separable ideal, and hence, */
1337: /* we do not apply radicalideal to its divisors. */
1338:
1339: if ( Sep[1] != 0 )
1340: {
1.3 noro 1341: if ( dp_gr_print() ) {
1342: print("The ideal is inseparable. ",2);
1343: }
1.1 noro 1344: CHECK2=checkgeneric2(Sep[2]);
1345: }
1346: else
1347: {
1.3 noro 1348: if ( dp_gr_print() ) {
1349: print("The ideal is already separable. ",2);
1350: }
1.1 noro 1351: }
1352:
1353: if ( Sep[1] !=0 && CHECK2 == 1 )
1354: {
1.3 noro 1355: if ( dp_gr_print() ) {
1356: print("The separable closure is of generic type. ",2);
1357: print("So, the intermediate ideal is prime or primary. ",2);
1358: }
1.1 noro 1359: PDiv=convertdivisor(Sep[0],TargetVSet,VSet,Sep[1]);
1360: if ( TargetVSet != VSet )
1361: {
1362: PDiv=contraction(PDiv,TargetVSet,VSet)[0];
1363: }
1364: Divisor=radicalideal(PDiv,2,VSet);
1365: ZDecomp=[Divisor];
1366: }
1367: else
1368: {
1369: #if 0
1370: ZSDecomp=zeroseparableprimedecomposition(Sep[0],TargetVSet,VSet);
1371: #else
1372: ZSDecomp=zerosepdec(Sep[0],TargetVSet,VSet,Ord);
1373: #endif
1374: /* We convert a prime separable ideal in K[TargetVSet] to its */
1375: /* corresponding prime ideal in K[VSet]. */
1376:
1377: NComp=length(ZSDecomp);
1378: ZDecomp=[];
1379:
1380: for (J=0;J<NComp;J++)
1381: {
1382: SDiv=ZSDecomp[J];
1383:
1384: /* First we convert a prime separable ideal in K[TargetVSet] to its */
1385: /* corresponding prime/primary ideal in K[TargetVSet] by computing the */
1386: /* image of Frobenius map. */
1387:
1388: PDiv=convertdivisor(SDiv,TargetVSet,VSet,Sep[1]);
1389:
1390: /* Then we compute the true prime divisor by contraction and radical */
1391: /* computation. */
1392:
1393: if ( TargetVSet != VSet )
1394: {
1395: PDiv=contraction(PDiv,TargetVSet,VSet)[0];
1396: }
1397:
1398: if (Sep[1] != 0 )
1399: {
1400: Divisor=radicalideal(PDiv,2,VSet);
1401: }
1402: else
1403: {
1404: Divisor=PDiv;
1405: }
1406:
1407:
1408: ZDecomp=append(ZDecomp,[Divisor]);
1409: }
1410: }
1411: }
1412:
1413: ANS=append(ANS, ZDecomp);
1414: }
1415: return map(monic_hc,ANS,VSet);
1416: }
1417:
1418: def monic_hc(Poly,V)
1419: {
1420: if ( type(Poly) == 4 )
1421: map(monic_hc,Poly,V);
1422: else {
1423: T = dp_ptod(Poly,V);
1424: return dp_dtop(T/dp_hc(T),V);
1425: }
1426: }
1427:
1428: def zeroseparableprimedecomposition(P,TargetVSet,VSet)
1429: {
1430: /* We compute prime decomposition for a separable */
1431: /* 0-dimensional ideal <P> in K[TargetVSet] by using */
1432: /* generic position. */
1433:
1434: ANS=[];
1435: Ord=0;
1436:
1437: NVSet=length(TargetVSet);
1438:
1439: /* The P is already a GB w.r.t. DRL. So, the following */
1440: /* must be replaced with NewP=P. */
1441:
1442: /* NewGP=dp_gr_f_main(P,TargetVSet,Hom,Ord); */
1443: NewGP = P;
1444:
1445: /* We search a polynomial f in generic position. */
1446: /* Generic=[f, minimal polynomial of f in newt, newt], */
1447: /* where newt (X) is a newly introduced variable. */
1448:
1.3 noro 1449: if ( dp_gr_print() ) {
1450: print("We search for a linear sum of variables in generic position. ",2);
1451: }
1.1 noro 1452: Generic=findgeneric(NewGP,TargetVSet,VSet);
1453:
1454: X=Generic[2]; /* newly introduced variable */
1455: Factors=sffctr(Generic[1]);
1456: NFactors=length(Factors);
1457: /* irreducible case */
1458: if ( NFactors == 2 && Factors[1][1] == 1 )
1459: return [NewGP];
1460: #if 0
1461: for (J=1;J<NFactors;J++)
1462: {
1463: AddPoly=Factors[J][0];
1464: AddPoly2=X-Generic[0];
1465:
1466: TestGP=append(NewGP,[AddPoly, AddPoly2]);
1467: VS=cons(X,TargetVSet);
1468: Q=dp_gr_f_main(TestGP,VS,Hom,[[0,1],[Ord,NVSet]]);
1469: QR=elimination(Q,VSet);
1470: ANS=append(ANS,[QR]);
1471: }
1472: #else
1473: /* noro */
1474: dp_ord([[0,1],[Ord,NVSet]]);
1475: XVSet = cons(X,TargetVSet);
1476: PS = newvect(length(NewGP)+1,map(dp_ptod,cons(X-Generic[0],NewGP),XVSet));
1477: for ( I = length(NewGP), Ind = [];I >= 0; I-- )
1478: Ind = cons(I,Ind);
1479: Ind = reverse(Ind);
1480: YSet = setminus(VSet,TargetVSet);
1481: NYSet = length(YSet);
1482: ElimVSet = append(TargetVSet,YSet);
1483: ElimOrd = [[Ord,NVSet],[0,NYSet]];
1484: for ( J = 1; J < NFactors; J++ ) {
1485: dp_ord([[0,1],[Ord,NVSet]]);
1486: Factor = dp_dtop(nf_sfrat(Ind,dp_ptod(Factors[J][0],XVSet),1,PS)[0],XVSet);
1487: #if 0
1488: Q = dp_gr_f_main(cons(Factor,NewGP),ElimVSet,Hom,ElimOrd);
1489: #else
1490: Q0 = dp_gr_f_main(cons(Factor,NewGP),ElimVSet,Hom,0);
1491: Q = dp_gr_f_main(Q0,ElimVSet,Hom,ElimOrd);
1492: #endif
1493: Q = dp_gr_f_main(Q,TargetVSet,Hom,Ord);
1494: ANS = cons(Q,ANS);
1495: }
1496: #endif
1497: return ANS;
1498: }
1499:
1500: /* partial decomposition by sums of variables
1501: -> zeroseparableprimedecomposition */
1502:
1503: #if 0
1504: def zerosepdec(P,W,V,Ord)
1505: {
1506: /* P is GB wrt (W,Ord) */
1507: dp_ord(Ord);
1508: DIM = length(dp_mbase(map(dp_ptod,P,W)));
1509: /* preprocessing */
1510: N = length(W);
1511: C = newvect(N);
1512: C[0] = 1;
1513: Vt = ttttt;
1514: do {
1515: for ( I = 0, LF = 0; I < N; I++ )
1516: if ( C[I] ) LF += W[I];
1517: LF = simp_ff(LF);
1518: MP = minipoly_sf(P,W,Ord,LF,Vt);
1519: Factors = map(first,cdr(sffctr(MP)));
1520: if ( deg(MP,Vt) == DIM ) {
1521: if ( length(Factors) == 1 )
1522: return [P];
1523: else
1524: return zerosepdec_main(P,W,V,Ord,map(subst,Factors,Vt,LF));
1525: } else if ( length(Factors) > 1 ) {
1526: R = zerosepdec_main(P,W,V,Ord,map(subst,Factors,Vt,LF));
1527: S = [];
1528: for ( TR = R; TR != []; TR = cdr(TR) )
1529: S = append(zerosepdec(car(TR),W,V,Ord),S);
1530: return S;
1531: }
1532: } while ( !nextchoice(C) );
1533: /* we could not find any useful combination */
1534: R = zeroseparableprimedecomposition(P,W,V);
1535: return R;
1536: }
1537: #else
1538:
1539: /* we only search for useful poly among v[i]+v[j] */
1540: def zerosepdec(P,W,V,Ord)
1541: {
1542: /* P is GB wrt (W,Ord) */
1543: dp_ord(Ord);
1544: DIM = length(dp_mbase(map(dp_ptod,P,W)));
1545: /* preprocessing */
1546: N = length(W);
1547: C = newvect(N);
1548: C[0] = 1;
1549: Vt = ttttt;
1550: for ( I1 = 0; I1 < N; I1++ )
1551: for ( I2 = I1+1; I2 < N; I2++ ) {
1552: LF = simp_ff(W[I1]+W[I2]);
1553: MP = minipoly_sf(P,W,Ord,LF,Vt);
1554: Factors = map(first,cdr(sffctr(MP)));
1555: if ( deg(MP,Vt) == DIM ) {
1556: if ( length(Factors) == 1 )
1557: return [P];
1558: else
1559: return zerosepdec_main(P,W,V,Ord,map(subst,Factors,Vt,LF));
1560: } else if ( length(Factors) > 1 ) {
1561: R = zerosepdec_main(P,W,V,Ord,map(subst,Factors,Vt,LF));
1562: S = [];
1563: for ( TR = R; TR != []; TR = cdr(TR) )
1564: S = append(zerosepdec(car(TR),W,V,Ord),S);
1565: return S;
1566: }
1567: }
1568: /* we could not find any useful combination */
1569: R = zeroseparableprimedecomposition(P,W,V);
1570: return R;
1571: }
1572: #endif
1573:
1574: def zerosepdec_main(P,W,V,Ord,Factors)
1575: {
1576: dp_ord(Ord);
1577: N = length(P);
1578: NFactors = length(Factors);
1579: PS = newvect(length(P),map(dp_ptod,P,W));
1580: for ( I = length(P)-1, Ind = [];I >= 0; I-- )
1581: Ind = cons(I,Ind);
1582: Y= setminus(V,W);
1583: NW = length(W);
1584: NY = length(Y);
1585: ElimV = append(W,Y);
1586: ElimOrd = [[Ord,NW],[0,NY]];
1587: ANS = [];
1588: for ( J = 0; J < NFactors; J++ ) {
1589: Factor = dp_dtop(nf_sfrat(Ind,dp_ptod(Factors[J],W),1,PS)[0],W);
1590: Q = dp_gr_f_main(cons(Factor,P),ElimV,Hom,ElimOrd);
1591: Q = dp_gr_f_main(Q,W,Hom,Ord);
1592: ANS = cons(Q,ANS);
1593: }
1594: return ANS;
1595: }
1596:
1597: def nextchoice(C)
1598: {
1599: N = size(C)[0];
1600: for ( I = N-1, Carry = 1; I >= 0; I-- ) {
1601: if ( C[I] ) {
1602: C[I] = !Carry;
1603: Carry = !C[I];
1604: } else {
1605: C[I] = Carry;
1606: Carry = 0;
1607: }
1608: }
1609: return Carry;
1610: }
1611:
1612: def separableclosure(CP,TargetVSet,VSet)
1613: {
1614: /* We compute a separable ideal <Q> from <P> by */
1615: /* computing inverse Frobenius map. */
1616:
1617: Ord=0;
1618:
1619: NVSet=length(TargetVSet);
1620: IndexVector=newvect(NVSet);
1621:
1622: /* First we check if <P> is already separable. */
1623: /* CHECK == 1 if <P> is already separable, */
1624: /* Otherwise, CHECK is the list of pairs of */
1625: /* the separable closure sc(m) of the minimal polynomial*/
1626: /* m and the exponent e, i.e. m=sc(m)(t^(q^e)). */
1627:
1628: CHECK=checkseparable(CP,TargetVSet,VSet);
1629:
1630: if ( CHECK == 1 )
1631: {
1.3 noro 1632: if ( dp_gr_print() ) {
1633: print("This is already a separable ideal.", 2);
1634: }
1.1 noro 1635: return [CP[0],0];
1636: }
1637:
1.3 noro 1638: if ( dp_gr_print() ) {
1639: print("This is not a separable ideal, so we make its separable closure.", 2);
1640: }
1.1 noro 1641: WSet=makecounterpart(TargetVSet);
1.6 noro 1642: Char=characteristic_ff();
1.1 noro 1643:
1644: NewP=CP[0];
1645: EXPVECTOR=newvect(NVSet);
1646: CHECKEXPVECTOR=newvect(NVSet);
1647:
1648: for (I=0;I<NVSet;I++)
1649: {
1650: EXPVECTOR[I]=CHECK[NVSet-I-1][0];
1651: CHECKEXPVECTOR[I]=deg(CHECK[NVSet-I-1][1],TargetVSet[I]);
1652:
1653: POW=Char^CHECK[NVSet-I-1][0];
1654:
1655: AddPoly=TargetVSet[I]^POW-WSet[I];
1656: /*SepClosure=subst(CHECK[I][0],TargetVSet[I],WSet[I]);*/
1657:
1658: NewP=cons(AddPoly,NewP);
1659: }
1660:
1661: NewOrder=[[Ord,NVSet],[Ord,NVSet]];
1662: XSet=append(TargetVSet,WSet);
1663: YSet=append(VSet,WSet);
1664:
1665: NewG=dp_gr_f_main(NewP,XSet,Hom,NewOrder);
1666:
1667: NWSet=setminus(YSet,TargetVSet);
1668:
1669: Q=elimination(NewG,NWSet);
1670:
1671: NQ=length(Q);
1672:
1673: ANS=[];
1674: for (I=NQ-1;I>=0;I--)
1675: {
1676: Poly=Q[I];
1677: for (J=0;J<NVSet;J++)
1678: {
1679: Poly=subst(Poly,WSet[J],TargetVSet[J]);
1680: }
1681: ANS=cons(Poly,ANS);
1682: }
1683: return [ANS,EXPVECTOR,CHECKEXPVECTOR];
1684: }
1685:
1686: def convertdivisor(P,TargetVSet,VSet,ExVector)
1687: {
1688: /* We compute a corresponding ideal <Q> from <P> by */
1689: /* computing Frobenius map. */
1690:
1691: if (ExVector == 0 )
1692: {
1693: return P;
1694: }
1695:
1696: NVSet=length(TargetVSet);
1697: WSet=makecounterpart(TargetVSet);
1.6 noro 1698: Char=characteristic_ff();
1.1 noro 1699: Ord=0;
1700:
1701: NewP=P;
1702:
1703: for (I=0;I<NVSet;I++)
1704: {
1705: POW=Char^ExVector[I];
1706:
1707: AddPoly=TargetVSet[I]-WSet[I]^POW;
1708: /*SepClosure=subst(CHECK[I][0],TargetVSet[I],WSet[I]);*/
1709:
1710: NewP=cons(AddPoly,NewP);
1711: }
1712:
1713: NewOrder=[[Ord,NVSet],[Ord,NVSet]];
1714:
1715: XSet=append(TargetVSet,WSet);
1716: YSet=append(VSet,WSet);
1717:
1718: NewG=dp_gr_f_main(NewP,XSet,Hom,NewOrder);
1719:
1720: NWSet=setminus(YSet,TargetVSet);
1721:
1722: Q=elimination(NewG,NWSet);
1723:
1724: NQ=length(Q);
1725:
1726: ANS=[];
1727: for (I=NQ-1;I>=0;I--)
1728: {
1729: Poly=Q[I];
1730: for (J=0;J<NVSet;J++)
1731: {
1732: Poly=subst(Poly,WSet[J],TargetVSet[J]);
1733: }
1734: ANS=cons(Poly,ANS);
1735: }
1736: return ANS;
1737: }
1738:
1739:
1740: def findgeneric(P,TargetVSet,VSet)
1741: {
1742: /* The number of trials is set as Trails. */
1743: NTargetVSet=length(TargetVSet);
1744: MNumber=0;
1745: /* Trials=100;*/
1746:
1747: if ( Trials == 0 )
1748: Trials = 2;
1749:
1750: Lineardimension=lineardimension(P,TargetVSet);
1751: NewVar=newt;
1752: Count=0;
1753: Ord=0;
1754:
1755: #if 0
1756: while(Count < Trials )
1757: {
1758: Candidate=0;
1759: MNumber=MNumber+1;
1760:
1761: MAGIC=makemagic(TargetVSet,MNumber);
1762:
1763: for (I=0;I<NTargetVSet;I++)
1764: {
1765: Candidate=Candidate+MAGIC[I]*TargetVSet[I];
1766: }
1767: MinPoly=minipoly_sf(P,TargetVSet,Ord,Candidate,NewVar);
1768: Deg=deg(MinPoly,NewVar);
1769: if ( Deg == Lineardimension )
1770: {
1771: return [Candidate,MinPoly,NewVar];
1772: }
1773: Count=Count+1;
1774: }
1775: #else
1776: YSet = setminus(VSet,TargetVSet);
1777: NYSet = length(YSet);
1778: Eval = newvect(NYSet);
1779: Q1 = field_order_ff()-1;
1780: HM = hmlist(P,TargetVSet,Ord);
1781: for ( Count = 0; Count < Trials; Count++ ) {
1782: Candidate = ptosfp(2)*TargetVSet[0];
1783: Candidate = 0;
1784: for ( I = 0; I < NTargetVSet; I++ )
1785: Candidate += random_ff()*TargetVSet[I];
1786: do {
1787: for ( I = 0; I < NYSet; I++ )
1788: Eval[I] = random()%Q1;
1789: } while ( !valid_modulus_sfrat(HM,YSet,Eval) );
1790: P0 = map(eval_sfrat,P,YSet,Eval);
1791: MinPoly0 = minipoly_sf(P0,TargetVSet,Ord,Candidate,NewVar);
1792: Deg = deg(MinPoly0,NewVar);
1793: if ( Deg == Lineardimension ) {
1794: MinPoly=minipoly_sf(P,TargetVSet,Ord,Candidate,NewVar);
1795: if ( deg(MinPoly,NewVar) != Deg )
1796: error("findgeneric : cannot happen");
1797: return [Candidate,MinPoly,NewVar];
1798: }
1799: }
1800: #endif
1.3 noro 1801: if ( dp_gr_print() ) {
1802: print("Extend the ground field. ",2);
1803: }
1.1 noro 1804: error();
1805: }
1806:
1807: def makemagic(VSet,MNumber)
1808: {
1809: NVSet=length(VSet);
1810: MAGIC=[1];
1811: for (I=1;I<NVSet;I++)
1812: {
1813: U=ptosfp(MNumber^I);
1814: MAGIC=append(MAGIC,[U]);
1815: }
1816: return MAGIC;
1817: }
1818:
1819: #if 0
1820: def zerogenericprimedecomposition(CP,MinP,TargetVSet,VSet)
1821: {
1822: P=CP[0];
1823:
1824: FACTORS=sffctr(MinP);
1825: NFACTORS=length(FACTORS);
1826:
1827: if ( NFACTORS == 2 )
1828: {
1829: return [P];
1830: }
1831:
1832: ANS=[];
1833:
1834: for (I=1;I<NFACTORS;I++)
1835: {
1836: AddPoly=NFACTORS[I][0];
1837: NewP=cos(AddPoly,P);
1838: NewG=dp_gr_f_main(NewP,TargetVSet,Hom,Ord);
1839: ANS=cons(NewG,ANS);
1840: }
1841: return ANS;
1842: }
1843: #endif
1844:
1845:
1846: def lineardimension(P,VSet)
1847: {
1848: Ord=0;
1849:
1850: PP=dp_gr_f_main(P,VSet,Hom,Ord);
1851: dp_ord(Ord);
1852: Dimension=length(dp_mbase(map(dp_ptod,PP,VSet)));
1853: return Dimension;
1854: }
1855:
1856: def checkgeneric(CP,TargetVSet,VSet)
1857: {
1858: Dimension=lineardimension(CP[0],TargetVSet);
1859: NVSet=length(TargetVSet);
1860: Flag=0;
1861:
1862: for (I=0;I<NVSet;I++)
1863: {
1864: MinP=CP[1][I];
1865:
1866: if ( deg(MinP,TargetVSet[NVSet-I-1]) == Dimension )
1867: {
1868: return [1,MinP];
1869: }
1870: }
1871: return 0;
1872: }
1873:
1874: def checkseparable(CP,TargetVSet,VSet)
1875: {
1876: NVSet=length(TargetVSet);
1877: EXPVector=newvect(NVSet);
1878: Flag=1;
1879:
1880: for (I=0;I<NVSet;I++)
1881: {
1882: MinP=CP[1][I];
1883: CHECK=checkseparablepoly(MinP,TargetVSet[NVSet-I-1]);
1884: if ( CHECK[0] != 0 )
1885: {
1886: Flag = 0;
1887: }
1888: EXPVector[I]=CHECK;
1889: }
1890: if ( Flag == 0 )
1891: {
1892: return EXPVector;
1893: }
1894: return 1;
1895: }
1896:
1897: def checkseparablepoly(F,V)
1898: {
1899: P = characteristic_ff();
1900: E = 0;
1901: Vt = newt;
1902: while ( 1 ) {
1903: if ( diff(F,V) != 0 )
1904: return [E,F];
1905: T = srem(F,V^P-Vt,V);
1906: F = subst(T,Vt,V);
1907: E++;
1908: }
1909: }
1910:
1911: def extcont(P,V,Ord)
1912: {
1913: /* We assume P is a Groebner Basis w.r.t. Ord. */
1914: /* We compute a polynomial f such that */
1915: /* \sqrt{<P>}=\sqrt{<P>+<f>}\cap \sqrt{(<P>)^{ec}} */
1916: /* by B.W. Proposition 8.96. */
1917: /* Remark: The square free part of f is also OK. */
1918:
1919: dp_ord(Ord);
1920: HC = map(dp_hc,map(dp_ptod,P,V));
1921: LCM = car(HC);
1922: for ( T = cdr(HC); T != []; T = cdr(T) )
1923: LCM = lcm_sfrat(LCM,car(T));
1924: return LCM;
1925: }
1926:
1927: def first(A)
1928: {
1929: return A[0];
1930: }
1931:
1932: def set_union(A,B)
1933: {
1934: for ( T = A; T != []; T = cdr(T) )
1935: B = insert_element(car(T),B);
1936: return B;
1937: }
1938:
1939: def insert_element(E,A)
1940: {
1941: for ( T = A; T != []; T = cdr(T) )
1942: if ( E == car(T) )
1943: break;
1944: if ( T == [] )
1945: return cons(E,A);
1946: else
1947: return A;
1948: }
1949:
1950: def extcont_factor(P,V,Ord)
1951: {
1952: /* We assume P is a Groebner Basis w.r.t. Ord. */
1953: /* We compute a polynomial f such that */
1954: /* \sqrt{<P>}=\sqrt{<P>+<f>}\cap \sqrt{(<P>)^{ec}} */
1955: /* by B.W. Proposition 8.96. */
1956: /* Remark: The square free part of f is also OK. */
1957:
1958: dp_ord(Ord);
1959: HC = map(dp_hc,map(dp_ptod,P,V));
1960: F = [];
1961: for ( T = HC; T != []; T = cdr(T) ) {
1962: F1 = map(first,cdr(sffctr(car(T))));
1963: F = set_union(F1,F);
1964: }
1965: return F;
1966: }
1967:
1968: def contraction(P,V,W)
1969: {
1970: /* We assume P is a Groebner Basis w.r.t. Ord. */
1971: /* We compute the contraction <P>^{c} by */
1972: /* <P>^c=(<G>:f^\infty) */
1973: /* by B.W. Proposition 8.91. */
1974: /* This procedure is called by zeroprimedecomposition. */
1975: /* So, P is supposed to be a GB w.r.t. DRL. */
1976:
1977: Ord=0;
1978: YSet=setminus(W,V);
1979:
1980: Ord1 = [[Ord,length(V)],[0,length(YSet)]];
1.14 ! noro 1981: W1 = append(V,YSet);
! 1982: GP1 = dp_gr_f_main(P,W1,Hom,Ord1);
1.1 noro 1983:
1984: Factor = extcont_factor(GP1,V,Ord);
1985: for ( F = 1, T = Factor; T != []; T = cdr(T) )
1986: F *= car(T);
1987: Vt = newt;
1988:
1989: G = dp_gr_f_main(cons(1-Vt*F,P),cons(Vt,W),0,[[0,1],[Ord,length(W)]]);
1990: R = [];
1991: for ( T = G; T != []; T = cdr(T) )
1992: if ( !member(Vt,vars(car(T))) )
1993: R = cons(car(T),R);
1994: return [R,F];
1995: }
1996:
1997: def checkgeneric2(LIST)
1998: {
1999: NList=size(LIST)[0];
2000:
2001: FLAG=0;
2002:
2003: for (I=0;I<NList;I++)
2004: {
2005: if ( LIST[I] > 1 )
2006: {
2007: FLAG=FLAG+1;
2008: }
2009: }
2010:
2011: if (FLAG < 2 )
2012: {
2013: return 1;
2014: }
2015: return 0;
2016: }
2017:
2018: #if 0
2019: def checkseparablepoly(P,V)
2020: {
2021: TestP=P;
2022: CHECK=diff(TestP,V);
2023: Count=0;
2024:
2025: while ( CHECK !=0 )
2026: {
2027: if ( deg(TestP,V) != 0 )
2028: {
2029: break;
2030: }
2031: TestP=pdivide(TestP);
2032: CHECK=diff(TestP,V);
2033: Count=Count+1;
2034: }
2035:
2036: return [TestP,Count];
2037: }
2038:
2039: def pdivide(F,V)
2040: {
1.6 noro 2041: Char=characteristic_ff();
1.1 noro 2042: TestP=P;
2043:
2044: Deg=ideg(TestP,V);
2045: DegP=idiv(Deg,Char);
2046:
2047: if ( irem(Deg,Char) != 0 )
2048: {
2049: error;
2050: }
2051: ANS=0;
2052:
2053: for (I=O;I<DegP;I++)
2054: {
2055: TempDeg=I*Char;
2056: ANS=ANS+coeff(TestP,V,TempDeg)*X^I;
2057: }
2058: return ANS;
2059: }
2060: #endif
2061:
2062:
2063: def convsf(PP,VSet,Ord,Flag)
2064: {
2065: /* Flag = 0 or 1 */
2066: /* If Flag = 1, we compute the intersection */
2067: /* of the Galois orbit. */
2068:
2069: CHECK=checkgaloisorbit(PP,VSet,Ord,Flag);
2070:
2071: NewPP=CHECK[0];
2072:
2073: ANS=[];
2074:
2075: NPP=length(NewPP);
2076:
2077: for (I=0;I<NPP;I++)
2078: {
2079: NewComp=convertsmallfield(CHECK[Flag][I],VSet,Ord);
2080: ANS=cons(NewComp,ANS);
2081: }
2082: return ANS;
2083: }
2084:
2085: def convertsmallfield(PP,VSet,Ord)
2086: {
2087: dp_ord(Ord);
2088: NVSet=length(VSet);
1.6 noro 2089: Char=characteristic_ff();
2090: ExtDeg=extdeg_ff();
1.1 noro 2091:
1.5 noro 2092: NewV=pgpgpgpgpgpgpg;
1.1 noro 2093: MPP=map(monic_hc,PP,VSet);
2094: MPP=map(sfptopsfp,MPP,NewV);
2095:
1.6 noro 2096: DefPoly=setmod_ff()[1];
1.9 noro 2097: /* GF(p) case */
2098: if ( !DefPoly )
2099: return MPP;
2100:
1.6 noro 2101: MinPoly=subst(DefPoly,var(DefPoly),NewV);
1.1 noro 2102: XSet=cons(NewV,VSet);
2103:
2104: Ord1=[[0,1],[Ord,NVSet]];
2105:
2106: /* setmod_ff(Char,1);*/
2107:
2108: NewP=dp_gr_mod_main(cons(MinPoly,MPP),XSet,0,Char,Ord1);
2109:
2110: ANS=elimination(NewP,VSet);
2111:
2112: /* setmod_ff(Char,ExtDeg);*/
2113:
2114: return ANS;
2115: }
2116:
2117: def checkgaloisorbit(PP,VSet,Ord,Flag)
2118: {
2119: NPP=length(PP);
2120: TmpPP=PP;
1.6 noro 2121: ExtDeg=extdeg_ff();
1.1 noro 2122:
2123: ANS=[];
2124: BNS=[];
2125:
2126: while (TmpPP != [] )
2127: {
2128: TestP=car(TmpPP);
2129: Dim=TestP[1];
2130: TmpPP=cdr(TmpPP);
2131: NewP=TestP[0];
2132:
2133: ANS=cons(TestP[0],ANS);
2134:
2135: for (J=1;J<ExtDeg;J++)
2136: {
2137: G1=map(sf_galois_action,TestP[0],J);
2138:
2139: if ( setminus(G1,TestP[0]) == [] )
2140: {
2141: break;
2142: }
2143: if (Flag == 1 )
2144: {
2145: NewP=ideal_intersection_sfrat(NewP,G1,VSet);
2146: }
2147: TmpPP=deletecomponent(TmpPP,[G1,Dim]);
2148: }
2149: BNS=cons(NewP,BNS);
2150:
2151: }
2152: return [ANS,BNS];
2153: }
2154:
2155: def deletecomponent(PP,G)
2156: {
2157: TmpPP=PP;
2158:
2159: while( TmpPP !=[] )
2160: {
2161: Test=car(TmpPP)[0];
2162:
2163: if ( setminus(Test,G[0]) == [] )
2164: {
2165: ANS=setminus(PP,[G]);
2166: return ANS;
2167: }
2168:
2169: TmpPP=cdr(TmpPP);
2170: }
2171: error();
2172: }
2173:
2174:
2175: def pfctr(F)
2176: {
2177: if ( type(F) == 1 )
2178: return [[F,1]];
2179: P = characteristic_ff();
2180: E = extdeg_ff();
2181: F = sfptop(F);
2182: check_coef(F,P);
2183: D = modfctr(F,P);
2184: setmod_ff(P,E);
2185: return map(mapsf_first,D);
2186: }
2187:
2188: def check_coef(F,P)
2189: {
2190: V = vars(F);
2191: D = dp_ptod(F,V);
2192: for ( T = D; T; T = dp_rest(T) )
2193: if ( dp_hc(T) >= P )
2194: error("invalid coef");
2195: }
2196:
2197: def mapsf_first(D)
2198: {
2199: return [ptosfp(D[0]),D[1]];
2200: }
2201:
2202: def partial_decomp(B,V)
2203: {
2204: T0 = time();
2205: if ( ParallelMinipoly ) {
2206: map(ox_cmo_rpc,ParallelMinipoly,"setmod_ff",characteristic_ff(),extdeg_ff());
2207: map(ox_pop_cmo,ParallelMinipoly);
2208: }
1.10 noro 2209: B = map(simp_ff,B);
1.1 noro 2210: B = dp_gr_f_main(B,V,0,0);
2211: R = partial_decomp0(B,V,length(V)-1);
2212: if ( PartialDecompByLex ) {
2213: R0 = [];
2214: for ( TR = R; TR != []; TR = cdr(TR) ) {
2215: T = car(TR);
2216: S = dp_gr_f_main(T[0],V,0,0);
2217: R0 = cons([S,T[1]],R0);
2218: }
2219: R = reverse(R0);
2220: }
2221: T_PD += time()[3]-T0[3];
2222: return R;
2223: }
2224:
2225: def setintersection(A,B)
2226: {
2227: for ( L = []; A != []; A = cdr(A) )
2228: if ( member(car(A),B) )
2229: L = cons(car(A),L);
2230: return L;
2231: }
2232:
2233: /* returns [[Plist,Mlist],...] */
2234:
2235: def partial_decomp0(B,V,I)
2236: {
2237: N = length(V);
2238: if ( I < 0 )
2239: return [[B,[]]];
2240: Ord = PartialDecompByLex ? [[0,I],[2,N-I]] : 0;
2241: #if 0
2242: if ( setminus(vars(B),V) == [] )
2243: B = fglm_sf_0dim(B,V,Ord0,Ord);
2244: else
2245: #endif
2246: B = dp_gr_f_main(B,V,0,Ord);
2247: if ( type(B[0]) == 1 )
2248: return [];
2249: if ( !zero_dim(B,V,Ord) )
2250: error("non zero-dimensional ideal");
2251: /* XXX */
2252: Vt = ttttt;
2253: VI = V[I];
2254: if ( PartialDecompByLex ) {
2255: for ( J = 0, W = V; J < I; J++ )
2256: W = cdr(W);
2257: VW = setminus(V,W);
2258: for ( Bw = [], T = B; T != []; T = cdr(T) )
2259: if ( setintersection(vars(car(T)),VW) == [] )
2260: Bw = cons(car(T),Bw);
2261: MI = minipoly_sf(Bw,W,2,VI,Vt);
2262: } else
2263: MI = minipoly_sf(B,V,0,VI,Vt);
2264: MIF = sffctr(MI);
2265: /* if MI is irreducible, then process the next variable */
2266: if ( length(MIF) == 2 && MIF[1][1] == 1 ) {
2267: L = partial_decomp0(B,V,I-1);
2268: R = [];
2269: for ( S = L; S != []; S = cdr(S) ) {
2270: L = car(S);
2271: R = cons([L[0],cons(subst(MI,Vt,VI),L[1])],R);
2272: }
2273: return R;
2274: }
2275:
2276: /* for nf computation */
2277: Ord1 = PartialDecompByLex ? 2 : [[0,1],[0,N]];
2278: Len = length(B);
2279: PS = newvect(Len+1);
2280: dp_ord(Ord1);
2281: XV = cons(Vt,V);
2282: for ( J = 0, T = cons(Vt-VI,B); T != []; T = cdr(T), J++ )
2283: PS[J] = dp_ptod(car(T),XV);
2284: for ( J = 0, GI = []; J <= Len; J++ )
2285: GI = cons(J,GI);
2286: if ( PartialDecompByLex )
2287: GI = reverse(GI);
2288:
2289: R = [];
2290: for ( T = MIF; T != []; T = cdr(T) ) {
2291: Mt = car(car(T));
2292: if ( type(Mt) == 1 )
2293: continue;
2294: dp_ord(Ord1);
2295: NfMt = dp_dtop(nf_sfrat(GI,dp_ptod(Mt,XV),1,PS)[0],XV);
2296: if ( NfMt )
2297: B1 = dp_gr_f_main(cons(NfMt,B),V,0,Ord);
2298: else
2299: B1 = B;
2300: Rt = partial_decomp0(B1,V,I-1);
2301: for ( S = Rt; S != []; S = cdr(S) ) {
2302: L = car(S);
2303: R = cons([L[0],cons(subst(Mt,Vt,VI),L[1])],R);
2304: }
2305: }
2306: return R;
2307: }
2308:
2309:
2310: /* G is a gb wrt (V,O) */
2311:
2312: def minipoly_sf(G,V,O,F,V0)
2313: {
2314: T0 = time();
2315: Vc = cons(V0,setminus(vars(G),V));
2316: if ( ParallelMinipoly ) {
2317: Proc0 = ParallelMinipoly[0];
2318: Proc1 = ParallelMinipoly[1];
2319: if ( length(Vc) == 1 ) {
2320: ox_rpc(Proc0,"minipoly_sf_by_buchberger",G,V,O,F,V0,1);
2321: ox_rpc(Proc1,"minipoly_sf_0dim",G,V,O,F,V0,1);
2322: map(ox_get,ParallelMinipoly);
2323: /* 258=SM_popSerializedLocalObject */
2324: map(ox_push_cmd,ParallelMinipoly,258);
2325: F = ox_select(ParallelMinipoly);
2326: MP = ox_get(F[0]);
2327: if ( F[0] == Proc0 ) {
2328: if ( length(F) == 1 )
2329: B_Win++;
2330: else
2331: ox_get(Proc1);
2332: } else {
2333: if ( length(F) == 1 )
2334: D_Win++;
2335: else
2336: ox_get(Proc0);
2337: }
2338: ox_reset(Proc0);
2339: ox_reset(Proc1);
2340: } else if ( length(Vc) == 2 ) {
2341: ox_rpc(Proc0,"minipoly_sf_by_buchberger",G,V,O,F,V0,1);
2342: ox_rpc(Proc1,"minipoly_sfrat",G,V,O,F,V0,1);
2343: map(ox_get,ParallelMinipoly);
2344: /* 258=SM_popSerializedLocalObject */
2345: map(ox_push_cmd,ParallelMinipoly,258);
2346: F = ox_select(ParallelMinipoly);
2347: MP = ox_get(F[0]);
2348: if ( F[0] == Proc0 ) {
2349: if ( length(F) == 1 )
2350: B_Win++;
2351: else
2352: ox_get(Proc1);
2353: } else {
2354: if ( length(F) == 1 )
2355: D_Win++;
2356: else
2357: ox_get(Proc0);
2358: }
2359: ox_reset(Proc0);
2360: ox_reset(Proc1);
2361: } else
2362: MP = minipoly_sf_by_buchberger(G,V,O,F,V0,0);
2363: } else if ( BuchbergerMinipoly )
2364: MP = minipoly_sf_by_buchberger(G,V,O,F,V0,0);
2365: else {
2366: if ( length(Vc) == 1 )
2367: MP = minipoly_sf_0dim(G,V,O,F,V0,0);
2368: else if ( length(Vc) == 2 )
2369: MP = minipoly_sfrat(G,V,O,F,V0,0);
2370: else
2371: MP = minipoly_sf_by_buchberger(G,V,O,F,V0,0);
2372: }
2373: T_MP += time()[3]-T0[3];
2374: return MP;
2375: }
2376:
2377: def minipoly_sf_by_buchberger(G,V,O,F,V0,Server)
2378: {
2379: if ( Server )
2380: ox_sync(0);
2381: Vc = cons(V0,setminus(vars(G),V));
1.10 noro 2382: Gf = cons(simp_ff(V0-F),G);
1.1 noro 2383: Vf = append(V,Vc);
2384: Gelim = dp_gr_f_main(Gf,Vf,1,[[0,length(V)],[0,length(Vc)]]);
2385: for ( Gc = [], T = Gelim; T != []; T = cdr(T) ) {
2386: Vt = setminus(vars(car(T)),Vc);
2387: if ( Vt == [] )
2388: Gc = cons(car(T),Gc);
2389: }
2390: Gt = dp_gr_f_main(Gc,Vc,1,[[0,1],[0,length(Vc)-1]]);
2391: Pmin = car(Gt); Dmin = deg(Pmin,V0);
2392: for ( T = cdr(Gt); T != []; T = cdr(T) ) {
2393: Dt = deg(car(T),V0);
2394: if ( Dt < Dmin ) {
2395: Pmin = car(T); Dmin = Dt;
2396: }
2397: }
2398: Cont = sfcont(Pmin,V0);
2399: return sdiv(Pmin,Cont);
2400: }
2401:
2402: def minipoly_sf_0dim(G,V,O,F,V0,Server)
2403: {
2404: if ( Server )
2405: ox_sync(0);
2406: N = length(V);
2407: Len = length(G);
2408: dp_ord(O);
2409: PS = newvect(Len);
2410: for ( I = 0, T = G; T != []; T = cdr(T), I++ )
2411: PS[I] = dp_ptod(car(T),V);
2412: for ( I = Len-1, HL = []; I >= 0; I-- )
2413: HL = cons(dp_ht(PS[I]),HL);
2414: for ( I = Len - 1, GI = []; I >= 0; I-- )
2415: GI = cons(I,GI);
2416: MB = dp_mbase(HL); DIM = length(MB); UT = newvect(DIM);
1.10 noro 2417: U = dp_ptod(simp_ff(F),V);
1.1 noro 2418: U = dp_nf_f(GI,U,PS,1);
2419: for ( I = 0; I < DIM; I++ )
2420: UT[I] = [MB[I],dp_nf_f(GI,U*MB[I],PS,1)];
2421:
1.10 noro 2422: T = dp_ptod(simp_ff(1),[V0]);
2423: TT = dp_ptod(simp_ff(1),V);
1.1 noro 2424: G = H = [[TT,T]];
2425:
2426: for ( I = 1; ; I++ ) {
2427: if ( dp_gr_print() )
2428: print(".",2);
1.10 noro 2429: T = dp_ptod(simp_ff(V0^I),[V0]);
1.1 noro 2430: TT = dp_nf_tab_f(H[0][0],UT);
2431: H = cons([TT,T],H);
2432: L = dp_lnf_f([TT,T],G);
2433: if ( !L[0] ) {
2434: if ( dp_gr_print() )
2435: print("");
2436: return dp_dtop(L[1],[V0]); /* XXX */
2437: } else
2438: G = insert(G,L);
2439: }
2440: }
2441:
2442: #if 1
2443: def minipoly_sf_rat(G,V,F,V0)
2444: {
2445: Vc = setminus(vars(G),V);
2446: Gf = cons(V0-F,G);
2447: Vf = append(V,[V0]);
1.10 noro 2448: G3 = dp_gr_f_main(map(simp_ff,Gf),Vf,0,3);
1.1 noro 2449: for ( T = G3; T != []; T = cdr(T) ) {
2450: Vt = setminus(vars(car(T)),Vc);
2451: if ( Vt == [V0] )
2452: return car(T);
2453: }
2454: }
2455:
2456: def minipoly_mod(G,V,Mod,F,V0)
2457: {
2458: Vc = setminus(vars(G),V);
2459: Gf = cons(V0-F,G);
2460: Vf = append(V,[V0]);
2461: G3 = dp_gr_mod_main(Gf,Vf,1,Mod,3);
2462: for ( T = G3; T != []; T = cdr(T) ) {
2463: Vt = setminus(vars(car(T)),Vc);
2464: if ( Vt == [V0] )
2465: return car(T);
2466: }
2467: }
2468: #endif
2469:
2470: /* find N/D s.t. F = N/D mod V^(2M), deg(N),deg(D)<M */
2471:
2472: def pade(F,M)
2473: {
2474: V = var(F);
2475: A = newvect(M);
2476: D = 0;
2477: for ( I = 0; I < M; I++ ) {
2478: A[I] = strtov("b"+rtostr(I));
2479: D += A[I]*V^I;
2480: }
2481: T = F*D;
2482: M2 = M*2;
2483: R = [];
2484: for ( I = M; I < M2; I++ )
2485: R = cons(coef(T,I,V),R);
2486: }
2487:
2488: def minipoly_sfrat(G0,V,O,P,V0,Server)
2489: {
2490: if ( Server )
2491: ox_sync(0);
2492: if ( !zero_dim(hmlist(G0,V,O),V,O) )
2493: error("minipoly_sfrat : ideal is not zero-dimensional!");
2494:
2495: G1 = cons(V0-P,G0);
2496: if ( type(O) <= 1 )
2497: O1 = [[0,1],[O,length(V)]];
2498: else
2499: O1 = cons([0,1],O);
2500: V1 = cons(V0,V);
2501: W = append(V,[V0]);
2502: Vc = setminus(vars(G0),V);
2503:
2504: N = length(V1);
2505: dp_ord(O1);
2506: HM = hmlist(G1,V1,O1);
2507: MB = dp_mbase(map(dp_ptod,HM,V1));
2508: dp_ord(O);
2509:
2510: Nc = length(Vc);
2511: Eval = newvect(Nc);
2512:
2513: /* heristic lower bound of deg(MP) */
2514: Q1 = field_order_ff()-1;
2515: do {
2516: for ( I = 0; I < Nc; I++ )
2517: Eval[I] = random()%Q1;
2518: } while ( !valid_modulus_sfrat(HM,Vc,Eval) );
2519: G0E = map(eval_sfrat,G0,Vc,Eval);
2520: P0 = eval_sfrat(P,Vc,Eval);
2521: MP = minipoly_sf(G0E,V,O,P0,V0);
2522: DMP = deg(MP,V0);
2523:
2524: for ( I = 0; I < Nc; I++ )
2525: Eval[I] = 0;
2526: while ( 1 ) {
2527: if ( valid_modulus_sfrat(HM,Vc,Eval) ) {
2528: G0E = map(eval_sfrat,G0,Vc,Eval);
2529: P0 = eval_sfrat(P,Vc,Eval);
2530: MP = minipoly_sf(G0E,V,O,P0,V0);
2531: D = deg(MP,V0);
2532: if ( D >= DMP ) {
2533: DMP = D;
2534: for ( TL = [], MPT = 0, J = 0; J <= D; J++ ) {
2535: TL = cons(V0^J,TL);
2536: MPT += car(TL);
2537: }
2538: NF = gennf_sfrat(G1,TL,V1,O1,V0,1)[0];
2539: R = tolex_sfrat_main(V1,O1,NF,[MPT],Vc,Eval,MB);
2540: if ( R )
2541: return sdiv(R[0],sfcont(R[0],V0));
2542: }
2543: }
2544: next_eval_sfrat(Eval);
2545: }
2546: }
2547:
2548: def next_eval_sfrat(Eval)
2549: {
2550: N = size(Eval)[0];
2551: for ( I = N-1; I >= 0; I-- )
2552: if ( Eval[I] ) break;
2553: if ( I < 0 ) Eval[N-1] = 1;
2554: else if ( I == 0 ) {
2555: T = Eval[0]; Eval[0] = 0; Eval[N-1] = T+1;
2556: } else {
2557: Eval[I-1]++; T = Eval[I];
2558: for ( J = I; J < N-1; J++ )
2559: Eval[J] = 0;
2560: Eval[N-1] = T-1;
2561: }
2562: }
2563:
2564: def eval_sfrat(F,V,Eval)
2565: {
2566: for ( I = 0; V != []; V = cdr(V), I++ )
2567: F = subst(F,car(V),ptosfp(Eval[I]));
2568: return F;
2569: }
2570:
2571: def valid_modulus_sfrat(HL,Vc,Eval) {
2572: for ( T = HL; T != []; T = cdr(T) ) {
2573: C = car(T);
2574: for ( S = Vc, I = 0; S != []; S = cdr(S), I++ )
2575: C = subst(C,car(S),ptosfp(Eval[I]));
2576: if ( !C )
2577: break;
2578: }
2579: return T == [] ? 1 : 0;
2580: }
2581:
2582: def gennf_sfrat(G,TL,V,O,V0,FLAG)
2583: {
2584: N = length(V); Len = length(G); dp_ord(O); PS = newvect(Len);
2585: for ( I = 0, T = G, HL = []; T != []; T = cdr(T), I++ ) {
2586: PS[I] = dp_ptod(car(T),V); HL = cons(dp_ht(PS[I]),HL);
2587: }
2588: for ( I = 0, DTL = []; TL != []; TL = cdr(TL) )
2589: DTL = cons(dp_ptod(car(TL),V),DTL);
2590: for ( I = Len - 1, GI = []; I >= 0; I-- )
2591: GI = cons(I,GI);
2592: T = car(DTL); DTL = cdr(DTL);
2593: H = [nf_sfrat(GI,T,T,PS)];
2594:
2595: USE_TAB = (FLAG != 0);
2596: if ( USE_TAB ) {
2597: T0 = time()[0];
2598: MB = dp_mbase(HL); DIM = length(MB);
2599: U = dp_ptod(V0,V);
2600: UTAB = newvect(DIM);
2601: for ( I = 0; I < DIM; I++ ) {
2602: UTAB[I] = [MB[I],remove_cont_sfrat(nf_sfrat(GI,U*MB[I],1,PS))];
2603: if ( dp_gr_print() )
2604: print(".",2);
2605: }
2606: if ( dp_gr_print() )
2607: print("");
2608: TTAB = time()[0]-T0;
2609: }
2610:
2611: T0 = time()[0];
2612: for ( LCM = 1; DTL != []; ) {
2613: if ( dp_gr_print() )
2614: print(".",2);
2615: T = car(DTL); DTL = cdr(DTL);
2616: if ( L = search_redble(T,H) ) {
2617: DD = dp_subd(T,L[1]);
2618: if ( USE_TAB && (DD == U) ) {
2619: NF = nf_tab_sfrat(L[0],UTAB);
2620: NF = [NF[0],dp_hc(L[1])*NF[1]*T];
2621: } else
2622: NF = nf_sfrat(GI,L[0]*dp_subd(T,L[1]),dp_hc(L[1])*T,PS);
2623: } else
2624: NF = nf_sfrat(GI,T,T,PS);
2625: NF = remove_cont_sfrat(NF);
2626: H = cons(NF,H);
2627: LCM = lcm_sfrat(LCM,dp_hc(NF[1]));
2628: }
2629: TNF = time()[0]-T0;
2630: if ( dp_gr_print() )
2631: print("gennf(TAB="+rtostr(TTAB)+" NF="+rtostr(TNF)+")");
2632: return [[map(adj_dn_sfrat,H,LCM),LCM],PS,GI];
2633: }
2634:
2635: def lcm_sfrat(A,B)
2636: {
2637: G = sfgcd(A,B);
2638: return sdiv(A,G)*B;
2639: }
2640:
2641: #define REDCONT(f) ((f)/sfcont(f))
2642:
2643: def remove_cont_sfrat(L)
2644: {
2645: if ( type(L[1]) <= 2 ) {
2646: T = remove_cont_sfrat([L[0],L[1]*<<0>>]);
2647: return [T[0],dp_hc(T[1])];
2648: } else if ( !L[0] )
2649: return [0,REDCONT(L[1])];
2650: else if ( !L[1] )
2651: return [REDCONT(L[0]),0];
2652: else {
2653: A0 = REDCONT(L[0]); A1 = REDCONT(L[1]);
2654: C0 = sdiv(dp_hc(L[0]),dp_hc(A0)); C1 = sdiv(dp_hc(L[1]),dp_hc(A1));
2655: GCD = sfgcd(C0,C1); M0 = sdiv(C0,GCD); M1 = sdiv(C1,GCD);
2656: return [M0*A0,M1*A1];
2657: }
2658: }
2659:
2660: def nf_sfrat(B,G,M,PS)
2661: {
2662: for ( D = 0; G; ) {
2663: for ( U = 0, L = B; L != []; L = cdr(L) ) {
2664: if ( dp_redble(G,R=PS[car(L)]) > 0 ) {
2665: GCD = sfgcd(dp_hc(G),dp_hc(R));
2666: CG = sdiv(dp_hc(R),GCD); CR = sdiv(dp_hc(G),GCD);
2667: U = CG*G-dp_subd(G,R)*CR*R;
2668: if ( !U )
2669: return [D,M];
2670: D *= CG; M *= CG;
2671: break;
2672: }
2673: }
2674: if ( U )
2675: G = U;
2676: else {
2677: D += dp_hm(G); G = dp_rest(G);
2678: }
2679: }
2680: return [D,M];
2681: }
2682:
2683: def nf_tab_sfrat(F,TAB)
2684: {
2685: for ( NM = 0, DN = 1, I = 0; F; F = dp_rest(F) ) {
2686: T = dp_ht(F);
2687: for ( ; TAB[I][0] != T; I++);
2688: NF = TAB[I][1]; N = NF[0]; D = NF[1];
2689: G = sfgcd(DN,D); DN1 = sdiv(DN,G); D1 = sdiv(D,G);
2690: NM = D1*NM + DN1*dp_hc(F)*N; DN *= D1;
2691: }
2692: return [NM,DN];
2693: }
2694:
2695: def adj_dn_sfrat(P,D)
2696: {
2697: return [(sdiv(D,dp_hc(P[1])))*P[0],dp_ht(P[1])];
2698: }
2699:
2700: def tolex_sfrat_main(V,O,NF,GM,Vc,Eval,MB)
2701: {
2702: if ( MB ) {
2703: PosDim = 0;
2704: DIM = length(MB);
2705: DV = newvect(DIM);
2706: } else
2707: PosDim = 1;
2708: for ( T = GM, SL = [], LCM = 1; T != []; T = cdr(T) ) {
2709: S = p_terms(car(T),V,2);
2710: if ( PosDim ) {
2711: MB = gather_nf_terms(S,NF,V,O);
2712: DV = newvect(length(MB));
2713: }
2714: dp_ord(O); RHS = termstomat_sfrat(NF,map(dp_ptod,cdr(S),V),MB,Vc,Eval);
2715: dp_ord(O); NHT = nf_tab_gsl_sfrat(dp_ptod(LCM*car(S),V),NF);
2716: dptov(NHT[0],DV,MB);
2717: dp_ord(O); B = hen_ttob_gsl_sfrat([DV,NHT[1]],RHS,cdr(S),Vc,Eval);
2718: if ( !B )
2719: return 0;
2720: Len = length(S);
2721: LCM *= B[1];
2722: for ( U = LCM*car(S), I = 1; I < Len; I++ )
2723: U += B[0][I-1]*S[I];
2724: SL = cons(U,SL);
2725: if ( dp_gr_print() )
2726: print(["DN",B[1]]);
2727: }
2728: return SL;
2729: }
2730:
2731: def termstomat_sfrat(NF,TERMS,MB,Vc,Eval)
2732: {
2733: DN = NF[1];
2734: NF = NF[0];
2735: N = length(MB);
2736: M = length(TERMS);
2737: MAT = newmat(N,M);
2738: W = newvect(N);
2739: Len = length(NF);
2740: for ( I = 0; I < M; I++ ) {
2741: T = TERMS[I];
2742: for ( K = 0; K < Len; K++ )
2743: if ( T == NF[K][1] )
2744: break;
2745: dptov(NF[K][0],W,MB);
2746: for ( J = 0; J < N; J++ )
2747: MAT[J][I] = W[J];
2748: }
2749: return [henleq_prep_sfrat(MAT,Vc,Eval),DN];
2750: }
2751:
2752: def henleq_prep_sfrat(A,Vc,Eval)
2753: {
2754: SIZE = size(A); ROW = SIZE[0]; COL = SIZE[1];
2755: L = geninv_sf_swap(map(eval_sfrat,A,Vc,Eval)); INV = L[0]; INDEX = L[1];
2756: AA = newmat(COL,COL);
2757: for ( I = 0; I < COL; I++ )
2758: for ( J = 0, T = AA[I], S = A[INDEX[I]]; J < COL; J++ )
2759: T[J] = S[J];
2760: if ( COL != ROW ) {
2761: RESTA = newmat(ROW-COL,COL);
2762: for ( ; I < ROW; I++ )
2763: for ( J = 0, T = RESTA[I-COL], S = A[INDEX[I]]; J < COL; J++ )
2764: T[J] = S[J];
2765: } else
2766: RESTA = 0;
2767: return [[A,AA,RESTA],L];
2768: }
2769:
2770: def hen_ttob_gsl_sfrat(LHS,RHS,TERMS,Vc,Eval)
2771: {
2772: LDN = LHS[1]; RDN = RHS[1]; LCM = lcm_sfrat(LDN,RDN);
2773: L1 = sdiv(LCM,LDN); R1 = sdiv(LCM,RDN);
2774: T0 = time()[0];
2775: S = henleq_gsl_sfrat(RHS[0],LHS[0]*L1,Vc,Eval);
2776: if ( dp_gr_print() )
2777: print(["henleq_gsl_sfrat",time()[0]-T0]);
2778: if ( !S )
2779: return 0;
2780: N = length(TERMS);
2781: return [S[0],S[1]*R1];
2782: }
2783:
2784: def nf_tab_gsl_sfrat(A,NF)
2785: {
2786: DN = NF[1];
2787: NF = NF[0];
2788: TLen = length(NF);
2789: for ( R = 0; A; A = dp_rest(A) ) {
2790: HM = dp_hm(A); C = dp_hc(HM); T = dp_ht(HM);
2791: for ( I = 0; I < TLen; I++ )
2792: if ( NF[I][1] == T )
2793: break;
2794: R += C*NF[I][0];
2795: }
2796: return remove_cont_sfrat([R,DN]);
2797: }
2798:
2799: def henleq_gsl_sfrat(L,B,Vc,Eval)
2800: {
2801: Nc = length(Vc);
2802: if ( Nc > 1 )
2803: return henleq_gsl_sfrat_higher(L,B,Vc,Eval);
2804:
2805: V0 = Vc[0]; E0 = ptosfp(Eval[0]);
2806:
2807: AL = L[0]; INVL = L[1];
2808: A = AL[0]; AA = AL[1]; RESTA = AL[2];
2809: INV = INVL[0]; INDEX = INVL[1];
2810:
2811: SIZE = size(A); ROW = SIZE[0]; COL = SIZE[1];
2812: BB = newvect(COL);
2813: for ( I = 0; I < COL; I++ )
2814: BB[I] = B[INDEX[I]];
2815: if ( COL != ROW ) {
2816: RESTB = newvect(ROW-COL);
2817: for ( ; I < ROW; I++ )
2818: RESTB[I-COL] = B[INDEX[I]];
2819: } else
2820: RESTB = 0;
2821:
2822: COUNT = 2;
2823: if ( !COUNT )
2824: COUNT = 2;
2825: X = newvect(size(AA)[0]);
2826: for ( I = 0, C = BB, CCC = 0, ITOR_FAIL = -1; ; I++ ) {
2827: if ( zerovector(C) ) {
2828: X = map(subst,X,V0,V0-E0);
2829: if ( zerovector(RESTA*X+RESTB) ) {
2830: if ( dp_gr_print() ) print("end",0);
1.10 noro 2831: return [X,simp_ff(1)];
1.1 noro 2832: } else
2833: return 0;
2834: } else if ( COUNT == CCC ) {
2835: CCC = 0;
2836: ND = polyvtoratv(X,V0,I);
2837: if ( ND ) {
2838: F = map(subst,ND[0],V0,V0-E0);
2839: LCM = subst(ND[1],V0,V0-E0);
2840: T = AA*F+LCM*BB;
2841: if ( zerovector(T) ) {
2842: T = RESTA*F+LCM*RESTB;
2843: if ( zerovector(T) ) {
2844: if ( dp_gr_print() ) print("end",0);
2845: return [F,LCM];
2846: } else
2847: return 0;
2848: }
2849: } else {
2850: }
2851: } else {
2852: if ( dp_gr_print() ) print(".",2);
2853: CCC++;
2854: }
2855: XT = -INV*map(subst,C,V0,E0);
2856: X += XT*V0^I;
2857: C += AA*XT;
2858: C = map(sdiv,C,V0-E0);
2859: }
2860: }
2861:
2862: def henleq_gsl_sfrat_higher(L,B,Vc,Eval)
2863: {
2864: Nc = length(Vc);
2865: E = map(ptosfp,Eval);
2866:
2867: AL = L[0]; INVL = L[1];
2868: A = AL[0]; AA0 = AL[1]; RESTA = AL[2];
2869: INV = INVL[0]; INDEX = INVL[1];
2870:
2871: SIZE = size(A); ROW = SIZE[0]; COL = SIZE[1];
2872:
2873: AA = map(mshift,AA0,Vc,E,1);
2874: BB = newvect(COL);
2875: for ( I = 0; I < COL; I++ )
2876: BB[I] = mshift(B[INDEX[I]],Vc,E,1);
2877:
2878: if ( COL != ROW ) {
2879: RESTB = newvect(ROW-COL);
2880: for ( ; I < ROW; I++ )
2881: RESTB[I-COL] = B[INDEX[I]];
2882: } else
2883: RESTB = 0;
2884:
2885: COUNT = 2;
2886: if ( !COUNT )
2887: COUNT = 2;
2888: X = newvect(size(AA)[0]);
2889: for ( I = 0, R = BB, CCC = 0, ITOR_FAIL = -1; ; I++ ) {
2890: if ( zerovector(R) ) {
2891: X = map(mshift,X,Vc,E,-1);
2892: if ( zerovector(RESTA*X+RESTB) ) {
2893: if ( dp_gr_print() ) print("end",0);
1.10 noro 2894: return [X,simp_ff(1)];
1.1 noro 2895: } else
2896: return 0;
2897: } else if ( COUNT == CCC ) {
2898: CCC = 0;
2899: ND = polyvtoratv_higher(X,Vc,I);
2900: if ( ND ) {
2901: F = map(mshift,ND[0],Vc,E,-1);
2902: LCM = mshift(ND[1],Vc,E,-1);
2903: T = AA*F+LCM*BB;
2904: if ( zerovector(T) ) {
2905: T = RESTA*F+LCM*RESTB;
2906: if ( zerovector(T) ) {
2907: if ( dp_gr_print() ) print("end",0);
2908: return [F,LCM];
2909: } else
2910: return 0;
2911: }
2912: } else {
2913: }
2914: } else {
2915: if ( dp_gr_print() ) print(".",2);
2916: CCC++;
2917: }
2918: RK = map(mtrunc,R,I+1);
2919: XT = -INV*RK;
2920: X += XT;
2921: R += AA*XT;
2922: }
2923: }
2924:
2925: /* V -> V+Sgn*E */
2926:
2927: def mshift(F,V,E,Sgn)
2928: {
2929: N = length(V);
2930: for ( I = 0; I < N; I++ )
2931: F = subst(F,V[I],V[I]+Sgn*E[I]);
2932: return F;
2933: }
2934:
2935: /* truncate terms whose degree are higher than or equal to D */
2936:
2937: def mtrunc(F,D)
2938: {
2939: if ( type(F) <= 1 )
2940: return F;
2941: else {
2942: R = 0;
2943: V = var(F);
2944: while ( F ) {
2945: K = deg(F,V);
2946: C = coef(F,K,V);
2947: if ( K < D )
2948: R += mtrunc(C,D-K)*V^K;
2949: F -= C*V^K;
2950: }
2951: return R;
2952: }
2953: }
2954:
2955: /* for 1-dim case */
2956:
2957: def polyvtoratv(Vect,V,K)
2958: {
2959: N = size(Vect)[0];
2960: R = newvect(N);
2961: K2 = idiv(K,2);
2962: Mat = newmat(K2,K2);
2963: for ( I = 0; I < N; I++ ) {
2964: T = polytorat(Vect[I],V,Mat,K2);
2965: if ( T )
2966: R[I] = T;
2967: else
2968: return 0;
2969: }
2970: LCM = R[0][1];
2971: for ( I = 1; I < N; I++ )
2972: LCM = lcm_sfrat(LCM,R[I][1]);
2973: for ( I = 0; I < N; I++ )
2974: R[I] = R[I][0]*sdiv(LCM,R[I][1]);
2975: return [R,LCM];
2976: }
2977:
2978: /* for higher dim case */
2979:
2980: def polyvtoratv_higher(Vect,Vc,K)
2981: {
2982: N = size(Vect)[0];
2983: R = newvect(N);
2984: K2 = idiv(K,2);
2985: for ( I = 0; I < N; I++ ) {
2986: T = polytorat_higher(Vect[I],Vc,K2);
2987: if ( T )
2988: R[I] = T;
2989: else
2990: return 0;
2991: }
2992: LCM = R[0][1];
2993: for ( I = 1; I < N; I++ )
2994: LCM = lcm_sfrat(LCM,R[I][1]);
2995: for ( I = 0; I < N; I++ )
2996: R[I] = R[I][0]*sdiv(LCM,R[I][1]);
2997: return [R,LCM];
2998: }
2999:
3000: /* find F = N/D mod V^(2K), deg(N), deg(D) < K */
3001: def polytorat_gcd(F,V,K)
3002: {
3003: if ( deg(F,V) < K )
1.10 noro 3004: return [F,simp_ff(1)];
1.1 noro 3005: F1 = Mod^(K*2); F2 = F;
3006: B1 = 0; B2 = 1;
3007: while ( 1 ) {
3008: Q = sdiv(F1,F2);
3009: F3 = F1-F2*Q;
3010: B3 = B1-B2*Q;
3011: if ( deg(F3,V) < K ) {
3012: if ( deg(B3,V) < K )
3013: return [F3,B3];
3014: else
3015: return 0;
3016: }
3017: F1 = F2; F2 = F3;
3018: B1 = B2; B2 = B3;
3019: }
3020: }
3021:
3022: /*
3023: * for 1-dim case
3024: *
3025: * solve
3026: *
3027: * [fk ... f1][ a0 ]
3028: * [f(k+1) ... f2][ a1 ] = 0
3029: * [ ... ][ ... ]
3030: * [f(2k-1) ... fk][a(k-1)]
3031: */
3032:
3033: def polytorat(F,V,Mat,K)
3034: {
3035: if ( deg(F,V) < K )
1.10 noro 3036: return [F,simp_ff(1)];
1.1 noro 3037: for ( I = 0; I < K; I++ )
3038: for ( J = 0; J < K; J++ )
3039: Mat[I][J] = coef(F,I+K-J);
3040: S = nullspace_ff(Mat);
3041: MT = S[0]; IND = S[1];
3042: for ( I = 0; I < K; I++ )
3043: if ( IND[I] )
3044: break;
3045: if ( I == K )
3046: return 0;
3047: D = null_to_poly_ff(MT,IND,V)[0];
3048: N = trunc(F*D,K-1);
3049: return [N,D];
3050: }
3051:
3052: /* find N,D s.t. tdeg(N), tdeg(D) < K, F = N/D mod <V0,...,VM>^(2K) */
3053:
3054: def polytorat_higher(F,V,K)
3055: {
3056: if ( K < 2 ) return 0;
3057: if ( homogeneous_deg(F) < K )
1.10 noro 3058: return [F,simp_ff(1)];
1.1 noro 3059: D = create_icpoly(V,K);
3060: C = extract_coef(D*F,V,K,2*K);
3061: Vc = vars(C);
3062: G = dp_gr_f_main(C,Vc,0,2);
3063: PS = newvect(length(G),map(dp_ptod,G,Vc));
3064: for ( I = length(G)-1, Ind = [];I >= 0; I-- )
3065: Ind = cons(I,Ind);
3066: D = dp_dtop(nf_sfrat(Ind,dp_ptod(D,Vc),1,PS)[0],Vc);
3067: if ( !D )
3068: return 0;
3069: Vp = setminus(vars(D),V);
3070: D = subst(D,car(Vp),1);
3071: for ( T = cdr(Vp); T != []; T = cdr(T) )
3072: D = subst(D,car(T),0);
3073: N = mtrunc(F*D,K);
3074: return [N,D];
3075: }
3076:
3077: def create_icpoly(V,K)
3078: {
3079: if ( V == [] )
3080: return uc();
3081: R = 0;
3082: for ( I = 0; I < K; I++ )
3083: R += create_icpoly(cdr(V),K-I)*V[0]^I;
3084: return R;
3085: }
3086:
3087: /* extract terms whose degrees are in [From,To) */
3088:
3089: def extract_coef(F,V,From,To)
3090: {
3091: if ( V == [] ) {
3092: if ( From == 0 )
3093: return [F];
3094: else
3095: return [];
3096: }
3097: R = [];
3098: V0 = V[0];
3099: for ( I = 0; I < To; I++ ) {
3100: C = coef(F,I,V0);
3101: if ( C ) {
3102: C = extract_coef(C,cdr(V),From>=I?From-I:0,To-I);
3103: R = append(C,R);
3104: }
3105: }
3106: return R;
3107: }
3108:
3109: def saturation_sfrat(F,G,V,Ord)
3110: {
3111: Vt = ttttt;
3112: G0 = dp_gr_f_main(cons(Vt*F-1,G),cons(Vt,V),0,[[0,1],[Ord,length(V)]]);
3113: return elimination(G0,V);
3114: }
3115:
3116: def ideal_list_intersection_sfrat(L,V)
3117: {
3118: R = car(L);
3119: for ( TL = cdr(L); TL != []; TL = cdr(TL) )
3120: R = ideal_intersection_sfrat(R,car(TL),V);
3121: return R;
3122: }
3123:
3124: def ideal_intersection_sfrat(A,B,V)
3125: {
3126: T0 = time();
3127: Vt = ttttt;
3128: C = [];
3129: for ( T = A; T != []; T = cdr(T) )
3130: C = cons(car(T)*Vt,C);
3131: for ( T = B; T != []; T = cdr(T) )
3132: C = cons(car(T)*(1-Vt),C);
3133: Ord = [[0,1],[0,length(V)]];
3134: #if 0
3135: G0 = dp_gr_f_main(C,cons(Vt,V),0,0);
3136: G = dp_gr_f_main(G0,cons(Vt,V),0,Ord);
3137: #else
3138: G = dp_gr_f_main(C,cons(Vt,V),0,Ord);
3139: #endif
3140: T_INT += time()[3]-T0[3];
3141: return elimination(G,V);
3142: }
3143:
3144: /* Shimoyama's gr_fctr */
3145:
3146: def idealsqfr_sf(G)
3147: {
3148: for(LL=[],I=length(G)-1;I>=0;I--) {
3149: for(A=1,L=sfsqfr(G[I]),J=1;J<length(L);J++)
3150: A*=L[J][0];
3151: LL=cons(A,LL);
3152: }
3153: return LL;
3154: }
3155:
3156: def ideal_uniq(L) /* sub procedure of welldec and normposdec */
3157: {
3158: for (R = [],I = 0,N=length(L); I < N; I++) {
3159: if ( R == [] )
3160: R = append(R,[L[I]]);
3161: else {
3162: for (J = 0; J < length(R); J++)
1.11 noro 3163: if ( gb_comp_old(L[I],R[J]) )
1.1 noro 3164: break;
3165: if ( J == length(R) )
3166: R = append(R,[L[I]]);
3167: }
3168: }
3169: return R;
3170: }
3171:
3172: def ideal_uniq_by_first(L) /* sub procedure of welldec and normposdec */
3173: {
3174: for (R = [],I = 0,N=length(L); I < N; I++) {
3175: if ( R == [] )
3176: R = append(R,[L[I]]);
3177: else {
3178: for (J = 0; J < length(R); J++)
1.11 noro 3179: if ( gb_comp_old(L[I][0],R[J][0]) )
1.1 noro 3180: break;
3181: if ( J == length(R) )
3182: R = append(R,[L[I]]);
3183: }
3184: }
3185: return R;
3186: }
3187:
3188: def prime_irred_sf(TP,VL,Ord)
3189: {
3190: TP = ideal_uniq(TP);
3191: N = length(TP);
3192: for (P = [], I = 0; I < N; I++) {
3193: for (J = 0; J < N; J++)
3194: if ( I != J && inclusion_test(TP[J],TP[I],VL,Ord) )
3195: break;
3196: if (J == N)
3197: P = append(P,[TP[I]]);
3198: }
3199: return P;
3200: }
3201:
3202: def prime_irred_sf_by_first(TP,VL,Ord)
3203: {
3204: TP = ideal_uniq_by_first(TP);
3205: N = length(TP);
3206: for (P = [], I = 0; I < N; I++) {
3207: for (J = 0; J < N; J++)
3208: if ( I != J && inclusion_test(car(TP[J]),car(TP[I]),VL,Ord) )
3209: break;
3210: if (J == N)
3211: P = append(P,[TP[I]]);
3212: }
3213: return P;
3214: }
3215:
3216: def monic_sf_first(L,V)
3217: {
3218: for ( R = [], T = L; T != []; T = cdr(T) )
3219: R = cons([monic_sf(car(T)[0],V),car(T)[1]],R);
3220: return reverse(R);
3221: }
3222:
3223: def monic_sf(P,V)
3224: {
3225: if ( type(P) == 4 )
3226: return map(monic_sf,P,V);
3227: else {
3228: D = dp_ptod(P,V);
3229: return dp_dtop(D/dp_hc(D),V);
3230: }
3231: }
3232:
3233: def gr_fctr_sf(FL,VL,Ord)
3234: {
3235: T0 = time();
3236: COMMONCHECK_SF = 1;
3237: for (TP = [],I = 0; I<length(FL); I++ ) {
3238: F = FL[I];
3239: SF = idealsqfr_sf(F);
1.11 noro 3240: if ( !gb_comp_old(F,SF) )
1.1 noro 3241: F = dp_gr_f_main(SF,VL,0,Ord);
3242: CID_SF=[1];
3243: SP = gr_fctr_sub_sf(F,VL,Ord);
3244: TP = append(TP,SP);
3245: }
3246: TP = prime_irred_sf(TP,VL,Ord);
3247: T_GRF += time()[3]-T0[3];
3248: return TP;
3249: }
3250:
3251: def gr_fctr_sub_sf(G,VL,Ord)
3252: {
3253: if ( length(G) == 1 && type(G[0]) == 1 )
3254: return [G];
3255: RL = [];
3256: for (I = 0; I < length(G); I++) {
3257: FL = sffctr(G[I]); L = length(FL); N = FL[1][1];
3258: if (L > 2 || N > 1) {
3259: TLL = [];
3260: for (J = 1; J < L; J++) {
3261: W = cons(FL[J][0],G);
3262: NG = dp_gr_f_main(W,VL,0,Ord);
3263: TNG = idealsqfr_sf(NG);
1.11 noro 3264: if ( !gb_comp_old(NG,TNG) )
1.1 noro 3265: NG = dp_gr_f_main(TNG,VL,0,Ord);
3266: if ( !inclusion_test(CID_SF,NG,VL,Ord) ) {
3267: DG = gr_fctr_sub_sf(NG,VL,Ord);
3268: RL = append(RL,DG);
3269: if ( J <= L-2
3270: && !inclusion_test(CID_SF,NG,VL,Ord)
3271: && COMMONCHECK_SF ) {
3272: CID_SF=ideal_intersection_sfrat(CID_SF,NG,VL);
3273: }
3274: }
3275: }
3276: break;
3277: }
3278: }
3279: if (I == length(G))
3280: RL = append([G],RL);
3281: return RL;
1.11 noro 3282: }
3283:
3284: def gb_comp_old(A,B)
3285: {
3286: LA = length(A);
3287: LB = length(B);
3288: if ( LA != LB )
3289: return 0;
3290: A = newvect(LA,A);
3291: B = newvect(LB,B);
3292: A1 = qsort(A);
3293: B1 = qsort(B);
3294: for ( I = 0; I < LA; I++ )
3295: if ( A1[I] != B1[I] && A1[I] != -B1[I] )
3296: break;
3297: return I == LA ? 1 : 0;
1.1 noro 3298: }
3299: end$
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>