From 5b1ab66797bb43edd2f0fb0b6283d4154ab37747 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 19 Apr 2020 23:50:13 +0200 Subject: [PATCH 1/2] rework push!, pushfirst!, append!, prepend! and rmul! --- src/arithmetic.jl | 42 ++++++++++++++++++++--------------------- test/AutGroup-tests.jl | 2 +- test/FreeGroup-tests.jl | 23 ++++++++++++++++++---- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 933c5ec..c7e8c21 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -10,30 +10,29 @@ end # Binary operators # -function Base.append!(w::GWord{T}, v::AbstractVector{T}) where T - append!(syllables(w), v) +function Base.push!(w::GWord{T}, s::T) where T <: GSymbol + push!(syllables(w), s) return w end -function Base.prepend!(w::GWord{T}, v::AbstractVector{T}) where T - prepend!(syllables(w), v) +function Base.pushfirst!(w::GWord{T}, s::T) where T <: GSymbol + pushfirst!(syllables(w), s) return w end -Base.append!(w::T, v::T) where T <: GWord = append!(w, syllables(v)) -Base.prepend!(w::T, v::T) where T <: GWord = prepend!(w, syllables(v)) - -for (mul, f) in ((:rmul!, :push!), (:lmul!, :pushfirst!)) - @eval begin - function $mul(out::T, w::T, s::GSymbol) where T <:GWord - resize!(syllables(out), syllablelength(w)) - syllables(out) .= syllables(w) - $f(syllables(out), s) - return freereduce!(out) - end - end +function Base.append!(w::T, v::T) where T <: GWord + append!(syllables(w), syllables(v)) + return w end +function Base.prepend!(w::T, v::T) where T <: GWord + prepend!(syllables(w), syllables(v)) + return w +end + +Base.append!(w::T, v::T, others::Vararg{T,N}) where {N,T <: GWord} = + append!(append!(w, v), others...) + function rmul!(out::T, x::T, y::T) where T<: GWord if out === x out = deepcopy(out) @@ -51,15 +50,16 @@ function rmul!(out::T, x::T, y::T) where T<: GWord end end +rmul!(out::T, v::T) where T<:GWord = freereduce!(append!(out, v)) +lmul!(out::T, v::T) where T<:GWord = freereduce!(prepend!(out, v)) + lmul!(out::T, x::T, y::T) where T <: GWord = rmul!(out, y, x) -function AbstractAlgebra.mul!(out::T, x::T, y::T) where T <: GWord - return rmul!(out, x, y) -end +AbstractAlgebra.mul!(out::T, x::T, y::T) where T <: GWord = rmul!(out, x, y) (*)(W::GW, Z::GW) where GW <: GWord = rmul!(deepcopy(W), W, Z) -(*)(W::GWord, s::GSymbol) = rmul!(deepcopy(W), W, s) -(*)(s::GSymbol, W::GWord) = lmul!(deepcopy(W), W, s) +(*)(W::GWord, s::GSymbol) = freereduce!(push!(deepcopy(W), s)) +(*)(s::GSymbol, W::GWord) = freereduce!(pushfirst!(deepcopy(W), s)) function power_by_squaring(W::GWord, p::Integer) if p < 0 diff --git a/test/AutGroup-tests.jl b/test/AutGroup-tests.jl index 7b29949..17fefcf 100644 --- a/test/AutGroup-tests.jl +++ b/test/AutGroup-tests.jl @@ -139,7 +139,7 @@ @testset "reductions/arithmetic" begin f = Groups.AutSymbol(perm"(1,2,3,4)") - f² = append!(A(f), [f]) + f² = push!(A(f), f) @test Groups.simplifyperms!(Bool, f²) == false @test f²^2 == one(A) @test !isone(f²) diff --git a/test/FreeGroup-tests.jl b/test/FreeGroup-tests.jl index da39e75..bf7520a 100644 --- a/test/FreeGroup-tests.jl +++ b/test/FreeGroup-tests.jl @@ -60,13 +60,28 @@ end t_symb = Groups.FreeSymbol(:t) tt = deepcopy(t) - @test string(Groups.rmul!(tt, tt, inv(t_symb))) == "(id)" + @test string(Groups.rmul!(tt, tt, inv(tt))) == "(id)" tt = deepcopy(t) - @test string(append!(tt, [inv(t_symb)])) == "t*t^-1" + @test string(Groups.lmul!(tt, tt, inv(tt))) == "(id)" + tt = deepcopy(t) - @test string(Groups.lmul!(tt, tt, inv(t_symb))) == "(id)" + push!(tt, inv(t_symb)) + @test string(tt) == "t*t^-1" tt = deepcopy(t) - @test string(prepend!(tt, [inv(t_symb)])) == "t^-1*t" + pushfirst!(tt, inv(t_symb)) + @test string(tt) == "t^-1*t" + + tt = deepcopy(t) + append!(tt, inv(t)) + @test string(tt) == "t*t^-1" + + tt = deepcopy(t) + prepend!(tt, inv(t)) + @test string(tt) == "t^-1*t" + + tt = deepcopy(t) + append!(tt, s, inv(t)) + @test string(tt) == "t*s*t^-1" end @testset "reductions" begin From a63fd76ca8bae5e20d63732a058d50d2eea64383 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 19 Apr 2020 23:51:40 +0200 Subject: [PATCH 2/2] drop julia 1.0, 1.2, 1.3 from travis --- .travis.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec9d8e4..951ff42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,8 @@ os: - linux - osx julia: - - 1.0 - - 1.1 - - 1.2 - 1.3 + - 1.4 - nightly notifications: email: true @@ -16,8 +14,4 @@ matrix: allow_failures: - julia: nightly -## uncomment the following lines to override the default test -# script: - # - julia -e 'Pkg.clone(pwd()); Pkg.build("Groups"); Pkg.test("Groups"; coverage=true)' - codecov: true