source: git/Singular/LIB/poly.lib @ 9b8feed

spielwiese
Last change on this file since 9b8feed was 9b8feed, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* added numerator/denom to list of procedures git-svn-id: file:///usr/local/Singular/svn/trunk@4068 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 21.6 KB
Line 
1// $Id: poly.lib,v 1.23 2000-01-10 16:40:41 obachman Exp $
2//(GMG, last modified 22.06.96)
3//(obachman: 17.12.97 -- added katsura)
4///////////////////////////////////////////////////////////////////////////////
5
6version="$Id: poly.lib,v 1.23 2000-01-10 16:40:41 obachman Exp $";
7info="
8LIBRARY:  poly.lib      PROCEDURES FOR MANIPULATING POLYS, IDEALS, MODULES
9
10PROCEDURES:
11 cyclic(int);           ideal of cyclic n-roots
12 katsura([i]);          katsura [i] ideal
13 freerank(poly/...)     rank of coker(input) if coker is free else -1
14 is_homog(poly/...);    int, =1 resp. =0 if input is homogeneous resp. not
15 is_zero(poly/...);     int, =1 resp. =0 if coker(input) is 0 resp. not
16 lcm(ideal);            lcm of given generators of ideal
17 maxcoef(poly/...);     maximal length of coefficient occuring in poly/...
18 maxdeg(poly/...);      int/intmat = degree/s of terms of maximal order
19 maxdeg1(poly/...);     int = [weighted] maximal degree of input
20 mindeg(poly/...);      int/intmat = degree/s of terms of minimal order
21 mindeg1(poly/...);     int = [weighted] minimal degree of input
22 normalize(poly/...);   normalize poly/... such that leading coefficient is 1
23 rad_con(p,I);          check radical containment of poly p in ideal I
24 content(f);            content of polynomial/vector f
25 numerator(n);          numerator of number n
26 denominator(n)         denominator of number n
27          (parameters in square brackets [] are optional)
28";
29
30LIB "general.lib";
31///////////////////////////////////////////////////////////////////////////////
32
33proc cyclic (int n)
34"USAGE:   cyclic(n);  n integer
35RETURN:  ideal of cyclic n-roots from 1-st n variables of basering
36EXAMPLE: example cyclic; shows examples
37"
38{
39//----------------------------- procedure body --------------------------------
40   ideal m = maxideal(1);
41   m = m[1..n],m[1..n];
42   int i,j;
43   ideal s; poly t;
44   for ( j=0; j<=n-2; j=j+1 )
45   {
46      t=0;
47      for( i=1;i<=n;i=i+1 ) { t=t+product(m,i..i+j); }
48      s=s+t;
49   }
50   s=s,product(m,1..n)-1;
51   return (s);
52}
53//-------------------------------- examples -----------------------------------
54example
55{ "EXAMPLE:"; echo = 2;
56   ring r=0,(u,v,w,x,y,z),lp;
57   cyclic(nvars(basering));
58   homog(cyclic(5),z);
59}
60///////////////////////////////////////////////////////////////////////////////
61
62proc katsura
63"USAGE: katsura([n]): n integer
64RETURN: katsura(n) : n-th katsura ideal of
65                      (1) newly created and set ring (32003, x(0..n), dp), if
66                          nvars(basering) < n
67                      (2) basering, if nvars(basering) >= n
68        katsura()  : katsura ideal of basering
69EXAMPLE: example katsura; shows examples
70"
71{
72  int n;
73  if ( size(#) == 1 && typeof(#[1]) == "int")
74  {
75    n = #[1] - 1;
76    while (1)
77    {
78      if (defined(basering))
79      {
80        if (nvars(basering) >= #[1]) {break;}
81      }
82      ring katsura_ring = 32003, x(0..#[1]), dp;
83      keepring katsura_ring;
84      break;
85    }
86  }
87  else
88  {
89    n = nvars(basering) -1;
90  }
91
92  ideal s;
93  int i, j;
94  poly p;
95
96  p = -1;
97  for (i = -n; i <= n; i++)
98  {
99    p = p + kat_var(i, n);
100  }
101  s[1] = p;
102
103  for (i = 0; i < n; i++)
104  {
105    p = -1 * kat_var(i,n);
106    for (j = -n; j <= n; j++)
107    {
108      p = p + kat_var(j,n) * kat_var(i-j, n);
109    }
110    s = s,p;
111  }
112  return (s);
113}
114//-------------------------------- examples -----------------------------------
115example
116{
117  "EXAMPLE:"; echo = 2;
118  ring r; basering;
119  katsura();
120  katsura(4); basering;
121}
122
123proc kat_var(int i, int n)
124{
125  poly p;
126  if (i < 0)  { i = -i;}
127  if (i <= n) { p = var(i+1); }
128  return (p);
129}
130///////////////////////////////////////////////////////////////////////////////
131
132proc freerank
133"USAGE:   freerank(M[,any]);  M=poly/ideal/vector/module/matrix
134COMPUTE: rank of module presented by M in case it is free. By definition this
135         is vdim(coker(M)/m*coker(M)) if coker(M) is free, where m = maximal
136         ideal of basering and M is considered as matrix (the 0-module is
137         free of rank 0)
138RETURN:  rank of coker(M) if coker(M) is free and -1 else;
139         in case of a second argument return a list:
140                L[1] = rank of coker(M) or -1
141                L[2] = minbase(M)
142NOTE:    freerank(syz(M)); computes the rank of M if M is free (and -1 else)
143         //* Zur Zeit noch ein Bug, da erste Bettizahl falsch berechnet wird:
144         //betti(0) ist -1 statt 0
145EXAMPLE: example freerank; shows examples
146"
147{
148  int rk;
149  def M = simplify(#[1],10);
150  resolution mre = res(M,2);
151  intmat B = betti(mre);
152  if ( ncols(B)>1 ) { rk = -1; }
153  else { rk = sum(B[1..nrows(B),1]); }
154  if (size(#) == 2) { list L=rk,mre[1]; return(L);}
155  return(rk);
156}
157example
158{"EXAMPLE";   echo=2;
159  ring r;
160  ideal i=x;
161  module M=[x,0,1],[-x,0,-1];
162  freerank(M);           // should be -1, coker(M) is not free
163                         // [1] should be 1, coker(syz(M))=M is free of rank 1
164  freerank(syz (M),"");  // [2] should be gen(2)+gen(1) (minimal relation of M)
165  freerank(i);
166  freerank(syz(i));      //* bug, should be 1, coker(syz(i))=i is free of rank 1
167}
168///////////////////////////////////////////////////////////////////////////////
169
170proc is_homog (id)
171"USAGE:   is_homog(id);  id  poly/ideal/vector/module/matrix
172RETURN:  integer which is 1 if input is homogeneous (resp. weighted homogeneous
173         if the monomial ordering consists of one block of type ws,Ws,wp or Wp,
174         assuming that all weights are positive) and 0 otherwise
175NOTE:    A vector is homogeneous, if the components are homogeneous of same
176         degree, a module/matrix is homogeneous if all column vectors are
177         homogeneous
178         //*** ergaenzen, wenn Matrizen-Spalten Gewichte haben
179EXAMPLE: example is_homog; shows examples
180"
181{
182//----------------------------- procedure body --------------------------------
183   module M = module(matrix(id));
184   M = simplify(M,2);                        // remove 0-columns
185   intvec v = ringweights(basering);
186   int i,j=1,1;
187   for (i=1; i<=ncols(M); i=i+1)
188   {
189      if( M[i]!=jet(M[i],deg(lead(M[i])),v)-jet(M[i],deg(lead(M[i]))-1,v))
190      { return(0); }
191   }
192   return(1);
193}
194//-------------------------------- examples -----------------------------------
195example
196{ "EXAMPLE:"; echo = 2;
197   ring r = 0,(x,y,z),wp(1,2,3);
198   is_homog(x5-yz+y3);
199   ideal i = x6+y3+z2, x9-z3;
200   is_homog(i);
201   ring s = 0,(a,b,c),ds;
202   vector v = [a2,0,ac+bc];
203   vector w = [a3,b3,c4];
204   is_homog(v);
205   is_homog(w);
206}
207///////////////////////////////////////////////////////////////////////////////
208
209proc is_zero
210"USAGE:   is_zero(M[,any]); M=poly/ideal/vector/module/matrix
211RETURN:  integer, 1 if coker(M)=0 resp. 0 if coker(M)!=0, where M is considered
212         as matrix
213         if a second argument is given, return a list:
214                L[1] = 1 if coker(M)=0 resp. 0 if coker(M)!=0
215                L[2] = dim(M)
216EXAMPLE: example is_zero; shows examples
217"
218{
219  int d=dim(std(#[1]));
220  int a = ( d==-1 );
221  if( size(#) >1 ) { list L=a,d; return(L); }
222  return(a);
223}
224example
225{ "EXAMPLE:";   echo=2;
226  ring r;
227  module m = [x],[y],[1,z];
228  is_zero(m,1);
229  qring q = std(ideal(x2+y3+z2));
230  ideal j = x2+y3+z2-37;
231  is_zero(j);
232}
233////////////////////////////////////////////////////////////////////////////////
234
235proc maxcoef (f)
236"USAGE:   maxcoef(f);  f  poly/ideal/vector/module/matrix
237RETURN:  maximal length of coefficient of f of type int (by counting the
238         length of the string of each coefficient)
239EXAMPLE: example maxcoef; shows examples
240"
241{
242//----------------------------- procedure body --------------------------------
243   int max,s,ii,jj; string t;
244   ideal i = ideal(matrix(f));
245   i = simplify(i,6);            // delete 0's and keep first of equal elements
246   poly m = var(1); matrix C;
247   for (ii=2;ii<=nvars(basering);ii=ii+1) { m = m*var(ii); }
248   for (ii=1; ii<=size(i); ii=ii+1)
249   {
250      C = coef(i[ii],m);
251      for (jj=1; jj<=ncols(C); jj=jj+1)
252      {
253         t = string(C[2,jj]);  s = size(t);
254         if ( t[1] == "-" ) { s = s - 1; }
255         if ( s > max ) { max = s; }
256      }
257   }
258   return(max);
259}
260//-------------------------------- examples -----------------------------------
261example
262{ "EXAMPLE:"; echo = 2;
263   ring r= 0,(x,y,z),ds;
264   poly g = 345x2-1234567890y+7/4z;
265   maxcoef(g);
266   ideal i = g,10/1234567890;
267   maxcoef(i);
268   // since i[2]=1/123456789
269}
270///////////////////////////////////////////////////////////////////////////////
271
272proc maxdeg (id)
273"USAGE:   maxdeg(id);  id  poly/ideal/vector/module/matrix
274RETURN:  int/intmat, each component equals maximal degree of monomials in the
275         corresponding component of id, independent of ring ordering
276         (maxdeg of each var is 1)
277         of type int if id is of type poly, of type intmat else
278NOTE:    proc maxdeg1 returns 1 integer, the absolut maximum; moreover, it has
279         an option for computing weighted degrees
280EXAMPLE: example maxdeg; shows examples
281"
282{
283   //-------- subprocedure to find maximal degree of given component ----------
284   proc findmaxdeg
285   {
286      poly c = #[1];
287      if (c==0) { return(-1); }
288   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
289      int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
290      int i = d;
291      while ( c-jet(c,i) != 0 ) { i = 2*(i+1); }
292      int o = i-1;
293      int u = (d != i)*((i /  2)-1);
294   //----------------------- "quick search" for maxdeg ------------------------
295      while ( (c-jet(c,i)==0)*(c-jet(c,i-1)!=0) == 0)
296      {
297         i = (o+1+u) /  2;
298         if (c-jet(c,i)!=0) { u = i+1; }
299         else { o = i-1; }
300      }
301      return(i);
302   }
303//------------------------------ main program ---------------------------------
304   matrix M = matrix(id);
305   int r,c = nrows(M), ncols(M); int i,j;
306   intmat m[r][c];
307   for (i=r; i>0; i=i-1)
308   {
309      for (j=c; j>0; j=j-1) { m[i,j] = findmaxdeg(M[i,j]); }
310   }
311   if (typeof(id)=="poly") { return(m[1,1]); }
312   return(m);
313}
314//-------------------------------- examples -----------------------------------
315example
316{ "EXAMPLE:"; echo = 2;
317   ring r = 0,(x,y,z),wp(-1,-2,-3);
318   poly f = x+y2+z3;
319   deg(f);               //deg; returns weighted degree (in case of 1 block)!
320   maxdeg(f);
321   matrix m[2][2]=f+x10,1,0,f^2;
322   maxdeg(m);
323}
324///////////////////////////////////////////////////////////////////////////////
325
326proc maxdeg1 (id,list #)
327"USAGE:   maxdeg1(id[,v]);  id=poly/ideal/vector/module/matrix, v=intvec
328RETURN:  integer, maximal [weighted] degree of monomials of id independent of
329         ring ordering, maxdeg1 of i-th variable is v[i] (default: v=1..1).
330NOTE:    This proc returns one integer while maxdeg returns, in general,
331         a matrix of integers. For one polynomial and if no intvec v is given
332         maxdeg is faster
333EXAMPLE: example maxdeg1; shows examples
334"
335{
336   //-------- subprocedure to find maximal degree of given component ----------
337   proc findmaxdeg
338   {
339      poly c = #[1];
340      if (c==0) { return(-1); }
341      intvec v = #[2];
342   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
343      int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
344      int i = d;
345      if ( c == jet(c,-1,v))      //case: maxdeg is negative
346      {
347         i = -d;
348         while ( c == jet(c,i,v) ) { i = 2*(i-1); }
349         int o = (d != -i)*((i /  2)+2) - 1;
350         int u = i+1;
351         int e = -1;
352      }
353      else                        //case: maxdeg is nonnegative
354      {
355         while ( c != jet(c,i,v) ) { i = 2*(i+1); }
356         int o = i-1;
357         int u = (d != i)*((i /  2)-1);
358         int e = 1;
359      }
360   //----------------------- "quick search" for maxdeg ------------------------
361      while ( ( c==jet(c,i,v) )*( c!=jet(c,i-1,v) ) == 0 )
362      {
363         i = (o+e+u) /  2;
364         if ( c!=jet(c,i,v) ) { u = i+1; }
365         else { o = i-1; }
366      }
367      return(i);
368   }
369//------------------------------ main program ---------------------------------
370   ideal M = simplify(ideal(matrix(id)),8);   //delete scalar multiples from id
371   int c = ncols(M);
372   int i,n;
373   if( size(#)==0 )
374   {
375      int m = maxdeg(M[c]);
376      for (i=c-1; i>0; i=i-1)
377      {
378          n = maxdeg(M[i]);
379          m = (m>=n)*m + (m<n)*n;             //let m be the maximum of m and n
380      }
381   }
382   else
383   {
384      intvec v=#[1];                          //weight vector for the variables
385      int m = findmaxdeg(M[c],v);
386      for (i=c-1; i>0; i--)
387      {
388         n = findmaxdeg(M[i],v);
389         if( n>m ) { m=n; }
390      }
391   }
392   return(m);
393}
394//-------------------------------- examples -----------------------------------
395example
396{ "EXAMPLE:"; echo = 2;
397   ring r = 0,(x,y,z),wp(-1,-2,-3);
398   poly f = x+y2+z3;
399   deg(f);                  //deg returns weighted degree (in case of 1 block)!
400   maxdeg1(f);
401   intvec v = ringweights(r);
402   maxdeg1(f,v);                             //weighted maximal degree
403   matrix m[2][2]=f+x10,1,0,f^2;
404   maxdeg1(m,v);                             //absolut weighted maximal degree
405}
406///////////////////////////////////////////////////////////////////////////////
407
408proc mindeg (id)
409"USAGE:   mindeg(id);  id  poly/ideal/vector/module/matrix
410RETURN:  minimal degree/s of monomials of id, independent of ring ordering
411         (mindeg of each variable is 1) of type int if id of type poly, else
412         of type intmat.
413NOTE:    proc mindeg1 returns one integer, the absolut minimum; moreover it
414         has an option for computing weighted degrees.
415EXAMPLE: example mindeg; shows examples
416"
417{
418   //--------- subprocedure to find minimal degree of given component ---------
419   proc findmindeg
420   {
421      poly c = #[1];
422      if (c==0) { return(-1); }
423   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
424      int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
425      int i = d;
426      while ( jet(c,i) == 0 ) { i = 2*(i+1); }
427      int o = i-1;
428      int u = (d != i)*((i /  2)-1);
429   //----------------------- "quick search" for mindeg ------------------------
430      while ( (jet(c,u)==0)*(jet(c,o)!=0) )
431      {
432         i = (o+u) / 2;
433         if (jet(c,i)==0) { u = i+1; }
434         else { o = i-1; }
435      }
436      if (jet(c,u)!=0) { return(u); }
437      else { return(o+1); }
438   }
439//------------------------------ main program ---------------------------------
440   matrix M = matrix(id);
441   int r,c = nrows(M), ncols(M); int i,j;
442   intmat m[r][c];
443   for (i=r; i>0; i=i-1)
444   {
445      for (j=c; j>0; j=j-1) { m[i,j] = findmindeg(M[i,j]); }
446   }
447   if (typeof(id)=="poly") { return(m[1,1]); }
448   return(m);
449}
450//-------------------------------- examples -----------------------------------
451example
452{ "EXAMPLE:"; echo = 2;
453   ring r = 0,(x,y,z),ls;
454   poly f = x5+y2+z3;
455   ord(f);                      // ord returns weighted order of leading term!
456   mindeg(f);                   // computes minimal degree
457   matrix m[2][2]=x10,1,0,f^2;
458   mindeg(m);                   // computes matrix of minimum degrees
459}
460///////////////////////////////////////////////////////////////////////////////
461
462proc mindeg1 (id, list #)
463"USAGE:   mindeg1(id[,v]);  id=poly/ideal/vector/module/matrix, v=intvec
464RETURN:  integer, minimal [weighted] degree of monomials of id independent of
465         ring ordering, mindeg1 of i-th variable is v[i] (default v=1..1).
466NOTE:    This proc returns one integer while mindeg returns, in general,
467         a matrix of integers. For one polynomial and if no intvec v is given
468         mindeg is faster.
469EXAMPLE: example mindeg1; shows examples
470"
471{
472   //--------- subprocedure to find minimal degree of given component ---------
473   proc findmindeg
474   {
475      poly c = #[1];
476      intvec v = #[2];
477      if (c==0) { return(-1); }
478   //--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
479      int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
480      int i = d;
481      if ( jet(c,-1,v) !=0 )      //case: mindeg is negative
482      {
483         i = -d;
484         while ( jet(c,i,v) != 0 ) { i = 2*(i-1); }
485         int o = (d != -i)*((i /  2)+2) - 1;
486         int u = i+1;
487         int e = -1; i=u;
488      }
489      else                        //case: inded is nonnegative
490      {
491         while ( jet(c,i,v) == 0 ) { i = 2*(i+1); }
492         int o = i-1;
493         int u = (d != i)*((i /  2)-1);
494         int e = 1; i=u;
495      }
496   //----------------------- "quick search" for mindeg ------------------------
497      while ( (jet(c,i-1,v)==0)*(jet(c,i,v)!=0) == 0 )
498      {
499         i = (o+e+u) /  2;
500         if (jet(c,i,v)==0) { u = i+1; }
501         else { o = i-1; }
502      }
503      return(i);
504   }
505//------------------------------ main program ---------------------------------
506   ideal M = simplify(ideal(matrix(id)),8);   //delete scalar multiples from id
507   int c = ncols(M);
508   int i,n;
509   if( size(#)==0 )
510   {
511      int m = mindeg(M[c]);
512      for (i=c-1; i>0; i=i-1)
513      {
514          n = mindeg(M[i]);
515          m = (m<=n)*m + (m>n)*n;             //let m be the maximum of m and n
516      }
517   }
518   else
519   {
520      intvec v=#[1];                          //weight vector for the variables
521      int m = findmindeg(M[c],v);
522      for (i=c-1; i>0; i=i-1)
523      {
524         n = findmindeg(M[i],v);
525         m = (m<=n)*m + (m>n)*n;              //let m be the maximum of m and n
526      }
527   }
528   return(m);
529}
530//-------------------------------- examples -----------------------------------
531example
532{ "EXAMPLE:"; echo = 2;
533   ring r = 0,(x,y,z),ls;
534   poly f = x5+y2+z3;
535   ord(f);                      // ord returns weighted order of leading term!
536   intvec v = 1,-3,2;
537   mindeg1(f,v);                // computes minimal weighted degree
538   matrix m[2][2]=x10,1,0,f^2;
539   mindeg1(m,1..3);             // computes absolut minimum of weighted degrees
540}
541///////////////////////////////////////////////////////////////////////////////
542
543proc normalize (id)
544"USAGE:   normalize(id);  id=poly/vector/ideal/module
545RETURN:  object of same type with leading coefficient equal to 1
546EXAMPLE: example normalize; shows an example
547"
548{
549   return(simplify(id,1));
550}
551//-------------------------------- examples -----------------------------------
552example
553{  "EXAMPLE:"; echo = 2;
554   ring r = 0,(x,y,z),ls;
555   poly f = 2x5+3y2+4z3;
556   normalize(f);
557   module m=[9xy,0,3z3],[4z,6y,2x];
558   normalize(m);
559   ring s = 0,(x,y,z),(c,ls);
560   module m=[9xy,0,3z3],[4z,6y,2x];
561   normalize(m);
562   normalize(matrix(m));             // by automatic type conversion to module!
563}
564///////////////////////////////////////////////////////////////////////////////
565
566////////////////////////////////////////////////////////////////////////////////
567// Input: <ideal>=<f1,f2,...,fm> and <polynomial> g
568// Question: Does g lie in the radical of <ideal>?
569// Solution: Compute a standard basis G for <f1,f2,...,fm,gz-1> where z is a new
570//           variable. Then g is contained in the radical of <ideal> <=> 1 is
571//           generator in G.
572////////////////////////////////////////////////////////////////////////////////
573proc rad_con (poly g,ideal I)
574"  USAGE:   rad_con(<poly>,<ideal>);
575  RETURNS: 1 (TRUE) (type <int>) if <poly> is contained in the radical of
576           <ideal>, 0 (FALSE) (type <int>) otherwise
577  EXAMPLE: example rad_con; shows an example
578"
579{ def br=basering;
580  int n=nvars(br);
581  int dB=degBound;
582  degBound=0;
583  string mp=string(minpoly);
584  execute "ring R=("+charstr(br)+"),(x(1..n),z),dp;";
585  execute "minpoly=number("+mp+");";
586  ideal irrel=x(1..n);
587  map f=br,irrel;
588  poly p=f(g);
589  ideal J=f(I)+ideal(p*z-1);
590  J=std(J);
591  degBound=dB;
592  if (J[1]==1)
593  { return(1);
594  }
595  else
596  { return(0);
597  }
598}
599example
600{ "  EXAMPLE: Sturmfels: Algorithms in Invariant Theory 2.3.7.";
601  echo=2;
602           ring R=0,(x,y,z),dp;
603           ideal I=x2+y2,z2;
604           poly f=x4+y4;
605           rad_con(f,I);
606           ideal J=x2+y2,z2,x4+y4;
607           poly g=z;
608           rad_con(g,I);
609}
610
611///////////////////////////////////////////////////////////////////////////////
612
613proc lcm (ideal i)
614"USAGE:   lcm(i); i ideal
615RETURN:  poly = lcm(i[1],...,i[size(i)])
616NOTE:
617EXAMPLE: example lcm; shows an example
618"
619{
620  int k,j;
621   poly p,q;
622  i=simplify(i,10);
623  for(j=1;j<=size(i);j++)
624  {
625    if(deg(i[j])>0)
626    {
627      p=i[j];
628      break;
629    }
630  }
631  if(deg(p)==-1)
632  {
633    return(1);
634  }
635  for (k=j+1;k<=size(i);k++)
636  {
637     if(deg(i[k])!=0)
638     {
639        q=gcd(p,i[k]);
640        if(deg(q)==0)
641        {
642           p=p*i[k];
643        }
644        else
645        {
646           p=p/q;
647           p=p*i[k];
648        }
649     }
650   }
651  return(p);
652}
653example
654{ "EXAMPLE:"; echo = 2;
655   ring  r = 0,(x,y,z),lp;
656   poly  p = (x+y)*(y+z);
657   poly  q = (z4+2)*(y+z);
658   ideal l=p,q;
659   poly  pr= lcm(l);
660   pr;
661   l=1,-1,p,1,-1,q,1;
662   pr=lcm(l);
663   pr;
664}
665
666///////////////////////////////////////////////////////////////////////////////
667
668proc content(f)
669"USAGE:   content(f); f polynomial/vector
670RETURN:  number, the content (greatest common factor of coefficients)
671         of the polynomial/vector f
672EXAMPLE: example content; shows an example
673"
674{
675  return(leadcoef(f)/leadcoef(cleardenom(f)));
676}
677example
678{ "EXAMPLE:"; echo = 2;
679   ring r=0,(x,y,z),(c,lp);
680   content(3x2+18xy-27xyz);
681   vector v=[3x2+18xy-27xyz,15x2+12y4,3];
682   content(v);
683}
684///////////////////////////////////////////////////////////////////////////////
685
686proc numerator(number n)
687"USAGE: numerator(n); n number
688RETURN: number, the numerator of n
689SEE ALSO: denominator, content, cleardenom
690EXAMPLE: example numerator; shows an example
691"
692{
693  poly p = n*var(1) + 1;
694  p = cleardenom(p);
695 
696  if (lead(var(1) + 1) == 1)
697  {
698    p = p - lead(p);
699  }
700 
701  return (leadcoef(p));
702}
703example
704{
705  "EXAMPLE:"; echo = 2;
706  ring r = 0,x, dp;
707  number n = 3/2;
708  numerator(n);
709}
710
711///////////////////////////////////////////////////////////////////////////////
712
713proc denominator(number n)
714"USAGE: denominator(n); n number
715RETURN: number, the denominator of n
716SEE ALSO: numerator, content, cleardenom
717EXAMPLE: example denominator; shows an example
718"
719{
720  poly p = n*var(1) + 1;
721  p = cleardenom(p);
722 
723  if (lead(var(1) + 1) != 1)
724  {
725    p = p - lead(p);
726  }
727 
728  return (leadcoef(p));
729}
730example
731{
732  "EXAMPLE:"; echo = 2;
733  ring r = 0,x, dp;
734  number n = 3/2;
735  denominator(n);
736}
737
738
739
740 
Note: See TracBrowser for help on using the repository browser.