From 126c8bbc22012e7264b3743ff572842d422730d4 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Thu, 25 May 2023 11:58:32 +0200 Subject: [PATCH] add test for hash/normalform --- src/types.jl | 15 +++++++++++++-- test/fp_groups.jl | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/types.jl b/src/types.jl index b2482d9..d6a567e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -88,6 +88,9 @@ end abstract type AbstractFPGroupElement{Gr} <: GroupElement end +Base.copy(g::AbstractFPGroupElement) = one(g) * g +word(f::AbstractFPGroupElement) = f.word + mutable struct FPGroupElement{Gr<:AbstractFPGroup,W<:AbstractWord} <: AbstractFPGroupElement{Gr} word::W @@ -111,7 +114,9 @@ function Base.show(io::IO, ::Type{<:FPGroupElement{Gr}}) where {Gr} return print(io, FPGroupElement, "{$Gr, …}") end -word(f::AbstractFPGroupElement) = f.word +function Base.copy(f::FPGroupElement) + return FPGroupElement(copy(word(f)), parent(f), f.savedhash) +end #convenience KnuthBendix.alphabet(g::AbstractFPGroupElement) = alphabet(parent(g)) @@ -134,7 +139,13 @@ function Base.:(==)(g::AbstractFPGroupElement, h::AbstractFPGroupElement) end function Base.deepcopy_internal(g::FPGroupElement, stackdict::IdDict) - return FPGroupElement(copy(word(g)), parent(g), g.savedhash) + haskey(stackdict, objectid(g)) && return stackdict[objectid(g)] + cw = if haskey(stackdict, objectid(word(g))) + stackdict[objectid(word(g))] + else + copy(word(g)) + end + return FPGroupElement(cw, parent(g), g.savedhash) end function Base.inv(g::GEl) where {GEl<:AbstractFPGroupElement} diff --git a/test/fp_groups.jl b/test/fp_groups.jl index 5e98dd5..8d9079f 100644 --- a/test/fp_groups.jl +++ b/test/fp_groups.jl @@ -64,4 +64,24 @@ test_GroupElement_interface(rand(H, 2)...) end end + + @testset "hash/normalform #28" begin + function cyclic_group(n::Integer) + A = Alphabet([:a, :A], [2, 1]) + F = FreeGroup(A) + a, = Groups.gens(F) + e = one(F) + Cₙ = FPGroup(F, [a^n => e]) + + return Cₙ + end + + n = 15 + G = cyclic_group(n) + ball, sizes = Groups.wlmetric_ball(gens(G); radius = n) + @test first(sizes) == 2 + @test last(sizes) == n + + @test Set(ball) == Set([first(gens(G))^i for i in 0:n-1]) + end end