source: git/Singular/LIB/grwalk.lib @ 92992c

fieker-DuValspielwiese
Last change on this file since 92992c 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: 14.2 KB
Line 
1///////////////////////////////////////////////////////////////
2version="version grwalk.lib 4.0.0.0 Jun_2013 "; // $Id$
3category="Commutative Algebra";
4
5info="
6LIBRARY: grwalk.lib   Groebner Walk Conversion Algorithms
7AUTHOR: I Made Sulandra
8
9PROCEDURES:
10 fwalk(ideal[,intvec]);   standard basis of ideal via fractalwalk alg
11 twalk(ideal[,intvec]);   standard basis of ideal via Tran's alg
12 awalk1(ideal[,intvec]);   standard basis of ideal via the first alt. alg
13 awalk2(ideal[,intvec]);   standard basis of ideal via the second alt. alg
14 pwalk(ideal[,intvec]);   standard basis of ideal via perturbation walk alg
15 gwalk(ideal[,intvec]);   standard basis of ideal via groebnerwalk alg
16";
17
18//////////////////////////////////////////////////////////////////////////////
19
20static proc OrderStringalp(string Wpal,list #)
21{
22  int n= nvars(basering);
23  string order_str;
24  intvec curr_weight, target_weight;
25  curr_weight = system("Mivdp",n);
26  target_weight = system("Mivlp",n);
27
28   if(size(#) != 0)
29   {
30     if(size(#) == 1)
31     {
32       if(typeof(#[1]) == "intvec")
33       {
34         if(Wpal == "al"){
35           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
36         }
37         else {
38           order_str = "(Wp("+string(#[1])+"),C)";
39         }
40         curr_weight = #[1];
41       }
42       else
43       {
44        if(typeof(#[1]) == "string")
45        {
46          if(#[1] == "Dp") {
47            order_str = "Dp";
48          }
49          else {
50            order_str = "dp";
51          }
52        }
53        else {
54          order_str = "dp";
55        }
56     }
57    }
58    else
59    {
60     if(size(#) == 2)
61     {
62       if(typeof(#[2]) == "intvec")
63       {
64         target_weight = #[2];
65       }
66       if(typeof(#[1]) == "intvec")
67       {
68         if(Wpal == "al"){
69           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
70         }
71         else {
72           order_str = "(Wp("+string(#[1])+"),C)";
73         }
74         curr_weight = #[1];
75       }
76       else
77       {
78        if(typeof(#[1]) == "string")
79        {
80          if(#[1] == "Dp") {
81            order_str = "Dp";
82           }
83           else {
84              order_str = "dp";
85           }
86        }
87        else {
88           order_str = "dp";
89        }
90      }
91     }
92    }
93   }
94   else {
95     order_str = "dp";
96   }
97   list result;
98   result[1] = order_str;
99   result[2] = curr_weight;
100   result[3] = target_weight;
101   return(result);
102}
103
104static proc OrderStringalp_NP(string Wpal,list #)
105{
106  int n= nvars(basering);
107  string order_str = "dp";
108  //string order_str = "Dp";
109
110  int nP = 1;// call LatsGB to compute the wanted GB  by pwalk
111
112  //Default:
113  // if size(#)=0, the Groebnerwalk algorithm and its developments compute
114  // a Groebner basis from "dp" to "lp"
115
116  intvec curr_weight = system("Mivdp",n); //define (1,1,...,1)
117  intvec target_weight = system("Mivlp",n); //define (1,0,...,0)
118
119  if(size(#) != 0)
120  {
121    if(size(#) == 1)
122    {
123      if(typeof(#[1]) == "intvec") {
124        curr_weight = #[1];
125
126        if(Wpal == "al"){
127          order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
128        }
129        else {
130          order_str = "(Wp("+string(#[1])+"),C)";
131        }
132      }
133      else {
134        if(typeof(#[1]) == "int"){
135          nP = #[1];
136        }
137        else {
138          print("// ** the input must be \"(ideal, int)\" or ");
139          print("// **                   \"(ideal, intvec)\"");
140          print("// ** a lex. GB will be computed from \"dp\" to \"lp\"");
141        }
142      }
143    }
144    else
145    {
146     if(size(#) == 2)
147     {
148       if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int"){
149         curr_weight = #[1];
150
151         if(Wpal == "al"){
152           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
153         }
154         else {
155           order_str = "(Wp("+string(#[1])+"),C)";
156         }
157       }
158       else{
159         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec"){
160           curr_weight = #[1];
161           target_weight = #[2];
162
163           if(Wpal == "al"){
164             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
165           }
166           else {
167             order_str = "(Wp("+string(#[1])+"),C)";
168           }
169         }
170         else{
171           print("// ** the input  must be \"(ideal,intvec,int)\" or ");
172           print("// **                    \"(ideal,intvec,intvec)\"");
173           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
174         }
175       }
176     }
177     else {
178       if(size(#) == 3) {
179         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and
180            typeof(#[3]) == "int")
181         {
182           curr_weight = #[1];
183           target_weight = #[2];
184           nP = #[3];
185           if(Wpal == "al"){
186             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
187           }
188           else {
189             order_str = "(Wp("+string(#[1])+"),C)";
190           }
191         }
192         else{
193           print("// ** the input must be \"(ideal,intvec,intvec,int)\"");
194           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
195
196         }
197       }
198       else{
199         print("// ** The given input is wrong");
200         print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
201       }
202     }
203    }
204  }
205
206  list result;
207  result[1] = nP;
208  result[2] = order_str;
209  result[3] = curr_weight;
210  result[4] = target_weight;
211
212  return(result);
213}
214
215
216proc gwalk(ideal Go, list #)
217"SYNTAX: gwalk(ideal i);
218         gwalk(ideal i, intvec v, intvec w);
219TYPE:    ideal
220PURPOSE: compute the standard basis of the ideal, calculated via
221         the improved Groebner walk algorithm  from the ordering
222         \"(a(v),lp)\", \"dp\" or \"Dp\"
223         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
224SEE ALSO: std, stdfglm, groebner, pwalk, fwalk, twalk, awalk1, awalk2
225KEYWORDS: Groebner walk
226EXAMPLE: example gwalk; shows an example"
227{
228
229   /* we use ring with ordering (a(...),lp,C) */
230   list OSCTW    = OrderStringalp_NP("al", #);//"dp"
231   //list OSCTW    = OrderStringalp("al", "Dp");//Dp
232
233   string ord_str =   OSCTW[2];
234   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
235   intvec target_weight =   OSCTW[4]; /* terget weight vector */
236   kill OSCTW;
237   option(redSB);
238   def xR = basering;
239
240   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
241   def old_ring = basering;
242
243   //print("//** help ring = " + string(basering));
244   ideal G = fetch(xR, Go);
245   G = system("Mwalk", G, curr_weight, target_weight);
246
247   setring xR;
248   //kill Go;
249
250   keepring basering;
251   ideal result = fetch(old_ring, G);
252   attrib(result,"isSB",1);
253   return (result);
254}
255example
256{
257  "EXAMPLE:"; echo = 2;
258  //** compute a Groebner basis of I w.r.t. lp.
259  ring r = 32003,(z,y,x), lp;
260  ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
261  gwalk(I);
262}
263
264
265/* 16 Mai 2003 */
266proc awalk1(ideal G, list #)
267"SYNTAX: awalk1(ideal i);
268         awalk1(ideal i, int n);
269         awalk1(ideal i, int n, intvec v, intvec w);
270         awalk1(ideal i, intvec v, intvec w);
271TYPE:    ideal
272PURPOSE: compute the standard basis of the ideal, calculated via
273          the first alternative algorithm from an ordering
274         \"(a(v),lp)\", \"dp\" or \"Dp\" to the ordering
275         \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\"
276         with a perturbation degree n for the weight vector w.
277SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk2
278KEYWORDS: the first alternative algorithm
279EXAMPLE: example awalk1; shows an example"
280{
281  if (size(#) == 0)
282  {
283    return (awalk1_tmp(G, nvars(basering)-1));
284  }
285  else {
286    if(typeof(#[1]) == "int")
287    {
288      return (awalk1_tmp(G, #[1]));
289    }
290    else  {
291      return (awalk1_tmp(G, nvars(basering)-1, #));
292    }
293  }
294}
295example
296{
297    "EXAMPLE:"; echo = 2;
298    ring r = 32003,(z,y,x), lp;
299    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
300    awalk1(I,3);
301}
302
303
304proc awalk1_tmp(ideal Go, int n2, list #)
305//proc awalk1(ideal Go, int n1, int n2, list #)
306{
307   int nV = nvars(basering);
308   int n1 = 1;
309
310   //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV);
311   if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV)
312   {
313     print("//Erorr: The perturbed degree is wrong!!");
314     print("//       It must be between 1 and " + string(nV));
315     return();
316   }
317
318   /* we use ring with ordering (a(...),lp,C) */
319   list OSCTW    = OrderStringalp_NP("al", #);
320   //list OSCTW    = OrderStringalp("al", "Dp");
321
322   string ord_str =   OSCTW[2];
323   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
324   intvec target_weight =   OSCTW[4]; /* terget weight vector */
325   kill OSCTW;
326   option(redSB);
327
328   def xR = basering;
329
330   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
331   def old_ring = basering;
332   //print("//** help ring = " + string(basering));
333
334   ideal G = fetch(xR, Go);
335   G = system("MAltwalk1", G, n1, n2, curr_weight, target_weight);
336
337   setring xR;
338   //kill Go;
339
340   keepring basering;
341   ideal result = fetch(old_ring, G);
342   attrib(result,"isSB",1);
343   return (result);
344}
345
346proc fwalk(ideal Go, list #)
347"SYNTAX: fwalk(ideal i);
348         fwalk(ideal i, intvec v, intvec w);
349TYPE:    ideal
350PURPOSE: compute the standard basis of the ideal w.r.t. the
351        lexicographical ordering or a weighted-lex ordering,
352        calculated via  the fractal walk algorithm.
353SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2
354KEYWORDS: The fractal walk algorithm
355EXAMPLE: example fwalk; shows an example"
356{
357   /* we use ring with ordering (a(...),lp,C) */
358   list OSCTW    = OrderStringalp_NP("al", #);
359
360   string ord_str =   OSCTW[2];
361   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
362   intvec target_weight =   OSCTW[4]; /* terget weight vector */
363   kill OSCTW;
364   option(redSB);
365   def xR = basering;
366
367   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
368   def old_ring = basering;
369   //print("//** help ring = " + string(basering));
370
371   ideal G = fetch(xR, Go);
372   G = system("Mfwalk", G, curr_weight, target_weight);
373
374   setring xR;
375   //kill Go;
376
377   keepring basering;
378   ideal result = fetch(old_ring, G);
379   attrib(result,"isSB",1);
380   return (result);
381}
382example
383{
384    "EXAMPLE:"; echo = 2;
385    ring r = 32003,(z,y,x), lp;
386    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
387    fwalk(I);
388}
389
390
391proc awalk2(ideal Go, list #)
392"SYNTAX: awalk2(ideal i);
393         awalk2(ideal i, intvec v, intvec w);
394TYPE:    ideal
395PURPOSE: compute the standard basis of the ideal, calculated via
396         the second alternative algorithm from the ordering
397         \"(a(v),lp)\", \"dp\" or \"Dp\"
398         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
399SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1
400KEYWORDS: Groebner walk
401EXAMPLE: example awalk2; shows an example"
402{
403   /* we use ring with ordering (a(...),lp,C) */
404   list OSCTW    = OrderStringalp_NP("al", #);//"dp"
405   //list OSCTW    = OrderStringalp("al", "Dp");//Dp
406
407   string ord_str =   OSCTW[2];
408   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
409   intvec target_weight =   OSCTW[4]; /* terget weight vector */
410   kill OSCTW;
411   option(redSB);   def xR = basering;
412
413   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
414   def old_ring = basering;
415
416   //print("//** help ring = " + string(basering));
417   ideal G = fetch(xR, Go);
418   G = system("MAltwalk2", G, curr_weight, target_weight);
419
420   setring xR;
421   //kill Go;
422
423   keepring basering;
424   ideal result = fetch(old_ring, G);
425   attrib(result,"isSB",1);
426   return (result);
427}
428example
429{
430    "EXAMPLE:"; echo = 2;
431    ring r = 32003,(z,y,x), lp;
432    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
433    awalk2(I);
434}
435
436proc pwalk(ideal Go, int n1, int n2, list #)
437"SYNTAX: pwalk(int d, ideal i, int n1, int n2);
438         pwalk(int d, ideal i, int n1, int n2, intvec v, intvec w);
439TYPE:    ideal
440PURPOSE: compute the standard basis of the ideal, calculated via
441         the perturbation walk algorithm  from the ordering
442         \"(a(v),lp)\", \"dp\" or \"Dp\"
443         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\"
444         with a perturbation degree n, m for v and w, resp.
445SEE ALSO: std, stdfglm, groebner, gwalk, fwalk, twalk, awalk1, awalk2
446KEYWORDS: Perturbation walk
447EXAMPLE: example pwalk; shows an example"
448{
449  int nV = nvars(basering);
450  //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV);
451  if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV)
452  {
453    print("//Erorr: The perturbed degree is wrong!!");
454    print("//       It must be between 1 and " + string(nV));
455    return();
456  }
457
458  /* we use ring with ordering (a(...),lp,C) */
459  list OSCTW    = OrderStringalp_NP("al", #);
460  //list OSCTW    = OrderStringalp("al", "Dp");//Dp
461  int nP = OSCTW[1];
462
463  string ord_str =   OSCTW[2];
464  intvec curr_weight   =   OSCTW[3]; /* original weight vector */
465  intvec target_weight =   OSCTW[4]; /* terget weight vector */
466  kill OSCTW;
467  option(redSB);
468
469  def xR = basering;
470
471  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
472  def old_ring = basering;
473
474  ideal G = fetch(xR, Go);
475  G = system("Mpwalk", G, n1, n2, curr_weight, target_weight,nP);
476
477  setring xR;
478  //kill Go;
479
480  keepring basering;
481  ideal result = fetch(old_ring, G);
482  attrib(result,"isSB",1);
483  return (result);
484}
485example
486{
487    "EXAMPLE:"; echo = 2;
488    ring r = 32003,(z,y,x), lp;
489    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
490    pwalk(I,2,3);
491}
492
493
494proc twalk(ideal Go, list #)
495"SYNTAX: twalk(ideal i);
496         twalk(ideal i, intvec v, intvec w);
497TYPE:    ideal
498PURPOSE: compute the standard basis of the ideal w.r.t.
499         the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\",
500         calculated via the Tran algorithm.
501SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2
502KEYWORDS: The Tran algorithm
503EXAMPLE: example twalk; shows an example"
504{
505  list L = OrderStringalp_NP("al", #);
506  int nP = L[1];
507
508  /* we use ring with ordering (a(...),lp,C) */
509  string ord_str =   L[2];
510  intvec curr_weight   = L[3];
511  intvec target_weight =  L[4];
512  kill L;
513
514  option(redSB);
515  def xR = basering;
516
517  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
518  def old_ring = basering;
519
520  //print("//** help ring = " + string(basering));
521  ideal G = fetch(xR, Go);
522  G = system("TranMImprovwalk", G, curr_weight, target_weight, nP);
523
524  setring xR;
525   //kill Go;
526
527  keepring basering;
528  ideal result = fetch(old_ring, G);
529  attrib(result,"isSB",1);
530  return (result);
531}
532example
533{
534    "EXAMPLE:"; echo = 2;
535    ring r = 32003,(z,y,x), lp;
536    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
537    twalk(I);
538}
Note: See TracBrowser for help on using the repository browser.