-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache betti numbers of normal toric varieties
Change name of method: ith_betti_number -> betti_number
- Loading branch information
1 parent
3470ef4
commit 0113ddb
Showing
3 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters