source: git/Singular/LIB/poly.lib @ 4508b59

fieker-DuValspielwiese
Last change on this file since 4508b59 was 4508b59, checked in by Viktor Levandovskyy <levandov@…>, 19 years ago
*levandov: procs, moved from noncomm libs git-svn-id: file:///usr/local/Singular/svn/trunk@8232 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 32.8 KB
RevLine 
[3d124a7]1///////////////////////////////////////////////////////////////////////////////
[4508b59]2version="$Id: poly.lib,v 1.37 2005-05-18 18:07:51 levandov Exp $";
[49998f]3category="General purpose";
[5480da]4info="
[8942a5]5LIBRARY:  poly.lib      Procedures for Manipulating Polys, Ideals, Modules
6AUTHORS:  O. Bachmann, G.-M: Greuel, A. Fruehbis
[3d124a7]7
[f34c37c]8PROCEDURES:
[6f2edc]9 cyclic(int);           ideal of cyclic n-roots
[82716e]10 katsura([i]);          katsura [i] ideal
[6f2edc]11 freerank(poly/...)     rank of coker(input) if coker is free else -1
12 is_zero(poly/...);     int, =1 resp. =0 if coker(input) is 0 resp. not
[927ed62]13 lcm(ideal);            lcm of given generators of ideal
[11dddeb]14 maxcoef(poly/...);     maximal length of coefficient occurring in poly/...
[3d124a7]15 maxdeg(poly/...);      int/intmat = degree/s of terms of maximal order
[6f2edc]16 maxdeg1(poly/...);     int = [weighted] maximal degree of input
[3d124a7]17 mindeg(poly/...);      int/intmat = degree/s of terms of minimal order
[6f2edc]18 mindeg1(poly/...);     int = [weighted] minimal degree of input
[3d124a7]19 normalize(poly/...);   normalize poly/... such that leading coefficient is 1
[839b04d]20 rad_con(p,I);          check radical containment of poly p in ideal I
[1caa72]21 content(f);            content of polynomial/vector f
[9b8feed]22 numerator(n);          numerator of number n
23 denominator(n)         denominator of number n
[590998]24 mod2id(M,iv);          conversion of a module M to an ideal
25 id2mod(i,iv);          conversion inverse to mod2id
[11dddeb]26 substitute(I,...)      substitute in I variables by polynomials
[590998]27 subrInterred(i1,i2,iv);interred w.r.t. a subset of variables
[4508b59]28 newtonDiag(f);         Newton diagram of a polynomial
29 hilbPoly(I);           Hilbert polynomial of basering/I
[1caa72]30          (parameters in square brackets [] are optional)
[4508b59]31
[5480da]32";
[839b04d]33
[3d124a7]34LIB "general.lib";
[5ae5d9]35LIB "ring.lib";
[3d124a7]36///////////////////////////////////////////////////////////////////////////////
[11dddeb]37static proc bino(int a, int b)
38{
39//computes binomial var(1)+a over b
40   int i;
41   if(b==0){return(1);}
42   poly p=(var(1)+a)/b;
43   for(i=1;i<=b-1;i++)
44   {
45      p=p*(var(1)+a-i)/i;
46   }
47   return(p);
48}
49
50proc hilbPoly(ideal I)
51"USAGE: hilbPoly(I) I a homogeneous ideal
52RETURN: the Hilbert polynomial of basering/I as an intvec v=v_0,...,v_r
53        such that the Hilbert polynomial is (v_0+v_1*t+...v_r*t^r)/r!
54EXAMPLE: example hilbPoly; shows an example
55"
56{
57   def R=basering;
58   if(!attrib(I,"isSB")){I=std(I);}
59   intvec v=hilb(I,2);
60   int s=dim(I);
61   intvec hp;
62   if(s==0){return(hp);}
63   int d=size(v)-2;
64   ring S=0,t,dp;
65   poly p=v[1+d]*bino(s-1-d,s-1);
66   int i;
67   for(i=1;i<=d;i++)
68   {
69      p=p+v[d-i+1]*bino(s-1-d+i,s-1);
70   }
71   int n=1;
72   for(i=2;i<=s-1;i++){n=n*i;}
73   p=n*p;
74   for(i=1;i<=s;i++)
75   {
76      hp[i]=int(leadcoef(p[s-i+1]));
77   }
78   setring R;
79   return(hp);
80}
81example
82{ "EXAMPLE:"; echo = 2;
83   ring r = 0,(b,c,t,h),dp;
84   ideal I=
85   bct-t2h+2th2+h3,
86   bt3-ct3-t4+b2th+c2th-2bt2h+2ct2h+2t3h-bch2-2bth2+2cth2+2th3,
87   b2c2+bt2h-ct2h-t3h+b2h2+2bch2+c2h2-2bth2+2cth2+t2h2-2bh3+2ch3+2th3+3h4,
88   c2t3+ct4-c3th-2c2t2h-2ct3h-t4h+bc2h2-2c2th2-bt2h2+4t3h2+2bth3-2cth3-t2h3
89   +bh4-6th4-2h5;
90   hilbPoly(I);
91}
92
93///////////////////////////////////////////////////////////////////////////////
94proc substitute (I,list #)
95"USAGE:  - case 1: typeof(#[1])==poly:
[3c4dcc]96           substitute (I,v,f[,v1,f1,v2,f2,...]); I object of basering which
[11dddeb]97           can be mapped, v,v1,v2,.. ring variables, f,f1,f2,... poly
98@*       - case 2: typeof(#[1])==ideal:
99           substitute1 (I,v,f); I object of basering which can be mapped,
100           v ideal of ring variables, f ideal
[3c4dcc]101RETURN:  object of same type as I,
[11dddeb]102@*       - case 1: ring variable v,v1,v2,... substituted by polynomials
103           f,f1,f2,..., in this order
104@*       - case 2: ring variables in v substituted by polynomials in f:
105           v[i] is substituted by f[i], i=1,...,i=min(size(v),ncols(f))
106NOTE:    this procedure extends the built-in command subst which substitutes
107         ring variables only by monomials
108EXAMPLE: example substitute; shows an example
109"
[3d124a7]110
[11dddeb]111{
112   def bas = basering;
113   ideal m = maxideal(1);
114   int i,ii;
115   if(typeof(#[1])=="poly")
116   {
117     poly v = #[1];
118     poly f = #[2];
119     map phi = bas,m;
120     def J = I;
121     for (ii=1; ii<=size(#) - 1; ii=ii+2)
122     {
123        m = maxideal(1);
124        i=rvar(#[ii]);
125        m[i] = #[ii+1];
126        phi = bas,m;
127        J = phi(J);
128     }
129     return(J);
130   }
131   if(typeof(#[1])=="ideal")
132   {
133     ideal v = #[1];
134     ideal f = #[2];
[3c4dcc]135     int mi = size(v);
[11dddeb]136     if(ncols(f)<mi)
137     {
138        mi = ncols(f);
139     }
140     m[rvar(v[1])]=f[1];
141     map phi = bas,m;
142     def J = phi(I);
143     for (ii=2; ii<=mi; ii++)
144     {
145        m = maxideal(1);
146        m[rvar(v[ii])]=f[ii];
147        phi = bas,m;
148        J = phi(J);
149     }
[3c4dcc]150     return(J);
[11dddeb]151   }
152}
153example
154{ "EXAMPLE:"; echo = 2;
155   ring r = 0,(b,c,t),dp;
156   ideal I = -bc+4b2c2t,bc2t-5b2c;
157   substitute(I,c,b+c,t,0,b,b-1);
158   ideal v = c,t,b;
159   ideal f = b+c,0,b-1;
160   substitute(I,v,f);
[3c4dcc]161}
[11dddeb]162///////////////////////////////////////////////////////////////////////////////
[6f2edc]163proc cyclic (int n)
[d2b2a7]164"USAGE:   cyclic(n);  n integer
[6f2edc]165RETURN:  ideal of cyclic n-roots from 1-st n variables of basering
166EXAMPLE: example cyclic; shows examples
[d2b2a7]167"
[6f2edc]168{
169//----------------------------- procedure body --------------------------------
170   ideal m = maxideal(1);
171   m = m[1..n],m[1..n];
172   int i,j;
173   ideal s; poly t;
174   for ( j=0; j<=n-2; j=j+1 )
175   {
176      t=0;
177      for( i=1;i<=n;i=i+1 ) { t=t+product(m,i..i+j); }
178      s=s+t;
179   }
180   s=s,product(m,1..n)-1;
181   return (s);
182}
183//-------------------------------- examples -----------------------------------
184example
185{ "EXAMPLE:"; echo = 2;
186   ring r=0,(u,v,w,x,y,z),lp;
187   cyclic(nvars(basering));
188   homog(cyclic(5),z);
189}
190///////////////////////////////////////////////////////////////////////////////
191
[599bc9]192proc katsura
[908d5a0]193"USAGE: katsura([n]): n integer
[917fb5]194RETURN: katsura(n) : n-th katsura ideal of
[8942a5]195         (1) newly created and set ring (32003, x(0..n), dp), if
196             nvars(basering) < n
197         (2) basering, if nvars(basering) >= n
[82716e]198        katsura()  : katsura ideal of basering
[599bc9]199EXAMPLE: example katsura; shows examples
[d2b2a7]200"
[599bc9]201{
[908d5a0]202  int n;
[599bc9]203  if ( size(#) == 1 && typeof(#[1]) == "int")
204  {
[908d5a0]205    n = #[1] - 1;
206    while (1)
207    {
208      if (defined(basering))
209      {
210        if (nvars(basering) >= #[1]) {break;}
211      }
212      ring katsura_ring = 32003, x(0..#[1]), dp;
213      keepring katsura_ring;
214      break;
215    }
216  }
217  else
218  {
219    n = nvars(basering) -1;
[599bc9]220  }
[917fb5]221
[599bc9]222  ideal s;
223  int i, j;
224  poly p;
[82716e]225
[599bc9]226  p = -1;
227  for (i = -n; i <= n; i++)
228  {
229    p = p + kat_var(i, n);
230  }
231  s[1] = p;
[82716e]232
[599bc9]233  for (i = 0; i < n; i++)
234  {
235    p = -1 * kat_var(i,n);
236    for (j = -n; j <= n; j++)
237    {
238      p = p + kat_var(j,n) * kat_var(i-j, n);
239    }
240    s = s,p;
241  }
242  return (s);
243}
244//-------------------------------- examples -----------------------------------
245example
246{
247  "EXAMPLE:"; echo = 2;
[0b59f5]248  ring r; basering;
[599bc9]249  katsura();
[0b59f5]250  katsura(4); basering;
[599bc9]251}
252
253proc kat_var(int i, int n)
254{
255  poly p;
256  if (i < 0)  { i = -i;}
257  if (i <= n) { p = var(i+1); }
258  return (p);
259}
260///////////////////////////////////////////////////////////////////////////////
261
[6f2edc]262proc freerank
[d2b2a7]263"USAGE:   freerank(M[,any]);  M=poly/ideal/vector/module/matrix
[b9b906]264COMPUTE: rank of module presented by M in case it is free.
[ff8d25]265         By definition this is vdim(coker(M)/m*coker(M)) if coker(M)
266         is free, where m = maximal ideal of the variables of the
[b9b906]267         basering and M is considered as matrix.
[ff8d25]268         (the 0-module is free of rank 0)
[6f2edc]269RETURN:  rank of coker(M) if coker(M) is free and -1 else;
270         in case of a second argument return a list:
271                L[1] = rank of coker(M) or -1
272                L[2] = minbase(M)
273NOTE:    freerank(syz(M)); computes the rank of M if M is free (and -1 else)
274EXAMPLE: example freerank; shows examples
[d2b2a7]275"
[6f2edc]276{
277  int rk;
278  def M = simplify(#[1],10);
[8632ac]279  resolution mre = res(M,2);
[6f2edc]280  intmat B = betti(mre);
281  if ( ncols(B)>1 ) { rk = -1; }
282  else { rk = sum(B[1..nrows(B),1]); }
283  if (size(#) == 2) { list L=rk,mre[1]; return(L);}
284  return(rk);
285}
286example
287{"EXAMPLE";   echo=2;
288  ring r;
289  ideal i=x;
290  module M=[x,0,1],[-x,0,-1];
[ff8d25]291  freerank(M);          // should be 2, coker(M) is not free
[b9b906]292  freerank(syz (M),"");
[ff8d25]293  // [1] should be 1, coker(syz(M))=M is free of rank 1
294  // [2] should be gen(2)+gen(1) (minimal relation of M)
[6f2edc]295  freerank(i);
[ff8d25]296  freerank(syz(i));     // should be 1, coker(syz(i))=i is free of rank 1
[6f2edc]297}
298///////////////////////////////////////////////////////////////////////////////
299
300proc is_zero
[d2b2a7]301"USAGE:   is_zero(M[,any]); M=poly/ideal/vector/module/matrix
[b9b906]302RETURN:  integer, 1 if coker(M)=0 resp. 0 if coker(M)!=0, where M is
[ff8d25]303         considered as matrix.
304         If a second argument is given, return a list:
[6f2edc]305                L[1] = 1 if coker(M)=0 resp. 0 if coker(M)!=0
306                L[2] = dim(M)
307EXAMPLE: example is_zero; shows examples
[d2b2a7]308"
[6f2edc]309{
310  int d=dim(std(#[1]));
311  int a = ( d==-1 );
312  if( size(#) >1 ) { list L=a,d; return(L); }
313  return(a);
314}
315example
316{ "EXAMPLE:";   echo=2;
317  ring r;
318  module m = [x],[y],[1,z];
319  is_zero(m,1);
320  qring q = std(ideal(x2+y3+z2));
321  ideal j = x2+y3+z2-37;
322  is_zero(j);
323}
[ff8d25]324///////////////////////////////////////////////////////////////////////////////
[6f2edc]325
[3d124a7]326proc maxcoef (f)
[d2b2a7]327"USAGE:   maxcoef(f);  f  poly/ideal/vector/module/matrix
[6f2edc]328RETURN:  maximal length of coefficient of f of type int (by counting the
[3d124a7]329         length of the string of each coefficient)
[6f2edc]330EXAMPLE: example maxcoef; shows examples
[d2b2a7]331"
[3d124a7]332{
[6f2edc]333//----------------------------- procedure body --------------------------------
[3d124a7]334   int max,s,ii,jj; string t;
335   ideal i = ideal(matrix(f));
[6f2edc]336   i = simplify(i,6);            // delete 0's and keep first of equal elements
[3d124a7]337   poly m = var(1); matrix C;
[6f2edc]338   for (ii=2;ii<=nvars(basering);ii=ii+1) { m = m*var(ii); }
339   for (ii=1; ii<=size(i); ii=ii+1)
[3d124a7]340   {
341      C = coef(i[ii],m);
[6f2edc]342      for (jj=1; jj<=ncols(C); jj=jj+1)
[3d124a7]343      {
344         t = string(C[2,jj]);  s = size(t);
345         if ( t[1] == "-" ) { s = s - 1; }
346         if ( s > max ) { max = s; }
347      }
348   }
349   return(max);
350}
[6f2edc]351//-------------------------------- examples -----------------------------------
[3d124a7]352example
353{ "EXAMPLE:"; echo = 2;
354   ring r= 0,(x,y,z),ds;
355   poly g = 345x2-1234567890y+7/4z;
356   maxcoef(g);
[6f2edc]357   ideal i = g,10/1234567890;
358   maxcoef(i);
359   // since i[2]=1/123456789
[3d124a7]360}
361///////////////////////////////////////////////////////////////////////////////
362
[6f2edc]363proc maxdeg (id)
[d2b2a7]364"USAGE:   maxdeg(id);  id  poly/ideal/vector/module/matrix
[6f2edc]365RETURN:  int/intmat, each component equals maximal degree of monomials in the
366         corresponding component of id, independent of ring ordering
[ff8d25]367         (maxdeg of each var is 1).
368         Of type int if id is of type poly, of type intmat else
[11dddeb]369NOTE:    proc maxdeg1 returns 1 integer, the absolute maximum; moreover, it has
[6f2edc]370         an option for computing weighted degrees
371EXAMPLE: example maxdeg; shows examples
[d2b2a7]372"
[3d124a7]373{
[6f2edc]374   //-------- subprocedure to find maximal degree of given component ----------
[3d124a7]375   proc findmaxdeg
376   {
377      poly c = #[1];
378      if (c==0) { return(-1); }
379   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
380      int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
381      int i = d;
382      while ( c-jet(c,i) != 0 ) { i = 2*(i+1); }
383      int o = i-1;
[e4e42c]384      int u = (d != i)*((i /  2)-1);
[3d124a7]385   //----------------------- "quick search" for maxdeg ------------------------
386      while ( (c-jet(c,i)==0)*(c-jet(c,i-1)!=0) == 0)
387      {
[e4e42c]388         i = (o+1+u) /  2;
[3d124a7]389         if (c-jet(c,i)!=0) { u = i+1; }
390         else { o = i-1; }
391      }
392      return(i);
393   }
394//------------------------------ main program ---------------------------------
395   matrix M = matrix(id);
396   int r,c = nrows(M), ncols(M); int i,j;
397   intmat m[r][c];
[6f2edc]398   for (i=r; i>0; i=i-1)
[3d124a7]399   {
[6f2edc]400      for (j=c; j>0; j=j-1) { m[i,j] = findmaxdeg(M[i,j]); }
[3d124a7]401   }
[6f2edc]402   if (typeof(id)=="poly") { return(m[1,1]); }
[3d124a7]403   return(m);
404}
[6f2edc]405//-------------------------------- examples -----------------------------------
[3d124a7]406example
407{ "EXAMPLE:"; echo = 2;
[11dddeb]408   ring r = 0,(x,y,z),wp(1,2,3);
[3d124a7]409   poly f = x+y2+z3;
[ff8d25]410   deg(f);             //deg; returns weighted degree (in case of 1 block)!
[3d124a7]411   maxdeg(f);
412   matrix m[2][2]=f+x10,1,0,f^2;
413   maxdeg(m);
414}
415///////////////////////////////////////////////////////////////////////////////
416
[6f2edc]417proc maxdeg1 (id,list #)
[d2b2a7]418"USAGE:   maxdeg1(id[,v]);  id=poly/ideal/vector/module/matrix, v=intvec
[6f2edc]419RETURN:  integer, maximal [weighted] degree of monomials of id independent of
420         ring ordering, maxdeg1 of i-th variable is v[i] (default: v=1..1).
421NOTE:    This proc returns one integer while maxdeg returns, in general,
422         a matrix of integers. For one polynomial and if no intvec v is given
423         maxdeg is faster
424EXAMPLE: example maxdeg1; shows examples
[d2b2a7]425"
[6f2edc]426{
427   //-------- subprocedure to find maximal degree of given component ----------
428   proc findmaxdeg
429   {
430      poly c = #[1];
431      if (c==0) { return(-1); }
432      intvec v = #[2];
433   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
434      int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
435      int i = d;
436      if ( c == jet(c,-1,v))      //case: maxdeg is negative
437      {
438         i = -d;
439         while ( c == jet(c,i,v) ) { i = 2*(i-1); }
[e4e42c]440         int o = (d != -i)*((i /  2)+2) - 1;
[6f2edc]441         int u = i+1;
442         int e = -1;
443      }
444      else                        //case: maxdeg is nonnegative
445      {
446         while ( c != jet(c,i,v) ) { i = 2*(i+1); }
447         int o = i-1;
[e4e42c]448         int u = (d != i)*((i /  2)-1);
[6f2edc]449         int e = 1;
450      }
451   //----------------------- "quick search" for maxdeg ------------------------
452      while ( ( c==jet(c,i,v) )*( c!=jet(c,i-1,v) ) == 0 )
453      {
[e4e42c]454         i = (o+e+u) /  2;
[6f2edc]455         if ( c!=jet(c,i,v) ) { u = i+1; }
456         else { o = i-1; }
457      }
458      return(i);
459   }
460//------------------------------ main program ---------------------------------
461   ideal M = simplify(ideal(matrix(id)),8);   //delete scalar multiples from id
462   int c = ncols(M);
463   int i,n;
464   if( size(#)==0 )
465   {
466      int m = maxdeg(M[c]);
467      for (i=c-1; i>0; i=i-1)
468      {
469          n = maxdeg(M[i]);
470          m = (m>=n)*m + (m<n)*n;             //let m be the maximum of m and n
471      }
472   }
473   else
474   {
475      intvec v=#[1];                          //weight vector for the variables
476      int m = findmaxdeg(M[c],v);
477      for (i=c-1; i>0; i--)
478      {
479         n = findmaxdeg(M[i],v);
480         if( n>m ) { m=n; }
481      }
482   }
483   return(m);
484}
485//-------------------------------- examples -----------------------------------
486example
487{ "EXAMPLE:"; echo = 2;
[11dddeb]488   ring r = 0,(x,y,z),wp(1,2,3);
[6f2edc]489   poly f = x+y2+z3;
[ff8d25]490   deg(f);            //deg returns weighted degree (in case of 1 block)!
[6f2edc]491   maxdeg1(f);
492   intvec v = ringweights(r);
[ff8d25]493   maxdeg1(f,v);                        //weighted maximal degree
[6f2edc]494   matrix m[2][2]=f+x10,1,0,f^2;
[11dddeb]495   maxdeg1(m,v);                        //absolute weighted maximal degree
[6f2edc]496}
497///////////////////////////////////////////////////////////////////////////////
498
[3d124a7]499proc mindeg (id)
[d2b2a7]500"USAGE:   mindeg(id);  id  poly/ideal/vector/module/matrix
[6f2edc]501RETURN:  minimal degree/s of monomials of id, independent of ring ordering
502         (mindeg of each variable is 1) of type int if id of type poly, else
503         of type intmat.
[11dddeb]504NOTE:    proc mindeg1 returns one integer, the absolute minimum; moreover it
[6f2edc]505         has an option for computing weighted degrees.
506EXAMPLE: example mindeg; shows examples
[d2b2a7]507"
[3d124a7]508{
[6f2edc]509   //--------- subprocedure to find minimal degree of given component ---------
[3d124a7]510   proc findmindeg
511   {
512      poly c = #[1];
513      if (c==0) { return(-1); }
514   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
515      int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
516      int i = d;
517      while ( jet(c,i) == 0 ) { i = 2*(i+1); }
518      int o = i-1;
[e4e42c]519      int u = (d != i)*((i /  2)-1);
[6f2edc]520   //----------------------- "quick search" for mindeg ------------------------
[3d124a7]521      while ( (jet(c,u)==0)*(jet(c,o)!=0) )
522      {
[e4e42c]523         i = (o+u) / 2;
[3d124a7]524         if (jet(c,i)==0) { u = i+1; }
525         else { o = i-1; }
526      }
527      if (jet(c,u)!=0) { return(u); }
528      else { return(o+1); }
529   }
530//------------------------------ main program ---------------------------------
531   matrix M = matrix(id);
532   int r,c = nrows(M), ncols(M); int i,j;
533   intmat m[r][c];
[6f2edc]534   for (i=r; i>0; i=i-1)
[3d124a7]535   {
[6f2edc]536      for (j=c; j>0; j=j-1) { m[i,j] = findmindeg(M[i,j]); }
[3d124a7]537   }
538   if (typeof(id)=="poly") { return(m[1,1]); }
539   return(m);
540}
[6f2edc]541//-------------------------------- examples -----------------------------------
542example
543{ "EXAMPLE:"; echo = 2;
544   ring r = 0,(x,y,z),ls;
545   poly f = x5+y2+z3;
[ff8d25]546   ord(f);                  // ord returns weighted order of leading term!
547   mindeg(f);               // computes minimal degree
[6f2edc]548   matrix m[2][2]=x10,1,0,f^2;
[ff8d25]549   mindeg(m);               // computes matrix of minimum degrees
[6f2edc]550}
551///////////////////////////////////////////////////////////////////////////////
552
553proc mindeg1 (id, list #)
[d2b2a7]554"USAGE:   mindeg1(id[,v]);  id=poly/ideal/vector/module/matrix, v=intvec
[6f2edc]555RETURN:  integer, minimal [weighted] degree of monomials of id independent of
556         ring ordering, mindeg1 of i-th variable is v[i] (default v=1..1).
557NOTE:    This proc returns one integer while mindeg returns, in general,
558         a matrix of integers. For one polynomial and if no intvec v is given
559         mindeg is faster.
560EXAMPLE: example mindeg1; shows examples
[d2b2a7]561"
[6f2edc]562{
563   //--------- subprocedure to find minimal degree of given component ---------
564   proc findmindeg
565   {
566      poly c = #[1];
567      intvec v = #[2];
568      if (c==0) { return(-1); }
569   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
570      int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
571      int i = d;
572      if ( jet(c,-1,v) !=0 )      //case: mindeg is negative
573      {
574         i = -d;
575         while ( jet(c,i,v) != 0 ) { i = 2*(i-1); }
[e4e42c]576         int o = (d != -i)*((i /  2)+2) - 1;
[6f2edc]577         int u = i+1;
578         int e = -1; i=u;
579      }
580      else                        //case: inded is nonnegative
581      {
582         while ( jet(c,i,v) == 0 ) { i = 2*(i+1); }
583         int o = i-1;
[e4e42c]584         int u = (d != i)*((i /  2)-1);
[6f2edc]585         int e = 1; i=u;
586      }
587   //----------------------- "quick search" for mindeg ------------------------
588      while ( (jet(c,i-1,v)==0)*(jet(c,i,v)!=0) == 0 )
589      {
[e4e42c]590         i = (o+e+u) /  2;
[6f2edc]591         if (jet(c,i,v)==0) { u = i+1; }
592         else { o = i-1; }
593      }
594      return(i);
595   }
596//------------------------------ main program ---------------------------------
597   ideal M = simplify(ideal(matrix(id)),8);   //delete scalar multiples from id
598   int c = ncols(M);
599   int i,n;
600   if( size(#)==0 )
601   {
602      int m = mindeg(M[c]);
603      for (i=c-1; i>0; i=i-1)
604      {
605          n = mindeg(M[i]);
606          m = (m<=n)*m + (m>n)*n;             //let m be the maximum of m and n
607      }
608   }
609   else
610   {
611      intvec v=#[1];                          //weight vector for the variables
612      int m = findmindeg(M[c],v);
613      for (i=c-1; i>0; i=i-1)
614      {
615         n = findmindeg(M[i],v);
616         m = (m<=n)*m + (m>n)*n;              //let m be the maximum of m and n
617      }
618   }
619   return(m);
620}
621//-------------------------------- examples -----------------------------------
[3d124a7]622example
623{ "EXAMPLE:"; echo = 2;
624   ring r = 0,(x,y,z),ls;
625   poly f = x5+y2+z3;
[ff8d25]626   ord(f);                  // ord returns weighted order of leading term!
[6f2edc]627   intvec v = 1,-3,2;
[ff8d25]628   mindeg1(f,v);            // computes minimal weighted degree
[3d124a7]629   matrix m[2][2]=x10,1,0,f^2;
[11dddeb]630   mindeg1(m,1..3);         // computes absolute minimum of weighted degrees
[3d124a7]631}
632///////////////////////////////////////////////////////////////////////////////
633
634proc normalize (id)
[d2b2a7]635"USAGE:   normalize(id);  id=poly/vector/ideal/module
[3d124a7]636RETURN:  object of same type with leading coefficient equal to 1
637EXAMPLE: example normalize; shows an example
[d2b2a7]638"
[6f2edc]639{
[3d124a7]640   return(simplify(id,1));
641}
[6f2edc]642//-------------------------------- examples -----------------------------------
[3d124a7]643example
[ff8d25]644{ "EXAMPLE:"; echo = 2;
[3d124a7]645   ring r = 0,(x,y,z),ls;
646   poly f = 2x5+3y2+4z3;
647   normalize(f);
648   module m=[9xy,0,3z3],[4z,6y,2x];
649   normalize(m);
650   ring s = 0,(x,y,z),(c,ls);
651   module m=[9xy,0,3z3],[4z,6y,2x];
652   normalize(m);
653}
654///////////////////////////////////////////////////////////////////////////////
[6f2edc]655
[ff8d25]656///////////////////////////////////////////////////////////////////////////////
[839b04d]657// Input: <ideal>=<f1,f2,...,fm> and <polynomial> g
658// Question: Does g lie in the radical of <ideal>?
[b9b906]659// Solution: Compute a standard basis G for <f1,f2,...,fm,gz-1> where z is a
660//           new variable. Then g is contained in the radical of <ideal> <=>
[ff8d25]661//           1 is generator in G.
662///////////////////////////////////////////////////////////////////////////////
[839b04d]663proc rad_con (poly g,ideal I)
[ff8d25]664"USAGE:   rad_con(g,I); g polynomial, I ideal
665RETURN:  1 (TRUE) (type int) if g is contained in the radical of I
666@*       0 (FALSE) (type int) otherwise
667EXAMPLE: example rad_con; shows an example
[d2b2a7]668"
[839b04d]669{ def br=basering;
670  int n=nvars(br);
671  int dB=degBound;
672  degBound=0;
673  string mp=string(minpoly);
[38c165]674  execute("ring R=("+charstr(br)+"),(x(1..n),z),dp;");
675  execute("minpoly=number("+mp+");");
[839b04d]676  ideal irrel=x(1..n);
677  map f=br,irrel;
678  poly p=f(g);
679  ideal J=f(I)+ideal(p*z-1);
680  J=std(J);
681  degBound=dB;
682  if (J[1]==1)
683  { return(1);
684  }
685  else
686  { return(0);
687  }
688}
689example
[ff8d25]690{ "EXAMPLE:"; echo=2;
691   ring R=0,(x,y,z),dp;
692   ideal I=x2+y2,z2;
693   poly f=x4+y4;
694   rad_con(f,I);
695   ideal J=x2+y2,z2,x4+y4;
696   poly g=z;
697   rad_con(g,I);
[839b04d]698}
[927ed62]699///////////////////////////////////////////////////////////////////////////////
700
[ff8d25]701proc lcm (id, list #)
[11dddeb]702"USAGE:   lcm(p[,q]); p int/intvec q a list of integers or
[ff8d25]703          p poly/ideal q a list of polynomials
704RETURN:  the least common multiple of the common entries of p and q:
705@*         - of type int if p is an int/intvec
706@*         - of type poly if p is a poly/ideal
[927ed62]707EXAMPLE: example lcm; shows an example
[d2b2a7]708"
[927ed62]709{
710  int k,j;
[ff8d25]711//------------------------------ integer case --------------------------------
712  if( typeof(id) == "int" or typeof(id) == "intvec" )
[927ed62]713  {
[ff8d25]714     intvec i = id;
715     if (size(#)!=0)
[927ed62]716     {
[ff8d25]717        for (j = 1; j<=size(#); j++)
[927ed62]718        {
[ff8d25]719           if (typeof(#[j]) !="int" and typeof(#[j]) !="intvec")
720           { ERROR("// ** list element must be an integer");}
721           else
722           { i = i,#[j]; }
[927ed62]723        }
[ff8d25]724     }
725     int p,q;
[b9b906]726     if( i == 0 )
727     {
728        return(0);
[ff8d25]729     }
730     for(j=1;j<=size(i);j++)
731     {
732       if( i[j] != 0 )
733       {
734         p=i[j];
735         break;
736       }
737     }
738     for (k=j+1;k<=size(i);k++)
739     {
740        if( i[k] !=0)
[927ed62]741        {
[ff8d25]742           q=gcd(p,i[k]);
[927ed62]743           p=p/q;
744           p=p*i[k];
745        }
746     }
[b9b906]747     if(p <0 )
[ff8d25]748     {return(-p);}
749     return(p);
[b9b906]750   }
[ff8d25]751
752//----------------------------- polynomial case ------------------------------
753  if( typeof(id) == "poly" or typeof(id) == "ideal" )
754  {
755     ideal i = id;
756     if (size(#)!=0)
757     {
758        for (j = 1; j<=size(#); j++)
759        {
760           if (typeof(#[j]) !="poly" and typeof(#[j]) !="ideal"
761              and typeof(#[j]) !="int" and typeof(#[j]) !="intvec")
762           { ERROR("// ** list element must be a polynomial");}
763           else
764           { i = i,#[j]; }
765        }
766     }
767     poly p,q;
768     i=simplify(i,10);
[b9b906]769     if(size(i) == 0)
770     {
771        return(0);
[ff8d25]772     }
773     for(j=1;j<=size(i);j++)
774     {
775       if(maxdeg(i[j])!= 0)
776       {
777         p=i[j];
778         break;
779       }
780     }
781     if(deg(p)==-1)
782     {
783       return(1);
784     }
785     for (k=j+1;k<=size(i);k++)
786     {
787        if(maxdeg(i[k])!=0)
788        {
789           q=gcd(p,i[k]);
790           if(maxdeg(q)==0)
791           {
792                 p=p*i[k];
793           }
794           else
795           {
796              p=p/q;
797              p=p*i[k];
798           }
799        }
800     }
801     return(p);
[927ed62]802   }
803}
804example
805{ "EXAMPLE:"; echo = 2;
806   ring  r = 0,(x,y,z),lp;
807   poly  p = (x+y)*(y+z);
808   poly  q = (z4+2)*(y+z);
[ff8d25]809   lcm(p,q);
810   ideal i=p,q,y+z;
811   lcm(i,p);
812   lcm(2,3,6);
813   lcm(2..6);
[927ed62]814}
815
816///////////////////////////////////////////////////////////////////////////////
817
818proc content(f)
[d2b2a7]819"USAGE:   content(f); f polynomial/vector
[927ed62]820RETURN:  number, the content (greatest common factor of coefficients)
821         of the polynomial/vector f
822EXAMPLE: example content; shows an example
[d2b2a7]823"
[927ed62]824{
825  return(leadcoef(f)/leadcoef(cleardenom(f)));
[82716e]826}
[927ed62]827example
828{ "EXAMPLE:"; echo = 2;
829   ring r=0,(x,y,z),(c,lp);
830   content(3x2+18xy-27xyz);
831   vector v=[3x2+18xy-27xyz,15x2+12y4,3];
832   content(v);
833}
[e5c7fb6]834///////////////////////////////////////////////////////////////////////////////
835
836proc numerator(number n)
[3a62db]837"USAGE:    numerator(n); n number
838RETURN:   number, the numerator of n
[e5c7fb6]839SEE ALSO: denominator, content, cleardenom
[3a62db]840EXAMPLE:  example numerator; shows an example
[e5c7fb6]841"
842{
[3a62db]843  poly p = cleardenom(n+var(1));
[2f436b]844  return (number(coeffs(p,var(1))[1,1]));
[e5c7fb6]845}
846example
847{
848  "EXAMPLE:"; echo = 2;
849  ring r = 0,x, dp;
850  number n = 3/2;
851  numerator(n);
852}
[ff8d25]853///////////////////////////////////////////////////////////////////////////////
[e5c7fb6]854
855proc denominator(number n)
[3a62db]856"USAGE:    denominator(n); n number
857RETURN:   number, the denominator of n
858SEE ALSO: denominator, content, cleardenom
859EXAMPLE:  example denominator; shows an example
[e5c7fb6]860"
861{
[3a62db]862  poly p = cleardenom(n+var(1));
[2f436b]863  return (number(coeffs(p,var(1))[2,1]));
[e5c7fb6]864}
865example
866{
867  "EXAMPLE:"; echo = 2;
868  ring r = 0,x, dp;
869  number n = 3/2;
870  denominator(n);
871}
[590998]872////////////////////////////////////////////////////////////////////////
873
[ff8d25]874////////////////////////////////////////////////////////////////////////
875// The idea of the procedures mod2id, id2mod and subrInterred is, to
876// perform standard basis computation or interreduction of a submodule
877// of a free module with generators gen(1),...,gen(n) over a ring R
878// in a ring R[t1,...,tn]/<ti*tj> with gen(i) maped to ti
879////////////////////////////////////////////////////////////////////////
880
[590998]881proc mod2id(matrix M,intvec vpos)
[ff8d25]882"USAGE:   mod2id(M,vpos); M matrix, vpos intvec
883ASSUME:  vpos is an integer vector such that gen(i) corresponds
884         to var(vpos[i]).
885         The basering contains variables var(vpos[i]) which do not occur
886         in M.
887RETURN:  ideal I in which each gen(i) from the module is replaced by
888         var(vpos[i]) and all monomials var(vpos[i])*var(vpos[j]) have
889         been added to the generating set of I.
890NOTE:    This procedure should be used in the following situation:
891         one wants to pass to a ring with new variables, say e(1),..,e(s),
892         which correspond to the components gen(1),..,gen(s) of the
893         module M such that e(i)*e(j)=0 for all i,j.
894         The new ring should already exist and be the current ring
895EXAMPLE: example mod2id; shows an example"
[590998]896{
897  int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
898//----------------------------------------------------------------------
899// define the ideal generated by the var(vpos[i]) and set up the matrix
900// for the multiplication
901//----------------------------------------------------------------------
902  ideal vars=var(vpos[1]);
903  for(int i=2;i<=size(vpos);i++)
904  {
905    vars=vars,var(vpos[i]);
906  }
907  matrix varm[1][size(vpos)]=vars;
908  if (size(vpos) > nrows(M))
909  {
910    matrix Mt[size(vpos)][ncols(M)];
911    Mt[1..nrows(M),1..ncols(M)]=M;
912    kill M;
913    matrix M=Mt;
914  }
915//----------------------------------------------------------------------
916// define the desired ideal
917//----------------------------------------------------------------------
918  ideal ret=vars^2,varm*M;
919  return(ret);
920}
921example
922{ "EXAMPLE:"; echo=2;
923  ring r=0,(e(1),e(2),x,y,z),(dp(2),ds(3));
924  module mo=x*gen(1)+y*gen(2);
925  intvec iv=2,1;
926  mod2id(mo,iv);
927}
928////////////////////////////////////////////////////////////////////////
929
930proc id2mod(ideal i,intvec vpos)
[ff8d25]931"USAGE:   id2mod(I,vpos); I ideal, vpos intvec
932RETURN:  module corresponding to the ideal by replacing var(vpos[i]) by
933         gen(i) and omitting all generators var(vpos[i])*var(vpos[j])
934NOTE:    * This procedure only makes sense if the ideal contains
935           all var(vpos[i])*var(vpos[j]) as monomial generators and
936           all other generators of I are linear combinations of the
937           var(vpos[i]) over the ring in the other variables.
938         * This is the inverse procedure to mod2id and should be applied
939           only to ideals created by mod2id using the same intvec vpos
940           (possibly after a standard basis computation)
941EXAMPLE: example id2mod; shows an example"
[590998]942{
943  int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
944//---------------------------------------------------------------------
945// Initialization
946//---------------------------------------------------------------------
947  int n=size(i);
948  int v=size(vpos);
949  matrix tempmat;
950  matrix mm[v][n];
951//---------------------------------------------------------------------
952// Conversion
953//---------------------------------------------------------------------
954  for(int j=1;j<=v;j++)
955  {
956    tempmat=coeffs(i,var(vpos[j]));
957    mm[j,1..n]=tempmat[2,1..n];
958  }
959  for(j=1;j<=v;j++)
960  {
961    mm=subst(mm,var(vpos[j]),0);
962  }
963  module ret=simplify(mm,10);
964  return(ret);
965}
966example
967{ "EXAMPLE:"; echo=2;
968  ring r=0,(e(1),e(2),x,y,z),(dp(2),ds(3));
969  ideal i=e(2)^2,e(1)*e(2),e(1)^2,e(1)*y+e(2)*x;
970  intvec iv=2,1;
971  id2mod(i,iv);
972}
973///////////////////////////////////////////////////////////////////////
974
975proc subrInterred(ideal mon, ideal sm, intvec iv)
[8942a5]976"USAGE:   subrInterred(mon,sm,iv);
977         sm:   ideal in a ring r with n + s variables,
978               e.g. x_1,..,x_n and t_1,..,t_s
979         mon:  ideal with monomial generators (not divisible by
[ff8d25]980               any of the t_i) such that sm is contained in the module
[8942a5]981               k[t_1,..,t_s]*mon[1]+..+k[t_1,..,t_s]*mon[size(mon)]
982         iv:   intvec listing the variables which are supposed to be used
983               as x_i
984RETURN:  list l:
[590998]985          l[1]=the monomials from mon in the order used
986          l[2]=their coefficients after interreduction
987          l[3]=l[1]*l[2]
[11dddeb]988PURPOSE:  Do interred only w.r.t. a subset of variables.
[b9b906]989         The procedure returns an interreduced system of generators of
[ff8d25]990         sm considered as a k[t_1,..,t_s]-submodule of the free module
991         k[t_1,..,t_s]*mon[1]+..+k[t_1,..,t_s]*mon[size(mon)]).
992EXAMPLE: example subrInterred; shows an example
993"
[590998]994{
995  int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
996//-----------------------------------------------------------------------
997// check that mon is really generated by monomials
998// and sort its generators with respect to the monomial ordering
999//-----------------------------------------------------------------------
1000  int err;
1001  for(int i=1;i<=ncols(mon);i++)
1002  {
1003    if ( size(mon[i]) > 1 )
1004    {
1005      err=1;
1006    }
1007  }
1008  if (err==1)
1009  {
1010    ERROR("mon has to be generated by monomials");
1011  }
1012  intvec sv=sortvec(mon);
1013  ideal mons;
1014  for(i=1;i<=size(sv);i++)
1015  {
1016    mons[i]=mon[sv[i]];
1017  }
1018  ideal itemp=maxideal(1);
1019  for(i=1;i<=size(iv);i++)
1020  {
1021    itemp=subst(itemp,var(iv[i]),0);
1022  }
1023  itemp=simplify(itemp,10);
1024  def r=basering;
1025  string tempstr="ring rtemp=" + charstr(basering) + ",(" + string(itemp)
1026                               + "),(C,dp);";
1027//-----------------------------------------------------------------------
1028// express m in terms of the generators of mon and check whether m
1029// can be considered as a submodule of k[t_1,..,t_n]*mon
1030//-----------------------------------------------------------------------
1031  module motemp;
1032  motemp[ncols(sm)]=0;
1033  poly ptemp;
1034  int j;
1035  for(i=1;i<=ncols(mons);i++)
1036  {
1037    for(j=1;j<=ncols(sm);j++)
1038    {
1039      ptemp=sm[j]/mons[i];
1040      motemp[j]=motemp[j]+ptemp*gen(i);
1041    }
1042  }
1043  for(i=1;i<=size(iv);i++)
1044  {
1045    motemp=subst(motemp,var(iv[i]),0);
1046  }
1047  matrix monmat[1][ncols(mons)]=mons;
1048  ideal dummy=monmat*motemp;
1049  for(i=1;i<=size(sm);i++)
1050  {
1051    if(sm[i]-dummy[i]!=0)
1052    {
1053      ERROR("the second argument is not a submodule of the assumed structure");
1054    }
1055  }
1056//----------------------------------------------------------------------
1057// do the interreduction and convert back
1058//----------------------------------------------------------------------
1059  execute(tempstr);
1060  def motemp=imap(r,motemp);
1061  motemp=interred(motemp);
1062  setring r;
1063  kill motemp;
1064  def motemp=imap(rtemp,motemp);
1065  list ret=monmat,motemp,monmat*motemp;
1066  for(i=1;i<=ncols(ret[2]);i++)
1067  {
1068    ret[2][i]=cleardenom(ret[2][i]);
1069  }
1070  for(i=1;i<=ncols(ret[3]);i++)
1071  {
1072    ret[3][i]=cleardenom(ret[3][i]);
1073  }
1074  return(ret);
1075}
1076example
1077{ "EXAMPLE:"; echo=2;
1078  ring r=0,(x,y,z),dp;
1079  ideal i=x^2+x*y^2,x*y+x^2*y,z;
1080  ideal j=x^2+x*y^2,x*y,z;
1081  ideal mon=x^2,z,x*y;
1082  intvec iv=1,3;
1083  subrInterred(mon,i,iv);
1084  subrInterred(mon,j,iv);
1085}
[e5c7fb6]1086
[4508b59]1087///////////////////////////////////////////////////////////////////////////////
1088// moved here from nctools.lib
1089// This procedure calculates the Newton diagram of the polynomial f
1090// The output is a intmat M, each row of M is the exp of a monomial in f
1091////////////////////////////////////////////////////////////////////////
1092proc newtonDiag(poly f)
1093"USAGE:  newtonDiag(f); f a poly
1094RETURN:  intmat
1095PURPOSE: compute the Newton diagram of f
1096NOTE:    each row is the exponent of a monomial of f
1097EXAMPLE: example newtonDiag; shows examples
1098"{
1099  int n = nvars(basering);
1100  intvec N=0;
1101  if ( f != 0 )
1102  {
1103    while ( f != 0 )
1104    {
1105      N = N, leadexp(f);
1106      f = f-lead(f);
1107    }
1108  }
1109  else
1110  {
1111    N=N, leadexp(f);
1112  }
1113  N = N[2..size(N)]; // Deletes the zero added in the definition of T
1114  intmat M=intmat(N,(size(N)/n),n); // Conversion from vector to matrix
1115  return (M);
1116}
1117example
1118{
1119  "EXAMPLE:";echo=2;
1120  ring r = 0,(x,y,z),lp;
1121  poly f = x2y+3xz-5y+3;
1122  newtonDiag(f);
1123}
[b9b906]1124
[4508b59]1125////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.