Changeset 36b81ac in git


Ignore:
Timestamp:
Sep 1, 2015, 3:13:14 PM (8 years ago)
Author:
Stephan Oberfranz <oberfran@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
510257fc6c7ff9c0c28e81f62f6fe06e63f024f8b430ca2b1337f52e1932f689e451e9abb002ec4a
Parents:
74fe3587102ed73b3858258975abbe6d63139abfcd38fbd954495900afc188a0e871f8586db00535
Message:
update
Merge branch 'spielwiese' of github.com:Singular/Sources into spielwiese
Files:
4 added
35 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/grwalk.lib

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

    r74fe358 r36b81ac  
    11///////////////////////////////////////////////////////////////////////////////
    2 version="version modstd.lib 4.0.0.0 May_2014 "; // $Id$
     2version="version modstd.lib 4.0.2.0 Aug_2015 "; // $Id$
    33category="Commutative Algebra";
    44info="
     
    219219/* test if 'command' applied to 'args' in characteristic p is the same as
    220220   'result' mapped to characteristic p */
    221 static proc pTest_std(string command, list args, ideal result, int p)
     221static proc pTest_std(string command, alias list args, alias ideal result,
     222    int p)
    222223{
    223224    /* change to characteristic p */
  • Singular/LIB/modwalk.lib

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

    r74fe358 r36b81ac  
    32763276/******************************************************/
    32773277proc multiDegBasis(intvec d)
    3278 "USAGE: multidegree d
     3278"USAGE: multiDegBasis(d), multidegree: intvec d
    32793279ASSUME: current ring is multigraded, monomial ordering is global
    32803280PURPOSE: compute all monomials of multidegree d
  • Singular/LIB/primdec.lib

    r74fe358 r36b81ac  
    79977997
    79987998  ideal jkeep=@j;
    7999   if(ordstr(@P)[1]=="w")
     7999  if((ordstr(@P)[1]=="w")&&(size(ringlist(@P)[3])==2)) // weighted ordering
    80008000  {
    80018001    def @Phelp=ring(ringlist(gnir));
  • Singular/LIB/rwalk.lib

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

    • Property mode changed from 100644 to 100755
  • Singular/extra.cc

    rcd38fbd r36b81ac  
    18641864    if (strcmp(sys_cmd, "Mwalk") == 0)
    18651865    {
    1866       const short t[]={4,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,RING_CMD};
     1866      const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,RING_CMD,INT_CMD,INT_CMD};
    18671867      if (!iiCheckTypes(h,t,1)) return TRUE;
    18681868      if (((intvec*) h->next->Data())->length() != currRing->N &&
     
    18751875      ideal arg1 = (ideal) h->Data();
    18761876      intvec* arg2 = (intvec*) h->next->Data();
    1877       intvec* arg3   =  (intvec*) h->next->next->Data();
    1878       ring arg4   =  (ring) h->next->next->next->Data();
    1879       ideal result = (ideal) Mwalk(arg1, arg2, arg3,arg4);
     1877      intvec* arg3 = (intvec*) h->next->next->Data();
     1878      ring arg4 = (ring) h->next->next->next->Data();
     1879      int arg5 = (int) (long) h->next->next->next->next->Data();
     1880      int arg6 = (int) (long) h->next->next->next->next->next->Data();
     1881      ideal result = (ideal) Mwalk(arg1, arg2, arg3, arg4, arg5, arg6);
    18801882      res->rtyp = IDEAL_CMD;
    18811883      res->data =  result;
     
    19131915    if (strcmp(sys_cmd, "Mpwalk") == 0)
    19141916    {
    1915       const short t[]={6,IDEAL_CMD,INT_CMD,INT_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD};
     1917      const short t[]={8,IDEAL_CMD,INT_CMD,INT_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD};
    19161918      if (!iiCheckTypes(h,t,1)) return TRUE;
    19171919      if(((intvec*) h->next->next->next->Data())->length() != currRing->N &&
     
    19271929      intvec* arg5 = (intvec*) h->next->next->next->next->Data();
    19281930      int arg6 = (int) (long) h->next->next->next->next->next->Data();
    1929       ideal result = (ideal) Mpwalk(arg1, arg2, arg3, arg4, arg5,arg6);
     1931      int arg7 = (int) (long) h->next->next->next->next->next->next->Data();
     1932      int arg8 = (int) (long) h->next->next->next->next->next->next->next->Data();
     1933      ideal result = (ideal) Mpwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
    19301934      res->rtyp = IDEAL_CMD;
    19311935      res->data =  result;
     
    19391943    if (strcmp(sys_cmd, "Mrwalk") == 0)
    19401944    {
    1941       const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,RING_CMD};
     1945      const short t[]={7,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD};
    19421946      if (!iiCheckTypes(h,t,1)) return TRUE;
    1943       if((((intvec*) h->next->Data())->length() != currRing->N &&
    1944          ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
    1945          (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
    1946          ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
     1947      if(((intvec*) h->next->Data())->length() != currRing->N &&
     1948         ((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
     1949         ((intvec*) h->next->next->Data())->length() != currRing->N &&
     1950         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) )
    19471951      {
    19481952        Werror("system(\"Mrwalk\" ...) intvecs not of length %d or %d\n",
     
    19551959      int arg4 = (int)(long) h->next->next->next->Data();
    19561960      int arg5 = (int)(long) h->next->next->next->next->Data();
    1957       ring arg6 = (ring) h->next->next->next->next->next->Data();
    1958       ideal result = (ideal) Mrwalk(arg1, arg2, arg3, arg4, arg5, arg6);
     1961      int arg6 = (int)(long) h->next->next->next->next->next->Data();
     1962      int arg7 = (int)(long) h->next->next->next->next->next->next->Data();
     1963      ideal result = (ideal) Mrwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
    19591964      res->rtyp = IDEAL_CMD;
    19601965      res->data =  result;
     
    20182023    if (strcmp(sys_cmd, "Mfwalk") == 0)
    20192024    {
    2020       const short t[]={3,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD};
     2025      const short t[]={5,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD};
    20212026      if (!iiCheckTypes(h,t,1)) return TRUE;
    20222027      if (((intvec*) h->next->Data())->length() != currRing->N &&
     
    20252030        Werror("system(\"Mfwalk\" ...) intvecs not of length %d\n",
    20262031                 currRing->N);
    2027         return TRUE;
    2028       }
    2029       ideal arg1 = (ideal) h->Data();
    2030       intvec* arg2 = (intvec*) h->next->Data();
    2031       intvec* arg3   =  (intvec*) h->next->next->Data();
    2032       ideal result = (ideal) Mfwalk(arg1, arg2, arg3);
    2033       res->rtyp = IDEAL_CMD;
    2034       res->data =  result;
    2035       return FALSE;
    2036     }
    2037     else
    2038   #endif
    2039   /*==================== Mfrwalk =================*/
    2040   #ifdef HAVE_WALK
    2041     if (strcmp(sys_cmd, "Mfrwalk") == 0)
    2042     {
    2043       const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,RING_CMD};
    2044       if (!iiCheckTypes(h,t,1)) return TRUE;
    2045       if (((intvec*) h->next->Data())->length() != currRing->N &&
    2046           ((intvec*) h->next->next->Data())->length() != currRing->N)
    2047       {
    2048         Werror("system(\"Mfrwalk\" ...) intvecs not of length %d\n",currRing->N);
    20492032        return TRUE;
    20502033      }
     
    20532036      intvec* arg3 = (intvec*) h->next->next->Data();
    20542037      int arg4 = (int)(long) h->next->next->next->Data();
    2055       ideal result = (ideal) Mfrwalk(arg1, arg2, arg3, arg4);
     2038      int arg5 = (int)(long) h->next->next->next->next->Data();
     2039      ideal result = (ideal) Mfwalk(arg1, arg2, arg3, arg4, arg5);
    20562040      res->rtyp = IDEAL_CMD;
    20572041      res->data =  result;
     
    20592043    }
    20602044    else
     2045  #endif
     2046  /*==================== Mfrwalk =================*/
     2047  #ifdef HAVE_WALK
     2048    if (strcmp(sys_cmd, "Mfrwalk") == 0)
     2049    {
     2050      const short t[]={6,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD};
     2051      if (!iiCheckTypes(h,t,1)) return TRUE;
     2052/*
     2053      if (((intvec*) h->next->Data())->length() != currRing->N &&
     2054          ((intvec*) h->next->next->Data())->length() != currRing->N)
     2055      {
     2056        Werror("system(\"Mfrwalk\" ...) intvecs not of length %d\n",currRing->N);
     2057        return TRUE;
     2058      }
     2059*/
     2060      if((((intvec*) h->next->Data())->length() != currRing->N &&
     2061         ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
     2062         (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
     2063         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
     2064      {
     2065        Werror("system(\"Mfrwalk\" ...) intvecs not of length %d or %d\n",
     2066               currRing->N,(currRing->N)*(currRing->N));
     2067        return TRUE;
     2068      }
     2069
     2070      ideal arg1 = (ideal) h->Data();
     2071      intvec* arg2 = (intvec*) h->next->Data();
     2072      intvec* arg3 = (intvec*) h->next->next->Data();
     2073      int arg4 = (int)(long) h->next->next->next->Data();
     2074      int arg5 = (int)(long) h->next->next->next->next->Data();
     2075      int arg6 = (int)(long) h->next->next->next->next->next->Data();
     2076      ideal result = (ideal) Mfrwalk(arg1, arg2, arg3, arg4, arg5, arg6);
     2077      res->rtyp = IDEAL_CMD;
     2078      res->data =  result;
     2079      return FALSE;
     2080    }
     2081    else
    20612082  /*==================== Mprwalk =================*/
    20622083    if (strcmp(sys_cmd, "Mprwalk") == 0)
    20632084    {
    2064       const short t[]={7,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,RING_CMD};
     2085      const short t[]={9,IDEAL_CMD,INTVEC_CMD,INTVEC_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD,INT_CMD};
    20652086      if (!iiCheckTypes(h,t,1)) return TRUE;
    2066       if (((intvec*) h->next->Data())->length() != currRing->N &&
    2067           ((intvec*) h->next->next->Data())->length() != currRing->N )
    2068       {
    2069         Werror("system(\"Mrwalk\" ...) intvecs not of length %d\n",
    2070                currRing->N);
     2087      if((((intvec*) h->next->Data())->length() != currRing->N &&
     2088         ((intvec*) h->next->next->Data())->length() != currRing->N ) &&
     2089         (((intvec*) h->next->Data())->length() != (currRing->N)*(currRing->N) &&
     2090         ((intvec*) h->next->next->Data())->length() != (currRing->N)*(currRing->N) ))
     2091      {
     2092        Werror("system(\"Mrwalk\" ...) intvecs not of length %d or %d\n",
     2093               currRing->N,(currRing->N)*(currRing->N));
    20712094        return TRUE;
    20722095      }
     
    20772100      int arg5 = (int)(long) h->next->next->next->next->Data();
    20782101      int arg6 = (int)(long) h->next->next->next->next->next->Data();
    2079       ring arg7 = (ring) h->next->next->next->next->next->next->Data();
    2080       ideal result = (ideal) Mprwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
     2102      int arg7 = (int)(long) h->next->next->next->next->next->next->Data();
     2103      int arg8 = (int)(long) h->next->next->next->next->next->next->next->Data();
     2104      int arg9 = (int)(long) h->next->next->next->next->next->next->next->next->Data();
     2105      ideal result = (ideal) Mprwalk(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
    20812106      res->rtyp = IDEAL_CMD;
    20822107      res->data =  result;
  • Singular/iparith.cc

    r74fe358 r36b81ac  
    34793479  return FALSE;
    34803480}
    3481 static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v);
    3482 static void jjSTD_1_ID(leftv res, ideal i0, int t0, ideal p0, attr a)
    3483 /* destroys i0, p0 */
    3484 /* result (with attributes) in res */
    3485 /* i0: SB*/
    3486 /* t0: type of p0*/
    3487 /* p0 new elements*/
    3488 /* a attributes of i0*/
    3489 {
    3490   int tp;
    3491   if (t0==IDEAL_CMD) tp=POLY_CMD;
    3492   else               tp=VECTOR_CMD;
    3493   for (int i=IDELEMS(p0)-1; i>=0; i--)
    3494   {
    3495     poly p=p0->m[i];
    3496     p0->m[i]=NULL;
    3497     if (p!=NULL)
    3498     {
    3499       sleftv u0,v0;
    3500       memset(&u0,0,sizeof(sleftv));
    3501       memset(&v0,0,sizeof(sleftv));
    3502       v0.rtyp=tp;
    3503       v0.data=(void*)p;
    3504       u0.rtyp=t0;
    3505       u0.data=i0;
    3506       u0.attribute=a;
    3507       setFlag(&u0,FLAG_STD);
    3508       jjSTD_1(res,&u0,&v0);
    3509       i0=(ideal)res->data;
    3510       res->data=NULL;
    3511       a=res->attribute;
    3512       res->attribute=NULL;
    3513       u0.CleanUp();
    3514       v0.CleanUp();
    3515       res->CleanUp();
    3516     }
    3517   }
    3518   idDelete(&p0);
    3519   res->attribute=a;
    3520   res->data=(void *)i0;
    3521   res->rtyp=t0;
    3522 }
    35233481static BOOLEAN jjSTD_1(leftv res, leftv u, leftv v)
    35243482{
     
    35673525  else /*IDEAL/MODULE*/
    35683526  {
    3569     attr *aa=u->Attribute();
    3570     attr a=NULL;
    3571     if ((aa!=NULL)&&(*aa!=NULL)) a=(*aa)->Copy();
    3572     jjSTD_1_ID(res,(ideal)u->CopyD(),r,(ideal)v->CopyD(),a);
     3527    i0=(ideal)v->CopyD();
     3528    int ii0=idElem(i0); /* size of i0 */
     3529    i1=idSimpleAdd(i1,i0); //
     3530    memset(i0->m,0,sizeof(poly)*IDELEMS(i0));
     3531    idDelete(&i0);
     3532    intvec *w=(intvec *)atGet(u,"isHomog",INTVEC_CMD);
     3533    tHomog hom=testHomog;
     3534
     3535    if (w!=NULL)
     3536    {
     3537      if (!idTestHomModule(i1,currRing->qideal,w))
     3538      {
     3539        // no warnung: this is legal, if i in std(i,p)
     3540        // is homogeneous, but p not
     3541        w=NULL;
     3542      }
     3543      else
     3544      {
     3545        w=ivCopy(w);
     3546        hom=isHomog;
     3547      }
     3548    }
     3549    if (ii0*4 >= 3*IDELEMS(i1)) // MAGIC: add few poly to large SB: 3/4
     3550    {
     3551      BITSET save1;
     3552      SI_SAVE_OPT1(save1);
     3553      si_opt_1|=Sy_bit(OPT_SB_1);
     3554      /* ii0 appears to be the position of the first element of il that
     3555       does not belong to the old SB ideal */
     3556      result=kStd(i1,currRing->qideal,hom,&w,NULL,0,ii0);
     3557      SI_RESTORE_OPT1(save1);
     3558    }
     3559    else
     3560    {
     3561      result=kStd(i1,currRing->qideal,hom,&w);
     3562    }
     3563    idDelete(&i1);
     3564    idSkipZeroes(result);
     3565    if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
     3566    res->data = (char *)result;
    35733567  }
    35743568  if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD);
  • Singular/walk.cc

    • Property mode changed from 100644 to 100755
    rcd38fbd r36b81ac  
    1616
    1717//#define TEST_OVERFLOW
    18 //#define CHECK_IDEAL
    19 //#define CHECK_IDEAL_MWALK
     18
     19#define CHECK_IDEAL_MWALK //to print intermediate results
    2020
    2121//#define NEXT_VECTORS_CC
    22 //#define PRINT_VECTORS //to print vectors (sigma, tau, omega)
     22#define PRINT_VECTORS //to print weight vectors
    2323
    2424#define INVEPS_SMALL_IN_FRACTAL  //to choose the small invers of epsilon
     
    2727
    2828#define FIRST_STEP_FRACTAL // to define the first step of the fractal
    29 //#define MSTDCC_FRACTAL // apply Buchberger alg to compute a red GB, if
    30 //                          tau doesn't stay in the correct cone
     29#define MSTDCC_FRACTAL // apply Buchberger alg to compute a red GB, if tau doesn't stay in the correct cone
    3130
    3231//#define TIME_TEST // print the used time of each subroutine
     
    4241#include <Singular/ipshell.h>
    4342#include <Singular/ipconv.h>
     43#include <coeffs/ffields.h>
    4444#include <coeffs/coeffs.h>
    4545#include <Singular/subexpr.h>
     46#include <polys/templates/p_Procs.h>
    4647
    4748#include <polys/monomials/maps.h>
     
    120121 ************************************/
    121122// unused
    122 #if 0
     123/*
    123124static void initSSpecialCC (ideal F, ideal Q, ideal P,kStrategy strat)
    124125{
     
    268269#endif
    269270}
    270 #endif
     271*/
    271272
    272273/*****************
     
    277278  int j;
    278279  kStrategy strat = new skStrategy;
    279 
    280 //  if (TEST_OPT_PROT)
    281 //  {
    282 //    writeTime("start InterRed:");
    283 //    mflush();
    284 //  }
    285   //strat->syzComp     = 0;
     280/*
     281  if (TEST_OPT_PROT)
     282  {
     283    writeTime("start InterRed:");
     284    mflush();
     285  }
     286  strat->syzComp     = 0;
     287*/
    286288  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
    287289  strat->kNoether=pCopy((currRing->ppNoether));
     
    346348    strat->fromQ = NULL;
    347349  }
    348 //  if (TEST_OPT_PROT)
    349 //  {
    350 //    writeTime("end Interred:");
    351 //    mflush();
    352 //  }
     350/*
     351  if (TEST_OPT_PROT)
     352  {
     353    writeTime("end Interred:");
     354    mflush();
     355  }
     356*/
    353357  ideal shdl=strat->Shdl;
    354358  idSkipZeroes(shdl);
     
    358362}
    359363
    360 //unused
    361 #if 0
     364#ifdef TIME_TEST
    362365static void TimeString(clock_t tinput, clock_t tostd, clock_t tif,clock_t tstd,
    363366                       clock_t tlf,clock_t tred, clock_t tnw, int step)
     
    397400        ((((double) xtextra)/1000000)/totm)*100);
    398401}
    399 #endif
    400 
    401 //unused
    402 #if 0
     402
    403403static void TimeStringFractal(clock_t tinput, clock_t tostd, clock_t tif,clock_t tstd,
    404404                       clock_t textra, clock_t tlf,clock_t tred, clock_t tnw)
     
    442442}
    443443#endif
    444 
     444/*
    445445#if defined(CHECK_IDEAL_MWALK) || defined(ENDWALKS)
    446446static void headidString(ideal L, char* st)
     
    496496}
    497497#endif
    498 
     498*/
    499499
    500500static void ivString(intvec* iv, const char* ch)
     
    510510}
    511511
    512 //unused
    513 #if 0
     512#ifdef PRINT_VECTORS
    514513static void MivString(intvec* iva, intvec* ivb, intvec* ivc)
    515514{
     
    558557  }
    559558  return p0;
     559}
     560
     561/*****************************************************************************
     562 * compute the gcd of the entries of the vectors curr_weight and diff_weight *
     563 *****************************************************************************/
     564static int simplify_gcd(intvec* curr_weight, intvec* diff_weight)
     565{
     566  int j;
     567  int nRing = currRing->N;
     568  int gcd_tmp = (*curr_weight)[0];
     569  for (j=1; j<nRing; j++)
     570  {
     571    gcd_tmp = gcd(gcd_tmp, (*curr_weight)[j]);
     572    if(gcd_tmp == 1)
     573    {
     574      break;
     575    }
     576  }
     577  if(gcd_tmp != 1)
     578  {
     579    for (j=0; j<nRing; j++)
     580    {
     581    gcd_tmp = gcd(gcd_tmp, (*diff_weight)[j]);
     582    if(gcd_tmp == 1)
     583      {
     584        break;
     585      }
     586    }
     587  }
     588  return gcd_tmp;
    560589}
    561590
     
    774803  for(i=nG-1; i>=0; i--)
    775804  {
    776     mi = MpolyInitialForm(G->m[i], iv);
    777     gi = G->m[i];
    778 
     805    mi = pHead(MpolyInitialForm(G->m[i], iv));
     806    //Print("\n **// test_w_in_ConeCC: lm(initial)= %s \n",pString(mi));
     807    gi = pHead(G->m[i]);
     808    //Print("\n **// test_w_in_ConeCC: lm(ideal)= %s \n",pString(gi));
    779809    if(mi == NULL)
    780810    {
     
    953983}
    954984
    955 /*****************************************************************************
    956 * create a weight matrix order as intvec of an extra weight vector (a(iv),lp)*
    957 ******************************************************************************/
     985/*********************************************************************************
     986* create a weight matrix order as intvec of an extra weight vector (a(iv),M(iw)) *
     987**********************************************************************************/
    958988intvec* MivMatrixOrderRefine(intvec* iv, intvec* iw)
    959989{
    960   assume(iv->length() == iw->length());
    961   int i, nR = iv->length();
    962 
     990  assume((iv->length())*(iv->length()) == iw->length());
     991  int i,j, nR = iv->length();
     992 
    963993  intvec* ivm = new intvec(nR*nR);
    964994
     
    966996  {
    967997    (*ivm)[i] = (*iv)[i];
    968     (*ivm)[i+nR] = (*iw)[i];
    969   }
    970   for(i=2; i<nR; i++)
    971   {
    972     (*ivm)[i*nR+i-2] = 1;
     998  }
     999  for(i=1; i<nR; i++)
     1000  {
     1001    for(j=0; j<nR; j++)
     1002    {
     1003      (*ivm)[j+i*nR] = (*iw)[j+i*nR];
     1004    }
    9731005  }
    9741006  return ivm;
     
    10051037 * print the max total degree and the max coefficient of G                   *
    10061038 *****************************************************************************/
    1007 #if 0
     1039/*
    10081040static void checkComplexity(ideal G, char* cG)
    10091041{
     
    10461078  PrintLn();
    10471079}
    1048 #endif
     1080*/
    10491081
    10501082/*****************************************************************************
     
    10681100  intvec* v_null =  new intvec(nV);
    10691101
    1070 
    10711102  // Check that the perturbed degree is valid
    10721103  if(pdeg > nV || pdeg <= 0)
     
    10821113  }
    10831114  mpz_t *pert_vector = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
    1084   //mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
     1115  mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
    10851116
    10861117  for(i=0; i<nV; i++)
    10871118  {
    10881119    mpz_init_set_si(pert_vector[i], (*ivtarget)[i]);
    1089    // mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]);
     1120    mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]);
    10901121  }
    10911122  // Calculate max1 = Max(A2)+Max(A3)+...+Max(Apdeg),
     
    11671198    }
    11681199  }
     1200
     1201  // 2147483647 is max. integer representation in SINGULAR
     1202  mpz_t sing_int;
     1203  mpz_init_set_ui(sing_int,  2147483647);
     1204
     1205  mpz_t check_int;
     1206  mpz_init_set_ui(check_int,  100000);
     1207
    11691208  mpz_t ztemp;
    11701209  mpz_init(ztemp);
     
    11861225  }
    11871226
    1188   intvec *pert_vector1= new intvec(nV);
    1189   j = 0;
    11901227  for(i=0; i<nV; i++)
    11911228  {
    1192     (* pert_vector1)[i] = mpz_get_si(pert_vector[i]);
    1193     (* pert_vector1)[i] = 0.1*(* pert_vector1)[i];
    1194     (* pert_vector1)[i] = floor((* pert_vector1)[i] + 0.5);
    1195     if((* pert_vector1)[i] == 0)
    1196     {
    1197       j++;
    1198     }
    1199   }
    1200   if(j > nV - 1)
    1201   {
    1202     // Print("\n//  MPertVectors: geaenderter vector gleich Null! \n");
    1203     delete pert_vector1;
    1204     goto CHECK_OVERFLOW;
    1205   }
    1206 
    1207 // check that the perturbed weight vector lies in the Groebner cone
    1208   if(test_w_in_ConeCC(G,pert_vector1) != 0)
    1209   {
    1210     // Print("\n//  MPertVectors: geaenderter vector liegt in Groebnerkegel! \n");
     1229    if(mpz_cmp(pert_vector[i], check_int)>=0)
     1230    {
     1231      for(j=0; j<nV; j++)
     1232      {
     1233        mpz_fdiv_q_ui(pert_vector1[j], pert_vector[j], 100);
     1234      }
     1235    }
     1236  }
     1237
     1238  intvec* result = new intvec(nV);
     1239
     1240  int ntrue=0;
     1241
     1242  for(i=0; i<nV; i++)
     1243  {
     1244    (*result)[i] = mpz_get_si(pert_vector1[i]);
     1245    if(mpz_cmp(pert_vector1[i], sing_int)>=0)
     1246    {
     1247      ntrue++;
     1248    }
     1249  }
     1250  if(ntrue > 0 || test_w_in_ConeCC(G,result)==0)
     1251  {
     1252    ntrue=0;
    12111253    for(i=0; i<nV; i++)
    12121254    {
    1213       mpz_set_si(pert_vector[i], (*pert_vector1)[i]);
    1214     }
    1215   }
    1216   else
    1217   {
    1218     //Print("\n// MpertVectors: geaenderter vector liegt nicht in Groebnerkegel! \n");
    1219   }
    1220   delete pert_vector1;
    1221 
    1222   CHECK_OVERFLOW:
    1223   intvec* result = new intvec(nV);
    1224 
    1225   /* 2147483647 is max. integer representation in SINGULAR */
    1226   mpz_t sing_int;
    1227   mpz_init_set_ui(sing_int,  2147483647);
    1228 
    1229   int ntrue=0;
    1230   for(i=0; i<nV; i++)
    1231   {
    1232     (*result)[i] = mpz_get_si(pert_vector[i]);
    1233     if(mpz_cmp(pert_vector[i], sing_int)>=0)
    1234     {
    1235       ntrue++;
    1236       if(Overflow_Error == FALSE)
    1237       {
    1238         Overflow_Error = TRUE;
    1239         PrintS("\n// ** OVERFLOW in \"MPertvectors\": ");
    1240         mpz_out_str( stdout, 10, pert_vector[i]);
    1241         PrintS(" is greater than 2147483647 (max. integer representation)");
    1242         Print("\n//  So vector[%d] := %d is wrong!!", i+1, (*result)[i]);
    1243       }
    1244     }
    1245   }
    1246 
    1247   if(Overflow_Error == TRUE)
    1248   {
    1249     ivString(result, "pert_vector");
    1250     Print("\n// %d element(s) of it is overflow!!", ntrue);
     1255      (*result)[i] = mpz_get_si(pert_vector[i]);
     1256      if(mpz_cmp(pert_vector[i], sing_int)>=0)
     1257      {
     1258        ntrue++;
     1259        if(Overflow_Error == FALSE)
     1260        {
     1261          Overflow_Error = TRUE;
     1262          PrintS("\n// ** OVERFLOW in \"MPertvectors\": ");
     1263          mpz_out_str( stdout, 10, pert_vector[i]);
     1264          PrintS(" is greater than 2147483647 (max. integer representation)");
     1265          Print("\n//  So vector[%d] := %d is wrong!!", i+1, (*result)[i]);
     1266        }
     1267      }
     1268    }
     1269
     1270    if(Overflow_Error == TRUE)
     1271    {
     1272      ivString(result, "pert_vector");
     1273      Print("\n// %d element(s) of it is overflow!!", ntrue);
     1274    }
    12511275  }
    12521276
    12531277  mpz_clear(ztemp);
    12541278  mpz_clear(sing_int);
     1279  mpz_clear(check_int);
    12551280  omFree(pert_vector);
    1256   //omFree(pert_vector1);
     1281  omFree(pert_vector1);
    12571282  mpz_clear(tot_deg);
    12581283  mpz_clear(maxdeg);
     
    14561481
    14571482//unused
    1458 #if 0
     1483/*
    14591484static intvec* MatrixOrderdp(int nV)
    14601485{
     
    14721497  return(ivM);
    14731498}
    1474 #endif
     1499*/
    14751500
    14761501intvec* MivUnit(int nV)
     
    15491574    mpz_cdiv_q_ui(inveps, inveps, nV);
    15501575  }
    1551   //PrintS("\n// choose the \"small\" inverse epsilon!");
     1576  // choose the small inverse epsilon
    15521577#endif
    15531578
     
    15831608
    15841609    for(j=0; j<nV; j++)
    1585       {
     1610    {
    15861611      mpz_init_set(pert_vector[i*nV+j],ivtemp[j]);
    1587       }
    1588   }
    1589 
    1590   /* 2147483647 is max. integer representation in SINGULAR */
     1612    }
     1613  }
     1614
     1615  // 2147483647 is max. integer representation in SINGULAR
    15911616  mpz_t sing_int;
    15921617  mpz_init_set_ui(sing_int,  2147483647);
     
    16111636    mpz_divexact(pert_vector[i], pert_vector[i], ztmp);
    16121637    (* result)[i] = mpz_get_si(pert_vector[i]);
    1613   }
    1614 
    1615   j = 0;
    1616   for(i=0; i<nV; i++)
    1617   {
    1618     (* result1)[i] = mpz_get_si(pert_vector[i]);
    1619     (* result1)[i] = 0.1*(* result1)[i];
    1620     (* result1)[i] = floor((* result1)[i] + 0.5);
    1621     if((* result1)[i] == 0)
    1622     {
    1623       j++;
    1624     }
    1625   }
    1626   if(j > nV - 1)
    1627   {
    1628     // Print("\n//  MfPertwalk: geaenderter vector gleich Null! \n");
    1629     delete result1;
    1630     goto CHECK_OVERFLOW;
    1631   }
    1632 
    1633 // check that the perturbed weight vector lies in the Groebner cone
    1634   if(test_w_in_ConeCC(G,result1) != 0)
    1635   {
    1636     // Print("\n//  MfPertwalk: geaenderter vector liegt in Groebnerkegel! \n");
    1637     delete result;
    1638     result = result1;
    1639     for(i=0; i<nV; i++)
    1640     {
    1641       mpz_set_si(pert_vector[i], (*result1)[i]);
    1642     }
    1643   }
    1644   else
    1645   {
    1646     delete result1;
    1647     // Print("\n// Mfpertwalk: geaenderter vector liegt nicht in Groebnerkegel! \n");
    16481638  }
    16491639
     
    16851675    while(p!=NULL)
    16861676    {
    1687       p_Setm(p,currRing); pIter(p);
     1677      p_Setm(p,currRing);
     1678      pIter(p);
    16881679    }
    16891680  }
     
    17681759
    17691760//unused
    1770 #if 0
     1761/*
    17711762static void checkidealCC(ideal G, char* Ch)
    17721763{
     
    17941785  PrintLn();
    17951786}
    1796 #endif
     1787*/
    17971788
    17981789//unused
    1799 #if 0
     1790/*
    18001791static void HeadidString(ideal L, char* st)
    18011792{
     
    18091800  Print(" %s;\n", pString(pHead(L->m[nL])));
    18101801}
    1811 #endif
    1812 
     1802
     1803*/
    18131804static inline int MivComp(intvec* iva, intvec* ivb)
    18141805{
     
    18591850}
    18601851
     1852
     1853/**************************************************************
     1854 * Look for the position of the smallest absolut value in vec *
     1855 **************************************************************/
     1856static int MivAbsMaxArg(intvec* vec)
     1857{
     1858  int k = MivAbsMax(vec);
     1859  int i=0;
     1860  while(1)
     1861  {
     1862    if((*vec)[i] == k || (*vec)[i] == -k)
     1863    {
     1864      break;
     1865    }
     1866    i++;
     1867  }
     1868  return i;
     1869}
     1870
     1871
    18611872/**********************************************************************
    18621873 * Compute a next weight vector between curr_weight and target_weight *
    18631874 * with respect to an ideal <G>.                                      *
    18641875**********************************************************************/
     1876/*
    18651877static intvec* MwalkNextWeightCC(intvec* curr_weight, intvec* target_weight,
    18661878                                 ideal G)
     
    18731885
    18741886  int nRing = currRing->N;
    1875   int checkRed, j, kkk, nG = IDELEMS(G);
     1887  int checkRed, j, nG = IDELEMS(G);
    18761888  intvec* ivtemp;
    18771889
     
    19111923  mpz_init(dcw);
    19121924
    1913   //int tn0, tn1, tz1, ncmp, gcd_tmp, ntmp;
    19141925  int gcd_tmp;
    19151926  intvec* diff_weight = MivSub(target_weight, curr_weight);
     
    19171928  intvec* diff_weight1 = MivSub(target_weight, curr_weight);
    19181929  poly g;
    1919   //poly g, gw;
     1930
    19201931  for (j=0; j<nG; j++)
    19211932  {
     
    19341945        mpz_set_si(MwWd, MivDotProduct(ivtemp, curr_weight));
    19351946        mpz_sub(s_zaehler, deg_w0_p1, MwWd);
    1936 
    19371947        if(mpz_cmp(s_zaehler, t_null) != 0)
    19381948        {
    19391949          mpz_set_si(MwWd, MivDotProduct(ivtemp, diff_weight));
    19401950          mpz_sub(s_nenner, MwWd, deg_d0_p1);
    1941 
    19421951          // check for 0 < s <= 1
    19431952          if( (mpz_cmp(s_zaehler,t_null) > 0 &&
     
    19791988    }
    19801989  }
    1981 //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
     1990  //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
    19821991  mpz_t *vec=(mpz_t*)omAlloc(nRing*sizeof(mpz_t));
    19831992
    19841993
    1985   // there is no 0<t<1 and define the next weight vector that is equal to the current weight vector
     1994  // there is no 0<t<1 and define the next weight vector that is equal
     1995  // to the current weight vector
    19861996  if(mpz_cmp(t_nenner, t_null) == 0)
    19871997  {
    1988     #ifndef SING_NDEBUG
    1989     Print("\n//MwalkNextWeightCC: t_nenner ist Null!");
    1990     #endif
     1998#ifndef SING_NDEBUG
     1999    Print("\n//MwalkNextWeightCC: t_nenner=0\n");
     2000#endif
    19912001    delete diff_weight;
    19922002    diff_weight = ivCopy(curr_weight);//take memory
     
    20542064#endif
    20552065
    2056   //  BOOLEAN isdwpos;
    2057 
    2058   // construct a new weight vector
     2066// construct a new weight vector and check whether vec[j] is overflow,
     2067// i.e. vec[j] > 2^31.
     2068// If vec[j] doesn't overflow, define a weight vector. Otherwise,
     2069// report that overflow appears. In the second case, test whether the
     2070// the correctness of the new vector plays an important role
     2071
    20592072  for (j=0; j<nRing; j++)
    20602073  {
     
    21002113    }
    21012114  }
    2102 
     2115  // reduce the vector with the gcd
     2116  if(mpz_cmp_si(ggt,1) != 0)
     2117  {
     2118    for (j=0; j<nRing; j++)
     2119    {
     2120      mpz_divexact(vec[j], vec[j], ggt);
     2121    }
     2122  }
    21032123#ifdef  NEXT_VECTORS_CC
    21042124  PrintS("\n// gcd of elements of the vector: ");
     
    21062126#endif
    21072127
    2108 /**********************************************************************
    2109 * construct a new weight vector and check whether vec[j] is overflow, *
    2110 * i.e. vec[j] > 2^31.                                                 *
    2111 * If vec[j] doesn't overflow, define a weight vector. Otherwise,      *
    2112 * report that overflow appears. In the second case, test whether the  *
    2113 * the correctness of the new vector plays an important role           *
    2114 **********************************************************************/
    2115   kkk=0;
    21162128  for(j=0; j<nRing; j++)
    2117     {
     2129  {
    21182130    if(mpz_cmp(vec[j], sing_int_half) >= 0)
    2119       {
     2131    {
    21202132      goto REDUCTION;
    2121       }
    2122     }
     2133    }
     2134  }
    21232135  checkRed = 1;
    21242136  for (j=0; j<nRing; j++)
     
    21292141
    21302142  REDUCTION:
     2143  checkRed = 1;
    21312144  for (j=0; j<nRing; j++)
    21322145  {
    2133     (*diff_weight)[j] = mpz_get_si(vec[j]);
    2134   }
    2135   while(MivAbsMax(diff_weight) >= 5)
    2136   {
    2137     for (j=0; j<nRing; j++)
    2138     {
    2139       if(mpz_cmp_si(ggt,1)==0)
    2140       {
    2141         (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
    2142         // Print("\n//  vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
    2143       }
    2144       else
    2145       {
    2146         mpz_divexact(vec[j], vec[j], ggt);
    2147         (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
    2148         // Print("\n//  vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
    2149       }
    2150 /*
    2151       if((*diff_weight1)[j] == 0)
    2152       {
    2153         kkk = kkk + 1;
    2154       }
    2155 */
    2156     }
    2157 
    2158 
    2159 /*
    2160     if(kkk > nRing - 1)
    2161     {
    2162       // diff_weight was reduced to zero
    2163       // Print("\n // MwalkNextWeightCC: geaenderter Vector gleich Null! \n");
    2164       goto TEST_OVERFLOW;
    2165     }
    2166 */
    2167 
    2168     if(test_w_in_ConeCC(G,diff_weight1) != 0)
    2169     {
    2170       Print("\n// MwalkNextWeightCC: geaenderter vector liegt in Groebnerkegel! \n");
    2171       for (j=0; j<nRing; j++)
    2172       {
    2173         (*diff_weight)[j] = (*diff_weight1)[j];
    2174       }
    2175       if(MivAbsMax(diff_weight) < 5)
    2176       {
    2177         checkRed = 1;
    2178         goto SIMPLIFY_GCD;
    2179       }
    2180     }
    2181     else
    2182     {
    2183       // Print("\n// MwalkNextWeightCC: geaenderter vector liegt nicht in Groebnerkegel! \n");
    2184       break;
    2185     }
     2146    (*diff_weight1)[j] = mpz_get_si(vec[j]);
     2147  }
     2148  while(test_w_in_ConeCC(G,diff_weight1))
     2149  {
     2150    for(j=0; j<nRing; j++)
     2151    {
     2152      (*diff_weight)[j] = (*diff_weight1)[j];
     2153      mpz_set_si(vec[j], (*diff_weight)[j]);     
     2154    }
     2155    for(j=0; j<nRing; j++)
     2156    {
     2157      (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
     2158    }
     2159  }
     2160  if(MivAbsMax(diff_weight)>10000)
     2161  {
     2162    for(j=0; j<nRing; j++)
     2163    {
     2164      (*diff_weight1)[j] = (*diff_weight)[j];
     2165    }
     2166    j = 0;
     2167    while(test_w_in_ConeCC(G,diff_weight1))
     2168    {
     2169      (*diff_weight)[j] = (*diff_weight1)[j];
     2170      mpz_set_si(vec[j], (*diff_weight)[j]);
     2171      j = MivAbsMaxArg(diff_weight1);
     2172      (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
     2173    }
     2174    goto SIMPLIFY_GCD;
    21862175  }
    21872176
     
    22222211   mpz_clear(t_null);
    22232212
    2224 
    2225 
    22262213  if(Overflow_Error == FALSE)
    22272214  {
    22282215    Overflow_Error = nError;
    22292216  }
    2230  rComplete(currRing);
    2231   for(kkk=0; kkk<IDELEMS(G);kkk++)
    2232   {
    2233     poly p=G->m[kkk];
     2217  rComplete(currRing);
     2218  for(j=0; j<IDELEMS(G); j++)
     2219  {
     2220    poly p=G->m[j];
    22342221    while(p!=NULL)
    22352222    {
     
    22402227return diff_weight;
    22412228}
     2229*/
     2230/**********************************************************************
     2231 * Compute a next weight vector between curr_weight and target_weight *
     2232 * with respect to an ideal <G>.                                      *
     2233**********************************************************************/
     2234static intvec* MwalkNextWeightCC(intvec* curr_weight, intvec* target_weight,
     2235                                 ideal G)
     2236{
     2237  BOOLEAN nError = Overflow_Error;
     2238  Overflow_Error = FALSE;
     2239
     2240  assume(currRing != NULL && curr_weight != NULL &&
     2241         target_weight != NULL && G != NULL);
     2242
     2243  int nRing = currRing->N;
     2244  int checkRed, j, nG = IDELEMS(G);
     2245  intvec* ivtemp;
     2246
     2247  mpz_t t_zaehler, t_nenner;
     2248  mpz_init(t_zaehler);
     2249  mpz_init(t_nenner);
     2250
     2251  mpz_t s_zaehler, s_nenner, temp, MwWd;
     2252  mpz_init(s_zaehler);
     2253  mpz_init(s_nenner);
     2254  mpz_init(temp);
     2255  mpz_init(MwWd);
     2256
     2257  mpz_t sing_int;
     2258  mpz_init(sing_int);
     2259  mpz_set_si(sing_int,  2147483647);
     2260
     2261  mpz_t sing_int_half;
     2262  mpz_init(sing_int_half);
     2263  mpz_set_si(sing_int_half,  3*(1073741824/2));
     2264
     2265  mpz_t deg_w0_p1, deg_d0_p1;
     2266  mpz_init(deg_w0_p1);
     2267  mpz_init(deg_d0_p1);
     2268
     2269  mpz_t sztn, sntz;
     2270  mpz_init(sztn);
     2271  mpz_init(sntz);
     2272
     2273  mpz_t t_null;
     2274  mpz_init(t_null);
     2275
     2276  mpz_t ggt;
     2277  mpz_init(ggt);
     2278
     2279  mpz_t dcw;
     2280  mpz_init(dcw);
     2281
     2282  int gcd_tmp;
     2283  //intvec* diff_weight = MivSub(target_weight, curr_weight);
     2284
     2285  intvec* diff_weight1 = new intvec(nRing); //MivSub(target_weight, curr_weight);
     2286  poly g;
     2287
     2288  // reduce the size of the entries of the current weight vector
     2289  if(TEST_OPT_REDSB)
     2290  {
     2291    for (j=0; j<nRing; j++)
     2292    {
     2293      (*diff_weight1)[j] = (*curr_weight)[j];
     2294    }
     2295    while(MivAbsMax(diff_weight1)>10000 && test_w_in_ConeCC(G,diff_weight1)==1)
     2296    {
     2297      for(j=0; j<nRing; j++)
     2298      {
     2299        (*curr_weight)[j] = (*diff_weight1)[j]; 
     2300      }
     2301      for(j=0; j<nRing; j++)
     2302      {
     2303        (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
     2304      }
     2305    }
     2306
     2307    if(MivAbsMax(curr_weight)>100000)
     2308    {
     2309      for(j=0; j<nRing; j++)
     2310      {
     2311        (*diff_weight1)[j] = (*curr_weight)[j];
     2312      }
     2313      j = 0;
     2314      while(test_w_in_ConeCC(G,diff_weight1)==1 && MivAbsMax(diff_weight1)>1000)
     2315      {
     2316        (*curr_weight)[j] = (*diff_weight1)[j];
     2317        j = MivAbsMaxArg(diff_weight1);
     2318        (*diff_weight1)[j] = floor(0.1*(*diff_weight1)[j] + 0.5);
     2319      }
     2320    }
     2321
     2322  }
     2323  intvec* diff_weight = MivSub(target_weight, curr_weight);
     2324
     2325  // compute a suitable next weight vector
     2326  for (j=0; j<nG; j++)
     2327  {
     2328    g = G->m[j];
     2329    if (g != NULL)
     2330    {
     2331      ivtemp = MExpPol(g);
     2332      mpz_set_si(deg_w0_p1, MivDotProduct(ivtemp, curr_weight));
     2333      mpz_set_si(deg_d0_p1, MivDotProduct(ivtemp, diff_weight));
     2334      delete ivtemp;
     2335
     2336      pIter(g);
     2337      while (g != NULL)
     2338      {
     2339        ivtemp = MExpPol(g);
     2340        mpz_set_si(MwWd, MivDotProduct(ivtemp, curr_weight));
     2341        mpz_sub(s_zaehler, deg_w0_p1, MwWd);
     2342        if(mpz_cmp(s_zaehler, t_null) != 0)
     2343        {
     2344          mpz_set_si(MwWd, MivDotProduct(ivtemp, diff_weight));
     2345          mpz_sub(s_nenner, MwWd, deg_d0_p1);
     2346          // check for 0 < s <= 1
     2347          if( (mpz_cmp(s_zaehler,t_null) > 0 &&
     2348               mpz_cmp(s_nenner, s_zaehler)>=0) ||
     2349              (mpz_cmp(s_zaehler, t_null) < 0 &&
     2350               mpz_cmp(s_nenner, s_zaehler)<=0))
     2351          {
     2352            // make both positive
     2353            if (mpz_cmp(s_zaehler, t_null) < 0)
     2354            {
     2355              mpz_neg(s_zaehler, s_zaehler);
     2356              mpz_neg(s_nenner, s_nenner);
     2357            }
     2358
     2359            //compute a simple fraction of s
     2360            cancel(s_zaehler, s_nenner);
     2361
     2362            if(mpz_cmp(t_nenner, t_null) != 0)
     2363            {
     2364              mpz_mul(sztn, s_zaehler, t_nenner);
     2365              mpz_mul(sntz, s_nenner, t_zaehler);
     2366
     2367              if(mpz_cmp(sztn,sntz) < 0)
     2368              {
     2369                mpz_add(t_nenner, t_null, s_nenner);
     2370                mpz_add(t_zaehler,t_null, s_zaehler);
     2371              }
     2372            }
     2373            else
     2374            {
     2375              mpz_add(t_nenner, t_null, s_nenner);
     2376              mpz_add(t_zaehler,t_null, s_zaehler);
     2377            }
     2378          }
     2379        }
     2380        pIter(g);
     2381        delete ivtemp;
     2382      }
     2383    }
     2384  }
     2385  //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
     2386  mpz_t *vec=(mpz_t*)omAlloc(nRing*sizeof(mpz_t));
     2387
     2388
     2389  // there is no 0<t<1 and define the next weight vector that is equal
     2390  // to the current weight vector
     2391  if(mpz_cmp(t_nenner, t_null) == 0)
     2392  {
     2393#ifndef SING_NDEBUG
     2394    Print("\n//MwalkNextWeightCC: t_nenner=0\n");
     2395#endif
     2396    delete diff_weight;
     2397    diff_weight = ivCopy(curr_weight);//take memory
     2398    goto FINISH;
     2399  }
     2400
     2401  // define the target vector as the next weight vector, if t = 1
     2402  if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
     2403  {
     2404    delete diff_weight;
     2405    diff_weight = ivCopy(target_weight); //this takes memory
     2406    goto FINISH;
     2407  }
     2408
     2409   //checkRed = 0;
     2410
     2411  SIMPLIFY_GCD:
     2412
     2413  // simplify the vectors curr_weight and diff_weight (C-int)
     2414  gcd_tmp = (*curr_weight)[0];
     2415
     2416  for (j=1; j<nRing; j++)
     2417  {
     2418    gcd_tmp = gcd(gcd_tmp, (*curr_weight)[j]);
     2419    if(gcd_tmp == 1)
     2420    {
     2421      break;
     2422    }
     2423  }
     2424  if(gcd_tmp != 1)
     2425  {
     2426    for (j=0; j<nRing; j++)
     2427    {
     2428      gcd_tmp = gcd(gcd_tmp, (*diff_weight)[j]);
     2429      if(gcd_tmp == 1)
     2430      {
     2431        break;
     2432      }
     2433    }
     2434  }
     2435  if(gcd_tmp != 1)
     2436  {
     2437    for (j=0; j<nRing; j++)
     2438    {
     2439      (*curr_weight)[j] =  (*curr_weight)[j]/gcd_tmp;
     2440      (*diff_weight)[j] =  (*diff_weight)[j]/gcd_tmp;
     2441    }
     2442  }
     2443  if(checkRed > 0)
     2444  {
     2445    for (j=0; j<nRing; j++)
     2446    {
     2447      mpz_set_si(vec[j], (*diff_weight)[j]);
     2448    }
     2449    goto TEST_OVERFLOW;
     2450  }
     2451
     2452#ifdef  NEXT_VECTORS_CC
     2453  Print("\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
     2454  ivString(curr_weight, "new cw");
     2455  ivString(diff_weight, "new dw");
     2456
     2457  PrintS("\n// t_zaehler: ");  mpz_out_str( stdout, 10, t_zaehler);
     2458  PrintS(", t_nenner: ");  mpz_out_str( stdout, 10, t_nenner);
     2459#endif
     2460
     2461// construct a new weight vector and check whether vec[j] is overflow, i.e. vec[j] > 2^31.
     2462// If vec[j] doesn't overflow, define a weight vector. Otherwise, report that overflow
     2463// appears. In the second case, test whether the the correctness of the new vector plays
     2464// an important role
     2465
     2466  for (j=0; j<nRing; j++)
     2467  {
     2468    mpz_set_si(dcw, (*curr_weight)[j]);
     2469    mpz_mul(s_nenner, t_nenner, dcw);
     2470
     2471    if( (*diff_weight)[j]>0)
     2472    {
     2473      mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
     2474    }
     2475    else
     2476    {
     2477      mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
     2478      mpz_neg(s_zaehler, s_zaehler);
     2479    }
     2480    mpz_add(sntz, s_nenner, s_zaehler);
     2481    mpz_init_set(vec[j], sntz);
     2482
     2483#ifdef NEXT_VECTORS_CC
     2484    Print("\n//   j = %d ==> ", j);
     2485    PrintS("(");
     2486    mpz_out_str( stdout, 10, t_nenner);
     2487    Print(" * %d)", (*curr_weight)[j]);
     2488    Print(" + ("); mpz_out_str( stdout, 10, t_zaehler);
     2489    Print(" * %d) =  ",  (*diff_weight)[j]);
     2490    mpz_out_str( stdout, 10, s_nenner);
     2491    PrintS(" + ");
     2492    mpz_out_str( stdout, 10, s_zaehler);
     2493    PrintS(" = "); mpz_out_str( stdout, 10, sntz);
     2494    Print(" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
     2495#endif
     2496
     2497    if(j==0)
     2498    {
     2499      mpz_set(ggt, sntz);
     2500    }
     2501    else
     2502    {
     2503      if(mpz_cmp_si(ggt,1) != 0)
     2504      {
     2505        mpz_gcd(ggt, ggt, sntz);
     2506      }
     2507    }
     2508  }
     2509  // reduce the vector with the gcd
     2510  if(mpz_cmp_si(ggt,1) != 0)
     2511  {
     2512    for (j=0; j<nRing; j++)
     2513    {
     2514      mpz_divexact(vec[j], vec[j], ggt);
     2515    }
     2516  }
     2517#ifdef  NEXT_VECTORS_CC
     2518  PrintS("\n// gcd of elements of the vector: ");
     2519  mpz_out_str( stdout, 10, ggt);
     2520#endif
     2521
     2522  for (j=0; j<nRing; j++)
     2523  {
     2524    (*diff_weight)[j] = mpz_get_si(vec[j]);
     2525  }
     2526
     2527 TEST_OVERFLOW:
     2528
     2529  for (j=0; j<nRing; j++)
     2530  {
     2531    if(mpz_cmp(vec[j], sing_int)>=0)
     2532    {
     2533      if(Overflow_Error == FALSE)
     2534      {
     2535        Overflow_Error = TRUE;
     2536        PrintS("\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
     2537        mpz_out_str( stdout, 10, vec[j]);
     2538        PrintS(" is greater than 2147483647 (max. integer representation)\n");
     2539        Print("//  So vector[%d] := %d is wrong!!\n",j+1, vec[j]);// vec[j] is mpz_t
     2540      }
     2541    }
     2542  }
     2543
     2544 FINISH:
     2545   delete diff_weight1;
     2546   mpz_clear(t_zaehler);
     2547   mpz_clear(t_nenner);
     2548   mpz_clear(s_zaehler);
     2549   mpz_clear(s_nenner);
     2550   mpz_clear(sntz);
     2551   mpz_clear(sztn);
     2552   mpz_clear(temp);
     2553   mpz_clear(MwWd);
     2554   mpz_clear(deg_w0_p1);
     2555   mpz_clear(deg_d0_p1);
     2556   mpz_clear(ggt);
     2557   omFree(vec);
     2558   mpz_clear(sing_int_half);
     2559   mpz_clear(sing_int);
     2560   mpz_clear(dcw);
     2561   mpz_clear(t_null);
     2562
     2563  if(Overflow_Error == FALSE)
     2564  {
     2565    Overflow_Error = nError;
     2566  }
     2567  rComplete(currRing);
     2568  for(j=0; j<IDELEMS(G); j++)
     2569  {
     2570    poly p=G->m[j];
     2571    while(p!=NULL)
     2572    {
     2573      p_Setm(p,currRing);
     2574      pIter(p);
     2575    }
     2576  }
     2577return diff_weight;
     2578}
     2579
    22422580
    22432581/**********************************************************************
     
    22712609}
    22722610
    2273 /**************************************************************
     2611/********************************************************************
    22742612 * define and execute a new ring which order is (a(vb),a(va),lp,C)  *
    2275  * ************************************************************/
    2276 #if 0
    2277 // unused
     2613 * ******************************************************************/
    22782614static void VMrHomogeneous(intvec* va, intvec* vb)
    22792615{
     
    23532689  rChangeCurrRing(r);
    23542690}
    2355 #endif
     2691
    23562692
    23572693/**************************************************************
     
    24282764}
    24292765
    2430 static ring VMrDefault1(intvec* va)
    2431 {
    2432 
    2433   if ((currRing->ppNoether)!=NULL)
    2434   {
    2435     pDelete(&(currRing->ppNoether));
    2436   }
    2437   if (((sLastPrinted.rtyp>BEGIN_RING) && (sLastPrinted.rtyp<END_RING)) ||
    2438       ((sLastPrinted.rtyp==LIST_CMD)&&(lRingDependend((lists)sLastPrinted.data))))
    2439   {
    2440     sLastPrinted.CleanUp();
    2441   }
    2442 
    2443   ring r = (ring) omAlloc0Bin(sip_sring_bin);
    2444   int i, nv = currRing->N;
    2445 
    2446   r->cf  = currRing->cf;
    2447   r->N   = currRing->N;
    2448 
    2449   int nb = 4;
    2450 
    2451   //names
    2452   char* Q; // In order to avoid the corrupted memory, do not change.
    2453   r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
    2454   for(i=0; i<nv; i++)
    2455   {
    2456     Q = currRing->names[i];
    2457     r->names[i]  = omStrDup(Q);
    2458   }
    2459 
    2460   /*weights: entries for 3 blocks: NULL Made:???*/
    2461   r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
    2462   r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
    2463   for(i=0; i<nv; i++)
    2464     r->wvhdl[0][i] = (*va)[i];
    2465 
    2466   /* order: a,lp,C,0 */
    2467   r->order = (int *) omAlloc(nb * sizeof(int *));
    2468   r->block0 = (int *)omAlloc0(nb * sizeof(int *));
    2469   r->block1 = (int *)omAlloc0(nb * sizeof(int *));
    2470 
    2471   // ringorder a for the first block: var 1..nv
    2472   r->order[0]  = ringorder_a;
    2473   r->block0[0] = 1;
    2474   r->block1[0] = nv;
    2475 
    2476   // ringorder lp for the second block: var 1..nv
    2477   r->order[1]  = ringorder_lp;
    2478   r->block0[1] = 1;
    2479   r->block1[1] = nv;
    2480 
    2481   // ringorder C for the third block
    2482   // it is very important within "idLift",
    2483   // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
    2484   // therefore, nb  must be (nBlocks(currRing)  + 1)
    2485   r->order[2]  = ringorder_C;
    2486 
    2487   // the last block: everything is 0
    2488   r->order[3]  = 0;
    2489 
    2490   // polynomial ring
    2491   r->OrdSgn    = 1;
    2492 
    2493   // complete ring intializations
    2494 
    2495   rComplete(r);
    2496 
    2497   //rChangeCurrRing(r);
    2498   return r;
    2499 }
    2500 
    25012766/****************************************************************
    25022767 * define and execute a new ring with ordering (a(va),Wp(vb),C) *
    25032768 * **************************************************************/
    2504 
    25052769static ring VMrRefine(intvec* va, intvec* vb)
    25062770{
     
    25762840
    25772841  // complete ring intializations
    2578 
     2842 
    25792843  rComplete(r);
    25802844
     
    28063070}
    28073071
    2808 
    2809 /* define a ring with parameters und change to it */
    2810 /* DefRingPar and DefRingParlp corrupt still memory */
     3072/***************************************************
     3073* define a ring with parameters und change to it   *
     3074* DefRingPar and DefRingParlp corrupt still memory *
     3075****************************************************/
    28113076static void DefRingPar(intvec* va)
    28123077{
     
    29563221}
    29573222
    2958 //unused
    2959 /**************************************************************
    2960  * check wheather one or more components of a vector are zero *
    2961  **************************************************************/
    2962 #if 0
     3223/*************************************************************
     3224 * check whether one or more components of a vector are zero *
     3225 *************************************************************/
    29633226static int isNolVector(intvec* hilb)
    29643227{
     
    29733236  return 0;
    29743237}
    2975 #endif
     3238
     3239/*************************************************************
     3240 * check whether one or more components of a vector are <= 0 *
     3241 *************************************************************/
     3242static int isNegNolVector(intvec* hilb)
     3243{
     3244  int i;
     3245  for(i=hilb->length()-1; i>=0; i--)
     3246  {
     3247    if((* hilb)[i]<=0)
     3248    {
     3249      return 1;
     3250    }
     3251  }
     3252  return 0;
     3253}
     3254
     3255/**************************************************************************
     3256* Gomega is the initial ideal of G w. r. t. the current weight vector     *
     3257* curr_weight. Check whether curr_weight lies on a border of the Groebner *
     3258* cone, i. e. check whether a monomial is divisible by a leading monomial *
     3259***************************************************************************/
     3260static ideal middleOfCone(ideal G, ideal Gomega)
     3261{
     3262  BOOLEAN middle = FALSE;
     3263  int i,j,N = IDELEMS(Gomega);
     3264  poly p,lm,factor1,factor2;
     3265
     3266  ideal Go = idCopy(G);
     3267 
     3268  // check whether leading monomials of G and Gomega coincide
     3269  // and return NULL if not
     3270  for(i=0; i<N; i++)
     3271  {
     3272    if(!pIsConstant(pSub(pCopy(Gomega->m[i]),pCopy(pHead(G->m[i])))))
     3273    {
     3274      idDelete(&Go);
     3275      return NULL;
     3276    }
     3277  }
     3278  for(i=0; i<N; i++)
     3279  {
     3280    for(j=0; j<N; j++)
     3281    {
     3282      if(i!=j)
     3283      {
     3284        p = pCopy(Gomega->m[i]);
     3285        lm = pCopy(Gomega->m[j]);
     3286        pIter(p);
     3287        while(p!=NULL)
     3288        {
     3289          if(pDivisibleBy(lm,p))
     3290          {
     3291            if(middle == FALSE)
     3292            {
     3293              middle = TRUE;
     3294            }
     3295            factor1 = singclap_pdivide(pHead(p),lm,currRing);
     3296            factor2 = pMult(pCopy(factor1),pCopy(Go->m[j]));
     3297            pDelete(&factor1);
     3298            Go->m[i] = pAdd((Go->m[i]),pNeg(pCopy(factor2)));
     3299            pDelete(&factor2);
     3300          }
     3301          pIter(p);
     3302        }
     3303        pDelete(&lm);
     3304        pDelete(&p);
     3305      }
     3306    }
     3307  }
     3308
     3309  if(middle == TRUE)
     3310  {
     3311    return Go;
     3312  }
     3313  idDelete(&Go);
     3314  return NULL;
     3315}
    29763316
    29773317/******************************  Februar 2002  ****************************
     
    31043444    {
    31053445      Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
     3446/*
    31063447      idElements(Gomega, "Gw");
    31073448      headidString(Gomega, "Gw");
     3449*/
    31083450    }
    31093451#endif
     
    31283470    else
    31293471    {
    3130       rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
     3472      rChangeCurrRing(VMrDefault(curr_weight));
    31313473    }
    31323474    newRing = currRing;
     
    32553597
    32563598/**********************************************************
    3257  * check whether a polynomial of G has least 3 monomials  *
     3599 * check whether a polynomial of G has least 4 monomials  *
    32583600 **********************************************************/
    32593601static int lengthpoly(ideal G)
     
    32623604  for(i=IDELEMS(G)-1; i>=0; i--)
    32633605  {
    3264 #if 0
    3265     if(pLength(G->m[i])>2)
    3266     {
    3267       return 1;
    3268     }
    3269 #else
    32703606    if((G->m[i]!=NULL) /* len >=0 */
    32713607       && (G->m[i]->next!=NULL) /* len >=1 */
    32723608       && (G->m[i]->next->next!=NULL) /* len >=2 */
    32733609       && (G->m[i]->next->next->next!=NULL) /* len >=3 */
    3274       //&& (G->m[i]->next->next->next->next!=NULL) /* len >=4 */
    3275        )
    3276     {
    3277     return 1;
    3278     }
    3279 #endif
     3610       && (G->m[i]->next->next->next->next!=NULL) /* len >=4*/ )
     3611    {
     3612      return 1;
     3613    }
    32803614  }
    32813615  return 0;
     3616}
     3617
     3618/*****************************************
     3619 * return maximal polynomial length of G *
     3620 *****************************************/
     3621static int maxlengthpoly(ideal G)
     3622{
     3623  int i,k,length=0;
     3624  for(i=IDELEMS(G)-1; i>=0; i--)
     3625  {
     3626    k = pLength(G->m[i]);
     3627    if(k>length)
     3628    {
     3629      length = k;
     3630    }
     3631  }
     3632  return length;
    32823633}
    32833634
     
    33503701  for(i=nG-1; i>=0; i--)
    33513702  {
    3352 #if 0
     3703/*
    33533704    poly t;
    33543705    if((t=pSub(pCopy(H0->m[i]), pCopy(H1->m[i]))) != NULL)
     
    33583709    }
    33593710    pDelete(&t);
    3360 #else
     3711*/
    33613712    if(!pEqualPolys(H0->m[i],H1->m[i]))
    33623713    {
    33633714      return 0;
    33643715    }
    3365 #endif
    33663716  }
    33673717  return 1;
     
    33723722 * find the maximal total degree of polynomials in G *
    33733723 *****************************************************/
    3374 #if 0
     3724/*
    33753725static int Trandegreebound(ideal G)
    33763726{
     
    33933743  return result;
    33943744}
    3395 #endif
     3745*/
    33963746
    33973747//unused
     
    37404090 * basis or n times, where n is the numbers of variables.                    *
    37414091 *****************************************************************************/
    3742 
    3743 //unused
    3744 #if 0
    3745 static int testnegintvec(intvec* v)
    3746 {
    3747   int n = v->length();
    3748   int i;
    3749   for(i=0; i<n; i++)
    3750   {
    3751     if((*v)[i]<0)
    3752     {
    3753       return(1);
    3754     }
    3755   }
    3756   return(0);
    3757 }
    3758 #endif
    37594092
    37604093// npwinc = 0, if curr_weight doesn't stay in the correct Groebner cone
     
    38844217    else
    38854218    {
    3886       rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
     4219      rChangeCurrRing(VMrDefault(curr_weight));
    38874220    }
    38884221    newRing = currRing;
     
    39684301        //nOverflow_Error = Overflow_Error;
    39694302        tproc=tproc+clock()-tinput;
    3970         /*
    3971           Print("\n// takes %d steps and calls \"Rec_LastGB\" (%d):",
    3972           nwalk, tp_deg+1);
    3973         */
     4303       
     4304        Print("\n// takes %d steps and calls \"Rec_LastGB\" (%d):",
     4305        nwalk, tp_deg+1);
     4306       
    39744307        G = Rec_LastGB(G,curr_weight, orig_target_weight, tp_deg+1,nnwinC);
    39754308        newRing = currRing;
     
    40054338    {
    40064339      // nOverflow_Error = Overflow_Error;
    4007       //Print("\n//  takes %d steps and calls \"Rec_LastGB (%d):", tp_deg+1);
     4340      Print("\n//  takes %d steps and calls \"Rec_LastGB (%d):", tp_deg+1);
    40084341      tproc=tproc+clock()-tinput;
    40094342      F1 = Rec_LastGB(F1,curr_weight, orig_target_weight, tp_deg+1,nnwinC);
     
    40594392    Overflow_Error=nError;
    40604393    }
    4061 // Print("\n// \"Rec_LastGB\" (%d) took %d steps and %.2f sec.Overflow_Error (%d)", tp_deg, nwalk, ((double) tproc)/1000000, nOverflow_Error);
     4394#ifdef TIME_TEST
     4395   Print("\n// \"Rec_LastGB\" (%d) took %d steps and %.2f sec.Overflow_Error (%d)", tp_deg, nwalk, ((double) tproc)/1000000, nOverflow_Error);
     4396#endif
    40624397  return(result);
    40634398}
     
    40814416  //BOOLEAN nOverflow_Error = FALSE;
    40824417  //Print("// pSetm_Error = (%d)", ErrorCheck());
    4083 
     4418#ifdef TIME_TEST
    40844419  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0; xtextra=0;
    40854420  xftinput = clock();
    40864421  clock_t tostd, tproc;
    4087 
     4422#endif
    40884423  nstep = 0;
    40894424  int i, nV = currRing->N;
     
    40964431  intvec* ivNull = new intvec(nV);
    40974432  intvec* next_weight;
    4098 #if 0
    4099   intvec* extra_curr_weight = new intvec(nV);
    4100 #endif
     4433  //intvec* extra_curr_weight = new intvec(nV);
    41014434  //intvec* hilb_func;
    41024435  intvec* exivlp = Mivlp(nV);
    4103 
    41044436  ring XXRing = currRing;
    41054437
    41064438  //Print("\n// ring r_input = %s;", rString(currRing));
     4439#ifdef TIME_TEST
    41074440  to = clock();
     4441#endif
    41084442  /* compute the reduced Groebner basis of the given ideal w.r.t.
    41094443     a "fast" monomial order, e.g. degree reverse lex. order (dp) */
    41104444  G = MstdCC(Go);
     4445#ifdef TIME_TEST
    41114446  tostd=clock()-to;
    41124447
    4113   /*
    41144448  Print("\n// Computation of the first std took = %.2f sec",
    41154449        ((double) tostd)/1000000);
    4116   */
     4450#endif
    41174451  if(currRing->order[0] == ringorder_a)
    41184452  {
     
    41234457    nwalk ++;
    41244458    nstep ++;
     4459#ifdef TIME_TEST
    41254460    to = clock();
     4461#endif
    41264462    /* compute an initial form ideal of <G> w.r.t. "curr_vector" */
    41274463    Gomega = MwalkInitialForm(G, curr_weight);
     4464#ifdef TIME_TEST
    41284465    xtif=xtif+clock()-to;
    4129 #if 0
     4466#endif
     4467/*
    41304468    if(Overflow_Error == TRUE)
    41314469    {
     
    41354473      goto LAST_GB_ALT2;
    41364474    }
    4137 #endif
     4475*/
    41384476    oldRing = currRing;
    41394477
     
    41454483    else
    41464484    {
    4147       rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
     4485      rChangeCurrRing(VMrDefault(curr_weight));
    41484486    }
    41494487    newRing = currRing;
    41504488    Gomega1 = idrMoveR(Gomega, oldRing,currRing);
     4489#ifdef TIME_TEST
    41514490    to = clock();
     4491#endif
    41524492    /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
    41534493    M = MstdhomCC(Gomega1);
     4494#ifdef TIME_TEST
    41544495    xtstd=xtstd+clock()-to;
     4496#endif
    41554497    /* change the ring to oldRing */
    41564498    rChangeCurrRing(oldRing);
    41574499    M1 =  idrMoveR(M, newRing,currRing);
    41584500    Gomega2 =  idrMoveR(Gomega1, newRing,currRing);
    4159 
     4501#ifdef TIME_TEST
    41604502    to = clock();
     4503#endif
    41614504    /* compute the reduced Groebner basis of <G> w.r.t. "newRing"
    41624505       by the liftig process */
    41634506    F = MLifttwoIdeal(Gomega2, M1, G);
     4507#ifdef TIME_TEST
    41644508    xtlift=xtlift+clock()-to;
     4509#endif
    41654510    idDelete(&M1);
    41664511    idDelete(&Gomega2);
     
    41704515    rChangeCurrRing(newRing);
    41714516    F1 = idrMoveR(F, oldRing,currRing);
    4172 
     4517#ifdef TIME_TEST
    41734518    to = clock();
     4519#endif
    41744520    /* reduce the Groebner basis <G> w.r.t. newRing */
    41754521    G = kInterRedCC(F1, NULL);
     4522#ifdef TIME_TEST
    41764523    xtred=xtred+clock()-to;
     4524#endif
    41774525    idDelete(&F1);
    41784526
     
    41814529
    41824530  NEXT_VECTOR:
     4531#ifdef TIME_TEST
    41834532    to = clock();
     4533#endif
    41844534    /* compute a next weight vector */
    41854535    next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     4536#ifdef TIME_TEST
    41864537    xtnw=xtnw+clock()-to;
     4538#endif
    41874539#ifdef PRINT_VECTORS
    41884540    MivString(curr_weight, target_weight, next_weight);
     
    42284580     // LAST_GB_ALT2:
    42294581        //nOverflow_Error = Overflow_Error;
     4582#ifdef TIME_TEST
    42304583        tproc = clock()-xftinput;
     4584#endif
    42314585        //Print("\n// takes %d steps and calls the recursion of level 2:",  nwalk);
    42324586        /* call the changed perturbation walk algorithm with degree 2 */
     
    42554609
    42564610#ifdef TIME_TEST
    4257  // Print("\n// \"Main procedure\"  took %d steps dnd %.2f sec. Overflow_Error (%d)", nwalk, ((double) tproc)/1000000, nOverflow_Error);
     4611  Print("\n// \"Main procedure\"  took %d steps dnd %.2f sec. Overflow_Error (%d)",
     4612        nwalk, ((double) tproc)/1000000, nOverflow_Error);
    42584613
    42594614  TimeStringFractal(xftinput, tostd, xtif, xtstd, xtextra,xtlift, xtred,xtnw);
     
    42874642intvec* Xivlp;
    42884643
    4289 #if 0
     4644
    42904645/********************************
    42914646 * compute a next weight vector *
    42924647 ********************************/
    4293 static intvec* MWalkRandomNextWeight(ideal G, intvec* curr_weight, intvec* target_weight, int weight_rad, int pert_deg)
     4648static intvec* MWalkRandomNextWeight(ideal G, intvec* orig_M, intvec* target_weight,
     4649       int weight_rad, int pert_deg)
    42944650{
    4295   int i, weight_norm;
    4296   int nV = currRing->N;
    4297   intvec* next_weight2;
     4651  assume(currRing != NULL && orig_M != NULL &&
     4652         target_weight != NULL && G->m[0] != NULL);
     4653
     4654  //BOOLEAN nError = Overflow_Error;
     4655  Overflow_Error = FALSE;
     4656
     4657  BOOLEAN found_random_weight = FALSE;
     4658  int i,nV = currRing->N;
     4659  intvec* curr_weight = new intvec(nV);
     4660
     4661  for(i=0; i<nV; i++)
     4662  {
     4663    (*curr_weight)[i] = (*orig_M)[i];
     4664  }
     4665
     4666  int k=0,weight_norm;
     4667  intvec* next_weight;
     4668  intvec* next_weight1 = MkInterRedNextWeight(curr_weight,target_weight,G);
     4669  intvec* next_weight2 = new intvec(nV);
    42984670  intvec* next_weight22 = new intvec(nV);
    4299   intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
    4300   if(MivComp(next_weight, target_weight) == 1)
    4301   {
    4302     return(next_weight);
    4303   }
    4304   else
    4305   {
    4306     //compute a perturbed next weight vector "next_weight1"
    4307     intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G, MivMatrixOrder(curr_weight), pert_deg), target_weight, G);
    4308     //Print("\n // size of next_weight1 = %d", sizeof((*next_weight1)));
    4309 
    4310     //compute a random next weight vector "next_weight2"
    4311     while(1)
    4312     {
    4313       weight_norm = 0;
    4314       while(weight_norm == 0)
     4671  intvec* result = new intvec(nV);
     4672  intvec* curr_weight1;
     4673  ideal G_test, G_test1, G_test2;
     4674
     4675  //try to find a random next weight vector "next_weight2"
     4676  if(weight_rad > 0){ while(k<10)
     4677  {
     4678    weight_norm = 0;
     4679    while(weight_norm == 0)
     4680    {
     4681
     4682      for(i=0; i<nV; i++)
     4683      {
     4684        (*next_weight2)[i] = rand() % 60000 - 30000;
     4685        weight_norm = weight_norm + (*next_weight2)[i]*(*next_weight2)[i];
     4686      }
     4687      weight_norm = 1 + floor(sqrt(weight_norm));
     4688    }
     4689
     4690    for(i=0; i<nV; i++)
     4691    {
     4692      if((*next_weight2)[i] < 0)
     4693      {
     4694        (*next_weight2)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight2)[i]/weight_norm);
     4695      }
     4696      else
     4697      {
     4698        (*next_weight2)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight2)[i]/weight_norm);
     4699      }
     4700    }
     4701   
     4702    if(test_w_in_ConeCC(G,next_weight2) == 1)
     4703    {
     4704      if(maxlengthpoly(MwalkInitialForm(G,next_weight2))<2)
     4705      {
     4706        next_weight2 = MkInterRedNextWeight(next_weight2,target_weight,G);
     4707      }
     4708/*
     4709      if(MivAbsMax(next_weight2)>1147483647)
    43154710      {
    43164711        for(i=0; i<nV; i++)
    43174712        {
    4318           //Print("\n//  next_weight[%d]  = %d", i, (*next_weight)[i]);
    4319           (*next_weight22)[i] = rand() % 60000 - 30000;
    4320           weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
     4713          (*next_weight22)[i] = (*next_weight2)[i];
    43214714        }
    4322         weight_norm = 1 + floor(sqrt(weight_norm));
    4323       }
    4324 
    4325       for(i=nV-1; i>=0; i--)
    4326       {
    4327         if((*next_weight22)[i] < 0)
     4715        i = 0;
     4716        // reduce the size of the maximal entry of the vector
     4717        while(test_w_in_ConeCC(G,next_weight22) == 1)
    43284718        {
    4329           (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
     4719          (*next_weight2)[i] = (*next_weight22)[i];
     4720          i = MivAbsMaxArg(next_weight22);
     4721          (*next_weight22)[i] = floor(0.1*(*next_weight22)[i] + 0.5);
     4722        }
     4723        delete next_weight22;
     4724      }
     4725*/
     4726      G_test2 = MwalkInitialForm(G, next_weight2);
     4727      found_random_weight = TRUE;
     4728      break;
     4729    }
     4730    k++;
     4731  }}
     4732Print("\n MWalkRandomNextWeight: compute perurbation...\n");
     4733  // compute "perturbed" next weight vector
     4734  if(pert_deg > 1)
     4735  {
     4736    curr_weight1 = MPertVectors(G,orig_M,pert_deg);
     4737    next_weight = MkInterRedNextWeight(curr_weight1,target_weight,G);
     4738    delete curr_weight1;
     4739  }
     4740  else
     4741  {
     4742    next_weight = MkInterRedNextWeight(curr_weight,target_weight,G);
     4743  }
     4744  if(MivSame(curr_weight,next_weight)==1 || Overflow_Error == TRUE)
     4745  {
     4746    Overflow_Error = FALSE;
     4747    delete next_weight;
     4748    next_weight = MkInterRedNextWeight(curr_weight,target_weight,G);
     4749  }
     4750  G_test=MwalkInitialForm(G,next_weight);
     4751  G_test1=MwalkInitialForm(G,next_weight1);
     4752Print("\n MWalkRandomNextWeight: finished...\n");
     4753  // compare next weights
     4754  if(Overflow_Error == FALSE)
     4755  {
     4756    if(found_random_weight == TRUE)
     4757    {
     4758    // random next weight vector found
     4759      if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))
     4760      {
     4761        if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test1))
     4762        {
     4763          for(i=0; i<nV; i++)
     4764          {
     4765            (*result)[i] = (*next_weight2)[i];
     4766          }
    43304767        }
    43314768        else
    43324769        {
    4333           (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
     4770          for(i=0; i<nV; i++)
     4771          {
     4772            (*result)[i] = (*next_weight1)[i];
     4773          }
     4774        }   
     4775      }
     4776      else
     4777      {
     4778        if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))
     4779        {
     4780          for(i=0; i<nV; i++)
     4781          {
     4782            (*result)[i] = (*next_weight2)[i];
     4783          }
    43344784        }
    4335       //Print("\n//  next_weight22[%d]  = %d", i, (*next_weight22)[i]);
    4336       }
    4337 
    4338       if(test_w_in_ConeCC(G, next_weight22) == 1)
    4339       {
    4340         //Print("\n//MWalkRandomNextWeight: next_weight2 im Kegel\n");
    4341         next_weight2 = MkInterRedNextWeight(next_weight22, target_weight, G);
    4342         delete next_weight22;
    4343         break;
    4344       }
    4345     }
    4346     intvec* result = new intvec(nV);
    4347     ideal G_test = MwalkInitialForm(G, next_weight);
    4348     ideal G_test1 = MwalkInitialForm(G, next_weight1);
    4349     ideal G_test2 = MwalkInitialForm(G, next_weight2);
    4350 
    4351     // compare next_weights
    4352     if(IDELEMS(G_test1) < IDELEMS(G_test))
    4353     {
    4354       if(IDELEMS(G_test2) <= IDELEMS(G_test1)) // |G_test2| <= |G_test1| < |G_test|
    4355       {
    4356         for(i=0; i<nV; i++)
     4785        else
    43574786        {
    4358           (*result)[i] = (*next_weight2)[i];
     4787          for(i=0; i<nV; i++)
     4788          {
     4789            (*result)[i] = (*next_weight)[i];
     4790          }
    43594791        }
    43604792      }
    4361       else // |G_test1| < |G_test|, |G_test1| < |G_test2|
    4362       {
    4363         for(i=0; i<nV; i++)
     4793    }
     4794    else
     4795    {
     4796      // no random next weight vector found
     4797      if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))
     4798      {
     4799       for(i=0; i<nV; i++)
    43644800        {
    43654801          (*result)[i] = (*next_weight1)[i];
    43664802        }
    43674803      }
    4368     }
    4369     else
    4370     {
    4371       if(IDELEMS(G_test2) <= IDELEMS(G_test)) // |G_test2| <= |G_test| <= |G_test1|
    4372       {
    4373         for(i=0; i<nV; i++)
    4374         {
    4375           (*result)[i] = (*next_weight2)[i];
    4376         }
    4377       }
    4378       else // |G_test| <= |G_test1|, |G_test| < |G_test2|
     4804      else
    43794805      {
    43804806        for(i=0; i<nV; i++)
     
    43844810      }
    43854811    }
    4386     delete next_weight;
    4387     delete next_weight1;
    4388     idDelete(&G_test);
    4389     idDelete(&G_test1);
    4390     idDelete(&G_test2);
    4391     if(test_w_in_ConeCC(G, result) == 1)
    4392     {
    4393       delete next_weight2;
    4394       return result;
    4395     }
    4396     else
    4397     {
    4398       delete result;
    4399       return next_weight2;
    4400     }
    4401   }
    4402 }
    4403 #endif
    4404 
    4405 /********************************
    4406  * compute a next weight vector *
    4407  ********************************/
    4408 static intvec* MWalkRandomNextWeight(ideal G, intvec* curr_weight, intvec* target_weight, int weight_rad, int pert_deg)
    4409 {
    4410   int i, weight_norm;
    4411   //int randCount=0;
    4412   int nV = currRing->N;
    4413   intvec* next_weight2;
    4414   intvec* next_weight22 = new intvec(nV);
    4415   intvec* result = new intvec(nV);
    4416 
    4417   //compute a perturbed next weight vector "next_weight1"
    4418   //intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G,MivMatrixOrderRefine(curr_weight,target_weight),pert_deg),target_weight,G);
    4419   intvec* next_weight1 =MkInterRedNextWeight(curr_weight,target_weight,G);
    4420   //compute a random next weight vector "next_weight2"
    4421   while(1)
    4422   {
    4423     weight_norm = 0;
    4424     while(weight_norm == 0)
    4425     {
    4426       for(i=0; i<nV; i++)
    4427       {
    4428         (*next_weight22)[i] = rand() % 60000 - 30000;
    4429         weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
    4430       }
    4431       weight_norm = 1 + floor(sqrt(weight_norm));
    4432     }
    4433     for(i=0; i<nV; i++)
    4434     {
    4435       if((*next_weight22)[i] < 0)
    4436       {
    4437         (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
    4438       }
    4439       else
    4440       {
    4441         (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
    4442       }
    4443     }
    4444     if(test_w_in_ConeCC(G, next_weight22) == 1)
    4445     {
    4446       next_weight2 = MkInterRedNextWeight(next_weight22,target_weight,G);
    4447       delete next_weight22;
    4448       break;
    4449     }
    4450   }
    4451   // compute "usual" next weight vector
    4452   intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
    4453   ideal G_test = MwalkInitialForm(G, next_weight);
    4454   ideal G_test2 = MwalkInitialForm(G, next_weight2);
    4455 
    4456   // compare next weights
    4457   if(Overflow_Error == FALSE)
    4458   {
    4459     ideal G_test1 = MwalkInitialForm(G, next_weight1);
    4460     if(IDELEMS(G_test1) < IDELEMS(G_test))
    4461     {
    4462       if(IDELEMS(G_test2) < IDELEMS(G_test1))
    4463       {
    4464         // |G_test2| < |G_test1| < |G_test|
    4465         for(i=0; i<nV; i++)
     4812  }
     4813  else
     4814  {
     4815    Overflow_Error = FALSE;
     4816    if(found_random_weight == TRUE)
     4817    {
     4818      if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))
     4819      {
     4820        for(i=1; i<nV; i++)
    44664821        {
    44674822          (*result)[i] = (*next_weight2)[i];
     
    44704825      else
    44714826      {
    4472         // |G_test1| < |G_test|, |G_test1| <= |G_test2|
    4473         for(i=0; i<nV; i++)
    4474         {
    4475           (*result)[i] = (*next_weight1)[i];
    4476         }
    4477       }
    4478     }
    4479     else
    4480     {
    4481       if(IDELEMS(G_test2) < IDELEMS(G_test)) // |G_test2| < |G_test| <= |G_test1|
    4482       {
    4483         for(i=0; i<nV; i++)
    4484         {
    4485           (*result)[i] = (*next_weight2)[i];
    4486         }
    4487       }
    4488       else
    4489       {
    4490         // |G_test| < |G_test1|, |G_test| <= |G_test2|
    44914827        for(i=0; i<nV; i++)
    44924828        {
     
    44954831      }
    44964832    }
    4497     idDelete(&G_test1);
    4498   }
    4499   else
    4500   {
    4501     Overflow_Error = FALSE;
    4502     if(IDELEMS(G_test2) < IDELEMS(G_test))
    4503     {
    4504       for(i=1; i<nV; i++)
    4505       {
    4506         (*result)[i] = (*next_weight2)[i];
    4507       }
    4508     }
    45094833    else
    45104834    {
     
    45154839    }
    45164840  }
     4841 // delete curr_weight1;
     4842  delete next_weight;
     4843  delete next_weight2;
    45174844  idDelete(&G_test);
    4518   idDelete(&G_test2);
    4519   if(test_w_in_ConeCC(G, result) == 1)
    4520   {
    4521     delete next_weight2;
    4522     delete next_weight;
     4845  idDelete(&G_test1);
     4846  if(found_random_weight == TRUE)
     4847  {
     4848    idDelete(&G_test2);
     4849  }
     4850  if(test_w_in_ConeCC(G, result) == 1 && MivSame(curr_weight,result)==0)
     4851  {
     4852    delete curr_weight;
    45234853    delete next_weight1;
    45244854    return result;
     
    45264856  else
    45274857  {
     4858    delete curr_weight;
    45284859    delete result;
    4529     delete next_weight2;
    4530     delete next_weight1;
    4531     return next_weight;
     4860    return next_weight1;
    45324861  }
    45334862}
     
    45374866 * The procedur REC_GB_Mwalk computes a GB for <G> w.r.t. the weight order *
    45384867 * otw, where G is a reduced GB w.r.t. the weight order cw.                *
    4539  * The new procedur Mwalk calls REC_GB.                                    *
     4868 * The new procedure Mwalk calls REC_GB.                                   *
    45404869 ***************************************************************************/
    45414870static ideal REC_GB_Mwalk(ideal G, intvec* curr_weight, intvec* orig_target_weight,
     
    45754904    else
    45764905    {
    4577       rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
     4906      rChangeCurrRing(VMrDefault(orig_target_weight));
    45784907    }
    45794908    TargetRing = currRing;
     
    46464975    else
    46474976    {
    4648       rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
     4977      rChangeCurrRing(VMrDefault(curr_weight));
    46494978    }
    46504979    newRing = currRing;
     
    47555084    else
    47565085    {
    4757       rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
     5086      rChangeCurrRing(VMrDefault(orig_target_weight));
    47585087    }
    47595088    F1 = idrMoveR(G, newRing,currRing);
     
    47865115      else
    47875116      {
    4788         rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
     5117        rChangeCurrRing(VMrDefault(orig_target_weight));
    47895118      }
    47905119    KSTD_Finish:
     
    48405169
    48415170  ideal Gomega, M, F, Gomega1, Gomega2, M1, F1, G;
    4842   //ideal G1;
    4843   //ring endRing;
     5171
    48445172  ring newRing, oldRing;
    48455173  intvec* ivNull = new intvec(nV);
     
    48835211         the recursive changed perturbation walk alg. */
    48845212      tim = clock();
    4885       /*
    4886         Print("\n// **** Grᅵbnerwalk took %d steps and ", nwalk);
     5213#ifdef CHECK_IDEAL_MWALK
     5214        Print("\n// **** Groebnerwalk took %d steps and ", nwalk);
    48875215        PrintS("\n// **** call the rec. Pert. Walk to compute a red GB of:");
    4888         idElements(Gomega, "G_omega");
    4889       */
     5216        idString(Gomega, "Gomega");
     5217#endif
    48905218
    48915219      if(MivSame(exivlp, target_weight)==1)
     
    48935221      else
    48945222        goto NORMAL_GW;
    4895       /*
     5223#ifdef TIME_TEST
    48965224        Print("\n//  time for the last std(Gw)  = %.2f sec",
    48975225        ((double) (clock()-tim)/1000000));
    4898         PrintS("\n// ***************************************************\n");
    4899       */
     5226#endif
     5227/*
    49005228#ifdef CHECK_IDEAL_MWALK
    49015229      idElements(Gomega, "G_omega");
     
    49045232      //headidString(M, "M");
    49055233#endif
     5234*/
    49065235      to = clock();
    49075236      F = MLifttwoIdeal(Gomega, M, G);
     
    49145243      oldRing = currRing;
    49155244
    4916       /* create a new ring newRing */
     5245      // create a new ring newRing
    49175246       if (rParameter(currRing) != NULL)
    49185247       {
     
    49215250       else
    49225251       {
    4923          rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
     5252         rChangeCurrRing(VMrDefault(curr_weight));
    49245253       }
    49255254      newRing = currRing;
     
    49475276      else
    49485277      {
    4949         rChangeCurrRing(VMrDefault(curr_weight));  //Aenderung
     5278        rChangeCurrRing(VMrDefault(curr_weight));
    49505279      }
    49515280      newRing = currRing;
     
    49595288      M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
    49605289      delete hilb_func;
    4961 #endif // BUCHBERGER_ALG
     5290#endif
    49625291      tstd = tstd + clock() - to;
    49635292
     
    49685297
    49695298      to = clock();
    4970       // 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.
     5299      // compute a representation of the generators of submod (M) with respect
     5300      // to those of mod (Gomega).
     5301      // Gomega is a reduced Groebner basis w.r.t. the current ring.
    49715302      F = MLifttwoIdeal(Gomega2, M1, G);
    49725303      tlift = tlift + clock() - to;
     
    50185349      else
    50195350      {
    5020         rChangeCurrRing(VMrDefault(target_weight)); // Aenderung
     5351        rChangeCurrRing(VMrDefault(target_weight));
    50215352      }
    50225353      F1 = idrMoveR(G, newRing,currRing);
     
    50615392}
    50625393
    5063 
    50645394/*******************************
    50655395 * THE GROEBNER WALK ALGORITHM *
    50665396 *******************************/
    5067 ideal Mwalk(ideal Go, intvec* orig_M, intvec* target_M, ring baseRing)
     5397ideal Mwalk(ideal Go, intvec* orig_M, intvec* target_M,
     5398            ring baseRing, int reduction, int printout)
    50685399{
    5069   BITSET save1 = si_opt_1; // save current options
    5070   //si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
    5071   //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
    5072   //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
     5400  // save current options
     5401  BITSET save1 = si_opt_1;
     5402  if(reduction == 0)
     5403  {
     5404    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
     5405    si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
     5406  }
    50735407  Set_Error(FALSE);
    50745408  Overflow_Error = FALSE;
     5409  //BOOLEAN endwalks = FALSE;
    50755410#ifdef TIME_TEST
    50765411  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
     
    50805415#endif
    50815416  nstep=0;
    5082   int i,nwalk,endwalks = 0;
     5417  int i,nwalk;
    50835418  int nV = baseRing->N;
    50845419
    5085   ideal Gomega, M, F, Gomega1, Gomega2, M1; //, F1;
     5420  ideal Gomega, M, F, FF, Gomega1, Gomega2, M1;
    50865421  ring newRing;
    50875422  ring XXRing = baseRing;
     5423  ring targetRing;
    50885424  intvec* ivNull = new intvec(nV);
    50895425  intvec* curr_weight = new intvec(nV);
    50905426  intvec* target_weight = new intvec(nV);
    50915427  intvec* exivlp = Mivlp(nV);
     5428/*
    50925429  intvec* tmp_weight = new intvec(nV);
    50935430  for(i=0; i<nV; i++)
    50945431  {
    5095     (*tmp_weight)[i] = (*target_M)[i];
    5096   }
     5432    (*tmp_weight)[i] = (*orig_M)[i];
     5433  }
     5434*/
    50975435  for(i=0; i<nV; i++)
    50985436  {
     
    51125450  rComplete(currRing);
    51135451#ifdef CHECK_IDEAL_MWALK
    5114     idString(Go,"Go");
    5115 #endif
     5452  if(printout > 2)
     5453  {
     5454    idString(Go,"//** Mwalk: Go");
     5455  }
     5456#endif
     5457
     5458  if(target_M->length() == nV)
     5459  {
     5460   // define the target ring
     5461    targetRing = VMrDefault(target_weight);
     5462  }
     5463  else
     5464  {
     5465    targetRing = VMatrDefault(target_M);
     5466  }
     5467  if(orig_M->length() == nV)
     5468  {
     5469    // define a new ring with ordering "(a(curr_weight),lp)
     5470    newRing = VMrDefault(curr_weight);
     5471  }
     5472  else
     5473  {
     5474    newRing = VMatrDefault(orig_M);
     5475  }
     5476  rChangeCurrRing(newRing);
     5477
    51165478#ifdef TIME_TEST
    51175479  to = clock();
    51185480#endif
    5119      if(orig_M->length() == nV)
    5120       {
    5121         newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
    5122       }
    5123       else
    5124       {
    5125         newRing = VMatrDefault(orig_M);
    5126       }
    5127   rChangeCurrRing(newRing);
    51285481  ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
     5482#ifdef TIME_TEST
     5483  tostd = clock()-to;
     5484#endif
     5485
    51295486  baseRing = currRing;
    5130 #ifdef TIME_TEST
    5131   tostd = clock()-to;
    5132 #endif
    5133 
    51345487  nwalk = 0;
     5488
    51355489  while(1)
    51365490  {
    51375491    nwalk ++;
    51385492    nstep ++;
     5493    //compute an initial form ideal of <G> w.r.t. "curr_vector"
    51395494#ifdef TIME_TEST
    51405495    to = clock();
    51415496#endif
     5497    Gomega = MwalkInitialForm(G, curr_weight);
     5498#ifdef TIME_TEST
     5499    tif = tif + clock()-to;
     5500#endif
     5501
    51425502#ifdef CHECK_IDEAL_MWALK
    5143     idString(G,"G");
    5144 #endif
    5145     Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
    5146 #ifdef TIME_TEST
    5147     tif = tif + clock()-to; //time for computing initial form ideal
    5148 #endif
    5149 #ifdef CHECK_IDEAL_MWALK
    5150     idString(Gomega,"Gomega");
    5151 #endif
     5503    if(printout > 1)
     5504    {
     5505      idString(Gomega,"//** Mwalk: Gomega");
     5506    }
     5507#endif
     5508
     5509    if(reduction == 0)
     5510    {
     5511      FF = middleOfCone(G,Gomega);
     5512      if(FF != NULL)
     5513      {
     5514        idDelete(&G);
     5515        G = idCopy(FF);
     5516        idDelete(&FF);
     5517        goto NEXT_VECTOR;
     5518      }
     5519    }
     5520
    51525521#ifndef  BUCHBERGER_ALG
    51535522    if(isNolVector(curr_weight) == 0)
    51545523    {
    51555524      hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
    5156     }
     5525    }   
    51575526    else
    51585527    {
     
    51605529    }
    51615530#endif
     5531
    51625532    if(nwalk == 1)
    51635533    {
    51645534      if(orig_M->length() == nV)
    51655535      {
    5166         newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
     5536        // define a new ring with ordering "(a(curr_weight),lp)
     5537        newRing = VMrDefault(curr_weight);
    51675538      }
    51685539      else
     
    51755546     if(target_M->length() == nV)
    51765547     {
    5177        newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
     5548       //define a new ring with ordering "(a(curr_weight),lp)"
     5549       newRing = VMrDefault(curr_weight);
    51785550     }
    51795551     else
    51805552     {
     5553       //define a new ring with matrix ordering
    51815554       newRing = VMatrRefine(target_M,curr_weight);
    51825555     }
     
    52005573    idSkipZeroes(M);
    52015574#ifdef CHECK_IDEAL_MWALK
    5202     PrintS("\n//** Mwalk: computed M.\n");
    5203     idString(M, "M");
     5575    if(printout > 2)
     5576    {
     5577      idString(M, "//** Mwalk: M");
     5578    }
    52045579#endif
    52055580    //change the ring to baseRing
     
    52125587    to = clock();
    52135588#endif
    5214     // 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
     5589    // compute a representation of the generators of submod (M) with respect to those of mod (Gomega),
     5590    // where Gomega is a reduced Groebner basis w.r.t. the current ring
    52155591    F = MLifttwoIdeal(Gomega2, M1, G);
    52165592#ifdef TIME_TEST
     
    52185594#endif
    52195595#ifdef CHECK_IDEAL_MWALK
    5220     idString(F, "F");
     5596    if(printout > 2)
     5597    {
     5598      idString(F, "//** Mwalk: F");
     5599    }
     5600#endif
     5601    idDelete(&Gomega2);
     5602    idDelete(&M1);
     5603
     5604    rChangeCurrRing(newRing); // change the ring to newRing
     5605    G = idrMoveR(F,baseRing,currRing);
     5606    idDelete(&F);
     5607    idSkipZeroes(G);
     5608
     5609#ifdef CHECK_IDEAL_MWALK
     5610    if(printout > 2)
     5611    {
     5612      idString(G, "//** Mwalk: G");
     5613    }
     5614#endif
     5615
     5616    rChangeCurrRing(targetRing);
     5617    G = idrMoveR(G,newRing,currRing);
     5618    // test whether target cone is reached
     5619    if(reduction !=0 && test_w_in_ConeCC(G,curr_weight) == 1)
     5620    {
     5621      baseRing = currRing;
     5622      break;
     5623      //endwalks = TRUE;
     5624    }
     5625
     5626    rChangeCurrRing(newRing);
     5627    G = idrMoveR(G,targetRing,currRing);
     5628    baseRing = currRing;
     5629
     5630    NEXT_VECTOR:
     5631#ifdef TIME_TEST
     5632    to = clock();
     5633#endif
     5634    intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
     5635#ifdef TIME_TEST
     5636    tnw = tnw + clock() - to;
     5637#endif
     5638#ifdef PRINT_VECTORS
     5639    if(printout > 0)
     5640    {
     5641      MivString(curr_weight, target_weight, next_weight);
     5642    }
     5643#endif
     5644    if(MivComp(target_weight,curr_weight) == 1)// || endwalks == TRUE)
     5645    {
     5646/*
     5647#ifdef CHECK_IDEAL_MWALK
     5648      if(printout > 0)
     5649      {
     5650        PrintS("\n//** Mwalk: entering last cone.\n");
     5651      }
     5652#endif
     5653
     5654      Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     5655      if(target_M->length() == nV)
     5656      {
     5657        newRing = VMrDefault(target_weight); // define a new ring with ordering "(a(curr_weight),lp)
     5658      }
     5659      else
     5660      {
     5661        newRing = VMatrDefault(target_M);
     5662      }
     5663      rChangeCurrRing(newRing);
     5664      Gomega1 = idrMoveR(Gomega, baseRing,currRing);
     5665      idDelete(&Gomega);
     5666#ifdef CHECK_IDEAL_MWALK
     5667      if(printout > 1)
     5668      {
     5669        idString(Gomega1, "//** Mwalk: Gomega");
     5670      }
     5671      PrintS("\n //** Mwalk: kStd(Gomega)");
     5672#endif
     5673      M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
     5674#ifdef CHECK_IDEAL_MWALK
     5675      if(printout > 1)
     5676      {
     5677        idString(M,"//** Mwalk: M");
     5678      }
     5679#endif
     5680      rChangeCurrRing(baseRing);
     5681      M1 =  idrMoveR(M, newRing,currRing);
     5682      idDelete(&M);
     5683      Gomega2 = idrMoveR(Gomega1, newRing,currRing);
     5684      idDelete(&Gomega1);
     5685      //PrintS("\n //** Mwalk: MLifttwoIdeal");
     5686      F = MLifttwoIdeal(Gomega2, M1, G);
     5687#ifdef CHECK_IDEAL_MWALK
     5688      if(printout > 2)
     5689      {
     5690        idString(F,"//** Mwalk: F");
     5691      }
     5692#endif
     5693      idDelete(&Gomega2);
     5694      idDelete(&M1);
     5695      rChangeCurrRing(newRing); // change the ring to newRing
     5696      G = idrMoveR(F,baseRing,currRing);
     5697      idDelete(&F);
     5698      baseRing = currRing;
     5699      idSkipZeroes(G);
     5700#ifdef TIME_TEST
     5701      to = clock();
     5702#endif
     5703      //PrintS("\n //**Mwalk: Interreduce");
     5704      //interreduce the Groebner basis <G> w.r.t. currRing
     5705      //G = kInterRedCC(G,NULL);
     5706#ifdef TIME_TEST
     5707      tred = tred + clock() - to;
     5708#endif
     5709      idSkipZeroes(G);
     5710      delete next_weight;
     5711*/
     5712      break;
     5713    }
     5714
     5715    for(i=nV-1; i>=0; i--)
     5716    {
     5717      //(*tmp_weight)[i] = (*curr_weight)[i];
     5718      (*curr_weight)[i] = (*next_weight)[i];
     5719    }
     5720    delete next_weight;
     5721  }
     5722  rChangeCurrRing(XXRing);
     5723  ideal result = idrMoveR(G,baseRing,currRing);
     5724  idDelete(&Go);
     5725  idDelete(&G);
     5726  //delete tmp_weight;
     5727  delete ivNull;
     5728  delete exivlp;
     5729#ifndef BUCHBERGER_ALG
     5730  delete last_omega;
     5731#endif
     5732#ifdef TIME_TEST
     5733  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
     5734  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
     5735  //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
     5736#endif
     5737  Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
     5738  si_opt_1 = save1; //set original options
     5739  return(result);
     5740}
     5741
     5742// THE RANDOM WALK ALGORITHM
     5743ideal Mrwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad, int pert_deg,
     5744             int reduction, int printout)
     5745{
     5746  BITSET save1 = si_opt_1; // save current options
     5747  if(reduction == 0)
     5748  {
     5749    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
     5750    si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
     5751  }
     5752
     5753  Set_Error(FALSE);
     5754  Overflow_Error = FALSE;
     5755  BOOLEAN endwalks = FALSE;
     5756#ifdef TIME_TEST
     5757  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
     5758  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
     5759  tinput = clock();
     5760  clock_t tim;
     5761#endif
     5762  nstep=0;
     5763  int i,nwalk;//polylength;
     5764  int nV = currRing->N;
     5765
     5766  //check that weight radius is valid
     5767  if(weight_rad < 0)
     5768  {
     5769    Werror("Invalid radius.\n");
     5770    return NULL;
     5771  }
     5772
     5773  //check that perturbation degree is valid
     5774  if(pert_deg > nV || pert_deg < 1)
     5775  {
     5776    Werror("Invalid perturbation degree.\n");
     5777    return NULL;
     5778  }
     5779
     5780  ideal Gomega, M, F,FF, Gomega1, Gomega2, M1;
     5781  ring newRing;
     5782  ring targetRing;
     5783  ring baseRing = currRing;
     5784  ring XXRing = currRing;
     5785  intvec* iv_M;
     5786  intvec* ivNull = new intvec(nV);
     5787  intvec* curr_weight = new intvec(nV);
     5788  intvec* target_weight = new intvec(nV);
     5789  intvec* next_weight= new intvec(nV);
     5790
     5791  for(i=0; i<nV; i++)
     5792  {
     5793    (*curr_weight)[i] = (*orig_M)[i];
     5794    (*target_weight)[i] = (*target_M)[i];
     5795  }
     5796
     5797#ifndef BUCHBERGER_ALG
     5798  intvec* hilb_func;
     5799   // to avoid (1,0,...,0) as the target vector
     5800  intvec* last_omega = new intvec(nV);
     5801  for(i=nV-1; i>0; i--)
     5802  {
     5803    (*last_omega)[i] = 1;
     5804  }
     5805  (*last_omega)[0] = 10000;
     5806#endif
     5807  rComplete(currRing);
     5808
     5809  if(target_M->length() == nV)
     5810  {
     5811    targetRing = VMrDefault(target_weight); // define the target ring
     5812  }
     5813  else
     5814  {
     5815    targetRing = VMatrDefault(target_M);
     5816  }
     5817  if(orig_M->length() == nV)
     5818  {
     5819    newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
     5820  }
     5821  else
     5822  {
     5823    newRing = VMatrDefault(orig_M);
     5824  }
     5825  rChangeCurrRing(newRing);
     5826#ifdef TIME_TEST
     5827  to = clock();
     5828#endif
     5829  ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
     5830#ifdef TIME_TEST
     5831  tostd = clock()-to;
     5832#endif
     5833  baseRing = currRing;
     5834  nwalk = 0;
     5835
     5836#ifdef TIME_TEST
     5837  to = clock();
     5838#endif
     5839  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     5840#ifdef TIME_TEST
     5841  tif = tif + clock()-to; //time for computing initial form ideal
     5842#endif
     5843
     5844  while(1)
     5845  {
     5846    nwalk ++;
     5847    nstep ++;
     5848#ifdef CHECK_IDEAL_MWALK
     5849    if(printout > 1)
     5850    {
     5851      idString(Gomega,"//** Mrwalk: Gomega");
     5852    }
     5853#endif
     5854    if(reduction == 0)
     5855    {
     5856      FF = middleOfCone(G,Gomega);
     5857      if(FF != NULL)
     5858      {
     5859        idDelete(&G);
     5860        G = idCopy(FF);
     5861        idDelete(&FF);
     5862        goto NEXT_VECTOR;
     5863      }
     5864    }
     5865#ifndef  BUCHBERGER_ALG
     5866    if(isNolVector(curr_weight) == 0)
     5867    {
     5868      hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
     5869    }   
     5870    else
     5871    {
     5872      hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
     5873    }
     5874#endif
     5875    if(nwalk == 1)
     5876    {
     5877      if(orig_M->length() == nV)
     5878      {
     5879        newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
     5880      }
     5881      else
     5882      {
     5883        newRing = VMatrDefault(orig_M);
     5884      }
     5885    }
     5886    else
     5887    {
     5888     if(target_M->length() == nV)
     5889     {
     5890       newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
     5891     }
     5892     else
     5893     {
     5894       newRing = VMatrRefine(target_M,curr_weight);
     5895     }
     5896    }
     5897    rChangeCurrRing(newRing);
     5898    Gomega1 = idrMoveR(Gomega, baseRing,currRing);
     5899    idDelete(&Gomega);
     5900    // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
     5901#ifdef TIME_TEST
     5902    to = clock();
     5903#endif
     5904#ifndef BUCHBERGER_ALG
     5905    M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
     5906    delete hilb_func;
     5907#else
     5908    M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
     5909#endif
     5910#ifdef TIME_TEST
     5911    tstd = tstd + clock() - to;
     5912#endif
     5913    idSkipZeroes(M);
     5914#ifdef CHECK_IDEAL_MWALK
     5915    if(printout > 2)
     5916    {
     5917      idString(M, "//** Mrwalk: M");
     5918    }
     5919#endif
     5920    //change the ring to baseRing
     5921    rChangeCurrRing(baseRing);
     5922    M1 =  idrMoveR(M, newRing,currRing);
     5923    idDelete(&M);
     5924    Gomega2 = idrMoveR(Gomega1, newRing,currRing);
     5925    idDelete(&Gomega1);
     5926#ifdef TIME_TEST
     5927    to = clock();
     5928#endif
     5929    // compute a representation of the generators of submod (M) with respect to those of mod (Gomega),
     5930    // where Gomega is a reduced Groebner basis w.r.t. the current ring
     5931    F = MLifttwoIdeal(Gomega2, M1, G);
     5932#ifdef TIME_TEST
     5933    tlift = tlift + clock() - to;
     5934#endif
     5935#ifdef CHECK_IDEAL_MWALK
     5936    if(printout > 2)
     5937    {
     5938      idString(F,"//** Mrwalk: F");
     5939    }
    52215940#endif
    52225941    idDelete(&Gomega2);
     
    52285947#ifdef TIME_TEST
    52295948    to = clock();
    5230 #endif
    5231     //G = kStd(F1,NULL,testHomog,NULL,NULL,0,0,NULL);
    5232 #ifdef TIME_TEST
    52335949    tstd = tstd + clock() - to;
    52345950#endif
    52355951    idSkipZeroes(G);
    52365952#ifdef CHECK_IDEAL_MWALK
    5237     idString(G, "G");
    5238 #endif
     5953    if(printout > 2)
     5954    {
     5955      idString(G,"//** Mrwalk: G");
     5956    }
     5957#endif
     5958
     5959    rChangeCurrRing(targetRing);
     5960    G = idrMoveR(G,newRing,currRing);
     5961
     5962    // test whether target cone is reached
     5963    if(reduction !=0 && test_w_in_ConeCC(G,curr_weight) == 1)
     5964    {
     5965      baseRing = currRing;
     5966      break;
     5967    }
     5968
     5969    rChangeCurrRing(newRing);
     5970    G = idrMoveR(G,targetRing,currRing);
     5971    baseRing = currRing;
     5972
     5973    NEXT_VECTOR:
    52395974#ifdef TIME_TEST
    52405975    to = clock();
    52415976#endif
    5242     intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
     5977    next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
    52435978#ifdef TIME_TEST
    52445979    tnw = tnw + clock() - to;
    52455980#endif
    5246 #ifdef PRINT_VECTORS
    5247     MivString(curr_weight, target_weight, next_weight);
    5248 #endif
    5249     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)
    5250     {
    5251 #ifdef CHECK_IDEAL_MWALK
    5252       PrintS("\n//** Mwalk: entering last cone.\n");
    5253 #endif
    5254       Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     5981
     5982#ifdef TIME_TEST
     5983    to = clock();
     5984#endif
     5985    Gomega = MwalkInitialForm(G, next_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     5986#ifdef TIME_TEST
     5987    tif = tif + clock()-to; //time for computing initial form ideal
     5988#endif
     5989
     5990    //lengthpoly(Gomega) = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
     5991    //polylength = lengthpoly(Gomega);
     5992    if(lengthpoly(Gomega) > 0)
     5993    {
     5994      //there is a polynomial in Gomega with at least 3 monomials,
     5995      //low-dimensional facet of the cone
     5996      delete next_weight;
    52555997      if(target_M->length() == nV)
    52565998      {
    5257         newRing = VMrDefault(target_weight); // define a new ring with ordering "(a(curr_weight),lp)
     5999        iv_M = MivMatrixOrder(curr_weight);
    52586000      }
    52596001      else
    52606002      {
    5261         newRing = VMatrDefault(target_M);
    5262       }
    5263       rChangeCurrRing(newRing);
    5264       Gomega1 = idrMoveR(Gomega, baseRing,currRing);
     6003        iv_M = MivMatrixOrderRefine(curr_weight,target_M);
     6004      }
     6005#ifdef TIME_TEST
     6006      to = clock();
     6007#endif
     6008      next_weight = MWalkRandomNextWeight(G, iv_M, target_weight, weight_rad, pert_deg);
     6009#ifdef TIME_TEST
     6010      tnw = tnw + clock() - to;
     6011#endif
    52656012      idDelete(&Gomega);
    5266 #ifdef CHECK_IDEAL_MWALK
    5267       idString(Gomega1, "Gomega");
    5268 #endif
    5269       M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
    5270 #ifdef CHECK_IDEAL_MWALK
    5271       idString(M,"M");
    5272 #endif
    5273       rChangeCurrRing(baseRing);
    5274       M1 =  idrMoveR(M, newRing,currRing);
    5275       idDelete(&M);
    5276       Gomega2 = idrMoveR(Gomega1, newRing,currRing);
    5277       idDelete(&Gomega1);
    5278       F = MLifttwoIdeal(Gomega2, M1, G);
    5279 #ifdef CHECK_IDEAL_MWALK
    5280       idString(F,"F");
    5281 #endif
    5282       idDelete(&Gomega2);
    5283       idDelete(&M1);
    5284       rChangeCurrRing(newRing); // change the ring to newRing
    5285       G = idrMoveR(F,baseRing,currRing);
    5286       idDelete(&F);
     6013#ifdef TIME_TEST
     6014      to = clock();
     6015#endif
     6016      Gomega = MwalkInitialForm(G, next_weight);
     6017#ifdef TIME_TEST
     6018      tif = tif + clock()-to; //time for computing initial form ideal
     6019#endif
     6020      delete iv_M;
     6021    }
     6022
     6023    // test whether target weight vector is reached
     6024    if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)
     6025    {
    52876026      baseRing = currRing;
    5288       si_opt_1 = save1; //set original options, e. g. option(RedSB)
    5289       idSkipZeroes(G);
    5290 #ifdef TIME_TEST
    5291       to = clock();
    5292 #endif
    5293  //     if(si_opt_1 == (Sy_bit(OPT_REDSB)))
    5294   //    {
    5295         G = kInterRedCC(G,NULL); //reduce the Groebner basis <G> w.r.t. currRing, if option(redSB) is set
    5296   //    }
    5297 #ifdef TIME_TEST
    5298       tred = tred + clock() - to;
    5299 #endif
    5300       idSkipZeroes(G);
    53016027      delete next_weight;
    53026028      break;
    5303 #ifdef CHECK_IDEAL_MWALK
    5304       PrintS("\n//** Mwalk: last cone.\n");
    5305 #endif
    5306     }
    5307 #ifdef CHECK_IDEAL_MWALK
    5308     PrintS("\n//** Mwalk: update weight vectors.\n");
    5309 #endif
     6029    }
     6030
     6031#ifdef PRINT_VECTORS
     6032    if(printout > 0)
     6033    {
     6034      MivString(curr_weight, target_weight, next_weight);
     6035    }
     6036#endif
     6037
    53106038    for(i=nV-1; i>=0; i--)
    53116039    {
    5312       (*tmp_weight)[i] = (*curr_weight)[i];
    53136040      (*curr_weight)[i] = (*next_weight)[i];
    53146041    }
    53156042    delete next_weight;
    53166043  }
     6044  baseRing = currRing;
    53176045  rChangeCurrRing(XXRing);
    53186046  ideal result = idrMoveR(G,baseRing,currRing);
    53196047  idDelete(&G);
    5320 /*#ifdef CHECK_IDEAL_MWALK
    5321   pDelete(&p);
    5322 #endif*/
    5323   delete tmp_weight;
    53246048  delete ivNull;
    5325   delete exivlp;
    53266049#ifndef BUCHBERGER_ALG
    53276050  delete last_omega;
    53286051#endif
    5329 #ifdef TIME_TEST
    5330   Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
     6052  Print("\n//** Mrwalk: Groebner Walk took %d steps.\n", nstep);
     6053#ifdef TIME_TEST
    53316054  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
    5332   Print("\n//** Mwalk: Ergebnis.\n");
    53336055  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
    53346056  //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
    53356057#endif
     6058  si_opt_1 = save1; //set original options
    53366059  return(result);
    53376060}
    5338 
    5339 // 07.11.2012
    5340 // THE RANDOM WALK ALGORITHM  ideal Go, intvec* orig_M, intvec* target_M, ring baseRing
    5341 ideal Mrwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad, int pert_deg, ring baseRing)
    5342 {
    5343   BITSET save1 = si_opt_1; // save current options
    5344   //si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
    5345   //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
    5346   //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
    5347   Set_Error(FALSE);
    5348   Overflow_Error = FALSE;
    5349 #ifdef TIME_TEST
    5350   clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
    5351   xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
    5352   tinput = clock();
    5353   clock_t tim;
    5354 #endif
    5355   nstep=0;
    5356   int i,nwalk,endwalks = 0;
    5357   int nV = baseRing->N;
    5358 
    5359   ideal Gomega, M, F, Gomega1, Gomega2, M1; //, F1;
    5360   ring newRing;
    5361   ring XXRing = baseRing;
    5362   intvec* ivNull = new intvec(nV);
    5363   intvec* curr_weight = new intvec(nV);
    5364   intvec* target_weight = new intvec(nV);
    5365   intvec* exivlp = Mivlp(nV);
    5366   intvec* tmp_weight = new intvec(nV);
    5367   for(i=0; i<nV; i++)
    5368   {
    5369     (*tmp_weight)[i] = (*target_M)[i];
    5370   }
    5371   for(i=0; i<nV; i++)
    5372   {
    5373     (*curr_weight)[i] = (*orig_M)[i];
    5374     (*target_weight)[i] = (*target_M)[i];
    5375   }
    5376 #ifndef BUCHBERGER_ALG
    5377   intvec* hilb_func;
    5378    // to avoid (1,0,...,0) as the target vector
    5379   intvec* last_omega = new intvec(nV);
    5380   for(i=nV-1; i>0; i--)
    5381   {
    5382     (*last_omega)[i] = 1;
    5383   }
    5384   (*last_omega)[0] = 10000;
    5385 #endif
    5386   rComplete(currRing);
    5387 #ifdef CHECK_IDEAL_MWALK
    5388     idString(Go,"Go");
    5389 #endif
    5390 #ifdef TIME_TEST
    5391   to = clock();
    5392 #endif
    5393      if(orig_M->length() == nV)
    5394       {
    5395         newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
    5396       }
    5397       else
    5398       {
    5399         newRing = VMatrDefault(orig_M);
    5400       }
    5401   rChangeCurrRing(newRing);
    5402   ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
    5403   baseRing = currRing;
    5404 #ifdef TIME_TEST
    5405   tostd = clock()-to;
    5406 #endif
    5407 
    5408   nwalk = 0;
    5409   while(1)
    5410   {
    5411     nwalk ++;
    5412     nstep ++;
    5413 #ifdef TIME_TEST
    5414     to = clock();
    5415 #endif
    5416 #ifdef CHECK_IDEAL_MWALK
    5417     idString(G,"G");
    5418 #endif
    5419     Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
    5420 #ifdef TIME_TEST
    5421     tif = tif + clock()-to; //time for computing initial form ideal
    5422 #endif
    5423 #ifdef CHECK_IDEAL_MWALK
    5424     idString(Gomega,"Gomega");
    5425 #endif
    5426 #ifndef  BUCHBERGER_ALG
    5427     if(isNolVector(curr_weight) == 0)
    5428     {
    5429       hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
    5430     }
    5431     else
    5432     {
    5433       hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
    5434     }
    5435 #endif
    5436     if(nwalk == 1)
    5437     {
    5438       if(orig_M->length() == nV)
    5439       {
    5440         newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
    5441       }
    5442       else
    5443       {
    5444         newRing = VMatrDefault(orig_M);
    5445       }
    5446     }
    5447     else
    5448     {
    5449      if(target_M->length() == nV)
    5450      {
    5451        newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
    5452      }
    5453      else
    5454      {
    5455        newRing = VMatrRefine(target_M,curr_weight);
    5456      }
    5457     }
    5458     rChangeCurrRing(newRing);
    5459     Gomega1 = idrMoveR(Gomega, baseRing,currRing);
    5460     idDelete(&Gomega);
    5461     // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
    5462 #ifdef TIME_TEST
    5463     to = clock();
    5464 #endif
    5465 #ifndef  BUCHBERGER_ALG
    5466     M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
    5467     delete hilb_func;
    5468 #else
    5469     M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
    5470 #endif
    5471 #ifdef TIME_TEST
    5472     tstd = tstd + clock() - to;
    5473 #endif
    5474     idSkipZeroes(M);
    5475 #ifdef CHECK_IDEAL_MWALK
    5476     PrintS("\n//** Mwalk: computed M.\n");
    5477     idString(M, "M");
    5478 #endif
    5479     //change the ring to baseRing
    5480     rChangeCurrRing(baseRing);
    5481     M1 =  idrMoveR(M, newRing,currRing);
    5482     idDelete(&M);
    5483     Gomega2 = idrMoveR(Gomega1, newRing,currRing);
    5484     idDelete(&Gomega1);
    5485 #ifdef TIME_TEST
    5486     to = clock();
    5487 #endif
    5488     // 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
    5489     F = MLifttwoIdeal(Gomega2, M1, G);
    5490 #ifdef TIME_TEST
    5491     tlift = tlift + clock() - to;
    5492 #endif
    5493 #ifdef CHECK_IDEAL_MWALK
    5494     idString(F, "F");
    5495 #endif
    5496     idDelete(&Gomega2);
    5497     idDelete(&M1);
    5498     rChangeCurrRing(newRing); // change the ring to newRing
    5499     G = idrMoveR(F,baseRing,currRing);
    5500     idDelete(&F);
    5501     baseRing = currRing;
    5502 #ifdef TIME_TEST
    5503     to = clock();
    5504 #endif
    5505     //G = kStd(F1,NULL,testHomog,NULL,NULL,0,0,NULL);
    5506 #ifdef TIME_TEST
    5507     tstd = tstd + clock() - to;
    5508 #endif
    5509     idSkipZeroes(G);
    5510 #ifdef CHECK_IDEAL_MWALK
    5511     idString(G, "G");
    5512 #endif
    5513 #ifdef TIME_TEST
    5514     to = clock();
    5515 #endif
    5516     intvec* next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, pert_deg);//next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
    5517 #ifdef TIME_TEST
    5518     tnw = tnw + clock() - to;
    5519 #endif
    5520 #ifdef PRINT_VECTORS
    5521     MivString(curr_weight, target_weight, next_weight);
    5522 #endif
    5523     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)
    5524     {
    5525 #ifdef CHECK_IDEAL_MWALK
    5526       PrintS("\n//** Mwalk: entering last cone.\n");
    5527 #endif
    5528       Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
    5529       if(target_M->length() == nV)
    5530       {
    5531         newRing = VMrDefault(target_weight); // define a new ring with ordering "(a(curr_weight),lp)
    5532       }
    5533       else
    5534       {
    5535         newRing = VMatrDefault(target_M);
    5536       }
    5537       rChangeCurrRing(newRing);
    5538       Gomega1 = idrMoveR(Gomega, baseRing,currRing);
    5539       idDelete(&Gomega);
    5540 #ifdef CHECK_IDEAL_MWALK
    5541       idString(Gomega1, "Gomega");
    5542 #endif
    5543       M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
    5544 #ifdef CHECK_IDEAL_MWALK
    5545       idString(M,"M");
    5546 #endif
    5547       rChangeCurrRing(baseRing);
    5548       M1 =  idrMoveR(M, newRing,currRing);
    5549       idDelete(&M);
    5550       Gomega2 = idrMoveR(Gomega1, newRing,currRing);
    5551       idDelete(&Gomega1);
    5552       F = MLifttwoIdeal(Gomega2, M1, G);
    5553 #ifdef CHECK_IDEAL_MWALK
    5554       idString(F,"F");
    5555 #endif
    5556       idDelete(&Gomega2);
    5557       idDelete(&M1);
    5558       rChangeCurrRing(newRing); // change the ring to newRing
    5559       G = idrMoveR(F,baseRing,currRing);
    5560       idDelete(&F);
    5561       baseRing = currRing;
    5562       si_opt_1 = save1; //set original options, e. g. option(RedSB)
    5563       idSkipZeroes(G);
    5564 #ifdef TIME_TEST
    5565       to = clock();
    5566 #endif
    5567  //     if(si_opt_1 == (Sy_bit(OPT_REDSB)))
    5568   //    {
    5569         //G = kInterRedCC(G,NULL); //reduce the Groebner basis <G> w.r.t. currRing, if option(redSB) is set
    5570   //    }
    5571 #ifdef TIME_TEST
    5572       tred = tred + clock() - to;
    5573 #endif
    5574       idSkipZeroes(G);
    5575       delete next_weight;
    5576       break;
    5577 #ifdef CHECK_IDEAL_MWALK
    5578       PrintS("\n//** Mwalk: last cone.\n");
    5579 #endif
    5580     }
    5581 #ifdef CHECK_IDEAL_MWALK
    5582     PrintS("\n//** Mwalk: update weight vectors.\n");
    5583 #endif
    5584     for(i=nV-1; i>=0; i--)
    5585     {
    5586       (*tmp_weight)[i] = (*curr_weight)[i];
    5587       (*curr_weight)[i] = (*next_weight)[i];
    5588     }
    5589     delete next_weight;
    5590   }
    5591   rChangeCurrRing(XXRing);
    5592   ideal result = idrMoveR(G,baseRing,currRing);
    5593   idDelete(&G);
    5594 /*#ifdef CHECK_IDEAL_MWALK
    5595   pDelete(&p);
    5596 #endif*/
    5597   delete tmp_weight;
    5598   delete ivNull;
    5599   delete exivlp;
    5600 #ifndef BUCHBERGER_ALG
    5601   delete last_omega;
    5602 #endif
    5603 #ifdef TIME_TEST
    5604   Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
    5605   TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
    5606   Print("\n//** Mwalk: Ergebnis.\n");
    5607   //Print("\n// pSetm_Error = (%d)", ErrorCheck());
    5608   //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
    5609 #endif
    5610   return(result);
    5611 }
    5612 
    5613 //unused
    5614 #if 0
    5615 ideal Mwalk_tst(ideal Go, intvec* curr_weight, intvec* target_weight)
    5616 {
    5617   //clock_t tinput=clock();
    5618   //idString(Go,"Ginp");
    5619   int i, nV = currRing->N;
    5620   int nwalk=0, endwalks=0;
    5621 
    5622   ideal Gomega, M, F, Gomega1, Gomega2, M1, F1, G;
    5623   // ideal G1; ring endRing;
    5624   ring newRing, oldRing;
    5625   intvec* ivNull = new intvec(nV);
    5626   ring XXRing = currRing;
    5627 
    5628   intvec* tmp_weight = new intvec(nV);
    5629   for(i=nV-1; i>=0; i--)
    5630   {
    5631     (*tmp_weight)[i] = (*curr_weight)[i];
    5632   }
    5633   /* the monomial ordering of this current ring would be "dp" */
    5634   G = MstdCC(Go);
    5635 #ifndef BUCHBERGER_ALG
    5636   intvec* hilb_func;
    5637 #endif
    5638   /* to avoid (1,0,...,0) as the target vector */
    5639   intvec* last_omega = new intvec(nV);
    5640   for(i=nV-1; i>0; i--)
    5641     (*last_omega)[i] = 1;
    5642   (*last_omega)[0] = 10000;
    5643 
    5644   while(1)
    5645   {
    5646     nwalk ++;
    5647     //Print("\n// Entering the %d-th step:", nwalk);
    5648     //Print("\n// ring r[%d] = %s;", nwalk, rString(currRing));
    5649     idString(G,"G");
    5650     /* compute an initial form ideal of <G> w.r.t. "curr_vector" */
    5651     Gomega = MwalkInitialForm(G, curr_weight);
    5652     //ivString(curr_weight, "omega");
    5653     idString(Gomega,"Gw");
    5654 
    5655 #ifndef  BUCHBERGER_ALG
    5656     if(isNolVector(curr_weight) == 0)
    5657       hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
    5658     else
    5659       hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
    5660 #endif // BUCHBERGER_ALG
    5661 
    5662 
    5663     oldRing = currRing;
    5664 
    5665     /* define a new ring that its ordering is "(a(curr_weight),lp) */
    5666     VMrDefault(curr_weight);
    5667     newRing = currRing;
    5668 
    5669     Gomega1 = idrMoveR(Gomega, oldRing,currRing);
    5670 
    5671     /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
    5672 #ifdef  BUCHBERGER_ALG
    5673     M = MstdhomCC(Gomega1);
    5674 #else
    5675     M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
    5676     delete hilb_func;
    5677 #endif // BUCHBERGER_ALG
    5678 
    5679     idString(M,"M");
    5680 
    5681       /* change the ring to oldRing */
    5682     rChangeCurrRing(oldRing);
    5683     M1 =  idrMoveR(M, newRing,currRing);
    5684     Gomega2 =  idrMoveR(Gomega1, newRing,currRing);
    5685 
    5686       /* compute a representation of the generators of submod (M)
    5687          with respect to those of mod (Gomega).
    5688          Gomega is a reduced Groebner basis w.r.t. the current ring */
    5689     F = MLifttwoIdeal(Gomega2, M1, G);
    5690     idDelete(&M1);
    5691     idDelete(&Gomega2);
    5692     idDelete(&G);
    5693     idString(F,"F");
    5694 
    5695     /* change the ring to newRing */
    5696     rChangeCurrRing(newRing);
    5697     F1 = idrMoveR(F, oldRing,currRing);
    5698 
    5699     /* reduce the Groebner basis <G> w.r.t. new ring */
    5700     G = kInterRedCC(F1, NULL);
    5701     //idSkipZeroes(G);//done by kInterRed
    5702     idDelete(&F1);
    5703     idString(G,"G");
    5704     if(endwalks == 1)
    5705       break;
    5706 
    5707     /* compute a next weight vector */
    5708     intvec* next_weight = MkInterRedNextWeight(curr_weight,target_weight,G);
    5709 #ifdef PRINT_VECTORS
    5710     MivString(curr_weight, target_weight, next_weight);
    5711 #endif
    5712 
    5713     if(MivComp(next_weight, ivNull) == 1)
    5714     {
    5715       delete next_weight;
    5716       break;
    5717     }
    5718     if(MivComp(next_weight, target_weight) == 1)
    5719       endwalks = 1;
    5720 
    5721     for(i=nV-1; i>=0; i--)
    5722       (*tmp_weight)[i] = (*curr_weight)[i];
    5723 
    5724     /* 06.11.01 to free the memory: NOT Changed!!*/
    5725     for(i=nV-1; i>=0; i--)
    5726       (*curr_weight)[i] = (*next_weight)[i];
    5727     delete next_weight;
    5728   }
    5729   rChangeCurrRing(XXRing);
    5730   G = idrMoveR(G, newRing,currRing);
    5731 
    5732   delete tmp_weight;
    5733   delete ivNull;
    5734   PrintLn();
    5735   return(G);
    5736 }
    5737 #endif
    57386061
    57396062/**************************************************************/
     
    57496072   2) the changed perturbation walk algorithm with a decreased degree.
    57506073*/
    5751 // use kStd, if nP = 0, else call LastGB
     6074// if nP = 0 use kStd, else call LastGB
    57526075ideal Mpwalk(ideal Go, int op_deg, int tp_deg,intvec* curr_weight,
    5753              intvec* target_weight, int nP)
     6076             intvec* target_weight, int nP, int reduction, int printout)
    57546077{
     6078  BITSET save1 = si_opt_1; // save current options
     6079  if(reduction == 0)
     6080  {
     6081    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
     6082    si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
     6083  }
    57556084  Set_Error(FALSE  );
    57566085  Overflow_Error = FALSE;
    57576086  //Print("// pSetm_Error = (%d)", ErrorCheck());
    5758 
     6087#ifdef TIME_TEST
    57596088  clock_t  tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
    57606089  xtextra=0;
     
    57636092
    57646093  clock_t tim;
    5765 
     6094#endif
    57666095  nstep = 0;
    57676096  int i, ntwC=1, ntestw=1,  nV = currRing->N;
    5768   int endwalks=0;
    5769 
    5770   ideal Gomega, M, F, G, Gomega1, Gomega2, M1,F1,Eresult,ssG;
     6097
     6098  //check that perturbation degree is valid
     6099  if(op_deg < 1 || tp_deg < 1 || op_deg > nV || tp_deg > nV)
     6100  {
     6101    Werror("Invalid perturbation degree.\n");
     6102    return NULL;
     6103  }
     6104
     6105  BOOLEAN endwalks = FALSE;
     6106  ideal Gomega, M, F, FF, G, Gomega1, Gomega2, M1,F1,Eresult,ssG;
    57716107  ring newRing, oldRing, TargetRing;
    57726108  intvec* iv_M_dp;
     
    57896125
    57906126  ring XXRing = currRing;
    5791 
    5792 
     6127#ifdef TIME_TEST
    57936128  to = clock();
    5794   /* perturbs the original vector */
     6129#endif
     6130  // perturbs the original vector
    57956131  if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) := "dp"
    57966132  {
    57976133    G = MstdCC(Go);
     6134#ifdef TIME_TEST
    57986135    tostd = clock()-to;
     6136#endif
    57996137    if(op_deg != 1){
    58006138      iv_M_dp = MivMatrixOrderdp(nV);
     
    58096147      DefRingPar(curr_weight);
    58106148    else
    5811       rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 1
     6149      rChangeCurrRing(VMrDefault(curr_weight));
    58126150
    58136151    G = idrMoveR(Go, XXRing,currRing);
    58146152    G = MstdCC(G);
     6153#ifdef TIME_TEST
    58156154    tostd = clock()-to;
     6155#endif
    58166156    if(op_deg != 1){
    58176157      iv_M_dp = MivMatrixOrder(curr_weight);
     
    58246164  ring HelpRing = currRing;
    58256165
    5826   /* perturbs the target weight vector */
     6166  // perturbs the target weight vector
    58276167  if(tp_deg > 1 && tp_deg <= nV)
    58286168  {
     
    58306170      DefRingPar(target_weight);
    58316171    else
    5832       rChangeCurrRing(VMrDefault(target_weight)); // Aenderung 2
     6172      rChangeCurrRing(VMrDefault(target_weight));
    58336173
    58346174    TargetRing = currRing;
     
    58376177    {
    58386178      iv_M_lp = MivMatrixOrderlp(nV);
    5839       //ivString(iv_M_lp, "iv_M_lp");
    5840       //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
    58416179      target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
    58426180    }
     
    58446182    {
    58456183      iv_M_lp = MivMatrixOrder(target_weight);
    5846       //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
    58476184      target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
    58486185    }
     
    58526189    G = idrMoveR(ssG, TargetRing,currRing);
    58536190  }
    5854   /*
    5855     Print("\n// Perturbationwalkalg. vom Gradpaar (%d,%d):",op_deg,tp_deg);
    5856     ivString(curr_weight, "new sigma");
    5857     ivString(target_weight, "new tau");
    5858   */
     6191  if(printout > 0)
     6192  {
     6193    Print("\n//** Mpwalk: Perturbation Walk of degree (%d,%d):",op_deg,tp_deg);
     6194#ifdef PRINT_VECTORS
     6195    ivString(curr_weight, "//** Mpwalk: new current weight");
     6196    ivString(target_weight, "//** Mpwalk: new target weight");
     6197#endif
     6198  }
    58596199  while(1)
    58606200  {
    58616201    nstep ++;
     6202#ifdef TIME_TEST
    58626203    to = clock();
    5863     /* compute an initial form ideal of <G> w.r.t. the weight vector
    5864        "curr_weight" */
     6204#endif
     6205    // compute an initial form ideal of <G> w.r.t. the weight vector
     6206    // "curr_weight"
    58656207    Gomega = MwalkInitialForm(G, curr_weight);
    5866 
     6208#ifdef TIME_TEST
     6209    tif = tif + clock()-to;
     6210#endif
     6211#ifdef CHECK_IDEAL_MWALK
     6212    if(printout > 1)
     6213    {
     6214      idString(Gomega,"//** Mpwalk: Gomega");
     6215    }
     6216#endif
     6217    if(reduction == 0 && nstep > 1)
     6218    {
     6219/*
     6220      // check whether weight vector is in the interior of the cone
     6221      while(1)
     6222      {
     6223        FF = middleOfCone(G,Gomega);
     6224        if(FF != NULL)
     6225        {
     6226          idDelete(&G);
     6227          G = idCopy(FF);
     6228          idDelete(&FF);
     6229          next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
     6230#ifdef PRINT_VECTORS
     6231          if(printout > 0)
     6232          {
     6233            MivString(curr_weight, target_weight, next_weight);
     6234          }
     6235#endif
     6236        }
     6237        else
     6238        {
     6239          break;
     6240        }
     6241        for(i=nV-1; i>=0; i--)
     6242        {
     6243          (*curr_weight)[i] = (*next_weight)[i];
     6244        }
     6245        Gomega = MwalkInitialForm(G, curr_weight);
     6246#ifdef CHECK_IDEAL_MWALK
     6247        if(printout > 1)
     6248        {
     6249          idString(Gomega,"//** Mpwalk: Gomega");
     6250        }
     6251#endif
     6252      }
     6253*/
     6254      FF = middleOfCone(G,Gomega);
     6255      if(FF != NULL)
     6256      {
     6257        idDelete(&G);
     6258        G = idCopy(FF);
     6259        idDelete(&FF);
     6260        goto NEXT_VECTOR;
     6261      }
     6262    }
    58676263
    58686264#ifdef ENDWALKS
    5869     if(endwalks == 1){
     6265    if(endwalks == TRUE)
     6266    {
    58706267      Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     6268/*
    58716269      idElements(G, "G");
    5872       // idElements(Gomega, "Gw");
    58736270      headidString(G, "G");
    5874       //headidString(Gomega, "Gw");
    5875     }
    5876 #endif
    5877 
    5878     tif = tif + clock()-to;
     6271*/
     6272    }
     6273#endif
    58796274
    58806275#ifndef  BUCHBERGER_ALG
     
    58916286      DefRingPar(curr_weight);
    58926287    else
    5893       rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 3
     6288      rChangeCurrRing(VMrDefault(curr_weight));
    58946289
    58956290    newRing = currRing;
     
    58976292
    58986293#ifdef ENDWALKS
    5899     if(endwalks==1)
     6294    if(endwalks==TRUE)
    59006295    {
    59016296      Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     6297/*
    59026298      idElements(Gomega1, "Gw");
    59036299      headidString(Gomega1, "headGw");
     6300*/
    59046301      PrintS("\n// compute a rGB of Gw:\n");
    5905 
    59066302#ifndef  BUCHBERGER_ALG
    59076303      ivString(hilb_func, "w");
     
    59096305    }
    59106306#endif
    5911 
     6307#ifdef TIME_TEST
    59126308    tim = clock();
    59136309    to = clock();
    5914     /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
     6310#endif
     6311    // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
    59156312#ifdef  BUCHBERGER_ALG
    59166313    M = MstdhomCC(Gomega1);
     
    59186315    M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
    59196316    delete hilb_func;
    5920 #endif // BUCHBERGER_ALG
    5921 
    5922     if(endwalks == 1){
     6317#endif
     6318
     6319    if(endwalks == TRUE)
     6320    {
     6321#ifdef TIME_TEST
    59236322      xtstd = xtstd+clock()-to;
     6323#endif
    59246324#ifdef ENDWALKS
    59256325      Print("\n// time for the last std(Gw)  = %.2f sec\n",
     
    59286328    }
    59296329    else
     6330    {
     6331#ifdef TIME_TEST
    59306332      tstd=tstd+clock()-to;
    5931 
    5932     /* change the ring to oldRing */
     6333#endif
     6334    }
     6335#ifdef CHECK_IDEAL_MWALK
     6336    if(printout > 2)
     6337    {
     6338      idString(M,"//** Mpwalk: M");
     6339    }
     6340#endif
     6341    // change the ring to oldRing
    59336342    rChangeCurrRing(oldRing);
    59346343    M1 =  idrMoveR(M, newRing,currRing);
    59356344    Gomega2 =  idrMoveR(Gomega1, newRing,currRing);
    5936 
    5937     //if(endwalks==1)  PrintS("\n// Lifting is working:..");
    5938 
     6345#ifdef TIME_TEST
    59396346    to=clock();
     6347#endif
    59406348    /* compute a representation of the generators of submod (M)
    59416349       with respect to those of mod (Gomega).
    59426350       Gomega is a reduced Groebner basis w.r.t. the current ring */
    59436351    F = MLifttwoIdeal(Gomega2, M1, G);
    5944     if(endwalks != 1)
     6352#ifdef TIME_TEST
     6353    if(endwalks == FALSE)
    59456354      tlift = tlift+clock()-to;
    59466355    else
    59476356      xtlift=clock()-to;
     6357#endif
     6358#ifdef CHECK_IDEAL_MWALK
     6359    if(printout > 2)
     6360    {
     6361      idString(F,"//** Mpwalk: F");
     6362    }
     6363#endif
    59486364
    59496365    idDelete(&M1);
     
    59516367    idDelete(&G);
    59526368
    5953     /* change the ring to newRing */
     6369    // change the ring to newRing
    59546370    rChangeCurrRing(newRing);
    5955     F1 = idrMoveR(F, oldRing,currRing);
    5956 
    5957     //if(endwalks==1)PrintS("\n// InterRed is working now:");
    5958 
     6371    if(reduction == 0)
     6372    {
     6373      G = idrMoveR(F,oldRing,currRing);
     6374    }
     6375    else
     6376    {
     6377      F1 = idrMoveR(F, oldRing,currRing);
     6378      if(printout > 2)
     6379      {
     6380        PrintS("\n //** Mpwalk: reduce the Groebner basis.\n");
     6381      }
     6382#ifdef TIME_TEST
     6383      to=clock();
     6384#endif
     6385      G = kInterRedCC(F1, NULL);
     6386#ifdef TIME_TEST
     6387      if(endwalks == FALSE)
     6388        tred = tred+clock()-to;
     6389      else
     6390        xtred=clock()-to;
     6391#endif
     6392      idDelete(&F1);
     6393    }
     6394    if(endwalks == TRUE)
     6395      break;
     6396
     6397    NEXT_VECTOR:
     6398#ifdef TIME_TEST
    59596399    to=clock();
    5960     /* reduce the Groebner basis <G> w.r.t. new ring */
    5961     G = kInterRedCC(F1, NULL);
    5962     if(endwalks != 1)
    5963       tred = tred+clock()-to;
    5964     else
    5965       xtred=clock()-to;
    5966 
    5967     idDelete(&F1);
    5968 
    5969     if(endwalks == 1)
    5970       break;
    5971 
    5972     to=clock();
    5973     /* compute a next weight vector */
     6400#endif
     6401    // compute a next weight vector
    59746402    next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     6403#ifdef TIME_TEST
    59756404    tnw=tnw+clock()-to;
     6405#endif
    59766406#ifdef PRINT_VECTORS
    5977     MivString(curr_weight, target_weight, next_weight);
     6407    if(printout > 0)
     6408    {
     6409      MivString(curr_weight, target_weight, next_weight);
     6410    }
    59786411#endif
    59796412
     
    59946427    }
    59956428    if(MivComp(next_weight, target_weight) == 1)
    5996       endwalks = 1;
     6429      endwalks = TRUE;
    59976430
    59986431    for(i=nV-1; i>=0; i--)
     
    60006433
    60016434    delete next_weight;
    6002   }//while
     6435  }//end of while-loop
    60036436
    60046437  if(tp_deg != 1)
     
    60146447        DefRingPar(orig_target);
    60156448      else
    6016         rChangeCurrRing(VMrDefault(orig_target)); //Aenderung
     6449        rChangeCurrRing(VMrDefault(orig_target));
    60176450
    60186451    TargetRing=currRing;
    60196452    F1 = idrMoveR(G, newRing,currRing);
    6020 #ifdef CHECK_IDEAL
     6453/*
     6454#ifdef CHECK_IDEAL_MWALK
    60216455      headidString(G, "G");
    60226456#endif
    6023 
     6457*/
    60246458
    60256459    // check whether the pertubed target vector stays in the correct cone
     
    60306464    if( ntestw != 1 || ntwC == 0)
    60316465    {
    6032       /*
    6033       if(ntestw != 1){
     6466      if(ntestw != 1 && printout >2)
     6467      {
    60346468        ivString(pert_target_vector, "tau");
    60356469        PrintS("\n// ** perturbed target vector doesn't stay in cone!!");
    60366470        Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
    6037         idElements(F1, "G");
    6038       }
    6039       */
     6471        //idElements(F1, "G");
     6472      }
    60406473      // LastGB is "better" than the kStd subroutine
    60416474      to=clock();
     
    60686501    Eresult = idrMoveR(G, newRing,currRing);
    60696502  }
     6503  si_opt_1 = save1; //set original options, e. g. option(RedSB)
    60706504  delete ivNull;
    60716505  if(tp_deg != 1)
     
    60826516             tnw+xtnw);
    60836517
    6084   Print("\n// pSetm_Error = (%d)", ErrorCheck());
    6085   Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep,  Overflow_Error);
    6086 #endif
     6518  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
     6519  //Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep,  Overflow_Error);
     6520#endif
     6521  Print("\n//** Mpwalk: Perturbation Walk took %d steps.\n", nstep);
     6522  return(Eresult);
     6523}
     6524
     6525/*******************************************************
     6526 * THE PERTURBATION WALK ALGORITHM WITH RANDOM ELEMENT *
     6527 *******************************************************/
     6528ideal Mprwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad,
     6529              int op_deg, int tp_deg, int nP, int reduction, int printout)
     6530{
     6531  BITSET save1 = si_opt_1; // save current options
     6532  if(reduction == 0)
     6533  {
     6534    si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
     6535    si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
     6536  }
     6537  Set_Error(FALSE);
     6538  Overflow_Error = FALSE;
     6539  //Print("// pSetm_Error = (%d)", ErrorCheck());
     6540#ifdef TIME_TEST
     6541  clock_t  tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
     6542  xtextra=0;
     6543  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
     6544  tinput = clock();
     6545
     6546  clock_t tim;
     6547#endif
     6548  nstep = 0;
     6549  int i, ntwC=1, ntestw=1, nV = currRing->N; //polylength
     6550
     6551  //check that weight radius is valid
     6552  if(weight_rad < 0)
     6553  {
     6554    Werror("Invalid radius.\n");
     6555    return NULL;
     6556  }
     6557
     6558  //check that perturbation degree is valid
     6559  if(op_deg < 1 || tp_deg < 1 || op_deg > nV || tp_deg > nV)
     6560  {
     6561    Werror("Invalid perturbation degree.\n");
     6562    return NULL;
     6563  }
     6564
     6565  BOOLEAN endwalks = FALSE;
     6566
     6567  ideal Gomega, M, F, FF, G, Gomega1, Gomega2, M1,F1,Eresult,ssG;
     6568  ring newRing, oldRing, TargetRing;
     6569  intvec* iv_M;
     6570  intvec* iv_M_dp;
     6571  intvec* iv_M_lp;
     6572  intvec* exivlp = Mivlp(nV);
     6573  intvec* curr_weight = new intvec(nV);
     6574  intvec* target_weight = new intvec(nV);
     6575  for(i=0; i<nV; i++)
     6576  {
     6577    (*curr_weight)[i] = (*orig_M)[i];
     6578    (*target_weight)[i] = (*target_M)[i];
     6579  }
     6580  intvec* orig_target = target_weight;
     6581  intvec* pert_target_vector = target_weight;
     6582  intvec* ivNull = new intvec(nV);
     6583  intvec* iv_dp = MivUnit(nV);// define (1,1,...,1)
     6584#ifndef BUCHBERGER_ALG
     6585  intvec* hilb_func;
     6586#endif
     6587  intvec* next_weight;
     6588
     6589  // to avoid (1,0,...,0) as the target vector
     6590  intvec* last_omega = new intvec(nV);
     6591  for(i=nV-1; i>0; i--)
     6592    (*last_omega)[i] = 1;
     6593  (*last_omega)[0] = 10000;
     6594
     6595  ring XXRing = currRing;
     6596
     6597  // perturbs the original vector
     6598  if(orig_M->length() == nV)
     6599  {
     6600    if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) := "dp"
     6601    {
     6602#ifdef TIME_TEST
     6603  to = clock();
     6604#endif
     6605      G = MstdCC(Go);
     6606#ifdef TIME_TEST
     6607      tostd = clock()-to;
     6608#endif
     6609      if(op_deg != 1)
     6610      {
     6611        iv_M_dp = MivMatrixOrderdp(nV);
     6612        curr_weight = MPertVectors(G, iv_M_dp, op_deg);
     6613      }
     6614    }
     6615    else
     6616    {
     6617      //define ring order := (a(curr_weight),lp);
     6618      if (rParameter(currRing) != NULL)
     6619        DefRingPar(curr_weight);
     6620      else
     6621        rChangeCurrRing(VMrDefault(curr_weight));
     6622
     6623      G = idrMoveR(Go, XXRing,currRing);
     6624#ifdef TIME_TEST
     6625  to = clock();
     6626#endif
     6627      G = MstdCC(G);
     6628#ifdef TIME_TEST
     6629      tostd = clock()-to;
     6630#endif
     6631      if(op_deg != 1)
     6632      {
     6633        iv_M_dp = MivMatrixOrder(curr_weight);
     6634        curr_weight = MPertVectors(G, iv_M_dp, op_deg);
     6635      }
     6636    }
     6637  }
     6638  else
     6639  {
     6640    rChangeCurrRing(VMatrDefault(orig_M));
     6641    G = idrMoveR(Go, XXRing,currRing);
     6642#ifdef TIME_TEST
     6643    to = clock();
     6644#endif
     6645    G = MstdCC(G);
     6646#ifdef TIME_TEST
     6647    tostd = clock()-to;
     6648#endif
     6649    if(op_deg != 1)
     6650    {
     6651      curr_weight = MPertVectors(G, orig_M, op_deg);
     6652    }
     6653  }
     6654
     6655  delete iv_dp;
     6656  if(op_deg != 1) delete iv_M_dp;
     6657
     6658  ring HelpRing = currRing;
     6659
     6660  // perturbs the target weight vector
     6661  if(target_M->length() == nV)
     6662  {
     6663    if(tp_deg > 1 && tp_deg <= nV)
     6664    {
     6665      if (rParameter(currRing) != NULL)
     6666        DefRingPar(target_weight);
     6667      else
     6668        rChangeCurrRing(VMrDefault(target_weight));
     6669
     6670      TargetRing = currRing;
     6671      ssG = idrMoveR(G,HelpRing,currRing);
     6672      if(MivSame(target_weight, exivlp) == 1)
     6673      {
     6674        iv_M_lp = MivMatrixOrderlp(nV);
     6675        target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
     6676      }
     6677      else
     6678      {
     6679        iv_M_lp = MivMatrixOrder(target_weight);
     6680        target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
     6681      }
     6682      delete iv_M_lp;
     6683      pert_target_vector = target_weight;
     6684      rChangeCurrRing(HelpRing);
     6685      G = idrMoveR(ssG, TargetRing,currRing);
     6686    }
     6687  }
     6688  else
     6689  {
     6690    if(tp_deg > 1 && tp_deg <= nV)
     6691    {
     6692      rChangeCurrRing(VMatrDefault(target_M));
     6693      TargetRing = currRing;
     6694      ssG = idrMoveR(G,HelpRing,currRing);
     6695      target_weight = MPertVectors(ssG, target_M, tp_deg);
     6696    }
     6697  }
     6698  if(printout > 0)
     6699  {
     6700    Print("\n//** Mprwalk: Random Perturbation Walk of degree (%d,%d):",op_deg,tp_deg);
     6701    ivString(curr_weight, "//** Mprwalk: new current weight");
     6702    ivString(target_weight, "//** Mprwalk: new target weight");
     6703  }
     6704
     6705#ifdef TIME_TEST
     6706  to = clock();
     6707#endif
     6708  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
     6709#ifdef TIME_TEST
     6710  tif = tif + clock()-to; //time for computing initial form ideal
     6711#endif
     6712
     6713  while(1)
     6714  {
     6715    nstep ++;
     6716#ifdef CHECK_IDEAL_MWALK
     6717    if(printout > 1)
     6718    {
     6719      idString(Gomega,"//** Mprwalk: Gomega");
     6720    }
     6721#endif
     6722
     6723    if(reduction == 0 && nstep > 1)
     6724    {
     6725/*
     6726      // check whether weight vector is in the interior of the cone
     6727      while(1)
     6728      {
     6729        FF = middleOfCone(G,Gomega);
     6730        if(FF != NULL)
     6731        {
     6732          idDelete(&G);
     6733          G = idCopy(FF);
     6734          idDelete(&FF);
     6735          next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
     6736#ifdef PRINT_VECTORS
     6737          if(printout > 0)
     6738          {
     6739            MivString(curr_weight, target_weight, next_weight);
     6740          }
     6741#endif
     6742        }
     6743        else
     6744        {
     6745          break;
     6746        }
     6747        for(i=nV-1; i>=0; i--)
     6748        {
     6749          (*curr_weight)[i] = (*next_weight)[i];
     6750        }
     6751        Gomega = MwalkInitialForm(G, curr_weight);
     6752#ifdef CHECK_IDEAL_MWALK
     6753        if(printout > 1)
     6754        {
     6755          idString(Gomega,"//** Mprwalk: Gomega");
     6756        }
     6757#endif
     6758      }
     6759*/
     6760      FF = middleOfCone(G,Gomega);
     6761      if(FF != NULL)
     6762      {
     6763        idDelete(&G);
     6764        G = idCopy(FF);
     6765        idDelete(&FF);
     6766        goto NEXT_VECTOR;
     6767      }
     6768    }
     6769
     6770#ifdef ENDWALKS
     6771    if(endwalks == TRUE)
     6772    {
     6773      Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     6774/*
     6775      idElements(G, "G");
     6776      headidString(G, "G");
     6777*/
     6778    }
     6779#endif
     6780
     6781#ifndef  BUCHBERGER_ALG
     6782    if(isNolVector(curr_weight) == 0)
     6783      hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
     6784    else
     6785      hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
     6786#endif // BUCHBERGER_ALG
     6787
     6788    oldRing = currRing;
     6789
     6790    if(target_M->length() == nV)
     6791    {
     6792      // define a new ring with ordering "(a(curr_weight),lp)
     6793      if (rParameter(currRing) != NULL)
     6794        DefRingPar(curr_weight);
     6795      else
     6796        rChangeCurrRing(VMrDefault(curr_weight));
     6797    }
     6798    else
     6799    {
     6800      rChangeCurrRing(VMatrRefine(target_M,curr_weight));
     6801    }
     6802    newRing = currRing;
     6803    Gomega1 = idrMoveR(Gomega, oldRing,currRing);
     6804#ifdef ENDWALKS
     6805    if(endwalks == TRUE)
     6806    {
     6807      Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     6808/*
     6809      idElements(Gomega1, "Gw");
     6810      headidString(Gomega1, "headGw");
     6811*/
     6812      PrintS("\n// compute a rGB of Gw:\n");
     6813
     6814#ifndef  BUCHBERGER_ALG
     6815      ivString(hilb_func, "w");
     6816#endif
     6817    }
     6818#endif
     6819#ifdef TIME_TEST
     6820    tim = clock();
     6821    to = clock();
     6822#endif
     6823    // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
     6824#ifdef  BUCHBERGER_ALG
     6825    M = MstdhomCC(Gomega1);
     6826#else
     6827    M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
     6828    delete hilb_func;
     6829#endif
     6830#ifdef CHECK_IDEAL_MWALK
     6831    if(printout > 2)
     6832    {
     6833      idString(M,"//** Mprwalk: M");
     6834    }
     6835#endif
     6836#ifdef TIME_TEST
     6837    if(endwalks == TRUE)
     6838    {
     6839      xtstd = xtstd+clock()-to;
     6840#ifdef ENDWALKS
     6841      Print("\n// time for the last std(Gw)  = %.2f sec\n",
     6842            ((double) clock())/1000000 -((double)tim) /1000000);
     6843#endif
     6844    }
     6845    else
     6846      tstd=tstd+clock()-to;
     6847#endif
     6848    /* change the ring to oldRing */
     6849    rChangeCurrRing(oldRing);
     6850    M1 =  idrMoveR(M, newRing,currRing);
     6851    Gomega2 =  idrMoveR(Gomega1, newRing,currRing);
     6852#ifdef TIME_TEST
     6853    to=clock();
     6854#endif
     6855    /* compute a representation of the generators of submod (M)
     6856       with respect to those of mod (Gomega).
     6857       Gomega is a reduced Groebner basis w.r.t. the current ring */
     6858    F = MLifttwoIdeal(Gomega2, M1, G);
     6859#ifdef TIME_TEST
     6860    if(endwalks == FALSE)
     6861      tlift = tlift+clock()-to;
     6862    else
     6863      xtlift=clock()-to;
     6864#endif
     6865#ifdef CHECK_IDEAL_MWALK
     6866    if(printout > 2)
     6867    {
     6868      idString(F,"//** Mprwalk: F");
     6869    }
     6870#endif
     6871
     6872    idDelete(&M1);
     6873    idDelete(&Gomega2);
     6874    idDelete(&G);
     6875
     6876    // change the ring to newRing
     6877    rChangeCurrRing(newRing);
     6878    if(reduction == 0)
     6879    {
     6880      G = idrMoveR(F,oldRing,currRing);
     6881    }
     6882    else
     6883    {
     6884      F1 = idrMoveR(F, oldRing,currRing);
     6885      if(printout > 2)
     6886      {
     6887        PrintS("\n //** Mprwalk: reduce the Groebner basis.\n");
     6888      }
     6889#ifdef TIME_TEST
     6890      to=clock();
     6891#endif
     6892      G = kInterRedCC(F1, NULL);
     6893#ifdef TIME_TEST
     6894      if(endwalks == FALSE)
     6895        tred = tred+clock()-to;
     6896      else
     6897        xtred=clock()-to;
     6898#endif
     6899      idDelete(&F1);
     6900    }
     6901
     6902    if(endwalks == TRUE)
     6903      break;
     6904
     6905    NEXT_VECTOR:
     6906#ifdef TIME_TEST
     6907    to = clock();
     6908#endif
     6909    next_weight = next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     6910#ifdef TIME_TEST
     6911    tnw = tnw + clock() - to;
     6912#endif
     6913
     6914#ifdef TIME_TEST
     6915    to = clock();
     6916#endif
     6917    // compute an initial form ideal of <G> w.r.t. "next_vector"
     6918    Gomega = MwalkInitialForm(G, next_weight);
     6919#ifdef TIME_TEST
     6920    tif = tif + clock()-to; //time for computing initial form ideal
     6921#endif
     6922
     6923    //lengthpoly(Gomega) = 1 if there is a polynomial in Gomega with at least 3 monomials and 0 otherwise
     6924    if(lengthpoly(Gomega) > 0)
     6925    {
     6926      Print("\n there is a polynomial in Gomega with at least 3 monomials,\n");
     6927      // low-dimensional facet of the cone
     6928      delete next_weight;
     6929      if(target_M->length() == nV)
     6930      {
     6931        iv_M = MivMatrixOrder(curr_weight);
     6932      }
     6933      else
     6934      {
     6935        iv_M = MivMatrixOrderRefine(curr_weight,target_M);
     6936      }
     6937#ifdef TIME_TEST
     6938      to = clock();
     6939#endif
     6940      next_weight = MWalkRandomNextWeight(G, iv_M, target_weight, weight_rad, op_deg);
     6941#ifdef TIME_TEST
     6942      tnw = tnw + clock() - to;
     6943#endif
     6944      idDelete(&Gomega);
     6945#ifdef TIME_TEST
     6946      to = clock();
     6947#endif
     6948      Gomega = MwalkInitialForm(G, next_weight);
     6949#ifdef TIME_TEST
     6950      tif = tif + clock()-to; //time for computing initial form ideal
     6951#endif
     6952  Print("delete\n");
     6953      delete iv_M;
     6954    }
     6955
     6956/*
     6957    to=clock();
     6958    next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     6959    if(polylength > 0)
     6960    {
     6961      if(printout > 2)
     6962      {
     6963        Print("\n //**Mprwalk: there is a polynomial in Gomega with at least 3 monomials, low-dimensional facet of the cone.\n");
     6964      }
     6965      delete next_weight;
     6966      next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, op_deg);
     6967    }
     6968    tnw=tnw+clock()-to;
     6969*/
     6970#ifdef PRINT_VECTORS
     6971    if(printout > 0)
     6972    {
     6973      MivString(curr_weight, target_weight, next_weight);
     6974    }
     6975#endif
     6976
     6977    if(Overflow_Error == TRUE)
     6978    {
     6979      ntwC = 0;
     6980      //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     6981      //idElements(G, "G");
     6982      delete next_weight;
     6983      goto FINISH_160302;
     6984    }
     6985    if(MivComp(next_weight, ivNull) == 1){
     6986      newRing = currRing;
     6987      delete next_weight;
     6988      //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     6989      break;
     6990    }
     6991    if(MivComp(next_weight, target_weight) == 1)
     6992      endwalks = TRUE;
     6993
     6994    for(i=nV-1; i>=0; i--)
     6995      (*curr_weight)[i] = (*next_weight)[i];
     6996
     6997    delete next_weight;
     6998  }// end of while-loop
     6999
     7000  if(tp_deg != 1)
     7001  {
     7002    FINISH_160302:
     7003    if(target_M->length() == nV)
     7004    {
     7005      if(MivSame(orig_target, exivlp) == 1)
     7006        if (rParameter(currRing) != NULL)
     7007          DefRingParlp();
     7008        else
     7009          VMrDefaultlp();
     7010      else
     7011        if (rParameter(currRing) != NULL)
     7012          DefRingPar(orig_target);
     7013        else
     7014          rChangeCurrRing(VMrDefault(orig_target));
     7015    }
     7016    else
     7017    {
     7018      rChangeCurrRing(VMatrDefault(target_M));
     7019    }
     7020    TargetRing=currRing;
     7021    F1 = idrMoveR(G, newRing,currRing);
     7022
     7023    // check whether the pertubed target vector stays in the correct cone
     7024    if(ntwC != 0)
     7025    {
     7026      ntestw = test_w_in_ConeCC(F1, pert_target_vector);
     7027    }
     7028    if(ntestw != 1 || ntwC == 0)
     7029    {
     7030      if(ntestw != 1 && printout > 2)
     7031      {
     7032#ifdef PRINT_VECTORS
     7033        ivString(pert_target_vector, "tau");
     7034#endif
     7035        PrintS("\n// **Mprwalk: perturbed target vector doesn't stay in cone.");
     7036        Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
     7037        //idElements(F1, "G");
     7038      }
     7039      // LastGB is "better" than the kStd subroutine
     7040#ifdef TIME_TEST
     7041      to=clock();
     7042#endif
     7043      ideal eF1;
     7044      if(nP == 0 || tp_deg == 1 || MivSame(orig_target, exivlp) != 1 || target_M->length() != nV)
     7045      {
     7046        if(printout > 2)
     7047        {
     7048          PrintS("\n// ** Mprwalk: Call \"std\" to compute a Groebner basis.\n");
     7049        }
     7050        eF1 = MstdCC(F1);
     7051        idDelete(&F1);
     7052      }
     7053      else
     7054      {
     7055        if(printout > 2)
     7056        {
     7057          PrintS("\n// **Mprwalk: Call \"LastGB\" to compute a Groebner basis.\n");
     7058        }
     7059        rChangeCurrRing(newRing);
     7060        ideal F2 = idrMoveR(F1, TargetRing,currRing);
     7061        eF1 = LastGB(F2, curr_weight, tp_deg-1);
     7062        F2=NULL;
     7063      }
     7064#ifdef TIME_TEST
     7065      xtextra=clock()-to;
     7066#endif
     7067      ring exTargetRing = currRing;
     7068
     7069      rChangeCurrRing(XXRing);
     7070      Eresult = idrMoveR(eF1, exTargetRing,currRing);
     7071    }
     7072    else
     7073    {
     7074      rChangeCurrRing(XXRing);
     7075      Eresult = idrMoveR(F1, TargetRing,currRing);
     7076    }
     7077  }
     7078  else
     7079  {
     7080    rChangeCurrRing(XXRing);
     7081    Eresult = idrMoveR(G, newRing,currRing);
     7082  }
     7083  si_opt_1 = save1; //set original options, e. g. option(RedSB)
     7084  delete ivNull;
     7085  if(tp_deg != 1)
     7086    delete target_weight;
     7087
     7088  if(op_deg != 1 )
     7089    delete curr_weight;
     7090
     7091  delete exivlp;
     7092  delete last_omega;
     7093
     7094#ifdef TIME_TEST
     7095  TimeStringFractal(tinput, tostd, tif+xtif, tstd+xtstd,0, tlift+xtlift, tred+xtred,
     7096             tnw+xtnw);
     7097
     7098  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
     7099  //Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep,  Overflow_Error);
     7100#endif
     7101  Print("\n//** Mprwalk: Perturbation Walk took %d steps.\n", nstep);
    60877102  return(Eresult);
    60887103}
     
    61107125 * Perturb the start weight vector at the top level, i.e. nlev = 1     *
    61117126 ***********************************************************************/
    6112 static ideal rec_fractal_call(ideal G, int nlev, intvec* omtmp)
     7127static ideal rec_fractal_call(ideal G, int nlev, intvec* ivtarget,
     7128             int reduction, int printout)
    61137129{
    61147130  Overflow_Error =  FALSE;
    6115   //Print("\n\n// Entering the %d-th recursion:", nlev);
    6116 
     7131  if(printout >0)
     7132  {
     7133    Print("\n\n// Entering the %d-th recursion:", nlev);
     7134  }
    61177135  int i, nV = currRing->N;
    61187136  ring new_ring, testring;
    61197137  //ring extoRing;
    6120   ideal Gomega, Gomega1, Gomega2, F, F1, Gresult, Gresult1, G1, Gt;
     7138  ideal Gomega, Gomega1, Gomega2, FF, F, F1, Gresult, Gresult1, G1, Gt;
    61217139  int nwalks = 0;
    61227140  intvec* Mwlp;
     
    61247142  intvec* hilb_func;
    61257143#endif
    6126 //  intvec* extXtau;
     7144  //intvec* extXtau;
    61277145  intvec* next_vect;
    61287146  intvec* omega2 = new intvec(nV);
    6129   intvec* altomega = new intvec(nV);
    6130 
     7147  intvec* omtmp = new intvec(nV);
     7148  //intvec* altomega = new intvec(nV);
     7149
     7150  for(i = nV -1; i>0; i--)
     7151  {
     7152    (*omtmp)[i] = (*ivtarget)[i];
     7153  }
    61317154  //BOOLEAN isnewtarget = FALSE;
    61327155
     
    61687191    nwalks ++;
    61697192    NEXT_VECTOR_FRACTAL:
     7193#ifdef TIME_TEST
    61707194    to=clock();
    6171     /* determine the next border */
     7195#endif
     7196    // determine the next border
    61727197    next_vect = MkInterRedNextWeight(omega,omega2,G);
     7198#ifdef TIME_TEST
    61737199    xtnw=xtnw+clock()-to;
    6174 #ifdef PRINT_VECTORS
    6175     MivString(omega, omega2, next_vect);
    61767200#endif
    61777201    oRing = currRing;
    61787202
    6179     /* We only perturb the current target vector at the recursion  level 1 */
     7203    // We only perturb the current target vector at the recursion level 1
    61807204    if(Xngleich == 0 && nlev == 1) //(ngleich == 0) important, e.g. ex2, ex3
    6181       if (MivComp(next_vect, omega2) != 1)
    6182       {
    6183         /* to dispense with taking initial (and lifting/interreducing
    6184            after the call of recursion */
    6185         //Print("\n\n// ** Perturb the both vectors with degree %d with",nlev);
    6186         //idElements(G, "G");
     7205      if (MivComp(next_vect, omega2) == 1)
     7206      {
     7207        // to dispense with taking initial (and lifting/interreducing
     7208        // after the call of recursion
     7209        if(printout > 0)
     7210        {
     7211          Print("\n//** rec_fractal_call: Perturb the both vectors with degree %d.",nlev);
     7212          //idElements(G, "G");
     7213        }
    61877214
    61887215        Xngleich = 1;
    61897216        nlev +=1;
    61907217
    6191         if (rParameter(currRing) != NULL)
    6192           DefRingPar(omtmp);
     7218        if(ivtarget->length() == nV)
     7219        {
     7220          if (rParameter(currRing) != NULL)
     7221            DefRingPar(omtmp);
     7222          else
     7223            rChangeCurrRing(VMrDefault(omtmp));
     7224        }
    61937225        else
    6194           rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung3
    6195 
     7226        {
     7227          rChangeCurrRing(VMatrDefault(ivtarget));
     7228        }
    61967229        testring = currRing;
    61977230        Gt = idrMoveR(G, oRing,currRing);
    61987231
    6199         /* perturb the original target vector w.r.t. the current GB */
    6200         delete Xtau;
    6201         Xtau = NewVectorlp(Gt);
     7232        // perturb the original target vector w.r.t. the current GB
     7233        if(ivtarget->length() == nV)
     7234        {
     7235          delete Xtau;
     7236          Xtau = NewVectorlp(Gt);
     7237        }
     7238        else
     7239        {
     7240          delete Xtau;
     7241          Xtau = Mfpertvector(Gt,ivtarget);
     7242        }
    62027243
    62037244        rChangeCurrRing(oRing);
    62047245        G = idrMoveR(Gt, testring,currRing);
    62057246
    6206         /* perturb the current vector w.r.t. the current GB */
     7247        // perturb the current vector w.r.t. the current GB
    62077248        Mwlp = MivWeightOrderlp(omega);
    62087249        Xsigma = Mfpertvector(G, Mwlp);
     
    62157256
    62167257        delete next_vect;
     7258#ifdef TIME_TEST
    62177259        to=clock();
    6218 
    6219         /* to avoid the value of Overflow_Error that occur in Mfpertvector*/
     7260#endif
     7261        // to avoid the value of Overflow_Error that occur in Mfpertvector
    62207262        Overflow_Error = FALSE;
    6221 
    62227263        next_vect = MkInterRedNextWeight(omega,omega2,G);
     7264#ifdef TIME_TEST
    62237265        xtnw=xtnw+clock()-to;
     7266#endif
     7267      }// end of (if MivComp(next_vect, omega2) == 1)
    62247268
    62257269#ifdef PRINT_VECTORS
     7270      if(printout > 0)
     7271      {
    62267272        MivString(omega, omega2, next_vect);
    6227 #endif
    6228       }
    6229 
    6230 
    6231     /* check whether the the computed vector is in the correct cone */
    6232     /* If no, the reduced GB of an omega-homogeneous ideal will be
    6233        computed by Buchberger algorithm and stop this recursion step*/
    6234     //if(test_w_in_ConeCC(G, next_vect) != 1) //e.g. Example s7, cyc6
    6235     if(Overflow_Error == TRUE)
     7273      }
     7274#endif
     7275
     7276    // check whether the the computed vector is in the correct cone.
     7277    // If no, compute the reduced Groebner basis of an omega-homogeneous
     7278    // ideal with Buchberger's algorithm and stop this recursion step
     7279    if(Overflow_Error == TRUE || test_w_in_ConeCC(G, next_vect) != 1)  //e.g. Example s7, cyc6
    62367280    {
    62377281      delete next_vect;
    6238       if (rParameter(currRing) != NULL)
    6239       {
    6240         DefRingPar(omtmp);
     7282      if(ivtarget->length() == nV)
     7283      {
     7284        if (rParameter(currRing) != NULL)
     7285          DefRingPar(omtmp);
     7286        else
     7287          rChangeCurrRing(VMrDefault(omtmp));
    62417288      }
    62427289      else
    62437290      {
    6244         rChangeCurrRing(VMrDefault1(omtmp)); // Aenderung4
     7291        rChangeCurrRing(VMatrDefault(ivtarget));
    62457292      }
    62467293#ifdef TEST_OVERFLOW
     
    62487295      Gt = NULL; return(Gt);
    62497296#endif
    6250 
    6251       //Print("\n\n// apply BB's alg. in ring r = %s;", rString(currRing));
     7297      if(printout > 0)
     7298      {
     7299        Print("\n//** rec_fractal_call: Applying Buchberger's algorithm in ring r = %s;",
     7300              rString(currRing));
     7301      }
     7302#ifdef TIME_TEST
    62527303      to=clock();
     7304#endif
    62537305      Gt = idrMoveR(G, oRing,currRing);
    62547306      G1 = MstdCC(Gt);
     7307#ifdef TIME_TEST