Merge pull request #7 from kalmarek/enh/rework_push_append_mul

Enh/rework push append mul
This commit is contained in:
kalmarek 2020-04-20 00:01:29 +02:00 committed by GitHub
commit b6634b3735
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -139,7 +139,7 @@
@testset "reductions/arithmetic" begin
f = Groups.AutSymbol(perm"(1,2,3,4)")
= append!(A(f), [f])
= push!(A(f), f)
@test Groups.simplifyperms!(Bool, ) == false
@test ^2 == one(A)
@test !isone()

View File

@ -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