source: git/Singular/LIB/multigrading.lib @ 62dc18e

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