Changeset d63ce7 in git


Ignore:
Timestamp:
Jan 28, 2015, 8:10:16 PM (9 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
a0082e2e3d7a68676ebf9aa816c2ca887ea0c56c
Parents:
6fcbe89e09cb8c0ccfddde65e57da4c5a60c8854
Message:
Cleanup / fixes in gradedModules.lib

chg: try to use align if present
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/gradedModules.lib

    r6fcbe89 rd63ce7  
    3232";
    3333
     34
     35
     36
    3437//////////////////////////////////////////////////////////////////////////////////////////////////////////
    3538// . view graded module/map
     
    204207}
    205208
     209// Q@Wolfram: what should be done with zero gens!?
    206210proc grdeg( def M, list # )
    207211"graded degrees of gens(i.e. columns)"
    208 
    209212{
    210213 // use initial grading if given
     
    221224    kill w;
    222225  }
    223 
    224   // try to homogenize otherwise
    225   if( typeof(attrib( M, "isHomog")) != "intvec" )
    226   { // no such attribute? //   ERROR("No grading!");
    227     ASSUME(0, /* input must be graded: cannot compute homogenizing grading */ homog(M) );
    228   }
    229 
    230  
    231   ASSUME(0, /* input must be graded! */ typeof(attrib(M, "isHomog")) == "intvec" );
    232   // input should be graded:
     226 
     227  ASSUME(1, grtest(M) );
     228
    233229  def w = attrib(M, "isHomog"); // grading weights?
    234   ASSUME(0, /* input must be correctly graded! */ nrows(M) == size(w) );   
    235 
    236   if( size(M) == 0 )  {    return (w);  } // TODO???
     230
     231  if( size(M) == 0 ){ return (w); } // TODO: Q@Wolfram!???
    237232
    238233  int m = ncols(M); // m > 0 in Singular!
     
    251246}
    252247
    253 
    254 static proc order( def M, int s, list #)
    255 "helper for reorder: compute graded degrees and the permutation to sort them"
    256 {
    257   if( size(#) > 0 ) { intvec gr = grdeg( M, #[1] ); }
    258   else              { intvec gr = grdeg( M       ); }
    259  
     248static proc reorder(def M, int s)
     249"
     250Reorder gens of M: compute graded degrees and the permutation to sort them
     251"
     252{
     253  // input should be graded:
     254  ASSUME(1, grtest(M) );
     255
     256  intvec w = attrib(M, "isHomog"); // grading weights
     257
     258  intvec gr = grdeg( M );
    260259 
    261260//  intvec d = deg(M[1..nocls(M)]); // no need to deal with un-weighted degrees??!
     
    263262  intvec pivot = mysort(gr, s);
    264263
     264  // grades & ordering permutation for N.  gr[pivot] should be sorted!
    265265  ASSUME(1, issorted(gr[pivot], s));
    266266 
    267   return (gr, pivot);
    268 }
    269 
    270 
    271 static proc reorder(def M, int s, list #)
    272 "
    273 helper for    Reorder gens of M
    274 "
    275 {
    276   // use initial grading if given
    277   if( size(#) == 1 )
    278   {
    279     def w = #[1];
    280     if( typeof(w) == "intvec" )
    281     {
    282       if( nrows(M) == size(w) )
    283       {
    284         attrib(M, "isHomog", w);
    285       }
    286     }
    287     kill w;
    288   }
    289 
    290   // try to homogenize otherwise
    291   if( typeof(attrib( M, "isHomog")) != "intvec" )
    292   { // no such attribute? //   ERROR("No grading!");
    293     ASSUME(0, /* input must be graded: cannot compute homogenizing grading */ homog(M) );
    294   }
    295 
    296   ASSUME(0, /* input must be graded! */ typeof(attrib(M, "isHomog")) == "intvec" );
    297   // input should be graded:
    298   def w = attrib(M, "isHomog"); // grading weights?
    299   ASSUME(0, /* input must be correctly graded! */ nrows(M) == size(w) );   
    300  
    301 
    302   intvec d, p;
    303 
    304   if( size(#) > 0 ) { (d, p) = order( M, s, #[1] ); }
    305   else              { (d, p) = order( M, s       ); } 
    306 
    307   // grades & ordering permutation for N.  d[p] should be sorted!
    308  
    309   def N = grobj(module(M[p]), w);  // reorder the starting ideal/module
    310 
    311   d = d[p];
     267  module N = grobj(module(M[pivot]), w);  // reorder the starting ideal/module
    312268
    313269//  "reorder: "; grview(N);
    314270 
    315   return (N, d);
    316 }
    317 
    318 /*
    319 // only for whole resolutions, please use grorder instead!
    320 static proc ordres( list L, list # )
    321 "
    322 reorder a resolution given by the list (and optionnaly a grading for its 1st entry)
    323 "
    324 
    325   int k = 1; // "k: ", k;
    326 
    327   // check 1st syzygy property?
    328 //  if( 0 != size( module( matrix(transpose(L[k+1]))*matrix(transpose(L[k-1+1])) ) ) ){L[k];"";L[k+1];module( matrix(transpose(L[k+1]))*matrix(transpose(L[k-1+1])) );ERROR( "Exactness test failed!!!!" );}
    329 
    330 
    331   // TODO: rewrite with reorder
    332   intvec d, p, pp;
    333   module N = L[1];
    334   (d, p) = order( N, 1, # ); // grades & ordering permutation for N.  d[p] should be sorted!
    335   N = module(N[p]);  // reorder the starting ideal/module
    336   attrib( N, "isHomog", w ); // set the grading
    337   L[1] = N; // put it back into the list of modules
    338 
    339 // grview(N);
    340  kill w, N;
    341  
    342  ///////////////////////////////////
    343  k++;
    344  while( k <= size(L) )
    345  {
    346   // "k: ", k;
    347   module N = L[k];
    348  
    349   if( size(N) == 0 ) { break; } // resolution should finish with 0 module?
    350  
    351   if( typeof(attrib( N, "isHomog")) != "intvec" ) 
    352   {
    353     attrib( N, "isHomog", d); // ERROR("Non-graded input!");
    354   }
    355  
    356 //  grview(N);
    357 
    358   intvec w = attrib( N, "isHomog"); 
    359   (d, pp) = order( N, w, 1 ); // grades & ordering permutation : d[p] should be sorted!
    360 
    361   // reorder k-th syzygy (columns):
    362   module T = module(N[pp]);
    363   kill N;
    364   module N = transpose(T);
    365   kill T;
    366 
    367   // reorder k-th syzygy (rows):
    368   module T = module(N[p]);
    369   kill N;
    370   module N = transpose(T);
    371   kill T;
    372 
    373   w = intvec(w[p]); attrib( N, "isHomog", w); // corresponding ordered grading
    374 
    375   L[k] = N; //  grview(N);
    376 
    377   // check syz. property?
    378 //  if( 0 != size( module( matrix(transpose(N))*matrix(transpose(L[k-1])) ) ) ) { N; L[k-1];  module( matrix(transpose(N))*matrix(transpose(L[k-1])) ); ERROR( "Exactness test failed!!!!" );  }
    379   kill N, w;
    380   p = pp;
    381   k++;
    382  }
    383 
    384  return (list( L[1 .. (k-1)] ));
    385 }
    386 */
    387 
    388 
    389 
    390 
    391 proc grtranspose(def M, list #)
     271  return (N, intvec(gr[pivot]));
     272}
     273
     274proc grtranspose(def M)
    392275"
    393276transpose graded module/map or a chain complex?...
     
    434317//////
    435318// "a";  grview(M);
     319  ASSUME(1, grtest(M) );
    436320
    437321  // TODO: something is wrong here:
     
    439323 intvec d; module N; 
    440324
    441  if( size(#) > 0 ) { (N,d) = reorder(M, -1, #[1]); }
    442  else              { (N,d) = reorder(M, -1); }
     325 (N,d) = reorder(M, -1);
    443326
    444327 kill M; module M = grobj(transpose(N), -d);
     
    461344
    462345
    463 proc grorder(def M, list #)
     346proc grorder(def M)
    464347"
    465348reorder graded module/map or a chain complex?...
     
    498381    return (L); // ?
    499382  }
     383 
     384  ASSUME(1, grtest(M) );
    500385
    501386// "a";  grview(M);
     
    503388  intvec d; module N;
    504389
    505   if( size(#) > 0 ) { (N,d) = reorder(M, 1, #[1]); }
    506   else              { (N,d) = reorder(M, 1); } 
    507   kill M; module M = grobj(transpose(N), -d);
     390  (N,d) = reorder(M, 1); kill M;
     391 
     392  module M = grobj(transpose(N), -d); kill N,d;
    508393
    509394// "b";  grview(M);
    510395 
    511   kill N,d; module N; intvec d;
     396  module N; intvec d;
    512397  // reverse order:
    513398  (N,d) = reorder(M, -1); kill M;
     
    533418  " = Ring: ", string(basering);
    534419
    535   I = groebner(I); attrib(I, "isHomog", intvec(0));
     420  I = groebner(I); attrib(I, "isHomog", intvec(0));
     421  ASSUME(0, grtest(I));
    536422//  " = Input degrees: "; grview(I);
    537423
     
    587473/////////////////////////////////////////////////////////
    588474
    589 // ????
     475// Q@Woflram?
    590476proc grzero()
    591477"presentation of S(0)^1
     
    593479"
    594480{
    595  module Z = 0;
    596  return ( grobj(Z,intvec(0)) );
     481 return ( grobj(module([0]), intvec(0)) );
    597482}
    598483
     
    602487"
    603488{
    604   if(p==0){ return ( grzero() ); } // just ERROR ???
     489  if(p==0){ ERROR("Sorry, we don't know what is A^0!?!?"); } // grzero!?
    605490
    606491  ASSUME(0, p > 0);
     492  ASSUME(1, grtest(A) );
    607493
    608494  if(p==1){ return(A); }
     
    626512"
    627513{
     514  ASSUME(1, grtest(A) );
     515  ASSUME(1, grtest(B) );
     516 
    628517  intvec a = attrib(A, "isHomog");
    629518  intvec b = attrib(B, "isHomog");
     
    631520  int r = nrows(A);
    632521 
    633   ASSUME( 0, r == size(a) );
    634  
    635   module T; T[r] = 0; T = T, module(transpose(B));
    636   module AB = module(A), transpose(T);
    637  
    638   return(grobj(AB, c));
     522  module T = align(module(B), r); //  T;  print(T);  nrows(T); // BUG!!!!
     523  module S = module(A), T;
     524 
     525  return(grobj(S, c));
    639526}
    640527example
     
    705592}
    706593
     594
     595proc grtest(def N)
     596"test if N is a matrix/module with matching isHomog attribute (intvec)"
     597{
     598  string t = typeof(N);
     599  if( (t != "ideal") && (t != "module") && (t != "matrix") ) { return (0); };  // N should be something like a matrix
     600
     601  // N must be graded!
     602  if ( typeof(attrib(N, "isHomog")) != "intvec" ){ return (0); };
     603
     604  intvec gr = attrib(N, "isHomog"); // grading weights...
     605  if ( nrows(N) > size(gr) ) { return (0); };  // wrong number of rows?
     606
     607//  if( attrib(N, "rank") != size(gr) ){ return (0); } // wrong rank :(
     608
     609
     610//  if( !homog(N) ) { return (0); };  // N should be homogenous
     611
     612 
     613  return (1);
     614}
     615
    707616proc grisequal (def A, def B)
    708617"TODO"
    709 {
    710   return (1==1); // TODO!
     618{
     619  ASSUME(1, grtest(A) );
     620  ASSUME(1, grtest(B) );
     621 
     622  int ra = nrows(A);
     623  int rb = nrows(B);
     624 
     625  intvec wa = attrib(A, "isHomog");
     626  intvec wb = attrib(B, "isHomog");
     627 
     628  if( (ra != rb) || (ncols(A) != ncols(B)) ){ return (0); } // TODO: ???
     629  return ( (wa == wb) &&
     630           (size(module(matrix(A) - matrix(B))) == 0)    ); // TODO: ???
    711631}
    712632
     
    716636"
    717637{
    718   module Z; Z[a] = 0;
    719   Z = grobj(Z, -intvec(d:a));
    720 
    721   ASSUME(2, grisequal(Z, grpower( grshift(grzero(), -d), a ) )); // optional check
     638  module Z; Z[a] = [0];
     639  Z = grobj(Z, -intvec(d:a)); // will set the rank as well
     640
     641  ASSUME(2, grisequal(Z, grpower( grshift(grzero(), d), a ) )); // optional check
    722642  return(Z);
    723643}
    724644
    725 proc grobj(module M, intvec w)
     645proc grobj(def A, intvec w)
    726646""
    727647{
     648  module M = module(A);
     649  ASSUME(0, size(w) >= nrows(M) );
     650  attrib(M, "rank", size(w));
    728651  attrib(M, "isHomog", w);
    729   attrib(M, "rank", size(w));
     652  ASSUME(1, grtest(M) );
    730653  return (M);
    731654}
     655
     656
     657static proc align( def A, int d)
     658"analog of align kernel command for older Singular versions
     659 this is static since it should not be used by @code{align}-able (newer)
     660 Singular releases.
     661 Note that this proc does not care about any attributes (of A)
     662"
     663{
     664  module T; T[d] = 0;
     665  T = T, module(transpose(A));
     666  return( module(transpose(T)) );
     667}
Note: See TracChangeset for help on using the changeset viewer.