1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-08-08 15:58:53 +02:00

allow passing order directly to FPGroup constructor

This commit is contained in:
Marek Kaluba 2021-12-18 19:33:37 +01:00
parent 667cd601ce
commit 5b5f3e3811
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15

View File

@ -137,17 +137,20 @@ Base.isone(g::AbstractFPGroupElement) = (normalform!(g); isempty(word(g)))
## Free Groups ## Free Groups
struct FreeGroup{T} <: AbstractFPGroup struct FreeGroup{T,O} <: AbstractFPGroup
gens::Vector{T} gens::Vector{T}
alphabet::KnuthBendix.Alphabet{T} ordering::O
function FreeGroup(gens, A::KnuthBendix.Alphabet) where {W} function FreeGroup(gens, ordering::KnuthBendix.WordOrdering)
@assert length(gens) == length(unique(gens)) @assert length(gens) == length(unique(gens))
@assert all(l -> l in KnuthBendix.letters(A), gens) L = KnuthBendix.letters(alphabet(ordering))
return new{eltype(gens)}(gens, A) @assert all(l -> l in L, gens)
return new{eltype(gens),typeof(ordering)}(gens, ordering)
end end
end end
FreeGroup(gens, A::Alphabet) = FreeGroup(gens, KnuthBendix.LenLex(A))
function FreeGroup(A::Alphabet) function FreeGroup(A::Alphabet)
@boundscheck @assert all( @boundscheck @assert all(
KnuthBendix.hasinverse(l, A) for l in KnuthBendix.letters(A) KnuthBendix.hasinverse(l, A) for l in KnuthBendix.letters(A)
@ -180,8 +183,10 @@ Base.show(io::IO, F::FreeGroup) =
print(io, "free group on $(ngens(F)) generators") print(io, "free group on $(ngens(F)) generators")
# mandatory methods: # mandatory methods:
KnuthBendix.alphabet(F::FreeGroup) = F.alphabet
relations(F::FreeGroup) = Pair{eltype(F)}[] relations(F::FreeGroup) = Pair{eltype(F)}[]
KnuthBendix.ordering(F::FreeGroup) = F.ordering
KnuthBendix.alphabet(F::FreeGroup) = alphabet(KnuthBendix.ordering(F))
rewriting(F::FreeGroup) = alphabet(F)
# GroupsCore interface: # GroupsCore interface:
# these are mathematically correct # these are mathematically correct
@ -198,23 +203,22 @@ struct FPGroup{T,R,S} <: AbstractFPGroup
rws::R rws::R
end end
KnuthBendix.alphabet(G::FPGroup) = alphabet(rewriting(G))
rewriting(G::FPGroup) = G.rws
relations(G::FPGroup) = G.relations relations(G::FPGroup) = G.relations
rewriting(G::FPGroup) = G.rws
KnuthBendix.ordering(G::FPGroup) = KnuthBendix.ordering(rewriting(G))
KnuthBendix.alphabet(G::FPGroup) = alphabet(KnuthBendix.ordering(G))
function FPGroup( function FPGroup(
G::AbstractFPGroup, G::AbstractFPGroup,
rels::AbstractVector{<:Pair{GEl,GEl}}; rels::AbstractVector{<:Pair{GEl,GEl}};
ordering = KnuthBendix.LenLex, ordering = KnuthBendix.ordering(G),
kwargs..., kwargs...,
) where {GEl<:FPGroupElement} ) where {GEl<:FPGroupElement}
O = ordering(alphabet(G))
for (lhs, rhs) in rels for (lhs, rhs) in rels
@assert parent(lhs) === parent(rhs) === G @assert parent(lhs) === parent(rhs) === G
end end
word_rels = [word(lhs) => word(rhs) for (lhs, rhs) in [relations(G); rels]] word_rels = [word(lhs) => word(rhs) for (lhs, rhs) in [relations(G); rels]]
rws = KnuthBendix.RewritingSystem(word_rels, O) rws = KnuthBendix.RewritingSystem(word_rels, ordering)
KnuthBendix.knuthbendix!(rws; kwargs...) KnuthBendix.knuthbendix!(rws; kwargs...)