Changeset a14482 in git


Ignore:
Timestamp:
Feb 26, 2015, 6:55:30 PM (9 years ago)
Author:
Stephan Oberfranz <oberfran@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
e57a75c6d0050e3db7e1a87294a311d4784df43c
Parents:
eca8d9cc9b3584a2f5741c75f69099751c4cbe8f
Message:
update
Location:
Singular
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/modwalk.lib

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

    reca8d9 ra14482  
    11061106  if(pdeg > nV || pdeg <= 0)
    11071107  {
    1108     WerrorS("//** The perturbed degree is wrong!!");
     1108    WerrorS("//**MPertVectors: The perturbed degree is wrong!!");
    11091109    return v_null;
    11101110  }
     
    11161116  }
    11171117  mpz_t *pert_vector = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
    1118   //mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
    11191118
    11201119  for(i=0; i<nV; i++)
     
    11231122   // mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]);
    11241123  }
    1125   // Calculate max1 = Max(A2)+Max(A3)+...+Max(Apdeg),
     1124  // Compute max1 = Max(A2)+Max(A3)+...+Max(Apdeg),
    11261125  // where the Ai are the i-te rows of the matrix target_ord.
    11271126  int ntemp, maxAi, maxA=0;
     
    11481147  }
    11491148
    1150   // Calculate inveps = 1/eps, where 1/eps > totaldeg(p)*max1 for all p in G.
     1149  // Compute inveps = 1/eps, where 1/eps > totaldeg(p)*max1 for all p in G.
    11511150
    11521151  intvec* ivUnit = Mivdp(nV);
     
    11801179  }
    11811180#else
    1182   // PrintS("\n// the \"big\" inverse epsilon: ");
     1181  PrintS("\n //**MPertVectors: the \"big\" inverse epsilon:");
    11831182  mpz_out_str(stdout, 10, inveps);
    11841183#endif
     
    12341233  if(j > nV - 1)
    12351234  {
    1236     // Print("\n//  MPertVectors: geaenderter vector gleich Null! \n");
     1235    //perturbed vector equals zero
    12371236    delete pert_vector1;
    12381237    goto CHECK_OVERFLOW;
    12391238  }
    12401239
    1241 // check that the perturbed weight vector lies in the Groebner cone
     1240  // check that the perturbed weight vector lies in the Groebner cone
    12421241  if(test_w_in_ConeCC(G,pert_vector1) != 0)
    12431242  {
    1244     // Print("\n//  MPertVectors: geaenderter vector liegt in Groebnerkegel! \n");
    12451243    for(i=0; i<nV; i++)
    12461244    {
     
    12481246    }
    12491247  }
    1250   else
    1251   {
    1252     //Print("\n// MpertVectors: geaenderter vector liegt nicht in Groebnerkegel! \n");
    1253   }
     1248
    12541249  delete pert_vector1;
    12551250
     
    12571252  intvec* result = new intvec(nV);
    12581253
    1259   /* 2147483647 is max. integer representation in SINGULAR */
     1254  // 2147483647 is max. integer representation in SINGULAR
    12601255  mpz_t sing_int;
    12611256  mpz_init_set_ui(sing_int,  2147483647);
     
    16441639  {
    16451640    mpz_divexact(pert_vector[i], pert_vector[i], ztmp);
    1646     (* result)[i] = mpz_get_si(pert_vector[i]);
    1647   }
    1648 
     1641    (* result1)[i] = mpz_get_si(pert_vector[i]);
     1642  }
    16491643  j = 0;
    1650   for(i=0; i<nV; i++)
    1651   {
    1652     (* result1)[i] = mpz_get_si(pert_vector[i]);
    1653     (* result1)[i] = 0.1*(* result1)[i];
    1654     (* result1)[i] = floor((* result1)[i] + 0.5);
    1655     if((* result1)[i] == 0)
    1656     {
    1657       j++;
    1658     }
    1659   }
    1660   if(j > nV - 1)
    1661   {
    1662     // Print("\n//  MfPertwalk: geaenderter vector gleich Null! \n");
    1663     delete result1;
    1664     goto CHECK_OVERFLOW;
    1665   }
    1666 
    1667 // check that the perturbed weight vector lies in the Groebner cone
    1668   if(test_w_in_ConeCC(G,result1) != 0)
    1669   {
    1670     // Print("\n//  MfPertwalk: geaenderter vector liegt in Groebnerkegel! \n");
    1671     delete result;
    1672     result = result1;
     1644  while(test_w_in_ConeCC(G,result1) && j<nV)
     1645  {
     1646    j = 0;
    16731647    for(i=0; i<nV; i++)
    16741648    {
     1649      (* result)[i] = (* result1)[i];
    16751650      mpz_set_si(pert_vector[i], (*result1)[i]);
    1676     }
    1677   }
    1678   else
    1679   {
    1680     delete result1;
    1681     // Print("\n// Mfpertwalk: geaenderter vector liegt nicht in Groebnerkegel! \n");
    1682   }
     1651      (* result1)[i] = floor(0.1*(mpz_get_si(pert_vector[i])) + 0.5);
     1652      if((* result1)[i] == 0)
     1653      {
     1654        j++;
     1655      }
     1656    }
     1657  }
     1658  delete result1;
    16831659
    16841660  CHECK_OVERFLOW:
     
    43434319  assume(currRing != NULL && curr_weight != NULL &&
    43444320         target_weight != NULL && G->m[0] != NULL);
    4345 
    4346   int i,weight_norm,nV = currRing->N;
     4321  //PrintS("\n //**MWalkRandomNextWeight: Anfang ok!\n");
     4322  int i,k,nV = currRing->N;
     4323  long weight_norm;
    43474324  intvec* next_weight2;
    4348   intvec* next_weight22 = new intvec(nV);
     4325  //intvec* next_weight22 = new intvec(nV);
    43494326  intvec* result = new intvec(nV);
     4327  ideal G_test;
     4328  ideal G_test2;
     4329  BOOLEAN random = FALSE;
    43504330
    43514331  intvec* next_weight1 =MkInterRedNextWeight(curr_weight,target_weight,G);
    43524332  //compute a random next weight vector "next_weight2"
    4353   while(1)
    4354   {
     4333  k = 1;
     4334  while(k<4)
     4335  {
     4336    k++;
    43554337    weight_norm = 0;
     4338    intvec* next_weight22 = new intvec(nV);
    43564339    while(weight_norm == 0)
    43574340    {
    4358 
     4341      //PrintS("\nWhile WeightNorm\n");
    43594342      for(i=0; i<nV; i++)
    43604343      {
    4361         (*next_weight22)[i] = rand() % 60000 - 30000;
     4344        (*next_weight22)[i] = rand() % 60000 ;
    43624345        weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
    43634346      }
     4347      //Print("\n// weight_norm vor Wurzel = %d\n", weight_norm);
    43644348      weight_norm = 1 + floor(sqrt(weight_norm));
    4365     }
    4366 
     4349     
     4350    }
     4351//Print("\n// weight_norm nach Wurzel = %d\n", weight_norm);
    43674352    for(i=0; i<nV; i++)
    43684353    {
    43694354      if((*next_weight22)[i] < 0)
    43704355      {
    4371         (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
     4356        (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor((weight_rad)*(*next_weight22)[i]/weight_norm);
    43724357      }
    43734358      else
    43744359      {
    4375         (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
     4360        (*next_weight22)[i] = (*curr_weight)[i] + floor((weight_rad)*(*next_weight22)[i]/weight_norm);
    43764361      }
    43774362    }
     
    43794364    if(test_w_in_ConeCC(G, next_weight22) == 1)
    43804365    {
     4366      //PrintS("\n //** MWalkRandomNextWeight: test ob in Kegel.\n");
    43814367      next_weight2 = MkInterRedNextWeight(next_weight22,target_weight,G);
    43824368      if(MivAbsMax(next_weight2)>1147483647)
     
    43954381        }
    43964382      }
    4397       delete next_weight22;
     4383      random = TRUE;
    43984384      break;
    43994385    }
    4400   }
    4401  
     4386    delete next_weight22;
     4387  }
     4388  //PrintS("\n //**MWalkRandomNextWeight: Ende while-Schleife!\n");
     4389
    44024390  // compute "usual" next weight vector
    44034391  intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
    4404   ideal G_test = MwalkInitialForm(G, next_weight);
    4405   ideal G_test2 = MwalkInitialForm(G, next_weight2);
    4406 
     4392  G_test = MwalkInitialForm(G, next_weight);
     4393  if(random == TRUE)
     4394  {
     4395    G_test2 = MwalkInitialForm(G, next_weight2);
     4396  }
    44074397  // compare next weights
    44084398  if(Overflow_Error == FALSE)
    44094399  {
    44104400    ideal G_test1 = MwalkInitialForm(G, next_weight1);
    4411     if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))//if(IDELEMS(G_test1) < IDELEMS(G_test))
    4412     {
    4413       if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test1)) //if(IDELEMS(G_test2) < IDELEMS(G_test1))
    4414       {
    4415         // |G_test2| < |G_test1| < |G_test|
     4401    if(G_test1->m[0] != NULL && maxlengthpoly(G_test1) < maxlengthpoly(G_test))
     4402    {
     4403      if(random == TRUE &&
     4404         G_test2->m[0] != NULL &&
     4405         maxlengthpoly(G_test2) < maxlengthpoly(G_test1))
     4406      {
    44164407        for(i=0; i<nV; i++)
    44174408        {
     
    44214412      else
    44224413      {
    4423         // |G_test1| < |G_test|, |G_test1| <= |G_test2|
    44244414        for(i=0; i<nV; i++)
    44254415        {
     
    44304420    else
    44314421    {
    4432       if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))//if(IDELEMS(G_test2) < IDELEMS(G_test)) // |G_test2| < |G_test| <= |G_test1|
     4422      if(random == TRUE &&
     4423         G_test2->m[0] != NULL &&
     4424         maxlengthpoly(G_test2) < maxlengthpoly(G_test))
    44334425      {
    44344426        for(i=0; i<nV; i++)
     
    44394431      else
    44404432      {
    4441         // |G_test| < |G_test1|, |G_test| <= |G_test2|
    44424433        for(i=0; i<nV; i++)
    44434434        {
     
    44514442  {
    44524443    Overflow_Error = FALSE;
    4453     if(G_test2->m[0] != NULL && maxlengthpoly(G_test2) < maxlengthpoly(G_test))//if(IDELEMS(G_test2) < IDELEMS(G_test))
     4444    if(random == TRUE &&
     4445       G_test2->m[0] != NULL &&
     4446       maxlengthpoly(G_test2) < maxlengthpoly(G_test))
    44544447    {
    44554448      for(i=1; i<nV; i++)
     
    44664459    }
    44674460  }
    4468   PrintS("\n MWalkRandomNextWeight: Ende ok!\n");
     4461  //PrintS("\n MWalkRandomNextWeight: Ende ok!\n");
    44694462  idDelete(&G_test);
    4470   idDelete(&G_test2);
     4463  if(random == TRUE)
     4464  {
     4465    idDelete(&G_test2);
     4466  }
    44714467  if(test_w_in_ConeCC(G, result) == 1)
    44724468  {
    4473     delete next_weight2;
     4469    if(random == TRUE)
     4470    {
     4471      delete next_weight2;
     4472    }
    44744473    delete next_weight;
    44754474    delete next_weight1;
     
    44794478  {
    44804479    delete result;
    4481     delete next_weight2;
     4480    if(random == TRUE)
     4481    {
     4482      delete next_weight2;
     4483    }
    44824484    delete next_weight1;
    44834485    return next_weight;
     
    60296031    to=clock();
    60306032    // compute a next weight vector
    6031     next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
     6033    next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);//MkInterRedNextWeight(curr_weight,target_weight, G);
    60326034    tnw=tnw+clock()-to;
    60336035//#ifdef PRINT_VECTORS
     
    70957097      delete next_vect;
    70967098      next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,nlev);
    7097       if(isNegNolVector(next_vect)==1)
     7099      if(isNegNolVector(next_vect)==1 || MivSame(omega,next_vect) == 1)
    70987100      {
    70997101        delete next_vect;
     
    71807182          delete next_vect;
    71817183          next_vect = MWalkRandomNextWeight(G,omega,omega2,weight_rad,nlev);
    7182           if(isNegNolVector(next_vect)==1)
     7184          if(isNegNolVector(next_vect)==1 || MivSame(omega,next_vect) == 1)
    71837185          {
    71847186            delete next_vect;
     
    72397241        Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n",
    72407242              nlev, nwalks);
    7241         //Print(" ** Overflow_Error? (%d)", Overflow_Error);
     7243      /*
     7244        Print(" ** Overflow_Error? (%d)", Overflow_Error);
     7245        idString(G1,"//** rec_r_fractal_call: G1");
     7246      */
    72427247      }
    72437248      nnflow ++;
     
    72797284          Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n",
    72807285                nlev, nwalks);
    7281           //Print(" ** Overflow_Error? (%d)", Overflow_Error);
     7286        /*
     7287          Print(" ** Overflow_Error? (%d)", Overflow_Error);
     7288          idString(Gt,"//** rec_r_fractal_call: Gt");
     7289        */
    72827290        }
    72837291        return (Gt);
     
    73827390          Print("\n//** rec_r_fractal_call: Leaving the %d-th recursion with %d steps.\n",
    73837391                nlev,nwalks);
    7384           //Print(" ** Overflow_Error? (%d)", Overflow_Error);
     7392         /*
     7393          Print(" ** Overflow_Error? (%d)", Overflow_Error);
     7394          idString(G,"//** rec_r_fractal_call: G");
     7395         */
    73857396        }
    73867397        if(Overflow_Error == TRUE)
Note: See TracChangeset for help on using the changeset viewer.