source: git/Singular/LIB/rwalk.lib @ fde66a9

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