source: git/Singular/LIB/grwalk.lib @ 7d56875

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