1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-26 02:20:30 +01:00

fast equality for Automorphisms

This commit is contained in:
kalmarek 2020-03-25 03:28:45 +01:00
parent 8248039d63
commit 99d5bc2f8c
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15

View File

@ -249,24 +249,29 @@ function compute_images(g::Automorphism)
end end
function (==)(g::Automorphism{N}, h::Automorphism{N}) where N function (==)(g::Automorphism{N}, h::Automorphism{N}) where N
parent(g) == parent(h) || return false img_c, imh_c = false, false
if !g.modified && !h.modified if ismodified(g)
if g.savedhash != h.savedhash img = compute_images(g)
return false img_c = true
end
end end
# expensive: if ismodified(h)
g_im = reduce!.(evaluate(g)) imh = compute_images(h)
h_im = reduce!.(evaluate(h)) imh_c = true
# cheap: end
g.savedhash = hash(g, g_im)
g.modified = false
h.savedhash = hash(h, h_im)
h.modified = false
return g_im == h_im @assert !ismodified(g) && !ismodified(h)
# cheap
hash(g) != hash(h) && return false # hashes differ, so images must have differed as well
# equal elements, or possibly hash conflict
if !img_c
img = compute_images(g)
end
if !imh_c
imh = compute_images(h)
end
return img == imh
end end
############################################################################### ###############################################################################