source: git/Singular/LIB/sagbi.lib @ c33727

fieker-DuValspielwiese
Last change on this file since c33727 was 453c2d, checked in by Viktor Levandovskyy <levandov@…>, 17 years ago
*levandov: replaced std with groebner, aux vars y through @y git-svn-id: file:///usr/local/Singular/svn/trunk@9510 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.6 KB
Line 
1//////////////////////////////////////////////////////////////////////////////
2version="$Id: sagbi.lib,v 1.5 2006-11-22 21:40:29 levandov Exp $";
3category="Commutative Algebra";
4info="
5LIBRARY:  SAGBI.lib  Compute Subalgebras bases Analogous to Groebner bases for ideals
6AUTHORS: Gerhard Pfister,        pfister@mathematik.uni-kl.de,
7@*       Anen Lakhal,            alakhal@mathematik.uni-kl.de
8
9PROCEDURES:
10 proc reduction(p,I);  Perform one step subalgebra reducton (for short S-reduction) of p w.r.t I
11 proc sagbiSPoly(I);   Compute the S-polynomilas of the Subalgebra defined by the genartors of I
12 proc sagbiNF(id,I);   Perform iterated S-reductions in order to compute Subalgebras normal forms
13 proc sagbi(I);        Construct SAGBI basis for the Subalgebra defined by I
14 proc sagbiPart(I);    Construct partial SAGBI basis for the Subalgebra defined by I
15";
16
17 LIB "algebra.lib";
18 LIB "elim.lib";
19
20///////////////////////////////////////////////////////////////////////////////
21proc sagbiSPoly(id ,list #)
22"USAGE: sagbiSPoly(id [,n]); id ideal, n positive integer.
23RETURN: an ideal
24@format
25      - If (n=0 or default) an ideal, whose generators are the S-polynomials.
26      - If (n=1) a  list of size 2:
27        the first element of this list is the ideal of S-polynomials.
28        the second element of this list is the ring in which is defined
29        the ideal of algebraic relations.
30@end format
31EXAMPLE: example sagbiSPoly; show an example "
32{
33  if(size(#)==0)
34    {
35      #[1]=0;
36    }
37  degBound=0;
38  def bsr=basering;
39  ideal vars=maxideal(1);
40  ideal B=ideal(bsr);//when the basering is quotient ring this "type casting"
41                    //gives th quotient ideal.
42  int b=size(B);
43
44
45  //In quotient rings,SINGULAR does not reduce polynomials w.r.t the
46  //quotient ideal,therefore we should first 'reduce';if it is necessary for
47  //computations to have a uniquely determined representant for each equivalent
48  //class,which is the case of this procedure.
49
50  if(b!=0)
51    {
52      id =reduce(id,groebner(0));
53    }
54  int n,m=nvars(bsr),ncols(id);
55  int z;
56  string mp=string(minpoly);
57  ideal P;
58  list L;
59
60  if(id==0)
61    {
62      if(#[1]==0)
63        {
64          return(P);
65        }
66      else
67        {
68          return(L);
69        }
70    }
71
72  else
73
74    {
75    //==================create anew ring with extra variables================
76
77      execute("ring R1="+charstr(bsr)+",("+varstr(bsr)+",@y(1..m)),(dp(n),dp(m));");
78      execute("minpoly=number("+mp+");");
79      ideal id=imap(bsr,id);
80      ideal A;
81
82      for(z=1;z<=m;z++)
83        {
84          A[z]=lead(id[z])-@y(z);
85        }
86
87      A=groebner(A);
88      ideal kern=nselect(A,1,n);// "kern" is the kernel of the ring map:
89                           // R1----->bsr ;y(z)----> lead(id[z]).
90                          //"kern" is the ideal of algebraic relations between
91                         // lead(id[z]).
92
93      export kern,A;// we export:* the ideal A  to avoid useless computations
94               //                  betwee 2 steps in sagbi procedure.
95              //                 *the ideal kern : some times we can get intresting
96             //                    informations from this ideal.
97
98      setring bsr;
99      map phi=R1,vars,id;
100
101      // the sagbiSPolynomials are the image by phi of the generators of kern
102
103      P=simplify(phi(kern),1);
104      if(#[1]==0)
105        {
106          return(P);
107        }
108      else
109        {
110          L=P,R1;
111          kill phi,vars;
112
113                 dbprint(printlevel-voice+3,"
114// 'sagbiSPoly' created a ring as 2nd element of the list.
115// The ring contains the ideal 'kern'  of algebraic relations between the
116//leading terms of the generators of I.
117// To access to this ring and see 'kern' you should give the ring a name,
118// e.g.:
119               def S = L[2]; setring S; kern;
120        ");
121                 return(L);
122        }
123
124    }
125}
126example
127{ "EXAMPLE:"; echo = 2;
128 ring r=0, (x,y),dp;
129 poly f1,f2,f3,f4=x2,y2,xy+y,2xy2;
130 ideal I=f1,f2,f3,f4;
131 sagbiSPoly(I);
132 list L=sagbiSPoly(I,1);
133 L[1];
134 def S= L[2]; setring S; kern;
135}
136
137
138///////////////////////////////////////////////////////////////////////////////
139static proc std1(ideal J,ideal I,list #)
140  // I is contained in J, and it is assumed to be a standard bases!
141  //This procedure computes a Standard basis for J from I one's
142  //This procedure is essential for Spoly1 procedure.
143{
144  def br=basering;
145  int tt;
146  ideal Res,@result;
147
148
149  if(size(#)>0)
150    {tt=#[1];}
151
152  if(size(I)==0)
153    {@result=groebner(J);}
154
155  if((size(I)!=0) && (size(J)-size(I)>=1))
156    {
157
158      qring Q=I;
159      ideal J=fetch(br,J);
160      J=groebner(J);
161      setring br;
162      Res=fetch(Q,J);// Res contains the generators that we add to I
163                      //to get the generators of std(J);
164      @result=Res+I;
165
166    }
167
168  if(tt==0)
169    {return(@result);}
170  else
171    {return(Res);}
172}
173
174///////////////////////////////////////////////////////////////////////////////
175
176static proc Spoly1(list l,ideal I,ideal J,int a)
177  //an implementation of SAGBI construction Algorithm using Spoly
178  //procedure leads to useless computations and affect the efficiency
179  //of SAGBI bases computations. This procedure is a variant of Spoly
180  //in order to avoid these useless compuations.
181{
182  degBound=0;
183  def br=basering;
184  ideal vars=maxideal(1);
185  ideal B=ideal(br);
186  int b=size(B);
187
188  if(b!=0)
189    {
190      I=reduce(I,groebner(0));
191      J=reduce(J,groebner(0));
192    }
193
194
195  int n,ii,jj=nvars(br),ncols(I),ncols(J);
196  int z;
197  list @L;
198  string mp =string(minpoly);
199
200  if(size(J)==0)
201    {
202      @L =sagbiSPoly(I,1);
203    }
204  else
205    {
206      ideal @sum=I+J;
207      ideal P1;
208      ideal P=l[1];//P is the ideal of spolynomials of I;
209      def R=l[2];setring R;int kk=nvars(R);
210      ideal J=fetch(br,J);
211
212
213
214      //================create a new ring with extra variables==============
215
216      execute("ring R1="+charstr(R)+",("+varstr(R)+",@y((ii+1)..(ii+jj))),(dp(n),dp(kk+jj-n));");
217      ideal kern1;
218      ideal A=fetch(R,A);
219      attrib(A,"isSB",1);
220      ideal J=fetch(R,J);
221      ideal kern=fetch(R,kern);
222      ideal A1;
223      for(z=1;z<=jj;z++)
224        {
225          A1[z]=lead(J[z])-var(z+kk);
226        }
227      A1=A+A1;
228      ideal @Res=std1(A1,A,1);//the generators of @Res are whose we have to add
229                             //to A to get std(A1).
230      A=A+@Res;
231      kern1=nselect(@Res,1,n);
232      kern=kern+kern1;
233      export kern,kern1,A;
234      setring br;
235      map phi=R1,vars,@sum;
236      P1=simplify(phi(kern1),1);//P1 is th ideal we add to P to get the ideal
237                                //of Spolynomials of @sum.
238      P=P+P1;
239
240      if (a==1)
241        {
242          @L=P,R1;
243          kill phi,vars;
244          dbprint(printlevel-voice+3,"
245// 'Spoly1' created a ring as 2nd element of the list.
246// The ring contains the ideal 'kern'  of algebraic relations between the
247//generators of I+J.
248// To access to this ring and see 'kern' you should give the ring a name,
249// e.g.:
250               def @ring = L[2]; setring @ring ; kern;
251        ");
252        }
253      if(a==2)
254        {
255          @L=P1,R1;
256          kill phi,vars;
257        }
258    }
259
260  return(@L);
261
262
263
264}
265///////////////////////////////////////////////////////////////////////////////
266
267proc reduction(poly p,ideal dom,list #)//one step Subalgebra reduction
268"USAGE: reduction(p,dom[,n]); p poly , dom  ideal
269RETURN: a polynomial
270@format
271    Three algorithm variants are used to perform subalgebra reduction.
272    The positive interger n determine which variant should be used.
273    n may take the values (0 or default),1 or 2.
274@end format
275EXAMPLE: reduction; show an example"
276{
277  def bsr=basering;
278  ideal B=ideal(bsr);//When the basering is quotient ring  this type casting
279                     // gives the quotient ideal.
280  int b=size(B);
281  int n=nvars(bsr);
282
283  //In quotient rings, SINGULAR, usually does not reduce polynomials w.r.t the
284  //quotient ideal,therefore we should first  reduce ,when it is necessary for computations,
285  // to have a uniquely determined representant for each equivalent
286  //class,which is the case of this algorithm.
287
288  if(b !=0) //means that the basering is a quotient ring
289    {
290      p=reduce(p,groebner(0));
291      dom=reduce(groebner,std(0));
292    }
293
294  int i,choose;
295  int z=ncols(dom);
296
297  if((size(#)>0) && (typeof(#[1])=="int"))
298    {
299      choose = #[1];
300    }
301  if (size(#)>1)
302    {
303      choose =#[2];
304    }
305
306  //=======================first algorithm(default)=========================
307   if ( choose == 0 )
308  {
309     list L = algebra_containment(lead(p),lead(dom),1);
310     if( L[1]==1 )
311     {
312  // the ring L[2] = char(bsr),(x(1..nvars(bsr)),y(1..z)),(dp(n),dp(m)),
313  // contains poly check s.t. LT(p) is of the form check(LT(f1),...,LT(fr))
314       def s1 = L[2];
315       map psi = s1,maxideal(1),dom;
316       poly re = p - psi(check);
317       // divide by the maximal power of #[1]
318          if ( (size(#)>0) && (typeof(#[1])=="poly") )
319
320            {  while ((re!=0) && (re!=#[1]) &&(subst(re,#[1],0)==0))
321             {
322               re=re/#[1];
323             }
324            }
325          return(re);
326     }
327  return(p);
328  }
329   //======================2end variant of algorithm=========================
330   //It uses two different commands for elimaination.
331   //if(choose==1):"elimainate"command.
332   //if (choose==2):"nselect" command.
333   else
334      {
335        poly v=product(maxideal(1));
336
337  //------------- change the basering bsr to bsr[@(0),...,@(z)] ----------
338  execute("ring s="+charstr(basering)+",("+varstr(basering)+",@(0..z)),dp;");
339// Ev hier die Reihenfolge der Vars aendern. Dazu muss unten aber entsprechend
340// geaendert werden:
341//  execute("ring s="+charstr(basering)+",(@(0..z),"+varstr(basering)+"),dp;");
342
343  //constructs the leading ideal of dom=(p-@(0),dom[1]-@(1),...,dom[z]-@(z))
344     ideal dom=imap(bsr,dom);
345     for (i=1;i<=z;i++)
346     {
347        dom[i]=lead(dom[i])-var(nvars(bsr)+i+1);
348     }
349     dom=lead(imap(bsr,p))-@(0),dom;
350
351      //---------- eliminate the variables of the basering bsr --------------
352  //i.e. computes dom intersected with K[@(0),...,@(z)].
353
354     if(choose==1)
355       {
356         ideal kern=eliminate(dom,imap(bsr,v));//eliminate does not need a
357                                              //standard basis as input.
358       }
359     if(choose==2)
360       {
361         ideal kern= nselect(groebner(dom),1,n);//"nselect" is combinatorial command
362                                         //which uses the internal command
363                                        // "simplify"
364       }
365
366  //---------  test wether @(0)-h(@(1),...,@(z)) is in ker ---------------
367  // for some poly h and divide by maximal power of q=#[1]
368     poly h;
369     z=size(kern);
370     for (i=1;i<=z;i++)
371     {
372        h=kern[i]/@(0);
373        if (deg(h)==0)
374        {  h=(1/h)*kern[i];
375        // define the map psi : s ---> bsr defined by @(i) ---> p,dom[i]
376           setring bsr;
377           map psi=s,maxideal(1),p,dom;
378           poly re=psi(h);
379           // divide by the maximal power of #[1]
380           if ((size(#)>0) && (typeof(#[1])== "poly") )
381           {  while ((re!=0) && (re!=#[1]) &&(subst(re,#[1],0)==0))
382              {  re=re/#[1];
383              }
384           }
385           return(re);
386        }
387     }
388     setring bsr;
389     return(p);
390  }
391
392
393}
394example
395{"EXAMPLE:"; echo = 2;
396  ring r= 0,(x,y),dp;
397  ideal dom =x2,y2,xy-y;
398  poly p=x4+x3y+xy2-y2;
399  reduction(p,dom);
400  reduction(p,dom,1);
401  reduction(p,dom,2);
402}
403
404///////////////////////////////////////////////////////////////////////////////
405static proc completeReduction(poly p,ideal dom,list#)//reduction
406{
407  poly p1=p;
408  poly p2=reduction(p,dom,#);
409  while (p1!=p2)
410  {
411    p1=p2;
412    p2=reduction(p1,dom,#);
413  }
414  return(p2);
415}
416///////////////////////////////////////////////////////////////////////////////
417
418static proc completeReduction1(poly p,ideal dom,list #) //tail reduction
419{
420  poly p1,p2,re;
421  p1=p;
422  while(p1!=0)
423    {
424      p2=reduction(p1,dom,#);
425      if(p2!=p1)
426        {
427          p1=p2;
428        }
429      else
430        {
431          re=re+lead(p2);
432          p1=p2-lead(p2);
433        }
434    }
435  return(re);
436}
437
438
439
440///////////////////////////////////////////////////////////////////////////////
441
442proc sagbiNF(id,ideal dom,int k,list#)
443"USAGE: sagbiNF(id,dom,k[,n]); id either poly or ideal,dom ideal, k and n positive intergers.
444RETURN: depends On the type of id; ideal or polynomial.
445@format
446    The integer k determine waht kind of s-reduction is performad:
447    - if (k=0) no tail s-reduction is performaed.
448    - if (k=1) tail s-reduction is perofrmed.
449    Three Algorthim  variants  are used to perform Subalgebra reduction.
450    The positive integer n determine which variant should be used.
451    n may take the values (0 or default),1 or 2.
452@end format
453NOTE: computation of Subalgebras normal forms may be performed either
454      in polynomial rings or quotient polynomial rings
455EXAMPLE: example sagbiNF; show example "
456{
457  int z;
458  ideal Red;
459  poly re;
460  if(typeof(id)=="ideal")
461    {
462      int i=ncols(id);
463      for(z=1;z<=i;z++)
464    {
465      if(k==0)
466        {
467
468          id[z]=completeReduction(id[z],dom,#);
469        }
470      else
471        {
472          id[z]=completeReduction1(id[z],dom,#);//tail reduction.
473        }
474    }
475  Red=simplify(id,7);
476  return(Red);
477    }
478  if(typeof(id)=="poly")
479    {
480      if(k==0)
481        {
482          re=completeReduction(id,dom,#);
483        }
484      else
485        {
486          re=completeReduction1(id,dom,#);
487        }
488      return(re);
489    }
490}
491example
492{"EXAMPLE:"; echo = 2;
493 ring r=0,(x,y),dp;
494 ideal I= x2-xy;
495 qring Q=std(I);
496 ideal dom =x2,x2y+y,x3y2;
497 poly p=x4+x2y+y;
498 sagbiNF(p,dom,0);
499 sagbiNF(p,dom,1);// tail subalgebra reduction is perofrmed
500}
501
502
503///////////////////////////////////////////////////////////////////////////////
504
505static proc intRed(id,int k, list #)
506{
507  int i,z;
508  ideal Rest,intRed;
509  z=ncols(id);
510  for(i=1;i<=z;i++)
511    {
512      Rest=id;
513      Rest[i]=0;
514      Rest=simplify(Rest,2);
515      if(k==0)
516        {
517          intRed[i]=completeReduction(id[i],Rest,#);
518        }
519      else
520        {
521          intRed[i]=completeReduction1(id[i],Rest,#);
522        }
523    }
524  intRed=simplify(intRed,7);//1+2+4 in simplify command
525  return(intRed);
526
527}
528//////////////////////////////////////////////////////////////////////////////
529
530proc sagbi(id,int k,list#)
531"USAGE: sagbi(id,k[,n]); id ideal, k and n positive integer.
532RETURN: A SAGBI basis for the subalgebra defined by the generators of id.
533@format
534    k determine waht kind of s-reduction is performad:
535     - if (k=0) no tail s-reduction is performaed.
536     - if (k=1) tail s-reduction is perofrmed, and S-intereduced SAGBI basis
537       is returned.
538    Three Algorthim  variants  are used to perform Subalgebra reduction.
539    The positive interger n determine which variant should be used.
540    n may take the values (0 or default),1 or 2.
541@end format
542NOTE: SAGBI bases computations may be performed either
543      in polynomial rings or quotient polynomial rings.
544EXAMPLE: example sagbi; show example "
545{
546  degBound=0;
547  ideal S,oldS,Red;
548  list L;
549  S=intRed(id,k,#);
550  while(size(S)!=size(oldS))
551    {
552      L=Spoly1(L,S,Red,2);
553      Red=L[1];
554      Red=sagbiNF(Red,S,k,#);
555      oldS=S;
556      S=S+Red;
557    }
558  return(S);
559}
560example
561{ "EXAMPLE:"; echo = 2;
562 ring r= 0,(x,y),dp;
563 ideal I=x2,y2,xy+y;
564 sagbi(I,1,1);
565}
566///////////////////////////////////////////////////////////////////////////////
567proc sagbiPart(id,int k,int c,list #)
568"USAGE: sagbi(id,k,c[,n]); id ideal, k, c and n positive integer.
569RETURN: A partial SAGBI basis for the subalgebra defined by the genrators of id.
570@format
571     should stop.k determine waht kind of s-reduction is performad:
572     - if (k=0) no tail s-reduction is performaed.
573     - if (k=1) tail s-reduction is perofrmed, and S-intereduced SAGBI basis
574      is returned.
575     c  determine; after which turn Sagbi basis computations should stop
576     Three Algorthim  variants  are used to perform Subalgebra reduction.
577     The positive interger n determine which variant should be used.
578     n may take the values (0 or default),1 or 2.
579@end format
580NOTE:- SAGBI bases computations may be performed either
581       in polynomial rings or quotient polynomial rings.
582     - This version of sagbi procedure is interesting in the case of an Subalgebras
583       with infinte SAGBI basis. In this case, by means of this procedure,
584       we may check for example, if the elements of this basis have a particular form.
585EXAMPLE: example sagbiPart; show example "
586{
587  degBound=0;
588  ideal S,oldS,Red;
589  int counter;
590  list L;
591  S=intRed(id,k,#);
592  while((size(S)!=size(oldS))&&(counter<=c))
593    {
594      L=Spoly1(L,S,Red,2);
595      Red=L[1];
596      Red=sagbiNF(Red,S,k,#);
597      oldS=S;
598      S=S+Red;
599      counter=counter+1;
600    }
601  return(S);
602}
603example
604{ "EXAMPLE:"; echo = 2;
605 ring r= 0,(x,y),dp;
606 ideal I=x,xy-y2,xy2;//the corresponding Subalgebra has an infinte SAGBI basis
607 sagbiPart(I,1,3);// computations should stop after 3 turns.
608}
609//////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.