Index: Singular/LIB/multigrading.lib
===================================================================
--- Singular/LIB/multigrading.lib	(revision efa2bca0582609e7d15dda825eb555ede060c868)
+++ Singular/LIB/multigrading.lib	(revision a0bf7951a2fbf51e98a47ec123b5e4a956e86e2f)
@@ -12,5 +12,5 @@
 OVERVIEW: using this library allows one can virtually add multigrading to Singular.
 For more see http://code.google.com/p/convex-singular/wiki/Multigrading
-For theoretical references see: 
+For theoretical references see:
 E. Miller, B. Sturmfels: 'Combinatorial Commutative Algebra' and
 M. Kreuzer, L. Robbiano: 'Computational Commutative Algebra'.
@@ -62,5 +62,5 @@
 PURPOSE: attaches weights of variables and torsion to the basering.
 NOTE: M encodes the weights of variables column-wise.
-The torsion is given by the lattice spanned by the columns of the integer 
+The torsion is given by the lattice spanned by the columns of the integer
 matrix T in Z^nrows(M) over Z.
 RETURN: nothing
@@ -74,5 +74,5 @@
 
   attrib(basering, attrMgrad, M);
-  
+
   if( size(#) > 0 and typeof(#[1]) == "intmat" )
   {
@@ -85,7 +85,7 @@
   if( nrows(T) == nrows(M) )
   {
-    attrib(basering, attrTorsion, T);  
+    attrib(basering, attrTorsion, T);
     def H;
-    attrib(basering, attrTorsionHNF, H);        
+    attrib(basering, attrTorsionHNF, H);
   }
   else
@@ -97,5 +97,5 @@
 {
   "EXAMPLE:"; echo=2;
-   
+
   ring R = 0, (x, y, z), dp;
 
@@ -109,7 +109,7 @@
   intmat L[3][2] =
     1, 1,
-    1, 3, 
+    1, 3,
     1, 5;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M, L); // Grading: Z^3/L
@@ -131,5 +131,5 @@
   getTorsion(basering, "hermite") == H;
 
-  
+
 
   kill L, M;
@@ -146,5 +146,5 @@
     0,
     2;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
@@ -166,5 +166,5 @@
   intmat L[1][1] =
     0;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M); // Grading: Z^3
@@ -207,10 +207,10 @@
   def M = attrib(R, attrMgrad);
   if( typeof(M) == "intmat"){ return (M); }
-  ERROR( "Sorry no multigrading matrix!" );  
+  ERROR( "Sorry no multigrading matrix!" );
 }
 example
 {
   "EXAMPLE:"; echo=2;
-   
+
   ring R = 0, (x, y, z), dp;
 
@@ -224,7 +224,7 @@
   intmat L[3][2] =
     1, 1,
-    1, 3, 
+    1, 3,
     1, 5;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M, L); // Grading: Z^3/L
@@ -246,5 +246,5 @@
     0,
     2;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
@@ -264,5 +264,5 @@
   intmat L[1][1] =
     0;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M); // Grading: Z^3
@@ -291,6 +291,6 @@
       def R = #[i];
       i++;
-    } 
-  } 
+    }
+  }
 
   if( !defined(R) )
@@ -303,13 +303,13 @@
     if( #[i] == "hermite" )
     {
-      if( typeof(attrib(R, attrTorsionHNF)) != "intmat" ) 
+      if( typeof(attrib(R, attrTorsionHNF)) != "intmat" )
       {
         def M = getTorsion(R);
         if( typeof(M) != "intmat")
-        { 
-          ERROR( "Sorry no torsion matrix!" );  
+        {
+          ERROR( "Sorry no torsion matrix!" );
         }
         attrib(R, attrTorsionHNF, hermite(M)); // this might not work with R != basering...
-      } 
+      }
       return (attrib(R, attrTorsionHNF));
     }
@@ -318,6 +318,6 @@
   def M = attrib(R, attrTorsion);
   if( typeof(M) != "intmat")
-  { 
-    ERROR( "Sorry no torsion matrix!" );  
+  {
+    ERROR( "Sorry no torsion matrix!" );
   }
   return (M);
@@ -326,5 +326,5 @@
 {
   "EXAMPLE:"; echo=2;
-   
+
   ring R = 0, (x, y, z), dp;
 
@@ -338,7 +338,7 @@
   intmat L[3][2] =
     1, 1,
-    1, 3, 
+    1, 3,
     1, 5;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M, L); // Grading: Z^3/L
@@ -363,5 +363,5 @@
     0,
     2;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
@@ -384,5 +384,5 @@
   intmat L[1][1] =
     0;
-   
+
   // attaches M & L to R (==basering):
   setBaseMultigrading(M); // Grading: Z^3
@@ -415,5 +415,5 @@
       return (VV);
     }
-     
+
     ERROR("Sorry: vector or module need module-grading-matrix! See 'getModuleGrading'.");
   }
@@ -428,5 +428,5 @@
     ERROR("Sorry wrong width of V: " + string(ncols(V)));
   }
-   
+
   return (V);
 }
@@ -434,5 +434,5 @@
 {
   "EXAMPLE:"; echo=2;
-   
+
    ring R = 0, (x,y), dp;
    intmat M[2][2]=
@@ -442,23 +442,23 @@
      1,  2,  3,  4, 0,
      0, 10, 20, 30, 1;
-   
+
    setBaseMultigrading(M, T);
-   
+
    ideal I = x, y, xy^5;
    isHomogenous(I);
- 
+
    intmat V = mDeg(I); print(V);
 
    module S = syz(I); print(S);
-   
+
    S = setModuleGrading(S, V);
 
    getModuleGrading(S) == V;
-   
+
    vector v = setModuleGrading(S[1], V);
    getModuleGrading(v) == V;
    isHomogenous(v);
-   print( mDeg(v) );   
-   
+   print( mDeg(v) );
+
    isHomogenous(S);
    print( mDeg(S) );
@@ -469,5 +469,5 @@
 "USAGE: setModuleGrading(m, G), m module/vector, G intmat
 PURPOSE: attaches the multiweights of free module generators to 'm'
-WARNING: The method does not verify that the multigrading makes the 
+WARNING: The method does not verify that the multigrading makes the
          module/vector homogenous. One can do that using isHomogenous(m).
 "
@@ -486,5 +486,5 @@
 {
   "EXAMPLE:"; echo=2;
-   
+
    ring R = 0, (x,y), dp;
    intmat M[2][2]=
@@ -494,24 +494,24 @@
      1,  2,  3,  4, 0,
      0, 10, 20, 30, 1;
-   
+
    setBaseMultigrading(M, T);
-   
+
    ideal I = x, y, xy^5;
    intmat V = mDeg(I);
-   
+
    // V == M; modulo T
    print(V);
 
    module S = syz(I);
-   
+
    S = setModuleGrading(S, V);
    getModuleGrading(S) == V;
 
    print(S);
-   
+
    vector v = S[1]; v = setModuleGrading(v, V);
    getModuleGrading(v) == V;
 
-   print( mDeg(v) );   
+   print( mDeg(v) );
 
    isHomogenous(S);
@@ -544,5 +544,5 @@
 
     if(H[j, i]!=0)
-    { 
+    {
       d=d*H[j, i];
     }
@@ -550,5 +550,5 @@
 
   if( (d*d)==1 )
-  { 
+  {
     return(1==1);
   }
@@ -566,7 +566,7 @@
      1, 2, 3, 4, 0,
      0,10,20,30, 1;
-   
+
    setBaseMultigrading(M,T);
-   
+
    // Is the resulting group torsion free?
    isTorsionFree();
@@ -576,5 +576,5 @@
 
    ring R=0,(x,y,z),dp;
-   intmat A[3][3] = 
+   intmat A[3][3] =
      1,0,0,
      0,1,0,
@@ -626,5 +626,5 @@
 
     if((i+l)>nrows(A)){ break; }
-    
+
     if(A[i+l, i]<0)
     {
@@ -658,5 +658,5 @@
 
               for(k=1;k<=nrows(A);k++)
-              { 
+              {
                 save=A[k, i];
                 A[k, i]=A[k, j];
@@ -668,5 +668,5 @@
             d=a2/A[i+l, i];
             for(k=1;k<=nrows(A);k++)
-            { 
+            {
               A[k, j]=A[k, j]- d*A[k, i];
             }
@@ -689,5 +689,5 @@
   "EXAMPLE:"; echo=2;
 
-   intmat M[2][5] = 
+   intmat M[2][5] =
      1, 2, 3, 4, 0,
      0,10,20,30, 1;
@@ -696,5 +696,5 @@
    print(hermite(M));
 
-   intmat T[3][4] = 
+   intmat T[3][4] =
      3,3,3,3,
      2,1,3,0,
@@ -704,5 +704,5 @@
    print(hermite(T));
 
-   intmat A[4][5] = 
+   intmat A[4][5] =
      1,2,3,2,2,
      1,2,3,4,0,
@@ -738,5 +738,5 @@
 
       if(x!=0)
-      { 
+      {
         return(1==0);
       }
@@ -745,5 +745,5 @@
 
       for( k=1; k <= rr; k++)
-      { 
+      {
         mdeg[k] = mdeg[k] - x*H[k,i];
       }
@@ -779,13 +779,13 @@
   v1;
   isTorsionElement(v1);
-  
+
   intvec v2 = mDeg(a) - mDeg(c);
   v2;
   isTorsionElement(v2);
-  
+
   intvec v3 = mDeg(e) - mDeg(f);
   v3;
   isTorsionElement(v3);
-  
+
   intvec v4 = mDeg(c) - mDeg(d);
   v4;
@@ -797,11 +797,11 @@
 proc defineHomogenous(poly f, list #)
 "USAGE: defineHomogenous(f[, G]); polynomial f, integer matrix G
-PURPOSE: Yields a matrix which has to be appended to the torsion matrix to make the 
+PURPOSE: Yields a matrix which has to be appended to the torsion matrix to make the
 polynomial f homogenous in the grading by grad.
 "
 {
-  if( size(#) > 0 ) 
-  {
-    if( typeof(#[1]) == "intmat" ) 
+  if( size(#) > 0 )
+  {
+    if( typeof(#[1]) == "intmat" )
     {
       intmat grad = #[1];
@@ -833,5 +833,5 @@
 
   ring r =0,(x,y,z),dp;
-  intmat grad[2][3] = 
+  intmat grad[2][3] =
     1,0,1,
     0,1,1;
@@ -844,5 +844,5 @@
   M;
   defineHomogenous(f, grad) == M;
-  
+
   isHomogenous(f);
   setBaseMultigrading(grad, M);
@@ -952,5 +952,5 @@
 
   // Setting degrees for preimage ring.;
-  intmat grad[3][3] = 
+  intmat grad[3][3] =
     1,0,0,
     0,1,0,
@@ -979,5 +979,5 @@
   getVariableWeights();
   getTorsion();
-  
+
   // TODO: Unfortunately this is not a very spectacular example.;
 
@@ -988,7 +988,7 @@
 proc equalMDeg(intvec exp1, intvec exp2, list #)
 "USAGE: equalMDeg(exp1, exp2[, V]); intvec exp1, exp2, intmat V
-PURPOSE: Tests if the exponent vectors of two monomials (given by exp1 and exp2) 
+PURPOSE: Tests if the exponent vectors of two monomials (given by exp1 and exp2)
 represent the same multidegree.
-NOTE: the integer matrix V encodes multidegrees of module components, 
+NOTE: the integer matrix V encodes multidegrees of module components,
 if module component is present in exp1 and exp2
 "
@@ -999,5 +999,5 @@
   }
 
-  if( exp1 == exp2) 
+  if( exp1 == exp2)
   {
     return (1==1);
@@ -1142,5 +1142,5 @@
     def g = groebner(a); // !!!!
 
-    def b, aa; int j; 
+    def b, aa; int j;
     for( int i = ncols(a); i > 0; i-- )
     {
@@ -1162,5 +1162,5 @@
     }
     return(1==1);
-  }  
+  }
 }
 example
@@ -1171,5 +1171,5 @@
 
   //Grading and Torsion matrices:
-  intmat M[3][3] = 
+  intmat M[3][3] =
     1,0,0,
     0,1,0,
@@ -1197,9 +1197,9 @@
   /////////////////////////////////////////////////////////
   // new Torsion matrix:
-  intmat T[3][4] = 
+  intmat T[3][4] =
     3,3,3,3,
     2,1,3,0,
     1,2,0,3;
-  
+
   setBaseMultigrading(M,T);
 
@@ -1208,5 +1208,5 @@
   mDegPartition(f);
 
-  // --------------------- 
+  // ---------------------
   g;
   isHomogenous(g);
@@ -1217,9 +1217,9 @@
   ring R = 0, (x,y,z), dp;
 
-  intmat A[2][3] = 
+  intmat A[2][3] =
     0,0,1,
     3,2,1;
-  intmat T[2][1] = 
-    -1, 
+  intmat T[2][1] =
+    -1,
      4;
   setBaseMultigrading(A, T);
@@ -1233,11 +1233,11 @@
   mDegPartition(x3 -y2z + x2 -y3 + z + 1);
 
-  
+
   module N = gen(1) + (x+y) * gen(2), z*gen(3);
 
   intmat V[2][3] = 0; // 1, 2, 3,  4, 5, 6; //  column-wise weights of components!!??
- 
+
   vector v1, v2;
- 
+
   v1 = setModuleGrading(N[1], V); v1;
   mDegPartition(v1);
@@ -1252,8 +1252,8 @@
   print( mDeg(N) );
 
-  /////////////////////////////////////// 
-
-  V = 
-    1, 2, 3,  
+  ///////////////////////////////////////
+
+  V =
+    1, 2, 3,
     4, 5, 6;
 
@@ -1270,8 +1270,8 @@
   print( mDeg(N) );
 
-  /////////////////////////////////////// 
-
-  V = 
-    0, 0, 0,  
+  ///////////////////////////////////////
+
+  V =
+    0, 0, 0,
     4, 1, 0;
 
@@ -1340,5 +1340,5 @@
     A = A - lead(A);
     while( size(A) > 0 )
-    { 
+    {
       v = leadexp(A); //  v;
       m = max( m, M * v, r ); // ????
@@ -1361,5 +1361,5 @@
     A = A - lead(A);
     while( size(A) > 0 )
-    { 
+    {
       v = leadexp(A); //  v;
 
@@ -1386,5 +1386,5 @@
       {
         G[j, i] = d[j];
-      }      
+      }
     }
     return(G);
@@ -1400,5 +1400,5 @@
       v = setModuleGrading(A[i], V);
 
-      // G[1..r, i] 
+      // G[1..r, i]
       d = mDeg(v);
 
@@ -1406,5 +1406,5 @@
       {
         G[j, i] = d[j];
-      }      
+      }
 
     }
@@ -1412,5 +1412,5 @@
     return(G);
   }
- 
+
 }
 example
@@ -1436,9 +1436,9 @@
 
   setBaseMultigrading(A, Ta);
-  
+
   mDeg( x*x*y );
-  
+
   mDeg( y*y*y*x );
-  
+
   mDeg( x*y + x + 1 );
 
@@ -1450,5 +1450,5 @@
 
 //  "ideal:";
-  
+
   ideal I = y*x*x, x*y*y*y;
   print( mDeg(I) );
@@ -1458,12 +1458,12 @@
 
 //  "vectors:";
-  
+
   intmat B[2][2] = 0, 1, 1, 0;
   print(B);
-  
+
   mDeg( setModuleGrading(y*y*y*gen(2), B ));
   mDeg( setModuleGrading(x*x*gen(1), B ));
 
-  
+
   vector V = x*gen(1) + y*gen(2);
   V = setModuleGrading(V, B);
@@ -1472,15 +1472,15 @@
   vector v1 = setModuleGrading([0, 0, 0], B);
   print( mDeg( v1 ) );
-  
+
   vector v2 = setModuleGrading([0], B);
   print( mDeg( v2 ) );
 
 //  "module:";
-  
+
   module D = x*gen(1), y*gen(2);
   D;
   D = setModuleGrading(D, B);
   print( mDeg( D ) );
-  
+
 
   module DD = [0, 0],[0, 0, 0];
@@ -1504,7 +1504,7 @@
 "
 {
-  if( typeof(p) == "poly" ) 
-  {
-    ideal I;      
+  if( typeof(p) == "poly" )
+  {
+    ideal I;
     poly mp, t, tt;
   }
@@ -1513,5 +1513,5 @@
     if(  typeof(p) == "vector" )
     {
-      module I;      
+      module I;
       vector mp, t, tt;
     }
@@ -1524,5 +1524,5 @@
   if( typeof(p) == "vector" )
   {
-    intmat V = getModuleGrading(p); 
+    intmat V = getModuleGrading(p);
   }
   else
@@ -1531,5 +1531,5 @@
   }
 
-  if( size(p) > 1) 
+  if( size(p) > 1)
   {
     intvec m;
@@ -1538,12 +1538,12 @@
     {
       m = leadexp(p);
-      mp = lead(p); 
+      mp = lead(p);
       p = p - lead(p);
       tt = p; t = 0;
 
       while( size(tt) > 0 )
-      { 
+      {
         // TODO: we make no caching of matrices (M,T,H,V), which remain the same!
-        if( equalMDeg( leadexp(tt), m, V  ) ) 
+        if( equalMDeg( leadexp(tt), m, V  ) )
         {
           mp = mp + lead(tt); // "mp", mp;
@@ -1592,10 +1592,10 @@
 
   mDegPartition(f);
-  
+
   vector v = xy*gen(1)-x3y2*gen(2)+x4y*gen(3);
   intmat B[2][3]=1,-1,-2,0,0,1;
   v = setModuleGrading(v,B);
   getModuleGrading(v);
-  
+
   mDegPartition(v, B);
 }
@@ -1607,5 +1607,5 @@
 {
   intmat A[n][n];
-  
+
   for( int i = n; i > 0; i-- )
   {
@@ -1650,8 +1650,8 @@
 
 
-  if( n > 0) 
-  {
-
-    intmat L[N][n]; 
+  if( n > 0)
+  {
+
+    intmat L[N][n];
     //  list L;
     int j = n;
@@ -1661,5 +1661,5 @@
       p = I[i];
 
-      if( size(p) > 1 ) 
+      if( size(p) > 1 )
       {
         intvec m0 = leadexp(p);
@@ -1676,6 +1676,6 @@
 
     print(L);
-    setBaseMultigrading(A, L);      
-  } 
+    setBaseMultigrading(A, L);
+  }
   else
   {
@@ -1714,5 +1714,5 @@
 
   if( size(#) > 0 and typeof(#[1]) == "intmat" )
-  { 
+  {
     attrib(F, "P", #[1]);
   }
@@ -1850,8 +1850,8 @@
    j=system("sh","hilbert -q -n sing4ti2"); ////////// be quiet + no loggin!!!
 
-   j=system("sh", "awk \'BEGIN{ORS=\",\";}{print $0;}\' sing4ti2.hil " + 
-                "| sed s/[\\\ \\\t\\\v\\\f]/,/g " + 
-                "| sed s/,+/,/g|sed s/,,/,/g " + 
-                "| sed s/,,/,/g " + 
+   j=system("sh", "awk \'BEGIN{ORS=\",\";}{print $0;}\' sing4ti2.hil " +
+                "| sed s/[\\\ \\\t\\\v\\\f]/,/g " +
+                "| sed s/,+/,/g|sed s/,,/,/g " +
+                "| sed s/,,/,/g " +
                 "> sing4ti2.converted" );
    if( defined(keepfiles) <= 0)
@@ -1869,10 +1869,10 @@
    string ergstr = "intvec erglist = " + s + "0;";
    execute(ergstr);
-  
+
    //   print(erglist);
-  
+
    int Rnc = erglist[1];
    int Rnr = erglist[2];
-   
+
    intmat R[Rnr][Rnc];
 
@@ -1940,5 +1940,5 @@
 
 /******************************************************/
-proc mDegBasis(intvec d) 
+proc mDegBasis(intvec d)
 "
 USAGE: multidegree d
@@ -1983,12 +1983,12 @@
 
     intmat AA[nr][nc + 2 * n];
-    AA[1..nr, 1.. nc] = A[1..nr, 1.. nc]; 
-    AA[1..nr, nc + (1.. n)] = T[1..nr, 1.. n]; 
-    AA[1..nr, nc + n + (1.. n)] = -T[1..nr, 1.. n]; 
+    AA[1..nr, 1.. nc] = A[1..nr, 1.. nc];
+    AA[1..nr, nc + (1.. n)] = T[1..nr, 1.. n];
+    AA[1..nr, nc + n + (1.. n)] = -T[1..nr, 1.. n];
 
 
     //      print ( AA );
 
-    intmat K = leftKernelZ(( AA ) ); // 
+    intmat K = leftKernelZ(( AA ) ); //
 
     //      print(K);
@@ -1999,5 +1999,5 @@
     //      "!";
 
-    intmat B = hilbert4ti2intmat(transpose(KK), 1);  
+    intmat B = hilbert4ti2intmat(transpose(KK), 1);
 
     //      "!";      print(B);
@@ -2010,5 +2010,5 @@
 
 
-  int i;  
+  int i;
   int nnr = nrows(B);
   int nnc = ncols(B);
@@ -2069,5 +2069,5 @@
   intvec v1=4,0;
   intvec v2=4,4;
-  
+
   intmat g3[1][2]=1,1;
   setBaseMultigrading(g3);
@@ -2075,10 +2075,10 @@
   v3;
   mDegBasis(v3);
-  
+
   setBaseMultigrading(g1,t);
   mDegBasis(v1);
   setBaseMultigrading(g2);
   mDegBasis(v2);
-  
+
   intmat M[2][2] = 1, -1, -1, 1;
   intvec d = -2, 2;
@@ -2142,11 +2142,11 @@
 PURPOSE: computes the multigraded syzygy of I
 RETURNS: module, the syzygy of I
-NOTE: generators of I must be multigraded homogeneous 
+NOTE: generators of I must be multigraded homogeneous
 "
 {
-  if( isHomogenous(I, "checkGens") == 0) 
-  { 
-    ERROR ("Sorry: inhomogenous input!"); 
-  } 
+  if( isHomogenous(I, "checkGens") == 0)
+  {
+    ERROR ("Sorry: inhomogenous input!");
+  }
   module S = syz(I);
   S = setModuleGrading(S, mDeg(I));
@@ -2156,5 +2156,5 @@
 {
   "EXAMPLE:"; echo=2;
-  
+
 
   ring r = 0,(x,y,z,w),dp;
@@ -2166,12 +2166,12 @@
   setBaseMultigrading(M);
 
-  
+
   module M = ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
-  
- 
+
+
   intmat v[2][nrows(M)]=
     1,
     0;
-  
+
   M = setModuleGrading(M, v);
 
@@ -2191,18 +2191,18 @@
 "USAGE: mDegGroebner(I); I is a poly/vector/ideal/module
 PURPOSE: computes the multigraded standard/groebner basis of I
-NOTE: I must be multigraded homogeneous 
+NOTE: I must be multigraded homogeneous
 RETURNS: ideal/module, the computed basis
 "
 {
-  if( isHomogenous(I) == 0) 
-  { 
-    ERROR ("Sorry: inhomogenous input!"); 
-  } 
+  if( isHomogenous(I) == 0)
+  {
+    ERROR ("Sorry: inhomogenous input!");
+  }
 
   def S = groebner(I);
-  
+
   if( typeof(I) == "module" or typeof(I) == "vector" )
   {
-    S = setModuleGrading(S, getModuleGrading(I));      
+    S = setModuleGrading(S, getModuleGrading(I));
   }
 
@@ -2221,12 +2221,12 @@
   setBaseMultigrading(M);
 
-  
+
   module M = ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
-  
- 
+
+
   intmat v[2][nrows(M)]=
     1,
     0;
-  
+
   M = setModuleGrading(M, v);
 
@@ -2261,6 +2261,6 @@
 proc mDegResolution(def I, int ll, list #)
 "USAGE: mDegResolution(I,l,[f]); I is poly/vector/ideal/module; l,f are integers
-PURPOSE: computes the multigraded resolution of I of the length l, 
-or the whole resolution if l is zero. Returns minimal resolution if an optional 
+PURPOSE: computes the multigraded resolution of I of the length l,
+or the whole resolution if l is zero. Returns minimal resolution if an optional
 argument 1 is supplied
 NOTE: input must have multigraded-homogeneous generators.
@@ -2269,8 +2269,8 @@
 "
 {
-  if( isHomogenous(I, "checkGens") == 0) 
-  { 
-    ERROR ("Sorry: inhomogenous input!"); 
-  } 
+  if( isHomogenous(I, "checkGens") == 0)
+  {
+    ERROR ("Sorry: inhomogenous input!");
+  }
 
   def R = res(I, ll, #); list L = R; int l = size(L);
@@ -2278,8 +2278,8 @@
   if( (typeof(I) == "module") or (typeof(I) == "vector") )
   {
-    L[1] = setModuleGrading(L[1], getModuleGrading(I));      
-  }
-
-  int i; 
+    L[1] = setModuleGrading(L[1], getModuleGrading(I));
+  }
+
+  int i;
   for( i = 2; i <= l; i++ )
   {
@@ -2292,13 +2292,13 @@
     }
   }
- 
+
   return (L);
 
-  
+
 }
 example
 {
   "EXAMPLE:"; echo=2;
-  
+
   ring r = 0,(x,y,z,w),dp;
 
@@ -2309,22 +2309,22 @@
   setBaseMultigrading(M);
 
-  
+
   module m= ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
-  
+
   isHomogenous(ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3), "checkGens");
-  
+
   ideal A = xw-yz, x2z-y3, xz2-y2w, yw2-z3;
 
   int j;
-  
+
   for(j=1; j<=ncols(A); j++)
   {
     mDegPartition(A[j]);
   }
-  
+
   intmat v[2][1]=
     1,
     0;
-  
+
   m = setModuleGrading(m, v);
 
@@ -2353,5 +2353,5 @@
 
   /////////////////////////////////////////////////////////////////////////////
-  
+
   L = mDegResolution(maxideal(1), 0, 1);
 
@@ -2363,7 +2363,7 @@
     "Multigrading: "; print(mDeg(L[j]));
   }
-  
+
   kill v;
-  
+
 
   def h = hilbertSeries(m);
@@ -2372,5 +2372,5 @@
   numerator1;
   factorize(numerator1);
-  
+
   denominator1;
   factorize(denominator1);
@@ -2386,22 +2386,22 @@
 proc hilbertSeries(def I)
 "USAGE: hilbertSeries(I); I is poly/vector/ideal/module
-PURPOSE: computes the multigraded Hilbert Series of M 
-NOTE: input must have multigraded-homogeneous generators. 
+PURPOSE: computes the multigraded Hilbert Series of M
+NOTE: input must have multigraded-homogeneous generators.
 Multigrading should be positive.
-RETURNS: a ring in variables t_(i), s_(i), with polynomials 
-numerator1 and denominator1 and muturally prime numerator2 
+RETURNS: a ring in variables t_(i), s_(i), with polynomials
+numerator1 and denominator1 and muturally prime numerator2
 and denominator2, quotients of which give the series.
 "
 {
-   
+
   if( !isFreeRepresented() )
   {
     ERROR("SORRY: ONLY TORSION-FREE CASE (POSITIVE GRADING)");
   }
-   
+
   int i, j, k, v;
 
   intmat M = getVariableWeights();
-  
+
   int cc = ncols(M);
   int n = nrows(M);
@@ -2415,5 +2415,5 @@
 
   int l = size(RES);
-  
+
   list L; L[l + 1] = 0;
 
@@ -2422,5 +2422,5 @@
     intmat zeros[n][1];
     L[1] = zeros;
-  } 
+  }
   else
   {
@@ -2432,17 +2432,17 @@
     L[j + 1] = mDeg(RES[j]);
   }
-  
+
   l++;
 
   ring R = 0,(t_(1..n),s_(1..n)),dp;
-  
-  ideal units; 
+
+  ideal units;
   for( i=n; i>=1; i--)
   {
     units[i] = (var(i) * var(n + i) - 1);
   }
-  
+
   qring Q = std(units);
-  
+
   // TODO: should not it be a quotient ring depending on Torsion???
   // I am not sure about what to do in the torsion case, but since
@@ -2453,5 +2453,5 @@
   poly monom, summand, numerator;
   poly denominator = 1;
-  
+
   for( i = 1; i <= cc; i++)
   {
@@ -2465,5 +2465,5 @@
       {
         monom = monom * (var(k)^(v));
-      } 
+      }
       else
       {
@@ -2471,5 +2471,5 @@
       }
     }
-    
+
     if( monom == 1)
     {
@@ -2479,6 +2479,6 @@
     denominator = denominator * (1 - monom);
   }
-  
-  for( j = 1; j<= l; j++) 
+
+  for( j = 1; j<= l; j++)
   {
     summand = 0;
@@ -2494,5 +2494,5 @@
         {
           monom = monom * (var(k)^v);
-        } 
+        }
         else
         {
@@ -2504,10 +2504,10 @@
     numerator = numerator - (-1)^j * summand;
   }
-  
+
   if( denominator == 0 )
   {
     ERROR("Multigrading not positive.");
-  } 
-  
+  }
+
   poly denominator1 = denominator;
   poly numerator1 = numerator;
@@ -2543,5 +2543,5 @@
   "The s_(i)-variables are defined to be the inverse of the t_(i)-variables.";
   " ------------ ";
-  
+
   return(Q);
 }
@@ -2549,5 +2549,5 @@
 {
   "EXAMPLE:"; echo=2;
-  
+
   ring r = 0,(x,y,z,w),dp;
   intmat g[2][4]=
@@ -2555,5 +2555,5 @@
     0,1,3,4;
   setBaseMultigrading(g);
-  
+
   module M = ideal(xw-yz, x2z-y3, xz2-y2w, yw2-z3);
   intmat V[2][1]=
@@ -2567,5 +2567,5 @@
   factorize(numerator2);
   factorize(denominator2);
-  
+
   kill g, h; setring r;
 
@@ -2573,7 +2573,7 @@
     1,2,3,4,
     0,0,5,8;
-  
+
   setBaseMultigrading(g);
-  
+
   ideal I = x^2, y, z^3;
   I = std(I);
@@ -2590,5 +2590,5 @@
   mDeg(I);
   def h = hilbertSeries(I); setring h;
-  
+
   factorize(numerator2);
   factorize(denominator2);
@@ -2597,14 +2597,14 @@
   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
-  
+
   ring R = 0,(x,y,z),dp;
-  intmat W[2][3] = 
+  intmat W[2][3] =
      1,1, 1,
      0,0,-1;
   setBaseMultigrading(W);
   ideal I = x3y,yz2,y2z,z4;
-  
+
   def h = hilbertSeries(I); setring h;
-  
+
   factorize(numerator2);
   factorize(denominator2);
@@ -2615,15 +2615,15 @@
 
   ring R = 0,(x,y,z,a,b,c),dp;
-  intmat W[2][6] = 
+  intmat W[2][6] =
      1,1, 1,1,1,1,
      0,0,-1,0,0,0;
   setBaseMultigrading(W);
   ideal I = x3y,yz2,y2z,z4;
-  
+
   def h = hilbertSeries(I); setring h;
-  
+
   factorize(numerator2);
   factorize(denominator2);
-  
+
   kill R, W, h;
 
@@ -2632,7 +2632,7 @@
   ////////////////////////////////////////////////
   // This is example 5.3.9. from Robbianos book.
-  
+
   ring R = 0,(x,y,z,w),dp;
-  intmat W[1][4] = 
+  intmat W[1][4] =
      1,1, 1,1;
   setBaseMultigrading(W);
@@ -2640,7 +2640,7 @@
 
   hilb(std(I));
-  
+
   def h = hilbertSeries(I); setring h;
-  
+
   numerator1;
   denominator1;
@@ -2648,5 +2648,5 @@
   factorize(numerator2);
   factorize(denominator2);
-  
+
 
   kill h;
@@ -2657,5 +2657,5 @@
 
   hilb(std(I2));
-  
+
   def h = hilbertSeries(I2); setring h;
 
@@ -2667,7 +2667,7 @@
   ////////////////////////////////////////////////
   setring R;
-  
+
   W = 2,2,2,2;
-  
+
   setBaseMultigrading(W);
 
@@ -2679,13 +2679,13 @@
 
   kill w;
-  
+
 
   def h = hilbertSeries(I2); setring h;
 
-  
+
   numerator1; denominator1;
   kill h;
 
-  
+
   kill R, W;
 
@@ -2704,5 +2704,5 @@
 
   hilb(std(I));
-  
+
   def h = hilbertSeries(I); setring h;
 
@@ -2720,30 +2720,4 @@
 
   numerator1; denominator1;
-  
-  kill h;  
-  ////////////////////////////////////////////////
-  setring R;
-
-  I = x^5; I;
-
-  hilb(std(I));
-  hilb(std(I), 1);
-
-  def h = hilbertSeries(I); setring h;
-
-  numerator1; denominator1;
-  
-  
-  kill h;  
-  ////////////////////////////////////////////////
-  setring R;
-
-  I = x^10; I;
-
-  hilb(std(I));
-
-  def h = hilbertSeries(I); setring h;
-
-  numerator1; denominator1;
 
   kill h;
@@ -2751,14 +2725,13 @@
   setring R;
 
-  module M = 1;
-
-  M = setModuleGrading(M, W);
-
-  
-  hilb(std(M));
-
-  def h = hilbertSeries(M); setring h;
+  I = x^5; I;
+
+  hilb(std(I));
+  hilb(std(I), 1);
+
+  def h = hilbertSeries(I); setring h;
 
   numerator1; denominator1;
+
 
   kill h;
@@ -2766,15 +2739,9 @@
   setring R;
 
-  kill M; module M = x^5*gen(1);
-
-//  intmat V[1][3] = 0; // TODO: this would lead to a wrong result!!!?
-
-  intmat V[1][1] = 0; // all gen(i) of degree 0!
-
-  M = setModuleGrading(M, V);
-
-  hilb(std(M));
-
-  def h = hilbertSeries(M); setring h;
+  I = x^10; I;
+
+  hilb(std(I));
+
+  def h = hilbertSeries(I); setring h;
 
   numerator1; denominator1;
@@ -2782,17 +2749,14 @@
   kill h;
   ////////////////////////////////////////////////
-  setring R; 
-
-  module N = x^5*gen(3);
-
-  kill V;
-  
-  intmat V[1][3] = 0; // all gen(i) of degree 0!
-
-  N = setModuleGrading(N, V);
-      
-  hilb(std(N));
-
-  def h = hilbertSeries(N); setring h;
+  setring R;
+
+  module M = 1;
+
+  M = setModuleGrading(M, W);
+
+
+  hilb(std(M));
+
+  def h = hilbertSeries(M); setring h;
 
   numerator1; denominator1;
@@ -2800,9 +2764,45 @@
   kill h;
   ////////////////////////////////////////////////
-  setring R; 
-
-  
+  setring R;
+
+  kill M; module M = x^5*gen(1);
+
+//  intmat V[1][3] = 0; // TODO: this would lead to a wrong result!!!?
+
+  intmat V[1][1] = 0; // all gen(i) of degree 0!
+
+  M = setModuleGrading(M, V);
+
+  hilb(std(M));
+
+  def h = hilbertSeries(M); setring h;
+
+  numerator1; denominator1;
+
+  kill h;
+  ////////////////////////////////////////////////
+  setring R;
+
+  module N = x^5*gen(3);
+
+  kill V;
+
+  intmat V[1][3] = 0; // all gen(i) of degree 0!
+
+  N = setModuleGrading(N, V);
+
+  hilb(std(N));
+
+  def h = hilbertSeries(N); setring h;
+
+  numerator1; denominator1;
+
+  kill h;
+  ////////////////////////////////////////////////
+  setring R;
+
+
   module S = M + N;
-  
+
   S = setModuleGrading(S, V);
 
