Skip to content

Commit

Permalink
fixes tensor
Browse files Browse the repository at this point in the history
almost fixes sheafHom, check commented out portion
  • Loading branch information
johndcobb committed Jun 3, 2024
1 parent 99a4c96 commit 3586790
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 34 deletions.
7 changes: 4 additions & 3 deletions packages/Complexes/ChainComplex.m2
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ isWellDefined Complex := Boolean => C -> (
true
)

Complex _ ZZ := Module => (C,i) -> if C.module#?i then C.module#i else (ring C)^0
Complex _ ZZ := Module => (C,i) -> tryHooks((symbol _, Complex, ZZ), (C,i), (C,i) -> ( if C.module#?i then C.module#i else (ring C)^0))
Complex ^ ZZ := Module => (C,i) -> C_(-i)

length Complex := (C) -> (
Expand Down Expand Up @@ -816,7 +816,8 @@ homomorphism(ZZ, Matrix, Complex) := ComplexMap => (i, f, E) -> (
--------------------------------------------------------------------
-- Tensor products -------------------------------------------------
--------------------------------------------------------------------
tensor(Complex, Complex) := Complex => {} >> opts -> (C, D) -> (

tensor(Complex, Complex) := Complex => {} >> opts -> (C, D) -> tryHooks((tensor, Complex, Complex), (opts,C,D), (opts, C, D) -> (
Y := youngest(C,D);
if Y.cache#?(tensor,C,D) then return Y.cache#(tensor,C,D);
R := ring C;
Expand Down Expand Up @@ -856,7 +857,7 @@ tensor(Complex, Complex) := Complex => {} >> opts -> (C, D) -> (
result.cache.tensor = (C,D);
Y.cache#(tensor,C,D) = result;
result
)
))
Complex ** Complex := Complex => (C,D) -> tensor(C,D)
Module ** Complex := Complex => (M,D) -> (complex M) ** D
Complex ** Module := Complex => (C,N) -> C ** (complex N)
Expand Down
127 changes: 96 additions & 31 deletions packages/Varieties/SheafComplexes.m2
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,108 @@ addHook((complex, List), Strategy => "sheaves", (opts, L) -> (
mapHash := hashTable for i from 0 to #L-1 list opts.Base+i+1 => L#i;
complex(mapHash, opts)))

--addHook((symbol _, Complex, ZZ), Strategy => "sheaves", (C,i) -> (
-- (lo,hi) := concentration C;
-- if not instance(C_lo,CoherentSheaf) then return null;
-- if C.module#?i then C.module#i else sheaf (ring C)^0)
--)

addHook((tensor, Complex, Complex), Strategy => "sheaves", (opts, C, D) -> (
Y := youngest(C,D);
if Y.cache#?(tensor,C,D) then return Y.cache#(tensor,C,D);
R := ring C;
if ring D =!= R then error "expected complexes over the same ring";
(loC,hiC) := C.concentration;
if not instance(C_loC,CoherentSheaf) then return null;
(loD,hiD) := D.concentration;
modules := hashTable for i from loC+loD to hiC+hiD list i => (
directSum for j from loC to hiC list (
if i-j >= loD and i-j <= hiD then
{j,i-j} => C_j ** D_(i-j)
else
continue
)
);
if loC === hiC and loD === hiD then (
result := complex(modules#(loC+loD), Base => loC+loD);
result.cache.tensor = (C,D);
Y.cache#(tensor,C,D) = result;
return result;
);
maps := hashTable for i from loC+loD+1 to hiC+hiD list i => (
map(modules#(i-1),
modules#i,
matrix table(
indices modules#(i-1),
indices modules#i,
(j,k) -> (
tar := component(modules#(i-1), j);
src := component(modules#i, k);
m := map(tar, src,
if k-j === {0,1} then (-1)^(k#0) * (C_(k#0) ** dd^D_(k#1))
else if k-j === {1,0} then (dd^C_(k#0) ** D_(k#1))
else 0);
matrix m
))));
result = complex maps;
result.cache.tensor = (C,D);
Y.cache#(tensor,C,D) = result;
result
))

sheaf Complex := Complex => C -> (
(lo,hi) := concentration C;
complex for i from lo+1 to hi list sheaf C.dd_i
)

-*
map(Complex, Complex, HashTable) := ComplexMap => opts -> (tar, src, maps) -> (
R := ring tar;
if ring src =!= R or any(values maps, f -> ring f =!= R) then
error "expected source, target and maps to be over the same ring";
deg := if opts.Degree === null
then 0
else if instance(opts.Degree, ZZ) then
opts.Degree
else
error "expected integer degree";
(lo,hi) := src.concentration;
maps' := hashTable for k in keys maps list (
if not instance(k, ZZ) then error "expected integer keys";
f := maps#k;
-- note: we use != instead of =!= in the next 2 tests,
-- since we want to ignore any term order differences
if source f != src_k then
error ("map with index "|k|" has inconsistent source");
if target f != tar_(k+deg) then
error ("map with index "|k|" has inconsistent target");
if k < lo or k > hi then continue else (k,f)

sheafHom(Complex, Complex) := Complex => opts -> (C,D) -> (
-- signs here are based from Christensen and Foxby
-- which agrees with Conrad (Grothendieck duality book)
Y := youngest(C,D);
if Y.cache#?(sheafHom,C,D) then return Y.cache#(sheafHom,C,D);
R := ring C;
if ring D =!= R then error "expected complexes over the same ring";
(loC,hiC) := C.concentration;
(loD,hiD) := D.concentration;
modules := hashTable for i from loD-hiC to hiD-loC list i => (
directSum for j from loC to hiC list {j,j+i} => sheafHom(C_j, D_(j+i), opts)
);
if loC === hiC and loD === hiD then (
result := complex(modules#(loD-hiC), Base => loD-loC);
result.cache.homomorphism = (C,D); -- source first, then target
Y.cache#(sheafHom,C,D) = result;
return result;
);
new ComplexMap from {
symbol source => src,
symbol target => tar,
symbol degree => deg,
symbol map => maps',
symbol cache => new CacheTable
}
maps := hashTable for i from loD-hiC+1 to hiD-loC list i => (
map(modules#(i-1),
modules#i,
matrix table(
indices modules#(i-1),
indices modules#i,
(j,k) -> (
tar := component(modules#(i-1), j);
src := component(modules#i, k);
m := map(tar, src,
if k-j === {0,1} then (-1)^(k#1-k#0+1) * sheafHom(C_(k#0), dd^D_(k#1), opts)
else if k-j === { -1,0 } then sheafHom(dd^C_(j#0), D_(k#1), opts)
else 0);
if instance(m, Matrix) then m else matrix m
))));
result = complex maps;
result.cache.homomorphism = (C,D); -- source first, then target
Y.cache#(sheafHom,C,D) = result;
result
)
*-



sheafHom(CoherentSheaf, Complex) := Complex => opts -> (M,C) -> sheafHom(complex M, C, opts)
sheafHom(Complex, CoherentSheaf) := Complex => opts -> (C,M) -> sheafHom(C, complex M, opts)
sheafHom(Complex, SheafOfRings) := Complex => opts -> (C,R) -> sheafHom(C, complex R, opts)
sheafHom(SheafOfRings, Complex) := Complex => opts -> (R,C) -> sheafHom(complex R, C, opts)

sheafDual = method();
sheafDual Complex := Complex => (C) -> sheafHom(C, sheaf (ring C)^1)

end--

Expand Down
2 changes: 2 additions & 0 deletions packages/Varieties/SheafMaps.m2
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ map(CoherentSheaf, CoherentSheaf, Matrix, InfiniteNumber) := SheafMap => opts ->
if d === -infinity then map(G, F, phi) else error "unexpected degree for map of sheaves")
-- TODO: support map(F, F, 1) and map(F, G, 0) for identity and zero maps
map(CoherentSheaf, CoherentSheaf, ZZ) := SheafMap => opts -> (G,F,n) -> sheaf map(module G, module F, 0)
map(CoherentSheaf, CoherentSheaf, SheafMap) := SheafMap => opts -> (G,F,phi) -> sheaf map(G,F,matrix phi)

sheaf SheafMap := SheafMap => phi -> sheaf matrix phi
sheaf Matrix := SheafMap => phi -> sheaf(variety ring phi, phi)
sheaf(Matrix, ZZ) := SheafMap => (phi, d) -> sheaf(variety ring phi, phi, d)
sheaf(Variety, Matrix) := SheafMap => (X, phi) -> map(sheaf_X target phi, sheaf_X source phi, phi)
Expand Down

0 comments on commit 3586790

Please sign in to comment.