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

replace AutGroupElem with Automorphism{N} <: GWord{AutSymbol}

this allows to store in the Automorphism struct
 precomputed hash and
 image of the canonical basis
This commit is contained in:
kalmarek 2018-03-25 23:54:49 +02:00
parent 0b800b5366
commit a7bf32145c

View File

@ -1,6 +1,6 @@
############################################################################### ###############################################################################
# #
# AutSymbol/ AutGroup / AutGroupElem # AutSymbol/ AutGroup / Automorphism
# #
############################################################################### ###############################################################################
@ -30,14 +30,23 @@ struct AutSymbol <: GSymbol
typ::Union{LTransvect, RTransvect, PermAut, FlipAut, Identity} typ::Union{LTransvect, RTransvect, PermAut, FlipAut, Identity}
end end
AutGroupElem = GWord{AutSymbol}
mutable struct AutGroup{N} <: AbstractFPGroup mutable struct AutGroup{N} <: AbstractFPGroup
objectGroup::FreeGroup objectGroup::FreeGroup
gens::Vector{AutSymbol} gens::Vector{AutSymbol}
end end
export AutGroupElem, AutGroup mutable struct Automorphism{N} <: GWord{AutSymbol}
symbols::Vector{AutSymbol}
modified::Bool
savedhash::UInt
savedimage::NTuple{N, FreeGroupElem}
parent::AutGroup{N}
Automorphism{N}(f::Vector{AutSymbol}) where N = new(f, true, UInt(0))
end
export Automorphism, AutGroup
############################################################################### ###############################################################################
# #
@ -45,9 +54,9 @@ export AutGroupElem, AutGroup
# #
############################################################################### ###############################################################################
elem_type(::AutGroup) = AutGroupElem elem_type(::AutGroup{N}) where N = Automorphism{N}
parent_type(::AutGroupElem) = AutGroup parent_type(::Automorphism{N}) where N = AutGroup{N}
############################################################################### ###############################################################################
# #
@ -133,7 +142,7 @@ domain(G::AutGroup)= NTuple{length(G.objectGroup.gens), FreeGroupElem}(gens(G.ob
############################################################################### ###############################################################################
# #
# AutGroup / AutGroupElem constructors # AutGroup / Automorphism constructors
# #
############################################################################### ###############################################################################
@ -165,26 +174,26 @@ end
# #
############################################################################### ###############################################################################
function (G::AutGroup)() function (G::AutGroup{N})() where N
id = AutGroupElem(id_autsymbol()) id = Automorphism{N}(id_autsymbol())
id.parent = G id.parent = G
return id return id
end end
function (G::AutGroup)(f::AutSymbol) function (G::AutGroup{N})(f::AutSymbol) where N
g = AutGroupElem(f) g = Automorphism{N}([f])
g.parent = G g.parent = G
return g return g
end end
function (G::AutGroup)(g::AutGroupElem) function (G::AutGroup{N})(g::Automorphism{N}) where N
g.parent = G g.parent = G
return g return g
end end
############################################################################### ###############################################################################
# #
# Functional call overloads for evaluation of AutSymbol and AutGroupElem # Functional call overloads for evaluation of AutSymbol and Automorphism
# #
############################################################################### ###############################################################################
@ -197,7 +206,7 @@ function (f::AutSymbol)(v::NTuple{N, T}) where {N, T}
return v return v
end end
function (F::AutGroupElem)(v::NTuple{N, T}) where {N, T} function (F::Automorphism{N})(v::NTuple{N, T}) where {N, T}
for f in F.symbols for f in F.symbols
v = f(v)::NTuple{N, T} v = f(v)::NTuple{N, T}
end end
@ -212,7 +221,7 @@ end
hash(s::AutSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(:AutSymbol, h))) hash(s::AutSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(:AutSymbol, h)))
function hash(g::AutGroupElem, h::UInt) function hash(g::Automorphism, h::UInt)
if g.modified if g.modified
g.savedhash = hash(g(domain(parent(g))), hash(typeof(g), hash(parent(g), h))) g.savedhash = hash(g(domain(parent(g))), hash(typeof(g), hash(parent(g), h)))
g.modified = false g.modified = false
@ -262,7 +271,7 @@ end
(==)(s::AutSymbol, t::AutSymbol) = s.str == t.str && s.pow == t.pow (==)(s::AutSymbol, t::AutSymbol) = s.str == t.str && s.pow == t.pow
function (==)(g::AutGroupElem, h::AutGroupElem) function (==)(g::Automorphism, h::Automorphism)
parent(g) == parent(h) || return false parent(g) == parent(h) || return false
return g(domain(parent(g))) == h(domain(parent(h))) return g(domain(parent(g))) == h(domain(parent(h)))
end end
@ -292,7 +301,7 @@ function getperm(s::AutSymbol)
return s.typ.p return s.typ.p
end end
function simplify_perms!(W::AutGroupElem) function simplify_perms!(W::Automorphism)
reduced = true reduced = true
for i in 1:length(W.symbols) - 1 for i in 1:length(W.symbols) - 1
current = W.symbols[i] current = W.symbols[i]
@ -318,7 +327,7 @@ function simplify_perms!(W::AutGroupElem)
return reduced return reduced
end end
function reduce!(W::AutGroupElem) function reduce!(W::Automorphism)
if length(W) < 2 if length(W) < 2
deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols)) deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols))
else else