1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-08-08 07:53:53 +02:00

general cleanup

This commit is contained in:
kalmarek 2020-03-25 05:24:34 +01:00
parent b125871697
commit ac4ee69fc6
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
3 changed files with 39 additions and 108 deletions

View File

@ -28,35 +28,29 @@ export FPGroupElem, FPGroup
# #
# Type and parent object methods # Type and parent object methods
# #
###############################################################################
elem_type(::Type{FPGroup}) = FPGroupElem AbstractAlgebra.elem_type(::Type{FPGroup}) = FPGroupElem
parent_type(::Type{FPGroupElem}) = FPGroup AbstractAlgebra.parent_type(::Type{FPGroupElem}) = FPGroup
############################################################################### ###############################################################################
# #
# FPSymbol constructors # FPSymbol constructors
# #
###############################################################################
FPSymbol(s::Symbol) = FPSymbol(s, 1) FPSymbol(s::Symbol) = FPSymbol(s, 1)
FPSymbol(s::String) = FPSymbol(Symbol(s)) FPSymbol(s::String) = FPSymbol(Symbol(s))
FPSymbol(s::GSymbol) = FPSymbol(s.id, s.pow) 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(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]) FPGroup(H::FreeGroup) = FPGroup([FPSymbol(s) for s in H.gens])
############################################################################### ###############################################################################
# #
# Parent object call overloads # Parent object call overloads
# #
###############################################################################
function (G::FPGroup)(w::GWord) function (G::FPGroup)(w::GWord)
if isempty(w) if isempty(w)
@ -80,48 +74,23 @@ function (G::FPGroup)(w::GWord)
return reduce!(w) return reduce!(w)
end end
###############################################################################
#
# Basic manipulation
#
###############################################################################
(G::FPGroup)(s::GSymbol) = G(FPGroupElem(s)) (G::FPGroup)(s::GSymbol) = G(FPGroupElem(s))
############################################################################### ###############################################################################
# #
# String I/O # String I/O
# #
###############################################################################
function show(io::IO, G::FPGroup) function show(io::IO, G::FPGroup)
print(io, "FPgroup on $(length(G.gens)) generators ") print(io, "FPgroup on $(length(G.gens)) generators ")
strrels = join(G.rels, ", ") strrels = join(G.rels, ", ")
if length(strrels) > 300 if length(strrels) > 200
print(io, "", join(G.gens, ", "), " | $(length(G.rels)) relation(s) ⟩.") print(io, "", join(G.gens, ", "), " | $(length(G.rels)) relation(s) ⟩.")
else else
print(io, "", join(G.gens, ", "), " | ", join(G.rels, ", "), " ⟩.") print(io, "", join(G.gens, ", "), " | ", join(G.rels, ", "), " ⟩.")
end end
end end
###############################################################################
#
# Comparison
#
###############################################################################
###############################################################################
#
# Inversion
#
###############################################################################
###############################################################################
#
# Binary operations
#
###############################################################################
function reduce!(W::FPGroupElem) function reduce!(W::FPGroupElem)
reduced = false reduced = false
while !reduced while !reduced

View File

@ -2,7 +2,6 @@
# #
# FreeSymbol/FreeGroupElem/FreeGroup definition # FreeSymbol/FreeGroupElem/FreeGroup definition
# #
###############################################################################
struct FreeSymbol <: GSymbol struct FreeSymbol <: GSymbol
id::Symbol id::Symbol
@ -14,7 +13,7 @@ FreeGroupElem = GroupWord{FreeSymbol}
mutable struct FreeGroup <: AbstractFPGroup mutable struct FreeGroup <: AbstractFPGroup
gens::Vector{FreeSymbol} gens::Vector{FreeSymbol}
function FreeGroup(gens::Vector{T}) where {T<:GSymbol} function FreeGroup(gens::AbstractVector{T}) where {T<:GSymbol}
G = new(gens) G = new(gens)
G.gens = gens G.gens = gens
return G return G
@ -27,72 +26,48 @@ export FreeGroupElem, FreeGroup
# #
# Type and parent object methods # Type and parent object methods
# #
###############################################################################
elem_type(::Type{FreeGroup}) = FreeGroupElem AbstractAlgebra.elem_type(::Type{FreeGroup}) = FreeGroupElem
AbstractAlgebra.parent_type(::Type{FreeGroupElem}) = FreeGroup
parent_type(::Type{FreeGroupElem}) = FreeGroup
############################################################################### ###############################################################################
# #
# FreeSymbol constructors # FreeSymbol constructors
# #
###############################################################################
FreeSymbol(s::Symbol) = FreeSymbol(s,1) 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(n::Int, symbol::String="f") = FreeGroup([Symbol(symbol,i) for i in 1:n])
FreeGroup(a::AbstractVector) = FreeGroup(FreeSymbol.(a))
FreeGroup(a::Vector) = FreeGroup(FreeSymbol.(a))
############################################################################### ###############################################################################
# #
# Parent object call overloads # Parent object call overloads
# #
###############################################################################
function (G::FreeGroup)(w::GroupWord{FreeSymbol}) function (G::FreeGroup)(w::GroupWord{FreeSymbol})
if length(syllables(w)) > 0 for s in syllables(w)
for s in w.symbols i = findfirst(g -> g.id == s.id, G.gens)
i = findfirst(g -> g.id == s.id, G.gens) isnothing(i) && throw(DomainError(
i == 0 && throw(DomainError( "Symbol $s does not belong to $G."))
"Symbol $s does not belong to $G.")) s.pow % G.gens[i].pow == 0 || throw(DomainError(
s.pow % G.gens[i].pow == 0 || throw(DomainError( "Symbol $s doesn't belong to $G."))
"Symbol $s doesn't belong to $G."))
end
end end
w.parent = G setparent!(w, G)
return w return reduce!(w)
end end
(G::FreeGroup)(s::FreeSymbol) = G(FreeGroupElem(s)) (G::FreeGroup)(s::GSymbol) = G(FreeGroupElem(s))
(G::FreeGroup)(v::AbstractVector{<:GSymbol}) = G(FreeGroupElem(FreeSymbol.(v)))
###############################################################################
#
# Basic manipulation
#
###############################################################################
############################################################################### ###############################################################################
# #
# String I/O # String I/O
# #
###############################################################################
function show(io::IO, G::FreeGroup) function show(io::IO, G::FreeGroup)
print(io, "Free group on $(length(G.gens)) generators: ") print(io, "Free group on $(length(G.gens)) generators: ")
join(io, G.gens, ", ") join(io, G.gens, ", ")
end end
###############################################################################
#
# Comparison
#
###############################################################################
###############################################################################
#
# Inversion
#
###############################################################################

View File

@ -15,7 +15,12 @@ using Markdown
include("types.jl") include("types.jl")
include("gsymbols.jl")
include("FreeGroup.jl")
include("FPGroups.jl")
include("AutGroup.jl")
include("symbols.jl")
include("fallbacks.jl") include("fallbacks.jl")
include("words.jl") include("words.jl")
include("hashing.jl") include("hashing.jl")
@ -23,51 +28,33 @@ include("freereduce.jl")
include("arithmetic.jl") include("arithmetic.jl")
include("findreplace.jl") include("findreplace.jl")
include("FreeGroup.jl")
include("FPGroups.jl")
include("AutGroup.jl")
include("DirectPower.jl") include("DirectPower.jl")
include("WreathProducts.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 # String I/O
# #
###############################################################################
@doc doc""" @doc doc"""
show(io::IO, W::GWord) show(io::IO, W::GWord)
> The actual string produced by show depends on the eltype of `W.symbols`. > 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 if length(W) == 0
print(io, "(id)") print(io, "(id)")
else else
join(io, [string(s) for s in W.symbols], "*") join(io, (string(s) for s in syllables(W)), "*")
end end
end end
function show(io::IO, s::T) where {T<:GSymbol} function Base.show(io::IO, s::T) where {T<:GSymbol}
if s.pow == 1 if s.pow == 1
print(io, string(s.id)) print(io, string(s.id))
else
print(io, string((s.id))*"^$(s.pow)")
end
end
else else
G = parent(W) print(io, "$(s.id)^$(s.pow)")
w = T([inv(s) for s in Iterators.reverse(syllables(W))])
return G(w)
end end
end end