simplify type of AutSymbols

This commit is contained in:
kalmarek 2019-01-03 03:37:02 +01:00
parent 2a359f52b1
commit 3cc6262356
1 changed files with 35 additions and 26 deletions

View File

@ -4,22 +4,22 @@
# #
############################################################################### ###############################################################################
struct RTransvect{I<:Integer} struct RTransvect
i::I i::Int8
j::I j::Int8
end end
struct LTransvect{I<:Integer} struct LTransvect
i::I i::Int8
j::I j::Int8
end end
struct FlipAut{I<:Integer} struct FlipAut
i::I i::Int8
end end
struct PermAut{I<:Integer} struct PermAut
perm::Generic.perm{I} perm::Generic.perm{Int8}
end end
struct Identity end struct Identity end
@ -41,8 +41,9 @@ mutable struct Automorphism{N} <: GWord{AutSymbol}
savedhash::UInt savedhash::UInt
parent::AutGroup{N} parent::AutGroup{N}
Automorphism{N}(f::Vector{AutSymbol}) where N = new(f, true, zero(UInt)) function Automorphism{N}(f::Vector{AutSymbol}) where {N}
return new{N}(f, true, zero(UInt))
end
end end
export Automorphism, AutGroup, Aut, SAut export Automorphism, AutGroup, Aut, SAut
@ -63,39 +64,47 @@ parent_type(::Automorphism{N}) where N = AutGroup{N}
# #
############################################################################### ###############################################################################
function (ϱ::RTransvect{I})(v, pow::Integer=one(I)) where I function (ϱ::RTransvect)(v, pow::Integer=1)
@inbounds Groups.r_multiply!(v[ϱ.i], (v[ϱ.j]^pow).symbols, reduced=false) @inbounds Groups.r_multiply!(v[ϱ.i], (v[ϱ.j]^pow).symbols, reduced=false)
return v return v
end end
function (λ::LTransvect{I})(v, pow::Integer=one(I)) where I function (λ::LTransvect)(v, pow::Integer=1)
@inbounds Groups.l_multiply!(v[λ.i], (v[λ.j]^pow).symbols, reduced=false) @inbounds Groups.l_multiply!(v[λ.i], (v[λ.j]^pow).symbols, reduced=false)
return v return v
end end
function (σ::PermAut{I})(v, pow::Integer=one(I)) where I function (σ::PermAut)(v, pow::Integer=1)
w = deepcopy(v) w = deepcopy(v)
s = (σ.perm^pow).d if pow == 1
@inbounds for k in eachindex(v) @inbounds for k in eachindex(v)
v[k].symbols = w[s[k]].symbols v[k].symbols = w[σ.perm.d[k]].symbols
end
else
s = (σ.perm^pow).d
@inbounds for k in eachindex(v)
v[k].symbols = w[s[k]].symbols
end
end end
return v return v
end end
function (ɛ::FlipAut{I})(v, pow::Integer=one(I)) where I function (ɛ::FlipAut)(v, pow::Integer=1)
@inbounds if isodd(pow) @inbounds if isodd(pow)
v[ɛ.i].symbols = inv(v[ɛ.i]).symbols v[ɛ.i].symbols = inv(v[ɛ.i]).symbols
end end
return v return v
end end
(::Identity)(v, pow::Integer=zero(Int8)) = v (::Identity)(v, pow::Integer=1) = v
# taken from ValidatedNumerics, under under the MIT "Expat" License: # taken from ValidatedNumerics, under under the MIT "Expat" License:
# https://github.com/JuliaIntervals/ValidatedNumerics.jl/blob/master/LICENSE.md # https://github.com/JuliaIntervals/ValidatedNumerics.jl/blob/master/LICENSE.md
function subscriptify(n::Integer) function subscriptify(n::Integer)
subscript_0 = Int(0x2080) # Char(0x2080) -> subscript 0 subscript_0 = Int(0x2080) # Char(0x2080) -> subscript 0
return join([Char(subscript_0 + i) for i in reverse(digits(n))]) @assert 0 <= n <= 9
return Char(subscript_0 + n)
# return [Char(subscript_0 + i) for i in reverse(digits(n))])
end end
function id_autsymbol() function id_autsymbol()
@ -123,7 +132,9 @@ function flip_autsymbol(i::I; pow::Integer=one(I)) where I<:Integer
end end
function perm_autsymbol(p::Generic.perm{I}; pow::Integer=one(I)) where I<:Integer function perm_autsymbol(p::Generic.perm{I}; pow::Integer=one(I)) where I<:Integer
p = p^pow if pow != 1
p = p^pow
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]) str = "σ"*join([subscriptify(i) for i in p.d])
@ -154,9 +165,7 @@ function AutGroup(G::FreeGroup; special=false)
n = length(gens(G)) n = length(gens(G))
n == 0 && return AutGroup{n}(G, S) n == 0 && return AutGroup{n}(G, S)
n = convert(Int8, n) indexing = [[i,j] for i in 1:n for j in 1:n if i≠j]
indexing = [[i,j] for i in Int8(1):n for j in Int8(1):n if i≠j]
rmuls = [rmul_autsymbol(i,j) for (i,j) in indexing] rmuls = [rmul_autsymbol(i,j) for (i,j) in indexing]
lmuls = [lmul_autsymbol(i,j) for (i,j) in indexing] lmuls = [lmul_autsymbol(i,j) for (i,j) in indexing]
@ -170,7 +179,7 @@ function AutGroup(G::FreeGroup; special=false)
append!(S, [flips; syms]) append!(S, [flips; syms])
end end
return AutGroup{Int64(n)}(G, S) return AutGroup{n}(G, S)
end end
Aut(G::Group) = AutGroup(G) Aut(G::Group) = AutGroup(G)