# source:git/Singular/LIB/rwalk.lib@75f460

spielwiese
Last change on this file since 75f460 was 75f460, checked in by Hans Schoenemann <hannes@…>, 9 years ago
format
• Property mode set to `100644`
File size: 8.9 KB
Line
1/////////////////////////////////////////////////
2version="version rwalk.lib 4.0.0.0 Jun_2014 ";
3category="Commutative Algebra";
4
5info="
6LIBRARY: rwalk.lib   Groebner Walk Conversion Algorithms
7AUTHOR: Stephan Oberfranz
8
9PROCEDURES:
10rwalk(ideal,int,int[,intvec,intvec]);   standard basis of ideal via Random Walk algorithm
11rwalk(ideal,int[,intvec,intvec]);       standard basis of ideal via Random Perturbation Walk algorithm
12frwalk(ideal,int[,intvec,intvec]);      standard basis of ideal via Random Fractal Walk algorithm
13";
14
15/***********************************
16 * Argument string for Random Walk *
17 ***********************************/
18static proc OrderStringalp_NP(string Wpal,list #)
19{
20  int n= nvars(basering);
21  string order_str = "dp";
22
23  int nP = 1;
24
25  //Default: if size(#)=0, the Groebnerwalk algorithm and its developments compute
26  //a Groebner basis from "dp" to "lp"
27
28  intvec curr_weight = system("Mivdp",n); //define (1,1,...,1)
29  intvec target_weight = system("Mivlp",n); //define (1,0,...,0)
30
31  if(size(#) != 0)
32  {
33    if(size(#) == 1)
34    {
35      if(typeof(#[1]) == "intvec") {
36        curr_weight = #[1];
37
38        if(Wpal == "al"){
39          order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
40        }
41        if(Wpal == "M"){
42          order_str = "(M("+string(#[1])+"),C)";
43        }
44        else {
45          order_str = "(Wp("+string(#[1])+"),C)";
46        }
47      }
48      else {
49        if(typeof(#[1]) == "int"){
50          nP = #[1];
51        }
52        else {
53          print("// ** the input must be \"(ideal, int)\" or ");
54          print("// **                   \"(ideal, intvec)\"");
55          print("// ** a lex. GB will be computed from \"dp\" to \"lp\"");
56        }
57      }
58    }
59    else
60    {
61     if(size(#) == 2)
62     {
63       if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int"){
64         curr_weight = #[1];
65
66         if(Wpal == "al"){
67           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
68         }
69         if(Wpal == "M"){
70          order_str = "(M("+string(#[1])+"),C)";
71         }
72         else {
73           order_str = "(Wp("+string(#[1])+"),C)";
74         }
75       }
76       else{
77         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec"){
78           curr_weight = #[1];
79           target_weight = #[2];
80
81           if(Wpal == "al"){
82             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
83           }
84           if(Wpal == "M"){
85             order_str = "(M("+string(#[1])+"),C)";
86           }
87           else {
88             order_str = "(Wp("+string(#[1])+"),C)";
89           //  order_str = "(a("+string(#[1])+"),C)";
90           }
91         }
92         else{
93           print("// ** the input  must be \"(ideal,intvec,int)\" or ");
94           print("// **                    \"(ideal,intvec,intvec)\"");
95           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
96         }
97       }
98     }
99     else {
100       if(size(#) == 3) {
101         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and
102            typeof(#[3]) == "int")
103         {
104           curr_weight = #[1];
105           target_weight = #[2];
106           nP = #[3];
107           if(Wpal == "al"){
108             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
109           }
110           if(Wpal == "M"){
111             order_str = "(M("+string(#[1])+"),C)";
112           }
113           else {
114             order_str = "(Wp("+string(#[1])+"),C)";
115           }
116         }
117         else{
118           print("// ** the input must be \"(ideal,intvec,intvec,int)\"");
119           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
120
121         }
122       }
123       else{
124         print("// ** The given input is wrong");
125         print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
126       }
127     }
128    }
129  }
130
131  list result;
132  result[1] = nP;
133  result[2] = order_str;
134  result[3] = curr_weight;
135  result[4] = target_weight;
136
137  return(result);
138}
139
140/****************
141 * Random Walk  *
142 ****************/
143proc rwalk(ideal Go, int radius, int pert_deg, list #)
145         if size(#)>0 then rwalk(ideal i, int radius, intvec v, intvec w);
146TYPE:    ideal
147PURPOSE: compute the standard basis of the ideal, calculated via
148         the Random walk algorithm  from the ordering
149         \"(a(v),lp)\", \"dp\", \"Dp\" or \"M\"
150         to the ordering  \"(a(w),lp)\", \"(a(1,0,...,0),lp)\" or \"M\".
152KEYWORDS: Groebner walk
153EXAMPLE: example rwalk; shows an example"
154{
155//--------------------  Initialize parameters  ------------------------
156int n= nvars(basering);
157list OSCTW = OrderStringalp_NP("al",#);
158if(size(#)>1)
159  {
160  if(size(#[2]) == n*n)
161    {
162    OSCTW= OrderStringalp_NP("M", #);
163    }
164  }
165else
166  {
167  OSCTW= OrderStringalp_NP("al", #);
168  }
169string ord_str = OSCTW[2];
170intvec curr_weight = OSCTW[3]; // original weight vector
171intvec target_weight = OSCTW[4]; // target weight vector
172kill OSCTW;
173
174//--------------------  Initialize parameters  ------------------------
175def xR = basering;
176execute("ring ostR = "+charstr(xR)+",("+varstr(xR)+"),"+ord_str+";");
177def old_ring = basering;
178
179ideal G = fetch(xR, Go);
180G = system("Mrwalk", G, curr_weight, target_weight, radius, pert_deg, basering);
181
182setring xR;
183kill Go;
184
185keepring basering;
186ideal result = fetch(old_ring, G);
187attrib(result,"isSB",1);
188return (result);
189}
190example
191{
192  "EXAMPLE:"; echo = 2;
193  // compute a Groebner basis of I w.r.t. lp.
194  ring r = 32003,(z,y,x), lp;
195  ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
197  int perturb_deg = 2;
199}
200
201/*****************************************
202 * Perturbation Walk with random element *
203 *****************************************/
204proc prwalk(ideal Go, int radius, int o_pert_deg, int t_pert_deg, list #)
206         if size(#)>0 then rwalk(ideal i, int radius, intvec v, intvec w);
207TYPE:    ideal
208PURPOSE: compute the standard basis of the ideal, calculated via
209         the Random Perturbation Walk algorithm  from the ordering
210         \"(a(v),lp)\", \"dp\", \"Dp\" or \"M\"
211         to the ordering  \"(a(w),lp)\", \"(a(1,0,...,0),lp)\" or \"M\".
213KEYWORDS: Groebner walk
214EXAMPLE: example rwalk; shows an example"
215{
216//--------------------  Initialize parameters  ------------------------
217list OSCTW = OrderStringalp_NP("al", #);
218if(size(#)>1)
219  {
220  if(size(#[2]) == n*n)
221    {
222    OSCTW= OrderStringalp_NP("M", #);
223    }
224  }
225else
226  {
227  OSCTW= OrderStringalp_NP("al", #);
228  }
229string ord_str = OSCTW[2];
230intvec curr_weight = OSCTW[3]; // original weight vector
231intvec target_weight = OSCTW[4]; // target weight vector
232kill OSCTW;
233
234//--------------------  Initialize parameters  ------------------------
235def xR = basering;
236execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
237def old_ring = basering;
238
239ideal G = fetch(xR, Go);
240G = system("Mprwalk", G, curr_weight, target_weight, radius, o_pert_deg, t_pert_deg, basering);
241
242setring xR;
243kill Go;
244
245keepring basering;
246ideal result = fetch(old_ring, G);
247attrib(result,"isSB",1);
248return (result);
249}
250example
251{
252  "EXAMPLE:"; echo = 2;
253  // compute a Groebner basis of I w.r.t. lp.
254  ring r = 32003,(z,y,x), lp;
255  ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
257  int o_perturb_deg = 2;
258  int t_perturb_deg = 2;
260}
261
262/************************************
263 * Fractal Walk with random element *
264 ************************************/
265proc frandwalk(ideal Go, int radius, list #)
267         frwalk(ideal i, int radius, intvec v, intvec w);
268TYPE:    ideal
269PURPOSE: compute the standard basis of the ideal, calculated via
270         the Random Fractal walk algorithm  from the ordering
271         \"(a(v),lp)\", \"dp\", \"Dp\" or \"M\"
272         to the ordering  \"(a(w),lp)\", \"(a(1,0,...,0),lp)\" or \"M\".
274KEYWORDS: The fractal walk algorithm
275EXAMPLE: example frwalk; shows an example"
276{
277   // we use ring with ordering (a(...),lp,C)
278   list OSCTW    = OrderStringalp_NP("al", #);
279   if(size(#)>1)
280   {
281     if(size(#[2]) == n*n)
282     {
283       OSCTW= OrderStringalp_NP("M", #);
284     }
285   }
286  else
287  {
288    OSCTW= OrderStringalp_NP("al", #);
289  }
290   string ord_str =   OSCTW[2];
291   intvec curr_weight   =   OSCTW[3]; /* current weight vector */
292   intvec target_weight =   OSCTW[4]; /* target weight vector */
293   kill OSCTW;
294   def xR = basering;
295
296   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
297   def old_ring = basering;
298   //print("//** help ring = " + string(basering));
299   ideal G = fetch(xR, Go);
300   int pert_deg = 2;
301   G = system("Mfrwalk", G, curr_weight, target_weight, radius);
302
303   setring xR;
304   //kill Go;
305
306   keepring basering;
307   ideal result = fetch(old_ring, G);
308   attrib(result,"isSB",1);
309   return (result);
310}
311example
312{
313    "EXAMPLE:"; echo = 2;
314    ring r = 0,(z,y,x), lp;
315    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
316    frandwalk(I,2);
317}
Note: See TracBrowser for help on using the repository browser.