Skip to content

Commit

Permalink
Merge pull request #29 from kalmarek/fix/#28_normalform_hashing
Browse files Browse the repository at this point in the history
Fix for #28: normalform & hashing
  • Loading branch information
Marek Kaluba committed Jun 12, 2023
2 parents 7230106 + c8805d6 commit d385992
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Groups"
uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
authors = ["Marek Kaluba <kalmar@amu.edu.pl>"]
version = "0.7.6"
version = "0.7.7"

[deps]
GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120"
Expand Down
7 changes: 1 addition & 6 deletions src/aut_groups/transvections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ end
λ(i, j) = Transvection(, i, j)

function Base.show(io::IO, t::Transvection)
id = if t.id ===
'ϱ'
else # if t.id === :λ
'λ'
end
print(io, id, subscriptify(t.i), '.', subscriptify(t.j))
print(io, t.id, subscriptify(t.i), '.', subscriptify(t.j))
return t.inv && print(io, "^-1")
end

Expand Down
1 change: 1 addition & 0 deletions src/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function _update_savedhash!(g::AbstractFPGroupElement, data)
end

function Base.hash(g::AbstractFPGroupElement, h::UInt)
g = normalform!(g)
_isvalidhash(g) || _update_savedhash!(g, equality_data(g))
return hash(g.savedhash >> count_ones(__BITFLAGS_MASK), h)
end
Expand Down
2 changes: 1 addition & 1 deletion src/matrix_groups/eltary_symplectic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end

function Base.show(io::IO, s::ElementarySymplectic)
i, j = Groups.subscriptify(s.i), Groups.subscriptify(s.j)
print(io, s.symbol, i, j)
print(io, s.symbol, i, '.', j)
return !isone(s.val) && print(io, "^$(s.val)")
end

Expand Down
15 changes: 13 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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}
Expand Down
3 changes: 1 addition & 2 deletions src/wl_ball.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function wlmetric_ball(
new = collect(
op(o, s) for o in @view(ball[sizes[end-1]:end]) for s in S
)
append!(ball, new)
unique!(ball)
ball = union!(ball, new)
push!(sizes, length(ball))
end
end
Expand Down
37 changes: 32 additions & 5 deletions test/fp_groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
G = FPGroup(F, [a * b => b * a, a * c => c * a, b * c => c * b])

@test G isa FPGroup
@test sprint(show, G) == "⟨ a b c | \n\t a*b => b*a a*c => c*a b*c => c*b ⟩"
@test sprint(show, G) ==
"⟨ a b c | \n\t a*b => b*a a*c => c*a b*c => c*b ⟩"
@test rand(G) isa FPGroupElement

f = a * c * b
Expand All @@ -40,28 +41,54 @@
end

# quotient of G
H = FPGroup(G, [aG^2 => cG, bG * cG => aG], max_rules=200)
H = FPGroup(G, [aG^2 => cG, bG * cG => aG]; max_rules = 200)

h = H(word(g))

@test h isa FPGroupElement
@test_throws AssertionError h == g
@test_throws MethodError h * g

H′ = FPGroup(G, [aG^2 => cG, bG * cG => aG], max_rules=200)
H′ = FPGroup(G, [aG^2 => cG, bG * cG => aG]; max_rules = 200)
@test_throws AssertionError one(H) == one(H′)

Groups.normalform!(h)
@test h == H([5])

@test_logs (:warn, "using generic isfiniteorder(::AbstractFPGroupElement): the returned `false` might be wrong") isfiniteorder(h)
@test_logs (
:warn,
"using generic isfiniteorder(::AbstractFPGroupElement): the returned `false` might be wrong",
) isfiniteorder(h)

@test_logs (:warn, "using generic isfinite(::AbstractFPGroup): the returned `false` might be wrong") isfinite(H)
@test_logs (
:warn,
"using generic isfinite(::AbstractFPGroup): the returned `false` might be wrong",
) isfinite(H)

Logging.with_logger(Logging.NullLogger()) do
@testset "GroupsCore conformance: H" begin
test_Group_interface(H)
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

2 comments on commit d385992

@kalmarek
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/85381

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.7 -m "<description of version>" d385992e92a62bd3a9e356f804341c6ea11878b9
git push origin v0.7.7

Please sign in to comment.