1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 02:05:30 +01:00

Merge pull request #2 from abulak/enh/make_automorphisms_functional

Enh/make automorphisms functional
This commit is contained in:
kalmar 2017-01-27 14:24:59 +01:00 committed by GitHub
commit b7d26bc132
2 changed files with 62 additions and 13 deletions

View File

@ -7,19 +7,31 @@ immutable AutSymbol <: GSymbol
gen::String
pow::Int
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
(==)(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)))
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)
if n == 0
return one(s)
end
symbol = s.ex.args[1]
if symbol ==
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)
elseif symbol ==
return lmul_AutSymbol(s.ex.args[2], s.ex.args[3], pow=n)
elseif symbol == :IdAutomorphism
elseif symbol == :Id
return s
else
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
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)
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
function lmul_AutSymbol(i,j; pow::Int=1)
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
function flip_AutSymbol(j; pow::Int=1)
gen = string('ɛ', Char(8320 + j))
return AutSymbol(gen, (2+ pow%2)%2, :(ɛ($j)))
return AutSymbol(gen, (2+ pow%2)%2, :(ɛ($j)), ɛ(j), ɛ(j))
end
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)
pow = pow % ord
perm = perm^pow
if array(perm) == collect(1:length(perm))
p = array(perm)
if p == collect(1:length(p))
return one(AutSymbol)
else
gen = string('σ', [Char(8320 + i) for i in array(perm)]...)
return AutSymbol(gen, 1, :(σ($(array(perm)))))
gen = string('σ', [Char(8320 + i) for i in p]...)
return AutSymbol(gen, 1, :(σ($p)), σ(p), σ(array(inv(perm))))
end
end
@ -77,6 +119,13 @@ end
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)
function simplify_perms!(W::AutWord)

View File

@ -113,7 +113,7 @@ end
@testset "AutSymbol" begin
@test_throws MethodError AutSymbol("a")
@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, AutSymbol)
@test isa(symmetric_AutSymbol([1,2,3,4]), AutSymbol)
@ -123,7 +123,7 @@ end
end
@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), AutWord)
@test isa(AutWord(f), AutWord)