1 | <<<<<<< HEAD |
---|
2 | ======= |
---|
3 | // |
---|
4 | >>>>>>> 92644b759d66f085c842e4284d78c2e203291b67 |
---|
5 | version="$Id$"; |
---|
6 | category="Commutative Algebra"; |
---|
7 | |
---|
8 | info=" |
---|
9 | LIBRARY: rwalk.lib Groebner Walk Conversion Algorithms |
---|
10 | AUTHOR: Stephan Oberfranz |
---|
11 | |
---|
12 | PROCEDURES: |
---|
13 | rwalk(ideal[,intvec]); standard basis of ideal via randomwalk algorithm |
---|
14 | "; |
---|
15 | |
---|
16 | /*********************************** |
---|
17 | * Argument string for Random Walk * |
---|
18 | ***********************************/ |
---|
19 | proc 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 | ****************/ |
---|
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\" or \"Dp\" |
---|
150 | to the ordering \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\". |
---|
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 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)\". |
---|
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 | string ord_str = OSCTW[2]; |
---|
219 | intvec curr_weight = OSCTW[3]; // original weight vector |
---|
220 | intvec target_weight = OSCTW[4]; // target weight vector |
---|
221 | kill OSCTW; |
---|
222 | |
---|
223 | //-------------------- Initialize parameters ------------------------ |
---|
224 | def xR = basering; |
---|
225 | execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); |
---|
226 | def old_ring = basering; |
---|
227 | |
---|
228 | ideal G = fetch(xR, Go); |
---|
229 | G = system("Mprwalk", G, curr_weight, target_weight, radius, o_pert_deg, t_pert_deg, basering); |
---|
230 | |
---|
231 | setring xR; |
---|
232 | kill Go; |
---|
233 | |
---|
234 | keepring basering; |
---|
235 | ideal result = fetch(old_ring, G); |
---|
236 | attrib(result,"isSB",1); |
---|
237 | return (result); |
---|
238 | } |
---|
239 | example |
---|
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 | ************************************/ |
---|
254 | proc frandwalk(ideal Go, int radius, list #) |
---|
255 | "SYNTAX: frwalk(ideal i, int radius); |
---|
256 | frwalk(ideal i, int radius, intvec v, intvec w); |
---|
257 | TYPE: ideal |
---|
258 | PURPOSE: 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. |
---|
261 | SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2 |
---|
262 | KEYWORDS: The fractal walk algorithm |
---|
263 | EXAMPLE: 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 | } |
---|
289 | example |
---|
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 | *******************************************/ |
---|
300 | proc trwalk(ideal Go, int radius, int pert_deg, list #) |
---|
301 | "SYNTAX: trwalk(ideal i); |
---|
302 | trwalk(ideal i, intvec v, intvec w); |
---|
303 | TYPE: ideal |
---|
304 | PURPOSE: 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. |
---|
307 | SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2 |
---|
308 | KEYWORDS: The Tran algorithm |
---|
309 | EXAMPLE: 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 | } |
---|
337 | example |
---|
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 | } |
---|