Changeset 343966 in git for Singular/LIB


Ignore:
Timestamp:
Sep 28, 2010, 6:27:37 PM (14 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
Children:
04e210843feb1167f9c6282699922f1756e760c5
Parents:
35b6ca571f5260579f60e2918659a4db705b4b5c
Message:
changes to 'multigrading.lib' due to Wolfram Decker
 


git-svn-id: file:///usr/local/Singular/svn/trunk@13300 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/multigrading.lib

    r35b6ca r343966  
    1010
    1111
    12 OVERVIEW: using this library allows one can virtually add multigrading to Singular.
     12OVERVIEW: This library allows one to virtually add multigradings to Singular.
    1313For more see http://code.google.com/p/convex-singular/wiki/Multigrading
    14 For theoretical references see:
     14For theoretical references see: 
    1515E. Miller, B. Sturmfels: 'Combinatorial Commutative Algebra' and
    1616M. Kreuzer, L. Robbiano: 'Computational Commutative Algebra'.
     
    6262PURPOSE: attaches weights of variables and torsion to the basering.
    6363NOTE: M encodes the weights of variables column-wise.
    64 The torsion is given by the lattice spanned by the columns of the integer
     64The torsion is given by the lattice spanned by the columns of the integer 
    6565matrix T in Z^nrows(M) over Z.
    6666RETURN: nothing
     
    7474
    7575  attrib(basering, attrMgrad, M);
    76 
     76 
    7777  if( size(#) > 0 and typeof(#[1]) == "intmat" )
    7878  {
     
    8585  if( nrows(T) == nrows(M) )
    8686  {
    87     attrib(basering, attrTorsion, T);
    88     def H;
    89     attrib(basering, attrTorsionHNF, H);
     87    attrib(basering, attrTorsion, T); 
     88//    def H;
     89//    attrib(basering, attrTorsionHNF, H);       
    9090  }
    9191  else
     
    9797{
    9898  "EXAMPLE:"; echo=2;
     99   
    99100  ring R = 0, (x, y, z), dp;
     101
    100102  // Weights of variables
    101103  intmat M[3][3] =
     
    103105    0, 1, 0,
    104106    0, 0, 1;
     107
    105108  // Torsion:
    106109  intmat L[3][2] =
    107110    1, 1,
    108     1, 3,
     111    1, 3, 
    109112    1, 5;
     113   
    110114  // attaches M & L to R (==basering):
    111115  setBaseMultigrading(M, L); // Grading: Z^3/L
     116
    112117  // Weights are accessible via "getVariableWeights()":
    113   getVariableWeights() == M;
    114   getVariableWeights(R) == M;
    115   getVariableWeights(basering) == M;
     118  getVariableWeights();
     119 
     120  // Test all possible usages:
     121  (getVariableWeights() == M) && (getVariableWeights(R) == M) && (getVariableWeights(basering) == M);
     122
    116123  // Torsion is accessible via "getTorsion()":
    117   getTorsion() == L;
    118   getTorsion(R) == L;
    119   getTorsion(basering) == L;
     124  getTorsion();
     125 
     126  // Test all possible usages:
     127  (getTorsion() == L) && (getTorsion(R) == L) && (getTorsion(basering) == L);
     128
    120129  // And its hermite NF via getTorsion("hermite"):
     130  getTorsion("hermite");
     131
     132  // Test all possible usages:
    121133  intmat H = hermite(L);
    122   getTorsion("hermite") == H;
    123   getTorsion(R, "hermite") == H;
    124   getTorsion(basering, "hermite") == H;
     134  (getTorsion("hermite") == H) && (getTorsion(R, "hermite") == H) && (getTorsion(basering, "hermite") == H);
     135
    125136  kill L, M;
     137
    126138  // ----------- isomorphic multigrading -------- //
     139
    127140  // Weights of variables
    128141  intmat M[2][3] =
    129142    1, -2, 1,
    130143    1,  1, 0;
     144
    131145  // Torsion:
    132146  intmat L[2][1] =
    133147    0,
    134148    2;
     149   
    135150  // attaches M & L to R (==basering):
    136151  setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
     152
    137153  // Weights are accessible via "getVariableWeights()":
    138154  getVariableWeights() == M;
     155
    139156  // Torsion is accessible via "getTorsion()":
    140157  getTorsion() == L;
     158
    141159  kill L, M;
    142160  // ----------- extreme case ------------ //
     161
    143162  // Weights of variables
    144163  intmat M[1][3] =
    145164    1,  -1, 10;
     165
    146166  // Torsion:
    147167  intmat L[1][1] =
    148168    0;
     169   
    149170  // attaches M & L to R (==basering):
    150171  setBaseMultigrading(M); // Grading: Z^3
     172
    151173  // Weights are accessible via "getVariableWeights()":
    152174  getVariableWeights() == M;
     175
    153176  // Torsion is accessible via "getTorsion()":
    154177  getTorsion() == L;
     
    185208  def M = attrib(R, attrMgrad);
    186209  if( typeof(M) == "intmat"){ return (M); }
    187   ERROR( "Sorry no multigrading matrix!" );
     210  ERROR( "Sorry no multigrading matrix!" ); 
    188211}
    189212example
    190213{
    191214  "EXAMPLE:"; echo=2;
     215   
    192216  ring R = 0, (x, y, z), dp;
     217
    193218  // Weights of variables
    194219  intmat M[3][3] =
     
    196221    0, 1, 0,
    197222    0, 0, 1;
     223
    198224  // Torsion:
    199225  intmat L[3][2] =
    200226    1, 1,
    201     1, 3,
     227    1, 3, 
    202228    1, 5;
     229   
    203230  // attaches M & L to R (==basering):
    204231  setBaseMultigrading(M, L); // Grading: Z^3/L
     232
    205233  // Weights are accessible via "getVariableWeights()":
    206234  getVariableWeights() == M;
     235
    207236  kill L, M;
     237
    208238  // ----------- isomorphic multigrading -------- //
     239
    209240  // Weights of variables
    210241  intmat M[2][3] =
    211242    1, -2, 1,
    212243    1,  1, 0;
     244
    213245  // Torsion:
    214246  intmat L[2][1] =
    215247    0,
    216248    2;
     249   
    217250  // attaches M & L to R (==basering):
    218251  setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
     252
    219253  // Weights are accessible via "getVariableWeights()":
    220254  getVariableWeights() == M;
     255
    221256  kill L, M;
     257
    222258  // ----------- extreme case ------------ //
     259
    223260  // Weights of variables
    224261  intmat M[1][3] =
    225262    1,  -1, 10;
     263
    226264  // Torsion:
    227265  intmat L[1][1] =
    228266    0;
     267   
    229268  // attaches M & L to R (==basering):
    230269  setBaseMultigrading(M); // Grading: Z^3
     270
    231271  // Weights are accessible via "getVariableWeights()":
    232272  getVariableWeights() == M;
     
    239279RETURN: intmat, the torsion matrix, or its hermite normal form
    240280        if an optional argument (\"hermite\") is given
     281EXAMPLE: example getTorsion; shows an example
    241282"
    242283{
     
    252293      def R = #[i];
    253294      i++;
    254     }
    255   }
     295    } 
     296  } 
    256297
    257298  if( !defined(R) )
     
    264305    if( #[i] == "hermite" )
    265306    {
    266       if( typeof(attrib(R, attrTorsionHNF)) != "intmat" )
     307      if( typeof(attrib(R, attrTorsionHNF)) != "intmat" ) 
    267308      {
    268309        def M = getTorsion(R);
    269310        if( typeof(M) != "intmat")
    270         {
    271           ERROR( "Sorry no torsion matrix!" );
     311        { 
     312          ERROR( "Sorry no torsion matrix!" ); 
    272313        }
    273         attrib(R, attrTorsionHNF, hermite(M)); // this might not work with R != basering...
    274       }
     314        M = hermite(M);
     315        attrib(R, attrTorsionHNF, M); // this might not work with R != basering...
     316      }
    275317      return (attrib(R, attrTorsionHNF));
    276318    }
     
    279321  def M = attrib(R, attrTorsion);
    280322  if( typeof(M) != "intmat")
    281   {
    282     ERROR( "Sorry no torsion matrix!" );
     323  { 
     324    ERROR( "Sorry no torsion matrix!" ); 
    283325  }
    284326  return (M);
     
    287329{
    288330  "EXAMPLE:"; echo=2;
     331   
    289332  ring R = 0, (x, y, z), dp;
     333
    290334  // Weights of variables
    291335  intmat M[3][3] =
     
    293337    0, 1, 0,
    294338    0, 0, 1;
     339
    295340  // Torsion:
    296341  intmat L[3][2] =
    297342    1, 1,
    298     1, 3,
     343    1, 3, 
    299344    1, 5;
     345   
    300346  // attaches M & L to R (==basering):
    301347  setBaseMultigrading(M, L); // Grading: Z^3/L
     348
    302349  // Torsion is accessible via "getTorsion()":
    303350  getTorsion() == L;
     351
    304352  // its hermite NF:
    305353  print(getTorsion("hermite"));
     354
    306355  kill L, M;
     356
    307357  // ----------- isomorphic multigrading -------- //
     358
    308359  // Weights of variables
    309360  intmat M[2][3] =
    310361    1, -2, 1,
    311362    1,  1, 0;
     363
    312364  // Torsion:
    313365  intmat L[2][1] =
    314366    0,
    315367    2;
     368   
    316369  // attaches M & L to R (==basering):
    317370  setBaseMultigrading(M, L); // Grading: Z + (Z/2Z)
     371
    318372  // Torsion is accessible via "getTorsion()":
    319373  getTorsion() == L;
     374
    320375  // its hermite NF:
    321376  print(getTorsion("hermite"));
     377
    322378  kill L, M;
     379
    323380  // ----------- extreme case ------------ //
     381
    324382  // Weights of variables
    325383  intmat M[1][3] =
    326384    1,  -1, 10;
     385
    327386  // Torsion:
    328387  intmat L[1][1] =
    329388    0;
     389   
    330390  // attaches M & L to R (==basering):
    331391  setBaseMultigrading(M); // Grading: Z^3
     392
    332393  // Torsion is accessible via "getTorsion()":
    333394  getTorsion() == L;
     395
    334396  // its hermite NF:
    335397  print(getTorsion("hermite"));
     
    340402"USAGE: getModuleGrading(m), 'm' module/vector
    341403RETURN: integer matrix of the multiweights of free module generators attached to 'm'
     404EXAMPLE: example getModuleGrading; shows an example
    342405"
    343406{
     
    356419      return (VV);
    357420    }
    358 
     421     
    359422    ERROR("Sorry: vector or module need module-grading-matrix! See 'getModuleGrading'.");
    360423  }
     
    369432    ERROR("Sorry wrong width of V: " + string(ncols(V)));
    370433  }
    371 
     434   
    372435  return (V);
    373436}
     
    375438{
    376439  "EXAMPLE:"; echo=2;
     440   
    377441   ring R = 0, (x,y), dp;
    378442   intmat M[2][2]=
     
    382446     1,  2,  3,  4, 0,
    383447     0, 10, 20, 30, 1;
     448   
    384449   setBaseMultigrading(M, T);
     450   
    385451   ideal I = x, y, xy^5;
    386452   isHomogenous(I);
     453 
    387454   intmat V = mDeg(I); print(V);
     455
    388456   module S = syz(I); print(S);
     457   
    389458   S = setModuleGrading(S, V);
     459
    390460   getModuleGrading(S) == V;
     461   
    391462   vector v = setModuleGrading(S[1], V);
    392463   getModuleGrading(v) == V;
    393464   isHomogenous(v);
    394    print( mDeg(v) );
     465   print( mDeg(v) );   
     466   
    395467   isHomogenous(S);
    396468   print( mDeg(S) );
     
    401473"USAGE: setModuleGrading(m, G), m module/vector, G intmat
    402474PURPOSE: attaches the multiweights of free module generators to 'm'
    403 WARNING: The method does not verify that the multigrading makes the
     475WARNING: The method does not verify whether the multigrading makes the
    404476         module/vector homogenous. One can do that using isHomogenous(m).
     477EXAMPLE: example setModuleGrading; shows an example
    405478"
    406479{
     
    418491{
    419492  "EXAMPLE:"; echo=2;
     493   
    420494   ring R = 0, (x,y), dp;
    421495   intmat M[2][2]=
     
    425499     1,  2,  3,  4, 0,
    426500     0, 10, 20, 30, 1;
     501   
    427502   setBaseMultigrading(M, T);
     503   
    428504   ideal I = x, y, xy^5;
    429505   intmat V = mDeg(I);
     506   
    430507   // V == M; modulo T
    431508   print(V);
     509
    432510   module S = syz(I);
     511   
    433512   S = setModuleGrading(S, V);
    434513   getModuleGrading(S) == V;
     514
    435515   print(S);
     516   
    436517   vector v = S[1]; v = setModuleGrading(v, V);
    437518   getModuleGrading(v) == V;
    438    print( mDeg(v) );
     519
     520   print( mDeg(v) );   
     521
    439522   isHomogenous(S);
     523
    440524   print( mDeg(S) );
    441525}
     
    449533PURPOSE: Determines whether the multigrading attached to the current ring is torsion-free.
    450534RETURN: boolean, the result of the test
     535EXAMPLE: example isTorsionFree; shows an example
    451536"
    452537{
    453538
    454   intmat H = hermite(transpose(getTorsion("hermite"))); // TODO: ?cache it?
     539  intmat H = hermite(transpose(getTorsion("hermite"))); // TODO: ?cache it?  //******
    455540
    456541  int i, j;
     
    465550
    466551    if(H[j, i]!=0)
    467     {
     552    { 
    468553      d=d*H[j, i];
    469554    }
     
    471556
    472557  if( (d*d)==1 )
    473   {
     558  { 
    474559    return(1==1);
    475560  }
     
    479564{
    480565  "EXAMPLE:"; echo=2;
     566
    481567   ring R = 0,(x,y),dp;
    482568   intmat M[2][2]=
     
    486572     1, 2, 3, 4, 0,
    487573     0,10,20,30, 1;
     574   
    488575   setBaseMultigrading(M,T);
     576   
    489577   // Is the resulting group torsion free?
    490578   isTorsionFree();
     579
    491580   kill R, M, T;
    492581   ///////////////////////////////////////////
     582
    493583   ring R=0,(x,y,z),dp;
    494    intmat A[3][3] =
     584   intmat A[3][3] = 
    495585     1,0,0,
    496586     0,1,0,
     
    503593   // Is the resulting group torsion free?
    504594   isTorsionFree();
     595
    505596   kill R, A, B;
    506597}
     
    511602proc hermite(intmat A)
    512603"USAGE: hermite( A );
    513 PROCEDURE: Computes the Hermite Normal Form of the matrix A by column operations.
     604PURPOSE: Computes the (lower triangular) Hermite Normal Form
     605           of the matrix A by column operations.
    514606RETURN: intmat, the Hermite Normal Form of A
     607EXAMPLE: example hermite; shows an example
    515608"
    516609{
     
    541634
    542635    if((i+l)>nrows(A)){ break; }
    543 
     636   
    544637    if(A[i+l, i]<0)
    545638    {
     
    573666
    574667              for(k=1;k<=nrows(A);k++)
    575               {
     668              { 
    576669                save=A[k, i];
    577670                A[k, i]=A[k, j];
     
    583676            d=a2/A[i+l, i];
    584677            for(k=1;k<=nrows(A);k++)
    585             {
     678            { 
    586679              A[k, j]=A[k, j]- d*A[k, i];
    587680            }
     
    603696{
    604697  "EXAMPLE:"; echo=2;
    605    intmat M[2][5] =
     698
     699   intmat M[2][5] =
    606700     1, 2, 3, 4, 0,
    607701     0,10,20,30, 1;
     702
    608703   // Hermite Normal Form of M:
    609704   print(hermite(M));
    610    intmat T[3][4] =
     705
     706   intmat T[3][4] =
    611707     3,3,3,3,
    612708     2,1,3,0,
    613709     1,2,0,3;
     710
    614711   // Hermite Normal Form of T:
    615712   print(hermite(T));
    616    intmat A[4][5] =
     713
     714   intmat A[4][5] =
    617715     1,2,3,2,2,
    618716     1,2,3,4,0,
    619717     0,5,4,2,1,
    620718     3,2,4,0,2;
     719
    621720   // Hermite Normal Form of A:
    622721   print(hermite(A));
     
    627726proc isTorsionElement(intvec mdeg)
    628727"USAGE: isTorsionElement(intvec mdeg);
    629 PROCEDURE: For a integer vector mdeg representing the multidegree of some polynomial
     728PURPOSE: For a integer vector mdeg representing the multidegree of some polynomial
    630729or vector this method computes if the multidegree is contained in the torsion
    631730group, i.e. if it is zero in the multigrading.
     731EXAMPLE: example isTorsionElement; shows an example
    632732"
    633733{
     
    647747
    648748      if(x!=0)
    649       {
     749      { 
    650750        return(1==0);
    651751      }
     
    654754
    655755      for( k=1; k <= rr; k++)
    656       {
     756      { 
    657757        mdeg[k] = mdeg[k] - x*H[k,i];
    658758      }
     
    666766{
    667767 "EXAMPLE:"; echo=2;
     768
    668769  ring r = 0,(x,y,z),dp;
     770
    669771  intmat g[2][3]=
    670772    1,0,1,
     
    673775    -2,
    674776    1;
     777
    675778  setBaseMultigrading(g,t);
     779
    676780  poly a = x10yz;
    677781  poly b = x8y2z;
     
    680784  poly e = x2y2;
    681785  poly f = z2;
     786
    682787  intvec v1 = mDeg(a) - mDeg(b);
    683788  v1;
    684789  isTorsionElement(v1);
     790 
    685791  intvec v2 = mDeg(a) - mDeg(c);
    686792  v2;
    687793  isTorsionElement(v2);
     794 
    688795  intvec v3 = mDeg(e) - mDeg(f);
    689796  v3;
    690797  isTorsionElement(v3);
     798 
    691799  intvec v4 = mDeg(c) - mDeg(d);
    692800  v4;
     
    698806proc defineHomogenous(poly f, list #)
    699807"USAGE: defineHomogenous(f[, G]); polynomial f, integer matrix G
    700 PURPOSE: Yields a matrix which has to be appended to the torsion matrix to make the
     808PURPOSE: Yields a matrix which has to be appended to the torsion matrix to make the 
    701809polynomial f homogenous in the grading by grad.
     810EXAMPLE: example defineHomogenous; shows an example
    702811"
    703812{
    704   if( size(#) > 0 )
    705   {
    706     if( typeof(#[1]) == "intmat" )
     813  if( size(#) > 0 ) 
     814  {
     815    if( typeof(#[1]) == "intmat" ) 
    707816    {
    708817      intmat grad = #[1];
     
    732841{
    733842  "EXAMPLE:"; echo=2;
     843
    734844  ring r =0,(x,y,z),dp;
    735   intmat grad[2][3] =
     845  intmat grad[2][3] = 
    736846    1,0,1,
    737847    0,1,1;
     848
    738849  setBaseMultigrading(grad);
     850
    739851  poly f = x2y3-z5+x-3zx;
     852
    740853  intmat M = defineHomogenous(f);
    741854  M;
    742855  defineHomogenous(f, grad) == M;
     856 
    743857  isHomogenous(f);
    744858  setBaseMultigrading(grad, M);
     
    754868the torsion matrix may not be a subgroup of the grading group. Still all columns
    755869are needed to find the correct image of the preimage gradings.
     870EXAMPLE: example pushForward; shows an example
    756871"
    757872{
    758873
    759874  int k,i,j;
    760   f;
    761 
    762   intmat oldgrad=getVariableWeights(preimage(f));
    763   intmat oldtor=getTorsion(preimage(f));
    764 
    765   int n=nvars(preimage(f));
     875//  f;
     876
     877  listvar();
     878
     879  def pre = preimage(f);
     880 
     881  "pre: ";
     882  pre;
     883
     884  intmat oldgrad=getVariableWeights(pre);
     885  intmat oldtor=getTorsion(pre);
     886
     887  int n=nvars(pre);
    766888  int np=nvars(basering);
    767889  int p=nrows(oldgrad);
     
    846968{
    847969  "EXAMPLE:"; echo=2;
     970
     971  ring r = 0,(x,y,z),dp;
     972 
     973 
     974
    848975  // Setting degrees for preimage ring.;
    849   intmat grad[3][3] =
     976  intmat grad[3][3] = 
    850977    1,0,0,
    851978    0,1,0,
    852979    0,0,1;
    853   ring r = 0,(x,y,z),dp;
    854   if (voice>1) {keepring(r);}
     980
    855981  setBaseMultigrading(grad);
     982 
    856983  // grading on r:
    857984  getVariableWeights();
    858985  getTorsion();
     986
     987  // only for the purpose of this example
     988  if( voice > 1 ){ keepring(r); export(r); }
     989
    859990  ring R = 0,(a,b),dp;
    860   ideal i=a2-b2+a6-b5+ab3,a7b+b15-ab6+a6b6;
     991  ideal i = a2-b2+a6-b5+ab3,a7b+b15-ab6+a6b6;
     992
    861993  // The quotient ring by this ideal will become our image ring.;
    862994  qring Q = std(i);
    863   map f = r,-a2b6+b5+a3b+a2+ab,-a2b7-3a2b5+b4+a,a6-b6-b3+a2;
    864   f;
     995
     996  listvar();
     997 
     998  map f = r,-a2b6+b5+a3b+a2+ab,-a2b7-3a2b5+b4+a,a6-b6-b3+a2; f;
     999
     1000 
     1001  // TODO: Unfortunately this is not a very spectacular example...:
    8651002  // Pushing forward f:
    8661003  pushForward(f);
     1004
    8671005  // due to pushForward we have got new grading on Q
    8681006  getVariableWeights();
    8691007  getTorsion();
    870   // TODO: Unfortunately this is not a very spectacular example.;
     1008 
     1009
     1010  // only for the purpose of this example
     1011  if( voice > 1 ){ kill r; }
     1012
    8711013}
    8721014
     
    8751017proc equalMDeg(intvec exp1, intvec exp2, list #)
    8761018"USAGE: equalMDeg(exp1, exp2[, V]); intvec exp1, exp2, intmat V
    877 PURPOSE: Tests if the exponent vectors of two monomials (given by exp1 and exp2)
     1019PURPOSE: Tests if the exponent vectors of two monomials (given by exp1 and exp2) 
    8781020represent the same multidegree.
    879 NOTE: the integer matrix V encodes multidegrees of module components,
     1021NOTE: the integer matrix V encodes multidegrees of module components, 
    8801022if module component is present in exp1 and exp2
     1023EXAMPLE: example equalMDeg; shows an example
    8811024"
    8821025{
     
    8861029  }
    8871030
    888   if( exp1 == exp2)
     1031  if( exp1 == exp2) 
    8891032  {
    8901033    return (1==1);
     
    9281071{
    9291072  "EXAMPLE:"; echo=2;
     1073
    9301074  ring r = 0,(x,y,z),dp;
     1075
    9311076  intmat g[2][3]=
    9321077    1,0,1,
    9331078    0,1,1;
     1079
    9341080  intmat t[2][1]=
    9351081    -2,
    9361082    1;
     1083
    9371084  setBaseMultigrading(g,t);
     1085
    9381086  poly a = x10yz;
    9391087  poly b = x8y2z;
     
    9421090  poly e = x2y2;
    9431091  poly f = z2;
     1092
     1093
    9441094  equalMDeg(leadexp(a), leadexp(b));
    9451095  equalMDeg(leadexp(a), leadexp(c));
     
    9471097  equalMDeg(leadexp(a), leadexp(e));
    9481098  equalMDeg(leadexp(a), leadexp(f));
     1099
    9491100  equalMDeg(leadexp(b), leadexp(c));
    9501101  equalMDeg(leadexp(b), leadexp(d));
    9511102  equalMDeg(leadexp(b), leadexp(e));
    9521103  equalMDeg(leadexp(b), leadexp(f));
     1104
    9531105  equalMDeg(leadexp(c), leadexp(d));
    9541106  equalMDeg(leadexp(c), leadexp(e));
    9551107  equalMDeg(leadexp(c), leadexp(f));
     1108
    9561109  equalMDeg(leadexp(d), leadexp(e));
    9571110  equalMDeg(leadexp(d), leadexp(f));
     1111
    9581112  equalMDeg(leadexp(e), leadexp(f));
     1113
    9591114}
    9601115
     
    9781133"USAGE: isHomogenous(a[, f]); a polynomial/vector/ideal/module
    9791134RETURN: boolean, TRUE if a is (multi)homogenous, and FALSE otherwise
     1135EXAMPLE: example isHomogenous; shows an example
    9801136"
    9811137{
     
    10171173    def g = groebner(a); // !!!!
    10181174
    1019     def b, aa; int j;
     1175    def b, aa; int j; 
    10201176    for( int i = ncols(a); i > 0; i-- )
    10211177    {
     
    10371193    }
    10381194    return(1==1);
    1039   }
     1195  } 
    10401196}
    10411197example
    10421198{
    10431199  "EXAMPLE:"; echo=2;
     1200
    10441201  ring r = 0,(x,y,z),dp;
     1202
    10451203  //Grading and Torsion matrices:
    1046   intmat M[3][3] =
     1204  intmat M[3][3] = 
    10471205    1,0,0,
    10481206    0,1,0,
    10491207    0,0,1;
     1208
    10501209  intmat T[3][1] =
    10511210    1,2,3;
     1211
    10521212  setBaseMultigrading(M,T);
     1213
    10531214  attrib(r);
     1215
    10541216  poly f = x-yz;
     1217
    10551218  mDegPartition(f);
    10561219  print(mDeg(_));
     1220
    10571221  isHomogenous(f);   // f: is not homogenous
     1222
    10581223  poly g = 1-xy2z3;
    10591224  isHomogenous(g); // g: is homogenous
    10601225  mDegPartition(g);
     1226
    10611227  kill T;
    10621228  /////////////////////////////////////////////////////////
    10631229  // new Torsion matrix:
    1064   intmat T[3][4] =
     1230  intmat T[3][4] = 
    10651231    3,3,3,3,
    10661232    2,1,3,0,
    10671233    1,2,0,3;
     1234 
    10681235  setBaseMultigrading(M,T);
     1236
    10691237  f;
    10701238  isHomogenous(f);
    10711239  mDegPartition(f);
    1072   // ---------------------
     1240
     1241  // ---------------------
    10731242  g;
    10741243  isHomogenous(g);
    10751244  mDegPartition(g);
     1245
    10761246  kill r, T, M;
     1247
    10771248  ring R = 0, (x,y,z), dp;
    1078   intmat A[2][3] =
     1249
     1250  intmat A[2][3] =
    10791251    0,0,1,
    10801252    3,2,1;
    1081   intmat T[2][1] =
    1082     -1,
     1253  intmat T[2][1] = 
     1254    -1, 
    10831255     4;
    10841256  setBaseMultigrading(A, T);
     1257
    10851258  isHomogenous(ideal(x2 - y3 -xy +z, x*y-z, x^3 - y^2*z + x^2 -y^3)); // 1
    10861259  isHomogenous(ideal(x2 - y3 -xy +z, x*y-z, x^3 - y^2*z + x^2 -y^3), "checkGens");
    10871260  isHomogenous(ideal(x+y, x2 - y2)); // 0
     1261
    10881262  // Degree partition:
    10891263  mDegPartition(x2 - y3 -xy +z);
    10901264  mDegPartition(x3 -y2z + x2 -y3 + z + 1);
     1265
     1266 
    10911267  module N = gen(1) + (x+y) * gen(2), z*gen(3);
     1268
    10921269  intmat V[2][3] = 0; // 1, 2, 3,  4, 5, 6; //  column-wise weights of components!!??
     1270 
    10931271  vector v1, v2;
     1272 
    10941273  v1 = setModuleGrading(N[1], V); v1;
    10951274  mDegPartition(v1);
    10961275  print( mDeg(_) );
     1276
    10971277  v2 = setModuleGrading(N[2], V); v2;
    10981278  mDegPartition(v2);
    10991279  print( mDeg(_) );
     1280
    11001281  N = setModuleGrading(N, V);
    11011282  isHomogenous(N);
    11021283  print( mDeg(N) );
    1103   ///////////////////////////////////////
    1104   V =
    1105     1, 2, 3,
     1284
     1285  ///////////////////////////////////////
     1286
     1287  V =
     1288    1, 2, 3, 
    11061289    4, 5, 6;
     1290
    11071291  v1 = setModuleGrading(N[1], V); v1;
    11081292  mDegPartition(v1);
    11091293  print( mDeg(_) );
     1294
    11101295  v2 = setModuleGrading(N[2], V); v2;
    11111296  mDegPartition(v2);
    11121297  print( mDeg(_) );
     1298
    11131299  N = setModuleGrading(N, V);
    11141300  isHomogenous(N);
    11151301  print( mDeg(N) );
    1116   ///////////////////////////////////////
    1117   V =
    1118     0, 0, 0,
     1302
     1303  ///////////////////////////////////////
     1304
     1305  V =
     1306    0, 0, 0, 
    11191307    4, 1, 0;
     1308
    11201309  N = gen(1) + x * gen(2), z*gen(3);
    1121   N = setModuleGrading(N, V); N;
     1310  N = setModuleGrading(N, V); print(N);
    11221311  isHomogenous(N);
    11231312  print( mDeg(N) );
    1124   v1 = setModuleGrading(N[1], V); v1;
     1313  v1 = setModuleGrading(N[1], V); print(v1);
    11251314  mDegPartition(v1);
    11261315  print( mDeg(_) );
    1127   N = setModuleGrading(N, V); N;
     1316  N = setModuleGrading(N, V); print(N);
    11281317  isHomogenous(N);
    11291318  print( mDeg(N) );
     
    11321321/******************************************************/
    11331322proc mDeg(def A)
    1134 "USAGE: mDeg(A); any A
     1323"USAGE: mDeg(A); polynomial/vector/ideal/module A
    11351324PURPOSE: compute multidegree
     1325EXAMPLE: example mDeg; shows an example
    11361326"
    11371327{
     
    11791369    A = A - lead(A);
    11801370    while( size(A) > 0 )
    1181     {
     1371    { 
    11821372      v = leadexp(A); //  v;
    11831373      m = max( m, M * v, r ); // ????
     
    12001390    A = A - lead(A);
    12011391    while( size(A) > 0 )
    1202     {
     1392    { 
    12031393      v = leadexp(A); //  v;
    12041394
     
    12251415      {
    12261416        G[j, i] = d[j];
    1227       }
     1417      }     
    12281418    }
    12291419    return(G);
     
    12391429      v = setModuleGrading(A[i], V);
    12401430
    1241       // G[1..r, i]
     1431      // G[1..r, i] 
    12421432      d = mDeg(v);
    12431433
     
    12451435      {
    12461436        G[j, i] = d[j];
    1247       }
     1437      }     
    12481438
    12491439    }
     
    12511441    return(G);
    12521442  }
    1253 
     1443 
    12541444}
    12551445example
    12561446{
    12571447  "EXAMPLE:"; echo=2;
     1448
    12581449  ring r = 0,(x, y), dp;
     1450
    12591451  intmat A[2][2] = 1, 0, 0, 1;
    12601452  print(A);
     1453
    12611454  intmat Ta[2][1] = 0, 3;
    12621455  print(Ta);
     1456
    12631457  //   attrib(A, "torsion", Ta); // to think about
     1458
    12641459//  "poly:";
    12651460  setBaseMultigrading(A);
     1461
     1462
    12661463  mDeg( x*x, A );
    12671464  mDeg( y*y*y, A );
     1465
    12681466  setBaseMultigrading(A, Ta);
     1467 
    12691468  mDeg( x*x*y );
     1469 
    12701470  mDeg( y*y*y*x );
     1471 
    12711472  mDeg( x*y + x + 1 );
     1473
    12721474  mDegPartition(x*y + x + 1);
     1475
    12731476  print ( mDeg(0) );
    12741477  poly zero = 0;
    12751478  print ( mDeg(zero) );
     1479
    12761480//  "ideal:";
     1481 
    12771482  ideal I = y*x*x, x*y*y*y;
    12781483  print( mDeg(I) );
     1484
    12791485  print ( mDeg(ideal(0)) );
    12801486  print ( mDeg(ideal(0,0,0)) );
     1487
    12811488//  "vectors:";
     1489 
    12821490  intmat B[2][2] = 0, 1, 1, 0;
    12831491  print(B);
     1492 
    12841493  mDeg( setModuleGrading(y*y*y*gen(2), B ));
    12851494  mDeg( setModuleGrading(x*x*gen(1), B ));
     1495
     1496 
    12861497  vector V = x*gen(1) + y*gen(2);
    12871498  V = setModuleGrading(V, B);
    12881499  mDeg( V );
     1500
    12891501  vector v1 = setModuleGrading([0, 0, 0], B);
    12901502  print( mDeg( v1 ) );
     1503 
    12911504  vector v2 = setModuleGrading([0], B);
    12921505  print( mDeg( v2 ) );
     1506
    12931507//  "module:";
     1508 
    12941509  module D = x*gen(1), y*gen(2);
    12951510  D;
    12961511  D = setModuleGrading(D, B);
    12971512  print( mDeg( D ) );
     1513 
     1514
    12981515  module DD = [0, 0],[0, 0, 0];
    12991516  DD = setModuleGrading(DD, B);
    13001517  print( mDeg( DD ) );
     1518
    13011519  module DDD = [0, 0];
    13021520  DDD = setModuleGrading(DDD, B);
    13031521  print( mDeg( DDD ) );
     1522
    13041523};
    13051524
     
    13121531"USAGE: mDegPartition(def p), p polynomial/vector
    13131532RETURNS: an ideal/module consisting of multigraded-homogeneous parts of p
     1533EXAMPLE: example mDegPartition; shows an example
    13141534"
    13151535{
    1316   if( typeof(p) == "poly" )
    1317   {
    1318     ideal I;
     1536  if( typeof(p) == "poly" ) 
     1537  {
     1538    ideal I;     
    13191539    poly mp, t, tt;
    13201540  }
     
    13231543    if(  typeof(p) == "vector" )
    13241544    {
    1325       module I;
     1545      module I;     
    13261546      vector mp, t, tt;
    13271547    }
     
    13341554  if( typeof(p) == "vector" )
    13351555  {
    1336     intmat V = getModuleGrading(p);
     1556    intmat V = getModuleGrading(p); 
    13371557  }
    13381558  else
     
    13411561  }
    13421562
    1343   if( size(p) > 1)
     1563  if( size(p) > 1) 
    13441564  {
    13451565    intvec m;
     
    13481568    {
    13491569      m = leadexp(p);
    1350       mp = lead(p);
     1570      mp = lead(p); 
    13511571      p = p - lead(p);
    13521572      tt = p; t = 0;
    13531573
    13541574      while( size(tt) > 0 )
    1355       {
    1356         // TODO: we make no caching of matrices (M,T,H,V), which remain the same!
    1357         if( equalMDeg( leadexp(tt), m, V  ) )
     1575      {
     1576        // TODO: we do not cache matrices (M,T,H,V), which remain the same :(
     1577        // TODO: we need some low-level procedure with all these arguments...!
     1578        if( equalMDeg( leadexp(tt), m, V  ) )
    13581579        {
    13591580          mp = mp + lead(tt); // "mp", mp;
     
    13871608{
    13881609  "EXAMPLE:"; echo=2;
     1610
    13891611  ring r = 0,(x,y,z),dp;
     1612
    13901613  intmat g[2][3]=
    13911614    1,0,1,
     
    13941617    -2,
    13951618    1;
     1619
    13961620  setBaseMultigrading(g,t);
     1621
    13971622  poly f = x10yz+x8y2z-x4z2+y5+x2y2-z2+x17z3-y6;
     1623
    13981624  mDegPartition(f);
     1625 
    13991626  vector v = xy*gen(1)-x3y2*gen(2)+x4y*gen(3);
    14001627  intmat B[2][3]=1,-1,-2,0,0,1;
    14011628  v = setModuleGrading(v,B);
    14021629  getModuleGrading(v);
     1630 
    14031631  mDegPartition(v, B);
    14041632}
     
    14101638{
    14111639  intmat A[n][n];
    1412 
     1640 
    14131641  for( int i = n; i > 0; i-- )
    14141642  {
     
    14241652static proc finestMDeg(def r)
    14251653"
    1426 USAGE:
    1427 PURPOSE: finest multigrading
     1654USAGE: finestMDeg(r); ring r
     1655RETURN: ring, r endowed with the finest multigrading
     1656TODO: not yet...
    14281657"
    14291658{
     
    14531682
    14541683
    1455   if( n > 0)
    1456   {
    1457 
    1458     intmat L[N][n];
     1684  if( n > 0) 
     1685  {
     1686
     1687    intmat L[N][n]; 
    14591688    //  list L;
    14601689    int j = n;
     
    14641693      p = I[i];
    14651694
    1466       if( size(p) > 1 )
     1695      if( size(p) > 1 ) 
    14671696      {
    14681697        intvec m0 = leadexp(p);
     
    14791708
    14801709    print(L);
    1481     setBaseMultigrading(A, L);
    1482   }
     1710    setBaseMultigrading(A, L);     
     1711  } 
    14831712  else
    14841713  {
     
    14961725{
    14971726  "EXAMPLE:"; echo=2;
     1727
    14981728  ring r = 0,(x, y), dp;
    14991729  qring q  = std(x^2 - y);
     1730
    15001731  finestMDeg(q);
     1732
    15011733}
    15021734
     
    15071739static proc newMap(map F, intmat Q, list #)
    15081740"
    1509 USAGE: ?? no use now...
    1510 PURPOSE: ??
     1741USAGE: newMap(F, Q[, P]); map F, intmat Q[, intmat P]
     1742PURPOSE: endowe the map F with the integer matrices P [and Q]
    15111743"
    15121744{
     
    15141746
    15151747  if( size(#) > 0 and typeof(#[1]) == "intmat" )
    1516   {
     1748  { 
    15171749    attrib(F, "P", #[1]);
    15181750  }
    15191751  return (F);
    15201752}
    1521 
    15221753
    15231754/******************************************************/
     
    15651796{
    15661797  "EXAMPLE:"; echo=2;
     1798
    15671799  ring r= 0,(x,y,z),dp;
    15681800  matrix M[3][1] = x,y,z;
     
    15841816@*       i=int
    15851817ASSUME:  - A is a matrix with integer entries which describes the lattice
    1586 @*         as ker(A), if second argument is not present,
     1818@*         as ker(A), if second argument is not present, and
    15871819@*         as the left image Im(A) = {zA : z \in ZZ^k}, if second argument is a positive integer
    15881820@*       - number of variables of basering equals number of columns of A
     
    16491881   j=system("sh","hilbert -q -n sing4ti2"); ////////// be quiet + no loggin!!!
    16501882
    1651    j=system("sh", "awk \'BEGIN{ORS=\",\";}{print $0;}\' sing4ti2.hil " +
    1652                 "| sed s/[\\\ \\\t\\\v\\\f]/,/g " +
    1653                 "| sed s/,+/,/g|sed s/,,/,/g " +
    1654                 "| sed s/,,/,/g " +
     1883   j=system("sh", "awk \'BEGIN{ORS=\",\";}{print $0;}\' sing4ti2.hil " + 
     1884                "| sed s/[\\\ \\\t\\\v\\\f]/,/g " + 
     1885                "| sed s/,+/,/g|sed s/,,/,/g " + 
     1886                "| sed s/,,/,/g " + 
    16551887                "> sing4ti2.converted" );
    16561888   if( defined(keepfiles) <= 0)
     
    16681900   string ergstr = "intvec erglist = " + s + "0;";
    16691901   execute(ergstr);
    1670 
     1902 
    16711903   //   print(erglist);
    1672 
     1904 
    16731905   int Rnc = erglist[1];
    16741906   int Rnr = erglist[2];
    1675 
     1907   
    16761908   intmat R[Rnr][Rnc];
    16771909
     
    16971929{
    16981930  "EXAMPLE:"; echo=2;
     1931
    16991932   ring r=0,(x1,x2,x3,x4,x5,x6,x7,x8,x9),dp;
    17001933   intmat M[7][9]=
     
    17381971
    17391972/******************************************************/
    1740 proc mDegBasis(intvec d)
     1973proc mDegBasis(intvec d) 
    17411974"
    17421975USAGE: multidegree d
    17431976ASSUME: current ring is multigraded, monomial ordering is global
    17441977PURPOSE: compute all monomials of multidegree d
     1978EXAMPLE: example mDegBasis; shows an example
    17451979"
    17461980{
     
    17812015
    17822016    intmat AA[nr][nc + 2 * n];
    1783     AA[1..nr, 1.. nc] = A[1..nr, 1.. nc];
    1784     AA[1..nr, nc + (1.. n)] = T[1..nr, 1.. n];
    1785     AA[1..nr, nc + n + (1.. n)] = -T[1..nr, 1.. n];
     2017    AA[1..nr, 1.. nc] = A[1..nr, 1.. nc]; 
     2018    AA[1..nr, nc + (1.. n)] = T[1..nr, 1.. n]; 
     2019    AA[1..nr, nc + n + (1.. n)] = -T[1..nr, 1.. n]; 
    17862020
    17872021
    17882022    //      print ( AA );
    17892023
    1790     intmat K = leftKernelZ(( AA ) ); //
     2024    intmat K = leftKernelZ(( AA ) ); // 
    17912025
    17922026    //      print(K);
     
    17972031    //      "!";
    17982032
    1799     intmat B = hilbert4ti2intmat(transpose(KK), 1);
     2033    intmat B = hilbert4ti2intmat(transpose(KK), 1); 
    18002034
    18012035    //      "!";      print(B);
     
    18082042
    18092043
    1810   int i;
     2044  int i; 
    18112045  int nnr = nrows(B);
    18122046  int nnc = ncols(B);
     
    18592093{
    18602094  "EXAMPLE:"; echo=2;
     2095
    18612096  ring R = 0, (x, y), dp;
     2097
    18622098  intmat g1[2][2]=1,0,0,1;
    18632099  intmat t[2][1]=2,0;
     
    18652101  intvec v1=4,0;
    18662102  intvec v2=4,4;
     2103 
    18672104  intmat g3[1][2]=1,1;
    18682105  setBaseMultigrading(g3);
     
    18702107  v3;
    18712108  mDegBasis(v3);
     2109 
    18722110  setBaseMultigrading(g1,t);
    18732111  mDegBasis(v1);
    18742112  setBaseMultigrading(g2);
    18752113  mDegBasis(v2);
     2114 
    18762115  intmat M[2][2] = 1, -1, -1, 1;
    18772116  intvec d = -2, 2;
     2117
    18782118  setBaseMultigrading(M);
     2119
    18792120  mDegBasis(d);
    18802121  attrib(_, "ZeroPart");
     2122
    18812123  kill R;
    18822124  ring R = 0, (x, y, z), dp;
     2125
    18832126  intmat M[2][3] = 1, -2, 1,     1, 1, 0;
     2127
    18842128  intmat T[2][1] = 0, 2;
     2129
    18852130  intvec d = 4, 1;
     2131
    18862132  setBaseMultigrading(M, T);
     2133
    18872134  mDegBasis(d);
    18882135  attrib(_, "ZeroPart");
     2136
     2137
    18892138  kill R;
     2139
    18902140  ring R = 0, (x, y, z), dp;
    18912141  qring Q = std(ideal( y^6+ x*y^3*z-x^2*z^2 ));
     2142
     2143
    18922144  intmat M[2][3] = 1, 1, 2,     2, 1, 1;
    18932145  //  intmat T[2][1] = 0, 2;
     2146
    18942147  setBaseMultigrading(M);
     2148
    18952149  intvec d = 6, 6;
    18962150  mDegBasis(d);
    18972151  attrib(_, "ZeroPart");
     2152
     2153
     2154
    18982155  kill R;
    18992156  ring R = 0, (x, y, z), dp;
    19002157  qring Q = std(ideal( x*z^3 - y *z^6, x*y*z  - x^4*y^2 ));
     2158
     2159
    19012160  intmat M[2][3] = 1, -2, 1,     1, 1, 0;
    19022161  intmat T[2][1] = 0, 2;
     2162
    19032163  intvec d = 4, 1;
     2164
    19042165  setBaseMultigrading(M, T);
     2166
    19052167  mDegBasis(d);
    19062168  attrib(_, "ZeroPart");
     
    19102172proc mDegSyzygy(def I)
    19112173"USAGE: mDegSyzygy(I); I is a poly/vector/ideal/module
    1912 PURPOSE: computes the multigraded syzygy of I
    1913 RETURNS: module, the syzygy of I
    1914 NOTE: generators of I must be multigraded homogeneous
     2174PURPOSE: computes the multigraded syzygy module of I
     2175RETURNS: module, the syzygy module of I
     2176NOTE: generators of I must be multigraded homogeneous
     2177EXAMPLE: example mDegSyzygy; shows an example
    19152178"
    19162179{
    1917   if( isHomogenous(I, "checkGens") == 0)
    1918   {
    1919     ERROR ("Sorry: inhomogenous input!");
    1920   }
     2180  if( isHomogenous(I, "checkGens") == 0) 
     2181  { 
     2182    ERROR ("Sorry: inhomogenous input!"); 
     2183  } 
    19212184  module S = syz(I);
    19222185  S = setModuleGrading(S, mDeg(I));
     
    19262189{
    19272190  "EXAMPLE:"; echo=2;
     2191 
     2192
    19282193  ring r = 0,(x,y,z,w),dp;
    19292194  intmat MM[2][4]=
     
    19322197  setBaseMultigrading(MM);
    19332198  module M = ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
     2199 
     2200 
    19342201  intmat v[2][nrows(M)]=
    19352202    1,
    19362203    0;
     2204 
    19372205  M = setModuleGrading(M, v);
     2206
    19382207  isHomogenous(M);
    19392208  "Multidegrees: "; print(mDeg(M));
    1940   // Let's compute Syzygy!
     2209  // Let's compute syzygies!
    19412210  def S = mDegSyzygy(M); S;
    19422211  "Module Units Multigrading: "; print( getModuleGrading(S) );
    19432212  "Multidegrees: "; print(mDeg(S));
     2213
    19442214  isHomogenous(S);
    19452215}
     
    19492219"USAGE: mDegGroebner(I); I is a poly/vector/ideal/module
    19502220PURPOSE: computes the multigraded standard/groebner basis of I
    1951 NOTE: I must be multigraded homogeneous
     2221NOTE: I must be multigraded homogeneous 
    19522222RETURNS: ideal/module, the computed basis
     2223EXAMPLE: example mDegGroebner; shows an example
    19532224"
    19542225{
    1955   if( isHomogenous(I) == 0)
    1956   {
    1957     ERROR ("Sorry: inhomogenous input!");
    1958   }
     2226  if( isHomogenous(I) == 0) 
     2227  { 
     2228    ERROR ("Sorry: inhomogenous input!"); 
     2229  } 
    19592230
    19602231  def S = groebner(I);
    1961 
     2232 
    19622233  if( typeof(I) == "module" or typeof(I) == "vector" )
    19632234  {
    1964     S = setModuleGrading(S, getModuleGrading(I));
     2235    S = setModuleGrading(S, getModuleGrading(I));     
    19652236  }
    19662237
     
    19792250  setBaseMultigrading(MM);
    19802251
    1981 
     2252 
    19822253  module M = ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
    1983 
    1984 
     2254 
     2255 
    19852256  intmat v[2][nrows(M)]=
    19862257    1,
    19872258    0;
    1988 
     2259 
    19892260  M = setModuleGrading(M, v);
    19902261
     
    20192290proc mDegResolution(def I, int ll, list #)
    20202291"USAGE: mDegResolution(I,l,[f]); I is poly/vector/ideal/module; l,f are integers
    2021 PURPOSE: computes the multigraded resolution of I of the length l,
    2022 or the whole resolution if l is zero. Returns minimal resolution if an optional
     2292PURPOSE: computes the multigraded resolution of I of the length l, 
     2293or the whole resolution if l is zero. Returns minimal resolution if an optional 
    20232294argument 1 is supplied
    20242295NOTE: input must have multigraded-homogeneous generators.
    2025 The returned list is trunkated at the first zero entry.
     2296The returned list is truncated beginning with the first zero differential.   
    20262297RETURNS: list, the computed resolution
     2298EXAMPLE: example mDegResolution; shows an example
    20272299"
    20282300{
    2029   if( isHomogenous(I, "checkGens") == 0)
    2030   {
    2031     ERROR ("Sorry: inhomogenous input!");
    2032   }
     2301  if( isHomogenous(I, "checkGens") == 0) 
     2302  { 
     2303    ERROR ("Sorry: inhomogenous input!"); 
     2304  } 
    20332305
    20342306  def R = res(I, ll, #); list L = R; int l = size(L);
     
    20362308  if( (typeof(I) == "module") or (typeof(I) == "vector") )
    20372309  {
    2038     L[1] = setModuleGrading(L[1], getModuleGrading(I));
    2039   }
    2040 
    2041   int i;
     2310    L[1] = setModuleGrading(L[1], getModuleGrading(I));     
     2311  }
     2312
     2313  int i; 
    20422314  for( i = 2; i <= l; i++ )
    20432315  {
     
    20502322    }
    20512323  }
    2052 
     2324 
    20532325  return (L);
    20542326
    2055 
     2327 
    20562328}
    20572329example
    20582330{
    20592331  "EXAMPLE:"; echo=2;
     2332 
    20602333  ring r = 0,(x,y,z,w),dp;
     2334
    20612335  intmat M[2][4]=
    20622336    1,1,1,1,
    20632337    0,1,3,4;
     2338
    20642339  setBaseMultigrading(M);
     2340
     2341 
    20652342  module m= ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3);
     2343 
    20662344  isHomogenous(ideal(  xw-yz, x2z-y3, xz2-y2w, yw2-z3), "checkGens");
     2345 
    20672346  ideal A = xw-yz, x2z-y3, xz2-y2w, yw2-z3;
     2347
    20682348  int j;
     2349 
    20692350  for(j=1; j<=ncols(A); j++)
    20702351  {
    20712352    mDegPartition(A[j]);
    20722353  }
     2354 
    20732355  intmat v[2][1]=
    20742356    1,
    20752357    0;
     2358 
    20762359  m = setModuleGrading(m, v);
     2360
    20772361  // Let's compute Syzygy!
    20782362  def S = mDegSyzygy(m); S;
    20792363  "Module Units Multigrading: "; print( getModuleGrading(S) );
    20802364  "Multidegrees: "; print(mDeg(S));
     2365
    20812366  /////////////////////////////////////////////////////////////////////////////
     2367
    20822368  S = mDegGroebner(S); S;
    20832369  "Module Units Multigrading: "; print( getModuleGrading(S) );
    20842370  "Multidegrees: "; print(mDeg(S));
     2371
    20852372  /////////////////////////////////////////////////////////////////////////////
     2373
    20862374  def L = mDegResolution(m, 0, 1);
     2375
    20872376  for( j =1; j<=size(L); j++)
    20882377  {
     
    20922381    "Multigrading: "; print(mDeg(L[j]));
    20932382  }
     2383
    20942384  /////////////////////////////////////////////////////////////////////////////
     2385 
    20952386  L = mDegResolution(maxideal(1), 0, 1);
     2387
    20962388  for( j =1; j<=size(L); j++)
    20972389  {
     
    21012393    "Multigrading: "; print(mDeg(L[j]));
    21022394  }
     2395 
    21032396  kill v;
     2397 
     2398
    21042399  def h = hilbertSeries(m);
    21052400  setring h;
     2401
    21062402  numerator1;
    21072403  factorize(numerator1);
     2404 
    21082405  denominator1;
    21092406  factorize(denominator1);
     2407
    21102408  numerator2;
    21112409  factorize(numerator2);
     2410
    21122411  denominator2;
    21132412  factorize(denominator2);
     
    21172416proc hilbertSeries(def I)
    21182417"USAGE: hilbertSeries(I); I is poly/vector/ideal/module
    2119 PURPOSE: computes the multigraded Hilbert Series of M
    2120 NOTE: input must have multigraded-homogeneous generators.
     2418PURPOSE: computes the multigraded Hilbert Series of M 
     2419NOTE: input must have multigraded-homogeneous generators. 
    21212420Multigrading should be positive.
    2122 RETURNS: a ring in variables t_(i), s_(i), with polynomials
    2123 numerator1 and denominator1 and muturally prime numerator2
     2421RETURNS: a ring in variables t_(i), s_(i), with polynomials 
     2422numerator1 and denominator1 and muturally prime numerator2 
    21242423and denominator2, quotients of which give the series.
     2424EXAMPLE: example hilbertSeries; shows an example
    21252425"
    21262426{
    2127 
     2427   
    21282428  if( !isFreeRepresented() )
    21292429  {
    21302430    ERROR("SORRY: ONLY TORSION-FREE CASE (POSITIVE GRADING)");
    21312431  }
    2132 
     2432   
    21332433  int i, j, k, v;
    21342434
    21352435  intmat M = getVariableWeights();
    2136 
     2436 
    21372437  int cc = ncols(M);
    21382438  int n = nrows(M);
     
    21462446
    21472447  int l = size(RES);
    2148 
     2448 
    21492449  list L; L[l + 1] = 0;
    21502450
     
    21532453    intmat zeros[n][1];
    21542454    L[1] = zeros;
    2155   }
     2455  } 
    21562456  else
    21572457  {
     
    21632463    L[j + 1] = mDeg(RES[j]);
    21642464  }
    2165 
     2465 
    21662466  l++;
    21672467
    21682468  ring R = 0,(t_(1..n),s_(1..n)),dp;
    2169 
    2170   ideal units;
     2469 
     2470  ideal units; 
    21712471  for( i=n; i>=1; i--)
    21722472  {
    21732473    units[i] = (var(i) * var(n + i) - 1);
    21742474  }
    2175 
     2475 
    21762476  qring Q = std(units);
    2177 
     2477 
    21782478  // TODO: should not it be a quotient ring depending on Torsion???
    21792479  // I am not sure about what to do in the torsion case, but since
     
    21842484  poly monom, summand, numerator;
    21852485  poly denominator = 1;
    2186 
     2486 
    21872487  for( i = 1; i <= cc; i++)
    21882488  {
     
    21962496      {
    21972497        monom = monom * (var(k)^(v));
    2198       }
     2498      } 
    21992499      else
    22002500      {
     
    22022502      }
    22032503    }
    2204 
     2504   
    22052505    if( monom == 1)
    22062506    {
     
    22102510    denominator = denominator * (1 - monom);
    22112511  }
    2212 
    2213   for( j = 1; j<= l; j++)
     2512 
     2513  for( j = 1; j<= l; j++) 
    22142514  {
    22152515    summand = 0;
     
    22252525        {
    22262526          monom = monom * (var(k)^v);
    2227         }
     2527        } 
    22282528        else
    22292529        {
     
    22352535    numerator = numerator - (-1)^j * summand;
    22362536  }
    2237 
     2537 
    22382538  if( denominator == 0 )
    22392539  {
    22402540    ERROR("Multigrading not positive.");
    2241   }
    2242 
     2541  } 
     2542 
    22432543  poly denominator1 = denominator;
    22442544  poly numerator1 = numerator;
     
    22742574  "The s_(i)-variables are defined to be the inverse of the t_(i)-variables.";
    22752575  " ------------ ";
    2276 
     2576 
    22772577  return(Q);
    22782578}
     
    22802580{
    22812581  "EXAMPLE:"; echo=2;
     2582 
    22822583  ring r = 0,(x,y,z,w),dp;
    22832584  intmat g[2][4]=
     
    22852586    0,1,3,4;
    22862587  setBaseMultigrading(g);
     2588 
    22872589  module M = ideal(xw-yz, x2z-y3, xz2-y2w, yw2-z3);
    22882590  intmat V[2][1]=
    22892591    1,
    22902592    0;
     2593
    22912594  M = setModuleGrading(M, V);
     2595
    22922596  def h = hilbertSeries(M); setring h;
     2597
    22932598  factorize(numerator2);
    22942599  factorize(denominator2);
     2600 
    22952601  kill g, h; setring r;
     2602
    22962603  intmat g[2][4]=
    22972604    1,2,3,4,
    22982605    0,0,5,8;
     2606 
    22992607  setBaseMultigrading(g);
     2608 
    23002609  ideal I = x^2, y, z^3;
    23012610  I = std(I);
    23022611  def L = mDegResolution(I, 0, 1);
     2612
    23032613  for( int j = 1; j<=size(L); j++)
    23042614  {
     
    23082618    "Multigrading: "; print(mDeg(L[j]));
    23092619  }
     2620
    23102621  mDeg(I);
    23112622  def h = hilbertSeries(I); setring h;
     2623 
    23122624  factorize(numerator2);
    23132625  factorize(denominator2);
     2626
    23142627  kill r, h, g, V;
    23152628  ////////////////////////////////////////////////
    23162629  ring R = 0,(x,y,z),dp;
    2317   intmat W[2][3] =
     2630  intmat W[2][3] = 
    23182631     1,1, 1,
    23192632     0,0,-1;
    23202633  setBaseMultigrading(W);
    23212634  ideal I = x3y,yz2,y2z,z4;
     2635 
    23222636  def h = hilbertSeries(I); setring h;
     2637 
    23232638  factorize(numerator2);
    23242639  factorize(denominator2);
     2640
    23252641  kill R, W, h;
    23262642  ////////////////////////////////////////////////
    23272643  ring R = 0,(x,y,z,a,b,c),dp;
    2328   intmat W[2][6] =
     2644  intmat W[2][6] = 
    23292645     1,1, 1,1,1,1,
    23302646     0,0,-1,0,0,0;
    23312647  setBaseMultigrading(W);
    23322648  ideal I = x3y,yz2,y2z,z4;
     2649 
    23332650  def h = hilbertSeries(I); setring h;
     2651 
    23342652  factorize(numerator2);
    23352653  factorize(denominator2);
     2654 
    23362655  kill R, W, h;
    23372656  ////////////////////////////////////////////////
    23382657  // This is example 5.3.9. from Robbianos book.
     2658 
    23392659  ring R = 0,(x,y,z,w),dp;
    2340   intmat W[1][4] =
     2660  intmat W[1][4] = 
    23412661     1,1, 1,1;
    23422662  setBaseMultigrading(W);
    23432663  ideal I = z3,y3zw2,x2y4w2xyz2;
     2664
    23442665  hilb(std(I));
     2666 
    23452667  def h = hilbertSeries(I); setring h;
     2668 
    23462669  numerator1;
    23472670  denominator1;
     2671
    23482672  factorize(numerator2);
    23492673  factorize(denominator2);
     2674 
     2675
    23502676  kill h;
    23512677  ////////////////////////////////////////////////
    23522678  setring R;
     2679
    23532680  ideal I2 = x2,y2,z2; I2;
     2681
    23542682  hilb(std(I2));
     2683 
    23552684  def h = hilbertSeries(I2); setring h;
     2685
    23562686  numerator1;
    23572687  denominator1;
     2688
     2689
    23582690  kill h;
    23592691  ////////////////////////////////////////////////
    23602692  setring R;
     2693 
    23612694  W = 2,2,2,2;
     2695 
    23622696  setBaseMultigrading(W);
     2697
    23632698  getVariableWeights();
     2699
    23642700  intvec w = 2,2,2,2;
     2701
    23652702  hilb(std(I2), 1, w);
     2703
    23662704  kill w;
     2705 
     2706
    23672707  def h = hilbertSeries(I2); setring h;
     2708
     2709 
    23682710  numerator1; denominator1;
    23692711  kill h;
     2712
     2713 
    23702714  kill R, W;
     2715
    23712716  ////////////////////////////////////////////////
    23722717  ring R = 0,(x),dp;
     
    23742719     1;
    23752720  setBaseMultigrading(W);
     2721
    23762722  ideal I;
     2723
    23772724  I = 1; I;
     2725
    23782726  hilb(std(I));
     2727 
    23792728  def h = hilbertSeries(I); setring h;
     2729
    23802730  numerator1; denominator1;
     2731
    23812732  kill h;
    23822733  ////////////////////////////////////////////////
    23832734  setring R;
     2735
    23842736  I = x; I;
     2737
    23852738  hilb(std(I));
     2739
    23862740  def h = hilbertSeries(I); setring h;
     2741
    23872742  numerator1; denominator1;
     2743 
     2744  kill h; 
     2745  ////////////////////////////////////////////////
     2746  setring R;
     2747
     2748  I = x^5; I;
     2749
     2750  hilb(std(I));
     2751  hilb(std(I), 1);
     2752
     2753  def h = hilbertSeries(I); setring h;
     2754
     2755  numerator1; denominator1;
     2756 
     2757 
     2758  kill h; 
     2759  ////////////////////////////////////////////////
     2760  setring R;
     2761
     2762  I = x^10; I;
     2763
     2764  hilb(std(I));
     2765
     2766  def h = hilbertSeries(I); setring h;
     2767
     2768  numerator1; denominator1;
     2769
    23882770  kill h;
    23892771  ////////////////////////////////////////////////
    23902772  setring R;
    2391   I = x^5; I;
    2392   hilb(std(I));
    2393   hilb(std(I), 1);
    2394   def h = hilbertSeries(I); setring h;
     2773
     2774  module M = 1;
     2775
     2776  M = setModuleGrading(M, W);
     2777
     2778 
     2779  hilb(std(M));
     2780
     2781  def h = hilbertSeries(M); setring h;
     2782
    23952783  numerator1; denominator1;
     2784
    23962785  kill h;
    23972786  ////////////////////////////////////////////////
    23982787  setring R;
    2399   I = x^10; I;
    2400   hilb(std(I));
    2401   def h = hilbertSeries(I); setring h;
     2788
     2789  kill M; module M = x^5*gen(1);
     2790//  intmat V[1][3] = 0; // TODO: this would lead to a wrong result!!!?
     2791  intmat V[1][1] = 0; // all gen(i) of degree 0!
     2792
     2793  M = setModuleGrading(M, V);
     2794
     2795  hilb(std(M));
     2796
     2797  def h = hilbertSeries(M); setring h;
     2798
    24022799  numerator1; denominator1;
     2800
    24032801  kill h;
    24042802  ////////////////////////////////////////////////
    2405   setring R;
    2406   module M = 1;
    2407   M = setModuleGrading(M, W);
    2408   hilb(std(M));
    2409   def h = hilbertSeries(M); setring h;
     2803  setring R;
     2804
     2805  module N = x^5*gen(3);
     2806
     2807  kill V;
     2808 
     2809  intmat V[1][3] = 0; // all gen(i) of degree 0!
     2810
     2811  N = setModuleGrading(N, V);
     2812     
     2813  hilb(std(N));
     2814
     2815  def h = hilbertSeries(N); setring h;
     2816
    24102817  numerator1; denominator1;
     2818
    24112819  kill h;
    24122820  ////////////////////////////////////////////////
    2413   setring R;
    2414   kill M; module M = x^5*gen(1);
    2415 //  intmat V[1][3] = 0; // TODO: this would lead to a wrong result!!!?
    2416   intmat V[1][1] = 0; // all gen(i) of degree 0!
    2417   M = setModuleGrading(M, V);
    2418   hilb(std(M));
    2419   def h = hilbertSeries(M); setring h;
     2821  setring R;
     2822
     2823 
     2824  module S = M + N;
     2825 
     2826  S = setModuleGrading(S, V);
     2827
     2828  hilb(std(S));
     2829
     2830  def h = hilbertSeries(S); setring h;
     2831
    24202832  numerator1; denominator1;
     2833
    24212834  kill h;
    2422   ////////////////////////////////////////////////
    2423   setring R;
    2424   module N = x^5*gen(3);
    2425   kill V;
    2426   intmat V[1][3] = 0; // all gen(i) of degree 0!
    2427   N = setModuleGrading(N, V);
    2428   hilb(std(N));
    2429   def h = hilbertSeries(N); setring h;
    2430   numerator1; denominator1;
    2431   kill h;
    2432   ////////////////////////////////////////////////
    2433   setring R;
    2434   module S = M + N;
    2435   S = setModuleGrading(S, V);
    2436   hilb(std(S));
    2437   def h = hilbertSeries(S); setring h;
    2438   numerator1; denominator1;
    2439   kill h;
     2835
    24402836  kill V;
    24412837  kill R, W;
     2838
    24422839}
    24432840
     
    24482845proc testMultigradingLib ()
    24492846{
     2847  echo = 2; printlevel = 3;
    24502848  example setBaseMultigrading;
    24512849  example setModuleGrading;
     
    24702868
    24712869  example mDegResolution;
     2870 
     2871  "// ******************* example hilbertSeries ************************//";
    24722872  example hilbertSeries;
    24732873
    24742874
    24752875// example mDegBasis; // needs 4ti2!
    2476 }
     2876
     2877  "The End!";
     2878
     2879}
Note: See TracChangeset for help on using the changeset viewer.