mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
Merge pull request #2 from abulak/enh/make_automorphisms_functional
Enh/make automorphisms functional
This commit is contained in:
commit
b7d26bc132
@ -7,19 +7,31 @@ immutable AutSymbol <: GSymbol
|
|||||||
gen::String
|
gen::String
|
||||||
pow::Int
|
pow::Int
|
||||||
ex::Expr
|
ex::Expr
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
(==)(s::AutSymbol, t::AutSymbol) = s.gen == t.gen && s.pow == t.pow
|
(==)(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)))
|
hash(s::AutSymbol, h::UInt) = hash(s.gen, hash(s.pow, hash(:AutSymbol, h)))
|
||||||
|
|
||||||
IdSymbol(::Type{AutSymbol}) = AutSymbol("(id)", 0, :(IdAutomorphism(N)))
|
IdSymbol(::Type{AutSymbol}) = AutSymbol("(id)", 0, :(Id(N)), v -> Vector{GWord}(v), v -> Vector{GWord}(v))
|
||||||
|
|
||||||
function change_pow(s::AutSymbol, n::Int)
|
function change_pow(s::AutSymbol, n::Int)
|
||||||
|
|
||||||
if n == 0
|
if n == 0
|
||||||
return one(s)
|
return one(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
symbol = s.ex.args[1]
|
symbol = s.ex.args[1]
|
||||||
if symbol == :ɛ
|
if symbol == :ɛ
|
||||||
return flip_AutSymbol(s.ex.args[2], pow=n)
|
return flip_AutSymbol(s.ex.args[2], pow=n)
|
||||||
@ -29,29 +41,58 @@ function change_pow(s::AutSymbol, n::Int)
|
|||||||
return rmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
|
return rmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
|
||||||
elseif symbol == :λ
|
elseif symbol == :λ
|
||||||
return lmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
|
return lmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
|
||||||
elseif symbol == :IdAutomorphism
|
elseif symbol == :Id
|
||||||
return s
|
return s
|
||||||
else
|
else
|
||||||
warn("Changing an unknown type of symbol! $s")
|
warn("Changing an unknown type of symbol! $s")
|
||||||
return AutSymbol(s.gen, n, s.ex)
|
return AutSymbol(s.gen, n, s.ex, s.fmap, s.imap)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
inv(f::AutSymbol) = change_pow(f, -f.pow)
|
inv(f::AutSymbol) = change_pow(f, -f.pow)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
function rmul_AutSymbol(i,j; pow::Int=1)
|
function rmul_AutSymbol(i,j; pow::Int=1)
|
||||||
gen = string('ϱ',Char(8320+i), Char(8320+j)...)
|
gen = string('ϱ',Char(8320+i), Char(8320+j)...)
|
||||||
return AutSymbol(gen, pow, :(ϱ($i,$j)))
|
return AutSymbol(gen, pow, :(ϱ($i,$j)), ϱ(i,j), ϱ_inv(i,j))
|
||||||
end
|
end
|
||||||
|
|
||||||
function lmul_AutSymbol(i,j; pow::Int=1)
|
function lmul_AutSymbol(i,j; pow::Int=1)
|
||||||
gen = string('λ',Char(8320+i), Char(8320+j)...)
|
gen = string('λ',Char(8320+i), Char(8320+j)...)
|
||||||
return AutSymbol(gen, pow, :(λ($i,$j)))
|
return AutSymbol(gen, pow, :(λ($i,$j)), λ(i,j), λ_inv(i,j))
|
||||||
end
|
end
|
||||||
|
|
||||||
function flip_AutSymbol(j; pow::Int=1)
|
function flip_AutSymbol(j; pow::Int=1)
|
||||||
gen = string('ɛ', Char(8320 + j))
|
gen = string('ɛ', Char(8320 + j))
|
||||||
return AutSymbol(gen, (2+ pow%2)%2, :(ɛ($j)))
|
return AutSymbol(gen, (2+ pow%2)%2, :(ɛ($j)), ɛ(j), ɛ(j))
|
||||||
end
|
end
|
||||||
|
|
||||||
function symmetric_AutSymbol(perm::Vector{Int}; pow::Int=1)
|
function symmetric_AutSymbol(perm::Vector{Int}; pow::Int=1)
|
||||||
@ -59,11 +100,12 @@ function symmetric_AutSymbol(perm::Vector{Int}; pow::Int=1)
|
|||||||
ord = order(perm)
|
ord = order(perm)
|
||||||
pow = pow % ord
|
pow = pow % ord
|
||||||
perm = perm^pow
|
perm = perm^pow
|
||||||
if array(perm) == collect(1:length(perm))
|
p = array(perm)
|
||||||
|
if p == collect(1:length(p))
|
||||||
return one(AutSymbol)
|
return one(AutSymbol)
|
||||||
else
|
else
|
||||||
gen = string('σ', [Char(8320 + i) for i in array(perm)]...)
|
gen = string('σ', [Char(8320 + i) for i in p]...)
|
||||||
return AutSymbol(gen, 1, :(σ($(array(perm)))))
|
return AutSymbol(gen, 1, :(σ($p)), σ(p), σ(array(inv(perm))))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -77,6 +119,13 @@ end
|
|||||||
|
|
||||||
typealias AutWord GWord{AutSymbol}
|
typealias AutWord GWord{AutSymbol}
|
||||||
|
|
||||||
|
function (F::AutWord)(v)
|
||||||
|
for f in F.symbols
|
||||||
|
v = f(v)
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
convert(::Type{AutWord}, s::AutSymbol) = GWord(s)
|
convert(::Type{AutWord}, s::AutSymbol) = GWord(s)
|
||||||
|
|
||||||
function simplify_perms!(W::AutWord)
|
function simplify_perms!(W::AutWord)
|
||||||
|
@ -113,7 +113,7 @@ end
|
|||||||
@testset "AutSymbol" begin
|
@testset "AutSymbol" begin
|
||||||
@test_throws MethodError AutSymbol("a")
|
@test_throws MethodError AutSymbol("a")
|
||||||
@test_throws MethodError AutSymbol("a", 1)
|
@test_throws MethodError AutSymbol("a", 1)
|
||||||
f = AutSymbol("a", 1, :(a(0)))
|
f = AutSymbol("a", 1, :(a(0)), v -> v, v -> v)
|
||||||
@test isa(f, GSymbol)
|
@test isa(f, GSymbol)
|
||||||
@test isa(f, AutSymbol)
|
@test isa(f, AutSymbol)
|
||||||
@test isa(symmetric_AutSymbol([1,2,3,4]), AutSymbol)
|
@test isa(symmetric_AutSymbol([1,2,3,4]), AutSymbol)
|
||||||
@ -123,7 +123,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
@testset "AutWords" begin
|
@testset "AutWords" begin
|
||||||
f = AutSymbol("a", 1, :(a(0)))
|
f = AutSymbol("a", 1, :(a(0)), v -> v, v -> v)
|
||||||
@test isa(GWord(f), GWord)
|
@test isa(GWord(f), GWord)
|
||||||
@test isa(GWord(f), AutWord)
|
@test isa(GWord(f), AutWord)
|
||||||
@test isa(AutWord(f), AutWord)
|
@test isa(AutWord(f), AutWord)
|
||||||
|
Loading…
Reference in New Issue
Block a user