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
27 changes: 25 additions & 2 deletions src/Combinatorics/SimplicialComplexes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ julia> h_vector(torus())
h_vector(K::SimplicialComplex) = Vector{Int}(pm_object(K).H_VECTOR)

@doc raw"""
betti_numbers(K::SimplicialComplex)
betti_numbers([R::Union{<: Field, ZZRing}=ZZ,] K::SimplicialComplex)

Return the reduced rational Betti numbers of the abstract simplicial complex `K`.
Return the reduced Betti numbers of the abstract simplicial complex `K`.
Defaults to computing Betti numbers over `ZZ`, otherwise computes the Betti numbers over the ring `R`.

# Examples
```jldoctest
Expand All @@ -209,10 +210,32 @@ julia> betti_numbers(klein_bottle())
0
1
0

julia> betti_numbers(GF(2), klein_bottle())
3-element Vector{Int64}:
0
2
1
```
"""
betti_numbers(K::SimplicialComplex) = Vector{Int}(Polymake.topaz.betti_numbers(pm_object(K)))

function betti_numbers(R::Union{<:Field, ZZRing}, K::SimplicialComplex)
c = characteristic(R)
iszero(c) && return betti_numbers(K)
b = Int[]
boundary_m = matrix(R, Polymake.topaz.boundary_matrix(Oscar.pm_object(K), 0))
im_dim = 1
for k = 1:dim(K) + 1
ker_dim = size(boundary_m)[1] - im_dim
boundary_m = matrix(R, Polymake.topaz.boundary_matrix(Oscar.pm_object(K), k))
im_dim = rank(boundary_m)

push!(b, ker_dim - im_dim)
end
return b
end

@doc raw"""
euler_characteristic(K::SimplicialComplex)

Expand Down
1 change: 1 addition & 0 deletions test/Combinatorics/SimplicialComplexes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@test f_vector(sphere) == [4, 6, 4]
@test h_vector(sphere) == [1, 1, 1, 1]
@test betti_numbers(sphere) == [0, 0, 1]
@test betti_numbers(fpField(UInt(2)), real_projective_plane()) == [0, 1, 1]
@test euler_characteristic(sphere) == 1
@test minimal_nonfaces(sphere) == [Set{Int}([1, 2, 3, 4])]
R, _ = polynomial_ring(ZZ, [:a, :x, :i_7, :n])
Expand Down