Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gap/pkg/OscarInterface/gap/hash.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BindGlobal("HashPermutation", function(p, s)
local l;
l:=LARGEST_MOVED_POINT_PERM(p);

if IsPerm4Rep(p) then
# is it a proper 4byte perm?
if l>65536 then
return HashKeyBag(p,s,GAPInfo.BytesPerVariable,4*l);
else
# the permutation does not require 4 bytes. Trim in two
# byte representation (we need to do this to get consistent
# hash keys, regardless of representation.)
TRIM_PERM(p,l);
fi;
fi;

# now we have a Perm2Rep:
return HashKeyBag(p,s,GAPInfo.BytesPerVariable,2*l);
end);
1 change: 1 addition & 0 deletions gap/pkg/OscarInterface/read.g
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
ReadPackage( "OscarInterface", "gap/OscarInterface.gi");
ReadPackage( "OscarInterface", "gap/alnuth.gi");
ReadPackage( "OscarInterface", "gap/QQBar.gi");
ReadPackage( "OscarInterface", "gap/hash.gi");

ReadPackage( "OscarInterface", "gap/ExperimentalMatrixGroups.g");
1 change: 1 addition & 0 deletions src/GAP/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ GAP.@wrap HasClassParameters(x::GapObj)::Bool
GAP.@wrap HasConjugacyClassesSubgroups(x::GapObj)::Bool
GAP.@wrap Hasfhmethsel(x::GapObj)::Bool
GAP.@wrap HasGrp(x::GapObj)::Bool
GAP.@wrap HashPermutation(x::GapObj, y::GapInt)::Int
GAP.@wrap HasImageRecogNode(x::GapObj)::Bool
GAP.@wrap HasIsRecogInfoForAlmostSimpleGroup(x::GapObj)::Bool
GAP.@wrap HasIsRecogInfoForSimpleGroup(x::GapObj)::Bool
Expand Down
15 changes: 15 additions & 0 deletions src/Groups/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ It is displayed as product of disjoint cycles.
"""
const PermGroupElem = BasicGAPGroupElem{PermGroup}

function Base.hash(x::PermGroupElem, h::UInt)
d = hash(degree(x), h)
modulus = Sys.WORD_SIZE == 32 ? 2^28 : 2^60 # GAP limitations on integer size for seed.
return UInt(GAPWrap.HashPermutation(GapObj(x), GapInt(d % modulus)))
end


"""
PcGroup
Expand Down Expand Up @@ -285,6 +291,11 @@ f1*f3
"""
const SubPcGroupElem = BasicGAPGroupElem{SubPcGroup}

function Base.hash(x::Union{PcGroupElem,SubPcGroupElem}, h::UInt)
G = full_group(parent(x))[1]
return hash(letters(x), hash(G, h))
Copy link
Member

Choose a reason for hiding this comment

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

If we think of groups with large relative orders then letters(x) can be expected to be a long list.
syllables(x) would usually be shorter.

Both letters and syllables create new objects. Ideally we would take the internally stored exponent vector; for that, a GAP function analogous to HashPermutation would be needed.

end


"""
FPGroup
Expand Down Expand Up @@ -432,6 +443,10 @@ mutable struct MatrixGroupElem{RE<:RingElem, T<:MatElem{RE}} <: AbstractMatrixGr
end
end

function Base.hash(x::MatrixGroupElem, h::UInt)
return hash(matrix(x), hash(parent(x), h))
end

################################################################################
#
# Construct an Oscar group wrapping the GAP group `obj`
Expand Down
22 changes: 22 additions & 0 deletions test/Groups/Permutations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,25 @@ end
z = g([2, 3, 1, 4]) # permutation (1 2 3)(4)
@test number_of_fixed_points(z) == 1 # only point 4 is fixed
end

@testset "hashing permutations" begin
g = symmetric_group(4)
a = perm(g, [2, 3, 4, 1])
b = perm(g, [2, 3, 4, 1])
c = perm(g, [1, 2, 3, 4])

@test hash(c) == hash(one(g))
@test hash(a) != hash(one(g))
@test hash(a) == hash(b)

h = sylow_subgroup(g, 3)[1]
a = perm(h, [3, 1, 2])
a_bar = @perm (1, 3, 2)
b = perm(h, [3, 1, 2])
c = perm(g, [1, 2, 3])

@test hash(c) == hash(one(g))
@test hash(a) != hash(one(h))
Copy link
Member

Choose a reason for hiding this comment

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

I am not a fan of these kinds of tests, as they can non-deterministically fail due to hash collisions

@test hash(a) == hash(b) # same degree
@test hash(a) != hash(a_bar) # differing degrees
end
Loading