From ac3d7f097775a391040a97478e90a9a6e1eba133 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Mon, 24 May 2021 15:35:28 +0200 Subject: [PATCH] implement and test GroupsCore interface for FreeGroup and FPGroup --- Project.toml | 1 + src/new_types.jl | 10 +++++++++- test/fp_groups.jl | 5 +++++ test/free_groups.jl | 5 +++++ test/runtests.jl | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 69c1ad6..e8a0767 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120" KnuthBendix = "c2604015-7b3d-4a30-8a26-9074551ec60a" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d" [compat] diff --git a/src/new_types.jl b/src/new_types.jl index 903bfe3..b5e3590 100644 --- a/src/new_types.jl +++ b/src/new_types.jl @@ -61,6 +61,8 @@ function Base.rand(rng::Random.AbstractRNG, rs::Random.SamplerTrivial{<:Abstract return FPGroupElement(word_type(G)(rand(1:nletters, l)), G) end +Base.isfinite(::AbstractFPGroup) = (@warn "using generic isfinite(::AbstractFPGroup): the returned `false` might be wrong"; false) + ## FPGroupElement mutable struct FPGroupElement{G<:AbstractFPGroup,W<:AbstractWord} <: GroupElement @@ -109,7 +111,7 @@ function Base.:(*)(g::FPGroupElement, h::FPGroupElement) return FPGroupElement(word(g) * word(h), parent(g)) end -GroupsCore.isfiniteorder(g::FPGroupElement) = isone(g) ? true : throw("Not Implemented") +GroupsCore.isfiniteorder(g::FPGroupElement) = isone(g) ? true : (@warn "using generic isfiniteorder(::FPGroupElement): the returned `false` might be wrong"; false) # additional methods: Base.isone(g::FPGroupElement) = (normalform!(g); isempty(word(g))) @@ -138,6 +140,12 @@ Base.show(io::IO, F::FreeGroup) = print(io, "free group on $(ngens(F)) generator KnuthBendix.alphabet(F::FreeGroup) = F.alphabet relations(F::FreeGroup) = Pair{eltype(F)}[] +# GroupsCore interface: +# these are mathematically correct +Base.isfinite(::FreeGroup) = false + +GroupsCore.isfiniteorder(g::FPGroupElement{<:FreeGroup}) = isone(g) ? true : false + ## FP Groups struct FPGroup{T,R,S} <: AbstractFPGroup diff --git a/test/fp_groups.jl b/test/fp_groups.jl index 3e7d37e..19fc9f4 100644 --- a/test/fp_groups.jl +++ b/test/fp_groups.jl @@ -41,4 +41,9 @@ New.normalform!(h) @test h == H([5]) + @testset "GroupsCore conformance: H" begin + test_Group_interface(H) + test_GroupElement_interface(rand(H, 2)...) + end + end diff --git a/test/free_groups.jl b/test/free_groups.jl index 007292e..5b85c4c 100644 --- a/test/free_groups.jl +++ b/test/free_groups.jl @@ -62,4 +62,9 @@ @test New.word(last(E8)) == Word([6])^8 end + @testset "GroupsCore conformance" begin + test_Group_interface(F3) + test_GroupElement_interface(rand(F3, 2)...) + end + end diff --git a/test/runtests.jl b/test/runtests.jl index 212c369..21e9a9d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -28,6 +28,9 @@ using LinearAlgebra using Groups.New using KnuthBendix + using GroupsCore + include(joinpath(pathof(GroupsCore), "..", "..", "test", "conformance_test.jl")) + include("free_groups.jl") include("fp_groups.jl") end