From c03882ae69d54f941d17b0d52176000dabe44257 Mon Sep 17 00:00:00 2001 From: kalmar Date: Wed, 17 May 2017 17:46:30 +0200 Subject: [PATCH] add Misc category with: products, generate_balls --- src/Groups.jl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Groups.jl b/src/Groups.jl index 221e6ed..e306917 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -330,6 +330,39 @@ end replace_all(W::GWord, subst_dict::Dict{GWord, GWord}) = replace_all!(deepcopy(W), subst_dict) +############################################################################### +# +# Misc +# +############################################################################### + +function products{T}(X::AbstractVector{T}, Y::AbstractVector{T}) + result = Vector{T}() + seen = Set{T}() + for x in X + for y in Y + z = x*y + if !in(z, seen) + push!(seen, z) + push!(result, z) + end + end + end + return result +end + +function generate_balls(S, Id; radius=2) + sizes = Vector{Int}() + S = unshift!(S, Id) + B = [Id] + for i in 1:radius + B = products(B, S); + push!(sizes, length(B)) + end + return B, sizes +end + + ############################################################################### # # Includes