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

spielwiese
Last change on this file since cb8103a was 66d68c, checked in by Hans Schoenemann <hannes@…>, 13 years ago
format git-svn-id: file:///usr/local/Singular/svn/trunk@13499 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 14.2 KB
Line 
1///////////////////////////////////////////////////////////////
2
3version="$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
217proc gwalk(ideal Go, list #)
218"SYNTAX: gwalk(ideal i);
219         gwalk(ideal i, intvec v, intvec w);
220TYPE:    ideal
221PURPOSE: compute the standard basis of the ideal, calculated via
222         the improved Groebner walk algorithm  from the ordering
223         \"(a(v),lp)\", \"dp\" or \"Dp\"
224         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
225SEE ALSO: std, stdfglm, groebner, pwalk, fwalk, twalk, awalk1, awalk2
226KEYWORDS: Groebner walk
227EXAMPLE: example gwalk; shows an example"
228{
229
230   /* we use ring with ordering (a(...),lp,C) */
231   list OSCTW    = OrderStringalp_NP("al", #);//"dp"
232   //list OSCTW    = OrderStringalp("al", "Dp");//Dp
233
234   string ord_str =   OSCTW[2];
235   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
236   intvec target_weight =   OSCTW[4]; /* terget weight vector */
237   kill OSCTW;
238   option(redSB);
239   def xR = basering;
240
241   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
242   def old_ring = basering;
243
244   //print("//** help ring = " + string(basering));
245   ideal G = fetch(xR, Go);
246   G = system("Mwalk", G, curr_weight, target_weight);
247
248   setring xR;
249   //kill Go;
250
251   keepring basering;
252   ideal result = fetch(old_ring, G);
253   attrib(result,"isSB",1);
254   return (result);
255}
256example
257{
258  "EXAMPLE:"; echo = 2;
259  //** compute a Groebner basis of I w.r.t. lp.
260  ring r = 32003,(z,y,x), lp;
261  ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
262  gwalk(I);
263}
264
265
266/* 16 Mai 2003 */
267proc awalk1(ideal G, list #)
268"SYNTAX: awalk1(ideal i);
269         awalk1(ideal i, int n);
270         awalk1(ideal i, int n, intvec v, intvec w);
271         awalk1(ideal i, intvec v, intvec w);
272TYPE:    ideal
273PURPOSE: compute the standard basis of the ideal, calculated via
274          the first alternative algorithm from an ordering
275         \"(a(v),lp)\", \"dp\" or \"Dp\" to the ordering
276         \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\"
277         with a perturbation degree n for the weight vector w.
278SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk2
279KEYWORDS: the first alternative algorithm
280EXAMPLE: example awalk1; shows an example"
281{
282  if (size(#) == 0)
283  {
284    return (awalk1_tmp(G, nvars(basering)-1));
285  }
286  else {
287    if(typeof(#[1]) == "int")
288    {
289      return (awalk1_tmp(G, #[1]));
290    }
291    else  {
292      return (awalk1_tmp(G, nvars(basering)-1, #));
293    }
294  }
295}
296example
297{
298    "EXAMPLE:"; echo = 2;
299    ring r = 32003,(z,y,x), lp;
300    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
301    awalk1(I,3);
302}
303
304
305proc awalk1_tmp(ideal Go, int n2, list #)
306//proc awalk1(ideal Go, int n1, int n2, list #)
307{
308   int nV = nvars(basering);
309   int n1 = 1;
310
311   //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV);
312   if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV)
313   {
314     print("//Erorr: The perturbed degree is wrong!!");
315     print("//       It must be between 1 and " + string(nV));
316     return();
317   }
318
319   /* we use ring with ordering (a(...),lp,C) */
320   list OSCTW    = OrderStringalp_NP("al", #);
321   //list OSCTW    = OrderStringalp("al", "Dp");
322
323   string ord_str =   OSCTW[2];
324   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
325   intvec target_weight =   OSCTW[4]; /* terget weight vector */
326   kill OSCTW;
327   option(redSB);
328
329   def xR = basering;
330
331   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
332   def old_ring = basering;
333   //print("//** help ring = " + string(basering));
334
335   ideal G = fetch(xR, Go);
336   G = system("MAltwalk1", G, n1, n2, curr_weight, target_weight);
337
338   setring xR;
339   //kill Go;
340
341   keepring basering;
342   ideal result = fetch(old_ring, G);
343   attrib(result,"isSB",1);
344   return (result);
345}
346
347proc fwalk(ideal Go, list #)
348"SYNTAX: fwalk(ideal i);
349         fwalk(ideal i, intvec v, intvec w);
350TYPE:    ideal
351PURPOSE: compute the standard basis of the ideal w.r.t. the
352        lexicographical ordering or a weighted-lex ordering,
353        calculated via  the fractal walk algorithm.
354SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2
355KEYWORDS: The fractal walk algorithm
356EXAMPLE: example fwalk; shows an example"
357{
358   /* we use ring with ordering (a(...),lp,C) */
359   list OSCTW    = OrderStringalp_NP("al", #);
360
361   string ord_str =   OSCTW[2];
362   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
363   intvec target_weight =   OSCTW[4]; /* terget weight vector */
364   kill OSCTW;
365   option(redSB);
366   def xR = basering;
367
368   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
369   def old_ring = basering;
370   //print("//** help ring = " + string(basering));
371
372   ideal G = fetch(xR, Go);
373   G = system("Mfwalk", G, curr_weight, target_weight);
374
375   setring xR;
376   //kill Go;
377
378   keepring basering;
379   ideal result = fetch(old_ring, G);
380   attrib(result,"isSB",1);
381   return (result);
382}
383example
384{
385    "EXAMPLE:"; echo = 2;
386    ring r = 32003,(z,y,x), lp;
387    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
388    fwalk(I);
389}
390
391
392proc awalk2(ideal Go, list #)
393"SYNTAX: awalk2(ideal i);
394         awalk2(ideal i, intvec v, intvec w);
395TYPE:    ideal
396PURPOSE: compute the standard basis of the ideal, calculated via
397         the second alternative algorithm from the ordering
398         \"(a(v),lp)\", \"dp\" or \"Dp\"
399         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
400SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1
401KEYWORDS: Groebner walk
402EXAMPLE: example awalk2; shows an example"
403{
404   /* we use ring with ordering (a(...),lp,C) */
405   list OSCTW    = OrderStringalp_NP("al", #);//"dp"
406   //list OSCTW    = OrderStringalp("al", "Dp");//Dp
407
408   string ord_str =   OSCTW[2];
409   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
410   intvec target_weight =   OSCTW[4]; /* terget weight vector */
411   kill OSCTW;
412   option(redSB);   def xR = basering;
413
414   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
415   def old_ring = basering;
416
417   //print("//** help ring = " + string(basering));
418   ideal G = fetch(xR, Go);
419   G = system("MAltwalk2", G, curr_weight, target_weight);
420
421   setring xR;
422   //kill Go;
423
424   keepring basering;
425   ideal result = fetch(old_ring, G);
426   attrib(result,"isSB",1);
427   return (result);
428}
429example
430{
431    "EXAMPLE:"; echo = 2;
432    ring r = 32003,(z,y,x), lp;
433    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
434    awalk2(I);
435}
436
437proc pwalk(ideal Go, int n1, int n2, list #)
438"SYNTAX: pwalk(int d, ideal i, int n1, int n2);
439         pwalk(int d, ideal i, int n1, int n2, intvec v, intvec w);
440TYPE:    ideal
441PURPOSE: compute the standard basis of the ideal, calculated via
442         the perturbation walk algorithm  from the ordering
443         \"(a(v),lp)\", \"dp\" or \"Dp\"
444         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\"
445         with a perturbation degree n, m for v and w, resp.
446SEE ALSO: std, stdfglm, groebner, gwalk, fwalk, twalk, awalk1, awalk2
447KEYWORDS: Perturbation walk
448EXAMPLE: example pwalk; shows an example"
449{
450  int nV = nvars(basering);
451  //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV);
452  if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV)
453  {
454    print("//Erorr: The perturbed degree is wrong!!");
455    print("//       It must be between 1 and " + string(nV));
456    return();
457  }
458
459  /* we use ring with ordering (a(...),lp,C) */
460  list OSCTW    = OrderStringalp_NP("al", #);
461  //list OSCTW    = OrderStringalp("al", "Dp");//Dp
462  int nP = OSCTW[1];
463
464  string ord_str =   OSCTW[2];
465  intvec curr_weight   =   OSCTW[3]; /* original weight vector */
466  intvec target_weight =   OSCTW[4]; /* terget weight vector */
467  kill OSCTW;
468  option(redSB);
469
470  def xR = basering;
471
472  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
473  def old_ring = basering;
474
475  ideal G = fetch(xR, Go);
476  G = system("Mpwalk", G, n1, n2, curr_weight, target_weight,nP);
477
478  setring xR;
479  //kill Go;
480
481  keepring basering;
482  ideal result = fetch(old_ring, G);
483  attrib(result,"isSB",1);
484  return (result);
485}
486example
487{
488    "EXAMPLE:"; echo = 2;
489    ring r = 32003,(z,y,x), lp;
490    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
491    pwalk(I,2,3);
492}
493
494
495proc twalk(ideal Go, list #)
496"SYNTAX: twalk(ideal i);
497         twalk(ideal i, intvec v, intvec w);
498TYPE:    ideal
499PURPOSE: compute the standard basis of the ideal w.r.t.
500         the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\",
501         calculated via the Tran algorithm.
502SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2
503KEYWORDS: The Tran algorithm
504EXAMPLE: example twalk; shows an example"
505{
506  list L = OrderStringalp_NP("al", #);
507  int nP = L[1];
508
509  /* we use ring with ordering (a(...),lp,C) */
510  string ord_str =   L[2];
511  intvec curr_weight   = L[3];
512  intvec target_weight =  L[4];
513  kill L;
514
515  option(redSB);
516  def xR = basering;
517
518  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
519  def old_ring = basering;
520
521  //print("//** help ring = " + string(basering));
522  ideal G = fetch(xR, Go);
523  G = system("TranMImprovwalk", G, curr_weight, target_weight, nP);
524
525  setring xR;
526   //kill Go;
527
528  keepring basering;
529  ideal result = fetch(old_ring, G);
530  attrib(result,"isSB",1);
531  return (result);
532}
533example
534{
535    "EXAMPLE:"; echo = 2;
536    ring r = 32003,(z,y,x), lp;
537    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
538    twalk(I);
539}
Note: See TracBrowser for help on using the repository browser.