Groups.jl/src/wl_ball.jl

37 lines
1.1 KiB
Julia
Raw Normal View History

2021-06-21 18:16:04 +02:00
"""
wlmetric_ball(S::AbstractVector{<:GroupElem}
[, center=one(first(S)); radius=2, op=*])
2021-06-21 18:16:04 +02:00
Compute metric ball as a list of elements of non-decreasing length, given the
word-length metric on the 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.
"""
2022-10-14 01:14:38 +02:00
function wlmetric_ball(
S::AbstractVector{T},
2023-03-15 19:07:14 +01:00
center::T = one(first(S));
radius = 2,
op = *,
2022-10-14 01:14:38 +02:00
) where {T}
ball = [center]
sizes = [1]
if radius 0
return ball, sizes[2:end]
else
ball = union!(ball, [center * s for s in S])
push!(sizes, length(ball))
if radius == 1
return ball, sizes[2:end]
else
for _ in 2:radius
new = collect(
op(o, s) for o in @view(ball[sizes[end-1]:end]) for s in S
)
2023-05-25 11:57:32 +02:00
ball = union!(ball, new)
push!(sizes, length(ball))
end
2021-06-21 18:16:04 +02:00
end
return ball, sizes[2:end]
2021-06-21 18:16:04 +02:00
end
# return wlmetric_ball_serial(S, center; radius = radius, op = op)
2021-06-21 18:16:04 +02:00
end