Groups.jl/src/FreeGroup.jl

105 lines
2.8 KiB
Julia
Raw Normal View History

2017-05-11 18:28:00 +02:00
###############################################################################
#
# FreeSymbol/FreeGroupElem/FreeGroup definition
2017-05-11 18:28:00 +02:00
#
###############################################################################
2017-05-09 17:46:52 +02:00
2017-09-13 11:22:21 +02:00
struct FreeSymbol <: GSymbol
2019-01-03 03:37:37 +01:00
id::Symbol
pow::Int
end
FreeGroupElem = GroupWord{FreeSymbol}
2017-05-09 17:46:52 +02:00
2017-09-13 11:22:21 +02:00
mutable struct FreeGroup <: AbstractFPGroup
gens::Vector{FreeSymbol}
2018-09-21 18:08:44 +02:00
function FreeGroup(gens::Vector{T}) where {T<:GSymbol}
G = new(gens)
2017-05-11 18:16:21 +02:00
G.gens = gens
return G
end
2017-05-09 17:46:52 +02:00
end
export FreeGroupElem, FreeGroup
2017-05-09 17:46:52 +02:00
2017-05-11 18:28:00 +02:00
###############################################################################
#
# Type and parent object methods
#
###############################################################################
2017-05-11 18:28:29 +02:00
elem_type(::Type{FreeGroup}) = FreeGroupElem
2017-05-11 18:17:42 +02:00
parent_type(::Type{FreeGroupElem}) = FreeGroup
2017-05-11 18:17:42 +02:00
2017-05-11 18:28:00 +02:00
###############################################################################
#
# FreeSymbol constructors
2017-05-11 18:28:00 +02:00
#
###############################################################################
2017-05-09 17:46:52 +02:00
2019-01-03 03:37:37 +01:00
FreeSymbol(s::Symbol) = FreeSymbol(s,1)
FreeSymbol(s::String) = FreeSymbol(Symbol(s))
2017-05-11 18:16:51 +02:00
2019-01-03 03:37:37 +01:00
FreeGroup(n::Int, symbol::String="f") = FreeGroup([Symbol(symbol,i) for i in 1:n])
2017-05-12 21:19:08 +02:00
2019-01-03 03:37:37 +01:00
FreeGroup(a::Vector) = FreeGroup(FreeSymbol.(a))
2017-05-11 18:16:51 +02:00
2017-05-11 18:28:00 +02:00
###############################################################################
#
# Parent object call overloads
#
###############################################################################
2019-11-14 09:21:11 +01:00
function Base.one(G::FreeGroup)
2018-03-28 12:21:50 +02:00
id = FreeGroupElem(FreeSymbol[])
2017-05-11 18:18:06 +02:00
id.parent = G
return id
2017-05-09 17:46:52 +02:00
end
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
2020-03-24 23:53:29 +01:00
if length(syllables(w)) > 0
2017-05-11 18:18:06 +02:00
for s in w.symbols
2019-01-03 03:37:37 +01:00
i = findfirst(g -> g.id == s.id, G.gens)
2018-07-30 14:59:11 +02:00
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."))
2017-05-11 18:18:06 +02:00
end
end
w.parent = G
return w
end
(G::FreeGroup)(s::FreeSymbol) = G(FreeGroupElem(s))
2017-05-11 18:18:06 +02:00
2017-05-11 18:28:00 +02:00
###############################################################################
#
# Basic manipulation
#
###############################################################################
2017-05-09 17:46:52 +02:00
2017-05-11 18:28:00 +02:00
###############################################################################
#
# String I/O
#
###############################################################################
function show(io::IO, G::FreeGroup)
2017-05-15 17:28:58 +02:00
print(io, "Free group on $(length(G.gens)) generators: ")
join(io, G.gens, ", ")
2017-05-09 17:46:52 +02:00
end
2017-05-11 18:28:00 +02:00
###############################################################################
#
# Comparison
#
###############################################################################
###############################################################################
#
# Inversion
#
###############################################################################