Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 95 additions & 97 deletions src/Modules/ModulesGraded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@
step, min, maxv = b.reverse_direction ? (-1, maximum(first, x), minimum(first, x)) : (1, minimum(first, x), maximum(first, x))
column_widths = Dict()
for j in min:step:maxv
sum_col = sum(getindex(T, x[m]) for m in 1:length(x) if x[m][1] == j)
sum_col = sum(T[y] for y in x if y[1] == j)
col_width_from_sum = ndigits(abs(sum_col))
col_width_from_header = ndigits(abs(j))# + (j < 0 ? 1 : 0)
column_widths[j] = max(col_width_from_sum, col_width_from_header) + 2
Expand All @@ -1539,9 +1539,7 @@
ngens(parent(x[1][2])) > 1 && println(io, "Betti Table for component ", i)

# figure out width of first column
L = sort(unique!(collect(x[k][2][i] for k in 1:length(x))))
mi = minimum(L)
mx = maximum(L)
mi, mx = extrema(y[2][i] for y in x)
# 6 = length(degree); we take length of mi into account in case it is negative
first_column_width = max(6, ndigits(mi), ndigits(mx))

Expand All @@ -1565,7 +1563,7 @@
for j in mi:mx
print(io, lpad(j, first_column_width), ":")
for h in min:step:maxv
sum_current = sum([getindex(T, x[k]) for k in 1:length(x) if x[k][1] == h && x[k][2][i] == j])
sum_current = sum([T[y] for y in x if y[1] == h && y[2][i] == j])
@assert column_widths[h] - ndigits(sum_current) >= 2
print(io, " "^(column_widths[h] - ndigits(sum_current) - 2))
print(io, " ", sum_current == 0 ? "-" : sum_current)
Expand All @@ -1580,7 +1578,7 @@
# footer row
print(io, lpad("total", first_column_width), ":")
for i_total in min:step:maxv
sum_row = sum(getindex(T, x[j]) for j in 1:length(x) if x[j][1] == i_total)
sum_row = sum(T[y] for y in x if y[1] == i_total)
print(io, " ", sum_row)
if i_total != maxv
print(io, " "^(column_widths[i_total] - ndigits(sum_row)-1))
Expand Down Expand Up @@ -1608,10 +1606,10 @@
print(io, L1[k], " " ^ (s2 - ndigits(L1[k]) + (5 - s2)), ": ")
for h in min:step:max
partial_sum = 0
for i in 1:length(x)
current_sum = (coordinates(b.project) * transpose(coordinates(x[i][2])))[1]
if current_sum == L1[k] && x[i][1] == h
partial_sum += getindex(T, x[i])
for y in x
current_sum = (coordinates(b.project) * transpose(coordinates(y[2])))[1]
if current_sum == L1[k] && y[1] == h
partial_sum += T[y]

Check warning on line 1612 in src/Modules/ModulesGraded.jl

View check run for this annotation

Codecov / codecov/patch

src/Modules/ModulesGraded.jl#L1609-L1612

Added lines #L1609 - L1612 were not covered by tests
end
end
if partial_sum == 0
Expand All @@ -1627,9 +1625,9 @@
print(io, "\n", "total: ")
for i in min:step:max
total_sum = 0
for j in 1:length(x)
if x[j][1] == i
total_sum += getindex(T, x[j])
for y in x
if y[1] == i
total_sum += T[y]

Check warning on line 1630 in src/Modules/ModulesGraded.jl

View check run for this annotation

Codecov / codecov/patch

src/Modules/ModulesGraded.jl#L1628-L1630

Added lines #L1628 - L1630 were not covered by tests
end
end
print(io, total_sum, " " ^ (spaces - ndigits(total_sum) + 1))
Expand All @@ -1645,21 +1643,23 @@
# https://www.singular.uni-kl.de/Manual/4-3-1/sing_1827.htm#SEC1908
###############################################################################

mutable struct sheafCohTable
mutable struct SheafCohTable
twist_range::UnitRange{Int}
values::Matrix{Int}
end

function Base.getindex(st::sheafCohTable, ind...)
function Base.getindex(st::SheafCohTable, ind...)
row_ind = size(st.values, 1) - ind[1]
col_ind = ind[2] - first(st.twist_range) + 1
return st.values[row_ind, col_ind]
end

function Base.show(io::IO, table::sheafCohTable)
function Base.show(io::IO, table::SheafCohTable)
chi = [any(==(-1), col) ? -1 : sum(col) for col in eachcol(table.values)]
# pad every value in the table to this length
val_space_length = max(maximum(_ndigits, table.values), maximum(_ndigits, chi))
val_space_length = max(maximum(_ndigits, table.values), maximum(_ndigits, chi)) + 1
# consider table.twist_range as well
# handle sign!
nrows = size(table.values, 1)

# rows to print
Expand All @@ -1668,18 +1668,19 @@
chi_print = [_shcoh_string_rep(v, val_space_length) for v in chi]

# row labels
row_label_length = max(_ndigits(nrows - 1), 3) + 3
row_label_length = max(ndigits(nrows - 1), 5) + 1
for i in 1:nrows
pushfirst!(print_rows[i], rpad("$(nrows-i): ", row_label_length, " "))
pushfirst!(print_rows[i], lpad("$(nrows-i):", row_label_length, " "))
end
pushfirst!(chi_print, rpad("chi: ", row_label_length, " "))
pushfirst!(chi_print, lpad("chi:", row_label_length, " "))

# header
header = [lpad(v, val_space_length, " ") for v in table.twist_range]
pushfirst!(header, rpad("twist:", row_label_length, " "))
pushfirst!(header, lpad("twist:", row_label_length, " "))

println(io, header...)
size_row = sum(length, first(print_rows))

println(io, header...)
println(io, repeat("-", size_row))
for rw in print_rows
println(io, rw...)
Expand Down Expand Up @@ -1728,14 +1729,14 @@
julia> M = cokernel(map(FI, 2));

julia> tbl = sheaf_cohomology(M, -6, 2)
twist: -6 -5 -4 -3 -2 -1 0 1 2
------------------------------------------
3: 70 36 15 4 - - - - *
2: * - - - - - - - -
1: * * - - - - 1 - -
0: * * * - - - - - 6
------------------------------------------
chi: * * * 4 - - 1 - *
twist: -6 -5 -4 -3 -2 -1 0 1 2
---------------------------------
3: 70 36 15 4 - - - - *
2: * - - - - - - - -
1: * * - - - - 1 - -
0: * * * - - - - - 6
---------------------------------
chi: * * * 4 - - 1 - *

julia> tbl[0, 2]
6
Expand All @@ -1744,33 +1745,31 @@
1

julia> sheaf_cohomology(M, -9, 5)
twist: -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5
---------------------------------------------------------------------------------
3: 280 189 120 70 36 15 4 - - - - - * * *
2: * - - - - - - - - - - - - * *
1: * * - - - - - - - 1 - - - - *
0: * * * - - - - - - - - 6 20 45 84
---------------------------------------------------------------------------------
chi: * * * 70 36 15 4 - - 1 - 6 * * *
```
twist: -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5
------------------------------------------------------------------
3: 280 189 120 70 36 15 4 - - - - - * * *
2: * - - - - - - - - - - - - * *
1: * * - - - - - - - 1 - - - - *
0: * * * - - - - - - - - 6 20 45 84
------------------------------------------------------------------
chi: * * * 70 36 15 4 - - 1 - 6 * * *

```jldoctest
julia> R, x = polynomial_ring(QQ, :x => 1:5);

julia> S, _ = grade(R);

julia> F = graded_free_module(S, 1);

julia> sheaf_cohomology(F, -8, 3, algorithm = :loccoh)
twist: -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3
------------------------------------------------------
4: 35 15 5 1 - - - - - - - -
3: - - - - - - - - - - - -
2: - - - - - - - - - - - -
1: - - - - - - - - - - - -
0: - - - - - - - - 1 5 15 35
------------------------------------------------------
chi: 35 15 5 1 - - - - 1 5 15 35
twist: -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3
------------------------------------------
4: 35 15 5 1 - - - - - - - -
3: - - - - - - - - - - - -
2: - - - - - - - - - - - -
1: - - - - - - - - - - - -
0: - - - - - - - - 1 5 15 35
------------------------------------------
chi: 35 15 5 1 - - - - 1 5 15 35
```
"""
function sheaf_cohomology(M::ModuleFP{T},
Expand Down Expand Up @@ -1806,26 +1805,26 @@
julia> F = graded_free_module(R, 1);

julia> Oscar._sheaf_cohomology_bgg(F, -7, 2)
twist: -7 -6 -5 -4 -3 -2 -1 0 1 2
----------------------------------------------
4: 15 5 1 - - - * * * *
3: * - - - - - - * * *
2: * * - - - - - - * *
1: * * * - - - - - - *
0: * * * * - - - 1 5 15
----------------------------------------------
chi: * * * * - - * * * *
twist: -7 -6 -5 -4 -3 -2 -1 0 1 2
------------------------------------
4: 15 5 1 - - - * * * *
3: * - - - - - - * * *
2: * * - - - - - - * *
1: * * * - - - - - - *
0: * * * * - - - 1 5 15
------------------------------------
chi: * * * * - - * * * *

julia> sheaf_cohomology(F, -11, 6)
twist: -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6
------------------------------------------------------------------------------------------------
4: 210 126 70 35 15 5 1 - - - - - - - * * * *
3: * - - - - - - - - - - - - - - * * *
2: * * - - - - - - - - - - - - - - * *
1: * * * - - - - - - - - - - - - - - *
0: * * * * - - - - - - - 1 5 15 35 70 126 210
------------------------------------------------------------------------------------------------
chi: * * * * 15 5 1 - - - - 1 5 15 * * * *
twist: -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6
------------------------------------------------------------------------------
4: 210 126 70 35 15 5 1 - - - - - - - * * * *
3: * - - - - - - - - - - - - - - * * *
2: * * - - - - - - - - - - - - - - * *
1: * * * - - - - - - - - - - - - - - *
0: * * * * - - - - - - - 1 5 15 35 70 126 210
------------------------------------------------------------------------------
chi: * * * * 15 5 1 - - - - 1 5 15 * * * *
```

```jldoctest
Expand All @@ -1848,14 +1847,14 @@
julia> M = cokernel(map(FI, 2));

julia> tbl = sheaf_cohomology(M, -6, 2, algorithm = :loccoh)
twist: -6 -5 -4 -3 -2 -1 0 1 2
------------------------------------------
3: 70 36 15 4 - - - - -
2: - - - - - - - - -
1: - - - - - - 1 - -
0: - - - - - - - - 6
------------------------------------------
chi: 70 36 15 4 - - 1 - 6
twist: -6 -5 -4 -3 -2 -1 0 1 2
---------------------------------
3: 70 36 15 4 - - - - -
2: - - - - - - - - -
1: - - - - - - 1 - -
0: - - - - - - - - 6
---------------------------------
chi: 70 36 15 4 - - 1 - 6

julia> tbl[3, -6]
70
Expand All @@ -1874,7 +1873,7 @@
values = Singular.LibSheafcoh.sheafCohBGGregul_w(sing_mod,
l, h, reg,
weights)
return sheafCohTable(l:h, values)
return SheafCohTable(l:h, values)
end

@doc raw"""
Expand Down Expand Up @@ -1909,14 +1908,14 @@
julia> M = cokernel(map(FI, 2));

julia> tbl = Oscar._sheaf_cohomology_loccoh(M, -6, 2)
twist: -6 -5 -4 -3 -2 -1 0 1 2
------------------------------------------
3: 70 36 15 4 - - - - -
2: - - - - - - - - -
1: - - - - - - 1 - -
0: - - - - - - - - 6
------------------------------------------
chi: 70 36 15 4 - - 1 - 6
twist: -6 -5 -4 -3 -2 -1 0 1 2
---------------------------------
3: 70 36 15 4 - - - - -
2: - - - - - - - - -
1: - - - - - - 1 - -
0: - - - - - - - - 6
---------------------------------
chi: 70 36 15 4 - - 1 - 6

julia> tbl[3, -6]
70
Expand All @@ -1931,15 +1930,15 @@
julia> F = graded_free_module(R, 1);

julia> Oscar._sheaf_cohomology_loccoh(F, -7, 2)
twist: -7 -6 -5 -4 -3 -2 -1 0 1 2
----------------------------------------------
4: 15 5 1 - - - - - - -
3: - - - - - - - - - -
2: - - - - - - - - - -
1: - - - - - - - - - -
0: - - - - - - - 1 5 15
----------------------------------------------
chi: 15 5 1 - - - - 1 5 15
twist: -7 -6 -5 -4 -3 -2 -1 0 1 2
------------------------------------
4: 15 5 1 - - - - - - -
3: - - - - - - - - - -
2: - - - - - - - - - -
1: - - - - - - - - - -
0: - - - - - - - 1 5 15
------------------------------------
chi: 15 5 1 - - - - 1 5 15
```
"""
function _sheaf_cohomology_loccoh(M::ModuleFP{T},
Expand All @@ -1951,7 +1950,7 @@
values = Singular.LibSheafcoh.sheafCoh_w(sing_mod,
l, h,
weights)
return sheafCohTable(l:h, values)
return SheafCohTable(l:h, values)
end

# helper functions
Expand All @@ -1962,9 +1961,8 @@
end

function _ndigits(val::Int)
iszero(val) && return 3
val == -1 && return 3
return Int(floor(log10(val))) + 3
val == -1 && return 1 # is display as '*'
return ndigits(val)
end

function _weights_and_sing_mod(M::ModuleFP{T}) where {T <: MPolyDecRingElem}
Expand Down
36 changes: 18 additions & 18 deletions test/book/cornerstones/algebraic-geometry/char3-surface-2.jlcon
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ julia> degree(I)
julia> MI = ideal_as_module(I);

julia> sheaf_cohomology(MI, -2, 8, algorithm = :loccoh)
twist: -2 -1 0 1 2 3 4 5 6 7 8
-------------------------------------------------------------
4: - - - - - - - - - - -
3: 30 10 - - - - - - - - -
2: - - - 2 - - - - - - -
1: - - - - 1 5 5 - - - -
0: - - - - - - - 5 32 84 170
-------------------------------------------------------------
chi: 30 10 - 2 1 5 5 5 32 84 170
twist: -2 -1 0 1 2 3 4 5 6 7 8
--------------------------------------------------
4: - - - - - - - - - - -
3: 30 10 - - - - - - - - -
2: - - - 2 - - - - - - -
1: - - - - 1 5 5 - - - -
0: - - - - - - - 5 32 84 170
--------------------------------------------------
chi: 30 10 - 2 1 5 5 5 32 84 170

julia> sheaf_cohomology(MI, -2, 8)
twist: -2 -1 0 1 2 3 4 5 6 7 8
-------------------------------------------------------------
4: - - - - - - - * * * *
3: * 10 - - - - - - * * *
2: * * - 2 - - - - - * *
1: * * * - 1 5 5 - - - *
0: * * * * - - - 5 32 84 170
-------------------------------------------------------------
chi: * * * * 1 5 5 * * * *
twist: -2 -1 0 1 2 3 4 5 6 7 8
--------------------------------------------------
4: - - - - - - - * * * *
3: * 10 - - - - - - * * *
2: * * - 2 - - - - - * *
1: * * * - 1 5 5 - - - *
0: * * * * - - - 5 32 84 170
--------------------------------------------------
chi: * * * * 1 5 5 * * * *
Loading