1 | ///////////////////////////////////////////////// |
---|
2 | version="version rwalk.lib 4.0.0.0 Jun_2014 "; |
---|
3 | category="Commutative Algebra"; |
---|
4 | |
---|
5 | info=" |
---|
6 | LIBRARY: rwalk.lib Groebner Walk Conversion Algorithms |
---|
7 | AUTHOR: Stephan Oberfranz |
---|
8 | |
---|
9 | PROCEDURES: |
---|
10 | rwalk(ideal,int,int[,intvec,intvec]); standard basis of ideal via Random Walk algorithm |
---|
11 | rwalk(ideal,int[,intvec,intvec]); standard basis of ideal via Random Perturbation Walk algorithm |
---|
12 | frwalk(ideal,int[,intvec,intvec]); standard basis of ideal via Random Fractal Walk algorithm |
---|
13 | "; |
---|
14 | |
---|
15 | /*********************************** |
---|
16 | * Argument string for Random Walk * |
---|
17 | ***********************************/ |
---|
18 | static 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 | ****************/ |
---|
143 | proc 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); |
---|
146 | TYPE: ideal |
---|
147 | PURPOSE: 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\". |
---|
151 | SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1, awalk2 |
---|
152 | KEYWORDS: Groebner walk |
---|
153 | EXAMPLE: example rwalk; shows an example" |
---|
154 | { |
---|
155 | //-------------------- Initialize parameters ------------------------ |
---|
156 | int n= nvars(basering); |
---|
157 | list OSCTW = OrderStringalp_NP("al",#); |
---|
158 | if(size(#)>1) |
---|
159 | { |
---|
160 | if(size(#[2]) == n*n) |
---|
161 | { |
---|
162 | OSCTW= OrderStringalp_NP("M", #); |
---|
163 | } |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | OSCTW= OrderStringalp_NP("al", #); |
---|
168 | } |
---|
169 | string ord_str = OSCTW[2]; |
---|
170 | intvec curr_weight = OSCTW[3]; // original weight vector |
---|
171 | intvec target_weight = OSCTW[4]; // target weight vector |
---|
172 | kill OSCTW; |
---|
173 | |
---|
174 | //-------------------- Initialize parameters ------------------------ |
---|
175 | def xR = basering; |
---|
176 | execute("ring ostR = "+charstr(xR)+",("+varstr(xR)+"),"+ord_str+";"); |
---|
177 | def old_ring = basering; |
---|
178 | |
---|
179 | ideal G = fetch(xR, Go); |
---|
180 | G = system("Mrwalk", G, curr_weight, target_weight, radius, pert_deg, basering); |
---|
181 | |
---|
182 | setring xR; |
---|
183 | kill Go; |
---|
184 | |
---|
185 | keepring basering; |
---|
186 | ideal result = fetch(old_ring, G); |
---|
187 | attrib(result,"isSB",1); |
---|
188 | return (result); |
---|
189 | } |
---|
190 | example |
---|
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 | *****************************************/ |
---|
204 | proc 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); |
---|
207 | TYPE: ideal |
---|
208 | PURPOSE: 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\". |
---|
212 | SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1, awalk2 |
---|
213 | KEYWORDS: Groebner walk |
---|
214 | EXAMPLE: example rwalk; shows an example" |
---|
215 | { |
---|
216 | //-------------------- Initialize parameters ------------------------ |
---|
217 | list OSCTW = OrderStringalp_NP("al", #); |
---|
218 | if(size(#)>1) |
---|
219 | { |
---|
220 | if(size(#[2]) == n*n) |
---|
221 | { |
---|
222 | OSCTW= OrderStringalp_NP("M", #); |
---|
223 | } |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | OSCTW= OrderStringalp_NP("al", #); |
---|
228 | } |
---|
229 | string ord_str = OSCTW[2]; |
---|
230 | intvec curr_weight = OSCTW[3]; // original weight vector |
---|
231 | intvec target_weight = OSCTW[4]; // target weight vector |
---|
232 | kill OSCTW; |
---|
233 | |
---|
234 | //-------------------- Initialize parameters ------------------------ |
---|
235 | def xR = basering; |
---|
236 | execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); |
---|
237 | def old_ring = basering; |
---|
238 | |
---|
239 | ideal G = fetch(xR, Go); |
---|
240 | G = system("Mprwalk", G, curr_weight, target_weight, radius, o_pert_deg, t_pert_deg, basering); |
---|
241 | |
---|
242 | setring xR; |
---|
243 | kill Go; |
---|
244 | |
---|
245 | keepring basering; |
---|
246 | ideal result = fetch(old_ring, G); |
---|
247 | attrib(result,"isSB",1); |
---|
248 | return (result); |
---|
249 | } |
---|
250 | example |
---|
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; |
---|
256 | int radius = 1; |
---|
257 | int o_perturb_deg = 2; |
---|
258 | int t_perturb_deg = 2; |
---|
259 | prwalk(I,radius,o_perturb_deg,t_perturb_deg); |
---|
260 | } |
---|
261 | |
---|
262 | /************************************ |
---|
263 | * Fractal Walk with random element * |
---|
264 | ************************************/ |
---|
265 | proc frandwalk(ideal Go, int radius, list #) |
---|
266 | "SYNTAX: frwalk(ideal i, int radius); |
---|
267 | frwalk(ideal i, int radius, intvec v, intvec w); |
---|
268 | TYPE: ideal |
---|
269 | PURPOSE: 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\". |
---|
273 | SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2 |
---|
274 | KEYWORDS: The fractal walk algorithm |
---|
275 | EXAMPLE: 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 | } |
---|
311 | example |
---|
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 | } |
---|