Annotation of OpenXM_contrib2/asir2000/lib/primdec_mod, Revision 1.12
1.12 ! takayama 1: /* $OpenXM: OpenXM_contrib2/asir2000/lib/primdec_mod,v 1.11 2003/08/05 05:56:19 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.12 ! takayama 10: if (!module_definedp("fff")) load("fff") $$
! 11: if (!module_definedp("gr")) load("gr") $$
! 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)]];
1981: GP1 = dp_gr_f_main(P,W,Hom,Ord1);
1982:
1983: Factor = extcont_factor(GP1,V,Ord);
1984: for ( F = 1, T = Factor; T != []; T = cdr(T) )
1985: F *= car(T);
1986: Vt = newt;
1987:
1988: G = dp_gr_f_main(cons(1-Vt*F,P),cons(Vt,W),0,[[0,1],[Ord,length(W)]]);
1989: R = [];
1990: for ( T = G; T != []; T = cdr(T) )
1991: if ( !member(Vt,vars(car(T))) )
1992: R = cons(car(T),R);
1993: return [R,F];
1994: }
1995:
1996: def checkgeneric2(LIST)
1997: {
1998: NList=size(LIST)[0];
1999:
2000: FLAG=0;
2001:
2002: for (I=0;I<NList;I++)
2003: {
2004: if ( LIST[I] > 1 )
2005: {
2006: FLAG=FLAG+1;
2007: }
2008: }
2009:
2010: if (FLAG < 2 )
2011: {
2012: return 1;
2013: }
2014: return 0;
2015: }
2016:
2017: #if 0
2018: def checkseparablepoly(P,V)
2019: {
2020: TestP=P;
2021: CHECK=diff(TestP,V);
2022: Count=0;
2023:
2024: while ( CHECK !=0 )
2025: {
2026: if ( deg(TestP,V) != 0 )
2027: {
2028: break;
2029: }
2030: TestP=pdivide(TestP);
2031: CHECK=diff(TestP,V);
2032: Count=Count+1;
2033: }
2034:
2035: return [TestP,Count];
2036: }
2037:
2038: def pdivide(F,V)
2039: {
1.6 noro 2040: Char=characteristic_ff();
1.1 noro 2041: TestP=P;
2042:
2043: Deg=ideg(TestP,V);
2044: DegP=idiv(Deg,Char);
2045:
2046: if ( irem(Deg,Char) != 0 )
2047: {
2048: error;
2049: }
2050: ANS=0;
2051:
2052: for (I=O;I<DegP;I++)
2053: {
2054: TempDeg=I*Char;
2055: ANS=ANS+coeff(TestP,V,TempDeg)*X^I;
2056: }
2057: return ANS;
2058: }
2059: #endif
2060:
2061:
2062: def convsf(PP,VSet,Ord,Flag)
2063: {
2064: /* Flag = 0 or 1 */
2065: /* If Flag = 1, we compute the intersection */
2066: /* of the Galois orbit. */
2067:
2068: CHECK=checkgaloisorbit(PP,VSet,Ord,Flag);
2069:
2070: NewPP=CHECK[0];
2071:
2072: ANS=[];
2073:
2074: NPP=length(NewPP);
2075:
2076: for (I=0;I<NPP;I++)
2077: {
2078: NewComp=convertsmallfield(CHECK[Flag][I],VSet,Ord);
2079: ANS=cons(NewComp,ANS);
2080: }
2081: return ANS;
2082: }
2083:
2084: def convertsmallfield(PP,VSet,Ord)
2085: {
2086: dp_ord(Ord);
2087: NVSet=length(VSet);
1.6 noro 2088: Char=characteristic_ff();
2089: ExtDeg=extdeg_ff();
1.1 noro 2090:
1.5 noro 2091: NewV=pgpgpgpgpgpgpg;
1.1 noro 2092: MPP=map(monic_hc,PP,VSet);
2093: MPP=map(sfptopsfp,MPP,NewV);
2094:
1.6 noro 2095: DefPoly=setmod_ff()[1];
1.9 noro 2096: /* GF(p) case */
2097: if ( !DefPoly )
2098: return MPP;
2099:
1.6 noro 2100: MinPoly=subst(DefPoly,var(DefPoly),NewV);
1.1 noro 2101: XSet=cons(NewV,VSet);
2102:
2103: Ord1=[[0,1],[Ord,NVSet]];
2104:
2105: /* setmod_ff(Char,1);*/
2106:
2107: NewP=dp_gr_mod_main(cons(MinPoly,MPP),XSet,0,Char,Ord1);
2108:
2109: ANS=elimination(NewP,VSet);
2110:
2111: /* setmod_ff(Char,ExtDeg);*/
2112:
2113: return ANS;
2114: }
2115:
2116: def checkgaloisorbit(PP,VSet,Ord,Flag)
2117: {
2118: NPP=length(PP);
2119: TmpPP=PP;
1.6 noro 2120: ExtDeg=extdeg_ff();
1.1 noro 2121:
2122: ANS=[];
2123: BNS=[];
2124:
2125: while (TmpPP != [] )
2126: {
2127: TestP=car(TmpPP);
2128: Dim=TestP[1];
2129: TmpPP=cdr(TmpPP);
2130: NewP=TestP[0];
2131:
2132: ANS=cons(TestP[0],ANS);
2133:
2134: for (J=1;J<ExtDeg;J++)
2135: {
2136: G1=map(sf_galois_action,TestP[0],J);
2137:
2138: if ( setminus(G1,TestP[0]) == [] )
2139: {
2140: break;
2141: }
2142: if (Flag == 1 )
2143: {
2144: NewP=ideal_intersection_sfrat(NewP,G1,VSet);
2145: }
2146: TmpPP=deletecomponent(TmpPP,[G1,Dim]);
2147: }
2148: BNS=cons(NewP,BNS);
2149:
2150: }
2151: return [ANS,BNS];
2152: }
2153:
2154: def deletecomponent(PP,G)
2155: {
2156: TmpPP=PP;
2157:
2158: while( TmpPP !=[] )
2159: {
2160: Test=car(TmpPP)[0];
2161:
2162: if ( setminus(Test,G[0]) == [] )
2163: {
2164: ANS=setminus(PP,[G]);
2165: return ANS;
2166: }
2167:
2168: TmpPP=cdr(TmpPP);
2169: }
2170: error();
2171: }
2172:
2173:
2174: def pfctr(F)
2175: {
2176: if ( type(F) == 1 )
2177: return [[F,1]];
2178: P = characteristic_ff();
2179: E = extdeg_ff();
2180: F = sfptop(F);
2181: check_coef(F,P);
2182: D = modfctr(F,P);
2183: setmod_ff(P,E);
2184: return map(mapsf_first,D);
2185: }
2186:
2187: def check_coef(F,P)
2188: {
2189: V = vars(F);
2190: D = dp_ptod(F,V);
2191: for ( T = D; T; T = dp_rest(T) )
2192: if ( dp_hc(T) >= P )
2193: error("invalid coef");
2194: }
2195:
2196: def mapsf_first(D)
2197: {
2198: return [ptosfp(D[0]),D[1]];
2199: }
2200:
2201: def partial_decomp(B,V)
2202: {
2203: T0 = time();
2204: if ( ParallelMinipoly ) {
2205: map(ox_cmo_rpc,ParallelMinipoly,"setmod_ff",characteristic_ff(),extdeg_ff());
2206: map(ox_pop_cmo,ParallelMinipoly);
2207: }
1.10 noro 2208: B = map(simp_ff,B);
1.1 noro 2209: B = dp_gr_f_main(B,V,0,0);
2210: R = partial_decomp0(B,V,length(V)-1);
2211: if ( PartialDecompByLex ) {
2212: R0 = [];
2213: for ( TR = R; TR != []; TR = cdr(TR) ) {
2214: T = car(TR);
2215: S = dp_gr_f_main(T[0],V,0,0);
2216: R0 = cons([S,T[1]],R0);
2217: }
2218: R = reverse(R0);
2219: }
2220: T_PD += time()[3]-T0[3];
2221: return R;
2222: }
2223:
2224: def setintersection(A,B)
2225: {
2226: for ( L = []; A != []; A = cdr(A) )
2227: if ( member(car(A),B) )
2228: L = cons(car(A),L);
2229: return L;
2230: }
2231:
2232: /* returns [[Plist,Mlist],...] */
2233:
2234: def partial_decomp0(B,V,I)
2235: {
2236: N = length(V);
2237: if ( I < 0 )
2238: return [[B,[]]];
2239: Ord = PartialDecompByLex ? [[0,I],[2,N-I]] : 0;
2240: #if 0
2241: if ( setminus(vars(B),V) == [] )
2242: B = fglm_sf_0dim(B,V,Ord0,Ord);
2243: else
2244: #endif
2245: B = dp_gr_f_main(B,V,0,Ord);
2246: if ( type(B[0]) == 1 )
2247: return [];
2248: if ( !zero_dim(B,V,Ord) )
2249: error("non zero-dimensional ideal");
2250: /* XXX */
2251: Vt = ttttt;
2252: VI = V[I];
2253: if ( PartialDecompByLex ) {
2254: for ( J = 0, W = V; J < I; J++ )
2255: W = cdr(W);
2256: VW = setminus(V,W);
2257: for ( Bw = [], T = B; T != []; T = cdr(T) )
2258: if ( setintersection(vars(car(T)),VW) == [] )
2259: Bw = cons(car(T),Bw);
2260: MI = minipoly_sf(Bw,W,2,VI,Vt);
2261: } else
2262: MI = minipoly_sf(B,V,0,VI,Vt);
2263: MIF = sffctr(MI);
2264: /* if MI is irreducible, then process the next variable */
2265: if ( length(MIF) == 2 && MIF[1][1] == 1 ) {
2266: L = partial_decomp0(B,V,I-1);
2267: R = [];
2268: for ( S = L; S != []; S = cdr(S) ) {
2269: L = car(S);
2270: R = cons([L[0],cons(subst(MI,Vt,VI),L[1])],R);
2271: }
2272: return R;
2273: }
2274:
2275: /* for nf computation */
2276: Ord1 = PartialDecompByLex ? 2 : [[0,1],[0,N]];
2277: Len = length(B);
2278: PS = newvect(Len+1);
2279: dp_ord(Ord1);
2280: XV = cons(Vt,V);
2281: for ( J = 0, T = cons(Vt-VI,B); T != []; T = cdr(T), J++ )
2282: PS[J] = dp_ptod(car(T),XV);
2283: for ( J = 0, GI = []; J <= Len; J++ )
2284: GI = cons(J,GI);
2285: if ( PartialDecompByLex )
2286: GI = reverse(GI);
2287:
2288: R = [];
2289: for ( T = MIF; T != []; T = cdr(T) ) {
2290: Mt = car(car(T));
2291: if ( type(Mt) == 1 )
2292: continue;
2293: dp_ord(Ord1);
2294: NfMt = dp_dtop(nf_sfrat(GI,dp_ptod(Mt,XV),1,PS)[0],XV);
2295: if ( NfMt )
2296: B1 = dp_gr_f_main(cons(NfMt,B),V,0,Ord);
2297: else
2298: B1 = B;
2299: Rt = partial_decomp0(B1,V,I-1);
2300: for ( S = Rt; S != []; S = cdr(S) ) {
2301: L = car(S);
2302: R = cons([L[0],cons(subst(Mt,Vt,VI),L[1])],R);
2303: }
2304: }
2305: return R;
2306: }
2307:
2308:
2309: /* G is a gb wrt (V,O) */
2310:
2311: def minipoly_sf(G,V,O,F,V0)
2312: {
2313: T0 = time();
2314: Vc = cons(V0,setminus(vars(G),V));
2315: if ( ParallelMinipoly ) {
2316: Proc0 = ParallelMinipoly[0];
2317: Proc1 = ParallelMinipoly[1];
2318: if ( length(Vc) == 1 ) {
2319: ox_rpc(Proc0,"minipoly_sf_by_buchberger",G,V,O,F,V0,1);
2320: ox_rpc(Proc1,"minipoly_sf_0dim",G,V,O,F,V0,1);
2321: map(ox_get,ParallelMinipoly);
2322: /* 258=SM_popSerializedLocalObject */
2323: map(ox_push_cmd,ParallelMinipoly,258);
2324: F = ox_select(ParallelMinipoly);
2325: MP = ox_get(F[0]);
2326: if ( F[0] == Proc0 ) {
2327: if ( length(F) == 1 )
2328: B_Win++;
2329: else
2330: ox_get(Proc1);
2331: } else {
2332: if ( length(F) == 1 )
2333: D_Win++;
2334: else
2335: ox_get(Proc0);
2336: }
2337: ox_reset(Proc0);
2338: ox_reset(Proc1);
2339: } else if ( length(Vc) == 2 ) {
2340: ox_rpc(Proc0,"minipoly_sf_by_buchberger",G,V,O,F,V0,1);
2341: ox_rpc(Proc1,"minipoly_sfrat",G,V,O,F,V0,1);
2342: map(ox_get,ParallelMinipoly);
2343: /* 258=SM_popSerializedLocalObject */
2344: map(ox_push_cmd,ParallelMinipoly,258);
2345: F = ox_select(ParallelMinipoly);
2346: MP = ox_get(F[0]);
2347: if ( F[0] == Proc0 ) {
2348: if ( length(F) == 1 )
2349: B_Win++;
2350: else
2351: ox_get(Proc1);
2352: } else {
2353: if ( length(F) == 1 )
2354: D_Win++;
2355: else
2356: ox_get(Proc0);
2357: }
2358: ox_reset(Proc0);
2359: ox_reset(Proc1);
2360: } else
2361: MP = minipoly_sf_by_buchberger(G,V,O,F,V0,0);
2362: } else if ( BuchbergerMinipoly )
2363: MP = minipoly_sf_by_buchberger(G,V,O,F,V0,0);
2364: else {
2365: if ( length(Vc) == 1 )
2366: MP = minipoly_sf_0dim(G,V,O,F,V0,0);
2367: else if ( length(Vc) == 2 )
2368: MP = minipoly_sfrat(G,V,O,F,V0,0);
2369: else
2370: MP = minipoly_sf_by_buchberger(G,V,O,F,V0,0);
2371: }
2372: T_MP += time()[3]-T0[3];
2373: return MP;
2374: }
2375:
2376: def minipoly_sf_by_buchberger(G,V,O,F,V0,Server)
2377: {
2378: if ( Server )
2379: ox_sync(0);
2380: Vc = cons(V0,setminus(vars(G),V));
1.10 noro 2381: Gf = cons(simp_ff(V0-F),G);
1.1 noro 2382: Vf = append(V,Vc);
2383: Gelim = dp_gr_f_main(Gf,Vf,1,[[0,length(V)],[0,length(Vc)]]);
2384: for ( Gc = [], T = Gelim; T != []; T = cdr(T) ) {
2385: Vt = setminus(vars(car(T)),Vc);
2386: if ( Vt == [] )
2387: Gc = cons(car(T),Gc);
2388: }
2389: Gt = dp_gr_f_main(Gc,Vc,1,[[0,1],[0,length(Vc)-1]]);
2390: Pmin = car(Gt); Dmin = deg(Pmin,V0);
2391: for ( T = cdr(Gt); T != []; T = cdr(T) ) {
2392: Dt = deg(car(T),V0);
2393: if ( Dt < Dmin ) {
2394: Pmin = car(T); Dmin = Dt;
2395: }
2396: }
2397: Cont = sfcont(Pmin,V0);
2398: return sdiv(Pmin,Cont);
2399: }
2400:
2401: def minipoly_sf_0dim(G,V,O,F,V0,Server)
2402: {
2403: if ( Server )
2404: ox_sync(0);
2405: N = length(V);
2406: Len = length(G);
2407: dp_ord(O);
2408: PS = newvect(Len);
2409: for ( I = 0, T = G; T != []; T = cdr(T), I++ )
2410: PS[I] = dp_ptod(car(T),V);
2411: for ( I = Len-1, HL = []; I >= 0; I-- )
2412: HL = cons(dp_ht(PS[I]),HL);
2413: for ( I = Len - 1, GI = []; I >= 0; I-- )
2414: GI = cons(I,GI);
2415: MB = dp_mbase(HL); DIM = length(MB); UT = newvect(DIM);
1.10 noro 2416: U = dp_ptod(simp_ff(F),V);
1.1 noro 2417: U = dp_nf_f(GI,U,PS,1);
2418: for ( I = 0; I < DIM; I++ )
2419: UT[I] = [MB[I],dp_nf_f(GI,U*MB[I],PS,1)];
2420:
1.10 noro 2421: T = dp_ptod(simp_ff(1),[V0]);
2422: TT = dp_ptod(simp_ff(1),V);
1.1 noro 2423: G = H = [[TT,T]];
2424:
2425: for ( I = 1; ; I++ ) {
2426: if ( dp_gr_print() )
2427: print(".",2);
1.10 noro 2428: T = dp_ptod(simp_ff(V0^I),[V0]);
1.1 noro 2429: TT = dp_nf_tab_f(H[0][0],UT);
2430: H = cons([TT,T],H);
2431: L = dp_lnf_f([TT,T],G);
2432: if ( !L[0] ) {
2433: if ( dp_gr_print() )
2434: print("");
2435: return dp_dtop(L[1],[V0]); /* XXX */
2436: } else
2437: G = insert(G,L);
2438: }
2439: }
2440:
2441: #if 1
2442: def minipoly_sf_rat(G,V,F,V0)
2443: {
2444: Vc = setminus(vars(G),V);
2445: Gf = cons(V0-F,G);
2446: Vf = append(V,[V0]);
1.10 noro 2447: G3 = dp_gr_f_main(map(simp_ff,Gf),Vf,0,3);
1.1 noro 2448: for ( T = G3; T != []; T = cdr(T) ) {
2449: Vt = setminus(vars(car(T)),Vc);
2450: if ( Vt == [V0] )
2451: return car(T);
2452: }
2453: }
2454:
2455: def minipoly_mod(G,V,Mod,F,V0)
2456: {
2457: Vc = setminus(vars(G),V);
2458: Gf = cons(V0-F,G);
2459: Vf = append(V,[V0]);
2460: G3 = dp_gr_mod_main(Gf,Vf,1,Mod,3);
2461: for ( T = G3; T != []; T = cdr(T) ) {
2462: Vt = setminus(vars(car(T)),Vc);
2463: if ( Vt == [V0] )
2464: return car(T);
2465: }
2466: }
2467: #endif
2468:
2469: /* find N/D s.t. F = N/D mod V^(2M), deg(N),deg(D)<M */
2470:
2471: def pade(F,M)
2472: {
2473: V = var(F);
2474: A = newvect(M);
2475: D = 0;
2476: for ( I = 0; I < M; I++ ) {
2477: A[I] = strtov("b"+rtostr(I));
2478: D += A[I]*V^I;
2479: }
2480: T = F*D;
2481: M2 = M*2;
2482: R = [];
2483: for ( I = M; I < M2; I++ )
2484: R = cons(coef(T,I,V),R);
2485: }
2486:
2487: def minipoly_sfrat(G0,V,O,P,V0,Server)
2488: {
2489: if ( Server )
2490: ox_sync(0);
2491: if ( !zero_dim(hmlist(G0,V,O),V,O) )
2492: error("minipoly_sfrat : ideal is not zero-dimensional!");
2493:
2494: G1 = cons(V0-P,G0);
2495: if ( type(O) <= 1 )
2496: O1 = [[0,1],[O,length(V)]];
2497: else
2498: O1 = cons([0,1],O);
2499: V1 = cons(V0,V);
2500: W = append(V,[V0]);
2501: Vc = setminus(vars(G0),V);
2502:
2503: N = length(V1);
2504: dp_ord(O1);
2505: HM = hmlist(G1,V1,O1);
2506: MB = dp_mbase(map(dp_ptod,HM,V1));
2507: dp_ord(O);
2508:
2509: Nc = length(Vc);
2510: Eval = newvect(Nc);
2511:
2512: /* heristic lower bound of deg(MP) */
2513: Q1 = field_order_ff()-1;
2514: do {
2515: for ( I = 0; I < Nc; I++ )
2516: Eval[I] = random()%Q1;
2517: } while ( !valid_modulus_sfrat(HM,Vc,Eval) );
2518: G0E = map(eval_sfrat,G0,Vc,Eval);
2519: P0 = eval_sfrat(P,Vc,Eval);
2520: MP = minipoly_sf(G0E,V,O,P0,V0);
2521: DMP = deg(MP,V0);
2522:
2523: for ( I = 0; I < Nc; I++ )
2524: Eval[I] = 0;
2525: while ( 1 ) {
2526: if ( valid_modulus_sfrat(HM,Vc,Eval) ) {
2527: G0E = map(eval_sfrat,G0,Vc,Eval);
2528: P0 = eval_sfrat(P,Vc,Eval);
2529: MP = minipoly_sf(G0E,V,O,P0,V0);
2530: D = deg(MP,V0);
2531: if ( D >= DMP ) {
2532: DMP = D;
2533: for ( TL = [], MPT = 0, J = 0; J <= D; J++ ) {
2534: TL = cons(V0^J,TL);
2535: MPT += car(TL);
2536: }
2537: NF = gennf_sfrat(G1,TL,V1,O1,V0,1)[0];
2538: R = tolex_sfrat_main(V1,O1,NF,[MPT],Vc,Eval,MB);
2539: if ( R )
2540: return sdiv(R[0],sfcont(R[0],V0));
2541: }
2542: }
2543: next_eval_sfrat(Eval);
2544: }
2545: }
2546:
2547: def next_eval_sfrat(Eval)
2548: {
2549: N = size(Eval)[0];
2550: for ( I = N-1; I >= 0; I-- )
2551: if ( Eval[I] ) break;
2552: if ( I < 0 ) Eval[N-1] = 1;
2553: else if ( I == 0 ) {
2554: T = Eval[0]; Eval[0] = 0; Eval[N-1] = T+1;
2555: } else {
2556: Eval[I-1]++; T = Eval[I];
2557: for ( J = I; J < N-1; J++ )
2558: Eval[J] = 0;
2559: Eval[N-1] = T-1;
2560: }
2561: }
2562:
2563: def eval_sfrat(F,V,Eval)
2564: {
2565: for ( I = 0; V != []; V = cdr(V), I++ )
2566: F = subst(F,car(V),ptosfp(Eval[I]));
2567: return F;
2568: }
2569:
2570: def valid_modulus_sfrat(HL,Vc,Eval) {
2571: for ( T = HL; T != []; T = cdr(T) ) {
2572: C = car(T);
2573: for ( S = Vc, I = 0; S != []; S = cdr(S), I++ )
2574: C = subst(C,car(S),ptosfp(Eval[I]));
2575: if ( !C )
2576: break;
2577: }
2578: return T == [] ? 1 : 0;
2579: }
2580:
2581: def gennf_sfrat(G,TL,V,O,V0,FLAG)
2582: {
2583: N = length(V); Len = length(G); dp_ord(O); PS = newvect(Len);
2584: for ( I = 0, T = G, HL = []; T != []; T = cdr(T), I++ ) {
2585: PS[I] = dp_ptod(car(T),V); HL = cons(dp_ht(PS[I]),HL);
2586: }
2587: for ( I = 0, DTL = []; TL != []; TL = cdr(TL) )
2588: DTL = cons(dp_ptod(car(TL),V),DTL);
2589: for ( I = Len - 1, GI = []; I >= 0; I-- )
2590: GI = cons(I,GI);
2591: T = car(DTL); DTL = cdr(DTL);
2592: H = [nf_sfrat(GI,T,T,PS)];
2593:
2594: USE_TAB = (FLAG != 0);
2595: if ( USE_TAB ) {
2596: T0 = time()[0];
2597: MB = dp_mbase(HL); DIM = length(MB);
2598: U = dp_ptod(V0,V);
2599: UTAB = newvect(DIM);
2600: for ( I = 0; I < DIM; I++ ) {
2601: UTAB[I] = [MB[I],remove_cont_sfrat(nf_sfrat(GI,U*MB[I],1,PS))];
2602: if ( dp_gr_print() )
2603: print(".",2);
2604: }
2605: if ( dp_gr_print() )
2606: print("");
2607: TTAB = time()[0]-T0;
2608: }
2609:
2610: T0 = time()[0];
2611: for ( LCM = 1; DTL != []; ) {
2612: if ( dp_gr_print() )
2613: print(".",2);
2614: T = car(DTL); DTL = cdr(DTL);
2615: if ( L = search_redble(T,H) ) {
2616: DD = dp_subd(T,L[1]);
2617: if ( USE_TAB && (DD == U) ) {
2618: NF = nf_tab_sfrat(L[0],UTAB);
2619: NF = [NF[0],dp_hc(L[1])*NF[1]*T];
2620: } else
2621: NF = nf_sfrat(GI,L[0]*dp_subd(T,L[1]),dp_hc(L[1])*T,PS);
2622: } else
2623: NF = nf_sfrat(GI,T,T,PS);
2624: NF = remove_cont_sfrat(NF);
2625: H = cons(NF,H);
2626: LCM = lcm_sfrat(LCM,dp_hc(NF[1]));
2627: }
2628: TNF = time()[0]-T0;
2629: if ( dp_gr_print() )
2630: print("gennf(TAB="+rtostr(TTAB)+" NF="+rtostr(TNF)+")");
2631: return [[map(adj_dn_sfrat,H,LCM),LCM],PS,GI];
2632: }
2633:
2634: def lcm_sfrat(A,B)
2635: {
2636: G = sfgcd(A,B);
2637: return sdiv(A,G)*B;
2638: }
2639:
2640: #define REDCONT(f) ((f)/sfcont(f))
2641:
2642: def remove_cont_sfrat(L)
2643: {
2644: if ( type(L[1]) <= 2 ) {
2645: T = remove_cont_sfrat([L[0],L[1]*<<0>>]);
2646: return [T[0],dp_hc(T[1])];
2647: } else if ( !L[0] )
2648: return [0,REDCONT(L[1])];
2649: else if ( !L[1] )
2650: return [REDCONT(L[0]),0];
2651: else {
2652: A0 = REDCONT(L[0]); A1 = REDCONT(L[1]);
2653: C0 = sdiv(dp_hc(L[0]),dp_hc(A0)); C1 = sdiv(dp_hc(L[1]),dp_hc(A1));
2654: GCD = sfgcd(C0,C1); M0 = sdiv(C0,GCD); M1 = sdiv(C1,GCD);
2655: return [M0*A0,M1*A1];
2656: }
2657: }
2658:
2659: def nf_sfrat(B,G,M,PS)
2660: {
2661: for ( D = 0; G; ) {
2662: for ( U = 0, L = B; L != []; L = cdr(L) ) {
2663: if ( dp_redble(G,R=PS[car(L)]) > 0 ) {
2664: GCD = sfgcd(dp_hc(G),dp_hc(R));
2665: CG = sdiv(dp_hc(R),GCD); CR = sdiv(dp_hc(G),GCD);
2666: U = CG*G-dp_subd(G,R)*CR*R;
2667: if ( !U )
2668: return [D,M];
2669: D *= CG; M *= CG;
2670: break;
2671: }
2672: }
2673: if ( U )
2674: G = U;
2675: else {
2676: D += dp_hm(G); G = dp_rest(G);
2677: }
2678: }
2679: return [D,M];
2680: }
2681:
2682: def nf_tab_sfrat(F,TAB)
2683: {
2684: for ( NM = 0, DN = 1, I = 0; F; F = dp_rest(F) ) {
2685: T = dp_ht(F);
2686: for ( ; TAB[I][0] != T; I++);
2687: NF = TAB[I][1]; N = NF[0]; D = NF[1];
2688: G = sfgcd(DN,D); DN1 = sdiv(DN,G); D1 = sdiv(D,G);
2689: NM = D1*NM + DN1*dp_hc(F)*N; DN *= D1;
2690: }
2691: return [NM,DN];
2692: }
2693:
2694: def adj_dn_sfrat(P,D)
2695: {
2696: return [(sdiv(D,dp_hc(P[1])))*P[0],dp_ht(P[1])];
2697: }
2698:
2699: def tolex_sfrat_main(V,O,NF,GM,Vc,Eval,MB)
2700: {
2701: if ( MB ) {
2702: PosDim = 0;
2703: DIM = length(MB);
2704: DV = newvect(DIM);
2705: } else
2706: PosDim = 1;
2707: for ( T = GM, SL = [], LCM = 1; T != []; T = cdr(T) ) {
2708: S = p_terms(car(T),V,2);
2709: if ( PosDim ) {
2710: MB = gather_nf_terms(S,NF,V,O);
2711: DV = newvect(length(MB));
2712: }
2713: dp_ord(O); RHS = termstomat_sfrat(NF,map(dp_ptod,cdr(S),V),MB,Vc,Eval);
2714: dp_ord(O); NHT = nf_tab_gsl_sfrat(dp_ptod(LCM*car(S),V),NF);
2715: dptov(NHT[0],DV,MB);
2716: dp_ord(O); B = hen_ttob_gsl_sfrat([DV,NHT[1]],RHS,cdr(S),Vc,Eval);
2717: if ( !B )
2718: return 0;
2719: Len = length(S);
2720: LCM *= B[1];
2721: for ( U = LCM*car(S), I = 1; I < Len; I++ )
2722: U += B[0][I-1]*S[I];
2723: SL = cons(U,SL);
2724: if ( dp_gr_print() )
2725: print(["DN",B[1]]);
2726: }
2727: return SL;
2728: }
2729:
2730: def termstomat_sfrat(NF,TERMS,MB,Vc,Eval)
2731: {
2732: DN = NF[1];
2733: NF = NF[0];
2734: N = length(MB);
2735: M = length(TERMS);
2736: MAT = newmat(N,M);
2737: W = newvect(N);
2738: Len = length(NF);
2739: for ( I = 0; I < M; I++ ) {
2740: T = TERMS[I];
2741: for ( K = 0; K < Len; K++ )
2742: if ( T == NF[K][1] )
2743: break;
2744: dptov(NF[K][0],W,MB);
2745: for ( J = 0; J < N; J++ )
2746: MAT[J][I] = W[J];
2747: }
2748: return [henleq_prep_sfrat(MAT,Vc,Eval),DN];
2749: }
2750:
2751: def henleq_prep_sfrat(A,Vc,Eval)
2752: {
2753: SIZE = size(A); ROW = SIZE[0]; COL = SIZE[1];
2754: L = geninv_sf_swap(map(eval_sfrat,A,Vc,Eval)); INV = L[0]; INDEX = L[1];
2755: AA = newmat(COL,COL);
2756: for ( I = 0; I < COL; I++ )
2757: for ( J = 0, T = AA[I], S = A[INDEX[I]]; J < COL; J++ )
2758: T[J] = S[J];
2759: if ( COL != ROW ) {
2760: RESTA = newmat(ROW-COL,COL);
2761: for ( ; I < ROW; I++ )
2762: for ( J = 0, T = RESTA[I-COL], S = A[INDEX[I]]; J < COL; J++ )
2763: T[J] = S[J];
2764: } else
2765: RESTA = 0;
2766: return [[A,AA,RESTA],L];
2767: }
2768:
2769: def hen_ttob_gsl_sfrat(LHS,RHS,TERMS,Vc,Eval)
2770: {
2771: LDN = LHS[1]; RDN = RHS[1]; LCM = lcm_sfrat(LDN,RDN);
2772: L1 = sdiv(LCM,LDN); R1 = sdiv(LCM,RDN);
2773: T0 = time()[0];
2774: S = henleq_gsl_sfrat(RHS[0],LHS[0]*L1,Vc,Eval);
2775: if ( dp_gr_print() )
2776: print(["henleq_gsl_sfrat",time()[0]-T0]);
2777: if ( !S )
2778: return 0;
2779: N = length(TERMS);
2780: return [S[0],S[1]*R1];
2781: }
2782:
2783: def nf_tab_gsl_sfrat(A,NF)
2784: {
2785: DN = NF[1];
2786: NF = NF[0];
2787: TLen = length(NF);
2788: for ( R = 0; A; A = dp_rest(A) ) {
2789: HM = dp_hm(A); C = dp_hc(HM); T = dp_ht(HM);
2790: for ( I = 0; I < TLen; I++ )
2791: if ( NF[I][1] == T )
2792: break;
2793: R += C*NF[I][0];
2794: }
2795: return remove_cont_sfrat([R,DN]);
2796: }
2797:
2798: def henleq_gsl_sfrat(L,B,Vc,Eval)
2799: {
2800: Nc = length(Vc);
2801: if ( Nc > 1 )
2802: return henleq_gsl_sfrat_higher(L,B,Vc,Eval);
2803:
2804: V0 = Vc[0]; E0 = ptosfp(Eval[0]);
2805:
2806: AL = L[0]; INVL = L[1];
2807: A = AL[0]; AA = AL[1]; RESTA = AL[2];
2808: INV = INVL[0]; INDEX = INVL[1];
2809:
2810: SIZE = size(A); ROW = SIZE[0]; COL = SIZE[1];
2811: BB = newvect(COL);
2812: for ( I = 0; I < COL; I++ )
2813: BB[I] = B[INDEX[I]];
2814: if ( COL != ROW ) {
2815: RESTB = newvect(ROW-COL);
2816: for ( ; I < ROW; I++ )
2817: RESTB[I-COL] = B[INDEX[I]];
2818: } else
2819: RESTB = 0;
2820:
2821: COUNT = 2;
2822: if ( !COUNT )
2823: COUNT = 2;
2824: X = newvect(size(AA)[0]);
2825: for ( I = 0, C = BB, CCC = 0, ITOR_FAIL = -1; ; I++ ) {
2826: if ( zerovector(C) ) {
2827: X = map(subst,X,V0,V0-E0);
2828: if ( zerovector(RESTA*X+RESTB) ) {
2829: if ( dp_gr_print() ) print("end",0);
1.10 noro 2830: return [X,simp_ff(1)];
1.1 noro 2831: } else
2832: return 0;
2833: } else if ( COUNT == CCC ) {
2834: CCC = 0;
2835: ND = polyvtoratv(X,V0,I);
2836: if ( ND ) {
2837: F = map(subst,ND[0],V0,V0-E0);
2838: LCM = subst(ND[1],V0,V0-E0);
2839: T = AA*F+LCM*BB;
2840: if ( zerovector(T) ) {
2841: T = RESTA*F+LCM*RESTB;
2842: if ( zerovector(T) ) {
2843: if ( dp_gr_print() ) print("end",0);
2844: return [F,LCM];
2845: } else
2846: return 0;
2847: }
2848: } else {
2849: }
2850: } else {
2851: if ( dp_gr_print() ) print(".",2);
2852: CCC++;
2853: }
2854: XT = -INV*map(subst,C,V0,E0);
2855: X += XT*V0^I;
2856: C += AA*XT;
2857: C = map(sdiv,C,V0-E0);
2858: }
2859: }
2860:
2861: def henleq_gsl_sfrat_higher(L,B,Vc,Eval)
2862: {
2863: Nc = length(Vc);
2864: E = map(ptosfp,Eval);
2865:
2866: AL = L[0]; INVL = L[1];
2867: A = AL[0]; AA0 = AL[1]; RESTA = AL[2];
2868: INV = INVL[0]; INDEX = INVL[1];
2869:
2870: SIZE = size(A); ROW = SIZE[0]; COL = SIZE[1];
2871:
2872: AA = map(mshift,AA0,Vc,E,1);
2873: BB = newvect(COL);
2874: for ( I = 0; I < COL; I++ )
2875: BB[I] = mshift(B[INDEX[I]],Vc,E,1);
2876:
2877: if ( COL != ROW ) {
2878: RESTB = newvect(ROW-COL);
2879: for ( ; I < ROW; I++ )
2880: RESTB[I-COL] = B[INDEX[I]];
2881: } else
2882: RESTB = 0;
2883:
2884: COUNT = 2;
2885: if ( !COUNT )
2886: COUNT = 2;
2887: X = newvect(size(AA)[0]);
2888: for ( I = 0, R = BB, CCC = 0, ITOR_FAIL = -1; ; I++ ) {
2889: if ( zerovector(R) ) {
2890: X = map(mshift,X,Vc,E,-1);
2891: if ( zerovector(RESTA*X+RESTB) ) {
2892: if ( dp_gr_print() ) print("end",0);
1.10 noro 2893: return [X,simp_ff(1)];
1.1 noro 2894: } else
2895: return 0;
2896: } else if ( COUNT == CCC ) {
2897: CCC = 0;
2898: ND = polyvtoratv_higher(X,Vc,I);
2899: if ( ND ) {
2900: F = map(mshift,ND[0],Vc,E,-1);
2901: LCM = mshift(ND[1],Vc,E,-1);
2902: T = AA*F+LCM*BB;
2903: if ( zerovector(T) ) {
2904: T = RESTA*F+LCM*RESTB;
2905: if ( zerovector(T) ) {
2906: if ( dp_gr_print() ) print("end",0);
2907: return [F,LCM];
2908: } else
2909: return 0;
2910: }
2911: } else {
2912: }
2913: } else {
2914: if ( dp_gr_print() ) print(".",2);
2915: CCC++;
2916: }
2917: RK = map(mtrunc,R,I+1);
2918: XT = -INV*RK;
2919: X += XT;
2920: R += AA*XT;
2921: }
2922: }
2923:
2924: /* V -> V+Sgn*E */
2925:
2926: def mshift(F,V,E,Sgn)
2927: {
2928: N = length(V);
2929: for ( I = 0; I < N; I++ )
2930: F = subst(F,V[I],V[I]+Sgn*E[I]);
2931: return F;
2932: }
2933:
2934: /* truncate terms whose degree are higher than or equal to D */
2935:
2936: def mtrunc(F,D)
2937: {
2938: if ( type(F) <= 1 )
2939: return F;
2940: else {
2941: R = 0;
2942: V = var(F);
2943: while ( F ) {
2944: K = deg(F,V);
2945: C = coef(F,K,V);
2946: if ( K < D )
2947: R += mtrunc(C,D-K)*V^K;
2948: F -= C*V^K;
2949: }
2950: return R;
2951: }
2952: }
2953:
2954: /* for 1-dim case */
2955:
2956: def polyvtoratv(Vect,V,K)
2957: {
2958: N = size(Vect)[0];
2959: R = newvect(N);
2960: K2 = idiv(K,2);
2961: Mat = newmat(K2,K2);
2962: for ( I = 0; I < N; I++ ) {
2963: T = polytorat(Vect[I],V,Mat,K2);
2964: if ( T )
2965: R[I] = T;
2966: else
2967: return 0;
2968: }
2969: LCM = R[0][1];
2970: for ( I = 1; I < N; I++ )
2971: LCM = lcm_sfrat(LCM,R[I][1]);
2972: for ( I = 0; I < N; I++ )
2973: R[I] = R[I][0]*sdiv(LCM,R[I][1]);
2974: return [R,LCM];
2975: }
2976:
2977: /* for higher dim case */
2978:
2979: def polyvtoratv_higher(Vect,Vc,K)
2980: {
2981: N = size(Vect)[0];
2982: R = newvect(N);
2983: K2 = idiv(K,2);
2984: for ( I = 0; I < N; I++ ) {
2985: T = polytorat_higher(Vect[I],Vc,K2);
2986: if ( T )
2987: R[I] = T;
2988: else
2989: return 0;
2990: }
2991: LCM = R[0][1];
2992: for ( I = 1; I < N; I++ )
2993: LCM = lcm_sfrat(LCM,R[I][1]);
2994: for ( I = 0; I < N; I++ )
2995: R[I] = R[I][0]*sdiv(LCM,R[I][1]);
2996: return [R,LCM];
2997: }
2998:
2999: /* find F = N/D mod V^(2K), deg(N), deg(D) < K */
3000: def polytorat_gcd(F,V,K)
3001: {
3002: if ( deg(F,V) < K )
1.10 noro 3003: return [F,simp_ff(1)];
1.1 noro 3004: F1 = Mod^(K*2); F2 = F;
3005: B1 = 0; B2 = 1;
3006: while ( 1 ) {
3007: Q = sdiv(F1,F2);
3008: F3 = F1-F2*Q;
3009: B3 = B1-B2*Q;
3010: if ( deg(F3,V) < K ) {
3011: if ( deg(B3,V) < K )
3012: return [F3,B3];
3013: else
3014: return 0;
3015: }
3016: F1 = F2; F2 = F3;
3017: B1 = B2; B2 = B3;
3018: }
3019: }
3020:
3021: /*
3022: * for 1-dim case
3023: *
3024: * solve
3025: *
3026: * [fk ... f1][ a0 ]
3027: * [f(k+1) ... f2][ a1 ] = 0
3028: * [ ... ][ ... ]
3029: * [f(2k-1) ... fk][a(k-1)]
3030: */
3031:
3032: def polytorat(F,V,Mat,K)
3033: {
3034: if ( deg(F,V) < K )
1.10 noro 3035: return [F,simp_ff(1)];
1.1 noro 3036: for ( I = 0; I < K; I++ )
3037: for ( J = 0; J < K; J++ )
3038: Mat[I][J] = coef(F,I+K-J);
3039: S = nullspace_ff(Mat);
3040: MT = S[0]; IND = S[1];
3041: for ( I = 0; I < K; I++ )
3042: if ( IND[I] )
3043: break;
3044: if ( I == K )
3045: return 0;
3046: D = null_to_poly_ff(MT,IND,V)[0];
3047: N = trunc(F*D,K-1);
3048: return [N,D];
3049: }
3050:
3051: /* find N,D s.t. tdeg(N), tdeg(D) < K, F = N/D mod <V0,...,VM>^(2K) */
3052:
3053: def polytorat_higher(F,V,K)
3054: {
3055: if ( K < 2 ) return 0;
3056: if ( homogeneous_deg(F) < K )
1.10 noro 3057: return [F,simp_ff(1)];
1.1 noro 3058: D = create_icpoly(V,K);
3059: C = extract_coef(D*F,V,K,2*K);
3060: Vc = vars(C);
3061: G = dp_gr_f_main(C,Vc,0,2);
3062: PS = newvect(length(G),map(dp_ptod,G,Vc));
3063: for ( I = length(G)-1, Ind = [];I >= 0; I-- )
3064: Ind = cons(I,Ind);
3065: D = dp_dtop(nf_sfrat(Ind,dp_ptod(D,Vc),1,PS)[0],Vc);
3066: if ( !D )
3067: return 0;
3068: Vp = setminus(vars(D),V);
3069: D = subst(D,car(Vp),1);
3070: for ( T = cdr(Vp); T != []; T = cdr(T) )
3071: D = subst(D,car(T),0);
3072: N = mtrunc(F*D,K);
3073: return [N,D];
3074: }
3075:
3076: def create_icpoly(V,K)
3077: {
3078: if ( V == [] )
3079: return uc();
3080: R = 0;
3081: for ( I = 0; I < K; I++ )
3082: R += create_icpoly(cdr(V),K-I)*V[0]^I;
3083: return R;
3084: }
3085:
3086: /* extract terms whose degrees are in [From,To) */
3087:
3088: def extract_coef(F,V,From,To)
3089: {
3090: if ( V == [] ) {
3091: if ( From == 0 )
3092: return [F];
3093: else
3094: return [];
3095: }
3096: R = [];
3097: V0 = V[0];
3098: for ( I = 0; I < To; I++ ) {
3099: C = coef(F,I,V0);
3100: if ( C ) {
3101: C = extract_coef(C,cdr(V),From>=I?From-I:0,To-I);
3102: R = append(C,R);
3103: }
3104: }
3105: return R;
3106: }
3107:
3108: def saturation_sfrat(F,G,V,Ord)
3109: {
3110: Vt = ttttt;
3111: G0 = dp_gr_f_main(cons(Vt*F-1,G),cons(Vt,V),0,[[0,1],[Ord,length(V)]]);
3112: return elimination(G0,V);
3113: }
3114:
3115: def ideal_list_intersection_sfrat(L,V)
3116: {
3117: R = car(L);
3118: for ( TL = cdr(L); TL != []; TL = cdr(TL) )
3119: R = ideal_intersection_sfrat(R,car(TL),V);
3120: return R;
3121: }
3122:
3123: def ideal_intersection_sfrat(A,B,V)
3124: {
3125: T0 = time();
3126: Vt = ttttt;
3127: C = [];
3128: for ( T = A; T != []; T = cdr(T) )
3129: C = cons(car(T)*Vt,C);
3130: for ( T = B; T != []; T = cdr(T) )
3131: C = cons(car(T)*(1-Vt),C);
3132: Ord = [[0,1],[0,length(V)]];
3133: #if 0
3134: G0 = dp_gr_f_main(C,cons(Vt,V),0,0);
3135: G = dp_gr_f_main(G0,cons(Vt,V),0,Ord);
3136: #else
3137: G = dp_gr_f_main(C,cons(Vt,V),0,Ord);
3138: #endif
3139: T_INT += time()[3]-T0[3];
3140: return elimination(G,V);
3141: }
3142:
3143: /* Shimoyama's gr_fctr */
3144:
3145: def idealsqfr_sf(G)
3146: {
3147: for(LL=[],I=length(G)-1;I>=0;I--) {
3148: for(A=1,L=sfsqfr(G[I]),J=1;J<length(L);J++)
3149: A*=L[J][0];
3150: LL=cons(A,LL);
3151: }
3152: return LL;
3153: }
3154:
3155: def ideal_uniq(L) /* sub procedure of welldec and normposdec */
3156: {
3157: for (R = [],I = 0,N=length(L); I < N; I++) {
3158: if ( R == [] )
3159: R = append(R,[L[I]]);
3160: else {
3161: for (J = 0; J < length(R); J++)
1.11 noro 3162: if ( gb_comp_old(L[I],R[J]) )
1.1 noro 3163: break;
3164: if ( J == length(R) )
3165: R = append(R,[L[I]]);
3166: }
3167: }
3168: return R;
3169: }
3170:
3171: def ideal_uniq_by_first(L) /* sub procedure of welldec and normposdec */
3172: {
3173: for (R = [],I = 0,N=length(L); I < N; I++) {
3174: if ( R == [] )
3175: R = append(R,[L[I]]);
3176: else {
3177: for (J = 0; J < length(R); J++)
1.11 noro 3178: if ( gb_comp_old(L[I][0],R[J][0]) )
1.1 noro 3179: break;
3180: if ( J == length(R) )
3181: R = append(R,[L[I]]);
3182: }
3183: }
3184: return R;
3185: }
3186:
3187: def prime_irred_sf(TP,VL,Ord)
3188: {
3189: TP = ideal_uniq(TP);
3190: N = length(TP);
3191: for (P = [], I = 0; I < N; I++) {
3192: for (J = 0; J < N; J++)
3193: if ( I != J && inclusion_test(TP[J],TP[I],VL,Ord) )
3194: break;
3195: if (J == N)
3196: P = append(P,[TP[I]]);
3197: }
3198: return P;
3199: }
3200:
3201: def prime_irred_sf_by_first(TP,VL,Ord)
3202: {
3203: TP = ideal_uniq_by_first(TP);
3204: N = length(TP);
3205: for (P = [], I = 0; I < N; I++) {
3206: for (J = 0; J < N; J++)
3207: if ( I != J && inclusion_test(car(TP[J]),car(TP[I]),VL,Ord) )
3208: break;
3209: if (J == N)
3210: P = append(P,[TP[I]]);
3211: }
3212: return P;
3213: }
3214:
3215: def monic_sf_first(L,V)
3216: {
3217: for ( R = [], T = L; T != []; T = cdr(T) )
3218: R = cons([monic_sf(car(T)[0],V),car(T)[1]],R);
3219: return reverse(R);
3220: }
3221:
3222: def monic_sf(P,V)
3223: {
3224: if ( type(P) == 4 )
3225: return map(monic_sf,P,V);
3226: else {
3227: D = dp_ptod(P,V);
3228: return dp_dtop(D/dp_hc(D),V);
3229: }
3230: }
3231:
3232: def gr_fctr_sf(FL,VL,Ord)
3233: {
3234: T0 = time();
3235: COMMONCHECK_SF = 1;
3236: for (TP = [],I = 0; I<length(FL); I++ ) {
3237: F = FL[I];
3238: SF = idealsqfr_sf(F);
1.11 noro 3239: if ( !gb_comp_old(F,SF) )
1.1 noro 3240: F = dp_gr_f_main(SF,VL,0,Ord);
3241: CID_SF=[1];
3242: SP = gr_fctr_sub_sf(F,VL,Ord);
3243: TP = append(TP,SP);
3244: }
3245: TP = prime_irred_sf(TP,VL,Ord);
3246: T_GRF += time()[3]-T0[3];
3247: return TP;
3248: }
3249:
3250: def gr_fctr_sub_sf(G,VL,Ord)
3251: {
3252: if ( length(G) == 1 && type(G[0]) == 1 )
3253: return [G];
3254: RL = [];
3255: for (I = 0; I < length(G); I++) {
3256: FL = sffctr(G[I]); L = length(FL); N = FL[1][1];
3257: if (L > 2 || N > 1) {
3258: TLL = [];
3259: for (J = 1; J < L; J++) {
3260: W = cons(FL[J][0],G);
3261: NG = dp_gr_f_main(W,VL,0,Ord);
3262: TNG = idealsqfr_sf(NG);
1.11 noro 3263: if ( !gb_comp_old(NG,TNG) )
1.1 noro 3264: NG = dp_gr_f_main(TNG,VL,0,Ord);
3265: if ( !inclusion_test(CID_SF,NG,VL,Ord) ) {
3266: DG = gr_fctr_sub_sf(NG,VL,Ord);
3267: RL = append(RL,DG);
3268: if ( J <= L-2
3269: && !inclusion_test(CID_SF,NG,VL,Ord)
3270: && COMMONCHECK_SF ) {
3271: CID_SF=ideal_intersection_sfrat(CID_SF,NG,VL);
3272: }
3273: }
3274: }
3275: break;
3276: }
3277: }
3278: if (I == length(G))
3279: RL = append([G],RL);
3280: return RL;
1.11 noro 3281: }
3282:
3283: def gb_comp_old(A,B)
3284: {
3285: LA = length(A);
3286: LB = length(B);
3287: if ( LA != LB )
3288: return 0;
3289: A = newvect(LA,A);
3290: B = newvect(LB,B);
3291: A1 = qsort(A);
3292: B1 = qsort(B);
3293: for ( I = 0; I < LA; I++ )
3294: if ( A1[I] != B1[I] && A1[I] != -B1[I] )
3295: break;
3296: return I == LA ? 1 : 0;
1.1 noro 3297: }
3298: end$
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>