wildart / ComputationalHomology.jl

This package provides various computational homology tools for cellular complexes.
Other
12 stars 3 forks source link

Support for Galois fields #1

Open piever opened 5 years ago

piever commented 5 years ago

Thanks for this nice package! I wanted to ask whether there are plans to support coefficients in a finite field (using for example https://github.com/tkluck/GaloisFields.jl). Otherwise it would be helpful to know what interface a number type needs to respect for things to just work.

wildart commented 5 years ago

I tried to design this packages to be agnostic to a coefficient types. Mainly, simplicies and chains can have any coefficient types which support: zero,one, +, -, *. I'll try to cook up an example with GaloisFields.jl.

wildart commented 5 years ago

So after some hacking I got the following:

julia> cplx = SimplicialComplex(Simplex(1,2,3)) SimplicialComplex((3, 3, 1))

julia> cells(cplx, 0) # all 0-simplexes 3-element Array{Simplex{Int64},1}: "σ1[2]" "σ2[3]" "σ3[1]"

julia> cplx[2,1] # second 1-simplex in the complex "σ2[2, 1]"

- Define PID
```julia
julia> using GaloisFields

julia> F = @GaloisField 29
𝔽₂₉

julia> boundary(cplx, 2, 1, Int) 1[3] + -1[1]

Calculation of homology group is a bit tricky. I hacked some additional functions in order to Smith decomposition to work
```julia
# a quotient function needed, for Smith decomposition (division does not work well with integers) 
Base.div(a::F, b::F) where F <: GaloisFields.AbstractGaloisField = a/b
# comparison
Base.isless(a::F, b::F) where F <: GaloisFields.AbstractGaloisField = a.n < b.n
# and maxumum type value
Base.typemax(::Type{F}) where F <: GaloisFields.AbstractGaloisField = char(F)-1

after that

julia> h = homology(cplx, F)
Homology(𝔽₂₉)[SimplicialComplex((3, 3, 1))]

julia> group(h,0)[1] # β₀
1