i1 : symExt = (m,E) ->(
          ev := map(E,ring m,vars E);
          mt := transpose jacobian m;
          jn := gens kernel mt;
          q  := vars(ring m)**id_(target m);
          ans:= transpose ev(q*jn);
          --now correct the degrees:
          map(E^{(rank target ans):1}, E^{(rank source ans):0}, 
              ans));
i2 : S=ZZ/32003[x_0..x_2];
i3 : E=ZZ/32003[e_0..e_2,SkewCommutative=>true];
i4 : M=coker matrix{{x_0^2, x_1^2}};
i5 : m=presentation truncate(regularity M,M);

             4       8
o5 : Matrix S  <--- S
i6 : symExt(m,E)

o6 = {-1} | e_2 e_1 e_0 0   |
     {-1} | 0   e_2 0   e_0 |
     {-1} | 0   0   e_2 e_1 |
     {-1} | 0   0   0   e_2 |

             4       4
o6 : Matrix E  <--- E
i7 : bgg = (i,M,E) ->(
          S :=ring(M);
          numvarsE := rank source vars E;
          ev:=map(E,S,vars E);
          f0:=basis(i,M);
          f1:=basis(i+1,M);
          g :=((vars S)**f0)//f1;
          b:=(ev g)*((transpose vars E)**(ev source f0));
          --correct the degrees (which are otherwise
          --wrong in the transpose)
          map(E^{(rank target b):i+1},E^{(rank source b):i}, b));
i8 : M=cokernel matrix{{x_0^2, x_1^2, x_2^2}};
i9 : bgg(1,M,E)

o9 = {-2} | e_1 e_0 0   |
     {-2} | e_2 0   e_0 |
     {-2} | 0   e_2 e_1 |

             3       3
o9 : Matrix E  <--- E
i10 : tateResolution = (m,E,loDeg,hiDeg)->(
           M := coker m;
           reg := regularity M;
           bnd := max(reg+1,hiDeg-1);
           mt  := presentation truncate(bnd,M);
           o   := symExt(mt,E);
           --adjust degrees, since symExt forgets them
           ofixed   :=  map(E^{(rank target o):bnd+1},
                      E^{(rank source o):bnd},
                      o);
           res(coker ofixed, LengthLimit=>max(1,bnd-loDeg+1)));
i11 : m = matrix{{x_0,x_1}};

              1       2
o11 : Matrix S  <--- S
i12 : regularity coker m

o12 = 0
i13 : T = tateResolution(m,E,-2,4)

       1      1      1      1      1      1      1
o13 = E  <-- E  <-- E  <-- E  <-- E  <-- E  <-- E
                                                 
      0      1      2      3      4      5      6

o13 : ChainComplex
i14 : betti T

o14 = total: 1 1 1 1 1 1 1
         -4: 1 1 1 1 1 1 1
i15 : T.dd_1

o15 = {-4} | e_2 |

              1       1
o15 : Matrix E  <--- E
i16 : sheafCohomology = (m,E,loDeg,hiDeg)->(
           T := tateResolution(m,E,loDeg,hiDeg);
           k := length T;
           d := k-hiDeg+loDeg;
           if d > 0 then 
              chainComplex apply(d+1 .. k, i->T.dd_(i))
           else T);
i17 : S=ZZ/32003[x_0..x_3];
i18 : E=ZZ/32003[e_0..e_3,SkewCommutative=>true];
i19 : m=koszul(3,vars S);

              6       4
o19 : Matrix S  <--- S
i20 : regularity coker m

o20 = 2
i21 : betti tateResolution(m,E,-6,2)

o21 = total: 45 20 6 1 4 15 36 70 120 189 280
         -4: 45 20 6 . .  .  .  .   .   .   .
         -3:  .  . . 1 .  .  .  .   .   .   .
         -2:  .  . . . .  .  .  .   .   .   .
         -1:  .  . . . 4 15 36 70 120 189 280
i22 : betti sheafCohomology(m,E,-6,2)

o22 = total: 6 1 4 15 36 70 120 189 280
         -2: 6 . .  .  .  .   .   .   .
         -1: . 1 .  .  .  .   .   .   .
          0: . . .  .  .  .   .   .   .
          1: . . 4 15 36 70 120 189 280
i23 : M=sheaf coker m;
i24 : HH^1(M(>=0))

o24 = cokernel | x_3 x_2 x_1 x_0 |

                             1
o24 : S-module, quotient of S
i25 : S = ZZ/32003[x_0..x_2];
i26 : U = coker koszul(3,vars S) ** S^{1};
i27 : k2 = koszul(2,vars S)

o27 = {1} | -x_1 -x_2 0    |
      {1} | x_0  0    -x_2 |
      {1} | 0    x_0  x_1  |

              3       3
o27 : Matrix S  <--- S
i28 : alpha = map(U ++ U, S^{-1}, transpose{{0,-1,0,1,0,0}});

o28 : Matrix
i29 : alphad = map(S^1, U ++ U, matrix{{0,1,0,0,0,1}} * (k2 ++ k2));

o29 : Matrix
i30 : F = prune homology(alphad, alpha);
i31 : betti  F

o31 = relations : total: 3 1
                      1: 2 .
                      2: 1 1
i32 : sortedBasis = (i,E) -> (
           m := basis(i,E);
           p := sortColumns(m,MonomialOrder=>Descending);
           m_p);
i33 : S=ZZ/32003[x_0..x_3];
i34 : E=ZZ/32003[e_0..e_3,SkewCommutative=>true];
i35 : koszul(2,vars S)

o35 = {1} | -x_1 -x_2 0    -x_3 0    0    |
      {1} | x_0  0    -x_2 0    -x_3 0    |
      {1} | 0    x_0  x_1  0    0    -x_3 |
      {1} | 0    0    0    x_0  x_1  x_2  |

              4       6
o35 : Matrix S  <--- S
i36 : sortedBasis(2,E)

o36 = | e_0e_1 e_0e_2 e_1e_2 e_0e_3 e_1e_3 e_2e_3 |

              1       6
o36 : Matrix E  <--- E
i37 : beilinson1=(e,dege,i,S)->(
           E := ring e;
           mi := if i < 0 or i >= numgens E then map(E^1, E^0, 0)
                 else if i === 0 then id_(E^1)
                 else sortedBasis(i+1,E);
           r := i - dege;
           mr := if r < 0 or r >= numgens E then map(E^1, E^0, 0)
                 else sortedBasis(r+1,E);
           s = numgens source mr;
           if i === 0 and r === 0 then
                substitute(map(E^1,E^1,{{e}}),S)
           else if i>0 and r === i then substitute(e*id_(E^s),S)
           else if i > 0 and r === 0 then
                (vars S) * substitute(contract(diff(e,mi),transpose mr),S)
           else substitute(contract(diff(e,mi), transpose mr),S));
i38 : beilinson1(e_1,1,3,S)

o38 = {-3} | 0 |
      {-3} | 0 |
      {-3} | 1 |
      {-3} | 0 |

              4       1
o38 : Matrix S  <--- S
i39 : beilinson1(e_1,1,2,S)

o39 = {-2} | 0  0  0 0 |
      {-2} | -1 0  0 0 |
      {-2} | 0  0  0 0 |
      {-2} | 0  -1 0 0 |
      {-2} | 0  0  0 0 |
      {-2} | 0  0  0 1 |

              6       4
o39 : Matrix S  <--- S
i40 : beilinson1(e_1,1,1,S)

o40 = | x_0 0 -x_2 0 -x_3 0 |

              1       6
o40 : Matrix S  <--- S
i41 : U = (i,S) -> (
           if i < 0 or i >= numgens S then S^0
           else if i === 0 then S^1
           else cokernel koszul(i+2,vars S) ** S^{i});
i42 : beilinson = (o,S) -> (
           coldegs := degrees source o;
           rowdegs := degrees target o;
           mats = table(numgens target o, numgens source o,
                    (r,c) -> (
                         rdeg = first rowdegs#r;
                         cdeg = first coldegs#c;
                         overS = beilinson1(o_(r,c),cdeg-rdeg,cdeg,S);
                         -- overS = substitute(overE,S);
                         map(U(rdeg,S),U(cdeg,S),overS)));
           if #mats === 0 then matrix(S,{{}})
           else matrix(mats));
i43 : S=ZZ/32003[x_0..x_2];
i44 : E = ZZ/32003[e_0..e_2,SkewCommutative=>true];
i45 : alphad = map(E^1,E^{-1,-1},{{e_1,e_2}})

o45 = | e_1 e_2 |

              1       2
o45 : Matrix E  <--- E
i46 : alpha = map(E^{-1,-1},E^{-2},{{e_1},{e_2}})

o46 = {1} | e_1 |
      {1} | e_2 |

              2       1
o46 : Matrix E  <--- E
i47 : alphad=beilinson(alphad,S);

o47 : Matrix
i48 : alpha=beilinson(alpha,S);

o48 : Matrix
i49 : F = prune homology(alphad,alpha);
i50 : betti  F

o50 = relations : total: 3 1
                      1: 2 .
                      2: 1 1
i51 : S = ZZ/32003[x_0..x_4];
i52 : E = ZZ/32003[e_0..e_4,SkewCommutative=>true];
i53 : beta=map(E^1,E^{-2,-1},{{e_0*e_2+e_1*e_3,-e_4}})

o53 = | e_0e_2+e_1e_3 -e_4 |

              1       2
o53 : Matrix E  <--- E
i54 : alpha=map(E^{-2,-1},E^{-3},{{e_4},{e_0*e_2+e_1*e_3}})

o54 = {2} | e_4           |
      {1} | e_0e_2+e_1e_3 |

              2       1
o54 : Matrix E  <--- E
i55 : beta=beilinson(beta,S);

o55 : Matrix
i56 : alpha=beilinson(alpha,S);

o56 : Matrix
i57 : G = prune homology(beta,alpha);
i58 : betti res G

o58 = total: 10 9 5 1
          1: 10 4 1 .
          2:  . 5 4 1
i59 : foursect = random(S^4, S^10) * presentation G;

              4       9
o59 : Matrix S  <--- S
i60 : IX = trim minors(4,foursect);

o60 : Ideal of S
i61 : codim IX

o61 = 2
i62 : degree IX

o62 = 8
i63 : codim singularLocus IX

o63 = 5
i64 : alphad = matrix{{e_4*e_1, e_2*e_3},{e_0*e_2, e_3*e_4},
                      {e_1*e_3, e_4*e_0},{e_2*e_4, e_0*e_1},
                      {e_3*e_0, e_1*e_2}};

              5       2
o64 : Matrix E  <--- E
i65 : alphad=map(E^5,E^{-2,-2},alphad)

o65 = | -e_1e_4 e_2e_3  |
      | e_0e_2  e_3e_4  |
      | e_1e_3  -e_0e_4 |
      | e_2e_4  e_0e_1  |
      | -e_0e_3 e_1e_2  |

              5       2
o65 : Matrix E  <--- E
i66 : alpha=syz alphad

o66 = {2} | e_2e_3 e_0e_4 e_1e_2 -e_3e_4 e_0e_1  |
      {2} | e_1e_4 e_1e_3 e_0e_3 e_0e_2  -e_2e_4 |

              2       5
o66 : Matrix E  <--- E
i67 : alphad=beilinson(alphad,S);

o67 : Matrix
i68 : alpha=beilinson(alpha,S);

o68 : Matrix
i69 : FHM = prune homology(alphad,alpha);
i70 : betti res FHM

o70 = total: 19 35 20 2
          3:  4  .  . .
          4: 15 35 20 .
          5:  .  .  . 2
i71 : regularity FHM

o71 = 5
i72 : betti sheafCohomology(presentation FHM,E,-6,6)

o72 = total: 210 100 37 14 10 5 2 5 10 14 37 100 210
         -6: 210 100 35  4  . . . .  .  .  .   .   .
         -5:   .   .  2 10 10 5 . .  .  .  .   .   .
         -4:   .   .  .  .  . . 2 .  .  .  .   .   .
         -3:   .   .  .  .  . . . 5 10 10  2   .   .
         -2:   .   .  .  .  . . . .  .  4 35 100 210
i73 : sect =  map(S^1,S^15,0) | random(S^1, S^4);

              1       19
o73 : Matrix S  <--- S
i74 : mapcone = sect || transpose presentation FHM;

              36       19
o74 : Matrix S   <--- S
i75 : fmapcone = res coker mapcone;
i76 : IX =  trim ideal fmapcone.dd_2;

o76 : Ideal of S
i77 : codim IX

o77 = 2
i78 : degree IX

o78 = 10
i79 : codim singularLocus IX

o79 = 5
i80 : 