diff --git a/src/Groups.jl b/src/Groups.jl index e89eef9..effdbb6 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -29,7 +29,6 @@ one(s::GSymbol) = one(typeof(s)) change_pow(s::GSymbol, n::Int) = throw(ArgumentError("Define change_pow function for $(typeof(s))!")) - abstract Word type GWord{T<:GSymbol} <: Word @@ -79,7 +78,7 @@ function join_free_symbols!(W::GWord) return reduced end -function freegroup_reduce!{T}(W::GWord{T}) +function reduce!{T}(W::GWord{T}) if length(W) < 2 deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols)) else @@ -95,16 +94,16 @@ function freegroup_reduce!{T}(W::GWord{T}) return W end -freegroup_reduce(W::GWord) = freegroup_reduce!(deepcopy(W)) +reduce(W::GWord) = reduce!(deepcopy(W)) function hash{T}(W::GWord{T}, h::UInt) - W.modified && freegroup_reduce!(W) + W.modified && reduce!(W) return W.savedhash + h end function (==){T}(W::GWord{T}, Z::GWord{T}) - W.modified && freegroup_reduce!(W) # reduce clears the flag and recalculate the hash - Z.modified && freegroup_reduce!(Z) + W.modified && reduce!(W) # reduce clears the flag and recalculate the hash + Z.modified && reduce!(Z) return W.savedhash == Z.savedhash && W.symbols == Z.symbols end @@ -124,7 +123,7 @@ function r_multiply!(W::GWord, x; reduced::Bool=true) push!(W.symbols, x...) end if reduced - freegroup_reduce!(W) + reduce!(W) end return W end @@ -134,7 +133,7 @@ function l_multiply!(W::GWord, x; reduced::Bool=true) unshift!(W.symbols, reverse(x)...) end if reduced - freegroup_reduce!(W) + reduce!(W) end return W end @@ -223,8 +222,7 @@ function replace!(W::GWord, index, toreplace::GWord, replacement::GWord; asserts last = W.symbols[index+n-1]*inv(toreplace.symbols[end]) replacement = first*replacement*last splice!(W.symbols, index:index+n-1, replacement.symbols) - Groups.freegroup_reduce!(W) - return W + return reduce!(W) end function replace(W::GWord, index, toreplace::GWord, replacement::GWord) diff --git a/src/automorphism_groups.jl b/src/automorphism_groups.jl index 25ee5a1..3272b2a 100644 --- a/src/automorphism_groups.jl +++ b/src/automorphism_groups.jl @@ -152,3 +152,20 @@ function simplify_perms!(W::AutWord) deleteat!(W.symbols, find(x -> x.pow == 0, W.symbols)) return reduced end + +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 diff --git a/src/free_groups.jl b/src/free_groups.jl index bc149f5..feb8a7b 100644 --- a/src/free_groups.jl +++ b/src/free_groups.jl @@ -1,4 +1,4 @@ -import Base:convert +import Base: convert export FGSymbol, FGWord diff --git a/test/runtests.jl b/test/runtests.jl index 8573a5b..c5845cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,7 +35,7 @@ t = FGSymbol("t") end end -@testset "GWords" begin +@testset "FGWords" begin @testset "defines" begin @test isa(Groups.GWord(s), Groups.GWord) @test isa(Groups.GWord(s), FGWord) @@ -69,14 +69,14 @@ end @test one(FGWord) == one(s)*one(s) w = GWord{FGSymbol}([s]) push!(w.symbols, (s^-1).symbols[1]) - @test Groups.freegroup_reduce!(w) == one(FGWord) + @test Groups.reduce!(w) == one(FGWord) o = (t*s)^3 @test o == t*s*t*s*t*s p = (t*s)^-3 @test p == s^-1*t^-1*s^-1*t^-1*s^-1*t^-1 @test o*p == one(FGWord) w = FGWord([o.symbols..., p.symbols...]) - @test Groups.freegroup_reduce!(w).symbols ==Vector{FGSymbol}([]) + @test Groups.reduce!(w).symbols ==Vector{FGSymbol}([]) end @testset "arithmetic" begin @test Groups.r_multiply!(FGWord(t),[s,t]; reduced=true) == t*s*t