source: git/Singular/LIB/grwalk.lib @ 61fbaf

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