diff --git a/src/Combinatorics/SimplicialComplexes.jl b/src/Combinatorics/SimplicialComplexes.jl index b5e8568b39c5..a169c5f1385f 100644 --- a/src/Combinatorics/SimplicialComplexes.jl +++ b/src/Combinatorics/SimplicialComplexes.jl @@ -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 @@ -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) diff --git a/test/Combinatorics/SimplicialComplexes.jl b/test/Combinatorics/SimplicialComplexes.jl index 1ec1f6d5d130..790750135cb0 100644 --- a/test/Combinatorics/SimplicialComplexes.jl +++ b/test/Combinatorics/SimplicialComplexes.jl @@ -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])