Groups.jl/src/normalform.jl

49 lines
1.3 KiB
Julia
Raw Permalink Normal View History

2021-05-05 01:10:28 +02:00
"""
normalform!(g::FPGroupElement)
Compute the normal form of `g`, possibly modifying `g` in-place.
"""
@inline function normalform!(g::AbstractFPGroupElement; force = false)
if !force
isnormalform(g) && return g
end
2021-05-05 01:10:28 +02:00
let w = one(word(g))
w = normalform!(w, g)
resize!(word(g), length(w))
copyto!(word(g), w)
end
2021-05-07 18:11:11 +02:00
_setnormalform!(g, true)
_setvalidhash!(g, false)
2021-05-05 01:10:28 +02:00
@assert isnormalform(g)
return g
end
"""
normalform!(res::GEl, g::GEl) where GEl<:FPGroupElement
Compute the normal fom of `g`, storing it in `res`.
"""
2021-06-29 16:52:35 +02:00
function normalform!(res::GEl, g::GEl) where {GEl<:AbstractFPGroupElement}
2021-05-05 01:10:28 +02:00
@boundscheck @assert parent(res) === parent(g)
if isnormalform(g)
copyto!(res, g)
else
resize!(word(res), 0)
normalform!(word(res), g)
2021-05-07 18:11:11 +02:00
_setnormalform!(res, true)
_setvalidhash!(res, false)
2021-05-05 01:10:28 +02:00
end
return res
end
"""
normalform!(res::AbstractWord, g::FPGroupElement)
Write the normal form of `g` to word `res`, modifying `res` in place.
2021-05-05 01:10:28 +02:00
The particular implementation of the normal form depends on `parent(g)`.
2021-05-05 01:10:28 +02:00
"""
2021-06-29 16:52:35 +02:00
@inline function normalform!(res::AbstractWord, g::AbstractFPGroupElement)
2021-05-05 01:10:28 +02:00
isone(res) && isnormalform(g) && return append!(res, word(g))
return KnuthBendix.rewrite!(res, word(g), rewriting(parent(g)))
2021-05-05 01:10:28 +02:00
end