//////////////////////////////////////////////////////////////////////////////// version="$Id$"; category = "Commutative Algebra"; info=" LIBRARY: primdecint.lib primary decomposition over the integers AUTHORS: G. Pfister pfister@mathematik.uni-kl.de @* A. Sadiq afshanatiq@gmail.com @* S. Steidel steidel@mathematik.uni-kl.de OVERVIEW: A library for computing the primary decomposition of an ideal in the polynomial ring over the integers, Z[x_1,...,x_n]. PROCEDURES: primdecZ(I); compute the primary decomposition of I minAssZ(I); compute the minimal associated primes of I radicalZ(I); compute the radical of I heightZ(I); compute the height of I equidimZ(I); compute the equidimensional part of I intersectZ(I,J) compute the intersection of I and J "; LIB "crypto.lib"; //////////////////////////////////////////////////////////////////////////////// proc primdecZ(ideal I, list #) "USAGE: primdecZ(I); I ideal NOTE: If size(#) > 0, then #[1] is the number of available processors for the computation. Parallelization is just applicable using 32-bit Singular version since MP-links are not compatible with 64-bit Singular version. RETURN: a list pr of primary ideals and their associated primes: @format pr[i][1] the i-th primary component, pr[i][2] the i-th prime component. @end format EXAMPLE: example primdecZ; shows an example " { if(size(I)==0){return(list(ideal(0),ideal(0)));} //-------------------- Initialize optional parameters ------------------------ if(size(#) > 0) { if(size(#) == 1) { int n = #[1]; if((n > 1) && (1 - system("with","MP"))) { "========================================================================"; "There is no MP available on your system. Since this is necessary to "; "parallelize the algorithm, the computation will be done without forking."; "========================================================================"; n = 1; } ideal TES = 1; } if(size(#) == 2) { int n = #[1]; if((n > 1) && (1 - system("with","MP"))) { "========================================================================"; "There is no MP available on your system. Since this is necessary to "; "parallelize the algorithm, the computation will be done without forking."; "========================================================================"; n = 1; } ideal TES = #[2]; } } else { int n = 1; ideal TES = 1; } if(deg(I[1])==0) { ideal J=I; } else { ideal J=stdZ(I); } ideal K,N; def R=basering; number s; list rl=ringlist(R); int i,j,p,m,ex,nu,k_link; list P,B,IS; ideal Q,JJ; ideal TQ=1; if(deg(J[1])==0) { //=== I intersected with Z is not zero list rp=rl; rp[1]=0; //=== q is generator of I intersect Z number q=leadcoef(J[1]); def Rhelp=ring(rp); setring Rhelp; number q=imap(R,q); //=== computes the primes occuring in a generator of I intersect Z list L = primefactors(q); list A; ideal J = imap(R,J); for(j=1;j<=size(L[2]);j++) { if(L[2][j] > 1){ ex = 1; break; } } if(printlevel >= 10) { "n = "+string(n); "size(L[2]) = "+string(size(L[2])); } int RT = rtimer; if((n > 1) && (n < size(L[2]))) { //----- Create n1 links l(1),...,l(n1), open all of them and compute --------- //----- standard basis for the primes L[1][2],...,L[1][n + 1]. --------- for(i = 1; i <= n; i++) { p=int(L[1][i + 1]); nu=int(L[2][i + 1]); link l(i) = "MPtcp:fork"; // link l(i) = "ssi:fork"; open(l(i)); write(l(i), quote(modp(eval(J), eval(p), eval(nu)))); } p = int(L[1][1]); nu = int(L[2][1]); int t = timer; A[size(A)+1] = modp(J, p, nu); t = timer - t; if(t > 60) { t = 60; } int i_sleep = system("sh", "sleep "+string(t)); j = n + 2; while(j <= size(L[2]) + 1) { for(i = 1; i <= n; i++) { //=== ask if link l(i) is ready otherwise sleep for t seconds if(status(l(i), "read", "ready")) { //=== read the result from l(i) A[size(A)+1] = read(l(i)); if(j <= size(L[2])) { p=int(L[1][j]); nu=int(L[2][j]); write(l(i), quote(modp(eval(J), eval(p), eval(nu)))); j++; } else { k_link++; close(l(i)); } } } //=== k_link describes the number of closed links if(k_link == n) { j++; } i_sleep = system("sh", "sleep "+string(t)); } } else { for(j=1;j<=size(L[2]);j++) { A[size(A)+1] = modp(J, L[1][j], L[2][j]); } } setring R; list A = imap(Rhelp,A); if(printlevel >= 10) { "A is computed in "+string(rtimer - RT)+" seconds."; } for(i=1;i<=size(A);i++) { //=== computes for all p in L the minimal associated primes of //=== IZ/p[variables] p = int(A[i][2]); if(printlevel >= 10) { "p = "+string(p); RT = rtimer; } nu = int(A[i][3]); //=== maximal power of p dividing q, generator of I intersect Z s = p^nu; rp[1] = p; def S = ring(rp); setring S; ideal J = imap(R,J); setring R; if(nu>1) { //=== p is of multiplicity > 1 in q B = A[i][1]; for(j=1;j<=size(B);j++) { //=== the minimal associated primes of I K=B[j],p; K=stdZ(K); B[j]=K; } for(j=1;j<=size(B);j++) { K=B[j]; //=== compute maximal independent set for KZ/p[variables] setring S; J=imap(R,K); J=simplify(J,2); attrib(J,"isSB",1); IS=maxIndependSet(J); setring R; //=== computing the pseudo primary and extract it N=J,s; N=stdZ(N); Q=extractZ(N,j,IS,B); //=== test for useless primaries if(size(reduce(TES,Q))>0) { TQ=intersectZ(TQ,Q); P[size(P)+1]=list(Q,K); } } } else { //=== p is of multiplicity 1 in q we can compute the //=== primary decomposition directly B = A[i][1]; for(j=1;j<=size(B);j++) { K=B[j][2],p; K=stdZ(K); Q=B[j][1],p; Q=stdZ(Q); if(size(reduce(TES,Q))>0) { //TQ=intersectZ(TQ,Q); P[size(P)+1]=list(Q,K); } } if(ex) { JJ=imap(S,J); JJ=JJ,p; JJ=stdZ(JJ); TQ=intersectZ(TQ,JJ); } } kill S; if(printlevel >= 10) { string(p)+" done in "+string(rtimer - RT)+" seconds."; } } setring R; if(!ex){return(P);} J=stdZ(J); TQ=intersectZ(TQ,TES); if(size(reduce(TQ,J))!=0) { //=== taking care about embedded components K=stdZ(quotientZ(J,TQ)); ideal W=K; m++; while(size(reduce(intersectZ(W,TQ),J))!=0) { //W=stdZ(addIdealZ(I,K^m)); W=stdZ(addIdealZ(I,specialPowerZ(K,m))); m++; } list E=primdecZ(W,n,TQ); for(i=1;i<=size(E);i++) { P[size(P)+1]=E[i]; } } return(P); } //==== the ideal intersected with Z is zero rl[1]=0; def Rhelp=ring(rl); setring Rhelp; ideal J=imap(R,J); J=std(J); //=== the primary decomposition over Q which gives the primary //=== decomposition of I:h for a suitable integer h list pr=primdecGTZ(J); for(i=1;i<=size(pr);i++) { pr[i]=list(std(pr[i][1]),std(pr[i][2])); } setring R; list pr=imap(Rhelp,pr); //=== intersection with Z[variables] for(i=1;i<=size(pr);i++) { pr[i]=list(coefZ(pr[i][1])[1],coefZ(pr[i][2])[1]); } //=== find h in Z such that I is the intersection of I:h and //=== and I:h = IQ[variables] intersected with Z[varables] list H =coefZ(J); ideal Y=H[1]; int h=H[2]; J=J,h; //=== call primary decomposition over Z for list M; if(h!=1) { M=primdecZ(J,n,Y); j=0; //=== remove useless primary ideals while(j1) { //=== p is of multiplicity >1 in q list A=minAssGTZ(J); j=0; while(j 1) resp. the primary //=== decomposition (else) of J in Z/p and maps the result back to the basering def R = basering; list rp = ringlist(R); rp[1] = p; def Rp = ring(rp); setring Rp; ideal J = imap(R,J); if(nu > 1) { //=== p is of multiplicity > 1 in q list A = minAssGTZ(J); setring R; list A = imap(Rp,A); return(list(A,p,nu)); } else { list A = primdecGTZ(J); setring R; list A = imap(Rp,A); return(list(A,p,nu)); } } //////////////////////////////////////////////////////////////////////////////// static proc coefPrimeZ(ideal I) { //=== computes the primes occuring in the product of the leading coefficients //=== of I number h=1; int i; for(i=1;i<=size(I);i++) { h=h*leadcoef(I[i]); // besser machen (gleich zerlegen, // nicht ausmultiplizieren) } def R=basering; ring Rhelp=0,x,dp; number h=imap(R,h); list L=PollardRho(h,5000,1); for(i=1;i<=size(L);i++){L[i]=int(L[i]);} setring R; return(L); } //////////////////////////////////////////////////////////////////////////////// static proc coefZ(ideal I) { //=== assume IQ[variables]=, Groebner basis, g_i in Z[variables] //=== computes an integer h such that //=== Z[variables]:h^infinity = IQ[variables] intersected //=== with Z[variables] //=== returns a list with IQ[variables] intersected with Z[variables] and h int h=1; int i,e; ideal K=1; list L=coefPrimeZ(I); if(size(L)==0){return(list(I,1));} int d=1; while(d!=0) { i++; K=quotientOneZ(I,L[i]); if(size(reduce(K,I))!=0) { h=h*L[i]; I=stdZ(K); e=1; } if(i==size(L)) { i=0; if(e) { e=0; } else { d=0; } } } if(h<0){h=-h;} return(list(K,h)); } //////////////////////////////////////////////////////////////////////////////// static proc specialPowerZ(ideal I, int m) { //=== computes the ideal generated by the m-th power of the generators of I int i; for(i=1;i<=size(I);i++) { I[i]=I[i]^m; } return(I); } //////////////////////////////////////////////////////////////////////////////// static proc separatorsZ(int j, list B) { //=== computes s such that s is not in B[j] but s is in B[i] for all i!=j int i,k; poly s=1; for(i=1;i<=size(B);i++) { if(i!=j) { for(k=1;k<=size(B[i]);k++) { if(reduce(B[i][k],B[j])!=0) { s=s*B[i][k]; break; } } } } return(s); } //////////////////////////////////////////////////////////////////////////////// static proc extractZ(ideal J, int j, list L, list B) { //=== P is an associated prime of J, the corresponding primary ideal is //=== computed, //=== L is a list of maximal independent sets for P in Z/p[variables] def R=basering; ideal P=B[j]; //=== first compute a pseudo primary ideal I, radical of I is P //=== method of Eisenbud //ideal I=addIdealZ(J,specialPowerZ(P,20)); //=== method of Shimoyama-Yokoyama poly s=separatorsZ(j,B); ideal I=satZ(J,s); //=== size(L)=0 means P is maximal ideal and I is primary if(size(L)>0) { if(L[1][3]!=0) { //=== if u in x is an independent set of L then we compute a Groebner //=== Basis in Z[u][x-u] execute("ring S=integer,("+L[1][1]+"),lp;"); ideal I=imap(R,I); I=stdZ(I); list rl=ringlist(S); rl[1]=0; def Shelp =ring(rl); setring Shelp; ideal I=imap(S,I); I[1]=0; I=simplify(I,2); //=== this is our way to obtain the coefficients in Z[u] of the //=== leading terms of the Groebner basis above string quotring=prepareQuotientring(nvars(basering)-L[1][3]); execute(quotring); ideal I=imap(Shelp,I); list C; int i; for(i=1;i<=size(I);i++) { C[i]=leadcoef(I[i]); } setring Shelp; list C=imap(quring,C); setring R; list C=imap(Shelp,C); } else { I=stdZ(I); list C; int i; for(i=1;i<=size(I);i++) { C[i]=I[i]; } list rl=ringlist(R); rl[1]=0; def Shelp =ring(rl); } poly h=1; for(i=1;i<=size(C);i++) { if(deg(C[i])>0){h=h*C[i];} // das muss noch besser gemacht werden, // nicht ausmultiplizieren! } setring Shelp; poly h=imap(R,h); ideal fac=factorize(h,1); setring R; ideal fac=imap(Shelp,fac); for(i=1;i<=size(fac);i++) { I=satZ(I,fac[i]); } } I=stdZ(I); return(I); } //////////////////////////////////////////////////////////////////////////////// static proc normalizeZ(ideal I) { //=== if I[1]=q in Z, it replaces all other coeffs of polys in I by there value //=== mod q, std should do this automatically and then this procedure should be //=== removed if(deg(I[1])>0){return(I);} int i,j; number n; poly p; for(i=2;i<=size(I);i++) { j=1; while(j<=size(I[i])) { n=leadcoef(I[i][j]) mod leadcoef(I[1]); p=n*leadmonom(I[i][j]); I[i]=I[i]-I[i][j]+p; if(p!=0){j++;} } } return(I); } //////////////////////////////////////////////////////////////////////////////// static proc satZ(ideal I,poly h) { //=== saturates I by h ideal J=quotientOneZ(I,h); while(size(reduce(J,stdZ(I)))!=0) { I=J; J=quotientOneZ(I,h); J=normalizeZ(J); } return(J); } //////////////////////////////////////////////////////////////////////////////// static proc prepareQuotientring (int nnp) { //=== this is from primdec.lib, it is static there, should be imported later //=== if it is no more static ideal @ih,@jh; int npar=npars(basering); int @n; string quotring= "ring quring = ("+charstr(basering); for(@n=nnp+1;@n<=nvars(basering);@n++) { quotring=quotring+",var("+string(@n)+")"; @ih=@ih+var(@n); } quotring=quotring+"),(var(1)"; @jh=@jh+var(1); for(@n=2;@n<=nnp;@n++) { quotring=quotring+",var("+string(@n)+")"; @jh=@jh+var(@n); } quotring=quotring+"),(C,lp);"; return(quotring); } //////////////////////////////////////////////////////////////////////////////// static proc maxIndependSet (ideal j) { //=== this is from primdec.lib, it is static there, should be imported later //=== if it is no more static int n,k,di; list resu,hilf; if(size(j)==0) { resu[1]=varstr(basering); resu[2]=ordstr(basering); resu[3]=0; return(list(resu)); } string var1,var2; list v=indepSet(j,0); for(n=1;n<=size(v);n++) { di=0; var1=""; var2=""; for(k=1;k<=size(v[n]);k++) { if(v[n][k]!=0) { di++; var2=var2+"var("+string(k)+"),"; } else { var1=var1+"var("+string(k)+"),"; } } if(di>0) { var1=var1+var2; var1=var1[1..size(var1)-1]; hilf[1]=var1; hilf[2]="lp"; hilf[3]=di; resu[n]=hilf; } else { resu[n]=varstr(basering),ordstr(basering),0; } } return(resu); } //////////////////////////////////////////////////////////////////////////////// static proc quotientOneZ(ideal I, poly f) { //=== this is needed because quotient(I,f) does not work properly, should be //=== replaced by quotient later def R=basering; int i; ideal K=intersectZ(I,ideal(f)); //=== K[i]/f; does not work in rings with integer! This should be replaced //=== later execute("ring Rhelp=0,("+varstr(R)+"),dp;"); ideal K=imap(R,K); poly f=imap(R,f); for(i=1;i<=size(K);i++) { K[i]=K[i]/f; } setring R; K=imap(Rhelp,K); return(K); } //////////////////////////////////////////////////////////////////////////////// static proc quotientZ(ideal I, ideal J) { //=== this is needed because quotient(I,J) does not work properly, should be //=== replaced by quotient later int i; ideal K=quotientOneZ(I,J[1]); for(i=2;i<=size(J);i++) { K=intersectZ(K,quotientOneZ(I,J[i])); } return(K); } //////////////////////////////////////////////////////////////////////////////// static proc reduceZ(poly f, ideal I) { //=== this is needed because reduce(f,I) does not work properly, should be //=== replaced by reduce later if(f==0){return(f);} def R=basering; execute("ring Rhelp=0,("+varstr(R)+"),dp;"); ideal I=imap(R,I); poly f=imap(R,f); int i,j; poly m; number n; while(!i) { i=1; j=0; while(j