source: git/Singular/LIB/grwalk.lib @ ede2ad8

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