source: git/Singular/LIB/swalk.lib @ 4c20ee

spielwiese
Last change on this file since 4c20ee was 4c20ee, checked in by Hans Schoenemann <hannes@…>, 11 years ago
fix: new version numbers for libs
  • Property mode set to 100644
File size: 14.5 KB
Line 
1//
2version="version swalk.lib 4.0.0.0 Jun_2013 ";
3category="Commutative Algebra";
4info="
5LIBRARY: swalk.lib               Sagbi Walk Conversion Algorithm
6AUTHOR:  Junaid Alam Khan        junaidalamkhan@gmail.com
7
8OVERVIEW:
9 A library for computing the Sagbi basis of subalgebra through Sagbi walk
10 algorithm.
11
12THEORY: The concept of SAGBI ( Subalgebra Analog to Groebner Basis for Ideals)
13 is defined in [L. Robbiano, M. Sweedler: Subalgebra Bases, volume 42, volume
14 1430 of Lectures Note in Mathematics series, Springer-Verlag (1988),61-87].
15 The Sagbi Walk algorithm is the subalgebra analogue to the Groebner Walk
16 algorithm which has been proposed in [S. Collart, M. Kalkbrener and D.Mall:
17 Converting bases with the Grobner Walk. J. Symbolic Computation 24 (1997),
18 465-469].
19
20PROCEDURE:
21 swalk(ideal[,intvec]);   Sagbi basis of subalgebra via Sagbi walk algorithm
22";
23
24LIB "sagbi.lib";
25//////////////////////////////////////////////////////////////////////////////
26proc swalk(ideal Gox, list #)
27"USAGE:  swalk(i[,v,w]); i ideal, v,w int vectors
28RETURN: The sagbi basis of the subalgebra defined by the generators of i,
29        calculated via the Sagbi walk algorithm from the ordering dp to lp
30        if v,w are not given (resp. from the ordering (a(v),lp) to the
31        ordering (a(w),lp) if v and w are given).
32EXAMPLE: example swalk; shows an example
33"
34{
35  /* we use ring with ordering (a(...),lp,C) */
36  list OSCTW    = OrderStringalp_NP("al", #);//"dp"
37  string ord_str =   OSCTW[2];
38  intvec icurr_weight   =   OSCTW[3]; /* original weight vector */
39  intvec itarget_weight =   OSCTW[4]; /* terget weight vector */
40  kill OSCTW;
41  option(redSB);
42  def xR = basering;
43  list rl=ringlist(xR);
44  rl[3][1][1]="dp";
45  def ostR=ring(rl);
46  setring ostR;
47  def new_ring = basering;
48  ideal Gnew = fetch(xR, Gox);
49  Gnew=sagbi(Gnew,1);
50  Gnew=interreduceSd(Gnew);
51  vector curr_weight=changeTypeInt(icurr_weight);
52  vector target_weight=changeTypeInt(itarget_weight);
53  ideal Gold;
54  list l;
55  intvec v;
56  int n=0;
57  while(n==0)
58    {
59       Gold=Gnew;
60       def old_ring=new_ring;
61       setring old_ring;
62       number ulast;
63       kill new_ring;
64       if(curr_weight==target_weight){n=1;}
65       else {
66              l=collectDiffExpo(Gold);
67              ulast=last(curr_weight, target_weight, l);
68              vector new_weight=(1-ulast)*curr_weight+ulast*target_weight;
69              vector w=cleardenom(new_weight);
70              v=changeType(w);
71              list p= ringlist(old_ring);
72              p[3][1][2]= v;
73              def new_ring=ring(p);
74              setring new_ring;
75              ideal Gold=fetch(old_ring,Gold);
76              vector curr_weight=fetch(old_ring,new_weight);
77              vector target_weight=fetch(old_ring,target_weight);
78              kill old_ring;
79              ideal Gnew=Convert(Gold);
80              Gnew=interreduceSd(Gnew);
81           }
82    }
83   setring xR;
84   ideal result = fetch(old_ring, Gnew);
85   attrib(result,"isSB",1);
86   return (result);
87}
88example
89{
90  "EXAMPLE:";echo = 2;
91  ring r = 0,(x,y), lp;
92  ideal I =x2,y2,xy+y,2xy2+y3;
93  swalk(I);
94}
95
96//////////////////////////////////////////////////////////////////////////////
97static proc inprod(vector v,vector w)
98"USAGE:  inprod(v,w); v,w vectors
99RETURN:  inner product of vector v and w
100EXAMPLE: example inprod; shows an example
101"
102{
103  poly a;
104  int i;
105  for(i=1;i<=nvars(basering);i++)
106    {
107      a=a+v[i]*w[i] ;
108    }
109  return(a);
110}
111example
112{ "EXAMPLE:"; echo = 2;
113   ring r=0,(x,y,z),lp;
114   vector v =[1,-1,2];
115   vector w = [1,0,3];
116   inprod(v,w);
117}
118
119//////////////////////////////////////////////////////////////////////////////
120static proc diffExpo(poly f)
121"USAGE:  diffExpo(f); f polynomial
122RETURN:  a list of integers vectors which are the difference of exponent
123         vector of leading monomial of f with the exponent vector of of other
124         monmials in f.
125EXAMPLE: example diffExpo; shows an example
126"
127{
128  list l;
129  int i;
130  intvec v;
131  for(i=size(f);i>=2;i--)
132   {
133     v=leadexp(f[1])-leadexp(f[i]);
134     l[i-1]=v;
135   }
136 return(l);
137}
138example
139{ "EXAMPLE:"; echo = 2;
140   ring r=0,(x,y,z),lp;
141   poly f = xy+z2 ;
142   diffExpo(f);
143}
144
145//////////////////////////////////////////////////////////////////////////////
146static proc collectDiffExpo( ideal i)
147"USAGE:  collectDiffExpo(i); i ideal
148RETURN:  a list which contains diffExpo(f), for all generators f of ideal i
149EXAMPLE: example collectDiffExpo; shows an example
150"
151{
152 list l;
153 int j;
154 for(j=ncols(i); j>=1;j--)
155  {
156   l[j]=diffExpo(i[j]);
157  }
158  return(l);
159}
160example
161{ "EXAMPLE:"; echo = 2;
162   ring r=0,(x,y,z),lp;
163   ideal I = xy+z2,y3+x2y2;
164   collectDiffExpo(I);
165}
166
167//////////////////////////////////////////////////////////////////////////////
168static proc changeType(vector v)
169"USAGE:  changeType(v); v  vector
170RETURN:  change the type of  vector
171         v into integer vector.
172
173EXAMPLE: example changeType; shows an example
174"
175{
176  intvec w ;
177  int j ;
178  for(j=1;j<=nvars(basering);j++)
179   {
180     w[j]=int(leadcoef(v[j]));
181   }
182  return(w);
183}
184example
185{ "EXAMPLE:"; echo = 2;
186   ring r=0,(x,y,z),lp;
187   vector v = [2,1,3];
188   changeType(v);
189}
190//////////////////////////////////////////////////////////////////////////////
191static proc changeTypeInt( intvec v)
192"USAGE:  changeTypeInt(v); v integer vector
193RETURN:  change the type of integer vector v into vector.
194EXAMPLE: example changeTypeInt; shows an example
195"
196{
197   vector w;
198   int j ;
199   for(j=1;j<=size(v);j++)
200   {
201     w=w+v[j]*gen(j);
202   }
203   return(w);
204}
205example
206{ "EXAMPLE:"; echo = 2;
207   ring r=0,(x,y,z),lp;
208   intvec v = 4,2,3;
209   changeTypeInt(v);
210}
211
212//////////////////////////////////////////////////////////////////////////////
213static proc last( vector c, vector t,list l)
214"USAGE: last(c,t,l); c,t vectors, l list
215RETURN: a  parametric value which corresponds to vector lies along the path
216        between c and t using list l of integer vectors. This vector is the
217        last vector on old Sagbi cone
218EXAMPLE: example last; shows an example
219"
220{
221 number ul=1;
222 int i,j,k;
223 number u;
224 vector v;
225 for(i=1;i<=size(l);i++)
226 {
227    for(j=1;j<=size(l[i]);j++)
228    {
229        v=0;
230        for(k=1;k<=size(l[i][j]);k++)
231        {
232            v=v+l[i][j][k]*gen(k);
233        }
234        poly n= inprod(c,v);
235        poly q= inprod(t,v);
236        number a=leadcoef(n);
237        number b=leadcoef(q);
238        number z=a-b;
239        if(b<0)
240        {
241            u=a/z;
242            if(u<ul) {ul=u;}
243        }
244        kill a,b,z,n,q ;
245    }
246 }
247 return(ul);
248}
249example
250{ "EXAMPLE:"; echo = 2;
251   ring r=0,(x,y,z),(a(0,0,1),lp);
252   vector v= [0,0,1];
253   vector w=[1,0,0];
254   ideal i=z2+xy,x2y2+y3;
255    list l=collectDiffExpo(i);
256    last(v,w,l)
257}
258
259//////////////////////////////////////////////////////////////////////////////
260static proc initialForm(poly P)
261"USAGE:  initialForm(P); P polynomial
262RETURN:  sum of monomials of P with maximum w-degree
263         where w is first row of matrix of a given monomial ordering
264EXAMPLE: example initialForm; shows an example
265"
266{
267 poly q;
268 int i=1;
269 while(deg(P[i])==deg(P[1]))
270 {
271     q=q+P[i];
272     i++;
273     if(i>size(P)) {break;}
274 }
275 return(q);
276}
277example
278{ "EXAMPLE:"; echo = 2;
279   ring r=0,(x,y,z),dp;
280   poly f = x2+yz+z;
281   initialForm(f);
282}
283
284//////////////////////////////////////////////////////////////////////////////
285static proc Initial(ideal I)
286"USAGE:  Initial(I); I ideal
287RETURN:  an ideal which is generate by the InitialForm
288         of the generators of I.
289EXAMPLE: example Initial; shows an example
290"
291{
292 ideal J;
293 int i;
294 for(i=1;i<=ncols(I);i++)
295 {
296     J[i]=initialForm(I[i]);
297 }
298 return(J);
299}
300example
301{ "EXAMPLE:"; echo = 2;
302   ring r=0,(x,y,z),dp;
303   ideal I = x+1,x+y+1;
304   Initial(I);
305}
306
307//////////////////////////////////////////////////////////////////////////////
308static proc Lift(ideal In,ideal InG,ideal Gold)
309"USAGE:  Lift(In, InG, Gold); In, InG, Gold ideals;
310         Gold given by Sagbi basis {g_1,...,g_t},
311         In given by tne initial forms In(g_1),...,In(g_t),
312         InG = {h_1,...,h_s} a Sagbi basis of In
313RETURN:  P_j, a polynomial in K[y_1,..,y_t] such that h_j =
314         P_j(In(g_1),...,In_(g_t))
315         and return f_j = P_j(g_1,...,g_t)
316EXAMPLE: example Lift; shows an example
317"
318{
319  int i;
320  ideal J;
321  for(i=1;i<=ncols(InG);i++)
322  {
323    poly f=InG[i];
324    list l=algebra_containment(f,In,1);
325    def s=l[2];
326    map F=s,maxideal(1),Gold ;
327    poly g=F(check);
328    ideal k=g;
329    J=J+k;
330    kill g,l,s,F,f,k;
331  }
332  return(J);
333 }
334example
335{ "EXAMPLE:"; echo = 2;
336   ring r=0,(x,y,z),(a(2,0,3),lp);
337   ideal In = xy+z2,x2y2;
338   ideal InG=xy+z2,x2y2,xyz2+1/2z4;
339   ideal Gold=xy+z2,y3+x2y2;
340   Lift(In,InG,Gold);
341}
342
343//////////////////////////////////////////////////////////////////////////////
344static proc Convert( ideal Gold )
345"USAGE: Convert(I); I ideal
346RETURN: Convert old Sagbi basis into new Sagbi basis
347EXAMPLE: example Convert; shows an example
348"
349{
350 ideal In=Initial(Gold);
351 ideal InG=sagbi(In,1)+In;
352 ideal Gnew=Lift(In,InG,Gold);
353 return(Gnew);
354}
355example
356{ "EXAMPLE:"; echo = 2;
357   ring r=0,(x,y,z),lp;
358   ideal I=xy+z2, y3+x2y2;
359   Convert(I);
360}
361
362//////////////////////////////////////////////////////////////////////////////
363static proc interreduceSd(ideal I)
364"USAGE:  interreduceSd(I); I ideal
365RETURN:  interreduceSd the set of generators if I with
366         respect to a given term ordering
367EXAMPLE: example interreduceSd; shows an example
368"
369{
370  list l,M;
371  ideal J,B;
372  int i,j,k;
373  poly f;
374  for(k=1;k<=ncols(I);k++)
375  {l[k]=I[k];}
376  for(j=1;j<=size(l);j++)
377  {
378     f=l[j];
379     M=delete(l,j);
380     for(i=1;i<=size(M);i++)
381     { B[i]=M[i];}
382     f=sagbiNF(f,B,1);
383     J=J+f;
384  }
385  return(J);
386}
387example
388{ "EXAMPLE:"; echo = 2;
389   ring r=0,(x,y,z),lp;
390   ideal I = xy+z2,x2y2+y3;
391   interreduceSd(I);
392}
393
394//////////////////////////////////////////////////////////////////////////////
395static proc OrderStringalp(string Wpal,list #)
396{
397  int n= nvars(basering);
398  string order_str;
399  intvec curr_weight, target_weight;
400  curr_weight = system("Mivdp",n);
401  target_weight = system("Mivlp",n);
402
403   if(size(#) != 0)
404   {
405     if(size(#) == 1)
406     {
407       if(typeof(#[1]) == "intvec")
408       {
409         if(Wpal == "al"){
410           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
411         }
412         else {
413           order_str = "(Wp("+string(#[1])+"),C)";
414         }
415         curr_weight = #[1];
416       }
417       else
418       {
419        if(typeof(#[1]) == "string")
420        {
421          if(#[1] == "Dp") {
422            order_str = "Dp";
423          }
424          else {
425            order_str = "dp";
426          }
427        }
428        else {
429          order_str = "dp";
430        }
431     }
432    }
433    else
434    {
435     if(size(#) == 2)
436     {
437       if(typeof(#[2]) == "intvec")
438       {
439         target_weight = #[2];
440       }
441       if(typeof(#[1]) == "intvec")
442       {
443         if(Wpal == "al"){
444           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
445         }
446         else {
447           order_str = "(Wp("+string(#[1])+"),C)";
448         }
449         curr_weight = #[1];
450       }
451       else
452       {
453        if(typeof(#[1]) == "string")
454        {
455          if(#[1] == "Dp") {
456            order_str = "Dp";
457           }
458           else {
459              order_str = "dp";
460           }
461        }
462        else {
463           order_str = "dp";
464        }
465      }
466     }
467    }
468   }
469   else {
470     order_str = "dp";
471   }
472   list result;
473   result[1] = order_str;
474   result[2] = curr_weight;
475   result[3] = target_weight;
476   return(result);
477}
478
479//////////////////////////////////////////////////////////////////////////////
480static proc OrderStringalp_NP(string Wpal,list #)
481{
482  int n= nvars(basering);
483  string order_str = "dp";
484  int nP = 1;// call LatsGB to compute the wanted GB  by pwalk
485  intvec curr_weight = system("Mivdp",n); //define (1,1,...,1)
486  intvec target_weight = system("Mivlp",n); //define (1,0,...,0)
487  if(size(#) != 0)
488  {
489    if(size(#) == 1)
490    {
491      if(typeof(#[1]) == "intvec")
492      {
493        curr_weight = #[1];
494
495        if(Wpal == "al")
496        {
497          order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
498        }
499        else
500        {
501          order_str = "(Wp("+string(#[1])+"),C)";
502        }
503      }
504      else {
505        if(typeof(#[1]) == "int")
506        {
507          nP = #[1];
508        }
509        else
510        {
511          print("// ** the input must be \"(ideal, int)\" or ");
512          print("// **                   \"(ideal, intvec)\"");
513          print("// ** a lex. GB will be computed from \"dp\" to \"lp\"");
514        }
515      }
516    }
517    else
518    {
519     if(size(#) == 2)
520     {
521       if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int")
522       {
523         curr_weight = #[1];
524
525         if(Wpal == "al")
526         {
527           order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
528         }
529         else
530         {
531           order_str = "(Wp("+string(#[1])+"),C)";
532         }
533       }
534       else
535       {
536         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec")
537         {
538           curr_weight = #[1];
539           target_weight = #[2];
540
541           if(Wpal == "al")
542           {
543             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
544           }
545           else
546           {
547             order_str = "(Wp("+string(#[1])+"),C)";
548           }
549         }
550         else
551         {
552           print("// ** the input  must be \"(ideal,intvec,int)\" or ");
553           print("// **                    \"(ideal,intvec,intvec)\"");
554           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
555         }
556       }
557     }
558     else {
559       if(size(#) == 3)
560       {
561         if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and
562            typeof(#[3]) == "int")
563         {
564           curr_weight = #[1];
565           target_weight = #[2];
566           nP = #[3];
567           if(Wpal == "al")
568           {
569             order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)";
570           }
571           else
572           {
573             order_str = "(Wp("+string(#[1])+"),C)";
574           }
575         }
576         else
577         {
578           print("// ** the input must be \"(ideal,intvec,intvec,int)\"");
579           print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
580
581         }
582       }
583       else
584       {
585         print("// ** The given input is wrong");
586         print("// ** and a lex. GB will be computed from \"dp\" to \"lp\"");
587       }
588     }
589    }
590  }
591  list result;
592  result[1] = nP;
593  result[2] = order_str;
594  result[3] = curr_weight;
595  result[4] = target_weight;
596  return(result);
597}
598
599///////////////////////////////////////////////////////////////////////////////*
600Further examples
601ring r=0,(x,y,z),lp;
602
603ideal I=x2y4, y4z2, xy4z+y2z, xy6z2+y10z5;
604
605ideal Q=x2y4, y4z2, xy4z+y2z, xy6z2+y14z7;
606
607ideal J=x2y4, y4z2, xy4z+y2z, xy6z2+y18z9;
608
609ideal K=x2,y2,xy+y,2xy2+y5,z3+x;
610
611ideal L=x2+y,y2+z,x+z2;
612*/
613
614
Note: See TracBrowser for help on using the repository browser.