From b125871697320de84575fc4cefa5edca8ee70ad5 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 25 Mar 2020 05:23:06 +0100 Subject: [PATCH] unify the two definitions of generate_balls; rename to metric_ball --- src/Groups.jl | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/Groups.jl b/src/Groups.jl index baf308a..3f5a27d 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -75,45 +75,31 @@ end # # Misc # -############################################################################### -function generate_balls(S::AbstractVector{T}, Id::T=one(parent(first(S))); - radius=2, op=*) where T<:GroupElem +@doc doc""" + gens(G::AbstractFPGroups) +> returns vector of generators of `G`, as its elements. +""" +AbstractAlgebra.gens(G::AbstractFPGroup) = G.(G.gens) + +@doc doc""" + metric_ball(S::Vector{GroupElem}, center=Id; radius=2, op=*) +Compute metric ball as a list of elements of non-decreasing length, given the +word-length metric on group generated by `S`. The ball is centered at `center` +(by default: the identity element). `radius` and `op` keywords specify the +radius and multiplication operation to be used. +""" +function generate_balls(S::AbstractVector{T}, center::T=one(first(S)); + radius=2, op=*) where T<:Union{GroupElem, NCRingElem} sizes = Int[] - B = [Id] + B = [one(first(S))] for i in 1:radius BB = [op(i,j) for (i,j) in Base.product(B,S)] B = unique([B; vec(BB)]) push!(sizes, length(B)) end - return B, sizes + isone(center) && return B, sizes + return c.*B, sizes end -function generate_balls(S::AbstractVector{T}, Id::T=one(parent(first(S))); - radius=2, op=*) where {T<:NCRingElem} - sizes = Int[] - B = [Id] - for i in 1:radius - BB = [op(i,j) for (i,j) in Base.product(B,S)] - B = unique([B; vec(BB)]) - push!(sizes, length(B)) - end - return B, sizes -end - -########### iteration for GFField - - -length(F::AbstractAlgebra.GFField) = order(F) - -function iterate(F::AbstractAlgebra.GFField, s=0) - if s >= order(F) - return nothing - else - return F(s), s+1 - end -end - -eltype(::Type{AbstractAlgebra.GFField{I}}) where I = AbstractAlgebra.gfelem{I} - end # of module Groups