From 4bcd851031395347e1bfcd2bc5556b09e142dee2 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Fri, 15 Nov 2019 23:32:04 +0100 Subject: [PATCH] fix FPGroups and add basic tests --- src/FPGroups.jl | 11 ++++++----- test/FPGroup-tests.jl | 15 +++++++++++++++ test/runtests.jl | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 test/FPGroup-tests.jl diff --git a/src/FPGroups.jl b/src/FPGroups.jl index a1e4ee7..e7aeb84 100644 --- a/src/FPGroups.jl +++ b/src/FPGroups.jl @@ -42,6 +42,7 @@ elem_type(::FPGroup) = FPGroupElem FPSymbol(s::Symbol) = FPSymbol(s, 1) FPSymbol(s::String) = FPSymbol(Symbol(s)) +FPSymbol(s::GSymbol) = FPSymbol(s.id, s.pow) convert(::Type{FPSymbol}, s::FreeSymbol) = FPSymbol(s.id, s.pow) @@ -70,7 +71,7 @@ function (G::FPGroup)(w::GWord) end if eltype(w.symbols) == FreeSymbol - w = FPGroupElem(w.symbols) + w = FPGroupElem(FPSymbol.(w.symbols)) end if eltype(w.symbols) == FPSymbol @@ -169,8 +170,8 @@ function add_rels!(G::FPGroup, newrels::Dict{FPGroupElem,FPGroupElem}) end end -function /(G::FPGroup, newrels::Vector{FPGroupElem}) - for r in rels +function Base.:/(G::FPGroup, newrels::Vector{FPGroupElem}) + for r in newrels parent(r) == G || throw(DomainError( "Can not form quotient group: $r is not an element of $G")) end @@ -180,12 +181,12 @@ function /(G::FPGroup, newrels::Vector{FPGroupElem}) return H end -function /(G::FreeGroup, rels::Vector{FreeGroupElem}) +function Base.:/(G::FreeGroup, rels::Vector{FreeGroupElem}) for r in rels parent(r) == G || throw(DomainError( "Can not form quotient group: $r is not an element of $G")) end - H = FPGroup(G) + H = FPGroup(deepcopy(G)) H.rels = Dict(H(rel) => one(H) for rel in unique(rels)) return H end diff --git a/test/FPGroup-tests.jl b/test/FPGroup-tests.jl new file mode 100644 index 0000000..831b78e --- /dev/null +++ b/test/FPGroup-tests.jl @@ -0,0 +1,15 @@ +@testset "FPGroups definitions" begin + F = FreeGroup(["a", "b", "c"]) + a,b,c = gens(F) + R = [a^2, a*b*a, c*b*a] + @test F/R isa FPGroup + @test F isa FreeGroup + G = F/R + A,B,C = gens(G) + + @test A^2 == one(G) + @test A*B*A*A == A + @test A*A*B*A == B*A + + @test G/[B^2, C*B*C] isa FPGroup +end diff --git a/test/runtests.jl b/test/runtests.jl index 6f55d86..25241ff 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,4 +21,5 @@ using LinearAlgebra include("AutGroup-tests.jl") include("DirectPower-tests.jl") include("WreathProd-tests.jl") + include("FPGroup-tests.jl") end