Index: Singular/LIB/standard.lib
===================================================================
--- Singular/LIB/standard.lib	(revision 45f7bfcca3edf19f70b4d4e83236758f8d71c6da)
+++ Singular/LIB/standard.lib	(revision 6149f4fc52e4155e098c88eb317a7abd5b8d6541)
@@ -1,6 +1,6 @@
-// $Id: standard.lib,v 1.12 1998-05-24 15:50:27 obachman Exp $
-///////////////////////////////////////////////////////////////////////////////
-
-version="$Id: standard.lib,v 1.12 1998-05-24 15:50:27 obachman Exp $";
+// $Id: standard.lib,v 1.13 1998-05-24 16:43:11 obachman Exp $
+//////////////////////////////////////////////////////////////////////////////
+
+version="$Id: standard.lib,v 1.13 1998-05-24 16:43:11 obachman Exp $";
 info="
 LIBRARY: standard.lib   PROCEDURES WHICH ARE ALWAYS LOADED AT START-UP
@@ -12,5 +12,5 @@
 ";
 
-///////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
 
 proc stdfglm (ideal i, list #)
@@ -55,5 +55,5 @@
    i2;
 }
-///////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
 
 proc stdhilb(ideal i,list #)
@@ -122,11 +122,11 @@
    ideal i2=stdhilb(i,v);
 }
-///////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
 
 proc groebner(def i, list #)
-"USAGE: groebner(i) i ideal/module
-RETURNS: standard basis of ideal or module which is computed using a 
+"USAGE: groebner(i[, wait]) i -- ideal/module; wait -- int
+RETURNS: Standard basis of ideal or module which is computed using a 
          heuristically choosen method: 
-         If the ordering of the current ring is a lokal ordering, or
+         If the ordering of the current ring is a local ordering, or
          if it is a non-block ordering and the current ring has no
          parameters, then std(i) is returned.  
@@ -135,7 +135,14 @@
          followed by a Hilbert-series based std computation in the
          original ring.
+NOTE: If a 2nd argument 'wait' is given, then the computation proceeds
+      at most 'wait' seconds. That is, if no result could be computed in 
+      'wait' seconds, then the computation is interrupted, 0 is returned, 
+       a warning message is displayed, and the global variable 
+       'groebner_error' is defined. 
 EXAMPLE: example groebner; shows an example"
 {
   def P=basering;
+
+  // we have two arguments -- try to use MPfork links
   if (size(#) > 0)
   {
@@ -144,18 +151,20 @@
       if (typeof(#[1]) == "int")
       {
-        int wait = #[1];
-        int j, pid;
+        int wait = #[1] * 1000000;
+        int j,k = 10, 0;
         string bs = nameof(basering);
         link l_fork = "MPtcp:fork";
         open(l_fork);
         write(l_fork, quote(system("pid")));
-        pid = read(l_fork);
+        int pid = read(l_fork);
         write(l_fork, quote(groebner(eval(i))));
         
-        for (j=0; j<wait; j++)
+        while(k < wait)
         {
-          if (status(l_fork, "read", "ready", 1)) {break;}
+          if (status(l_fork, "read", "ready", j)) {break;}
+          k = k + j;
+          j = j + j;
         }
-        
+
         if (status(l_fork, "read", "ready"))
         {
@@ -168,4 +177,8 @@
             kill PP;
           }
+          if (defined(groebner_error))
+          {
+            kill(groebner_error);
+          }
           kill (l_fork);
         }
@@ -173,10 +186,10 @@
         {
           ideal result;
+          groebner_error = 1;
           if (! defined(groebner_error))
           {
-            int groebner_error;
+            int groebner_error = 1;
             export groebner_error;
           }
-          groebner_error = 1;
           "// ** groebner did not finish";
           j = system("sh", "kill " + string(pid));
@@ -194,150 +207,151 @@
     }
   }
-   string ordstr_P = ordstr(P);
-
-   if (find(ordstr_P,"s") > 0)
-   {
-     //spaeter den lokalen fall ueber lp oder aehnlich behandeln
-      return(std(i));
-   }
-   
-   int IsSimple_P;
-   if (system("nblocks") <= 2)
-   {
-     if (find(ordstr_P, "M") <= 0)
-     {
-       IsSimple_P = 1;
-     }
-   }
-   int npars_P = npars(P);
-
-   // return std if no parameters and (dp or wp)
-   if ((npars_P == 0) && IsSimple_P)
-   {
-     if (find(ordstr_P, "d") > 0)
-     {
-       return (std(i));
-     }
-     if (find(ordstr_P,"w") > 0)
-     {
-       return (std(i));
-     }
-   }
-
-   // reset options
-   intvec opt=option(get);
-   int p_opt;
-   string s_opt = option();
-   option(none);
-   // turn on option(prot) and/or option(mem), if previously set
-   if (find(s_opt, "prot"))
-   {
-     option(prot);
-     p_opt = 1;
-   }
-   if (find(s_opt, "mem"))
-   {
-     option(mem);
-   }
-   
-   // construct ring in which first std computation is done
-   string varstr_P = varstr(P);
-   string parstr_P = parstr(P);
-   int is_homog = (homog(i) && (npars_P == 0)); 
-   
-   string ri = "ring Phelp =" + string(char(P)) + ",(" + varstr_P;
-   // parameters are converted to ring variables
-   if (npars_P > 0)
-   {
-     ri = ri + "," + parstr_P;
-   }
-   // a homogenizing variable is added, if necessary
-   if (! is_homog)
-   {
-     ri = ri + ",@t";
-   }
-   // ordering is set to (dp, C)
-   ri = ri + "),(dp,C);";
-
-   // change the ring
-   execute(ri);
-   
-   // get ideal from previous ring
-   if (is_homog)
-   {
-     ideal qh = imap(P, i);
-   }
-   else
-   {
-     // and homogenize
-     ideal qh=homog(imap(P,i),@t);
-   }
-   
-   // compute std and hilbert series
-   if (p_opt)
-   {
-     "std in " + ri[13, size(ri) - 13];
-   }
-   ideal qh1=std(qh);
-   intvec hi=hilb(qh1,1);
-
-   if (is_homog && (npars_P == 0))
-   {
-     // no additional variables were introduced
-     setring P; // can immediately change to original ring
-     // simply compute std with hilbert series in original ring
-     if (p_opt)
-     {
-       "std with hilb in basering";
-       i = std(i, hi);
-     }
-   }
-   else
-   {
-     // additional variables were introduced
-     // need another intermediate ring
-     ri = "ring Phelp1 =" + string(char(P)) 
-       + ",(" + varstr(Phelp) + "),(" + ordstr_P;
+
+  // we are still here -- do the actual computation
+  string ordstr_P = ordstr(P);
+  if (find(ordstr_P,"s") > 0)
+  {
+    //spaeter den lokalen fall ueber lp oder aehnlich behandeln
+    return(std(i));
+  }
+   
+  int IsSimple_P;
+  if (system("nblocks") <= 2)
+  {
+    if (find(ordstr_P, "M") <= 0)
+    {
+      IsSimple_P = 1;
+    }
+  }
+  int npars_P = npars(P);
+
+  // return std if no parameters and (dp or wp)
+  if ((npars_P == 0) && IsSimple_P)
+  {
+    if (find(ordstr_P, "d") > 0)
+    {
+      return (std(i));
+    }
+    if (find(ordstr_P,"w") > 0)
+    {
+      return (std(i));
+    }
+  }
+
+  // reset options
+  intvec opt=option(get);
+  int p_opt;
+  string s_opt = option();
+  option(none);
+  // turn on option(prot) and/or option(mem), if previously set
+  if (find(s_opt, "prot"))
+  {
+    option(prot);
+    p_opt = 1;
+  }
+  if (find(s_opt, "mem"))
+  {
+    option(mem);
+  }
+   
+  // construct ring in which first std computation is done
+  string varstr_P = varstr(P);
+  string parstr_P = parstr(P);
+  int is_homog = (homog(i) && (npars_P == 0)); 
+   
+  string ri = "ring Phelp =" + string(char(P)) + ",(" + varstr_P;
+  // parameters are converted to ring variables
+  if (npars_P > 0)
+  {
+    ri = ri + "," + parstr_P;
+  }
+  // a homogenizing variable is added, if necessary
+  if (! is_homog)
+  {
+    ri = ri + ",@t";
+  }
+  // ordering is set to (dp, C)
+  ri = ri + "),(dp,C);";
+
+  // change the ring
+  execute(ri);
+   
+  // get ideal from previous ring
+  if (is_homog)
+  {
+    ideal qh = imap(P, i);
+  }
+  else
+  {
+    // and homogenize
+    ideal qh=homog(imap(P,i),@t);
+  }
+   
+  // compute std and hilbert series
+  if (p_opt)
+  {
+    "std in " + ri[13, size(ri) - 13];
+  }
+  ideal qh1=std(qh);
+  intvec hi=hilb(qh1,1);
+
+  if (is_homog && (npars_P == 0))
+  {
+    // no additional variables were introduced
+    setring P; // can immediately change to original ring
+    // simply compute std with hilbert series in original ring
+    if (p_opt)
+    {
+      "std with hilb in basering";
+      i = std(i, hi);
+    }
+  }
+  else
+  {
+    // additional variables were introduced
+    // need another intermediate ring
+    ri = "ring Phelp1 =" + string(char(P)) 
+      + ",(" + varstr(Phelp) + "),(" + ordstr_P;
      
-     // for lp without parameters, we do not need a block ordering
-     if ( ! (IsSimple_P && (npars_P + is_homog < 2) && find(ordstr_P, "l")))
-     {
-       // need block ordering
-       ri = ri + ", dp(" + string(npars_P + is_homog) + ")";
-     }
-     ri = ri + ");";
+    // for lp without parameters, we do not need a block ordering
+    if ( ! (IsSimple_P && (npars_P + is_homog < 2) && find(ordstr_P, "l")))
+    {
+      // need block ordering
+      ri = ri + ", dp(" + string(npars_P + is_homog) + ")";
+    }
+    ri = ri + ");";
      
-     // change to intermediate ring
-     execute(ri);
-     ideal qh = imap(Phelp, qh);
-     kill Phelp;
-     if (p_opt)
-     {
-       "std with hilb in " + ri[14,size(ri)-14];
-     }
-     // compute std with Hilbert series
-     qh = std(qh, hi);
-     // subst 1 for homogenizing var
-     if (!is_homog)
-     {
-       qh = subst(qh, @t, 1);
-     }
+    // change to intermediate ring
+    execute(ri);
+    ideal qh = imap(Phelp, qh);
+    kill Phelp;
+    if (p_opt)
+    {
+      "std with hilb in " + ri[14,size(ri)-14];
+    }
+    // compute std with Hilbert series
+    qh = std(qh, hi);
+    // subst 1 for homogenizing var
+    if (!is_homog)
+    {
+      qh = subst(qh, @t, 1);
+    }
      
-     // go back to original ring
-     setring P;
-     // get ideal, delete zeros and clean SB
-     i = imap(Phelp1,qh);
-     i = simplify(i, 34);
-     kill Phelp1;
-   }
-
-   // clean-up time
-   option(set, opt);
-   if (find(s_opt, "redSB") > 0)
-   {
-     i=interred(i);
-   }
-   attrib(i, "isSB", 1);
-   return (i);
+    // go back to original ring
+    setring P;
+    // get ideal, delete zeros and clean SB
+    i = imap(Phelp1,qh);
+    i = simplify(i, 34);
+    kill Phelp1;
+  }
+
+  // clean-up time
+  option(set, opt);
+  if (find(s_opt, "redSB") > 0)
+  {
+    i=interred(i);
+  }
+  attrib(i, "isSB", 1);
+  return (i);
 }
 example
@@ -353,4 +367,70 @@
   option(noprot);
   j; simplify(j, 1); std(i);
-}
-
+  if (system("with", "MP")) {groebner(i, 0);}
+  defined(groebner_error);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+proc resu(list #)
+{
+   def P=basering;
+   list result;
+   def m=#[1]; //the ideal or module
+   
+   int i=#[2]; //the length of the resolution
+               //if size(#)>2 a minimal resolution is computed
+
+   //LaScala for the homogeneous case
+   if(homog(m)==1)
+   {
+      resolution re=lres(m,i);
+      if(size(#)>2)
+      {
+         re=minres(re);
+      }
+      return(re);
+   }
+
+   //mres for the global non homogeneous case
+   if(find(ordstr(P),"s")==0)
+   {
+      string ri= "ring Phelp ="
+                  +string(char(P))+",("+varstr_P+"),(dp,C);";
+      execute(ri);
+      def m=imap(P,m);
+      list re=mres(m,i);
+      setring P;
+      result=imap(Phelp,re);
+      return(result);   
+   }
+
+   //sres for the local case and not minimal resolution
+   if(size(#)<=2)
+   {
+      string ri= "ring Phelp ="
+                  +string(char(P))+",("+varstr_P+"),(ls,c);";
+      execute(ri);
+      def m=imap(P,m);
+      m=std(m);
+      list re=sres(m,i);
+      setring P;
+      result=imap(Phelp,re);
+      return(result);
+   }
+
+   //mres for the local case and minimal resolution
+   string ri= "ring Phelp ="
+                  +string(char(P))+",("+varstr_P+"),(ls,C);";
+   execute(ri);
+   def m=imap(P,m);
+   list re=mres(m,i);
+   setring P;
+   result=imap(Phelp,re);
+   return(result);      
+}
+
+proc minresu(list #)
+{
+   return(resu(#[1],#[2],1));
+}
