mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-26 02:20:30 +01:00
rework push!, pushfirst!, append!, prepend! and rmul!
This commit is contained in:
parent
c3eb34eee8
commit
5b1ab66797
@ -10,30 +10,29 @@ end
|
|||||||
# Binary operators
|
# Binary operators
|
||||||
#
|
#
|
||||||
|
|
||||||
function Base.append!(w::GWord{T}, v::AbstractVector{T}) where T
|
function Base.push!(w::GWord{T}, s::T) where T <: GSymbol
|
||||||
append!(syllables(w), v)
|
push!(syllables(w), s)
|
||||||
return w
|
return w
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.prepend!(w::GWord{T}, v::AbstractVector{T}) where T
|
function Base.pushfirst!(w::GWord{T}, s::T) where T <: GSymbol
|
||||||
prepend!(syllables(w), v)
|
pushfirst!(syllables(w), s)
|
||||||
return w
|
return w
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.append!(w::T, v::T) where T <: GWord = append!(w, syllables(v))
|
function Base.append!(w::T, v::T) where T <: GWord
|
||||||
Base.prepend!(w::T, v::T) where T <: GWord = prepend!(w, syllables(v))
|
append!(syllables(w), syllables(v))
|
||||||
|
return w
|
||||||
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
|
|
||||||
end
|
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
|
function rmul!(out::T, x::T, y::T) where T<: GWord
|
||||||
if out === x
|
if out === x
|
||||||
out = deepcopy(out)
|
out = deepcopy(out)
|
||||||
@ -51,15 +50,16 @@ function rmul!(out::T, x::T, y::T) where T<: GWord
|
|||||||
end
|
end
|
||||||
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)
|
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
|
AbstractAlgebra.mul!(out::T, x::T, y::T) where T <: GWord = rmul!(out, x, y)
|
||||||
return rmul!(out, x, y)
|
|
||||||
end
|
|
||||||
|
|
||||||
(*)(W::GW, Z::GW) where GW <: GWord = rmul!(deepcopy(W), W, Z)
|
(*)(W::GW, Z::GW) where GW <: GWord = rmul!(deepcopy(W), W, Z)
|
||||||
(*)(W::GWord, s::GSymbol) = rmul!(deepcopy(W), W, s)
|
(*)(W::GWord, s::GSymbol) = freereduce!(push!(deepcopy(W), s))
|
||||||
(*)(s::GSymbol, W::GWord) = lmul!(deepcopy(W), W, s)
|
(*)(s::GSymbol, W::GWord) = freereduce!(pushfirst!(deepcopy(W), s))
|
||||||
|
|
||||||
function power_by_squaring(W::GWord, p::Integer)
|
function power_by_squaring(W::GWord, p::Integer)
|
||||||
if p < 0
|
if p < 0
|
||||||
|
@ -139,7 +139,7 @@
|
|||||||
@testset "reductions/arithmetic" begin
|
@testset "reductions/arithmetic" begin
|
||||||
f = Groups.AutSymbol(perm"(1,2,3,4)")
|
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 Groups.simplifyperms!(Bool, f²) == false
|
||||||
@test f²^2 == one(A)
|
@test f²^2 == one(A)
|
||||||
@test !isone(f²)
|
@test !isone(f²)
|
||||||
|
@ -60,13 +60,28 @@ end
|
|||||||
|
|
||||||
t_symb = Groups.FreeSymbol(:t)
|
t_symb = Groups.FreeSymbol(:t)
|
||||||
tt = deepcopy(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)
|
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)
|
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)
|
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
|
end
|
||||||
|
|
||||||
@testset "reductions" begin
|
@testset "reductions" begin
|
||||||
|
Loading…
Reference in New Issue
Block a user