source: git/Singular/LIB/sheafcoh.lib

spielwiese
Last change on this file was 15379b, checked in by Hans Schoenemann <hannes@…>, 6 months ago
add sheafCoh_w to sheafcoh.lib
  • Property mode set to 100644
File size: 44.8 KB
Line 
1///////////////////////////////////////////////////////////////////////////
2version="version sheafcoh.lib 4.3.2.9 Oct_2023 "; // $Id$
3category="Commutative Algebra";
4info="
5LIBRARY:  sheafcoh.lib   Procedures for Computing Sheaf Cohomology
6AUTHORS:  Wolfram Decker, decker@mathematik.uni-kl.de
7          Christoph Lossen,  lossen@mathematik.uni-kl.de
8          Gerhard Pfister,  pfister@mathematik.uni-kl.de
9          Oleksandr Motsak, U@D, where U={motsak}, D={mathematik.uni-kl.de}
10
11PROCEDURES:
12 truncate(phi,d);        truncation of coker(phi) at d
13 truncateFast(phi,d);    truncation of coker(phi) at d (fast+ experimental)
14 CM_regularity(M);       Castelnuovo-Mumford regularity of coker(M)
15 sheafCohBGG(M,l,h);     cohomology of sheaf associated to coker(M)
16 sheafCohBGGregul(M,l,h,r); cohomology of sheaf associated to coker(M)
17                          with given regularity
18 sheafCohBGGregul_w(M,l,h,r,w); cohomology with given module weights
19 sheafCohBGG2(M,l,h);    cohomology of sheaf associated to coker(M), experimental version
20 sheafCoh(M,l,h);        cohomology of sheaf associated to coker(M)
21 sheafCoh_w(M,l,h);      cohomology of coker(M) with given module weights
22 dimH(i,M,d);            compute h^i(F(d)), F sheaf associated to coker(M)
23 dimGradedPart()
24
25 displayCohom(B,l,h,n);  display intmat as Betti diagram (with zero rows)
26
27KEYWORDS: sheaf cohomology
28";
29
30///////////////////////////////////////////////////////////////////////////////
31LIB "matrix.lib";
32LIB "nctools.lib";
33LIB "homolog.lib";
34
35
36///////////////////////////////////////////////////////////////////////////////
37static proc jacobM(matrix M)
38{
39   int n=nvars(basering);
40   matrix B=transpose(diff(M,var(1)));
41   int i;
42   for(i=2;i<=n;i++)
43   {
44     B=concat(B,transpose(diff(M,var(i))));
45   }
46   return(transpose(B));
47}
48
49
50///////////////////////////////////////////////////////////////////////////////
51/**
52  let M = { w_1, ..., w_k }, k = size(M) == ncols(M), n = nvars(currRing).
53  assuming that nrows(M) <= m*n;
54  computes transpose(M) * transpose( var(1) I_m | ... | var(n) I_m ) :== transpose(module{f_1, ... f_k}),
55  where f_i = \sum_{j=1}^{m} (w_i, v_j) gen(j),  (w_i, v_j) is a `scalar` multiplication.
56  that is, if w_i = (a^1_1, ... a^1_m) | (a^2_1, ..., a^2_m) | ... | (a^n_1, ..., a^n_m) then
57
58  (a^1_1, ... a^1_m) | (a^2_1, ..., a^2_m) | ... | (a^n_1, ..., a^n_m)
59*  var_1  ... var_1  |  var_2  ...  var_2  | ... |  var_n  ...  var(n)
60*  gen_1  ... gen_m  |  gen_1  ...  gen_m  | ... |  gen_1  ...  gen_m
61+ =>
62  f_i =
63
64   a^1_1 * var(1) * gen(1) + ... + a^1_m * var(1) * gen(m) +
65   a^2_1 * var(2) * gen(1) + ... + a^2_m * var(2) * gen(m) +
66                             ...
67   a^n_1 * var(n) * gen(1) + ... + a^n_m * var(n) * gen(m);
68
69   NOTE: for every f_i we run only ONCE along w_i saving partial sums into a temporary array of polys of size m
70
71*/
72static proc TensorModuleMult(int m, module M)
73{
74  return( system("tensorModuleMult", m, M) ); // trick!
75
76  int n = nvars(basering);
77  int k = ncols(M);
78
79  int g, cc, vv;
80
81  poly h;
82
83  module Temp; // = {f_1, ..., f_k }
84
85  intvec exp;
86  vector pTempSum, w;
87
88  for( int i = k; i > 0; i-- ) // for every w \in M
89  {
90    pTempSum[m] = 0;
91    w = M[i];
92
93    while(w != 0) // for each term of w...
94    {
95      exp = leadexp(w);
96      g = exp[n+1]; // module component!
97      h = w[g];
98
99      w = w - h * gen(g);
100
101      cc = g % m;
102
103      if( cc == 0)
104      {
105        cc = m;
106      }
107
108      vv = 1 + (g - cc) / m;
109
110      pTempSum = pTempSum + h * var(vv) * gen(cc);
111    }
112
113    Temp[i] = pTempSum;
114  }
115
116  Temp = transpose(Temp);
117
118  return(Temp);
119}
120
121///////////////////////////////////////////////////////////////////////////////
122proc truncate(module phi, int d)
123"USAGE:   truncate(M,d);  M module, d int
124ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
125         vector as an attribute
126RETURN:  module
127NOTE:    Output is a presentation matrix for the truncation of coker(M)
128         at degree d.
129EXAMPLE: example truncate; shows an example
130KEYWORDS: truncated module
131"
132{
133  if ( typeof(attrib(phi,"isHomog"))=="string" )
134  {
135    if (size(phi)==0)
136    {
137      // assign weights 0 to generators of R^n (n=nrows(phi))
138      intvec v;
139      v[nrows(phi)]=0;
140      attrib(phi,"isHomog",v);
141    }
142    else
143    {
144      ERROR("No admissible degree vector assigned");
145    }
146  }
147  else
148  {
149   intvec v=attrib(phi,"isHomog");
150  }
151  int i,m,dummy;
152  int s = nrows(phi);
153  module L; // TOO BIG!!!
154  for (i=1; i<=s; i++)
155  {
156    if (d>v[i])
157    {
158      L = L+maxideal(d-v[i])*gen(i);
159    }
160    else
161    {
162      L = L+gen(i);
163    }
164  }
165  L = modulo(L,phi);
166  L = minbase(prune(L));
167  if (size(L)==0) {return(L);}
168
169  // it only remains to set the degrees for L:
170  // ------------------------------------------
171  m = v[1];
172  for(i=2; i<=size(v); i++) {  if(v[i]<m) { m = v[i]; } }
173  dummy = homog(L);
174  intvec vv = attrib(L,"isHomog");
175  if (d>m) { vv = vv+d; }
176  else     { vv = vv+m; }
177  attrib(L,"isHomog",vv);
178  return(L);
179}
180example
181{"EXAMPLE:";
182   echo = 2;
183   ring R=0,(x,y,z),dp;
184   module M=maxideal(3);
185   homog(M);
186   // compute presentation matrix for truncated module (R/<x,y,z>^3)_(>=2)
187   module M2=truncate(M,2);
188   print(M2);
189   dimGradedPart(M2,1);
190   dimGradedPart(M2,2);
191   // this should coincide with:
192   dimGradedPart(M,2);
193   // shift grading by 1:
194   intvec v=1;
195   attrib(M,"isHomog",v);
196   M2=truncate(M,2);
197   print(M2);
198   dimGradedPart(M2,3);
199}
200
201///////////////////////////////////////////////////////////////////////////////
202
203proc truncateFast(module M, int d)
204"USAGE:   truncateFast(M,d);  M module, d int
205ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
206         vector as an attribute 'isHomog'
207RETURN:  module
208NOTE:    Output is a presentation matrix for the truncation of coker(M)
209         at d.
210         Fast + experimental version. M should be a SB!
211DISPLAY: If @code{printlevel}>=1, step-by step timings will be printed.
212         If @code{printlevel}>=2 we add progress debug messages
213         if @code{printlevel}>=3, even all intermediate results...
214EXAMPLE: example truncateFast; shows an example
215KEYWORDS: truncated module
216"
217{
218//  int PL = printlevel + 1;
219  int PL = printlevel - voice + 2;
220
221  dbprint(PL-1, "// truncateFast(M: "+ string(nrows(M)) + " x " + string(ncols(M)) +", " + string(d) + "):");
222  dbprint(PL-2, M);
223
224  intvec save = option(get);
225  if( PL >= 2 )
226  {
227    option(prot);
228    option(mem);
229  }
230
231  int tTruncateBegin=timer;
232
233  if (attrib(M,"isSB")!=1)
234  {
235    ERROR("M must be a standard basis!");
236  }
237
238  dbprint(PL-1, "// M is a SB! ");
239
240  if ( typeof(attrib(M,"isHomog"))=="string" )
241  {
242    if (size(M)==0)
243    {
244      // assign weights 0 to generators of R^n (n=nrows(M))
245      intvec v;
246      v[nrows(M)]=0;
247      attrib(M,"isHomog",v);
248    }
249    else
250    {
251      ERROR("No admissible degree vector assigned");
252    }
253  }
254  else
255  {
256   intvec v=attrib(M,"isHomog");
257  }
258
259  dbprint(PL-1, "// weighting(M): ["+ string(v) + "]");
260
261  int i,m,dummy;
262  int s = nrows(M);
263
264  int tKBaseBegin = timer;
265  module L = kbase(M, d); // TODO: check whether this is always correct!?!
266
267  dbprint(PL-1, "// L = kbase(M,d): "+string(nrows(L)) + " x " + string(ncols(L)) +"");
268  dbprint(PL-2, L);
269  dbprint(PL-1, "// weighting(L): ["+ string(attrib(L, "isHomog")) + "]");
270
271  int tModuloBegin = timer;
272  L = modulo(L,M);
273
274  dbprint(PL-1, "// L = modulo(L,M): "+string(nrows(L)) + " x " + string(ncols(L)) +"");
275  dbprint(PL-2, L);
276  dbprint(PL-1, "// weighting(L): ["+ string(attrib(L, "isHomog")) + "]");
277
278  int tPruneBegin = timer;
279  L = prune(L);
280
281  dbprint(PL-1, "// L = prune(L): "+string(nrows(L)) + " x " + string(ncols(L)) +"");
282  dbprint(PL-2, L);
283  dbprint(PL-1, "// weighting(L): ["+ string(attrib(L, "isHomog")) + "]");
284
285  int tPruneEnd = timer;
286  L = minbase(L);
287  int tMinBaseEnd = timer;
288
289  dbprint(PL-1, "// L = minbase(L): "+string(nrows(L)) + " x " + string(ncols(L)) +"");
290  dbprint(PL-2, L);
291  dbprint(PL-1, "// weighting(L): ["+ string(attrib(L, "isHomog")) + "]");
292
293  if (size(L)!=0)
294  {
295    // it only remains to set the degrees for L:
296    // ------------------------------------------
297    m = v[1];
298    for(i=2; i<=size(v); i++) {  if(v[i]<m) { m = v[i]; } }
299    dummy = homog(L);
300    intvec vv = attrib(L,"isHomog");
301    if (d>m) { vv = vv+d; }
302    else     { vv = vv+m; }
303    attrib(L,"isHomog",vv);
304  }
305
306  int tTruncateEnd=timer;
307
308  dbprint(PL-1, "// corrected weighting(L): ["+ string(attrib(L, "isHomog")) + "]");
309
310  if(PL > 0)
311  {
312  "
313  -------------- TIMINGS --------------
314  Trunc        Time: ", tTruncateEnd - tTruncateBegin, "
315    :: Before .Time: ", tKBaseBegin - tTruncateBegin, "
316    :: kBase   Time: ", tModuloBegin - tKBaseBegin, "
317    :: Modulo  Time: ", tPruneBegin - tModuloBegin, "
318    :: Prune   Time: ", tPruneEnd - tPruneBegin, "
319    :: Minbase Time: ", tMinBaseEnd - tPruneEnd, "
320    :: After  .Time: ", tTruncateEnd - tMinBaseEnd;
321  }
322
323  option(set, save);
324  return(L);
325}
326example
327{"EXAMPLE:";
328  echo = 2;
329  ring R=0,(x,y,z,u,v),dp;
330  module M=maxideal(3);
331  homog(M);
332  // compute presentation matrix for truncated module (R/<x,y,z,u>^3)_(>=2)
333  int t=timer;
334  module M2t=truncate(M,2);
335  t = timer - t;
336  "// Simple truncate: ", t;
337  t=timer;
338  module M2=truncateFast(std(M),2);
339  t = timer - t;
340  "// Fast truncate: ", t;
341  print(M2);
342  "// Check: M2t == M2?: ", size(NF(M2, std(M2t))) + size(NF(M2t, std(M2)));
343
344  dimGradedPart(M2,1);
345  dimGradedPart(M2,2);
346  // this should coincide with:
347  dimGradedPart(M,2);
348  // shift grading by 1:
349  intvec v=1;
350  attrib(M,"isHomog",v);
351  t=timer;
352  M2t=truncate(M,2);
353  t = timer - t;
354  "// Simple truncate: ", t;
355  t=timer;
356  M2=truncateFast(std(M),2);
357  t = timer - t;
358  "// Fast truncate: ", t;
359  print(M2);
360  "// Check: M2t == M2?: ", size(NF(M2, std(M2t))) + size(NF(M2t, std(M2))); //?
361  dimGradedPart(M2,3);
362}
363
364///////////////////////////////////////////////////////////////////////////////
365
366proc dimGradedPart(module phi, int d)
367"USAGE:   dimGradedPart(M,d);  M module, d int
368ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
369         vector as an attribute
370RETURN:  int
371NOTE:    Output is the vector space dimension of the graded part of degree d
372         of coker(M).
373EXAMPLE: example dimGradedPart; shows an example
374KEYWORDS: graded module, graded piece
375"
376{
377  if ( typeof(attrib(phi,"isHomog"))=="string" )
378  {
379    if (size(phi)==0)
380    {
381      // assign weights 0 to generators of R^n (n=nrows(phi))
382      intvec v;
383      v[nrows(phi)]=0;
384    }
385    else { ERROR("No admissible degree vector assigned"); }
386  }
387  else
388  {
389    intvec v=attrib(phi,"isHomog");
390  }
391  int s = nrows(phi);
392  int i,m,dummy;
393  module L,LL;
394  for (i=1; i<=s; i++)
395  {
396    if (d>v[i])
397    {
398      L = L+maxideal(d-v[i])*gen(i);
399      LL = LL+maxideal(d+1-v[i])*gen(i);
400    }
401    else
402    {
403      L = L+gen(i);
404      if (d==v[i])
405      {
406        LL = LL+maxideal(1)*gen(i);
407      }
408      else
409      {
410        LL = LL+gen(i);
411      }
412    }
413  }
414  LL=LL,phi;
415  L = modulo(L,LL);
416  L = std(prune(L));
417  if (size(L)==0) {return(0);}
418  return(vdim(L));
419}
420example
421{"EXAMPLE:";
422   echo = 2;
423   ring R=0,(x,y,z),dp;
424   module M=maxideal(3);
425   // assign compatible weight vector (here: 0)
426   homog(M);
427   // compute dimension of graded pieces of R/<x,y,z>^3 :
428   dimGradedPart(M,0);
429   dimGradedPart(M,1);
430   dimGradedPart(M,2);
431   dimGradedPart(M,3);
432   // shift grading:
433   attrib(M,"isHomog",intvec(2));
434   dimGradedPart(M,2);
435}
436
437///////////////////////////////////////////////////////////////////////////////
438
439proc CM_regularity (module M)
440"USAGE:   CM_regularity(M);    M module
441ASSUME:   @code{M} is graded, and it comes assigned with an admissible degree
442         vector as an attribute
443RETURN:  integer, the Castelnuovo-Mumford regularity of coker(M)
444NOTE:    procedure calls mres
445EXAMPLE: example CM_regularity; shows an example
446KEYWORDS: Castelnuovo-Mumford regularity
447"
448{
449  if ( typeof(attrib(M,"isHomog"))=="string" )
450  {
451    if (size(M)==0)
452    {
453      // assign weights 0 to generators of R^n (n=nrows(M))
454      intvec v;
455      v[nrows(M)]=0;
456      attrib(M,"isHomog",v);
457    }
458    else
459    {
460      ERROR("No admissible degree vector assigned");
461    }
462  }
463
464  if( attrib(CM_regularity,"Algorithm") == "minres_res" )
465  {
466    def L = minres( res(M,0) ); // let's try it out!
467  }
468  else
469  {
470    def L = mres(M,0);
471  }
472
473  intmat BeL = betti(L);
474  int r = nrows(module(matrix(BeL)));  // last non-zero row
475  if (typeof(attrib(BeL,"rowShift"))!="string")
476  {
477    int shift = attrib(BeL,"rowShift");
478  }
479  return(r+shift-1);
480}
481example
482{"EXAMPLE:";
483  echo = 2;
484  ring R=0,(x,y,z,u),dp;
485  resolution T1=mres(maxideal(1),0);
486  module M=T1[3];
487  intvec v=2,2,2,2,2,2;
488  attrib(M,"isHomog",v);
489  CM_regularity(M);
490}
491
492///////////////////////////////////////////////////////////////////////////////
493proc sheafCohBGG(module M,int l,int h)
494"USAGE:   sheafCohBGG(M,l,h);    M module, l,h int
495ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
496         vector as an attribute, @code{h>=l}, and the basering has @code{n+1}
497         variables.
498RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
499         associated to coker(M). The range of twists is determined by @code{l},
500         @code{h}.
501DISPLAY: The intmat is displayed in a diagram of the following form:
502         with @code{displayCohom(A,l,h,nvars(r)-1);}@*
503  @format
504                l            l+1                      h
505  ----------------------------------------------------------
506      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
507           ...............................................
508      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
509      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
510  ----------------------------------------------------------
511    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
512  @end format
513         A @code{'-'} in the diagram refers to a zero entry; a @code{'*'}
514         refers to a negative entry (= dimension not yet determined).
515         refers to a not computed dimension. @*
516NOTE:    This procedure is based on the Bernstein-Gel'fand-Gel'fand
517         correspondence and on Tate resolution ( see [Eisenbud, Floystad,
518         Schreyer: Sheaf cohomology and free resolutions over exterior
519         algebras, Trans AMS 355 (2003)] ).@*
520         @code{sheafCohBGG(M,l,h)} does not compute all values in the above
521         table. To determine all values of @code{h^i(F(d))}, @code{d=l..h},
522         use @code{sheafCohBGG(M,l-n,h+n)}.
523SEE ALSO: sheafCoh, dimH, displayCohom
524EXAMPLE: example sheafCohBGG; shows an example
525"
526{
527  int i,j,k,row,col;
528  if( typeof(attrib(M,"isHomog"))!="intvec" )
529  {
530     if (size(M)==0) { attrib(M,"isHomog",0); }
531     else { ERROR("No admissible degree vector assigned"); }
532  }
533  int n=nvars(basering)-1;
534  int ell=l+n;
535  def R=basering;
536  int reg = CM_regularity(M);
537  int bound=max(reg+1,h-1);
538  module MT=truncate(M,bound);
539  int m=nrows(MT);
540  MT=transpose(jacobM(MT));
541  MT=syz(MT);
542  matrix ML[n+1][1]=maxideal(1);
543  matrix S=transpose(outer(ML,unitmat(m)));
544  matrix SS=transpose(S*MT);
545  //--- to the exterior algebra
546  def AR = Exterior();
547  setring AR;
548  intvec saveopt=option(get);
549  option(redSB);
550  option(redTail);
551  module EM=imap(R,SS);
552  intvec w;
553  //--- here we are with our matrix
554  int bound1=max(1,bound-ell+1);
555  for (i=1; i<=nrows(EM); i++)
556  {
557     w[i]=-bound-1;
558  }
559  attrib(EM,"isHomog",w);
560  resolution RE=mres(EM,bound1);
561  intmat Betti=betti(RE);
562  k=ncols(Betti);
563  row=nrows(Betti);
564  int shift=attrib(Betti,"rowShift")+(k+ell-1);
565  intmat newBetti[n+1][h-l+1];
566  for (j=1; j<=row; j++)
567  {
568    for (i=l; i<=h; i++)
569    {
570      if (((n+2-shift-j)>0)&&((n+2-shift-j)<=(n+1))
571      && ((i-l+1)>0)&&((i-l+1)<=(h-l+1)))
572      {
573        if ((k+1-j-i+ell-shift>0) and (j+i-ell+shift>=1))
574        {
575          newBetti[n+2-shift-j,i-l+1]=Betti[j,k+1-j-i+ell-shift];
576        }
577        else
578        {
579          newBetti[n+2-shift-j,i-l+1]=-1;
580        }
581      }
582    }
583  }
584  for (j=2; j<=n+1; j++)
585  {
586    for (i=1; i<j; i++)
587    {
588      newBetti[j,i]=-1;
589    }
590  }
591  int d=k-h+ell-1;
592  for (j=1; j<=n; j++)
593  {
594    for (i=h-l+1; i>=k+j; i--)
595    {
596      newBetti[j,i]=-1;
597    }
598  }
599  option(set,saveopt);
600  setring R;
601  return(newBetti);
602}
603example
604{"EXAMPLE:";
605  echo = 2;
606  // cohomology of structure sheaf on P^4:
607  //-------------------------------------------
608  ring r=0,x(1..5),dp;
609  module M=0;
610  intmat A=sheafCohBGG(M,-9,4);
611  A;
612  displayCohom(A,-9,4,nvars(r)-1);
613  // cohomology of cotangential bundle on P^3:
614  //-------------------------------------------
615  ring R=0,(x,y,z,u),dp;
616  resolution T1=mres(maxideal(1),0);
617  module M=T1[3];
618  intvec v=2,2,2,2,2,2;
619  attrib(M,"isHomog",v);
620  intmat B=sheafCohBGG(M,-8,4);
621  B;
622  displayCohom(B,-8,4,nvars(R)-1);
623}
624proc sheafCohBGGregul(module M,int l,int h, int reg)
625"USAGE:   sheafCohBGGregul(M,l,h);    M module, l,h int, reg int
626ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
627         vector as an attribute, @code{h>=l}, and the basering has @code{n+1}
628         variables.
629RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
630         associated to coker(M). The range of twists is determined by @code{l},
631         @code{h}.
632NOTE:    This procedure is based on the Bernstein-Gel'fand-Gel'fand
633         correspondence and on Tate resolution ( see [Eisenbud, Floystad,
634         Schreyer: Sheaf cohomology and free resolutions over exterior
635         algebras, Trans AMS 355 (2003)] ).@*
636         @code{sheafCohBGG(M,l,h)} does not compute all values in the above
637         table. To determine all values of @code{h^i(F(d))}, @code{d=l..h},
638         use @code{sheafCohBGG(M,l-n,h+n)}.
639SEE ALSO: sheafCoh, dimH, displayCohom
640EXAMPLE: example sheafCohBGGregul; shows an example
641"
642{
643  int i,j,k,row,col;
644  if( typeof(attrib(M,"isHomog"))!="intvec" )
645  {
646     if (size(M)==0) { attrib(M,"isHomog",0); }
647     else { ERROR("No admissible degree vector assigned"); }
648  }
649  int n=nvars(basering)-1;
650  int ell=l+n;
651  def R=basering;
652  int bound=max(reg+1,h-1);
653  module MT=truncate(M,bound);
654  int m=nrows(MT);
655  MT=transpose(jacobM(MT));
656  MT=syz(MT);
657  matrix ML[n+1][1]=maxideal(1);
658  matrix S=transpose(outer(ML,unitmat(m)));
659  matrix SS=transpose(S*MT);
660  //--- to the exterior algebra
661  def AR = Exterior();
662  setring AR;
663  intvec saveopt=option(get);
664  option(redSB);
665  option(redTail);
666  module EM=imap(R,SS);
667  intvec w;
668  //--- here we are with our matrix
669  int bound1=max(1,bound-ell+1);
670  for (i=1; i<=nrows(EM); i++)
671  {
672     w[i]=-bound-1;
673  }
674  attrib(EM,"isHomog",w);
675  resolution RE=mres(EM,bound1);
676  intmat Betti=betti(RE);
677  k=ncols(Betti);
678  row=nrows(Betti);
679  int shift=attrib(Betti,"rowShift")+(k+ell-1);
680  intmat newBetti[n+1][h-l+1];
681  for (j=1; j<=row; j++)
682  {
683    for (i=l; i<=h; i++)
684    {
685      if ((k+1-j-i+ell-shift>0) and (j+i-ell+shift>=1))
686      {
687        newBetti[n+2-shift-j,i-l+1]=Betti[j,k+1-j-i+ell-shift];
688      }
689      else { newBetti[n+2-shift-j,i-l+1]=-1; }
690    }
691  }
692  for (j=2; j<=n+1; j++)
693  {
694    for (i=1; i<j; i++)
695    {
696      newBetti[j,i]=-1;
697    }
698  }
699  int d=k-h+ell-1;
700  for (j=1; j<=n; j++)
701  {
702    for (i=h-l+1; i>=k+j; i--)
703    {
704      newBetti[j,i]=-1;
705    }
706  }
707  option(set,saveopt);
708  setring R;
709  return(newBetti);
710}
711example
712{"EXAMPLE:";
713  echo = 2;
714  // cohomology of structure sheaf on P^4:
715  //-------------------------------------------
716  ring r=0,x(1..5),dp;
717  module M=0;
718  def A=sheafCohBGGregul(M,-9,4,CM_regularity(M));
719  A;
720  // cohomology of cotangential bundle on P^3:
721  //-------------------------------------------
722  ring R=0,(x,y,z,u),dp;
723  resolution T1=mres(maxideal(1),0);
724  module M=T1[3];
725  intvec v=2,2,2,2,2,2;
726  attrib(M,"isHomog",v);
727  def B=sheafCohBGGregul(M,-8,4,CM_regularity(M));
728  B;
729}
730
731proc sheafCohBGGregul_w(module M,int l,int h,int regul, intvec w)
732"USAGE:   sheafCohBGGregul_w(M,l,h,w);    M module, l,h int, reg int, w intvec
733ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
734         vector w, @code{h>=l}, and the basering has @code{n+1}
735         variables.
736RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
737         associated to coker(M). The range of twists is determined by @code{l},
738         @code{h}.
739NOTE:    This procedure is based on the Bernstein-Gel'fand-Gel'fand
740         correspondence and on Tate resolution ( see [Eisenbud, Floystad,
741         Schreyer: Sheaf cohomology and free resolutions over exterior
742         algebras, Trans AMS 355 (2003)] ).@*
743         @code{sheafCohBGG(M,l,h)} does not compute all values in the above
744         table. To determine all values of @code{h^i(F(d))}, @code{d=l..h},
745         use @code{sheafCohBGG(M,l-n,h+n)}.
746SEE ALSO: sheafCoh, dimH, displayCohom
747EXAMPLE: example sheafCohBGGregul_w; shows an example
748"
749{
750  attrib(M,"isHomog",w);
751  return(sheafCohBGGregul(M,l,h,regul));
752}
753example
754{"EXAMPLE:";
755  echo = 2;
756  // cohomology of cotangential bundle on P^3:
757  //-------------------------------------------
758  ring R=0,(x,y,z,u),dp;
759  resolution T1=mres(maxideal(1),0);
760  module M=T1[3];
761  intvec v=2,2,2,2,2,2;
762  def B=sheafCohBGGregul_w(M,-8,4,CM_regularity(M),v);
763  B;
764}
765
766
767///////////////////////////////////////////////////////////////////////////////
768static proc showResult( def R, int l, int h )
769{
770  int PL = 1; // printlevel - voice + 2;
771// int PL = printlevel + 1;
772
773  intmat Betti;
774  if(typeof(R)=="resolution")
775  {
776    Betti = betti(R);
777  }
778  else
779  {
780    if(typeof(R)!="intmat")
781    {
782      ERROR("Wrong input!!!");
783    }
784
785    Betti = R;
786  }
787
788  int n=nvars(basering)-1;
789  int ell = l + n;
790
791  int k     = ncols(Betti);
792  int row   = nrows(Betti);
793  int shift = attrib(Betti,"rowShift") + (k + ell - 1);
794
795  int iWTH = h-l+1;
796
797  int d = k - h + ell - 1;
798
799  if( PL > 1 )
800  {
801    "// l: ", l;
802    "// h: ", h;
803    "// n: ", n;
804    "// ell: ", ell;
805    "// k: ", k;
806    "// row: ", row;
807    "// shift: ", shift;
808    "// iWTH: ", iWTH;
809    "// d: ", d;
810  }
811
812  intmat newBetti[ n + 1 ][ iWTH ];
813  int i, j;
814
815  for (j=1; j<=row; j++)
816  {
817    for (i=l; i<=h; i++)
818    {
819      if( (n+2-shift-j)>0 )
820      {
821        if (  (k+1-j-i+ell-shift>0) and (j+i-ell+shift>=1))
822        {
823          newBetti[n+2-shift-j,i-l+1]=Betti[j,k+1-j-i+ell-shift];
824        }
825        else { newBetti[n+2-shift-j,i-l+1]=-1; }
826      }
827    }
828  }
829
830  for (j=2; j<=n+1; j++)
831  {
832    for (i=1; i<min(j, iWTH); i++)
833    {
834      newBetti[j,i]= -1;
835    }
836  }
837
838  for (j=1; j<=n; j++)
839  {
840    for (i=iWTH; i>=k+j; i--)
841    {
842      newBetti[j,i]=0; // -1;
843    }
844  }
845
846  if( PL > 0 )
847  {
848    "Cohomology table:";
849    displayCohom(newBetti, l, h, n);
850  }
851  return(newBetti);
852}
853///////////////////////////////////////////////////////////////////////////////
854
855
856
857///////////////////////////////////////////////////////////////////////////////
858proc sheafCohBGG2(module M,int l,int h)
859"USAGE:   sheafCohBGG2(M,l,h);    M module, l,h int
860ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
861         vector as an attribute, @code{h>=l}, and the basering has @code{n+1}
862         variables.
863RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
864         associated to coker(M). The range of twists is determined by @code{l},
865         @code{h}.
866DISPLAY: The intmat is displayed in a diagram of the following form:
867         with @code{displayCohom(A,l,h,nvars(r)-1);}@*
868  @format
869                l            l+1                      h
870  ----------------------------------------------------------
871      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
872           ...............................................
873      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
874      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
875  ----------------------------------------------------------
876    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
877  @end format
878         A @code{'-'} in the diagram refers to a zero entry; a @code{'*'}
879         refers to a negative entry (= dimension not yet determined).
880         refers to a not computed dimension. @*
881         If @code{printlevel}>=1, step-by step timings will be printed.
882         If @code{printlevel}>=2 we add progress debug messages
883         if @code{printlevel}>=3, even all intermediate results...
884NOTE:    This procedure is based on the Bernstein-Gel'fand-Gel'fand
885         correspondence and on Tate resolution ( see [Eisenbud, Floystad,
886         Schreyer: Sheaf cohomology and free resolutions over exterior
887         algebras, Trans AMS 355 (2003)] ).@*
888         @code{sheafCohBGG(M,l,h)} does not compute all values in the above
889         table. To determine all values of @code{h^i(F(d))}, @code{d=l..h},
890         use @code{sheafCohBGG(M,l-n,h+n)}.
891         Experimental version. Should require less memory.
892SEE ALSO: sheafCohBGG, displayCohom
893EXAMPLE: example sheafCohBGG2; shows an example
894"
895{
896  int PL = printlevel - voice + 2;
897//  int PL = printlevel;
898
899  dbprint(PL-1, "// sheafCohBGG2(M: "+ string(nrows(M)) + " x " + string(ncols(M)) +", " + string(l) + ", " + string(h) + "):");
900  dbprint(PL-2, M);
901
902  intvec save = option(get);
903
904  if( PL >= 2 )
905  {
906    option(prot);
907    option(mem);
908  }
909
910  def isCoker = attrib(M, "isCoker");
911  if( typeof(isCoker) == "int" )
912  {
913    if( isCoker > 0 )
914    {
915      dbprint(PL-1, "We are going to assume that M is given by coker matrix (that is, M is not a submodule presentation!)");
916    }
917  }
918
919  int i,j,k,row,col;
920
921  if( typeof(attrib(M,"isHomog"))!="intvec" )
922  {
923     if (size(M)==0) { attrib(M,"isHomog",0); }
924     else { ERROR("No admissible degree vector assigned"); }
925  }
926
927  dbprint(PL-1, "// weighting(M): ["+ string(attrib(M, "isHomog")) + "]");
928
929  option(redSB); option(redTail);
930
931  def R=basering;
932
933  int n = nvars(R) - 1;
934  int ell = l + n;
935
936
937/////////////////////////////////////////////////////////////////////////////
938// computations
939
940  int tBegin=timer;
941  int reg   = CM_regularity(M);
942  int tCMEnd = timer;
943
944  dbprint(PL-1, "// CM_reg(M): "+ string(reg));
945
946  int bound = max(reg + 1, h - 1);
947
948  dbprint(PL-1, "// bound: "+ string(bound));
949
950  ///////////////////////////////////////////////////////////////
951  int tSTDBegin=timer;
952  M = std(M); // for kbase! // NOTE: this should be after CM_regularity, since otherwise CM_regularity computes JUST TOOOOOOO LONG sometimes (see Reg_Hard examples!)
953  int tSTDEnd = timer;
954
955  dbprint(PL-1, "// M = std(M: "+string(nrows(M)) + " x " + string(ncols(M))  + ")");
956  dbprint(PL-2, M);
957  dbprint(PL-1, "// weighting(M): ["+ string(attrib(M, "isHomog")) + "]");
958
959
960  printlevel = printlevel + 1;
961  int tTruncateBegin=timer;
962  module MT = truncateFast(M, bound);
963  int tTruncateEnd=timer;
964  printlevel = printlevel - 1;
965
966  dbprint(PL-1, "// MT = truncateFast(M: "+string(nrows(MT)) + " x " + string(ncols(MT)) +", " + string(bound) + ")");
967  dbprint(PL-2, MT);
968  dbprint(PL-1, "// weighting(MT): ["+ string(attrib(MT, "isHomog")) + "]");
969
970  int m=nrows(MT);
971
972  ///////////////////////////////////////////////////////////////
973  int tTransposeJacobBegin=timer;
974  MT = jacob(MT); // ! :(
975  int tTransposeJacobEnd=timer;
976
977  dbprint(PL-1, "// MT = jacob(MT: "+string(nrows(MT)) + " x " + string(ncols(MT))  + ")");
978  dbprint(PL-2, MT);
979  dbprint(PL-1, "// weighting(MT): ["+ string(attrib(MT, "isHomog")) + "]");
980
981  int tSyzBegin=timer;
982  MT = syz(MT);
983  int tSyzEnd=timer;
984
985  dbprint(PL-1, "// MT = syz(MT: "+string(nrows(MT)) + " x " + string(ncols(MT))  + ")");
986  dbprint(PL-2, MT);
987  dbprint(PL-1, "// weighting(MT): ["+ string(attrib(MT, "isHomog")) + "]");
988
989  int tMatrixOppBegin=timer;
990  module SS = TensorModuleMult(m, MT);
991  int tMatrixOppEnd=timer;
992
993  dbprint(PL-1, "// SS = TensorModuleMult("+ string(m)+ ", MT: "+string(nrows(MT)) + " x " + string(ncols(MT))  + ")");
994  dbprint(PL-2, SS);
995  dbprint(PL-1, "// weighting(SS): ["+ string(attrib(SS, "isHomog")) + "]");
996
997  //--- to the exterior algebra
998  def AR = Exterior(); setring AR;
999
1000  dbprint(PL-1, "// Test: var(1) * var(1): "+ string(var(1) * var(1)));
1001
1002  int maxbound = max(1, bound - ell + 1);
1003//  int maxbound = max(1, bound - l + 1); // As In M2!!!
1004
1005  dbprint(PL-1, "// maxbound: "+ string(maxbound));
1006
1007  //--- here we are with our matrix
1008  module EM=imap(R,SS);
1009  intvec w;
1010  for (i=1; i<=nrows(EM); i++)
1011  {
1012     w[i]=-bound-1;
1013  }
1014
1015  attrib(EM,"isHomog",w);
1016
1017  ///////////////////////////////////////////////////////////////
1018
1019  dbprint(PL-1, "// EM: "+string(nrows(EM)) + " x " + string(ncols(EM))  + ")");
1020  dbprint(PL-2, EM);
1021  dbprint(PL-1, "// weighting(EM): ["+ string(attrib(EM, "isHomog")) + "]");
1022
1023  int tResulutionBegin=timer;
1024  resolution RE = nres(EM, maxbound); // TODO: Plural computes one too many syzygies...?!
1025  int tMinResBegin=timer;
1026  RE = minres(RE);
1027  int tBettiBegin=timer;
1028  intmat Betti = betti(RE); // betti(RE, 1);?
1029  int tResulutionEnd=timer;
1030
1031  int tEnd = tResulutionEnd;
1032
1033  if( PL > 0 )
1034  {
1035    //    list L = RE; // TODO: size(L/RE) is wrong!
1036    "
1037        ----      RESULTS  ----
1038        Tate Resolution:
1039    ";
1040    RE;
1041    "Betti numbers for Tate resolution (diagonal cohomology table):";
1042    print(Betti, "betti"); // Diagonal form!
1043  }
1044
1045//  printlevel = printlevel + 1;
1046  Betti = showResult(Betti, l, h ); // Show usual form of cohomology table
1047//  printlevel = printlevel - 1;
1048
1049  if(PL > 0)
1050  {
1051  "
1052      ----      TIMINGS     -------
1053      Trunc      Time: ", tTruncateEnd - tTruncateBegin, "
1054      Reg        Time: ", tCMEnd - tBegin, "
1055      kStd       Time: ", tSTDEnd - tSTDBegin, "
1056      Jacob      Time: ", tTransposeJacobEnd - tTransposeJacobBegin, "
1057      Syz        Time: ", tSyzEnd - tSyzBegin, "
1058      Mat        Time: ", tMatrixOppEnd - tMatrixOppBegin, "
1059      ------------------------------
1060      Res        Time: ", tResulutionEnd - tResulutionBegin, "
1061      :: NRes    Time: ", tMinResBegin - tResulutionBegin, "
1062      :: MinRes .Time: ", tBettiBegin - tMinResBegin, "
1063      :: Betti  .Time: ", tResulutionEnd - tBettiBegin, "
1064      ---------------------------------------------------------
1065      Total Time: ", tEnd - tBegin, "
1066      ---------------------------------------------------------
1067      ";
1068  }
1069
1070  setring R;
1071
1072  option(set, save);
1073
1074  return(Betti);
1075}
1076example
1077{"EXAMPLE:";
1078  echo = 2;
1079  int pl = printlevel;
1080  int l,h, t;
1081
1082  //-------------------------------------------
1083  // cohomology of structure sheaf on P^4:
1084  //-------------------------------------------
1085  ring r=32001,x(1..5),dp;
1086
1087  module M= getStructureSheaf(); // OO_P^4
1088
1089  l = -12; h = 12; // range of twists: l..h
1090
1091  printlevel = 0;
1092  //////////////////////////////////////////////
1093  t = timer;
1094
1095  def A = sheafCoh(M, l, h); // global Ext method:
1096  displayCohom(A,l,h,nvars(basering)-1);
1097
1098  "Time: ", timer - t;
1099  //////////////////////////////////////////////
1100  t = timer;
1101
1102  A = sheafCohBGG(M, l, h);  // BGG method (without optimization):
1103  displayCohom(A,l,h,nvars(basering)-1);
1104
1105  "Time: ", timer - t;
1106  //////////////////////////////////////////////
1107  t = timer;
1108
1109  A = sheafCohBGG2(M, l, h); // BGG method (with optimization)
1110  displayCohom(A,l,h,nvars(basering)-1);
1111
1112  "Time: ", timer - t;
1113  //////////////////////////////////////////////
1114  printlevel = pl;
1115
1116  kill A, r;
1117
1118  //-------------------------------------------
1119  // cohomology of cotangential bundle on P^3:
1120  //-------------------------------------------
1121  ring R=32001,(x,y,z,u),dp;
1122
1123  module M = getCotangentialBundle();
1124
1125  l = -12; h = 11; // range of twists: l..h
1126
1127  //////////////////////////////////////////////
1128  printlevel = 0;
1129  t = timer;
1130
1131  def B = sheafCoh(M, l, h); // global Ext method:
1132  displayCohom(B,l,h,nvars(basering)-1);
1133
1134  "Time: ", timer - t;
1135  //////////////////////////////////////////////
1136  t = timer;
1137
1138  B = sheafCohBGG(M, l, h);  // BGG method (without optimization):
1139  displayCohom(B,l,h,nvars(basering)-1);
1140
1141  "Time: ", timer - t;
1142  //////////////////////////////////////////////
1143  t = timer;
1144
1145  B = sheafCohBGG2(M, l, h); // BGG method (with optimization)
1146  displayCohom(B,l,h,nvars(basering)-1);
1147
1148  "Time: ", timer - t;
1149  //////////////////////////////////////////////
1150  printlevel = pl;
1151}
1152
1153
1154///////////////////////////////////////////////////////////////////////////////
1155
1156proc dimH(int i,module M,int d)
1157"USAGE:   dimH(i,M,d);    M module, i,d int
1158ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
1159         vector as an attribute, @code{h>=l}, and the basering @code{S} has
1160         @code{n+1} variables.
1161RETURN:  int,  vector space dimension of @math{H^i(F(d))} for F the coherent
1162         sheaf on P^n associated to coker(M).
1163NOTE:    The procedure is based on local duality as described in [Eisenbud:
1164         Computing cohomology. In Vasconcelos: Computational methods in
1165         commutative algebra and algebraic geometry. Springer (1998)].
1166SEE ALSO: sheafCoh, sheafCohBGG
1167EXAMPLE: example dimH; shows an example
1168"
1169{
1170  if( typeof(attrib(M,"isHomog"))=="string" )
1171  {
1172    if (size(M)==0)
1173    {
1174      // assign weights 0 to generators of R^n (n=nrows(M))
1175      intvec v;
1176      v[nrows(M)]=0;
1177      attrib(M,"isHomog",v);
1178    }
1179    else
1180    {
1181      ERROR("No admissible degree vector assigned");
1182    }
1183  }
1184  int Result;
1185  int n=nvars(basering)-1;
1186  if ((i>0) and (i<=n))
1187  {
1188    list L=Ext_R(n-i,M,1)[2];
1189    def N=L[1];
1190    return(dimGradedPart(N,-n-1-d));
1191  }
1192  else
1193  {
1194    if (i==0)
1195    {
1196      list L=Ext_R(intvec(n+1,n+2),M,1)[2];
1197      def N0=L[2];
1198      def N1=L[1];
1199      Result=dimGradedPart(M,d) - dimGradedPart(N0,-n-1-d)
1200                                - dimGradedPart(N1,-n-1-d);
1201      return(Result);
1202    }
1203    else
1204    {
1205      return(0);
1206    }
1207  }
1208}
1209example
1210{"EXAMPLE:";
1211  echo = 2;
1212  ring R=0,(x,y,z,u),dp;
1213  resolution T1=mres(maxideal(1),0);
1214  module M=T1[3];
1215  intvec v=2,2,2,2,2,2;
1216  attrib(M,"isHomog",v);
1217  dimH(0,M,2);
1218  dimH(1,M,0);
1219  dimH(2,M,1);
1220  dimH(3,M,-5);
1221}
1222
1223
1224///////////////////////////////////////////////////////////////////////////////
1225
1226proc sheafCoh(module M,int l,int h,list #)
1227"USAGE:   sheafCoh(M,l,h);    M module, l,h int
1228ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
1229         vector as an attribute, @code{h>=l}. The basering @code{S} has
1230         @code{n+1} variables.
1231RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
1232         associated to coker(M). The range of twists is determined by @code{l},
1233         @code{h}.
1234DISPLAY: The intmat can be displayed in a diagram of the following form:
1235         with @code{displayCohom(A,l,h,nvars(r)-1);}@*
1236  @format
1237                l            l+1                      h
1238  ----------------------------------------------------------
1239      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
1240           ...............................................
1241      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
1242      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
1243  ----------------------------------------------------------
1244    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
1245  @end format
1246         A @code{'-'} in the diagram refers to a zero entry.
1247NOTE:    The procedure is based on local duality as described in [Eisenbud:
1248         Computing cohomology. In Vasconcelos: Computational methods in
1249         commutative algebra and algebraic geometry. Springer (1998)].@*
1250         By default, the procedure uses @code{mres} to compute the Ext
1251         modules. If called with the additional parameter @code{\"sres\"},
1252         the @code{sres} command is used instead.
1253SEE ALSO: dimH, sheafCohBGG, sheafCoh_w
1254EXAMPLE: example sheafCoh; shows an example
1255"
1256{
1257  int use_sres;
1258  if( typeof(attrib(M,"isHomog"))!="intvec" )
1259  {
1260     if (size(M)==0) { attrib(M,"isHomog",0); }
1261     else { ERROR("No admissible degree vector assigned"); }
1262  }
1263  if (size(#)>0)
1264  {
1265    if (#[1]=="sres") { use_sres=1; }
1266  }
1267  int i,j;
1268  module N,N0,N1;
1269  int n=nvars(basering)-1;
1270  intvec v=0..n+1;
1271  int col=h-l+1;
1272  intmat newBetti[n+1][col];
1273  if (use_sres) { list L=Ext_R(v,M,1,"sres")[2]; }
1274  else          { list L=Ext_R(v,M,1)[2]; }
1275  for (i=l; i<=h; i++)
1276  {
1277    N0=L[n+2];
1278    N1=L[n+1];
1279    newBetti[n+1,i-l+1]=dimGradedPart(M,i) - dimGradedPart(N0,-n-1-i)
1280                             - dimGradedPart(N0,-n-1-i);
1281  }
1282  for (j=1; j<=n; j++)
1283  {
1284     N=L[j];
1285     attrib(N,"isSB",1);
1286     if (dim(N)>=0)
1287     {
1288       for (i=l; i<=h; i++)
1289       {
1290         newBetti[j,i-l+1]=dimGradedPart(N,-n-1-i);
1291       }
1292     }
1293  }
1294  return(newBetti);
1295}
1296example
1297{"EXAMPLE:";
1298  echo = 2;
1299  //
1300  // cohomology of structure sheaf on P^4:
1301  //-------------------------------------------
1302  ring r=0,x(1..5),dp;
1303  module M=0;
1304  intmat A=sheafCoh(0,-7,2);
1305  A;
1306  displayCohom(A,-7,2,nvars(r)-1);
1307  //
1308  // cohomology of cotangential bundle on P^3:
1309  //-------------------------------------------
1310  ring R=0,(x,y,z,u),dp;
1311  resolution T1=mres(maxideal(1),0);
1312  module M=T1[3];
1313  intvec v=2,2,2,2,2,2;
1314  attrib(M,"isHomog",v);
1315  intmat B=sheafCoh(M,-6,2);
1316  displayCohom(B,-6,2,nvars(R)-1);
1317}
1318
1319proc sheafCoh_w(module M,int l,int h,intvec w, list #)
1320"USAGE:   sheafCoh(M,l,h);    M module, l,h int, w intvec
1321ASSUME:  @code{M} is graded by w, @code{h>=l}. The basering @code{S} has
1322         @code{n+1} variables.
1323RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
1324         associated to coker(M). The range of twists is determined by @code{l},
1325         @code{h}.
1326DISPLAY: The intmat can be displayed in a diagram of the following form:
1327         with @code{displayCohom(A,l,h,nvars(r)-1);}@*
1328  @format
1329                l            l+1                      h
1330  ----------------------------------------------------------
1331      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
1332           ...............................................
1333      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
1334      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
1335  ----------------------------------------------------------
1336    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
1337  @end format
1338         A @code{'-'} in the diagram refers to a zero entry.
1339NOTE:    The procedure is based on local duality as described in [Eisenbud:
1340         Computing cohomology. In Vasconcelos: Computational methods in
1341         commutative algebra and algebraic geometry. Springer (1998)].@*
1342         By default, the procedure uses @code{mres} to compute the Ext
1343         modules. If called with the additional parameter @code{\"sres\"},
1344         the @code{sres} command is used instead.
1345SEE ALSO: dimH, sheafCohBGG, sheafCoh
1346EXAMPLE: example sheafCoh; shows an example
1347"
1348{
1349  attrib(M,"isHomog",w);
1350  return(sheafCoh(M,l,h,#));
1351}
1352example
1353{"EXAMPLE:";
1354  echo = 2;
1355  //
1356  // cohomology of structure sheaf on P^4:
1357  //-------------------------------------------
1358  ring r=0,x(1..5),dp;
1359  module M=0;
1360  intmat A=sheafCoh_w(0,-7,2,intvec(0));
1361  A;
1362  displayCohom(A,-7,2,nvars(r)-1);
1363  //
1364  // cohomology of cotangential bundle on P^3:
1365  //-------------------------------------------
1366  ring R=0,(x,y,z,u),dp;
1367  resolution T1=mres(maxideal(1),0);
1368  module M=T1[3];
1369  intvec v=2,2,2,2,2,2;
1370  intmat B=sheafCoh_w(M,-6,2,v);
1371  displayCohom(B,-6,2,nvars(R)-1);
1372}
1373
1374///////////////////////////////////////////////////////////////////////////////
1375proc displayCohom (intmat data, int l, int h, int n)
1376"USAGE:   displayCohom(data,l,h,n);  data intmat, l,h,n int
1377ASSUME:  @code{h>=l}, @code{data} is the return value of
1378         @code{sheafCoh(M,l,h)} or of @code{sheafCohBGG(M,l,h)}, and the
1379         basering has @code{n+1} variables.
1380RETURN:  none
1381NOTE:    The intmat is displayed in a diagram of the following form: @*
1382  @format
1383                l            l+1                      h
1384  ----------------------------------------------------------
1385      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
1386           ...............................................
1387      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
1388      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
1389  ----------------------------------------------------------
1390    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
1391  @end format
1392         where @code{F} refers to the associated sheaf of @code{M} on P^n.@*
1393         A @code{'-'} in the diagram refers to a zero entry,  a @code{'*'}
1394         refers to a negative entry (= dimension not yet determined).
1395"
1396{
1397  int i,j,k,dat,maxL;
1398  intvec notSumCol;
1399  notSumCol[h-l+1]=0;
1400  string s;
1401  maxL=4;
1402  for (i=1;i<=nrows(data);i++)
1403  {
1404    for (j=1;j<=ncols(data);j++)
1405    {
1406      if (size(string(data[i,j]))>=maxL-1)
1407      {
1408        maxL=size(string(data[i,j]))+2;
1409      }
1410    }
1411  }
1412  string Row="    ";
1413  string Row1="----";
1414  for (i=l; i<=h; i++)
1415  {
1416    for (j=1; j<=maxL-size(string(i)); j++)
1417    {
1418      Row=Row+" ";
1419    }
1420    Row=Row+string(i);
1421    for (j=1; j<=maxL; j++) { Row1 = Row1+"-"; }
1422  }
1423  print(Row);
1424  print(Row1);
1425  for (j=1; j<=n+1; j++)
1426  {
1427    s = string(n+1-j);
1428    Row = "";
1429    for(k=1; k<4-size(s); k++) { Row = Row+" "; }
1430    Row = Row + s+":";
1431    for (i=0; i<=h-l; i++)
1432    {
1433      dat = data[j,i+1];
1434      if (dat>0) { s = string(dat); }
1435      else
1436      {
1437        if (dat==0) { s="-"; }
1438        else        { s="*"; notSumCol[i+1]=1; }
1439      }
1440      for(k=1; k<=maxL-size(s); k++) { Row = Row+" "; }
1441      Row = Row + s;
1442    }
1443    print(Row);
1444  }
1445  print(Row1);
1446  Row="chi:";
1447  for (i=0; i<=h-l; i++)
1448  {
1449    dat = 0;
1450    if (notSumCol[i+1]==0)
1451    {
1452      for (j=0; j<=n; j++) { dat = dat + (-1)^j * data[n+1-j,i+1]; }
1453      s = string(dat);
1454    }
1455    else { s="*"; }
1456    for (k=1; k<=maxL-size(s); k++) { Row = Row+" "; }
1457    Row = Row + s;
1458  }
1459  print(Row);
1460}
1461///////////////////////////////////////////////////////////////////////////////
1462
1463proc getStructureSheaf(list #)
1464{
1465
1466  if( size(#) == 0 )
1467  {
1468    module M = 0;
1469    intvec v = 0;
1470    attrib(M,"isHomog",v);
1471//    homog(M);
1472
1473    attrib(M, "isCoker", 1);
1474
1475//     attrib(M);
1476    return(M);
1477  }
1478
1479  if( typeof(#[1]) == "ideal")
1480  {
1481    ideal I = #[1];
1482
1483    if( size(#) == 2 )
1484    {
1485      if( typeof(#[2]) == "int" )
1486      {
1487        if( #[2] != 0 )
1488        {
1489          qring @@@@QQ = std(I);
1490
1491          module M = getStructureSheaf();
1492
1493          export M;
1494
1495//          keepring @@@@QQ; // This is a bad idea... :(?
1496          return (@@@@QQ);
1497        }
1498      }
1499    }
1500
1501/*
1502    // This seems to be wrong!!!
1503    module M = I * gen(1);
1504    homog(M);
1505
1506    M = modulo(gen(1), module(I * gen(1))); // basering^1 / I
1507
1508    homog(M);
1509
1510    attrib(M, "isCoker", 1);
1511
1512    attrib(M);
1513    return(M);
1514*/
1515  }
1516
1517  ERROR("Wrong argument");
1518
1519}
1520example
1521{"EXAMPLE:";
1522  echo = 2; int pl = printlevel;
1523  printlevel = voice;
1524
1525
1526  //////////////////////////////////////////////////////////////////////////////
1527  ring r;
1528  module M = getStructureSheaf();
1529  "Basering: ";
1530  basering;
1531  "Module: ", string(M), ", grading is given by weights: ", attrib(M, "isHomog");
1532
1533  def A=sheafCohBGG2(M,-9,9);
1534  print(A);
1535
1536  //////////////////////////////////////////////////////////////////////////////
1537  setring r;
1538  module M = getStructureSheaf(ideal(var(1)), 0);
1539
1540  "Basering: ";
1541  basering;
1542  "Module: ", string(M), ", grading is given by weights: ", attrib(M, "isHomog");
1543
1544  def A=sheafCohBGG2(M,-9,9);
1545  print(A);
1546
1547  //////////////////////////////////////////////////////////////////////////////
1548  setring r;
1549  def Q = getStructureSheaf(ideal(var(1)), 1); // returns a new ring!
1550  setring Q; // M was exported in the new ring!
1551
1552  "Basering: ";
1553  basering;
1554  "Module: ", string(M), ", grading is given by weights: ", attrib(M, "isHomog");
1555
1556  def A=sheafCohBGG2(M,-9,9);
1557  print(A);
1558
1559  printlevel = pl;
1560}
1561
1562
1563proc getCotangentialBundle()
1564{
1565  resolution T1=mres(maxideal(1),3);
1566  module M=T1[3];
1567//  attrib(M,"isHomog");
1568//  homog(M);
1569  attrib(M, "isCoker", 1);
1570  // attrib(M);
1571  return (M);
1572}
1573
1574proc getIdealSheafPullback(ideal I, ideal pi)
1575{
1576  def save = basering;
1577  map P = save, pi;
1578  return( P(I) );
1579}
1580
1581// TODO: set attributes!
1582
1583
1584proc getIdealSheaf(ideal I)
1585{
1586  int i = homog(I);
1587  resolution FI = mres(I,2); // Syz + grading...
1588  module M = FI[2];
1589  attrib(M, "isCoker", 1);
1590  //  attrib(M);
1591  return(M);
1592}
1593
1594
1595/*
1596Examples:
1597---------
1598 LIB "sheafcoh.lib";
1599
1600 ring S = 32003, x(0..4), dp;
1601 module MI=maxideal(1);
1602 attrib(MI,"isHomog",intvec(-1));
1603 resolution kos = nres(MI,0);
1604 print(betti(kos),"betti");
1605 LIB "random.lib";
1606 matrix alpha0 = random(32002,10,3);
1607 module pres = module(alpha0)+kos[3];
1608 attrib(pres,"isHomog",intvec(1,1,1,1,1,1,1,1,1,1));
1609 resolution fcokernel = mres(pres,0);
1610 print(betti(fcokernel),"betti");
1611 module dir = transpose(pres);
1612 attrib(dir,"isHomog",intvec(-1,-1,-1,-2,-2,-2,
1613                             -2,-2,-2,-2,-2,-2,-2));
1614 resolution fdir = mres(dir,2);
1615 print(betti(fdir),"betti");
1616 ideal I = groebner(flatten(fdir[2]));
1617 resolution FI = mres(I,0);
1618 print(betti(FI),"betti");
1619 module F=FI[2];
1620 int t=timer;
1621 def A1=sheafCoh(F,-8,8);
1622 timer-t;
1623 t=timer;
1624 def A2=sheafCohBGG(F,-8,8);
1625 timer-t;
1626
1627 LIB "sheafcoh.lib";
1628 LIB "random.lib";
1629 ring S = 32003, x(0..4), dp;
1630 resolution kos = nres(maxideal(1),0);
1631 betti(kos);
1632 matrix kos5 = kos[5];
1633 matrix tphi = transpose(dsum(kos5,kos5));
1634 matrix kos3 = kos[3];
1635 matrix psi = dsum(kos3,kos3);
1636 matrix beta1 = random(32002,20,2);
1637 matrix tbeta1tilde = transpose(psi*beta1);
1638 matrix tbeta0 = lift(tphi,tbeta1tilde);
1639 matrix kos4 = kos[4];
1640 matrix tkos4pluskos4 = transpose(dsum(kos4,kos4));
1641 matrix tgammamin1 = random(32002,20,1);
1642 matrix tgamma0 = tkos4pluskos4*tgammamin1;
1643 matrix talpha0 = concat(tbeta0,tgamma0);
1644 matrix zero[20][1];
1645 matrix tpsi = transpose(psi);
1646 matrix tpresg = concat(tpsi,zero);
1647 matrix pres = module(transpose(talpha0))
1648                    + module(transpose(tpresg));
1649 module dir = transpose(pres);
1650 dir = prune(dir);
1651 homog(dir);
1652 intvec deg_dir = attrib(dir,"isHomog");
1653 attrib(dir,"isHomog",deg_dir-2);        // set degrees
1654 resolution fdir = mres(prune(dir),2);
1655 print(betti(fdir),"betti");
1656 ideal I = groebner(flatten(fdir[2]));
1657 resolution FI = mres(I,0);
1658
1659 module F=FI[2];
1660 def A1=sheafCoh(F,-5,7);
1661 def A2=sheafCohBGG(F,-5,7);
1662
1663*/
Note: See TracBrowser for help on using the repository browser.