Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 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,13 @@ f1*f3
"""
const SubPcGroupElem = BasicGAPGroupElem{SubPcGroup}

function Base.hash(x::Union{PcGroupElem,SubPcGroupElem}, h::UInt)
G = full_group(parent(x))[1]
h = is_finite_order(x) ? hash(order(x), h) : h
h = hash(is_finite(G), hash(G, h))
return hash(syllables(x), h)
end


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

function Base.hash(x::MatrixGroupElem, h::UInt)
return hash(matrix(x), hash(base_ring(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))
@test hash(a) == hash(b) # same degree
@test hash(a) != hash(a_bar) # differing degrees
end
13 changes: 13 additions & 0 deletions test/Groups/matrixgroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -824,3 +824,16 @@ end
@test h * v == mat * v
end
end

@testset "hashing matrix elements" begin
matrices = [matrix(ZZ, [0 -1; 1 -1]), matrix(ZZ, [0 1; 1 0])]
G = matrix_group(matrices)
A = matrix(ZZ, [1 -1; 0 -1])
B = matrix(ZZ, [-1 0; -1 1])
C = G([1 0; 0 1])

@test hash(C) == hash(one(G))
@test hash(G(A)) != hash(one(G))
@test hash(G(A)) == hash(G(A))
@test hash(G(A)) != hash(G(B))
end
40 changes: 40 additions & 0 deletions test/Groups/pcgroup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,43 @@ end
@test is_bijective(f)
end
end

@testset "hashing polycyclic group elements" begin
# finite polycyclic groups
G = small_group(6, 1)
a = G[1]^5 * G[2]^-4
a_bar = G[1]^-5 * G[2]^-7
b = G[1]^2 * G[2]^3

@test hash(b) == hash(one(G))
@test hash(a) != hash(one(G))
@test hash(a) == hash(a_bar)

# finite polycyclic subgroups
G = pc_group(symmetric_group(4))
H = derived_subgroup(G)[1]
a = H[1]^2 * H[2]^3 * H[3]^3
a_bar = H[1]^5 * H[2]^5 * H[3]^5
b = H[1]^3 * H[2]^4 * H[3]^2

@test hash(b) == hash(one(G))
@test hash(a) != hash(one(G))
@test hash(a) == hash(a_bar)

# infinite polycyclic groups
G = abelian_group(PcGroup, [5, 0])
a = G[1]^3
a_bar = G[1]^8

@test hash(G[1]^0) == hash(one(G))
@test hash(a) != hash(one(G))
@test hash(a) == hash(a_bar)

# case for finite and infinite pcgroups
G = abelian_group(PcGroup, [2, 0])
H = pc_group(symmetric_group(4))
a = G[1]^3
b = H[1]^3
@test syllables(a) == syllables(b)
@test hash(a) != hash(b)
end
Loading