1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 18:15:29 +01:00

add replace and replace_all functions

This commit is contained in:
kalmar 2017-01-26 12:50:54 +01:00
parent ebecf988ec
commit 986dc7748f

View File

@ -222,6 +222,10 @@ function replace!(W::GWord, index, toreplace::GWord, replacement::GWord; asserts
return W return W
end end
function replace(W::GWord, index, toreplace::GWord, replacement::GWord)
replace!(deepcopy(W), index, toreplace, replacement)
end
function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}}) function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}})
for toreplace in reverse!(sort!(collect(keys(subst_dict)),by=length)) for toreplace in reverse!(sort!(collect(keys(subst_dict)),by=length))
replacement = subst_dict[toreplace] replacement = subst_dict[toreplace]
@ -234,6 +238,8 @@ function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}})
return W return W
end end
replace_all(W::GWord, subst_dict::Dict{GWord, GWord}) = replace_all!(deepcopy(W), subst_dict)
include("free_groups.jl") include("free_groups.jl")
include("automorphism_groups.jl") include("automorphism_groups.jl")