Changeset 654a23 in git


Ignore:
Timestamp:
Jul 23, 2015, 2:48:14 PM (8 years ago)
Author:
Stephan Oberfranz <oberfran@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
74fe3587102ed73b3858258975abbe6d63139abf
Parents:
8d7ca03d4444afafa6c2111db95d65216b93ad464132ee2e5b539d15463dcf3db09fbf9aa7c00877
Message:
update

Merge branch 'spielwiese' of github.com:Singular/Sources into spielwiese
Files:
4 deleted
70 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/classify_aeq.lib

    r8d7ca0 r654a23  
    77AUTHORS: Faira Kanwal Janjua     fairakanwaljanjua@gmail.com
    88         Gerhard Pfister         pfister@mathematik.uni-kl.de
     9         Khawar Mehmood          khawar1073@gmail.com                         NEU
    910
    1011OVERVIEW: A library for classifying the simple singularities
     
    2223  [4] Bruce, J.W.,Gaffney, T.J.: Simple singularities of mappings (C, 0) ->(C2,0).
    2324  J. London Math. Soc. (2) 26 (1982), 465-474.
    24 
     25  [5] Ishikawa,G; Janeczko,S.: The Complex Symplectic Moduli Spaces of Unimodal Parametric Plane Curve  NEU Singularities. Insitute of Mathematics of the Polish Academy of Sciences,Preprint 664(2006)
    2526PROCEDURES:
    2627          sagbiAlg(G);    Compute the Sagbi-basis of the Algebra.
     
    662663
    663664////////////////////////////////////////////////////////////////////////////////
    664 proc sagbiAlg(ideal I)
     665proc sagbiAlg(ideal I,list #)
    665666"USAGE":  sagbiAlg(I);  I ideal
    666667RETURN: An ideal.The sagbi bases of I.
     
    676677
    677678    if(size(I)==0){return(I);}
    678     int b=ConductorBound(I);
    679 
    680   // int b=200;
     679    if(size(#)==0)
     680    {
     681       int b=ConductorBound(I);
     682    // int b=200;
    681683  //   b=correctBound(I,b);
     684    }
     685    else
     686    {
     687       int b=#[1];
     688    }
    682689   ideal S=interReduceSagbi(I,b) ;
    683690  // b=correctBound(S,b);
     
    699706   return(S);
    700707}
    701 
    702708example
    703709{
     
    709715sagbiAlg(I);
    710716}
    711 
     717//////////////////////////////////////////////////////////////////////////////// NEU
     718proc reducedSagbiAlg(ideal I,list #)
     719{
     720
     721   I=sagbiAlg(I,#);
     722   intvec L=semiGroup(I)[3];
     723   if(size(#)==0)
     724   {
     725      int b=findConductor(L);
     726   }
     727   else
     728   {
     729      int b=#[1];
     730   }
     731   int i;
     732   poly q;
     733   for(i=1;i<=size(I);i++)
     734   {
     735      q=I[i]-lead(I[i]);
     736      q=sagbiNF(q,I,b);
     737      I[i]=lead(I[i])+q;
     738   }
     739   return(I);
     740}
     741example
     742{
     743  "EXAMPLE:"; echo=2;
     744ring R=0,t,ds;
     745ideal I=t4+2t9,t9+t10+19/18t11-3t12+t13-t14;
     746reducedSagbiAlg(I);
     747}
     748////////////////////////////////////////////////////////////////////////////////   NEU
     749proc classifyAEQunimodal(ideal I)
     750"USAGE":  classifyAEQunimodal(I);  I ideal generated by 2 polynomials
     751RETURN: An ideal.Ideal is one of the singularity in the list of Ishikawa and Jenczko [5]
     752EXAMPLE: example classifyAEQunimodal;  shows an example
     753"
     754{
     755    def R=basering;
     756    ring @S=0,t,ds;
     757    ideal I=fetch(R,I);
     758    ideal J;
     759    poly g;
     760    if(size(I)>=3){ERROR("not a plane curve");}
     761    I=simplify(I,2);   //deletes zero’s i I
     762    I=simplify(I,1);   //creates monic generators in I
     763    if(ord(I[1])>ord(I[2])){poly q=I[2];I[2]=I[1];I[1]=q;}
     764    if((ord(I[1])>=6)||(ord(I[1])<=3)){return("not in the unimodal list");}
     765    //compute estimate of the term with the modulus
     766    int c=ord(sagbiNF(I[2],ideal(I[1]),10));
     767    if(c==10)
     768    {
     769       if(ord(I[1])!=4){return("not in the unimodal list");}
     770       c=ord(I[2][2])+2;
     771    }
     772    else
     773    {
     774       c=0;
     775       intvec v=ord(I[1]),ord(I[2]);
     776       if(v==intvec(5,6)){c=14;}
     777       if(v==intvec(5,7)){c=18;}
     778       if(v==intvec(5,8)){c=22;}
     779       if(v==intvec(4,9)){c=19;}
     780       if(v==intvec(4,11)){c=25;}
     781       if(c==0){return("not in the unimodal list");}
     782    }
     783    while(size(I[1])>1)
     784    {
     785      I=jet(subst(I,t,t-number(1)/number(ord(I[1]))*leadcoef(I[1][2])*t^(ord(I[1][2])-ord(I[1])+1)),c);
     786    }
     787    ideal G=I;
     788    G[2]=sagbiNF(G[2],ideal(G[1]),c);
     789    ideal M=sagbiMod(diff(G,t),G);
     790    list K=semiMod(M,G);
     791
     792    if(K[1]==intvec(4,9))
     793    {
     794       if(K[4]==intvec(3,8)){J=t4,t9;}
     795       if(K[4]==intvec(3,8,22)){J=t4,t9+t19;}
     796       if(K[4]==intvec(3,8,18)){J=t4,t9+t15;}
     797       if(K[4]==intvec(3,8,14)){J=t4,t9+t11;}
     798       if(K[4]==intvec(3,8,13))
     799       {
     800          G=reducedSagbiAlg(G,15);
     801          if(ord(G[2][4])==14)
     802          {
     803             //kill the term t14 by some transformation
     804             G=subst(G,t,t-leadcoef(G[2][4])/9*t^6);
     805             G=jet(G,15);
     806             G[1]=sagbiNF(G[1],ideal(G[2]),15);
     807             //arrange the first element to be t4
     808             while(size(G[1])>1)
     809             {
     810                G=subst(G,t,t-1/4*(G[1]-lead(G[1]))/t^3);
     811                G=jet(G,15);
     812             }
     813          }
     814          G[2]=sagbiNF(G[2],ideal(G[1]),15);
     815          //arrange the coefficient of t10 to become 1
     816          number m=leadcoef(G[2]-lead(G[2]));
     817          G[2]=m^9*subst(G[2],t,1/m*t);
     818          J=G;
     819       }
     820       if(K[4]==intvec(3,8,13,18))
     821       {
     822          G=reducedSagbiAlg(G,11);
     823          number m=leadcoef(G[2]-lead(G[2]));
     824          G[2]=m^9*subst(G[2],t,1/m*t);
     825          J=G;
     826       }
     827    }
     828    if(K[1]==intvec(4,11))
     829    {
     830       if(K[4]==intvec(3,10)){J=t4,t11;}
     831       if(K[4]==intvec(3,10,28)){J=t4,t11+t25;}
     832       if(K[4]==intvec(3,10,24)){J=t4,t11+t21;}
     833       if(K[4]==intvec(3,10,20)){J=t4,t11+t17;}
     834       if(K[4]==intvec(3,10,16))
     835       {
     836          G=reducedSagbiAlg(G,14);
     837          number m=leadcoef(G[2]-lead(G[2]));
     838          number l=leadcoef(G[2][3]);
     839          //lambda^2=l^2/m^3
     840          J=G;
     841       }
     842       if(K[4]==intvec(3,10,17))
     843       {
     844          G=reducedSagbiAlg(G,21);
     845          if(ord(G[2][4])==18)
     846          {
     847             //kill the term t18 by some transformation
     848             G=subst(G,t,t-leadcoef(G[2][4])/11*t^8);
     849             G=jet(G,21);
     850             G[1]=sagbiNF(G[1],ideal(G[2]),21);
     851             //arrange the first element to be t4
     852             while(size(G[1])>1)
     853             {
     854                G=subst(G,t,t-1/4*(G[1]-lead(G[1]))/t^3);
     855                G=jet(G,21);
     856             }
     857          }
     858          G[2]=sagbiNF(G[2],ideal(G[1]),21);
     859          //arrange the coefficient of t14 to become 1
     860          number m=leadcoef(G[2]-lead(G[2]));
     861          number l=leadcoef(G[2][4]);
     862          //lambda^2=l^3/m^10
     863          J=G;
     864
     865
     866       }
     867       if(K[4]==intvec(3,10,17,24))
     868       {
     869          G=reducedSagbiAlg(G,18);
     870          //arrange the coefficient of t14 to become 1
     871          number m=leadcoef(G[2]-lead(G[2]));
     872          G[2]=t11+t14+leadcoef(G[2][3])/m^2*t17;
     873          J=G;
     874       }
     875    }
     876    if((size(K[1])==3)&&(K[1][1]==4)&&(K[1][2]==10))
     877    {
     878       int l=(K[1][3]-19) div 2;
     879       G=reducedSagbiAlg(G,2*l+12);
     880       number m=leadcoef(G[2]-lead(G[2]));
     881       number s=leadcoef(G[2][3]);
     882       //lambda^(2l-1)=s^(2l-1)/m^(2l+1)
     883       J=G;
     884    }
     885    if(K[1]==intvec(5,6))
     886    {
     887       if(K[4]==intvec(4,5)){J=t5,t6;}
     888       if(K[4]==intvec(4,5,18)){J=t5,t6+t14;}
     889       if(K[4]==intvec(4,5,13)){J=t5,t6+t9;}
     890       if(K[4]==intvec(4,5,12))
     891       {
     892          G=reducedSagbiAlg(G,9);
     893          if(ord(G[2][2])==7)
     894          {
     895             //kill the term t7 by some transformation
     896             G=subst(G,t,t-leadcoef(G[2][2])/6*t^2);
     897             G=jet(G,10);
     898             G[1]=sagbiNF(G[1],ideal(G[2]),9);
     899             //arrange the first element to be t4
     900             while(size(G[1])>1)
     901             {
     902                G=subst(G,t,t-1/5*(G[1]-lead(G[1]))/t^4);
     903                G=jet(G,9);
     904             }
     905          }
     906          G[2]=sagbiNF(G[2],ideal(G[1]),9);
     907          //arrange the coefficient of t8 to become 1
     908          number m=leadcoef(G[2]-lead(G[2]));
     909          number l=leadcoef(G[2][3]);
     910          //lambda^2=l^2/m^3
     911          J=G;
     912
     913       }
     914    }
     915    if(K[1]==intvec(5,7))
     916    {
     917       if(K[4]==intvec(4,6)){J=t5,t7;}
     918       if(K[4]==intvec(4,6,22)){J=t5,t7+t18;}
     919       if(K[4]==intvec(4,6,17)){J=t5,t7+t13;}
     920       if(K[4]==intvec(4,6,12))
     921       {
     922          G=reducedSagbiAlg(G,11);
     923          if(ord(G[2][3])==9)
     924          {
     925             //kill the term t9 by some transformation
     926             G=subst(G,t,t-leadcoef(G[2][3])/7*t^3);
     927             G=jet(G,11);
     928             G[1]=sagbiNF(G[1],ideal(G[2]),11);
     929             //arrange the first element to be t4
     930             while(size(G[1])>1)
     931             {
     932                G=subst(G,t,t-1/5*(G[1]-lead(G[1]))/t^4);
     933                G=jet(G,11);
     934             }
     935          }
     936          G[2]=sagbiNF(G[2],ideal(G[1]),11);
     937          //arrange the coefficient of t8 to become 1
     938          number m=leadcoef(G[2]-lead(G[2]));
     939          G[2]=m^7*subst(G[2],t,1/m*t);
     940          J=G;
     941       }
     942       if(K[4]==intvec(4,6,15))
     943       {
     944          G=reducedSagbiAlg(G,14);
     945          if(ord(G[2][2])==9)
     946          {
     947             //kill the term t9 by some transformation
     948             G=subst(G,t,t-leadcoef(G[2][2])/7*t^3);
     949             G=jet(G,14);
     950             G[1]=sagbiNF(G[1],ideal(G[2]),14);
     951             //arrange the first element to be t4
     952             while(size(G[1])>1)
     953             {
     954                G=subst(G,t,t-1/5*(G[1]-lead(G[1]))/t^4);
     955                G=jet(G,14);
     956             }
     957          }
     958          G[2]=sagbiNF(G[2],ideal(G[1]),14);
     959          //arrange the coefficient of t11 to become 1
     960          number m=leadcoef(G[2]-lead(G[2]));
     961          number l=leadcoef(G[2][3]);
     962          //lambda^2=l^2/m^3
     963          J=G;
     964       }
     965
     966    }
     967    if(K[1]==intvec(5,8))
     968    {
     969       if(K[4]==intvec(4,7)){J=t5,t8;}
     970       if(K[4]==intvec(4,7,26)){J=t5,t8+t22;}
     971       if(K[4]==intvec(4,7,21)){J=t5,t8+t17;}
     972       if(K[4]==intvec(4,7,13))
     973       {
     974          G=reducedSagbiAlg(G,12);
     975          if(ord(G[2][3])==11)
     976          {
     977             //kill the term t11 by some transformation
     978             G=subst(G,t,t-leadcoef(G[2][3])/8*t^4);
     979             G=jet(G,12);
     980             G[1]=sagbiNF(G[1],ideal(G[2]),12);
     981             //arrange the first element to be t4
     982             while(size(G[1])>1)
     983             {
     984                G=subst(G,t,t-1/5*(G[1]-lead(G[1]))/t^4);
     985                G=jet(G,12);
     986             }
     987          }
     988          G[2]=sagbiNF(G[2],ideal(G[1]),12);
     989          //arrange the coefficient of t9 to become 1
     990          number m=leadcoef(G[2]-lead(G[2]));
     991          G[2]=m^8*subst(G[2],t,1/m*t);
     992          J=G;
     993       }
     994
     995       if(K[4]==intvec(4,7,16))
     996       {
     997          G=reducedSagbiAlg(G,14);
     998          if(ord(G[2][2])==11)
     999          {
     1000             //kill the term t11 by some transformation
     1001             G=subst(G,t,t-leadcoef(G[2][2])/8*t^4);
     1002             G=jet(G,14);
     1003             G[1]=sagbiNF(G[1],ideal(G[2]),14);
     1004             //arrange the first element to be t4
     1005             while(size(G[1])>1)
     1006             {
     1007                G=subst(G,t,t-1/5*(G[1]-lead(G[1]))/t^4);
     1008                G=jet(G,14);
     1009             }
     1010          }
     1011          G[2]=sagbiNF(G[2],ideal(G[1]),14);
     1012          //arrange the coefficient of t12 to become 1
     1013          number m=leadcoef(G[2]-lead(G[2]));
     1014          number l=leadcoef(G[2][3]);
     1015          //lambda^2=l^2/m^3
     1016          J=G;
     1017
     1018       }
     1019       if(K[4]==intvec(4,7,18))
     1020       {
     1021          G=reducedSagbiAlg(G,17);
     1022          if(ord(G[2][2])==11)
     1023          {
     1024             //kill the term t11 by some transformation
     1025             G=subst(G,t,t-leadcoef(G[2][2])/8*t^4);
     1026             G=jet(G,17);
     1027             G[1]=sagbiNF(G[1],ideal(G[2]),17);
     1028             //arrange the first element to be t4
     1029             while(size(G[1])>1)
     1030             {
     1031                G=subst(G,t,t-1/5*(G[1]-lead(G[1]))/t^4);
     1032                G=jet(G,17);
     1033             }
     1034          }
     1035          G[2]=sagbiNF(G[2],ideal(G[1]),17);
     1036          //arrange the coefficient of t12 to become 1
     1037          number m=leadcoef(G[2]-lead(G[2]));
     1038          number l=leadcoef(G[2][3]);
     1039          //lambda^2=l^2/m^3
     1040          J=G;
     1041       }
     1042    }
     1043    setring R;
     1044    ideal J=fetch(@S,J);
     1045    if(size(J)==0)
     1046    {
     1047       return("not in the unimodal list");
     1048    }
     1049    return(J);
     1050}
     1051example
     1052{
     1053  "EXAMPLE:"; echo=2;
     1054ring R=0,t,ds;
     1055ideal I=t4,9t9+18t10+38t11-216t12+144t13-288t14;
     1056classifyAEQunimodal(I);
     1057I=t4,9t9+18t10+40t11-216t12+144t13-288t14;
     1058classifyAEQunimodal(I);
     1059I=t4,t11+t12+3t14+2t15+7t16+7t17;
     1060classifyAEQunimodal(I);
     1061I=t4,t11+t14+25/22t17+3t18+4t21;
     1062classifyAEQunimodal(I);
     1063I=t5,t6+2t7+t8+3t9;
     1064classifyAEQunimodal(I);
     1065I=t5,t7+3t8+3t9+5t10;
     1066classifyAEQunimodal(I);
     1067I=t5,t7+3t11+3t12+5t13;
     1068classifyAEQunimodal(I);
     1069I=t5,t8+3t9+5t10+2t11+3t12+5t13;
     1070classifyAEQunimodal(I);
     1071I=t5,t8+5t11+3t12+7t13+5t14;
     1072classifyAEQunimodal(I);
     1073I=t5,t8+5t11+7t13+5t14+7t15+2t16+8t17;
     1074classifyAEQunimodal(I);
     1075I=subst(I,t,t+t2);
     1076classifyAEQunimodal(I);
     1077I=t4+2t5+3t6+5t7+t8,9t9+18t10+40t11-216t12+144t13-288t14;
     1078classifyAEQunimodal(I);
     1079}
     1080////////////////////////////////////////////////////////////////////////////////   NEU
     1081proc computeModulus(poly p)
     1082"USAGE":  computeModulus(p);  p monic poly with 3 or 4 monomials
     1083RETURN: A polynomial with first and second coefficient 1
     1084EXAMPLE: computeModulus;  shows an example
     1085ASSUME: the basering has one vearable and one parameter
     1086"
     1087{
     1088   def R=basering;
     1089   int a1=ord(p);
     1090   int a2=ord(p-lead(p));
     1091   number m=leadcoef(p-lead(p));
     1092
     1093   poly q=par(1)^(a2-a1)-1/m;
     1094   ring S=(0,a),t,ds;
     1095   number m=fetch(R,m);
     1096   minpoly=par(1)^(a2-a1)-1/m;
     1097   poly p=fetch(R,p);
     1098   p=1/par(1)^a1*subst(p,var(1),par(1)*var(1));
     1099   setring R;
     1100   p=imap(S,p);
     1101   return(list(p,q));
     1102}
     1103example
     1104{
     1105  "EXAMPLE:"; echo=2;
     1106ring R=(0,a),t,ds;
     1107poly p=t8-395/16t14+4931/32t17;
     1108computeModulus(p);
     1109p=t8+3t12-395/16t14;
     1110computeModulus(p);
     1111p=t8-395/16t14+4931/32t17;
     1112computeModulus(p);
     1113
     1114}
     1115
     1116////////////////////////////////////////////////////////////////////////////////   NEU
     1117static proc n_thRoot(poly p,int n, int b)
     1118{
     1119   //computes the n-th root of 1+p up to order b
     1120   //assumes that p(0)=0
     1121   poly s=1;
     1122   poly q=jet(p,b);
     1123   if(q==0){return(s);}
     1124   int i;
     1125   for(i=1;i<=b;i++)
     1126   {
     1127      s=s+bino(n,i)*q;
     1128      q=jet(q*p,b);
     1129   }
     1130   return(jet(s,b));
     1131}
     1132////////////////////////////////////////////////////////////////////////////////   NEU
     1133static proc bino(number n, int i)
     1134{
     1135//computes the i-th binomial coefficient of 1/n
     1136   if(i==0){return(1);}
     1137   return(bino(n,i-1)*(1/n-i+1)/i);
     1138}
    7121139////////////////////////////////////////////////////////////////////////////////
    7131140proc sagbiMod(ideal I,ideal G)
     
    12831710    execute
    12841711    ("ring T=("+charstr(br)+",x(1),z(1..n)),(x(2),y(1..m)),dp;");
    1285     execute
    1286     ("ring R=("+charstr(br)+"),(x(1..2),y(1..m),z(1..n)),(lp(m+2),dp(n));");
     1712     execute
     1713    ("ring R=("+charstr(br)+"),(x(1..2),y(1..m),z(1..n)),(lp(2),dp(m),dp(n));");
     1714
    12871715     map phi = br,x(1);
    12881716     ideal P = phi(G1);
     
    13051733     M[size(M)+1]=check-x(2);
    13061734     check=check*keep;
     1735
    13071736     option(redSB);
    13081737     M=std(M);
    13091738     int j,s;
     1739
    13101740     for(i=1;i<=size(M);i++)
    13111741     {
     
    13421772         f=sagbiNFMODO(f,G,I,b);
    13431773    }
    1344     return(f+sagbiNFMOD(p-lead(p),G,I,b));
     1774    return(lead(f)+sagbiNFMOD(p-lead(p),G,I,b));
    13451775}
    13461776////////////////////////////////////////////////////////////////////////////////
  • Singular/LIB/crypto.lib

    r8d7ca0 r654a23  
    6969  merkle_hellman_transformation(list knapsack, int key, int mod1                generates a hard knapsack for the  Merkle-Hellman Kryptosystem for a given easy knapsack , a multiplicator key and a modulus mod1
    7070  merkle_hellman_encryption(list knapsack, list message)                    encrypts a message with the Merkle-Hellman Kryptosystem, using a hard knapsack and a message encoded as binary list
    71   merkle_hellman_decryption(list knapsack, int key, int mod1, int message)          decrypts a message with the multiplicative Merkle-Hellman Kryptosystem, using the hard knapsack, the key, the modulus mod1 and the message encoded as integer   
     71  merkle_hellman_decryption(list knapsack, int key, int mod1, int message)          decrypts a message with the multiplicative Merkle-Hellman Kryptosystem, using the hard knapsack, the key, the modulus mod1 and the message encoded as integer
    7272  super_increasing_knapsack(int ksize)                            Creates the smallest super-increasing knapsack of given size ksize
    7373  h_increasing_knapsack(int ksize, int h)                            Creates the smallest h-increasing knapsack of given size ksize and h
     
    12721272   if((k mod 2)==0)
    12731273   {
    1274       resu=ellipticMult(N,a,b,P,k/2);
     1274      resu=ellipticMult(N,a,b,P,k div 2);
    12751275      return(ellipticAdd(N,a,b,resu,resu));
    12761276   }
  • Singular/LIB/gmssing.lib

    r8d7ca0 r654a23  
    110110
    111111  M=transpose(simplify(M,2));
    112   I=M[1];
     112  I=ideal(M[1]);
    113113  attrib(I,"isSB",1);
    114114  M=M[2..ncols(M)];
  • Singular/LIB/gradedModules.lib

    r8d7ca0 r654a23  
    3131    grsum(M,N)      direct sum of two graded modules coker(M) + coker(N)
    3232    grpower(M,p)    direct p-th power of graded module coker(M)
    33     grtranspose(M)  un-ordered graded transpose of map M       
     33    grtranspose(M)  un-ordered graded transpose of map M
    3434    grgens(M)       try to compute submodule generators of coker(M)
    3535    grpres(F)       presentation of submodule generated by columns of F
     
    5151    mappingcone(M,N)   mapping cone?
    5252    grlifting3(A,B)    RND! chain lifting? probably wrong one
    53     mappingcone3(A,B)  mapping cone3? 
     53    mappingcone3(A,B)  mapping cone3?
    5454    grrange(M)         get the row-weightings
    5555    grneg(A)           graded object given by -A
    5656    matrixpres(a)      matrix presentation of direct sum of Omega^{a[i]}(i)
    5757";
    58    
     58
    5959//    grisequal(A,B)  check whether A is exactly eqal to B? TODO: isomorphic!
    6060
     
    8686
    8787  v = -v; // NOTE: due to Mathematical meanings of Singular data
    88  
     88
    8989
    9090  int lst = v[1];
    91   int cnt = 1; 
     91  int cnt = 1;
    9292
    9393  string p = R;
     
    9595
    9696  int k, d;
    97   for (k = 2; k <= n; k++ ) 
     97  for (k = 2; k <= n; k++ )
    9898  {
    9999    d = v[k];
    100100    if( d == lst ) { cnt = cnt + 1; }
    101     else 
     101    else
    102102    {
    103103      if (cnt > 1){ p = p + "^" + string(cnt); }
     
    120120  def E = grtwist(2, 0);
    121121  def v = grrange(E); // grdeg(E);
    122   grsumstr("", v ); 
     122  grsumstr("", v );
    123123}
    124124
     
    180180  {
    181181    int n = size(N); ASSUME(0, n > 0);
    182    
     182
    183183    string msg1 = "";
    184184    if( size(R) >= 2 )
     
    186186      msg1 = msg1 + "(let R:="+R+")";
    187187      R = "R"; // !!!
    188     }   
     188    }
    189189    msg1 = msg1 + ": " ;
    190190
    191    
     191
    192192
    193193    list arr; arr[n] = list();
    194194    int exact = (1==1);
    195    
     195
    196196    int i = 1;
    197    
     197
    198198    ASSUME(1, grtest(N[i]));
    199    
     199
    200200    string dst = grsumstr(R, grrange(N[i]));
    201201    string src = grsumstr(R, grdeg(N[i]));
    202    
     202
    203203    arr[i] = list(dst,  src);
    204204
    205205    i = i + 1;
    206    
     206
    207207    while( i <= n )
    208208    {
    209209      ASSUME(1, grtest(N[i]));
    210      
     210
    211211      dst = grsumstr(R, grrange(N[i]));
    212      
     212
    213213      if( exact && (src != dst) )
    214214      {
     
    218218
    219219      src = grsumstr(R, grdeg(N[i]));
    220      
     220
    221221      arr[i] = list(dst,  src);
    222222
     
    236236        msg = msg + newline + arr[i][1] + " <-- "+o+"_" + string(i) + " --";
    237237      };
    238      
     238
    239239      msg =  msg + newline + arr[n][2];
    240       msg = msg + ", given by maps: "; 
     240      msg = msg + ", given by maps: ";
    241241    } else
    242242    {
    243243//      print(arr);
    244244
    245       msg = msg + "-object collection";     
     245      msg = msg + "-object collection";
    246246      o = "o";
    247      
     247
    248248//      for( i = 1; i <= n; i++ )
    249249//      {
    250250//        msg = msg + newline + arr[i][1] + " <-- "+o+"_" + string(i) + " -- " + arr[i][2];
    251 //      };     
    252       msg = msg + ", given by the following maps (named here as "+o+"_[1 .. "+string(n)+"]): "; 
     251//      };
     252      msg = msg + ", given by the following maps (named here as "+o+"_[1 .. "+string(n)+"]): ";
    253253    }
    254254
     
    257257
    258258    for( i = 1; i <= size(N); i++ )
    259     { 
     259    {
    260260      print( o+"_" + string(i) + " :" );
    261       grview( N[i] ); 
     261      grview( N[i] );
    262262    };
    263263
     
    268268
    269269  ASSUME(1, grtest(N) );
    270  
     270
    271271  msg = msg + " homomorphism";
    272272  if( size(R) >= 2 )
     
    280280  intvec gr = grrange(N); // grading weights?
    281281  string dst = grsumstr(R, gr);
    282  
     282
    283283  intvec G = grdeg(N);
    284284  string src = grsumstr(R, G);
    285  
     285
    286286  if( ncols(N) == 0 )
    287287  {
    288288    src = "0";
    289   } 
     289  }
    290290
    291291  lst = msg;
    292292
    293   if( (size(lst) + size(dst) + size(src) + 4) > 80 ) 
    294   { 
     293  if( (size(lst) + size(dst) + size(src) + 4) > 80 )
     294  {
    295295    if( (size(lst) + size(dst)) > 80 ) { msg = msg + newline; lst = ""; }
    296296
     
    312312//  lst = lst + ", given by ";
    313313
    314  
     314
    315315  int nc = ncols(N); int nr = nrows(N);
    316316
     
    323323  {
    324324    ASSUME(0, nc > 0);
    325    
     325
    326326    matrix M = module(N);
    327    
     327
    328328    int r,c;
    329329    int d = 1; // number of extra cols/rows for extra info around the central degree(N) block in D
     
    361361      }
    362362
    363     } else 
    364     { 
     363    } else
     364    {
    365365      msg = msg + "a matrix";
    366366    }
    367367
    368     print(msg + ", with degrees: " );   
    369     draw(D, d); // print it nicely!   
     368    print(msg + ", with degrees: " );
     369    draw(D, d); // print it nicely!
    370370  }
    371371}
     
    462462"
    463463{
    464   ASSUME(1, grtest(M) ); 
    465  
     464  ASSUME(1, grtest(M) );
     465
    466466  if ( typeof(attrib(M, "degHomog")) == "intvec" )
    467467  {
     
    469469
    470470    if( size(t) == 0 ){ return (t); } // ZERO!
    471    
     471
    472472    ASSUME(2, ncols(M) == size(t) );
    473473    return (t);
     
    629629  "Input degrees: "; grview(I);
    630630
    631   def RR = grres(I, 0, 1); list L = RR; 
     631  def RR = grres(I, 0, 1); list L = RR;
    632632
    633633  " = Non-minimal betti numbers: "; print(betti(L, 0), "betti");
     
    830830
    831831  ring r=32003,(x,y,z),dp;
    832  
     832
    833833  grview( grtwists ( intvec(-4, 1, 6 )) );
    834834
     
    843843"
    844844{
    845   ASSUME(0, a > 0); 
     845  ASSUME(0, a > 0);
    846846  def Z = grtwists( intvec(d:a) ); // will set the rank as well
    847847//  ASSUME(2, grisequal(Z, grpower( grshift(grzero(), d), a ) )); // optional check
     
    931931
    932932  def SS = grobj(S, c, dc);
    933  
     933
    934934  ASSUME(0, size( grrange(SS) ) == (size(a) + size(b)) );
    935935  ASSUME(0, size( grdeg(SS) ) == (size(da) + size(db)) );
    936936  ASSUME(0, ncols( SS ) == size( grdeg(SS) ) );
    937937  ASSUME(0, nrows( SS ) == size( grrange(SS) ) );
    938  
     938
    939939  return(SS);
    940940}
     
    984984{
    985985  ASSUME(1, grtest(M) );
    986            
    987            
     986
     987
    988988
    989989  intvec a = grrange(M);
     
    993993  {
    994994    "!! Warning: shifting '0 <- 0' leaves it as it unchanged!";
    995     return (M);   
    996   }
    997  
     995    return (M);
     996  }
     997
    998998  a = a - intvec(d:size(a));
    999999  t = t - intvec(d:size(t));
     
    10561056{
    10571057  ASSUME(0, size(w) >= nrows(A) );
    1058  
     1058
    10591059  module M = module(A);
    10601060
     
    10631063
    10641064  intvec @ww = 0:0;
    1065  
     1065
    10661066  if( size(#) > 0 )
    10671067  {
    10681068    ASSUME(0, typeof(#[1]) == "intvec" );
    1069    
     1069
    10701070    @ww = intvec( #[1] );
    10711071
     
    10771077      }
    10781078    }
    1079    
     1079
    10801080    ASSUME(0, size(@ww) == ncols(M) );
    10811081  }
     
    10911091        M = freemodule(0);
    10921092      }
    1093      
     1093
    10941094      attrib( M, "rank", size(w) );
    10951095      attrib( M, "isHomog", w );
    1096      
     1096
    10971097//      ASSUME(0, /* PROBLEM WITH ZERO COLUMNS / THEIR DEGREES! */ (ncols(M) == 0) );
    10981098    }
    10991099  }
    1100  
     1100
    11011101//  type(@ww);  type(M);
    1102  
     1102
    11031103  ASSUME(0, size(@ww) == ncols(M) ); // ?!
    1104  
     1104
    11051105  attrib(M, "degHomog", @ww);
    11061106
     
    11321132  grview( grobj( freemodule(0), intvec(1,2,3) ) );
    11331133
    1134   matrix z1[0][3]; grview( grobj( z1, 0:0, intvec(1,2,3) ) ); 
     1134  matrix z1[0][3]; grview( grobj( z1, 0:0, intvec(1,2,3) ) );
    11351135  grview( grobj( freemodule(0), 0:0, intvec(1,2,3) ) );
    11361136
    11371137  matrix z0[0][0]; grview( grobj( z0, 0:0 ) );
    11381138  grview( grobj( freemodule(0), 0:0 ) );
    1139  
    1140  
     1139
     1140
    11411141
    11421142}
     
    11451145"USAGE:  grtest(M[,b]), anyting M, optionally int b
    11461146RETURN:  1 if M is a valid graded object, 0 otherwise
    1147 PURPOSE: validate a graded object. Print an invalid object message if b is not given 
     1147PURPOSE: validate a graded object. Print an invalid object message if b is not given
    11481148NOTE: M should be an ideal or module or matrix, with weighting attribute
    11491149   'isHomog' and optionally total graded degrees attribute 'degHomog'.
     
    11691169  if ( nrows(N) != size(gr) )
    11701170  {
    1171     if(b) { "   ? grtest: Input has wrong number of rows!"; };   
     1171    if(b) { "   ? grtest: Input has wrong number of rows!"; };
    11721172    return (0);
    11731173  };
     
    11771177    return(1);
    11781178  }
    1179  
     1179
    11801180//  if( attrib(N, "rank") != size(gr) ){ return (0); } // wrong rank :(
    11811181
     
    11891189      return (1);
    11901190    }
    1191    
     1191
    11921192    if ( ncols(N) != size(T) )
    11931193    {
    1194       if(b) { "   ? grtest: Input has wrong number of cols!"; };   
     1194      if(b) { "   ? grtest: Input has wrong number of cols!"; };
    11951195      return (0);
    11961196    };
    1197    
     1197
    11981198    int k = nvars(basering) + 1; // index of mod. column in the leadexp
    11991199
     
    12591259{
    12601260  ASSUME(0, d >= 0 );
    1261  
     1261
    12621262  if( d == 0 ) { return (A); }
    1263  
     1263
    12641264  if( ncols(A) == 0 )
    12651265  {
    12661266    matrix B[nrows(A) + d][0];
    1267     return (B);   
    1268   }
    1269  
     1267    return (B);
     1268  }
     1269
    12701270  module T; T[d] = 0;
    12711271  T = T, module(transpose(A));
     
    12811281  matrix m[0][2];
    12821282  type( align(m, 3) );
    1283 } 
     1283}
    12841284
    12851285
     
    13021302  module A = grobj( module([x+y, x, 0, 0], [0, x+y, y, 0]), intvec(0,0,0,1) );
    13031303  grview(A);
    1304  
     1304
    13051305  module B = grgroebner(A);
    13061306  grview(B);
     
    13241324  ring r=32003,(x,y,z),dp;
    13251325
    1326   module A = grgroebner( grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) ) ); 
     1326  module A = grgroebner( grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) ) );
    13271327  grview(A);
    1328  
     1328
    13291329  grview(grsyz(A));
    1330  
    1331   module X = grgroebner( grobj( module([x]), intvec(2) ) ); 
     1330
     1331  module X = grgroebner( grobj( module([x]), intvec(2) ) );
    13321332  grview(X);
    13331333
    13341334  // syzygy module should be zero!
    13351335  grview(grsyz(X));
    1336  
    1337  
     1336
     1337
    13381338}
    13391339
     
    13511351  intvec a = grdeg(A);
    13521352  intvec b = grrange(B);
    1353  
     1353
    13541354  ASSUME(0, (size(a) == size(b)) && (a == b));  // == for intvec :(
    13551355
     
    13611361  ring r=32003,(x,y,z),dp;
    13621362
    1363   module A = grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) ); 
     1363  module A = grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) );
    13641364  grview(A);
    1365  
     1365
    13661366  A = grgroebner(A);
    13671367  grview(A);
    1368  
     1368
    13691369  module B = grsyz(A);
    13701370  grview(B);
    13711371  print(B);
    1372  
     1372
    13731373  module D = grprod( A, B );
    13741374  grview(D);
     
    13841384"USAGE:  grres(M, l[, b]), graded object M, int l, int b
    13851385RETURN:  graded resolution = list of graded objects
    1386 PURPOSE: compute graded resolution of M (of length l) and minimise it if b was given                             
     1386PURPOSE: compute graded resolution of M (of length l) and minimise it if b was given
    13871387EXAMPLE: example grres; shows an example
    13881388"
     
    13921392
    13931393  intvec v = grrange(A);
    1394  
     1394
    13951395  int b = (size(#) > 0);
    13961396  if(b) { list r = res(A, l, #[1]); } else { list r = res(A, l); }
    13971397
    13981398  l = size(r);
    1399  
     1399
    14001400  int i;
    1401  
     1401
    14021402  for ( i = 1; i <= l; i++ )
    14031403  {
     
    14111411    r[i] = grobj(r[i], v); v = grdeg(r[i]);
    14121412  }
    1413  
     1413
    14141414  i = i-1;
    14151415
     
    14211421  ring r=32003,(x,y,z),dp;
    14221422
    1423   module A = grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) ); 
     1423  module A = grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) );
    14241424  grview(A);
    1425  
     1425
    14261426  module B = grgroebner(A);
    14271427  grview(B);
     
    14381438RETURN:  graded object
    14391439PURPOSE: graded transpose of M
    1440 NOTE:    no reordering is performend by this procedure   
     1440NOTE:    no reordering is performend by this procedure
    14411441EXAMPLE: example grtranspose; shows an example
    14421442"
     
    14571457
    14581458  module K = grsyz( L ); grview(K);
    1459  
     1459
    14601460
    14611461  // Corner cases: 0 <- 0!
     
    14631463  grview( grtranspose( Z ) );
    14641464
    1465  
     1465
    14661466  // Corner cases: * <- 0
    14671467  matrix M1[3][0];
    1468  
     1468
    14691469  module Z1 = grobj( M1, intvec(-1, 0, 1) ); grview(Z1);
    14701470  grview( grtranspose( Z1 ) );
    1471  
    1472  
     1471
     1472
    14731473  // Corner cases: 0 <- *
    14741474  matrix M2[0][3];
     
    14761476  module Z2 = grobj( M2, 0:0, intvec(-1, 0, 1) ); grview(Z2);
    14771477  grview( grtranspose( Z2 ) );
    1478  
     1478
    14791479}
    14801480
     
    14821482proc grgens(def M)
    14831483"USAGE:   grgens(M), graded object M (map)
    1484 RETURN:  graded object 
     1484RETURN:  graded object
    14851485PURPOSE: try compute graded generators of coker(M) and return them as columns
    14861486         of a graded map.
     
    14921492
    14931493  module N = grtranspose( grsyz( grtranspose(M) ) );
    1494  
     1494
    14951495//  ASSUME(3, grisequal( grgroebner(M), grgroebner( grpres( N ) ) ) ); // FIXME: not always true!?
    1496  
     1496
    14971497  return ( N );
    14981498}
     
    15051505
    15061506  module N = grgens(M);
    1507  
     1507
    15081508  grview( N ); print(N); // fine == M
    15091509
    15101510
    1511   module A = grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) ); 
     1511  module A = grobj( module([x+y, x, 0, 3], [0, x+y, y, 2], [y, y, z, 1]), intvec(0,0,0,1) );
    15121512
    15131513  A = grgroebner(A); grview(A);
     
    15181518
    15191519  grview( grgens( grzero() ) );
    1520  
     1520
    15211521}
    15221522
     
    15341534
    15351535//  ASSUME(3, grisequal( M, grgens( N ) ) );
    1536  
     1536
    15371537  return ( N );
    15381538}
     
    15451545  grview(A);
    15461546
    1547   "graded transpose: "; def B = grtranspose(A); grview( B ); print(B); 
     1547  "graded transpose: "; def B = grtranspose(A); grview( B ); print(B);
    15481548
    15491549  "... syzygy: "; def C = grsyz(B); grview(C);
     
    15531553  "... and back to presentation: "; def E = grsyz( D ); grview(E); print(E);
    15541554
    1555   def F = grgens( E ); grview(F); print(F); 
     1555  def F = grgens( E ); grview(F); print(F);
    15561556  def G = grpres( F ); grview(G); print(G);
    15571557
    15581558
    15591559  def M = grtwists( intvec(-2, 0, 4, 4) ); grview(M);
    1560  
     1560
    15611561  def N = grgens(M); grview( N ); print(N);
    1562  
    1563   def L = grpres( N ); grview( L ); print(L); 
     1562
     1563  def L = grpres( N ); grview( L ); print(L);
    15641564}
    15651565
     
    16521652  module N;
    16531653
    1654   if(i>n) 
     1654  if(i>n)
    16551655    { // no middle part
    16561656      if(a[1]>0)
     
    16591659
    16601660          if(a[n+1]>0)
    1661             { N=grsum(N,grtwist(a[n+1],-1));}       
    1662         } 
     1661            { N=grsum(N,grtwist(a[n+1],-1));}
     1662        }
    16631663      else
    16641664        { N=grtwist(a[n+1],-1);}
    1665      
    1666       return (N); // grorder(N)); 
     1665
     1666      return (N); // grorder(N));
    16671667    }
    1668   else // i <= n: middle part is present, a_i != 0 
     1668  else // i <= n: middle part is present, a_i != 0
    16691669    { // a = a1  ... |  i:2, a_2 ..... i: n, a_n | .... i: n+1a_(n+1)
    16701670      j = i - 1;
     
    16971697
    16981698
    1699       return ((N)); //      return (grorder(N)); 
     1699      return ((N)); //      return (grorder(N));
    17001700    }
    17011701}
     
    17041704  ring r = 32003,(x(0..4)),dp;
    17051705
    1706   def N1 = KeneshlouMatrixPresentation(intvec(2,0,0,0,0)); 
     1706  def N1 = KeneshlouMatrixPresentation(intvec(2,0,0,0,0));
    17071707  grview(N1);
    17081708
     
    17381738  ASSUME(1, grtest(B));
    17391739  ASSUME(0, grrange(A)==grrange(B));
    1740  
     1740
    17411741  intvec v = grrange(A);
    17421742  intvec w=grdeg(A),grdeg(B);
     
    17461746{ "EXAMPLE:"; echo = 2;
    17471747  ring r;
    1748  
     1748
    17491749  module R=grobj(module([x,y,z]),intvec(0:3));
    17501750  grview(R);
     
    17711771//  matrix U;
    17721772  matrix L =lift(A,B/*,U*/);  //  module(B*U) = module(matrix(A)*L)
    1773  
     1773
    17741774  return(grobj(L, grdeg(A), grdeg(B)));
    17751775}
     
    17821782
    17831783
    1784   module D=grobj(module([y,0,z],[x2+y2,z,0]),intvec(0,1,0)); 
     1784  module D=grobj(module([y,0,z],[x2+y2,z,0]),intvec(0,1,0));
    17851785  grview(D);
    17861786
     
    17881788  grview(G);
    17891789
    1790   ASSUME(0, grisequal( grprod(D, G), P) ); 
     1790  ASSUME(0, grisequal( grprod(D, G), P) );
    17911791}
    17921792
     
    18071807
    18081808  module Z = grobj(freemodule(0),intvec(0:0),intvec(0:0));
    1809  
     1809
    18101810  grrange(Z);
    18111811  grdeg(Z);
    1812  
     1812
    18131813  grview(Z);
    18141814
     
    18381838       grtranspose( grprod( N,  alpha1 ) ) )
    18391839       ) ); // alpha0!
    1840    
     1840
    18411841}
    18421842example
     
    18991899
    19001900  ASSUME(0, t >= 2);
    1901  
     1901
    19021902  list P;
    19031903
    19041904  "t: ", t;
    1905  
     1905
    19061906  P[1]= grrndmap( rM[1], rN[1] ); // alpha1
    19071907
    1908   if(t==2){return(P[1]);} 
    1909    
     1908  if(t==2){return(P[1]);}
     1909
    19101910  for(k=2; k<=t; k++)
    19111911  {
    1912     P[k] = grlift( grprod(P[k-1],rM[k]), rN[k] ); 
    1913      grview(P[k]); 
    1914    
    1915   }
    1916      
     1912    P[k] = grlift( grprod(P[k-1],rM[k]), rN[k] );
     1913     grview(P[k]);
     1914
     1915  }
     1916
    19171917  return(P);
    1918    
     1918
    19191919}
    19201920example
     
    19231923  ring r=32003,(x,y,z),dp;
    19241924
    1925   module P=grobj(module([xy,0,xz]),intvec(0,1,0)); 
     1925  module P=grobj(module([xy,0,xz]),intvec(0,1,0));
    19261926  grview(P);
    19271927
    1928   module D=grobj(module([y,0,z],[x2+y2,z,0]),intvec(0,1,0)); 
     1928  module D=grobj(module([y,0,z],[x2+y2,z,0]),intvec(0,1,0));
    19291929  grview(D);
    19301930
     
    19371937  module D=grobj(module([y,0,z],[x2+y2,z,0], [z3, xy, xy2]),intvec(0,1,0));
    19381938  D = grgroebner(D);
    1939   grview( grres(D, 0)); 
     1939  grview( grres(D, 0));
    19401940
    19411941  def G=grlifting(D, D);
     
    19511951  def M = KeneshlouMatrixPresentation(intvec(0,0,1,0));
    19521952  grview( grres(M, 0) );
    1953  
     1953
    19541954//   module N = grshift(kos[3], 1); // psi, Syz_2(K(1))
    19551955  def N = KeneshlouMatrixPresentation(intvec(0,1,0,0));
     
    19661966proc mappingcone(M,N)
    19671967"USAGE: mappingcone(M,N), M,N graded objects
    1968 RETURN: chain complex (as a list) 
     1968RETURN: chain complex (as a list)
    19691969PURPOSE: construct a free resolution of the cokernel of a random map between Img(M), and Img(N).
    19701970EXAMPLE: example mappingcone; shows an example
     
    20262026
    20272027// correct
    2028 proc grrndmap(def S, def D, list #) 
     2028proc grrndmap(def S, def D, list #)
    20292029"USAGE: grrndmap(S,D), graded objects S and D
    20302030RETURN: graded object
     
    20922092// 0<---M<----F0<----F1<----F2<----F3<----
    20932093//              |p1   |p2
    2094 // 
     2094//
    20952095// 0<---N<----G0<----G1<----G2<----G3<----
    20962096//                B(g1)      g2     g3
    2097 // 
     2097//
    20982098proc grlifting2(A,B)
    20992099"USAGE: grlifting2(A,B), graded objects A and B (matrices defining maps)
    2100 RETURN: map of chain complexes (as a list) 
     2100RETURN: map of chain complexes (as a list)
    21012101PURPOSE: construct a map of chain complexes between free resolution of
    21022102M=coker(A) and N=coker(B).
     
    21272127  P[1]=grrndmap2(A,B);
    21282128
    2129   // A(or B)=0 
     2129  // A(or B)=0
    21302130  if(t==1){return(P[1])};
    2131  
     2131
    21322132  for(k=2;k<=t;k++)
    21332133  {
     
    21612161def T=grlifting2(DD,PP); T;
    21622162
    2163 // def Z=grlifting2(P,D); Z; // WRONG!!! 
    2164              
     2163// def Z=grlifting2(P,D); Z; // WRONG!!!
     2164
    21652165}
    21662166
     
    21712171proc mappingcone2(A,B)
    21722172"USAGE: mappingcone2(A,B), graded objects A and B (matrices defining maps)
    2173 RETURN: chain complex (as a list) 
     2173RETURN: chain complex (as a list)
    21742174PURPOSE: construct the free resolution of a cokernel of a random map between M=coker(A), and N=coker(B)
    21752175EXAMPLE: example mappingcone2;
     
    22342234*/
    22352235
    2236 proc grlifting3(A,B) 
     2236proc grlifting3(A,B)
    22372237"TODO: grlifting4 was newer and had more documentation than this proc, but was removed... Please verify and update!
    22382238"
     
    22472247  list rN = grres(B,0,1);
    22482248  print( betti(rN), "betti");
    2249  
     2249
    22502250  int i,j,k;
    22512251
     
    22602260  }
    22612261  int t=min(i,j);
    2262  
     2262
    22632263  list P;
    22642264
    22652265  "t: ", t;
    22662266//  grview(rM[t]);  grview(rN[t]);
    2267  
     2267
    22682268  P[t]= grrndmap2(rM[t],rN[t]);
    22692269  grview(P[t]);
     
    23122312//def I=KeneshlouMatrixPresentation(intvec(2,3,0,6,2));
    23132313//def J=KeneshlouMatrixPresentation(intvec(4,0,1,2,1));
    2314 //def N=grlifting3(I,J); grview(N); 
     2314//def N=grlifting3(I,J); grview(N);
    23152315}
    23162316
     
    23182318"USAGE: grneg(A), graded object A
    23192319RETURN: graded object
    2320 PURPOSE: graded map defined by -A 
     2320PURPOSE: graded map defined by -A
    23212321EXAMPLE: example grneg; shows an example
    23222322"
     
    23412341proc mappingcone3(A,B)
    23422342"USAGE: mappingcone3(A,B), graded objects A and B (matrices defining maps)
    2343 RETURN: chain complex (as a list) 
     2343RETURN: chain complex (as a list)
    23442344PURPOSE: construct a free resolution of the cokernel of a random map between M=coker(A), and N=coker(B)
    23452345EXAMPLE: example mappingcone3; shows an example
     
    23762376
    23772377    T[i]=grtranspose(D);
    2378    
     2378
    23792379    kill A, B, C, D, v, w, r, s, zero;
    23802380  }
     
    23942394def F=grlifting3(A,T); grview(F);
    23952395
    2396 // BUG in the proc 
     2396// BUG in the proc
    23972397def G=mappingcone3(A,T); grview(G);
    23982398
     
    24032403ideal P=groebner(flatten(U[2]));
    24042404resolution L=mres(P,0);
    2405 print(betti(L),"betti");   
     2405print(betti(L),"betti");
    24062406*/
    24072407
     
    24212421def I=KeneshlouMatrixPresentation(intvec(2,3,0,6,2));
    24222422def J=KeneshlouMatrixPresentation(intvec(4,0,1,2,1));
    2423 // def N=grlifting3(I,J); 
     2423// def N=grlifting3(I,J);
    24242424// 2nd module does not lie in the first:
    24252425// def NN=mappingcone3(I,J); // ????????
     
    24582458  module N;
    24592459
    2460   if(i>n) 
     2460  if(i>n)
    24612461    { // no middle part
    24622462      if(a[1]>0)
     
    24652465
    24662466          if(a[n+1]>0)
    2467             { N=grsum(N,grtwist(a[n+1],0));}         
    2468         } 
     2467            { N=grsum(N,grtwist(a[n+1],0));}
     2468        }
    24692469      else
    24702470        { N=grtwist(a[n+1],0);}
    2471      
    2472       return (N); // grorder(N)); 
     2471
     2472      return (N); // grorder(N));
    24732473    }
    24742474
    2475 else // i <= n: middle part is present, a_i != 0 
     2475else // i <= n: middle part is present, a_i != 0
    24762476    { // a = a1  ... |  i:2, a_2 ..... i: n, a_n | .... i: n+1a_(n+1)
    24772477      module I = maxideal(1);
     
    25052505
    25062506
    2507       return ((N)); //      return (grorder(N)); 
     2507      return ((N)); //      return (grorder(N));
    25082508    }
    25092509}
     
    25182518grview(S);
    25192519
    2520 def N1 = matrixpres(intvec(2,0,0,0,0)); 
     2520def N1 = matrixpres(intvec(2,0,0,0,0));
    25212521grview(N1);
    25222522
  • Singular/LIB/grobcov.lib

    r8d7ca0 r654a23  
    11//
    2 version="version grobcov.lib 4.0.1.2 Jan_2015 "; // $Id$
     2version="version grobcov.lib 4.0.2.0 Jul_2015 "; // $Id$
     3           // version L;  July_2015;
    34category="General purpose";
    45info="
     
    5455            Groebner Cover, and new theoretical developments have been done.
    5556
     57            The actual version also includes a routine (ConsLevels)
     58            for computing the canonical form of a constructible set, given as a
     59            union of locally closed sets. It is used in the new version for the
     60            computation of loci and envelops. It determines the canonical locally closed
     61            level sets of a constructuble. They will be described in a forthcoming paper:
     62
     63             J.M. Brunat, A. Montes,
     64            \"Computing the canonical representation of constructible sets\".
     65            Submited to Mathematics in Computer Science. July 2015.
     66
    5667            A new set of routines (locus, locusdg, locusto) has been included to
    5768            compute loci of points. The routines are used in the Dynamic
     
    6980             \''Envelops in Dynamic Geometry using the Groebner cover\''.
    7081
    71             The actual version also includes two routines (AddCons and AddconsP)
    72             for computing the canonical form of a constructible set, given as a
    73             union of locally closed sets. They are used in the new version for the
    74             computation of loci and envelops. It determines the canonical locally closed
    75             level sets of a constructuble. They will be described in a forthcoming paper:
    76 
    77             A. Montes, J.M. Brunat,
    78             \"Canonical representations of constructible sets\".
    79 
    80             This version was finished on 31/01/2015
     82
     83            This version was finished on 31/07/2015
    8184
    8285NOTATIONS: All given and determined polynomials and ideals are in the
     
    8588@*         grobcov, cgsdr,
    8689@*         generate the global rings
    87 @*         Grobcov::@R   (Q[a][x]),
    88 @*         Grobcov::@P   (Q[a]),
    89 @*         Grobcov::@RP  (Q[x,a])
     90@*         @R   (Q[a][x]),
     91@*         @P   (Q[a]),
     92@*         @RP  (Q[x,a])
    9093@*         that are used inside and killed before the output.
    91 @*         If you want to use some internal routine you must
    92 @*         create before the above rings by calling setglobalrings();
    93 @*         because some of the internal routines use these rings.
    94 @*         The call to the basic routines grobcov, cgsdr will
    95 @*         kill these rings.
    9694
    9795PROCEDURES:
     
    109107             (the own routine of 2010 that is no more used).
    110108             Now, KSW algorithm is used.
    111 
    112 setglobalrings();  Generates the global rings @R, @P and @PR that
    113               are respectively the rings Q[a][x], Q[a], Q[x,a].  (a=parameters,
    114              x=variables) It is called inside each of the fundamental
    115              routines of the library: grobcov, cgsdr, locus, locusdg and
    116              killed before the output.
    117109
    118110pdivi(f,F); Performs a pseudodivision of a parametric polynomial
     
    138130             the bases are computed, and one can obtain the full
    139131             representation using extend.
     132
     133ConsLevels(L); Given a list L of locally closed sets, it returns the canonical levels
     134             of the constructible set of the union of them, as well as the levels
     135             of the complement. It is described in the paper
     136
     137             J.M. Brunat, A. Montes,
     138            \"Computing the canonical representation of constructible sets\".
     139            Submited to Mathematics in Computer Science. July 2015.
    140140
    141141locus(G);    Special routine for determining the geometrical locus of points
     
    178178             \''Envelops in Dynamic Geometry using the Gr\"obner cover\''.
    179179
    180 
    181180envelopdg(ev); Is a special routine to determine the 'Relevant' components
    182181             of the envelop of a family of curves to be used in Dynamic Geometry.
    183182             It must be called to the output of envelop(F,C).
    184183
    185 locusto(L); Transforms the output of locus, locusdg, envelop and  envelopdg
     184locusto(L); Transforms the output of locus, locusdg, envelop and envelopdg
    186185             into a string that can be reed from different computational systems.
    187186
    188 AddCons(L); Uses the routine AddConsP. Given a set of locally closed sets as
    189              difference of of varieties (does not need to be in C-representation)
    190              it returns the canonical P-representation of the constructible set
    191              formed by the union of them. The result is formed by a set of embedded,
    192              disjoint, locally closed sets (levels).
    193 
    194 AddConsP(L);  Given a set of locally closed P-components, it returns the
    195              canonical P-representation of the constructible set
    196              formed by the union of them, consisting of a set of embedded,
    197              disjoint locally closed sets (levels).
    198              The routines AddCons and AddConsP and the canonical structure
    199              of the constructible sets will be described in a forthcoming paper.
    200 
    201              A. Montes, J.M. Brunat,
    202              \"Canonical representations of constructible sets\".
    203187
    204188SEE ALSO: compregb_lib
     
    228212// Uses KSW algorithm for cgsdr
    229213// Final data: 21-11-2013
    230 // Release K: (public)
    231 // Updated locus: 8-1-2015
    232 // Updated AddConsP and AddCons: 8-1-2015
    233 // Reformed many routines, examples and helps: 8-1-2015
     214// Release L: (public)
     215// New routine ConsLevels: 10-7-2015
     216// Updated locus: 10-7-2015 (uses Conslevels)
    234217// New routines for computing the envelop of a family of curves: 22-1-2015
    235 // Final data: 22-1-2015
     218// Final data: 22-7-2015
    236219
    237220//*************Auxiliary routines**************
     
    297280  if (size(l)==1 and i==1){return(L);}
    298281  // L=l[1];
    299   if(i==1)
    300   {
    301     for(j=2;j<=size(l);j++)
    302     {
    303       L[j-1]=l[j];
    304     }
    305   }
    306   else
     282  if(i>1)
    307283  {
    308284    for(j=1;j<=i-1;j++)
    309285    {
    310       L[j]=l[j];
    311     }
    312     for(j=i+1;j<=size(l);j++)
    313     {
    314       L[j-1]=l[j];
    315     }
     286      L[size(L)+1]=l[j];
     287    }
     288  }
     289  for(j=i+1;j<=size(l);j++)
     290  {
     291    L[size(L)+1]=l[j];
    316292  }
    317293  return(L);
     
    773749//}
    774750
    775 proc setglobalrings()
    776 "USAGE:   setglobalrings();
    777           No arguments
    778 RETURN:   After its call the rings @R=Q[a][x], @P=Q[a], @RP=Q[x,a] are
    779           defined as global variables.  (a=parameters, x=variables)
    780 NOTE: It is called internally by many basic routines of the
    781           library grobcov, cgsdr, extend, pdivi, pnormalf, locus, locusdg,
    782           envelop, envelopdg, and killed before the output.
    783           The user does not need to call it, except when it is interested
    784           in using some internal routine of the library that
    785           uses these rings.
    786           The basering R, must be of the form Q[a][x], (a=parameters,
    787           x=variables), and should be defined previously.
    788 KEYWORDS: ring, rings
    789 EXAMPLE:  setglobalrings; shows an example"
     751static proc setglobalrings()
     752// "USAGE:   setglobalrings();
     753//           No arguments
     754// RETURN: After its call the rings Grobcov::@R=Q[a][x], Grobcov::@P=Q[a],
     755//           Grobcov::@RP=Q[x,a] are defined as global variables.
     756//           (a=parameters, x=variables)
     757// NOTE: It is called internally by many basic routines of the
     758//           library grobcov, cgsdr, extend, pdivi, pnormalf, locus, locusdg,
     759//           envelop, envelopdg, and killed before the output.
     760//           The user does not need to call it, except when it is interested
     761//           in using some internal routine of the library that
     762//           uses these rings.
     763//           The basering R, must be of the form Q[a][x], (a=parameters,
     764//           x=variables), and should be defined previously.
     765// KEYWORDS: ring, rings
     766// EXAMPLE:  setglobalrings; shows an example"
    790767{
    791768  if (defined(@P))
     
    810787  setring(RR);
    811788};
    812 example
    813 {
    814   "EXAMPLE:"; echo = 2;
    815   ring R=(0,a,b),(x,y,z),dp;
    816   setglobalrings();
    817   R;
    818   Grobcov::@R;
    819   Grobcov::@P;
    820   Grobcov::@RP;
    821   ringlist(Grobcov::@R);
    822   ringlist(Grobcov::@P);
    823   ringlist(Grobcov::@RP);
    824 }
     789// example
     790// {
     791//   "EXAMPLE:"; echo = 2;
     792//   ring R=(0,a,b),(x,y,z),dp;
     793//   setglobalrings();
     794//   " ";"R=";R;
     795//   " ";"Grobcov::@R=";Grobcov::@R;
     796//   " ";"Grobcov::@P=";Grobcov::@P;
     797//   " ";"Grobcov::@RP=";Grobcov::@RP;
     798//  " "; "ringlist(Grobcov::@R)=";  ringlist(Grobcov::@R);
     799//  " "; "ringlist(Grobcov::@P)=";  ringlist(Grobcov::@P);
     800//  " "; "ringlist(Grobcov::@RP)=";  ringlist(Grobcov::@RP);
     801// }
    825802
    826803// cld : clears denominators of an ideal and normalizes to content 1
     
    15151492    }
    15161493  }
     1494  //"T_abans="; prep;
    15171495  if (size(prep)==0){prep=list(list(ideal(1),list(ideal(1))));}
     1496  //"T_Prep="; prep;
     1497  //def Lout=CompleteA(prep,prep);
     1498  //"T_Lout="; Lout;
    15181499  return(prep);
    15191500}
     
    39343915
    39353916//********************* End KapurSunWang *************************
     3917
     3918//********************* Begin ConsLevels ***************************
     3919
     3920static proc zeroone(int n)
     3921{
     3922  list L; list L2;
     3923  intvec e; intvec e2; intvec e3;
     3924  int j;
     3925  if(n==1)
     3926  {
     3927    e[1]=0;
     3928    L[1]=e;
     3929    e[1]=1;
     3930    L[2]=e;
     3931    return(L);
     3932  }
     3933  if(n>1)
     3934  {
     3935    L=zeroone(n-1);
     3936    for(j=1;j<=size(L);j++)
     3937    {
     3938      e2=L[j];
     3939      e3=e2;
     3940      e3[size(e3)+1]=0;
     3941      L2[size(L2)+1]=e3;
     3942      e3=e2;
     3943      e3[size(e3)+1]=1;
     3944      L2[size(L2)+1]=e3;
     3945    }
     3946  }
     3947  return(L2);
     3948}
     3949
     3950// Auxiliary routine
     3951// subsets: the list of subsets of (1,..n)
     3952static proc subsets(int n)
     3953{
     3954  list L; list L1;
     3955  int i; int j;
     3956  L=zeroone(n);
     3957  intvec e; intvec e1;
     3958  for(i=1;i<=size(L);i++)
     3959  {
     3960    e=L[i];
     3961    kill e1; intvec e1;
     3962    for(j=1;j<=n;j++)
     3963    {
     3964      if(e[n+1-j]==1)
     3965      {
     3966        if(e1==intvec(0)){e1[1]=j;}
     3967        else{e1[size(e1)+1]=j};
     3968      }
     3969    }
     3970    L1[i]=e1;
     3971  }
     3972  return(L1);
     3973}
     3974
     3975// Input a list A of locally closed sets in C-rep
     3976// Output a list B of a simplified list of A
     3977static proc SimplifyUnion(list A)
     3978{
     3979  int i; int j;
     3980  list L=A;
     3981  int n=size(L);
     3982  if(n<2){return(A);}
     3983  for(i=1;i<=size(L);i++)
     3984  {
     3985    for(j=1;j<=size(L);j++)
     3986    {
     3987      if(i != j)
     3988      {
     3989        if(equalideals(L[i][2],L[j][1])==1)
     3990        {
     3991          L[i][2]=L[j][2];
     3992        }
     3993      }
     3994    }
     3995  }
     3996  ideal T=ideal(1);
     3997  intvec v;
     3998  for(i=1;i<=size(L);i++)
     3999  {
     4000    if(equalideals(L[i][2],ideal(1)))
     4001    {
     4002      v[size(v)+1]=i;
     4003      T=intersect(T,L[i][1]);
     4004    }
     4005  }
     4006  if(size(v)>0)
     4007  {
     4008    for(i=1; i<=size(v);i++)
     4009    {
     4010      j=v[size(v)+1-i];
     4011      L=elimfromlist(L, j);
     4012    }
     4013  }
     4014  if(equalideals(T,ideal(1))==0){L[size(L)+1]=list(std(T),ideal(1))};
     4015  //string("T_n=",n," new n0",size(L));
     4016  return(L);
     4017}
     4018
     4019// Input: list(A)
     4020//          A is a list of locally closed sets in Crep. A=[[P1,Q1],[P2,Q2],..,[Pr,Qr]]
     4021//          whose union is a constructible set from
     4022// Output list [Lev,C]:
     4023//          where Lev is the Crep of the canonical first level of A, and
     4024//          C is the complement of the first level Lev wrt to the closure of A. The elements are given in Crep,
     4025static proc FirstLevel(list A)
     4026{
     4027  int n=size(A);
     4028  list T=zeroone(n);
     4029  ideal P; ideal Q;
     4030  list Cb;  ideal Cc=ideal(1);
     4031  int i; int j;
     4032  intvec t;
     4033  ideal Z=ideal(1);
     4034  list C;
     4035  for(i=1;i<=size(A);i++)
     4036  {
     4037    Z=intersect(Z,A[i][1]);
     4038  }
     4039  for(i=2; i<=size(T);i++)
     4040  {
     4041    t=T[i];
     4042    P=ideal(1); Q=ideal(0);
     4043    for(j=1;j<=n;j++)
     4044    {
     4045      if(t[n+1-j]==1)
     4046      {
     4047        Q=Q+A[j][2];
     4048      }
     4049      else
     4050      {
     4051        P=intersect(P,A[j][1]);
     4052      }
     4053    }
     4054    //"T_Q="; Q; "T_P="; P;
     4055    Cb=Crep(Q,P);
     4056    //"T_Cb="; Cb;
     4057    if(Cb[1][1]<>1)
     4058    {
     4059      C[size(C)+1]=Cb;
     4060      Cc=intersect(Cc,Cb[1]);
     4061    }
     4062  }
     4063  list Lev=list(Z,Cc);                //Crep(Z,Cc);
     4064  if(size(C)>1){C=SimplifyUnion(C);}
     4065  return(list(Lev,C));
     4066}
     4067
     4068// Input: list(A)
     4069//          A is a list of locally closed sets in Crep. A=[[P1,Q1],[P2,Q2],..,[Pr,Qr]]
     4070//          whose union is a constructible set from which the algorithm computes its canonical form.
     4071// Output:
     4072//     list [L,C] where
     4073//          where L is the list of canonical levels of A,
     4074//          and C is the list of canonical levels of the complement of A wrt to the closure of A.
     4075//          All locally closed sets are given in Crep.
     4076//          L=[[1,[p1,p2],[3,[p3,p4],..,[2r-1,[p_{2r-1},p_2r]]]] is the list of levels of A in Crep.
     4077//          C=[[2,p2,p3],[4,[p4,p5],..,[2s,[p_{2s},p_{2s+1}]]]  is the list of levels of C,
     4078//                                              the complement of S wrt the closure of A, in Crep.
     4079proc ConsLevels(list A)
     4080"USAGE:   ConsLevels(A);
     4081          A is a list of locally closed sets in Crep. A=[[P1,Q1],[P2,Q2],..,[Pr,Qr]]
     4082          whose union is a constructible set from which the algorithm computes its
     4083          canonical form.
     4084RETURN: A list with two elements: [L,C]
     4085          where L is the list of canonical levels of A, and C is the list of canonical
     4086          levels of the
     4087          complement of A wrt to the closure of A.
     4088          All locally closed sets are given in Crep.
     4089          L=[[1,[p1,p2],[3,[p3,p4],..,[2r-1,[p_{2r-1},p_2r]]]]
     4090          C=[[2,p2,p3],[4,[p4,p5],..,[2s,[p_{2s},p_{2s+1}]]]
     4091NOTE: The basering R, must be of the form Q[a]
     4092KEYWORDS: locally closed set, constructible set
     4093EXAMPLE:  ConsLevels; shows an example"
     4094{
     4095  list L; list C; int i;
     4096  list B; list T;
     4097  for(i=1; i<=size(A);i++)
     4098  {
     4099    T=Crep(A[i][1],A[i][2]);
     4100    B[size(B)+1]=T;
     4101  }
     4102  int level=0;
     4103  list K;
     4104  while(size(B)>0)
     4105  {
     4106    level++;
     4107    K=FirstLevel(B);
     4108    if(level mod 2==1){L[size(L)+1]=list(level,K[1]);}
     4109    else{C[size(C)+1]=list(level,K[1]);}
     4110    //"T_L="; L;
     4111    //"T_C="; C;
     4112    B=K[2];
     4113    //"T_size(B)="; size(B);
     4114  }
     4115  return(list(L,C));
     4116}
     4117example
     4118{ "EXAMPLE:"; echo = 2;
     4119// Example of ConsLevels with nice geometrical interpretetion and 2 levels
     4120
     4121if (defined(R)){kill R;}
     4122if (defined(@P)){kill @P; kill @R; kill @RP;}
     4123
     4124  ring R=0,(x,y,z),lp;
     4125  short=0;
     4126  ideal P1=x*(x^2+y^2+z^2-1);
     4127  ideal Q1=z,x^2+y^2-1;
     4128  ideal P2=y,x^2+z^2-1;
     4129  ideal Q2=z*(z+1),y,x*(x+1);
     4130
     4131  list Cr1=Crep(P1,Q1);
     4132  list Cr2=Crep(P2,Q2);
     4133
     4134  list L=list(Cr1,Cr2);
     4135  L;
     4136  // ConsLevels(L)=
     4137  ConsLevels(L);
     4138
     4139//----------------------------------------------------------------------
     4140// Begin Problem S93
     4141// Automatic theorem proving
     4142// Generalized Steiner-Lehmus Theorem
     4143// A.Montes, T.Recio
     4144
     4145// Bisector of A(-1,0) = Bisector of B(1,0) varying C(a,b)
     4146
     4147if(defined(R1)){kill R1;}
     4148ring R1=(0,a,b),(x1,y1,x2,y2,p,r),dp;
     4149ideal S93=(a+1)^2+b^2-(p+1)^2,
     4150                    (a-1)^2+b^2-(1-r)^2,
     4151                    a*y1-b*x1-y1+b,
     4152                    a*y2-b*x2+y2-b,
     4153                    -2*y1+b*x1-(a+p)*y1+b,
     4154                    2*y2+b*x2-(a+r)*y2-b,
     4155                    (x1+1)^2+y1^2-(x2-1)^2-y2^2;
     4156
     4157short=0;
     4158def GC93=grobcov(S93,"nonnull",ideal(b),"rep",1);
     4159//"grobcov(S93,'nonnull',ideal(b),"rep",1)="; GC93;
     4160
     4161list L0;
     4162for(int i=1;i<=size(GC93);i++)
     4163{
     4164   L0[size(L0)+1]=GC93[i][3];
     4165}
     4166
     4167def GC93ab=grobcov(S93,"nonnull",ideal(a*b),"rep",1);
     4168
     4169ring RR=0,(a,b),lp;
     4170
     4171list L1;
     4172L1=imap(R1,L0);
     4173// L1=Total elements of the grobcov(S93,'nonnull',ideal(b),'rep',1) to be added=
     4174L1;
     4175
     4176// Adding all the elements of grobcov(S93,'nonnull',ideal(b),'rep',1)=
     4177ConsLevels(L1);
     4178}
     4179
     4180//**************************** End ConsLevels ******************
    39364181
    39374182//******************** Begin locus ******************************
     
    45224767  locus(grobcov(S));
    45234768  kill R;
    4524   "********************************************";
     4769  //********************************************
    45254770
    45264771  ring R=(0,x,y),(x1,x2),dp;
     
    46114856  locusdg(locus(grobcov(S96)));
    46124857  kill R;
    4613   "********************************************";
     4858  //********************************************
    46144859  ring R=(0,a,b),(x4,x3,x2,x1),dp;
    46154860  ideal S=(x1-3)^2+(x2-1)^2-9,
     
    46224867  locusdg(locus(grobcov(S)));
    46234868  kill R;
    4624   "********************************************";
     4869  //********************************************
    46254870
    46264871  ring R=(0,x,y),(x1,x2),dp;
     
    46334878}
    46344879
    4635 // locusto: Transforms the output of locus to a string that
    4636 //      can be read by different computational systems.
     4880// locusto: Transforms the output of locus, locusdg, envelop and envelopdg
     4881//             into a string that can be reed from different computational systems.
    46374882// input:
    46384883//     list L: The output of locus
     
    47174962  locusto(locusdg(locus(grobcov(S))));
    47184963  kill R;
    4719   "********************************************";
     4964  //********************************************
    47204965
    47214966  // 1. Take a fixed line l: x1-y1=0  and consider
     
    47374982  locusto(envelopdg(envelop(F,C)));
    47384983  kill R;
    4739   "********************************************";
     4984  //********************************************
    47404985
    47414986  // Steiner Deltoid
     
    48045049  return(d);
    48055050}
    4806 
    4807 // // locusdgto: Transforms the output of locusdg to a string that
    4808 // //      can be read by different computational systems.
    4809 // // input:
    4810 // //     list L: The output of locus
    4811 // // output:
    4812 // //     string s: The output of locus converted to a string readable by other programs
    4813 // //                   Outputs only the relevant dynamical geometry components.
    4814 // //                   Without unnecessary parenthesis
    4815 // proc locusdgto(list LL)
    4816 // "USAGE: locusdgto(L);
    4817 //           The argument must be the output of locusdg of a parametrical ideal
    4818 //           It transforms the output into a string in standard form
    4819 //           readable in many languages (Geogebra).
    4820 // RETURN: The locusdg in string standard form
    4821 // NOTE: It can only be called after computing the locusdg(grobcov(F)) of the
    4822 //           parametrical ideal.
    4823 //           The basering R, must be of the form Q[a,b,..][x,y,..].
    4824 // KEYWORDS: geometrical locus, locus, loci.
    4825 // EXAMPLE:  locusdgto; shows an example"
    4826 // {
    4827 //   int i; int j; int k; int short0=short; int ojo;
    4828 //   int te=0;
    4829 //   short=0;
    4830 //   if(size(LL)==0){ojo=1; list L;}
    4831 //   else
    4832 //   {
    4833 //     def L=LL;
    4834 //   }
    4835 //   string s="["; string sf="]"; string st=s+sf;
    4836 //   if(size(L)==0){return(st);}
    4837 //   ideal p;
    4838 //   ideal q;
    4839 //   for(i=1;i<=size(L);i++)
    4840 //   {
    4841 //     if(L[i][3]=="Relevant")
    4842 //     {
    4843 //       s=string(s,"[[");
    4844 //       for (j=1;j<=size(L[i][1]);j++)
    4845 //       {
    4846 //         s=string(s,L[i][1][j],",");
    4847 //       }
    4848 //       s[size(s)]="]";
    4849 //       s=string(s,",[");
    4850 //       for(j=1;j<=size(L[i][2]);j++)
    4851 //       {
    4852 //         s=string(s,"[");
    4853 //         for(k=1;k<=size(L[i][2][j]);k++)
    4854 //         {
    4855 //           s=string(s,L[i][2][j][k],",");
    4856 //         }
    4857 //         s[size(s)]="]";
    4858 //         s=string(s,",");
    4859 //       }
    4860 //       s[size(s)]="]";
    4861 //       s=string(s,"]");
    4862 //       s[size(s)]="]";
    4863 //       s=string(s,",");
    4864 //     }
    4865 //   }
    4866 //   if(s=="["){s="[]";}
    4867 //   else{s[size(s)]="]";}
    4868 //   short=short0;
    4869 //   return(s);
    4870 // }
    4871 // example
    4872 // {"EXAMPLE:"; echo = 2;
    4873 //   ring R=(0,a,b),(x,y),dp;
    4874 //   short=0;
    4875 //   ideal S96=x^2+y^2-4,(b-2)*x-a*y+2*a,(a-x)^2+(b-y)^2-1;
    4876 //   "System="; S96; " ";
    4877 //   "locusdgto(locusdg(grobcov(S96)))=";
    4878 //   locusdgto(locusdg(grobcov(S96)));
    4879 // }
    48805051
    48815052static proc norspec(ideal F)
     
    48985069  exportto(Top,@RP);     // global ring K[x,a] with product order
    48995070  setring(RR);
    4900 
    49015071}
    49025072
     
    50595229}
    50605230
    5061 //********************* End locus ****************************
    5062 
    5063 //********************* Begin AddCons **********************
    5064 
    5065 // Input: L1,L2: lists of components with common top
    5066 // Output L: list of the union of L1 and L2.
    5067 static proc Add2ComWithCommonTop(list L1, list L2)
    5068 {
    5069   int i; int j; ideal pij; list L; list Lp; list PR; int k;
    5070   for(i=1;i<=size(L1[2]);i++)
    5071   {
    5072     for(j=1;j<=size(L2[2]);j++)
    5073     {
    5074       pij=std(L1[2][i]+L2[2][j]);
    5075       PR=minGTZ(pij);
    5076       for(k=1;k<=size(PR);k++)
    5077       {
    5078         Lp[size(Lp)+1]=PR[k];
    5079       }
    5080     }
    5081   }
    5082   for(i=1; i<=size(Lp);i++)
    5083   {
    5084     for(j=i+1;j<=size(Lp);j++)
    5085     {
    5086       if(idcontains(Lp[i],Lp[j])) {Lp=delete(Lp,j);}
    5087     }
    5088     for(j=1;j<i;j++)
    5089     {
    5090       if(idcontains(Lp[i],Lp[j])){Lp=delete(Lp,j); j=j-1; i=i-1;}
    5091     }
    5092   }
    5093   L[1]=L1[1];
    5094   L[2]=Lp;
    5095   return(L);
    5096 }
    5097 
    5098 // Input: L list od P-rep of components to be added. L[i]=[p_i,[p_{i1},...p_{ir_i}]]
    5099 // Output: lists A,B,L
    5100 //       where no top in the lists are repeated
    5101 //       A: list of components with higher tops
    5102 //       B: list of components with lower tops
    5103 //       L1: A,B
    5104 static proc SepareAB(list L)
    5105 {
    5106   int i;  int j; list Ln=L;
    5107   for(i=1;i<=size(Ln);i++)
    5108   {
    5109     for(j=i+1;j<=size(Ln);j++)
    5110     {
    5111       if (equalideals(Ln[j][1],Ln[i][1]))
    5112       {
    5113         Ln[i]=Add2ComWithCommonTop(Ln[i],Ln[j]);
    5114         Ln=delete(Ln,j);
    5115         j=j-1;
    5116       }
    5117     }
    5118   }
    5119   list A; list B; int clas; list T; list L1;
    5120   for(i=1;i<=size(Ln);i++)
    5121   {
    5122     j=1;
    5123     clas=0;
    5124     while((clas==0) and  (j<=size(Ln)))
    5125     {
    5126       if(j!=i)
    5127       {
    5128         if(idcontains(Ln[i][1],Ln[j][1]) ) {B[size(B)+1]=Ln[i]; clas=1;}
    5129       }
    5130       j++;
    5131     }
    5132     if(clas==0) {A[size(A)+1]=Ln[i];}
    5133   }
    5134   L1=A; for(j=1;j<=size(B);j++){L1[size(L1)+1]=B[j];}
    5135   T[1]=A; T[2]=B; T[3]=L1;
    5136   return(T);
    5137 }
    5138 
    5139 // Input:
    5140 //  A1: list of high set of P-reps to be completed by the remaining P-reps
    5141 //  L1: the list A1, completed with the list of lower P-reps.
    5142 // Output:
    5143 //  A: list A1 completed with all possible parts of the remaining parts of L1 with the
    5144 //      condition of building locally closed sets.
    5145 static proc CompleteA(list A1,list L1)
    5146 {
    5147   int modif; int i; int j; int k; int l;
    5148   ideal pij; ideal pk; ideal pijkl; ideal pkl;
    5149   int n; list nl; int te; int clas; list vvv; list AAA;
    5150   list Lp; int m; ideal Pij;
    5151   list A0;
    5152   modif=1;
    5153   list A=A1;
    5154   while(modif==1)
    5155   {
    5156       modif=0;
    5157       A0=A;
    5158       for(i=1;i<=size(A);i++)
    5159       {
    5160           for(j=1;j<=size(A[i][2]); j++)
    5161           {
    5162               pij=A[i][2][j];
    5163              for(k=1;k<=size(L1);k++)
    5164              {
    5165                  if(k!=i)
    5166                  {
    5167                      pk=L1[k][1];
    5168                      if(idcontains(pij,pk)==1)
    5169                      {
    5170                          te=0;
    5171                          kill nl;
    5172                          list nl; l=1;
    5173                          while((te==0) and (l<=size(L1[k][2])))
    5174                          {
    5175                               pkl=L1[k][2][l];
    5176                               if((equalideals(pij,pkl)==1) or (idcontains(pij,pkl)==1)) {te=1;}
    5177                               l++;
    5178                          }   // end while ((te=0) and (l>...
    5179                          //"T_te="; te; pause();
    5180                          if(te==0)
    5181                          {
    5182                            modif=1;
    5183                            kill Pij; ideal Pij=1;
    5184                            for(l=1; l<=size(L1[k][2]);l++)
    5185                            {
    5186                              pkl=L1[k][2][l];
    5187                              pijkl=std(pij+pkl);
    5188                              Pij=intersect(Pij,pijkl);
    5189                            }
    5190                            kill Lp; list Lp;
    5191                            Lp=minGTZ(Pij);
    5192                            for(m=1;m<=size(Lp);m++)
    5193                             {
    5194                                nl[size(nl)+1]=Lp[m];
    5195                             }
    5196                             A[i][2]=delete(A[i][2], j);
    5197                             for(n=1;n<=size(nl);n++)
    5198                             {
    5199                               A[i][2][size(A[i][2])+1]=nl[n];
    5200                             }
    5201                           } // end if(te==0)
    5202                      } // end if(idcontains(pij,pk)==1)
    5203                  }  // end if (k!=i)
    5204              } // end for k
    5205          }  // end for j
    5206          kill vvv; list vvv;
    5207          if(modif==1)
    5208          // Select the maximal ideals of the set A[I][2][j]
    5209          {
    5210              kill nl; list nl;
    5211              nl=selectminideals(A[i][2]);
    5212              kill AAA; list AAA;
    5213              for(j=1;j<=size(nl);j++)
    5214              {
    5215                AAA[size(AAA)+1]=A[i][2][nl[j]];
    5216              }
    5217              A[i][2]=AAA;
    5218          } // end if(modif=1)
    5219       }  // end for i
    5220       modif=1-equallistsAall(A,A0);
    5221   } // end while(modif==1)
    5222   return(A);
    5223 }
    5224 
    5225 // Input:
    5226 //   A: list of the top P-reps of one level
    5227 //   B: list of remaining lower P-reps that have not yeen be possible to add
    5228 // Output:
    5229 //   Bn: list B where the elements that are completely included in A are removed and the parts that are
    5230 //         included in A also.
    5231 static proc ReduceB(list A,list B)
    5232 {
    5233      int i; int j; list nl; list Bn; int te; int k; int elim;
    5234      ideal pC; ideal pD; ideal pCD; ideal pBC; list nB; int j0;
    5235      for(i=1;i<=size(B);i++)
    5236      {
    5237          j=1; te=0;
    5238          while((te==0) and (j<=size(A)))
    5239          {
    5240              if(idcontains(B[i][1],A[j][1])){te=1; j0=j;}
    5241              else{j++;}
    5242          }
    5243          pD=B[i][2][1];
    5244          for(k=2;k<=size(B[i][2]);k++){pD=intersect(pD,B[i][2][k]);}
    5245          pC=A[j0][2][1];
    5246          for(k=2;k<=size(A[j0][2]);k++) {pC=intersect(pC,A[j0][2][k]);}
    5247          pCD=std(pD+pC);
    5248          pBC=std(B[i][1]+pC);
    5249          elim=0;
    5250          if(idcontains(pBC,pCD)){elim=1;}   // B=delfromlist(B,i);i=i-1;
    5251          else
    5252          {
    5253               nB=Prep(pBC,pCD);
    5254               if(equalideals(nB[1][1],ideal(1))==0)
    5255               {
    5256                   for(k=1;k<=size(nB);k++){Bn[size(Bn)+1]=nB[k];}
    5257               }
    5258          }
    5259     }   // end for i
    5260     return(Bn);
    5261 }
    5262 
    5263 // AddConsP: given a set of components of locally closed sets in P-representation, it builds the
    5264 //       canonical P-representation of the corresponding constructible set, of its union,
    5265 //       including levels it they are.
    5266 proc AddConsP(list L)
    5267 "USAGE:   AddConsP(L)
    5268       Input L: list of components in P-rep to be added
    5269       [  [[p_1,[p_11,..,p_1,r1]],..[p_k,[p_k1,..,p_kr_k]]  ]
    5270 RETURN:
    5271      list of lists of levels of the different locally closed sets of
    5272      the canonical P-rep of the constructible.
    5273      [  [level_1,[ [Comp_11,..Comp_1r_1] ] ], .. ,
    5274         [level_s,[ [Comp_s1,..Comp_sr_1] ]
    5275      ]
    5276      where level_i=i,   Comp_ij=[ p_i,[p_i1,..,p_it_i] ] is a prime component.
    5277 NOTE:     Operates in a ring R=Q[u_1,..,u_m]
    5278 KEYWORDS: Constructible set, Canoncial form
    5279 EXAMPLE:  AddConsP; shows an example"
    5280 {
    5281   list LL; list A; list B; list L1; list T; int level=0; list h;
    5282   LL=L; int i;
    5283   while(size(LL)!=0)
    5284   {
    5285     level++;
    5286     L1=SepareAB(LL);
    5287     A=L1[1]; B=L1[2]; LL=L1[3];
    5288     A=CompleteA(A,LL);
    5289     for(i=1;i<=size(A);i++)
    5290     {
    5291       LL[i]=A[i];
    5292     }
    5293     h[1]=level; h[2]=A;
    5294     T[size(T)+1]=h;
    5295     LL=ReduceB(A,B);
    5296   }
    5297   return(T);
    5298 }
    5299 example
    5300 {
    5301   "EXAMPLE:"; echo = 2;
    5302   if (defined(Grobcov::@P)){kill Grobcov::@P; kill Grobcov::@R; kill Grobcov::@RP;}
    5303   ring R=0,(x,y,z),lp;
    5304   short=0;
    5305 
    5306   ideal P1=x;
    5307   ideal Q1=x,y;
    5308   ideal P2=y;
    5309   ideal Q2=y,z;
    5310 
    5311   list L=list(Prep(P1,Q1)[1],Prep(P2,Q2)[1]);
    5312   L;
    5313   AddConsP(L);
    5314 }
    5315 
    5316 // AddCons:  given a set of  locally closed sets by pairs of ideal, it builds the
    5317 //       canonical P-representation of the corresponding constructible set, of its union,
    5318 //       including levels it they are.
    5319 //       It makes a call to AddConsP after transforming the input.
    5320 // Input list of lists of pairs of ideals representing locally colsed sets:
    5321 //     L=  [ [E1,N1], .. , [E_s,N_s] ]
    5322 // Output: The canonical frepresentation of the constructible set union of the V(E_i) \ V(N_i)
    5323 //     T=[  [level_1,[ [p_1,[p_11,..,p_1s_1]],.., [p_k,[p_k1,..,p_ks_k]] ]],, .. , [level_r,[..       ]]  ]
    5324 proc AddCons(list L)
    5325 "USAGE:   AddCons(L)
    5326       Calls internally AddConsP and allows a different input.
    5327       Input L: list of pairs of of ideals [ [P_1,Q_1], .., [Pr,Qr] ]
    5328       representing a set of locally closed setsV(P_i) \ V(Q_i)
    5329       to be added.
    5330 RETURN:
    5331       list of lists of levels of the different locally closed sets of
    5332       the canonical P-rep of the constructible.
    5333       [  [level_1,[ [Comp_11,..Comp_1r_1] ] ], .. ,
    5334          [level_s,[ [Comp_s1,..Comp_sr_1] ]
    5335       ]
    5336       where level_i=i,   Comp_ij=[ p_i,[p_i1,..,p_it_i] ] is a prime component.
    5337 NOTE: Operates in a ring R=Q[u_1,..,u_m]
    5338 KEYWORDS: Constructible set, Canoncial form
    5339 EXAMPLE: AddCons; shows an example"
    5340 {
    5341   int i; list H; list P; int j;
    5342   for(i=1;i<=size(L);i++)
    5343   {
    5344     P=Prep(L[i][1],L[i][2]);
    5345     for(j=1;j<=size(P);j++)
    5346     {
    5347       H[size(H)+1]=P[j];
    5348     }
    5349   }
    5350   return(AddConsP(H));
    5351 }
    5352 example
    5353 {
    5354   "EXAMPLE:"; echo = 2;
    5355   if (defined(Grobcov::@P)){kill Grobcov::@P; kill Grobcov::@R; kill Grobcov::@RP;}
    5356   ring R=0,(x,y,z),lp;
    5357   short=0;
    5358 
    5359   ideal P1=x;
    5360   ideal Q1=x,y;
    5361   ideal P2=y;
    5362   ideal Q2=y,z;
    5363 
    5364   list L=list(list(P1,Q1), list(P2,Q2) );
    5365   L;
    5366 
    5367   AddCons(L);
    5368 }
    5369 
    53705231// AddLocus: auxilliary routine for locus0 that computes the components of the constructible:
    53715232// Input:  the list of locally closed sets to be added, each with its type as third argument
     
    53975258    }
    53985259  }
    5399   L3=AddConsP(L1);
     5260  L3=LocusConsLevels(L1);
    54005261  list L4; int level;
    54015262  ideal p1; ideal pp1; int t; int k; int k0; string typ; list l4;
     
    54265287}
    54275288
    5428 //********************* End AddCons **********************
    5429 ;
     5289// Input L: list of components in P-rep to be added
     5290//         [  [[p_1,[p_11,..,p_1,r1]],..[p_k,[p_k1,..,p_kr_k]]  ]
     5291// Output:
     5292//          list of lists of levels of the different locally closed sets of
     5293//          the canonical P-rep of the constructible.
     5294//          [  [level_1,[ [Comp_11,..Comp_1r_1] ] ], .. ,
     5295//             [level_s,[ [Comp_s1,..Comp_sr_1] ]
     5296//          ]
     5297//          where level_i=i,   Comp_ij=[ p_i,[p_i1,..,p_it_i] ] is a prime component.
     5298// LocusConsLevels: given a set of components of locally closed sets in P-representation, it builds the
     5299//       canonical P-representation of the corresponding constructible set of its union,
     5300//       including levels it they are.
     5301static proc LocusConsLevels(list L)
     5302{
     5303  list Lc; list Sc;
     5304  int i;
     5305  for(i=1;i<=size(L);i++)
     5306  {
     5307    Sc=PtoCrep(list(L[i]));
     5308    Lc[size(Lc)+1]=Sc;
     5309  }
     5310  list S=ConsLevels(Lc)[1];
     5311  list Sout;
     5312  list Lev;
     5313  for(i=1;i<=size(S);i++)
     5314  {
     5315    Lev=list(i,Prep(S[i][2][1],S[i][2][2]));
     5316    Sout[size(Sout)+1]=Lev;
     5317  }
     5318  return(Sout);
     5319}
     5320
     5321//********************* End locus ****************************
     5322
  • Singular/LIB/grwalk.lib

    r4132ee r654a23  
    255255}
    256256
    257 proc gwalk(ideal Go, list #)
    258 "SYNTAX: gwalk(ideal i);
    259          gwalk(ideal i, intvec v, intvec w);
     257proc gwalk(ideal Go, int reduction,int printout, list #)
     258"SYNTAX: gwalk(ideal i, int reduction, int printout);
     259         gwalk(ideal i, int reduction, int printout, intvec v, intvec w);
    260260TYPE:    ideal
    261261PURPOSE: compute the standard basis of the ideal, calculated via
     
    274274   string ord_str =   OSCTW[2];
    275275   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
    276    intvec target_weight =   OSCTW[4]; /* terget weight vector */
     276   intvec target_weight =   OSCTW[4]; /* target weight vector */
    277277   kill OSCTW;
    278278   option(redSB);
     
    284284   //print("//** help ring = " + string(basering));
    285285   ideal G = fetch(xR, Go);
    286    G = system("Mwalk", G, curr_weight, target_weight,basering);
     286   G = system("Mwalk", G, curr_weight, target_weight,basering,reduction,printout);
    287287
    288288   setring xR;
     
    299299  //** compute a Groebner basis of I w.r.t. lp.
    300300  ring r = 32003,(z,y,x), lp;
    301   ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
    302   gwalk(I);
     301  ideal I = zy2+yx2+yx+3,
     302            z3x+y3+zyx-yx2-yx-3,
     303            z2yx3-y5+z2yx2+y3x2+y2x3+y3x+y2x2+3z2x+3y2+3yx,
     304            zyx5+y6-y4x2-y3x3+2zyx4-y4x-y3x2+zyx3-3z2yx+3zx3-3y3-3y2x+3zx2,
     305            yx7-y7+y5x2+y4x3+3yx6+y5x+y4x2+3yx5-6zyx3+yx4+3x5+3y4+3y3x-6zyx2+6x4+3x3-9zx;
     306  gwalk(I,0,1);
    303307}
    304308
     
    346350}
    347351
    348 proc fwalk(ideal Go, list #)
    349 "SYNTAX: fwalk(ideal i);
    350          fwalk(ideal i, intvec v, intvec w);
     352proc fwalk(ideal Go, int reduction, int printout, list #)
     353"SYNTAX: fwalk(ideal i,int reductioin);
     354         fwalk(ideal i, int reduction intvec v, intvec w);
    351355TYPE:    ideal
    352356PURPOSE: compute the standard basis of the ideal w.r.t. the
     
    372376
    373377   ideal G = fetch(xR, Go);
    374    G = system("Mfwalk", G, curr_weight, target_weight);
     378   G = system("Mfwalk", G, curr_weight, target_weight, reduction, printout);
    375379
    376380   setring xR;
     
    387391    ring r = 32003,(z,y,x), lp;
    388392    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
    389     fwalk(I);
     393    int reduction = 1;
     394    int printout = 1;
     395    fwalk(I,reduction,printout);
    390396}
    391397
     
    437443}
    438444
    439 proc pwalk(ideal Go, int n1, int n2, list #)
    440 "SYNTAX: pwalk(int d, ideal i, int n1, int n2);
    441          pwalk(int d, ideal i, int n1, int n2, intvec v, intvec w);
     445proc pwalk(ideal Go, int n1, int n2, int reduction, int printout, list #)
     446"SYNTAX: pwalk(int d, ideal i, int n1, int n2, int reduction, int printout);
     447         pwalk(int d, ideal i, int n1, int n2, int reduction, int printout, intvec v, intvec w);
    442448TYPE:    ideal
    443449PURPOSE: compute the standard basis of the ideal, calculated via
     
    477483  ideal G = fetch(xR, Go);
    478484
    479   G = system("Mpwalk", G, n1, n2, curr_weight, target_weight,nP);
    480 
     485  G = system("Mpwalk",G,n1,n2,curr_weight,target_weight,nP,reduction,printout);
     486 
    481487  setring xR;
    482   //kill Go;
     488  //kill Go; //unused
    483489
    484490  keepring basering;
     
    492498    ring r = 32003,(z,y,x), lp;
    493499    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
    494     //I = std(I);
    495     //ring rr = 32003,(z,y,x),lp;
    496     //ideal I = fetch(r,I);
    497     pwalk(I,2,2);
     500    int reduction = 1;
     501    int printout = 2;
     502    pwalk(I,2,2,reduction,printout);
    498503}
    499504
  • Singular/LIB/modstd.lib

    r8d7ca0 r654a23  
    283283 * (same as size(reduce(I_reduce, G_reduce))).
    284284 * Uses parallelization. */
    285 static proc reduce_parallel(ideal I_reduce, ideal G_reduce)
     285static proc reduce_parallel(def I_reduce, def G_reduce)
    286286{
    287287    exportto(Modstd, I_reduce);
  • Singular/LIB/modwalk.lib

    • Property mode changed from 100644 to 100755
    r4132ee r654a23  
    1616
    1717PROCEDURES:
    18 modWalk(ideal,int,int[,int,int,int,int]);        standard basis conversion of I using modular methods (chinese remainder)
     18
     19modWalk(I,#);                   standard basis conversion of I by Groebner Walk using modular methods
     20modrWalk(I,radius,pertdeg,#);   standard basis conversion of I by Random Walk using modular methods
     21modfWalk(I,#);                  standard basis conversion of I by Fractal Walk using modular methods
     22modfrWalk(I,radius,#);          standard basis conversion of I by Random Fractal Walk using modular methods
    1923";
    2024
    21 LIB "poly.lib";
    22 LIB "ring.lib";
    23 LIB "parallel.lib";
    2425LIB "rwalk.lib";
    2526LIB "grwalk.lib";
    26 LIB "modstd.lib";
    27 
    28 
    29 ////////////////////////////////////////////////////////////////////////////////
    30 
    31 static proc modpWalk(def II, int p, int variant, list #)
    32 "USAGE:  modpWalk(I,p,#); I ideal, p integer, variant integer
    33 ASSUME:  If size(#) > 0, then
    34            #[1] is an intvec describing the current weight vector
    35            #[2] is an intvec describing the target weight vector
    36 RETURN:  ideal - a standard basis of I mod p, integer - p
    37 NOTE:    The procedure computes a standard basis of the ideal I modulo p and
    38          fetches the result to the basering.
    39 EXAMPLE: example modpWalk; shows an example
    40 "
    41 {
    42   option(redSB);
    43   int k,nvar@r;
    44   def R0 = basering;
    45   string ordstr_R0 = ordstr(R0);
    46   list rl = ringlist(R0);
    47   int sizerl = size(rl);
    48   int neg = 1 - attrib(R0,"global");
    49   if(typeof(II) == "ideal")
    50   {
    51     ideal I = II;
     27LIB "modular.lib";
     28
     29proc modWalk(ideal I, list #)
     30"USAGE:   modWalk(I, [, v, w]); I ideal, v intvec, w intvec
     31RETURN:   a standard basis of I
     32NOTE:     The procedure computes a standard basis of I (over the rational
     33          numbers) by using modular methods.
     34SEE ALSO: modular
     35EXAMPLE:  example modWalk; shows an example"
     36{
     37    /* read optional parameter */
     38    if (size(#) > 0) {
     39        if (size(#) == 1) {
     40            intvec w = #[1];
     41        }
     42        if (size(#) == 2) {
     43            intvec v = #[1];
     44            intvec w = #[2];
     45        }
     46        if (size(#) > 2 || typeof(#[1]) != "intvec") {
     47            ERROR("wrong optional parameter");
     48        }
     49    }
     50
     51    /* save options */
     52    intvec opt = option(get);
     53    option(redSB);
     54
     55    /* set additional parameters */
     56    int reduction = 1;
     57    int printout = 0;
     58
     59    /* call modular() */
     60    if (size(#) > 0) {
     61        I = modular("gwalk", list(I,reduction,printout,#));
     62    }
     63    else {
     64        I = modular("gwalk", list(I,reduction,printout));
     65    }
     66
     67    /* return the result */
     68    attrib(I, "isSB", 1);
     69    option(set, opt);
     70    return(I);
     71}
     72example
     73{
     74    "EXAMPLE:";
     75    echo = 2;
     76    ring R1 = 0, (x,y,z,t), dp;
     77    ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4;
     78    I = std(I);
     79    ring R2 = 0, (x,y,z,t), lp;
     80    ideal I = fetch(R1, I);
     81    ideal J = modWalk(I);
     82    J;
     83}
     84
     85proc modrWalk(ideal I, int radius, int pertdeg, list #)
     86"USAGE:   modrWalk(I, radius, pertdeg[, v, w]);
     87          I ideal, radius int, pertdeg int, v intvec, w intvec
     88RETURN:   a standard basis of I
     89NOTE:     The procedure computes a standard basis of I (over the rational
     90          numbers) by using modular methods.
     91SEE ALSO: modular
     92EXAMPLE:  example modrWalk; shows an example"
     93{
     94    /* read optional parameter */
     95    if (size(#) > 0) {
     96        if (size(#) == 1) {
     97            intvec w = #[1];
     98        }
     99        if (size(#) == 2) {
     100            intvec v = #[1];
     101            intvec w = #[2];
     102        }
     103        if (size(#) > 2 || typeof(#[1]) != "intvec") {
     104            ERROR("wrong optional parameter");
     105        }
     106    }
     107
     108    /* save options */
     109    intvec opt = option(get);
     110    option(redSB);
     111
     112    /* set additional parameters */
     113    int reduction = 1;
     114    int printout = 0;
     115
     116    /* call modular() */
     117    if (size(#) > 0) {
     118        I = modular("rwalk", list(I,radius,pertdeg,reduction,printout,#));
     119    }
     120    else {
     121        I = modular("rwalk", list(I,radius,pertdeg,reduction,printout));
     122    }
     123
     124    /* return the result */
     125    attrib(I, "isSB", 1);
     126    option(set, opt);
     127    return(I);
     128}
     129example
     130{
     131    "EXAMPLE:";
     132    echo = 2;
     133    ring R1 = 0, (x,y,z,t), dp;
     134    ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4;
     135    I = std(I);
     136    ring R2 = 0, (x,y,z,t), lp;
     137    ideal I = fetch(R1, I);
    52138    int radius = 2;
    53     int pert_deg = 2;
    54   }
    55   if(typeof(II) == "list" && typeof(II[1]) == "ideal")
    56   {
    57     ideal I = II[1];
    58     if(size(II) == 2)
    59     {
    60       int radius = II[2];
    61       int pert_deg = 2;
    62     }
    63     if(size(II) == 3)
    64     {
    65       int radius = II[2];
    66       int pert_deg = II[3];
    67     }
    68   }
    69   rl[1] = p;
    70   int h = homog(I);
    71   def @r = ring(rl);
    72   setring @r;
    73   ideal i = fetch(R0,I);
    74   string order;
    75   if(system("nblocks") <= 2)
    76   {
    77     if(find(ordstr_R0, "M") + find(ordstr_R0, "lp") + find(ordstr_R0, "rp") <= 0)
    78     {
    79       order = "simple";
    80     }
    81   }
    82 
    83 //-------------------------  make i homogeneous  -----------------------------
    84   if(!mixedTest() && !h)
    85   {
    86     if(!((find(ordstr_R0, "M") > 0) || (find(ordstr_R0, "a") > 0) || neg))
    87     {
    88       if(!((order == "simple") || (sizerl > 4)))
    89       {
    90         list rl@r = ringlist(@r);
    91         nvar@r = nvars(@r);
    92         intvec w;
    93         for(k = 1; k <= nvar@r; k++)
    94         {
    95           w[k] = deg(var(k));
    96         }
    97         w[nvar@r + 1] = 1;
    98         rl@r[2][nvar@r + 1] = "homvar";
    99         rl@r[3][2][2] = w;
    100         def HomR = ring(rl@r);
    101         setring HomR;
    102         ideal i = imap(@r, i);
    103         i = homog(i, homvar);
    104       }
    105     }
    106   }
    107 
    108 //-------------------------  compute a standard basis mod p  -----------------------------
    109 
    110   if(variant == 1)
    111   {
    112     if(size(#)>0)
    113     {
    114       i = rwalk(i,radius,pert_deg,#);
    115      // rwalk(i,radius,pert_deg,#); std(i);
    116     }
    117     else
    118     {
    119       i = rwalk(i,radius,pert_deg);
    120     }
    121   }
    122   if(variant == 2)
    123   {
    124     if(size(#) == 2)
    125     {
    126       i = gwalk(i,#);
    127     }
    128     else
    129     {
    130       i = gwalk(i);
    131     }
    132   }
    133   if(variant == 3)
    134   {
    135     if(size(#) == 2)
    136     {
    137       i = frandwalk(i,radius,#);
    138     }
    139     else
    140     {
    141       i = frandwalk(i,radius);
    142     }
    143   }
    144   if(variant == 4)
    145   {
    146     if(size(#) == 2)
    147     {
    148       i=fwalk(i,#);
    149     }
    150     else
    151     {
    152       i=fwalk(i);
    153     }
    154   }
    155   if(variant == 5)
    156   {
    157     if(size(#) == 2)
    158     {
    159      i=prwalk(i,radius,pert_deg,pert_deg,#);
    160     }
    161     else
    162     {
    163       i=prwalk(i,radius,pert_deg,pert_deg);
    164     }
    165   }
    166   if(variant == 6)
    167   {
    168     if(size(#) == 2)
    169     {
    170       i=pwalk(i,pert_deg,pert_deg,#);
    171     }
    172     else
    173     {
    174       i=pwalk(i,pert_deg,pert_deg);
    175     }
    176   }
    177 
    178   if(!mixedTest() && !h)
    179   {
    180     if(!((find(ordstr_R0, "M") > 0) || (find(ordstr_R0, "a") > 0) || neg))
    181     {
    182       if(!((order == "simple") || (sizerl > 4)))
    183       {
    184         i = subst(i, homvar, 1);
    185         i = simplify(i, 34);
    186         setring @r;
    187         i = imap(HomR, i);
    188         i = interred(i);
    189         kill HomR;
    190       }
    191     }
    192   }
    193   setring R0;
    194   return(list(fetch(@r,i),p));
    195 }
    196 example
    197 {
    198   "EXAMPLE:"; echo = 2;
    199   option(redSB);
    200 
    201   int p = 181;
    202   intvec a = 2,1,3,4;
    203   intvec b = 1,9,1,1;
    204   ring ra = 0,x(1..4),(a(a),lp);
    205   ideal I = std(cyclic(4));
    206   ring rb = 0,x(1..4),(a(b),lp);
    207   ideal I = imap(ra,I);
    208   modpWalk(I,p,1,a,b);
    209   std(I);
    210 }
    211 
    212 ////////////////////////////////////////////////////////////////////////////////
    213 
    214 proc modWalk(def II, int variant, list #)
    215 "USAGE:  modWalk(II); II ideal or list(ideal,int)
    216 ASSUME:  If variant =
    217 @*       - 1 the Random Walk algorithm with radius II[2] is applied
    218            to II[1] if II = list(ideal, int). It is applied to II with radius 2
    219            if II is an ideal.
    220 @*       - 2, the Groebner Walk algorithm is applied to II[1] or to II, respectively.
    221 @*       - 3, the Fractal Walk algorithm with random element is applied to II[1] or II,
    222            respectively.
    223 @*       - 4, the Fractal Walk algorithm is applied to II[1] or II, respectively.
    224 @*       - 5, the Perturbation Walk algorithm with random element is applied to II[1]
    225            or II, respectively, with radius II[3] and perturbation degree II[2].
    226 @*       - 6, the Perturbation Walk algorithm is applied to II[1] or II, respectively,
    227            with perturbation degree II[3].
    228          If size(#) > 0, then # contains either 1, 2 or 4 integers such that
    229 @*       - #[1] is the number of available processors for the computation,
    230 @*       - #[2] is an optional parameter for the exactness of the computation,
    231                 if #[2] = 1, the procedure computes a standard basis for sure,
    232 @*       - #[3] is the number of primes until the first lifting,
    233 @*       - #[4] is the constant number of primes between two liftings until
    234            the computation stops.
    235 RETURN:  a standard basis of I if no warning appears.
    236 NOTE:    The procedure converts a standard basis of I (over the rational
    237          numbers) from the ordering \"a(v),lp\", "dp\" or \"Dp\" to the ordering
    238          \"(a(w),lp\" or \"a(1,0,...,0),lp\" by using modular methods.
    239          By default the procedure computes a standard basis of I for sure, but
    240          if the optional parameter #[2] = 0, it computes a standard basis of I
    241          with high probability.
    242 EXAMPLE: example modWalk; shows an example
    243 "
    244 {
    245   int TT = timer;
    246   int RT = rtimer;
    247   int i,j,pTest,sizeTest,weighted,n1;
    248   bigint N;
    249 
    250   def R0 = basering;
    251   list rl = ringlist(R0);
    252   if((npars(R0) > 0) || (rl[1] > 0))
    253   {
    254     ERROR("Characteristic of basering should be zero, basering should have no parameters.");
    255   }
    256 
    257   if(typeof(II) == "ideal")
    258   {
    259     ideal I = II;
    260     kill II;
    261     list II;
    262     II[1] = I;
    263     II[2] = 2;
    264     II[3] = 2;
    265   }
    266   else
    267   {
    268     if(typeof(II) == "list" && typeof(II[1]) == "ideal")
    269     {
    270       ideal I = II[1];
    271       if(size(II) == 1)
    272       {
    273         II[2] = 2;
    274         II[3] = 2;
    275       }
    276       if(size(II) == 2)
    277       {
    278         II[3] = 2;
    279       }
    280 
    281     }
    282     else
    283     {
    284       ERROR("Unexpected type of input.");
    285     }
    286   }
    287 
    288 //--------------------  Initialize optional parameters  ------------------------
    289   n1 = system("--cpus");
    290   if(size(#) == 0)
    291   {
    292     int exactness = 1;
    293     int n2 = 10;
    294     int n3 = 10;
    295   }
    296   else
    297   {
    298     if(size(#) == 1)
    299     {
    300       if(typeof(#[1]) == "int")
    301       {
    302         if(#[1] < n1)
    303         {
    304           n1 = #[1];
    305         }
    306         int exactness = 1;
    307         if(n1 >= 10)
    308         {
    309           int n2 = n1 + 1;
    310           int n3 = n1;
    311         }
    312         else
    313         {
    314           int n2 = 10;
    315           int n3 = 10;
    316         }
    317       }
    318       else
    319       {
    320         ERROR("Unexpected type of input.");
    321       }
    322     }
    323     if(size(#) == 2)
    324     {
    325       if(typeof(#[1]) == "int" && typeof(#[2]) == "int")
    326       {
    327         if(#[1] < n1)
    328         {
    329           n1 = #[1];
    330         }
    331         int exactness = #[2];
    332         if(n1 >= 10)
    333         {
    334           int n2 = n1 + 1;
    335           int n3 = n1;
    336         }
    337         else
    338         {
    339           int n2 = 10;
    340           int n3 = 10;
    341         }
    342       }
    343       else
    344       {
    345         if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec")
    346         {
    347           intvec curr_weight = #[1];
    348           intvec target_weight = #[2];
    349           weighted = 1;
    350           int n2 = 10;
    351           int n3 = 10;
    352           int exactness = 1;
    353         }
    354         else
    355         {
    356           ERROR("Unexpected type of input.");
    357         }
    358       }
    359     }
    360     if(size(#) == 3)
    361     {
    362       if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec" && typeof(#[3]) == "int")
    363       {
    364         intvec curr_weight = #[1];
    365         intvec target_weight = #[2];
    366         weighted = 1;
    367         n1 = #[3];
    368         int n2 = 10;
    369         int n3 = 10;
    370         int exactness = 1;
    371       }
    372       else
    373       {
    374         ERROR("Unexpected type of input.");
    375       }
    376     }
    377     if(size(#) == 4)
    378     {
    379       if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec" && typeof(#[3]) == "int"
    380           && typeof(#[4]) == "int")
    381       {
    382         intvec curr_weight = #[1];
    383         intvec target_weight = #[2];
    384         weighted = 1;
    385         if(#[1] < n1)
    386         {
    387           n1 = #[3];
    388         }
    389         int exactness = #[4];
    390         if(n1 >= 10)
    391         {
    392           int n2 = n1 + 1;
    393           int n3 = n1;
    394         }
    395         else
    396         {
    397           int n2 = 10;
    398           int n3 = 10;
    399         }
    400       }
    401       else
    402       {
    403         if(typeof(#[1]) == "int" && typeof(#[2]) == "int" && typeof(#[3]) == "int" && typeof(#[4]) == "int")
    404         {
    405           if(#[1] < n1)
    406           {
    407             n1 = #[1];
    408           }
    409           int exactness = #[2];
    410           if(n1 >= #[3])
    411           {
    412             int n2 = n1 + 1;
    413           }
    414           else
    415           {
    416             int n2 = #[3];
    417           }
    418           if(n1 >= #[4])
    419           {
    420             int n3 = n1;
    421           }
    422           else
    423           {
    424             int n3 = #[4];
    425           }
    426         }
    427         else
    428         {
    429           ERROR("Unexpected type of input.");
    430         }
    431       }
    432     }
    433     if(size(#) == 6)
    434     {
    435       if(typeof(#[1]) == "intvec" && typeof(#[2]) == "intvec" && typeof(#[3]) == "int" && typeof(#[4]) == "int" && typeof(#[5]) == "int" && typeof(#[6]) == "int")
    436       {
    437         intvec curr_weight = #[1];
    438         intvec target_weight = #[2];
    439         weighted = 1;
    440         if(#[3] < n1)
    441         {
    442           n1 = #[3];
    443         }
    444         int exactness = #[4];
    445         if(n1 >= #[5])
    446         {
    447           int n2 = n1 + 1;
    448         }
    449         else
    450         {
    451           int n2 = #[5];
    452         }
    453         if(n1 >= #[6])
    454         {
    455           int n3 = n1;
    456         }
    457         else
    458         {
    459           int n3 = #[6];
    460         }
    461       }
    462       else
    463       {
    464         ERROR("Expected list(intvec,intvec,int,int,int,int) as optional parameter list.");
    465       }
    466     }
    467     if(size(#) == 1 || size(#) == 5 || size(#) > 6)
    468     {
    469       ERROR("Expected 0,2,3,4 or 5 optional arguments.");
    470     }
    471   }
    472   if(printlevel >= 10)
    473   {
    474   "n1 = "+string(n1)+", n2 = "+string(n2)+", n3 = "+string(n3)+", exactness = "+string(exactness);
    475   }
    476 
    477 //-------------------------  Save current options  -----------------------------
    478   intvec opt = option(get);
    479   //option(redSB);
    480 
    481 //--------------------  Initialize the list of primes  -------------------------
    482   int tt = timer;
    483   int rt = rtimer;
    484   int en = 2134567879;
    485   int an = 1000000000;
    486   intvec L = primeList(I,n2);
    487   if(n2 > 4)
    488   {
    489   //  L[5] = prime(random(an,en));
    490   }
    491   if(printlevel >= 10)
    492   {
    493     "CPU-time for primeList: "+string(timer-tt)+" seconds.";
    494     "Real-time for primeList: "+string(rtimer-rt)+" seconds.";
    495   }
    496   int h = homog(I);
    497   list P,T1,T2,LL,Arguments,PP;
    498   ideal J,K,H;
    499 
    500 //-------------------  parallelized Groebner Walk in positive characteristic  --------------------
    501 
    502   if(weighted)
    503   {
    504     for(i=1; i<=size(L); i++)
    505     {
    506       Arguments[i] = list(II,L[i],variant,list(curr_weight,target_weight));
    507     }
    508   }
    509   else
    510   {
    511     for(i=1; i<=size(L); i++)
    512     {
    513       Arguments[i] = list(II,L[i],variant);
    514     }
    515   }
    516   P = parallelWaitAll("modpWalk",Arguments);
    517   for(i=1; i<=size(P); i++)
    518   {
    519     T1[i] = P[i][1];
    520     T2[i] = bigint(P[i][2]);
    521   }
    522 
    523   while(1)
    524   {
    525     LL = deleteUnluckyPrimes(T1,T2,h);
    526     T1 = LL[1];
    527     T2 = LL[2];
    528 //-------------------  Now all leading ideals are the same  --------------------
    529 //-------------------  Lift results to basering via farey  ---------------------
    530 
    531     tt = timer; rt = rtimer;
    532     N = T2[1];
    533     for(i=2; i<=size(T2); i++)
    534     {
    535       N = N*T2[i];
    536     }
    537     H = chinrem(T1,T2);
    538     J = parallelFarey(H,N,n1);
    539     //J=farey(H,N);
    540     if(printlevel >= 10)
    541     {
    542       "CPU-time for lifting-process is "+string(timer - tt)+" seconds.";
    543       "Real-time for lifting-process is "+string(rtimer - rt)+" seconds.";
    544     }
    545 
    546 //----------------  Test if we already have a standard basis of I --------------
    547 
    548     tt = timer; rt = rtimer;
    549     pTest = pTestSB(I,J,L,variant);
    550     //pTest = primeTestSB(I,J,L,variant);
    551     if(printlevel >= 10)
    552     {
    553       "CPU-time for pTest is "+string(timer - tt)+" seconds.";
    554       "Real-time for pTest is "+string(rtimer - rt)+" seconds.";
    555     }
    556     if(pTest)
    557     {
    558       if(printlevel >= 10)
    559       {
    560         "CPU-time for computation without final tests is "+string(timer - TT)+" seconds.";
    561         "Real-time for computation without final tests is "+string(rtimer - RT)+" seconds.";
    562       }
    563       attrib(J,"isSB",1);
    564       if(exactness == 0)
    565       {
    566         option(set, opt);
    567         return(J);
    568       }
    569       else
    570       {
    571         tt = timer;
    572         rt = rtimer;
    573         sizeTest = 1 - isIdealIncluded(I,J,n1);
    574         if(printlevel >= 10)
    575         {
    576           "CPU-time for checking if I subset <G> is "+string(timer - tt)+" seconds.";
    577           "Real-time for checking if I subset <G> is "+string(rtimer - rt)+" seconds.";
    578         }
    579         if(sizeTest == 0)
    580         {
    581           tt = timer;
    582           rt = rtimer;
    583           K = std(J);
    584           if(printlevel >= 10)
    585           {
    586             "CPU-time for last std-computation is "+string(timer - tt)+" seconds.";
    587             "Real-time for last std-computation is "+string(rtimer - rt)+" seconds.";
    588           }
    589           if(size(reduce(K,J)) == 0)
    590           {
    591             option(set, opt);
    592             return(J);
    593           }
    594         }
    595       }
    596     }
    597 //--------------  We do not already have a standard basis of I, therefore do the main computation for more primes  --------------
    598 
    599     T1 = H;
    600     T2 = N;
    601     j = size(L)+1;
    602     tt = timer; rt = rtimer;
    603     L = primeList(I,n3,L,n1);
    604     if(printlevel >= 10)
    605     {
    606       "CPU-time for primeList: "+string(timer-tt)+" seconds.";
    607       "Real-time for primeList: "+string(rtimer-rt)+" seconds.";
    608     }
    609     Arguments = list();
    610     PP = list();
    611     if(weighted)
    612     {
    613       for(i=j; i<=size(L); i++)
    614       {
    615         //Arguments[i-j+1] = list(II,L[i],variant,list(curr_weight,target_weight));
    616         Arguments[size(Arguments)+1] = list(II,L[i],variant,list(curr_weight,target_weight));
    617       }
    618     }
    619     else
    620     {
    621       for(i=j; i<=size(L); i++)
    622       {
    623         //Arguments[i-j+1] = list(II,L[i],variant);
    624         Arguments[size(Arguments)+1] = list(II,L[i],variant);
    625       }
    626     }
    627     PP = parallelWaitAll("modpWalk",Arguments);
    628     if(printlevel >= 10)
    629     {
    630       "parallel modpWalk";
    631     }
    632     for(i=1; i<=size(PP); i++)
    633     {
    634       //P[size(P) + 1] = PP[i];
    635       T1[size(T1) + 1] = PP[i][1];
    636       T2[size(T2) + 1] = bigint(PP[i][2]);
    637     }
    638   }
    639   if(printlevel >= 10)
    640   {
    641     "CPU-time for computation with final tests is "+string(timer - TT)+" seconds.";
    642     "Real-time for computation with final tests is "+string(rtimer - RT)+" seconds.";
    643   }
    644 }
    645 
    646 example
    647 {
    648   "EXAMPLE:";
    649   echo = 2;
    650   ring R=0,(x,y,z),lp;
    651   ideal I=-x+y2z-z,xz+1,x2+y2-1;
    652   // I is a standard basis in dp
    653   ideal J = modWalk(I,1);
    654   J;
    655 }
    656 
    657 ////////////////////////////////////////////////////////////////////////////////
    658 static proc isIdealIncluded(ideal I, ideal J, int n1)
    659 "USAGE:  isIdealIncluded(I,J,int n1); I ideal, J ideal, n1 integer
    660 "
    661 {
    662   if(n1 > 1)
    663   {
    664     int k;
    665     list args,results;
    666     for(k=1; k<=size(I); k++)
    667     {
    668       args[k] = list(ideal(I[k]),J,1);
    669     }
    670     results = parallelWaitAll("reduce",args);
    671     for(k=1; k<=size(results); k++)
    672     {
    673       if(results[k] == 0)
    674       {
    675         return(1);
    676       }
    677     }
    678     return(0);
    679   }
    680   else
    681   {
    682     if(reduce(I,J,1) == 0)
    683     {
    684       return(1);
    685     }
    686     else
    687     {
    688       return(0);
    689     }
    690   }
    691 }
    692 
    693 ////////////////////////////////////////////////////////////////////////////////
    694 static proc parallelChinrem(list T1, list T2, int n1)
    695 "USAGE:  parallelChinrem(T1,T2); T1 list of ideals, T2 list of primes, n1 integer"
    696 {
    697   int i,j,k;
    698 
    699   ideal H,J;
    700 
    701   list arguments_chinrem,results_chinrem;
    702   for(i=1; i<=size(T1); i++)
    703   {
    704     J = ideal(T1[i]);
    705     attrib(J,"isSB",1);
    706     arguments_chinrem[size(arguments_chinrem)+1] = list(list(J),T2);
    707   }
    708   results_chinrem = parallelWaitAll("chinrem",arguments_chinrem);
    709     for(j=1; j <= size(results_chinrem); j++)
    710     {
    711       J = results_chinrem[j];
    712       attrib(J,"isSB",1);
    713       if(isIdealIncluded(J,H,n1) == 0)
    714       {
    715         if(H == 0)
    716         {
    717           H = J;
    718         }
    719         else
    720         {
    721           H = H,J;
    722         }
    723       }
    724     }
    725   return(H);
    726 }
    727 
    728 ////////////////////////////////////////////////////////////////////////////////
    729 static proc parallelFarey(ideal H, bigint N, int n1)
    730 "USAGE:  parallelFarey(H,N,n1); H ideal, N bigint, n1 integer
    731 "
    732 {
    733   int i,j;
    734   int ii = 1;
    735   list arguments_farey,results_farey;
    736   for(i=1; i<=size(H); i++)
    737   {
    738     for(j=1; j<=size(H[i]); j++)
    739     {
    740       arguments_farey[size(arguments_farey)+1] = list(H[i][j],N);
    741     }
    742   }
    743   results_farey = parallelWaitAll("farey",arguments_farey);
    744   ideal J,K;
    745   poly f_farey;
    746   while(ii<=size(results_farey))
    747   {
    748     for(i=1; i<=size(H); i++)
    749     {
    750       f_farey = 0;
    751       for(j=1; j<=size(H[i]); j++)
    752       {
    753         f_farey = f_farey + results_farey[ii][1];
    754         ii++;
    755       }
    756       K = ideal(f_farey);
    757       attrib(K,"isSB",1);
    758       attrib(J,"isSB",1);
    759       if(isIdealIncluded(K,J,n1) == 0)
    760       {
    761         if(J == 0)
    762         {
    763           J = K;
    764         }
    765         else
    766         {
    767           J = J,K;
    768         }
    769       }
    770     }
    771   }
    772   return(J);
    773 }
    774 //////////////////////////////////////////////////////////////////////////////////
    775 static proc primeTestSB(def II, ideal J, list L, int variant, list #)
    776 "USAGE:  primeTestSB(I,J,L,variant,#); I,J ideals, L intvec of primes, variant int
    777 RETURN:  1 (resp. 0) if for a randomly chosen prime p that is not in L
    778          J mod p is (resp. is not) a standard basis of I mod p
    779 EXAMPLE: example primeTestSB; shows an example
    780 "
    781 {
    782 if(typeof(II) == "ideal")
    783   {
    784   ideal I = II;
    785   int radius = 2;
    786   }
    787 if(typeof(II) == "list")
    788   {
    789   ideal I = II[1];
    790   int radius = II[2];
    791   }
    792 
    793 int i,j,k,p;
    794 def R = basering;
    795 list r = ringlist(R);
    796 
    797 while(!j)
    798   {
    799   j = 1;
    800   p = prime(random(1000000000,2134567879));
    801   for(i = 1; i <= size(L); i++)
    802     {
    803     if(p == L[i])
    804       {
    805       j = 0;
    806       break;
    807       }
    808     }
    809   if(j)
    810     {
    811     for(i = 1; i <= ncols(I); i++)
    812       {
    813       for(k = 2; k <= size(I[i]); k++)
    814         {
    815         if((denominator(leadcoef(I[i][k])) mod p) == 0)
    816           {
    817           j = 0;
    818           break;
    819           }
    820         }
    821       if(!j)
    822         {
    823         break;
    824         }
    825       }
    826     }
    827   if(j)
    828     {
    829     if(!primeTest(I,p))
    830       {
    831       j = 0;
    832       }
    833     }
    834   }
    835 r[1] = p;
    836 def @R = ring(r);
    837 setring @R;
    838 ideal I = imap(R,I);
    839 ideal J = imap(R,J);
    840 attrib(J,"isSB",1);
    841 
    842 int t = timer;
    843 j = 1;
    844 if(isIncluded(I,J) == 0)
    845   {
    846   j = 0;
    847   }
    848 if(printlevel >= 11)
    849   {
    850   "isIncluded(I,J) takes "+string(timer - t)+" seconds";
    851   "j = "+string(j);
    852   }
    853 t = timer;
    854 if(j)
    855   {
    856   if(size(#) > 0)
    857     {
    858     ideal K = modpWalk(I,p,variant,#)[1];
    859     }
    860   else
    861     {
    862     ideal K = modpWalk(I,p,variant)[1];
    863     }
    864   t = timer;
    865   if(isIncluded(J,K) == 0)
    866     {
    867     j = 0;
    868     }
    869   if(printlevel >= 11)
    870     {
    871     "isIncluded(K,J) takes "+string(timer - t)+" seconds";
    872     "j = "+string(j);
    873     }
    874   }
    875 setring R;
    876 
    877 return(j);
    878 }
    879 example
    880 { "EXAMPLE:"; echo = 2;
    881    intvec L = 2,3,5;
    882    ring r = 0,(x,y,z),lp;
    883    ideal I = x+1,x+y+1;
    884    ideal J = x+1,y;
    885    primeTestSB(I,I,L,1);
    886    primeTestSB(I,J,L,1);
    887 }
    888 
    889 ////////////////////////////////////////////////////////////////////////////////
    890 static proc pTestSB(ideal I, ideal J, list L, int variant, list #)
    891 "USAGE:  pTestSB(I,J,L,variant,#); I,J ideals, L intvec of primes, variant int
    892 RETURN:  1 (resp. 0) if for a randomly chosen prime p that is not in L
    893          J mod p is (resp. is not) a standard basis of I mod p
    894 EXAMPLE: example pTestSB; shows an example
    895 "
    896 {
    897    int i,j,k,p;
    898    def R = basering;
    899    list r = ringlist(R);
    900 
    901    while(!j)
    902    {
    903       j = 1;
    904       p = prime(random(1000000000,2134567879));
    905       for(i = 1; i <= size(L); i++)
    906       {
    907          if(p == L[i]) { j = 0; break; }
    908       }
    909       if(j)
    910       {
    911          for(i = 1; i <= ncols(I); i++)
    912          {
    913             for(k = 2; k <= size(I[i]); k++)
    914             {
    915                if((denominator(leadcoef(I[i][k])) mod p) == 0) { j = 0; break; }
    916             }
    917             if(!j){ break; }
    918          }
    919       }
    920       if(j)
    921       {
    922          if(!primeTest(I,p)) { j = 0; }
    923       }
    924    }
    925    r[1] = p;
    926    def @R = ring(r);
    927    setring @R;
    928    ideal I = imap(R,I);
    929    ideal J = imap(R,J);
    930    attrib(J,"isSB",1);
    931 
    932    int t = timer;
    933    j = 1;
    934    if(isIncluded(I,J) == 0) { j = 0; }
    935 
    936    if(printlevel >= 11)
    937    {
    938       "isIncluded(I,J) takes "+string(timer - t)+" seconds";
    939       "j = "+string(j);
    940    }
    941 
    942    t = timer;
    943    if(j)
    944    {
    945       if(size(#) > 0)
    946       {
    947          ideal K = modpStd(I,p,variant,#[1])[1];
    948       }
    949       else
    950       {
    951          ideal K = groebner(I);
    952       }
    953       t = timer;
    954       if(isIncluded(J,K) == 0) { j = 0; }
    955 
    956       if(printlevel >= 11)
    957       {
    958          "isIncluded(J,K) takes "+string(timer - t)+" seconds";
    959          "j = "+string(j);
    960       }
    961    }
    962    setring R;
    963    return(j);
    964 }
    965 example
    966 { "EXAMPLE:"; echo = 2;
    967    intvec L = 2,3,5;
    968    ring r = 0,(x,y,z),dp;
    969    ideal I = x+1,x+y+1;
    970    ideal J = x+1,y;
    971    pTestSB(I,I,L,2);
    972    pTestSB(I,J,L,2);
    973 }
    974 ////////////////////////////////////////////////////////////////////////////////
    975 static proc mixedTest()
    976 "USAGE:  mixedTest();
    977 RETURN:  1 if ordering of basering is mixed, 0 else
    978 EXAMPLE: example mixedTest(); shows an example
    979 "
    980 {
    981    int i,p,m;
    982    for(i = 1; i <= nvars(basering); i++)
    983    {
    984       if(var(i) > 1)
    985       {
    986          p++;
    987       }
    988       else
    989       {
    990          m++;
    991       }
    992    }
    993    if((p > 0) && (m > 0)) { return(1); }
    994    return(0);
    995 }
    996 example
    997 { "EXAMPLE:"; echo = 2;
    998    ring R1 = 0,(x,y,z),dp;
    999    mixedTest();
    1000    ring R2 = 31,(x(1..4),y(1..3)),(ds(4),lp(3));
    1001    mixedTest();
    1002    ring R3 = 181,x(1..9),(dp(5),lp(4));
    1003    mixedTest();
    1004 }
     139    int pertdeg = 3;
     140    ideal J = modrWalk(I,radius,pertdeg);
     141    J;
     142}
     143
     144proc modfWalk(ideal I, list #)
     145"USAGE:   modfWalk(I, [, v, w]); I ideal, v intvec, w intvec
     146RETURN:   a standard basis of I
     147NOTE:     The procedure computes a standard basis of I (over the rational
     148          numbers) by using modular methods.
     149SEE ALSO: modular
     150EXAMPLE:  example modfWalk; shows an example"
     151{
     152    /* read optional parameter */
     153    if (size(#) > 0) {
     154        if (size(#) == 1) {
     155            intvec w = #[1];
     156        }
     157        if (size(#) == 2) {
     158            intvec v = #[1];
     159            intvec w = #[2];
     160        }
     161        if (size(#) > 2 || typeof(#[1]) != "intvec") {
     162            ERROR("wrong optional parameter");
     163        }
     164    }
     165
     166    /* save options */
     167    intvec opt = option(get);
     168    option(redSB);
     169
     170    /* set additional parameters */
     171    int reduction = 1;
     172    int printout = 0;
     173
     174    /* call modular() */
     175    if (size(#) > 0) {
     176        I = modular("fwalk", list(I,reduction,printout,#));
     177    }
     178    else {
     179        I = modular("fwalk", list(I,reduction,printout));
     180    }
     181
     182    /* return the result */
     183    attrib(I, "isSB", 1);
     184    option(set, opt);
     185    return(I);
     186}
     187example
     188{
     189    "EXAMPLE:";
     190    echo = 2;
     191    ring R1 = 0, (x,y,z,t), dp;
     192    ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4;
     193    I = std(I);
     194    ring R2 = 0, (x,y,z,t), lp;
     195    ideal I = fetch(R1, I);
     196    ideal J = modfWalk(I);
     197    J;
     198}
     199
     200proc modfrWalk(ideal I, int radius, list #)
     201"USAGE:   modfrWalk(I, radius [, v, w]); I ideal, radius int, v intvec, w intvec
     202RETURN:   a standard basis of I
     203NOTE:     The procedure computes a standard basis of I (over the rational
     204          numbers) by using modular methods.
     205SEE ALSO: modular
     206EXAMPLE:  example modfrWalk; shows an example"
     207{
     208    /* read optional parameter */
     209    if (size(#) > 0) {
     210        if (size(#) == 1) {
     211            intvec w = #[1];
     212        }
     213        if (size(#) == 2) {
     214            intvec v = #[1];
     215            intvec w = #[2];
     216        }
     217        if (size(#) > 2 || typeof(#[1]) != "intvec") {
     218            ERROR("wrong optional parameter");
     219        }
     220    }
     221
     222    /* save options */
     223    intvec opt = option(get);
     224    option(redSB);
     225
     226    /* set additional parameters */
     227    int reduction = 1;
     228    int printout = 0;
     229
     230    /* call modular() */
     231    if (size(#) > 0) {
     232        I = modular("frandwalk", list(I,radius,reduction,printout,#));
     233    }
     234    else {
     235        I = modular("frandwalk", list(I,radius,reduction,printout));
     236    }
     237
     238    /* return the result */
     239    attrib(I, "isSB", 1);
     240    option(set, opt);
     241    return(I);
     242}
     243example
     244{
     245    "EXAMPLE:";
     246    echo = 2;
     247    ring R1 = 0, (x,y,z,t), dp;
     248    ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4;
     249    I = std(I);
     250    ring R2 = 0, (x,y,z,t), lp;
     251    ideal I = fetch(R1, I);
     252    int radius = 2;
     253    ideal J = modfrWalk(I,radius);
     254    J;
     255}
  • Singular/LIB/ncfactor.lib

    r8d7ca0 r654a23  
    64986498    def Firstweyl = nc_algebra(1,1);
    64996499    setring Firstweyl;
    6500     ideal M = 0:nvars(@r);
     6500    ideal M = ideal(0:nvars(@r));
    65016501    M[varnumX]=var(2);
    65026502    M[varnumD]=var(1);
  • Singular/LIB/nctools.lib

    r8d7ca0 r654a23  
    15971597  matrix U = UpOneMatrix(N);
    15981598  if (size(ideal(C-U)) <> 0) { return(notW); } // lt(xy)<>lt(yx)
    1599   ideal I = D;
     1599  ideal I = ideal(D);
    16001600  if (size(I) <> n) { return(notW); } // not n entries<>0
    16011601  I = simplify(I,4+2);
  • Singular/LIB/nfmodstd.lib

    r8d7ca0 r654a23  
    524524    I;
    525525}
     526
     527//////////////////////////////////////////////////////////////////////////////
     528
     529/*
     530Benchmark Problems from
     531
     532Boku, Decker, Fieker, Steenpass: Groebner Bases over Algebraic Number
     533Fields.
     534
     535// 1
     536ring R = (0,a), (x,y,z), dp;
     537minpoly = (a^2+1);
     538poly f1 = (a+8)*x^2*y^2+5*x*y^3+(-a+3)*x^3*z
     539          +x^2*y*z;
     540poly f2 = x^5+2*y^3*z^2+13*y^2*z^3+5*y*z^4;
     541poly f3 = 8*x^3+(a+12)*y^3+x*z^2+3;
     542poly f4 = (-a+7)*x^2*y^4+y^3*z^3+18*y^3*z^2;
     543ideal I1 = f1,f2,f3,f4;
     544
     545// 2
     546ring R = (0,a), (x,y,z), dp;
     547minpoly = (a^5+a^2+2);
     548poly f1 = 2*x*y^4*z^2+(a-1)*x^2*y^3*z
     549          +(2*a)*x*y*z^2+7*y^3+(7*a+1);
     550poly f2 = 2*x^2*y^4*z+(a)*x^2*y*z^2-x*y^2*z^2
     551          +(2*a+3)*x^2*y*z-12*x+(12*a)*y;
     552poly f3 = (2*a)*y^5*z+x^2*y^2*z-x*y^3*z
     553          +(-a)*x*y^3+y^4+2*y^2*z;
     554poly f4 = (3*a)*x*y^4*z^3+(a+1)*x^2*y^2*z
     555          -x*y^3*z+4*y^3*z^2+(3*a)*x*y*z^3
     556          +4*z^2-x+(a)*y;
     557ideal I2 = f1,f2,f3,f4;
     558
     559// 3a
     560ring R = (0,a), (v,w,x,y,z), dp;
     561minpoly = (a^7-7*a+3);
     562poly f1 = (a)*v+(a-1)*w+x+(a+2)*y+z;
     563poly f2 = v*w+(a-1)*w*x+(a+2)*v*y+x*y+(a)*y*z;
     564poly f3 = (a)*v*w*x+(a+5)*w*x*y+(a)*v*w*z
     565          +(a+2)*v*y*z+(a)*x*y*z;
     566poly f4 = (a-11)*v*w*x*y+(a+5)*v*w*x*z
     567          +(a)*v*w*y*z+(a)*v*x*y*z
     568          +(a)*w*x*y*z;
     569poly f5 = (a+3)*v*w*x*y*z+(a+23);
     570ideal I3a = f1,f2,f3,f4,f5;
     571
     572// 3b
     573ring R = (0,a), (u,v,w,x,y,z), dp;
     574minpoly = (a^7-7*a+3);
     575poly f1 = (a)*u+(a+2)*v+w+x+y+z;
     576poly f2 = u*v+v*w+w*x+x*y+(a+3)*u*z+y*z;
     577poly f3 = u*v*w+v*w*x+(a+1)*w*x*y+u*v*z+u*y*z
     578          +x*y*z;
     579poly f4 = (a-1)*u*v*w*x+v*w*x*y+u*v*w*z
     580          +u*v*y*z+u*x*y*z+w*x*y*z;
     581poly f5 = u*v*w*x*y+(a+1)*u*v*w*x*z+u*v*w*y*z
     582          +u*v*x*y*z+u*w*x*y*z+v*w*x*y*z;
     583poly f6 = u*v*w*x*y*z+(-a+2);
     584ideal I3b = f1,f2,f3,f4,f5,f6;
     585
     586// 4
     587ring R = (0,a), (w,x,y,z), dp;
     588minpoly = (a^6+a^5+a^4+a^3+a^2+a+1);
     589poly f1 = (a+5)*w^3*x^2*y+(a-3)*w^2*x^3*y
     590          +(a+7)*w*x^2*y^2;
     591poly f2 = (a)*w^5+(a+3)*w*x^2*y^2
     592          +(a^2+11)*x^2*y^2*z;
     593poly f3 = (a+7)*w^3+12*x^3+4*w*x*y+(a)*z^3;
     594poly f4 = 3*w^3+(a-4)*x^3+x*y^2;
     595ideal I4 = f1,f2,f3,f4;
     596
     597// 5
     598ring R = (0,a), (w,x,y,z), dp;
     599minpoly = (a^12-5*a^11+24*a^10-115*a^9+551*a^8
     600          -2640*a^7+12649*a^6-2640*a^5+551*a^4
     601          -115*a^3+24*a^2-5*a+1);
     602poly f1 = (2*a+3)*w*x^4*y^2+(a+1)*w^2*x^3*y*z
     603          +2*w*x*y^2*z^3+(7*a-1)*x^3*z^4;
     604poly f2 = 2*w^2*x^4*y+w^2*x*y^2*z^2
     605          +(-a)*w*x^2*y^2*z^2
     606          +(a+11)*w^2*x*y*z^3-12*w*z^6
     607          +12*x*z^6;
     608poly f3 = 2*x^5*y+w^2*x^2*y*z-w*x^3*y*z
     609          -w*x^3*z^2+(a)*x^4*z^2+2*x^2*y*z^3;
     610poly f4 = 3*w*x^4*y^3+w^2*x^2*y*z^3
     611          -w*x^3*y*z^3+(a+4)*x^3*y^2*z^3
     612          +3*w*x*y^3*z^3+(4*a)*y^2*z^6-w*z^7
     613          +x*z^7;
     614ideal I5 = f1,f2,f3,f4;
     615
     616// 6
     617ring R = (0,a), (u,v,w,x,y,z), dp;
     618minpoly = (a^2+5*a+1);
     619poly f1 = u+v+w+x+y+z+(a);
     620poly f2 = u*v+v*w+w*x+x*y+y*z+(a)*u+(a)*z;
     621poly f3 = u*v*w+v*w*x+w*x*y+x*y*z+(a)*u*v
     622          +(a)*u*z+(a)*y*z;
     623poly f4 = u*v*w*x+v*w*x*y+w*x*y*z+(a)*u*v*w
     624          +(a)*u*v*z+(a)*u*y*z+(a)*x*y*z;
     625poly f5 = u*v*w*x*y+v*w*x*y*z+(a)*u*v*w*x
     626          +(a)*u*v*w*z+(a)*u*v*y*z+(a)*u*x*y*z
     627          +(a)*w*x*y*z;
     628poly f6 = u*v*w*x*y*z+(a)*u*v*w*x*y
     629          +(a)*u*v*w*x*z+(a)*u*v*w*y*z
     630          +(a)*u*v*x*y*z+(a)*u*w*x*y*z
     631          +(a)*v*w*x*y*z;
     632poly f7 = (a)*u*v*w*x*y*z-1;
     633ideal I6 = f1,f2,f3,f4,f5,f6,f7;
     634
     635// 7
     636ring R = (0,a), (w,x,y,z), dp;
     637minpoly = (a^8-16*a^7+19*a^6-a^5-5*a^4+13*a^3
     638          -9*a^2+13*a+17);
     639poly f1 = (-a^2-1)*x^2*y+2*w*x*z-2*w
     640          +(a^2+1)*y;
     641poly f2 = (a^3-a-3)*w^3*y+4*w*x^2*y+4*w^2*x*z
     642          +2*x^3*z+(a)*w^2-10*x^2+4*w*y-10*x*z
     643          +(2*a^2+a);
     644poly f3 = (a^2+a+11)*x*y*z+w*z^2-w-2*y;
     645poly f4 = -w*y^3+4*x*y^2*z+4*w*y*z^2+2*x*z^3
     646          +(2*a^3+a^2)*w*y+4*y^2-10*x*z-10*z^2
     647          +(3*a^2+5);
     648ideal I7 = f1,f2,f3,f4;
     649
     650// 8
     651ring R = (0,a), (t,u,v,w,x,y,z), dp;
     652minpoly = (a^7+10*a^5+5*a^3+10*a+1);
     653poly f1 = v*x+w*y-x*z-w-y;
     654poly f2 = v*w-u*x+x*y-w*z+v+x+z;
     655poly f3 = t*w-w^2+x^2-t;
     656poly f4 = (-a)*v^2-u*y+y^2-v*z-z^2+u;
     657poly f5 = t*v+v*w+(-a^2-a-5)*x*y-t*z+w*z+v+x+z
     658          +(a+1);
     659poly f6 = t*u+u*w+(-a-11)*v*x-t*y+w*y-x*z-t-u
     660          +w+y;
     661poly f7 = w^2*y^3-w*x*y^3+x^2*y^3+w^2*y^2*z
     662          -w*x*y^2*z+x^2*y^2*z+w^2*y*z^2
     663          -w*x*y*z^2+x^2*y*z^2+w^2*z^3-w*x*z^3
     664          +x^2*z^3;
     665poly f8 = t^2*u^3+t^2*u^2*v+t^2*u*v^2+t^2*v^3
     666          -t*u^3*x-t*u^2*v*x-t*u*v^2*x-t*v^3*x
     667          +u^3*x^2+u^2*v*x^2+u*v^2*x^2
     668          +v^3*x^2;
     669ideal I8 = f1,f2,f3,f4,f5,f6,f7,f8;
     670*/
  • Singular/LIB/primdec.lib

    r8d7ca0 r654a23  
    874874  int uytrewq;
    875875  int nva = nvars(basering);
    876   int @k,@s,@n,@k1,zz;
     876  int @k,@s,@n,@k1,@zz;
    877877  list primary,lres0,lres1,act,@lh,@wh;
    878878  map phi,psi,phi1,psi1;
     
    10551055  {
    10561056    poly randp;
    1057     for(zz=1;zz<nvars(basering);zz++)
     1057    for(@zz=1;@zz<nvars(basering);@zz++)
    10581058    {
    10591059      randp=randp
    1060               +(random(0,5)*par(1)^2+random(0,5)*par(1)+random(0,5))*var(zz);
     1060              +(random(0,5)*par(1)^2+random(0,5)*par(1)+random(0,5))*var(@zz);
    10611061    }
    10621062    randp=randp+var(nvars(basering));
     
    10681068    if (size(primary[2*@k])==0)
    10691069    {
    1070       for(zz=1;zz<size(primary[2*@k-1])-1;zz++)
     1070      for(@zz=1;@zz<size(primary[2*@k-1])-1;@zz++)
    10711071      {
    10721072        attrib(primary[2*@k-1],"isSB",1);
    1073         if(vdim(primary[2*@k-1])==deg(primary[2*@k-1][zz]))
     1073        if(vdim(primary[2*@k-1])==deg(primary[2*@k-1][@zz]))
    10741074        {
    10751075          primary[2*@k]=primary[2*@k-1];
     
    10991099        if(deg(lead(primary[2*@k-1][@n]))==1)
    11001100        {
    1101           for(zz=1;zz<=nva;zz++)
     1101          for(@zz=1;@zz<=nva;@zz++)
    11021102          {
    1103             if(lead(primary[2*@k-1][@n])/var(zz)!=0)
     1103            if(lead(primary[2*@k-1][@n])/var(@zz)!=0)
    11041104            {
    1105               jmap1[zz]=-1/leadcoef(primary[2*@k-1][@n])*primary[2*@k-1][@n]
     1105              jmap1[@zz]=-1/leadcoef(primary[2*@k-1][@n])*primary[2*@k-1][@n]
    11061106                   +2/leadcoef(primary[2*@k-1][@n])*lead(primary[2*@k-1][@n]);
    1107               jmap2[zz]=primary[2*@k-1][@n];
    1108               @qht[@n]=var(zz);
     1107              jmap2[@zz]=primary[2*@k-1][@n];
     1108              @qht[@n]=var(@zz);
    11091109            }
    11101110          }
     
    34133413
    34143414  ideal jkeep=@j;
    3415   if(ordstr(@P)[1]=="w")
     3415  if((ordstr(@P)[1]=="w")&&(size(ringlist(@P)[3])==2)) // weighted ordering
    34163416  {
    34173417    list gnir_l=ringlist(gnir);
     
    90239023  int uytrewq;
    90249024  int nva = nvars(basering);
    9025   int @k,@s,@n,@k1,zz;
     9025  int @k,@s,@n,@k1,@zz;
    90269026  list primary,lres0,lres1,act,@lh,@wh;
    90279027  map phi,psi,phi1,psi1;
     
    92069206  {
    92079207    poly randp;
    9208     for(zz=1;zz<nvars(basering);zz++)
     9208    for(@zz=1;@zz<nvars(basering);@zz++)
    92099209    {
    92109210      randp=randp
    9211               +(random(0,5)*par(1)^2+random(0,5)*par(1)+random(0,5))*var(zz);
     9211              +(random(0,5)*par(1)^2+random(0,5)*par(1)+random(0,5))*var(@zz);
    92129212    }
    92139213    randp=randp+var(nvars(basering));
     
    92199219    if (size(primary[2*@k])==0)
    92209220    {
    9221       for(zz=1;zz<size(primary[2*@k-1])-1;zz++)
     9221      for(@zz=1;@zz<size(primary[2*@k-1])-1;@zz++)
    92229222      {
    92239223        attrib(primary[2*@k-1],"isSB",1);
    9224         if(vdim(primary[2*@k-1])==deg(primary[2*@k-1][zz]))
     9224        if(vdim(primary[2*@k-1])==deg(primary[2*@k-1][@zz]))
    92259225        {
    92269226          primary[2*@k]=primary[2*@k-1];
     
    92509250        if(deg(lead(primary[2*@k-1][@n]))==1)
    92519251        {
    9252           for(zz=1;zz<=nva;zz++)
     9252          for(@zz=1;@zz<=nva;@zz++)
    92539253          {
    9254             if(lead(primary[2*@k-1][@n])/var(zz)!=0)
     9254            if(lead(primary[2*@k-1][@n])/var(@zz)!=0)
    92559255            {
    9256               jmap1[zz]=-1/leadcoef(primary[2*@k-1][@n])*primary[2*@k-1][@n]
     9256              jmap1[@zz]=-1/leadcoef(primary[2*@k-1][@n])*primary[2*@k-1][@n]
    92579257                   +2/leadcoef(primary[2*@k-1][@n])*lead(primary[2*@k-1][@n]);
    9258               jmap2[zz]=primary[2*@k-1][@n];
    9259               @qht[@n]=var(zz);
     9258              jmap2[@zz]=primary[2*@k-1][@n];
     9259              @qht[@n]=var(@zz);
    92609260            }
    92619261          }
  • Singular/LIB/rwalk.lib

    • Property mode changed from 100644 to 100755
    r4132ee r654a23  
    1010rwalk(ideal,int,int[,intvec,intvec]);   standard basis of ideal via Random Walk algorithm
    1111rwalk(ideal,int[,intvec,intvec]);       standard basis of ideal via Random Perturbation Walk algorithm
    12 frwalk(ideal,int[,intvec,intvec]);      standard basis of ideal via Random Fractal Walk algorithm
     12frandwalk(ideal,int[,intvec,intvec]);      standard basis of ideal via Random Fractal Walk algorithm
    1313";
    1414
     
    141141 * Random Walk  *
    142142 ****************/
    143 proc rwalk(ideal Go, int radius, int pert_deg, list #)
     143proc rwalk(ideal Go, int radius, int pert_deg, int reduction, int printout, list #)
    144144"SYNTAX: rwalk(ideal i, int radius);
    145145         if size(#)>0 then rwalk(ideal i, int radius, intvec v, intvec w);
     146         intermediate Groebner bases are not reduced if reduction = 0
    146147TYPE:    ideal
    147148PURPOSE: compute the standard basis of the ideal, calculated via
     
    178179
    179180ideal G = fetch(xR, Go);
    180 G = system("Mrwalk", G, curr_weight, target_weight, radius, pert_deg, basering);
     181G = system("Mrwalk", G, curr_weight, target_weight, radius, pert_deg, reduction, printout);
    181182
    182183setring xR;
     
    196197  int radius = 1;
    197198  int perturb_deg = 2;
    198   rwalk(I,radius,perturb_deg);
     199  int reduction = 0;
     200  int printout = 1;
     201  rwalk(I,radius,perturb_deg,reduction,printout);
    199202}
    200203
     
    202205 * Perturbation Walk with random element *
    203206 *****************************************/
    204 proc prwalk(ideal Go, int radius, int o_pert_deg, int t_pert_deg, list #)
     207proc prwalk(ideal Go, int radius, int o_pert_deg, int t_pert_deg, int reduction, int printout, list #)
    205208"SYNTAX: rwalk(ideal i, int radius);
    206209         if size(#)>0 then rwalk(ideal i, int radius, intvec v, intvec w);
     
    227230  OSCTW= OrderStringalp_NP("al", #);
    228231  }
     232int nP = OSCTW[1];
    229233string ord_str = OSCTW[2];
    230234intvec curr_weight = OSCTW[3]; // original weight vector
     
    238242
    239243ideal G = fetch(xR, Go);
    240 G = system("Mprwalk", G, curr_weight, target_weight, radius, o_pert_deg, t_pert_deg, basering);
     244G = system("Mprwalk", G, curr_weight, target_weight, radius, o_pert_deg, t_pert_deg,
     245           nP, reduction, printout);
    241246
    242247setring xR;
     
    257262  int o_perturb_deg = 2;
    258263  int t_perturb_deg = 2;
    259   prwalk(I,radius,o_perturb_deg,t_perturb_deg);
     264  int reduction = 0;
     265  int printout = 2;
     266  prwalk(I,radius,o_perturb_deg,t_perturb_deg,reduction,printout);
    260267}
    261268
     
    263270 * Fractal Walk with random element *
    264271 ************************************/
    265 proc frandwalk(ideal Go, int radius, list #)
    266 "SYNTAX: frwalk(ideal i, int radius);
    267          frwalk(ideal i, int radius, intvec v, intvec w);
     272proc frandwalk(ideal Go, int radius, int reduction, int printout, list #)
     273"SYNTAX: frwalk(ideal i, int radius, int reduction, int printout);
     274         frwalk(ideal i, int radius, int reduction, int printout, intvec v, intvec w);
    268275TYPE:    ideal
    269276PURPOSE: compute the standard basis of the ideal, calculated via
     
    299306   ideal G = fetch(xR, Go);
    300307   int pert_deg = 2;
    301    G = system("Mfrwalk", G, curr_weight, target_weight, radius);
     308
     309   G = system("Mfrwalk", G, curr_weight, target_weight, radius, reduction, printout);
    302310
    303311   setring xR;
     
    314322    ring r = 0,(z,y,x), lp;
    315323    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
    316     frandwalk(I,2);
    317 }
     324    int reduction = 0;
     325    frandwalk(I,2,0,1);
     326}
  • Singular/LIB/surf.lib

    r8d7ca0 r654a23  
    274274
    275275  string surf_call; i = 0;
    276  
     276
    277277  if (isWindows())
    278278  {
     
    303303  else
    304304  {
    305     surf_call = "surfer";   
     305    surf_call = "surfer";
    306306    surf_call = surf_call + " " + l + " >/dev/null 2>&1";
    307307    "Close window to exit from `surfer`.";
    308308    i = system("sh", surf_call);
    309    
    310     if ( (i != 0) && isMacOSX() ) 
     309
     310    if ( (i != 0) && isMacOSX() )
    311311    {
    312312      "*!* Sorry: calling `surfer` failed ['"+surf_call+"']" + newline
    313313      + " (The shell returned the error code " + string(i) + "." + newline
    314       + "But since we are on Mac OS X, let us try to open SURFER.app instead..." + newline 
     314      + "But since we are on Mac OS X, let us try to open SURFER.app instead..." + newline
    315315      + "Appropriate SURFER.app is available for instance at http://www.mathematik.uni-kl.de/~motsak/files/SURFER.dmg";
    316      
     316
    317317      // fallback, will only work if SURFER.app is available (e.g. in /Applications)
    318318      // get SURFER.app e.g. from http://www.mathematik.uni-kl.de/~motsak/files/SURFER.dmg
    319319      // note that the newer (Java-based) variant of Surfer may not support command line usage yet :(
    320      
     320
    321321      surf_call = "open -a SURFER -W --args -t -s";
    322322      surf_call = surf_call + " " + l + " >/dev/null 2>&1";
     
    324324      i = system("sh", surf_call);
    325325    }
    326    
    327    
    328    
     326
     327
     328
    329329  }
    330330  system("sh", "/bin/rm " + l);
     
    381381{
    382382  string s = system("uname");
    383  
     383
    384384  for (int i = 1; i <= size(s)-2; i = i + 1)
    385385  {
  • Singular/LIB/swalk.lib

    • Property mode changed from 100644 to 100755
  • Singular/Makefile.am

    r8d7ca0 r654a23  
    9898   mmalloc.h \
    9999   mod_lib.h \
    100    omSingularConfig.h \
    101100   links/ndbm.h \
    102101   newstruct.h \
  • Singular/blackbox.cc

    r8d7ca0 r654a23  
    5454BOOLEAN blackbox_default_serialize(blackbox */*b*/, void */*d*/, si_link /*f*/)
    5555{
     56  WerrorS("blackbox_serialize is not implemented");
    5657  return TRUE;
    5758}
     
    5960BOOLEAN blackbox_default_deserialize(blackbox **/*b*/, void **/*d*/, si_link /*f*/)
    6061{
     62  WerrorS("blackbox_deserialize is not implemented");
    6163  return TRUE;
    6264}
  • Singular/cntrlc.cc

    r8d7ca0 r654a23  
    55* ABSTRACT - interupt handling
    66*/
    7 #include <kernel/mod2.h>
    8 
    9 /* includes */
    10 #ifdef DecAlpha_OSF1
    11 #define _XOPEN_SOURCE_EXTENDED
    12 #endif /* MP3-Y2 0.022UF */
    13 
    14 #include <omalloc/omalloc.h>
    15 
    16 #include <reporter/si_signals.h>
    17 #include <Singular/fevoices.h>
    18 
    19 #include <Singular/tok.h>
    20 #include <Singular/ipshell.h>
    21 void sig_chld_hdl(int sig); /*#include <Singular/links/ssiLink.h>*/
    22 #include <Singular/cntrlc.h>
    23 #include <Singular/feOpt.h>
    24 #include <Singular/misc_ip.h>
    25 #include <Singular/links/silink.h>
    26 #include <Singular/links/ssiLink.h>
    27 
    287#include <stdio.h>
    298#include <stddef.h>
     
    3312#include <sys/types.h>
    3413#include <sys/wait.h>
     14
     15#include <kernel/mod2.h>
     16
     17#include <omalloc/omalloc.h>
     18
     19#include <reporter/si_signals.h>
     20#include <Singular/fevoices.h>
     21
     22#include <Singular/tok.h>
     23#include <Singular/ipshell.h>
     24#include <Singular/cntrlc.h>
     25#include <Singular/feOpt.h>
     26#include <Singular/misc_ip.h>
     27#include <Singular/links/silink.h>
     28#include <Singular/links/ssiLink.h>
    3529
    3630/* undef, if you don't want GDB to come up on error */
     
    352346      if (feOptValue(FE_OPT_EMACS) == NULL)
    353347      {
    354         fputs("abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);fflush(stderr);
     348        fputs("abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
     349        fflush(stderr);fflush(stdin);
    355350        c = fgetc(stdin);
    356351      }
     
    371366                  fputs("** Warning: Singular should be restarted as soon as possible **\n",stderr);
    372367                  fflush(stderr);
     368                  extern void my_yy_flush();
     369                  my_yy_flush();
     370                  currentVoice=feInitStdin(NULL);
    373371                  longjmp(si_start_jmpbuf,1);
    374372                }
  • Singular/dyn_modules/gfanlib/bbcone.cc

    r8d7ca0 r654a23  
    17391739}
    17401740
    1741 
     1741#if 0
     1742BOOLEAN bbcone_serialize(blackbox *b, void *d, si_link f)
     1743{
     1744  ssiInfo *dd = (ssiInfo *)f->data;
     1745  sleftv l;
     1746  memset(&l,0,sizeof(l));
     1747  l.rtyp=STRING_CMD;
     1748  l.data=(void*)"cone";
     1749  f->m->Write(f, &l);
     1750  gfan::ZCone *Z=((gfan::ZCone*) d;
     1751  /* AMBIENT_DIM */ fprintf(dd->f_write("%d ",Z->ambientDimension());
     1752  /* FACETS or INEQUALITIES */ fprintf(dd->f_write("%d ",Z->areFacetsKnown());
     1753  gfan::ZMatrix i=Z->getInequalities();
     1754....
     1755  /* LINEAR_SPAN or EQUATIONS */ fprintf(dd->f_write("%d ",Z->areImpliedEquationsKnown());
     1756  gfan::ZMatrix e=Z->getEquations();
     1757....
     1758  /* RAYS */
     1759  gfan::ZMatrix r=Z->extremeRays();
     1760....
     1761  /* LINEALITY_SPACE */
     1762  gfan::ZMatrix l=Z->generatorsOfLinealitySpace();
     1763....
     1764  return FALSE;
     1765}
     1766BOOLEAN bbcone_deserialize(blackbox **b, void **d, si_link f)
     1767{
     1768  ssiInfo *dd = (ssiInfo *)f->data;
     1769  gfan::ZCone *Z;
     1770  /* AMBIENT_DIM */ = s_readint(dd->f_read);
     1771  /* areFacetsKnown: */ = s_readint(dd->f_read);
     1772  if (areFacetsKnown)
     1773  ....FACETS
     1774  else
     1775  ....INEQUALITIES
     1776  /* areImpliedEquationsKnown*/ = s_readint(dd->f_read);
     1777  if(areImpliedEquationsKnown)
     1778  ....EQUATIONS
     1779  else
     1780  ...LINEAR_SPAN
     1781  ...RAYS
     1782  ...LINEALITY_SPACE
     1783  *d=Z;
     1784  return FALSE;
     1785}
     1786#endif
    17421787void bbcone_setup(SModulFunctions* p)
    17431788{
     
    17531798  b->blackbox_Assign=bbcone_Assign;
    17541799  b->blackbox_Op2=bbcone_Op2;
     1800  //b->blackbox_serialize=bbcone_serialize;
     1801  //b->blackbox_deserialize=bbcone_deserialize;
    17551802  p->iiAddCproc("","coneViaInequalities",FALSE,coneViaNormals);
    17561803  p->iiAddCproc("","coneViaPoints",FALSE,coneViaRays);
  • Singular/dyn_modules/singmathic/singmathic.cc

    r8d7ca0 r654a23  
    468468  result->rtyp=NONE;
    469469
    470   if (arg == NULL || arg->next != NULL || 
     470  if (arg == NULL || arg->next != NULL ||
    471471  ((arg->Typ() != IDEAL_CMD) &&(arg->Typ() != MODUL_CMD))){
    472472    WerrorS("Syntax: mathicgb(<ideal>/<module>)");
  • Singular/dyn_modules/syzextra/mod_main.cc

    r8d7ca0 r654a23  
    8282    for (int j=0; j<l; j++)
    8383      if (id->m[j] != NULL && p_GetComp(id->m[j], r) > 0)
    84         return TRUE;   
     84        return TRUE;
    8585
    8686    return FALSE; // rank: 1, only zero or no entries? can be an ideal OR module... BUT in the use-case should better be an ideal!
     
    9191
    9292
    93    
     93
    9494
    9595static inline void NoReturn(leftv& res)
     
    15501550  const int iLimit = r->typ[pos].data.is.limit;
    15511551  const ideal F = r->typ[pos].data.is.F;
    1552  
     1552
    15531553  ideal FF = id_Copy(F, r);
    15541554
  • Singular/extra.cc

    r8d7ca0 r654a23  
    37943794    }
    37953795    else
    3796 #endif   
     3796#endif
    37973797/*==================== Error =================*/
    37983798      Werror( "(extended) system(\"%s\",...) %s", sys_cmd, feNotImplemented );
  • Singular/fevoices.cc

    r8d7ca0 r654a23  
    1717#include <Singular/subexpr.h>
    1818#include <Singular/ipshell.h>
     19#include <Singular/sdb.h>
    1920
    2021#include <stdlib.h>
  • Singular/ipassign.cc

    r8d7ca0 r654a23  
    844844  if (res->data!=NULL) idDelete((ideal*)&res->data);
    845845  matrix m=(matrix)a->CopyD(MATRIX_CMD);
     846  if (TEST_V_ALLWARN)
     847    if (MATROWS(m)>1)
     848      Warn("assign matrix with %d rows to an ideal in >>%s<<",MATROWS(m),my_yylinebuf);
    846849  IDELEMS((ideal)m)=MATROWS(m)*MATCOLS(m);
    847850  ((ideal)m)->rank=1;
  • Singular/ipshell.cc

    r8d7ca0 r654a23  
    6565#include <Singular/subexpr.h>
    6666#include <Singular/fevoices.h>
     67#include <Singular/sdb.h>
    6768
    6869#include <math.h>
     
    10291030void iiDebug()
    10301031{
     1032#ifdef HAVE_SDB
     1033  sdb_flags=1;
     1034#endif
    10311035  Print("\n-- break point in %s --\n",VoiceName());
    10321036  if (iiDebugMarker) VoiceBackTrack();
  • Singular/misc_ip.cc

    r8d7ca0 r654a23  
    716716  } while (v!=NULL);
    717717
    718 #ifdef OM_SINGULAR_CONFIG_H
    719718   // set global variable to show memory usage
    720719  extern int om_sing_opt_show_mem;
    721720  if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1;
    722721  else om_sing_opt_show_mem = 0;
    723 #endif
    724722
    725723  return FALSE;
     
    10951093#endif   // HAVE_SIMPLEIPC
    10961094    fe_reset_input_mode();
     1095    monitor(NULL,0);
    10971096#ifdef PAGE_TEST
    10981097    mmEndStat();
  • Singular/scanner.cc

    r8d7ca0 r654a23  
    23302330  //yy_flush_buffer((YY_BUFFER_STATE)oldb);
    23312331}
     2332
     2333void my_yy_flush() { YY_FLUSH_BUFFER;BEGIN(0); }
     2334
  • Singular/scanner.ll

    r8d7ca0 r654a23  
    380380  //yy_flush_buffer((YY_BUFFER_STATE)oldb);
    381381}
     382
     383void my_yy_flush() { YY_FLUSH_BUFFER;BEGIN(0); }
  • Singular/sdb.cc

    r8d7ca0 r654a23  
    244244          "p <var> - display type and value of the variable <var>\n"
    245245          "q <flags> - quit debugger, set debugger flags(0,1,2)\n"
     246          "   0: stop debug, 1:continue, 2: throw an error, return to toplevel\n"
    246247          "Q - quit Singular\n");
    247248          int i;
  • Singular/test.cc

    r8d7ca0 r654a23  
    194194#include <Singular/links/ndbm.h>
    195195#include <Singular/newstruct.h>
    196 #include <Singular/omSingularConfig.h>
    197196#include <Singular/pcv.h>
    198197#include <Singular/links/pipeLink.h>
  • Singular/tesths.cc

    r8d7ca0 r654a23  
    146146  {
    147147    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
    148 #ifdef HAVE_SDB
    149     sdb_flags = 0;
    150 #endif
    151148    dup2(1,2);
    152149    /* alternative:
  • Singular/walk.cc

    • Property mode changed from 100644 to 100755
    r4132ee r654a23  
    1616
    1717//#define TEST_OVERFLOW
    18 //#define CHECK_IDEAL
    19 //#define CHECK_IDEAL_MWALK
     18
     19#define CHECK_IDEAL_MWALK //to print intermediate results
    2020
    2121//#define NEXT_VECTORS_CC
    22 //#define PRINT_VECTORS //to print vectors (sigma, tau, omega)
     22#define PRINT_VECTORS //to print weight vectors
    2323
    2424#define INVEPS_SMALL_IN_FRACTAL  //to choose the small invers of epsilon
     
    2727
    2828#define FIRST_STEP_FRACTAL // to define the first step of the fractal
    29 //#define MSTDCC_FRACTAL // apply Buchberger alg to compute a red GB, if
    30 //                          tau doesn't stay in the correct cone
     29#define MSTDCC_FRACTAL // apply Buchberger alg to compute a red GB, if tau doesn't stay in the correct cone
    3130
    3231//#define TIME_TEST // print the used time of each subroutine
     
    4241#include <Singular/ipshell.h>
    4342#include <Singular/ipconv.h>
     43#include <coeffs/ffields.h>
    4444#include <coeffs/coeffs.h>
    4545#include <Singular/subexpr.h>
     46#include <polys/templates/p_Procs.h>
    4647
    4748#include <polys/monomials/maps.h>
     
    120121 ************************************/
    121122// unused
    122 #if 0
     123/*
    123124static void initSSpecialCC (ideal F, ideal Q, ideal P,kStrategy strat)
    124125{
     
    268269#endif
    269270}
    270 #endif
     271*/
    271272
    272273/*****************
     
    277278  int j;
    278279  kStrategy strat = new skStrategy;
    279 
    280 //  if (TEST_OPT_PROT)
    281 //  {
    282 //    writeTime("start InterRed:");
    283 //    mflush();
    284 //  }
    285   //strat->syzComp     = 0;
     280/*
     281  if (TEST_OPT_PROT)
     282  {
     283    writeTime("start InterRed:");
     284    mflush();
     285  }
     286  strat->syzComp     = 0;
     287*/
    286288  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
    287289  strat->kNoether=pCopy((currRing->ppNoether));
     
    346348    strat->fromQ = NULL;
    347349  }
    348 //  if (TEST_OPT_PROT)
    349 //  {
    350 //    writeTime("end Interred:");
    351 //    mflush();
    352 //  }
     350/*
     351  if (TEST_OPT_PROT)
     352  {
     353    writeTime("end Interred:");
     354    mflush();
     355  }
     356*/
    353357  ideal shdl=strat->Shdl;
    354358  idSkipZeroes(shdl);
     
    358362}
    359363
    360 //unused
    361 #if 0
     364#ifdef TIME_TEST
    362365static void TimeString(clock_t tinput, clock_t tostd, clock_t tif,clock_t tstd,
    363366                       clock_t tlf,clock_t tred, clock_t tnw, int step)
     
    397400        ((((double) xtextra)/1000000)/totm)*100);
    398401}
    399 #endif
    400 
    401 //unused
    402 #if 0
     402
    403403static void TimeStringFractal(clock_t tinput, clock_t tostd, clock_t tif,clock_t tstd,
    404404                       clock_t textra, clock_t tlf,clock_t tred, clock_t tnw)
     
    442442}
    443443#endif
    444 
     444/*
    445445#if defined(CHECK_IDEAL_MWALK) || defined(ENDWALKS)
    446446static void headidString(ideal L, char* st)
     
    496496}
    497497#endif
    498 
     498*/
    499499
    500500static void ivString(intvec* iv, const char* ch)
     
    510510}
    511511
    512 //unused
    513 #if 0
     512#ifdef PRINT_VECTORS
    514513static void MivString(intvec* iva, intvec* ivb, intvec* ivc)
    515514{
     
    558557  }
    559558  return p0;
     559}
     560
     561/*****************************************************************************
     562 * compute the gcd of the entries of the vectors curr_weight and diff_weight *
     563 *****************************************************************************/
     564static int simplify_gcd(intvec* curr_weight, intvec* diff_weight)
     565{
     566  int j;
     567  int nRing = currRing->N;
     568  int gcd_tmp = (*curr_weight)[0];
     569  for (j=1; j<nRing; j++)
     570  {
     571    gcd_tmp = gcd(gcd_tmp, (*curr_weight)[j]);
     572    if(gcd_tmp == 1)
     573    {
     574      break;
     575    }
     576  }
     577  if(gcd_tmp != 1)
     578  {
     579    for (j=0; j<nRing; j++)
     580    {
     581    gcd_tmp = gcd(gcd_tmp, (*diff_weight)[j]);
     582    if(gcd_tmp == 1)
     583      {
     584        break;
     585      }
     586    }
     587  }
     588  return gcd_tmp;
    560589}
    561590
     
    774803  for(i=nG-1; i>=0; i--)
    775804  {
    776     mi = MpolyInitialForm(G->m[i], iv);
    777     gi = G->m[i];
    778 
     805    mi = pHead(MpolyInitialForm(G->m[i], iv));
     806    //Print("\n **// test_w_in_ConeCC: lm(initial)= %s \n",pString(mi));
     807    gi = pHead(G->m[i]);
     808    //Print("\n **// test_w_in_ConeCC: lm(ideal)= %s \n",pString(gi));
    779809    if(mi == NULL)
    780810    {
     
    953983}
    954984
    955 /*****************************************************************************
    956 * create a weight matrix order as intvec of an extra weight vector (a(iv),lp)*
    957 ******************************************************************************/
     985/*********************************************************************************
     986* create a weight matrix order as intvec of an extra weight vector (a(iv),M(iw)) *
     987**********************************************************************************/
    958988intvec* MivMatrixOrderRefine(intvec* iv, intvec* iw)
    959989{
    960   assume(iv->length() == iw->length());
    961   int i, nR = iv->length();
    962 
     990  assume((iv->length())*(iv->length()) == iw->length());
     991  int i,j, nR = iv->length();
     992 
    963993  intvec* ivm = new intvec(nR*nR);
    964994
     
    966996  {
    967997    (*ivm)[i] = (*iv)[i];
    968     (*ivm)[i+nR] = (*iw)[i];
    969   }
    970   for(i=2; i<nR; i++)
    971   {
    972     (*ivm)[i*nR+i-2] = 1;
     998  }
     999  for(i=1; i<nR; i++)
     1000  {
     1001    for(j=0; j<nR; j++)
     1002    {
     1003      (*ivm)[j+i*nR] = (*iw)[j+i*nR];
     1004    }
    9731005  }
    9741006  return ivm;
     
    10051037 * print the max total degree and the max coefficient of G                   *
    10061038 *****************************************************************************/
    1007 #if 0
     1039/*
    10081040static void checkComplexity(ideal G, char* cG)
    10091041{
     
    10461078  PrintLn();
    10471079}
    1048 #endif
     1080*/
    10491081
    10501082/*****************************************************************************
     
    10681100  intvec* v_null =  new intvec(nV);
    10691101
    1070 
    10711102  // Check that the perturbed degree is valid
    10721103  if(pdeg > nV || pdeg <= 0)
     
    10821113  }
    10831114  mpz_t *pert_vector = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
    1084   //mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
     1115  mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
    10851116
    10861117  for(i=0; i<nV; i++)
    10871118  {
    10881119    mpz_init_set_si(pert_vector[i], (*ivtarget)[i]);
    1089    // mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]);
     1120    mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]);
    10901121  }
    10911122  // Calculate max1 = Max(A2)+Max(A3)+...+Max(Apdeg),
     
    11671198    }
    11681199  }
     1200
     1201  // 2147483647 is max. integer representation in SINGULAR
     1202  mpz_t sing_int;
     1203  mpz_init_set_ui(sing_int,  2147483647);
     1204
     1205  mpz_t check_int;
     1206  mpz_init_set_ui(check_int,  100000);
     1207
    11691208  mpz_t ztemp;
    11701209  mpz_init(ztemp);
     
    11861225  }
    11871226
    1188   intvec *pert_vector1= new intvec(nV);
    1189   j = 0;
    11901227  for(i=0; i<nV; i++)
    11911228  {
    1192     (* pert_vector1)[i] = mpz_get_si(pert_vector[i]);
    1193     (* pert_vector1)[i] = 0.1*(* pert_vector1)[i];
    1194     (* pert_vector1)[i] = floor((* pert_vector1)[i] + 0.5);
    1195     if((* pert_vector1)[i] == 0)
    1196     {
    1197       j++;
    1198     }
    1199   }
    1200   if(j > nV - 1)
    1201   {
    1202     // Print("\n//  MPertVectors: geaenderter vector gleich Null! \n");
    1203     delete pert_vector1;
    1204     goto CHECK_OVERFLOW;
    1205   }
    1206 
    1207 // check that the perturbed weight vector lies in the Groebner cone
    1208   if(test_w_in_ConeCC(G,pert_vector1) != 0)
    1209   {
    1210     // Print("\n//  MPertVectors: geaenderter vector liegt in Groebnerkegel! \n");
     1229    if(mpz_cmp(pert_vector[i], check_int)>=0)
     1230    {
     1231      for(j=0; j<nV; j++)
     1232      {
     1233        mpz_fdiv_q_ui(pert_vector1[j], pert_vector[j], 100);
     1234      }
     1235    }
     1236  }
     1237
     1238  intvec* result = new intvec(nV);
     1239
     1240  int ntrue=0;
     1241
     1242  for(i=0; i<nV; i++)
     1243  {
     1244    (*result)[i] = mpz_get_si(pert_vector1[i]);
     1245    if(mpz_cmp(pert_vector1[i], sing_int)>=0)
     1246    {
     1247      ntrue++;
     1248    }
     1249  }
     1250  if(ntrue > 0 || test_w_in_ConeCC(G,result)==0)
     1251  {
     1252    ntrue=0;
    12111253    for(i=0; i<nV; i++)
    12121254    {
    1213       mpz_set_si(pert_vector[i], (*pert_vector1)[i]);
    1214     }
    1215   }
    1216   else
    1217   {
    1218     //Print("\n// MpertVectors: geaenderter vector liegt nicht in Groebnerkegel! \n");
    1219   }
    1220   delete pert_vector1;
    1221 
    1222   CHECK_OVERFLOW:
    1223   intvec* result = new intvec(nV);
    1224 
    1225   /* 2147483647 is max. integer representation in SINGULAR */
    1226   mpz_t sing_int;
    1227   mpz_init_set_ui(sing_int,  2147483647);
    1228 
    1229   int ntrue=0;
    1230   for(i=0; i<nV; i++)
    1231   {
    1232     (*result)[i] = mpz_get_si(pert_vector[i]);
    1233     if(mpz_cmp(pert_vector[i], sing_int)>=0)
    1234     {
    1235       ntrue++;
    1236       if(Overflow_Error == FALSE)
    1237       {
    1238         Overflow_Error = TRUE;
    1239         PrintS("\n// ** OVERFLOW in \"MPertvectors\": ");
    1240         mpz_out_str( stdout, 10, pert_vector[i]);
    1241         PrintS(" is greater than 2147483647 (max. integer representation)");
    1242         Print("\n//  So vector[%d] := %d is wrong!!", i+1, (*result)[i]);
    1243       }
    1244     }
    1245   }
    1246 
    1247   if(Overflow_Error == TRUE)
    1248   {
    1249     ivString(result, "pert_vector");
    1250     Print("\n// %d element(s) of it is overflow!!", ntrue);
     1255      (*result)[i] = mpz_get_si(pert_vector[i]);
     1256      if(mpz_cmp(pert_vector[i], sing_int)>=0)
     1257      {
     1258        ntrue++;
     1259        if(Overflow_Error == FALSE)
     1260        {
     1261          Overflow_Error = TRUE;
     1262          PrintS("\n// ** OVERFLOW in \"MPertvectors\": ");
     1263          mpz_out_str( stdout, 10, pert_vector[i]);
     1264          PrintS(" is greater than 2147483647 (max. integer representation)");
     1265          Print("\n//  So vector[%d] := %d is wrong!!", i+1, (*result)[i]);
     1266        }
     1267      }
     1268    }
     1269
     1270    if(Overflow_Error == TRUE)
     1271    {
     1272      ivString(result, "pert_vector");
     1273      Print("\n// %d element(s) of it is overflow!!", ntrue);
     1274    }
    12511275  }
    12521276
    12531277  mpz_clear(ztemp);
    12541278  mpz_clear(sing_int);
     1279  mpz_clear(check_int);
    12551280  omFree(pert_vector);
    1256   //omFree(pert_vector1);
     1281  omFree(pert_vector1);
    12571282  mpz_clear(tot_deg);
    12581283  mpz_clear(maxdeg);
     
    14561481
    14571482//unused
    1458 #if 0
     1483/*
    14591484static intvec* MatrixOrderdp(int nV)
    14601485{
     
    14721497  return(ivM);
    14731498}
    1474 #endif
     1499*/
    14751500
    14761501intvec* MivUnit(int nV)
     
    15491574    mpz_cdiv_q_ui(inveps, inveps, nV);
    15501575  }
    1551   //PrintS("\n// choose the \"small\" inverse epsilon!");
     1576  // choose the small inverse epsilon
    15521577#endif
    15531578
     
    15831608
    15841609    for(j=0; j<nV; j++)
    1585       {
     1610    {
    15861611      mpz_init_set(pert_vector[i*nV+j],ivtemp[j]);
    1587       }
    1588   }
    1589 
    1590   /* 2147483647 is max. integer representation in SINGULAR */
     1612    }
     1613  }
     1614
     1615  // 2147483647 is max. integer representation in SINGULAR
    15911616  mpz_t sing_int;
    15921617  mpz_init_set_ui(sing_int,  2147483647);
     
    16111636    mpz_divexact(pert_vector[i], pert_vector[i], ztmp);
    16121637    (* result)[i] = mpz_get_si(pert_vector[i]);
    1613   }
    1614 
    1615   j = 0;
    1616   for(i=0; i<nV; i++)
    1617   {
    1618     (* result1)[i] = mpz_get_si(pert_vector[i]);
    1619     (* result1)[i] = 0.1*(* result1)[i];
    1620     (* result1)[i] = floor((* result1)[i] + 0.5);
    1621     if((* result1)[i] == 0)
    1622     {
    1623       j++;
    1624     }
    1625   }
    1626   if(j > nV - 1)
    1627   {
    1628     // Print("\n//  MfPertwalk: geaenderter vector gleich Null! \n");
    1629     delete result1;
    1630     goto CHECK_OVERFLOW;
    1631   }
    1632 
    1633 // check that the perturbed weight vector lies in the Groebner cone
    1634   if(test_w_in_ConeCC(G,result1) != 0)
    1635   {
    1636     // Print("\n//  MfPertwalk: geaenderter vector liegt in Groebnerkegel! \n");
    1637     delete result;
    1638     result = result1;
    1639     for(i=0; i<nV; i++)
    1640     {
    1641       mpz_set_si(pert_vector[i], (*result1)[i]);
    1642     }
    1643   }
    1644   else
    1645   {
    1646     delete result1;
    1647     // Print("\n// Mfpertwalk: geaenderter vector liegt nicht in Groebnerkegel! \n");
    16481638  }
    16491639
     
    16851675    while(p!=NULL)
    16861676    {
    1687       p_Setm(p,currRing); pIter(p);
     1677      p_Setm(p,currRing);
     1678      pIter(p);
    16881679    }
    16891680  }
     
    17681759
    17691760//unused
    1770 #if 0
     1761/*
    17711762static void checkidealCC(ideal G, char* Ch)
    17721763{
     
    17941785  PrintLn();
    17951786}
    1796 #endif
     1787*/
    17971788
    17981789//unused
    1799 #if 0
     1790/*
    18001791static void HeadidString(ideal L, char* st)
    18011792{
     
    18091800  Print(" %s;\n", pString(pHead(L->m[nL])));
    18101801}
    1811 #endif
    1812 
     1802
     1803*/
    18131804static inline int MivComp(intvec* iva, intvec* ivb)
    18141805{
     
    18591850}
    18601851
     1852
     1853/**************************************************************
     1854 * Look for the position of the smallest absolut value in vec *
     1855 **************************************************************/
     1856static int MivAbsMaxArg(intvec* vec)
     1857{
     1858  int k = MivAbsMax(vec);
     1859  int i=0;
     1860  while(1)
     1861  {
     1862    if((*vec)[i] == k || (*vec)[i] == -k)
     1863    {
     1864      break;
     1865    }
     1866    i++;
     1867  }
     1868  return i;
     1869}
     1870
     1871
    18611872/**********************************************************************
    18621873 * Compute a next weight vector between curr_weight and target_weight *
    18631874 * with respect to an ideal <G>.                                      *
    18641875**********************************************************************/
     1876/*
    18651877static intvec* MwalkNextWeightCC(intvec* curr_weight, intvec* target_weight,
    18661878                                 ideal G)
     
    18731885
    18741886  int nRing = currRing->N;
    1875   int checkRed, j, kkk, nG = IDELEMS(G);
     1887  int checkRed, j, nG = IDELEMS(G);
    18761888  intvec* ivtemp;
    18771889
     
    19111923  mpz_init(dcw);
    19121924
    1913   //int tn0, tn1, tz1, ncmp, gcd_tmp, ntmp;
    19141925  int gcd_tmp;
    19151926  intvec* diff_weight = MivSub(target_weight, curr_weight);
     
    19171928  intvec* diff_weight1 = MivSub(target_weight, curr_weight);
    19181929  poly g;
    1919   //poly g, gw;
     1930
    19201931  for (j=0; j<nG; j++)
    19211932  {
     
    19341945        mpz_set_si(MwWd, MivDotProduct(ivtemp, curr_weight));
    19351946        mpz_sub(s_zaehler, deg_w0_p1, MwWd);
    1936 
    19371947        if(mpz_cmp(s_zaehler, t_null) != 0)
    19381948        {
    19391949          mpz_set_si(MwWd, MivDotProduct(ivtemp, diff_weight));
    19401950          mpz_sub(s_nenner, MwWd, deg_d0_p1);
    1941 
    19421951          // check for 0 < s <= 1
    19431952          if( (mpz_cmp(s_zaehler,t_null) > 0 &&
     
    19791988    }
    19801989  }
    1981 //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
     1990  //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
    19821991  mpz_t *vec=(mpz_t*)omAlloc(nRing*sizeof(mpz_t));
    19831992
    19841993
    1985   // there is no 0<t<1 and define the next weight vector that is equal to the current weight vector
     1994  // there is no 0<t<1 and define the next weight vector that is equal
     1995  // to the current weight vector
    19861996  if(mpz_cmp(t_nenner, t_null) == 0)
    19871997  {
    1988     #ifndef SING_NDEBUG
    1989     Print("\n//MwalkNextWeightCC: t_nenner ist Null!");
    1990     #endif
     1998#ifndef SING_NDEBUG
     1999    Print("\n//MwalkNextWeightCC: t_nenner=0\n");
     2000#endif
    19912001    delete diff_weight;
    19922002    diff_weight = ivCopy(curr_weight);//take memory
     
    20542064#endif
    20552065
    2056   //  BOOLEAN isdwpos;
    2057 
    2058   // construct a new weight vector
     2066// construct a new weight vector and check whether vec[j] is overflow,
     2067// i.e. vec[j] > 2^31.
     2068// If vec[j] doesn't overflow, define a weight vector. Otherwise,
     2069// report that overflow appears. In the second case, test whether the
     2070// the correctness of the new vector plays an important role
     2071
    20592072  for (j=0; j<nRing; j++)
    20602073  {
     
    21002113    }
    21012114  }
    2102 
     2115  // reduce the vector with the gcd
     2116  if(mpz_cmp_si(ggt,1) != 0)
     2117  {
     2118    for (j=0; j<nRing; j++)
     2119    {
     2120      mpz_divexact(vec[j], vec[j], ggt);
     2121    }
     2122  }
    21032123#ifdef  NEXT_VECTORS_CC
    21042124  PrintS("\n// gcd of elements of the vector: ");
     
    21062126#endif
    21072127
    2108 /**********************************************************************
    2109 * construct a new weight vector and check whether vec[j] is overflow, *
    2110 * i.e. vec[j] > 2^31.                                                 *
    2111 * If vec[j] doesn't overflow, define a weight vector. Otherwise,      *
    2112 * report that overflow appears. In the second case, test whether the  *
    2113 * the correctness of the new vector plays an important role           *
    2114 **********************************************************************/
    2115   kkk=0;
    21162128  for(j=0; j<nRing; j++)
    2117     {
     2129  {
    21182130    if(mpz_cmp(vec[j], sing_int_half) >= 0)
    2119       {
     2131    {
    21202132      goto REDUCTION;
    2121       }
    2122     }
     2133    }
     2134  }
    21232135  checkRed = 1;
    21242136  for (j=0; j<nRing; j++)
     
    21292141
    21302142  REDUCTION:
     2143  checkRed = 1;
    21312144  for (j=0; j<nRing; j++)
    21322145  {
    2133     (*diff_weight)[j] = mpz_get_si(vec[j]);
    2134   }
    2135   while(MivAbsMax(diff_weight) >= 5)
    2136   {
    2137     for (j=0; j<nRing; j++)
    2138     {
    2139       if(mpz_cmp_si(ggt,1)==0)
    2140       {
    2141         (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
    2142         // Print("\n//  vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
    2143       }
    2144       else
    2145       {
    2146         mpz_divexact(vec[j], vec[j], ggt);
    2147         (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
    2148         // Print("\n//  vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
    2149       }
    2150 /*
    2151       if((*diff_weight1)[j] == 0)
    2152       {
    2153         kkk = kkk + 1;
    2154       }
    2155 */
    2156     }
    2157 
    2158 
    2159 /*
    2160     if(kkk > nRing - 1)
    2161     {
    2162       // diff_weight was reduced to zero
    2163       // Print("\n // MwalkNextWeightCC: geaenderter Vector gleich Null! \n");
    2164       goto TEST_OVERFLOW;
    2165     }
    2166 */
    2167 
    2168     if(test_w_in_ConeCC(G,diff_weight1) != 0)
    2169     {
    2170       Print("\n// MwalkNextWeightCC: geaenderter vector liegt in Groebnerkegel! \n");
    2171       for (j=0; j<nRing; j++)
    2172       {
    2173         (*diff_weight)[j] = (*diff_weight1)[j];
    2174       }
    2175       if(MivAbsMax(diff_weight) < 5)
    2176       {
    2177         checkRed = 1;
    2178         goto SIMPLIFY_GCD;
    2179       }
    2180     }
    2181     else
    2182     {
    2183       // Print("\n// MwalkNextWeightCC: geaenderter vector liegt nicht in Groebnerkegel! \n");
    2184       break;
    2185     }
     2146    (*diff_weight1)[j] = mpz_get_si(vec[j]);
     2147  }
     2148  while(test_w_in_ConeCC(G,diff_weight1))
     2149  {
     2150    for(j=0; j<nRing; j++)
     2151    {
     2152      (*diff_weight)[j] = (*diff_weight1)[j];
     2153      mpz_set_si(vec[j], (*diff_weight)[j]);     
     2154    }
     2155    for(j=0; j<nRing; j++)
     2156    {
     2157      (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
     2158    }
     2159  }
     2160  if(MivAbsMax(diff_weight)>10000)
     2161  {
     2162    for(j=0; j<nRing; j++)
     2163    {
     2164      (*diff_weight1)[j] = (*diff_weight)[j];
     2165    }
     2166    j = 0;
     2167    while(test_w_in_ConeCC(G,diff_weight1))
     2168    {
     2169      (*diff_weight)[j] = (*diff_weight1)[j];
     2170      mpz_set_si(vec[j], (*diff_weight)[j]);
     2171      j = MivAbsMaxArg(diff_weight1);
     2172      (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
     2173    }
     2174    goto SIMPLIFY_GCD;
    21862175  }
    21872176
     
    22222211   mpz_clear(t_null);
    22232212
    2224 
    2225 
    22262213  if(Overflow_Error == FALSE)
    22272214  {
    22282215    Overflow_Error = nError;
    22292216  }
    2230  rComplete(currRing);
    2231   for(kkk=0; kkk<IDELEMS(G);kkk++)
    2232   {
    2233     poly p=G->m[kkk];
     2217  rComplete(currRing);
     2218  for(j=0; j<IDELEMS(G); j++)
     2219  {
     2220    poly p=G->m[j];
    22342221    while(p!=NULL)
    22352222    {
     
    22402227return diff_weight;
    22412228}
     2229*/
     2230/**********************************************************************
     2231 * Compute a next weight vector between curr_weight and target_weight *
     2232 * with respect to an ideal <G>.                                      *
     2233**********************************************************************/
     2234static intvec* MwalkNextWeightCC(intvec* curr_weight, intvec* target_weight,
     2235                                 ideal G)
     2236{
     2237  BOOLEAN nError = Overflow_Error;
     2238  Overflow_Error = FALSE;
     2239
     2240  assume(currRing != NULL && curr_weight != NULL &&
     2241         target_weight != NULL && G != NULL);
     2242
     2243  int nRing = currRing->N;
     2244  int checkRed, j, nG = IDELEMS(G);
     2245  intvec* ivtemp;
     2246
     2247  mpz_t t_zaehler, t_nenner;
     2248  mpz_init(t_zaehler);
     2249  mpz_init(t_nenner);
     2250
     2251  mpz_t s_zaehler, s_nenner, temp, MwWd;
     2252  mpz_init(s_zaehler);
     2253  mpz_init(s_nenner);
     2254  mpz_init(temp);
     2255  mpz_init(MwWd);
     2256
     2257  mpz_t sing_int;
     2258  mpz_init(sing_int);
     2259  mpz_set_si(sing_int,  2147483647);
     2260
     2261  mpz_t sing_int_half;
     2262  mpz_init(sing_int_half);
     2263  mpz_set_si(sing_int_half,  3*(1073741824/2));
     2264
     2265  mpz_t deg_w0_p1, deg_d0_p1;
     2266  mpz_init(deg_w0_p1);
     2267  mpz_init(deg_d0_p1);
     2268
     2269  mpz_t sztn, sntz;
     2270  mpz_init(sztn);
     2271  mpz_init(sntz);
     2272
     2273  mpz_t t_null;
     2274  mpz_init(t_null);
     2275
     2276  mpz_t ggt;
     2277  mpz_init(ggt);
     2278
     2279  mpz_t dcw;
     2280  mpz_init(dcw);
     2281
     2282  int gcd_tmp;
     2283  //intvec* diff_weight = MivSub(target_weight, curr_weight);
     2284
     2285  intvec* diff_weight1 = new intvec(nRing); //MivSub(target_weight, curr_weight);
     2286  poly g;
     2287
     2288  // reduce the size of the entries of the current weight vector
     2289  if(TEST_OPT_REDSB)
     2290  {
     2291    for (j=0; j<nRing; j++)
     2292    {
     2293      (*diff_weight1)[j] = (*curr_weight)[j];
     2294    }
     2295    while(MivAbsMax(diff_weight1)>10000 && test_w_in_ConeCC(G,diff_weight1)==1)
     2296    {
     2297      for(j=0; j<nRing; j++)
     2298      {
     2299        (*curr_weight)[j] = (*diff_weight1)[j]; 
     2300      }
     2301      for(j=0; j<nRing; j++)
     2302      {
     2303        (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
     2304      }
     2305    }
     2306
     2307    if(MivAbsMax(curr_weight)>100000)
     2308    {
     2309      for(j=0; j<nRing; j++)
     2310      {
     2311        (*diff_weight1)[j] = (*curr_weight)[j];
     2312      }
     2313      j = 0;
     2314      while(test_w_in_ConeCC(G,diff_weight1)==1 && MivAbsMax(diff_weight1)>1000)
     2315      {
     2316        (*curr_weight)[j] = (*diff_weight1)[j];
     2317        j = MivAbsMaxArg(diff_weight1);
     2318        (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
     2319      }
     2320    }
     2321
     2322  }
     2323  intvec* diff_weight = MivSub(target_weight, curr_weight);
     2324
     2325  // compute a suitable next weight vector
     2326  for (j=0; j<nG; j++)
     2327  {
     2328    g = G->m[j];
     2329    if (g != NULL)
     2330    {
     2331      ivtemp = MExpPol(g);
     2332      mpz_set_si(deg_w0_p1, MivDotProduct(ivtemp, curr_weight));
     2333      mpz_set_si(deg_d0_p1, MivDotProduct(ivtemp, diff_weight));
     2334      delete ivtemp;
     2335
     2336      pIter(g);
     2337      while (g != NULL)
     2338      {
     2339        ivtemp = MExpPol(g);
     2340        mpz_set_si(MwWd, MivDotProduct(ivtemp, curr_weight));
     2341        mpz_sub(s_zaehler, deg_w0_p1, MwWd);
     2342        if(mpz_cmp(s_zaehler, t_null) != 0)
     2343        {
     2344          mpz_set_si(MwWd, MivDotProduct(ivtemp, diff_weight));
     2345          mpz_sub(s_nenner, MwWd, deg_d0_p1);
     2346          // check for 0 < s <= 1
     2347          if( (mpz_cmp(s_zaehler,t_null) > 0 &&
     2348               mpz_cmp(s_nenner, s_zaehler)>=0) ||
     2349              (mpz_cmp(s_zaehler, t_null) < 0 &&
     2350               mpz_cmp(s_nenner, s_zaehler)<=0))
     2351          {
     2352            // make both positive
     2353            if (mpz_cmp(s_zaehler, t_null) < 0)
     2354            {
     2355              mpz_neg(s_zaehler, s_zaehler);
     2356              mpz_neg(s_nenner, s_nenner);
     2357            }
     2358
     2359            //compute a simple fraction of s
     2360            cancel(s_zaehler, s_nenner);
     2361
     2362            if(mpz_cmp(t_nenner, t_null) != 0)
     2363            {
     2364              mpz_mul(sztn, s_zaehler, t_nenner);
     2365              mpz_mul(sntz, s_nenner, t_zaehler);
     2366
     2367              if(mpz_cmp(sztn,sntz) < 0)
     2368              {
     2369                mpz_add(t_nenner, t_null, s_nenner);
     2370                mpz_add(t_zaehler,t_null, s_zaehler);
     2371              }
     2372            }
     2373            else
     2374            {
     2375              mpz_add(t_nenner, t_null, s_nenner);
     2376              mpz_add(t_zaehler,t_null, s_zaehler);
     2377            }
     2378          }
     2379        }
     2380        pIter(g);
     2381        delete ivtemp;
     2382      }
     2383    }
     2384  }
     2385  //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
     2386  mpz_t *vec=(mpz_t*)omAlloc(nRing*sizeof(mpz_t));
     2387
     2388
     2389  // there is no 0<t<1 and define the next weight vector that is equal
     2390  // to the current weight vector
     2391  if(mpz_cmp(t_nenner, t_null) == 0)
     2392  {
     2393#ifndef SING_NDEBUG
     2394    Print("\n//MwalkNextWeightCC: t_nenner=0\n");
     2395#endif
     2396    delete diff_weight;
     2397    diff_weight = ivCopy(curr_weight);//take memory
     2398    goto FINISH;
     2399  }
     2400
     2401  // define the target vector as the next weight vector, if t = 1
     2402  if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
     2403  {
     2404    delete diff_weight;
     2405    diff_weight = ivCopy(target_weight); //this takes memory
     2406    goto FINISH;
     2407  }
     2408
     2409   //checkRed = 0;
     2410
     2411  SIMPLIFY_GCD:
     2412
     2413  // simplify the vectors curr_weight and diff_weight (C-int)
     2414  gcd_tmp = (*curr_weight)[0];
     2415
     2416  for (j=1; j<nRing; j++)
     2417  {
     2418    gcd_tmp = gcd(gcd_tmp, (*curr_weight)[j]);
     2419    if(gcd_tmp == 1)
     2420    {
     2421      break;
     2422    }
     2423  }
     2424  if(gcd_tmp != 1)
     2425  {
     2426    for (j=0; j<nRing; j++)
     2427    {
     2428      gcd_tmp = gcd(gcd_tmp, (*diff_weight)[j]);
     2429      if(gcd_tmp == 1)
     2430      {
     2431        break;
     2432      }
     2433    }
     2434  }
     2435  if(gcd_tmp != 1)
     2436  {
     2437    for (j=0; j<nRing; j++)
     2438    {
     2439      (*curr_weight)[j] =  (*curr_weight)[j]/gcd_tmp;
     2440      (*diff_weight)[j] =  (*diff_weight)[j]/gcd_tmp;
     2441    }
     2442  }
     2443  if(checkRed > 0)
     2444  {
     2445    for (j=0; j<nRing; j++)
     2446    {
     2447      mpz_set_si(vec[j], (*diff_weight)[j]);
     2448    }
     2449    goto TEST_OVERFLOW;
     2450  }
     2451
     2452#ifdef  NEXT_VECTORS_CC
     2453  Print("\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
     2454  ivString(curr_weight, "new cw");
     2455  ivString(diff_weight, "new dw");
     2456
     2457  PrintS("\n// t_zaehler: ");  mpz_out_str( stdout, 10, t_zaehler);
     2458  PrintS(", t_nenner: ");  mpz_out_str( stdout, 10, t_nenner);
     2459#endif
     2460
     2461// construct a new weight vector and check whether vec[j] is overflow, i.e. vec[j] > 2^31.
     2462// If vec[j] doesn't overflow, define a weight vector. Otherwise, report that overflow
     2463// appears. In the second case, test whether the the correctness of the new vector plays
     2464// an important role
     2465
     2466  for (j=0; j<nRing; j++)
     2467  {
     2468    mpz_set_si(dcw, (*curr_weight)[j]);
     2469    mpz_mul(s_nenner, t_nenner, dcw);
     2470
     2471    if( (*diff_weight)[j]>0)
     2472    {
     2473      mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
     2474    }
     2475    else
     2476    {
     2477      mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
     2478      mpz_neg(s_zaehler, s_zaehler);
     2479    }
     2480    mpz_add(sntz, s_nenner, s_zaehler);
     2481    mpz_init_set(vec[j], sntz);
     2482
     2483#ifdef NEXT_VECTORS_CC
     2484    Print("\n//   j = %d ==> ", j);
     2485    PrintS("(");
     2486    mpz_out_str( stdout, 10, t_nenner);
     2487    Print(" * %d)", (*curr_weight)[j]);
     2488    Print(" + ("); mpz_out_str( stdout, 10, t_zaehler);
     2489    Print(" * %d) =  ",  (*diff_weight)[j]);
     2490    mpz_out_str( stdout, 10, s_nenner);
     2491    PrintS(" + ");
     2492    mpz_out_str( stdout, 10, s_zaehler);
     2493    PrintS(" = "); mpz_out_str( stdout, 10, sntz);
     2494    Print(" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
     2495#endif
     2496
     2497    if(j==0)
     2498    {
     2499      mpz_set(ggt, sntz);
     2500    }
     2501    else
     2502    {
     2503      if(mpz_cmp_si(ggt,1) != 0)
     2504      {
     2505        mpz_gcd(ggt, ggt, sntz);
     2506      }
     2507    }
     2508  }
     2509  // reduce the vector with the gcd
     2510  if(mpz_cmp_si(ggt,1) != 0)
     2511  {
     2512    for (j=0; j<nRing; j++)
     2513    {
     2514      mpz_divexact(vec[j], vec[j], ggt);
     2515    }
     2516  }
     2517#ifdef  NEXT_VECTORS_CC
     2518  PrintS("\n// gcd of elements of the vector: ");
     2519  mpz_out_str( stdout, 10, ggt);
     2520#endif
     2521
     2522  for (j=0; j<nRing; j++)
     2523  {
     2524    (*diff_weight)[j] = mpz_get_si(vec[j]);
     2525  }
     2526
     2527 TEST_OVERFLOW:
     2528
     2529  for (j=0; j<nRing; j++)
     2530  {
     2531    if(mpz_cmp(vec[j], sing_int)>=0)
     2532    {
     2533      if(Overflow_Error == FALSE)
     2534      {
     2535        Overflow_Error = TRUE;
     2536        PrintS("\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
     2537        mpz_out_str( stdout, 10, vec[j]);
     2538        PrintS(" is greater than 2147483647 (max. integer representation)\n");
     2539        Print("//  So vector[%d] := %d is wrong!!\n",j+1, vec[j]);// vec[j] is mpz_t
     2540      }
     2541    }
     2542  }
     2543
     2544 FINISH:
     2545   delete diff_weight1;
     2546   mpz_clear(t_zaehler);
     2547   mpz_clear(t_nenner);
     2548   mpz_clear(s_zaehler);
     2549   mpz_clear(s_nenner);
     2550   mpz_clear(sntz);
     2551   mpz_clear(sztn);
     2552   mpz_clear(temp);
     2553   mpz_clear(MwWd);
     2554   mpz_clear(deg_w0_p1);
     2555   mpz_clear(deg_d0_p1);
     2556   mpz_clear(ggt);
     2557   omFree(vec);
     2558   mpz_clear(sing_int_half);
     2559   mpz_clear(sing_int);
     2560   mpz_clear(dcw);
     2561   mpz_clear(t_null);
     2562
     2563  if(Overflow_Error == FALSE)
     2564  {
     2565    Overflow_Error = nError;
     2566  }
     2567  rComplete(currRing);
     2568  for(j=0; j<IDELEMS(G); j++)
     2569  {
     2570    poly p=G->m[j];
     2571    while(p!=NULL)
     2572    {
     2573      p_Setm(p,currRing);
     2574      pIter(p);
     2575    }
     2576  }
     2577return diff_weight;
     2578}
     2579
    22422580
    22432581/**********************************************************************
     
    22712609}
    22722610
    2273 /**************************************************************
     2611/********************************************************************
    22742612 * define and execute a new ring which order is (a(vb),a(va),lp,C)  *
    2275  * ************************************************************/
    2276 #if 0
    2277 // unused
     2613 * ******************************************************************/
    22782614static void VMrHomogeneous(intvec* va, intvec* vb)
    22792615{
     
    23532689  rChangeCurrRing(r);
    23542690}
    2355 #endif
     2691
    23562692
    23572693/**************************************************************
     
    24282764}
    24292765
    2430 static ring VMrDefault1(intvec* va)
    2431 {
    2432 
    2433   if ((currRing->ppNoether)!=NULL)
    2434   {
    2435     pDelete(&(currRing->ppNoether));
    2436   }
    2437   if (((sLastPrinted.rtyp>BEGIN_RING) && (sLastPrinted.rtyp<END_RING)) ||
    2438       ((sLastPrinted.rtyp==LIST_CMD)&&(lRingDependend((lists)sLastPrinted.data))))
    2439   {
    2440     sLastPrinted.CleanUp();
    2441   }
    2442 
    2443   ring r = (ring) omAlloc0Bin(sip_sring_bin);
    2444   int i, nv = currRing->N;
    2445 
    2446   r->cf  = currRing->cf;
    2447   r->N   = currRing->N;
    2448 
    2449   int nb = 4;
    2450 
    2451   //names
    2452   char* Q; // In order to avoid the corrupted memory, do not change.
    2453   r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
    2454   for(i=0; i<nv; i++)
    2455   {
    2456     Q = currRing->names[i];
    2457     r->names[i]  = omStrDup(Q);
    2458   }
    2459 
    2460   /*weights: entries for 3 blocks: NULL Made:???*/
    2461   r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
    2462   r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
    2463   for(i=0; i<nv; i++)
    2464     r->wvhdl[0][i] = (*va)[i];
    2465 
    2466   /* order: a,lp,C,0 */
    2467   r->order = (int *) omAlloc(nb * sizeof(int *));
    2468   r->block0 = (int *)omAlloc0(nb * sizeof(int *));
    2469   r->block1 = (int *)omAlloc0(nb * sizeof(int *));
    2470 
    2471   // ringorder a for the first block: var 1..nv
    2472   r->order[0]  = ringorder_a;
    2473   r->block0[0] = 1;
    2474   r->block1[0] = nv;
    2475 
    2476   // ringorder lp for the second block: var 1..nv
    2477   r->order[1]  = ringorder_lp;
    2478   r->block0[1] = 1;
    2479   r->block1[1] = nv;
    2480 
    2481   // ringorder C for the third block
    2482   // it is very important within "idLift",
    2483   // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
    2484   // therefore, nb  must be (nBlocks(currRing)  + 1)
    2485   r->order[2]  = ringorder_C;
    2486 
    2487   // the last block: everything is 0
    2488   r->order[3]  = 0;
    2489 
    2490   // polynomial ring
    2491   r->OrdSgn    = 1;
    2492 
    2493   // complete ring intializations
    2494 
    2495   rComplete(r);
    2496 
    2497   //rChangeCurrRing(r);
    2498   return r;
    2499 }
    2500 
    25012766/****************************************************************
    25022767 * define and execute a new ring with ordering (a(va),Wp(vb),C) *
    25032768 * **************************************************************/
    2504 
    25052769static ring VMrRefine(intvec* va, intvec* vb)
    25062770{
     
    25762840
    25772841  // complete ring intializations
    2578 
     2842 
    25792843  rComplete(r);
    25802844
     
    28063070}
    28073071
    2808 
    2809 /* define a ring with parameters und change to it */
    2810 /* DefRingPar and DefRingParlp corrupt still memory */
     3072/***************************************************
     3073* define a ring with parameters und change to it   *
     3074* DefRingPar and DefRingParlp corrupt still memory *
     3075****************************************************/
    28113076static void DefRingPar(intvec* va)
    28123077{
     
    29563221}
    29573222
    2958 //unused
    2959 /**************************************************************
    2960  * check wheather one or more components of a vector are zero *
    2961  **************************************************************/
    2962 #if 0
     3223/*************************************************************
     3224 * check whether one or more components of a vector are zero *
     3225 *************************************************************/
    29633226static int isNolVector(intvec* hilb)
    29643227{
     
    29733236  return 0;
    29743237}
    2975 #endif
     3238
     3239/*************************************************************
     3240 * check whether one or more components of a vector are <= 0 *
     3241 *************************************************************/
     3242static int isNegNolVector(intvec* hilb)
     3243{
     3244  int i;
     3245  for(i=hilb->length()-1; i>=0; i--)
     3246  {
     3247    if((* hilb)[i]<=0)
     3248    {
     3249      return 1;
     3250    }
     3251  }
     3252  return 0;
     3253}
     3254
     3255/**************************************************************************
     3256* Gomega is the initial ideal of G w. r. t. the current weight vector     *
     3257* curr_weight. Check whether curr_weight lies on a border of the Groebner *
     3258* cone, i. e. check whether a monomial is divisible by a leading monomial *
     3259***************************************************************************/
     3260static ideal middleOfCone(ideal G, ideal Gomega)
     3261{
     3262  BOOLEAN middle = FALSE;
     3263  int i,j,N = IDELEMS(Gomega);
     3264  poly p,lm,factor1,factor2;
     3265
     3266  ideal Go = idCopy(G);
     3267 
     3268  // check whether leading monomials of G and Gomega coincide
     3269  // and return NULL if not
     3270  for(i=0; i<N; i++)
     3271  {
     3272    if(!pIsConstant(pSub(pCopy(Gomega->m[i]),pCopy(pHead(G->m[i])))))
     3273    {
     3274      idDelete(&Go);
     3275      return NULL;
     3276    }
     3277  }
     3278  for(i=0; i<N; i++)
     3279  {
     3280    for(j=0; j<N; j++)
     3281    {
     3282      if(i!=j)
     3283      {
     3284        p = pCopy(Gomega->m[i]);
     3285        lm = pCopy(Gomega->m[j]);
     3286        pIter(p);
     3287        while(p!=NULL)
     3288        {
     3289          if(pDivisibleBy(lm,p))
     3290          {
     3291            if(middle == FALSE)
     3292            {
     3293              middle = TRUE;
     3294            }
     3295            factor1 = singclap_pdivide(pHead(p),lm,currRing);
     3296            factor2 = pMult(pCopy(factor1),pCopy(Go->m[j]));
     3297            pDelete(&factor1);
     3298            Go->m[i] = pAdd((Go->m[i]),pNeg(pCopy(factor2)));
     3299            pDelete(&factor2);
     3300          }
     3301          pIter(p);
     3302        }
     3303        pDelete(&lm);
     3304        pDelete(&p);
     3305      }
     3306    }
     3307  }
     3308
     3309  if(middle == TRUE)
     3310  {
     3311    return Go;
     3312  }
     3313  idDelete(&Go);
     3314  return NULL;
     3315}
    29763316
    29773317/******************************  Februar 2002  ****************************
     
    31043444    {
    31053445      Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
     3446/*
    31063447      idElements(Gomega, "Gw");
    31073448      headidString(Gomega, "Gw");
     3449*/
    31083450    }
    31093451#endif
     
    31283470    else
    31293471    {