mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-26 02:20:30 +01:00
replace strings with Symbols
This commit is contained in:
parent
3cc6262356
commit
1aa64647c8
@ -25,7 +25,7 @@ end
|
|||||||
struct Identity end
|
struct Identity end
|
||||||
|
|
||||||
struct AutSymbol <: GSymbol
|
struct AutSymbol <: GSymbol
|
||||||
str::String
|
id::Symbol
|
||||||
pow::Int8
|
pow::Int8
|
||||||
fn::Union{LTransvect, RTransvect, PermAut, FlipAut, Identity}
|
fn::Union{LTransvect, RTransvect, PermAut, FlipAut, Identity}
|
||||||
end
|
end
|
||||||
@ -108,26 +108,25 @@ function subscriptify(n::Integer)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function id_autsymbol()
|
function id_autsymbol()
|
||||||
return AutSymbol("(id)", 0, Identity())
|
return AutSymbol(Symbol("(id)"), 0, Identity())
|
||||||
end
|
end
|
||||||
|
|
||||||
function rmul_autsymbol(i::I, j::I; pow::Integer=one(I)) where I<:Integer
|
function rmul_autsymbol(i::Integer, j::Integer; pow::Integer=1)
|
||||||
str = "ϱ"*subscriptify(i)*subscriptify(j)
|
id = Symbol("ϱ", subscriptify(i), subscriptify(j))
|
||||||
return AutSymbol(str, I(pow), RTransvect(i, j))
|
return AutSymbol(id, pow, RTransvect(i, j))
|
||||||
end
|
end
|
||||||
|
|
||||||
function lmul_autsymbol(i::I, j::I; pow::Integer=one(I)) where I<:Integer
|
function lmul_autsymbol(i::Integer, j::Integer; pow::Integer=1)
|
||||||
str = "λ"*subscriptify(i)*subscriptify(j)
|
id = Symbol("λ", subscriptify(i), subscriptify(j))
|
||||||
return AutSymbol(str, I(pow), LTransvect(i, j))
|
return AutSymbol(id, pow, LTransvect(i, j))
|
||||||
end
|
end
|
||||||
|
|
||||||
function flip_autsymbol(i::I; pow::Integer=one(I)) where I<:Integer
|
function flip_autsymbol(i::Integer; pow::Integer=1)
|
||||||
pow = I((2+pow%2)%2)
|
if iseven(pow)
|
||||||
if pow == zero(I)
|
|
||||||
return id_autsymbol()
|
return id_autsymbol()
|
||||||
else
|
else
|
||||||
str = "ɛ"*subscriptify(i)
|
id = Symbol("ɛ", subscriptify(i))
|
||||||
return AutSymbol(str, I(pow), FlipAut(i))
|
return AutSymbol(id, 1, FlipAut(i))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -137,8 +136,8 @@ function perm_autsymbol(p::Generic.perm{I}; pow::Integer=one(I)) where I<:Intege
|
|||||||
end
|
end
|
||||||
for i in eachindex(p.d)
|
for i in eachindex(p.d)
|
||||||
if p.d[i] != i
|
if p.d[i] != i
|
||||||
str = "σ"*join([subscriptify(i) for i in p.d])
|
id = Symbol("σ", [subscriptify(i) for i in p.d]...)
|
||||||
return AutSymbol(str, one(I), PermAut(p))
|
return AutSymbol(id, 1, PermAut(p))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return id_autsymbol()
|
return id_autsymbol()
|
||||||
@ -238,7 +237,7 @@ end
|
|||||||
|
|
||||||
const HASHINGCONST = 0x7d28276b01874b19 # hash(Automorphism)
|
const HASHINGCONST = 0x7d28276b01874b19 # hash(Automorphism)
|
||||||
|
|
||||||
hash(s::AutSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(:AutSymbol, h)))
|
hash(s::AutSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(:AutSymbol, h)))
|
||||||
|
|
||||||
function hash(g::Automorphism, h::UInt)
|
function hash(g::Automorphism, h::UInt)
|
||||||
if g.modified
|
if g.modified
|
||||||
@ -293,7 +292,7 @@ function change_pow(s::AutSymbol, n::Integer)
|
|||||||
return s
|
return s
|
||||||
else
|
else
|
||||||
warn("Changing power of an unknown type of symbol! $s")
|
warn("Changing power of an unknown type of symbol! $s")
|
||||||
return AutSymbol(s.str, n, s.fn)
|
return AutSymbol(s.id, n, s.fn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
struct FPSymbol <: GSymbol
|
struct FPSymbol <: GSymbol
|
||||||
str::String
|
id::Symbol
|
||||||
pow::Int
|
pow::Int
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -40,9 +40,10 @@ elem_type(::FPGroup) = FPGroupElem
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
FPSymbol(s::String) = FPSymbol(s,1)
|
FPSymbol(s::Symbol) = FPSymbol(s, 1)
|
||||||
|
FPSymbol(s::String) = FPSymbol(Symbol(s))
|
||||||
|
|
||||||
convert(::Type{FPSymbol}, s::FreeSymbol) = FPSymbol(s.str, s.pow)
|
convert(::Type{FPSymbol}, s::FreeSymbol) = FPSymbol(s.id, s.pow)
|
||||||
|
|
||||||
FPGroup(gens::Vector{FPSymbol}) = FPGroup(gens, Dict{FPGroupElem, FPGroupElem}())
|
FPGroup(gens::Vector{FPSymbol}) = FPGroup(gens, Dict{FPGroupElem, FPGroupElem}())
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ function (G::FPGroup)(w::GWord)
|
|||||||
|
|
||||||
if eltype(w.symbols) == FPSymbol
|
if eltype(w.symbols) == FPSymbol
|
||||||
for s in w.symbols
|
for s in w.symbols
|
||||||
i = findfirst(g -> g.str == s.str, G.gens)
|
i = findfirst(g -> g.id == s.id, G.gens)
|
||||||
i == 0 && 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(
|
||||||
@ -93,9 +94,9 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
hash(s::FPSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(FPSymbol, h)))
|
hash(s::FPSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(FPSymbol, h)))
|
||||||
|
|
||||||
change_pow(s::FPSymbol, n::Int) = FPSymbol(s.str, n)
|
change_pow(s::FPSymbol, n::Int) = FPSymbol(s.id, n)
|
||||||
|
|
||||||
length(s::FPSymbol) = abs(s.pow)
|
length(s::FPSymbol) = abs(s.pow)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
struct FreeSymbol <: GSymbol
|
struct FreeSymbol <: GSymbol
|
||||||
str::String
|
id::Symbol
|
||||||
pow::Int
|
pow::Int
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,11 +39,12 @@ parent_type(::Type{FreeGroupElem}) = FreeGroup
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
FreeSymbol(s::String) = FreeSymbol(s,1)
|
FreeSymbol(s::Symbol) = FreeSymbol(s,1)
|
||||||
|
FreeSymbol(s::String) = FreeSymbol(Symbol(s))
|
||||||
|
|
||||||
FreeGroup(n::Int, symbol::String="f") = FreeGroup(["$symbol$i" for i in 1:n])
|
FreeGroup(n::Int, symbol::String="f") = FreeGroup([Symbol(symbol,i) for i in 1:n])
|
||||||
|
|
||||||
FreeGroup(a::Vector{String}) = FreeGroup([FreeSymbol(i) for i in a])
|
FreeGroup(a::Vector) = FreeGroup(FreeSymbol.(a))
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
@ -60,7 +61,7 @@ end
|
|||||||
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
|
function (G::FreeGroup)(w::GroupWord{FreeSymbol})
|
||||||
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.id == s.id, G.gens)
|
||||||
i == 0 && 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(
|
||||||
@ -79,9 +80,9 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
hash(s::FreeSymbol, h::UInt) = hash(s.str, hash(s.pow, hash(FreeSymbol, h)))
|
hash(s::FreeSymbol, h::UInt) = hash(s.id, hash(s.pow, hash(FreeSymbol, h)))
|
||||||
|
|
||||||
change_pow(s::FreeSymbol, n::Int) = FreeSymbol(s.str, n)
|
change_pow(s::FreeSymbol, n::Int) = FreeSymbol(s.id, n)
|
||||||
|
|
||||||
length(s::FreeSymbol) = abs(s.pow)
|
length(s::FreeSymbol) = abs(s.pow)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ using Markdown
|
|||||||
::GSymbol
|
::GSymbol
|
||||||
> Abstract type which all group symbols of AbstractFPGroups should subtype. Each
|
> Abstract type which all group symbols of AbstractFPGroups should subtype. Each
|
||||||
> concrete subtype should implement fields:
|
> concrete subtype should implement fields:
|
||||||
> * `str` which is the string representation/identification of a symbol
|
> * `id` which is the `Symbol` representation/identification of a symbol
|
||||||
> * `pow` which is the (multiplicative) exponent of a symbol.
|
> * `pow` which is the (multiplicative) exponent of a symbol.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -128,7 +128,7 @@ function freereduce!(W::GWord)
|
|||||||
for i in 1:length(W.symbols) - 1
|
for i in 1:length(W.symbols) - 1
|
||||||
if W.symbols[i].pow == 0
|
if W.symbols[i].pow == 0
|
||||||
continue
|
continue
|
||||||
elseif W.symbols[i].str == W.symbols[i+1].str
|
elseif W.symbols[i].id == W.symbols[i+1].id
|
||||||
reduced = false
|
reduced = false
|
||||||
p1 = W.symbols[i].pow
|
p1 = W.symbols[i].pow
|
||||||
p2 = W.symbols[i+1].pow
|
p2 = W.symbols[i+1].pow
|
||||||
@ -161,7 +161,7 @@ end
|
|||||||
reduce(W::GWord)
|
reduce(W::GWord)
|
||||||
> performs reduction/simplification of a group element (word in generators).
|
> performs reduction/simplification of a group element (word in generators).
|
||||||
> The default reduction is the free group reduction, i.e. consists of
|
> The default reduction is the free group reduction, i.e. consists of
|
||||||
> multiplying adjacent symbols with the same `str` identifier and deleting the
|
> multiplying adjacent symbols with the same `id` identifier and deleting the
|
||||||
> identity elements from `W.symbols`.
|
> identity elements from `W.symbols`.
|
||||||
> More specific procedures should be dispatched on `GWord`s type parameter.
|
> More specific procedures should be dispatched on `GWord`s type parameter.
|
||||||
|
|
||||||
@ -196,9 +196,9 @@ end
|
|||||||
|
|
||||||
function show(io::IO, s::T) where {T<:GSymbol}
|
function show(io::IO, s::T) where {T<:GSymbol}
|
||||||
if s.pow == 1
|
if s.pow == 1
|
||||||
print(io, s.str)
|
print(io, string(s.id))
|
||||||
else
|
else
|
||||||
print(io, (s.str)*"^$(s.pow)")
|
print(io, string((s.id))*"^$(s.pow)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ end
|
|||||||
function (==)(s::GSymbol, t::GSymbol)
|
function (==)(s::GSymbol, t::GSymbol)
|
||||||
s.pow == t.pow || return false
|
s.pow == t.pow || return false
|
||||||
s.pow == 0 && return true
|
s.pow == 0 && return true
|
||||||
s.str == t.str || return false
|
s.id == t.id || return false
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ end
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
issubsymbol(s::GSymbol, t::GSymbol) =
|
issubsymbol(s::GSymbol, t::GSymbol) =
|
||||||
s.str == t.str && (0 ≤ s.pow ≤ t.pow || 0 ≥ s.pow ≥ t.pow)
|
s.id == t.id && (0 ≤ s.pow ≤ t.pow || 0 ≥ s.pow ≥ t.pow)
|
||||||
|
|
||||||
"""doc
|
"""doc
|
||||||
Find the first linear index k>=i such that Z < W.symbols[k:k+length(Z)-1]
|
Find the first linear index k>=i such that Z < W.symbols[k:k+length(Z)-1]
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
G = PermutationGroup(Int8(4))
|
G = PermutationGroup(Int8(4))
|
||||||
|
|
||||||
@testset "AutSymbol" begin
|
@testset "AutSymbol" begin
|
||||||
@test_throws MethodError Groups.AutSymbol("a")
|
@test_throws MethodError Groups.AutSymbol(:a)
|
||||||
@test_throws MethodError Groups.AutSymbol("a", 1)
|
@test_throws MethodError Groups.AutSymbol(:a, 1)
|
||||||
f = Groups.AutSymbol("a", 1, Groups.FlipAut(2))
|
f = Groups.AutSymbol(:a, 1, Groups.FlipAut(2))
|
||||||
@test isa(f, Groups.GSymbol)
|
@test isa(f, Groups.GSymbol)
|
||||||
@test isa(f, Groups.AutSymbol)
|
@test isa(f, Groups.AutSymbol)
|
||||||
@test isa(Groups.perm_autsymbol(Int8.([1,2,3,4])), Groups.AutSymbol)
|
@test isa(Groups.perm_autsymbol(Int8.([1,2,3,4])), Groups.AutSymbol)
|
||||||
@ -82,7 +82,7 @@
|
|||||||
|
|
||||||
@testset "AutGroup/Automorphism constructors" begin
|
@testset "AutGroup/Automorphism constructors" begin
|
||||||
|
|
||||||
f = Groups.AutSymbol("a", 1, Groups.FlipAut(1))
|
f = Groups.AutSymbol(:a, 1, Groups.FlipAut(1))
|
||||||
@test isa(Automorphism{3}(f), Groups.GWord)
|
@test isa(Automorphism{3}(f), Groups.GWord)
|
||||||
@test isa(Automorphism{3}(f), Automorphism)
|
@test isa(Automorphism{3}(f), Automorphism)
|
||||||
@test isa(AutGroup(FreeGroup(3)), AbstractAlgebra.Group)
|
@test isa(AutGroup(FreeGroup(3)), AbstractAlgebra.Group)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
@testset "Groups.FreeSymbols" begin
|
@testset "Groups.FreeSymbols" begin
|
||||||
s = Groups.FreeSymbol("s")
|
s = Groups.FreeSymbol(:s)
|
||||||
t = Groups.FreeSymbol("t")
|
t = Groups.FreeSymbol(:t)
|
||||||
|
|
||||||
@testset "constructors" begin
|
@testset "constructors" begin
|
||||||
@test isa(Groups.FreeSymbol("aaaaaaaaaaaaaaaa"), Groups.GSymbol)
|
@test isa(Groups.FreeSymbol(:aaaaaaaaaaaaaaaa), Groups.GSymbol)
|
||||||
@test Groups.FreeSymbol("abc").pow == 1
|
@test Groups.FreeSymbol(:abc).pow == 1
|
||||||
@test isa(s, Groups.FreeSymbol)
|
@test isa(s, Groups.FreeSymbol)
|
||||||
@test isa(t, Groups.FreeSymbol)
|
@test isa(t, Groups.FreeSymbol)
|
||||||
end
|
end
|
||||||
@ -14,20 +14,20 @@
|
|||||||
@test Groups.change_pow(s, 0) == Groups.change_pow(t, 0)
|
@test Groups.change_pow(s, 0) == Groups.change_pow(t, 0)
|
||||||
@test length(Groups.change_pow(s, 0)) == 0
|
@test length(Groups.change_pow(s, 0)) == 0
|
||||||
@test inv(s).pow == -1
|
@test inv(s).pow == -1
|
||||||
@test Groups.FreeSymbol("s", 3) == Groups.change_pow(s, 3)
|
@test Groups.FreeSymbol(:s, 3) == Groups.change_pow(s, 3)
|
||||||
@test Groups.FreeSymbol("s", 3) != Groups.FreeSymbol("t", 3)
|
@test Groups.FreeSymbol(:s, 3) != Groups.FreeSymbol(:t, 3)
|
||||||
@test Groups.change_pow(inv(s), -3) == inv(Groups.change_pow(s, 3))
|
@test Groups.change_pow(inv(s), -3) == inv(Groups.change_pow(s, 3))
|
||||||
end
|
end
|
||||||
@testset "powers" begin
|
@testset "powers" begin
|
||||||
s⁴ = Groups.change_pow(s,4)
|
s⁴ = Groups.change_pow(s,4)
|
||||||
@test s⁴.pow == 4
|
@test s⁴.pow == 4
|
||||||
@test Groups.change_pow(s, 4) == Groups.FreeSymbol("s", 4)
|
@test Groups.change_pow(s, 4) == Groups.FreeSymbol(:s, 4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "FreeGroupSymbols manipulation" begin
|
@testset "FreeGroupSymbols manipulation" begin
|
||||||
s = Groups.FreeSymbol("s")
|
s = Groups.FreeSymbol("s")
|
||||||
t = Groups.FreeSymbol("t", -2)
|
t = Groups.FreeSymbol(:t, -2)
|
||||||
|
|
||||||
@test isa(Groups.GroupWord(s), Groups.GWord{Groups.FreeSymbol})
|
@test isa(Groups.GroupWord(s), Groups.GWord{Groups.FreeSymbol})
|
||||||
@test isa(Groups.GroupWord(s), FreeGroupElem)
|
@test isa(Groups.GroupWord(s), FreeGroupElem)
|
||||||
@ -60,7 +60,7 @@ end
|
|||||||
@test (s*s).symbols == (s^2).symbols
|
@test (s*s).symbols == (s^2).symbols
|
||||||
@test hash([t^1,s^1]) == hash([t^2*inv(t),s*inv(s)*s])
|
@test hash([t^1,s^1]) == hash([t^2*inv(t),s*inv(s)*s])
|
||||||
|
|
||||||
t_symb = Groups.FreeSymbol("t")
|
t_symb = Groups.FreeSymbol(:t)
|
||||||
tt = deepcopy(t)
|
tt = deepcopy(t)
|
||||||
@test string(Groups.r_multiply!(tt,[inv(t_symb)]; reduced=true)) ==
|
@test string(Groups.r_multiply!(tt,[inv(t_symb)]; reduced=true)) ==
|
||||||
"(id)"
|
"(id)"
|
||||||
@ -109,8 +109,8 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
@testset "replacements" begin
|
@testset "replacements" begin
|
||||||
a = Groups.FreeSymbol("a")
|
a = Groups.FreeSymbol(:a)
|
||||||
b = Groups.FreeSymbol("b")
|
b = Groups.FreeSymbol(:b)
|
||||||
@test Groups.issubsymbol(a, Groups.change_pow(a,2)) == true
|
@test Groups.issubsymbol(a, Groups.change_pow(a,2)) == true
|
||||||
@test Groups.issubsymbol(a, Groups.change_pow(a,-2)) == false
|
@test Groups.issubsymbol(a, Groups.change_pow(a,-2)) == false
|
||||||
@test Groups.issubsymbol(b, Groups.change_pow(a,-2)) == false
|
@test Groups.issubsymbol(b, Groups.change_pow(a,-2)) == false
|
||||||
|
Loading…
Reference in New Issue
Block a user