From 6c53b3b7c0896844d9050626e679d7177cb71620 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 25 Mar 2020 00:42:23 +0100 Subject: [PATCH] favour append! and prepend! in place of rmul! and lmul! --- src/AutGroup.jl | 6 ++++-- src/Groups.jl | 50 +++++++++++++++++++------------------------------ 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index ceb9edf..31acf96 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -65,12 +65,14 @@ parent_type(::Automorphism{N}) where N = AutGroup{N} ############################################################################### function (ϱ::RTransvect)(v, pow::Integer=1) - @inbounds Groups.r_multiply!(v[ϱ.i], (v[ϱ.j]^pow).symbols, reduced=false) + append!(v[ϱ.i], v[ϱ.j]^pow) + freereduce!(v[ϱ.i]) return v end function (λ::LTransvect)(v, pow::Integer=1) - @inbounds Groups.l_multiply!(v[λ.i], (v[λ.j]^pow).symbols, reduced=false) + prepend!(v[λ.i], v[λ.j]^pow) + freereduce!(v[λ.i]) return v end diff --git a/src/Groups.jl b/src/Groups.jl index 3840b96..e700437 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -234,44 +234,32 @@ end # ############################################################################### -function AbstractAlgebra.mul!(out::GWord, x::GWord, y::GWord; reduced::Bool=true) - resize!(out.symbols, length(x.symbols)+length(y.symbols)) - for i in eachindex(x.symbols) - out.symbols[i] = x.symbols[i] - end - for i in eachindex(y.symbols) - out.symbols[length(x.symbols)+i] = y.symbols[i] - end - if reduced - reduce!(out) - end - return out +function Base.append!(w::GWord{T}, v::AbstractVector{T}) where T + append!(syllables(w), v) + return w end -function r_multiply!(W::GWord, x; reduced::Bool=true) - if length(x) > 0 - append!(W.symbols, x) - end - if reduced - reduce!(W) - end - return W +function Base.prepend!(w::GWord{T}, v::AbstractVector{T}) where T + prepend!(syllables(w), v) + return w end -function l_multiply!(W::GWord, x; reduced::Bool=true) - if length(x) > 0 - prepend!(W.symbols, x) +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 + $f(syllables(out), s) + return freereduce!(out) + end + end +end + + end end - if reduced - reduce!(W) - end - return W end -r_multiply(W::GWord, x; reduced=true) = - r_multiply!(deepcopy(W),x, reduced=reduced) -l_multiply(W::GWord, x; reduced=true) = - l_multiply!(deepcopy(W),x, reduced=reduced) (*)(W::GWord, Z::GWord) = r_multiply(W, Z.symbols) (*)(W::GWord, s::GSymbol) = r_multiply(W, [s])