2017-01-23 19:46:41 +01:00
|
|
|
|
using Permutations
|
|
|
|
|
|
2017-01-24 11:02:42 +01:00
|
|
|
|
import Base: convert
|
2017-01-23 19:46:41 +01:00
|
|
|
|
export AutSymbol, AutWord, rmul_AutSymbol, lmul_AutSymbol, flip_AutSymbol, symmetric_AutSymbol
|
|
|
|
|
|
|
|
|
|
immutable AutSymbol <: GSymbol
|
|
|
|
|
gen::String
|
|
|
|
|
pow::Int
|
|
|
|
|
ex::Expr
|
2017-01-27 12:46:55 +01:00
|
|
|
|
fmap::Function
|
|
|
|
|
imap::Function
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function (f::AutSymbol){T}(v::Vector{GWord{T}})
|
|
|
|
|
if f.pow > 0
|
|
|
|
|
map = f.fmap
|
|
|
|
|
else
|
|
|
|
|
map = f.imap
|
|
|
|
|
end
|
|
|
|
|
for i in 1:abs(f.pow)
|
|
|
|
|
v::Vector{GWord{T}} = map(v)
|
|
|
|
|
end
|
|
|
|
|
return v
|
2017-01-23 19:46:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
(==)(s::AutSymbol, t::AutSymbol) = s.gen == t.gen && s.pow == t.pow
|
|
|
|
|
hash(s::AutSymbol, h::UInt) = hash(s.gen, hash(s.pow, hash(:AutSymbol, h)))
|
|
|
|
|
|
2017-01-27 12:46:55 +01:00
|
|
|
|
IdSymbol(::Type{AutSymbol}) = AutSymbol("(id)", 0, :(Id(N)), v -> Vector{GWord}(v), v -> Vector{GWord}(v))
|
2017-01-23 19:46:41 +01:00
|
|
|
|
|
|
|
|
|
function change_pow(s::AutSymbol, n::Int)
|
|
|
|
|
if n == 0
|
|
|
|
|
return one(s)
|
|
|
|
|
end
|
|
|
|
|
symbol = s.ex.args[1]
|
|
|
|
|
if symbol == :ɛ
|
|
|
|
|
return flip_AutSymbol(s.ex.args[2], pow=n)
|
|
|
|
|
elseif symbol == :σ
|
|
|
|
|
return symmetric_AutSymbol(s.ex.args[2], pow=n)
|
|
|
|
|
elseif symbol == :ϱ
|
|
|
|
|
return rmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
|
|
|
|
|
elseif symbol == :λ
|
|
|
|
|
return lmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
|
2017-01-27 12:46:55 +01:00
|
|
|
|
elseif symbol == :Id
|
2017-01-23 19:46:41 +01:00
|
|
|
|
return s
|
|
|
|
|
else
|
|
|
|
|
warn("Changing an unknown type of symbol! $s")
|
2017-01-27 12:46:55 +01:00
|
|
|
|
return AutSymbol(s.gen, n, s.ex, s.fmap, s.imap)
|
2017-01-23 19:46:41 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-24 11:02:42 +01:00
|
|
|
|
inv(f::AutSymbol) = change_pow(f, -f.pow)
|
2017-01-23 19:46:41 +01:00
|
|
|
|
|
2017-01-27 12:46:55 +01:00
|
|
|
|
function ϱ(i,j)
|
|
|
|
|
# @assert i ≠ j
|
|
|
|
|
return v -> [(k!=i ? GWord(v[k]) : v[i]*v[j]) for k in eachindex(v)]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ϱ_inv(i,j)
|
|
|
|
|
# @assert i ≠ j
|
|
|
|
|
return v -> [(k!=i ? GWord(v[k]) : v[i]*v[j]^-1) for k in eachindex(v)]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function λ(i,j)
|
|
|
|
|
# @assert i ≠ j
|
|
|
|
|
return v -> ([(k!=i ? GWord(v[k]) : v[j]*v[i]) for k in eachindex(v)])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function λ_inv(i,j)
|
|
|
|
|
# @assert i ≠ j
|
|
|
|
|
return v -> ([(k!=i ? GWord(v[k]) : v[j]^-1*v[i]) for k in eachindex(v)])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ɛ(i) = v -> [(k!=i ? GWord(v[k]) : v[k]^-1) for k in eachindex(v)]
|
|
|
|
|
|
|
|
|
|
function σ(perm)
|
|
|
|
|
# @assert sort(perm) == collect(1:length(perm))
|
|
|
|
|
return v -> [GWord(v[perm[k]]) for k in eachindex(v)]
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-23 19:46:41 +01:00
|
|
|
|
function rmul_AutSymbol(i,j; pow::Int=1)
|
|
|
|
|
gen = string('ϱ',Char(8320+i), Char(8320+j)...)
|
2017-01-27 12:46:55 +01:00
|
|
|
|
return AutSymbol(gen, pow, :(ϱ($i,$j)), ϱ(i,j), ϱ_inv(i,j))
|
2017-01-23 19:46:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function lmul_AutSymbol(i,j; pow::Int=1)
|
|
|
|
|
gen = string('λ',Char(8320+i), Char(8320+j)...)
|
2017-01-27 12:46:55 +01:00
|
|
|
|
return AutSymbol(gen, pow, :(λ($i,$j)), λ(i,j), λ_inv(i,j))
|
2017-01-23 19:46:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function flip_AutSymbol(j; pow::Int=1)
|
|
|
|
|
gen = string('ɛ', Char(8320 + j))
|
2017-01-27 12:46:55 +01:00
|
|
|
|
return AutSymbol(gen, (2+ pow%2)%2, :(ɛ($j)), ɛ(j), ɛ(j))
|
2017-01-23 19:46:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function symmetric_AutSymbol(perm::Vector{Int}; pow::Int=1)
|
|
|
|
|
perm = Permutation(perm)
|
|
|
|
|
ord = order(perm)
|
|
|
|
|
pow = pow % ord
|
|
|
|
|
perm = perm^pow
|
2017-01-27 12:46:55 +01:00
|
|
|
|
p = array(perm)
|
|
|
|
|
if p == collect(1:length(p))
|
2017-01-24 12:22:42 +01:00
|
|
|
|
return one(AutSymbol)
|
|
|
|
|
else
|
2017-01-27 12:46:55 +01:00
|
|
|
|
gen = string('σ', [Char(8320 + i) for i in p]...)
|
|
|
|
|
return AutSymbol(gen, 1, :(σ($p)), σ(p), σ(array(inv(perm))))
|
2017-01-24 12:22:42 +01:00
|
|
|
|
end
|
2017-01-23 19:46:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function getperm(s::AutSymbol)
|
|
|
|
|
if s.ex.args[1] == :σ
|
|
|
|
|
return s.ex.args[2]
|
|
|
|
|
else
|
|
|
|
|
throw(ArgumentError("$s is not a permutation automorphism!"))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
typealias AutWord GWord{AutSymbol}
|
|
|
|
|
|
2017-01-27 12:46:55 +01:00
|
|
|
|
function (F::AutWord)(v)
|
|
|
|
|
for f in F.symbols
|
|
|
|
|
v = f(v)
|
|
|
|
|
end
|
|
|
|
|
return v
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-24 11:02:42 +01:00
|
|
|
|
convert(::Type{AutWord}, s::AutSymbol) = GWord(s)
|
|
|
|
|
|
2017-01-23 19:46:41 +01:00
|
|
|
|
function simplify_perms!(W::AutWord)
|
|
|
|
|
reduced = true
|
|
|
|
|
for i in 1:length(W.symbols) - 1
|
|
|
|
|
current = W.symbols[i]
|
|
|
|
|
if current.ex.args[1] == :σ
|
|
|
|
|
if current.pow != 1
|
|
|
|
|
current = symmetric_AutSymbol(perm(current), pow=current.pow)
|
|
|
|
|
end
|
|
|
|
|
next_s = W.symbols[i+1]
|
|
|
|
|
if next_s.ex.args[1] == :σ
|
|
|
|
|
reduced = false
|
|
|
|
|
if next_s.pow != 1
|
|
|
|
|
next_s = symmetric_AutSymbol(perm(next_s), pow=next_s.pow)
|
|
|
|
|
end
|
|
|
|
|
p1 = Permutation(getperm(current))
|
|
|
|
|
p2 = Permutation(getperm(next_s))
|
|
|
|
|
W.symbols[i] = one(AutSymbol)
|
|
|
|
|
W.symbols[i+1] = symmetric_AutSymbol(array(p1*p2))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-24 13:06:21 +01:00
|
|
|
|
deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols))
|
2017-01-23 19:46:41 +01:00
|
|
|
|
return reduced
|
|
|
|
|
end
|
2017-01-31 16:59:10 +01:00
|
|
|
|
|
|
|
|
|
function reduce!(W::AutWord)
|
|
|
|
|
if length(W) < 2
|
|
|
|
|
deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols))
|
|
|
|
|
else
|
|
|
|
|
reduced = false
|
|
|
|
|
while !reduced
|
|
|
|
|
reduced = join_free_symbols!(W)
|
|
|
|
|
reduced = simplify_perms!(W)
|
|
|
|
|
deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
W.modified = false
|
|
|
|
|
W.savedhash = hash(W.symbols,hash(typeof(W)))
|
|
|
|
|
return W
|
|
|
|
|
end
|