1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-19 06:30:29 +01: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
struct FreeGroup{T} <: AbstractFPGroup
struct FreeGroup{T,O} <: AbstractFPGroup
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 all(l -> l in KnuthBendix.letters(A), gens)
return new{eltype(gens)}(gens, A)
L = KnuthBendix.letters(alphabet(ordering))
@assert all(l -> l in L, gens)
return new{eltype(gens),typeof(ordering)}(gens, ordering)
end
end
FreeGroup(gens, A::Alphabet) = FreeGroup(gens, KnuthBendix.LenLex(A))
function FreeGroup(A::Alphabet)
@boundscheck @assert all(
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")
# mandatory methods:
KnuthBendix.alphabet(F::FreeGroup) = F.alphabet
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:
# these are mathematically correct
@ -198,23 +203,22 @@ struct FPGroup{T,R,S} <: AbstractFPGroup
rws::R
end
KnuthBendix.alphabet(G::FPGroup) = alphabet(rewriting(G))
rewriting(G::FPGroup) = G.rws
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(
G::AbstractFPGroup,
rels::AbstractVector{<:Pair{GEl,GEl}};
ordering = KnuthBendix.LenLex,
ordering = KnuthBendix.ordering(G),
kwargs...,
) where {GEl<:FPGroupElement}
O = ordering(alphabet(G))
for (lhs, rhs) in rels
@assert parent(lhs) === parent(rhs) === G
end
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...)