mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-24 18:05:27 +01:00
Make AutSymbol and AutWord callable via fmap and imap
This commit is contained in:
parent
26e3d74800
commit
3ca4563439
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user