source: git/Singular/LIB/rwalk.lib @ 91c7251

spielwiese
Last change on this file since 91c7251 was 3686937, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Added '$Id$' as a comment to all libs (LIB/*.lib)
  • Property mode set to 100644
File size: 7.6 KB
Line 
1/////////////////////////////////////////////////
2version="version rwalk.lib 4.0.0.0 Jun_2013 "; // $Id$
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 ***********************************/
16static proc 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        else {
39          order_str = "(Wp("+string(#[1])+"),C)";
40        }
41      }
42      else {
43        if(typeof(#[1]) == "int"){
44          nP = #[1];
45        }
46        else {
47          print("// ** the input must be \"(ideal, int)\" or ");
48          print("// **                   \"(ideal, intvec)\"");
49          print("// ** a lex. GB will be computed from \"dp\" to \"lp\"");
50        }
51      }
52    }
53    else
54    {
55     if(size(#) == 2)
56     {
57       if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int"){
58         curr_weight = #[1];
59
60         if(Wpal == "al"){
61           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
62         }
63         else {
64           order_str = "(Wp("+string(#[1])+"),C)";
65         }
66       }
67       else{
68         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec"){
69           curr_weight = #[1];
70           target_weight = #[2];
71
72           if(Wpal == "al"){
73             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
74           }
75           else {
76             order_str = "(Wp("+string(#[1])+"),C)";
77           }
78         }
79         else{
80           print("// ** the input  must be \"(ideal,intvec,int)\" or ");
81           print("// **                    \"(ideal,intvec,intvec)\"");
82           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
83         }
84       }
85     }
86     else {
87       if(size(#) == 3) {
88         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and
89            typeof(#[3]) == "int")
90         {
91           curr_weight = #[1];
92           target_weight = #[2];
93           nP = #[3];
94           if(Wpal == "al"){
95             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
96           }
97           else {
98             order_str = "(Wp("+string(#[1])+"),C)";
99           }
100         }
101         else{
102           print("// ** the input must be \"(ideal,intvec,intvec,int)\"");
103           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
104
105         }
106       }
107       else{
108         print("// ** The given input is wrong");
109         print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
110       }
111     }
112    }
113  }
114
115  list result;
116  result[1] = nP;
117  result[2] = order_str;
118  result[3] = curr_weight;
119  result[4] = target_weight;
120
121  return(result);
122}
123
124/************************************
125 * Random Walk with perturbation    *
126 ************************************/
127proc rwalk(ideal Go, int radius, int pert_deg, list #)
128"SYNTAX: rwalk(ideal i, int radius);
129         rwalk(ideal i, int radius, intvec v, intvec w);
130TYPE:    ideal
131PURPOSE: compute the standard basis of the ideal, calculated via
132         the Random walk algorithm  from the ordering
133         \"(a(v),lp)\", \"dp\" or \"Dp\"
134         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
135SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1, awalk2
136KEYWORDS: Groebner walk
137EXAMPLE: example rwalk; shows an example"
138{
139//--------------------  Initialize parameters  ------------------------
140list OSCTW = OrderStringalp_NP("al", #);
141string ord_str = OSCTW[2];
142intvec curr_weight = OSCTW[3]; // original weight vector
143intvec target_weight = OSCTW[4]; // target weight vector
144kill OSCTW;
145option(redSB);
146
147//--------------------  Initialize parameters  ------------------------
148def xR = basering;
149execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
150def old_ring = basering;
151
152ideal G = fetch(xR, Go);
153G = system("Mrwalk", G, curr_weight, target_weight, radius, pert_deg);
154
155setring xR;
156kill Go;
157
158keepring basering;
159ideal result = fetch(old_ring, G);
160attrib(result,"isSB",1);
161return (result);
162}
163example
164{
165  "EXAMPLE:"; echo = 2;
166  // compute a Groebner basis of I w.r.t. lp.
167  ring r = 32003,(z,y,x), lp;
168  ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
169  int radius = 1;
170  int perturb_deg = 2;
171  rwalk(I,radius,perturb_deg);
172}
173
174/************************************
175 * Fractal Walk with random element *
176 ************************************/
177proc frandwalk(ideal Go, int radius, list #)
178"SYNTAX: frwalk(ideal i, int radius);
179         frwalk(ideal i, int radius, intvec v, intvec w);
180TYPE:    ideal
181PURPOSE: compute the standard basis of the ideal w.r.t. the
182        lexicographical ordering or a weighted-lex ordering,
183        calculated via  the fractal walk algorithm with random element.
184SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2
185KEYWORDS: The fractal walk algorithm
186EXAMPLE: example frwalk; shows an example"
187{
188   // we use ring with ordering (a(...),lp,C)
189   list OSCTW    = OrderStringalp_NP("al", #);
190
191   string ord_str =   OSCTW[2];
192   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
193   intvec target_weight =   OSCTW[4]; /* target weight vector */
194   kill OSCTW;
195   option(redSB);
196   def xR = basering;
197
198   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
199   def old_ring = basering;
200   //print("//** help ring = " + string(basering));
201   ideal G = fetch(xR, Go);
202
203   G = system("Mfrwalk", G, curr_weight, target_weight, radius);
204
205   setring xR;
206   //kill Go;
207
208   keepring basering;
209   ideal result = fetch(old_ring, G);
210   attrib(result,"isSB",1);
211   return (result);
212}
213example
214{
215    "EXAMPLE:"; echo = 2;
216    ring r = 0,(z,y,x), lp;
217    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
218    frandwalk(I,2);
219}
220
221/*******************************************
222 * Tran Walk Algorithm with random element *
223 *******************************************/
224proc trwalk(ideal Go, int radius, int pert_deg, list #)
225"SYNTAX: trwalk(ideal i);
226         trwalk(ideal i, intvec v, intvec w);
227TYPE:    ideal
228PURPOSE: compute the standard basis of the ideal w.r.t.
229         the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\",
230         calculated via the Tran algorithm with random element.
231SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2
232KEYWORDS: The Tran algorithm
233EXAMPLE: example trwalk; shows an example"
234{
235  list L = OrderStringalp_NP("al", #);
236  int nP = L[1];
237
238  // we use ring with ordering (a(...),lp,C)
239  string ord_str =   L[2];
240  intvec curr_weight   = L[3];
241  intvec target_weight =  L[4];
242  kill L;
243
244  option(redSB);
245  def xR = basering;
246
247  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
248  def old_ring = basering;
249
250  //print("//** help ring = " + string(basering));
251  ideal G = fetch(xR, Go);
252  G = system("TranMrImprovwalk", G, curr_weight, target_weight, nP, radius, pert_deg);
253
254  setring xR;
255   //kill Go;
256
257  keepring basering;
258  ideal result = fetch(old_ring, G);
259  attrib(result,"isSB",1);
260  return (result);
261}
262example
263{
264    "EXAMPLE:"; echo = 2;
265    ring r = 32003,(z,y,x), lp;
266    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
267    int radius = 2;
268    int perturb_degree = 3;
269    trwalk(I,radius,perturb_degree);
270}
Note: See TracBrowser for help on using the repository browser.