source: git/Singular/LIB/multigrading.lib @ 63da27

spielwiese
Last change on this file since 63da27 was 63da27, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
fixed: conformance with Singular rules git-svn-id: file:///usr/local/Singular/svn/trunk@13260 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 54.1 KB
Line 
1///////////////////////////////////////////////////////////////////
2version="$Id$";
3category="Combinatorial Commutative Algebra";
4info="
5LIBRARY:  multigrading.lib          Multigraded Rings
6
7AUTHORS:  Rene Birkner, rbirkner@math.fu-berlin.de
8@*        Lars Kastner, lkastner@math.fu-berlin.de
9@*        Oleksandr Motsak, U@D, where U={motsak}, D={mathematik.uni-kl.de}
10
11
12OVERVIEW: using this library allows one can virtually add multigrading to Singular.
13For more see http://code.google.com/p/convex-singular/wiki/Multigrading
14For theoretical references see:
15E. Miller, B. Sturmfels: 'Combinatorial Commutative Algebra' and
16M. Kreuzer, L. Robbiano: 'Computational Commutative Algebra'.
17
18NOTE: 'mDegBasis' relies on 4ti2 for computing Hilbert Bases.
19
20PROCEDURES:
21setBaseMultigrading(M,T); attach multiweights/torsion matrices to the basering
22getVariableWeights([R]);  get matrix of multidegrees of vars attached to a ring
23getTorsion([R]);          get torsion matrix attached to a ring
24
25setModuleGrading(M,v);    attach multiweights of units to a module and return it
26getModuleGrading(M);      get multiweights of module units (attached to M)
27
28mDeg(A);                  compute the multidegree of A
29mDegBasis(d);             compute all monomials of multidegree d
30mDegPartition(p);         compute the multigraded-homogenous components of p
31
32isTorsionFree();          test whether the current multigrading is torsion free
33isTorsionElement(p);      test whether p has zero multidegree
34isHomogenous(a);          test whether 'a' is multigraded-homogenous
35
36equalMDeg(e1,e2[,V]);     test whether e1==e2 in the current multigrading
37
38mDegGroebner(M);          compute the multigraded GB/SB of M
39mDegSyzygy(M);            compute the multigraded syzygies of M
40mDegResolution(M,l[,m]);  compute the multigraded resolution of M
41
42defineHomogenous(p);      get a torsion matrix wrt which p becomes homogenous
43pushForward(f);           find the finest grading on the image ring, homogenizing f
44
45hermite(A);               compute the Hermite Normal Form of a matrix
46
47hilbertSeries(M);         compute the multigraded Hilbert Series of M
48
49           (parameters in square brackets [] are optional)
50
51KEYWORDS:  multigradeding, multidegree, multiweights, multigraded-homogenous
52";
53
54// finestMDeg(def r)
55// newMap(map F, intmat Q, list #)
56
57LIB "standard.lib"; // for groebner
58
59/******************************************************/
60proc setBaseMultigrading(intmat M, list #)
61"USAGE: setBaseMultigrading(M[, T]); M, T are integer matrices
62PURPOSE: attaches weights of variables and torsion to the basering.
63NOTE: M encodes the weights of variables column-wise.
64The torsion is given by the lattice spanned by the columns of the integer
65matrix T in Z^nrows(M) over Z.
66RETURN: nothing
67EXAMPLE: example setBaseMultigrading; shows an example
68"
69{
70  string attrMgrad   = "mgrad";
71  string attrTorsion = "torsion";
72  string attrTorsionHNF = "torsion_hermite";
73
74
75  attrib(basering, attrMgrad, M);
76 
77  if( size(#) > 0 and typeof(#[1]) == "intmat" )
78  {
79    def T = #[1];
80  } else
81  {
82    intmat T[nrows(M)][1];
83  }
84
85  if( nrows(T) == nrows(M) )
86  {
87    attrib(basering, attrTorsion, T); 
88    def H;
89    attrib(basering, attrTorsionHNF, H);       
90  }
91  else
92  {
93    ERROR("Incompatible matrix sizes!");
94  }
95}
96example
97{
98  "EXAMPLE:"; echo=2;
99   
100  ring R = 0, (x, y, z), dp;
101
102  // Weights of variables
103  intmat M[3][3] =
104    1, 0, 0,
105    0, 1, 0,
106    0, 0, 1;
107
108  // Torsion:
109  intmat L[3][2] =
110    1, 1,
111    1, 3,
112    1, 5;
113   
114  // attaches M & L to R (==basering):
115  setBaseMultigrading(M, L); // Grading: Z^3/L
116
117  // Weights are accessible via "getVariableWeights()":
118  getVariableWeights() == M;
119  getVariableWeights(R) == M;
120  getVariableWeights(basering) == M;
121
122  // Torsion is accessible via "getTorsion()":
123  getTorsion() == L;
124  getTorsion(R) == L;
125  getTorsion(basering) == L;
126
127  // And its hermite NF via getTorsion("hermite"):
128  intmat H = hermite(L);
129  getTorsion("hermite") == H;
130  getTorsion(R, "hermite") == H;
131  getTorsion(basering, "hermite") == H;
132
133 
134
135  kill L, M;
136
137  // ----------- isomorphic multigrading -------- //
138
139  // Weights of variables
140  intmat M[2][3] =
141    1, -2, 1,
142    1,  1, 0;
143
144  // Torsion:
145  intmat L[2][1] =
146    0,
147    2;
148   
149  // attaches M & L to R (==basering):
150  setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
151
152  // Weights are accessible via "getVariableWeights()":
153  getVariableWeights() == M;
154
155  // Torsion is accessible via "getTorsion()":
156  getTorsion() == L;
157
158  kill L, M;
159  // ----------- extreme case ------------ //
160
161  // Weights of variables
162  intmat M[1][3] =
163    1,  -1, 10;
164
165  // Torsion:
166  intmat L[1][1] =
167    0;
168   
169  // attaches M & L to R (==basering):
170  setBaseMultigrading(M); // Grading: Z^3
171
172  // Weights are accessible via "getVariableWeights()":
173  getVariableWeights() == M;
174
175  // Torsion is accessible via "getTorsion()":
176  getTorsion() == L;
177}
178
179
180/******************************************************/
181proc getVariableWeights(list #)
182"USAGE: getVariableWeights([R])
183PURPOSE: get associated multigrading matrix for the basering [or R]
184RETURN:  intmat, matrix of multidegrees of variables
185EXAMPLE: example getVariableWeights; shows an example
186"
187{
188  string attrMgrad = "mgrad";
189
190
191  if( size(#) > 0 )
192  {
193    if(( typeof(#[1]) == "ring" ) || ( typeof(#[1]) == "qring" ))
194    {
195      def R = #[1];
196    }
197    else
198    {
199      ERROR("Optional argument must be a ring!");
200    }
201  }
202  else
203  {
204    def R = basering;
205  }
206
207  def M = attrib(R, attrMgrad);
208  if( typeof(M) == "intmat"){ return (M); }
209  ERROR( "Sorry no multigrading matrix!" ); 
210}
211example
212{
213  "EXAMPLE:"; echo=2;
214   
215  ring R = 0, (x, y, z), dp;
216
217  // Weights of variables
218  intmat M[3][3] =
219    1, 0, 0,
220    0, 1, 0,
221    0, 0, 1;
222
223  // Torsion:
224  intmat L[3][2] =
225    1, 1,
226    1, 3,
227    1, 5;
228   
229  // attaches M & L to R (==basering):
230  setBaseMultigrading(M, L); // Grading: Z^3/L
231
232  // Weights are accessible via "getVariableWeights()":
233  getVariableWeights() == M;
234
235  kill L, M;
236
237  // ----------- isomorphic multigrading -------- //
238
239  // Weights of variables
240  intmat M[2][3] =
241    1, -2, 1,
242    1,  1, 0;
243
244  // Torsion:
245  intmat L[2][1] =
246    0,
247    2;
248   
249  // attaches M & L to R (==basering):
250  setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
251
252  // Weights are accessible via "getVariableWeights()":
253  getVariableWeights() == M;
254
255  kill L, M;
256
257  // ----------- extreme case ------------ //
258
259  // Weights of variables
260  intmat M[1][3] =
261    1,  -1, 10;
262
263  // Torsion:
264  intmat L[1][1] =
265    0;
266   
267  // attaches M & L to R (==basering):
268  setBaseMultigrading(M); // Grading: Z^3
269
270  // Weights are accessible via "getVariableWeights()":
271  getVariableWeights() == M;
272}
273
274/******************************************************/
275proc getTorsion(list #)
276"USAGE: getTorsion([R[,opt]])
277PURPOSE: get associated torsion matrix, i.e. generators (cols) of the Torsion group
278RETURN: intmat, the torsion matrix, or its hermite normal form
279        if an optional argument (\"hermite\") is given
280"
281{
282  string attrTorsion    = "torsion";
283  string attrTorsionHNF = "torsion_hermite";
284
285  int i = 1;
286
287  if( size(#) >= i )
288  {
289    if( ( typeof(#[i]) == "ring" ) or ( typeof(#[i]) == "qring" ) )
290    {
291      def R = #[i];
292      i++;
293    }
294  }
295
296  if( !defined(R) )
297  {
298    def R = basering;
299  }
300
301  if( size(#) >= i )
302  {
303    if( #[i] == "hermite" )
304    {
305      if( typeof(attrib(R, attrTorsionHNF)) != "intmat" )
306      {
307        def M = getTorsion(R);
308        if( typeof(M) != "intmat")
309        {
310          ERROR( "Sorry no torsion matrix!" ); 
311        }
312        attrib(R, attrTorsionHNF, hermite(M)); // this might not work with R != basering...
313      }
314      return (attrib(R, attrTorsionHNF));
315    }
316  }
317
318  def M = attrib(R, attrTorsion);
319  if( typeof(M) != "intmat")
320  {
321    ERROR( "Sorry no torsion matrix!" ); 
322  }
323  return (M);
324}
325example
326{
327  "EXAMPLE:"; echo=2;
328   
329  ring R = 0, (x, y, z), dp;
330
331  // Weights of variables
332  intmat M[3][3] =
333    1, 0, 0,
334    0, 1, 0,
335    0, 0, 1;
336
337  // Torsion:
338  intmat L[3][2] =
339    1, 1,
340    1, 3,
341    1, 5;
342   
343  // attaches M & L to R (==basering):
344  setBaseMultigrading(M, L); // Grading: Z^3/L
345
346  // Torsion is accessible via "getTorsion()":
347  getTorsion() == L;
348
349  // its hermite NF:
350  print(getTorsion("hermite"));
351
352  kill L, M;
353
354  // ----------- isomorphic multigrading -------- //
355
356  // Weights of variables
357  intmat M[2][3] =
358    1, -2, 1,
359    1,  1, 0;
360
361  // Torsion:
362  intmat L[2][1] =
363    0,
364    2;
365   
366  // attaches M & L to R (==basering):
367  setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
368
369  // Torsion is accessible via "getTorsion()":
370  getTorsion() == L;
371
372  // its hermite NF:
373  print(getTorsion("hermite"));
374
375  kill L, M;
376
377  // ----------- extreme case ------------ //
378
379  // Weights of variables
380  intmat M[1][3] =
381    1,  -1, 10;
382
383  // Torsion:
384  intmat L[1][1] =
385    0;
386   
387  // attaches M & L to R (==basering):
388  setBaseMultigrading(M); // Grading: Z^3
389
390  // Torsion is accessible via "getTorsion()":
391  getTorsion() == L;
392
393  // its hermite NF:
394  print(getTorsion("hermite"));
395}
396
397/******************************************************/
398proc getModuleGrading(def m)
399"USAGE: getModuleGrading(m), 'm' module/vector
400RETURN: integer matrix of the multiweights of free module generators attached to 'm'
401"
402{
403  string attrModuleGrading = "genWeights";
404
405  //  print(m);  typeof(m);  attrib(m);
406
407  def V = attrib(m, attrModuleGrading);
408
409  if( typeof(V) != "intmat" )
410  {
411    if( (typeof(m) == "ideal") or (typeof(m) == "poly") )
412    {
413      intmat M = getVariableWeights();
414      intmat VV[nrows(M)][1];
415      return (VV);
416    }
417     
418    ERROR("Sorry: vector or module need module-grading-matrix! See 'getModuleGrading'.");
419  }
420
421  if( nrows(V) != nrows(getVariableWeights()) )
422  {
423    ERROR("Sorry wrong height of V: " + string(nrows(V)));
424  }
425
426  if( ncols(V) < nrows(m) )
427  {
428    ERROR("Sorry wrong width of V: " + string(ncols(V)));
429  }
430   
431  return (V);
432}
433example
434{
435  "EXAMPLE:"; echo=2;
436   
437   ring R = 0, (x,y), dp;
438   intmat M[2][2]=
439     1, 1,
440     0, 2;
441   intmat T[2][5]=
442     1,  2,  3,  4, 0,
443     0, 10, 20, 30, 1;
444   
445   setBaseMultigrading(M, T);
446   
447   ideal I = x, y, xy^5;
448   isHomogenous(I);
449 
450   intmat V = mDeg(I); print(V);
451
452   module S = syz(I); print(S);
453   
454   S = setModuleGrading(S, V);
455
456   getModuleGrading(S) == V;
457   
458   vector v = setModuleGrading(S[1], V);
459   getModuleGrading(v) == V;
460   isHomogenous(v);
461   print( mDeg(v) );   
462   
463   isHomogenous(S);
464   print( mDeg(S) );
465}
466
467/******************************************************/
468proc setModuleGrading(def m, intmat G)
469"USAGE: setModuleGrading(m, G), m module/vector, G intmat
470PURPOSE: attaches the multiweights of free module generators to 'm'
471WARNING: The method does not verify that the multigrading makes the
472         module/vector homogenous. One can do that using isHomogenous(m).
473"
474{
475  string attrModuleGrading = "genWeights";
476
477  intmat R = getVariableWeights();
478
479  if(nrows(G) != nrows(R)){ ERROR("Incompatible gradings.");}
480  if(ncols(G) < nrows(m)){ ERROR("Multigrading does not fit to module.");}
481
482  attrib(m, attrModuleGrading, G);
483  return(m);
484}
485example
486{
487  "EXAMPLE:"; echo=2;
488   
489   ring R = 0, (x,y), dp;
490   intmat M[2][2]=
491     1, 1,
492     0, 2;
493   intmat T[2][5]=
494     1,  2,  3,  4, 0,
495     0, 10, 20, 30, 1;
496   
497   setBaseMultigrading(M, T);
498   
499   ideal I = x, y, xy^5;
500   intmat V = mDeg(I);
501   
502   // V == M; modulo T
503   print(V);
504
505   module S = syz(I);
506   
507   S = setModuleGrading(S, V);
508   getModuleGrading(S) == V;
509
510   print(S);
511   
512   vector v = S[1]; v = setModuleGrading(v, V);
513   getModuleGrading(v) == V;
514
515   print( mDeg(v) );   
516
517   isHomogenous(S);
518
519   print( mDeg(S) );
520}
521
522
523
524
525/******************************************************/
526proc isTorsionFree()
527"USAGE: isTorsionFree()
528PURPOSE: Determines whether the multigrading attached to the current ring is torsion-free.
529RETURN: boolean, the result of the test
530"
531{
532
533  intmat H = hermite(transpose(getTorsion("hermite"))); // TODO: ?cache it?
534
535  int i, j;
536  int r = nrows(H);
537  int c = ncols(H);
538  int d = 1;
539  for( i = 1; (i <= c) && (i <= r); i++ )
540  {
541    for( j = i; (H[j, i] == 0)&&(j < r); j++ )
542    {
543    }
544
545    if(H[j, i]!=0)
546    {
547      d=d*H[j, i];
548    }
549  }
550
551  if( (d*d)==1 )
552  {
553    return(1==1);
554  }
555  return(0==1);
556}
557example
558{
559  "EXAMPLE:"; echo=2;
560
561   ring R = 0,(x,y),dp;
562   intmat M[2][2]=
563     1,0,
564     0,1;
565   intmat T[2][5]=
566     1, 2, 3, 4, 0,
567     0,10,20,30, 1;
568   
569   setBaseMultigrading(M,T);
570   
571   // Is the resulting group torsion free?
572   isTorsionFree();
573
574   kill R, M, T;
575   ///////////////////////////////////////////
576
577   ring R=0,(x,y,z),dp;
578   intmat A[3][3] =
579     1,0,0,
580     0,1,0,
581     0,0,1;
582   intmat B[3][4]=
583     3,3,3,3,
584     2,1,3,0,
585     1,2,0,3;
586   setBaseMultigrading(A,B);
587   // Is the resulting group torsion free?
588   isTorsionFree();
589
590   kill R, A, B;
591}
592
593
594
595/******************************************************/
596proc hermite(intmat A)
597"USAGE: hermite( A );
598PROCEDURE: Computes the Hermite Normal Form of the matrix A by column operations.
599RETURN: intmat, the Hermite Normal Form of A
600"
601{
602  intmat g;
603  int i,j,k, save, d, a1, a2, c, l;
604  c=0;
605  l=0;
606  for(i=1; ((i+l)<=nrows(A))&&((i+l)<=ncols(A)); i++)
607  {
608    //i;
609    if(A[i+l, i]==0)
610    {
611      for(j=i;j<=ncols(A); j++)
612      {
613        if(A[i+l, j]!=0)
614        {
615          for(k=1;k<=nrows(A);k++)
616          {
617            save=A[k, i];
618            A[k, i]=A[k, j];
619            A[k, j]=save;
620          }
621          break;
622        }
623        if(j==ncols(A)){ c=1; l=l+1; }
624      }
625    }
626
627    if((i+l)>nrows(A)){ break; }
628   
629    if(A[i+l, i]<0)
630    {
631      for(k=1;k<=nrows(A);k++){ A[k, i]=A[k, i]*(-1); }
632    }
633
634    if(c==0)
635    {
636      for(j=i+1;j<=ncols(A);j++)
637      {
638        //A;
639        if(A[i+l, j]<0)
640        {
641          for(k=1;k<=nrows(A);k++){ A[k, j]=(-1)*A[k, j];}
642        }
643
644        if(A[i+l, i]==1)
645        {
646          d=A[i+l, j];
647          for(k=1;k<=nrows(A);k++)
648          {
649            A[k, j]=A[k, j]-d*A[k, i];
650          }
651        }
652        else
653        {
654          while((A[i+l, i] * A[i+l, j])!=0)
655          {
656            if(A[i+l, i]> A[i+l, j])
657            {
658
659              for(k=1;k<=nrows(A);k++)
660              {
661                save=A[k, i];
662                A[k, i]=A[k, j];
663                A[k, j]=save;
664              }
665            }
666            a1=A[i+l, j]%A[i+l,i];
667            a2=A[i+l, j]-a1;
668            d=a2/A[i+l, i];
669            for(k=1;k<=nrows(A);k++)
670            {
671              A[k, j]=A[k, j]- d*A[k, i];
672            }
673          }
674        }
675      }
676      for(j=1;j<i;j++)
677      {
678        a1=A[i+l, j]%A[i+l,i];
679        d=(A[i+l, j]-a1)/A[i+l, i];
680        for(k=1;k<=nrows(A);k++){ A[k, j]=A[k, j]-d*A[k, i];}
681      }
682    }
683    c=0;
684  }
685  return( A);
686}
687example
688{
689  "EXAMPLE:"; echo=2;
690
691   intmat M[2][5] =
692     1, 2, 3, 4, 0,
693     0,10,20,30, 1;
694
695   // Hermite Normal Form of M:
696   print(hermite(M));
697
698   intmat T[3][4] =
699     3,3,3,3,
700     2,1,3,0,
701     1,2,0,3;
702
703   // Hermite Normal Form of T:
704   print(hermite(T));
705
706   intmat A[4][5] =
707     1,2,3,2,2,
708     1,2,3,4,0,
709     0,5,4,2,1,
710     3,2,4,0,2;
711
712   // Hermite Normal Form of A:
713   print(hermite(A));
714}
715
716
717/******************************************************/
718proc isTorsionElement(intvec mdeg)
719"USAGE: isTorsionElement(intvec mdeg);
720PROCEDURE: For a integer vector mdeg representing the multidegree of some polynomial
721or vector this method computes if the multidegree is contained in the torsion
722group, i.e. if it is zero in the multigrading.
723"
724{
725  intmat H = getTorsion("hermite");
726  int x, k, i;
727
728  int r = nrows(H);
729  int c = ncols(H);
730
731  int rr = nrows(mdeg);
732
733  for( i = 1; (i<=r) && (i<=c); i++)
734  {
735    if(H[i, i]!=0)
736    {
737      x = mdeg[i]%H[i, i];
738
739      if(x!=0)
740      {
741        return(1==0);
742      }
743
744      x = mdeg[i] / H[i,i];
745
746      for( k=1; k <= rr; k++)
747      {
748        mdeg[k] = mdeg[k] - x*H[k,i];
749      }
750    }
751  }
752
753  return( mdeg == 0 );
754
755}
756example
757{
758 "EXAMPLE:"; echo=2;
759
760  ring r = 0,(x,y,z),dp;
761
762  intmat g[2][3]=
763    1,0,1,
764    0,1,1;
765  intmat t[2][1]=
766    -2,
767    1;
768
769  setBaseMultigrading(g,t);
770
771  poly a = x10yz;
772  poly b = x8y2z;
773  poly c = x4z2;
774  poly d = y5;
775  poly e = x2y2;
776  poly f = z2;
777
778  intvec v1 = mDeg(a) - mDeg(b);
779  v1;
780  isTorsionElement(v1);
781 
782  intvec v2 = mDeg(a) - mDeg(c);
783  v2;
784  isTorsionElement(v2);
785 
786  intvec v3 = mDeg(e) - mDeg(f);
787  v3;
788  isTorsionElement(v3);
789 
790  intvec v4 = mDeg(c) - mDeg(d);
791  v4;
792  isTorsionElement(v4);
793}
794
795
796/******************************************************/
797proc defineHomogenous(poly f, list #)
798"USAGE: defineHomogenous(f[, G]); polynomial f, integer matrix G
799PURPOSE: Yields a matrix which has to be appended to the torsion matrix to make the
800polynomial f homogenous in the grading by grad.
801"
802{
803  if( size(#) > 0 )
804  {
805    if( typeof(#[1]) == "intmat" )
806    {
807      intmat grad = #[1];
808    }
809  }
810
811  if( !defined(grad) )
812  {
813    intmat grad = getVariableWeights();
814  }
815
816  intmat newtor[nrows(grad)][size(f)-1];
817  int i,j;
818  intvec l = grad*leadexp(f);
819  intvec v;
820  for(i=2; i <= size(f); i++)
821  {
822    v = grad * leadexp(f[i]) - l;
823    for( j=1; j<=size(v); j++)
824    {
825      newtor[j,i-1] = v[j];
826    }
827  }
828  return(newtor);
829}
830example
831{
832  "EXAMPLE:"; echo=2;
833
834  ring r =0,(x,y,z),dp;
835  intmat grad[2][3] =
836    1,0,1,
837    0,1,1;
838
839  setBaseMultigrading(grad);
840
841  poly f = x2y3-z5+x-3zx;
842
843  intmat M = defineHomogenous(f);
844  M;
845  defineHomogenous(f, grad) == M;
846 
847  isHomogenous(f);
848  setBaseMultigrading(grad, M);
849  isHomogenous(f);
850}
851
852/******************************************************/
853proc pushForward(map f)
854"USAGE: pushForward(f);
855PURPOSE: Computes the finest grading of the image ring which makes the map f
856a map of graded rings. The group map between the two grading groups is given
857by transpose( (Id, 0) ). Pay attention that the group spanned by the columns of
858the torsion matrix may not be a subgroup of the grading group. Still all columns
859are needed to find the correct image of the preimage gradings.
860"
861{
862
863  int k,i,j;
864  f;
865
866  intmat oldgrad=getVariableWeights(preimage(f));
867  intmat oldtor=getTorsion(preimage(f));
868
869  int n=nvars(preimage(f));
870  int np=nvars(basering);
871  int p=nrows(oldgrad);
872  int pp=p+np;
873
874  intmat newgrad[pp][np];
875
876  for(i=1;i<=np;i++){ newgrad[p+i,i]=1;}
877
878  //newgrad;
879
880
881
882  list newtor;
883  intmat toadd;
884  int columns=0;
885
886  intmat toadd1[pp][n];
887  intvec v;
888  poly im;
889
890  for(i=1;i<=p;i++){
891    for(j=1;j<=n;j++){ toadd1[i,j]=oldgrad[i,j];}
892  }
893
894  for(i=1;i<=n;i++){
895    im=f[i];
896    //im;
897    toadd = defineHomogenous(im, newgrad);
898    newtor=insert(newtor,toadd);
899    columns=columns+ncols(toadd);
900
901    v=leadexp(f[i]);
902    for(j=p+1;j<=p+np;j++){ toadd1[j,i]=-v[j-p];}
903  }
904
905  newtor=insert(newtor,toadd1);
906  columns=columns+ncols(toadd1);
907
908
909  if(typeof(basering)=="qring"){
910    //"Entering qring";
911    ideal a=ideal(basering);
912    for(i=1;i<=size(a);i++){
913      toadd = defineHomogenous(a[i], newgrad);
914      //toadd;
915      columns=columns+ncols(toadd);
916      newtor=insert(newtor,toadd);
917    }
918  }
919
920  //newtor;
921  intmat imofoldtor[pp][ncols(oldtor)];
922  for(i=1; i<=nrows(oldtor);i++){
923    for(j=1; j<=ncols(oldtor); j++){
924      imofoldtor[i,j]=oldtor[i,j];
925    }
926  }
927
928  columns=columns+ncols(oldtor);
929  newtor=insert(newtor, imofoldtor);
930
931  intmat torsion[pp][columns];
932  columns=0;
933  for(k=1;k<=size(newtor);k++){
934    for(i=1;i<=pp;i++){
935      for(j=1;j<=ncols(newtor[k]);j++){torsion[i,j+columns]=newtor[k][i,j];}
936    }
937    columns=columns+ncols(newtor[k]);
938  }
939
940  torsion=hermite(torsion);
941  intmat result[pp][pp];
942  for(i=1;i<=pp;i++){
943    for(j=1;j<=pp;j++){result[i,j]=torsion[i,j];}
944  }
945
946  setBaseMultigrading(newgrad, result);
947
948}
949example
950{
951  "EXAMPLE:"; echo=2;
952
953  // Setting degrees for preimage ring.;
954  intmat grad[3][3] =
955    1,0,0,
956    0,1,0,
957    0,0,1;
958
959  ring r = 0,(x,y,z),dp;
960  keepring(r);
961  setBaseMultigrading(grad);
962
963  // grading on r:
964  getVariableWeights();
965  getTorsion();
966
967  ring R = 0,(a,b),dp;
968  ideal i=a2-b2+a6-b5+ab3,a7b+b15-ab6+a6b6;
969
970  // The quotient ring by this ideal will become our image ring.;
971  qring Q = std(i);
972  map f = r,-a2b6+b5+a3b+a2+ab,-a2b7-3a2b5+b4+a,a6-b6-b3+a2;
973  f;
974
975  // Pushing forward f:
976  pushForward(f);
977
978  // due to pushForward we have got new grading on Q
979  getVariableWeights();
980  getTorsion();
981 
982  // TODO: Unfortunately this is not a very spectacular example.;
983
984}
985
986
987/******************************************************/
988proc equalMDeg(intvec exp1, intvec exp2, list #)
989"USAGE: equalMDeg(exp1, exp2[, V]); intvec exp1, exp2, intmat V
990PURPOSE: Tests if the exponent vectors of two monomials (given by exp1 and exp2)
991represent the same multidegree.
992NOTE: the integer matrix V encodes multidegrees of module components,
993if module component is present in exp1 and exp2
994"
995{
996  if( size(exp1) != size(exp2) )
997  {
998    ERROR("Sorry: we cannot compare exponents comming from a polynomial and a vector yet!");
999  }
1000
1001  if( exp1 == exp2)
1002  {
1003    return (1==1);
1004  }
1005
1006
1007
1008  intmat M = getVariableWeights();
1009
1010  if( nrows(exp1) > ncols(M) ) // vectors => last exponent is the module component!
1011  {
1012    if( (size(#) == 0) or (typeof(#[1])!="intmat") )
1013    {
1014      ERROR("Sorry: wrong or missing module-unit-weights-matrix V!");
1015    }
1016    intmat V = #[1];
1017
1018    // typeof(V); print(V);
1019
1020    int N = ncols(M);
1021    int r = nrows(M);
1022
1023    intvec d = intvec(exp1[1..N]) - intvec(exp2[1..N]);
1024    intvec dm = intvec(V[1..r, exp1[N+1]]) - intvec(V[1..r, exp2[N+1]]);
1025
1026    intvec difference = M * d + dm;
1027  }
1028  else
1029  {
1030    intvec d = (exp1 - exp2);
1031    intvec difference = M * d;
1032  }
1033
1034  if (isFreeRepresented()) // no torsion!?
1035  {
1036    return ( difference == 0);
1037  }
1038  return ( isTorsionElement( difference ) );
1039}
1040example
1041{
1042  "EXAMPLE:"; echo=2;
1043
1044  ring r = 0,(x,y,z),dp;
1045
1046  intmat g[2][3]=
1047    1,0,1,
1048    0,1,1;
1049
1050  intmat t[2][1]=
1051    -2,
1052    1;
1053
1054  setBaseMultigrading(g,t);
1055
1056  poly a = x10yz;
1057  poly b = x8y2z;
1058  poly c = x4z2;
1059  poly d = y5;
1060  poly e = x2y2;
1061  poly f = z2;
1062
1063
1064  equalMDeg(leadexp(a), leadexp(b));
1065  equalMDeg(leadexp(a), leadexp(c));
1066  equalMDeg(leadexp(a), leadexp(d));
1067  equalMDeg(leadexp(a), leadexp(e));
1068  equalMDeg(leadexp(a), leadexp(f));
1069
1070  equalMDeg(leadexp(b), leadexp(c));
1071  equalMDeg(leadexp(b), leadexp(d));
1072  equalMDeg(leadexp(b), leadexp(e));
1073  equalMDeg(leadexp(b), leadexp(f));
1074
1075  equalMDeg(leadexp(c), leadexp(d));
1076  equalMDeg(leadexp(c), leadexp(e));
1077  equalMDeg(leadexp(c), leadexp(f));
1078
1079  equalMDeg(leadexp(d), leadexp(e));
1080  equalMDeg(leadexp(d), leadexp(f));
1081
1082  equalMDeg(leadexp(e), leadexp(f));
1083
1084}
1085
1086
1087
1088/******************************************************/
1089static proc isFreeRepresented()
1090"check whether the base muligrading is torsion-free (it is zero).
1091"
1092{
1093  intmat T = getTorsion();
1094
1095  intmat Z[nrows(T)][ncols(T)];
1096
1097  return (T == Z); // no torsion!
1098}
1099
1100
1101/******************************************************/
1102proc isHomogenous(def a, list #)
1103"USAGE: isHomogenous(a[, f]); a polynomial/vector/ideal/module
1104RETURN: boolean, TRUE if a is (multi)homogenous, and FALSE otherwise
1105"
1106{
1107  if( (typeof(a) == "poly") or (typeof(a) == "vector") )
1108  {
1109    return ( size(mDegPartition(a)) <= 1 )
1110  }
1111
1112  if( typeof(a) == "vector" or typeof(a) == "module" )
1113  {
1114    intmat V = getModuleGrading(a);
1115  }
1116
1117  if( (typeof(a) == "ideal") or (typeof(a) == "module") )
1118  {
1119    if(size(#) > 0)
1120    {
1121      if (#[1] == "checkGens")
1122      {
1123        def aa;
1124        for( int i = ncols(a); i > 0; i-- )
1125        {
1126          aa = a[i];
1127
1128          if(defined(V))
1129          {
1130            aa = setModuleGrading(aa, V);
1131          }
1132
1133          if(!isHomogenous(aa))
1134          {
1135            return(0==1);
1136          }
1137        }
1138        return(1==1);
1139      }
1140    }
1141
1142    def g = groebner(a); // !!!!
1143
1144    def b, aa; int j;
1145    for( int i = ncols(a); i > 0; i-- )
1146    {
1147      aa = a[i];
1148
1149      if(defined(V))
1150      {
1151        aa = setModuleGrading(aa, V);
1152      }
1153
1154      b = mDegPartition(aa);
1155      for( j = ncols(b); j > 0; j-- )
1156      {
1157        if(NF(b[j],g) != 0)
1158        {
1159          return(0==1);
1160        }
1161      }
1162    }
1163    return(1==1);
1164  } 
1165}
1166example
1167{
1168  "EXAMPLE:"; echo=2;
1169
1170  ring r = 0,(x,y,z),dp;
1171
1172  //Grading and Torsion matrices:
1173  intmat M[3][3] =
1174    1,0,0,
1175    0,1,0,
1176    0,0,1;
1177
1178  intmat T[3][1] =
1179    1,2,3;
1180
1181  setBaseMultigrading(M,T);
1182
1183  attrib(r);
1184
1185  poly f = x-yz;
1186
1187  mDegPartition(f);
1188  print(mDeg(_));
1189
1190  isHomogenous(f);   // f: is not homogenous
1191
1192  poly g = 1-xy2z3;
1193  isHomogenous(g); // g: is homogenous
1194  mDegPartition(g);
1195
1196  kill T;
1197  /////////////////////////////////////////////////////////
1198  // new Torsion matrix:
1199  intmat T[3][4] =
1200    3,3,3,3,
1201    2,1,3,0,
1202    1,2,0,3;
1203 
1204  setBaseMultigrading(M,T);
1205
1206  f;
1207  isHomogenous(f);
1208  mDegPartition(f);
1209
1210  // ---------------------
1211  g;
1212  isHomogenous(g);
1213  mDegPartition(g);
1214
1215  kill r, T, M;
1216
1217  ring R = 0, (x,y,z), dp;
1218
1219  intmat A[2][3] =
1220    0,0,1,
1221    3,2,1;
1222  intmat T[2][1] =
1223    -1,
1224     4;
1225  setBaseMultigrading(A, T);
1226
1227  isHomogenous(ideal(x2 - y3 -xy +z, x*y-z, x^3 - y^2*z + x^2 -y^3)); // 1
1228  isHomogenous(ideal(x2 - y3 -xy +z, x*y-z, x^3 - y^2*z + x^2 -y^3), "checkGens");
1229  isHomogenous(ideal(x+y, x2 - y2)); // 0
1230
1231  // Degree partition:
1232  mDegPartition(x2 - y3 -xy +z);
1233  mDegPartition(x3 -y2z + x2 -y3 + z + 1);
1234
1235 
1236  module N = gen(1) + (x+y) * gen(2), z*gen(3);
1237
1238  intmat V[2][3] = 0; // 1, 2, 3,  4, 5, 6; //  column-wise weights of components!!??
1239 
1240  vector v1, v2;
1241 
1242  v1 = setModuleGrading(N[1], V); v1;
1243  mDegPartition(v1);
1244  print( mDeg(_) );
1245
1246  v2 = setModuleGrading(N[2], V); v2;
1247  mDegPartition(v2);
1248  print( mDeg(_) );
1249
1250  N = setModuleGrading(N, V);
1251  isHomogenous(N);
1252  print( mDeg(N) );
1253
1254  ///////////////////////////////////////
1255
1256  V =
1257    1, 2, 3, 
1258    4, 5, 6;
1259
1260  v1 = setModuleGrading(N[1], V); v1;
1261  mDegPartition(v1);
1262  print( mDeg(_) );
1263
1264  v2 = setModuleGrading(N[2], V); v2;
1265  mDegPartition(v2);
1266  print( mDeg(_) );
1267
1268  N = setModuleGrading(N, V);
1269  isHomogenous(N);
1270  print( mDeg(N) );
1271
1272  ///////////////////////////////////////
1273
1274  V =
1275    0, 0, 0, 
1276    4, 1, 0;
1277
1278  N = gen(1) + x * gen(2), z*gen(3);
1279
1280  N = setModuleGrading(N, V); N;
1281  isHomogenous(N);
1282  print( mDeg(N) );
1283
1284  v1 = setModuleGrading(N[1], V); v1;
1285  mDegPartition(v1);
1286  print( mDeg(_) );
1287
1288  N = setModuleGrading(N, V); N;
1289  isHomogenous(N);
1290  print( mDeg(N) );
1291}
1292
1293/******************************************************/
1294proc mDeg(def A)
1295"USAGE: mDeg(A); any A
1296PURPOSE: compute multidegree
1297"
1298{
1299  if( defined(attrib(A, "grad")) > 0 )
1300  {
1301    return (attrib(A, "grad"));
1302  }
1303
1304  intmat M = getVariableWeights();
1305  int N = nvars(basering);
1306
1307  if( ncols(M) != N )
1308  {
1309    ERROR("Sorry wrong mgrad-size of M: " + string(ncols(M)));
1310  }
1311
1312  int r = nrows(M);
1313
1314  if( A == 0 )
1315  {
1316    intvec v; v[r] = 0;
1317    return (v);
1318  }
1319
1320  if( (typeof(A) == "vector") or (typeof(A) == "module") )
1321  {
1322    intmat V = getModuleGrading(A);
1323
1324    if( nrows(V) != r )
1325    {
1326      ERROR("Sorry wrong mgrad-size of V: " + string(nrows(V)));
1327    }
1328  }
1329
1330  intvec m; m[r] = 0;
1331
1332  if( typeof(A) == "poly" )
1333  {
1334    intvec v = leadexp(A); //  v;
1335    m = M * v;
1336
1337    // We assume homogeneous input!
1338    return(m);
1339
1340    A = A - lead(A);
1341    while( size(A) > 0 )
1342    {
1343      v = leadexp(A); //  v;
1344      m = max( m, M * v, r ); // ????
1345      A = A - lead(A);
1346    }
1347
1348    return(m);
1349  }
1350
1351
1352  if( typeof(A) == "vector" )
1353  {
1354    intvec v;
1355    v = leadexp(A); //  v;
1356    m = intvec(M * intvec(v[1..N])) + intvec(V[1..r, v[N+1]]);
1357
1358    // We assume homogeneous input!
1359    return(m);
1360
1361    A = A - lead(A);
1362    while( size(A) > 0 )
1363    {
1364      v = leadexp(A); //  v;
1365
1366      // intvec(M * intvec(v[1..N])) + intvec(V[1..r, v[N+1]]);
1367
1368      m = max( m, intvec(M * intvec(v[1..N])) + intvec(V[1..r, v[N+1]]), r ); // ???
1369
1370      A = A - lead(A);
1371    }
1372
1373    return(m);
1374  }
1375
1376  int i, j; intvec d;
1377
1378  if( typeof(A) == "ideal" )
1379  {
1380    intmat G[ r ] [ ncols(A)];
1381    for( i = ncols(A); i > 0; i-- )
1382    {
1383      d = mDeg( A[i] );
1384
1385      for( j = 1; j <= r; j++ ) // see ticket: 253
1386      {
1387        G[j, i] = d[j];
1388      }     
1389    }
1390    return(G);
1391  }
1392
1393  if( typeof(A) == "module" )
1394  {
1395    intmat G[ r ] [ ncols(A)];
1396    vector v;
1397
1398    for( i = ncols(A); i > 0; i-- )
1399    {
1400      v = setModuleGrading(A[i], V);
1401
1402      // G[1..r, i]
1403      d = mDeg(v);
1404
1405      for( j = 1; j <= r; j++ ) // see ticket: 253
1406      {
1407        G[j, i] = d[j];
1408      }     
1409
1410    }
1411
1412    return(G);
1413  }
1414 
1415}
1416example
1417{
1418  "EXAMPLE:"; echo=2;
1419
1420  ring r = 0,(x, y), dp;
1421
1422  intmat A[2][2] = 1, 0, 0, 1;
1423  print(A);
1424
1425  intmat Ta[2][1] = 0, 3;
1426  print(Ta);
1427
1428  //   attrib(A, "torsion", Ta); // to think about
1429
1430//  "poly:";
1431  setBaseMultigrading(A);
1432
1433
1434  mDeg( x*x, A );
1435  mDeg( y*y*y, A );
1436
1437  setBaseMultigrading(A, Ta);
1438 
1439  mDeg( x*x*y );
1440 
1441  mDeg( y*y*y*x );
1442 
1443  mDeg( x*y + x + 1 );
1444
1445  mDegPartition(x*y + x + 1);
1446
1447  print ( mDeg(0) );
1448  poly zero = 0;
1449  print ( mDeg(zero) );
1450
1451//  "ideal:";
1452 
1453  ideal I = y*x*x, x*y*y*y;
1454  print( mDeg(I) );
1455
1456  print ( mDeg(ideal(0)) );
1457  print ( mDeg(ideal(0,0,0)) );
1458
1459//  "vectors:";
1460 
1461  intmat B[2][2] = 0, 1, 1, 0;
1462  print(B);
1463 
1464  mDeg( setModuleGrading(y*y*y*gen(2), B ));
1465  mDeg( setModuleGrading(x*x*gen(1), B ));
1466
1467 
1468  vector V = x*gen(1) + y*gen(2);
1469  V = setModuleGrading(V, B);
1470  mDeg( V );
1471
1472  vector v1 = setModuleGrading([0, 0, 0], B);
1473  print( mDeg( v1 ) );
1474 
1475  vector v2 = setModuleGrading([0], B);
1476  print( mDeg( v2 ) );
1477
1478//  "module:";
1479 
1480  module D = x*gen(1), y*gen(2);
1481  D;
1482  D = setModuleGrading(D, B);
1483  print( mDeg( D ) );
1484 
1485
1486  module DD = [0, 0],[0, 0, 0];
1487  DD = setModuleGrading(DD, B);
1488  print( mDeg( DD ) );
1489
1490  module DDD = [0, 0];
1491  DDD = setModuleGrading(DDD, B);
1492  print( mDeg( DDD ) );
1493
1494};
1495
1496
1497
1498
1499
1500/******************************************************/
1501proc mDegPartition(def p)
1502"USAGE: mDegPartition(def p), p polynomial/vector
1503RETURNS: an ideal/module consisting of multigraded-homogeneous parts of p
1504"
1505{
1506  if( typeof(p) == "poly" )
1507  {
1508    ideal I;     
1509    poly mp, t, tt;
1510  }
1511  else
1512  {
1513    if(  typeof(p) == "vector" )
1514    {
1515      module I;     
1516      vector mp, t, tt;
1517    }
1518    else
1519    {
1520      ERROR("Wrong ARGUMENT type!");
1521    }
1522  }
1523
1524  if( typeof(p) == "vector" )
1525  {
1526    intmat V = getModuleGrading(p);
1527  }
1528  else
1529  {
1530    intmat V;
1531  }
1532
1533  if( size(p) > 1)
1534  {
1535    intvec m;
1536
1537    while( p != 0 )
1538    {
1539      m = leadexp(p);
1540      mp = lead(p);
1541      p = p - lead(p);
1542      tt = p; t = 0;
1543
1544      while( size(tt) > 0 )
1545      {
1546        // TODO: we make no caching of matrices (M,T,H,V), which remain the same!
1547        if( equalMDeg( leadexp(tt), m, V  ) )
1548        {
1549          mp = mp + lead(tt); // "mp", mp;
1550        }
1551        else
1552        {
1553          t = t + lead(tt);  //  "t", t;
1554        }
1555
1556        tt = tt - lead(tt);
1557      }
1558
1559      I[size(I)+1] = mp;
1560
1561      p = t;
1562    }
1563  }
1564  else
1565  {
1566    I[1] = p; // single monom
1567  }
1568
1569  if( typeof(I) == "module" )
1570  {
1571    I = setModuleGrading(I, V);
1572  }
1573
1574  return (I);
1575}
1576example
1577{
1578  "EXAMPLE:"; echo=2;
1579
1580  ring r = 0,(x,y,z),dp;
1581
1582  intmat g[2][3]=
1583    1,0,1,
1584    0,1,1;
1585  intmat t[2][1]=
1586    -2,
1587    1;
1588
1589  setBaseMultigrading(g,t);
1590
1591  poly f = x10yz+x8y2z-x4z2+y5+x2y2-z2+x17z3-y6;
1592
1593  mDegPartition(f);
1594 
1595  vector v = xy*gen(1)-x3y2*gen(2)+x4y*gen(3);
1596  intmat B[2][3]=1,-1,-2,0,0,1;
1597  v = setModuleGrading(v,B);
1598  getModuleGrading(v);
1599 
1600  mDegPartition(v, B);
1601}
1602
1603
1604
1605/******************************************************/
1606static proc unitMatrix(int n)
1607{
1608  intmat A[n][n];
1609 
1610  for( int i = n; i > 0; i-- )
1611  {
1612    A[i,i] = 1;
1613  }
1614
1615  return (A);
1616}
1617
1618
1619
1620/******************************************************/
1621static proc finestMDeg(def r)
1622"
1623USAGE:
1624PURPOSE: finest multigrading
1625"
1626{
1627  def save = basering;
1628  setring (r);
1629
1630  // in basering
1631      ideal I = ideal(basering);
1632
1633  int n = 0; int i; poly p;
1634  for( i = ncols(I); i > 0; i-- )
1635  {
1636    p = I[i];
1637    if( size(p) > 1 )
1638    {
1639      n = n + (size(p) - 1);
1640    }
1641    else
1642    {
1643      I[i] = 0;
1644    }
1645  }
1646
1647  int N = nvars(basering);
1648  intmat A = unitMatrix(N);
1649
1650
1651
1652  if( n > 0)
1653  {
1654
1655    intmat L[N][n];
1656    //  list L;
1657    int j = n;
1658
1659    for(  i = ncols(I); i > 0; i-- )
1660    {
1661      p = I[i];
1662
1663      if( size(p) > 1 )
1664      {
1665        intvec m0 = leadexp(p);
1666        p = p - lead(p);
1667
1668        while( size(p) > 0 )
1669        {
1670          L[ 1..N, j ] = leadexp(p) - m0;
1671          p = p - lead(p);
1672          j--;
1673        }
1674      }
1675    }
1676
1677    print(L);
1678    setBaseMultigrading(A, L);     
1679  }
1680  else
1681  {
1682    setBaseMultigrading(A);
1683  }
1684
1685  //  ERROR("nope");
1686
1687  //  ring T = integer, (x), (C, dp);
1688
1689  setring(save);
1690  return (r);
1691}
1692example
1693{
1694  "EXAMPLE:"; echo=2;
1695
1696  ring r = 0,(x, y), dp;
1697  qring q  = std(x^2 - y);
1698
1699  finestMDeg(q);
1700
1701}
1702
1703
1704
1705
1706/******************************************************/
1707static proc newMap(map F, intmat Q, list #)
1708"
1709USAGE: ?? no use now...
1710PURPOSE: ??
1711"
1712{
1713  attrib(F, "Q", Q);
1714
1715  if( size(#) > 0 and typeof(#[1]) == "intmat" )
1716  {
1717    attrib(F, "P", #[1]);
1718  }
1719  return (F);
1720}
1721
1722
1723/******************************************************/
1724static proc matrix2intmat( matrix M )
1725{
1726  execute( "intmat A[ "+ string(nrows(M)) + "]["+ string(ncols(M)) + "] = " + string(M) + ";" );
1727  return (A);
1728}
1729
1730
1731/******************************************************/
1732static proc leftKernelZ(intmat M)
1733"USAGE:  leftKernel(M);   M a matrix
1734RETURN:  module
1735PURPOSE: computes left kernel of matrix M (a module of all elements v such that vM=0)
1736EXAMPLE: example leftKernel; shows an example
1737"
1738{
1739  if( nameof(basering) != "basering" )
1740  {
1741    def save = basering;
1742  }
1743
1744  ring r = integer, (x), dp;
1745
1746
1747  //  basering;
1748  module N = matrix((M)); // transpose
1749  //  print(N);
1750
1751  def MM = modulo( N, std(0) ) ;
1752  //  print(MM);
1753
1754  intmat R = (  matrix2intmat( MM ) ); // transpose
1755
1756  if( defined(save) > 0 )
1757  {
1758    setring save;
1759  }
1760
1761  kill r;
1762  return( R );
1763}
1764example
1765{
1766  "EXAMPLE:"; echo=2;
1767
1768  ring r= 0,(x,y,z),dp;
1769  matrix M[3][1] = x,y,z;
1770  print(M);
1771  matrix L = leftKernel(M);
1772  print(L);
1773  // check:
1774  print(L*M);
1775};
1776
1777
1778
1779/******************************************************/
1780// the following is taken from "sing4ti2.lib" as we need 'hilbert' from 4ti2
1781
1782static proc hilbert4ti2intmat(intmat A, list #)
1783"USAGE:  hilbert4ti2(A[,i]);
1784@*       A=intmat
1785@*       i=int
1786ASSUME:  - A is a matrix with integer entries which describes the lattice
1787@*         as ker(A), if second argument is not present,
1788@*         as the left image Im(A) = {zA : z \in ZZ^k}, if second argument is a positive integer
1789@*       - number of variables of basering equals number of columns of A
1790@*         (for ker(A)) resp. of rows of A (for Im(A))
1791CREATE:  temporary files sing4ti2.mat, sing4ti2.lat, sing4ti2.mar
1792@*       in the current directory (I/O files for communication with 4ti2)
1793NOTE:    input rules for 4ti2 also apply to input to this procedure
1794@*       hence ker(A)={x|Ax=0} and Im(A)={xA}
1795RETURN:  toric ideal specified by Hilbert basis thereof
1796EXAMPLE: example graver4ti2; shows an example
1797"
1798{
1799//--------------------------------------------------------------------------
1800// Initialization and Sanity Checks
1801//--------------------------------------------------------------------------
1802   int i,j;
1803   int nr=nrows(A);
1804   int nc=ncols(A);
1805   string fileending="mat";
1806   if (size(#)!=0)
1807   {
1808//--- default behaviour: use ker(A) as lattice
1809//--- if #[1]!=0 use Im(A) as lattice
1810      if(typeof(#[1])!="int")
1811      {
1812         ERROR("optional parameter needs to be integer value");
1813      }
1814      if(#[1]!=0)
1815      {
1816         fileending="lat";
1817      }
1818   }
1819//--- we should also be checking whether all entries are indeed integers
1820//--- or whether there are fractions, but in this case the error message
1821//--- of 4ti2 is printed directly
1822
1823//--------------------------------------------------------------------------
1824// preparing input file for 4ti2
1825//--------------------------------------------------------------------------
1826   link eing=":w sing4ti2."+fileending;
1827   string eingstring=string(nr)+" "+string(nc);
1828   write(eing,eingstring);
1829   for(i=1;i<=nr;i++)
1830   {
1831      kill eingstring;
1832      string eingstring;
1833      for(j=1;j<=nc;j++)
1834      {
1835        //          if(g(A[i,j])>0)||(char(basering)!=0)||(npars(basering)>0))
1836        //          {
1837        //             ERROR("Input to hilbert4ti2 needs to be a matrix with integer entries");
1838        //          }
1839        eingstring=eingstring+string(A[i,j])+" ";
1840      }
1841      write(eing, eingstring);
1842   }
1843   close(eing);
1844
1845//----------------------------------------------------------------------
1846// calling 4ti2 and converting output
1847// Singular's string is too clumsy for this, hence we first prepare
1848// using standard unix commands
1849//----------------------------------------------------------------------
1850   j=system("sh","hilbert -q -n sing4ti2"); ////////// be quiet + no loggin!!!
1851
1852   j=system("sh", "awk \'BEGIN{ORS=\",\";}{print $0;}\' sing4ti2.hil " +
1853                "| sed s/[\\\ \\\t\\\v\\\f]/,/g " +
1854                "| sed s/,+/,/g|sed s/,,/,/g " +
1855                "| sed s/,,/,/g " +
1856                "> sing4ti2.converted" );
1857   if( defined(keepfiles) <= 0)
1858   {
1859      j=system("sh",("rm -f sing4ti2.hil sing4ti2."+fileending));
1860   }
1861//----------------------------------------------------------------------
1862// reading output of 4ti2
1863//----------------------------------------------------------------------
1864   link ausg=":r sing4ti2.converted";
1865//--- last entry ideal(0) is used to tie the list to the basering
1866//--- it will not be processed any further
1867
1868   string s = read(ausg);
1869   string ergstr = "intvec erglist = " + s + "0;";
1870   execute(ergstr);
1871 
1872   //   print(erglist);
1873 
1874   int Rnc = erglist[1];
1875   int Rnr = erglist[2];
1876   
1877   intmat R[Rnr][Rnc];
1878
1879   int k = 3;
1880
1881   for(i=1;i<=Rnc;i++)
1882   {
1883     for(j=1;j<=Rnr;j++)
1884     {
1885       //       "i: ", i, ", j: ", j, ", v: ", erglist[k];
1886       R[j, i] = erglist[k];
1887       k = k + 1;
1888     }
1889   }
1890
1891   return (R);
1892//--- get rid of leading entry 0;
1893//   toric=toric[2..ncols(toric)];
1894//   return(toric);
1895}
1896// A nice example here is the 3x3 Magic Squares
1897example
1898{
1899  "EXAMPLE:"; echo=2;
1900
1901   ring r=0,(x1,x2,x3,x4,x5,x6,x7,x8,x9),dp;
1902   intmat M[7][9]=
1903      1, 1, 1, -1, -1, -1, 0, 0, 0,
1904      1, 1, 1,  0,  0,  0,-1,-1,-1,
1905      0, 1, 1, -1,  0,  0,-1, 0, 0,
1906      1, 0, 1,  0, -1,  0, 0,-1, 0,
1907      1, 1, 0,  0,  0, -1, 0, 0,-1,
1908      0, 1, 1,  0, -1,  0, 0, 0,-1,
1909      1, 1, 0,  0, -1,  0,-1, 0, 0;
1910   hilbert4ti2intmat(M);
1911   hermite(M);
1912}
1913
1914/////////////////////////////////////////////////////////////////////////////
1915static proc getMonomByExponent(intvec exp)
1916{
1917  int n = nvars(basering);
1918
1919  if( nrows(exp) < n )
1920  {
1921    n = nrows(exp);
1922  }
1923
1924  poly m = 1; int e;
1925
1926  for( int i = 1; i <= n; i++ )
1927  {
1928    e = exp[i];
1929    if( e < 0 )
1930    {
1931      ERROR("Negative exponent!!!");
1932    }
1933
1934    m = m * (var(i)^e);
1935  }
1936
1937  return (m);
1938
1939}
1940
1941/******************************************************/
1942proc mDegBasis(intvec d)
1943"
1944USAGE: multidegree d
1945ASSUME: current ring is multigraded, monomial ordering is global
1946PURPOSE: compute all monomials of multidegree d
1947"
1948{
1949  def R = basering;  // setring R;
1950
1951  intmat M = getVariableWeights(R);
1952
1953  //  print(M);
1954
1955  int nr = nrows(M);
1956  int nc = ncols(M);
1957
1958  intmat A[nr][nc+1];
1959  A[1..nr, 1..nc] = M[1..nr, 1..nc];
1960  //typeof(A[1..nr, nc+1]);
1961  if( nr==1)
1962  {
1963    A[1..nr, nc+1]=-d[1];
1964  }
1965  else
1966  {
1967    A[1..nr, nc+1] = -d;
1968  }
1969
1970  intmat T = getTorsion(R);
1971
1972  if( isFreeRepresented() )
1973  {
1974    intmat B = hilbert4ti2intmat(A);
1975
1976    //      matrix B = unitMatrix(nrows(T));
1977  }
1978  else
1979  {
1980    int n = ncols(T);
1981
1982    nc = ncols(A);
1983
1984    intmat AA[nr][nc + 2 * n];
1985    AA[1..nr, 1.. nc] = A[1..nr, 1.. nc];
1986    AA[1..nr, nc + (1.. n)] = T[1..nr, 1.. n];
1987    AA[1..nr, nc + n + (1.. n)] = -T[1..nr, 1.. n];
1988
1989
1990    //      print ( AA );
1991
1992    intmat K = leftKernelZ(( AA ) ); //
1993
1994    //      print(K);
1995
1996    intmat KK[nc][ncols(K)] = K[ 1.. nc, 1.. ncols(K) ];
1997
1998    //      print(KK);
1999    //      "!";
2000
2001    intmat B = hilbert4ti2intmat(transpose(KK), 1); 
2002
2003    //      "!";      print(B);
2004
2005  }
2006
2007
2008  //  print(A);
2009
2010
2011
2012  int i; 
2013  int nnr = nrows(B);
2014  int nnc = ncols(B);
2015  ideal I, J;
2016  if(nnc==0){
2017    I=0;
2018    return(I);
2019  }
2020  I[nnc] = 0;
2021  J[nnc] = 0;
2022
2023  for( i = 1; i <= nnc; i++ )
2024  {
2025    //      "i: ", i;    B[nnr, i];
2026
2027    if( B[nnr, i] == 1)
2028    {
2029      // intvec(B[1..nnr-1, i]);
2030      I[i] = getMonomByExponent(intvec(B[1..nnr-1, i]));
2031    }
2032    else
2033    {
2034      if( B[nnr, i] == 0)
2035      {
2036        // intvec(B[1..nnr-1, i]);
2037        J[i] = getMonomByExponent(intvec(B[1..nnr-1, i]));
2038      }
2039    }
2040    //      I[i];
2041  }
2042
2043  ideal Q = (ideal(basering));
2044
2045  if ( size(Q) > 0 )
2046  {
2047    I = NF( I, lead(Q) );
2048    J = NF( J, lead(Q) ); // Global ordering!!!
2049  }
2050
2051  I = simplify(I, 2); // d
2052  J = simplify(J, 2); // d
2053
2054  attrib(I, "ZeroPart", J);
2055
2056  return (I);
2057
2058  //  setring ;
2059}
2060example
2061{
2062  "EXAMPLE:"; echo=2;
2063
2064  ring R = 0, (x, y), dp;
2065
2066  intmat g1[2][2]=1,0,0,1;
2067  intmat t[2][1]=2,0;
2068  intmat g2[2][2]=1,1,1,1;
2069  intvec v1=4,0;
2070  intvec v2=4,4;
2071 
2072  intmat g3[1][2]=1,1;
2073  setBaseMultigrading(g3);
2074  intvec v3=4:1;
2075  v3;
2076  mDegBasis(v3);
2077 
2078  setBaseMultigrading(g1,t);
2079  mDegBasis(v1);
2080  setBaseMultigrading(g2);
2081  mDegBasis(v2);
2082 
2083  intmat M[2][2] = 1, -1, -1, 1;
2084  intvec d = -2, 2;
2085
2086  setBaseMultigrading(M);
2087
2088  mDegBasis(d);
2089  attrib(_, "ZeroPart");
2090
2091  kill R;
2092  ring R = 0, (x, y, z), dp;
2093
2094  intmat M[2][3] = 1, -2, 1,     1, 1, 0;
2095
2096  intmat T[2][1] = 0, 2;
2097
2098  intvec d = 4, 1;
2099
2100  setBaseMultigrading(M, T);
2101
2102  mDegBasis(d);
2103  attrib(_, "ZeroPart");
2104
2105
2106  kill R;
2107
2108  ring R = 0, (x, y, z), dp;
2109  qring Q = std(ideal( y^6+ x*y^3*z-x^2*z^2 ));
2110
2111
2112  intmat M[2][3] = 1, 1, 2,     2, 1, 1;
2113  //  intmat T[2][1] = 0, 2;
2114
2115  setBaseMultigrading(M);
2116
2117  intvec d = 6, 6;
2118  mDegBasis(d);
2119  attrib(_, "ZeroPart");
2120
2121
2122
2123  kill R;
2124  ring R = 0, (x, y, z), dp;
2125  qring Q = std(ideal( x*z^3 - y *z^6, x*y*z  - x^4*y^2 ));
2126
2127
2128  intmat M[2][3] = 1, -2, 1,     1, 1, 0;
2129  intmat T[2][1] = 0, 2;
2130
2131  intvec d = 4, 1;
2132
2133  setBaseMultigrading(M, T);
2134
2135  mDegBasis(d);
2136  attrib(_, "ZeroPart");
2137}
2138
2139
2140proc mDegSyzygy(def I)
2141"USAGE: mDegSyzygy(I); I is a poly/vector/ideal/module
2142PURPOSE: computes the multigraded syzygy of I
2143RETURNS: module, the syzygy of I
2144NOTE: generators of I must be multigraded homogeneous
2145"
2146{
2147  if( isHomogenous(I, "checkGens") == 0)
2148  {
2149    ERROR ("Sorry: inhomogenous input!");
2150  }
2151  module S = syz(I);
2152  S = setModuleGrading(S, mDeg(I));
2153  return (S);
2154}
2155example
2156{
2157  "EXAMPLE:"; echo=2;
2158 
2159
2160  ring r = 0,(x,y,z,w),dp;
2161
2162  intmat M[2][4]=
2163    1,1,1,1,
2164    0,1,3,4;
2165
2166  setBaseMultigrading(M);
2167
2168 
2169  module M = ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
2170 
2171 
2172  intmat v[2][nrows(M)]=
2173    1,
2174    0;
2175 
2176  M = setModuleGrading(M, v);
2177
2178  isHomogenous(M);
2179  "Multidegrees: "; print(mDeg(M));
2180
2181  // Let's compute Syzygy!
2182  def S = mDegSyzygy(M); S;
2183  "Module Units Multigrading: "; print( getModuleGrading(S) );
2184  "Multidegrees: "; print(mDeg(S));
2185
2186  isHomogenous(S);
2187}
2188
2189
2190proc mDegGroebner(def I)
2191"USAGE: mDegGroebner(I); I is a poly/vector/ideal/module
2192PURPOSE: computes the multigraded standard/groebner basis of I
2193NOTE: I must be multigraded homogeneous
2194RETURNS: ideal/module, the computed basis
2195"
2196{
2197  if( isHomogenous(I) == 0)
2198  {
2199    ERROR ("Sorry: inhomogenous input!");
2200  }
2201
2202  def S = groebner(I);
2203 
2204  if( typeof(I) == "module" or typeof(I) == "vector" )
2205  {
2206    S = setModuleGrading(S, getModuleGrading(I));     
2207  }
2208
2209  return(S);
2210}
2211example
2212{
2213  "EXAMPLE:"; echo=2;
2214
2215  ring r = 0,(x,y,z,w),dp;
2216
2217  intmat M[2][4]=
2218    1,1,1,1,
2219    0,1,3,4;
2220
2221  setBaseMultigrading(M);
2222
2223 
2224  module M = ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
2225 
2226 
2227  intmat v[2][nrows(M)]=
2228    1,
2229    0;
2230 
2231  M = setModuleGrading(M, v);
2232
2233
2234  /////////////////////////////////////////////////////////////////////////////
2235  // GB:
2236  M = mDegGroebner(M); M;
2237  "Module Units Multigrading: "; print( getModuleGrading(M) );
2238  "Multidegrees: "; print(mDeg(M));
2239
2240  isHomogenous(M);
2241
2242  /////////////////////////////////////////////////////////////////////////////
2243  // Let's compute Syzygy!
2244  def S = mDegSyzygy(M); S;
2245  "Module Units Multigrading: "; print( getModuleGrading(S) );
2246  "Multidegrees: "; print(mDeg(S));
2247
2248  isHomogenous(S);
2249
2250  /////////////////////////////////////////////////////////////////////////////
2251  // GB:
2252  S = mDegGroebner(S); S;
2253  "Module Units Multigrading: "; print( getModuleGrading(S) );
2254  "Multidegrees: "; print(mDeg(S));
2255
2256  isHomogenous(S);
2257}
2258
2259
2260/******************************************************/
2261proc mDegResolution(def I, int ll, list #)
2262"USAGE: mDegResolution(I,l,[f]); I is poly/vector/ideal/module; l,f are integers
2263PURPOSE: computes the multigraded resolution of I of the length l,
2264or the whole resolution if l is zero. Returns minimal resolution if an optional
2265argument 1 is supplied
2266NOTE: input must have multigraded-homogeneous generators.
2267The returned list is trunkated at the first zero entry.
2268RETURNS: list, the computed resolution
2269"
2270{
2271  if( isHomogenous(I, "checkGens") == 0)
2272  {
2273    ERROR ("Sorry: inhomogenous input!");
2274  }
2275
2276  def R = res(I, ll, #); list L = R; int l = size(L);
2277
2278  if( (typeof(I) == "module") or (typeof(I) == "vector") )
2279  {
2280    L[1] = setModuleGrading(L[1], getModuleGrading(I));     
2281  }
2282
2283  int i;
2284  for( i = 2; i <= l; i++ )
2285  {
2286    if( size(L[i]) > 0 )
2287    {
2288      L[i] = setModuleGrading( L[i], mDeg(L[i-1]) );
2289    } else
2290    {
2291      return (L[1..(i-1)]);
2292    }
2293  }
2294 
2295  return (L);
2296
2297 
2298}
2299example
2300{
2301  "EXAMPLE:"; echo=2;
2302 
2303  ring r = 0,(x,y,z,w),dp;
2304
2305  intmat M[2][4]=
2306    1,1,1,1,
2307    0,1,3,4;
2308
2309  setBaseMultigrading(M);
2310
2311 
2312  module m= ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
2313 
2314  isHomogenous(ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3), "checkGens");
2315 
2316  ideal A = xw-yz, x2z-y3, xz2-y2w, yw2-z3;
2317
2318  int j;
2319 
2320  for(j=1; j<=ncols(A); j++)
2321  {
2322    mDegPartition(A[j]);
2323  }
2324 
2325  intmat v[2][1]=
2326    1,
2327    0;
2328 
2329  m = setModuleGrading(m, v);
2330
2331  // Let's compute Syzygy!
2332  def S = mDegSyzygy(m); S;
2333  "Module Units Multigrading: "; print( getModuleGrading(S) );
2334  "Multidegrees: "; print(mDeg(S));
2335
2336  /////////////////////////////////////////////////////////////////////////////
2337
2338  S = mDegGroebner(S); S;
2339  "Module Units Multigrading: "; print( getModuleGrading(S) );
2340  "Multidegrees: "; print(mDeg(S));
2341
2342  /////////////////////////////////////////////////////////////////////////////
2343
2344  def L = mDegResolution(m, 0, 1);
2345
2346  for( j =1; j<=size(L); j++)
2347  {
2348    "----------------------------------- ", j, " -----------------------------";
2349    L[j];
2350    "Module Multigrading: "; print( getModuleGrading(L[j]) );
2351    "Multigrading: "; print(mDeg(L[j]));
2352  }
2353
2354  /////////////////////////////////////////////////////////////////////////////
2355 
2356  L = mDegResolution(maxideal(1), 0, 1);
2357
2358  for( j =1; j<=size(L); j++)
2359  {
2360    "----------------------------------- ", j, " -----------------------------";
2361    L[j];
2362    "Module Multigrading: "; print( getModuleGrading(L[j]) );
2363    "Multigrading: "; print(mDeg(L[j]));
2364  }
2365 
2366  kill v;
2367 
2368
2369  def h = hilbertSeries(m);
2370  setring h;
2371
2372  numerator1;
2373  factorize(numerator1);
2374 
2375  denominator1;
2376  factorize(denominator1);
2377
2378  numerator2;
2379  factorize(numerator2);
2380
2381  denominator2;
2382  factorize(denominator2);
2383}
2384
2385/******************************************************/
2386proc hilbertSeries(def I)
2387"USAGE: hilbertSeries(I); I is poly/vector/ideal/module
2388PURPOSE: computes the multigraded Hilbert Series of M
2389NOTE: input must have multigraded-homogeneous generators.
2390Multigrading should be positive.
2391RETURNS: a ring in variables t_(i), s_(i), with polynomials
2392numerator1 and denominator1 and muturally prime numerator2
2393and denominator2, quotients of which give the series.
2394"
2395{
2396   
2397  if( !isFreeRepresented() )
2398  {
2399    ERROR("SORRY: ONLY TORSION-FREE CASE (POSITIVE GRADING)");
2400  }
2401   
2402  int i, j, k, v;
2403
2404  intmat M = getVariableWeights();
2405 
2406  int cc = ncols(M);
2407  int n = nrows(M);
2408
2409  if( n == 0 )
2410  {
2411    ERROR("Error: wrong Variable Weights?");
2412  }
2413
2414  list RES = mDegResolution(I,0,1);
2415
2416  int l = size(RES);
2417 
2418  list L; L[l + 1] = 0;
2419
2420  if(typeof(I) == "ideal")
2421  {
2422    intmat zeros[n][1];
2423    L[1] = zeros;
2424  }
2425  else
2426  {
2427    L[1] = getModuleGrading(RES[1]);
2428  }
2429
2430  for( j = 1; j <= l; j++)
2431  {
2432    L[j + 1] = mDeg(RES[j]);
2433  }
2434 
2435  l++;
2436
2437  ring R = 0,(t_(1..n),s_(1..n)),dp;
2438 
2439  ideal units;
2440  for( i=n; i>=1; i--)
2441  {
2442    units[i] = (var(i) * var(n + i) - 1);
2443  }
2444 
2445  qring Q = std(units);
2446 
2447  // TODO: should not it be a quotient ring depending on Torsion???
2448  // I am not sure about what to do in the torsion case, but since
2449  // we want to evaluate the polynomial at certain points to get
2450  // a dimension we need uniqueness for this. I think we would lose
2451  // this uniqueness if switching to this torsion ring.
2452
2453  poly monom, summand, numerator;
2454  poly denominator = 1;
2455 
2456  for( i = 1; i <= cc; i++)
2457  {
2458    monom = 1;
2459
2460    for( k = 1; k <= n; k++)
2461    {
2462      v = M[k,i];
2463
2464      if(v >= 0)
2465      {
2466        monom = monom * (var(k)^(v));
2467      }
2468      else
2469      {
2470        monom = monom * (var(n+k)^(-v));
2471      }
2472    }
2473   
2474    if( monom == 1)
2475    {
2476      ERROR("Multigrading not positive.");
2477    }
2478
2479    denominator = denominator * (1 - monom);
2480  }
2481 
2482  for( j = 1; j<= l; j++)
2483  {
2484    summand = 0;
2485    M = L[j];
2486
2487    for( i = 1; i <= ncols(M); i++)
2488    {
2489      monom = 1;
2490      for( k = 1; k <= n; k++)
2491      {
2492        v = M[k,i];
2493        if( v > 0 )
2494        {
2495          monom = monom * (var(k)^v);
2496        }
2497        else
2498        {
2499          monom = monom * (var(n+k)^(-v));
2500        }
2501      }
2502      summand = summand + monom;
2503    }
2504    numerator = numerator - (-1)^j * summand;
2505  }
2506 
2507  if( denominator == 0 )
2508  {
2509    ERROR("Multigrading not positive.");
2510  }
2511 
2512  poly denominator1 = denominator;
2513  poly numerator1 = numerator;
2514
2515  export denominator1;
2516  export numerator1;
2517
2518  if( numerator != 0 )
2519  {
2520    poly d = gcd(denominator, numerator);
2521
2522    poly denominator2 = denominator/d;
2523    poly numerator2 = numerator/d;
2524
2525    if( gcd(denominator2, numerator2) != 1 )
2526    {
2527      ERROR("Sorry: gcd should be 1 (after dividing out gcd)! Something went wrong!");
2528    }
2529  }
2530  else
2531  {
2532    poly denominator2 = denominator;
2533    poly numerator2 = numerator;
2534  }
2535
2536
2537  export denominator2;
2538  export numerator2;
2539
2540  " ------------ ";
2541  "This proc returns a ring with polynomials called 'numerator1/2' and 'denominator1/2'!";
2542  "They represent the first and the second Hilbert Series.";
2543  "The s_(i)-variables are defined to be the inverse of the t_(i)-variables.";
2544  " ------------ ";
2545 
2546  return(Q);
2547}
2548example
2549{
2550  "EXAMPLE:"; echo=2;
2551 
2552  ring r = 0,(x,y,z,w),dp;
2553  intmat g[2][4]=
2554    1,1,1,1,
2555    0,1,3,4;
2556  setBaseMultigrading(g);
2557 
2558  module M = ideal(xw-yz, x2z-y3, xz2-y2w, yw2-z3);
2559  intmat V[2][1]=
2560    1,
2561    0;
2562
2563  M = setModuleGrading(M, V);
2564
2565  def h = hilbertSeries(M); setring h;
2566
2567  factorize(numerator2);
2568  factorize(denominator2);
2569 
2570  kill g, h; setring r;
2571
2572  intmat g[2][4]=
2573    1,2,3,4,
2574    0,0,5,8;
2575 
2576  setBaseMultigrading(g);
2577 
2578  ideal I = x^2, y, z^3;
2579  I = std(I);
2580  def L = mDegResolution(I, 0, 1);
2581
2582  for( int j = 1; j<=size(L); j++)
2583  {
2584    "----------------------------------- ", j, " -----------------------------";
2585    L[j];
2586    "Module Multigrading: "; print( getModuleGrading(L[j]) );
2587    "Multigrading: "; print(mDeg(L[j]));
2588  }
2589
2590  mDeg(I);
2591  def h = hilbertSeries(I); setring h;
2592 
2593  factorize(numerator2);
2594  factorize(denominator2);
2595
2596  kill r, h, g, V;
2597  ////////////////////////////////////////////////
2598  ////////////////////////////////////////////////
2599 
2600  ring R = 0,(x,y,z),dp;
2601  intmat W[2][3] =
2602     1,1, 1,
2603     0,0,-1;
2604  setBaseMultigrading(W);
2605  ideal I = x3y,yz2,y2z,z4;
2606 
2607  def h = hilbertSeries(I); setring h;
2608 
2609  factorize(numerator2);
2610  factorize(denominator2);
2611
2612  kill R, W, h;
2613  ////////////////////////////////////////////////
2614  ////////////////////////////////////////////////
2615
2616  ring R = 0,(x,y,z,a,b,c),dp;
2617  intmat W[2][6] =
2618     1,1, 1,1,1,1,
2619     0,0,-1,0,0,0;
2620  setBaseMultigrading(W);
2621  ideal I = x3y,yz2,y2z,z4;
2622 
2623  def h = hilbertSeries(I); setring h;
2624 
2625  factorize(numerator2);
2626  factorize(denominator2);
2627 
2628  kill R, W, h;
2629
2630  ////////////////////////////////////////////////
2631  ////////////////////////////////////////////////
2632  ////////////////////////////////////////////////
2633  // This is example 5.3.9. from Robbianos book.
2634 
2635  ring R = 0,(x,y,z,w),dp;
2636  intmat W[1][4] =
2637     1,1, 1,1;
2638  setBaseMultigrading(W);
2639  ideal I = z3,y3zw2,x2y4w2xyz2;
2640
2641  hilb(std(I));
2642 
2643  def h = hilbertSeries(I); setring h;
2644 
2645  numerator1;
2646  denominator1;
2647
2648  factorize(numerator2);
2649  factorize(denominator2);
2650 
2651
2652  kill h;
2653  ////////////////////////////////////////////////
2654  setring R;
2655
2656  ideal I2 = x2,y2,z2; I2;
2657
2658  hilb(std(I2));
2659 
2660  def h = hilbertSeries(I2); setring h;
2661
2662  numerator1;
2663  denominator1;
2664
2665
2666  kill h;
2667  ////////////////////////////////////////////////
2668  setring R;
2669 
2670  W = 2,2,2,2;
2671 
2672  setBaseMultigrading(W);
2673
2674  getVariableWeights();
2675
2676  intvec w = 2,2,2,2;
2677
2678  hilb(std(I2), 1, w);
2679
2680  kill w;
2681 
2682
2683  def h = hilbertSeries(I2); setring h;
2684
2685 
2686  numerator1; denominator1;
2687  kill h;
2688
2689 
2690  kill R, W;
2691
2692  ////////////////////////////////////////////////
2693  ////////////////////////////////////////////////
2694  ////////////////////////////////////////////////
2695
2696  ring R = 0,(x),dp;
2697  intmat W[1][1] =
2698     1;
2699  setBaseMultigrading(W);
2700
2701  ideal I;
2702
2703  I = 1; I;
2704
2705  hilb(std(I));
2706 
2707  def h = hilbertSeries(I); setring h;
2708
2709  numerator1; denominator1;
2710
2711  kill h;
2712  ////////////////////////////////////////////////
2713  setring R;
2714
2715  I = x; I;
2716
2717  hilb(std(I));
2718
2719  def h = hilbertSeries(I); setring h;
2720
2721  numerator1; denominator1;
2722 
2723  kill h; 
2724  ////////////////////////////////////////////////
2725  setring R;
2726
2727  I = x^5; I;
2728
2729  hilb(std(I));
2730  hilb(std(I), 1);
2731
2732  def h = hilbertSeries(I); setring h;
2733
2734  numerator1; denominator1;
2735 
2736 
2737  kill h; 
2738  ////////////////////////////////////////////////
2739  setring R;
2740
2741  I = x^10; I;
2742
2743  hilb(std(I));
2744
2745  def h = hilbertSeries(I); setring h;
2746
2747  numerator1; denominator1;
2748
2749  kill h;
2750  ////////////////////////////////////////////////
2751  setring R;
2752
2753  module M = 1;
2754
2755  M = setModuleGrading(M, W);
2756
2757 
2758  hilb(std(M));
2759
2760  def h = hilbertSeries(M); setring h;
2761
2762  numerator1; denominator1;
2763
2764  kill h;
2765  ////////////////////////////////////////////////
2766  setring R;
2767
2768  kill M; module M = x^5*gen(1);
2769
2770//  intmat V[1][3] = 0; // TODO: this would lead to a wrong result!!!?
2771
2772  intmat V[1][1] = 0; // all gen(i) of degree 0!
2773
2774  M = setModuleGrading(M, V);
2775
2776  hilb(std(M));
2777
2778  def h = hilbertSeries(M); setring h;
2779
2780  numerator1; denominator1;
2781
2782  kill h;
2783  ////////////////////////////////////////////////
2784  setring R;
2785
2786  module N = x^5*gen(3);
2787
2788  kill V;
2789 
2790  intmat V[1][3] = 0; // all gen(i) of degree 0!
2791
2792  N = setModuleGrading(N, V);
2793     
2794  hilb(std(N));
2795
2796  def h = hilbertSeries(N); setring h;
2797
2798  numerator1; denominator1;
2799
2800  kill h;
2801  ////////////////////////////////////////////////
2802  setring R;
2803
2804 
2805  module S = M + N;
2806 
2807  S = setModuleGrading(S, V);
2808
2809  hilb(std(S));
2810
2811  def h = hilbertSeries(S); setring h;
2812
2813  numerator1; denominator1;
2814
2815  kill h;
2816
2817  kill V;
2818  kill R, W;
2819
2820}
2821
2822
2823
2824///////////////////////////////////////////////////////////////////////////////
2825// testing for consistency of the library:
2826proc testMultigradingLib ()
2827{
2828  example setBaseMultigrading;
2829  example setModuleGrading;
2830
2831  example getVariableWeights;
2832  example getTorsion;
2833  example getModuleGrading;
2834
2835
2836  example mDeg;
2837  example mDegPartition;
2838
2839
2840  example hermite;
2841  example isHomogenous;
2842  example isTorsionFree;
2843  example pushForward;
2844  example defineHomogenous;
2845
2846  example equalMDeg;
2847  example isTorsionElement;
2848
2849  example mDegResolution;
2850  example hilbertSeries;
2851
2852
2853// example mDegBasis; // needs 4ti2!
2854}
Note: See TracBrowser for help on using the repository browser.