mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2025-03-15 00:42:11 +01:00
make multiplication abstract
This commit is contained in:
parent
a3db467bd1
commit
f7bf1598ee
@ -122,10 +122,6 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
(*)(W::FPGroupElem, Z::FPGroupElem) = r_multiply(W, Z.symbols)
|
|
||||||
(*)(W::FPGroupElem, s::FPSymbol) = r_multiply(W, [s])
|
|
||||||
(*)(s::FPSymbol, W::FPGroupElem) = l_multiply(W, [s])
|
|
||||||
|
|
||||||
function reduce!(W::FPGroupElem)
|
function reduce!(W::FPGroupElem)
|
||||||
reduced = false
|
reduced = false
|
||||||
while !reduced
|
while !reduced
|
||||||
|
@ -270,14 +270,32 @@ for (mul, f) in ((:rmul!, :push!), (:lmul!, :pushfirst!))
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
function rmul!(out::T, x::T, y::T) where T<: GWord
|
||||||
|
if out === x
|
||||||
|
out = deepcopy(out)
|
||||||
|
return freereduce!(append!(out, y))
|
||||||
|
elseif out === y
|
||||||
|
out = deepcopy(out)
|
||||||
|
return freereduce!(prepend!(out, x))
|
||||||
|
else
|
||||||
|
slenx = syllablelength(x)
|
||||||
|
sleny = syllablelength(y)
|
||||||
|
resize!(syllables(out), slenx+sleny)
|
||||||
|
syllables(out)[1:slenx] .= syllables(x)
|
||||||
|
syllables(out)[slenx+1:slenx+sleny] .= syllables(y)
|
||||||
|
return freereduce!(out)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
lmul!(out::T, x::T, y::T) where T <: GWord = rmul!(out, y, x)
|
||||||
|
|
||||||
(*)(W::GWord, Z::GWord) = r_multiply(W, Z.symbols)
|
function AbstractAlgebra.mul!(out::T, x::T, y::T) where T <: GWord
|
||||||
(*)(W::GWord, s::GSymbol) = r_multiply(W, [s])
|
return rmul!(out, x, y)
|
||||||
(*)(s::GSymbol, W::GWord) = l_multiply(W, [s])
|
end
|
||||||
|
|
||||||
|
(*)(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)
|
||||||
|
|
||||||
function power_by_squaring(W::GWord, p::Integer)
|
function power_by_squaring(W::GWord, p::Integer)
|
||||||
if p < 0
|
if p < 0
|
||||||
@ -293,18 +311,19 @@ function power_by_squaring(W::GWord, p::Integer)
|
|||||||
t = trailing_zeros(p) + 1
|
t = trailing_zeros(p) + 1
|
||||||
p >>= t
|
p >>= t
|
||||||
while (t -= 1) > 0
|
while (t -= 1) > 0
|
||||||
r_multiply!(W, W.symbols)
|
append!(W, W)
|
||||||
end
|
end
|
||||||
Z = deepcopy(W)
|
Z = deepcopy(W)
|
||||||
while p > 0
|
while p > 0
|
||||||
t = trailing_zeros(p) + 1
|
t = trailing_zeros(p) + 1
|
||||||
p >>= t
|
p >>= t
|
||||||
while (t -= 1) >= 0
|
while (t -= 1) >= 0
|
||||||
r_multiply!(W, W.symbols)
|
append!(W, W)
|
||||||
end
|
end
|
||||||
r_multiply!(Z, W.symbols)
|
append!(Z, W)
|
||||||
end
|
end
|
||||||
return Z
|
|
||||||
|
return freereduce!(Z)
|
||||||
end
|
end
|
||||||
|
|
||||||
(^)(x::GWord, n::Integer) = power_by_squaring(x,n)
|
(^)(x::GWord, n::Integer) = power_by_squaring(x,n)
|
||||||
|
Loading…
Reference in New Issue
Block a user