mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-26 02:20:30 +01:00
use syllables api for GWords
This commit is contained in:
parent
7b211014e3
commit
b2d6c14515
@ -66,7 +66,7 @@ function Base.one(G::FPGroup)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function (G::FPGroup)(w::GWord)
|
function (G::FPGroup)(w::GWord)
|
||||||
if length(w) == 0
|
if isempty(w)
|
||||||
return one(G)
|
return one(G)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ function Base.one(G::FreeGroup)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
|
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
|
||||||
if length(w) > 0
|
if length(syllables(w)) > 0
|
||||||
for s in w.symbols
|
for s in w.symbols
|
||||||
i = findfirst(g -> g.id == s.id, G.gens)
|
i = findfirst(g -> g.id == s.id, G.gens)
|
||||||
i == 0 && throw(DomainError(
|
i == 0 && throw(DomainError(
|
||||||
|
@ -63,15 +63,21 @@ abstract type GWord{T<:GSymbol} <: GroupElem end
|
|||||||
"""
|
"""
|
||||||
mutable struct GroupWord{T} <: GWord{T}
|
mutable struct GroupWord{T} <: GWord{T}
|
||||||
symbols::Vector{T}
|
symbols::Vector{T}
|
||||||
savedhash::UInt
|
|
||||||
modified::Bool
|
modified::Bool
|
||||||
|
savedhash::UInt
|
||||||
parent::Group
|
parent::Group
|
||||||
|
|
||||||
function GroupWord{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, true, zero(UInt))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
syllablelength(w::GWord) = length(w.symbols)
|
||||||
|
syllables(w::GWord) = w.symbols
|
||||||
|
ismodified(w::GWord) = w.modified
|
||||||
|
setmodified!(w::GWord) = (w.modified = true; w)
|
||||||
|
unsetmodified!(w::GWord) = (w.modified = false; w)
|
||||||
|
|
||||||
abstract type AbstractFPGroup <: Group end
|
abstract type AbstractFPGroup <: Group end
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -128,19 +134,7 @@ end
|
|||||||
# WARNING: Due to specialised (constant) hash function of GWords this one is actually necessary!
|
# WARNING: Due to specialised (constant) hash function of GWords this one is actually necessary!
|
||||||
function deepcopy_internal(W::T, dict::IdDict) where {T<:GWord}
|
function deepcopy_internal(W::T, dict::IdDict) where {T<:GWord}
|
||||||
G = parent(W)
|
G = parent(W)
|
||||||
return G(T(deepcopy(W.symbols)))
|
return G(T(deepcopy(syllables(W))))
|
||||||
end
|
|
||||||
|
|
||||||
length(W::GWord) = sum([length(s) for s in W.symbols])
|
|
||||||
|
|
||||||
function deleteids!(W::GWord)
|
|
||||||
to_delete = Int[]
|
|
||||||
for i in 1:length(W.symbols)
|
|
||||||
if W.symbols[i].pow == 0
|
|
||||||
push!(to_delete, i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
deleteat!(W.symbols, to_delete)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function freereduce!(W::GWord)
|
function freereduce!(W::GWord)
|
||||||
@ -157,7 +151,7 @@ function freereduce!(W::GWord)
|
|||||||
W.symbols[i] = change_pow(W.symbols[i], 0)
|
W.symbols[i] = change_pow(W.symbols[i], 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
deleteids!(W)
|
filter!(!isone, syllables(w))
|
||||||
return reduced
|
return reduced
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -242,10 +236,9 @@ function (==)(W::GWord, Z::GWord)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function (==)(s::GSymbol, t::GSymbol)
|
function (==)(s::GSymbol, t::GSymbol)
|
||||||
s.pow == t.pow || return false
|
isone(s) && isone(t) && return true
|
||||||
s.pow == 0 && return true
|
s.pow == t.pow && s.id == t.id && return true
|
||||||
s.id == t.id || return false
|
return false
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -333,13 +326,12 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function inv(W::T) where {T<:GWord}
|
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 = T(reverse([inv(s) for s in W.symbols]))
|
w = T([inv(s) for s in Iterators.reverse(syllables(W))])
|
||||||
w.modified = true
|
|
||||||
return G(w)
|
return G(w)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user