diff --git a/src/new_types.jl b/src/new_types.jl index ca34915..5195228 100644 --- a/src/new_types.jl +++ b/src/new_types.jl @@ -131,7 +131,16 @@ end function FreeGroup(A::Alphabet) @boundscheck @assert all(KnuthBendix.hasinverse(l, A) for l in KnuthBendix.letters(A)) - return FreeGroup(KnuthBendix.letters(A), A) + ltrs = KnuthBendix.letters(A) + gens = Vector{eltype(ltrs)}() + invs = Vector{eltype(ltrs)}() + for l in ltrs + l ∈ invs && continue + push!(gens, l) + push!(invs, inv(A, l)) + end + + return FreeGroup(gens, A) end function FreeGroup(n::Integer) diff --git a/test/fp_groups.jl b/test/fp_groups.jl index 19fc9f4..d49a032 100644 --- a/test/fp_groups.jl +++ b/test/fp_groups.jl @@ -1,7 +1,11 @@ @testset "FPGroups" begin A = Alphabet([:a, :A, :b, :B, :c, :C], [2,1,4,3,6,5]) + @test New.FreeGroup(A) isa New.FreeGroup + @test sprint(show, New.FreeGroup(A)) == "free group on 3 generators" + F = New.FreeGroup([:a, :b, :c], A) + @test sprint(show, F) == "free group on 3 generators" a,b,c = gens(F) @test c*b*a isa New.FPGroupElement