mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-24 02:00:30 +01:00
Separation between Groups, FreeGroups and AutGroups
This commit is contained in:
parent
cec6f98392
commit
1189c38504
64
AutGroups.jl
Normal file
64
AutGroups.jl
Normal file
@ -0,0 +1,64 @@
|
||||
module AutGroups
|
||||
|
||||
using Groups
|
||||
using Permutations
|
||||
|
||||
import Base: inv
|
||||
|
||||
export IDSymbol, AutSymbol, AutWord
|
||||
export rmul_AutSymbol, lmul_AutSymbol, flip_AutSymbol, symmetric_AutSymbol
|
||||
|
||||
immutable AutSymbol <: GSymbol
|
||||
gen::String
|
||||
pow::Int
|
||||
ex::Expr
|
||||
end
|
||||
|
||||
IDSymbol(::Type{AutSymbol}) = AutSymbol("(id)", 0, :(IDAutomorphism(N)))
|
||||
|
||||
change_pow(s::AutSymbol, n::Int) = reduce(AutSymbol(s.gen, n, s.ex))
|
||||
|
||||
function inv(f::AutSymbol)
|
||||
symbol = f.ex.args[1]
|
||||
if symbol == :ɛ
|
||||
return change_pow(f, f.pow % 2)
|
||||
elseif symbol == :σ
|
||||
perm = invperm(f.ex.args[2])
|
||||
gen = string('σ', [Char(8320 + i) for i in perm]...)
|
||||
return AutSymbol(gen, f.pow, :(σ($perm)))
|
||||
elseif symbol == :(ϱ) || symbol == :λ
|
||||
return AutSymbol(f.gen, -f.pow, f.ex)
|
||||
elseif symbol == :IDAutomorphism
|
||||
return f
|
||||
else
|
||||
throw(ArgumentError("Don't know how to invert $f (of type $symbol)"))
|
||||
end
|
||||
end
|
||||
|
||||
function rmul_AutSymbol(i,j, pow::Int=1)
|
||||
gen = string('ϱ',Char(8320+i), Char(8320+j)...)
|
||||
return AutSymbol(gen, pow, :(ϱ($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)))
|
||||
end
|
||||
|
||||
function flip_AutSymbol(j, pow::Int=1)
|
||||
gen = string('ɛ', Char(8320 + j))
|
||||
return AutSymbol(gen, pow%2, :(ɛ($j)))
|
||||
end
|
||||
|
||||
function symmetric_AutSymbol(perm::Vector{Int}, pow::Int=1)
|
||||
perm = Permutation(perm)
|
||||
ord = order(perm)
|
||||
pow = pow % ord
|
||||
perm = perm^pow
|
||||
gen = string('σ', [Char(8320 + i) for i in array(perm)]...)
|
||||
return AutSymbol(gen, 1, :(σ($(array(perm)))))
|
||||
end
|
||||
|
||||
typealias AutWord GWord{AutSymbol}
|
||||
|
||||
end #end of module AutGroups
|
25
FreeGroups.jl
Normal file
25
FreeGroups.jl
Normal file
@ -0,0 +1,25 @@
|
||||
module FreeGroups
|
||||
|
||||
using Groups
|
||||
|
||||
import Base: inv, convert
|
||||
|
||||
export FGSymbol, IDSymbol
|
||||
|
||||
immutable FGSymbol <: GSymbol
|
||||
gen::String
|
||||
pow::Int
|
||||
end
|
||||
|
||||
IDSymbol(::Type{FGSymbol}) = FGSymbol("(id)", 0)
|
||||
FGSymbol(x::String) = FGSymbol(x,1)
|
||||
|
||||
inv(s::FGSymbol) = FGSymbol(s.gen, -s.pow)
|
||||
convert(::Type{FGSymbol}, x::String) = FGSymbol(x)
|
||||
change_pow(s::FGSymbol, n::Int) = reduce(FGSymbol(s.gen, n))
|
||||
|
||||
typealias FGWord GWord{FGSymbol}
|
||||
|
||||
FGWord(s::FGSymbol) = FGWord([s])
|
||||
|
||||
end #end of module FreeGroups
|
153
Groups.jl
153
Groups.jl
@ -1,74 +1,33 @@
|
||||
module FreeGroups
|
||||
module Groups
|
||||
|
||||
export GSymbol, AutSymbol, Word, GWord, FGWord, AutWord, FGAutomorphism
|
||||
export GSymbol, GWord
|
||||
export reduce!, reduce
|
||||
|
||||
import Base: length, ==, hash, show
|
||||
import Base: one, inv, reduce, *, ^
|
||||
|
||||
import Base: length, ==, hash, show, convert
|
||||
import Base: *, ^, convert
|
||||
import Base: one, inv, reduce, push!, unshift!
|
||||
|
||||
abstract GSymbol
|
||||
|
||||
immutable FGSymbol <: GSymbol
|
||||
gen::String
|
||||
pow::Int
|
||||
end
|
||||
|
||||
immutable AutSymbol <: GSymbol
|
||||
gen::String
|
||||
pow::Int
|
||||
ex::Expr
|
||||
end
|
||||
|
||||
IDSymbol(::Type{FGSymbol}) = FGSymbol("(id)", 0)
|
||||
IDSymbol(::Type{AutSymbol}) = AutSymbol("(id)", 0, :(IDAutomorphism(N)))
|
||||
FGSymbol(x::String) = FGSymbol(x,1)
|
||||
|
||||
function show(io::IO, s::GSymbol)
|
||||
if s.pow == 1
|
||||
print(io, (s.gen))
|
||||
elseif s.pow == 0
|
||||
print(io, "(id)")
|
||||
if s.pow == 0 || s.pow == 1
|
||||
print(io, s.gen)
|
||||
else
|
||||
print(io, (s.gen)*"^$(s.pow)")
|
||||
end
|
||||
end
|
||||
|
||||
(==)(s::GSymbol, t::GSymbol) = s.gen == t.gen && s.pow == t.pow
|
||||
|
||||
length(s::GSymbol) = (s.pow == 0 ? 0 : 1)
|
||||
|
||||
one{T<:GSymbol}(::Type{T}) = IDSymbol(T)
|
||||
one(s::GSymbol) = one(typeof(s))
|
||||
inv(s::FGSymbol) = FGSymbol(s.gen, -s.pow)
|
||||
|
||||
convert(::Type{FGSymbol}, x::String) = FGSymbol(x)
|
||||
|
||||
reduce(s::GSymbol) = (s.pow == 0 ? one(s) : s)
|
||||
change_pow(s::FGSymbol, n::Int) = reduce(FGSymbol(s.gen, n))
|
||||
change_pow(s::AutSymbol, n::Int) = reduce(AutSymbol(s.gen, n, s.ex))
|
||||
|
||||
(^)(s::GSymbol, n::Integer) = change_pow(s, s.pow*n)
|
||||
|
||||
|
||||
function inv(f::AutSymbol)
|
||||
symbol = f.ex.args[1]
|
||||
if symbol == :ɛ
|
||||
return FreeGroups.change_pow(f, f.pow % 2)
|
||||
elseif symbol == :σ
|
||||
perm = invperm(f.ex.args[2])
|
||||
gen = string('σ', [Char(8320 + i) for i in perm]...)
|
||||
return AutSymbol(gen, f.pow, :(σ($perm)))
|
||||
elseif symbol == :(ϱ) || symbol == :λ
|
||||
return AutSymbol(f.gen, -f.pow, f.ex)
|
||||
elseif symbol == :IDAutomorphism
|
||||
return f
|
||||
else
|
||||
throw(ArgumentError("Don't know how to invert $f (of type $symbol)"))
|
||||
end
|
||||
end
|
||||
|
||||
function (*){T<:GSymbol}(s::T, t::T)
|
||||
return GWord{T}([s])*t
|
||||
end
|
||||
(*){T<:GSymbol}(s::T, t::T) = return GWord{T}([s])*t
|
||||
|
||||
|
||||
abstract Word
|
||||
@ -107,11 +66,7 @@ immutable GWord{T<:GSymbol} <: Word
|
||||
symbols::Vector{T}
|
||||
end
|
||||
|
||||
typealias FGWord GWord{FGSymbol}
|
||||
typealias AutWord GWord{AutSymbol}
|
||||
|
||||
GWord{T<:GSymbol}(s::T) = GWord{T}([s])
|
||||
FGWord(s::FGSymbol) = FGWord([s])
|
||||
|
||||
IDWord{T<:GSymbol}(::Type{T}) = GWord(one(T))
|
||||
IDWord{T<:GSymbol}(W::GWord{T}) = IDWord(T)
|
||||
@ -181,12 +136,9 @@ function show(io::IO, W::GWord)
|
||||
end
|
||||
end
|
||||
|
||||
push!(W::GWord, x) = push!(W.symbols, x...)
|
||||
unshift!(W::GWord, x) = unshift!(W.symbols, x...)
|
||||
|
||||
function r_multiply!(W::GWord, x; reduced::Bool=true)
|
||||
if length(x) > 0
|
||||
push!(W, x)
|
||||
push!(W.symbols, x...)
|
||||
end
|
||||
if reduced
|
||||
reduce!(W)
|
||||
@ -196,7 +148,7 @@ end
|
||||
|
||||
function l_multiply!(W::GWord, x; reduced::Bool=true)
|
||||
if length(x) > 0
|
||||
unshift!(W, reverse(x))
|
||||
unshift!(W.symbols, reverse(x)...)
|
||||
end
|
||||
if reduced
|
||||
reduce!(W)
|
||||
@ -243,85 +195,4 @@ end
|
||||
(^)(x::GWord, n::Integer) = power_by_squaring(x,n)
|
||||
|
||||
|
||||
|
||||
type FGAutomorphism{T<:GSymbol}
|
||||
domain::Vector{T}
|
||||
image::Vector{GWord{T}}
|
||||
map::Function
|
||||
|
||||
function FGAutomorphism{T}(domain::Vector{T}, image::Vector{GWord{T}}, map::Function)
|
||||
length(domain) == length(unique(domain)) ||
|
||||
throw(ArgumentError("The elements of $domain are not unique"))
|
||||
length(domain) == length(image) ||
|
||||
throw(ArgumentError("Dimensions of image and domain must match"))
|
||||
# Set(vcat([[s.gen for s in reduce!(x).symbols]
|
||||
# for x in image]...)) == Set(s.gen for s in domain) ||
|
||||
# throw(ArgumentError("Are You sure that $image defines an automorphism??"))
|
||||
new(domain, image, map)
|
||||
end
|
||||
end
|
||||
|
||||
function show(io::IO, X::FGAutomorphism)
|
||||
title = "Endomorphism of Free Group on $(length(X.domain)) generators, sending"
|
||||
map = ["$x ⟶ $y" for (x,y) in zip(X.domain, X.image)]
|
||||
join(io, vcat(title,map), "\n")
|
||||
end
|
||||
|
||||
(==)(f::FGAutomorphism, g::FGAutomorphism) =
|
||||
f.domain == g.domain && f.image == g.image
|
||||
|
||||
function aut_func_from_table(table::Vector{Tuple{Int,Int}}, GroupIdentity=one(FGWord))
|
||||
if length(table) == 0
|
||||
# warn("The map is not an automorphism")
|
||||
nothing
|
||||
end
|
||||
return v->reduce(*,GroupIdentity, v[idx]^power for (idx, power) in table)
|
||||
end
|
||||
|
||||
function aut_func_from_word(domain, w::GWord)
|
||||
table = Vector{Tuple{Int, Int}}()
|
||||
for s in w.symbols
|
||||
pair = (findfirst([x.gen for x in domain], s.gen), s.pow)
|
||||
push!(table, pair)
|
||||
end
|
||||
return aut_func_from_table(table)
|
||||
end
|
||||
|
||||
function FGMap(domain::Vector{FGSymbol}, image::Vector{GWord})
|
||||
|
||||
function_vector = Vector{Function}()
|
||||
|
||||
for word in image
|
||||
push!(function_vector, aut_func_from_word(domain, word))
|
||||
end
|
||||
|
||||
return v -> Vector{FGWord}([f(v) for f in function_vector])
|
||||
end
|
||||
|
||||
FGAutomorphism(domain::Vector{FGSymbol}, image::Vector{GWord}) =
|
||||
FGAutomorphism(domain, image, FGMap(domain, image))
|
||||
|
||||
FGAutomorphism(domain::Vector{FGSymbol}, image::Vector{FGSymbol}) =
|
||||
FGAutomorphism(domain, Vector{GWord}(image))
|
||||
|
||||
function FGAutomorphism(domain::Vector, image::Vector)
|
||||
FGAutomorphism(Vector{FGSymbol}(domain), Vector{GWord}(image))
|
||||
end
|
||||
|
||||
function FGAutomorphism(domain, image)
|
||||
FGAutomorphism([domain...], [image...])
|
||||
end
|
||||
|
||||
"""Computes the composition g∘f of two morphisms"""
|
||||
function compose(f::FGAutomorphism, g::FGAutomorphism)
|
||||
if length(f.image) != length(g.domain)
|
||||
throw(ArgumentError("Cannot compose $f and $g"))
|
||||
else
|
||||
h(v) = g.map(f.map(v))
|
||||
return FGAutomorphism(f.domain, h(f.domain), h)
|
||||
end
|
||||
end
|
||||
|
||||
(*)(f::FGAutomorphism, g::FGAutomorphism) = compose(f,g)
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user