mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
general cleanup
This commit is contained in:
parent
b125871697
commit
ac4ee69fc6
@ -28,35 +28,29 @@ export FPGroupElem, FPGroup
|
||||
#
|
||||
# Type and parent object methods
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
elem_type(::Type{FPGroup}) = FPGroupElem
|
||||
parent_type(::Type{FPGroupElem}) = FPGroup
|
||||
AbstractAlgebra.elem_type(::Type{FPGroup}) = FPGroupElem
|
||||
AbstractAlgebra.parent_type(::Type{FPGroupElem}) = FPGroup
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# FPSymbol constructors
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
FPSymbol(s::Symbol) = FPSymbol(s, 1)
|
||||
FPSymbol(s::String) = FPSymbol(Symbol(s))
|
||||
FPSymbol(s::GSymbol) = FPSymbol(s.id, s.pow)
|
||||
|
||||
convert(::Type{FPSymbol}, s::FreeSymbol) = FPSymbol(s.id, s.pow)
|
||||
|
||||
FPGroup(n::Int, symbol::String="f") = FPGroup([Symbol(symbol,i) for i in 1:n])
|
||||
FPGroup(a::AbstractVector) = FPGroup([FPSymbol(i) for i in a])
|
||||
FPGroup(gens::Vector{FPSymbol}) = FPGroup(gens, Dict{FreeGroupElem, FreeGroupElem}())
|
||||
|
||||
FPGroup(a::Vector{String}) = FPGroup([FPSymbol(i) for i in a])
|
||||
|
||||
FPGroup(n::Int, symbol::String="f") = FPGroup(["$symbol$i" for i in 1:n])
|
||||
FPGroup(H::FreeGroup) = FPGroup([FPSymbol(s) for s in H.gens])
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Parent object call overloads
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function (G::FPGroup)(w::GWord)
|
||||
if isempty(w)
|
||||
@ -80,48 +74,23 @@ function (G::FPGroup)(w::GWord)
|
||||
return reduce!(w)
|
||||
end
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Basic manipulation
|
||||
#
|
||||
###############################################################################
|
||||
(G::FPGroup)(s::GSymbol) = G(FPGroupElem(s))
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# String I/O
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function show(io::IO, G::FPGroup)
|
||||
print(io, "FPgroup on $(length(G.gens)) generators ")
|
||||
strrels = join(G.rels, ", ")
|
||||
if length(strrels) > 300
|
||||
print(io, "⟨ ", join(G.gens, ", "), " | $(length(G.rels)) relation(s) ⟩.")
|
||||
else
|
||||
print(io, "⟨ ", join(G.gens, ", "), " | ", join(G.rels, ", "), " ⟩.")
|
||||
end
|
||||
print(io, "FPgroup on $(length(G.gens)) generators ")
|
||||
strrels = join(G.rels, ", ")
|
||||
if length(strrels) > 200
|
||||
print(io, "⟨ ", join(G.gens, ", "), " | $(length(G.rels)) relation(s) ⟩.")
|
||||
else
|
||||
print(io, "⟨ ", join(G.gens, ", "), " | ", join(G.rels, ", "), " ⟩.")
|
||||
end
|
||||
end
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Comparison
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Inversion
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Binary operations
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function reduce!(W::FPGroupElem)
|
||||
reduced = false
|
||||
while !reduced
|
||||
|
@ -2,7 +2,6 @@
|
||||
#
|
||||
# FreeSymbol/FreeGroupElem/FreeGroup definition
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
struct FreeSymbol <: GSymbol
|
||||
id::Symbol
|
||||
@ -14,7 +13,7 @@ FreeGroupElem = GroupWord{FreeSymbol}
|
||||
mutable struct FreeGroup <: AbstractFPGroup
|
||||
gens::Vector{FreeSymbol}
|
||||
|
||||
function FreeGroup(gens::Vector{T}) where {T<:GSymbol}
|
||||
function FreeGroup(gens::AbstractVector{T}) where {T<:GSymbol}
|
||||
G = new(gens)
|
||||
G.gens = gens
|
||||
return G
|
||||
@ -27,72 +26,48 @@ export FreeGroupElem, FreeGroup
|
||||
#
|
||||
# Type and parent object methods
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
elem_type(::Type{FreeGroup}) = FreeGroupElem
|
||||
|
||||
parent_type(::Type{FreeGroupElem}) = FreeGroup
|
||||
AbstractAlgebra.elem_type(::Type{FreeGroup}) = FreeGroupElem
|
||||
AbstractAlgebra.parent_type(::Type{FreeGroupElem}) = FreeGroup
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# FreeSymbol constructors
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
FreeSymbol(s::Symbol) = FreeSymbol(s,1)
|
||||
FreeSymbol(s::String) = FreeSymbol(Symbol(s))
|
||||
FreeSymbol(s::AbstractString) = FreeSymbol(Symbol(s))
|
||||
FreeSymbol(s::GSymbol) = FreeSymbol(s.id, s.pow)
|
||||
|
||||
FreeGroup(n::Int, symbol::String="f") = FreeGroup([Symbol(symbol,i) for i in 1:n])
|
||||
|
||||
FreeGroup(a::Vector) = FreeGroup(FreeSymbol.(a))
|
||||
FreeGroup(a::AbstractVector) = FreeGroup(FreeSymbol.(a))
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Parent object call overloads
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
|
||||
if length(syllables(w)) > 0
|
||||
for s in w.symbols
|
||||
i = findfirst(g -> g.id == s.id, G.gens)
|
||||
i == 0 && throw(DomainError(
|
||||
"Symbol $s does not belong to $G."))
|
||||
s.pow % G.gens[i].pow == 0 || throw(DomainError(
|
||||
"Symbol $s doesn't belong to $G."))
|
||||
end
|
||||
for s in syllables(w)
|
||||
i = findfirst(g -> g.id == s.id, G.gens)
|
||||
isnothing(i) && throw(DomainError(
|
||||
"Symbol $s does not belong to $G."))
|
||||
s.pow % G.gens[i].pow == 0 || throw(DomainError(
|
||||
"Symbol $s doesn't belong to $G."))
|
||||
end
|
||||
w.parent = G
|
||||
return w
|
||||
setparent!(w, G)
|
||||
return reduce!(w)
|
||||
end
|
||||
|
||||
(G::FreeGroup)(s::FreeSymbol) = G(FreeGroupElem(s))
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Basic manipulation
|
||||
#
|
||||
###############################################################################
|
||||
(G::FreeGroup)(s::GSymbol) = G(FreeGroupElem(s))
|
||||
(G::FreeGroup)(v::AbstractVector{<:GSymbol}) = G(FreeGroupElem(FreeSymbol.(v)))
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# String I/O
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function show(io::IO, G::FreeGroup)
|
||||
print(io, "Free group on $(length(G.gens)) generators: ")
|
||||
join(io, G.gens, ", ")
|
||||
end
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Comparison
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Inversion
|
||||
#
|
||||
###############################################################################
|
||||
|
@ -15,7 +15,12 @@ using Markdown
|
||||
|
||||
|
||||
include("types.jl")
|
||||
include("gsymbols.jl")
|
||||
|
||||
include("FreeGroup.jl")
|
||||
include("FPGroups.jl")
|
||||
include("AutGroup.jl")
|
||||
|
||||
include("symbols.jl")
|
||||
include("fallbacks.jl")
|
||||
include("words.jl")
|
||||
include("hashing.jl")
|
||||
@ -23,51 +28,33 @@ include("freereduce.jl")
|
||||
include("arithmetic.jl")
|
||||
include("findreplace.jl")
|
||||
|
||||
include("FreeGroup.jl")
|
||||
include("FPGroups.jl")
|
||||
include("AutGroup.jl")
|
||||
|
||||
include("DirectPower.jl")
|
||||
include("WreathProducts.jl")
|
||||
|
||||
|
||||
@doc doc"""
|
||||
gens(G::AbstractFPGroups)
|
||||
> returns vector of generators of `G`, as its elements.
|
||||
|
||||
"""
|
||||
gens(G::AbstractFPGroup) = [G(g) for g in G.gens]
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# String I/O
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
@doc doc"""
|
||||
show(io::IO, W::GWord)
|
||||
> The actual string produced by show depends on the eltype of `W.symbols`.
|
||||
|
||||
"""
|
||||
function show(io::IO, W::GWord)
|
||||
function Base.show(io::IO, W::GWord)
|
||||
if length(W) == 0
|
||||
print(io, "(id)")
|
||||
else
|
||||
join(io, [string(s) for s in W.symbols], "*")
|
||||
join(io, (string(s) for s in syllables(W)), "*")
|
||||
end
|
||||
end
|
||||
|
||||
function show(io::IO, s::T) where {T<:GSymbol}
|
||||
if s.pow == 1
|
||||
print(io, string(s.id))
|
||||
else
|
||||
print(io, string((s.id))*"^$(s.pow)")
|
||||
end
|
||||
end
|
||||
function Base.show(io::IO, s::T) where {T<:GSymbol}
|
||||
if s.pow == 1
|
||||
print(io, string(s.id))
|
||||
else
|
||||
G = parent(W)
|
||||
w = T([inv(s) for s in Iterators.reverse(syllables(W))])
|
||||
return G(w)
|
||||
print(io, "$(s.id)^$(s.pow)")
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user