Skip to content

Commit

Permalink
rename PRASampler to ProductReplacementSampler
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Nov 19, 2024
1 parent dde4eb5 commit 79486a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions docs/src/groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ istrivial(G::Group)
We provide two methods for generating random elements of a group or monoid.

```@docs
PRASampler
RandomWordSampler
GroupsCore.ProductReplacementSampler
GroupsCore.RandomWordSampler
```

By default for finite monoids `PRASampler` is used and
By default for finite monoids `ProductReplacementSampler` is used and
`RandomWordSampler` following `Poisson(λ=8)` is employed for inifinite ones.
14 changes: 7 additions & 7 deletions src/rand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Random.Sampler(
repetition::Random.Repetition = Val(Inf),
)
if isfinite(M)
return PRASampler(RNG(), M)
return ProductReplacementSampler(RNG(), M)
else
# for infinite groups/monoids PRA will either return
# ridiculously long words or just run out of memory
Expand All @@ -19,7 +19,7 @@ function Random.Sampler(
end

"""
PRASampler
ProductReplacementSampler
Implements Product Replacement Algorithm for a group or monoid generated by
an explicit finite set of generators.
Expand All @@ -43,22 +43,22 @@ finite groups. For infinite groups [`RandomWordSampler`](@ref) is used.
growth of words during scrambling will result in excessive memory use and
out-of-memory situation.
"""
mutable struct PRASampler{T} <: Random.Sampler{T}
mutable struct ProductReplacementSampler{T} <: Random.Sampler{T}
gentuple::Vector{T}
right::T
left::T
end

# constants taken from GAP
function PRASampler(
function ProductReplacementSampler(
rng::Random.AbstractRNG,
M::Monoid,
n::Integer = 2ngens(M) + 10,
scramble_time::Integer = 10max(n, 10),
)
@assert hasgens(M)
if istrivial(M)
return PRASampler(fill(one(M), n), one(M), one(M))
return ProductReplacementSampler(fill(one(M), n), one(M), one(M))
end
@assert hasgens(M)
l = max(n, 2ngens(M), 2)
Expand All @@ -67,15 +67,15 @@ function PRASampler(
S = union!(S, inv.(S))
end
append!(S, rand(rng, S, l - length(S)))
PRASampler(S, one(M), one(M))
ProductReplacementSampler(S, one(M), one(M))
end
for _ in 1:scramble_time
_ = rand(rng, sampler)
end
return sampler
end

function Random.rand(rng::Random.AbstractRNG, pra::PRASampler)
function Random.rand(rng::Random.AbstractRNG, pra::ProductReplacementSampler)
i = rand(rng, 1:length(pra.gentuple))

pra.right = pra.right * rand(rng, pra.gentuple)
Expand Down

0 comments on commit 79486a5

Please sign in to comment.