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

spielwiese
Last change on this file since ffd4a9 was ffd4a9, checked in by Stephan Oberfranz <oberfran@…>, 10 years ago
Groebner Walk, Sagbi Walk
  • Property mode set to 100755
File size: 9.7 KB
Line 
1<<<<<<< HEAD
2=======
3//
4>>>>>>> 92644b759d66f085c842e4284d78c2e203291b67
5version="$Id$";
6category="Commutative Algebra";
7
8info="
9LIBRARY: rwalk.lib   Groebner Walk Conversion Algorithms
10AUTHOR: Stephan Oberfranz
11
12PROCEDURES:
13 rwalk(ideal[,intvec]);   standard basis of ideal via randomwalk algorithm
14";
15
16/***********************************
17 * Argument string for Random Walk *
18 ***********************************/
19proc OrderStringalp_NP(string Wpal,list #)
20{
21  int n= nvars(basering);
22  string order_str = "dp";
23
24  int nP = 1;
25
26  //Default: if size(#)=0, the Groebnerwalk algorithm and its developments compute 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 #)
144"SYNTAX: rwalk(ideal i, int radius);
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\" or \"Dp\"
150         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
151SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1, awalk2
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;
196  int radius = 1;
197  int perturb_deg = 2;
198  rwalk(I,radius,perturb_deg);
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 #)
205"SYNTAX: rwalk(ideal i, int radius);
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 walk algorithm  from the ordering
210         \"(a(v),lp)\", \"dp\" or \"Dp\"
211         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
212SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1, awalk2
213KEYWORDS: Groebner walk
214EXAMPLE: example rwalk; shows an example"
215{
216//--------------------  Initialize parameters  ------------------------
217list OSCTW = OrderStringalp_NP("al", #);
218string ord_str = OSCTW[2];
219intvec curr_weight = OSCTW[3]; // original weight vector
220intvec target_weight = OSCTW[4]; // target weight vector
221kill OSCTW;
222
223//--------------------  Initialize parameters  ------------------------
224def xR = basering;
225execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
226def old_ring = basering;
227
228ideal G = fetch(xR, Go);
229G = system("Mprwalk", G, curr_weight, target_weight, radius, o_pert_deg, t_pert_deg, basering);
230
231setring xR;
232kill Go;
233
234keepring basering;
235ideal result = fetch(old_ring, G);
236attrib(result,"isSB",1);
237return (result);
238}
239example
240{
241  "EXAMPLE:"; echo = 2;
242  // compute a Groebner basis of I w.r.t. lp.
243  ring r = 32003,(z,y,x), lp;
244  ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
245  int radius = 1;
246  int o_perturb_deg = 2;
247  int t_perturb_deg = 2;
248  prwalk(I,radius,o_perturb_deg,t_perturb_deg);
249}
250
251/************************************
252 * Fractal Walk with random element *
253 ************************************/
254proc frandwalk(ideal Go, int radius, list #)
255"SYNTAX: frwalk(ideal i, int radius);
256         frwalk(ideal i, int radius, intvec v, intvec w);
257TYPE:    ideal
258PURPOSE: compute the standard basis of the ideal w.r.t. the
259        lexicographical ordering or a weighted-lex ordering,
260        calculated via  the fractal walk algorithm with random element.
261SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2
262KEYWORDS: The fractal walk algorithm
263EXAMPLE: example frwalk; shows an example"
264{
265   // we use ring with ordering (a(...),lp,C)
266   list OSCTW    = OrderStringalp_NP("al", #);
267
268   string ord_str =   OSCTW[2];
269   intvec curr_weight   =   OSCTW[3]; /* current weight vector */
270   intvec target_weight =   OSCTW[4]; /* target weight vector */
271   kill OSCTW;
272   def xR = basering;
273
274   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
275   def old_ring = basering;
276   //print("//** help ring = " + string(basering));
277   ideal G = fetch(xR, Go);
278   int pert_deg = 2;
279   G = system("Mfrwalk", G, curr_weight, target_weight, pert_deg, radius, basering);
280
281   setring xR;
282   //kill Go;
283
284   keepring basering;
285   ideal result = fetch(old_ring, G);
286   attrib(result,"isSB",1);
287   return (result);
288}
289example
290{
291    "EXAMPLE:"; echo = 2;
292    ring r = 0,(z,y,x), lp;
293    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
294    frandwalk(I,2);
295}
296
297/*******************************************
298 * Tran Walk Algorithm with random element *
299 *******************************************/
300proc trwalk(ideal Go, int radius, int pert_deg, list #)
301"SYNTAX: trwalk(ideal i);
302         trwalk(ideal i, intvec v, intvec w);
303TYPE:    ideal
304PURPOSE: compute the standard basis of the ideal w.r.t.
305         the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\",
306         calculated via the Tran algorithm with random element.
307SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2
308KEYWORDS: The Tran algorithm
309EXAMPLE: example trwalk; shows an example"
310{
311  list L = OrderStringalp_NP("al", #);
312  int nP = L[1];
313
314  // we use ring with ordering (a(...),lp,C)
315  string ord_str =   L[2];
316  intvec curr_weight   = L[3];
317  intvec target_weight =  L[4];
318  kill L;
319
320  def xR = basering;
321
322  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
323  def old_ring = basering;
324
325  //print("//** help ring = " + string(basering));
326  ideal G = fetch(xR, Go);
327  G = system("TranMrImprovwalk", G, curr_weight, target_weight, nP, radius, pert_deg);
328
329  setring xR;
330   //kill Go;
331
332  keepring basering;
333  ideal result = fetch(old_ring, G);
334  attrib(result,"isSB",1);
335  return (result);
336}
337example
338{
339    "EXAMPLE:"; echo = 2;
340    ring r = 32003,(z,y,x), lp;
341    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
342    int radius = 2;
343    int perturb_degree = 3;
344    trwalk(I,radius,perturb_degree);
345}
Note: See TracBrowser for help on using the repository browser.