cosmetic changes to (*) and (^=power_by_squaring)
This commit is contained in:
parent
d3adfdb8b6
commit
3077ec0e8b
|
@ -151,36 +151,36 @@ r_multiply(W::GWord, x; reduced::Bool=true) =
|
||||||
l_multiply(W::GWord, x; reduced::Bool=true) =
|
l_multiply(W::GWord, x; reduced::Bool=true) =
|
||||||
l_multiply!(deepcopy(W),x, reduced=reduced)
|
l_multiply!(deepcopy(W),x, reduced=reduced)
|
||||||
|
|
||||||
(*){T}(W::GWord{T}, Z::GWord{T}) = r_multiply(W, Z.symbols)
|
(*)(W::GWord, Z::GWord) = r_multiply(W, Z.symbols)
|
||||||
(*)(W::GWord, s::GSymbol) = W*GWord(s)
|
(*)(W::GWord, s::GSymbol) = r_multiply(W, [s])
|
||||||
(*)(s::GSymbol, W::GWord) = GWord(s)*W
|
(*)(s::GSymbol, W::GWord) = l_multiply(W, [s])
|
||||||
|
|
||||||
function power_by_squaring{T}(x::GWord{T}, p::Integer)
|
function power_by_squaring(W::GWord, p::Integer)
|
||||||
if p < 0
|
if p < 0
|
||||||
return power_by_squaring(inv(x), -p)
|
return power_by_squaring(inv(W), -p)
|
||||||
elseif p == 0
|
elseif p == 0
|
||||||
return parent(W)()
|
return parent(W)()
|
||||||
elseif p == 1
|
elseif p == 1
|
||||||
return x
|
return W
|
||||||
elseif p == 2
|
elseif p == 2
|
||||||
return x*x
|
return W*W
|
||||||
end
|
end
|
||||||
x = deepcopy(x)
|
W = deepcopy(W)
|
||||||
t = trailing_zeros(p) + 1
|
t = trailing_zeros(p) + 1
|
||||||
p >>= t
|
p >>= t
|
||||||
while (t -= 1) > 0
|
while (t -= 1) > 0
|
||||||
r_multiply!(x, x.symbols)
|
r_multiply!(W, W.symbols)
|
||||||
end
|
end
|
||||||
y = deepcopy(x)
|
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!(x, x.symbols)
|
r_multiply!(W, W.symbols)
|
||||||
end
|
end
|
||||||
r_multiply!(y, x.symbols)
|
r_multiply!(Z, W.symbols)
|
||||||
end
|
end
|
||||||
return y
|
return 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