Index: Singular/walk.cc
===================================================================
--- Singular/walk.cc	(revision 75f460d8b1424a14103e3ee48d499b71e1cb46ee)
+++ Singular/walk.cc	(revision 4083faab6546fc5c3396c90683e190ab3b4d1327)
@@ -429,5 +429,5 @@
 #endif
 
-#ifdef CHECK_IDEAL_MWALK
+//#ifdef CHECK_IDEAL_MWALK
 static void idString(ideal L, const char* st)
 {
@@ -441,5 +441,5 @@
   Print(" %s;", pString(L->m[nL-1]));
 }
-#endif
+//#endif
 
 #if defined(CHECK_IDEAL_MWALK) || defined(ENDWALKS)
@@ -558,4 +558,34 @@
   }
   return p0;
+}
+
+/*****************************************************************************
+ * compute the gcd of the entries of the vectors curr_weight and diff_weight *
+ *****************************************************************************/
+static int simplify_gcd(intvec* curr_weight, intvec* diff_weight)
+{
+  int j;
+  int nRing = currRing->N;
+  int gcd_tmp = (*curr_weight)[0];
+  for (j=1; j<nRing; j++)
+  {
+    gcd_tmp = gcd(gcd_tmp, (*curr_weight)[j]);
+    if(gcd_tmp == 1)
+    {
+      break;
+    }
+  }
+  if(gcd_tmp != 1)
+  {
+    for (j=0; j<nRing; j++)
+    {
+    gcd_tmp = gcd(gcd_tmp, (*diff_weight)[j]);
+    if(gcd_tmp == 1)
+      {
+        break;
+      }
+    }
+  }
+  return gcd_tmp;
 }
 
@@ -953,12 +983,18 @@
 }
 
-/*****************************************************************************
-* create a weight matrix order as intvec of an extra weight vector (a(iv),lp)*
-******************************************************************************/
+/*********************************************************************************
+* create a weight matrix order as intvec of an extra weight vector (a(iv),M(iw)) *
+**********************************************************************************/
 intvec* MivMatrixOrderRefine(intvec* iv, intvec* iw)
 {
+<<<<<<< HEAD
+  assume((iv->length())*(iv->length()) == iw->length());
+  int i,j, nR = iv->length();
+  
+=======
   assume(iv->length() == iw->length());
   int i, nR = iv->length();
 
+>>>>>>> f533f6f7667328bccb271b19b2f603aaebe41596
   intvec* ivm = new intvec(nR*nR);
 
@@ -966,9 +1002,11 @@
   {
     (*ivm)[i] = (*iv)[i];
-    (*ivm)[i+nR] = (*iw)[i];
-  }
-  for(i=2; i<nR; i++)
-  {
-    (*ivm)[i*nR+i-2] = 1;
+  }
+  for(i=1; i<nR; i++)
+  {
+    for(j=0; j<nR; j++)
+    {
+      (*ivm)[j+i*nR] = (*iw)[j+i*nR];
+    }
   }
   return ivm;
@@ -1859,4 +1897,24 @@
 }
 
+
+/**************************************************************
+ * Look for the position of the smallest absolut value in vec *
+ **************************************************************/
+static int MivAbsMaxArg(intvec* vec)
+{
+  int k = MivAbsMax(vec);
+  int i=0;
+  while(1)
+  {
+    if((*vec)[i] == k || (*vec)[i] == -k)
+    {
+      break;
+    }
+    i++;
+  }
+  return i;
+}
+
+
 /**********************************************************************
  * Compute a next weight vector between curr_weight and target_weight *
@@ -1873,5 +1931,5 @@
 
   int nRing = currRing->N;
-  int checkRed, j, kkk, nG = IDELEMS(G);
+  int checkRed, j, nG = IDELEMS(G);
   intvec* ivtemp;
 
@@ -1911,5 +1969,4 @@
   mpz_init(dcw);
 
-  //int tn0, tn1, tz1, ncmp, gcd_tmp, ntmp;
   int gcd_tmp;
   intvec* diff_weight = MivSub(target_weight, curr_weight);
@@ -1917,5 +1974,5 @@
   intvec* diff_weight1 = MivSub(target_weight, curr_weight);
   poly g;
-  //poly g, gw;
+
   for (j=0; j<nG; j++)
   {
@@ -1979,9 +2036,10 @@
     }
   }
-//Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
+  //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
   mpz_t *vec=(mpz_t*)omAlloc(nRing*sizeof(mpz_t));
 
 
-  // there is no 0<t<1 and define the next weight vector that is equal to the current weight vector
+  // there is no 0<t<1 and define the next weight vector that is equal
+  // to the current weight vector
   if(mpz_cmp(t_nenner, t_null) == 0)
   {
@@ -2054,7 +2112,10 @@
 #endif
 
-  //  BOOLEAN isdwpos;
-
-  // construct a new weight vector
+// construct a new weight vector and check whether vec[j] is overflow,
+// i.e. vec[j] > 2^31.
+// If vec[j] doesn't overflow, define a weight vector. Otherwise,
+// report that overflow appears. In the second case, test whether the
+// the correctness of the new vector plays an important role
+
   for (j=0; j<nRing; j++)
   {
@@ -2100,5 +2161,12 @@
     }
   }
-
+  // reduce the vector with the gcd
+  if(mpz_cmp_si(ggt,1) != 0)
+  {
+    for (j=0; j<nRing; j++)
+    {
+      mpz_divexact(vec[j], vec[j], ggt);
+    }
+  }
 #ifdef  NEXT_VECTORS_CC
   PrintS("\n// gcd of elements of the vector: ");
@@ -2106,12 +2174,4 @@
 #endif
 
-/**********************************************************************
-* construct a new weight vector and check whether vec[j] is overflow, *
-* i.e. vec[j] > 2^31.                                                 *
-* If vec[j] doesn't overflow, define a weight vector. Otherwise,      *
-* report that overflow appears. In the second case, test whether the  *
-* the correctness of the new vector plays an important role           *
-**********************************************************************/
-  kkk=0;
   for(j=0; j<nRing; j++)
     {
@@ -2129,59 +2189,36 @@
 
   REDUCTION:
+  checkRed = 1;
   for (j=0; j<nRing; j++)
   {
-    (*diff_weight)[j] = mpz_get_si(vec[j]);
-  }
-  while(MivAbsMax(diff_weight) >= 5)
-  {
-    for (j=0; j<nRing; j++)
-    {
-      if(mpz_cmp_si(ggt,1)==0)
-      {
-        (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
-        // Print("\n//  vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
-      }
-      else
-      {
-        mpz_divexact(vec[j], vec[j], ggt);
-        (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
-        // Print("\n//  vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
-      }
-/*
-      if((*diff_weight1)[j] == 0)
-      {
-        kkk = kkk + 1;
-      }
-*/
-    }
-
-
-/*
-    if(kkk > nRing - 1)
-    {
-      // diff_weight was reduced to zero
-      // Print("\n // MwalkNextWeightCC: geaenderter Vector gleich Null! \n");
-      goto TEST_OVERFLOW;
-    }
-*/
-
-    if(test_w_in_ConeCC(G,diff_weight1) != 0)
-    {
-      Print("\n// MwalkNextWeightCC: geaenderter vector liegt in Groebnerkegel! \n");
-      for (j=0; j<nRing; j++)
-      {
-        (*diff_weight)[j] = (*diff_weight1)[j];
-      }
-      if(MivAbsMax(diff_weight) < 5)
-      {
-        checkRed = 1;
-        goto SIMPLIFY_GCD;
-      }
-    }
-    else
-    {
-      // Print("\n// MwalkNextWeightCC: geaenderter vector liegt nicht in Groebnerkegel! \n");
-      break;
-    }
+    (*diff_weight1)[j] = mpz_get_si(vec[j]);
+  }
+  while(test_w_in_ConeCC(G,diff_weight1))
+  {
+    for(j=0; j<nRing; j++)
+    {
+      (*diff_weight)[j] = (*diff_weight1)[j];
+      mpz_set_si(vec[j], (*diff_weight)[j]);      
+    }
+    for(j=0; j<nRing; j++)
+    {
+      (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
+    }
+  }
+  if(MivAbsMax(diff_weight)>10000)
+  {
+    for(j=0; j<nRing; j++)
+    {
+      (*diff_weight1)[j] = (*diff_weight)[j];
+    }
+    j = 0;
+    while(test_w_in_ConeCC(G,diff_weight1))
+    {
+      (*diff_weight)[j] = (*diff_weight1)[j];
+      mpz_set_si(vec[j], (*diff_weight)[j]);
+      j = MivAbsMaxArg(diff_weight1);
+      (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
+    }
+    goto SIMPLIFY_GCD;
   }
 
@@ -2222,14 +2259,12 @@
    mpz_clear(t_null);
 
-
-
   if(Overflow_Error == FALSE)
   {
     Overflow_Error = nError;
   }
- rComplete(currRing);
-  for(kkk=0; kkk<IDELEMS(G);kkk++)
-  {
-    poly p=G->m[kkk];
+  rComplete(currRing);
+  for(j=0; j<IDELEMS(G); j++)
+  {
+    poly p=G->m[j];
     while(p!=NULL)
     {
@@ -2271,7 +2306,7 @@
 }
 
-/**************************************************************
+/********************************************************************
  * define and execute a new ring which order is (a(vb),a(va),lp,C)  *
- * ************************************************************/
+ * ******************************************************************/
 static void VMrHomogeneous(intvec* va, intvec* vb)
 {
@@ -2425,5 +2460,6 @@
   //rChangeCurrRing(r);
 }
-
+//unused
+#if 0
 static ring VMrDefault1(intvec* va)
 {
@@ -2496,5 +2532,5 @@
   return r;
 }
-
+#endif
 /****************************************************************
  * define and execute a new ring with ordering (a(va),Wp(vb),C) *
@@ -3126,5 +3162,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -3882,5 +3918,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -4143,5 +4179,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -4285,119 +4321,4 @@
 intvec* Xivlp;
 
-#if 0
-/********************************
- * compute a next weight vector *
- ********************************/
-static intvec* MWalkRandomNextWeight(ideal G, intvec* curr_weight, intvec* target_weight, int weight_rad, int pert_deg)
-{
-  int i, weight_norm;
-  int nV = currRing->N;
-  intvec* next_weight2;
-  intvec* next_weight22 = new intvec(nV);
-  intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
-  if(MivComp(next_weight, target_weight) == 1)
-  {
-    return(next_weight);
-  }
-  else
-  {
-    //compute a perturbed next weight vector "next_weight1"
-    intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G, MivMatrixOrder(curr_weight), pert_deg), target_weight, G);
-    //Print("\n // size of next_weight1 = %d", sizeof((*next_weight1)));
-
-    //compute a random next weight vector "next_weight2"
-    while(1)
-    {
-      weight_norm = 0;
-      while(weight_norm == 0)
-      {
-        for(i=0; i<nV; i++)
-        {
-          //Print("\n//  next_weight[%d]  = %d", i, (*next_weight)[i]);
-          (*next_weight22)[i] = rand() % 60000 - 30000;
-          weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
-        }
-        weight_norm = 1 + floor(sqrt(weight_norm));
-      }
-
-      for(i=nV-1; i>=0; i--)
-      {
-        if((*next_weight22)[i] < 0)
-        {
-          (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
-        }
-        else
-        {
-          (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
-        }
-      //Print("\n//  next_weight22[%d]  = %d", i, (*next_weight22)[i]);
-      }
-
-      if(test_w_in_ConeCC(G, next_weight22) == 1)
-      {
-        //Print("\n//MWalkRandomNextWeight: next_weight2 im Kegel\n");
-        next_weight2 = MkInterRedNextWeight(next_weight22, target_weight, G);
-        delete next_weight22;
-        break;
-      }
-    }
-    intvec* result = new intvec(nV);
-    ideal G_test = MwalkInitialForm(G, next_weight);
-    ideal G_test1 = MwalkInitialForm(G, next_weight1);
-    ideal G_test2 = MwalkInitialForm(G, next_weight2);
-
-    // compare next_weights
-    if(IDELEMS(G_test1) < IDELEMS(G_test))
-    {
-      if(IDELEMS(G_test2) <= IDELEMS(G_test1)) // |G_test2| <= |G_test1| < |G_test|
-      {
-        for(i=0; i<nV; i++)
-        {
-          (*result)[i] = (*next_weight2)[i];
-        }
-      }
-      else // |G_test1| < |G_test|, |G_test1| < |G_test2|
-      {
-        for(i=0; i<nV; i++)
-        {
-          (*result)[i] = (*next_weight1)[i];
-        }
-      }
-    }
-    else
-    {
-      if(IDELEMS(G_test2) <= IDELEMS(G_test)) // |G_test2| <= |G_test| <= |G_test1|
-      {
-        for(i=0; i<nV; i++)
-        {
-          (*result)[i] = (*next_weight2)[i];
-        }
-      }
-      else // |G_test| <= |G_test1|, |G_test| < |G_test2|
-      {
-        for(i=0; i<nV; i++)
-        {
-          (*result)[i] = (*next_weight)[i];
-        }
-      }
-    }
-    delete next_weight;
-    delete next_weight1;
-    idDelete(&G_test);
-    idDelete(&G_test1);
-    idDelete(&G_test2);
-    if(test_w_in_ConeCC(G, result) == 1)
-    {
-      delete next_weight2;
-      return result;
-    }
-    else
-    {
-      delete result;
-      return next_weight2;
-    }
-  }
-}
-#endif
 
 /********************************
@@ -4414,5 +4335,4 @@
 
   //compute a perturbed next weight vector "next_weight1"
-  //intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G,MivMatrixOrderRefine(curr_weight,target_weight),pert_deg),target_weight,G);
   intvec* next_weight1 =MkInterRedNextWeight(curr_weight,target_weight,G);
   //compute a random next weight vector "next_weight2"
@@ -4443,4 +4363,18 @@
     {
       next_weight2 = MkInterRedNextWeight(next_weight22,target_weight,G);
+      if(MivAbsMax(next_weight2)>1147483647)
+      {
+        for(i=0; i<nV; i++)
+        {
+          (*next_weight22)[i] = (*next_weight2)[i];
+        }
+        i = 0;
+        while(test_w_in_ConeCC(G,next_weight22))
+        {
+          (*next_weight2)[i] = (*next_weight22)[i];
+          i = MivAbsMaxArg(next_weight22);
+          (*next_weight22)[i] = floor(0.1*(*next_weight22)[i] + 0.5);
+        }
+      }
       delete next_weight22;
       break;
@@ -4573,5 +4507,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
+      rChangeCurrRing(VMrDefault(orig_target_weight));
     }
     TargetRing = currRing;
@@ -4644,5 +4578,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -4753,5 +4687,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
+      rChangeCurrRing(VMrDefault(orig_target_weight));
     }
     F1 = idrMoveR(G, newRing,currRing);
@@ -4784,5 +4718,5 @@
       else
       {
-        rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
+        rChangeCurrRing(VMrDefault(orig_target_weight));
       }
     KSTD_Finish:
@@ -4882,5 +4816,5 @@
       tim = clock();
       /*
-        Print("\n// **** Grï¿œbnerwalk took %d steps and ", nwalk);
+        Print("\n// **** Groebnerwalk took %d steps and ", nwalk);
         PrintS("\n// **** call the rec. Pert. Walk to compute a red GB of:");
         idElements(Gomega, "G_omega");
@@ -4912,5 +4846,5 @@
       oldRing = currRing;
 
-      /* create a new ring newRing */
+      // create a new ring newRing
        if (rParameter(currRing) != NULL)
        {
@@ -4919,5 +4853,5 @@
        else
        {
-         rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
+         rChangeCurrRing(VMrDefault(curr_weight));
        }
       newRing = currRing;
@@ -4945,5 +4879,5 @@
       else
       {
-        rChangeCurrRing(VMrDefault(curr_weight));  //Aenderung
+        rChangeCurrRing(VMrDefault(curr_weight));
       }
       newRing = currRing;
@@ -4957,5 +4891,5 @@
       M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
       delete hilb_func;
-#endif // BUCHBERGER_ALG
+#endif
       tstd = tstd + clock() - to;
 
@@ -4966,5 +4900,7 @@
 
       to = clock();
-      // compute a representation of the generators of submod (M) with respect to those of mod (Gomega). Gomega is a reduced Groebner basis w.r.t. the current ring.
+      // compute a representation of the generators of submod (M) with respect
+      // to those of mod (Gomega).
+      // Gomega is a reduced Groebner basis w.r.t. the current ring.
       F = MLifttwoIdeal(Gomega2, M1, G);
       tlift = tlift + clock() - to;
@@ -5016,5 +4952,5 @@
       else
       {
-        rChangeCurrRing(VMrDefault(target_weight)); // Aenderung
+        rChangeCurrRing(VMrDefault(target_weight));
       }
       F1 = idrMoveR(G, newRing,currRing);
@@ -5063,10 +4999,16 @@
  * THE GROEBNER WALK ALGORITHM *
  *******************************/
-ideal Mwalk(ideal Go, intvec* orig_M, intvec* target_M, ring baseRing)
+ideal Mwalk(ideal Go, intvec* orig_M, intvec* target_M,
+            ring baseRing, int reduction, int printout)
 {
-  BITSET save1 = si_opt_1; // save current options
-  //si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
-  //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
-  //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
+  // save current options
+  BITSET save1 = si_opt_1;
+  if(reduction == 0)
+  {
+    // no reduced Groebner basis
+    si_opt_1 &= (~Sy_bit(OPT_REDSB));
+    // not tail reductions
+    //si_opt_1 &= (~Sy_bit(OPT_REDTAIL));
+  }
   Set_Error(FALSE);
   Overflow_Error = FALSE;
@@ -5109,18 +5051,22 @@
 #endif
   rComplete(currRing);
-#ifdef CHECK_IDEAL_MWALK
-    idString(Go,"Go");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+  if(printout > 2)
+  {
+    idString(Go,"//** Mwalk: Go");
+  }
+//#endif
 #ifdef TIME_TEST
   to = clock();
 #endif
-     if(orig_M->length() == nV)
-      {
-        newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
-      }
-      else
-      {
-        newRing = VMatrDefault(orig_M);
-      }
+  if(orig_M->length() == nV)
+  {
+    // define a new ring with ordering "(a(curr_weight),lp)
+    newRing = VMrDefault(curr_weight);
+  }
+  else
+  {
+    newRing = VMatrDefault(orig_M);
+  }
   rChangeCurrRing(newRing);
   ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
@@ -5138,14 +5084,22 @@
     to = clock();
 #endif
-#ifdef CHECK_IDEAL_MWALK
-    idString(G,"G");
-#endif
-    Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(G,"//** Mwalk: G");
+    }
+//#endif
+    // compute an initial form ideal of <G> w.r.t. "curr_vector"
+    Gomega = MwalkInitialForm(G, curr_weight);
 #ifdef TIME_TEST
-    tif = tif + clock()-to; //time for computing initial form ideal
-#endif
-#ifdef CHECK_IDEAL_MWALK
-    idString(Gomega,"Gomega");
-#endif
+    //time for computing initial form ideal
+    tif = tif + clock()-to;
+#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 1)
+    {
+      idString(Gomega,"//** Mwalk: Gomega");
+    }
+//#endif
 #ifndef  BUCHBERGER_ALG
     if(isNolVector(curr_weight) == 0)
@@ -5162,5 +5116,6 @@
       if(orig_M->length() == nV)
       {
-        newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
+        // define a new ring with ordering "(a(curr_weight),lp)
+        newRing = VMrDefault(curr_weight);
       }
       else
@@ -5173,8 +5128,10 @@
      if(target_M->length() == nV)
      {
-       newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
+       //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
+       newRing = VMrRefine(curr_weight,target_weight);
      }
      else
      {
+       //define a new ring with matrix ordering
        newRing = VMatrRefine(target_M,curr_weight);
      }
@@ -5197,8 +5154,10 @@
 #endif
     idSkipZeroes(M);
-#ifdef CHECK_IDEAL_MWALK
-    PrintS("\n//** Mwalk: computed M.\n");
-    idString(M, "M");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(M, "//** Mwalk: M");
+    }
+//#endif
     //change the ring to baseRing
     rChangeCurrRing(baseRing);
@@ -5210,12 +5169,16 @@
     to = clock();
 #endif
-    // compute a representation of the generators of submod (M) with respect to those of mod (Gomega), where Gomega is a reduced Groebner basis w.r.t. the current ring
+    // compute a representation of the generators of submod (M) with respect to those of mod (Gomega),
+    // where Gomega is a reduced Groebner basis w.r.t. the current ring
     F = MLifttwoIdeal(Gomega2, M1, G);
 #ifdef TIME_TEST
     tlift = tlift + clock() - to;
 #endif
-#ifdef CHECK_IDEAL_MWALK
-    idString(F, "F");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(F, "//** Mwalk: F");
+    }
+//#endif
     idDelete(&Gomega2);
     idDelete(&M1);
@@ -5227,12 +5190,15 @@
     to = clock();
 #endif
-    //G = kStd(F1,NULL,testHomog,NULL,NULL,0,0,NULL);
+
 #ifdef TIME_TEST
     tstd = tstd + clock() - to;
 #endif
     idSkipZeroes(G);
-#ifdef CHECK_IDEAL_MWALK
-    idString(G, "G");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(G, "//** Mwalk: G");
+    }
+//#endif
 #ifdef TIME_TEST
     to = clock();
@@ -5242,12 +5208,18 @@
     tnw = tnw + clock() - to;
 #endif
-#ifdef PRINT_VECTORS
-    MivString(curr_weight, target_weight, next_weight);
-#endif
-    if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)// || test_w_in_ConeCC(G, target_weight) == 1 || MivComp(next_weight,curr_weight) == 1)
-    {
-#ifdef CHECK_IDEAL_MWALK
-      PrintS("\n//** Mwalk: entering last cone.\n");
-#endif
+//#ifdef PRINT_VECTORS
+    if(printout > 0)
+    {
+      MivString(curr_weight, target_weight, next_weight);
+    }
+//#endif
+    if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1 || test_w_in_ConeCC(G, target_weight) == 1)
+    {
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 0)
+      {
+        PrintS("\n//** Mwalk: entering last cone.\n");
+      }
+//#endif
       Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
       if(target_M->length() == nV)
@@ -5262,11 +5234,17 @@
       Gomega1 = idrMoveR(Gomega, baseRing,currRing);
       idDelete(&Gomega);
-#ifdef CHECK_IDEAL_MWALK
-      idString(Gomega1, "Gomega");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 1)
+      {
+        idString(Gomega1, "//** Mwalk: Gomega");
+      }
+//#endif
       M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
-#ifdef CHECK_IDEAL_MWALK
-      idString(M,"M");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 1)
+      {
+        idString(M,"//** Mwalk: M");
+      }
+//#endif
       rChangeCurrRing(baseRing);
       M1 =  idrMoveR(M, newRing,currRing);
@@ -5275,7 +5253,10 @@
       idDelete(&Gomega1);
       F = MLifttwoIdeal(Gomega2, M1, G);
-#ifdef CHECK_IDEAL_MWALK
-      idString(F,"F");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(F,"//** Mwalk: F");
+    }
+//#endif
       idDelete(&Gomega2);
       idDelete(&M1);
@@ -5289,8 +5270,6 @@
       to = clock();
 #endif
- //     if(si_opt_1 == (Sy_bit(OPT_REDSB)))
-  //    {
-        G = kInterRedCC(G,NULL); //reduce the Groebner basis <G> w.r.t. currRing, if option(redSB) is set
-  //    }
+      //interreduce the Groebner basis <G> w.r.t. currRing
+      G = kInterRedCC(G,NULL);
 #ifdef TIME_TEST
       tred = tred + clock() - to;
@@ -5299,11 +5278,5 @@
       delete next_weight;
       break;
-#ifdef CHECK_IDEAL_MWALK
-      PrintS("\n//** Mwalk: last cone.\n");
-#endif
-    }
-#ifdef CHECK_IDEAL_MWALK
-    PrintS("\n//** Mwalk: update weight vectors.\n");
-#endif
+    }
     for(i=nV-1; i>=0; i--)
     {
@@ -5316,7 +5289,4 @@
   ideal result = idrMoveR(G,baseRing,currRing);
   idDelete(&G);
-/*#ifdef CHECK_IDEAL_MWALK
-  pDelete(&p);
-#endif*/
   delete tmp_weight;
   delete ivNull;
@@ -5326,21 +5296,23 @@
 #endif
 #ifdef TIME_TEST
-  Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
   TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
-  Print("\n//** Mwalk: Ergebnis.\n");
   //Print("\n// pSetm_Error = (%d)", ErrorCheck());
   //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
 #endif
+  Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
   return(result);
 }
 
-// 07.11.2012
-// THE RANDOM WALK ALGORITHM  ideal Go, intvec* orig_M, intvec* target_M, ring baseRing
-ideal Mrwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad, int pert_deg, ring baseRing)
+// THE RANDOM WALK ALGORITHM
+ideal Mrwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad, int pert_deg,
+             int reduction, int printout)
 {
   BITSET save1 = si_opt_1; // save current options
-  //si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
-  //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
-  //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
+  if(reduction == 0)
+  {
+    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
+    //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
+    //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
+  }
   Set_Error(FALSE);
   Overflow_Error = FALSE;
@@ -5352,10 +5324,11 @@
 #endif
   nstep=0;
-  int i,nwalk,endwalks = 0;
-  int nV = baseRing->N;
+  int i,polylength,nwalk,endwalks = 0;
+  int nV = currRing->N;
 
   ideal Gomega, M, F, Gomega1, Gomega2, M1; //, F1;
   ring newRing;
-  ring XXRing = baseRing;
+  ring baseRing = currRing;
+  ring XXRing = currRing;
   intvec* ivNull = new intvec(nV);
   intvec* curr_weight = new intvec(nV);
@@ -5363,4 +5336,5 @@
   intvec* exivlp = Mivlp(nV);
   intvec* tmp_weight = new intvec(nV);
+  intvec* next_weight= new intvec(nV);
   for(i=0; i<nV; i++)
   {
@@ -5383,18 +5357,15 @@
 #endif
   rComplete(currRing);
-#ifdef CHECK_IDEAL_MWALK
-    idString(Go,"Go");
-#endif
 #ifdef TIME_TEST
   to = clock();
 #endif
-     if(orig_M->length() == nV)
-      {
-        newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
-      }
-      else
-      {
-        newRing = VMatrDefault(orig_M);
-      }
+  if(orig_M->length() == nV)
+  {
+    newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
+  }
+  else
+  {
+    newRing = VMatrDefault(orig_M);
+  }
   rChangeCurrRing(newRing);
   ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
@@ -5412,14 +5383,22 @@
     to = clock();
 #endif
-#ifdef CHECK_IDEAL_MWALK
-    idString(G,"G");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(G,"//** Mrwalk: G");
+    }
+//#endif
     Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
+    //polylength = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
+    polylength = lengthpoly(Gomega);
 #ifdef TIME_TEST
     tif = tif + clock()-to; //time for computing initial form ideal
 #endif
-#ifdef CHECK_IDEAL_MWALK
-    idString(Gomega,"Gomega");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 1)
+    {
+      idString(Gomega,"//** Mrwalk: Gomega");
+    }
+//#endif
 #ifndef  BUCHBERGER_ALG
     if(isNolVector(curr_weight) == 0)
@@ -5471,8 +5450,10 @@
 #endif
     idSkipZeroes(M);
-#ifdef CHECK_IDEAL_MWALK
-    PrintS("\n//** Mwalk: computed M.\n");
-    idString(M, "M");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(M, "//** Mrwalk: M");
+    }
+//#endif
     //change the ring to baseRing
     rChangeCurrRing(baseRing);
@@ -5484,12 +5465,16 @@
     to = clock();
 #endif
-    // compute a representation of the generators of submod (M) with respect to those of mod (Gomega), where Gomega is a reduced Groebner basis w.r.t. the current ring
+    // compute a representation of the generators of submod (M) with respect to those of mod (Gomega),
+    // where Gomega is a reduced Groebner basis w.r.t. the current ring
     F = MLifttwoIdeal(Gomega2, M1, G);
 #ifdef TIME_TEST
     tlift = tlift + clock() - to;
 #endif
-#ifdef CHECK_IDEAL_MWALK
-    idString(F, "F");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(F, "//** Mrwalk: F");
+    }
+//#endif
     idDelete(&Gomega2);
     idDelete(&M1);
@@ -5500,23 +5485,33 @@
 #ifdef TIME_TEST
     to = clock();
-#endif
-    //G = kStd(F1,NULL,testHomog,NULL,NULL,0,0,NULL);
-#ifdef TIME_TEST
     tstd = tstd + clock() - to;
 #endif
     idSkipZeroes(G);
-#ifdef CHECK_IDEAL_MWALK
-    idString(G, "G");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(G, "//** Mrwalk: G");
+    }
+//#endif
 #ifdef TIME_TEST
     to = clock();
 #endif
-    intvec* next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, pert_deg);//next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
+    next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
+    if(polylength > 0)
+    {
+      //there is a polynomial in Gomega with at least 3 monomials,
+      //low-dimensional facet of the cone
+      delete next_weight;
+      next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, pert_deg);
+    }
 #ifdef TIME_TEST
     tnw = tnw + clock() - to;
 #endif
-#ifdef PRINT_VECTORS
-    MivString(curr_weight, target_weight, next_weight);
-#endif
+//#ifdef PRINT_VECTORS
+    if(printout > 0)
+    {
+      MivString(curr_weight, target_weight, next_weight);
+    }
+//#endif
     if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)// || test_w_in_ConeCC(G, target_weight) == 1 || MivComp(next_weight,curr_weight) == 1)
     {
@@ -5525,4 +5520,10 @@
 #endif
       Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 1)
+      {
+        idString(Gomega, "//** Mrwalk: Gomega");
+      }
+//#endif
       if(target_M->length() == nV)
       {
@@ -5536,11 +5537,11 @@
       Gomega1 = idrMoveR(Gomega, baseRing,currRing);
       idDelete(&Gomega);
-#ifdef CHECK_IDEAL_MWALK
-      idString(Gomega1, "Gomega");
-#endif
       M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
-#ifdef CHECK_IDEAL_MWALK
-      idString(M,"M");
-#endif
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 2)
+      {
+        idString(M,"//** Mrwalk: M");
+      }
+//#endif
       rChangeCurrRing(baseRing);
       M1 =  idrMoveR(M, newRing,currRing);
@@ -5549,7 +5550,4 @@
       idDelete(&Gomega1);
       F = MLifttwoIdeal(Gomega2, M1, G);
-#ifdef CHECK_IDEAL_MWALK
-      idString(F,"F");
-#endif
       idDelete(&Gomega2);
       idDelete(&M1);
@@ -5558,13 +5556,18 @@
       idDelete(&F);
       baseRing = currRing;
-      si_opt_1 = save1; //set original options, e. g. option(RedSB)
       idSkipZeroes(G);
 #ifdef TIME_TEST
       to = clock();
 #endif
- //     if(si_opt_1 == (Sy_bit(OPT_REDSB)))
-  //    {
-        //G = kInterRedCC(G,NULL); //reduce the Groebner basis <G> w.r.t. currRing, if option(redSB) is set
-  //    }
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 2)
+      {
+        idString(G,"//** Mrwalk: G");
+      }
+/*#endif
+      if(si_opt_1 == (Sy_bit(OPT_REDSB)))
+      {*/
+        G = kInterRedCC(G,NULL); //interreduce the Groebner basis <G> w.r.t. currRing
+//      }
 #ifdef TIME_TEST
       tred = tred + clock() - to;
@@ -5573,11 +5576,5 @@
       delete next_weight;
       break;
-#ifdef CHECK_IDEAL_MWALK
-      PrintS("\n//** Mwalk: last cone.\n");
-#endif
-    }
-#ifdef CHECK_IDEAL_MWALK
-    PrintS("\n//** Mwalk: update weight vectors.\n");
-#endif
+    }
     for(i=nV-1; i>=0; i--)
     {
@@ -5587,10 +5584,9 @@
     delete next_weight;
   }
+  baseRing = currRing;
   rChangeCurrRing(XXRing);
   ideal result = idrMoveR(G,baseRing,currRing);
   idDelete(&G);
-/*#ifdef CHECK_IDEAL_MWALK
-  pDelete(&p);
-#endif*/
+  si_opt_1 = save1; //set original options, e. g. option(RedSB)
   delete tmp_weight;
   delete ivNull;
@@ -5599,8 +5595,7 @@
   delete last_omega;
 #endif
+  Print("\n//** Mrwalk: Groebner Walk took %d steps.\n", nstep);
 #ifdef TIME_TEST
-  Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
   TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
-  Print("\n//** Mwalk: Ergebnis.\n");
   //Print("\n// pSetm_Error = (%d)", ErrorCheck());
   //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
@@ -5749,6 +5744,13 @@
 // use kStd, if nP = 0, else call LastGB
 ideal Mpwalk(ideal Go, int op_deg, int tp_deg,intvec* curr_weight,
-             intvec* target_weight, int nP)
+             intvec* target_weight, int nP, int reduction, int printout)
 {
+  BITSET save1 = si_opt_1; // save current options
+  if(reduction == 0)
+  {
+    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
+    //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
+    //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
+  }
   Set_Error(FALSE  );
   Overflow_Error = FALSE;
@@ -5788,7 +5790,6 @@
   ring XXRing = currRing;
 
-
   to = clock();
-  /* perturbs the original vector */
+  // perturbs the original vector
   if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) := "dp"
   {
@@ -5807,5 +5808,5 @@
       DefRingPar(curr_weight);
     else
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 1
+      rChangeCurrRing(VMrDefault(curr_weight));
 
     G = idrMoveR(Go, XXRing,currRing);
@@ -5822,5 +5823,5 @@
   ring HelpRing = currRing;
 
-  /* perturbs the target weight vector */
+  // perturbs the target weight vector
   if(tp_deg > 1 && tp_deg <= nV)
   {
@@ -5828,5 +5829,5 @@
       DefRingPar(target_weight);
     else
-      rChangeCurrRing(VMrDefault(target_weight)); // Aenderung 2
+      rChangeCurrRing(VMrDefault(target_weight));
 
     TargetRing = currRing;
@@ -5850,9 +5851,10 @@
     G = idrMoveR(ssG, TargetRing,currRing);
   }
-  /*
-    Print("\n// Perturbationwalkalg. vom Gradpaar (%d,%d):",op_deg,tp_deg);
-    ivString(curr_weight, "new sigma");
-    ivString(target_weight, "new tau");
-  */
+    if(printout > 0)
+    {
+      Print("\n//** Mpwalk: Perturbation Walk of degree (%d,%d):",op_deg,tp_deg);
+      ivString(curr_weight, "//** Mpwalk: new current weight");
+      ivString(target_weight, "//** Mpwalk: new target weight");
+    }
   while(1)
   {
@@ -5862,13 +5864,17 @@
        "curr_weight" */
     Gomega = MwalkInitialForm(G, curr_weight);
-
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 1)
+      {
+        idString(Gomega,"//** Mpwalk: Gomega");
+      }
+//#endif
 
 #ifdef ENDWALKS
-    if(endwalks == 1){
+    if(endwalks == 1)
+    {
       Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
       idElements(G, "G");
-      // idElements(Gomega, "Gw");
       headidString(G, "G");
-      //headidString(Gomega, "Gw");
     }
 #endif
@@ -5889,5 +5895,5 @@
       DefRingPar(curr_weight);
     else
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 3
+      rChangeCurrRing(VMrDefault(curr_weight));
 
     newRing = currRing;
@@ -5916,5 +5922,11 @@
     M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
     delete hilb_func;
-#endif // BUCHBERGER_ALG
+#endif
+//#ifdef CHECK_IDEAL_MWALK
+      if(printout > 2)
+      {
+        idString(M,"//** Mpwalk: M");
+      }
+//#endif
 
     if(endwalks == 1){
@@ -5932,6 +5944,4 @@
     M1 =  idrMoveR(M, newRing,currRing);
     Gomega2 =  idrMoveR(Gomega1, newRing,currRing);
-
-    //if(endwalks==1)  PrintS("\n// Lifting is working:..");
 
     to=clock();
@@ -5945,4 +5955,11 @@
       xtlift=clock()-to;
 
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(F,"//** Mpwalk: F");
+    }
+//#endif
+
     idDelete(&M1);
     idDelete(&Gomega2);
@@ -5952,6 +5969,4 @@
     rChangeCurrRing(newRing);
     F1 = idrMoveR(F, oldRing,currRing);
-
-    //if(endwalks==1)PrintS("\n// InterRed is working now:");
 
     to=clock();
@@ -5969,10 +5984,13 @@
 
     to=clock();
-    /* compute a next weight vector */
+    // compute a next weight vector
     next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     tnw=tnw+clock()-to;
-#ifdef PRINT_VECTORS
-    MivString(curr_weight, target_weight, next_weight);
-#endif
+//#ifdef PRINT_VECTORS
+    if(printout > 2)
+    {
+      MivString(curr_weight, target_weight, next_weight);
+    }
+//#endif
 
     if(Overflow_Error == TRUE)
@@ -6012,5 +6030,5 @@
         DefRingPar(orig_target);
       else
-        rChangeCurrRing(VMrDefault(orig_target)); //Aenderung
+        rChangeCurrRing(VMrDefault(orig_target));
 
     TargetRing=currRing;
@@ -6066,4 +6084,5 @@
     Eresult = idrMoveR(G, newRing,currRing);
   }
+  si_opt_1 = save1; //set original options, e. g. option(RedSB)
   delete ivNull;
   if(tp_deg != 1)
@@ -6080,7 +6099,430 @@
              tnw+xtnw);
 
-  Print("\n// pSetm_Error = (%d)", ErrorCheck());
-  Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep,  Overflow_Error);
-#endif
+  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
+  //Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep,  Overflow_Error);
+#endif
+  Print("\n//** Mpwalk: Perturbation Walk took %d steps.\n", nstep);
+  return(Eresult);
+}
+
+/*******************************************************
+ * THE PERTURBATION WALK ALGORITHM WITH RANDOM ELEMENT *
+ *******************************************************/
+ideal Mprwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad,
+              int op_deg, int tp_deg, int nP, int reduction, int printout)
+{
+  BITSET save1 = si_opt_1; // save current options
+  if(reduction == 0)
+  {
+    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
+    //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
+    //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
+  }
+  Set_Error(FALSE);
+  Overflow_Error = FALSE;
+  //Print("// pSetm_Error = (%d)", ErrorCheck());
+
+  clock_t  tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
+  xtextra=0;
+  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
+  tinput = clock();
+
+  clock_t tim;
+
+  nstep = 0;
+  int i, ntwC=1, ntestw=1, polylength, nV = currRing->N;
+  int endwalks=0;
+
+  ideal Gomega, M, F, G, Gomega1, Gomega2, M1,F1,Eresult,ssG;
+  ring newRing, oldRing, TargetRing;
+  intvec* iv_M_dp;
+  intvec* iv_M_lp;
+  intvec* exivlp = Mivlp(nV);
+  intvec* curr_weight = new intvec(nV);
+  intvec* target_weight = new intvec(nV);
+  for(i=0; i<nV; i++)
+  {
+    (*curr_weight)[i] = (*orig_M)[i];
+    (*target_weight)[i] = (*target_M)[i];
+  }
+  intvec* orig_target = target_weight;
+  intvec* pert_target_vector = target_weight;
+  intvec* ivNull = new intvec(nV);
+  intvec* iv_dp = MivUnit(nV);// define (1,1,...,1)
+#ifndef BUCHBERGER_ALG
+  intvec* hilb_func;
+#endif
+  intvec* next_weight;
+
+  // to avoid (1,0,...,0) as the target vector
+  intvec* last_omega = new intvec(nV);
+  for(i=nV-1; i>0; i--)
+    (*last_omega)[i] = 1;
+  (*last_omega)[0] = 10000;
+
+  ring XXRing = currRing;
+
+  to = clock();
+  // perturbs the original vector
+  if(orig_M->length() == nV)
+  {
+    if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) := "dp"
+    {
+      G = MstdCC(Go);
+      tostd = clock()-to;
+      if(op_deg != 1)
+      {
+        iv_M_dp = MivMatrixOrderdp(nV);
+        //ivString(iv_M_dp, "iv_M_dp");
+        curr_weight = MPertVectors(G, iv_M_dp, op_deg);
+      }
+    }
+    else
+    {
+      //define ring order := (a(curr_weight),lp);
+      if (rParameter(currRing) != NULL)
+        DefRingPar(curr_weight);
+      else
+        rChangeCurrRing(VMrDefault(curr_weight));
+
+      G = idrMoveR(Go, XXRing,currRing);
+      G = MstdCC(G);
+      tostd = clock()-to;
+      if(op_deg != 1)
+      {
+        iv_M_dp = MivMatrixOrder(curr_weight);
+        curr_weight = MPertVectors(G, iv_M_dp, op_deg);
+      }
+    }
+  }
+  else
+  {
+    rChangeCurrRing(VMatrDefault(orig_M));
+    G = idrMoveR(Go, XXRing,currRing);
+    G = MstdCC(G);
+    tostd = clock()-to;
+    if(op_deg != 1)
+    {
+      curr_weight = MPertVectors(G, orig_M, op_deg);
+    }
+  }
+
+  delete iv_dp;
+  if(op_deg != 1) delete iv_M_dp;
+
+  ring HelpRing = currRing;
+
+  // perturbs the target weight vector
+  if(target_M->length() == nV)
+  {
+    if(tp_deg > 1 && tp_deg <= nV)
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingPar(target_weight);
+      else
+        rChangeCurrRing(VMrDefault(target_weight));
+
+      TargetRing = currRing;
+      ssG = idrMoveR(G,HelpRing,currRing);
+      if(MivSame(target_weight, exivlp) == 1)
+      {
+        iv_M_lp = MivMatrixOrderlp(nV);
+        //ivString(iv_M_lp, "iv_M_lp");
+        //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
+        target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
+      }
+      else
+      {
+        iv_M_lp = MivMatrixOrder(target_weight);
+        //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
+        target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
+      }
+      delete iv_M_lp;
+      pert_target_vector = target_weight;
+      rChangeCurrRing(HelpRing);
+      G = idrMoveR(ssG, TargetRing,currRing);
+    }
+  }
+  else
+  {
+    if(tp_deg > 1 && tp_deg <= nV)
+    {
+      rChangeCurrRing(VMatrDefault(target_M));
+      TargetRing = currRing;
+      ssG = idrMoveR(G,HelpRing,currRing);
+      target_weight = MPertVectors(ssG, target_M, tp_deg);
+    }
+  }
+  if(printout > 0)
+  {
+    Print("\n//** Mprwalk: Random Perturbation Walk of degree (%d,%d):",op_deg,tp_deg);
+    ivString(curr_weight, "//** Mprwalk: new current weight");
+    ivString(target_weight, "//** Mprwalk: new target weight");
+  }
+  while(1)
+  {
+    nstep ++;
+    to = clock();
+    /* compute an initial form ideal of <G> w.r.t. the weight vector
+       "curr_weight" */
+    Gomega = MwalkInitialForm(G, curr_weight);
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 1)
+    {
+      idString(Gomega,"//** Mprwalk: Gomega");
+    }
+//#endif
+    polylength = lengthpoly(Gomega);
+#ifdef ENDWALKS
+    if(endwalks == 1)
+    {
+      Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
+      idElements(G, "G");
+      headidString(G, "G");
+    }
+#endif
+
+    tif = tif + clock()-to;
+
+#ifndef  BUCHBERGER_ALG
+    if(isNolVector(curr_weight) == 0)
+      hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
+    else
+      hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
+#endif // BUCHBERGER_ALG
+
+    oldRing = currRing;
+
+    if(target_M->length() == nV)
+    {
+      // define a new ring with ordering "(a(curr_weight),lp)
+      if (rParameter(currRing) != NULL)
+        DefRingPar(curr_weight);
+      else
+        rChangeCurrRing(VMrDefault(curr_weight));
+    }
+    else
+    {
+      rChangeCurrRing(VMatrRefine(target_M,curr_weight));
+    }
+    newRing = currRing;
+    Gomega1 = idrMoveR(Gomega, oldRing,currRing);
+
+#ifdef ENDWALKS
+    if(endwalks==1)
+    {
+      Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
+      idElements(Gomega1, "Gw");
+      headidString(Gomega1, "headGw");
+      PrintS("\n// compute a rGB of Gw:\n");
+
+#ifndef  BUCHBERGER_ALG
+      ivString(hilb_func, "w");
+#endif
+    }
+#endif
+
+    tim = clock();
+    to = clock();
+    /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
+#ifdef  BUCHBERGER_ALG
+    M = MstdhomCC(Gomega1);
+#else
+    M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
+    delete hilb_func;
+#endif
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(M,"//** Mprwalk: M");
+    }
+//#endif
+
+    if(endwalks == 1)
+    {
+      xtstd = xtstd+clock()-to;
+#ifdef ENDWALKS
+      Print("\n// time for the last std(Gw)  = %.2f sec\n",
+            ((double) clock())/1000000 -((double)tim) /1000000);
+#endif
+    }
+    else
+      tstd=tstd+clock()-to;
+
+    /* change the ring to oldRing */
+    rChangeCurrRing(oldRing);
+    M1 =  idrMoveR(M, newRing,currRing);
+    Gomega2 =  idrMoveR(Gomega1, newRing,currRing);
+
+    to=clock();
+    /* compute a representation of the generators of submod (M)
+       with respect to those of mod (Gomega).
+       Gomega is a reduced Groebner basis w.r.t. the current ring */
+    F = MLifttwoIdeal(Gomega2, M1, G);
+    if(endwalks != 1)
+      tlift = tlift+clock()-to;
+    else
+      xtlift=clock()-to;
+
+//#ifdef CHECK_IDEAL_MWALK
+    if(printout > 2)
+    {
+      idString(F,"//** Mprwalk: F");
+    }
+//#endif
+
+    idDelete(&M1);
+    idDelete(&Gomega2);
+    idDelete(&G);
+
+    /* change the ring to newRing */
+    rChangeCurrRing(newRing);
+    F1 = idrMoveR(F, oldRing,currRing);
+
+    to=clock();
+    /* reduce the Groebner basis <G> w.r.t. new ring */
+    G = kInterRedCC(F1, NULL);
+    if(endwalks != 1)
+      tred = tred+clock()-to;
+    else
+      xtred=clock()-to;
+
+    idDelete(&F1);
+
+    if(endwalks == 1)
+      break;
+
+    to=clock();
+    // compute a next weight vector
+    next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
+    if(polylength > 0)
+    {
+      //there is a polynomial in Gomega with at least 3 monomials,
+      //low-dimensional facet of the cone
+      delete next_weight;
+      next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, op_deg);
+    }
+    tnw=tnw+clock()-to;
+//#ifdef PRINT_VECTORS
+    if(printout > 2)
+    {
+      MivString(curr_weight, target_weight, next_weight);
+    }
+//#endif
+
+    if(Overflow_Error == TRUE)
+    {
+      ntwC = 0;
+      //ntestomega = 1;
+      //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
+      //idElements(G, "G");
+      delete next_weight;
+      goto FINISH_160302;
+    }
+    if(MivComp(next_weight, ivNull) == 1){
+      newRing = currRing;
+      delete next_weight;
+      //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
+      break;
+    }
+    if(MivComp(next_weight, target_weight) == 1)
+      endwalks = 1;
+
+    for(i=nV-1; i>=0; i--)
+      (*curr_weight)[i] = (*next_weight)[i];
+
+    delete next_weight;
+  }//while
+
+  if(tp_deg != 1)
+  {
+    FINISH_160302:
+    if(target_M->length() == nV)
+    {
+      if(MivSame(orig_target, exivlp) == 1)
+        if (rParameter(currRing) != NULL)
+          DefRingParlp();
+        else
+          VMrDefaultlp();
+      else
+        if (rParameter(currRing) != NULL)
+          DefRingPar(orig_target);
+        else
+          rChangeCurrRing(VMrDefault(orig_target));
+    }
+    else
+    {
+      rChangeCurrRing(VMatrDefault(target_M));
+    }
+    TargetRing=currRing;
+    F1 = idrMoveR(G, newRing,currRing);
+#ifdef CHECK_IDEAL
+      headidString(G, "G");
+#endif
+
+    // check whether the pertubed target vector stays in the correct cone
+    if(ntwC != 0){
+      ntestw = test_w_in_ConeCC(F1, pert_target_vector);
+    }
+
+    if( ntestw != 1 || ntwC == 0)
+    {
+      /*
+      if(ntestw != 1){
+        ivString(pert_target_vector, "tau");
+        PrintS("\n// ** perturbed target vector doesn't stay in cone!!");
+        Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
+        idElements(F1, "G");
+      }
+      */
+      // LastGB is "better" than the kStd subroutine
+      to=clock();
+      ideal eF1;
+      if(nP == 0 || tp_deg == 1 || MivSame(orig_target, exivlp) != 1 || target_M->length() != nV){
+        // PrintS("\n// ** calls \"std\" to compute a GB");
+        eF1 = MstdCC(F1);
+        idDelete(&F1);
+      }
+      else {
+        // PrintS("\n// ** calls \"LastGB\" to compute a GB");
+        rChangeCurrRing(newRing);
+        ideal F2 = idrMoveR(F1, TargetRing,currRing);
+        eF1 = LastGB(F2, curr_weight, tp_deg-1);
+        F2=NULL;
+      }
+      xtextra=clock()-to;
+      ring exTargetRing = currRing;
+
+      rChangeCurrRing(XXRing);
+      Eresult = idrMoveR(eF1, exTargetRing,currRing);
+    }
+    else{
+      rChangeCurrRing(XXRing);
+      Eresult = idrMoveR(F1, TargetRing,currRing);
+    }
+  }
+  else {
+    rChangeCurrRing(XXRing);
+    Eresult = idrMoveR(G, newRing,currRing);
+  }
+  si_opt_1 = save1; //set original options, e. g. option(RedSB)
+  delete ivNull;
+  if(tp_deg != 1)
+    delete target_weight;
+
+  if(op_deg != 1 )
+    delete curr_weight;
+
+  delete exivlp;
+  delete last_omega;
+
+#ifdef TIME_TEST
+  TimeStringFractal(tinput, tostd, tif+xtif, tstd+xtstd,0, tlift+xtlift, tred+xtred,
+             tnw+xtnw);
+
+  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
+  //Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep,  Overflow_Error);
+#endif
+  Print("\n//** Mprwalk: Perturbation Walk took %d steps.\n", nstep);
   return(Eresult);
 }
@@ -6108,5 +6550,5 @@
  * Perturb the start weight vector at the top level, i.e. nlev = 1     *
  ***********************************************************************/
-static ideal rec_fractal_call(ideal G, int nlev, intvec* omtmp)
+static ideal rec_fractal_call(ideal G, int nlev, intvec* ivtarget, int printout)
 {
   Overflow_Error =  FALSE;
@@ -6125,6 +6567,11 @@
   intvec* next_vect;
   intvec* omega2 = new intvec(nV);
+  intvec* omtmp = new intvec(nV);
   intvec* altomega = new intvec(nV);
 
+  for(i = nV -1; i>0; i--)
+  {
+    (*omtmp)[i] = (*ivtarget)[i];
+  }
   //BOOLEAN isnewtarget = FALSE;
 
@@ -6167,40 +6614,55 @@
     NEXT_VECTOR_FRACTAL:
     to=clock();
-    /* determine the next border */
+    // determine the next border
     next_vect = MkInterRedNextWeight(omega,omega2,G);
     xtnw=xtnw+clock()-to;
-#ifdef PRINT_VECTORS
-    MivString(omega, omega2, next_vect);
-#endif
+
     oRing = currRing;
 
-    /* We only perturb the current target vector at the recursion  level 1 */
+    // We only perturb the current target vector at the recursion  level 1
     if(Xngleich == 0 && nlev == 1) //(ngleich == 0) important, e.g. ex2, ex3
       if (MivComp(next_vect, omega2) == 1)
       {
-        /* to dispense with taking initial (and lifting/interreducing
-           after the call of recursion */
-        //Print("\n\n// ** Perturb the both vectors with degree %d with",nlev);
-        //idElements(G, "G");
+        // to dispense with taking initial (and lifting/interreducing
+        // after the call of recursion
+        if(printout > 0)
+        {
+          Print("\n//** rec_fractal_call: Perturb the both vectors with degree %d.",nlev);
+          //idElements(G, "G");
+        }
 
         Xngleich = 1;
         nlev +=1;
 
-        if (rParameter(currRing) != NULL)
-          DefRingPar(omtmp);
+        if(ivtarget->length() == nV)
+        {
+          if (rParameter(currRing) != NULL)
+            DefRingPar(omtmp);
+          else
+            rChangeCurrRing(VMrDefault(omtmp));
+        }
         else
-          rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung3
-
+        {
+          rChangeCurrRing(VMatrDefault(ivtarget));
+        }
         testring = currRing;
         Gt = idrMoveR(G, oRing,currRing);
 
-        /* perturb the original target vector w.r.t. the current GB */
-        delete Xtau;
-        Xtau = NewVectorlp(Gt);
+        // perturb the original target vector w.r.t. the current GB
+        if(ivtarget->length() == nV)
+        {
+          delete Xtau;
+          Xtau = NewVectorlp(Gt);
+        }
+        else
+        {
+          delete Xtau;
+          Xtau = Mfpertvector(Gt,ivtarget);
+        }
 
         rChangeCurrRing(oRing);
         G = idrMoveR(Gt, testring,currRing);
 
-        /* perturb the current vector w.r.t. the current GB */
+        // perturb the current vector w.r.t. the current GB
         Mwlp = MivWeightOrderlp(omega);
         Xsigma = Mfpertvector(G, Mwlp);
@@ -6220,10 +6682,11 @@
         next_vect = MkInterRedNextWeight(omega,omega2,G);
         xtnw=xtnw+clock()-to;
-
-#ifdef PRINT_VECTORS
+      }
+//#ifdef PRINT_VECTORS
+      if(printout > 0)
+      {
         MivString(omega, omega2, next_vect);
-#endif
-      }
-
+      }
+//#endif
 
     /* check whether the the computed vector is in the correct cone */
@@ -6234,11 +6697,14 @@
     {
       delete next_vect;
-      if (rParameter(currRing) != NULL)
-      {
-        DefRingPar(omtmp);
+      if(ivtarget->length() == nV)
+      {
+        if (rParameter(currRing) != NULL)
+          DefRingPar(omtmp);
+        else
+          rChangeCurrRing(VMrDefault(omtmp));
       }
       else
       {
-        rChangeCurrRing(VMrDefault1(omtmp)); // Aenderung4
+        rChangeCurrRing(VMatrDefault(ivtarget));
       }
 #ifdef TEST_OVERFLOW
@@ -6246,6 +6712,9 @@
       Gt = NULL; return(Gt);
 #endif
-
-      //Print("\n\n// apply BB's alg. in ring r = %s;", rString(currRing));
+      if(printout > 0)
+      {
+        Print("\n//** rec_fractal_call: applying Buchberger's algorithm in ring r = %s;",
+              rString(currRing));
+      }
       to=clock();
       Gt = idrMoveR(G, oRing,currRing);
@@ -6256,7 +6725,11 @@
       delete omega2;
       delete altomega;
-
-      //Print("\n// Leaving the %d-th recursion with %d steps", nlev, nwalks);
-      //Print("  ** Overflow_Error? (%d)", Overflow_Error);
+      if(printout > 0)
+      {
+        Print("\n//** rec_fractal_call: Leaving the %d-th recursion with %d steps.\n",
+              nlev, nwalks);
+        //Print(" ** Overflow_Error? (%d)", Overflow_Error);
+      }
+
       nnflow ++;
 
@@ -6275,8 +6748,15 @@
     if (MivComp(next_vect, XivNull) == 1)
     {
-      if (rParameter(currRing) != NULL)
-        DefRingPar(omtmp);
+      if(ivtarget->length() == nV)
+      {
+        if (rParameter(currRing) != NULL)
+          DefRingPar(omtmp);
+        else
+          rChangeCurrRing(VMrDefault(omtmp));
+      }
       else
-        rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung5
+      {
+        rChangeCurrRing(VMatrDefault(ivtarget));
+      }
 
       testring = currRing;
@@ -6287,7 +6767,10 @@
         delete next_vect;
         delete altomega;
-        //Print("\n// Leaving the %d-th recursion with %d steps ",nlev, nwalks);
-        //Print(" ** Overflow_Error? (%d)", Overflow_Error);
-
+        if(printout > 0)
+        {
+          Print("\n//** rec_fractal_call: Leaving the %d-th recursion with %d steps.\n",
+              nlev, nwalks);
+          //Print(" ** Overflow_Error? (%d)", Overflow_Error);
+        }
         return (Gt);
       }
@@ -6300,5 +6783,13 @@
         //07.08.03
         //ivString(Xtau, "old Xtau");
-        intvec* Xtautmp = Mfpertvector(Gt, MivMatrixOrder(omtmp));
+        intvec* Xtautmp;
+        if(ivtarget->length() == nV)
+        {
+          Xtautmp = Mfpertvector(Gt, MivMatrixOrder(omtmp));
+        }
+        else
+        {
+          Xtautmp = Mfpertvector(Gt, ivtarget);
+        }
 #ifdef TEST_OVERFLOW
       if(Overflow_Error == TRUE)
@@ -6328,5 +6819,9 @@
 
       FRACTAL_MSTDCC:
-        //Print("\n//  apply BB-Alg in ring = %s;", rString(currRing));
+        if(printout > 0)
+        {
+          Print("\n//** rec_fractal_call: apply Buchberger's algorithm in ring = %s.\n",
+                rString(currRing));
+        }
         to=clock();
         G = MstdCC(Gt);
@@ -6336,15 +6831,21 @@
 
         // update the original target vector w.r.t. the current GB
-        if(MivSame(Xivinput, Xivlp) == 1)
-          if (rParameter(currRing) != NULL)
-            DefRingParlp();
+        if(ivtarget->length() == nV)
+        {
+          if(MivSame(Xivinput, Xivlp) == 1)
+            if (rParameter(currRing) != NULL)
+              DefRingParlp();
+            else
+              VMrDefaultlp();
           else
-            VMrDefaultlp();
+            if (rParameter(currRing) != NULL)
+              DefRingPar(Xivinput);
+            else
+              rChangeCurrRing(VMrDefault(Xivinput));
+        }
         else
-          if (rParameter(currRing) != NULL)
-            DefRingPar(Xivinput);
-          else
-            rChangeCurrRing(VMrDefault1(Xivinput)); //Aenderung6
-
+        {
+          rChangeCurrRing(VMatrRefine(ivtarget,Xivinput));
+        }
         testring = currRing;
         Gt = idrMoveR(G, oRing,currRing);
@@ -6359,8 +6860,10 @@
         delete next_vect;
         delete altomega;
-        /*
-          Print("\n// Leaving the %d-th recursion with %d steps,", nlev,nwalks);
-          Print(" ** Overflow_Error? (%d)", Overflow_Error);
-        */
+        if(printout > 0)
+        {
+          Print("\n//** rec_fractal_call: Leaving the %d-th recursion with %d steps.\n",
+              nlev, nwalks);
+          //Print(" ** Overflow_Error? (%d)", Overflow_Error);
+        }
         if(Overflow_Error == TRUE)
           nnflow ++;
@@ -6381,5 +6884,8 @@
     Gomega = MwalkInitialForm(G, omega);
     xtif=xtif+clock()-to;
-
+    if(printout > 1)
+    {
+      idString(Gomega,"//** rec_fractal_call: Gomega");
+    }
 #ifndef  BUCHBERGER_ALG
     if(isNolVector(omega) == 0)
@@ -6388,26 +6894,24 @@
       hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
 #endif // BUCHBERGER_ALG
-
-    if (rParameter(currRing) != NULL)
-      DefRingPar(omega);
+    if(ivtarget->length() == nV)
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingPar(omega);
+      else
+        rChangeCurrRing(VMrDefault(omega));
+    }
     else
-      rChangeCurrRing(VMrDefault1(omega)); //Aenderung7
-
+    {
+      rChangeCurrRing(VMatrRefine(ivtarget,omega));
+    }
     Gomega1 = idrMoveR(Gomega, oRing,currRing);
 
-    /* Maximal recursion depth, to compute a red. GB */
-    /* Fractal walk with the alternative recursion */
-    /* alternative recursion */
+    // Maximal recursion depth, to compute a red. GB
+    // Fractal walk with the alternative recursion
+    // alternative recursion
     // if(nlev == nV || lengthpoly(Gomega1) == 0)
     if(nlev == Xnlev || lengthpoly(Gomega1) == 0)
       //if(nlev == nV) // blind recursion
     {
-      /*
-      if(Xnlev != nV)
-      {
-        Print("\n// ** Xnlev = %d", Xnlev);
-        ivString(Xtau, "Xtau");
-      }
-      */
       to=clock();
 #ifdef  BUCHBERGER_ALG
@@ -6419,11 +6923,15 @@
       xtstd=xtstd+clock()-to;
     }
-    else {
+    else
+    {
       rChangeCurrRing(oRing);
       Gomega1 = idrMoveR(Gomega1, oRing,currRing);
-      Gresult = rec_fractal_call(idCopy(Gomega1),nlev+1,omega);
-    }
-
-    //convert a Groebner basis from a ring to another ring,
+      Gresult = rec_fractal_call(idCopy(Gomega1),nlev+1,omega,printout);
+    }
+    if(printout > 2)
+    {
+      idString(Gresult,"//** rec_fractal_call: M");
+    }
+    //convert a Groebner basis from a ring to another ring
     new_ring = currRing;
 
@@ -6433,7 +6941,11 @@
 
     to=clock();
-    /* Lifting process */
+    // Lifting process
     F = MLifttwoIdeal(Gomega2, Gresult1, G);
     xtlift=xtlift+clock()-to;
+    if(printout > 2)
+    {
+      idString(F,"//** rec_fractal_call: F");
+    }
     idDelete(&Gresult1);
     idDelete(&Gomega2);
@@ -6454,10 +6966,11 @@
  * Perturb the start weight vector at the top level with random element *
  ************************************************************************/
-static ideal rec_r_fractal_call(ideal G, int nlev, intvec* omtmp, int weight_rad)
+static ideal rec_r_fractal_call(ideal G, int nlev, intvec* ivtarget,
+                int weight_rad, int printout)
 {
   Overflow_Error =  FALSE;
   //Print("\n\n// Entering the %d-th recursion:", nlev);
 
-  int i, nV = currRing->N;
+  int i, polylength, nV = currRing->N;
   ring new_ring, testring;
   //ring extoRing;
@@ -6471,8 +6984,13 @@
   intvec* next_vect;
   intvec* omega2 = new intvec(nV);
+  intvec* omtmp = new intvec(nV);
   intvec* altomega = new intvec(nV);
 
   //BOOLEAN isnewtarget = FALSE;
 
+  for(i = nV -1; i>0; i--)
+  {
+    (*omtmp)[i] = (*ivtarget)[i];
+  }
   // to avoid (1,0,...,0) as the target vector (Hans)
   intvec* last_omega = new intvec(nV);
@@ -6514,41 +7032,70 @@
     to=clock();
     /* determine the next border */
-    next_vect = MWalkRandomNextWeight(G, omega,omega2, weight_rad, 1+nlev);
-    //next_vect = MkInterRedNextWeight(omega,omega2,G);
+    next_vect = MkInterRedNextWeight(omega,omega2,G);
+    if(polylength > 0)
+    {
+      //there is a polynomial in Gomega with at least 3 monomials,
+      //low-dimensional facet of the cone
+      delete next_vect;
+      next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,1+nlev);
+      if(isNolVector(next_vect))
+      {
+        delete next_vect;
+        next_vect = MkInterRedNextWeight(omega,omega2,G);
+      }
+    }
     xtnw=xtnw+clock()-to;
-#ifdef PRINT_VECTORS
-    MivString(omega, omega2, next_vect);
-#endif
+
     oRing = currRing;
 
-    /* We only perturb the current target vector at the recursion  level 1 */
+    // We only perturb the current target vector at the recursion  level 1
     if(Xngleich == 0 && nlev == 1) //(ngleich == 0) important, e.g. ex2, ex3
       if (MivComp(next_vect, omega2) == 1)
       {
-        /* to dispense with taking initial (and lifting/interreducing
-           after the call of recursion */
-        //Print("\n\n// ** Perturb the both vectors with degree %d with",nlev);
-        //idElements(G, "G");
-
+        // to dispense with taking initials and lifting/interreducing
+        // after the call of recursion.
+        if(printout > 0)
+        {
+          Print("\n//** rec_r_fractal_call: Perturb the both vectors with degree %d.",nlev);
+          //idElements(G, "G");
+        }
         Xngleich = 1;
         nlev +=1;
-
-        if (rParameter(currRing) != NULL)
-          DefRingPar(omtmp);
+        if(ivtarget->length() == nV)
+        {
+          if (rParameter(currRing) != NULL)
+            DefRingPar(omtmp);
+          else
+            rChangeCurrRing(VMrDefault(omtmp));
+        }
         else
-          rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung3
-
+        {
+          rChangeCurrRing(VMatrDefault(ivtarget));
+        }
         testring = currRing;
         Gt = idrMoveR(G, oRing,currRing);
 
-        /* perturb the original target vector w.r.t. the current GB */
-        delete Xtau;
-        Xtau = NewVectorlp(Gt);
+        // perturb the original target vector w.r.t. the current GB
+        if(ivtarget->length() == nV)
+        {
+          delete Xtau;
+          Xtau = NewVectorlp(Gt);
+        }
+        else
+        {
+          delete Xtau;
+          Xtau = Mfpertvector(Gt,ivtarget);
+        }
 
         rChangeCurrRing(oRing);
-        G = idrMoveR(Gt, testring,currRing);
-
-        /* perturb the current vector w.r.t. the current GB */
+        G = idrMoveR(Gt,testring,currRing);
+
+        // perturb the current vector w.r.t. the current GB
         Mwlp = MivWeightOrderlp(omega);
+        if(ivtarget->length() > nV)
+        {
+          delete Mwlp;
+          Mwlp = MivMatrixOrderRefine(omega,ivtarget);
+        }
         Xsigma = Mfpertvector(G, Mwlp);
         delete Mwlp;
@@ -6566,14 +7113,27 @@
 
         next_vect = MkInterRedNextWeight(omega,omega2,G);
+        if(polylength > 0)
+        {
+          //there is a polynomial in Gomega with at least 3 monomials,
+          //low-dimensional facet of the cone
+          delete next_vect;
+          next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,1+nlev);
+          if(isNolVector(next_vect))
+          {
+            delete next_vect;
+            next_vect = MkInterRedNextWeight(omega,omega2,G);
+          }
+        }
         xtnw=xtnw+clock()-to;
-
-#ifdef PRINT_VECTORS
+      }
+//#ifdef PRINT_VECTORS
+      if(printout > 0)
+      {
         MivString(omega, omega2, next_vect);
-#endif
-      }
-
-
-    /* check whether the the computed vector is in the correct cone */
-    /* If no, the reduced GB of an omega-homogeneous ideal will be
+      }
+//#endif
+
+    /* check whether the the computed vector is in the correct cone
+       If no, the reduced GB of an omega-homogeneous ideal will be
        computed by Buchberger algorithm and stop this recursion step*/
     //if(test_w_in_ConeCC(G, next_vect) != 1) //e.g. Example s7, cyc6
@@ -6581,18 +7141,29 @@
     {
       delete next_vect;
-      if (rParameter(currRing) != NULL)
-      {
-        DefRingPar(omtmp);
+      if(ivtarget->length() == nV)
+      {
+        if (rParameter(currRing) != NULL)
+        {
+          DefRingPar(omtmp);
+        }
+        else
+        {
+          rChangeCurrRing(VMrDefault(omtmp));
+        }
       }
       else
       {
-        rChangeCurrRing(VMrDefault1(omtmp)); // Aenderung4
+        rChangeCurrRing(VMatrDefault(ivtarget));
       }
 #ifdef TEST_OVERFLOW
       Gt = idrMoveR(G, oRing,currRing);
-      Gt = NULL; return(Gt);
-#endif
-
-      //Print("\n\n// apply BB's alg. in ring r = %s;", rString(currRing));
+      Gt = NULL;
+      return(Gt);
+#endif
+      if(printout > 0)
+      {
+        Print("\n//** rec_r_fractal_call: applying Buchberger's algorithm in ring r = %s;",
+              rString(currRing));
+      }
       to=clock();
       Gt = idrMoveR(G, oRing,currRing);
@@ -6603,49 +7174,69 @@
       delete omega2;
       delete altomega;
-
-      //Print("\n// Leaving the %d-th recursion with %d steps", nlev, nwalks);
-      //Print("  ** Overflow_Error? (%d)", Overflow_Error);
+      if(printout > 0)
+      {
+        Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n",
+              nlev, nwalks);
+        //Print(" ** Overflow_Error? (%d)", Overflow_Error);
+      }
       nnflow ++;
-
       Overflow_Error = FALSE;
       return (G1);
     }
-
-
-    /* If the perturbed target vector stays in the correct cone,
-       return the current GB,
-       otherwise, return the computed  GB by the Buchberger-algorithm.
-       Then we update the perturbed target vectors w.r.t. this GB. */
-
-    /* the computed vector is equal to the origin vector, since
-       t is not defined */
+    /*
+       If the perturbed target vector stays in the correct cone,
+       return the current Groebner basis.
+       Otherwise, return the Groebner basis computed with Buchberger's
+       algorithm.
+       Then we update the perturbed target vectors w.r.t. this GB.
+    */
     if (MivComp(next_vect, XivNull) == 1)
     {
-      if (rParameter(currRing) != NULL)
-        DefRingPar(omtmp);
+      // The computed vector is equal to the origin vector,
+      // because t is not defined
+      if(ivtarget->length() == nV)
+      {
+        if (rParameter(currRing) != NULL)
+          DefRingPar(omtmp);
+        else
+          rChangeCurrRing(VMrDefault(omtmp));
+      }
       else
-        rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung5
-
+      {
+        rChangeCurrRing(VMatrDefault(ivtarget));
+      }
       testring = currRing;
       Gt = idrMoveR(G, oRing,currRing);
 
-      if(test_w_in_ConeCC(Gt, omega2) == 1) {
+      if(test_w_in_ConeCC(Gt, omega2) == 1)
+      {
         delete omega2;
         delete next_vect;
         delete altomega;
-        //Print("\n// Leaving the %d-th recursion with %d steps ",nlev, nwalks);
-        //Print(" ** Overflow_Error? (%d)", Overflow_Error);
-
+        if(printout > 0)
+        {
+          Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n",
+                nlev, nwalks);
+          //Print(" ** Overflow_Error? (%d)", Overflow_Error);
+        }
         return (Gt);
       }
       else
-      {
-        //ivString(omega2, "tau'");
-        //Print("\n//  tau' doesn't stay in the correct cone!!");
-
+      { 
+        if(printout > 0)
+        {
+          Print("\n//** rec_r_fractal_call: target weight doesn't stay in the correct cone.\n");
+        }
 #ifndef  MSTDCC_FRACTAL
-        //07.08.03
         //ivString(Xtau, "old Xtau");
-        intvec* Xtautmp = Mfpertvector(Gt, MivMatrixOrder(omtmp));
+        intvec* Xtautmp;
+        if(ivtarget->length() == nV)
+        {
+          Xtautmp = Mfpertvector(Gt, MivMatrixOrder(omtmp));
+        }
+        else
+        {
+          Xtautmp = Mfpertvector(Gt, ivtarget);
+        }
 #ifdef TEST_OVERFLOW
       if(Overflow_Error == TRUE)
@@ -6675,5 +7266,9 @@
 
       FRACTAL_MSTDCC:
-        //Print("\n//  apply BB-Alg in ring = %s;", rString(currRing));
+        if(printout > 0)
+        {
+          Print("\n//** rec_r_fractal_call: apply Buchberge's algorithm in ring = %s.\n",
+                rString(currRing));
+        }
         to=clock();
         G = MstdCC(Gt);
@@ -6683,15 +7278,21 @@
 
         // update the original target vector w.r.t. the current GB
-        if(MivSame(Xivinput, Xivlp) == 1)
-          if (rParameter(currRing) != NULL)
-            DefRingParlp();
+        if(ivtarget->length() == nV)
+        {
+          if(MivSame(Xivinput, Xivlp) == 1)
+            if (rParameter(currRing) != NULL)
+              DefRingParlp();
+            else
+              VMrDefaultlp();
           else
-            VMrDefaultlp();
+            if (rParameter(currRing) != NULL)
+              DefRingPar(Xivinput);
+            else
+              rChangeCurrRing(VMrDefault(Xivinput));
+        }
         else
-          if (rParameter(currRing) != NULL)
-            DefRingPar(Xivinput);
-          else
-            rChangeCurrRing(VMrDefault1(Xivinput)); //Aenderung6
-
+        {
+          rChangeCurrRing(VMatrRefine(ivtarget,Xivinput));
+        }
         testring = currRing;
         Gt = idrMoveR(G, oRing,currRing);
@@ -6706,8 +7307,10 @@
         delete next_vect;
         delete altomega;
-        /*
-          Print("\n// Leaving the %d-th recursion with %d steps,", nlev,nwalks);
-          Print(" ** Overflow_Error? (%d)", Overflow_Error);
-        */
+        if(printout > 0)
+        {
+          Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n",
+                nlev,nwalks);
+          //Print(" ** Overflow_Error? (%d)", Overflow_Error);
+        }
         if(Overflow_Error == TRUE)
           nnflow ++;
@@ -6725,8 +7328,13 @@
 
     to=clock();
-    /* Take the initial form of <G> w.r.t. omega */
+    // Take the initial form of <G> w.r.t. omega
     Gomega = MwalkInitialForm(G, omega);
     xtif=xtif+clock()-to;
-
+    //polylength = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
+    polylength = lengthpoly(Gomega);
+    if(printout > 1)
+    {
+      idString(Gomega,"//** rec_r_fractal_call: Gomega");
+    }
 #ifndef  BUCHBERGER_ALG
     if(isNolVector(omega) == 0)
@@ -6734,27 +7342,23 @@
     else
       hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
-#endif // BUCHBERGER_ALG
-
-    if (rParameter(currRing) != NULL)
-      DefRingPar(omega);
+#endif
+    if(ivtarget->length() == nV)
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingPar(omega);
+      else
+        rChangeCurrRing(VMrDefault(omega));
+    }
     else
-      rChangeCurrRing(VMrDefault1(omega)); //Aenderung7
-
+    {
+      rChangeCurrRing(VMatrRefine(ivtarget,omega));
+    }
     Gomega1 = idrMoveR(Gomega, oRing,currRing);
 
-    /* Maximal recursion depth, to compute a red. GB */
-    /* Fractal walk with the alternative recursion */
-    /* alternative recursion */
-    // if(nlev == nV || lengthpoly(Gomega1) == 0)
+    // Maximal recursion depth, to compute a red. GB
+    // Fractal walk with the alternative recursion
+    // alternative recursion
     if(nlev == Xnlev || lengthpoly(Gomega1) == 0)
-      //if(nlev == nV) // blind recursion
-    {
-      /*
-      if(Xnlev != nV)
-      {
-        Print("\n// ** Xnlev = %d", Xnlev);
-        ivString(Xtau, "Xtau");
-      }
-      */
+    {
       to=clock();
 #ifdef  BUCHBERGER_ALG
@@ -6763,14 +7367,18 @@
       Gresult =kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,omega);
       delete hilb_func;
-#endif // BUCHBERGER_ALG
+#endif
       xtstd=xtstd+clock()-to;
     }
-    else {
+    else
+    {
       rChangeCurrRing(oRing);
       Gomega1 = idrMoveR(Gomega1, oRing,currRing);
-      Gresult = rec_fractal_call(idCopy(Gomega1),nlev+1,omega);
-    }
-
-    //convert a Groebner basis from a ring to another ring,
+      Gresult = rec_fractal_call(idCopy(Gomega1),nlev+1,omega,printout);
+    }
+    if(printout > 2)
+    {
+      idString(Gresult,"//** rec_r_fractal_call: M");
+    }
+    //convert a Groebner basis from a ring to another ring
     new_ring = currRing;
 
@@ -6780,7 +7388,13 @@
 
     to=clock();
-    /* Lifting process */
+    // Lifting process
     F = MLifttwoIdeal(Gomega2, Gresult1, G);
     xtlift=xtlift+clock()-to;
+
+    if(printout > 2)
+    {
+      idString(F,"//** rec_r_fractal_call: F");
+    }
+
     idDelete(&Gresult1);
     idDelete(&Gomega2);
@@ -6791,5 +7405,5 @@
 
     to=clock();
-    /* Interreduce G */
+    // Interreduce G
     G = kInterRedCC(F1, NULL);
     xtred=xtred+clock()-to;
@@ -6797,6 +7411,4 @@
   }
 }
-
-
 
 
@@ -6805,11 +7417,18 @@
  *                                                                             *
  * The main procedur Mfwalk calls the recursive Subroutine                     *
- * rec_fractal_call to compute the wanted Grï¿œbner basis.                       *
- * At the main procedur we compute the reduced Grï¿œbner basis w.r.t. a "fast"   *
+ * rec_fractal_call to compute the wanted Groebner basis.                      *
+ * At the main procedur we compute the reduced Groebner basis w.r.t. a "fast"  *
  * order, e.g. "dp" and a sequence of weight vectors which are row vectors     *
  * of a matrix. This matrix defines the given monomial order, e.g. "lp"        *
  *******************************************************************************/
-ideal Mfwalk(ideal G, intvec* ivstart, intvec* ivtarget)
+ideal Mfwalk(ideal G, intvec* ivstart, intvec* ivtarget,
+             int reduction, int printout)
 {
+  BITSET save1 = si_opt_1; // save current options
+  if(reduction == 0)
+  {
+    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
+    //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
+  }
   Set_Error(FALSE);
   Overflow_Error = FALSE;
@@ -6846,9 +7465,15 @@
       intvec* iv_dp = MivUnit(nV); // define (1,1,...,1)
       intvec* Mdp;
-
-      if(MivSame(ivstart, iv_dp) != 1)
-        Mdp = MivWeightOrderdp(ivstart);
+      if(ivstart->length() == nV)
+      {
+        if(MivSame(ivstart, iv_dp) != 1)
+          Mdp = MivWeightOrderdp(ivstart);
+        else
+          Mdp = MivMatrixOrderdp(nV);
+      }
       else
-        Mdp = MivMatrixOrderdp(nV);
+      {
+        Mdp = ivstart;
+      }
 
       Xsigma = Mfpertvector(I, Mdp);
@@ -6867,24 +7492,34 @@
   Xivlp = Mivlp(nV);
 
-  if(MivComp(ivtarget, Xivlp)  != 1)
-  {
-    if (rParameter(currRing) != NULL)
-      DefRingPar(ivtarget);
+  if(ivtarget->length() == nV)
+  {
+    if(MivComp(ivtarget, Xivlp)  != 1)
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingPar(ivtarget);
+      else
+        rChangeCurrRing(VMrDefault(ivtarget));
+
+      I1 = idrMoveR(I, oldRing,currRing);
+      Mlp = MivWeightOrderlp(ivtarget);
+      Xtau = Mfpertvector(I1, Mlp);
+    }
     else
-      rChangeCurrRing(VMrDefault1(ivtarget)); //Aenderung1
-
-    I1 = idrMoveR(I, oldRing,currRing);
-    Mlp = MivWeightOrderlp(ivtarget);
-    Xtau = Mfpertvector(I1, Mlp);
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingParlp();
+      else
+        VMrDefaultlp();
+
+      I1 = idrMoveR(I, oldRing,currRing);
+      Mlp =  MivMatrixOrderlp(nV);
+      Xtau = Mfpertvector(I1, Mlp);
+    }
   }
   else
   {
-    if (rParameter(currRing) != NULL)
-      DefRingParlp();
-    else
-      VMrDefaultlp();
-
-    I1 = idrMoveR(I, oldRing,currRing);
-    Mlp =  MivMatrixOrderlp(nV);
+    rChangeCurrRing(VMatrDefault(ivtarget));
+    I1 = idrMoveR(I,oldRing,currRing);
+    Mlp =  ivtarget;
     Xtau = Mfpertvector(I1, Mlp);
   }
@@ -6897,9 +7532,15 @@
   id_Delete(&I, oldRing);
   ring tRing = currRing;
-
-  if (rParameter(currRing) != NULL)
-    DefRingPar(ivstart);
+  if(ivtarget->length() == nV)
+  {
+    if (rParameter(currRing) != NULL)
+      DefRingPar(ivstart);
+    else
+      rChangeCurrRing(VMrDefault(ivstart));
+  }
   else
-    rChangeCurrRing(VMrDefault1(ivstart)); //Aenderung2
+  {
+    rChangeCurrRing(VMatrDefault(ivstart));
+  }
 
   I = idrMoveR(I1,tRing,currRing);
@@ -6912,5 +7553,5 @@
   ring helpRing = currRing;
 
-  J = rec_fractal_call(J, 1, ivtarget);
+  J = rec_fractal_call(J,1,ivtarget,printout);
 
   rChangeCurrRing(oldRing);
@@ -6918,4 +7559,5 @@
   idSkipZeroes(resF);
 
+  si_opt_1 = save1; //set original options, e. g. option(RedSB)
   delete Xivlp;
   delete Xsigma;
@@ -6936,6 +7578,22 @@
 }
 
-ideal Mfrwalk(ideal G, intvec* ivstart, intvec* ivtarget,int weight_rad)
+/*******************************************************************************
+ * The implementation of the fractal walk algorithm with random element        *
+ *                                                                             *
+ * The main procedur Mfwalk calls the recursive Subroutine                     *
+ * rec_r_fractal_call to compute the wanted Groebner basis.                    *
+ * At the main procedure we compute the reduced Groebner basis w.r.t. a "fast" *
+ * order, e.g. "dp" and a sequence of weight vectors which are row vectors     *
+ * of a matrix. This matrix defines the given monomial order, e.g. "lp"        *
+ *******************************************************************************/
+ideal Mfrwalk(ideal G, intvec* ivstart, intvec* ivtarget,
+              int weight_rad, int reduction, int printout)
 {
+  BITSET save1 = si_opt_1; // save current options
+  if(reduction == 0)
+  {
+    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
+    //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
+  }
   Set_Error(FALSE);
   Overflow_Error = FALSE;
@@ -6972,9 +7630,15 @@
       intvec* iv_dp = MivUnit(nV); // define (1,1,...,1)
       intvec* Mdp;
-
-      if(MivSame(ivstart, iv_dp) != 1)
-        Mdp = MivWeightOrderdp(ivstart);
+      if(ivstart->length() == nV)
+      {
+        if(MivSame(ivstart, iv_dp) != 1)
+          Mdp = MivWeightOrderdp(ivstart);
+        else
+          Mdp = MivMatrixOrderdp(nV);
+      }
       else
-        Mdp = MivMatrixOrderdp(nV);
+      {
+        Mdp = ivstart;
+      }
 
       Xsigma = Mfpertvector(I, Mdp);
@@ -6993,24 +7657,34 @@
   Xivlp = Mivlp(nV);
 
-  if(MivComp(ivtarget, Xivlp)  != 1)
-  {
-    if (rParameter(currRing) != NULL)
-      DefRingPar(ivtarget);
+  if(ivtarget->length() == nV)
+  {
+    if(MivComp(ivtarget, Xivlp)  != 1)
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingPar(ivtarget);
+      else
+        rChangeCurrRing(VMrDefault(ivtarget));
+
+      I1 = idrMoveR(I, oldRing,currRing);
+      Mlp = MivWeightOrderlp(ivtarget);
+      Xtau = Mfpertvector(I1, Mlp);
+    }
     else
-      rChangeCurrRing(VMrDefault1(ivtarget)); //Aenderung1
-
-    I1 = idrMoveR(I, oldRing,currRing);
-    Mlp = MivWeightOrderlp(ivtarget);
-    Xtau = Mfpertvector(I1, Mlp);
+    {
+      if (rParameter(currRing) != NULL)
+        DefRingParlp();
+      else
+        VMrDefaultlp();
+
+      I1 = idrMoveR(I, oldRing,currRing);
+      Mlp =  MivMatrixOrderlp(nV);
+      Xtau = Mfpertvector(I1, Mlp);
+    }
   }
   else
   {
-    if (rParameter(currRing) != NULL)
-      DefRingParlp();
-    else
-      VMrDefaultlp();
-
-    I1 = idrMoveR(I, oldRing,currRing);
-    Mlp =  MivMatrixOrderlp(nV);
+    rChangeCurrRing(VMatrDefault(ivtarget));
+    I1 = idrMoveR(I,oldRing,currRing);
+    Mlp =  ivtarget;
     Xtau = Mfpertvector(I1, Mlp);
   }
@@ -7023,9 +7697,15 @@
   id_Delete(&I, oldRing);
   ring tRing = currRing;
-
-  if (rParameter(currRing) != NULL)
-    DefRingPar(ivstart);
+  if(ivtarget->length() == nV)
+  {
+    if (rParameter(currRing) != NULL)
+      DefRingPar(ivstart);
+    else
+      rChangeCurrRing(VMrDefault(ivstart));
+  }
   else
-    rChangeCurrRing(VMrDefault1(ivstart)); //Aenderung2
+  {
+    rChangeCurrRing(VMatrDefault(ivstart));
+  }
 
   I = idrMoveR(I1,tRing,currRing);
@@ -7037,6 +7717,6 @@
   ideal resF;
   ring helpRing = currRing;
-//ideal G, int nlev, intvec* omtmp, int weight_rad)
-  J = rec_r_fractal_call(J, 1, ivtarget,weight_rad);
+
+  J = rec_r_fractal_call(J,1,ivtarget,weight_rad,printout);
 
   rChangeCurrRing(oldRing);
@@ -7044,4 +7724,5 @@
   idSkipZeroes(resF);
 
+  si_opt_1 = save1; //set original options, e. g. option(RedSB)
   delete Xivlp;
   delete Xsigma;
@@ -7099,5 +7780,5 @@
   intvec* hilb_func;
 #endif
-  /* to avoid (1,0,...,0) as the target vector */
+  // to avoid (1,0,...,0) as the target vector
   intvec* last_omega = new intvec(nV);
   for(i=nV-1; i>0; i--)
@@ -7114,5 +7795,5 @@
 
   to=clock();
-  /* compute a red. GB w.r.t. the help ring */
+  // compute a red. GB w.r.t. the help ring
   if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) = "dp"
     G = MstdCC(G);
@@ -7123,5 +7804,5 @@
       DefRingPar(curr_weight);
     else
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 4
+      rChangeCurrRing(VMrDefault(curr_weight));
     G = idrMoveR(G, XXRing,currRing);
     G = MstdCC(G);
@@ -7149,5 +7830,5 @@
       DefRingPar(curr_weight);
     else
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 5
+      rChangeCurrRing(VMrDefault(curr_weight));
     to=clock();
     Gw = idrMoveR(G, exring,currRing);
@@ -7184,5 +7865,5 @@
       DefRingPar(curr_weight);
     else
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 6
+      rChangeCurrRing(VMrDefault(curr_weight));
 
     newRing = currRing;
@@ -7269,5 +7950,5 @@
           DefRingPar(target_tmp);
         else
-          rChangeCurrRing(VMrDefault(target_tmp)); // Aenderung 8
+          rChangeCurrRing(VMrDefault(target_tmp));
 
       lpRing = currRing;
@@ -7329,5 +8010,5 @@
           DefRingPar(target_tmp);
         else
-          rChangeCurrRing(VMrDefault(target_tmp)); //Aenderung 9
+          rChangeCurrRing(VMrDefault(target_tmp));
 
       lpRing = currRing;
@@ -7532,5 +8213,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 10
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     G = idrMoveR(G, XXRing,currRing);
@@ -7565,5 +8246,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 11
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     to=clock();
@@ -7608,5 +8289,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 12
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -7777,5 +8458,5 @@
         else
         {
-          rChangeCurrRing(VMrDefault(target_tmp)); // Aenderung 13
+          rChangeCurrRing(VMrDefault(target_tmp));
         }
       }
@@ -7850,5 +8531,5 @@
         else
         {
-          rChangeCurrRing(VMrDefault(target_tmp)); // Aenderung 14
+          rChangeCurrRing(VMrDefault(target_tmp));
         }
       }
@@ -8093,5 +8774,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 15
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -8235,4 +8916,6 @@
 
   //Print("\n// \"Mpwalk\" (1,%d) took %d steps and %.2f sec. Overflow_Error (%d)", tp_deg, nwalk, ((double) clock()-tinput)/1000000, nOverflow_Error);
+<<<<<<< HEAD
+=======
 
   return(result);
@@ -8421,20 +9104,7 @@
     delete next_weight;
   } //end of while-loop
+>>>>>>> f533f6f7667328bccb271b19b2f603aaebe41596
   Print("\n// Mprwalk took %d steps. Ring= %s;\n", nwalk, rString(currRing));
-  idSkipZeroes(G);
-  si_opt_1 = save1; //set original options, e. g. option(RedSB)
-  baseRing = currRing;
-  rChangeCurrRing(XXRing);
-  ideal Res = idrMoveR(G,baseRing,currRing);
-  delete tmp_weight;
-  delete ivNull;
-  delete exivlp;
-#ifndef BUCHBERGER_ALG
-  delete last_omega;
-#endif
-#ifdef TIME_TEST
-  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
-#endif
-  return(Res);
+  return(result);
 }
 
@@ -8515,5 +9185,5 @@
         else
         {
-          rChangeCurrRing(VMrDefault(cw_tmp)); // Aenderung 16
+          rChangeCurrRing(VMrDefault(cw_tmp));
         }
         G = idrMoveR(Go, XXRing,currRing);
@@ -8589,5 +9259,5 @@
     else
     {
-      rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 17
+      rChangeCurrRing(VMrDefault(curr_weight));
     }
     newRing = currRing;
@@ -8651,5 +9321,5 @@
       else
       {
-        rChangeCurrRing(VMrDefault(target_weight)); // Aenderung 18
+        rChangeCurrRing(VMrDefault(target_weight));
       }
       F1 = idrMoveR(G, newRing,currRing);
