From 13edfe7c7678e7a902b48a7c53866f3fe449c09a Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 24 Jan 2017 12:30:23 +0100 Subject: [PATCH 1/4] add travis master status --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e97b3e9..9e070e8 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # Groups +[![Build Status](https://travis-ci.org/abulak/Groups.jl.svg?branch=master)](https://travis-ci.org/abulak/Groups.jl) From 57f0559eae537784e7fee1913c7b4c3f2d7eedd6 Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 24 Jan 2017 12:30:45 +0100 Subject: [PATCH 2/4] cosmetics --- src/Groups.jl | 1 - src/free_groups.jl | 2 +- test/runtests.jl | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Groups.jl b/src/Groups.jl index 97b7a41..3b4a7b3 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -28,7 +28,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 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 a35dbff..7ed2238 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) From e98784bd987bb982605f7d13d54a2bdeb34ded07 Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 31 Jan 2017 16:56:49 +0100 Subject: [PATCH 3/4] =?UTF-8?q?rename=20freegroup=5Freduce=20=E2=86=92=20r?= =?UTF-8?q?educe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Groups.jl | 17 ++++++++--------- test/runtests.jl | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Groups.jl b/src/Groups.jl index 910cd4f..7cfb6db 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -78,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 @@ -94,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 @@ -123,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 @@ -133,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 @@ -221,8 +221,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/test/runtests.jl b/test/runtests.jl index d32f6d2..c5845cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 From 5bfd4858a015f6f4039d9adff37e4e4f72adcebc Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 31 Jan 2017 16:59:10 +0100 Subject: [PATCH 4/4] overload reduce function for AutWords --- src/automorphism_groups.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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