source: git/Singular/LIB/sheafcoh.lib @ fa7c85

spielwiese
Last change on this file since fa7c85 was fa7c85, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: minor optimizations git-svn-id: file:///usr/local/Singular/svn/trunk@9493 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 18.5 KB
Line 
1S///////////////////////////////////////////////////////////////////////////////
2version="$Id: sheafcoh.lib,v 1.9 2006-11-17 14:15:42 Singular Exp $";
3category="Commutative Algebra";
4info="
5LIBRARY:  sheafcoh.lib   Procedures for Computing Sheaf Cohomology
6AUTHORS:  Wolfram Decker, decker@math.uni-sb.de,
7@*        Christoph Lossen,  lossen@mathematik.uni-kl.de
8@*        Gerhrd Pfister,  pfister@mathematik.uni-kl.de
9
10PROCEDURES:
11 truncate(phi,d);        truncation of coker(phi) at d
12 CM_regularity(M);       Castelnuovo-Mumford regularity of coker(M)
13 sheafCohBGG(M,l,h);     cohomology of sheaf associated to coker(M)
14 sheafCoh(M,l,h);        cohomology of sheaf associated to coker(M)
15 dimH(i,M,d);            compute h^i(F(d)), F sheaf associated to coker(M)
16
17AUXILIARY PROCEDURES:
18 displayCohom(B,l,h,n);  display intmat as Betti diagram (with zero rows)
19
20KEYWORDS: sheaf cohomology
21";
22
23///////////////////////////////////////////////////////////////////////////////
24LIB "matrix.lib";
25LIB "nctools.lib";
26LIB "homolog.lib";
27
28///////////////////////////////////////////////////////////////////////////////
29static proc jacobM(matrix M)
30{
31   int n=nvars(basering);
32   matrix B=transpose(diff(M,var(1)));
33   int i;
34   for(i=2;i<=n;i++)
35   {
36     B=concat(B,transpose(diff(M,var(i))));
37   }
38   return(transpose(B));
39}
40///////////////////////////////////////////////////////////////////////////////
41static proc max(int i,int j)
42{
43  if(i>j){return(i);}
44  return(j);
45}
46
47///////////////////////////////////////////////////////////////////////////////
48proc truncate(module phi, int d)
49"USAGE:   truncate(M,d);  M module, d int
50ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
51         vector as an attribute
52RETURN:  module
53NOTE:    Output is a presentation matrix for the truncation of coker(M)
54         at d.
55EXAMPLE: example truncate; shows an example
56KEYWORDS: truncated module
57"
58{
59  if ( typeof(attrib(phi,"isHomog"))=="string" ) {
60    if (size(phi)==0) {
61      // assign weights 0 to generators of R^n (n=nrows(phi))
62      intvec v;
63      v[nrows(phi)]=0;
64      attrib(phi,"isHomog",v);
65    }
66    else {
67      ERROR("No admissible degree vector assigned");
68    }
69  }
70  else {
71   intvec v=attrib(phi,"isHomog");
72  }
73  int i,m,dummy;
74  int s = nrows(phi);
75  module L;
76  for (i=1; i<=s; i++) {
77    if (d>v[i]) {
78      L = L+maxideal(d-v[i])*gen(i);
79    }
80    else {
81      L = L+gen(i);
82    }
83  }
84  L = modulo(L,phi);
85  L = minbase(prune(L));
86  if (size(L)==0) {return(L);}
87
88  // it only remains to set the degrees for L:
89  // ------------------------------------------
90  m = v[1];
91  for(i=2; i<=size(v); i++) {  if(v[i]<m) { m = v[i]; } }
92  dummy = homog(L);
93  intvec vv = attrib(L,"isHomog");
94  if (d>m) { vv = vv+d; }
95  else     { vv = vv+m; }
96  attrib(L,"isHomog",vv);
97  return(L);
98}
99example
100{"EXAMPLE:";
101   echo = 2;
102   ring R=0,(x,y,z),dp;
103   module M=maxideal(3);
104   homog(M);
105   // compute presentation matrix for truncated module (R/<x,y,z>^3)_(>=2)
106   module M2=truncate(M,2);
107   print(M2);
108   dimGradedPart(M2,1);
109   dimGradedPart(M2,2);
110   // this should coincide with:
111   dimGradedPart(M,2);
112   // shift grading by 1:
113   intvec v=1;
114   attrib(M,"isHomog",v);
115   M2=truncate(M,2);
116   print(M2);
117   dimGradedPart(M2,3);
118}
119
120///////////////////////////////////////////////////////////////////////////////
121
122proc dimGradedPart(module phi, int d)
123"USAGE:   dimGradedPart(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:  int
127NOTE:    Output is the vector space dimension of the graded part of degree d
128         of coker(M).
129EXAMPLE: example dimGradedPart; shows an example
130KEYWORDS: graded module, graded piece
131"
132{
133  if ( typeof(attrib(phi,"isHomog"))=="string" ) {
134    if (size(phi)==0) {
135      // assign weights 0 to generators of R^n (n=nrows(phi))
136      intvec v;
137      v[nrows(phi)]=0;
138    }
139    else { ERROR("No admissible degree vector assigned"); }
140  }
141  else {
142    intvec v=attrib(phi,"isHomog");
143  }
144  int s = nrows(phi);
145  int i,m,dummy;
146  module L,LL;
147  for (i=1; i<=s; i++) {
148    if (d>v[i]) {
149      L = L+maxideal(d-v[i])*gen(i);
150      LL = LL+maxideal(d+1-v[i])*gen(i);
151    }
152    else {
153      L = L+gen(i);
154      if (d==v[i]) {
155        LL = LL+maxideal(1)*gen(i);
156      }
157      else {
158        LL = LL+gen(i);
159      }
160    }
161  }
162  LL=LL,phi;
163  L = modulo(L,LL);
164  L = std(prune(L));
165  if (size(L)==0) {return(0);}
166  return(vdim(L));
167}
168example
169{"EXAMPLE:";
170   echo = 2;
171   ring R=0,(x,y,z),dp;
172   module M=maxideal(3);
173   // assign compatible weight vector (here: 0)
174   homog(M);
175   // compute dimension of graded pieces of R/<x,y,z>^3 :
176   dimGradedPart(M,0);
177   dimGradedPart(M,1);
178   dimGradedPart(M,2);
179   dimGradedPart(M,3);
180   // shift grading:
181   attrib(M,"isHomog",intvec(2));
182   dimGradedPart(M,2);
183}
184
185///////////////////////////////////////////////////////////////////////////////
186
187proc CM_regularity (module M)
188"USAGE:   CM_regularity(M);    M module
189ASSUME:   @code{M} is graded, and it comes assigned with an admissible degree
190         vector as an attribute
191RETURN:  integer, the Castelnuovo-Mumford regularity of coker(M)
192NOTE:    procedure calls mres
193EXAMPLE: example CM_regularity; shows an example
194KEYWORDS: Castelnuovo-Mumford regularity
195"
196{
197  if ( typeof(attrib(M,"isHomog"))=="string" ) {
198    if (size(M)==0) {
199      // assign weights 0 to generators of R^n (n=nrows(M))
200      intvec v;
201      v[nrows(M)]=0;
202      attrib(M,"isHomog",v);
203    }
204    else {
205      ERROR("No admissible degree vector assigned");
206    }
207  }
208  def L = mres(M,0);
209  intmat BeL = betti(L);
210  int r = nrows(module(matrix(BeL)));  // last non-zero row
211  if (typeof(attrib(BeL,"rowShift"))!="string") {
212    int shift = attrib(BeL,"rowShift");
213  }
214  return(r+shift-1);
215}
216example
217{"EXAMPLE:";
218   echo = 2;
219   ring R=0,(x,y,z,u),dp;
220   resolution T1=mres(maxideal(1),0);
221   module M=T1[3];
222   intvec v=2,2,2,2,2,2;
223   attrib(M,"isHomog",v);
224   CM_regularity(M);
225}
226
227///////////////////////////////////////////////////////////////////////////////
228
229proc sheafCohBGG(module M,int l,int h)
230"USAGE:   sheafCohBGG(M,l,h);    M module, l,h int
231ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
232         vector as an attribute, @code{h>=l}, and the basering has @code{n+1}
233         variables.
234RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
235         associated to coker(M). The range of twists is determined by @code{l},
236         @code{h}.
237DISPLAY: The intmat is displayed in a diagram of the following form: @*
238  @format
239                l            l+1                      h
240  ----------------------------------------------------------
241      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
242           ...............................................
243      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
244      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
245  ----------------------------------------------------------
246    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
247  @end format
248         A @code{'-'} in the diagram refers to a zero entry; a @code{'*'}
249         refers to a negative entry (= dimension not yet determined).
250         refers to a not computed dimension. @*
251NOTE:    This procedure is based on the Bernstein-Gel'fand-Gel'fand
252         correspondence and on Tate resolution ( see [Eisenbud, Floystad,
253         Schreyer: Sheaf cohomology and free resolutions over exterior
254         algebras, Trans AMS 355 (2003)] ).@*
255         @code{sheafCohBGG(M,l,h)} does not compute all values in the above
256         table. To determine all values of @code{h^i(F(d))}, @code{d=l..h},
257         use @code{sheafCohBGG(M,l-n,h+n)}.
258SEE ALSO: sheafCoh, dimH
259EXAMPLE: example sheafCohBGG; shows an example
260"
261{
262  int i,j,k,row,col;
263  if( typeof(attrib(M,"isHomog"))!="intvec" ) {
264     if (size(M)==0) { attrib(M,"isHomog",0); }
265     else { ERROR("No admissible degree vector assigned"); }
266  }
267  int n=nvars(basering)-1;
268  int ell=l+n;
269  def R=basering;
270  int reg = CM_regularity(M);
271  int bound=max(reg+1,h-1);
272  module MT=truncate(M,bound);
273  int m=nrows(MT);
274  MT=transpose(jacobM(MT));
275  MT=syz(MT);
276  matrix ML[n+1][1]=maxideal(1);
277  matrix S=transpose(outer(ML,unitmat(m)));
278  matrix SS=transpose(S*MT);
279  //--- to the exterior algebra
280  def AR = Exterior();
281  setring AR;
282  option(redSB);
283  option(redTail);
284  module EM=imap(R,SS);
285  intvec w;
286  //--- here we are with our matrix
287  int bound1=max(1,bound-ell+1);
288  for (i=1; i<=nrows(EM); i++)
289  {
290     w[i]=-bound-1;
291  }
292  attrib(EM,"isHomog",w);
293  resolution RE=mres(EM,bound1);
294  intmat Betti=betti(RE);
295  k=ncols(Betti);
296  row=nrows(Betti);
297  int shift=attrib(Betti,"rowShift")+(k+ell-1);
298  intmat newBetti[n+1][h-l+1];
299  for (j=1; j<=row; j++) {
300    for (i=l; i<=h; i++) {
301      if ((k+1-j-i+ell-shift>0) and (j+i-ell+shift>=1)) {
302        newBetti[n+2-shift-j,i-l+1]=Betti[j,k+1-j-i+ell-shift];
303      }
304      else { newBetti[n+2-shift-j,i-l+1]=-1; }
305    }
306  }
307  for (j=2; j<=n+1; j++) {
308    for (i=1; i<j; i++) {
309      newBetti[j,i]=-1;
310    }
311  }
312  int d=k-h+ell-1;
313  for (j=1; j<=n; j++) {
314    for (i=h-l+1; i>=k+j; i--) {
315      newBetti[j,i]=-1;
316    }
317  }
318  displayCohom(newBetti,l,h,n);
319  setring R;
320  return(newBetti);
321  option(noredSB);
322  option(noredTail);
323}
324example
325{"EXAMPLE:";
326   echo = 2;
327   // cohomology of structure sheaf on P^4:
328   //-------------------------------------------
329   ring r=0,x(1..5),dp;
330   module M=0;
331   def A=sheafCohBGG(0,-9,4);
332   // cohomology of cotangential bundle on P^3:
333   //-------------------------------------------
334   ring R=0,(x,y,z,u),dp;
335   resolution T1=mres(maxideal(1),0);
336   module M=T1[3];
337   intvec v=2,2,2,2,2,2;
338   attrib(M,"isHomog",v);
339   def B=sheafCohBGG(M,-8,4);
340}
341
342///////////////////////////////////////////////////////////////////////////////
343
344proc dimH(int i,module M,int d)
345"USAGE:   dimH(i,M,d);    M module, i,d int
346ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
347         vector as an attribute, @code{h>=l}, and the basering @code{S} has
348         @code{n+1} variables.
349RETURN:  int,  vector space dimension of @math{H^i(F(d))} for F the coherent
350         sheaf on P^n associated to coker(M).
351NOTE:    The procedure is based on local duality as described in [Eisenbud:
352         Computing cohomology. In Vasconcelos: Computational methods in
353         commutative algebra and algebraic geometry. Springer (1998)].
354SEE ALSO: sheafCoh, sheafCohBGG
355EXAMPLE: example dimH; shows an example
356"
357{
358  if( typeof(attrib(M,"isHomog"))=="string" ) {
359    if (size(M)==0) {
360      // assign weights 0 to generators of R^n (n=nrows(M))
361      intvec v;
362      v[nrows(M)]=0;
363      attrib(M,"isHomog",v);
364    }
365    else {
366      ERROR("No admissible degree vector assigned");
367    }
368  }
369  int Result;
370  int n=nvars(basering)-1;
371  if ((i>0) and (i<=n)) {
372    list L=Ext_R(n-i,M,1)[2];
373    def N=L[1];
374    return(dimGradedPart(N,-n-1-d));
375  }
376  else {
377    if (i==0) {
378      list L=Ext_R(intvec(n+1,n+2),M,1)[2];
379      def N0=L[2];
380      def N1=L[1];
381      Result=dimGradedPart(M,d) - dimGradedPart(N0,-n-1-d)
382                                - dimGradedPart(N1,-n-1-d);
383      return(Result);
384    }
385    else {
386      return(0);
387    }
388  }
389}
390example
391{"EXAMPLE:";
392   echo = 2;
393   ring R=0,(x,y,z,u),dp;
394   resolution T1=mres(maxideal(1),0);
395   module M=T1[3];
396   intvec v=2,2,2,2,2,2;
397   attrib(M,"isHomog",v);
398   dimH(0,M,2);
399   dimH(1,M,0);
400   dimH(2,M,1);
401   dimH(3,M,-5);
402}
403
404
405///////////////////////////////////////////////////////////////////////////////
406
407proc sheafCoh(module M,int l,int h,list #)
408"USAGE:   sheafCoh(M,l,h);    M module, l,h int
409ASSUME:  @code{M} is graded, and it comes assigned with an admissible degree
410         vector as an attribute, @code{h>=l}. The basering @code{S} has
411         @code{n+1} variables.
412RETURN:  intmat, cohomology of twists of the coherent sheaf F on P^n
413         associated to coker(M). The range of twists is determined by @code{l},
414         @code{h}.
415DISPLAY: The intmat is displayed in a diagram of the following form: @*
416  @format
417                l            l+1                      h
418  ----------------------------------------------------------
419      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
420           ...............................................
421      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
422      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
423  ----------------------------------------------------------
424    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
425  @end format
426         A @code{'-'} in the diagram refers to a zero entry.
427NOTE:    The procedure is based on local duality as described in [Eisenbud:
428         Computing cohomology. In Vasconcelos: Computational methods in
429         commutative algebra and algebraic geometry. Springer (1998)].@*
430         By default, the procedure uses @code{mres} to compute the Ext
431         modules. If called with the additional parameter @code{\"sres\"},
432         the @code{sres} command is used instead.
433SEE ALSO: dimH, sheafCohBGG
434EXAMPLE: example sheafCoh; shows an example
435"
436{
437  int use_sres;
438  if( typeof(attrib(M,"isHomog"))!="intvec" ) {
439     if (size(M)==0) { attrib(M,"isHomog",0); }
440     else { ERROR("No admissible degree vector assigned"); }
441  }
442  if (size(#)>0) {
443    if (#[1]=="sres") { use_sres=1; }
444  }
445  int i,j;
446  module N,N0,N1;
447  int n=nvars(basering)-1;
448  intvec v=0..n+1;
449  int col=h-l+1;
450  intmat newBetti[n+1][col];
451  if (use_sres) { list L=Ext_R(v,M,1,"sres")[2]; }
452  else          { list L=Ext_R(v,M,1)[2]; }
453  for (i=l; i<=h; i++) {
454    N0=L[n+2];
455    N1=L[n+1];
456    newBetti[n+1,i-l+1]=dimGradedPart(M,i) - dimGradedPart(N0,-n-1-i)
457                             - dimGradedPart(N0,-n-1-i);
458  }
459  for (j=1; j<=n; j++) {
460     N=L[j];
461     attrib(N,"isSB",1);
462     if (dim(N)>=0) {
463       for (i=l; i<=h; i++) {
464         newBetti[j,i-l+1]=dimGradedPart(N,-n-1-i);
465       }
466     }
467  }
468  displayCohom(newBetti,l,h,n);
469  return(newBetti);
470}
471example
472{"EXAMPLE:";
473   echo = 2;
474   //
475   // cohomology of structure sheaf on P^4:
476   //-------------------------------------------
477   ring r=0,x(1..5),dp;
478   module M=0;
479   def A=sheafCoh(0,-7,2);
480   //
481   // cohomology of cotangential bundle on P^3:
482   //-------------------------------------------
483   ring R=0,(x,y,z,u),dp;
484   resolution T1=mres(maxideal(1),0);
485   module M=T1[3];
486   intvec v=2,2,2,2,2,2;
487   attrib(M,"isHomog",v);
488   def B=sheafCoh(M,-6,2);
489}
490
491///////////////////////////////////////////////////////////////////////////////
492proc displayCohom (intmat data, int l, int h, int n)
493"USAGE:   displayCohom(data,l,h,n);  data intmat, l,h,n int
494ASSUME:  @code{h>=l}, @code{data} is the return value of
495         @code{sheafCoh(M,l,h)} or of @code{sheafCohBGG(M,l,h)}, and the
496         basering has @code{n+1} variables.
497RETURN:  none
498NOTE:    The intmat is displayed in a diagram of the following form: @*
499  @format
500                l            l+1                      h
501  ----------------------------------------------------------
502      n:     h^n(F(l))    h^n(F(l+1))   ......    h^n(F(h))
503           ...............................................
504      1:     h^1(F(l))    h^1(F(l+1))   ......    h^1(F(h))
505      0:     h^0(F(l))    h^0(F(l+1))   ......    h^0(F(h))
506  ----------------------------------------------------------
507    chi:     chi(F(l))    chi(F(l+1))   ......    chi(F(h))
508  @end format
509         where @code{F} refers to the associated sheaf of @code{M} on P^n.@*
510         A @code{'-'} in the diagram refers to a zero entry,  a @code{'*'}
511         refers to a negative entry (= dimension not yet determined).
512"
513{
514  int i,j,k,dat,maxL;
515  intvec notSumCol;
516  notSumCol[h-l+1]=0;
517  string s;
518  maxL=4;
519  for (i=1;i<=nrows(data);i++) {
520    for (j=1;j<=ncols(data);j++) {
521      if (size(string(data[i,j]))>=maxL-1) {
522        maxL=size(string(data[i,j]))+2;
523      }
524    }
525  }
526  string Row="    ";
527  string Row1="----";
528  for (i=l; i<=h; i++) {
529    for (j=1; j<=maxL-size(string(i)); j++) {
530      Row=Row+" ";
531    }
532    Row=Row+string(i);
533    for (j=1; j<=maxL; j++) { Row1 = Row1+"-"; }
534  }
535  print(Row);
536  print(Row1);
537  for (j=1; j<=n+1; j++) {
538    s = string(n+1-j);
539    Row = "";
540    for(k=1; k<4-size(s); k++) { Row = Row+" "; }
541    Row = Row + s+":";
542    for (i=0; i<=h-l; i++) {
543      dat = data[j,i+1];
544      if (dat>0) { s = string(dat); }
545      else {
546        if (dat==0) { s="-"; }
547        else        { s="*"; notSumCol[i+1]=1; }
548      }
549      for(k=1; k<=maxL-size(s); k++) { Row = Row+" "; }
550      Row = Row + s;
551    }
552    print(Row);
553  }
554  print(Row1);
555  Row="chi:";
556  for (i=0; i<=h-l; i++) {
557    dat = 0;
558    if (notSumCol[i+1]==0) {
559      for (j=0; j<=n; j++) { dat = dat + (-1)^j * data[n+1-j,i+1]; }
560      s = string(dat);
561    }
562    else { s="*"; }
563    for (k=1; k<=maxL-size(s); k++) { Row = Row+" "; }
564    Row = Row + s;
565  }
566  print(Row);
567}
568///////////////////////////////////////////////////////////////////////////////
569
570
571/*
572Examples:
573---------
574 LIB "sheafcoh.lib";
575
576 ring S = 32003, x(0..4), dp;
577 module MI=maxideal(1);
578 attrib(MI,"isHomog",intvec(-1));
579 resolution kos = nres(MI,0);
580 print(betti(kos),"betti");
581 LIB "random.lib";
582 matrix alpha0 = random(32002,10,3);
583 module pres = module(alpha0)+kos[3];
584 attrib(pres,"isHomog",intvec(1,1,1,1,1,1,1,1,1,1));
585 resolution fcokernel = mres(pres,0);
586 print(betti(fcokernel),"betti");
587 module dir = transpose(pres);
588 attrib(dir,"isHomog",intvec(-1,-1,-1,-2,-2,-2,
589                             -2,-2,-2,-2,-2,-2,-2));
590 resolution fdir = mres(dir,2);
591 print(betti(fdir),"betti");
592 ideal I = groebner(flatten(fdir[2]));
593 resolution FI = mres(I,0);
594 print(betti(FI),"betti");
595 module F=FI[2];
596 int t=timer;
597 def A1=sheafCoh(F,-8,8);
598 timer-t;
599 t=timer;
600 def A2=sheafCohBGG(F,-8,8);
601 timer-t;
602
603 LIB "sheafcoh.lib";
604 LIB "random.lib";
605 ring S = 32003, x(0..4), dp;
606 resolution kos = nres(maxideal(1),0);
607 betti(kos);
608 matrix kos5 = kos[5];
609 matrix tphi = transpose(dsum(kos5,kos5));
610 matrix kos3 = kos[3];
611 matrix psi = dsum(kos3,kos3);
612 matrix beta1 = random(32002,20,2);
613 matrix tbeta1tilde = transpose(psi*beta1);
614 matrix tbeta0 = lift(tphi,tbeta1tilde);
615 matrix kos4 = kos[4];
616 matrix tkos4pluskos4 = transpose(dsum(kos4,kos4));
617 matrix tgammamin1 = random(32002,20,1);
618 matrix tgamma0 = tkos4pluskos4*tgammamin1;
619 matrix talpha0 = concat(tbeta0,tgamma0);
620 matrix zero[20][1];
621 matrix tpsi = transpose(psi);
622 matrix tpresg = concat(tpsi,zero);
623 matrix pres = module(transpose(talpha0))
624                    + module(transpose(tpresg));
625 module dir = transpose(pres);
626 dir = prune(dir);
627 homog(dir);
628 intvec deg_dir = attrib(dir,"isHomog");
629 attrib(dir,"isHomog",deg_dir-2);        // set degrees
630 resolution fdir = mres(prune(dir),2);
631 print(betti(fdir),"betti");
632 ideal I = groebner(flatten(fdir[2]));
633 resolution FI = mres(I,0);
634
635 module F=FI[2];
636 def A1=sheafCoh(F,-5,7);
637 def A2=sheafCohBGG(F,-5,7);
638
639*/
Note: See TracBrowser for help on using the repository browser.