source: git/Singular/LIB/groebnerwalk.lib @ ac4f06e

spielwiese
Last change on this file since ac4f06e was ac4f06e, checked in by Hans Schönemann <hannes@…>, 18 years ago
*hannes from 2-0-6 git-svn-id: file:///usr/local/Singular/svn/trunk@8038 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 14.2 KB
Line 
1///////////////////////////////////////////////////////////////
2// $Id: groebnerwalk.lib,v 1.2 2005-05-04 13:16:46 Singular Exp $   //
3///////////////////////////////////////////////////////////////
4
5version="$Id: groebnerwalk.lib,v 1.2 2005-05-04 13:16:46 Singular Exp $";
6category="cc";
7 
8info="   
9LIBRARY: groebnerwalk.lib   
10
11PROCEDURES:
12 gwalk(ideal[,intvec]);   standard basis of ideal via groebnerwalk alg
13 pwalk(ideal[,intvec]);   standard basis of ideal via perturbation walk alg
14 fwalk(ideal[,intvec]);   standard basis of ideal via fractalwalk alg
15 twalk(ideal[,intvec]);   standard basis of ideal via Tran's alg
16 awalk1(ideal[,intvec]);   standard basis of ideal via the first alt. alg
17 awalk2(ideal[,intvec]);   standard basis of ideal via the second alt. alg
18";   
19   
20//////////////////////////////////////////////////////////////////////////////
21
22static proc OrderStringalp(string Wpal,list #)
23{
24  int n= nvars(basering);
25  string order_str;
26  intvec curr_weight, target_weight;
27  curr_weight = system("Mivdp",n);   
28  target_weight = system("Mivlp",n);   
29
30   if(size(#) != 0)
31   {
32     if(size(#) == 1)
33     {
34       if(typeof(#[1]) == "intvec")
35       {
36         if(Wpal == "al"){
37           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
38         }
39         else {
40           order_str = "(Wp("+string(#[1])+"),C)";
41         }         
42         curr_weight = #[1];
43       }
44       else
45       {
46        if(typeof(#[1]) == "string")
47        {
48          if(#[1] == "Dp") {
49            order_str = "Dp";
50          }
51          else {
52            order_str = "dp";
53          }
54        }   
55        else {
56          order_str = "dp";
57        }   
58     }
59    }
60    else
61    {
62     if(size(#) == 2)
63     {
64       if(typeof(#[2]) == "intvec")
65       {
66         target_weight = #[2];
67       }
68       if(typeof(#[1]) == "intvec")
69       {
70         if(Wpal == "al"){
71           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
72         }
73         else {
74           order_str = "(Wp("+string(#[1])+"),C)";
75         }
76         curr_weight = #[1];
77       }
78       else
79       {
80        if(typeof(#[1]) == "string")
81        {
82          if(#[1] == "Dp") {
83            order_str = "Dp";
84           }
85           else {
86              order_str = "dp";
87           }
88        }
89        else {
90           order_str = "dp";
91        }
92      }
93     } 
94    }           
95   }
96   else {
97     order_str = "dp";
98   }
99   list result;
100   result[1] = order_str;
101   result[2] = curr_weight;
102   result[3] = target_weight;   
103   return(result);
104}
105
106static proc OrderStringalp_NP(string Wpal,list #)
107{
108  int n= nvars(basering);
109  string order_str = "dp";
110  //string order_str = "Dp";
111
112  int nP = 1;// call LatsGB to compute the wanted GB  by pwalk
113
114  //Default:
115  // if size(#)=0, the Gröbnerwalk algorithm and its developments compute
116  // a Groebner basis from "dp" to "lp"
117 
118  intvec curr_weight = system("Mivdp",n); //define (1,1,...,1)
119  intvec target_weight = system("Mivlp",n); //define (1,0,...,0)
120
121  if(size(#) != 0)
122  {
123    if(size(#) == 1)
124    {
125      if(typeof(#[1]) == "intvec") {
126        curr_weight = #[1];
127       
128        if(Wpal == "al"){
129          order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
130        }
131        else {
132          order_str = "(Wp("+string(#[1])+"),C)";
133        }         
134      }
135      else {
136        if(typeof(#[1]) == "int"){
137          nP = #[1];
138        }
139        else {
140          print("// ** the input must be \"(ideal, int)\" or ");
141          print("// **                   \"(ideal, intvec)\"");
142          print("// ** a lex. GB will be computed from \"dp\" to \"lp\"");
143        }
144      }
145    }
146    else
147    {
148     if(size(#) == 2)
149     {
150       if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int"){
151         curr_weight = #[1];
152
153         if(Wpal == "al"){
154           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
155         }
156         else {
157           order_str = "(Wp("+string(#[1])+"),C)";
158         }
159       }
160       else{
161         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec"){
162           curr_weight = #[1];
163           target_weight = #[2];
164           
165           if(Wpal == "al"){
166             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
167           }
168           else {
169             order_str = "(Wp("+string(#[1])+"),C)";
170           }
171         }
172         else{
173           print("// ** the input  must be \"(ideal,intvec,int)\" or ");
174           print("// **                    \"(ideal,intvec,intvec)\"");
175           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
176         }
177       }
178     }
179     else {
180       if(size(#) == 3) {
181         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and
182            typeof(#[3]) == "int")
183         {
184           curr_weight = #[1];
185           target_weight = #[2];
186           nP = #[3];   
187           if(Wpal == "al"){
188             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
189           }
190           else {
191             order_str = "(Wp("+string(#[1])+"),C)";
192           }
193         }
194         else{
195           print("// ** the input must be \"(ideal,intvec,intvec,int)\"");
196           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
197         
198         }         
199       }
200       else{
201         print("// ** The given input is wrong");
202         print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
203       }
204     }
205    }
206  }
207 
208  list result;
209  result[1] = nP;
210  result[2] = order_str;
211  result[3] = curr_weight;
212  result[4] = target_weight;
213
214  return(result);
215}
216
217
218proc gwalk(ideal Go, list #)
219"SYNTAX: gwalk(ideal i);
220         gwalk(ideal i, intvec v, intvec w);
221TYPE:    ideal
222PURPOSE: compute the standard basis of the ideal, calculated via
223         the improved Groebner walk algorithm  from the ordering
224         \"(a(v),lp)\", \"dp\" or \"Dp\"
225         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
226SEE ALSO: std, stdfglm, groebner, pwalk, fwalk, twalk, awalk1, awalk2
227KEYWORDS: Groebner walk
228EXAMPLE: example gwalk; shows an example"         
229{
230
231   /* we use ring with ordering (a(...),lp,C) */
232   list OSCTW    = OrderStringalp_NP("al", #);//"dp"
233   //list OSCTW    = OrderStringalp("al", "Dp");//Dp
234
235   string ord_str =   OSCTW[2];
236   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
237   intvec target_weight =   OSCTW[4]; /* terget weight vector */
238   kill(OSCTW);
239   option(redSB);   
240   def xR = basering;
241
242   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
243   def old_ring = basering;
244
245   //print("//** help ring = " + string(basering));
246   ideal G = fetch(xR, Go);
247   G = system("Mwalk", G, curr_weight, target_weight);
248     
249   setring xR;
250   //kill(Go);
251
252   keepring basering;
253   ideal result = fetch(old_ring, G);
254   return (result);
255}
256example
257{
258  "EXAMPLE:"; echo = 2;
259  //** compute a Gröbner 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   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   return (result);
380}
381example
382{
383    "EXAMPLE:"; echo = 2;
384    ring r = 32003,(z,y,x), lp;
385    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
386    fwalk(I);     
387}
388
389
390proc awalk2(ideal Go, list #)
391"SYNTAX: awalk2(ideal i);
392         awalk2(ideal i, intvec v, intvec w);
393TYPE:    ideal
394PURPOSE: compute the standard basis of the ideal, calculated via
395         the second alternative algorithm from the ordering
396         \"(a(v),lp)\", \"dp\" or \"Dp\"
397         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\".
398SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1
399KEYWORDS: Groebner walk
400EXAMPLE: example awalk2; shows an example"
401{
402   /* we use ring with ordering (a(...),lp,C) */
403   list OSCTW    = OrderStringalp_NP("al", #);//"dp"
404   //list OSCTW    = OrderStringalp("al", "Dp");//Dp
405
406   string ord_str =   OSCTW[2];
407   intvec curr_weight   =   OSCTW[3]; /* original weight vector */
408   intvec target_weight =   OSCTW[4]; /* terget weight vector */
409   kill(OSCTW);
410   option(redSB);   def xR = basering;
411
412   execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
413   def old_ring = basering;
414
415   //print("//** help ring = " + string(basering));
416   ideal G = fetch(xR, Go);
417   G = system("MAltwalk2", G, curr_weight, target_weight);
418   
419   setring xR;
420   //kill(Go);
421
422   keepring basering;
423   ideal result = fetch(old_ring, G);
424   return (result);
425}
426example
427{
428    "EXAMPLE:"; echo = 2;
429    ring r = 32003,(z,y,x), lp;
430    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
431    awalk2(I);     
432}
433
434proc pwalk(ideal Go, int n1, int n2, list #)
435"SYNTAX: pwalk(int d, ideal i, int n1, int n2);
436         pwalk(int d, ideal i, int n1, int n2, intvec v, intvec w);
437TYPE:    ideal
438PURPOSE: compute the standard basis of the ideal, calculated via
439         the perturbation walk algorithm  from the ordering
440         \"(a(v),lp)\", \"dp\" or \"Dp\"
441         to the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\"
442         with a perturbation degree n, m for v and w, resp.
443SEE ALSO: std, stdfglm, groebner, gwalk, fwalk, twalk, awalk1, awalk2
444KEYWORDS: Perturbation walk
445EXAMPLE: example pwalk; shows an example"
446{
447  int nV = nvars(basering);
448  //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV);
449  if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV)
450  {
451    print("//Erorr: The perturbed degree is wrong!!");
452    print("//       It must be between 1 and " + string(nV));
453    return();
454  }
455
456  /* we use ring with ordering (a(...),lp,C) */
457  list OSCTW    = OrderStringalp_NP("al", #);
458  //list OSCTW    = OrderStringalp("al", "Dp");//Dp
459  int nP = OSCTW[1];
460   
461  string ord_str =   OSCTW[2];
462  intvec curr_weight   =   OSCTW[3]; /* original weight vector */
463  intvec target_weight =   OSCTW[4]; /* terget weight vector */
464  kill(OSCTW);
465  option(redSB);
466
467  def xR = basering;
468
469  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
470  def old_ring = basering;
471
472  ideal G = fetch(xR, Go);
473  G = system("Mpwalk", G, n1, n2, curr_weight, target_weight,nP);
474   
475  setring xR;
476  //kill(Go);
477
478  keepring basering;
479  ideal result = fetch(old_ring, G);
480  return (result);
481}
482example
483{
484    "EXAMPLE:"; echo = 2;
485    ring r = 32003,(z,y,x), lp;
486    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
487    pwalk(I,2,3);     
488}
489
490
491proc twalk(ideal Go, list #)
492"SYNTAX: twalk(ideal i);
493         twalk(ideal i, intvec v, intvec w);
494TYPE:    ideal
495PURPOSE: compute the standard basis of the ideal w.r.t.
496         the ordering  \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\",
497         calculated via the Tran algorithm.
498SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2
499KEYWORDS: The Tran algorithm
500EXAMPLE: example twalk; shows an example"
501{
502  list L = OrderStringalp_NP("al", #);
503  int nP = L[1];
504 
505  /* we use ring with ordering (a(...),lp,C) */
506  string ord_str =   L[2];
507  intvec curr_weight   = L[3];
508  intvec target_weight =  L[4];
509  kill(L);
510   
511  option(redSB);
512  def xR = basering;
513 
514  execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";");
515  def old_ring = basering;
516   
517  //print("//** help ring = " + string(basering));
518  ideal G = fetch(xR, Go);
519  G = system("TranMImprovwalk", G, curr_weight, target_weight, nP);
520   
521  setring xR;
522   //kill(Go);
523
524   keepring basering;
525   ideal result = fetch(old_ring, G);
526   return (result);
527}
528example
529{
530    "EXAMPLE:"; echo = 2;
531    ring r = 32003,(z,y,x), lp;
532    ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z;
533    twalk(I);     
534}
Note: See TracBrowser for help on using the repository browser.