mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-04 18:11:26 +01:00
introduce GroupWord{T} <: GWord{T<:GSymbol}
This allows subtyping of GWord{T} with more specific group elements
This commit is contained in:
parent
02d947899f
commit
6939c0f00a
@ -9,7 +9,7 @@ struct FPSymbol <: GSymbol
|
|||||||
pow::Int
|
pow::Int
|
||||||
end
|
end
|
||||||
|
|
||||||
FPGroupElem = GWord{FPSymbol}
|
FPGroupElem = GroupWord{FPSymbol}
|
||||||
|
|
||||||
mutable struct FPGroup <: AbstractFPGroup
|
mutable struct FPGroup <: AbstractFPGroup
|
||||||
gens::Vector{FPSymbol}
|
gens::Vector{FPSymbol}
|
||||||
|
@ -9,7 +9,7 @@ struct FreeSymbol <: GSymbol
|
|||||||
pow::Int
|
pow::Int
|
||||||
end
|
end
|
||||||
|
|
||||||
FreeGroupElem = GWord{FreeSymbol}
|
FreeGroupElem = GroupWord{FreeSymbol}
|
||||||
|
|
||||||
mutable struct FreeGroup <: AbstractFPGroup
|
mutable struct FreeGroup <: AbstractFPGroup
|
||||||
gens::Vector{FreeSymbol}
|
gens::Vector{FreeSymbol}
|
||||||
@ -58,8 +58,7 @@ function (G::FreeGroup)()
|
|||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
function (G::FreeGroup)(w::GWord)
|
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
|
||||||
eltype(w.symbols) == FreeSymbol || throw("Can not coerce $w to FreeGroup $G.")
|
|
||||||
if length(w) > 0
|
if length(w) > 0
|
||||||
for s in w.symbols
|
for s in w.symbols
|
||||||
i = findfirst(g -> g.str == s.str, G.gens)
|
i = findfirst(g -> g.str == s.str, G.gens)
|
||||||
|
@ -43,13 +43,15 @@ doc"""
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mutable struct GWord{T<:GSymbol} <: GroupElem
|
abstract type GWord{T<:GSymbol} <:GroupElem end
|
||||||
|
|
||||||
|
mutable struct GroupWord{T} <: GWord{T}
|
||||||
symbols::Vector{T}
|
symbols::Vector{T}
|
||||||
savedhash::UInt
|
savedhash::UInt
|
||||||
modified::Bool
|
modified::Bool
|
||||||
parent::Group
|
parent::Group
|
||||||
|
|
||||||
function GWord{T}(symbols::Vector{T}) where {T}
|
function GroupWord{T}(symbols::Vector{T}) where {T}
|
||||||
return new{T}(symbols, hash(symbols), true)
|
return new{T}(symbols, hash(symbols), true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -70,8 +72,8 @@ parent{T<:GSymbol}(w::GWord{T}) = w.parent
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
GWord(s::T) where {T} = GWord{T}(T[s])
|
GroupWord(s::T) where {T<:GSymbol} = GroupWord{T}(T[s])
|
||||||
convert(::Type{GWord{T}}, s::T) where {T<:GSymbol} = GWord{T}(T[s])
|
convert(::Type{GroupWord{T}}, s::T) where {T<:GSymbol} = GroupWord{T}(T[s])
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
@ -85,9 +87,9 @@ function hash(W::GWord, h::UInt)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
function deepcopy_internal(W::GWord{T}, dict::ObjectIdDict) where {T<:GSymbol}
|
function deepcopy_internal(W::T, dict::ObjectIdDict) where {T<:GWord}
|
||||||
G = parent(W)
|
G = parent(W)
|
||||||
return G(GWord{T}(deepcopy(W.symbols)))
|
return G(T(deepcopy(W.symbols)))
|
||||||
end
|
end
|
||||||
|
|
||||||
isone(s::GSymbol) = s.pow == 0
|
isone(s::GSymbol) = s.pow == 0
|
||||||
@ -255,12 +257,12 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function inv(W::GWord{T}) where {T}
|
function inv(W::T) where {T<:GWord}
|
||||||
if length(W) == 0
|
if length(W) == 0
|
||||||
return W
|
return W
|
||||||
else
|
else
|
||||||
G = parent(W)
|
G = parent(W)
|
||||||
w = GWord{T}(reverse([inv(s) for s in W.symbols]))
|
w = T(reverse([inv(s) for s in W.symbols]))
|
||||||
w.modified = true
|
w.modified = true
|
||||||
return G(w)
|
return G(w)
|
||||||
end
|
end
|
||||||
@ -377,7 +379,7 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T=parent(first(S))(); radius=2, op=*)
|
function generate_balls(S::Vector{T}, Id::T=parent(first(S))(); radius=2, op=*) where T<:GWord
|
||||||
sizes = Int[]
|
sizes = Int[]
|
||||||
B = [Id]
|
B = [Id]
|
||||||
for i in 1:radius
|
for i in 1:radius
|
||||||
|
Loading…
Reference in New Issue
Block a user