1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-24 18:05:27 +01:00

allow for different group operation in generate_balls/products

This commit is contained in:
kalmar 2017-07-06 09:45:14 +02:00
parent 4b68fe745f
commit ff7bbe8e21

View File

@ -371,12 +371,12 @@ replace_all{T<:GSymbol}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}}) = rep
#
###############################################################################
function products{T<:GroupElem}(X::AbstractVector{T}, Y::AbstractVector{T})
function products{T<:GroupElem}(X::AbstractVector{T}, Y::AbstractVector{T}, op=*)
result = Vector{T}()
seen = Set{T}()
for x in X
for y in Y
z = x*y
z = op(x,y)
if !in(z, seen)
push!(seen, z)
push!(result, z)
@ -386,12 +386,12 @@ function products{T<:GroupElem}(X::AbstractVector{T}, Y::AbstractVector{T})
return result
end
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T; radius=2)
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T; radius=2, op=*)
sizes = Vector{Int}()
S = unshift!(S, Id)
B = [Id]
for i in 1:radius
B = products(B, S);
B = products(B, S, op);
push!(sizes, length(B))
end
return B, sizes