Skip to content

Commit

Permalink
Cache betti numbers of normal toric varieties
Browse files Browse the repository at this point in the history
Change name of method: ith_betti_number -> betti_number
  • Loading branch information
HereAround committed Dec 23, 2021
1 parent 3470ef4 commit 0113ddb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/src/ToricVarieties/NormalToricVarieties.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ nef_cone(v::NormalToricVariety)
dim(v::AbstractNormalToricVariety)
dim_of_torusfactor(v::AbstractNormalToricVariety)
euler_characteristic(v::AbstractNormalToricVariety)
ith_betti_number(v::AbstractNormalToricVariety, i::Int)
betti_number(v::AbstractNormalToricVariety, i::Int)
```

### Rings and ideals
Expand Down
38 changes: 28 additions & 10 deletions src/ToricVarieties/NormalToricVarieties/methods.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
############################
# Dimensions
# Betti numbers
############################

@doc Markdown.doc"""
ith_betti_number(v::AbstractNormalToricVariety, i::Int)
betti_number(v::AbstractNormalToricVariety, i::Int)
Compute the i-th Betti number of the normal toric variety `v`.
"""
function ith_betti_number(v::AbstractNormalToricVariety, i::Int)
if isodd(i)
function betti_number(v::AbstractNormalToricVariety, i::Int)
# check input
if i > 2*dim(v) || i < 0
return 0
end
k = div(i, 2)
f_vector = Vector{Int}(pm_object(v).F_VECTOR)
pushfirst!(f_vector, 1)
betti_number = sum((-1)^(i-k) * binomial(i,k) * f_vector[dim(v) - i + 1] for i=k:dim(v))
return betti_number

# extract vector of currently-known Betti numbers (or create it if necessary)
if !has_attribute(v, :betti_number)
betti_numbers = fill(fmpz(-1),2*dim(v)+1)
else
betti_numbers = get_attribute(v, :betti_number)
end

# compute the Betti number if needed
if betti_numbers[i+1] == -1
if isodd(i)
betti_numbers[i+1] = fmpz(0)
else
k = div(i, 2)
f_vector = Vector{Int}(pm_object(v).F_VECTOR)
pushfirst!(f_vector, 1)
betti_numbers[i+1] = fmpz(sum((-1)^(i-k) * binomial(i,k) * f_vector[dim(v) - i + 1] for i=k:dim(v)))
end
set_attribute!(v, :betti_number, betti_numbers)
end

# return result
return get_attribute(v, :betti_number)[i+1]
end
export ith_betti_number
export betti_number
48 changes: 24 additions & 24 deletions test/ToricVarieties/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ P2 = toric_projective_space(2)
@test hastorusfactor(P2) == false
@test isorbifold(P2) == true
@test issimplicial(P2) == true
@test ith_betti_number(P2, 0) == 1
@test ith_betti_number(P2, 1) == 0
@test ith_betti_number(P2, 2) == 1
@test ith_betti_number(P2, 3) == 0
@test ith_betti_number(P2, 4) == 1
@test betti_number(P2, 0) == 1
@test betti_number(P2, 1) == 0
@test betti_number(P2, 2) == 1
@test betti_number(P2, 3) == 0
@test betti_number(P2, 4) == 1
S = cox_ring(P2)
@test ngens(S) == 3
@test length(stanley_reisner_ideal(P2).gens) == 1
Expand All @@ -93,11 +93,11 @@ H5 = hirzebruch_surface(5)
@test dim(H5) == 2
@test dim_of_torusfactor(H5) == 0
@test euler_characteristic(H5) == 4
@test ith_betti_number(H5, 0) == 1
@test ith_betti_number(H5, 1) == 0
@test ith_betti_number(H5, 2) == 2
@test ith_betti_number(H5, 3) == 0
@test ith_betti_number(H5, 4) == 1
@test betti_number(H5, 0) == 1
@test betti_number(H5, 1) == 0
@test betti_number(H5, 2) == 2
@test betti_number(H5, 3) == 0
@test betti_number(H5, 4) == 1
@test length(affine_open_covering(H5)) == 4
@test fan(H5).pm_fan.FAN_DIM == 2
@test rank(torusinvariant_divisor_group(H5)) == 4
Expand Down Expand Up @@ -139,11 +139,11 @@ blowup_variety = blowup_on_ith_minimal_torus_orbit(P2, 1)
@test hastorusfactor(blowup_variety) == false
@test isorbifold(blowup_variety) == true
@test issimplicial(blowup_variety) == true
@test ith_betti_number(blowup_variety, 0) == 1
@test ith_betti_number(blowup_variety, 1) == 0
@test ith_betti_number(blowup_variety, 2) == 2
@test ith_betti_number(blowup_variety, 3) == 0
@test ith_betti_number(blowup_variety, 4) == 1
@test betti_number(blowup_variety, 0) == 1
@test betti_number(blowup_variety, 1) == 0
@test betti_number(blowup_variety, 2) == 2
@test betti_number(blowup_variety, 3) == 0
@test betti_number(blowup_variety, 4) == 1
@test euler_characteristic(blowup_variety) == 4
@test rank(picard_group(blowup_variety)) == 2
end
Expand All @@ -159,15 +159,15 @@ v = H5 * P2
@test hastorusfactor(v) == false
@test isorbifold(v) == true
@test issimplicial(v) == true
@test ith_betti_number(v, 0) == 1
@test ith_betti_number(v, 1) == 0
@test ith_betti_number(v, 2) == 3
@test ith_betti_number(v, 3) == 0
@test ith_betti_number(v, 4) == 4
@test ith_betti_number(v, 5) == 0
@test ith_betti_number(v, 6) == 3
@test ith_betti_number(v, 7) == 0
@test ith_betti_number(v, 8) == 1
@test betti_number(v, 0) == 1
@test betti_number(v, 1) == 0
@test betti_number(v, 2) == 3
@test betti_number(v, 3) == 0
@test betti_number(v, 4) == 4
@test betti_number(v, 5) == 0
@test betti_number(v, 6) == 3
@test betti_number(v, 7) == 0
@test betti_number(v, 8) == 1
end

@testset "ComparisonWithProjectiveSpace" begin
Expand Down

0 comments on commit 0113ddb

Please sign in to comment.