Skip to content

Commit

Permalink
adds fix to return non reduced (co)homology (#3372)
Browse files Browse the repository at this point in the history
* adds fix to return non reduced (co)homology

* changes for better code readability
  • Loading branch information
antonydellavecchia authored Feb 16, 2024
1 parent 82f6440 commit af59f73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions src/Combinatorics/SimplicialComplexes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ function vertexindices(K::SimplicialComplex)
end
end

function _convert_finitely_generated_abelian_group(A::Polymake.HomologyGroupAllocated{Polymake.Integer})
vec = zeros(Int, Polymake.betti_number(A))
torsion_i = Polymake.torsion(A)
for (p,k) in torsion_i
append!(vec, fill(p,k))
end
return abelian_group(vec)
function _convert_finitely_generated_abelian_group(A::Polymake.Array{Polymake.HomologyGroup{Polymake.Integer}},
h_index::Int)
# we return non-reduced homology and cohomology
B = A[h_index + 1] # index shift
betti_number = is_zero(h_index) ? Polymake.betti_number(B) + 1 : Polymake.betti_number(B)
vec = zeros(Int, betti_number)
torsion_i = Polymake.torsion(B)
for (p,k) in torsion_i
append!(vec, fill(p,k))
end
return abelian_group(vec)
end

################################################################################
Expand Down Expand Up @@ -199,24 +203,23 @@ euler_characteristic(K::SimplicialComplex) = pm_object(K).EULER_CHARACTERISTIC::
@doc raw"""
homology(K::SimplicialComplex, i::Int)
Return `i`-th reduced integral homology group of `K`.
Recall that the 0-th homology group is trivial if and only if `K` is connected.
Return `i`-th integral homology group of `K`.
# Examples
```jldoctest
julia> [ homology(real_projective_plane(), i) for i in [0,1,2] ]
3-element Vector{FinGenAbGroup}:
Z/1
Z
Z/2
Z/1
```
"""
homology(K::SimplicialComplex, i::Int) = _convert_finitely_generated_abelian_group(pm_object(K).HOMOLOGY[i+1]) # index shift
homology(K::SimplicialComplex, i::Int) = _convert_finitely_generated_abelian_group(pm_object(K).HOMOLOGY, i)

@doc raw"""
cohomology(K::SimplicialComplex, i::Int)
Return `i`-th reduced integral cohomology group of `K`.
Return `i`-th integral cohomology group of `K`.
# Examples
```jldoctest
Expand All @@ -226,7 +229,7 @@ julia> cohomology(K,1)
Z
```
"""
cohomology(K::SimplicialComplex, i::Int) = _convert_finitely_generated_abelian_group(pm_object(K).COHOMOLOGY[i+1]) # index shift
cohomology(K::SimplicialComplex, i::Int) = _convert_finitely_generated_abelian_group(pm_object(K).COHOMOLOGY, i)

@doc raw"""
minimal_nonfaces(K::SimplicialComplex)
Expand Down
4 changes: 2 additions & 2 deletions test/Combinatorics/SimplicialComplexes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
H0 = homology(T, 0)
H1 = homology(T, 1)
H2 = homology(T, 2)
@test is_trivial(H0)
@test !is_trivial(H0)
@test !is_trivial(H1)
@test !is_trivial(H2)
@test rank(H0) == 0
@test rank(H0) == 1
@test rank(H1) == 2
@test rank(H2) == 1
end
Expand Down

0 comments on commit af59f73

Please sign in to comment.